@testing-library/user-event 14.4.2 → 14.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_interop/dtl.js +30 -0
- package/dist/cjs/_interop/dtlEventMap.js +30 -0
- package/dist/cjs/_interop/dtlHelpers.js +30 -0
- package/dist/cjs/clipboard/copy.js +6 -16
- package/dist/cjs/clipboard/cut.js +6 -16
- package/dist/cjs/clipboard/paste.js +6 -16
- package/dist/cjs/convenience/click.js +1 -4
- package/dist/cjs/convenience/hover.js +2 -12
- package/dist/cjs/convenience/tab.js +1 -1
- package/dist/cjs/document/UI.js +94 -0
- package/dist/cjs/document/copySelection.js +37 -0
- package/dist/cjs/document/getValueOrTextContent.js +27 -0
- package/dist/cjs/document/index.js +13 -68
- package/dist/cjs/document/interceptor.js +89 -4
- package/dist/cjs/document/prepareDocument.js +67 -0
- package/dist/cjs/document/trackValue.js +65 -0
- package/dist/cjs/event/behavior/click.js +8 -12
- package/dist/cjs/event/behavior/cut.js +5 -11
- package/dist/cjs/event/behavior/keydown.js +43 -47
- package/dist/cjs/event/behavior/keypress.js +12 -12
- package/dist/cjs/event/behavior/keyup.js +6 -8
- package/dist/cjs/event/behavior/paste.js +7 -13
- package/dist/cjs/event/createEvent.js +43 -50
- package/dist/cjs/event/dispatchEvent.js +21 -3
- package/dist/cjs/event/eventMap.js +2 -2
- package/dist/cjs/event/focus.js +44 -0
- package/dist/cjs/event/index.js +24 -17
- package/dist/cjs/{utils/edit → event}/input.js +52 -50
- package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/cjs/event/selection/getInputRange.js +20 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +41 -0
- package/dist/cjs/event/selection/index.js +26 -0
- package/dist/cjs/event/selection/modifySelection.js +30 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +50 -0
- package/dist/cjs/event/selection/moveSelection.js +48 -0
- package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +10 -18
- package/dist/cjs/event/selection/selectAll.js +48 -0
- package/dist/cjs/event/selection/setSelection.js +30 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +91 -0
- package/dist/cjs/event/selection/setSelectionRange.js +40 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +46 -0
- package/dist/cjs/event/wrapEvent.js +3 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/keyboard/index.js +13 -23
- package/dist/cjs/keyboard/parseKeyDef.js +9 -17
- package/dist/cjs/options.js +0 -28
- package/dist/cjs/pointer/index.js +28 -38
- package/dist/cjs/pointer/keyMap.js +1 -1
- package/dist/cjs/pointer/parseKeyDef.js +2 -10
- package/dist/cjs/setup/api.js +19 -17
- package/dist/cjs/setup/directApi.js +6 -6
- package/dist/cjs/setup/index.js +0 -2
- package/dist/cjs/setup/setup.js +70 -42
- package/dist/cjs/setup/wrapAsync.js +3 -2
- package/dist/cjs/system/index.js +15 -2
- package/dist/cjs/system/keyboard.js +34 -21
- package/dist/cjs/system/pointer/buttons.js +14 -1
- package/dist/cjs/system/pointer/device.js +14 -1
- package/dist/cjs/system/pointer/index.js +60 -45
- package/dist/cjs/system/pointer/mouse.js +77 -56
- package/dist/cjs/system/pointer/pointer.js +56 -42
- package/dist/cjs/system/pointer/shared.js +10 -0
- package/dist/cjs/utility/clear.js +10 -11
- package/dist/cjs/utility/selectOptions.js +28 -29
- package/dist/cjs/utility/type.js +6 -15
- package/dist/cjs/utility/upload.js +9 -18
- package/dist/cjs/utils/dataTransfer/Clipboard.js +26 -24
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +25 -9
- package/dist/cjs/utils/edit/isEditable.js +6 -10
- package/dist/cjs/utils/edit/maxLength.js +6 -17
- package/dist/cjs/utils/edit/setFiles.js +4 -4
- package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
- package/dist/cjs/utils/focus/cursor.js +2 -18
- package/dist/cjs/utils/focus/getActiveElement.js +4 -3
- package/dist/cjs/utils/focus/selection.js +1 -271
- package/dist/cjs/utils/focus/selector.js +1 -1
- package/dist/cjs/utils/index.js +7 -32
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -5
- package/dist/cjs/utils/misc/getTreeDiff.js +3 -3
- package/dist/cjs/utils/misc/getWindow.js +3 -2
- package/dist/cjs/utils/misc/isDisabled.js +3 -3
- package/dist/cjs/utils/misc/isVisible.js +3 -2
- package/dist/cjs/utils/misc/level.js +4 -9
- package/dist/cjs/utils/misc/wait.js +1 -1
- package/dist/cjs/utils/pointer/cssPointerEvents.js +31 -40
- package/dist/esm/_interop/dtl.js +6 -0
- package/dist/esm/_interop/dtlEventMap.js +6 -0
- package/dist/esm/_interop/dtlHelpers.js +6 -0
- package/dist/esm/clipboard/copy.js +6 -16
- package/dist/esm/clipboard/cut.js +6 -16
- package/dist/esm/clipboard/paste.js +6 -16
- package/dist/esm/convenience/click.js +1 -4
- package/dist/esm/convenience/hover.js +2 -12
- package/dist/esm/convenience/tab.js +1 -1
- package/dist/esm/document/UI.js +79 -0
- package/dist/esm/document/copySelection.js +33 -0
- package/dist/esm/document/getValueOrTextContent.js +23 -0
- package/dist/esm/document/index.js +4 -66
- package/dist/esm/document/interceptor.js +87 -5
- package/dist/esm/document/prepareDocument.js +63 -0
- package/dist/esm/document/trackValue.js +59 -0
- package/dist/esm/event/behavior/click.js +8 -12
- package/dist/esm/event/behavior/cut.js +5 -11
- package/dist/esm/event/behavior/keydown.js +36 -40
- package/dist/esm/event/behavior/keypress.js +12 -12
- package/dist/esm/event/behavior/keyup.js +6 -8
- package/dist/esm/event/behavior/paste.js +7 -13
- package/dist/esm/event/createEvent.js +43 -50
- package/dist/esm/event/dispatchEvent.js +20 -4
- package/dist/esm/event/eventMap.js +2 -2
- package/dist/esm/event/focus.js +39 -0
- package/dist/esm/event/index.js +14 -19
- package/dist/esm/{utils/edit → event}/input.js +39 -37
- package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +37 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +26 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +46 -0
- package/dist/esm/event/selection/moveSelection.js +44 -0
- package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +9 -17
- package/dist/esm/event/selection/selectAll.js +43 -0
- package/dist/esm/event/selection/setSelection.js +26 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +87 -0
- package/dist/esm/event/selection/setSelectionRange.js +36 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +42 -0
- package/dist/esm/event/wrapEvent.js +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/keyboard/index.js +13 -23
- package/dist/esm/keyboard/parseKeyDef.js +9 -17
- package/dist/esm/options.js +1 -26
- package/dist/esm/pointer/index.js +28 -38
- package/dist/esm/pointer/keyMap.js +1 -1
- package/dist/esm/pointer/parseKeyDef.js +2 -10
- package/dist/esm/setup/api.js +33 -12
- package/dist/esm/setup/directApi.js +6 -6
- package/dist/esm/setup/index.js +0 -1
- package/dist/esm/setup/setup.js +66 -39
- package/dist/esm/setup/wrapAsync.js +2 -1
- package/dist/esm/system/index.js +15 -2
- package/dist/esm/system/keyboard.js +34 -21
- package/dist/esm/system/pointer/buttons.js +14 -1
- package/dist/esm/system/pointer/device.js +14 -1
- package/dist/esm/system/pointer/index.js +61 -45
- package/dist/esm/system/pointer/mouse.js +74 -53
- package/dist/esm/system/pointer/pointer.js +55 -41
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +10 -11
- package/dist/esm/utility/selectOptions.js +24 -25
- package/dist/esm/utility/type.js +5 -14
- package/dist/esm/utility/upload.js +9 -18
- package/dist/esm/utils/dataTransfer/Clipboard.js +26 -24
- package/dist/esm/utils/dataTransfer/DataTransfer.js +25 -9
- package/dist/esm/utils/edit/isEditable.js +4 -8
- package/dist/esm/utils/edit/maxLength.js +5 -17
- package/dist/esm/utils/edit/setFiles.js +4 -4
- package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
- package/dist/esm/utils/focus/cursor.js +2 -18
- package/dist/esm/utils/focus/getActiveElement.js +4 -3
- package/dist/esm/utils/focus/selection.js +3 -265
- package/dist/esm/utils/focus/selector.js +1 -1
- package/dist/esm/utils/index.js +4 -11
- package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -5
- package/dist/esm/utils/misc/getTreeDiff.js +3 -3
- package/dist/esm/utils/misc/getWindow.js +2 -1
- package/dist/esm/utils/misc/isDisabled.js +3 -3
- package/dist/esm/utils/misc/isVisible.js +3 -2
- package/dist/esm/utils/misc/level.js +4 -9
- package/dist/esm/utils/misc/wait.js +1 -1
- package/dist/esm/utils/pointer/cssPointerEvents.js +31 -40
- package/dist/types/_interop/dtl.d.ts +3 -0
- package/dist/types/_interop/dtlEventMap.d.ts +3 -0
- package/dist/types/_interop/dtlHelpers.d.ts +3 -0
- package/dist/types/clipboard/copy.d.ts +1 -1
- package/dist/types/clipboard/cut.d.ts +1 -1
- package/dist/types/clipboard/paste.d.ts +1 -1
- package/dist/types/convenience/click.d.ts +1 -1
- package/dist/types/convenience/hover.d.ts +1 -1
- package/dist/types/convenience/tab.d.ts +1 -1
- package/dist/types/document/UI.d.ts +42 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -10
- package/dist/types/document/interceptor.d.ts +6 -3
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/registry.d.ts +2 -2
- package/dist/types/event/createEvent.d.ts +1 -1
- package/dist/types/event/dispatchEvent.d.ts +5 -2
- package/dist/types/event/eventMap.d.ts +8 -0
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +6 -4
- package/dist/types/event/input.d.ts +2 -0
- package/dist/types/event/radio.d.ts +4 -0
- package/dist/types/event/selection/getInputRange.d.ts +5 -0
- package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
- package/dist/types/event/selection/index.d.ts +15 -0
- package/dist/types/event/selection/modifySelection.d.ts +8 -0
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
- package/dist/types/event/selection/moveSelection.d.ts +4 -0
- package/dist/types/event/selection/setSelection.d.ts +10 -0
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
- package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
- package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
- package/dist/types/event/types.d.ts +3 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/options.d.ts +2 -10
- package/dist/types/pointer/index.d.ts +7 -7
- package/dist/types/setup/api.d.ts +23 -5
- package/dist/types/setup/directApi.d.ts +5 -5
- package/dist/types/setup/index.d.ts +2 -15
- package/dist/types/setup/setup.d.ts +25 -7
- package/dist/types/system/keyboard.d.ts +4 -4
- package/dist/types/system/pointer/buttons.d.ts +2 -2
- package/dist/types/system/pointer/device.d.ts +1 -1
- package/dist/types/system/pointer/index.d.ts +7 -25
- package/dist/types/system/pointer/mouse.d.ts +6 -6
- package/dist/types/system/pointer/pointer.d.ts +8 -8
- package/dist/types/system/pointer/shared.d.ts +20 -0
- package/dist/types/utility/clear.d.ts +1 -1
- package/dist/types/utility/selectOptions.d.ts +1 -1
- package/dist/types/utility/type.d.ts +4 -4
- package/dist/types/utility/upload.d.ts +1 -1
- package/dist/types/utils/click/isClickableInput.d.ts +2 -2
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
- package/dist/types/utils/edit/isEditable.d.ts +6 -7
- package/dist/types/utils/edit/maxLength.d.ts +14 -1
- package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
- package/dist/types/utils/focus/selection.d.ts +4 -69
- package/dist/types/utils/index.d.ts +2 -9
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +1 -1
- package/dist/types/utils/misc/isElementType.d.ts +1 -1
- package/dist/types/utils/misc/level.d.ts +4 -13
- package/dist/types/utils/misc/wait.d.ts +2 -2
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
- package/package.json +24 -12
- package/dist/cjs/document/selection.js +0 -108
- package/dist/cjs/document/setRangeText.js +0 -21
- package/dist/cjs/document/value.js +0 -127
- package/dist/cjs/setup/config.js +0 -7
- package/dist/cjs/utils/edit/getValue.js +0 -35
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
- package/dist/cjs/utils/focus/blur.js +0 -16
- package/dist/cjs/utils/focus/copySelection.js +0 -46
- package/dist/cjs/utils/focus/focus.js +0 -29
- package/dist/cjs/utils/focus/selectAll.js +0 -56
- package/dist/cjs/utils/misc/eventWrapper.js +0 -15
- package/dist/esm/document/selection.js +0 -100
- package/dist/esm/document/setRangeText.js +0 -17
- package/dist/esm/document/value.js +0 -117
- package/dist/esm/setup/config.js +0 -3
- package/dist/esm/utils/edit/getValue.js +0 -31
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
- package/dist/esm/utils/focus/blur.js +0 -12
- package/dist/esm/utils/focus/copySelection.js +0 -42
- package/dist/esm/utils/focus/focus.js +0 -25
- package/dist/esm/utils/focus/selectAll.js +0 -51
- package/dist/esm/utils/misc/eventWrapper.js +0 -11
- package/dist/types/document/selection.d.ts +0 -29
- package/dist/types/document/setRangeText.d.ts +0 -1
- package/dist/types/document/value.d.ts +0 -26
- package/dist/types/setup/config.d.ts +0 -6
- package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/types/utils/edit/getValue.d.ts +0 -1
- package/dist/types/utils/edit/input.d.ts +0 -2
- package/dist/types/utils/edit/walkRadio.d.ts +0 -4
- package/dist/types/utils/focus/blur.d.ts +0 -2
- package/dist/types/utils/focus/focus.d.ts +0 -5
- package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
- /package/dist/cjs/{event → _interop}/dom-events.d.js +0 -0
- /package/dist/cjs/{utils/misc → _interop}/dom-helpers.d.js +0 -0
- /package/dist/esm/{event → _interop}/dom-events.d.js +0 -0
- /package/dist/esm/{utils/misc → _interop}/dom-helpers.d.js +0 -0
- /package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
- /package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
- /package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
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,22 +76,25 @@ 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
|
-
const { newValue
|
|
97
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
96
98
|
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
@@ -109,18 +111,18 @@ 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
|
});
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
function calculateNewValue(inputData, node, { startOffset
|
|
125
|
+
function calculateNewValue(inputData, node, { startOffset, endOffset }, inputType) {
|
|
124
126
|
const value = getUIValue(node);
|
|
125
127
|
const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
|
|
126
128
|
const prolog = value.substring(0, prologEnd);
|
|
@@ -143,17 +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) {
|
|
151
|
-
var
|
|
153
|
+
var _value_match, _value_match1;
|
|
152
154
|
// the browser allows some invalid input but not others
|
|
153
155
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
154
156
|
// it allows one '.' at any place before e
|
|
155
157
|
const valueParts = value.split('e', 2);
|
|
156
|
-
return !(/[^\d.\-e]/.test(value) || Number((
|
|
158
|
+
return !(/[^\d.\-e]/.test(value) || Number((_value_match = value.match(/-/g)) === null || _value_match === void 0 ? void 0 : _value_match.length) > 2 || Number((_value_match1 = value.match(/\./g)) === null || _value_match1 === void 0 ? void 0 : _value_match1.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
157
159
|
}
|
|
158
160
|
|
|
159
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 _typeAndSelection_selection;
|
|
11
|
+
// Multi-range on contenteditable edits the first selection instead of the last
|
|
12
|
+
return (_typeAndSelection_selection = typeAndSelection.selection) === null || _typeAndSelection_selection === void 0 ? void 0 : _typeAndSelection_selection.getRangeAt(0);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getInputRange };
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
var _element, _selection;
|
|
17
|
+
const element = getElement(node);
|
|
18
|
+
if (element && hasOwnSelection(element)) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'input',
|
|
21
|
+
selection: getUISelection(element)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const selection = (_element = element) === null || _element === void 0 ? void 0 : _element.ownerDocument.getSelection();
|
|
25
|
+
// It is possible to extend a single-range selection into a contenteditable.
|
|
26
|
+
// This results in the range acting like a range outside of contenteditable.
|
|
27
|
+
const isCE = getContentEditable(node) && ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
28
|
+
return {
|
|
29
|
+
type: isCE ? 'contenteditable' : 'default',
|
|
30
|
+
selection
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getElement(node) {
|
|
34
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
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 _focusNode_ownerDocument_getSelection, _focusNode_ownerDocument;
|
|
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
|
+
(_focusNode_ownerDocument = focusNode.ownerDocument) === null || _focusNode_ownerDocument === void 0 ? void 0 : (_focusNode_ownerDocument_getSelection = _focusNode_ownerDocument.getSelection()) === null || _focusNode_ownerDocument_getSelection === void 0 ? void 0 : _focusNode_ownerDocument_getSelection.extend(focusNode, focusOffset);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { modifySelection };
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
var _selection, _selection1;
|
|
33
|
+
const range = selectionRange.cloneRange();
|
|
34
|
+
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
35
|
+
if (cmp < 0) {
|
|
36
|
+
range.setStart(selectionFocus.node, selectionFocus.offset);
|
|
37
|
+
} else if (cmp > 0) {
|
|
38
|
+
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
39
|
+
}
|
|
40
|
+
const selection = document.getSelection();
|
|
41
|
+
(_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
|
|
42
|
+
(_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { modifySelectionPerMouseMove };
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
var _selection;
|
|
26
|
+
const selection = node.ownerDocument.getSelection();
|
|
27
|
+
if (!((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.focusNode)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (selection.isCollapsed) {
|
|
31
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
32
|
+
if (nextPosition) {
|
|
33
|
+
setSelection({
|
|
34
|
+
focusNode: nextPosition.node,
|
|
35
|
+
focusOffset: nextPosition.offset
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { moveSelection };
|
|
@@ -1,23 +1,15 @@
|
|
|
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
|
-
function resolveCaretPosition({ target
|
|
12
|
+
function resolveCaretPosition({ target, node, offset }) {
|
|
21
13
|
if (hasOwnSelection(target)) {
|
|
22
14
|
return {
|
|
23
15
|
node: target,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getUIValue, 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
|
+
import { setSelection } from './setSelection.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Expand a selection like the browser does when pressing Ctrl+A.
|
|
16
|
+
*/ function selectAll(target) {
|
|
17
|
+
if (hasOwnSelection(target)) {
|
|
18
|
+
return setSelection({
|
|
19
|
+
focusNode: target,
|
|
20
|
+
anchorOffset: 0,
|
|
21
|
+
focusOffset: getUIValue(target).length
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
var _getContentEditable;
|
|
25
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
26
|
+
setSelection({
|
|
27
|
+
focusNode,
|
|
28
|
+
anchorOffset: 0,
|
|
29
|
+
focusOffset: focusNode.childNodes.length
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function isAllSelected(target) {
|
|
33
|
+
var _selection;
|
|
34
|
+
if (hasOwnSelection(target)) {
|
|
35
|
+
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
36
|
+
}
|
|
37
|
+
var _getContentEditable;
|
|
38
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
39
|
+
const selection = target.ownerDocument.getSelection();
|
|
40
|
+
return ((_selection = selection) === null || _selection === void 0 ? void 0 : _selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { isAllSelected, selectAll };
|
|
@@ -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
|
+
* Set the selection
|
|
14
|
+
*/ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
|
|
15
|
+
var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
|
|
16
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
17
|
+
if (typeAndSelection.type === 'input') {
|
|
18
|
+
return setUISelection(focusNode, {
|
|
19
|
+
anchorOffset,
|
|
20
|
+
focusOffset
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
(_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === void 0 ? void 0 : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === void 0 ? void 0 : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { setSelection };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getUIValue, 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 { hasNoSelection, hasOwnSelection } from '../../utils/focus/selection.js';
|
|
8
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../../utils/misc/level.js';
|
|
10
|
+
import '../../options.js';
|
|
11
|
+
import { resolveCaretPosition } from './resolveCaretPosition.js';
|
|
12
|
+
|
|
13
|
+
function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
|
|
14
|
+
if (hasNoSelection(target)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const targetHasOwnSelection = hasOwnSelection(target);
|
|
18
|
+
// On non-input elements the text selection per multiple click
|
|
19
|
+
// can extend beyond the target boundaries.
|
|
20
|
+
// The exact mechanism what is considered in the same line is unclear.
|
|
21
|
+
// Looks it might be every inline element.
|
|
22
|
+
// TODO: Check what might be considered part of the same line of text.
|
|
23
|
+
const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
|
|
24
|
+
const [start, end] = node ? // which elements might be considered in the same line of text.
|
|
25
|
+
// TODO: support expanding initial range on multiple clicks if node is given
|
|
26
|
+
[
|
|
27
|
+
offset,
|
|
28
|
+
offset
|
|
29
|
+
] : getTextRange(text, offset, clickCount);
|
|
30
|
+
// TODO: implement modifying selection per shift/ctrl+mouse
|
|
31
|
+
if (targetHasOwnSelection) {
|
|
32
|
+
setUISelection(target, {
|
|
33
|
+
anchorOffset: start !== null && start !== void 0 ? start : text.length,
|
|
34
|
+
focusOffset: end !== null && end !== void 0 ? end : text.length
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
node: target,
|
|
38
|
+
start: start !== null && start !== void 0 ? start : 0,
|
|
39
|
+
end: end !== null && end !== void 0 ? end : text.length
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
var _selection, _selection1;
|
|
43
|
+
const { node: startNode, offset: startOffset } = resolveCaretPosition({
|
|
44
|
+
target,
|
|
45
|
+
node,
|
|
46
|
+
offset: start
|
|
47
|
+
});
|
|
48
|
+
const { node: endNode, offset: endOffset } = resolveCaretPosition({
|
|
49
|
+
target,
|
|
50
|
+
node,
|
|
51
|
+
offset: end
|
|
52
|
+
});
|
|
53
|
+
const range = target.ownerDocument.createRange();
|
|
54
|
+
try {
|
|
55
|
+
range.setStart(startNode, startOffset);
|
|
56
|
+
range.setEnd(endNode, endOffset);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw new Error('The given offset is out of bounds.');
|
|
59
|
+
}
|
|
60
|
+
const selection = document.getSelection();
|
|
61
|
+
(_selection = selection) === null || _selection === void 0 ? void 0 : _selection.removeAllRanges();
|
|
62
|
+
(_selection1 = selection) === null || _selection1 === void 0 ? void 0 : _selection1.addRange(range.cloneRange());
|
|
63
|
+
return range;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getTextRange(text, pos, clickCount) {
|
|
67
|
+
if (clickCount % 3 === 1 || text.length === 0) {
|
|
68
|
+
return [
|
|
69
|
+
pos,
|
|
70
|
+
pos
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
const textPos = pos !== null && pos !== void 0 ? pos : text.length;
|
|
74
|
+
if (clickCount % 3 === 2) {
|
|
75
|
+
return [
|
|
76
|
+
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
|
|
77
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
// triple click
|
|
81
|
+
return [
|
|
82
|
+
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
|
|
83
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { setSelectionPerMouseDown };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import '../../utils/click/isClickableInput.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
4
|
+
import '../../utils/edit/isEditable.js';
|
|
5
|
+
import '../../utils/edit/maxLength.js';
|
|
6
|
+
import '@testing-library/dom/dist/helpers.js';
|
|
7
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
8
|
+
import '../../utils/keyDef/readNextDescriptor.js';
|
|
9
|
+
import '../../utils/misc/level.js';
|
|
10
|
+
import '../../options.js';
|
|
11
|
+
import { setSelection } from './setSelection.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Backward-compatible selection.
|
|
15
|
+
*
|
|
16
|
+
* Handles input elements and contenteditable if it only contains a single text node.
|
|
17
|
+
*/ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
18
|
+
var _element_firstChild;
|
|
19
|
+
if (hasOwnSelection(element)) {
|
|
20
|
+
return setSelection({
|
|
21
|
+
focusNode: element,
|
|
22
|
+
anchorOffset,
|
|
23
|
+
focusOffset
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
|
|
27
|
+
return setSelection({
|
|
28
|
+
focusNode: element.firstChild,
|
|
29
|
+
anchorOffset,
|
|
30
|
+
focusOffset
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { setSelectionRange };
|