@testing-library/user-event 14.2.5 → 14.4.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/dist/cjs/clipboard/copy.js +40 -0
- package/dist/cjs/clipboard/cut.js +40 -0
- package/dist/cjs/clipboard/index.js +13 -0
- package/dist/cjs/clipboard/paste.js +41 -0
- package/dist/cjs/convenience/click.js +40 -0
- package/dist/cjs/convenience/hover.js +37 -0
- package/dist/cjs/convenience/index.js +16 -0
- package/dist/cjs/convenience/tab.js +9 -0
- package/dist/cjs/document/index.js +74 -0
- package/dist/cjs/document/interceptor.js +30 -0
- package/dist/cjs/document/selection.js +107 -0
- package/dist/cjs/document/setRangeText.js +21 -0
- package/dist/cjs/document/value.js +125 -0
- package/dist/cjs/event/behavior/click.js +42 -0
- package/dist/cjs/event/behavior/cut.js +26 -0
- package/dist/cjs/event/behavior/index.js +15 -0
- package/dist/cjs/event/behavior/keydown.js +134 -0
- package/dist/cjs/event/behavior/keypress.js +58 -0
- package/dist/cjs/event/behavior/keyup.js +24 -0
- package/dist/cjs/event/behavior/paste.js +29 -0
- package/dist/cjs/event/behavior/registry.js +7 -0
- package/dist/cjs/event/createEvent.js +193 -0
- package/dist/cjs/event/dispatchEvent.js +37 -0
- package/dist/cjs/event/dom-events.d.js +2 -0
- package/dist/cjs/event/eventMap.js +64 -0
- package/dist/cjs/event/index.js +24 -0
- package/dist/cjs/event/types.js +2 -0
- package/dist/cjs/event/wrapEvent.js +11 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/keyboard/index.js +59 -0
- package/dist/cjs/keyboard/keyMap.js +158 -0
- package/dist/cjs/keyboard/parseKeyDef.js +58 -0
- package/dist/cjs/options.js +42 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pointer/index.js +88 -0
- package/dist/cjs/pointer/keyMap.js +35 -0
- package/dist/cjs/pointer/parseKeyDef.js +39 -0
- package/dist/cjs/setup/api.js +35 -0
- package/dist/cjs/setup/config.js +7 -0
- package/dist/cjs/setup/directApi.js +77 -0
- package/dist/cjs/setup/index.js +15 -0
- package/dist/cjs/setup/setup.js +97 -0
- package/dist/cjs/setup/wrapAsync.js +13 -0
- package/dist/cjs/system/index.js +31 -0
- package/dist/cjs/system/keyboard.js +135 -0
- package/dist/cjs/system/pointer/buttons.js +71 -0
- package/dist/cjs/system/pointer/device.js +21 -0
- package/dist/cjs/system/pointer/index.js +146 -0
- package/dist/cjs/system/pointer/mouse.js +186 -0
- package/dist/cjs/system/pointer/pointer.js +114 -0
- package/dist/cjs/utility/clear.js +42 -0
- package/dist/cjs/utility/index.js +16 -0
- package/dist/cjs/utility/selectOptions.js +125 -0
- package/dist/cjs/utility/type.js +41 -0
- package/dist/cjs/utility/upload.js +72 -0
- package/dist/cjs/utils/click/isClickableInput.js +22 -0
- package/dist/cjs/utils/dataTransfer/Blob.js +18 -0
- package/dist/cjs/utils/dataTransfer/Clipboard.js +168 -0
- package/dist/cjs/utils/dataTransfer/DataTransfer.js +124 -0
- package/dist/cjs/utils/dataTransfer/FileList.js +26 -0
- package/dist/cjs/utils/edit/buildTimeValue.js +36 -0
- package/dist/cjs/utils/edit/getValue.js +35 -0
- package/dist/cjs/utils/edit/input.js +162 -0
- package/dist/cjs/utils/edit/isContentEditable.js +20 -0
- package/dist/cjs/utils/edit/isEditable.js +35 -0
- package/dist/cjs/utils/edit/isValidDateOrTimeValue.js +11 -0
- package/dist/cjs/utils/edit/maxLength.js +38 -0
- package/dist/cjs/utils/edit/setFiles.js +59 -0
- package/dist/cjs/utils/edit/walkRadio.js +28 -0
- package/dist/cjs/utils/focus/blur.js +16 -0
- package/dist/cjs/utils/focus/copySelection.js +46 -0
- package/dist/cjs/utils/focus/cursor.js +143 -0
- package/dist/cjs/utils/focus/focus.js +26 -0
- package/dist/cjs/utils/focus/getActiveElement.js +24 -0
- package/dist/cjs/utils/focus/getTabDestination.js +82 -0
- package/dist/cjs/utils/focus/isFocusable.js +11 -0
- package/dist/cjs/utils/focus/resolveCaretPosition.js +78 -0
- package/dist/cjs/utils/focus/selectAll.js +54 -0
- package/dist/cjs/utils/focus/selection.js +287 -0
- package/dist/cjs/utils/focus/selector.js +16 -0
- package/dist/cjs/utils/index.js +108 -0
- package/dist/cjs/utils/keyDef/readNextDescriptor.js +92 -0
- package/dist/cjs/utils/misc/cloneEvent.js +9 -0
- package/dist/cjs/utils/misc/dom-helpers.d.js +2 -0
- package/dist/cjs/utils/misc/eventWrapper.js +15 -0
- package/dist/cjs/utils/misc/findClosest.js +16 -0
- package/dist/cjs/utils/misc/getDocumentFromNode.js +12 -0
- package/dist/cjs/utils/misc/getTreeDiff.js +27 -0
- package/dist/cjs/utils/misc/getWindow.js +11 -0
- package/dist/cjs/utils/misc/isDescendantOrSelf.js +16 -0
- package/dist/cjs/utils/misc/isDisabled.js +34 -0
- package/dist/cjs/utils/misc/isElementType.js +22 -0
- package/dist/cjs/utils/misc/isVisible.js +21 -0
- package/dist/cjs/utils/misc/level.js +20 -0
- package/dist/cjs/utils/misc/wait.js +16 -0
- package/dist/cjs/utils/pointer/cssPointerEvents.js +111 -0
- package/dist/esm/clipboard/copy.js +36 -0
- package/dist/esm/clipboard/cut.js +36 -0
- package/dist/esm/clipboard/index.js +3 -0
- package/dist/esm/clipboard/paste.js +37 -0
- package/dist/esm/convenience/click.js +34 -0
- package/dist/esm/convenience/hover.js +32 -0
- package/dist/esm/convenience/index.js +3 -0
- package/dist/esm/convenience/tab.js +5 -0
- package/dist/esm/document/index.js +66 -0
- package/dist/esm/document/interceptor.js +26 -0
- package/dist/esm/document/selection.js +99 -0
- package/dist/esm/document/setRangeText.js +17 -0
- package/dist/esm/document/value.js +115 -0
- package/dist/esm/event/behavior/click.js +40 -0
- package/dist/esm/event/behavior/cut.js +24 -0
- package/dist/esm/event/behavior/index.js +7 -0
- package/dist/esm/event/behavior/keydown.js +132 -0
- package/dist/esm/event/behavior/keypress.js +56 -0
- package/dist/esm/event/behavior/keyup.js +22 -0
- package/dist/esm/event/behavior/paste.js +27 -0
- package/dist/esm/event/behavior/registry.js +3 -0
- package/dist/esm/event/createEvent.js +189 -0
- package/dist/esm/event/dispatchEvent.js +33 -0
- package/dist/esm/event/dom-events.d.js +1 -0
- package/dist/esm/event/eventMap.js +57 -0
- package/dist/esm/event/index.js +19 -0
- package/dist/esm/event/types.js +1 -0
- package/dist/esm/event/wrapEvent.js +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/keyboard/index.js +54 -0
- package/dist/esm/keyboard/keyMap.js +154 -0
- package/dist/esm/keyboard/parseKeyDef.js +54 -0
- package/dist/esm/options.js +37 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pointer/index.js +84 -0
- package/dist/esm/pointer/keyMap.js +31 -0
- package/dist/esm/pointer/parseKeyDef.js +35 -0
- package/dist/esm/setup/api.js +12 -0
- package/dist/esm/setup/config.js +3 -0
- package/dist/esm/setup/directApi.js +58 -0
- package/dist/esm/setup/index.js +10 -0
- package/dist/esm/setup/setup.js +90 -0
- package/dist/esm/setup/wrapAsync.js +9 -0
- package/dist/esm/system/index.js +27 -0
- package/dist/esm/system/keyboard.js +131 -0
- package/dist/esm/system/pointer/buttons.js +63 -0
- package/dist/esm/system/pointer/device.js +17 -0
- package/dist/esm/system/pointer/index.js +141 -0
- package/dist/esm/system/pointer/mouse.js +182 -0
- package/dist/esm/system/pointer/pointer.js +110 -0
- package/dist/esm/utility/clear.js +38 -0
- package/dist/esm/utility/index.js +4 -0
- package/dist/esm/utility/selectOptions.js +120 -0
- package/dist/esm/utility/type.js +37 -0
- package/dist/esm/utility/upload.js +68 -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 +159 -0
- package/dist/esm/utils/dataTransfer/DataTransfer.js +119 -0
- package/dist/esm/utils/dataTransfer/FileList.js +22 -0
- package/dist/esm/utils/edit/buildTimeValue.js +32 -0
- package/dist/esm/utils/edit/getValue.js +31 -0
- package/dist/esm/utils/edit/input.js +158 -0
- package/dist/esm/utils/edit/isContentEditable.js +15 -0
- package/dist/esm/utils/edit/isEditable.js +30 -0
- package/dist/esm/utils/edit/isValidDateOrTimeValue.js +7 -0
- package/dist/esm/utils/edit/maxLength.js +34 -0
- package/dist/esm/utils/edit/setFiles.js +55 -0
- package/dist/esm/utils/edit/walkRadio.js +24 -0
- package/dist/esm/utils/focus/blur.js +12 -0
- package/dist/esm/utils/focus/copySelection.js +42 -0
- package/dist/esm/utils/focus/cursor.js +139 -0
- package/dist/esm/utils/focus/focus.js +22 -0
- package/dist/esm/utils/focus/getActiveElement.js +19 -0
- package/dist/esm/utils/focus/getTabDestination.js +78 -0
- package/dist/esm/utils/focus/isFocusable.js +7 -0
- package/dist/esm/utils/focus/resolveCaretPosition.js +74 -0
- package/dist/esm/utils/focus/selectAll.js +49 -0
- package/dist/esm/utils/focus/selection.js +274 -0
- package/dist/esm/utils/focus/selector.js +12 -0
- package/dist/esm/utils/index.js +36 -0
- package/dist/esm/utils/keyDef/readNextDescriptor.js +88 -0
- package/dist/esm/utils/misc/cloneEvent.js +5 -0
- package/dist/esm/utils/misc/dom-helpers.d.js +1 -0
- package/dist/esm/utils/misc/eventWrapper.js +11 -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 +7 -0
- package/dist/esm/utils/misc/isDescendantOrSelf.js +12 -0
- package/dist/esm/utils/misc/isDisabled.js +30 -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 +15 -0
- package/dist/esm/utils/misc/wait.js +12 -0
- package/dist/esm/utils/pointer/cssPointerEvents.js +106 -0
- package/dist/types/document/index.d.ts +1 -1
- package/dist/types/document/selection.d.ts +1 -0
- package/dist/types/document/value.d.ts +4 -5
- package/dist/types/event/createEvent.d.ts +2 -8
- package/dist/types/event/eventMap.d.ts +204 -181
- package/dist/types/event/index.d.ts +1 -2
- package/dist/types/event/types.d.ts +6 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/keyboard/index.d.ts +2 -6
- package/dist/types/keyboard/keyMap.d.ts +1 -1
- package/dist/types/keyboard/parseKeyDef.d.ts +1 -1
- package/dist/types/options.d.ts +4 -4
- package/dist/types/pointer/index.d.ts +23 -5
- package/dist/types/pointer/keyMap.d.ts +1 -1
- package/dist/types/pointer/parseKeyDef.d.ts +1 -1
- package/dist/types/setup/config.d.ts +3 -7
- package/dist/types/setup/directApi.d.ts +21 -16
- package/dist/types/setup/index.d.ts +1 -2
- package/dist/types/setup/setup.d.ts +7 -1
- package/dist/types/system/index.d.ts +10 -0
- package/dist/types/system/keyboard.d.ts +53 -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 +39 -0
- package/dist/types/system/pointer/mouse.d.ts +26 -0
- package/dist/types/system/pointer/pointer.d.ts +30 -0
- package/dist/types/utils/click/isClickableInput.d.ts +15 -1
- package/dist/types/utils/edit/walkRadio.d.ts +4 -0
- package/dist/types/utils/focus/getActiveElement.d.ts +1 -0
- package/dist/types/utils/focus/resolveCaretPosition.d.ts +8 -0
- package/dist/types/utils/focus/selection.d.ts +28 -1
- package/dist/types/utils/index.d.ts +3 -3
- package/dist/types/utils/misc/getTreeDiff.d.ts +1 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +6 -2
- package/package.json +9 -15
- package/dist/index.cjs +0 -3057
- package/dist/index.mjs +0 -3107
- package/dist/types/event/eventTypes.d.ts +0 -2
- package/dist/types/keyboard/keyboardAction.d.ts +0 -10
- package/dist/types/keyboard/modifiers.d.ts +0 -9
- package/dist/types/keyboard/types.d.ts +0 -73
- package/dist/types/pointer/firePointerEvents.d.ts +0 -11
- package/dist/types/pointer/pointerAction.d.ts +0 -7
- package/dist/types/pointer/pointerMove.d.ts +0 -6
- package/dist/types/pointer/pointerPress.d.ts +0 -8
- package/dist/types/pointer/resolveSelectionTarget.d.ts +0 -5
- package/dist/types/pointer/types.d.ts +0 -62
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +0 -5
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +0 -15
- package/dist/types/utils/pointer/mouseButtons.d.ts +0 -12
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index$1 = require('../document/index.js');
|
|
6
|
+
var index$2 = require('../event/index.js');
|
|
7
|
+
var options = require('../options.js');
|
|
8
|
+
require('../utils/click/isClickableInput.js');
|
|
9
|
+
var Clipboard = require('../utils/dataTransfer/Clipboard.js');
|
|
10
|
+
require('../utils/edit/maxLength.js');
|
|
11
|
+
require('../utils/edit/isEditable.js');
|
|
12
|
+
require('@testing-library/dom');
|
|
13
|
+
require('@testing-library/dom/dist/helpers.js');
|
|
14
|
+
require('../utils/keyDef/readNextDescriptor.js');
|
|
15
|
+
var getDocumentFromNode = require('../utils/misc/getDocumentFromNode.js');
|
|
16
|
+
var level = require('../utils/misc/level.js');
|
|
17
|
+
var wait = require('../utils/misc/wait.js');
|
|
18
|
+
var index = require('../system/index.js');
|
|
19
|
+
var config = require('./config.js');
|
|
20
|
+
var api = require('./api.js');
|
|
21
|
+
var wrapAsync = require('./wrapAsync.js');
|
|
22
|
+
|
|
23
|
+
function createConfig(options$1 = {}, defaults = options.defaultOptionsSetup, node) {
|
|
24
|
+
const document = getDocument(options$1, node, defaults);
|
|
25
|
+
return {
|
|
26
|
+
...defaults,
|
|
27
|
+
...options$1,
|
|
28
|
+
document,
|
|
29
|
+
system: options$1.system ?? new index.System()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Start a "session" with userEvent.
|
|
34
|
+
* All APIs returned by this function share an input device state and a default configuration.
|
|
35
|
+
*/ function setupMain(options = {}) {
|
|
36
|
+
const config = createConfig(options);
|
|
37
|
+
index$1.prepareDocument(config.document);
|
|
38
|
+
const view = config.document.defaultView ?? /* istanbul ignore next */ globalThis.window;
|
|
39
|
+
Clipboard.attachClipboardStubToView(view);
|
|
40
|
+
return doSetup(config);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Setup in direct call per `userEvent.anyApi()`
|
|
44
|
+
*/ function setupDirect({ keyboardState , pointerState , ...options$1 } = {}, node) {
|
|
45
|
+
const config = createConfig({
|
|
46
|
+
...options$1,
|
|
47
|
+
system: pointerState ?? keyboardState
|
|
48
|
+
}, options.defaultOptionsDirect, node);
|
|
49
|
+
index$1.prepareDocument(config.document);
|
|
50
|
+
return {
|
|
51
|
+
config,
|
|
52
|
+
api: doSetup(config)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a set of callbacks with different default settings but the same state.
|
|
57
|
+
*/ function setupSub(options) {
|
|
58
|
+
return doSetup({
|
|
59
|
+
...this[config.Config],
|
|
60
|
+
...options
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function wrapAndBindImpl(instance, impl) {
|
|
64
|
+
function method(...args) {
|
|
65
|
+
level.setLevelRef(instance[config.Config], level.ApiLevel.Call);
|
|
66
|
+
return wrapAsync.wrapAsync(()=>impl.apply(instance, args).then(async (ret)=>{
|
|
67
|
+
await wait.wait(instance[config.Config]);
|
|
68
|
+
return ret;
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
Object.defineProperty(method, 'name', {
|
|
72
|
+
get: ()=>impl.name
|
|
73
|
+
});
|
|
74
|
+
return method;
|
|
75
|
+
}
|
|
76
|
+
function doSetup(config$1) {
|
|
77
|
+
const instance = {
|
|
78
|
+
[config.Config]: config$1,
|
|
79
|
+
dispatchUIEvent: index$2.bindDispatchUIEvent(config$1),
|
|
80
|
+
...api
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
...Object.fromEntries(Object.entries(api).map(([name, api])=>[
|
|
84
|
+
name,
|
|
85
|
+
wrapAndBindImpl(instance, api),
|
|
86
|
+
])),
|
|
87
|
+
setup: setupSub.bind(instance)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function getDocument(options, node, defaults) {
|
|
91
|
+
return (options.document ?? (node && getDocumentFromNode.getDocumentFromNode(node))) ?? defaults.document;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.createConfig = createConfig;
|
|
95
|
+
exports.setupDirect = setupDirect;
|
|
96
|
+
exports.setupMain = setupMain;
|
|
97
|
+
exports.setupSub = setupSub;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dom = require('@testing-library/dom');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wrap an internal Promise
|
|
9
|
+
*/ function wrapAsync(implementation) {
|
|
10
|
+
return dom.getConfig().asyncWrapper(implementation);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.wrapAsync = wrapAsync;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var keyboard = require('./keyboard.js');
|
|
6
|
+
var index = require('./pointer/index.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
10
|
+
*/ class System {
|
|
11
|
+
keyboard = new keyboard.KeyboardHost(this);
|
|
12
|
+
pointer = new index.PointerHost(this);
|
|
13
|
+
getUIEventModifiers() {
|
|
14
|
+
return {
|
|
15
|
+
altKey: this.keyboard.modifiers.Alt,
|
|
16
|
+
ctrlKey: this.keyboard.modifiers.Control,
|
|
17
|
+
metaKey: this.keyboard.modifiers.Meta,
|
|
18
|
+
shiftKey: this.keyboard.modifiers.Shift,
|
|
19
|
+
modifierAltGraph: this.keyboard.modifiers.AltGraph,
|
|
20
|
+
modifierCapsLock: this.keyboard.modifiers.CapsLock,
|
|
21
|
+
modifierFn: this.keyboard.modifiers.Fn,
|
|
22
|
+
modifierFnLock: this.keyboard.modifiers.FnLock,
|
|
23
|
+
modifierNumLock: this.keyboard.modifiers.NumLock,
|
|
24
|
+
modifierScrollLock: this.keyboard.modifiers.ScrollLock,
|
|
25
|
+
modifierSymbol: this.keyboard.modifiers.Symbol,
|
|
26
|
+
modifierSymbolLock: this.keyboard.modifiers.SymbolLock
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.System = System;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index = require('../event/index.js');
|
|
6
|
+
require('../utils/click/isClickableInput.js');
|
|
7
|
+
require('../utils/dataTransfer/Clipboard.js');
|
|
8
|
+
require('../utils/edit/maxLength.js');
|
|
9
|
+
require('../utils/edit/isEditable.js');
|
|
10
|
+
require('@testing-library/dom');
|
|
11
|
+
var getActiveElement = require('../utils/focus/getActiveElement.js');
|
|
12
|
+
require('@testing-library/dom/dist/helpers.js');
|
|
13
|
+
require('../utils/keyDef/readNextDescriptor.js');
|
|
14
|
+
require('../utils/misc/level.js');
|
|
15
|
+
require('../options.js');
|
|
16
|
+
|
|
17
|
+
exports.DOM_KEY_LOCATION = void 0;
|
|
18
|
+
(function(DOM_KEY_LOCATION) {
|
|
19
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["STANDARD"] = 0] = "STANDARD";
|
|
20
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["LEFT"] = 1] = "LEFT";
|
|
21
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["RIGHT"] = 2] = "RIGHT";
|
|
22
|
+
DOM_KEY_LOCATION[DOM_KEY_LOCATION["NUMPAD"] = 3] = "NUMPAD";
|
|
23
|
+
})(exports.DOM_KEY_LOCATION || (exports.DOM_KEY_LOCATION = {}));
|
|
24
|
+
const modifierKeys = [
|
|
25
|
+
'Alt',
|
|
26
|
+
'AltGraph',
|
|
27
|
+
'Control',
|
|
28
|
+
'Fn',
|
|
29
|
+
'Meta',
|
|
30
|
+
'Shift',
|
|
31
|
+
'Symbol',
|
|
32
|
+
];
|
|
33
|
+
function isModifierKey(key) {
|
|
34
|
+
return modifierKeys.includes(key);
|
|
35
|
+
}
|
|
36
|
+
const modifierLocks = [
|
|
37
|
+
'CapsLock',
|
|
38
|
+
'FnLock',
|
|
39
|
+
'NumLock',
|
|
40
|
+
'ScrollLock',
|
|
41
|
+
'SymbolLock',
|
|
42
|
+
];
|
|
43
|
+
function isModifierLock(key) {
|
|
44
|
+
return modifierLocks.includes(key);
|
|
45
|
+
}
|
|
46
|
+
class KeyboardHost {
|
|
47
|
+
constructor(system){
|
|
48
|
+
this.system = system;
|
|
49
|
+
}
|
|
50
|
+
modifiers = {
|
|
51
|
+
Alt: false,
|
|
52
|
+
AltGraph: false,
|
|
53
|
+
CapsLock: false,
|
|
54
|
+
Control: false,
|
|
55
|
+
Fn: false,
|
|
56
|
+
FnLock: false,
|
|
57
|
+
Meta: false,
|
|
58
|
+
NumLock: false,
|
|
59
|
+
ScrollLock: false,
|
|
60
|
+
Shift: false,
|
|
61
|
+
Symbol: false,
|
|
62
|
+
SymbolLock: false
|
|
63
|
+
};
|
|
64
|
+
pressed = {};
|
|
65
|
+
carryChar = '';
|
|
66
|
+
lastKeydownTarget = undefined;
|
|
67
|
+
modifierLockStart = {};
|
|
68
|
+
isKeyPressed(keyDef) {
|
|
69
|
+
return !!this.pressed[String(keyDef.code)];
|
|
70
|
+
}
|
|
71
|
+
getPressedKeys() {
|
|
72
|
+
return Object.values(this.pressed).map((p)=>p.keyDef);
|
|
73
|
+
}
|
|
74
|
+
/** Press a key */ async keydown(config, keyDef) {
|
|
75
|
+
const key = String(keyDef.key);
|
|
76
|
+
const code = String(keyDef.code);
|
|
77
|
+
const target = getActiveElement.getActiveElementOrBody(config.document);
|
|
78
|
+
this.setKeydownTarget(target);
|
|
79
|
+
this.pressed[code] ??= {
|
|
80
|
+
keyDef,
|
|
81
|
+
unpreventedDefault: false
|
|
82
|
+
};
|
|
83
|
+
if (isModifierKey(key)) {
|
|
84
|
+
this.modifiers[key] = true;
|
|
85
|
+
}
|
|
86
|
+
const unprevented = index.dispatchUIEvent(config, target, 'keydown', {
|
|
87
|
+
key,
|
|
88
|
+
code
|
|
89
|
+
});
|
|
90
|
+
if (isModifierLock(key) && !this.modifiers[key]) {
|
|
91
|
+
this.modifiers[key] = true;
|
|
92
|
+
this.modifierLockStart[key] = true;
|
|
93
|
+
}
|
|
94
|
+
this.pressed[code].unpreventedDefault ||= unprevented;
|
|
95
|
+
if (unprevented && this.hasKeyPress(key)) {
|
|
96
|
+
index.dispatchUIEvent(config, getActiveElement.getActiveElementOrBody(config.document), 'keypress', {
|
|
97
|
+
key,
|
|
98
|
+
code,
|
|
99
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Release a key */ async keyup(config, keyDef) {
|
|
104
|
+
const key = String(keyDef.key);
|
|
105
|
+
const code = String(keyDef.code);
|
|
106
|
+
const unprevented = this.pressed[code].unpreventedDefault;
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
108
|
+
delete this.pressed[code];
|
|
109
|
+
if (isModifierKey(key) && !Object.values(this.pressed).find((p)=>p.keyDef.key === key)) {
|
|
110
|
+
this.modifiers[key] = false;
|
|
111
|
+
}
|
|
112
|
+
index.dispatchUIEvent(config, getActiveElement.getActiveElementOrBody(config.document), 'keyup', {
|
|
113
|
+
key,
|
|
114
|
+
code
|
|
115
|
+
}, !unprevented);
|
|
116
|
+
if (isModifierLock(key) && this.modifiers[key]) {
|
|
117
|
+
if (this.modifierLockStart[key]) {
|
|
118
|
+
this.modifierLockStart[key] = false;
|
|
119
|
+
} else {
|
|
120
|
+
this.modifiers[key] = false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
setKeydownTarget(target) {
|
|
125
|
+
if (target !== this.lastKeydownTarget) {
|
|
126
|
+
this.carryChar = '';
|
|
127
|
+
}
|
|
128
|
+
this.lastKeydownTarget = target;
|
|
129
|
+
}
|
|
130
|
+
hasKeyPress(key) {
|
|
131
|
+
return (key.length === 1 || key === 'Enter') && !this.modifiers.Control && !this.modifiers.Alt;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.KeyboardHost = KeyboardHost;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class Buttons {
|
|
6
|
+
pressed = {};
|
|
7
|
+
getButtons() {
|
|
8
|
+
let v = 0;
|
|
9
|
+
for (const button of Object.keys(this.pressed)){
|
|
10
|
+
// eslint-disable-next-line no-bitwise
|
|
11
|
+
v |= 2 ** Number(button);
|
|
12
|
+
}
|
|
13
|
+
return v;
|
|
14
|
+
}
|
|
15
|
+
down(keyDef) {
|
|
16
|
+
const button = getMouseButtonId(keyDef.button);
|
|
17
|
+
if (button in this.pressed) {
|
|
18
|
+
this.pressed[button].push(keyDef);
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
this.pressed[button] = [
|
|
22
|
+
keyDef
|
|
23
|
+
];
|
|
24
|
+
return button;
|
|
25
|
+
}
|
|
26
|
+
up(keyDef) {
|
|
27
|
+
const button = getMouseButtonId(keyDef.button);
|
|
28
|
+
if (button in this.pressed) {
|
|
29
|
+
this.pressed[button] = this.pressed[button].filter((k)=>k.name !== keyDef.name);
|
|
30
|
+
if (this.pressed[button].length === 0) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
32
|
+
delete this.pressed[button];
|
|
33
|
+
return button;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const MouseButton = {
|
|
40
|
+
primary: 0,
|
|
41
|
+
secondary: 1,
|
|
42
|
+
auxiliary: 2,
|
|
43
|
+
back: 3,
|
|
44
|
+
X1: 3,
|
|
45
|
+
forward: 4,
|
|
46
|
+
X2: 4
|
|
47
|
+
};
|
|
48
|
+
function getMouseButtonId(button = 0) {
|
|
49
|
+
if (button in MouseButton) {
|
|
50
|
+
return MouseButton[button];
|
|
51
|
+
}
|
|
52
|
+
return Number(button);
|
|
53
|
+
}
|
|
54
|
+
// On the `MouseEvent.button` property auxiliary and secondary button are flipped compared to `MouseEvent.buttons`.
|
|
55
|
+
const MouseButtonFlip = {
|
|
56
|
+
1: 2,
|
|
57
|
+
2: 1
|
|
58
|
+
};
|
|
59
|
+
function getMouseEventButton(button) {
|
|
60
|
+
button = getMouseButtonId(button);
|
|
61
|
+
if (button in MouseButtonFlip) {
|
|
62
|
+
return MouseButtonFlip[button];
|
|
63
|
+
}
|
|
64
|
+
return button;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.Buttons = Buttons;
|
|
68
|
+
exports.MouseButton = MouseButton;
|
|
69
|
+
exports.MouseButtonFlip = MouseButtonFlip;
|
|
70
|
+
exports.getMouseButtonId = getMouseButtonId;
|
|
71
|
+
exports.getMouseEventButton = getMouseEventButton;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class Device {
|
|
6
|
+
pressedKeys = new Set();
|
|
7
|
+
get countPressed() {
|
|
8
|
+
return this.pressedKeys.size;
|
|
9
|
+
}
|
|
10
|
+
isPressed(keyDef) {
|
|
11
|
+
return this.pressedKeys.has(keyDef.name);
|
|
12
|
+
}
|
|
13
|
+
addPressed(keyDef) {
|
|
14
|
+
return this.pressedKeys.add(keyDef.name);
|
|
15
|
+
}
|
|
16
|
+
removePressed(keyDef) {
|
|
17
|
+
return this.pressedKeys.delete(keyDef.name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.Device = Device;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var buttons = require('./buttons.js');
|
|
6
|
+
var device = require('./device.js');
|
|
7
|
+
var mouse = require('./mouse.js');
|
|
8
|
+
var pointer = require('./pointer.js');
|
|
9
|
+
|
|
10
|
+
class PointerHost {
|
|
11
|
+
constructor(system){
|
|
12
|
+
this.system = system;
|
|
13
|
+
this.buttons = new buttons.Buttons();
|
|
14
|
+
this.mouse = new mouse.Mouse();
|
|
15
|
+
}
|
|
16
|
+
devices = new class {
|
|
17
|
+
registry = {};
|
|
18
|
+
get(k) {
|
|
19
|
+
this.registry[k] ??= new device.Device();
|
|
20
|
+
return this.registry[k];
|
|
21
|
+
}
|
|
22
|
+
}();
|
|
23
|
+
pointers = new class {
|
|
24
|
+
registry = {
|
|
25
|
+
mouse: new pointer.Pointer({
|
|
26
|
+
pointerId: 1,
|
|
27
|
+
pointerType: 'mouse',
|
|
28
|
+
isPrimary: true
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
nextId = 2;
|
|
32
|
+
new(pointerName, keyDef) {
|
|
33
|
+
const isPrimary = keyDef.pointerType !== 'touch' || !Object.values(this.registry).some((p)=>p.pointerType === 'touch' && !p.isCancelled);
|
|
34
|
+
if (!isPrimary) {
|
|
35
|
+
Object.values(this.registry).forEach((p)=>{
|
|
36
|
+
if (p.pointerType === keyDef.pointerType && !p.isCancelled) {
|
|
37
|
+
p.isMultitouch = true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.registry[pointerName] = new pointer.Pointer({
|
|
42
|
+
pointerId: this.nextId++,
|
|
43
|
+
pointerType: keyDef.pointerType,
|
|
44
|
+
isPrimary
|
|
45
|
+
});
|
|
46
|
+
return this.registry[pointerName];
|
|
47
|
+
}
|
|
48
|
+
get(pointerName) {
|
|
49
|
+
if (!this.has(pointerName)) {
|
|
50
|
+
throw new Error(`Trying to access pointer "${pointerName}" which does not exist.`);
|
|
51
|
+
}
|
|
52
|
+
return this.registry[pointerName];
|
|
53
|
+
}
|
|
54
|
+
has(pointerName) {
|
|
55
|
+
return pointerName in this.registry;
|
|
56
|
+
}
|
|
57
|
+
}();
|
|
58
|
+
isKeyPressed(keyDef) {
|
|
59
|
+
return this.devices.get(keyDef.pointerType).isPressed(keyDef);
|
|
60
|
+
}
|
|
61
|
+
async press(config, keyDef, position) {
|
|
62
|
+
const pointerName = this.getPointerName(keyDef);
|
|
63
|
+
const pointer = keyDef.pointerType === 'touch' ? this.pointers.new(pointerName, keyDef).init(config, position) : this.pointers.get(pointerName);
|
|
64
|
+
// TODO: deprecate the following implicit setting of position
|
|
65
|
+
pointer.position = position;
|
|
66
|
+
if (pointer.pointerType !== 'touch') {
|
|
67
|
+
this.mouse.position = position;
|
|
68
|
+
}
|
|
69
|
+
this.devices.get(keyDef.pointerType).addPressed(keyDef);
|
|
70
|
+
this.buttons.down(keyDef);
|
|
71
|
+
pointer.down(config, keyDef);
|
|
72
|
+
if (pointer.pointerType !== 'touch' && !pointer.isPrevented) {
|
|
73
|
+
this.mouse.down(config, keyDef, pointer);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async move(config, pointerName, position) {
|
|
77
|
+
const pointer = this.pointers.get(pointerName);
|
|
78
|
+
// In (some?) browsers this order of events can be observed.
|
|
79
|
+
// This interweaving of events is probably unnecessary.
|
|
80
|
+
// While the order of mouse (or pointer) events is defined per spec,
|
|
81
|
+
// the order in which they interweave/follow on a user interaction depends on the implementation.
|
|
82
|
+
const pointermove = pointer.move(config, position);
|
|
83
|
+
const mousemove = pointer.pointerType === 'touch' || pointer.isPrevented && pointer.isDown ? undefined : this.mouse.move(config, position);
|
|
84
|
+
pointermove?.leave();
|
|
85
|
+
mousemove?.leave();
|
|
86
|
+
pointermove?.enter();
|
|
87
|
+
mousemove?.enter();
|
|
88
|
+
pointermove?.move();
|
|
89
|
+
mousemove?.move();
|
|
90
|
+
}
|
|
91
|
+
async release(config, keyDef, position) {
|
|
92
|
+
const device = this.devices.get(keyDef.pointerType);
|
|
93
|
+
device.removePressed(keyDef);
|
|
94
|
+
this.buttons.up(keyDef);
|
|
95
|
+
const pointer = this.pointers.get(this.getPointerName(keyDef));
|
|
96
|
+
// TODO: deprecate the following implicit setting of position
|
|
97
|
+
pointer.position = position;
|
|
98
|
+
if (pointer.pointerType !== 'touch') {
|
|
99
|
+
this.mouse.position = position;
|
|
100
|
+
}
|
|
101
|
+
if (device.countPressed === 0) {
|
|
102
|
+
pointer.up(config, keyDef);
|
|
103
|
+
}
|
|
104
|
+
if (pointer.pointerType === 'touch') {
|
|
105
|
+
pointer.release(config);
|
|
106
|
+
}
|
|
107
|
+
if (!pointer.isPrevented) {
|
|
108
|
+
if (pointer.pointerType === 'touch' && !pointer.isMultitouch) {
|
|
109
|
+
const mousemove = this.mouse.move(config, pointer.position);
|
|
110
|
+
mousemove?.leave();
|
|
111
|
+
mousemove?.enter();
|
|
112
|
+
mousemove?.move();
|
|
113
|
+
this.mouse.down(config, keyDef, pointer);
|
|
114
|
+
}
|
|
115
|
+
if (!pointer.isMultitouch) {
|
|
116
|
+
const mousemove1 = this.mouse.move(config, pointer.position);
|
|
117
|
+
mousemove1?.leave();
|
|
118
|
+
mousemove1?.enter();
|
|
119
|
+
mousemove1?.move();
|
|
120
|
+
this.mouse.up(config, keyDef, pointer);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getPointerName(keyDef) {
|
|
125
|
+
return keyDef.pointerType === 'touch' ? keyDef.name : keyDef.pointerType;
|
|
126
|
+
}
|
|
127
|
+
getPreviousPosition(pointerName) {
|
|
128
|
+
return this.pointers.has(pointerName) ? this.pointers.get(pointerName).position : undefined;
|
|
129
|
+
}
|
|
130
|
+
resetClickCount() {
|
|
131
|
+
this.mouse.resetClickCount();
|
|
132
|
+
}
|
|
133
|
+
getMouseTarget(config) {
|
|
134
|
+
return this.mouse.position.target ?? config.document.body;
|
|
135
|
+
}
|
|
136
|
+
setMousePosition(position) {
|
|
137
|
+
this.mouse.position = position;
|
|
138
|
+
this.pointers.get('mouse').position = position;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function isDifferentPointerPosition(positionA, positionB) {
|
|
142
|
+
return positionA.target !== positionB.target || positionA.coords?.x !== positionB.coords?.y || positionA.coords?.y !== positionB.coords?.y || positionA.caret?.node !== positionB.caret?.node || positionA.caret?.offset !== positionB.caret?.offset;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
exports.PointerHost = PointerHost;
|
|
146
|
+
exports.isDifferentPointerPosition = isDifferentPointerPosition;
|