@testing-library/user-event 14.4.0 → 14.4.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 +2 -1
- package/dist/cjs/clipboard/cut.js +2 -1
- package/dist/cjs/clipboard/paste.js +4 -2
- package/dist/cjs/document/interceptor.js +4 -4
- package/dist/cjs/document/selection.js +4 -3
- package/dist/cjs/document/value.js +4 -2
- package/dist/cjs/event/behavior/keydown.js +6 -2
- package/dist/cjs/event/behavior/keypress.js +1 -1
- package/dist/cjs/event/behavior/keyup.js +2 -1
- package/dist/cjs/event/behavior/paste.js +2 -1
- package/dist/cjs/event/createEvent.js +35 -19
- package/dist/cjs/event/dispatchEvent.js +2 -1
- package/dist/cjs/keyboard/parseKeyDef.js +7 -4
- package/dist/cjs/pointer/index.js +10 -6
- package/dist/cjs/setup/setup.js +7 -4
- package/dist/cjs/system/index.js +4 -2
- package/dist/cjs/system/keyboard.js +25 -23
- package/dist/cjs/system/pointer/buttons.js +3 -1
- package/dist/cjs/system/pointer/device.js +3 -1
- package/dist/cjs/system/pointer/index.js +69 -61
- package/dist/cjs/system/pointer/mouse.js +53 -44
- package/dist/cjs/system/pointer/pointer.js +13 -12
- package/dist/cjs/utility/type.js +1 -1
- package/dist/cjs/utility/upload.js +6 -2
- package/dist/cjs/utils/dataTransfer/Clipboard.js +10 -6
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/cjs/utils/edit/input.js +2 -1
- package/dist/cjs/utils/edit/maxLength.js +2 -1
- package/dist/cjs/utils/edit/setFiles.js +4 -2
- package/dist/cjs/utils/focus/cursor.js +2 -1
- package/dist/cjs/utils/focus/focus.js +6 -3
- package/dist/cjs/utils/focus/getActiveElement.js +3 -2
- package/dist/cjs/utils/focus/resolveCaretPosition.js +3 -3
- package/dist/cjs/utils/focus/selectAll.js +5 -3
- package/dist/cjs/utils/focus/selection.js +23 -18
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/cjs/utils/misc/isDisabled.js +2 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +5 -2
- package/dist/cjs/utils/pointer/cssPointerEvents.js +18 -11
- package/dist/esm/clipboard/copy.js +2 -1
- package/dist/esm/clipboard/cut.js +2 -1
- package/dist/esm/clipboard/paste.js +4 -2
- package/dist/esm/document/interceptor.js +4 -4
- package/dist/esm/document/selection.js +4 -3
- package/dist/esm/document/value.js +4 -2
- package/dist/esm/event/behavior/keydown.js +6 -2
- package/dist/esm/event/behavior/keypress.js +1 -1
- package/dist/esm/event/behavior/keyup.js +2 -1
- package/dist/esm/event/behavior/paste.js +2 -1
- package/dist/esm/event/createEvent.js +35 -19
- package/dist/esm/event/dispatchEvent.js +2 -1
- package/dist/esm/keyboard/parseKeyDef.js +7 -4
- package/dist/esm/pointer/index.js +10 -6
- package/dist/esm/setup/setup.js +7 -4
- package/dist/esm/system/index.js +4 -2
- package/dist/esm/system/keyboard.js +25 -23
- package/dist/esm/system/pointer/buttons.js +3 -1
- package/dist/esm/system/pointer/device.js +3 -1
- package/dist/esm/system/pointer/index.js +69 -61
- package/dist/esm/system/pointer/mouse.js +54 -45
- package/dist/esm/system/pointer/pointer.js +13 -12
- package/dist/esm/utility/type.js +1 -1
- package/dist/esm/utility/upload.js +6 -2
- package/dist/esm/utils/dataTransfer/Clipboard.js +10 -6
- package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/esm/utils/edit/input.js +2 -1
- package/dist/esm/utils/edit/maxLength.js +2 -1
- package/dist/esm/utils/edit/setFiles.js +4 -2
- package/dist/esm/utils/focus/cursor.js +2 -1
- package/dist/esm/utils/focus/focus.js +6 -3
- package/dist/esm/utils/focus/getActiveElement.js +3 -2
- package/dist/esm/utils/focus/resolveCaretPosition.js +3 -3
- package/dist/esm/utils/focus/selectAll.js +5 -3
- package/dist/esm/utils/focus/selection.js +23 -18
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/esm/utils/misc/isDisabled.js +2 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +5 -2
- package/dist/esm/utils/pointer/cssPointerEvents.js +18 -11
- package/package.json +3 -3
|
@@ -7,54 +7,8 @@ var device = require('./device.js');
|
|
|
7
7
|
var mouse = require('./mouse.js');
|
|
8
8
|
var pointer = require('./pointer.js');
|
|
9
9
|
|
|
10
|
+
var _registry, _k;
|
|
10
11
|
class PointerHost {
|
|
11
|
-
constructor(system){
|
|
12
|
-
this.system = system;
|
|
13
|
-
this.buttons = new buttons.Buttons();
|
|
14
|
-
this.mouse = new mouse.Mouse();
|
|
15
|
-
}
|
|
16
|
-
devices = new class {
|
|
17
|
-
registry = {};
|
|
18
|
-
get(k) {
|
|
19
|
-
this.registry[k] ??= new device.Device();
|
|
20
|
-
return this.registry[k];
|
|
21
|
-
}
|
|
22
|
-
}();
|
|
23
|
-
pointers = new class {
|
|
24
|
-
registry = {
|
|
25
|
-
mouse: new pointer.Pointer({
|
|
26
|
-
pointerId: 1,
|
|
27
|
-
pointerType: 'mouse',
|
|
28
|
-
isPrimary: true
|
|
29
|
-
})
|
|
30
|
-
};
|
|
31
|
-
nextId = 2;
|
|
32
|
-
new(pointerName, keyDef) {
|
|
33
|
-
const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
|
|
34
|
-
if (!isPrimary) {
|
|
35
|
-
Object.values(this.registry).forEach((p)=>{
|
|
36
|
-
if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
|
|
37
|
-
p.isMultitouch = true;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
this.registry[pointerName] = new pointer.Pointer({
|
|
42
|
-
pointerId: this.nextId++,
|
|
43
|
-
pointerType: keyDef.pointerType,
|
|
44
|
-
isPrimary
|
|
45
|
-
});
|
|
46
|
-
return this.registry[pointerName];
|
|
47
|
-
}
|
|
48
|
-
get(pointerName) {
|
|
49
|
-
if (!this.has(pointerName)) {
|
|
50
|
-
throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
|
|
51
|
-
}
|
|
52
|
-
return this.registry[pointerName];
|
|
53
|
-
}
|
|
54
|
-
has(pointerName) {
|
|
55
|
-
return pointerName in this.registry;
|
|
56
|
-
}
|
|
57
|
-
}();
|
|
58
12
|
isKeyPressed(keyDef) {
|
|
59
13
|
return this.devices.get(keyDef.pointerType).isPressed(keyDef);
|
|
60
14
|
}
|
|
@@ -81,12 +35,12 @@ class PointerHost {
|
|
|
81
35
|
// the order in which they interweave/follow on a user interaction depends on the implementation.
|
|
82
36
|
const pointermove = pointer.move(config, position);
|
|
83
37
|
const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(config, position);
|
|
84
|
-
pointermove
|
|
85
|
-
mousemove
|
|
86
|
-
pointermove
|
|
87
|
-
mousemove
|
|
88
|
-
pointermove
|
|
89
|
-
mousemove
|
|
38
|
+
pointermove === null || pointermove === void 0 ? void 0 : pointermove.leave();
|
|
39
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
|
|
40
|
+
pointermove === null || pointermove === void 0 ? void 0 : pointermove.enter();
|
|
41
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
|
|
42
|
+
pointermove === null || pointermove === void 0 ? void 0 : pointermove.move();
|
|
43
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
|
|
90
44
|
}
|
|
91
45
|
async release(config, keyDef, position) {
|
|
92
46
|
const device = this.devices.get(keyDef.pointerType);
|
|
@@ -107,16 +61,16 @@ class PointerHost {
|
|
|
107
61
|
if (!pointer.isPrevented) {
|
|
108
62
|
if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
|
|
109
63
|
const mousemove = this.mouse.move(config, pointer.position);
|
|
110
|
-
mousemove
|
|
111
|
-
mousemove
|
|
112
|
-
mousemove
|
|
64
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
|
|
65
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
|
|
66
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
|
|
113
67
|
this.mouse.down(config, keyDef, pointer);
|
|
114
68
|
}
|
|
115
69
|
if (!pointer.isMultitouch) {
|
|
116
70
|
const mousemove1 = this.mouse.move(config, pointer.position);
|
|
117
|
-
mousemove1
|
|
118
|
-
mousemove1
|
|
119
|
-
mousemove1
|
|
71
|
+
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.leave();
|
|
72
|
+
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.enter();
|
|
73
|
+
mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.move();
|
|
120
74
|
this.mouse.up(config, keyDef, pointer);
|
|
121
75
|
}
|
|
122
76
|
}
|
|
@@ -131,15 +85,69 @@ class PointerHost {
|
|
|
131
85
|
this.mouse.resetClickCount();
|
|
132
86
|
}
|
|
133
87
|
getMouseTarget(config) {
|
|
134
|
-
|
|
88
|
+
var _target;
|
|
89
|
+
return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : config.document.body;
|
|
135
90
|
}
|
|
136
91
|
setMousePosition(position) {
|
|
137
92
|
this.mouse.position = position;
|
|
138
93
|
this.pointers.get('mouse').position = position;
|
|
139
94
|
}
|
|
95
|
+
constructor(system){
|
|
96
|
+
this.devices = new class {
|
|
97
|
+
get(k) {
|
|
98
|
+
var ref;
|
|
99
|
+
(ref = (_registry = this.registry)[_k = k]) !== null && ref !== void 0 ? ref : _registry[_k] = new device.Device();
|
|
100
|
+
return this.registry[k];
|
|
101
|
+
}
|
|
102
|
+
constructor(){
|
|
103
|
+
this.registry = {};
|
|
104
|
+
}
|
|
105
|
+
}();
|
|
106
|
+
this.pointers = new class {
|
|
107
|
+
new(pointerName, keyDef) {
|
|
108
|
+
const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
|
|
109
|
+
if (!isPrimary) {
|
|
110
|
+
Object.values(this.registry).forEach((p)=>{
|
|
111
|
+
if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
|
|
112
|
+
p.isMultitouch = true;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
this.registry[pointerName] = new pointer.Pointer({
|
|
117
|
+
pointerId: this.nextId++,
|
|
118
|
+
pointerType: keyDef.pointerType,
|
|
119
|
+
isPrimary
|
|
120
|
+
});
|
|
121
|
+
return this.registry[pointerName];
|
|
122
|
+
}
|
|
123
|
+
get(pointerName) {
|
|
124
|
+
if (!this.has(pointerName)) {
|
|
125
|
+
throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
|
|
126
|
+
}
|
|
127
|
+
return this.registry[pointerName];
|
|
128
|
+
}
|
|
129
|
+
has(pointerName) {
|
|
130
|
+
return pointerName in this.registry;
|
|
131
|
+
}
|
|
132
|
+
constructor(){
|
|
133
|
+
this.registry = {
|
|
134
|
+
mouse: new pointer.Pointer({
|
|
135
|
+
pointerId: 1,
|
|
136
|
+
pointerType: 'mouse',
|
|
137
|
+
isPrimary: true
|
|
138
|
+
})
|
|
139
|
+
};
|
|
140
|
+
this.nextId = 2;
|
|
141
|
+
}
|
|
142
|
+
}();
|
|
143
|
+
this.system = system;
|
|
144
|
+
this.buttons = new buttons.Buttons();
|
|
145
|
+
this.mouse = new mouse.Mouse();
|
|
146
|
+
}
|
|
140
147
|
}
|
|
141
148
|
function isDifferentPointerPosition(positionA, positionB) {
|
|
142
|
-
|
|
149
|
+
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
|
|
150
|
+
return positionA.target !== positionB.target || ((ref = positionA.coords) === null || ref === void 0 ? void 0 : ref.x) !== ((ref1 = positionB.coords) === null || ref1 === void 0 ? void 0 : ref1.y) || ((ref2 = positionA.coords) === null || ref2 === void 0 ? void 0 : ref2.y) !== ((ref3 = positionB.coords) === null || ref3 === void 0 ? void 0 : ref3.y) || ((ref4 = positionA.caret) === null || ref4 === void 0 ? void 0 : ref4.node) !== ((ref5 = positionB.caret) === null || ref5 === void 0 ? void 0 : ref5.node) || ((ref6 = positionA.caret) === null || ref6 === void 0 ? void 0 : ref6.offset) !== ((ref7 = positionB.caret) === null || ref7 === void 0 ? void 0 : ref7.offset);
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
exports.PointerHost = PointerHost;
|
|
@@ -22,45 +22,6 @@ var buttons = require('./buttons.js');
|
|
|
22
22
|
/**
|
|
23
23
|
* This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
|
|
24
24
|
*/ class Mouse {
|
|
25
|
-
position = {};
|
|
26
|
-
buttons = new buttons.Buttons();
|
|
27
|
-
buttonDownTarget = {};
|
|
28
|
-
// According to spec the `detail` on click events should be the number
|
|
29
|
-
// of *consecutive* clicks with a specific button.
|
|
30
|
-
// On `mousedown` and `mouseup` it should be this number increased by one.
|
|
31
|
-
// But the browsers don't implement it this way.
|
|
32
|
-
// If another button is pressed,
|
|
33
|
-
// in Webkit: the `mouseup` on the previously pressed button has `detail: 0` and no `click`/`auxclick`.
|
|
34
|
-
// in Gecko: the `mouseup` and click events have the same detail as the `mousedown`.
|
|
35
|
-
// If there is a delay while a button is pressed,
|
|
36
|
-
// the `mouseup` and `click` are normal, but a following `mousedown` starts a new click count.
|
|
37
|
-
// We'll follow the minimal implementation of Webkit.
|
|
38
|
-
clickCount = new class {
|
|
39
|
-
down = {};
|
|
40
|
-
count = {};
|
|
41
|
-
incOnClick(button) {
|
|
42
|
-
const current = this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
|
|
43
|
-
this.count = this.count[button] === undefined ? {} : {
|
|
44
|
-
[button]: Number(this.count[button]) + 1
|
|
45
|
-
};
|
|
46
|
-
return current;
|
|
47
|
-
}
|
|
48
|
-
getOnDown(button) {
|
|
49
|
-
this.down = {
|
|
50
|
-
[button]: this.count[button] ?? 0
|
|
51
|
-
};
|
|
52
|
-
this.count = {
|
|
53
|
-
[button]: this.count[button] ?? 0
|
|
54
|
-
};
|
|
55
|
-
return Number(this.count[button]) + 1;
|
|
56
|
-
}
|
|
57
|
-
getOnUp(button) {
|
|
58
|
-
return this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
|
|
59
|
-
}
|
|
60
|
-
reset() {
|
|
61
|
-
this.count = {};
|
|
62
|
-
}
|
|
63
|
-
}();
|
|
64
25
|
move(config, position) {
|
|
65
26
|
const prevPosition = this.position;
|
|
66
27
|
const prevTarget = this.getTarget(config);
|
|
@@ -155,32 +116,80 @@ var buttons = require('./buttons.js');
|
|
|
155
116
|
return init;
|
|
156
117
|
}
|
|
157
118
|
getTarget(config) {
|
|
158
|
-
|
|
119
|
+
var _target;
|
|
120
|
+
return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
|
|
159
121
|
}
|
|
160
122
|
startSelecting(config, clickCount) {
|
|
123
|
+
var ref, ref1;
|
|
161
124
|
// TODO: support extending range (shift)
|
|
162
125
|
this.selecting = selection.setSelectionPerMouseDown({
|
|
163
126
|
document: config.document,
|
|
164
127
|
target: this.getTarget(config),
|
|
165
|
-
node: this.position.caret
|
|
166
|
-
offset: this.position.caret
|
|
128
|
+
node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
|
|
129
|
+
offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset,
|
|
167
130
|
clickCount
|
|
168
131
|
});
|
|
169
132
|
}
|
|
170
133
|
modifySelecting(config) {
|
|
134
|
+
var ref, ref1;
|
|
171
135
|
if (!this.selecting) {
|
|
172
136
|
return;
|
|
173
137
|
}
|
|
174
138
|
selection.modifySelectionPerMouseMove(this.selecting, {
|
|
175
139
|
document: config.document,
|
|
176
140
|
target: this.getTarget(config),
|
|
177
|
-
node: this.position.caret
|
|
178
|
-
offset: this.position.caret
|
|
141
|
+
node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
|
|
142
|
+
offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
|
|
179
143
|
});
|
|
180
144
|
}
|
|
181
145
|
endSelecting() {
|
|
182
146
|
this.selecting = undefined;
|
|
183
147
|
}
|
|
148
|
+
constructor(){
|
|
149
|
+
this.position = {};
|
|
150
|
+
this.buttons = new buttons.Buttons();
|
|
151
|
+
this.buttonDownTarget = {};
|
|
152
|
+
// According to spec the `detail` on click events should be the number
|
|
153
|
+
// of *consecutive* clicks with a specific button.
|
|
154
|
+
// On `mousedown` and `mouseup` it should be this number increased by one.
|
|
155
|
+
// But the browsers don't implement it this way.
|
|
156
|
+
// If another button is pressed,
|
|
157
|
+
// in Webkit: the `mouseup` on the previously pressed button has `detail: 0` and no `click`/`auxclick`.
|
|
158
|
+
// in Gecko: the `mouseup` and click events have the same detail as the `mousedown`.
|
|
159
|
+
// If there is a delay while a button is pressed,
|
|
160
|
+
// the `mouseup` and `click` are normal, but a following `mousedown` starts a new click count.
|
|
161
|
+
// We'll follow the minimal implementation of Webkit.
|
|
162
|
+
this.clickCount = new class {
|
|
163
|
+
incOnClick(button) {
|
|
164
|
+
const current = this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
|
|
165
|
+
this.count = this.count[button] === undefined ? {} : {
|
|
166
|
+
[button]: Number(this.count[button]) + 1
|
|
167
|
+
};
|
|
168
|
+
return current;
|
|
169
|
+
}
|
|
170
|
+
getOnDown(button) {
|
|
171
|
+
var _button;
|
|
172
|
+
this.down = {
|
|
173
|
+
[button]: (_button = this.count[button]) !== null && _button !== void 0 ? _button : 0
|
|
174
|
+
};
|
|
175
|
+
var _button1;
|
|
176
|
+
this.count = {
|
|
177
|
+
[button]: (_button1 = this.count[button]) !== null && _button1 !== void 0 ? _button1 : 0
|
|
178
|
+
};
|
|
179
|
+
return Number(this.count[button]) + 1;
|
|
180
|
+
}
|
|
181
|
+
getOnUp(button) {
|
|
182
|
+
return this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
|
|
183
|
+
}
|
|
184
|
+
reset() {
|
|
185
|
+
this.count = {};
|
|
186
|
+
}
|
|
187
|
+
constructor(){
|
|
188
|
+
this.down = {};
|
|
189
|
+
this.count = {};
|
|
190
|
+
}
|
|
191
|
+
}();
|
|
192
|
+
}
|
|
184
193
|
}
|
|
185
194
|
|
|
186
195
|
exports.Mouse = Mouse;
|
|
@@ -16,17 +16,6 @@ var cssPointerEvents = require('../../utils/pointer/cssPointerEvents.js');
|
|
|
16
16
|
var index$1 = require('./index.js');
|
|
17
17
|
|
|
18
18
|
class Pointer {
|
|
19
|
-
constructor({ pointerId , pointerType , isPrimary }){
|
|
20
|
-
this.pointerId = pointerId;
|
|
21
|
-
this.pointerType = pointerType;
|
|
22
|
-
this.isPrimary = isPrimary;
|
|
23
|
-
this.isMultitouch = !isPrimary;
|
|
24
|
-
}
|
|
25
|
-
isMultitouch = false;
|
|
26
|
-
isCancelled = false;
|
|
27
|
-
isDown = false;
|
|
28
|
-
isPrevented = false;
|
|
29
|
-
position = {};
|
|
30
19
|
init(config, position) {
|
|
31
20
|
this.position = position;
|
|
32
21
|
const target = this.getTarget(config);
|
|
@@ -99,7 +88,8 @@ class Pointer {
|
|
|
99
88
|
this.isCancelled = true;
|
|
100
89
|
}
|
|
101
90
|
getTarget(config) {
|
|
102
|
-
|
|
91
|
+
var _target;
|
|
92
|
+
return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
|
|
103
93
|
}
|
|
104
94
|
getEventInit() {
|
|
105
95
|
return {
|
|
@@ -109,6 +99,17 @@ class Pointer {
|
|
|
109
99
|
isPrimary: this.isPrimary
|
|
110
100
|
};
|
|
111
101
|
}
|
|
102
|
+
constructor({ pointerId , pointerType , isPrimary }){
|
|
103
|
+
this.isMultitouch = false;
|
|
104
|
+
this.isCancelled = false;
|
|
105
|
+
this.isDown = false;
|
|
106
|
+
this.isPrevented = false;
|
|
107
|
+
this.position = {};
|
|
108
|
+
this.pointerId = pointerId;
|
|
109
|
+
this.pointerType = pointerType;
|
|
110
|
+
this.isPrimary = isPrimary;
|
|
111
|
+
this.isMultitouch = !isPrimary;
|
|
112
|
+
}
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
exports.Pointer = Pointer;
|
package/dist/cjs/utility/type.js
CHANGED
|
@@ -30,7 +30,7 @@ async function type(element, text, { skipClick =this[config.Config].skipClick ,
|
|
|
30
30
|
await this.click(element);
|
|
31
31
|
}
|
|
32
32
|
if (initialSelectionStart !== undefined) {
|
|
33
|
-
selection.setSelectionRange(element, initialSelectionStart, initialSelectionEnd
|
|
33
|
+
selection.setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart);
|
|
34
34
|
}
|
|
35
35
|
await this.keyboard(text);
|
|
36
36
|
if (!skipAutoClose) {
|
|
@@ -30,15 +30,19 @@ async function upload(element, fileOrFiles) {
|
|
|
30
30
|
if (!input || !isElementType.isElementType(input, 'input', {
|
|
31
31
|
type: 'file'
|
|
32
32
|
})) {
|
|
33
|
-
throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input
|
|
33
|
+
throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input === null || input === void 0 ? void 0 : input.tagName} element does not accept file uploads`);
|
|
34
34
|
}
|
|
35
35
|
if (isDisabled.isDisabled(element)) return;
|
|
36
36
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [
|
|
37
37
|
fileOrFiles
|
|
38
38
|
]).filter((file)=>!this[config.Config].applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1);
|
|
39
39
|
const fileDialog = ()=>{
|
|
40
|
+
var ref;
|
|
40
41
|
// do not fire an input event if the file selection does not change
|
|
41
|
-
if (files.length === input.files
|
|
42
|
+
if (files.length === ((ref = input.files) === null || ref === void 0 ? void 0 : ref.length) && files.every((f, i)=>{
|
|
43
|
+
var ref;
|
|
44
|
+
return f === ((ref = input.files) === null || ref === void 0 ? void 0 : ref.item(i));
|
|
45
|
+
})) {
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
48
|
setFiles.setFiles(input, FileList.createFileList(getWindow.getWindow(element), files));
|
|
@@ -34,9 +34,6 @@ function createClipboardItem(window, ...blobs) {
|
|
|
34
34
|
return new window.ClipboardItem(dataMap);
|
|
35
35
|
}
|
|
36
36
|
return new class ClipboardItem {
|
|
37
|
-
constructor(d){
|
|
38
|
-
this.data = d;
|
|
39
|
-
}
|
|
40
37
|
get types() {
|
|
41
38
|
return Array.from(Object.keys(this.data));
|
|
42
39
|
}
|
|
@@ -51,12 +48,14 @@ function createClipboardItem(window, ...blobs) {
|
|
|
51
48
|
type
|
|
52
49
|
});
|
|
53
50
|
}
|
|
51
|
+
constructor(d){
|
|
52
|
+
this.data = d;
|
|
53
|
+
}
|
|
54
54
|
}(dataMap);
|
|
55
55
|
}
|
|
56
56
|
const ClipboardStubControl = Symbol('Manage ClipboardSub');
|
|
57
57
|
function createClipboardStub(window, control) {
|
|
58
58
|
return Object.assign(new class Clipboard extends window.EventTarget {
|
|
59
|
-
items = [];
|
|
60
59
|
async read() {
|
|
61
60
|
return Array.from(this.items);
|
|
62
61
|
}
|
|
@@ -78,12 +77,17 @@ function createClipboardStub(window, control) {
|
|
|
78
77
|
createClipboardItem(window, text)
|
|
79
78
|
];
|
|
80
79
|
}
|
|
80
|
+
constructor(...args){
|
|
81
|
+
super(...args);
|
|
82
|
+
this.items = [];
|
|
83
|
+
}
|
|
81
84
|
}(), {
|
|
82
85
|
[ClipboardStubControl]: control
|
|
83
86
|
});
|
|
84
87
|
}
|
|
85
88
|
function isClipboardStub(clipboard) {
|
|
86
|
-
|
|
89
|
+
var ref;
|
|
90
|
+
return !!((ref = clipboard) === null || ref === void 0 ? void 0 : ref[ClipboardStubControl]);
|
|
87
91
|
}
|
|
88
92
|
function attachClipboardStubToView(window) {
|
|
89
93
|
if (isClipboardStub(window.navigator.clipboard)) {
|
|
@@ -125,7 +129,7 @@ function detachClipboardStubFromView(window) {
|
|
|
125
129
|
}
|
|
126
130
|
async function readDataTransferFromClipboard(document) {
|
|
127
131
|
const window = document.defaultView;
|
|
128
|
-
const clipboard = window
|
|
132
|
+
const clipboard = window === null || window === void 0 ? void 0 : window.navigator.clipboard;
|
|
129
133
|
const items = clipboard && await clipboard.read();
|
|
130
134
|
if (!items) {
|
|
131
135
|
throw new Error('The Clipboard API is unavailable.');
|
|
@@ -7,19 +7,6 @@ var FileList = require('./FileList.js');
|
|
|
7
7
|
// DataTransfer is not implemented in jsdom.
|
|
8
8
|
// DataTransfer with FileList is being created by the browser on certain events.
|
|
9
9
|
class DataTransferItemStub {
|
|
10
|
-
file = null;
|
|
11
|
-
data = undefined;
|
|
12
|
-
constructor(dataOrFile, type){
|
|
13
|
-
if (typeof dataOrFile === 'string') {
|
|
14
|
-
this.kind = 'string';
|
|
15
|
-
this.type = String(type);
|
|
16
|
-
this.data = dataOrFile;
|
|
17
|
-
} else {
|
|
18
|
-
this.kind = 'file';
|
|
19
|
-
this.type = dataOrFile.type;
|
|
20
|
-
this.file = dataOrFile;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
10
|
getAsFile() {
|
|
24
11
|
return this.file;
|
|
25
12
|
}
|
|
@@ -31,6 +18,19 @@ class DataTransferItemStub {
|
|
|
31
18
|
/* istanbul ignore next */ webkitGetAsEntry() {
|
|
32
19
|
throw new Error('not implemented');
|
|
33
20
|
}
|
|
21
|
+
constructor(dataOrFile, type){
|
|
22
|
+
this.file = null;
|
|
23
|
+
this.data = undefined;
|
|
24
|
+
if (typeof dataOrFile === 'string') {
|
|
25
|
+
this.kind = 'string';
|
|
26
|
+
this.type = String(type);
|
|
27
|
+
this.data = dataOrFile;
|
|
28
|
+
} else {
|
|
29
|
+
this.kind = 'file';
|
|
30
|
+
this.type = dataOrFile.type;
|
|
31
|
+
this.file = dataOrFile;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
35
|
class DataTransferItemListStub extends Array {
|
|
36
36
|
add(...args) {
|
|
@@ -55,9 +55,10 @@ function getTypeMatcher(type, exact) {
|
|
|
55
55
|
function createDataTransferStub(window) {
|
|
56
56
|
return new class DataTransferStub {
|
|
57
57
|
getData(format) {
|
|
58
|
-
|
|
58
|
+
var ref;
|
|
59
|
+
const match = (ref = this.items.find(getTypeMatcher(format, true))) !== null && ref !== void 0 ? ref : this.items.find(getTypeMatcher(format, false));
|
|
59
60
|
let text = '';
|
|
60
|
-
match
|
|
61
|
+
match === null || match === void 0 ? void 0 : match.getAsString((t)=>{
|
|
61
62
|
text = t;
|
|
62
63
|
});
|
|
63
64
|
return text;
|
|
@@ -81,10 +82,6 @@ function createDataTransferStub(window) {
|
|
|
81
82
|
this.items.clear();
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
dropEffect = 'none';
|
|
85
|
-
effectAllowed = 'uninitialized';
|
|
86
|
-
items = new DataTransferItemListStub();
|
|
87
|
-
files = FileList.createFileList(window, []);
|
|
88
85
|
get types() {
|
|
89
86
|
const t = [];
|
|
90
87
|
if (this.files.length) {
|
|
@@ -95,6 +92,12 @@ function createDataTransferStub(window) {
|
|
|
95
92
|
return t;
|
|
96
93
|
}
|
|
97
94
|
/* istanbul ignore next */ setDragImage() {}
|
|
95
|
+
constructor(){
|
|
96
|
+
this.dropEffect = 'none';
|
|
97
|
+
this.effectAllowed = 'uninitialized';
|
|
98
|
+
this.items = new DataTransferItemListStub();
|
|
99
|
+
this.files = FileList.createFileList(window, []);
|
|
100
|
+
}
|
|
98
101
|
}();
|
|
99
102
|
}
|
|
100
103
|
function createDataTransfer(window, files = []) {
|
|
@@ -152,11 +152,12 @@ function commitInput(config, element, newOffset, inputInit) {
|
|
|
152
152
|
value.commitValueAfterInput(element, newOffset);
|
|
153
153
|
}
|
|
154
154
|
function isValidNumberInput(value) {
|
|
155
|
+
var ref, ref1;
|
|
155
156
|
// the browser allows some invalid input but not others
|
|
156
157
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
157
158
|
// it allows one '.' at any place before e
|
|
158
159
|
const valueParts = value.split('e', 2);
|
|
159
|
-
return !(/[^\d.\-e]/.test(value) || Number(value.match(/-/g)
|
|
160
|
+
return !(/[^\d.\-e]/.test(value) || Number((ref = value.match(/-/g)) === null || ref === void 0 ? void 0 : ref.length) > 2 || Number((ref1 = value.match(/\./g)) === null || ref1 === void 0 ? void 0 : ref1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
160
161
|
}
|
|
161
162
|
|
|
162
163
|
exports.input = input;
|
|
@@ -28,7 +28,8 @@ function getSanitizedMaxLength(element) {
|
|
|
28
28
|
if (!supportsMaxLength(element)) {
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
var ref;
|
|
32
|
+
const attr = (ref = element.getAttribute('maxlength')) !== null && ref !== void 0 ? ref : '';
|
|
32
33
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
|
|
33
34
|
}
|
|
34
35
|
function supportsMaxLength(element) {
|
|
@@ -15,7 +15,8 @@ function restoreProperty(obj, prop, descriptor) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function setFiles(el, files) {
|
|
18
|
-
|
|
18
|
+
var ref;
|
|
19
|
+
(ref = el[fakeFiles]) === null || ref === void 0 ? void 0 : ref.restore();
|
|
19
20
|
const typeDescr = Object.getOwnPropertyDescriptor(el, 'type');
|
|
20
21
|
const valueDescr = Object.getOwnPropertyDescriptor(el, 'value');
|
|
21
22
|
const filesDescr = Object.getOwnPropertyDescriptor(el, 'files');
|
|
@@ -39,7 +40,8 @@ function setFiles(el, files) {
|
|
|
39
40
|
if (v === '') {
|
|
40
41
|
restore();
|
|
41
42
|
} else {
|
|
42
|
-
|
|
43
|
+
var ref;
|
|
44
|
+
valueDescr === null || valueDescr === void 0 ? void 0 : (ref = valueDescr.set) === null || ref === void 0 ? void 0 : ref.call(el, v);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
},
|
|
@@ -120,13 +120,14 @@ function isTextNode(node) {
|
|
|
120
120
|
}
|
|
121
121
|
function walkNodes(node, direction, callback) {
|
|
122
122
|
for(;;){
|
|
123
|
+
var ref;
|
|
123
124
|
const sibling = node[`${direction}Sibling`];
|
|
124
125
|
if (sibling) {
|
|
125
126
|
node = getDescendant(sibling, direction === 'next' ? 'first' : 'last');
|
|
126
127
|
if (callback(node)) {
|
|
127
128
|
return node;
|
|
128
129
|
}
|
|
129
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable.isContentEditable(node.parentNode) && node.parentNode !== node.ownerDocument
|
|
130
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable.isContentEditable(node.parentNode) && node.parentNode !== ((ref = node.ownerDocument) === null || ref === void 0 ? void 0 : ref.body))) {
|
|
130
131
|
node = node.parentNode;
|
|
131
132
|
} else {
|
|
132
133
|
break;
|
|
@@ -13,14 +13,17 @@ var selection = require('./selection.js');
|
|
|
13
13
|
*/ function focus(element) {
|
|
14
14
|
const target = findClosest.findClosest(element, isFocusable.isFocusable);
|
|
15
15
|
const activeElement = getActiveElement.getActiveElement(element.ownerDocument);
|
|
16
|
-
if ((target
|
|
16
|
+
if ((target !== null && target !== void 0 ? target : element.ownerDocument.body) === activeElement) {
|
|
17
17
|
return;
|
|
18
18
|
} else if (target) {
|
|
19
19
|
eventWrapper.eventWrapper(()=>target.focus());
|
|
20
20
|
} else {
|
|
21
|
-
eventWrapper.eventWrapper(()=>
|
|
21
|
+
eventWrapper.eventWrapper(()=>{
|
|
22
|
+
var ref;
|
|
23
|
+
return (ref = activeElement) === null || ref === void 0 ? void 0 : ref.blur();
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
|
-
selection.updateSelectionOnFocus(target
|
|
26
|
+
selection.updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
exports.focus = focus;
|
|
@@ -6,7 +6,7 @@ var isDisabled = require('../misc/isDisabled.js');
|
|
|
6
6
|
|
|
7
7
|
function getActiveElement(document) {
|
|
8
8
|
const activeElement = document.activeElement;
|
|
9
|
-
if (activeElement
|
|
9
|
+
if (activeElement === null || activeElement === void 0 ? void 0 : activeElement.shadowRoot) {
|
|
10
10
|
return getActiveElement(activeElement.shadowRoot);
|
|
11
11
|
} else {
|
|
12
12
|
// Browser does not yield disabled elements as document.activeElement - jsdom does
|
|
@@ -17,7 +17,8 @@ function getActiveElement(document) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
function getActiveElementOrBody(document) {
|
|
20
|
-
|
|
20
|
+
var ref;
|
|
21
|
+
return (ref = getActiveElement(document)) !== null && ref !== void 0 ? ref : /* istanbul ignore next */ document.body;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
exports.getActiveElement = getActiveElement;
|
|
@@ -25,12 +25,12 @@ function resolveCaretPosition({ target , node , offset }) {
|
|
|
25
25
|
if (selection.hasOwnSelection(target)) {
|
|
26
26
|
return {
|
|
27
27
|
node: target,
|
|
28
|
-
offset: offset
|
|
28
|
+
offset: offset !== null && offset !== void 0 ? offset : value.getUIValue(target).length
|
|
29
29
|
};
|
|
30
30
|
} else if (node) {
|
|
31
31
|
return {
|
|
32
32
|
node,
|
|
33
|
-
offset: offset
|
|
33
|
+
offset: offset !== null && offset !== void 0 ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
return findNodeAtTextOffset(target, offset);
|
|
@@ -62,7 +62,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
62
62
|
if (c.nodeType === 3) {
|
|
63
63
|
return {
|
|
64
64
|
node: c,
|
|
65
|
-
offset: offset
|
|
65
|
+
offset: offset !== null && offset !== void 0 ? offset : c.nodeValue.length
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -34,7 +34,8 @@ var value = require('../../document/value.js');
|
|
|
34
34
|
focusOffset: value.getUIValue(target).length
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
var ref;
|
|
38
|
+
const focusNode = (ref = isContentEditable.getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body;
|
|
38
39
|
selection.setSelection({
|
|
39
40
|
focusNode,
|
|
40
41
|
anchorOffset: 0,
|
|
@@ -45,9 +46,10 @@ function isAllSelected(target) {
|
|
|
45
46
|
if (isElementType.isElementType(target, 'textarea') || isElementType.isElementType(target, 'input') && target.type in isEditable.editableInputTypes) {
|
|
46
47
|
return selection$1.getUISelection(target).startOffset === 0 && selection$1.getUISelection(target).endOffset === value.getUIValue(target).length;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
var ref;
|
|
50
|
+
const focusNode = (ref = isContentEditable.getContentEditable(target)) !== null && ref !== void 0 ? ref : target.ownerDocument.body;
|
|
49
51
|
const selection = target.ownerDocument.getSelection();
|
|
50
|
-
return selection
|
|
52
|
+
return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
exports.isAllSelected = isAllSelected;
|