@testing-library/user-event 14.5.2 → 14.6.1
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 +1 -7
- package/dist/cjs/clipboard/cut.js +1 -7
- package/dist/cjs/clipboard/paste.js +2 -8
- package/dist/cjs/convenience/hover.js +0 -5
- package/dist/cjs/document/UI.js +3 -3
- package/dist/cjs/document/copySelection.js +0 -6
- package/dist/cjs/document/getValueOrTextContent.js +0 -6
- package/dist/cjs/document/interceptor.js +5 -11
- package/dist/cjs/document/patchFocus.js +104 -0
- package/dist/cjs/document/prepareDocument.js +1 -7
- package/dist/cjs/document/trackValue.js +2 -8
- package/dist/cjs/event/behavior/click.js +3 -9
- package/dist/cjs/event/behavior/cut.js +0 -5
- package/dist/cjs/event/behavior/keydown.js +5 -10
- package/dist/cjs/event/behavior/keypress.js +2 -7
- package/dist/cjs/event/behavior/keyup.js +1 -6
- package/dist/cjs/event/behavior/paste.js +1 -6
- package/dist/cjs/event/createEvent.js +40 -33
- package/dist/cjs/event/dispatchEvent.js +1 -1
- package/dist/cjs/event/eventMap.js +32 -0
- package/dist/cjs/event/focus.js +5 -9
- package/dist/cjs/event/index.js +0 -6
- package/dist/cjs/event/input.js +2 -7
- package/dist/cjs/event/radio.js +1 -6
- package/dist/cjs/event/selection/getInputRange.js +1 -1
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +2 -8
- package/dist/cjs/event/selection/modifySelection.js +1 -7
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +2 -8
- package/dist/cjs/event/selection/moveSelection.js +1 -7
- package/dist/cjs/event/selection/resolveCaretPosition.js +4 -10
- package/dist/cjs/event/selection/selectAll.js +3 -9
- package/dist/cjs/event/selection/setSelection.js +1 -7
- package/dist/cjs/event/selection/setSelectionPerMouse.js +7 -13
- package/dist/cjs/event/selection/setSelectionRange.js +1 -7
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +6 -8
- package/dist/cjs/index.js +1 -4
- package/dist/cjs/keyboard/index.js +0 -6
- package/dist/cjs/keyboard/keyMap.js +23 -1
- package/dist/cjs/keyboard/parseKeyDef.js +4 -9
- package/dist/cjs/options.js +5 -3
- package/dist/cjs/pointer/index.js +6 -11
- package/dist/cjs/pointer/parseKeyDef.js +0 -5
- package/dist/cjs/setup/setup.js +7 -7
- package/dist/cjs/system/keyboard.js +47 -25
- package/dist/cjs/system/pointer/index.js +45 -50
- package/dist/cjs/system/pointer/mouse.js +24 -29
- package/dist/cjs/system/pointer/pointer.js +24 -19
- package/dist/cjs/system/pointer/shared.js +2 -2
- package/dist/cjs/utility/clear.js +0 -5
- package/dist/cjs/utility/selectOptions.js +1 -6
- package/dist/cjs/utility/type.js +1 -7
- package/dist/cjs/utility/upload.js +13 -15
- package/dist/cjs/utils/click/isClickableInput.js +3 -3
- package/dist/cjs/utils/dataTransfer/Clipboard.js +5 -6
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +6 -10
- package/dist/cjs/utils/edit/isEditable.js +3 -3
- package/dist/cjs/utils/edit/maxLength.js +4 -4
- package/dist/cjs/utils/edit/setFiles.js +2 -2
- package/dist/cjs/utils/focus/cursor.js +2 -2
- package/dist/cjs/utils/focus/getActiveElement.js +2 -2
- package/dist/cjs/utils/index.js +1 -4
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +6 -6
- package/dist/cjs/utils/misc/getWindow.js +1 -1
- package/dist/cjs/utils/misc/isDisabled.js +1 -1
- package/dist/cjs/utils/misc/isVisible.js +1 -1
- package/dist/cjs/utils/misc/level.js +4 -3
- package/dist/cjs/utils/pointer/cssPointerEvents.js +11 -11
- package/dist/esm/clipboard/copy.js +1 -7
- package/dist/esm/clipboard/cut.js +1 -7
- package/dist/esm/clipboard/paste.js +2 -8
- package/dist/esm/convenience/hover.js +0 -5
- package/dist/esm/document/UI.js +3 -3
- package/dist/esm/document/copySelection.js +0 -6
- package/dist/esm/document/getValueOrTextContent.js +0 -6
- package/dist/esm/document/interceptor.js +5 -11
- package/dist/esm/document/patchFocus.js +101 -0
- package/dist/esm/document/prepareDocument.js +1 -7
- package/dist/esm/document/trackValue.js +2 -8
- package/dist/esm/event/behavior/click.js +3 -9
- package/dist/esm/event/behavior/cut.js +0 -5
- package/dist/esm/event/behavior/keydown.js +5 -10
- package/dist/esm/event/behavior/keypress.js +2 -7
- package/dist/esm/event/behavior/keyup.js +1 -6
- package/dist/esm/event/behavior/paste.js +1 -6
- package/dist/esm/event/createEvent.js +40 -33
- package/dist/esm/event/dispatchEvent.js +1 -1
- package/dist/esm/event/eventMap.js +32 -0
- package/dist/esm/event/focus.js +5 -9
- package/dist/esm/event/index.js +0 -6
- package/dist/esm/event/input.js +2 -7
- package/dist/esm/event/radio.js +1 -6
- package/dist/esm/event/selection/getInputRange.js +1 -1
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +2 -8
- package/dist/esm/event/selection/modifySelection.js +1 -7
- package/dist/esm/event/selection/modifySelectionPerMouse.js +2 -8
- package/dist/esm/event/selection/moveSelection.js +1 -7
- package/dist/esm/event/selection/resolveCaretPosition.js +4 -10
- package/dist/esm/event/selection/selectAll.js +3 -9
- package/dist/esm/event/selection/setSelection.js +1 -7
- package/dist/esm/event/selection/setSelectionPerMouse.js +7 -13
- package/dist/esm/event/selection/setSelectionRange.js +1 -7
- package/dist/esm/event/selection/updateSelectionOnFocus.js +6 -8
- package/dist/esm/keyboard/index.js +0 -6
- package/dist/esm/keyboard/keyMap.js +23 -1
- package/dist/esm/keyboard/parseKeyDef.js +4 -9
- package/dist/esm/options.js +3 -3
- package/dist/esm/pointer/index.js +6 -11
- package/dist/esm/pointer/parseKeyDef.js +0 -5
- package/dist/esm/setup/setup.js +7 -7
- package/dist/esm/system/keyboard.js +46 -25
- package/dist/esm/system/pointer/index.js +45 -50
- package/dist/esm/system/pointer/mouse.js +24 -29
- package/dist/esm/system/pointer/pointer.js +24 -19
- package/dist/esm/system/pointer/shared.js +2 -2
- package/dist/esm/utility/clear.js +0 -5
- package/dist/esm/utility/selectOptions.js +1 -6
- package/dist/esm/utility/type.js +1 -7
- package/dist/esm/utility/upload.js +13 -15
- package/dist/esm/utils/click/isClickableInput.js +3 -3
- package/dist/esm/utils/dataTransfer/Clipboard.js +5 -6
- package/dist/esm/utils/dataTransfer/DataTransfer.js +6 -10
- package/dist/esm/utils/edit/isEditable.js +3 -3
- package/dist/esm/utils/edit/maxLength.js +4 -4
- package/dist/esm/utils/edit/setFiles.js +2 -2
- package/dist/esm/utils/focus/cursor.js +2 -2
- package/dist/esm/utils/focus/getActiveElement.js +2 -2
- package/dist/esm/utils/keyDef/readNextDescriptor.js +6 -6
- package/dist/esm/utils/misc/getWindow.js +1 -1
- package/dist/esm/utils/misc/isDisabled.js +1 -1
- package/dist/esm/utils/misc/isVisible.js +1 -1
- package/dist/esm/utils/misc/level.js +3 -3
- package/dist/esm/utils/pointer/cssPointerEvents.js +11 -11
- package/dist/types/document/patchFocus.d.ts +9 -0
- package/dist/types/event/eventMap.d.ts +32 -0
- package/dist/types/event/types.d.ts +1 -1
- package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
- package/dist/types/options.d.ts +1 -1
- package/dist/types/system/keyboard.d.ts +1 -4
- package/dist/types/system/pointer/mouse.d.ts +9 -4
- package/dist/types/system/pointer/pointer.d.ts +7 -5
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('../utils/click/isClickableInput.js');
|
|
4
3
|
require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
-
require('../utils/edit/isEditable.js');
|
|
6
|
-
require('../utils/edit/maxLength.js');
|
|
7
4
|
var getWindow = require('../utils/misc/getWindow.js');
|
|
8
|
-
require('../utils/keyDef/readNextDescriptor.js');
|
|
9
|
-
require('../utils/misc/level.js');
|
|
10
|
-
require('../options.js');
|
|
11
5
|
var eventMap = require('./eventMap.js');
|
|
12
6
|
|
|
13
7
|
const eventInitializer = {
|
|
@@ -15,24 +9,28 @@ const eventInitializer = {
|
|
|
15
9
|
initClipboardEvent
|
|
16
10
|
],
|
|
17
11
|
Event: [],
|
|
12
|
+
FocusEvent: [
|
|
13
|
+
initUIEvent,
|
|
14
|
+
initFocusEvent
|
|
15
|
+
],
|
|
18
16
|
InputEvent: [
|
|
19
17
|
initUIEvent,
|
|
20
18
|
initInputEvent
|
|
21
19
|
],
|
|
22
20
|
MouseEvent: [
|
|
23
21
|
initUIEvent,
|
|
24
|
-
|
|
22
|
+
initUIEventModifiers,
|
|
25
23
|
initMouseEvent
|
|
26
24
|
],
|
|
27
25
|
PointerEvent: [
|
|
28
26
|
initUIEvent,
|
|
29
|
-
|
|
27
|
+
initUIEventModifiers,
|
|
30
28
|
initMouseEvent,
|
|
31
29
|
initPointerEvent
|
|
32
30
|
],
|
|
33
31
|
KeyboardEvent: [
|
|
34
32
|
initUIEvent,
|
|
35
|
-
|
|
33
|
+
initUIEventModifiers,
|
|
36
34
|
initKeyboardEvent
|
|
37
35
|
]
|
|
38
36
|
};
|
|
@@ -40,54 +38,54 @@ function createEvent(type, target, init) {
|
|
|
40
38
|
const window = getWindow.getWindow(target);
|
|
41
39
|
const { EventType, defaultInit } = eventMap.eventMap[type];
|
|
42
40
|
const event = new (getEventConstructors(window))[EventType](type, defaultInit);
|
|
43
|
-
eventInitializer[EventType].forEach((f)=>f(event, init !== null && init !==
|
|
41
|
+
eventInitializer[EventType].forEach((f)=>f(event, init !== null && init !== undefined ? init : {}));
|
|
44
42
|
return event;
|
|
45
43
|
}
|
|
46
44
|
/* istanbul ignore next */ function getEventConstructors(window) {
|
|
47
45
|
var _window_Event;
|
|
48
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_window_Event = window.Event) !== null && _window_Event !==
|
|
46
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_window_Event = window.Event) !== null && _window_Event !== undefined ? _window_Event : class Event {
|
|
49
47
|
};
|
|
50
48
|
var _window_AnimationEvent;
|
|
51
|
-
const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !==
|
|
49
|
+
const AnimationEvent = (_window_AnimationEvent = window.AnimationEvent) !== null && _window_AnimationEvent !== undefined ? _window_AnimationEvent : class AnimationEvent extends Event {
|
|
52
50
|
};
|
|
53
51
|
var _window_ClipboardEvent;
|
|
54
|
-
const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !==
|
|
52
|
+
const ClipboardEvent = (_window_ClipboardEvent = window.ClipboardEvent) !== null && _window_ClipboardEvent !== undefined ? _window_ClipboardEvent : class ClipboardEvent extends Event {
|
|
55
53
|
};
|
|
56
54
|
var _window_PopStateEvent;
|
|
57
|
-
const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !==
|
|
55
|
+
const PopStateEvent = (_window_PopStateEvent = window.PopStateEvent) !== null && _window_PopStateEvent !== undefined ? _window_PopStateEvent : class PopStateEvent extends Event {
|
|
58
56
|
};
|
|
59
57
|
var _window_ProgressEvent;
|
|
60
|
-
const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !==
|
|
58
|
+
const ProgressEvent = (_window_ProgressEvent = window.ProgressEvent) !== null && _window_ProgressEvent !== undefined ? _window_ProgressEvent : class ProgressEvent extends Event {
|
|
61
59
|
};
|
|
62
60
|
var _window_TransitionEvent;
|
|
63
|
-
const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !==
|
|
61
|
+
const TransitionEvent = (_window_TransitionEvent = window.TransitionEvent) !== null && _window_TransitionEvent !== undefined ? _window_TransitionEvent : class TransitionEvent extends Event {
|
|
64
62
|
};
|
|
65
63
|
var _window_UIEvent;
|
|
66
|
-
const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !==
|
|
64
|
+
const UIEvent = (_window_UIEvent = window.UIEvent) !== null && _window_UIEvent !== undefined ? _window_UIEvent : class UIEvent extends Event {
|
|
67
65
|
};
|
|
68
66
|
var _window_CompositionEvent;
|
|
69
|
-
const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !==
|
|
67
|
+
const CompositionEvent = (_window_CompositionEvent = window.CompositionEvent) !== null && _window_CompositionEvent !== undefined ? _window_CompositionEvent : class CompositionEvent extends UIEvent {
|
|
70
68
|
};
|
|
71
69
|
var _window_FocusEvent;
|
|
72
|
-
const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !==
|
|
70
|
+
const FocusEvent = (_window_FocusEvent = window.FocusEvent) !== null && _window_FocusEvent !== undefined ? _window_FocusEvent : class FocusEvent extends UIEvent {
|
|
73
71
|
};
|
|
74
72
|
var _window_InputEvent;
|
|
75
|
-
const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !==
|
|
73
|
+
const InputEvent = (_window_InputEvent = window.InputEvent) !== null && _window_InputEvent !== undefined ? _window_InputEvent : class InputEvent extends UIEvent {
|
|
76
74
|
};
|
|
77
75
|
var _window_KeyboardEvent;
|
|
78
|
-
const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !==
|
|
76
|
+
const KeyboardEvent = (_window_KeyboardEvent = window.KeyboardEvent) !== null && _window_KeyboardEvent !== undefined ? _window_KeyboardEvent : class KeyboardEvent extends UIEvent {
|
|
79
77
|
};
|
|
80
78
|
var _window_MouseEvent;
|
|
81
|
-
const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !==
|
|
79
|
+
const MouseEvent = (_window_MouseEvent = window.MouseEvent) !== null && _window_MouseEvent !== undefined ? _window_MouseEvent : class MouseEvent extends UIEvent {
|
|
82
80
|
};
|
|
83
81
|
var _window_DragEvent;
|
|
84
|
-
const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !==
|
|
82
|
+
const DragEvent = (_window_DragEvent = window.DragEvent) !== null && _window_DragEvent !== undefined ? _window_DragEvent : class DragEvent extends MouseEvent {
|
|
85
83
|
};
|
|
86
84
|
var _window_PointerEvent;
|
|
87
|
-
const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !==
|
|
85
|
+
const PointerEvent = (_window_PointerEvent = window.PointerEvent) !== null && _window_PointerEvent !== undefined ? _window_PointerEvent : class PointerEvent extends MouseEvent {
|
|
88
86
|
};
|
|
89
87
|
var _window_TouchEvent;
|
|
90
|
-
const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !==
|
|
88
|
+
const TouchEvent = (_window_TouchEvent = window.TouchEvent) !== null && _window_TouchEvent !== undefined ? _window_TouchEvent : class TouchEvent extends UIEvent {
|
|
91
89
|
};
|
|
92
90
|
/* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
|
|
93
91
|
Event,
|
|
@@ -110,18 +108,23 @@ function createEvent(type, target, init) {
|
|
|
110
108
|
function assignProps(obj, props) {
|
|
111
109
|
for (const [key, value] of Object.entries(props)){
|
|
112
110
|
Object.defineProperty(obj, key, {
|
|
113
|
-
get: ()=>value !== null && value !==
|
|
111
|
+
get: ()=>value !== null && value !== undefined ? value : null
|
|
114
112
|
});
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
115
|
function sanitizeNumber(n) {
|
|
118
|
-
return Number(n !== null && n !==
|
|
116
|
+
return Number(n !== null && n !== undefined ? n : 0);
|
|
119
117
|
}
|
|
120
118
|
function initClipboardEvent(event, { clipboardData }) {
|
|
121
119
|
assignProps(event, {
|
|
122
120
|
clipboardData
|
|
123
121
|
});
|
|
124
122
|
}
|
|
123
|
+
function initFocusEvent(event, { relatedTarget }) {
|
|
124
|
+
assignProps(event, {
|
|
125
|
+
relatedTarget
|
|
126
|
+
});
|
|
127
|
+
}
|
|
125
128
|
function initInputEvent(event, { data, inputType, isComposing }) {
|
|
126
129
|
assignProps(event, {
|
|
127
130
|
data,
|
|
@@ -132,10 +135,10 @@ function initInputEvent(event, { data, inputType, isComposing }) {
|
|
|
132
135
|
function initUIEvent(event, { view, detail }) {
|
|
133
136
|
assignProps(event, {
|
|
134
137
|
view,
|
|
135
|
-
detail: sanitizeNumber(detail !== null && detail !==
|
|
138
|
+
detail: sanitizeNumber(detail !== null && detail !== undefined ? detail : 0)
|
|
136
139
|
});
|
|
137
140
|
}
|
|
138
|
-
function
|
|
141
|
+
function initUIEventModifiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
|
|
139
142
|
assignProps(event, {
|
|
140
143
|
altKey: Boolean(altKey),
|
|
141
144
|
ctrlKey: Boolean(ctrlKey),
|
|
@@ -169,7 +172,7 @@ function initKeyboardEvent(event, { key, code, location, repeat, isComposing, ch
|
|
|
169
172
|
charCode
|
|
170
173
|
});
|
|
171
174
|
}
|
|
172
|
-
function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY = y, button, buttons, relatedTarget }) {
|
|
175
|
+
function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY = y, button, buttons, relatedTarget, offsetX, offsetY, pageX, pageY }) {
|
|
173
176
|
assignProps(event, {
|
|
174
177
|
screenX: sanitizeNumber(screenX),
|
|
175
178
|
screenY: sanitizeNumber(screenY),
|
|
@@ -179,14 +182,18 @@ function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY =
|
|
|
179
182
|
y: sanitizeNumber(clientY),
|
|
180
183
|
button: sanitizeNumber(button),
|
|
181
184
|
buttons: sanitizeNumber(buttons),
|
|
182
|
-
relatedTarget
|
|
185
|
+
relatedTarget,
|
|
186
|
+
offsetX: sanitizeNumber(offsetX),
|
|
187
|
+
offsetY: sanitizeNumber(offsetY),
|
|
188
|
+
pageX: sanitizeNumber(pageX),
|
|
189
|
+
pageY: sanitizeNumber(pageY)
|
|
183
190
|
});
|
|
184
191
|
}
|
|
185
192
|
function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary }) {
|
|
186
193
|
assignProps(event, {
|
|
187
194
|
pointerId: sanitizeNumber(pointerId),
|
|
188
|
-
width: sanitizeNumber(width),
|
|
189
|
-
height: sanitizeNumber(height),
|
|
195
|
+
width: sanitizeNumber(width !== null && width !== undefined ? width : 1),
|
|
196
|
+
height: sanitizeNumber(height !== null && height !== undefined ? height : 1),
|
|
190
197
|
pressure: sanitizeNumber(pressure),
|
|
191
198
|
tangentialPressure: sanitizeNumber(tangentialPressure),
|
|
192
199
|
tiltX: sanitizeNumber(tiltX),
|
|
@@ -24,7 +24,7 @@ function dispatchUIEvent(target, type, init, preventDefault = false) {
|
|
|
24
24
|
function dispatchEvent(target, event, preventDefault = false) {
|
|
25
25
|
var _behavior_type;
|
|
26
26
|
const type = event.type;
|
|
27
|
-
const behaviorImplementation = preventDefault ? ()=>{} : (_behavior_type = registry.behavior[type]) === null || _behavior_type ===
|
|
27
|
+
const behaviorImplementation = preventDefault ? ()=>{} : (_behavior_type = registry.behavior[type]) === null || _behavior_type === undefined ? undefined : _behavior_type.call(registry.behavior, event, target, this);
|
|
28
28
|
if (behaviorImplementation) {
|
|
29
29
|
event.preventDefault();
|
|
30
30
|
let defaultPrevented = false;
|
|
@@ -17,6 +17,14 @@ const eventMap = {
|
|
|
17
17
|
composed: true
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
+
blur: {
|
|
21
|
+
EventType: 'FocusEvent',
|
|
22
|
+
defaultInit: {
|
|
23
|
+
bubbles: false,
|
|
24
|
+
cancelable: false,
|
|
25
|
+
composed: true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
20
28
|
click: {
|
|
21
29
|
EventType: 'PointerEvent',
|
|
22
30
|
defaultInit: {
|
|
@@ -64,6 +72,30 @@ const eventMap = {
|
|
|
64
72
|
composed: true
|
|
65
73
|
}
|
|
66
74
|
},
|
|
75
|
+
focus: {
|
|
76
|
+
EventType: 'FocusEvent',
|
|
77
|
+
defaultInit: {
|
|
78
|
+
bubbles: false,
|
|
79
|
+
cancelable: false,
|
|
80
|
+
composed: true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
focusin: {
|
|
84
|
+
EventType: 'FocusEvent',
|
|
85
|
+
defaultInit: {
|
|
86
|
+
bubbles: true,
|
|
87
|
+
cancelable: false,
|
|
88
|
+
composed: true
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
focusout: {
|
|
92
|
+
EventType: 'FocusEvent',
|
|
93
|
+
defaultInit: {
|
|
94
|
+
bubbles: true,
|
|
95
|
+
cancelable: false,
|
|
96
|
+
composed: true
|
|
97
|
+
}
|
|
98
|
+
},
|
|
67
99
|
keydown: {
|
|
68
100
|
EventType: 'KeyboardEvent',
|
|
69
101
|
defaultInit: {
|
package/dist/cjs/event/focus.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('../utils/click/isClickableInput.js');
|
|
4
3
|
require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
-
require('../utils/edit/isEditable.js');
|
|
6
|
-
require('../utils/edit/maxLength.js');
|
|
7
4
|
var getActiveElement = require('../utils/focus/getActiveElement.js');
|
|
8
5
|
var isFocusable = require('../utils/focus/isFocusable.js');
|
|
9
|
-
require('../utils/keyDef/readNextDescriptor.js');
|
|
10
6
|
var findClosest = require('../utils/misc/findClosest.js');
|
|
11
|
-
require('../utils/misc/level.js');
|
|
12
|
-
require('../options.js');
|
|
13
7
|
var updateSelectionOnFocus = require('./selection/updateSelectionOnFocus.js');
|
|
14
8
|
var wrapEvent = require('./wrapEvent.js');
|
|
15
9
|
|
|
10
|
+
// Browsers do not dispatch FocusEvent if the document does not have focus.
|
|
11
|
+
// TODO: simulate FocusEvent in browsers
|
|
16
12
|
/**
|
|
17
13
|
* Focus closest focusable element.
|
|
18
14
|
*/ function focusElement(element) {
|
|
19
15
|
const target = findClosest.findClosest(element, isFocusable.isFocusable);
|
|
20
16
|
const activeElement = getActiveElement.getActiveElement(element.ownerDocument);
|
|
21
|
-
if ((target !== null && target !==
|
|
17
|
+
if ((target !== null && target !== undefined ? target : element.ownerDocument.body) === activeElement) {
|
|
22
18
|
return;
|
|
23
19
|
} else if (target) {
|
|
24
20
|
wrapEvent.wrapEvent(()=>target.focus());
|
|
25
21
|
} else {
|
|
26
|
-
wrapEvent.wrapEvent(()=>activeElement === null || activeElement ===
|
|
22
|
+
wrapEvent.wrapEvent(()=>activeElement === null || activeElement === undefined ? undefined : activeElement.blur());
|
|
27
23
|
}
|
|
28
|
-
updateSelectionOnFocus.updateSelectionOnFocus(target !== null && target !==
|
|
24
|
+
updateSelectionOnFocus.updateSelectionOnFocus(target !== null && target !== undefined ? target : element.ownerDocument.body);
|
|
29
25
|
}
|
|
30
26
|
function blurElement(element) {
|
|
31
27
|
if (!isFocusable.isFocusable(element)) return;
|
package/dist/cjs/event/index.js
CHANGED
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
var dispatchEvent = require('./dispatchEvent.js');
|
|
4
4
|
var focus = require('./focus.js');
|
|
5
5
|
var input = require('./input.js');
|
|
6
|
-
require('../utils/click/isClickableInput.js');
|
|
7
6
|
require('../utils/dataTransfer/Clipboard.js');
|
|
8
|
-
require('../utils/edit/isEditable.js');
|
|
9
|
-
require('../utils/edit/maxLength.js');
|
|
10
|
-
require('../utils/keyDef/readNextDescriptor.js');
|
|
11
|
-
require('../utils/misc/level.js');
|
|
12
|
-
require('../options.js');
|
|
13
7
|
var setSelectionPerMouse = require('./selection/setSelectionPerMouse.js');
|
|
14
8
|
var modifySelectionPerMouse = require('./selection/modifySelectionPerMouse.js');
|
|
15
9
|
var selectAll = require('./selection/selectAll.js');
|
package/dist/cjs/event/input.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../document/UI.js');
|
|
4
|
-
require('../utils/
|
|
4
|
+
var isElementType = require('../utils/misc/isElementType.js');
|
|
5
5
|
require('../utils/dataTransfer/Clipboard.js');
|
|
6
6
|
var timeValue = require('../utils/edit/timeValue.js');
|
|
7
|
-
require('../utils/edit/isEditable.js');
|
|
8
7
|
var maxLength = require('../utils/edit/maxLength.js');
|
|
9
8
|
var cursor = require('../utils/focus/cursor.js');
|
|
10
|
-
var isElementType = require('../utils/misc/isElementType.js');
|
|
11
|
-
require('../utils/keyDef/readNextDescriptor.js');
|
|
12
|
-
require('../utils/misc/level.js');
|
|
13
|
-
require('../options.js');
|
|
14
9
|
var trackValue = require('../document/trackValue.js');
|
|
15
10
|
var getInputRange = require('./selection/getInputRange.js');
|
|
16
11
|
var setSelection = require('./selection/setSelection.js');
|
|
@@ -156,7 +151,7 @@ function isValidNumberInput(value) {
|
|
|
156
151
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
157
152
|
// it allows one '.' at any place before e
|
|
158
153
|
const valueParts = value.split('e', 2);
|
|
159
|
-
return !(/[^\d.\-e]/.test(value) || Number((_value_match = value.match(/-/g)) === null || _value_match ===
|
|
154
|
+
return !(/[^\d.\-e]/.test(value) || Number((_value_match = value.match(/-/g)) === null || _value_match === undefined ? undefined : _value_match.length) > 2 || Number((_value_match1 = value.match(/\./g)) === null || _value_match1 === undefined ? undefined : _value_match1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
160
155
|
}
|
|
161
156
|
|
|
162
157
|
exports.input = input;
|
package/dist/cjs/event/radio.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('../utils/click/isClickableInput.js');
|
|
4
3
|
require('../utils/dataTransfer/Clipboard.js');
|
|
5
|
-
require('../utils/edit/isEditable.js');
|
|
6
|
-
require('../utils/edit/maxLength.js');
|
|
7
4
|
var isDisabled = require('../utils/misc/isDisabled.js');
|
|
8
5
|
var getWindow = require('../utils/misc/getWindow.js');
|
|
9
|
-
require('../utils/keyDef/readNextDescriptor.js');
|
|
10
|
-
require('../utils/misc/level.js');
|
|
11
|
-
require('../options.js');
|
|
12
6
|
var focus = require('./focus.js');
|
|
13
7
|
|
|
14
8
|
function walkRadio(instance, el, direction) {
|
|
@@ -26,6 +20,7 @@ function walkRadio(instance, el, direction) {
|
|
|
26
20
|
}
|
|
27
21
|
focus.focusElement(group[i]);
|
|
28
22
|
instance.dispatchUIEvent(group[i], 'click');
|
|
23
|
+
return;
|
|
29
24
|
}
|
|
30
25
|
}
|
|
31
26
|
|
|
@@ -11,7 +11,7 @@ var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
|
|
|
11
11
|
} else if (typeAndSelection.type === 'contenteditable') {
|
|
12
12
|
var _typeAndSelection_selection;
|
|
13
13
|
// Multi-range on contenteditable edits the first selection instead of the last
|
|
14
|
-
return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection ===
|
|
14
|
+
return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection === undefined ? undefined : _typeAndSelection_selection.getRangeAt(0);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
5
|
var isContentEditable = require('../../utils/edit/isContentEditable.js');
|
|
7
|
-
require('../../utils/edit/isEditable.js');
|
|
8
|
-
require('../../utils/edit/maxLength.js');
|
|
9
6
|
var selection = require('../../utils/focus/selection.js');
|
|
10
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
11
|
-
require('../../utils/misc/level.js');
|
|
12
|
-
require('../../options.js');
|
|
13
7
|
|
|
14
8
|
/**
|
|
15
9
|
* Determine which selection logic and selection ranges to consider.
|
|
@@ -21,10 +15,10 @@ require('../../options.js');
|
|
|
21
15
|
selection: UI.getUISelection(element)
|
|
22
16
|
};
|
|
23
17
|
}
|
|
24
|
-
const selection$1 = element === null || element ===
|
|
18
|
+
const selection$1 = element === null || element === undefined ? undefined : element.ownerDocument.getSelection();
|
|
25
19
|
// It is possible to extend a single-range selection into a contenteditable.
|
|
26
20
|
// This results in the range acting like a range outside of contenteditable.
|
|
27
|
-
const isCE = isContentEditable.getContentEditable(node) && (selection$1 === null || selection$1 ===
|
|
21
|
+
const isCE = isContentEditable.getContentEditable(node) && (selection$1 === null || selection$1 === undefined ? undefined : selection$1.anchorNode) && isContentEditable.getContentEditable(selection$1.anchorNode);
|
|
28
22
|
return {
|
|
29
23
|
type: isCE ? 'contenteditable' : 'default',
|
|
30
24
|
selection: selection$1
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
|
-
require('../../utils/edit/isEditable.js');
|
|
7
|
-
require('../../utils/edit/maxLength.js');
|
|
8
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
9
|
-
require('../../utils/misc/level.js');
|
|
10
|
-
require('../../options.js');
|
|
11
5
|
var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
|
|
12
6
|
|
|
13
7
|
/**
|
|
@@ -21,7 +15,7 @@ var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
|
|
|
21
15
|
focusOffset
|
|
22
16
|
}, 'modify');
|
|
23
17
|
}
|
|
24
|
-
(_focusNode_ownerDocument = focusNode.ownerDocument) === null || _focusNode_ownerDocument ===
|
|
18
|
+
(_focusNode_ownerDocument = focusNode.ownerDocument) === null || _focusNode_ownerDocument === undefined ? undefined : (_focusNode_ownerDocument_getSelection = _focusNode_ownerDocument.getSelection()) === null || _focusNode_ownerDocument_getSelection === undefined ? undefined : _focusNode_ownerDocument_getSelection.extend(focusNode, focusOffset);
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
exports.modifySelection = modifySelection;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
|
-
require('../../utils/edit/isEditable.js');
|
|
7
|
-
require('../../utils/edit/maxLength.js');
|
|
8
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
9
|
-
require('../../utils/misc/level.js');
|
|
10
|
-
require('../../options.js');
|
|
11
5
|
var resolveCaretPosition = require('./resolveCaretPosition.js');
|
|
12
6
|
|
|
13
7
|
function modifySelectionPerMouseMove(selectionRange, { document, target, node, offset }) {
|
|
@@ -38,8 +32,8 @@ function modifySelectionPerMouseMove(selectionRange, { document, target, node, o
|
|
|
38
32
|
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
39
33
|
}
|
|
40
34
|
const selection = document.getSelection();
|
|
41
|
-
selection === null || selection ===
|
|
42
|
-
selection === null || selection ===
|
|
35
|
+
selection === null || selection === undefined ? undefined : selection.removeAllRanges();
|
|
36
|
+
selection === null || selection === undefined ? undefined : selection.addRange(range.cloneRange());
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
|
-
require('../../utils/edit/isEditable.js');
|
|
7
|
-
require('../../utils/edit/maxLength.js');
|
|
8
5
|
var cursor = require('../../utils/focus/cursor.js');
|
|
9
6
|
var selection = require('../../utils/focus/selection.js');
|
|
10
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
11
|
-
require('../../utils/misc/level.js');
|
|
12
|
-
require('../../options.js');
|
|
13
7
|
var setSelection = require('./setSelection.js');
|
|
14
8
|
|
|
15
9
|
/**
|
|
@@ -24,7 +18,7 @@ var setSelection = require('./setSelection.js');
|
|
|
24
18
|
});
|
|
25
19
|
} else {
|
|
26
20
|
const selection = node.ownerDocument.getSelection();
|
|
27
|
-
if (!(selection === null || selection ===
|
|
21
|
+
if (!(selection === null || selection === undefined ? undefined : selection.focusNode)) {
|
|
28
22
|
return;
|
|
29
23
|
}
|
|
30
24
|
if (selection.isCollapsed) {
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
|
-
require('../../utils/edit/isEditable.js');
|
|
7
|
-
require('../../utils/edit/maxLength.js');
|
|
8
5
|
var selection = require('../../utils/focus/selection.js');
|
|
9
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
10
|
-
require('../../utils/misc/level.js');
|
|
11
|
-
require('../../options.js');
|
|
12
6
|
|
|
13
7
|
function resolveCaretPosition({ target, node, offset }) {
|
|
14
8
|
if (selection.hasOwnSelection(target)) {
|
|
15
9
|
return {
|
|
16
10
|
node: target,
|
|
17
|
-
offset: offset !== null && offset !==
|
|
11
|
+
offset: offset !== null && offset !== undefined ? offset : UI.getUIValue(target).length
|
|
18
12
|
};
|
|
19
13
|
} else if (node) {
|
|
20
14
|
return {
|
|
21
15
|
node,
|
|
22
|
-
offset: offset !== null && offset !==
|
|
16
|
+
offset: offset !== null && offset !== undefined ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
23
17
|
};
|
|
24
18
|
}
|
|
25
19
|
return findNodeAtTextOffset(target, offset);
|
|
@@ -32,7 +26,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
32
26
|
// the browser moves the cursor to the last non-empty text node inside this element.
|
|
33
27
|
// 3. Otherwise the cursor is moved to the end of the target.
|
|
34
28
|
let i = offset === undefined ? node.childNodes.length - 1 : 0;
|
|
35
|
-
const step = offset === undefined ? -1 :
|
|
29
|
+
const step = offset === undefined ? -1 : 1;
|
|
36
30
|
while(offset === undefined ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length){
|
|
37
31
|
if (offset && i === node.childNodes.length) {
|
|
38
32
|
throw new Error('The given offset is out of bounds.');
|
|
@@ -51,7 +45,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
51
45
|
if (c.nodeType === 3) {
|
|
52
46
|
return {
|
|
53
47
|
node: c,
|
|
54
|
-
offset: offset !== null && offset !==
|
|
48
|
+
offset: offset !== null && offset !== undefined ? offset : c.nodeValue.length
|
|
55
49
|
};
|
|
56
50
|
}
|
|
57
51
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
5
|
var isContentEditable = require('../../utils/edit/isContentEditable.js');
|
|
7
|
-
require('../../utils/edit/isEditable.js');
|
|
8
|
-
require('../../utils/edit/maxLength.js');
|
|
9
6
|
var selection = require('../../utils/focus/selection.js');
|
|
10
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
11
|
-
require('../../utils/misc/level.js');
|
|
12
|
-
require('../../options.js');
|
|
13
7
|
var setSelection = require('./setSelection.js');
|
|
14
8
|
|
|
15
9
|
/**
|
|
@@ -23,7 +17,7 @@ var setSelection = require('./setSelection.js');
|
|
|
23
17
|
});
|
|
24
18
|
}
|
|
25
19
|
var _getContentEditable;
|
|
26
|
-
const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !==
|
|
20
|
+
const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
|
|
27
21
|
setSelection.setSelection({
|
|
28
22
|
focusNode,
|
|
29
23
|
anchorOffset: 0,
|
|
@@ -35,9 +29,9 @@ function isAllSelected(target) {
|
|
|
35
29
|
return UI.getUISelection(target).startOffset === 0 && UI.getUISelection(target).endOffset === UI.getUIValue(target).length;
|
|
36
30
|
}
|
|
37
31
|
var _getContentEditable;
|
|
38
|
-
const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !==
|
|
32
|
+
const focusNode = (_getContentEditable = isContentEditable.getContentEditable(target)) !== null && _getContentEditable !== undefined ? _getContentEditable : target.ownerDocument.body;
|
|
39
33
|
const selection$1 = target.ownerDocument.getSelection();
|
|
40
|
-
return (selection$1 === null || selection$1 ===
|
|
34
|
+
return (selection$1 === null || selection$1 === undefined ? undefined : selection$1.anchorNode) === focusNode && selection$1.focusNode === focusNode && selection$1.anchorOffset === 0 && selection$1.focusOffset === focusNode.childNodes.length;
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
exports.isAllSelected = isAllSelected;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
|
-
require('../../utils/edit/isEditable.js');
|
|
7
|
-
require('../../utils/edit/maxLength.js');
|
|
8
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
9
|
-
require('../../utils/misc/level.js');
|
|
10
|
-
require('../../options.js');
|
|
11
5
|
var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
|
|
12
6
|
|
|
13
7
|
/**
|
|
@@ -21,7 +15,7 @@ var getTargetTypeAndSelection = require('./getTargetTypeAndSelection.js');
|
|
|
21
15
|
focusOffset
|
|
22
16
|
});
|
|
23
17
|
}
|
|
24
|
-
(_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument ===
|
|
18
|
+
(_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === undefined ? undefined : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === undefined ? undefined : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
exports.setSelection = setSelection;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var UI = require('../../document/UI.js');
|
|
4
|
-
require('../../utils/click/isClickableInput.js');
|
|
5
4
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
6
|
-
require('../../utils/edit/isEditable.js');
|
|
7
|
-
require('../../utils/edit/maxLength.js');
|
|
8
5
|
var selection = require('../../utils/focus/selection.js');
|
|
9
|
-
require('../../utils/keyDef/readNextDescriptor.js');
|
|
10
|
-
require('../../utils/misc/level.js');
|
|
11
|
-
require('../../options.js');
|
|
12
6
|
var resolveCaretPosition = require('./resolveCaretPosition.js');
|
|
13
7
|
|
|
14
8
|
function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
|
|
@@ -31,13 +25,13 @@ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }
|
|
|
31
25
|
// TODO: implement modifying selection per shift/ctrl+mouse
|
|
32
26
|
if (targetHasOwnSelection) {
|
|
33
27
|
UI.setUISelection(target, {
|
|
34
|
-
anchorOffset: start !== null && start !==
|
|
35
|
-
focusOffset: end !== null && end !==
|
|
28
|
+
anchorOffset: start !== null && start !== undefined ? start : text.length,
|
|
29
|
+
focusOffset: end !== null && end !== undefined ? end : text.length
|
|
36
30
|
});
|
|
37
31
|
return {
|
|
38
32
|
node: target,
|
|
39
|
-
start: start !== null && start !==
|
|
40
|
-
end: end !== null && end !==
|
|
33
|
+
start: start !== null && start !== undefined ? start : 0,
|
|
34
|
+
end: end !== null && end !== undefined ? end : text.length
|
|
41
35
|
};
|
|
42
36
|
} else {
|
|
43
37
|
const { node: startNode, offset: startOffset } = resolveCaretPosition.resolveCaretPosition({
|
|
@@ -58,8 +52,8 @@ function setSelectionPerMouseDown({ document, target, clickCount, node, offset }
|
|
|
58
52
|
throw new Error('The given offset is out of bounds.');
|
|
59
53
|
}
|
|
60
54
|
const selection = document.getSelection();
|
|
61
|
-
selection === null || selection ===
|
|
62
|
-
selection === null || selection ===
|
|
55
|
+
selection === null || selection === undefined ? undefined : selection.removeAllRanges();
|
|
56
|
+
selection === null || selection === undefined ? undefined : selection.addRange(range.cloneRange());
|
|
63
57
|
return range;
|
|
64
58
|
}
|
|
65
59
|
}
|
|
@@ -70,7 +64,7 @@ function getTextRange(text, pos, clickCount) {
|
|
|
70
64
|
pos
|
|
71
65
|
];
|
|
72
66
|
}
|
|
73
|
-
const textPos = pos !== null && pos !==
|
|
67
|
+
const textPos = pos !== null && pos !== undefined ? pos : text.length;
|
|
74
68
|
if (clickCount % 3 === 2) {
|
|
75
69
|
return [
|
|
76
70
|
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
|