@testing-library/user-event 14.5.2 → 14.6.1
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/cjs/clipboard/copy.js +1 -7
- package/dist/cjs/clipboard/cut.js +1 -7
- package/dist/cjs/clipboard/paste.js +2 -8
- package/dist/cjs/convenience/hover.js +0 -5
- package/dist/cjs/document/UI.js +3 -3
- package/dist/cjs/document/copySelection.js +0 -6
- package/dist/cjs/document/getValueOrTextContent.js +0 -6
- package/dist/cjs/document/interceptor.js +5 -11
- package/dist/cjs/document/patchFocus.js +104 -0
- package/dist/cjs/document/prepareDocument.js +1 -7
- package/dist/cjs/document/trackValue.js +2 -8
- package/dist/cjs/event/behavior/click.js +3 -9
- package/dist/cjs/event/behavior/cut.js +0 -5
- package/dist/cjs/event/behavior/keydown.js +5 -10
- package/dist/cjs/event/behavior/keypress.js +2 -7
- package/dist/cjs/event/behavior/keyup.js +1 -6
- package/dist/cjs/event/behavior/paste.js +1 -6
- package/dist/cjs/event/createEvent.js +40 -33
- package/dist/cjs/event/dispatchEvent.js +1 -1
- package/dist/cjs/event/eventMap.js +32 -0
- package/dist/cjs/event/focus.js +5 -9
- package/dist/cjs/event/index.js +0 -6
- package/dist/cjs/event/input.js +2 -7
- package/dist/cjs/event/radio.js +1 -6
- package/dist/cjs/event/selection/getInputRange.js +1 -1
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +2 -8
- package/dist/cjs/event/selection/modifySelection.js +1 -7
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +2 -8
- package/dist/cjs/event/selection/moveSelection.js +1 -7
- package/dist/cjs/event/selection/resolveCaretPosition.js +4 -10
- package/dist/cjs/event/selection/selectAll.js +3 -9
- package/dist/cjs/event/selection/setSelection.js +1 -7
- package/dist/cjs/event/selection/setSelectionPerMouse.js +7 -13
- package/dist/cjs/event/selection/setSelectionRange.js +1 -7
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +6 -8
- package/dist/cjs/index.js +1 -4
- package/dist/cjs/keyboard/index.js +0 -6
- package/dist/cjs/keyboard/keyMap.js +23 -1
- package/dist/cjs/keyboard/parseKeyDef.js +4 -9
- package/dist/cjs/options.js +5 -3
- package/dist/cjs/pointer/index.js +6 -11
- package/dist/cjs/pointer/parseKeyDef.js +0 -5
- package/dist/cjs/setup/setup.js +7 -7
- package/dist/cjs/system/keyboard.js +47 -25
- package/dist/cjs/system/pointer/index.js +45 -50
- package/dist/cjs/system/pointer/mouse.js +24 -29
- package/dist/cjs/system/pointer/pointer.js +24 -19
- package/dist/cjs/system/pointer/shared.js +2 -2
- package/dist/cjs/utility/clear.js +0 -5
- package/dist/cjs/utility/selectOptions.js +1 -6
- package/dist/cjs/utility/type.js +1 -7
- package/dist/cjs/utility/upload.js +13 -15
- package/dist/cjs/utils/click/isClickableInput.js +3 -3
- package/dist/cjs/utils/dataTransfer/Clipboard.js +5 -6
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +6 -10
- package/dist/cjs/utils/edit/isEditable.js +3 -3
- package/dist/cjs/utils/edit/maxLength.js +4 -4
- package/dist/cjs/utils/edit/setFiles.js +2 -2
- package/dist/cjs/utils/focus/cursor.js +2 -2
- package/dist/cjs/utils/focus/getActiveElement.js +2 -2
- package/dist/cjs/utils/index.js +1 -4
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +6 -6
- package/dist/cjs/utils/misc/getWindow.js +1 -1
- package/dist/cjs/utils/misc/isDisabled.js +1 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +4 -3
- package/dist/cjs/utils/pointer/cssPointerEvents.js +11 -11
- package/dist/esm/clipboard/copy.js +1 -7
- package/dist/esm/clipboard/cut.js +1 -7
- package/dist/esm/clipboard/paste.js +2 -8
- package/dist/esm/convenience/hover.js +0 -5
- package/dist/esm/document/UI.js +3 -3
- package/dist/esm/document/copySelection.js +0 -6
- package/dist/esm/document/getValueOrTextContent.js +0 -6
- package/dist/esm/document/interceptor.js +5 -11
- package/dist/esm/document/patchFocus.js +101 -0
- package/dist/esm/document/prepareDocument.js +1 -7
- package/dist/esm/document/trackValue.js +2 -8
- package/dist/esm/event/behavior/click.js +3 -9
- package/dist/esm/event/behavior/cut.js +0 -5
- package/dist/esm/event/behavior/keydown.js +5 -10
- package/dist/esm/event/behavior/keypress.js +2 -7
- package/dist/esm/event/behavior/keyup.js +1 -6
- package/dist/esm/event/behavior/paste.js +1 -6
- package/dist/esm/event/createEvent.js +40 -33
- package/dist/esm/event/dispatchEvent.js +1 -1
- package/dist/esm/event/eventMap.js +32 -0
- package/dist/esm/event/focus.js +5 -9
- package/dist/esm/event/index.js +0 -6
- package/dist/esm/event/input.js +2 -7
- package/dist/esm/event/radio.js +1 -6
- package/dist/esm/event/selection/getInputRange.js +1 -1
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +2 -8
- package/dist/esm/event/selection/modifySelection.js +1 -7
- package/dist/esm/event/selection/modifySelectionPerMouse.js +2 -8
- package/dist/esm/event/selection/moveSelection.js +1 -7
- package/dist/esm/event/selection/resolveCaretPosition.js +4 -10
- package/dist/esm/event/selection/selectAll.js +3 -9
- package/dist/esm/event/selection/setSelection.js +1 -7
- package/dist/esm/event/selection/setSelectionPerMouse.js +7 -13
- package/dist/esm/event/selection/setSelectionRange.js +1 -7
- package/dist/esm/event/selection/updateSelectionOnFocus.js +6 -8
- package/dist/esm/keyboard/index.js +0 -6
- package/dist/esm/keyboard/keyMap.js +23 -1
- package/dist/esm/keyboard/parseKeyDef.js +4 -9
- package/dist/esm/options.js +3 -3
- package/dist/esm/pointer/index.js +6 -11
- package/dist/esm/pointer/parseKeyDef.js +0 -5
- package/dist/esm/setup/setup.js +7 -7
- package/dist/esm/system/keyboard.js +46 -25
- package/dist/esm/system/pointer/index.js +45 -50
- package/dist/esm/system/pointer/mouse.js +24 -29
- package/dist/esm/system/pointer/pointer.js +24 -19
- package/dist/esm/system/pointer/shared.js +2 -2
- package/dist/esm/utility/clear.js +0 -5
- package/dist/esm/utility/selectOptions.js +1 -6
- package/dist/esm/utility/type.js +1 -7
- package/dist/esm/utility/upload.js +13 -15
- package/dist/esm/utils/click/isClickableInput.js +3 -3
- package/dist/esm/utils/dataTransfer/Clipboard.js +5 -6
- package/dist/esm/utils/dataTransfer/DataTransfer.js +6 -10
- package/dist/esm/utils/edit/isEditable.js +3 -3
- package/dist/esm/utils/edit/maxLength.js +4 -4
- package/dist/esm/utils/edit/setFiles.js +2 -2
- package/dist/esm/utils/focus/cursor.js +2 -2
- package/dist/esm/utils/focus/getActiveElement.js +2 -2
- package/dist/esm/utils/keyDef/readNextDescriptor.js +6 -6
- package/dist/esm/utils/misc/getWindow.js +1 -1
- package/dist/esm/utils/misc/isDisabled.js +1 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +3 -3
- package/dist/esm/utils/pointer/cssPointerEvents.js +11 -11
- package/dist/types/document/patchFocus.d.ts +9 -0
- package/dist/types/event/eventMap.d.ts +32 -0
- package/dist/types/event/types.d.ts +1 -1
- package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
- package/dist/types/options.d.ts +1 -1
- package/dist/types/system/keyboard.d.ts +1 -4
- package/dist/types/system/pointer/mouse.d.ts +9 -4
- package/dist/types/system/pointer/pointer.d.ts +7 -5
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import '../../utils/click/isClickableInput.js';
|
|
2
1
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
2
|
import { getContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
4
|
-
import '../../utils/edit/isEditable.js';
|
|
5
|
-
import '../../utils/edit/maxLength.js';
|
|
6
3
|
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
7
|
-
import '../../utils/keyDef/readNextDescriptor.js';
|
|
8
|
-
import '../../utils/misc/level.js';
|
|
9
|
-
import '../../options.js';
|
|
10
4
|
|
|
5
|
+
// The browser implementation seems to have changed.
|
|
6
|
+
// When focus is inside <input type="text"/>,
|
|
7
|
+
// Chrome updates Selection to be collapsed at the position of the input element.
|
|
8
|
+
// TODO: update implementation to match that of current browsers
|
|
11
9
|
/**
|
|
12
10
|
* Reset the Document Selection when moving focus into an element
|
|
13
11
|
* with own selection implementation.
|
|
14
12
|
*/ function updateSelectionOnFocus(element) {
|
|
15
13
|
const selection = element.ownerDocument.getSelection();
|
|
16
|
-
/* istanbul ignore if */ if (!(selection === null || selection ===
|
|
14
|
+
/* istanbul ignore if */ if (!(selection === null || selection === undefined ? undefined : selection.focusNode)) {
|
|
17
15
|
return;
|
|
18
16
|
}
|
|
19
17
|
// If the focus moves inside an element with own selection implementation,
|
|
@@ -28,7 +26,7 @@ import '../../options.js';
|
|
|
28
26
|
if (contenteditable) {
|
|
29
27
|
if (!selection.isCollapsed) {
|
|
30
28
|
var _contenteditable_firstChild;
|
|
31
|
-
const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild ===
|
|
29
|
+
const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === undefined ? undefined : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
32
30
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
33
31
|
}
|
|
34
32
|
} else {
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import '../utils/click/isClickableInput.js';
|
|
2
1
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../utils/edit/isEditable.js';
|
|
4
|
-
import '../utils/edit/maxLength.js';
|
|
5
|
-
import '../utils/keyDef/readNextDescriptor.js';
|
|
6
|
-
import '../utils/misc/level.js';
|
|
7
2
|
import { wait } from '../utils/misc/wait.js';
|
|
8
|
-
import '../options.js';
|
|
9
3
|
import { parseKeyDef } from './parseKeyDef.js';
|
|
10
4
|
|
|
11
5
|
async function keyboard(text) {
|
|
@@ -3,7 +3,7 @@ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Mapping for a default US-104-QWERTY keyboard
|
|
5
5
|
*/ const defaultKeyMap = [
|
|
6
|
-
// alphanumeric
|
|
6
|
+
// alphanumeric block - writing system
|
|
7
7
|
...'0123456789'.split('').map((c)=>({
|
|
8
8
|
code: `Digit${c}`,
|
|
9
9
|
key: c
|
|
@@ -22,6 +22,24 @@ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
|
|
|
22
22
|
key: c,
|
|
23
23
|
shiftKey: true
|
|
24
24
|
})),
|
|
25
|
+
{
|
|
26
|
+
code: 'BracketLeft',
|
|
27
|
+
key: '['
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
code: 'BracketLeft',
|
|
31
|
+
key: '{',
|
|
32
|
+
shiftKey: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
code: 'BracketRight',
|
|
36
|
+
key: ']'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: 'BracketRight',
|
|
40
|
+
key: '}',
|
|
41
|
+
shiftKey: true
|
|
42
|
+
},
|
|
25
43
|
// alphanumeric block - functional
|
|
26
44
|
{
|
|
27
45
|
code: 'Space',
|
|
@@ -77,6 +95,10 @@ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
|
|
|
77
95
|
key: 'OS',
|
|
78
96
|
location: DOM_KEY_LOCATION.RIGHT
|
|
79
97
|
},
|
|
98
|
+
{
|
|
99
|
+
code: 'ContextMenu',
|
|
100
|
+
key: 'ContextMenu'
|
|
101
|
+
},
|
|
80
102
|
{
|
|
81
103
|
code: 'Tab',
|
|
82
104
|
key: 'Tab'
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import '../utils/click/isClickableInput.js';
|
|
2
1
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../utils/edit/isEditable.js';
|
|
4
|
-
import '../utils/edit/maxLength.js';
|
|
5
2
|
import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
|
|
6
|
-
import '../utils/misc/level.js';
|
|
7
|
-
import '../options.js';
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
|
-
* Parse key
|
|
5
|
+
* Parse key definitions per `keyboardMap`
|
|
11
6
|
*
|
|
12
7
|
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
13
8
|
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
@@ -23,13 +18,13 @@ import '../options.js';
|
|
|
23
18
|
const keyDef = (_keyboardMap_find = keyboardMap.find((def)=>{
|
|
24
19
|
if (type === '[') {
|
|
25
20
|
var _def_code;
|
|
26
|
-
return ((_def_code = def.code) === null || _def_code ===
|
|
21
|
+
return ((_def_code = def.code) === null || _def_code === undefined ? undefined : _def_code.toLowerCase()) === descriptor.toLowerCase();
|
|
27
22
|
} else if (type === '{') {
|
|
28
23
|
var _def_key;
|
|
29
|
-
return ((_def_key = def.key) === null || _def_key ===
|
|
24
|
+
return ((_def_key = def.key) === null || _def_key === undefined ? undefined : _def_key.toLowerCase()) === descriptor.toLowerCase();
|
|
30
25
|
}
|
|
31
26
|
return def.key === descriptor;
|
|
32
|
-
})) !== null && _keyboardMap_find !==
|
|
27
|
+
})) !== null && _keyboardMap_find !== undefined ? _keyboardMap_find : {
|
|
33
28
|
key: 'Unknown',
|
|
34
29
|
code: 'Unknown',
|
|
35
30
|
[type === '[' ? 'code' : 'key']: descriptor
|
package/dist/esm/options.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var PointerEventsCheckLevel
|
|
2
|
-
(function(PointerEventsCheckLevel) {
|
|
1
|
+
var PointerEventsCheckLevel = /*#__PURE__*/ function(PointerEventsCheckLevel) {
|
|
3
2
|
/**
|
|
4
3
|
* Check pointer events on every user interaction that triggers a bunch of events.
|
|
5
4
|
* E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
|
|
@@ -7,6 +6,7 @@ var PointerEventsCheckLevel;
|
|
|
7
6
|
/** Check each target once per call to pointer (related) API */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachApiCall"] = 2] = "EachApiCall";
|
|
8
7
|
/** Check each event target once */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachTarget"] = 1] = "EachTarget";
|
|
9
8
|
/** No pointer events check */ PointerEventsCheckLevel[PointerEventsCheckLevel["Never"] = 0] = "Never";
|
|
10
|
-
|
|
9
|
+
return PointerEventsCheckLevel;
|
|
10
|
+
}({});
|
|
11
11
|
|
|
12
12
|
export { PointerEventsCheckLevel };
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import '../utils/click/isClickableInput.js';
|
|
2
1
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../utils/edit/isEditable.js';
|
|
4
|
-
import '../utils/edit/maxLength.js';
|
|
5
|
-
import '../utils/keyDef/readNextDescriptor.js';
|
|
6
2
|
import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
|
|
7
3
|
import { wait } from '../utils/misc/wait.js';
|
|
8
|
-
import '../options.js';
|
|
9
4
|
import { parseKeyDef } from './parseKeyDef.js';
|
|
10
5
|
|
|
11
6
|
async function pointer(input) {
|
|
@@ -37,11 +32,11 @@ async function pointerAction(instance, action) {
|
|
|
37
32
|
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
|
|
38
33
|
var _action_target, _action_coords, _action_node, _action_offset;
|
|
39
34
|
const position = {
|
|
40
|
-
target: (_action_target = action.target) !== null && _action_target !==
|
|
41
|
-
coords: (_action_coords = action.coords) !== null && _action_coords !==
|
|
35
|
+
target: (_action_target = action.target) !== null && _action_target !== undefined ? _action_target : getPrevTarget(instance, previousPosition),
|
|
36
|
+
coords: (_action_coords = action.coords) !== null && _action_coords !== undefined ? _action_coords : previousPosition === null || previousPosition === undefined ? undefined : previousPosition.coords,
|
|
42
37
|
caret: {
|
|
43
|
-
node: (_action_node = action.node) !== null && _action_node !==
|
|
44
|
-
offset: (_action_offset = action.offset) !== null && _action_offset !==
|
|
38
|
+
node: (_action_node = action.node) !== null && _action_node !== undefined ? _action_node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === undefined ? undefined : (_previousPosition_caret = previousPosition.caret) === null || _previousPosition_caret === undefined ? undefined : _previousPosition_caret.node,
|
|
39
|
+
offset: (_action_offset = action.offset) !== null && _action_offset !== undefined ? _action_offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === undefined ? undefined : (_previousPosition_caret1 = previousPosition.caret) === null || _previousPosition_caret1 === undefined ? undefined : _previousPosition_caret1.offset
|
|
45
40
|
}
|
|
46
41
|
};
|
|
47
42
|
if ('keyDef' in action) {
|
|
@@ -64,14 +59,14 @@ async function pointerAction(instance, action) {
|
|
|
64
59
|
}
|
|
65
60
|
function hasCaretPosition(action) {
|
|
66
61
|
var _action_target, _ref;
|
|
67
|
-
return !!((_ref = (_action_target = action.target) !== null && _action_target !==
|
|
62
|
+
return !!((_ref = (_action_target = action.target) !== null && _action_target !== undefined ? _action_target : action.node) !== null && _ref !== undefined ? _ref : action.offset !== undefined);
|
|
68
63
|
}
|
|
69
64
|
function getPrevTarget(instance, position) {
|
|
70
65
|
if (!position) {
|
|
71
66
|
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
72
67
|
}
|
|
73
68
|
var _position_target;
|
|
74
|
-
return (_position_target = position.target) !== null && _position_target !==
|
|
69
|
+
return (_position_target = position.target) !== null && _position_target !== undefined ? _position_target : instance.config.document.body;
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
export { pointer };
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import '../utils/click/isClickableInput.js';
|
|
2
1
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../utils/edit/isEditable.js';
|
|
4
|
-
import '../utils/edit/maxLength.js';
|
|
5
2
|
import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
|
|
6
|
-
import '../utils/misc/level.js';
|
|
7
|
-
import '../options.js';
|
|
8
3
|
|
|
9
4
|
function parseKeyDef(pointerMap, keys) {
|
|
10
5
|
const defs = [];
|
package/dist/esm/setup/setup.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import { patchFocus } from '../document/patchFocus.js';
|
|
1
2
|
import { prepareDocument } from '../document/prepareDocument.js';
|
|
2
3
|
import { dispatchEvent, dispatchUIEvent } from '../event/dispatchEvent.js';
|
|
3
|
-
import '../utils/click/isClickableInput.js';
|
|
4
4
|
import { attachClipboardStubToView } from '../utils/dataTransfer/Clipboard.js';
|
|
5
|
-
import '../utils/
|
|
6
|
-
import '../utils/edit/maxLength.js';
|
|
7
|
-
import '../utils/keyDef/readNextDescriptor.js';
|
|
5
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
8
6
|
import { getDocumentFromNode } from '../utils/misc/getDocumentFromNode.js';
|
|
9
7
|
import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
|
|
10
8
|
import { wait } from '../utils/misc/wait.js';
|
|
@@ -52,8 +50,9 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
52
50
|
*/ function setupMain(options = {}) {
|
|
53
51
|
const config = createConfig(options);
|
|
54
52
|
prepareDocument(config.document);
|
|
53
|
+
patchFocus(getWindow(config.document).HTMLElement);
|
|
55
54
|
var _config_document_defaultView;
|
|
56
|
-
const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !==
|
|
55
|
+
const view = (_config_document_defaultView = config.document.defaultView) !== null && _config_document_defaultView !== undefined ? _config_document_defaultView : /* istanbul ignore next */ globalThis.window;
|
|
57
56
|
attachClipboardStubToView(view);
|
|
58
57
|
return createInstance(config).api;
|
|
59
58
|
}
|
|
@@ -62,8 +61,9 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
62
61
|
*/ function setupDirect({ keyboardState, pointerState, ...options } = {}, node) {
|
|
63
62
|
const config = createConfig(options, defaultOptionsDirect, node);
|
|
64
63
|
prepareDocument(config.document);
|
|
64
|
+
patchFocus(getWindow(config.document).HTMLElement);
|
|
65
65
|
var _ref;
|
|
66
|
-
const system = (_ref = pointerState !== null && pointerState !==
|
|
66
|
+
const system = (_ref = pointerState !== null && pointerState !== undefined ? pointerState : keyboardState) !== null && _ref !== undefined ? _ref : new System();
|
|
67
67
|
return {
|
|
68
68
|
api: createInstance(config, system).api,
|
|
69
69
|
system
|
|
@@ -113,7 +113,7 @@ function createInstance(config, system = new System()) {
|
|
|
113
113
|
}
|
|
114
114
|
function getDocument(options, node, defaults) {
|
|
115
115
|
var _options_document, _ref;
|
|
116
|
-
return (_ref = (_options_document = options.document) !== null && _options_document !==
|
|
116
|
+
return (_ref = (_options_document = options.document) !== null && _options_document !== undefined ? _options_document : node && getDocumentFromNode(node)) !== null && _ref !== undefined ? _ref : defaults.document;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
export { createConfig, createInstance, setupDirect, setupMain, setupSub };
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import '../utils/click/isClickableInput.js';
|
|
2
1
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../utils/edit/isEditable.js';
|
|
4
|
-
import '../utils/edit/maxLength.js';
|
|
5
2
|
import { getActiveElementOrBody } from '../utils/focus/getActiveElement.js';
|
|
6
|
-
import '../utils/keyDef/readNextDescriptor.js';
|
|
7
|
-
import '../utils/misc/level.js';
|
|
8
|
-
import '../options.js';
|
|
9
3
|
|
|
10
4
|
function _define_property(obj, key, value) {
|
|
11
5
|
if (key in obj) {
|
|
@@ -20,13 +14,13 @@ function _define_property(obj, key, value) {
|
|
|
20
14
|
}
|
|
21
15
|
return obj;
|
|
22
16
|
}
|
|
23
|
-
var DOM_KEY_LOCATION
|
|
24
|
-
(function(DOM_KEY_LOCATION) {
|
|
17
|
+
var DOM_KEY_LOCATION = /*#__PURE__*/ function(DOM_KEY_LOCATION) {
|
|
25
18
|
DOM_KEY_LOCATION[DOM_KEY_LOCATION["STANDARD"] = 0] = "STANDARD";
|
|
26
19
|
DOM_KEY_LOCATION[DOM_KEY_LOCATION["LEFT"] = 1] = "LEFT";
|
|
27
20
|
DOM_KEY_LOCATION[DOM_KEY_LOCATION["RIGHT"] = 2] = "RIGHT";
|
|
28
21
|
DOM_KEY_LOCATION[DOM_KEY_LOCATION["NUMPAD"] = 3] = "NUMPAD";
|
|
29
|
-
|
|
22
|
+
return DOM_KEY_LOCATION;
|
|
23
|
+
}({});
|
|
30
24
|
const modifierKeys = [
|
|
31
25
|
'Alt',
|
|
32
26
|
'AltGraph',
|
|
@@ -51,23 +45,17 @@ function isModifierLock(key) {
|
|
|
51
45
|
}
|
|
52
46
|
class KeyboardHost {
|
|
53
47
|
isKeyPressed(keyDef) {
|
|
54
|
-
return
|
|
48
|
+
return this.pressed.has(String(keyDef.code));
|
|
55
49
|
}
|
|
56
50
|
getPressedKeys() {
|
|
57
|
-
return
|
|
51
|
+
return this.pressed.values().map((p)=>p.keyDef);
|
|
58
52
|
}
|
|
59
53
|
/** Press a key */ async keydown(instance, keyDef) {
|
|
60
|
-
var // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
61
|
-
_this_pressed, _code, _this_pressed_code;
|
|
62
54
|
const key = String(keyDef.key);
|
|
63
55
|
const code = String(keyDef.code);
|
|
64
56
|
const target = getActiveElementOrBody(instance.config.document);
|
|
65
57
|
this.setKeydownTarget(target);
|
|
66
|
-
|
|
67
|
-
(_ = (_this_pressed = this.pressed)[_code = code]) !== null && _ !== void 0 ? _ : _this_pressed[_code] = {
|
|
68
|
-
keyDef,
|
|
69
|
-
unpreventedDefault: false
|
|
70
|
-
};
|
|
58
|
+
this.pressed.add(code, keyDef);
|
|
71
59
|
if (isModifierKey(key)) {
|
|
72
60
|
this.modifiers[key] = true;
|
|
73
61
|
}
|
|
@@ -79,7 +67,9 @@ class KeyboardHost {
|
|
|
79
67
|
this.modifiers[key] = true;
|
|
80
68
|
this.modifierLockStart[key] = true;
|
|
81
69
|
}
|
|
82
|
-
|
|
70
|
+
if (unprevented) {
|
|
71
|
+
this.pressed.setUnprevented(code);
|
|
72
|
+
}
|
|
83
73
|
if (unprevented && this.hasKeyPress(key)) {
|
|
84
74
|
instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keypress', {
|
|
85
75
|
key,
|
|
@@ -91,10 +81,9 @@ class KeyboardHost {
|
|
|
91
81
|
/** Release a key */ async keyup(instance, keyDef) {
|
|
92
82
|
const key = String(keyDef.key);
|
|
93
83
|
const code = String(keyDef.code);
|
|
94
|
-
const unprevented = this.pressed
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (isModifierKey(key) && !Object.values(this.pressed).find((p)=>p.keyDef.key === key)) {
|
|
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)) {
|
|
98
87
|
this.modifiers[key] = false;
|
|
99
88
|
}
|
|
100
89
|
instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keyup', {
|
|
@@ -119,7 +108,7 @@ class KeyboardHost {
|
|
|
119
108
|
return (key.length === 1 || key === 'Enter') && !this.modifiers.Control && !this.modifiers.Alt;
|
|
120
109
|
}
|
|
121
110
|
constructor(system){
|
|
122
|
-
_define_property(this, "system",
|
|
111
|
+
_define_property(this, "system", undefined);
|
|
123
112
|
_define_property(this, "modifiers", {
|
|
124
113
|
Alt: false,
|
|
125
114
|
AltGraph: false,
|
|
@@ -134,7 +123,39 @@ class KeyboardHost {
|
|
|
134
123
|
Symbol: false,
|
|
135
124
|
SymbolLock: false
|
|
136
125
|
});
|
|
137
|
-
_define_property(this, "pressed", {
|
|
126
|
+
_define_property(this, "pressed", new class {
|
|
127
|
+
add(code, keyDef) {
|
|
128
|
+
var _this_registry, _code;
|
|
129
|
+
var _;
|
|
130
|
+
(_ = (_this_registry = this.registry)[_code = code]) !== null && _ !== undefined ? _ : _this_registry[_code] = {
|
|
131
|
+
keyDef,
|
|
132
|
+
unpreventedDefault: false
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
has(code) {
|
|
136
|
+
return !!this.registry[code];
|
|
137
|
+
}
|
|
138
|
+
setUnprevented(code) {
|
|
139
|
+
const o = this.registry[code];
|
|
140
|
+
if (o) {
|
|
141
|
+
o.unpreventedDefault = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
isUnprevented(code) {
|
|
145
|
+
var _this_registry_code;
|
|
146
|
+
return !!((_this_registry_code = this.registry[code]) === null || _this_registry_code === undefined ? undefined : _this_registry_code.unpreventedDefault);
|
|
147
|
+
}
|
|
148
|
+
delete(code) {
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
150
|
+
delete this.registry[code];
|
|
151
|
+
}
|
|
152
|
+
values() {
|
|
153
|
+
return Object.values(this.registry);
|
|
154
|
+
}
|
|
155
|
+
constructor(){
|
|
156
|
+
_define_property(this, "registry", {});
|
|
157
|
+
}
|
|
158
|
+
}());
|
|
138
159
|
_define_property(this, "carryChar", '');
|
|
139
160
|
_define_property(this, "lastKeydownTarget", undefined);
|
|
140
161
|
_define_property(this, "modifierLockStart", {});
|
|
@@ -21,18 +21,21 @@ class PointerHost {
|
|
|
21
21
|
return this.devices.get(keyDef.pointerType).isPressed(keyDef);
|
|
22
22
|
}
|
|
23
23
|
async press(instance, keyDef, position) {
|
|
24
|
+
this.devices.get(keyDef.pointerType).addPressed(keyDef);
|
|
25
|
+
this.buttons.down(keyDef);
|
|
24
26
|
const pointerName = this.getPointerName(keyDef);
|
|
25
|
-
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef
|
|
27
|
+
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef.pointerType, this.buttons) : this.pointers.get(pointerName);
|
|
26
28
|
// TODO: deprecate the following implicit setting of position
|
|
27
29
|
pointer.position = position;
|
|
28
30
|
if (pointer.pointerType !== 'touch') {
|
|
29
31
|
this.mouse.position = position;
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (pointer.pointerType === 'touch') {
|
|
34
|
+
pointer.init(instance);
|
|
35
|
+
}
|
|
36
|
+
pointer.down(instance, keyDef.button);
|
|
37
|
+
if (pointer.pointerType !== 'touch') {
|
|
38
|
+
this.mouse.down(instance, keyDef, pointer.isPrevented);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
async move(instance, pointerName, position) {
|
|
@@ -42,45 +45,44 @@ class PointerHost {
|
|
|
42
45
|
// While the order of mouse (or pointer) events is defined per spec,
|
|
43
46
|
// the order in which they interweave/follow on a user interaction depends on the implementation.
|
|
44
47
|
const pointermove = pointer.move(instance, position);
|
|
45
|
-
const mousemove = pointer.pointerType === 'touch'
|
|
46
|
-
pointermove === null || pointermove ===
|
|
47
|
-
mousemove === null || mousemove ===
|
|
48
|
-
pointermove === null || pointermove ===
|
|
49
|
-
mousemove === null || mousemove ===
|
|
50
|
-
pointermove === null || pointermove ===
|
|
51
|
-
mousemove === null || mousemove ===
|
|
48
|
+
const mousemove = pointer.pointerType === 'touch' ? undefined : this.mouse.move(instance, position, pointer.isPrevented);
|
|
49
|
+
pointermove === null || pointermove === undefined ? undefined : pointermove.leave();
|
|
50
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
|
|
51
|
+
pointermove === null || pointermove === undefined ? undefined : pointermove.enter();
|
|
52
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
|
|
53
|
+
pointermove === null || pointermove === undefined ? undefined : pointermove.move();
|
|
54
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.move();
|
|
52
55
|
}
|
|
53
56
|
async release(instance, keyDef, position) {
|
|
54
57
|
const device = this.devices.get(keyDef.pointerType);
|
|
55
58
|
device.removePressed(keyDef);
|
|
56
59
|
this.buttons.up(keyDef);
|
|
57
60
|
const pointer = this.pointers.get(this.getPointerName(keyDef));
|
|
61
|
+
const isPrevented = pointer.isPrevented;
|
|
58
62
|
// TODO: deprecate the following implicit setting of position
|
|
59
63
|
pointer.position = position;
|
|
60
64
|
if (pointer.pointerType !== 'touch') {
|
|
61
65
|
this.mouse.position = position;
|
|
62
66
|
}
|
|
63
67
|
if (device.countPressed === 0) {
|
|
64
|
-
pointer.up(instance, keyDef);
|
|
68
|
+
pointer.up(instance, keyDef.button);
|
|
65
69
|
}
|
|
66
70
|
if (pointer.pointerType === 'touch') {
|
|
67
71
|
pointer.release(instance);
|
|
68
72
|
}
|
|
69
|
-
if (!pointer.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.mouse.up(instance, keyDef, pointer);
|
|
83
|
-
}
|
|
73
|
+
if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
|
|
74
|
+
const mousemove = this.mouse.move(instance, position, isPrevented);
|
|
75
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
|
|
76
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
|
|
77
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.move();
|
|
78
|
+
this.mouse.down(instance, keyDef, isPrevented);
|
|
79
|
+
}
|
|
80
|
+
if (!pointer.isMultitouch) {
|
|
81
|
+
const mousemove = this.mouse.move(instance, position, isPrevented);
|
|
82
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
|
|
83
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
|
|
84
|
+
mousemove === null || mousemove === undefined ? undefined : mousemove.move();
|
|
85
|
+
this.mouse.up(instance, keyDef, isPrevented);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
getPointerName(keyDef) {
|
|
@@ -94,43 +96,41 @@ class PointerHost {
|
|
|
94
96
|
}
|
|
95
97
|
getMouseTarget(instance) {
|
|
96
98
|
var _this_mouse_position_target;
|
|
97
|
-
return (_this_mouse_position_target = this.mouse.position.target) !== null && _this_mouse_position_target !==
|
|
99
|
+
return (_this_mouse_position_target = this.mouse.position.target) !== null && _this_mouse_position_target !== undefined ? _this_mouse_position_target : instance.config.document.body;
|
|
98
100
|
}
|
|
99
101
|
setMousePosition(position) {
|
|
100
102
|
this.mouse.position = position;
|
|
101
103
|
this.pointers.get('mouse').position = position;
|
|
102
104
|
}
|
|
103
105
|
constructor(system){
|
|
104
|
-
_define_property(this, "system",
|
|
105
|
-
_define_property(this, "mouse",
|
|
106
|
-
_define_property(this, "buttons",
|
|
106
|
+
_define_property(this, "system", undefined);
|
|
107
|
+
_define_property(this, "mouse", undefined);
|
|
108
|
+
_define_property(this, "buttons", undefined);
|
|
107
109
|
_define_property(this, "devices", new class {
|
|
108
110
|
get(k) {
|
|
109
|
-
var
|
|
110
|
-
_this_registry, _k;
|
|
111
|
+
var _this_registry, _k;
|
|
111
112
|
var _;
|
|
112
|
-
(_ = (_this_registry = this.registry)[_k = k]) !== null && _ !==
|
|
113
|
-
return this.registry[k];
|
|
113
|
+
return (_ = (_this_registry = this.registry)[_k = k]) !== null && _ !== undefined ? _ : _this_registry[_k] = new Device();
|
|
114
114
|
}
|
|
115
115
|
constructor(){
|
|
116
116
|
_define_property(this, "registry", {});
|
|
117
117
|
}
|
|
118
118
|
}());
|
|
119
119
|
_define_property(this, "pointers", new class {
|
|
120
|
-
new(pointerName,
|
|
121
|
-
const isPrimary =
|
|
120
|
+
new(pointerName, pointerType, buttons) {
|
|
121
|
+
const isPrimary = pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
|
|
122
122
|
if (!isPrimary) {
|
|
123
123
|
Object.values(this.registry).forEach((p)=>{
|
|
124
|
-
if (p.pointerType ===
|
|
124
|
+
if (p.pointerType === pointerType && !p.isCancelled) {
|
|
125
125
|
p.isMultitouch = true;
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
this.registry[pointerName] = new Pointer({
|
|
130
130
|
pointerId: this.nextId++,
|
|
131
|
-
pointerType
|
|
131
|
+
pointerType,
|
|
132
132
|
isPrimary
|
|
133
|
-
});
|
|
133
|
+
}, buttons);
|
|
134
134
|
return this.registry[pointerName];
|
|
135
135
|
}
|
|
136
136
|
get(pointerName) {
|
|
@@ -143,19 +143,14 @@ class PointerHost {
|
|
|
143
143
|
return pointerName in this.registry;
|
|
144
144
|
}
|
|
145
145
|
constructor(){
|
|
146
|
-
_define_property(this, "registry", {
|
|
147
|
-
|
|
148
|
-
pointerId: 1,
|
|
149
|
-
pointerType: 'mouse',
|
|
150
|
-
isPrimary: true
|
|
151
|
-
})
|
|
152
|
-
});
|
|
153
|
-
_define_property(this, "nextId", 2);
|
|
146
|
+
_define_property(this, "registry", {});
|
|
147
|
+
_define_property(this, "nextId", 1);
|
|
154
148
|
}
|
|
155
149
|
}());
|
|
156
150
|
this.system = system;
|
|
157
151
|
this.buttons = new Buttons();
|
|
158
152
|
this.mouse = new Mouse();
|
|
153
|
+
this.pointers.new('mouse', 'mouse', this.buttons);
|
|
159
154
|
}
|
|
160
155
|
}
|
|
161
156
|
|