@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,36 @@
|
|
|
1
|
+
import { getUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { getNextCursorPosition } from '../../utils/focus/cursor.js';
|
|
4
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
5
|
+
import { setSelection } from './setSelection.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Move the selection
|
|
9
|
+
*/ function moveSelection(node, direction) {
|
|
10
|
+
// TODO: implement shift
|
|
11
|
+
if (hasOwnSelection(node)) {
|
|
12
|
+
const selection = getUISelection(node);
|
|
13
|
+
setSelection({
|
|
14
|
+
focusNode: node,
|
|
15
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
const selection = node.ownerDocument.getSelection();
|
|
19
|
+
if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (selection.isCollapsed) {
|
|
23
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
24
|
+
if (nextPosition) {
|
|
25
|
+
setSelection({
|
|
26
|
+
focusNode: nextPosition.node,
|
|
27
|
+
focusOffset: nextPosition.offset
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
selection[direction < 0 ? 'collapseToStart' : 'collapseToEnd']();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { moveSelection };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getUIValue } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
4
|
+
|
|
5
|
+
function resolveCaretPosition({ target, node, offset }) {
|
|
6
|
+
if (hasOwnSelection(target)) {
|
|
7
|
+
return {
|
|
8
|
+
node: target,
|
|
9
|
+
offset: offset !== null && offset !== void 0 ? offset : getUIValue(target).length
|
|
10
|
+
};
|
|
11
|
+
} else if (node) {
|
|
12
|
+
return {
|
|
13
|
+
node,
|
|
14
|
+
offset: offset !== null && offset !== void 0 ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return findNodeAtTextOffset(target, offset);
|
|
18
|
+
}
|
|
19
|
+
function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
20
|
+
// When clicking after the content the browser behavior can be complicated:
|
|
21
|
+
// 1. If there is textContent after the last element child,
|
|
22
|
+
// the cursor is moved there.
|
|
23
|
+
// 2. If there is textContent in the last element child,
|
|
24
|
+
// the browser moves the cursor to the last non-empty text node inside this element.
|
|
25
|
+
// 3. Otherwise the cursor is moved to the end of the target.
|
|
26
|
+
let i = offset === undefined ? node.childNodes.length - 1 : 0;
|
|
27
|
+
const step = offset === undefined ? -1 : 1;
|
|
28
|
+
while(offset === undefined ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length){
|
|
29
|
+
if (offset && i === node.childNodes.length) {
|
|
30
|
+
throw new Error('The given offset is out of bounds.');
|
|
31
|
+
}
|
|
32
|
+
const c = node.childNodes.item(i);
|
|
33
|
+
const text = String(c.textContent);
|
|
34
|
+
if (text.length) {
|
|
35
|
+
if (offset !== undefined && text.length < offset) {
|
|
36
|
+
offset -= text.length;
|
|
37
|
+
} else if (c.nodeType === 1) {
|
|
38
|
+
return findNodeAtTextOffset(c, offset, false);
|
|
39
|
+
} else {
|
|
40
|
+
// The pre-commit hooks keeps changing this
|
|
41
|
+
// See https://github.com/kentcdodds/kcd-scripts/issues/218
|
|
42
|
+
/* istanbul ignore else */ if (c.nodeType === 3) {
|
|
43
|
+
return {
|
|
44
|
+
node: c,
|
|
45
|
+
offset: offset !== null && offset !== void 0 ? offset : c.nodeValue.length
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
i += step;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
node,
|
|
54
|
+
offset: node.childNodes.length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { resolveCaretPosition };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getUISelection, getUIValue } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { getContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
4
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
5
|
+
import { setSelection } from './setSelection.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Expand a selection like the browser does when pressing Ctrl+A.
|
|
9
|
+
*/ function selectAll(target) {
|
|
10
|
+
var _getContentEditable;
|
|
11
|
+
if (hasOwnSelection(target)) {
|
|
12
|
+
return setSelection({
|
|
13
|
+
focusNode: target,
|
|
14
|
+
anchorOffset: 0,
|
|
15
|
+
focusOffset: getUIValue(target).length
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
19
|
+
setSelection({
|
|
20
|
+
focusNode,
|
|
21
|
+
anchorOffset: 0,
|
|
22
|
+
focusOffset: focusNode.childNodes.length
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function isAllSelected(target) {
|
|
26
|
+
var _getContentEditable;
|
|
27
|
+
if (hasOwnSelection(target)) {
|
|
28
|
+
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
29
|
+
}
|
|
30
|
+
const focusNode = (_getContentEditable = getContentEditable(target)) !== null && _getContentEditable !== void 0 ? _getContentEditable : target.ownerDocument.body;
|
|
31
|
+
const selection = target.ownerDocument.getSelection();
|
|
32
|
+
return (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { isAllSelected, selectAll };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { setUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { getTargetTypeAndSelection } from './getTargetTypeAndSelection.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set the selection
|
|
7
|
+
*/ function setSelection({ focusNode, focusOffset, anchorNode = focusNode, anchorOffset = focusOffset }) {
|
|
8
|
+
var _anchorNode_ownerDocument_getSelection, _anchorNode_ownerDocument;
|
|
9
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
10
|
+
if (typeAndSelection.type === 'input') {
|
|
11
|
+
return setUISelection(focusNode, {
|
|
12
|
+
anchorOffset,
|
|
13
|
+
focusOffset
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
(_anchorNode_ownerDocument = anchorNode.ownerDocument) === null || _anchorNode_ownerDocument === void 0 ? void 0 : (_anchorNode_ownerDocument_getSelection = _anchorNode_ownerDocument.getSelection()) === null || _anchorNode_ownerDocument_getSelection === void 0 ? void 0 : _anchorNode_ownerDocument_getSelection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { setSelection };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { getUIValue, setUISelection } from '../../document/UI.js';
|
|
2
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
3
|
+
import { hasNoSelection, hasOwnSelection } from '../../utils/focus/selection.js';
|
|
4
|
+
import { resolveCaretPosition } from './resolveCaretPosition.js';
|
|
5
|
+
|
|
6
|
+
function setSelectionPerMouseDown({ document, target, clickCount, node, offset }) {
|
|
7
|
+
if (hasNoSelection(target)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const targetHasOwnSelection = hasOwnSelection(target);
|
|
11
|
+
// On non-input elements the text selection per multiple click
|
|
12
|
+
// can extend beyond the target boundaries.
|
|
13
|
+
// The exact mechanism what is considered in the same line is unclear.
|
|
14
|
+
// Looks it might be every inline element.
|
|
15
|
+
// TODO: Check what might be considered part of the same line of text.
|
|
16
|
+
const text = String(targetHasOwnSelection ? getUIValue(target) : target.textContent);
|
|
17
|
+
const [start, end] = node ? [
|
|
18
|
+
offset,
|
|
19
|
+
offset
|
|
20
|
+
] : getTextRange(text, offset, clickCount);
|
|
21
|
+
// TODO: implement modifying selection per shift/ctrl+mouse
|
|
22
|
+
if (targetHasOwnSelection) {
|
|
23
|
+
setUISelection(target, {
|
|
24
|
+
anchorOffset: start !== null && start !== void 0 ? start : text.length,
|
|
25
|
+
focusOffset: end !== null && end !== void 0 ? end : text.length
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
node: target,
|
|
29
|
+
start: start !== null && start !== void 0 ? start : 0,
|
|
30
|
+
end: end !== null && end !== void 0 ? end : text.length
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
const { node: startNode, offset: startOffset } = resolveCaretPosition({
|
|
34
|
+
target,
|
|
35
|
+
node,
|
|
36
|
+
offset: start
|
|
37
|
+
});
|
|
38
|
+
const { node: endNode, offset: endOffset } = resolveCaretPosition({
|
|
39
|
+
target,
|
|
40
|
+
node,
|
|
41
|
+
offset: end
|
|
42
|
+
});
|
|
43
|
+
const range = target.ownerDocument.createRange();
|
|
44
|
+
try {
|
|
45
|
+
range.setStart(startNode, startOffset);
|
|
46
|
+
range.setEnd(endNode, endOffset);
|
|
47
|
+
} catch {
|
|
48
|
+
throw new Error('The given offset is out of bounds.');
|
|
49
|
+
}
|
|
50
|
+
const selection = document.getSelection();
|
|
51
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
52
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(range.cloneRange());
|
|
53
|
+
return range;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function getTextRange(text, pos, clickCount) {
|
|
57
|
+
if (clickCount % 3 === 1 || text.length === 0) {
|
|
58
|
+
return [
|
|
59
|
+
pos,
|
|
60
|
+
pos
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
const textPos = pos !== null && pos !== void 0 ? pos : text.length;
|
|
64
|
+
if (clickCount % 3 === 2) {
|
|
65
|
+
return [
|
|
66
|
+
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
|
|
67
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
// triple click
|
|
71
|
+
return [
|
|
72
|
+
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
|
|
73
|
+
pos === undefined ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { setSelectionPerMouseDown };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
2
|
+
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
3
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
4
|
+
import { setSelection } from './setSelection.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Backward-compatible selection.
|
|
8
|
+
*
|
|
9
|
+
* Handles input elements and contenteditable if it only contains a single text node.
|
|
10
|
+
*/ function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
11
|
+
var _element_firstChild;
|
|
12
|
+
if (hasOwnSelection(element)) {
|
|
13
|
+
return setSelection({
|
|
14
|
+
focusNode: element,
|
|
15
|
+
anchorOffset,
|
|
16
|
+
focusOffset
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/* istanbul ignore else */ if (isContentEditable(element) && ((_element_firstChild = element.firstChild) === null || _element_firstChild === void 0 ? void 0 : _element_firstChild.nodeType) === 3) {
|
|
20
|
+
return setSelection({
|
|
21
|
+
focusNode: element.firstChild,
|
|
22
|
+
anchorOffset,
|
|
23
|
+
focusOffset
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/* istanbul ignore next */ throw new Error('Not implemented. The result of this interaction is unreliable.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { setSelectionRange };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import '../../utils/dataTransfer/Clipboard.js';
|
|
2
|
+
import { getContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
3
|
+
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
4
|
+
|
|
5
|
+
// The browser implementation seems to have changed.
|
|
6
|
+
// When focus is inside <input type="text"/>,
|
|
7
|
+
// Chrome updates Selection to be collapsed at the position of the input element.
|
|
8
|
+
// TODO: update implementation to match that of current browsers
|
|
9
|
+
/**
|
|
10
|
+
* Reset the Document Selection when moving focus into an element
|
|
11
|
+
* with own selection implementation.
|
|
12
|
+
*/ function updateSelectionOnFocus(element) {
|
|
13
|
+
const selection = element.ownerDocument.getSelection();
|
|
14
|
+
/* istanbul ignore if */ if (!(selection === null || selection === void 0 ? void 0 : selection.focusNode)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// If the focus moves inside an element with own selection implementation,
|
|
18
|
+
// the document selection will be this element.
|
|
19
|
+
// But if the focused element is inside a contenteditable,
|
|
20
|
+
// 1) a collapsed selection will be retained.
|
|
21
|
+
// 2) other selections will be replaced by a cursor
|
|
22
|
+
// 2.a) at the start of the first child if it is a text node
|
|
23
|
+
// 2.b) at the start of the contenteditable.
|
|
24
|
+
if (hasOwnSelection(element)) {
|
|
25
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
26
|
+
if (contenteditable) {
|
|
27
|
+
if (!selection.isCollapsed) {
|
|
28
|
+
var _contenteditable_firstChild;
|
|
29
|
+
const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
30
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { updateSelectionOnFocus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
2
|
+
import { wait } from '../utils/misc/wait.js';
|
|
3
|
+
import { parseKeyDef } from './parseKeyDef.js';
|
|
4
|
+
|
|
5
|
+
async function keyboard(text) {
|
|
6
|
+
const actions = parseKeyDef(this.config.keyboardMap, text);
|
|
7
|
+
for(let i = 0; i < actions.length; i++){
|
|
8
|
+
await wait(this.config);
|
|
9
|
+
await keyboardAction(this, actions[i]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
13
|
+
const { system } = instance;
|
|
14
|
+
// Release the key automatically if it was pressed before.
|
|
15
|
+
if (system.keyboard.isKeyPressed(keyDef)) {
|
|
16
|
+
await system.keyboard.keyup(instance, keyDef);
|
|
17
|
+
}
|
|
18
|
+
if (!releasePrevious) {
|
|
19
|
+
for(let i = 1; i <= repeat; i++){
|
|
20
|
+
await system.keyboard.keydown(instance, keyDef);
|
|
21
|
+
if (i < repeat) {
|
|
22
|
+
await wait(instance.config);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Release the key only on the last iteration on `state.repeatKey`.
|
|
26
|
+
if (releaseSelf) {
|
|
27
|
+
await system.keyboard.keyup(instance, keyDef);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function releaseAllKeys(instance) {
|
|
32
|
+
for (const k of instance.system.keyboard.getPressedKeys()){
|
|
33
|
+
await instance.system.keyboard.keyup(instance, k);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { keyboard, releaseAllKeys };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { DOM_KEY_LOCATION } from '../system/keyboard.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mapping for a default US-104-QWERTY keyboard
|
|
5
|
+
*/ const defaultKeyMap = [
|
|
6
|
+
// alphanumeric block - writing system
|
|
7
|
+
...'0123456789'.split('').map((c)=>({
|
|
8
|
+
code: `Digit${c}`,
|
|
9
|
+
key: c
|
|
10
|
+
})),
|
|
11
|
+
...')!@#$%^&*('.split('').map((c, i)=>({
|
|
12
|
+
code: `Digit${i}`,
|
|
13
|
+
key: c,
|
|
14
|
+
shiftKey: true
|
|
15
|
+
})),
|
|
16
|
+
...'abcdefghijklmnopqrstuvwxyz'.split('').map((c)=>({
|
|
17
|
+
code: `Key${c.toUpperCase()}`,
|
|
18
|
+
key: c
|
|
19
|
+
})),
|
|
20
|
+
...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map((c)=>({
|
|
21
|
+
code: `Key${c}`,
|
|
22
|
+
key: c,
|
|
23
|
+
shiftKey: true
|
|
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
|
+
},
|
|
43
|
+
// alphanumeric block - functional
|
|
44
|
+
{
|
|
45
|
+
code: 'Space',
|
|
46
|
+
key: ' '
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: 'AltLeft',
|
|
50
|
+
key: 'Alt',
|
|
51
|
+
location: DOM_KEY_LOCATION.LEFT
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
code: 'AltRight',
|
|
55
|
+
key: 'Alt',
|
|
56
|
+
location: DOM_KEY_LOCATION.RIGHT
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
code: 'ShiftLeft',
|
|
60
|
+
key: 'Shift',
|
|
61
|
+
location: DOM_KEY_LOCATION.LEFT
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
code: 'ShiftRight',
|
|
65
|
+
key: 'Shift',
|
|
66
|
+
location: DOM_KEY_LOCATION.RIGHT
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
code: 'ControlLeft',
|
|
70
|
+
key: 'Control',
|
|
71
|
+
location: DOM_KEY_LOCATION.LEFT
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
code: 'ControlRight',
|
|
75
|
+
key: 'Control',
|
|
76
|
+
location: DOM_KEY_LOCATION.RIGHT
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
code: 'MetaLeft',
|
|
80
|
+
key: 'Meta',
|
|
81
|
+
location: DOM_KEY_LOCATION.LEFT
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
code: 'MetaRight',
|
|
85
|
+
key: 'Meta',
|
|
86
|
+
location: DOM_KEY_LOCATION.RIGHT
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
code: 'OSLeft',
|
|
90
|
+
key: 'OS',
|
|
91
|
+
location: DOM_KEY_LOCATION.LEFT
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
code: 'OSRight',
|
|
95
|
+
key: 'OS',
|
|
96
|
+
location: DOM_KEY_LOCATION.RIGHT
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
code: 'ContextMenu',
|
|
100
|
+
key: 'ContextMenu'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
code: 'Tab',
|
|
104
|
+
key: 'Tab'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
code: 'CapsLock',
|
|
108
|
+
key: 'CapsLock'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
code: 'Backspace',
|
|
112
|
+
key: 'Backspace'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
code: 'Enter',
|
|
116
|
+
key: 'Enter'
|
|
117
|
+
},
|
|
118
|
+
// function
|
|
119
|
+
{
|
|
120
|
+
code: 'Escape',
|
|
121
|
+
key: 'Escape'
|
|
122
|
+
},
|
|
123
|
+
// arrows
|
|
124
|
+
{
|
|
125
|
+
code: 'ArrowUp',
|
|
126
|
+
key: 'ArrowUp'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
code: 'ArrowDown',
|
|
130
|
+
key: 'ArrowDown'
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
code: 'ArrowLeft',
|
|
134
|
+
key: 'ArrowLeft'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
code: 'ArrowRight',
|
|
138
|
+
key: 'ArrowRight'
|
|
139
|
+
},
|
|
140
|
+
// control pad
|
|
141
|
+
{
|
|
142
|
+
code: 'Home',
|
|
143
|
+
key: 'Home'
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
code: 'End',
|
|
147
|
+
key: 'End'
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
code: 'Delete',
|
|
151
|
+
key: 'Delete'
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
code: 'PageUp',
|
|
155
|
+
key: 'PageUp'
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
code: 'PageDown',
|
|
159
|
+
key: 'PageDown'
|
|
160
|
+
},
|
|
161
|
+
// Special keys that are not part of a default US-layout but included for specific behavior
|
|
162
|
+
{
|
|
163
|
+
code: 'Fn',
|
|
164
|
+
key: 'Fn'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
code: 'Symbol',
|
|
168
|
+
key: 'Symbol'
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
code: 'AltRight',
|
|
172
|
+
key: 'AltGraph'
|
|
173
|
+
}
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
export { defaultKeyMap };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
2
|
+
import { readNextDescriptor } from '../utils/keyDef/readNextDescriptor.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse key definitions per `keyboardMap`
|
|
6
|
+
*
|
|
7
|
+
* Keys can be referenced by `{key}` or `{special}` as well as physical locations per `[code]`.
|
|
8
|
+
* Everything else will be interpreted as a typed character - e.g. `a`.
|
|
9
|
+
* Brackets `{` and `[` can be escaped by doubling - e.g. `foo[[bar` translates to `foo[bar`.
|
|
10
|
+
* Keeping the key pressed can be written as `{key>}`.
|
|
11
|
+
* When keeping the key pressed you can choose how long (how many keydown and keypress) the key is pressed `{key>3}`.
|
|
12
|
+
* You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
|
|
13
|
+
*/ function parseKeyDef(keyboardMap, text) {
|
|
14
|
+
const defs = [];
|
|
15
|
+
do {
|
|
16
|
+
var _keyboardMap_find;
|
|
17
|
+
const { type, descriptor, consumedLength, releasePrevious, releaseSelf = true, repeat } = readNextDescriptor(text, 'keyboard');
|
|
18
|
+
const keyDef = (_keyboardMap_find = keyboardMap.find((def)=>{
|
|
19
|
+
if (type === '[') {
|
|
20
|
+
var _def_code;
|
|
21
|
+
return ((_def_code = def.code) === null || _def_code === void 0 ? void 0 : _def_code.toLowerCase()) === descriptor.toLowerCase();
|
|
22
|
+
} else if (type === '{') {
|
|
23
|
+
var _def_key;
|
|
24
|
+
return ((_def_key = def.key) === null || _def_key === void 0 ? void 0 : _def_key.toLowerCase()) === descriptor.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
return def.key === descriptor;
|
|
27
|
+
})) !== null && _keyboardMap_find !== void 0 ? _keyboardMap_find : {
|
|
28
|
+
key: 'Unknown',
|
|
29
|
+
code: 'Unknown',
|
|
30
|
+
[type === '[' ? 'code' : 'key']: descriptor
|
|
31
|
+
};
|
|
32
|
+
defs.push({
|
|
33
|
+
keyDef,
|
|
34
|
+
releasePrevious,
|
|
35
|
+
releaseSelf,
|
|
36
|
+
repeat
|
|
37
|
+
});
|
|
38
|
+
text = text.slice(consumedLength);
|
|
39
|
+
}while (text)
|
|
40
|
+
return defs;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { parseKeyDef };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var PointerEventsCheckLevel = /*#__PURE__*/ function(PointerEventsCheckLevel) {
|
|
2
|
+
/**
|
|
3
|
+
* Check pointer events on every user interaction that triggers a bunch of events.
|
|
4
|
+
* E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
|
|
5
|
+
*/ PointerEventsCheckLevel[PointerEventsCheckLevel["EachTrigger"] = 4] = "EachTrigger";
|
|
6
|
+
/** Check each target once per call to pointer (related) API */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachApiCall"] = 2] = "EachApiCall";
|
|
7
|
+
/** Check each event target once */ PointerEventsCheckLevel[PointerEventsCheckLevel["EachTarget"] = 1] = "EachTarget";
|
|
8
|
+
/** No pointer events check */ PointerEventsCheckLevel[PointerEventsCheckLevel["Never"] = 0] = "Never";
|
|
9
|
+
return PointerEventsCheckLevel;
|
|
10
|
+
}({});
|
|
11
|
+
|
|
12
|
+
export { PointerEventsCheckLevel };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import '../utils/dataTransfer/Clipboard.js';
|
|
2
|
+
import { setLevelRef, ApiLevel } from '../utils/misc/level.js';
|
|
3
|
+
import { wait } from '../utils/misc/wait.js';
|
|
4
|
+
import { parseKeyDef } from './parseKeyDef.js';
|
|
5
|
+
|
|
6
|
+
async function pointer(input) {
|
|
7
|
+
const { pointerMap } = this.config;
|
|
8
|
+
const actions = [];
|
|
9
|
+
(Array.isArray(input) ? input : [
|
|
10
|
+
input
|
|
11
|
+
]).forEach((actionInput)=>{
|
|
12
|
+
if (typeof actionInput === 'string') {
|
|
13
|
+
actions.push(...parseKeyDef(pointerMap, actionInput));
|
|
14
|
+
} else if ('keys' in actionInput) {
|
|
15
|
+
actions.push(...parseKeyDef(pointerMap, actionInput.keys).map((i)=>({
|
|
16
|
+
...actionInput,
|
|
17
|
+
...i
|
|
18
|
+
})));
|
|
19
|
+
} else {
|
|
20
|
+
actions.push(actionInput);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
for(let i = 0; i < actions.length; i++){
|
|
24
|
+
await wait(this.config);
|
|
25
|
+
await pointerAction(this, actions[i]);
|
|
26
|
+
}
|
|
27
|
+
this.system.pointer.resetClickCount();
|
|
28
|
+
}
|
|
29
|
+
async function pointerAction(instance, action) {
|
|
30
|
+
var _action_target, _action_coords, _action_node, _action_offset;
|
|
31
|
+
var _previousPosition_caret, _previousPosition_caret1;
|
|
32
|
+
const pointerName = 'pointerName' in action && action.pointerName ? action.pointerName : 'keyDef' in action ? instance.system.pointer.getPointerName(action.keyDef) : 'mouse';
|
|
33
|
+
const previousPosition = instance.system.pointer.getPreviousPosition(pointerName);
|
|
34
|
+
const position = {
|
|
35
|
+
target: (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : getPrevTarget(instance, previousPosition),
|
|
36
|
+
coords: (_action_coords = action.coords) !== null && _action_coords !== void 0 ? _action_coords : previousPosition === null || previousPosition === void 0 ? void 0 : previousPosition.coords,
|
|
37
|
+
caret: {
|
|
38
|
+
node: (_action_node = action.node) !== null && _action_node !== void 0 ? _action_node : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret = previousPosition.caret) === null || _previousPosition_caret === void 0 ? void 0 : _previousPosition_caret.node,
|
|
39
|
+
offset: (_action_offset = action.offset) !== null && _action_offset !== void 0 ? _action_offset : hasCaretPosition(action) ? undefined : previousPosition === null || previousPosition === void 0 ? void 0 : (_previousPosition_caret1 = previousPosition.caret) === null || _previousPosition_caret1 === void 0 ? void 0 : _previousPosition_caret1.offset
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if ('keyDef' in action) {
|
|
43
|
+
if (instance.system.pointer.isKeyPressed(action.keyDef)) {
|
|
44
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
45
|
+
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
46
|
+
}
|
|
47
|
+
if (!action.releasePrevious) {
|
|
48
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
49
|
+
await instance.system.pointer.press(instance, action.keyDef, position);
|
|
50
|
+
if (action.releaseSelf) {
|
|
51
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
52
|
+
await instance.system.pointer.release(instance, action.keyDef, position);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
setLevelRef(instance, ApiLevel.Trigger);
|
|
57
|
+
await instance.system.pointer.move(instance, pointerName, position);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function hasCaretPosition(action) {
|
|
61
|
+
var _ref, _action_target;
|
|
62
|
+
return !!((_ref = (_action_target = action.target) !== null && _action_target !== void 0 ? _action_target : action.node) !== null && _ref !== void 0 ? _ref : action.offset !== undefined);
|
|
63
|
+
}
|
|
64
|
+
function getPrevTarget(instance, position) {
|
|
65
|
+
var _position_target;
|
|
66
|
+
if (!position) {
|
|
67
|
+
throw new Error('This pointer has no previous position. Provide a target property!');
|
|
68
|
+
}
|
|
69
|
+
return (_position_target = position.target) !== null && _position_target !== void 0 ? _position_target : instance.config.document.body;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { pointer };
|