@testing-library/user-event 14.4.0 → 14.4.1

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 (81) hide show
  1. package/dist/cjs/clipboard/copy.js +2 -1
  2. package/dist/cjs/clipboard/cut.js +2 -1
  3. package/dist/cjs/clipboard/paste.js +4 -2
  4. package/dist/cjs/document/interceptor.js +4 -4
  5. package/dist/cjs/document/selection.js +4 -3
  6. package/dist/cjs/document/value.js +4 -2
  7. package/dist/cjs/event/behavior/keydown.js +6 -2
  8. package/dist/cjs/event/behavior/keypress.js +1 -1
  9. package/dist/cjs/event/behavior/keyup.js +2 -1
  10. package/dist/cjs/event/behavior/paste.js +2 -1
  11. package/dist/cjs/event/createEvent.js +35 -19
  12. package/dist/cjs/event/dispatchEvent.js +2 -1
  13. package/dist/cjs/keyboard/parseKeyDef.js +7 -4
  14. package/dist/cjs/pointer/index.js +10 -6
  15. package/dist/cjs/setup/setup.js +7 -4
  16. package/dist/cjs/system/index.js +4 -2
  17. package/dist/cjs/system/keyboard.js +25 -23
  18. package/dist/cjs/system/pointer/buttons.js +3 -1
  19. package/dist/cjs/system/pointer/device.js +3 -1
  20. package/dist/cjs/system/pointer/index.js +69 -61
  21. package/dist/cjs/system/pointer/mouse.js +53 -44
  22. package/dist/cjs/system/pointer/pointer.js +13 -12
  23. package/dist/cjs/utility/type.js +1 -1
  24. package/dist/cjs/utility/upload.js +6 -2
  25. package/dist/cjs/utils/dataTransfer/Clipboard.js +10 -6
  26. package/dist/cjs/utils/dataTransfer/DataTransfer.js +22 -19
  27. package/dist/cjs/utils/edit/input.js +2 -1
  28. package/dist/cjs/utils/edit/maxLength.js +2 -1
  29. package/dist/cjs/utils/edit/setFiles.js +4 -2
  30. package/dist/cjs/utils/focus/cursor.js +2 -1
  31. package/dist/cjs/utils/focus/focus.js +6 -3
  32. package/dist/cjs/utils/focus/getActiveElement.js +3 -2
  33. package/dist/cjs/utils/focus/resolveCaretPosition.js +3 -3
  34. package/dist/cjs/utils/focus/selectAll.js +5 -3
  35. package/dist/cjs/utils/focus/selection.js +23 -18
  36. package/dist/cjs/utils/keyDef/readNextDescriptor.js +5 -3
  37. package/dist/cjs/utils/misc/isDisabled.js +2 -1
  38. package/dist/cjs/utils/misc/isVisible.js +1 -1
  39. package/dist/cjs/utils/misc/level.js +5 -2
  40. package/dist/cjs/utils/pointer/cssPointerEvents.js +18 -11
  41. package/dist/esm/clipboard/copy.js +2 -1
  42. package/dist/esm/clipboard/cut.js +2 -1
  43. package/dist/esm/clipboard/paste.js +4 -2
  44. package/dist/esm/document/interceptor.js +4 -4
  45. package/dist/esm/document/selection.js +4 -3
  46. package/dist/esm/document/value.js +4 -2
  47. package/dist/esm/event/behavior/keydown.js +6 -2
  48. package/dist/esm/event/behavior/keypress.js +1 -1
  49. package/dist/esm/event/behavior/keyup.js +2 -1
  50. package/dist/esm/event/behavior/paste.js +2 -1
  51. package/dist/esm/event/createEvent.js +35 -19
  52. package/dist/esm/event/dispatchEvent.js +2 -1
  53. package/dist/esm/keyboard/parseKeyDef.js +7 -4
  54. package/dist/esm/pointer/index.js +10 -6
  55. package/dist/esm/setup/setup.js +7 -4
  56. package/dist/esm/system/index.js +4 -2
  57. package/dist/esm/system/keyboard.js +25 -23
  58. package/dist/esm/system/pointer/buttons.js +3 -1
  59. package/dist/esm/system/pointer/device.js +3 -1
  60. package/dist/esm/system/pointer/index.js +69 -61
  61. package/dist/esm/system/pointer/mouse.js +54 -45
  62. package/dist/esm/system/pointer/pointer.js +13 -12
  63. package/dist/esm/utility/type.js +1 -1
  64. package/dist/esm/utility/upload.js +6 -2
  65. package/dist/esm/utils/dataTransfer/Clipboard.js +10 -6
  66. package/dist/esm/utils/dataTransfer/DataTransfer.js +22 -19
  67. package/dist/esm/utils/edit/input.js +2 -1
  68. package/dist/esm/utils/edit/maxLength.js +2 -1
  69. package/dist/esm/utils/edit/setFiles.js +4 -2
  70. package/dist/esm/utils/focus/cursor.js +2 -1
  71. package/dist/esm/utils/focus/focus.js +6 -3
  72. package/dist/esm/utils/focus/getActiveElement.js +3 -2
  73. package/dist/esm/utils/focus/resolveCaretPosition.js +3 -3
  74. package/dist/esm/utils/focus/selectAll.js +5 -3
  75. package/dist/esm/utils/focus/selection.js +23 -18
  76. package/dist/esm/utils/keyDef/readNextDescriptor.js +5 -3
  77. package/dist/esm/utils/misc/isDisabled.js +2 -1
  78. package/dist/esm/utils/misc/isVisible.js +1 -1
  79. package/dist/esm/utils/misc/level.js +5 -2
  80. package/dist/esm/utils/pointer/cssPointerEvents.js +18 -11
  81. package/package.json +3 -3
@@ -24,7 +24,8 @@ var config = require('../setup/config.js');
24
24
 
25
25
  async function copy() {
26
26
  const doc = this[config.Config].document;
27
- const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
27
+ var _activeElement;
28
+ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
28
29
  const clipboardData = copySelection.copySelection(target);
29
30
  if (clipboardData.items.length === 0) {
30
31
  return;
@@ -24,7 +24,8 @@ var config = require('../setup/config.js');
24
24
 
25
25
  async function cut() {
26
26
  const doc = this[config.Config].document;
27
- const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
27
+ var _activeElement;
28
+ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
28
29
  const clipboardData = copySelection.copySelection(target);
29
30
  if (clipboardData.items.length === 0) {
30
31
  return;
@@ -24,8 +24,10 @@ var config = require('../setup/config.js');
24
24
 
25
25
  async function paste(clipboardData) {
26
26
  const doc = this[config.Config].document;
27
- const target = doc.activeElement ?? /* istanbul ignore next */ doc.body;
28
- const dataTransfer = (typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) ?? await Clipboard.readDataTransferFromClipboard(doc).catch(()=>{
27
+ var _activeElement;
28
+ const target = (_activeElement = doc.activeElement) !== null && _activeElement !== void 0 ? _activeElement : /* istanbul ignore next */ doc.body;
29
+ var ref;
30
+ const dataTransfer = (ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && ref !== void 0 ? ref : await Clipboard.readDataTransferFromClipboard(doc).catch(()=>{
29
31
  throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
30
32
  });
31
33
  this.dispatchUIEvent(target, 'paste', {
@@ -6,8 +6,8 @@ const Interceptor = Symbol('Interceptor for programmatical calls');
6
6
  function prepareInterceptor(element, propName, interceptorImpl) {
7
7
  const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
8
8
  const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
9
- const target = prototypeDescriptor?.set ? 'set' : 'value';
10
- /* istanbul ignore if */ if (typeof prototypeDescriptor?.[target] !== 'function' || prototypeDescriptor[target][Interceptor]) {
9
+ const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
10
+ /* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
11
11
  throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
12
12
  }
13
13
  function intercept(...args) {
@@ -18,11 +18,11 @@ function prepareInterceptor(element, propName, interceptorImpl) {
18
18
  } else {
19
19
  realFunc.call(this, ...realArgs);
20
20
  }
21
- then?.();
21
+ then === null || then === void 0 ? void 0 : then();
22
22
  }
23
23
  intercept[Interceptor] = Interceptor;
24
24
  Object.defineProperty(element, propName, {
25
- ...objectDescriptor ?? prototypeDescriptor,
25
+ ...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
26
26
  [target]: intercept
27
27
  });
28
28
  }
@@ -83,9 +83,10 @@ function setUISelection(element, { focusOffset: focusOffsetParam , anchorOffset:
83
83
  }
84
84
  }
85
85
  function getUISelection(element) {
86
- const sel = element[UISelection] ?? {
87
- anchorOffset: element.selectionStart ?? 0,
88
- focusOffset: element.selectionEnd ?? 0
86
+ var _selectionStart, _selectionEnd, _UISelection;
87
+ const sel = (_UISelection = element[UISelection]) !== null && _UISelection !== void 0 ? _UISelection : {
88
+ anchorOffset: (_selectionStart = element.selectionStart) !== null && _selectionStart !== void 0 ? _selectionStart : 0,
89
+ focusOffset: (_selectionEnd = element.selectionEnd) !== null && _selectionEnd !== void 0 ? _selectionEnd : 0
89
90
  };
90
91
  return {
91
92
  ...sel,
@@ -91,7 +91,8 @@ function startTrackValue(element) {
91
91
  };
92
92
  }
93
93
  function trackOrSetValue(element, v) {
94
- element[TrackChanges]?.tracked?.push(v);
94
+ var ref, ref1;
95
+ (ref = element[TrackChanges]) === null || ref === void 0 ? void 0 : (ref1 = ref.tracked) === null || ref1 === void 0 ? void 0 : ref1.push(v);
95
96
  if (!element[TrackChanges]) {
96
97
  setUIValueClean(element);
97
98
  selection.setUISelection(element, {
@@ -100,9 +101,10 @@ function trackOrSetValue(element, v) {
100
101
  }
101
102
  }
102
103
  function commitValueAfterInput(element, cursorOffset) {
104
+ var ref;
103
105
  const changes = element[TrackChanges];
104
106
  element[TrackChanges] = undefined;
105
- if (!changes?.tracked?.length) {
107
+ if (!(changes === null || changes === void 0 ? void 0 : (ref = changes.tracked) === null || ref === void 0 ? void 0 : ref.length)) {
106
108
  return;
107
109
  }
108
110
  const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
@@ -27,7 +27,9 @@ var registry = require('./registry.js');
27
27
  var selection$1 = require('../../document/selection.js');
28
28
 
29
29
  registry.behavior.keydown = (event, target, config)=>{
30
- return keydownBehavior[event.key]?.(event, target, config) ?? combinationBehavior(event, target, config);
30
+ var ref;
31
+ var ref1;
32
+ return (ref1 = (ref = keydownBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keydownBehavior, event, target, config)) !== null && ref1 !== void 0 ? ref1 : combinationBehavior(event, target, config);
31
33
  };
32
34
  const keydownBehavior = {
33
35
  ArrowDown: (event, target, config)=>{
@@ -80,7 +82,9 @@ const keydownBehavior = {
80
82
  'textarea'
81
83
  ]) || isContentEditable.isContentEditable(target)) {
82
84
  return ()=>{
83
- const newPos = getValue.getValue(target)?.length ?? /* istanbul ignore next */ 0;
85
+ var ref;
86
+ var ref1;
87
+ const newPos = (ref1 = (ref = getValue.getValue(target)) === null || ref === void 0 ? void 0 : ref.length) !== null && ref1 !== void 0 ? ref1 : /* istanbul ignore next */ 0;
84
88
  selection.setSelectionRange(target, newPos, newPos);
85
89
  };
86
90
  }
@@ -22,7 +22,7 @@ registry.behavior.keypress = (event, target, config)=>{
22
22
  };
23
23
  } else if (isElementType.isElementType(target, 'input')) {
24
24
  const form = target.form;
25
- const submit = form?.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
25
+ const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
26
26
  if (submit) {
27
27
  return ()=>index.dispatchUIEvent(config, submit, 'click');
28
28
  } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
@@ -13,7 +13,8 @@ require('../../options.js');
13
13
  var registry = require('./registry.js');
14
14
 
15
15
  registry.behavior.keyup = (event, target, config)=>{
16
- return keyupBehavior[event.key]?.(event, target, config);
16
+ var ref;
17
+ return (ref = keyupBehavior[event.key]) === null || ref === void 0 ? void 0 : ref.call(keyupBehavior, event, target, config);
17
18
  };
18
19
  const keyupBehavior = {
19
20
  ' ': (event, target, config)=>{
@@ -20,7 +20,8 @@ require('../../options.js');
20
20
  registry.behavior.paste = (event, target, config)=>{
21
21
  if (isEditable.isEditable(target)) {
22
22
  return ()=>{
23
- const insertData = event.clipboardData?.getData('text');
23
+ var ref;
24
+ const insertData = (ref = event.clipboardData) === null || ref === void 0 ? void 0 : ref.getData('text');
24
25
  if (insertData) {
25
26
  input.input(config, target, insertData, 'insertFromPaste');
26
27
  }
@@ -45,42 +45,58 @@ const eventInitializer = {
45
45
  ]
46
46
  };
47
47
  function createEvent(type, target, init) {
48
+ var ref;
48
49
  const window = getWindow.getWindow(target);
49
50
  const { EventType , defaultInit } = eventMap.eventMap[eventMap.eventMapKeys[type]];
50
51
  const event = new (getEventConstructors(window))[EventType](type, defaultInit);
51
- eventInitializer[EventType]?.forEach((f)=>f(event, init ?? {}));
52
+ (ref = eventInitializer[EventType]) === null || ref === void 0 ? void 0 : ref.forEach((f)=>f(event, init !== null && init !== void 0 ? init : {}));
52
53
  return event;
53
54
  }
54
55
  /* istanbul ignore next */ function getEventConstructors(window) {
55
- /* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = window.Event ?? class Event {
56
+ var _Event;
57
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ const Event = (_Event = window.Event) !== null && _Event !== void 0 ? _Event : class Event {
56
58
  };
57
- const AnimationEvent = window.AnimationEvent ?? class AnimationEvent extends Event {
59
+ var _AnimationEvent;
60
+ const AnimationEvent = (_AnimationEvent = window.AnimationEvent) !== null && _AnimationEvent !== void 0 ? _AnimationEvent : class AnimationEvent extends Event {
58
61
  };
59
- const ClipboardEvent = window.ClipboardEvent ?? class ClipboardEvent extends Event {
62
+ var _ClipboardEvent;
63
+ const ClipboardEvent = (_ClipboardEvent = window.ClipboardEvent) !== null && _ClipboardEvent !== void 0 ? _ClipboardEvent : class ClipboardEvent extends Event {
60
64
  };
61
- const PopStateEvent = window.PopStateEvent ?? class PopStateEvent extends Event {
65
+ var _PopStateEvent;
66
+ const PopStateEvent = (_PopStateEvent = window.PopStateEvent) !== null && _PopStateEvent !== void 0 ? _PopStateEvent : class PopStateEvent extends Event {
62
67
  };
63
- const ProgressEvent = window.ProgressEvent ?? class ProgressEvent extends Event {
68
+ var _ProgressEvent;
69
+ const ProgressEvent = (_ProgressEvent = window.ProgressEvent) !== null && _ProgressEvent !== void 0 ? _ProgressEvent : class ProgressEvent extends Event {
64
70
  };
65
- const TransitionEvent = window.TransitionEvent ?? class TransitionEvent extends Event {
71
+ var _TransitionEvent;
72
+ const TransitionEvent = (_TransitionEvent = window.TransitionEvent) !== null && _TransitionEvent !== void 0 ? _TransitionEvent : class TransitionEvent extends Event {
66
73
  };
67
- const UIEvent = window.UIEvent ?? class UIEvent extends Event {
74
+ var _UIEvent;
75
+ const UIEvent = (_UIEvent = window.UIEvent) !== null && _UIEvent !== void 0 ? _UIEvent : class UIEvent extends Event {
68
76
  };
69
- const CompositionEvent = window.CompositionEvent ?? class CompositionEvent extends UIEvent {
77
+ var _CompositionEvent;
78
+ const CompositionEvent = (_CompositionEvent = window.CompositionEvent) !== null && _CompositionEvent !== void 0 ? _CompositionEvent : class CompositionEvent extends UIEvent {
70
79
  };
71
- const FocusEvent = window.FocusEvent ?? class FocusEvent extends UIEvent {
80
+ var _FocusEvent;
81
+ const FocusEvent = (_FocusEvent = window.FocusEvent) !== null && _FocusEvent !== void 0 ? _FocusEvent : class FocusEvent extends UIEvent {
72
82
  };
73
- const InputEvent = window.InputEvent ?? class InputEvent extends UIEvent {
83
+ var _InputEvent;
84
+ const InputEvent = (_InputEvent = window.InputEvent) !== null && _InputEvent !== void 0 ? _InputEvent : class InputEvent extends UIEvent {
74
85
  };
75
- const KeyboardEvent = window.KeyboardEvent ?? class KeyboardEvent extends UIEvent {
86
+ var _KeyboardEvent;
87
+ const KeyboardEvent = (_KeyboardEvent = window.KeyboardEvent) !== null && _KeyboardEvent !== void 0 ? _KeyboardEvent : class KeyboardEvent extends UIEvent {
76
88
  };
77
- const MouseEvent = window.MouseEvent ?? class MouseEvent extends UIEvent {
89
+ var _MouseEvent;
90
+ const MouseEvent = (_MouseEvent = window.MouseEvent) !== null && _MouseEvent !== void 0 ? _MouseEvent : class MouseEvent extends UIEvent {
78
91
  };
79
- const DragEvent = window.DragEvent ?? class DragEvent extends MouseEvent {
92
+ var _DragEvent;
93
+ const DragEvent = (_DragEvent = window.DragEvent) !== null && _DragEvent !== void 0 ? _DragEvent : class DragEvent extends MouseEvent {
80
94
  };
81
- const PointerEvent = window.PointerEvent ?? class PointerEvent extends MouseEvent {
95
+ var _PointerEvent;
96
+ const PointerEvent = (_PointerEvent = window.PointerEvent) !== null && _PointerEvent !== void 0 ? _PointerEvent : class PointerEvent extends MouseEvent {
82
97
  };
83
- const TouchEvent = window.TouchEvent ?? class TouchEvent extends UIEvent {
98
+ var _TouchEvent;
99
+ const TouchEvent = (_TouchEvent = window.TouchEvent) !== null && _TouchEvent !== void 0 ? _TouchEvent : class TouchEvent extends UIEvent {
84
100
  };
85
101
  /* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-extraneous-class */ return {
86
102
  Event,
@@ -103,12 +119,12 @@ function createEvent(type, target, init) {
103
119
  function assignProps(obj, props) {
104
120
  for (const [key, value] of Object.entries(props)){
105
121
  Object.defineProperty(obj, key, {
106
- get: ()=>value ?? null
122
+ get: ()=>value !== null && value !== void 0 ? value : null
107
123
  });
108
124
  }
109
125
  }
110
126
  function sanitizeNumber(n) {
111
- return Number(n ?? 0);
127
+ return Number(n !== null && n !== void 0 ? n : 0);
112
128
  }
113
129
  function initClipboardEvent(event, { clipboardData }) {
114
130
  assignProps(event, {
@@ -125,7 +141,7 @@ function initInputEvent(event, { data , inputType , isComposing }) {
125
141
  function initUIEvent(event, { view , detail }) {
126
142
  assignProps(event, {
127
143
  view,
128
- detail: sanitizeNumber(detail ?? 0)
144
+ detail: sanitizeNumber(detail !== null && detail !== void 0 ? detail : 0)
129
145
  });
130
146
  }
131
147
  function initUIEventModififiers(event, { altKey , ctrlKey , metaKey , shiftKey , modifierAltGraph , modifierCapsLock , modifierFn , modifierFnLock , modifierNumLock , modifierScrollLock , modifierSymbol , modifierSymbolLock }) {
@@ -12,8 +12,9 @@ var registry = require('./behavior/registry.js');
12
12
  var wrapEvent = require('./wrapEvent.js');
13
13
 
14
14
  function dispatchEvent(config, target, event, preventDefault = false) {
15
+ var ref;
15
16
  const type = event.type;
16
- const behaviorImplementation = preventDefault ? ()=>{} : registry.behavior[type]?.(event, target, config);
17
+ const behaviorImplementation = preventDefault ? ()=>{} : (ref = registry.behavior[type]) === null || ref === void 0 ? void 0 : ref(event, target, config);
17
18
  if (behaviorImplementation) {
18
19
  event.preventDefault();
19
20
  let defaultPrevented = false;
@@ -32,14 +32,17 @@ require('../options.js');
32
32
  const defs = [];
33
33
  do {
34
34
  const { type , descriptor , consumedLength , releasePrevious , releaseSelf =true , repeat , } = readNextDescriptor.readNextDescriptor(text, 'keyboard');
35
- const keyDef = keyboardMap.find((def)=>{
35
+ var ref;
36
+ const keyDef = (ref = keyboardMap.find((def)=>{
36
37
  if (type === '[') {
37
- return def.code?.toLowerCase() === descriptor.toLowerCase();
38
+ var ref;
39
+ return ((ref = def.code) === null || ref === void 0 ? void 0 : ref.toLowerCase()) === descriptor.toLowerCase();
38
40
  } else if (type === '{') {
39
- return def.key?.toLowerCase() === descriptor.toLowerCase();
41
+ var ref1;
42
+ return ((ref1 = def.key) === null || ref1 === void 0 ? void 0 : ref1.toLowerCase()) === descriptor.toLowerCase();
40
43
  }
41
44
  return def.key === descriptor;
42
- }) ?? {
45
+ })) !== null && ref !== void 0 ? ref : {
43
46
  key: 'Unknown',
44
47
  code: 'Unknown',
45
48
  [type === '[' ? 'code' : 'key']: descriptor
@@ -47,14 +47,16 @@ async function pointer(input) {
47
47
  this[config.Config].system.pointer.resetClickCount();
48
48
  }
49
49
  async function pointerAction(config, action) {
50
+ var ref, ref1;
50
51
  const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? config.system.pointer.getPointerName(action.keyDef) : 'mouse';
51
52
  const previousPosition = config.system.pointer.getPreviousPosition(pointerName);
53
+ var _target, _coords, _node, _offset;
52
54
  const position = {
53
- target: action.target ?? getPrevTarget(config, previousPosition),
54
- coords: action.coords ?? previousPosition?.coords,
55
+ target: (_target = action.target) !== null && _target !== void 0 ? _target : getPrevTarget(config, previousPosition),
56
+ coords: (_coords = action.coords) !== null && _coords !== void 0 ? _coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
55
57
  caret: {
56
- node: action.node ?? (hasCaretPosition(action) ? undefined : previousPosition?.caret?.node),
57
- offset: action.offset ?? (hasCaretPosition(action) ? undefined : previousPosition?.caret?.offset)
58
+ node: (_node = action.node) !== null && _node !== void 0 ? _node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref = previousPosition.caret) === null || ref === void 0 ? void 0 : ref.node,
59
+ offset: (_offset = action.offset) !== null && _offset !== void 0 ? _offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (ref1 = previousPosition.caret) === null || ref1 === void 0 ? void 0 : ref1.offset
58
60
  }
59
61
  };
60
62
  if ('keyDef' in action) {
@@ -76,13 +78,15 @@ async function pointerAction(config, action) {
76
78
  }
77
79
  }
78
80
  function hasCaretPosition(action) {
79
- return !!((action.target ?? action.node) ?? action.offset !== undefined);
81
+ var _target, ref;
82
+ return !!((ref = (_target = action.target) !== null && _target !== void 0 ? _target : action.node) !== null && ref !== void 0 ? ref : action.offset !== undefined);
80
83
  }
81
84
  function getPrevTarget(config, position) {
82
85
  if (!position) {
83
86
  throw new Error('This pointer has no previous position. Provide a target property!');
84
87
  }
85
- return position.target ?? config.document.body;
88
+ var _target;
89
+ return (_target = position.target) !== null && _target !== void 0 ? _target : config.document.body;
86
90
  }
87
91
 
88
92
  exports.pointer = pointer;
@@ -22,11 +22,12 @@ var wrapAsync = require('./wrapAsync.js');
22
22
 
23
23
  function createConfig(options$1 = {}, defaults = options.defaultOptionsSetup, node) {
24
24
  const document = getDocument(options$1, node, defaults);
25
+ var _system;
25
26
  return {
26
27
  ...defaults,
27
28
  ...options$1,
28
29
  document,
29
- system: options$1.system ?? new index.System()
30
+ system: (_system = options$1.system) !== null && _system !== void 0 ? _system : new index.System()
30
31
  };
31
32
  }
32
33
  /**
@@ -35,7 +36,8 @@ function createConfig(options$1 = {}, defaults = options.defaultOptionsSetup, no
35
36
  */ function setupMain(options = {}) {
36
37
  const config = createConfig(options);
37
38
  index$1.prepareDocument(config.document);
38
- const view = config.document.defaultView ?? /* istanbul ignore next */ globalThis.window;
39
+ var _defaultView;
40
+ const view = (_defaultView = config.document.defaultView) !== null && _defaultView !== void 0 ? _defaultView : /* istanbul ignore next */ globalThis.window;
39
41
  Clipboard.attachClipboardStubToView(view);
40
42
  return doSetup(config);
41
43
  }
@@ -44,7 +46,7 @@ function createConfig(options$1 = {}, defaults = options.defaultOptionsSetup, no
44
46
  */ function setupDirect({ keyboardState , pointerState , ...options$1 } = {}, node) {
45
47
  const config = createConfig({
46
48
  ...options$1,
47
- system: pointerState ?? keyboardState
49
+ system: pointerState !== null && pointerState !== void 0 ? pointerState : keyboardState
48
50
  }, options.defaultOptionsDirect, node);
49
51
  index$1.prepareDocument(config.document);
50
52
  return {
@@ -88,7 +90,8 @@ function doSetup(config$1) {
88
90
  };
89
91
  }
90
92
  function getDocument(options, node, defaults) {
91
- return (options.document ?? (node && getDocumentFromNode.getDocumentFromNode(node))) ?? defaults.document;
93
+ var _document, ref;
94
+ return (ref = (_document = options.document) !== null && _document !== void 0 ? _document : node && getDocumentFromNode.getDocumentFromNode(node)) !== null && ref !== void 0 ? ref : defaults.document;
92
95
  }
93
96
 
94
97
  exports.createConfig = createConfig;
@@ -8,8 +8,6 @@ var index = require('./pointer/index.js');
8
8
  /**
9
9
  * @internal Do not create/alter this by yourself as this type might be subject to changes.
10
10
  */ class System {
11
- keyboard = new keyboard.KeyboardHost(this);
12
- pointer = new index.PointerHost(this);
13
11
  getUIEventModifiers() {
14
12
  return {
15
13
  altKey: this.keyboard.modifiers.Alt,
@@ -26,6 +24,10 @@ var index = require('./pointer/index.js');
26
24
  modifierSymbolLock: this.keyboard.modifiers.SymbolLock
27
25
  };
28
26
  }
27
+ constructor(){
28
+ this.keyboard = new keyboard.KeyboardHost(this);
29
+ this.pointer = new index.PointerHost(this);
30
+ }
29
31
  }
30
32
 
31
33
  exports.System = System;
@@ -14,6 +14,7 @@ require('../utils/keyDef/readNextDescriptor.js');
14
14
  require('../utils/misc/level.js');
15
15
  require('../options.js');
16
16
 
17
+ var _pressed, _code, _code1;
17
18
  exports.DOM_KEY_LOCATION = void 0;
18
19
  (function(DOM_KEY_LOCATION) {
19
20
  DOM_KEY_LOCATION[DOM_KEY_LOCATION["STANDARD"] = 0] = "STANDARD";
@@ -44,27 +45,6 @@ function isModifierLock(key) {
44
45
  return modifierLocks.includes(key);
45
46
  }
46
47
  class KeyboardHost {
47
- constructor(system){
48
- this.system = system;
49
- }
50
- modifiers = {
51
- Alt: false,
52
- AltGraph: false,
53
- CapsLock: false,
54
- Control: false,
55
- Fn: false,
56
- FnLock: false,
57
- Meta: false,
58
- NumLock: false,
59
- ScrollLock: false,
60
- Shift: false,
61
- Symbol: false,
62
- SymbolLock: false
63
- };
64
- pressed = {};
65
- carryChar = '';
66
- lastKeydownTarget = undefined;
67
- modifierLockStart = {};
68
48
  isKeyPressed(keyDef) {
69
49
  return !!this.pressed[String(keyDef.code)];
70
50
  }
@@ -76,7 +56,8 @@ class KeyboardHost {
76
56
  const code = String(keyDef.code);
77
57
  const target = getActiveElement.getActiveElementOrBody(config.document);
78
58
  this.setKeydownTarget(target);
79
- this.pressed[code] ??= {
59
+ var ref;
60
+ (ref = (_pressed = this.pressed)[_code = code]) !== null && ref !== void 0 ? ref : _pressed[_code] = {
80
61
  keyDef,
81
62
  unpreventedDefault: false
82
63
  };
@@ -91,7 +72,7 @@ class KeyboardHost {
91
72
  this.modifiers[key] = true;
92
73
  this.modifierLockStart[key] = true;
93
74
  }
94
- this.pressed[code].unpreventedDefault ||= unprevented;
75
+ (_code1 = this.pressed[code]).unpreventedDefault || (_code1.unpreventedDefault = unprevented);
95
76
  if (unprevented && this.hasKeyPress(key)) {
96
77
  index.dispatchUIEvent(config, getActiveElement.getActiveElementOrBody(config.document), 'keypress', {
97
78
  key,
@@ -130,6 +111,27 @@ class KeyboardHost {
130
111
  hasKeyPress(key) {
131
112
  return (key.length === 1 || key === 'Enter') && !this.modifiers.Control && !this.modifiers.Alt;
132
113
  }
114
+ constructor(system){
115
+ this.modifiers = {
116
+ Alt: false,
117
+ AltGraph: false,
118
+ CapsLock: false,
119
+ Control: false,
120
+ Fn: false,
121
+ FnLock: false,
122
+ Meta: false,
123
+ NumLock: false,
124
+ ScrollLock: false,
125
+ Shift: false,
126
+ Symbol: false,
127
+ SymbolLock: false
128
+ };
129
+ this.pressed = {};
130
+ this.carryChar = '';
131
+ this.lastKeydownTarget = undefined;
132
+ this.modifierLockStart = {};
133
+ this.system = system;
134
+ }
133
135
  }
134
136
 
135
137
  exports.KeyboardHost = KeyboardHost;
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  class Buttons {
6
- pressed = {};
7
6
  getButtons() {
8
7
  let v = 0;
9
8
  for (const button of Object.keys(this.pressed)){
@@ -35,6 +34,9 @@ class Buttons {
35
34
  }
36
35
  return undefined;
37
36
  }
37
+ constructor(){
38
+ this.pressed = {};
39
+ }
38
40
  }
39
41
  const MouseButton = {
40
42
  primary: 0,
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  class Device {
6
- pressedKeys = new Set();
7
6
  get countPressed() {
8
7
  return this.pressedKeys.size;
9
8
  }
@@ -16,6 +15,9 @@ class Device {
16
15
  removePressed(keyDef) {
17
16
  return this.pressedKeys.delete(keyDef.name);
18
17
  }
18
+ constructor(){
19
+ this.pressedKeys = new Set();
20
+ }
19
21
  }
20
22
 
21
23
  exports.Device = Device;