@testing-library/user-event 14.0.0-beta.9 → 14.0.2
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 +2 -2
- package/dist/index.cjs +762 -832
- package/dist/index.mjs +756 -821
- package/dist/types/document/selection.d.ts +0 -1
- package/dist/types/document/value.d.ts +9 -2
- package/dist/types/event/behavior/cut.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +5 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/paste.d.ts +1 -0
- package/dist/types/event/dispatchEvent.d.ts +1 -1
- package/dist/types/event/eventMap.d.ts +361 -0
- package/dist/types/event/index.d.ts +2 -2
- package/dist/types/keyboard/modifiers.d.ts +9 -0
- package/dist/types/keyboard/types.d.ts +0 -5
- package/dist/types/utils/dataTransfer/Blob.d.ts +3 -1
- package/dist/types/utils/dataTransfer/Clipboard.d.ts +1 -1
- package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -2
- package/dist/types/utils/edit/input.d.ts +2 -0
- package/dist/types/utils/edit/isValidDateOrTimeValue.d.ts +3 -0
- package/dist/types/utils/focus/selection.d.ts +4 -0
- package/dist/types/utils/index.d.ts +2 -8
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +3 -1
- package/dist/types/utils/misc/getWindow.d.ts +1 -0
- package/package.json +15 -15
- package/dist/types/keyboard/plugins/arrow.d.ts +0 -6
- package/dist/types/keyboard/plugins/character.d.ts +0 -5
- package/dist/types/keyboard/plugins/combination.d.ts +0 -5
- package/dist/types/keyboard/plugins/control.d.ts +0 -6
- package/dist/types/keyboard/plugins/functional.d.ts +0 -8
- package/dist/types/keyboard/plugins/index.d.ts +0 -7
- package/dist/types/keyboard/plugins/modifiers.d.ts +0 -8
- package/dist/types/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -4
- package/dist/types/keyboard/shared/index.d.ts +0 -1
- package/dist/types/utils/edit/calculateNewValue.d.ts +0 -14
- package/dist/types/utils/edit/editInputElement.d.ts +0 -14
- package/dist/types/utils/edit/isValidDateValue.d.ts +0 -3
- package/dist/types/utils/edit/isValidInputTimeValue.d.ts +0 -3
- package/dist/types/utils/edit/prepareInput.d.ts +0 -8
- package/dist/types/utils/misc/hasFormSubmit.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -19,24 +19,19 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
return a;
|
|
20
20
|
};
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
23
22
|
var __export = (target, all) => {
|
|
24
23
|
for (var name in all)
|
|
25
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
25
|
};
|
|
27
|
-
var
|
|
28
|
-
if (
|
|
29
|
-
for (let key of __getOwnPropNames(
|
|
30
|
-
if (!__hasOwnProp.call(
|
|
31
|
-
__defProp(
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
31
|
}
|
|
33
|
-
return
|
|
32
|
+
return to;
|
|
34
33
|
};
|
|
35
|
-
var __toCommonJS =
|
|
36
|
-
return (module2, temp) => {
|
|
37
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
38
|
-
};
|
|
39
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
35
|
|
|
41
36
|
// src/index.ts
|
|
42
37
|
var src_exports = {};
|
|
@@ -44,6 +39,7 @@ __export(src_exports, {
|
|
|
44
39
|
PointerEventsCheckLevel: () => PointerEventsCheckLevel,
|
|
45
40
|
default: () => userEvent
|
|
46
41
|
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
47
43
|
|
|
48
44
|
// src/utils/misc/isElementType.ts
|
|
49
45
|
function isElementType(element, tag, props) {
|
|
@@ -76,7 +72,7 @@ function isClickableInput(element) {
|
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
// src/utils/dataTransfer/Blob.ts
|
|
79
|
-
function readBlobText(blob) {
|
|
75
|
+
function readBlobText(blob, FileReader) {
|
|
80
76
|
return new Promise((res, rej) => {
|
|
81
77
|
const fr = new FileReader();
|
|
82
78
|
fr.onerror = rej;
|
|
@@ -160,8 +156,8 @@ var DataTransferStub = class {
|
|
|
160
156
|
this.files = createFileList([]);
|
|
161
157
|
}
|
|
162
158
|
getData(format) {
|
|
163
|
-
var
|
|
164
|
-
const match = (
|
|
159
|
+
var _a3;
|
|
160
|
+
const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : this.items.find(getTypeMatcher(format, false));
|
|
165
161
|
let text = "";
|
|
166
162
|
match == null ? void 0 : match.getAsString((t) => {
|
|
167
163
|
text = t;
|
|
@@ -199,12 +195,12 @@ var DataTransferStub = class {
|
|
|
199
195
|
setDragImage() {
|
|
200
196
|
}
|
|
201
197
|
};
|
|
202
|
-
function createDataTransfer(files = []) {
|
|
203
|
-
const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
|
|
198
|
+
function createDataTransfer(window2, files = []) {
|
|
199
|
+
const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
|
|
204
200
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
205
201
|
return dt;
|
|
206
202
|
}
|
|
207
|
-
function getBlobFromDataTransferItem(item) {
|
|
203
|
+
function getBlobFromDataTransferItem(window2, item) {
|
|
208
204
|
if (item.kind === "file") {
|
|
209
205
|
return item.getAsFile();
|
|
210
206
|
}
|
|
@@ -212,12 +208,21 @@ function getBlobFromDataTransferItem(item) {
|
|
|
212
208
|
item.getAsString((s) => {
|
|
213
209
|
data = s;
|
|
214
210
|
});
|
|
215
|
-
return new Blob([data], { type: item.type });
|
|
211
|
+
return new window2.Blob([data], { type: item.type });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/utils/misc/getWindow.ts
|
|
215
|
+
var import_helpers = require("@testing-library/dom/dist/helpers.js");
|
|
216
|
+
function getWindow(node) {
|
|
217
|
+
return (0, import_helpers.getWindowFromNode)(node);
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
// src/utils/dataTransfer/Clipboard.ts
|
|
221
|
+
var Window = Symbol("Window reference");
|
|
222
|
+
var _a;
|
|
219
223
|
var ClipboardItemStub = class {
|
|
220
224
|
constructor(data) {
|
|
225
|
+
this[_a] = window;
|
|
221
226
|
this.data = data;
|
|
222
227
|
}
|
|
223
228
|
get types() {
|
|
@@ -228,14 +233,17 @@ var ClipboardItemStub = class {
|
|
|
228
233
|
if (!data) {
|
|
229
234
|
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
230
235
|
}
|
|
231
|
-
return data instanceof Blob ? data : new Blob([data], { type: type3 });
|
|
236
|
+
return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
|
|
232
237
|
}
|
|
233
238
|
};
|
|
239
|
+
_a = Window;
|
|
234
240
|
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
235
|
-
var
|
|
241
|
+
var _a2;
|
|
242
|
+
var ClipboardStub = class extends window.EventTarget {
|
|
236
243
|
constructor() {
|
|
237
244
|
super(...arguments);
|
|
238
245
|
this.items = [];
|
|
246
|
+
this[_a2] = window;
|
|
239
247
|
}
|
|
240
248
|
async read() {
|
|
241
249
|
return Array.from(this.items);
|
|
@@ -245,7 +253,7 @@ var ClipboardStub = class extends EventTarget {
|
|
|
245
253
|
for (const item of this.items) {
|
|
246
254
|
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
247
255
|
if (type3) {
|
|
248
|
-
text += await item.getType(type3).then((b) => readBlobText(b));
|
|
256
|
+
text += await item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
|
|
249
257
|
}
|
|
250
258
|
}
|
|
251
259
|
return text;
|
|
@@ -254,16 +262,22 @@ var ClipboardStub = class extends EventTarget {
|
|
|
254
262
|
this.items = data;
|
|
255
263
|
}
|
|
256
264
|
async writeText(text) {
|
|
257
|
-
this.items = [createClipboardItem(text)];
|
|
265
|
+
this.items = [createClipboardItem(this[Window], text)];
|
|
258
266
|
}
|
|
259
267
|
};
|
|
260
|
-
ClipboardStubControl;
|
|
261
|
-
function createClipboardItem(...blobs) {
|
|
262
|
-
const
|
|
263
|
-
return new constructor(Object.fromEntries(blobs.map((b) => [
|
|
268
|
+
_a2 = Window, ClipboardStubControl;
|
|
269
|
+
function createClipboardItem(window2, ...blobs) {
|
|
270
|
+
const data = Object.fromEntries(blobs.map((b) => [
|
|
264
271
|
typeof b === "string" ? "text/plain" : b.type,
|
|
265
272
|
Promise.resolve(b)
|
|
266
|
-
]))
|
|
273
|
+
]));
|
|
274
|
+
if (typeof window2.ClipboardItem === "undefined") {
|
|
275
|
+
const item = new ClipboardItemStub(data);
|
|
276
|
+
item[Window] = window2;
|
|
277
|
+
return item;
|
|
278
|
+
} else {
|
|
279
|
+
return new window2.ClipboardItem(data);
|
|
280
|
+
}
|
|
267
281
|
}
|
|
268
282
|
function attachClipboardStubToView(window2) {
|
|
269
283
|
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
@@ -271,9 +285,11 @@ function attachClipboardStubToView(window2) {
|
|
|
271
285
|
}
|
|
272
286
|
const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
|
|
273
287
|
let stub = new ClipboardStub();
|
|
288
|
+
stub[Window] = window2;
|
|
274
289
|
const control = {
|
|
275
290
|
resetClipboardStub: () => {
|
|
276
291
|
stub = new ClipboardStub();
|
|
292
|
+
stub[Window] = window2;
|
|
277
293
|
stub[ClipboardStubControl] = control;
|
|
278
294
|
},
|
|
279
295
|
detachClipboardStub: () => {
|
|
@@ -305,28 +321,28 @@ function detachClipboardStubFromView(window2) {
|
|
|
305
321
|
}
|
|
306
322
|
}
|
|
307
323
|
async function readDataTransferFromClipboard(document2) {
|
|
308
|
-
|
|
309
|
-
const clipboard =
|
|
324
|
+
const window2 = document2.defaultView;
|
|
325
|
+
const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
|
|
310
326
|
const items = clipboard && await clipboard.read();
|
|
311
327
|
if (!items) {
|
|
312
328
|
throw new Error("The Clipboard API is unavailable.");
|
|
313
329
|
}
|
|
314
|
-
const dt = createDataTransfer();
|
|
330
|
+
const dt = createDataTransfer(window2);
|
|
315
331
|
for (const item of items) {
|
|
316
332
|
for (const type3 of item.types) {
|
|
317
|
-
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b)));
|
|
333
|
+
dt.setData(type3, await item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
|
|
318
334
|
}
|
|
319
335
|
}
|
|
320
336
|
return dt;
|
|
321
337
|
}
|
|
322
338
|
async function writeDataTransferToClipboard(document2, clipboardData) {
|
|
323
|
-
|
|
324
|
-
const clipboard =
|
|
339
|
+
const window2 = getWindow(document2);
|
|
340
|
+
const clipboard = window2.navigator.clipboard;
|
|
325
341
|
const items = [];
|
|
326
342
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
327
343
|
const dtItem = clipboardData.items[i];
|
|
328
|
-
const blob = getBlobFromDataTransferItem(dtItem);
|
|
329
|
-
items.push(createClipboardItem(blob));
|
|
344
|
+
const blob = getBlobFromDataTransferItem(window2, dtItem);
|
|
345
|
+
items.push(createClipboardItem(window2, blob));
|
|
330
346
|
}
|
|
331
347
|
const written = clipboard && await clipboard.write(items).then(() => true, () => false);
|
|
332
348
|
if (!written) {
|
|
@@ -340,6 +356,29 @@ if (typeof afterAll === "function") {
|
|
|
340
356
|
afterAll(() => detachClipboardStubFromView(window));
|
|
341
357
|
}
|
|
342
358
|
|
|
359
|
+
// src/utils/edit/isContentEditable.ts
|
|
360
|
+
function isContentEditable(element) {
|
|
361
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
362
|
+
}
|
|
363
|
+
function getContentEditable(node) {
|
|
364
|
+
const element = getElement(node);
|
|
365
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
366
|
+
}
|
|
367
|
+
function getElement(node) {
|
|
368
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/utils/edit/getValue.ts
|
|
372
|
+
function getValue(element) {
|
|
373
|
+
if (!element) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
if (isContentEditable(element)) {
|
|
377
|
+
return element.textContent;
|
|
378
|
+
}
|
|
379
|
+
return getUIValue(element);
|
|
380
|
+
}
|
|
381
|
+
|
|
343
382
|
// src/utils/edit/buildTimeValue.ts
|
|
344
383
|
function buildTimeValue(value) {
|
|
345
384
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -371,21 +410,137 @@ function build(onlyDigitsValue, index) {
|
|
|
371
410
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
372
411
|
}
|
|
373
412
|
|
|
374
|
-
// src/utils/edit/
|
|
375
|
-
function
|
|
413
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
414
|
+
function isValidDateOrTimeValue(element, value) {
|
|
376
415
|
const clone = element.cloneNode();
|
|
377
416
|
clone.value = value;
|
|
378
417
|
return clone.value === value;
|
|
379
418
|
}
|
|
380
419
|
|
|
381
|
-
// src/utils/edit/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
420
|
+
// src/utils/edit/maxLength.ts
|
|
421
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
422
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
423
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
424
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
425
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
426
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
427
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
428
|
+
return maxLengthSupportedTypes2;
|
|
429
|
+
})(maxLengthSupportedTypes || {});
|
|
430
|
+
function getSpaceUntilMaxLength(element) {
|
|
431
|
+
const value = getValue(element);
|
|
432
|
+
if (value === null) {
|
|
433
|
+
return void 0;
|
|
434
|
+
}
|
|
435
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
436
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
437
|
+
}
|
|
438
|
+
function getSanitizedMaxLength(element) {
|
|
439
|
+
var _a3;
|
|
440
|
+
if (!supportsMaxLength(element)) {
|
|
441
|
+
return void 0;
|
|
442
|
+
}
|
|
443
|
+
const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
|
|
444
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
445
|
+
}
|
|
446
|
+
function supportsMaxLength(element) {
|
|
447
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
386
448
|
}
|
|
387
449
|
|
|
388
|
-
// src/utils/edit/
|
|
450
|
+
// src/utils/edit/input.ts
|
|
451
|
+
function isDateOrTime(element) {
|
|
452
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
453
|
+
}
|
|
454
|
+
function input(config, element, data, inputType = "insertText") {
|
|
455
|
+
const inputRange = getInputRange(element);
|
|
456
|
+
if (!inputRange) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (!isDateOrTime(element)) {
|
|
460
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
461
|
+
inputType,
|
|
462
|
+
data
|
|
463
|
+
});
|
|
464
|
+
if (!unprevented) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if ("startContainer" in inputRange) {
|
|
469
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
470
|
+
} else {
|
|
471
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
475
|
+
let del = false;
|
|
476
|
+
if (!inputRange.collapsed) {
|
|
477
|
+
del = true;
|
|
478
|
+
inputRange.deleteContents();
|
|
479
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
480
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
481
|
+
if (nextPosition) {
|
|
482
|
+
del = true;
|
|
483
|
+
const delRange = inputRange.cloneRange();
|
|
484
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
485
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
486
|
+
} else {
|
|
487
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
488
|
+
}
|
|
489
|
+
delRange.deleteContents();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (data) {
|
|
493
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
494
|
+
const offset = inputRange.endOffset;
|
|
495
|
+
inputRange.endContainer.insertData(offset, data);
|
|
496
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
497
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
498
|
+
} else {
|
|
499
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
500
|
+
inputRange.insertNode(text);
|
|
501
|
+
inputRange.setStart(text, data.length);
|
|
502
|
+
inputRange.setEnd(text, data.length);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (del || data) {
|
|
506
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
510
|
+
let dataToInsert = data;
|
|
511
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
512
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
513
|
+
if (spaceUntilMaxLength > 0) {
|
|
514
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
515
|
+
} else {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
520
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
setUIValue(element, newValue);
|
|
527
|
+
setSelection({
|
|
528
|
+
focusNode: element,
|
|
529
|
+
anchorOffset: newOffset,
|
|
530
|
+
focusOffset: newOffset
|
|
531
|
+
});
|
|
532
|
+
if (isDateOrTime(element)) {
|
|
533
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
534
|
+
commitInput(config, element, newOffset, {});
|
|
535
|
+
dispatchUIEvent(config, element, "change");
|
|
536
|
+
}
|
|
537
|
+
} else {
|
|
538
|
+
commitInput(config, element, newOffset, {
|
|
539
|
+
data,
|
|
540
|
+
inputType
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
389
544
|
function calculateNewValue(inputData, node, {
|
|
390
545
|
startOffset,
|
|
391
546
|
endOffset
|
|
@@ -396,15 +551,12 @@ function calculateNewValue(inputData, node, {
|
|
|
396
551
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
397
552
|
const epilog = value.substring(epilogStart, value.length);
|
|
398
553
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
399
|
-
|
|
400
|
-
if (node
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
newValue = inputData;
|
|
406
|
-
} else {
|
|
407
|
-
newValue = value;
|
|
554
|
+
let newOffset = prologEnd + inputData.length;
|
|
555
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
556
|
+
const builtValue = buildTimeValue(newValue);
|
|
557
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
558
|
+
newValue = builtValue;
|
|
559
|
+
newOffset = builtValue.length;
|
|
408
560
|
}
|
|
409
561
|
}
|
|
410
562
|
return {
|
|
@@ -413,17 +565,21 @@ function calculateNewValue(inputData, node, {
|
|
|
413
565
|
newOffset
|
|
414
566
|
};
|
|
415
567
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
568
|
+
function commitInput(config, element, newOffset, inputInit) {
|
|
569
|
+
startTrackValue(element);
|
|
570
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
571
|
+
if (endTrackValue(element)) {
|
|
572
|
+
setSelection({
|
|
573
|
+
focusNode: element,
|
|
574
|
+
anchorOffset: newOffset,
|
|
575
|
+
focusOffset: newOffset
|
|
576
|
+
});
|
|
577
|
+
}
|
|
424
578
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
579
|
+
function isValidNumberInput(value) {
|
|
580
|
+
var _a3, _b;
|
|
581
|
+
const valueParts = value.split("e", 2);
|
|
582
|
+
return !(/[^\d.\-e]/.test(value) || Number((_a3 = value.match(/-/g)) == null ? void 0 : _a3.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
427
583
|
}
|
|
428
584
|
|
|
429
585
|
// src/utils/edit/isEditable.ts
|
|
@@ -449,157 +605,123 @@ function isEditableInput(element) {
|
|
|
449
605
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
450
606
|
}
|
|
451
607
|
|
|
452
|
-
// src/utils/
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
focusNode: element.firstChild,
|
|
465
|
-
anchorOffset,
|
|
466
|
-
focusOffset
|
|
608
|
+
// src/utils/edit/setFiles.ts
|
|
609
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
610
|
+
function setFiles(el, files) {
|
|
611
|
+
var _a3;
|
|
612
|
+
(_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
|
|
613
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
614
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
615
|
+
function restore() {
|
|
616
|
+
Object.defineProperties(el, {
|
|
617
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
618
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
619
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
467
620
|
});
|
|
468
621
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
486
|
-
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
487
|
-
return {
|
|
488
|
-
type: isCE ? "contenteditable" : "default",
|
|
489
|
-
selection
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
function getElement2(node) {
|
|
493
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
494
|
-
}
|
|
495
|
-
function updateSelectionOnFocus(element) {
|
|
496
|
-
var _a;
|
|
497
|
-
const selection = element.ownerDocument.getSelection();
|
|
498
|
-
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
if (hasOwnSelection(element)) {
|
|
502
|
-
const contenteditable = getContentEditable(selection.focusNode);
|
|
503
|
-
if (contenteditable) {
|
|
504
|
-
if (!selection.isCollapsed) {
|
|
505
|
-
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
506
|
-
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
622
|
+
el[fakeFiles] = { restore };
|
|
623
|
+
Object.defineProperties(el, {
|
|
624
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
625
|
+
get: () => files
|
|
626
|
+
}),
|
|
627
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
628
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
629
|
+
set(v) {
|
|
630
|
+
var _a4;
|
|
631
|
+
if (v === "") {
|
|
632
|
+
restore();
|
|
633
|
+
} else {
|
|
634
|
+
(_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
|
|
635
|
+
}
|
|
507
636
|
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
} else if (typeAndSelection.type === "contenteditable") {
|
|
519
|
-
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
function setSelection({
|
|
523
|
-
focusNode,
|
|
524
|
-
focusOffset,
|
|
525
|
-
anchorNode = focusNode,
|
|
526
|
-
anchorOffset = focusOffset
|
|
527
|
-
}) {
|
|
528
|
-
var _a, _b;
|
|
529
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
530
|
-
if (typeAndSelection.type === "input") {
|
|
531
|
-
return setUISelection(focusNode, {
|
|
532
|
-
anchorOffset,
|
|
533
|
-
focusOffset
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
637
|
+
}),
|
|
638
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
639
|
+
set(v) {
|
|
640
|
+
if (v !== "file") {
|
|
641
|
+
restore();
|
|
642
|
+
el.type = v;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
})
|
|
646
|
+
});
|
|
537
647
|
}
|
|
538
648
|
|
|
539
|
-
// src/utils/
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const oldValue = element.value;
|
|
546
|
-
setUIValue(element, newValue);
|
|
547
|
-
setSelection({
|
|
548
|
-
focusNode: newSelection.node,
|
|
549
|
-
anchorOffset: newSelection.offset,
|
|
550
|
-
focusOffset: newSelection.offset
|
|
649
|
+
// src/utils/misc/eventWrapper.ts
|
|
650
|
+
var import_dom = require("@testing-library/dom");
|
|
651
|
+
function eventWrapper(cb) {
|
|
652
|
+
let result;
|
|
653
|
+
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
654
|
+
result = cb();
|
|
551
655
|
});
|
|
552
|
-
|
|
553
|
-
dispatchUIEvent(config, element, "input", eventOverrides);
|
|
554
|
-
const tracked = endTrackValue(element);
|
|
555
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
556
|
-
setSelection({
|
|
557
|
-
focusNode: newSelection.node,
|
|
558
|
-
anchorOffset: newSelection.offset,
|
|
559
|
-
focusOffset: newSelection.offset
|
|
560
|
-
});
|
|
561
|
-
}
|
|
656
|
+
return result;
|
|
562
657
|
}
|
|
563
658
|
|
|
564
|
-
// src/utils/
|
|
565
|
-
function
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
659
|
+
// src/utils/misc/isDisabled.ts
|
|
660
|
+
function isDisabled(element) {
|
|
661
|
+
var _a3;
|
|
662
|
+
for (let el = element; el; el = el.parentElement) {
|
|
663
|
+
if (isElementType(el, [
|
|
664
|
+
"button",
|
|
665
|
+
"input",
|
|
666
|
+
"select",
|
|
667
|
+
"textarea",
|
|
668
|
+
"optgroup",
|
|
669
|
+
"option"
|
|
670
|
+
])) {
|
|
671
|
+
if (el.hasAttribute("disabled")) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
} else if (isElementType(el, "fieldset")) {
|
|
675
|
+
if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
|
|
676
|
+
return true;
|
|
677
|
+
}
|
|
678
|
+
} else if (el.tagName.includes("-")) {
|
|
679
|
+
if (el.constructor.formAssociated && el.hasAttribute("disabled")) {
|
|
680
|
+
return true;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
571
683
|
}
|
|
572
|
-
return
|
|
684
|
+
return false;
|
|
573
685
|
}
|
|
574
686
|
|
|
575
|
-
// src/utils/
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
function getSpaceUntilMaxLength(element) {
|
|
586
|
-
const value = getValue(element);
|
|
587
|
-
if (value === null) {
|
|
588
|
-
return void 0;
|
|
687
|
+
// src/utils/focus/getActiveElement.ts
|
|
688
|
+
function getActiveElement(document2) {
|
|
689
|
+
const activeElement = document2.activeElement;
|
|
690
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
691
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
692
|
+
} else {
|
|
693
|
+
if (isDisabled(activeElement)) {
|
|
694
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
695
|
+
}
|
|
696
|
+
return activeElement;
|
|
589
697
|
}
|
|
590
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
591
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
592
698
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
699
|
+
|
|
700
|
+
// src/utils/focus/selector.ts
|
|
701
|
+
var FOCUSABLE_SELECTOR = [
|
|
702
|
+
"input:not([type=hidden]):not([disabled])",
|
|
703
|
+
"button:not([disabled])",
|
|
704
|
+
"select:not([disabled])",
|
|
705
|
+
"textarea:not([disabled])",
|
|
706
|
+
'[contenteditable=""]',
|
|
707
|
+
'[contenteditable="true"]',
|
|
708
|
+
"a[href]",
|
|
709
|
+
"[tabindex]:not([disabled])"
|
|
710
|
+
].join(", ");
|
|
711
|
+
|
|
712
|
+
// src/utils/focus/isFocusable.ts
|
|
713
|
+
function isFocusable(element) {
|
|
714
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
600
715
|
}
|
|
601
|
-
|
|
602
|
-
|
|
716
|
+
|
|
717
|
+
// src/utils/focus/blur.ts
|
|
718
|
+
function blur(element) {
|
|
719
|
+
if (!isFocusable(element))
|
|
720
|
+
return;
|
|
721
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
722
|
+
if (!wasActive)
|
|
723
|
+
return;
|
|
724
|
+
eventWrapper(() => element.blur());
|
|
603
725
|
}
|
|
604
726
|
|
|
605
727
|
// src/utils/focus/cursor.ts
|
|
@@ -650,7 +772,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
650
772
|
}
|
|
651
773
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
652
774
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
653
|
-
if (offset !== void 0 &&
|
|
775
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
654
776
|
node = node.children[nextOffset];
|
|
655
777
|
}
|
|
656
778
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -659,7 +781,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
659
781
|
if (isTextNode(node)) {
|
|
660
782
|
return true;
|
|
661
783
|
}
|
|
662
|
-
if (
|
|
784
|
+
if (isElement(node)) {
|
|
663
785
|
if (isElementType(node, ["input", "textarea"])) {
|
|
664
786
|
return node.type !== "hidden";
|
|
665
787
|
} else if (isElementType(node, "br")) {
|
|
@@ -676,14 +798,14 @@ function getOffset(node) {
|
|
|
676
798
|
}
|
|
677
799
|
return i;
|
|
678
800
|
}
|
|
679
|
-
function
|
|
801
|
+
function isElement(node) {
|
|
680
802
|
return node.nodeType === 1;
|
|
681
803
|
}
|
|
682
804
|
function isTextNode(node) {
|
|
683
805
|
return node.nodeType === 3;
|
|
684
806
|
}
|
|
685
807
|
function walkNodes(node, direction, callback) {
|
|
686
|
-
var
|
|
808
|
+
var _a3;
|
|
687
809
|
for (; ; ) {
|
|
688
810
|
const sibling = node[`${direction}Sibling`];
|
|
689
811
|
if (sibling) {
|
|
@@ -691,7 +813,7 @@ function walkNodes(node, direction, callback) {
|
|
|
691
813
|
if (callback(node)) {
|
|
692
814
|
return node;
|
|
693
815
|
}
|
|
694
|
-
} else if (node.parentNode && (!
|
|
816
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
|
|
695
817
|
node = node.parentNode;
|
|
696
818
|
} else {
|
|
697
819
|
break;
|
|
@@ -705,173 +827,122 @@ function getDescendant(node, direction) {
|
|
|
705
827
|
return node;
|
|
706
828
|
}
|
|
707
829
|
|
|
708
|
-
// src/utils/
|
|
709
|
-
function
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
return
|
|
830
|
+
// src/utils/focus/selection.ts
|
|
831
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
832
|
+
var _a3;
|
|
833
|
+
if (hasOwnSelection(element)) {
|
|
834
|
+
return setSelection({
|
|
835
|
+
focusNode: element,
|
|
836
|
+
anchorOffset,
|
|
837
|
+
focusOffset
|
|
838
|
+
});
|
|
713
839
|
}
|
|
714
|
-
if (
|
|
715
|
-
return {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
if (data) {
|
|
735
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
736
|
-
const offset = inputRange.endOffset;
|
|
737
|
-
inputRange.endContainer.insertData(offset, data);
|
|
738
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
739
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
740
|
-
} else {
|
|
741
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
742
|
-
inputRange.insertNode(text);
|
|
743
|
-
inputRange.setStart(text, data.length);
|
|
744
|
-
inputRange.setEnd(text, data.length);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
if (del || data) {
|
|
748
|
-
dispatchUIEvent(config, element, "input", { inputType });
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
} else {
|
|
840
|
+
if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
|
|
841
|
+
return setSelection({
|
|
842
|
+
focusNode: element.firstChild,
|
|
843
|
+
anchorOffset,
|
|
844
|
+
focusOffset
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
848
|
+
}
|
|
849
|
+
function hasOwnSelection(node) {
|
|
850
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
851
|
+
}
|
|
852
|
+
function isElement2(node) {
|
|
853
|
+
return node.nodeType === 1;
|
|
854
|
+
}
|
|
855
|
+
function getTargetTypeAndSelection(node) {
|
|
856
|
+
const element = getElement2(node);
|
|
857
|
+
if (element && hasOwnSelection(element)) {
|
|
753
858
|
return {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
|
|
757
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
editInputElement(config, element, {
|
|
761
|
-
newValue,
|
|
762
|
-
newSelection: {
|
|
763
|
-
node: element,
|
|
764
|
-
offset: newOffset
|
|
765
|
-
},
|
|
766
|
-
eventOverrides: {
|
|
767
|
-
inputType
|
|
768
|
-
}
|
|
769
|
-
});
|
|
770
|
-
}
|
|
859
|
+
type: "input",
|
|
860
|
+
selection: getUISelection(element)
|
|
771
861
|
};
|
|
772
862
|
}
|
|
863
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
864
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
865
|
+
return {
|
|
866
|
+
type: isCE ? "contenteditable" : "default",
|
|
867
|
+
selection
|
|
868
|
+
};
|
|
773
869
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
function
|
|
778
|
-
var
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
function restore() {
|
|
783
|
-
Object.defineProperties(el, {
|
|
784
|
-
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
785
|
-
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
786
|
-
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
787
|
-
});
|
|
870
|
+
function getElement2(node) {
|
|
871
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
872
|
+
}
|
|
873
|
+
function updateSelectionOnFocus(element) {
|
|
874
|
+
var _a3;
|
|
875
|
+
const selection = element.ownerDocument.getSelection();
|
|
876
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
877
|
+
return;
|
|
788
878
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
796
|
-
set(v) {
|
|
797
|
-
var _a2;
|
|
798
|
-
if (v === "") {
|
|
799
|
-
restore();
|
|
800
|
-
} else {
|
|
801
|
-
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}),
|
|
805
|
-
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
806
|
-
set(v) {
|
|
807
|
-
if (v !== "file") {
|
|
808
|
-
restore();
|
|
809
|
-
el.type = v;
|
|
810
|
-
}
|
|
879
|
+
if (hasOwnSelection(element)) {
|
|
880
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
881
|
+
if (contenteditable) {
|
|
882
|
+
if (!selection.isCollapsed) {
|
|
883
|
+
const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
884
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
811
885
|
}
|
|
812
|
-
}
|
|
813
|
-
|
|
886
|
+
} else {
|
|
887
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
814
890
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
return result;
|
|
891
|
+
function getInputRange(focusNode) {
|
|
892
|
+
var _a3;
|
|
893
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
894
|
+
if (typeAndSelection.type === "input") {
|
|
895
|
+
return typeAndSelection.selection;
|
|
896
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
897
|
+
return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
|
|
898
|
+
}
|
|
824
899
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
900
|
+
function setSelection({
|
|
901
|
+
focusNode,
|
|
902
|
+
focusOffset,
|
|
903
|
+
anchorNode = focusNode,
|
|
904
|
+
anchorOffset = focusOffset
|
|
905
|
+
}) {
|
|
906
|
+
var _a3, _b;
|
|
907
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
908
|
+
if (typeAndSelection.type === "input") {
|
|
909
|
+
return setUISelection(focusNode, {
|
|
910
|
+
anchorOffset,
|
|
911
|
+
focusOffset
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
(_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
829
915
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
916
|
+
function moveSelection(node, direction) {
|
|
917
|
+
if (hasOwnSelection(node)) {
|
|
918
|
+
const selection = getUISelection(node);
|
|
919
|
+
setSelection({
|
|
920
|
+
focusNode: node,
|
|
921
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
922
|
+
});
|
|
836
923
|
} else {
|
|
837
|
-
|
|
838
|
-
|
|
924
|
+
const selection = node.ownerDocument.getSelection();
|
|
925
|
+
if (!selection) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (selection.isCollapsed) {
|
|
929
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
930
|
+
if (nextPosition) {
|
|
931
|
+
setSelection({
|
|
932
|
+
focusNode: nextPosition.node,
|
|
933
|
+
focusOffset: nextPosition.offset
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
} else {
|
|
937
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
839
938
|
}
|
|
840
|
-
return activeElement;
|
|
841
939
|
}
|
|
842
940
|
}
|
|
843
941
|
|
|
844
|
-
// src/utils/focus/selector.ts
|
|
845
|
-
var FOCUSABLE_SELECTOR = [
|
|
846
|
-
"input:not([type=hidden]):not([disabled])",
|
|
847
|
-
"button:not([disabled])",
|
|
848
|
-
"select:not([disabled])",
|
|
849
|
-
"textarea:not([disabled])",
|
|
850
|
-
'[contenteditable=""]',
|
|
851
|
-
'[contenteditable="true"]',
|
|
852
|
-
"a[href]",
|
|
853
|
-
"[tabindex]:not([disabled])"
|
|
854
|
-
].join(", ");
|
|
855
|
-
|
|
856
|
-
// src/utils/focus/isFocusable.ts
|
|
857
|
-
function isFocusable(element) {
|
|
858
|
-
return element.matches(FOCUSABLE_SELECTOR);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// src/utils/focus/blur.ts
|
|
862
|
-
function blur(element) {
|
|
863
|
-
if (!isFocusable(element))
|
|
864
|
-
return;
|
|
865
|
-
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
866
|
-
if (!wasActive)
|
|
867
|
-
return;
|
|
868
|
-
eventWrapper(() => element.blur());
|
|
869
|
-
}
|
|
870
|
-
|
|
871
942
|
// src/utils/focus/copySelection.ts
|
|
872
943
|
function copySelection(target) {
|
|
873
944
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
874
|
-
const dt = createDataTransfer();
|
|
945
|
+
const dt = createDataTransfer(getWindow(target));
|
|
875
946
|
for (const type3 in data) {
|
|
876
947
|
if (data[type3]) {
|
|
877
948
|
dt.setData(type3, data[type3]);
|
|
@@ -912,9 +983,8 @@ function focus(element) {
|
|
|
912
983
|
}
|
|
913
984
|
|
|
914
985
|
// src/utils/misc/isVisible.ts
|
|
915
|
-
var import_helpers = require("@testing-library/dom/dist/helpers.js");
|
|
916
986
|
function isVisible(element) {
|
|
917
|
-
const window2 = (
|
|
987
|
+
const window2 = getWindow(element);
|
|
918
988
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
919
989
|
const { display, visibility } = window2.getComputedStyle(el);
|
|
920
990
|
if (display === "none") {
|
|
@@ -980,7 +1050,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
980
1050
|
|
|
981
1051
|
// src/utils/focus/selectAll.ts
|
|
982
1052
|
function selectAll(target) {
|
|
983
|
-
var
|
|
1053
|
+
var _a3;
|
|
984
1054
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
985
1055
|
return setSelection({
|
|
986
1056
|
focusNode: target,
|
|
@@ -988,7 +1058,7 @@ function selectAll(target) {
|
|
|
988
1058
|
focusOffset: getUIValue(target).length
|
|
989
1059
|
});
|
|
990
1060
|
}
|
|
991
|
-
const focusNode = (
|
|
1061
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
992
1062
|
setSelection({
|
|
993
1063
|
focusNode,
|
|
994
1064
|
anchorOffset: 0,
|
|
@@ -996,11 +1066,11 @@ function selectAll(target) {
|
|
|
996
1066
|
});
|
|
997
1067
|
}
|
|
998
1068
|
function isAllSelected(target) {
|
|
999
|
-
var
|
|
1069
|
+
var _a3;
|
|
1000
1070
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1001
1071
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1002
1072
|
}
|
|
1003
|
-
const focusNode = (
|
|
1073
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1004
1074
|
const selection = target.ownerDocument.getSelection();
|
|
1005
1075
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1006
1076
|
}
|
|
@@ -1037,7 +1107,7 @@ var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
|
1037
1107
|
bracketDict2["["] = "]";
|
|
1038
1108
|
return bracketDict2;
|
|
1039
1109
|
})(bracketDict || {});
|
|
1040
|
-
function readNextDescriptor(text) {
|
|
1110
|
+
function readNextDescriptor(text, context) {
|
|
1041
1111
|
let pos = 0;
|
|
1042
1112
|
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
1043
1113
|
pos += startBracket.length;
|
|
@@ -1045,11 +1115,11 @@ function readNextDescriptor(text) {
|
|
|
1045
1115
|
const type3 = isEscapedChar ? "" : startBracket;
|
|
1046
1116
|
return __spreadValues({
|
|
1047
1117
|
type: type3
|
|
1048
|
-
}, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
|
|
1118
|
+
}, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
|
|
1049
1119
|
}
|
|
1050
|
-
function readPrintableChar(text, pos) {
|
|
1120
|
+
function readPrintableChar(text, pos, context) {
|
|
1051
1121
|
const descriptor = text[pos];
|
|
1052
|
-
assertDescriptor(descriptor, text, pos);
|
|
1122
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1053
1123
|
pos += descriptor.length;
|
|
1054
1124
|
return {
|
|
1055
1125
|
consumedLength: pos,
|
|
@@ -1059,14 +1129,14 @@ function readPrintableChar(text, pos) {
|
|
|
1059
1129
|
repeat: 1
|
|
1060
1130
|
};
|
|
1061
1131
|
}
|
|
1062
|
-
function readTag(text, pos, startBracket) {
|
|
1063
|
-
var
|
|
1132
|
+
function readTag(text, pos, startBracket, context) {
|
|
1133
|
+
var _a3, _b, _c;
|
|
1064
1134
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1065
1135
|
pos += releasePreviousModifier.length;
|
|
1066
1136
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1067
1137
|
pos += Number(escapedDescriptor);
|
|
1068
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1069
|
-
assertDescriptor(descriptor, text, pos);
|
|
1138
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
|
|
1139
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1070
1140
|
pos += descriptor.length;
|
|
1071
1141
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
1072
1142
|
pos += repeatModifier.length;
|
|
@@ -1079,7 +1149,7 @@ function readTag(text, pos, startBracket) {
|
|
|
1079
1149
|
!repeatModifier && "repeat modifier",
|
|
1080
1150
|
!releaseSelfModifier && "release modifier",
|
|
1081
1151
|
`"${expectedEndBracket}"`
|
|
1082
|
-
].filter(Boolean).join(" or "), text[pos], text));
|
|
1152
|
+
].filter(Boolean).join(" or "), text[pos], text, context));
|
|
1083
1153
|
}
|
|
1084
1154
|
pos += endBracket.length;
|
|
1085
1155
|
return {
|
|
@@ -1090,9 +1160,9 @@ function readTag(text, pos, startBracket) {
|
|
|
1090
1160
|
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
1091
1161
|
};
|
|
1092
1162
|
}
|
|
1093
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
1163
|
+
function assertDescriptor(descriptor, text, pos, context) {
|
|
1094
1164
|
if (!descriptor) {
|
|
1095
|
-
throw new Error(getErrorMessage("key descriptor", text[pos], text));
|
|
1165
|
+
throw new Error(getErrorMessage("key descriptor", text[pos], text, context));
|
|
1096
1166
|
}
|
|
1097
1167
|
}
|
|
1098
1168
|
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
@@ -1103,9 +1173,9 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
1103
1173
|
return false;
|
|
1104
1174
|
}
|
|
1105
1175
|
}
|
|
1106
|
-
function getErrorMessage(expected, found, text) {
|
|
1176
|
+
function getErrorMessage(expected, found, text, context) {
|
|
1107
1177
|
return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
|
|
1108
|
-
See https://
|
|
1178
|
+
See ${context === "pointer" ? `https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen` : `https://testing-library.com/docs/user-event/keyboard`}
|
|
1109
1179
|
for more information about how userEvent parses your input.`;
|
|
1110
1180
|
}
|
|
1111
1181
|
|
|
@@ -1137,13 +1207,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1137
1207
|
// src/utils/misc/level.ts
|
|
1138
1208
|
var Level = Symbol("Api level refs");
|
|
1139
1209
|
function setLevelRef(config, level) {
|
|
1140
|
-
var
|
|
1141
|
-
(
|
|
1210
|
+
var _a3;
|
|
1211
|
+
(_a3 = config[Level]) != null ? _a3 : config[Level] = {};
|
|
1142
1212
|
config[Level][level] = {};
|
|
1143
1213
|
}
|
|
1144
1214
|
function getLevelRef(config, level) {
|
|
1145
|
-
var
|
|
1146
|
-
return (
|
|
1215
|
+
var _a3;
|
|
1216
|
+
return (_a3 = config[Level]) == null ? void 0 : _a3[level];
|
|
1147
1217
|
}
|
|
1148
1218
|
|
|
1149
1219
|
// src/utils/misc/wait.ts
|
|
@@ -1151,12 +1221,6 @@ function wait(time) {
|
|
|
1151
1221
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1152
1222
|
}
|
|
1153
1223
|
|
|
1154
|
-
// src/utils/misc/hasFormSubmit.ts
|
|
1155
|
-
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1156
|
-
|
|
1157
|
-
// src/utils/pointer/cssPointerEvents.ts
|
|
1158
|
-
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1159
|
-
|
|
1160
1224
|
// src/keyboard/keyMap.ts
|
|
1161
1225
|
var defaultKeyMap = [
|
|
1162
1226
|
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
@@ -1250,7 +1314,7 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1250
1314
|
|
|
1251
1315
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1252
1316
|
function hasPointerEvents(element) {
|
|
1253
|
-
const window2 = (
|
|
1317
|
+
const window2 = getWindow(element);
|
|
1254
1318
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1255
1319
|
const pointerEvents = window2.getComputedStyle(el).pointerEvents;
|
|
1256
1320
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
@@ -1313,13 +1377,22 @@ function getMouseButtons(...buttons) {
|
|
|
1313
1377
|
|
|
1314
1378
|
// src/event/createEvent.ts
|
|
1315
1379
|
var import_dom2 = require("@testing-library/dom");
|
|
1316
|
-
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1317
1380
|
|
|
1318
|
-
// src/event/
|
|
1381
|
+
// src/event/eventMap.ts
|
|
1319
1382
|
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1320
|
-
var
|
|
1383
|
+
var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
|
|
1384
|
+
beforeInput: {
|
|
1385
|
+
EventType: "InputEvent",
|
|
1386
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1390
|
+
|
|
1391
|
+
// src/event/eventTypes.ts
|
|
1392
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1393
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map2.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1321
1394
|
function getEventClass(type3) {
|
|
1322
|
-
return
|
|
1395
|
+
return type3 in eventKeys ? import_event_map2.eventMap[eventKeys[type3]].EventType : "Event";
|
|
1323
1396
|
}
|
|
1324
1397
|
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1325
1398
|
function isMouseEvent(type3) {
|
|
@@ -1331,8 +1404,7 @@ function isKeyboardEvent(type3) {
|
|
|
1331
1404
|
|
|
1332
1405
|
// src/event/createEvent.ts
|
|
1333
1406
|
function createEvent(type3, target, init) {
|
|
1334
|
-
const
|
|
1335
|
-
const event = import_dom2.createEvent[eventKey](target, init);
|
|
1407
|
+
const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1336
1408
|
if (isMouseEvent(type3) && init) {
|
|
1337
1409
|
assignPositionInit(event, init);
|
|
1338
1410
|
assignPointerInit(event, init);
|
|
@@ -1356,9 +1428,9 @@ function assignPositionInit(obj, {
|
|
|
1356
1428
|
screenX,
|
|
1357
1429
|
screenY
|
|
1358
1430
|
}) {
|
|
1359
|
-
var
|
|
1431
|
+
var _a3, _b, _c, _d;
|
|
1360
1432
|
assignProps(obj, {
|
|
1361
|
-
x: (
|
|
1433
|
+
x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
|
|
1362
1434
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1363
1435
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1364
1436
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1383,8 +1455,8 @@ var behavior = {};
|
|
|
1383
1455
|
|
|
1384
1456
|
// src/event/behavior/click.ts
|
|
1385
1457
|
behavior.click = (event, target, config) => {
|
|
1386
|
-
|
|
1387
|
-
const control =
|
|
1458
|
+
const context = target.closest("button,input,label,select,textarea");
|
|
1459
|
+
const control = context && isElementType(context, "label") && context.control;
|
|
1388
1460
|
if (control) {
|
|
1389
1461
|
return () => {
|
|
1390
1462
|
if (isFocusable(control)) {
|
|
@@ -1395,17 +1467,175 @@ behavior.click = (event, target, config) => {
|
|
|
1395
1467
|
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1396
1468
|
return () => {
|
|
1397
1469
|
blur(target);
|
|
1398
|
-
target.dispatchEvent(new Event("fileDialog"));
|
|
1470
|
+
target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
|
|
1399
1471
|
focus(target);
|
|
1400
1472
|
};
|
|
1401
1473
|
}
|
|
1402
1474
|
};
|
|
1403
1475
|
|
|
1476
|
+
// src/event/behavior/cut.ts
|
|
1477
|
+
behavior.cut = (event, target, config) => {
|
|
1478
|
+
return () => {
|
|
1479
|
+
if (isEditable(target)) {
|
|
1480
|
+
input(config, target, "", "deleteByCut");
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
// src/event/behavior/keydown.ts
|
|
1486
|
+
behavior.keydown = (event, target, config) => {
|
|
1487
|
+
var _a3, _b;
|
|
1488
|
+
return (_b = (_a3 = keydownBehavior[event.key]) == null ? void 0 : _a3.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1489
|
+
};
|
|
1490
|
+
var keydownBehavior = {
|
|
1491
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1492
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1493
|
+
Backspace: (event, target, config) => {
|
|
1494
|
+
if (isEditable(target)) {
|
|
1495
|
+
return () => {
|
|
1496
|
+
input(config, target, "", "deleteContentBackward");
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
Delete: (event, target, config) => {
|
|
1501
|
+
if (isEditable(target)) {
|
|
1502
|
+
return () => {
|
|
1503
|
+
input(config, target, "", "deleteContentForward");
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
End: (event, target) => {
|
|
1508
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1509
|
+
return () => {
|
|
1510
|
+
var _a3, _b;
|
|
1511
|
+
const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
|
|
1512
|
+
setSelectionRange(target, newPos, newPos);
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
},
|
|
1516
|
+
Home: (event, target) => {
|
|
1517
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1518
|
+
return () => {
|
|
1519
|
+
setSelectionRange(target, 0, 0);
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
PageDown: (event, target) => {
|
|
1524
|
+
if (isElementType(target, ["input"])) {
|
|
1525
|
+
return () => {
|
|
1526
|
+
const newPos = getValue(target).length;
|
|
1527
|
+
setSelectionRange(target, newPos, newPos);
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
},
|
|
1531
|
+
PageUp: (event, target) => {
|
|
1532
|
+
if (isElementType(target, ["input"])) {
|
|
1533
|
+
return () => {
|
|
1534
|
+
setSelectionRange(target, 0, 0);
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1539
|
+
return () => {
|
|
1540
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1541
|
+
focus(dest);
|
|
1542
|
+
if (hasOwnSelection(dest)) {
|
|
1543
|
+
setUISelection(dest, {
|
|
1544
|
+
anchorOffset: 0,
|
|
1545
|
+
focusOffset: dest.value.length
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
var combinationBehavior = (event, target, config) => {
|
|
1552
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1553
|
+
return () => selectAll(target);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// src/event/behavior/keypress.ts
|
|
1558
|
+
behavior.keypress = (event, target, config) => {
|
|
1559
|
+
if (event.key === "Enter") {
|
|
1560
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1561
|
+
return () => {
|
|
1562
|
+
dispatchUIEvent(config, target, "click");
|
|
1563
|
+
};
|
|
1564
|
+
} else if (isElementType(target, "input")) {
|
|
1565
|
+
const form = target.form;
|
|
1566
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1567
|
+
if (submit) {
|
|
1568
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1569
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1570
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1571
|
+
} else {
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
if (isEditable(target)) {
|
|
1577
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1578
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1579
|
+
return () => input(config, target, inputData, inputType);
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
var ClickInputOnEnter = [
|
|
1583
|
+
"button",
|
|
1584
|
+
"color",
|
|
1585
|
+
"file",
|
|
1586
|
+
"image",
|
|
1587
|
+
"reset",
|
|
1588
|
+
"submit"
|
|
1589
|
+
];
|
|
1590
|
+
var SubmitSingleInputOnEnter = [
|
|
1591
|
+
"email",
|
|
1592
|
+
"month",
|
|
1593
|
+
"password",
|
|
1594
|
+
"search",
|
|
1595
|
+
"tel",
|
|
1596
|
+
"text",
|
|
1597
|
+
"url",
|
|
1598
|
+
"week"
|
|
1599
|
+
];
|
|
1600
|
+
|
|
1601
|
+
// src/event/behavior/keyup.ts
|
|
1602
|
+
behavior.keyup = (event, target, config) => {
|
|
1603
|
+
var _a3;
|
|
1604
|
+
return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
|
|
1605
|
+
};
|
|
1606
|
+
var keyupBehavior = {
|
|
1607
|
+
" ": (event, target, config) => {
|
|
1608
|
+
if (isClickableInput(target)) {
|
|
1609
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
// src/event/behavior/paste.ts
|
|
1615
|
+
behavior.paste = (event, target, config) => {
|
|
1616
|
+
if (isEditable(target)) {
|
|
1617
|
+
return () => {
|
|
1618
|
+
var _a3;
|
|
1619
|
+
const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
|
|
1620
|
+
if (insertData) {
|
|
1621
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
|
|
1627
|
+
// src/event/wrapEvent.ts
|
|
1628
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1629
|
+
function wrapEvent(cb, _element) {
|
|
1630
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1404
1633
|
// src/event/dispatchEvent.ts
|
|
1405
|
-
function dispatchEvent(config, target, event) {
|
|
1406
|
-
var
|
|
1634
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1635
|
+
var _a3, _b;
|
|
1407
1636
|
const type3 = event.type;
|
|
1408
|
-
const behaviorImplementation =
|
|
1637
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1638
|
+
} : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
|
|
1409
1639
|
if (behaviorImplementation) {
|
|
1410
1640
|
event.preventDefault();
|
|
1411
1641
|
let defaultPrevented = false;
|
|
@@ -1417,28 +1647,22 @@ function dispatchEvent(config, target, event) {
|
|
|
1417
1647
|
defaultPrevented = event.cancelable;
|
|
1418
1648
|
}
|
|
1419
1649
|
});
|
|
1420
|
-
target.dispatchEvent(event);
|
|
1650
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1421
1651
|
if (!defaultPrevented) {
|
|
1422
1652
|
behaviorImplementation();
|
|
1423
1653
|
}
|
|
1424
1654
|
return !defaultPrevented;
|
|
1425
1655
|
}
|
|
1426
|
-
return target.dispatchEvent(event);
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
// src/event/wrapEvent.ts
|
|
1430
|
-
var import_dom3 = require("@testing-library/dom");
|
|
1431
|
-
function wrapEvent(cb, _element) {
|
|
1432
|
-
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1656
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1433
1657
|
}
|
|
1434
1658
|
|
|
1435
1659
|
// src/event/index.ts
|
|
1436
|
-
function dispatchUIEvent(config, target, type3, init) {
|
|
1660
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1437
1661
|
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1438
1662
|
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1439
1663
|
}
|
|
1440
1664
|
const event = createEvent(type3, target, init);
|
|
1441
|
-
return
|
|
1665
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1442
1666
|
}
|
|
1443
1667
|
function bindDispatchUIEvent(config) {
|
|
1444
1668
|
return dispatchUIEvent.bind(void 0, config);
|
|
@@ -1515,9 +1739,9 @@ function setUISelection(element, {
|
|
|
1515
1739
|
}
|
|
1516
1740
|
}
|
|
1517
1741
|
function getUISelection(element) {
|
|
1518
|
-
var
|
|
1742
|
+
var _a3, _b, _c;
|
|
1519
1743
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1520
|
-
anchorOffset: (
|
|
1744
|
+
anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
|
|
1521
1745
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1522
1746
|
};
|
|
1523
1747
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1525,9 +1749,6 @@ function getUISelection(element) {
|
|
|
1525
1749
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1526
1750
|
});
|
|
1527
1751
|
}
|
|
1528
|
-
function clearUISelection(element) {
|
|
1529
|
-
element[UISelection] = void 0;
|
|
1530
|
-
}
|
|
1531
1752
|
|
|
1532
1753
|
// src/document/value.ts
|
|
1533
1754
|
var UIValue = Symbol("Displayed value in UI");
|
|
@@ -1535,17 +1756,23 @@ var InitialValue = Symbol("Initial value to compare on blur");
|
|
|
1535
1756
|
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1536
1757
|
function valueInterceptor(v) {
|
|
1537
1758
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1759
|
+
if (isUI) {
|
|
1760
|
+
this[UIValue] = String(v);
|
|
1761
|
+
setPreviousValue(this, String(this.value));
|
|
1762
|
+
} else {
|
|
1763
|
+
trackOrSetValue(this, String(v));
|
|
1543
1764
|
}
|
|
1544
1765
|
return {
|
|
1545
1766
|
applyNative: !!isUI,
|
|
1546
|
-
realArgs:
|
|
1767
|
+
realArgs: sanitizeValue(this, v)
|
|
1547
1768
|
};
|
|
1548
1769
|
}
|
|
1770
|
+
function sanitizeValue(element, v) {
|
|
1771
|
+
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) {
|
|
1772
|
+
return String(Number(v));
|
|
1773
|
+
}
|
|
1774
|
+
return String(v);
|
|
1775
|
+
}
|
|
1549
1776
|
function prepareValueInterceptor(element) {
|
|
1550
1777
|
prepareInterceptor(element, "value", valueInterceptor);
|
|
1551
1778
|
}
|
|
@@ -1564,17 +1791,36 @@ function setInitialValue(element) {
|
|
|
1564
1791
|
function getInitialValue(element) {
|
|
1565
1792
|
return element[InitialValue];
|
|
1566
1793
|
}
|
|
1794
|
+
function setPreviousValue(element, v) {
|
|
1795
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
|
|
1796
|
+
}
|
|
1567
1797
|
function startTrackValue(element) {
|
|
1568
|
-
element[TrackChanges] = []
|
|
1798
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
|
|
1799
|
+
nextValue: String(element.value),
|
|
1800
|
+
tracked: []
|
|
1801
|
+
});
|
|
1569
1802
|
}
|
|
1570
|
-
function
|
|
1571
|
-
var
|
|
1572
|
-
(
|
|
1803
|
+
function trackOrSetValue(element, v) {
|
|
1804
|
+
var _a3, _b, _c;
|
|
1805
|
+
(_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
|
|
1806
|
+
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1807
|
+
setCleanValue(element, v);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
function setCleanValue(element, v) {
|
|
1811
|
+
element[UIValue] = void 0;
|
|
1812
|
+
element[InitialValue] = v;
|
|
1813
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1573
1814
|
}
|
|
1574
1815
|
function endTrackValue(element) {
|
|
1575
|
-
|
|
1816
|
+
var _a3, _b;
|
|
1817
|
+
const changes = element[TrackChanges];
|
|
1576
1818
|
element[TrackChanges] = void 0;
|
|
1577
|
-
|
|
1819
|
+
const isJustReactStateUpdate = ((_a3 = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a3.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
|
|
1820
|
+
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1821
|
+
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1822
|
+
}
|
|
1823
|
+
return isJustReactStateUpdate;
|
|
1578
1824
|
}
|
|
1579
1825
|
|
|
1580
1826
|
// src/document/index.ts
|
|
@@ -1619,259 +1865,7 @@ function prepareElement(el) {
|
|
|
1619
1865
|
el[isPrepared] = isPrepared;
|
|
1620
1866
|
}
|
|
1621
1867
|
|
|
1622
|
-
// src/keyboard/
|
|
1623
|
-
var keydownBehavior = [
|
|
1624
|
-
{
|
|
1625
|
-
matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
|
|
1626
|
-
handle: (keyDef, element) => {
|
|
1627
|
-
if (hasOwnSelection(element)) {
|
|
1628
|
-
const selection = getUISelection(element);
|
|
1629
|
-
setSelection({
|
|
1630
|
-
focusNode: element,
|
|
1631
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1632
|
-
});
|
|
1633
|
-
} else {
|
|
1634
|
-
const selection = element.ownerDocument.getSelection();
|
|
1635
|
-
if (!selection) {
|
|
1636
|
-
return;
|
|
1637
|
-
}
|
|
1638
|
-
if (selection.isCollapsed) {
|
|
1639
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1640
|
-
if (nextPosition) {
|
|
1641
|
-
setSelection({
|
|
1642
|
-
focusNode: nextPosition.node,
|
|
1643
|
-
focusOffset: nextPosition.offset
|
|
1644
|
-
});
|
|
1645
|
-
}
|
|
1646
|
-
} else {
|
|
1647
|
-
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
];
|
|
1653
|
-
|
|
1654
|
-
// src/keyboard/plugins/control.ts
|
|
1655
|
-
var keydownBehavior2 = [
|
|
1656
|
-
{
|
|
1657
|
-
matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
|
|
1658
|
-
handle: (keyDef, element) => {
|
|
1659
|
-
var _a, _b;
|
|
1660
|
-
if (keyDef.key === "Home") {
|
|
1661
|
-
setSelectionRange(element, 0, 0);
|
|
1662
|
-
} else {
|
|
1663
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1664
|
-
setSelectionRange(element, newPos, newPos);
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
},
|
|
1668
|
-
{
|
|
1669
|
-
matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
|
|
1670
|
-
handle: (keyDef, element) => {
|
|
1671
|
-
var _a, _b;
|
|
1672
|
-
if (keyDef.key === "PageUp") {
|
|
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 === "Delete" && isEditable(element),
|
|
1682
|
-
handle: (keDef, element, config) => {
|
|
1683
|
-
var _a;
|
|
1684
|
-
(_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
];
|
|
1688
|
-
|
|
1689
|
-
// src/keyboard/shared/fireChangeForInputTimeIfValid.ts
|
|
1690
|
-
function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
|
|
1691
|
-
if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
|
|
1692
|
-
setUIValue(el, timeNewEntry);
|
|
1693
|
-
dispatchUIEvent(config, el, "change");
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
// src/keyboard/plugins/character.ts
|
|
1698
|
-
var keypressBehavior = [
|
|
1699
|
-
{
|
|
1700
|
-
matches: (keyDef, element) => {
|
|
1701
|
-
var _a;
|
|
1702
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1703
|
-
},
|
|
1704
|
-
handle: (keyDef, element, config) => {
|
|
1705
|
-
var _a;
|
|
1706
|
-
let newEntry = keyDef.key;
|
|
1707
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1708
|
-
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1709
|
-
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1710
|
-
newEntry = timeNewEntry;
|
|
1711
|
-
}
|
|
1712
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1713
|
-
const prevValue = getValue(element);
|
|
1714
|
-
if (prevValue !== newValue) {
|
|
1715
|
-
editInputElement(config, element, {
|
|
1716
|
-
newValue,
|
|
1717
|
-
newSelection: {
|
|
1718
|
-
node: element,
|
|
1719
|
-
offset: newOffset
|
|
1720
|
-
},
|
|
1721
|
-
eventOverrides: {
|
|
1722
|
-
data: keyDef.key,
|
|
1723
|
-
inputType: "insertText"
|
|
1724
|
-
}
|
|
1725
|
-
});
|
|
1726
|
-
}
|
|
1727
|
-
fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
|
|
1728
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1729
|
-
}
|
|
1730
|
-
},
|
|
1731
|
-
{
|
|
1732
|
-
matches: (keyDef, element) => {
|
|
1733
|
-
var _a;
|
|
1734
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1735
|
-
},
|
|
1736
|
-
handle: (keyDef, element, config) => {
|
|
1737
|
-
var _a;
|
|
1738
|
-
let newEntry = keyDef.key;
|
|
1739
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1740
|
-
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1741
|
-
if (isValidToBeTyped) {
|
|
1742
|
-
newEntry = textToBeTyped;
|
|
1743
|
-
}
|
|
1744
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1745
|
-
const prevValue = getValue(element);
|
|
1746
|
-
if (prevValue !== newValue) {
|
|
1747
|
-
editInputElement(config, element, {
|
|
1748
|
-
newValue,
|
|
1749
|
-
newSelection: {
|
|
1750
|
-
node: element,
|
|
1751
|
-
offset: newOffset
|
|
1752
|
-
},
|
|
1753
|
-
eventOverrides: {
|
|
1754
|
-
data: keyDef.key,
|
|
1755
|
-
inputType: "insertText"
|
|
1756
|
-
}
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
if (isValidToBeTyped) {
|
|
1760
|
-
setUIValue(element, textToBeTyped);
|
|
1761
|
-
dispatchUIEvent(config, element, "change");
|
|
1762
|
-
}
|
|
1763
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1764
|
-
}
|
|
1765
|
-
},
|
|
1766
|
-
{
|
|
1767
|
-
matches: (keyDef, element) => {
|
|
1768
|
-
var _a;
|
|
1769
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1770
|
-
},
|
|
1771
|
-
handle: (keyDef, element, config) => {
|
|
1772
|
-
var _a, _b;
|
|
1773
|
-
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1774
|
-
return;
|
|
1775
|
-
}
|
|
1776
|
-
const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
|
|
1777
|
-
const newValue = getNewValue();
|
|
1778
|
-
const valueParts = newValue.split("e", 2);
|
|
1779
|
-
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])) {
|
|
1780
|
-
return;
|
|
1781
|
-
}
|
|
1782
|
-
commit();
|
|
1783
|
-
}
|
|
1784
|
-
},
|
|
1785
|
-
{
|
|
1786
|
-
matches: (keyDef, element) => {
|
|
1787
|
-
var _a;
|
|
1788
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1789
|
-
},
|
|
1790
|
-
handle: (keyDef, element, config) => {
|
|
1791
|
-
var _a;
|
|
1792
|
-
(_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1793
|
-
}
|
|
1794
|
-
},
|
|
1795
|
-
{
|
|
1796
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1797
|
-
handle: (keyDef, element, config) => {
|
|
1798
|
-
var _a;
|
|
1799
|
-
(_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
];
|
|
1803
|
-
|
|
1804
|
-
// src/keyboard/plugins/functional.ts
|
|
1805
|
-
var keydownBehavior3 = [
|
|
1806
|
-
{
|
|
1807
|
-
matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
|
|
1808
|
-
handle: (keyDef, element, config) => {
|
|
1809
|
-
var _a;
|
|
1810
|
-
(_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1811
|
-
}
|
|
1812
|
-
},
|
|
1813
|
-
{
|
|
1814
|
-
matches: (keyDef) => keyDef.key === "Tab",
|
|
1815
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1816
|
-
const dest = getTabDestination(element, keyboardState.modifiers.Shift);
|
|
1817
|
-
if (dest === element.ownerDocument.body) {
|
|
1818
|
-
blur(element);
|
|
1819
|
-
} else {
|
|
1820
|
-
focus(dest);
|
|
1821
|
-
if (isElementType(dest, ["input", "textarea"])) {
|
|
1822
|
-
setUISelection(dest, {
|
|
1823
|
-
anchorOffset: 0,
|
|
1824
|
-
focusOffset: dest.value.length
|
|
1825
|
-
});
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
];
|
|
1831
|
-
var keypressBehavior2 = [
|
|
1832
|
-
{
|
|
1833
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
|
|
1834
|
-
handle: (keyDef, element, config) => {
|
|
1835
|
-
const form = element.form;
|
|
1836
|
-
if (hasFormSubmit(form)) {
|
|
1837
|
-
dispatchUIEvent(config, form, "submit");
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
},
|
|
1841
|
-
{
|
|
1842
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1843
|
-
handle: (keyDef, element, config) => {
|
|
1844
|
-
dispatchUIEvent(config, element, "click");
|
|
1845
|
-
}
|
|
1846
|
-
},
|
|
1847
|
-
{
|
|
1848
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1849
|
-
handle: (keyDef, element, config) => {
|
|
1850
|
-
const form = element.form;
|
|
1851
|
-
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1852
|
-
dispatchUIEvent(config, form, "submit");
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
];
|
|
1857
|
-
var keyupBehavior = [
|
|
1858
|
-
{
|
|
1859
|
-
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1860
|
-
handle: (keyDef, element, config) => {
|
|
1861
|
-
dispatchUIEvent(config, element, "click");
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
];
|
|
1865
|
-
|
|
1866
|
-
// src/keyboard/plugins/combination.ts
|
|
1867
|
-
var keydownBehavior4 = [
|
|
1868
|
-
{
|
|
1869
|
-
matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
|
|
1870
|
-
handle: (keyDef, element) => selectAll(element)
|
|
1871
|
-
}
|
|
1872
|
-
];
|
|
1873
|
-
|
|
1874
|
-
// src/keyboard/plugins/modifiers.ts
|
|
1868
|
+
// src/keyboard/modifiers.ts
|
|
1875
1869
|
var modifierKeys = [
|
|
1876
1870
|
"Alt",
|
|
1877
1871
|
"AltGraph",
|
|
@@ -1881,6 +1875,9 @@ var modifierKeys = [
|
|
|
1881
1875
|
"Shift",
|
|
1882
1876
|
"Symbol"
|
|
1883
1877
|
];
|
|
1878
|
+
function isModifierKey(key) {
|
|
1879
|
+
return modifierKeys.includes(key);
|
|
1880
|
+
}
|
|
1884
1881
|
var modifierLocks = [
|
|
1885
1882
|
"CapsLock",
|
|
1886
1883
|
"FnLock",
|
|
@@ -1888,78 +1885,40 @@ var modifierLocks = [
|
|
|
1888
1885
|
"ScrollLock",
|
|
1889
1886
|
"SymbolLock"
|
|
1890
1887
|
];
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1888
|
+
function isModifierLock(key) {
|
|
1889
|
+
return modifierLocks.includes(key);
|
|
1890
|
+
}
|
|
1891
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1892
|
+
var _a3;
|
|
1893
|
+
if (isModifierKey(key)) {
|
|
1894
|
+
config.keyboardState.modifiers[key] = true;
|
|
1895
|
+
if (key === "AltGraph") {
|
|
1896
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1897
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1901
1898
|
}
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
const key = keyDef.key;
|
|
1907
|
-
keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
|
|
1908
|
-
if (!keyboardState.modifierPhase[key]) {
|
|
1909
|
-
keyboardState.modifiers[key] = true;
|
|
1910
|
-
}
|
|
1899
|
+
} else if (isModifierLock(key)) {
|
|
1900
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1901
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1902
|
+
config.keyboardState.modifiers[key] = true;
|
|
1911
1903
|
}
|
|
1912
1904
|
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
{
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
},
|
|
1921
|
-
{
|
|
1922
|
-
matches: (keyDef) => modifierLocks.includes(keyDef.key),
|
|
1923
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1924
|
-
const key = keyDef.key;
|
|
1925
|
-
if (keyboardState.modifierPhase[key]) {
|
|
1926
|
-
keyboardState.modifiers[key] = false;
|
|
1927
|
-
}
|
|
1905
|
+
}
|
|
1906
|
+
function preKeyupBehavior(config, { key }) {
|
|
1907
|
+
if (isModifierKey(key)) {
|
|
1908
|
+
config.keyboardState.modifiers[key] = false;
|
|
1909
|
+
} else if (isModifierLock(key)) {
|
|
1910
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1911
|
+
config.keyboardState.modifiers[key] = false;
|
|
1928
1912
|
}
|
|
1929
1913
|
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1937
|
-
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1938
|
-
}
|
|
1914
|
+
}
|
|
1915
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1916
|
+
var _a3;
|
|
1917
|
+
if (key === "AltGraph") {
|
|
1918
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1919
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1939
1920
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
// src/keyboard/plugins/index.ts
|
|
1943
|
-
var preKeydownBehavior2 = [
|
|
1944
|
-
...preKeydownBehavior
|
|
1945
|
-
];
|
|
1946
|
-
var keydownBehavior5 = [
|
|
1947
|
-
...keydownBehavior,
|
|
1948
|
-
...keydownBehavior2,
|
|
1949
|
-
...keydownBehavior3,
|
|
1950
|
-
...keydownBehavior4
|
|
1951
|
-
];
|
|
1952
|
-
var keypressBehavior3 = [
|
|
1953
|
-
...keypressBehavior2,
|
|
1954
|
-
...keypressBehavior
|
|
1955
|
-
];
|
|
1956
|
-
var preKeyupBehavior2 = [
|
|
1957
|
-
...preKeyupBehavior
|
|
1958
|
-
];
|
|
1959
|
-
var keyupBehavior2 = [...keyupBehavior];
|
|
1960
|
-
var postKeyupBehavior2 = [
|
|
1961
|
-
...postKeyupBehavior
|
|
1962
|
-
];
|
|
1921
|
+
}
|
|
1963
1922
|
|
|
1964
1923
|
// src/keyboard/keyboardAction.ts
|
|
1965
1924
|
async function keyboardAction(config, actions) {
|
|
@@ -1994,8 +1953,8 @@ async function keyboardKeyAction(config, { keyDef, releasePrevious, releaseSelf,
|
|
|
1994
1953
|
}
|
|
1995
1954
|
}
|
|
1996
1955
|
function getActive(document2) {
|
|
1997
|
-
var
|
|
1998
|
-
return (
|
|
1956
|
+
var _a3;
|
|
1957
|
+
return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
|
|
1999
1958
|
}
|
|
2000
1959
|
async function releaseAllKeys(config) {
|
|
2001
1960
|
const getCurrentElement = () => getActive(config.document);
|
|
@@ -2010,48 +1969,32 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
2010
1969
|
config.keyboardState.carryChar = "";
|
|
2011
1970
|
}
|
|
2012
1971
|
config.keyboardState.activeElement = element;
|
|
2013
|
-
|
|
1972
|
+
preKeydownBehavior(config, keyDef, element);
|
|
2014
1973
|
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
2015
1974
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
2016
|
-
if (unpreventedDefault) {
|
|
2017
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
2018
|
-
}
|
|
2019
1975
|
return unpreventedDefault;
|
|
2020
1976
|
}
|
|
2021
1977
|
async function keypress(keyDef, getCurrentElement, config) {
|
|
2022
1978
|
const element = getCurrentElement();
|
|
2023
|
-
|
|
1979
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2024
1980
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2025
1981
|
}));
|
|
2026
|
-
if (unpreventedDefault) {
|
|
2027
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2028
|
-
}
|
|
2029
1982
|
}
|
|
2030
1983
|
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2031
1984
|
const element = getCurrentElement();
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
if (unprevented && unpreventedDefault) {
|
|
2035
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2036
|
-
}
|
|
1985
|
+
preKeyupBehavior(config, keyDef);
|
|
1986
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2037
1987
|
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
2038
|
-
|
|
2039
|
-
}
|
|
2040
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
2041
|
-
const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
|
|
2042
|
-
if (plugin) {
|
|
2043
|
-
plugin.handle(keyDef, element, config);
|
|
2044
|
-
}
|
|
2045
|
-
return !!plugin;
|
|
1988
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2046
1989
|
}
|
|
2047
1990
|
function hasKeyPress(keyDef, config) {
|
|
2048
|
-
var
|
|
2049
|
-
return (((
|
|
1991
|
+
var _a3;
|
|
1992
|
+
return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
2050
1993
|
}
|
|
2051
1994
|
|
|
2052
1995
|
// src/keyboard/parseKeyDef.ts
|
|
2053
1996
|
function parseKeyDef(keyboardMap, text) {
|
|
2054
|
-
var
|
|
1997
|
+
var _a3;
|
|
2055
1998
|
const defs = [];
|
|
2056
1999
|
do {
|
|
2057
2000
|
const {
|
|
@@ -2061,16 +2004,16 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2061
2004
|
releasePrevious,
|
|
2062
2005
|
releaseSelf = true,
|
|
2063
2006
|
repeat
|
|
2064
|
-
} = readNextDescriptor(text);
|
|
2065
|
-
const keyDef = (
|
|
2066
|
-
var
|
|
2007
|
+
} = readNextDescriptor(text, "keyboard");
|
|
2008
|
+
const keyDef = (_a3 = keyboardMap.find((def) => {
|
|
2009
|
+
var _a4, _b;
|
|
2067
2010
|
if (type3 === "[") {
|
|
2068
|
-
return ((
|
|
2011
|
+
return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
|
|
2069
2012
|
} else if (type3 === "{") {
|
|
2070
2013
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2071
2014
|
}
|
|
2072
2015
|
return def.key === descriptor;
|
|
2073
|
-
})) != null ?
|
|
2016
|
+
})) != null ? _a3 : {
|
|
2074
2017
|
key: "Unknown",
|
|
2075
2018
|
code: "Unknown",
|
|
2076
2019
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2118,7 +2061,7 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2118
2061
|
consumedLength,
|
|
2119
2062
|
releasePrevious,
|
|
2120
2063
|
releaseSelf = true
|
|
2121
|
-
} = readNextDescriptor(keys);
|
|
2064
|
+
} = readNextDescriptor(keys, "pointer");
|
|
2122
2065
|
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
2123
2066
|
if (keyDef) {
|
|
2124
2067
|
defs.push({ keyDef, releasePrevious, releaseSelf });
|
|
@@ -2147,8 +2090,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2147
2090
|
}
|
|
2148
2091
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2149
2092
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2150
|
-
var
|
|
2151
|
-
return (
|
|
2093
|
+
var _a3;
|
|
2094
|
+
return (_a3 = p.keyDef.button) != null ? _a3 : 0;
|
|
2152
2095
|
}));
|
|
2153
2096
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2154
2097
|
init.detail = clickCount;
|
|
@@ -2306,7 +2249,7 @@ function getNextPointerId(state) {
|
|
|
2306
2249
|
return state.pointerId;
|
|
2307
2250
|
}
|
|
2308
2251
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2309
|
-
var
|
|
2252
|
+
var _a3, _b, _c;
|
|
2310
2253
|
setLevelRef(config, 2 /* Trigger */);
|
|
2311
2254
|
assertPointerEvents(config, target);
|
|
2312
2255
|
const { pointerState } = config;
|
|
@@ -2329,7 +2272,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2329
2272
|
}
|
|
2330
2273
|
}
|
|
2331
2274
|
}
|
|
2332
|
-
if (((
|
|
2275
|
+
if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
|
|
2333
2276
|
delete pointerState.activeClickCount;
|
|
2334
2277
|
}
|
|
2335
2278
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2483,7 +2426,7 @@ function mousedownDefaultBehavior({
|
|
|
2483
2426
|
node,
|
|
2484
2427
|
offset: end
|
|
2485
2428
|
});
|
|
2486
|
-
const range =
|
|
2429
|
+
const range = target.ownerDocument.createRange();
|
|
2487
2430
|
range.setStart(startNode, startOffset);
|
|
2488
2431
|
range.setEnd(endNode, endOffset);
|
|
2489
2432
|
position.selectionRange = range;
|
|
@@ -2512,11 +2455,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2512
2455
|
|
|
2513
2456
|
// src/pointer/pointerAction.ts
|
|
2514
2457
|
async function pointerAction(config, actions) {
|
|
2515
|
-
var
|
|
2458
|
+
var _a3, _b;
|
|
2516
2459
|
for (let i = 0; i < actions.length; i++) {
|
|
2517
2460
|
const action = actions[i];
|
|
2518
2461
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2519
|
-
const target = (
|
|
2462
|
+
const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
|
|
2520
2463
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2521
2464
|
await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
|
|
2522
2465
|
if (typeof config.delay === "number") {
|
|
@@ -2535,10 +2478,10 @@ function getPrevTarget(pointerName, state) {
|
|
|
2535
2478
|
}
|
|
2536
2479
|
|
|
2537
2480
|
// src/pointer/index.ts
|
|
2538
|
-
async function pointer(
|
|
2481
|
+
async function pointer(input2) {
|
|
2539
2482
|
const { pointerMap } = this[Config];
|
|
2540
2483
|
const actions = [];
|
|
2541
|
-
(Array.isArray(
|
|
2484
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2542
2485
|
if (typeof actionInput === "string") {
|
|
2543
2486
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2544
2487
|
} else if ("keys" in actionInput) {
|
|
@@ -2630,17 +2573,16 @@ async function tab({
|
|
|
2630
2573
|
|
|
2631
2574
|
// src/clipboard/copy.ts
|
|
2632
2575
|
async function copy() {
|
|
2633
|
-
var
|
|
2576
|
+
var _a3;
|
|
2634
2577
|
const doc = this[Config].document;
|
|
2635
|
-
const target = (
|
|
2578
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2636
2579
|
const clipboardData = copySelection(target);
|
|
2637
2580
|
if (clipboardData.items.length === 0) {
|
|
2638
2581
|
return;
|
|
2639
2582
|
}
|
|
2640
|
-
this.dispatchUIEvent(target, "copy", {
|
|
2583
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2641
2584
|
clipboardData
|
|
2642
|
-
})
|
|
2643
|
-
if (this[Config].writeToClipboard) {
|
|
2585
|
+
}) && this[Config].writeToClipboard) {
|
|
2644
2586
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2645
2587
|
}
|
|
2646
2588
|
return clipboardData;
|
|
@@ -2648,52 +2590,41 @@ async function copy() {
|
|
|
2648
2590
|
|
|
2649
2591
|
// src/clipboard/cut.ts
|
|
2650
2592
|
async function cut() {
|
|
2651
|
-
var
|
|
2593
|
+
var _a3;
|
|
2652
2594
|
const doc = this[Config].document;
|
|
2653
|
-
const target = (
|
|
2595
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2654
2596
|
const clipboardData = copySelection(target);
|
|
2655
2597
|
if (clipboardData.items.length === 0) {
|
|
2656
2598
|
return;
|
|
2657
2599
|
}
|
|
2658
|
-
this.dispatchUIEvent(target, "cut", {
|
|
2600
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2659
2601
|
clipboardData
|
|
2660
|
-
})
|
|
2661
|
-
|
|
2662
|
-
(_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2663
|
-
}
|
|
2664
|
-
if (this[Config].writeToClipboard) {
|
|
2665
|
-
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2602
|
+
}) && this[Config].writeToClipboard) {
|
|
2603
|
+
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2666
2604
|
}
|
|
2667
2605
|
return clipboardData;
|
|
2668
2606
|
}
|
|
2669
2607
|
|
|
2670
2608
|
// src/clipboard/paste.ts
|
|
2671
2609
|
async function paste(clipboardData) {
|
|
2672
|
-
var
|
|
2610
|
+
var _a3, _b;
|
|
2673
2611
|
const doc = this[Config].document;
|
|
2674
|
-
const target = (
|
|
2675
|
-
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2612
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2613
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2676
2614
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2677
2615
|
});
|
|
2678
2616
|
this.dispatchUIEvent(target, "paste", {
|
|
2679
2617
|
clipboardData: dataTransfer
|
|
2680
2618
|
});
|
|
2681
|
-
if (isEditable(target)) {
|
|
2682
|
-
const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2683
|
-
if (textData) {
|
|
2684
|
-
(_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
2619
|
}
|
|
2688
|
-
function getClipboardDataFromString(text) {
|
|
2689
|
-
const dt = createDataTransfer();
|
|
2620
|
+
function getClipboardDataFromString(doc, text) {
|
|
2621
|
+
const dt = createDataTransfer(getWindow(doc));
|
|
2690
2622
|
dt.setData("text", text);
|
|
2691
2623
|
return dt;
|
|
2692
2624
|
}
|
|
2693
2625
|
|
|
2694
2626
|
// src/utility/clear.ts
|
|
2695
2627
|
async function clear(element) {
|
|
2696
|
-
var _a;
|
|
2697
2628
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2698
2629
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2699
2630
|
}
|
|
@@ -2705,7 +2636,7 @@ async function clear(element) {
|
|
|
2705
2636
|
if (!isAllSelected(element)) {
|
|
2706
2637
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2707
2638
|
}
|
|
2708
|
-
(
|
|
2639
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2709
2640
|
}
|
|
2710
2641
|
|
|
2711
2642
|
// src/utility/selectOptions.ts
|
|
@@ -2822,28 +2753,28 @@ async function type(element, text, {
|
|
|
2822
2753
|
|
|
2823
2754
|
// src/utility/upload.ts
|
|
2824
2755
|
async function upload(element, fileOrFiles) {
|
|
2825
|
-
const
|
|
2826
|
-
if (!
|
|
2827
|
-
throw new TypeError(`The ${
|
|
2756
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2757
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2758
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2828
2759
|
}
|
|
2829
2760
|
if (isDisabled(element))
|
|
2830
2761
|
return;
|
|
2831
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file,
|
|
2762
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2832
2763
|
const fileDialog = () => {
|
|
2833
|
-
var
|
|
2834
|
-
if (files.length === ((
|
|
2835
|
-
var
|
|
2836
|
-
return f === ((
|
|
2764
|
+
var _a3;
|
|
2765
|
+
if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
|
|
2766
|
+
var _a4;
|
|
2767
|
+
return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
|
|
2837
2768
|
})) {
|
|
2838
2769
|
return;
|
|
2839
2770
|
}
|
|
2840
|
-
setFiles(
|
|
2841
|
-
this.dispatchUIEvent(
|
|
2842
|
-
this.dispatchUIEvent(
|
|
2771
|
+
setFiles(input2, createFileList(files));
|
|
2772
|
+
this.dispatchUIEvent(input2, "input");
|
|
2773
|
+
this.dispatchUIEvent(input2, "change");
|
|
2843
2774
|
};
|
|
2844
|
-
|
|
2775
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2845
2776
|
await this.click(element);
|
|
2846
|
-
|
|
2777
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2847
2778
|
}
|
|
2848
2779
|
function isAcceptableFile(file, accept) {
|
|
2849
2780
|
if (!accept) {
|
|
@@ -2880,10 +2811,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
2880
2811
|
});
|
|
2881
2812
|
}
|
|
2882
2813
|
function setupMain(options = {}) {
|
|
2883
|
-
var
|
|
2814
|
+
var _a3;
|
|
2884
2815
|
const config = createConfig(options);
|
|
2885
2816
|
prepareDocument(config.document);
|
|
2886
|
-
const view = (
|
|
2817
|
+
const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
|
|
2887
2818
|
attachClipboardStubToView(view);
|
|
2888
2819
|
return doSetup(config);
|
|
2889
2820
|
}
|
|
@@ -2919,8 +2850,8 @@ function doSetup(config) {
|
|
|
2919
2850
|
});
|
|
2920
2851
|
}
|
|
2921
2852
|
function getDocument(options, node) {
|
|
2922
|
-
var
|
|
2923
|
-
return (_b = (
|
|
2853
|
+
var _a3, _b;
|
|
2854
|
+
return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
|
|
2924
2855
|
}
|
|
2925
2856
|
|
|
2926
2857
|
// src/setup/directApi.ts
|
|
@@ -2968,9 +2899,9 @@ async function keyboard2(text, options = {}) {
|
|
|
2968
2899
|
const { config, api } = setupDirect(options);
|
|
2969
2900
|
return api.keyboard(text).then(() => config.keyboardState);
|
|
2970
2901
|
}
|
|
2971
|
-
async function pointer2(
|
|
2902
|
+
async function pointer2(input2, options = {}) {
|
|
2972
2903
|
const { config, api } = setupDirect(options);
|
|
2973
|
-
return api.pointer(
|
|
2904
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2974
2905
|
}
|
|
2975
2906
|
function paste2(clipboardData, options) {
|
|
2976
2907
|
return setupDirect(options).api.paste(clipboardData);
|
|
@@ -3000,4 +2931,3 @@ function tab2(options = {}) {
|
|
|
3000
2931
|
var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
|
|
3001
2932
|
setup: setupMain
|
|
3002
2933
|
});
|
|
3003
|
-
module.exports = __toCommonJS(src_exports);
|