@testing-library/user-event 14.4.2 → 14.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_interop/dtl.js +30 -0
- package/dist/cjs/_interop/dtlEventMap.js +30 -0
- package/dist/cjs/_interop/dtlHelpers.js +30 -0
- package/dist/cjs/clipboard/copy.js +6 -16
- package/dist/cjs/clipboard/cut.js +6 -16
- package/dist/cjs/clipboard/paste.js +6 -16
- package/dist/cjs/convenience/click.js +1 -4
- package/dist/cjs/convenience/hover.js +2 -12
- package/dist/cjs/convenience/tab.js +1 -1
- 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 +89 -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 -47
- package/dist/cjs/event/behavior/keypress.js +12 -12
- package/dist/cjs/event/behavior/keyup.js +6 -8
- package/dist/cjs/event/behavior/paste.js +7 -13
- package/dist/cjs/event/createEvent.js +43 -50
- package/dist/cjs/event/dispatchEvent.js +21 -3
- package/dist/cjs/event/eventMap.js +2 -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 +52 -50
- 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 +41 -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 +50 -0
- package/dist/cjs/event/selection/moveSelection.js +48 -0
- package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +10 -18
- package/dist/cjs/event/selection/selectAll.js +48 -0
- package/dist/cjs/event/selection/setSelection.js +30 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +91 -0
- package/dist/cjs/event/selection/setSelectionRange.js +40 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +46 -0
- package/dist/cjs/event/wrapEvent.js +3 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/keyboard/index.js +13 -23
- package/dist/cjs/keyboard/parseKeyDef.js +9 -17
- package/dist/cjs/options.js +0 -28
- package/dist/cjs/pointer/index.js +28 -38
- package/dist/cjs/pointer/keyMap.js +1 -1
- package/dist/cjs/pointer/parseKeyDef.js +2 -10
- package/dist/cjs/setup/api.js +19 -17
- package/dist/cjs/setup/directApi.js +6 -6
- package/dist/cjs/setup/index.js +0 -2
- package/dist/cjs/setup/setup.js +70 -42
- package/dist/cjs/setup/wrapAsync.js +3 -2
- package/dist/cjs/system/index.js +15 -2
- package/dist/cjs/system/keyboard.js +34 -21
- package/dist/cjs/system/pointer/buttons.js +14 -1
- package/dist/cjs/system/pointer/device.js +14 -1
- package/dist/cjs/system/pointer/index.js +60 -45
- package/dist/cjs/system/pointer/mouse.js +77 -56
- package/dist/cjs/system/pointer/pointer.js +56 -42
- package/dist/cjs/system/pointer/shared.js +10 -0
- package/dist/cjs/utility/clear.js +10 -11
- package/dist/cjs/utility/selectOptions.js +28 -29
- package/dist/cjs/utility/type.js +6 -15
- package/dist/cjs/utility/upload.js +9 -18
- package/dist/cjs/utils/dataTransfer/Clipboard.js +26 -24
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +25 -9
- package/dist/cjs/utils/edit/isEditable.js +6 -10
- package/dist/cjs/utils/edit/maxLength.js +6 -17
- package/dist/cjs/utils/edit/setFiles.js +4 -4
- package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
- package/dist/cjs/utils/focus/cursor.js +2 -18
- package/dist/cjs/utils/focus/getActiveElement.js +4 -3
- package/dist/cjs/utils/focus/selection.js +1 -271
- package/dist/cjs/utils/focus/selector.js +1 -1
- package/dist/cjs/utils/index.js +7 -32
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -5
- package/dist/cjs/utils/misc/getTreeDiff.js +3 -3
- package/dist/cjs/utils/misc/getWindow.js +3 -2
- package/dist/cjs/utils/misc/isDisabled.js +3 -3
- package/dist/cjs/utils/misc/isVisible.js +3 -2
- package/dist/cjs/utils/misc/level.js +4 -9
- package/dist/cjs/utils/misc/wait.js +1 -1
- package/dist/cjs/utils/pointer/cssPointerEvents.js +31 -40
- package/dist/esm/_interop/dtl.js +6 -0
- package/dist/esm/_interop/dtlEventMap.js +6 -0
- package/dist/esm/_interop/dtlHelpers.js +6 -0
- package/dist/esm/clipboard/copy.js +6 -16
- package/dist/esm/clipboard/cut.js +6 -16
- package/dist/esm/clipboard/paste.js +6 -16
- package/dist/esm/convenience/click.js +1 -4
- package/dist/esm/convenience/hover.js +2 -12
- package/dist/esm/convenience/tab.js +1 -1
- 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 +87 -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 -40
- package/dist/esm/event/behavior/keypress.js +12 -12
- package/dist/esm/event/behavior/keyup.js +6 -8
- package/dist/esm/event/behavior/paste.js +7 -13
- package/dist/esm/event/createEvent.js +43 -50
- package/dist/esm/event/dispatchEvent.js +20 -4
- package/dist/esm/event/eventMap.js +2 -2
- package/dist/esm/event/focus.js +39 -0
- package/dist/esm/event/index.js +14 -19
- package/dist/esm/{utils/edit → event}/input.js +39 -37
- 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 +37 -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 +46 -0
- package/dist/esm/event/selection/moveSelection.js +44 -0
- package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +9 -17
- package/dist/esm/event/selection/selectAll.js +43 -0
- package/dist/esm/event/selection/setSelection.js +26 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +87 -0
- package/dist/esm/event/selection/setSelectionRange.js +36 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +42 -0
- package/dist/esm/event/wrapEvent.js +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/keyboard/index.js +13 -23
- package/dist/esm/keyboard/parseKeyDef.js +9 -17
- package/dist/esm/options.js +1 -26
- package/dist/esm/pointer/index.js +28 -38
- package/dist/esm/pointer/keyMap.js +1 -1
- package/dist/esm/pointer/parseKeyDef.js +2 -10
- package/dist/esm/setup/api.js +33 -12
- package/dist/esm/setup/directApi.js +6 -6
- package/dist/esm/setup/index.js +0 -1
- package/dist/esm/setup/setup.js +66 -39
- package/dist/esm/setup/wrapAsync.js +2 -1
- package/dist/esm/system/index.js +15 -2
- package/dist/esm/system/keyboard.js +34 -21
- package/dist/esm/system/pointer/buttons.js +14 -1
- package/dist/esm/system/pointer/device.js +14 -1
- package/dist/esm/system/pointer/index.js +61 -45
- package/dist/esm/system/pointer/mouse.js +74 -53
- package/dist/esm/system/pointer/pointer.js +55 -41
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +10 -11
- package/dist/esm/utility/selectOptions.js +24 -25
- package/dist/esm/utility/type.js +5 -14
- package/dist/esm/utility/upload.js +9 -18
- package/dist/esm/utils/dataTransfer/Clipboard.js +26 -24
- package/dist/esm/utils/dataTransfer/DataTransfer.js +25 -9
- package/dist/esm/utils/edit/isEditable.js +4 -8
- package/dist/esm/utils/edit/maxLength.js +5 -17
- package/dist/esm/utils/edit/setFiles.js +4 -4
- package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
- package/dist/esm/utils/focus/cursor.js +2 -18
- package/dist/esm/utils/focus/getActiveElement.js +4 -3
- package/dist/esm/utils/focus/selection.js +3 -265
- package/dist/esm/utils/focus/selector.js +1 -1
- package/dist/esm/utils/index.js +4 -11
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -5
- package/dist/esm/utils/misc/getTreeDiff.js +3 -3
- package/dist/esm/utils/misc/getWindow.js +2 -1
- package/dist/esm/utils/misc/isDisabled.js +3 -3
- package/dist/esm/utils/misc/isVisible.js +3 -2
- package/dist/esm/utils/misc/level.js +4 -9
- package/dist/esm/utils/misc/wait.js +1 -1
- package/dist/esm/utils/pointer/cssPointerEvents.js +31 -40
- package/dist/types/_interop/dtl.d.ts +3 -0
- package/dist/types/_interop/dtlEventMap.d.ts +3 -0
- package/dist/types/_interop/dtlHelpers.d.ts +3 -0
- 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/convenience/tab.d.ts +1 -1
- package/dist/types/document/UI.d.ts +42 -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 +6 -3
- 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/createEvent.d.ts +1 -1
- package/dist/types/event/dispatchEvent.d.ts +5 -2
- package/dist/types/event/eventMap.d.ts +8 -0
- 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/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/event/types.d.ts +3 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/options.d.ts +2 -10
- package/dist/types/pointer/index.d.ts +7 -7
- package/dist/types/setup/api.d.ts +23 -5
- package/dist/types/setup/directApi.d.ts +5 -5
- 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 +4 -4
- package/dist/types/system/pointer/buttons.d.ts +2 -2
- package/dist/types/system/pointer/device.d.ts +1 -1
- package/dist/types/system/pointer/index.d.ts +7 -25
- package/dist/types/system/pointer/mouse.d.ts +6 -6
- package/dist/types/system/pointer/pointer.d.ts +8 -8
- 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 +4 -4
- package/dist/types/utility/upload.d.ts +1 -1
- package/dist/types/utils/click/isClickableInput.d.ts +2 -2
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
- package/dist/types/utils/edit/isEditable.d.ts +6 -7
- 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/keyDef/readNextDescriptor.d.ts +1 -1
- package/dist/types/utils/misc/isElementType.d.ts +1 -1
- 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 +24 -12
- package/dist/cjs/document/selection.js +0 -108
- package/dist/cjs/document/setRangeText.js +0 -21
- package/dist/cjs/document/value.js +0 -127
- 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 -29
- package/dist/cjs/utils/focus/selectAll.js +0 -56
- package/dist/cjs/utils/misc/eventWrapper.js +0 -15
- package/dist/esm/document/selection.js +0 -100
- package/dist/esm/document/setRangeText.js +0 -17
- package/dist/esm/document/value.js +0 -117
- 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 -25
- package/dist/esm/utils/focus/selectAll.js +0 -51
- 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
- /package/dist/cjs/{event → _interop}/dom-events.d.js +0 -0
- /package/dist/cjs/{utils/misc → _interop}/dom-helpers.d.js +0 -0
- /package/dist/esm/{event → _interop}/dom-events.d.js +0 -0
- /package/dist/esm/{utils/misc → _interop}/dom-helpers.d.js +0 -0
- /package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -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
|
@@ -1,34 +1,24 @@
|
|
|
1
|
-
import '../setup/index.js';
|
|
2
1
|
import '../utils/click/isClickableInput.js';
|
|
3
2
|
import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
|
|
4
|
-
import '../event/eventMap.js';
|
|
5
|
-
import '../event/behavior/click.js';
|
|
6
|
-
import '../event/behavior/cut.js';
|
|
7
|
-
import '../event/behavior/keydown.js';
|
|
8
|
-
import '../event/behavior/keypress.js';
|
|
9
|
-
import '../event/behavior/keyup.js';
|
|
10
|
-
import '../event/behavior/paste.js';
|
|
11
|
-
import '@testing-library/dom';
|
|
12
|
-
import '../utils/edit/maxLength.js';
|
|
13
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
14
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
15
|
-
import { copySelection } from '../utils/focus/copySelection.js';
|
|
16
6
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
17
7
|
import '../utils/misc/level.js';
|
|
18
8
|
import '../options.js';
|
|
19
|
-
import {
|
|
9
|
+
import { copySelection } from '../document/copySelection.js';
|
|
20
10
|
|
|
21
11
|
async function copy() {
|
|
22
|
-
const doc = this
|
|
23
|
-
var
|
|
24
|
-
const target = (
|
|
12
|
+
const doc = this.config.document;
|
|
13
|
+
var _doc_activeElement;
|
|
14
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
25
15
|
const clipboardData = copySelection(target);
|
|
26
16
|
if (clipboardData.items.length === 0) {
|
|
27
17
|
return;
|
|
28
18
|
}
|
|
29
19
|
if (this.dispatchUIEvent(target, 'copy', {
|
|
30
20
|
clipboardData
|
|
31
|
-
}) && this
|
|
21
|
+
}) && this.config.writeToClipboard) {
|
|
32
22
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
33
23
|
}
|
|
34
24
|
return clipboardData;
|
|
@@ -1,34 +1,24 @@
|
|
|
1
|
-
import '../setup/index.js';
|
|
2
1
|
import '../utils/click/isClickableInput.js';
|
|
3
2
|
import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
|
|
4
|
-
import '../event/eventMap.js';
|
|
5
|
-
import '../event/behavior/click.js';
|
|
6
|
-
import '../event/behavior/cut.js';
|
|
7
|
-
import '../event/behavior/keydown.js';
|
|
8
|
-
import '../event/behavior/keypress.js';
|
|
9
|
-
import '../event/behavior/keyup.js';
|
|
10
|
-
import '../event/behavior/paste.js';
|
|
11
|
-
import '@testing-library/dom';
|
|
12
|
-
import '../utils/edit/maxLength.js';
|
|
13
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
14
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
15
|
-
import { copySelection } from '../utils/focus/copySelection.js';
|
|
16
6
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
17
7
|
import '../utils/misc/level.js';
|
|
18
8
|
import '../options.js';
|
|
19
|
-
import {
|
|
9
|
+
import { copySelection } from '../document/copySelection.js';
|
|
20
10
|
|
|
21
11
|
async function cut() {
|
|
22
|
-
const doc = this
|
|
23
|
-
var
|
|
24
|
-
const target = (
|
|
12
|
+
const doc = this.config.document;
|
|
13
|
+
var _doc_activeElement;
|
|
14
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
25
15
|
const clipboardData = copySelection(target);
|
|
26
16
|
if (clipboardData.items.length === 0) {
|
|
27
17
|
return;
|
|
28
18
|
}
|
|
29
19
|
if (this.dispatchUIEvent(target, 'cut', {
|
|
30
20
|
clipboardData
|
|
31
|
-
}) && this
|
|
21
|
+
}) && this.config.writeToClipboard) {
|
|
32
22
|
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
33
23
|
}
|
|
34
24
|
return clipboardData;
|
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import '../setup/index.js';
|
|
2
1
|
import '../utils/click/isClickableInput.js';
|
|
3
2
|
import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
|
|
4
3
|
import { readDataTransferFromClipboard } from '../utils/dataTransfer/Clipboard.js';
|
|
5
|
-
import '../event/eventMap.js';
|
|
6
|
-
import '../event/behavior/click.js';
|
|
7
|
-
import '../event/behavior/cut.js';
|
|
8
|
-
import '../event/behavior/keydown.js';
|
|
9
|
-
import '../event/behavior/keypress.js';
|
|
10
|
-
import '../event/behavior/keyup.js';
|
|
11
|
-
import '../event/behavior/paste.js';
|
|
12
|
-
import '@testing-library/dom';
|
|
13
|
-
import '../utils/edit/maxLength.js';
|
|
14
4
|
import '../utils/edit/isEditable.js';
|
|
5
|
+
import '../utils/edit/maxLength.js';
|
|
15
6
|
import { getWindow } from '../utils/misc/getWindow.js';
|
|
16
7
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
17
8
|
import '../utils/misc/level.js';
|
|
18
9
|
import '../options.js';
|
|
19
|
-
import { Config } from '../setup/config.js';
|
|
20
10
|
|
|
21
11
|
async function paste(clipboardData) {
|
|
22
|
-
const doc = this
|
|
23
|
-
var
|
|
24
|
-
const target = (
|
|
25
|
-
var
|
|
26
|
-
const dataTransfer = (
|
|
12
|
+
const doc = this.config.document;
|
|
13
|
+
var _doc_activeElement;
|
|
14
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
15
|
+
var _ref;
|
|
16
|
+
const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== void 0 ? _ref : await readDataTransferFromClipboard(doc).catch(()=>{
|
|
27
17
|
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
28
18
|
});
|
|
29
19
|
this.dispatchUIEvent(target, 'paste', {
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import '../setup/index.js';
|
|
2
1
|
import '../utils/click/isClickableInput.js';
|
|
3
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
-
import '../event/eventMap.js';
|
|
5
|
-
import '../event/behavior/click.js';
|
|
6
|
-
import '../event/behavior/cut.js';
|
|
7
|
-
import '../event/behavior/keydown.js';
|
|
8
|
-
import '../event/behavior/keypress.js';
|
|
9
|
-
import '../event/behavior/keyup.js';
|
|
10
|
-
import '../event/behavior/paste.js';
|
|
11
|
-
import '@testing-library/dom';
|
|
12
|
-
import '../utils/edit/maxLength.js';
|
|
13
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
14
5
|
import '@testing-library/dom/dist/helpers.js';
|
|
15
6
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
16
7
|
import '../utils/misc/level.js';
|
|
17
8
|
import { assertPointerEvents } from '../utils/pointer/cssPointerEvents.js';
|
|
18
|
-
import { Config } from '../setup/config.js';
|
|
19
9
|
|
|
20
10
|
async function hover(element) {
|
|
21
11
|
return this.pointer({
|
|
@@ -23,7 +13,7 @@ async function hover(element) {
|
|
|
23
13
|
});
|
|
24
14
|
}
|
|
25
15
|
async function unhover(element) {
|
|
26
|
-
assertPointerEvents(this
|
|
16
|
+
assertPointerEvents(this, this.system.pointer.getMouseTarget(this));
|
|
27
17
|
return this.pointer({
|
|
28
18
|
target: element.ownerDocument.body
|
|
29
19
|
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const UIValue = Symbol('Displayed value in UI');
|
|
2
|
+
const UISelection = Symbol('Displayed selection in UI');
|
|
3
|
+
const InitialValue = Symbol('Initial value to compare on blur');
|
|
4
|
+
function isUIValue(value) {
|
|
5
|
+
return typeof value === 'object' && UIValue in value;
|
|
6
|
+
}
|
|
7
|
+
function isUISelectionStart(start) {
|
|
8
|
+
return !!start && typeof start === 'object' && UISelection in start;
|
|
9
|
+
}
|
|
10
|
+
function setUIValue(element, value) {
|
|
11
|
+
if (element[InitialValue] === undefined) {
|
|
12
|
+
element[InitialValue] = element.value;
|
|
13
|
+
}
|
|
14
|
+
element[UIValue] = value;
|
|
15
|
+
// eslint-disable-next-line no-new-wrappers
|
|
16
|
+
element.value = Object.assign(new String(value), {
|
|
17
|
+
[UIValue]: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function getUIValue(element) {
|
|
21
|
+
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
22
|
+
}
|
|
23
|
+
/** Flag the IDL value as clean. This does not change the value.*/ function setUIValueClean(element) {
|
|
24
|
+
element[UIValue] = undefined;
|
|
25
|
+
}
|
|
26
|
+
function clearInitialValue(element) {
|
|
27
|
+
element[InitialValue] = undefined;
|
|
28
|
+
}
|
|
29
|
+
function getInitialValue(element) {
|
|
30
|
+
return element[InitialValue];
|
|
31
|
+
}
|
|
32
|
+
function setUISelectionRaw(element, selection) {
|
|
33
|
+
element[UISelection] = selection;
|
|
34
|
+
}
|
|
35
|
+
function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam = focusOffsetParam }, mode = 'replace') {
|
|
36
|
+
const valueLength = getUIValue(element).length;
|
|
37
|
+
const sanitizeOffset = (o)=>Math.max(0, Math.min(valueLength, o));
|
|
38
|
+
const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
39
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
40
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
41
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
42
|
+
element[UISelection] = {
|
|
43
|
+
anchorOffset,
|
|
44
|
+
focusOffset
|
|
45
|
+
};
|
|
46
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line no-new-wrappers
|
|
50
|
+
const startObj = Object.assign(new Number(startOffset), {
|
|
51
|
+
[UISelection]: true
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
element.setSelectionRange(startObj, endOffset);
|
|
55
|
+
} catch {
|
|
56
|
+
// DOMException for invalid state is expected when calling this
|
|
57
|
+
// on an element without support for setSelectionRange
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function getUISelection(element) {
|
|
61
|
+
var _element_selectionStart, _element_selectionEnd, _element_UISelection;
|
|
62
|
+
const sel = (_element_UISelection = element[UISelection]) !== null && _element_UISelection !== void 0 ? _element_UISelection : {
|
|
63
|
+
anchorOffset: (_element_selectionStart = element.selectionStart) !== null && _element_selectionStart !== void 0 ? _element_selectionStart : 0,
|
|
64
|
+
focusOffset: (_element_selectionEnd = element.selectionEnd) !== null && _element_selectionEnd !== void 0 ? _element_selectionEnd : 0
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
...sel,
|
|
68
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
69
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function hasUISelection(element) {
|
|
73
|
+
return !!element[UISelection];
|
|
74
|
+
}
|
|
75
|
+
/** Flag the IDL selection as clean. This does not change the selection. */ function setUISelectionClean(element) {
|
|
76
|
+
element[UISelection] = undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { clearInitialValue, getInitialValue, getUISelection, getUIValue, hasUISelection, isUISelectionStart, isUIValue, setUISelection, setUISelectionClean, setUISelectionRaw, setUIValue, setUIValueClean };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
2
|
+
import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
|
|
3
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../utils/edit/isEditable.js';
|
|
5
|
+
import '../utils/edit/maxLength.js';
|
|
6
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
7
|
+
import { hasOwnSelection } from '../utils/focus/selection.js';
|
|
8
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../utils/misc/level.js';
|
|
10
|
+
import '../options.js';
|
|
11
|
+
import { getUISelection, getUIValue } from './UI.js';
|
|
12
|
+
|
|
13
|
+
function copySelection(target) {
|
|
14
|
+
const data = hasOwnSelection(target) ? {
|
|
15
|
+
'text/plain': readSelectedValueFromInput(target)
|
|
16
|
+
} : {
|
|
17
|
+
'text/plain': String(target.ownerDocument.getSelection())
|
|
18
|
+
};
|
|
19
|
+
const dt = createDataTransfer(getWindow(target));
|
|
20
|
+
for(const type in data){
|
|
21
|
+
if (data[type]) {
|
|
22
|
+
dt.setData(type, data[type]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return dt;
|
|
26
|
+
}
|
|
27
|
+
function readSelectedValueFromInput(target) {
|
|
28
|
+
const sel = getUISelection(target);
|
|
29
|
+
const val = getUIValue(target);
|
|
30
|
+
return val.substring(sel.startOffset, sel.endOffset);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { copySelection };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
2
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { isContentEditable } from '../utils/edit/isContentEditable.js';
|
|
4
|
+
import '../utils/edit/isEditable.js';
|
|
5
|
+
import '../utils/edit/maxLength.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 { getUIValue } from './UI.js';
|
|
11
|
+
|
|
12
|
+
function getValueOrTextContent(element) {
|
|
13
|
+
// istanbul ignore if
|
|
14
|
+
if (!element) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (isContentEditable(element)) {
|
|
18
|
+
return element.textContent;
|
|
19
|
+
}
|
|
20
|
+
return getUIValue(element);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getValueOrTextContent };
|
|
@@ -1,66 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import '../utils/edit/isEditable.js';
|
|
6
|
-
import '@testing-library/dom';
|
|
7
|
-
import { isElementType } from '../utils/misc/isElementType.js';
|
|
8
|
-
import '@testing-library/dom/dist/helpers.js';
|
|
9
|
-
import '../utils/keyDef/readNextDescriptor.js';
|
|
10
|
-
import '../utils/misc/level.js';
|
|
11
|
-
import '../options.js';
|
|
12
|
-
import { prepareSelectionInterceptor } from './selection.js';
|
|
13
|
-
export { getUISelection, setUISelection } from './selection.js';
|
|
14
|
-
import { prepareRangeTextInterceptor } from './setRangeText.js';
|
|
15
|
-
import { getInitialValue, clearInitialValue, prepareValueInterceptor } from './value.js';
|
|
16
|
-
export { clearInitialValue, commitValueAfterInput, getUIValue, setUIValue } from './value.js';
|
|
17
|
-
|
|
18
|
-
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
19
|
-
function prepareDocument(document) {
|
|
20
|
-
if (document[isPrepared]) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
document.addEventListener('focus', (e)=>{
|
|
24
|
-
const el = e.target;
|
|
25
|
-
prepareElement(el);
|
|
26
|
-
}, {
|
|
27
|
-
capture: true,
|
|
28
|
-
passive: true
|
|
29
|
-
});
|
|
30
|
-
// Our test environment defaults to `document.body` as `activeElement`.
|
|
31
|
-
// In other environments this might be `null` when preparing.
|
|
32
|
-
// istanbul ignore else
|
|
33
|
-
if (document.activeElement) {
|
|
34
|
-
prepareElement(document.activeElement);
|
|
35
|
-
}
|
|
36
|
-
document.addEventListener('blur', (e)=>{
|
|
37
|
-
const el = e.target;
|
|
38
|
-
const initialValue = getInitialValue(el);
|
|
39
|
-
if (initialValue !== undefined) {
|
|
40
|
-
if (el.value !== initialValue) {
|
|
41
|
-
dispatchUIEvent({}, el, 'change');
|
|
42
|
-
}
|
|
43
|
-
clearInitialValue(el);
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
capture: true,
|
|
47
|
-
passive: true
|
|
48
|
-
});
|
|
49
|
-
document[isPrepared] = isPrepared;
|
|
50
|
-
}
|
|
51
|
-
function prepareElement(el) {
|
|
52
|
-
if (el[isPrepared]) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (isElementType(el, [
|
|
56
|
-
'input',
|
|
57
|
-
'textarea'
|
|
58
|
-
])) {
|
|
59
|
-
prepareValueInterceptor(el);
|
|
60
|
-
prepareSelectionInterceptor(el);
|
|
61
|
-
prepareRangeTextInterceptor(el);
|
|
62
|
-
}
|
|
63
|
-
el[isPrepared] = isPrepared;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { prepareDocument };
|
|
1
|
+
export { clearInitialValue, getUISelection, getUIValue, setUISelection, setUIValue } from './UI.js';
|
|
2
|
+
export { getValueOrTextContent } from './getValueOrTextContent.js';
|
|
3
|
+
export { copySelection } from './copySelection.js';
|
|
4
|
+
export { commitValueAfterInput } from './trackValue.js';
|
|
@@ -1,20 +1,34 @@
|
|
|
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) {
|
|
15
|
+
var _prototypeDescriptor, _prototypeDescriptor1;
|
|
3
16
|
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
4
17
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
5
|
-
const target = (prototypeDescriptor === null ||
|
|
6
|
-
/* istanbul ignore if */ if (typeof (prototypeDescriptor === null ||
|
|
18
|
+
const target = ((_prototypeDescriptor = prototypeDescriptor) === null || _prototypeDescriptor === void 0 ? void 0 : _prototypeDescriptor.set) ? 'set' : 'value';
|
|
19
|
+
/* istanbul ignore if */ if (typeof ((_prototypeDescriptor1 = prototypeDescriptor) === null || _prototypeDescriptor1 === void 0 ? void 0 : _prototypeDescriptor1[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
7
20
|
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
8
21
|
}
|
|
9
22
|
function intercept(...args) {
|
|
10
|
-
|
|
23
|
+
var _then;
|
|
24
|
+
const { applyNative = false, realArgs, then } = interceptorImpl.call(this, ...args);
|
|
11
25
|
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
12
26
|
if (target === 'set') {
|
|
13
27
|
realFunc.call(this, realArgs);
|
|
14
28
|
} else {
|
|
15
29
|
realFunc.call(this, ...realArgs);
|
|
16
30
|
}
|
|
17
|
-
then === null ||
|
|
31
|
+
(_then = then) === null || _then === void 0 ? void 0 : _then();
|
|
18
32
|
}
|
|
19
33
|
intercept[Interceptor] = Interceptor;
|
|
20
34
|
Object.defineProperty(element, propName, {
|
|
@@ -22,5 +36,73 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
22
36
|
[target]: intercept
|
|
23
37
|
});
|
|
24
38
|
}
|
|
39
|
+
function prepareValueInterceptor(element) {
|
|
40
|
+
prepareInterceptor(element, 'value', function interceptorImpl(v) {
|
|
41
|
+
const isUI = isUIValue(v);
|
|
42
|
+
if (isUI) {
|
|
43
|
+
startTrackValue(this);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
applyNative: !!isUI,
|
|
47
|
+
realArgs: sanitizeValue(this, v),
|
|
48
|
+
then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function sanitizeValue(element, v) {
|
|
53
|
+
// Workaround for JSDOM
|
|
54
|
+
if (isElementType(element, 'input', {
|
|
55
|
+
type: 'number'
|
|
56
|
+
}) && String(v) !== '' && !Number.isNaN(Number(v))) {
|
|
57
|
+
// Setting value to "1." results in `null` in JSDOM
|
|
58
|
+
return String(Number(v));
|
|
59
|
+
}
|
|
60
|
+
return String(v);
|
|
61
|
+
}
|
|
62
|
+
function prepareSelectionInterceptor(element) {
|
|
63
|
+
prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
|
|
64
|
+
const isUI = isUISelectionStart(start);
|
|
65
|
+
return {
|
|
66
|
+
applyNative: !!isUI,
|
|
67
|
+
realArgs: [
|
|
68
|
+
Number(start),
|
|
69
|
+
...others
|
|
70
|
+
],
|
|
71
|
+
then: ()=>isUI ? undefined : setUISelectionClean(element)
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) {
|
|
75
|
+
return {
|
|
76
|
+
realArgs: v,
|
|
77
|
+
then: ()=>setUISelectionClean(element)
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) {
|
|
81
|
+
return {
|
|
82
|
+
realArgs: v,
|
|
83
|
+
then: ()=>setUISelectionClean(element)
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
prepareInterceptor(element, 'select', function interceptorImpl() {
|
|
87
|
+
return {
|
|
88
|
+
realArgs: [],
|
|
89
|
+
then: ()=>setUISelectionRaw(element, {
|
|
90
|
+
anchorOffset: 0,
|
|
91
|
+
focusOffset: getUIValue(element).length
|
|
92
|
+
})
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function prepareRangeTextInterceptor(element) {
|
|
97
|
+
prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) {
|
|
98
|
+
return {
|
|
99
|
+
realArgs,
|
|
100
|
+
then: ()=>{
|
|
101
|
+
setUIValueClean(element);
|
|
102
|
+
setUISelectionClean(element);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
25
107
|
|
|
26
|
-
export { prepareInterceptor };
|
|
108
|
+
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 _element_TrackChanges_tracked, _element_TrackChanges;
|
|
33
|
+
(_element_TrackChanges = element[TrackChanges]) === null || _element_TrackChanges === void 0 ? void 0 : (_element_TrackChanges_tracked = _element_TrackChanges.tracked) === null || _element_TrackChanges_tracked === void 0 ? void 0 : _element_TrackChanges_tracked.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 _changes_tracked, _changes;
|
|
43
|
+
const changes = element[TrackChanges];
|
|
44
|
+
element[TrackChanges] = undefined;
|
|
45
|
+
if (!((_changes = changes) === null || _changes === void 0 ? void 0 : (_changes_tracked = _changes.tracked) === null || _changes_tracked === void 0 ? void 0 : _changes_tracked.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 };
|