@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.mjs
CHANGED
|
@@ -74,7 +74,7 @@ function isClickableInput(element) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/utils/dataTransfer/Blob.ts
|
|
77
|
-
function readBlobText(blob) {
|
|
77
|
+
function readBlobText(blob, FileReader) {
|
|
78
78
|
return new Promise((res, rej) => {
|
|
79
79
|
const fr = new FileReader();
|
|
80
80
|
fr.onerror = rej;
|
|
@@ -158,8 +158,8 @@ var DataTransferStub = class {
|
|
|
158
158
|
this.files = createFileList([]);
|
|
159
159
|
}
|
|
160
160
|
getData(format) {
|
|
161
|
-
var
|
|
162
|
-
const match = (
|
|
161
|
+
var _a3;
|
|
162
|
+
const match = (_a3 = this.items.find(getTypeMatcher(format, true))) != null ? _a3 : this.items.find(getTypeMatcher(format, false));
|
|
163
163
|
let text = "";
|
|
164
164
|
match == null ? void 0 : match.getAsString((t) => {
|
|
165
165
|
text = t;
|
|
@@ -197,12 +197,12 @@ var DataTransferStub = class {
|
|
|
197
197
|
setDragImage() {
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
|
-
function createDataTransfer(files = []) {
|
|
201
|
-
const dt = typeof DataTransfer === "undefined" ? new DataTransferStub() : new DataTransfer();
|
|
200
|
+
function createDataTransfer(window2, files = []) {
|
|
201
|
+
const dt = typeof window2.DataTransfer === "undefined" ? new DataTransferStub() : new window2.DataTransfer();
|
|
202
202
|
Object.defineProperty(dt, "files", { get: () => createFileList(files) });
|
|
203
203
|
return dt;
|
|
204
204
|
}
|
|
205
|
-
function getBlobFromDataTransferItem(item) {
|
|
205
|
+
function getBlobFromDataTransferItem(window2, item) {
|
|
206
206
|
if (item.kind === "file") {
|
|
207
207
|
return item.getAsFile();
|
|
208
208
|
}
|
|
@@ -210,12 +210,21 @@ function getBlobFromDataTransferItem(item) {
|
|
|
210
210
|
item.getAsString((s) => {
|
|
211
211
|
data = s;
|
|
212
212
|
});
|
|
213
|
-
return new Blob([data], { type: item.type });
|
|
213
|
+
return new window2.Blob([data], { type: item.type });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/utils/misc/getWindow.ts
|
|
217
|
+
import { getWindowFromNode } from "@testing-library/dom/dist/helpers.js";
|
|
218
|
+
function getWindow(node) {
|
|
219
|
+
return getWindowFromNode(node);
|
|
214
220
|
}
|
|
215
221
|
|
|
216
222
|
// src/utils/dataTransfer/Clipboard.ts
|
|
223
|
+
var Window = Symbol("Window reference");
|
|
224
|
+
var _a;
|
|
217
225
|
var ClipboardItemStub = class {
|
|
218
226
|
constructor(data) {
|
|
227
|
+
this[_a] = window;
|
|
219
228
|
this.data = data;
|
|
220
229
|
}
|
|
221
230
|
get types() {
|
|
@@ -227,15 +236,18 @@ var ClipboardItemStub = class {
|
|
|
227
236
|
if (!data) {
|
|
228
237
|
throw new Error(`${type3} is not one of the available MIME types on this item.`);
|
|
229
238
|
}
|
|
230
|
-
return data instanceof Blob ? data : new Blob([data], { type: type3 });
|
|
239
|
+
return data instanceof this[Window].Blob ? data : new this[Window].Blob([data], { type: type3 });
|
|
231
240
|
});
|
|
232
241
|
}
|
|
233
242
|
};
|
|
243
|
+
_a = Window;
|
|
234
244
|
var ClipboardStubControl = Symbol("Manage ClipboardSub");
|
|
235
|
-
var
|
|
245
|
+
var _a2;
|
|
246
|
+
var ClipboardStub = class extends window.EventTarget {
|
|
236
247
|
constructor() {
|
|
237
248
|
super(...arguments);
|
|
238
249
|
this.items = [];
|
|
250
|
+
this[_a2] = window;
|
|
239
251
|
}
|
|
240
252
|
read() {
|
|
241
253
|
return __async(this, null, function* () {
|
|
@@ -248,7 +260,7 @@ var ClipboardStub = class extends EventTarget {
|
|
|
248
260
|
for (const item of this.items) {
|
|
249
261
|
const type3 = item.types.includes("text/plain") ? "text/plain" : item.types.find((t) => t.startsWith("text/"));
|
|
250
262
|
if (type3) {
|
|
251
|
-
text += yield item.getType(type3).then((b) => readBlobText(b));
|
|
263
|
+
text += yield item.getType(type3).then((b) => readBlobText(b, this[Window].FileReader));
|
|
252
264
|
}
|
|
253
265
|
}
|
|
254
266
|
return text;
|
|
@@ -261,17 +273,23 @@ var ClipboardStub = class extends EventTarget {
|
|
|
261
273
|
}
|
|
262
274
|
writeText(text) {
|
|
263
275
|
return __async(this, null, function* () {
|
|
264
|
-
this.items = [createClipboardItem(text)];
|
|
276
|
+
this.items = [createClipboardItem(this[Window], text)];
|
|
265
277
|
});
|
|
266
278
|
}
|
|
267
279
|
};
|
|
268
|
-
ClipboardStubControl;
|
|
269
|
-
function createClipboardItem(...blobs) {
|
|
270
|
-
const
|
|
271
|
-
return new constructor(Object.fromEntries(blobs.map((b) => [
|
|
280
|
+
_a2 = Window, ClipboardStubControl;
|
|
281
|
+
function createClipboardItem(window2, ...blobs) {
|
|
282
|
+
const data = Object.fromEntries(blobs.map((b) => [
|
|
272
283
|
typeof b === "string" ? "text/plain" : b.type,
|
|
273
284
|
Promise.resolve(b)
|
|
274
|
-
]))
|
|
285
|
+
]));
|
|
286
|
+
if (typeof window2.ClipboardItem === "undefined") {
|
|
287
|
+
const item = new ClipboardItemStub(data);
|
|
288
|
+
item[Window] = window2;
|
|
289
|
+
return item;
|
|
290
|
+
} else {
|
|
291
|
+
return new window2.ClipboardItem(data);
|
|
292
|
+
}
|
|
275
293
|
}
|
|
276
294
|
function attachClipboardStubToView(window2) {
|
|
277
295
|
if (window2.navigator.clipboard instanceof ClipboardStub) {
|
|
@@ -279,9 +297,11 @@ function attachClipboardStubToView(window2) {
|
|
|
279
297
|
}
|
|
280
298
|
const realClipboard = Object.getOwnPropertyDescriptor(window2.navigator, "clipboard");
|
|
281
299
|
let stub = new ClipboardStub();
|
|
300
|
+
stub[Window] = window2;
|
|
282
301
|
const control = {
|
|
283
302
|
resetClipboardStub: () => {
|
|
284
303
|
stub = new ClipboardStub();
|
|
304
|
+
stub[Window] = window2;
|
|
285
305
|
stub[ClipboardStubControl] = control;
|
|
286
306
|
},
|
|
287
307
|
detachClipboardStub: () => {
|
|
@@ -314,16 +334,16 @@ function detachClipboardStubFromView(window2) {
|
|
|
314
334
|
}
|
|
315
335
|
function readDataTransferFromClipboard(document2) {
|
|
316
336
|
return __async(this, null, function* () {
|
|
317
|
-
|
|
318
|
-
const clipboard =
|
|
337
|
+
const window2 = document2.defaultView;
|
|
338
|
+
const clipboard = window2 == null ? void 0 : window2.navigator.clipboard;
|
|
319
339
|
const items = clipboard && (yield clipboard.read());
|
|
320
340
|
if (!items) {
|
|
321
341
|
throw new Error("The Clipboard API is unavailable.");
|
|
322
342
|
}
|
|
323
|
-
const dt = createDataTransfer();
|
|
343
|
+
const dt = createDataTransfer(window2);
|
|
324
344
|
for (const item of items) {
|
|
325
345
|
for (const type3 of item.types) {
|
|
326
|
-
dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b)));
|
|
346
|
+
dt.setData(type3, yield item.getType(type3).then((b) => readBlobText(b, window2.FileReader)));
|
|
327
347
|
}
|
|
328
348
|
}
|
|
329
349
|
return dt;
|
|
@@ -331,13 +351,13 @@ function readDataTransferFromClipboard(document2) {
|
|
|
331
351
|
}
|
|
332
352
|
function writeDataTransferToClipboard(document2, clipboardData) {
|
|
333
353
|
return __async(this, null, function* () {
|
|
334
|
-
|
|
335
|
-
const clipboard =
|
|
354
|
+
const window2 = getWindow(document2);
|
|
355
|
+
const clipboard = window2.navigator.clipboard;
|
|
336
356
|
const items = [];
|
|
337
357
|
for (let i = 0; i < clipboardData.items.length; i++) {
|
|
338
358
|
const dtItem = clipboardData.items[i];
|
|
339
|
-
const blob = getBlobFromDataTransferItem(dtItem);
|
|
340
|
-
items.push(createClipboardItem(blob));
|
|
359
|
+
const blob = getBlobFromDataTransferItem(window2, dtItem);
|
|
360
|
+
items.push(createClipboardItem(window2, blob));
|
|
341
361
|
}
|
|
342
362
|
const written = clipboard && (yield clipboard.write(items).then(() => true, () => false));
|
|
343
363
|
if (!written) {
|
|
@@ -352,6 +372,29 @@ if (typeof afterAll === "function") {
|
|
|
352
372
|
afterAll(() => detachClipboardStubFromView(window));
|
|
353
373
|
}
|
|
354
374
|
|
|
375
|
+
// src/utils/edit/isContentEditable.ts
|
|
376
|
+
function isContentEditable(element) {
|
|
377
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
378
|
+
}
|
|
379
|
+
function getContentEditable(node) {
|
|
380
|
+
const element = getElement(node);
|
|
381
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
382
|
+
}
|
|
383
|
+
function getElement(node) {
|
|
384
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/utils/edit/getValue.ts
|
|
388
|
+
function getValue(element) {
|
|
389
|
+
if (!element) {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
if (isContentEditable(element)) {
|
|
393
|
+
return element.textContent;
|
|
394
|
+
}
|
|
395
|
+
return getUIValue(element);
|
|
396
|
+
}
|
|
397
|
+
|
|
355
398
|
// src/utils/edit/buildTimeValue.ts
|
|
356
399
|
function buildTimeValue(value) {
|
|
357
400
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -383,21 +426,137 @@ function build(onlyDigitsValue, index) {
|
|
|
383
426
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
384
427
|
}
|
|
385
428
|
|
|
386
|
-
// src/utils/edit/
|
|
387
|
-
function
|
|
429
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
430
|
+
function isValidDateOrTimeValue(element, value) {
|
|
388
431
|
const clone = element.cloneNode();
|
|
389
432
|
clone.value = value;
|
|
390
433
|
return clone.value === value;
|
|
391
434
|
}
|
|
392
435
|
|
|
393
|
-
// src/utils/edit/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
436
|
+
// src/utils/edit/maxLength.ts
|
|
437
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
438
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
439
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
440
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
441
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
442
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
443
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
444
|
+
return maxLengthSupportedTypes2;
|
|
445
|
+
})(maxLengthSupportedTypes || {});
|
|
446
|
+
function getSpaceUntilMaxLength(element) {
|
|
447
|
+
const value = getValue(element);
|
|
448
|
+
if (value === null) {
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
452
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
453
|
+
}
|
|
454
|
+
function getSanitizedMaxLength(element) {
|
|
455
|
+
var _a3;
|
|
456
|
+
if (!supportsMaxLength(element)) {
|
|
457
|
+
return void 0;
|
|
458
|
+
}
|
|
459
|
+
const attr = (_a3 = element.getAttribute("maxlength")) != null ? _a3 : "";
|
|
460
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
461
|
+
}
|
|
462
|
+
function supportsMaxLength(element) {
|
|
463
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
398
464
|
}
|
|
399
465
|
|
|
400
|
-
// src/utils/edit/
|
|
466
|
+
// src/utils/edit/input.ts
|
|
467
|
+
function isDateOrTime(element) {
|
|
468
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
469
|
+
}
|
|
470
|
+
function input(config, element, data, inputType = "insertText") {
|
|
471
|
+
const inputRange = getInputRange(element);
|
|
472
|
+
if (!inputRange) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (!isDateOrTime(element)) {
|
|
476
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
477
|
+
inputType,
|
|
478
|
+
data
|
|
479
|
+
});
|
|
480
|
+
if (!unprevented) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if ("startContainer" in inputRange) {
|
|
485
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
486
|
+
} else {
|
|
487
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
491
|
+
let del = false;
|
|
492
|
+
if (!inputRange.collapsed) {
|
|
493
|
+
del = true;
|
|
494
|
+
inputRange.deleteContents();
|
|
495
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
496
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
497
|
+
if (nextPosition) {
|
|
498
|
+
del = true;
|
|
499
|
+
const delRange = inputRange.cloneRange();
|
|
500
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
501
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
502
|
+
} else {
|
|
503
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
504
|
+
}
|
|
505
|
+
delRange.deleteContents();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (data) {
|
|
509
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
510
|
+
const offset = inputRange.endOffset;
|
|
511
|
+
inputRange.endContainer.insertData(offset, data);
|
|
512
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
513
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
514
|
+
} else {
|
|
515
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
516
|
+
inputRange.insertNode(text);
|
|
517
|
+
inputRange.setStart(text, data.length);
|
|
518
|
+
inputRange.setEnd(text, data.length);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (del || data) {
|
|
522
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
526
|
+
let dataToInsert = data;
|
|
527
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
528
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
529
|
+
if (spaceUntilMaxLength > 0) {
|
|
530
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
531
|
+
} else {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
536
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
setUIValue(element, newValue);
|
|
543
|
+
setSelection({
|
|
544
|
+
focusNode: element,
|
|
545
|
+
anchorOffset: newOffset,
|
|
546
|
+
focusOffset: newOffset
|
|
547
|
+
});
|
|
548
|
+
if (isDateOrTime(element)) {
|
|
549
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
550
|
+
commitInput(config, element, newOffset, {});
|
|
551
|
+
dispatchUIEvent(config, element, "change");
|
|
552
|
+
}
|
|
553
|
+
} else {
|
|
554
|
+
commitInput(config, element, newOffset, {
|
|
555
|
+
data,
|
|
556
|
+
inputType
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
401
560
|
function calculateNewValue(inputData, node, {
|
|
402
561
|
startOffset,
|
|
403
562
|
endOffset
|
|
@@ -408,15 +567,12 @@ function calculateNewValue(inputData, node, {
|
|
|
408
567
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
409
568
|
const epilog = value.substring(epilogStart, value.length);
|
|
410
569
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
411
|
-
|
|
412
|
-
if (node
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
newValue = inputData;
|
|
418
|
-
} else {
|
|
419
|
-
newValue = value;
|
|
570
|
+
let newOffset = prologEnd + inputData.length;
|
|
571
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
572
|
+
const builtValue = buildTimeValue(newValue);
|
|
573
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
574
|
+
newValue = builtValue;
|
|
575
|
+
newOffset = builtValue.length;
|
|
420
576
|
}
|
|
421
577
|
}
|
|
422
578
|
return {
|
|
@@ -425,17 +581,21 @@ function calculateNewValue(inputData, node, {
|
|
|
425
581
|
newOffset
|
|
426
582
|
};
|
|
427
583
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
584
|
+
function commitInput(config, element, newOffset, inputInit) {
|
|
585
|
+
startTrackValue(element);
|
|
586
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
587
|
+
if (endTrackValue(element)) {
|
|
588
|
+
setSelection({
|
|
589
|
+
focusNode: element,
|
|
590
|
+
anchorOffset: newOffset,
|
|
591
|
+
focusOffset: newOffset
|
|
592
|
+
});
|
|
593
|
+
}
|
|
436
594
|
}
|
|
437
|
-
function
|
|
438
|
-
|
|
595
|
+
function isValidNumberInput(value) {
|
|
596
|
+
var _a3, _b;
|
|
597
|
+
const valueParts = value.split("e", 2);
|
|
598
|
+
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]));
|
|
439
599
|
}
|
|
440
600
|
|
|
441
601
|
// src/utils/edit/isEditable.ts
|
|
@@ -461,157 +621,123 @@ function isEditableInput(element) {
|
|
|
461
621
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
462
622
|
}
|
|
463
623
|
|
|
464
|
-
// src/utils/
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
focusNode: element.firstChild,
|
|
477
|
-
anchorOffset,
|
|
478
|
-
focusOffset
|
|
624
|
+
// src/utils/edit/setFiles.ts
|
|
625
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
626
|
+
function setFiles(el, files) {
|
|
627
|
+
var _a3;
|
|
628
|
+
(_a3 = el[fakeFiles]) == null ? void 0 : _a3.restore();
|
|
629
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
630
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
631
|
+
function restore() {
|
|
632
|
+
Object.defineProperties(el, {
|
|
633
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
634
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
635
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
479
636
|
});
|
|
480
637
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
498
|
-
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
499
|
-
return {
|
|
500
|
-
type: isCE ? "contenteditable" : "default",
|
|
501
|
-
selection
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
function getElement2(node) {
|
|
505
|
-
return node.nodeType === 1 ? node : node.parentElement;
|
|
506
|
-
}
|
|
507
|
-
function updateSelectionOnFocus(element) {
|
|
508
|
-
var _a;
|
|
509
|
-
const selection = element.ownerDocument.getSelection();
|
|
510
|
-
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (hasOwnSelection(element)) {
|
|
514
|
-
const contenteditable = getContentEditable(selection.focusNode);
|
|
515
|
-
if (contenteditable) {
|
|
516
|
-
if (!selection.isCollapsed) {
|
|
517
|
-
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
518
|
-
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
638
|
+
el[fakeFiles] = { restore };
|
|
639
|
+
Object.defineProperties(el, {
|
|
640
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
641
|
+
get: () => files
|
|
642
|
+
}),
|
|
643
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
644
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
645
|
+
set(v) {
|
|
646
|
+
var _a4;
|
|
647
|
+
if (v === "") {
|
|
648
|
+
restore();
|
|
649
|
+
} else {
|
|
650
|
+
(_a4 = objectDescriptors.value.set) == null ? void 0 : _a4.call(el, v);
|
|
651
|
+
}
|
|
519
652
|
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
} else if (typeAndSelection.type === "contenteditable") {
|
|
531
|
-
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
function setSelection({
|
|
535
|
-
focusNode,
|
|
536
|
-
focusOffset,
|
|
537
|
-
anchorNode = focusNode,
|
|
538
|
-
anchorOffset = focusOffset
|
|
539
|
-
}) {
|
|
540
|
-
var _a, _b;
|
|
541
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
542
|
-
if (typeAndSelection.type === "input") {
|
|
543
|
-
return setUISelection(focusNode, {
|
|
544
|
-
anchorOffset,
|
|
545
|
-
focusOffset
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
653
|
+
}),
|
|
654
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
655
|
+
set(v) {
|
|
656
|
+
if (v !== "file") {
|
|
657
|
+
restore();
|
|
658
|
+
el.type = v;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
})
|
|
662
|
+
});
|
|
549
663
|
}
|
|
550
664
|
|
|
551
|
-
// src/utils/
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const oldValue = element.value;
|
|
558
|
-
setUIValue(element, newValue);
|
|
559
|
-
setSelection({
|
|
560
|
-
focusNode: newSelection.node,
|
|
561
|
-
anchorOffset: newSelection.offset,
|
|
562
|
-
focusOffset: newSelection.offset
|
|
665
|
+
// src/utils/misc/eventWrapper.ts
|
|
666
|
+
import { getConfig } from "@testing-library/dom";
|
|
667
|
+
function eventWrapper(cb) {
|
|
668
|
+
let result;
|
|
669
|
+
getConfig().eventWrapper(() => {
|
|
670
|
+
result = cb();
|
|
563
671
|
});
|
|
564
|
-
|
|
565
|
-
dispatchUIEvent(config, element, "input", eventOverrides);
|
|
566
|
-
const tracked = endTrackValue(element);
|
|
567
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
568
|
-
setSelection({
|
|
569
|
-
focusNode: newSelection.node,
|
|
570
|
-
anchorOffset: newSelection.offset,
|
|
571
|
-
focusOffset: newSelection.offset
|
|
572
|
-
});
|
|
573
|
-
}
|
|
672
|
+
return result;
|
|
574
673
|
}
|
|
575
674
|
|
|
576
|
-
// src/utils/
|
|
577
|
-
function
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
675
|
+
// src/utils/misc/isDisabled.ts
|
|
676
|
+
function isDisabled(element) {
|
|
677
|
+
var _a3;
|
|
678
|
+
for (let el = element; el; el = el.parentElement) {
|
|
679
|
+
if (isElementType(el, [
|
|
680
|
+
"button",
|
|
681
|
+
"input",
|
|
682
|
+
"select",
|
|
683
|
+
"textarea",
|
|
684
|
+
"optgroup",
|
|
685
|
+
"option"
|
|
686
|
+
])) {
|
|
687
|
+
if (el.hasAttribute("disabled")) {
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
} else if (isElementType(el, "fieldset")) {
|
|
691
|
+
if (el.hasAttribute("disabled") && !((_a3 = el.querySelector(":scope > legend")) == null ? void 0 : _a3.contains(element))) {
|
|
692
|
+
return true;
|
|
693
|
+
}
|
|
694
|
+
} else if (el.tagName.includes("-")) {
|
|
695
|
+
if (el.constructor.formAssociated && el.hasAttribute("disabled")) {
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
583
699
|
}
|
|
584
|
-
return
|
|
700
|
+
return false;
|
|
585
701
|
}
|
|
586
702
|
|
|
587
|
-
// src/utils/
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
function getSpaceUntilMaxLength(element) {
|
|
598
|
-
const value = getValue(element);
|
|
599
|
-
if (value === null) {
|
|
600
|
-
return void 0;
|
|
703
|
+
// src/utils/focus/getActiveElement.ts
|
|
704
|
+
function getActiveElement(document2) {
|
|
705
|
+
const activeElement = document2.activeElement;
|
|
706
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
707
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
708
|
+
} else {
|
|
709
|
+
if (isDisabled(activeElement)) {
|
|
710
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
711
|
+
}
|
|
712
|
+
return activeElement;
|
|
601
713
|
}
|
|
602
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
603
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
604
714
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
715
|
+
|
|
716
|
+
// src/utils/focus/selector.ts
|
|
717
|
+
var FOCUSABLE_SELECTOR = [
|
|
718
|
+
"input:not([type=hidden]):not([disabled])",
|
|
719
|
+
"button:not([disabled])",
|
|
720
|
+
"select:not([disabled])",
|
|
721
|
+
"textarea:not([disabled])",
|
|
722
|
+
'[contenteditable=""]',
|
|
723
|
+
'[contenteditable="true"]',
|
|
724
|
+
"a[href]",
|
|
725
|
+
"[tabindex]:not([disabled])"
|
|
726
|
+
].join(", ");
|
|
727
|
+
|
|
728
|
+
// src/utils/focus/isFocusable.ts
|
|
729
|
+
function isFocusable(element) {
|
|
730
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
612
731
|
}
|
|
613
|
-
|
|
614
|
-
|
|
732
|
+
|
|
733
|
+
// src/utils/focus/blur.ts
|
|
734
|
+
function blur(element) {
|
|
735
|
+
if (!isFocusable(element))
|
|
736
|
+
return;
|
|
737
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
738
|
+
if (!wasActive)
|
|
739
|
+
return;
|
|
740
|
+
eventWrapper(() => element.blur());
|
|
615
741
|
}
|
|
616
742
|
|
|
617
743
|
// src/utils/focus/cursor.ts
|
|
@@ -662,7 +788,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
662
788
|
}
|
|
663
789
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
664
790
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
665
|
-
if (offset !== void 0 &&
|
|
791
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
666
792
|
node = node.children[nextOffset];
|
|
667
793
|
}
|
|
668
794
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -671,7 +797,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
671
797
|
if (isTextNode(node)) {
|
|
672
798
|
return true;
|
|
673
799
|
}
|
|
674
|
-
if (
|
|
800
|
+
if (isElement(node)) {
|
|
675
801
|
if (isElementType(node, ["input", "textarea"])) {
|
|
676
802
|
return node.type !== "hidden";
|
|
677
803
|
} else if (isElementType(node, "br")) {
|
|
@@ -688,14 +814,14 @@ function getOffset(node) {
|
|
|
688
814
|
}
|
|
689
815
|
return i;
|
|
690
816
|
}
|
|
691
|
-
function
|
|
817
|
+
function isElement(node) {
|
|
692
818
|
return node.nodeType === 1;
|
|
693
819
|
}
|
|
694
820
|
function isTextNode(node) {
|
|
695
821
|
return node.nodeType === 3;
|
|
696
822
|
}
|
|
697
823
|
function walkNodes(node, direction, callback) {
|
|
698
|
-
var
|
|
824
|
+
var _a3;
|
|
699
825
|
for (; ; ) {
|
|
700
826
|
const sibling = node[`${direction}Sibling`];
|
|
701
827
|
if (sibling) {
|
|
@@ -703,7 +829,7 @@ function walkNodes(node, direction, callback) {
|
|
|
703
829
|
if (callback(node)) {
|
|
704
830
|
return node;
|
|
705
831
|
}
|
|
706
|
-
} else if (node.parentNode && (!
|
|
832
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a3 = node.ownerDocument) == null ? void 0 : _a3.body))) {
|
|
707
833
|
node = node.parentNode;
|
|
708
834
|
} else {
|
|
709
835
|
break;
|
|
@@ -717,173 +843,122 @@ function getDescendant(node, direction) {
|
|
|
717
843
|
return node;
|
|
718
844
|
}
|
|
719
845
|
|
|
720
|
-
// src/utils/
|
|
721
|
-
function
|
|
722
|
-
|
|
723
|
-
if (
|
|
724
|
-
return
|
|
846
|
+
// src/utils/focus/selection.ts
|
|
847
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
848
|
+
var _a3;
|
|
849
|
+
if (hasOwnSelection(element)) {
|
|
850
|
+
return setSelection({
|
|
851
|
+
focusNode: element,
|
|
852
|
+
anchorOffset,
|
|
853
|
+
focusOffset
|
|
854
|
+
});
|
|
725
855
|
}
|
|
726
|
-
if (
|
|
727
|
-
return {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
if (data) {
|
|
747
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
748
|
-
const offset = inputRange.endOffset;
|
|
749
|
-
inputRange.endContainer.insertData(offset, data);
|
|
750
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
751
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
752
|
-
} else {
|
|
753
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
754
|
-
inputRange.insertNode(text);
|
|
755
|
-
inputRange.setStart(text, data.length);
|
|
756
|
-
inputRange.setEnd(text, data.length);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
if (del || data) {
|
|
760
|
-
dispatchUIEvent(config, element, "input", { inputType });
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
} else {
|
|
856
|
+
if (isContentEditable(element) && ((_a3 = element.firstChild) == null ? void 0 : _a3.nodeType) === 3) {
|
|
857
|
+
return setSelection({
|
|
858
|
+
focusNode: element.firstChild,
|
|
859
|
+
anchorOffset,
|
|
860
|
+
focusOffset
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
864
|
+
}
|
|
865
|
+
function hasOwnSelection(node) {
|
|
866
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
867
|
+
}
|
|
868
|
+
function isElement2(node) {
|
|
869
|
+
return node.nodeType === 1;
|
|
870
|
+
}
|
|
871
|
+
function getTargetTypeAndSelection(node) {
|
|
872
|
+
const element = getElement2(node);
|
|
873
|
+
if (element && hasOwnSelection(element)) {
|
|
765
874
|
return {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
|
|
769
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
editInputElement(config, element, {
|
|
773
|
-
newValue,
|
|
774
|
-
newSelection: {
|
|
775
|
-
node: element,
|
|
776
|
-
offset: newOffset
|
|
777
|
-
},
|
|
778
|
-
eventOverrides: {
|
|
779
|
-
inputType
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
}
|
|
875
|
+
type: "input",
|
|
876
|
+
selection: getUISelection(element)
|
|
783
877
|
};
|
|
784
878
|
}
|
|
879
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
880
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
881
|
+
return {
|
|
882
|
+
type: isCE ? "contenteditable" : "default",
|
|
883
|
+
selection
|
|
884
|
+
};
|
|
785
885
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
function
|
|
790
|
-
var
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
function restore() {
|
|
795
|
-
Object.defineProperties(el, {
|
|
796
|
-
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
797
|
-
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
798
|
-
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
799
|
-
});
|
|
886
|
+
function getElement2(node) {
|
|
887
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
888
|
+
}
|
|
889
|
+
function updateSelectionOnFocus(element) {
|
|
890
|
+
var _a3;
|
|
891
|
+
const selection = element.ownerDocument.getSelection();
|
|
892
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
893
|
+
return;
|
|
800
894
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
808
|
-
set(v) {
|
|
809
|
-
var _a2;
|
|
810
|
-
if (v === "") {
|
|
811
|
-
restore();
|
|
812
|
-
} else {
|
|
813
|
-
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}),
|
|
817
|
-
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
818
|
-
set(v) {
|
|
819
|
-
if (v !== "file") {
|
|
820
|
-
restore();
|
|
821
|
-
el.type = v;
|
|
822
|
-
}
|
|
895
|
+
if (hasOwnSelection(element)) {
|
|
896
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
897
|
+
if (contenteditable) {
|
|
898
|
+
if (!selection.isCollapsed) {
|
|
899
|
+
const focusNode = ((_a3 = contenteditable.firstChild) == null ? void 0 : _a3.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
900
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
823
901
|
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
// src/utils/misc/eventWrapper.ts
|
|
829
|
-
import { getConfig } from "@testing-library/dom";
|
|
830
|
-
function eventWrapper(cb) {
|
|
831
|
-
let result;
|
|
832
|
-
getConfig().eventWrapper(() => {
|
|
833
|
-
result = cb();
|
|
834
|
-
});
|
|
835
|
-
return result;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// src/utils/misc/isDisabled.ts
|
|
839
|
-
function isDisabled(element) {
|
|
840
|
-
return Boolean(element && element.disabled);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
// src/utils/focus/getActiveElement.ts
|
|
844
|
-
function getActiveElement(document2) {
|
|
845
|
-
const activeElement = document2.activeElement;
|
|
846
|
-
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
847
|
-
return getActiveElement(activeElement.shadowRoot);
|
|
848
|
-
} else {
|
|
849
|
-
if (isDisabled(activeElement)) {
|
|
850
|
-
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
902
|
+
} else {
|
|
903
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
851
904
|
}
|
|
852
|
-
return activeElement;
|
|
853
905
|
}
|
|
854
906
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
"input
|
|
859
|
-
|
|
860
|
-
"
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
907
|
+
function getInputRange(focusNode) {
|
|
908
|
+
var _a3;
|
|
909
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
910
|
+
if (typeAndSelection.type === "input") {
|
|
911
|
+
return typeAndSelection.selection;
|
|
912
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
913
|
+
return (_a3 = typeAndSelection.selection) == null ? void 0 : _a3.getRangeAt(0);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function setSelection({
|
|
917
|
+
focusNode,
|
|
918
|
+
focusOffset,
|
|
919
|
+
anchorNode = focusNode,
|
|
920
|
+
anchorOffset = focusOffset
|
|
921
|
+
}) {
|
|
922
|
+
var _a3, _b;
|
|
923
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
924
|
+
if (typeAndSelection.type === "input") {
|
|
925
|
+
return setUISelection(focusNode, {
|
|
926
|
+
anchorOffset,
|
|
927
|
+
focusOffset
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
(_b = (_a3 = anchorNode.ownerDocument) == null ? void 0 : _a3.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
871
931
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
932
|
+
function moveSelection(node, direction) {
|
|
933
|
+
if (hasOwnSelection(node)) {
|
|
934
|
+
const selection = getUISelection(node);
|
|
935
|
+
setSelection({
|
|
936
|
+
focusNode: node,
|
|
937
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
938
|
+
});
|
|
939
|
+
} else {
|
|
940
|
+
const selection = node.ownerDocument.getSelection();
|
|
941
|
+
if (!selection) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
if (selection.isCollapsed) {
|
|
945
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
946
|
+
if (nextPosition) {
|
|
947
|
+
setSelection({
|
|
948
|
+
focusNode: nextPosition.node,
|
|
949
|
+
focusOffset: nextPosition.offset
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
} else {
|
|
953
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
881
956
|
}
|
|
882
957
|
|
|
883
958
|
// src/utils/focus/copySelection.ts
|
|
884
959
|
function copySelection(target) {
|
|
885
960
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
886
|
-
const dt = createDataTransfer();
|
|
961
|
+
const dt = createDataTransfer(getWindow(target));
|
|
887
962
|
for (const type3 in data) {
|
|
888
963
|
if (data[type3]) {
|
|
889
964
|
dt.setData(type3, data[type3]);
|
|
@@ -924,9 +999,8 @@ function focus(element) {
|
|
|
924
999
|
}
|
|
925
1000
|
|
|
926
1001
|
// src/utils/misc/isVisible.ts
|
|
927
|
-
import { getWindowFromNode } from "@testing-library/dom/dist/helpers.js";
|
|
928
1002
|
function isVisible(element) {
|
|
929
|
-
const window2 =
|
|
1003
|
+
const window2 = getWindow(element);
|
|
930
1004
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
931
1005
|
const { display, visibility } = window2.getComputedStyle(el);
|
|
932
1006
|
if (display === "none") {
|
|
@@ -992,7 +1066,7 @@ function getTabDestination(activeElement, shift) {
|
|
|
992
1066
|
|
|
993
1067
|
// src/utils/focus/selectAll.ts
|
|
994
1068
|
function selectAll(target) {
|
|
995
|
-
var
|
|
1069
|
+
var _a3;
|
|
996
1070
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
997
1071
|
return setSelection({
|
|
998
1072
|
focusNode: target,
|
|
@@ -1000,7 +1074,7 @@ function selectAll(target) {
|
|
|
1000
1074
|
focusOffset: getUIValue(target).length
|
|
1001
1075
|
});
|
|
1002
1076
|
}
|
|
1003
|
-
const focusNode = (
|
|
1077
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1004
1078
|
setSelection({
|
|
1005
1079
|
focusNode,
|
|
1006
1080
|
anchorOffset: 0,
|
|
@@ -1008,11 +1082,11 @@ function selectAll(target) {
|
|
|
1008
1082
|
});
|
|
1009
1083
|
}
|
|
1010
1084
|
function isAllSelected(target) {
|
|
1011
|
-
var
|
|
1085
|
+
var _a3;
|
|
1012
1086
|
if (isElementType(target, "textarea") || isElementType(target, "input") && target.type in editableInputTypes) {
|
|
1013
1087
|
return getUISelection(target).startOffset === 0 && getUISelection(target).endOffset === getUIValue(target).length;
|
|
1014
1088
|
}
|
|
1015
|
-
const focusNode = (
|
|
1089
|
+
const focusNode = (_a3 = getContentEditable(target)) != null ? _a3 : target.ownerDocument.body;
|
|
1016
1090
|
const selection = target.ownerDocument.getSelection();
|
|
1017
1091
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1018
1092
|
}
|
|
@@ -1049,7 +1123,7 @@ var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
|
1049
1123
|
bracketDict2["["] = "]";
|
|
1050
1124
|
return bracketDict2;
|
|
1051
1125
|
})(bracketDict || {});
|
|
1052
|
-
function readNextDescriptor(text) {
|
|
1126
|
+
function readNextDescriptor(text, context) {
|
|
1053
1127
|
let pos = 0;
|
|
1054
1128
|
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
1055
1129
|
pos += startBracket.length;
|
|
@@ -1057,11 +1131,11 @@ function readNextDescriptor(text) {
|
|
|
1057
1131
|
const type3 = isEscapedChar ? "" : startBracket;
|
|
1058
1132
|
return __spreadValues({
|
|
1059
1133
|
type: type3
|
|
1060
|
-
}, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
|
|
1134
|
+
}, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
|
|
1061
1135
|
}
|
|
1062
|
-
function readPrintableChar(text, pos) {
|
|
1136
|
+
function readPrintableChar(text, pos, context) {
|
|
1063
1137
|
const descriptor = text[pos];
|
|
1064
|
-
assertDescriptor(descriptor, text, pos);
|
|
1138
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1065
1139
|
pos += descriptor.length;
|
|
1066
1140
|
return {
|
|
1067
1141
|
consumedLength: pos,
|
|
@@ -1071,14 +1145,14 @@ function readPrintableChar(text, pos) {
|
|
|
1071
1145
|
repeat: 1
|
|
1072
1146
|
};
|
|
1073
1147
|
}
|
|
1074
|
-
function readTag(text, pos, startBracket) {
|
|
1075
|
-
var
|
|
1148
|
+
function readTag(text, pos, startBracket, context) {
|
|
1149
|
+
var _a3, _b, _c;
|
|
1076
1150
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1077
1151
|
pos += releasePreviousModifier.length;
|
|
1078
1152
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1079
1153
|
pos += Number(escapedDescriptor);
|
|
1080
|
-
const descriptor = escapedDescriptor ? text[pos] : (
|
|
1081
|
-
assertDescriptor(descriptor, text, pos);
|
|
1154
|
+
const descriptor = escapedDescriptor ? text[pos] : (_a3 = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a3[0];
|
|
1155
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1082
1156
|
pos += descriptor.length;
|
|
1083
1157
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
1084
1158
|
pos += repeatModifier.length;
|
|
@@ -1091,7 +1165,7 @@ function readTag(text, pos, startBracket) {
|
|
|
1091
1165
|
!repeatModifier && "repeat modifier",
|
|
1092
1166
|
!releaseSelfModifier && "release modifier",
|
|
1093
1167
|
`"${expectedEndBracket}"`
|
|
1094
|
-
].filter(Boolean).join(" or "), text[pos], text));
|
|
1168
|
+
].filter(Boolean).join(" or "), text[pos], text, context));
|
|
1095
1169
|
}
|
|
1096
1170
|
pos += endBracket.length;
|
|
1097
1171
|
return {
|
|
@@ -1102,9 +1176,9 @@ function readTag(text, pos, startBracket) {
|
|
|
1102
1176
|
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
1103
1177
|
};
|
|
1104
1178
|
}
|
|
1105
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
1179
|
+
function assertDescriptor(descriptor, text, pos, context) {
|
|
1106
1180
|
if (!descriptor) {
|
|
1107
|
-
throw new Error(getErrorMessage("key descriptor", text[pos], text));
|
|
1181
|
+
throw new Error(getErrorMessage("key descriptor", text[pos], text, context));
|
|
1108
1182
|
}
|
|
1109
1183
|
}
|
|
1110
1184
|
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
@@ -1115,9 +1189,9 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
1115
1189
|
return false;
|
|
1116
1190
|
}
|
|
1117
1191
|
}
|
|
1118
|
-
function getErrorMessage(expected, found, text) {
|
|
1192
|
+
function getErrorMessage(expected, found, text, context) {
|
|
1119
1193
|
return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
|
|
1120
|
-
See https://
|
|
1194
|
+
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`}
|
|
1121
1195
|
for more information about how userEvent parses your input.`;
|
|
1122
1196
|
}
|
|
1123
1197
|
|
|
@@ -1149,13 +1223,13 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1149
1223
|
// src/utils/misc/level.ts
|
|
1150
1224
|
var Level = Symbol("Api level refs");
|
|
1151
1225
|
function setLevelRef(config, level) {
|
|
1152
|
-
var
|
|
1153
|
-
(
|
|
1226
|
+
var _a3;
|
|
1227
|
+
(_a3 = config[Level]) != null ? _a3 : config[Level] = {};
|
|
1154
1228
|
config[Level][level] = {};
|
|
1155
1229
|
}
|
|
1156
1230
|
function getLevelRef(config, level) {
|
|
1157
|
-
var
|
|
1158
|
-
return (
|
|
1231
|
+
var _a3;
|
|
1232
|
+
return (_a3 = config[Level]) == null ? void 0 : _a3[level];
|
|
1159
1233
|
}
|
|
1160
1234
|
|
|
1161
1235
|
// src/utils/misc/wait.ts
|
|
@@ -1163,12 +1237,6 @@ function wait(time) {
|
|
|
1163
1237
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1164
1238
|
}
|
|
1165
1239
|
|
|
1166
|
-
// src/utils/misc/hasFormSubmit.ts
|
|
1167
|
-
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1168
|
-
|
|
1169
|
-
// src/utils/pointer/cssPointerEvents.ts
|
|
1170
|
-
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1171
|
-
|
|
1172
1240
|
// src/keyboard/keyMap.ts
|
|
1173
1241
|
var defaultKeyMap = [
|
|
1174
1242
|
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
@@ -1262,7 +1330,7 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1262
1330
|
|
|
1263
1331
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1264
1332
|
function hasPointerEvents(element) {
|
|
1265
|
-
const window2 =
|
|
1333
|
+
const window2 = getWindow(element);
|
|
1266
1334
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
1267
1335
|
const pointerEvents = window2.getComputedStyle(el).pointerEvents;
|
|
1268
1336
|
if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
|
|
@@ -1325,13 +1393,22 @@ function getMouseButtons(...buttons) {
|
|
|
1325
1393
|
|
|
1326
1394
|
// src/event/createEvent.ts
|
|
1327
1395
|
import { createEvent as createEventBase } from "@testing-library/dom";
|
|
1328
|
-
|
|
1396
|
+
|
|
1397
|
+
// src/event/eventMap.ts
|
|
1398
|
+
import { eventMap as baseEventMap } from "@testing-library/dom/dist/event-map.js";
|
|
1399
|
+
var eventMap = __spreadProps(__spreadValues({}, baseEventMap), {
|
|
1400
|
+
beforeInput: {
|
|
1401
|
+
EventType: "InputEvent",
|
|
1402
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1329
1406
|
|
|
1330
1407
|
// src/event/eventTypes.ts
|
|
1331
|
-
import { eventMap } from "@testing-library/dom/dist/event-map.js";
|
|
1332
|
-
var eventKeys = Object.fromEntries(Object.keys(
|
|
1408
|
+
import { eventMap as eventMap2 } from "@testing-library/dom/dist/event-map.js";
|
|
1409
|
+
var eventKeys = Object.fromEntries(Object.keys(eventMap2).map((k) => [k.toLowerCase(), k]));
|
|
1333
1410
|
function getEventClass(type3) {
|
|
1334
|
-
return
|
|
1411
|
+
return type3 in eventKeys ? eventMap2[eventKeys[type3]].EventType : "Event";
|
|
1335
1412
|
}
|
|
1336
1413
|
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1337
1414
|
function isMouseEvent(type3) {
|
|
@@ -1343,8 +1420,7 @@ function isKeyboardEvent(type3) {
|
|
|
1343
1420
|
|
|
1344
1421
|
// src/event/createEvent.ts
|
|
1345
1422
|
function createEvent(type3, target, init) {
|
|
1346
|
-
const
|
|
1347
|
-
const event = createEventBase[eventKey](target, init);
|
|
1423
|
+
const event = createEventBase(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1348
1424
|
if (isMouseEvent(type3) && init) {
|
|
1349
1425
|
assignPositionInit(event, init);
|
|
1350
1426
|
assignPointerInit(event, init);
|
|
@@ -1368,9 +1444,9 @@ function assignPositionInit(obj, {
|
|
|
1368
1444
|
screenX,
|
|
1369
1445
|
screenY
|
|
1370
1446
|
}) {
|
|
1371
|
-
var
|
|
1447
|
+
var _a3, _b, _c, _d;
|
|
1372
1448
|
assignProps(obj, {
|
|
1373
|
-
x: (
|
|
1449
|
+
x: (_a3 = x != null ? x : clientX) != null ? _a3 : 0,
|
|
1374
1450
|
y: (_b = y != null ? y : clientY) != null ? _b : 0,
|
|
1375
1451
|
clientX: (_c = x != null ? x : clientX) != null ? _c : 0,
|
|
1376
1452
|
clientY: (_d = y != null ? y : clientY) != null ? _d : 0,
|
|
@@ -1395,8 +1471,8 @@ var behavior = {};
|
|
|
1395
1471
|
|
|
1396
1472
|
// src/event/behavior/click.ts
|
|
1397
1473
|
behavior.click = (event, target, config) => {
|
|
1398
|
-
|
|
1399
|
-
const control =
|
|
1474
|
+
const context = target.closest("button,input,label,select,textarea");
|
|
1475
|
+
const control = context && isElementType(context, "label") && context.control;
|
|
1400
1476
|
if (control) {
|
|
1401
1477
|
return () => {
|
|
1402
1478
|
if (isFocusable(control)) {
|
|
@@ -1407,17 +1483,175 @@ behavior.click = (event, target, config) => {
|
|
|
1407
1483
|
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1408
1484
|
return () => {
|
|
1409
1485
|
blur(target);
|
|
1410
|
-
target.dispatchEvent(new Event("fileDialog"));
|
|
1486
|
+
target.dispatchEvent(new (getWindow(target)).Event("fileDialog"));
|
|
1411
1487
|
focus(target);
|
|
1412
1488
|
};
|
|
1413
1489
|
}
|
|
1414
1490
|
};
|
|
1415
1491
|
|
|
1492
|
+
// src/event/behavior/cut.ts
|
|
1493
|
+
behavior.cut = (event, target, config) => {
|
|
1494
|
+
return () => {
|
|
1495
|
+
if (isEditable(target)) {
|
|
1496
|
+
input(config, target, "", "deleteByCut");
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
// src/event/behavior/keydown.ts
|
|
1502
|
+
behavior.keydown = (event, target, config) => {
|
|
1503
|
+
var _a3, _b;
|
|
1504
|
+
return (_b = (_a3 = keydownBehavior[event.key]) == null ? void 0 : _a3.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1505
|
+
};
|
|
1506
|
+
var keydownBehavior = {
|
|
1507
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1508
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1509
|
+
Backspace: (event, target, config) => {
|
|
1510
|
+
if (isEditable(target)) {
|
|
1511
|
+
return () => {
|
|
1512
|
+
input(config, target, "", "deleteContentBackward");
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
},
|
|
1516
|
+
Delete: (event, target, config) => {
|
|
1517
|
+
if (isEditable(target)) {
|
|
1518
|
+
return () => {
|
|
1519
|
+
input(config, target, "", "deleteContentForward");
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
End: (event, target) => {
|
|
1524
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1525
|
+
return () => {
|
|
1526
|
+
var _a3, _b;
|
|
1527
|
+
const newPos = (_b = (_a3 = getValue(target)) == null ? void 0 : _a3.length) != null ? _b : 0;
|
|
1528
|
+
setSelectionRange(target, newPos, newPos);
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
},
|
|
1532
|
+
Home: (event, target) => {
|
|
1533
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1534
|
+
return () => {
|
|
1535
|
+
setSelectionRange(target, 0, 0);
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
},
|
|
1539
|
+
PageDown: (event, target) => {
|
|
1540
|
+
if (isElementType(target, ["input"])) {
|
|
1541
|
+
return () => {
|
|
1542
|
+
const newPos = getValue(target).length;
|
|
1543
|
+
setSelectionRange(target, newPos, newPos);
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
},
|
|
1547
|
+
PageUp: (event, target) => {
|
|
1548
|
+
if (isElementType(target, ["input"])) {
|
|
1549
|
+
return () => {
|
|
1550
|
+
setSelectionRange(target, 0, 0);
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
},
|
|
1554
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1555
|
+
return () => {
|
|
1556
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1557
|
+
focus(dest);
|
|
1558
|
+
if (hasOwnSelection(dest)) {
|
|
1559
|
+
setUISelection(dest, {
|
|
1560
|
+
anchorOffset: 0,
|
|
1561
|
+
focusOffset: dest.value.length
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
var combinationBehavior = (event, target, config) => {
|
|
1568
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1569
|
+
return () => selectAll(target);
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
|
|
1573
|
+
// src/event/behavior/keypress.ts
|
|
1574
|
+
behavior.keypress = (event, target, config) => {
|
|
1575
|
+
if (event.key === "Enter") {
|
|
1576
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1577
|
+
return () => {
|
|
1578
|
+
dispatchUIEvent(config, target, "click");
|
|
1579
|
+
};
|
|
1580
|
+
} else if (isElementType(target, "input")) {
|
|
1581
|
+
const form = target.form;
|
|
1582
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1583
|
+
if (submit) {
|
|
1584
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1585
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1586
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1587
|
+
} else {
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if (isEditable(target)) {
|
|
1593
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1594
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1595
|
+
return () => input(config, target, inputData, inputType);
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
var ClickInputOnEnter = [
|
|
1599
|
+
"button",
|
|
1600
|
+
"color",
|
|
1601
|
+
"file",
|
|
1602
|
+
"image",
|
|
1603
|
+
"reset",
|
|
1604
|
+
"submit"
|
|
1605
|
+
];
|
|
1606
|
+
var SubmitSingleInputOnEnter = [
|
|
1607
|
+
"email",
|
|
1608
|
+
"month",
|
|
1609
|
+
"password",
|
|
1610
|
+
"search",
|
|
1611
|
+
"tel",
|
|
1612
|
+
"text",
|
|
1613
|
+
"url",
|
|
1614
|
+
"week"
|
|
1615
|
+
];
|
|
1616
|
+
|
|
1617
|
+
// src/event/behavior/keyup.ts
|
|
1618
|
+
behavior.keyup = (event, target, config) => {
|
|
1619
|
+
var _a3;
|
|
1620
|
+
return (_a3 = keyupBehavior[event.key]) == null ? void 0 : _a3.call(keyupBehavior, event, target, config);
|
|
1621
|
+
};
|
|
1622
|
+
var keyupBehavior = {
|
|
1623
|
+
" ": (event, target, config) => {
|
|
1624
|
+
if (isClickableInput(target)) {
|
|
1625
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
// src/event/behavior/paste.ts
|
|
1631
|
+
behavior.paste = (event, target, config) => {
|
|
1632
|
+
if (isEditable(target)) {
|
|
1633
|
+
return () => {
|
|
1634
|
+
var _a3;
|
|
1635
|
+
const insertData = (_a3 = event.clipboardData) == null ? void 0 : _a3.getData("text");
|
|
1636
|
+
if (insertData) {
|
|
1637
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
// src/event/wrapEvent.ts
|
|
1644
|
+
import { getConfig as getConfig2 } from "@testing-library/dom";
|
|
1645
|
+
function wrapEvent(cb, _element) {
|
|
1646
|
+
return getConfig2().eventWrapper(cb);
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1416
1649
|
// src/event/dispatchEvent.ts
|
|
1417
|
-
function dispatchEvent(config, target, event) {
|
|
1418
|
-
var
|
|
1650
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1651
|
+
var _a3, _b;
|
|
1419
1652
|
const type3 = event.type;
|
|
1420
|
-
const behaviorImplementation =
|
|
1653
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1654
|
+
} : (_b = (_a3 = behavior)[type3]) == null ? void 0 : _b.call(_a3, event, target, config);
|
|
1421
1655
|
if (behaviorImplementation) {
|
|
1422
1656
|
event.preventDefault();
|
|
1423
1657
|
let defaultPrevented = false;
|
|
@@ -1429,28 +1663,22 @@ function dispatchEvent(config, target, event) {
|
|
|
1429
1663
|
defaultPrevented = event.cancelable;
|
|
1430
1664
|
}
|
|
1431
1665
|
});
|
|
1432
|
-
target.dispatchEvent(event);
|
|
1666
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1433
1667
|
if (!defaultPrevented) {
|
|
1434
1668
|
behaviorImplementation();
|
|
1435
1669
|
}
|
|
1436
1670
|
return !defaultPrevented;
|
|
1437
1671
|
}
|
|
1438
|
-
return target.dispatchEvent(event);
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
// src/event/wrapEvent.ts
|
|
1442
|
-
import { getConfig as getConfig2 } from "@testing-library/dom";
|
|
1443
|
-
function wrapEvent(cb, _element) {
|
|
1444
|
-
return getConfig2().eventWrapper(cb);
|
|
1672
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1445
1673
|
}
|
|
1446
1674
|
|
|
1447
1675
|
// src/event/index.ts
|
|
1448
|
-
function dispatchUIEvent(config, target, type3, init) {
|
|
1676
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1449
1677
|
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1450
1678
|
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1451
1679
|
}
|
|
1452
1680
|
const event = createEvent(type3, target, init);
|
|
1453
|
-
return
|
|
1681
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1454
1682
|
}
|
|
1455
1683
|
function bindDispatchUIEvent(config) {
|
|
1456
1684
|
return dispatchUIEvent.bind(void 0, config);
|
|
@@ -1527,9 +1755,9 @@ function setUISelection(element, {
|
|
|
1527
1755
|
}
|
|
1528
1756
|
}
|
|
1529
1757
|
function getUISelection(element) {
|
|
1530
|
-
var
|
|
1758
|
+
var _a3, _b, _c;
|
|
1531
1759
|
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1532
|
-
anchorOffset: (
|
|
1760
|
+
anchorOffset: (_a3 = element.selectionStart) != null ? _a3 : 0,
|
|
1533
1761
|
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1534
1762
|
};
|
|
1535
1763
|
return __spreadProps(__spreadValues({}, sel), {
|
|
@@ -1537,9 +1765,6 @@ function getUISelection(element) {
|
|
|
1537
1765
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1538
1766
|
});
|
|
1539
1767
|
}
|
|
1540
|
-
function clearUISelection(element) {
|
|
1541
|
-
element[UISelection] = void 0;
|
|
1542
|
-
}
|
|
1543
1768
|
|
|
1544
1769
|
// src/document/value.ts
|
|
1545
1770
|
var UIValue = Symbol("Displayed value in UI");
|
|
@@ -1547,17 +1772,23 @@ var InitialValue = Symbol("Initial value to compare on blur");
|
|
|
1547
1772
|
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1548
1773
|
function valueInterceptor(v) {
|
|
1549
1774
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1775
|
+
if (isUI) {
|
|
1776
|
+
this[UIValue] = String(v);
|
|
1777
|
+
setPreviousValue(this, String(this.value));
|
|
1778
|
+
} else {
|
|
1779
|
+
trackOrSetValue(this, String(v));
|
|
1555
1780
|
}
|
|
1556
1781
|
return {
|
|
1557
1782
|
applyNative: !!isUI,
|
|
1558
|
-
realArgs:
|
|
1783
|
+
realArgs: sanitizeValue(this, v)
|
|
1559
1784
|
};
|
|
1560
1785
|
}
|
|
1786
|
+
function sanitizeValue(element, v) {
|
|
1787
|
+
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) {
|
|
1788
|
+
return String(Number(v));
|
|
1789
|
+
}
|
|
1790
|
+
return String(v);
|
|
1791
|
+
}
|
|
1561
1792
|
function prepareValueInterceptor(element) {
|
|
1562
1793
|
prepareInterceptor(element, "value", valueInterceptor);
|
|
1563
1794
|
}
|
|
@@ -1576,17 +1807,36 @@ function setInitialValue(element) {
|
|
|
1576
1807
|
function getInitialValue(element) {
|
|
1577
1808
|
return element[InitialValue];
|
|
1578
1809
|
}
|
|
1810
|
+
function setPreviousValue(element, v) {
|
|
1811
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
|
|
1812
|
+
}
|
|
1579
1813
|
function startTrackValue(element) {
|
|
1580
|
-
element[TrackChanges] = []
|
|
1814
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
|
|
1815
|
+
nextValue: String(element.value),
|
|
1816
|
+
tracked: []
|
|
1817
|
+
});
|
|
1581
1818
|
}
|
|
1582
|
-
function
|
|
1583
|
-
var
|
|
1584
|
-
(
|
|
1819
|
+
function trackOrSetValue(element, v) {
|
|
1820
|
+
var _a3, _b, _c;
|
|
1821
|
+
(_b = (_a3 = element[TrackChanges]) == null ? void 0 : _a3.tracked) == null ? void 0 : _b.push(v);
|
|
1822
|
+
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1823
|
+
setCleanValue(element, v);
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
function setCleanValue(element, v) {
|
|
1827
|
+
element[UIValue] = void 0;
|
|
1828
|
+
element[InitialValue] = v;
|
|
1829
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1585
1830
|
}
|
|
1586
1831
|
function endTrackValue(element) {
|
|
1587
|
-
|
|
1832
|
+
var _a3, _b;
|
|
1833
|
+
const changes = element[TrackChanges];
|
|
1588
1834
|
element[TrackChanges] = void 0;
|
|
1589
|
-
|
|
1835
|
+
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;
|
|
1836
|
+
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1837
|
+
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1838
|
+
}
|
|
1839
|
+
return isJustReactStateUpdate;
|
|
1590
1840
|
}
|
|
1591
1841
|
|
|
1592
1842
|
// src/document/index.ts
|
|
@@ -1631,259 +1881,7 @@ function prepareElement(el) {
|
|
|
1631
1881
|
el[isPrepared] = isPrepared;
|
|
1632
1882
|
}
|
|
1633
1883
|
|
|
1634
|
-
// src/keyboard/
|
|
1635
|
-
var keydownBehavior = [
|
|
1636
|
-
{
|
|
1637
|
-
matches: (keyDef) => keyDef.key === "ArrowLeft" || keyDef.key === "ArrowRight",
|
|
1638
|
-
handle: (keyDef, element) => {
|
|
1639
|
-
if (hasOwnSelection(element)) {
|
|
1640
|
-
const selection = getUISelection(element);
|
|
1641
|
-
setSelection({
|
|
1642
|
-
focusNode: element,
|
|
1643
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1644
|
-
});
|
|
1645
|
-
} else {
|
|
1646
|
-
const selection = element.ownerDocument.getSelection();
|
|
1647
|
-
if (!selection) {
|
|
1648
|
-
return;
|
|
1649
|
-
}
|
|
1650
|
-
if (selection.isCollapsed) {
|
|
1651
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1652
|
-
if (nextPosition) {
|
|
1653
|
-
setSelection({
|
|
1654
|
-
focusNode: nextPosition.node,
|
|
1655
|
-
focusOffset: nextPosition.offset
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
|
-
} else {
|
|
1659
|
-
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
];
|
|
1665
|
-
|
|
1666
|
-
// src/keyboard/plugins/control.ts
|
|
1667
|
-
var keydownBehavior2 = [
|
|
1668
|
-
{
|
|
1669
|
-
matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
|
|
1670
|
-
handle: (keyDef, element) => {
|
|
1671
|
-
var _a, _b;
|
|
1672
|
-
if (keyDef.key === "Home") {
|
|
1673
|
-
setSelectionRange(element, 0, 0);
|
|
1674
|
-
} else {
|
|
1675
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1676
|
-
setSelectionRange(element, newPos, newPos);
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
},
|
|
1680
|
-
{
|
|
1681
|
-
matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
|
|
1682
|
-
handle: (keyDef, element) => {
|
|
1683
|
-
var _a, _b;
|
|
1684
|
-
if (keyDef.key === "PageUp") {
|
|
1685
|
-
setSelectionRange(element, 0, 0);
|
|
1686
|
-
} else {
|
|
1687
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1688
|
-
setSelectionRange(element, newPos, newPos);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
},
|
|
1692
|
-
{
|
|
1693
|
-
matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
|
|
1694
|
-
handle: (keDef, element, config) => {
|
|
1695
|
-
var _a;
|
|
1696
|
-
(_a = prepareInput(config, "", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
];
|
|
1700
|
-
|
|
1701
|
-
// src/keyboard/shared/fireChangeForInputTimeIfValid.ts
|
|
1702
|
-
function fireChangeForInputTimeIfValid(config, el, prevValue, timeNewEntry) {
|
|
1703
|
-
if (isValidInputTimeValue(el, timeNewEntry) && prevValue !== timeNewEntry) {
|
|
1704
|
-
setUIValue(el, timeNewEntry);
|
|
1705
|
-
dispatchUIEvent(config, el, "change");
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
// src/keyboard/plugins/character.ts
|
|
1710
|
-
var keypressBehavior = [
|
|
1711
|
-
{
|
|
1712
|
-
matches: (keyDef, element) => {
|
|
1713
|
-
var _a;
|
|
1714
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1715
|
-
},
|
|
1716
|
-
handle: (keyDef, element, config) => {
|
|
1717
|
-
var _a;
|
|
1718
|
-
let newEntry = keyDef.key;
|
|
1719
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1720
|
-
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1721
|
-
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1722
|
-
newEntry = timeNewEntry;
|
|
1723
|
-
}
|
|
1724
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1725
|
-
const prevValue = getValue(element);
|
|
1726
|
-
if (prevValue !== newValue) {
|
|
1727
|
-
editInputElement(config, element, {
|
|
1728
|
-
newValue,
|
|
1729
|
-
newSelection: {
|
|
1730
|
-
node: element,
|
|
1731
|
-
offset: newOffset
|
|
1732
|
-
},
|
|
1733
|
-
eventOverrides: {
|
|
1734
|
-
data: keyDef.key,
|
|
1735
|
-
inputType: "insertText"
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
}
|
|
1739
|
-
fireChangeForInputTimeIfValid(config, element, prevValue, timeNewEntry);
|
|
1740
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1741
|
-
}
|
|
1742
|
-
},
|
|
1743
|
-
{
|
|
1744
|
-
matches: (keyDef, element) => {
|
|
1745
|
-
var _a;
|
|
1746
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1747
|
-
},
|
|
1748
|
-
handle: (keyDef, element, config) => {
|
|
1749
|
-
var _a;
|
|
1750
|
-
let newEntry = keyDef.key;
|
|
1751
|
-
const textToBeTyped = ((_a = config.keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1752
|
-
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1753
|
-
if (isValidToBeTyped) {
|
|
1754
|
-
newEntry = textToBeTyped;
|
|
1755
|
-
}
|
|
1756
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1757
|
-
const prevValue = getValue(element);
|
|
1758
|
-
if (prevValue !== newValue) {
|
|
1759
|
-
editInputElement(config, element, {
|
|
1760
|
-
newValue,
|
|
1761
|
-
newSelection: {
|
|
1762
|
-
node: element,
|
|
1763
|
-
offset: newOffset
|
|
1764
|
-
},
|
|
1765
|
-
eventOverrides: {
|
|
1766
|
-
data: keyDef.key,
|
|
1767
|
-
inputType: "insertText"
|
|
1768
|
-
}
|
|
1769
|
-
});
|
|
1770
|
-
}
|
|
1771
|
-
if (isValidToBeTyped) {
|
|
1772
|
-
setUIValue(element, textToBeTyped);
|
|
1773
|
-
dispatchUIEvent(config, element, "change");
|
|
1774
|
-
}
|
|
1775
|
-
config.keyboardState.carryValue = textToBeTyped;
|
|
1776
|
-
}
|
|
1777
|
-
},
|
|
1778
|
-
{
|
|
1779
|
-
matches: (keyDef, element) => {
|
|
1780
|
-
var _a;
|
|
1781
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1782
|
-
},
|
|
1783
|
-
handle: (keyDef, element, config) => {
|
|
1784
|
-
var _a, _b;
|
|
1785
|
-
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1786
|
-
return;
|
|
1787
|
-
}
|
|
1788
|
-
const { getNewValue, commit } = prepareInput(config, keyDef.key, element);
|
|
1789
|
-
const newValue = getNewValue();
|
|
1790
|
-
const valueParts = newValue.split("e", 2);
|
|
1791
|
-
if (Number((_a = newValue.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = newValue.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1])) {
|
|
1792
|
-
return;
|
|
1793
|
-
}
|
|
1794
|
-
commit();
|
|
1795
|
-
}
|
|
1796
|
-
},
|
|
1797
|
-
{
|
|
1798
|
-
matches: (keyDef, element) => {
|
|
1799
|
-
var _a;
|
|
1800
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1801
|
-
},
|
|
1802
|
-
handle: (keyDef, element, config) => {
|
|
1803
|
-
var _a;
|
|
1804
|
-
(_a = prepareInput(config, keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1805
|
-
}
|
|
1806
|
-
},
|
|
1807
|
-
{
|
|
1808
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1809
|
-
handle: (keyDef, element, config) => {
|
|
1810
|
-
var _a;
|
|
1811
|
-
(_a = prepareInput(config, "\n", element, isContentEditable(element) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
];
|
|
1815
|
-
|
|
1816
|
-
// src/keyboard/plugins/functional.ts
|
|
1817
|
-
var keydownBehavior3 = [
|
|
1818
|
-
{
|
|
1819
|
-
matches: (keyDef, element) => keyDef.key === "Backspace" && isEditable(element),
|
|
1820
|
-
handle: (keyDef, element, config) => {
|
|
1821
|
-
var _a;
|
|
1822
|
-
(_a = prepareInput(config, "", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1823
|
-
}
|
|
1824
|
-
},
|
|
1825
|
-
{
|
|
1826
|
-
matches: (keyDef) => keyDef.key === "Tab",
|
|
1827
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1828
|
-
const dest = getTabDestination(element, keyboardState.modifiers.Shift);
|
|
1829
|
-
if (dest === element.ownerDocument.body) {
|
|
1830
|
-
blur(element);
|
|
1831
|
-
} else {
|
|
1832
|
-
focus(dest);
|
|
1833
|
-
if (isElementType(dest, ["input", "textarea"])) {
|
|
1834
|
-
setUISelection(dest, {
|
|
1835
|
-
anchorOffset: 0,
|
|
1836
|
-
focusOffset: dest.value.length
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
];
|
|
1843
|
-
var keypressBehavior2 = [
|
|
1844
|
-
{
|
|
1845
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input") && ["checkbox", "radio"].includes(element.type),
|
|
1846
|
-
handle: (keyDef, element, config) => {
|
|
1847
|
-
const form = element.form;
|
|
1848
|
-
if (hasFormSubmit(form)) {
|
|
1849
|
-
dispatchUIEvent(config, form, "submit");
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
},
|
|
1853
|
-
{
|
|
1854
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1855
|
-
handle: (keyDef, element, config) => {
|
|
1856
|
-
dispatchUIEvent(config, element, "click");
|
|
1857
|
-
}
|
|
1858
|
-
},
|
|
1859
|
-
{
|
|
1860
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1861
|
-
handle: (keyDef, element, config) => {
|
|
1862
|
-
const form = element.form;
|
|
1863
|
-
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1864
|
-
dispatchUIEvent(config, form, "submit");
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
];
|
|
1869
|
-
var keyupBehavior = [
|
|
1870
|
-
{
|
|
1871
|
-
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1872
|
-
handle: (keyDef, element, config) => {
|
|
1873
|
-
dispatchUIEvent(config, element, "click");
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
];
|
|
1877
|
-
|
|
1878
|
-
// src/keyboard/plugins/combination.ts
|
|
1879
|
-
var keydownBehavior4 = [
|
|
1880
|
-
{
|
|
1881
|
-
matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
|
|
1882
|
-
handle: (keyDef, element) => selectAll(element)
|
|
1883
|
-
}
|
|
1884
|
-
];
|
|
1885
|
-
|
|
1886
|
-
// src/keyboard/plugins/modifiers.ts
|
|
1884
|
+
// src/keyboard/modifiers.ts
|
|
1887
1885
|
var modifierKeys = [
|
|
1888
1886
|
"Alt",
|
|
1889
1887
|
"AltGraph",
|
|
@@ -1893,6 +1891,9 @@ var modifierKeys = [
|
|
|
1893
1891
|
"Shift",
|
|
1894
1892
|
"Symbol"
|
|
1895
1893
|
];
|
|
1894
|
+
function isModifierKey(key) {
|
|
1895
|
+
return modifierKeys.includes(key);
|
|
1896
|
+
}
|
|
1896
1897
|
var modifierLocks = [
|
|
1897
1898
|
"CapsLock",
|
|
1898
1899
|
"FnLock",
|
|
@@ -1900,78 +1901,40 @@ var modifierLocks = [
|
|
|
1900
1901
|
"ScrollLock",
|
|
1901
1902
|
"SymbolLock"
|
|
1902
1903
|
];
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1904
|
+
function isModifierLock(key) {
|
|
1905
|
+
return modifierLocks.includes(key);
|
|
1906
|
+
}
|
|
1907
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1908
|
+
var _a3;
|
|
1909
|
+
if (isModifierKey(key)) {
|
|
1910
|
+
config.keyboardState.modifiers[key] = true;
|
|
1911
|
+
if (key === "AltGraph") {
|
|
1912
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1913
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1913
1914
|
}
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
const key = keyDef.key;
|
|
1919
|
-
keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
|
|
1920
|
-
if (!keyboardState.modifierPhase[key]) {
|
|
1921
|
-
keyboardState.modifiers[key] = true;
|
|
1922
|
-
}
|
|
1915
|
+
} else if (isModifierLock(key)) {
|
|
1916
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1917
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1918
|
+
config.keyboardState.modifiers[key] = true;
|
|
1923
1919
|
}
|
|
1924
1920
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
{
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
},
|
|
1933
|
-
{
|
|
1934
|
-
matches: (keyDef) => modifierLocks.includes(keyDef.key),
|
|
1935
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1936
|
-
const key = keyDef.key;
|
|
1937
|
-
if (keyboardState.modifierPhase[key]) {
|
|
1938
|
-
keyboardState.modifiers[key] = false;
|
|
1939
|
-
}
|
|
1921
|
+
}
|
|
1922
|
+
function preKeyupBehavior(config, { key }) {
|
|
1923
|
+
if (isModifierKey(key)) {
|
|
1924
|
+
config.keyboardState.modifiers[key] = false;
|
|
1925
|
+
} else if (isModifierLock(key)) {
|
|
1926
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1927
|
+
config.keyboardState.modifiers[key] = false;
|
|
1940
1928
|
}
|
|
1941
1929
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1949
|
-
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1950
|
-
}
|
|
1930
|
+
}
|
|
1931
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1932
|
+
var _a3;
|
|
1933
|
+
if (key === "AltGraph") {
|
|
1934
|
+
const ctrlKeyDef = (_a3 = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a3 : { key: "Control", code: "Control" };
|
|
1935
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1951
1936
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
// src/keyboard/plugins/index.ts
|
|
1955
|
-
var preKeydownBehavior2 = [
|
|
1956
|
-
...preKeydownBehavior
|
|
1957
|
-
];
|
|
1958
|
-
var keydownBehavior5 = [
|
|
1959
|
-
...keydownBehavior,
|
|
1960
|
-
...keydownBehavior2,
|
|
1961
|
-
...keydownBehavior3,
|
|
1962
|
-
...keydownBehavior4
|
|
1963
|
-
];
|
|
1964
|
-
var keypressBehavior3 = [
|
|
1965
|
-
...keypressBehavior2,
|
|
1966
|
-
...keypressBehavior
|
|
1967
|
-
];
|
|
1968
|
-
var preKeyupBehavior2 = [
|
|
1969
|
-
...preKeyupBehavior
|
|
1970
|
-
];
|
|
1971
|
-
var keyupBehavior2 = [...keyupBehavior];
|
|
1972
|
-
var postKeyupBehavior2 = [
|
|
1973
|
-
...postKeyupBehavior
|
|
1974
|
-
];
|
|
1937
|
+
}
|
|
1975
1938
|
|
|
1976
1939
|
// src/keyboard/keyboardAction.ts
|
|
1977
1940
|
function keyboardAction(config, actions) {
|
|
@@ -2010,8 +1973,8 @@ function keyboardKeyAction(_0, _1) {
|
|
|
2010
1973
|
});
|
|
2011
1974
|
}
|
|
2012
1975
|
function getActive(document2) {
|
|
2013
|
-
var
|
|
2014
|
-
return (
|
|
1976
|
+
var _a3;
|
|
1977
|
+
return (_a3 = getActiveElement(document2)) != null ? _a3 : document2.body;
|
|
2015
1978
|
}
|
|
2016
1979
|
function releaseAllKeys(config) {
|
|
2017
1980
|
return __async(this, null, function* () {
|
|
@@ -2029,53 +1992,37 @@ function keydown(keyDef, getCurrentElement, config) {
|
|
|
2029
1992
|
config.keyboardState.carryChar = "";
|
|
2030
1993
|
}
|
|
2031
1994
|
config.keyboardState.activeElement = element;
|
|
2032
|
-
|
|
1995
|
+
preKeydownBehavior(config, keyDef, element);
|
|
2033
1996
|
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
2034
1997
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
2035
|
-
if (unpreventedDefault) {
|
|
2036
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
2037
|
-
}
|
|
2038
1998
|
return unpreventedDefault;
|
|
2039
1999
|
});
|
|
2040
2000
|
}
|
|
2041
2001
|
function keypress(keyDef, getCurrentElement, config) {
|
|
2042
2002
|
return __async(this, null, function* () {
|
|
2043
2003
|
const element = getCurrentElement();
|
|
2044
|
-
|
|
2004
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2045
2005
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2046
2006
|
}));
|
|
2047
|
-
if (unpreventedDefault) {
|
|
2048
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2049
|
-
}
|
|
2050
2007
|
});
|
|
2051
2008
|
}
|
|
2052
2009
|
function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2053
2010
|
return __async(this, null, function* () {
|
|
2054
2011
|
const element = getCurrentElement();
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
if (unprevented && unpreventedDefault) {
|
|
2058
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2059
|
-
}
|
|
2012
|
+
preKeyupBehavior(config, keyDef);
|
|
2013
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2060
2014
|
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
2061
|
-
|
|
2015
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2062
2016
|
});
|
|
2063
2017
|
}
|
|
2064
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
2065
|
-
const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
|
|
2066
|
-
if (plugin) {
|
|
2067
|
-
plugin.handle(keyDef, element, config);
|
|
2068
|
-
}
|
|
2069
|
-
return !!plugin;
|
|
2070
|
-
}
|
|
2071
2018
|
function hasKeyPress(keyDef, config) {
|
|
2072
|
-
var
|
|
2073
|
-
return (((
|
|
2019
|
+
var _a3;
|
|
2020
|
+
return (((_a3 = keyDef.key) == null ? void 0 : _a3.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
2074
2021
|
}
|
|
2075
2022
|
|
|
2076
2023
|
// src/keyboard/parseKeyDef.ts
|
|
2077
2024
|
function parseKeyDef(keyboardMap, text) {
|
|
2078
|
-
var
|
|
2025
|
+
var _a3;
|
|
2079
2026
|
const defs = [];
|
|
2080
2027
|
do {
|
|
2081
2028
|
const {
|
|
@@ -2085,16 +2032,16 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2085
2032
|
releasePrevious,
|
|
2086
2033
|
releaseSelf = true,
|
|
2087
2034
|
repeat
|
|
2088
|
-
} = readNextDescriptor(text);
|
|
2089
|
-
const keyDef = (
|
|
2090
|
-
var
|
|
2035
|
+
} = readNextDescriptor(text, "keyboard");
|
|
2036
|
+
const keyDef = (_a3 = keyboardMap.find((def) => {
|
|
2037
|
+
var _a4, _b;
|
|
2091
2038
|
if (type3 === "[") {
|
|
2092
|
-
return ((
|
|
2039
|
+
return ((_a4 = def.code) == null ? void 0 : _a4.toLowerCase()) === descriptor.toLowerCase();
|
|
2093
2040
|
} else if (type3 === "{") {
|
|
2094
2041
|
return ((_b = def.key) == null ? void 0 : _b.toLowerCase()) === descriptor.toLowerCase();
|
|
2095
2042
|
}
|
|
2096
2043
|
return def.key === descriptor;
|
|
2097
|
-
})) != null ?
|
|
2044
|
+
})) != null ? _a3 : {
|
|
2098
2045
|
key: "Unknown",
|
|
2099
2046
|
code: "Unknown",
|
|
2100
2047
|
[type3 === "[" ? "code" : "key"]: descriptor
|
|
@@ -2144,7 +2091,7 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2144
2091
|
consumedLength,
|
|
2145
2092
|
releasePrevious,
|
|
2146
2093
|
releaseSelf = true
|
|
2147
|
-
} = readNextDescriptor(keys);
|
|
2094
|
+
} = readNextDescriptor(keys, "pointer");
|
|
2148
2095
|
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
2149
2096
|
if (keyDef) {
|
|
2150
2097
|
defs.push({ keyDef, releasePrevious, releaseSelf });
|
|
@@ -2173,8 +2120,8 @@ function firePointerEvent(config, target, type3, {
|
|
|
2173
2120
|
}
|
|
2174
2121
|
init.button = getMouseButton(button != null ? button : 0);
|
|
2175
2122
|
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2176
|
-
var
|
|
2177
|
-
return (
|
|
2123
|
+
var _a3;
|
|
2124
|
+
return (_a3 = p.keyDef.button) != null ? _a3 : 0;
|
|
2178
2125
|
}));
|
|
2179
2126
|
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2180
2127
|
init.detail = clickCount;
|
|
@@ -2336,7 +2283,7 @@ function getNextPointerId(state) {
|
|
|
2336
2283
|
return state.pointerId;
|
|
2337
2284
|
}
|
|
2338
2285
|
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2339
|
-
var
|
|
2286
|
+
var _a3, _b, _c;
|
|
2340
2287
|
setLevelRef(config, 2 /* Trigger */);
|
|
2341
2288
|
assertPointerEvents(config, target);
|
|
2342
2289
|
const { pointerState } = config;
|
|
@@ -2359,7 +2306,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2359
2306
|
}
|
|
2360
2307
|
}
|
|
2361
2308
|
}
|
|
2362
|
-
if (((
|
|
2309
|
+
if (((_a3 = pointerState.activeClickCount) == null ? void 0 : _a3[0]) !== name) {
|
|
2363
2310
|
delete pointerState.activeClickCount;
|
|
2364
2311
|
}
|
|
2365
2312
|
const clickCount = Number((_c = (_b = pointerState.activeClickCount) == null ? void 0 : _b[1]) != null ? _c : 0) + 1;
|
|
@@ -2513,7 +2460,7 @@ function mousedownDefaultBehavior({
|
|
|
2513
2460
|
node,
|
|
2514
2461
|
offset: end
|
|
2515
2462
|
});
|
|
2516
|
-
const range =
|
|
2463
|
+
const range = target.ownerDocument.createRange();
|
|
2517
2464
|
range.setStart(startNode, startOffset);
|
|
2518
2465
|
range.setEnd(endNode, endOffset);
|
|
2519
2466
|
position.selectionRange = range;
|
|
@@ -2543,11 +2490,11 @@ function getTextRange(text, pos, clickCount) {
|
|
|
2543
2490
|
// src/pointer/pointerAction.ts
|
|
2544
2491
|
function pointerAction(config, actions) {
|
|
2545
2492
|
return __async(this, null, function* () {
|
|
2546
|
-
var
|
|
2493
|
+
var _a3, _b;
|
|
2547
2494
|
for (let i = 0; i < actions.length; i++) {
|
|
2548
2495
|
const action = actions[i];
|
|
2549
2496
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2550
|
-
const target = (
|
|
2497
|
+
const target = (_a3 = action.target) != null ? _a3 : getPrevTarget(pointerName, config.pointerState);
|
|
2551
2498
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2552
2499
|
yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
|
|
2553
2500
|
if (typeof config.delay === "number") {
|
|
@@ -2567,11 +2514,11 @@ function getPrevTarget(pointerName, state) {
|
|
|
2567
2514
|
}
|
|
2568
2515
|
|
|
2569
2516
|
// src/pointer/index.ts
|
|
2570
|
-
function pointer(
|
|
2517
|
+
function pointer(input2) {
|
|
2571
2518
|
return __async(this, null, function* () {
|
|
2572
2519
|
const { pointerMap } = this[Config];
|
|
2573
2520
|
const actions = [];
|
|
2574
|
-
(Array.isArray(
|
|
2521
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2575
2522
|
if (typeof actionInput === "string") {
|
|
2576
2523
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2577
2524
|
} else if ("keys" in actionInput) {
|
|
@@ -2677,17 +2624,16 @@ function tab() {
|
|
|
2677
2624
|
// src/clipboard/copy.ts
|
|
2678
2625
|
function copy() {
|
|
2679
2626
|
return __async(this, null, function* () {
|
|
2680
|
-
var
|
|
2627
|
+
var _a3;
|
|
2681
2628
|
const doc = this[Config].document;
|
|
2682
|
-
const target = (
|
|
2629
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2683
2630
|
const clipboardData = copySelection(target);
|
|
2684
2631
|
if (clipboardData.items.length === 0) {
|
|
2685
2632
|
return;
|
|
2686
2633
|
}
|
|
2687
|
-
this.dispatchUIEvent(target, "copy", {
|
|
2634
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2688
2635
|
clipboardData
|
|
2689
|
-
})
|
|
2690
|
-
if (this[Config].writeToClipboard) {
|
|
2636
|
+
}) && this[Config].writeToClipboard) {
|
|
2691
2637
|
yield writeDataTransferToClipboard(doc, clipboardData);
|
|
2692
2638
|
}
|
|
2693
2639
|
return clipboardData;
|
|
@@ -2697,21 +2643,17 @@ function copy() {
|
|
|
2697
2643
|
// src/clipboard/cut.ts
|
|
2698
2644
|
function cut() {
|
|
2699
2645
|
return __async(this, null, function* () {
|
|
2700
|
-
var
|
|
2646
|
+
var _a3;
|
|
2701
2647
|
const doc = this[Config].document;
|
|
2702
|
-
const target = (
|
|
2648
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2703
2649
|
const clipboardData = copySelection(target);
|
|
2704
2650
|
if (clipboardData.items.length === 0) {
|
|
2705
2651
|
return;
|
|
2706
2652
|
}
|
|
2707
|
-
this.dispatchUIEvent(target, "cut", {
|
|
2653
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2708
2654
|
clipboardData
|
|
2709
|
-
})
|
|
2710
|
-
|
|
2711
|
-
(_b = prepareInput(this[Config], "", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2712
|
-
}
|
|
2713
|
-
if (this[Config].writeToClipboard) {
|
|
2714
|
-
yield writeDataTransferToClipboard(doc, clipboardData);
|
|
2655
|
+
}) && this[Config].writeToClipboard) {
|
|
2656
|
+
yield writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2715
2657
|
}
|
|
2716
2658
|
return clipboardData;
|
|
2717
2659
|
});
|
|
@@ -2720,25 +2662,19 @@ function cut() {
|
|
|
2720
2662
|
// src/clipboard/paste.ts
|
|
2721
2663
|
function paste(clipboardData) {
|
|
2722
2664
|
return __async(this, null, function* () {
|
|
2723
|
-
var
|
|
2665
|
+
var _a3, _b;
|
|
2724
2666
|
const doc = this[Config].document;
|
|
2725
|
-
const target = (
|
|
2726
|
-
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2667
|
+
const target = (_a3 = doc.activeElement) != null ? _a3 : doc.body;
|
|
2668
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(doc, clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2727
2669
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2728
2670
|
});
|
|
2729
2671
|
this.dispatchUIEvent(target, "paste", {
|
|
2730
2672
|
clipboardData: dataTransfer
|
|
2731
2673
|
});
|
|
2732
|
-
if (isEditable(target)) {
|
|
2733
|
-
const textData = dataTransfer.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2734
|
-
if (textData) {
|
|
2735
|
-
(_c = prepareInput(this[Config], textData, target, "insertFromPaste")) == null ? void 0 : _c.commit();
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
2674
|
});
|
|
2739
2675
|
}
|
|
2740
|
-
function getClipboardDataFromString(text) {
|
|
2741
|
-
const dt = createDataTransfer();
|
|
2676
|
+
function getClipboardDataFromString(doc, text) {
|
|
2677
|
+
const dt = createDataTransfer(getWindow(doc));
|
|
2742
2678
|
dt.setData("text", text);
|
|
2743
2679
|
return dt;
|
|
2744
2680
|
}
|
|
@@ -2746,7 +2682,6 @@ function getClipboardDataFromString(text) {
|
|
|
2746
2682
|
// src/utility/clear.ts
|
|
2747
2683
|
function clear(element) {
|
|
2748
2684
|
return __async(this, null, function* () {
|
|
2749
|
-
var _a;
|
|
2750
2685
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2751
2686
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2752
2687
|
}
|
|
@@ -2758,7 +2693,7 @@ function clear(element) {
|
|
|
2758
2693
|
if (!isAllSelected(element)) {
|
|
2759
2694
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2760
2695
|
}
|
|
2761
|
-
(
|
|
2696
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2762
2697
|
});
|
|
2763
2698
|
}
|
|
2764
2699
|
|
|
@@ -2885,28 +2820,28 @@ function type(_0, _1) {
|
|
|
2885
2820
|
// src/utility/upload.ts
|
|
2886
2821
|
function upload(element, fileOrFiles) {
|
|
2887
2822
|
return __async(this, null, function* () {
|
|
2888
|
-
const
|
|
2889
|
-
if (!
|
|
2890
|
-
throw new TypeError(`The ${
|
|
2823
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2824
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2825
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2891
2826
|
}
|
|
2892
2827
|
if (isDisabled(element))
|
|
2893
2828
|
return;
|
|
2894
|
-
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file,
|
|
2829
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2895
2830
|
const fileDialog = () => {
|
|
2896
|
-
var
|
|
2897
|
-
if (files.length === ((
|
|
2898
|
-
var
|
|
2899
|
-
return f === ((
|
|
2831
|
+
var _a3;
|
|
2832
|
+
if (files.length === ((_a3 = input2.files) == null ? void 0 : _a3.length) && files.every((f, i) => {
|
|
2833
|
+
var _a4;
|
|
2834
|
+
return f === ((_a4 = input2.files) == null ? void 0 : _a4.item(i));
|
|
2900
2835
|
})) {
|
|
2901
2836
|
return;
|
|
2902
2837
|
}
|
|
2903
|
-
setFiles(
|
|
2904
|
-
this.dispatchUIEvent(
|
|
2905
|
-
this.dispatchUIEvent(
|
|
2838
|
+
setFiles(input2, createFileList(files));
|
|
2839
|
+
this.dispatchUIEvent(input2, "input");
|
|
2840
|
+
this.dispatchUIEvent(input2, "change");
|
|
2906
2841
|
};
|
|
2907
|
-
|
|
2842
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2908
2843
|
yield this.click(element);
|
|
2909
|
-
|
|
2844
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2910
2845
|
});
|
|
2911
2846
|
}
|
|
2912
2847
|
function isAcceptableFile(file, accept) {
|
|
@@ -2944,10 +2879,10 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
|
2944
2879
|
});
|
|
2945
2880
|
}
|
|
2946
2881
|
function setupMain(options = {}) {
|
|
2947
|
-
var
|
|
2882
|
+
var _a3;
|
|
2948
2883
|
const config = createConfig(options);
|
|
2949
2884
|
prepareDocument(config.document);
|
|
2950
|
-
const view = (
|
|
2885
|
+
const view = (_a3 = config.document.defaultView) != null ? _a3 : window;
|
|
2951
2886
|
attachClipboardStubToView(view);
|
|
2952
2887
|
return doSetup(config);
|
|
2953
2888
|
}
|
|
@@ -2983,8 +2918,8 @@ function doSetup(config) {
|
|
|
2983
2918
|
});
|
|
2984
2919
|
}
|
|
2985
2920
|
function getDocument(options, node) {
|
|
2986
|
-
var
|
|
2987
|
-
return (_b = (
|
|
2921
|
+
var _a3, _b;
|
|
2922
|
+
return (_b = (_a3 = options.document) != null ? _a3 : node && getDocumentFromNode(node)) != null ? _b : document;
|
|
2988
2923
|
}
|
|
2989
2924
|
|
|
2990
2925
|
// src/setup/directApi.ts
|
|
@@ -3035,9 +2970,9 @@ function keyboard2(_0) {
|
|
|
3035
2970
|
});
|
|
3036
2971
|
}
|
|
3037
2972
|
function pointer2(_0) {
|
|
3038
|
-
return __async(this, arguments, function* (
|
|
2973
|
+
return __async(this, arguments, function* (input2, options = {}) {
|
|
3039
2974
|
const { config, api } = setupDirect(options);
|
|
3040
|
-
return api.pointer(
|
|
2975
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
3041
2976
|
});
|
|
3042
2977
|
}
|
|
3043
2978
|
function paste2(clipboardData, options) {
|