@testing-library/user-event 14.4.2 → 14.4.3

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 (209) hide show
  1. package/dist/cjs/clipboard/copy.js +4 -14
  2. package/dist/cjs/clipboard/cut.js +4 -14
  3. package/dist/cjs/clipboard/paste.js +2 -12
  4. package/dist/cjs/convenience/click.js +1 -4
  5. package/dist/cjs/convenience/hover.js +2 -12
  6. package/dist/cjs/document/{selection.js → UI.js} +43 -57
  7. package/dist/cjs/document/copySelection.js +37 -0
  8. package/dist/cjs/document/getValueOrTextContent.js +27 -0
  9. package/dist/cjs/document/index.js +13 -68
  10. package/dist/cjs/document/interceptor.js +83 -0
  11. package/dist/cjs/document/prepareDocument.js +67 -0
  12. package/dist/cjs/document/trackValue.js +65 -0
  13. package/dist/cjs/event/behavior/click.js +8 -12
  14. package/dist/cjs/event/behavior/cut.js +5 -11
  15. package/dist/cjs/event/behavior/keydown.js +39 -43
  16. package/dist/cjs/event/behavior/keypress.js +8 -9
  17. package/dist/cjs/event/behavior/keyup.js +5 -7
  18. package/dist/cjs/event/behavior/paste.js +5 -11
  19. package/dist/cjs/event/createEvent.js +2 -9
  20. package/dist/cjs/event/dispatchEvent.js +20 -2
  21. package/dist/cjs/event/focus.js +44 -0
  22. package/dist/cjs/event/index.js +24 -17
  23. package/dist/cjs/{utils/edit → event}/input.js +48 -46
  24. package/dist/cjs/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  25. package/dist/cjs/event/selection/getInputRange.js +20 -0
  26. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +40 -0
  27. package/dist/cjs/event/selection/index.js +26 -0
  28. package/dist/cjs/event/selection/modifySelection.js +30 -0
  29. package/dist/cjs/event/selection/modifySelectionPerMouse.js +49 -0
  30. package/dist/cjs/event/selection/moveSelection.js +47 -0
  31. package/dist/cjs/{utils/focus → event/selection}/resolveCaretPosition.js +9 -17
  32. package/dist/cjs/event/selection/selectAll.js +47 -0
  33. package/dist/cjs/event/selection/setSelection.js +30 -0
  34. package/dist/cjs/event/selection/setSelectionPerMouse.js +90 -0
  35. package/dist/cjs/event/selection/setSelectionRange.js +40 -0
  36. package/dist/cjs/event/selection/updateSelectionOnFocus.js +45 -0
  37. package/dist/cjs/keyboard/index.js +13 -23
  38. package/dist/cjs/keyboard/parseKeyDef.js +1 -9
  39. package/dist/cjs/options.js +0 -28
  40. package/dist/cjs/pointer/index.js +20 -30
  41. package/dist/cjs/pointer/parseKeyDef.js +1 -9
  42. package/dist/cjs/setup/directApi.js +6 -6
  43. package/dist/cjs/setup/index.js +0 -2
  44. package/dist/cjs/setup/setup.js +65 -37
  45. package/dist/cjs/system/keyboard.js +7 -9
  46. package/dist/cjs/system/pointer/index.js +16 -21
  47. package/dist/cjs/system/pointer/mouse.js +45 -38
  48. package/dist/cjs/system/pointer/pointer.js +33 -35
  49. package/dist/cjs/system/pointer/shared.js +10 -0
  50. package/dist/cjs/utility/clear.js +10 -11
  51. package/dist/cjs/utility/selectOptions.js +17 -19
  52. package/dist/cjs/utility/type.js +6 -15
  53. package/dist/cjs/utility/upload.js +3 -13
  54. package/dist/cjs/utils/dataTransfer/Clipboard.js +1 -15
  55. package/dist/cjs/utils/edit/isEditable.js +6 -10
  56. package/dist/cjs/utils/edit/maxLength.js +4 -15
  57. package/dist/cjs/utils/edit/{buildTimeValue.js → timeValue.js} +6 -0
  58. package/dist/cjs/utils/focus/cursor.js +0 -16
  59. package/dist/cjs/utils/focus/selection.js +1 -271
  60. package/dist/cjs/utils/index.js +7 -32
  61. package/dist/cjs/utils/misc/level.js +4 -9
  62. package/dist/cjs/utils/pointer/cssPointerEvents.js +9 -22
  63. package/dist/esm/clipboard/copy.js +4 -14
  64. package/dist/esm/clipboard/cut.js +4 -14
  65. package/dist/esm/clipboard/paste.js +2 -12
  66. package/dist/esm/convenience/click.js +1 -4
  67. package/dist/esm/convenience/hover.js +2 -12
  68. package/dist/esm/document/{selection.js → UI.js} +35 -56
  69. package/dist/esm/document/copySelection.js +33 -0
  70. package/dist/esm/document/getValueOrTextContent.js +23 -0
  71. package/dist/esm/document/index.js +4 -66
  72. package/dist/esm/document/interceptor.js +81 -1
  73. package/dist/esm/document/prepareDocument.js +63 -0
  74. package/dist/esm/document/{value.js → trackValue.js} +3 -61
  75. package/dist/esm/event/behavior/click.js +8 -12
  76. package/dist/esm/event/behavior/cut.js +5 -11
  77. package/dist/esm/event/behavior/keydown.js +32 -36
  78. package/dist/esm/event/behavior/keypress.js +8 -9
  79. package/dist/esm/event/behavior/keyup.js +5 -7
  80. package/dist/esm/event/behavior/paste.js +5 -11
  81. package/dist/esm/event/createEvent.js +2 -9
  82. package/dist/esm/event/dispatchEvent.js +19 -3
  83. package/dist/esm/event/focus.js +39 -0
  84. package/dist/esm/event/index.js +14 -19
  85. package/dist/esm/{utils/edit → event}/input.js +35 -33
  86. package/dist/esm/{utils/edit/walkRadio.js → event/radio.js} +13 -7
  87. package/dist/esm/event/selection/getInputRange.js +16 -0
  88. package/dist/esm/event/selection/getTargetTypeAndSelection.js +36 -0
  89. package/dist/esm/event/selection/index.js +9 -0
  90. package/dist/esm/event/selection/modifySelection.js +26 -0
  91. package/dist/esm/event/selection/modifySelectionPerMouse.js +45 -0
  92. package/dist/esm/event/selection/moveSelection.js +43 -0
  93. package/dist/esm/{utils/focus → event/selection}/resolveCaretPosition.js +8 -16
  94. package/dist/esm/{utils/focus → event/selection}/selectAll.js +12 -21
  95. package/dist/esm/event/selection/setSelection.js +26 -0
  96. package/dist/esm/event/selection/setSelectionPerMouse.js +86 -0
  97. package/dist/esm/event/selection/setSelectionRange.js +36 -0
  98. package/dist/esm/event/selection/updateSelectionOnFocus.js +41 -0
  99. package/dist/esm/keyboard/index.js +13 -23
  100. package/dist/esm/keyboard/parseKeyDef.js +1 -9
  101. package/dist/esm/options.js +1 -26
  102. package/dist/esm/pointer/index.js +20 -30
  103. package/dist/esm/pointer/parseKeyDef.js +1 -9
  104. package/dist/esm/setup/directApi.js +6 -6
  105. package/dist/esm/setup/index.js +0 -1
  106. package/dist/esm/setup/setup.js +59 -32
  107. package/dist/esm/system/keyboard.js +7 -9
  108. package/dist/esm/system/pointer/index.js +17 -21
  109. package/dist/esm/system/pointer/mouse.js +42 -35
  110. package/dist/esm/system/pointer/pointer.js +32 -34
  111. package/dist/esm/system/pointer/shared.js +6 -0
  112. package/dist/esm/utility/clear.js +10 -11
  113. package/dist/esm/utility/selectOptions.js +17 -19
  114. package/dist/esm/utility/type.js +5 -14
  115. package/dist/esm/utility/upload.js +3 -13
  116. package/dist/esm/utils/dataTransfer/Clipboard.js +1 -15
  117. package/dist/esm/utils/edit/isEditable.js +4 -8
  118. package/dist/esm/utils/edit/maxLength.js +3 -15
  119. package/dist/esm/utils/edit/{buildTimeValue.js → timeValue.js} +6 -1
  120. package/dist/esm/utils/focus/cursor.js +0 -16
  121. package/dist/esm/utils/focus/selection.js +3 -265
  122. package/dist/esm/utils/index.js +4 -11
  123. package/dist/esm/utils/misc/level.js +4 -9
  124. package/dist/esm/utils/pointer/cssPointerEvents.js +9 -22
  125. package/dist/types/clipboard/copy.d.ts +1 -1
  126. package/dist/types/clipboard/cut.d.ts +1 -1
  127. package/dist/types/clipboard/paste.d.ts +1 -1
  128. package/dist/types/convenience/click.d.ts +1 -1
  129. package/dist/types/convenience/hover.d.ts +1 -1
  130. package/dist/types/document/UI.d.ts +42 -0
  131. package/dist/types/{utils/focus → document}/copySelection.d.ts +0 -0
  132. package/dist/types/document/getValueOrTextContent.d.ts +1 -0
  133. package/dist/types/document/index.d.ts +5 -10
  134. package/dist/types/document/interceptor.d.ts +3 -0
  135. package/dist/types/document/prepareDocument.d.ts +8 -0
  136. package/dist/types/document/trackValue.d.ts +17 -0
  137. package/dist/types/event/behavior/registry.d.ts +2 -2
  138. package/dist/types/event/dispatchEvent.d.ts +5 -2
  139. package/dist/types/event/focus.d.ts +5 -0
  140. package/dist/types/event/index.d.ts +6 -4
  141. package/dist/types/event/input.d.ts +2 -0
  142. package/dist/types/event/radio.d.ts +4 -0
  143. package/dist/types/event/selection/getInputRange.d.ts +5 -0
  144. package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
  145. package/dist/types/event/selection/index.d.ts +15 -0
  146. package/dist/types/event/selection/modifySelection.d.ts +8 -0
  147. package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
  148. package/dist/types/event/selection/moveSelection.d.ts +4 -0
  149. package/dist/types/{utils/focus → event/selection}/resolveCaretPosition.d.ts +0 -0
  150. package/dist/types/{utils/focus → event/selection}/selectAll.d.ts +0 -0
  151. package/dist/types/event/selection/setSelection.d.ts +10 -0
  152. package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
  153. package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
  154. package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
  155. package/dist/types/keyboard/index.d.ts +2 -2
  156. package/dist/types/options.d.ts +0 -8
  157. package/dist/types/pointer/index.d.ts +3 -3
  158. package/dist/types/setup/directApi.d.ts +1 -1
  159. package/dist/types/setup/index.d.ts +2 -15
  160. package/dist/types/setup/setup.d.ts +25 -7
  161. package/dist/types/system/keyboard.d.ts +3 -3
  162. package/dist/types/system/pointer/buttons.d.ts +1 -1
  163. package/dist/types/system/pointer/index.d.ts +7 -25
  164. package/dist/types/system/pointer/mouse.d.ts +5 -5
  165. package/dist/types/system/pointer/pointer.d.ts +7 -7
  166. package/dist/types/system/pointer/shared.d.ts +20 -0
  167. package/dist/types/utility/clear.d.ts +1 -1
  168. package/dist/types/utility/selectOptions.d.ts +1 -1
  169. package/dist/types/utility/type.d.ts +3 -3
  170. package/dist/types/utility/upload.d.ts +1 -1
  171. package/dist/types/utils/click/isClickableInput.d.ts +2 -2
  172. package/dist/types/utils/edit/isEditable.d.ts +5 -6
  173. package/dist/types/utils/edit/maxLength.d.ts +14 -1
  174. package/dist/types/utils/edit/{isValidDateOrTimeValue.d.ts → timeValue.d.ts} +1 -0
  175. package/dist/types/utils/focus/selection.d.ts +4 -69
  176. package/dist/types/utils/index.d.ts +2 -9
  177. package/dist/types/utils/misc/level.d.ts +4 -13
  178. package/dist/types/utils/misc/wait.d.ts +2 -2
  179. package/dist/types/utils/pointer/cssPointerEvents.d.ts +4 -4
  180. package/package.json +3 -2
  181. package/dist/cjs/document/setRangeText.js +0 -21
  182. package/dist/cjs/document/value.js +0 -127
  183. package/dist/cjs/setup/config.js +0 -7
  184. package/dist/cjs/utils/edit/getValue.js +0 -35
  185. package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +0 -11
  186. package/dist/cjs/utils/focus/blur.js +0 -16
  187. package/dist/cjs/utils/focus/copySelection.js +0 -46
  188. package/dist/cjs/utils/focus/focus.js +0 -29
  189. package/dist/cjs/utils/focus/selectAll.js +0 -56
  190. package/dist/cjs/utils/misc/eventWrapper.js +0 -15
  191. package/dist/esm/document/setRangeText.js +0 -17
  192. package/dist/esm/setup/config.js +0 -3
  193. package/dist/esm/utils/edit/getValue.js +0 -31
  194. package/dist/esm/utils/edit/isValidDateOrTimeValue.js +0 -7
  195. package/dist/esm/utils/focus/blur.js +0 -12
  196. package/dist/esm/utils/focus/copySelection.js +0 -42
  197. package/dist/esm/utils/focus/focus.js +0 -25
  198. package/dist/esm/utils/misc/eventWrapper.js +0 -11
  199. package/dist/types/document/selection.d.ts +0 -29
  200. package/dist/types/document/setRangeText.d.ts +0 -1
  201. package/dist/types/document/value.d.ts +0 -26
  202. package/dist/types/setup/config.d.ts +0 -6
  203. package/dist/types/utils/edit/buildTimeValue.d.ts +0 -1
  204. package/dist/types/utils/edit/getValue.d.ts +0 -1
  205. package/dist/types/utils/edit/input.d.ts +0 -2
  206. package/dist/types/utils/edit/walkRadio.d.ts +0 -4
  207. package/dist/types/utils/focus/blur.d.ts +0 -2
  208. package/dist/types/utils/focus/focus.d.ts +0 -5
  209. package/dist/types/utils/misc/eventWrapper.d.ts +0 -1
@@ -1,29 +1,50 @@
1
- import { prepareDocument } from '../document/index.js';
2
- import { bindDispatchUIEvent } from '../event/index.js';
3
- import { defaultOptionsSetup, defaultOptionsDirect } from '../options.js';
1
+ import { prepareDocument } from '../document/prepareDocument.js';
2
+ import { dispatchEvent, dispatchUIEvent } from '../event/dispatchEvent.js';
4
3
  import '../utils/click/isClickableInput.js';
5
4
  import { attachClipboardStubToView } from '../utils/dataTransfer/Clipboard.js';
6
- import '../utils/edit/maxLength.js';
7
5
  import '../utils/edit/isEditable.js';
8
- import '@testing-library/dom';
6
+ import '../utils/edit/maxLength.js';
9
7
  import '@testing-library/dom/dist/helpers.js';
10
8
  import '../utils/keyDef/readNextDescriptor.js';
11
9
  import { getDocumentFromNode } from '../utils/misc/getDocumentFromNode.js';
12
10
  import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
13
11
  import { wait } from '../utils/misc/wait.js';
12
+ import { PointerEventsCheckLevel } from '../options.js';
13
+ import '@testing-library/dom';
14
+ import { defaultKeyMap } from '../keyboard/keyMap.js';
15
+ import { defaultKeyMap as defaultKeyMap$1 } from '../pointer/keyMap.js';
14
16
  import { System } from '../system/index.js';
15
- import { Config } from './config.js';
16
17
  import * as api from './api.js';
17
18
  import { wrapAsync } from './wrapAsync.js';
18
19
 
20
+ /**
21
+ * Default options applied when API is called per `userEvent.anyApi()`
22
+ */ const defaultOptionsDirect = {
23
+ applyAccept: true,
24
+ autoModify: true,
25
+ delay: 0,
26
+ document: globalThis.document,
27
+ keyboardMap: defaultKeyMap,
28
+ pointerMap: defaultKeyMap$1,
29
+ pointerEventsCheck: PointerEventsCheckLevel.EachApiCall,
30
+ skipAutoClose: false,
31
+ skipClick: false,
32
+ skipHover: false,
33
+ writeToClipboard: false,
34
+ advanceTimers: ()=>Promise.resolve()
35
+ };
36
+ /**
37
+ * Default options applied when API is called per `userEvent().anyApi()`
38
+ */ const defaultOptionsSetup = {
39
+ ...defaultOptionsDirect,
40
+ writeToClipboard: true
41
+ };
19
42
  function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
20
43
  const document = getDocument(options, node, defaults);
21
- var _system;
22
44
  return {
23
45
  ...defaults,
24
46
  ...options,
25
- document,
26
- system: (_system = options.system) !== null && _system !== void 0 ? _system : new System()
47
+ document
27
48
  };
28
49
  }
29
50
  /**
@@ -35,34 +56,33 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
35
56
  var _defaultView;
36
57
  const view = (_defaultView = config.document.defaultView) !== null && _defaultView !== void 0 ? _defaultView : /* istanbul ignore next */ globalThis.window;
37
58
  attachClipboardStubToView(view);
38
- return doSetup(config);
59
+ return createInstance(config).api;
39
60
  }
40
61
  /**
41
62
  * Setup in direct call per `userEvent.anyApi()`
42
63
  */ function setupDirect({ keyboardState , pointerState , ...options } = {}, node) {
43
- const config = createConfig({
44
- ...options,
45
- system: pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState
46
- }, defaultOptionsDirect, node);
64
+ const config = createConfig(options, defaultOptionsDirect, node);
47
65
  prepareDocument(config.document);
66
+ var ref;
67
+ const system = (ref = pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState) !== null && ref !== void 0 ? ref : new System();
48
68
  return {
49
- config,
50
- api: doSetup(config)
69
+ api: createInstance(config, system).api,
70
+ system
51
71
  };
52
72
  }
53
73
  /**
54
74
  * Create a set of callbacks with different default settings but the same state.
55
75
  */ function setupSub(options) {
56
- return doSetup({
57
- ...this[Config],
76
+ return createInstance({
77
+ ...this.config,
58
78
  ...options
59
- });
79
+ }, this.system).api;
60
80
  }
61
81
  function wrapAndBindImpl(instance, impl) {
62
82
  function method(...args) {
63
- setLevelRef(instance[Config], ApiLevel.Call);
83
+ setLevelRef(instance, ApiLevel.Call);
64
84
  return wrapAsync(()=>impl.apply(instance, args).then(async (ret)=>{
65
- await wait(instance[Config]);
85
+ await wait(instance.config);
66
86
  return ret;
67
87
  }));
68
88
  }
@@ -71,18 +91,25 @@ function wrapAndBindImpl(instance, impl) {
71
91
  });
72
92
  return method;
73
93
  }
74
- function doSetup(config) {
75
- const instance = {
76
- [Config]: config,
77
- dispatchUIEvent: bindDispatchUIEvent(config),
94
+ function createInstance(config, system = new System()) {
95
+ const instance = {};
96
+ Object.assign(instance, {
97
+ config,
98
+ dispatchEvent: dispatchEvent.bind(instance),
99
+ dispatchUIEvent: dispatchUIEvent.bind(instance),
100
+ system,
101
+ levelRefs: {},
78
102
  ...api
79
- };
103
+ });
80
104
  return {
81
- ...Object.fromEntries(Object.entries(api).map(([name, api])=>[
82
- name,
83
- wrapAndBindImpl(instance, api),
84
- ])),
85
- setup: setupSub.bind(instance)
105
+ instance,
106
+ api: {
107
+ ...Object.fromEntries(Object.entries(api).map(([name, api])=>[
108
+ name,
109
+ wrapAndBindImpl(instance, api),
110
+ ])),
111
+ setup: setupSub.bind(instance)
112
+ }
86
113
  };
87
114
  }
88
115
  function getDocument(options, node, defaults) {
@@ -90,4 +117,4 @@ function getDocument(options, node, defaults) {
90
117
  return (ref = (_document = options.document) !== null && _document !== void 0 ? _document : node && getDocumentFromNode(node)) !== null && ref !== void 0 ? ref : defaults.document;
91
118
  }
92
119
 
93
- export { createConfig, setupDirect, setupMain, setupSub };
120
+ export { createConfig, createInstance, setupDirect, setupMain, setupSub };
@@ -1,9 +1,7 @@
1
- import { dispatchUIEvent } from '../event/index.js';
2
1
  import '../utils/click/isClickableInput.js';
3
2
  import '../utils/dataTransfer/Clipboard.js';
4
- import '../utils/edit/maxLength.js';
5
3
  import '../utils/edit/isEditable.js';
6
- import '@testing-library/dom';
4
+ import '../utils/edit/maxLength.js';
7
5
  import { getActiveElementOrBody } from '../utils/focus/getActiveElement.js';
8
6
  import '@testing-library/dom/dist/helpers.js';
9
7
  import '../utils/keyDef/readNextDescriptor.js';
@@ -47,10 +45,10 @@ class KeyboardHost {
47
45
  getPressedKeys() {
48
46
  return Object.values(this.pressed).map((p)=>p.keyDef);
49
47
  }
50
- /** Press a key */ async keydown(config, keyDef) {
48
+ /** Press a key */ async keydown(instance, keyDef) {
51
49
  const key = String(keyDef.key);
52
50
  const code = String(keyDef.code);
53
- const target = getActiveElementOrBody(config.document);
51
+ const target = getActiveElementOrBody(instance.config.document);
54
52
  this.setKeydownTarget(target);
55
53
  var ref;
56
54
  (ref = (_pressed = this.pressed)[_code = code]) !== null && ref !== void 0 ? ref : _pressed[_code] = {
@@ -60,7 +58,7 @@ class KeyboardHost {
60
58
  if (isModifierKey(key)) {
61
59
  this.modifiers[key] = true;
62
60
  }
63
- const unprevented = dispatchUIEvent(config, target, 'keydown', {
61
+ const unprevented = instance.dispatchUIEvent(target, 'keydown', {
64
62
  key,
65
63
  code
66
64
  });
@@ -70,14 +68,14 @@ class KeyboardHost {
70
68
  }
71
69
  (_code1 = this.pressed[code]).unpreventedDefault || (_code1.unpreventedDefault = unprevented);
72
70
  if (unprevented && this.hasKeyPress(key)) {
73
- dispatchUIEvent(config, getActiveElementOrBody(config.document), 'keypress', {
71
+ instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keypress', {
74
72
  key,
75
73
  code,
76
74
  charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
77
75
  });
78
76
  }
79
77
  }
80
- /** Release a key */ async keyup(config, keyDef) {
78
+ /** Release a key */ async keyup(instance, keyDef) {
81
79
  const key = String(keyDef.key);
82
80
  const code = String(keyDef.code);
83
81
  const unprevented = this.pressed[code].unpreventedDefault;
@@ -86,7 +84,7 @@ class KeyboardHost {
86
84
  if (isModifierKey(key) && !Object.values(this.pressed).find((p)=>p.keyDef.key === key)) {
87
85
  this.modifiers[key] = false;
88
86
  }
89
- dispatchUIEvent(config, getActiveElementOrBody(config.document), 'keyup', {
87
+ instance.dispatchUIEvent(getActiveElementOrBody(instance.config.document), 'keyup', {
90
88
  key,
91
89
  code
92
90
  }, !unprevented);
@@ -8,9 +8,9 @@ class PointerHost {
8
8
  isKeyPressed(keyDef) {
9
9
  return this.devices.get(keyDef.pointerType).isPressed(keyDef);
10
10
  }
11
- async press(config, keyDef, position) {
11
+ async press(instance, keyDef, position) {
12
12
  const pointerName = this.getPointerName(keyDef);
13
- const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(config, position) : this.pointers.get(pointerName);
13
+ const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(instance, position) : this.pointers.get(pointerName);
14
14
  // TODO: deprecate the following implicit setting of position
15
15
  pointer.position = position;
16
16
  if (pointer.pointerType !== 'touch') {
@@ -18,19 +18,19 @@ class PointerHost {
18
18
  }
19
19
  this.devices.get(keyDef.pointerType).addPressed(keyDef);
20
20
  this.buttons.down(keyDef);
21
- pointer.down(config, keyDef);
21
+ pointer.down(instance, keyDef);
22
22
  if (pointer.pointerType !== 'touch' && !pointer.isPrevented) {
23
- this.mouse.down(config, keyDef, pointer);
23
+ this.mouse.down(instance, keyDef, pointer);
24
24
  }
25
25
  }
26
- async move(config, pointerName, position) {
26
+ async move(instance, pointerName, position) {
27
27
  const pointer = this.pointers.get(pointerName);
28
28
  // In (some?) browsers this order of events can be observed.
29
29
  // This interweaving of events is probably unnecessary.
30
30
  // While the order of mouse (or pointer) events is defined per spec,
31
31
  // the order in which they interweave/follow on a user interaction depends on the implementation.
32
- const pointermove = pointer.move(config, position);
33
- const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(config, position);
32
+ const pointermove = pointer.move(instance, position);
33
+ const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(instance, position);
34
34
  pointermove === null || pointermove === void 0 ? void 0 : pointermove.leave();
35
35
  mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
36
36
  pointermove === null || pointermove === void 0 ? void 0 : pointermove.enter();
@@ -38,7 +38,7 @@ class PointerHost {
38
38
  pointermove === null || pointermove === void 0 ? void 0 : pointermove.move();
39
39
  mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
40
40
  }
41
- async release(config, keyDef, position) {
41
+ async release(instance, keyDef, position) {
42
42
  const device = this.devices.get(keyDef.pointerType);
43
43
  device.removePressed(keyDef);
44
44
  this.buttons.up(keyDef);
@@ -49,25 +49,25 @@ class PointerHost {
49
49
  this.mouse.position = position;
50
50
  }
51
51
  if (device.countPressed === 0) {
52
- pointer.up(config, keyDef);
52
+ pointer.up(instance, keyDef);
53
53
  }
54
54
  if (pointer.pointerType === 'touch') {
55
- pointer.release(config);
55
+ pointer.release(instance);
56
56
  }
57
57
  if (!pointer.isPrevented) {
58
58
  if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
59
- const mousemove = this.mouse.move(config, pointer.position);
59
+ const mousemove = this.mouse.move(instance, pointer.position);
60
60
  mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
61
61
  mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
62
62
  mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
63
- this.mouse.down(config, keyDef, pointer);
63
+ this.mouse.down(instance, keyDef, pointer);
64
64
  }
65
65
  if (!pointer.isMultitouch) {
66
- const mousemove1 = this.mouse.move(config, pointer.position);
66
+ const mousemove1 = this.mouse.move(instance, pointer.position);
67
67
  mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.leave();
68
68
  mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.enter();
69
69
  mousemove1 === null || mousemove1 === void 0 ? void 0 : mousemove1.move();
70
- this.mouse.up(config, keyDef, pointer);
70
+ this.mouse.up(instance, keyDef, pointer);
71
71
  }
72
72
  }
73
73
  }
@@ -80,9 +80,9 @@ class PointerHost {
80
80
  resetClickCount() {
81
81
  this.mouse.resetClickCount();
82
82
  }
83
- getMouseTarget(config) {
83
+ getMouseTarget(instance) {
84
84
  var _target;
85
- return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : config.document.body;
85
+ return (_target = this.mouse.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body;
86
86
  }
87
87
  setMousePosition(position) {
88
88
  this.mouse.position = position;
@@ -141,9 +141,5 @@ class PointerHost {
141
141
  this.mouse = new Mouse();
142
142
  }
143
143
  }
144
- function isDifferentPointerPosition(positionA, positionB) {
145
- var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
146
- return positionA.target !== positionB.target || ((ref = positionA.coords) === null || ref === void 0 ? void 0 : ref.x) !== ((ref1 = positionB.coords) === null || ref1 === void 0 ? void 0 : ref1.y) || ((ref2 = positionA.coords) === null || ref2 === void 0 ? void 0 : ref2.y) !== ((ref3 = positionB.coords) === null || ref3 === void 0 ? void 0 : ref3.y) || ((ref4 = positionA.caret) === null || ref4 === void 0 ? void 0 : ref4.node) !== ((ref5 = positionB.caret) === null || ref5 === void 0 ? void 0 : ref5.node) || ((ref6 = positionA.caret) === null || ref6 === void 0 ? void 0 : ref6.offset) !== ((ref7 = positionB.caret) === null || ref7 === void 0 ? void 0 : ref7.offset);
147
- }
148
144
 
149
- export { PointerHost, isDifferentPointerPosition };
145
+ export { PointerHost };
@@ -1,85 +1,92 @@
1
- import { dispatchUIEvent } from '../../event/index.js';
1
+ import '../../event/behavior/click.js';
2
+ import '../../event/behavior/cut.js';
3
+ import '../../event/behavior/keydown.js';
4
+ import '../../event/behavior/keypress.js';
5
+ import '../../event/behavior/keyup.js';
6
+ import '../../event/behavior/paste.js';
7
+ import '@testing-library/dom';
8
+ import '../../event/eventMap.js';
2
9
  import '../../utils/click/isClickableInput.js';
3
10
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/maxLength.js';
5
11
  import '../../utils/edit/isEditable.js';
6
- import { focus } from '../../utils/focus/focus.js';
7
- import '@testing-library/dom/dist/helpers.js';
12
+ import '../../utils/edit/maxLength.js';
8
13
  import { isDisabled } from '../../utils/misc/isDisabled.js';
9
- import '@testing-library/dom';
10
- import { setSelectionPerMouseDown, modifySelectionPerMouseMove } from '../../utils/focus/selection.js';
14
+ import '@testing-library/dom/dist/helpers.js';
11
15
  import '../../utils/keyDef/readNextDescriptor.js';
12
16
  import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
13
17
  import '../../utils/misc/level.js';
14
18
  import '../../options.js';
15
- import { isDifferentPointerPosition } from './index.js';
19
+ import { focusElement } from '../../event/focus.js';
20
+ import { setSelectionPerMouseDown } from '../../event/selection/setSelectionPerMouse.js';
21
+ import { modifySelectionPerMouseMove } from '../../event/selection/modifySelectionPerMouse.js';
16
22
  import { getMouseEventButton, Buttons } from './buttons.js';
23
+ import { isDifferentPointerPosition } from './shared.js';
17
24
 
18
25
  /**
19
26
  * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
20
27
  */ class Mouse {
21
- move(config, position) {
28
+ move(instance, position) {
22
29
  const prevPosition = this.position;
23
- const prevTarget = this.getTarget(config);
30
+ const prevTarget = this.getTarget(instance);
24
31
  this.position = position;
25
32
  if (!isDifferentPointerPosition(prevPosition, position)) {
26
33
  return;
27
34
  }
28
- const nextTarget = this.getTarget(config);
35
+ const nextTarget = this.getTarget(instance);
29
36
  const init = this.getEventInit('mousemove');
30
37
  const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
31
38
  return {
32
39
  leave: ()=>{
33
40
  if (prevTarget !== nextTarget) {
34
- dispatchUIEvent(config, prevTarget, 'mouseout', init);
35
- leave.forEach((el)=>dispatchUIEvent(config, el, 'mouseleave', init));
41
+ instance.dispatchUIEvent(prevTarget, 'mouseout', init);
42
+ leave.forEach((el)=>instance.dispatchUIEvent(el, 'mouseleave', init));
36
43
  }
37
44
  },
38
45
  enter: ()=>{
39
46
  if (prevTarget !== nextTarget) {
40
- dispatchUIEvent(config, nextTarget, 'mouseover', init);
41
- enter.forEach((el)=>dispatchUIEvent(config, el, 'mouseenter', init));
47
+ instance.dispatchUIEvent(nextTarget, 'mouseover', init);
48
+ enter.forEach((el)=>instance.dispatchUIEvent(el, 'mouseenter', init));
42
49
  }
43
50
  },
44
51
  move: ()=>{
45
- dispatchUIEvent(config, nextTarget, 'mousemove', init);
46
- this.modifySelecting(config);
52
+ instance.dispatchUIEvent(nextTarget, 'mousemove', init);
53
+ this.modifySelecting(instance);
47
54
  }
48
55
  };
49
56
  }
50
- down(config, keyDef, pointer) {
57
+ down(instance, keyDef, pointer) {
51
58
  const button = this.buttons.down(keyDef);
52
59
  if (button === undefined) {
53
60
  return;
54
61
  }
55
- const target = this.getTarget(config);
62
+ const target = this.getTarget(instance);
56
63
  this.buttonDownTarget[button] = target;
57
64
  const disabled = isDisabled(target);
58
65
  const init = this.getEventInit('mousedown', keyDef.button);
59
- if (disabled || dispatchUIEvent(config, target, 'mousedown', init)) {
60
- this.startSelecting(config, init.detail);
61
- focus(target);
66
+ if (disabled || instance.dispatchUIEvent(target, 'mousedown', init)) {
67
+ this.startSelecting(instance, init.detail);
68
+ focusElement(target);
62
69
  }
63
70
  if (!disabled && getMouseEventButton(keyDef.button) === 2) {
64
- dispatchUIEvent(config, target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer));
71
+ instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer));
65
72
  }
66
73
  }
67
- up(config, keyDef, pointer) {
74
+ up(instance, keyDef, pointer) {
68
75
  const button = this.buttons.up(keyDef);
69
76
  if (button === undefined) {
70
77
  return;
71
78
  }
72
- const target = this.getTarget(config);
79
+ const target = this.getTarget(instance);
73
80
  if (!isDisabled(target)) {
74
- dispatchUIEvent(config, target, 'mouseup', this.getEventInit('mouseup', keyDef.button));
81
+ instance.dispatchUIEvent(target, 'mouseup', this.getEventInit('mouseup', keyDef.button));
75
82
  this.endSelecting();
76
83
  const clickTarget = getTreeDiff(this.buttonDownTarget[button], target)[2][0];
77
84
  if (clickTarget) {
78
85
  const init = this.getEventInit('click', keyDef.button, pointer);
79
86
  if (init.detail) {
80
- dispatchUIEvent(config, clickTarget, init.button === 0 ? 'click' : 'auxclick', init);
87
+ instance.dispatchUIEvent(clickTarget, init.button === 0 ? 'click' : 'auxclick', init);
81
88
  if (init.button === 0 && init.detail === 2) {
82
- dispatchUIEvent(config, clickTarget, 'dblclick', {
89
+ instance.dispatchUIEvent(clickTarget, 'dblclick', {
83
90
  ...this.getEventInit('dblclick', keyDef.button),
84
91
  detail: init.detail
85
92
  });
@@ -111,29 +118,29 @@ import { getMouseEventButton, Buttons } from './buttons.js';
111
118
  }
112
119
  return init;
113
120
  }
114
- getTarget(config) {
121
+ getTarget(instance) {
115
122
  var _target;
116
- return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
123
+ return (_target = this.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body;
117
124
  }
118
- startSelecting(config, clickCount) {
125
+ startSelecting(instance, clickCount) {
119
126
  var ref, ref1;
120
127
  // TODO: support extending range (shift)
121
128
  this.selecting = setSelectionPerMouseDown({
122
- document: config.document,
123
- target: this.getTarget(config),
129
+ document: instance.config.document,
130
+ target: this.getTarget(instance),
124
131
  node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
125
132
  offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset,
126
133
  clickCount
127
134
  });
128
135
  }
129
- modifySelecting(config) {
136
+ modifySelecting(instance) {
130
137
  var ref, ref1;
131
138
  if (!this.selecting) {
132
139
  return;
133
140
  }
134
141
  modifySelectionPerMouseMove(this.selecting, {
135
- document: config.document,
136
- target: this.getTarget(config),
142
+ document: instance.config.document,
143
+ target: this.getTarget(instance),
137
144
  node: (ref = this.position.caret) === null || ref === void 0 ? void 0 : ref.node,
138
145
  offset: (ref1 = this.position.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
139
146
  });
@@ -1,91 +1,89 @@
1
- import { dispatchUIEvent } from '../../event/index.js';
2
1
  import '../../utils/click/isClickableInput.js';
3
2
  import '../../utils/dataTransfer/Clipboard.js';
4
- import '../../utils/edit/maxLength.js';
5
3
  import '../../utils/edit/isEditable.js';
6
- import '@testing-library/dom';
4
+ import '../../utils/edit/maxLength.js';
7
5
  import '@testing-library/dom/dist/helpers.js';
8
6
  import '../../utils/keyDef/readNextDescriptor.js';
9
7
  import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
10
8
  import '../../utils/misc/level.js';
11
9
  import { assertPointerEvents, hasPointerEvents } from '../../utils/pointer/cssPointerEvents.js';
12
- import { isDifferentPointerPosition } from './index.js';
10
+ import { isDifferentPointerPosition } from './shared.js';
13
11
 
14
12
  class Pointer {
15
- init(config, position) {
13
+ init(instance, position) {
16
14
  this.position = position;
17
- const target = this.getTarget(config);
15
+ const target = this.getTarget(instance);
18
16
  const [, enter] = getTreeDiff(null, target);
19
17
  const init = this.getEventInit();
20
- assertPointerEvents(config, target);
21
- dispatchUIEvent(config, target, 'pointerover', init);
22
- enter.forEach((el)=>dispatchUIEvent(config, el, 'pointerenter', init));
18
+ assertPointerEvents(instance, target);
19
+ instance.dispatchUIEvent(target, 'pointerover', init);
20
+ enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init));
23
21
  return this;
24
22
  }
25
- move(config, position) {
23
+ move(instance, position) {
26
24
  const prevPosition = this.position;
27
- const prevTarget = this.getTarget(config);
25
+ const prevTarget = this.getTarget(instance);
28
26
  this.position = position;
29
27
  if (!isDifferentPointerPosition(prevPosition, position)) {
30
28
  return;
31
29
  }
32
- const nextTarget = this.getTarget(config);
30
+ const nextTarget = this.getTarget(instance);
33
31
  const init = this.getEventInit();
34
32
  const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
35
33
  return {
36
34
  leave: ()=>{
37
- if (hasPointerEvents(config, prevTarget)) {
35
+ if (hasPointerEvents(instance, prevTarget)) {
38
36
  if (prevTarget !== nextTarget) {
39
- dispatchUIEvent(config, prevTarget, 'pointerout', init);
40
- leave.forEach((el)=>dispatchUIEvent(config, el, 'pointerleave', init));
37
+ instance.dispatchUIEvent(prevTarget, 'pointerout', init);
38
+ leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init));
41
39
  }
42
40
  }
43
41
  },
44
42
  enter: ()=>{
45
- assertPointerEvents(config, nextTarget);
43
+ assertPointerEvents(instance, nextTarget);
46
44
  if (prevTarget !== nextTarget) {
47
- dispatchUIEvent(config, nextTarget, 'pointerover', init);
48
- enter.forEach((el)=>dispatchUIEvent(config, el, 'pointerenter', init));
45
+ instance.dispatchUIEvent(nextTarget, 'pointerover', init);
46
+ enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init));
49
47
  }
50
48
  },
51
49
  move: ()=>{
52
- dispatchUIEvent(config, nextTarget, 'pointermove', init);
50
+ instance.dispatchUIEvent(nextTarget, 'pointermove', init);
53
51
  }
54
52
  };
55
53
  }
56
- down(config, _keyDef) {
54
+ down(instance, _keyDef) {
57
55
  if (this.isDown) {
58
56
  return;
59
57
  }
60
- const target = this.getTarget(config);
61
- assertPointerEvents(config, target);
58
+ const target = this.getTarget(instance);
59
+ assertPointerEvents(instance, target);
62
60
  this.isDown = true;
63
- this.isPrevented = !dispatchUIEvent(config, target, 'pointerdown', this.getEventInit());
61
+ this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit());
64
62
  }
65
- up(config, _keyDef) {
63
+ up(instance, _keyDef) {
66
64
  if (!this.isDown) {
67
65
  return;
68
66
  }
69
- const target = this.getTarget(config);
70
- assertPointerEvents(config, target);
67
+ const target = this.getTarget(instance);
68
+ assertPointerEvents(instance, target);
71
69
  this.isDown = false;
72
- dispatchUIEvent(config, target, 'pointerup', this.getEventInit());
70
+ instance.dispatchUIEvent(target, 'pointerup', this.getEventInit());
73
71
  }
74
- release(config) {
75
- const target = this.getTarget(config);
72
+ release(instance) {
73
+ const target = this.getTarget(instance);
76
74
  const [leave] = getTreeDiff(target, null);
77
75
  const init = this.getEventInit();
78
76
  // Currently there is no PointerEventsCheckLevel that would
79
77
  // make this check not use the *asserted* cached value from `up`.
80
- /* istanbul ignore else */ if (hasPointerEvents(config, target)) {
81
- dispatchUIEvent(config, target, 'pointerout', init);
82
- leave.forEach((el)=>dispatchUIEvent(config, el, 'pointerleave', init));
78
+ /* istanbul ignore else */ if (hasPointerEvents(instance, target)) {
79
+ instance.dispatchUIEvent(target, 'pointerout', init);
80
+ leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init));
83
81
  }
84
82
  this.isCancelled = true;
85
83
  }
86
- getTarget(config) {
84
+ getTarget(instance) {
87
85
  var _target;
88
- return (_target = this.position.target) !== null && _target !== void 0 ? _target : config.document.body;
86
+ return (_target = this.position.target) !== null && _target !== void 0 ? _target : instance.config.document.body;
89
87
  }
90
88
  getEventInit() {
91
89
  return {
@@ -0,0 +1,6 @@
1
+ function isDifferentPointerPosition(positionA, positionB) {
2
+ var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
3
+ return positionA.target !== positionB.target || ((ref = positionA.coords) === null || ref === void 0 ? void 0 : ref.x) !== ((ref1 = positionB.coords) === null || ref1 === void 0 ? void 0 : ref1.y) || ((ref2 = positionA.coords) === null || ref2 === void 0 ? void 0 : ref2.y) !== ((ref3 = positionB.coords) === null || ref3 === void 0 ? void 0 : ref3.y) || ((ref4 = positionA.caret) === null || ref4 === void 0 ? void 0 : ref4.node) !== ((ref5 = positionB.caret) === null || ref5 === void 0 ? void 0 : ref5.node) || ((ref6 = positionA.caret) === null || ref6 === void 0 ? void 0 : ref6.offset) !== ((ref7 = positionB.caret) === null || ref7 === void 0 ? void 0 : ref7.offset);
4
+ }
5
+
6
+ export { isDifferentPointerPosition };
@@ -1,7 +1,3 @@
1
- import '../setup/index.js';
2
- import '../utils/click/isClickableInput.js';
3
- import '../utils/dataTransfer/Clipboard.js';
4
- import '../event/eventMap.js';
5
1
  import '../event/behavior/click.js';
6
2
  import '../event/behavior/cut.js';
7
3
  import '../event/behavior/keydown.js';
@@ -9,22 +5,25 @@ import '../event/behavior/keypress.js';
9
5
  import '../event/behavior/keyup.js';
10
6
  import '../event/behavior/paste.js';
11
7
  import '@testing-library/dom';
12
- import { input } from '../utils/edit/input.js';
8
+ import '../event/eventMap.js';
9
+ import '../utils/click/isClickableInput.js';
10
+ import '../utils/dataTransfer/Clipboard.js';
13
11
  import { isEditable } from '../utils/edit/isEditable.js';
14
- import { focus } from '../utils/focus/focus.js';
15
- import '@testing-library/dom/dist/helpers.js';
12
+ import '../utils/edit/maxLength.js';
16
13
  import { isDisabled } from '../utils/misc/isDisabled.js';
17
- import { selectAll, isAllSelected } from '../utils/focus/selectAll.js';
14
+ import '@testing-library/dom/dist/helpers.js';
18
15
  import '../utils/keyDef/readNextDescriptor.js';
19
16
  import '../utils/misc/level.js';
20
17
  import '../options.js';
21
- import { Config } from '../setup/config.js';
18
+ import { focusElement } from '../event/focus.js';
19
+ import { input } from '../event/input.js';
20
+ import { selectAll, isAllSelected } from '../event/selection/selectAll.js';
22
21
 
23
22
  async function clear(element) {
24
23
  if (!isEditable(element) || isDisabled(element)) {
25
24
  throw new Error('clear()` is only supported on editable elements.');
26
25
  }
27
- focus(element);
26
+ focusElement(element);
28
27
  if (element.ownerDocument.activeElement !== element) {
29
28
  throw new Error('The element to be cleared could not be focused.');
30
29
  }
@@ -32,7 +31,7 @@ async function clear(element) {
32
31
  if (!isAllSelected(element)) {
33
32
  throw new Error('The element content to be cleared could not be selected.');
34
33
  }
35
- input(this[Config], element, '', 'deleteContentBackward');
34
+ input(this, element, '', 'deleteContentBackward');
36
35
  }
37
36
 
38
37
  export { clear };