@depup/testing-library__user-event 14.6.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/cjs/clipboard/copy.js +22 -0
- package/dist/cjs/clipboard/cut.js +22 -0
- package/dist/cjs/clipboard/index.js +11 -0
- package/dist/cjs/clipboard/paste.js +24 -0
- package/dist/cjs/convenience/click.js +35 -0
- package/dist/cjs/convenience/hover.js +19 -0
- package/dist/cjs/convenience/index.js +14 -0
- package/dist/cjs/convenience/tab.js +7 -0
- package/dist/cjs/document/UI.js +90 -0
- package/dist/cjs/document/copySelection.js +29 -0
- package/dist/cjs/document/getValueOrTextContent.js +18 -0
- package/dist/cjs/document/index.js +17 -0
- package/dist/cjs/document/interceptor.js +104 -0
- package/dist/cjs/document/patchFocus.js +106 -0
- package/dist/cjs/document/prepareDocument.js +58 -0
- package/dist/cjs/document/trackValue.js +57 -0
- package/dist/cjs/event/behavior/click.js +32 -0
- package/dist/cjs/event/behavior/cut.js +14 -0
- package/dist/cjs/event/behavior/index.js +13 -0
- package/dist/cjs/event/behavior/keydown.js +128 -0
- package/dist/cjs/event/behavior/keypress.js +51 -0
- package/dist/cjs/event/behavior/keyup.js +17 -0
- package/dist/cjs/event/behavior/paste.js +18 -0
- package/dist/cjs/event/behavior/registry.js +5 -0
- package/dist/cjs/event/createEvent.js +193 -0
- package/dist/cjs/event/dispatchEvent.js +54 -0
- package/dist/cjs/event/eventMap.js +281 -0
- package/dist/cjs/event/focus.js +34 -0
- package/dist/cjs/event/index.js +22 -0
- package/dist/cjs/event/input.js +158 -0
- package/dist/cjs/event/radio.js +27 -0
- package/dist/cjs/event/selection/getInputRange.js +18 -0
- package/dist/cjs/event/selection/getTargetTypeAndSelection.js +31 -0
- package/dist/cjs/event/selection/index.js +24 -0
- package/dist/cjs/event/selection/modifySelection.js +21 -0
- package/dist/cjs/event/selection/modifySelectionPerMouse.js +40 -0
- package/dist/cjs/event/selection/moveSelection.js +38 -0
- package/dist/cjs/event/selection/resolveCaretPosition.js +60 -0
- package/dist/cjs/event/selection/selectAll.js +38 -0
- package/dist/cjs/event/selection/setSelection.js +21 -0
- package/dist/cjs/event/selection/setSelectionPerMouse.js +79 -0
- package/dist/cjs/event/selection/setSelectionRange.js +31 -0
- package/dist/cjs/event/selection/updateSelectionOnFocus.js +40 -0
- package/dist/cjs/event/types.js +2 -0
- package/dist/cjs/event/wrapEvent.js +10 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/keyboard/index.js +40 -0
- package/dist/cjs/keyboard/keyMap.js +178 -0
- package/dist/cjs/keyboard/parseKeyDef.js +45 -0
- package/dist/cjs/options.js +14 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pointer/index.js +74 -0
- package/dist/cjs/pointer/keyMap.js +33 -0
- package/dist/cjs/pointer/parseKeyDef.js +23 -0
- package/dist/cjs/setup/api.js +35 -0
- package/dist/cjs/setup/directApi.js +75 -0
- package/dist/cjs/setup/index.js +11 -0
- package/dist/cjs/setup/setup.js +125 -0
- package/dist/cjs/setup/wrapAsync.js +11 -0
- package/dist/cjs/system/index.js +42 -0
- package/dist/cjs/system/keyboard.js +165 -0
- package/dist/cjs/system/pointer/buttons.js +80 -0
- package/dist/cjs/system/pointer/device.js +32 -0
- package/dist/cjs/system/pointer/index.js +156 -0
- package/dist/cjs/system/pointer/mouse.js +204 -0
- package/dist/cjs/system/pointer/pointer.js +129 -0
- package/dist/cjs/system/pointer/shared.js +8 -0
- package/dist/cjs/utility/clear.js +32 -0
- package/dist/cjs/utility/index.js +14 -0
- package/dist/cjs/utility/selectOptions.js +114 -0
- package/dist/cjs/utility/type.js +23 -0
- package/dist/cjs/utility/upload.js +62 -0
- package/dist/cjs/utils/click/isClickableInput.js +20 -0
- package/dist/cjs/utils/dataTransfer/Blob.js +16 -0
- package/dist/cjs/utils/dataTransfer/Clipboard.js +174 -0
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +134 -0
- package/dist/cjs/utils/dataTransfer/FileList.js +24 -0
- package/dist/cjs/utils/edit/isContentEditable.js +18 -0
- package/dist/cjs/utils/edit/isEditable.js +29 -0
- package/dist/cjs/utils/edit/maxLength.js +26 -0
- package/dist/cjs/utils/edit/setFiles.js +58 -0
- package/dist/cjs/utils/edit/timeValue.js +40 -0
- package/dist/cjs/utils/focus/cursor.js +126 -0
- package/dist/cjs/utils/focus/getActiveElement.js +25 -0
- package/dist/cjs/utils/focus/getTabDestination.js +80 -0
- package/dist/cjs/utils/focus/isFocusable.js +9 -0
- package/dist/cjs/utils/focus/selection.js +20 -0
- package/dist/cjs/utils/focus/selector.js +15 -0
- package/dist/cjs/utils/index.js +78 -0
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +91 -0
- package/dist/cjs/utils/misc/cloneEvent.js +7 -0
- package/dist/cjs/utils/misc/findClosest.js +14 -0
- package/dist/cjs/utils/misc/getDocumentFromNode.js +10 -0
- package/dist/cjs/utils/misc/getTreeDiff.js +25 -0
- package/dist/cjs/utils/misc/getWindow.js +19 -0
- package/dist/cjs/utils/misc/isDescendantOrSelf.js +14 -0
- package/dist/cjs/utils/misc/isDisabled.js +33 -0
- package/dist/cjs/utils/misc/isElementType.js +20 -0
- package/dist/cjs/utils/misc/isVisible.js +19 -0
- package/dist/cjs/utils/misc/level.js +17 -0
- package/dist/cjs/utils/misc/wait.js +14 -0
- package/dist/cjs/utils/pointer/cssPointerEvents.js +102 -0
- package/dist/esm/clipboard/copy.js +20 -0
- package/dist/esm/clipboard/cut.js +20 -0
- package/dist/esm/clipboard/index.js +3 -0
- package/dist/esm/clipboard/paste.js +22 -0
- package/dist/esm/convenience/click.js +31 -0
- package/dist/esm/convenience/hover.js +16 -0
- package/dist/esm/convenience/index.js +3 -0
- package/dist/esm/convenience/tab.js +5 -0
- package/dist/esm/document/UI.js +77 -0
- package/dist/esm/document/copySelection.js +27 -0
- package/dist/esm/document/getValueOrTextContent.js +16 -0
- package/dist/esm/document/index.js +4 -0
- package/dist/esm/document/interceptor.js +99 -0
- package/dist/esm/document/patchFocus.js +103 -0
- package/dist/esm/document/prepareDocument.js +56 -0
- package/dist/esm/document/trackValue.js +53 -0
- package/dist/esm/event/behavior/click.js +30 -0
- package/dist/esm/event/behavior/cut.js +12 -0
- package/dist/esm/event/behavior/index.js +7 -0
- package/dist/esm/event/behavior/keydown.js +126 -0
- package/dist/esm/event/behavior/keypress.js +49 -0
- package/dist/esm/event/behavior/keyup.js +15 -0
- package/dist/esm/event/behavior/paste.js +16 -0
- package/dist/esm/event/behavior/registry.js +3 -0
- package/dist/esm/event/createEvent.js +191 -0
- package/dist/esm/event/dispatchEvent.js +50 -0
- package/dist/esm/event/eventMap.js +277 -0
- package/dist/esm/event/focus.js +31 -0
- package/dist/esm/event/index.js +7 -0
- package/dist/esm/event/input.js +156 -0
- package/dist/esm/event/radio.js +25 -0
- package/dist/esm/event/selection/getInputRange.js +16 -0
- package/dist/esm/event/selection/getTargetTypeAndSelection.js +29 -0
- package/dist/esm/event/selection/index.js +9 -0
- package/dist/esm/event/selection/modifySelection.js +19 -0
- package/dist/esm/event/selection/modifySelectionPerMouse.js +38 -0
- package/dist/esm/event/selection/moveSelection.js +36 -0
- package/dist/esm/event/selection/resolveCaretPosition.js +58 -0
- package/dist/esm/event/selection/selectAll.js +35 -0
- package/dist/esm/event/selection/setSelection.js +19 -0
- package/dist/esm/event/selection/setSelectionPerMouse.js +77 -0
- package/dist/esm/event/selection/setSelectionRange.js +29 -0
- package/dist/esm/event/selection/updateSelectionOnFocus.js +38 -0
- package/dist/esm/event/types.js +1 -0
- package/dist/esm/event/wrapEvent.js +8 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/keyboard/index.js +37 -0
- package/dist/esm/keyboard/keyMap.js +176 -0
- package/dist/esm/keyboard/parseKeyDef.js +43 -0
- package/dist/esm/options.js +12 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pointer/index.js +72 -0
- package/dist/esm/pointer/keyMap.js +31 -0
- package/dist/esm/pointer/parseKeyDef.js +21 -0
- package/dist/esm/setup/api.js +33 -0
- package/dist/esm/setup/directApi.js +58 -0
- package/dist/esm/setup/index.js +9 -0
- package/dist/esm/setup/setup.js +119 -0
- package/dist/esm/setup/wrapAsync.js +9 -0
- package/dist/esm/system/index.js +40 -0
- package/dist/esm/system/keyboard.js +162 -0
- package/dist/esm/system/pointer/buttons.js +74 -0
- package/dist/esm/system/pointer/device.js +30 -0
- package/dist/esm/system/pointer/index.js +154 -0
- package/dist/esm/system/pointer/mouse.js +202 -0
- package/dist/esm/system/pointer/pointer.js +127 -0
- package/dist/esm/system/pointer/shared.js +6 -0
- package/dist/esm/utility/clear.js +30 -0
- package/dist/esm/utility/index.js +4 -0
- package/dist/esm/utility/selectOptions.js +111 -0
- package/dist/esm/utility/type.js +21 -0
- package/dist/esm/utility/upload.js +60 -0
- package/dist/esm/utils/click/isClickableInput.js +18 -0
- package/dist/esm/utils/dataTransfer/Blob.js +14 -0
- package/dist/esm/utils/dataTransfer/Clipboard.js +167 -0
- package/dist/esm/utils/dataTransfer/DataTransfer.js +131 -0
- package/dist/esm/utils/dataTransfer/FileList.js +22 -0
- package/dist/esm/utils/edit/isContentEditable.js +15 -0
- package/dist/esm/utils/edit/isEditable.js +26 -0
- package/dist/esm/utils/edit/maxLength.js +23 -0
- package/dist/esm/utils/edit/setFiles.js +56 -0
- package/dist/esm/utils/edit/timeValue.js +37 -0
- package/dist/esm/utils/focus/cursor.js +124 -0
- package/dist/esm/utils/focus/getActiveElement.js +22 -0
- package/dist/esm/utils/focus/getTabDestination.js +78 -0
- package/dist/esm/utils/focus/isFocusable.js +7 -0
- package/dist/esm/utils/focus/selection.js +17 -0
- package/dist/esm/utils/focus/selector.js +13 -0
- package/dist/esm/utils/index.js +29 -0
- package/dist/esm/utils/keyDef/readNextDescriptor.js +89 -0
- package/dist/esm/utils/misc/cloneEvent.js +5 -0
- package/dist/esm/utils/misc/findClosest.js +12 -0
- package/dist/esm/utils/misc/getDocumentFromNode.js +8 -0
- package/dist/esm/utils/misc/getTreeDiff.js +23 -0
- package/dist/esm/utils/misc/getWindow.js +17 -0
- package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
- package/dist/esm/utils/misc/isDisabled.js +31 -0
- package/dist/esm/utils/misc/isElementType.js +18 -0
- package/dist/esm/utils/misc/isVisible.js +17 -0
- package/dist/esm/utils/misc/level.js +13 -0
- package/dist/esm/utils/misc/wait.js +12 -0
- package/dist/esm/utils/pointer/cssPointerEvents.js +99 -0
- package/dist/types/clipboard/copy.d.ts +2 -0
- package/dist/types/clipboard/cut.d.ts +2 -0
- package/dist/types/clipboard/index.d.ts +3 -0
- package/dist/types/clipboard/paste.d.ts +2 -0
- package/dist/types/convenience/click.d.ts +4 -0
- package/dist/types/convenience/hover.d.ts +3 -0
- package/dist/types/convenience/index.d.ts +3 -0
- package/dist/types/convenience/tab.d.ts +4 -0
- package/dist/types/document/UI.d.ts +42 -0
- package/dist/types/document/copySelection.d.ts +1 -0
- package/dist/types/document/getValueOrTextContent.d.ts +1 -0
- package/dist/types/document/index.d.ts +5 -0
- package/dist/types/document/interceptor.d.ts +19 -0
- package/dist/types/document/patchFocus.d.ts +9 -0
- package/dist/types/document/prepareDocument.d.ts +8 -0
- package/dist/types/document/trackValue.d.ts +17 -0
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/cut.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +8 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/paste.d.ts +1 -0
- package/dist/types/event/behavior/registry.d.ts +8 -0
- package/dist/types/event/createEvent.d.ts +2 -0
- package/dist/types/event/dispatchEvent.d.ts +5 -0
- package/dist/types/event/eventMap.d.ts +265 -0
- package/dist/types/event/focus.d.ts +5 -0
- package/dist/types/event/index.d.ts +7 -0
- package/dist/types/event/input.d.ts +2 -0
- package/dist/types/event/radio.d.ts +4 -0
- package/dist/types/event/selection/getInputRange.d.ts +5 -0
- package/dist/types/event/selection/getTargetTypeAndSelection.d.ts +10 -0
- package/dist/types/event/selection/index.d.ts +15 -0
- package/dist/types/event/selection/modifySelection.d.ts +8 -0
- package/dist/types/event/selection/modifySelectionPerMouse.d.ts +7 -0
- package/dist/types/event/selection/moveSelection.d.ts +4 -0
- package/dist/types/event/selection/resolveCaretPosition.d.ts +8 -0
- package/dist/types/event/selection/selectAll.d.ts +5 -0
- package/dist/types/event/selection/setSelection.d.ts +10 -0
- package/dist/types/event/selection/setSelectionPerMouse.d.ts +8 -0
- package/dist/types/event/selection/setSelectionRange.d.ts +6 -0
- package/dist/types/event/selection/updateSelectionOnFocus.d.ts +5 -0
- package/dist/types/event/types.d.ts +20 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/keyboard/index.d.ts +3 -0
- package/dist/types/keyboard/keyMap.d.ts +5 -0
- package/dist/types/keyboard/parseKeyDef.d.ts +17 -0
- package/dist/types/options.d.ts +115 -0
- package/dist/types/pointer/index.d.ts +28 -0
- package/dist/types/pointer/keyMap.d.ts +2 -0
- package/dist/types/pointer/parseKeyDef.d.ts +6 -0
- package/dist/types/setup/api.d.ts +23 -0
- package/dist/types/setup/directApi.d.ts +24 -0
- package/dist/types/setup/index.d.ts +22 -0
- package/dist/types/setup/setup.d.ts +44 -0
- package/dist/types/setup/wrapAsync.d.ts +4 -0
- package/dist/types/system/index.d.ts +10 -0
- package/dist/types/system/keyboard.d.ts +50 -0
- package/dist/types/system/pointer/buttons.d.ts +23 -0
- package/dist/types/system/pointer/device.d.ts +8 -0
- package/dist/types/system/pointer/index.d.ts +21 -0
- package/dist/types/system/pointer/mouse.d.ts +31 -0
- package/dist/types/system/pointer/pointer.d.ts +32 -0
- package/dist/types/system/pointer/shared.d.ts +20 -0
- package/dist/types/utility/clear.d.ts +2 -0
- package/dist/types/utility/index.d.ts +4 -0
- package/dist/types/utility/selectOptions.d.ts +3 -0
- package/dist/types/utility/type.d.ts +9 -0
- package/dist/types/utility/upload.d.ts +5 -0
- package/dist/types/utils/click/isClickableInput.d.ts +15 -0
- package/dist/types/utils/dataTransfer/Blob.d.ts +3 -0
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +11 -0
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
- package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
- package/dist/types/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/types/utils/edit/isEditable.d.ts +24 -0
- package/dist/types/utils/edit/maxLength.d.ts +14 -0
- package/dist/types/utils/edit/setFiles.d.ts +12 -0
- package/dist/types/utils/edit/timeValue.d.ts +4 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/types/utils/focus/getActiveElement.d.ts +2 -0
- package/dist/types/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/types/utils/focus/isFocusable.d.ts +1 -0
- package/dist/types/utils/focus/selection.d.ts +8 -0
- package/dist/types/utils/focus/selector.d.ts +1 -0
- package/dist/types/utils/index.d.ts +29 -0
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +21 -0
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -0
- package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
- package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
- package/dist/types/utils/misc/getWindow.d.ts +1 -0
- package/dist/types/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/types/utils/misc/isDisabled.d.ts +1 -0
- package/dist/types/utils/misc/isElementType.d.ts +5 -0
- package/dist/types/utils/misc/isVisible.d.ts +1 -0
- package/dist/types/utils/misc/level.d.ts +8 -0
- package/dist/types/utils/misc/wait.d.ts +2 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +19 -0
- package/package.json +131 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Buttons } from './buttons.js';
|
|
2
|
+
import { Device } from './device.js';
|
|
3
|
+
import { Mouse } from './mouse.js';
|
|
4
|
+
import { Pointer } from './pointer.js';
|
|
5
|
+
|
|
6
|
+
function _define_property(obj, key, value) {
|
|
7
|
+
if (key in obj) {
|
|
8
|
+
Object.defineProperty(obj, key, {
|
|
9
|
+
value: value,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true
|
|
13
|
+
});
|
|
14
|
+
} else obj[key] = value;
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
class PointerHost {
|
|
18
|
+
isKeyPressed(keyDef) {
|
|
19
|
+
return this.devices.get(keyDef.pointerType).isPressed(keyDef);
|
|
20
|
+
}
|
|
21
|
+
async press(instance, keyDef, position) {
|
|
22
|
+
this.devices.get(keyDef.pointerType).addPressed(keyDef);
|
|
23
|
+
this.buttons.down(keyDef);
|
|
24
|
+
const pointerName = this.getPointerName(keyDef);
|
|
25
|
+
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef.pointerType, this.buttons) : this.pointers.get(pointerName);
|
|
26
|
+
// TODO: deprecate the following implicit setting of position
|
|
27
|
+
pointer.position = position;
|
|
28
|
+
if (pointer.pointerType !== 'touch') {
|
|
29
|
+
this.mouse.position = position;
|
|
30
|
+
}
|
|
31
|
+
if (pointer.pointerType === 'touch') {
|
|
32
|
+
pointer.init(instance);
|
|
33
|
+
}
|
|
34
|
+
pointer.down(instance, keyDef.button);
|
|
35
|
+
if (pointer.pointerType !== 'touch') {
|
|
36
|
+
this.mouse.down(instance, keyDef, pointer.isPrevented);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async move(instance, pointerName, position) {
|
|
40
|
+
const pointer = this.pointers.get(pointerName);
|
|
41
|
+
// In (some?) browsers this order of events can be observed.
|
|
42
|
+
// This interweaving of events is probably unnecessary.
|
|
43
|
+
// While the order of mouse (or pointer) events is defined per spec,
|
|
44
|
+
// the order in which they interweave/follow on a user interaction depends on the implementation.
|
|
45
|
+
const pointermove = pointer.move(instance, position);
|
|
46
|
+
const mousemove = pointer.pointerType === 'touch' ? undefined : this.mouse.move(instance, position, pointer.isPrevented);
|
|
47
|
+
pointermove === null || pointermove === void 0 ? void 0 : pointermove.leave();
|
|
48
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
|
|
49
|
+
pointermove === null || pointermove === void 0 ? void 0 : pointermove.enter();
|
|
50
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
|
|
51
|
+
pointermove === null || pointermove === void 0 ? void 0 : pointermove.move();
|
|
52
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
|
|
53
|
+
}
|
|
54
|
+
async release(instance, keyDef, position) {
|
|
55
|
+
const device = this.devices.get(keyDef.pointerType);
|
|
56
|
+
device.removePressed(keyDef);
|
|
57
|
+
this.buttons.up(keyDef);
|
|
58
|
+
const pointer = this.pointers.get(this.getPointerName(keyDef));
|
|
59
|
+
const isPrevented = pointer.isPrevented;
|
|
60
|
+
// TODO: deprecate the following implicit setting of position
|
|
61
|
+
pointer.position = position;
|
|
62
|
+
if (pointer.pointerType !== 'touch') {
|
|
63
|
+
this.mouse.position = position;
|
|
64
|
+
}
|
|
65
|
+
if (device.countPressed === 0) {
|
|
66
|
+
pointer.up(instance, keyDef.button);
|
|
67
|
+
}
|
|
68
|
+
if (pointer.pointerType === 'touch') {
|
|
69
|
+
pointer.release(instance);
|
|
70
|
+
}
|
|
71
|
+
if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
|
|
72
|
+
const mousemove = this.mouse.move(instance, position, isPrevented);
|
|
73
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
|
|
74
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
|
|
75
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
|
|
76
|
+
this.mouse.down(instance, keyDef, isPrevented);
|
|
77
|
+
}
|
|
78
|
+
if (!pointer.isMultitouch) {
|
|
79
|
+
const mousemove = this.mouse.move(instance, position, isPrevented);
|
|
80
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.leave();
|
|
81
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.enter();
|
|
82
|
+
mousemove === null || mousemove === void 0 ? void 0 : mousemove.move();
|
|
83
|
+
this.mouse.up(instance, keyDef, isPrevented);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
getPointerName(keyDef) {
|
|
87
|
+
return keyDef.pointerType === 'touch' ? keyDef.name : keyDef.pointerType;
|
|
88
|
+
}
|
|
89
|
+
getPreviousPosition(pointerName) {
|
|
90
|
+
return this.pointers.has(pointerName) ? this.pointers.get(pointerName).position : undefined;
|
|
91
|
+
}
|
|
92
|
+
resetClickCount() {
|
|
93
|
+
this.mouse.resetClickCount();
|
|
94
|
+
}
|
|
95
|
+
getMouseTarget(instance) {
|
|
96
|
+
var _this_mouse_position_target;
|
|
97
|
+
return (_this_mouse_position_target = this.mouse.position.target) !== null && _this_mouse_position_target !== void 0 ? _this_mouse_position_target : instance.config.document.body;
|
|
98
|
+
}
|
|
99
|
+
setMousePosition(position) {
|
|
100
|
+
this.mouse.position = position;
|
|
101
|
+
this.pointers.get('mouse').position = position;
|
|
102
|
+
}
|
|
103
|
+
constructor(system){
|
|
104
|
+
_define_property(this, "system", void 0);
|
|
105
|
+
_define_property(this, "mouse", void 0);
|
|
106
|
+
_define_property(this, "buttons", void 0);
|
|
107
|
+
_define_property(this, "devices", new class {
|
|
108
|
+
get(k) {
|
|
109
|
+
var _this_registry, _k, _;
|
|
110
|
+
return (_ = (_this_registry = this.registry)[_k = k]) !== null && _ !== void 0 ? _ : _this_registry[_k] = new Device();
|
|
111
|
+
}
|
|
112
|
+
constructor(){
|
|
113
|
+
_define_property(this, "registry", {});
|
|
114
|
+
}
|
|
115
|
+
}());
|
|
116
|
+
_define_property(this, "pointers", new class {
|
|
117
|
+
new(pointerName, pointerType, buttons) {
|
|
118
|
+
const isPrimary = pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
|
|
119
|
+
if (!isPrimary) {
|
|
120
|
+
Object.values(this.registry).forEach((p)=>{
|
|
121
|
+
if (p.pointerType === pointerType && !p.isCancelled) {
|
|
122
|
+
p.isMultitouch = true;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
this.registry[pointerName] = new Pointer({
|
|
127
|
+
pointerId: this.nextId++,
|
|
128
|
+
pointerType,
|
|
129
|
+
isPrimary
|
|
130
|
+
}, buttons);
|
|
131
|
+
return this.registry[pointerName];
|
|
132
|
+
}
|
|
133
|
+
get(pointerName) {
|
|
134
|
+
if (!this.has(pointerName)) {
|
|
135
|
+
throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
|
|
136
|
+
}
|
|
137
|
+
return this.registry[pointerName];
|
|
138
|
+
}
|
|
139
|
+
has(pointerName) {
|
|
140
|
+
return pointerName in this.registry;
|
|
141
|
+
}
|
|
142
|
+
constructor(){
|
|
143
|
+
_define_property(this, "registry", {});
|
|
144
|
+
_define_property(this, "nextId", 1);
|
|
145
|
+
}
|
|
146
|
+
}());
|
|
147
|
+
this.system = system;
|
|
148
|
+
this.buttons = new Buttons();
|
|
149
|
+
this.mouse = new Mouse();
|
|
150
|
+
this.pointers.new('mouse', 'mouse', this.buttons);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { PointerHost };
|
|
@@ -0,0 +1,202 @@
|
|
|
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 '../../utils/dataTransfer/Clipboard.js';
|
|
9
|
+
import { isDisabled } from '../../utils/misc/isDisabled.js';
|
|
10
|
+
import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
|
|
11
|
+
import { focusElement } from '../../event/focus.js';
|
|
12
|
+
import { setSelectionPerMouseDown } from '../../event/selection/setSelectionPerMouse.js';
|
|
13
|
+
import { modifySelectionPerMouseMove } from '../../event/selection/modifySelectionPerMouse.js';
|
|
14
|
+
import { getMouseEventButton, Buttons } from './buttons.js';
|
|
15
|
+
import { isDifferentPointerPosition } from './shared.js';
|
|
16
|
+
|
|
17
|
+
function _define_property(obj, key, value) {
|
|
18
|
+
if (key in obj) {
|
|
19
|
+
Object.defineProperty(obj, key, {
|
|
20
|
+
value: value,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true
|
|
24
|
+
});
|
|
25
|
+
} else obj[key] = value;
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* This object is the single "virtual" mouse that might be controlled by multiple different pointer devices.
|
|
30
|
+
*/ class Mouse {
|
|
31
|
+
move(instance, position, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
|
|
32
|
+
const prevPosition = this.position;
|
|
33
|
+
const prevTarget = this.getTarget(instance);
|
|
34
|
+
this.position = position;
|
|
35
|
+
if (!isDifferentPointerPosition(prevPosition, position)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const nextTarget = this.getTarget(instance);
|
|
39
|
+
const init = this.getEventInit('mousemove');
|
|
40
|
+
const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
|
|
41
|
+
return {
|
|
42
|
+
leave: ()=>{
|
|
43
|
+
if (prevTarget !== nextTarget) {
|
|
44
|
+
instance.dispatchUIEvent(prevTarget, 'mouseout', init);
|
|
45
|
+
leave.forEach((el)=>instance.dispatchUIEvent(el, 'mouseleave', init));
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
enter: ()=>{
|
|
49
|
+
if (prevTarget !== nextTarget) {
|
|
50
|
+
instance.dispatchUIEvent(nextTarget, 'mouseover', init);
|
|
51
|
+
enter.forEach((el)=>instance.dispatchUIEvent(el, 'mouseenter', init));
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
move: ()=>{
|
|
55
|
+
if (isPrevented) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
instance.dispatchUIEvent(nextTarget, 'mousemove', init);
|
|
59
|
+
this.modifySelecting(instance);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
down(instance, keyDef, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
|
|
64
|
+
const button = this.buttons.down(keyDef);
|
|
65
|
+
if (button === undefined) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const target = this.getTarget(instance);
|
|
69
|
+
this.buttonDownTarget[button] = target;
|
|
70
|
+
const init = this.getEventInit('mousedown', keyDef.button);
|
|
71
|
+
const disabled = isDisabled(target);
|
|
72
|
+
if (!isPrevented && (disabled || instance.dispatchUIEvent(target, 'mousedown', init))) {
|
|
73
|
+
this.startSelecting(instance, init.detail);
|
|
74
|
+
focusElement(target);
|
|
75
|
+
}
|
|
76
|
+
if (!disabled && getMouseEventButton(keyDef.button) === 2) {
|
|
77
|
+
instance.dispatchUIEvent(target, 'contextmenu', this.getEventInit('contextmenu', keyDef.button));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
up(instance, keyDef, /** Whether `preventDefault()` has been called on the `pointerdown` event */ isPrevented) {
|
|
81
|
+
const button = this.buttons.up(keyDef);
|
|
82
|
+
if (button === undefined) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const target = this.getTarget(instance);
|
|
86
|
+
if (!isDisabled(target)) {
|
|
87
|
+
if (!isPrevented) {
|
|
88
|
+
const mouseUpInit = this.getEventInit('mouseup', keyDef.button);
|
|
89
|
+
instance.dispatchUIEvent(target, 'mouseup', mouseUpInit);
|
|
90
|
+
this.endSelecting();
|
|
91
|
+
}
|
|
92
|
+
const clickTarget = getTreeDiff(this.buttonDownTarget[button], target)[2][0];
|
|
93
|
+
if (clickTarget) {
|
|
94
|
+
const init = this.getEventInit('click', keyDef.button);
|
|
95
|
+
if (init.detail) {
|
|
96
|
+
instance.dispatchUIEvent(clickTarget, init.button === 0 ? 'click' : 'auxclick', init);
|
|
97
|
+
if (init.button === 0 && init.detail === 2) {
|
|
98
|
+
instance.dispatchUIEvent(clickTarget, 'dblclick', {
|
|
99
|
+
...this.getEventInit('dblclick', keyDef.button),
|
|
100
|
+
detail: init.detail
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
resetClickCount() {
|
|
108
|
+
this.clickCount.reset();
|
|
109
|
+
}
|
|
110
|
+
getEventInit(type, button) {
|
|
111
|
+
const init = {
|
|
112
|
+
...this.position.coords
|
|
113
|
+
};
|
|
114
|
+
init.button = getMouseEventButton(button);
|
|
115
|
+
init.buttons = this.buttons.getButtons();
|
|
116
|
+
if (type === 'mousedown') {
|
|
117
|
+
init.detail = this.clickCount.getOnDown(init.button);
|
|
118
|
+
} else if (type === 'mouseup') {
|
|
119
|
+
init.detail = this.clickCount.getOnUp(init.button);
|
|
120
|
+
} else if (type === 'click' || type === 'auxclick') {
|
|
121
|
+
init.detail = this.clickCount.incOnClick(init.button);
|
|
122
|
+
}
|
|
123
|
+
return init;
|
|
124
|
+
}
|
|
125
|
+
getTarget(instance) {
|
|
126
|
+
var _this_position_target;
|
|
127
|
+
return (_this_position_target = this.position.target) !== null && _this_position_target !== void 0 ? _this_position_target : instance.config.document.body;
|
|
128
|
+
}
|
|
129
|
+
startSelecting(instance, clickCount) {
|
|
130
|
+
var _this_position_caret, _this_position_caret1;
|
|
131
|
+
// TODO: support extending range (shift)
|
|
132
|
+
this.selecting = setSelectionPerMouseDown({
|
|
133
|
+
document: instance.config.document,
|
|
134
|
+
target: this.getTarget(instance),
|
|
135
|
+
node: (_this_position_caret = this.position.caret) === null || _this_position_caret === void 0 ? void 0 : _this_position_caret.node,
|
|
136
|
+
offset: (_this_position_caret1 = this.position.caret) === null || _this_position_caret1 === void 0 ? void 0 : _this_position_caret1.offset,
|
|
137
|
+
clickCount
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
modifySelecting(instance) {
|
|
141
|
+
var _this_position_caret, _this_position_caret1;
|
|
142
|
+
if (!this.selecting) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
modifySelectionPerMouseMove(this.selecting, {
|
|
146
|
+
document: instance.config.document,
|
|
147
|
+
target: this.getTarget(instance),
|
|
148
|
+
node: (_this_position_caret = this.position.caret) === null || _this_position_caret === void 0 ? void 0 : _this_position_caret.node,
|
|
149
|
+
offset: (_this_position_caret1 = this.position.caret) === null || _this_position_caret1 === void 0 ? void 0 : _this_position_caret1.offset
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
endSelecting() {
|
|
153
|
+
this.selecting = undefined;
|
|
154
|
+
}
|
|
155
|
+
constructor(){
|
|
156
|
+
_define_property(this, "position", {});
|
|
157
|
+
_define_property(this, "buttons", new Buttons());
|
|
158
|
+
_define_property(this, "selecting", void 0);
|
|
159
|
+
_define_property(this, "buttonDownTarget", {});
|
|
160
|
+
// According to spec the `detail` on click events should be the number
|
|
161
|
+
// of *consecutive* clicks with a specific button.
|
|
162
|
+
// On `mousedown` and `mouseup` it should be this number increased by one.
|
|
163
|
+
// But the browsers don't implement it this way.
|
|
164
|
+
// If another button is pressed,
|
|
165
|
+
// in Webkit: the `mouseup` on the previously pressed button has `detail: 0` and no `click`/`auxclick`.
|
|
166
|
+
// in Gecko: the `mouseup` and click events have the same detail as the `mousedown`.
|
|
167
|
+
// If there is a delay while a button is pressed,
|
|
168
|
+
// the `mouseup` and `click` are normal, but a following `mousedown` starts a new click count.
|
|
169
|
+
// We'll follow the minimal implementation of Webkit.
|
|
170
|
+
_define_property(this, "clickCount", new class {
|
|
171
|
+
incOnClick(button) {
|
|
172
|
+
const current = this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
|
|
173
|
+
this.count = this.count[button] === undefined ? {} : {
|
|
174
|
+
[button]: Number(this.count[button]) + 1
|
|
175
|
+
};
|
|
176
|
+
return current;
|
|
177
|
+
}
|
|
178
|
+
getOnDown(button) {
|
|
179
|
+
var _this_count_button, _this_count_button1;
|
|
180
|
+
this.down = {
|
|
181
|
+
[button]: (_this_count_button = this.count[button]) !== null && _this_count_button !== void 0 ? _this_count_button : 0
|
|
182
|
+
};
|
|
183
|
+
this.count = {
|
|
184
|
+
[button]: (_this_count_button1 = this.count[button]) !== null && _this_count_button1 !== void 0 ? _this_count_button1 : 0
|
|
185
|
+
};
|
|
186
|
+
return Number(this.count[button]) + 1;
|
|
187
|
+
}
|
|
188
|
+
getOnUp(button) {
|
|
189
|
+
return this.down[button] === undefined ? undefined : Number(this.down[button]) + 1;
|
|
190
|
+
}
|
|
191
|
+
reset() {
|
|
192
|
+
this.count = {};
|
|
193
|
+
}
|
|
194
|
+
constructor(){
|
|
195
|
+
_define_property(this, "down", {});
|
|
196
|
+
_define_property(this, "count", {});
|
|
197
|
+
}
|
|
198
|
+
}());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { Mouse };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
2
|
+
import { getTreeDiff } from '../../utils/misc/getTreeDiff.js';
|
|
3
|
+
import { assertPointerEvents, hasPointerEvents } from '../../utils/pointer/cssPointerEvents.js';
|
|
4
|
+
import { isDifferentPointerPosition } from './shared.js';
|
|
5
|
+
import { getMouseEventButton } from './buttons.js';
|
|
6
|
+
|
|
7
|
+
function _define_property(obj, key, value) {
|
|
8
|
+
if (key in obj) {
|
|
9
|
+
Object.defineProperty(obj, key, {
|
|
10
|
+
value: value,
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true
|
|
14
|
+
});
|
|
15
|
+
} else obj[key] = value;
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
class Pointer {
|
|
19
|
+
init(instance) {
|
|
20
|
+
const target = this.getTarget(instance);
|
|
21
|
+
const [, enter] = getTreeDiff(null, target);
|
|
22
|
+
const init = this.getEventInit();
|
|
23
|
+
assertPointerEvents(instance, target);
|
|
24
|
+
instance.dispatchUIEvent(target, 'pointerover', init);
|
|
25
|
+
enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init));
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
move(instance, position) {
|
|
29
|
+
const prevPosition = this.position;
|
|
30
|
+
const prevTarget = this.getTarget(instance);
|
|
31
|
+
this.position = position;
|
|
32
|
+
if (!isDifferentPointerPosition(prevPosition, position)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const nextTarget = this.getTarget(instance);
|
|
36
|
+
const init = this.getEventInit(-1);
|
|
37
|
+
const [leave, enter] = getTreeDiff(prevTarget, nextTarget);
|
|
38
|
+
return {
|
|
39
|
+
leave: ()=>{
|
|
40
|
+
if (hasPointerEvents(instance, prevTarget)) {
|
|
41
|
+
if (prevTarget !== nextTarget) {
|
|
42
|
+
instance.dispatchUIEvent(prevTarget, 'pointerout', init);
|
|
43
|
+
leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
enter: ()=>{
|
|
48
|
+
assertPointerEvents(instance, nextTarget);
|
|
49
|
+
if (prevTarget !== nextTarget) {
|
|
50
|
+
instance.dispatchUIEvent(nextTarget, 'pointerover', init);
|
|
51
|
+
enter.forEach((el)=>instance.dispatchUIEvent(el, 'pointerenter', init));
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
move: ()=>{
|
|
55
|
+
instance.dispatchUIEvent(nextTarget, 'pointermove', init);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
down(instance, button = 0) {
|
|
60
|
+
if (this.isDown) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const target = this.getTarget(instance);
|
|
64
|
+
assertPointerEvents(instance, target);
|
|
65
|
+
this.isDown = true;
|
|
66
|
+
this.isPrevented = !instance.dispatchUIEvent(target, 'pointerdown', this.getEventInit(button));
|
|
67
|
+
}
|
|
68
|
+
up(instance, button = 0) {
|
|
69
|
+
if (!this.isDown) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const target = this.getTarget(instance);
|
|
73
|
+
assertPointerEvents(instance, target);
|
|
74
|
+
this.isPrevented = false;
|
|
75
|
+
this.isDown = false;
|
|
76
|
+
instance.dispatchUIEvent(target, 'pointerup', this.getEventInit(button));
|
|
77
|
+
}
|
|
78
|
+
release(instance) {
|
|
79
|
+
const target = this.getTarget(instance);
|
|
80
|
+
const [leave] = getTreeDiff(target, null);
|
|
81
|
+
const init = this.getEventInit();
|
|
82
|
+
// Currently there is no PointerEventsCheckLevel that would
|
|
83
|
+
// make this check not use the *asserted* cached value from `up`.
|
|
84
|
+
/* istanbul ignore else */ if (hasPointerEvents(instance, target)) {
|
|
85
|
+
instance.dispatchUIEvent(target, 'pointerout', init);
|
|
86
|
+
leave.forEach((el)=>instance.dispatchUIEvent(el, 'pointerleave', init));
|
|
87
|
+
}
|
|
88
|
+
this.isCancelled = true;
|
|
89
|
+
}
|
|
90
|
+
getTarget(instance) {
|
|
91
|
+
var _this_position_target;
|
|
92
|
+
return (_this_position_target = this.position.target) !== null && _this_position_target !== void 0 ? _this_position_target : instance.config.document.body;
|
|
93
|
+
}
|
|
94
|
+
getEventInit(/**
|
|
95
|
+
* The `button` that caused the event.
|
|
96
|
+
*
|
|
97
|
+
* This should be `-1` if the event is not caused by a button or touch/pen contact,
|
|
98
|
+
* e.g. a moving pointer.
|
|
99
|
+
*/ button) {
|
|
100
|
+
return {
|
|
101
|
+
...this.position.coords,
|
|
102
|
+
pointerId: this.pointerId,
|
|
103
|
+
pointerType: this.pointerType,
|
|
104
|
+
isPrimary: this.isPrimary,
|
|
105
|
+
button: getMouseEventButton(button),
|
|
106
|
+
buttons: this.buttons.getButtons()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
constructor({ pointerId, pointerType, isPrimary }, buttons){
|
|
110
|
+
_define_property(this, "pointerId", void 0);
|
|
111
|
+
_define_property(this, "pointerType", void 0);
|
|
112
|
+
_define_property(this, "isPrimary", void 0);
|
|
113
|
+
_define_property(this, "buttons", void 0);
|
|
114
|
+
_define_property(this, "isMultitouch", false);
|
|
115
|
+
_define_property(this, "isCancelled", false);
|
|
116
|
+
_define_property(this, "isDown", false);
|
|
117
|
+
_define_property(this, "isPrevented", false);
|
|
118
|
+
_define_property(this, "position", {});
|
|
119
|
+
this.pointerId = pointerId;
|
|
120
|
+
this.pointerType = pointerType;
|
|
121
|
+
this.isPrimary = isPrimary;
|
|
122
|
+
this.isMultitouch = !isPrimary;
|
|
123
|
+
this.buttons = buttons;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { Pointer };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function isDifferentPointerPosition(positionA, positionB) {
|
|
2
|
+
var _positionA_coords, _positionB_coords, _positionA_coords1, _positionB_coords1, _positionA_coords2, _positionB_coords2, _positionA_coords3, _positionB_coords3, _positionA_coords4, _positionB_coords4, _positionA_coords5, _positionB_coords5, _positionA_coords6, _positionB_coords6, _positionA_coords7, _positionB_coords7, _positionA_coords8, _positionB_coords8, _positionA_coords9, _positionB_coords9, _positionA_caret, _positionB_caret, _positionA_caret1, _positionB_caret1;
|
|
3
|
+
return positionA.target !== positionB.target || ((_positionA_coords = positionA.coords) === null || _positionA_coords === void 0 ? void 0 : _positionA_coords.x) !== ((_positionB_coords = positionB.coords) === null || _positionB_coords === void 0 ? void 0 : _positionB_coords.x) || ((_positionA_coords1 = positionA.coords) === null || _positionA_coords1 === void 0 ? void 0 : _positionA_coords1.y) !== ((_positionB_coords1 = positionB.coords) === null || _positionB_coords1 === void 0 ? void 0 : _positionB_coords1.y) || ((_positionA_coords2 = positionA.coords) === null || _positionA_coords2 === void 0 ? void 0 : _positionA_coords2.clientX) !== ((_positionB_coords2 = positionB.coords) === null || _positionB_coords2 === void 0 ? void 0 : _positionB_coords2.clientX) || ((_positionA_coords3 = positionA.coords) === null || _positionA_coords3 === void 0 ? void 0 : _positionA_coords3.clientY) !== ((_positionB_coords3 = positionB.coords) === null || _positionB_coords3 === void 0 ? void 0 : _positionB_coords3.clientY) || ((_positionA_coords4 = positionA.coords) === null || _positionA_coords4 === void 0 ? void 0 : _positionA_coords4.offsetX) !== ((_positionB_coords4 = positionB.coords) === null || _positionB_coords4 === void 0 ? void 0 : _positionB_coords4.offsetX) || ((_positionA_coords5 = positionA.coords) === null || _positionA_coords5 === void 0 ? void 0 : _positionA_coords5.offsetY) !== ((_positionB_coords5 = positionB.coords) === null || _positionB_coords5 === void 0 ? void 0 : _positionB_coords5.offsetY) || ((_positionA_coords6 = positionA.coords) === null || _positionA_coords6 === void 0 ? void 0 : _positionA_coords6.pageX) !== ((_positionB_coords6 = positionB.coords) === null || _positionB_coords6 === void 0 ? void 0 : _positionB_coords6.pageX) || ((_positionA_coords7 = positionA.coords) === null || _positionA_coords7 === void 0 ? void 0 : _positionA_coords7.pageY) !== ((_positionB_coords7 = positionB.coords) === null || _positionB_coords7 === void 0 ? void 0 : _positionB_coords7.pageY) || ((_positionA_coords8 = positionA.coords) === null || _positionA_coords8 === void 0 ? void 0 : _positionA_coords8.screenX) !== ((_positionB_coords8 = positionB.coords) === null || _positionB_coords8 === void 0 ? void 0 : _positionB_coords8.screenX) || ((_positionA_coords9 = positionA.coords) === null || _positionA_coords9 === void 0 ? void 0 : _positionA_coords9.screenY) !== ((_positionB_coords9 = positionB.coords) === null || _positionB_coords9 === void 0 ? void 0 : _positionB_coords9.screenY) || ((_positionA_caret = positionA.caret) === null || _positionA_caret === void 0 ? void 0 : _positionA_caret.node) !== ((_positionB_caret = positionB.caret) === null || _positionB_caret === void 0 ? void 0 : _positionB_caret.node) || ((_positionA_caret1 = positionA.caret) === null || _positionA_caret1 === void 0 ? void 0 : _positionA_caret1.offset) !== ((_positionB_caret1 = positionB.caret) === null || _positionB_caret1 === void 0 ? void 0 : _positionB_caret1.offset);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { isDifferentPointerPosition };
|
|
@@ -0,0 +1,30 @@
|
|
|
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 '../utils/dataTransfer/Clipboard.js';
|
|
9
|
+
import { isEditable } from '../utils/edit/isEditable.js';
|
|
10
|
+
import { isDisabled } from '../utils/misc/isDisabled.js';
|
|
11
|
+
import { focusElement } from '../event/focus.js';
|
|
12
|
+
import { input } from '../event/input.js';
|
|
13
|
+
import { selectAll, isAllSelected } from '../event/selection/selectAll.js';
|
|
14
|
+
|
|
15
|
+
async function clear(element) {
|
|
16
|
+
if (!isEditable(element) || isDisabled(element)) {
|
|
17
|
+
throw new Error('clear()` is only supported on editable elements.');
|
|
18
|
+
}
|
|
19
|
+
focusElement(element);
|
|
20
|
+
if (element.ownerDocument.activeElement !== element) {
|
|
21
|
+
throw new Error('The element to be cleared could not be focused.');
|
|
22
|
+
}
|
|
23
|
+
selectAll(element);
|
|
24
|
+
if (!isAllSelected(element)) {
|
|
25
|
+
throw new Error('The element content to be cleared could not be selected.');
|
|
26
|
+
}
|
|
27
|
+
input(this, element, '', 'deleteContentBackward');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { clear };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { getConfig } from '@testing-library/dom';
|
|
2
|
+
import { isElementType } from '../utils/misc/isElementType.js';
|
|
3
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
4
|
+
import { isDisabled } from '../utils/misc/isDisabled.js';
|
|
5
|
+
import { wait } from '../utils/misc/wait.js';
|
|
6
|
+
import { hasPointerEvents } from '../utils/pointer/cssPointerEvents.js';
|
|
7
|
+
import '../event/behavior/click.js';
|
|
8
|
+
import '../event/behavior/cut.js';
|
|
9
|
+
import '../event/behavior/keydown.js';
|
|
10
|
+
import '../event/behavior/keypress.js';
|
|
11
|
+
import '../event/behavior/keyup.js';
|
|
12
|
+
import '../event/behavior/paste.js';
|
|
13
|
+
import { focusElement } from '../event/focus.js';
|
|
14
|
+
|
|
15
|
+
async function selectOptions(select, values) {
|
|
16
|
+
return selectOptionsBase.call(this, true, select, values);
|
|
17
|
+
}
|
|
18
|
+
async function deselectOptions(select, values) {
|
|
19
|
+
return selectOptionsBase.call(this, false, select, values);
|
|
20
|
+
}
|
|
21
|
+
async function selectOptionsBase(newValue, select, values) {
|
|
22
|
+
if (!newValue && !select.multiple) {
|
|
23
|
+
throw getConfig().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
24
|
+
}
|
|
25
|
+
const valArray = Array.isArray(values) ? values : [
|
|
26
|
+
values
|
|
27
|
+
];
|
|
28
|
+
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
|
|
29
|
+
const selectedOptions = valArray.map((val)=>{
|
|
30
|
+
if (typeof val !== 'string' && allOptions.includes(val)) {
|
|
31
|
+
return val;
|
|
32
|
+
} else {
|
|
33
|
+
const matchingOption = allOptions.find((o)=>o.value === val || o.innerHTML === val);
|
|
34
|
+
if (matchingOption) {
|
|
35
|
+
return matchingOption;
|
|
36
|
+
} else {
|
|
37
|
+
throw getConfig().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}).filter((option)=>!isDisabled(option));
|
|
41
|
+
if (isDisabled(select) || !selectedOptions.length) return;
|
|
42
|
+
const selectOption = (option)=>{
|
|
43
|
+
option.selected = newValue;
|
|
44
|
+
this.dispatchUIEvent(select, 'input', {
|
|
45
|
+
bubbles: true,
|
|
46
|
+
cancelable: false,
|
|
47
|
+
composed: true
|
|
48
|
+
});
|
|
49
|
+
this.dispatchUIEvent(select, 'change');
|
|
50
|
+
};
|
|
51
|
+
if (isElementType(select, 'select')) {
|
|
52
|
+
if (select.multiple) {
|
|
53
|
+
for (const option of selectedOptions){
|
|
54
|
+
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, option);
|
|
55
|
+
// events fired for multiple select are weird. Can't use hover...
|
|
56
|
+
if (withPointerEvents) {
|
|
57
|
+
this.dispatchUIEvent(option, 'pointerover');
|
|
58
|
+
this.dispatchUIEvent(select, 'pointerenter');
|
|
59
|
+
this.dispatchUIEvent(option, 'mouseover');
|
|
60
|
+
this.dispatchUIEvent(select, 'mouseenter');
|
|
61
|
+
this.dispatchUIEvent(option, 'pointermove');
|
|
62
|
+
this.dispatchUIEvent(option, 'mousemove');
|
|
63
|
+
this.dispatchUIEvent(option, 'pointerdown');
|
|
64
|
+
this.dispatchUIEvent(option, 'mousedown');
|
|
65
|
+
}
|
|
66
|
+
focusElement(select);
|
|
67
|
+
if (withPointerEvents) {
|
|
68
|
+
this.dispatchUIEvent(option, 'pointerup');
|
|
69
|
+
this.dispatchUIEvent(option, 'mouseup');
|
|
70
|
+
}
|
|
71
|
+
selectOption(option);
|
|
72
|
+
if (withPointerEvents) {
|
|
73
|
+
this.dispatchUIEvent(option, 'click');
|
|
74
|
+
}
|
|
75
|
+
await wait(this.config);
|
|
76
|
+
}
|
|
77
|
+
} else if (selectedOptions.length === 1) {
|
|
78
|
+
const withPointerEvents = this.config.pointerEventsCheck === 0 ? true : hasPointerEvents(this, select);
|
|
79
|
+
// the click to open the select options
|
|
80
|
+
if (withPointerEvents) {
|
|
81
|
+
await this.click(select);
|
|
82
|
+
} else {
|
|
83
|
+
focusElement(select);
|
|
84
|
+
}
|
|
85
|
+
selectOption(selectedOptions[0]);
|
|
86
|
+
if (withPointerEvents) {
|
|
87
|
+
// the browser triggers another click event on the select for the click on the option
|
|
88
|
+
// this second click has no 'down' phase
|
|
89
|
+
this.dispatchUIEvent(select, 'pointerover');
|
|
90
|
+
this.dispatchUIEvent(select, 'pointerenter');
|
|
91
|
+
this.dispatchUIEvent(select, 'mouseover');
|
|
92
|
+
this.dispatchUIEvent(select, 'mouseenter');
|
|
93
|
+
this.dispatchUIEvent(select, 'pointerup');
|
|
94
|
+
this.dispatchUIEvent(select, 'mouseup');
|
|
95
|
+
this.dispatchUIEvent(select, 'click');
|
|
96
|
+
}
|
|
97
|
+
await wait(this.config);
|
|
98
|
+
} else {
|
|
99
|
+
throw getConfig().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
100
|
+
}
|
|
101
|
+
} else if (select.getAttribute('role') === 'listbox') {
|
|
102
|
+
for (const option of selectedOptions){
|
|
103
|
+
await this.click(option);
|
|
104
|
+
await this.unhover(option);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
throw getConfig().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { deselectOptions, selectOptions };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { releaseAllKeys } from '../keyboard/index.js';
|
|
2
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { setSelectionRange } from '../event/selection/setSelectionRange.js';
|
|
4
|
+
|
|
5
|
+
async function type(element, text, { skipClick = this.config.skipClick, skipAutoClose = this.config.skipAutoClose, initialSelectionStart, initialSelectionEnd } = {}) {
|
|
6
|
+
// TODO: properly type guard
|
|
7
|
+
// we use this workaround for now to prevent changing behavior
|
|
8
|
+
if (element.disabled) return;
|
|
9
|
+
if (!skipClick) {
|
|
10
|
+
await this.click(element);
|
|
11
|
+
}
|
|
12
|
+
if (initialSelectionStart !== undefined) {
|
|
13
|
+
setSelectionRange(element, initialSelectionStart, initialSelectionEnd !== null && initialSelectionEnd !== void 0 ? initialSelectionEnd : initialSelectionStart);
|
|
14
|
+
}
|
|
15
|
+
await this.keyboard(text);
|
|
16
|
+
if (!skipAutoClose) {
|
|
17
|
+
await releaseAllKeys(this);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { type };
|