@testing-library/user-event 14.4.0 → 14.4.3
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/cjs/clipboard/copy.js +6 -15
- package/dist/cjs/clipboard/cut.js +6 -15
- package/dist/cjs/clipboard/paste.js +6 -14
- package/dist/cjs/convenience/click.js +1 -4
- package/dist/cjs/convenience/hover.js +2 -12
- package/dist/cjs/document/UI.js +94 -0
- package/dist/cjs/document/copySelection.js +37 -0
- package/dist/cjs/document/getValueOrTextContent.js +27 -0
- package/dist/cjs/document/index.js +13 -68
- package/dist/cjs/document/interceptor.js +87 -4
- package/dist/cjs/document/prepareDocument.js +67 -0
- package/dist/cjs/document/trackValue.js +65 -0
- package/dist/cjs/event/behavior/click.js +8 -12
- package/dist/cjs/event/behavior/cut.js +5 -11
- package/dist/cjs/event/behavior/keydown.js +43 -43
- package/dist/cjs/event/behavior/keypress.js +9 -10
- package/dist/cjs/event/behavior/keyup.js +6 -7
- package/dist/cjs/event/behavior/paste.js +7 -12
- package/dist/cjs/event/createEvent.js +37 -28
- package/dist/cjs/event/dispatchEvent.js +21 -2
- package/dist/cjs/event/focus.js +44 -0
- package/dist/cjs/event/index.js +24 -17
- package/dist/cjs/{utils/edit → event}/input.js +50 -47
- package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/cjs/event/selection/getInputRange.js +20 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +40 -0
- package/dist/cjs/event/selection/index.js +26 -0
- package/dist/cjs/event/selection/modifySelection.js +30 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +49 -0
- package/dist/cjs/event/selection/moveSelection.js +47 -0
- package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
- package/dist/cjs/event/selection/selectAll.js +47 -0
- package/dist/cjs/event/selection/setSelection.js +30 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +90 -0
- package/dist/cjs/event/selection/setSelectionRange.js +40 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +45 -0
- package/dist/cjs/keyboard/index.js +13 -23
- package/dist/cjs/keyboard/parseKeyDef.js +8 -13
- package/dist/cjs/options.js +0 -28
- package/dist/cjs/pointer/index.js +28 -34
- package/dist/cjs/pointer/parseKeyDef.js +1 -9
- package/dist/cjs/setup/directApi.js +6 -6
- package/dist/cjs/setup/index.js +0 -2
- package/dist/cjs/setup/setup.js +69 -38
- package/dist/cjs/system/index.js +4 -2
- package/dist/cjs/system/keyboard.js +32 -32
- package/dist/cjs/system/pointer/buttons.js +3 -1
- package/dist/cjs/system/pointer/device.js +3 -1
- package/dist/cjs/system/pointer/index.js +82 -79
- package/dist/cjs/system/pointer/mouse.js +97 -81
- package/dist/cjs/system/pointer/pointer.js +45 -46
- package/dist/cjs/system/pointer/shared.js +10 -0
- package/dist/cjs/utility/clear.js +10 -11
- package/dist/cjs/utility/selectOptions.js +17 -19
- package/dist/cjs/utility/type.js +6 -15
- package/dist/cjs/utility/upload.js +9 -15
- package/dist/cjs/utils/dataTransfer/Clipboard.js +11 -21
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/cjs/utils/edit/isEditable.js +6 -10
- package/dist/cjs/utils/edit/maxLength.js +6 -16
- package/dist/cjs/utils/edit/setFiles.js +4 -2
- package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
- package/dist/cjs/utils/focus/cursor.js +2 -17
- package/dist/cjs/utils/focus/getActiveElement.js +3 -2
- package/dist/cjs/utils/focus/selection.js +1 -266
- package/dist/cjs/utils/index.js +7 -32
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/cjs/utils/misc/isDisabled.js +2 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +4 -6
- package/dist/cjs/utils/pointer/cssPointerEvents.js +26 -32
- package/dist/esm/clipboard/copy.js +6 -15
- package/dist/esm/clipboard/cut.js +6 -15
- package/dist/esm/clipboard/paste.js +6 -14
- package/dist/esm/convenience/click.js +1 -4
- package/dist/esm/convenience/hover.js +2 -12
- package/dist/esm/document/UI.js +79 -0
- package/dist/esm/document/copySelection.js +33 -0
- package/dist/esm/document/getValueOrTextContent.js +23 -0
- package/dist/esm/document/index.js +4 -66
- package/dist/esm/document/interceptor.js +85 -5
- package/dist/esm/document/prepareDocument.js +63 -0
- package/dist/esm/document/trackValue.js +59 -0
- package/dist/esm/event/behavior/click.js +8 -12
- package/dist/esm/event/behavior/cut.js +5 -11
- package/dist/esm/event/behavior/keydown.js +36 -36
- package/dist/esm/event/behavior/keypress.js +9 -10
- package/dist/esm/event/behavior/keyup.js +6 -7
- package/dist/esm/event/behavior/paste.js +7 -12
- package/dist/esm/event/createEvent.js +37 -28
- package/dist/esm/event/dispatchEvent.js +20 -3
- package/dist/esm/event/focus.js +39 -0
- package/dist/esm/event/index.js +14 -19
- package/dist/esm/{utils/edit → event}/input.js +37 -34
- package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +26 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
- package/dist/esm/event/selection/moveSelection.js +43 -0
- package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
- package/dist/esm/event/selection/selectAll.js +42 -0
- package/dist/esm/event/selection/setSelection.js +26 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
- package/dist/esm/event/selection/setSelectionRange.js +36 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
- package/dist/esm/keyboard/index.js +13 -23
- package/dist/esm/keyboard/parseKeyDef.js +8 -13
- package/dist/esm/options.js +1 -26
- package/dist/esm/pointer/index.js +28 -34
- package/dist/esm/pointer/parseKeyDef.js +1 -9
- package/dist/esm/setup/directApi.js +6 -6
- package/dist/esm/setup/index.js +0 -1
- package/dist/esm/setup/setup.js +63 -33
- package/dist/esm/system/index.js +4 -2
- package/dist/esm/system/keyboard.js +32 -32
- package/dist/esm/system/pointer/buttons.js +3 -1
- package/dist/esm/system/pointer/device.js +3 -1
- package/dist/esm/system/pointer/index.js +83 -79
- package/dist/esm/system/pointer/mouse.js +95 -79
- package/dist/esm/system/pointer/pointer.js +44 -45
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +10 -11
- package/dist/esm/utility/selectOptions.js +17 -19
- package/dist/esm/utility/type.js +6 -15
- package/dist/esm/utility/upload.js +9 -15
- package/dist/esm/utils/dataTransfer/Clipboard.js +11 -21
- package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/esm/utils/edit/isEditable.js +4 -8
- package/dist/esm/utils/edit/maxLength.js +5 -16
- package/dist/esm/utils/edit/setFiles.js +4 -2
- package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
- package/dist/esm/utils/focus/cursor.js +2 -17
- package/dist/esm/utils/focus/getActiveElement.js +3 -2
- package/dist/esm/utils/focus/selection.js +3 -260
- package/dist/esm/utils/index.js +4 -11
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/esm/utils/misc/isDisabled.js +2 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +4 -6
- package/dist/esm/utils/pointer/cssPointerEvents.js +26 -32
- package/dist/types/clipboard/copy.d.ts +1 -1
- package/dist/types/clipboard/cut.d.ts +1 -1
- package/dist/types/clipboard/paste.d.ts +1 -1
- package/dist/types/convenience/click.d.ts +1 -1
- package/dist/types/convenience/hover.d.ts +1 -1
- package/dist/types/document/UI.d.ts +42 -0
- package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -10
- package/dist/types/document/interceptor.d.ts +3 -0
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/registry.d.ts +2 -2
- package/dist/types/event/dispatchEvent.d.ts +5 -2
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +6 -4
- package/dist/types/event/input.d.ts +2 -0
- package/dist/types/event/radio.d.ts +4 -0
- package/dist/types/event/selection/getInputRange.d.ts +5 -0
- package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
- package/dist/types/event/selection/index.d.ts +15 -0
- package/dist/types/event/selection/modifySelection.d.ts +8 -0
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
- package/dist/types/event/selection/moveSelection.d.ts +4 -0
- package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
- package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
- package/dist/types/event/selection/setSelection.d.ts +10 -0
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
- package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
- package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/options.d.ts +0 -8
- package/dist/types/pointer/index.d.ts +3 -3
- package/dist/types/setup/directApi.d.ts +1 -1
- package/dist/types/setup/index.d.ts +2 -15
- package/dist/types/setup/setup.d.ts +25 -7
- package/dist/types/system/keyboard.d.ts +3 -3
- package/dist/types/system/pointer/buttons.d.ts +1 -1
- package/dist/types/system/pointer/index.d.ts +7 -25
- package/dist/types/system/pointer/mouse.d.ts +5 -5
- package/dist/types/system/pointer/pointer.d.ts +7 -7
- package/dist/types/system/pointer/shared.d.ts +20 -0
- package/dist/types/utility/clear.d.ts +1 -1
- package/dist/types/utility/selectOptions.d.ts +1 -1
- package/dist/types/utility/type.d.ts +3 -3
- package/dist/types/utility/upload.d.ts +1 -1
- package/dist/types/utils/click/isClickableInput.d.ts +2 -2
- package/dist/types/utils/edit/isEditable.d.ts +5 -6
- package/dist/types/utils/edit/maxLength.d.ts +14 -1
- package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
- package/dist/types/utils/focus/selection.d.ts +4 -69
- package/dist/types/utils/index.d.ts +2 -9
- package/dist/types/utils/misc/level.d.ts +4 -13
- package/dist/types/utils/misc/wait.d.ts +2 -2
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
- package/package.json +29 -4
- package/dist/cjs/document/selection.js +0 -107
- package/dist/cjs/document/setRangeText.js +0 -21
- package/dist/cjs/document/value.js +0 -125
- package/dist/cjs/setup/config.js +0 -7
- package/dist/cjs/utils/edit/getValue.js +0 -35
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
- package/dist/cjs/utils/focus/blur.js +0 -16
- package/dist/cjs/utils/focus/copySelection.js +0 -46
- package/dist/cjs/utils/focus/focus.js +0 -26
- package/dist/cjs/utils/focus/selectAll.js +0 -54
- package/dist/cjs/utils/misc/eventWrapper.js +0 -15
- package/dist/esm/document/selection.js +0 -99
- package/dist/esm/document/setRangeText.js +0 -17
- package/dist/esm/document/value.js +0 -115
- package/dist/esm/setup/config.js +0 -3
- package/dist/esm/utils/edit/getValue.js +0 -31
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
- package/dist/esm/utils/focus/blur.js +0 -12
- package/dist/esm/utils/focus/copySelection.js +0 -42
- package/dist/esm/utils/focus/focus.js +0 -22
- package/dist/esm/utils/focus/selectAll.js +0 -49
- package/dist/esm/utils/misc/eventWrapper.js +0 -11
- package/dist/types/document/selection.d.ts +0 -29
- package/dist/types/document/setRangeText.d.ts +0 -1
- package/dist/types/document/value.d.ts +0 -26
- package/dist/types/setup/config.d.ts +0 -6
- package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/types/utils/edit/getValue.d.ts +0 -1
- package/dist/types/utils/edit/input.d.ts +0 -2
- package/dist/types/utils/edit/walkRadio.d.ts +0 -4
- package/dist/types/utils/focus/blur.d.ts +0 -2
- package/dist/types/utils/focus/focus.d.ts +0 -5
- package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
2
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
5
|
+
import { isElementType } from '../utils/misc/isElementType.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
8
|
+
import '../utils/misc/level.js';
|
|
9
|
+
import '../options.js';
|
|
10
|
+
import { startTrackValue, trackOrSetValue } from './trackValue.js';
|
|
11
|
+
import { setUISelectionClean, setUISelectionRaw, getUIValue, setUIValueClean, isUIValue, isUISelectionStart } from './UI.js';
|
|
12
|
+
|
|
1
13
|
const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
2
14
|
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
3
15
|
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
4
16
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
5
|
-
const target = prototypeDescriptor
|
|
6
|
-
/* istanbul ignore if */ if (typeof prototypeDescriptor
|
|
17
|
+
const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
|
|
18
|
+
/* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
7
19
|
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
8
20
|
}
|
|
9
21
|
function intercept(...args) {
|
|
@@ -14,13 +26,81 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
14
26
|
} else {
|
|
15
27
|
realFunc.call(this, ...realArgs);
|
|
16
28
|
}
|
|
17
|
-
then
|
|
29
|
+
then === null || then === void 0 ? void 0 : then();
|
|
18
30
|
}
|
|
19
31
|
intercept[Interceptor] = Interceptor;
|
|
20
32
|
Object.defineProperty(element, propName, {
|
|
21
|
-
...objectDescriptor
|
|
33
|
+
...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
|
|
22
34
|
[target]: intercept
|
|
23
35
|
});
|
|
24
36
|
}
|
|
37
|
+
function prepareValueInterceptor(element) {
|
|
38
|
+
prepareInterceptor(element, 'value', function interceptorImpl(v) {
|
|
39
|
+
const isUI = isUIValue(v);
|
|
40
|
+
if (isUI) {
|
|
41
|
+
startTrackValue(this);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
applyNative: !!isUI,
|
|
45
|
+
realArgs: sanitizeValue(this, v),
|
|
46
|
+
then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function sanitizeValue(element, v) {
|
|
51
|
+
// Workaround for JSDOM
|
|
52
|
+
if (isElementType(element, 'input', {
|
|
53
|
+
type: 'number'
|
|
54
|
+
}) && String(v) !== '' && !Number.isNaN(Number(v))) {
|
|
55
|
+
// Setting value to "1." results in `null` in JSDOM
|
|
56
|
+
return String(Number(v));
|
|
57
|
+
}
|
|
58
|
+
return String(v);
|
|
59
|
+
}
|
|
60
|
+
function prepareSelectionInterceptor(element) {
|
|
61
|
+
prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
|
|
62
|
+
const isUI = isUISelectionStart(start);
|
|
63
|
+
return {
|
|
64
|
+
applyNative: !!isUI,
|
|
65
|
+
realArgs: [
|
|
66
|
+
Number(start),
|
|
67
|
+
...others
|
|
68
|
+
],
|
|
69
|
+
then: ()=>isUI ? undefined : setUISelectionClean(element)
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) {
|
|
73
|
+
return {
|
|
74
|
+
realArgs: v,
|
|
75
|
+
then: ()=>setUISelectionClean(element)
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) {
|
|
79
|
+
return {
|
|
80
|
+
realArgs: v,
|
|
81
|
+
then: ()=>setUISelectionClean(element)
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
prepareInterceptor(element, 'select', function interceptorImpl() {
|
|
85
|
+
return {
|
|
86
|
+
realArgs: [],
|
|
87
|
+
then: ()=>setUISelectionRaw(element, {
|
|
88
|
+
anchorOffset: 0,
|
|
89
|
+
focusOffset: getUIValue(element).length
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function prepareRangeTextInterceptor(element) {
|
|
95
|
+
prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) {
|
|
96
|
+
return {
|
|
97
|
+
realArgs,
|
|
98
|
+
then: ()=>{
|
|
99
|
+
setUIValueClean(element);
|
|
100
|
+
setUISelectionClean(element);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
25
105
|
|
|
26
|
-
export { prepareInterceptor };
|
|
106
|
+
export { prepareInterceptor, prepareRangeTextInterceptor, prepareSelectionInterceptor, prepareValueInterceptor };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { dispatchDOMEvent } from '../event/dispatchEvent.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../utils/edit/isEditable.js';
|
|
5
|
+
import '../utils/edit/maxLength.js';
|
|
6
|
+
import { isElementType } from '../utils/misc/isElementType.js';
|
|
7
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
8
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../utils/misc/level.js';
|
|
10
|
+
import '../options.js';
|
|
11
|
+
import { getInitialValue, clearInitialValue } from './UI.js';
|
|
12
|
+
import '@testing-library/dom';
|
|
13
|
+
import { prepareValueInterceptor, prepareSelectionInterceptor, prepareRangeTextInterceptor } from './interceptor.js';
|
|
14
|
+
|
|
15
|
+
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
16
|
+
function prepareDocument(document) {
|
|
17
|
+
if (document[isPrepared]) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
document.addEventListener('focus', (e)=>{
|
|
21
|
+
const el = e.target;
|
|
22
|
+
prepareElement(el);
|
|
23
|
+
}, {
|
|
24
|
+
capture: true,
|
|
25
|
+
passive: true
|
|
26
|
+
});
|
|
27
|
+
// Our test environment defaults to `document.body` as `activeElement`.
|
|
28
|
+
// In other environments this might be `null` when preparing.
|
|
29
|
+
// istanbul ignore else
|
|
30
|
+
if (document.activeElement) {
|
|
31
|
+
prepareElement(document.activeElement);
|
|
32
|
+
}
|
|
33
|
+
document.addEventListener('blur', (e)=>{
|
|
34
|
+
const el = e.target;
|
|
35
|
+
const initialValue = getInitialValue(el);
|
|
36
|
+
if (initialValue !== undefined) {
|
|
37
|
+
if (el.value !== initialValue) {
|
|
38
|
+
dispatchDOMEvent(el, 'change');
|
|
39
|
+
}
|
|
40
|
+
clearInitialValue(el);
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
capture: true,
|
|
44
|
+
passive: true
|
|
45
|
+
});
|
|
46
|
+
document[isPrepared] = isPrepared;
|
|
47
|
+
}
|
|
48
|
+
function prepareElement(el) {
|
|
49
|
+
if (el[isPrepared]) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (isElementType(el, [
|
|
53
|
+
'input',
|
|
54
|
+
'textarea'
|
|
55
|
+
])) {
|
|
56
|
+
prepareValueInterceptor(el);
|
|
57
|
+
prepareSelectionInterceptor(el);
|
|
58
|
+
prepareRangeTextInterceptor(el);
|
|
59
|
+
}
|
|
60
|
+
el[isPrepared] = isPrepared;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { prepareDocument };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
2
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
5
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
6
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
7
|
+
import '../utils/misc/level.js';
|
|
8
|
+
import '../options.js';
|
|
9
|
+
import { setUIValueClean, setUISelection, hasUISelection } from './UI.js';
|
|
10
|
+
|
|
11
|
+
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
12
|
+
// When the input event happens in the browser, React executes all event handlers
|
|
13
|
+
// and if they change state of a controlled value, nothing happens.
|
|
14
|
+
// But when we trigger the event handlers in test environment with React@17,
|
|
15
|
+
// the changes are rolled back before the state update is applied.
|
|
16
|
+
// This results in a reset cursor.
|
|
17
|
+
// There might be a better way to work around if we figure out
|
|
18
|
+
// why the batched update is executed differently in our test environment.
|
|
19
|
+
function isReact17Element(element) {
|
|
20
|
+
return Object.getOwnPropertyNames(element).some((k)=>k.startsWith('__react')) && getWindow(element).REACT_VERSION === 17;
|
|
21
|
+
}
|
|
22
|
+
function startTrackValue(element) {
|
|
23
|
+
if (!isReact17Element(element)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
element[TrackChanges] = {
|
|
27
|
+
previousValue: String(element.value),
|
|
28
|
+
tracked: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function trackOrSetValue(element, v) {
|
|
32
|
+
var ref, ref1;
|
|
33
|
+
(ref = element[TrackChanges]) === null || ref === void 0 ? void 0 : (ref1 = ref.tracked) === null || ref1 === void 0 ? void 0 : ref1.push(v);
|
|
34
|
+
if (!element[TrackChanges]) {
|
|
35
|
+
setUIValueClean(element);
|
|
36
|
+
setUISelection(element, {
|
|
37
|
+
focusOffset: v.length
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function commitValueAfterInput(element, cursorOffset) {
|
|
42
|
+
var ref;
|
|
43
|
+
const changes = element[TrackChanges];
|
|
44
|
+
element[TrackChanges] = undefined;
|
|
45
|
+
if (!(changes === null || changes === void 0 ? void 0 : (ref = changes.tracked) === null || ref === void 0 ? void 0 : ref.length)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
49
|
+
if (!isJustReactStateUpdate) {
|
|
50
|
+
setUIValueClean(element);
|
|
51
|
+
}
|
|
52
|
+
if (hasUISelection(element)) {
|
|
53
|
+
setUISelection(element, {
|
|
54
|
+
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { commitValueAfterInput, startTrackValue, trackOrSetValue };
|
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
import '../../utils/click/isClickableInput.js';
|
|
2
2
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../eventMap.js';
|
|
4
|
-
import { dispatchEvent } from '../dispatchEvent.js';
|
|
5
|
-
import '../../utils/edit/maxLength.js';
|
|
6
3
|
import '../../utils/edit/isEditable.js';
|
|
7
|
-
import
|
|
8
|
-
import { getWindow } from '../../utils/misc/getWindow.js';
|
|
4
|
+
import '../../utils/edit/maxLength.js';
|
|
9
5
|
import { isElementType } from '../../utils/misc/isElementType.js';
|
|
10
|
-
import {
|
|
6
|
+
import { getWindow } from '../../utils/misc/getWindow.js';
|
|
11
7
|
import { isFocusable } from '../../utils/focus/isFocusable.js';
|
|
12
8
|
import '../../utils/keyDef/readNextDescriptor.js';
|
|
13
9
|
import { cloneEvent } from '../../utils/misc/cloneEvent.js';
|
|
14
|
-
import '@testing-library/dom';
|
|
15
10
|
import '../../utils/misc/level.js';
|
|
16
11
|
import '../../options.js';
|
|
12
|
+
import { focusElement, blurElement } from '../focus.js';
|
|
17
13
|
import { behavior } from './registry.js';
|
|
18
14
|
|
|
19
|
-
behavior.click = (event, target,
|
|
15
|
+
behavior.click = (event, target, instance)=>{
|
|
20
16
|
const context = target.closest('button,input,label,select,textarea');
|
|
21
17
|
const control = context && isElementType(context, 'label') && context.control;
|
|
22
18
|
if (control) {
|
|
23
19
|
return ()=>{
|
|
24
20
|
if (isFocusable(control)) {
|
|
25
|
-
|
|
21
|
+
focusElement(control);
|
|
26
22
|
}
|
|
27
|
-
dispatchEvent(
|
|
23
|
+
instance.dispatchEvent(control, cloneEvent(event));
|
|
28
24
|
};
|
|
29
25
|
} else if (isElementType(target, 'input', {
|
|
30
26
|
type: 'file'
|
|
31
27
|
})) {
|
|
32
28
|
return ()=>{
|
|
33
29
|
// blur fires when the file selector pops up
|
|
34
|
-
|
|
30
|
+
blurElement(target);
|
|
35
31
|
target.dispatchEvent(new (getWindow(target)).Event('fileDialog'));
|
|
36
32
|
// focus fires after the file selector has been closed
|
|
37
|
-
|
|
33
|
+
focusElement(target);
|
|
38
34
|
};
|
|
39
35
|
}
|
|
40
36
|
};
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import '../../utils/click/isClickableInput.js';
|
|
2
2
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../eventMap.js';
|
|
4
|
-
import './click.js';
|
|
5
|
-
import './keydown.js';
|
|
6
|
-
import './keypress.js';
|
|
7
|
-
import './keyup.js';
|
|
8
|
-
import './paste.js';
|
|
9
|
-
import { behavior } from './registry.js';
|
|
10
|
-
import '@testing-library/dom';
|
|
11
|
-
import { input } from '../../utils/edit/input.js';
|
|
12
3
|
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
4
|
+
import '../../utils/edit/maxLength.js';
|
|
13
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
14
6
|
import '../../utils/keyDef/readNextDescriptor.js';
|
|
15
7
|
import '../../utils/misc/level.js';
|
|
16
8
|
import '../../options.js';
|
|
9
|
+
import { input } from '../input.js';
|
|
10
|
+
import { behavior } from './registry.js';
|
|
17
11
|
|
|
18
|
-
behavior.cut = (event, target,
|
|
12
|
+
behavior.cut = (event, target, instance)=>{
|
|
19
13
|
return ()=>{
|
|
20
14
|
if (isEditable(target)) {
|
|
21
|
-
input(
|
|
15
|
+
input(instance, target, '', 'deleteByCut');
|
|
22
16
|
}
|
|
23
17
|
};
|
|
24
18
|
};
|
|
@@ -1,74 +1,72 @@
|
|
|
1
|
+
import { getUIValue, setUISelection } from '../../document/UI.js';
|
|
2
|
+
import { getValueOrTextContent } from '../../document/getValueOrTextContent.js';
|
|
1
3
|
import '../../utils/click/isClickableInput.js';
|
|
2
4
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import { getValue } from '../../utils/edit/getValue.js';
|
|
4
|
-
import { input } from '../../utils/edit/input.js';
|
|
5
5
|
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
6
6
|
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
7
|
-
import
|
|
8
|
-
import '@testing-library/dom';
|
|
7
|
+
import '../../utils/edit/maxLength.js';
|
|
9
8
|
import { isElementType } from '../../utils/misc/isElementType.js';
|
|
10
|
-
import '@testing-library/dom/dist/helpers.js';
|
|
11
|
-
import { moveSelection, setSelectionRange, hasOwnSelection } from '../../utils/focus/selection.js';
|
|
12
|
-
import { focus } from '../../utils/focus/focus.js';
|
|
13
9
|
import { getTabDestination } from '../../utils/focus/getTabDestination.js';
|
|
14
|
-
import {
|
|
10
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
15
11
|
import '../../utils/keyDef/readNextDescriptor.js';
|
|
12
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
16
13
|
import '../../utils/misc/level.js';
|
|
17
14
|
import '../../options.js';
|
|
18
|
-
import '../
|
|
19
|
-
import '
|
|
20
|
-
import '
|
|
21
|
-
import '
|
|
22
|
-
import '
|
|
23
|
-
import '
|
|
15
|
+
import { focusElement } from '../focus.js';
|
|
16
|
+
import { input } from '../input.js';
|
|
17
|
+
import { moveSelection } from '../selection/moveSelection.js';
|
|
18
|
+
import { selectAll } from '../selection/selectAll.js';
|
|
19
|
+
import { setSelectionRange } from '../selection/setSelectionRange.js';
|
|
20
|
+
import { walkRadio } from '../radio.js';
|
|
24
21
|
import { behavior } from './registry.js';
|
|
25
|
-
import { setUISelection } from '../../document/selection.js';
|
|
26
22
|
|
|
27
|
-
behavior.keydown = (event, target,
|
|
28
|
-
|
|
23
|
+
behavior.keydown = (event, target, instance)=>{
|
|
24
|
+
var ref;
|
|
25
|
+
var ref1;
|
|
26
|
+
return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, instance)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, instance);
|
|
29
27
|
};
|
|
30
28
|
const keydownBehavior = {
|
|
31
|
-
ArrowDown: (event, target,
|
|
29
|
+
ArrowDown: (event, target, instance)=>{
|
|
32
30
|
/* istanbul ignore else */ if (isElementType(target, 'input', {
|
|
33
31
|
type: 'radio'
|
|
34
32
|
})) {
|
|
35
|
-
return ()=>walkRadio(
|
|
33
|
+
return ()=>walkRadio(instance, target, -1);
|
|
36
34
|
}
|
|
37
35
|
},
|
|
38
|
-
ArrowLeft: (event, target,
|
|
36
|
+
ArrowLeft: (event, target, instance)=>{
|
|
39
37
|
if (isElementType(target, 'input', {
|
|
40
38
|
type: 'radio'
|
|
41
39
|
})) {
|
|
42
|
-
return ()=>walkRadio(
|
|
40
|
+
return ()=>walkRadio(instance, target, -1);
|
|
43
41
|
}
|
|
44
42
|
return ()=>moveSelection(target, -1);
|
|
45
43
|
},
|
|
46
|
-
ArrowRight: (event, target,
|
|
44
|
+
ArrowRight: (event, target, instance)=>{
|
|
47
45
|
if (isElementType(target, 'input', {
|
|
48
46
|
type: 'radio'
|
|
49
47
|
})) {
|
|
50
|
-
return ()=>walkRadio(
|
|
48
|
+
return ()=>walkRadio(instance, target, 1);
|
|
51
49
|
}
|
|
52
50
|
return ()=>moveSelection(target, 1);
|
|
53
51
|
},
|
|
54
|
-
ArrowUp: (event, target,
|
|
52
|
+
ArrowUp: (event, target, instance)=>{
|
|
55
53
|
/* istanbul ignore else */ if (isElementType(target, 'input', {
|
|
56
54
|
type: 'radio'
|
|
57
55
|
})) {
|
|
58
|
-
return ()=>walkRadio(
|
|
56
|
+
return ()=>walkRadio(instance, target, 1);
|
|
59
57
|
}
|
|
60
58
|
},
|
|
61
|
-
Backspace: (event, target,
|
|
59
|
+
Backspace: (event, target, instance)=>{
|
|
62
60
|
if (isEditable(target)) {
|
|
63
61
|
return ()=>{
|
|
64
|
-
input(
|
|
62
|
+
input(instance, target, '', 'deleteContentBackward');
|
|
65
63
|
};
|
|
66
64
|
}
|
|
67
65
|
},
|
|
68
|
-
Delete: (event, target,
|
|
66
|
+
Delete: (event, target, instance)=>{
|
|
69
67
|
if (isEditable(target)) {
|
|
70
68
|
return ()=>{
|
|
71
|
-
input(
|
|
69
|
+
input(instance, target, '', 'deleteContentForward');
|
|
72
70
|
};
|
|
73
71
|
}
|
|
74
72
|
},
|
|
@@ -78,7 +76,9 @@ const keydownBehavior = {
|
|
|
78
76
|
'textarea'
|
|
79
77
|
]) || isContentEditable(target)) {
|
|
80
78
|
return ()=>{
|
|
81
|
-
|
|
79
|
+
var ref;
|
|
80
|
+
var ref1;
|
|
81
|
+
const newPos = (ref1 = (ref = getValueOrTextContent(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0;
|
|
82
82
|
setSelectionRange(target, newPos, newPos);
|
|
83
83
|
};
|
|
84
84
|
}
|
|
@@ -98,7 +98,7 @@ const keydownBehavior = {
|
|
|
98
98
|
'input'
|
|
99
99
|
])) {
|
|
100
100
|
return ()=>{
|
|
101
|
-
const newPos =
|
|
101
|
+
const newPos = getUIValue(target).length;
|
|
102
102
|
setSelectionRange(target, newPos, newPos);
|
|
103
103
|
};
|
|
104
104
|
}
|
|
@@ -112,10 +112,10 @@ const keydownBehavior = {
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
|
-
Tab: (event, target,
|
|
115
|
+
Tab: (event, target, instance)=>{
|
|
116
116
|
return ()=>{
|
|
117
|
-
const dest = getTabDestination(target,
|
|
118
|
-
|
|
117
|
+
const dest = getTabDestination(target, instance.system.keyboard.modifiers.Shift);
|
|
118
|
+
focusElement(dest);
|
|
119
119
|
if (hasOwnSelection(dest)) {
|
|
120
120
|
setUISelection(dest, {
|
|
121
121
|
anchorOffset: 0,
|
|
@@ -125,8 +125,8 @@ const keydownBehavior = {
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
|
-
const combinationBehavior = (event, target,
|
|
129
|
-
if (event.code === 'KeyA' &&
|
|
128
|
+
const combinationBehavior = (event, target, instance)=>{
|
|
129
|
+
if (event.code === 'KeyA' && instance.system.keyboard.modifiers.Control) {
|
|
130
130
|
return ()=>selectAll(target);
|
|
131
131
|
}
|
|
132
132
|
};
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import { dispatchUIEvent } from '../index.js';
|
|
2
1
|
import '../../utils/click/isClickableInput.js';
|
|
3
2
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
3
|
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
5
|
-
import { input } from '../../utils/edit/input.js';
|
|
6
4
|
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
7
|
-
import '
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
8
6
|
import { isElementType } from '../../utils/misc/isElementType.js';
|
|
9
7
|
import '@testing-library/dom/dist/helpers.js';
|
|
10
8
|
import '../../utils/keyDef/readNextDescriptor.js';
|
|
11
9
|
import '../../utils/misc/level.js';
|
|
12
10
|
import '../../options.js';
|
|
11
|
+
import { input } from '../input.js';
|
|
13
12
|
import { behavior } from './registry.js';
|
|
14
13
|
|
|
15
|
-
behavior.keypress = (event, target,
|
|
14
|
+
behavior.keypress = (event, target, instance)=>{
|
|
16
15
|
if (event.key === 'Enter') {
|
|
17
16
|
if (isElementType(target, 'button') || isElementType(target, 'input') && ClickInputOnEnter.includes(target.type) || isElementType(target, 'a') && Boolean(target.href)) {
|
|
18
17
|
return ()=>{
|
|
19
|
-
dispatchUIEvent(
|
|
18
|
+
instance.dispatchUIEvent(target, 'click');
|
|
20
19
|
};
|
|
21
20
|
} else if (isElementType(target, 'input')) {
|
|
22
21
|
const form = target.form;
|
|
23
|
-
const submit = form
|
|
22
|
+
const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
24
23
|
if (submit) {
|
|
25
|
-
return ()=>dispatchUIEvent(
|
|
24
|
+
return ()=>instance.dispatchUIEvent(submit, 'click');
|
|
26
25
|
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
|
|
27
|
-
return ()=>dispatchUIEvent(
|
|
26
|
+
return ()=>instance.dispatchUIEvent(form, 'submit');
|
|
28
27
|
} else {
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
if (isEditable(target)) {
|
|
34
|
-
const inputType = event.key === 'Enter' ? isContentEditable(target) && !
|
|
33
|
+
const inputType = event.key === 'Enter' ? isContentEditable(target) && !instance.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText';
|
|
35
34
|
const inputData = event.key === 'Enter' ? '\n' : event.key;
|
|
36
|
-
return ()=>input(
|
|
35
|
+
return ()=>input(instance, target, inputData, inputType);
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
38
|
const ClickInputOnEnter = [
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { isClickableInput } from '../../utils/click/isClickableInput.js';
|
|
2
2
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import { dispatchUIEvent } from '../index.js';
|
|
4
|
-
import '../../utils/edit/maxLength.js';
|
|
5
3
|
import '../../utils/edit/isEditable.js';
|
|
6
|
-
import '
|
|
4
|
+
import '../../utils/edit/maxLength.js';
|
|
7
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
8
6
|
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
7
|
import '../../utils/misc/level.js';
|
|
10
8
|
import '../../options.js';
|
|
11
9
|
import { behavior } from './registry.js';
|
|
12
10
|
|
|
13
|
-
behavior.keyup = (event, target,
|
|
14
|
-
|
|
11
|
+
behavior.keyup = (event, target, instance)=>{
|
|
12
|
+
var ref;
|
|
13
|
+
return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, instance);
|
|
15
14
|
};
|
|
16
15
|
const keyupBehavior = {
|
|
17
|
-
' ': (event, target,
|
|
16
|
+
' ': (event, target, instance)=>{
|
|
18
17
|
if (isClickableInput(target)) {
|
|
19
|
-
return ()=>dispatchUIEvent(
|
|
18
|
+
return ()=>instance.dispatchUIEvent(target, 'click');
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
};
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import '../../utils/click/isClickableInput.js';
|
|
2
2
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import '../eventMap.js';
|
|
4
|
-
import './click.js';
|
|
5
|
-
import './cut.js';
|
|
6
|
-
import './keydown.js';
|
|
7
|
-
import './keypress.js';
|
|
8
|
-
import './keyup.js';
|
|
9
|
-
import { behavior } from './registry.js';
|
|
10
|
-
import '@testing-library/dom';
|
|
11
|
-
import { input } from '../../utils/edit/input.js';
|
|
12
3
|
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
4
|
+
import '../../utils/edit/maxLength.js';
|
|
13
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
14
6
|
import '../../utils/keyDef/readNextDescriptor.js';
|
|
15
7
|
import '../../utils/misc/level.js';
|
|
16
8
|
import '../../options.js';
|
|
9
|
+
import { input } from '../input.js';
|
|
10
|
+
import { behavior } from './registry.js';
|
|
17
11
|
|
|
18
|
-
behavior.paste = (event, target,
|
|
12
|
+
behavior.paste = (event, target, instance)=>{
|
|
19
13
|
if (isEditable(target)) {
|
|
20
14
|
return ()=>{
|
|
21
|
-
|
|
15
|
+
var ref;
|
|
16
|
+
const insertData = (ref = event.clipboardData) === null || ref === void 0 ? void 0 : ref.getData('text');
|
|
22
17
|
if (insertData) {
|
|
23
|
-
input(
|
|
18
|
+
input(instance, target, insertData, 'insertFromPaste');
|
|
24
19
|
}
|
|
25
20
|
};
|
|
26
21
|
}
|