@testing-library/user-event 14.0.3 → 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 +238 -224
- package/dist/index.mjs +249 -235
- package/dist/types/document/index.d.ts +1 -1
- package/dist/types/document/interceptor.d.ts +1 -0
- package/dist/types/document/value.d.ts +1 -1
- package/dist/types/options.d.ts +7 -1
- package/dist/types/utils/misc/wait.d.ts +2 -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) {
|
|
@@ -509,7 +503,7 @@ function editContenteditable(config, element, inputRange, data, inputType) {
|
|
|
509
503
|
function editInputElement(config, element, inputRange, data, inputType) {
|
|
510
504
|
let dataToInsert = data;
|
|
511
505
|
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
512
|
-
if (spaceUntilMaxLength !== void 0) {
|
|
506
|
+
if (spaceUntilMaxLength !== void 0 && data.length > 0) {
|
|
513
507
|
if (spaceUntilMaxLength > 0) {
|
|
514
508
|
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
515
509
|
} else {
|
|
@@ -533,6 +527,7 @@ function editInputElement(config, element, inputRange, data, inputType) {
|
|
|
533
527
|
if (isValidDateOrTimeValue(element, newValue)) {
|
|
534
528
|
commitInput(config, element, newOffset, {});
|
|
535
529
|
dispatchUIEvent(config, element, "change");
|
|
530
|
+
clearInitialValue(element);
|
|
536
531
|
}
|
|
537
532
|
} else {
|
|
538
533
|
commitInput(config, element, newOffset, {
|
|
@@ -577,9 +572,9 @@ function commitInput(config, element, newOffset, inputInit) {
|
|
|
577
572
|
}
|
|
578
573
|
}
|
|
579
574
|
function isValidNumberInput(value) {
|
|
580
|
-
var
|
|
575
|
+
var _a, _b;
|
|
581
576
|
const valueParts = value.split("e", 2);
|
|
582
|
-
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]));
|
|
583
578
|
}
|
|
584
579
|
|
|
585
580
|
// src/utils/edit/isEditable.ts
|
|
@@ -608,8 +603,8 @@ function isEditableInput(element) {
|
|
|
608
603
|
// src/utils/edit/setFiles.ts
|
|
609
604
|
var fakeFiles = Symbol("files and value properties are mocked");
|
|
610
605
|
function setFiles(el, files) {
|
|
611
|
-
var
|
|
612
|
-
(
|
|
606
|
+
var _a;
|
|
607
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
613
608
|
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
614
609
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
615
610
|
function restore() {
|
|
@@ -627,11 +622,11 @@ function setFiles(el, files) {
|
|
|
627
622
|
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
628
623
|
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
629
624
|
set(v) {
|
|
630
|
-
var
|
|
625
|
+
var _a2;
|
|
631
626
|
if (v === "") {
|
|
632
627
|
restore();
|
|
633
628
|
} else {
|
|
634
|
-
(
|
|
629
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
635
630
|
}
|
|
636
631
|
}
|
|
637
632
|
}),
|
|
@@ -658,7 +653,7 @@ function eventWrapper(cb) {
|
|
|
658
653
|
|
|
659
654
|
// src/utils/misc/isDisabled.ts
|
|
660
655
|
function isDisabled(element) {
|
|
661
|
-
var
|
|
656
|
+
var _a;
|
|
662
657
|
for (let el = element; el; el = el.parentElement) {
|
|
663
658
|
if (isElementType(el, [
|
|
664
659
|
"button",
|
|
@@ -672,7 +667,7 @@ function isDisabled(element) {
|
|
|
672
667
|
return true;
|
|
673
668
|
}
|
|
674
669
|
} else if (isElementType(el, "fieldset")) {
|
|
675
|
-
if (el.hasAttribute("disabled") && !((
|
|
670
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
676
671
|
return true;
|
|
677
672
|
}
|
|
678
673
|
} else if (el.tagName.includes("-")) {
|
|
@@ -685,13 +680,13 @@ function isDisabled(element) {
|
|
|
685
680
|
}
|
|
686
681
|
|
|
687
682
|
// src/utils/focus/getActiveElement.ts
|
|
688
|
-
function getActiveElement(
|
|
689
|
-
const activeElement =
|
|
683
|
+
function getActiveElement(document) {
|
|
684
|
+
const activeElement = document.activeElement;
|
|
690
685
|
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
691
686
|
return getActiveElement(activeElement.shadowRoot);
|
|
692
687
|
} else {
|
|
693
688
|
if (isDisabled(activeElement)) {
|
|
694
|
-
return
|
|
689
|
+
return document.ownerDocument ? document.ownerDocument.body : document.body;
|
|
695
690
|
}
|
|
696
691
|
return activeElement;
|
|
697
692
|
}
|
|
@@ -805,7 +800,7 @@ function isTextNode(node) {
|
|
|
805
800
|
return node.nodeType === 3;
|
|
806
801
|
}
|
|
807
802
|
function walkNodes(node, direction, callback) {
|
|
808
|
-
var
|
|
803
|
+
var _a;
|
|
809
804
|
for (; ; ) {
|
|
810
805
|
const sibling = node[`${direction}Sibling`];
|
|
811
806
|
if (sibling) {
|
|
@@ -813,7 +808,7 @@ function walkNodes(node, direction, callback) {
|
|
|
813
808
|
if (callback(node)) {
|
|
814
809
|
return node;
|
|
815
810
|
}
|
|
816
|
-
} 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))) {
|
|
817
812
|
node = node.parentNode;
|
|
818
813
|
} else {
|
|
819
814
|
break;
|
|
@@ -829,7 +824,7 @@ function getDescendant(node, direction) {
|
|
|
829
824
|
|
|
830
825
|
// src/utils/focus/selection.ts
|
|
831
826
|
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
832
|
-
var
|
|
827
|
+
var _a;
|
|
833
828
|
if (hasOwnSelection(element)) {
|
|
834
829
|
return setSelection({
|
|
835
830
|
focusNode: element,
|
|
@@ -837,7 +832,7 @@ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
|
837
832
|
focusOffset
|
|
838
833
|
});
|
|
839
834
|
}
|
|
840
|
-
if (isContentEditable(element) && ((
|
|
835
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
841
836
|
return setSelection({
|
|
842
837
|
focusNode: element.firstChild,
|
|
843
838
|
anchorOffset,
|
|
@@ -871,7 +866,7 @@ function getElement2(node) {
|
|
|
871
866
|
return node.nodeType === 1 ? node : node.parentElement;
|
|
872
867
|
}
|
|
873
868
|
function updateSelectionOnFocus(element) {
|
|
874
|
-
var
|
|
869
|
+
var _a;
|
|
875
870
|
const selection = element.ownerDocument.getSelection();
|
|
876
871
|
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
877
872
|
return;
|
|
@@ -880,7 +875,7 @@ function updateSelectionOnFocus(element) {
|
|
|
880
875
|
const contenteditable = getContentEditable(selection.focusNode);
|
|
881
876
|
if (contenteditable) {
|
|
882
877
|
if (!selection.isCollapsed) {
|
|
883
|
-
const focusNode = ((
|
|
878
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
884
879
|
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
885
880
|
}
|
|
886
881
|
} else {
|
|
@@ -889,12 +884,12 @@ function updateSelectionOnFocus(element) {
|
|
|
889
884
|
}
|
|
890
885
|
}
|
|
891
886
|
function getInputRange(focusNode) {
|
|
892
|
-
var
|
|
887
|
+
var _a;
|
|
893
888
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
894
889
|
if (typeAndSelection.type === "input") {
|
|
895
890
|
return typeAndSelection.selection;
|
|
896
891
|
} else if (typeAndSelection.type === "contenteditable") {
|
|
897
|
-
return (
|
|
892
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
898
893
|
}
|
|
899
894
|
}
|
|
900
895
|
function setSelection({
|
|
@@ -903,7 +898,7 @@ function setSelection({
|
|
|
903
898
|
anchorNode = focusNode,
|
|
904
899
|
anchorOffset = focusOffset
|
|
905
900
|
}) {
|
|
906
|
-
var
|
|
901
|
+
var _a, _b;
|
|
907
902
|
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
908
903
|
if (typeAndSelection.type === "input") {
|
|
909
904
|
return setUISelection(focusNode, {
|
|
@@ -911,7 +906,7 @@ function setSelection({
|
|
|
911
906
|
focusOffset
|
|
912
907
|
});
|
|
913
908
|
}
|
|
914
|
-
(_b = (
|
|
909
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
915
910
|
}
|
|
916
911
|
function moveSelection(node, direction) {
|
|
917
912
|
if (hasOwnSelection(node)) {
|
|
@@ -984,9 +979,9 @@ function focus(element) {
|
|
|
984
979
|
|
|
985
980
|
// src/utils/misc/isVisible.ts
|
|
986
981
|
function isVisible(element) {
|
|
987
|
-
const
|
|
982
|
+
const window = getWindow(element);
|
|
988
983
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
989
|
-
const { display, visibility } =
|
|
984
|
+
const { display, visibility } = window.getComputedStyle(el);
|
|
990
985
|
if (display === "none") {
|
|
991
986
|
return false;
|
|
992
987
|
}
|
|
@@ -999,8 +994,8 @@ function isVisible(element) {
|
|
|
999
994
|
|
|
1000
995
|
// src/utils/focus/getTabDestination.ts
|
|
1001
996
|
function getTabDestination(activeElement, shift) {
|
|
1002
|
-
const
|
|
1003
|
-
const focusableElements =
|
|
997
|
+
const document = activeElement.ownerDocument;
|
|
998
|
+
const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
1004
999
|
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
|
|
1005
1000
|
if (activeElement.getAttribute("tabindex") !== "-1") {
|
|
1006
1001
|
enabledElements.sort((a, b) => {
|
|
@@ -1017,7 +1012,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1017
1012
|
});
|
|
1018
1013
|
}
|
|
1019
1014
|
const checkedRadio = {};
|
|
1020
|
-
let prunedElements = [
|
|
1015
|
+
let prunedElements = [document.body];
|
|
1021
1016
|
const activeRadioGroup = isElementType(activeElement, "input", {
|
|
1022
1017
|
type: "radio"
|
|
1023
1018
|
}) ? activeElement.name : void 0;
|
|
@@ -1050,7 +1045,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
1050
1045
|
|
|
1051
1046
|
// src/utils/focus/selectAll.ts
|
|
1052
1047
|
function selectAll(target) {
|
|
1053
|
-
var
|
|
1048
|
+
var _a;
|
|
1054
1049
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1055
1050
|
return setSelection({
|
|
1056
1051
|
focusNode: target,
|
|
@@ -1058,7 +1053,7 @@ function selectAll(target) {
|
|
|
1058
1053
|
focusOffset: getUIValue(target).length
|
|
1059
1054
|
});
|
|
1060
1055
|
}
|
|
1061
|
-
const focusNode = (
|
|
1056
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1062
1057
|
setSelection({
|
|
1063
1058
|
focusNode,
|
|
1064
1059
|
anchorOffset: 0,
|
|
@@ -1066,11 +1061,11 @@ function selectAll(target) {
|
|
|
1066
1061
|
});
|
|
1067
1062
|
}
|
|
1068
1063
|
function isAllSelected(target) {
|
|
1069
|
-
var
|
|
1064
|
+
var _a;
|
|
1070
1065
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1071
1066
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1072
1067
|
}
|
|
1073
|
-
const focusNode = (
|
|
1068
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1074
1069
|
const selection = target.ownerDocument.getSelection();
|
|
1075
1070
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1076
1071
|
}
|
|
@@ -1130,12 +1125,12 @@ function readPrintableChar(text, pos, context) {
|
|
|
1130
1125
|
};
|
|
1131
1126
|
}
|
|
1132
1127
|
function readTag(text, pos, startBracket, context) {
|
|
1133
|
-
var
|
|
1128
|
+
var _a, _b, _c;
|
|
1134
1129
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1135
1130
|
pos += releasePreviousModifier.length;
|
|
1136
1131
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1137
1132
|
pos += Number(escapedDescriptor);
|
|
1138
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1133
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1139
1134
|
assertDescriptor(descriptor, text, pos, context);
|
|
1140
1135
|
pos += descriptor.length;
|
|
1141
1136
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
@@ -1207,18 +1202,25 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1207
1202
|
// src/utils/misc/level.ts
|
|
1208
1203
|
var Level = Symbol("Api level refs");
|
|
1209
1204
|
function setLevelRef(config, level) {
|
|
1210
|
-
var
|
|
1211
|
-
(
|
|
1205
|
+
var _a;
|
|
1206
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1212
1207
|
config[Level][level] = {};
|
|
1213
1208
|
}
|
|
1214
1209
|
function getLevelRef(config, level) {
|
|
1215
|
-
var
|
|
1216
|
-
return (
|
|
1210
|
+
var _a;
|
|
1211
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1217
1212
|
}
|
|
1218
1213
|
|
|
1219
1214
|
// src/utils/misc/wait.ts
|
|
1220
|
-
function wait(
|
|
1221
|
-
|
|
1215
|
+
function wait(config) {
|
|
1216
|
+
const delay = config.delay;
|
|
1217
|
+
if (typeof delay !== "number") {
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
return Promise.all([
|
|
1221
|
+
new Promise((resolve) => globalThis.setTimeout(() => resolve(), delay)),
|
|
1222
|
+
config.advanceTimers(delay)
|
|
1223
|
+
]);
|
|
1222
1224
|
}
|
|
1223
1225
|
|
|
1224
1226
|
// src/keyboard/keyMap.ts
|
|
@@ -1299,14 +1301,15 @@ var defaultOptionsDirect = {
|
|
|
1299
1301
|
applyAccept: true,
|
|
1300
1302
|
autoModify: true,
|
|
1301
1303
|
delay: 0,
|
|
1302
|
-
document:
|
|
1304
|
+
document: globalThis.document,
|
|
1303
1305
|
keyboardMap: defaultKeyMap,
|
|
1304
1306
|
pointerMap: defaultKeyMap2,
|
|
1305
1307
|
pointerEventsCheck: 2 /* EachApiCall */,
|
|
1306
1308
|
skipAutoClose: false,
|
|
1307
1309
|
skipClick: false,
|
|
1308
1310
|
skipHover: false,
|
|
1309
|
-
writeToClipboard: false
|
|
1311
|
+
writeToClipboard: false,
|
|
1312
|
+
advanceTimers: () => Promise.resolve()
|
|
1310
1313
|
};
|
|
1311
1314
|
var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
|
|
1312
1315
|
writeToClipboard: true
|
|
@@ -1314,9 +1317,9 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1314
1317
|
|
|
1315
1318
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1316
1319
|
function hasPointerEvents(element) {
|
|
1317
|
-
const
|
|
1320
|
+
const window = getWindow(element);
|
|
1318
1321
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1319
|
-
const pointerEvents =
|
|
1322
|
+
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
1320
1323
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
1321
1324
|
return pointerEvents !== "none";
|
|
1322
1325
|
}
|
|
@@ -1428,9 +1431,9 @@ function assignPositionInit(obj, {
|
|
|
1428
1431
|
screenX,
|
|
1429
1432
|
screenY
|
|
1430
1433
|
}) {
|
|
1431
|
-
var
|
|
1434
|
+
var _a, _b, _c, _d;
|
|
1432
1435
|
assignProps(obj, {
|
|
1433
|
-
x: (
|
|
1436
|
+
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1434
1437
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1435
1438
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1436
1439
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1484,8 +1487,8 @@ behavior.cut = (event, target, config) => {
|
|
|
1484
1487
|
|
|
1485
1488
|
// src/event/behavior/keydown.ts
|
|
1486
1489
|
behavior.keydown = (event, target, config) => {
|
|
1487
|
-
var
|
|
1488
|
-
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);
|
|
1489
1492
|
};
|
|
1490
1493
|
var keydownBehavior = {
|
|
1491
1494
|
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
@@ -1507,8 +1510,8 @@ var keydownBehavior = {
|
|
|
1507
1510
|
End: (event, target) => {
|
|
1508
1511
|
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1509
1512
|
return () => {
|
|
1510
|
-
var
|
|
1511
|
-
const newPos = (_b = (
|
|
1513
|
+
var _a, _b;
|
|
1514
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1512
1515
|
setSelectionRange(target, newPos, newPos);
|
|
1513
1516
|
};
|
|
1514
1517
|
}
|
|
@@ -1600,8 +1603,8 @@ var SubmitSingleInputOnEnter = [
|
|
|
1600
1603
|
|
|
1601
1604
|
// src/event/behavior/keyup.ts
|
|
1602
1605
|
behavior.keyup = (event, target, config) => {
|
|
1603
|
-
var
|
|
1604
|
-
return (
|
|
1606
|
+
var _a;
|
|
1607
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1605
1608
|
};
|
|
1606
1609
|
var keyupBehavior = {
|
|
1607
1610
|
" ": (event, target, config) => {
|
|
@@ -1615,8 +1618,8 @@ var keyupBehavior = {
|
|
|
1615
1618
|
behavior.paste = (event, target, config) => {
|
|
1616
1619
|
if (isEditable(target)) {
|
|
1617
1620
|
return () => {
|
|
1618
|
-
var
|
|
1619
|
-
const insertData = (
|
|
1621
|
+
var _a;
|
|
1622
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1620
1623
|
if (insertData) {
|
|
1621
1624
|
input(config, target, insertData, "insertFromPaste");
|
|
1622
1625
|
}
|
|
@@ -1632,10 +1635,10 @@ function wrapEvent(cb, _element) {
|
|
|
1632
1635
|
|
|
1633
1636
|
// src/event/dispatchEvent.ts
|
|
1634
1637
|
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1635
|
-
var
|
|
1638
|
+
var _a, _b;
|
|
1636
1639
|
const type3 = event.type;
|
|
1637
1640
|
const behaviorImplementation = preventDefault ? () => {
|
|
1638
|
-
} : (_b = (
|
|
1641
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1639
1642
|
if (behaviorImplementation) {
|
|
1640
1643
|
event.preventDefault();
|
|
1641
1644
|
let defaultPrevented = false;
|
|
@@ -1678,13 +1681,18 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
1678
1681
|
return;
|
|
1679
1682
|
}
|
|
1680
1683
|
function intercept(...args) {
|
|
1681
|
-
const {
|
|
1684
|
+
const {
|
|
1685
|
+
applyNative = true,
|
|
1686
|
+
realArgs,
|
|
1687
|
+
then
|
|
1688
|
+
} = interceptorImpl.call(this, ...args);
|
|
1682
1689
|
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
1683
1690
|
if (target === "set") {
|
|
1684
1691
|
realFunc.call(this, realArgs);
|
|
1685
1692
|
} else {
|
|
1686
1693
|
realFunc.call(this, ...realArgs);
|
|
1687
1694
|
}
|
|
1695
|
+
then == null ? void 0 : then();
|
|
1688
1696
|
}
|
|
1689
1697
|
;
|
|
1690
1698
|
intercept[Interceptor] = Interceptor;
|
|
@@ -1713,6 +1721,13 @@ function prepareSelectionInterceptor(element) {
|
|
|
1713
1721
|
this[UISelection] = void 0;
|
|
1714
1722
|
return { realArgs: v };
|
|
1715
1723
|
});
|
|
1724
|
+
prepareInterceptor(element, "select", function interceptorImpl() {
|
|
1725
|
+
this[UISelection] = {
|
|
1726
|
+
anchorOffset: 0,
|
|
1727
|
+
focusOffset: getUIValue(element).length
|
|
1728
|
+
};
|
|
1729
|
+
return { realArgs: [] };
|
|
1730
|
+
});
|
|
1716
1731
|
}
|
|
1717
1732
|
function setUISelection(element, {
|
|
1718
1733
|
focusOffset: focusOffsetParam,
|
|
@@ -1739,9 +1754,9 @@ function setUISelection(element, {
|
|
|
1739
1754
|
}
|
|
1740
1755
|
}
|
|
1741
1756
|
function getUISelection(element) {
|
|
1742
|
-
var
|
|
1757
|
+
var _a, _b, _c;
|
|
1743
1758
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1744
|
-
anchorOffset: (
|
|
1759
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1745
1760
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1746
1761
|
};
|
|
1747
1762
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1759,12 +1774,11 @@ function valueInterceptor(v) {
|
|
|
1759
1774
|
if (isUI) {
|
|
1760
1775
|
this[UIValue] = String(v);
|
|
1761
1776
|
setPreviousValue(this, String(this.value));
|
|
1762
|
-
} else {
|
|
1763
|
-
trackOrSetValue(this, String(v));
|
|
1764
1777
|
}
|
|
1765
1778
|
return {
|
|
1766
1779
|
applyNative: !!isUI,
|
|
1767
|
-
realArgs: sanitizeValue(this, v)
|
|
1780
|
+
realArgs: sanitizeValue(this, v),
|
|
1781
|
+
then: isUI ? void 0 : () => trackOrSetValue(this, String(v))
|
|
1768
1782
|
};
|
|
1769
1783
|
}
|
|
1770
1784
|
function sanitizeValue(element, v) {
|
|
@@ -1777,6 +1791,9 @@ function prepareValueInterceptor(element) {
|
|
|
1777
1791
|
prepareInterceptor(element, "value", valueInterceptor);
|
|
1778
1792
|
}
|
|
1779
1793
|
function setUIValue(element, value) {
|
|
1794
|
+
if (element[InitialValue] === void 0) {
|
|
1795
|
+
element[InitialValue] = element.value;
|
|
1796
|
+
}
|
|
1780
1797
|
element.value = {
|
|
1781
1798
|
[UIValue]: UIValue,
|
|
1782
1799
|
toString: () => value
|
|
@@ -1785,8 +1802,8 @@ function setUIValue(element, value) {
|
|
|
1785
1802
|
function getUIValue(element) {
|
|
1786
1803
|
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
1787
1804
|
}
|
|
1788
|
-
function
|
|
1789
|
-
element[InitialValue] =
|
|
1805
|
+
function clearInitialValue(element) {
|
|
1806
|
+
element[InitialValue] = void 0;
|
|
1790
1807
|
}
|
|
1791
1808
|
function getInitialValue(element) {
|
|
1792
1809
|
return element[InitialValue];
|
|
@@ -1801,22 +1818,21 @@ function startTrackValue(element) {
|
|
|
1801
1818
|
});
|
|
1802
1819
|
}
|
|
1803
1820
|
function trackOrSetValue(element, v) {
|
|
1804
|
-
var
|
|
1805
|
-
(_b = (
|
|
1821
|
+
var _a, _b, _c;
|
|
1822
|
+
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1806
1823
|
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1807
1824
|
setCleanValue(element, v);
|
|
1808
1825
|
}
|
|
1809
1826
|
}
|
|
1810
1827
|
function setCleanValue(element, v) {
|
|
1811
1828
|
element[UIValue] = void 0;
|
|
1812
|
-
element[InitialValue] = v;
|
|
1813
1829
|
setUISelection(element, { focusOffset: v.length });
|
|
1814
1830
|
}
|
|
1815
1831
|
function endTrackValue(element) {
|
|
1816
|
-
var
|
|
1832
|
+
var _a, _b;
|
|
1817
1833
|
const changes = element[TrackChanges];
|
|
1818
1834
|
element[TrackChanges] = void 0;
|
|
1819
|
-
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;
|
|
1820
1836
|
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1821
1837
|
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1822
1838
|
}
|
|
@@ -1825,36 +1841,36 @@ function endTrackValue(element) {
|
|
|
1825
1841
|
|
|
1826
1842
|
// src/document/index.ts
|
|
1827
1843
|
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1828
|
-
function prepareDocument(
|
|
1829
|
-
if (
|
|
1844
|
+
function prepareDocument(document) {
|
|
1845
|
+
if (document[isPrepared]) {
|
|
1830
1846
|
return;
|
|
1831
1847
|
}
|
|
1832
|
-
|
|
1848
|
+
document.addEventListener("focus", (e) => {
|
|
1833
1849
|
const el = e.target;
|
|
1834
1850
|
prepareElement(el);
|
|
1835
1851
|
}, {
|
|
1836
1852
|
capture: true,
|
|
1837
1853
|
passive: true
|
|
1838
1854
|
});
|
|
1839
|
-
if (
|
|
1840
|
-
prepareElement(
|
|
1855
|
+
if (document.activeElement) {
|
|
1856
|
+
prepareElement(document.activeElement);
|
|
1841
1857
|
}
|
|
1842
|
-
|
|
1858
|
+
document.addEventListener("blur", (e) => {
|
|
1843
1859
|
const el = e.target;
|
|
1844
1860
|
const initialValue = getInitialValue(el);
|
|
1845
|
-
if (
|
|
1846
|
-
|
|
1861
|
+
if (initialValue !== void 0) {
|
|
1862
|
+
if (el.value !== initialValue) {
|
|
1863
|
+
dispatchUIEvent({}, el, "change");
|
|
1864
|
+
}
|
|
1865
|
+
clearInitialValue(el);
|
|
1847
1866
|
}
|
|
1848
1867
|
}, {
|
|
1849
1868
|
capture: true,
|
|
1850
1869
|
passive: true
|
|
1851
1870
|
});
|
|
1852
|
-
|
|
1871
|
+
document[isPrepared] = isPrepared;
|
|
1853
1872
|
}
|
|
1854
1873
|
function prepareElement(el) {
|
|
1855
|
-
if ("value" in el) {
|
|
1856
|
-
setInitialValue(el);
|
|
1857
|
-
}
|
|
1858
1874
|
if (el[isPrepared]) {
|
|
1859
1875
|
return;
|
|
1860
1876
|
}
|
|
@@ -1889,11 +1905,11 @@ function isModifierLock(key) {
|
|
|
1889
1905
|
return modifierLocks.includes(key);
|
|
1890
1906
|
}
|
|
1891
1907
|
function preKeydownBehavior(config, { key }, element) {
|
|
1892
|
-
var
|
|
1908
|
+
var _a;
|
|
1893
1909
|
if (isModifierKey(key)) {
|
|
1894
1910
|
config.keyboardState.modifiers[key] = true;
|
|
1895
1911
|
if (key === "AltGraph") {
|
|
1896
|
-
const ctrlKeyDef = (
|
|
1912
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1897
1913
|
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1898
1914
|
}
|
|
1899
1915
|
} else if (isModifierLock(key)) {
|
|
@@ -1913,9 +1929,9 @@ function preKeyupBehavior(config, { key }) {
|
|
|
1913
1929
|
}
|
|
1914
1930
|
}
|
|
1915
1931
|
function postKeyupBehavior(config, { key }, element) {
|
|
1916
|
-
var
|
|
1932
|
+
var _a;
|
|
1917
1933
|
if (key === "AltGraph") {
|
|
1918
|
-
const ctrlKeyDef = (
|
|
1934
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1919
1935
|
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1920
1936
|
}
|
|
1921
1937
|
}
|
|
@@ -1924,14 +1940,14 @@ function postKeyupBehavior(config, { key }, element) {
|
|
|
1924
1940
|
async function keyboardAction(config, actions) {
|
|
1925
1941
|
for (let i = 0; i < actions.length; i++) {
|
|
1926
1942
|
await keyboardKeyAction(config, actions[i]);
|
|
1927
|
-
if (
|
|
1928
|
-
await wait(config
|
|
1943
|
+
if (i < actions.length - 1) {
|
|
1944
|
+
await wait(config);
|
|
1929
1945
|
}
|
|
1930
1946
|
}
|
|
1931
1947
|
}
|
|
1932
1948
|
async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
1933
|
-
const { document
|
|
1934
|
-
const getCurrentElement = () => getActive(
|
|
1949
|
+
const { document, keyboardState } = config;
|
|
1950
|
+
const getCurrentElement = () => getActive(document);
|
|
1935
1951
|
const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
|
|
1936
1952
|
if (pressed) {
|
|
1937
1953
|
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
@@ -1943,8 +1959,8 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
|
|
|
1943
1959
|
if (unpreventedDefault && hasKeyPress(keyDef, config)) {
|
|
1944
1960
|
await keypress(keyDef, getCurrentElement, config);
|
|
1945
1961
|
}
|
|
1946
|
-
if (
|
|
1947
|
-
await wait(
|
|
1962
|
+
if (i < repeat) {
|
|
1963
|
+
await wait(config);
|
|
1948
1964
|
}
|
|
1949
1965
|
}
|
|
1950
1966
|
if (releaseSelf) {
|
|
@@ -1952,9 +1968,9 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
|
|
|
1952
1968
|
}
|
|
1953
1969
|
}
|
|
1954
1970
|
}
|
|
1955
|
-
function getActive(
|
|
1956
|
-
var
|
|
1957
|
-
return (
|
|
1971
|
+
function getActive(document) {
|
|
1972
|
+
var _a;
|
|
1973
|
+
return (_a = getActiveElement(document)) != null ? _a : document.body;
|
|
1958
1974
|
}
|
|
1959
1975
|
async function releaseAllKeys(config) {
|
|
1960
1976
|
const getCurrentElement = () => getActive(config.document);
|
|
@@ -1988,13 +2004,13 @@ async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
|
1988
2004
|
postKeyupBehavior(config, keyDef, element);
|
|
1989
2005
|
}
|
|
1990
2006
|
function hasKeyPress(keyDef, config) {
|
|
1991
|
-
var
|
|
1992
|
-
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;
|
|
1993
2009
|
}
|
|
1994
2010
|
|
|
1995
2011
|
// src/keyboard/parseKeyDef.ts
|
|
1996
2012
|
function parseKeyDef(keyboardMap, text) {
|
|
1997
|
-
var
|
|
2013
|
+
var _a;
|
|
1998
2014
|
const defs = [];
|
|
1999
2015
|
do {
|
|
2000
2016
|
const {
|
|
@@ -2005,15 +2021,15 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2005
2021
|
releaseSelf = true,
|
|
2006
2022
|
repeat
|
|
2007
2023
|
} = readNextDescriptor(text, "keyboard");
|
|
2008
|
-
const keyDef = (
|
|
2009
|
-
var
|
|
2024
|
+
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2025
|
+
var _a2, _b;
|
|
2010
2026
|
if (type3 === "[") {
|
|
2011
|
-
return ((
|
|
2027
|
+
return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
|
|
2012
2028
|
} else if (type3 === "{") {
|
|
2013
2029
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2014
2030
|
}
|
|
2015
2031
|
return def.key === descriptor;
|
|
2016
|
-
})) != null ?
|
|
2032
|
+
})) != null ? _a : {
|
|
2017
2033
|
key: "Unknown",
|
|
2018
2034
|
code: "Unknown",
|
|
2019
2035
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2090,8 +2106,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2090
2106
|
}
|
|
2091
2107
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2092
2108
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2093
|
-
var
|
|
2094
|
-
return (
|
|
2109
|
+
var _a;
|
|
2110
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2095
2111
|
}));
|
|
2096
2112
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2097
2113
|
init.detail = clickCount;
|
|
@@ -2249,7 +2265,7 @@ function getNextPointerId(state) {
|
|
|
2249
2265
|
return state.pointerId;
|
|
2250
2266
|
}
|
|
2251
2267
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2252
|
-
var
|
|
2268
|
+
var _a, _b, _c;
|
|
2253
2269
|
setLevelRef(config, 2 /* Trigger */);
|
|
2254
2270
|
assertPointerEvents(config, target);
|
|
2255
2271
|
const { pointerState } = config;
|
|
@@ -2272,7 +2288,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2272
2288
|
}
|
|
2273
2289
|
}
|
|
2274
2290
|
}
|
|
2275
|
-
if (((
|
|
2291
|
+
if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
|
|
2276
2292
|
delete pointerState.activeClickCount;
|
|
2277
2293
|
}
|
|
2278
2294
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2455,17 +2471,15 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2455
2471
|
|
|
2456
2472
|
// src/pointer/pointerAction.ts
|
|
2457
2473
|
async function pointerAction(config, actions) {
|
|
2458
|
-
var
|
|
2474
|
+
var _a, _b;
|
|
2459
2475
|
for (let i = 0; i < actions.length; i++) {
|
|
2460
2476
|
const action = actions[i];
|
|
2461
2477
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2462
|
-
const target = (
|
|
2478
|
+
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2463
2479
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2464
2480
|
await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
|
|
2465
|
-
if (
|
|
2466
|
-
|
|
2467
|
-
await wait(config.delay);
|
|
2468
|
-
}
|
|
2481
|
+
if (i < actions.length - 1) {
|
|
2482
|
+
await wait(config);
|
|
2469
2483
|
}
|
|
2470
2484
|
}
|
|
2471
2485
|
delete config.pointerState.activeClickCount;
|
|
@@ -2492,14 +2506,14 @@ async function pointer(input2) {
|
|
|
2492
2506
|
});
|
|
2493
2507
|
return pointerAction(this[Config], actions).then(() => void 0);
|
|
2494
2508
|
}
|
|
2495
|
-
function createPointerState(
|
|
2509
|
+
function createPointerState(document) {
|
|
2496
2510
|
return {
|
|
2497
2511
|
pointerId: 1,
|
|
2498
2512
|
position: {
|
|
2499
2513
|
mouse: {
|
|
2500
2514
|
pointerType: "mouse",
|
|
2501
2515
|
pointerId: 1,
|
|
2502
|
-
target:
|
|
2516
|
+
target: document.body,
|
|
2503
2517
|
coords: {
|
|
2504
2518
|
clientX: 0,
|
|
2505
2519
|
clientY: 0,
|
|
@@ -2573,9 +2587,9 @@ async function tab({
|
|
|
2573
2587
|
|
|
2574
2588
|
// src/clipboard/copy.ts
|
|
2575
2589
|
async function copy() {
|
|
2576
|
-
var
|
|
2590
|
+
var _a;
|
|
2577
2591
|
const doc = this[Config].document;
|
|
2578
|
-
const target = (
|
|
2592
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2579
2593
|
const clipboardData = copySelection(target);
|
|
2580
2594
|
if (clipboardData.items.length === 0) {
|
|
2581
2595
|
return;
|
|
@@ -2590,9 +2604,9 @@ async function copy() {
|
|
|
2590
2604
|
|
|
2591
2605
|
// src/clipboard/cut.ts
|
|
2592
2606
|
async function cut() {
|
|
2593
|
-
var
|
|
2607
|
+
var _a;
|
|
2594
2608
|
const doc = this[Config].document;
|
|
2595
|
-
const target = (
|
|
2609
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2596
2610
|
const clipboardData = copySelection(target);
|
|
2597
2611
|
if (clipboardData.items.length === 0) {
|
|
2598
2612
|
return;
|
|
@@ -2607,9 +2621,9 @@ async function cut() {
|
|
|
2607
2621
|
|
|
2608
2622
|
// src/clipboard/paste.ts
|
|
2609
2623
|
async function paste(clipboardData) {
|
|
2610
|
-
var
|
|
2624
|
+
var _a, _b;
|
|
2611
2625
|
const doc = this[Config].document;
|
|
2612
|
-
const target = (
|
|
2626
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2613
2627
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2614
2628
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2615
2629
|
});
|
|
@@ -2761,10 +2775,10 @@ async function upload(element, fileOrFiles) {
|
|
|
2761
2775
|
return;
|
|
2762
2776
|
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2763
2777
|
const fileDialog = () => {
|
|
2764
|
-
var
|
|
2765
|
-
if (files.length === ((
|
|
2766
|
-
var
|
|
2767
|
-
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));
|
|
2768
2782
|
})) {
|
|
2769
2783
|
return;
|
|
2770
2784
|
}
|
|
@@ -2799,22 +2813,22 @@ function wrapAsync(implementation) {
|
|
|
2799
2813
|
|
|
2800
2814
|
// src/setup/setup.ts
|
|
2801
2815
|
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2802
|
-
const
|
|
2816
|
+
const document = getDocument(options, node, defaults);
|
|
2803
2817
|
const {
|
|
2804
2818
|
keyboardState = createKeyboardState(),
|
|
2805
|
-
pointerState = createPointerState(
|
|
2819
|
+
pointerState = createPointerState(document)
|
|
2806
2820
|
} = options;
|
|
2807
2821
|
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2808
|
-
document
|
|
2822
|
+
document,
|
|
2809
2823
|
keyboardState,
|
|
2810
2824
|
pointerState
|
|
2811
2825
|
});
|
|
2812
2826
|
}
|
|
2813
2827
|
function setupMain(options = {}) {
|
|
2814
|
-
var
|
|
2828
|
+
var _a;
|
|
2815
2829
|
const config = createConfig(options);
|
|
2816
2830
|
prepareDocument(config.document);
|
|
2817
|
-
const view = (
|
|
2831
|
+
const view = (_a = config.document.defaultView) != null ? _a : globalThis.window;
|
|
2818
2832
|
attachClipboardStubToView(view);
|
|
2819
2833
|
return doSetup(config);
|
|
2820
2834
|
}
|
|
@@ -2849,9 +2863,9 @@ function doSetup(config) {
|
|
|
2849
2863
|
setup: setupSub.bind(instance)
|
|
2850
2864
|
});
|
|
2851
2865
|
}
|
|
2852
|
-
function getDocument(options, node) {
|
|
2853
|
-
var
|
|
2854
|
-
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;
|
|
2855
2869
|
}
|
|
2856
2870
|
|
|
2857
2871
|
// src/setup/directApi.ts
|