@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.
- package/dist/index.d.ts +1110 -8
- package/dist/index.js +2824 -15
- package/dist/package.json +1 -0
- package/package.json +6 -30
- package/dist/clear.d.ts +0 -2
- package/dist/clear.js +0 -46
- package/dist/click.d.ts +0 -9
- package/dist/click.js +0 -62
- package/dist/document/index.d.ts +0 -10
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.d.ts +0 -15
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.d.ts +0 -27
- package/dist/document/selection.js +0 -90
- package/dist/document/value.d.ts +0 -18
- package/dist/document/value.js +0 -77
- package/dist/hover.d.ts +0 -4
- package/dist/hover.js +0 -43
- package/dist/keyboard/getEventProps.d.ts +0 -17
- package/dist/keyboard/getEventProps.js +0 -33
- package/dist/keyboard/getNextKeyDef.d.ts +0 -19
- package/dist/keyboard/getNextKeyDef.js +0 -85
- package/dist/keyboard/index.d.ts +0 -19
- package/dist/keyboard/index.js +0 -78
- package/dist/keyboard/keyMap.d.ts +0 -5
- package/dist/keyboard/keyMap.js +0 -143
- package/dist/keyboard/keyboardImplementation.d.ts +0 -3
- package/dist/keyboard/keyboardImplementation.js +0 -169
- package/dist/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.d.ts +0 -5
- package/dist/keyboard/plugins/character.js +0 -166
- package/dist/keyboard/plugins/combination.d.ts +0 -5
- package/dist/keyboard/plugins/combination.js +0 -17
- package/dist/keyboard/plugins/control.d.ts +0 -6
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.d.ts +0 -11
- package/dist/keyboard/plugins/functional.js +0 -140
- package/dist/keyboard/plugins/index.d.ts +0 -8
- package/dist/keyboard/plugins/index.js +0 -42
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.d.ts +0 -1
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/specialCharMap.d.ts +0 -22
- package/dist/keyboard/specialCharMap.js +0 -30
- package/dist/keyboard/types.d.ts +0 -80
- package/dist/keyboard/types.js +0 -19
- package/dist/paste.d.ts +0 -7
- package/dist/paste.js +0 -60
- package/dist/pointer/index.d.ts +0 -18
- package/dist/pointer/index.js +0 -90
- package/dist/pointer/keyMap.d.ts +0 -2
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.d.ts +0 -6
- package/dist/pointer/parseKeyDef.js +0 -36
- package/dist/pointer/pointerAction.d.ts +0 -6
- package/dist/pointer/pointerAction.js +0 -52
- package/dist/pointer/pointerMove.d.ts +0 -5
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.d.ts +0 -7
- package/dist/pointer/pointerPress.js +0 -330
- package/dist/pointer/resolveSelectionTarget.d.ts +0 -5
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.d.ts +0 -72
- package/dist/pointer/types.js +0 -1
- package/dist/selectOptions.d.ts +0 -4
- package/dist/selectOptions.js +0 -142
- package/dist/setup.d.ts +0 -92
- package/dist/setup.js +0 -203
- package/dist/tab.d.ts +0 -5
- package/dist/tab.js +0 -12
- package/dist/type.d.ts +0 -14
- package/dist/type.js +0 -74
- package/dist/upload.d.ts +0 -10
- package/dist/upload.js +0 -92
- package/dist/utils/click/isClickableInput.d.ts +0 -1
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/edit/buildTimeValue.d.ts +0 -1
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.d.ts +0 -16
- package/dist/utils/edit/calculateNewValue.js +0 -50
- package/dist/utils/edit/fireInputEvent.d.ts +0 -11
- package/dist/utils/edit/fireInputEvent.js +0 -65
- package/dist/utils/edit/getValue.d.ts +0 -1
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.d.ts +0 -7
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.d.ts +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.d.ts +0 -1
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.d.ts +0 -4
- package/dist/utils/edit/prepareInput.js +0 -60
- package/dist/utils/focus/blur.d.ts +0 -2
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/focus.d.ts +0 -2
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.d.ts +0 -1
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.d.ts +0 -1
- package/dist/utils/focus/getTabDestination.js +0 -71
- package/dist/utils/focus/isFocusable.d.ts +0 -1
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selectAll.d.ts +0 -4
- package/dist/utils/focus/selectAll.js +0 -38
- package/dist/utils/focus/selection.d.ts +0 -42
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.d.ts +0 -1
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.d.ts +0 -31
- package/dist/utils/index.js +0 -408
- package/dist/utils/keyDef/readNextDescriptor.d.ts +0 -19
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.d.ts +0 -1
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.d.ts +0 -1
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.d.ts +0 -1
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.d.ts +0 -5
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/misc/isVisible.js +0 -24
- package/dist/utils/misc/wait.d.ts +0 -1
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/firePointerEvents.d.ts +0 -25
- package/dist/utils/pointer/firePointerEvents.js +0 -112
- package/dist/utils/pointer/mouseButtons.d.ts +0 -12
- package/dist/utils/pointer/mouseButtons.js +0 -45
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.readNextDescriptor = readNextDescriptor;
|
|
7
|
-
var bracketDict;
|
|
8
|
-
/**
|
|
9
|
-
* Read the next key definition from user input
|
|
10
|
-
*
|
|
11
|
-
* Describe key per `{descriptor}` or `[descriptor]`.
|
|
12
|
-
* Everything else will be interpreted as a single character as descriptor - e.g. `a`.
|
|
13
|
-
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
14
|
-
* A previously pressed key can be released per `{/descriptor}`.
|
|
15
|
-
* Keeping the key pressed can be written as `{descriptor>}`.
|
|
16
|
-
* When keeping the key pressed you can choose how long the key is pressed `{descriptor>3}`.
|
|
17
|
-
* You can then release the key per `{descriptor>3/}` or keep it pressed and continue with the next key.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
(function (bracketDict) {
|
|
21
|
-
bracketDict["{"] = "}";
|
|
22
|
-
bracketDict["["] = "]";
|
|
23
|
-
})(bracketDict || (bracketDict = {}));
|
|
24
|
-
|
|
25
|
-
function readNextDescriptor(text) {
|
|
26
|
-
let pos = 0;
|
|
27
|
-
const startBracket = text[pos] in bracketDict ? text[pos] : '';
|
|
28
|
-
pos += startBracket.length; // `foo{{bar` is an escaped char at position 3,
|
|
29
|
-
// but `foo{{{>5}bar` should be treated as `{` pressed down for 5 keydowns.
|
|
30
|
-
|
|
31
|
-
const startBracketRepeated = startBracket ? text.match(new RegExp(`^\\${startBracket}+`))[0].length : 0;
|
|
32
|
-
const isEscapedChar = startBracketRepeated === 2 || startBracket === '{' && startBracketRepeated > 3;
|
|
33
|
-
const type = isEscapedChar ? '' : startBracket;
|
|
34
|
-
return {
|
|
35
|
-
type,
|
|
36
|
-
...(type === '' ? readPrintableChar(text, pos) : readTag(text, pos, type))
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function readPrintableChar(text, pos) {
|
|
41
|
-
const descriptor = text[pos];
|
|
42
|
-
assertDescriptor(descriptor, text, pos);
|
|
43
|
-
pos += descriptor.length;
|
|
44
|
-
return {
|
|
45
|
-
consumedLength: pos,
|
|
46
|
-
descriptor,
|
|
47
|
-
releasePrevious: false,
|
|
48
|
-
releaseSelf: true,
|
|
49
|
-
repeat: 1
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function readTag(text, pos, startBracket) {
|
|
54
|
-
var _text$slice$match, _text$slice$match$, _text$slice$match2;
|
|
55
|
-
|
|
56
|
-
const releasePreviousModifier = text[pos] === '/' ? '/' : '';
|
|
57
|
-
pos += releasePreviousModifier.length;
|
|
58
|
-
const descriptor = (_text$slice$match = text.slice(pos).match(/^\w+/)) == null ? void 0 : _text$slice$match[0];
|
|
59
|
-
assertDescriptor(descriptor, text, pos);
|
|
60
|
-
pos += descriptor.length;
|
|
61
|
-
const repeatModifier = (_text$slice$match$ = (_text$slice$match2 = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _text$slice$match2[0]) != null ? _text$slice$match$ : '';
|
|
62
|
-
pos += repeatModifier.length;
|
|
63
|
-
const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
|
|
64
|
-
pos += releaseSelfModifier.length;
|
|
65
|
-
const expectedEndBracket = bracketDict[startBracket];
|
|
66
|
-
const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : '';
|
|
67
|
-
|
|
68
|
-
if (!endBracket) {
|
|
69
|
-
throw new Error(getErrorMessage([!repeatModifier && 'repeat modifier', !releaseSelfModifier && 'release modifier', `"${expectedEndBracket}"`].filter(Boolean).join(' or '), text[pos], text));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
pos += endBracket.length;
|
|
73
|
-
return {
|
|
74
|
-
consumedLength: pos,
|
|
75
|
-
descriptor,
|
|
76
|
-
releasePrevious: !!releasePreviousModifier,
|
|
77
|
-
repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
|
|
78
|
-
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
83
|
-
if (!descriptor) {
|
|
84
|
-
throw new Error(getErrorMessage('key descriptor', text[pos], text));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
89
|
-
if (releaseSelfModifier) {
|
|
90
|
-
return releaseSelfModifier === '/';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (repeatModifier) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function getErrorMessage(expected, found, text) {
|
|
99
|
-
return `Expected ${expected} but found "${found != null ? found : ''}" in "${text}"
|
|
100
|
-
See https://github.com/testing-library/user-event/blob/main/README.md#keyboardtext-options
|
|
101
|
-
for more information about how userEvent parses your input.`;
|
|
102
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function eventWrapper<T>(cb: () => T): T | undefined;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.eventWrapper = eventWrapper;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
function eventWrapper(cb) {
|
|
11
|
-
let result;
|
|
12
|
-
(0, _dom.getConfig)().eventWrapper(() => {
|
|
13
|
-
result = cb();
|
|
14
|
-
});
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function findClosest(element: Element, callback: (e: Element) => boolean): Element | undefined;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findClosest = findClosest;
|
|
7
|
-
|
|
8
|
-
function findClosest(element, callback) {
|
|
9
|
-
let el = element;
|
|
10
|
-
|
|
11
|
-
do {
|
|
12
|
-
if (callback(el)) {
|
|
13
|
-
return el;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
el = el.parentElement;
|
|
17
|
-
} while (el && el !== element.ownerDocument.body);
|
|
18
|
-
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const hasFormSubmit: (form: HTMLFormElement | null) => form is HTMLFormElement;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hasFormSubmit = void 0;
|
|
7
|
-
|
|
8
|
-
const hasFormSubmit = form => !!(form && (form.querySelector('input[type="submit"]') || form.querySelector('button[type="submit"]')));
|
|
9
|
-
|
|
10
|
-
exports.hasFormSubmit = hasFormSubmit;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options that can be passed to any event that relies
|
|
3
|
-
* on pointer-events property
|
|
4
|
-
*/
|
|
5
|
-
export declare interface PointerOptions {
|
|
6
|
-
/**
|
|
7
|
-
* When set to `true` the event skips checking if any element
|
|
8
|
-
* in the DOM-tree has `'pointer-events: none'` set. This check is
|
|
9
|
-
* costly in general and very costly when rendering large DOM-trees.
|
|
10
|
-
* Can be used to speed up tests.
|
|
11
|
-
* Default: `false`
|
|
12
|
-
* */
|
|
13
|
-
skipPointerEventsCheck?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare function hasPointerEvents(element: Element): boolean;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hasPointerEvents = hasPointerEvents;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@testing-library/dom/dist/helpers");
|
|
9
|
-
|
|
10
|
-
function hasPointerEvents(element) {
|
|
11
|
-
const window = (0, _helpers.getWindowFromNode)(element);
|
|
12
|
-
|
|
13
|
-
for (let el = element; (_el = el) != null && _el.ownerDocument; el = el.parentElement) {
|
|
14
|
-
var _el;
|
|
15
|
-
|
|
16
|
-
const pointerEvents = window.getComputedStyle(el).pointerEvents;
|
|
17
|
-
|
|
18
|
-
if (pointerEvents && !['inherit', 'unset'].includes(pointerEvents)) {
|
|
19
|
-
return pointerEvents !== 'none';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDescendantOrSelf(potentialDescendant: Element, potentialAncestor: Element): boolean;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isDescendantOrSelf = isDescendantOrSelf;
|
|
7
|
-
|
|
8
|
-
function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
9
|
-
let el = potentialDescendant;
|
|
10
|
-
|
|
11
|
-
do {
|
|
12
|
-
if (el === potentialAncestor) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
el = el.parentElement;
|
|
17
|
-
} while (el);
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDisabled(element: Element | null): boolean;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isDisabled = isDisabled;
|
|
7
|
-
|
|
8
|
-
// This should probably be extended with checking the element type
|
|
9
|
-
// https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
|
|
10
|
-
function isDisabled(element) {
|
|
11
|
-
return Boolean(element && element.disabled);
|
|
12
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
declare type tag = keyof HTMLElementTagNameMap;
|
|
2
|
-
export declare function isElementType<T extends tag, P extends {
|
|
3
|
-
[k: string]: unknown;
|
|
4
|
-
} | undefined = undefined>(element: Element, tag: T | T[], props?: P): element is P extends undefined ? HTMLElementTagNameMap[T] : HTMLElementTagNameMap[T] & P;
|
|
5
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isElementType = isElementType;
|
|
7
|
-
|
|
8
|
-
function isElementType(element, tag, props) {
|
|
9
|
-
if (element.namespaceURI && element.namespaceURI !== 'http://www.w3.org/1999/xhtml') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
tag = Array.isArray(tag) ? tag : [tag]; // tagName is uppercase in HTMLDocument and lowercase in XMLDocument
|
|
14
|
-
|
|
15
|
-
if (!tag.includes(element.tagName.toLowerCase())) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (props) {
|
|
20
|
-
return Object.entries(props).every(([k, v]) => element[k] === v);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isVisible(element: Element): boolean;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isVisible = isVisible;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@testing-library/dom/dist/helpers");
|
|
9
|
-
|
|
10
|
-
function isVisible(element) {
|
|
11
|
-
const window = (0, _helpers.getWindowFromNode)(element);
|
|
12
|
-
|
|
13
|
-
for (let el = element; (_el = el) != null && _el.ownerDocument; el = el.parentElement) {
|
|
14
|
-
var _el;
|
|
15
|
-
|
|
16
|
-
const display = window.getComputedStyle(el).display;
|
|
17
|
-
|
|
18
|
-
if (display === 'none') {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function wait(time?: number): Promise<void>;
|
package/dist/utils/misc/wait.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { pointerState } from '../../pointer/types';
|
|
2
|
-
import type { keyboardState } from '../../keyboard/types';
|
|
3
|
-
import { MouseButton } from './mouseButtons';
|
|
4
|
-
export declare function firePointerEvent(target: Element, type: string, { pointerState, keyboardState, pointerType, button, coords, pointerId, isPrimary, clickCount, }: {
|
|
5
|
-
pointerState: pointerState;
|
|
6
|
-
keyboardState: keyboardState;
|
|
7
|
-
pointerType?: 'mouse' | 'pen' | 'touch';
|
|
8
|
-
button?: MouseButton;
|
|
9
|
-
coords?: PointerCoords;
|
|
10
|
-
pointerId?: number;
|
|
11
|
-
isPrimary?: boolean;
|
|
12
|
-
clickCount?: number;
|
|
13
|
-
}): boolean;
|
|
14
|
-
export interface PointerCoords {
|
|
15
|
-
x?: number;
|
|
16
|
-
y?: number;
|
|
17
|
-
clientX?: number;
|
|
18
|
-
clientY?: number;
|
|
19
|
-
offsetX?: number;
|
|
20
|
-
offsetY?: number;
|
|
21
|
-
pageX?: number;
|
|
22
|
-
pageY?: number;
|
|
23
|
-
screenX?: number;
|
|
24
|
-
screenY?: number;
|
|
25
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.firePointerEvent = firePointerEvent;
|
|
7
|
-
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _eventMap = require("@testing-library/dom/dist/event-map");
|
|
11
|
-
|
|
12
|
-
var _mouseButtons = require("./mouseButtons");
|
|
13
|
-
|
|
14
|
-
function firePointerEvent(target, type, {
|
|
15
|
-
pointerState,
|
|
16
|
-
keyboardState,
|
|
17
|
-
pointerType,
|
|
18
|
-
button,
|
|
19
|
-
coords,
|
|
20
|
-
pointerId,
|
|
21
|
-
isPrimary,
|
|
22
|
-
clickCount
|
|
23
|
-
}) {
|
|
24
|
-
const init = { ...coords,
|
|
25
|
-
altKey: keyboardState.modifiers.alt,
|
|
26
|
-
ctrlKey: keyboardState.modifiers.ctrl,
|
|
27
|
-
metaKey: keyboardState.modifiers.meta,
|
|
28
|
-
shiftKey: keyboardState.modifiers.shift
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
if (type === 'click' || type.startsWith('pointer')) {
|
|
32
|
-
init.pointerId = pointerId;
|
|
33
|
-
init.pointerType = pointerType;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (['pointerdown', 'pointerup'].includes(type)) {
|
|
37
|
-
init.isPrimary = isPrimary;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click'].includes(type)) {
|
|
41
|
-
init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
|
|
42
|
-
init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
|
|
43
|
-
var _p$keyDef$button;
|
|
44
|
-
|
|
45
|
-
return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (['mousedown', 'mouseup', 'click', 'dblclick'].includes(type)) {
|
|
50
|
-
init.detail = clickCount;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const eventKey = Object.keys(_eventMap.eventMap).find(k => k.toLowerCase() === type);
|
|
54
|
-
|
|
55
|
-
const event = _dom.createEvent[eventKey](target, init); // see https://github.com/testing-library/react-testing-library/issues/268
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
assignPositionInit(event, init);
|
|
59
|
-
assignPointerInit(event, init);
|
|
60
|
-
return (0, _dom.fireEvent)(target, event);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function assignProps(obj, props) {
|
|
64
|
-
for (const [key, value] of Object.entries(props)) {
|
|
65
|
-
Object.defineProperty(obj, key, {
|
|
66
|
-
get: () => value
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function assignPositionInit(obj, {
|
|
72
|
-
x,
|
|
73
|
-
y,
|
|
74
|
-
clientX,
|
|
75
|
-
clientY,
|
|
76
|
-
offsetX,
|
|
77
|
-
offsetY,
|
|
78
|
-
pageX,
|
|
79
|
-
pageY,
|
|
80
|
-
screenX,
|
|
81
|
-
screenY
|
|
82
|
-
}) {
|
|
83
|
-
var _ref, _ref2, _ref3, _ref4;
|
|
84
|
-
|
|
85
|
-
assignProps(obj, {
|
|
86
|
-
/* istanbul ignore start */
|
|
87
|
-
x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
|
|
88
|
-
y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
|
|
89
|
-
clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
|
|
90
|
-
clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
|
|
91
|
-
offsetX: offsetX != null ? offsetX : 0,
|
|
92
|
-
offsetY: offsetY != null ? offsetY : 0,
|
|
93
|
-
pageX: pageX != null ? pageX : 0,
|
|
94
|
-
pageY: pageY != null ? pageY : 0,
|
|
95
|
-
screenX: screenX != null ? screenX : 0,
|
|
96
|
-
screenY: screenY != null ? screenY : 0
|
|
97
|
-
/* istanbul ignore end */
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function assignPointerInit(obj, {
|
|
103
|
-
isPrimary,
|
|
104
|
-
pointerId,
|
|
105
|
-
pointerType
|
|
106
|
-
}) {
|
|
107
|
-
assignProps(obj, {
|
|
108
|
-
isPrimary,
|
|
109
|
-
pointerId,
|
|
110
|
-
pointerType
|
|
111
|
-
});
|
|
112
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const MouseButton: {
|
|
2
|
-
readonly primary: 0;
|
|
3
|
-
readonly secondary: 1;
|
|
4
|
-
readonly auxiliary: 2;
|
|
5
|
-
readonly back: 3;
|
|
6
|
-
readonly X1: 3;
|
|
7
|
-
readonly forward: 4;
|
|
8
|
-
readonly X2: 4;
|
|
9
|
-
};
|
|
10
|
-
export declare type MouseButton = keyof typeof MouseButton | number;
|
|
11
|
-
export declare function getMouseButton(button: MouseButton): number;
|
|
12
|
-
export declare function getMouseButtons(...buttons: Array<MouseButton>): number;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.MouseButton = void 0;
|
|
7
|
-
exports.getMouseButton = getMouseButton;
|
|
8
|
-
exports.getMouseButtons = getMouseButtons;
|
|
9
|
-
const MouseButton = {
|
|
10
|
-
primary: 0,
|
|
11
|
-
secondary: 1,
|
|
12
|
-
auxiliary: 2,
|
|
13
|
-
back: 3,
|
|
14
|
-
X1: 3,
|
|
15
|
-
forward: 4,
|
|
16
|
-
X2: 4
|
|
17
|
-
};
|
|
18
|
-
exports.MouseButton = MouseButton;
|
|
19
|
-
// Some legacy...
|
|
20
|
-
const MouseButtonFlip = {
|
|
21
|
-
auxiliary: 1,
|
|
22
|
-
secondary: 2,
|
|
23
|
-
1: 2,
|
|
24
|
-
2: 1
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function getMouseButton(button) {
|
|
28
|
-
if (button in MouseButtonFlip) {
|
|
29
|
-
return MouseButtonFlip[button];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return typeof button === 'number' ? button : MouseButton[button];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getMouseButtons(...buttons) {
|
|
36
|
-
let v = 0;
|
|
37
|
-
|
|
38
|
-
for (const t of buttons) {
|
|
39
|
-
const pos = typeof t === 'number' ? t : MouseButton[t]; // eslint-disable-next-line no-bitwise
|
|
40
|
-
|
|
41
|
-
v |= 2 ** pos;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return v;
|
|
45
|
-
}
|