@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.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,100 @@ 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
|
-
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
486
|
-
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
487
|
-
return {
|
|
488
|
-
type: isCE ? "contenteditable" : "default",
|
|
489
|
-
selection
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
function getElement2(node) {
|
|
493
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
494
|
-
}
|
|
495
|
-
function updateSelectionOnFocus(element) {
|
|
496
|
-
var _a;
|
|
497
|
-
const selection = element.ownerDocument.getSelection();
|
|
498
|
-
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
if (hasOwnSelection(element)) {
|
|
502
|
-
const contenteditable = getContentEditable(selection.focusNode);
|
|
503
|
-
if (contenteditable) {
|
|
504
|
-
if (!selection.isCollapsed) {
|
|
505
|
-
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
506
|
-
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
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
|
+
}
|
|
507
621
|
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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);
|
|
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
|
+
});
|
|
537
632
|
}
|
|
538
633
|
|
|
539
|
-
// src/utils/
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const oldValue = element.value;
|
|
546
|
-
setUIValue(element, newValue);
|
|
547
|
-
setSelection({
|
|
548
|
-
focusNode: newSelection.node,
|
|
549
|
-
anchorOffset: newSelection.offset,
|
|
550
|
-
focusOffset: newSelection.offset
|
|
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();
|
|
551
640
|
});
|
|
552
|
-
|
|
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
|
-
});
|
|
561
|
-
}
|
|
641
|
+
return result;
|
|
562
642
|
}
|
|
563
643
|
|
|
564
|
-
// src/utils/
|
|
565
|
-
function
|
|
566
|
-
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
569
|
-
if (isContentEditable(element)) {
|
|
570
|
-
return element.textContent;
|
|
571
|
-
}
|
|
572
|
-
return getUIValue(element);
|
|
644
|
+
// src/utils/misc/isDisabled.ts
|
|
645
|
+
function isDisabled(element) {
|
|
646
|
+
return Boolean(element && element.disabled);
|
|
573
647
|
}
|
|
574
648
|
|
|
575
|
-
// src/utils/
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
function getSpaceUntilMaxLength(element) {
|
|
586
|
-
const value = getValue(element);
|
|
587
|
-
if (value === null) {
|
|
588
|
-
return void 0;
|
|
649
|
+
// src/utils/focus/getActiveElement.ts
|
|
650
|
+
function getActiveElement(document2) {
|
|
651
|
+
const activeElement = document2.activeElement;
|
|
652
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
653
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
654
|
+
} else {
|
|
655
|
+
if (isDisabled(activeElement)) {
|
|
656
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
657
|
+
}
|
|
658
|
+
return activeElement;
|
|
589
659
|
}
|
|
590
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
591
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
592
660
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
661
|
+
|
|
662
|
+
// src/utils/focus/selector.ts
|
|
663
|
+
var FOCUSABLE_SELECTOR = [
|
|
664
|
+
"input:not([type=hidden]):not([disabled])",
|
|
665
|
+
"button:not([disabled])",
|
|
666
|
+
"select:not([disabled])",
|
|
667
|
+
"textarea:not([disabled])",
|
|
668
|
+
'[contenteditable=""]',
|
|
669
|
+
'[contenteditable="true"]',
|
|
670
|
+
"a[href]",
|
|
671
|
+
"[tabindex]:not([disabled])"
|
|
672
|
+
].join(", ");
|
|
673
|
+
|
|
674
|
+
// src/utils/focus/isFocusable.ts
|
|
675
|
+
function isFocusable(element) {
|
|
676
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
600
677
|
}
|
|
601
|
-
|
|
602
|
-
|
|
678
|
+
|
|
679
|
+
// src/utils/focus/blur.ts
|
|
680
|
+
function blur(element) {
|
|
681
|
+
if (!isFocusable(element))
|
|
682
|
+
return;
|
|
683
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
684
|
+
if (!wasActive)
|
|
685
|
+
return;
|
|
686
|
+
eventWrapper(() => element.blur());
|
|
603
687
|
}
|
|
604
688
|
|
|
605
689
|
// src/utils/focus/cursor.ts
|
|
@@ -650,7 +734,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
650
734
|
}
|
|
651
735
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
652
736
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
653
|
-
if (offset !== void 0 &&
|
|
737
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
654
738
|
node = node.children[nextOffset];
|
|
655
739
|
}
|
|
656
740
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -659,7 +743,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
659
743
|
if (isTextNode(node)) {
|
|
660
744
|
return true;
|
|
661
745
|
}
|
|
662
|
-
if (
|
|
746
|
+
if (isElement(node)) {
|
|
663
747
|
if (isElementType(node, ["input", "textarea"])) {
|
|
664
748
|
return node.type !== "hidden";
|
|
665
749
|
} else if (isElementType(node, "br")) {
|
|
@@ -676,7 +760,7 @@ function getOffset(node) {
|
|
|
676
760
|
}
|
|
677
761
|
return i;
|
|
678
762
|
}
|
|
679
|
-
function
|
|
763
|
+
function isElement(node) {
|
|
680
764
|
return node.nodeType === 1;
|
|
681
765
|
}
|
|
682
766
|
function isTextNode(node) {
|
|
@@ -691,7 +775,7 @@ function walkNodes(node, direction, callback) {
|
|
|
691
775
|
if (callback(node)) {
|
|
692
776
|
return node;
|
|
693
777
|
}
|
|
694
|
-
} else if (node.parentNode && (!
|
|
778
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
695
779
|
node = node.parentNode;
|
|
696
780
|
} else {
|
|
697
781
|
break;
|
|
@@ -705,169 +789,118 @@ function getDescendant(node, direction) {
|
|
|
705
789
|
return node;
|
|
706
790
|
}
|
|
707
791
|
|
|
708
|
-
// src/utils/
|
|
709
|
-
function
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
return
|
|
792
|
+
// src/utils/focus/selection.ts
|
|
793
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
794
|
+
var _a;
|
|
795
|
+
if (hasOwnSelection(element)) {
|
|
796
|
+
return setSelection({
|
|
797
|
+
focusNode: element,
|
|
798
|
+
anchorOffset,
|
|
799
|
+
focusOffset
|
|
800
|
+
});
|
|
713
801
|
}
|
|
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 {
|
|
802
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
803
|
+
return setSelection({
|
|
804
|
+
focusNode: element.firstChild,
|
|
805
|
+
anchorOffset,
|
|
806
|
+
focusOffset
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
810
|
+
}
|
|
811
|
+
function hasOwnSelection(node) {
|
|
812
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
813
|
+
}
|
|
814
|
+
function isElement2(node) {
|
|
815
|
+
return node.nodeType === 1;
|
|
816
|
+
}
|
|
817
|
+
function getTargetTypeAndSelection(node) {
|
|
818
|
+
const element = getElement2(node);
|
|
819
|
+
if (element && hasOwnSelection(element)) {
|
|
753
820
|
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
|
-
}
|
|
821
|
+
type: "input",
|
|
822
|
+
selection: getUISelection(element)
|
|
771
823
|
};
|
|
772
824
|
}
|
|
825
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
826
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
827
|
+
return {
|
|
828
|
+
type: isCE ? "contenteditable" : "default",
|
|
829
|
+
selection
|
|
830
|
+
};
|
|
773
831
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
function
|
|
832
|
+
function getElement2(node) {
|
|
833
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
834
|
+
}
|
|
835
|
+
function updateSelectionOnFocus(element) {
|
|
778
836
|
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
|
-
});
|
|
837
|
+
const selection = element.ownerDocument.getSelection();
|
|
838
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
839
|
+
return;
|
|
788
840
|
}
|
|
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
|
-
}
|
|
841
|
+
if (hasOwnSelection(element)) {
|
|
842
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
843
|
+
if (contenteditable) {
|
|
844
|
+
if (!selection.isCollapsed) {
|
|
845
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
846
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
811
847
|
}
|
|
812
|
-
}
|
|
813
|
-
|
|
848
|
+
} else {
|
|
849
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
814
852
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
return result;
|
|
853
|
+
function getInputRange(focusNode) {
|
|
854
|
+
var _a;
|
|
855
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
856
|
+
if (typeAndSelection.type === "input") {
|
|
857
|
+
return typeAndSelection.selection;
|
|
858
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
859
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
860
|
+
}
|
|
824
861
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
862
|
+
function setSelection({
|
|
863
|
+
focusNode,
|
|
864
|
+
focusOffset,
|
|
865
|
+
anchorNode = focusNode,
|
|
866
|
+
anchorOffset = focusOffset
|
|
867
|
+
}) {
|
|
868
|
+
var _a, _b;
|
|
869
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
870
|
+
if (typeAndSelection.type === "input") {
|
|
871
|
+
return setUISelection(focusNode, {
|
|
872
|
+
anchorOffset,
|
|
873
|
+
focusOffset
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
829
877
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
878
|
+
function moveSelection(node, direction) {
|
|
879
|
+
if (hasOwnSelection(node)) {
|
|
880
|
+
const selection = getUISelection(node);
|
|
881
|
+
setSelection({
|
|
882
|
+
focusNode: node,
|
|
883
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
884
|
+
});
|
|
836
885
|
} else {
|
|
837
|
-
|
|
838
|
-
|
|
886
|
+
const selection = node.ownerDocument.getSelection();
|
|
887
|
+
if (!selection) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
if (selection.isCollapsed) {
|
|
891
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
892
|
+
if (nextPosition) {
|
|
893
|
+
setSelection({
|
|
894
|
+
focusNode: nextPosition.node,
|
|
895
|
+
focusOffset: nextPosition.offset
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
} else {
|
|
899
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
839
900
|
}
|
|
840
|
-
return activeElement;
|
|
841
901
|
}
|
|
842
902
|
}
|
|
843
903
|
|
|
844
|
-
// src/utils/focus/selector.ts
|
|
845
|
-
var FOCUSABLE_SELECTOR = [
|
|
846
|
-
"input:not([type=hidden]):not([disabled])",
|
|
847
|
-
"button:not([disabled])",
|
|
848
|
-
"select:not([disabled])",
|
|
849
|
-
"textarea:not([disabled])",
|
|
850
|
-
'[contenteditable=""]',
|
|
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);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// src/utils/focus/blur.ts
|
|
862
|
-
function blur(element) {
|
|
863
|
-
if (!isFocusable(element))
|
|
864
|
-
return;
|
|
865
|
-
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
866
|
-
if (!wasActive)
|
|
867
|
-
return;
|
|
868
|
-
eventWrapper(() => element.blur());
|
|
869
|
-
}
|
|
870
|
-
|
|
871
904
|
// src/utils/focus/copySelection.ts
|
|
872
905
|
function copySelection(target) {
|
|
873
906
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
@@ -1151,9 +1184,6 @@ function wait(time) {
|
|
|
1151
1184
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1152
1185
|
}
|
|
1153
1186
|
|
|
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
1187
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1158
1188
|
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1159
1189
|
|
|
@@ -1313,13 +1343,21 @@ function getMouseButtons(...buttons) {
|
|
|
1313
1343
|
|
|
1314
1344
|
// src/event/createEvent.ts
|
|
1315
1345
|
var import_dom2 = require("@testing-library/dom");
|
|
1316
|
-
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1317
1346
|
|
|
1318
|
-
// src/event/
|
|
1347
|
+
// src/event/eventMap.ts
|
|
1319
1348
|
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1320
|
-
var
|
|
1349
|
+
var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
|
|
1350
|
+
beforeInput: {
|
|
1351
|
+
EventType: "InputEvent",
|
|
1352
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
|
|
1356
|
+
// src/event/eventTypes.ts
|
|
1357
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1358
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map2.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1321
1359
|
function getEventClass(type3) {
|
|
1322
|
-
return
|
|
1360
|
+
return type3 in eventKeys ? import_event_map2.eventMap[eventKeys[type3]].EventType : "Event";
|
|
1323
1361
|
}
|
|
1324
1362
|
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1325
1363
|
function isMouseEvent(type3) {
|
|
@@ -1331,8 +1369,8 @@ function isKeyboardEvent(type3) {
|
|
|
1331
1369
|
|
|
1332
1370
|
// src/event/createEvent.ts
|
|
1333
1371
|
function createEvent(type3, target, init) {
|
|
1334
|
-
const eventKey = Object.keys(
|
|
1335
|
-
const event = import_dom2.createEvent
|
|
1372
|
+
const eventKey = Object.keys(eventMap).find((k) => k.toLowerCase() === type3);
|
|
1373
|
+
const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventKey]);
|
|
1336
1374
|
if (isMouseEvent(type3) && init) {
|
|
1337
1375
|
assignPositionInit(event, init);
|
|
1338
1376
|
assignPointerInit(event, init);
|
|
@@ -1401,11 +1439,147 @@ behavior.click = (event, target, config) => {
|
|
|
1401
1439
|
}
|
|
1402
1440
|
};
|
|
1403
1441
|
|
|
1442
|
+
// src/event/behavior/keydown.ts
|
|
1443
|
+
behavior.keydown = (event, target, config) => {
|
|
1444
|
+
var _a, _b;
|
|
1445
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1446
|
+
};
|
|
1447
|
+
var keydownBehavior = {
|
|
1448
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1449
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1450
|
+
Backspace: (event, target, config) => {
|
|
1451
|
+
if (isEditable(target)) {
|
|
1452
|
+
return () => {
|
|
1453
|
+
input(config, target, "", "deleteContentBackward");
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
},
|
|
1457
|
+
Delete: (event, target, config) => {
|
|
1458
|
+
if (isEditable(target)) {
|
|
1459
|
+
return () => {
|
|
1460
|
+
input(config, target, "", "deleteContentForward");
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
},
|
|
1464
|
+
End: (event, target) => {
|
|
1465
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1466
|
+
return () => {
|
|
1467
|
+
var _a, _b;
|
|
1468
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1469
|
+
setSelectionRange(target, newPos, newPos);
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
},
|
|
1473
|
+
Home: (event, target) => {
|
|
1474
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1475
|
+
return () => {
|
|
1476
|
+
setSelectionRange(target, 0, 0);
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
},
|
|
1480
|
+
PageDown: (event, target) => {
|
|
1481
|
+
if (isElementType(target, ["input"])) {
|
|
1482
|
+
return () => {
|
|
1483
|
+
const newPos = getValue(target).length;
|
|
1484
|
+
setSelectionRange(target, newPos, newPos);
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
PageUp: (event, target) => {
|
|
1489
|
+
if (isElementType(target, ["input"])) {
|
|
1490
|
+
return () => {
|
|
1491
|
+
setSelectionRange(target, 0, 0);
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
},
|
|
1495
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1496
|
+
return () => {
|
|
1497
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1498
|
+
focus(dest);
|
|
1499
|
+
if (hasOwnSelection(dest)) {
|
|
1500
|
+
setUISelection(dest, {
|
|
1501
|
+
anchorOffset: 0,
|
|
1502
|
+
focusOffset: dest.value.length
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1508
|
+
var combinationBehavior = (event, target, config) => {
|
|
1509
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1510
|
+
return () => selectAll(target);
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
|
|
1514
|
+
// src/event/behavior/keypress.ts
|
|
1515
|
+
behavior.keypress = (event, target, config) => {
|
|
1516
|
+
if (event.key === "Enter") {
|
|
1517
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1518
|
+
return () => {
|
|
1519
|
+
dispatchUIEvent(config, target, "click");
|
|
1520
|
+
};
|
|
1521
|
+
} else if (isElementType(target, "input")) {
|
|
1522
|
+
const form = target.form;
|
|
1523
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1524
|
+
if (submit) {
|
|
1525
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1526
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1527
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1528
|
+
} else {
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
if (isEditable(target)) {
|
|
1534
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1535
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1536
|
+
return () => input(config, target, inputData, inputType);
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
var ClickInputOnEnter = [
|
|
1540
|
+
"button",
|
|
1541
|
+
"color",
|
|
1542
|
+
"file",
|
|
1543
|
+
"image",
|
|
1544
|
+
"reset",
|
|
1545
|
+
"submit"
|
|
1546
|
+
];
|
|
1547
|
+
var SubmitSingleInputOnEnter = [
|
|
1548
|
+
"email",
|
|
1549
|
+
"month",
|
|
1550
|
+
"password",
|
|
1551
|
+
"search",
|
|
1552
|
+
"tel",
|
|
1553
|
+
"text",
|
|
1554
|
+
"url",
|
|
1555
|
+
"week"
|
|
1556
|
+
];
|
|
1557
|
+
|
|
1558
|
+
// src/event/behavior/keyup.ts
|
|
1559
|
+
behavior.keyup = (event, target, config) => {
|
|
1560
|
+
var _a;
|
|
1561
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1562
|
+
};
|
|
1563
|
+
var keyupBehavior = {
|
|
1564
|
+
" ": (event, target, config) => {
|
|
1565
|
+
if (isClickableInput(target)) {
|
|
1566
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
// src/event/wrapEvent.ts
|
|
1572
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1573
|
+
function wrapEvent(cb, _element) {
|
|
1574
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1404
1577
|
// src/event/dispatchEvent.ts
|
|
1405
|
-
function dispatchEvent(config, target, event) {
|
|
1578
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1406
1579
|
var _a, _b;
|
|
1407
1580
|
const type3 = event.type;
|
|
1408
|
-
const behaviorImplementation =
|
|
1581
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1582
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1409
1583
|
if (behaviorImplementation) {
|
|
1410
1584
|
event.preventDefault();
|
|
1411
1585
|
let defaultPrevented = false;
|
|
@@ -1417,28 +1591,22 @@ function dispatchEvent(config, target, event) {
|
|
|
1417
1591
|
defaultPrevented = event.cancelable;
|
|
1418
1592
|
}
|
|
1419
1593
|
});
|
|
1420
|
-
target.dispatchEvent(event);
|
|
1594
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1421
1595
|
if (!defaultPrevented) {
|
|
1422
1596
|
behaviorImplementation();
|
|
1423
1597
|
}
|
|
1424
1598
|
return !defaultPrevented;
|
|
1425
1599
|
}
|
|
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);
|
|
1600
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1433
1601
|
}
|
|
1434
1602
|
|
|
1435
1603
|
// src/event/index.ts
|
|
1436
|
-
function dispatchUIEvent(config, target, type3, init) {
|
|
1604
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1437
1605
|
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1438
1606
|
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1439
1607
|
}
|
|
1440
1608
|
const event = createEvent(type3, target, init);
|
|
1441
|
-
return
|
|
1609
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1442
1610
|
}
|
|
1443
1611
|
function bindDispatchUIEvent(config) {
|
|
1444
1612
|
return dispatchUIEvent.bind(void 0, config);
|
|
@@ -1619,259 +1787,7 @@ function prepareElement(el) {
|
|
|
1619
1787
|
el[isPrepared] = isPrepared;
|
|
1620
1788
|
}
|
|
1621
1789
|
|
|
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
|
|
1790
|
+
// src/keyboard/modifiers.ts
|
|
1875
1791
|
var modifierKeys = [
|
|
1876
1792
|
"Alt",
|
|
1877
1793
|
"AltGraph",
|
|
@@ -1881,6 +1797,9 @@ var modifierKeys = [
|
|
|
1881
1797
|
"Shift",
|
|
1882
1798
|
"Symbol"
|
|
1883
1799
|
];
|
|
1800
|
+
function isModifierKey(key) {
|
|
1801
|
+
return modifierKeys.includes(key);
|
|
1802
|
+
}
|
|
1884
1803
|
var modifierLocks = [
|
|
1885
1804
|
"CapsLock",
|
|
1886
1805
|
"FnLock",
|
|
@@ -1888,78 +1807,40 @@ var modifierLocks = [
|
|
|
1888
1807
|
"ScrollLock",
|
|
1889
1808
|
"SymbolLock"
|
|
1890
1809
|
];
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1810
|
+
function isModifierLock(key) {
|
|
1811
|
+
return modifierLocks.includes(key);
|
|
1812
|
+
}
|
|
1813
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1814
|
+
var _a;
|
|
1815
|
+
if (isModifierKey(key)) {
|
|
1816
|
+
config.keyboardState.modifiers[key] = true;
|
|
1817
|
+
if (key === "AltGraph") {
|
|
1818
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1819
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1901
1820
|
}
|
|
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
|
-
}
|
|
1821
|
+
} else if (isModifierLock(key)) {
|
|
1822
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1823
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1824
|
+
config.keyboardState.modifiers[key] = true;
|
|
1911
1825
|
}
|
|
1912
1826
|
}
|
|
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
|
-
}
|
|
1827
|
+
}
|
|
1828
|
+
function preKeyupBehavior(config, { key }) {
|
|
1829
|
+
if (isModifierKey(key)) {
|
|
1830
|
+
config.keyboardState.modifiers[key] = false;
|
|
1831
|
+
} else if (isModifierLock(key)) {
|
|
1832
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1833
|
+
config.keyboardState.modifiers[key] = false;
|
|
1928
1834
|
}
|
|
1929
1835
|
}
|
|
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
|
-
}
|
|
1836
|
+
}
|
|
1837
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1838
|
+
var _a;
|
|
1839
|
+
if (key === "AltGraph") {
|
|
1840
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1841
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1939
1842
|
}
|
|
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
|
-
];
|
|
1843
|
+
}
|
|
1963
1844
|
|
|
1964
1845
|
// src/keyboard/keyboardAction.ts
|
|
1965
1846
|
async function keyboardAction(config, actions) {
|
|
@@ -2010,39 +1891,23 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
2010
1891
|
config.keyboardState.carryChar = "";
|
|
2011
1892
|
}
|
|
2012
1893
|
config.keyboardState.activeElement = element;
|
|
2013
|
-
|
|
1894
|
+
preKeydownBehavior(config, keyDef, element);
|
|
2014
1895
|
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
2015
1896
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
2016
|
-
if (unpreventedDefault) {
|
|
2017
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
2018
|
-
}
|
|
2019
1897
|
return unpreventedDefault;
|
|
2020
1898
|
}
|
|
2021
1899
|
async function keypress(keyDef, getCurrentElement, config) {
|
|
2022
1900
|
const element = getCurrentElement();
|
|
2023
|
-
|
|
1901
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2024
1902
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2025
1903
|
}));
|
|
2026
|
-
if (unpreventedDefault) {
|
|
2027
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2028
|
-
}
|
|
2029
1904
|
}
|
|
2030
1905
|
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2031
1906
|
const element = getCurrentElement();
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
if (unprevented && unpreventedDefault) {
|
|
2035
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2036
|
-
}
|
|
1907
|
+
preKeyupBehavior(config, keyDef);
|
|
1908
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2037
1909
|
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;
|
|
1910
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2046
1911
|
}
|
|
2047
1912
|
function hasKeyPress(keyDef, config) {
|
|
2048
1913
|
var _a;
|
|
@@ -2535,10 +2400,10 @@ function getPrevTarget(pointerName, state) {
|
|
|
2535
2400
|
}
|
|
2536
2401
|
|
|
2537
2402
|
// src/pointer/index.ts
|
|
2538
|
-
async function pointer(
|
|
2403
|
+
async function pointer(input2) {
|
|
2539
2404
|
const { pointerMap } = this[Config];
|
|
2540
2405
|
const actions = [];
|
|
2541
|
-
(Array.isArray(
|
|
2406
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2542
2407
|
if (typeof actionInput === "string") {
|
|
2543
2408
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2544
2409
|
} else if ("keys" in actionInput) {
|
|
@@ -2648,7 +2513,7 @@ async function copy() {
|
|
|
2648
2513
|
|
|
2649
2514
|
// src/clipboard/cut.ts
|
|
2650
2515
|
async function cut() {
|
|
2651
|
-
var _a
|
|
2516
|
+
var _a;
|
|
2652
2517
|
const doc = this[Config].document;
|
|
2653
2518
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2654
2519
|
const clipboardData = copySelection(target);
|
|
@@ -2659,7 +2524,7 @@ async function cut() {
|
|
|
2659
2524
|
clipboardData
|
|
2660
2525
|
});
|
|
2661
2526
|
if (isEditable(target)) {
|
|
2662
|
-
(
|
|
2527
|
+
input(this[Config], target, "", "deleteByCut");
|
|
2663
2528
|
}
|
|
2664
2529
|
if (this[Config].writeToClipboard) {
|
|
2665
2530
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
@@ -2669,7 +2534,7 @@ async function cut() {
|
|
|
2669
2534
|
|
|
2670
2535
|
// src/clipboard/paste.ts
|
|
2671
2536
|
async function paste(clipboardData) {
|
|
2672
|
-
var _a, _b
|
|
2537
|
+
var _a, _b;
|
|
2673
2538
|
const doc = this[Config].document;
|
|
2674
2539
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2675
2540
|
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
@@ -2679,10 +2544,7 @@ async function paste(clipboardData) {
|
|
|
2679
2544
|
clipboardData: dataTransfer
|
|
2680
2545
|
});
|
|
2681
2546
|
if (isEditable(target)) {
|
|
2682
|
-
|
|
2683
|
-
if (textData) {
|
|
2684
|
-
(_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
|
|
2685
|
-
}
|
|
2547
|
+
input(this[Config], target, dataTransfer.getData("text"), "insertFromPaste");
|
|
2686
2548
|
}
|
|
2687
2549
|
}
|
|
2688
2550
|
function getClipboardDataFromString(text) {
|
|
@@ -2693,7 +2555,6 @@ function getClipboardDataFromString(text) {
|
|
|
2693
2555
|
|
|
2694
2556
|
// src/utility/clear.ts
|
|
2695
2557
|
async function clear(element) {
|
|
2696
|
-
var _a;
|
|
2697
2558
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2698
2559
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2699
2560
|
}
|
|
@@ -2705,7 +2566,7 @@ async function clear(element) {
|
|
|
2705
2566
|
if (!isAllSelected(element)) {
|
|
2706
2567
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2707
2568
|
}
|
|
2708
|
-
(
|
|
2569
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2709
2570
|
}
|
|
2710
2571
|
|
|
2711
2572
|
// src/utility/selectOptions.ts
|
|
@@ -2822,28 +2683,28 @@ async function type(element, text, {
|
|
|
2822
2683
|
|
|
2823
2684
|
// src/utility/upload.ts
|
|
2824
2685
|
async function upload(element, fileOrFiles) {
|
|
2825
|
-
const
|
|
2826
|
-
if (!
|
|
2827
|
-
throw new TypeError(`The ${
|
|
2686
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2687
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2688
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2828
2689
|
}
|
|
2829
2690
|
if (isDisabled(element))
|
|
2830
2691
|
return;
|
|
2831
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file,
|
|
2692
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2832
2693
|
const fileDialog = () => {
|
|
2833
2694
|
var _a;
|
|
2834
|
-
if (files.length === ((_a =
|
|
2695
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2835
2696
|
var _a2;
|
|
2836
|
-
return f === ((_a2 =
|
|
2697
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2837
2698
|
})) {
|
|
2838
2699
|
return;
|
|
2839
2700
|
}
|
|
2840
|
-
setFiles(
|
|
2841
|
-
this.dispatchUIEvent(
|
|
2842
|
-
this.dispatchUIEvent(
|
|
2701
|
+
setFiles(input2, createFileList(files));
|
|
2702
|
+
this.dispatchUIEvent(input2, "input");
|
|
2703
|
+
this.dispatchUIEvent(input2, "change");
|
|
2843
2704
|
};
|
|
2844
|
-
|
|
2705
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2845
2706
|
await this.click(element);
|
|
2846
|
-
|
|
2707
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2847
2708
|
}
|
|
2848
2709
|
function isAcceptableFile(file, accept) {
|
|
2849
2710
|
if (!accept) {
|
|
@@ -2968,9 +2829,9 @@ async function keyboard2(text, options = {}) {
|
|
|
2968
2829
|
const { config, api } = setupDirect(options);
|
|
2969
2830
|
return api.keyboard(text).then(() => config.keyboardState);
|
|
2970
2831
|
}
|
|
2971
|
-
async function pointer2(
|
|
2832
|
+
async function pointer2(input2, options = {}) {
|
|
2972
2833
|
const { config, api } = setupDirect(options);
|
|
2973
|
-
return api.pointer(
|
|
2834
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2974
2835
|
}
|
|
2975
2836
|
function paste2(clipboardData, options) {
|
|
2976
2837
|
return setupDirect(options).api.paste(clipboardData);
|