@testing-library/user-event 14.2.3 → 14.2.6
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/index.cjs +96 -86
- package/dist/index.mjs +98 -87
- package/dist/types/document/index.d.ts +1 -1
- package/dist/types/document/interceptor.d.ts +1 -1
- package/dist/types/document/selection.d.ts +1 -0
- package/dist/types/document/value.d.ts +5 -6
- package/dist/types/utils/dataTransfer/FileList.d.ts +1 -1
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +6 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ function readBlobText(blob, FileReader) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
// src/utils/dataTransfer/FileList.ts
|
|
72
|
-
function createFileList(files) {
|
|
72
|
+
function createFileList(window, files) {
|
|
73
73
|
const list = {
|
|
74
74
|
...files,
|
|
75
75
|
length: files.length,
|
|
@@ -80,8 +80,8 @@ function createFileList(files) {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
list.constructor = FileList;
|
|
84
|
-
Object.setPrototypeOf(list, FileList.prototype);
|
|
83
|
+
list.constructor = window.FileList;
|
|
84
|
+
Object.setPrototypeOf(list, window.FileList.prototype);
|
|
85
85
|
Object.freeze(list);
|
|
86
86
|
return list;
|
|
87
87
|
}
|
|
@@ -133,56 +133,58 @@ function getTypeMatcher(type3, exact) {
|
|
|
133
133
|
return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
getData(format) {
|
|
144
|
-
var _a;
|
|
145
|
-
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
146
|
-
let text = "";
|
|
147
|
-
match == null ? void 0 : match.getAsString((t) => {
|
|
148
|
-
text = t;
|
|
149
|
-
});
|
|
150
|
-
return text;
|
|
151
|
-
}
|
|
152
|
-
setData(format, data) {
|
|
153
|
-
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
154
|
-
const item = new DataTransferItemStub(data, format);
|
|
155
|
-
if (matchIndex >= 0) {
|
|
156
|
-
this.items.splice(matchIndex, 1, item);
|
|
157
|
-
} else {
|
|
158
|
-
this.items.push(item);
|
|
136
|
+
function createDataTransferStub(window) {
|
|
137
|
+
return new class DataTransferStub {
|
|
138
|
+
constructor() {
|
|
139
|
+
this.dropEffect = "none";
|
|
140
|
+
this.effectAllowed = "uninitialized";
|
|
141
|
+
this.items = new DataTransferItemListStub();
|
|
142
|
+
this.files = createFileList(window, []);
|
|
159
143
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
144
|
+
getData(format) {
|
|
145
|
+
var _a;
|
|
146
|
+
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
147
|
+
let text = "";
|
|
148
|
+
match == null ? void 0 : match.getAsString((t) => {
|
|
149
|
+
text = t;
|
|
150
|
+
});
|
|
151
|
+
return text;
|
|
152
|
+
}
|
|
153
|
+
setData(format, data) {
|
|
163
154
|
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
155
|
+
const item = new DataTransferItemStub(data, format);
|
|
164
156
|
if (matchIndex >= 0) {
|
|
165
|
-
this.items.
|
|
157
|
+
this.items.splice(matchIndex, 1, item);
|
|
158
|
+
} else {
|
|
159
|
+
this.items.push(item);
|
|
166
160
|
}
|
|
167
|
-
} else {
|
|
168
|
-
this.items.clear();
|
|
169
161
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
162
|
+
clearData(format) {
|
|
163
|
+
if (format) {
|
|
164
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
165
|
+
if (matchIndex >= 0) {
|
|
166
|
+
this.items.remove(matchIndex);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
this.items.clear();
|
|
170
|
+
}
|
|
175
171
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
172
|
+
get types() {
|
|
173
|
+
const t = [];
|
|
174
|
+
if (this.files.length) {
|
|
175
|
+
t.push("Files");
|
|
176
|
+
}
|
|
177
|
+
this.items.forEach((i) => t.push(i.type));
|
|
178
|
+
Object.freeze(t);
|
|
179
|
+
return t;
|
|
180
|
+
}
|
|
181
|
+
setDragImage() {
|
|
182
|
+
}
|
|
183
|
+
}();
|
|
184
|
+
}
|
|
183
185
|
function createDataTransfer(window, files = []) {
|
|
184
|
-
const dt = typeof window.DataTransfer === "undefined" ?
|
|
185
|
-
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
186
|
+
const dt = typeof window.DataTransfer === "undefined" ? createDataTransferStub(window) : new window.DataTransfer();
|
|
187
|
+
Object.defineProperty(dt, "files", { get: () => createFileList(window, files) });
|
|
186
188
|
return dt;
|
|
187
189
|
}
|
|
188
190
|
function getBlobFromDataTransferItem(window, item) {
|
|
@@ -546,15 +548,8 @@ function calculateNewValue(inputData, node, {
|
|
|
546
548
|
};
|
|
547
549
|
}
|
|
548
550
|
function commitInput(config, element, newOffset, inputInit) {
|
|
549
|
-
startTrackValue(element);
|
|
550
551
|
dispatchUIEvent(config, element, "input", inputInit);
|
|
551
|
-
|
|
552
|
-
setSelection({
|
|
553
|
-
focusNode: element,
|
|
554
|
-
anchorOffset: newOffset,
|
|
555
|
-
focusOffset: newOffset
|
|
556
|
-
});
|
|
557
|
-
}
|
|
552
|
+
commitValueAfterInput(element, newOffset);
|
|
558
553
|
}
|
|
559
554
|
function isValidNumberInput(value) {
|
|
560
555
|
var _a, _b;
|
|
@@ -1325,9 +1320,9 @@ var defaultOptionsSetup = {
|
|
|
1325
1320
|
};
|
|
1326
1321
|
|
|
1327
1322
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1328
|
-
function hasPointerEvents(element) {
|
|
1323
|
+
function hasPointerEvents(config, element) {
|
|
1329
1324
|
var _a;
|
|
1330
|
-
return ((_a =
|
|
1325
|
+
return ((_a = checkPointerEvents(config, element)) == null ? void 0 : _a.pointerEvents) !== "none";
|
|
1331
1326
|
}
|
|
1332
1327
|
function closestPointerEventsDeclaration(element) {
|
|
1333
1328
|
const window = getWindow(element);
|
|
@@ -1341,18 +1336,22 @@ function closestPointerEventsDeclaration(element) {
|
|
|
1341
1336
|
return void 0;
|
|
1342
1337
|
}
|
|
1343
1338
|
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1344
|
-
function
|
|
1339
|
+
function checkPointerEvents(config, element) {
|
|
1345
1340
|
const lastCheck = element[PointerEventsCheck];
|
|
1346
1341
|
const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
|
|
1347
1342
|
if (!needsCheck) {
|
|
1348
|
-
return;
|
|
1343
|
+
return lastCheck == null ? void 0 : lastCheck.result;
|
|
1349
1344
|
}
|
|
1350
1345
|
const declaration = closestPointerEventsDeclaration(element);
|
|
1351
1346
|
element[PointerEventsCheck] = {
|
|
1352
1347
|
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1353
1348
|
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1354
|
-
result:
|
|
1349
|
+
result: declaration
|
|
1355
1350
|
};
|
|
1351
|
+
return declaration;
|
|
1352
|
+
}
|
|
1353
|
+
function assertPointerEvents(config, element) {
|
|
1354
|
+
const declaration = checkPointerEvents(config, element);
|
|
1356
1355
|
if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
|
|
1357
1356
|
throw new Error([
|
|
1358
1357
|
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
@@ -1740,7 +1739,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
1740
1739
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1741
1740
|
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1742
1741
|
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1743
|
-
|
|
1742
|
+
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
1744
1743
|
}
|
|
1745
1744
|
function intercept(...args) {
|
|
1746
1745
|
const {
|
|
@@ -1829,6 +1828,9 @@ function getUISelection(element) {
|
|
|
1829
1828
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1830
1829
|
};
|
|
1831
1830
|
}
|
|
1831
|
+
function hasUISelection(element) {
|
|
1832
|
+
return !!element[UISelection];
|
|
1833
|
+
}
|
|
1832
1834
|
function setUISelectionClean(element) {
|
|
1833
1835
|
element[UISelection] = void 0;
|
|
1834
1836
|
}
|
|
@@ -1841,7 +1843,7 @@ function valueInterceptor(v) {
|
|
|
1841
1843
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1842
1844
|
if (isUI) {
|
|
1843
1845
|
this[UIValue] = String(v);
|
|
1844
|
-
|
|
1846
|
+
startTrackValue(this);
|
|
1845
1847
|
}
|
|
1846
1848
|
return {
|
|
1847
1849
|
applyNative: !!isUI,
|
|
@@ -1879,36 +1881,42 @@ function clearInitialValue(element) {
|
|
|
1879
1881
|
function getInitialValue(element) {
|
|
1880
1882
|
return element[InitialValue];
|
|
1881
1883
|
}
|
|
1882
|
-
function
|
|
1883
|
-
element
|
|
1884
|
+
function isReact17Element(element) {
|
|
1885
|
+
return Object.getOwnPropertyNames(element).some((k) => k.startsWith("__react")) && getWindow(element).REACT_VERSION === 17;
|
|
1884
1886
|
}
|
|
1885
1887
|
function startTrackValue(element) {
|
|
1888
|
+
if (!isReact17Element(element)) {
|
|
1889
|
+
return;
|
|
1890
|
+
}
|
|
1886
1891
|
element[TrackChanges] = {
|
|
1887
|
-
|
|
1888
|
-
nextValue: String(element.value),
|
|
1892
|
+
previousValue: String(element.value),
|
|
1889
1893
|
tracked: []
|
|
1890
1894
|
};
|
|
1891
1895
|
}
|
|
1892
1896
|
function trackOrSetValue(element, v) {
|
|
1893
|
-
var _a, _b
|
|
1897
|
+
var _a, _b;
|
|
1894
1898
|
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1895
|
-
if (!
|
|
1896
|
-
|
|
1899
|
+
if (!element[TrackChanges]) {
|
|
1900
|
+
setUIValueClean(element);
|
|
1901
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1897
1902
|
}
|
|
1898
1903
|
}
|
|
1899
|
-
function
|
|
1900
|
-
|
|
1901
|
-
setUISelection(element, { focusOffset: v.length });
|
|
1902
|
-
}
|
|
1903
|
-
function endTrackValue(element) {
|
|
1904
|
-
var _a, _b;
|
|
1904
|
+
function commitValueAfterInput(element, cursorOffset) {
|
|
1905
|
+
var _a;
|
|
1905
1906
|
const changes = element[TrackChanges];
|
|
1906
1907
|
element[TrackChanges] = void 0;
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1908
|
+
if (!((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length)) {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
1912
|
+
if (!isJustReactStateUpdate) {
|
|
1913
|
+
setUIValueClean(element);
|
|
1914
|
+
}
|
|
1915
|
+
if (hasUISelection(element)) {
|
|
1916
|
+
setUISelection(element, {
|
|
1917
|
+
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
|
|
1918
|
+
});
|
|
1910
1919
|
}
|
|
1911
|
-
return isJustReactStateUpdate;
|
|
1912
1920
|
}
|
|
1913
1921
|
|
|
1914
1922
|
// src/document/setRangeText.ts
|
|
@@ -1959,7 +1967,7 @@ function prepareElement(el) {
|
|
|
1959
1967
|
if (el[isPrepared]) {
|
|
1960
1968
|
return;
|
|
1961
1969
|
}
|
|
1962
|
-
if ("
|
|
1970
|
+
if (isElementType(el, ["input", "textarea"])) {
|
|
1963
1971
|
prepareValueInterceptor(el);
|
|
1964
1972
|
prepareSelectionInterceptor(el);
|
|
1965
1973
|
prepareRangeTextInterceptor(el);
|
|
@@ -2263,10 +2271,11 @@ async function pointerMove(config, { pointerName = "mouse", target, coords, node
|
|
|
2263
2271
|
} = pointerState.position[pointerName];
|
|
2264
2272
|
if (prevTarget && prevTarget !== target) {
|
|
2265
2273
|
setLevelRef(config, 2 /* Trigger */);
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2274
|
+
if (hasPointerEvents(config, prevTarget)) {
|
|
2275
|
+
fireMove(prevTarget, prevCoords);
|
|
2276
|
+
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
2277
|
+
fireLeave(prevTarget, prevCoords);
|
|
2278
|
+
}
|
|
2270
2279
|
}
|
|
2271
2280
|
}
|
|
2272
2281
|
setLevelRef(config, 2 /* Trigger */);
|
|
@@ -2670,6 +2679,7 @@ async function hover(element) {
|
|
|
2670
2679
|
return this.pointer({ target: element });
|
|
2671
2680
|
}
|
|
2672
2681
|
async function unhover(element) {
|
|
2682
|
+
assertPointerEvents(this[Config], this[Config].pointerState.position.mouse.target);
|
|
2673
2683
|
return this.pointer({ target: element.ownerDocument.body });
|
|
2674
2684
|
}
|
|
2675
2685
|
|
|
@@ -2788,7 +2798,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2788
2798
|
if (isElementType(select, "select")) {
|
|
2789
2799
|
if (select.multiple) {
|
|
2790
2800
|
for (const option of selectedOptions) {
|
|
2791
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2801
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option);
|
|
2792
2802
|
if (withPointerEvents) {
|
|
2793
2803
|
this.dispatchUIEvent(option, "pointerover");
|
|
2794
2804
|
this.dispatchUIEvent(select, "pointerenter");
|
|
@@ -2811,7 +2821,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2811
2821
|
await wait(this[Config]);
|
|
2812
2822
|
}
|
|
2813
2823
|
} else if (selectedOptions.length === 1) {
|
|
2814
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2824
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select);
|
|
2815
2825
|
if (withPointerEvents) {
|
|
2816
2826
|
await this.click(select);
|
|
2817
2827
|
} else {
|
|
@@ -2879,7 +2889,7 @@ async function upload(element, fileOrFiles) {
|
|
|
2879
2889
|
})) {
|
|
2880
2890
|
return;
|
|
2881
2891
|
}
|
|
2882
|
-
setFiles(input2, createFileList(files));
|
|
2892
|
+
setFiles(input2, createFileList(getWindow(element), files));
|
|
2883
2893
|
this.dispatchUIEvent(input2, "input");
|
|
2884
2894
|
this.dispatchUIEvent(input2, "change");
|
|
2885
2895
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -87,7 +87,7 @@ function readBlobText(blob, FileReader) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// src/utils/dataTransfer/FileList.ts
|
|
90
|
-
function createFileList(files) {
|
|
90
|
+
function createFileList(window, files) {
|
|
91
91
|
const list = __spreadProps(__spreadValues({}, files), {
|
|
92
92
|
length: files.length,
|
|
93
93
|
item: (index) => list[index],
|
|
@@ -97,8 +97,8 @@ function createFileList(files) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
|
-
list.constructor = FileList;
|
|
101
|
-
Object.setPrototypeOf(list, FileList.prototype);
|
|
100
|
+
list.constructor = window.FileList;
|
|
101
|
+
Object.setPrototypeOf(list, window.FileList.prototype);
|
|
102
102
|
Object.freeze(list);
|
|
103
103
|
return list;
|
|
104
104
|
}
|
|
@@ -150,56 +150,58 @@ function getTypeMatcher(type3, exact) {
|
|
|
150
150
|
return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
getData(format) {
|
|
161
|
-
var _a;
|
|
162
|
-
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
163
|
-
let text = "";
|
|
164
|
-
match == null ? void 0 : match.getAsString((t) => {
|
|
165
|
-
text = t;
|
|
166
|
-
});
|
|
167
|
-
return text;
|
|
168
|
-
}
|
|
169
|
-
setData(format, data) {
|
|
170
|
-
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
171
|
-
const item = new DataTransferItemStub(data, format);
|
|
172
|
-
if (matchIndex >= 0) {
|
|
173
|
-
this.items.splice(matchIndex, 1, item);
|
|
174
|
-
} else {
|
|
175
|
-
this.items.push(item);
|
|
153
|
+
function createDataTransferStub(window) {
|
|
154
|
+
return new class DataTransferStub {
|
|
155
|
+
constructor() {
|
|
156
|
+
this.dropEffect = "none";
|
|
157
|
+
this.effectAllowed = "uninitialized";
|
|
158
|
+
this.items = new DataTransferItemListStub();
|
|
159
|
+
this.files = createFileList(window, []);
|
|
176
160
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
161
|
+
getData(format) {
|
|
162
|
+
var _a;
|
|
163
|
+
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
164
|
+
let text = "";
|
|
165
|
+
match == null ? void 0 : match.getAsString((t) => {
|
|
166
|
+
text = t;
|
|
167
|
+
});
|
|
168
|
+
return text;
|
|
169
|
+
}
|
|
170
|
+
setData(format, data) {
|
|
180
171
|
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
172
|
+
const item = new DataTransferItemStub(data, format);
|
|
181
173
|
if (matchIndex >= 0) {
|
|
182
|
-
this.items.
|
|
174
|
+
this.items.splice(matchIndex, 1, item);
|
|
175
|
+
} else {
|
|
176
|
+
this.items.push(item);
|
|
183
177
|
}
|
|
184
|
-
} else {
|
|
185
|
-
this.items.clear();
|
|
186
178
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
179
|
+
clearData(format) {
|
|
180
|
+
if (format) {
|
|
181
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
182
|
+
if (matchIndex >= 0) {
|
|
183
|
+
this.items.remove(matchIndex);
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
this.items.clear();
|
|
187
|
+
}
|
|
192
188
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
189
|
+
get types() {
|
|
190
|
+
const t = [];
|
|
191
|
+
if (this.files.length) {
|
|
192
|
+
t.push("Files");
|
|
193
|
+
}
|
|
194
|
+
this.items.forEach((i) => t.push(i.type));
|
|
195
|
+
Object.freeze(t);
|
|
196
|
+
return t;
|
|
197
|
+
}
|
|
198
|
+
setDragImage() {
|
|
199
|
+
}
|
|
200
|
+
}();
|
|
201
|
+
}
|
|
200
202
|
function createDataTransfer(window, files = []) {
|
|
201
|
-
const dt = typeof window.DataTransfer === "undefined" ?
|
|
202
|
-
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
203
|
+
const dt = typeof window.DataTransfer === "undefined" ? createDataTransferStub(window) : new window.DataTransfer();
|
|
204
|
+
Object.defineProperty(dt, "files", { get: () => createFileList(window, files) });
|
|
203
205
|
return dt;
|
|
204
206
|
}
|
|
205
207
|
function getBlobFromDataTransferItem(window, item) {
|
|
@@ -577,15 +579,8 @@ function calculateNewValue(inputData, node, {
|
|
|
577
579
|
};
|
|
578
580
|
}
|
|
579
581
|
function commitInput(config, element, newOffset, inputInit) {
|
|
580
|
-
startTrackValue(element);
|
|
581
582
|
dispatchUIEvent(config, element, "input", inputInit);
|
|
582
|
-
|
|
583
|
-
setSelection({
|
|
584
|
-
focusNode: element,
|
|
585
|
-
anchorOffset: newOffset,
|
|
586
|
-
focusOffset: newOffset
|
|
587
|
-
});
|
|
588
|
-
}
|
|
583
|
+
commitValueAfterInput(element, newOffset);
|
|
589
584
|
}
|
|
590
585
|
function isValidNumberInput(value) {
|
|
591
586
|
var _a, _b;
|
|
@@ -1339,9 +1334,9 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1339
1334
|
});
|
|
1340
1335
|
|
|
1341
1336
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1342
|
-
function hasPointerEvents(element) {
|
|
1337
|
+
function hasPointerEvents(config, element) {
|
|
1343
1338
|
var _a;
|
|
1344
|
-
return ((_a =
|
|
1339
|
+
return ((_a = checkPointerEvents(config, element)) == null ? void 0 : _a.pointerEvents) !== "none";
|
|
1345
1340
|
}
|
|
1346
1341
|
function closestPointerEventsDeclaration(element) {
|
|
1347
1342
|
const window = getWindow(element);
|
|
@@ -1355,18 +1350,22 @@ function closestPointerEventsDeclaration(element) {
|
|
|
1355
1350
|
return void 0;
|
|
1356
1351
|
}
|
|
1357
1352
|
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1358
|
-
function
|
|
1353
|
+
function checkPointerEvents(config, element) {
|
|
1359
1354
|
const lastCheck = element[PointerEventsCheck];
|
|
1360
1355
|
const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
|
|
1361
1356
|
if (!needsCheck) {
|
|
1362
|
-
return;
|
|
1357
|
+
return lastCheck == null ? void 0 : lastCheck.result;
|
|
1363
1358
|
}
|
|
1364
1359
|
const declaration = closestPointerEventsDeclaration(element);
|
|
1365
1360
|
element[PointerEventsCheck] = {
|
|
1366
1361
|
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1367
1362
|
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1368
|
-
result:
|
|
1363
|
+
result: declaration
|
|
1369
1364
|
};
|
|
1365
|
+
return declaration;
|
|
1366
|
+
}
|
|
1367
|
+
function assertPointerEvents(config, element) {
|
|
1368
|
+
const declaration = checkPointerEvents(config, element);
|
|
1370
1369
|
if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
|
|
1371
1370
|
throw new Error([
|
|
1372
1371
|
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
@@ -1750,7 +1749,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
1750
1749
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1751
1750
|
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1752
1751
|
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1753
|
-
|
|
1752
|
+
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
1754
1753
|
}
|
|
1755
1754
|
function intercept(...args) {
|
|
1756
1755
|
const {
|
|
@@ -1837,6 +1836,9 @@ function getUISelection(element) {
|
|
|
1837
1836
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1838
1837
|
});
|
|
1839
1838
|
}
|
|
1839
|
+
function hasUISelection(element) {
|
|
1840
|
+
return !!element[UISelection];
|
|
1841
|
+
}
|
|
1840
1842
|
function setUISelectionClean(element) {
|
|
1841
1843
|
element[UISelection] = void 0;
|
|
1842
1844
|
}
|
|
@@ -1849,7 +1851,7 @@ function valueInterceptor(v) {
|
|
|
1849
1851
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1850
1852
|
if (isUI) {
|
|
1851
1853
|
this[UIValue] = String(v);
|
|
1852
|
-
|
|
1854
|
+
startTrackValue(this);
|
|
1853
1855
|
}
|
|
1854
1856
|
return {
|
|
1855
1857
|
applyNative: !!isUI,
|
|
@@ -1887,35 +1889,42 @@ function clearInitialValue(element) {
|
|
|
1887
1889
|
function getInitialValue(element) {
|
|
1888
1890
|
return element[InitialValue];
|
|
1889
1891
|
}
|
|
1890
|
-
function
|
|
1891
|
-
element
|
|
1892
|
+
function isReact17Element(element) {
|
|
1893
|
+
return Object.getOwnPropertyNames(element).some((k) => k.startsWith("__react")) && getWindow(element).REACT_VERSION === 17;
|
|
1892
1894
|
}
|
|
1893
1895
|
function startTrackValue(element) {
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
+
if (!isReact17Element(element)) {
|
|
1897
|
+
return;
|
|
1898
|
+
}
|
|
1899
|
+
element[TrackChanges] = {
|
|
1900
|
+
previousValue: String(element.value),
|
|
1896
1901
|
tracked: []
|
|
1897
|
-
}
|
|
1902
|
+
};
|
|
1898
1903
|
}
|
|
1899
1904
|
function trackOrSetValue(element, v) {
|
|
1900
|
-
var _a, _b
|
|
1905
|
+
var _a, _b;
|
|
1901
1906
|
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1902
|
-
if (!
|
|
1903
|
-
|
|
1907
|
+
if (!element[TrackChanges]) {
|
|
1908
|
+
setUIValueClean(element);
|
|
1909
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1904
1910
|
}
|
|
1905
1911
|
}
|
|
1906
|
-
function
|
|
1907
|
-
|
|
1908
|
-
setUISelection(element, { focusOffset: v.length });
|
|
1909
|
-
}
|
|
1910
|
-
function endTrackValue(element) {
|
|
1911
|
-
var _a, _b;
|
|
1912
|
+
function commitValueAfterInput(element, cursorOffset) {
|
|
1913
|
+
var _a;
|
|
1912
1914
|
const changes = element[TrackChanges];
|
|
1913
1915
|
element[TrackChanges] = void 0;
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1916
|
+
if (!((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length)) {
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
1920
|
+
if (!isJustReactStateUpdate) {
|
|
1921
|
+
setUIValueClean(element);
|
|
1922
|
+
}
|
|
1923
|
+
if (hasUISelection(element)) {
|
|
1924
|
+
setUISelection(element, {
|
|
1925
|
+
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
|
|
1926
|
+
});
|
|
1917
1927
|
}
|
|
1918
|
-
return isJustReactStateUpdate;
|
|
1919
1928
|
}
|
|
1920
1929
|
|
|
1921
1930
|
// src/document/setRangeText.ts
|
|
@@ -1966,7 +1975,7 @@ function prepareElement(el) {
|
|
|
1966
1975
|
if (el[isPrepared]) {
|
|
1967
1976
|
return;
|
|
1968
1977
|
}
|
|
1969
|
-
if ("
|
|
1978
|
+
if (isElementType(el, ["input", "textarea"])) {
|
|
1970
1979
|
prepareValueInterceptor(el);
|
|
1971
1980
|
prepareSelectionInterceptor(el);
|
|
1972
1981
|
prepareRangeTextInterceptor(el);
|
|
@@ -2282,10 +2291,11 @@ function pointerMove(_0, _1) {
|
|
|
2282
2291
|
} = pointerState.position[pointerName];
|
|
2283
2292
|
if (prevTarget && prevTarget !== target) {
|
|
2284
2293
|
setLevelRef(config, 2 /* Trigger */);
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2294
|
+
if (hasPointerEvents(config, prevTarget)) {
|
|
2295
|
+
fireMove(prevTarget, prevCoords);
|
|
2296
|
+
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
2297
|
+
fireLeave(prevTarget, prevCoords);
|
|
2298
|
+
}
|
|
2289
2299
|
}
|
|
2290
2300
|
}
|
|
2291
2301
|
setLevelRef(config, 2 /* Trigger */);
|
|
@@ -2699,6 +2709,7 @@ function hover(element) {
|
|
|
2699
2709
|
}
|
|
2700
2710
|
function unhover(element) {
|
|
2701
2711
|
return __async(this, null, function* () {
|
|
2712
|
+
assertPointerEvents(this[Config], this[Config].pointerState.position.mouse.target);
|
|
2702
2713
|
return this.pointer({ target: element.ownerDocument.body });
|
|
2703
2714
|
});
|
|
2704
2715
|
}
|
|
@@ -2833,7 +2844,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2833
2844
|
if (isElementType(select, "select")) {
|
|
2834
2845
|
if (select.multiple) {
|
|
2835
2846
|
for (const option of selectedOptions) {
|
|
2836
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2847
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option);
|
|
2837
2848
|
if (withPointerEvents) {
|
|
2838
2849
|
this.dispatchUIEvent(option, "pointerover");
|
|
2839
2850
|
this.dispatchUIEvent(select, "pointerenter");
|
|
@@ -2856,7 +2867,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2856
2867
|
yield wait(this[Config]);
|
|
2857
2868
|
}
|
|
2858
2869
|
} else if (selectedOptions.length === 1) {
|
|
2859
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2870
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select);
|
|
2860
2871
|
if (withPointerEvents) {
|
|
2861
2872
|
yield this.click(select);
|
|
2862
2873
|
} else {
|
|
@@ -2928,7 +2939,7 @@ function upload(element, fileOrFiles) {
|
|
|
2928
2939
|
})) {
|
|
2929
2940
|
return;
|
|
2930
2941
|
}
|
|
2931
|
-
setFiles(input2, createFileList(files));
|
|
2942
|
+
setFiles(input2, createFileList(getWindow(element), files));
|
|
2932
2943
|
this.dispatchUIEvent(input2, "input");
|
|
2933
2944
|
this.dispatchUIEvent(input2, "change");
|
|
2934
2945
|
};
|
|
@@ -5,6 +5,6 @@ declare global {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare function prepareDocument(document: Document): void;
|
|
8
|
-
export { getUIValue, setUIValue,
|
|
8
|
+
export { getUIValue, setUIValue, commitValueAfterInput, clearInitialValue, } from './value';
|
|
9
9
|
export { getUISelection, setUISelection } from './selection';
|
|
10
10
|
export type { UISelectionRange } from './selection';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare type anyFunc = (...a: any[]) => any;
|
|
2
2
|
declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
|
|
3
3
|
declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
|
|
4
|
-
export declare function prepareInterceptor<ElementType extends
|
|
4
|
+
export declare function prepareInterceptor<ElementType extends Element, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
|
|
5
5
|
/**
|
|
6
6
|
* React tracks the changes on element properties.
|
|
7
7
|
* This workaround tries to alter the DOM element without React noticing,
|
|
@@ -23,6 +23,7 @@ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaE
|
|
|
23
23
|
anchorOffset: number;
|
|
24
24
|
focusOffset: number;
|
|
25
25
|
};
|
|
26
|
+
export declare function hasUISelection(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
26
27
|
/** Flag the IDL selection as clean. This does not change the selection. */
|
|
27
28
|
export declare function setUISelectionClean(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
28
29
|
export {};
|
|
@@ -2,6 +2,9 @@ declare const UIValue: unique symbol;
|
|
|
2
2
|
declare const InitialValue: unique symbol;
|
|
3
3
|
declare const TrackChanges: unique symbol;
|
|
4
4
|
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
REACT_VERSION?: number;
|
|
7
|
+
}
|
|
5
8
|
interface Element {
|
|
6
9
|
[UIValue]?: string;
|
|
7
10
|
[InitialValue]?: string;
|
|
@@ -12,16 +15,12 @@ declare global {
|
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
|
-
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
18
|
+
export declare function prepareValueInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
16
19
|
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
17
20
|
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
|
|
18
21
|
/** Flag the IDL value as clean. This does not change the value.*/
|
|
19
22
|
export declare function setUIValueClean(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
20
23
|
export declare function clearInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
21
24
|
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
22
|
-
export declare function
|
|
23
|
-
/**
|
|
24
|
-
* @returns `true` if we recognize a React state reset and update
|
|
25
|
-
*/
|
|
26
|
-
export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
25
|
+
export declare function commitValueAfterInput(element: HTMLInputElement | HTMLTextAreaElement, cursorOffset: number): void;
|
|
27
26
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createFileList(files: File[]): FileList;
|
|
1
|
+
export declare function createFileList(window: Window & typeof globalThis, files: File[]): FileList;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Config } from '../../setup';
|
|
2
2
|
import { ApiLevel } from '..';
|
|
3
|
-
export declare function hasPointerEvents(element: Element): boolean;
|
|
3
|
+
export declare function hasPointerEvents(config: Config, element: Element): boolean;
|
|
4
|
+
declare function closestPointerEventsDeclaration(element: Element): {
|
|
5
|
+
pointerEvents: string;
|
|
6
|
+
tree: Element[];
|
|
7
|
+
} | undefined;
|
|
4
8
|
declare const PointerEventsCheck: unique symbol;
|
|
5
9
|
declare global {
|
|
6
10
|
interface Element {
|
|
7
11
|
[PointerEventsCheck]?: {
|
|
8
12
|
[k in ApiLevel]?: object;
|
|
9
13
|
} & {
|
|
10
|
-
result:
|
|
14
|
+
result: ReturnType<typeof closestPointerEventsDeclaration>;
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
17
|
}
|