@testing-library/user-event 14.4.0 → 14.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clipboard/copy.js +6 -15
- package/dist/cjs/clipboard/cut.js +6 -15
- package/dist/cjs/clipboard/paste.js +6 -14
- package/dist/cjs/convenience/click.js +1 -4
- package/dist/cjs/convenience/hover.js +2 -12
- package/dist/cjs/document/UI.js +94 -0
- package/dist/cjs/document/copySelection.js +37 -0
- package/dist/cjs/document/getValueOrTextContent.js +27 -0
- package/dist/cjs/document/index.js +13 -68
- package/dist/cjs/document/interceptor.js +87 -4
- package/dist/cjs/document/prepareDocument.js +67 -0
- package/dist/cjs/document/trackValue.js +65 -0
- package/dist/cjs/event/behavior/click.js +8 -12
- package/dist/cjs/event/behavior/cut.js +5 -11
- package/dist/cjs/event/behavior/keydown.js +43 -43
- package/dist/cjs/event/behavior/keypress.js +9 -10
- package/dist/cjs/event/behavior/keyup.js +6 -7
- package/dist/cjs/event/behavior/paste.js +7 -12
- package/dist/cjs/event/createEvent.js +37 -28
- package/dist/cjs/event/dispatchEvent.js +21 -2
- package/dist/cjs/event/focus.js +44 -0
- package/dist/cjs/event/index.js +24 -17
- package/dist/cjs/{utils/edit → event}/input.js +50 -47
- package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/cjs/event/selection/getInputRange.js +20 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +40 -0
- package/dist/cjs/event/selection/index.js +26 -0
- package/dist/cjs/event/selection/modifySelection.js +30 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +49 -0
- package/dist/cjs/event/selection/moveSelection.js +47 -0
- package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
- package/dist/cjs/event/selection/selectAll.js +47 -0
- package/dist/cjs/event/selection/setSelection.js +30 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +90 -0
- package/dist/cjs/event/selection/setSelectionRange.js +40 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +45 -0
- package/dist/cjs/keyboard/index.js +13 -23
- package/dist/cjs/keyboard/parseKeyDef.js +8 -13
- package/dist/cjs/options.js +0 -28
- package/dist/cjs/pointer/index.js +28 -34
- package/dist/cjs/pointer/parseKeyDef.js +1 -9
- package/dist/cjs/setup/directApi.js +6 -6
- package/dist/cjs/setup/index.js +0 -2
- package/dist/cjs/setup/setup.js +69 -38
- package/dist/cjs/system/index.js +4 -2
- package/dist/cjs/system/keyboard.js +32 -32
- package/dist/cjs/system/pointer/buttons.js +3 -1
- package/dist/cjs/system/pointer/device.js +3 -1
- package/dist/cjs/system/pointer/index.js +82 -79
- package/dist/cjs/system/pointer/mouse.js +97 -81
- package/dist/cjs/system/pointer/pointer.js +45 -46
- package/dist/cjs/system/pointer/shared.js +10 -0
- package/dist/cjs/utility/clear.js +10 -11
- package/dist/cjs/utility/selectOptions.js +17 -19
- package/dist/cjs/utility/type.js +6 -15
- package/dist/cjs/utility/upload.js +9 -15
- package/dist/cjs/utils/dataTransfer/Clipboard.js +11 -21
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/cjs/utils/edit/isEditable.js +6 -10
- package/dist/cjs/utils/edit/maxLength.js +6 -16
- package/dist/cjs/utils/edit/setFiles.js +4 -2
- package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
- package/dist/cjs/utils/focus/cursor.js +2 -17
- package/dist/cjs/utils/focus/getActiveElement.js +3 -2
- package/dist/cjs/utils/focus/selection.js +1 -266
- package/dist/cjs/utils/index.js +7 -32
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/cjs/utils/misc/isDisabled.js +2 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +4 -6
- package/dist/cjs/utils/pointer/cssPointerEvents.js +26 -32
- package/dist/esm/clipboard/copy.js +6 -15
- package/dist/esm/clipboard/cut.js +6 -15
- package/dist/esm/clipboard/paste.js +6 -14
- package/dist/esm/convenience/click.js +1 -4
- package/dist/esm/convenience/hover.js +2 -12
- package/dist/esm/document/UI.js +79 -0
- package/dist/esm/document/copySelection.js +33 -0
- package/dist/esm/document/getValueOrTextContent.js +23 -0
- package/dist/esm/document/index.js +4 -66
- package/dist/esm/document/interceptor.js +85 -5
- package/dist/esm/document/prepareDocument.js +63 -0
- package/dist/esm/document/trackValue.js +59 -0
- package/dist/esm/event/behavior/click.js +8 -12
- package/dist/esm/event/behavior/cut.js +5 -11
- package/dist/esm/event/behavior/keydown.js +36 -36
- package/dist/esm/event/behavior/keypress.js +9 -10
- package/dist/esm/event/behavior/keyup.js +6 -7
- package/dist/esm/event/behavior/paste.js +7 -12
- package/dist/esm/event/createEvent.js +37 -28
- package/dist/esm/event/dispatchEvent.js +20 -3
- package/dist/esm/event/focus.js +39 -0
- package/dist/esm/event/index.js +14 -19
- package/dist/esm/{utils/edit → event}/input.js +37 -34
- package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +26 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
- package/dist/esm/event/selection/moveSelection.js +43 -0
- package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +11 -19
- package/dist/esm/event/selection/selectAll.js +42 -0
- package/dist/esm/event/selection/setSelection.js +26 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
- package/dist/esm/event/selection/setSelectionRange.js +36 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
- package/dist/esm/keyboard/index.js +13 -23
- package/dist/esm/keyboard/parseKeyDef.js +8 -13
- package/dist/esm/options.js +1 -26
- package/dist/esm/pointer/index.js +28 -34
- package/dist/esm/pointer/parseKeyDef.js +1 -9
- package/dist/esm/setup/directApi.js +6 -6
- package/dist/esm/setup/index.js +0 -1
- package/dist/esm/setup/setup.js +63 -33
- package/dist/esm/system/index.js +4 -2
- package/dist/esm/system/keyboard.js +32 -32
- package/dist/esm/system/pointer/buttons.js +3 -1
- package/dist/esm/system/pointer/device.js +3 -1
- package/dist/esm/system/pointer/index.js +83 -79
- package/dist/esm/system/pointer/mouse.js +95 -79
- package/dist/esm/system/pointer/pointer.js +44 -45
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +10 -11
- package/dist/esm/utility/selectOptions.js +17 -19
- package/dist/esm/utility/type.js +6 -15
- package/dist/esm/utility/upload.js +9 -15
- package/dist/esm/utils/dataTransfer/Clipboard.js +11 -21
- package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
- package/dist/esm/utils/edit/isEditable.js +4 -8
- package/dist/esm/utils/edit/maxLength.js +5 -16
- package/dist/esm/utils/edit/setFiles.js +4 -2
- package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
- package/dist/esm/utils/focus/cursor.js +2 -17
- package/dist/esm/utils/focus/getActiveElement.js +3 -2
- package/dist/esm/utils/focus/selection.js +3 -260
- package/dist/esm/utils/index.js +4 -11
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
- package/dist/esm/utils/misc/isDisabled.js +2 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +4 -6
- package/dist/esm/utils/pointer/cssPointerEvents.js +26 -32
- package/dist/types/clipboard/copy.d.ts +1 -1
- package/dist/types/clipboard/cut.d.ts +1 -1
- package/dist/types/clipboard/paste.d.ts +1 -1
- package/dist/types/convenience/click.d.ts +1 -1
- package/dist/types/convenience/hover.d.ts +1 -1
- package/dist/types/document/UI.d.ts +42 -0
- package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -10
- package/dist/types/document/interceptor.d.ts +3 -0
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/registry.d.ts +2 -2
- package/dist/types/event/dispatchEvent.d.ts +5 -2
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +6 -4
- package/dist/types/event/input.d.ts +2 -0
- package/dist/types/event/radio.d.ts +4 -0
- package/dist/types/event/selection/getInputRange.d.ts +5 -0
- package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
- package/dist/types/event/selection/index.d.ts +15 -0
- package/dist/types/event/selection/modifySelection.d.ts +8 -0
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
- package/dist/types/event/selection/moveSelection.d.ts +4 -0
- package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
- package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
- package/dist/types/event/selection/setSelection.d.ts +10 -0
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
- package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
- package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/options.d.ts +0 -8
- package/dist/types/pointer/index.d.ts +3 -3
- package/dist/types/setup/directApi.d.ts +1 -1
- package/dist/types/setup/index.d.ts +2 -15
- package/dist/types/setup/setup.d.ts +25 -7
- package/dist/types/system/keyboard.d.ts +3 -3
- package/dist/types/system/pointer/buttons.d.ts +1 -1
- package/dist/types/system/pointer/index.d.ts +7 -25
- package/dist/types/system/pointer/mouse.d.ts +5 -5
- package/dist/types/system/pointer/pointer.d.ts +7 -7
- package/dist/types/system/pointer/shared.d.ts +20 -0
- package/dist/types/utility/clear.d.ts +1 -1
- package/dist/types/utility/selectOptions.d.ts +1 -1
- package/dist/types/utility/type.d.ts +3 -3
- package/dist/types/utility/upload.d.ts +1 -1
- package/dist/types/utils/click/isClickableInput.d.ts +2 -2
- package/dist/types/utils/edit/isEditable.d.ts +5 -6
- package/dist/types/utils/edit/maxLength.d.ts +14 -1
- package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
- package/dist/types/utils/focus/selection.d.ts +4 -69
- package/dist/types/utils/index.d.ts +2 -9
- package/dist/types/utils/misc/level.d.ts +4 -13
- package/dist/types/utils/misc/wait.d.ts +2 -2
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
- package/package.json +29 -4
- package/dist/cjs/document/selection.js +0 -107
- package/dist/cjs/document/setRangeText.js +0 -21
- package/dist/cjs/document/value.js +0 -125
- package/dist/cjs/setup/config.js +0 -7
- package/dist/cjs/utils/edit/getValue.js +0 -35
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
- package/dist/cjs/utils/focus/blur.js +0 -16
- package/dist/cjs/utils/focus/copySelection.js +0 -46
- package/dist/cjs/utils/focus/focus.js +0 -26
- package/dist/cjs/utils/focus/selectAll.js +0 -54
- package/dist/cjs/utils/misc/eventWrapper.js +0 -15
- package/dist/esm/document/selection.js +0 -99
- package/dist/esm/document/setRangeText.js +0 -17
- package/dist/esm/document/value.js +0 -115
- package/dist/esm/setup/config.js +0 -3
- package/dist/esm/utils/edit/getValue.js +0 -31
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
- package/dist/esm/utils/focus/blur.js +0 -12
- package/dist/esm/utils/focus/copySelection.js +0 -42
- package/dist/esm/utils/focus/focus.js +0 -22
- package/dist/esm/utils/focus/selectAll.js +0 -49
- package/dist/esm/utils/misc/eventWrapper.js +0 -11
- package/dist/types/document/selection.d.ts +0 -29
- package/dist/types/document/setRangeText.d.ts +0 -1
- package/dist/types/document/value.d.ts +0 -26
- package/dist/types/setup/config.d.ts +0 -6
- package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/types/utils/edit/getValue.d.ts +0 -1
- package/dist/types/utils/edit/input.d.ts +0 -2
- package/dist/types/utils/edit/walkRadio.d.ts +0 -4
- package/dist/types/utils/focus/blur.d.ts +0 -2
- package/dist/types/utils/focus/focus.d.ts +0 -5
- package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
|
@@ -1,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: [
|
|
@@ -41,42 +34,58 @@ const eventInitializer = {
|
|
|
41
34
|
]
|
|
42
35
|
};
|
|
43
36
|
function createEvent(type, target, init) {
|
|
37
|
+
var ref;
|
|
44
38
|
const window = getWindow(target);
|
|
45
39
|
const { EventType , defaultInit } = eventMap[eventMapKeys[type]];
|
|
46
40
|
const event = new (getEventConstructors(window))[EventType](type, defaultInit);
|
|
47
|
-
eventInitializer[EventType]
|
|
41
|
+
(ref = eventInitializer[EventType]) === null || ref === void 0 ? void 0 : ref.forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
|
|
48
42
|
return event;
|
|
49
43
|
}
|
|
50
44
|
/* istanbul ignore next */ function getEventConstructors(window) {
|
|
51
|
-
|
|
45
|
+
var _Event;
|
|
46
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_Event = window.Event) !== null && _Event !== void 0 ? _Event : class Event {
|
|
52
47
|
};
|
|
53
|
-
|
|
48
|
+
var _AnimationEvent;
|
|
49
|
+
const AnimationEvent = (_AnimationEvent = window.AnimationEvent) !== null && _AnimationEvent !== void 0 ? _AnimationEvent : class AnimationEvent extends Event {
|
|
54
50
|
};
|
|
55
|
-
|
|
51
|
+
var _ClipboardEvent;
|
|
52
|
+
const ClipboardEvent = (_ClipboardEvent = window.ClipboardEvent) !== null && _ClipboardEvent !== void 0 ? _ClipboardEvent : class ClipboardEvent extends Event {
|
|
56
53
|
};
|
|
57
|
-
|
|
54
|
+
var _PopStateEvent;
|
|
55
|
+
const PopStateEvent = (_PopStateEvent = window.PopStateEvent) !== null && _PopStateEvent !== void 0 ? _PopStateEvent : class PopStateEvent extends Event {
|
|
58
56
|
};
|
|
59
|
-
|
|
57
|
+
var _ProgressEvent;
|
|
58
|
+
const ProgressEvent = (_ProgressEvent = window.ProgressEvent) !== null && _ProgressEvent !== void 0 ? _ProgressEvent : class ProgressEvent extends Event {
|
|
60
59
|
};
|
|
61
|
-
|
|
60
|
+
var _TransitionEvent;
|
|
61
|
+
const TransitionEvent = (_TransitionEvent = window.TransitionEvent) !== null && _TransitionEvent !== void 0 ? _TransitionEvent : class TransitionEvent extends Event {
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
var _UIEvent;
|
|
64
|
+
const UIEvent = (_UIEvent = window.UIEvent) !== null && _UIEvent !== void 0 ? _UIEvent : class UIEvent extends Event {
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
+
var _CompositionEvent;
|
|
67
|
+
const CompositionEvent = (_CompositionEvent = window.CompositionEvent) !== null && _CompositionEvent !== void 0 ? _CompositionEvent : class CompositionEvent extends UIEvent {
|
|
66
68
|
};
|
|
67
|
-
|
|
69
|
+
var _FocusEvent;
|
|
70
|
+
const FocusEvent = (_FocusEvent = window.FocusEvent) !== null && _FocusEvent !== void 0 ? _FocusEvent : class FocusEvent extends UIEvent {
|
|
68
71
|
};
|
|
69
|
-
|
|
72
|
+
var _InputEvent;
|
|
73
|
+
const InputEvent = (_InputEvent = window.InputEvent) !== null && _InputEvent !== void 0 ? _InputEvent : class InputEvent extends UIEvent {
|
|
70
74
|
};
|
|
71
|
-
|
|
75
|
+
var _KeyboardEvent;
|
|
76
|
+
const KeyboardEvent = (_KeyboardEvent = window.KeyboardEvent) !== null && _KeyboardEvent !== void 0 ? _KeyboardEvent : class KeyboardEvent extends UIEvent {
|
|
72
77
|
};
|
|
73
|
-
|
|
78
|
+
var _MouseEvent;
|
|
79
|
+
const MouseEvent = (_MouseEvent = window.MouseEvent) !== null && _MouseEvent !== void 0 ? _MouseEvent : class MouseEvent extends UIEvent {
|
|
74
80
|
};
|
|
75
|
-
|
|
81
|
+
var _DragEvent;
|
|
82
|
+
const DragEvent = (_DragEvent = window.DragEvent) !== null && _DragEvent !== void 0 ? _DragEvent : class DragEvent extends MouseEvent {
|
|
76
83
|
};
|
|
77
|
-
|
|
84
|
+
var _PointerEvent;
|
|
85
|
+
const PointerEvent = (_PointerEvent = window.PointerEvent) !== null && _PointerEvent !== void 0 ? _PointerEvent : class PointerEvent extends MouseEvent {
|
|
78
86
|
};
|
|
79
|
-
|
|
87
|
+
var _TouchEvent;
|
|
88
|
+
const TouchEvent = (_TouchEvent = window.TouchEvent) !== null && _TouchEvent !== void 0 ? _TouchEvent : class TouchEvent extends UIEvent {
|
|
80
89
|
};
|
|
81
90
|
/* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
|
|
82
91
|
Event,
|
|
@@ -99,12 +108,12 @@ function createEvent(type, target, init) {
|
|
|
99
108
|
function assignProps(obj, props) {
|
|
100
109
|
for (const [key, value] of Object.entries(props)){
|
|
101
110
|
Object.defineProperty(obj, key, {
|
|
102
|
-
get: ()=>value
|
|
111
|
+
get: ()=>value !== null && value !== void 0 ? value : null
|
|
103
112
|
});
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
function sanitizeNumber(n) {
|
|
107
|
-
return Number(n
|
|
116
|
+
return Number(n !== null && n !== void 0 ? n : 0);
|
|
108
117
|
}
|
|
109
118
|
function initClipboardEvent(event, { clipboardData }) {
|
|
110
119
|
assignProps(event, {
|
|
@@ -121,7 +130,7 @@ function initInputEvent(event, { data , inputType , isComposing }) {
|
|
|
121
130
|
function initUIEvent(event, { view , detail }) {
|
|
122
131
|
assignProps(event, {
|
|
123
132
|
view,
|
|
124
|
-
detail: sanitizeNumber(detail
|
|
133
|
+
detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
|
|
125
134
|
});
|
|
126
135
|
}
|
|
127
136
|
function initUIEventModififiers(event, { altKey , ctrlKey , metaKey , shiftKey , modifierAltGraph , modifierCapsLock , modifierFn , modifierFnLock , modifierNumLock , modifierScrollLock , modifierSymbol , modifierSymbolLock }) {
|
|
@@ -6,10 +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
|
|
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 ref;
|
|
11
24
|
const type = event.type;
|
|
12
|
-
const behaviorImplementation = preventDefault ? ()=>{} : behavior[type]
|
|
25
|
+
const behaviorImplementation = preventDefault ? ()=>{} : (ref = behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, this);
|
|
13
26
|
if (behaviorImplementation) {
|
|
14
27
|
event.preventDefault();
|
|
15
28
|
let defaultPrevented = false;
|
|
@@ -29,5 +42,9 @@ function dispatchEvent(config, target, event, preventDefault = false) {
|
|
|
29
42
|
}
|
|
30
43
|
return wrapEvent(()=>target.dispatchEvent(event));
|
|
31
44
|
}
|
|
45
|
+
function dispatchDOMEvent(target, type, init) {
|
|
46
|
+
const event = createEvent(type, target, init);
|
|
47
|
+
wrapEvent(()=>target.dispatchEvent(event));
|
|
48
|
+
}
|
|
32
49
|
|
|
33
|
-
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 ref;
|
|
27
|
+
return (ref = activeElement) === null || ref === void 0 ? void 0 : ref.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 };
|
package/dist/esm/event/index.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
function bindDispatchUIEvent(config) {
|
|
16
|
-
return dispatchUIEvent.bind(undefined, config);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { bindDispatchUIEvent, dispatchUIEvent };
|
|
1
|
+
export { dispatchDOMEvent, dispatchEvent, dispatchUIEvent } from './dispatchEvent.js';
|
|
2
|
+
export { blurElement, focusElement } from './focus.js';
|
|
3
|
+
export { input } from './input.js';
|
|
4
|
+
import '../utils/click/isClickableInput.js';
|
|
5
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
6
|
+
import '../utils/edit/isEditable.js';
|
|
7
|
+
import '../utils/edit/maxLength.js';
|
|
8
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
9
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
10
|
+
import '../utils/misc/level.js';
|
|
11
|
+
import '../options.js';
|
|
12
|
+
export { setSelectionPerMouseDown } from './selection/setSelectionPerMouse.js';
|
|
13
|
+
export { modifySelectionPerMouseMove } from './selection/modifySelectionPerMouse.js';
|
|
14
|
+
export { isAllSelected, selectAll } from './selection/selectAll.js';
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../click/isClickableInput.js';
|
|
3
|
-
import '../dataTransfer/Clipboard.js';
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { setUIValue, clearInitialValue, getUIValue } from '../document/UI.js';
|
|
2
|
+
import '../utils/click/isClickableInput.js';
|
|
3
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import { isValidDateOrTimeValue, buildTimeValue } from '../utils/edit/timeValue.js';
|
|
5
|
+
import '../utils/edit/isEditable.js';
|
|
6
|
+
import { supportsMaxLength, getMaxLength } from '../utils/edit/maxLength.js';
|
|
7
|
+
import { getNextCursorPosition } from '../utils/focus/cursor.js';
|
|
8
|
+
import { isElementType } from '../utils/misc/isElementType.js';
|
|
8
9
|
import '@testing-library/dom/dist/helpers.js';
|
|
9
|
-
import
|
|
10
|
-
import '../
|
|
11
|
-
import '../
|
|
12
|
-
import '
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { isValidDateOrTimeValue } from './isValidDateOrTimeValue.js';
|
|
16
|
-
import { getSpaceUntilMaxLength } from './maxLength.js';
|
|
10
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
11
|
+
import '../utils/misc/level.js';
|
|
12
|
+
import '../options.js';
|
|
13
|
+
import { commitValueAfterInput } from '../document/trackValue.js';
|
|
14
|
+
import { getInputRange } from './selection/getInputRange.js';
|
|
15
|
+
import { setSelection } from './selection/setSelection.js';
|
|
17
16
|
|
|
18
17
|
function isDateOrTime(element) {
|
|
19
18
|
return isElementType(element, 'input') && [
|
|
@@ -21,14 +20,14 @@ function isDateOrTime(element) {
|
|
|
21
20
|
'time'
|
|
22
21
|
].includes(element.type);
|
|
23
22
|
}
|
|
24
|
-
function input(
|
|
23
|
+
function input(instance, element, data, inputType = 'insertText') {
|
|
25
24
|
const inputRange = getInputRange(element);
|
|
26
25
|
/* istanbul ignore if */ if (!inputRange) {
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
29
28
|
// There is no `beforeinput` event on `date` and `time` input
|
|
30
29
|
if (!isDateOrTime(element)) {
|
|
31
|
-
const unprevented = dispatchUIEvent(
|
|
30
|
+
const unprevented = instance.dispatchUIEvent(element, 'beforeinput', {
|
|
32
31
|
inputType,
|
|
33
32
|
data
|
|
34
33
|
});
|
|
@@ -37,12 +36,12 @@ function input(config, element, data, inputType = 'insertText') {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
if ('startContainer' in inputRange) {
|
|
40
|
-
editContenteditable(
|
|
39
|
+
editContenteditable(instance, element, inputRange, data, inputType);
|
|
41
40
|
} else {
|
|
42
|
-
editInputElement(
|
|
41
|
+
editInputElement(instance, element, inputRange, data, inputType);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
function editContenteditable(
|
|
44
|
+
function editContenteditable(instance, element, inputRange, data, inputType) {
|
|
46
45
|
let del = false;
|
|
47
46
|
if (!inputRange.collapsed) {
|
|
48
47
|
del = true;
|
|
@@ -77,19 +76,22 @@ function editContenteditable(config, element, inputRange, data, inputType) {
|
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
if (del || data) {
|
|
80
|
-
dispatchUIEvent(
|
|
79
|
+
instance.dispatchUIEvent(element, 'input', {
|
|
81
80
|
inputType
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
function editInputElement(
|
|
84
|
+
function editInputElement(instance, element, inputRange, data, inputType) {
|
|
86
85
|
let dataToInsert = data;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
if (supportsMaxLength(element)) {
|
|
87
|
+
const maxLength = getMaxLength(element);
|
|
88
|
+
if (maxLength !== undefined && data.length > 0) {
|
|
89
|
+
const spaceUntilMaxLength = maxLength - element.value.length;
|
|
90
|
+
if (spaceUntilMaxLength > 0) {
|
|
91
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
92
|
+
} else {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
const { newValue , newOffset , oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
@@ -109,12 +111,12 @@ function editInputElement(config, element, inputRange, data, inputType) {
|
|
|
109
111
|
});
|
|
110
112
|
if (isDateOrTime(element)) {
|
|
111
113
|
if (isValidDateOrTimeValue(element, newValue)) {
|
|
112
|
-
commitInput(
|
|
113
|
-
dispatchUIEvent(
|
|
114
|
+
commitInput(instance, element, newOffset, {});
|
|
115
|
+
instance.dispatchUIEvent(element, 'change');
|
|
114
116
|
clearInitialValue(element);
|
|
115
117
|
}
|
|
116
118
|
} else {
|
|
117
|
-
commitInput(
|
|
119
|
+
commitInput(instance, element, newOffset, {
|
|
118
120
|
data,
|
|
119
121
|
inputType
|
|
120
122
|
});
|
|
@@ -143,16 +145,17 @@ function calculateNewValue(inputData, node, { startOffset , endOffset }, inputT
|
|
|
143
145
|
newOffset
|
|
144
146
|
};
|
|
145
147
|
}
|
|
146
|
-
function commitInput(
|
|
147
|
-
dispatchUIEvent(
|
|
148
|
+
function commitInput(instance, element, newOffset, inputInit) {
|
|
149
|
+
instance.dispatchUIEvent(element, 'input', inputInit);
|
|
148
150
|
commitValueAfterInput(element, newOffset);
|
|
149
151
|
}
|
|
150
152
|
function isValidNumberInput(value) {
|
|
153
|
+
var ref, ref1;
|
|
151
154
|
// the browser allows some invalid input but not others
|
|
152
155
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
153
156
|
// it allows one '.' at any place before e
|
|
154
157
|
const valueParts = value.split('e', 2);
|
|
155
|
-
return !(/[^\d.\-e]/.test(value) || Number(value.match(/-/g)
|
|
158
|
+
return !(/[^\d.\-e]/.test(value) || Number((ref = value.match(/-/g)) === null || ref === void 0 ? void 0 : ref.length) > 2 || Number((ref1 = value.match(/\./g)) === null || ref1 === void 0 ? void 0 : ref1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
156
159
|
}
|
|
157
160
|
|
|
158
161
|
export { input };
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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 { isDisabled } from '../utils/misc/isDisabled.js';
|
|
6
|
+
import { getWindow } from '../utils/misc/getWindow.js';
|
|
7
|
+
import '../utils/keyDef/readNextDescriptor.js';
|
|
8
|
+
import '../utils/misc/level.js';
|
|
9
|
+
import '../options.js';
|
|
10
|
+
import { focusElement } from './focus.js';
|
|
5
11
|
|
|
6
|
-
function walkRadio(
|
|
12
|
+
function walkRadio(instance, el, direction) {
|
|
7
13
|
const window = getWindow(el);
|
|
8
14
|
const group = Array.from(el.ownerDocument.querySelectorAll(el.name ? `input[type="radio"][name="${window.CSS.escape(el.name)}"]` : `input[type="radio"][name=""], input[type="radio"]:not([name])`));
|
|
9
15
|
for(let i = group.findIndex((e)=>e === el) + direction;; i += direction){
|
|
@@ -16,8 +22,8 @@ function walkRadio(config, el, direction) {
|
|
|
16
22
|
if (isDisabled(group[i])) {
|
|
17
23
|
continue;
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
dispatchUIEvent(
|
|
25
|
+
focusElement(group[i]);
|
|
26
|
+
instance.dispatchUIEvent(group[i], 'click');
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the range that would be overwritten by input.
|
|
5
|
+
*/ function getInputRange(focusNode) {
|
|
6
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
7
|
+
if (typeAndSelection.type === 'input') {
|
|
8
|
+
return typeAndSelection.selection;
|
|
9
|
+
} else if (typeAndSelection.type === 'contenteditable') {
|
|
10
|
+
var ref;
|
|
11
|
+
// Multi-range on contenteditable edits the first selection instead of the last
|
|
12
|
+
return (ref = typeAndSelection.selection) === null || ref === void 0 ? void 0 : ref.getRangeAt(0);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getInputRange };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import { getContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
5
|
+
import '../../utils/edit/isEditable.js';
|
|
6
|
+
import '../../utils/edit/maxLength.js';
|
|
7
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
8
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
9
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
10
|
+
import '../../utils/misc/level.js';
|
|
11
|
+
import '../../options.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Determine which selection logic and selection ranges to consider.
|
|
15
|
+
*/ function getTargetTypeAndSelection(node) {
|
|
16
|
+
const element = getElement(node);
|
|
17
|
+
if (element && hasOwnSelection(element)) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'input',
|
|
20
|
+
selection: getUISelection(element)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const selection = element === null || element === void 0 ? void 0 : element.ownerDocument.getSelection();
|
|
24
|
+
// It is possible to extend a single-range selection into a contenteditable.
|
|
25
|
+
// This results in the range acting like a range outside of contenteditable.
|
|
26
|
+
const isCE = getContentEditable(node) && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
27
|
+
return {
|
|
28
|
+
type: isCE ? 'contenteditable' : 'default',
|
|
29
|
+
selection
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getElement(node) {
|
|
33
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { getTargetTypeAndSelection };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { getInputRange } from './getInputRange.js';
|
|
2
|
+
export { modifySelection } from './modifySelection.js';
|
|
3
|
+
export { moveSelection } from './moveSelection.js';
|
|
4
|
+
export { setSelectionPerMouseDown } from './setSelectionPerMouse.js';
|
|
5
|
+
export { modifySelectionPerMouseMove } from './modifySelectionPerMouse.js';
|
|
6
|
+
export { isAllSelected, selectAll } from './selectAll.js';
|
|
7
|
+
export { setSelectionRange } from './setSelectionRange.js';
|
|
8
|
+
export { setSelection } from './setSelection.js';
|
|
9
|
+
export { updateSelectionOnFocus } from './updateSelectionOnFocus.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
8
|
+
import '../../utils/misc/level.js';
|
|
9
|
+
import '../../options.js';
|
|
10
|
+
import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
|
|
14
|
+
*/ function modifySelection({ focusNode , focusOffset }) {
|
|
15
|
+
var ref, ref1;
|
|
16
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
17
|
+
if (typeAndSelection.type === 'input') {
|
|
18
|
+
return setUISelection(focusNode, {
|
|
19
|
+
anchorOffset: typeAndSelection.selection.anchorOffset,
|
|
20
|
+
focusOffset
|
|
21
|
+
}, 'modify');
|
|
22
|
+
}
|
|
23
|
+
(ref1 = (ref = focusNode.ownerDocument) === null || ref === void 0 ? void 0 : ref.getSelection()) === null || ref1 === void 0 ? void 0 : ref1.extend(focusNode, focusOffset);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { modifySelection };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { setUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
8
|
+
import '../../utils/misc/level.js';
|
|
9
|
+
import '../../options.js';
|
|
10
|
+
import { resolveCaretPosition } from './resolveCaretPosition.js';
|
|
11
|
+
|
|
12
|
+
function modifySelectionPerMouseMove(selectionRange, { document , target , node , offset }) {
|
|
13
|
+
const selectionFocus = resolveCaretPosition({
|
|
14
|
+
target,
|
|
15
|
+
node,
|
|
16
|
+
offset
|
|
17
|
+
});
|
|
18
|
+
if ('node' in selectionRange) {
|
|
19
|
+
// When the mouse is dragged outside of an input/textarea,
|
|
20
|
+
// the selection is extended to the beginning or end of the input
|
|
21
|
+
// depending on pointer position.
|
|
22
|
+
// TODO: extend selection according to pointer position
|
|
23
|
+
/* istanbul ignore else */ if (selectionFocus.node === selectionRange.node) {
|
|
24
|
+
const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
|
|
25
|
+
const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
|
|
26
|
+
setUISelection(selectionRange.node, {
|
|
27
|
+
anchorOffset,
|
|
28
|
+
focusOffset
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
const range = selectionRange.cloneRange();
|
|
33
|
+
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
34
|
+
if (cmp < 0) {
|
|
35
|
+
range.setStart(selectionFocus.node, selectionFocus.offset);
|
|
36
|
+
} else if (cmp > 0) {
|
|
37
|
+
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
38
|
+
}
|
|
39
|
+
const selection = document.getSelection();
|
|
40
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
41
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { modifySelectionPerMouseMove };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import { getNextCursorPosition } from '../../utils/focus/cursor.js';
|
|
7
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
8
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
9
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
10
|
+
import '../../utils/misc/level.js';
|
|
11
|
+
import '../../options.js';
|
|
12
|
+
import { setSelection } from './setSelection.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Move the selection
|
|
16
|
+
*/ function moveSelection(node, direction) {
|
|
17
|
+
// TODO: implement shift
|
|
18
|
+
if (hasOwnSelection(node)) {
|
|
19
|
+
const selection = getUISelection(node);
|
|
20
|
+
setSelection({
|
|
21
|
+
focusNode: node,
|
|
22
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
const selection1 = node.ownerDocument.getSelection();
|
|
26
|
+
if (!(selection1 === null || selection1 === void 0 ? void 0 : selection1.focusNode)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (selection1.isCollapsed) {
|
|
30
|
+
const nextPosition = getNextCursorPosition(selection1.focusNode, selection1.focusOffset, direction);
|
|
31
|
+
if (nextPosition) {
|
|
32
|
+
setSelection({
|
|
33
|
+
focusNode: nextPosition.node,
|
|
34
|
+
focusOffset: nextPosition.offset
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
selection1[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { moveSelection };
|
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import '
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import { hasOwnSelection } from './selection.js';
|
|
1
|
+
import { getUIValue } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/click/isClickableInput.js';
|
|
3
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
7
6
|
import '@testing-library/dom/dist/helpers.js';
|
|
8
|
-
import '
|
|
9
|
-
import '
|
|
7
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
8
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../../utils/misc/level.js';
|
|
10
10
|
import '../../options.js';
|
|
11
|
-
import '../../event/eventMap.js';
|
|
12
|
-
import '../../event/behavior/click.js';
|
|
13
|
-
import '../../event/behavior/cut.js';
|
|
14
|
-
import '../../event/behavior/keydown.js';
|
|
15
|
-
import '../../event/behavior/keypress.js';
|
|
16
|
-
import '../../event/behavior/keyup.js';
|
|
17
|
-
import '../../event/behavior/paste.js';
|
|
18
|
-
import { getUIValue } from '../../document/value.js';
|
|
19
11
|
|
|
20
12
|
function resolveCaretPosition({ target , node , offset }) {
|
|
21
13
|
if (hasOwnSelection(target)) {
|
|
22
14
|
return {
|
|
23
15
|
node: target,
|
|
24
|
-
offset: offset
|
|
16
|
+
offset: offset !== null && offset !== void 0 ? offset : getUIValue(target).length
|
|
25
17
|
};
|
|
26
18
|
} else if (node) {
|
|
27
19
|
return {
|
|
28
20
|
node,
|
|
29
|
-
offset: offset
|
|
21
|
+
offset: offset !== null && offset !== void 0 ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
30
22
|
};
|
|
31
23
|
}
|
|
32
24
|
return findNodeAtTextOffset(target, offset);
|
|
@@ -58,7 +50,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
58
50
|
if (c.nodeType === 3) {
|
|
59
51
|
return {
|
|
60
52
|
node: c,
|
|
61
|
-
offset: offset
|
|
53
|
+
offset: offset !== null && offset !== void 0 ? offset : c.nodeValue.length
|
|
62
54
|
};
|
|
63
55
|
}
|
|
64
56
|
}
|