@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,188 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.attachClipboardStubToView = attachClipboardStubToView;
7
- exports.createClipboardItem = createClipboardItem;
8
- exports.detachClipboardStubFromView = detachClipboardStubFromView;
9
- exports.readDataTransferFromClipboard = readDataTransferFromClipboard;
10
- exports.resetClipboardStubOnView = resetClipboardStubOnView;
11
- exports.writeDataTransferToClipboard = writeDataTransferToClipboard;
12
-
13
- var _ = require("..");
14
-
15
- // Clipboard is not available in jsdom
16
- class ClipboardItemStub {
17
- constructor(data) {
18
- this.data = void 0;
19
- this.data = data;
20
- }
21
-
22
- get types() {
23
- return Array.from(Object.keys(this.data));
24
- }
25
-
26
- async getType(type) {
27
- const data = await this.data[type];
28
-
29
- if (!data) {
30
- throw new Error(`${type} is not one of the available MIME types on this item.`);
31
- }
32
-
33
- return data instanceof Blob ? data : new Blob([data], {
34
- type
35
- });
36
- }
37
-
38
- }
39
-
40
- const ClipboardStubControl = Symbol('Manage ClipboardSub');
41
-
42
- class ClipboardStub extends EventTarget {
43
- constructor(...args) {
44
- super(...args);
45
- this.items = [];
46
- this[ClipboardStubControl] = void 0;
47
- }
48
-
49
- async read() {
50
- return Array.from(this.items);
51
- }
52
-
53
- async readText() {
54
- let text = '';
55
-
56
- for (const item of this.items) {
57
- const type = item.types.includes('text/plain') ? 'text/plain' : item.types.find(t => t.startsWith('text/'));
58
-
59
- if (type) {
60
- text += await item.getType(type).then(b => (0, _.readBlobText)(b));
61
- }
62
- }
63
-
64
- return text;
65
- }
66
-
67
- async write(data) {
68
- this.items = data;
69
- }
70
-
71
- async writeText(text) {
72
- this.items = [createClipboardItem(text)];
73
- }
74
-
75
- } // MDN lists string|Blob|Promise<Blob|string> as possible types in ClipboardItemData
76
- // lib.dom.d.ts lists only Promise<Blob|string>
77
- // https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/ClipboardItem#syntax
78
-
79
-
80
- function createClipboardItem(...blobs) {
81
- // use real ClipboardItem if available
82
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
83
- const constructor = typeof ClipboardItem === 'undefined' ? ClipboardItemStub :
84
- /* istanbul ignore next */
85
- ClipboardItem;
86
- return new constructor(Object.fromEntries(blobs.map(b => [typeof b === 'string' ? 'text/plain' : b.type, Promise.resolve(b)])));
87
- }
88
-
89
- function attachClipboardStubToView(window) {
90
- if (window.navigator.clipboard instanceof ClipboardStub) {
91
- return window.navigator.clipboard[ClipboardStubControl];
92
- }
93
-
94
- const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, 'clipboard');
95
- let stub = new ClipboardStub();
96
- const control = {
97
- resetClipboardStub: () => {
98
- stub = new ClipboardStub();
99
- stub[ClipboardStubControl] = control;
100
- },
101
- detachClipboardStub: () => {
102
- /* istanbul ignore if */
103
- if (realClipboard) {
104
- Object.defineProperty(window.navigator, 'clipboard', realClipboard);
105
- } else {
106
- Object.defineProperty(window.navigator, 'clipboard', {
107
- value: undefined,
108
- configurable: true
109
- });
110
- }
111
- }
112
- };
113
- stub[ClipboardStubControl] = control;
114
- Object.defineProperty(window.navigator, 'clipboard', {
115
- get: () => stub,
116
- configurable: true
117
- });
118
- return stub[ClipboardStubControl];
119
- }
120
-
121
- function resetClipboardStubOnView(window) {
122
- if (window.navigator.clipboard instanceof ClipboardStub) {
123
- window.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
124
- }
125
- }
126
-
127
- function detachClipboardStubFromView(window) {
128
- if (window.navigator.clipboard instanceof ClipboardStub) {
129
- window.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
130
- }
131
- }
132
-
133
- async function readDataTransferFromClipboard(document) {
134
- var _document$defaultView;
135
-
136
- const clipboard = (_document$defaultView = document.defaultView) == null ? void 0 : _document$defaultView.navigator.clipboard;
137
- const items = clipboard && (await clipboard.read());
138
-
139
- if (!items) {
140
- throw new Error('The Clipboard API is unavailable.');
141
- }
142
-
143
- const dt = (0, _.createDataTransfer)();
144
-
145
- for (const item of items) {
146
- for (const type of item.types) {
147
- dt.setData(type, await item.getType(type).then(b => (0, _.readBlobText)(b)));
148
- }
149
- }
150
-
151
- return dt;
152
- }
153
-
154
- async function writeDataTransferToClipboard(document, clipboardData) {
155
- var _document$defaultView2;
156
-
157
- const clipboard = (_document$defaultView2 = document.defaultView) == null ? void 0 : _document$defaultView2.navigator.clipboard;
158
- const items = [];
159
-
160
- for (let i = 0; i < clipboardData.items.length; i++) {
161
- const dtItem = clipboardData.items[i];
162
- const blob = (0, _.getBlobFromDataTransferItem)(dtItem);
163
- items.push(createClipboardItem(blob));
164
- }
165
-
166
- const written = clipboard && (await clipboard.write(items).then(() => true, // Can happen with other implementations that e.g. require permissions
167
-
168
- /* istanbul ignore next */
169
- () => false));
170
-
171
- if (!written) {
172
- throw new Error('The Clipboard API is unavailable.');
173
- }
174
- }
175
- /* istanbul ignore else */
176
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
177
-
178
-
179
- if (afterEach) {
180
- afterEach(() => resetClipboardStubOnView(window));
181
- }
182
- /* istanbul ignore else */
183
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
184
-
185
-
186
- if (afterAll) {
187
- afterAll(() => detachClipboardStubFromView(window));
188
- }
@@ -1,158 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createDataTransfer = createDataTransfer;
7
- exports.getBlobFromDataTransferItem = getBlobFromDataTransferItem;
8
-
9
- var _FileList = require("./FileList");
10
-
11
- // DataTransfer is not implemented in jsdom.
12
- // DataTransfer with FileList is being created by the browser on certain events.
13
- class DataTransferItemStub {
14
- constructor(dataOrFile, type) {
15
- this.kind = void 0;
16
- this.type = void 0;
17
- this.file = null;
18
- this.data = undefined;
19
-
20
- if (typeof dataOrFile === 'string') {
21
- this.kind = 'string';
22
- this.type = String(type);
23
- this.data = dataOrFile;
24
- } else {
25
- this.kind = 'file';
26
- this.type = dataOrFile.type;
27
- this.file = dataOrFile;
28
- }
29
- }
30
-
31
- getAsFile() {
32
- return this.file;
33
- }
34
-
35
- getAsString(callback) {
36
- if (typeof this.data === 'string') {
37
- callback(this.data);
38
- }
39
- }
40
- /* istanbul ignore next */
41
-
42
-
43
- webkitGetAsEntry() {
44
- throw new Error('not implemented');
45
- }
46
-
47
- }
48
-
49
- class DataTransferItemListStub extends Array {
50
- add(...args) {
51
- const item = new DataTransferItemStub(args[0], args[1]);
52
- this.push(item);
53
- return item;
54
- }
55
-
56
- clear() {
57
- this.splice(0, this.length);
58
- }
59
-
60
- remove(index) {
61
- this.splice(index, 1);
62
- }
63
-
64
- }
65
-
66
- function getTypeMatcher(type, exact) {
67
- const [group, sub] = type.split('/');
68
- const isGroup = !sub || sub === '*';
69
- return item => {
70
- return exact ? item.type === (isGroup ? group : type) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
71
- };
72
- }
73
-
74
- class DataTransferStub {
75
- constructor() {
76
- this.dropEffect = 'none';
77
- this.effectAllowed = 'uninitialized';
78
- this.items = new DataTransferItemListStub();
79
- this.files = (0, _FileList.createFileList)([]);
80
- }
81
-
82
- getData(format) {
83
- var _this$items$find;
84
-
85
- const match = (_this$items$find = this.items.find(getTypeMatcher(format, true))) != null ? _this$items$find : this.items.find(getTypeMatcher(format, false));
86
- let text = '';
87
- match == null ? void 0 : match.getAsString(t => {
88
- text = t;
89
- });
90
- return text;
91
- }
92
-
93
- setData(format, data) {
94
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
95
- const item = new DataTransferItemStub(data, format);
96
-
97
- if (matchIndex >= 0) {
98
- this.items.splice(matchIndex, 1, item);
99
- } else {
100
- this.items.push(item);
101
- }
102
- }
103
-
104
- clearData(format) {
105
- if (format) {
106
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
107
-
108
- if (matchIndex >= 0) {
109
- this.items.remove(matchIndex);
110
- }
111
- } else {
112
- this.items.clear();
113
- }
114
- }
115
-
116
- get types() {
117
- const t = [];
118
-
119
- if (this.files.length) {
120
- t.push('Files');
121
- }
122
-
123
- this.items.forEach(i => t.push(i.type));
124
- Object.freeze(t);
125
- return t;
126
- }
127
- /* istanbul ignore next */
128
-
129
-
130
- setDragImage() {}
131
-
132
- }
133
-
134
- function createDataTransfer(files = []) {
135
- // Use real DataTransfer if available
136
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
137
- const dt = typeof DataTransfer === 'undefined' ? new DataTransferStub() :
138
- /* istanbul ignore next */
139
- new DataTransfer();
140
- Object.defineProperty(dt, 'files', {
141
- get: () => (0, _FileList.createFileList)(files)
142
- });
143
- return dt;
144
- }
145
-
146
- function getBlobFromDataTransferItem(item) {
147
- if (item.kind === 'file') {
148
- return item.getAsFile();
149
- }
150
-
151
- let data = '';
152
- item.getAsString(s => {
153
- data = s;
154
- });
155
- return new Blob([data], {
156
- type: item.type
157
- });
158
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createFileList = createFileList;
7
-
8
- // FileList can not be created per constructor.
9
- function createFileList(files) {
10
- const list = { ...files,
11
- length: files.length,
12
- item: index => list[index],
13
- [Symbol.iterator]: function* nextFile() {
14
- for (let i = 0; i < list.length; i++) {
15
- yield list[i];
16
- }
17
- }
18
- };
19
- list.constructor = FileList;
20
- Object.setPrototypeOf(list, FileList.prototype);
21
- Object.freeze(list);
22
- return list;
23
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildTimeValue = buildTimeValue;
7
-
8
- function buildTimeValue(value) {
9
- const onlyDigitsValue = value.replace(/\D/g, '');
10
-
11
- if (onlyDigitsValue.length < 2) {
12
- return value;
13
- }
14
-
15
- const firstDigit = parseInt(onlyDigitsValue[0], 10);
16
- const secondDigit = parseInt(onlyDigitsValue[1], 10);
17
-
18
- if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
19
- let index;
20
-
21
- if (firstDigit >= 3) {
22
- index = 1;
23
- } else {
24
- index = 2;
25
- }
26
-
27
- return build(onlyDigitsValue, index);
28
- }
29
-
30
- if (value.length === 2) {
31
- return value;
32
- }
33
-
34
- return build(onlyDigitsValue, 2);
35
- }
36
-
37
- function build(onlyDigitsValue, index) {
38
- const hours = onlyDigitsValue.slice(0, index);
39
- const validHours = Math.min(parseInt(hours, 10), 23);
40
- const minuteCharacters = onlyDigitsValue.slice(index);
41
- const parsedMinutes = parseInt(minuteCharacters, 10);
42
- const validMinutes = Math.min(parsedMinutes, 59);
43
- return `${validHours.toString().padStart(2, '0')}:${validMinutes.toString().padStart(2, '0')}`;
44
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.calculateNewValue = calculateNewValue;
7
-
8
- var _document = require("../../document");
9
-
10
- var _isValidDateValue = require("./isValidDateValue");
11
-
12
- var _isValidInputTimeValue = require("./isValidInputTimeValue");
13
-
14
- /**
15
- * Calculate a new text value.
16
- */
17
- function calculateNewValue(inputData, node, {
18
- startOffset,
19
- endOffset
20
- }, inputType) {
21
- const value = (0, _document.getUIValue)(node);
22
- const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
23
- const prolog = value.substring(0, prologEnd);
24
- const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === 'deleteContentForward' ? startOffset + 1 : endOffset);
25
- const epilog = value.substring(epilogStart, value.length);
26
- let newValue = `${prolog}${inputData}${epilog}`;
27
- const newOffset = prologEnd + inputData.length;
28
-
29
- if (node.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(node, newValue)) {
30
- newValue = value;
31
- }
32
-
33
- if (node.type === 'time' && !(0, _isValidInputTimeValue.isValidInputTimeValue)(node, newValue)) {
34
- if ((0, _isValidInputTimeValue.isValidInputTimeValue)(node, inputData)) {
35
- newValue = inputData;
36
- } else {
37
- newValue = value;
38
- }
39
- }
40
-
41
- return {
42
- oldValue: value,
43
- newValue,
44
- newOffset
45
- };
46
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.editInputElement = editInputElement;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _document = require("../../document");
11
-
12
- var _selection = require("../focus/selection");
13
-
14
- /**
15
- * Change the value of an element as if it was changed as a result of a user input.
16
- *
17
- * Fires the input event.
18
- */
19
- function editInputElement(element, {
20
- newValue,
21
- newSelection,
22
- eventOverrides
23
- }) {
24
- const oldValue = element.value; // apply the changes before firing the input event, so that input handlers can access the altered dom and selection
25
-
26
- (0, _document.setUIValue)(element, newValue);
27
- (0, _selection.setSelection)({
28
- focusNode: newSelection.node,
29
- anchorOffset: newSelection.offset,
30
- focusOffset: newSelection.offset
31
- }); // When the input event happens in the browser, React executes all event handlers
32
- // and if they change state of a controlled value, nothing happens.
33
- // But when we trigger the event handlers in test environment,
34
- // the changes are rolled back by React before the state update is applied.
35
- // Then the updated state is applied which results in a resetted cursor.
36
- // There is probably a better way to work around if we figure out
37
- // why the batched update is executed differently in our test environment.
38
-
39
- (0, _document.startTrackValue)(element);
40
-
41
- _dom.fireEvent.input(element, { ...eventOverrides
42
- });
43
-
44
- const tracked = (0, _document.endTrackValue)(element);
45
-
46
- if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
47
- (0, _selection.setSelection)({
48
- focusNode: newSelection.node,
49
- anchorOffset: newSelection.offset,
50
- focusOffset: newSelection.offset
51
- });
52
- }
53
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getValue = getValue;
7
-
8
- var _document = require("../../document");
9
-
10
- var _isContentEditable = require("./isContentEditable");
11
-
12
- function getValue(element) {
13
- // istanbul ignore if
14
- if (!element) {
15
- return null;
16
- }
17
-
18
- if ((0, _isContentEditable.isContentEditable)(element)) {
19
- return element.textContent;
20
- }
21
-
22
- return (0, _document.getUIValue)(element);
23
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getContentEditable = getContentEditable;
7
- exports.isContentEditable = isContentEditable;
8
-
9
- //jsdom is not supporting isContentEditable
10
- function isContentEditable(element) {
11
- return element.hasAttribute('contenteditable') && (element.getAttribute('contenteditable') == 'true' || element.getAttribute('contenteditable') == '');
12
- }
13
- /**
14
- * If a node is a contenteditable or inside one, return that element.
15
- */
16
-
17
-
18
- function getContentEditable(node) {
19
- const element = getElement(node);
20
- return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
21
- }
22
-
23
- function getElement(node) {
24
- return node.nodeType === 1 ? node : node.parentElement;
25
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.editableInputTypes = void 0;
7
- exports.isEditable = isEditable;
8
- exports.isEditableInput = isEditableInput;
9
-
10
- var _isElementType = require("../misc/isElementType");
11
-
12
- var _isContentEditable = require("./isContentEditable");
13
-
14
- function isEditable(element) {
15
- return isEditableInput(element) || (0, _isElementType.isElementType)(element, 'textarea', {
16
- readOnly: false
17
- }) || (0, _isContentEditable.isContentEditable)(element);
18
- }
19
-
20
- let editableInputTypes;
21
- exports.editableInputTypes = editableInputTypes;
22
-
23
- (function (editableInputTypes) {
24
- editableInputTypes["text"] = "text";
25
- editableInputTypes["date"] = "date";
26
- editableInputTypes["datetime-local"] = "datetime-local";
27
- editableInputTypes["email"] = "email";
28
- editableInputTypes["month"] = "month";
29
- editableInputTypes["number"] = "number";
30
- editableInputTypes["password"] = "password";
31
- editableInputTypes["search"] = "search";
32
- editableInputTypes["tel"] = "tel";
33
- editableInputTypes["time"] = "time";
34
- editableInputTypes["url"] = "url";
35
- editableInputTypes["week"] = "week";
36
- })(editableInputTypes || (exports.editableInputTypes = editableInputTypes = {}));
37
-
38
- function isEditableInput(element) {
39
- return (0, _isElementType.isElementType)(element, 'input', {
40
- readOnly: false
41
- }) && Boolean(editableInputTypes[element.type]);
42
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isValidDateValue = isValidDateValue;
7
-
8
- function isValidDateValue(element, value) {
9
- const clone = element.cloneNode();
10
- clone.value = value;
11
- return clone.value === value;
12
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isValidInputTimeValue = isValidInputTimeValue;
7
-
8
- function isValidInputTimeValue(element, timeValue) {
9
- const clone = element.cloneNode();
10
- clone.value = timeValue;
11
- return clone.value === timeValue;
12
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSpaceUntilMaxLength = getSpaceUntilMaxLength;
7
-
8
- var _isElementType = require("../misc/isElementType");
9
-
10
- var _getValue = require("./getValue");
11
-
12
- var maxLengthSupportedTypes;
13
-
14
- (function (maxLengthSupportedTypes) {
15
- maxLengthSupportedTypes["email"] = "email";
16
- maxLengthSupportedTypes["password"] = "password";
17
- maxLengthSupportedTypes["search"] = "search";
18
- maxLengthSupportedTypes["telephone"] = "telephone";
19
- maxLengthSupportedTypes["text"] = "text";
20
- maxLengthSupportedTypes["url"] = "url";
21
- })(maxLengthSupportedTypes || (maxLengthSupportedTypes = {}));
22
-
23
- function getSpaceUntilMaxLength(element) {
24
- const value = (0, _getValue.getValue)(element);
25
- /* istanbul ignore if */
26
-
27
- if (value === null) {
28
- return undefined;
29
- }
30
-
31
- const maxLength = getSanitizedMaxLength(element);
32
- return maxLength ? maxLength - value.length : undefined;
33
- } // can't use .maxLength property because of a jsdom bug:
34
- // https://github.com/jsdom/jsdom/issues/2927
35
-
36
-
37
- function getSanitizedMaxLength(element) {
38
- var _element$getAttribute;
39
-
40
- if (!supportsMaxLength(element)) {
41
- return undefined;
42
- }
43
-
44
- const attr = (_element$getAttribute = element.getAttribute('maxlength')) != null ? _element$getAttribute : '';
45
- return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : undefined;
46
- }
47
-
48
- function supportsMaxLength(element) {
49
- return (0, _isElementType.isElementType)(element, 'textarea') || (0, _isElementType.isElementType)(element, 'input') && Boolean(maxLengthSupportedTypes[element.type]);
50
- }