@testing-library/user-event 14.0.0-beta.3 → 14.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1110 -3
- package/dist/index.js +2826 -8
- package/dist/package.json +1 -0
- package/package.json +6 -30
- package/dist/clipboard/copy.d.ts +0 -2
- package/dist/clipboard/copy.js +0 -36
- package/dist/clipboard/cut.d.ts +0 -2
- package/dist/clipboard/cut.js +0 -42
- package/dist/clipboard/index.d.ts +0 -3
- package/dist/clipboard/index.js +0 -44
- package/dist/clipboard/paste.d.ts +0 -2
- package/dist/clipboard/paste.js +0 -47
- package/dist/convenience/click.d.ts +0 -4
- package/dist/convenience/click.js +0 -52
- package/dist/convenience/hover.d.ts +0 -3
- package/dist/convenience/hover.js +0 -31
- package/dist/convenience/index.d.ts +0 -3
- package/dist/convenience/index.js +0 -44
- package/dist/convenience/tab.d.ts +0 -4
- package/dist/convenience/tab.js +0 -12
- package/dist/document/index.d.ts +0 -10
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.d.ts +0 -15
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.d.ts +0 -27
- package/dist/document/selection.js +0 -90
- package/dist/document/value.d.ts +0 -18
- package/dist/document/value.js +0 -77
- package/dist/keyboard/getEventProps.d.ts +0 -15
- package/dist/keyboard/getEventProps.js +0 -27
- package/dist/keyboard/index.d.ts +0 -7
- package/dist/keyboard/index.js +0 -42
- package/dist/keyboard/keyMap.d.ts +0 -5
- package/dist/keyboard/keyMap.js +0 -119
- package/dist/keyboard/keyboardAction.d.ts +0 -10
- package/dist/keyboard/keyboardAction.js +0 -156
- package/dist/keyboard/parseKeyDef.d.ts +0 -17
- package/dist/keyboard/parseKeyDef.js +0 -61
- package/dist/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.d.ts +0 -5
- package/dist/keyboard/plugins/character.js +0 -173
- package/dist/keyboard/plugins/combination.d.ts +0 -5
- package/dist/keyboard/plugins/combination.js +0 -19
- package/dist/keyboard/plugins/control.d.ts +0 -6
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.d.ts +0 -11
- package/dist/keyboard/plugins/functional.js +0 -158
- package/dist/keyboard/plugins/index.d.ts +0 -7
- package/dist/keyboard/plugins/index.js +0 -33
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.d.ts +0 -1
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/types.d.ts +0 -64
- package/dist/keyboard/types.js +0 -19
- package/dist/options.d.ts +0 -102
- package/dist/options.js +0 -36
- package/dist/pointer/index.d.ts +0 -10
- package/dist/pointer/index.js +0 -56
- package/dist/pointer/keyMap.d.ts +0 -2
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.d.ts +0 -6
- package/dist/pointer/parseKeyDef.js +0 -34
- package/dist/pointer/pointerAction.d.ts +0 -7
- package/dist/pointer/pointerAction.js +0 -46
- package/dist/pointer/pointerMove.d.ts +0 -6
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.d.ts +0 -8
- package/dist/pointer/pointerPress.js +0 -327
- package/dist/pointer/resolveSelectionTarget.d.ts +0 -5
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.d.ts +0 -61
- package/dist/pointer/types.js +0 -1
- package/dist/setup/api.d.ts +0 -5
- package/dist/setup/api.js +0 -111
- package/dist/setup/config.d.ts +0 -10
- package/dist/setup/config.js +0 -8
- package/dist/setup/directApi.d.ts +0 -20
- package/dist/setup/directApi.js +0 -95
- package/dist/setup/index.d.ts +0 -30
- package/dist/setup/index.js +0 -27
- package/dist/setup/setup.d.ts +0 -74
- package/dist/setup/setup.js +0 -98
- package/dist/setup/wrapAsync.d.ts +0 -4
- package/dist/setup/wrapAsync.js +0 -15
- package/dist/utility/clear.d.ts +0 -2
- package/dist/utility/clear.js +0 -30
- package/dist/utility/index.d.ts +0 -4
- package/dist/utility/index.js +0 -57
- package/dist/utility/selectOptions.d.ts +0 -3
- package/dist/utility/selectOptions.js +0 -132
- package/dist/utility/type.d.ts +0 -9
- package/dist/utility/type.js +0 -37
- package/dist/utility/upload.d.ts +0 -5
- package/dist/utility/upload.js +0 -64
- package/dist/utils/click/isClickableInput.d.ts +0 -1
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/dataTransfer/Blob.d.ts +0 -1
- package/dist/utils/dataTransfer/Blob.js +0 -21
- package/dist/utils/dataTransfer/Clipboard.d.ts +0 -9
- package/dist/utils/dataTransfer/Clipboard.js +0 -188
- package/dist/utils/dataTransfer/DataTransfer.d.ts +0 -2
- package/dist/utils/dataTransfer/DataTransfer.js +0 -158
- package/dist/utils/dataTransfer/FileList.d.ts +0 -1
- package/dist/utils/dataTransfer/FileList.js +0 -23
- package/dist/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.d.ts +0 -14
- package/dist/utils/edit/calculateNewValue.js +0 -46
- package/dist/utils/edit/editInputElement.d.ts +0 -16
- package/dist/utils/edit/editInputElement.js +0 -53
- package/dist/utils/edit/getValue.d.ts +0 -1
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.d.ts +0 -7
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.d.ts +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.d.ts +0 -1
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.d.ts +0 -7
- package/dist/utils/edit/prepareInput.js +0 -77
- package/dist/utils/edit/setFiles.d.ts +0 -12
- package/dist/utils/edit/setFiles.js +0 -72
- package/dist/utils/focus/blur.d.ts +0 -2
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/copySelection.d.ts +0 -1
- package/dist/utils/focus/copySelection.js +0 -36
- package/dist/utils/focus/focus.d.ts +0 -2
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.d.ts +0 -1
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.d.ts +0 -1
- package/dist/utils/focus/getTabDestination.js +0 -84
- package/dist/utils/focus/isFocusable.d.ts +0 -1
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selectAll.d.ts +0 -5
- package/dist/utils/focus/selectAll.js +0 -51
- package/dist/utils/focus/selection.d.ts +0 -42
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.d.ts +0 -1
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.d.ts +0 -38
- package/dist/utils/index.js +0 -499
- package/dist/utils/keyDef/readNextDescriptor.d.ts +0 -19
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.d.ts +0 -1
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.d.ts +0 -1
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/getDocumentFromNode.d.ts +0 -1
- package/dist/utils/misc/getDocumentFromNode.js +0 -14
- package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.d.ts +0 -1
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.d.ts +0 -5
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/misc/isVisible.js +0 -31
- package/dist/utils/misc/wait.d.ts +0 -1
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/firePointerEvents.d.ts +0 -25
- package/dist/utils/pointer/firePointerEvents.js +0 -110
- package/dist/utils/pointer/mouseButtons.d.ts +0 -12
- package/dist/utils/pointer/mouseButtons.js +0 -45
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.clearUISelection = clearUISelection;
|
|
7
|
-
exports.getUISelection = getUISelection;
|
|
8
|
-
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
9
|
-
exports.setUISelection = setUISelection;
|
|
10
|
-
|
|
11
|
-
var _ = require(".");
|
|
12
|
-
|
|
13
|
-
var _interceptor = require("./interceptor");
|
|
14
|
-
|
|
15
|
-
const UISelection = Symbol('Displayed selection in UI');
|
|
16
|
-
|
|
17
|
-
function prepareSelectionInterceptor(element) {
|
|
18
|
-
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
|
|
19
|
-
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
20
|
-
|
|
21
|
-
if (!isUI) {
|
|
22
|
-
this[UISelection] = undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
realArgs: [Number(start), end, direction]
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
(0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
|
|
30
|
-
this[UISelection] = undefined;
|
|
31
|
-
return {
|
|
32
|
-
realArgs: v
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
(0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
|
|
36
|
-
this[UISelection] = undefined;
|
|
37
|
-
return {
|
|
38
|
-
realArgs: v
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function setUISelection(element, {
|
|
44
|
-
focusOffset: focusOffsetParam,
|
|
45
|
-
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
46
|
-
}, mode = 'replace') {
|
|
47
|
-
const valueLength = (0, _.getUIValue)(element).length;
|
|
48
|
-
|
|
49
|
-
const sanitizeOffset = o => Math.max(0, Math.min(valueLength, o));
|
|
50
|
-
|
|
51
|
-
const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
52
|
-
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
53
|
-
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
54
|
-
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
55
|
-
element[UISelection] = {
|
|
56
|
-
anchorOffset,
|
|
57
|
-
focusOffset
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
61
|
-
return;
|
|
62
|
-
} // eslint-disable-next-line no-new-wrappers
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const startObj = new Number(startOffset);
|
|
66
|
-
startObj[UISelection] = UISelection;
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
element.setSelectionRange(startObj, endOffset);
|
|
70
|
-
} catch {// DOMException for invalid state is expected when calling this
|
|
71
|
-
// on an element without support for setSelectionRange
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getUISelection(element) {
|
|
76
|
-
var _element$UISelection, _element$selectionSta, _element$selectionEnd;
|
|
77
|
-
|
|
78
|
-
const sel = (_element$UISelection = element[UISelection]) != null ? _element$UISelection : {
|
|
79
|
-
anchorOffset: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta : 0,
|
|
80
|
-
focusOffset: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd : 0
|
|
81
|
-
};
|
|
82
|
-
return { ...sel,
|
|
83
|
-
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
84
|
-
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function clearUISelection(element) {
|
|
89
|
-
element[UISelection] = undefined;
|
|
90
|
-
}
|
package/dist/document/value.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
declare const UIValue: unique symbol;
|
|
2
|
-
declare const InitialValue: unique symbol;
|
|
3
|
-
declare const TrackChanges: unique symbol;
|
|
4
|
-
declare global {
|
|
5
|
-
interface Element {
|
|
6
|
-
[UIValue]?: string;
|
|
7
|
-
[InitialValue]?: string;
|
|
8
|
-
[TrackChanges]?: string[];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
12
|
-
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
13
|
-
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
|
|
14
|
-
export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
15
|
-
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
16
|
-
export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
|
-
export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): string[] | undefined;
|
|
18
|
-
export {};
|
package/dist/document/value.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.endTrackValue = endTrackValue;
|
|
7
|
-
exports.getInitialValue = getInitialValue;
|
|
8
|
-
exports.getUIValue = getUIValue;
|
|
9
|
-
exports.prepareValueInterceptor = prepareValueInterceptor;
|
|
10
|
-
exports.setInitialValue = setInitialValue;
|
|
11
|
-
exports.setUIValue = setUIValue;
|
|
12
|
-
exports.startTrackValue = startTrackValue;
|
|
13
|
-
|
|
14
|
-
var _interceptor = require("./interceptor");
|
|
15
|
-
|
|
16
|
-
var _selection = require("./selection");
|
|
17
|
-
|
|
18
|
-
const UIValue = Symbol('Displayed value in UI');
|
|
19
|
-
const InitialValue = Symbol('Initial value to compare on blur');
|
|
20
|
-
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
21
|
-
|
|
22
|
-
function valueInterceptor(v) {
|
|
23
|
-
const isUI = typeof v === 'object' && v[UIValue];
|
|
24
|
-
this[UIValue] = isUI ? String(v) : undefined;
|
|
25
|
-
|
|
26
|
-
if (!isUI) {
|
|
27
|
-
trackValue(this, String(v));
|
|
28
|
-
this[InitialValue] = String(v); // Programmatically setting the value property
|
|
29
|
-
// moves the cursor to the end of the input.
|
|
30
|
-
|
|
31
|
-
(0, _selection.clearUISelection)(this);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
applyNative: !!isUI,
|
|
36
|
-
realArgs: String(v)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function prepareValueInterceptor(element) {
|
|
41
|
-
(0, _interceptor.prepareInterceptor)(element, 'value', valueInterceptor);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function setUIValue(element, value) {
|
|
45
|
-
element.value = {
|
|
46
|
-
[UIValue]: UIValue,
|
|
47
|
-
toString: () => value
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getUIValue(element) {
|
|
52
|
-
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setInitialValue(element) {
|
|
56
|
-
element[InitialValue] = element.value;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getInitialValue(element) {
|
|
60
|
-
return element[InitialValue];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function startTrackValue(element) {
|
|
64
|
-
element[TrackChanges] = [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function trackValue(element, v) {
|
|
68
|
-
var _element$TrackChanges;
|
|
69
|
-
|
|
70
|
-
(_element$TrackChanges = element[TrackChanges]) == null ? void 0 : _element$TrackChanges.push(v);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function endTrackValue(element) {
|
|
74
|
-
const tracked = element[TrackChanges];
|
|
75
|
-
element[TrackChanges] = undefined;
|
|
76
|
-
return tracked;
|
|
77
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { keyboardKey, keyboardState } from './types';
|
|
2
|
-
export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardState): {
|
|
3
|
-
key: string | undefined;
|
|
4
|
-
code: string | undefined;
|
|
5
|
-
altKey: boolean;
|
|
6
|
-
ctrlKey: boolean;
|
|
7
|
-
metaKey: boolean;
|
|
8
|
-
shiftKey: boolean;
|
|
9
|
-
};
|
|
10
|
-
export declare function getMouseEventProps(state: keyboardState): {
|
|
11
|
-
altKey: boolean;
|
|
12
|
-
ctrlKey: boolean;
|
|
13
|
-
metaKey: boolean;
|
|
14
|
-
shiftKey: boolean;
|
|
15
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getKeyEventProps = getKeyEventProps;
|
|
7
|
-
exports.getMouseEventProps = getMouseEventProps;
|
|
8
|
-
|
|
9
|
-
function getKeyEventProps(keyDef, state) {
|
|
10
|
-
return {
|
|
11
|
-
key: keyDef.key,
|
|
12
|
-
code: keyDef.code,
|
|
13
|
-
altKey: state.modifiers.alt,
|
|
14
|
-
ctrlKey: state.modifiers.ctrl,
|
|
15
|
-
metaKey: state.modifiers.meta,
|
|
16
|
-
shiftKey: state.modifiers.shift
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getMouseEventProps(state) {
|
|
21
|
-
return {
|
|
22
|
-
altKey: state.modifiers.alt,
|
|
23
|
-
ctrlKey: state.modifiers.ctrl,
|
|
24
|
-
metaKey: state.modifiers.meta,
|
|
25
|
-
shiftKey: state.modifiers.shift
|
|
26
|
-
};
|
|
27
|
-
}
|
package/dist/keyboard/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { UserEvent } from '../setup';
|
|
2
|
-
import { releaseAllKeys } from './keyboardAction';
|
|
3
|
-
import type { keyboardState, keyboardKey } from './types';
|
|
4
|
-
export { releaseAllKeys };
|
|
5
|
-
export type { keyboardKey, keyboardState };
|
|
6
|
-
export declare function keyboard(this: UserEvent, text: string): Promise<void>;
|
|
7
|
-
export declare function createKeyboardState(): keyboardState;
|
package/dist/keyboard/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createKeyboardState = createKeyboardState;
|
|
7
|
-
exports.keyboard = keyboard;
|
|
8
|
-
Object.defineProperty(exports, "releaseAllKeys", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _keyboardAction.releaseAllKeys;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
var _setup = require("../setup");
|
|
16
|
-
|
|
17
|
-
var _keyboardAction = require("./keyboardAction");
|
|
18
|
-
|
|
19
|
-
var _parseKeyDef = require("./parseKeyDef");
|
|
20
|
-
|
|
21
|
-
async function keyboard(text) {
|
|
22
|
-
const {
|
|
23
|
-
keyboardMap
|
|
24
|
-
} = this[_setup.Config];
|
|
25
|
-
const actions = (0, _parseKeyDef.parseKeyDef)(keyboardMap, text);
|
|
26
|
-
return (0, _keyboardAction.keyboardAction)(this[_setup.Config], actions);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function createKeyboardState() {
|
|
30
|
-
return {
|
|
31
|
-
activeElement: null,
|
|
32
|
-
pressed: [],
|
|
33
|
-
carryChar: '',
|
|
34
|
-
modifiers: {
|
|
35
|
-
alt: false,
|
|
36
|
-
caps: false,
|
|
37
|
-
ctrl: false,
|
|
38
|
-
meta: false,
|
|
39
|
-
shift: false
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
package/dist/keyboard/keyMap.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.defaultKeyMap = void 0;
|
|
7
|
-
|
|
8
|
-
var _types = require("./types");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Mapping for a default US-104-QWERTY keyboard
|
|
12
|
-
*/
|
|
13
|
-
const defaultKeyMap = [// alphanumeric keys
|
|
14
|
-
...'0123456789'.split('').map(c => ({
|
|
15
|
-
code: `Digit${c}`,
|
|
16
|
-
key: c
|
|
17
|
-
})), ...')!@#$%^&*('.split('').map((c, i) => ({
|
|
18
|
-
code: `Digit${i}`,
|
|
19
|
-
key: c,
|
|
20
|
-
shiftKey: true
|
|
21
|
-
})), ...'abcdefghijklmnopqrstuvwxyz'.split('').map(c => ({
|
|
22
|
-
code: `Key${c.toUpperCase()}`,
|
|
23
|
-
key: c
|
|
24
|
-
})), ...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map(c => ({
|
|
25
|
-
code: `Key${c}`,
|
|
26
|
-
key: c,
|
|
27
|
-
shiftKey: true
|
|
28
|
-
})), // alphanumeric block - functional
|
|
29
|
-
{
|
|
30
|
-
code: 'Space',
|
|
31
|
-
key: ' '
|
|
32
|
-
}, {
|
|
33
|
-
code: 'AltLeft',
|
|
34
|
-
key: 'Alt',
|
|
35
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
36
|
-
}, {
|
|
37
|
-
code: 'AltRight',
|
|
38
|
-
key: 'Alt',
|
|
39
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
40
|
-
}, {
|
|
41
|
-
code: 'ShiftLeft',
|
|
42
|
-
key: 'Shift',
|
|
43
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
44
|
-
}, {
|
|
45
|
-
code: 'ShiftRight',
|
|
46
|
-
key: 'Shift',
|
|
47
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
48
|
-
}, {
|
|
49
|
-
code: 'ControlLeft',
|
|
50
|
-
key: 'Control',
|
|
51
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
52
|
-
}, {
|
|
53
|
-
code: 'ControlRight',
|
|
54
|
-
key: 'Control',
|
|
55
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
56
|
-
}, {
|
|
57
|
-
code: 'MetaLeft',
|
|
58
|
-
key: 'Meta',
|
|
59
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
60
|
-
}, {
|
|
61
|
-
code: 'MetaRight',
|
|
62
|
-
key: 'Meta',
|
|
63
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
64
|
-
}, {
|
|
65
|
-
code: 'OSLeft',
|
|
66
|
-
key: 'OS',
|
|
67
|
-
location: _types.DOM_KEY_LOCATION.LEFT
|
|
68
|
-
}, {
|
|
69
|
-
code: 'OSRight',
|
|
70
|
-
key: 'OS',
|
|
71
|
-
location: _types.DOM_KEY_LOCATION.RIGHT
|
|
72
|
-
}, {
|
|
73
|
-
code: 'Tab',
|
|
74
|
-
key: 'Tab'
|
|
75
|
-
}, {
|
|
76
|
-
code: 'CapsLock',
|
|
77
|
-
key: 'CapsLock'
|
|
78
|
-
}, {
|
|
79
|
-
code: 'Backspace',
|
|
80
|
-
key: 'Backspace'
|
|
81
|
-
}, {
|
|
82
|
-
code: 'Enter',
|
|
83
|
-
key: 'Enter'
|
|
84
|
-
}, // function
|
|
85
|
-
{
|
|
86
|
-
code: 'Escape',
|
|
87
|
-
key: 'Escape'
|
|
88
|
-
}, // arrows
|
|
89
|
-
{
|
|
90
|
-
code: 'ArrowUp',
|
|
91
|
-
key: 'ArrowUp'
|
|
92
|
-
}, {
|
|
93
|
-
code: 'ArrowDown',
|
|
94
|
-
key: 'ArrowDown'
|
|
95
|
-
}, {
|
|
96
|
-
code: 'ArrowLeft',
|
|
97
|
-
key: 'ArrowLeft'
|
|
98
|
-
}, {
|
|
99
|
-
code: 'ArrowRight',
|
|
100
|
-
key: 'ArrowRight'
|
|
101
|
-
}, // control pad
|
|
102
|
-
{
|
|
103
|
-
code: 'Home',
|
|
104
|
-
key: 'Home'
|
|
105
|
-
}, {
|
|
106
|
-
code: 'End',
|
|
107
|
-
key: 'End'
|
|
108
|
-
}, {
|
|
109
|
-
code: 'Delete',
|
|
110
|
-
key: 'Delete'
|
|
111
|
-
}, {
|
|
112
|
-
code: 'PageUp',
|
|
113
|
-
key: 'PageUp'
|
|
114
|
-
}, {
|
|
115
|
-
code: 'PageDown',
|
|
116
|
-
key: 'PageDown'
|
|
117
|
-
} // TODO: add mappings
|
|
118
|
-
];
|
|
119
|
-
exports.defaultKeyMap = defaultKeyMap;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Config } from '../setup';
|
|
2
|
-
import { keyboardKey } from './types';
|
|
3
|
-
export interface KeyboardAction {
|
|
4
|
-
keyDef: keyboardKey;
|
|
5
|
-
releasePrevious: boolean;
|
|
6
|
-
releaseSelf: boolean;
|
|
7
|
-
repeat: number;
|
|
8
|
-
}
|
|
9
|
-
export declare function keyboardAction(config: Config, actions: KeyboardAction[]): Promise<void>;
|
|
10
|
-
export declare function releaseAllKeys(config: Config): Promise<void>;
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.keyboardAction = keyboardAction;
|
|
7
|
-
exports.releaseAllKeys = releaseAllKeys;
|
|
8
|
-
|
|
9
|
-
var _dom = require("@testing-library/dom");
|
|
10
|
-
|
|
11
|
-
var _utils = require("../utils");
|
|
12
|
-
|
|
13
|
-
var plugins = _interopRequireWildcard(require("./plugins"));
|
|
14
|
-
|
|
15
|
-
var _getEventProps = require("./getEventProps");
|
|
16
|
-
|
|
17
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
|
-
|
|
19
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
-
|
|
21
|
-
async function keyboardAction(config, actions) {
|
|
22
|
-
for (let i = 0; i < actions.length; i++) {
|
|
23
|
-
await keyboardKeyAction(config, actions[i]);
|
|
24
|
-
|
|
25
|
-
if (typeof config.delay === 'number' && i < actions.length - 1) {
|
|
26
|
-
await (0, _utils.wait)(config.delay);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function keyboardKeyAction(config, {
|
|
32
|
-
keyDef,
|
|
33
|
-
releasePrevious,
|
|
34
|
-
releaseSelf,
|
|
35
|
-
repeat
|
|
36
|
-
}) {
|
|
37
|
-
const {
|
|
38
|
-
document,
|
|
39
|
-
keyboardState,
|
|
40
|
-
delay
|
|
41
|
-
} = config;
|
|
42
|
-
|
|
43
|
-
const getCurrentElement = () => getActive(document); // Release the key automatically if it was pressed before.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const pressed = keyboardState.pressed.find(p => p.keyDef === keyDef);
|
|
47
|
-
|
|
48
|
-
if (pressed) {
|
|
49
|
-
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!releasePrevious) {
|
|
53
|
-
let unpreventedDefault = true;
|
|
54
|
-
|
|
55
|
-
for (let i = 1; i <= repeat; i++) {
|
|
56
|
-
unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
|
|
57
|
-
|
|
58
|
-
if (unpreventedDefault && hasKeyPress(keyDef, config)) {
|
|
59
|
-
await keypress(keyDef, getCurrentElement, config);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (typeof delay === 'number' && i < repeat) {
|
|
63
|
-
await (0, _utils.wait)(delay);
|
|
64
|
-
}
|
|
65
|
-
} // Release the key only on the last iteration on `state.repeatKey`.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (releaseSelf) {
|
|
69
|
-
await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getActive(document) {
|
|
75
|
-
var _getActiveElement;
|
|
76
|
-
|
|
77
|
-
return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
|
|
78
|
-
/* istanbul ignore next */
|
|
79
|
-
document.body;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function releaseAllKeys(config) {
|
|
83
|
-
const getCurrentElement = () => getActive(config.document);
|
|
84
|
-
|
|
85
|
-
for (const k of config.keyboardState.pressed) {
|
|
86
|
-
await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function keydown(keyDef, getCurrentElement, config) {
|
|
91
|
-
const element = getCurrentElement(); // clear carried characters when focus is moved
|
|
92
|
-
|
|
93
|
-
if (element !== config.keyboardState.activeElement) {
|
|
94
|
-
config.keyboardState.carryValue = undefined;
|
|
95
|
-
config.keyboardState.carryChar = '';
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
config.keyboardState.activeElement = element;
|
|
99
|
-
applyPlugins(plugins.preKeydownBehavior, keyDef, element, config);
|
|
100
|
-
|
|
101
|
-
const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
102
|
-
|
|
103
|
-
config.keyboardState.pressed.push({
|
|
104
|
-
keyDef,
|
|
105
|
-
unpreventedDefault
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (unpreventedDefault) {
|
|
109
|
-
// all default behavior like keypress/submit etc is applied to the currentElement
|
|
110
|
-
applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), config);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return unpreventedDefault;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function keypress(keyDef, getCurrentElement, config) {
|
|
117
|
-
const element = getCurrentElement();
|
|
118
|
-
|
|
119
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState),
|
|
120
|
-
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
if (unpreventedDefault) {
|
|
124
|
-
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), config);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
129
|
-
const element = getCurrentElement();
|
|
130
|
-
applyPlugins(plugins.preKeyupBehavior, keyDef, element, config);
|
|
131
|
-
|
|
132
|
-
const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, config.keyboardState));
|
|
133
|
-
|
|
134
|
-
if (unprevented && unpreventedDefault) {
|
|
135
|
-
applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), config);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
config.keyboardState.pressed = config.keyboardState.pressed.filter(k => k.keyDef !== keyDef);
|
|
139
|
-
applyPlugins(plugins.postKeyupBehavior, keyDef, element, config);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
143
|
-
const plugin = pluginCollection.find(p => p.matches(keyDef, element, config));
|
|
144
|
-
|
|
145
|
-
if (plugin) {
|
|
146
|
-
plugin.handle(keyDef, element, config);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return !!plugin;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function hasKeyPress(keyDef, config) {
|
|
153
|
-
var _keyDef$key;
|
|
154
|
-
|
|
155
|
-
return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !config.keyboardState.modifiers.ctrl && !config.keyboardState.modifiers.alt;
|
|
156
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { keyboardKey } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Parse key defintions per `keyboardMap`
|
|
4
|
-
*
|
|
5
|
-
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
6
|
-
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
7
|
-
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
8
|
-
* Keeping the key pressed can be written as `{key>}`.
|
|
9
|
-
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
10
|
-
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
11
|
-
*/
|
|
12
|
-
export declare function parseKeyDef(keyboardMap: keyboardKey[], text: string): {
|
|
13
|
-
keyDef: keyboardKey;
|
|
14
|
-
releasePrevious: boolean;
|
|
15
|
-
releaseSelf: boolean;
|
|
16
|
-
repeat: number;
|
|
17
|
-
}[];
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseKeyDef = parseKeyDef;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../utils");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Parse key defintions per `keyboardMap`
|
|
12
|
-
*
|
|
13
|
-
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
14
|
-
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
15
|
-
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
16
|
-
* Keeping the key pressed can be written as `{key>}`.
|
|
17
|
-
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
18
|
-
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
19
|
-
*/
|
|
20
|
-
function parseKeyDef(keyboardMap, text) {
|
|
21
|
-
const defs = [];
|
|
22
|
-
|
|
23
|
-
do {
|
|
24
|
-
var _keyboardMap$find;
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
type,
|
|
28
|
-
descriptor,
|
|
29
|
-
consumedLength,
|
|
30
|
-
releasePrevious,
|
|
31
|
-
releaseSelf = true,
|
|
32
|
-
repeat
|
|
33
|
-
} = (0, _utils.readNextDescriptor)(text);
|
|
34
|
-
const keyDef = (_keyboardMap$find = keyboardMap.find(def => {
|
|
35
|
-
if (type === '[') {
|
|
36
|
-
var _def$code;
|
|
37
|
-
|
|
38
|
-
return ((_def$code = def.code) == null ? void 0 : _def$code.toLowerCase()) === descriptor.toLowerCase();
|
|
39
|
-
} else if (type === '{') {
|
|
40
|
-
var _def$key;
|
|
41
|
-
|
|
42
|
-
return ((_def$key = def.key) == null ? void 0 : _def$key.toLowerCase()) === descriptor.toLowerCase();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return def.key === descriptor;
|
|
46
|
-
})) != null ? _keyboardMap$find : {
|
|
47
|
-
key: 'Unknown',
|
|
48
|
-
code: 'Unknown',
|
|
49
|
-
[type === '[' ? 'code' : 'key']: descriptor
|
|
50
|
-
};
|
|
51
|
-
defs.push({
|
|
52
|
-
keyDef,
|
|
53
|
-
releasePrevious,
|
|
54
|
-
releaseSelf,
|
|
55
|
-
repeat
|
|
56
|
-
});
|
|
57
|
-
text = text.slice(consumedLength);
|
|
58
|
-
} while (text);
|
|
59
|
-
|
|
60
|
-
return defs;
|
|
61
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.keydownBehavior = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("../../utils");
|
|
9
|
-
|
|
10
|
-
var _document = require("../../document");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* This file should contain behavior for arrow keys as described here:
|
|
14
|
-
* https://w3c.github.io/uievents-code/#key-arrowpad-section
|
|
15
|
-
*/
|
|
16
|
-
const keydownBehavior = [{
|
|
17
|
-
// TODO: implement for contentEditable
|
|
18
|
-
matches: (keyDef, element) => (keyDef.key === 'ArrowLeft' || keyDef.key === 'ArrowRight') && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
19
|
-
handle: (keyDef, element) => {
|
|
20
|
-
const selection = (0, _document.getUISelection)(element); // TODO: implement shift/ctrl
|
|
21
|
-
|
|
22
|
-
(0, _utils.setSelection)({
|
|
23
|
-
focusNode: element,
|
|
24
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === 'ArrowLeft' ? -1 : 1) : keyDef.key === 'ArrowLeft' ? selection.startOffset : selection.endOffset
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}];
|
|
28
|
-
exports.keydownBehavior = keydownBehavior;
|