@testing-library/user-event 14.0.0-alpha.1 → 14.0.0-alpha.5

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 (135) hide show
  1. package/dist/{src/clear.d.ts → clear.d.ts} +0 -0
  2. package/dist/{src/click.d.ts → click.d.ts} +0 -0
  3. package/dist/{src/document → document}/index.d.ts +2 -3
  4. package/dist/document/index.js +8 -10
  5. package/dist/document/interceptor.d.ts +15 -0
  6. package/dist/document/interceptor.js +7 -4
  7. package/dist/{src/document → document}/selection.d.ts +0 -1
  8. package/dist/document/selection.js +22 -15
  9. package/dist/{src/document → document}/value.d.ts +4 -0
  10. package/dist/document/value.js +26 -5
  11. package/dist/{src/hover.d.ts → hover.d.ts} +0 -0
  12. package/dist/{src/index.d.ts → index.d.ts} +0 -0
  13. package/dist/{src/keyboard → keyboard}/getEventProps.d.ts +0 -0
  14. package/dist/{src/keyboard → keyboard}/getNextKeyDef.d.ts +0 -0
  15. package/dist/{src/keyboard → keyboard}/index.d.ts +0 -0
  16. package/dist/{src/keyboard → keyboard}/keyMap.d.ts +0 -0
  17. package/dist/keyboard/keyMap.js +4 -0
  18. package/dist/{src/keyboard → keyboard}/keyboardImplementation.d.ts +0 -0
  19. package/dist/keyboard/keyboardImplementation.js +3 -1
  20. package/dist/{src/keyboard → keyboard}/plugins/arrow.d.ts +0 -0
  21. package/dist/{src/keyboard → keyboard}/plugins/character.d.ts +0 -0
  22. package/dist/{src/keyboard → keyboard}/plugins/control.d.ts +0 -0
  23. package/dist/{src/keyboard → keyboard}/plugins/functional.d.ts +0 -0
  24. package/dist/keyboard/plugins/functional.js +17 -0
  25. package/dist/{src/keyboard → keyboard}/plugins/index.d.ts +0 -0
  26. package/dist/{src/keyboard → keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
  27. package/dist/{src/keyboard → keyboard}/shared/index.d.ts +0 -0
  28. package/dist/{src/keyboard → keyboard}/specialCharMap.d.ts +0 -0
  29. package/dist/{src/keyboard → keyboard}/types.d.ts +0 -0
  30. package/dist/{src/paste.d.ts → paste.d.ts} +0 -0
  31. package/dist/{src/pointer → pointer}/index.d.ts +0 -0
  32. package/dist/{src/pointer → pointer}/keyMap.d.ts +0 -0
  33. package/dist/{src/pointer → pointer}/parseKeyDef.d.ts +0 -0
  34. package/dist/{src/pointer → pointer}/pointerAction.d.ts +2 -6
  35. package/dist/pointer/pointerAction.js +2 -26
  36. package/dist/pointer/pointerMove.d.ts +5 -0
  37. package/dist/pointer/pointerMove.js +38 -5
  38. package/dist/pointer/pointerPress.d.ts +7 -0
  39. package/dist/pointer/pointerPress.js +133 -29
  40. package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
  41. package/dist/pointer/resolveSelectionTarget.js +74 -0
  42. package/dist/{src/pointer → pointer}/types.d.ts +18 -4
  43. package/dist/{src/selectOptions.d.ts → selectOptions.d.ts} +0 -0
  44. package/dist/{src/setup.d.ts → setup.d.ts} +1 -1
  45. package/dist/setup.js +0 -7
  46. package/dist/tab.d.ts +5 -0
  47. package/dist/tab.js +3 -132
  48. package/dist/{src/type.d.ts → type.d.ts} +0 -0
  49. package/dist/type.js +3 -19
  50. package/dist/{src/upload.d.ts → upload.d.ts} +0 -0
  51. package/dist/{src/utils → utils}/click/isClickableInput.d.ts +0 -0
  52. package/dist/{src/utils → utils}/edit/buildTimeValue.d.ts +0 -0
  53. package/dist/{src/utils → utils}/edit/calculateNewValue.d.ts +0 -0
  54. package/dist/{src/utils → utils}/edit/cursorPosition.d.ts +0 -0
  55. package/dist/{src/utils → utils}/edit/fireInputEvent.d.ts +0 -0
  56. package/dist/utils/edit/fireInputEvent.js +20 -16
  57. package/dist/{src/utils → utils}/edit/getValue.d.ts +0 -0
  58. package/dist/utils/edit/getValue.js +1 -3
  59. package/dist/{src/utils → utils}/edit/isContentEditable.d.ts +0 -0
  60. package/dist/{src/utils → utils}/edit/isEditable.d.ts +0 -0
  61. package/dist/{src/utils → utils}/edit/isValidDateValue.d.ts +0 -0
  62. package/dist/{src/utils → utils}/edit/isValidInputTimeValue.d.ts +0 -0
  63. package/dist/{src/utils → utils}/edit/maxLength.d.ts +0 -0
  64. package/dist/{src/utils → utils}/edit/selectionRange.d.ts +0 -0
  65. package/dist/{src/utils → utils}/focus/blur.d.ts +0 -0
  66. package/dist/{src/utils → utils}/focus/focus.d.ts +0 -0
  67. package/dist/{src/utils → utils}/focus/getActiveElement.d.ts +0 -0
  68. package/dist/utils/focus/getTabDestination.d.ts +1 -0
  69. package/dist/utils/focus/getTabDestination.js +71 -0
  70. package/dist/{src/utils → utils}/focus/isFocusable.d.ts +0 -0
  71. package/dist/{src/utils → utils}/focus/selector.d.ts +0 -0
  72. package/dist/{src/utils → utils}/index.d.ts +1 -1
  73. package/dist/utils/index.js +13 -13
  74. package/dist/{src/utils → utils}/keyDef/readNextDescriptor.d.ts +0 -0
  75. package/dist/{src/utils → utils}/misc/eventWrapper.d.ts +0 -0
  76. package/dist/{src/utils → utils}/misc/findClosest.d.ts +0 -0
  77. package/dist/{src/utils → utils}/misc/hasFormSubmit.d.ts +0 -0
  78. package/dist/{src/utils → utils}/misc/hasPointerEvents.d.ts +0 -0
  79. package/dist/{src/utils → utils}/misc/isDescendantOrSelf.d.ts +0 -0
  80. package/dist/{src/utils → utils}/misc/isDisabled.d.ts +0 -0
  81. package/dist/{src/utils → utils}/misc/isElementType.d.ts +0 -0
  82. package/dist/{src/utils → utils}/misc/isVisible.d.ts +0 -0
  83. package/dist/{src/utils → utils}/misc/wait.d.ts +0 -0
  84. package/dist/utils/pointer/fakeEvent.d.ts +20 -0
  85. package/dist/utils/pointer/fakeEvent.js +18 -9
  86. package/dist/{src/utils → utils}/pointer/firePointerEvents.d.ts +2 -11
  87. package/dist/{src/utils → utils}/pointer/mouseButtons.d.ts +0 -0
  88. package/package.json +2 -2
  89. package/dist/document/applyNative.js +0 -28
  90. package/dist/src/document/applyNative.d.ts +0 -8
  91. package/dist/src/document/interceptor.d.ts +0 -5
  92. package/dist/src/pointer/pointerMove.d.ts +0 -5
  93. package/dist/src/pointer/pointerPress.d.ts +0 -7
  94. package/dist/src/tab.d.ts +0 -6
  95. package/dist/src/utils/misc/isDocument.d.ts +0 -1
  96. package/dist/src/utils/pointer/fakeEvent.d.ts +0 -16
  97. package/dist/tests/_helpers/custom-element.d.ts +0 -8
  98. package/dist/tests/_helpers/utils.d.ts +0 -73
  99. package/dist/tests/_setup-env.d.ts +0 -1
  100. package/dist/tests/clear.d.ts +0 -1
  101. package/dist/tests/click/click.d.ts +0 -1
  102. package/dist/tests/click/dblclick.d.ts +0 -1
  103. package/dist/tests/document/index.d.ts +0 -1
  104. package/dist/tests/document/selectionRange.d.ts +0 -1
  105. package/dist/tests/hover/hover.d.ts +0 -1
  106. package/dist/tests/hover/unhover.d.ts +0 -1
  107. package/dist/tests/keyboard/getNextKeyDef.d.ts +0 -1
  108. package/dist/tests/keyboard/index.d.ts +0 -1
  109. package/dist/tests/keyboard/keyboardImplementation.d.ts +0 -1
  110. package/dist/tests/keyboard/plugin/arrow.d.ts +0 -1
  111. package/dist/tests/keyboard/plugin/character.d.ts +0 -1
  112. package/dist/tests/keyboard/plugin/control.d.ts +0 -1
  113. package/dist/tests/keyboard/plugin/functional.d.ts +0 -1
  114. package/dist/tests/keyboard/shared/fireInputEvent.d.ts +0 -1
  115. package/dist/tests/paste.d.ts +0 -1
  116. package/dist/tests/pointer/index.d.ts +0 -1
  117. package/dist/tests/react/keyboard.d.ts +0 -1
  118. package/dist/tests/react/type.d.ts +0 -1
  119. package/dist/tests/selectOptions/deselect.d.ts +0 -1
  120. package/dist/tests/selectOptions/select.d.ts +0 -1
  121. package/dist/tests/setup.d.ts +0 -10
  122. package/dist/tests/tab.d.ts +0 -1
  123. package/dist/tests/type/index.d.ts +0 -1
  124. package/dist/tests/type/modifiers.d.ts +0 -1
  125. package/dist/tests/upload.d.ts +0 -1
  126. package/dist/tests/utils/edit/calculateNewValue.d.ts +0 -1
  127. package/dist/tests/utils/edit/isContentEditable.d.ts +0 -1
  128. package/dist/tests/utils/focus/blur.d.ts +0 -1
  129. package/dist/tests/utils/focus/focus.d.ts +0 -1
  130. package/dist/tests/utils/misc/hasPointerEvents.d.ts +0 -1
  131. package/dist/tests/utils/misc/isDescendantOrSelf.d.ts +0 -1
  132. package/dist/tests/utils/misc/isElementType.d.ts +0 -1
  133. package/dist/tests/utils/misc/isVisible.d.ts +0 -1
  134. package/dist/utils/misc/dom-helpers.d.ts +0 -3
  135. package/dist/utils/misc/isDocument.js +0 -10
File without changes
File without changes
@@ -5,6 +5,5 @@ declare global {
5
5
  }
6
6
  }
7
7
  export declare function prepareDocument(document: Document): void;
8
- export { applyNative } from './applyNative';
9
- export { getUIValue, setUIValue } from './value';
10
- export { getUISelection, hasUISelection, setUISelection } from './selection';
8
+ export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
9
+ export { getUISelection, setUISelection } from './selection';
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "applyNative", {
6
+ Object.defineProperty(exports, "endTrackValue", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _applyNative.applyNative;
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 realArgs = interceptorImpl.call(this, ...args);
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.constructor.prototype, propName, { ...prototypeDescriptor,
34
+ Object.defineProperty(element, propName, { ...(objectDescriptor != null ? objectDescriptor : prototypeDescriptor),
32
35
  [target]: intercept
33
36
  });
34
37
  }
@@ -14,5 +14,4 @@ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaE
14
14
  selectionEnd: number | null;
15
15
  };
16
16
  export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
17
- export declare function hasUISelection(element: HTMLInputElement | HTMLTextAreaElement): boolean;
18
17
  export {};
@@ -5,7 +5,6 @@ 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
 
@@ -13,17 +12,29 @@ var _interceptor = require("./interceptor");
13
12
 
14
13
  const UISelection = Symbol('Displayed selection in UI');
15
14
 
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
15
  function prepareSelectionInterceptor(element) {
26
- (0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', setSelectionInterceptor);
16
+ (0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(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 {
23
+ realArgs: [Number(start), end, direction]
24
+ };
25
+ });
26
+ (0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
27
+ this[UISelection] = undefined;
28
+ return {
29
+ realArgs: v
30
+ };
31
+ });
32
+ (0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
33
+ this[UISelection] = undefined;
34
+ return {
35
+ realArgs: v
36
+ };
37
+ });
27
38
  }
28
39
 
29
40
  function setUISelection(element, start, end) {
@@ -60,8 +71,4 @@ function getUISelection(element) {
60
71
 
61
72
  function clearUISelection(element) {
62
73
  element[UISelection] = undefined;
63
- }
64
-
65
- function hasUISelection(element) {
66
- return Boolean(element[UISelection]);
67
74
  }
@@ -1,9 +1,11 @@
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;
@@ -11,4 +13,6 @@ export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaEleme
11
13
  export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
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 {};
@@ -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 String(v);
34
+ return {
35
+ applyNative: !!isUI,
36
+ realArgs: String(v)
37
+ };
33
38
  }
34
39
 
35
40
  function prepareValueInterceptor(element) {
@@ -37,10 +42,10 @@ function prepareValueInterceptor(element) {
37
42
  }
38
43
 
39
44
  function setUIValue(element, value) {
40
- (0, _applyNative.applyNative)(element, 'value', {
45
+ element.value = {
41
46
  [UIValue]: UIValue,
42
47
  toString: () => value
43
- });
48
+ };
44
49
  }
45
50
 
46
51
  function getUIValue(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
@@ -79,6 +79,10 @@ const defaultKeyMap = [// alphanumeric keys
79
79
  key: 'OS',
80
80
  location: _types.DOM_KEY_LOCATION.RIGHT,
81
81
  keyCode: 91
82
+ }, {
83
+ code: 'Tab',
84
+ key: 'Tab',
85
+ keyCode: 9
82
86
  }, {
83
87
  code: 'CapsLock',
84
88
  key: 'CapsLock',
@@ -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.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");
@@ -65,6 +67,21 @@ const keydownBehavior = [{
65
67
  }
66
68
  });
67
69
  }
70
+ }, {
71
+ matches: keyDef => keyDef.key === 'Tab',
72
+ handle: (keyDef, element, options, state) => {
73
+ const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
74
+
75
+ if (dest === element.ownerDocument.body) {
76
+ (0, _utils.blur)(element);
77
+ } else {
78
+ (0, _utils.focus)(dest);
79
+
80
+ if ((0, _utils.isElementType)(dest, ['input', 'textarea'])) {
81
+ (0, _document.setUISelection)(dest, 0, dest.value.length);
82
+ }
83
+ }
84
+ }
68
85
  }];
69
86
  exports.keydownBehavior = keydownBehavior;
70
87
  const keypressBehavior = [{
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,10 +1,6 @@
1
- import { Coords } from '../utils';
2
1
  import { PointerMoveAction } from './pointerMove';
3
2
  import { PointerPressAction } from './pointerPress';
4
- import { inputDeviceState, pointerOptions } from './types';
5
- export declare type PointerActionTarget = {
6
- target?: Element;
7
- coords?: Partial<Coords>;
8
- };
3
+ import { inputDeviceState, pointerOptions, PointerTarget, SelectionTarget } from './types';
4
+ export declare type PointerActionTarget = Partial<PointerTarget> & Partial<SelectionTarget>;
9
5
  export declare type PointerAction = PointerActionTarget & (Omit<PointerPressAction, 'target' | 'coords'> | Omit<PointerMoveAction, 'target' | 'coords'>);
10
6
  export declare function pointerAction(actions: PointerAction[], options: pointerOptions, state: inputDeviceState): Promise<unknown[]>;
@@ -15,14 +15,12 @@ async function pointerAction(actions, options, state) {
15
15
  const ret = [];
16
16
 
17
17
  for (let i = 0; i < actions.length; i++) {
18
- var _action$target;
18
+ var _action$target, _action$coords;
19
19
 
20
20
  const action = actions[i];
21
21
  const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? action.keyDef.pointerType === 'touch' ? action.keyDef.name : action.keyDef.pointerType : 'mouse';
22
22
  const target = (_action$target = action.target) != null ? _action$target : getPrevTarget(pointerName, state.pointerState);
23
- const coords = completeCoords({ ...(pointerName in state.pointerState.position ? state.pointerState.position[pointerName].coords : undefined),
24
- ...action.coords
25
- });
23
+ const coords = (_action$coords = action.coords) != null ? _action$coords : pointerName in state.pointerState.position ? state.pointerState.position[pointerName].coords : undefined;
26
24
  const promise = 'keyDef' in action ? (0, _pointerPress.pointerPress)({ ...action,
27
25
  target,
28
26
  coords
@@ -51,26 +49,4 @@ function getPrevTarget(pointerName, state) {
51
49
  }
52
50
 
53
51
  return state.position[pointerName].target;
54
- }
55
-
56
- function completeCoords({
57
- x = 0,
58
- y = 0,
59
- clientX = x,
60
- clientY = y,
61
- offsetX = x,
62
- offsetY = y,
63
- pageX = clientX,
64
- pageY = clientY
65
- }) {
66
- return {
67
- x,
68
- y,
69
- clientX,
70
- clientY,
71
- offsetX,
72
- offsetY,
73
- pageX,
74
- pageY
75
- };
76
52
  }
@@ -0,0 +1,5 @@
1
+ import { inputDeviceState, PointerTarget, SelectionTarget } from './types';
2
+ export interface PointerMoveAction extends PointerTarget, SelectionTarget {
3
+ pointerName?: string;
4
+ }
5
+ export declare function pointerMove({ pointerName, target, coords, node, offset }: PointerMoveAction, { pointerState, keyboardState }: inputDeviceState): Promise<void>;
@@ -5,12 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.pointerMove = pointerMove;
7
7
 
8
+ var _document = require("../document");
9
+
8
10
  var _utils = require("../utils");
9
11
 
12
+ var _resolveSelectionTarget = require("./resolveSelectionTarget");
13
+
10
14
  async function pointerMove({
11
15
  pointerName = 'mouse',
12
16
  target,
13
- coords
17
+ coords,
18
+ node,
19
+ offset
14
20
  }, {
15
21
  pointerState,
16
22
  keyboardState
@@ -23,7 +29,8 @@ async function pointerMove({
23
29
  pointerId,
24
30
  pointerType,
25
31
  target: prevTarget,
26
- coords: prevCoords
32
+ coords: prevCoords,
33
+ selectionRange
27
34
  } = pointerState.position[pointerName];
28
35
 
29
36
  if (prevTarget && prevTarget !== target) {
@@ -35,9 +42,7 @@ async function pointerMove({
35
42
  }
36
43
  }
37
44
 
38
- pointerState.position[pointerName] = {
39
- pointerId,
40
- pointerType,
45
+ pointerState.position[pointerName] = { ...pointerState.position[pointerName],
41
46
  target,
42
47
  coords
43
48
  };
@@ -52,6 +57,34 @@ async function pointerMove({
52
57
 
53
58
  fireMove(target, coords);
54
59
 
60
+ if (selectionRange) {
61
+ const selectionFocus = (0, _resolveSelectionTarget.resolveSelectionTarget)({
62
+ target,
63
+ node,
64
+ offset
65
+ });
66
+
67
+ if ('node' in selectionRange && selectionFocus.node === selectionRange.node) {
68
+ (0, _document.setUISelection)(selectionRange.node, Math.min(selectionRange.start, selectionFocus.offset), Math.max(selectionRange.end, selectionFocus.offset));
69
+ } else
70
+ /* istanbul ignore else */
71
+ if ('setEnd' in selectionRange) {
72
+ const range = selectionRange.cloneRange();
73
+ const cmp = selectionRange.comparePoint(selectionFocus.node, selectionFocus.offset);
74
+
75
+ if (cmp < 0) {
76
+ range.setStart(selectionFocus.node, selectionFocus.offset);
77
+ } else if (cmp > 0) {
78
+ range.setEnd(selectionFocus.node, selectionFocus.offset);
79
+ } // TODO: support multiple ranges
80
+
81
+
82
+ const selection = target.ownerDocument.getSelection();
83
+ selection.removeAllRanges();
84
+ selection.addRange(range.cloneRange());
85
+ }
86
+ }
87
+
55
88
  function fireMove(eventTarget, eventCoords) {
56
89
  fire(eventTarget, 'pointermove', eventCoords);
57
90
 
@@ -0,0 +1,7 @@
1
+ import type { inputDeviceState, pointerKey, PointerTarget, SelectionTarget } from './types';
2
+ export interface PointerPressAction extends PointerTarget, SelectionTarget {
3
+ keyDef: pointerKey;
4
+ releasePrevious: boolean;
5
+ releaseSelf: boolean;
6
+ }
7
+ export declare function pointerPress(action: PointerPressAction, state: inputDeviceState): Promise<void>;