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