@testing-library/user-event 14.0.0-alpha.9 → 14.0.0-beta.4

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 (140) hide show
  1. package/dist/index.d.ts +1110 -8
  2. package/dist/index.js +2824 -15
  3. package/dist/package.json +1 -0
  4. package/package.json +6 -30
  5. package/dist/clear.d.ts +0 -2
  6. package/dist/clear.js +0 -46
  7. package/dist/click.d.ts +0 -9
  8. package/dist/click.js +0 -62
  9. package/dist/document/index.d.ts +0 -10
  10. package/dist/document/index.js +0 -100
  11. package/dist/document/interceptor.d.ts +0 -15
  12. package/dist/document/interceptor.js +0 -37
  13. package/dist/document/selection.d.ts +0 -27
  14. package/dist/document/selection.js +0 -90
  15. package/dist/document/value.d.ts +0 -18
  16. package/dist/document/value.js +0 -77
  17. package/dist/hover.d.ts +0 -4
  18. package/dist/hover.js +0 -43
  19. package/dist/keyboard/getEventProps.d.ts +0 -17
  20. package/dist/keyboard/getEventProps.js +0 -33
  21. package/dist/keyboard/getNextKeyDef.d.ts +0 -19
  22. package/dist/keyboard/getNextKeyDef.js +0 -85
  23. package/dist/keyboard/index.d.ts +0 -19
  24. package/dist/keyboard/index.js +0 -78
  25. package/dist/keyboard/keyMap.d.ts +0 -5
  26. package/dist/keyboard/keyMap.js +0 -143
  27. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  28. package/dist/keyboard/keyboardImplementation.js +0 -169
  29. package/dist/keyboard/plugins/arrow.d.ts +0 -6
  30. package/dist/keyboard/plugins/arrow.js +0 -28
  31. package/dist/keyboard/plugins/character.d.ts +0 -5
  32. package/dist/keyboard/plugins/character.js +0 -166
  33. package/dist/keyboard/plugins/combination.d.ts +0 -5
  34. package/dist/keyboard/plugins/combination.js +0 -17
  35. package/dist/keyboard/plugins/control.d.ts +0 -6
  36. package/dist/keyboard/plugins/control.js +0 -52
  37. package/dist/keyboard/plugins/functional.d.ts +0 -11
  38. package/dist/keyboard/plugins/functional.js +0 -140
  39. package/dist/keyboard/plugins/index.d.ts +0 -8
  40. package/dist/keyboard/plugins/index.js +0 -42
  41. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
  42. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
  43. package/dist/keyboard/shared/index.d.ts +0 -1
  44. package/dist/keyboard/shared/index.js +0 -18
  45. package/dist/keyboard/specialCharMap.d.ts +0 -22
  46. package/dist/keyboard/specialCharMap.js +0 -30
  47. package/dist/keyboard/types.d.ts +0 -80
  48. package/dist/keyboard/types.js +0 -19
  49. package/dist/paste.d.ts +0 -7
  50. package/dist/paste.js +0 -60
  51. package/dist/pointer/index.d.ts +0 -18
  52. package/dist/pointer/index.js +0 -90
  53. package/dist/pointer/keyMap.d.ts +0 -2
  54. package/dist/pointer/keyMap.js +0 -29
  55. package/dist/pointer/parseKeyDef.d.ts +0 -6
  56. package/dist/pointer/parseKeyDef.js +0 -36
  57. package/dist/pointer/pointerAction.d.ts +0 -6
  58. package/dist/pointer/pointerAction.js +0 -52
  59. package/dist/pointer/pointerMove.d.ts +0 -5
  60. package/dist/pointer/pointerMove.js +0 -136
  61. package/dist/pointer/pointerPress.d.ts +0 -7
  62. package/dist/pointer/pointerPress.js +0 -330
  63. package/dist/pointer/resolveSelectionTarget.d.ts +0 -5
  64. package/dist/pointer/resolveSelectionTarget.js +0 -75
  65. package/dist/pointer/types.d.ts +0 -72
  66. package/dist/pointer/types.js +0 -1
  67. package/dist/selectOptions.d.ts +0 -4
  68. package/dist/selectOptions.js +0 -142
  69. package/dist/setup.d.ts +0 -92
  70. package/dist/setup.js +0 -203
  71. package/dist/tab.d.ts +0 -5
  72. package/dist/tab.js +0 -12
  73. package/dist/type.d.ts +0 -14
  74. package/dist/type.js +0 -74
  75. package/dist/upload.d.ts +0 -10
  76. package/dist/upload.js +0 -92
  77. package/dist/utils/click/isClickableInput.d.ts +0 -1
  78. package/dist/utils/click/isClickableInput.js +0 -14
  79. package/dist/utils/edit/buildTimeValue.d.ts +0 -1
  80. package/dist/utils/edit/buildTimeValue.js +0 -44
  81. package/dist/utils/edit/calculateNewValue.d.ts +0 -16
  82. package/dist/utils/edit/calculateNewValue.js +0 -50
  83. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
  84. package/dist/utils/edit/fireInputEvent.js +0 -65
  85. package/dist/utils/edit/getValue.d.ts +0 -1
  86. package/dist/utils/edit/getValue.js +0 -23
  87. package/dist/utils/edit/isContentEditable.d.ts +0 -7
  88. package/dist/utils/edit/isContentEditable.js +0 -25
  89. package/dist/utils/edit/isEditable.d.ts +0 -25
  90. package/dist/utils/edit/isEditable.js +0 -42
  91. package/dist/utils/edit/isValidDateValue.d.ts +0 -3
  92. package/dist/utils/edit/isValidDateValue.js +0 -12
  93. package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
  94. package/dist/utils/edit/isValidInputTimeValue.js +0 -12
  95. package/dist/utils/edit/maxLength.d.ts +0 -1
  96. package/dist/utils/edit/maxLength.js +0 -50
  97. package/dist/utils/edit/prepareInput.d.ts +0 -4
  98. package/dist/utils/edit/prepareInput.js +0 -60
  99. package/dist/utils/focus/blur.d.ts +0 -2
  100. package/dist/utils/focus/blur.js +0 -19
  101. package/dist/utils/focus/focus.d.ts +0 -2
  102. package/dist/utils/focus/focus.js +0 -22
  103. package/dist/utils/focus/getActiveElement.d.ts +0 -1
  104. package/dist/utils/focus/getActiveElement.js +0 -26
  105. package/dist/utils/focus/getTabDestination.d.ts +0 -1
  106. package/dist/utils/focus/getTabDestination.js +0 -71
  107. package/dist/utils/focus/isFocusable.d.ts +0 -1
  108. package/dist/utils/focus/isFocusable.js +0 -12
  109. package/dist/utils/focus/selectAll.d.ts +0 -4
  110. package/dist/utils/focus/selectAll.js +0 -38
  111. package/dist/utils/focus/selection.d.ts +0 -42
  112. package/dist/utils/focus/selection.js +0 -190
  113. package/dist/utils/focus/selector.d.ts +0 -1
  114. package/dist/utils/focus/selector.js +0 -8
  115. package/dist/utils/index.d.ts +0 -31
  116. package/dist/utils/index.js +0 -408
  117. package/dist/utils/keyDef/readNextDescriptor.d.ts +0 -19
  118. package/dist/utils/keyDef/readNextDescriptor.js +0 -102
  119. package/dist/utils/misc/eventWrapper.d.ts +0 -1
  120. package/dist/utils/misc/eventWrapper.js +0 -16
  121. package/dist/utils/misc/findClosest.d.ts +0 -1
  122. package/dist/utils/misc/findClosest.js +0 -20
  123. package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
  124. package/dist/utils/misc/hasFormSubmit.js +0 -10
  125. package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
  126. package/dist/utils/misc/hasPointerEvents.js +0 -24
  127. package/dist/utils/misc/isDescendantOrSelf.d.ts +0 -1
  128. package/dist/utils/misc/isDescendantOrSelf.js +0 -20
  129. package/dist/utils/misc/isDisabled.d.ts +0 -1
  130. package/dist/utils/misc/isDisabled.js +0 -12
  131. package/dist/utils/misc/isElementType.d.ts +0 -5
  132. package/dist/utils/misc/isElementType.js +0 -24
  133. package/dist/utils/misc/isVisible.d.ts +0 -1
  134. package/dist/utils/misc/isVisible.js +0 -24
  135. package/dist/utils/misc/wait.d.ts +0 -1
  136. package/dist/utils/misc/wait.js +0 -10
  137. package/dist/utils/pointer/firePointerEvents.d.ts +0 -25
  138. package/dist/utils/pointer/firePointerEvents.js +0 -112
  139. package/dist/utils/pointer/mouseButtons.d.ts +0 -12
  140. package/dist/utils/pointer/mouseButtons.js +0 -45
package/dist/setup.d.ts DELETED
@@ -1,92 +0,0 @@
1
- import { clear } from './clear';
2
- import { click, clickOptions, dblClick, tripleClick } from './click';
3
- import { hover, unhover } from './hover';
4
- import { keyboard, keyboardOptions } from './keyboard';
5
- import type { keyboardState } from './keyboard/types';
6
- import { paste } from './paste';
7
- import { pointer } from './pointer';
8
- import type { pointerOptions, pointerState } from './pointer/types';
9
- import { deselectOptions, selectOptions } from './selectOptions';
10
- import { tab, tabOptions } from './tab';
11
- import { type, typeOptions } from './type';
12
- import { upload, uploadOptions } from './upload';
13
- import { PointerOptions } from './utils';
14
- export declare const userEventApis: {
15
- clear: typeof clear;
16
- click: typeof click;
17
- dblClick: typeof dblClick;
18
- deselectOptions: typeof deselectOptions;
19
- hover: typeof hover;
20
- keyboard: typeof keyboard;
21
- paste: typeof paste;
22
- pointer: typeof pointer;
23
- selectOptions: typeof selectOptions;
24
- tab: typeof tab;
25
- tripleClick: typeof tripleClick;
26
- type: typeof type;
27
- unhover: typeof unhover;
28
- upload: typeof upload;
29
- };
30
- export declare type UserEventApis = typeof userEventApis;
31
- declare type setup = ReturnType<typeof _setup>['setup'];
32
- export declare type UserEvent = UserEventApis & {
33
- setup: setup;
34
- };
35
- declare type ClickOptions = Omit<clickOptions, 'clickCount'>;
36
- declare type KeyboardOptions = Partial<keyboardOptions>;
37
- declare type PointerApiOptions = Partial<pointerOptions>;
38
- declare type TabOptions = Omit<tabOptions, 'shift'>;
39
- declare type TypeOptions = Omit<typeOptions, 'initialSelectionStart' | 'initialSelectionEnd'>;
40
- declare type UploadOptions = uploadOptions;
41
- interface SetupOptions extends ClickOptions, KeyboardOptions, PointerOptions, PointerApiOptions, TabOptions, TypeOptions, UploadOptions {
42
- }
43
- /**
44
- * Start a "session" with userEvent.
45
- * All APIs returned by this function share an input device state and a default configuration.
46
- */
47
- export declare function setup(options?: SetupOptions): {
48
- clear: typeof clear;
49
- click: typeof click;
50
- dblClick: typeof dblClick;
51
- deselectOptions: typeof deselectOptions;
52
- hover: typeof hover;
53
- keyboard: typeof keyboard;
54
- paste: typeof paste;
55
- pointer: typeof pointer;
56
- selectOptions: typeof selectOptions;
57
- tab: typeof tab;
58
- tripleClick: typeof tripleClick;
59
- type: typeof type;
60
- unhover: typeof unhover;
61
- upload: typeof upload;
62
- } & {
63
- /**
64
- * Create a set of callbacks with different default settings but the same state.
65
- */
66
- setup(options: SetupOptions): {
67
- clear: typeof clear;
68
- click: typeof click;
69
- dblClick: typeof dblClick;
70
- deselectOptions: typeof deselectOptions;
71
- hover: typeof hover;
72
- keyboard: typeof keyboard;
73
- paste: typeof paste;
74
- pointer: typeof pointer;
75
- selectOptions: typeof selectOptions;
76
- tab: typeof tab;
77
- tripleClick: typeof tripleClick;
78
- type: typeof type;
79
- unhover: typeof unhover;
80
- upload: typeof upload;
81
- } & any;
82
- };
83
- declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
84
- keyboardState: keyboardState;
85
- pointerState: pointerState;
86
- }): UserEventApis & {
87
- /**
88
- * Create a set of callbacks with different default settings but the same state.
89
- */
90
- setup(options: SetupOptions): ReturnType<typeof _setup>;
91
- };
92
- export {};
package/dist/setup.js DELETED
@@ -1,203 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setup = setup;
7
- exports.userEventApis = void 0;
8
-
9
- var _clear = require("./clear");
10
-
11
- var _click = require("./click");
12
-
13
- var _document = require("./document");
14
-
15
- var _hover = require("./hover");
16
-
17
- var _keyboard = require("./keyboard");
18
-
19
- var _paste = require("./paste");
20
-
21
- var _pointer = require("./pointer");
22
-
23
- var _selectOptions = require("./selectOptions");
24
-
25
- var _tab = require("./tab");
26
-
27
- var _type = require("./type");
28
-
29
- var _upload = require("./upload");
30
-
31
- const userEventApis = {
32
- clear: _clear.clear,
33
- click: _click.click,
34
- dblClick: _click.dblClick,
35
- deselectOptions: _selectOptions.deselectOptions,
36
- hover: _hover.hover,
37
- keyboard: _keyboard.keyboard,
38
- paste: _paste.paste,
39
- pointer: _pointer.pointer,
40
- selectOptions: _selectOptions.selectOptions,
41
- tab: _tab.tab,
42
- tripleClick: _click.tripleClick,
43
- type: _type.type,
44
- unhover: _hover.unhover,
45
- upload: _upload.upload
46
- };
47
- exports.userEventApis = userEventApis;
48
-
49
- /**
50
- * Start a "session" with userEvent.
51
- * All APIs returned by this function share an input device state and a default configuration.
52
- */
53
- function setup(options = {}) {
54
- var _options$document;
55
-
56
- (0, _document.prepareDocument)((_options$document = options.document) != null ? _options$document : document);
57
- return _setup(options, {
58
- keyboardState: (0, _keyboard.createKeyboardState)(),
59
- pointerState: (0, _pointer.createPointerState)()
60
- });
61
- }
62
-
63
- function _setup({
64
- applyAccept,
65
- autoModify,
66
- delay = 0,
67
- document,
68
- keyboardMap,
69
- pointerMap,
70
- skipAutoClose,
71
- skipClick,
72
- skipHover,
73
- skipPointerEventsCheck = false
74
- }, {
75
- keyboardState,
76
- pointerState
77
- }) {
78
- const keyboardDefaults = {
79
- autoModify,
80
- delay,
81
- document,
82
- keyboardMap
83
- };
84
- const pointerDefaults = {
85
- skipPointerEventsCheck
86
- };
87
- const pointerApiDefaults = {
88
- delay,
89
- pointerMap
90
- };
91
- const clickDefaults = {
92
- skipHover
93
- };
94
- const typeDefaults = {
95
- delay,
96
- skipAutoClose,
97
- skipClick
98
- };
99
- const uploadDefaults = {
100
- applyAccept
101
- };
102
- const userEvent = {
103
- clear: (...args) => {
104
- return _clear.clear.call(userEvent, ...args);
105
- },
106
- click: (...args) => {
107
- args[2] = { ...pointerDefaults,
108
- ...clickDefaults,
109
- ...args[2]
110
- };
111
- return _click.click.call(userEvent, ...args);
112
- },
113
- dblClick: (...args) => {
114
- args[2] = { ...pointerDefaults,
115
- ...clickDefaults,
116
- ...args[2]
117
- };
118
- return _click.dblClick.call(userEvent, ...args);
119
- },
120
- deselectOptions: (...args) => {
121
- args[3] = { ...pointerDefaults,
122
- ...args[3]
123
- };
124
- return _selectOptions.deselectOptions.call(userEvent, ...args);
125
- },
126
- hover: (...args) => {
127
- args[2] = { ...pointerDefaults,
128
- ...args[2]
129
- };
130
- return _hover.hover.call(userEvent, ...args);
131
- },
132
- // keyboard needs typecasting because of the overloading
133
- keyboard: (...args) => {
134
- args[1] = { ...keyboardDefaults,
135
- ...args[1],
136
- keyboardState
137
- };
138
- const ret = (0, _keyboard.keyboard)(...args);
139
-
140
- if (ret instanceof Promise) {
141
- return ret.then(() => undefined);
142
- }
143
- },
144
- paste: (...args) => {
145
- return _paste.paste.call(userEvent, ...args);
146
- },
147
- // pointer needs typecasting because of the overloading
148
- pointer: (...args) => {
149
- args[1] = { ...pointerApiDefaults,
150
- ...args[1],
151
- pointerState,
152
- keyboardState
153
- };
154
- const ret = (0, _pointer.pointer)(...args);
155
-
156
- if (ret instanceof Promise) {
157
- return ret.then(() => undefined);
158
- }
159
- },
160
- selectOptions: (...args) => {
161
- args[3] = { ...pointerDefaults,
162
- ...args[3]
163
- };
164
- return _selectOptions.selectOptions.call(userEvent, ...args);
165
- },
166
- setup: options => {
167
- return _setup({ ...keyboardDefaults,
168
- ...pointerDefaults,
169
- ...clickDefaults,
170
- ...options
171
- }, {
172
- keyboardState,
173
- pointerState
174
- });
175
- },
176
- tab: (...args) => {
177
- return _tab.tab.call(userEvent, ...args);
178
- },
179
- tripleClick: (...args) => {
180
- return _click.tripleClick.call(userEvent, ...args);
181
- },
182
- // type needs typecasting because of the overloading
183
- type: (...args) => {
184
- args[2] = { ...typeDefaults,
185
- ...args[2]
186
- };
187
- return _type.type.call(userEvent, ...args);
188
- },
189
- unhover: (...args) => {
190
- args[2] = { ...pointerDefaults,
191
- ...args[2]
192
- };
193
- return _hover.unhover.call(userEvent, ...args);
194
- },
195
- upload: (...args) => {
196
- args[3] = { ...uploadDefaults,
197
- ...args[3]
198
- };
199
- return _upload.upload.call(userEvent, ...args);
200
- }
201
- };
202
- return userEvent;
203
- }
package/dist/tab.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export interface tabOptions {
3
- shift?: boolean;
4
- }
5
- export declare function tab(this: UserEvent, { shift }?: tabOptions): void;
package/dist/tab.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.tab = tab;
7
-
8
- function tab({
9
- shift
10
- } = {}) {
11
- this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
12
- }
package/dist/type.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export interface typeOptions {
3
- delay?: number;
4
- skipClick?: boolean;
5
- skipAutoClose?: boolean;
6
- initialSelectionStart?: number;
7
- initialSelectionEnd?: number;
8
- }
9
- export declare function type(this: UserEvent, element: Element, text: string, options?: typeOptions & {
10
- delay?: 0;
11
- }): void;
12
- export declare function type(this: UserEvent, element: Element, text: string, options: typeOptions & {
13
- delay: number;
14
- }): Promise<void>;
package/dist/type.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.type = type;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _document = require("./document");
11
-
12
- var _utils = require("./utils");
13
-
14
- var _keyboard = require("./keyboard");
15
-
16
- // this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
17
- // depending on whether it will be async.
18
- function type(element, text, {
19
- delay = 0,
20
- ...options
21
- } = {}) {
22
- (0, _document.prepareDocument)(element.ownerDocument); // we do not want to wrap in the asyncWrapper if we're not
23
- // going to actually be doing anything async, so we only wrap
24
- // if the delay is greater than 0
25
-
26
- if (delay > 0) {
27
- return (0, _dom.getConfig)().asyncWrapper(() => typeImplementation(this, element, text, {
28
- delay,
29
- ...options
30
- }));
31
- } else {
32
- return void typeImplementation(this, element, text, {
33
- delay,
34
- ...options
35
- }) // prevents users from dealing with UnhandledPromiseRejectionWarning
36
- .catch(console.error);
37
- }
38
- }
39
-
40
- async function typeImplementation(userEvent, element, text, {
41
- delay,
42
- skipClick = false,
43
- skipAutoClose = false,
44
- initialSelectionStart = undefined,
45
- initialSelectionEnd = undefined
46
- }) {
47
- // TODO: properly type guard
48
- // we use this workaround for now to prevent changing behavior
49
- if (element.disabled) return;
50
- if (!skipClick) userEvent.click(element);
51
-
52
- if (initialSelectionStart !== undefined) {
53
- (0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
54
- }
55
-
56
- const {
57
- promise,
58
- releaseAllKeys
59
- } = (0, _keyboard.keyboardImplementationWrapper)(text, {
60
- delay,
61
- document: element.ownerDocument
62
- });
63
-
64
- if (delay > 0) {
65
- await promise;
66
- }
67
-
68
- if (!skipAutoClose) {
69
- releaseAllKeys();
70
- } // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
71
-
72
-
73
- return promise;
74
- }
package/dist/upload.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- interface uploadInit {
3
- clickInit?: MouseEventInit;
4
- changeInit?: EventInit;
5
- }
6
- export interface uploadOptions {
7
- applyAccept?: boolean;
8
- }
9
- export declare function upload(this: UserEvent, element: HTMLElement, fileOrFiles: File | File[], init?: uploadInit, { applyAccept }?: uploadOptions): void;
10
- export {};
package/dist/upload.js DELETED
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.upload = upload;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _utils = require("./utils");
11
-
12
- function upload(element, fileOrFiles, init, {
13
- applyAccept = false
14
- } = {}) {
15
- var _input$files;
16
-
17
- const input = (0, _utils.isElementType)(element, 'label') ? element.control : element;
18
-
19
- if (!input || !(0, _utils.isElementType)(input, 'input', {
20
- type: 'file'
21
- })) {
22
- throw new TypeError(`The ${input === element ? 'given' : 'associated'} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
23
- }
24
-
25
- if ((0, _utils.isDisabled)(element)) return;
26
- this.click(element, init == null ? void 0 : init.clickInit);
27
- const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter(file => !applyAccept || isAcceptableFile(file, input.accept)).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
28
-
29
- (0, _utils.blur)(element); // focus fires when they make their selection
30
-
31
- (0, _utils.focus)(element); // do not fire an input event if the file selection does not change
32
-
33
- if (files.length === ((_input$files = input.files) == null ? void 0 : _input$files.length) && files.every((f, i) => {
34
- var _input$files2;
35
-
36
- return f === ((_input$files2 = input.files) == null ? void 0 : _input$files2.item(i));
37
- })) {
38
- return;
39
- } // the event fired in the browser isn't actually an "input" or "change" event
40
- // but a new Event with a type set to "input" and "change"
41
- // Kinda odd...
42
-
43
-
44
- const inputFiles = { ...files,
45
- length: files.length,
46
- item: index => files[index],
47
-
48
- [Symbol.iterator]() {
49
- let i = 0;
50
- return {
51
- next: () => ({
52
- done: i >= files.length,
53
- value: files[i++]
54
- })
55
- };
56
- }
57
-
58
- };
59
- (0, _dom.fireEvent)(input, (0, _dom.createEvent)('input', input, {
60
- target: {
61
- files: inputFiles
62
- },
63
- bubbles: true,
64
- cancelable: false,
65
- composed: true
66
- }));
67
-
68
- _dom.fireEvent.change(input, {
69
- target: {
70
- files: inputFiles
71
- },
72
- ...(init == null ? void 0 : init.changeInit)
73
- });
74
- }
75
-
76
- function isAcceptableFile(file, accept) {
77
- if (!accept) {
78
- return true;
79
- }
80
-
81
- const wildcards = ['audio/*', 'image/*', 'video/*'];
82
- return accept.split(',').some(acceptToken => {
83
- if (acceptToken.startsWith('.')) {
84
- // tokens starting with a dot represent a file extension
85
- return file.name.endsWith(acceptToken);
86
- } else if (wildcards.includes(acceptToken)) {
87
- return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
88
- }
89
-
90
- return file.type === acceptToken;
91
- });
92
- }
@@ -1 +0,0 @@
1
- export declare function isClickableInput(element: Element): boolean;
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isClickableInput = isClickableInput;
7
-
8
- var _isElementType = require("../misc/isElementType");
9
-
10
- const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit', 'checkbox', 'radio'];
11
-
12
- function isClickableInput(element) {
13
- return (0, _isElementType.isElementType)(element, 'button') || (0, _isElementType.isElementType)(element, 'input') && CLICKABLE_INPUT_TYPES.includes(element.type);
14
- }
@@ -1 +0,0 @@
1
- export declare function buildTimeValue(value: string): string;
@@ -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,16 +0,0 @@
1
- import { EditableInputType } from './isEditable';
2
- /**
3
- * Calculate a new text value.
4
- */
5
- export declare function calculateNewValue(inputData: string, node: (HTMLInputElement & {
6
- type: EditableInputType;
7
- }) | HTMLTextAreaElement | (Node & {
8
- nodeType: 3;
9
- }) | Text, { startOffset, endOffset, }: {
10
- startOffset: number;
11
- endOffset: number;
12
- }, inputType?: string): {
13
- oldValue: string;
14
- newValue: string;
15
- newOffset: number;
16
- };
@@ -1,50 +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
- // This implementation does not properly calculate a new DOM state.
18
- // It only handles text values and neither cares for DOM offsets nor accounts for non-character elements.
19
- // It can be used for text nodes and elements supporting value property.
20
- // TODO: The implementation of `deleteContent` is brittle and should be replaced.
21
- function calculateNewValue(inputData, node, {
22
- startOffset,
23
- endOffset
24
- }, inputType) {
25
- const value = node.nodeType === 3 ? String(node.nodeValue) : (0, _document.getUIValue)(node);
26
- const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
27
- const prolog = value.substring(0, prologEnd);
28
- const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === 'deleteContentForward' ? startOffset + 1 : endOffset);
29
- const epilog = value.substring(epilogStart, value.length);
30
- let newValue = `${prolog}${inputData}${epilog}`;
31
- const newOffset = prologEnd + inputData.length;
32
-
33
- if (node.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(node, newValue)) {
34
- newValue = value;
35
- }
36
-
37
- if (node.type === 'time' && !(0, _isValidInputTimeValue.isValidInputTimeValue)(node, newValue)) {
38
- if ((0, _isValidInputTimeValue.isValidInputTimeValue)(node, inputData)) {
39
- newValue = inputData;
40
- } else {
41
- newValue = value;
42
- }
43
- }
44
-
45
- return {
46
- oldValue: value,
47
- newValue,
48
- newOffset
49
- };
50
- }
@@ -1,11 +0,0 @@
1
- import { fireEvent } from '@testing-library/dom';
2
- export declare function fireInputEvent(element: HTMLElement, { newValue, newSelection, eventOverrides, }: {
3
- newValue: string;
4
- newSelection: {
5
- node: Node;
6
- offset: number;
7
- };
8
- eventOverrides: Partial<Parameters<typeof fireEvent>[1]> & {
9
- [k: string]: unknown;
10
- };
11
- }): void;