@testing-library/user-event 14.0.0-beta.9 → 14.0.0
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/README.md +2 -2
- package/dist/index.cjs +632 -739
- package/dist/index.mjs +624 -726
- package/dist/types/event/behavior/cut.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +5 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/paste.d.ts +1 -0
- package/dist/types/event/dispatchEvent.d.ts +1 -1
- package/dist/types/event/eventMap.d.ts +361 -0
- package/dist/types/event/index.d.ts +2 -2
- package/dist/types/keyboard/modifiers.d.ts +9 -0
- package/dist/types/keyboard/types.d.ts +0 -5
- package/dist/types/utils/edit/input.d.ts +2 -0
- package/dist/types/utils/edit/isValidDateOrTimeValue.d.ts +3 -0
- package/dist/types/utils/focus/selection.d.ts +4 -0
- package/dist/types/utils/index.d.ts +1 -8
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +3 -1
- package/package.json +10 -13
- package/dist/types/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/types/keyboard/plugins/character.d.ts +0 -5
- package/dist/types/keyboard/plugins/combination.d.ts +0 -5
- package/dist/types/keyboard/plugins/control.d.ts +0 -6
- package/dist/types/keyboard/plugins/functional.d.ts +0 -8
- package/dist/types/keyboard/plugins/index.d.ts +0 -7
- package/dist/types/keyboard/plugins/modifiers.d.ts +0 -8
- package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -4
- package/dist/types/keyboard/shared/index.d.ts +0 -1
- package/dist/types/utils/edit/calculateNewValue.d.ts +0 -14
- package/dist/types/utils/edit/editInputElement.d.ts +0 -14
- package/dist/types/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/types/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/types/utils/edit/prepareInput.d.ts +0 -8
- package/dist/types/utils/misc/hasFormSubmit.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -19,24 +19,19 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
return a;
|
|
20
20
|
};
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
23
22
|
var __export = (target, all) => {
|
|
24
23
|
for (var name in all)
|
|
25
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
25
|
};
|
|
27
|
-
var
|
|
28
|
-
if (
|
|
29
|
-
for (let key of __getOwnPropNames(
|
|
30
|
-
if (!__hasOwnProp.call(
|
|
31
|
-
__defProp(
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
31
|
}
|
|
33
|
-
return
|
|
32
|
+
return to;
|
|
34
33
|
};
|
|
35
|
-
var __toCommonJS =
|
|
36
|
-
return (module2, temp) => {
|
|
37
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
38
|
-
};
|
|
39
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
35
|
|
|
41
36
|
// src/index.ts
|
|
42
37
|
var src_exports = {};
|
|
@@ -44,6 +39,7 @@ __export(src_exports, {
|
|
|
44
39
|
PointerEventsCheckLevel: () => PointerEventsCheckLevel,
|
|
45
40
|
default: () => userEvent
|
|
46
41
|
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
47
43
|
|
|
48
44
|
// src/utils/misc/isElementType.ts
|
|
49
45
|
function isElementType(element, tag, props) {
|
|
@@ -340,6 +336,29 @@ if (typeof afterAll === "function") {
|
|
|
340
336
|
afterAll(() => detachClipboardStubFromView(window));
|
|
341
337
|
}
|
|
342
338
|
|
|
339
|
+
// src/utils/edit/isContentEditable.ts
|
|
340
|
+
function isContentEditable(element) {
|
|
341
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
342
|
+
}
|
|
343
|
+
function getContentEditable(node) {
|
|
344
|
+
const element = getElement(node);
|
|
345
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
346
|
+
}
|
|
347
|
+
function getElement(node) {
|
|
348
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/utils/edit/getValue.ts
|
|
352
|
+
function getValue(element) {
|
|
353
|
+
if (!element) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
if (isContentEditable(element)) {
|
|
357
|
+
return element.textContent;
|
|
358
|
+
}
|
|
359
|
+
return getUIValue(element);
|
|
360
|
+
}
|
|
361
|
+
|
|
343
362
|
// src/utils/edit/buildTimeValue.ts
|
|
344
363
|
function buildTimeValue(value) {
|
|
345
364
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -371,21 +390,137 @@ function build(onlyDigitsValue, index) {
|
|
|
371
390
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
372
391
|
}
|
|
373
392
|
|
|
374
|
-
// src/utils/edit/
|
|
375
|
-
function
|
|
393
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
394
|
+
function isValidDateOrTimeValue(element, value) {
|
|
376
395
|
const clone = element.cloneNode();
|
|
377
396
|
clone.value = value;
|
|
378
397
|
return clone.value === value;
|
|
379
398
|
}
|
|
380
399
|
|
|
381
|
-
// src/utils/edit/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
400
|
+
// src/utils/edit/maxLength.ts
|
|
401
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
402
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
403
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
404
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
405
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
406
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
407
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
408
|
+
return maxLengthSupportedTypes2;
|
|
409
|
+
})(maxLengthSupportedTypes || {});
|
|
410
|
+
function getSpaceUntilMaxLength(element) {
|
|
411
|
+
const value = getValue(element);
|
|
412
|
+
if (value === null) {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
416
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
417
|
+
}
|
|
418
|
+
function getSanitizedMaxLength(element) {
|
|
419
|
+
var _a;
|
|
420
|
+
if (!supportsMaxLength(element)) {
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
424
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
425
|
+
}
|
|
426
|
+
function supportsMaxLength(element) {
|
|
427
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
386
428
|
}
|
|
387
429
|
|
|
388
|
-
// src/utils/edit/
|
|
430
|
+
// src/utils/edit/input.ts
|
|
431
|
+
function isDateOrTime(element) {
|
|
432
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
433
|
+
}
|
|
434
|
+
function input(config, element, data, inputType = "insertText") {
|
|
435
|
+
const inputRange = getInputRange(element);
|
|
436
|
+
if (!inputRange) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (!isDateOrTime(element)) {
|
|
440
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
441
|
+
inputType,
|
|
442
|
+
data
|
|
443
|
+
});
|
|
444
|
+
if (!unprevented) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if ("startContainer" in inputRange) {
|
|
449
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
450
|
+
} else {
|
|
451
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
455
|
+
let del = false;
|
|
456
|
+
if (!inputRange.collapsed) {
|
|
457
|
+
del = true;
|
|
458
|
+
inputRange.deleteContents();
|
|
459
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
460
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
461
|
+
if (nextPosition) {
|
|
462
|
+
del = true;
|
|
463
|
+
const delRange = inputRange.cloneRange();
|
|
464
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
465
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
466
|
+
} else {
|
|
467
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
468
|
+
}
|
|
469
|
+
delRange.deleteContents();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (data) {
|
|
473
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
474
|
+
const offset = inputRange.endOffset;
|
|
475
|
+
inputRange.endContainer.insertData(offset, data);
|
|
476
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
477
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
478
|
+
} else {
|
|
479
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
480
|
+
inputRange.insertNode(text);
|
|
481
|
+
inputRange.setStart(text, data.length);
|
|
482
|
+
inputRange.setEnd(text, data.length);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (del || data) {
|
|
486
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
490
|
+
let dataToInsert = data;
|
|
491
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
492
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
493
|
+
if (spaceUntilMaxLength > 0) {
|
|
494
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
495
|
+
} else {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
500
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
setUIValue(element, newValue);
|
|
507
|
+
setSelection({
|
|
508
|
+
focusNode: element,
|
|
509
|
+
anchorOffset: newOffset,
|
|
510
|
+
focusOffset: newOffset
|
|
511
|
+
});
|
|
512
|
+
if (isDateOrTime(element)) {
|
|
513
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
514
|
+
commitInput(config, element, oldValue, newValue, newOffset, {});
|
|
515
|
+
dispatchUIEvent(config, element, "change");
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
commitInput(config, element, oldValue, newValue, newOffset, {
|
|
519
|
+
data,
|
|
520
|
+
inputType
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
389
524
|
function calculateNewValue(inputData, node, {
|
|
390
525
|
startOffset,
|
|
391
526
|
endOffset
|
|
@@ -396,15 +531,12 @@ function calculateNewValue(inputData, node, {
|
|
|
396
531
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
397
532
|
const epilog = value.substring(epilogStart, value.length);
|
|
398
533
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
399
|
-
|
|
400
|
-
if (node
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
newValue = inputData;
|
|
406
|
-
} else {
|
|
407
|
-
newValue = value;
|
|
534
|
+
let newOffset = prologEnd + inputData.length;
|
|
535
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
536
|
+
const builtValue = buildTimeValue(newValue);
|
|
537
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
538
|
+
newValue = builtValue;
|
|
539
|
+
newOffset = builtValue.length;
|
|
408
540
|
}
|
|
409
541
|
}
|
|
410
542
|
return {
|
|
@@ -413,17 +545,22 @@ function calculateNewValue(inputData, node, {
|
|
|
413
545
|
newOffset
|
|
414
546
|
};
|
|
415
547
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
548
|
+
function commitInput(config, element, oldValue, newValue, newOffset, inputInit) {
|
|
549
|
+
startTrackValue(element);
|
|
550
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
551
|
+
const tracked = endTrackValue(element);
|
|
552
|
+
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
553
|
+
setSelection({
|
|
554
|
+
focusNode: element,
|
|
555
|
+
anchorOffset: newOffset,
|
|
556
|
+
focusOffset: newOffset
|
|
557
|
+
});
|
|
558
|
+
}
|
|
424
559
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
560
|
+
function isValidNumberInput(value) {
|
|
561
|
+
var _a, _b;
|
|
562
|
+
const valueParts = value.split("e", 2);
|
|
563
|
+
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]));
|
|
427
564
|
}
|
|
428
565
|
|
|
429
566
|
// src/utils/edit/isEditable.ts
|
|
@@ -449,157 +586,123 @@ function isEditableInput(element) {
|
|
|
449
586
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
450
587
|
}
|
|
451
588
|
|
|
452
|
-
// src/utils/
|
|
453
|
-
|
|
589
|
+
// src/utils/edit/setFiles.ts
|
|
590
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
591
|
+
function setFiles(el, files) {
|
|
454
592
|
var _a;
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return setSelection({
|
|
464
|
-
focusNode: element.firstChild,
|
|
465
|
-
anchorOffset,
|
|
466
|
-
focusOffset
|
|
593
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
594
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
595
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
596
|
+
function restore() {
|
|
597
|
+
Object.defineProperties(el, {
|
|
598
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
599
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
600
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
467
601
|
});
|
|
468
602
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
603
|
+
el[fakeFiles] = { restore };
|
|
604
|
+
Object.defineProperties(el, {
|
|
605
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
606
|
+
get: () => files
|
|
607
|
+
}),
|
|
608
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
609
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
610
|
+
set(v) {
|
|
611
|
+
var _a2;
|
|
612
|
+
if (v === "") {
|
|
613
|
+
restore();
|
|
614
|
+
} else {
|
|
615
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}),
|
|
619
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
620
|
+
set(v) {
|
|
621
|
+
if (v !== "file") {
|
|
622
|
+
restore();
|
|
623
|
+
el.type = v;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
})
|
|
627
|
+
});
|
|
491
628
|
}
|
|
492
|
-
|
|
493
|
-
|
|
629
|
+
|
|
630
|
+
// src/utils/misc/eventWrapper.ts
|
|
631
|
+
var import_dom = require("@testing-library/dom");
|
|
632
|
+
function eventWrapper(cb) {
|
|
633
|
+
let result;
|
|
634
|
+
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
635
|
+
result = cb();
|
|
636
|
+
});
|
|
637
|
+
return result;
|
|
494
638
|
}
|
|
495
|
-
|
|
639
|
+
|
|
640
|
+
// src/utils/misc/isDisabled.ts
|
|
641
|
+
function isDisabled(element) {
|
|
496
642
|
var _a;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
643
|
+
for (let el = element; el; el = el.parentElement) {
|
|
644
|
+
if (isElementType(el, [
|
|
645
|
+
"button",
|
|
646
|
+
"input",
|
|
647
|
+
"select",
|
|
648
|
+
"textarea",
|
|
649
|
+
"optgroup",
|
|
650
|
+
"option"
|
|
651
|
+
])) {
|
|
652
|
+
if (el.hasAttribute("disabled")) {
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
} else if (isElementType(el, "fieldset")) {
|
|
656
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
} else if (el.tagName.includes("-")) {
|
|
660
|
+
if (el.constructor.formAssociated && el.hasAttribute("disabled")) {
|
|
661
|
+
return true;
|
|
507
662
|
}
|
|
508
|
-
} else {
|
|
509
|
-
selection.setBaseAndExtent(element, 0, element, 0);
|
|
510
663
|
}
|
|
511
664
|
}
|
|
512
|
-
|
|
513
|
-
function getInputRange(focusNode) {
|
|
514
|
-
var _a;
|
|
515
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
516
|
-
if (typeAndSelection.type === "input") {
|
|
517
|
-
return typeAndSelection.selection;
|
|
518
|
-
} else if (typeAndSelection.type === "contenteditable") {
|
|
519
|
-
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
function setSelection({
|
|
523
|
-
focusNode,
|
|
524
|
-
focusOffset,
|
|
525
|
-
anchorNode = focusNode,
|
|
526
|
-
anchorOffset = focusOffset
|
|
527
|
-
}) {
|
|
528
|
-
var _a, _b;
|
|
529
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
530
|
-
if (typeAndSelection.type === "input") {
|
|
531
|
-
return setUISelection(focusNode, {
|
|
532
|
-
anchorOffset,
|
|
533
|
-
focusOffset
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
665
|
+
return false;
|
|
537
666
|
}
|
|
538
667
|
|
|
539
|
-
// src/utils/
|
|
540
|
-
function
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
anchorOffset: newSelection.offset,
|
|
550
|
-
focusOffset: newSelection.offset
|
|
551
|
-
});
|
|
552
|
-
startTrackValue(element);
|
|
553
|
-
dispatchUIEvent(config, element, "input", eventOverrides);
|
|
554
|
-
const tracked = endTrackValue(element);
|
|
555
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
556
|
-
setSelection({
|
|
557
|
-
focusNode: newSelection.node,
|
|
558
|
-
anchorOffset: newSelection.offset,
|
|
559
|
-
focusOffset: newSelection.offset
|
|
560
|
-
});
|
|
668
|
+
// src/utils/focus/getActiveElement.ts
|
|
669
|
+
function getActiveElement(document2) {
|
|
670
|
+
const activeElement = document2.activeElement;
|
|
671
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
672
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
673
|
+
} else {
|
|
674
|
+
if (isDisabled(activeElement)) {
|
|
675
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
676
|
+
}
|
|
677
|
+
return activeElement;
|
|
561
678
|
}
|
|
562
679
|
}
|
|
563
680
|
|
|
564
|
-
// src/utils/
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
681
|
+
// src/utils/focus/selector.ts
|
|
682
|
+
var FOCUSABLE_SELECTOR = [
|
|
683
|
+
"input:not([type=hidden]):not([disabled])",
|
|
684
|
+
"button:not([disabled])",
|
|
685
|
+
"select:not([disabled])",
|
|
686
|
+
"textarea:not([disabled])",
|
|
687
|
+
'[contenteditable=""]',
|
|
688
|
+
'[contenteditable="true"]',
|
|
689
|
+
"a[href]",
|
|
690
|
+
"[tabindex]:not([disabled])"
|
|
691
|
+
].join(", ");
|
|
574
692
|
|
|
575
|
-
// src/utils/
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
maxLengthSupportedTypes2["password"] = "password";
|
|
579
|
-
maxLengthSupportedTypes2["search"] = "search";
|
|
580
|
-
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
581
|
-
maxLengthSupportedTypes2["text"] = "text";
|
|
582
|
-
maxLengthSupportedTypes2["url"] = "url";
|
|
583
|
-
return maxLengthSupportedTypes2;
|
|
584
|
-
})(maxLengthSupportedTypes || {});
|
|
585
|
-
function getSpaceUntilMaxLength(element) {
|
|
586
|
-
const value = getValue(element);
|
|
587
|
-
if (value === null) {
|
|
588
|
-
return void 0;
|
|
589
|
-
}
|
|
590
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
591
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
592
|
-
}
|
|
593
|
-
function getSanitizedMaxLength(element) {
|
|
594
|
-
var _a;
|
|
595
|
-
if (!supportsMaxLength(element)) {
|
|
596
|
-
return void 0;
|
|
597
|
-
}
|
|
598
|
-
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
599
|
-
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
693
|
+
// src/utils/focus/isFocusable.ts
|
|
694
|
+
function isFocusable(element) {
|
|
695
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
600
696
|
}
|
|
601
|
-
|
|
602
|
-
|
|
697
|
+
|
|
698
|
+
// src/utils/focus/blur.ts
|
|
699
|
+
function blur(element) {
|
|
700
|
+
if (!isFocusable(element))
|
|
701
|
+
return;
|
|
702
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
703
|
+
if (!wasActive)
|
|
704
|
+
return;
|
|
705
|
+
eventWrapper(() => element.blur());
|
|
603
706
|
}
|
|
604
707
|
|
|
605
708
|
// src/utils/focus/cursor.ts
|
|
@@ -650,7 +753,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
650
753
|
}
|
|
651
754
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
652
755
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
653
|
-
if (offset !== void 0 &&
|
|
756
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
654
757
|
node = node.children[nextOffset];
|
|
655
758
|
}
|
|
656
759
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -659,7 +762,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
659
762
|
if (isTextNode(node)) {
|
|
660
763
|
return true;
|
|
661
764
|
}
|
|
662
|
-
if (
|
|
765
|
+
if (isElement(node)) {
|
|
663
766
|
if (isElementType(node, ["input", "textarea"])) {
|
|
664
767
|
return node.type !== "hidden";
|
|
665
768
|
} else if (isElementType(node, "br")) {
|
|
@@ -676,7 +779,7 @@ function getOffset(node) {
|
|
|
676
779
|
}
|
|
677
780
|
return i;
|
|
678
781
|
}
|
|
679
|
-
function
|
|
782
|
+
function isElement(node) {
|
|
680
783
|
return node.nodeType === 1;
|
|
681
784
|
}
|
|
682
785
|
function isTextNode(node) {
|
|
@@ -691,7 +794,7 @@ function walkNodes(node, direction, callback) {
|
|
|
691
794
|
if (callback(node)) {
|
|
692
795
|
return node;
|
|
693
796
|
}
|
|
694
|
-
} else if (node.parentNode && (!
|
|
797
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
695
798
|
node = node.parentNode;
|
|
696
799
|
} else {
|
|
697
800
|
break;
|
|
@@ -705,167 +808,116 @@ function getDescendant(node, direction) {
|
|
|
705
808
|
return node;
|
|
706
809
|
}
|
|
707
810
|
|
|
708
|
-
// src/utils/
|
|
709
|
-
function
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
return
|
|
811
|
+
// src/utils/focus/selection.ts
|
|
812
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
813
|
+
var _a;
|
|
814
|
+
if (hasOwnSelection(element)) {
|
|
815
|
+
return setSelection({
|
|
816
|
+
focusNode: element,
|
|
817
|
+
anchorOffset,
|
|
818
|
+
focusOffset
|
|
819
|
+
});
|
|
713
820
|
}
|
|
714
|
-
if (
|
|
715
|
-
return {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
if (data) {
|
|
735
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
736
|
-
const offset = inputRange.endOffset;
|
|
737
|
-
inputRange.endContainer.insertData(offset, data);
|
|
738
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
739
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
740
|
-
} else {
|
|
741
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
742
|
-
inputRange.insertNode(text);
|
|
743
|
-
inputRange.setStart(text, data.length);
|
|
744
|
-
inputRange.setEnd(text, data.length);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
if (del || data) {
|
|
748
|
-
dispatchUIEvent(config, element, "input", { inputType });
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
} else {
|
|
821
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
822
|
+
return setSelection({
|
|
823
|
+
focusNode: element.firstChild,
|
|
824
|
+
anchorOffset,
|
|
825
|
+
focusOffset
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
829
|
+
}
|
|
830
|
+
function hasOwnSelection(node) {
|
|
831
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
832
|
+
}
|
|
833
|
+
function isElement2(node) {
|
|
834
|
+
return node.nodeType === 1;
|
|
835
|
+
}
|
|
836
|
+
function getTargetTypeAndSelection(node) {
|
|
837
|
+
const element = getElement2(node);
|
|
838
|
+
if (element && hasOwnSelection(element)) {
|
|
753
839
|
return {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
|
|
757
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
editInputElement(config, element, {
|
|
761
|
-
newValue,
|
|
762
|
-
newSelection: {
|
|
763
|
-
node: element,
|
|
764
|
-
offset: newOffset
|
|
765
|
-
},
|
|
766
|
-
eventOverrides: {
|
|
767
|
-
inputType
|
|
768
|
-
}
|
|
769
|
-
});
|
|
770
|
-
}
|
|
840
|
+
type: "input",
|
|
841
|
+
selection: getUISelection(element)
|
|
771
842
|
};
|
|
772
843
|
}
|
|
844
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
845
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
846
|
+
return {
|
|
847
|
+
type: isCE ? "contenteditable" : "default",
|
|
848
|
+
selection
|
|
849
|
+
};
|
|
773
850
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
function
|
|
851
|
+
function getElement2(node) {
|
|
852
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
853
|
+
}
|
|
854
|
+
function updateSelectionOnFocus(element) {
|
|
778
855
|
var _a;
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
function restore() {
|
|
783
|
-
Object.defineProperties(el, {
|
|
784
|
-
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
785
|
-
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
786
|
-
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
787
|
-
});
|
|
856
|
+
const selection = element.ownerDocument.getSelection();
|
|
857
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
858
|
+
return;
|
|
788
859
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
796
|
-
set(v) {
|
|
797
|
-
var _a2;
|
|
798
|
-
if (v === "") {
|
|
799
|
-
restore();
|
|
800
|
-
} else {
|
|
801
|
-
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}),
|
|
805
|
-
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
806
|
-
set(v) {
|
|
807
|
-
if (v !== "file") {
|
|
808
|
-
restore();
|
|
809
|
-
el.type = v;
|
|
810
|
-
}
|
|
860
|
+
if (hasOwnSelection(element)) {
|
|
861
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
862
|
+
if (contenteditable) {
|
|
863
|
+
if (!selection.isCollapsed) {
|
|
864
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
865
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
811
866
|
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
// src/utils/misc/eventWrapper.ts
|
|
817
|
-
var import_dom = require("@testing-library/dom");
|
|
818
|
-
function eventWrapper(cb) {
|
|
819
|
-
let result;
|
|
820
|
-
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
821
|
-
result = cb();
|
|
822
|
-
});
|
|
823
|
-
return result;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
// src/utils/misc/isDisabled.ts
|
|
827
|
-
function isDisabled(element) {
|
|
828
|
-
return Boolean(element && element.disabled);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
// src/utils/focus/getActiveElement.ts
|
|
832
|
-
function getActiveElement(document2) {
|
|
833
|
-
const activeElement = document2.activeElement;
|
|
834
|
-
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
835
|
-
return getActiveElement(activeElement.shadowRoot);
|
|
836
|
-
} else {
|
|
837
|
-
if (isDisabled(activeElement)) {
|
|
838
|
-
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
867
|
+
} else {
|
|
868
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
839
869
|
}
|
|
840
|
-
return activeElement;
|
|
841
870
|
}
|
|
842
871
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
"input
|
|
847
|
-
|
|
848
|
-
"
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
'[contenteditable="true"]',
|
|
852
|
-
"a[href]",
|
|
853
|
-
"[tabindex]:not([disabled])"
|
|
854
|
-
].join(", ");
|
|
855
|
-
|
|
856
|
-
// src/utils/focus/isFocusable.ts
|
|
857
|
-
function isFocusable(element) {
|
|
858
|
-
return element.matches(FOCUSABLE_SELECTOR);
|
|
872
|
+
function getInputRange(focusNode) {
|
|
873
|
+
var _a;
|
|
874
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
875
|
+
if (typeAndSelection.type === "input") {
|
|
876
|
+
return typeAndSelection.selection;
|
|
877
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
878
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
879
|
+
}
|
|
859
880
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
881
|
+
function setSelection({
|
|
882
|
+
focusNode,
|
|
883
|
+
focusOffset,
|
|
884
|
+
anchorNode = focusNode,
|
|
885
|
+
anchorOffset = focusOffset
|
|
886
|
+
}) {
|
|
887
|
+
var _a, _b;
|
|
888
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
889
|
+
if (typeAndSelection.type === "input") {
|
|
890
|
+
return setUISelection(focusNode, {
|
|
891
|
+
anchorOffset,
|
|
892
|
+
focusOffset
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
896
|
+
}
|
|
897
|
+
function moveSelection(node, direction) {
|
|
898
|
+
if (hasOwnSelection(node)) {
|
|
899
|
+
const selection = getUISelection(node);
|
|
900
|
+
setSelection({
|
|
901
|
+
focusNode: node,
|
|
902
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
903
|
+
});
|
|
904
|
+
} else {
|
|
905
|
+
const selection = node.ownerDocument.getSelection();
|
|
906
|
+
if (!selection) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (selection.isCollapsed) {
|
|
910
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
911
|
+
if (nextPosition) {
|
|
912
|
+
setSelection({
|
|
913
|
+
focusNode: nextPosition.node,
|
|
914
|
+
focusOffset: nextPosition.offset
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
} else {
|
|
918
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
919
|
+
}
|
|
920
|
+
}
|
|
869
921
|
}
|
|
870
922
|
|
|
871
923
|
// src/utils/focus/copySelection.ts
|
|
@@ -1037,7 +1089,7 @@ var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
|
1037
1089
|
bracketDict2["["] = "]";
|
|
1038
1090
|
return bracketDict2;
|
|
1039
1091
|
})(bracketDict || {});
|
|
1040
|
-
function readNextDescriptor(text) {
|
|
1092
|
+
function readNextDescriptor(text, context) {
|
|
1041
1093
|
let pos = 0;
|
|
1042
1094
|
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
1043
1095
|
pos += startBracket.length;
|
|
@@ -1045,11 +1097,11 @@ function readNextDescriptor(text) {
|
|
|
1045
1097
|
const type3 = isEscapedChar ? "" : startBracket;
|
|
1046
1098
|
return __spreadValues({
|
|
1047
1099
|
type: type3
|
|
1048
|
-
}, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
|
|
1100
|
+
}, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
|
|
1049
1101
|
}
|
|
1050
|
-
function readPrintableChar(text, pos) {
|
|
1102
|
+
function readPrintableChar(text, pos, context) {
|
|
1051
1103
|
const descriptor = text[pos];
|
|
1052
|
-
assertDescriptor(descriptor, text, pos);
|
|
1104
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1053
1105
|
pos += descriptor.length;
|
|
1054
1106
|
return {
|
|
1055
1107
|
consumedLength: pos,
|
|
@@ -1059,14 +1111,14 @@ function readPrintableChar(text, pos) {
|
|
|
1059
1111
|
repeat: 1
|
|
1060
1112
|
};
|
|
1061
1113
|
}
|
|
1062
|
-
function readTag(text, pos, startBracket) {
|
|
1114
|
+
function readTag(text, pos, startBracket, context) {
|
|
1063
1115
|
var _a, _b, _c;
|
|
1064
1116
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1065
1117
|
pos += releasePreviousModifier.length;
|
|
1066
1118
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1067
1119
|
pos += Number(escapedDescriptor);
|
|
1068
1120
|
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1069
|
-
assertDescriptor(descriptor, text, pos);
|
|
1121
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1070
1122
|
pos += descriptor.length;
|
|
1071
1123
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
1072
1124
|
pos += repeatModifier.length;
|
|
@@ -1079,7 +1131,7 @@ function readTag(text, pos, startBracket) {
|
|
|
1079
1131
|
!repeatModifier && "repeat modifier",
|
|
1080
1132
|
!releaseSelfModifier && "release modifier",
|
|
1081
1133
|
`"${expectedEndBracket}"`
|
|
1082
|
-
].filter(Boolean).join(" or "), text[pos], text));
|
|
1134
|
+
].filter(Boolean).join(" or "), text[pos], text, context));
|
|
1083
1135
|
}
|
|
1084
1136
|
pos += endBracket.length;
|
|
1085
1137
|
return {
|
|
@@ -1090,9 +1142,9 @@ function readTag(text, pos, startBracket) {
|
|
|
1090
1142
|
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
1091
1143
|
};
|
|
1092
1144
|
}
|
|
1093
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
1145
|
+
function assertDescriptor(descriptor, text, pos, context) {
|
|
1094
1146
|
if (!descriptor) {
|
|
1095
|
-
throw new Error(getErrorMessage("key descriptor", text[pos], text));
|
|
1147
|
+
throw new Error(getErrorMessage("key descriptor", text[pos], text, context));
|
|
1096
1148
|
}
|
|
1097
1149
|
}
|
|
1098
1150
|
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
@@ -1103,9 +1155,9 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
1103
1155
|
return false;
|
|
1104
1156
|
}
|
|
1105
1157
|
}
|
|
1106
|
-
function getErrorMessage(expected, found, text) {
|
|
1158
|
+
function getErrorMessage(expected, found, text, context) {
|
|
1107
1159
|
return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
|
|
1108
|
-
See https://
|
|
1160
|
+
See ${context === "pointer" ? `https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen` : `https://testing-library.com/docs/user-event/keyboard`}
|
|
1109
1161
|
for more information about how userEvent parses your input.`;
|
|
1110
1162
|
}
|
|
1111
1163
|
|
|
@@ -1151,9 +1203,6 @@ function wait(time) {
|
|
|
1151
1203
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1152
1204
|
}
|
|
1153
1205
|
|
|
1154
|
-
// src/utils/misc/hasFormSubmit.ts
|
|
1155
|
-
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1156
|
-
|
|
1157
1206
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1158
1207
|
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1159
1208
|
|
|
@@ -1313,13 +1362,22 @@ function getMouseButtons(...buttons) {
|
|
|
1313
1362
|
|
|
1314
1363
|
// src/event/createEvent.ts
|
|
1315
1364
|
var import_dom2 = require("@testing-library/dom");
|
|
1316
|
-
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1317
1365
|
|
|
1318
|
-
// src/event/
|
|
1366
|
+
// src/event/eventMap.ts
|
|
1319
1367
|
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1320
|
-
var
|
|
1368
|
+
var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
|
|
1369
|
+
beforeInput: {
|
|
1370
|
+
EventType: "InputEvent",
|
|
1371
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1375
|
+
|
|
1376
|
+
// src/event/eventTypes.ts
|
|
1377
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1378
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map2.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1321
1379
|
function getEventClass(type3) {
|
|
1322
|
-
return
|
|
1380
|
+
return type3 in eventKeys ? import_event_map2.eventMap[eventKeys[type3]].EventType : "Event";
|
|
1323
1381
|
}
|
|
1324
1382
|
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1325
1383
|
function isMouseEvent(type3) {
|
|
@@ -1331,8 +1389,7 @@ function isKeyboardEvent(type3) {
|
|
|
1331
1389
|
|
|
1332
1390
|
// src/event/createEvent.ts
|
|
1333
1391
|
function createEvent(type3, target, init) {
|
|
1334
|
-
const
|
|
1335
|
-
const event = import_dom2.createEvent[eventKey](target, init);
|
|
1392
|
+
const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1336
1393
|
if (isMouseEvent(type3) && init) {
|
|
1337
1394
|
assignPositionInit(event, init);
|
|
1338
1395
|
assignPointerInit(event, init);
|
|
@@ -1383,8 +1440,8 @@ var behavior = {};
|
|
|
1383
1440
|
|
|
1384
1441
|
// src/event/behavior/click.ts
|
|
1385
1442
|
behavior.click = (event, target, config) => {
|
|
1386
|
-
|
|
1387
|
-
const control =
|
|
1443
|
+
const context = target.closest("button,input,label,textarea");
|
|
1444
|
+
const control = context && isElementType(context, "label") && context.control;
|
|
1388
1445
|
if (control) {
|
|
1389
1446
|
return () => {
|
|
1390
1447
|
if (isFocusable(control)) {
|
|
@@ -1401,11 +1458,169 @@ behavior.click = (event, target, config) => {
|
|
|
1401
1458
|
}
|
|
1402
1459
|
};
|
|
1403
1460
|
|
|
1461
|
+
// src/event/behavior/cut.ts
|
|
1462
|
+
behavior.cut = (event, target, config) => {
|
|
1463
|
+
return () => {
|
|
1464
|
+
if (isEditable(target)) {
|
|
1465
|
+
input(config, target, "", "deleteByCut");
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1470
|
+
// src/event/behavior/keydown.ts
|
|
1471
|
+
behavior.keydown = (event, target, config) => {
|
|
1472
|
+
var _a, _b;
|
|
1473
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1474
|
+
};
|
|
1475
|
+
var keydownBehavior = {
|
|
1476
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1477
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1478
|
+
Backspace: (event, target, config) => {
|
|
1479
|
+
if (isEditable(target)) {
|
|
1480
|
+
return () => {
|
|
1481
|
+
input(config, target, "", "deleteContentBackward");
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
},
|
|
1485
|
+
Delete: (event, target, config) => {
|
|
1486
|
+
if (isEditable(target)) {
|
|
1487
|
+
return () => {
|
|
1488
|
+
input(config, target, "", "deleteContentForward");
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
},
|
|
1492
|
+
End: (event, target) => {
|
|
1493
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1494
|
+
return () => {
|
|
1495
|
+
var _a, _b;
|
|
1496
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1497
|
+
setSelectionRange(target, newPos, newPos);
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
},
|
|
1501
|
+
Home: (event, target) => {
|
|
1502
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1503
|
+
return () => {
|
|
1504
|
+
setSelectionRange(target, 0, 0);
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
},
|
|
1508
|
+
PageDown: (event, target) => {
|
|
1509
|
+
if (isElementType(target, ["input"])) {
|
|
1510
|
+
return () => {
|
|
1511
|
+
const newPos = getValue(target).length;
|
|
1512
|
+
setSelectionRange(target, newPos, newPos);
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
},
|
|
1516
|
+
PageUp: (event, target) => {
|
|
1517
|
+
if (isElementType(target, ["input"])) {
|
|
1518
|
+
return () => {
|
|
1519
|
+
setSelectionRange(target, 0, 0);
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1524
|
+
return () => {
|
|
1525
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1526
|
+
focus(dest);
|
|
1527
|
+
if (hasOwnSelection(dest)) {
|
|
1528
|
+
setUISelection(dest, {
|
|
1529
|
+
anchorOffset: 0,
|
|
1530
|
+
focusOffset: dest.value.length
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
var combinationBehavior = (event, target, config) => {
|
|
1537
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1538
|
+
return () => selectAll(target);
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
// src/event/behavior/keypress.ts
|
|
1543
|
+
behavior.keypress = (event, target, config) => {
|
|
1544
|
+
if (event.key === "Enter") {
|
|
1545
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1546
|
+
return () => {
|
|
1547
|
+
dispatchUIEvent(config, target, "click");
|
|
1548
|
+
};
|
|
1549
|
+
} else if (isElementType(target, "input")) {
|
|
1550
|
+
const form = target.form;
|
|
1551
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1552
|
+
if (submit) {
|
|
1553
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1554
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1555
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1556
|
+
} else {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
if (isEditable(target)) {
|
|
1562
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1563
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1564
|
+
return () => input(config, target, inputData, inputType);
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
var ClickInputOnEnter = [
|
|
1568
|
+
"button",
|
|
1569
|
+
"color",
|
|
1570
|
+
"file",
|
|
1571
|
+
"image",
|
|
1572
|
+
"reset",
|
|
1573
|
+
"submit"
|
|
1574
|
+
];
|
|
1575
|
+
var SubmitSingleInputOnEnter = [
|
|
1576
|
+
"email",
|
|
1577
|
+
"month",
|
|
1578
|
+
"password",
|
|
1579
|
+
"search",
|
|
1580
|
+
"tel",
|
|
1581
|
+
"text",
|
|
1582
|
+
"url",
|
|
1583
|
+
"week"
|
|
1584
|
+
];
|
|
1585
|
+
|
|
1586
|
+
// src/event/behavior/keyup.ts
|
|
1587
|
+
behavior.keyup = (event, target, config) => {
|
|
1588
|
+
var _a;
|
|
1589
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1590
|
+
};
|
|
1591
|
+
var keyupBehavior = {
|
|
1592
|
+
" ": (event, target, config) => {
|
|
1593
|
+
if (isClickableInput(target)) {
|
|
1594
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/event/behavior/paste.ts
|
|
1600
|
+
behavior.paste = (event, target, config) => {
|
|
1601
|
+
if (isEditable(target)) {
|
|
1602
|
+
return () => {
|
|
1603
|
+
var _a;
|
|
1604
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1605
|
+
if (insertData) {
|
|
1606
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
// src/event/wrapEvent.ts
|
|
1613
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1614
|
+
function wrapEvent(cb, _element) {
|
|
1615
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1404
1618
|
// src/event/dispatchEvent.ts
|
|
1405
|
-
function dispatchEvent(config, target, event) {
|
|
1619
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1406
1620
|
var _a, _b;
|
|
1407
1621
|
const type3 = event.type;
|
|
1408
|
-
const behaviorImplementation =
|
|
1622
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1623
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1409
1624
|
if (behaviorImplementation) {
|
|
1410
1625
|
event.preventDefault();
|
|
1411
1626
|
let defaultPrevented = false;
|
|
@@ -1417,28 +1632,22 @@ function dispatchEvent(config, target, event) {
|
|
|
1417
1632
|
defaultPrevented = event.cancelable;
|
|
1418
1633
|
}
|
|
1419
1634
|
});
|
|
1420
|
-
target.dispatchEvent(event);
|
|
1635
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1421
1636
|
if (!defaultPrevented) {
|
|
1422
1637
|
behaviorImplementation();
|
|
1423
1638
|
}
|
|
1424
1639
|
return !defaultPrevented;
|
|
1425
1640
|
}
|
|
1426
|
-
return target.dispatchEvent(event);
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
// src/event/wrapEvent.ts
|
|
1430
|
-
var import_dom3 = require("@testing-library/dom");
|
|
1431
|
-
function wrapEvent(cb, _element) {
|
|
1432
|
-
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1641
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1433
1642
|
}
|
|
1434
1643
|
|
|
1435
1644
|
// src/event/index.ts
|
|
1436
|
-
function dispatchUIEvent(config, target, type3, init) {
|
|
1645
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1437
1646
|
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1438
1647
|
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1439
1648
|
}
|
|
1440
1649
|
const event = createEvent(type3, target, init);
|
|
1441
|
-
return
|
|
1650
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1442
1651
|
}
|
|
1443
1652
|
function bindDispatchUIEvent(config) {
|
|
1444
1653
|
return dispatchUIEvent.bind(void 0, config);
|
|
@@ -1619,259 +1828,7 @@ function prepareElement(el) {
|
|
|
1619
1828
|
el[isPrepared] = isPrepared;
|
|
1620
1829
|
}
|
|
1621
1830
|
|
|
1622
|
-
// src/keyboard/
|
|
1623
|
-
var keydownBehavior = [
|
|
1624
|
-
{
|
|
1625
|
-
matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
|
|
1626
|
-
handle: (keyDef, element) => {
|
|
1627
|
-
if (hasOwnSelection(element)) {
|
|
1628
|
-
const selection = getUISelection(element);
|
|
1629
|
-
setSelection({
|
|
1630
|
-
focusNode: element,
|
|
1631
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1632
|
-
});
|
|
1633
|
-
} else {
|
|
1634
|
-
const selection = element.ownerDocument.getSelection();
|
|
1635
|
-
if (!selection) {
|
|
1636
|
-
return;
|
|
1637
|
-
}
|
|
1638
|
-
if (selection.isCollapsed) {
|
|
1639
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1640
|
-
if (nextPosition) {
|
|
1641
|
-
setSelection({
|
|
1642
|
-
focusNode: nextPosition.node,
|
|
1643
|
-
focusOffset: nextPosition.offset
|
|
1644
|
-
});
|
|
1645
|
-
}
|
|
1646
|
-
} else {
|
|
1647
|
-
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
];
|
|
1653
|
-
|
|
1654
|
-
// src/keyboard/plugins/control.ts
|
|
1655
|
-
var keydownBehavior2 = [
|
|
1656
|
-
{
|
|
1657
|
-
matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
|
|
1658
|
-
handle: (keyDef, element) => {
|
|
1659
|
-
var _a, _b;
|
|
1660
|
-
if (keyDef.key === "Home") {
|
|
1661
|
-
setSelectionRange(element, 0, 0);
|
|
1662
|
-
} else {
|
|
1663
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1664
|
-
setSelectionRange(element, newPos, newPos);
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
|
|
1670
|
-
handle: (keyDef, element) => {
|
|
1671
|
-
var _a, _b;
|
|
1672
|
-
if (keyDef.key === "PageUp") {
|
|
1673
|
-
setSelectionRange(element, 0, 0);
|
|
1674
|
-
} else {
|
|
1675
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1676
|
-
setSelectionRange(element, newPos, newPos);
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
},
|
|
1680
|
-
{
|
|
1681
|
-
matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
|
|
1682
|
-
handle: (keDef, element, config) => {
|
|
1683
|
-
var _a;
|
|
1684
|
-
(_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
];
|
|
1688
|
-
|
|
1689
|
-
// src/keyboard/shared/fireChangeForInputTimeIfValid.ts
|
|
1690
|
-
function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
|
|
1691
|
-
if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
|
|
1692
|
-
setUIValue(el, timeNewEntry);
|
|
1693
|
-
dispatchUIEvent(config, el, "change");
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
// src/keyboard/plugins/character.ts
|
|
1698
|
-
var keypressBehavior = [
|
|
1699
|
-
{
|
|
1700
|
-
matches: (keyDef, element) => {
|
|
1701
|
-
var _a;
|
|
1702
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1703
|
-
},
|
|
1704
|
-
handle: (keyDef, element, config) => {
|
|
1705
|
-
var _a;
|
|
1706
|
-
let newEntry = keyDef.key;
|
|
1707
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1708
|
-
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1709
|
-
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1710
|
-
newEntry = timeNewEntry;
|
|
1711
|
-
}
|
|
1712
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1713
|
-
const prevValue = getValue(element);
|
|
1714
|
-
if (prevValue !== newValue) {
|
|
1715
|
-
editInputElement(config, element, {
|
|
1716
|
-
newValue,
|
|
1717
|
-
newSelection: {
|
|
1718
|
-
node: element,
|
|
1719
|
-
offset: newOffset
|
|
1720
|
-
},
|
|
1721
|
-
eventOverrides: {
|
|
1722
|
-
data: keyDef.key,
|
|
1723
|
-
inputType: "insertText"
|
|
1724
|
-
}
|
|
1725
|
-
});
|
|
1726
|
-
}
|
|
1727
|
-
fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
|
|
1728
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1729
|
-
}
|
|
1730
|
-
},
|
|
1731
|
-
{
|
|
1732
|
-
matches: (keyDef, element) => {
|
|
1733
|
-
var _a;
|
|
1734
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1735
|
-
},
|
|
1736
|
-
handle: (keyDef, element, config) => {
|
|
1737
|
-
var _a;
|
|
1738
|
-
let newEntry = keyDef.key;
|
|
1739
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1740
|
-
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1741
|
-
if (isValidToBeTyped) {
|
|
1742
|
-
newEntry = textToBeTyped;
|
|
1743
|
-
}
|
|
1744
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1745
|
-
const prevValue = getValue(element);
|
|
1746
|
-
if (prevValue !== newValue) {
|
|
1747
|
-
editInputElement(config, element, {
|
|
1748
|
-
newValue,
|
|
1749
|
-
newSelection: {
|
|
1750
|
-
node: element,
|
|
1751
|
-
offset: newOffset
|
|
1752
|
-
},
|
|
1753
|
-
eventOverrides: {
|
|
1754
|
-
data: keyDef.key,
|
|
1755
|
-
inputType: "insertText"
|
|
1756
|
-
}
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
if (isValidToBeTyped) {
|
|
1760
|
-
setUIValue(element, textToBeTyped);
|
|
1761
|
-
dispatchUIEvent(config, element, "change");
|
|
1762
|
-
}
|
|
1763
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1764
|
-
}
|
|
1765
|
-
},
|
|
1766
|
-
{
|
|
1767
|
-
matches: (keyDef, element) => {
|
|
1768
|
-
var _a;
|
|
1769
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1770
|
-
},
|
|
1771
|
-
handle: (keyDef, element, config) => {
|
|
1772
|
-
var _a, _b;
|
|
1773
|
-
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1774
|
-
return;
|
|
1775
|
-
}
|
|
1776
|
-
const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
|
|
1777
|
-
const newValue = getNewValue();
|
|
1778
|
-
const valueParts = newValue.split("e", 2);
|
|
1779
|
-
if (Number((_a = newValue.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = newValue.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1])) {
|
|
1780
|
-
return;
|
|
1781
|
-
}
|
|
1782
|
-
commit();
|
|
1783
|
-
}
|
|
1784
|
-
},
|
|
1785
|
-
{
|
|
1786
|
-
matches: (keyDef, element) => {
|
|
1787
|
-
var _a;
|
|
1788
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1789
|
-
},
|
|
1790
|
-
handle: (keyDef, element, config) => {
|
|
1791
|
-
var _a;
|
|
1792
|
-
(_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1793
|
-
}
|
|
1794
|
-
},
|
|
1795
|
-
{
|
|
1796
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1797
|
-
handle: (keyDef, element, config) => {
|
|
1798
|
-
var _a;
|
|
1799
|
-
(_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
];
|
|
1803
|
-
|
|
1804
|
-
// src/keyboard/plugins/functional.ts
|
|
1805
|
-
var keydownBehavior3 = [
|
|
1806
|
-
{
|
|
1807
|
-
matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
|
|
1808
|
-
handle: (keyDef, element, config) => {
|
|
1809
|
-
var _a;
|
|
1810
|
-
(_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1811
|
-
}
|
|
1812
|
-
},
|
|
1813
|
-
{
|
|
1814
|
-
matches: (keyDef) => keyDef.key === "Tab",
|
|
1815
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1816
|
-
const dest = getTabDestination(element, keyboardState.modifiers.Shift);
|
|
1817
|
-
if (dest === element.ownerDocument.body) {
|
|
1818
|
-
blur(element);
|
|
1819
|
-
} else {
|
|
1820
|
-
focus(dest);
|
|
1821
|
-
if (isElementType(dest, ["input", "textarea"])) {
|
|
1822
|
-
setUISelection(dest, {
|
|
1823
|
-
anchorOffset: 0,
|
|
1824
|
-
focusOffset: dest.value.length
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
];
|
|
1831
|
-
var keypressBehavior2 = [
|
|
1832
|
-
{
|
|
1833
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
|
|
1834
|
-
handle: (keyDef, element, config) => {
|
|
1835
|
-
const form = element.form;
|
|
1836
|
-
if (hasFormSubmit(form)) {
|
|
1837
|
-
dispatchUIEvent(config, form, "submit");
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
},
|
|
1841
|
-
{
|
|
1842
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1843
|
-
handle: (keyDef, element, config) => {
|
|
1844
|
-
dispatchUIEvent(config, element, "click");
|
|
1845
|
-
}
|
|
1846
|
-
},
|
|
1847
|
-
{
|
|
1848
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1849
|
-
handle: (keyDef, element, config) => {
|
|
1850
|
-
const form = element.form;
|
|
1851
|
-
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1852
|
-
dispatchUIEvent(config, form, "submit");
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
];
|
|
1857
|
-
var keyupBehavior = [
|
|
1858
|
-
{
|
|
1859
|
-
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1860
|
-
handle: (keyDef, element, config) => {
|
|
1861
|
-
dispatchUIEvent(config, element, "click");
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
];
|
|
1865
|
-
|
|
1866
|
-
// src/keyboard/plugins/combination.ts
|
|
1867
|
-
var keydownBehavior4 = [
|
|
1868
|
-
{
|
|
1869
|
-
matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
|
|
1870
|
-
handle: (keyDef, element) => selectAll(element)
|
|
1871
|
-
}
|
|
1872
|
-
];
|
|
1873
|
-
|
|
1874
|
-
// src/keyboard/plugins/modifiers.ts
|
|
1831
|
+
// src/keyboard/modifiers.ts
|
|
1875
1832
|
var modifierKeys = [
|
|
1876
1833
|
"Alt",
|
|
1877
1834
|
"AltGraph",
|
|
@@ -1881,6 +1838,9 @@ var modifierKeys = [
|
|
|
1881
1838
|
"Shift",
|
|
1882
1839
|
"Symbol"
|
|
1883
1840
|
];
|
|
1841
|
+
function isModifierKey(key) {
|
|
1842
|
+
return modifierKeys.includes(key);
|
|
1843
|
+
}
|
|
1884
1844
|
var modifierLocks = [
|
|
1885
1845
|
"CapsLock",
|
|
1886
1846
|
"FnLock",
|
|
@@ -1888,78 +1848,40 @@ var modifierLocks = [
|
|
|
1888
1848
|
"ScrollLock",
|
|
1889
1849
|
"SymbolLock"
|
|
1890
1850
|
];
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1851
|
+
function isModifierLock(key) {
|
|
1852
|
+
return modifierLocks.includes(key);
|
|
1853
|
+
}
|
|
1854
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1855
|
+
var _a;
|
|
1856
|
+
if (isModifierKey(key)) {
|
|
1857
|
+
config.keyboardState.modifiers[key] = true;
|
|
1858
|
+
if (key === "AltGraph") {
|
|
1859
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1860
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1901
1861
|
}
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
const key = keyDef.key;
|
|
1907
|
-
keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
|
|
1908
|
-
if (!keyboardState.modifierPhase[key]) {
|
|
1909
|
-
keyboardState.modifiers[key] = true;
|
|
1910
|
-
}
|
|
1862
|
+
} else if (isModifierLock(key)) {
|
|
1863
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1864
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1865
|
+
config.keyboardState.modifiers[key] = true;
|
|
1911
1866
|
}
|
|
1912
1867
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
{
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
},
|
|
1921
|
-
{
|
|
1922
|
-
matches: (keyDef) => modifierLocks.includes(keyDef.key),
|
|
1923
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1924
|
-
const key = keyDef.key;
|
|
1925
|
-
if (keyboardState.modifierPhase[key]) {
|
|
1926
|
-
keyboardState.modifiers[key] = false;
|
|
1927
|
-
}
|
|
1868
|
+
}
|
|
1869
|
+
function preKeyupBehavior(config, { key }) {
|
|
1870
|
+
if (isModifierKey(key)) {
|
|
1871
|
+
config.keyboardState.modifiers[key] = false;
|
|
1872
|
+
} else if (isModifierLock(key)) {
|
|
1873
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1874
|
+
config.keyboardState.modifiers[key] = false;
|
|
1928
1875
|
}
|
|
1929
1876
|
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1937
|
-
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1938
|
-
}
|
|
1877
|
+
}
|
|
1878
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1879
|
+
var _a;
|
|
1880
|
+
if (key === "AltGraph") {
|
|
1881
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1882
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1939
1883
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
// src/keyboard/plugins/index.ts
|
|
1943
|
-
var preKeydownBehavior2 = [
|
|
1944
|
-
...preKeydownBehavior
|
|
1945
|
-
];
|
|
1946
|
-
var keydownBehavior5 = [
|
|
1947
|
-
...keydownBehavior,
|
|
1948
|
-
...keydownBehavior2,
|
|
1949
|
-
...keydownBehavior3,
|
|
1950
|
-
...keydownBehavior4
|
|
1951
|
-
];
|
|
1952
|
-
var keypressBehavior3 = [
|
|
1953
|
-
...keypressBehavior2,
|
|
1954
|
-
...keypressBehavior
|
|
1955
|
-
];
|
|
1956
|
-
var preKeyupBehavior2 = [
|
|
1957
|
-
...preKeyupBehavior
|
|
1958
|
-
];
|
|
1959
|
-
var keyupBehavior2 = [...keyupBehavior];
|
|
1960
|
-
var postKeyupBehavior2 = [
|
|
1961
|
-
...postKeyupBehavior
|
|
1962
|
-
];
|
|
1884
|
+
}
|
|
1963
1885
|
|
|
1964
1886
|
// src/keyboard/keyboardAction.ts
|
|
1965
1887
|
async function keyboardAction(config, actions) {
|
|
@@ -2010,39 +1932,23 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
2010
1932
|
config.keyboardState.carryChar = "";
|
|
2011
1933
|
}
|
|
2012
1934
|
config.keyboardState.activeElement = element;
|
|
2013
|
-
|
|
1935
|
+
preKeydownBehavior(config, keyDef, element);
|
|
2014
1936
|
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
2015
1937
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
2016
|
-
if (unpreventedDefault) {
|
|
2017
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
2018
|
-
}
|
|
2019
1938
|
return unpreventedDefault;
|
|
2020
1939
|
}
|
|
2021
1940
|
async function keypress(keyDef, getCurrentElement, config) {
|
|
2022
1941
|
const element = getCurrentElement();
|
|
2023
|
-
|
|
1942
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2024
1943
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2025
1944
|
}));
|
|
2026
|
-
if (unpreventedDefault) {
|
|
2027
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2028
|
-
}
|
|
2029
1945
|
}
|
|
2030
1946
|
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2031
1947
|
const element = getCurrentElement();
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
if (unprevented && unpreventedDefault) {
|
|
2035
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2036
|
-
}
|
|
1948
|
+
preKeyupBehavior(config, keyDef);
|
|
1949
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2037
1950
|
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
2038
|
-
|
|
2039
|
-
}
|
|
2040
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
2041
|
-
const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
|
|
2042
|
-
if (plugin) {
|
|
2043
|
-
plugin.handle(keyDef, element, config);
|
|
2044
|
-
}
|
|
2045
|
-
return !!plugin;
|
|
1951
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2046
1952
|
}
|
|
2047
1953
|
function hasKeyPress(keyDef, config) {
|
|
2048
1954
|
var _a;
|
|
@@ -2061,7 +1967,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2061
1967
|
releasePrevious,
|
|
2062
1968
|
releaseSelf = true,
|
|
2063
1969
|
repeat
|
|
2064
|
-
} = readNextDescriptor(text);
|
|
1970
|
+
} = readNextDescriptor(text, "keyboard");
|
|
2065
1971
|
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2066
1972
|
var _a2, _b;
|
|
2067
1973
|
if (type3 === "[") {
|
|
@@ -2118,7 +2024,7 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2118
2024
|
consumedLength,
|
|
2119
2025
|
releasePrevious,
|
|
2120
2026
|
releaseSelf = true
|
|
2121
|
-
} = readNextDescriptor(keys);
|
|
2027
|
+
} = readNextDescriptor(keys, "pointer");
|
|
2122
2028
|
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
2123
2029
|
if (keyDef) {
|
|
2124
2030
|
defs.push({ keyDef, releasePrevious, releaseSelf });
|
|
@@ -2535,10 +2441,10 @@ function getPrevTarget(pointerName, state) {
|
|
|
2535
2441
|
}
|
|
2536
2442
|
|
|
2537
2443
|
// src/pointer/index.ts
|
|
2538
|
-
async function pointer(
|
|
2444
|
+
async function pointer(input2) {
|
|
2539
2445
|
const { pointerMap } = this[Config];
|
|
2540
2446
|
const actions = [];
|
|
2541
|
-
(Array.isArray(
|
|
2447
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2542
2448
|
if (typeof actionInput === "string") {
|
|
2543
2449
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2544
2450
|
} else if ("keys" in actionInput) {
|
|
@@ -2637,10 +2543,9 @@ async function copy() {
|
|
|
2637
2543
|
if (clipboardData.items.length === 0) {
|
|
2638
2544
|
return;
|
|
2639
2545
|
}
|
|
2640
|
-
this.dispatchUIEvent(target, "copy", {
|
|
2546
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2641
2547
|
clipboardData
|
|
2642
|
-
})
|
|
2643
|
-
if (this[Config].writeToClipboard) {
|
|
2548
|
+
}) && this[Config].writeToClipboard) {
|
|
2644
2549
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2645
2550
|
}
|
|
2646
2551
|
return clipboardData;
|
|
@@ -2648,28 +2553,24 @@ async function copy() {
|
|
|
2648
2553
|
|
|
2649
2554
|
// src/clipboard/cut.ts
|
|
2650
2555
|
async function cut() {
|
|
2651
|
-
var _a
|
|
2556
|
+
var _a;
|
|
2652
2557
|
const doc = this[Config].document;
|
|
2653
2558
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2654
2559
|
const clipboardData = copySelection(target);
|
|
2655
2560
|
if (clipboardData.items.length === 0) {
|
|
2656
2561
|
return;
|
|
2657
2562
|
}
|
|
2658
|
-
this.dispatchUIEvent(target, "cut", {
|
|
2563
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2659
2564
|
clipboardData
|
|
2660
|
-
})
|
|
2661
|
-
|
|
2662
|
-
(_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2663
|
-
}
|
|
2664
|
-
if (this[Config].writeToClipboard) {
|
|
2665
|
-
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2565
|
+
}) && this[Config].writeToClipboard) {
|
|
2566
|
+
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2666
2567
|
}
|
|
2667
2568
|
return clipboardData;
|
|
2668
2569
|
}
|
|
2669
2570
|
|
|
2670
2571
|
// src/clipboard/paste.ts
|
|
2671
2572
|
async function paste(clipboardData) {
|
|
2672
|
-
var _a, _b
|
|
2573
|
+
var _a, _b;
|
|
2673
2574
|
const doc = this[Config].document;
|
|
2674
2575
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2675
2576
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
@@ -2678,12 +2579,6 @@ async function paste(clipboardData) {
|
|
|
2678
2579
|
this.dispatchUIEvent(target, "paste", {
|
|
2679
2580
|
clipboardData: dataTransfer
|
|
2680
2581
|
});
|
|
2681
|
-
if (isEditable(target)) {
|
|
2682
|
-
const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2683
|
-
if (textData) {
|
|
2684
|
-
(_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
2582
|
}
|
|
2688
2583
|
function getClipboardDataFromString(text) {
|
|
2689
2584
|
const dt = createDataTransfer();
|
|
@@ -2693,7 +2588,6 @@ function getClipboardDataFromString(text) {
|
|
|
2693
2588
|
|
|
2694
2589
|
// src/utility/clear.ts
|
|
2695
2590
|
async function clear(element) {
|
|
2696
|
-
var _a;
|
|
2697
2591
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2698
2592
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2699
2593
|
}
|
|
@@ -2705,7 +2599,7 @@ async function clear(element) {
|
|
|
2705
2599
|
if (!isAllSelected(element)) {
|
|
2706
2600
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2707
2601
|
}
|
|
2708
|
-
(
|
|
2602
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2709
2603
|
}
|
|
2710
2604
|
|
|
2711
2605
|
// src/utility/selectOptions.ts
|
|
@@ -2822,28 +2716,28 @@ async function type(element, text, {
|
|
|
2822
2716
|
|
|
2823
2717
|
// src/utility/upload.ts
|
|
2824
2718
|
async function upload(element, fileOrFiles) {
|
|
2825
|
-
const
|
|
2826
|
-
if (!
|
|
2827
|
-
throw new TypeError(`The ${
|
|
2719
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2720
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2721
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2828
2722
|
}
|
|
2829
2723
|
if (isDisabled(element))
|
|
2830
2724
|
return;
|
|
2831
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file,
|
|
2725
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2832
2726
|
const fileDialog = () => {
|
|
2833
2727
|
var _a;
|
|
2834
|
-
if (files.length === ((_a =
|
|
2728
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2835
2729
|
var _a2;
|
|
2836
|
-
return f === ((_a2 =
|
|
2730
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2837
2731
|
})) {
|
|
2838
2732
|
return;
|
|
2839
2733
|
}
|
|
2840
|
-
setFiles(
|
|
2841
|
-
this.dispatchUIEvent(
|
|
2842
|
-
this.dispatchUIEvent(
|
|
2734
|
+
setFiles(input2, createFileList(files));
|
|
2735
|
+
this.dispatchUIEvent(input2, "input");
|
|
2736
|
+
this.dispatchUIEvent(input2, "change");
|
|
2843
2737
|
};
|
|
2844
|
-
|
|
2738
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2845
2739
|
await this.click(element);
|
|
2846
|
-
|
|
2740
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2847
2741
|
}
|
|
2848
2742
|
function isAcceptableFile(file, accept) {
|
|
2849
2743
|
if (!accept) {
|
|
@@ -2968,9 +2862,9 @@ async function keyboard2(text, options = {}) {
|
|
|
2968
2862
|
const { config, api } = setupDirect(options);
|
|
2969
2863
|
return api.keyboard(text).then(() => config.keyboardState);
|
|
2970
2864
|
}
|
|
2971
|
-
async function pointer2(
|
|
2865
|
+
async function pointer2(input2, options = {}) {
|
|
2972
2866
|
const { config, api } = setupDirect(options);
|
|
2973
|
-
return api.pointer(
|
|
2867
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2974
2868
|
}
|
|
2975
2869
|
function paste2(clipboardData, options) {
|
|
2976
2870
|
return setupDirect(options).api.paste(clipboardData);
|
|
@@ -3000,4 +2894,3 @@ function tab2(options = {}) {
|
|
|
3000
2894
|
var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
|
|
3001
2895
|
setup: setupMain
|
|
3002
2896
|
});
|
|
3003
|
-
module.exports = __toCommonJS(src_exports);
|