@testing-library/user-event 14.0.0-beta.3 → 14.0.0-beta.7

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.
Files changed (193) hide show
  1. package/dist/index.cjs +2941 -0
  2. package/dist/index.mjs +3012 -0
  3. package/dist/types/clipboard/copy.d.ts +2 -0
  4. package/dist/types/clipboard/cut.d.ts +2 -0
  5. package/dist/{clipboard → types/clipboard}/index.d.ts +0 -0
  6. package/dist/types/clipboard/paste.d.ts +2 -0
  7. package/dist/types/convenience/click.d.ts +4 -0
  8. package/dist/types/convenience/hover.d.ts +3 -0
  9. package/dist/{convenience → types/convenience}/index.d.ts +0 -0
  10. package/dist/types/convenience/tab.d.ts +4 -0
  11. package/dist/{document → types/document}/index.d.ts +0 -0
  12. package/dist/{document → types/document}/interceptor.d.ts +0 -0
  13. package/dist/{document → types/document}/selection.d.ts +0 -0
  14. package/dist/{document → types/document}/value.d.ts +0 -0
  15. package/dist/{index.d.ts → types/index.d.ts} +1 -0
  16. package/dist/{keyboard → types/keyboard}/index.d.ts +2 -2
  17. package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
  18. package/dist/{keyboard → types/keyboard}/keyboardAction.d.ts +0 -0
  19. package/dist/{keyboard → types/keyboard}/parseKeyDef.d.ts +0 -0
  20. package/dist/{keyboard → types/keyboard}/plugins/arrow.d.ts +0 -0
  21. package/dist/{keyboard → types/keyboard}/plugins/character.d.ts +0 -0
  22. package/dist/{keyboard → types/keyboard}/plugins/combination.d.ts +0 -0
  23. package/dist/{keyboard → types/keyboard}/plugins/control.d.ts +0 -0
  24. package/dist/{keyboard → types/keyboard}/plugins/functional.d.ts +0 -3
  25. package/dist/{keyboard → types/keyboard}/plugins/index.d.ts +0 -0
  26. package/dist/types/keyboard/plugins/modifiers.d.ts +8 -0
  27. package/dist/{keyboard → types/keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
  28. package/dist/{keyboard → types/keyboard}/shared/index.d.ts +0 -0
  29. package/dist/{keyboard → types/keyboard}/types.d.ts +19 -5
  30. package/dist/{options.d.ts → types/options.d.ts} +23 -8
  31. package/dist/{pointer → types/pointer}/index.d.ts +2 -2
  32. package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
  33. package/dist/{pointer → types/pointer}/parseKeyDef.d.ts +0 -0
  34. package/dist/{pointer → types/pointer}/pointerAction.d.ts +0 -0
  35. package/dist/types/pointer/pointerMove.d.ts +6 -0
  36. package/dist/{pointer → types/pointer}/pointerPress.d.ts +2 -2
  37. package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
  38. package/dist/{pointer → types/pointer}/types.d.ts +0 -0
  39. package/dist/{setup → types/setup}/api.d.ts +0 -0
  40. package/dist/{setup → types/setup}/config.d.ts +0 -0
  41. package/dist/{setup → types/setup}/directApi.d.ts +1 -2
  42. package/dist/{setup → types/setup}/index.d.ts +6 -2
  43. package/dist/types/setup/setup.d.ts +19 -0
  44. package/dist/{setup → types/setup}/wrapAsync.d.ts +0 -0
  45. package/dist/types/utility/clear.d.ts +2 -0
  46. package/dist/{utility → types/utility}/index.d.ts +0 -0
  47. package/dist/types/utility/selectOptions.d.ts +3 -0
  48. package/dist/types/utility/type.d.ts +9 -0
  49. package/dist/types/utility/upload.d.ts +5 -0
  50. package/dist/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
  51. package/dist/{utils → types/utils}/dataTransfer/Blob.d.ts +0 -0
  52. package/dist/{utils → types/utils}/dataTransfer/Clipboard.d.ts +0 -0
  53. package/dist/{utils → types/utils}/dataTransfer/DataTransfer.d.ts +0 -0
  54. package/dist/{utils → types/utils}/dataTransfer/FileList.d.ts +0 -0
  55. package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
  56. package/dist/{utils → types/utils}/edit/calculateNewValue.d.ts +0 -0
  57. package/dist/{utils → types/utils}/edit/editInputElement.d.ts +0 -0
  58. package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
  59. package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
  60. package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
  61. package/dist/{utils → types/utils}/edit/isValidDateValue.d.ts +0 -0
  62. package/dist/{utils → types/utils}/edit/isValidInputTimeValue.d.ts +0 -0
  63. package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
  64. package/dist/{utils → types/utils}/edit/prepareInput.d.ts +0 -0
  65. package/dist/{utils → types/utils}/edit/setFiles.d.ts +0 -0
  66. package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
  67. package/dist/{utils → types/utils}/focus/copySelection.d.ts +0 -0
  68. package/dist/types/utils/focus/cursor.d.ts +9 -0
  69. package/dist/{utils → types/utils}/focus/focus.d.ts +0 -0
  70. package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
  71. package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
  72. package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
  73. package/dist/{utils → types/utils}/focus/selectAll.d.ts +0 -0
  74. package/dist/{utils → types/utils}/focus/selection.d.ts +0 -0
  75. package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
  76. package/dist/{utils → types/utils}/index.d.ts +5 -1
  77. package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
  78. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +17 -0
  79. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
  80. package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
  81. package/dist/{utils → types/utils}/misc/findClosest.d.ts +0 -0
  82. package/dist/{utils → types/utils}/misc/getDocumentFromNode.d.ts +0 -0
  83. package/dist/{utils → types/utils}/misc/hasFormSubmit.d.ts +0 -0
  84. package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
  85. package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
  86. package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
  87. package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
  88. package/dist/types/utils/misc/level.d.ts +17 -0
  89. package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
  90. package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
  91. package/dist/{utils → types/utils}/pointer/firePointerEvents.d.ts +0 -0
  92. package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
  93. package/package.json +13 -30
  94. package/dist/clipboard/copy.d.ts +0 -2
  95. package/dist/clipboard/copy.js +0 -36
  96. package/dist/clipboard/cut.d.ts +0 -2
  97. package/dist/clipboard/cut.js +0 -42
  98. package/dist/clipboard/index.js +0 -44
  99. package/dist/clipboard/paste.d.ts +0 -2
  100. package/dist/clipboard/paste.js +0 -47
  101. package/dist/convenience/click.d.ts +0 -4
  102. package/dist/convenience/click.js +0 -52
  103. package/dist/convenience/hover.d.ts +0 -3
  104. package/dist/convenience/hover.js +0 -31
  105. package/dist/convenience/index.js +0 -44
  106. package/dist/convenience/tab.d.ts +0 -4
  107. package/dist/convenience/tab.js +0 -12
  108. package/dist/document/index.js +0 -100
  109. package/dist/document/interceptor.js +0 -37
  110. package/dist/document/selection.js +0 -90
  111. package/dist/document/value.js +0 -77
  112. package/dist/index.js +0 -13
  113. package/dist/keyboard/getEventProps.d.ts +0 -15
  114. package/dist/keyboard/getEventProps.js +0 -27
  115. package/dist/keyboard/index.js +0 -42
  116. package/dist/keyboard/keyMap.js +0 -119
  117. package/dist/keyboard/keyboardAction.js +0 -156
  118. package/dist/keyboard/parseKeyDef.js +0 -61
  119. package/dist/keyboard/plugins/arrow.js +0 -28
  120. package/dist/keyboard/plugins/character.js +0 -173
  121. package/dist/keyboard/plugins/combination.js +0 -19
  122. package/dist/keyboard/plugins/control.js +0 -52
  123. package/dist/keyboard/plugins/functional.js +0 -158
  124. package/dist/keyboard/plugins/index.js +0 -33
  125. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
  126. package/dist/keyboard/shared/index.js +0 -18
  127. package/dist/keyboard/types.js +0 -19
  128. package/dist/options.js +0 -36
  129. package/dist/pointer/index.js +0 -56
  130. package/dist/pointer/keyMap.js +0 -29
  131. package/dist/pointer/parseKeyDef.js +0 -34
  132. package/dist/pointer/pointerAction.js +0 -46
  133. package/dist/pointer/pointerMove.d.ts +0 -6
  134. package/dist/pointer/pointerMove.js +0 -136
  135. package/dist/pointer/pointerPress.js +0 -327
  136. package/dist/pointer/resolveSelectionTarget.js +0 -75
  137. package/dist/pointer/types.js +0 -1
  138. package/dist/setup/api.js +0 -111
  139. package/dist/setup/config.js +0 -8
  140. package/dist/setup/directApi.js +0 -95
  141. package/dist/setup/index.js +0 -27
  142. package/dist/setup/setup.d.ts +0 -74
  143. package/dist/setup/setup.js +0 -98
  144. package/dist/setup/wrapAsync.js +0 -15
  145. package/dist/utility/clear.d.ts +0 -2
  146. package/dist/utility/clear.js +0 -30
  147. package/dist/utility/index.js +0 -57
  148. package/dist/utility/selectOptions.d.ts +0 -3
  149. package/dist/utility/selectOptions.js +0 -132
  150. package/dist/utility/type.d.ts +0 -9
  151. package/dist/utility/type.js +0 -37
  152. package/dist/utility/upload.d.ts +0 -5
  153. package/dist/utility/upload.js +0 -64
  154. package/dist/utils/click/isClickableInput.js +0 -14
  155. package/dist/utils/dataTransfer/Blob.js +0 -21
  156. package/dist/utils/dataTransfer/Clipboard.js +0 -188
  157. package/dist/utils/dataTransfer/DataTransfer.js +0 -158
  158. package/dist/utils/dataTransfer/FileList.js +0 -23
  159. package/dist/utils/edit/buildTimeValue.js +0 -44
  160. package/dist/utils/edit/calculateNewValue.js +0 -46
  161. package/dist/utils/edit/editInputElement.js +0 -53
  162. package/dist/utils/edit/getValue.js +0 -23
  163. package/dist/utils/edit/isContentEditable.js +0 -25
  164. package/dist/utils/edit/isEditable.js +0 -42
  165. package/dist/utils/edit/isValidDateValue.js +0 -12
  166. package/dist/utils/edit/isValidInputTimeValue.js +0 -12
  167. package/dist/utils/edit/maxLength.js +0 -50
  168. package/dist/utils/edit/prepareInput.js +0 -77
  169. package/dist/utils/edit/setFiles.js +0 -72
  170. package/dist/utils/focus/blur.js +0 -19
  171. package/dist/utils/focus/copySelection.js +0 -36
  172. package/dist/utils/focus/focus.js +0 -22
  173. package/dist/utils/focus/getActiveElement.js +0 -26
  174. package/dist/utils/focus/getTabDestination.js +0 -84
  175. package/dist/utils/focus/isFocusable.js +0 -12
  176. package/dist/utils/focus/selectAll.js +0 -51
  177. package/dist/utils/focus/selection.js +0 -190
  178. package/dist/utils/focus/selector.js +0 -8
  179. package/dist/utils/index.js +0 -499
  180. package/dist/utils/keyDef/readNextDescriptor.js +0 -102
  181. package/dist/utils/misc/eventWrapper.js +0 -16
  182. package/dist/utils/misc/findClosest.js +0 -20
  183. package/dist/utils/misc/getDocumentFromNode.js +0 -14
  184. package/dist/utils/misc/hasFormSubmit.js +0 -10
  185. package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
  186. package/dist/utils/misc/hasPointerEvents.js +0 -24
  187. package/dist/utils/misc/isDescendantOrSelf.js +0 -20
  188. package/dist/utils/misc/isDisabled.js +0 -12
  189. package/dist/utils/misc/isElementType.js +0 -24
  190. package/dist/utils/misc/isVisible.js +0 -31
  191. package/dist/utils/misc/wait.js +0 -10
  192. package/dist/utils/pointer/firePointerEvents.js +0 -110
  193. package/dist/utils/pointer/mouseButtons.js +0 -45
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.prepareInput = prepareInput;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _utils = require("../../utils");
11
-
12
- function prepareInput(data, element, inputType = 'insertText') {
13
- const inputRange = (0, _utils.getInputRange)(element);
14
- /* istanbul ignore if */
15
-
16
- if (!inputRange) {
17
- return;
18
- }
19
-
20
- if ('startContainer' in inputRange) {
21
- return {
22
- commit: () => {
23
- const del = !inputRange.collapsed;
24
-
25
- if (del) {
26
- inputRange.deleteContents();
27
- }
28
-
29
- if (data) {
30
- if (inputRange.endContainer.nodeType === 3) {
31
- const offset = inputRange.endOffset;
32
- inputRange.endContainer.insertData(offset, data);
33
- inputRange.setStart(inputRange.endContainer, offset + data.length);
34
- inputRange.setEnd(inputRange.endContainer, offset + data.length);
35
- } else {
36
- const text = element.ownerDocument.createTextNode(data);
37
- inputRange.insertNode(text);
38
- inputRange.setStart(text, data.length);
39
- inputRange.setEnd(text, data.length);
40
- }
41
- }
42
-
43
- if (del || data) {
44
- _dom.fireEvent.input(element, {
45
- inputType
46
- });
47
- }
48
- }
49
- };
50
- } else {
51
- return {
52
- getNewValue: () => (0, _utils.calculateNewValue)(data, element, inputRange, inputType).newValue,
53
- commit: () => {
54
- const {
55
- newValue,
56
- newOffset,
57
- oldValue
58
- } = (0, _utils.calculateNewValue)(data, element, inputRange, inputType);
59
-
60
- if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
61
- return;
62
- }
63
-
64
- (0, _utils.editInputElement)(element, {
65
- newValue,
66
- newSelection: {
67
- node: element,
68
- offset: newOffset
69
- },
70
- eventOverrides: {
71
- inputType
72
- }
73
- });
74
- }
75
- };
76
- }
77
- }
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setFiles = setFiles;
7
- // It is not possible to create a real FileList programmatically.
8
- // Therefore assigning `files` property with a programmatically created FileList results in an error.
9
- // Just assigning the property (as per fireEvent) breaks the interweaving with the `value` property.
10
- const fakeFiles = Symbol('files and value properties are mocked');
11
-
12
- function setFiles(el, files) {
13
- var _el$fakeFiles;
14
-
15
- (_el$fakeFiles = el[fakeFiles]) == null ? void 0 : _el$fakeFiles.restore();
16
- const objectDescriptors = Object.getOwnPropertyDescriptors(el);
17
- const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
18
-
19
- function restore() {
20
- Object.defineProperties(el, {
21
- files: { ...prototypeDescriptors.files,
22
- ...objectDescriptors.files
23
- },
24
- value: { ...prototypeDescriptors.value,
25
- ...objectDescriptors.value
26
- },
27
- type: { ...prototypeDescriptors.type,
28
- ...objectDescriptors.type
29
- }
30
- });
31
- }
32
-
33
- el[fakeFiles] = {
34
- restore
35
- };
36
- Object.defineProperties(el, {
37
- files: { ...prototypeDescriptors.files,
38
- ...objectDescriptors.files,
39
- get: () => files
40
- },
41
- value: { ...prototypeDescriptors.value,
42
- ...objectDescriptors.value,
43
- get: () => files.length ? `C:\\fakepath\\${files[0].name}` : '',
44
-
45
- set(v) {
46
- if (v === '') {
47
- restore();
48
- } else {
49
- var _objectDescriptors$va;
50
-
51
- (_objectDescriptors$va = objectDescriptors.value.set) == null ? void 0 : _objectDescriptors$va.call(el, v);
52
- }
53
- }
54
-
55
- },
56
- // eslint-disable-next-line accessor-pairs
57
- type: { ...prototypeDescriptors.type,
58
- ...objectDescriptors.type,
59
-
60
- set(v) {
61
- if (v !== 'file') {
62
- restore() // In the browser the value will be empty.
63
- // In Jsdom the value will be the same as
64
- // before this element became file input - which might be empty.
65
- ;
66
- el.type = v;
67
- }
68
- }
69
-
70
- }
71
- });
72
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.blur = blur;
7
-
8
- var _eventWrapper = require("../misc/eventWrapper");
9
-
10
- var _getActiveElement = require("./getActiveElement");
11
-
12
- var _isFocusable = require("./isFocusable");
13
-
14
- function blur(element) {
15
- if (!(0, _isFocusable.isFocusable)(element)) return;
16
- const wasActive = (0, _getActiveElement.getActiveElement)(element.ownerDocument) === element;
17
- if (!wasActive) return;
18
- (0, _eventWrapper.eventWrapper)(() => element.blur());
19
- }
@@ -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,84 +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) => {
25
- const i = Number(a.getAttribute('tabindex'));
26
- const j = Number(b.getAttribute('tabindex'));
27
-
28
- if (i === j) {
29
- return 0;
30
- } else if (i === 0) {
31
- return 1;
32
- } else if (j === 0) {
33
- return -1;
34
- }
35
-
36
- return i - j;
37
- });
38
- }
39
-
40
- const checkedRadio = {};
41
- let prunedElements = [document.body];
42
- const activeRadioGroup = (0, _isElementType.isElementType)(activeElement, 'input', {
43
- type: 'radio'
44
- }) ? activeElement.name : undefined;
45
- enabledElements.forEach(currentElement => {
46
- const el = currentElement; // For radio groups keep only the active radio
47
- // If there is no active radio, keep only the checked radio
48
- // If there is no checked radio, treat like everything else
49
-
50
- if ((0, _isElementType.isElementType)(el, 'input', {
51
- type: 'radio'
52
- }) && el.name) {
53
- // If the active element is part of the group, add only that
54
- if (el === activeElement) {
55
- prunedElements.push(el);
56
- return;
57
- } else if (el.name === activeRadioGroup) {
58
- return;
59
- } // If we stumble upon a checked radio, remove the others
60
-
61
-
62
- if (el.checked) {
63
- prunedElements = prunedElements.filter(e => !(0, _isElementType.isElementType)(e, 'input', {
64
- type: 'radio',
65
- name: el.name
66
- }));
67
- prunedElements.push(el);
68
- checkedRadio[el.name] = el;
69
- return;
70
- } // If we already found the checked one, skip
71
-
72
-
73
- if (typeof checkedRadio[el.name] !== 'undefined') {
74
- return;
75
- }
76
- }
77
-
78
- prunedElements.push(el);
79
- });
80
- const currentIndex = prunedElements.findIndex(el => el === activeElement);
81
- const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
82
- const defaultIndex = shift ? prunedElements.length - 1 : 0;
83
- return prunedElements[nextIndex] || prunedElements[defaultIndex];
84
- }
@@ -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;