@testing-library/user-event 14.0.0-beta.10 → 14.0.0-beta.11
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 +561 -700
- package/dist/index.mjs +562 -701
- package/dist/types/event/behavior/index.d.ts +3 -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/dispatchEvent.d.ts +1 -1
- package/dist/types/event/eventMap.d.ts +342 -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.mjs
CHANGED
|
@@ -352,6 +352,29 @@ if (typeof afterAll === "function") {
|
|
|
352
352
|
afterAll(() => detachClipboardStubFromView(window));
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
// src/utils/edit/isContentEditable.ts
|
|
356
|
+
function isContentEditable(element) {
|
|
357
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
358
|
+
}
|
|
359
|
+
function getContentEditable(node) {
|
|
360
|
+
const element = getElement(node);
|
|
361
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
362
|
+
}
|
|
363
|
+
function getElement(node) {
|
|
364
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/utils/edit/getValue.ts
|
|
368
|
+
function getValue(element) {
|
|
369
|
+
if (!element) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
if (isContentEditable(element)) {
|
|
373
|
+
return element.textContent;
|
|
374
|
+
}
|
|
375
|
+
return getUIValue(element);
|
|
376
|
+
}
|
|
377
|
+
|
|
355
378
|
// src/utils/edit/buildTimeValue.ts
|
|
356
379
|
function buildTimeValue(value) {
|
|
357
380
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -383,21 +406,137 @@ function build(onlyDigitsValue, index) {
|
|
|
383
406
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
384
407
|
}
|
|
385
408
|
|
|
386
|
-
// src/utils/edit/
|
|
387
|
-
function
|
|
409
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
410
|
+
function isValidDateOrTimeValue(element, value) {
|
|
388
411
|
const clone = element.cloneNode();
|
|
389
412
|
clone.value = value;
|
|
390
413
|
return clone.value === value;
|
|
391
414
|
}
|
|
392
415
|
|
|
393
|
-
// src/utils/edit/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
416
|
+
// src/utils/edit/maxLength.ts
|
|
417
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
418
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
419
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
420
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
421
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
422
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
423
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
424
|
+
return maxLengthSupportedTypes2;
|
|
425
|
+
})(maxLengthSupportedTypes || {});
|
|
426
|
+
function getSpaceUntilMaxLength(element) {
|
|
427
|
+
const value = getValue(element);
|
|
428
|
+
if (value === null) {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
432
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
433
|
+
}
|
|
434
|
+
function getSanitizedMaxLength(element) {
|
|
435
|
+
var _a;
|
|
436
|
+
if (!supportsMaxLength(element)) {
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
440
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
441
|
+
}
|
|
442
|
+
function supportsMaxLength(element) {
|
|
443
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
398
444
|
}
|
|
399
445
|
|
|
400
|
-
// src/utils/edit/
|
|
446
|
+
// src/utils/edit/input.ts
|
|
447
|
+
function isDateOrTime(element) {
|
|
448
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
449
|
+
}
|
|
450
|
+
function input(config, element, data, inputType = "insertText") {
|
|
451
|
+
const inputRange = getInputRange(element);
|
|
452
|
+
if (!inputRange) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (!isDateOrTime(element)) {
|
|
456
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
457
|
+
inputType,
|
|
458
|
+
data
|
|
459
|
+
});
|
|
460
|
+
if (!unprevented) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if ("startContainer" in inputRange) {
|
|
465
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
466
|
+
} else {
|
|
467
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
471
|
+
let del = false;
|
|
472
|
+
if (!inputRange.collapsed) {
|
|
473
|
+
del = true;
|
|
474
|
+
inputRange.deleteContents();
|
|
475
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
476
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
477
|
+
if (nextPosition) {
|
|
478
|
+
del = true;
|
|
479
|
+
const delRange = inputRange.cloneRange();
|
|
480
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
481
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
482
|
+
} else {
|
|
483
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
484
|
+
}
|
|
485
|
+
delRange.deleteContents();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (data) {
|
|
489
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
490
|
+
const offset = inputRange.endOffset;
|
|
491
|
+
inputRange.endContainer.insertData(offset, data);
|
|
492
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
493
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
494
|
+
} else {
|
|
495
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
496
|
+
inputRange.insertNode(text);
|
|
497
|
+
inputRange.setStart(text, data.length);
|
|
498
|
+
inputRange.setEnd(text, data.length);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (del || data) {
|
|
502
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
506
|
+
let dataToInsert = data;
|
|
507
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
508
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
509
|
+
if (spaceUntilMaxLength > 0) {
|
|
510
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
511
|
+
} else {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
516
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
setUIValue(element, newValue);
|
|
523
|
+
setSelection({
|
|
524
|
+
focusNode: element,
|
|
525
|
+
anchorOffset: newOffset,
|
|
526
|
+
focusOffset: newOffset
|
|
527
|
+
});
|
|
528
|
+
if (isDateOrTime(element)) {
|
|
529
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
530
|
+
commitInput(config, element, oldValue, newValue, newOffset, {});
|
|
531
|
+
dispatchUIEvent(config, element, "change");
|
|
532
|
+
}
|
|
533
|
+
} else {
|
|
534
|
+
commitInput(config, element, oldValue, newValue, newOffset, {
|
|
535
|
+
data,
|
|
536
|
+
inputType
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
401
540
|
function calculateNewValue(inputData, node, {
|
|
402
541
|
startOffset,
|
|
403
542
|
endOffset
|
|
@@ -408,15 +547,12 @@ function calculateNewValue(inputData, node, {
|
|
|
408
547
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
409
548
|
const epilog = value.substring(epilogStart, value.length);
|
|
410
549
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
411
|
-
|
|
412
|
-
if (node
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
newValue = inputData;
|
|
418
|
-
} else {
|
|
419
|
-
newValue = value;
|
|
550
|
+
let newOffset = prologEnd + inputData.length;
|
|
551
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
552
|
+
const builtValue = buildTimeValue(newValue);
|
|
553
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
554
|
+
newValue = builtValue;
|
|
555
|
+
newOffset = builtValue.length;
|
|
420
556
|
}
|
|
421
557
|
}
|
|
422
558
|
return {
|
|
@@ -425,17 +561,22 @@ function calculateNewValue(inputData, node, {
|
|
|
425
561
|
newOffset
|
|
426
562
|
};
|
|
427
563
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
564
|
+
function commitInput(config, element, oldValue, newValue, newOffset, inputInit) {
|
|
565
|
+
startTrackValue(element);
|
|
566
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
567
|
+
const tracked = endTrackValue(element);
|
|
568
|
+
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
569
|
+
setSelection({
|
|
570
|
+
focusNode: element,
|
|
571
|
+
anchorOffset: newOffset,
|
|
572
|
+
focusOffset: newOffset
|
|
573
|
+
});
|
|
574
|
+
}
|
|
436
575
|
}
|
|
437
|
-
function
|
|
438
|
-
|
|
576
|
+
function isValidNumberInput(value) {
|
|
577
|
+
var _a, _b;
|
|
578
|
+
const valueParts = value.split("e", 2);
|
|
579
|
+
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]));
|
|
439
580
|
}
|
|
440
581
|
|
|
441
582
|
// src/utils/edit/isEditable.ts
|
|
@@ -461,157 +602,100 @@ function isEditableInput(element) {
|
|
|
461
602
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
462
603
|
}
|
|
463
604
|
|
|
464
|
-
// src/utils/
|
|
465
|
-
|
|
605
|
+
// src/utils/edit/setFiles.ts
|
|
606
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
607
|
+
function setFiles(el, files) {
|
|
466
608
|
var _a;
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return setSelection({
|
|
476
|
-
focusNode: element.firstChild,
|
|
477
|
-
anchorOffset,
|
|
478
|
-
focusOffset
|
|
609
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
610
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
611
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
612
|
+
function restore() {
|
|
613
|
+
Object.defineProperties(el, {
|
|
614
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
615
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
616
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
479
617
|
});
|
|
480
618
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
498
|
-
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
499
|
-
return {
|
|
500
|
-
type: isCE ? "contenteditable" : "default",
|
|
501
|
-
selection
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
function getElement2(node) {
|
|
505
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
506
|
-
}
|
|
507
|
-
function updateSelectionOnFocus(element) {
|
|
508
|
-
var _a;
|
|
509
|
-
const selection = element.ownerDocument.getSelection();
|
|
510
|
-
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (hasOwnSelection(element)) {
|
|
514
|
-
const contenteditable = getContentEditable(selection.focusNode);
|
|
515
|
-
if (contenteditable) {
|
|
516
|
-
if (!selection.isCollapsed) {
|
|
517
|
-
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
518
|
-
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
619
|
+
el[fakeFiles] = { restore };
|
|
620
|
+
Object.defineProperties(el, {
|
|
621
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
622
|
+
get: () => files
|
|
623
|
+
}),
|
|
624
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
625
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
626
|
+
set(v) {
|
|
627
|
+
var _a2;
|
|
628
|
+
if (v === "") {
|
|
629
|
+
restore();
|
|
630
|
+
} else {
|
|
631
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
632
|
+
}
|
|
519
633
|
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
} else if (typeAndSelection.type === "contenteditable") {
|
|
531
|
-
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
function setSelection({
|
|
535
|
-
focusNode,
|
|
536
|
-
focusOffset,
|
|
537
|
-
anchorNode = focusNode,
|
|
538
|
-
anchorOffset = focusOffset
|
|
539
|
-
}) {
|
|
540
|
-
var _a, _b;
|
|
541
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
542
|
-
if (typeAndSelection.type === "input") {
|
|
543
|
-
return setUISelection(focusNode, {
|
|
544
|
-
anchorOffset,
|
|
545
|
-
focusOffset
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
634
|
+
}),
|
|
635
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
636
|
+
set(v) {
|
|
637
|
+
if (v !== "file") {
|
|
638
|
+
restore();
|
|
639
|
+
el.type = v;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
})
|
|
643
|
+
});
|
|
549
644
|
}
|
|
550
645
|
|
|
551
|
-
// src/utils/
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const oldValue = element.value;
|
|
558
|
-
setUIValue(element, newValue);
|
|
559
|
-
setSelection({
|
|
560
|
-
focusNode: newSelection.node,
|
|
561
|
-
anchorOffset: newSelection.offset,
|
|
562
|
-
focusOffset: newSelection.offset
|
|
646
|
+
// src/utils/misc/eventWrapper.ts
|
|
647
|
+
import { getConfig } from "@testing-library/dom";
|
|
648
|
+
function eventWrapper(cb) {
|
|
649
|
+
let result;
|
|
650
|
+
getConfig().eventWrapper(() => {
|
|
651
|
+
result = cb();
|
|
563
652
|
});
|
|
564
|
-
|
|
565
|
-
dispatchUIEvent(config, element, "input", eventOverrides);
|
|
566
|
-
const tracked = endTrackValue(element);
|
|
567
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
568
|
-
setSelection({
|
|
569
|
-
focusNode: newSelection.node,
|
|
570
|
-
anchorOffset: newSelection.offset,
|
|
571
|
-
focusOffset: newSelection.offset
|
|
572
|
-
});
|
|
573
|
-
}
|
|
653
|
+
return result;
|
|
574
654
|
}
|
|
575
655
|
|
|
576
|
-
// src/utils/
|
|
577
|
-
function
|
|
578
|
-
|
|
579
|
-
return null;
|
|
580
|
-
}
|
|
581
|
-
if (isContentEditable(element)) {
|
|
582
|
-
return element.textContent;
|
|
583
|
-
}
|
|
584
|
-
return getUIValue(element);
|
|
656
|
+
// src/utils/misc/isDisabled.ts
|
|
657
|
+
function isDisabled(element) {
|
|
658
|
+
return Boolean(element && element.disabled);
|
|
585
659
|
}
|
|
586
660
|
|
|
587
|
-
// src/utils/
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
function getSpaceUntilMaxLength(element) {
|
|
598
|
-
const value = getValue(element);
|
|
599
|
-
if (value === null) {
|
|
600
|
-
return void 0;
|
|
661
|
+
// src/utils/focus/getActiveElement.ts
|
|
662
|
+
function getActiveElement(document2) {
|
|
663
|
+
const activeElement = document2.activeElement;
|
|
664
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
665
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
666
|
+
} else {
|
|
667
|
+
if (isDisabled(activeElement)) {
|
|
668
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
669
|
+
}
|
|
670
|
+
return activeElement;
|
|
601
671
|
}
|
|
602
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
603
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
604
672
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
673
|
+
|
|
674
|
+
// src/utils/focus/selector.ts
|
|
675
|
+
var FOCUSABLE_SELECTOR = [
|
|
676
|
+
"input:not([type=hidden]):not([disabled])",
|
|
677
|
+
"button:not([disabled])",
|
|
678
|
+
"select:not([disabled])",
|
|
679
|
+
"textarea:not([disabled])",
|
|
680
|
+
'[contenteditable=""]',
|
|
681
|
+
'[contenteditable="true"]',
|
|
682
|
+
"a[href]",
|
|
683
|
+
"[tabindex]:not([disabled])"
|
|
684
|
+
].join(", ");
|
|
685
|
+
|
|
686
|
+
// src/utils/focus/isFocusable.ts
|
|
687
|
+
function isFocusable(element) {
|
|
688
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
612
689
|
}
|
|
613
|
-
|
|
614
|
-
|
|
690
|
+
|
|
691
|
+
// src/utils/focus/blur.ts
|
|
692
|
+
function blur(element) {
|
|
693
|
+
if (!isFocusable(element))
|
|
694
|
+
return;
|
|
695
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
696
|
+
if (!wasActive)
|
|
697
|
+
return;
|
|
698
|
+
eventWrapper(() => element.blur());
|
|
615
699
|
}
|
|
616
700
|
|
|
617
701
|
// src/utils/focus/cursor.ts
|
|
@@ -662,7 +746,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
662
746
|
}
|
|
663
747
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
664
748
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
665
|
-
if (offset !== void 0 &&
|
|
749
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
666
750
|
node = node.children[nextOffset];
|
|
667
751
|
}
|
|
668
752
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -671,7 +755,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
671
755
|
if (isTextNode(node)) {
|
|
672
756
|
return true;
|
|
673
757
|
}
|
|
674
|
-
if (
|
|
758
|
+
if (isElement(node)) {
|
|
675
759
|
if (isElementType(node, ["input", "textarea"])) {
|
|
676
760
|
return node.type !== "hidden";
|
|
677
761
|
} else if (isElementType(node, "br")) {
|
|
@@ -688,7 +772,7 @@ function getOffset(node) {
|
|
|
688
772
|
}
|
|
689
773
|
return i;
|
|
690
774
|
}
|
|
691
|
-
function
|
|
775
|
+
function isElement(node) {
|
|
692
776
|
return node.nodeType === 1;
|
|
693
777
|
}
|
|
694
778
|
function isTextNode(node) {
|
|
@@ -703,7 +787,7 @@ function walkNodes(node, direction, callback) {
|
|
|
703
787
|
if (callback(node)) {
|
|
704
788
|
return node;
|
|
705
789
|
}
|
|
706
|
-
} else if (node.parentNode && (!
|
|
790
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
707
791
|
node = node.parentNode;
|
|
708
792
|
} else {
|
|
709
793
|
break;
|
|
@@ -717,169 +801,118 @@ function getDescendant(node, direction) {
|
|
|
717
801
|
return node;
|
|
718
802
|
}
|
|
719
803
|
|
|
720
|
-
// src/utils/
|
|
721
|
-
function
|
|
722
|
-
|
|
723
|
-
if (
|
|
724
|
-
return
|
|
804
|
+
// src/utils/focus/selection.ts
|
|
805
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
806
|
+
var _a;
|
|
807
|
+
if (hasOwnSelection(element)) {
|
|
808
|
+
return setSelection({
|
|
809
|
+
focusNode: element,
|
|
810
|
+
anchorOffset,
|
|
811
|
+
focusOffset
|
|
812
|
+
});
|
|
725
813
|
}
|
|
726
|
-
if (
|
|
727
|
-
return {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
if (data) {
|
|
747
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
748
|
-
const offset = inputRange.endOffset;
|
|
749
|
-
inputRange.endContainer.insertData(offset, data);
|
|
750
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
751
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
752
|
-
} else {
|
|
753
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
754
|
-
inputRange.insertNode(text);
|
|
755
|
-
inputRange.setStart(text, data.length);
|
|
756
|
-
inputRange.setEnd(text, data.length);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
if (del || data) {
|
|
760
|
-
dispatchUIEvent(config, element, "input", { inputType });
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
} else {
|
|
814
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
815
|
+
return setSelection({
|
|
816
|
+
focusNode: element.firstChild,
|
|
817
|
+
anchorOffset,
|
|
818
|
+
focusOffset
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
822
|
+
}
|
|
823
|
+
function hasOwnSelection(node) {
|
|
824
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
825
|
+
}
|
|
826
|
+
function isElement2(node) {
|
|
827
|
+
return node.nodeType === 1;
|
|
828
|
+
}
|
|
829
|
+
function getTargetTypeAndSelection(node) {
|
|
830
|
+
const element = getElement2(node);
|
|
831
|
+
if (element && hasOwnSelection(element)) {
|
|
765
832
|
return {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
|
|
769
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
editInputElement(config, element, {
|
|
773
|
-
newValue,
|
|
774
|
-
newSelection: {
|
|
775
|
-
node: element,
|
|
776
|
-
offset: newOffset
|
|
777
|
-
},
|
|
778
|
-
eventOverrides: {
|
|
779
|
-
inputType
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
}
|
|
833
|
+
type: "input",
|
|
834
|
+
selection: getUISelection(element)
|
|
783
835
|
};
|
|
784
836
|
}
|
|
837
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
838
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
839
|
+
return {
|
|
840
|
+
type: isCE ? "contenteditable" : "default",
|
|
841
|
+
selection
|
|
842
|
+
};
|
|
785
843
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
function
|
|
844
|
+
function getElement2(node) {
|
|
845
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
846
|
+
}
|
|
847
|
+
function updateSelectionOnFocus(element) {
|
|
790
848
|
var _a;
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
function restore() {
|
|
795
|
-
Object.defineProperties(el, {
|
|
796
|
-
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
797
|
-
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
798
|
-
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
799
|
-
});
|
|
849
|
+
const selection = element.ownerDocument.getSelection();
|
|
850
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
851
|
+
return;
|
|
800
852
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
808
|
-
set(v) {
|
|
809
|
-
var _a2;
|
|
810
|
-
if (v === "") {
|
|
811
|
-
restore();
|
|
812
|
-
} else {
|
|
813
|
-
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}),
|
|
817
|
-
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
818
|
-
set(v) {
|
|
819
|
-
if (v !== "file") {
|
|
820
|
-
restore();
|
|
821
|
-
el.type = v;
|
|
822
|
-
}
|
|
853
|
+
if (hasOwnSelection(element)) {
|
|
854
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
855
|
+
if (contenteditable) {
|
|
856
|
+
if (!selection.isCollapsed) {
|
|
857
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
858
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
823
859
|
}
|
|
824
|
-
}
|
|
825
|
-
|
|
860
|
+
} else {
|
|
861
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
826
864
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
return result;
|
|
865
|
+
function getInputRange(focusNode) {
|
|
866
|
+
var _a;
|
|
867
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
868
|
+
if (typeAndSelection.type === "input") {
|
|
869
|
+
return typeAndSelection.selection;
|
|
870
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
871
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
872
|
+
}
|
|
836
873
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
874
|
+
function setSelection({
|
|
875
|
+
focusNode,
|
|
876
|
+
focusOffset,
|
|
877
|
+
anchorNode = focusNode,
|
|
878
|
+
anchorOffset = focusOffset
|
|
879
|
+
}) {
|
|
880
|
+
var _a, _b;
|
|
881
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
882
|
+
if (typeAndSelection.type === "input") {
|
|
883
|
+
return setUISelection(focusNode, {
|
|
884
|
+
anchorOffset,
|
|
885
|
+
focusOffset
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
841
889
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
890
|
+
function moveSelection(node, direction) {
|
|
891
|
+
if (hasOwnSelection(node)) {
|
|
892
|
+
const selection = getUISelection(node);
|
|
893
|
+
setSelection({
|
|
894
|
+
focusNode: node,
|
|
895
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
896
|
+
});
|
|
897
|
+
} else {
|
|
898
|
+
const selection = node.ownerDocument.getSelection();
|
|
899
|
+
if (!selection) {
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (selection.isCollapsed) {
|
|
903
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
904
|
+
if (nextPosition) {
|
|
905
|
+
setSelection({
|
|
906
|
+
focusNode: nextPosition.node,
|
|
907
|
+
focusOffset: nextPosition.offset
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
} else {
|
|
911
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
851
912
|
}
|
|
852
|
-
return activeElement;
|
|
853
913
|
}
|
|
854
914
|
}
|
|
855
915
|
|
|
856
|
-
// src/utils/focus/selector.ts
|
|
857
|
-
var FOCUSABLE_SELECTOR = [
|
|
858
|
-
"input:not([type=hidden]):not([disabled])",
|
|
859
|
-
"button:not([disabled])",
|
|
860
|
-
"select:not([disabled])",
|
|
861
|
-
"textarea:not([disabled])",
|
|
862
|
-
'[contenteditable=""]',
|
|
863
|
-
'[contenteditable="true"]',
|
|
864
|
-
"a[href]",
|
|
865
|
-
"[tabindex]:not([disabled])"
|
|
866
|
-
].join(", ");
|
|
867
|
-
|
|
868
|
-
// src/utils/focus/isFocusable.ts
|
|
869
|
-
function isFocusable(element) {
|
|
870
|
-
return element.matches(FOCUSABLE_SELECTOR);
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
// src/utils/focus/blur.ts
|
|
874
|
-
function blur(element) {
|
|
875
|
-
if (!isFocusable(element))
|
|
876
|
-
return;
|
|
877
|
-
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
878
|
-
if (!wasActive)
|
|
879
|
-
return;
|
|
880
|
-
eventWrapper(() => element.blur());
|
|
881
|
-
}
|
|
882
|
-
|
|
883
916
|
// src/utils/focus/copySelection.ts
|
|
884
917
|
function copySelection(target) {
|
|
885
918
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
@@ -1163,9 +1196,6 @@ function wait(time) {
|
|
|
1163
1196
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1164
1197
|
}
|
|
1165
1198
|
|
|
1166
|
-
// src/utils/misc/hasFormSubmit.ts
|
|
1167
|
-
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1168
|
-
|
|
1169
1199
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1170
1200
|
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1171
1201
|
|
|
@@ -1325,13 +1355,21 @@ function getMouseButtons(...buttons) {
|
|
|
1325
1355
|
|
|
1326
1356
|
// src/event/createEvent.ts
|
|
1327
1357
|
import { createEvent as createEventBase } from "@testing-library/dom";
|
|
1328
|
-
|
|
1358
|
+
|
|
1359
|
+
// src/event/eventMap.ts
|
|
1360
|
+
import { eventMap as baseEventMap } from "@testing-library/dom/dist/event-map.js";
|
|
1361
|
+
var eventMap = __spreadProps(__spreadValues({}, baseEventMap), {
|
|
1362
|
+
beforeInput: {
|
|
1363
|
+
EventType: "InputEvent",
|
|
1364
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1329
1367
|
|
|
1330
1368
|
// src/event/eventTypes.ts
|
|
1331
|
-
import { eventMap } from "@testing-library/dom/dist/event-map.js";
|
|
1332
|
-
var eventKeys = Object.fromEntries(Object.keys(
|
|
1369
|
+
import { eventMap as eventMap2 } from "@testing-library/dom/dist/event-map.js";
|
|
1370
|
+
var eventKeys = Object.fromEntries(Object.keys(eventMap2).map((k) => [k.toLowerCase(), k]));
|
|
1333
1371
|
function getEventClass(type3) {
|
|
1334
|
-
return
|
|
1372
|
+
return type3 in eventKeys ? eventMap2[eventKeys[type3]].EventType : "Event";
|
|
1335
1373
|
}
|
|
1336
1374
|
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1337
1375
|
function isMouseEvent(type3) {
|
|
@@ -1343,8 +1381,8 @@ function isKeyboardEvent(type3) {
|
|
|
1343
1381
|
|
|
1344
1382
|
// src/event/createEvent.ts
|
|
1345
1383
|
function createEvent(type3, target, init) {
|
|
1346
|
-
const eventKey = Object.keys(
|
|
1347
|
-
const event = createEventBase
|
|
1384
|
+
const eventKey = Object.keys(eventMap).find((k) => k.toLowerCase() === type3);
|
|
1385
|
+
const event = createEventBase(type3, target, init, eventMap[eventKey]);
|
|
1348
1386
|
if (isMouseEvent(type3) && init) {
|
|
1349
1387
|
assignPositionInit(event, init);
|
|
1350
1388
|
assignPointerInit(event, init);
|
|
@@ -1413,11 +1451,147 @@ behavior.click = (event, target, config) => {
|
|
|
1413
1451
|
}
|
|
1414
1452
|
};
|
|
1415
1453
|
|
|
1454
|
+
// src/event/behavior/keydown.ts
|
|
1455
|
+
behavior.keydown = (event, target, config) => {
|
|
1456
|
+
var _a, _b;
|
|
1457
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1458
|
+
};
|
|
1459
|
+
var keydownBehavior = {
|
|
1460
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1461
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1462
|
+
Backspace: (event, target, config) => {
|
|
1463
|
+
if (isEditable(target)) {
|
|
1464
|
+
return () => {
|
|
1465
|
+
input(config, target, "", "deleteContentBackward");
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
},
|
|
1469
|
+
Delete: (event, target, config) => {
|
|
1470
|
+
if (isEditable(target)) {
|
|
1471
|
+
return () => {
|
|
1472
|
+
input(config, target, "", "deleteContentForward");
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
},
|
|
1476
|
+
End: (event, target) => {
|
|
1477
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1478
|
+
return () => {
|
|
1479
|
+
var _a, _b;
|
|
1480
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1481
|
+
setSelectionRange(target, newPos, newPos);
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
},
|
|
1485
|
+
Home: (event, target) => {
|
|
1486
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1487
|
+
return () => {
|
|
1488
|
+
setSelectionRange(target, 0, 0);
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
},
|
|
1492
|
+
PageDown: (event, target) => {
|
|
1493
|
+
if (isElementType(target, ["input"])) {
|
|
1494
|
+
return () => {
|
|
1495
|
+
const newPos = getValue(target).length;
|
|
1496
|
+
setSelectionRange(target, newPos, newPos);
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
PageUp: (event, target) => {
|
|
1501
|
+
if (isElementType(target, ["input"])) {
|
|
1502
|
+
return () => {
|
|
1503
|
+
setSelectionRange(target, 0, 0);
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1508
|
+
return () => {
|
|
1509
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1510
|
+
focus(dest);
|
|
1511
|
+
if (hasOwnSelection(dest)) {
|
|
1512
|
+
setUISelection(dest, {
|
|
1513
|
+
anchorOffset: 0,
|
|
1514
|
+
focusOffset: dest.value.length
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
var combinationBehavior = (event, target, config) => {
|
|
1521
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1522
|
+
return () => selectAll(target);
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
|
|
1526
|
+
// src/event/behavior/keypress.ts
|
|
1527
|
+
behavior.keypress = (event, target, config) => {
|
|
1528
|
+
if (event.key === "Enter") {
|
|
1529
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1530
|
+
return () => {
|
|
1531
|
+
dispatchUIEvent(config, target, "click");
|
|
1532
|
+
};
|
|
1533
|
+
} else if (isElementType(target, "input")) {
|
|
1534
|
+
const form = target.form;
|
|
1535
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1536
|
+
if (submit) {
|
|
1537
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1538
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1539
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1540
|
+
} else {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (isEditable(target)) {
|
|
1546
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1547
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1548
|
+
return () => input(config, target, inputData, inputType);
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
var ClickInputOnEnter = [
|
|
1552
|
+
"button",
|
|
1553
|
+
"color",
|
|
1554
|
+
"file",
|
|
1555
|
+
"image",
|
|
1556
|
+
"reset",
|
|
1557
|
+
"submit"
|
|
1558
|
+
];
|
|
1559
|
+
var SubmitSingleInputOnEnter = [
|
|
1560
|
+
"email",
|
|
1561
|
+
"month",
|
|
1562
|
+
"password",
|
|
1563
|
+
"search",
|
|
1564
|
+
"tel",
|
|
1565
|
+
"text",
|
|
1566
|
+
"url",
|
|
1567
|
+
"week"
|
|
1568
|
+
];
|
|
1569
|
+
|
|
1570
|
+
// src/event/behavior/keyup.ts
|
|
1571
|
+
behavior.keyup = (event, target, config) => {
|
|
1572
|
+
var _a;
|
|
1573
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1574
|
+
};
|
|
1575
|
+
var keyupBehavior = {
|
|
1576
|
+
" ": (event, target, config) => {
|
|
1577
|
+
if (isClickableInput(target)) {
|
|
1578
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1583
|
+
// src/event/wrapEvent.ts
|
|
1584
|
+
import { getConfig as getConfig2 } from "@testing-library/dom";
|
|
1585
|
+
function wrapEvent(cb, _element) {
|
|
1586
|
+
return getConfig2().eventWrapper(cb);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1416
1589
|
// src/event/dispatchEvent.ts
|
|
1417
|
-
function dispatchEvent(config, target, event) {
|
|
1590
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1418
1591
|
var _a, _b;
|
|
1419
1592
|
const type3 = event.type;
|
|
1420
|
-
const behaviorImplementation =
|
|
1593
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1594
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1421
1595
|
if (behaviorImplementation) {
|
|
1422
1596
|
event.preventDefault();
|
|
1423
1597
|
let defaultPrevented = false;
|
|
@@ -1429,28 +1603,22 @@ function dispatchEvent(config, target, event) {
|
|
|
1429
1603
|
defaultPrevented = event.cancelable;
|
|
1430
1604
|
}
|
|
1431
1605
|
});
|
|
1432
|
-
target.dispatchEvent(event);
|
|
1606
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1433
1607
|
if (!defaultPrevented) {
|
|
1434
1608
|
behaviorImplementation();
|
|
1435
1609
|
}
|
|
1436
1610
|
return !defaultPrevented;
|
|
1437
1611
|
}
|
|
1438
|
-
return target.dispatchEvent(event);
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
// src/event/wrapEvent.ts
|
|
1442
|
-
import { getConfig as getConfig2 } from "@testing-library/dom";
|
|
1443
|
-
function wrapEvent(cb, _element) {
|
|
1444
|
-
return getConfig2().eventWrapper(cb);
|
|
1612
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1445
1613
|
}
|
|
1446
1614
|
|
|
1447
1615
|
// src/event/index.ts
|
|
1448
|
-
function dispatchUIEvent(config, target, type3, init) {
|
|
1616
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1449
1617
|
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1450
1618
|
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1451
1619
|
}
|
|
1452
1620
|
const event = createEvent(type3, target, init);
|
|
1453
|
-
return
|
|
1621
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1454
1622
|
}
|
|
1455
1623
|
function bindDispatchUIEvent(config) {
|
|
1456
1624
|
return dispatchUIEvent.bind(void 0, config);
|
|
@@ -1631,259 +1799,7 @@ function prepareElement(el) {
|
|
|
1631
1799
|
el[isPrepared] = isPrepared;
|
|
1632
1800
|
}
|
|
1633
1801
|
|
|
1634
|
-
// src/keyboard/
|
|
1635
|
-
var keydownBehavior = [
|
|
1636
|
-
{
|
|
1637
|
-
matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
|
|
1638
|
-
handle: (keyDef, element) => {
|
|
1639
|
-
if (hasOwnSelection(element)) {
|
|
1640
|
-
const selection = getUISelection(element);
|
|
1641
|
-
setSelection({
|
|
1642
|
-
focusNode: element,
|
|
1643
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1644
|
-
});
|
|
1645
|
-
} else {
|
|
1646
|
-
const selection = element.ownerDocument.getSelection();
|
|
1647
|
-
if (!selection) {
|
|
1648
|
-
return;
|
|
1649
|
-
}
|
|
1650
|
-
if (selection.isCollapsed) {
|
|
1651
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1652
|
-
if (nextPosition) {
|
|
1653
|
-
setSelection({
|
|
1654
|
-
focusNode: nextPosition.node,
|
|
1655
|
-
focusOffset: nextPosition.offset
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
|
-
} else {
|
|
1659
|
-
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
];
|
|
1665
|
-
|
|
1666
|
-
// src/keyboard/plugins/control.ts
|
|
1667
|
-
var keydownBehavior2 = [
|
|
1668
|
-
{
|
|
1669
|
-
matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
|
|
1670
|
-
handle: (keyDef, element) => {
|
|
1671
|
-
var _a, _b;
|
|
1672
|
-
if (keyDef.key === "Home") {
|
|
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 === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
|
|
1682
|
-
handle: (keyDef, element) => {
|
|
1683
|
-
var _a, _b;
|
|
1684
|
-
if (keyDef.key === "PageUp") {
|
|
1685
|
-
setSelectionRange(element, 0, 0);
|
|
1686
|
-
} else {
|
|
1687
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1688
|
-
setSelectionRange(element, newPos, newPos);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
},
|
|
1692
|
-
{
|
|
1693
|
-
matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
|
|
1694
|
-
handle: (keDef, element, config) => {
|
|
1695
|
-
var _a;
|
|
1696
|
-
(_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
];
|
|
1700
|
-
|
|
1701
|
-
// src/keyboard/shared/fireChangeForInputTimeIfValid.ts
|
|
1702
|
-
function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
|
|
1703
|
-
if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
|
|
1704
|
-
setUIValue(el, timeNewEntry);
|
|
1705
|
-
dispatchUIEvent(config, el, "change");
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
// src/keyboard/plugins/character.ts
|
|
1710
|
-
var keypressBehavior = [
|
|
1711
|
-
{
|
|
1712
|
-
matches: (keyDef, element) => {
|
|
1713
|
-
var _a;
|
|
1714
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1715
|
-
},
|
|
1716
|
-
handle: (keyDef, element, config) => {
|
|
1717
|
-
var _a;
|
|
1718
|
-
let newEntry = keyDef.key;
|
|
1719
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1720
|
-
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1721
|
-
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1722
|
-
newEntry = timeNewEntry;
|
|
1723
|
-
}
|
|
1724
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1725
|
-
const prevValue = getValue(element);
|
|
1726
|
-
if (prevValue !== newValue) {
|
|
1727
|
-
editInputElement(config, element, {
|
|
1728
|
-
newValue,
|
|
1729
|
-
newSelection: {
|
|
1730
|
-
node: element,
|
|
1731
|
-
offset: newOffset
|
|
1732
|
-
},
|
|
1733
|
-
eventOverrides: {
|
|
1734
|
-
data: keyDef.key,
|
|
1735
|
-
inputType: "insertText"
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
|
|
1740
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1741
|
-
}
|
|
1742
|
-
},
|
|
1743
|
-
{
|
|
1744
|
-
matches: (keyDef, element) => {
|
|
1745
|
-
var _a;
|
|
1746
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1747
|
-
},
|
|
1748
|
-
handle: (keyDef, element, config) => {
|
|
1749
|
-
var _a;
|
|
1750
|
-
let newEntry = keyDef.key;
|
|
1751
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1752
|
-
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1753
|
-
if (isValidToBeTyped) {
|
|
1754
|
-
newEntry = textToBeTyped;
|
|
1755
|
-
}
|
|
1756
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1757
|
-
const prevValue = getValue(element);
|
|
1758
|
-
if (prevValue !== newValue) {
|
|
1759
|
-
editInputElement(config, element, {
|
|
1760
|
-
newValue,
|
|
1761
|
-
newSelection: {
|
|
1762
|
-
node: element,
|
|
1763
|
-
offset: newOffset
|
|
1764
|
-
},
|
|
1765
|
-
eventOverrides: {
|
|
1766
|
-
data: keyDef.key,
|
|
1767
|
-
inputType: "insertText"
|
|
1768
|
-
}
|
|
1769
|
-
});
|
|
1770
|
-
}
|
|
1771
|
-
if (isValidToBeTyped) {
|
|
1772
|
-
setUIValue(element, textToBeTyped);
|
|
1773
|
-
dispatchUIEvent(config, element, "change");
|
|
1774
|
-
}
|
|
1775
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1776
|
-
}
|
|
1777
|
-
},
|
|
1778
|
-
{
|
|
1779
|
-
matches: (keyDef, element) => {
|
|
1780
|
-
var _a;
|
|
1781
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1782
|
-
},
|
|
1783
|
-
handle: (keyDef, element, config) => {
|
|
1784
|
-
var _a, _b;
|
|
1785
|
-
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1786
|
-
return;
|
|
1787
|
-
}
|
|
1788
|
-
const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
|
|
1789
|
-
const newValue = getNewValue();
|
|
1790
|
-
const valueParts = newValue.split("e", 2);
|
|
1791
|
-
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])) {
|
|
1792
|
-
return;
|
|
1793
|
-
}
|
|
1794
|
-
commit();
|
|
1795
|
-
}
|
|
1796
|
-
},
|
|
1797
|
-
{
|
|
1798
|
-
matches: (keyDef, element) => {
|
|
1799
|
-
var _a;
|
|
1800
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1801
|
-
},
|
|
1802
|
-
handle: (keyDef, element, config) => {
|
|
1803
|
-
var _a;
|
|
1804
|
-
(_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1805
|
-
}
|
|
1806
|
-
},
|
|
1807
|
-
{
|
|
1808
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1809
|
-
handle: (keyDef, element, config) => {
|
|
1810
|
-
var _a;
|
|
1811
|
-
(_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
];
|
|
1815
|
-
|
|
1816
|
-
// src/keyboard/plugins/functional.ts
|
|
1817
|
-
var keydownBehavior3 = [
|
|
1818
|
-
{
|
|
1819
|
-
matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
|
|
1820
|
-
handle: (keyDef, element, config) => {
|
|
1821
|
-
var _a;
|
|
1822
|
-
(_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1823
|
-
}
|
|
1824
|
-
},
|
|
1825
|
-
{
|
|
1826
|
-
matches: (keyDef) => keyDef.key === "Tab",
|
|
1827
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1828
|
-
const dest = getTabDestination(element, keyboardState.modifiers.Shift);
|
|
1829
|
-
if (dest === element.ownerDocument.body) {
|
|
1830
|
-
blur(element);
|
|
1831
|
-
} else {
|
|
1832
|
-
focus(dest);
|
|
1833
|
-
if (isElementType(dest, ["input", "textarea"])) {
|
|
1834
|
-
setUISelection(dest, {
|
|
1835
|
-
anchorOffset: 0,
|
|
1836
|
-
focusOffset: dest.value.length
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
];
|
|
1843
|
-
var keypressBehavior2 = [
|
|
1844
|
-
{
|
|
1845
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
|
|
1846
|
-
handle: (keyDef, element, config) => {
|
|
1847
|
-
const form = element.form;
|
|
1848
|
-
if (hasFormSubmit(form)) {
|
|
1849
|
-
dispatchUIEvent(config, form, "submit");
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
},
|
|
1853
|
-
{
|
|
1854
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1855
|
-
handle: (keyDef, element, config) => {
|
|
1856
|
-
dispatchUIEvent(config, element, "click");
|
|
1857
|
-
}
|
|
1858
|
-
},
|
|
1859
|
-
{
|
|
1860
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1861
|
-
handle: (keyDef, element, config) => {
|
|
1862
|
-
const form = element.form;
|
|
1863
|
-
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1864
|
-
dispatchUIEvent(config, form, "submit");
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
];
|
|
1869
|
-
var keyupBehavior = [
|
|
1870
|
-
{
|
|
1871
|
-
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1872
|
-
handle: (keyDef, element, config) => {
|
|
1873
|
-
dispatchUIEvent(config, element, "click");
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
];
|
|
1877
|
-
|
|
1878
|
-
// src/keyboard/plugins/combination.ts
|
|
1879
|
-
var keydownBehavior4 = [
|
|
1880
|
-
{
|
|
1881
|
-
matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
|
|
1882
|
-
handle: (keyDef, element) => selectAll(element)
|
|
1883
|
-
}
|
|
1884
|
-
];
|
|
1885
|
-
|
|
1886
|
-
// src/keyboard/plugins/modifiers.ts
|
|
1802
|
+
// src/keyboard/modifiers.ts
|
|
1887
1803
|
var modifierKeys = [
|
|
1888
1804
|
"Alt",
|
|
1889
1805
|
"AltGraph",
|
|
@@ -1893,6 +1809,9 @@ var modifierKeys = [
|
|
|
1893
1809
|
"Shift",
|
|
1894
1810
|
"Symbol"
|
|
1895
1811
|
];
|
|
1812
|
+
function isModifierKey(key) {
|
|
1813
|
+
return modifierKeys.includes(key);
|
|
1814
|
+
}
|
|
1896
1815
|
var modifierLocks = [
|
|
1897
1816
|
"CapsLock",
|
|
1898
1817
|
"FnLock",
|
|
@@ -1900,78 +1819,40 @@ var modifierLocks = [
|
|
|
1900
1819
|
"ScrollLock",
|
|
1901
1820
|
"SymbolLock"
|
|
1902
1821
|
];
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1822
|
+
function isModifierLock(key) {
|
|
1823
|
+
return modifierLocks.includes(key);
|
|
1824
|
+
}
|
|
1825
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1826
|
+
var _a;
|
|
1827
|
+
if (isModifierKey(key)) {
|
|
1828
|
+
config.keyboardState.modifiers[key] = true;
|
|
1829
|
+
if (key === "AltGraph") {
|
|
1830
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1831
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1913
1832
|
}
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
const key = keyDef.key;
|
|
1919
|
-
keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
|
|
1920
|
-
if (!keyboardState.modifierPhase[key]) {
|
|
1921
|
-
keyboardState.modifiers[key] = true;
|
|
1922
|
-
}
|
|
1833
|
+
} else if (isModifierLock(key)) {
|
|
1834
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1835
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1836
|
+
config.keyboardState.modifiers[key] = true;
|
|
1923
1837
|
}
|
|
1924
1838
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
{
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
},
|
|
1933
|
-
{
|
|
1934
|
-
matches: (keyDef) => modifierLocks.includes(keyDef.key),
|
|
1935
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1936
|
-
const key = keyDef.key;
|
|
1937
|
-
if (keyboardState.modifierPhase[key]) {
|
|
1938
|
-
keyboardState.modifiers[key] = false;
|
|
1939
|
-
}
|
|
1839
|
+
}
|
|
1840
|
+
function preKeyupBehavior(config, { key }) {
|
|
1841
|
+
if (isModifierKey(key)) {
|
|
1842
|
+
config.keyboardState.modifiers[key] = false;
|
|
1843
|
+
} else if (isModifierLock(key)) {
|
|
1844
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1845
|
+
config.keyboardState.modifiers[key] = false;
|
|
1940
1846
|
}
|
|
1941
1847
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1949
|
-
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1950
|
-
}
|
|
1848
|
+
}
|
|
1849
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1850
|
+
var _a;
|
|
1851
|
+
if (key === "AltGraph") {
|
|
1852
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1853
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1951
1854
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
// src/keyboard/plugins/index.ts
|
|
1955
|
-
var preKeydownBehavior2 = [
|
|
1956
|
-
...preKeydownBehavior
|
|
1957
|
-
];
|
|
1958
|
-
var keydownBehavior5 = [
|
|
1959
|
-
...keydownBehavior,
|
|
1960
|
-
...keydownBehavior2,
|
|
1961
|
-
...keydownBehavior3,
|
|
1962
|
-
...keydownBehavior4
|
|
1963
|
-
];
|
|
1964
|
-
var keypressBehavior3 = [
|
|
1965
|
-
...keypressBehavior2,
|
|
1966
|
-
...keypressBehavior
|
|
1967
|
-
];
|
|
1968
|
-
var preKeyupBehavior2 = [
|
|
1969
|
-
...preKeyupBehavior
|
|
1970
|
-
];
|
|
1971
|
-
var keyupBehavior2 = [...keyupBehavior];
|
|
1972
|
-
var postKeyupBehavior2 = [
|
|
1973
|
-
...postKeyupBehavior
|
|
1974
|
-
];
|
|
1855
|
+
}
|
|
1975
1856
|
|
|
1976
1857
|
// src/keyboard/keyboardAction.ts
|
|
1977
1858
|
function keyboardAction(config, actions) {
|
|
@@ -2029,45 +1910,29 @@ function keydown(keyDef, getCurrentElement, config) {
|
|
|
2029
1910
|
config.keyboardState.carryChar = "";
|
|
2030
1911
|
}
|
|
2031
1912
|
config.keyboardState.activeElement = element;
|
|
2032
|
-
|
|
1913
|
+
preKeydownBehavior(config, keyDef, element);
|
|
2033
1914
|
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
2034
1915
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
2035
|
-
if (unpreventedDefault) {
|
|
2036
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
2037
|
-
}
|
|
2038
1916
|
return unpreventedDefault;
|
|
2039
1917
|
});
|
|
2040
1918
|
}
|
|
2041
1919
|
function keypress(keyDef, getCurrentElement, config) {
|
|
2042
1920
|
return __async(this, null, function* () {
|
|
2043
1921
|
const element = getCurrentElement();
|
|
2044
|
-
|
|
1922
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2045
1923
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2046
1924
|
}));
|
|
2047
|
-
if (unpreventedDefault) {
|
|
2048
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2049
|
-
}
|
|
2050
1925
|
});
|
|
2051
1926
|
}
|
|
2052
1927
|
function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2053
1928
|
return __async(this, null, function* () {
|
|
2054
1929
|
const element = getCurrentElement();
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
if (unprevented && unpreventedDefault) {
|
|
2058
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2059
|
-
}
|
|
1930
|
+
preKeyupBehavior(config, keyDef);
|
|
1931
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2060
1932
|
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
2061
|
-
|
|
1933
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2062
1934
|
});
|
|
2063
1935
|
}
|
|
2064
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
2065
|
-
const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
|
|
2066
|
-
if (plugin) {
|
|
2067
|
-
plugin.handle(keyDef, element, config);
|
|
2068
|
-
}
|
|
2069
|
-
return !!plugin;
|
|
2070
|
-
}
|
|
2071
1936
|
function hasKeyPress(keyDef, config) {
|
|
2072
1937
|
var _a;
|
|
2073
1938
|
return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
@@ -2567,11 +2432,11 @@ function getPrevTarget(pointerName, state) {
|
|
|
2567
2432
|
}
|
|
2568
2433
|
|
|
2569
2434
|
// src/pointer/index.ts
|
|
2570
|
-
function pointer(
|
|
2435
|
+
function pointer(input2) {
|
|
2571
2436
|
return __async(this, null, function* () {
|
|
2572
2437
|
const { pointerMap } = this[Config];
|
|
2573
2438
|
const actions = [];
|
|
2574
|
-
(Array.isArray(
|
|
2439
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2575
2440
|
if (typeof actionInput === "string") {
|
|
2576
2441
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2577
2442
|
} else if ("keys" in actionInput) {
|
|
@@ -2697,7 +2562,7 @@ function copy() {
|
|
|
2697
2562
|
// src/clipboard/cut.ts
|
|
2698
2563
|
function cut() {
|
|
2699
2564
|
return __async(this, null, function* () {
|
|
2700
|
-
var _a
|
|
2565
|
+
var _a;
|
|
2701
2566
|
const doc = this[Config].document;
|
|
2702
2567
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2703
2568
|
const clipboardData = copySelection(target);
|
|
@@ -2708,7 +2573,7 @@ function cut() {
|
|
|
2708
2573
|
clipboardData
|
|
2709
2574
|
});
|
|
2710
2575
|
if (isEditable(target)) {
|
|
2711
|
-
(
|
|
2576
|
+
input(this[Config], target, "", "deleteByCut");
|
|
2712
2577
|
}
|
|
2713
2578
|
if (this[Config].writeToClipboard) {
|
|
2714
2579
|
yield writeDataTransferToClipboard(doc, clipboardData);
|
|
@@ -2720,7 +2585,7 @@ function cut() {
|
|
|
2720
2585
|
// src/clipboard/paste.ts
|
|
2721
2586
|
function paste(clipboardData) {
|
|
2722
2587
|
return __async(this, null, function* () {
|
|
2723
|
-
var _a, _b
|
|
2588
|
+
var _a, _b;
|
|
2724
2589
|
const doc = this[Config].document;
|
|
2725
2590
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2726
2591
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
@@ -2730,10 +2595,7 @@ function paste(clipboardData) {
|
|
|
2730
2595
|
clipboardData: dataTransfer
|
|
2731
2596
|
});
|
|
2732
2597
|
if (isEditable(target)) {
|
|
2733
|
-
|
|
2734
|
-
if (textData) {
|
|
2735
|
-
(_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
|
|
2736
|
-
}
|
|
2598
|
+
input(this[Config], target, dataTransfer.getData("text"), "insertFromPaste");
|
|
2737
2599
|
}
|
|
2738
2600
|
});
|
|
2739
2601
|
}
|
|
@@ -2746,7 +2608,6 @@ function getClipboardDataFromString(text) {
|
|
|
2746
2608
|
// src/utility/clear.ts
|
|
2747
2609
|
function clear(element) {
|
|
2748
2610
|
return __async(this, null, function* () {
|
|
2749
|
-
var _a;
|
|
2750
2611
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2751
2612
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2752
2613
|
}
|
|
@@ -2758,7 +2619,7 @@ function clear(element) {
|
|
|
2758
2619
|
if (!isAllSelected(element)) {
|
|
2759
2620
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2760
2621
|
}
|
|
2761
|
-
(
|
|
2622
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2762
2623
|
});
|
|
2763
2624
|
}
|
|
2764
2625
|
|
|
@@ -2885,28 +2746,28 @@ function type(_0, _1) {
|
|
|
2885
2746
|
// src/utility/upload.ts
|
|
2886
2747
|
function upload(element, fileOrFiles) {
|
|
2887
2748
|
return __async(this, null, function* () {
|
|
2888
|
-
const
|
|
2889
|
-
if (!
|
|
2890
|
-
throw new TypeError(`The ${
|
|
2749
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2750
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2751
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2891
2752
|
}
|
|
2892
2753
|
if (isDisabled(element))
|
|
2893
2754
|
return;
|
|
2894
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file,
|
|
2755
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2895
2756
|
const fileDialog = () => {
|
|
2896
2757
|
var _a;
|
|
2897
|
-
if (files.length === ((_a =
|
|
2758
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2898
2759
|
var _a2;
|
|
2899
|
-
return f === ((_a2 =
|
|
2760
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2900
2761
|
})) {
|
|
2901
2762
|
return;
|
|
2902
2763
|
}
|
|
2903
|
-
setFiles(
|
|
2904
|
-
this.dispatchUIEvent(
|
|
2905
|
-
this.dispatchUIEvent(
|
|
2764
|
+
setFiles(input2, createFileList(files));
|
|
2765
|
+
this.dispatchUIEvent(input2, "input");
|
|
2766
|
+
this.dispatchUIEvent(input2, "change");
|
|
2906
2767
|
};
|
|
2907
|
-
|
|
2768
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2908
2769
|
yield this.click(element);
|
|
2909
|
-
|
|
2770
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2910
2771
|
});
|
|
2911
2772
|
}
|
|
2912
2773
|
function isAcceptableFile(file, accept) {
|
|
@@ -3035,9 +2896,9 @@ function keyboard2(_0) {
|
|
|
3035
2896
|
});
|
|
3036
2897
|
}
|
|
3037
2898
|
function pointer2(_0) {
|
|
3038
|
-
return __async(this, arguments, function* (
|
|
2899
|
+
return __async(this, arguments, function* (input2, options = {}) {
|
|
3039
2900
|
const { config, api } = setupDirect(options);
|
|
3040
|
-
return api.pointer(
|
|
2901
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
3041
2902
|
});
|
|
3042
2903
|
}
|
|
3043
2904
|
function paste2(clipboardData, options) {
|