@depup/testing-library__user-event 14.6.3-depup.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/LICENSE +20 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/cjs/clipboard/copy.js +22 -0
- package/dist/cjs/clipboard/cut.js +22 -0
- package/dist/cjs/clipboard/index.js +11 -0
- package/dist/cjs/clipboard/paste.js +24 -0
- package/dist/cjs/convenience/click.js +35 -0
- package/dist/cjs/convenience/hover.js +19 -0
- package/dist/cjs/convenience/index.js +14 -0
- package/dist/cjs/convenience/tab.js +7 -0
- package/dist/cjs/document/UI.js +90 -0
- package/dist/cjs/document/copySelection.js +29 -0
- package/dist/cjs/document/getValueOrTextContent.js +18 -0
- package/dist/cjs/document/index.js +17 -0
- package/dist/cjs/document/interceptor.js +104 -0
- package/dist/cjs/document/patchFocus.js +106 -0
- package/dist/cjs/document/prepareDocument.js +58 -0
- package/dist/cjs/document/trackValue.js +57 -0
- package/dist/cjs/event/behavior/click.js +32 -0
- package/dist/cjs/event/behavior/cut.js +14 -0
- package/dist/cjs/event/behavior/index.js +13 -0
- package/dist/cjs/event/behavior/keydown.js +128 -0
- package/dist/cjs/event/behavior/keypress.js +51 -0
- package/dist/cjs/event/behavior/keyup.js +17 -0
- package/dist/cjs/event/behavior/paste.js +18 -0
- package/dist/cjs/event/behavior/registry.js +5 -0
- package/dist/cjs/event/createEvent.js +193 -0
- package/dist/cjs/event/dispatchEvent.js +54 -0
- package/dist/cjs/event/eventMap.js +281 -0
- package/dist/cjs/event/focus.js +34 -0
- package/dist/cjs/event/index.js +22 -0
- package/dist/cjs/event/input.js +158 -0
- package/dist/cjs/event/radio.js +27 -0
- package/dist/cjs/event/selection/getInputRange.js +18 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +31 -0
- package/dist/cjs/event/selection/index.js +24 -0
- package/dist/cjs/event/selection/modifySelection.js +21 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +40 -0
- package/dist/cjs/event/selection/moveSelection.js +38 -0
- package/dist/cjs/event/selection/resolveCaretPosition.js +60 -0
- package/dist/cjs/event/selection/selectAll.js +38 -0
- package/dist/cjs/event/selection/setSelection.js +21 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +79 -0
- package/dist/cjs/event/selection/setSelectionRange.js +31 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +40 -0
- package/dist/cjs/event/types.js +2 -0
- package/dist/cjs/event/wrapEvent.js +10 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/keyboard/index.js +40 -0
- package/dist/cjs/keyboard/keyMap.js +178 -0
- package/dist/cjs/keyboard/parseKeyDef.js +45 -0
- package/dist/cjs/options.js +14 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pointer/index.js +74 -0
- package/dist/cjs/pointer/keyMap.js +33 -0
- package/dist/cjs/pointer/parseKeyDef.js +23 -0
- package/dist/cjs/setup/api.js +35 -0
- package/dist/cjs/setup/directApi.js +75 -0
- package/dist/cjs/setup/index.js +11 -0
- package/dist/cjs/setup/setup.js +125 -0
- package/dist/cjs/setup/wrapAsync.js +11 -0
- package/dist/cjs/system/index.js +42 -0
- package/dist/cjs/system/keyboard.js +165 -0
- package/dist/cjs/system/pointer/buttons.js +80 -0
- package/dist/cjs/system/pointer/device.js +32 -0
- package/dist/cjs/system/pointer/index.js +156 -0
- package/dist/cjs/system/pointer/mouse.js +204 -0
- package/dist/cjs/system/pointer/pointer.js +129 -0
- package/dist/cjs/system/pointer/shared.js +8 -0
- package/dist/cjs/utility/clear.js +32 -0
- package/dist/cjs/utility/index.js +14 -0
- package/dist/cjs/utility/selectOptions.js +114 -0
- package/dist/cjs/utility/type.js +23 -0
- package/dist/cjs/utility/upload.js +62 -0
- package/dist/cjs/utils/click/isClickableInput.js +20 -0
- package/dist/cjs/utils/dataTransfer/Blob.js +16 -0
- package/dist/cjs/utils/dataTransfer/Clipboard.js +174 -0
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +134 -0
- package/dist/cjs/utils/dataTransfer/FileList.js +24 -0
- package/dist/cjs/utils/edit/isContentEditable.js +18 -0
- package/dist/cjs/utils/edit/isEditable.js +29 -0
- package/dist/cjs/utils/edit/maxLength.js +26 -0
- package/dist/cjs/utils/edit/setFiles.js +58 -0
- package/dist/cjs/utils/edit/timeValue.js +40 -0
- package/dist/cjs/utils/focus/cursor.js +126 -0
- package/dist/cjs/utils/focus/getActiveElement.js +25 -0
- package/dist/cjs/utils/focus/getTabDestination.js +80 -0
- package/dist/cjs/utils/focus/isFocusable.js +9 -0
- package/dist/cjs/utils/focus/selection.js +20 -0
- package/dist/cjs/utils/focus/selector.js +15 -0
- package/dist/cjs/utils/index.js +78 -0
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +91 -0
- package/dist/cjs/utils/misc/cloneEvent.js +7 -0
- package/dist/cjs/utils/misc/findClosest.js +14 -0
- package/dist/cjs/utils/misc/getDocumentFromNode.js +10 -0
- package/dist/cjs/utils/misc/getTreeDiff.js +25 -0
- package/dist/cjs/utils/misc/getWindow.js +19 -0
- package/dist/cjs/utils/misc/isDescendantOrSelf.js +14 -0
- package/dist/cjs/utils/misc/isDisabled.js +33 -0
- package/dist/cjs/utils/misc/isElementType.js +20 -0
- package/dist/cjs/utils/misc/isVisible.js +19 -0
- package/dist/cjs/utils/misc/level.js +17 -0
- package/dist/cjs/utils/misc/wait.js +14 -0
- package/dist/cjs/utils/pointer/cssPointerEvents.js +102 -0
- package/dist/esm/clipboard/copy.js +20 -0
- package/dist/esm/clipboard/cut.js +20 -0
- package/dist/esm/clipboard/index.js +3 -0
- package/dist/esm/clipboard/paste.js +22 -0
- package/dist/esm/convenience/click.js +31 -0
- package/dist/esm/convenience/hover.js +16 -0
- package/dist/esm/convenience/index.js +3 -0
- package/dist/esm/convenience/tab.js +5 -0
- package/dist/esm/document/UI.js +77 -0
- package/dist/esm/document/copySelection.js +27 -0
- package/dist/esm/document/getValueOrTextContent.js +16 -0
- package/dist/esm/document/index.js +4 -0
- package/dist/esm/document/interceptor.js +99 -0
- package/dist/esm/document/patchFocus.js +103 -0
- package/dist/esm/document/prepareDocument.js +56 -0
- package/dist/esm/document/trackValue.js +53 -0
- package/dist/esm/event/behavior/click.js +30 -0
- package/dist/esm/event/behavior/cut.js +12 -0
- package/dist/esm/event/behavior/index.js +7 -0
- package/dist/esm/event/behavior/keydown.js +126 -0
- package/dist/esm/event/behavior/keypress.js +49 -0
- package/dist/esm/event/behavior/keyup.js +15 -0
- package/dist/esm/event/behavior/paste.js +16 -0
- package/dist/esm/event/behavior/registry.js +3 -0
- package/dist/esm/event/createEvent.js +191 -0
- package/dist/esm/event/dispatchEvent.js +50 -0
- package/dist/esm/event/eventMap.js +277 -0
- package/dist/esm/event/focus.js +31 -0
- package/dist/esm/event/index.js +7 -0
- package/dist/esm/event/input.js +156 -0
- package/dist/esm/event/radio.js +25 -0
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +29 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +19 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +38 -0
- package/dist/esm/event/selection/moveSelection.js +36 -0
- package/dist/esm/event/selection/resolveCaretPosition.js +58 -0
- package/dist/esm/event/selection/selectAll.js +35 -0
- package/dist/esm/event/selection/setSelection.js +19 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +77 -0
- package/dist/esm/event/selection/setSelectionRange.js +29 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +38 -0
- package/dist/esm/event/types.js +1 -0
- package/dist/esm/event/wrapEvent.js +8 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/keyboard/index.js +37 -0
- package/dist/esm/keyboard/keyMap.js +176 -0
- package/dist/esm/keyboard/parseKeyDef.js +43 -0
- package/dist/esm/options.js +12 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pointer/index.js +72 -0
- package/dist/esm/pointer/keyMap.js +31 -0
- package/dist/esm/pointer/parseKeyDef.js +21 -0
- package/dist/esm/setup/api.js +33 -0
- package/dist/esm/setup/directApi.js +58 -0
- package/dist/esm/setup/index.js +9 -0
- package/dist/esm/setup/setup.js +119 -0
- package/dist/esm/setup/wrapAsync.js +9 -0
- package/dist/esm/system/index.js +40 -0
- package/dist/esm/system/keyboard.js +162 -0
- package/dist/esm/system/pointer/buttons.js +74 -0
- package/dist/esm/system/pointer/device.js +30 -0
- package/dist/esm/system/pointer/index.js +154 -0
- package/dist/esm/system/pointer/mouse.js +202 -0
- package/dist/esm/system/pointer/pointer.js +127 -0
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +30 -0
- package/dist/esm/utility/index.js +4 -0
- package/dist/esm/utility/selectOptions.js +111 -0
- package/dist/esm/utility/type.js +21 -0
- package/dist/esm/utility/upload.js +60 -0
- package/dist/esm/utils/click/isClickableInput.js +18 -0
- package/dist/esm/utils/dataTransfer/Blob.js +14 -0
- package/dist/esm/utils/dataTransfer/Clipboard.js +167 -0
- package/dist/esm/utils/dataTransfer/DataTransfer.js +131 -0
- package/dist/esm/utils/dataTransfer/FileList.js +22 -0
- package/dist/esm/utils/edit/isContentEditable.js +15 -0
- package/dist/esm/utils/edit/isEditable.js +26 -0
- package/dist/esm/utils/edit/maxLength.js +23 -0
- package/dist/esm/utils/edit/setFiles.js +56 -0
- package/dist/esm/utils/edit/timeValue.js +37 -0
- package/dist/esm/utils/focus/cursor.js +124 -0
- package/dist/esm/utils/focus/getActiveElement.js +22 -0
- package/dist/esm/utils/focus/getTabDestination.js +78 -0
- package/dist/esm/utils/focus/isFocusable.js +7 -0
- package/dist/esm/utils/focus/selection.js +17 -0
- package/dist/esm/utils/focus/selector.js +13 -0
- package/dist/esm/utils/index.js +29 -0
- package/dist/esm/utils/keyDef/readNextDescriptor.js +89 -0
- package/dist/esm/utils/misc/cloneEvent.js +5 -0
- package/dist/esm/utils/misc/findClosest.js +12 -0
- package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
- package/dist/esm/utils/misc/getTreeDiff.js +23 -0
- package/dist/esm/utils/misc/getWindow.js +17 -0
- package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
- package/dist/esm/utils/misc/isDisabled.js +31 -0
- package/dist/esm/utils/misc/isElementType.js +18 -0
- package/dist/esm/utils/misc/isVisible.js +17 -0
- package/dist/esm/utils/misc/level.js +13 -0
- package/dist/esm/utils/misc/wait.js +12 -0
- package/dist/esm/utils/pointer/cssPointerEvents.js +99 -0
- package/dist/types/clipboard/copy.d.ts +2 -0
- package/dist/types/clipboard/cut.d.ts +2 -0
- package/dist/types/clipboard/index.d.ts +3 -0
- package/dist/types/clipboard/paste.d.ts +2 -0
- package/dist/types/convenience/click.d.ts +4 -0
- package/dist/types/convenience/hover.d.ts +3 -0
- package/dist/types/convenience/index.d.ts +3 -0
- package/dist/types/convenience/tab.d.ts +4 -0
- package/dist/types/document/UI.d.ts +42 -0
- package/dist/types/document/copySelection.d.ts +1 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -0
- package/dist/types/document/interceptor.d.ts +19 -0
- package/dist/types/document/patchFocus.d.ts +9 -0
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/cut.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +8 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/paste.d.ts +1 -0
- package/dist/types/event/behavior/registry.d.ts +8 -0
- package/dist/types/event/createEvent.d.ts +2 -0
- package/dist/types/event/dispatchEvent.d.ts +5 -0
- package/dist/types/event/eventMap.d.ts +265 -0
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +7 -0
- 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/resolveCaretPosition.d.ts +8 -0
- package/dist/types/event/selection/selectAll.d.ts +5 -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 +20 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/keyboard/index.d.ts +3 -0
- package/dist/types/keyboard/keyMap.d.ts +5 -0
- package/dist/types/keyboard/parseKeyDef.d.ts +17 -0
- package/dist/types/options.d.ts +115 -0
- package/dist/types/pointer/index.d.ts +28 -0
- package/dist/types/pointer/keyMap.d.ts +2 -0
- package/dist/types/pointer/parseKeyDef.d.ts +6 -0
- package/dist/types/setup/api.d.ts +23 -0
- package/dist/types/setup/directApi.d.ts +24 -0
- package/dist/types/setup/index.d.ts +22 -0
- package/dist/types/setup/setup.d.ts +44 -0
- package/dist/types/setup/wrapAsync.d.ts +4 -0
- package/dist/types/system/index.d.ts +10 -0
- package/dist/types/system/keyboard.d.ts +50 -0
- package/dist/types/system/pointer/buttons.d.ts +23 -0
- package/dist/types/system/pointer/device.d.ts +8 -0
- package/dist/types/system/pointer/index.d.ts +21 -0
- package/dist/types/system/pointer/mouse.d.ts +31 -0
- package/dist/types/system/pointer/pointer.d.ts +32 -0
- package/dist/types/system/pointer/shared.d.ts +20 -0
- package/dist/types/utility/clear.d.ts +2 -0
- package/dist/types/utility/index.d.ts +4 -0
- package/dist/types/utility/selectOptions.d.ts +3 -0
- package/dist/types/utility/type.d.ts +9 -0
- package/dist/types/utility/upload.d.ts +5 -0
- package/dist/types/utils/click/isClickableInput.d.ts +15 -0
- package/dist/types/utils/dataTransfer/Blob.d.ts +3 -0
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +11 -0
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/types/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/types/utils/edit/isEditable.d.ts +24 -0
- package/dist/types/utils/edit/maxLength.d.ts +14 -0
- package/dist/types/utils/edit/setFiles.d.ts +12 -0
- package/dist/types/utils/edit/timeValue.d.ts +4 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/types/utils/focus/getActiveElement.d.ts +2 -0
- package/dist/types/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/types/utils/focus/isFocusable.d.ts +1 -0
- package/dist/types/utils/focus/selection.d.ts +8 -0
- package/dist/types/utils/focus/selector.d.ts +1 -0
- package/dist/types/utils/index.d.ts +29 -0
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +21 -0
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -0
- package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
- package/dist/types/utils/misc/getWindow.d.ts +1 -0
- package/dist/types/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/types/utils/misc/isDisabled.d.ts +1 -0
- package/dist/types/utils/misc/isElementType.d.ts +5 -0
- package/dist/types/utils/misc/isVisible.d.ts +1 -0
- package/dist/types/utils/misc/level.d.ts +8 -0
- package/dist/types/utils/misc/wait.d.ts +2 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +19 -0
- package/package.json +131 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2020 Giorgio Polvara
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @depup/testing-library__user-event
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [@testing-library/user-event](https://www.npmjs.com/package/@testing-library/user-event)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/testing-library__user-event
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [@testing-library/user-event](https://www.npmjs.com/package/@testing-library/user-event) @ 14.6.3 |
|
|
17
|
+
| Processed | 2026-08-04 |
|
|
18
|
+
| Smoke test | failed |
|
|
19
|
+
| Deps updated | 0 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@testing-library/user-event
|
|
24
|
+
|
|
25
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Clipboard = require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var copySelection = require('../document/copySelection.js');
|
|
5
|
+
|
|
6
|
+
async function copy() {
|
|
7
|
+
var _doc_activeElement;
|
|
8
|
+
const doc = this.config.document;
|
|
9
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
10
|
+
const clipboardData = copySelection.copySelection(target);
|
|
11
|
+
if (clipboardData.items.length === 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (this.dispatchUIEvent(target, 'copy', {
|
|
15
|
+
clipboardData
|
|
16
|
+
}) && this.config.writeToClipboard) {
|
|
17
|
+
await Clipboard.writeDataTransferToClipboard(doc, clipboardData);
|
|
18
|
+
}
|
|
19
|
+
return clipboardData;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.copy = copy;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Clipboard = require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var copySelection = require('../document/copySelection.js');
|
|
5
|
+
|
|
6
|
+
async function cut() {
|
|
7
|
+
var _doc_activeElement;
|
|
8
|
+
const doc = this.config.document;
|
|
9
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
10
|
+
const clipboardData = copySelection.copySelection(target);
|
|
11
|
+
if (clipboardData.items.length === 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (this.dispatchUIEvent(target, 'cut', {
|
|
15
|
+
clipboardData
|
|
16
|
+
}) && this.config.writeToClipboard) {
|
|
17
|
+
await Clipboard.writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
18
|
+
}
|
|
19
|
+
return clipboardData;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.cut = cut;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var DataTransfer = require('../utils/dataTransfer/DataTransfer.js');
|
|
4
|
+
var Clipboard = require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
+
var getWindow = require('../utils/misc/getWindow.js');
|
|
6
|
+
|
|
7
|
+
async function paste(clipboardData) {
|
|
8
|
+
var _doc_activeElement, _ref;
|
|
9
|
+
const doc = this.config.document;
|
|
10
|
+
const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
|
|
11
|
+
const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== void 0 ? _ref : await Clipboard.readDataTransferFromClipboard(doc).catch(()=>{
|
|
12
|
+
throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
|
|
13
|
+
});
|
|
14
|
+
this.dispatchUIEvent(target, 'paste', {
|
|
15
|
+
clipboardData: dataTransfer
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function getClipboardDataFromString(doc, text) {
|
|
19
|
+
const dt = DataTransfer.createDataTransfer(getWindow.getWindow(doc));
|
|
20
|
+
dt.setData('text', text);
|
|
21
|
+
return dt;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.paste = paste;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
async function click(element) {
|
|
4
|
+
const pointerIn = [];
|
|
5
|
+
if (!this.config.skipHover) {
|
|
6
|
+
pointerIn.push({
|
|
7
|
+
target: element
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
pointerIn.push({
|
|
11
|
+
keys: '[MouseLeft]',
|
|
12
|
+
target: element
|
|
13
|
+
});
|
|
14
|
+
return this.pointer(pointerIn);
|
|
15
|
+
}
|
|
16
|
+
async function dblClick(element) {
|
|
17
|
+
return this.pointer([
|
|
18
|
+
{
|
|
19
|
+
target: element
|
|
20
|
+
},
|
|
21
|
+
'[MouseLeft][MouseLeft]'
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
async function tripleClick(element) {
|
|
25
|
+
return this.pointer([
|
|
26
|
+
{
|
|
27
|
+
target: element
|
|
28
|
+
},
|
|
29
|
+
'[MouseLeft][MouseLeft][MouseLeft]'
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.click = click;
|
|
34
|
+
exports.dblClick = dblClick;
|
|
35
|
+
exports.tripleClick = tripleClick;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var cssPointerEvents = require('../utils/pointer/cssPointerEvents.js');
|
|
5
|
+
|
|
6
|
+
async function hover(element) {
|
|
7
|
+
return this.pointer({
|
|
8
|
+
target: element
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
async function unhover(element) {
|
|
12
|
+
cssPointerEvents.assertPointerEvents(this, this.system.pointer.getMouseTarget(this));
|
|
13
|
+
return this.pointer({
|
|
14
|
+
target: element.ownerDocument.body
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.hover = hover;
|
|
19
|
+
exports.unhover = unhover;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var click = require('./click.js');
|
|
4
|
+
var hover = require('./hover.js');
|
|
5
|
+
var tab = require('./tab.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.click = click.click;
|
|
10
|
+
exports.dblClick = click.dblClick;
|
|
11
|
+
exports.tripleClick = click.tripleClick;
|
|
12
|
+
exports.hover = hover.hover;
|
|
13
|
+
exports.unhover = hover.unhover;
|
|
14
|
+
exports.tab = tab.tab;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const UIValue = Symbol('Displayed value in UI');
|
|
4
|
+
const UISelection = Symbol('Displayed selection in UI');
|
|
5
|
+
const InitialValue = Symbol('Initial value to compare on blur');
|
|
6
|
+
function isUIValue(value) {
|
|
7
|
+
return typeof value === 'object' && UIValue in value;
|
|
8
|
+
}
|
|
9
|
+
function isUISelectionStart(start) {
|
|
10
|
+
return !!start && typeof start === 'object' && UISelection in start;
|
|
11
|
+
}
|
|
12
|
+
function setUIValue(element, value) {
|
|
13
|
+
if (element[InitialValue] === undefined) {
|
|
14
|
+
element[InitialValue] = element.value;
|
|
15
|
+
}
|
|
16
|
+
element[UIValue] = value;
|
|
17
|
+
element.value = Object.assign(new String(value), {
|
|
18
|
+
[UIValue]: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function getUIValue(element) {
|
|
22
|
+
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
23
|
+
}
|
|
24
|
+
/** Flag the IDL value as clean. This does not change the value. */ function setUIValueClean(element) {
|
|
25
|
+
element[UIValue] = undefined;
|
|
26
|
+
}
|
|
27
|
+
function clearInitialValue(element) {
|
|
28
|
+
element[InitialValue] = undefined;
|
|
29
|
+
}
|
|
30
|
+
function getInitialValue(element) {
|
|
31
|
+
return element[InitialValue];
|
|
32
|
+
}
|
|
33
|
+
function setUISelectionRaw(element, selection) {
|
|
34
|
+
element[UISelection] = selection;
|
|
35
|
+
}
|
|
36
|
+
function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam = focusOffsetParam }, mode = 'replace') {
|
|
37
|
+
const valueLength = getUIValue(element).length;
|
|
38
|
+
const sanitizeOffset = (o)=>Math.max(0, Math.min(valueLength, o));
|
|
39
|
+
const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
40
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
41
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
42
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
43
|
+
element[UISelection] = {
|
|
44
|
+
anchorOffset,
|
|
45
|
+
focusOffset
|
|
46
|
+
};
|
|
47
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
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_UISelection, _element_selectionStart, _element_selectionEnd;
|
|
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
|
+
exports.clearInitialValue = clearInitialValue;
|
|
80
|
+
exports.getInitialValue = getInitialValue;
|
|
81
|
+
exports.getUISelection = getUISelection;
|
|
82
|
+
exports.getUIValue = getUIValue;
|
|
83
|
+
exports.hasUISelection = hasUISelection;
|
|
84
|
+
exports.isUISelectionStart = isUISelectionStart;
|
|
85
|
+
exports.isUIValue = isUIValue;
|
|
86
|
+
exports.setUISelection = setUISelection;
|
|
87
|
+
exports.setUISelectionClean = setUISelectionClean;
|
|
88
|
+
exports.setUISelectionRaw = setUISelectionRaw;
|
|
89
|
+
exports.setUIValue = setUIValue;
|
|
90
|
+
exports.setUIValueClean = setUIValueClean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var DataTransfer = require('../utils/dataTransfer/DataTransfer.js');
|
|
4
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
+
var getWindow = require('../utils/misc/getWindow.js');
|
|
6
|
+
var selection = require('../utils/focus/selection.js');
|
|
7
|
+
var UI = require('./UI.js');
|
|
8
|
+
|
|
9
|
+
function copySelection(target) {
|
|
10
|
+
const data = selection.hasOwnSelection(target) ? {
|
|
11
|
+
'text/plain': readSelectedValueFromInput(target)
|
|
12
|
+
} : {
|
|
13
|
+
'text/plain': String(target.ownerDocument.getSelection())
|
|
14
|
+
};
|
|
15
|
+
const dt = DataTransfer.createDataTransfer(getWindow.getWindow(target));
|
|
16
|
+
for(const type in data){
|
|
17
|
+
if (data[type]) {
|
|
18
|
+
dt.setData(type, data[type]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return dt;
|
|
22
|
+
}
|
|
23
|
+
function readSelectedValueFromInput(target) {
|
|
24
|
+
const sel = UI.getUISelection(target);
|
|
25
|
+
const val = UI.getUIValue(target);
|
|
26
|
+
return val.substring(sel.startOffset, sel.endOffset);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.copySelection = copySelection;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
4
|
+
var isContentEditable = require('../utils/edit/isContentEditable.js');
|
|
5
|
+
var UI = require('./UI.js');
|
|
6
|
+
|
|
7
|
+
function getValueOrTextContent(element) {
|
|
8
|
+
// istanbul ignore if
|
|
9
|
+
if (!element) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (isContentEditable.isContentEditable(element)) {
|
|
13
|
+
return element.textContent;
|
|
14
|
+
}
|
|
15
|
+
return UI.getUIValue(element);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.getValueOrTextContent = getValueOrTextContent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var UI = require('./UI.js');
|
|
4
|
+
var getValueOrTextContent = require('./getValueOrTextContent.js');
|
|
5
|
+
var copySelection = require('./copySelection.js');
|
|
6
|
+
var trackValue = require('./trackValue.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.clearInitialValue = UI.clearInitialValue;
|
|
11
|
+
exports.getUISelection = UI.getUISelection;
|
|
12
|
+
exports.getUIValue = UI.getUIValue;
|
|
13
|
+
exports.setUISelection = UI.setUISelection;
|
|
14
|
+
exports.setUIValue = UI.setUIValue;
|
|
15
|
+
exports.getValueOrTextContent = getValueOrTextContent.getValueOrTextContent;
|
|
16
|
+
exports.copySelection = copySelection.copySelection;
|
|
17
|
+
exports.commitValueAfterInput = trackValue.commitValueAfterInput;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isElementType = require('../utils/misc/isElementType.js');
|
|
4
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
+
var trackValue = require('./trackValue.js');
|
|
6
|
+
var UI = require('./UI.js');
|
|
7
|
+
|
|
8
|
+
const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
9
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
10
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
11
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
12
|
+
const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
|
|
13
|
+
/* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
14
|
+
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
15
|
+
}
|
|
16
|
+
function intercept(...args) {
|
|
17
|
+
const { applyNative = false, realArgs, then } = interceptorImpl.call(this, ...args);
|
|
18
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
19
|
+
if (target === 'set') {
|
|
20
|
+
realFunc.call(this, realArgs);
|
|
21
|
+
} else {
|
|
22
|
+
realFunc.call(this, ...realArgs);
|
|
23
|
+
}
|
|
24
|
+
then === null || then === void 0 ? void 0 : then();
|
|
25
|
+
}
|
|
26
|
+
intercept[Interceptor] = Interceptor;
|
|
27
|
+
Object.defineProperty(element, propName, {
|
|
28
|
+
...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
|
|
29
|
+
[target]: intercept
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function prepareValueInterceptor(element) {
|
|
33
|
+
prepareInterceptor(element, 'value', function interceptorImpl(v) {
|
|
34
|
+
const isUI = UI.isUIValue(v);
|
|
35
|
+
if (isUI) {
|
|
36
|
+
trackValue.startTrackValue(this);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
applyNative: !!isUI,
|
|
40
|
+
realArgs: sanitizeValue(this, v),
|
|
41
|
+
then: isUI ? undefined : ()=>trackValue.trackOrSetValue(this, String(v))
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function sanitizeValue(element, v) {
|
|
46
|
+
// Workaround for JSDOM
|
|
47
|
+
if (isElementType.isElementType(element, 'input', {
|
|
48
|
+
type: 'number'
|
|
49
|
+
}) && String(v) !== '' && !Number.isNaN(Number(v))) {
|
|
50
|
+
// Setting value to "1." results in `null` in JSDOM
|
|
51
|
+
return String(Number(v));
|
|
52
|
+
}
|
|
53
|
+
return String(v);
|
|
54
|
+
}
|
|
55
|
+
function prepareSelectionInterceptor(element) {
|
|
56
|
+
prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
|
|
57
|
+
const isUI = UI.isUISelectionStart(start);
|
|
58
|
+
return {
|
|
59
|
+
applyNative: !!isUI,
|
|
60
|
+
realArgs: [
|
|
61
|
+
Number(start),
|
|
62
|
+
...others
|
|
63
|
+
],
|
|
64
|
+
then: ()=>isUI ? undefined : UI.setUISelectionClean(element)
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
prepareInterceptor(element, 'selectionStart', function interceptorImpl(v) {
|
|
68
|
+
return {
|
|
69
|
+
realArgs: v,
|
|
70
|
+
then: ()=>UI.setUISelectionClean(element)
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
prepareInterceptor(element, 'selectionEnd', function interceptorImpl(v) {
|
|
74
|
+
return {
|
|
75
|
+
realArgs: v,
|
|
76
|
+
then: ()=>UI.setUISelectionClean(element)
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
prepareInterceptor(element, 'select', function interceptorImpl() {
|
|
80
|
+
return {
|
|
81
|
+
realArgs: [],
|
|
82
|
+
then: ()=>UI.setUISelectionRaw(element, {
|
|
83
|
+
anchorOffset: 0,
|
|
84
|
+
focusOffset: UI.getUIValue(element).length
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function prepareRangeTextInterceptor(element) {
|
|
90
|
+
prepareInterceptor(element, 'setRangeText', function interceptorImpl(...realArgs) {
|
|
91
|
+
return {
|
|
92
|
+
realArgs,
|
|
93
|
+
then: ()=>{
|
|
94
|
+
UI.setUIValueClean(element);
|
|
95
|
+
UI.setUISelectionClean(element);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
exports.prepareInterceptor = prepareInterceptor;
|
|
102
|
+
exports.prepareRangeTextInterceptor = prepareRangeTextInterceptor;
|
|
103
|
+
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
104
|
+
exports.prepareValueInterceptor = prepareValueInterceptor;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dispatchEvent = require('../event/dispatchEvent.js');
|
|
4
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
+
var getActiveElement = require('../utils/focus/getActiveElement.js');
|
|
6
|
+
require('@testing-library/dom');
|
|
7
|
+
|
|
8
|
+
const patched = Symbol('patched focus/blur methods');
|
|
9
|
+
function patchFocus(HTMLElement) {
|
|
10
|
+
if (HTMLElement.prototype[patched]) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
14
|
+
const { focus, blur } = HTMLElement.prototype;
|
|
15
|
+
Object.defineProperties(HTMLElement.prototype, {
|
|
16
|
+
focus: {
|
|
17
|
+
configurable: true,
|
|
18
|
+
value: patchedFocus,
|
|
19
|
+
writable: true
|
|
20
|
+
},
|
|
21
|
+
blur: {
|
|
22
|
+
configurable: true,
|
|
23
|
+
value: patchedBlur,
|
|
24
|
+
writable: true
|
|
25
|
+
},
|
|
26
|
+
[patched]: {
|
|
27
|
+
configurable: true,
|
|
28
|
+
get: ()=>({
|
|
29
|
+
focus,
|
|
30
|
+
blur
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
let activeCall;
|
|
35
|
+
function patchedFocus(options) {
|
|
36
|
+
if (this.ownerDocument.visibilityState !== 'hidden') {
|
|
37
|
+
return focus.call(this, options);
|
|
38
|
+
}
|
|
39
|
+
const blurred = getActiveTarget(this.ownerDocument);
|
|
40
|
+
if (blurred === this) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const thisCall = Symbol('focus call');
|
|
44
|
+
activeCall = thisCall;
|
|
45
|
+
if (blurred) {
|
|
46
|
+
blur.call(blurred);
|
|
47
|
+
dispatchEvent.dispatchDOMEvent(blurred, 'blur', {
|
|
48
|
+
relatedTarget: this
|
|
49
|
+
});
|
|
50
|
+
dispatchEvent.dispatchDOMEvent(blurred, 'focusout', {
|
|
51
|
+
relatedTarget: activeCall === thisCall ? this : null
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (activeCall === thisCall) {
|
|
55
|
+
focus.call(this, options);
|
|
56
|
+
dispatchEvent.dispatchDOMEvent(this, 'focus', {
|
|
57
|
+
relatedTarget: blurred
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (activeCall === thisCall) {
|
|
61
|
+
dispatchEvent.dispatchDOMEvent(this, 'focusin', {
|
|
62
|
+
relatedTarget: blurred
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function patchedBlur() {
|
|
67
|
+
if (this.ownerDocument.visibilityState !== 'hidden') {
|
|
68
|
+
return blur.call(this);
|
|
69
|
+
}
|
|
70
|
+
const blurred = getActiveTarget(this.ownerDocument);
|
|
71
|
+
if (blurred !== this) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const thisCall = Symbol('blur call');
|
|
75
|
+
activeCall = thisCall;
|
|
76
|
+
blur.call(this);
|
|
77
|
+
dispatchEvent.dispatchDOMEvent(blurred, 'blur', {
|
|
78
|
+
relatedTarget: null
|
|
79
|
+
});
|
|
80
|
+
dispatchEvent.dispatchDOMEvent(blurred, 'focusout', {
|
|
81
|
+
relatedTarget: null
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function getActiveTarget(document) {
|
|
86
|
+
const active = getActiveElement.getActiveElement(document);
|
|
87
|
+
return (active === null || active === void 0 ? void 0 : active.tagName) === 'BODY' ? null : active;
|
|
88
|
+
}
|
|
89
|
+
function restoreFocus(HTMLElement) {
|
|
90
|
+
if (HTMLElement.prototype[patched]) {
|
|
91
|
+
const { focus, blur } = HTMLElement.prototype[patched];
|
|
92
|
+
Object.defineProperties(HTMLElement.prototype, {
|
|
93
|
+
focus: {
|
|
94
|
+
configurable: true,
|
|
95
|
+
get: ()=>focus
|
|
96
|
+
},
|
|
97
|
+
blur: {
|
|
98
|
+
configurable: true,
|
|
99
|
+
get: ()=>blur
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.patchFocus = patchFocus;
|
|
106
|
+
exports.restoreFocus = restoreFocus;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dispatchEvent = require('../event/dispatchEvent.js');
|
|
4
|
+
var isElementType = require('../utils/misc/isElementType.js');
|
|
5
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
6
|
+
var UI = require('./UI.js');
|
|
7
|
+
require('@testing-library/dom');
|
|
8
|
+
var interceptor = require('./interceptor.js');
|
|
9
|
+
|
|
10
|
+
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
11
|
+
function prepareDocument(document) {
|
|
12
|
+
if (document[isPrepared]) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
document.addEventListener('focus', (e)=>{
|
|
16
|
+
const el = e.target;
|
|
17
|
+
prepareElement(el);
|
|
18
|
+
}, {
|
|
19
|
+
capture: true,
|
|
20
|
+
passive: true
|
|
21
|
+
});
|
|
22
|
+
// Our test environment defaults to `document.body` as `activeElement`.
|
|
23
|
+
// In other environments this might be `null` when preparing.
|
|
24
|
+
// istanbul ignore else
|
|
25
|
+
if (document.activeElement) {
|
|
26
|
+
prepareElement(document.activeElement);
|
|
27
|
+
}
|
|
28
|
+
document.addEventListener('blur', (e)=>{
|
|
29
|
+
const el = e.target;
|
|
30
|
+
const initialValue = UI.getInitialValue(el);
|
|
31
|
+
if (initialValue !== undefined) {
|
|
32
|
+
if (el.value !== initialValue) {
|
|
33
|
+
dispatchEvent.dispatchDOMEvent(el, 'change');
|
|
34
|
+
}
|
|
35
|
+
UI.clearInitialValue(el);
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
capture: true,
|
|
39
|
+
passive: true
|
|
40
|
+
});
|
|
41
|
+
document[isPrepared] = isPrepared;
|
|
42
|
+
}
|
|
43
|
+
function prepareElement(el) {
|
|
44
|
+
if (el[isPrepared]) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (isElementType.isElementType(el, [
|
|
48
|
+
'input',
|
|
49
|
+
'textarea'
|
|
50
|
+
])) {
|
|
51
|
+
interceptor.prepareValueInterceptor(el);
|
|
52
|
+
interceptor.prepareSelectionInterceptor(el);
|
|
53
|
+
interceptor.prepareRangeTextInterceptor(el);
|
|
54
|
+
}
|
|
55
|
+
el[isPrepared] = isPrepared;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.prepareDocument = prepareDocument;
|