@testing-library/user-event 14.3.0 → 14.4.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/clipboard/copy.js +40 -0
- package/dist/cjs/clipboard/cut.js +40 -0
- package/dist/cjs/clipboard/index.js +13 -0
- package/dist/cjs/clipboard/paste.js +41 -0
- package/dist/cjs/convenience/click.js +40 -0
- package/dist/cjs/convenience/hover.js +37 -0
- package/dist/cjs/convenience/index.js +16 -0
- package/dist/cjs/convenience/tab.js +9 -0
- package/dist/cjs/document/index.js +74 -0
- package/dist/cjs/document/interceptor.js +30 -0
- package/dist/cjs/document/selection.js +107 -0
- package/dist/cjs/document/setRangeText.js +21 -0
- package/dist/cjs/document/value.js +125 -0
- package/dist/cjs/event/behavior/click.js +42 -0
- package/dist/cjs/event/behavior/cut.js +26 -0
- package/dist/cjs/event/behavior/index.js +15 -0
- package/dist/cjs/event/behavior/keydown.js +134 -0
- package/dist/cjs/event/behavior/keypress.js +58 -0
- package/dist/cjs/event/behavior/keyup.js +24 -0
- package/dist/cjs/event/behavior/paste.js +29 -0
- package/dist/cjs/event/behavior/registry.js +7 -0
- package/dist/cjs/event/createEvent.js +193 -0
- package/dist/cjs/event/dispatchEvent.js +37 -0
- package/dist/cjs/event/dom-events.d.js +2 -0
- package/dist/cjs/event/eventMap.js +64 -0
- package/dist/cjs/event/index.js +24 -0
- package/dist/cjs/event/types.js +2 -0
- package/dist/cjs/event/wrapEvent.js +11 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/keyboard/index.js +59 -0
- package/dist/cjs/keyboard/keyMap.js +158 -0
- package/dist/cjs/keyboard/parseKeyDef.js +58 -0
- package/dist/cjs/options.js +42 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pointer/index.js +88 -0
- package/dist/cjs/pointer/keyMap.js +35 -0
- package/dist/cjs/pointer/parseKeyDef.js +39 -0
- package/dist/cjs/setup/api.js +35 -0
- package/dist/cjs/setup/config.js +7 -0
- package/dist/cjs/setup/directApi.js +77 -0
- package/dist/cjs/setup/index.js +15 -0
- package/dist/cjs/setup/setup.js +97 -0
- package/dist/cjs/setup/wrapAsync.js +13 -0
- package/dist/cjs/system/index.js +31 -0
- package/dist/cjs/system/keyboard.js +135 -0
- package/dist/cjs/system/pointer/buttons.js +71 -0
- package/dist/cjs/system/pointer/device.js +21 -0
- package/dist/cjs/system/pointer/index.js +146 -0
- package/dist/cjs/system/pointer/mouse.js +186 -0
- package/dist/cjs/system/pointer/pointer.js +114 -0
- package/dist/cjs/utility/clear.js +42 -0
- package/dist/cjs/utility/index.js +16 -0
- package/dist/cjs/utility/selectOptions.js +125 -0
- package/dist/cjs/utility/type.js +41 -0
- package/dist/cjs/utility/upload.js +72 -0
- package/dist/cjs/utils/click/isClickableInput.js +22 -0
- package/dist/cjs/utils/dataTransfer/Blob.js +18 -0
- package/dist/cjs/utils/dataTransfer/Clipboard.js +168 -0
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +124 -0
- package/dist/cjs/utils/dataTransfer/FileList.js +26 -0
- package/dist/cjs/utils/edit/buildTimeValue.js +36 -0
- package/dist/cjs/utils/edit/getValue.js +35 -0
- package/dist/cjs/utils/edit/input.js +162 -0
- package/dist/cjs/utils/edit/isContentEditable.js +20 -0
- package/dist/cjs/utils/edit/isEditable.js +35 -0
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +11 -0
- package/dist/cjs/utils/edit/maxLength.js +38 -0
- package/dist/cjs/utils/edit/setFiles.js +59 -0
- package/dist/cjs/utils/edit/walkRadio.js +28 -0
- package/dist/cjs/utils/focus/blur.js +16 -0
- package/dist/cjs/utils/focus/copySelection.js +46 -0
- package/dist/cjs/utils/focus/cursor.js +143 -0
- package/dist/cjs/utils/focus/focus.js +26 -0
- package/dist/cjs/utils/focus/getActiveElement.js +24 -0
- package/dist/cjs/utils/focus/getTabDestination.js +82 -0
- package/dist/cjs/utils/focus/isFocusable.js +11 -0
- package/dist/cjs/utils/focus/resolveCaretPosition.js +78 -0
- package/dist/cjs/utils/focus/selectAll.js +54 -0
- package/dist/cjs/utils/focus/selection.js +287 -0
- package/dist/cjs/utils/focus/selector.js +16 -0
- package/dist/cjs/utils/index.js +108 -0
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +92 -0
- package/dist/cjs/utils/misc/cloneEvent.js +9 -0
- package/dist/cjs/utils/misc/dom-helpers.d.js +2 -0
- package/dist/cjs/utils/misc/eventWrapper.js +15 -0
- package/dist/cjs/utils/misc/findClosest.js +16 -0
- package/dist/cjs/utils/misc/getDocumentFromNode.js +12 -0
- package/dist/cjs/utils/misc/getTreeDiff.js +27 -0
- package/dist/cjs/utils/misc/getWindow.js +11 -0
- package/dist/cjs/utils/misc/isDescendantOrSelf.js +16 -0
- package/dist/cjs/utils/misc/isDisabled.js +34 -0
- package/dist/cjs/utils/misc/isElementType.js +22 -0
- package/dist/cjs/utils/misc/isVisible.js +21 -0
- package/dist/cjs/utils/misc/level.js +20 -0
- package/dist/cjs/utils/misc/wait.js +16 -0
- package/dist/cjs/utils/pointer/cssPointerEvents.js +111 -0
- package/dist/esm/clipboard/copy.js +36 -0
- package/dist/esm/clipboard/cut.js +36 -0
- package/dist/esm/clipboard/index.js +3 -0
- package/dist/esm/clipboard/paste.js +37 -0
- package/dist/esm/convenience/click.js +34 -0
- package/dist/esm/convenience/hover.js +32 -0
- package/dist/esm/convenience/index.js +3 -0
- package/dist/esm/convenience/tab.js +5 -0
- package/dist/esm/document/index.js +66 -0
- package/dist/esm/document/interceptor.js +26 -0
- package/dist/esm/document/selection.js +99 -0
- package/dist/esm/document/setRangeText.js +17 -0
- package/dist/esm/document/value.js +115 -0
- package/dist/esm/event/behavior/click.js +40 -0
- package/dist/esm/event/behavior/cut.js +24 -0
- package/dist/esm/event/behavior/index.js +7 -0
- package/dist/esm/event/behavior/keydown.js +132 -0
- package/dist/esm/event/behavior/keypress.js +56 -0
- package/dist/esm/event/behavior/keyup.js +22 -0
- package/dist/esm/event/behavior/paste.js +27 -0
- package/dist/esm/event/behavior/registry.js +3 -0
- package/dist/esm/event/createEvent.js +189 -0
- package/dist/esm/event/dispatchEvent.js +33 -0
- package/dist/esm/event/dom-events.d.js +1 -0
- package/dist/esm/event/eventMap.js +57 -0
- package/dist/esm/event/index.js +19 -0
- package/dist/esm/event/types.js +1 -0
- package/dist/esm/event/wrapEvent.js +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/keyboard/index.js +54 -0
- package/dist/esm/keyboard/keyMap.js +154 -0
- package/dist/esm/keyboard/parseKeyDef.js +54 -0
- package/dist/esm/options.js +37 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pointer/index.js +84 -0
- package/dist/esm/pointer/keyMap.js +31 -0
- package/dist/esm/pointer/parseKeyDef.js +35 -0
- package/dist/esm/setup/api.js +12 -0
- package/dist/esm/setup/config.js +3 -0
- package/dist/esm/setup/directApi.js +58 -0
- package/dist/esm/setup/index.js +10 -0
- package/dist/esm/setup/setup.js +90 -0
- package/dist/esm/setup/wrapAsync.js +9 -0
- package/dist/esm/system/index.js +27 -0
- package/dist/esm/system/keyboard.js +131 -0
- package/dist/esm/system/pointer/buttons.js +63 -0
- package/dist/esm/system/pointer/device.js +17 -0
- package/dist/esm/system/pointer/index.js +141 -0
- package/dist/esm/system/pointer/mouse.js +182 -0
- package/dist/esm/system/pointer/pointer.js +110 -0
- package/dist/esm/utility/clear.js +38 -0
- package/dist/esm/utility/index.js +4 -0
- package/dist/esm/utility/selectOptions.js +120 -0
- package/dist/esm/utility/type.js +37 -0
- package/dist/esm/utility/upload.js +68 -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 +159 -0
- package/dist/esm/utils/dataTransfer/DataTransfer.js +119 -0
- package/dist/esm/utils/dataTransfer/FileList.js +22 -0
- package/dist/esm/utils/edit/buildTimeValue.js +32 -0
- package/dist/esm/utils/edit/getValue.js +31 -0
- package/dist/esm/utils/edit/input.js +158 -0
- package/dist/esm/utils/edit/isContentEditable.js +15 -0
- package/dist/esm/utils/edit/isEditable.js +30 -0
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +7 -0
- package/dist/esm/utils/edit/maxLength.js +34 -0
- package/dist/esm/utils/edit/setFiles.js +55 -0
- package/dist/esm/utils/edit/walkRadio.js +24 -0
- package/dist/esm/utils/focus/blur.js +12 -0
- package/dist/esm/utils/focus/copySelection.js +42 -0
- package/dist/esm/utils/focus/cursor.js +139 -0
- package/dist/esm/utils/focus/focus.js +22 -0
- package/dist/esm/utils/focus/getActiveElement.js +19 -0
- package/dist/esm/utils/focus/getTabDestination.js +78 -0
- package/dist/esm/utils/focus/isFocusable.js +7 -0
- package/dist/esm/utils/focus/resolveCaretPosition.js +74 -0
- package/dist/esm/utils/focus/selectAll.js +49 -0
- package/dist/esm/utils/focus/selection.js +274 -0
- package/dist/esm/utils/focus/selector.js +12 -0
- package/dist/esm/utils/index.js +36 -0
- package/dist/esm/utils/keyDef/readNextDescriptor.js +88 -0
- package/dist/esm/utils/misc/cloneEvent.js +5 -0
- package/dist/esm/utils/misc/dom-helpers.d.js +1 -0
- package/dist/esm/utils/misc/eventWrapper.js +11 -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 +7 -0
- package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
- package/dist/esm/utils/misc/isDisabled.js +30 -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 +15 -0
- package/dist/esm/utils/misc/wait.js +12 -0
- package/dist/esm/utils/pointer/cssPointerEvents.js +106 -0
- package/dist/types/event/createEvent.d.ts +2 -8
- package/dist/types/event/eventMap.d.ts +204 -181
- package/dist/types/event/index.d.ts +1 -2
- package/dist/types/event/types.d.ts +6 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/keyboard/index.d.ts +2 -6
- package/dist/types/keyboard/keyMap.d.ts +1 -1
- package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
- package/dist/types/options.d.ts +4 -4
- package/dist/types/pointer/index.d.ts +23 -5
- package/dist/types/pointer/keyMap.d.ts +1 -1
- package/dist/types/pointer/parseKeyDef.d.ts +1 -1
- package/dist/types/setup/config.d.ts +3 -7
- package/dist/types/setup/directApi.d.ts +21 -16
- package/dist/types/setup/index.d.ts +1 -2
- package/dist/types/setup/setup.d.ts +7 -1
- package/dist/types/system/index.d.ts +10 -0
- package/dist/types/system/keyboard.d.ts +53 -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 +39 -0
- package/dist/types/system/pointer/mouse.d.ts +26 -0
- package/dist/types/system/pointer/pointer.d.ts +30 -0
- package/dist/types/utils/click/isClickableInput.d.ts +15 -1
- package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
- package/dist/types/utils/focus/resolveCaretPosition.d.ts +8 -0
- package/dist/types/utils/focus/selection.d.ts +28 -1
- package/dist/types/utils/index.d.ts +2 -3
- package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
- package/package.json +9 -15
- package/dist/index.cjs +0 -3104
- package/dist/index.mjs +0 -3155
- package/dist/types/event/eventTypes.d.ts +0 -2
- package/dist/types/keyboard/keyboardAction.d.ts +0 -10
- package/dist/types/keyboard/modifiers.d.ts +0 -9
- package/dist/types/keyboard/types.d.ts +0 -73
- package/dist/types/pointer/firePointerEvents.d.ts +0 -11
- package/dist/types/pointer/pointerAction.d.ts +0 -7
- package/dist/types/pointer/pointerMove.d.ts +0 -6
- package/dist/types/pointer/pointerPress.d.ts +0 -8
- package/dist/types/pointer/resolveSelectionTarget.d.ts +0 -5
- package/dist/types/pointer/types.d.ts +0 -62
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +0 -5
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +0 -15
- package/dist/types/utils/pointer/mouseButtons.d.ts +0 -12
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
2
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import '../event/eventMap.js';
|
|
4
|
+
import '../event/behavior/click.js';
|
|
5
|
+
import '../event/behavior/cut.js';
|
|
6
|
+
import '../event/behavior/keydown.js';
|
|
7
|
+
import '../event/behavior/keypress.js';
|
|
8
|
+
import '../event/behavior/keyup.js';
|
|
9
|
+
import '../event/behavior/paste.js';
|
|
10
|
+
import '@testing-library/dom';
|
|
11
|
+
import { hasUISelection, setUISelection } from './selection.js';
|
|
12
|
+
import { prepareInterceptor } from './interceptor.js';
|
|
13
|
+
import '../utils/edit/maxLength.js';
|
|
14
|
+
import '../utils/edit/isEditable.js';
|
|
15
|
+
import { isElementType } from '../utils/misc/isElementType.js';
|
|
16
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
17
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
18
|
+
import '../utils/misc/level.js';
|
|
19
|
+
import '../options.js';
|
|
20
|
+
|
|
21
|
+
const UIValue = Symbol('Displayed value in UI');
|
|
22
|
+
const InitialValue = Symbol('Initial value to compare on blur');
|
|
23
|
+
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
24
|
+
function valueInterceptor(v) {
|
|
25
|
+
const isUI = typeof v === 'object' && v[UIValue];
|
|
26
|
+
if (isUI) {
|
|
27
|
+
this[UIValue] = String(v);
|
|
28
|
+
startTrackValue(this);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
applyNative: !!isUI,
|
|
32
|
+
realArgs: sanitizeValue(this, v),
|
|
33
|
+
then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function sanitizeValue(element, v) {
|
|
37
|
+
// Workaround for JSDOM
|
|
38
|
+
if (isElementType(element, 'input', {
|
|
39
|
+
type: 'number'
|
|
40
|
+
}) && String(v) !== '' && !Number.isNaN(Number(v))) {
|
|
41
|
+
// Setting value to "1." results in `null` in JSDOM
|
|
42
|
+
return String(Number(v));
|
|
43
|
+
}
|
|
44
|
+
return String(v);
|
|
45
|
+
}
|
|
46
|
+
function prepareValueInterceptor(element) {
|
|
47
|
+
prepareInterceptor(element, 'value', valueInterceptor);
|
|
48
|
+
}
|
|
49
|
+
function setUIValue(element, value) {
|
|
50
|
+
if (element[InitialValue] === undefined) {
|
|
51
|
+
element[InitialValue] = element.value;
|
|
52
|
+
}
|
|
53
|
+
element.value = {
|
|
54
|
+
[UIValue]: UIValue,
|
|
55
|
+
toString: ()=>value
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function getUIValue(element) {
|
|
59
|
+
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
60
|
+
}
|
|
61
|
+
/** Flag the IDL value as clean. This does not change the value.*/ function setUIValueClean(element) {
|
|
62
|
+
element[UIValue] = undefined;
|
|
63
|
+
}
|
|
64
|
+
function clearInitialValue(element) {
|
|
65
|
+
element[InitialValue] = undefined;
|
|
66
|
+
}
|
|
67
|
+
function getInitialValue(element) {
|
|
68
|
+
return element[InitialValue];
|
|
69
|
+
}
|
|
70
|
+
// When the input event happens in the browser, React executes all event handlers
|
|
71
|
+
// and if they change state of a controlled value, nothing happens.
|
|
72
|
+
// But when we trigger the event handlers in test environment with React@17,
|
|
73
|
+
// the changes are rolled back before the state update is applied.
|
|
74
|
+
// This results in a reset cursor.
|
|
75
|
+
// There might be a better way to work around if we figure out
|
|
76
|
+
// why the batched update is executed differently in our test environment.
|
|
77
|
+
function isReact17Element(element) {
|
|
78
|
+
return Object.getOwnPropertyNames(element).some((k)=>k.startsWith('__react')) && getWindow(element).REACT_VERSION === 17;
|
|
79
|
+
}
|
|
80
|
+
function startTrackValue(element) {
|
|
81
|
+
if (!isReact17Element(element)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
element[TrackChanges] = {
|
|
85
|
+
previousValue: String(element.value),
|
|
86
|
+
tracked: []
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function trackOrSetValue(element, v) {
|
|
90
|
+
element[TrackChanges]?.tracked?.push(v);
|
|
91
|
+
if (!element[TrackChanges]) {
|
|
92
|
+
setUIValueClean(element);
|
|
93
|
+
setUISelection(element, {
|
|
94
|
+
focusOffset: v.length
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function commitValueAfterInput(element, cursorOffset) {
|
|
99
|
+
const changes = element[TrackChanges];
|
|
100
|
+
element[TrackChanges] = undefined;
|
|
101
|
+
if (!changes?.tracked?.length) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
105
|
+
if (!isJustReactStateUpdate) {
|
|
106
|
+
setUIValueClean(element);
|
|
107
|
+
}
|
|
108
|
+
if (hasUISelection(element)) {
|
|
109
|
+
setUISelection(element, {
|
|
110
|
+
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { clearInitialValue, commitValueAfterInput, getInitialValue, getUIValue, prepareValueInterceptor, setUIValue, setUIValueClean };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import '../eventMap.js';
|
|
4
|
+
import { dispatchEvent } from '../dispatchEvent.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '../../utils/edit/isEditable.js';
|
|
7
|
+
import { focus } from '../../utils/focus/focus.js';
|
|
8
|
+
import { getWindow } from '../../utils/misc/getWindow.js';
|
|
9
|
+
import { isElementType } from '../../utils/misc/isElementType.js';
|
|
10
|
+
import { blur } from '../../utils/focus/blur.js';
|
|
11
|
+
import { isFocusable } from '../../utils/focus/isFocusable.js';
|
|
12
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
13
|
+
import { cloneEvent } from '../../utils/misc/cloneEvent.js';
|
|
14
|
+
import '@testing-library/dom';
|
|
15
|
+
import '../../utils/misc/level.js';
|
|
16
|
+
import '../../options.js';
|
|
17
|
+
import { behavior } from './registry.js';
|
|
18
|
+
|
|
19
|
+
behavior.click = (event, target, config)=>{
|
|
20
|
+
const context = target.closest('button,input,label,select,textarea');
|
|
21
|
+
const control = context && isElementType(context, 'label') && context.control;
|
|
22
|
+
if (control) {
|
|
23
|
+
return ()=>{
|
|
24
|
+
if (isFocusable(control)) {
|
|
25
|
+
focus(control);
|
|
26
|
+
}
|
|
27
|
+
dispatchEvent(config, control, cloneEvent(event));
|
|
28
|
+
};
|
|
29
|
+
} else if (isElementType(target, 'input', {
|
|
30
|
+
type: 'file'
|
|
31
|
+
})) {
|
|
32
|
+
return ()=>{
|
|
33
|
+
// blur fires when the file selector pops up
|
|
34
|
+
blur(target);
|
|
35
|
+
target.dispatchEvent(new (getWindow(target)).Event('fileDialog'));
|
|
36
|
+
// focus fires after the file selector has been closed
|
|
37
|
+
focus(target);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
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
|
+
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
13
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
14
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
15
|
+
import '../../utils/misc/level.js';
|
|
16
|
+
import '../../options.js';
|
|
17
|
+
|
|
18
|
+
behavior.cut = (event, target, config)=>{
|
|
19
|
+
return ()=>{
|
|
20
|
+
if (isEditable(target)) {
|
|
21
|
+
input(config, target, '', 'deleteByCut');
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { getValue } from '../../utils/edit/getValue.js';
|
|
4
|
+
import { input } from '../../utils/edit/input.js';
|
|
5
|
+
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
6
|
+
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
7
|
+
import { walkRadio } from '../../utils/edit/walkRadio.js';
|
|
8
|
+
import '@testing-library/dom';
|
|
9
|
+
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
|
+
import { getTabDestination } from '../../utils/focus/getTabDestination.js';
|
|
14
|
+
import { selectAll } from '../../utils/focus/selectAll.js';
|
|
15
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
16
|
+
import '../../utils/misc/level.js';
|
|
17
|
+
import '../../options.js';
|
|
18
|
+
import '../eventMap.js';
|
|
19
|
+
import './click.js';
|
|
20
|
+
import './cut.js';
|
|
21
|
+
import './keypress.js';
|
|
22
|
+
import './keyup.js';
|
|
23
|
+
import './paste.js';
|
|
24
|
+
import { behavior } from './registry.js';
|
|
25
|
+
import { setUISelection } from '../../document/selection.js';
|
|
26
|
+
|
|
27
|
+
behavior.keydown = (event, target, config)=>{
|
|
28
|
+
return keydownBehavior[event.key]?.(event, target, config) ?? combinationBehavior(event, target, config);
|
|
29
|
+
};
|
|
30
|
+
const keydownBehavior = {
|
|
31
|
+
ArrowDown: (event, target, config)=>{
|
|
32
|
+
/* istanbul ignore else */ if (isElementType(target, 'input', {
|
|
33
|
+
type: 'radio'
|
|
34
|
+
})) {
|
|
35
|
+
return ()=>walkRadio(config, target, -1);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
ArrowLeft: (event, target, config)=>{
|
|
39
|
+
if (isElementType(target, 'input', {
|
|
40
|
+
type: 'radio'
|
|
41
|
+
})) {
|
|
42
|
+
return ()=>walkRadio(config, target, -1);
|
|
43
|
+
}
|
|
44
|
+
return ()=>moveSelection(target, -1);
|
|
45
|
+
},
|
|
46
|
+
ArrowRight: (event, target, config)=>{
|
|
47
|
+
if (isElementType(target, 'input', {
|
|
48
|
+
type: 'radio'
|
|
49
|
+
})) {
|
|
50
|
+
return ()=>walkRadio(config, target, 1);
|
|
51
|
+
}
|
|
52
|
+
return ()=>moveSelection(target, 1);
|
|
53
|
+
},
|
|
54
|
+
ArrowUp: (event, target, config)=>{
|
|
55
|
+
/* istanbul ignore else */ if (isElementType(target, 'input', {
|
|
56
|
+
type: 'radio'
|
|
57
|
+
})) {
|
|
58
|
+
return ()=>walkRadio(config, target, 1);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
Backspace: (event, target, config)=>{
|
|
62
|
+
if (isEditable(target)) {
|
|
63
|
+
return ()=>{
|
|
64
|
+
input(config, target, '', 'deleteContentBackward');
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
Delete: (event, target, config)=>{
|
|
69
|
+
if (isEditable(target)) {
|
|
70
|
+
return ()=>{
|
|
71
|
+
input(config, target, '', 'deleteContentForward');
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
End: (event, target)=>{
|
|
76
|
+
if (isElementType(target, [
|
|
77
|
+
'input',
|
|
78
|
+
'textarea'
|
|
79
|
+
]) || isContentEditable(target)) {
|
|
80
|
+
return ()=>{
|
|
81
|
+
const newPos = getValue(target)?.length ?? /* istanbul ignore next */ 0;
|
|
82
|
+
setSelectionRange(target, newPos, newPos);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
Home: (event, target)=>{
|
|
87
|
+
if (isElementType(target, [
|
|
88
|
+
'input',
|
|
89
|
+
'textarea'
|
|
90
|
+
]) || isContentEditable(target)) {
|
|
91
|
+
return ()=>{
|
|
92
|
+
setSelectionRange(target, 0, 0);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
PageDown: (event, target)=>{
|
|
97
|
+
if (isElementType(target, [
|
|
98
|
+
'input'
|
|
99
|
+
])) {
|
|
100
|
+
return ()=>{
|
|
101
|
+
const newPos = getValue(target).length;
|
|
102
|
+
setSelectionRange(target, newPos, newPos);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
PageUp: (event, target)=>{
|
|
107
|
+
if (isElementType(target, [
|
|
108
|
+
'input'
|
|
109
|
+
])) {
|
|
110
|
+
return ()=>{
|
|
111
|
+
setSelectionRange(target, 0, 0);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
Tab: (event, target, config)=>{
|
|
116
|
+
return ()=>{
|
|
117
|
+
const dest = getTabDestination(target, config.system.keyboard.modifiers.Shift);
|
|
118
|
+
focus(dest);
|
|
119
|
+
if (hasOwnSelection(dest)) {
|
|
120
|
+
setUISelection(dest, {
|
|
121
|
+
anchorOffset: 0,
|
|
122
|
+
focusOffset: dest.value.length
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const combinationBehavior = (event, target, config)=>{
|
|
129
|
+
if (event.code === 'KeyA' && config.system.keyboard.modifiers.Control) {
|
|
130
|
+
return ()=>selectAll(target);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { dispatchUIEvent } from '../index.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
5
|
+
import { input } from '../../utils/edit/input.js';
|
|
6
|
+
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
7
|
+
import '@testing-library/dom';
|
|
8
|
+
import { isElementType } from '../../utils/misc/isElementType.js';
|
|
9
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
10
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
11
|
+
import '../../utils/misc/level.js';
|
|
12
|
+
import '../../options.js';
|
|
13
|
+
import { behavior } from './registry.js';
|
|
14
|
+
|
|
15
|
+
behavior.keypress = (event, target, config)=>{
|
|
16
|
+
if (event.key === 'Enter') {
|
|
17
|
+
if (isElementType(target, 'button') || isElementType(target, 'input') && ClickInputOnEnter.includes(target.type) || isElementType(target, 'a') && Boolean(target.href)) {
|
|
18
|
+
return ()=>{
|
|
19
|
+
dispatchUIEvent(config, target, 'click');
|
|
20
|
+
};
|
|
21
|
+
} else if (isElementType(target, 'input')) {
|
|
22
|
+
const form = target.form;
|
|
23
|
+
const submit = form?.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
24
|
+
if (submit) {
|
|
25
|
+
return ()=>dispatchUIEvent(config, submit, 'click');
|
|
26
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
|
|
27
|
+
return ()=>dispatchUIEvent(config, form, 'submit');
|
|
28
|
+
} else {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (isEditable(target)) {
|
|
34
|
+
const inputType = event.key === 'Enter' ? isContentEditable(target) && !config.system.keyboard.modifiers.Shift ? 'insertParagraph' : 'insertLineBreak' : 'insertText';
|
|
35
|
+
const inputData = event.key === 'Enter' ? '\n' : event.key;
|
|
36
|
+
return ()=>input(config, target, inputData, inputType);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const ClickInputOnEnter = [
|
|
40
|
+
'button',
|
|
41
|
+
'color',
|
|
42
|
+
'file',
|
|
43
|
+
'image',
|
|
44
|
+
'reset',
|
|
45
|
+
'submit',
|
|
46
|
+
];
|
|
47
|
+
const SubmitSingleInputOnEnter = [
|
|
48
|
+
'email',
|
|
49
|
+
'month',
|
|
50
|
+
'password',
|
|
51
|
+
'search',
|
|
52
|
+
'tel',
|
|
53
|
+
'text',
|
|
54
|
+
'url',
|
|
55
|
+
'week',
|
|
56
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isClickableInput } from '../../utils/click/isClickableInput.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { dispatchUIEvent } from '../index.js';
|
|
4
|
+
import '../../utils/edit/maxLength.js';
|
|
5
|
+
import '../../utils/edit/isEditable.js';
|
|
6
|
+
import '@testing-library/dom';
|
|
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 { behavior } from './registry.js';
|
|
12
|
+
|
|
13
|
+
behavior.keyup = (event, target, config)=>{
|
|
14
|
+
return keyupBehavior[event.key]?.(event, target, config);
|
|
15
|
+
};
|
|
16
|
+
const keyupBehavior = {
|
|
17
|
+
' ': (event, target, config)=>{
|
|
18
|
+
if (isClickableInput(target)) {
|
|
19
|
+
return ()=>dispatchUIEvent(config, target, 'click');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
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
|
+
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
13
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
14
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
15
|
+
import '../../utils/misc/level.js';
|
|
16
|
+
import '../../options.js';
|
|
17
|
+
|
|
18
|
+
behavior.paste = (event, target, config)=>{
|
|
19
|
+
if (isEditable(target)) {
|
|
20
|
+
return ()=>{
|
|
21
|
+
const insertData = event.clipboardData?.getData('text');
|
|
22
|
+
if (insertData) {
|
|
23
|
+
input(config, target, insertData, 'insertFromPaste');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import '../utils/click/isClickableInput.js';
|
|
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
|
+
import '../utils/edit/isEditable.js';
|
|
13
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
14
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
15
|
+
import '../utils/misc/level.js';
|
|
16
|
+
import '../options.js';
|
|
17
|
+
|
|
18
|
+
const eventInitializer = {
|
|
19
|
+
ClipboardEvent: [
|
|
20
|
+
initClipboardEvent
|
|
21
|
+
],
|
|
22
|
+
InputEvent: [
|
|
23
|
+
initUIEvent,
|
|
24
|
+
initInputEvent
|
|
25
|
+
],
|
|
26
|
+
MouseEvent: [
|
|
27
|
+
initUIEvent,
|
|
28
|
+
initUIEventModififiers,
|
|
29
|
+
initMouseEvent
|
|
30
|
+
],
|
|
31
|
+
PointerEvent: [
|
|
32
|
+
initUIEvent,
|
|
33
|
+
initUIEventModififiers,
|
|
34
|
+
initMouseEvent,
|
|
35
|
+
initPointerEvent,
|
|
36
|
+
],
|
|
37
|
+
KeyboardEvent: [
|
|
38
|
+
initUIEvent,
|
|
39
|
+
initUIEventModififiers,
|
|
40
|
+
initKeyboardEvent
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
function createEvent(type, target, init) {
|
|
44
|
+
const window = getWindow(target);
|
|
45
|
+
const { EventType , defaultInit } = eventMap[eventMapKeys[type]];
|
|
46
|
+
const event = new (getEventConstructors(window))[EventType](type, defaultInit);
|
|
47
|
+
eventInitializer[EventType]?.forEach((f)=>f(event, init ?? {}));
|
|
48
|
+
return event;
|
|
49
|
+
}
|
|
50
|
+
/* istanbul ignore next */ function getEventConstructors(window) {
|
|
51
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = window.Event ?? class Event {
|
|
52
|
+
};
|
|
53
|
+
const AnimationEvent = window.AnimationEvent ?? class AnimationEvent extends Event {
|
|
54
|
+
};
|
|
55
|
+
const ClipboardEvent = window.ClipboardEvent ?? class ClipboardEvent extends Event {
|
|
56
|
+
};
|
|
57
|
+
const PopStateEvent = window.PopStateEvent ?? class PopStateEvent extends Event {
|
|
58
|
+
};
|
|
59
|
+
const ProgressEvent = window.ProgressEvent ?? class ProgressEvent extends Event {
|
|
60
|
+
};
|
|
61
|
+
const TransitionEvent = window.TransitionEvent ?? class TransitionEvent extends Event {
|
|
62
|
+
};
|
|
63
|
+
const UIEvent = window.UIEvent ?? class UIEvent extends Event {
|
|
64
|
+
};
|
|
65
|
+
const CompositionEvent = window.CompositionEvent ?? class CompositionEvent extends UIEvent {
|
|
66
|
+
};
|
|
67
|
+
const FocusEvent = window.FocusEvent ?? class FocusEvent extends UIEvent {
|
|
68
|
+
};
|
|
69
|
+
const InputEvent = window.InputEvent ?? class InputEvent extends UIEvent {
|
|
70
|
+
};
|
|
71
|
+
const KeyboardEvent = window.KeyboardEvent ?? class KeyboardEvent extends UIEvent {
|
|
72
|
+
};
|
|
73
|
+
const MouseEvent = window.MouseEvent ?? class MouseEvent extends UIEvent {
|
|
74
|
+
};
|
|
75
|
+
const DragEvent = window.DragEvent ?? class DragEvent extends MouseEvent {
|
|
76
|
+
};
|
|
77
|
+
const PointerEvent = window.PointerEvent ?? class PointerEvent extends MouseEvent {
|
|
78
|
+
};
|
|
79
|
+
const TouchEvent = window.TouchEvent ?? class TouchEvent extends UIEvent {
|
|
80
|
+
};
|
|
81
|
+
/* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
|
|
82
|
+
Event,
|
|
83
|
+
AnimationEvent,
|
|
84
|
+
ClipboardEvent,
|
|
85
|
+
PopStateEvent,
|
|
86
|
+
ProgressEvent,
|
|
87
|
+
TransitionEvent,
|
|
88
|
+
UIEvent,
|
|
89
|
+
CompositionEvent,
|
|
90
|
+
FocusEvent,
|
|
91
|
+
InputEvent,
|
|
92
|
+
KeyboardEvent,
|
|
93
|
+
MouseEvent,
|
|
94
|
+
DragEvent,
|
|
95
|
+
PointerEvent,
|
|
96
|
+
TouchEvent
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function assignProps(obj, props) {
|
|
100
|
+
for (const [key, value] of Object.entries(props)){
|
|
101
|
+
Object.defineProperty(obj, key, {
|
|
102
|
+
get: ()=>value ?? null
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function sanitizeNumber(n) {
|
|
107
|
+
return Number(n ?? 0);
|
|
108
|
+
}
|
|
109
|
+
function initClipboardEvent(event, { clipboardData }) {
|
|
110
|
+
assignProps(event, {
|
|
111
|
+
clipboardData
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function initInputEvent(event, { data , inputType , isComposing }) {
|
|
115
|
+
assignProps(event, {
|
|
116
|
+
data,
|
|
117
|
+
isComposing: Boolean(isComposing),
|
|
118
|
+
inputType: String(inputType)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function initUIEvent(event, { view , detail }) {
|
|
122
|
+
assignProps(event, {
|
|
123
|
+
view,
|
|
124
|
+
detail: sanitizeNumber(detail ?? 0)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function initUIEventModififiers(event, { altKey , ctrlKey , metaKey , shiftKey , modifierAltGraph , modifierCapsLock , modifierFn , modifierFnLock , modifierNumLock , modifierScrollLock , modifierSymbol , modifierSymbolLock }) {
|
|
128
|
+
assignProps(event, {
|
|
129
|
+
altKey: Boolean(altKey),
|
|
130
|
+
ctrlKey: Boolean(ctrlKey),
|
|
131
|
+
metaKey: Boolean(metaKey),
|
|
132
|
+
shiftKey: Boolean(shiftKey),
|
|
133
|
+
getModifierState (k) {
|
|
134
|
+
return Boolean({
|
|
135
|
+
Alt: altKey,
|
|
136
|
+
AltGraph: modifierAltGraph,
|
|
137
|
+
CapsLock: modifierCapsLock,
|
|
138
|
+
Control: ctrlKey,
|
|
139
|
+
Fn: modifierFn,
|
|
140
|
+
FnLock: modifierFnLock,
|
|
141
|
+
Meta: metaKey,
|
|
142
|
+
NumLock: modifierNumLock,
|
|
143
|
+
ScrollLock: modifierScrollLock,
|
|
144
|
+
Shift: shiftKey,
|
|
145
|
+
Symbol: modifierSymbol,
|
|
146
|
+
SymbolLock: modifierSymbolLock
|
|
147
|
+
}[k]);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function initKeyboardEvent(event, { key , code , location , repeat , isComposing , charCode }) {
|
|
152
|
+
assignProps(event, {
|
|
153
|
+
key: String(key),
|
|
154
|
+
code: String(code),
|
|
155
|
+
location: sanitizeNumber(location),
|
|
156
|
+
repeat: Boolean(repeat),
|
|
157
|
+
isComposing: Boolean(isComposing),
|
|
158
|
+
charCode
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function initMouseEvent(event, { x , y , screenX , screenY , clientX =x , clientY =y , button , buttons , relatedTarget }) {
|
|
162
|
+
assignProps(event, {
|
|
163
|
+
screenX: sanitizeNumber(screenX),
|
|
164
|
+
screenY: sanitizeNumber(screenY),
|
|
165
|
+
clientX: sanitizeNumber(clientX),
|
|
166
|
+
x: sanitizeNumber(clientX),
|
|
167
|
+
clientY: sanitizeNumber(clientY),
|
|
168
|
+
y: sanitizeNumber(clientY),
|
|
169
|
+
button: sanitizeNumber(button),
|
|
170
|
+
buttons: sanitizeNumber(buttons),
|
|
171
|
+
relatedTarget
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function initPointerEvent(event, { pointerId , width , height , pressure , tangentialPressure , tiltX , tiltY , twist , pointerType , isPrimary }) {
|
|
175
|
+
assignProps(event, {
|
|
176
|
+
pointerId: sanitizeNumber(pointerId),
|
|
177
|
+
width: sanitizeNumber(width),
|
|
178
|
+
height: sanitizeNumber(height),
|
|
179
|
+
pressure: sanitizeNumber(pressure),
|
|
180
|
+
tangentialPressure: sanitizeNumber(tangentialPressure),
|
|
181
|
+
tiltX: sanitizeNumber(tiltX),
|
|
182
|
+
tiltY: sanitizeNumber(tiltY),
|
|
183
|
+
twist: sanitizeNumber(twist),
|
|
184
|
+
pointerType: String(pointerType),
|
|
185
|
+
isPrimary: Boolean(isPrimary)
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { createEvent };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import './behavior/click.js';
|
|
2
|
+
import './behavior/cut.js';
|
|
3
|
+
import './behavior/keydown.js';
|
|
4
|
+
import './behavior/keypress.js';
|
|
5
|
+
import './behavior/keyup.js';
|
|
6
|
+
import './behavior/paste.js';
|
|
7
|
+
import { behavior } from './behavior/registry.js';
|
|
8
|
+
import { wrapEvent } from './wrapEvent.js';
|
|
9
|
+
|
|
10
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
11
|
+
const type = event.type;
|
|
12
|
+
const behaviorImplementation = preventDefault ? ()=>{} : behavior[type]?.(event, target, config);
|
|
13
|
+
if (behaviorImplementation) {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
let defaultPrevented = false;
|
|
16
|
+
Object.defineProperty(event, 'defaultPrevented', {
|
|
17
|
+
get: ()=>defaultPrevented
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(event, 'preventDefault', {
|
|
20
|
+
value: ()=>{
|
|
21
|
+
defaultPrevented = event.cancelable;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
wrapEvent(()=>target.dispatchEvent(event));
|
|
25
|
+
if (!defaultPrevented) {
|
|
26
|
+
behaviorImplementation();
|
|
27
|
+
}
|
|
28
|
+
return !defaultPrevented;
|
|
29
|
+
}
|
|
30
|
+
return wrapEvent(()=>target.dispatchEvent(event));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { dispatchEvent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|