@testing-library/user-event 14.0.0-beta.2 → 14.0.0-beta.6
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/index.cjs +2896 -0
- package/dist/index.mjs +2967 -0
- package/dist/{clipboard → types/clipboard}/copy.d.ts +0 -0
- package/dist/{clipboard → types/clipboard}/cut.d.ts +0 -0
- package/dist/{clipboard → types/clipboard}/index.d.ts +0 -0
- package/dist/{clipboard → types/clipboard}/paste.d.ts +0 -0
- package/dist/{convenience → types/convenience}/click.d.ts +0 -0
- package/dist/{convenience → types/convenience}/hover.d.ts +0 -0
- package/dist/{convenience → types/convenience}/index.d.ts +0 -0
- package/dist/{convenience → types/convenience}/tab.d.ts +0 -0
- package/dist/{document → types/document}/index.d.ts +0 -0
- package/dist/{document → types/document}/interceptor.d.ts +0 -0
- package/dist/{document → types/document}/selection.d.ts +0 -0
- package/dist/{document → types/document}/value.d.ts +0 -0
- package/dist/{index.d.ts → types/index.d.ts} +0 -0
- package/dist/{keyboard → types/keyboard}/index.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/keyboardAction.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/parseKeyDef.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/arrow.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/character.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/combination.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/control.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/plugins/functional.d.ts +0 -3
- package/dist/{keyboard → types/keyboard}/plugins/index.d.ts +0 -0
- package/dist/types/keyboard/plugins/modifiers.d.ts +8 -0
- package/dist/{keyboard → types/keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/shared/index.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/types.d.ts +19 -5
- package/dist/{options.d.ts → types/options.d.ts} +0 -0
- package/dist/{pointer → types/pointer}/index.d.ts +0 -0
- package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
- package/dist/{pointer → types/pointer}/parseKeyDef.d.ts +0 -0
- package/dist/{pointer → types/pointer}/pointerAction.d.ts +0 -0
- package/dist/{pointer → types/pointer}/pointerMove.d.ts +0 -0
- package/dist/{pointer → types/pointer}/pointerPress.d.ts +0 -0
- package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
- package/dist/{pointer → types/pointer}/types.d.ts +0 -0
- package/dist/{setup → types/setup}/api.d.ts +0 -0
- package/dist/{setup → types/setup}/config.d.ts +0 -0
- package/dist/{setup → types/setup}/directApi.d.ts +0 -0
- package/dist/{setup → types/setup}/index.d.ts +0 -0
- package/dist/{setup → types/setup}/setup.d.ts +0 -0
- package/dist/{setup → types/setup}/wrapAsync.d.ts +0 -0
- package/dist/{utility → types/utility}/clear.d.ts +0 -0
- package/dist/{utility → types/utility}/index.d.ts +0 -0
- package/dist/{utility → types/utility}/selectOptions.d.ts +0 -0
- package/dist/{utility → types/utility}/type.d.ts +0 -0
- package/dist/{utility → types/utility}/upload.d.ts +0 -0
- package/dist/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/Blob.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/Clipboard.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/DataTransfer.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/FileList.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/calculateNewValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/editInputElement.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isValidDateValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isValidInputTimeValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/prepareInput.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/setFiles.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/copySelection.d.ts +0 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/{utils → types/utils}/focus/focus.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selectAll.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selection.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
- package/dist/{utils → types/utils}/index.d.ts +3 -0
- package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +17 -0
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
- package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/findClosest.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/getDocumentFromNode.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/hasFormSubmit.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/hasPointerEvents.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
- package/dist/{utils → types/utils}/pointer/firePointerEvents.d.ts +0 -0
- package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +13 -30
- package/dist/clipboard/copy.js +0 -36
- package/dist/clipboard/cut.js +0 -42
- package/dist/clipboard/index.js +0 -44
- package/dist/clipboard/paste.js +0 -47
- package/dist/convenience/click.js +0 -52
- package/dist/convenience/hover.js +0 -31
- package/dist/convenience/index.js +0 -44
- package/dist/convenience/tab.js +0 -12
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.js +0 -90
- package/dist/document/value.js +0 -77
- package/dist/index.js +0 -13
- package/dist/keyboard/getEventProps.d.ts +0 -15
- package/dist/keyboard/getEventProps.js +0 -27
- package/dist/keyboard/index.js +0 -42
- package/dist/keyboard/keyMap.js +0 -119
- package/dist/keyboard/keyboardAction.js +0 -156
- package/dist/keyboard/parseKeyDef.js +0 -61
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.js +0 -173
- package/dist/keyboard/plugins/combination.js +0 -19
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.js +0 -158
- package/dist/keyboard/plugins/index.js +0 -33
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/types.js +0 -19
- package/dist/options.js +0 -36
- package/dist/pointer/index.js +0 -56
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.js +0 -34
- package/dist/pointer/pointerAction.js +0 -46
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.js +0 -330
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.js +0 -1
- package/dist/setup/api.js +0 -111
- package/dist/setup/config.js +0 -8
- package/dist/setup/directApi.js +0 -95
- package/dist/setup/index.js +0 -27
- package/dist/setup/setup.js +0 -98
- package/dist/setup/wrapAsync.js +0 -15
- package/dist/utility/clear.js +0 -30
- package/dist/utility/index.js +0 -57
- package/dist/utility/selectOptions.js +0 -132
- package/dist/utility/type.js +0 -37
- package/dist/utility/upload.js +0 -64
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/dataTransfer/Blob.js +0 -21
- package/dist/utils/dataTransfer/Clipboard.js +0 -188
- package/dist/utils/dataTransfer/DataTransfer.js +0 -158
- package/dist/utils/dataTransfer/FileList.js +0 -23
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.js +0 -46
- package/dist/utils/edit/editInputElement.js +0 -53
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.js +0 -77
- package/dist/utils/edit/setFiles.js +0 -72
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/copySelection.js +0 -36
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.js +0 -71
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selectAll.js +0 -51
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.js +0 -499
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/getDocumentFromNode.js +0 -14
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.js +0 -31
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/firePointerEvents.js +0 -112
- package/dist/utils/pointer/mouseButtons.js +0 -45
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.copySelection = copySelection;
|
|
7
|
-
|
|
8
|
-
var _document = require("../../document");
|
|
9
|
-
|
|
10
|
-
var _DataTransfer = require("../dataTransfer/DataTransfer");
|
|
11
|
-
|
|
12
|
-
var _selection = require("./selection");
|
|
13
|
-
|
|
14
|
-
function copySelection(target) {
|
|
15
|
-
const data = (0, _selection.hasOwnSelection)(target) ? {
|
|
16
|
-
'text/plain': readSelectedValueFromInput(target)
|
|
17
|
-
} : // TODO: We could implement text/html copying of DOM nodes here
|
|
18
|
-
{
|
|
19
|
-
'text/plain': String(target.ownerDocument.getSelection())
|
|
20
|
-
};
|
|
21
|
-
const dt = (0, _DataTransfer.createDataTransfer)();
|
|
22
|
-
|
|
23
|
-
for (const type in data) {
|
|
24
|
-
if (data[type]) {
|
|
25
|
-
dt.setData(type, data[type]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return dt;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function readSelectedValueFromInput(target) {
|
|
33
|
-
const sel = (0, _document.getUISelection)(target);
|
|
34
|
-
const val = (0, _document.getUIValue)(target);
|
|
35
|
-
return val.substring(sel.startOffset, sel.endOffset);
|
|
36
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.focus = focus;
|
|
7
|
-
|
|
8
|
-
var _eventWrapper = require("../misc/eventWrapper");
|
|
9
|
-
|
|
10
|
-
var _getActiveElement = require("./getActiveElement");
|
|
11
|
-
|
|
12
|
-
var _isFocusable = require("./isFocusable");
|
|
13
|
-
|
|
14
|
-
var _selection = require("./selection");
|
|
15
|
-
|
|
16
|
-
function focus(element) {
|
|
17
|
-
if (!(0, _isFocusable.isFocusable)(element)) return;
|
|
18
|
-
const isAlreadyActive = (0, _getActiveElement.getActiveElement)(element.ownerDocument) === element;
|
|
19
|
-
if (isAlreadyActive) return;
|
|
20
|
-
(0, _eventWrapper.eventWrapper)(() => element.focus());
|
|
21
|
-
(0, _selection.updateSelectionOnFocus)(element);
|
|
22
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getActiveElement = getActiveElement;
|
|
7
|
-
|
|
8
|
-
var _isDisabled = require("../misc/isDisabled");
|
|
9
|
-
|
|
10
|
-
function getActiveElement(document) {
|
|
11
|
-
const activeElement = document.activeElement;
|
|
12
|
-
|
|
13
|
-
if (activeElement != null && activeElement.shadowRoot) {
|
|
14
|
-
return getActiveElement(activeElement.shadowRoot);
|
|
15
|
-
} else {
|
|
16
|
-
// Browser does not yield disabled elements as document.activeElement - jsdom does
|
|
17
|
-
if ((0, _isDisabled.isDisabled)(activeElement)) {
|
|
18
|
-
return document.ownerDocument ? // TODO: verify behavior in ShadowRoot
|
|
19
|
-
|
|
20
|
-
/* istanbul ignore next */
|
|
21
|
-
document.ownerDocument.body : document.body;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return activeElement;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getTabDestination = getTabDestination;
|
|
7
|
-
|
|
8
|
-
var _isDisabled = require("../misc/isDisabled");
|
|
9
|
-
|
|
10
|
-
var _isElementType = require("../misc/isElementType");
|
|
11
|
-
|
|
12
|
-
var _isVisible = require("../misc/isVisible");
|
|
13
|
-
|
|
14
|
-
var _selector = require("./selector");
|
|
15
|
-
|
|
16
|
-
function getTabDestination(activeElement, shift) {
|
|
17
|
-
const document = activeElement.ownerDocument;
|
|
18
|
-
const focusableElements = document.querySelectorAll(_selector.FOCUSABLE_SELECTOR);
|
|
19
|
-
const enabledElements = Array.from(focusableElements).filter(el => el === activeElement || el.getAttribute('tabindex') !== '-1' && !(0, _isDisabled.isDisabled)(el) && // Hidden elements are not tabable
|
|
20
|
-
(0, _isVisible.isVisible)(el));
|
|
21
|
-
|
|
22
|
-
if (activeElement.getAttribute('tabindex') !== '-1') {
|
|
23
|
-
// tabindex has no effect if the active element has tabindex="-1"
|
|
24
|
-
enabledElements.sort((a, b) => Number(a.getAttribute('tabindex')) - Number(b.getAttribute('tabindex')));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const checkedRadio = {};
|
|
28
|
-
let prunedElements = [document.body];
|
|
29
|
-
const activeRadioGroup = (0, _isElementType.isElementType)(activeElement, 'input', {
|
|
30
|
-
type: 'radio'
|
|
31
|
-
}) ? activeElement.name : undefined;
|
|
32
|
-
enabledElements.forEach(currentElement => {
|
|
33
|
-
const el = currentElement; // For radio groups keep only the active radio
|
|
34
|
-
// If there is no active radio, keep only the checked radio
|
|
35
|
-
// If there is no checked radio, treat like everything else
|
|
36
|
-
|
|
37
|
-
if ((0, _isElementType.isElementType)(el, 'input', {
|
|
38
|
-
type: 'radio'
|
|
39
|
-
}) && el.name) {
|
|
40
|
-
// If the active element is part of the group, add only that
|
|
41
|
-
if (el === activeElement) {
|
|
42
|
-
prunedElements.push(el);
|
|
43
|
-
return;
|
|
44
|
-
} else if (el.name === activeRadioGroup) {
|
|
45
|
-
return;
|
|
46
|
-
} // If we stumble upon a checked radio, remove the others
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (el.checked) {
|
|
50
|
-
prunedElements = prunedElements.filter(e => !(0, _isElementType.isElementType)(e, 'input', {
|
|
51
|
-
type: 'radio',
|
|
52
|
-
name: el.name
|
|
53
|
-
}));
|
|
54
|
-
prunedElements.push(el);
|
|
55
|
-
checkedRadio[el.name] = el;
|
|
56
|
-
return;
|
|
57
|
-
} // If we already found the checked one, skip
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (typeof checkedRadio[el.name] !== 'undefined') {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
prunedElements.push(el);
|
|
66
|
-
});
|
|
67
|
-
const currentIndex = prunedElements.findIndex(el => el === activeElement);
|
|
68
|
-
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
69
|
-
const defaultIndex = shift ? prunedElements.length - 1 : 0;
|
|
70
|
-
return prunedElements[nextIndex] || prunedElements[defaultIndex];
|
|
71
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isFocusable = isFocusable;
|
|
7
|
-
|
|
8
|
-
var _selector = require("./selector");
|
|
9
|
-
|
|
10
|
-
function isFocusable(element) {
|
|
11
|
-
return element.matches(_selector.FOCUSABLE_SELECTOR);
|
|
12
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isAllSelected = isAllSelected;
|
|
7
|
-
exports.selectAll = selectAll;
|
|
8
|
-
|
|
9
|
-
var _document = require("../../document");
|
|
10
|
-
|
|
11
|
-
var _isContentEditable = require("../edit/isContentEditable");
|
|
12
|
-
|
|
13
|
-
var _isEditable = require("../edit/isEditable");
|
|
14
|
-
|
|
15
|
-
var _isElementType = require("../misc/isElementType");
|
|
16
|
-
|
|
17
|
-
var _selection = require("./selection");
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Expand a selection like the browser does when pressing Ctrl+A.
|
|
21
|
-
*/
|
|
22
|
-
function selectAll(target) {
|
|
23
|
-
var _getContentEditable;
|
|
24
|
-
|
|
25
|
-
if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
|
|
26
|
-
return (0, _selection.setSelection)({
|
|
27
|
-
focusNode: target,
|
|
28
|
-
anchorOffset: 0,
|
|
29
|
-
focusOffset: (0, _document.getUIValue)(target).length
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const focusNode = (_getContentEditable = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable : target.ownerDocument.body;
|
|
34
|
-
(0, _selection.setSelection)({
|
|
35
|
-
focusNode,
|
|
36
|
-
anchorOffset: 0,
|
|
37
|
-
focusOffset: focusNode.childNodes.length
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isAllSelected(target) {
|
|
42
|
-
var _getContentEditable2;
|
|
43
|
-
|
|
44
|
-
if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
|
|
45
|
-
return (0, _document.getUISelection)(target).startOffset === 0 && (0, _document.getUISelection)(target).endOffset === (0, _document.getUIValue)(target).length;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const focusNode = (_getContentEditable2 = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable2 : target.ownerDocument.body;
|
|
49
|
-
const selection = target.ownerDocument.getSelection();
|
|
50
|
-
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
51
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getInputRange = getInputRange;
|
|
7
|
-
exports.hasOwnSelection = hasOwnSelection;
|
|
8
|
-
exports.modifySelection = modifySelection;
|
|
9
|
-
exports.setSelection = setSelection;
|
|
10
|
-
exports.setSelectionRange = setSelectionRange;
|
|
11
|
-
exports.updateSelectionOnFocus = updateSelectionOnFocus;
|
|
12
|
-
|
|
13
|
-
var _isElementType = require("../misc/isElementType");
|
|
14
|
-
|
|
15
|
-
var _document = require("../../document");
|
|
16
|
-
|
|
17
|
-
var _isEditable = require("../edit/isEditable");
|
|
18
|
-
|
|
19
|
-
var _isContentEditable = require("../edit/isContentEditable");
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Backward-compatible selection.
|
|
23
|
-
*
|
|
24
|
-
* Handles input elements and contenteditable if it only contains a single text node.
|
|
25
|
-
*/
|
|
26
|
-
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
27
|
-
var _element$firstChild;
|
|
28
|
-
|
|
29
|
-
if (hasOwnSelection(element)) {
|
|
30
|
-
return setSelection({
|
|
31
|
-
focusNode: element,
|
|
32
|
-
anchorOffset,
|
|
33
|
-
focusOffset
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/* istanbul ignore else */
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if ((0, _isContentEditable.isContentEditable)(element) && ((_element$firstChild = element.firstChild) == null ? void 0 : _element$firstChild.nodeType) === 3) {
|
|
40
|
-
return setSelection({
|
|
41
|
-
focusNode: element.firstChild,
|
|
42
|
-
anchorOffset,
|
|
43
|
-
focusOffset
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/* istanbul ignore next */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
throw new Error('Not implemented. The result of this interaction is unreliable.');
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Determine if the element has its own selection implementation
|
|
53
|
-
* and does not interact with the Document Selection API.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
function hasOwnSelection(node) {
|
|
58
|
-
return isElement(node) && ((0, _isElementType.isElementType)(node, 'textarea') || (0, _isElementType.isElementType)(node, 'input') && node.type in _isEditable.editableInputTypes);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function isElement(node) {
|
|
62
|
-
return node.nodeType === 1;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Determine which selection logic and selection ranges to consider.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
function getTargetTypeAndSelection(node) {
|
|
70
|
-
const element = getElement(node);
|
|
71
|
-
|
|
72
|
-
if (element && hasOwnSelection(element)) {
|
|
73
|
-
return {
|
|
74
|
-
type: 'input',
|
|
75
|
-
selection: (0, _document.getUISelection)(element)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const selection = element == null ? void 0 : element.ownerDocument.getSelection(); // It is possible to extend a single-range selection into a contenteditable.
|
|
80
|
-
// This results in the range acting like a range outside of contenteditable.
|
|
81
|
-
|
|
82
|
-
const isCE = (0, _isContentEditable.getContentEditable)(node) && (selection == null ? void 0 : selection.anchorNode) && (0, _isContentEditable.getContentEditable)(selection.anchorNode);
|
|
83
|
-
return {
|
|
84
|
-
type: isCE ? 'contenteditable' : 'default',
|
|
85
|
-
selection
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function getElement(node) {
|
|
90
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Reset the Document Selection when moving focus into an element
|
|
94
|
-
* with own selection implementation.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function updateSelectionOnFocus(element) {
|
|
99
|
-
const selection = element.ownerDocument.getSelection();
|
|
100
|
-
/* istanbul ignore if */
|
|
101
|
-
|
|
102
|
-
if (!(selection != null && selection.focusNode)) {
|
|
103
|
-
return;
|
|
104
|
-
} // If the focus moves inside an element with own selection implementation,
|
|
105
|
-
// the document selection will be this element.
|
|
106
|
-
// But if the focused element is inside a contenteditable,
|
|
107
|
-
// 1) a collapsed selection will be retained.
|
|
108
|
-
// 2) other selections will be replaced by a cursor
|
|
109
|
-
// 2.a) at the start of the first child if it is a text node
|
|
110
|
-
// 2.b) at the start of the contenteditable.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (hasOwnSelection(element)) {
|
|
114
|
-
const contenteditable = (0, _isContentEditable.getContentEditable)(selection.focusNode);
|
|
115
|
-
|
|
116
|
-
if (contenteditable) {
|
|
117
|
-
if (!selection.isCollapsed) {
|
|
118
|
-
var _contenteditable$firs;
|
|
119
|
-
|
|
120
|
-
const focusNode = ((_contenteditable$firs = contenteditable.firstChild) == null ? void 0 : _contenteditable$firs.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
121
|
-
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
selection.setBaseAndExtent(element, 0, element, 0);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Get the range that would be overwritten by input.
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
function getInputRange(focusNode) {
|
|
134
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
135
|
-
|
|
136
|
-
if (typeAndSelection.type === 'input') {
|
|
137
|
-
return typeAndSelection.selection;
|
|
138
|
-
} else if (typeAndSelection.type === 'contenteditable') {
|
|
139
|
-
var _typeAndSelection$sel;
|
|
140
|
-
|
|
141
|
-
// Multi-range on contenteditable edits the first selection instead of the last
|
|
142
|
-
return (_typeAndSelection$sel = typeAndSelection.selection) == null ? void 0 : _typeAndSelection$sel.getRangeAt(0);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Extend/shrink the selection like with Shift+Arrows or Shift+Mouse
|
|
147
|
-
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
function modifySelection({
|
|
151
|
-
focusNode,
|
|
152
|
-
focusOffset
|
|
153
|
-
}) {
|
|
154
|
-
var _focusNode$ownerDocum, _focusNode$ownerDocum2;
|
|
155
|
-
|
|
156
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
157
|
-
|
|
158
|
-
if (typeAndSelection.type === 'input') {
|
|
159
|
-
return (0, _document.setUISelection)(focusNode, {
|
|
160
|
-
anchorOffset: typeAndSelection.selection.anchorOffset,
|
|
161
|
-
focusOffset
|
|
162
|
-
}, 'modify');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
(_focusNode$ownerDocum = focusNode.ownerDocument) == null ? void 0 : (_focusNode$ownerDocum2 = _focusNode$ownerDocum.getSelection()) == null ? void 0 : _focusNode$ownerDocum2.extend(focusNode, focusOffset);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Set the selection
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
function setSelection({
|
|
173
|
-
focusNode,
|
|
174
|
-
focusOffset,
|
|
175
|
-
anchorNode = focusNode,
|
|
176
|
-
anchorOffset = focusOffset
|
|
177
|
-
}) {
|
|
178
|
-
var _anchorNode$ownerDocu, _anchorNode$ownerDocu2;
|
|
179
|
-
|
|
180
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
181
|
-
|
|
182
|
-
if (typeAndSelection.type === 'input') {
|
|
183
|
-
return (0, _document.setUISelection)(focusNode, {
|
|
184
|
-
anchorOffset,
|
|
185
|
-
focusOffset
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
(_anchorNode$ownerDocu = anchorNode.ownerDocument) == null ? void 0 : (_anchorNode$ownerDocu2 = _anchorNode$ownerDocu.getSelection()) == null ? void 0 : _anchorNode$ownerDocu2.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
190
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FOCUSABLE_SELECTOR = void 0;
|
|
7
|
-
const FOCUSABLE_SELECTOR = ['input:not([type=hidden]):not([disabled])', 'button:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', '[contenteditable=""]', '[contenteditable="true"]', 'a[href]', '[tabindex]:not([disabled])'].join(', ');
|
|
8
|
-
exports.FOCUSABLE_SELECTOR = FOCUSABLE_SELECTOR;
|