@testing-library/user-event 14.0.0-alpha.3 → 14.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/click.d.ts +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +3 -3
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +11 -1
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +17 -8
- package/dist/document/selection.js +51 -28
- package/dist/document/value.d.ts +5 -1
- package/dist/document/value.js +27 -6
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/keyboard/plugins/character.js +23 -42
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/keyboard/plugins/functional.js +23 -11
- package/dist/paste.js +8 -15
- package/dist/pointer/pointerMove.js +28 -17
- package/dist/pointer/pointerPress.js +6 -4
- package/dist/pointer/resolveSelectionTarget.js +7 -6
- package/dist/setup.d.ts +5 -2
- package/dist/setup.js +4 -7
- package/dist/tab.d.ts +1 -2
- package/dist/tab.js +3 -132
- package/dist/utils/edit/calculateNewValue.d.ts +14 -5
- package/dist/utils/edit/calculateNewValue.js +23 -21
- package/dist/utils/edit/fireInputEvent.d.ts +5 -2
- package/dist/utils/edit/fireInputEvent.js +35 -25
- package/dist/utils/edit/isContentEditable.d.ts +4 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/utils/edit/isEditable.d.ts +1 -0
- package/dist/utils/edit/prepareInput.d.ts +4 -0
- package/dist/utils/edit/prepareInput.js +60 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +30 -30
- package/package.json +1 -1
- package/dist/document/applyNative.d.ts +0 -8
- package/dist/document/applyNative.js +0 -28
- package/dist/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/selectionRange.d.ts +0 -5
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
package/dist/click.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare interface clickOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function click(this: UserEvent, element: Element, init?: MouseEventInit, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
|
|
8
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
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.click = click;
|
|
7
7
|
exports.dblClick = dblClick;
|
|
8
|
+
exports.tripleClick = tripleClick;
|
|
8
9
|
|
|
9
10
|
var _utils = require("./utils");
|
|
10
11
|
|
|
@@ -42,4 +43,20 @@ function dblClick(element, init, {
|
|
|
42
43
|
keys: '[MouseLeft][MouseLeft]',
|
|
43
44
|
target: element
|
|
44
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
|
+
});
|
|
45
62
|
}
|
package/dist/document/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ declare global {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare function prepareDocument(document: Document): void;
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
8
|
+
export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
|
|
9
|
+
export { getUISelection, setUISelection } from './selection';
|
|
10
|
+
export type { UISelectionRange } from './selection';
|
package/dist/document/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "endTrackValue", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _value.endTrackValue;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "getUISelection", {
|
|
@@ -21,12 +21,6 @@ Object.defineProperty(exports, "getUIValue", {
|
|
|
21
21
|
return _value.getUIValue;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "hasUISelection", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _selection.hasUISelection;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
24
|
exports.prepareDocument = prepareDocument;
|
|
31
25
|
Object.defineProperty(exports, "setUISelection", {
|
|
32
26
|
enumerable: true,
|
|
@@ -40,6 +34,12 @@ Object.defineProperty(exports, "setUIValue", {
|
|
|
40
34
|
return _value.setUIValue;
|
|
41
35
|
}
|
|
42
36
|
});
|
|
37
|
+
Object.defineProperty(exports, "startTrackValue", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _value.startTrackValue;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
43
|
|
|
44
44
|
var _dom = require("@testing-library/dom");
|
|
45
45
|
|
|
@@ -47,8 +47,6 @@ var _selection = require("./selection");
|
|
|
47
47
|
|
|
48
48
|
var _value = require("./value");
|
|
49
49
|
|
|
50
|
-
var _applyNative = require("./applyNative");
|
|
51
|
-
|
|
52
50
|
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
53
51
|
|
|
54
52
|
function prepareDocument(document) {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
declare type anyFunc = (...a: any[]) => any;
|
|
2
2
|
declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
|
|
3
3
|
declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
|
|
4
|
-
export declare function prepareInterceptor<ElementType extends
|
|
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;
|
|
5
15
|
export {};
|
|
@@ -8,16 +8,19 @@ const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
|
8
8
|
|
|
9
9
|
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
10
10
|
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
11
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
11
12
|
const target = prototypeDescriptor != null && prototypeDescriptor.set ? 'set' : 'value';
|
|
12
13
|
|
|
13
14
|
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
const realFunc = prototypeDescriptor[target];
|
|
18
|
-
|
|
19
18
|
function intercept(...args) {
|
|
20
|
-
const
|
|
19
|
+
const {
|
|
20
|
+
applyNative = true,
|
|
21
|
+
realArgs
|
|
22
|
+
} = interceptorImpl.call(this, ...args);
|
|
23
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
21
24
|
|
|
22
25
|
if (target === 'set') {
|
|
23
26
|
realFunc.call(this, realArgs);
|
|
@@ -28,7 +31,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
28
31
|
|
|
29
32
|
;
|
|
30
33
|
intercept[Interceptor] = Interceptor;
|
|
31
|
-
Object.defineProperty(element
|
|
34
|
+
Object.defineProperty(element, propName, { ...(objectDescriptor != null ? objectDescriptor : prototypeDescriptor),
|
|
32
35
|
[target]: intercept
|
|
33
36
|
});
|
|
34
37
|
}
|
|
@@ -1,18 +1,27 @@
|
|
|
1
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
|
+
}
|
|
2
10
|
declare global {
|
|
3
11
|
interface Element {
|
|
4
|
-
[UISelection]?:
|
|
5
|
-
start: number;
|
|
6
|
-
end: number;
|
|
7
|
-
};
|
|
12
|
+
[UISelection]?: UISelection;
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
11
|
-
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement,
|
|
16
|
+
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement, { focusOffset: focusOffsetParam, anchorOffset: anchorOffsetParam, }: {
|
|
17
|
+
anchorOffset?: number;
|
|
18
|
+
focusOffset: number;
|
|
19
|
+
}, mode?: 'replace' | 'modify'): void;
|
|
12
20
|
export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaElement): {
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
startOffset: number;
|
|
22
|
+
endOffset: number;
|
|
23
|
+
anchorOffset: number;
|
|
24
|
+
focusOffset: number;
|
|
15
25
|
};
|
|
16
26
|
export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
|
-
export declare function hasUISelection(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
18
27
|
export {};
|
|
@@ -5,63 +5,86 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.clearUISelection = clearUISelection;
|
|
7
7
|
exports.getUISelection = getUISelection;
|
|
8
|
-
exports.hasUISelection = hasUISelection;
|
|
9
8
|
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
10
9
|
exports.setUISelection = setUISelection;
|
|
11
10
|
|
|
11
|
+
var _ = require(".");
|
|
12
|
+
|
|
12
13
|
var _interceptor = require("./interceptor");
|
|
13
14
|
|
|
14
15
|
const UISelection = Symbol('Displayed selection in UI');
|
|
15
16
|
|
|
16
|
-
function setSelectionInterceptor(start, end, direction = 'none') {
|
|
17
|
-
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
18
|
-
this[UISelection] = isUI ? {
|
|
19
|
-
start: start.valueOf(),
|
|
20
|
-
end: Number(end)
|
|
21
|
-
} : undefined;
|
|
22
|
-
return [Number(start), end, direction];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
17
|
function prepareSelectionInterceptor(element) {
|
|
26
|
-
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange',
|
|
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
|
+
});
|
|
27
41
|
}
|
|
28
42
|
|
|
29
|
-
function setUISelection(element,
|
|
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);
|
|
30
55
|
element[UISelection] = {
|
|
31
|
-
|
|
32
|
-
|
|
56
|
+
anchorOffset,
|
|
57
|
+
focusOffset
|
|
33
58
|
};
|
|
34
59
|
|
|
35
|
-
if (element.selectionStart ===
|
|
60
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
36
61
|
return;
|
|
37
62
|
} // eslint-disable-next-line no-new-wrappers
|
|
38
63
|
|
|
39
64
|
|
|
40
|
-
const startObj = new Number(
|
|
65
|
+
const startObj = new Number(startOffset);
|
|
41
66
|
startObj[UISelection] = UISelection;
|
|
42
67
|
|
|
43
68
|
try {
|
|
44
|
-
element.setSelectionRange(startObj,
|
|
69
|
+
element.setSelectionRange(startObj, endOffset);
|
|
45
70
|
} catch {// DOMException for invalid state is expected when calling this
|
|
46
71
|
// on an element without support for setSelectionRange
|
|
47
72
|
}
|
|
48
73
|
}
|
|
49
74
|
|
|
50
75
|
function getUISelection(element) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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)
|
|
58
85
|
};
|
|
59
86
|
}
|
|
60
87
|
|
|
61
88
|
function clearUISelection(element) {
|
|
62
89
|
element[UISelection] = undefined;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function hasUISelection(element) {
|
|
66
|
-
return Boolean(element[UISelection]);
|
|
67
90
|
}
|
package/dist/document/value.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
declare const UIValue: unique symbol;
|
|
2
2
|
declare const InitialValue: unique symbol;
|
|
3
|
+
declare const TrackChanges: unique symbol;
|
|
3
4
|
declare global {
|
|
4
5
|
interface Element {
|
|
5
6
|
[UIValue]?: string;
|
|
6
7
|
[InitialValue]?: string;
|
|
8
|
+
[TrackChanges]?: string[];
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
10
12
|
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
11
|
-
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string
|
|
13
|
+
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
|
|
12
14
|
export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
13
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;
|
|
14
18
|
export {};
|
package/dist/document/value.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.endTrackValue = endTrackValue;
|
|
6
7
|
exports.getInitialValue = getInitialValue;
|
|
7
8
|
exports.getUIValue = getUIValue;
|
|
8
9
|
exports.prepareValueInterceptor = prepareValueInterceptor;
|
|
9
10
|
exports.setInitialValue = setInitialValue;
|
|
10
11
|
exports.setUIValue = setUIValue;
|
|
11
|
-
|
|
12
|
-
var _applyNative = require("./applyNative");
|
|
12
|
+
exports.startTrackValue = startTrackValue;
|
|
13
13
|
|
|
14
14
|
var _interceptor = require("./interceptor");
|
|
15
15
|
|
|
@@ -17,19 +17,24 @@ var _selection = require("./selection");
|
|
|
17
17
|
|
|
18
18
|
const UIValue = Symbol('Displayed value in UI');
|
|
19
19
|
const InitialValue = Symbol('Initial value to compare on blur');
|
|
20
|
+
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
20
21
|
|
|
21
22
|
function valueInterceptor(v) {
|
|
22
23
|
const isUI = typeof v === 'object' && v[UIValue];
|
|
23
24
|
this[UIValue] = isUI ? String(v) : undefined;
|
|
24
25
|
|
|
25
26
|
if (!isUI) {
|
|
27
|
+
trackValue(this, String(v));
|
|
26
28
|
this[InitialValue] = String(v); // Programmatically setting the value property
|
|
27
29
|
// moves the cursor to the end of the input.
|
|
28
30
|
|
|
29
31
|
(0, _selection.clearUISelection)(this);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
applyNative: !!isUI,
|
|
36
|
+
realArgs: String(v)
|
|
37
|
+
};
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
function prepareValueInterceptor(element) {
|
|
@@ -37,14 +42,14 @@ function prepareValueInterceptor(element) {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
function setUIValue(element, value) {
|
|
40
|
-
|
|
45
|
+
element.value = {
|
|
41
46
|
[UIValue]: UIValue,
|
|
42
47
|
toString: () => value
|
|
43
|
-
}
|
|
48
|
+
};
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
function getUIValue(element) {
|
|
47
|
-
return element[UIValue] === undefined ? element.value : element[UIValue];
|
|
52
|
+
return element[UIValue] === undefined ? element.value : String(element[UIValue]);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
function setInitialValue(element) {
|
|
@@ -53,4 +58,20 @@ function setInitialValue(element) {
|
|
|
53
58
|
|
|
54
59
|
function getInitialValue(element) {
|
|
55
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;
|
|
56
77
|
}
|
package/dist/keyboard/keyMap.js
CHANGED
|
@@ -129,7 +129,9 @@ function keydown(keyDef, getCurrentElement, options, state) {
|
|
|
129
129
|
function keypress(keyDef, getCurrentElement, options, state) {
|
|
130
130
|
const element = getCurrentElement();
|
|
131
131
|
|
|
132
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, (0, _getEventProps.getKeyEventProps)(keyDef, state)
|
|
132
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
|
|
133
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
134
|
+
});
|
|
133
135
|
|
|
134
136
|
if (unpreventedDefault) {
|
|
135
137
|
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
|
|
@@ -7,6 +7,8 @@ exports.keydownBehavior = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("../../utils");
|
|
9
9
|
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* This file should contain behavior for arrow keys as described here:
|
|
12
14
|
* https://w3c.github.io/uievents-code/#key-arrowpad-section
|
|
@@ -15,19 +17,12 @@ const keydownBehavior = [{
|
|
|
15
17
|
// TODO: implement for contentEditable
|
|
16
18
|
matches: (keyDef, element) => (keyDef.key === 'ArrowLeft' || keyDef.key === 'ArrowRight') && (0, _utils.isElementType)(element, ['input', 'textarea']),
|
|
17
19
|
handle: (keyDef, element) => {
|
|
18
|
-
|
|
20
|
+
const selection = (0, _document.getUISelection)(element); // TODO: implement shift/ctrl
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const direction = keyDef.key === 'ArrowLeft' ? -1 : 1;
|
|
25
|
-
const newPos = (_ref = selectionStart === selectionEnd ? (selectionStart != null ? selectionStart :
|
|
26
|
-
/* istanbul ignore next */
|
|
27
|
-
0) + direction : direction < 0 ? selectionStart : selectionEnd) != null ? _ref :
|
|
28
|
-
/* istanbul ignore next */
|
|
29
|
-
0;
|
|
30
|
-
(0, _utils.setSelectionRange)(element, newPos, newPos);
|
|
22
|
+
(0, _utils.setSelection)({
|
|
23
|
+
focusNode: element,
|
|
24
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === 'ArrowLeft' ? -1 : 1) : keyDef.key === 'ArrowLeft' ? selection.startOffset : selection.endOffset
|
|
25
|
+
});
|
|
31
26
|
}
|
|
32
27
|
}];
|
|
33
28
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -36,15 +36,18 @@ const keypressBehavior = [{
|
|
|
36
36
|
|
|
37
37
|
const {
|
|
38
38
|
newValue,
|
|
39
|
-
|
|
40
|
-
} = (0, _utils.calculateNewValue)(newEntry, element);
|
|
39
|
+
newOffset
|
|
40
|
+
} = (0, _utils.calculateNewValue)(newEntry, element, (0, _utils.getInputRange)(element));
|
|
41
41
|
const prevValue = (0, _utils.getValue)(element); // this check was provided by fireInputEventIfNeeded
|
|
42
42
|
// TODO: verify if it is even needed by this handler
|
|
43
43
|
|
|
44
44
|
if (prevValue !== newValue) {
|
|
45
45
|
(0, _utils.fireInputEvent)(element, {
|
|
46
46
|
newValue,
|
|
47
|
-
|
|
47
|
+
newSelection: {
|
|
48
|
+
node: element,
|
|
49
|
+
offset: newOffset
|
|
50
|
+
},
|
|
48
51
|
eventOverrides: {
|
|
49
52
|
data: keyDef.key,
|
|
50
53
|
inputType: 'insertText'
|
|
@@ -77,15 +80,18 @@ const keypressBehavior = [{
|
|
|
77
80
|
|
|
78
81
|
const {
|
|
79
82
|
newValue,
|
|
80
|
-
|
|
81
|
-
} = (0, _utils.calculateNewValue)(newEntry, element);
|
|
83
|
+
newOffset
|
|
84
|
+
} = (0, _utils.calculateNewValue)(newEntry, element, (0, _utils.getInputRange)(element));
|
|
82
85
|
const prevValue = (0, _utils.getValue)(element); // this check was provided by fireInputEventIfNeeded
|
|
83
86
|
// TODO: verify if it is even needed by this handler
|
|
84
87
|
|
|
85
88
|
if (prevValue !== newValue) {
|
|
86
89
|
(0, _utils.fireInputEvent)(element, {
|
|
87
90
|
newValue,
|
|
88
|
-
|
|
91
|
+
newSelection: {
|
|
92
|
+
node: element,
|
|
93
|
+
offset: newOffset
|
|
94
|
+
},
|
|
89
95
|
eventOverrides: {
|
|
90
96
|
data: keyDef.key,
|
|
91
97
|
inputType: 'insertText'
|
|
@@ -121,8 +127,8 @@ const keypressBehavior = [{
|
|
|
121
127
|
|
|
122
128
|
const {
|
|
123
129
|
newValue,
|
|
124
|
-
|
|
125
|
-
} = (0, _utils.
|
|
130
|
+
commit
|
|
131
|
+
} = (0, _utils.prepareInput)(keyDef.key, element); // the browser allows some invalid input but not others
|
|
126
132
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
127
133
|
// it allows one '.' at any place before e
|
|
128
134
|
|
|
@@ -132,54 +138,29 @@ const keypressBehavior = [{
|
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
|
|
135
|
-
(
|
|
136
|
-
newValue,
|
|
137
|
-
newSelectionStart,
|
|
138
|
-
eventOverrides: {
|
|
139
|
-
data: keyDef.key,
|
|
140
|
-
inputType: 'insertText'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
141
|
+
commit();
|
|
143
142
|
}
|
|
144
143
|
}, {
|
|
145
144
|
matches: (keyDef, element) => {
|
|
146
145
|
var _keyDef$key4;
|
|
147
146
|
|
|
148
|
-
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.
|
|
147
|
+
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.isEditableInput)(element) || (0, _utils.isElementType)(element, 'textarea', {
|
|
149
148
|
readOnly: false
|
|
150
|
-
})
|
|
149
|
+
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0;
|
|
151
150
|
},
|
|
152
151
|
handle: (keyDef, element) => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} = (0, _utils.calculateNewValue)(keyDef.key, element);
|
|
157
|
-
(0, _utils.fireInputEvent)(element, {
|
|
158
|
-
newValue,
|
|
159
|
-
newSelectionStart,
|
|
160
|
-
eventOverrides: {
|
|
161
|
-
data: keyDef.key,
|
|
162
|
-
inputType: 'insertText'
|
|
163
|
-
}
|
|
164
|
-
});
|
|
152
|
+
var _prepareInput;
|
|
153
|
+
|
|
154
|
+
(_prepareInput = (0, _utils.prepareInput)(keyDef.key, element)) == null ? void 0 : _prepareInput.commit();
|
|
165
155
|
}
|
|
166
156
|
}, {
|
|
167
157
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
|
|
168
158
|
readOnly: false
|
|
169
159
|
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
|
|
170
160
|
handle: (keyDef, element, options, state) => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
} = (0, _utils.calculateNewValue)('\n', element);
|
|
175
|
-
const inputType = (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak';
|
|
176
|
-
(0, _utils.fireInputEvent)(element, {
|
|
177
|
-
newValue,
|
|
178
|
-
newSelectionStart,
|
|
179
|
-
eventOverrides: {
|
|
180
|
-
inputType
|
|
181
|
-
}
|
|
182
|
-
});
|
|
161
|
+
var _prepareInput2;
|
|
162
|
+
|
|
163
|
+
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
|
|
183
164
|
}
|
|
184
165
|
}];
|
|
185
166
|
exports.keypressBehavior = keypressBehavior;
|
|
@@ -42,19 +42,11 @@ const keydownBehavior = [{
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}, {
|
|
45
|
-
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element)
|
|
45
|
+
matches: (keyDef, element) => keyDef.key === 'Delete' && (0, _utils.isEditable)(element),
|
|
46
46
|
handle: (keDef, element) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} = (0, _utils.calculateNewValue)('', element, undefined, undefined, 'forward');
|
|
51
|
-
(0, _utils.fireInputEvent)(element, {
|
|
52
|
-
newValue,
|
|
53
|
-
newSelectionStart,
|
|
54
|
-
eventOverrides: {
|
|
55
|
-
inputType: 'deleteContentForward'
|
|
56
|
-
}
|
|
57
|
-
});
|
|
47
|
+
var _prepareInput;
|
|
48
|
+
|
|
49
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentForward')) == null ? void 0 : _prepareInput.commit();
|
|
58
50
|
}
|
|
59
51
|
}];
|
|
60
52
|
exports.keydownBehavior = keydownBehavior;
|
|
@@ -7,6 +7,8 @@ exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavio
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
10
12
|
var _utils = require("../../utils");
|
|
11
13
|
|
|
12
14
|
var _getEventProps = require("../getEventProps");
|
|
@@ -51,19 +53,29 @@ const keydownBehavior = [{
|
|
|
51
53
|
state.modifiers.caps = !state.modifiers.caps;
|
|
52
54
|
}
|
|
53
55
|
}, {
|
|
54
|
-
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element)
|
|
56
|
+
matches: (keyDef, element) => keyDef.key === 'Backspace' && (0, _utils.isEditable)(element),
|
|
55
57
|
handle: (keyDef, element) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
var _prepareInput;
|
|
59
|
+
|
|
60
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentBackward')) == null ? void 0 : _prepareInput.commit();
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
matches: keyDef => keyDef.key === 'Tab',
|
|
64
|
+
handle: (keyDef, element, options, state) => {
|
|
65
|
+
const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
|
|
66
|
+
|
|
67
|
+
if (dest === element.ownerDocument.body) {
|
|
68
|
+
(0, _utils.blur)(element);
|
|
69
|
+
} else {
|
|
70
|
+
(0, _utils.focus)(dest);
|
|
71
|
+
|
|
72
|
+
if ((0, _utils.isElementType)(dest, ['input', 'textarea'])) {
|
|
73
|
+
(0, _document.setUISelection)(dest, {
|
|
74
|
+
anchorOffset: 0,
|
|
75
|
+
focusOffset: dest.value.length
|
|
76
|
+
});
|
|
65
77
|
}
|
|
66
|
-
}
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
}];
|
|
69
81
|
exports.keydownBehavior = keydownBehavior;
|