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