@testing-library/user-event 14.0.0-alpha.1 → 14.0.0-alpha.10
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/{src/clear.d.ts → clear.d.ts} +0 -0
- package/dist/clear.js +14 -27
- package/dist/{src/click.d.ts → click.d.ts} +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +51 -28
- package/dist/{src/document → document}/value.d.ts +5 -1
- package/dist/document/value.js +27 -6
- package/dist/{src/hover.d.ts → hover.d.ts} +0 -0
- package/dist/{src/index.d.ts → index.d.ts} +0 -0
- package/dist/{src/keyboard → keyboard}/getEventProps.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/getNextKeyDef.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/keyMap.d.ts +0 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/{src/keyboard → keyboard}/keyboardImplementation.d.ts +0 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/{src/keyboard → keyboard}/plugins/arrow.d.ts +0 -0
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/{src/keyboard → keyboard}/plugins/character.d.ts +0 -0
- package/dist/keyboard/plugins/character.js +27 -45
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/{src/keyboard → keyboard}/plugins/control.d.ts +0 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/{src/keyboard → keyboard}/plugins/functional.d.ts +0 -0
- package/dist/keyboard/plugins/functional.js +23 -11
- package/dist/{src/keyboard → keyboard}/plugins/index.d.ts +0 -0
- package/dist/keyboard/plugins/index.js +3 -1
- package/dist/{src/keyboard → keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/shared/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/specialCharMap.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/types.d.ts +0 -0
- package/dist/{src/paste.d.ts → paste.d.ts} +0 -0
- package/dist/paste.js +8 -15
- package/dist/{src/pointer → pointer}/index.d.ts +0 -0
- package/dist/{src/pointer → pointer}/keyMap.d.ts +0 -0
- package/dist/{src/pointer → pointer}/parseKeyDef.d.ts +0 -0
- package/dist/{src/pointer → pointer}/pointerAction.d.ts +2 -6
- package/dist/pointer/pointerAction.js +2 -26
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +49 -5
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +135 -29
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/{src/pointer → pointer}/types.d.ts +18 -4
- package/dist/{src/selectOptions.d.ts → selectOptions.d.ts} +0 -0
- package/dist/{src/setup.d.ts → setup.d.ts} +5 -2
- package/dist/setup.js +4 -7
- package/dist/tab.d.ts +5 -0
- package/dist/tab.js +3 -132
- package/dist/{src/type.d.ts → type.d.ts} +0 -0
- package/dist/type.js +3 -19
- package/dist/{src/upload.d.ts → upload.d.ts} +0 -0
- package/dist/{src/utils → utils}/click/isClickableInput.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/utils/edit/calculateNewValue.d.ts +14 -0
- package/dist/utils/edit/calculateNewValue.js +19 -21
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/editInputElement.js +53 -0
- package/dist/{src/utils → utils}/edit/getValue.d.ts +0 -0
- package/dist/utils/edit/getValue.js +1 -3
- package/dist/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/{src/utils → utils}/edit/isEditable.d.ts +1 -0
- package/dist/{src/utils → utils}/edit/isValidDateValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/isValidInputTimeValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/maxLength.d.ts +0 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{src/utils → utils}/focus/blur.d.ts +0 -0
- package/dist/{src/utils → utils}/focus/focus.d.ts +0 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/{src/utils → utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/{src/utils → utils}/focus/isFocusable.d.ts +0 -0
- package/dist/utils/focus/selectAll.d.ts +5 -0
- package/dist/utils/focus/selectAll.js +51 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/{src/utils → utils}/focus/selector.d.ts +0 -0
- package/dist/{src/utils → utils}/index.d.ts +5 -5
- package/dist/utils/index.js +47 -47
- package/dist/{src/utils → utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/findClosest.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasFormSubmit.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasPointerEvents.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isElementType.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isVisible.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/wait.d.ts +0 -0
- package/dist/{src/utils → utils}/pointer/firePointerEvents.d.ts +13 -11
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/dist/{src/utils → utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +2 -2
- package/dist/document/applyNative.js +0 -28
- package/dist/src/document/applyNative.d.ts +0 -8
- package/dist/src/document/index.d.ts +0 -10
- package/dist/src/document/interceptor.d.ts +0 -5
- package/dist/src/document/selection.d.ts +0 -18
- package/dist/src/pointer/pointerMove.d.ts +0 -5
- package/dist/src/pointer/pointerPress.d.ts +0 -7
- package/dist/src/tab.d.ts +0 -6
- package/dist/src/utils/edit/calculateNewValue.d.ts +0 -7
- package/dist/src/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/src/utils/edit/fireInputEvent.d.ts +0 -8
- package/dist/src/utils/edit/isContentEditable.d.ts +0 -3
- package/dist/src/utils/edit/selectionRange.d.ts +0 -5
- package/dist/src/utils/misc/isDocument.d.ts +0 -1
- package/dist/src/utils/pointer/fakeEvent.d.ts +0 -16
- package/dist/tests/_helpers/custom-element.d.ts +0 -8
- package/dist/tests/_helpers/utils.d.ts +0 -73
- package/dist/tests/_setup-env.d.ts +0 -1
- package/dist/tests/clear.d.ts +0 -1
- package/dist/tests/click/click.d.ts +0 -1
- package/dist/tests/click/dblclick.d.ts +0 -1
- package/dist/tests/document/index.d.ts +0 -1
- package/dist/tests/document/selectionRange.d.ts +0 -1
- package/dist/tests/hover/hover.d.ts +0 -1
- package/dist/tests/hover/unhover.d.ts +0 -1
- package/dist/tests/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/tests/keyboard/index.d.ts +0 -1
- package/dist/tests/keyboard/keyboardImplementation.d.ts +0 -1
- package/dist/tests/keyboard/plugin/arrow.d.ts +0 -1
- package/dist/tests/keyboard/plugin/character.d.ts +0 -1
- package/dist/tests/keyboard/plugin/control.d.ts +0 -1
- package/dist/tests/keyboard/plugin/functional.d.ts +0 -1
- package/dist/tests/keyboard/shared/fireInputEvent.d.ts +0 -1
- package/dist/tests/paste.d.ts +0 -1
- package/dist/tests/pointer/index.d.ts +0 -1
- package/dist/tests/react/keyboard.d.ts +0 -1
- package/dist/tests/react/type.d.ts +0 -1
- package/dist/tests/selectOptions/deselect.d.ts +0 -1
- package/dist/tests/selectOptions/select.d.ts +0 -1
- package/dist/tests/setup.d.ts +0 -10
- package/dist/tests/tab.d.ts +0 -1
- package/dist/tests/type/index.d.ts +0 -1
- package/dist/tests/type/modifiers.d.ts +0 -1
- package/dist/tests/upload.d.ts +0 -1
- package/dist/tests/utils/edit/calculateNewValue.d.ts +0 -1
- package/dist/tests/utils/edit/isContentEditable.d.ts +0 -1
- package/dist/tests/utils/focus/blur.d.ts +0 -1
- package/dist/tests/utils/focus/focus.d.ts +0 -1
- package/dist/tests/utils/misc/hasPointerEvents.d.ts +0 -1
- package/dist/tests/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/tests/utils/misc/isElementType.d.ts +0 -1
- package/dist/tests/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/fireInputEvent.js +0 -55
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/misc/dom-helpers.d.ts +0 -3
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/pointer/fakeEvent.js +0 -82
|
File without changes
|
package/dist/clear.js
CHANGED
|
@@ -5,42 +5,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.clear = clear;
|
|
7
7
|
|
|
8
|
+
var _document = require("./document");
|
|
9
|
+
|
|
8
10
|
var _utils = require("./utils");
|
|
9
11
|
|
|
10
12
|
function clear(element) {
|
|
11
|
-
var
|
|
13
|
+
var _prepareInput;
|
|
12
14
|
|
|
13
|
-
if (!(0, _utils.
|
|
14
|
-
|
|
15
|
-
throw new Error('clear currently only supports input and textarea elements.');
|
|
15
|
+
if (!(0, _utils.isEditable)(element) || (0, _utils.isDisabled)(element)) {
|
|
16
|
+
throw new Error('clear()` is only supported on editable elements.');
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
19
|
+
(0, _document.prepareDocument)(element.ownerDocument);
|
|
20
|
+
(0, _utils.focus)(element);
|
|
22
21
|
|
|
22
|
+
if (element.ownerDocument.activeElement !== element) {
|
|
23
|
+
throw new Error('The element to be cleared could not be focused.');
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
(0, _utils.selectAll)(element);
|
|
25
27
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
;
|
|
29
|
-
element.type = 'text';
|
|
28
|
+
if (!(0, _utils.isAllSelected)(element)) {
|
|
29
|
+
throw new Error('The element content to be cleared could not be selected.');
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
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
|
-
}
|
|
32
|
+
(_prepareInput = (0, _utils.prepareInput)('', element, 'deleteContentBackward')) == null ? void 0 : _prepareInput.commit();
|
|
46
33
|
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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';
|
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) {
|
|
@@ -0,0 +1,15 @@
|
|
|
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 {};
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 {};
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/keyboard/keyMap.js
CHANGED
|
File without changes
|
|
@@ -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);
|
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
|
@@ -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
|
-
(0, _utils.
|
|
45
|
+
(0, _utils.editInputElement)(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
|
-
(0, _utils.
|
|
89
|
+
(0, _utils.editInputElement)(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'
|
|
@@ -120,9 +126,10 @@ const keypressBehavior = [{
|
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
const {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
} = (0, _utils.
|
|
129
|
+
getNewValue,
|
|
130
|
+
commit
|
|
131
|
+
} = (0, _utils.prepareInput)(keyDef.key, element);
|
|
132
|
+
const newValue = getNewValue(); // the browser allows some invalid input but not others
|
|
126
133
|
// it allows up to two '-' at any place before any 'e' or one directly following 'e'
|
|
127
134
|
// it allows one '.' at any place before e
|
|
128
135
|
|
|
@@ -132,54 +139,29 @@ const keypressBehavior = [{
|
|
|
132
139
|
return;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
(
|
|
136
|
-
newValue,
|
|
137
|
-
newSelectionStart,
|
|
138
|
-
eventOverrides: {
|
|
139
|
-
data: keyDef.key,
|
|
140
|
-
inputType: 'insertText'
|
|
141
|
-
}
|
|
142
|
-
});
|
|
142
|
+
commit();
|
|
143
143
|
}
|
|
144
144
|
}, {
|
|
145
145
|
matches: (keyDef, element) => {
|
|
146
146
|
var _keyDef$key4;
|
|
147
147
|
|
|
148
|
-
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.
|
|
148
|
+
return ((_keyDef$key4 = keyDef.key) == null ? void 0 : _keyDef$key4.length) === 1 && ((0, _utils.isEditableInput)(element) || (0, _utils.isElementType)(element, 'textarea', {
|
|
149
149
|
readOnly: false
|
|
150
|
-
})
|
|
150
|
+
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0;
|
|
151
151
|
},
|
|
152
152
|
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
|
-
});
|
|
153
|
+
var _prepareInput;
|
|
154
|
+
|
|
155
|
+
(_prepareInput = (0, _utils.prepareInput)(keyDef.key, element)) == null ? void 0 : _prepareInput.commit();
|
|
165
156
|
}
|
|
166
157
|
}, {
|
|
167
158
|
matches: (keyDef, element) => keyDef.key === 'Enter' && ((0, _utils.isElementType)(element, 'textarea', {
|
|
168
159
|
readOnly: false
|
|
169
160
|
}) || (0, _utils.isContentEditable)(element)) && (0, _utils.getSpaceUntilMaxLength)(element) !== 0,
|
|
170
161
|
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
|
-
});
|
|
162
|
+
var _prepareInput2;
|
|
163
|
+
|
|
164
|
+
(_prepareInput2 = (0, _utils.prepareInput)('\n', element, (0, _utils.isContentEditable)(element) && !state.modifiers.shift ? 'insertParagraph' : 'insertLineBreak')) == null ? void 0 : _prepareInput2.commit();
|
|
183
165
|
}
|
|
184
166
|
}];
|
|
185
167
|
exports.keypressBehavior = keypressBehavior;
|