@testing-library/user-event 14.6.0 → 14.6.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.
@@ -34,30 +34,30 @@ function patchFocus(HTMLElement) {
34
34
  if (this.ownerDocument.visibilityState !== 'hidden') {
35
35
  return focus.call(this, options);
36
36
  }
37
- const blured = getActiveTarget(this.ownerDocument);
38
- if (blured === this) {
37
+ const blurred = getActiveTarget(this.ownerDocument);
38
+ if (blurred === this) {
39
39
  return;
40
40
  }
41
41
  const thisCall = Symbol('focus call');
42
42
  activeCall = thisCall;
43
- if (blured) {
44
- blur.call(blured);
45
- dispatchEvent.dispatchDOMEvent(blured, 'blur', {
43
+ if (blurred) {
44
+ blur.call(blurred);
45
+ dispatchEvent.dispatchDOMEvent(blurred, 'blur', {
46
46
  relatedTarget: this
47
47
  });
48
- dispatchEvent.dispatchDOMEvent(blured, 'focusout', {
48
+ dispatchEvent.dispatchDOMEvent(blurred, 'focusout', {
49
49
  relatedTarget: activeCall === thisCall ? this : null
50
50
  });
51
51
  }
52
52
  if (activeCall === thisCall) {
53
53
  focus.call(this, options);
54
54
  dispatchEvent.dispatchDOMEvent(this, 'focus', {
55
- relatedTarget: blured
55
+ relatedTarget: blurred
56
56
  });
57
57
  }
58
58
  if (activeCall === thisCall) {
59
59
  dispatchEvent.dispatchDOMEvent(this, 'focusin', {
60
- relatedTarget: blured
60
+ relatedTarget: blurred
61
61
  });
62
62
  }
63
63
  }
@@ -65,17 +65,17 @@ function patchFocus(HTMLElement) {
65
65
  if (this.ownerDocument.visibilityState !== 'hidden') {
66
66
  return blur.call(this);
67
67
  }
68
- const blured = getActiveTarget(this.ownerDocument);
69
- if (blured !== this) {
68
+ const blurred = getActiveTarget(this.ownerDocument);
69
+ if (blurred !== this) {
70
70
  return;
71
71
  }
72
72
  const thisCall = Symbol('blur call');
73
73
  activeCall = thisCall;
74
74
  blur.call(this);
75
- dispatchEvent.dispatchDOMEvent(blured, 'blur', {
75
+ dispatchEvent.dispatchDOMEvent(blurred, 'blur', {
76
76
  relatedTarget: null
77
77
  });
78
- dispatchEvent.dispatchDOMEvent(blured, 'focusout', {
78
+ dispatchEvent.dispatchDOMEvent(blurred, 'focusout', {
79
79
  relatedTarget: null
80
80
  });
81
81
  }
@@ -11,12 +11,12 @@ var registry = require('./registry.js');
11
11
  registry.behavior.click = (event, target, instance)=>{
12
12
  const context = target.closest('button,input,label,select,textarea');
13
13
  const control = context && isElementType.isElementType(context, 'label') && context.control;
14
- if (control) {
14
+ if (control && control !== target) {
15
15
  return ()=>{
16
16
  if (isFocusable.isFocusable(control)) {
17
17
  focus.focusElement(control);
18
+ instance.dispatchEvent(control, cloneEvent.cloneEvent(event));
18
19
  }
19
- instance.dispatchEvent(control, cloneEvent.cloneEvent(event));
20
20
  };
21
21
  } else if (isElementType.isElementType(target, 'input', {
22
22
  type: 'file'
@@ -26,7 +26,7 @@ const keydownBehavior = {
26
26
  /* istanbul ignore else */ if (isElementType.isElementType(target, 'input', {
27
27
  type: 'radio'
28
28
  })) {
29
- return ()=>radio.walkRadio(instance, target, -1);
29
+ return ()=>radio.walkRadio(instance, target, 1);
30
30
  }
31
31
  },
32
32
  ArrowLeft: (event, target, instance)=>{
@@ -49,7 +49,7 @@ const keydownBehavior = {
49
49
  /* istanbul ignore else */ if (isElementType.isElementType(target, 'input', {
50
50
  type: 'radio'
51
51
  })) {
52
- return ()=>radio.walkRadio(instance, target, 1);
52
+ return ()=>radio.walkRadio(instance, target, -1);
53
53
  }
54
54
  },
55
55
  Backspace: (event, target, instance)=>{
@@ -19,18 +19,18 @@ const eventInitializer = {
19
19
  ],
20
20
  MouseEvent: [
21
21
  initUIEvent,
22
- initUIEventModififiers,
22
+ initUIEventModifiers,
23
23
  initMouseEvent
24
24
  ],
25
25
  PointerEvent: [
26
26
  initUIEvent,
27
- initUIEventModififiers,
27
+ initUIEventModifiers,
28
28
  initMouseEvent,
29
29
  initPointerEvent
30
30
  ],
31
31
  KeyboardEvent: [
32
32
  initUIEvent,
33
- initUIEventModififiers,
33
+ initUIEventModifiers,
34
34
  initKeyboardEvent
35
35
  ]
36
36
  };
@@ -138,7 +138,7 @@ function initUIEvent(event, { view, detail }) {
138
138
  detail: sanitizeNumber(detail !== null && detail !== undefined ? detail : 0)
139
139
  });
140
140
  }
141
- function initUIEventModififiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
141
+ function initUIEventModifiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
142
142
  assignProps(event, {
143
143
  altKey: Boolean(altKey),
144
144
  ctrlKey: Boolean(ctrlKey),
@@ -192,8 +192,8 @@ function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY =
192
192
  function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary }) {
193
193
  assignProps(event, {
194
194
  pointerId: sanitizeNumber(pointerId),
195
- width: sanitizeNumber(width),
196
- height: sanitizeNumber(height),
195
+ width: sanitizeNumber(width !== null && width !== undefined ? width : 1),
196
+ height: sanitizeNumber(height !== null && height !== undefined ? height : 1),
197
197
  pressure: sanitizeNumber(pressure),
198
198
  tangentialPressure: sanitizeNumber(tangentialPressure),
199
199
  tiltX: sanitizeNumber(tiltX),
@@ -20,6 +20,7 @@ function walkRadio(instance, el, direction) {
20
20
  }
21
21
  focus.focusElement(group[i]);
22
22
  instance.dispatchUIEvent(group[i], 'click');
23
+ return;
23
24
  }
24
25
  }
25
26
 
@@ -5,7 +5,7 @@ var keyboard = require('../system/keyboard.js');
5
5
  /**
6
6
  * Mapping for a default US-104-QWERTY keyboard
7
7
  */ const defaultKeyMap = [
8
- // alphanumeric keys
8
+ // alphanumeric block - writing system
9
9
  ...'0123456789'.split('').map((c)=>({
10
10
  code: `Digit${c}`,
11
11
  key: c
@@ -24,6 +24,24 @@ var keyboard = require('../system/keyboard.js');
24
24
  key: c,
25
25
  shiftKey: true
26
26
  })),
27
+ {
28
+ code: 'BracketLeft',
29
+ key: '['
30
+ },
31
+ {
32
+ code: 'BracketLeft',
33
+ key: '{',
34
+ shiftKey: true
35
+ },
36
+ {
37
+ code: 'BracketRight',
38
+ key: ']'
39
+ },
40
+ {
41
+ code: 'BracketRight',
42
+ key: '}',
43
+ shiftKey: true
44
+ },
27
45
  // alphanumeric block - functional
28
46
  {
29
47
  code: 'Space',
@@ -79,6 +97,10 @@ var keyboard = require('../system/keyboard.js');
79
97
  key: 'OS',
80
98
  location: keyboard.DOM_KEY_LOCATION.RIGHT
81
99
  },
100
+ {
101
+ code: 'ContextMenu',
102
+ key: 'ContextMenu'
103
+ },
82
104
  {
83
105
  code: 'Tab',
84
106
  key: 'Tab'
@@ -4,7 +4,7 @@ require('../utils/dataTransfer/Clipboard.js');
4
4
  var readNextDescriptor = require('../utils/keyDef/readNextDescriptor.js');
5
5
 
6
6
  /**
7
- * Parse key defintions per `keyboardMap`
7
+ * Parse key definitions per `keyboardMap`
8
8
  *
9
9
  * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
10
10
  * Everything else will be interpreted as a typed character - e.g. `a`.
@@ -23,18 +23,21 @@ class PointerHost {
23
23
  return this.devices.get(keyDef.pointerType).isPressed(keyDef);
24
24
  }
25
25
  async press(instance, keyDef, position) {
26
+ this.devices.get(keyDef.pointerType).addPressed(keyDef);
27
+ this.buttons.down(keyDef);
26
28
  const pointerName = this.getPointerName(keyDef);
27
- const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(instance, position) : this.pointers.get(pointerName);
29
+ const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef.pointerType, this.buttons) : this.pointers.get(pointerName);
28
30
  // TODO: deprecate the following implicit setting of position
29
31
  pointer.position = position;
30
32
  if (pointer.pointerType !== 'touch') {
31
33
  this.mouse.position = position;
32
34
  }
33
- this.devices.get(keyDef.pointerType).addPressed(keyDef);
34
- this.buttons.down(keyDef);
35
- pointer.down(instance, keyDef);
36
- if (pointer.pointerType !== 'touch' && !pointer.isPrevented) {
37
- this.mouse.down(instance, keyDef, pointer);
35
+ if (pointer.pointerType === 'touch') {
36
+ pointer.init(instance);
37
+ }
38
+ pointer.down(instance, keyDef.button);
39
+ if (pointer.pointerType !== 'touch') {
40
+ this.mouse.down(instance, keyDef, pointer.isPrevented);
38
41
  }
39
42
  }
40
43
  async move(instance, pointerName, position) {
@@ -44,7 +47,7 @@ class PointerHost {
44
47
  // While the order of mouse (or pointer) events is defined per spec,
45
48
  // the order in which they interweave/follow on a user interaction depends on the implementation.
46
49
  const pointermove = pointer.move(instance, position);
47
- const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(instance, position);
50
+ const mousemove = pointer.pointerType === 'touch' ? undefined : this.mouse.move(instance, position, pointer.isPrevented);
48
51
  pointermove === null || pointermove === undefined ? undefined : pointermove.leave();
49
52
  mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
50
53
  pointermove === null || pointermove === undefined ? undefined : pointermove.enter();
@@ -57,32 +60,31 @@ class PointerHost {
57
60
  device.removePressed(keyDef);
58
61
  this.buttons.up(keyDef);
59
62
  const pointer = this.pointers.get(this.getPointerName(keyDef));
63
+ const isPrevented = pointer.isPrevented;
60
64
  // TODO: deprecate the following implicit setting of position
61
65
  pointer.position = position;
62
66
  if (pointer.pointerType !== 'touch') {
63
67
  this.mouse.position = position;
64
68
  }
65
69
  if (device.countPressed === 0) {
66
- pointer.up(instance, keyDef);
70
+ pointer.up(instance, keyDef.button);
67
71
  }
68
72
  if (pointer.pointerType === 'touch') {
69
73
  pointer.release(instance);
70
74
  }
71
- if (!pointer.isPrevented) {
72
- if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
73
- const mousemove = this.mouse.move(instance, pointer.position);
74
- mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
75
- mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
76
- mousemove === null || mousemove === undefined ? undefined : mousemove.move();
77
- this.mouse.down(instance, keyDef, pointer);
78
- }
79
- if (!pointer.isMultitouch) {
80
- const mousemove = this.mouse.move(instance, pointer.position);
81
- mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
82
- mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
83
- mousemove === null || mousemove === undefined ? undefined : mousemove.move();
84
- this.mouse.up(instance, keyDef, pointer);
85
- }
75
+ if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
76
+ const mousemove = this.mouse.move(instance, position, isPrevented);
77
+ mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
78
+ mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
79
+ mousemove === null || mousemove === undefined ? undefined : mousemove.move();
80
+ this.mouse.down(instance, keyDef, isPrevented);
81
+ }
82
+ if (!pointer.isMultitouch) {
83
+ const mousemove = this.mouse.move(instance, position, isPrevented);
84
+ mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
85
+ mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
86
+ mousemove === null || mousemove === undefined ? undefined : mousemove.move();
87
+ this.mouse.up(instance, keyDef, isPrevented);
86
88
  }
87
89
  }
88
90
  getPointerName(keyDef) {
@@ -117,20 +119,20 @@ class PointerHost {
117
119
  }
118
120
  }());
119
121
  _define_property(this, "pointers", new class {
120
- new(pointerName, keyDef) {
121
- const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
122
+ new(pointerName, pointerType, buttons) {
123
+ const isPrimary = pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
122
124
  if (!isPrimary) {
123
125
  Object.values(this.registry).forEach((p)=>{
124
- if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
126
+ if (p.pointerType === pointerType && !p.isCancelled) {
125
127
  p.isMultitouch = true;
126
128
  }
127
129
  });
128
130
  }
129
131
  this.registry[pointerName] = new pointer.Pointer({
130
132
  pointerId: this.nextId++,
131
- pointerType: keyDef.pointerType,
133
+ pointerType,
132
134
  isPrimary
133
- });
135
+ }, buttons);
134
136
  return this.registry[pointerName];
135
137
  }
136
138
  get(pointerName) {
@@ -143,19 +145,14 @@ class PointerHost {
143
145
  return pointerName in this.registry;
144
146
  }
145
147
  constructor(){
146
- _define_property(this, "registry", {
147
- mouse: new pointer.Pointer({
148
- pointerId: 1,
149
- pointerType: 'mouse',
150
- isPrimary: true
151
- })
152
- });
153
- _define_property(this, "nextId", 2);
148
+ _define_property(this, "registry", {});
149
+ _define_property(this, "nextId", 1);
154
150
  }
155
151
  }());
156
152
  this.system = system;
157
153
  this.buttons = new buttons.Buttons();
158
154
  this.mouse = new mouse.Mouse();
155
+ this.pointers.new('mouse', 'mouse', this.buttons);
159
156
  }
160
157
  }
161
158
 
@@ -32,7 +32,7 @@ function _define_property(obj, key, value) {
32
32
  /**
33
33
  * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
34
34
  */ class Mouse {
35
- move(instance, position) {
35
+ move(instance, position, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
36
36
  const prevPosition = this.position;
37
37
  const prevTarget = this.getTarget(instance);
38
38
  this.position = position;
@@ -56,40 +56,46 @@ function _define_property(obj, key, value) {
56
56
  }
57
57
  },
58
58
  move: ()=>{
59
+ if (isPrevented) {
60
+ return;
61
+ }
59
62
  instance.dispatchUIEvent(nextTarget, 'mousemove', init);
60
63
  this.modifySelecting(instance);
61
64
  }
62
65
  };
63
66
  }
64
- down(instance, keyDef, pointer) {
67
+ down(instance, keyDef, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
65
68
  const button = this.buttons.down(keyDef);
66
69
  if (button === undefined) {
67
70
  return;
68
71
  }
69
72
  const target = this.getTarget(instance);
70
73
  this.buttonDownTarget[button] = target;
71
- const disabled = isDisabled.isDisabled(target);
72
74
  const init = this.getEventInit('mousedown', keyDef.button);
73
- if (disabled || instance.dispatchUIEvent(target, 'mousedown', init)) {
75
+ const disabled = isDisabled.isDisabled(target);
76
+ if (!isPrevented && (disabled || instance.dispatchUIEvent(target, 'mousedown', init))) {
74
77
  this.startSelecting(instance, init.detail);
75
78
  focus.focusElement(target);
76
79
  }
77
80
  if (!disabled && buttons.getMouseEventButton(keyDef.button) === 2) {
78
- instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer));
81
+ instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button));
79
82
  }
80
83
  }
81
- up(instance, keyDef, pointer) {
84
+ up(instance, keyDef, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
82
85
  const button = this.buttons.up(keyDef);
83
86
  if (button === undefined) {
84
87
  return;
85
88
  }
86
89
  const target = this.getTarget(instance);
87
90
  if (!isDisabled.isDisabled(target)) {
88
- instance.dispatchUIEvent(target, 'mouseup', this.getEventInit('mouseup', keyDef.button));
89
- this.endSelecting();
91
+ if (!isPrevented) {
92
+ const mouseUpInit = this.getEventInit('mouseup', keyDef.button);
93
+ instance.dispatchUIEvent(target, 'mouseup', mouseUpInit);
94
+ this.endSelecting();
95
+ }
90
96
  const clickTarget = getTreeDiff.getTreeDiff(this.buttonDownTarget[button], target)[2][0];
91
97
  if (clickTarget) {
92
- const init = this.getEventInit('click', keyDef.button, pointer);
98
+ const init = this.getEventInit('click', keyDef.button);
93
99
  if (init.detail) {
94
100
  instance.dispatchUIEvent(clickTarget, init.button === 0 ? 'click' : 'auxclick', init);
95
101
  if (init.button === 0 && init.detail === 2) {
@@ -105,15 +111,10 @@ function _define_property(obj, key, value) {
105
111
  resetClickCount() {
106
112
  this.clickCount.reset();
107
113
  }
108
- getEventInit(type, button, pointer) {
114
+ getEventInit(type, button) {
109
115
  const init = {
110
116
  ...this.position.coords
111
117
  };
112
- if (pointer) {
113
- init.pointerId = pointer.pointerId;
114
- init.pointerType = pointer.pointerType;
115
- init.isPrimary = pointer.isPrimary;
116
- }
117
118
  init.button = buttons.getMouseEventButton(button);
118
119
  init.buttons = this.buttons.getButtons();
119
120
  if (type === 'mousedown') {
@@ -4,6 +4,7 @@ require('../../utils/dataTransfer/Clipboard.js');
4
4
  var getTreeDiff = require('../../utils/misc/getTreeDiff.js');
5
5
  var cssPointerEvents = require('../../utils/pointer/cssPointerEvents.js');
6
6
  var shared = require('./shared.js');
7
+ var buttons = require('./buttons.js');
7
8
 
8
9
  function _define_property(obj, key, value) {
9
10
  if (key in obj) {
@@ -19,8 +20,7 @@ function _define_property(obj, key, value) {
19
20
  return obj;
20
21
  }
21
22
  class Pointer {
22
- init(instance, position) {
23
- this.position = position;
23
+ init(instance) {
24
24
  const target = this.getTarget(instance);
25
25
  const [, enter] = getTreeDiff.getTreeDiff(null, target);
26
26
  const init = this.getEventInit();
@@ -37,7 +37,7 @@ class Pointer {
37
37
  return;
38
38
  }
39
39
  const nextTarget = this.getTarget(instance);
40
- const init = this.getEventInit();
40
+ const init = this.getEventInit(-1);
41
41
  const [leave, enter] = getTreeDiff.getTreeDiff(prevTarget, nextTarget);
42
42
  return {
43
43
  leave: ()=>{
@@ -60,23 +60,24 @@ class Pointer {
60
60
  }
61
61
  };
62
62
  }
63
- down(instance, _keyDef) {
63
+ down(instance, button = 0) {
64
64
  if (this.isDown) {
65
65
  return;
66
66
  }
67
67
  const target = this.getTarget(instance);
68
68
  cssPointerEvents.assertPointerEvents(instance, target);
69
69
  this.isDown = true;
70
- this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit());
70
+ this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit(button));
71
71
  }
72
- up(instance, _keyDef) {
72
+ up(instance, button = 0) {
73
73
  if (!this.isDown) {
74
74
  return;
75
75
  }
76
76
  const target = this.getTarget(instance);
77
77
  cssPointerEvents.assertPointerEvents(instance, target);
78
+ this.isPrevented = false;
78
79
  this.isDown = false;
79
- instance.dispatchUIEvent(target, 'pointerup', this.getEventInit());
80
+ instance.dispatchUIEvent(target, 'pointerup', this.getEventInit(button));
80
81
  }
81
82
  release(instance) {
82
83
  const target = this.getTarget(instance);
@@ -94,18 +95,26 @@ class Pointer {
94
95
  var _this_position_target;
95
96
  return (_this_position_target = this.position.target) !== null && _this_position_target !== undefined ? _this_position_target : instance.config.document.body;
96
97
  }
97
- getEventInit() {
98
+ getEventInit(/**
99
+ * The `button` that caused the event.
100
+ *
101
+ * This should be `-1` if the event is not caused by a button or touch/pen contact,
102
+ * e.g. a moving pointer.
103
+ */ button) {
98
104
  return {
99
105
  ...this.position.coords,
100
106
  pointerId: this.pointerId,
101
107
  pointerType: this.pointerType,
102
- isPrimary: this.isPrimary
108
+ isPrimary: this.isPrimary,
109
+ button: buttons.getMouseEventButton(button),
110
+ buttons: this.buttons.getButtons()
103
111
  };
104
112
  }
105
- constructor({ pointerId, pointerType, isPrimary }){
113
+ constructor({ pointerId, pointerType, isPrimary }, buttons){
106
114
  _define_property(this, "pointerId", undefined);
107
115
  _define_property(this, "pointerType", undefined);
108
116
  _define_property(this, "isPrimary", undefined);
117
+ _define_property(this, "buttons", undefined);
109
118
  _define_property(this, "isMultitouch", false);
110
119
  _define_property(this, "isCancelled", false);
111
120
  _define_property(this, "isDown", false);
@@ -115,6 +124,7 @@ class Pointer {
115
124
  this.pointerType = pointerType;
116
125
  this.isPrimary = isPrimary;
117
126
  this.isMultitouch = !isPrimary;
127
+ this.buttons = buttons;
118
128
  }
119
129
  }
120
130
 
@@ -35,6 +35,10 @@ async function upload(element, fileOrFiles) {
35
35
  await this.click(element);
36
36
  input.removeEventListener('fileDialog', fileDialog);
37
37
  }
38
+ // When matching files, browsers ignore case and consider jpeg/jpg interchangeable.
39
+ function normalize(nameOrType) {
40
+ return nameOrType.toLowerCase().replace(/(\.|\/)jpg\b/g, '$1jpeg');
41
+ }
38
42
  function isAcceptableFile(file, accept) {
39
43
  if (!accept) {
40
44
  return true;
@@ -44,14 +48,14 @@ function isAcceptableFile(file, accept) {
44
48
  'image/*',
45
49
  'video/*'
46
50
  ];
47
- return accept.split(',').some((acceptToken)=>{
51
+ return normalize(accept).trim().split(/\s*,\s*/).some((acceptToken)=>{
52
+ // tokens starting with a dot represent a file extension
48
53
  if (acceptToken.startsWith('.')) {
49
- // tokens starting with a dot represent a file extension
50
- return file.name.endsWith(acceptToken);
54
+ return normalize(file.name).endsWith(acceptToken);
51
55
  } else if (wildcards.includes(acceptToken)) {
52
- return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
56
+ return normalize(file.type).startsWith(acceptToken.replace('*', ''));
53
57
  }
54
- return file.type === acceptToken;
58
+ return normalize(file.type) === acceptToken;
55
59
  });
56
60
  }
57
61
 
@@ -9,7 +9,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
9
9
  // Firefox always moves to zero offset and jumps over last offset.
10
10
  // Chrome jumps over zero offset per default but over last offset when Shift is pressed.
11
11
  // The cursor always moves to zero offset if the focus area (contenteditable or body) ends there.
12
- // When walking foward both ignore zero offset.
12
+ // When walking forward both ignore zero offset.
13
13
  // When walking over input elements the cursor moves before or after that element.
14
14
  // When walking over line breaks the cursor moves inside any following text node.
15
15
  if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
@@ -32,30 +32,30 @@ function patchFocus(HTMLElement) {
32
32
  if (this.ownerDocument.visibilityState !== 'hidden') {
33
33
  return focus.call(this, options);
34
34
  }
35
- const blured = getActiveTarget(this.ownerDocument);
36
- if (blured === this) {
35
+ const blurred = getActiveTarget(this.ownerDocument);
36
+ if (blurred === this) {
37
37
  return;
38
38
  }
39
39
  const thisCall = Symbol('focus call');
40
40
  activeCall = thisCall;
41
- if (blured) {
42
- blur.call(blured);
43
- dispatchDOMEvent(blured, 'blur', {
41
+ if (blurred) {
42
+ blur.call(blurred);
43
+ dispatchDOMEvent(blurred, 'blur', {
44
44
  relatedTarget: this
45
45
  });
46
- dispatchDOMEvent(blured, 'focusout', {
46
+ dispatchDOMEvent(blurred, 'focusout', {
47
47
  relatedTarget: activeCall === thisCall ? this : null
48
48
  });
49
49
  }
50
50
  if (activeCall === thisCall) {
51
51
  focus.call(this, options);
52
52
  dispatchDOMEvent(this, 'focus', {
53
- relatedTarget: blured
53
+ relatedTarget: blurred
54
54
  });
55
55
  }
56
56
  if (activeCall === thisCall) {
57
57
  dispatchDOMEvent(this, 'focusin', {
58
- relatedTarget: blured
58
+ relatedTarget: blurred
59
59
  });
60
60
  }
61
61
  }
@@ -63,17 +63,17 @@ function patchFocus(HTMLElement) {
63
63
  if (this.ownerDocument.visibilityState !== 'hidden') {
64
64
  return blur.call(this);
65
65
  }
66
- const blured = getActiveTarget(this.ownerDocument);
67
- if (blured !== this) {
66
+ const blurred = getActiveTarget(this.ownerDocument);
67
+ if (blurred !== this) {
68
68
  return;
69
69
  }
70
70
  const thisCall = Symbol('blur call');
71
71
  activeCall = thisCall;
72
72
  blur.call(this);
73
- dispatchDOMEvent(blured, 'blur', {
73
+ dispatchDOMEvent(blurred, 'blur', {
74
74
  relatedTarget: null
75
75
  });
76
- dispatchDOMEvent(blured, 'focusout', {
76
+ dispatchDOMEvent(blurred, 'focusout', {
77
77
  relatedTarget: null
78
78
  });
79
79
  }
@@ -9,12 +9,12 @@ import { behavior } from './registry.js';
9
9
  behavior.click = (event, target, instance)=>{
10
10
  const context = target.closest('button,input,label,select,textarea');
11
11
  const control = context && isElementType(context, 'label') && context.control;
12
- if (control) {
12
+ if (control && control !== target) {
13
13
  return ()=>{
14
14
  if (isFocusable(control)) {
15
15
  focusElement(control);
16
+ instance.dispatchEvent(control, cloneEvent(event));
16
17
  }
17
- instance.dispatchEvent(control, cloneEvent(event));
18
18
  };
19
19
  } else if (isElementType(target, 'input', {
20
20
  type: 'file'
@@ -24,7 +24,7 @@ const keydownBehavior = {
24
24
  /* istanbul ignore else */ if (isElementType(target, 'input', {
25
25
  type: 'radio'
26
26
  })) {
27
- return ()=>walkRadio(instance, target, -1);
27
+ return ()=>walkRadio(instance, target, 1);
28
28
  }
29
29
  },
30
30
  ArrowLeft: (event, target, instance)=>{
@@ -47,7 +47,7 @@ const keydownBehavior = {
47
47
  /* istanbul ignore else */ if (isElementType(target, 'input', {
48
48
  type: 'radio'
49
49
  })) {
50
- return ()=>walkRadio(instance, target, 1);
50
+ return ()=>walkRadio(instance, target, -1);
51
51
  }
52
52
  },
53
53
  Backspace: (event, target, instance)=>{
@@ -17,18 +17,18 @@ const eventInitializer = {
17
17
  ],
18
18
  MouseEvent: [
19
19
  initUIEvent,
20
- initUIEventModififiers,
20
+ initUIEventModifiers,
21
21
  initMouseEvent
22
22
  ],
23
23
  PointerEvent: [
24
24
  initUIEvent,
25
- initUIEventModififiers,
25
+ initUIEventModifiers,
26
26
  initMouseEvent,
27
27
  initPointerEvent
28
28
  ],
29
29
  KeyboardEvent: [
30
30
  initUIEvent,
31
- initUIEventModififiers,
31
+ initUIEventModifiers,
32
32
  initKeyboardEvent
33
33
  ]
34
34
  };
@@ -136,7 +136,7 @@ function initUIEvent(event, { view, detail }) {
136
136
  detail: sanitizeNumber(detail !== null && detail !== undefined ? detail : 0)
137
137
  });
138
138
  }
139
- function initUIEventModififiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
139
+ function initUIEventModifiers(event, { altKey, ctrlKey, metaKey, shiftKey, modifierAltGraph, modifierCapsLock, modifierFn, modifierFnLock, modifierNumLock, modifierScrollLock, modifierSymbol, modifierSymbolLock }) {
140
140
  assignProps(event, {
141
141
  altKey: Boolean(altKey),
142
142
  ctrlKey: Boolean(ctrlKey),
@@ -190,8 +190,8 @@ function initMouseEvent(event, { x, y, screenX, screenY, clientX = x, clientY =
190
190
  function initPointerEvent(event, { pointerId, width, height, pressure, tangentialPressure, tiltX, tiltY, twist, pointerType, isPrimary }) {
191
191
  assignProps(event, {
192
192
  pointerId: sanitizeNumber(pointerId),
193
- width: sanitizeNumber(width),
194
- height: sanitizeNumber(height),
193
+ width: sanitizeNumber(width !== null && width !== undefined ? width : 1),
194
+ height: sanitizeNumber(height !== null && height !== undefined ? height : 1),
195
195
  pressure: sanitizeNumber(pressure),
196
196
  tangentialPressure: sanitizeNumber(tangentialPressure),
197
197
  tiltX: sanitizeNumber(tiltX),
@@ -18,6 +18,7 @@ function walkRadio(instance, el, direction) {
18
18
  }
19
19
  focusElement(group[i]);
20
20
  instance.dispatchUIEvent(group[i], 'click');
21
+ return;
21
22
  }
22
23
  }
23
24
 
@@ -3,7 +3,7 @@ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
3
3
  /**
4
4
  * Mapping for a default US-104-QWERTY keyboard
5
5
  */ const defaultKeyMap = [
6
- // alphanumeric keys
6
+ // alphanumeric block - writing system
7
7
  ...'0123456789'.split('').map((c)=>({
8
8
  code: `Digit${c}`,
9
9
  key: c
@@ -22,6 +22,24 @@ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
22
22
  key: c,
23
23
  shiftKey: true
24
24
  })),
25
+ {
26
+ code: 'BracketLeft',
27
+ key: '['
28
+ },
29
+ {
30
+ code: 'BracketLeft',
31
+ key: '{',
32
+ shiftKey: true
33
+ },
34
+ {
35
+ code: 'BracketRight',
36
+ key: ']'
37
+ },
38
+ {
39
+ code: 'BracketRight',
40
+ key: '}',
41
+ shiftKey: true
42
+ },
25
43
  // alphanumeric block - functional
26
44
  {
27
45
  code: 'Space',
@@ -77,6 +95,10 @@ import { DOM_KEY_LOCATION } from '../system/keyboard.js';
77
95
  key: 'OS',
78
96
  location: DOM_KEY_LOCATION.RIGHT
79
97
  },
98
+ {
99
+ code: 'ContextMenu',
100
+ key: 'ContextMenu'
101
+ },
80
102
  {
81
103
  code: 'Tab',
82
104
  key: 'Tab'
@@ -2,7 +2,7 @@ import '../utils/dataTransfer/Clipboard.js';
2
2
  import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
3
3
 
4
4
  /**
5
- * Parse key defintions per `keyboardMap`
5
+ * Parse key definitions per `keyboardMap`
6
6
  *
7
7
  * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
8
8
  * Everything else will be interpreted as a typed character - e.g. `a`.
@@ -21,18 +21,21 @@ class PointerHost {
21
21
  return this.devices.get(keyDef.pointerType).isPressed(keyDef);
22
22
  }
23
23
  async press(instance, keyDef, position) {
24
+ this.devices.get(keyDef.pointerType).addPressed(keyDef);
25
+ this.buttons.down(keyDef);
24
26
  const pointerName = this.getPointerName(keyDef);
25
- const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(instance, position) : this.pointers.get(pointerName);
27
+ const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef.pointerType, this.buttons) : this.pointers.get(pointerName);
26
28
  // TODO: deprecate the following implicit setting of position
27
29
  pointer.position = position;
28
30
  if (pointer.pointerType !== 'touch') {
29
31
  this.mouse.position = position;
30
32
  }
31
- this.devices.get(keyDef.pointerType).addPressed(keyDef);
32
- this.buttons.down(keyDef);
33
- pointer.down(instance, keyDef);
34
- if (pointer.pointerType !== 'touch' && !pointer.isPrevented) {
35
- this.mouse.down(instance, keyDef, pointer);
33
+ if (pointer.pointerType === 'touch') {
34
+ pointer.init(instance);
35
+ }
36
+ pointer.down(instance, keyDef.button);
37
+ if (pointer.pointerType !== 'touch') {
38
+ this.mouse.down(instance, keyDef, pointer.isPrevented);
36
39
  }
37
40
  }
38
41
  async move(instance, pointerName, position) {
@@ -42,7 +45,7 @@ class PointerHost {
42
45
  // While the order of mouse (or pointer) events is defined per spec,
43
46
  // the order in which they interweave/follow on a user interaction depends on the implementation.
44
47
  const pointermove = pointer.move(instance, position);
45
- const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(instance, position);
48
+ const mousemove = pointer.pointerType === 'touch' ? undefined : this.mouse.move(instance, position, pointer.isPrevented);
46
49
  pointermove === null || pointermove === undefined ? undefined : pointermove.leave();
47
50
  mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
48
51
  pointermove === null || pointermove === undefined ? undefined : pointermove.enter();
@@ -55,32 +58,31 @@ class PointerHost {
55
58
  device.removePressed(keyDef);
56
59
  this.buttons.up(keyDef);
57
60
  const pointer = this.pointers.get(this.getPointerName(keyDef));
61
+ const isPrevented = pointer.isPrevented;
58
62
  // TODO: deprecate the following implicit setting of position
59
63
  pointer.position = position;
60
64
  if (pointer.pointerType !== 'touch') {
61
65
  this.mouse.position = position;
62
66
  }
63
67
  if (device.countPressed === 0) {
64
- pointer.up(instance, keyDef);
68
+ pointer.up(instance, keyDef.button);
65
69
  }
66
70
  if (pointer.pointerType === 'touch') {
67
71
  pointer.release(instance);
68
72
  }
69
- if (!pointer.isPrevented) {
70
- if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
71
- const mousemove = this.mouse.move(instance, pointer.position);
72
- mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
73
- mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
74
- mousemove === null || mousemove === undefined ? undefined : mousemove.move();
75
- this.mouse.down(instance, keyDef, pointer);
76
- }
77
- if (!pointer.isMultitouch) {
78
- const mousemove = this.mouse.move(instance, pointer.position);
79
- mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
80
- mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
81
- mousemove === null || mousemove === undefined ? undefined : mousemove.move();
82
- this.mouse.up(instance, keyDef, pointer);
83
- }
73
+ if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
74
+ const mousemove = this.mouse.move(instance, position, isPrevented);
75
+ mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
76
+ mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
77
+ mousemove === null || mousemove === undefined ? undefined : mousemove.move();
78
+ this.mouse.down(instance, keyDef, isPrevented);
79
+ }
80
+ if (!pointer.isMultitouch) {
81
+ const mousemove = this.mouse.move(instance, position, isPrevented);
82
+ mousemove === null || mousemove === undefined ? undefined : mousemove.leave();
83
+ mousemove === null || mousemove === undefined ? undefined : mousemove.enter();
84
+ mousemove === null || mousemove === undefined ? undefined : mousemove.move();
85
+ this.mouse.up(instance, keyDef, isPrevented);
84
86
  }
85
87
  }
86
88
  getPointerName(keyDef) {
@@ -115,20 +117,20 @@ class PointerHost {
115
117
  }
116
118
  }());
117
119
  _define_property(this, "pointers", new class {
118
- new(pointerName, keyDef) {
119
- const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
120
+ new(pointerName, pointerType, buttons) {
121
+ const isPrimary = pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
120
122
  if (!isPrimary) {
121
123
  Object.values(this.registry).forEach((p)=>{
122
- if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
124
+ if (p.pointerType === pointerType && !p.isCancelled) {
123
125
  p.isMultitouch = true;
124
126
  }
125
127
  });
126
128
  }
127
129
  this.registry[pointerName] = new Pointer({
128
130
  pointerId: this.nextId++,
129
- pointerType: keyDef.pointerType,
131
+ pointerType,
130
132
  isPrimary
131
- });
133
+ }, buttons);
132
134
  return this.registry[pointerName];
133
135
  }
134
136
  get(pointerName) {
@@ -141,19 +143,14 @@ class PointerHost {
141
143
  return pointerName in this.registry;
142
144
  }
143
145
  constructor(){
144
- _define_property(this, "registry", {
145
- mouse: new Pointer({
146
- pointerId: 1,
147
- pointerType: 'mouse',
148
- isPrimary: true
149
- })
150
- });
151
- _define_property(this, "nextId", 2);
146
+ _define_property(this, "registry", {});
147
+ _define_property(this, "nextId", 1);
152
148
  }
153
149
  }());
154
150
  this.system = system;
155
151
  this.buttons = new Buttons();
156
152
  this.mouse = new Mouse();
153
+ this.pointers.new('mouse', 'mouse', this.buttons);
157
154
  }
158
155
  }
159
156
 
@@ -30,7 +30,7 @@ function _define_property(obj, key, value) {
30
30
  /**
31
31
  * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
32
32
  */ class Mouse {
33
- move(instance, position) {
33
+ move(instance, position, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
34
34
  const prevPosition = this.position;
35
35
  const prevTarget = this.getTarget(instance);
36
36
  this.position = position;
@@ -54,40 +54,46 @@ function _define_property(obj, key, value) {
54
54
  }
55
55
  },
56
56
  move: ()=>{
57
+ if (isPrevented) {
58
+ return;
59
+ }
57
60
  instance.dispatchUIEvent(nextTarget, 'mousemove', init);
58
61
  this.modifySelecting(instance);
59
62
  }
60
63
  };
61
64
  }
62
- down(instance, keyDef, pointer) {
65
+ down(instance, keyDef, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
63
66
  const button = this.buttons.down(keyDef);
64
67
  if (button === undefined) {
65
68
  return;
66
69
  }
67
70
  const target = this.getTarget(instance);
68
71
  this.buttonDownTarget[button] = target;
69
- const disabled = isDisabled(target);
70
72
  const init = this.getEventInit('mousedown', keyDef.button);
71
- if (disabled || instance.dispatchUIEvent(target, 'mousedown', init)) {
73
+ const disabled = isDisabled(target);
74
+ if (!isPrevented && (disabled || instance.dispatchUIEvent(target, 'mousedown', init))) {
72
75
  this.startSelecting(instance, init.detail);
73
76
  focusElement(target);
74
77
  }
75
78
  if (!disabled && getMouseEventButton(keyDef.button) === 2) {
76
- instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button, pointer));
79
+ instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button));
77
80
  }
78
81
  }
79
- up(instance, keyDef, pointer) {
82
+ up(instance, keyDef, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
80
83
  const button = this.buttons.up(keyDef);
81
84
  if (button === undefined) {
82
85
  return;
83
86
  }
84
87
  const target = this.getTarget(instance);
85
88
  if (!isDisabled(target)) {
86
- instance.dispatchUIEvent(target, 'mouseup', this.getEventInit('mouseup', keyDef.button));
87
- this.endSelecting();
89
+ if (!isPrevented) {
90
+ const mouseUpInit = this.getEventInit('mouseup', keyDef.button);
91
+ instance.dispatchUIEvent(target, 'mouseup', mouseUpInit);
92
+ this.endSelecting();
93
+ }
88
94
  const clickTarget = getTreeDiff(this.buttonDownTarget[button], target)[2][0];
89
95
  if (clickTarget) {
90
- const init = this.getEventInit('click', keyDef.button, pointer);
96
+ const init = this.getEventInit('click', keyDef.button);
91
97
  if (init.detail) {
92
98
  instance.dispatchUIEvent(clickTarget, init.button === 0 ? 'click' : 'auxclick', init);
93
99
  if (init.button === 0 && init.detail === 2) {
@@ -103,15 +109,10 @@ function _define_property(obj, key, value) {
103
109
  resetClickCount() {
104
110
  this.clickCount.reset();
105
111
  }
106
- getEventInit(type, button, pointer) {
112
+ getEventInit(type, button) {
107
113
  const init = {
108
114
  ...this.position.coords
109
115
  };
110
- if (pointer) {
111
- init.pointerId = pointer.pointerId;
112
- init.pointerType = pointer.pointerType;
113
- init.isPrimary = pointer.isPrimary;
114
- }
115
116
  init.button = getMouseEventButton(button);
116
117
  init.buttons = this.buttons.getButtons();
117
118
  if (type === 'mousedown') {
@@ -2,6 +2,7 @@ import '../../utils/dataTransfer/Clipboard.js';
2
2
  import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
3
3
  import { assertPointerEvents, hasPointerEvents } from '../../utils/pointer/cssPointerEvents.js';
4
4
  import { isDifferentPointerPosition } from './shared.js';
5
+ import { getMouseEventButton } from './buttons.js';
5
6
 
6
7
  function _define_property(obj, key, value) {
7
8
  if (key in obj) {
@@ -17,8 +18,7 @@ function _define_property(obj, key, value) {
17
18
  return obj;
18
19
  }
19
20
  class Pointer {
20
- init(instance, position) {
21
- this.position = position;
21
+ init(instance) {
22
22
  const target = this.getTarget(instance);
23
23
  const [, enter] = getTreeDiff(null, target);
24
24
  const init = this.getEventInit();
@@ -35,7 +35,7 @@ class Pointer {
35
35
  return;
36
36
  }
37
37
  const nextTarget = this.getTarget(instance);
38
- const init = this.getEventInit();
38
+ const init = this.getEventInit(-1);
39
39
  const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
40
40
  return {
41
41
  leave: ()=>{
@@ -58,23 +58,24 @@ class Pointer {
58
58
  }
59
59
  };
60
60
  }
61
- down(instance, _keyDef) {
61
+ down(instance, button = 0) {
62
62
  if (this.isDown) {
63
63
  return;
64
64
  }
65
65
  const target = this.getTarget(instance);
66
66
  assertPointerEvents(instance, target);
67
67
  this.isDown = true;
68
- this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit());
68
+ this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit(button));
69
69
  }
70
- up(instance, _keyDef) {
70
+ up(instance, button = 0) {
71
71
  if (!this.isDown) {
72
72
  return;
73
73
  }
74
74
  const target = this.getTarget(instance);
75
75
  assertPointerEvents(instance, target);
76
+ this.isPrevented = false;
76
77
  this.isDown = false;
77
- instance.dispatchUIEvent(target, 'pointerup', this.getEventInit());
78
+ instance.dispatchUIEvent(target, 'pointerup', this.getEventInit(button));
78
79
  }
79
80
  release(instance) {
80
81
  const target = this.getTarget(instance);
@@ -92,18 +93,26 @@ class Pointer {
92
93
  var _this_position_target;
93
94
  return (_this_position_target = this.position.target) !== null && _this_position_target !== undefined ? _this_position_target : instance.config.document.body;
94
95
  }
95
- getEventInit() {
96
+ getEventInit(/**
97
+ * The `button` that caused the event.
98
+ *
99
+ * This should be `-1` if the event is not caused by a button or touch/pen contact,
100
+ * e.g. a moving pointer.
101
+ */ button) {
96
102
  return {
97
103
  ...this.position.coords,
98
104
  pointerId: this.pointerId,
99
105
  pointerType: this.pointerType,
100
- isPrimary: this.isPrimary
106
+ isPrimary: this.isPrimary,
107
+ button: getMouseEventButton(button),
108
+ buttons: this.buttons.getButtons()
101
109
  };
102
110
  }
103
- constructor({ pointerId, pointerType, isPrimary }){
111
+ constructor({ pointerId, pointerType, isPrimary }, buttons){
104
112
  _define_property(this, "pointerId", undefined);
105
113
  _define_property(this, "pointerType", undefined);
106
114
  _define_property(this, "isPrimary", undefined);
115
+ _define_property(this, "buttons", undefined);
107
116
  _define_property(this, "isMultitouch", false);
108
117
  _define_property(this, "isCancelled", false);
109
118
  _define_property(this, "isDown", false);
@@ -113,6 +122,7 @@ class Pointer {
113
122
  this.pointerType = pointerType;
114
123
  this.isPrimary = isPrimary;
115
124
  this.isMultitouch = !isPrimary;
125
+ this.buttons = buttons;
116
126
  }
117
127
  }
118
128
 
@@ -33,6 +33,10 @@ async function upload(element, fileOrFiles) {
33
33
  await this.click(element);
34
34
  input.removeEventListener('fileDialog', fileDialog);
35
35
  }
36
+ // When matching files, browsers ignore case and consider jpeg/jpg interchangeable.
37
+ function normalize(nameOrType) {
38
+ return nameOrType.toLowerCase().replace(/(\.|\/)jpg\b/g, '$1jpeg');
39
+ }
36
40
  function isAcceptableFile(file, accept) {
37
41
  if (!accept) {
38
42
  return true;
@@ -42,14 +46,14 @@ function isAcceptableFile(file, accept) {
42
46
  'image/*',
43
47
  'video/*'
44
48
  ];
45
- return accept.split(',').some((acceptToken)=>{
49
+ return normalize(accept).trim().split(/\s*,\s*/).some((acceptToken)=>{
50
+ // tokens starting with a dot represent a file extension
46
51
  if (acceptToken.startsWith('.')) {
47
- // tokens starting with a dot represent a file extension
48
- return file.name.endsWith(acceptToken);
52
+ return normalize(file.name).endsWith(acceptToken);
49
53
  } else if (wildcards.includes(acceptToken)) {
50
- return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
54
+ return normalize(file.type).startsWith(acceptToken.replace('*', ''));
51
55
  }
52
- return file.type === acceptToken;
56
+ return normalize(file.type) === acceptToken;
53
57
  });
54
58
  }
55
59
 
@@ -7,7 +7,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
7
7
  // Firefox always moves to zero offset and jumps over last offset.
8
8
  // Chrome jumps over zero offset per default but over last offset when Shift is pressed.
9
9
  // The cursor always moves to zero offset if the focus area (contenteditable or body) ends there.
10
- // When walking foward both ignore zero offset.
10
+ // When walking forward both ignore zero offset.
11
11
  // When walking over input elements the cursor moves before or after that element.
12
12
  // When walking over line breaks the cursor moves inside any following text node.
13
13
  if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
@@ -1,6 +1,6 @@
1
1
  import { keyboardKey } from '../system/keyboard';
2
2
  /**
3
- * Parse key defintions per `keyboardMap`
3
+ * Parse key definitions per `keyboardMap`
4
4
  *
5
5
  * Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
6
6
  * Everything else will be interpreted as a typed character - e.g. `a`.
@@ -33,7 +33,7 @@ export interface Options {
33
33
  autoModify?: boolean;
34
34
  /**
35
35
  * Between some subsequent inputs like typing a series of characters
36
- * the code execution is delayed per `setTimeout` for (at least) `delay` seconds.
36
+ * the code execution is delayed per `setTimeout` for (at least) `delay` milliseconds.
37
37
  * This moves the next changes at least to next macro task
38
38
  * and allows other (asynchronous) code to run between events.
39
39
  *
@@ -1,5 +1,4 @@
1
1
  import { type Instance } from '../../setup';
2
- import { type Pointer } from './pointer';
3
2
  import { pointerKey, PointerPosition } from './shared';
4
3
  /**
5
4
  * This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
@@ -10,13 +9,19 @@ export declare class Mouse {
10
9
  private selecting?;
11
10
  private buttonDownTarget;
12
11
  private readonly clickCount;
13
- move(instance: Instance, position: PointerPosition): {
12
+ move(instance: Instance, position: PointerPosition,
13
+ /** Whether `preventDefault()` has been called on the `pointerdown` event */
14
+ isPrevented: boolean): {
14
15
  leave: () => void;
15
16
  enter: () => void;
16
17
  move: () => void;
17
18
  } | undefined;
18
- down(instance: Instance, keyDef: pointerKey, pointer: Pointer): void;
19
- up(instance: Instance, keyDef: pointerKey, pointer: Pointer): void;
19
+ down(instance: Instance, keyDef: pointerKey,
20
+ /** Whether `preventDefault()` has been called on the `pointerdown` event */
21
+ isPrevented: boolean): void;
22
+ up(instance: Instance, keyDef: pointerKey,
23
+ /** Whether `preventDefault()` has been called on the `pointerdown` event */
24
+ isPrevented: boolean): void;
20
25
  resetClickCount(): void;
21
26
  private getEventInit;
22
27
  private getTarget;
@@ -1,28 +1,30 @@
1
1
  import { type Instance } from '../../setup';
2
- import { pointerKey, PointerPosition } from './shared';
2
+ import { PointerPosition } from './shared';
3
+ import { Buttons, MouseButton } from './buttons';
3
4
  type PointerInit = {
4
5
  pointerId: number;
5
6
  pointerType: string;
6
7
  isPrimary: boolean;
7
8
  };
8
9
  export declare class Pointer {
9
- constructor({ pointerId, pointerType, isPrimary }: PointerInit);
10
+ constructor({ pointerId, pointerType, isPrimary }: PointerInit, buttons: Buttons);
10
11
  readonly pointerId: number;
11
12
  readonly pointerType: string;
12
13
  readonly isPrimary: boolean;
14
+ readonly buttons: Buttons;
13
15
  isMultitouch: boolean;
14
16
  isCancelled: boolean;
15
17
  isDown: boolean;
16
18
  isPrevented: boolean;
17
19
  position: PointerPosition;
18
- init(instance: Instance, position: PointerPosition): this;
20
+ init(instance: Instance): this;
19
21
  move(instance: Instance, position: PointerPosition): {
20
22
  leave: () => void;
21
23
  enter: () => void;
22
24
  move: () => void;
23
25
  } | undefined;
24
- down(instance: Instance, _keyDef: pointerKey): void;
25
- up(instance: Instance, _keyDef: pointerKey): void;
26
+ down(instance: Instance, button?: MouseButton): void;
27
+ up(instance: Instance, button?: MouseButton): void;
26
28
  release(instance: Instance): void;
27
29
  private getTarget;
28
30
  private getEventInit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.6.0",
3
+ "version": "14.6.1",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",