@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,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,76 +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
|
-
var
|
|
29
|
-
var
|
|
30
|
-
return (
|
|
23
|
+
behavior.keydown = (event, target, instance)=>{
|
|
24
|
+
var _keydownBehavior_event_key, _keydownBehavior;
|
|
25
|
+
var _keydownBehavior_event_key1;
|
|
26
|
+
return (_keydownBehavior_event_key1 = (_keydownBehavior_event_key = (_keydownBehavior = keydownBehavior)[event.key]) === null || _keydownBehavior_event_key === void 0 ? void 0 : _keydownBehavior_event_key.call(_keydownBehavior, event, target, instance)) !== null && _keydownBehavior_event_key1 !== void 0 ? _keydownBehavior_event_key1 : combinationBehavior(event, target, instance);
|
|
31
27
|
};
|
|
32
28
|
const keydownBehavior = {
|
|
33
|
-
ArrowDown: (event, target,
|
|
29
|
+
ArrowDown: (event, target, instance)=>{
|
|
34
30
|
/* istanbul ignore else */ if (isElementType(target, 'input', {
|
|
35
31
|
type: 'radio'
|
|
36
32
|
})) {
|
|
37
|
-
return ()=>walkRadio(
|
|
33
|
+
return ()=>walkRadio(instance, target, -1);
|
|
38
34
|
}
|
|
39
35
|
},
|
|
40
|
-
ArrowLeft: (event, target,
|
|
36
|
+
ArrowLeft: (event, target, instance)=>{
|
|
41
37
|
if (isElementType(target, 'input', {
|
|
42
38
|
type: 'radio'
|
|
43
39
|
})) {
|
|
44
|
-
return ()=>walkRadio(
|
|
40
|
+
return ()=>walkRadio(instance, target, -1);
|
|
45
41
|
}
|
|
46
42
|
return ()=>moveSelection(target, -1);
|
|
47
43
|
},
|
|
48
|
-
ArrowRight: (event, target,
|
|
44
|
+
ArrowRight: (event, target, instance)=>{
|
|
49
45
|
if (isElementType(target, 'input', {
|
|
50
46
|
type: 'radio'
|
|
51
47
|
})) {
|
|
52
|
-
return ()=>walkRadio(
|
|
48
|
+
return ()=>walkRadio(instance, target, 1);
|
|
53
49
|
}
|
|
54
50
|
return ()=>moveSelection(target, 1);
|
|
55
51
|
},
|
|
56
|
-
ArrowUp: (event, target,
|
|
52
|
+
ArrowUp: (event, target, instance)=>{
|
|
57
53
|
/* istanbul ignore else */ if (isElementType(target, 'input', {
|
|
58
54
|
type: 'radio'
|
|
59
55
|
})) {
|
|
60
|
-
return ()=>walkRadio(
|
|
56
|
+
return ()=>walkRadio(instance, target, 1);
|
|
61
57
|
}
|
|
62
58
|
},
|
|
63
|
-
Backspace: (event, target,
|
|
59
|
+
Backspace: (event, target, instance)=>{
|
|
64
60
|
if (isEditable(target)) {
|
|
65
61
|
return ()=>{
|
|
66
|
-
input(
|
|
62
|
+
input(instance, target, '', 'deleteContentBackward');
|
|
67
63
|
};
|
|
68
64
|
}
|
|
69
65
|
},
|
|
70
|
-
Delete: (event, target,
|
|
66
|
+
Delete: (event, target, instance)=>{
|
|
71
67
|
if (isEditable(target)) {
|
|
72
68
|
return ()=>{
|
|
73
|
-
input(
|
|
69
|
+
input(instance, target, '', 'deleteContentForward');
|
|
74
70
|
};
|
|
75
71
|
}
|
|
76
72
|
},
|
|
@@ -80,9 +76,9 @@ const keydownBehavior = {
|
|
|
80
76
|
'textarea'
|
|
81
77
|
]) || isContentEditable(target)) {
|
|
82
78
|
return ()=>{
|
|
83
|
-
var
|
|
84
|
-
var
|
|
85
|
-
const newPos = (
|
|
79
|
+
var _getValueOrTextContent;
|
|
80
|
+
var _getValueOrTextContent_length;
|
|
81
|
+
const newPos = (_getValueOrTextContent_length = (_getValueOrTextContent = getValueOrTextContent(target)) === null || _getValueOrTextContent === void 0 ? void 0 : _getValueOrTextContent.length) !== null && _getValueOrTextContent_length !== void 0 ? _getValueOrTextContent_length : /* istanbul ignore next */ 0;
|
|
86
82
|
setSelectionRange(target, newPos, newPos);
|
|
87
83
|
};
|
|
88
84
|
}
|
|
@@ -102,7 +98,7 @@ const keydownBehavior = {
|
|
|
102
98
|
'input'
|
|
103
99
|
])) {
|
|
104
100
|
return ()=>{
|
|
105
|
-
const newPos =
|
|
101
|
+
const newPos = getUIValue(target).length;
|
|
106
102
|
setSelectionRange(target, newPos, newPos);
|
|
107
103
|
};
|
|
108
104
|
}
|
|
@@ -116,10 +112,10 @@ const keydownBehavior = {
|
|
|
116
112
|
};
|
|
117
113
|
}
|
|
118
114
|
},
|
|
119
|
-
Tab: (event, target,
|
|
115
|
+
Tab: (event, target, instance)=>{
|
|
120
116
|
return ()=>{
|
|
121
|
-
const dest = getTabDestination(target,
|
|
122
|
-
|
|
117
|
+
const dest = getTabDestination(target, instance.system.keyboard.modifiers.Shift);
|
|
118
|
+
focusElement(dest);
|
|
123
119
|
if (hasOwnSelection(dest)) {
|
|
124
120
|
setUISelection(dest, {
|
|
125
121
|
anchorOffset: 0,
|
|
@@ -129,8 +125,8 @@ const keydownBehavior = {
|
|
|
129
125
|
};
|
|
130
126
|
}
|
|
131
127
|
};
|
|
132
|
-
const combinationBehavior = (event, target,
|
|
133
|
-
if (event.code === 'KeyA' &&
|
|
128
|
+
const combinationBehavior = (event, target, instance)=>{
|
|
129
|
+
if (event.code === 'KeyA' && instance.system.keyboard.modifiers.Control) {
|
|
134
130
|
return ()=>selectAll(target);
|
|
135
131
|
}
|
|
136
132
|
};
|
|
@@ -1,39 +1,39 @@
|
|
|
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')) {
|
|
21
|
+
var _form;
|
|
22
22
|
const form = target.form;
|
|
23
|
-
const submit = form === null ||
|
|
23
|
+
const submit = (_form = form) === null || _form === void 0 ? void 0 : _form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
24
24
|
if (submit) {
|
|
25
|
-
return ()=>dispatchUIEvent(
|
|
25
|
+
return ()=>instance.dispatchUIEvent(submit, 'click');
|
|
26
26
|
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
|
|
27
|
-
return ()=>dispatchUIEvent(
|
|
27
|
+
return ()=>instance.dispatchUIEvent(form, 'submit');
|
|
28
28
|
} else {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
if (isEditable(target)) {
|
|
34
|
-
const inputType = event.key === 'Enter' ? isContentEditable(target) && !
|
|
34
|
+
const inputType = event.key === 'Enter' ? isContentEditable(target) && !instance.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText';
|
|
35
35
|
const inputData = event.key === 'Enter' ? '\n' : event.key;
|
|
36
|
-
return ()=>input(
|
|
36
|
+
return ()=>input(instance, target, inputData, inputType);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
const ClickInputOnEnter = [
|
|
@@ -42,7 +42,7 @@ const ClickInputOnEnter = [
|
|
|
42
42
|
'file',
|
|
43
43
|
'image',
|
|
44
44
|
'reset',
|
|
45
|
-
'submit'
|
|
45
|
+
'submit'
|
|
46
46
|
];
|
|
47
47
|
const SubmitSingleInputOnEnter = [
|
|
48
48
|
'email',
|
|
@@ -52,5 +52,5 @@ const SubmitSingleInputOnEnter = [
|
|
|
52
52
|
'tel',
|
|
53
53
|
'text',
|
|
54
54
|
'url',
|
|
55
|
-
'week'
|
|
55
|
+
'week'
|
|
56
56
|
];
|
|
@@ -1,23 +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
|
-
var
|
|
15
|
-
return (
|
|
11
|
+
behavior.keyup = (event, target, instance)=>{
|
|
12
|
+
var _keyupBehavior_event_key, _keyupBehavior;
|
|
13
|
+
return (_keyupBehavior_event_key = (_keyupBehavior = keyupBehavior)[event.key]) === null || _keyupBehavior_event_key === void 0 ? void 0 : _keyupBehavior_event_key.call(_keyupBehavior, event, target, instance);
|
|
16
14
|
};
|
|
17
15
|
const keyupBehavior = {
|
|
18
|
-
' ': (event, target,
|
|
16
|
+
' ': (event, target, instance)=>{
|
|
19
17
|
if (isClickableInput(target)) {
|
|
20
|
-
return ()=>dispatchUIEvent(
|
|
18
|
+
return ()=>instance.dispatchUIEvent(target, 'click');
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
};
|
|
@@ -1,27 +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
|
-
var
|
|
22
|
-
const insertData = (
|
|
15
|
+
var _event_clipboardData;
|
|
16
|
+
const insertData = (_event_clipboardData = event.clipboardData) === null || _event_clipboardData === void 0 ? void 0 : _event_clipboardData.getData('text');
|
|
23
17
|
if (insertData) {
|
|
24
|
-
input(
|
|
18
|
+
input(instance, target, insertData, 'insertFromPaste');
|
|
25
19
|
}
|
|
26
20
|
};
|
|
27
21
|
}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import '../utils/click/isClickableInput.js';
|
|
2
2
|
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
-
import './behavior/click.js';
|
|
4
|
-
import './behavior/cut.js';
|
|
5
|
-
import './behavior/keydown.js';
|
|
6
|
-
import './behavior/keypress.js';
|
|
7
|
-
import './behavior/keyup.js';
|
|
8
|
-
import './behavior/paste.js';
|
|
9
|
-
import '@testing-library/dom';
|
|
10
|
-
import { eventMap, eventMapKeys } from './eventMap.js';
|
|
11
|
-
import '../utils/edit/maxLength.js';
|
|
12
3
|
import '../utils/edit/isEditable.js';
|
|
4
|
+
import '../utils/edit/maxLength.js';
|
|
13
5
|
import { getWindow } from '../utils/misc/getWindow.js';
|
|
14
6
|
import '../utils/keyDef/readNextDescriptor.js';
|
|
15
7
|
import '../utils/misc/level.js';
|
|
16
8
|
import '../options.js';
|
|
9
|
+
import { eventMap, eventMapKeys } from './eventMap.js';
|
|
17
10
|
|
|
18
11
|
const eventInitializer = {
|
|
19
12
|
ClipboardEvent: [
|
|
@@ -32,7 +25,7 @@ const eventInitializer = {
|
|
|
32
25
|
initUIEvent,
|
|
33
26
|
initUIEventModififiers,
|
|
34
27
|
initMouseEvent,
|
|
35
|
-
initPointerEvent
|
|
28
|
+
initPointerEvent
|
|
36
29
|
],
|
|
37
30
|
KeyboardEvent: [
|
|
38
31
|
initUIEvent,
|
|
@@ -41,58 +34,58 @@ const eventInitializer = {
|
|
|
41
34
|
]
|
|
42
35
|
};
|
|
43
36
|
function createEvent(type, target, init) {
|
|
44
|
-
var
|
|
37
|
+
var _eventInitializer_EventType;
|
|
45
38
|
const window = getWindow(target);
|
|
46
|
-
const { EventType
|
|
39
|
+
const { EventType, defaultInit } = eventMap[eventMapKeys[type]];
|
|
47
40
|
const event = new (getEventConstructors(window))[EventType](type, defaultInit);
|
|
48
|
-
(
|
|
41
|
+
(_eventInitializer_EventType = eventInitializer[EventType]) === null || _eventInitializer_EventType === void 0 ? void 0 : _eventInitializer_EventType.forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
|
|
49
42
|
return event;
|
|
50
43
|
}
|
|
51
44
|
/* istanbul ignore next */ function getEventConstructors(window) {
|
|
52
|
-
var
|
|
53
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (
|
|
45
|
+
var _window_Event;
|
|
46
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_window_Event = window.Event) !== null && _window_Event !== void 0 ? _window_Event : class Event {
|
|
54
47
|
};
|
|
55
|
-
var
|
|
56
|
-
const AnimationEvent = (
|
|
48
|
+
var _window_AnimationEvent;
|
|
49
|
+
const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !== void 0 ? _window_AnimationEvent : class AnimationEvent extends Event {
|
|
57
50
|
};
|
|
58
|
-
var
|
|
59
|
-
const ClipboardEvent = (
|
|
51
|
+
var _window_ClipboardEvent;
|
|
52
|
+
const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !== void 0 ? _window_ClipboardEvent : class ClipboardEvent extends Event {
|
|
60
53
|
};
|
|
61
|
-
var
|
|
62
|
-
const PopStateEvent = (
|
|
54
|
+
var _window_PopStateEvent;
|
|
55
|
+
const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !== void 0 ? _window_PopStateEvent : class PopStateEvent extends Event {
|
|
63
56
|
};
|
|
64
|
-
var
|
|
65
|
-
const ProgressEvent = (
|
|
57
|
+
var _window_ProgressEvent;
|
|
58
|
+
const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !== void 0 ? _window_ProgressEvent : class ProgressEvent extends Event {
|
|
66
59
|
};
|
|
67
|
-
var
|
|
68
|
-
const TransitionEvent = (
|
|
60
|
+
var _window_TransitionEvent;
|
|
61
|
+
const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !== void 0 ? _window_TransitionEvent : class TransitionEvent extends Event {
|
|
69
62
|
};
|
|
70
|
-
var
|
|
71
|
-
const UIEvent = (
|
|
63
|
+
var _window_UIEvent;
|
|
64
|
+
const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !== void 0 ? _window_UIEvent : class UIEvent extends Event {
|
|
72
65
|
};
|
|
73
|
-
var
|
|
74
|
-
const CompositionEvent = (
|
|
66
|
+
var _window_CompositionEvent;
|
|
67
|
+
const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !== void 0 ? _window_CompositionEvent : class CompositionEvent extends UIEvent {
|
|
75
68
|
};
|
|
76
|
-
var
|
|
77
|
-
const FocusEvent = (
|
|
69
|
+
var _window_FocusEvent;
|
|
70
|
+
const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !== void 0 ? _window_FocusEvent : class FocusEvent extends UIEvent {
|
|
78
71
|
};
|
|
79
|
-
var
|
|
80
|
-
const InputEvent = (
|
|
72
|
+
var _window_InputEvent;
|
|
73
|
+
const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !== void 0 ? _window_InputEvent : class InputEvent extends UIEvent {
|
|
81
74
|
};
|
|
82
|
-
var
|
|
83
|
-
const KeyboardEvent = (
|
|
75
|
+
var _window_KeyboardEvent;
|
|
76
|
+
const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !== void 0 ? _window_KeyboardEvent : class KeyboardEvent extends UIEvent {
|
|
84
77
|
};
|
|
85
|
-
var
|
|
86
|
-
const MouseEvent = (
|
|
78
|
+
var _window_MouseEvent;
|
|
79
|
+
const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !== void 0 ? _window_MouseEvent : class MouseEvent extends UIEvent {
|
|
87
80
|
};
|
|
88
|
-
var
|
|
89
|
-
const DragEvent = (
|
|
81
|
+
var _window_DragEvent;
|
|
82
|
+
const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !== void 0 ? _window_DragEvent : class DragEvent extends MouseEvent {
|
|
90
83
|
};
|
|
91
|
-
var
|
|
92
|
-
const PointerEvent = (
|
|
84
|
+
var _window_PointerEvent;
|
|
85
|
+
const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !== void 0 ? _window_PointerEvent : class PointerEvent extends MouseEvent {
|
|
93
86
|
};
|
|
94
|
-
var
|
|
95
|
-
const TouchEvent = (
|
|
87
|
+
var _window_TouchEvent;
|
|
88
|
+
const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !== void 0 ? _window_TouchEvent : class TouchEvent extends UIEvent {
|
|
96
89
|
};
|
|
97
90
|
/* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
|
|
98
91
|
Event,
|
|
@@ -122,25 +115,25 @@ function assignProps(obj, props) {
|
|
|
122
115
|
function sanitizeNumber(n) {
|
|
123
116
|
return Number(n !== null && n !== void 0 ? n : 0);
|
|
124
117
|
}
|
|
125
|
-
function initClipboardEvent(event, { clipboardData
|
|
118
|
+
function initClipboardEvent(event, { clipboardData }) {
|
|
126
119
|
assignProps(event, {
|
|
127
120
|
clipboardData
|
|
128
121
|
});
|
|
129
122
|
}
|
|
130
|
-
function initInputEvent(event, { data
|
|
123
|
+
function initInputEvent(event, { data, inputType, isComposing }) {
|
|
131
124
|
assignProps(event, {
|
|
132
125
|
data,
|
|
133
126
|
isComposing: Boolean(isComposing),
|
|
134
127
|
inputType: String(inputType)
|
|
135
128
|
});
|
|
136
129
|
}
|
|
137
|
-
function initUIEvent(event, { view
|
|
130
|
+
function initUIEvent(event, { view, detail }) {
|
|
138
131
|
assignProps(event, {
|
|
139
132
|
view,
|
|
140
133
|
detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
|
|
141
134
|
});
|
|
142
135
|
}
|
|
143
|
-
function initUIEventModififiers(event, { altKey
|
|
136
|
+
function initUIEventModififiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
|
|
144
137
|
assignProps(event, {
|
|
145
138
|
altKey: Boolean(altKey),
|
|
146
139
|
ctrlKey: Boolean(ctrlKey),
|
|
@@ -164,7 +157,7 @@ function initUIEventModififiers(event, { altKey , ctrlKey , metaKey , shiftKey ,
|
|
|
164
157
|
}
|
|
165
158
|
});
|
|
166
159
|
}
|
|
167
|
-
function initKeyboardEvent(event, { key
|
|
160
|
+
function initKeyboardEvent(event, { key, code, location, repeat, isComposing, charCode }) {
|
|
168
161
|
assignProps(event, {
|
|
169
162
|
key: String(key),
|
|
170
163
|
code: String(code),
|
|
@@ -174,7 +167,7 @@ function initKeyboardEvent(event, { key , code , location , repeat , isComposing
|
|
|
174
167
|
charCode
|
|
175
168
|
});
|
|
176
169
|
}
|
|
177
|
-
function initMouseEvent(event, { x
|
|
170
|
+
function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY = y, button, buttons, relatedTarget }) {
|
|
178
171
|
assignProps(event, {
|
|
179
172
|
screenX: sanitizeNumber(screenX),
|
|
180
173
|
screenY: sanitizeNumber(screenY),
|
|
@@ -187,7 +180,7 @@ function initMouseEvent(event, { x , y , screenX , screenY , clientX =x , client
|
|
|
187
180
|
relatedTarget
|
|
188
181
|
});
|
|
189
182
|
}
|
|
190
|
-
function initPointerEvent(event, { pointerId
|
|
183
|
+
function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary }) {
|
|
191
184
|
assignProps(event, {
|
|
192
185
|
pointerId: sanitizeNumber(pointerId),
|
|
193
186
|
width: sanitizeNumber(width),
|
|
@@ -6,11 +6,23 @@ import './behavior/keyup.js';
|
|
|
6
6
|
import './behavior/paste.js';
|
|
7
7
|
import { behavior } from './behavior/registry.js';
|
|
8
8
|
import { wrapEvent } from './wrapEvent.js';
|
|
9
|
+
import { isMouseEvent, isKeyboardEvent } from './eventMap.js';
|
|
10
|
+
import { createEvent } from './createEvent.js';
|
|
9
11
|
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
+
function dispatchUIEvent(target, type, init, preventDefault = false) {
|
|
13
|
+
if (isMouseEvent(type) || isKeyboardEvent(type)) {
|
|
14
|
+
init = {
|
|
15
|
+
...init,
|
|
16
|
+
...this.system.getUIEventModifiers()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const event = createEvent(type, target, init);
|
|
20
|
+
return dispatchEvent.call(this, target, event, preventDefault);
|
|
21
|
+
}
|
|
22
|
+
function dispatchEvent(target, event, preventDefault = false) {
|
|
23
|
+
var _behavior_type, _behavior;
|
|
12
24
|
const type = event.type;
|
|
13
|
-
const behaviorImplementation = preventDefault ? ()=>{} : (
|
|
25
|
+
const behaviorImplementation = preventDefault ? ()=>{} : (_behavior_type = (_behavior = behavior)[type]) === null || _behavior_type === void 0 ? void 0 : _behavior_type.call(_behavior, event, target, this);
|
|
14
26
|
if (behaviorImplementation) {
|
|
15
27
|
event.preventDefault();
|
|
16
28
|
let defaultPrevented = false;
|
|
@@ -30,5 +42,9 @@ function dispatchEvent(config, target, event, preventDefault = false) {
|
|
|
30
42
|
}
|
|
31
43
|
return wrapEvent(()=>target.dispatchEvent(event));
|
|
32
44
|
}
|
|
45
|
+
function dispatchDOMEvent(target, type, init) {
|
|
46
|
+
const event = createEvent(type, target, init);
|
|
47
|
+
wrapEvent(()=>target.dispatchEvent(event));
|
|
48
|
+
}
|
|
33
49
|
|
|
34
|
-
export { dispatchEvent };
|
|
50
|
+
export { dispatchDOMEvent, dispatchEvent, dispatchUIEvent };
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { getActiveElement } from '../utils/focus/getActiveElement.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import { isFocusable } from '../utils/focus/isFocusable.js';
|
|
8
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import { findClosest } from '../utils/misc/findClosest.js';
|
|
10
|
+
import '../utils/misc/level.js';
|
|
11
|
+
import '../options.js';
|
|
12
|
+
import { updateSelectionOnFocus } from './selection/updateSelectionOnFocus.js';
|
|
13
|
+
import { wrapEvent } from './wrapEvent.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Focus closest focusable element.
|
|
17
|
+
*/ function focusElement(element) {
|
|
18
|
+
const target = findClosest(element, isFocusable);
|
|
19
|
+
const activeElement = getActiveElement(element.ownerDocument);
|
|
20
|
+
if ((target !== null && target !== void 0 ? target : element.ownerDocument.body) === activeElement) {
|
|
21
|
+
return;
|
|
22
|
+
} else if (target) {
|
|
23
|
+
wrapEvent(()=>target.focus());
|
|
24
|
+
} else {
|
|
25
|
+
wrapEvent(()=>{
|
|
26
|
+
var _activeElement;
|
|
27
|
+
return (_activeElement = activeElement) === null || _activeElement === void 0 ? void 0 : _activeElement.blur();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body);
|
|
31
|
+
}
|
|
32
|
+
function blurElement(element) {
|
|
33
|
+
if (!isFocusable(element)) return;
|
|
34
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
35
|
+
if (!wasActive) return;
|
|
36
|
+
wrapEvent(()=>element.blur());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { blurElement, focusElement };
|