@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
@@ -0,0 +1 @@
1
+ {"type":"module"}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-alpha.9",
3
+ "version": "14.0.0-beta.4",
4
4
  "description": "Fire events the same way the user does",
5
- "main": "dist/index.js",
6
5
  "keywords": [
7
6
  "react-testing-library",
8
7
  "dom-testing-library",
@@ -26,8 +25,10 @@
26
25
  "files": [
27
26
  "dist"
28
27
  ],
28
+ "main": "./dist/index.js",
29
+ "exports": "./dist/index.js",
29
30
  "scripts": {
30
- "build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json",
31
+ "build": "node build.js",
31
32
  "lint": "kcd-scripts lint",
32
33
  "setup": "npm install && npm run validate -s",
33
34
  "test": "kcd-scripts test",
@@ -46,6 +47,7 @@
46
47
  "@types/estree": "0.0.45",
47
48
  "@types/jest-in-case": "^1.0.3",
48
49
  "@types/react": "^17.0.3",
50
+ "esbuild": "^0.14.9",
49
51
  "eslint-import-resolver-typescript": "^2.5.0",
50
52
  "is-ci": "^2.0.0",
51
53
  "jest-in-case": "^1.0.2",
@@ -57,31 +59,5 @@
57
59
  },
58
60
  "peerDependencies": {
59
61
  "@testing-library/dom": ">=7.21.4"
60
- },
61
- "eslintConfig": {
62
- "extends": "./node_modules/kcd-scripts/eslint.js",
63
- "rules": {
64
- "jsx-a11y/click-events-have-key-events": "off",
65
- "jsx-a11y/tabindex-no-positive": "off",
66
- "no-func-assign": "off",
67
- "no-return-assign": "off",
68
- "react/prop-types": "off",
69
- "testing-library/no-dom-import": "off"
70
- },
71
- "overrides": [
72
- {
73
- "files": [
74
- "**/__tests__/**"
75
- ],
76
- "rules": {
77
- "no-console": "off"
78
- }
79
- }
80
- ]
81
- },
82
- "eslintIgnore": [
83
- "node_modules",
84
- "coverage",
85
- "dist"
86
- ]
62
+ }
87
63
  }
package/dist/clear.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export declare function clear(this: UserEvent, element: Element): void;
package/dist/clear.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clear = clear;
7
-
8
- var _utils = require("./utils");
9
-
10
- function clear(element) {
11
- var _element$selectionSta, _element$selectionEnd;
12
-
13
- if (!(0, _utils.isElementType)(element, ['input', 'textarea'])) {
14
- // TODO: support contenteditable
15
- throw new Error('clear currently only supports input and textarea elements.');
16
- }
17
-
18
- if ((0, _utils.isDisabled)(element)) {
19
- return;
20
- } // TODO: track the selection range ourselves so we don't have to do this input "type" trickery
21
- // just like cypress does: https://github.com/cypress-io/cypress/blob/8d7f1a0bedc3c45a2ebf1ff50324b34129fdc683/packages/driver/src/dom/selection.ts#L16-L37
22
-
23
-
24
- const elementType = element.type;
25
-
26
- if (elementType !== 'textarea') {
27
- // setSelectionRange is not supported on certain types of inputs, e.g. "number" or "email"
28
- ;
29
- element.type = 'text';
30
- }
31
-
32
- this.type(element, '{selectall}{del}', {
33
- delay: 0,
34
- initialSelectionStart: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta :
35
- /* istanbul ignore next */
36
- undefined,
37
- initialSelectionEnd: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd :
38
- /* istanbul ignore next */
39
- undefined
40
- });
41
-
42
- if (elementType !== 'textarea') {
43
- ;
44
- element.type = elementType;
45
- }
46
- }
package/dist/click.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { PointerOptions } from './utils';
2
- import type { UserEvent } from './setup';
3
- export declare interface clickOptions {
4
- skipHover?: boolean;
5
- clickCount?: number;
6
- }
7
- export declare function click(this: UserEvent, element: Element, init?: MouseEventInit, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
8
- export declare function dblClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
9
- export declare function tripleClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
package/dist/click.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.click = click;
7
- exports.dblClick = dblClick;
8
- exports.tripleClick = tripleClick;
9
-
10
- var _utils = require("./utils");
11
-
12
- function click(element, init, {
13
- skipHover = false,
14
- skipPointerEventsCheck = false
15
- } = {}) {
16
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
17
- throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
18
- } // istanbul ignore else
19
-
20
-
21
- if (!skipHover) // We just checked for `pointerEvents`. We can always skip this one in `hover`.
22
- this.hover(element, init, {
23
- skipPointerEventsCheck: true
24
- });
25
- const keys = (init == null ? void 0 : init.button) === 2 || (init == null ? void 0 : init.buttons) === 2 ? '[MouseRight]' : '[MouseLeft]';
26
- this.pointer({
27
- keys,
28
- target: element
29
- });
30
- }
31
-
32
- function dblClick(element, init, {
33
- skipPointerEventsCheck = false
34
- } = {}) {
35
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
36
- throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
37
- }
38
-
39
- this.hover(element, init, {
40
- skipPointerEventsCheck
41
- });
42
- this.pointer({
43
- keys: '[MouseLeft][MouseLeft]',
44
- target: element
45
- });
46
- }
47
-
48
- function tripleClick(element, init, {
49
- skipPointerEventsCheck = false
50
- } = {}) {
51
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
52
- throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
53
- }
54
-
55
- this.hover(element, init, {
56
- skipPointerEventsCheck: true
57
- });
58
- this.pointer({
59
- keys: '[MouseLeft][MouseLeft][MouseLeft]',
60
- target: element
61
- });
62
- }
@@ -1,10 +0,0 @@
1
- declare const isPrepared: unique symbol;
2
- declare global {
3
- interface Node {
4
- [isPrepared]?: typeof isPrepared;
5
- }
6
- }
7
- export declare function prepareDocument(document: Document): void;
8
- export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
9
- export { getUISelection, setUISelection } from './selection';
10
- export type { UISelectionRange } from './selection';
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "endTrackValue", {
7
- enumerable: true,
8
- get: function () {
9
- return _value.endTrackValue;
10
- }
11
- });
12
- Object.defineProperty(exports, "getUISelection", {
13
- enumerable: true,
14
- get: function () {
15
- return _selection.getUISelection;
16
- }
17
- });
18
- Object.defineProperty(exports, "getUIValue", {
19
- enumerable: true,
20
- get: function () {
21
- return _value.getUIValue;
22
- }
23
- });
24
- exports.prepareDocument = prepareDocument;
25
- Object.defineProperty(exports, "setUISelection", {
26
- enumerable: true,
27
- get: function () {
28
- return _selection.setUISelection;
29
- }
30
- });
31
- Object.defineProperty(exports, "setUIValue", {
32
- enumerable: true,
33
- get: function () {
34
- return _value.setUIValue;
35
- }
36
- });
37
- Object.defineProperty(exports, "startTrackValue", {
38
- enumerable: true,
39
- get: function () {
40
- return _value.startTrackValue;
41
- }
42
- });
43
-
44
- var _dom = require("@testing-library/dom");
45
-
46
- var _selection = require("./selection");
47
-
48
- var _value = require("./value");
49
-
50
- const isPrepared = Symbol('Node prepared with document state workarounds');
51
-
52
- function prepareDocument(document) {
53
- if (document[isPrepared]) {
54
- return;
55
- }
56
-
57
- document.addEventListener('focus', e => {
58
- const el = e.target;
59
- prepareElement(el);
60
- }, {
61
- capture: true,
62
- passive: true
63
- }); // Our test environment defaults to `document.body` as `activeElement`.
64
- // In other environments this might be `null` when preparing.
65
- // istanbul ignore else
66
-
67
- if (document.activeElement) {
68
- prepareElement(document.activeElement);
69
- }
70
-
71
- document.addEventListener('blur', e => {
72
- const el = e.target;
73
- const initialValue = (0, _value.getInitialValue)(el);
74
-
75
- if (typeof initialValue === 'string' && el.value !== initialValue) {
76
- _dom.fireEvent.change(el);
77
- }
78
- }, {
79
- capture: true,
80
- passive: true
81
- });
82
- document[isPrepared] = isPrepared;
83
- }
84
-
85
- function prepareElement(el) {
86
- if ('value' in el) {
87
- (0, _value.setInitialValue)(el);
88
- }
89
-
90
- if (el[isPrepared]) {
91
- return;
92
- }
93
-
94
- if ('value' in el) {
95
- (0, _value.prepareValueInterceptor)(el);
96
- (0, _selection.prepareSelectionInterceptor)(el);
97
- }
98
-
99
- el[isPrepared] = isPrepared;
100
- }
@@ -1,15 +0,0 @@
1
- declare type anyFunc = (...a: any[]) => any;
2
- declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
3
- declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
4
- export declare function prepareInterceptor<ElementType extends Node, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
5
- /**
6
- * React tracks the changes on element properties.
7
- * This workaround tries to alter the DOM element without React noticing,
8
- * so that it later picks up the change.
9
- *
10
- * @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
11
- */
12
- applyNative?: boolean;
13
- realArgs?: ImplReturn<ElementType[PropName]>;
14
- }): void;
15
- export {};
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.prepareInterceptor = prepareInterceptor;
7
- const Interceptor = Symbol('Interceptor for programmatical calls');
8
-
9
- function prepareInterceptor(element, propName, interceptorImpl) {
10
- const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
11
- const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
12
- const target = prototypeDescriptor != null && prototypeDescriptor.set ? 'set' : 'value';
13
-
14
- if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
15
- return;
16
- }
17
-
18
- function intercept(...args) {
19
- const {
20
- applyNative = true,
21
- realArgs
22
- } = interceptorImpl.call(this, ...args);
23
- const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
24
-
25
- if (target === 'set') {
26
- realFunc.call(this, realArgs);
27
- } else {
28
- realFunc.call(this, ...realArgs);
29
- }
30
- }
31
-
32
- ;
33
- intercept[Interceptor] = Interceptor;
34
- Object.defineProperty(element, propName, { ...(objectDescriptor != null ? objectDescriptor : prototypeDescriptor),
35
- [target]: intercept
36
- });
37
- }
@@ -1,27 +0,0 @@
1
- declare const UISelection: unique symbol;
2
- export interface UISelectionRange {
3
- startOffset: number;
4
- endOffset: number;
5
- }
6
- export interface UISelection {
7
- anchorOffset: number;
8
- focusOffset: number;
9
- }
10
- declare global {
11
- interface Element {
12
- [UISelection]?: UISelection;
13
- }
14
- }
15
- export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
16
- export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam, }: {
17
- anchorOffset?: number;
18
- focusOffset: number;
19
- }, mode?: 'replace' | 'modify'): void;
20
- export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaElement): {
21
- startOffset: number;
22
- endOffset: number;
23
- anchorOffset: number;
24
- focusOffset: number;
25
- };
26
- export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
27
- export {};
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clearUISelection = clearUISelection;
7
- exports.getUISelection = getUISelection;
8
- exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
9
- exports.setUISelection = setUISelection;
10
-
11
- var _ = require(".");
12
-
13
- var _interceptor = require("./interceptor");
14
-
15
- const UISelection = Symbol('Displayed selection in UI');
16
-
17
- function prepareSelectionInterceptor(element) {
18
- (0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
19
- const isUI = start && typeof start === 'object' && start[UISelection];
20
-
21
- if (!isUI) {
22
- this[UISelection] = undefined;
23
- }
24
-
25
- return {
26
- realArgs: [Number(start), end, direction]
27
- };
28
- });
29
- (0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
30
- this[UISelection] = undefined;
31
- return {
32
- realArgs: v
33
- };
34
- });
35
- (0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
36
- this[UISelection] = undefined;
37
- return {
38
- realArgs: v
39
- };
40
- });
41
- }
42
-
43
- function setUISelection(element, {
44
- focusOffset: focusOffsetParam,
45
- anchorOffset: anchorOffsetParam = focusOffsetParam
46
- }, mode = 'replace') {
47
- const valueLength = (0, _.getUIValue)(element).length;
48
-
49
- const sanitizeOffset = o => Math.max(0, Math.min(valueLength, o));
50
-
51
- const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
52
- const focusOffset = sanitizeOffset(focusOffsetParam);
53
- const startOffset = Math.min(anchorOffset, focusOffset);
54
- const endOffset = Math.max(anchorOffset, focusOffset);
55
- element[UISelection] = {
56
- anchorOffset,
57
- focusOffset
58
- };
59
-
60
- if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
61
- return;
62
- } // eslint-disable-next-line no-new-wrappers
63
-
64
-
65
- const startObj = new Number(startOffset);
66
- startObj[UISelection] = UISelection;
67
-
68
- try {
69
- element.setSelectionRange(startObj, endOffset);
70
- } catch {// DOMException for invalid state is expected when calling this
71
- // on an element without support for setSelectionRange
72
- }
73
- }
74
-
75
- function getUISelection(element) {
76
- var _element$UISelection, _element$selectionSta, _element$selectionEnd;
77
-
78
- const sel = (_element$UISelection = element[UISelection]) != null ? _element$UISelection : {
79
- anchorOffset: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta : 0,
80
- focusOffset: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd : 0
81
- };
82
- return { ...sel,
83
- startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
84
- endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
85
- };
86
- }
87
-
88
- function clearUISelection(element) {
89
- element[UISelection] = undefined;
90
- }
@@ -1,18 +0,0 @@
1
- declare const UIValue: unique symbol;
2
- declare const InitialValue: unique symbol;
3
- declare const TrackChanges: unique symbol;
4
- declare global {
5
- interface Element {
6
- [UIValue]?: string;
7
- [InitialValue]?: string;
8
- [TrackChanges]?: string[];
9
- }
10
- }
11
- export declare function prepareValueInterceptor(element: HTMLInputElement): void;
12
- export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
13
- export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
14
- export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
15
- export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
16
- export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
17
- export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): string[] | undefined;
18
- export {};
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.endTrackValue = endTrackValue;
7
- exports.getInitialValue = getInitialValue;
8
- exports.getUIValue = getUIValue;
9
- exports.prepareValueInterceptor = prepareValueInterceptor;
10
- exports.setInitialValue = setInitialValue;
11
- exports.setUIValue = setUIValue;
12
- exports.startTrackValue = startTrackValue;
13
-
14
- var _interceptor = require("./interceptor");
15
-
16
- var _selection = require("./selection");
17
-
18
- const UIValue = Symbol('Displayed value in UI');
19
- const InitialValue = Symbol('Initial value to compare on blur');
20
- const TrackChanges = Symbol('Track programmatic changes for React workaround');
21
-
22
- function valueInterceptor(v) {
23
- const isUI = typeof v === 'object' && v[UIValue];
24
- this[UIValue] = isUI ? String(v) : undefined;
25
-
26
- if (!isUI) {
27
- trackValue(this, String(v));
28
- this[InitialValue] = String(v); // Programmatically setting the value property
29
- // moves the cursor to the end of the input.
30
-
31
- (0, _selection.clearUISelection)(this);
32
- }
33
-
34
- return {
35
- applyNative: !!isUI,
36
- realArgs: String(v)
37
- };
38
- }
39
-
40
- function prepareValueInterceptor(element) {
41
- (0, _interceptor.prepareInterceptor)(element, 'value', valueInterceptor);
42
- }
43
-
44
- function setUIValue(element, value) {
45
- element.value = {
46
- [UIValue]: UIValue,
47
- toString: () => value
48
- };
49
- }
50
-
51
- function getUIValue(element) {
52
- return element[UIValue] === undefined ? element.value : String(element[UIValue]);
53
- }
54
-
55
- function setInitialValue(element) {
56
- element[InitialValue] = element.value;
57
- }
58
-
59
- function getInitialValue(element) {
60
- return element[InitialValue];
61
- }
62
-
63
- function startTrackValue(element) {
64
- element[TrackChanges] = [];
65
- }
66
-
67
- function trackValue(element, v) {
68
- var _element$TrackChanges;
69
-
70
- (_element$TrackChanges = element[TrackChanges]) == null ? void 0 : _element$TrackChanges.push(v);
71
- }
72
-
73
- function endTrackValue(element) {
74
- const tracked = element[TrackChanges];
75
- element[TrackChanges] = undefined;
76
- return tracked;
77
- }
package/dist/hover.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- import { PointerOptions } from './utils';
3
- export declare function hover(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
4
- export declare function unhover(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
package/dist/hover.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hover = hover;
7
- exports.unhover = unhover;
8
-
9
- var _pointer = require("./pointer");
10
-
11
- var _utils = require("./utils");
12
-
13
- function hover(element, init, {
14
- skipPointerEventsCheck = false
15
- } = {}) {
16
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
17
- throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
18
- }
19
-
20
- const pointerState = (0, _pointer.createPointerState)();
21
- pointerState.position.mouse.target = element.ownerDocument.body;
22
- this.pointer({
23
- target: element
24
- }, {
25
- pointerState
26
- });
27
- }
28
-
29
- function unhover(element, init, {
30
- skipPointerEventsCheck = false
31
- } = {}) {
32
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
33
- throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
34
- }
35
-
36
- const pointerState = (0, _pointer.createPointerState)();
37
- pointerState.position.mouse.target = element;
38
- this.pointer({
39
- target: element.ownerDocument.body
40
- }, {
41
- pointerState
42
- });
43
- }
@@ -1,17 +0,0 @@
1
- import { keyboardKey, keyboardState } from './types';
2
- export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardState): {
3
- key: string | undefined;
4
- code: string | undefined;
5
- altKey: boolean;
6
- ctrlKey: boolean;
7
- metaKey: boolean;
8
- shiftKey: boolean;
9
- /** @deprecated use code instead */
10
- keyCode: number | undefined;
11
- };
12
- export declare function getMouseEventProps(state: keyboardState): {
13
- altKey: boolean;
14
- ctrlKey: boolean;
15
- metaKey: boolean;
16
- shiftKey: boolean;
17
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getKeyEventProps = getKeyEventProps;
7
- exports.getMouseEventProps = getMouseEventProps;
8
-
9
- function getKeyEventProps(keyDef, state) {
10
- var _keyDef$keyCode, _keyDef$key;
11
-
12
- return {
13
- key: keyDef.key,
14
- code: keyDef.code,
15
- altKey: state.modifiers.alt,
16
- ctrlKey: state.modifiers.ctrl,
17
- metaKey: state.modifiers.meta,
18
- shiftKey: state.modifiers.shift,
19
-
20
- /** @deprecated use code instead */
21
- keyCode: (_keyDef$keyCode = keyDef.keyCode) != null ? _keyDef$keyCode : // istanbul ignore next
22
- ((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 ? keyDef.key.charCodeAt(0) : undefined
23
- };
24
- }
25
-
26
- function getMouseEventProps(state) {
27
- return {
28
- altKey: state.modifiers.alt,
29
- ctrlKey: state.modifiers.ctrl,
30
- metaKey: state.modifiers.meta,
31
- shiftKey: state.modifiers.shift
32
- };
33
- }