@testing-library/user-event 14.0.0-beta.8 → 14.0.1
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 +1007 -1033
- package/dist/index.mjs +998 -1019
- package/dist/types/document/selection.d.ts +0 -1
- package/dist/types/document/value.d.ts +9 -2
- package/dist/types/event/behavior/click.d.ts +1 -0
- package/dist/types/event/behavior/cut.d.ts +1 -0
- package/dist/types/event/behavior/index.d.ts +8 -0
- package/dist/types/event/behavior/keydown.d.ts +1 -0
- package/dist/types/event/behavior/keypress.d.ts +1 -0
- package/dist/types/event/behavior/keyup.d.ts +1 -0
- package/dist/types/event/behavior/paste.d.ts +1 -0
- package/dist/types/event/behavior/registry.d.ts +9 -0
- package/dist/types/event/createEvent.d.ts +8 -0
- package/dist/types/event/dispatchEvent.d.ts +2 -0
- package/dist/types/event/eventMap.d.ts +361 -0
- package/dist/types/event/eventTypes.d.ts +2 -0
- package/dist/types/event/index.d.ts +6 -0
- package/dist/types/event/types.d.ts +13 -0
- package/dist/types/event/wrapEvent.d.ts +1 -0
- package/dist/types/keyboard/modifiers.d.ts +9 -0
- package/dist/types/keyboard/types.d.ts +0 -5
- package/dist/types/pointer/firePointerEvents.d.ts +11 -0
- package/dist/types/pointer/types.d.ts +2 -1
- package/dist/types/setup/index.d.ts +2 -0
- package/dist/types/setup/setup.d.ts +1 -0
- package/dist/types/utility/clear.d.ts +1 -1
- 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 -9
- package/dist/types/utils/keyDef/readNextDescriptor.d.ts +3 -1
- package/dist/types/utils/keyboard/getKeyEventProps.d.ts +2 -14
- package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
- package/package.json +10 -13
- package/CHANGELOG.md +0 -5
- 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 -3
- 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 -16
- 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 -7
- package/dist/types/utils/misc/hasFormSubmit.d.ts +0 -1
- package/dist/types/utils/pointer/firePointerEvents.d.ts +0 -25
package/dist/index.mjs
CHANGED
|
@@ -43,187 +43,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
// src/document/index.ts
|
|
47
|
-
import { fireEvent } from "@testing-library/dom";
|
|
48
|
-
|
|
49
|
-
// src/document/interceptor.ts
|
|
50
|
-
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
51
|
-
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
52
|
-
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
53
|
-
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
54
|
-
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
55
|
-
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
function intercept(...args) {
|
|
59
|
-
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
60
|
-
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
61
|
-
if (target === "set") {
|
|
62
|
-
realFunc.call(this, realArgs);
|
|
63
|
-
} else {
|
|
64
|
-
realFunc.call(this, ...realArgs);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
;
|
|
68
|
-
intercept[Interceptor] = Interceptor;
|
|
69
|
-
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
70
|
-
[target]: intercept
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// src/document/selection.ts
|
|
75
|
-
var UISelection = Symbol("Displayed selection in UI");
|
|
76
|
-
function prepareSelectionInterceptor(element) {
|
|
77
|
-
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
78
|
-
const isUI = start && typeof start === "object" && start[UISelection];
|
|
79
|
-
if (!isUI) {
|
|
80
|
-
this[UISelection] = void 0;
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
realArgs: [Number(start), end, direction]
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
87
|
-
this[UISelection] = void 0;
|
|
88
|
-
return { realArgs: v };
|
|
89
|
-
});
|
|
90
|
-
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
91
|
-
this[UISelection] = void 0;
|
|
92
|
-
return { realArgs: v };
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function setUISelection(element, {
|
|
96
|
-
focusOffset: focusOffsetParam,
|
|
97
|
-
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
98
|
-
}, mode = "replace") {
|
|
99
|
-
const valueLength = getUIValue(element).length;
|
|
100
|
-
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
101
|
-
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
102
|
-
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
103
|
-
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
104
|
-
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
105
|
-
element[UISelection] = {
|
|
106
|
-
anchorOffset,
|
|
107
|
-
focusOffset
|
|
108
|
-
};
|
|
109
|
-
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const startObj = new Number(startOffset);
|
|
113
|
-
startObj[UISelection] = UISelection;
|
|
114
|
-
try {
|
|
115
|
-
element.setSelectionRange(startObj, endOffset);
|
|
116
|
-
} catch (e) {
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function getUISelection(element) {
|
|
120
|
-
var _a, _b, _c;
|
|
121
|
-
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
122
|
-
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
123
|
-
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
124
|
-
};
|
|
125
|
-
return __spreadProps(__spreadValues({}, sel), {
|
|
126
|
-
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
127
|
-
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function clearUISelection(element) {
|
|
131
|
-
element[UISelection] = void 0;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/document/value.ts
|
|
135
|
-
var UIValue = Symbol("Displayed value in UI");
|
|
136
|
-
var InitialValue = Symbol("Initial value to compare on blur");
|
|
137
|
-
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
138
|
-
function valueInterceptor(v) {
|
|
139
|
-
const isUI = typeof v === "object" && v[UIValue];
|
|
140
|
-
this[UIValue] = isUI ? String(v) : void 0;
|
|
141
|
-
if (!isUI) {
|
|
142
|
-
trackValue(this, String(v));
|
|
143
|
-
this[InitialValue] = String(v);
|
|
144
|
-
clearUISelection(this);
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
applyNative: !!isUI,
|
|
148
|
-
realArgs: String(v)
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function prepareValueInterceptor(element) {
|
|
152
|
-
prepareInterceptor(element, "value", valueInterceptor);
|
|
153
|
-
}
|
|
154
|
-
function setUIValue(element, value) {
|
|
155
|
-
element.value = {
|
|
156
|
-
[UIValue]: UIValue,
|
|
157
|
-
toString: () => value
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function getUIValue(element) {
|
|
161
|
-
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
162
|
-
}
|
|
163
|
-
function setInitialValue(element) {
|
|
164
|
-
element[InitialValue] = element.value;
|
|
165
|
-
}
|
|
166
|
-
function getInitialValue(element) {
|
|
167
|
-
return element[InitialValue];
|
|
168
|
-
}
|
|
169
|
-
function startTrackValue(element) {
|
|
170
|
-
element[TrackChanges] = [];
|
|
171
|
-
}
|
|
172
|
-
function trackValue(element, v) {
|
|
173
|
-
var _a;
|
|
174
|
-
(_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
|
|
175
|
-
}
|
|
176
|
-
function endTrackValue(element) {
|
|
177
|
-
const tracked = element[TrackChanges];
|
|
178
|
-
element[TrackChanges] = void 0;
|
|
179
|
-
return tracked;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// src/document/index.ts
|
|
183
|
-
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
184
|
-
function prepareDocument(document2) {
|
|
185
|
-
if (document2[isPrepared]) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
document2.addEventListener("focus", (e) => {
|
|
189
|
-
const el = e.target;
|
|
190
|
-
prepareElement(el);
|
|
191
|
-
}, {
|
|
192
|
-
capture: true,
|
|
193
|
-
passive: true
|
|
194
|
-
});
|
|
195
|
-
if (document2.activeElement) {
|
|
196
|
-
prepareElement(document2.activeElement);
|
|
197
|
-
}
|
|
198
|
-
document2.addEventListener("blur", (e) => {
|
|
199
|
-
const el = e.target;
|
|
200
|
-
const initialValue = getInitialValue(el);
|
|
201
|
-
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
202
|
-
fireEvent.change(el);
|
|
203
|
-
}
|
|
204
|
-
}, {
|
|
205
|
-
capture: true,
|
|
206
|
-
passive: true
|
|
207
|
-
});
|
|
208
|
-
document2[isPrepared] = isPrepared;
|
|
209
|
-
}
|
|
210
|
-
function prepareElement(el) {
|
|
211
|
-
if ("value" in el) {
|
|
212
|
-
setInitialValue(el);
|
|
213
|
-
}
|
|
214
|
-
if (el[isPrepared]) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if ("value" in el) {
|
|
218
|
-
prepareValueInterceptor(el);
|
|
219
|
-
prepareSelectionInterceptor(el);
|
|
220
|
-
}
|
|
221
|
-
el[isPrepared] = isPrepared;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/keyboard/keyboardAction.ts
|
|
225
|
-
import { fireEvent as fireEvent9 } from "@testing-library/dom";
|
|
226
|
-
|
|
227
46
|
// src/utils/misc/isElementType.ts
|
|
228
47
|
function isElementType(element, tag, props) {
|
|
229
48
|
if (element.namespaceURI && element.namespaceURI !== "http://www.w3.org/1999/xhtml") {
|
|
@@ -533,6 +352,29 @@ if (typeof afterAll === "function") {
|
|
|
533
352
|
afterAll(() => detachClipboardStubFromView(window));
|
|
534
353
|
}
|
|
535
354
|
|
|
355
|
+
// src/utils/edit/isContentEditable.ts
|
|
356
|
+
function isContentEditable(element) {
|
|
357
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
358
|
+
}
|
|
359
|
+
function getContentEditable(node) {
|
|
360
|
+
const element = getElement(node);
|
|
361
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
362
|
+
}
|
|
363
|
+
function getElement(node) {
|
|
364
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/utils/edit/getValue.ts
|
|
368
|
+
function getValue(element) {
|
|
369
|
+
if (!element) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
if (isContentEditable(element)) {
|
|
373
|
+
return element.textContent;
|
|
374
|
+
}
|
|
375
|
+
return getUIValue(element);
|
|
376
|
+
}
|
|
377
|
+
|
|
536
378
|
// src/utils/edit/buildTimeValue.ts
|
|
537
379
|
function buildTimeValue(value) {
|
|
538
380
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -564,21 +406,137 @@ function build(onlyDigitsValue, index) {
|
|
|
564
406
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
565
407
|
}
|
|
566
408
|
|
|
567
|
-
// src/utils/edit/
|
|
568
|
-
function
|
|
409
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
410
|
+
function isValidDateOrTimeValue(element, value) {
|
|
569
411
|
const clone = element.cloneNode();
|
|
570
412
|
clone.value = value;
|
|
571
413
|
return clone.value === value;
|
|
572
414
|
}
|
|
573
415
|
|
|
574
|
-
// src/utils/edit/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
416
|
+
// src/utils/edit/maxLength.ts
|
|
417
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
418
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
419
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
420
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
421
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
422
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
423
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
424
|
+
return maxLengthSupportedTypes2;
|
|
425
|
+
})(maxLengthSupportedTypes || {});
|
|
426
|
+
function getSpaceUntilMaxLength(element) {
|
|
427
|
+
const value = getValue(element);
|
|
428
|
+
if (value === null) {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
432
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
433
|
+
}
|
|
434
|
+
function getSanitizedMaxLength(element) {
|
|
435
|
+
var _a;
|
|
436
|
+
if (!supportsMaxLength(element)) {
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
440
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
441
|
+
}
|
|
442
|
+
function supportsMaxLength(element) {
|
|
443
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
579
444
|
}
|
|
580
445
|
|
|
581
|
-
// src/utils/edit/
|
|
446
|
+
// src/utils/edit/input.ts
|
|
447
|
+
function isDateOrTime(element) {
|
|
448
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
449
|
+
}
|
|
450
|
+
function input(config, element, data, inputType = "insertText") {
|
|
451
|
+
const inputRange = getInputRange(element);
|
|
452
|
+
if (!inputRange) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (!isDateOrTime(element)) {
|
|
456
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
457
|
+
inputType,
|
|
458
|
+
data
|
|
459
|
+
});
|
|
460
|
+
if (!unprevented) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if ("startContainer" in inputRange) {
|
|
465
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
466
|
+
} else {
|
|
467
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
471
|
+
let del = false;
|
|
472
|
+
if (!inputRange.collapsed) {
|
|
473
|
+
del = true;
|
|
474
|
+
inputRange.deleteContents();
|
|
475
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
476
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
477
|
+
if (nextPosition) {
|
|
478
|
+
del = true;
|
|
479
|
+
const delRange = inputRange.cloneRange();
|
|
480
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
481
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
482
|
+
} else {
|
|
483
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
484
|
+
}
|
|
485
|
+
delRange.deleteContents();
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (data) {
|
|
489
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
490
|
+
const offset = inputRange.endOffset;
|
|
491
|
+
inputRange.endContainer.insertData(offset, data);
|
|
492
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
493
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
494
|
+
} else {
|
|
495
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
496
|
+
inputRange.insertNode(text);
|
|
497
|
+
inputRange.setStart(text, data.length);
|
|
498
|
+
inputRange.setEnd(text, data.length);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (del || data) {
|
|
502
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
506
|
+
let dataToInsert = data;
|
|
507
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
508
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
509
|
+
if (spaceUntilMaxLength > 0) {
|
|
510
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
511
|
+
} else {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
516
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
setUIValue(element, newValue);
|
|
523
|
+
setSelection({
|
|
524
|
+
focusNode: element,
|
|
525
|
+
anchorOffset: newOffset,
|
|
526
|
+
focusOffset: newOffset
|
|
527
|
+
});
|
|
528
|
+
if (isDateOrTime(element)) {
|
|
529
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
530
|
+
commitInput(config, element, newOffset, {});
|
|
531
|
+
dispatchUIEvent(config, element, "change");
|
|
532
|
+
}
|
|
533
|
+
} else {
|
|
534
|
+
commitInput(config, element, newOffset, {
|
|
535
|
+
data,
|
|
536
|
+
inputType
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
582
540
|
function calculateNewValue(inputData, node, {
|
|
583
541
|
startOffset,
|
|
584
542
|
endOffset
|
|
@@ -589,15 +547,12 @@ function calculateNewValue(inputData, node, {
|
|
|
589
547
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
590
548
|
const epilog = value.substring(epilogStart, value.length);
|
|
591
549
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
592
|
-
|
|
593
|
-
if (node
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
newValue = inputData;
|
|
599
|
-
} else {
|
|
600
|
-
newValue = value;
|
|
550
|
+
let newOffset = prologEnd + inputData.length;
|
|
551
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
552
|
+
const builtValue = buildTimeValue(newValue);
|
|
553
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
554
|
+
newValue = builtValue;
|
|
555
|
+
newOffset = builtValue.length;
|
|
601
556
|
}
|
|
602
557
|
}
|
|
603
558
|
return {
|
|
@@ -606,20 +561,21 @@ function calculateNewValue(inputData, node, {
|
|
|
606
561
|
newOffset
|
|
607
562
|
};
|
|
608
563
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
564
|
+
function commitInput(config, element, newOffset, inputInit) {
|
|
565
|
+
startTrackValue(element);
|
|
566
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
567
|
+
if (endTrackValue(element)) {
|
|
568
|
+
setSelection({
|
|
569
|
+
focusNode: element,
|
|
570
|
+
anchorOffset: newOffset,
|
|
571
|
+
focusOffset: newOffset
|
|
572
|
+
});
|
|
573
|
+
}
|
|
620
574
|
}
|
|
621
|
-
function
|
|
622
|
-
|
|
575
|
+
function isValidNumberInput(value) {
|
|
576
|
+
var _a, _b;
|
|
577
|
+
const valueParts = value.split("e", 2);
|
|
578
|
+
return !(/[^\d.\-e]/.test(value) || Number((_a = value.match(/-/g)) == null ? void 0 : _a.length) > 2 || Number((_b = value.match(/\./g)) == null ? void 0 : _b.length) > 1 || valueParts[1] && !/^-?\d*$/.test(valueParts[1]));
|
|
623
579
|
}
|
|
624
580
|
|
|
625
581
|
// src/utils/edit/isEditable.ts
|
|
@@ -645,161 +601,124 @@ function isEditableInput(element) {
|
|
|
645
601
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
646
602
|
}
|
|
647
603
|
|
|
648
|
-
// src/utils/
|
|
649
|
-
|
|
604
|
+
// src/utils/edit/setFiles.ts
|
|
605
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
606
|
+
function setFiles(el, files) {
|
|
650
607
|
var _a;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
return setSelection({
|
|
660
|
-
focusNode: element.firstChild,
|
|
661
|
-
anchorOffset,
|
|
662
|
-
focusOffset
|
|
608
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
609
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
610
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
611
|
+
function restore() {
|
|
612
|
+
Object.defineProperties(el, {
|
|
613
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
614
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
615
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
663
616
|
});
|
|
664
617
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
618
|
+
el[fakeFiles] = { restore };
|
|
619
|
+
Object.defineProperties(el, {
|
|
620
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
621
|
+
get: () => files
|
|
622
|
+
}),
|
|
623
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
624
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
625
|
+
set(v) {
|
|
626
|
+
var _a2;
|
|
627
|
+
if (v === "") {
|
|
628
|
+
restore();
|
|
629
|
+
} else {
|
|
630
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}),
|
|
634
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
635
|
+
set(v) {
|
|
636
|
+
if (v !== "file") {
|
|
637
|
+
restore();
|
|
638
|
+
el.type = v;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
})
|
|
642
|
+
});
|
|
687
643
|
}
|
|
688
|
-
|
|
689
|
-
|
|
644
|
+
|
|
645
|
+
// src/utils/misc/eventWrapper.ts
|
|
646
|
+
import { getConfig } from "@testing-library/dom";
|
|
647
|
+
function eventWrapper(cb) {
|
|
648
|
+
let result;
|
|
649
|
+
getConfig().eventWrapper(() => {
|
|
650
|
+
result = cb();
|
|
651
|
+
});
|
|
652
|
+
return result;
|
|
690
653
|
}
|
|
691
|
-
|
|
654
|
+
|
|
655
|
+
// src/utils/misc/isDisabled.ts
|
|
656
|
+
function isDisabled(element) {
|
|
692
657
|
var _a;
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
658
|
+
for (let el = element; el; el = el.parentElement) {
|
|
659
|
+
if (isElementType(el, [
|
|
660
|
+
"button",
|
|
661
|
+
"input",
|
|
662
|
+
"select",
|
|
663
|
+
"textarea",
|
|
664
|
+
"optgroup",
|
|
665
|
+
"option"
|
|
666
|
+
])) {
|
|
667
|
+
if (el.hasAttribute("disabled")) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
} else if (isElementType(el, "fieldset")) {
|
|
671
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
} else if (el.tagName.includes("-")) {
|
|
675
|
+
if (el.constructor.formAssociated && el.hasAttribute("disabled")) {
|
|
676
|
+
return true;
|
|
703
677
|
}
|
|
704
|
-
} else {
|
|
705
|
-
selection.setBaseAndExtent(element, 0, element, 0);
|
|
706
678
|
}
|
|
707
679
|
}
|
|
708
|
-
|
|
709
|
-
function getInputRange(focusNode) {
|
|
710
|
-
var _a;
|
|
711
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
712
|
-
if (typeAndSelection.type === "input") {
|
|
713
|
-
return typeAndSelection.selection;
|
|
714
|
-
} else if (typeAndSelection.type === "contenteditable") {
|
|
715
|
-
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
function setSelection({
|
|
719
|
-
focusNode,
|
|
720
|
-
focusOffset,
|
|
721
|
-
anchorNode = focusNode,
|
|
722
|
-
anchorOffset = focusOffset
|
|
723
|
-
}) {
|
|
724
|
-
var _a, _b;
|
|
725
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
726
|
-
if (typeAndSelection.type === "input") {
|
|
727
|
-
return setUISelection(focusNode, {
|
|
728
|
-
anchorOffset,
|
|
729
|
-
focusOffset
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
680
|
+
return false;
|
|
733
681
|
}
|
|
734
682
|
|
|
735
|
-
// src/utils/
|
|
736
|
-
function
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
anchorOffset: newSelection.offset,
|
|
746
|
-
focusOffset: newSelection.offset
|
|
747
|
-
});
|
|
748
|
-
startTrackValue(element);
|
|
749
|
-
fireEvent2.input(element, __spreadValues({}, eventOverrides));
|
|
750
|
-
const tracked = endTrackValue(element);
|
|
751
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
752
|
-
setSelection({
|
|
753
|
-
focusNode: newSelection.node,
|
|
754
|
-
anchorOffset: newSelection.offset,
|
|
755
|
-
focusOffset: newSelection.offset
|
|
756
|
-
});
|
|
683
|
+
// src/utils/focus/getActiveElement.ts
|
|
684
|
+
function getActiveElement(document2) {
|
|
685
|
+
const activeElement = document2.activeElement;
|
|
686
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
687
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
688
|
+
} else {
|
|
689
|
+
if (isDisabled(activeElement)) {
|
|
690
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
691
|
+
}
|
|
692
|
+
return activeElement;
|
|
757
693
|
}
|
|
758
694
|
}
|
|
759
695
|
|
|
760
|
-
// src/utils/
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
696
|
+
// src/utils/focus/selector.ts
|
|
697
|
+
var FOCUSABLE_SELECTOR = [
|
|
698
|
+
"input:not([type=hidden]):not([disabled])",
|
|
699
|
+
"button:not([disabled])",
|
|
700
|
+
"select:not([disabled])",
|
|
701
|
+
"textarea:not([disabled])",
|
|
702
|
+
'[contenteditable=""]',
|
|
703
|
+
'[contenteditable="true"]',
|
|
704
|
+
"a[href]",
|
|
705
|
+
"[tabindex]:not([disabled])"
|
|
706
|
+
].join(", ");
|
|
770
707
|
|
|
771
|
-
// src/utils/
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
maxLengthSupportedTypes2["password"] = "password";
|
|
775
|
-
maxLengthSupportedTypes2["search"] = "search";
|
|
776
|
-
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
777
|
-
maxLengthSupportedTypes2["text"] = "text";
|
|
778
|
-
maxLengthSupportedTypes2["url"] = "url";
|
|
779
|
-
return maxLengthSupportedTypes2;
|
|
780
|
-
})(maxLengthSupportedTypes || {});
|
|
781
|
-
function getSpaceUntilMaxLength(element) {
|
|
782
|
-
const value = getValue(element);
|
|
783
|
-
if (value === null) {
|
|
784
|
-
return void 0;
|
|
785
|
-
}
|
|
786
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
787
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
788
|
-
}
|
|
789
|
-
function getSanitizedMaxLength(element) {
|
|
790
|
-
var _a;
|
|
791
|
-
if (!supportsMaxLength(element)) {
|
|
792
|
-
return void 0;
|
|
793
|
-
}
|
|
794
|
-
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
795
|
-
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
796
|
-
}
|
|
797
|
-
function supportsMaxLength(element) {
|
|
798
|
-
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
708
|
+
// src/utils/focus/isFocusable.ts
|
|
709
|
+
function isFocusable(element) {
|
|
710
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
799
711
|
}
|
|
800
712
|
|
|
801
|
-
// src/utils/
|
|
802
|
-
|
|
713
|
+
// src/utils/focus/blur.ts
|
|
714
|
+
function blur(element) {
|
|
715
|
+
if (!isFocusable(element))
|
|
716
|
+
return;
|
|
717
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
718
|
+
if (!wasActive)
|
|
719
|
+
return;
|
|
720
|
+
eventWrapper(() => element.blur());
|
|
721
|
+
}
|
|
803
722
|
|
|
804
723
|
// src/utils/focus/cursor.ts
|
|
805
724
|
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
@@ -849,7 +768,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
849
768
|
}
|
|
850
769
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
851
770
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
852
|
-
if (offset !== void 0 &&
|
|
771
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
853
772
|
node = node.children[nextOffset];
|
|
854
773
|
}
|
|
855
774
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -858,7 +777,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
858
777
|
if (isTextNode(node)) {
|
|
859
778
|
return true;
|
|
860
779
|
}
|
|
861
|
-
if (
|
|
780
|
+
if (isElement(node)) {
|
|
862
781
|
if (isElementType(node, ["input", "textarea"])) {
|
|
863
782
|
return node.type !== "hidden";
|
|
864
783
|
} else if (isElementType(node, "br")) {
|
|
@@ -875,7 +794,7 @@ function getOffset(node) {
|
|
|
875
794
|
}
|
|
876
795
|
return i;
|
|
877
796
|
}
|
|
878
|
-
function
|
|
797
|
+
function isElement(node) {
|
|
879
798
|
return node.nodeType === 1;
|
|
880
799
|
}
|
|
881
800
|
function isTextNode(node) {
|
|
@@ -890,7 +809,7 @@ function walkNodes(node, direction, callback) {
|
|
|
890
809
|
if (callback(node)) {
|
|
891
810
|
return node;
|
|
892
811
|
}
|
|
893
|
-
} else if (node.parentNode && (!
|
|
812
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
894
813
|
node = node.parentNode;
|
|
895
814
|
} else {
|
|
896
815
|
break;
|
|
@@ -904,167 +823,116 @@ function getDescendant(node, direction) {
|
|
|
904
823
|
return node;
|
|
905
824
|
}
|
|
906
825
|
|
|
907
|
-
// src/utils/
|
|
908
|
-
function
|
|
909
|
-
|
|
910
|
-
if (
|
|
911
|
-
return
|
|
826
|
+
// src/utils/focus/selection.ts
|
|
827
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
828
|
+
var _a;
|
|
829
|
+
if (hasOwnSelection(element)) {
|
|
830
|
+
return setSelection({
|
|
831
|
+
focusNode: element,
|
|
832
|
+
anchorOffset,
|
|
833
|
+
focusOffset
|
|
834
|
+
});
|
|
912
835
|
}
|
|
913
|
-
if (
|
|
914
|
-
return {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
if (data) {
|
|
934
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
935
|
-
const offset = inputRange.endOffset;
|
|
936
|
-
inputRange.endContainer.insertData(offset, data);
|
|
937
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
938
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
939
|
-
} else {
|
|
940
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
941
|
-
inputRange.insertNode(text);
|
|
942
|
-
inputRange.setStart(text, data.length);
|
|
943
|
-
inputRange.setEnd(text, data.length);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
if (del || data) {
|
|
947
|
-
fireEvent3.input(element, { inputType });
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
} else {
|
|
836
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
837
|
+
return setSelection({
|
|
838
|
+
focusNode: element.firstChild,
|
|
839
|
+
anchorOffset,
|
|
840
|
+
focusOffset
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
844
|
+
}
|
|
845
|
+
function hasOwnSelection(node) {
|
|
846
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
847
|
+
}
|
|
848
|
+
function isElement2(node) {
|
|
849
|
+
return node.nodeType === 1;
|
|
850
|
+
}
|
|
851
|
+
function getTargetTypeAndSelection(node) {
|
|
852
|
+
const element = getElement2(node);
|
|
853
|
+
if (element && hasOwnSelection(element)) {
|
|
952
854
|
return {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
|
|
956
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
957
|
-
return;
|
|
958
|
-
}
|
|
959
|
-
editInputElement(element, {
|
|
960
|
-
newValue,
|
|
961
|
-
newSelection: {
|
|
962
|
-
node: element,
|
|
963
|
-
offset: newOffset
|
|
964
|
-
},
|
|
965
|
-
eventOverrides: {
|
|
966
|
-
inputType
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
}
|
|
855
|
+
type: "input",
|
|
856
|
+
selection: getUISelection(element)
|
|
970
857
|
};
|
|
971
858
|
}
|
|
859
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
860
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
861
|
+
return {
|
|
862
|
+
type: isCE ? "contenteditable" : "default",
|
|
863
|
+
selection
|
|
864
|
+
};
|
|
972
865
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
function
|
|
866
|
+
function getElement2(node) {
|
|
867
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
868
|
+
}
|
|
869
|
+
function updateSelectionOnFocus(element) {
|
|
977
870
|
var _a;
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
function restore() {
|
|
982
|
-
Object.defineProperties(el, {
|
|
983
|
-
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
984
|
-
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
985
|
-
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
986
|
-
});
|
|
871
|
+
const selection = element.ownerDocument.getSelection();
|
|
872
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
873
|
+
return;
|
|
987
874
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
995
|
-
set(v) {
|
|
996
|
-
var _a2;
|
|
997
|
-
if (v === "") {
|
|
998
|
-
restore();
|
|
999
|
-
} else {
|
|
1000
|
-
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
}),
|
|
1004
|
-
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
1005
|
-
set(v) {
|
|
1006
|
-
if (v !== "file") {
|
|
1007
|
-
restore();
|
|
1008
|
-
el.type = v;
|
|
1009
|
-
}
|
|
875
|
+
if (hasOwnSelection(element)) {
|
|
876
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
877
|
+
if (contenteditable) {
|
|
878
|
+
if (!selection.isCollapsed) {
|
|
879
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
880
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
1010
881
|
}
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
// src/utils/misc/eventWrapper.ts
|
|
1016
|
-
import { getConfig } from "@testing-library/dom";
|
|
1017
|
-
function eventWrapper(cb) {
|
|
1018
|
-
let result;
|
|
1019
|
-
getConfig().eventWrapper(() => {
|
|
1020
|
-
result = cb();
|
|
1021
|
-
});
|
|
1022
|
-
return result;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
// src/utils/misc/isDisabled.ts
|
|
1026
|
-
function isDisabled(element) {
|
|
1027
|
-
return Boolean(element && element.disabled);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
// src/utils/focus/getActiveElement.ts
|
|
1031
|
-
function getActiveElement(document2) {
|
|
1032
|
-
const activeElement = document2.activeElement;
|
|
1033
|
-
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
1034
|
-
return getActiveElement(activeElement.shadowRoot);
|
|
1035
|
-
} else {
|
|
1036
|
-
if (isDisabled(activeElement)) {
|
|
1037
|
-
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
882
|
+
} else {
|
|
883
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
1038
884
|
}
|
|
1039
|
-
return activeElement;
|
|
1040
885
|
}
|
|
1041
886
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
"input
|
|
1046
|
-
|
|
1047
|
-
"
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
'[contenteditable="true"]',
|
|
1051
|
-
"a[href]",
|
|
1052
|
-
"[tabindex]:not([disabled])"
|
|
1053
|
-
].join(", ");
|
|
1054
|
-
|
|
1055
|
-
// src/utils/focus/isFocusable.ts
|
|
1056
|
-
function isFocusable(element) {
|
|
1057
|
-
return element.matches(FOCUSABLE_SELECTOR);
|
|
887
|
+
function getInputRange(focusNode) {
|
|
888
|
+
var _a;
|
|
889
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
890
|
+
if (typeAndSelection.type === "input") {
|
|
891
|
+
return typeAndSelection.selection;
|
|
892
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
893
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
894
|
+
}
|
|
1058
895
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
896
|
+
function setSelection({
|
|
897
|
+
focusNode,
|
|
898
|
+
focusOffset,
|
|
899
|
+
anchorNode = focusNode,
|
|
900
|
+
anchorOffset = focusOffset
|
|
901
|
+
}) {
|
|
902
|
+
var _a, _b;
|
|
903
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
904
|
+
if (typeAndSelection.type === "input") {
|
|
905
|
+
return setUISelection(focusNode, {
|
|
906
|
+
anchorOffset,
|
|
907
|
+
focusOffset
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
911
|
+
}
|
|
912
|
+
function moveSelection(node, direction) {
|
|
913
|
+
if (hasOwnSelection(node)) {
|
|
914
|
+
const selection = getUISelection(node);
|
|
915
|
+
setSelection({
|
|
916
|
+
focusNode: node,
|
|
917
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
918
|
+
});
|
|
919
|
+
} else {
|
|
920
|
+
const selection = node.ownerDocument.getSelection();
|
|
921
|
+
if (!selection) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (selection.isCollapsed) {
|
|
925
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
926
|
+
if (nextPosition) {
|
|
927
|
+
setSelection({
|
|
928
|
+
focusNode: nextPosition.node,
|
|
929
|
+
focusOffset: nextPosition.offset
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
} else {
|
|
933
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
934
|
+
}
|
|
935
|
+
}
|
|
1068
936
|
}
|
|
1069
937
|
|
|
1070
938
|
// src/utils/focus/copySelection.ts
|
|
@@ -1204,6 +1072,14 @@ function isAllSelected(target) {
|
|
|
1204
1072
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1205
1073
|
}
|
|
1206
1074
|
|
|
1075
|
+
// src/utils/keyboard/getKeyEventProps.ts
|
|
1076
|
+
function getKeyEventProps(keyDef) {
|
|
1077
|
+
return {
|
|
1078
|
+
key: keyDef.key,
|
|
1079
|
+
code: keyDef.code
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1207
1083
|
// src/utils/keyboard/getUIEventModifiers.ts
|
|
1208
1084
|
function getUIEventModifiers(keyboardState) {
|
|
1209
1085
|
return {
|
|
@@ -1222,21 +1098,13 @@ function getUIEventModifiers(keyboardState) {
|
|
|
1222
1098
|
};
|
|
1223
1099
|
}
|
|
1224
1100
|
|
|
1225
|
-
// src/utils/keyboard/getKeyEventProps.ts
|
|
1226
|
-
function getKeyEventProps(keyDef, state) {
|
|
1227
|
-
return __spreadValues({
|
|
1228
|
-
key: keyDef.key,
|
|
1229
|
-
code: keyDef.code
|
|
1230
|
-
}, getUIEventModifiers(state));
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
1101
|
// src/utils/keyDef/readNextDescriptor.ts
|
|
1234
1102
|
var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
1235
1103
|
bracketDict2["{"] = "}";
|
|
1236
1104
|
bracketDict2["["] = "]";
|
|
1237
1105
|
return bracketDict2;
|
|
1238
1106
|
})(bracketDict || {});
|
|
1239
|
-
function readNextDescriptor(text) {
|
|
1107
|
+
function readNextDescriptor(text, context) {
|
|
1240
1108
|
let pos = 0;
|
|
1241
1109
|
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
1242
1110
|
pos += startBracket.length;
|
|
@@ -1244,11 +1112,11 @@ function readNextDescriptor(text) {
|
|
|
1244
1112
|
const type3 = isEscapedChar ? "" : startBracket;
|
|
1245
1113
|
return __spreadValues({
|
|
1246
1114
|
type: type3
|
|
1247
|
-
}, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
|
|
1115
|
+
}, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
|
|
1248
1116
|
}
|
|
1249
|
-
function readPrintableChar(text, pos) {
|
|
1117
|
+
function readPrintableChar(text, pos, context) {
|
|
1250
1118
|
const descriptor = text[pos];
|
|
1251
|
-
assertDescriptor(descriptor, text, pos);
|
|
1119
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1252
1120
|
pos += descriptor.length;
|
|
1253
1121
|
return {
|
|
1254
1122
|
consumedLength: pos,
|
|
@@ -1258,14 +1126,14 @@ function readPrintableChar(text, pos) {
|
|
|
1258
1126
|
repeat: 1
|
|
1259
1127
|
};
|
|
1260
1128
|
}
|
|
1261
|
-
function readTag(text, pos, startBracket) {
|
|
1129
|
+
function readTag(text, pos, startBracket, context) {
|
|
1262
1130
|
var _a, _b, _c;
|
|
1263
1131
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1264
1132
|
pos += releasePreviousModifier.length;
|
|
1265
1133
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1266
1134
|
pos += Number(escapedDescriptor);
|
|
1267
1135
|
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1268
|
-
assertDescriptor(descriptor, text, pos);
|
|
1136
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1269
1137
|
pos += descriptor.length;
|
|
1270
1138
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
1271
1139
|
pos += repeatModifier.length;
|
|
@@ -1278,7 +1146,7 @@ function readTag(text, pos, startBracket) {
|
|
|
1278
1146
|
!repeatModifier && "repeat modifier",
|
|
1279
1147
|
!releaseSelfModifier && "release modifier",
|
|
1280
1148
|
`"${expectedEndBracket}"`
|
|
1281
|
-
].filter(Boolean).join(" or "), text[pos], text));
|
|
1149
|
+
].filter(Boolean).join(" or "), text[pos], text, context));
|
|
1282
1150
|
}
|
|
1283
1151
|
pos += endBracket.length;
|
|
1284
1152
|
return {
|
|
@@ -1289,9 +1157,9 @@ function readTag(text, pos, startBracket) {
|
|
|
1289
1157
|
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
1290
1158
|
};
|
|
1291
1159
|
}
|
|
1292
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
1160
|
+
function assertDescriptor(descriptor, text, pos, context) {
|
|
1293
1161
|
if (!descriptor) {
|
|
1294
|
-
throw new Error(getErrorMessage("key descriptor", text[pos], text));
|
|
1162
|
+
throw new Error(getErrorMessage("key descriptor", text[pos], text, context));
|
|
1295
1163
|
}
|
|
1296
1164
|
}
|
|
1297
1165
|
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
@@ -1302,12 +1170,17 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
1302
1170
|
return false;
|
|
1303
1171
|
}
|
|
1304
1172
|
}
|
|
1305
|
-
function getErrorMessage(expected, found, text) {
|
|
1173
|
+
function getErrorMessage(expected, found, text, context) {
|
|
1306
1174
|
return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
|
|
1307
|
-
See https://
|
|
1175
|
+
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`}
|
|
1308
1176
|
for more information about how userEvent parses your input.`;
|
|
1309
1177
|
}
|
|
1310
1178
|
|
|
1179
|
+
// src/utils/misc/cloneEvent.ts
|
|
1180
|
+
function cloneEvent(event) {
|
|
1181
|
+
return new event.constructor(event.type, event);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1311
1184
|
// src/utils/misc/getDocumentFromNode.ts
|
|
1312
1185
|
function getDocumentFromNode(el) {
|
|
1313
1186
|
return isDocument(el) ? el : el.ownerDocument;
|
|
@@ -1345,9 +1218,6 @@ function wait(time) {
|
|
|
1345
1218
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1346
1219
|
}
|
|
1347
1220
|
|
|
1348
|
-
// src/utils/misc/hasFormSubmit.ts
|
|
1349
|
-
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1350
|
-
|
|
1351
1221
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1352
1222
|
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1353
1223
|
|
|
@@ -1474,10 +1344,6 @@ function hasBitFlag(conf, flag) {
|
|
|
1474
1344
|
return (conf & flag) > 0;
|
|
1475
1345
|
}
|
|
1476
1346
|
|
|
1477
|
-
// src/utils/pointer/firePointerEvents.ts
|
|
1478
|
-
import { createEvent, fireEvent as fireEvent4 } from "@testing-library/dom";
|
|
1479
|
-
import { eventMap } from "@testing-library/dom/dist/event-map.js";
|
|
1480
|
-
|
|
1481
1347
|
// src/utils/pointer/mouseButtons.ts
|
|
1482
1348
|
var MouseButton = {
|
|
1483
1349
|
primary: 0,
|
|
@@ -1509,38 +1375,41 @@ function getMouseButtons(...buttons) {
|
|
|
1509
1375
|
return v;
|
|
1510
1376
|
}
|
|
1511
1377
|
|
|
1512
|
-
// src/
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
clickCount
|
|
1522
|
-
}) {
|
|
1523
|
-
const init = __spreadValues(__spreadValues({}, coords), getUIEventModifiers(keyboardState));
|
|
1524
|
-
if (type3 === "click" || type3.startsWith("pointer")) {
|
|
1525
|
-
init.pointerId = pointerId;
|
|
1526
|
-
init.pointerType = pointerType;
|
|
1527
|
-
}
|
|
1528
|
-
if (["pointerdown", "pointerup"].includes(type3)) {
|
|
1529
|
-
init.isPrimary = isPrimary;
|
|
1378
|
+
// src/event/createEvent.ts
|
|
1379
|
+
import { createEvent as createEventBase } from "@testing-library/dom";
|
|
1380
|
+
|
|
1381
|
+
// src/event/eventMap.ts
|
|
1382
|
+
import { eventMap as baseEventMap } from "@testing-library/dom/dist/event-map.js";
|
|
1383
|
+
var eventMap = __spreadProps(__spreadValues({}, baseEventMap), {
|
|
1384
|
+
beforeInput: {
|
|
1385
|
+
EventType: "InputEvent",
|
|
1386
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1530
1387
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1388
|
+
});
|
|
1389
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1390
|
+
|
|
1391
|
+
// src/event/eventTypes.ts
|
|
1392
|
+
import { eventMap as eventMap2 } from "@testing-library/dom/dist/event-map.js";
|
|
1393
|
+
var eventKeys = Object.fromEntries(Object.keys(eventMap2).map((k) => [k.toLowerCase(), k]));
|
|
1394
|
+
function getEventClass(type3) {
|
|
1395
|
+
return type3 in eventKeys ? eventMap2[eventKeys[type3]].EventType : "Event";
|
|
1396
|
+
}
|
|
1397
|
+
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1398
|
+
function isMouseEvent(type3) {
|
|
1399
|
+
return mouseEvents.includes(getEventClass(type3));
|
|
1400
|
+
}
|
|
1401
|
+
function isKeyboardEvent(type3) {
|
|
1402
|
+
return getEventClass(type3) === "KeyboardEvent";
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// src/event/createEvent.ts
|
|
1406
|
+
function createEvent(type3, target, init) {
|
|
1407
|
+
const event = createEventBase(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1408
|
+
if (isMouseEvent(type3) && init) {
|
|
1409
|
+
assignPositionInit(event, init);
|
|
1410
|
+
assignPointerInit(event, init);
|
|
1538
1411
|
}
|
|
1539
|
-
|
|
1540
|
-
const event = createEvent[eventKey](target, init);
|
|
1541
|
-
assignPositionInit(event, init);
|
|
1542
|
-
assignPointerInit(event, init);
|
|
1543
|
-
return fireEvent4(target, event);
|
|
1412
|
+
return event;
|
|
1544
1413
|
}
|
|
1545
1414
|
function assignProps(obj, props) {
|
|
1546
1415
|
for (const [key, value] of Object.entries(props)) {
|
|
@@ -1573,273 +1442,430 @@ function assignPositionInit(obj, {
|
|
|
1573
1442
|
screenY: screenY != null ? screenY : 0
|
|
1574
1443
|
});
|
|
1575
1444
|
}
|
|
1576
|
-
function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
1577
|
-
assignProps(obj, {
|
|
1578
|
-
isPrimary,
|
|
1579
|
-
pointerId,
|
|
1580
|
-
pointerType
|
|
1445
|
+
function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
1446
|
+
assignProps(obj, {
|
|
1447
|
+
isPrimary,
|
|
1448
|
+
pointerId,
|
|
1449
|
+
pointerType
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
// src/event/behavior/registry.ts
|
|
1454
|
+
var behavior = {};
|
|
1455
|
+
|
|
1456
|
+
// src/event/behavior/click.ts
|
|
1457
|
+
behavior.click = (event, target, config) => {
|
|
1458
|
+
const context = target.closest("button,input,label,select,textarea");
|
|
1459
|
+
const control = context && isElementType(context, "label") && context.control;
|
|
1460
|
+
if (control) {
|
|
1461
|
+
return () => {
|
|
1462
|
+
if (isFocusable(control)) {
|
|
1463
|
+
focus(control);
|
|
1464
|
+
}
|
|
1465
|
+
dispatchEvent(config, control, cloneEvent(event));
|
|
1466
|
+
};
|
|
1467
|
+
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1468
|
+
return () => {
|
|
1469
|
+
blur(target);
|
|
1470
|
+
target.dispatchEvent(new Event("fileDialog"));
|
|
1471
|
+
focus(target);
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
// src/event/behavior/cut.ts
|
|
1477
|
+
behavior.cut = (event, target, config) => {
|
|
1478
|
+
return () => {
|
|
1479
|
+
if (isEditable(target)) {
|
|
1480
|
+
input(config, target, "", "deleteByCut");
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
// src/event/behavior/keydown.ts
|
|
1486
|
+
behavior.keydown = (event, target, config) => {
|
|
1487
|
+
var _a, _b;
|
|
1488
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1489
|
+
};
|
|
1490
|
+
var keydownBehavior = {
|
|
1491
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1492
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1493
|
+
Backspace: (event, target, config) => {
|
|
1494
|
+
if (isEditable(target)) {
|
|
1495
|
+
return () => {
|
|
1496
|
+
input(config, target, "", "deleteContentBackward");
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
Delete: (event, target, config) => {
|
|
1501
|
+
if (isEditable(target)) {
|
|
1502
|
+
return () => {
|
|
1503
|
+
input(config, target, "", "deleteContentForward");
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
End: (event, target) => {
|
|
1508
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1509
|
+
return () => {
|
|
1510
|
+
var _a, _b;
|
|
1511
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1512
|
+
setSelectionRange(target, newPos, newPos);
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
},
|
|
1516
|
+
Home: (event, target) => {
|
|
1517
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1518
|
+
return () => {
|
|
1519
|
+
setSelectionRange(target, 0, 0);
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
PageDown: (event, target) => {
|
|
1524
|
+
if (isElementType(target, ["input"])) {
|
|
1525
|
+
return () => {
|
|
1526
|
+
const newPos = getValue(target).length;
|
|
1527
|
+
setSelectionRange(target, newPos, newPos);
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
},
|
|
1531
|
+
PageUp: (event, target) => {
|
|
1532
|
+
if (isElementType(target, ["input"])) {
|
|
1533
|
+
return () => {
|
|
1534
|
+
setSelectionRange(target, 0, 0);
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1539
|
+
return () => {
|
|
1540
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1541
|
+
focus(dest);
|
|
1542
|
+
if (hasOwnSelection(dest)) {
|
|
1543
|
+
setUISelection(dest, {
|
|
1544
|
+
anchorOffset: 0,
|
|
1545
|
+
focusOffset: dest.value.length
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
var combinationBehavior = (event, target, config) => {
|
|
1552
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1553
|
+
return () => selectAll(target);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// src/event/behavior/keypress.ts
|
|
1558
|
+
behavior.keypress = (event, target, config) => {
|
|
1559
|
+
if (event.key === "Enter") {
|
|
1560
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1561
|
+
return () => {
|
|
1562
|
+
dispatchUIEvent(config, target, "click");
|
|
1563
|
+
};
|
|
1564
|
+
} else if (isElementType(target, "input")) {
|
|
1565
|
+
const form = target.form;
|
|
1566
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1567
|
+
if (submit) {
|
|
1568
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1569
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1570
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1571
|
+
} else {
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
if (isEditable(target)) {
|
|
1577
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1578
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1579
|
+
return () => input(config, target, inputData, inputType);
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
var ClickInputOnEnter = [
|
|
1583
|
+
"button",
|
|
1584
|
+
"color",
|
|
1585
|
+
"file",
|
|
1586
|
+
"image",
|
|
1587
|
+
"reset",
|
|
1588
|
+
"submit"
|
|
1589
|
+
];
|
|
1590
|
+
var SubmitSingleInputOnEnter = [
|
|
1591
|
+
"email",
|
|
1592
|
+
"month",
|
|
1593
|
+
"password",
|
|
1594
|
+
"search",
|
|
1595
|
+
"tel",
|
|
1596
|
+
"text",
|
|
1597
|
+
"url",
|
|
1598
|
+
"week"
|
|
1599
|
+
];
|
|
1600
|
+
|
|
1601
|
+
// src/event/behavior/keyup.ts
|
|
1602
|
+
behavior.keyup = (event, target, config) => {
|
|
1603
|
+
var _a;
|
|
1604
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1605
|
+
};
|
|
1606
|
+
var keyupBehavior = {
|
|
1607
|
+
" ": (event, target, config) => {
|
|
1608
|
+
if (isClickableInput(target)) {
|
|
1609
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
// src/event/behavior/paste.ts
|
|
1615
|
+
behavior.paste = (event, target, config) => {
|
|
1616
|
+
if (isEditable(target)) {
|
|
1617
|
+
return () => {
|
|
1618
|
+
var _a;
|
|
1619
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1620
|
+
if (insertData) {
|
|
1621
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
|
|
1627
|
+
// src/event/wrapEvent.ts
|
|
1628
|
+
import { getConfig as getConfig2 } from "@testing-library/dom";
|
|
1629
|
+
function wrapEvent(cb, _element) {
|
|
1630
|
+
return getConfig2().eventWrapper(cb);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// src/event/dispatchEvent.ts
|
|
1634
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1635
|
+
var _a, _b;
|
|
1636
|
+
const type3 = event.type;
|
|
1637
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1638
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1639
|
+
if (behaviorImplementation) {
|
|
1640
|
+
event.preventDefault();
|
|
1641
|
+
let defaultPrevented = false;
|
|
1642
|
+
Object.defineProperty(event, "defaultPrevented", {
|
|
1643
|
+
get: () => defaultPrevented
|
|
1644
|
+
});
|
|
1645
|
+
Object.defineProperty(event, "preventDefault", {
|
|
1646
|
+
value: () => {
|
|
1647
|
+
defaultPrevented = event.cancelable;
|
|
1648
|
+
}
|
|
1649
|
+
});
|
|
1650
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1651
|
+
if (!defaultPrevented) {
|
|
1652
|
+
behaviorImplementation();
|
|
1653
|
+
}
|
|
1654
|
+
return !defaultPrevented;
|
|
1655
|
+
}
|
|
1656
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
// src/event/index.ts
|
|
1660
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1661
|
+
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1662
|
+
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1663
|
+
}
|
|
1664
|
+
const event = createEvent(type3, target, init);
|
|
1665
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1666
|
+
}
|
|
1667
|
+
function bindDispatchUIEvent(config) {
|
|
1668
|
+
return dispatchUIEvent.bind(void 0, config);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// src/document/interceptor.ts
|
|
1672
|
+
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
1673
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
1674
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
1675
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1676
|
+
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1677
|
+
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
function intercept(...args) {
|
|
1681
|
+
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
1682
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
1683
|
+
if (target === "set") {
|
|
1684
|
+
realFunc.call(this, realArgs);
|
|
1685
|
+
} else {
|
|
1686
|
+
realFunc.call(this, ...realArgs);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
;
|
|
1690
|
+
intercept[Interceptor] = Interceptor;
|
|
1691
|
+
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
1692
|
+
[target]: intercept
|
|
1693
|
+
}));
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// src/document/selection.ts
|
|
1697
|
+
var UISelection = Symbol("Displayed selection in UI");
|
|
1698
|
+
function prepareSelectionInterceptor(element) {
|
|
1699
|
+
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
1700
|
+
const isUI = start && typeof start === "object" && start[UISelection];
|
|
1701
|
+
if (!isUI) {
|
|
1702
|
+
this[UISelection] = void 0;
|
|
1703
|
+
}
|
|
1704
|
+
return {
|
|
1705
|
+
realArgs: [Number(start), end, direction]
|
|
1706
|
+
};
|
|
1707
|
+
});
|
|
1708
|
+
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
1709
|
+
this[UISelection] = void 0;
|
|
1710
|
+
return { realArgs: v };
|
|
1711
|
+
});
|
|
1712
|
+
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
1713
|
+
this[UISelection] = void 0;
|
|
1714
|
+
return { realArgs: v };
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
function setUISelection(element, {
|
|
1718
|
+
focusOffset: focusOffsetParam,
|
|
1719
|
+
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
1720
|
+
}, mode = "replace") {
|
|
1721
|
+
const valueLength = getUIValue(element).length;
|
|
1722
|
+
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
1723
|
+
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
1724
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
1725
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
1726
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
1727
|
+
element[UISelection] = {
|
|
1728
|
+
anchorOffset,
|
|
1729
|
+
focusOffset
|
|
1730
|
+
};
|
|
1731
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
const startObj = new Number(startOffset);
|
|
1735
|
+
startObj[UISelection] = UISelection;
|
|
1736
|
+
try {
|
|
1737
|
+
element.setSelectionRange(startObj, endOffset);
|
|
1738
|
+
} catch (e) {
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
function getUISelection(element) {
|
|
1742
|
+
var _a, _b, _c;
|
|
1743
|
+
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1744
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1745
|
+
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1746
|
+
};
|
|
1747
|
+
return __spreadProps(__spreadValues({}, sel), {
|
|
1748
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
1749
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
// src/document/value.ts
|
|
1754
|
+
var UIValue = Symbol("Displayed value in UI");
|
|
1755
|
+
var InitialValue = Symbol("Initial value to compare on blur");
|
|
1756
|
+
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1757
|
+
function valueInterceptor(v) {
|
|
1758
|
+
const isUI = typeof v === "object" && v[UIValue];
|
|
1759
|
+
if (isUI) {
|
|
1760
|
+
this[UIValue] = String(v);
|
|
1761
|
+
setPreviousValue(this, String(this.value));
|
|
1762
|
+
} else {
|
|
1763
|
+
trackOrSetValue(this, String(v));
|
|
1764
|
+
}
|
|
1765
|
+
return {
|
|
1766
|
+
applyNative: !!isUI,
|
|
1767
|
+
realArgs: sanitizeValue(this, v)
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
function sanitizeValue(element, v) {
|
|
1771
|
+
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) {
|
|
1772
|
+
return String(Number(v));
|
|
1773
|
+
}
|
|
1774
|
+
return String(v);
|
|
1775
|
+
}
|
|
1776
|
+
function prepareValueInterceptor(element) {
|
|
1777
|
+
prepareInterceptor(element, "value", valueInterceptor);
|
|
1778
|
+
}
|
|
1779
|
+
function setUIValue(element, value) {
|
|
1780
|
+
element.value = {
|
|
1781
|
+
[UIValue]: UIValue,
|
|
1782
|
+
toString: () => value
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
function getUIValue(element) {
|
|
1786
|
+
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
1787
|
+
}
|
|
1788
|
+
function setInitialValue(element) {
|
|
1789
|
+
element[InitialValue] = element.value;
|
|
1790
|
+
}
|
|
1791
|
+
function getInitialValue(element) {
|
|
1792
|
+
return element[InitialValue];
|
|
1793
|
+
}
|
|
1794
|
+
function setPreviousValue(element, v) {
|
|
1795
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
|
|
1796
|
+
}
|
|
1797
|
+
function startTrackValue(element) {
|
|
1798
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
|
|
1799
|
+
nextValue: String(element.value),
|
|
1800
|
+
tracked: []
|
|
1581
1801
|
});
|
|
1582
1802
|
}
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
{
|
|
1587
|
-
|
|
1588
|
-
handle: (keyDef, element) => {
|
|
1589
|
-
if (hasOwnSelection(element)) {
|
|
1590
|
-
const selection = getUISelection(element);
|
|
1591
|
-
setSelection({
|
|
1592
|
-
focusNode: element,
|
|
1593
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1594
|
-
});
|
|
1595
|
-
} else {
|
|
1596
|
-
const selection = element.ownerDocument.getSelection();
|
|
1597
|
-
if (!selection) {
|
|
1598
|
-
return;
|
|
1599
|
-
}
|
|
1600
|
-
if (selection.isCollapsed) {
|
|
1601
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1602
|
-
if (nextPosition) {
|
|
1603
|
-
setSelection({
|
|
1604
|
-
focusNode: nextPosition.node,
|
|
1605
|
-
focusOffset: nextPosition.offset
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
} else {
|
|
1609
|
-
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
];
|
|
1615
|
-
|
|
1616
|
-
// src/keyboard/plugins/control.ts
|
|
1617
|
-
var keydownBehavior2 = [
|
|
1618
|
-
{
|
|
1619
|
-
matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
|
|
1620
|
-
handle: (keyDef, element) => {
|
|
1621
|
-
var _a, _b;
|
|
1622
|
-
if (keyDef.key === "Home") {
|
|
1623
|
-
setSelectionRange(element, 0, 0);
|
|
1624
|
-
} else {
|
|
1625
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1626
|
-
setSelectionRange(element, newPos, newPos);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
},
|
|
1630
|
-
{
|
|
1631
|
-
matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
|
|
1632
|
-
handle: (keyDef, element) => {
|
|
1633
|
-
var _a, _b;
|
|
1634
|
-
if (keyDef.key === "PageUp") {
|
|
1635
|
-
setSelectionRange(element, 0, 0);
|
|
1636
|
-
} else {
|
|
1637
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1638
|
-
setSelectionRange(element, newPos, newPos);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
},
|
|
1642
|
-
{
|
|
1643
|
-
matches: (keyDef, element) => keyDef.key === "Delete" && isEditable(element),
|
|
1644
|
-
handle: (keDef, element) => {
|
|
1645
|
-
var _a;
|
|
1646
|
-
(_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1647
|
-
}
|
|
1803
|
+
function trackOrSetValue(element, v) {
|
|
1804
|
+
var _a, _b, _c;
|
|
1805
|
+
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1806
|
+
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1807
|
+
setCleanValue(element, v);
|
|
1648
1808
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1809
|
+
}
|
|
1810
|
+
function setCleanValue(element, v) {
|
|
1811
|
+
element[UIValue] = void 0;
|
|
1812
|
+
element[InitialValue] = v;
|
|
1813
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1814
|
+
}
|
|
1815
|
+
function endTrackValue(element) {
|
|
1816
|
+
var _a, _b;
|
|
1817
|
+
const changes = element[TrackChanges];
|
|
1818
|
+
element[TrackChanges] = void 0;
|
|
1819
|
+
const isJustReactStateUpdate = ((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length) === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === changes.nextValue;
|
|
1820
|
+
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1821
|
+
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1659
1822
|
}
|
|
1823
|
+
return isJustReactStateUpdate;
|
|
1660
1824
|
}
|
|
1661
1825
|
|
|
1662
|
-
// src/
|
|
1663
|
-
var
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1668
|
-
},
|
|
1669
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1670
|
-
var _a;
|
|
1671
|
-
let newEntry = keyDef.key;
|
|
1672
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1673
|
-
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1674
|
-
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1675
|
-
newEntry = timeNewEntry;
|
|
1676
|
-
}
|
|
1677
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1678
|
-
const prevValue = getValue(element);
|
|
1679
|
-
if (prevValue !== newValue) {
|
|
1680
|
-
editInputElement(element, {
|
|
1681
|
-
newValue,
|
|
1682
|
-
newSelection: {
|
|
1683
|
-
node: element,
|
|
1684
|
-
offset: newOffset
|
|
1685
|
-
},
|
|
1686
|
-
eventOverrides: {
|
|
1687
|
-
data: keyDef.key,
|
|
1688
|
-
inputType: "insertText"
|
|
1689
|
-
}
|
|
1690
|
-
});
|
|
1691
|
-
}
|
|
1692
|
-
fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
|
|
1693
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1694
|
-
}
|
|
1695
|
-
},
|
|
1696
|
-
{
|
|
1697
|
-
matches: (keyDef, element) => {
|
|
1698
|
-
var _a;
|
|
1699
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1700
|
-
},
|
|
1701
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1702
|
-
var _a;
|
|
1703
|
-
let newEntry = keyDef.key;
|
|
1704
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1705
|
-
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1706
|
-
if (isValidToBeTyped) {
|
|
1707
|
-
newEntry = textToBeTyped;
|
|
1708
|
-
}
|
|
1709
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1710
|
-
const prevValue = getValue(element);
|
|
1711
|
-
if (prevValue !== newValue) {
|
|
1712
|
-
editInputElement(element, {
|
|
1713
|
-
newValue,
|
|
1714
|
-
newSelection: {
|
|
1715
|
-
node: element,
|
|
1716
|
-
offset: newOffset
|
|
1717
|
-
},
|
|
1718
|
-
eventOverrides: {
|
|
1719
|
-
data: keyDef.key,
|
|
1720
|
-
inputType: "insertText"
|
|
1721
|
-
}
|
|
1722
|
-
});
|
|
1723
|
-
}
|
|
1724
|
-
if (isValidToBeTyped) {
|
|
1725
|
-
fireEvent6.change(element, {
|
|
1726
|
-
target: { value: textToBeTyped }
|
|
1727
|
-
});
|
|
1728
|
-
}
|
|
1729
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1730
|
-
}
|
|
1731
|
-
},
|
|
1732
|
-
{
|
|
1733
|
-
matches: (keyDef, element) => {
|
|
1734
|
-
var _a;
|
|
1735
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1736
|
-
},
|
|
1737
|
-
handle: (keyDef, element) => {
|
|
1738
|
-
var _a, _b;
|
|
1739
|
-
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1740
|
-
return;
|
|
1741
|
-
}
|
|
1742
|
-
const { getNewValue, commit } = prepareInput(keyDef.key, element);
|
|
1743
|
-
const newValue = getNewValue();
|
|
1744
|
-
const valueParts = newValue.split("e", 2);
|
|
1745
|
-
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])) {
|
|
1746
|
-
return;
|
|
1747
|
-
}
|
|
1748
|
-
commit();
|
|
1749
|
-
}
|
|
1750
|
-
},
|
|
1751
|
-
{
|
|
1752
|
-
matches: (keyDef, element) => {
|
|
1753
|
-
var _a;
|
|
1754
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1755
|
-
},
|
|
1756
|
-
handle: (keyDef, element) => {
|
|
1757
|
-
var _a;
|
|
1758
|
-
(_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1759
|
-
}
|
|
1760
|
-
},
|
|
1761
|
-
{
|
|
1762
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1763
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1764
|
-
var _a;
|
|
1765
|
-
(_a = prepareInput("\n", element, isContentEditable(element) && !keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1766
|
-
}
|
|
1826
|
+
// src/document/index.ts
|
|
1827
|
+
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1828
|
+
function prepareDocument(document2) {
|
|
1829
|
+
if (document2[isPrepared]) {
|
|
1830
|
+
return;
|
|
1767
1831
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
(_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1778
|
-
}
|
|
1779
|
-
},
|
|
1780
|
-
{
|
|
1781
|
-
matches: (keyDef) => keyDef.key === "Tab",
|
|
1782
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1783
|
-
const dest = getTabDestination(element, keyboardState.modifiers.Shift);
|
|
1784
|
-
if (dest === element.ownerDocument.body) {
|
|
1785
|
-
blur(element);
|
|
1786
|
-
} else {
|
|
1787
|
-
focus(dest);
|
|
1788
|
-
if (isElementType(dest, ["input", "textarea"])) {
|
|
1789
|
-
setUISelection(dest, {
|
|
1790
|
-
anchorOffset: 0,
|
|
1791
|
-
focusOffset: dest.value.length
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1832
|
+
document2.addEventListener("focus", (e) => {
|
|
1833
|
+
const el = e.target;
|
|
1834
|
+
prepareElement(el);
|
|
1835
|
+
}, {
|
|
1836
|
+
capture: true,
|
|
1837
|
+
passive: true
|
|
1838
|
+
});
|
|
1839
|
+
if (document2.activeElement) {
|
|
1840
|
+
prepareElement(document2.activeElement);
|
|
1796
1841
|
}
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
const form = element.form;
|
|
1803
|
-
if (hasFormSubmit(form)) {
|
|
1804
|
-
fireEvent7.submit(form);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
},
|
|
1808
|
-
{
|
|
1809
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1810
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1811
|
-
fireEvent7.click(element, getUIEventModifiers(keyboardState));
|
|
1812
|
-
}
|
|
1813
|
-
},
|
|
1814
|
-
{
|
|
1815
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1816
|
-
handle: (keyDef, element) => {
|
|
1817
|
-
const form = element.form;
|
|
1818
|
-
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1819
|
-
fireEvent7.submit(form);
|
|
1820
|
-
}
|
|
1842
|
+
document2.addEventListener("blur", (e) => {
|
|
1843
|
+
const el = e.target;
|
|
1844
|
+
const initialValue = getInitialValue(el);
|
|
1845
|
+
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
1846
|
+
dispatchUIEvent({}, el, "change");
|
|
1821
1847
|
}
|
|
1848
|
+
}, {
|
|
1849
|
+
capture: true,
|
|
1850
|
+
passive: true
|
|
1851
|
+
});
|
|
1852
|
+
document2[isPrepared] = isPrepared;
|
|
1853
|
+
}
|
|
1854
|
+
function prepareElement(el) {
|
|
1855
|
+
if ("value" in el) {
|
|
1856
|
+
setInitialValue(el);
|
|
1822
1857
|
}
|
|
1823
|
-
]
|
|
1824
|
-
|
|
1825
|
-
{
|
|
1826
|
-
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1827
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1828
|
-
fireEvent7.click(element, getUIEventModifiers(keyboardState));
|
|
1829
|
-
}
|
|
1858
|
+
if (el[isPrepared]) {
|
|
1859
|
+
return;
|
|
1830
1860
|
}
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
var keydownBehavior4 = [
|
|
1835
|
-
{
|
|
1836
|
-
matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
|
|
1837
|
-
handle: (keyDef, element) => selectAll(element)
|
|
1861
|
+
if ("value" in el) {
|
|
1862
|
+
prepareValueInterceptor(el);
|
|
1863
|
+
prepareSelectionInterceptor(el);
|
|
1838
1864
|
}
|
|
1839
|
-
];
|
|
1865
|
+
el[isPrepared] = isPrepared;
|
|
1866
|
+
}
|
|
1840
1867
|
|
|
1841
|
-
// src/keyboard/
|
|
1842
|
-
import { fireEvent as fireEvent8 } from "@testing-library/dom";
|
|
1868
|
+
// src/keyboard/modifiers.ts
|
|
1843
1869
|
var modifierKeys = [
|
|
1844
1870
|
"Alt",
|
|
1845
1871
|
"AltGraph",
|
|
@@ -1849,6 +1875,9 @@ var modifierKeys = [
|
|
|
1849
1875
|
"Shift",
|
|
1850
1876
|
"Symbol"
|
|
1851
1877
|
];
|
|
1878
|
+
function isModifierKey(key) {
|
|
1879
|
+
return modifierKeys.includes(key);
|
|
1880
|
+
}
|
|
1852
1881
|
var modifierLocks = [
|
|
1853
1882
|
"CapsLock",
|
|
1854
1883
|
"FnLock",
|
|
@@ -1856,78 +1885,40 @@ var modifierLocks = [
|
|
|
1856
1885
|
"ScrollLock",
|
|
1857
1886
|
"SymbolLock"
|
|
1858
1887
|
];
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1888
|
+
function isModifierLock(key) {
|
|
1889
|
+
return modifierLocks.includes(key);
|
|
1890
|
+
}
|
|
1891
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1892
|
+
var _a;
|
|
1893
|
+
if (isModifierKey(key)) {
|
|
1894
|
+
config.keyboardState.modifiers[key] = true;
|
|
1895
|
+
if (key === "AltGraph") {
|
|
1896
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1897
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1869
1898
|
}
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
const key = keyDef.key;
|
|
1875
|
-
keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
|
|
1876
|
-
if (!keyboardState.modifierPhase[key]) {
|
|
1877
|
-
keyboardState.modifiers[key] = true;
|
|
1878
|
-
}
|
|
1899
|
+
} else if (isModifierLock(key)) {
|
|
1900
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1901
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1902
|
+
config.keyboardState.modifiers[key] = true;
|
|
1879
1903
|
}
|
|
1880
1904
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
{
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
},
|
|
1889
|
-
{
|
|
1890
|
-
matches: (keyDef) => modifierLocks.includes(keyDef.key),
|
|
1891
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1892
|
-
const key = keyDef.key;
|
|
1893
|
-
if (keyboardState.modifierPhase[key]) {
|
|
1894
|
-
keyboardState.modifiers[key] = false;
|
|
1895
|
-
}
|
|
1905
|
+
}
|
|
1906
|
+
function preKeyupBehavior(config, { key }) {
|
|
1907
|
+
if (isModifierKey(key)) {
|
|
1908
|
+
config.keyboardState.modifiers[key] = false;
|
|
1909
|
+
} else if (isModifierLock(key)) {
|
|
1910
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1911
|
+
config.keyboardState.modifiers[key] = false;
|
|
1896
1912
|
}
|
|
1897
1913
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1905
|
-
fireEvent8.keyUp(element, getKeyEventProps(ctrlKeyDef, keyboardState));
|
|
1906
|
-
}
|
|
1914
|
+
}
|
|
1915
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1916
|
+
var _a;
|
|
1917
|
+
if (key === "AltGraph") {
|
|
1918
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1919
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1907
1920
|
}
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
// src/keyboard/plugins/index.ts
|
|
1911
|
-
var preKeydownBehavior2 = [
|
|
1912
|
-
...preKeydownBehavior
|
|
1913
|
-
];
|
|
1914
|
-
var keydownBehavior5 = [
|
|
1915
|
-
...keydownBehavior,
|
|
1916
|
-
...keydownBehavior2,
|
|
1917
|
-
...keydownBehavior3,
|
|
1918
|
-
...keydownBehavior4
|
|
1919
|
-
];
|
|
1920
|
-
var keypressBehavior3 = [
|
|
1921
|
-
...keypressBehavior2,
|
|
1922
|
-
...keypressBehavior
|
|
1923
|
-
];
|
|
1924
|
-
var preKeyupBehavior2 = [
|
|
1925
|
-
...preKeyupBehavior
|
|
1926
|
-
];
|
|
1927
|
-
var keyupBehavior2 = [...keyupBehavior];
|
|
1928
|
-
var postKeyupBehavior2 = [
|
|
1929
|
-
...postKeyupBehavior
|
|
1930
|
-
];
|
|
1921
|
+
}
|
|
1931
1922
|
|
|
1932
1923
|
// src/keyboard/keyboardAction.ts
|
|
1933
1924
|
function keyboardAction(config, actions) {
|
|
@@ -1985,45 +1976,29 @@ function keydown(keyDef, getCurrentElement, config) {
|
|
|
1985
1976
|
config.keyboardState.carryChar = "";
|
|
1986
1977
|
}
|
|
1987
1978
|
config.keyboardState.activeElement = element;
|
|
1988
|
-
|
|
1989
|
-
const unpreventedDefault =
|
|
1979
|
+
preKeydownBehavior(config, keyDef, element);
|
|
1980
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
1990
1981
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
1991
|
-
if (unpreventedDefault) {
|
|
1992
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
1993
|
-
}
|
|
1994
1982
|
return unpreventedDefault;
|
|
1995
1983
|
});
|
|
1996
1984
|
}
|
|
1997
1985
|
function keypress(keyDef, getCurrentElement, config) {
|
|
1998
1986
|
return __async(this, null, function* () {
|
|
1999
1987
|
const element = getCurrentElement();
|
|
2000
|
-
|
|
1988
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
2001
1989
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
2002
1990
|
}));
|
|
2003
|
-
if (unpreventedDefault) {
|
|
2004
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
2005
|
-
}
|
|
2006
1991
|
});
|
|
2007
1992
|
}
|
|
2008
1993
|
function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
2009
1994
|
return __async(this, null, function* () {
|
|
2010
1995
|
const element = getCurrentElement();
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
if (unprevented && unpreventedDefault) {
|
|
2014
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
2015
|
-
}
|
|
1996
|
+
preKeyupBehavior(config, keyDef);
|
|
1997
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
2016
1998
|
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
2017
|
-
|
|
1999
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2018
2000
|
});
|
|
2019
2001
|
}
|
|
2020
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
2021
|
-
const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
|
|
2022
|
-
if (plugin) {
|
|
2023
|
-
plugin.handle(keyDef, element, config);
|
|
2024
|
-
}
|
|
2025
|
-
return !!plugin;
|
|
2026
|
-
}
|
|
2027
2002
|
function hasKeyPress(keyDef, config) {
|
|
2028
2003
|
var _a;
|
|
2029
2004
|
return (((_a = keyDef.key) == null ? void 0 : _a.length) === 1 || keyDef.key === "Enter") && !config.keyboardState.modifiers.Control && !config.keyboardState.modifiers.Alt;
|
|
@@ -2041,7 +2016,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2041
2016
|
releasePrevious,
|
|
2042
2017
|
releaseSelf = true,
|
|
2043
2018
|
repeat
|
|
2044
|
-
} = readNextDescriptor(text);
|
|
2019
|
+
} = readNextDescriptor(text, "keyboard");
|
|
2045
2020
|
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2046
2021
|
var _a2, _b;
|
|
2047
2022
|
if (type3 === "[") {
|
|
@@ -2064,8 +2039,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2064
2039
|
// src/keyboard/index.ts
|
|
2065
2040
|
function keyboard(text) {
|
|
2066
2041
|
return __async(this, null, function* () {
|
|
2067
|
-
const
|
|
2068
|
-
const actions = parseKeyDef(keyboardMap, text);
|
|
2042
|
+
const actions = parseKeyDef(this[Config].keyboardMap, text);
|
|
2069
2043
|
return keyboardAction(this[Config], actions);
|
|
2070
2044
|
});
|
|
2071
2045
|
}
|
|
@@ -2101,7 +2075,7 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2101
2075
|
consumedLength,
|
|
2102
2076
|
releasePrevious,
|
|
2103
2077
|
releaseSelf = true
|
|
2104
|
-
} = readNextDescriptor(keys);
|
|
2078
|
+
} = readNextDescriptor(keys, "pointer");
|
|
2105
2079
|
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
2106
2080
|
if (keyDef) {
|
|
2107
2081
|
defs.push({ keyDef, releasePrevious, releaseSelf });
|
|
@@ -2111,6 +2085,34 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2111
2085
|
return defs;
|
|
2112
2086
|
}
|
|
2113
2087
|
|
|
2088
|
+
// src/pointer/firePointerEvents.ts
|
|
2089
|
+
function firePointerEvent(config, target, type3, {
|
|
2090
|
+
pointerType,
|
|
2091
|
+
button,
|
|
2092
|
+
coords,
|
|
2093
|
+
pointerId,
|
|
2094
|
+
isPrimary,
|
|
2095
|
+
clickCount
|
|
2096
|
+
}) {
|
|
2097
|
+
const init = __spreadValues({}, coords);
|
|
2098
|
+
if (type3 === "click" || type3.startsWith("pointer")) {
|
|
2099
|
+
init.pointerId = pointerId;
|
|
2100
|
+
init.pointerType = pointerType;
|
|
2101
|
+
}
|
|
2102
|
+
if (["pointerdown", "pointerup"].includes(type3)) {
|
|
2103
|
+
init.isPrimary = isPrimary;
|
|
2104
|
+
}
|
|
2105
|
+
init.button = getMouseButton(button != null ? button : 0);
|
|
2106
|
+
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2107
|
+
var _a;
|
|
2108
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2109
|
+
}));
|
|
2110
|
+
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2111
|
+
init.detail = clickCount;
|
|
2112
|
+
}
|
|
2113
|
+
return dispatchUIEvent(config, target, type3, init);
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2114
2116
|
// src/pointer/resolveSelectionTarget.ts
|
|
2115
2117
|
function resolveSelectionTarget({
|
|
2116
2118
|
target,
|
|
@@ -2158,7 +2160,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
2158
2160
|
// src/pointer/pointerMove.ts
|
|
2159
2161
|
function pointerMove(_0, _1) {
|
|
2160
2162
|
return __async(this, arguments, function* (config, { pointerName = "mouse", target, coords, node, offset }) {
|
|
2161
|
-
const { pointerState
|
|
2163
|
+
const { pointerState } = config;
|
|
2162
2164
|
if (!(pointerName in pointerState.position)) {
|
|
2163
2165
|
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
2164
2166
|
}
|
|
@@ -2233,9 +2235,7 @@ function pointerMove(_0, _1) {
|
|
|
2233
2235
|
}
|
|
2234
2236
|
}
|
|
2235
2237
|
function fire(eventTarget, type3, eventCoords) {
|
|
2236
|
-
return firePointerEvent(eventTarget, type3, {
|
|
2237
|
-
pointerState,
|
|
2238
|
-
keyboardState,
|
|
2238
|
+
return firePointerEvent(config, eventTarget, type3, {
|
|
2239
2239
|
coords: eventCoords,
|
|
2240
2240
|
pointerId,
|
|
2241
2241
|
pointerType
|
|
@@ -2270,7 +2270,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2270
2270
|
var _a, _b, _c;
|
|
2271
2271
|
setLevelRef(config, 2 /* Trigger */);
|
|
2272
2272
|
assertPointerEvents(config, target);
|
|
2273
|
-
const { pointerState
|
|
2273
|
+
const { pointerState } = config;
|
|
2274
2274
|
const { name, pointerType, button } = keyDef;
|
|
2275
2275
|
const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
|
|
2276
2276
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
@@ -2332,9 +2332,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2332
2332
|
}
|
|
2333
2333
|
return pressObj;
|
|
2334
2334
|
function fire(type3) {
|
|
2335
|
-
return firePointerEvent(target, type3, {
|
|
2336
|
-
pointerState,
|
|
2337
|
-
keyboardState,
|
|
2335
|
+
return firePointerEvent(config, target, type3, {
|
|
2338
2336
|
button,
|
|
2339
2337
|
clickCount,
|
|
2340
2338
|
coords,
|
|
@@ -2351,10 +2349,9 @@ function up(config, pointerName, {
|
|
|
2351
2349
|
node,
|
|
2352
2350
|
offset
|
|
2353
2351
|
}, pressed, targetIsDisabled) {
|
|
2354
|
-
var _a;
|
|
2355
2352
|
setLevelRef(config, 2 /* Trigger */);
|
|
2356
2353
|
assertPointerEvents(config, target);
|
|
2357
|
-
const { pointerState
|
|
2354
|
+
const { pointerState } = config;
|
|
2358
2355
|
pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
|
|
2359
2356
|
const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
|
|
2360
2357
|
let { unpreventedDefault } = pressed;
|
|
@@ -2395,21 +2392,15 @@ function up(config, pointerName, {
|
|
|
2395
2392
|
unpreventedDefault = fire("mouseup") && unpreventedDefault;
|
|
2396
2393
|
const canClick = pointerType !== "mouse" || button === "primary";
|
|
2397
2394
|
if (canClick && target === pressed.downTarget) {
|
|
2398
|
-
|
|
2395
|
+
fire("click");
|
|
2399
2396
|
if (clickCount === 2) {
|
|
2400
2397
|
fire("dblclick");
|
|
2401
2398
|
}
|
|
2402
|
-
const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
|
|
2403
|
-
if (unpreventedClick && control && isFocusable(control)) {
|
|
2404
|
-
focus(control);
|
|
2405
|
-
}
|
|
2406
2399
|
}
|
|
2407
2400
|
}
|
|
2408
2401
|
}
|
|
2409
2402
|
function fire(type3) {
|
|
2410
|
-
return firePointerEvent(target, type3, {
|
|
2411
|
-
pointerState,
|
|
2412
|
-
keyboardState,
|
|
2403
|
+
return firePointerEvent(config, target, type3, {
|
|
2413
2404
|
button,
|
|
2414
2405
|
clickCount,
|
|
2415
2406
|
coords,
|
|
@@ -2507,11 +2498,11 @@ function getPrevTarget(pointerName, state) {
|
|
|
2507
2498
|
}
|
|
2508
2499
|
|
|
2509
2500
|
// src/pointer/index.ts
|
|
2510
|
-
function pointer(
|
|
2501
|
+
function pointer(input2) {
|
|
2511
2502
|
return __async(this, null, function* () {
|
|
2512
2503
|
const { pointerMap } = this[Config];
|
|
2513
2504
|
const actions = [];
|
|
2514
|
-
(Array.isArray(
|
|
2505
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2515
2506
|
if (typeof actionInput === "string") {
|
|
2516
2507
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2517
2508
|
} else if ("keys" in actionInput) {
|
|
@@ -2615,7 +2606,6 @@ function tab() {
|
|
|
2615
2606
|
}
|
|
2616
2607
|
|
|
2617
2608
|
// src/clipboard/copy.ts
|
|
2618
|
-
import { fireEvent as fireEvent10 } from "@testing-library/dom";
|
|
2619
2609
|
function copy() {
|
|
2620
2610
|
return __async(this, null, function* () {
|
|
2621
2611
|
var _a;
|
|
@@ -2625,10 +2615,9 @@ function copy() {
|
|
|
2625
2615
|
if (clipboardData.items.length === 0) {
|
|
2626
2616
|
return;
|
|
2627
2617
|
}
|
|
2628
|
-
|
|
2618
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2629
2619
|
clipboardData
|
|
2630
|
-
})
|
|
2631
|
-
if (this[Config].writeToClipboard) {
|
|
2620
|
+
}) && this[Config].writeToClipboard) {
|
|
2632
2621
|
yield writeDataTransferToClipboard(doc, clipboardData);
|
|
2633
2622
|
}
|
|
2634
2623
|
return clipboardData;
|
|
@@ -2636,53 +2625,37 @@ function copy() {
|
|
|
2636
2625
|
}
|
|
2637
2626
|
|
|
2638
2627
|
// src/clipboard/cut.ts
|
|
2639
|
-
import { fireEvent as fireEvent11 } from "@testing-library/dom";
|
|
2640
2628
|
function cut() {
|
|
2641
2629
|
return __async(this, null, function* () {
|
|
2642
|
-
var _a
|
|
2630
|
+
var _a;
|
|
2643
2631
|
const doc = this[Config].document;
|
|
2644
2632
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2645
2633
|
const clipboardData = copySelection(target);
|
|
2646
2634
|
if (clipboardData.items.length === 0) {
|
|
2647
2635
|
return;
|
|
2648
2636
|
}
|
|
2649
|
-
|
|
2637
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2650
2638
|
clipboardData
|
|
2651
|
-
})
|
|
2652
|
-
|
|
2653
|
-
(_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2654
|
-
}
|
|
2655
|
-
if (this[Config].writeToClipboard) {
|
|
2656
|
-
yield writeDataTransferToClipboard(doc, clipboardData);
|
|
2639
|
+
}) && this[Config].writeToClipboard) {
|
|
2640
|
+
yield writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2657
2641
|
}
|
|
2658
2642
|
return clipboardData;
|
|
2659
2643
|
});
|
|
2660
2644
|
}
|
|
2661
2645
|
|
|
2662
2646
|
// src/clipboard/paste.ts
|
|
2663
|
-
import { fireEvent as fireEvent12 } from "@testing-library/dom";
|
|
2664
2647
|
function paste(clipboardData) {
|
|
2665
2648
|
return __async(this, null, function* () {
|
|
2666
2649
|
var _a, _b;
|
|
2667
2650
|
const doc = this[Config].document;
|
|
2668
2651
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2669
|
-
const
|
|
2652
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : yield readDataTransferFromClipboard(doc).catch(() => {
|
|
2670
2653
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2671
2654
|
});
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
}
|
|
2675
|
-
function pasteImpl(target, clipboardData) {
|
|
2676
|
-
var _a;
|
|
2677
|
-
fireEvent12.paste(target, {
|
|
2678
|
-
clipboardData
|
|
2655
|
+
this.dispatchUIEvent(target, "paste", {
|
|
2656
|
+
clipboardData: dataTransfer
|
|
2657
|
+
});
|
|
2679
2658
|
});
|
|
2680
|
-
if (isEditable(target)) {
|
|
2681
|
-
const data = clipboardData.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2682
|
-
if (data) {
|
|
2683
|
-
(_a = prepareInput(data, target, "insertFromPaste")) == null ? void 0 : _a.commit();
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
2659
|
}
|
|
2687
2660
|
function getClipboardDataFromString(text) {
|
|
2688
2661
|
const dt = createDataTransfer();
|
|
@@ -2693,7 +2666,6 @@ function getClipboardDataFromString(text) {
|
|
|
2693
2666
|
// src/utility/clear.ts
|
|
2694
2667
|
function clear(element) {
|
|
2695
2668
|
return __async(this, null, function* () {
|
|
2696
|
-
var _a;
|
|
2697
2669
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2698
2670
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2699
2671
|
}
|
|
@@ -2705,12 +2677,12 @@ function clear(element) {
|
|
|
2705
2677
|
if (!isAllSelected(element)) {
|
|
2706
2678
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2707
2679
|
}
|
|
2708
|
-
(
|
|
2680
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2709
2681
|
});
|
|
2710
2682
|
}
|
|
2711
2683
|
|
|
2712
2684
|
// src/utility/selectOptions.ts
|
|
2713
|
-
import {
|
|
2685
|
+
import { getConfig as getConfig3 } from "@testing-library/dom";
|
|
2714
2686
|
function selectOptions(select, values) {
|
|
2715
2687
|
return __async(this, null, function* () {
|
|
2716
2688
|
return selectOptionsBase.call(this, true, select, values);
|
|
@@ -2724,7 +2696,7 @@ function deselectOptions(select, values) {
|
|
|
2724
2696
|
function selectOptionsBase(newValue, select, values) {
|
|
2725
2697
|
return __async(this, null, function* () {
|
|
2726
2698
|
if (!newValue && !select.multiple) {
|
|
2727
|
-
throw
|
|
2699
|
+
throw getConfig3().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
2728
2700
|
}
|
|
2729
2701
|
const valArray = Array.isArray(values) ? values : [values];
|
|
2730
2702
|
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
|
|
@@ -2736,34 +2708,43 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2736
2708
|
if (matchingOption) {
|
|
2737
2709
|
return matchingOption;
|
|
2738
2710
|
} else {
|
|
2739
|
-
throw
|
|
2711
|
+
throw getConfig3().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
2740
2712
|
}
|
|
2741
2713
|
}
|
|
2742
2714
|
}).filter((option) => !isDisabled(option));
|
|
2743
2715
|
if (isDisabled(select) || !selectedOptions.length)
|
|
2744
2716
|
return;
|
|
2717
|
+
const selectOption = (option) => {
|
|
2718
|
+
option.selected = newValue;
|
|
2719
|
+
this.dispatchUIEvent(select, "input", {
|
|
2720
|
+
bubbles: true,
|
|
2721
|
+
cancelable: false,
|
|
2722
|
+
composed: true
|
|
2723
|
+
});
|
|
2724
|
+
this.dispatchUIEvent(select, "change");
|
|
2725
|
+
};
|
|
2745
2726
|
if (isElementType(select, "select")) {
|
|
2746
2727
|
if (select.multiple) {
|
|
2747
2728
|
for (const option of selectedOptions) {
|
|
2748
2729
|
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2749
2730
|
if (withPointerEvents) {
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2731
|
+
this.dispatchUIEvent(option, "pointerover");
|
|
2732
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2733
|
+
this.dispatchUIEvent(option, "mouseover");
|
|
2734
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2735
|
+
this.dispatchUIEvent(option, "pointermove");
|
|
2736
|
+
this.dispatchUIEvent(option, "mousemove");
|
|
2737
|
+
this.dispatchUIEvent(option, "pointerdown");
|
|
2738
|
+
this.dispatchUIEvent(option, "mousedown");
|
|
2758
2739
|
}
|
|
2759
2740
|
focus(select);
|
|
2760
2741
|
if (withPointerEvents) {
|
|
2761
|
-
|
|
2762
|
-
|
|
2742
|
+
this.dispatchUIEvent(option, "pointerup");
|
|
2743
|
+
this.dispatchUIEvent(option, "mouseup");
|
|
2763
2744
|
}
|
|
2764
2745
|
selectOption(option);
|
|
2765
2746
|
if (withPointerEvents) {
|
|
2766
|
-
|
|
2747
|
+
this.dispatchUIEvent(option, "click");
|
|
2767
2748
|
}
|
|
2768
2749
|
}
|
|
2769
2750
|
} else if (selectedOptions.length === 1) {
|
|
@@ -2775,16 +2756,16 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2775
2756
|
}
|
|
2776
2757
|
selectOption(selectedOptions[0]);
|
|
2777
2758
|
if (withPointerEvents) {
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2759
|
+
this.dispatchUIEvent(select, "pointerover");
|
|
2760
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2761
|
+
this.dispatchUIEvent(select, "mouseover");
|
|
2762
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2763
|
+
this.dispatchUIEvent(select, "pointerup");
|
|
2764
|
+
this.dispatchUIEvent(select, "mouseup");
|
|
2765
|
+
this.dispatchUIEvent(select, "click");
|
|
2785
2766
|
}
|
|
2786
2767
|
} else {
|
|
2787
|
-
throw
|
|
2768
|
+
throw getConfig3().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2788
2769
|
}
|
|
2789
2770
|
} else if (select.getAttribute("role") === "listbox") {
|
|
2790
2771
|
for (const option of selectedOptions) {
|
|
@@ -2792,16 +2773,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2792
2773
|
yield this.unhover(option);
|
|
2793
2774
|
}
|
|
2794
2775
|
} else {
|
|
2795
|
-
throw
|
|
2796
|
-
}
|
|
2797
|
-
function selectOption(option) {
|
|
2798
|
-
option.selected = newValue;
|
|
2799
|
-
fireEvent13(select, createEvent2("input", select, {
|
|
2800
|
-
bubbles: true,
|
|
2801
|
-
cancelable: false,
|
|
2802
|
-
composed: true
|
|
2803
|
-
}));
|
|
2804
|
-
fireEvent13.change(select);
|
|
2776
|
+
throw getConfig3().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
2805
2777
|
}
|
|
2806
2778
|
});
|
|
2807
2779
|
}
|
|
@@ -2830,29 +2802,30 @@ function type(_0, _1) {
|
|
|
2830
2802
|
}
|
|
2831
2803
|
|
|
2832
2804
|
// src/utility/upload.ts
|
|
2833
|
-
import { fireEvent as fireEvent14 } from "@testing-library/dom";
|
|
2834
2805
|
function upload(element, fileOrFiles) {
|
|
2835
2806
|
return __async(this, null, function* () {
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
|
|
2807
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2808
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2809
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2840
2810
|
}
|
|
2841
2811
|
if (isDisabled(element))
|
|
2842
2812
|
return;
|
|
2813
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2814
|
+
const fileDialog = () => {
|
|
2815
|
+
var _a;
|
|
2816
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2817
|
+
var _a2;
|
|
2818
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2819
|
+
})) {
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
setFiles(input2, createFileList(files));
|
|
2823
|
+
this.dispatchUIEvent(input2, "input");
|
|
2824
|
+
this.dispatchUIEvent(input2, "change");
|
|
2825
|
+
};
|
|
2826
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2843
2827
|
yield this.click(element);
|
|
2844
|
-
|
|
2845
|
-
blur(input);
|
|
2846
|
-
focus(input);
|
|
2847
|
-
if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2848
|
-
var _a2;
|
|
2849
|
-
return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
|
|
2850
|
-
})) {
|
|
2851
|
-
return;
|
|
2852
|
-
}
|
|
2853
|
-
setFiles(input, createFileList(files));
|
|
2854
|
-
fireEvent14.input(input);
|
|
2855
|
-
fireEvent14.change(input);
|
|
2828
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2856
2829
|
});
|
|
2857
2830
|
}
|
|
2858
2831
|
function isAcceptableFile(file, accept) {
|
|
@@ -2877,24 +2850,29 @@ function wrapAsync(implementation) {
|
|
|
2877
2850
|
}
|
|
2878
2851
|
|
|
2879
2852
|
// src/setup/setup.ts
|
|
2853
|
+
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2854
|
+
const document2 = getDocument(options, node);
|
|
2855
|
+
const {
|
|
2856
|
+
keyboardState = createKeyboardState(),
|
|
2857
|
+
pointerState = createPointerState(document2)
|
|
2858
|
+
} = options;
|
|
2859
|
+
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2860
|
+
document: document2,
|
|
2861
|
+
keyboardState,
|
|
2862
|
+
pointerState
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2880
2865
|
function setupMain(options = {}) {
|
|
2881
2866
|
var _a;
|
|
2882
|
-
const
|
|
2883
|
-
prepareDocument(
|
|
2884
|
-
const view = (_a =
|
|
2867
|
+
const config = createConfig(options);
|
|
2868
|
+
prepareDocument(config.document);
|
|
2869
|
+
const view = (_a = config.document.defaultView) != null ? _a : window;
|
|
2885
2870
|
attachClipboardStubToView(view);
|
|
2886
|
-
return doSetup(
|
|
2887
|
-
keyboardState: createKeyboardState(),
|
|
2888
|
-
pointerState: createPointerState(doc)
|
|
2889
|
-
}));
|
|
2871
|
+
return doSetup(config);
|
|
2890
2872
|
}
|
|
2891
2873
|
function setupDirect(options = {}, node) {
|
|
2892
|
-
const
|
|
2893
|
-
prepareDocument(
|
|
2894
|
-
const config = __spreadValues(__spreadValues({
|
|
2895
|
-
keyboardState: createKeyboardState(),
|
|
2896
|
-
pointerState: createPointerState(doc)
|
|
2897
|
-
}, defaultOptionsDirect), options);
|
|
2874
|
+
const config = createConfig(options, defaultOptionsDirect, node);
|
|
2875
|
+
prepareDocument(config.document);
|
|
2898
2876
|
return {
|
|
2899
2877
|
config,
|
|
2900
2878
|
api: doSetup(config)
|
|
@@ -2913,7 +2891,8 @@ function wrapAndBindImpl(instance, impl) {
|
|
|
2913
2891
|
}
|
|
2914
2892
|
function doSetup(config) {
|
|
2915
2893
|
const instance = __spreadValues({
|
|
2916
|
-
[Config]: config
|
|
2894
|
+
[Config]: config,
|
|
2895
|
+
dispatchUIEvent: bindDispatchUIEvent(config)
|
|
2917
2896
|
}, api_exports);
|
|
2918
2897
|
return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
|
|
2919
2898
|
name,
|
|
@@ -2975,9 +2954,9 @@ function keyboard2(_0) {
|
|
|
2975
2954
|
});
|
|
2976
2955
|
}
|
|
2977
2956
|
function pointer2(_0) {
|
|
2978
|
-
return __async(this, arguments, function* (
|
|
2957
|
+
return __async(this, arguments, function* (input2, options = {}) {
|
|
2979
2958
|
const { config, api } = setupDirect(options);
|
|
2980
|
-
return api.pointer(
|
|
2959
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2981
2960
|
});
|
|
2982
2961
|
}
|
|
2983
2962
|
function paste2(clipboardData, options) {
|