@testing-library/user-event 14.0.0-beta.10 → 14.0.0-beta.13
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 +609 -711
- package/dist/index.mjs +609 -711
- 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 +345 -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/package.json +1 -1
- 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
|
@@ -340,6 +340,29 @@ if (typeof afterAll === "function") {
|
|
|
340
340
|
afterAll(() => detachClipboardStubFromView(window));
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
+
// src/utils/edit/isContentEditable.ts
|
|
344
|
+
function isContentEditable(element) {
|
|
345
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
346
|
+
}
|
|
347
|
+
function getContentEditable(node) {
|
|
348
|
+
const element = getElement(node);
|
|
349
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
350
|
+
}
|
|
351
|
+
function getElement(node) {
|
|
352
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/utils/edit/getValue.ts
|
|
356
|
+
function getValue(element) {
|
|
357
|
+
if (!element) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
if (isContentEditable(element)) {
|
|
361
|
+
return element.textContent;
|
|
362
|
+
}
|
|
363
|
+
return getUIValue(element);
|
|
364
|
+
}
|
|
365
|
+
|
|
343
366
|
// src/utils/edit/buildTimeValue.ts
|
|
344
367
|
function buildTimeValue(value) {
|
|
345
368
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -371,21 +394,137 @@ function build(onlyDigitsValue, index) {
|
|
|
371
394
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
372
395
|
}
|
|
373
396
|
|
|
374
|
-
// src/utils/edit/
|
|
375
|
-
function
|
|
397
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
398
|
+
function isValidDateOrTimeValue(element, value) {
|
|
376
399
|
const clone = element.cloneNode();
|
|
377
400
|
clone.value = value;
|
|
378
401
|
return clone.value === value;
|
|
379
402
|
}
|
|
380
403
|
|
|
381
|
-
// src/utils/edit/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
404
|
+
// src/utils/edit/maxLength.ts
|
|
405
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
406
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
407
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
408
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
409
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
410
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
411
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
412
|
+
return maxLengthSupportedTypes2;
|
|
413
|
+
})(maxLengthSupportedTypes || {});
|
|
414
|
+
function getSpaceUntilMaxLength(element) {
|
|
415
|
+
const value = getValue(element);
|
|
416
|
+
if (value === null) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
420
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
421
|
+
}
|
|
422
|
+
function getSanitizedMaxLength(element) {
|
|
423
|
+
var _a;
|
|
424
|
+
if (!supportsMaxLength(element)) {
|
|
425
|
+
return void 0;
|
|
426
|
+
}
|
|
427
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
428
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
429
|
+
}
|
|
430
|
+
function supportsMaxLength(element) {
|
|
431
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
386
432
|
}
|
|
387
433
|
|
|
388
|
-
// src/utils/edit/
|
|
434
|
+
// src/utils/edit/input.ts
|
|
435
|
+
function isDateOrTime(element) {
|
|
436
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
437
|
+
}
|
|
438
|
+
function input(config, element, data, inputType = "insertText") {
|
|
439
|
+
const inputRange = getInputRange(element);
|
|
440
|
+
if (!inputRange) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (!isDateOrTime(element)) {
|
|
444
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
445
|
+
inputType,
|
|
446
|
+
data
|
|
447
|
+
});
|
|
448
|
+
if (!unprevented) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if ("startContainer" in inputRange) {
|
|
453
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
454
|
+
} else {
|
|
455
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
459
|
+
let del = false;
|
|
460
|
+
if (!inputRange.collapsed) {
|
|
461
|
+
del = true;
|
|
462
|
+
inputRange.deleteContents();
|
|
463
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
464
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
465
|
+
if (nextPosition) {
|
|
466
|
+
del = true;
|
|
467
|
+
const delRange = inputRange.cloneRange();
|
|
468
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
469
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
470
|
+
} else {
|
|
471
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
472
|
+
}
|
|
473
|
+
delRange.deleteContents();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (data) {
|
|
477
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
478
|
+
const offset = inputRange.endOffset;
|
|
479
|
+
inputRange.endContainer.insertData(offset, data);
|
|
480
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
481
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
482
|
+
} else {
|
|
483
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
484
|
+
inputRange.insertNode(text);
|
|
485
|
+
inputRange.setStart(text, data.length);
|
|
486
|
+
inputRange.setEnd(text, data.length);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (del || data) {
|
|
490
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
494
|
+
let dataToInsert = data;
|
|
495
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
496
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
497
|
+
if (spaceUntilMaxLength > 0) {
|
|
498
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
499
|
+
} else {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
504
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
setUIValue(element, newValue);
|
|
511
|
+
setSelection({
|
|
512
|
+
focusNode: element,
|
|
513
|
+
anchorOffset: newOffset,
|
|
514
|
+
focusOffset: newOffset
|
|
515
|
+
});
|
|
516
|
+
if (isDateOrTime(element)) {
|
|
517
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
518
|
+
commitInput(config, element, oldValue, newValue, newOffset, {});
|
|
519
|
+
dispatchUIEvent(config, element, "change");
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
commitInput(config, element, oldValue, newValue, newOffset, {
|
|
523
|
+
data,
|
|
524
|
+
inputType
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}
|
|
389
528
|
function calculateNewValue(inputData, node, {
|
|
390
529
|
startOffset,
|
|
391
530
|
endOffset
|
|
@@ -396,15 +535,12 @@ function calculateNewValue(inputData, node, {
|
|
|
396
535
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
397
536
|
const epilog = value.substring(epilogStart, value.length);
|
|
398
537
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
399
|
-
|
|
400
|
-
if (node
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
newValue = inputData;
|
|
406
|
-
} else {
|
|
407
|
-
newValue = value;
|
|
538
|
+
let newOffset = prologEnd + inputData.length;
|
|
539
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
540
|
+
const builtValue = buildTimeValue(newValue);
|
|
541
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
542
|
+
newValue = builtValue;
|
|
543
|
+
newOffset = builtValue.length;
|
|
408
544
|
}
|
|
409
545
|
}
|
|
410
546
|
return {
|
|
@@ -413,17 +549,22 @@ function calculateNewValue(inputData, node, {
|
|
|
413
549
|
newOffset
|
|
414
550
|
};
|
|
415
551
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
552
|
+
function commitInput(config, element, oldValue, newValue, newOffset, inputInit) {
|
|
553
|
+
startTrackValue(element);
|
|
554
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
555
|
+
const tracked = endTrackValue(element);
|
|
556
|
+
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
557
|
+
setSelection({
|
|
558
|
+
focusNode: element,
|
|
559
|
+
anchorOffset: newOffset,
|
|
560
|
+
focusOffset: newOffset
|
|
561
|
+
});
|
|
562
|
+
}
|
|
424
563
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
564
|
+
function isValidNumberInput(value) {
|
|
565
|
+
var _a, _b;
|
|
566
|
+
const valueParts = value.split("e", 2);
|
|
567
|
+
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
568
|
}
|
|
428
569
|
|
|
429
570
|
// src/utils/edit/isEditable.ts
|
|
@@ -449,157 +590,123 @@ function isEditableInput(element) {
|
|
|
449
590
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
450
591
|
}
|
|
451
592
|
|
|
452
|
-
// src/utils/
|
|
453
|
-
|
|
593
|
+
// src/utils/edit/setFiles.ts
|
|
594
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
595
|
+
function setFiles(el, files) {
|
|
454
596
|
var _a;
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
return setSelection({
|
|
464
|
-
focusNode: element.firstChild,
|
|
465
|
-
anchorOffset,
|
|
466
|
-
focusOffset
|
|
597
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
598
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
599
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
600
|
+
function restore() {
|
|
601
|
+
Object.defineProperties(el, {
|
|
602
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
603
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
604
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
467
605
|
});
|
|
468
606
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
607
|
+
el[fakeFiles] = { restore };
|
|
608
|
+
Object.defineProperties(el, {
|
|
609
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
610
|
+
get: () => files
|
|
611
|
+
}),
|
|
612
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
613
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
614
|
+
set(v) {
|
|
615
|
+
var _a2;
|
|
616
|
+
if (v === "") {
|
|
617
|
+
restore();
|
|
618
|
+
} else {
|
|
619
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}),
|
|
623
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
624
|
+
set(v) {
|
|
625
|
+
if (v !== "file") {
|
|
626
|
+
restore();
|
|
627
|
+
el.type = v;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
})
|
|
631
|
+
});
|
|
491
632
|
}
|
|
492
|
-
|
|
493
|
-
|
|
633
|
+
|
|
634
|
+
// src/utils/misc/eventWrapper.ts
|
|
635
|
+
var import_dom = require("@testing-library/dom");
|
|
636
|
+
function eventWrapper(cb) {
|
|
637
|
+
let result;
|
|
638
|
+
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
639
|
+
result = cb();
|
|
640
|
+
});
|
|
641
|
+
return result;
|
|
494
642
|
}
|
|
495
|
-
|
|
643
|
+
|
|
644
|
+
// src/utils/misc/isDisabled.ts
|
|
645
|
+
function isDisabled(element) {
|
|
496
646
|
var _a;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
647
|
+
for (let el = element; el; el = el.parentElement) {
|
|
648
|
+
if (isElementType(el, [
|
|
649
|
+
"button",
|
|
650
|
+
"input",
|
|
651
|
+
"select",
|
|
652
|
+
"textarea",
|
|
653
|
+
"optgroup",
|
|
654
|
+
"option"
|
|
655
|
+
])) {
|
|
656
|
+
if (el.hasAttribute("disabled")) {
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
} else if (isElementType(el, "fieldset")) {
|
|
660
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
} else if (el.tagName.includes("-")) {
|
|
664
|
+
if (el.constructor.formAssociated && el.hasAttribute("disabled")) {
|
|
665
|
+
return true;
|
|
507
666
|
}
|
|
508
|
-
} else {
|
|
509
|
-
selection.setBaseAndExtent(element, 0, element, 0);
|
|
510
667
|
}
|
|
511
668
|
}
|
|
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);
|
|
669
|
+
return false;
|
|
537
670
|
}
|
|
538
671
|
|
|
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
|
-
});
|
|
672
|
+
// src/utils/focus/getActiveElement.ts
|
|
673
|
+
function getActiveElement(document2) {
|
|
674
|
+
const activeElement = document2.activeElement;
|
|
675
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
676
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
677
|
+
} else {
|
|
678
|
+
if (isDisabled(activeElement)) {
|
|
679
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
680
|
+
}
|
|
681
|
+
return activeElement;
|
|
561
682
|
}
|
|
562
683
|
}
|
|
563
684
|
|
|
564
|
-
// src/utils/
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
685
|
+
// src/utils/focus/selector.ts
|
|
686
|
+
var FOCUSABLE_SELECTOR = [
|
|
687
|
+
"input:not([type=hidden]):not([disabled])",
|
|
688
|
+
"button:not([disabled])",
|
|
689
|
+
"select:not([disabled])",
|
|
690
|
+
"textarea:not([disabled])",
|
|
691
|
+
'[contenteditable=""]',
|
|
692
|
+
'[contenteditable="true"]',
|
|
693
|
+
"a[href]",
|
|
694
|
+
"[tabindex]:not([disabled])"
|
|
695
|
+
].join(", ");
|
|
574
696
|
|
|
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;
|
|
697
|
+
// src/utils/focus/isFocusable.ts
|
|
698
|
+
function isFocusable(element) {
|
|
699
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
600
700
|
}
|
|
601
|
-
|
|
602
|
-
|
|
701
|
+
|
|
702
|
+
// src/utils/focus/blur.ts
|
|
703
|
+
function blur(element) {
|
|
704
|
+
if (!isFocusable(element))
|
|
705
|
+
return;
|
|
706
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
707
|
+
if (!wasActive)
|
|
708
|
+
return;
|
|
709
|
+
eventWrapper(() => element.blur());
|
|
603
710
|
}
|
|
604
711
|
|
|
605
712
|
// src/utils/focus/cursor.ts
|
|
@@ -650,7 +757,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
650
757
|
}
|
|
651
758
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
652
759
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
653
|
-
if (offset !== void 0 &&
|
|
760
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
654
761
|
node = node.children[nextOffset];
|
|
655
762
|
}
|
|
656
763
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -659,7 +766,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
659
766
|
if (isTextNode(node)) {
|
|
660
767
|
return true;
|
|
661
768
|
}
|
|
662
|
-
if (
|
|
769
|
+
if (isElement(node)) {
|
|
663
770
|
if (isElementType(node, ["input", "textarea"])) {
|
|
664
771
|
return node.type !== "hidden";
|
|
665
772
|
} else if (isElementType(node, "br")) {
|
|
@@ -676,7 +783,7 @@ function getOffset(node) {
|
|
|
676
783
|
}
|
|
677
784
|
return i;
|
|
678
785
|
}
|
|
679
|
-
function
|
|
786
|
+
function isElement(node) {
|
|
680
787
|
return node.nodeType === 1;
|
|
681
788
|
}
|
|
682
789
|
function isTextNode(node) {
|
|
@@ -691,7 +798,7 @@ function walkNodes(node, direction, callback) {
|
|
|
691
798
|
if (callback(node)) {
|
|
692
799
|
return node;
|
|
693
800
|
}
|
|
694
|
-
} else if (node.parentNode && (!
|
|
801
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
695
802
|
node = node.parentNode;
|
|
696
803
|
} else {
|
|
697
804
|
break;
|
|
@@ -705,167 +812,116 @@ function getDescendant(node, direction) {
|
|
|
705
812
|
return node;
|
|
706
813
|
}
|
|
707
814
|
|
|
708
|
-
// src/utils/
|
|
709
|
-
function
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
return
|
|
815
|
+
// src/utils/focus/selection.ts
|
|
816
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
817
|
+
var _a;
|
|
818
|
+
if (hasOwnSelection(element)) {
|
|
819
|
+
return setSelection({
|
|
820
|
+
focusNode: element,
|
|
821
|
+
anchorOffset,
|
|
822
|
+
focusOffset
|
|
823
|
+
});
|
|
713
824
|
}
|
|
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 {
|
|
825
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
826
|
+
return setSelection({
|
|
827
|
+
focusNode: element.firstChild,
|
|
828
|
+
anchorOffset,
|
|
829
|
+
focusOffset
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
833
|
+
}
|
|
834
|
+
function hasOwnSelection(node) {
|
|
835
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
836
|
+
}
|
|
837
|
+
function isElement2(node) {
|
|
838
|
+
return node.nodeType === 1;
|
|
839
|
+
}
|
|
840
|
+
function getTargetTypeAndSelection(node) {
|
|
841
|
+
const element = getElement2(node);
|
|
842
|
+
if (element && hasOwnSelection(element)) {
|
|
753
843
|
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
|
-
}
|
|
844
|
+
type: "input",
|
|
845
|
+
selection: getUISelection(element)
|
|
771
846
|
};
|
|
772
847
|
}
|
|
848
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
849
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
850
|
+
return {
|
|
851
|
+
type: isCE ? "contenteditable" : "default",
|
|
852
|
+
selection
|
|
853
|
+
};
|
|
773
854
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
function
|
|
855
|
+
function getElement2(node) {
|
|
856
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
857
|
+
}
|
|
858
|
+
function updateSelectionOnFocus(element) {
|
|
778
859
|
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
|
-
});
|
|
860
|
+
const selection = element.ownerDocument.getSelection();
|
|
861
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
862
|
+
return;
|
|
788
863
|
}
|
|
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
|
-
}
|
|
864
|
+
if (hasOwnSelection(element)) {
|
|
865
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
866
|
+
if (contenteditable) {
|
|
867
|
+
if (!selection.isCollapsed) {
|
|
868
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
869
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
811
870
|
}
|
|
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;
|
|
871
|
+
} else {
|
|
872
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
839
873
|
}
|
|
840
|
-
return activeElement;
|
|
841
874
|
}
|
|
842
875
|
}
|
|
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);
|
|
876
|
+
function getInputRange(focusNode) {
|
|
877
|
+
var _a;
|
|
878
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
879
|
+
if (typeAndSelection.type === "input") {
|
|
880
|
+
return typeAndSelection.selection;
|
|
881
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
882
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
883
|
+
}
|
|
859
884
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
885
|
+
function setSelection({
|
|
886
|
+
focusNode,
|
|
887
|
+
focusOffset,
|
|
888
|
+
anchorNode = focusNode,
|
|
889
|
+
anchorOffset = focusOffset
|
|
890
|
+
}) {
|
|
891
|
+
var _a, _b;
|
|
892
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
893
|
+
if (typeAndSelection.type === "input") {
|
|
894
|
+
return setUISelection(focusNode, {
|
|
895
|
+
anchorOffset,
|
|
896
|
+
focusOffset
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
900
|
+
}
|
|
901
|
+
function moveSelection(node, direction) {
|
|
902
|
+
if (hasOwnSelection(node)) {
|
|
903
|
+
const selection = getUISelection(node);
|
|
904
|
+
setSelection({
|
|
905
|
+
focusNode: node,
|
|
906
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
907
|
+
});
|
|
908
|
+
} else {
|
|
909
|
+
const selection = node.ownerDocument.getSelection();
|
|
910
|
+
if (!selection) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
if (selection.isCollapsed) {
|
|
914
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
915
|
+
if (nextPosition) {
|
|
916
|
+
setSelection({
|
|
917
|
+
focusNode: nextPosition.node,
|
|
918
|
+
focusOffset: nextPosition.offset
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
} else {
|
|
922
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
923
|
+
}
|
|
924
|
+
}
|
|
869
925
|
}
|
|
870
926
|
|
|
871
927
|
// src/utils/focus/copySelection.ts
|
|
@@ -1151,9 +1207,6 @@ function wait(time) {
|
|
|
1151
1207
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1152
1208
|
}
|
|
1153
1209
|
|
|
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
1210
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1158
1211
|
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1159
1212
|
|
|
@@ -1313,13 +1366,22 @@ function getMouseButtons(...buttons) {
|
|
|
1313
1366
|
|
|
1314
1367
|
// src/event/createEvent.ts
|
|
1315
1368
|
var import_dom2 = require("@testing-library/dom");
|
|
1316
|
-
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1317
1369
|
|
|
1318
|
-
// src/event/
|
|
1370
|
+
// src/event/eventMap.ts
|
|
1319
1371
|
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1320
|
-
var
|
|
1372
|
+
var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
|
|
1373
|
+
beforeInput: {
|
|
1374
|
+
EventType: "InputEvent",
|
|
1375
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1379
|
+
|
|
1380
|
+
// src/event/eventTypes.ts
|
|
1381
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1382
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map2.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1321
1383
|
function getEventClass(type3) {
|
|
1322
|
-
return
|
|
1384
|
+
return type3 in eventKeys ? import_event_map2.eventMap[eventKeys[type3]].EventType : "Event";
|
|
1323
1385
|
}
|
|
1324
1386
|
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1325
1387
|
function isMouseEvent(type3) {
|
|
@@ -1331,8 +1393,7 @@ function isKeyboardEvent(type3) {
|
|
|
1331
1393
|
|
|
1332
1394
|
// src/event/createEvent.ts
|
|
1333
1395
|
function createEvent(type3, target, init) {
|
|
1334
|
-
const
|
|
1335
|
-
const event = import_dom2.createEvent[eventKey](target, init);
|
|
1396
|
+
const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1336
1397
|
if (isMouseEvent(type3) && init) {
|
|
1337
1398
|
assignPositionInit(event, init);
|
|
1338
1399
|
assignPointerInit(event, init);
|
|
@@ -1401,11 +1462,169 @@ behavior.click = (event, target, config) => {
|
|
|
1401
1462
|
}
|
|
1402
1463
|
};
|
|
1403
1464
|
|
|
1465
|
+
// src/event/behavior/cut.ts
|
|
1466
|
+
behavior.cut = (event, target, config) => {
|
|
1467
|
+
return () => {
|
|
1468
|
+
if (isEditable(target)) {
|
|
1469
|
+
input(config, target, "", "deleteByCut");
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1474
|
+
// src/event/behavior/keydown.ts
|
|
1475
|
+
behavior.keydown = (event, target, config) => {
|
|
1476
|
+
var _a, _b;
|
|
1477
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1478
|
+
};
|
|
1479
|
+
var keydownBehavior = {
|
|
1480
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1481
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1482
|
+
Backspace: (event, target, config) => {
|
|
1483
|
+
if (isEditable(target)) {
|
|
1484
|
+
return () => {
|
|
1485
|
+
input(config, target, "", "deleteContentBackward");
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
Delete: (event, target, config) => {
|
|
1490
|
+
if (isEditable(target)) {
|
|
1491
|
+
return () => {
|
|
1492
|
+
input(config, target, "", "deleteContentForward");
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
End: (event, target) => {
|
|
1497
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1498
|
+
return () => {
|
|
1499
|
+
var _a, _b;
|
|
1500
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1501
|
+
setSelectionRange(target, newPos, newPos);
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
Home: (event, target) => {
|
|
1506
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1507
|
+
return () => {
|
|
1508
|
+
setSelectionRange(target, 0, 0);
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
PageDown: (event, target) => {
|
|
1513
|
+
if (isElementType(target, ["input"])) {
|
|
1514
|
+
return () => {
|
|
1515
|
+
const newPos = getValue(target).length;
|
|
1516
|
+
setSelectionRange(target, newPos, newPos);
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
},
|
|
1520
|
+
PageUp: (event, target) => {
|
|
1521
|
+
if (isElementType(target, ["input"])) {
|
|
1522
|
+
return () => {
|
|
1523
|
+
setSelectionRange(target, 0, 0);
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1528
|
+
return () => {
|
|
1529
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1530
|
+
focus(dest);
|
|
1531
|
+
if (hasOwnSelection(dest)) {
|
|
1532
|
+
setUISelection(dest, {
|
|
1533
|
+
anchorOffset: 0,
|
|
1534
|
+
focusOffset: dest.value.length
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
var combinationBehavior = (event, target, config) => {
|
|
1541
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1542
|
+
return () => selectAll(target);
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
// src/event/behavior/keypress.ts
|
|
1547
|
+
behavior.keypress = (event, target, config) => {
|
|
1548
|
+
if (event.key === "Enter") {
|
|
1549
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1550
|
+
return () => {
|
|
1551
|
+
dispatchUIEvent(config, target, "click");
|
|
1552
|
+
};
|
|
1553
|
+
} else if (isElementType(target, "input")) {
|
|
1554
|
+
const form = target.form;
|
|
1555
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1556
|
+
if (submit) {
|
|
1557
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1558
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1559
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1560
|
+
} else {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (isEditable(target)) {
|
|
1566
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1567
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1568
|
+
return () => input(config, target, inputData, inputType);
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
var ClickInputOnEnter = [
|
|
1572
|
+
"button",
|
|
1573
|
+
"color",
|
|
1574
|
+
"file",
|
|
1575
|
+
"image",
|
|
1576
|
+
"reset",
|
|
1577
|
+
"submit"
|
|
1578
|
+
];
|
|
1579
|
+
var SubmitSingleInputOnEnter = [
|
|
1580
|
+
"email",
|
|
1581
|
+
"month",
|
|
1582
|
+
"password",
|
|
1583
|
+
"search",
|
|
1584
|
+
"tel",
|
|
1585
|
+
"text",
|
|
1586
|
+
"url",
|
|
1587
|
+
"week"
|
|
1588
|
+
];
|
|
1589
|
+
|
|
1590
|
+
// src/event/behavior/keyup.ts
|
|
1591
|
+
behavior.keyup = (event, target, config) => {
|
|
1592
|
+
var _a;
|
|
1593
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1594
|
+
};
|
|
1595
|
+
var keyupBehavior = {
|
|
1596
|
+
" ": (event, target, config) => {
|
|
1597
|
+
if (isClickableInput(target)) {
|
|
1598
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/event/behavior/paste.ts
|
|
1604
|
+
behavior.paste = (event, target, config) => {
|
|
1605
|
+
if (isEditable(target)) {
|
|
1606
|
+
return () => {
|
|
1607
|
+
var _a;
|
|
1608
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1609
|
+
if (insertData) {
|
|
1610
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
// src/event/wrapEvent.ts
|
|
1617
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1618
|
+
function wrapEvent(cb, _element) {
|
|
1619
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1404
1622
|
// src/event/dispatchEvent.ts
|
|
1405
|
-
function dispatchEvent(config, target, event) {
|
|
1623
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1406
1624
|
var _a, _b;
|
|
1407
1625
|
const type3 = event.type;
|
|
1408
|
-
const behaviorImplementation =
|
|
1626
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1627
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1409
1628
|
if (behaviorImplementation) {
|
|
1410
1629
|
event.preventDefault();
|
|
1411
1630
|
let defaultPrevented = false;
|
|
@@ -1417,28 +1636,22 @@ function dispatchEvent(config, target, event) {
|
|
|
1417
1636
|
defaultPrevented = event.cancelable;
|
|
1418
1637
|
}
|
|
1419
1638
|
});
|
|
1420
|
-
target.dispatchEvent(event);
|
|
1639
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1421
1640
|
if (!defaultPrevented) {
|
|
1422
1641
|
behaviorImplementation();
|
|
1423
1642
|
}
|
|
1424
1643
|
return !defaultPrevented;
|
|
1425
1644
|
}
|
|
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);
|
|
1645
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1433
1646
|
}
|
|
1434
1647
|
|
|
1435
1648
|
// src/event/index.ts
|
|
1436
|
-
function dispatchUIEvent(config, target, type3, init) {
|
|
1649
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1437
1650
|
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1438
1651
|
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1439
1652
|
}
|
|
1440
1653
|
const event = createEvent(type3, target, init);
|
|
1441
|
-
return
|
|
1654
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1442
1655
|
}
|
|
1443
1656
|
function bindDispatchUIEvent(config) {
|
|
1444
1657
|
return dispatchUIEvent.bind(void 0, config);
|
|
@@ -1619,259 +1832,7 @@ function prepareElement(el) {
|
|
|
1619
1832
|
el[isPrepared] = isPrepared;
|
|
1620
1833
|
}
|
|
1621
1834
|
|
|
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
|
|
1835
|
+
// src/keyboard/modifiers.ts
|
|
1875
1836
|
var modifierKeys = [
|
|
1876
1837
|
"Alt",
|
|
1877
1838
|
"AltGraph",
|
|
@@ -1881,6 +1842,9 @@ var modifierKeys = [
|
|
|
1881
1842
|
"Shift",
|
|
1882
1843
|
"Symbol"
|
|
1883
1844
|
];
|
|
1845
|
+
function isModifierKey(key) {
|
|
1846
|
+
return modifierKeys.includes(key);
|
|
1847
|
+
}
|
|
1884
1848
|
var modifierLocks = [
|
|
1885
1849
|
"CapsLock",
|
|
1886
1850
|
"FnLock",
|
|
@@ -1888,78 +1852,40 @@ var modifierLocks = [
|
|
|
1888
1852
|
"ScrollLock",
|
|
1889
1853
|
"SymbolLock"
|
|
1890
1854
|
];
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1855
|
+
function isModifierLock(key) {
|
|
1856
|
+
return modifierLocks.includes(key);
|
|
1857
|
+
}
|
|
1858
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1859
|
+
var _a;
|
|
1860
|
+
if (isModifierKey(key)) {
|
|
1861
|
+
config.keyboardState.modifiers[key] = true;
|
|
1862
|
+
if (key === "AltGraph") {
|
|
1863
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1864
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1901
1865
|
}
|
|
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
|
-
}
|
|
1866
|
+
} else if (isModifierLock(key)) {
|
|
1867
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1868
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1869
|
+
config.keyboardState.modifiers[key] = true;
|
|
1911
1870
|
}
|
|
1912
1871
|
}
|
|
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
|
-
}
|
|
1872
|
+
}
|
|
1873
|
+
function preKeyupBehavior(config, { key }) {
|
|
1874
|
+
if (isModifierKey(key)) {
|
|
1875
|
+
config.keyboardState.modifiers[key] = false;
|
|
1876
|
+
} else if (isModifierLock(key)) {
|
|
1877
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1878
|
+
config.keyboardState.modifiers[key] = false;
|
|
1928
1879
|
}
|
|
1929
1880
|
}
|
|
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
|
-
}
|
|
1881
|
+
}
|
|
1882
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1883
|
+
var _a;
|
|
1884
|
+
if (key === "AltGraph") {
|
|
1885
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1886
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1939
1887
|
}
|
|
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
|
-
];
|
|
1888
|
+
}
|
|
1963
1889
|
|
|
1964
1890
|
// src/keyboard/keyboardAction.ts
|
|
1965
1891
|
async function keyboardAction(config, actions) {
|
|
@@ -2010,39 +1936,23 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
2010
1936
|
config.keyboardState.carryChar = "";
|
|
2011
1937
|
}
|
|
2012
1938
|
config.keyboardState.activeElement = element;
|
|
2013
|
-
|
|
1939
|
+
preKeydownBehavior(config, keyDef, element);
|
|
2014
1940
|
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
2015
1941
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
2016
|
-
if (unpreventedDefault) {
|
|
2017
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
2018
|
-
}
|
|
2019
1942
|
return unpreventedDefault;
|
|
2020
1943
|
}
|
|
2021
1944
|
async function keypress(keyDef, getCurrentElement, config) {
|
|
2022
1945
|
const element = getCurrentElement();
|
|
2023
|
-
|
|
1946
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2024
1947
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2025
1948
|
}));
|
|
2026
|
-
if (unpreventedDefault) {
|
|
2027
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2028
|
-
}
|
|
2029
1949
|
}
|
|
2030
1950
|
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2031
1951
|
const element = getCurrentElement();
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
if (unprevented && unpreventedDefault) {
|
|
2035
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2036
|
-
}
|
|
1952
|
+
preKeyupBehavior(config, keyDef);
|
|
1953
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2037
1954
|
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;
|
|
1955
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2046
1956
|
}
|
|
2047
1957
|
function hasKeyPress(keyDef, config) {
|
|
2048
1958
|
var _a;
|
|
@@ -2535,10 +2445,10 @@ function getPrevTarget(pointerName, state) {
|
|
|
2535
2445
|
}
|
|
2536
2446
|
|
|
2537
2447
|
// src/pointer/index.ts
|
|
2538
|
-
async function pointer(
|
|
2448
|
+
async function pointer(input2) {
|
|
2539
2449
|
const { pointerMap } = this[Config];
|
|
2540
2450
|
const actions = [];
|
|
2541
|
-
(Array.isArray(
|
|
2451
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2542
2452
|
if (typeof actionInput === "string") {
|
|
2543
2453
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2544
2454
|
} else if ("keys" in actionInput) {
|
|
@@ -2637,10 +2547,9 @@ async function copy() {
|
|
|
2637
2547
|
if (clipboardData.items.length === 0) {
|
|
2638
2548
|
return;
|
|
2639
2549
|
}
|
|
2640
|
-
this.dispatchUIEvent(target, "copy", {
|
|
2550
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2641
2551
|
clipboardData
|
|
2642
|
-
})
|
|
2643
|
-
if (this[Config].writeToClipboard) {
|
|
2552
|
+
}) && this[Config].writeToClipboard) {
|
|
2644
2553
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2645
2554
|
}
|
|
2646
2555
|
return clipboardData;
|
|
@@ -2648,28 +2557,24 @@ async function copy() {
|
|
|
2648
2557
|
|
|
2649
2558
|
// src/clipboard/cut.ts
|
|
2650
2559
|
async function cut() {
|
|
2651
|
-
var _a
|
|
2560
|
+
var _a;
|
|
2652
2561
|
const doc = this[Config].document;
|
|
2653
2562
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2654
2563
|
const clipboardData = copySelection(target);
|
|
2655
2564
|
if (clipboardData.items.length === 0) {
|
|
2656
2565
|
return;
|
|
2657
2566
|
}
|
|
2658
|
-
this.dispatchUIEvent(target, "cut", {
|
|
2567
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2659
2568
|
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);
|
|
2569
|
+
}) && this[Config].writeToClipboard) {
|
|
2570
|
+
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2666
2571
|
}
|
|
2667
2572
|
return clipboardData;
|
|
2668
2573
|
}
|
|
2669
2574
|
|
|
2670
2575
|
// src/clipboard/paste.ts
|
|
2671
2576
|
async function paste(clipboardData) {
|
|
2672
|
-
var _a, _b
|
|
2577
|
+
var _a, _b;
|
|
2673
2578
|
const doc = this[Config].document;
|
|
2674
2579
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2675
2580
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
@@ -2678,12 +2583,6 @@ async function paste(clipboardData) {
|
|
|
2678
2583
|
this.dispatchUIEvent(target, "paste", {
|
|
2679
2584
|
clipboardData: dataTransfer
|
|
2680
2585
|
});
|
|
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
2586
|
}
|
|
2688
2587
|
function getClipboardDataFromString(text) {
|
|
2689
2588
|
const dt = createDataTransfer();
|
|
@@ -2693,7 +2592,6 @@ function getClipboardDataFromString(text) {
|
|
|
2693
2592
|
|
|
2694
2593
|
// src/utility/clear.ts
|
|
2695
2594
|
async function clear(element) {
|
|
2696
|
-
var _a;
|
|
2697
2595
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2698
2596
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2699
2597
|
}
|
|
@@ -2705,7 +2603,7 @@ async function clear(element) {
|
|
|
2705
2603
|
if (!isAllSelected(element)) {
|
|
2706
2604
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2707
2605
|
}
|
|
2708
|
-
(
|
|
2606
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2709
2607
|
}
|
|
2710
2608
|
|
|
2711
2609
|
// src/utility/selectOptions.ts
|
|
@@ -2822,28 +2720,28 @@ async function type(element, text, {
|
|
|
2822
2720
|
|
|
2823
2721
|
// src/utility/upload.ts
|
|
2824
2722
|
async function upload(element, fileOrFiles) {
|
|
2825
|
-
const
|
|
2826
|
-
if (!
|
|
2827
|
-
throw new TypeError(`The ${
|
|
2723
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2724
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2725
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2828
2726
|
}
|
|
2829
2727
|
if (isDisabled(element))
|
|
2830
2728
|
return;
|
|
2831
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file,
|
|
2729
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2832
2730
|
const fileDialog = () => {
|
|
2833
2731
|
var _a;
|
|
2834
|
-
if (files.length === ((_a =
|
|
2732
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2835
2733
|
var _a2;
|
|
2836
|
-
return f === ((_a2 =
|
|
2734
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2837
2735
|
})) {
|
|
2838
2736
|
return;
|
|
2839
2737
|
}
|
|
2840
|
-
setFiles(
|
|
2841
|
-
this.dispatchUIEvent(
|
|
2842
|
-
this.dispatchUIEvent(
|
|
2738
|
+
setFiles(input2, createFileList(files));
|
|
2739
|
+
this.dispatchUIEvent(input2, "input");
|
|
2740
|
+
this.dispatchUIEvent(input2, "change");
|
|
2843
2741
|
};
|
|
2844
|
-
|
|
2742
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2845
2743
|
await this.click(element);
|
|
2846
|
-
|
|
2744
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2847
2745
|
}
|
|
2848
2746
|
function isAcceptableFile(file, accept) {
|
|
2849
2747
|
if (!accept) {
|
|
@@ -2968,9 +2866,9 @@ async function keyboard2(text, options = {}) {
|
|
|
2968
2866
|
const { config, api } = setupDirect(options);
|
|
2969
2867
|
return api.keyboard(text).then(() => config.keyboardState);
|
|
2970
2868
|
}
|
|
2971
|
-
async function pointer2(
|
|
2869
|
+
async function pointer2(input2, options = {}) {
|
|
2972
2870
|
const { config, api } = setupDirect(options);
|
|
2973
|
-
return api.pointer(
|
|
2871
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2974
2872
|
}
|
|
2975
2873
|
function paste2(clipboardData, options) {
|
|
2976
2874
|
return setupDirect(options).api.paste(clipboardData);
|