@testing-library/user-event 14.0.0-alpha.10 → 14.0.0-alpha.14

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 (48) hide show
  1. package/dist/click.d.ts +3 -3
  2. package/dist/click.js +8 -9
  3. package/dist/clipboard/copy.d.ts +11 -0
  4. package/dist/clipboard/copy.js +30 -0
  5. package/dist/clipboard/cut.d.ts +11 -0
  6. package/dist/clipboard/cut.js +36 -0
  7. package/dist/clipboard/index.d.ts +3 -0
  8. package/dist/clipboard/index.js +44 -0
  9. package/dist/clipboard/paste.d.ts +6 -0
  10. package/dist/clipboard/paste.js +45 -0
  11. package/dist/hover.d.ts +2 -2
  12. package/dist/hover.js +2 -2
  13. package/dist/index.d.ts +0 -2
  14. package/dist/index.js +0 -8
  15. package/dist/keyboard/getEventProps.d.ts +0 -2
  16. package/dist/keyboard/getEventProps.js +1 -7
  17. package/dist/keyboard/getNextKeyDef.d.ts +0 -1
  18. package/dist/keyboard/getNextKeyDef.js +2 -32
  19. package/dist/keyboard/index.d.ts +0 -1
  20. package/dist/keyboard/index.js +0 -8
  21. package/dist/keyboard/keyMap.js +24 -48
  22. package/dist/keyboard/keyboardImplementation.js +12 -16
  23. package/dist/keyboard/plugins/index.d.ts +0 -1
  24. package/dist/keyboard/plugins/index.js +1 -10
  25. package/dist/keyboard/types.d.ts +0 -2
  26. package/dist/selectOptions.d.ts +2 -2
  27. package/dist/selectOptions.js +25 -26
  28. package/dist/setup.d.ts +11 -3
  29. package/dist/setup.js +57 -19
  30. package/dist/upload.d.ts +0 -1
  31. package/dist/upload.js +1 -1
  32. package/dist/utils/dataTransfer/Blob.d.ts +1 -0
  33. package/dist/utils/dataTransfer/Blob.js +21 -0
  34. package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
  35. package/dist/utils/dataTransfer/Clipboard.js +188 -0
  36. package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
  37. package/dist/utils/dataTransfer/DataTransfer.js +158 -0
  38. package/dist/utils/dataTransfer/FileList.d.ts +1 -0
  39. package/dist/utils/dataTransfer/FileList.js +13 -0
  40. package/dist/utils/focus/copySelection.d.ts +1 -0
  41. package/dist/utils/focus/copySelection.js +36 -0
  42. package/dist/utils/index.d.ts +5 -0
  43. package/dist/utils/index.js +65 -0
  44. package/package.json +1 -1
  45. package/dist/keyboard/specialCharMap.d.ts +0 -22
  46. package/dist/keyboard/specialCharMap.js +0 -30
  47. package/dist/paste.d.ts +0 -7
  48. package/dist/paste.js +0 -60
@@ -0,0 +1,158 @@
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
+ }
@@ -0,0 +1 @@
1
+ export declare function createFileList(files: File[]): FileList;
@@ -0,0 +1,13 @@
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 f = [...files];
11
+ Object.setPrototypeOf(f, FileList.prototype);
12
+ return f;
13
+ }
@@ -0,0 +1 @@
1
+ export declare function copySelection(target: Element): DataTransfer;
@@ -0,0 +1,36 @@
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,4 +1,8 @@
1
1
  export * from './click/isClickableInput';
2
+ export * from './dataTransfer/Blob';
3
+ export * from './dataTransfer/DataTransfer';
4
+ export * from './dataTransfer/FileList';
5
+ export * from './dataTransfer/Clipboard';
2
6
  export * from './edit/buildTimeValue';
3
7
  export * from './edit/calculateNewValue';
4
8
  export * from './edit/editInputElement';
@@ -10,6 +14,7 @@ export * from './edit/isValidInputTimeValue';
10
14
  export * from './edit/maxLength';
11
15
  export * from './edit/prepareInput';
12
16
  export * from './focus/blur';
17
+ export * from './focus/copySelection';
13
18
  export * from './focus/focus';
14
19
  export * from './focus/getActiveElement';
15
20
  export * from './focus/getTabDestination';
@@ -17,6 +17,58 @@ Object.keys(_isClickableInput).forEach(function (key) {
17
17
  });
18
18
  });
19
19
 
20
+ var _Blob = require("./dataTransfer/Blob");
21
+
22
+ Object.keys(_Blob).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _Blob[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _Blob[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _DataTransfer = require("./dataTransfer/DataTransfer");
34
+
35
+ Object.keys(_DataTransfer).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _DataTransfer[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _DataTransfer[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _FileList = require("./dataTransfer/FileList");
47
+
48
+ Object.keys(_FileList).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _FileList[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _FileList[key];
55
+ }
56
+ });
57
+ });
58
+
59
+ var _Clipboard = require("./dataTransfer/Clipboard");
60
+
61
+ Object.keys(_Clipboard).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (key in exports && exports[key] === _Clipboard[key]) return;
64
+ Object.defineProperty(exports, key, {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _Clipboard[key];
68
+ }
69
+ });
70
+ });
71
+
20
72
  var _buildTimeValue = require("./edit/buildTimeValue");
21
73
 
22
74
  Object.keys(_buildTimeValue).forEach(function (key) {
@@ -160,6 +212,19 @@ Object.keys(_blur).forEach(function (key) {
160
212
  });
161
213
  });
162
214
 
215
+ var _copySelection = require("./focus/copySelection");
216
+
217
+ Object.keys(_copySelection).forEach(function (key) {
218
+ if (key === "default" || key === "__esModule") return;
219
+ if (key in exports && exports[key] === _copySelection[key]) return;
220
+ Object.defineProperty(exports, key, {
221
+ enumerable: true,
222
+ get: function () {
223
+ return _copySelection[key];
224
+ }
225
+ });
226
+ });
227
+
163
228
  var _focus = require("./focus/focus");
164
229
 
165
230
  Object.keys(_focus).forEach(function (key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-alpha.10",
3
+ "version": "14.0.0-alpha.14",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -1,22 +0,0 @@
1
- /**
2
- * @deprecated This list of strings with special meaning is no longer necessary
3
- * as we've introduced a standardized way to describe any keystroke for `userEvent`.
4
- * @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
5
- */
6
- export declare const specialCharMap: {
7
- readonly arrowLeft: "{arrowleft}";
8
- readonly arrowRight: "{arrowright}";
9
- readonly arrowDown: "{arrowdown}";
10
- readonly arrowUp: "{arrowup}";
11
- readonly enter: "{enter}";
12
- readonly escape: "{esc}";
13
- readonly delete: "{del}";
14
- readonly backspace: "{backspace}";
15
- readonly home: "{home}";
16
- readonly end: "{end}";
17
- readonly selectAll: "{selectall}";
18
- readonly space: "{space}";
19
- readonly whitespace: " ";
20
- readonly pageUp: "{pageUp}";
21
- readonly pageDown: "{pageDown}";
22
- };
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.specialCharMap = void 0;
7
-
8
- /**
9
- * @deprecated This list of strings with special meaning is no longer necessary
10
- * as we've introduced a standardized way to describe any keystroke for `userEvent`.
11
- * @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
12
- */
13
- const specialCharMap = {
14
- arrowLeft: '{arrowleft}',
15
- arrowRight: '{arrowright}',
16
- arrowDown: '{arrowdown}',
17
- arrowUp: '{arrowup}',
18
- enter: '{enter}',
19
- escape: '{esc}',
20
- delete: '{del}',
21
- backspace: '{backspace}',
22
- home: '{home}',
23
- end: '{end}',
24
- selectAll: '{selectall}',
25
- space: '{space}',
26
- whitespace: ' ',
27
- pageUp: '{pageUp}',
28
- pageDown: '{pageDown}'
29
- };
30
- exports.specialCharMap = specialCharMap;
package/dist/paste.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- interface pasteOptions {
3
- initialSelectionStart?: number;
4
- initialSelectionEnd?: number;
5
- }
6
- export declare function paste(this: UserEvent, element: HTMLElement, text: string, init?: ClipboardEventInit, { initialSelectionStart, initialSelectionEnd }?: pasteOptions): void;
7
- export {};
package/dist/paste.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.paste = paste;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _utils = require("./utils");
11
-
12
- function isSupportedElement(element) {
13
- return (0, _utils.isElementType)(element, 'input') && Boolean(_utils.editableInputTypes[element.type]) || (0, _utils.isElementType)(element, 'textarea');
14
- }
15
-
16
- function paste(element, text, init, {
17
- initialSelectionStart,
18
- initialSelectionEnd
19
- } = {}) {
20
- var _prepareInput;
21
-
22
- // TODO: implement for contenteditable
23
- if (!isSupportedElement(element)) {
24
- throw new TypeError(`The given ${element.tagName} element is currently unsupported.
25
- A PR extending this implementation would be very much welcome at https://github.com/testing-library/user-event`);
26
- }
27
-
28
- if ((0, _utils.isDisabled)(element)) {
29
- return;
30
- }
31
-
32
- (0, _utils.eventWrapper)(() => element.focus()); // by default, a new element has it's selection start and end at 0
33
- // but most of the time when people call "paste", they expect it to paste
34
- // at the end of the current input value. So, if the selection start
35
- // and end are both the default of 0, then we'll go ahead and change
36
- // them to the length of the current value.
37
- // the only time it would make sense to pass the initialSelectionStart or
38
- // initialSelectionEnd is if you have an input with a value and want to
39
- // explicitely start typing with the cursor at 0. Not super common.
40
-
41
- if (element.selectionStart === 0 && element.selectionEnd === 0) {
42
- (0, _utils.setSelectionRange)(element, initialSelectionStart != null ? initialSelectionStart : element.value.length, initialSelectionEnd != null ? initialSelectionEnd : element.value.length);
43
- }
44
-
45
- _dom.fireEvent.paste(element, init);
46
-
47
- if (element.readOnly) {
48
- return;
49
- }
50
-
51
- text = text.substr(0, (0, _utils.getSpaceUntilMaxLength)(element));
52
- const inputRange = (0, _utils.getInputRange)(element);
53
- /* istanbul ignore if */
54
-
55
- if (!inputRange) {
56
- return;
57
- }
58
-
59
- (_prepareInput = (0, _utils.prepareInput)(text, element, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
60
- }