mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
update to blueprintjs 5.x
This commit is contained in:
committed by
David Lechner
parent
2fc3bea48f
commit
65e5627568
@@ -9,10 +9,6 @@ import '@testing-library/jest-dom/extend-expect';
|
||||
import 'navigator.locks';
|
||||
import crypto from 'crypto';
|
||||
import { inspect } from 'util';
|
||||
import {
|
||||
KeyCodes,
|
||||
Modifiers,
|
||||
} from '@blueprintjs/core/lib/cjs/components/hotkeys/hotkeyParser';
|
||||
// @ts-expect-error no typings
|
||||
import matchMediaPolyfill from 'mq-polyfill';
|
||||
import { config } from 'react-transition-group';
|
||||
@@ -42,54 +38,6 @@ if (!Element.prototype.scrollTo) {
|
||||
Element.prototype.scrollTo = jest.fn();
|
||||
}
|
||||
|
||||
// HACK: work around https://github.com/palantir/blueprint/issues/4165
|
||||
// userEvent.keyboard does not set which, so we have to do a reverse lookup
|
||||
// using the blueprintjs keymap.
|
||||
|
||||
// handle cases that are not simple lower case conversion
|
||||
const specialCases: Record<string, string> = {
|
||||
Control: 'ctrl',
|
||||
' ': 'space',
|
||||
ArrowDown: 'down',
|
||||
ArrowLeft: 'left',
|
||||
ArrowRight: 'right',
|
||||
ArrowUp: 'up',
|
||||
Delete: 'del',
|
||||
Insert: 'ins',
|
||||
Escape: 'esc',
|
||||
};
|
||||
|
||||
function addWhichToKeyboardEvent(e: KeyboardEvent) {
|
||||
// blueprints and testing-library both don't do this one
|
||||
if (e.key === 'ContextMenu') {
|
||||
// HACK: work around lack of ContextMenu key support in user-events
|
||||
if (e.target !== null) {
|
||||
e.target.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const blueprintsKeyName = specialCases[e.key] ?? e.key.toLowerCase();
|
||||
let which = 0;
|
||||
|
||||
for (const [k, v] of Object.entries(KeyCodes).concat(Object.entries(Modifiers))) {
|
||||
if (v === blueprintsKeyName) {
|
||||
which = Number(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (which === 0) {
|
||||
console.warn('unsupported key:', e.key, e.code);
|
||||
}
|
||||
|
||||
Object.defineProperty(e, 'which', { value: which });
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', addWhichToKeyboardEvent, { capture: true });
|
||||
document.addEventListener('keypress', addWhichToKeyboardEvent, { capture: true });
|
||||
document.addEventListener('keyup', addWhichToKeyboardEvent, { capture: true });
|
||||
|
||||
Object.defineProperty(global.self, 'crypto', {
|
||||
value: crypto.webcrypto,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user