@testing-library/user-event 14.0.0-beta.1 → 14.0.0-beta.12
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/README.md +5 -192
- package/dist/index.cjs +2878 -0
- package/dist/index.mjs +2949 -0
- package/dist/types/clipboard/copy.d.ts +2 -0
- package/dist/types/clipboard/cut.d.ts +2 -0
- package/dist/{clipboard → types/clipboard}/index.d.ts +0 -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/{convenience → types/convenience}/index.d.ts +0 -0
- package/dist/types/convenience/tab.d.ts +4 -0
- package/dist/{document → types/document}/index.d.ts +0 -0
- package/dist/{document → types/document}/interceptor.d.ts +0 -0
- package/dist/{document → types/document}/selection.d.ts +0 -0
- package/dist/{document → types/document}/value.d.ts +0 -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 +9 -0
- package/dist/types/event/createEvent.d.ts +8 -0
- package/dist/types/event/dispatchEvent.d.ts +2 -0
- package/dist/types/event/eventMap.d.ts +345 -0
- package/dist/types/event/eventTypes.d.ts +2 -0
- package/dist/types/event/index.d.ts +6 -0
- package/dist/types/event/types.d.ts +13 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/{index.d.ts → types/index.d.ts} +1 -0
- package/dist/{keyboard → types/keyboard}/index.d.ts +2 -2
- package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/keyboardAction.d.ts +0 -0
- package/dist/types/keyboard/modifiers.d.ts +9 -0
- package/dist/{keyboard → types/keyboard}/parseKeyDef.d.ts +0 -0
- package/dist/{keyboard → types/keyboard}/types.d.ts +19 -10
- package/dist/{options.d.ts → types/options.d.ts} +23 -8
- package/dist/types/pointer/firePointerEvents.d.ts +11 -0
- package/dist/{pointer → types/pointer}/index.d.ts +2 -2
- package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
- package/dist/{pointer → types/pointer}/parseKeyDef.d.ts +0 -0
- package/dist/{pointer → types/pointer}/pointerAction.d.ts +0 -0
- package/dist/types/pointer/pointerMove.d.ts +6 -0
- package/dist/{pointer → types/pointer}/pointerPress.d.ts +2 -2
- package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
- package/dist/{pointer → types/pointer}/types.d.ts +2 -1
- package/dist/{setup → types/setup}/api.d.ts +0 -0
- package/dist/{setup → types/setup}/config.d.ts +0 -0
- package/dist/{setup → types/setup}/directApi.d.ts +1 -2
- package/dist/{setup → types/setup}/index.d.ts +8 -2
- package/dist/types/setup/setup.d.ts +20 -0
- package/dist/{setup → types/setup}/wrapAsync.d.ts +0 -0
- package/dist/types/utility/clear.d.ts +2 -0
- package/dist/{utility → types/utility}/index.d.ts +0 -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/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/Blob.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/Clipboard.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/DataTransfer.d.ts +0 -0
- package/dist/{utils → types/utils}/dataTransfer/FileList.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
- package/dist/types/utils/edit/input.d.ts +2 -0
- package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
- package/dist/types/utils/edit/isValidDateOrTimeValue.d.ts +3 -0
- package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
- package/dist/{utils → types/utils}/edit/setFiles.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/copySelection.d.ts +0 -0
- package/dist/types/utils/focus/cursor.d.ts +9 -0
- package/dist/{utils → types/utils}/focus/focus.d.ts +3 -0
- package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selectAll.d.ts +0 -0
- package/dist/{utils → types/utils}/focus/selection.d.ts +4 -0
- package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
- package/dist/{utils → types/utils}/index.d.ts +7 -10
- package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +5 -0
- package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/types/utils/misc/findClosest.d.ts +1 -0
- package/dist/{utils → types/utils}/misc/getDocumentFromNode.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
- package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
- package/dist/types/utils/misc/level.d.ts +17 -0
- package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
- package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +13 -30
- package/CHANGELOG.md +0 -5
- package/dist/clipboard/copy.d.ts +0 -2
- package/dist/clipboard/copy.js +0 -36
- package/dist/clipboard/cut.d.ts +0 -2
- package/dist/clipboard/cut.js +0 -42
- package/dist/clipboard/index.js +0 -44
- package/dist/clipboard/paste.d.ts +0 -2
- package/dist/clipboard/paste.js +0 -47
- package/dist/convenience/click.d.ts +0 -4
- package/dist/convenience/click.js +0 -52
- package/dist/convenience/hover.d.ts +0 -3
- package/dist/convenience/hover.js +0 -31
- package/dist/convenience/index.js +0 -44
- package/dist/convenience/tab.d.ts +0 -4
- package/dist/convenience/tab.js +0 -12
- package/dist/document/index.js +0 -100
- package/dist/document/interceptor.js +0 -37
- package/dist/document/selection.js +0 -90
- package/dist/document/value.js +0 -77
- package/dist/index.js +0 -13
- package/dist/keyboard/getEventProps.d.ts +0 -15
- package/dist/keyboard/getEventProps.js +0 -27
- package/dist/keyboard/index.js +0 -42
- package/dist/keyboard/keyMap.js +0 -119
- package/dist/keyboard/keyboardAction.js +0 -156
- package/dist/keyboard/parseKeyDef.js +0 -61
- package/dist/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/keyboard/plugins/arrow.js +0 -28
- package/dist/keyboard/plugins/character.d.ts +0 -5
- package/dist/keyboard/plugins/character.js +0 -173
- package/dist/keyboard/plugins/combination.d.ts +0 -5
- package/dist/keyboard/plugins/combination.js +0 -19
- package/dist/keyboard/plugins/control.d.ts +0 -6
- package/dist/keyboard/plugins/control.js +0 -52
- package/dist/keyboard/plugins/functional.d.ts +0 -11
- package/dist/keyboard/plugins/functional.js +0 -158
- package/dist/keyboard/plugins/index.d.ts +0 -7
- package/dist/keyboard/plugins/index.js +0 -33
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
- package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
- package/dist/keyboard/shared/index.d.ts +0 -1
- package/dist/keyboard/shared/index.js +0 -18
- package/dist/keyboard/types.js +0 -19
- package/dist/options.js +0 -36
- package/dist/pointer/index.js +0 -56
- package/dist/pointer/keyMap.js +0 -29
- package/dist/pointer/parseKeyDef.js +0 -34
- package/dist/pointer/pointerAction.js +0 -46
- package/dist/pointer/pointerMove.d.ts +0 -6
- package/dist/pointer/pointerMove.js +0 -136
- package/dist/pointer/pointerPress.js +0 -330
- package/dist/pointer/resolveSelectionTarget.js +0 -75
- package/dist/pointer/types.js +0 -1
- package/dist/setup/api.js +0 -111
- package/dist/setup/config.js +0 -8
- package/dist/setup/directApi.js +0 -95
- package/dist/setup/index.js +0 -27
- package/dist/setup/setup.d.ts +0 -74
- package/dist/setup/setup.js +0 -98
- package/dist/setup/wrapAsync.js +0 -15
- package/dist/utility/clear.d.ts +0 -2
- package/dist/utility/clear.js +0 -30
- package/dist/utility/index.js +0 -57
- package/dist/utility/selectOptions.d.ts +0 -3
- package/dist/utility/selectOptions.js +0 -132
- package/dist/utility/type.d.ts +0 -9
- package/dist/utility/type.js +0 -37
- package/dist/utility/upload.d.ts +0 -5
- package/dist/utility/upload.js +0 -64
- package/dist/utils/click/isClickableInput.js +0 -14
- package/dist/utils/dataTransfer/Blob.js +0 -21
- package/dist/utils/dataTransfer/Clipboard.js +0 -188
- package/dist/utils/dataTransfer/DataTransfer.js +0 -158
- package/dist/utils/dataTransfer/FileList.js +0 -23
- package/dist/utils/edit/buildTimeValue.js +0 -44
- package/dist/utils/edit/calculateNewValue.d.ts +0 -14
- package/dist/utils/edit/calculateNewValue.js +0 -46
- package/dist/utils/edit/editInputElement.d.ts +0 -16
- package/dist/utils/edit/editInputElement.js +0 -53
- package/dist/utils/edit/getValue.js +0 -23
- package/dist/utils/edit/isContentEditable.js +0 -25
- package/dist/utils/edit/isEditable.js +0 -42
- package/dist/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/utils/edit/isValidDateValue.js +0 -12
- package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/utils/edit/isValidInputTimeValue.js +0 -12
- package/dist/utils/edit/maxLength.js +0 -50
- package/dist/utils/edit/prepareInput.d.ts +0 -7
- package/dist/utils/edit/prepareInput.js +0 -77
- package/dist/utils/edit/setFiles.js +0 -72
- package/dist/utils/focus/blur.js +0 -19
- package/dist/utils/focus/copySelection.js +0 -36
- package/dist/utils/focus/focus.js +0 -22
- package/dist/utils/focus/getActiveElement.js +0 -26
- package/dist/utils/focus/getTabDestination.js +0 -71
- package/dist/utils/focus/isFocusable.js +0 -12
- package/dist/utils/focus/selectAll.js +0 -51
- package/dist/utils/focus/selection.js +0 -190
- package/dist/utils/focus/selector.js +0 -8
- package/dist/utils/index.js +0 -499
- package/dist/utils/keyDef/readNextDescriptor.js +0 -102
- package/dist/utils/misc/eventWrapper.js +0 -16
- package/dist/utils/misc/findClosest.d.ts +0 -1
- package/dist/utils/misc/findClosest.js +0 -20
- package/dist/utils/misc/getDocumentFromNode.js +0 -14
- package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
- package/dist/utils/misc/hasFormSubmit.js +0 -10
- package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
- package/dist/utils/misc/hasPointerEvents.js +0 -24
- package/dist/utils/misc/isDescendantOrSelf.js +0 -20
- package/dist/utils/misc/isDisabled.js +0 -12
- package/dist/utils/misc/isElementType.js +0 -24
- package/dist/utils/misc/isVisible.js +0 -24
- package/dist/utils/misc/wait.js +0 -10
- package/dist/utils/pointer/firePointerEvents.d.ts +0 -25
- package/dist/utils/pointer/firePointerEvents.js +0 -112
- package/dist/utils/pointer/mouseButtons.js +0 -45
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2878 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
28
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(module2))
|
|
30
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
31
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
36
|
+
return (module2, temp) => {
|
|
37
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
38
|
+
};
|
|
39
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
40
|
+
|
|
41
|
+
// src/index.ts
|
|
42
|
+
var src_exports = {};
|
|
43
|
+
__export(src_exports, {
|
|
44
|
+
PointerEventsCheckLevel: () => PointerEventsCheckLevel,
|
|
45
|
+
default: () => userEvent
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// src/utils/misc/isElementType.ts
|
|
49
|
+
function isElementType(element, tag, props) {
|
|
50
|
+
if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
tag = Array.isArray(tag) ? tag : [tag];
|
|
54
|
+
if (!tag.includes(element.tagName.toLowerCase())) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (props) {
|
|
58
|
+
return Object.entries(props).every(([k, v]) => element[k] === v);
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/utils/click/isClickableInput.ts
|
|
64
|
+
var CLICKABLE_INPUT_TYPES = [
|
|
65
|
+
"button",
|
|
66
|
+
"color",
|
|
67
|
+
"file",
|
|
68
|
+
"image",
|
|
69
|
+
"reset",
|
|
70
|
+
"submit",
|
|
71
|
+
"checkbox",
|
|
72
|
+
"radio"
|
|
73
|
+
];
|
|
74
|
+
function isClickableInput(element) {
|
|
75
|
+
return isElementType(element, "button") || isElementType(element, "input") && CLICKABLE_INPUT_TYPES.includes(element.type);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/utils/dataTransfer/Blob.ts
|
|
79
|
+
function readBlobText(blob) {
|
|
80
|
+
return new Promise((res, rej) => {
|
|
81
|
+
const fr = new FileReader();
|
|
82
|
+
fr.onerror = rej;
|
|
83
|
+
fr.onabort = rej;
|
|
84
|
+
fr.onload = () => {
|
|
85
|
+
res(String(fr.result));
|
|
86
|
+
};
|
|
87
|
+
fr.readAsText(blob);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/utils/dataTransfer/FileList.ts
|
|
92
|
+
function createFileList(files) {
|
|
93
|
+
const list = __spreadProps(__spreadValues({}, files), {
|
|
94
|
+
length: files.length,
|
|
95
|
+
item: (index) => list[index],
|
|
96
|
+
[Symbol.iterator]: function* nextFile() {
|
|
97
|
+
for (let i = 0; i < list.length; i++) {
|
|
98
|
+
yield list[i];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
list.constructor = FileList;
|
|
103
|
+
Object.setPrototypeOf(list, FileList.prototype);
|
|
104
|
+
Object.freeze(list);
|
|
105
|
+
return list;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/utils/dataTransfer/DataTransfer.ts
|
|
109
|
+
var DataTransferItemStub = class {
|
|
110
|
+
constructor(dataOrFile, type3) {
|
|
111
|
+
this.file = null;
|
|
112
|
+
this.data = void 0;
|
|
113
|
+
if (typeof dataOrFile === "string") {
|
|
114
|
+
this.kind = "string";
|
|
115
|
+
this.type = String(type3);
|
|
116
|
+
this.data = dataOrFile;
|
|
117
|
+
} else {
|
|
118
|
+
this.kind = "file";
|
|
119
|
+
this.type = dataOrFile.type;
|
|
120
|
+
this.file = dataOrFile;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
getAsFile() {
|
|
124
|
+
return this.file;
|
|
125
|
+
}
|
|
126
|
+
getAsString(callback) {
|
|
127
|
+
if (typeof this.data === "string") {
|
|
128
|
+
callback(this.data);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
webkitGetAsEntry() {
|
|
132
|
+
throw new Error("not implemented");
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var DataTransferItemListStub = class extends Array {
|
|
136
|
+
add(...args) {
|
|
137
|
+
const item = new DataTransferItemStub(args[0], args[1]);
|
|
138
|
+
this.push(item);
|
|
139
|
+
return item;
|
|
140
|
+
}
|
|
141
|
+
clear() {
|
|
142
|
+
this.splice(0, this.length);
|
|
143
|
+
}
|
|
144
|
+
remove(index) {
|
|
145
|
+
this.splice(index, 1);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function getTypeMatcher(type3, exact) {
|
|
149
|
+
const [group, sub] = type3.split("/");
|
|
150
|
+
const isGroup = !sub || sub === "*";
|
|
151
|
+
return (item) => {
|
|
152
|
+
return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
var DataTransferStub = class {
|
|
156
|
+
constructor() {
|
|
157
|
+
this.dropEffect = "none";
|
|
158
|
+
this.effectAllowed = "uninitialized";
|
|
159
|
+
this.items = new DataTransferItemListStub();
|
|
160
|
+
this.files = createFileList([]);
|
|
161
|
+
}
|
|
162
|
+
getData(format) {
|
|
163
|
+
var _a;
|
|
164
|
+
const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
|
|
165
|
+
let text = "";
|
|
166
|
+
match == null ? void 0 : match.getAsString((t) => {
|
|
167
|
+
text = t;
|
|
168
|
+
});
|
|
169
|
+
return text;
|
|
170
|
+
}
|
|
171
|
+
setData(format, data) {
|
|
172
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
173
|
+
const item = new DataTransferItemStub(data, format);
|
|
174
|
+
if (matchIndex >= 0) {
|
|
175
|
+
this.items.splice(matchIndex, 1, item);
|
|
176
|
+
} else {
|
|
177
|
+
this.items.push(item);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
clearData(format) {
|
|
181
|
+
if (format) {
|
|
182
|
+
const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
|
|
183
|
+
if (matchIndex >= 0) {
|
|
184
|
+
this.items.remove(matchIndex);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
this.items.clear();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
get types() {
|
|
191
|
+
const t = [];
|
|
192
|
+
if (this.files.length) {
|
|
193
|
+
t.push("Files");
|
|
194
|
+
}
|
|
195
|
+
this.items.forEach((i) => t.push(i.type));
|
|
196
|
+
Object.freeze(t);
|
|
197
|
+
return t;
|
|
198
|
+
}
|
|
199
|
+
setDragImage() {
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
function createDataTransfer(files = []) {
|
|
203
|
+
const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
|
|
204
|
+
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
205
|
+
return dt;
|
|
206
|
+
}
|
|
207
|
+
function getBlobFromDataTransferItem(item) {
|
|
208
|
+
if (item.kind === "file") {
|
|
209
|
+
return item.getAsFile();
|
|
210
|
+
}
|
|
211
|
+
let data = "";
|
|
212
|
+
item.getAsString((s) => {
|
|
213
|
+
data = s;
|
|
214
|
+
});
|
|
215
|
+
return new Blob([data], { type: item.type });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/utils/dataTransfer/Clipboard.ts
|
|
219
|
+
var ClipboardItemStub = class {
|
|
220
|
+
constructor(data) {
|
|
221
|
+
this.data = data;
|
|
222
|
+
}
|
|
223
|
+
get types() {
|
|
224
|
+
return Array.from(Object.keys(this.data));
|
|
225
|
+
}
|
|
226
|
+
async getType(type3) {
|
|
227
|
+
const data = await this.data[type3];
|
|
228
|
+
if (!data) {
|
|
229
|
+
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
230
|
+
}
|
|
231
|
+
return data instanceof Blob ? data : new Blob([data], { type: type3 });
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
235
|
+
var ClipboardStub = class extends EventTarget {
|
|
236
|
+
constructor() {
|
|
237
|
+
super(...arguments);
|
|
238
|
+
this.items = [];
|
|
239
|
+
}
|
|
240
|
+
async read() {
|
|
241
|
+
return Array.from(this.items);
|
|
242
|
+
}
|
|
243
|
+
async readText() {
|
|
244
|
+
let text = "";
|
|
245
|
+
for (const item of this.items) {
|
|
246
|
+
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
247
|
+
if (type3) {
|
|
248
|
+
text += await item.getType(type3).then((b) => readBlobText(b));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return text;
|
|
252
|
+
}
|
|
253
|
+
async write(data) {
|
|
254
|
+
this.items = data;
|
|
255
|
+
}
|
|
256
|
+
async writeText(text) {
|
|
257
|
+
this.items = [createClipboardItem(text)];
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
ClipboardStubControl;
|
|
261
|
+
function createClipboardItem(...blobs) {
|
|
262
|
+
const constructor = typeof ClipboardItem === "undefined" ? ClipboardItemStub : ClipboardItem;
|
|
263
|
+
return new constructor(Object.fromEntries(blobs.map((b) => [
|
|
264
|
+
typeof b === "string" ? "text/plain" : b.type,
|
|
265
|
+
Promise.resolve(b)
|
|
266
|
+
])));
|
|
267
|
+
}
|
|
268
|
+
function attachClipboardStubToView(window2) {
|
|
269
|
+
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
270
|
+
return window2.navigator.clipboard[ClipboardStubControl];
|
|
271
|
+
}
|
|
272
|
+
const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
|
|
273
|
+
let stub = new ClipboardStub();
|
|
274
|
+
const control = {
|
|
275
|
+
resetClipboardStub: () => {
|
|
276
|
+
stub = new ClipboardStub();
|
|
277
|
+
stub[ClipboardStubControl] = control;
|
|
278
|
+
},
|
|
279
|
+
detachClipboardStub: () => {
|
|
280
|
+
if (realClipboard) {
|
|
281
|
+
Object.defineProperty(window2.navigator, "clipboard", realClipboard);
|
|
282
|
+
} else {
|
|
283
|
+
Object.defineProperty(window2.navigator, "clipboard", {
|
|
284
|
+
value: void 0,
|
|
285
|
+
configurable: true
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
stub[ClipboardStubControl] = control;
|
|
291
|
+
Object.defineProperty(window2.navigator, "clipboard", {
|
|
292
|
+
get: () => stub,
|
|
293
|
+
configurable: true
|
|
294
|
+
});
|
|
295
|
+
return stub[ClipboardStubControl];
|
|
296
|
+
}
|
|
297
|
+
function resetClipboardStubOnView(window2) {
|
|
298
|
+
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
299
|
+
window2.navigator.clipboard[ClipboardStubControl].resetClipboardStub();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function detachClipboardStubFromView(window2) {
|
|
303
|
+
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
304
|
+
window2.navigator.clipboard[ClipboardStubControl].detachClipboardStub();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function readDataTransferFromClipboard(document2) {
|
|
308
|
+
var _a;
|
|
309
|
+
const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
|
|
310
|
+
const items = clipboard && await clipboard.read();
|
|
311
|
+
if (!items) {
|
|
312
|
+
throw new Error("The Clipboard API is unavailable.");
|
|
313
|
+
}
|
|
314
|
+
const dt = createDataTransfer();
|
|
315
|
+
for (const item of items) {
|
|
316
|
+
for (const type3 of item.types) {
|
|
317
|
+
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b)));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return dt;
|
|
321
|
+
}
|
|
322
|
+
async function writeDataTransferToClipboard(document2, clipboardData) {
|
|
323
|
+
var _a;
|
|
324
|
+
const clipboard = (_a = document2.defaultView) == null ? void 0 : _a.navigator.clipboard;
|
|
325
|
+
const items = [];
|
|
326
|
+
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
327
|
+
const dtItem = clipboardData.items[i];
|
|
328
|
+
const blob = getBlobFromDataTransferItem(dtItem);
|
|
329
|
+
items.push(createClipboardItem(blob));
|
|
330
|
+
}
|
|
331
|
+
const written = clipboard && await clipboard.write(items).then(() => true, () => false);
|
|
332
|
+
if (!written) {
|
|
333
|
+
throw new Error("The Clipboard API is unavailable.");
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (typeof afterEach === "function") {
|
|
337
|
+
afterEach(() => resetClipboardStubOnView(window));
|
|
338
|
+
}
|
|
339
|
+
if (typeof afterAll === "function") {
|
|
340
|
+
afterAll(() => detachClipboardStubFromView(window));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/utils/edit/isContentEditable.ts
|
|
344
|
+
function isContentEditable(element) {
|
|
345
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
346
|
+
}
|
|
347
|
+
function getContentEditable(node) {
|
|
348
|
+
const element = getElement(node);
|
|
349
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
350
|
+
}
|
|
351
|
+
function getElement(node) {
|
|
352
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/utils/edit/getValue.ts
|
|
356
|
+
function getValue(element) {
|
|
357
|
+
if (!element) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
if (isContentEditable(element)) {
|
|
361
|
+
return element.textContent;
|
|
362
|
+
}
|
|
363
|
+
return getUIValue(element);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/utils/edit/buildTimeValue.ts
|
|
367
|
+
function buildTimeValue(value) {
|
|
368
|
+
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
369
|
+
if (onlyDigitsValue.length < 2) {
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
const firstDigit = parseInt(onlyDigitsValue[0], 10);
|
|
373
|
+
const secondDigit = parseInt(onlyDigitsValue[1], 10);
|
|
374
|
+
if (firstDigit >= 3 || firstDigit === 2 && secondDigit >= 4) {
|
|
375
|
+
let index;
|
|
376
|
+
if (firstDigit >= 3) {
|
|
377
|
+
index = 1;
|
|
378
|
+
} else {
|
|
379
|
+
index = 2;
|
|
380
|
+
}
|
|
381
|
+
return build(onlyDigitsValue, index);
|
|
382
|
+
}
|
|
383
|
+
if (value.length === 2) {
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
return build(onlyDigitsValue, 2);
|
|
387
|
+
}
|
|
388
|
+
function build(onlyDigitsValue, index) {
|
|
389
|
+
const hours = onlyDigitsValue.slice(0, index);
|
|
390
|
+
const validHours = Math.min(parseInt(hours, 10), 23);
|
|
391
|
+
const minuteCharacters = onlyDigitsValue.slice(index);
|
|
392
|
+
const parsedMinutes = parseInt(minuteCharacters, 10);
|
|
393
|
+
const validMinutes = Math.min(parsedMinutes, 59);
|
|
394
|
+
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
398
|
+
function isValidDateOrTimeValue(element, value) {
|
|
399
|
+
const clone = element.cloneNode();
|
|
400
|
+
clone.value = value;
|
|
401
|
+
return clone.value === value;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/utils/edit/maxLength.ts
|
|
405
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
406
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
407
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
408
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
409
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
410
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
411
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
412
|
+
return maxLengthSupportedTypes2;
|
|
413
|
+
})(maxLengthSupportedTypes || {});
|
|
414
|
+
function getSpaceUntilMaxLength(element) {
|
|
415
|
+
const value = getValue(element);
|
|
416
|
+
if (value === null) {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
420
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
421
|
+
}
|
|
422
|
+
function getSanitizedMaxLength(element) {
|
|
423
|
+
var _a;
|
|
424
|
+
if (!supportsMaxLength(element)) {
|
|
425
|
+
return void 0;
|
|
426
|
+
}
|
|
427
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
428
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
429
|
+
}
|
|
430
|
+
function supportsMaxLength(element) {
|
|
431
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// src/utils/edit/input.ts
|
|
435
|
+
function isDateOrTime(element) {
|
|
436
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
437
|
+
}
|
|
438
|
+
function input(config, element, data, inputType = "insertText") {
|
|
439
|
+
const inputRange = getInputRange(element);
|
|
440
|
+
if (!inputRange) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (!isDateOrTime(element)) {
|
|
444
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
445
|
+
inputType,
|
|
446
|
+
data
|
|
447
|
+
});
|
|
448
|
+
if (!unprevented) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if ("startContainer" in inputRange) {
|
|
453
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
454
|
+
} else {
|
|
455
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
459
|
+
let del = false;
|
|
460
|
+
if (!inputRange.collapsed) {
|
|
461
|
+
del = true;
|
|
462
|
+
inputRange.deleteContents();
|
|
463
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
464
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
465
|
+
if (nextPosition) {
|
|
466
|
+
del = true;
|
|
467
|
+
const delRange = inputRange.cloneRange();
|
|
468
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
469
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
470
|
+
} else {
|
|
471
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
472
|
+
}
|
|
473
|
+
delRange.deleteContents();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (data) {
|
|
477
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
478
|
+
const offset = inputRange.endOffset;
|
|
479
|
+
inputRange.endContainer.insertData(offset, data);
|
|
480
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
481
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
482
|
+
} else {
|
|
483
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
484
|
+
inputRange.insertNode(text);
|
|
485
|
+
inputRange.setStart(text, data.length);
|
|
486
|
+
inputRange.setEnd(text, data.length);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (del || data) {
|
|
490
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
494
|
+
let dataToInsert = data;
|
|
495
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
496
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
497
|
+
if (spaceUntilMaxLength > 0) {
|
|
498
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
499
|
+
} else {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
504
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
setUIValue(element, newValue);
|
|
511
|
+
setSelection({
|
|
512
|
+
focusNode: element,
|
|
513
|
+
anchorOffset: newOffset,
|
|
514
|
+
focusOffset: newOffset
|
|
515
|
+
});
|
|
516
|
+
if (isDateOrTime(element)) {
|
|
517
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
518
|
+
commitInput(config, element, oldValue, newValue, newOffset, {});
|
|
519
|
+
dispatchUIEvent(config, element, "change");
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
commitInput(config, element, oldValue, newValue, newOffset, {
|
|
523
|
+
data,
|
|
524
|
+
inputType
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function calculateNewValue(inputData, node, {
|
|
529
|
+
startOffset,
|
|
530
|
+
endOffset
|
|
531
|
+
}, inputType) {
|
|
532
|
+
const value = getUIValue(node);
|
|
533
|
+
const prologEnd = Math.max(0, startOffset === endOffset && inputType === "deleteContentBackward" ? startOffset - 1 : startOffset);
|
|
534
|
+
const prolog = value.substring(0, prologEnd);
|
|
535
|
+
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
536
|
+
const epilog = value.substring(epilogStart, value.length);
|
|
537
|
+
let newValue = `${prolog}${inputData}${epilog}`;
|
|
538
|
+
let newOffset = prologEnd + inputData.length;
|
|
539
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
540
|
+
const builtValue = buildTimeValue(newValue);
|
|
541
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
542
|
+
newValue = builtValue;
|
|
543
|
+
newOffset = builtValue.length;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return {
|
|
547
|
+
oldValue: value,
|
|
548
|
+
newValue,
|
|
549
|
+
newOffset
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function commitInput(config, element, oldValue, newValue, newOffset, inputInit) {
|
|
553
|
+
startTrackValue(element);
|
|
554
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
555
|
+
const tracked = endTrackValue(element);
|
|
556
|
+
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
557
|
+
setSelection({
|
|
558
|
+
focusNode: element,
|
|
559
|
+
anchorOffset: newOffset,
|
|
560
|
+
focusOffset: newOffset
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function isValidNumberInput(value) {
|
|
565
|
+
var _a, _b;
|
|
566
|
+
const valueParts = value.split("e", 2);
|
|
567
|
+
return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// src/utils/edit/isEditable.ts
|
|
571
|
+
function isEditable(element) {
|
|
572
|
+
return isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element);
|
|
573
|
+
}
|
|
574
|
+
var editableInputTypes = /* @__PURE__ */ ((editableInputTypes2) => {
|
|
575
|
+
editableInputTypes2["text"] = "text";
|
|
576
|
+
editableInputTypes2["date"] = "date";
|
|
577
|
+
editableInputTypes2["datetime-local"] = "datetime-local";
|
|
578
|
+
editableInputTypes2["email"] = "email";
|
|
579
|
+
editableInputTypes2["month"] = "month";
|
|
580
|
+
editableInputTypes2["number"] = "number";
|
|
581
|
+
editableInputTypes2["password"] = "password";
|
|
582
|
+
editableInputTypes2["search"] = "search";
|
|
583
|
+
editableInputTypes2["tel"] = "tel";
|
|
584
|
+
editableInputTypes2["time"] = "time";
|
|
585
|
+
editableInputTypes2["url"] = "url";
|
|
586
|
+
editableInputTypes2["week"] = "week";
|
|
587
|
+
return editableInputTypes2;
|
|
588
|
+
})(editableInputTypes || {});
|
|
589
|
+
function isEditableInput(element) {
|
|
590
|
+
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/utils/edit/setFiles.ts
|
|
594
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
595
|
+
function setFiles(el, files) {
|
|
596
|
+
var _a;
|
|
597
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
598
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
599
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
600
|
+
function restore() {
|
|
601
|
+
Object.defineProperties(el, {
|
|
602
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
603
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
604
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
el[fakeFiles] = { restore };
|
|
608
|
+
Object.defineProperties(el, {
|
|
609
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
610
|
+
get: () => files
|
|
611
|
+
}),
|
|
612
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
613
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
614
|
+
set(v) {
|
|
615
|
+
var _a2;
|
|
616
|
+
if (v === "") {
|
|
617
|
+
restore();
|
|
618
|
+
} else {
|
|
619
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}),
|
|
623
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
624
|
+
set(v) {
|
|
625
|
+
if (v !== "file") {
|
|
626
|
+
restore();
|
|
627
|
+
el.type = v;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
})
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/utils/misc/eventWrapper.ts
|
|
635
|
+
var import_dom = require("@testing-library/dom");
|
|
636
|
+
function eventWrapper(cb) {
|
|
637
|
+
let result;
|
|
638
|
+
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
639
|
+
result = cb();
|
|
640
|
+
});
|
|
641
|
+
return result;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/utils/misc/isDisabled.ts
|
|
645
|
+
function isDisabled(element) {
|
|
646
|
+
return Boolean(element && element.disabled);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/utils/focus/getActiveElement.ts
|
|
650
|
+
function getActiveElement(document2) {
|
|
651
|
+
const activeElement = document2.activeElement;
|
|
652
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
653
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
654
|
+
} else {
|
|
655
|
+
if (isDisabled(activeElement)) {
|
|
656
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
657
|
+
}
|
|
658
|
+
return activeElement;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/utils/focus/selector.ts
|
|
663
|
+
var FOCUSABLE_SELECTOR = [
|
|
664
|
+
"input:not([type=hidden]):not([disabled])",
|
|
665
|
+
"button:not([disabled])",
|
|
666
|
+
"select:not([disabled])",
|
|
667
|
+
"textarea:not([disabled])",
|
|
668
|
+
'[contenteditable=""]',
|
|
669
|
+
'[contenteditable="true"]',
|
|
670
|
+
"a[href]",
|
|
671
|
+
"[tabindex]:not([disabled])"
|
|
672
|
+
].join(", ");
|
|
673
|
+
|
|
674
|
+
// src/utils/focus/isFocusable.ts
|
|
675
|
+
function isFocusable(element) {
|
|
676
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// src/utils/focus/blur.ts
|
|
680
|
+
function blur(element) {
|
|
681
|
+
if (!isFocusable(element))
|
|
682
|
+
return;
|
|
683
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
684
|
+
if (!wasActive)
|
|
685
|
+
return;
|
|
686
|
+
eventWrapper(() => element.blur());
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/utils/focus/cursor.ts
|
|
690
|
+
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
691
|
+
if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
|
|
692
|
+
return { node, offset: offset + direction };
|
|
693
|
+
}
|
|
694
|
+
const nextNode = getNextCharacterContentNode(node, offset, direction);
|
|
695
|
+
if (nextNode) {
|
|
696
|
+
if (isTextNode(nextNode)) {
|
|
697
|
+
return {
|
|
698
|
+
node: nextNode,
|
|
699
|
+
offset: direction > 0 ? Math.min(1, nextNode.nodeValue.length) : Math.max(nextNode.nodeValue.length - 1, 0)
|
|
700
|
+
};
|
|
701
|
+
} else if (isElementType(nextNode, "br")) {
|
|
702
|
+
const nextPlusOne = getNextCharacterContentNode(nextNode, void 0, direction);
|
|
703
|
+
if (!nextPlusOne) {
|
|
704
|
+
if (direction < 0 && inputType === "deleteContentBackward") {
|
|
705
|
+
return {
|
|
706
|
+
node: nextNode.parentNode,
|
|
707
|
+
offset: getOffset(nextNode)
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
return void 0;
|
|
711
|
+
} else if (isTextNode(nextPlusOne)) {
|
|
712
|
+
return {
|
|
713
|
+
node: nextPlusOne,
|
|
714
|
+
offset: direction > 0 ? 0 : nextPlusOne.nodeValue.length
|
|
715
|
+
};
|
|
716
|
+
} else if (direction < 0 && isElementType(nextPlusOne, "br")) {
|
|
717
|
+
return {
|
|
718
|
+
node: nextNode.parentNode,
|
|
719
|
+
offset: getOffset(nextNode)
|
|
720
|
+
};
|
|
721
|
+
} else {
|
|
722
|
+
return {
|
|
723
|
+
node: nextPlusOne.parentNode,
|
|
724
|
+
offset: getOffset(nextPlusOne) + (direction > 0 ? 0 : 1)
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
} else {
|
|
728
|
+
return {
|
|
729
|
+
node: nextNode.parentNode,
|
|
730
|
+
offset: getOffset(nextNode) + (direction > 0 ? 1 : 0)
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
function getNextCharacterContentNode(node, offset, direction) {
|
|
736
|
+
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
737
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
738
|
+
node = node.children[nextOffset];
|
|
739
|
+
}
|
|
740
|
+
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
741
|
+
}
|
|
742
|
+
function isTreatedAsCharacterContent(node) {
|
|
743
|
+
if (isTextNode(node)) {
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
if (isElement(node)) {
|
|
747
|
+
if (isElementType(node, ["input", "textarea"])) {
|
|
748
|
+
return node.type !== "hidden";
|
|
749
|
+
} else if (isElementType(node, "br")) {
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
function getOffset(node) {
|
|
756
|
+
let i = 0;
|
|
757
|
+
while (node.previousSibling) {
|
|
758
|
+
i++;
|
|
759
|
+
node = node.previousSibling;
|
|
760
|
+
}
|
|
761
|
+
return i;
|
|
762
|
+
}
|
|
763
|
+
function isElement(node) {
|
|
764
|
+
return node.nodeType === 1;
|
|
765
|
+
}
|
|
766
|
+
function isTextNode(node) {
|
|
767
|
+
return node.nodeType === 3;
|
|
768
|
+
}
|
|
769
|
+
function walkNodes(node, direction, callback) {
|
|
770
|
+
var _a;
|
|
771
|
+
for (; ; ) {
|
|
772
|
+
const sibling = node[`${direction}Sibling`];
|
|
773
|
+
if (sibling) {
|
|
774
|
+
node = getDescendant(sibling, direction === "next" ? "first" : "last");
|
|
775
|
+
if (callback(node)) {
|
|
776
|
+
return node;
|
|
777
|
+
}
|
|
778
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
779
|
+
node = node.parentNode;
|
|
780
|
+
} else {
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function getDescendant(node, direction) {
|
|
786
|
+
while (node.hasChildNodes()) {
|
|
787
|
+
node = node[`${direction}Child`];
|
|
788
|
+
}
|
|
789
|
+
return node;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// src/utils/focus/selection.ts
|
|
793
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
794
|
+
var _a;
|
|
795
|
+
if (hasOwnSelection(element)) {
|
|
796
|
+
return setSelection({
|
|
797
|
+
focusNode: element,
|
|
798
|
+
anchorOffset,
|
|
799
|
+
focusOffset
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
803
|
+
return setSelection({
|
|
804
|
+
focusNode: element.firstChild,
|
|
805
|
+
anchorOffset,
|
|
806
|
+
focusOffset
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
810
|
+
}
|
|
811
|
+
function hasOwnSelection(node) {
|
|
812
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
813
|
+
}
|
|
814
|
+
function isElement2(node) {
|
|
815
|
+
return node.nodeType === 1;
|
|
816
|
+
}
|
|
817
|
+
function getTargetTypeAndSelection(node) {
|
|
818
|
+
const element = getElement2(node);
|
|
819
|
+
if (element && hasOwnSelection(element)) {
|
|
820
|
+
return {
|
|
821
|
+
type: "input",
|
|
822
|
+
selection: getUISelection(element)
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
826
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
827
|
+
return {
|
|
828
|
+
type: isCE ? "contenteditable" : "default",
|
|
829
|
+
selection
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function getElement2(node) {
|
|
833
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
834
|
+
}
|
|
835
|
+
function updateSelectionOnFocus(element) {
|
|
836
|
+
var _a;
|
|
837
|
+
const selection = element.ownerDocument.getSelection();
|
|
838
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
if (hasOwnSelection(element)) {
|
|
842
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
843
|
+
if (contenteditable) {
|
|
844
|
+
if (!selection.isCollapsed) {
|
|
845
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
846
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
847
|
+
}
|
|
848
|
+
} else {
|
|
849
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
function getInputRange(focusNode) {
|
|
854
|
+
var _a;
|
|
855
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
856
|
+
if (typeAndSelection.type === "input") {
|
|
857
|
+
return typeAndSelection.selection;
|
|
858
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
859
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function setSelection({
|
|
863
|
+
focusNode,
|
|
864
|
+
focusOffset,
|
|
865
|
+
anchorNode = focusNode,
|
|
866
|
+
anchorOffset = focusOffset
|
|
867
|
+
}) {
|
|
868
|
+
var _a, _b;
|
|
869
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
870
|
+
if (typeAndSelection.type === "input") {
|
|
871
|
+
return setUISelection(focusNode, {
|
|
872
|
+
anchorOffset,
|
|
873
|
+
focusOffset
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
877
|
+
}
|
|
878
|
+
function moveSelection(node, direction) {
|
|
879
|
+
if (hasOwnSelection(node)) {
|
|
880
|
+
const selection = getUISelection(node);
|
|
881
|
+
setSelection({
|
|
882
|
+
focusNode: node,
|
|
883
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
884
|
+
});
|
|
885
|
+
} else {
|
|
886
|
+
const selection = node.ownerDocument.getSelection();
|
|
887
|
+
if (!selection) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
if (selection.isCollapsed) {
|
|
891
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
892
|
+
if (nextPosition) {
|
|
893
|
+
setSelection({
|
|
894
|
+
focusNode: nextPosition.node,
|
|
895
|
+
focusOffset: nextPosition.offset
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
} else {
|
|
899
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// src/utils/focus/copySelection.ts
|
|
905
|
+
function copySelection(target) {
|
|
906
|
+
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
907
|
+
const dt = createDataTransfer();
|
|
908
|
+
for (const type3 in data) {
|
|
909
|
+
if (data[type3]) {
|
|
910
|
+
dt.setData(type3, data[type3]);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
return dt;
|
|
914
|
+
}
|
|
915
|
+
function readSelectedValueFromInput(target) {
|
|
916
|
+
const sel = getUISelection(target);
|
|
917
|
+
const val = getUIValue(target);
|
|
918
|
+
return val.substring(sel.startOffset, sel.endOffset);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/utils/misc/findClosest.ts
|
|
922
|
+
function findClosest(element, callback) {
|
|
923
|
+
let el = element;
|
|
924
|
+
do {
|
|
925
|
+
if (callback(el)) {
|
|
926
|
+
return el;
|
|
927
|
+
}
|
|
928
|
+
el = el.parentElement;
|
|
929
|
+
} while (el && el !== element.ownerDocument.body);
|
|
930
|
+
return void 0;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// src/utils/focus/focus.ts
|
|
934
|
+
function focus(element) {
|
|
935
|
+
const target = findClosest(element, isFocusable);
|
|
936
|
+
const activeElement = getActiveElement(element.ownerDocument);
|
|
937
|
+
if ((target != null ? target : element.ownerDocument.body) === activeElement) {
|
|
938
|
+
return;
|
|
939
|
+
} else if (target) {
|
|
940
|
+
eventWrapper(() => target.focus());
|
|
941
|
+
} else {
|
|
942
|
+
eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
|
|
943
|
+
}
|
|
944
|
+
updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// src/utils/misc/isVisible.ts
|
|
948
|
+
var import_helpers = require("@testing-library/dom/dist/helpers.js");
|
|
949
|
+
function isVisible(element) {
|
|
950
|
+
const window2 = (0, import_helpers.getWindowFromNode)(element);
|
|
951
|
+
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
952
|
+
const { display, visibility } = window2.getComputedStyle(el);
|
|
953
|
+
if (display === "none") {
|
|
954
|
+
return false;
|
|
955
|
+
}
|
|
956
|
+
if (visibility === "hidden") {
|
|
957
|
+
return false;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return true;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/utils/focus/getTabDestination.ts
|
|
964
|
+
function getTabDestination(activeElement, shift) {
|
|
965
|
+
const document2 = activeElement.ownerDocument;
|
|
966
|
+
const focusableElements = document2.querySelectorAll(FOCUSABLE_SELECTOR);
|
|
967
|
+
const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
|
|
968
|
+
if (activeElement.getAttribute("tabindex") !== "-1") {
|
|
969
|
+
enabledElements.sort((a, b) => {
|
|
970
|
+
const i = Number(a.getAttribute("tabindex"));
|
|
971
|
+
const j = Number(b.getAttribute("tabindex"));
|
|
972
|
+
if (i === j) {
|
|
973
|
+
return 0;
|
|
974
|
+
} else if (i === 0) {
|
|
975
|
+
return 1;
|
|
976
|
+
} else if (j === 0) {
|
|
977
|
+
return -1;
|
|
978
|
+
}
|
|
979
|
+
return i - j;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
const checkedRadio = {};
|
|
983
|
+
let prunedElements = [document2.body];
|
|
984
|
+
const activeRadioGroup = isElementType(activeElement, "input", {
|
|
985
|
+
type: "radio"
|
|
986
|
+
}) ? activeElement.name : void 0;
|
|
987
|
+
enabledElements.forEach((currentElement) => {
|
|
988
|
+
const el = currentElement;
|
|
989
|
+
if (isElementType(el, "input", { type: "radio" }) && el.name) {
|
|
990
|
+
if (el === activeElement) {
|
|
991
|
+
prunedElements.push(el);
|
|
992
|
+
return;
|
|
993
|
+
} else if (el.name === activeRadioGroup) {
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
if (el.checked) {
|
|
997
|
+
prunedElements = prunedElements.filter((e) => !isElementType(e, "input", { type: "radio", name: el.name }));
|
|
998
|
+
prunedElements.push(el);
|
|
999
|
+
checkedRadio[el.name] = el;
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (typeof checkedRadio[el.name] !== "undefined") {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
prunedElements.push(el);
|
|
1007
|
+
});
|
|
1008
|
+
const currentIndex = prunedElements.findIndex((el) => el === activeElement);
|
|
1009
|
+
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
1010
|
+
const defaultIndex = shift ? prunedElements.length - 1 : 0;
|
|
1011
|
+
return prunedElements[nextIndex] || prunedElements[defaultIndex];
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// src/utils/focus/selectAll.ts
|
|
1015
|
+
function selectAll(target) {
|
|
1016
|
+
var _a;
|
|
1017
|
+
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1018
|
+
return setSelection({
|
|
1019
|
+
focusNode: target,
|
|
1020
|
+
anchorOffset: 0,
|
|
1021
|
+
focusOffset: getUIValue(target).length
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1025
|
+
setSelection({
|
|
1026
|
+
focusNode,
|
|
1027
|
+
anchorOffset: 0,
|
|
1028
|
+
focusOffset: focusNode.childNodes.length
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
function isAllSelected(target) {
|
|
1032
|
+
var _a;
|
|
1033
|
+
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1034
|
+
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1035
|
+
}
|
|
1036
|
+
const focusNode = (_a = getContentEditable(target)) != null ? _a : target.ownerDocument.body;
|
|
1037
|
+
const selection = target.ownerDocument.getSelection();
|
|
1038
|
+
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
// src/utils/keyboard/getKeyEventProps.ts
|
|
1042
|
+
function getKeyEventProps(keyDef) {
|
|
1043
|
+
return {
|
|
1044
|
+
key: keyDef.key,
|
|
1045
|
+
code: keyDef.code
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// src/utils/keyboard/getUIEventModifiers.ts
|
|
1050
|
+
function getUIEventModifiers(keyboardState) {
|
|
1051
|
+
return {
|
|
1052
|
+
altKey: keyboardState.modifiers.Alt,
|
|
1053
|
+
ctrlKey: keyboardState.modifiers.Control,
|
|
1054
|
+
metaKey: keyboardState.modifiers.Meta,
|
|
1055
|
+
shiftKey: keyboardState.modifiers.Shift,
|
|
1056
|
+
modifierAltGraph: keyboardState.modifiers.AltGraph,
|
|
1057
|
+
modifierCapsLock: keyboardState.modifiers.CapsLock,
|
|
1058
|
+
modifierFn: keyboardState.modifiers.Fn,
|
|
1059
|
+
modifierFnLock: keyboardState.modifiers.FnLock,
|
|
1060
|
+
modifierNumLock: keyboardState.modifiers.NumLock,
|
|
1061
|
+
modifierScrollLock: keyboardState.modifiers.ScrollLock,
|
|
1062
|
+
modifierSymbol: keyboardState.modifiers.Symbol,
|
|
1063
|
+
modifierSymbolLock: keyboardState.modifiers.SymbolLock
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/utils/keyDef/readNextDescriptor.ts
|
|
1068
|
+
var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
1069
|
+
bracketDict2["{"] = "}";
|
|
1070
|
+
bracketDict2["["] = "]";
|
|
1071
|
+
return bracketDict2;
|
|
1072
|
+
})(bracketDict || {});
|
|
1073
|
+
function readNextDescriptor(text) {
|
|
1074
|
+
let pos = 0;
|
|
1075
|
+
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
1076
|
+
pos += startBracket.length;
|
|
1077
|
+
const isEscapedChar = new RegExp(`^\\${startBracket}{2}`).test(text);
|
|
1078
|
+
const type3 = isEscapedChar ? "" : startBracket;
|
|
1079
|
+
return __spreadValues({
|
|
1080
|
+
type: type3
|
|
1081
|
+
}, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
|
|
1082
|
+
}
|
|
1083
|
+
function readPrintableChar(text, pos) {
|
|
1084
|
+
const descriptor = text[pos];
|
|
1085
|
+
assertDescriptor(descriptor, text, pos);
|
|
1086
|
+
pos += descriptor.length;
|
|
1087
|
+
return {
|
|
1088
|
+
consumedLength: pos,
|
|
1089
|
+
descriptor,
|
|
1090
|
+
releasePrevious: false,
|
|
1091
|
+
releaseSelf: true,
|
|
1092
|
+
repeat: 1
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function readTag(text, pos, startBracket) {
|
|
1096
|
+
var _a, _b, _c;
|
|
1097
|
+
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1098
|
+
pos += releasePreviousModifier.length;
|
|
1099
|
+
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1100
|
+
pos += Number(escapedDescriptor);
|
|
1101
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1102
|
+
assertDescriptor(descriptor, text, pos);
|
|
1103
|
+
pos += descriptor.length;
|
|
1104
|
+
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
1105
|
+
pos += repeatModifier.length;
|
|
1106
|
+
const releaseSelfModifier = text[pos] === "/" || !repeatModifier && text[pos] === ">" ? text[pos] : "";
|
|
1107
|
+
pos += releaseSelfModifier.length;
|
|
1108
|
+
const expectedEndBracket = bracketDict[startBracket];
|
|
1109
|
+
const endBracket = text[pos] === expectedEndBracket ? expectedEndBracket : "";
|
|
1110
|
+
if (!endBracket) {
|
|
1111
|
+
throw new Error(getErrorMessage([
|
|
1112
|
+
!repeatModifier && "repeat modifier",
|
|
1113
|
+
!releaseSelfModifier && "release modifier",
|
|
1114
|
+
`"${expectedEndBracket}"`
|
|
1115
|
+
].filter(Boolean).join(" or "), text[pos], text));
|
|
1116
|
+
}
|
|
1117
|
+
pos += endBracket.length;
|
|
1118
|
+
return {
|
|
1119
|
+
consumedLength: pos,
|
|
1120
|
+
descriptor,
|
|
1121
|
+
releasePrevious: !!releasePreviousModifier,
|
|
1122
|
+
repeat: repeatModifier ? Math.max(Number(repeatModifier.substr(1)), 1) : 1,
|
|
1123
|
+
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function assertDescriptor(descriptor, text, pos) {
|
|
1127
|
+
if (!descriptor) {
|
|
1128
|
+
throw new Error(getErrorMessage("key descriptor", text[pos], text));
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
1132
|
+
if (releaseSelfModifier) {
|
|
1133
|
+
return releaseSelfModifier === "/";
|
|
1134
|
+
}
|
|
1135
|
+
if (repeatModifier) {
|
|
1136
|
+
return false;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
function getErrorMessage(expected, found, text) {
|
|
1140
|
+
return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
|
|
1141
|
+
See https://github.com/testing-library/user-event/blob/main/README.md#keyboardtext-options
|
|
1142
|
+
for more information about how userEvent parses your input.`;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// src/utils/misc/cloneEvent.ts
|
|
1146
|
+
function cloneEvent(event) {
|
|
1147
|
+
return new event.constructor(event.type, event);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// src/utils/misc/getDocumentFromNode.ts
|
|
1151
|
+
function getDocumentFromNode(el) {
|
|
1152
|
+
return isDocument(el) ? el : el.ownerDocument;
|
|
1153
|
+
}
|
|
1154
|
+
function isDocument(node) {
|
|
1155
|
+
return node.nodeType === 9;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// src/utils/misc/isDescendantOrSelf.ts
|
|
1159
|
+
function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
1160
|
+
let el = potentialDescendant;
|
|
1161
|
+
do {
|
|
1162
|
+
if (el === potentialAncestor) {
|
|
1163
|
+
return true;
|
|
1164
|
+
}
|
|
1165
|
+
el = el.parentElement;
|
|
1166
|
+
} while (el);
|
|
1167
|
+
return false;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// src/utils/misc/level.ts
|
|
1171
|
+
var Level = Symbol("Api level refs");
|
|
1172
|
+
function setLevelRef(config, level) {
|
|
1173
|
+
var _a;
|
|
1174
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1175
|
+
config[Level][level] = {};
|
|
1176
|
+
}
|
|
1177
|
+
function getLevelRef(config, level) {
|
|
1178
|
+
var _a;
|
|
1179
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// src/utils/misc/wait.ts
|
|
1183
|
+
function wait(time) {
|
|
1184
|
+
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
// src/utils/pointer/cssPointerEvents.ts
|
|
1188
|
+
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1189
|
+
|
|
1190
|
+
// src/keyboard/keyMap.ts
|
|
1191
|
+
var defaultKeyMap = [
|
|
1192
|
+
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
1193
|
+
...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
|
|
1194
|
+
..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
|
|
1195
|
+
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
|
|
1196
|
+
{ code: "Space", key: " " },
|
|
1197
|
+
{ code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
|
|
1198
|
+
{ code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
|
|
1199
|
+
{
|
|
1200
|
+
code: "ShiftLeft",
|
|
1201
|
+
key: "Shift",
|
|
1202
|
+
location: 1 /* LEFT */
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
code: "ShiftRight",
|
|
1206
|
+
key: "Shift",
|
|
1207
|
+
location: 2 /* RIGHT */
|
|
1208
|
+
},
|
|
1209
|
+
{
|
|
1210
|
+
code: "ControlLeft",
|
|
1211
|
+
key: "Control",
|
|
1212
|
+
location: 1 /* LEFT */
|
|
1213
|
+
},
|
|
1214
|
+
{
|
|
1215
|
+
code: "ControlRight",
|
|
1216
|
+
key: "Control",
|
|
1217
|
+
location: 2 /* RIGHT */
|
|
1218
|
+
},
|
|
1219
|
+
{ code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
|
|
1220
|
+
{
|
|
1221
|
+
code: "MetaRight",
|
|
1222
|
+
key: "Meta",
|
|
1223
|
+
location: 2 /* RIGHT */
|
|
1224
|
+
},
|
|
1225
|
+
{ code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
|
|
1226
|
+
{ code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
|
|
1227
|
+
{ code: "Tab", key: "Tab" },
|
|
1228
|
+
{ code: "CapsLock", key: "CapsLock" },
|
|
1229
|
+
{ code: "Backspace", key: "Backspace" },
|
|
1230
|
+
{ code: "Enter", key: "Enter" },
|
|
1231
|
+
{ code: "Escape", key: "Escape" },
|
|
1232
|
+
{ code: "ArrowUp", key: "ArrowUp" },
|
|
1233
|
+
{ code: "ArrowDown", key: "ArrowDown" },
|
|
1234
|
+
{ code: "ArrowLeft", key: "ArrowLeft" },
|
|
1235
|
+
{ code: "ArrowRight", key: "ArrowRight" },
|
|
1236
|
+
{ code: "Home", key: "Home" },
|
|
1237
|
+
{ code: "End", key: "End" },
|
|
1238
|
+
{ code: "Delete", key: "Delete" },
|
|
1239
|
+
{ code: "PageUp", key: "PageUp" },
|
|
1240
|
+
{ code: "PageDown", key: "PageDown" },
|
|
1241
|
+
{ code: "Fn", key: "Fn" },
|
|
1242
|
+
{ code: "Symbol", key: "Symbol" },
|
|
1243
|
+
{ code: "AltRight", key: "AltGraph" }
|
|
1244
|
+
];
|
|
1245
|
+
|
|
1246
|
+
// src/pointer/keyMap.ts
|
|
1247
|
+
var defaultKeyMap2 = [
|
|
1248
|
+
{ name: "MouseLeft", pointerType: "mouse", button: "primary" },
|
|
1249
|
+
{ name: "MouseRight", pointerType: "mouse", button: "secondary" },
|
|
1250
|
+
{ name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
|
|
1251
|
+
{ name: "TouchA", pointerType: "touch" },
|
|
1252
|
+
{ name: "TouchB", pointerType: "touch" },
|
|
1253
|
+
{ name: "TouchC", pointerType: "touch" }
|
|
1254
|
+
];
|
|
1255
|
+
|
|
1256
|
+
// src/options.ts
|
|
1257
|
+
var PointerEventsCheckLevel = /* @__PURE__ */ ((PointerEventsCheckLevel2) => {
|
|
1258
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTrigger"] = 4] = "EachTrigger";
|
|
1259
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachApiCall"] = 2] = "EachApiCall";
|
|
1260
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTarget"] = 1] = "EachTarget";
|
|
1261
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["Never"] = 0] = "Never";
|
|
1262
|
+
return PointerEventsCheckLevel2;
|
|
1263
|
+
})(PointerEventsCheckLevel || {});
|
|
1264
|
+
var defaultOptionsDirect = {
|
|
1265
|
+
applyAccept: true,
|
|
1266
|
+
autoModify: true,
|
|
1267
|
+
delay: 0,
|
|
1268
|
+
document: global.document,
|
|
1269
|
+
keyboardMap: defaultKeyMap,
|
|
1270
|
+
pointerMap: defaultKeyMap2,
|
|
1271
|
+
pointerEventsCheck: 2 /* EachApiCall */,
|
|
1272
|
+
skipAutoClose: false,
|
|
1273
|
+
skipClick: false,
|
|
1274
|
+
skipHover: false,
|
|
1275
|
+
writeToClipboard: false
|
|
1276
|
+
};
|
|
1277
|
+
var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
|
|
1278
|
+
writeToClipboard: true
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
// src/utils/pointer/cssPointerEvents.ts
|
|
1282
|
+
function hasPointerEvents(element) {
|
|
1283
|
+
const window2 = (0, import_helpers2.getWindowFromNode)(element);
|
|
1284
|
+
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1285
|
+
const pointerEvents = window2.getComputedStyle(el).pointerEvents;
|
|
1286
|
+
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
1287
|
+
return pointerEvents !== "none";
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
return true;
|
|
1291
|
+
}
|
|
1292
|
+
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1293
|
+
function assertPointerEvents(config, element) {
|
|
1294
|
+
const lastCheck = element[PointerEventsCheck];
|
|
1295
|
+
const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
|
|
1296
|
+
if (!needsCheck) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const result = hasPointerEvents(element);
|
|
1300
|
+
element[PointerEventsCheck] = {
|
|
1301
|
+
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1302
|
+
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1303
|
+
result
|
|
1304
|
+
};
|
|
1305
|
+
if (!result) {
|
|
1306
|
+
throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
function hasBitFlag(conf, flag) {
|
|
1310
|
+
return (conf & flag) > 0;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// src/utils/pointer/mouseButtons.ts
|
|
1314
|
+
var MouseButton = {
|
|
1315
|
+
primary: 0,
|
|
1316
|
+
secondary: 1,
|
|
1317
|
+
auxiliary: 2,
|
|
1318
|
+
back: 3,
|
|
1319
|
+
X1: 3,
|
|
1320
|
+
forward: 4,
|
|
1321
|
+
X2: 4
|
|
1322
|
+
};
|
|
1323
|
+
var MouseButtonFlip = {
|
|
1324
|
+
auxiliary: 1,
|
|
1325
|
+
secondary: 2,
|
|
1326
|
+
1: 2,
|
|
1327
|
+
2: 1
|
|
1328
|
+
};
|
|
1329
|
+
function getMouseButton(button) {
|
|
1330
|
+
if (button in MouseButtonFlip) {
|
|
1331
|
+
return MouseButtonFlip[button];
|
|
1332
|
+
}
|
|
1333
|
+
return typeof button === "number" ? button : MouseButton[button];
|
|
1334
|
+
}
|
|
1335
|
+
function getMouseButtons(...buttons) {
|
|
1336
|
+
let v = 0;
|
|
1337
|
+
for (const t of buttons) {
|
|
1338
|
+
const pos = typeof t === "number" ? t : MouseButton[t];
|
|
1339
|
+
v |= 2 ** pos;
|
|
1340
|
+
}
|
|
1341
|
+
return v;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// src/event/createEvent.ts
|
|
1345
|
+
var import_dom2 = require("@testing-library/dom");
|
|
1346
|
+
|
|
1347
|
+
// src/event/eventMap.ts
|
|
1348
|
+
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1349
|
+
var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
|
|
1350
|
+
beforeInput: {
|
|
1351
|
+
EventType: "InputEvent",
|
|
1352
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1356
|
+
|
|
1357
|
+
// src/event/eventTypes.ts
|
|
1358
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1359
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map2.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1360
|
+
function getEventClass(type3) {
|
|
1361
|
+
return type3 in eventKeys ? import_event_map2.eventMap[eventKeys[type3]].EventType : "Event";
|
|
1362
|
+
}
|
|
1363
|
+
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1364
|
+
function isMouseEvent(type3) {
|
|
1365
|
+
return mouseEvents.includes(getEventClass(type3));
|
|
1366
|
+
}
|
|
1367
|
+
function isKeyboardEvent(type3) {
|
|
1368
|
+
return getEventClass(type3) === "KeyboardEvent";
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
// src/event/createEvent.ts
|
|
1372
|
+
function createEvent(type3, target, init) {
|
|
1373
|
+
const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1374
|
+
if (isMouseEvent(type3) && init) {
|
|
1375
|
+
assignPositionInit(event, init);
|
|
1376
|
+
assignPointerInit(event, init);
|
|
1377
|
+
}
|
|
1378
|
+
return event;
|
|
1379
|
+
}
|
|
1380
|
+
function assignProps(obj, props) {
|
|
1381
|
+
for (const [key, value] of Object.entries(props)) {
|
|
1382
|
+
Object.defineProperty(obj, key, { get: () => value });
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
function assignPositionInit(obj, {
|
|
1386
|
+
x,
|
|
1387
|
+
y,
|
|
1388
|
+
clientX,
|
|
1389
|
+
clientY,
|
|
1390
|
+
offsetX,
|
|
1391
|
+
offsetY,
|
|
1392
|
+
pageX,
|
|
1393
|
+
pageY,
|
|
1394
|
+
screenX,
|
|
1395
|
+
screenY
|
|
1396
|
+
}) {
|
|
1397
|
+
var _a, _b, _c, _d;
|
|
1398
|
+
assignProps(obj, {
|
|
1399
|
+
x: (_a = x != null ? x : clientX) != null ? _a : 0,
|
|
1400
|
+
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1401
|
+
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1402
|
+
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
1403
|
+
offsetX: offsetX != null ? offsetX : 0,
|
|
1404
|
+
offsetY: offsetY != null ? offsetY : 0,
|
|
1405
|
+
pageX: pageX != null ? pageX : 0,
|
|
1406
|
+
pageY: pageY != null ? pageY : 0,
|
|
1407
|
+
screenX: screenX != null ? screenX : 0,
|
|
1408
|
+
screenY: screenY != null ? screenY : 0
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
1412
|
+
assignProps(obj, {
|
|
1413
|
+
isPrimary,
|
|
1414
|
+
pointerId,
|
|
1415
|
+
pointerType
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// src/event/behavior/registry.ts
|
|
1420
|
+
var behavior = {};
|
|
1421
|
+
|
|
1422
|
+
// src/event/behavior/click.ts
|
|
1423
|
+
behavior.click = (event, target, config) => {
|
|
1424
|
+
const context = target.closest("button,input,label,textarea");
|
|
1425
|
+
const control = context && isElementType(context, "label") && context.control;
|
|
1426
|
+
if (control) {
|
|
1427
|
+
return () => {
|
|
1428
|
+
if (isFocusable(control)) {
|
|
1429
|
+
focus(control);
|
|
1430
|
+
}
|
|
1431
|
+
dispatchEvent(config, control, cloneEvent(event));
|
|
1432
|
+
};
|
|
1433
|
+
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1434
|
+
return () => {
|
|
1435
|
+
blur(target);
|
|
1436
|
+
target.dispatchEvent(new Event("fileDialog"));
|
|
1437
|
+
focus(target);
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
// src/event/behavior/cut.ts
|
|
1443
|
+
behavior.cut = (event, target, config) => {
|
|
1444
|
+
return () => {
|
|
1445
|
+
if (isEditable(target)) {
|
|
1446
|
+
input(config, target, "", "deleteByCut");
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/event/behavior/keydown.ts
|
|
1452
|
+
behavior.keydown = (event, target, config) => {
|
|
1453
|
+
var _a, _b;
|
|
1454
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1455
|
+
};
|
|
1456
|
+
var keydownBehavior = {
|
|
1457
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1458
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1459
|
+
Backspace: (event, target, config) => {
|
|
1460
|
+
if (isEditable(target)) {
|
|
1461
|
+
return () => {
|
|
1462
|
+
input(config, target, "", "deleteContentBackward");
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
},
|
|
1466
|
+
Delete: (event, target, config) => {
|
|
1467
|
+
if (isEditable(target)) {
|
|
1468
|
+
return () => {
|
|
1469
|
+
input(config, target, "", "deleteContentForward");
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
},
|
|
1473
|
+
End: (event, target) => {
|
|
1474
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1475
|
+
return () => {
|
|
1476
|
+
var _a, _b;
|
|
1477
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1478
|
+
setSelectionRange(target, newPos, newPos);
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
},
|
|
1482
|
+
Home: (event, target) => {
|
|
1483
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1484
|
+
return () => {
|
|
1485
|
+
setSelectionRange(target, 0, 0);
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
PageDown: (event, target) => {
|
|
1490
|
+
if (isElementType(target, ["input"])) {
|
|
1491
|
+
return () => {
|
|
1492
|
+
const newPos = getValue(target).length;
|
|
1493
|
+
setSelectionRange(target, newPos, newPos);
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
},
|
|
1497
|
+
PageUp: (event, target) => {
|
|
1498
|
+
if (isElementType(target, ["input"])) {
|
|
1499
|
+
return () => {
|
|
1500
|
+
setSelectionRange(target, 0, 0);
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
},
|
|
1504
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1505
|
+
return () => {
|
|
1506
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1507
|
+
focus(dest);
|
|
1508
|
+
if (hasOwnSelection(dest)) {
|
|
1509
|
+
setUISelection(dest, {
|
|
1510
|
+
anchorOffset: 0,
|
|
1511
|
+
focusOffset: dest.value.length
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
var combinationBehavior = (event, target, config) => {
|
|
1518
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1519
|
+
return () => selectAll(target);
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// src/event/behavior/keypress.ts
|
|
1524
|
+
behavior.keypress = (event, target, config) => {
|
|
1525
|
+
if (event.key === "Enter") {
|
|
1526
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1527
|
+
return () => {
|
|
1528
|
+
dispatchUIEvent(config, target, "click");
|
|
1529
|
+
};
|
|
1530
|
+
} else if (isElementType(target, "input")) {
|
|
1531
|
+
const form = target.form;
|
|
1532
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1533
|
+
if (submit) {
|
|
1534
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1535
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1536
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1537
|
+
} else {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
if (isEditable(target)) {
|
|
1543
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1544
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1545
|
+
return () => input(config, target, inputData, inputType);
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
var ClickInputOnEnter = [
|
|
1549
|
+
"button",
|
|
1550
|
+
"color",
|
|
1551
|
+
"file",
|
|
1552
|
+
"image",
|
|
1553
|
+
"reset",
|
|
1554
|
+
"submit"
|
|
1555
|
+
];
|
|
1556
|
+
var SubmitSingleInputOnEnter = [
|
|
1557
|
+
"email",
|
|
1558
|
+
"month",
|
|
1559
|
+
"password",
|
|
1560
|
+
"search",
|
|
1561
|
+
"tel",
|
|
1562
|
+
"text",
|
|
1563
|
+
"url",
|
|
1564
|
+
"week"
|
|
1565
|
+
];
|
|
1566
|
+
|
|
1567
|
+
// src/event/behavior/keyup.ts
|
|
1568
|
+
behavior.keyup = (event, target, config) => {
|
|
1569
|
+
var _a;
|
|
1570
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1571
|
+
};
|
|
1572
|
+
var keyupBehavior = {
|
|
1573
|
+
" ": (event, target, config) => {
|
|
1574
|
+
if (isClickableInput(target)) {
|
|
1575
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
|
|
1580
|
+
// src/event/behavior/paste.ts
|
|
1581
|
+
behavior.paste = (event, target, config) => {
|
|
1582
|
+
if (isEditable(target)) {
|
|
1583
|
+
return () => {
|
|
1584
|
+
var _a;
|
|
1585
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1586
|
+
if (insertData) {
|
|
1587
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
// src/event/wrapEvent.ts
|
|
1594
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1595
|
+
function wrapEvent(cb, _element) {
|
|
1596
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
// src/event/dispatchEvent.ts
|
|
1600
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1601
|
+
var _a, _b;
|
|
1602
|
+
const type3 = event.type;
|
|
1603
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1604
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1605
|
+
if (behaviorImplementation) {
|
|
1606
|
+
event.preventDefault();
|
|
1607
|
+
let defaultPrevented = false;
|
|
1608
|
+
Object.defineProperty(event, "defaultPrevented", {
|
|
1609
|
+
get: () => defaultPrevented
|
|
1610
|
+
});
|
|
1611
|
+
Object.defineProperty(event, "preventDefault", {
|
|
1612
|
+
value: () => {
|
|
1613
|
+
defaultPrevented = event.cancelable;
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1617
|
+
if (!defaultPrevented) {
|
|
1618
|
+
behaviorImplementation();
|
|
1619
|
+
}
|
|
1620
|
+
return !defaultPrevented;
|
|
1621
|
+
}
|
|
1622
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// src/event/index.ts
|
|
1626
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1627
|
+
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1628
|
+
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1629
|
+
}
|
|
1630
|
+
const event = createEvent(type3, target, init);
|
|
1631
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1632
|
+
}
|
|
1633
|
+
function bindDispatchUIEvent(config) {
|
|
1634
|
+
return dispatchUIEvent.bind(void 0, config);
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
// src/document/interceptor.ts
|
|
1638
|
+
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
1639
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
1640
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
1641
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1642
|
+
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1643
|
+
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
function intercept(...args) {
|
|
1647
|
+
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
1648
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
1649
|
+
if (target === "set") {
|
|
1650
|
+
realFunc.call(this, realArgs);
|
|
1651
|
+
} else {
|
|
1652
|
+
realFunc.call(this, ...realArgs);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
;
|
|
1656
|
+
intercept[Interceptor] = Interceptor;
|
|
1657
|
+
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
1658
|
+
[target]: intercept
|
|
1659
|
+
}));
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
// src/document/selection.ts
|
|
1663
|
+
var UISelection = Symbol("Displayed selection in UI");
|
|
1664
|
+
function prepareSelectionInterceptor(element) {
|
|
1665
|
+
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
1666
|
+
const isUI = start && typeof start === "object" && start[UISelection];
|
|
1667
|
+
if (!isUI) {
|
|
1668
|
+
this[UISelection] = void 0;
|
|
1669
|
+
}
|
|
1670
|
+
return {
|
|
1671
|
+
realArgs: [Number(start), end, direction]
|
|
1672
|
+
};
|
|
1673
|
+
});
|
|
1674
|
+
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
1675
|
+
this[UISelection] = void 0;
|
|
1676
|
+
return { realArgs: v };
|
|
1677
|
+
});
|
|
1678
|
+
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
1679
|
+
this[UISelection] = void 0;
|
|
1680
|
+
return { realArgs: v };
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
function setUISelection(element, {
|
|
1684
|
+
focusOffset: focusOffsetParam,
|
|
1685
|
+
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
1686
|
+
}, mode = "replace") {
|
|
1687
|
+
const valueLength = getUIValue(element).length;
|
|
1688
|
+
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
1689
|
+
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
1690
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
1691
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
1692
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
1693
|
+
element[UISelection] = {
|
|
1694
|
+
anchorOffset,
|
|
1695
|
+
focusOffset
|
|
1696
|
+
};
|
|
1697
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
const startObj = new Number(startOffset);
|
|
1701
|
+
startObj[UISelection] = UISelection;
|
|
1702
|
+
try {
|
|
1703
|
+
element.setSelectionRange(startObj, endOffset);
|
|
1704
|
+
} catch {
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
function getUISelection(element) {
|
|
1708
|
+
var _a, _b, _c;
|
|
1709
|
+
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1710
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1711
|
+
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1712
|
+
};
|
|
1713
|
+
return __spreadProps(__spreadValues({}, sel), {
|
|
1714
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
1715
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
function clearUISelection(element) {
|
|
1719
|
+
element[UISelection] = void 0;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
// src/document/value.ts
|
|
1723
|
+
var UIValue = Symbol("Displayed value in UI");
|
|
1724
|
+
var InitialValue = Symbol("Initial value to compare on blur");
|
|
1725
|
+
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1726
|
+
function valueInterceptor(v) {
|
|
1727
|
+
const isUI = typeof v === "object" && v[UIValue];
|
|
1728
|
+
this[UIValue] = isUI ? String(v) : void 0;
|
|
1729
|
+
if (!isUI) {
|
|
1730
|
+
trackValue(this, String(v));
|
|
1731
|
+
this[InitialValue] = String(v);
|
|
1732
|
+
clearUISelection(this);
|
|
1733
|
+
}
|
|
1734
|
+
return {
|
|
1735
|
+
applyNative: !!isUI,
|
|
1736
|
+
realArgs: String(v)
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
function prepareValueInterceptor(element) {
|
|
1740
|
+
prepareInterceptor(element, "value", valueInterceptor);
|
|
1741
|
+
}
|
|
1742
|
+
function setUIValue(element, value) {
|
|
1743
|
+
element.value = {
|
|
1744
|
+
[UIValue]: UIValue,
|
|
1745
|
+
toString: () => value
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
function getUIValue(element) {
|
|
1749
|
+
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
1750
|
+
}
|
|
1751
|
+
function setInitialValue(element) {
|
|
1752
|
+
element[InitialValue] = element.value;
|
|
1753
|
+
}
|
|
1754
|
+
function getInitialValue(element) {
|
|
1755
|
+
return element[InitialValue];
|
|
1756
|
+
}
|
|
1757
|
+
function startTrackValue(element) {
|
|
1758
|
+
element[TrackChanges] = [];
|
|
1759
|
+
}
|
|
1760
|
+
function trackValue(element, v) {
|
|
1761
|
+
var _a;
|
|
1762
|
+
(_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
|
|
1763
|
+
}
|
|
1764
|
+
function endTrackValue(element) {
|
|
1765
|
+
const tracked = element[TrackChanges];
|
|
1766
|
+
element[TrackChanges] = void 0;
|
|
1767
|
+
return tracked;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
// src/document/index.ts
|
|
1771
|
+
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1772
|
+
function prepareDocument(document2) {
|
|
1773
|
+
if (document2[isPrepared]) {
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
document2.addEventListener("focus", (e) => {
|
|
1777
|
+
const el = e.target;
|
|
1778
|
+
prepareElement(el);
|
|
1779
|
+
}, {
|
|
1780
|
+
capture: true,
|
|
1781
|
+
passive: true
|
|
1782
|
+
});
|
|
1783
|
+
if (document2.activeElement) {
|
|
1784
|
+
prepareElement(document2.activeElement);
|
|
1785
|
+
}
|
|
1786
|
+
document2.addEventListener("blur", (e) => {
|
|
1787
|
+
const el = e.target;
|
|
1788
|
+
const initialValue = getInitialValue(el);
|
|
1789
|
+
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
1790
|
+
dispatchUIEvent({}, el, "change");
|
|
1791
|
+
}
|
|
1792
|
+
}, {
|
|
1793
|
+
capture: true,
|
|
1794
|
+
passive: true
|
|
1795
|
+
});
|
|
1796
|
+
document2[isPrepared] = isPrepared;
|
|
1797
|
+
}
|
|
1798
|
+
function prepareElement(el) {
|
|
1799
|
+
if ("value" in el) {
|
|
1800
|
+
setInitialValue(el);
|
|
1801
|
+
}
|
|
1802
|
+
if (el[isPrepared]) {
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
if ("value" in el) {
|
|
1806
|
+
prepareValueInterceptor(el);
|
|
1807
|
+
prepareSelectionInterceptor(el);
|
|
1808
|
+
}
|
|
1809
|
+
el[isPrepared] = isPrepared;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
// src/keyboard/modifiers.ts
|
|
1813
|
+
var modifierKeys = [
|
|
1814
|
+
"Alt",
|
|
1815
|
+
"AltGraph",
|
|
1816
|
+
"Control",
|
|
1817
|
+
"Fn",
|
|
1818
|
+
"Meta",
|
|
1819
|
+
"Shift",
|
|
1820
|
+
"Symbol"
|
|
1821
|
+
];
|
|
1822
|
+
function isModifierKey(key) {
|
|
1823
|
+
return modifierKeys.includes(key);
|
|
1824
|
+
}
|
|
1825
|
+
var modifierLocks = [
|
|
1826
|
+
"CapsLock",
|
|
1827
|
+
"FnLock",
|
|
1828
|
+
"NumLock",
|
|
1829
|
+
"ScrollLock",
|
|
1830
|
+
"SymbolLock"
|
|
1831
|
+
];
|
|
1832
|
+
function isModifierLock(key) {
|
|
1833
|
+
return modifierLocks.includes(key);
|
|
1834
|
+
}
|
|
1835
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1836
|
+
var _a;
|
|
1837
|
+
if (isModifierKey(key)) {
|
|
1838
|
+
config.keyboardState.modifiers[key] = true;
|
|
1839
|
+
if (key === "AltGraph") {
|
|
1840
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1841
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1842
|
+
}
|
|
1843
|
+
} else if (isModifierLock(key)) {
|
|
1844
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1845
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1846
|
+
config.keyboardState.modifiers[key] = true;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
function preKeyupBehavior(config, { key }) {
|
|
1851
|
+
if (isModifierKey(key)) {
|
|
1852
|
+
config.keyboardState.modifiers[key] = false;
|
|
1853
|
+
} else if (isModifierLock(key)) {
|
|
1854
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1855
|
+
config.keyboardState.modifiers[key] = false;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1860
|
+
var _a;
|
|
1861
|
+
if (key === "AltGraph") {
|
|
1862
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1863
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// src/keyboard/keyboardAction.ts
|
|
1868
|
+
async function keyboardAction(config, actions) {
|
|
1869
|
+
for (let i = 0; i < actions.length; i++) {
|
|
1870
|
+
await keyboardKeyAction(config, actions[i]);
|
|
1871
|
+
if (typeof config.delay === "number" && i < actions.length - 1) {
|
|
1872
|
+
await wait(config.delay);
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf, repeat }) {
|
|
1877
|
+
const { document: document2, keyboardState, delay } = config;
|
|
1878
|
+
const getCurrentElement = () => getActive(document2);
|
|
1879
|
+
const pressed = keyboardState.pressed.find((p) => p.keyDef === keyDef);
|
|
1880
|
+
if (pressed) {
|
|
1881
|
+
await keyup(keyDef, getCurrentElement, config, pressed.unpreventedDefault);
|
|
1882
|
+
}
|
|
1883
|
+
if (!releasePrevious) {
|
|
1884
|
+
let unpreventedDefault = true;
|
|
1885
|
+
for (let i = 1; i <= repeat; i++) {
|
|
1886
|
+
unpreventedDefault = await keydown(keyDef, getCurrentElement, config);
|
|
1887
|
+
if (unpreventedDefault && hasKeyPress(keyDef, config)) {
|
|
1888
|
+
await keypress(keyDef, getCurrentElement, config);
|
|
1889
|
+
}
|
|
1890
|
+
if (typeof delay === "number" && i < repeat) {
|
|
1891
|
+
await wait(delay);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
if (releaseSelf) {
|
|
1895
|
+
await keyup(keyDef, getCurrentElement, config, unpreventedDefault);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
function getActive(document2) {
|
|
1900
|
+
var _a;
|
|
1901
|
+
return (_a = getActiveElement(document2)) != null ? _a : document2.body;
|
|
1902
|
+
}
|
|
1903
|
+
async function releaseAllKeys(config) {
|
|
1904
|
+
const getCurrentElement = () => getActive(config.document);
|
|
1905
|
+
for (const k of config.keyboardState.pressed) {
|
|
1906
|
+
await keyup(k.keyDef, getCurrentElement, config, k.unpreventedDefault);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
async function keydown(keyDef, getCurrentElement, config) {
|
|
1910
|
+
const element = getCurrentElement();
|
|
1911
|
+
if (element !== config.keyboardState.activeElement) {
|
|
1912
|
+
config.keyboardState.carryValue = void 0;
|
|
1913
|
+
config.keyboardState.carryChar = "";
|
|
1914
|
+
}
|
|
1915
|
+
config.keyboardState.activeElement = element;
|
|
1916
|
+
preKeydownBehavior(config, keyDef, element);
|
|
1917
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
1918
|
+
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
1919
|
+
return unpreventedDefault;
|
|
1920
|
+
}
|
|
1921
|
+
async function keypress(keyDef, getCurrentElement, config) {
|
|
1922
|
+
const element = getCurrentElement();
|
|
1923
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
1924
|
+
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
1925
|
+
}));
|
|
1926
|
+
}
|
|
1927
|
+
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
1928
|
+
const element = getCurrentElement();
|
|
1929
|
+
preKeyupBehavior(config, keyDef);
|
|
1930
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
1931
|
+
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
1932
|
+
postKeyupBehavior(config, keyDef, element);
|
|
1933
|
+
}
|
|
1934
|
+
function hasKeyPress(keyDef, config) {
|
|
1935
|
+
var _a;
|
|
1936
|
+
return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
// src/keyboard/parseKeyDef.ts
|
|
1940
|
+
function parseKeyDef(keyboardMap, text) {
|
|
1941
|
+
var _a;
|
|
1942
|
+
const defs = [];
|
|
1943
|
+
do {
|
|
1944
|
+
const {
|
|
1945
|
+
type: type3,
|
|
1946
|
+
descriptor,
|
|
1947
|
+
consumedLength,
|
|
1948
|
+
releasePrevious,
|
|
1949
|
+
releaseSelf = true,
|
|
1950
|
+
repeat
|
|
1951
|
+
} = readNextDescriptor(text);
|
|
1952
|
+
const keyDef = (_a = keyboardMap.find((def) => {
|
|
1953
|
+
var _a2, _b;
|
|
1954
|
+
if (type3 === "[") {
|
|
1955
|
+
return ((_a2 = def.code) == null ? void 0 : _a2.toLowerCase()) === descriptor.toLowerCase();
|
|
1956
|
+
} else if (type3 === "{") {
|
|
1957
|
+
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
1958
|
+
}
|
|
1959
|
+
return def.key === descriptor;
|
|
1960
|
+
})) != null ? _a : {
|
|
1961
|
+
key: "Unknown",
|
|
1962
|
+
code: "Unknown",
|
|
1963
|
+
[type3 === "[" ? "code" : "key"]: descriptor
|
|
1964
|
+
};
|
|
1965
|
+
defs.push({ keyDef, releasePrevious, releaseSelf, repeat });
|
|
1966
|
+
text = text.slice(consumedLength);
|
|
1967
|
+
} while (text);
|
|
1968
|
+
return defs;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
// src/keyboard/index.ts
|
|
1972
|
+
async function keyboard(text) {
|
|
1973
|
+
const actions = parseKeyDef(this[Config].keyboardMap, text);
|
|
1974
|
+
return keyboardAction(this[Config], actions);
|
|
1975
|
+
}
|
|
1976
|
+
function createKeyboardState() {
|
|
1977
|
+
return {
|
|
1978
|
+
activeElement: null,
|
|
1979
|
+
pressed: [],
|
|
1980
|
+
carryChar: "",
|
|
1981
|
+
modifiers: {
|
|
1982
|
+
Alt: false,
|
|
1983
|
+
AltGraph: false,
|
|
1984
|
+
Control: false,
|
|
1985
|
+
CapsLock: false,
|
|
1986
|
+
Fn: false,
|
|
1987
|
+
FnLock: false,
|
|
1988
|
+
Meta: false,
|
|
1989
|
+
NumLock: false,
|
|
1990
|
+
ScrollLock: false,
|
|
1991
|
+
Shift: false,
|
|
1992
|
+
Symbol: false,
|
|
1993
|
+
SymbolLock: false
|
|
1994
|
+
},
|
|
1995
|
+
modifierPhase: {}
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
// src/pointer/parseKeyDef.ts
|
|
2000
|
+
function parseKeyDef2(pointerMap, keys) {
|
|
2001
|
+
const defs = [];
|
|
2002
|
+
do {
|
|
2003
|
+
const {
|
|
2004
|
+
descriptor,
|
|
2005
|
+
consumedLength,
|
|
2006
|
+
releasePrevious,
|
|
2007
|
+
releaseSelf = true
|
|
2008
|
+
} = readNextDescriptor(keys);
|
|
2009
|
+
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
2010
|
+
if (keyDef) {
|
|
2011
|
+
defs.push({ keyDef, releasePrevious, releaseSelf });
|
|
2012
|
+
}
|
|
2013
|
+
keys = keys.slice(consumedLength);
|
|
2014
|
+
} while (keys);
|
|
2015
|
+
return defs;
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
// src/pointer/firePointerEvents.ts
|
|
2019
|
+
function firePointerEvent(config, target, type3, {
|
|
2020
|
+
pointerType,
|
|
2021
|
+
button,
|
|
2022
|
+
coords,
|
|
2023
|
+
pointerId,
|
|
2024
|
+
isPrimary,
|
|
2025
|
+
clickCount
|
|
2026
|
+
}) {
|
|
2027
|
+
const init = __spreadValues({}, coords);
|
|
2028
|
+
if (type3 === "click" || type3.startsWith("pointer")) {
|
|
2029
|
+
init.pointerId = pointerId;
|
|
2030
|
+
init.pointerType = pointerType;
|
|
2031
|
+
}
|
|
2032
|
+
if (["pointerdown", "pointerup"].includes(type3)) {
|
|
2033
|
+
init.isPrimary = isPrimary;
|
|
2034
|
+
}
|
|
2035
|
+
init.button = getMouseButton(button != null ? button : 0);
|
|
2036
|
+
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2037
|
+
var _a;
|
|
2038
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2039
|
+
}));
|
|
2040
|
+
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2041
|
+
init.detail = clickCount;
|
|
2042
|
+
}
|
|
2043
|
+
return dispatchUIEvent(config, target, type3, init);
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
// src/pointer/resolveSelectionTarget.ts
|
|
2047
|
+
function resolveSelectionTarget({
|
|
2048
|
+
target,
|
|
2049
|
+
node,
|
|
2050
|
+
offset
|
|
2051
|
+
}) {
|
|
2052
|
+
if (isElementType(target, ["input", "textarea"])) {
|
|
2053
|
+
return {
|
|
2054
|
+
node: target,
|
|
2055
|
+
offset: offset != null ? offset : getUIValue(target).length
|
|
2056
|
+
};
|
|
2057
|
+
} else if (node) {
|
|
2058
|
+
return {
|
|
2059
|
+
node,
|
|
2060
|
+
offset: offset != null ? offset : node.nodeType === 3 ? node.nodeValue.length : node.childNodes.length
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
return findNodeAtTextOffset(target, offset);
|
|
2064
|
+
}
|
|
2065
|
+
function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
2066
|
+
let i = offset === void 0 ? node.childNodes.length - 1 : 0;
|
|
2067
|
+
const step = offset === void 0 ? -1 : 1;
|
|
2068
|
+
while (offset === void 0 ? i >= (isRoot ? Math.max(node.childNodes.length - 1, 0) : 0) : i <= node.childNodes.length) {
|
|
2069
|
+
const c = node.childNodes.item(i);
|
|
2070
|
+
const text = String(c.textContent);
|
|
2071
|
+
if (text.length) {
|
|
2072
|
+
if (offset !== void 0 && text.length < offset) {
|
|
2073
|
+
offset -= text.length;
|
|
2074
|
+
} else if (c.nodeType === 1) {
|
|
2075
|
+
return findNodeAtTextOffset(c, offset, false);
|
|
2076
|
+
} else {
|
|
2077
|
+
if (c.nodeType === 3) {
|
|
2078
|
+
return {
|
|
2079
|
+
node: c,
|
|
2080
|
+
offset: offset != null ? offset : c.nodeValue.length
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
i += step;
|
|
2086
|
+
}
|
|
2087
|
+
return { node, offset: node.childNodes.length };
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
// src/pointer/pointerMove.ts
|
|
2091
|
+
async function pointerMove(config, { pointerName = "mouse", target, coords, node, offset }) {
|
|
2092
|
+
const { pointerState } = config;
|
|
2093
|
+
if (!(pointerName in pointerState.position)) {
|
|
2094
|
+
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
2095
|
+
}
|
|
2096
|
+
const {
|
|
2097
|
+
pointerId,
|
|
2098
|
+
pointerType,
|
|
2099
|
+
target: prevTarget,
|
|
2100
|
+
coords: prevCoords,
|
|
2101
|
+
selectionRange
|
|
2102
|
+
} = pointerState.position[pointerName];
|
|
2103
|
+
if (prevTarget && prevTarget !== target) {
|
|
2104
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2105
|
+
assertPointerEvents(config, prevTarget);
|
|
2106
|
+
fireMove(prevTarget, prevCoords);
|
|
2107
|
+
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
2108
|
+
fireLeave(prevTarget, prevCoords);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2112
|
+
assertPointerEvents(config, target);
|
|
2113
|
+
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
2114
|
+
target,
|
|
2115
|
+
coords
|
|
2116
|
+
});
|
|
2117
|
+
if (prevTarget !== target) {
|
|
2118
|
+
if (!prevTarget || !isDescendantOrSelf(prevTarget, target)) {
|
|
2119
|
+
fireEnter(target, coords);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
fireMove(target, coords);
|
|
2123
|
+
if (selectionRange) {
|
|
2124
|
+
const selectionFocus = resolveSelectionTarget({ target, node, offset });
|
|
2125
|
+
if ("node" in selectionRange) {
|
|
2126
|
+
if (selectionFocus.node === selectionRange.node) {
|
|
2127
|
+
const anchorOffset = selectionFocus.offset < selectionRange.start ? selectionRange.end : selectionRange.start;
|
|
2128
|
+
const focusOffset = selectionFocus.offset > selectionRange.end || selectionFocus.offset < selectionRange.start ? selectionFocus.offset : selectionRange.end;
|
|
2129
|
+
setUISelection(selectionRange.node, { anchorOffset, focusOffset });
|
|
2130
|
+
}
|
|
2131
|
+
} else {
|
|
2132
|
+
const range = selectionRange.cloneRange();
|
|
2133
|
+
const cmp = range.comparePoint(selectionFocus.node, selectionFocus.offset);
|
|
2134
|
+
if (cmp < 0) {
|
|
2135
|
+
range.setStart(selectionFocus.node, selectionFocus.offset);
|
|
2136
|
+
} else if (cmp > 0) {
|
|
2137
|
+
range.setEnd(selectionFocus.node, selectionFocus.offset);
|
|
2138
|
+
}
|
|
2139
|
+
const selection = target.ownerDocument.getSelection();
|
|
2140
|
+
selection.removeAllRanges();
|
|
2141
|
+
selection.addRange(range.cloneRange());
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
function fireMove(eventTarget, eventCoords) {
|
|
2145
|
+
fire(eventTarget, "pointermove", eventCoords);
|
|
2146
|
+
if (pointerType === "mouse" && !isDisabled(eventTarget)) {
|
|
2147
|
+
fire(eventTarget, "mousemove", eventCoords);
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
function fireLeave(eventTarget, eventCoords) {
|
|
2151
|
+
fire(eventTarget, "pointerout", eventCoords);
|
|
2152
|
+
fire(eventTarget, "pointerleave", eventCoords);
|
|
2153
|
+
if (pointerType === "mouse" && !isDisabled(eventTarget)) {
|
|
2154
|
+
fire(eventTarget, "mouseout", eventCoords);
|
|
2155
|
+
fire(eventTarget, "mouseleave", eventCoords);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
function fireEnter(eventTarget, eventCoords) {
|
|
2159
|
+
fire(eventTarget, "pointerover", eventCoords);
|
|
2160
|
+
fire(eventTarget, "pointerenter", eventCoords);
|
|
2161
|
+
if (pointerType === "mouse" && !isDisabled(eventTarget)) {
|
|
2162
|
+
fire(eventTarget, "mouseover", eventCoords);
|
|
2163
|
+
fire(eventTarget, "mouseenter", eventCoords);
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
function fire(eventTarget, type3, eventCoords) {
|
|
2167
|
+
return firePointerEvent(config, eventTarget, type3, {
|
|
2168
|
+
coords: eventCoords,
|
|
2169
|
+
pointerId,
|
|
2170
|
+
pointerType
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
// src/pointer/pointerPress.ts
|
|
2176
|
+
async function pointerPress(config, action) {
|
|
2177
|
+
const { keyDef, target, releasePrevious, releaseSelf } = action;
|
|
2178
|
+
const previous = config.pointerState.pressed.find((p) => p.keyDef === keyDef);
|
|
2179
|
+
const pointerName = keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
|
|
2180
|
+
const targetIsDisabled = isDisabled(target);
|
|
2181
|
+
if (previous) {
|
|
2182
|
+
up(config, pointerName, action, previous, targetIsDisabled);
|
|
2183
|
+
}
|
|
2184
|
+
if (!releasePrevious) {
|
|
2185
|
+
const press = down(config, pointerName, action, targetIsDisabled);
|
|
2186
|
+
if (releaseSelf) {
|
|
2187
|
+
up(config, pointerName, action, press, targetIsDisabled);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
function getNextPointerId(state) {
|
|
2192
|
+
state.pointerId = state.pointerId + 1;
|
|
2193
|
+
return state.pointerId;
|
|
2194
|
+
}
|
|
2195
|
+
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2196
|
+
var _a, _b, _c;
|
|
2197
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2198
|
+
assertPointerEvents(config, target);
|
|
2199
|
+
const { pointerState } = config;
|
|
2200
|
+
const { name, pointerType, button } = keyDef;
|
|
2201
|
+
const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
|
|
2202
|
+
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
2203
|
+
pointerId,
|
|
2204
|
+
pointerType,
|
|
2205
|
+
target,
|
|
2206
|
+
coords
|
|
2207
|
+
});
|
|
2208
|
+
let isMultiTouch = false;
|
|
2209
|
+
let isPrimary = true;
|
|
2210
|
+
if (pointerType !== "mouse") {
|
|
2211
|
+
for (const obj of pointerState.pressed) {
|
|
2212
|
+
if (obj.keyDef.pointerType === pointerType) {
|
|
2213
|
+
obj.isMultiTouch = true;
|
|
2214
|
+
isMultiTouch = true;
|
|
2215
|
+
isPrimary = false;
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
if (((_a = pointerState.activeClickCount) == null ? void 0 : _a[0]) !== name) {
|
|
2220
|
+
delete pointerState.activeClickCount;
|
|
2221
|
+
}
|
|
2222
|
+
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
2223
|
+
pointerState.activeClickCount = [name, clickCount];
|
|
2224
|
+
const pressObj = {
|
|
2225
|
+
keyDef,
|
|
2226
|
+
downTarget: target,
|
|
2227
|
+
pointerId,
|
|
2228
|
+
unpreventedDefault: true,
|
|
2229
|
+
isMultiTouch,
|
|
2230
|
+
isPrimary,
|
|
2231
|
+
clickCount
|
|
2232
|
+
};
|
|
2233
|
+
pointerState.pressed.push(pressObj);
|
|
2234
|
+
if (pointerType !== "mouse") {
|
|
2235
|
+
fire("pointerover");
|
|
2236
|
+
fire("pointerenter");
|
|
2237
|
+
}
|
|
2238
|
+
if (pointerType !== "mouse" || !pointerState.pressed.some((p) => p.keyDef !== keyDef && p.keyDef.pointerType === pointerType)) {
|
|
2239
|
+
fire("pointerdown");
|
|
2240
|
+
}
|
|
2241
|
+
if (pointerType === "mouse") {
|
|
2242
|
+
if (!targetIsDisabled) {
|
|
2243
|
+
pressObj.unpreventedDefault = fire("mousedown");
|
|
2244
|
+
}
|
|
2245
|
+
if (pressObj.unpreventedDefault) {
|
|
2246
|
+
mousedownDefaultBehavior({
|
|
2247
|
+
target,
|
|
2248
|
+
targetIsDisabled,
|
|
2249
|
+
clickCount,
|
|
2250
|
+
position: pointerState.position[pointerName],
|
|
2251
|
+
node,
|
|
2252
|
+
offset
|
|
2253
|
+
});
|
|
2254
|
+
}
|
|
2255
|
+
if (button === "secondary") {
|
|
2256
|
+
fire("contextmenu");
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
return pressObj;
|
|
2260
|
+
function fire(type3) {
|
|
2261
|
+
return firePointerEvent(config, target, type3, {
|
|
2262
|
+
button,
|
|
2263
|
+
clickCount,
|
|
2264
|
+
coords,
|
|
2265
|
+
isPrimary,
|
|
2266
|
+
pointerId,
|
|
2267
|
+
pointerType
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
function up(config, pointerName, {
|
|
2272
|
+
keyDef: { pointerType, button },
|
|
2273
|
+
target,
|
|
2274
|
+
coords,
|
|
2275
|
+
node,
|
|
2276
|
+
offset
|
|
2277
|
+
}, pressed, targetIsDisabled) {
|
|
2278
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2279
|
+
assertPointerEvents(config, target);
|
|
2280
|
+
const { pointerState } = config;
|
|
2281
|
+
pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
|
|
2282
|
+
const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
|
|
2283
|
+
let { unpreventedDefault } = pressed;
|
|
2284
|
+
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
2285
|
+
target,
|
|
2286
|
+
coords
|
|
2287
|
+
});
|
|
2288
|
+
if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
|
|
2289
|
+
fire("pointerup");
|
|
2290
|
+
}
|
|
2291
|
+
if (pointerType !== "mouse") {
|
|
2292
|
+
fire("pointerout");
|
|
2293
|
+
fire("pointerleave");
|
|
2294
|
+
}
|
|
2295
|
+
if (pointerType !== "mouse" && !isMultiTouch) {
|
|
2296
|
+
if (!targetIsDisabled) {
|
|
2297
|
+
if (clickCount === 1) {
|
|
2298
|
+
fire("mouseover");
|
|
2299
|
+
fire("mouseenter");
|
|
2300
|
+
}
|
|
2301
|
+
fire("mousemove");
|
|
2302
|
+
unpreventedDefault = fire("mousedown") && unpreventedDefault;
|
|
2303
|
+
}
|
|
2304
|
+
if (unpreventedDefault) {
|
|
2305
|
+
mousedownDefaultBehavior({
|
|
2306
|
+
target,
|
|
2307
|
+
targetIsDisabled,
|
|
2308
|
+
clickCount,
|
|
2309
|
+
position: pointerState.position[pointerName],
|
|
2310
|
+
node,
|
|
2311
|
+
offset
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
delete pointerState.position[pointerName].selectionRange;
|
|
2316
|
+
if (!targetIsDisabled) {
|
|
2317
|
+
if (pointerType === "mouse" || !isMultiTouch) {
|
|
2318
|
+
unpreventedDefault = fire("mouseup") && unpreventedDefault;
|
|
2319
|
+
const canClick = pointerType !== "mouse" || button === "primary";
|
|
2320
|
+
if (canClick && target === pressed.downTarget) {
|
|
2321
|
+
fire("click");
|
|
2322
|
+
if (clickCount === 2) {
|
|
2323
|
+
fire("dblclick");
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
function fire(type3) {
|
|
2329
|
+
return firePointerEvent(config, target, type3, {
|
|
2330
|
+
button,
|
|
2331
|
+
clickCount,
|
|
2332
|
+
coords,
|
|
2333
|
+
isPrimary,
|
|
2334
|
+
pointerId,
|
|
2335
|
+
pointerType
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
function mousedownDefaultBehavior({
|
|
2340
|
+
position,
|
|
2341
|
+
target,
|
|
2342
|
+
targetIsDisabled,
|
|
2343
|
+
clickCount,
|
|
2344
|
+
node,
|
|
2345
|
+
offset
|
|
2346
|
+
}) {
|
|
2347
|
+
focus(target);
|
|
2348
|
+
if (!targetIsDisabled) {
|
|
2349
|
+
const hasValue = isElementType(target, ["input", "textarea"]);
|
|
2350
|
+
const text = String(hasValue ? getUIValue(target) : target.textContent);
|
|
2351
|
+
const [start, end] = node ? [offset, offset] : getTextRange(text, offset, clickCount);
|
|
2352
|
+
if (hasValue) {
|
|
2353
|
+
setUISelection(target, {
|
|
2354
|
+
anchorOffset: start != null ? start : text.length,
|
|
2355
|
+
focusOffset: end != null ? end : text.length
|
|
2356
|
+
});
|
|
2357
|
+
position.selectionRange = {
|
|
2358
|
+
node: target,
|
|
2359
|
+
start: start != null ? start : 0,
|
|
2360
|
+
end: end != null ? end : text.length
|
|
2361
|
+
};
|
|
2362
|
+
} else {
|
|
2363
|
+
const { node: startNode, offset: startOffset } = resolveSelectionTarget({
|
|
2364
|
+
target,
|
|
2365
|
+
node,
|
|
2366
|
+
offset: start
|
|
2367
|
+
});
|
|
2368
|
+
const { node: endNode, offset: endOffset } = resolveSelectionTarget({
|
|
2369
|
+
target,
|
|
2370
|
+
node,
|
|
2371
|
+
offset: end
|
|
2372
|
+
});
|
|
2373
|
+
const range = new Range();
|
|
2374
|
+
range.setStart(startNode, startOffset);
|
|
2375
|
+
range.setEnd(endNode, endOffset);
|
|
2376
|
+
position.selectionRange = range;
|
|
2377
|
+
const selection = target.ownerDocument.getSelection();
|
|
2378
|
+
selection.removeAllRanges();
|
|
2379
|
+
selection.addRange(range.cloneRange());
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
function getTextRange(text, pos, clickCount) {
|
|
2384
|
+
if (clickCount % 3 === 1 || text.length === 0) {
|
|
2385
|
+
return [pos, pos];
|
|
2386
|
+
}
|
|
2387
|
+
const textPos = pos != null ? pos : text.length;
|
|
2388
|
+
if (clickCount % 3 === 2) {
|
|
2389
|
+
return [
|
|
2390
|
+
textPos - text.substr(0, pos).match(/(\w+|\s+|\W)?$/)[0].length,
|
|
2391
|
+
pos === void 0 ? pos : pos + text.substr(pos).match(/^(\w+|\s+|\W)?/)[0].length
|
|
2392
|
+
];
|
|
2393
|
+
}
|
|
2394
|
+
return [
|
|
2395
|
+
textPos - text.substr(0, pos).match(/[^\r\n]*$/)[0].length,
|
|
2396
|
+
pos === void 0 ? pos : pos + text.substr(pos).match(/^[^\r\n]*/)[0].length
|
|
2397
|
+
];
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
// src/pointer/pointerAction.ts
|
|
2401
|
+
async function pointerAction(config, actions) {
|
|
2402
|
+
var _a, _b;
|
|
2403
|
+
for (let i = 0; i < actions.length; i++) {
|
|
2404
|
+
const action = actions[i];
|
|
2405
|
+
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2406
|
+
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2407
|
+
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2408
|
+
await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
|
|
2409
|
+
if (typeof config.delay === "number") {
|
|
2410
|
+
if (i < actions.length - 1) {
|
|
2411
|
+
await wait(config.delay);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
delete config.pointerState.activeClickCount;
|
|
2416
|
+
}
|
|
2417
|
+
function getPrevTarget(pointerName, state) {
|
|
2418
|
+
if (!(pointerName in state.position) || !state.position[pointerName].target) {
|
|
2419
|
+
throw new Error("This pointer has no previous position. Provide a target property!");
|
|
2420
|
+
}
|
|
2421
|
+
return state.position[pointerName].target;
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
// src/pointer/index.ts
|
|
2425
|
+
async function pointer(input2) {
|
|
2426
|
+
const { pointerMap } = this[Config];
|
|
2427
|
+
const actions = [];
|
|
2428
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2429
|
+
if (typeof actionInput === "string") {
|
|
2430
|
+
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2431
|
+
} else if ("keys" in actionInput) {
|
|
2432
|
+
actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => __spreadValues(__spreadValues({}, actionInput), i)));
|
|
2433
|
+
} else {
|
|
2434
|
+
actions.push(actionInput);
|
|
2435
|
+
}
|
|
2436
|
+
});
|
|
2437
|
+
return pointerAction(this[Config], actions).then(() => void 0);
|
|
2438
|
+
}
|
|
2439
|
+
function createPointerState(document2) {
|
|
2440
|
+
return {
|
|
2441
|
+
pointerId: 1,
|
|
2442
|
+
position: {
|
|
2443
|
+
mouse: {
|
|
2444
|
+
pointerType: "mouse",
|
|
2445
|
+
pointerId: 1,
|
|
2446
|
+
target: document2.body,
|
|
2447
|
+
coords: {
|
|
2448
|
+
clientX: 0,
|
|
2449
|
+
clientY: 0,
|
|
2450
|
+
offsetX: 0,
|
|
2451
|
+
offsetY: 0,
|
|
2452
|
+
pageX: 0,
|
|
2453
|
+
pageY: 0,
|
|
2454
|
+
x: 0,
|
|
2455
|
+
y: 0
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
},
|
|
2459
|
+
pressed: []
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
// src/setup/config.ts
|
|
2464
|
+
var Config = Symbol("Config");
|
|
2465
|
+
|
|
2466
|
+
// src/setup/api.ts
|
|
2467
|
+
var api_exports = {};
|
|
2468
|
+
__export(api_exports, {
|
|
2469
|
+
clear: () => clear,
|
|
2470
|
+
click: () => click,
|
|
2471
|
+
copy: () => copy,
|
|
2472
|
+
cut: () => cut,
|
|
2473
|
+
dblClick: () => dblClick,
|
|
2474
|
+
deselectOptions: () => deselectOptions,
|
|
2475
|
+
hover: () => hover,
|
|
2476
|
+
keyboard: () => keyboard,
|
|
2477
|
+
paste: () => paste,
|
|
2478
|
+
pointer: () => pointer,
|
|
2479
|
+
selectOptions: () => selectOptions,
|
|
2480
|
+
tab: () => tab,
|
|
2481
|
+
tripleClick: () => tripleClick,
|
|
2482
|
+
type: () => type,
|
|
2483
|
+
unhover: () => unhover,
|
|
2484
|
+
upload: () => upload
|
|
2485
|
+
});
|
|
2486
|
+
|
|
2487
|
+
// src/convenience/click.ts
|
|
2488
|
+
async function click(element) {
|
|
2489
|
+
const pointerIn = [];
|
|
2490
|
+
if (!this[Config].skipHover) {
|
|
2491
|
+
pointerIn.push({ target: element });
|
|
2492
|
+
}
|
|
2493
|
+
pointerIn.push({ keys: "[MouseLeft]", target: element });
|
|
2494
|
+
return this.pointer(pointerIn);
|
|
2495
|
+
}
|
|
2496
|
+
async function dblClick(element) {
|
|
2497
|
+
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
|
|
2498
|
+
}
|
|
2499
|
+
async function tripleClick(element) {
|
|
2500
|
+
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
// src/convenience/hover.ts
|
|
2504
|
+
async function hover(element) {
|
|
2505
|
+
return this.pointer({ target: element });
|
|
2506
|
+
}
|
|
2507
|
+
async function unhover(element) {
|
|
2508
|
+
return this.pointer({ target: element.ownerDocument.body });
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
// src/convenience/tab.ts
|
|
2512
|
+
async function tab({
|
|
2513
|
+
shift
|
|
2514
|
+
} = {}) {
|
|
2515
|
+
return this.keyboard(shift === true ? "{Shift>}{Tab}{/Shift}" : shift === false ? "[/ShiftLeft][/ShiftRight]{Tab}" : "{Tab}");
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
// src/clipboard/copy.ts
|
|
2519
|
+
async function copy() {
|
|
2520
|
+
var _a;
|
|
2521
|
+
const doc = this[Config].document;
|
|
2522
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2523
|
+
const clipboardData = copySelection(target);
|
|
2524
|
+
if (clipboardData.items.length === 0) {
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2527
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2528
|
+
clipboardData
|
|
2529
|
+
}) && this[Config].writeToClipboard) {
|
|
2530
|
+
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2531
|
+
}
|
|
2532
|
+
return clipboardData;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
// src/clipboard/cut.ts
|
|
2536
|
+
async function cut() {
|
|
2537
|
+
var _a;
|
|
2538
|
+
const doc = this[Config].document;
|
|
2539
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2540
|
+
const clipboardData = copySelection(target);
|
|
2541
|
+
if (clipboardData.items.length === 0) {
|
|
2542
|
+
return;
|
|
2543
|
+
}
|
|
2544
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2545
|
+
clipboardData
|
|
2546
|
+
}) && this[Config].writeToClipboard) {
|
|
2547
|
+
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2548
|
+
}
|
|
2549
|
+
return clipboardData;
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
// src/clipboard/paste.ts
|
|
2553
|
+
async function paste(clipboardData) {
|
|
2554
|
+
var _a, _b;
|
|
2555
|
+
const doc = this[Config].document;
|
|
2556
|
+
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2557
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2558
|
+
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2559
|
+
});
|
|
2560
|
+
this.dispatchUIEvent(target, "paste", {
|
|
2561
|
+
clipboardData: dataTransfer
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
function getClipboardDataFromString(text) {
|
|
2565
|
+
const dt = createDataTransfer();
|
|
2566
|
+
dt.setData("text", text);
|
|
2567
|
+
return dt;
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// src/utility/clear.ts
|
|
2571
|
+
async function clear(element) {
|
|
2572
|
+
if (!isEditable(element) || isDisabled(element)) {
|
|
2573
|
+
throw new Error("clear()` is only supported on editable elements.");
|
|
2574
|
+
}
|
|
2575
|
+
focus(element);
|
|
2576
|
+
if (element.ownerDocument.activeElement !== element) {
|
|
2577
|
+
throw new Error("The element to be cleared could not be focused.");
|
|
2578
|
+
}
|
|
2579
|
+
selectAll(element);
|
|
2580
|
+
if (!isAllSelected(element)) {
|
|
2581
|
+
throw new Error("The element content to be cleared could not be selected.");
|
|
2582
|
+
}
|
|
2583
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
// src/utility/selectOptions.ts
|
|
2587
|
+
var import_dom4 = require("@testing-library/dom");
|
|
2588
|
+
async function selectOptions(select, values) {
|
|
2589
|
+
return selectOptionsBase.call(this, true, select, values);
|
|
2590
|
+
}
|
|
2591
|
+
async function deselectOptions(select, values) {
|
|
2592
|
+
return selectOptionsBase.call(this, false, select, values);
|
|
2593
|
+
}
|
|
2594
|
+
async function selectOptionsBase(newValue, select, values) {
|
|
2595
|
+
if (!newValue && !select.multiple) {
|
|
2596
|
+
throw (0, import_dom4.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
2597
|
+
}
|
|
2598
|
+
const valArray = Array.isArray(values) ? values : [values];
|
|
2599
|
+
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
|
|
2600
|
+
const selectedOptions = valArray.map((val) => {
|
|
2601
|
+
if (typeof val !== "string" && allOptions.includes(val)) {
|
|
2602
|
+
return val;
|
|
2603
|
+
} else {
|
|
2604
|
+
const matchingOption = allOptions.find((o) => o.value === val || o.innerHTML === val);
|
|
2605
|
+
if (matchingOption) {
|
|
2606
|
+
return matchingOption;
|
|
2607
|
+
} else {
|
|
2608
|
+
throw (0, import_dom4.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
}).filter((option) => !isDisabled(option));
|
|
2612
|
+
if (isDisabled(select) || !selectedOptions.length)
|
|
2613
|
+
return;
|
|
2614
|
+
const selectOption = (option) => {
|
|
2615
|
+
option.selected = newValue;
|
|
2616
|
+
this.dispatchUIEvent(select, "input", {
|
|
2617
|
+
bubbles: true,
|
|
2618
|
+
cancelable: false,
|
|
2619
|
+
composed: true
|
|
2620
|
+
});
|
|
2621
|
+
this.dispatchUIEvent(select, "change");
|
|
2622
|
+
};
|
|
2623
|
+
if (isElementType(select, "select")) {
|
|
2624
|
+
if (select.multiple) {
|
|
2625
|
+
for (const option of selectedOptions) {
|
|
2626
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2627
|
+
if (withPointerEvents) {
|
|
2628
|
+
this.dispatchUIEvent(option, "pointerover");
|
|
2629
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2630
|
+
this.dispatchUIEvent(option, "mouseover");
|
|
2631
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2632
|
+
this.dispatchUIEvent(option, "pointermove");
|
|
2633
|
+
this.dispatchUIEvent(option, "mousemove");
|
|
2634
|
+
this.dispatchUIEvent(option, "pointerdown");
|
|
2635
|
+
this.dispatchUIEvent(option, "mousedown");
|
|
2636
|
+
}
|
|
2637
|
+
focus(select);
|
|
2638
|
+
if (withPointerEvents) {
|
|
2639
|
+
this.dispatchUIEvent(option, "pointerup");
|
|
2640
|
+
this.dispatchUIEvent(option, "mouseup");
|
|
2641
|
+
}
|
|
2642
|
+
selectOption(option);
|
|
2643
|
+
if (withPointerEvents) {
|
|
2644
|
+
this.dispatchUIEvent(option, "click");
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
} else if (selectedOptions.length === 1) {
|
|
2648
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2649
|
+
if (withPointerEvents) {
|
|
2650
|
+
await this.click(select);
|
|
2651
|
+
} else {
|
|
2652
|
+
focus(select);
|
|
2653
|
+
}
|
|
2654
|
+
selectOption(selectedOptions[0]);
|
|
2655
|
+
if (withPointerEvents) {
|
|
2656
|
+
this.dispatchUIEvent(select, "pointerover");
|
|
2657
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2658
|
+
this.dispatchUIEvent(select, "mouseover");
|
|
2659
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2660
|
+
this.dispatchUIEvent(select, "pointerup");
|
|
2661
|
+
this.dispatchUIEvent(select, "mouseup");
|
|
2662
|
+
this.dispatchUIEvent(select, "click");
|
|
2663
|
+
}
|
|
2664
|
+
} else {
|
|
2665
|
+
throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2666
|
+
}
|
|
2667
|
+
} else if (select.getAttribute("role") === "listbox") {
|
|
2668
|
+
for (const option of selectedOptions) {
|
|
2669
|
+
await this.click(option);
|
|
2670
|
+
await this.unhover(option);
|
|
2671
|
+
}
|
|
2672
|
+
} else {
|
|
2673
|
+
throw (0, import_dom4.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
// src/utility/type.ts
|
|
2678
|
+
async function type(element, text, {
|
|
2679
|
+
skipClick = this[Config].skipClick,
|
|
2680
|
+
skipAutoClose = this[Config].skipAutoClose,
|
|
2681
|
+
initialSelectionStart,
|
|
2682
|
+
initialSelectionEnd
|
|
2683
|
+
} = {}) {
|
|
2684
|
+
if (element.disabled)
|
|
2685
|
+
return;
|
|
2686
|
+
if (!skipClick) {
|
|
2687
|
+
await this.click(element);
|
|
2688
|
+
}
|
|
2689
|
+
if (initialSelectionStart !== void 0) {
|
|
2690
|
+
setSelectionRange(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
|
|
2691
|
+
}
|
|
2692
|
+
await this.keyboard(text);
|
|
2693
|
+
if (!skipAutoClose) {
|
|
2694
|
+
await releaseAllKeys(this[Config]);
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
// src/utility/upload.ts
|
|
2699
|
+
async function upload(element, fileOrFiles) {
|
|
2700
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2701
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2702
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2703
|
+
}
|
|
2704
|
+
if (isDisabled(element))
|
|
2705
|
+
return;
|
|
2706
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2707
|
+
const fileDialog = () => {
|
|
2708
|
+
var _a;
|
|
2709
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2710
|
+
var _a2;
|
|
2711
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2712
|
+
})) {
|
|
2713
|
+
return;
|
|
2714
|
+
}
|
|
2715
|
+
setFiles(input2, createFileList(files));
|
|
2716
|
+
this.dispatchUIEvent(input2, "input");
|
|
2717
|
+
this.dispatchUIEvent(input2, "change");
|
|
2718
|
+
};
|
|
2719
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2720
|
+
await this.click(element);
|
|
2721
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2722
|
+
}
|
|
2723
|
+
function isAcceptableFile(file, accept) {
|
|
2724
|
+
if (!accept) {
|
|
2725
|
+
return true;
|
|
2726
|
+
}
|
|
2727
|
+
const wildcards = ["audio/*", "image/*", "video/*"];
|
|
2728
|
+
return accept.split(",").some((acceptToken) => {
|
|
2729
|
+
if (acceptToken.startsWith(".")) {
|
|
2730
|
+
return file.name.endsWith(acceptToken);
|
|
2731
|
+
} else if (wildcards.includes(acceptToken)) {
|
|
2732
|
+
return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1));
|
|
2733
|
+
}
|
|
2734
|
+
return file.type === acceptToken;
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
// src/setup/wrapAsync.ts
|
|
2739
|
+
var import_dom5 = require("@testing-library/dom");
|
|
2740
|
+
function wrapAsync(implementation) {
|
|
2741
|
+
return (0, import_dom5.getConfig)().asyncWrapper(implementation);
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
// src/setup/setup.ts
|
|
2745
|
+
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2746
|
+
const document2 = getDocument(options, node);
|
|
2747
|
+
const {
|
|
2748
|
+
keyboardState = createKeyboardState(),
|
|
2749
|
+
pointerState = createPointerState(document2)
|
|
2750
|
+
} = options;
|
|
2751
|
+
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2752
|
+
document: document2,
|
|
2753
|
+
keyboardState,
|
|
2754
|
+
pointerState
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
function setupMain(options = {}) {
|
|
2758
|
+
var _a;
|
|
2759
|
+
const config = createConfig(options);
|
|
2760
|
+
prepareDocument(config.document);
|
|
2761
|
+
const view = (_a = config.document.defaultView) != null ? _a : window;
|
|
2762
|
+
attachClipboardStubToView(view);
|
|
2763
|
+
return doSetup(config);
|
|
2764
|
+
}
|
|
2765
|
+
function setupDirect(options = {}, node) {
|
|
2766
|
+
const config = createConfig(options, defaultOptionsDirect, node);
|
|
2767
|
+
prepareDocument(config.document);
|
|
2768
|
+
return {
|
|
2769
|
+
config,
|
|
2770
|
+
api: doSetup(config)
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
function setupSub(options) {
|
|
2774
|
+
return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
|
|
2775
|
+
}
|
|
2776
|
+
function wrapAndBindImpl(instance, impl) {
|
|
2777
|
+
function method(...args) {
|
|
2778
|
+
setLevelRef(instance[Config], 1 /* Call */);
|
|
2779
|
+
return wrapAsync(() => impl.apply(instance, args));
|
|
2780
|
+
}
|
|
2781
|
+
Object.defineProperty(method, "name", { get: () => impl.name });
|
|
2782
|
+
return method;
|
|
2783
|
+
}
|
|
2784
|
+
function doSetup(config) {
|
|
2785
|
+
const instance = __spreadValues({
|
|
2786
|
+
[Config]: config,
|
|
2787
|
+
dispatchUIEvent: bindDispatchUIEvent(config)
|
|
2788
|
+
}, api_exports);
|
|
2789
|
+
return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
|
|
2790
|
+
name,
|
|
2791
|
+
wrapAndBindImpl(instance, api)
|
|
2792
|
+
]))), {
|
|
2793
|
+
setup: setupSub.bind(instance)
|
|
2794
|
+
});
|
|
2795
|
+
}
|
|
2796
|
+
function getDocument(options, node) {
|
|
2797
|
+
var _a, _b;
|
|
2798
|
+
return (_b = (_a = options.document) != null ? _a : node && getDocumentFromNode(node)) != null ? _b : document;
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
// src/setup/directApi.ts
|
|
2802
|
+
var directApi_exports = {};
|
|
2803
|
+
__export(directApi_exports, {
|
|
2804
|
+
clear: () => clear2,
|
|
2805
|
+
click: () => click2,
|
|
2806
|
+
copy: () => copy2,
|
|
2807
|
+
cut: () => cut2,
|
|
2808
|
+
dblClick: () => dblClick2,
|
|
2809
|
+
deselectOptions: () => deselectOptions2,
|
|
2810
|
+
hover: () => hover2,
|
|
2811
|
+
keyboard: () => keyboard2,
|
|
2812
|
+
paste: () => paste2,
|
|
2813
|
+
pointer: () => pointer2,
|
|
2814
|
+
selectOptions: () => selectOptions2,
|
|
2815
|
+
tab: () => tab2,
|
|
2816
|
+
tripleClick: () => tripleClick2,
|
|
2817
|
+
type: () => type2,
|
|
2818
|
+
unhover: () => unhover2,
|
|
2819
|
+
upload: () => upload2
|
|
2820
|
+
});
|
|
2821
|
+
function clear2(element) {
|
|
2822
|
+
return setupDirect().api.clear(element);
|
|
2823
|
+
}
|
|
2824
|
+
function click2(element, options = {}) {
|
|
2825
|
+
return setupDirect(options, element).api.click(element);
|
|
2826
|
+
}
|
|
2827
|
+
function copy2(options = {}) {
|
|
2828
|
+
return setupDirect(options).api.copy();
|
|
2829
|
+
}
|
|
2830
|
+
function cut2(options = {}) {
|
|
2831
|
+
return setupDirect(options).api.cut();
|
|
2832
|
+
}
|
|
2833
|
+
function dblClick2(element, options = {}) {
|
|
2834
|
+
return setupDirect(options).api.dblClick(element);
|
|
2835
|
+
}
|
|
2836
|
+
function deselectOptions2(select, values, options = {}) {
|
|
2837
|
+
return setupDirect(options).api.deselectOptions(select, values);
|
|
2838
|
+
}
|
|
2839
|
+
function hover2(element, options = {}) {
|
|
2840
|
+
return setupDirect(options).api.hover(element);
|
|
2841
|
+
}
|
|
2842
|
+
async function keyboard2(text, options = {}) {
|
|
2843
|
+
const { config, api } = setupDirect(options);
|
|
2844
|
+
return api.keyboard(text).then(() => config.keyboardState);
|
|
2845
|
+
}
|
|
2846
|
+
async function pointer2(input2, options = {}) {
|
|
2847
|
+
const { config, api } = setupDirect(options);
|
|
2848
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2849
|
+
}
|
|
2850
|
+
function paste2(clipboardData, options) {
|
|
2851
|
+
return setupDirect(options).api.paste(clipboardData);
|
|
2852
|
+
}
|
|
2853
|
+
function selectOptions2(select, values, options = {}) {
|
|
2854
|
+
return setupDirect(options).api.selectOptions(select, values);
|
|
2855
|
+
}
|
|
2856
|
+
function tripleClick2(element, options = {}) {
|
|
2857
|
+
return setupDirect(options).api.tripleClick(element);
|
|
2858
|
+
}
|
|
2859
|
+
function type2(element, text, options = {}) {
|
|
2860
|
+
return setupDirect(options, element).api.type(element, text, options);
|
|
2861
|
+
}
|
|
2862
|
+
function unhover2(element, options = {}) {
|
|
2863
|
+
const { config, api } = setupDirect(options);
|
|
2864
|
+
config.pointerState.position.mouse.target = element;
|
|
2865
|
+
return api.unhover(element);
|
|
2866
|
+
}
|
|
2867
|
+
function upload2(element, fileOrFiles, options = {}) {
|
|
2868
|
+
return setupDirect(options).api.upload(element, fileOrFiles);
|
|
2869
|
+
}
|
|
2870
|
+
function tab2(options = {}) {
|
|
2871
|
+
return setupDirect().api.tab(options);
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
// src/setup/index.ts
|
|
2875
|
+
var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
|
|
2876
|
+
setup: setupMain
|
|
2877
|
+
});
|
|
2878
|
+
module.exports = __toCommonJS(src_exports);
|