@testing-library/user-event 14.6.6 → 14.6.7
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.
|
@@ -43,9 +43,15 @@ class DataTransferItemStub {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
function toAsciiLowercase(value) {
|
|
47
|
+
return value.replace(/[A-Z]/g, (char)=>char.toLowerCase());
|
|
48
|
+
}
|
|
46
49
|
class DataTransferItemListStub extends Array {
|
|
47
50
|
add(...args) {
|
|
48
|
-
|
|
51
|
+
// The spec converts the type to ASCII lowercase here, but - unlike
|
|
52
|
+
// `setData()` - does not replace the `text` and `url` shorthands.
|
|
53
|
+
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-add
|
|
54
|
+
const item = typeof args[0] === 'string' ? new DataTransferItemStub(args[0], toAsciiLowercase(args[1])) : new DataTransferItemStub(args[0]);
|
|
49
55
|
this.push(item);
|
|
50
56
|
return item;
|
|
51
57
|
}
|
|
@@ -56,6 +62,13 @@ class DataTransferItemListStub extends Array {
|
|
|
56
62
|
this.splice(index, 1);
|
|
57
63
|
}
|
|
58
64
|
}
|
|
65
|
+
// The spec requires the format to be converted to ASCII lowercase
|
|
66
|
+
// and the shorthands `text` and `url` to be replaced with their MIME types.
|
|
67
|
+
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-setdata
|
|
68
|
+
function normalizeFormat(format) {
|
|
69
|
+
const type = toAsciiLowercase(format);
|
|
70
|
+
return type === 'text' ? 'text/plain' : type === 'url' ? 'text/uri-list' : type;
|
|
71
|
+
}
|
|
59
72
|
function getTypeMatcher(type, exact) {
|
|
60
73
|
const [group, sub] = type.split('/');
|
|
61
74
|
const isGroup = !sub || sub === '*';
|
|
@@ -67,7 +80,8 @@ function createDataTransferStub(window) {
|
|
|
67
80
|
return new class DataTransferStub {
|
|
68
81
|
getData(format) {
|
|
69
82
|
var _this_items_find;
|
|
70
|
-
const
|
|
83
|
+
const type = normalizeFormat(format);
|
|
84
|
+
const match = (_this_items_find = this.items.find(getTypeMatcher(type, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(type, false));
|
|
71
85
|
let text = '';
|
|
72
86
|
match === null || match === void 0 ? void 0 : match.getAsString((t)=>{
|
|
73
87
|
text = t;
|
|
@@ -75,8 +89,9 @@ function createDataTransferStub(window) {
|
|
|
75
89
|
return text;
|
|
76
90
|
}
|
|
77
91
|
setData(format, data) {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
92
|
+
const type = normalizeFormat(format);
|
|
93
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
|
|
94
|
+
const item = new DataTransferItemStub(data, type);
|
|
80
95
|
if (matchIndex >= 0) {
|
|
81
96
|
this.items.splice(matchIndex, 1, item);
|
|
82
97
|
} else {
|
|
@@ -85,7 +100,8 @@ function createDataTransferStub(window) {
|
|
|
85
100
|
}
|
|
86
101
|
clearData(format) {
|
|
87
102
|
if (format) {
|
|
88
|
-
const
|
|
103
|
+
const type = normalizeFormat(format);
|
|
104
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
|
|
89
105
|
if (matchIndex >= 0) {
|
|
90
106
|
this.items.remove(matchIndex);
|
|
91
107
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var isDisabled = require('../misc/isDisabled.js');
|
|
4
|
+
var isElementType = require('../misc/isElementType.js');
|
|
4
5
|
|
|
5
6
|
function getActiveElement(document) {
|
|
6
7
|
const activeElement = document.activeElement;
|
|
@@ -9,6 +10,11 @@ function getActiveElement(document) {
|
|
|
9
10
|
if (activeElementInShadowTree) {
|
|
10
11
|
return activeElementInShadowTree;
|
|
11
12
|
}
|
|
13
|
+
} else if (activeElement && isElementType.isElementType(activeElement, 'iframe')) {
|
|
14
|
+
const contentDocument = activeElement.contentDocument;
|
|
15
|
+
if (contentDocument) {
|
|
16
|
+
return getActiveElement(contentDocument);
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
19
|
// Browser does not yield disabled elements as document.activeElement - jsdom does
|
|
14
20
|
if (isDisabled.isDisabled(activeElement)) {
|
|
@@ -41,9 +41,15 @@ class DataTransferItemStub {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
function toAsciiLowercase(value) {
|
|
45
|
+
return value.replace(/[A-Z]/g, (char)=>char.toLowerCase());
|
|
46
|
+
}
|
|
44
47
|
class DataTransferItemListStub extends Array {
|
|
45
48
|
add(...args) {
|
|
46
|
-
|
|
49
|
+
// The spec converts the type to ASCII lowercase here, but - unlike
|
|
50
|
+
// `setData()` - does not replace the `text` and `url` shorthands.
|
|
51
|
+
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-add
|
|
52
|
+
const item = typeof args[0] === 'string' ? new DataTransferItemStub(args[0], toAsciiLowercase(args[1])) : new DataTransferItemStub(args[0]);
|
|
47
53
|
this.push(item);
|
|
48
54
|
return item;
|
|
49
55
|
}
|
|
@@ -54,6 +60,13 @@ class DataTransferItemListStub extends Array {
|
|
|
54
60
|
this.splice(index, 1);
|
|
55
61
|
}
|
|
56
62
|
}
|
|
63
|
+
// The spec requires the format to be converted to ASCII lowercase
|
|
64
|
+
// and the shorthands `text` and `url` to be replaced with their MIME types.
|
|
65
|
+
// https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-setdata
|
|
66
|
+
function normalizeFormat(format) {
|
|
67
|
+
const type = toAsciiLowercase(format);
|
|
68
|
+
return type === 'text' ? 'text/plain' : type === 'url' ? 'text/uri-list' : type;
|
|
69
|
+
}
|
|
57
70
|
function getTypeMatcher(type, exact) {
|
|
58
71
|
const [group, sub] = type.split('/');
|
|
59
72
|
const isGroup = !sub || sub === '*';
|
|
@@ -65,7 +78,8 @@ function createDataTransferStub(window) {
|
|
|
65
78
|
return new class DataTransferStub {
|
|
66
79
|
getData(format) {
|
|
67
80
|
var _this_items_find;
|
|
68
|
-
const
|
|
81
|
+
const type = normalizeFormat(format);
|
|
82
|
+
const match = (_this_items_find = this.items.find(getTypeMatcher(type, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(type, false));
|
|
69
83
|
let text = '';
|
|
70
84
|
match === null || match === void 0 ? void 0 : match.getAsString((t)=>{
|
|
71
85
|
text = t;
|
|
@@ -73,8 +87,9 @@ function createDataTransferStub(window) {
|
|
|
73
87
|
return text;
|
|
74
88
|
}
|
|
75
89
|
setData(format, data) {
|
|
76
|
-
const
|
|
77
|
-
const
|
|
90
|
+
const type = normalizeFormat(format);
|
|
91
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
|
|
92
|
+
const item = new DataTransferItemStub(data, type);
|
|
78
93
|
if (matchIndex >= 0) {
|
|
79
94
|
this.items.splice(matchIndex, 1, item);
|
|
80
95
|
} else {
|
|
@@ -83,7 +98,8 @@ function createDataTransferStub(window) {
|
|
|
83
98
|
}
|
|
84
99
|
clearData(format) {
|
|
85
100
|
if (format) {
|
|
86
|
-
const
|
|
101
|
+
const type = normalizeFormat(format);
|
|
102
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
|
|
87
103
|
if (matchIndex >= 0) {
|
|
88
104
|
this.items.remove(matchIndex);
|
|
89
105
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDisabled } from '../misc/isDisabled.js';
|
|
2
|
+
import { isElementType } from '../misc/isElementType.js';
|
|
2
3
|
|
|
3
4
|
function getActiveElement(document) {
|
|
4
5
|
const activeElement = document.activeElement;
|
|
@@ -7,6 +8,11 @@ function getActiveElement(document) {
|
|
|
7
8
|
if (activeElementInShadowTree) {
|
|
8
9
|
return activeElementInShadowTree;
|
|
9
10
|
}
|
|
11
|
+
} else if (activeElement && isElementType(activeElement, 'iframe')) {
|
|
12
|
+
const contentDocument = activeElement.contentDocument;
|
|
13
|
+
if (contentDocument) {
|
|
14
|
+
return getActiveElement(contentDocument);
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
// Browser does not yield disabled elements as document.activeElement - jsdom does
|
|
12
18
|
if (isDisabled(activeElement)) {
|