@testing-library/user-event 14.1.0 → 14.1.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/index.cjs +195 -201
- package/dist/index.mjs +206 -212
- package/dist/types/options.d.ts +1 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -156,8 +156,8 @@ var DataTransferStub = class {
|
|
|
156
156
|
this.files = createFileList([]);
|
|
157
157
|
}
|
|
158
158
|
getData(format) {
|
|
159
|
-
var
|
|
160
|
-
const match = (
|
|
159
|
+
var _a;
|
|
160
|
+
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
161
161
|
let text = "";
|
|
162
162
|
match == null ? void 0 : match.getAsString((t) => {
|
|
163
163
|
text = t;
|
|
@@ -195,12 +195,12 @@ var DataTransferStub = class {
|
|
|
195
195
|
setDragImage() {
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
|
-
function createDataTransfer(
|
|
199
|
-
const dt = typeof
|
|
198
|
+
function createDataTransfer(window, files = []) {
|
|
199
|
+
const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
|
|
200
200
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
201
201
|
return dt;
|
|
202
202
|
}
|
|
203
|
-
function getBlobFromDataTransferItem(
|
|
203
|
+
function getBlobFromDataTransferItem(window, item) {
|
|
204
204
|
if (item.kind === "file") {
|
|
205
205
|
return item.getAsFile();
|
|
206
206
|
}
|
|
@@ -208,7 +208,7 @@ function getBlobFromDataTransferItem(window2, item) {
|
|
|
208
208
|
item.getAsString((s) => {
|
|
209
209
|
data = s;
|
|
210
210
|
});
|
|
211
|
-
return new
|
|
211
|
+
return new window.Blob([data], { type: item.type });
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
// src/utils/misc/getWindow.ts
|
|
@@ -218,85 +218,78 @@ function getWindow(node) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// src/utils/dataTransfer/Clipboard.ts
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
get types() {
|
|
229
|
-
return Array.from(Object.keys(this.data));
|
|
221
|
+
function createClipboardItem(window, ...blobs) {
|
|
222
|
+
const dataMap = Object.fromEntries(blobs.map((b) => [
|
|
223
|
+
typeof b === "string" ? "text/plain" : b.type,
|
|
224
|
+
Promise.resolve(b)
|
|
225
|
+
]));
|
|
226
|
+
if (typeof window.ClipboardItem !== "undefined") {
|
|
227
|
+
return new window.ClipboardItem(dataMap);
|
|
230
228
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
229
|
+
return new class ClipboardItem {
|
|
230
|
+
constructor(d) {
|
|
231
|
+
this.data = d;
|
|
235
232
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
233
|
+
get types() {
|
|
234
|
+
return Array.from(Object.keys(this.data));
|
|
235
|
+
}
|
|
236
|
+
async getType(type3) {
|
|
237
|
+
const value = await this.data[type3];
|
|
238
|
+
if (!value) {
|
|
239
|
+
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
240
|
+
}
|
|
241
|
+
return value instanceof window.Blob ? value : new window.Blob([value], { type: type3 });
|
|
242
|
+
}
|
|
243
|
+
}(dataMap);
|
|
244
|
+
}
|
|
240
245
|
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
241
|
-
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
246
|
+
function createClipboardStub(window) {
|
|
247
|
+
var _a;
|
|
248
|
+
return new (_a = class extends window.EventTarget {
|
|
249
|
+
constructor() {
|
|
250
|
+
super(...arguments);
|
|
251
|
+
this.items = [];
|
|
252
|
+
}
|
|
253
|
+
async read() {
|
|
254
|
+
return Array.from(this.items);
|
|
255
|
+
}
|
|
256
|
+
async readText() {
|
|
257
|
+
let text = "";
|
|
258
|
+
for (const item of this.items) {
|
|
259
|
+
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
260
|
+
if (type3) {
|
|
261
|
+
text += await item.getType(type3).then((b) => readBlobText(b, window.FileReader));
|
|
262
|
+
}
|
|
257
263
|
}
|
|
264
|
+
return text;
|
|
258
265
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
function createClipboardItem(window2, ...blobs) {
|
|
270
|
-
const data = Object.fromEntries(blobs.map((b) => [
|
|
271
|
-
typeof b === "string" ? "text/plain" : b.type,
|
|
272
|
-
Promise.resolve(b)
|
|
273
|
-
]));
|
|
274
|
-
if (typeof window2.ClipboardItem === "undefined") {
|
|
275
|
-
const item = new ClipboardItemStub(data);
|
|
276
|
-
item[Window] = window2;
|
|
277
|
-
return item;
|
|
278
|
-
} else {
|
|
279
|
-
return new window2.ClipboardItem(data);
|
|
280
|
-
}
|
|
266
|
+
async write(data) {
|
|
267
|
+
this.items = data;
|
|
268
|
+
}
|
|
269
|
+
async writeText(text) {
|
|
270
|
+
this.items = [createClipboardItem(window, text)];
|
|
271
|
+
}
|
|
272
|
+
}, ClipboardStubControl, _a)();
|
|
273
|
+
}
|
|
274
|
+
function isClipboardStub(clipboard) {
|
|
275
|
+
return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
|
|
281
276
|
}
|
|
282
|
-
function attachClipboardStubToView(
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
277
|
+
function attachClipboardStubToView(window) {
|
|
278
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
279
|
+
return window.navigator.clipboard[ClipboardStubControl];
|
|
285
280
|
}
|
|
286
|
-
const realClipboard = Object.getOwnPropertyDescriptor(
|
|
287
|
-
let stub =
|
|
288
|
-
stub[Window] = window2;
|
|
281
|
+
const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
|
|
282
|
+
let stub = createClipboardStub(window);
|
|
289
283
|
const control = {
|
|
290
284
|
resetClipboardStub: () => {
|
|
291
|
-
stub =
|
|
292
|
-
stub[Window] = window2;
|
|
285
|
+
stub = createClipboardStub(window);
|
|
293
286
|
stub[ClipboardStubControl] = control;
|
|
294
287
|
},
|
|
295
288
|
detachClipboardStub: () => {
|
|
296
289
|
if (realClipboard) {
|
|
297
|
-
Object.defineProperty(
|
|
290
|
+
Object.defineProperty(window.navigator, "clipboard", realClipboard);
|
|
298
291
|
} else {
|
|
299
|
-
Object.defineProperty(
|
|
292
|
+
Object.defineProperty(window.navigator, "clipboard", {
|
|
300
293
|
value: void 0,
|
|
301
294
|
configurable: true
|
|
302
295
|
});
|
|
@@ -304,56 +297,56 @@ function attachClipboardStubToView(window2) {
|
|
|
304
297
|
}
|
|
305
298
|
};
|
|
306
299
|
stub[ClipboardStubControl] = control;
|
|
307
|
-
Object.defineProperty(
|
|
300
|
+
Object.defineProperty(window.navigator, "clipboard", {
|
|
308
301
|
get: () => stub,
|
|
309
302
|
configurable: true
|
|
310
303
|
});
|
|
311
304
|
return stub[ClipboardStubControl];
|
|
312
305
|
}
|
|
313
|
-
function resetClipboardStubOnView(
|
|
314
|
-
if (
|
|
315
|
-
|
|
306
|
+
function resetClipboardStubOnView(window) {
|
|
307
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
308
|
+
window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
316
309
|
}
|
|
317
310
|
}
|
|
318
|
-
function detachClipboardStubFromView(
|
|
319
|
-
if (
|
|
320
|
-
|
|
311
|
+
function detachClipboardStubFromView(window) {
|
|
312
|
+
if (isClipboardStub(window.navigator.clipboard)) {
|
|
313
|
+
window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
321
314
|
}
|
|
322
315
|
}
|
|
323
|
-
async function readDataTransferFromClipboard(
|
|
324
|
-
const
|
|
325
|
-
const clipboard =
|
|
316
|
+
async function readDataTransferFromClipboard(document) {
|
|
317
|
+
const window = document.defaultView;
|
|
318
|
+
const clipboard = window == null ? void 0 : window.navigator.clipboard;
|
|
326
319
|
const items = clipboard && await clipboard.read();
|
|
327
320
|
if (!items) {
|
|
328
321
|
throw new Error("The Clipboard API is unavailable.");
|
|
329
322
|
}
|
|
330
|
-
const dt = createDataTransfer(
|
|
323
|
+
const dt = createDataTransfer(window);
|
|
331
324
|
for (const item of items) {
|
|
332
325
|
for (const type3 of item.types) {
|
|
333
|
-
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b,
|
|
326
|
+
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window.FileReader)));
|
|
334
327
|
}
|
|
335
328
|
}
|
|
336
329
|
return dt;
|
|
337
330
|
}
|
|
338
|
-
async function writeDataTransferToClipboard(
|
|
339
|
-
const
|
|
340
|
-
const clipboard =
|
|
331
|
+
async function writeDataTransferToClipboard(document, clipboardData) {
|
|
332
|
+
const window = getWindow(document);
|
|
333
|
+
const clipboard = window.navigator.clipboard;
|
|
341
334
|
const items = [];
|
|
342
335
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
343
336
|
const dtItem = clipboardData.items[i];
|
|
344
|
-
const blob = getBlobFromDataTransferItem(
|
|
345
|
-
items.push(createClipboardItem(
|
|
337
|
+
const blob = getBlobFromDataTransferItem(window, dtItem);
|
|
338
|
+
items.push(createClipboardItem(window, blob));
|
|
346
339
|
}
|
|
347
340
|
const written = clipboard && await clipboard.write(items).then(() => true, () => false);
|
|
348
341
|
if (!written) {
|
|
349
342
|
throw new Error("The Clipboard API is unavailable.");
|
|
350
343
|
}
|
|
351
344
|
}
|
|
352
|
-
if (typeof afterEach === "function") {
|
|
353
|
-
afterEach(() => resetClipboardStubOnView(window));
|
|
345
|
+
if (typeof globalThis.afterEach === "function") {
|
|
346
|
+
globalThis.afterEach(() => resetClipboardStubOnView(globalThis.window));
|
|
354
347
|
}
|
|
355
|
-
if (typeof afterAll === "function") {
|
|
356
|
-
afterAll(() => detachClipboardStubFromView(window));
|
|
348
|
+
if (typeof globalThis.afterAll === "function") {
|
|
349
|
+
globalThis.afterAll(() => detachClipboardStubFromView(globalThis.window));
|
|
357
350
|
}
|
|
358
351
|
|
|
359
352
|
// src/utils/edit/isContentEditable.ts
|
|
@@ -380,6 +373,7 @@ function getValue(element) {
|
|
|
380
373
|
}
|
|
381
374
|
|
|
382
375
|
// src/utils/edit/buildTimeValue.ts
|
|
376
|
+
var parseInt = globalThis.parseInt;
|
|
383
377
|
function buildTimeValue(value) {
|
|
384
378
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
385
379
|
if (onlyDigitsValue.length < 2) {
|
|
@@ -436,11 +430,11 @@ function getSpaceUntilMaxLength(element) {
|
|
|
436
430
|
return maxLength ? maxLength - value.length : void 0;
|
|
437
431
|
}
|
|
438
432
|
function getSanitizedMaxLength(element) {
|
|
439
|
-
var
|
|
433
|
+
var _a;
|
|
440
434
|
if (!supportsMaxLength(element)) {
|
|
441
435
|
return void 0;
|
|
442
436
|
}
|
|
443
|
-
const attr = (
|
|
437
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
444
438
|
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
445
439
|
}
|
|
446
440
|
function supportsMaxLength(element) {
|
|
@@ -578,9 +572,9 @@ function commitInput(config, element, newOffset, inputInit) {
|
|
|
578
572
|
}
|
|
579
573
|
}
|
|
580
574
|
function isValidNumberInput(value) {
|
|
581
|
-
var
|
|
575
|
+
var _a, _b;
|
|
582
576
|
const valueParts = value.split("e", 2);
|
|
583
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
577
|
+
return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
584
578
|
}
|
|
585
579
|
|
|
586
580
|
// src/utils/edit/isEditable.ts
|
|
@@ -609,8 +603,8 @@ function isEditableInput(element) {
|
|
|
609
603
|
// src/utils/edit/setFiles.ts
|
|
610
604
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
611
605
|
function setFiles(el, files) {
|
|
612
|
-
var
|
|
613
|
-
(
|
|
606
|
+
var _a;
|
|
607
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
614
608
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
615
609
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
616
610
|
function restore() {
|
|
@@ -628,11 +622,11 @@ function setFiles(el, files) {
|
|
|
628
622
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
629
623
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
630
624
|
set(v) {
|
|
631
|
-
var
|
|
625
|
+
var _a2;
|
|
632
626
|
if (v === "") {
|
|
633
627
|
restore();
|
|
634
628
|
} else {
|
|
635
|
-
(
|
|
629
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
636
630
|
}
|
|
637
631
|
}
|
|
638
632
|
}),
|
|
@@ -659,7 +653,7 @@ function eventWrapper(cb) {
|
|
|
659
653
|
|
|
660
654
|
// src/utils/misc/isDisabled.ts
|
|
661
655
|
function isDisabled(element) {
|
|
662
|
-
var
|
|
656
|
+
var _a;
|
|
663
657
|
for (let el = element; el; el = el.parentElement) {
|
|
664
658
|
if (isElementType(el, [
|
|
665
659
|
"button",
|
|
@@ -673,7 +667,7 @@ function isDisabled(element) {
|
|
|
673
667
|
return true;
|
|
674
668
|
}
|
|
675
669
|
} else if (isElementType(el, "fieldset")) {
|
|
676
|
-
if (el.hasAttribute("disabled") && !((
|
|
670
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
677
671
|
return true;
|
|
678
672
|
}
|
|
679
673
|
} else if (el.tagName.includes("-")) {
|
|
@@ -686,13 +680,13 @@ function isDisabled(element) {
|
|
|
686
680
|
}
|
|
687
681
|
|
|
688
682
|
// src/utils/focus/getActiveElement.ts
|
|
689
|
-
function getActiveElement(
|
|
690
|
-
const activeElement =
|
|
683
|
+
function getActiveElement(document) {
|
|
684
|
+
const activeElement = document.activeElement;
|
|
691
685
|
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
692
686
|
return getActiveElement(activeElement.shadowRoot);
|
|
693
687
|
} else {
|
|
694
688
|
if (isDisabled(activeElement)) {
|
|
695
|
-
return
|
|
689
|
+
return document.ownerDocument ? document.ownerDocument.body : document.body;
|
|
696
690
|
}
|
|
697
691
|
return activeElement;
|
|
698
692
|
}
|
|
@@ -806,7 +800,7 @@ function isTextNode(node) {
|
|
|
806
800
|
return node.nodeType === 3;
|
|
807
801
|
}
|
|
808
802
|
function walkNodes(node, direction, callback) {
|
|
809
|
-
var
|
|
803
|
+
var _a;
|
|
810
804
|
for (; ; ) {
|
|
811
805
|
const sibling = node[`${direction}Sibling`];
|
|
812
806
|
if (sibling) {
|
|
@@ -814,7 +808,7 @@ function walkNodes(node, direction, callback) {
|
|
|
814
808
|
if (callback(node)) {
|
|
815
809
|
return node;
|
|
816
810
|
}
|
|
817
|
-
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((
|
|
811
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
818
812
|
node = node.parentNode;
|
|
819
813
|
} else {
|
|
820
814
|
break;
|
|
@@ -830,7 +824,7 @@ function getDescendant(node, direction) {
|
|
|
830
824
|
|
|
831
825
|
// src/utils/focus/selection.ts
|
|
832
826
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
833
|
-
var
|
|
827
|
+
var _a;
|
|
834
828
|
if (hasOwnSelection(element)) {
|
|
835
829
|
return setSelection({
|
|
836
830
|
focusNode: element,
|
|
@@ -838,7 +832,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
838
832
|
focusOffset
|
|
839
833
|
});
|
|
840
834
|
}
|
|
841
|
-
if (isContentEditable(element) && ((
|
|
835
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
842
836
|
return setSelection({
|
|
843
837
|
focusNode: element.firstChild,
|
|
844
838
|
anchorOffset,
|
|
@@ -872,7 +866,7 @@ function getElement2(node) {
|
|
|
872
866
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
873
867
|
}
|
|
874
868
|
function updateSelectionOnFocus(element) {
|
|
875
|
-
var
|
|
869
|
+
var _a;
|
|
876
870
|
const selection = element.ownerDocument.getSelection();
|
|
877
871
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
878
872
|
return;
|
|
@@ -881,7 +875,7 @@ function updateSelectionOnFocus(element) {
|
|
|
881
875
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
882
876
|
if (contenteditable) {
|
|
883
877
|
if (!selection.isCollapsed) {
|
|
884
|
-
const focusNode = ((
|
|
878
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
885
879
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
886
880
|
}
|
|
887
881
|
} else {
|
|
@@ -890,12 +884,12 @@ function updateSelectionOnFocus(element) {
|
|
|
890
884
|
}
|
|
891
885
|
}
|
|
892
886
|
function getInputRange(focusNode) {
|
|
893
|
-
var
|
|
887
|
+
var _a;
|
|
894
888
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
895
889
|
if (typeAndSelection.type === "input") {
|
|
896
890
|
return typeAndSelection.selection;
|
|
897
891
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
898
|
-
return (
|
|
892
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
899
893
|
}
|
|
900
894
|
}
|
|
901
895
|
function setSelection({
|
|
@@ -904,7 +898,7 @@ function setSelection({
|
|
|
904
898
|
anchorNode = focusNode,
|
|
905
899
|
anchorOffset = focusOffset
|
|
906
900
|
}) {
|
|
907
|
-
var
|
|
901
|
+
var _a, _b;
|
|
908
902
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
909
903
|
if (typeAndSelection.type === "input") {
|
|
910
904
|
return setUISelection(focusNode, {
|
|
@@ -912,7 +906,7 @@ function setSelection({
|
|
|
912
906
|
focusOffset
|
|
913
907
|
});
|
|
914
908
|
}
|
|
915
|
-
(_b = (
|
|
909
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
916
910
|
}
|
|
917
911
|
function moveSelection(node, direction) {
|
|
918
912
|
if (hasOwnSelection(node)) {
|
|
@@ -985,9 +979,9 @@ function focus(element) {
|
|
|
985
979
|
|
|
986
980
|
// src/utils/misc/isVisible.ts
|
|
987
981
|
function isVisible(element) {
|
|
988
|
-
const
|
|
982
|
+
const window = getWindow(element);
|
|
989
983
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
990
|
-
const { display, visibility } =
|
|
984
|
+
const { display, visibility } = window.getComputedStyle(el);
|
|
991
985
|
if (display === "none") {
|
|
992
986
|
return false;
|
|
993
987
|
}
|
|
@@ -1000,8 +994,8 @@ function isVisible(element) {
|
|
|
1000
994
|
|
|
1001
995
|
// src/utils/focus/getTabDestination.ts
|
|
1002
996
|
function getTabDestination(activeElement, shift) {
|
|
1003
|
-
const
|
|
1004
|
-
const focusableElements =
|
|
997
|
+
const document = activeElement.ownerDocument;
|
|
998
|
+
const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
1005
999
|
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
|
|
1006
1000
|
if (activeElement.getAttribute("tabindex") !== "-1") {
|
|
1007
1001
|
enabledElements.sort((a, b) => {
|
|
@@ -1018,7 +1012,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1018
1012
|
});
|
|
1019
1013
|
}
|
|
1020
1014
|
const checkedRadio = {};
|
|
1021
|
-
let prunedElements = [
|
|
1015
|
+
let prunedElements = [document.body];
|
|
1022
1016
|
const activeRadioGroup = isElementType(activeElement, "input", {
|
|
1023
1017
|
type: "radio"
|
|
1024
1018
|
}) ? activeElement.name : void 0;
|
|
@@ -1051,7 +1045,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1051
1045
|
|
|
1052
1046
|
// src/utils/focus/selectAll.ts
|
|
1053
1047
|
function selectAll(target) {
|
|
1054
|
-
var
|
|
1048
|
+
var _a;
|
|
1055
1049
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1056
1050
|
return setSelection({
|
|
1057
1051
|
focusNode: target,
|
|
@@ -1059,7 +1053,7 @@ function selectAll(target) {
|
|
|
1059
1053
|
focusOffset: getUIValue(target).length
|
|
1060
1054
|
});
|
|
1061
1055
|
}
|
|
1062
|
-
const focusNode = (
|
|
1056
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1063
1057
|
setSelection({
|
|
1064
1058
|
focusNode,
|
|
1065
1059
|
anchorOffset: 0,
|
|
@@ -1067,11 +1061,11 @@ function selectAll(target) {
|
|
|
1067
1061
|
});
|
|
1068
1062
|
}
|
|
1069
1063
|
function isAllSelected(target) {
|
|
1070
|
-
var
|
|
1064
|
+
var _a;
|
|
1071
1065
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1072
1066
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1073
1067
|
}
|
|
1074
|
-
const focusNode = (
|
|
1068
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1075
1069
|
const selection = target.ownerDocument.getSelection();
|
|
1076
1070
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1077
1071
|
}
|
|
@@ -1131,12 +1125,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1131
1125
|
};
|
|
1132
1126
|
}
|
|
1133
1127
|
function readTag(text, pos, startBracket, context) {
|
|
1134
|
-
var
|
|
1128
|
+
var _a, _b, _c;
|
|
1135
1129
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1136
1130
|
pos += releasePreviousModifier.length;
|
|
1137
1131
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1138
1132
|
pos += Number(escapedDescriptor);
|
|
1139
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1133
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1140
1134
|
assertDescriptor(descriptor, text, pos, context);
|
|
1141
1135
|
pos += descriptor.length;
|
|
1142
1136
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1208,13 +1202,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1208
1202
|
// src/utils/misc/level.ts
|
|
1209
1203
|
var Level = Symbol("Api level refs");
|
|
1210
1204
|
function setLevelRef(config, level) {
|
|
1211
|
-
var
|
|
1212
|
-
(
|
|
1205
|
+
var _a;
|
|
1206
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1213
1207
|
config[Level][level] = {};
|
|
1214
1208
|
}
|
|
1215
1209
|
function getLevelRef(config, level) {
|
|
1216
|
-
var
|
|
1217
|
-
return (
|
|
1210
|
+
var _a;
|
|
1211
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1218
1212
|
}
|
|
1219
1213
|
|
|
1220
1214
|
// src/utils/misc/wait.ts
|
|
@@ -1224,7 +1218,7 @@ function wait(config) {
|
|
|
1224
1218
|
return;
|
|
1225
1219
|
}
|
|
1226
1220
|
return Promise.all([
|
|
1227
|
-
new Promise((resolve) => setTimeout(() => resolve(), delay)),
|
|
1221
|
+
new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)),
|
|
1228
1222
|
config.advanceTimers(delay)
|
|
1229
1223
|
]);
|
|
1230
1224
|
}
|
|
@@ -1307,7 +1301,7 @@ var defaultOptionsDirect = {
|
|
|
1307
1301
|
applyAccept: true,
|
|
1308
1302
|
autoModify: true,
|
|
1309
1303
|
delay: 0,
|
|
1310
|
-
document:
|
|
1304
|
+
document: globalThis.document,
|
|
1311
1305
|
keyboardMap: defaultKeyMap,
|
|
1312
1306
|
pointerMap: defaultKeyMap2,
|
|
1313
1307
|
pointerEventsCheck: 2 /* EachApiCall */,
|
|
@@ -1323,9 +1317,9 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1323
1317
|
|
|
1324
1318
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1325
1319
|
function hasPointerEvents(element) {
|
|
1326
|
-
const
|
|
1320
|
+
const window = getWindow(element);
|
|
1327
1321
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1328
|
-
const pointerEvents =
|
|
1322
|
+
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
1329
1323
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
1330
1324
|
return pointerEvents !== "none";
|
|
1331
1325
|
}
|
|
@@ -1437,9 +1431,9 @@ function assignPositionInit(obj, {
|
|
|
1437
1431
|
screenX,
|
|
1438
1432
|
screenY
|
|
1439
1433
|
}) {
|
|
1440
|
-
var
|
|
1434
|
+
var _a, _b, _c, _d;
|
|
1441
1435
|
assignProps(obj, {
|
|
1442
|
-
x: (
|
|
1436
|
+
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1443
1437
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1444
1438
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1445
1439
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1493,8 +1487,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1493
1487
|
|
|
1494
1488
|
// src/event/behavior/keydown.ts
|
|
1495
1489
|
behavior.keydown = (event, target, config) => {
|
|
1496
|
-
var
|
|
1497
|
-
return (_b = (
|
|
1490
|
+
var _a, _b;
|
|
1491
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1498
1492
|
};
|
|
1499
1493
|
var keydownBehavior = {
|
|
1500
1494
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1516,8 +1510,8 @@ var keydownBehavior = {
|
|
|
1516
1510
|
End: (event, target) => {
|
|
1517
1511
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1518
1512
|
return () => {
|
|
1519
|
-
var
|
|
1520
|
-
const newPos = (_b = (
|
|
1513
|
+
var _a, _b;
|
|
1514
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1521
1515
|
setSelectionRange(target, newPos, newPos);
|
|
1522
1516
|
};
|
|
1523
1517
|
}
|
|
@@ -1609,8 +1603,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1609
1603
|
|
|
1610
1604
|
// src/event/behavior/keyup.ts
|
|
1611
1605
|
behavior.keyup = (event, target, config) => {
|
|
1612
|
-
var
|
|
1613
|
-
return (
|
|
1606
|
+
var _a;
|
|
1607
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1614
1608
|
};
|
|
1615
1609
|
var keyupBehavior = {
|
|
1616
1610
|
" ": (event, target, config) => {
|
|
@@ -1624,8 +1618,8 @@ var keyupBehavior = {
|
|
|
1624
1618
|
behavior.paste = (event, target, config) => {
|
|
1625
1619
|
if (isEditable(target)) {
|
|
1626
1620
|
return () => {
|
|
1627
|
-
var
|
|
1628
|
-
const insertData = (
|
|
1621
|
+
var _a;
|
|
1622
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1629
1623
|
if (insertData) {
|
|
1630
1624
|
input(config, target, insertData, "insertFromPaste");
|
|
1631
1625
|
}
|
|
@@ -1641,10 +1635,10 @@ function wrapEvent(cb, _element) {
|
|
|
1641
1635
|
|
|
1642
1636
|
// src/event/dispatchEvent.ts
|
|
1643
1637
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1644
|
-
var
|
|
1638
|
+
var _a, _b;
|
|
1645
1639
|
const type3 = event.type;
|
|
1646
1640
|
const behaviorImplementation = preventDefault ? () => {
|
|
1647
|
-
} : (_b = (
|
|
1641
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1648
1642
|
if (behaviorImplementation) {
|
|
1649
1643
|
event.preventDefault();
|
|
1650
1644
|
let defaultPrevented = false;
|
|
@@ -1760,9 +1754,9 @@ function setUISelection(element, {
|
|
|
1760
1754
|
}
|
|
1761
1755
|
}
|
|
1762
1756
|
function getUISelection(element) {
|
|
1763
|
-
var
|
|
1757
|
+
var _a, _b, _c;
|
|
1764
1758
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1765
|
-
anchorOffset: (
|
|
1759
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1766
1760
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1767
1761
|
};
|
|
1768
1762
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1824,8 +1818,8 @@ function startTrackValue(element) {
|
|
|
1824
1818
|
});
|
|
1825
1819
|
}
|
|
1826
1820
|
function trackOrSetValue(element, v) {
|
|
1827
|
-
var
|
|
1828
|
-
(_b = (
|
|
1821
|
+
var _a, _b, _c;
|
|
1822
|
+
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1829
1823
|
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1830
1824
|
setCleanValue(element, v);
|
|
1831
1825
|
}
|
|
@@ -1835,10 +1829,10 @@ function setCleanValue(element, v) {
|
|
|
1835
1829
|
setUISelection(element, { focusOffset: v.length });
|
|
1836
1830
|
}
|
|
1837
1831
|
function endTrackValue(element) {
|
|
1838
|
-
var
|
|
1832
|
+
var _a, _b;
|
|
1839
1833
|
const changes = element[TrackChanges];
|
|
1840
1834
|
element[TrackChanges] = void 0;
|
|
1841
|
-
const isJustReactStateUpdate = ((
|
|
1835
|
+
const isJustReactStateUpdate = ((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
|
|
1842
1836
|
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1843
1837
|
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1844
1838
|
}
|
|
@@ -1847,21 +1841,21 @@ function endTrackValue(element) {
|
|
|
1847
1841
|
|
|
1848
1842
|
// src/document/index.ts
|
|
1849
1843
|
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1850
|
-
function prepareDocument(
|
|
1851
|
-
if (
|
|
1844
|
+
function prepareDocument(document) {
|
|
1845
|
+
if (document[isPrepared]) {
|
|
1852
1846
|
return;
|
|
1853
1847
|
}
|
|
1854
|
-
|
|
1848
|
+
document.addEventListener("focus", (e) => {
|
|
1855
1849
|
const el = e.target;
|
|
1856
1850
|
prepareElement(el);
|
|
1857
1851
|
}, {
|
|
1858
1852
|
capture: true,
|
|
1859
1853
|
passive: true
|
|
1860
1854
|
});
|
|
1861
|
-
if (
|
|
1862
|
-
prepareElement(
|
|
1855
|
+
if (document.activeElement) {
|
|
1856
|
+
prepareElement(document.activeElement);
|
|
1863
1857
|
}
|
|
1864
|
-
|
|
1858
|
+
document.addEventListener("blur", (e) => {
|
|
1865
1859
|
const el = e.target;
|
|
1866
1860
|
const initialValue = getInitialValue(el);
|
|
1867
1861
|
if (initialValue !== void 0) {
|
|
@@ -1874,7 +1868,7 @@ function prepareDocument(document2) {
|
|
|
1874
1868
|
capture: true,
|
|
1875
1869
|
passive: true
|
|
1876
1870
|
});
|
|
1877
|
-
|
|
1871
|
+
document[isPrepared] = isPrepared;
|
|
1878
1872
|
}
|
|
1879
1873
|
function prepareElement(el) {
|
|
1880
1874
|
if (el[isPrepared]) {
|
|
@@ -1911,11 +1905,11 @@ function isModifierLock(key) {
|
|
|
1911
1905
|
return modifierLocks.includes(key);
|
|
1912
1906
|
}
|
|
1913
1907
|
function preKeydownBehavior(config, { key }, element) {
|
|
1914
|
-
var
|
|
1908
|
+
var _a;
|
|
1915
1909
|
if (isModifierKey(key)) {
|
|
1916
1910
|
config.keyboardState.modifiers[key] = true;
|
|
1917
1911
|
if (key === "AltGraph") {
|
|
1918
|
-
const ctrlKeyDef = (
|
|
1912
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1919
1913
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1920
1914
|
}
|
|
1921
1915
|
} else if (isModifierLock(key)) {
|
|
@@ -1935,9 +1929,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1935
1929
|
}
|
|
1936
1930
|
}
|
|
1937
1931
|
function postKeyupBehavior(config, { key }, element) {
|
|
1938
|
-
var
|
|
1932
|
+
var _a;
|
|
1939
1933
|
if (key === "AltGraph") {
|
|
1940
|
-
const ctrlKeyDef = (
|
|
1934
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1941
1935
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1942
1936
|
}
|
|
1943
1937
|
}
|
|
@@ -1952,8 +1946,8 @@ async function keyboardAction(config, actions) {
|
|
|
1952
1946
|
}
|
|
1953
1947
|
}
|
|
1954
1948
|
async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
1955
|
-
const { document
|
|
1956
|
-
const getCurrentElement = () => getActive(
|
|
1949
|
+
const { document, keyboardState } = config;
|
|
1950
|
+
const getCurrentElement = () => getActive(document);
|
|
1957
1951
|
const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
|
|
1958
1952
|
if (pressed) {
|
|
1959
1953
|
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
@@ -1974,9 +1968,9 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
|
|
|
1974
1968
|
}
|
|
1975
1969
|
}
|
|
1976
1970
|
}
|
|
1977
|
-
function getActive(
|
|
1978
|
-
var
|
|
1979
|
-
return (
|
|
1971
|
+
function getActive(document) {
|
|
1972
|
+
var _a;
|
|
1973
|
+
return (_a = getActiveElement(document)) != null ? _a : document.body;
|
|
1980
1974
|
}
|
|
1981
1975
|
async function releaseAllKeys(config) {
|
|
1982
1976
|
const getCurrentElement = () => getActive(config.document);
|
|
@@ -2010,13 +2004,13 @@ async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
2010
2004
|
postKeyupBehavior(config, keyDef, element);
|
|
2011
2005
|
}
|
|
2012
2006
|
function hasKeyPress(keyDef, config) {
|
|
2013
|
-
var
|
|
2014
|
-
return (((
|
|
2007
|
+
var _a;
|
|
2008
|
+
return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
2015
2009
|
}
|
|
2016
2010
|
|
|
2017
2011
|
// src/keyboard/parseKeyDef.ts
|
|
2018
2012
|
function parseKeyDef(keyboardMap, text) {
|
|
2019
|
-
var
|
|
2013
|
+
var _a;
|
|
2020
2014
|
const defs = [];
|
|
2021
2015
|
do {
|
|
2022
2016
|
const {
|
|
@@ -2027,15 +2021,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2027
2021
|
releaseSelf = true,
|
|
2028
2022
|
repeat
|
|
2029
2023
|
} = readNextDescriptor(text, "keyboard");
|
|
2030
|
-
const keyDef = (
|
|
2031
|
-
var
|
|
2024
|
+
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2025
|
+
var _a2, _b;
|
|
2032
2026
|
if (type3 === "[") {
|
|
2033
|
-
return ((
|
|
2027
|
+
return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
|
|
2034
2028
|
} else if (type3 === "{") {
|
|
2035
2029
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2036
2030
|
}
|
|
2037
2031
|
return def.key === descriptor;
|
|
2038
|
-
})) != null ?
|
|
2032
|
+
})) != null ? _a : {
|
|
2039
2033
|
key: "Unknown",
|
|
2040
2034
|
code: "Unknown",
|
|
2041
2035
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2112,8 +2106,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2112
2106
|
}
|
|
2113
2107
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2114
2108
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2115
|
-
var
|
|
2116
|
-
return (
|
|
2109
|
+
var _a;
|
|
2110
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2117
2111
|
}));
|
|
2118
2112
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2119
2113
|
init.detail = clickCount;
|
|
@@ -2271,7 +2265,7 @@ function getNextPointerId(state) {
|
|
|
2271
2265
|
return state.pointerId;
|
|
2272
2266
|
}
|
|
2273
2267
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2274
|
-
var
|
|
2268
|
+
var _a, _b, _c;
|
|
2275
2269
|
setLevelRef(config, 2 /* Trigger */);
|
|
2276
2270
|
assertPointerEvents(config, target);
|
|
2277
2271
|
const { pointerState } = config;
|
|
@@ -2294,7 +2288,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2294
2288
|
}
|
|
2295
2289
|
}
|
|
2296
2290
|
}
|
|
2297
|
-
if (((
|
|
2291
|
+
if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
|
|
2298
2292
|
delete pointerState.activeClickCount;
|
|
2299
2293
|
}
|
|
2300
2294
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2477,11 +2471,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2477
2471
|
|
|
2478
2472
|
// src/pointer/pointerAction.ts
|
|
2479
2473
|
async function pointerAction(config, actions) {
|
|
2480
|
-
var
|
|
2474
|
+
var _a, _b;
|
|
2481
2475
|
for (let i = 0; i < actions.length; i++) {
|
|
2482
2476
|
const action = actions[i];
|
|
2483
2477
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2484
|
-
const target = (
|
|
2478
|
+
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2485
2479
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2486
2480
|
await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
|
|
2487
2481
|
if (i < actions.length - 1) {
|
|
@@ -2512,14 +2506,14 @@ async function pointer(input2) {
|
|
|
2512
2506
|
});
|
|
2513
2507
|
return pointerAction(this[Config], actions).then(() => void 0);
|
|
2514
2508
|
}
|
|
2515
|
-
function createPointerState(
|
|
2509
|
+
function createPointerState(document) {
|
|
2516
2510
|
return {
|
|
2517
2511
|
pointerId: 1,
|
|
2518
2512
|
position: {
|
|
2519
2513
|
mouse: {
|
|
2520
2514
|
pointerType: "mouse",
|
|
2521
2515
|
pointerId: 1,
|
|
2522
|
-
target:
|
|
2516
|
+
target: document.body,
|
|
2523
2517
|
coords: {
|
|
2524
2518
|
clientX: 0,
|
|
2525
2519
|
clientY: 0,
|
|
@@ -2593,9 +2587,9 @@ async function tab({
|
|
|
2593
2587
|
|
|
2594
2588
|
// src/clipboard/copy.ts
|
|
2595
2589
|
async function copy() {
|
|
2596
|
-
var
|
|
2590
|
+
var _a;
|
|
2597
2591
|
const doc = this[Config].document;
|
|
2598
|
-
const target = (
|
|
2592
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2599
2593
|
const clipboardData = copySelection(target);
|
|
2600
2594
|
if (clipboardData.items.length === 0) {
|
|
2601
2595
|
return;
|
|
@@ -2610,9 +2604,9 @@ async function copy() {
|
|
|
2610
2604
|
|
|
2611
2605
|
// src/clipboard/cut.ts
|
|
2612
2606
|
async function cut() {
|
|
2613
|
-
var
|
|
2607
|
+
var _a;
|
|
2614
2608
|
const doc = this[Config].document;
|
|
2615
|
-
const target = (
|
|
2609
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2616
2610
|
const clipboardData = copySelection(target);
|
|
2617
2611
|
if (clipboardData.items.length === 0) {
|
|
2618
2612
|
return;
|
|
@@ -2627,9 +2621,9 @@ async function cut() {
|
|
|
2627
2621
|
|
|
2628
2622
|
// src/clipboard/paste.ts
|
|
2629
2623
|
async function paste(clipboardData) {
|
|
2630
|
-
var
|
|
2624
|
+
var _a, _b;
|
|
2631
2625
|
const doc = this[Config].document;
|
|
2632
|
-
const target = (
|
|
2626
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2633
2627
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2634
2628
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2635
2629
|
});
|
|
@@ -2781,10 +2775,10 @@ async function upload(element, fileOrFiles) {
|
|
|
2781
2775
|
return;
|
|
2782
2776
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2783
2777
|
const fileDialog = () => {
|
|
2784
|
-
var
|
|
2785
|
-
if (files.length === ((
|
|
2786
|
-
var
|
|
2787
|
-
return f === ((
|
|
2778
|
+
var _a;
|
|
2779
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2780
|
+
var _a2;
|
|
2781
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2788
2782
|
})) {
|
|
2789
2783
|
return;
|
|
2790
2784
|
}
|
|
@@ -2819,22 +2813,22 @@ function wrapAsync(implementation) {
|
|
|
2819
2813
|
|
|
2820
2814
|
// src/setup/setup.ts
|
|
2821
2815
|
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2822
|
-
const
|
|
2816
|
+
const document = getDocument(options, node, defaults);
|
|
2823
2817
|
const {
|
|
2824
2818
|
keyboardState = createKeyboardState(),
|
|
2825
|
-
pointerState = createPointerState(
|
|
2819
|
+
pointerState = createPointerState(document)
|
|
2826
2820
|
} = options;
|
|
2827
2821
|
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2828
|
-
document
|
|
2822
|
+
document,
|
|
2829
2823
|
keyboardState,
|
|
2830
2824
|
pointerState
|
|
2831
2825
|
});
|
|
2832
2826
|
}
|
|
2833
2827
|
function setupMain(options = {}) {
|
|
2834
|
-
var
|
|
2828
|
+
var _a;
|
|
2835
2829
|
const config = createConfig(options);
|
|
2836
2830
|
prepareDocument(config.document);
|
|
2837
|
-
const view = (
|
|
2831
|
+
const view = (_a = config.document.defaultView) != null ? _a : globalThis.window;
|
|
2838
2832
|
attachClipboardStubToView(view);
|
|
2839
2833
|
return doSetup(config);
|
|
2840
2834
|
}
|
|
@@ -2869,9 +2863,9 @@ function doSetup(config) {
|
|
|
2869
2863
|
setup: setupSub.bind(instance)
|
|
2870
2864
|
});
|
|
2871
2865
|
}
|
|
2872
|
-
function getDocument(options, node) {
|
|
2873
|
-
var
|
|
2874
|
-
return (_b = (
|
|
2866
|
+
function getDocument(options, node, defaults) {
|
|
2867
|
+
var _a, _b;
|
|
2868
|
+
return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : defaults.document;
|
|
2875
2869
|
}
|
|
2876
2870
|
|
|
2877
2871
|
// src/setup/directApi.ts
|