@depup/testing-library__user-event 14.6.3-depup.0
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/LICENSE +20 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/cjs/clipboard/copy.js +22 -0
- package/dist/cjs/clipboard/cut.js +22 -0
- package/dist/cjs/clipboard/index.js +11 -0
- package/dist/cjs/clipboard/paste.js +24 -0
- package/dist/cjs/convenience/click.js +35 -0
- package/dist/cjs/convenience/hover.js +19 -0
- package/dist/cjs/convenience/index.js +14 -0
- package/dist/cjs/convenience/tab.js +7 -0
- package/dist/cjs/document/UI.js +90 -0
- package/dist/cjs/document/copySelection.js +29 -0
- package/dist/cjs/document/getValueOrTextContent.js +18 -0
- package/dist/cjs/document/index.js +17 -0
- package/dist/cjs/document/interceptor.js +104 -0
- package/dist/cjs/document/patchFocus.js +106 -0
- package/dist/cjs/document/prepareDocument.js +58 -0
- package/dist/cjs/document/trackValue.js +57 -0
- package/dist/cjs/event/behavior/click.js +32 -0
- package/dist/cjs/event/behavior/cut.js +14 -0
- package/dist/cjs/event/behavior/index.js +13 -0
- package/dist/cjs/event/behavior/keydown.js +128 -0
- package/dist/cjs/event/behavior/keypress.js +51 -0
- package/dist/cjs/event/behavior/keyup.js +17 -0
- package/dist/cjs/event/behavior/paste.js +18 -0
- package/dist/cjs/event/behavior/registry.js +5 -0
- package/dist/cjs/event/createEvent.js +193 -0
- package/dist/cjs/event/dispatchEvent.js +54 -0
- package/dist/cjs/event/eventMap.js +281 -0
- package/dist/cjs/event/focus.js +34 -0
- package/dist/cjs/event/index.js +22 -0
- package/dist/cjs/event/input.js +158 -0
- package/dist/cjs/event/radio.js +27 -0
- package/dist/cjs/event/selection/getInputRange.js +18 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +31 -0
- package/dist/cjs/event/selection/index.js +24 -0
- package/dist/cjs/event/selection/modifySelection.js +21 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +40 -0
- package/dist/cjs/event/selection/moveSelection.js +38 -0
- package/dist/cjs/event/selection/resolveCaretPosition.js +60 -0
- package/dist/cjs/event/selection/selectAll.js +38 -0
- package/dist/cjs/event/selection/setSelection.js +21 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +79 -0
- package/dist/cjs/event/selection/setSelectionRange.js +31 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +40 -0
- package/dist/cjs/event/types.js +2 -0
- package/dist/cjs/event/wrapEvent.js +10 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/keyboard/index.js +40 -0
- package/dist/cjs/keyboard/keyMap.js +178 -0
- package/dist/cjs/keyboard/parseKeyDef.js +45 -0
- package/dist/cjs/options.js +14 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pointer/index.js +74 -0
- package/dist/cjs/pointer/keyMap.js +33 -0
- package/dist/cjs/pointer/parseKeyDef.js +23 -0
- package/dist/cjs/setup/api.js +35 -0
- package/dist/cjs/setup/directApi.js +75 -0
- package/dist/cjs/setup/index.js +11 -0
- package/dist/cjs/setup/setup.js +125 -0
- package/dist/cjs/setup/wrapAsync.js +11 -0
- package/dist/cjs/system/index.js +42 -0
- package/dist/cjs/system/keyboard.js +165 -0
- package/dist/cjs/system/pointer/buttons.js +80 -0
- package/dist/cjs/system/pointer/device.js +32 -0
- package/dist/cjs/system/pointer/index.js +156 -0
- package/dist/cjs/system/pointer/mouse.js +204 -0
- package/dist/cjs/system/pointer/pointer.js +129 -0
- package/dist/cjs/system/pointer/shared.js +8 -0
- package/dist/cjs/utility/clear.js +32 -0
- package/dist/cjs/utility/index.js +14 -0
- package/dist/cjs/utility/selectOptions.js +114 -0
- package/dist/cjs/utility/type.js +23 -0
- package/dist/cjs/utility/upload.js +62 -0
- package/dist/cjs/utils/click/isClickableInput.js +20 -0
- package/dist/cjs/utils/dataTransfer/Blob.js +16 -0
- package/dist/cjs/utils/dataTransfer/Clipboard.js +174 -0
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +134 -0
- package/dist/cjs/utils/dataTransfer/FileList.js +24 -0
- package/dist/cjs/utils/edit/isContentEditable.js +18 -0
- package/dist/cjs/utils/edit/isEditable.js +29 -0
- package/dist/cjs/utils/edit/maxLength.js +26 -0
- package/dist/cjs/utils/edit/setFiles.js +58 -0
- package/dist/cjs/utils/edit/timeValue.js +40 -0
- package/dist/cjs/utils/focus/cursor.js +126 -0
- package/dist/cjs/utils/focus/getActiveElement.js +25 -0
- package/dist/cjs/utils/focus/getTabDestination.js +80 -0
- package/dist/cjs/utils/focus/isFocusable.js +9 -0
- package/dist/cjs/utils/focus/selection.js +20 -0
- package/dist/cjs/utils/focus/selector.js +15 -0
- package/dist/cjs/utils/index.js +78 -0
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +91 -0
- package/dist/cjs/utils/misc/cloneEvent.js +7 -0
- package/dist/cjs/utils/misc/findClosest.js +14 -0
- package/dist/cjs/utils/misc/getDocumentFromNode.js +10 -0
- package/dist/cjs/utils/misc/getTreeDiff.js +25 -0
- package/dist/cjs/utils/misc/getWindow.js +19 -0
- package/dist/cjs/utils/misc/isDescendantOrSelf.js +14 -0
- package/dist/cjs/utils/misc/isDisabled.js +33 -0
- package/dist/cjs/utils/misc/isElementType.js +20 -0
- package/dist/cjs/utils/misc/isVisible.js +19 -0
- package/dist/cjs/utils/misc/level.js +17 -0
- package/dist/cjs/utils/misc/wait.js +14 -0
- package/dist/cjs/utils/pointer/cssPointerEvents.js +102 -0
- package/dist/esm/clipboard/copy.js +20 -0
- package/dist/esm/clipboard/cut.js +20 -0
- package/dist/esm/clipboard/index.js +3 -0
- package/dist/esm/clipboard/paste.js +22 -0
- package/dist/esm/convenience/click.js +31 -0
- package/dist/esm/convenience/hover.js +16 -0
- package/dist/esm/convenience/index.js +3 -0
- package/dist/esm/convenience/tab.js +5 -0
- package/dist/esm/document/UI.js +77 -0
- package/dist/esm/document/copySelection.js +27 -0
- package/dist/esm/document/getValueOrTextContent.js +16 -0
- package/dist/esm/document/index.js +4 -0
- package/dist/esm/document/interceptor.js +99 -0
- package/dist/esm/document/patchFocus.js +103 -0
- package/dist/esm/document/prepareDocument.js +56 -0
- package/dist/esm/document/trackValue.js +53 -0
- package/dist/esm/event/behavior/click.js +30 -0
- package/dist/esm/event/behavior/cut.js +12 -0
- package/dist/esm/event/behavior/index.js +7 -0
- package/dist/esm/event/behavior/keydown.js +126 -0
- package/dist/esm/event/behavior/keypress.js +49 -0
- package/dist/esm/event/behavior/keyup.js +15 -0
- package/dist/esm/event/behavior/paste.js +16 -0
- package/dist/esm/event/behavior/registry.js +3 -0
- package/dist/esm/event/createEvent.js +191 -0
- package/dist/esm/event/dispatchEvent.js +50 -0
- package/dist/esm/event/eventMap.js +277 -0
- package/dist/esm/event/focus.js +31 -0
- package/dist/esm/event/index.js +7 -0
- package/dist/esm/event/input.js +156 -0
- package/dist/esm/event/radio.js +25 -0
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +29 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +19 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +38 -0
- package/dist/esm/event/selection/moveSelection.js +36 -0
- package/dist/esm/event/selection/resolveCaretPosition.js +58 -0
- package/dist/esm/event/selection/selectAll.js +35 -0
- package/dist/esm/event/selection/setSelection.js +19 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +77 -0
- package/dist/esm/event/selection/setSelectionRange.js +29 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +38 -0
- package/dist/esm/event/types.js +1 -0
- package/dist/esm/event/wrapEvent.js +8 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/keyboard/index.js +37 -0
- package/dist/esm/keyboard/keyMap.js +176 -0
- package/dist/esm/keyboard/parseKeyDef.js +43 -0
- package/dist/esm/options.js +12 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pointer/index.js +72 -0
- package/dist/esm/pointer/keyMap.js +31 -0
- package/dist/esm/pointer/parseKeyDef.js +21 -0
- package/dist/esm/setup/api.js +33 -0
- package/dist/esm/setup/directApi.js +58 -0
- package/dist/esm/setup/index.js +9 -0
- package/dist/esm/setup/setup.js +119 -0
- package/dist/esm/setup/wrapAsync.js +9 -0
- package/dist/esm/system/index.js +40 -0
- package/dist/esm/system/keyboard.js +162 -0
- package/dist/esm/system/pointer/buttons.js +74 -0
- package/dist/esm/system/pointer/device.js +30 -0
- package/dist/esm/system/pointer/index.js +154 -0
- package/dist/esm/system/pointer/mouse.js +202 -0
- package/dist/esm/system/pointer/pointer.js +127 -0
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +30 -0
- package/dist/esm/utility/index.js +4 -0
- package/dist/esm/utility/selectOptions.js +111 -0
- package/dist/esm/utility/type.js +21 -0
- package/dist/esm/utility/upload.js +60 -0
- package/dist/esm/utils/click/isClickableInput.js +18 -0
- package/dist/esm/utils/dataTransfer/Blob.js +14 -0
- package/dist/esm/utils/dataTransfer/Clipboard.js +167 -0
- package/dist/esm/utils/dataTransfer/DataTransfer.js +131 -0
- package/dist/esm/utils/dataTransfer/FileList.js +22 -0
- package/dist/esm/utils/edit/isContentEditable.js +15 -0
- package/dist/esm/utils/edit/isEditable.js +26 -0
- package/dist/esm/utils/edit/maxLength.js +23 -0
- package/dist/esm/utils/edit/setFiles.js +56 -0
- package/dist/esm/utils/edit/timeValue.js +37 -0
- package/dist/esm/utils/focus/cursor.js +124 -0
- package/dist/esm/utils/focus/getActiveElement.js +22 -0
- package/dist/esm/utils/focus/getTabDestination.js +78 -0
- package/dist/esm/utils/focus/isFocusable.js +7 -0
- package/dist/esm/utils/focus/selection.js +17 -0
- package/dist/esm/utils/focus/selector.js +13 -0
- package/dist/esm/utils/index.js +29 -0
- package/dist/esm/utils/keyDef/readNextDescriptor.js +89 -0
- package/dist/esm/utils/misc/cloneEvent.js +5 -0
- package/dist/esm/utils/misc/findClosest.js +12 -0
- package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
- package/dist/esm/utils/misc/getTreeDiff.js +23 -0
- package/dist/esm/utils/misc/getWindow.js +17 -0
- package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
- package/dist/esm/utils/misc/isDisabled.js +31 -0
- package/dist/esm/utils/misc/isElementType.js +18 -0
- package/dist/esm/utils/misc/isVisible.js +17 -0
- package/dist/esm/utils/misc/level.js +13 -0
- package/dist/esm/utils/misc/wait.js +12 -0
- package/dist/esm/utils/pointer/cssPointerEvents.js +99 -0
- package/dist/types/clipboard/copy.d.ts +2 -0
- package/dist/types/clipboard/cut.d.ts +2 -0
- package/dist/types/clipboard/index.d.ts +3 -0
- package/dist/types/clipboard/paste.d.ts +2 -0
- package/dist/types/convenience/click.d.ts +4 -0
- package/dist/types/convenience/hover.d.ts +3 -0
- package/dist/types/convenience/index.d.ts +3 -0
- package/dist/types/convenience/tab.d.ts +4 -0
- package/dist/types/document/UI.d.ts +42 -0
- package/dist/types/document/copySelection.d.ts +1 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -0
- package/dist/types/document/interceptor.d.ts +19 -0
- package/dist/types/document/patchFocus.d.ts +9 -0
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/cut.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +8 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/paste.d.ts +1 -0
- package/dist/types/event/behavior/registry.d.ts +8 -0
- package/dist/types/event/createEvent.d.ts +2 -0
- package/dist/types/event/dispatchEvent.d.ts +5 -0
- package/dist/types/event/eventMap.d.ts +265 -0
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +7 -0
- package/dist/types/event/input.d.ts +2 -0
- package/dist/types/event/radio.d.ts +4 -0
- package/dist/types/event/selection/getInputRange.d.ts +5 -0
- package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
- package/dist/types/event/selection/index.d.ts +15 -0
- package/dist/types/event/selection/modifySelection.d.ts +8 -0
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
- package/dist/types/event/selection/moveSelection.d.ts +4 -0
- package/dist/types/event/selection/resolveCaretPosition.d.ts +8 -0
- package/dist/types/event/selection/selectAll.d.ts +5 -0
- package/dist/types/event/selection/setSelection.d.ts +10 -0
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
- package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
- package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
- package/dist/types/event/types.d.ts +20 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/keyboard/index.d.ts +3 -0
- package/dist/types/keyboard/keyMap.d.ts +5 -0
- package/dist/types/keyboard/parseKeyDef.d.ts +17 -0
- package/dist/types/options.d.ts +115 -0
- package/dist/types/pointer/index.d.ts +28 -0
- package/dist/types/pointer/keyMap.d.ts +2 -0
- package/dist/types/pointer/parseKeyDef.d.ts +6 -0
- package/dist/types/setup/api.d.ts +23 -0
- package/dist/types/setup/directApi.d.ts +24 -0
- package/dist/types/setup/index.d.ts +22 -0
- package/dist/types/setup/setup.d.ts +44 -0
- package/dist/types/setup/wrapAsync.d.ts +4 -0
- package/dist/types/system/index.d.ts +10 -0
- package/dist/types/system/keyboard.d.ts +50 -0
- package/dist/types/system/pointer/buttons.d.ts +23 -0
- package/dist/types/system/pointer/device.d.ts +8 -0
- package/dist/types/system/pointer/index.d.ts +21 -0
- package/dist/types/system/pointer/mouse.d.ts +31 -0
- package/dist/types/system/pointer/pointer.d.ts +32 -0
- package/dist/types/system/pointer/shared.d.ts +20 -0
- package/dist/types/utility/clear.d.ts +2 -0
- package/dist/types/utility/index.d.ts +4 -0
- package/dist/types/utility/selectOptions.d.ts +3 -0
- package/dist/types/utility/type.d.ts +9 -0
- package/dist/types/utility/upload.d.ts +5 -0
- package/dist/types/utils/click/isClickableInput.d.ts +15 -0
- package/dist/types/utils/dataTransfer/Blob.d.ts +3 -0
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +11 -0
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/types/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/types/utils/edit/isEditable.d.ts +24 -0
- package/dist/types/utils/edit/maxLength.d.ts +14 -0
- package/dist/types/utils/edit/setFiles.d.ts +12 -0
- package/dist/types/utils/edit/timeValue.d.ts +4 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/types/utils/focus/getActiveElement.d.ts +2 -0
- package/dist/types/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/types/utils/focus/isFocusable.d.ts +1 -0
- package/dist/types/utils/focus/selection.d.ts +8 -0
- package/dist/types/utils/focus/selector.d.ts +1 -0
- package/dist/types/utils/index.d.ts +29 -0
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +21 -0
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -0
- package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
- package/dist/types/utils/misc/getWindow.d.ts +1 -0
- package/dist/types/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/types/utils/misc/isDisabled.d.ts +1 -0
- package/dist/types/utils/misc/isElementType.d.ts +5 -0
- package/dist/types/utils/misc/isVisible.d.ts +1 -0
- package/dist/types/utils/misc/level.d.ts +8 -0
- package/dist/types/utils/misc/wait.d.ts +2 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +19 -0
- package/package.json +131 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var level = require('../utils/misc/level.js');
|
|
5
|
+
var wait = require('../utils/misc/wait.js');
|
|
6
|
+
var parseKeyDef = require('./parseKeyDef.js');
|
|
7
|
+
|
|
8
|
+
async function pointer(input) {
|
|
9
|
+
const { pointerMap } = this.config;
|
|
10
|
+
const actions = [];
|
|
11
|
+
(Array.isArray(input) ? input : [
|
|
12
|
+
input
|
|
13
|
+
]).forEach((actionInput)=>{
|
|
14
|
+
if (typeof actionInput === 'string') {
|
|
15
|
+
actions.push(...parseKeyDef.parseKeyDef(pointerMap, actionInput));
|
|
16
|
+
} else if ('keys' in actionInput) {
|
|
17
|
+
actions.push(...parseKeyDef.parseKeyDef(pointerMap, actionInput.keys).map((i)=>({
|
|
18
|
+
...actionInput,
|
|
19
|
+
...i
|
|
20
|
+
})));
|
|
21
|
+
} else {
|
|
22
|
+
actions.push(actionInput);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
for(let i = 0; i < actions.length; i++){
|
|
26
|
+
await wait.wait(this.config);
|
|
27
|
+
await pointerAction(this, actions[i]);
|
|
28
|
+
}
|
|
29
|
+
this.system.pointer.resetClickCount();
|
|
30
|
+
}
|
|
31
|
+
async function pointerAction(instance, action) {
|
|
32
|
+
var _action_target, _action_coords, _action_node, _action_offset;
|
|
33
|
+
var _previousPosition_caret, _previousPosition_caret1;
|
|
34
|
+
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse';
|
|
35
|
+
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
|
|
36
|
+
const position = {
|
|
37
|
+
target: (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : getPrevTarget(instance, previousPosition),
|
|
38
|
+
coords: (_action_coords = action.coords) !== null && _action_coords !== void 0 ? _action_coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
|
|
39
|
+
caret: {
|
|
40
|
+
node: (_action_node = action.node) !== null && _action_node !== void 0 ? _action_node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret = previousPosition.caret) === null || _previousPosition_caret === void 0 ? void 0 : _previousPosition_caret.node,
|
|
41
|
+
offset: (_action_offset = action.offset) !== null && _action_offset !== void 0 ? _action_offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret1 = previousPosition.caret) === null || _previousPosition_caret1 === void 0 ? void 0 : _previousPosition_caret1.offset
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if ('keyDef' in action) {
|
|
45
|
+
if (instance.system.pointer.isKeyPressed(action.keyDef)) {
|
|
46
|
+
level.setLevelRef(instance, level.ApiLevel.Trigger);
|
|
47
|
+
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
48
|
+
}
|
|
49
|
+
if (!action.releasePrevious) {
|
|
50
|
+
level.setLevelRef(instance, level.ApiLevel.Trigger);
|
|
51
|
+
await instance.system.pointer.press(instance, action.keyDef, position);
|
|
52
|
+
if (action.releaseSelf) {
|
|
53
|
+
level.setLevelRef(instance, level.ApiLevel.Trigger);
|
|
54
|
+
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
level.setLevelRef(instance, level.ApiLevel.Trigger);
|
|
59
|
+
await instance.system.pointer.move(instance, pointerName, position);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function hasCaretPosition(action) {
|
|
63
|
+
var _ref, _action_target;
|
|
64
|
+
return !!((_ref = (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : action.node) !== null && _ref !== void 0 ? _ref : action.offset !== undefined);
|
|
65
|
+
}
|
|
66
|
+
function getPrevTarget(instance, position) {
|
|
67
|
+
var _position_target;
|
|
68
|
+
if (!position) {
|
|
69
|
+
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
70
|
+
}
|
|
71
|
+
return (_position_target = position.target) !== null && _position_target !== void 0 ? _position_target : instance.config.document.body;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.pointer = pointer;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const defaultKeyMap = [
|
|
4
|
+
{
|
|
5
|
+
name: 'MouseLeft',
|
|
6
|
+
pointerType: 'mouse',
|
|
7
|
+
button: 'primary'
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: 'MouseRight',
|
|
11
|
+
pointerType: 'mouse',
|
|
12
|
+
button: 'secondary'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'MouseMiddle',
|
|
16
|
+
pointerType: 'mouse',
|
|
17
|
+
button: 'auxiliary'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'TouchA',
|
|
21
|
+
pointerType: 'touch'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'TouchB',
|
|
25
|
+
pointerType: 'touch'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'TouchC',
|
|
29
|
+
pointerType: 'touch'
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
exports.defaultKeyMap = defaultKeyMap;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js');
|
|
5
|
+
|
|
6
|
+
function parseKeyDef(pointerMap, keys) {
|
|
7
|
+
const defs = [];
|
|
8
|
+
do {
|
|
9
|
+
const { descriptor, consumedLength, releasePrevious, releaseSelf = true } = readNextDescriptor.readNextDescriptor(keys, 'pointer');
|
|
10
|
+
const keyDef = pointerMap.find((p)=>p.name === descriptor);
|
|
11
|
+
if (keyDef) {
|
|
12
|
+
defs.push({
|
|
13
|
+
keyDef,
|
|
14
|
+
releasePrevious,
|
|
15
|
+
releaseSelf
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
keys = keys.slice(consumedLength);
|
|
19
|
+
}while (keys)
|
|
20
|
+
return defs;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.parseKeyDef = parseKeyDef;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var click = require('../convenience/click.js');
|
|
4
|
+
var hover = require('../convenience/hover.js');
|
|
5
|
+
var tab = require('../convenience/tab.js');
|
|
6
|
+
var index$1 = require('../keyboard/index.js');
|
|
7
|
+
var copy = require('../clipboard/copy.js');
|
|
8
|
+
var cut = require('../clipboard/cut.js');
|
|
9
|
+
var paste = require('../clipboard/paste.js');
|
|
10
|
+
var index = require('../pointer/index.js');
|
|
11
|
+
var clear = require('../utility/clear.js');
|
|
12
|
+
var selectOptions = require('../utility/selectOptions.js');
|
|
13
|
+
var type = require('../utility/type.js');
|
|
14
|
+
var upload = require('../utility/upload.js');
|
|
15
|
+
|
|
16
|
+
const userEventApi = {
|
|
17
|
+
click: click.click,
|
|
18
|
+
dblClick: click.dblClick,
|
|
19
|
+
tripleClick: click.tripleClick,
|
|
20
|
+
hover: hover.hover,
|
|
21
|
+
unhover: hover.unhover,
|
|
22
|
+
tab: tab.tab,
|
|
23
|
+
keyboard: index$1.keyboard,
|
|
24
|
+
copy: copy.copy,
|
|
25
|
+
cut: cut.cut,
|
|
26
|
+
paste: paste.paste,
|
|
27
|
+
pointer: index.pointer,
|
|
28
|
+
clear: clear.clear,
|
|
29
|
+
deselectOptions: selectOptions.deselectOptions,
|
|
30
|
+
selectOptions: selectOptions.selectOptions,
|
|
31
|
+
type: type.type,
|
|
32
|
+
upload: upload.upload
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.userEventApi = userEventApi;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var setup = require('./setup.js');
|
|
4
|
+
|
|
5
|
+
function clear(element) {
|
|
6
|
+
return setup.setupDirect().api.clear(element);
|
|
7
|
+
}
|
|
8
|
+
function click(element, options = {}) {
|
|
9
|
+
return setup.setupDirect(options, element).api.click(element);
|
|
10
|
+
}
|
|
11
|
+
function copy(options = {}) {
|
|
12
|
+
return setup.setupDirect(options).api.copy();
|
|
13
|
+
}
|
|
14
|
+
function cut(options = {}) {
|
|
15
|
+
return setup.setupDirect(options).api.cut();
|
|
16
|
+
}
|
|
17
|
+
function dblClick(element, options = {}) {
|
|
18
|
+
return setup.setupDirect(options).api.dblClick(element);
|
|
19
|
+
}
|
|
20
|
+
function deselectOptions(select, values, options = {}) {
|
|
21
|
+
return setup.setupDirect(options).api.deselectOptions(select, values);
|
|
22
|
+
}
|
|
23
|
+
function hover(element, options = {}) {
|
|
24
|
+
return setup.setupDirect(options).api.hover(element);
|
|
25
|
+
}
|
|
26
|
+
async function keyboard(text, options = {}) {
|
|
27
|
+
const { api, system } = setup.setupDirect(options);
|
|
28
|
+
return api.keyboard(text).then(()=>system);
|
|
29
|
+
}
|
|
30
|
+
async function pointer(input, options = {}) {
|
|
31
|
+
const { api, system } = setup.setupDirect(options);
|
|
32
|
+
return api.pointer(input).then(()=>system);
|
|
33
|
+
}
|
|
34
|
+
function paste(clipboardData, options) {
|
|
35
|
+
return setup.setupDirect(options).api.paste(clipboardData);
|
|
36
|
+
}
|
|
37
|
+
function selectOptions(select, values, options = {}) {
|
|
38
|
+
return setup.setupDirect(options).api.selectOptions(select, values);
|
|
39
|
+
}
|
|
40
|
+
function tripleClick(element, options = {}) {
|
|
41
|
+
return setup.setupDirect(options).api.tripleClick(element);
|
|
42
|
+
}
|
|
43
|
+
function type(element, text, options = {}) {
|
|
44
|
+
return setup.setupDirect(options, element).api.type(element, text, options);
|
|
45
|
+
}
|
|
46
|
+
function unhover(element, options = {}) {
|
|
47
|
+
const { api, system } = setup.setupDirect(options);
|
|
48
|
+
system.pointer.setMousePosition({
|
|
49
|
+
target: element
|
|
50
|
+
});
|
|
51
|
+
return api.unhover(element);
|
|
52
|
+
}
|
|
53
|
+
function upload(element, fileOrFiles, options = {}) {
|
|
54
|
+
return setup.setupDirect(options).api.upload(element, fileOrFiles);
|
|
55
|
+
}
|
|
56
|
+
function tab(options = {}) {
|
|
57
|
+
return setup.setupDirect().api.tab(options);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.clear = clear;
|
|
61
|
+
exports.click = click;
|
|
62
|
+
exports.copy = copy;
|
|
63
|
+
exports.cut = cut;
|
|
64
|
+
exports.dblClick = dblClick;
|
|
65
|
+
exports.deselectOptions = deselectOptions;
|
|
66
|
+
exports.hover = hover;
|
|
67
|
+
exports.keyboard = keyboard;
|
|
68
|
+
exports.paste = paste;
|
|
69
|
+
exports.pointer = pointer;
|
|
70
|
+
exports.selectOptions = selectOptions;
|
|
71
|
+
exports.tab = tab;
|
|
72
|
+
exports.tripleClick = tripleClick;
|
|
73
|
+
exports.type = type;
|
|
74
|
+
exports.unhover = unhover;
|
|
75
|
+
exports.upload = upload;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var patchFocus = require('../document/patchFocus.js');
|
|
4
|
+
var prepareDocument = require('../document/prepareDocument.js');
|
|
5
|
+
var dispatchEvent = require('../event/dispatchEvent.js');
|
|
6
|
+
var Clipboard = require('../utils/dataTransfer/Clipboard.js');
|
|
7
|
+
var getWindow = require('../utils/misc/getWindow.js');
|
|
8
|
+
var getDocumentFromNode = require('../utils/misc/getDocumentFromNode.js');
|
|
9
|
+
var level = require('../utils/misc/level.js');
|
|
10
|
+
var wait = require('../utils/misc/wait.js');
|
|
11
|
+
var options = require('../options.js');
|
|
12
|
+
require('@testing-library/dom');
|
|
13
|
+
var keyMap$1 = require('../keyboard/keyMap.js');
|
|
14
|
+
var keyMap = require('../pointer/keyMap.js');
|
|
15
|
+
var index = require('../system/index.js');
|
|
16
|
+
var api = require('./api.js');
|
|
17
|
+
var wrapAsync = require('./wrapAsync.js');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Default options applied when API is called per `userEvent.anyApi()`
|
|
21
|
+
*/ const defaultOptionsDirect = {
|
|
22
|
+
applyAccept: true,
|
|
23
|
+
autoModify: true,
|
|
24
|
+
delay: 0,
|
|
25
|
+
document: globalThis.document,
|
|
26
|
+
keyboardMap: keyMap$1.defaultKeyMap,
|
|
27
|
+
pointerMap: keyMap.defaultKeyMap,
|
|
28
|
+
pointerEventsCheck: options.PointerEventsCheckLevel.EachApiCall,
|
|
29
|
+
skipAutoClose: false,
|
|
30
|
+
skipClick: false,
|
|
31
|
+
skipHover: false,
|
|
32
|
+
writeToClipboard: false,
|
|
33
|
+
advanceTimers: ()=>Promise.resolve()
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Default options applied when API is called per `userEvent().anyApi()`
|
|
37
|
+
*/ const defaultOptionsSetup = {
|
|
38
|
+
...defaultOptionsDirect,
|
|
39
|
+
writeToClipboard: true
|
|
40
|
+
};
|
|
41
|
+
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
42
|
+
const document = getDocument(options, node, defaults);
|
|
43
|
+
return {
|
|
44
|
+
...defaults,
|
|
45
|
+
...options,
|
|
46
|
+
document
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Start a "session" with userEvent.
|
|
51
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
52
|
+
*/ function setupMain(options = {}) {
|
|
53
|
+
var _config_document_defaultView;
|
|
54
|
+
const config = createConfig(options);
|
|
55
|
+
prepareDocument.prepareDocument(config.document);
|
|
56
|
+
patchFocus.patchFocus(getWindow.getWindow(config.document).HTMLElement);
|
|
57
|
+
const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !== void 0 ? _config_document_defaultView : /* istanbul ignore next */ globalThis.window;
|
|
58
|
+
Clipboard.attachClipboardStubToView(view);
|
|
59
|
+
return createInstance(config).api;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Setup in direct call per `userEvent.anyApi()`
|
|
63
|
+
*/ function setupDirect({ keyboardState, pointerState, ...options } = {}, node) {
|
|
64
|
+
var _ref;
|
|
65
|
+
const config = createConfig(options, defaultOptionsDirect, node);
|
|
66
|
+
prepareDocument.prepareDocument(config.document);
|
|
67
|
+
patchFocus.patchFocus(getWindow.getWindow(config.document).HTMLElement);
|
|
68
|
+
const system = (_ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && _ref !== void 0 ? _ref : new index.System();
|
|
69
|
+
return {
|
|
70
|
+
api: createInstance(config, system).api,
|
|
71
|
+
system
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a set of callbacks with different default settings but the same state.
|
|
76
|
+
*/ function setupSub(options) {
|
|
77
|
+
return createInstance({
|
|
78
|
+
...this.config,
|
|
79
|
+
...options
|
|
80
|
+
}, this.system).api;
|
|
81
|
+
}
|
|
82
|
+
function wrapAndBindImpl(instance, impl) {
|
|
83
|
+
function method(...args) {
|
|
84
|
+
level.setLevelRef(instance, level.ApiLevel.Call);
|
|
85
|
+
return wrapAsync.wrapAsync(()=>impl.apply(instance, args).then(async (ret)=>{
|
|
86
|
+
await wait.wait(instance.config);
|
|
87
|
+
return ret;
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
Object.defineProperty(method, 'name', {
|
|
91
|
+
get: ()=>impl.name
|
|
92
|
+
});
|
|
93
|
+
return method;
|
|
94
|
+
}
|
|
95
|
+
function createInstance(config, system = new index.System()) {
|
|
96
|
+
const instance = {};
|
|
97
|
+
Object.assign(instance, {
|
|
98
|
+
config,
|
|
99
|
+
dispatchEvent: dispatchEvent.dispatchEvent.bind(instance),
|
|
100
|
+
dispatchUIEvent: dispatchEvent.dispatchUIEvent.bind(instance),
|
|
101
|
+
system,
|
|
102
|
+
levelRefs: {},
|
|
103
|
+
...api.userEventApi
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
instance,
|
|
107
|
+
api: {
|
|
108
|
+
...Object.fromEntries(Object.entries(api.userEventApi).map(([name, api])=>[
|
|
109
|
+
name,
|
|
110
|
+
wrapAndBindImpl(instance, api)
|
|
111
|
+
])),
|
|
112
|
+
setup: setupSub.bind(instance)
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function getDocument(options, node, defaults) {
|
|
117
|
+
var _ref, _options_document;
|
|
118
|
+
return (_ref = (_options_document = options.document) !== null && _options_document !== void 0 ? _options_document : node && getDocumentFromNode.getDocumentFromNode(node)) !== null && _ref !== void 0 ? _ref : defaults.document;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
exports.createConfig = createConfig;
|
|
122
|
+
exports.createInstance = createInstance;
|
|
123
|
+
exports.setupDirect = setupDirect;
|
|
124
|
+
exports.setupMain = setupMain;
|
|
125
|
+
exports.setupSub = setupSub;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var keyboard = require('./keyboard.js');
|
|
4
|
+
var index = require('./pointer/index.js');
|
|
5
|
+
|
|
6
|
+
function _define_property(obj, key, value) {
|
|
7
|
+
if (key in obj) {
|
|
8
|
+
Object.defineProperty(obj, key, {
|
|
9
|
+
value: value,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
} else obj[key] = value;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
19
|
+
*/ class System {
|
|
20
|
+
getUIEventModifiers() {
|
|
21
|
+
return {
|
|
22
|
+
altKey: this.keyboard.modifiers.Alt,
|
|
23
|
+
ctrlKey: this.keyboard.modifiers.Control,
|
|
24
|
+
metaKey: this.keyboard.modifiers.Meta,
|
|
25
|
+
shiftKey: this.keyboard.modifiers.Shift,
|
|
26
|
+
modifierAltGraph: this.keyboard.modifiers.AltGraph,
|
|
27
|
+
modifierCapsLock: this.keyboard.modifiers.CapsLock,
|
|
28
|
+
modifierFn: this.keyboard.modifiers.Fn,
|
|
29
|
+
modifierFnLock: this.keyboard.modifiers.FnLock,
|
|
30
|
+
modifierNumLock: this.keyboard.modifiers.NumLock,
|
|
31
|
+
modifierScrollLock: this.keyboard.modifiers.ScrollLock,
|
|
32
|
+
modifierSymbol: this.keyboard.modifiers.Symbol,
|
|
33
|
+
modifierSymbolLock: this.keyboard.modifiers.SymbolLock
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
constructor(){
|
|
37
|
+
_define_property(this, "keyboard", new keyboard.KeyboardHost(this));
|
|
38
|
+
_define_property(this, "pointer", new index.PointerHost(this));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.System = System;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var getActiveElement = require('../utils/focus/getActiveElement.js');
|
|
5
|
+
|
|
6
|
+
function _define_property(obj, key, value) {
|
|
7
|
+
if (key in obj) {
|
|
8
|
+
Object.defineProperty(obj, key, {
|
|
9
|
+
value: value,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
} else obj[key] = value;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
var DOM_KEY_LOCATION = /*#__PURE__*/ function(DOM_KEY_LOCATION) {
|
|
18
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["STANDARD"] = 0] = "STANDARD";
|
|
19
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["LEFT"] = 1] = "LEFT";
|
|
20
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["RIGHT"] = 2] = "RIGHT";
|
|
21
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["NUMPAD"] = 3] = "NUMPAD";
|
|
22
|
+
return DOM_KEY_LOCATION;
|
|
23
|
+
}({});
|
|
24
|
+
const modifierKeys = [
|
|
25
|
+
'Alt',
|
|
26
|
+
'AltGraph',
|
|
27
|
+
'Control',
|
|
28
|
+
'Fn',
|
|
29
|
+
'Meta',
|
|
30
|
+
'Shift',
|
|
31
|
+
'Symbol'
|
|
32
|
+
];
|
|
33
|
+
function isModifierKey(key) {
|
|
34
|
+
return modifierKeys.includes(key);
|
|
35
|
+
}
|
|
36
|
+
const modifierLocks = [
|
|
37
|
+
'CapsLock',
|
|
38
|
+
'FnLock',
|
|
39
|
+
'NumLock',
|
|
40
|
+
'ScrollLock',
|
|
41
|
+
'SymbolLock'
|
|
42
|
+
];
|
|
43
|
+
function isModifierLock(key) {
|
|
44
|
+
return modifierLocks.includes(key);
|
|
45
|
+
}
|
|
46
|
+
class KeyboardHost {
|
|
47
|
+
isKeyPressed(keyDef) {
|
|
48
|
+
return this.pressed.has(String(keyDef.code));
|
|
49
|
+
}
|
|
50
|
+
getPressedKeys() {
|
|
51
|
+
return this.pressed.values().map((p)=>p.keyDef);
|
|
52
|
+
}
|
|
53
|
+
/** Press a key */ async keydown(instance, keyDef) {
|
|
54
|
+
const key = String(keyDef.key);
|
|
55
|
+
const code = String(keyDef.code);
|
|
56
|
+
const target = getActiveElement.getActiveElementOrBody(instance.config.document);
|
|
57
|
+
this.setKeydownTarget(target);
|
|
58
|
+
this.pressed.add(code, keyDef);
|
|
59
|
+
if (isModifierKey(key)) {
|
|
60
|
+
this.modifiers[key] = true;
|
|
61
|
+
}
|
|
62
|
+
const unprevented = instance.dispatchUIEvent(target, 'keydown', {
|
|
63
|
+
key,
|
|
64
|
+
code
|
|
65
|
+
});
|
|
66
|
+
if (isModifierLock(key) && !this.modifiers[key]) {
|
|
67
|
+
this.modifiers[key] = true;
|
|
68
|
+
this.modifierLockStart[key] = true;
|
|
69
|
+
}
|
|
70
|
+
if (unprevented) {
|
|
71
|
+
this.pressed.setUnprevented(code);
|
|
72
|
+
}
|
|
73
|
+
if (unprevented && this.hasKeyPress(key)) {
|
|
74
|
+
instance.dispatchUIEvent(getActiveElement.getActiveElementOrBody(instance.config.document), 'keypress', {
|
|
75
|
+
key,
|
|
76
|
+
code,
|
|
77
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Release a key */ async keyup(instance, keyDef) {
|
|
82
|
+
const key = String(keyDef.key);
|
|
83
|
+
const code = String(keyDef.code);
|
|
84
|
+
const unprevented = this.pressed.isUnprevented(code);
|
|
85
|
+
this.pressed.delete(code);
|
|
86
|
+
if (isModifierKey(key) && !this.pressed.values().find((p)=>p.keyDef.key === key)) {
|
|
87
|
+
this.modifiers[key] = false;
|
|
88
|
+
}
|
|
89
|
+
instance.dispatchUIEvent(getActiveElement.getActiveElementOrBody(instance.config.document), 'keyup', {
|
|
90
|
+
key,
|
|
91
|
+
code
|
|
92
|
+
}, !unprevented);
|
|
93
|
+
if (isModifierLock(key) && this.modifiers[key]) {
|
|
94
|
+
if (this.modifierLockStart[key]) {
|
|
95
|
+
this.modifierLockStart[key] = false;
|
|
96
|
+
} else {
|
|
97
|
+
this.modifiers[key] = false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
setKeydownTarget(target) {
|
|
102
|
+
if (target !== this.lastKeydownTarget) {
|
|
103
|
+
this.carryChar = '';
|
|
104
|
+
}
|
|
105
|
+
this.lastKeydownTarget = target;
|
|
106
|
+
}
|
|
107
|
+
hasKeyPress(key) {
|
|
108
|
+
return (key.length === 1 || key === 'Enter') && !this.modifiers.Control && !this.modifiers.Alt;
|
|
109
|
+
}
|
|
110
|
+
constructor(system){
|
|
111
|
+
_define_property(this, "system", void 0);
|
|
112
|
+
_define_property(this, "modifiers", {
|
|
113
|
+
Alt: false,
|
|
114
|
+
AltGraph: false,
|
|
115
|
+
CapsLock: false,
|
|
116
|
+
Control: false,
|
|
117
|
+
Fn: false,
|
|
118
|
+
FnLock: false,
|
|
119
|
+
Meta: false,
|
|
120
|
+
NumLock: false,
|
|
121
|
+
ScrollLock: false,
|
|
122
|
+
Shift: false,
|
|
123
|
+
Symbol: false,
|
|
124
|
+
SymbolLock: false
|
|
125
|
+
});
|
|
126
|
+
_define_property(this, "pressed", new class {
|
|
127
|
+
add(code, keyDef) {
|
|
128
|
+
var _this_registry, _code, _;
|
|
129
|
+
(_ = (_this_registry = this.registry)[_code = code]) !== null && _ !== void 0 ? _ : _this_registry[_code] = {
|
|
130
|
+
keyDef,
|
|
131
|
+
unpreventedDefault: false
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
has(code) {
|
|
135
|
+
return !!this.registry[code];
|
|
136
|
+
}
|
|
137
|
+
setUnprevented(code) {
|
|
138
|
+
const o = this.registry[code];
|
|
139
|
+
if (o) {
|
|
140
|
+
o.unpreventedDefault = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
isUnprevented(code) {
|
|
144
|
+
var _this_registry_code;
|
|
145
|
+
return !!((_this_registry_code = this.registry[code]) === null || _this_registry_code === void 0 ? void 0 : _this_registry_code.unpreventedDefault);
|
|
146
|
+
}
|
|
147
|
+
delete(code) {
|
|
148
|
+
delete this.registry[code];
|
|
149
|
+
}
|
|
150
|
+
values() {
|
|
151
|
+
return Object.values(this.registry);
|
|
152
|
+
}
|
|
153
|
+
constructor(){
|
|
154
|
+
_define_property(this, "registry", {});
|
|
155
|
+
}
|
|
156
|
+
}());
|
|
157
|
+
_define_property(this, "carryChar", '');
|
|
158
|
+
_define_property(this, "lastKeydownTarget", undefined);
|
|
159
|
+
_define_property(this, "modifierLockStart", {});
|
|
160
|
+
this.system = system;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
exports.DOM_KEY_LOCATION = DOM_KEY_LOCATION;
|
|
165
|
+
exports.KeyboardHost = KeyboardHost;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) {
|
|
5
|
+
Object.defineProperty(obj, key, {
|
|
6
|
+
value: value,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true
|
|
10
|
+
});
|
|
11
|
+
} else obj[key] = value;
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
class Buttons {
|
|
15
|
+
getButtons() {
|
|
16
|
+
let v = 0;
|
|
17
|
+
for (const button of Object.keys(this.pressed)){
|
|
18
|
+
v |= 2 ** Number(button);
|
|
19
|
+
}
|
|
20
|
+
return v;
|
|
21
|
+
}
|
|
22
|
+
down(keyDef) {
|
|
23
|
+
const button = getMouseButtonId(keyDef.button);
|
|
24
|
+
if (button in this.pressed) {
|
|
25
|
+
this.pressed[button].push(keyDef);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
this.pressed[button] = [
|
|
29
|
+
keyDef
|
|
30
|
+
];
|
|
31
|
+
return button;
|
|
32
|
+
}
|
|
33
|
+
up(keyDef) {
|
|
34
|
+
const button = getMouseButtonId(keyDef.button);
|
|
35
|
+
if (button in this.pressed) {
|
|
36
|
+
this.pressed[button] = this.pressed[button].filter((k)=>k.name !== keyDef.name);
|
|
37
|
+
if (this.pressed[button].length === 0) {
|
|
38
|
+
delete this.pressed[button];
|
|
39
|
+
return button;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
constructor(){
|
|
45
|
+
_define_property(this, "pressed", {});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const MouseButton = {
|
|
49
|
+
primary: 0,
|
|
50
|
+
secondary: 1,
|
|
51
|
+
auxiliary: 2,
|
|
52
|
+
back: 3,
|
|
53
|
+
X1: 3,
|
|
54
|
+
forward: 4,
|
|
55
|
+
X2: 4
|
|
56
|
+
};
|
|
57
|
+
function getMouseButtonId(button = 0) {
|
|
58
|
+
if (button in MouseButton) {
|
|
59
|
+
return MouseButton[button];
|
|
60
|
+
}
|
|
61
|
+
return Number(button);
|
|
62
|
+
}
|
|
63
|
+
// On the `MouseEvent.button` property auxiliary and secondary button are flipped compared to `MouseEvent.buttons`.
|
|
64
|
+
const MouseButtonFlip = {
|
|
65
|
+
1: 2,
|
|
66
|
+
2: 1
|
|
67
|
+
};
|
|
68
|
+
function getMouseEventButton(button) {
|
|
69
|
+
button = getMouseButtonId(button);
|
|
70
|
+
if (button in MouseButtonFlip) {
|
|
71
|
+
return MouseButtonFlip[button];
|
|
72
|
+
}
|
|
73
|
+
return button;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.Buttons = Buttons;
|
|
77
|
+
exports.MouseButton = MouseButton;
|
|
78
|
+
exports.MouseButtonFlip = MouseButtonFlip;
|
|
79
|
+
exports.getMouseButtonId = getMouseButtonId;
|
|
80
|
+
exports.getMouseEventButton = getMouseEventButton;
|