@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.cjs
CHANGED
|
@@ -19,24 +19,19 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
return a;
|
|
20
20
|
};
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
23
22
|
var __export = (target, all) => {
|
|
24
23
|
for (var name in all)
|
|
25
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
25
|
};
|
|
27
|
-
var
|
|
28
|
-
if (
|
|
29
|
-
for (let key of __getOwnPropNames(
|
|
30
|
-
if (!__hasOwnProp.call(
|
|
31
|
-
__defProp(
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
31
|
}
|
|
33
|
-
return
|
|
32
|
+
return to;
|
|
34
33
|
};
|
|
35
|
-
var __toCommonJS =
|
|
36
|
-
return (module2, temp) => {
|
|
37
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
38
|
-
};
|
|
39
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
35
|
|
|
41
36
|
// src/index.ts
|
|
42
37
|
var src_exports = {};
|
|
@@ -44,187 +39,7 @@ __export(src_exports, {
|
|
|
44
39
|
PointerEventsCheckLevel: () => PointerEventsCheckLevel,
|
|
45
40
|
default: () => userEvent
|
|
46
41
|
});
|
|
47
|
-
|
|
48
|
-
// src/document/index.ts
|
|
49
|
-
var import_dom = require("@testing-library/dom");
|
|
50
|
-
|
|
51
|
-
// src/document/interceptor.ts
|
|
52
|
-
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
53
|
-
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
54
|
-
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
55
|
-
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
56
|
-
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
57
|
-
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
function intercept(...args) {
|
|
61
|
-
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
62
|
-
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
63
|
-
if (target === "set") {
|
|
64
|
-
realFunc.call(this, realArgs);
|
|
65
|
-
} else {
|
|
66
|
-
realFunc.call(this, ...realArgs);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
;
|
|
70
|
-
intercept[Interceptor] = Interceptor;
|
|
71
|
-
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
72
|
-
[target]: intercept
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// src/document/selection.ts
|
|
77
|
-
var UISelection = Symbol("Displayed selection in UI");
|
|
78
|
-
function prepareSelectionInterceptor(element) {
|
|
79
|
-
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
80
|
-
const isUI = start && typeof start === "object" && start[UISelection];
|
|
81
|
-
if (!isUI) {
|
|
82
|
-
this[UISelection] = void 0;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
realArgs: [Number(start), end, direction]
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
89
|
-
this[UISelection] = void 0;
|
|
90
|
-
return { realArgs: v };
|
|
91
|
-
});
|
|
92
|
-
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
93
|
-
this[UISelection] = void 0;
|
|
94
|
-
return { realArgs: v };
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function setUISelection(element, {
|
|
98
|
-
focusOffset: focusOffsetParam,
|
|
99
|
-
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
100
|
-
}, mode = "replace") {
|
|
101
|
-
const valueLength = getUIValue(element).length;
|
|
102
|
-
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
103
|
-
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
104
|
-
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
105
|
-
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
106
|
-
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
107
|
-
element[UISelection] = {
|
|
108
|
-
anchorOffset,
|
|
109
|
-
focusOffset
|
|
110
|
-
};
|
|
111
|
-
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const startObj = new Number(startOffset);
|
|
115
|
-
startObj[UISelection] = UISelection;
|
|
116
|
-
try {
|
|
117
|
-
element.setSelectionRange(startObj, endOffset);
|
|
118
|
-
} catch {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function getUISelection(element) {
|
|
122
|
-
var _a, _b, _c;
|
|
123
|
-
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
124
|
-
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
125
|
-
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
126
|
-
};
|
|
127
|
-
return __spreadProps(__spreadValues({}, sel), {
|
|
128
|
-
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
129
|
-
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function clearUISelection(element) {
|
|
133
|
-
element[UISelection] = void 0;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// src/document/value.ts
|
|
137
|
-
var UIValue = Symbol("Displayed value in UI");
|
|
138
|
-
var InitialValue = Symbol("Initial value to compare on blur");
|
|
139
|
-
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
140
|
-
function valueInterceptor(v) {
|
|
141
|
-
const isUI = typeof v === "object" && v[UIValue];
|
|
142
|
-
this[UIValue] = isUI ? String(v) : void 0;
|
|
143
|
-
if (!isUI) {
|
|
144
|
-
trackValue(this, String(v));
|
|
145
|
-
this[InitialValue] = String(v);
|
|
146
|
-
clearUISelection(this);
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
applyNative: !!isUI,
|
|
150
|
-
realArgs: String(v)
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function prepareValueInterceptor(element) {
|
|
154
|
-
prepareInterceptor(element, "value", valueInterceptor);
|
|
155
|
-
}
|
|
156
|
-
function setUIValue(element, value) {
|
|
157
|
-
element.value = {
|
|
158
|
-
[UIValue]: UIValue,
|
|
159
|
-
toString: () => value
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function getUIValue(element) {
|
|
163
|
-
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
164
|
-
}
|
|
165
|
-
function setInitialValue(element) {
|
|
166
|
-
element[InitialValue] = element.value;
|
|
167
|
-
}
|
|
168
|
-
function getInitialValue(element) {
|
|
169
|
-
return element[InitialValue];
|
|
170
|
-
}
|
|
171
|
-
function startTrackValue(element) {
|
|
172
|
-
element[TrackChanges] = [];
|
|
173
|
-
}
|
|
174
|
-
function trackValue(element, v) {
|
|
175
|
-
var _a;
|
|
176
|
-
(_a = element[TrackChanges]) == null ? void 0 : _a.push(v);
|
|
177
|
-
}
|
|
178
|
-
function endTrackValue(element) {
|
|
179
|
-
const tracked = element[TrackChanges];
|
|
180
|
-
element[TrackChanges] = void 0;
|
|
181
|
-
return tracked;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/document/index.ts
|
|
185
|
-
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
186
|
-
function prepareDocument(document2) {
|
|
187
|
-
if (document2[isPrepared]) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
document2.addEventListener("focus", (e) => {
|
|
191
|
-
const el = e.target;
|
|
192
|
-
prepareElement(el);
|
|
193
|
-
}, {
|
|
194
|
-
capture: true,
|
|
195
|
-
passive: true
|
|
196
|
-
});
|
|
197
|
-
if (document2.activeElement) {
|
|
198
|
-
prepareElement(document2.activeElement);
|
|
199
|
-
}
|
|
200
|
-
document2.addEventListener("blur", (e) => {
|
|
201
|
-
const el = e.target;
|
|
202
|
-
const initialValue = getInitialValue(el);
|
|
203
|
-
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
204
|
-
import_dom.fireEvent.change(el);
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
capture: true,
|
|
208
|
-
passive: true
|
|
209
|
-
});
|
|
210
|
-
document2[isPrepared] = isPrepared;
|
|
211
|
-
}
|
|
212
|
-
function prepareElement(el) {
|
|
213
|
-
if ("value" in el) {
|
|
214
|
-
setInitialValue(el);
|
|
215
|
-
}
|
|
216
|
-
if (el[isPrepared]) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if ("value" in el) {
|
|
220
|
-
prepareValueInterceptor(el);
|
|
221
|
-
prepareSelectionInterceptor(el);
|
|
222
|
-
}
|
|
223
|
-
el[isPrepared] = isPrepared;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// src/keyboard/keyboardAction.ts
|
|
227
|
-
var import_dom10 = require("@testing-library/dom");
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
228
43
|
|
|
229
44
|
// src/utils/misc/isElementType.ts
|
|
230
45
|
function isElementType(element, tag, props) {
|
|
@@ -521,6 +336,29 @@ if (typeof afterAll === "function") {
|
|
|
521
336
|
afterAll(() => detachClipboardStubFromView(window));
|
|
522
337
|
}
|
|
523
338
|
|
|
339
|
+
// src/utils/edit/isContentEditable.ts
|
|
340
|
+
function isContentEditable(element) {
|
|
341
|
+
return element.hasAttribute("contenteditable") && (element.getAttribute("contenteditable") == "true" || element.getAttribute("contenteditable") == "");
|
|
342
|
+
}
|
|
343
|
+
function getContentEditable(node) {
|
|
344
|
+
const element = getElement(node);
|
|
345
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
346
|
+
}
|
|
347
|
+
function getElement(node) {
|
|
348
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/utils/edit/getValue.ts
|
|
352
|
+
function getValue(element) {
|
|
353
|
+
if (!element) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
if (isContentEditable(element)) {
|
|
357
|
+
return element.textContent;
|
|
358
|
+
}
|
|
359
|
+
return getUIValue(element);
|
|
360
|
+
}
|
|
361
|
+
|
|
524
362
|
// src/utils/edit/buildTimeValue.ts
|
|
525
363
|
function buildTimeValue(value) {
|
|
526
364
|
const onlyDigitsValue = value.replace(/\D/g, "");
|
|
@@ -552,21 +390,137 @@ function build(onlyDigitsValue, index) {
|
|
|
552
390
|
return `${validHours.toString().padStart(2, "0")}:${validMinutes.toString().padStart(2, "0")}`;
|
|
553
391
|
}
|
|
554
392
|
|
|
555
|
-
// src/utils/edit/
|
|
556
|
-
function
|
|
393
|
+
// src/utils/edit/isValidDateOrTimeValue.ts
|
|
394
|
+
function isValidDateOrTimeValue(element, value) {
|
|
557
395
|
const clone = element.cloneNode();
|
|
558
396
|
clone.value = value;
|
|
559
397
|
return clone.value === value;
|
|
560
398
|
}
|
|
561
399
|
|
|
562
|
-
// src/utils/edit/
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
400
|
+
// src/utils/edit/maxLength.ts
|
|
401
|
+
var maxLengthSupportedTypes = /* @__PURE__ */ ((maxLengthSupportedTypes2) => {
|
|
402
|
+
maxLengthSupportedTypes2["email"] = "email";
|
|
403
|
+
maxLengthSupportedTypes2["password"] = "password";
|
|
404
|
+
maxLengthSupportedTypes2["search"] = "search";
|
|
405
|
+
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
406
|
+
maxLengthSupportedTypes2["text"] = "text";
|
|
407
|
+
maxLengthSupportedTypes2["url"] = "url";
|
|
408
|
+
return maxLengthSupportedTypes2;
|
|
409
|
+
})(maxLengthSupportedTypes || {});
|
|
410
|
+
function getSpaceUntilMaxLength(element) {
|
|
411
|
+
const value = getValue(element);
|
|
412
|
+
if (value === null) {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
const maxLength = getSanitizedMaxLength(element);
|
|
416
|
+
return maxLength ? maxLength - value.length : void 0;
|
|
417
|
+
}
|
|
418
|
+
function getSanitizedMaxLength(element) {
|
|
419
|
+
var _a;
|
|
420
|
+
if (!supportsMaxLength(element)) {
|
|
421
|
+
return void 0;
|
|
422
|
+
}
|
|
423
|
+
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
424
|
+
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
425
|
+
}
|
|
426
|
+
function supportsMaxLength(element) {
|
|
427
|
+
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
567
428
|
}
|
|
568
429
|
|
|
569
|
-
// src/utils/edit/
|
|
430
|
+
// src/utils/edit/input.ts
|
|
431
|
+
function isDateOrTime(element) {
|
|
432
|
+
return isElementType(element, "input") && ["date", "time"].includes(element.type);
|
|
433
|
+
}
|
|
434
|
+
function input(config, element, data, inputType = "insertText") {
|
|
435
|
+
const inputRange = getInputRange(element);
|
|
436
|
+
if (!inputRange) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (!isDateOrTime(element)) {
|
|
440
|
+
const unprevented = dispatchUIEvent(config, element, "beforeinput", {
|
|
441
|
+
inputType,
|
|
442
|
+
data
|
|
443
|
+
});
|
|
444
|
+
if (!unprevented) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if ("startContainer" in inputRange) {
|
|
449
|
+
editContenteditable(config, element, inputRange, data, inputType);
|
|
450
|
+
} else {
|
|
451
|
+
editInputElement(config, element, inputRange, data, inputType);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function editContenteditable(config, element, inputRange, data, inputType) {
|
|
455
|
+
let del = false;
|
|
456
|
+
if (!inputRange.collapsed) {
|
|
457
|
+
del = true;
|
|
458
|
+
inputRange.deleteContents();
|
|
459
|
+
} else if (["deleteContentBackward", "deleteContentForward"].includes(inputType)) {
|
|
460
|
+
const nextPosition = getNextCursorPosition(inputRange.startContainer, inputRange.startOffset, inputType === "deleteContentBackward" ? -1 : 1, inputType);
|
|
461
|
+
if (nextPosition) {
|
|
462
|
+
del = true;
|
|
463
|
+
const delRange = inputRange.cloneRange();
|
|
464
|
+
if (delRange.comparePoint(nextPosition.node, nextPosition.offset) < 0) {
|
|
465
|
+
delRange.setStart(nextPosition.node, nextPosition.offset);
|
|
466
|
+
} else {
|
|
467
|
+
delRange.setEnd(nextPosition.node, nextPosition.offset);
|
|
468
|
+
}
|
|
469
|
+
delRange.deleteContents();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (data) {
|
|
473
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
474
|
+
const offset = inputRange.endOffset;
|
|
475
|
+
inputRange.endContainer.insertData(offset, data);
|
|
476
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
477
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
478
|
+
} else {
|
|
479
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
480
|
+
inputRange.insertNode(text);
|
|
481
|
+
inputRange.setStart(text, data.length);
|
|
482
|
+
inputRange.setEnd(text, data.length);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (del || data) {
|
|
486
|
+
dispatchUIEvent(config, element, "input", { inputType });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function editInputElement(config, element, inputRange, data, inputType) {
|
|
490
|
+
let dataToInsert = data;
|
|
491
|
+
const spaceUntilMaxLength = getSpaceUntilMaxLength(element);
|
|
492
|
+
if (spaceUntilMaxLength !== void 0) {
|
|
493
|
+
if (spaceUntilMaxLength > 0) {
|
|
494
|
+
dataToInsert = data.substring(0, spaceUntilMaxLength);
|
|
495
|
+
} else {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const { newValue, newOffset, oldValue } = calculateNewValue(dataToInsert, element, inputRange, inputType);
|
|
500
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (isElementType(element, "input", { type: "number" }) && !isValidNumberInput(newValue)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
setUIValue(element, newValue);
|
|
507
|
+
setSelection({
|
|
508
|
+
focusNode: element,
|
|
509
|
+
anchorOffset: newOffset,
|
|
510
|
+
focusOffset: newOffset
|
|
511
|
+
});
|
|
512
|
+
if (isDateOrTime(element)) {
|
|
513
|
+
if (isValidDateOrTimeValue(element, newValue)) {
|
|
514
|
+
commitInput(config, element, newOffset, {});
|
|
515
|
+
dispatchUIEvent(config, element, "change");
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
commitInput(config, element, newOffset, {
|
|
519
|
+
data,
|
|
520
|
+
inputType
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
570
524
|
function calculateNewValue(inputData, node, {
|
|
571
525
|
startOffset,
|
|
572
526
|
endOffset
|
|
@@ -577,15 +531,12 @@ function calculateNewValue(inputData, node, {
|
|
|
577
531
|
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === "deleteContentForward" ? startOffset + 1 : endOffset);
|
|
578
532
|
const epilog = value.substring(epilogStart, value.length);
|
|
579
533
|
let newValue = `${prolog}${inputData}${epilog}`;
|
|
580
|
-
|
|
581
|
-
if (node
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
newValue = inputData;
|
|
587
|
-
} else {
|
|
588
|
-
newValue = value;
|
|
534
|
+
let newOffset = prologEnd + inputData.length;
|
|
535
|
+
if (isElementType(node, "input", { type: "time" })) {
|
|
536
|
+
const builtValue = buildTimeValue(newValue);
|
|
537
|
+
if (builtValue !== "" && isValidDateOrTimeValue(node, builtValue)) {
|
|
538
|
+
newValue = builtValue;
|
|
539
|
+
newOffset = builtValue.length;
|
|
589
540
|
}
|
|
590
541
|
}
|
|
591
542
|
return {
|
|
@@ -594,20 +545,21 @@ function calculateNewValue(inputData, node, {
|
|
|
594
545
|
newOffset
|
|
595
546
|
};
|
|
596
547
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
548
|
+
function commitInput(config, element, newOffset, inputInit) {
|
|
549
|
+
startTrackValue(element);
|
|
550
|
+
dispatchUIEvent(config, element, "input", inputInit);
|
|
551
|
+
if (endTrackValue(element)) {
|
|
552
|
+
setSelection({
|
|
553
|
+
focusNode: element,
|
|
554
|
+
anchorOffset: newOffset,
|
|
555
|
+
focusOffset: newOffset
|
|
556
|
+
});
|
|
557
|
+
}
|
|
608
558
|
}
|
|
609
|
-
function
|
|
610
|
-
|
|
559
|
+
function isValidNumberInput(value) {
|
|
560
|
+
var _a, _b;
|
|
561
|
+
const valueParts = value.split("e", 2);
|
|
562
|
+
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]));
|
|
611
563
|
}
|
|
612
564
|
|
|
613
565
|
// src/utils/edit/isEditable.ts
|
|
@@ -633,161 +585,124 @@ function isEditableInput(element) {
|
|
|
633
585
|
return isElementType(element, "input", { readOnly: false }) && Boolean(editableInputTypes[element.type]);
|
|
634
586
|
}
|
|
635
587
|
|
|
636
|
-
// src/utils/
|
|
637
|
-
|
|
588
|
+
// src/utils/edit/setFiles.ts
|
|
589
|
+
var fakeFiles = Symbol("files and value properties are mocked");
|
|
590
|
+
function setFiles(el, files) {
|
|
638
591
|
var _a;
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
return setSelection({
|
|
648
|
-
focusNode: element.firstChild,
|
|
649
|
-
anchorOffset,
|
|
650
|
-
focusOffset
|
|
592
|
+
(_a = el[fakeFiles]) == null ? void 0 : _a.restore();
|
|
593
|
+
const objectDescriptors = Object.getOwnPropertyDescriptors(el);
|
|
594
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
|
|
595
|
+
function restore() {
|
|
596
|
+
Object.defineProperties(el, {
|
|
597
|
+
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
598
|
+
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
599
|
+
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
651
600
|
});
|
|
652
601
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
602
|
+
el[fakeFiles] = { restore };
|
|
603
|
+
Object.defineProperties(el, {
|
|
604
|
+
files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
|
|
605
|
+
get: () => files
|
|
606
|
+
}),
|
|
607
|
+
value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
|
|
608
|
+
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
609
|
+
set(v) {
|
|
610
|
+
var _a2;
|
|
611
|
+
if (v === "") {
|
|
612
|
+
restore();
|
|
613
|
+
} else {
|
|
614
|
+
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}),
|
|
618
|
+
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
619
|
+
set(v) {
|
|
620
|
+
if (v !== "file") {
|
|
621
|
+
restore();
|
|
622
|
+
el.type = v;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
})
|
|
626
|
+
});
|
|
675
627
|
}
|
|
676
|
-
|
|
677
|
-
|
|
628
|
+
|
|
629
|
+
// src/utils/misc/eventWrapper.ts
|
|
630
|
+
var import_dom = require("@testing-library/dom");
|
|
631
|
+
function eventWrapper(cb) {
|
|
632
|
+
let result;
|
|
633
|
+
(0, import_dom.getConfig)().eventWrapper(() => {
|
|
634
|
+
result = cb();
|
|
635
|
+
});
|
|
636
|
+
return result;
|
|
678
637
|
}
|
|
679
|
-
|
|
638
|
+
|
|
639
|
+
// src/utils/misc/isDisabled.ts
|
|
640
|
+
function isDisabled(element) {
|
|
680
641
|
var _a;
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
642
|
+
for (let el = element; el; el = el.parentElement) {
|
|
643
|
+
if (isElementType(el, [
|
|
644
|
+
"button",
|
|
645
|
+
"input",
|
|
646
|
+
"select",
|
|
647
|
+
"textarea",
|
|
648
|
+
"optgroup",
|
|
649
|
+
"option"
|
|
650
|
+
])) {
|
|
651
|
+
if (el.hasAttribute("disabled")) {
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
} else if (isElementType(el, "fieldset")) {
|
|
655
|
+
if (el.hasAttribute("disabled") && !((_a = el.querySelector(":scope > legend")) == null ? void 0 : _a.contains(element))) {
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
} else if (el.tagName.includes("-")) {
|
|
659
|
+
if (el.constructor.formAssociated && el.hasAttribute("disabled")) {
|
|
660
|
+
return true;
|
|
691
661
|
}
|
|
692
|
-
} else {
|
|
693
|
-
selection.setBaseAndExtent(element, 0, element, 0);
|
|
694
662
|
}
|
|
695
663
|
}
|
|
696
|
-
|
|
697
|
-
function getInputRange(focusNode) {
|
|
698
|
-
var _a;
|
|
699
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
700
|
-
if (typeAndSelection.type === "input") {
|
|
701
|
-
return typeAndSelection.selection;
|
|
702
|
-
} else if (typeAndSelection.type === "contenteditable") {
|
|
703
|
-
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
function setSelection({
|
|
707
|
-
focusNode,
|
|
708
|
-
focusOffset,
|
|
709
|
-
anchorNode = focusNode,
|
|
710
|
-
anchorOffset = focusOffset
|
|
711
|
-
}) {
|
|
712
|
-
var _a, _b;
|
|
713
|
-
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
714
|
-
if (typeAndSelection.type === "input") {
|
|
715
|
-
return setUISelection(focusNode, {
|
|
716
|
-
anchorOffset,
|
|
717
|
-
focusOffset
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
664
|
+
return false;
|
|
721
665
|
}
|
|
722
666
|
|
|
723
|
-
// src/utils/
|
|
724
|
-
function
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
anchorOffset: newSelection.offset,
|
|
734
|
-
focusOffset: newSelection.offset
|
|
735
|
-
});
|
|
736
|
-
startTrackValue(element);
|
|
737
|
-
import_dom2.fireEvent.input(element, __spreadValues({}, eventOverrides));
|
|
738
|
-
const tracked = endTrackValue(element);
|
|
739
|
-
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
740
|
-
setSelection({
|
|
741
|
-
focusNode: newSelection.node,
|
|
742
|
-
anchorOffset: newSelection.offset,
|
|
743
|
-
focusOffset: newSelection.offset
|
|
744
|
-
});
|
|
667
|
+
// src/utils/focus/getActiveElement.ts
|
|
668
|
+
function getActiveElement(document2) {
|
|
669
|
+
const activeElement = document2.activeElement;
|
|
670
|
+
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
671
|
+
return getActiveElement(activeElement.shadowRoot);
|
|
672
|
+
} else {
|
|
673
|
+
if (isDisabled(activeElement)) {
|
|
674
|
+
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
675
|
+
}
|
|
676
|
+
return activeElement;
|
|
745
677
|
}
|
|
746
678
|
}
|
|
747
679
|
|
|
748
|
-
// src/utils/
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
680
|
+
// src/utils/focus/selector.ts
|
|
681
|
+
var FOCUSABLE_SELECTOR = [
|
|
682
|
+
"input:not([type=hidden]):not([disabled])",
|
|
683
|
+
"button:not([disabled])",
|
|
684
|
+
"select:not([disabled])",
|
|
685
|
+
"textarea:not([disabled])",
|
|
686
|
+
'[contenteditable=""]',
|
|
687
|
+
'[contenteditable="true"]',
|
|
688
|
+
"a[href]",
|
|
689
|
+
"[tabindex]:not([disabled])"
|
|
690
|
+
].join(", ");
|
|
758
691
|
|
|
759
|
-
// src/utils/
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
maxLengthSupportedTypes2["password"] = "password";
|
|
763
|
-
maxLengthSupportedTypes2["search"] = "search";
|
|
764
|
-
maxLengthSupportedTypes2["telephone"] = "telephone";
|
|
765
|
-
maxLengthSupportedTypes2["text"] = "text";
|
|
766
|
-
maxLengthSupportedTypes2["url"] = "url";
|
|
767
|
-
return maxLengthSupportedTypes2;
|
|
768
|
-
})(maxLengthSupportedTypes || {});
|
|
769
|
-
function getSpaceUntilMaxLength(element) {
|
|
770
|
-
const value = getValue(element);
|
|
771
|
-
if (value === null) {
|
|
772
|
-
return void 0;
|
|
773
|
-
}
|
|
774
|
-
const maxLength = getSanitizedMaxLength(element);
|
|
775
|
-
return maxLength ? maxLength - value.length : void 0;
|
|
776
|
-
}
|
|
777
|
-
function getSanitizedMaxLength(element) {
|
|
778
|
-
var _a;
|
|
779
|
-
if (!supportsMaxLength(element)) {
|
|
780
|
-
return void 0;
|
|
781
|
-
}
|
|
782
|
-
const attr = (_a = element.getAttribute("maxlength")) != null ? _a : "";
|
|
783
|
-
return /^\d+$/.test(attr) && Number(attr) >= 0 ? Number(attr) : void 0;
|
|
784
|
-
}
|
|
785
|
-
function supportsMaxLength(element) {
|
|
786
|
-
return isElementType(element, "textarea") || isElementType(element, "input") && Boolean(maxLengthSupportedTypes[element.type]);
|
|
692
|
+
// src/utils/focus/isFocusable.ts
|
|
693
|
+
function isFocusable(element) {
|
|
694
|
+
return element.matches(FOCUSABLE_SELECTOR);
|
|
787
695
|
}
|
|
788
696
|
|
|
789
|
-
// src/utils/
|
|
790
|
-
|
|
697
|
+
// src/utils/focus/blur.ts
|
|
698
|
+
function blur(element) {
|
|
699
|
+
if (!isFocusable(element))
|
|
700
|
+
return;
|
|
701
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
702
|
+
if (!wasActive)
|
|
703
|
+
return;
|
|
704
|
+
eventWrapper(() => element.blur());
|
|
705
|
+
}
|
|
791
706
|
|
|
792
707
|
// src/utils/focus/cursor.ts
|
|
793
708
|
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
@@ -837,7 +752,7 @@ function getNextCursorPosition(node, offset, direction, inputType) {
|
|
|
837
752
|
}
|
|
838
753
|
function getNextCharacterContentNode(node, offset, direction) {
|
|
839
754
|
const nextOffset = Number(offset) + (direction < 0 ? -1 : 0);
|
|
840
|
-
if (offset !== void 0 &&
|
|
755
|
+
if (offset !== void 0 && isElement(node) && nextOffset >= 0 && nextOffset < node.children.length) {
|
|
841
756
|
node = node.children[nextOffset];
|
|
842
757
|
}
|
|
843
758
|
return walkNodes(node, direction === 1 ? "next" : "previous", isTreatedAsCharacterContent);
|
|
@@ -846,7 +761,7 @@ function isTreatedAsCharacterContent(node) {
|
|
|
846
761
|
if (isTextNode(node)) {
|
|
847
762
|
return true;
|
|
848
763
|
}
|
|
849
|
-
if (
|
|
764
|
+
if (isElement(node)) {
|
|
850
765
|
if (isElementType(node, ["input", "textarea"])) {
|
|
851
766
|
return node.type !== "hidden";
|
|
852
767
|
} else if (isElementType(node, "br")) {
|
|
@@ -863,7 +778,7 @@ function getOffset(node) {
|
|
|
863
778
|
}
|
|
864
779
|
return i;
|
|
865
780
|
}
|
|
866
|
-
function
|
|
781
|
+
function isElement(node) {
|
|
867
782
|
return node.nodeType === 1;
|
|
868
783
|
}
|
|
869
784
|
function isTextNode(node) {
|
|
@@ -878,7 +793,7 @@ function walkNodes(node, direction, callback) {
|
|
|
878
793
|
if (callback(node)) {
|
|
879
794
|
return node;
|
|
880
795
|
}
|
|
881
|
-
} else if (node.parentNode && (!
|
|
796
|
+
} else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable(node.parentNode) && node.parentNode !== ((_a = node.ownerDocument) == null ? void 0 : _a.body))) {
|
|
882
797
|
node = node.parentNode;
|
|
883
798
|
} else {
|
|
884
799
|
break;
|
|
@@ -892,167 +807,116 @@ function getDescendant(node, direction) {
|
|
|
892
807
|
return node;
|
|
893
808
|
}
|
|
894
809
|
|
|
895
|
-
// src/utils/
|
|
896
|
-
function
|
|
897
|
-
|
|
898
|
-
if (
|
|
899
|
-
return
|
|
810
|
+
// src/utils/focus/selection.ts
|
|
811
|
+
function setSelectionRange(element, anchorOffset, focusOffset) {
|
|
812
|
+
var _a;
|
|
813
|
+
if (hasOwnSelection(element)) {
|
|
814
|
+
return setSelection({
|
|
815
|
+
focusNode: element,
|
|
816
|
+
anchorOffset,
|
|
817
|
+
focusOffset
|
|
818
|
+
});
|
|
900
819
|
}
|
|
901
|
-
if (
|
|
902
|
-
return {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
if (data) {
|
|
922
|
-
if (inputRange.endContainer.nodeType === 3) {
|
|
923
|
-
const offset = inputRange.endOffset;
|
|
924
|
-
inputRange.endContainer.insertData(offset, data);
|
|
925
|
-
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
926
|
-
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
927
|
-
} else {
|
|
928
|
-
const text = element.ownerDocument.createTextNode(data);
|
|
929
|
-
inputRange.insertNode(text);
|
|
930
|
-
inputRange.setStart(text, data.length);
|
|
931
|
-
inputRange.setEnd(text, data.length);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
if (del || data) {
|
|
935
|
-
import_dom3.fireEvent.input(element, { inputType });
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
};
|
|
939
|
-
} else {
|
|
820
|
+
if (isContentEditable(element) && ((_a = element.firstChild) == null ? void 0 : _a.nodeType) === 3) {
|
|
821
|
+
return setSelection({
|
|
822
|
+
focusNode: element.firstChild,
|
|
823
|
+
anchorOffset,
|
|
824
|
+
focusOffset
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
throw new Error("Not implemented. The result of this interaction is unreliable.");
|
|
828
|
+
}
|
|
829
|
+
function hasOwnSelection(node) {
|
|
830
|
+
return isElement2(node) && (isElementType(node, "textarea") || isElementType(node, "input") && node.type in editableInputTypes);
|
|
831
|
+
}
|
|
832
|
+
function isElement2(node) {
|
|
833
|
+
return node.nodeType === 1;
|
|
834
|
+
}
|
|
835
|
+
function getTargetTypeAndSelection(node) {
|
|
836
|
+
const element = getElement2(node);
|
|
837
|
+
if (element && hasOwnSelection(element)) {
|
|
940
838
|
return {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
const { newValue, newOffset, oldValue } = calculateNewValue(data, element, inputRange, inputType);
|
|
944
|
-
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
945
|
-
return;
|
|
946
|
-
}
|
|
947
|
-
editInputElement(element, {
|
|
948
|
-
newValue,
|
|
949
|
-
newSelection: {
|
|
950
|
-
node: element,
|
|
951
|
-
offset: newOffset
|
|
952
|
-
},
|
|
953
|
-
eventOverrides: {
|
|
954
|
-
inputType
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
}
|
|
839
|
+
type: "input",
|
|
840
|
+
selection: getUISelection(element)
|
|
958
841
|
};
|
|
959
842
|
}
|
|
843
|
+
const selection = element == null ? void 0 : element.ownerDocument.getSelection();
|
|
844
|
+
const isCE = getContentEditable(node) && (selection == null ? void 0 : selection.anchorNode) && getContentEditable(selection.anchorNode);
|
|
845
|
+
return {
|
|
846
|
+
type: isCE ? "contenteditable" : "default",
|
|
847
|
+
selection
|
|
848
|
+
};
|
|
960
849
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
function
|
|
850
|
+
function getElement2(node) {
|
|
851
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
852
|
+
}
|
|
853
|
+
function updateSelectionOnFocus(element) {
|
|
965
854
|
var _a;
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
function restore() {
|
|
970
|
-
Object.defineProperties(el, {
|
|
971
|
-
files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
|
|
972
|
-
value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
|
|
973
|
-
type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
|
|
974
|
-
});
|
|
855
|
+
const selection = element.ownerDocument.getSelection();
|
|
856
|
+
if (!(selection == null ? void 0 : selection.focusNode)) {
|
|
857
|
+
return;
|
|
975
858
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
|
|
983
|
-
set(v) {
|
|
984
|
-
var _a2;
|
|
985
|
-
if (v === "") {
|
|
986
|
-
restore();
|
|
987
|
-
} else {
|
|
988
|
-
(_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
}),
|
|
992
|
-
type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
|
|
993
|
-
set(v) {
|
|
994
|
-
if (v !== "file") {
|
|
995
|
-
restore();
|
|
996
|
-
el.type = v;
|
|
997
|
-
}
|
|
859
|
+
if (hasOwnSelection(element)) {
|
|
860
|
+
const contenteditable = getContentEditable(selection.focusNode);
|
|
861
|
+
if (contenteditable) {
|
|
862
|
+
if (!selection.isCollapsed) {
|
|
863
|
+
const focusNode = ((_a = contenteditable.firstChild) == null ? void 0 : _a.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
|
|
864
|
+
selection.setBaseAndExtent(focusNode, 0, focusNode, 0);
|
|
998
865
|
}
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
// src/utils/misc/eventWrapper.ts
|
|
1004
|
-
var import_dom4 = require("@testing-library/dom");
|
|
1005
|
-
function eventWrapper(cb) {
|
|
1006
|
-
let result;
|
|
1007
|
-
(0, import_dom4.getConfig)().eventWrapper(() => {
|
|
1008
|
-
result = cb();
|
|
1009
|
-
});
|
|
1010
|
-
return result;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
// src/utils/misc/isDisabled.ts
|
|
1014
|
-
function isDisabled(element) {
|
|
1015
|
-
return Boolean(element && element.disabled);
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
// src/utils/focus/getActiveElement.ts
|
|
1019
|
-
function getActiveElement(document2) {
|
|
1020
|
-
const activeElement = document2.activeElement;
|
|
1021
|
-
if (activeElement == null ? void 0 : activeElement.shadowRoot) {
|
|
1022
|
-
return getActiveElement(activeElement.shadowRoot);
|
|
1023
|
-
} else {
|
|
1024
|
-
if (isDisabled(activeElement)) {
|
|
1025
|
-
return document2.ownerDocument ? document2.ownerDocument.body : document2.body;
|
|
866
|
+
} else {
|
|
867
|
+
selection.setBaseAndExtent(element, 0, element, 0);
|
|
1026
868
|
}
|
|
1027
|
-
return activeElement;
|
|
1028
869
|
}
|
|
1029
870
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
"input
|
|
1034
|
-
|
|
1035
|
-
"
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
871
|
+
function getInputRange(focusNode) {
|
|
872
|
+
var _a;
|
|
873
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
874
|
+
if (typeAndSelection.type === "input") {
|
|
875
|
+
return typeAndSelection.selection;
|
|
876
|
+
} else if (typeAndSelection.type === "contenteditable") {
|
|
877
|
+
return (_a = typeAndSelection.selection) == null ? void 0 : _a.getRangeAt(0);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
function setSelection({
|
|
881
|
+
focusNode,
|
|
882
|
+
focusOffset,
|
|
883
|
+
anchorNode = focusNode,
|
|
884
|
+
anchorOffset = focusOffset
|
|
885
|
+
}) {
|
|
886
|
+
var _a, _b;
|
|
887
|
+
const typeAndSelection = getTargetTypeAndSelection(focusNode);
|
|
888
|
+
if (typeAndSelection.type === "input") {
|
|
889
|
+
return setUISelection(focusNode, {
|
|
890
|
+
anchorOffset,
|
|
891
|
+
focusOffset
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
(_b = (_a = anchorNode.ownerDocument) == null ? void 0 : _a.getSelection()) == null ? void 0 : _b.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
1046
895
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
896
|
+
function moveSelection(node, direction) {
|
|
897
|
+
if (hasOwnSelection(node)) {
|
|
898
|
+
const selection = getUISelection(node);
|
|
899
|
+
setSelection({
|
|
900
|
+
focusNode: node,
|
|
901
|
+
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + direction : direction < 0 ? selection.startOffset : selection.endOffset
|
|
902
|
+
});
|
|
903
|
+
} else {
|
|
904
|
+
const selection = node.ownerDocument.getSelection();
|
|
905
|
+
if (!selection) {
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
if (selection.isCollapsed) {
|
|
909
|
+
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, direction);
|
|
910
|
+
if (nextPosition) {
|
|
911
|
+
setSelection({
|
|
912
|
+
focusNode: nextPosition.node,
|
|
913
|
+
focusOffset: nextPosition.offset
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
} else {
|
|
917
|
+
selection[direction < 0 ? "collapseToStart" : "collapseToEnd"]();
|
|
918
|
+
}
|
|
919
|
+
}
|
|
1056
920
|
}
|
|
1057
921
|
|
|
1058
922
|
// src/utils/focus/copySelection.ts
|
|
@@ -1192,6 +1056,14 @@ function isAllSelected(target) {
|
|
|
1192
1056
|
return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
|
|
1193
1057
|
}
|
|
1194
1058
|
|
|
1059
|
+
// src/utils/keyboard/getKeyEventProps.ts
|
|
1060
|
+
function getKeyEventProps(keyDef) {
|
|
1061
|
+
return {
|
|
1062
|
+
key: keyDef.key,
|
|
1063
|
+
code: keyDef.code
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1195
1067
|
// src/utils/keyboard/getUIEventModifiers.ts
|
|
1196
1068
|
function getUIEventModifiers(keyboardState) {
|
|
1197
1069
|
return {
|
|
@@ -1210,21 +1082,13 @@ function getUIEventModifiers(keyboardState) {
|
|
|
1210
1082
|
};
|
|
1211
1083
|
}
|
|
1212
1084
|
|
|
1213
|
-
// src/utils/keyboard/getKeyEventProps.ts
|
|
1214
|
-
function getKeyEventProps(keyDef, state) {
|
|
1215
|
-
return __spreadValues({
|
|
1216
|
-
key: keyDef.key,
|
|
1217
|
-
code: keyDef.code
|
|
1218
|
-
}, getUIEventModifiers(state));
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
1085
|
// src/utils/keyDef/readNextDescriptor.ts
|
|
1222
1086
|
var bracketDict = /* @__PURE__ */ ((bracketDict2) => {
|
|
1223
1087
|
bracketDict2["{"] = "}";
|
|
1224
1088
|
bracketDict2["["] = "]";
|
|
1225
1089
|
return bracketDict2;
|
|
1226
1090
|
})(bracketDict || {});
|
|
1227
|
-
function readNextDescriptor(text) {
|
|
1091
|
+
function readNextDescriptor(text, context) {
|
|
1228
1092
|
let pos = 0;
|
|
1229
1093
|
const startBracket = text[pos] in bracketDict ? text[pos] : "";
|
|
1230
1094
|
pos += startBracket.length;
|
|
@@ -1232,11 +1096,11 @@ function readNextDescriptor(text) {
|
|
|
1232
1096
|
const type3 = isEscapedChar ? "" : startBracket;
|
|
1233
1097
|
return __spreadValues({
|
|
1234
1098
|
type: type3
|
|
1235
|
-
}, type3 === "" ? readPrintableChar(text, pos) : readTag(text, pos, type3));
|
|
1099
|
+
}, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
|
|
1236
1100
|
}
|
|
1237
|
-
function readPrintableChar(text, pos) {
|
|
1101
|
+
function readPrintableChar(text, pos, context) {
|
|
1238
1102
|
const descriptor = text[pos];
|
|
1239
|
-
assertDescriptor(descriptor, text, pos);
|
|
1103
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1240
1104
|
pos += descriptor.length;
|
|
1241
1105
|
return {
|
|
1242
1106
|
consumedLength: pos,
|
|
@@ -1246,14 +1110,14 @@ function readPrintableChar(text, pos) {
|
|
|
1246
1110
|
repeat: 1
|
|
1247
1111
|
};
|
|
1248
1112
|
}
|
|
1249
|
-
function readTag(text, pos, startBracket) {
|
|
1113
|
+
function readTag(text, pos, startBracket, context) {
|
|
1250
1114
|
var _a, _b, _c;
|
|
1251
1115
|
const releasePreviousModifier = text[pos] === "/" ? "/" : "";
|
|
1252
1116
|
pos += releasePreviousModifier.length;
|
|
1253
1117
|
const escapedDescriptor = startBracket === "{" && text[pos] === "\\";
|
|
1254
1118
|
pos += Number(escapedDescriptor);
|
|
1255
1119
|
const descriptor = escapedDescriptor ? text[pos] : (_a = text.slice(pos).match(startBracket === "{" ? /^\w+|^[^}>/]/ : /^\w+/)) == null ? void 0 : _a[0];
|
|
1256
|
-
assertDescriptor(descriptor, text, pos);
|
|
1120
|
+
assertDescriptor(descriptor, text, pos, context);
|
|
1257
1121
|
pos += descriptor.length;
|
|
1258
1122
|
const repeatModifier = (_c = (_b = text.slice(pos).match(/^>\d+/)) == null ? void 0 : _b[0]) != null ? _c : "";
|
|
1259
1123
|
pos += repeatModifier.length;
|
|
@@ -1266,7 +1130,7 @@ function readTag(text, pos, startBracket) {
|
|
|
1266
1130
|
!repeatModifier && "repeat modifier",
|
|
1267
1131
|
!releaseSelfModifier && "release modifier",
|
|
1268
1132
|
`"${expectedEndBracket}"`
|
|
1269
|
-
].filter(Boolean).join(" or "), text[pos], text));
|
|
1133
|
+
].filter(Boolean).join(" or "), text[pos], text, context));
|
|
1270
1134
|
}
|
|
1271
1135
|
pos += endBracket.length;
|
|
1272
1136
|
return {
|
|
@@ -1277,9 +1141,9 @@ function readTag(text, pos, startBracket) {
|
|
|
1277
1141
|
releaseSelf: hasReleaseSelf(releaseSelfModifier, repeatModifier)
|
|
1278
1142
|
};
|
|
1279
1143
|
}
|
|
1280
|
-
function assertDescriptor(descriptor, text, pos) {
|
|
1144
|
+
function assertDescriptor(descriptor, text, pos, context) {
|
|
1281
1145
|
if (!descriptor) {
|
|
1282
|
-
throw new Error(getErrorMessage("key descriptor", text[pos], text));
|
|
1146
|
+
throw new Error(getErrorMessage("key descriptor", text[pos], text, context));
|
|
1283
1147
|
}
|
|
1284
1148
|
}
|
|
1285
1149
|
function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
@@ -1290,12 +1154,17 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
|
|
|
1290
1154
|
return false;
|
|
1291
1155
|
}
|
|
1292
1156
|
}
|
|
1293
|
-
function getErrorMessage(expected, found, text) {
|
|
1157
|
+
function getErrorMessage(expected, found, text, context) {
|
|
1294
1158
|
return `Expected ${expected} but found "${found != null ? found : ""}" in "${text}"
|
|
1295
|
-
See https://
|
|
1159
|
+
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`}
|
|
1296
1160
|
for more information about how userEvent parses your input.`;
|
|
1297
1161
|
}
|
|
1298
1162
|
|
|
1163
|
+
// src/utils/misc/cloneEvent.ts
|
|
1164
|
+
function cloneEvent(event) {
|
|
1165
|
+
return new event.constructor(event.type, event);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1299
1168
|
// src/utils/misc/getDocumentFromNode.ts
|
|
1300
1169
|
function getDocumentFromNode(el) {
|
|
1301
1170
|
return isDocument(el) ? el : el.ownerDocument;
|
|
@@ -1333,9 +1202,6 @@ function wait(time) {
|
|
|
1333
1202
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1334
1203
|
}
|
|
1335
1204
|
|
|
1336
|
-
// src/utils/misc/hasFormSubmit.ts
|
|
1337
|
-
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1338
|
-
|
|
1339
1205
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1340
1206
|
var import_helpers2 = require("@testing-library/dom/dist/helpers.js");
|
|
1341
1207
|
|
|
@@ -1462,10 +1328,6 @@ function hasBitFlag(conf, flag) {
|
|
|
1462
1328
|
return (conf & flag) > 0;
|
|
1463
1329
|
}
|
|
1464
1330
|
|
|
1465
|
-
// src/utils/pointer/firePointerEvents.ts
|
|
1466
|
-
var import_dom5 = require("@testing-library/dom");
|
|
1467
|
-
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1468
|
-
|
|
1469
1331
|
// src/utils/pointer/mouseButtons.ts
|
|
1470
1332
|
var MouseButton = {
|
|
1471
1333
|
primary: 0,
|
|
@@ -1497,38 +1359,41 @@ function getMouseButtons(...buttons) {
|
|
|
1497
1359
|
return v;
|
|
1498
1360
|
}
|
|
1499
1361
|
|
|
1500
|
-
// src/
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
clickCount
|
|
1510
|
-
}) {
|
|
1511
|
-
const init = __spreadValues(__spreadValues({}, coords), getUIEventModifiers(keyboardState));
|
|
1512
|
-
if (type3 === "click" || type3.startsWith("pointer")) {
|
|
1513
|
-
init.pointerId = pointerId;
|
|
1514
|
-
init.pointerType = pointerType;
|
|
1515
|
-
}
|
|
1516
|
-
if (["pointerdown", "pointerup"].includes(type3)) {
|
|
1517
|
-
init.isPrimary = isPrimary;
|
|
1362
|
+
// src/event/createEvent.ts
|
|
1363
|
+
var import_dom2 = require("@testing-library/dom");
|
|
1364
|
+
|
|
1365
|
+
// src/event/eventMap.ts
|
|
1366
|
+
var import_event_map = require("@testing-library/dom/dist/event-map.js");
|
|
1367
|
+
var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
|
|
1368
|
+
beforeInput: {
|
|
1369
|
+
EventType: "InputEvent",
|
|
1370
|
+
defaultInit: { bubbles: true, cancelable: true, composed: true }
|
|
1518
1371
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1372
|
+
});
|
|
1373
|
+
var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1374
|
+
|
|
1375
|
+
// src/event/eventTypes.ts
|
|
1376
|
+
var import_event_map2 = require("@testing-library/dom/dist/event-map.js");
|
|
1377
|
+
var eventKeys = Object.fromEntries(Object.keys(import_event_map2.eventMap).map((k) => [k.toLowerCase(), k]));
|
|
1378
|
+
function getEventClass(type3) {
|
|
1379
|
+
return type3 in eventKeys ? import_event_map2.eventMap[eventKeys[type3]].EventType : "Event";
|
|
1380
|
+
}
|
|
1381
|
+
var mouseEvents = ["MouseEvent", "PointerEvent"];
|
|
1382
|
+
function isMouseEvent(type3) {
|
|
1383
|
+
return mouseEvents.includes(getEventClass(type3));
|
|
1384
|
+
}
|
|
1385
|
+
function isKeyboardEvent(type3) {
|
|
1386
|
+
return getEventClass(type3) === "KeyboardEvent";
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
// src/event/createEvent.ts
|
|
1390
|
+
function createEvent(type3, target, init) {
|
|
1391
|
+
const event = (0, import_dom2.createEvent)(type3, target, init, eventMap[eventMapKeys[type3]]);
|
|
1392
|
+
if (isMouseEvent(type3) && init) {
|
|
1393
|
+
assignPositionInit(event, init);
|
|
1394
|
+
assignPointerInit(event, init);
|
|
1526
1395
|
}
|
|
1527
|
-
|
|
1528
|
-
const event = import_dom5.createEvent[eventKey](target, init);
|
|
1529
|
-
assignPositionInit(event, init);
|
|
1530
|
-
assignPointerInit(event, init);
|
|
1531
|
-
return (0, import_dom5.fireEvent)(target, event);
|
|
1396
|
+
return event;
|
|
1532
1397
|
}
|
|
1533
1398
|
function assignProps(obj, props) {
|
|
1534
1399
|
for (const [key, value] of Object.entries(props)) {
|
|
@@ -1561,273 +1426,430 @@ function assignPositionInit(obj, {
|
|
|
1561
1426
|
screenY: screenY != null ? screenY : 0
|
|
1562
1427
|
});
|
|
1563
1428
|
}
|
|
1564
|
-
function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
1565
|
-
assignProps(obj, {
|
|
1566
|
-
isPrimary,
|
|
1567
|
-
pointerId,
|
|
1568
|
-
pointerType
|
|
1429
|
+
function assignPointerInit(obj, { isPrimary, pointerId, pointerType }) {
|
|
1430
|
+
assignProps(obj, {
|
|
1431
|
+
isPrimary,
|
|
1432
|
+
pointerId,
|
|
1433
|
+
pointerType
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// src/event/behavior/registry.ts
|
|
1438
|
+
var behavior = {};
|
|
1439
|
+
|
|
1440
|
+
// src/event/behavior/click.ts
|
|
1441
|
+
behavior.click = (event, target, config) => {
|
|
1442
|
+
const context = target.closest("button,input,label,select,textarea");
|
|
1443
|
+
const control = context && isElementType(context, "label") && context.control;
|
|
1444
|
+
if (control) {
|
|
1445
|
+
return () => {
|
|
1446
|
+
if (isFocusable(control)) {
|
|
1447
|
+
focus(control);
|
|
1448
|
+
}
|
|
1449
|
+
dispatchEvent(config, control, cloneEvent(event));
|
|
1450
|
+
};
|
|
1451
|
+
} else if (isElementType(target, "input", { type: "file" })) {
|
|
1452
|
+
return () => {
|
|
1453
|
+
blur(target);
|
|
1454
|
+
target.dispatchEvent(new Event("fileDialog"));
|
|
1455
|
+
focus(target);
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
// src/event/behavior/cut.ts
|
|
1461
|
+
behavior.cut = (event, target, config) => {
|
|
1462
|
+
return () => {
|
|
1463
|
+
if (isEditable(target)) {
|
|
1464
|
+
input(config, target, "", "deleteByCut");
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
// src/event/behavior/keydown.ts
|
|
1470
|
+
behavior.keydown = (event, target, config) => {
|
|
1471
|
+
var _a, _b;
|
|
1472
|
+
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1473
|
+
};
|
|
1474
|
+
var keydownBehavior = {
|
|
1475
|
+
ArrowLeft: (event, target) => () => moveSelection(target, -1),
|
|
1476
|
+
ArrowRight: (event, target) => () => moveSelection(target, 1),
|
|
1477
|
+
Backspace: (event, target, config) => {
|
|
1478
|
+
if (isEditable(target)) {
|
|
1479
|
+
return () => {
|
|
1480
|
+
input(config, target, "", "deleteContentBackward");
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
},
|
|
1484
|
+
Delete: (event, target, config) => {
|
|
1485
|
+
if (isEditable(target)) {
|
|
1486
|
+
return () => {
|
|
1487
|
+
input(config, target, "", "deleteContentForward");
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
},
|
|
1491
|
+
End: (event, target) => {
|
|
1492
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1493
|
+
return () => {
|
|
1494
|
+
var _a, _b;
|
|
1495
|
+
const newPos = (_b = (_a = getValue(target)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1496
|
+
setSelectionRange(target, newPos, newPos);
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
Home: (event, target) => {
|
|
1501
|
+
if (isElementType(target, ["input", "textarea"]) || isContentEditable(target)) {
|
|
1502
|
+
return () => {
|
|
1503
|
+
setSelectionRange(target, 0, 0);
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
PageDown: (event, target) => {
|
|
1508
|
+
if (isElementType(target, ["input"])) {
|
|
1509
|
+
return () => {
|
|
1510
|
+
const newPos = getValue(target).length;
|
|
1511
|
+
setSelectionRange(target, newPos, newPos);
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
PageUp: (event, target) => {
|
|
1516
|
+
if (isElementType(target, ["input"])) {
|
|
1517
|
+
return () => {
|
|
1518
|
+
setSelectionRange(target, 0, 0);
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
},
|
|
1522
|
+
Tab: (event, target, { keyboardState }) => {
|
|
1523
|
+
return () => {
|
|
1524
|
+
const dest = getTabDestination(target, keyboardState.modifiers.Shift);
|
|
1525
|
+
focus(dest);
|
|
1526
|
+
if (hasOwnSelection(dest)) {
|
|
1527
|
+
setUISelection(dest, {
|
|
1528
|
+
anchorOffset: 0,
|
|
1529
|
+
focusOffset: dest.value.length
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
var combinationBehavior = (event, target, config) => {
|
|
1536
|
+
if (event.code === "KeyA" && config.keyboardState.modifiers.Control) {
|
|
1537
|
+
return () => selectAll(target);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
// src/event/behavior/keypress.ts
|
|
1542
|
+
behavior.keypress = (event, target, config) => {
|
|
1543
|
+
if (event.key === "Enter") {
|
|
1544
|
+
if (isElementType(target, "button") || isElementType(target, "input") && ClickInputOnEnter.includes(target.type) || isElementType(target, "a") && Boolean(target.href)) {
|
|
1545
|
+
return () => {
|
|
1546
|
+
dispatchUIEvent(config, target, "click");
|
|
1547
|
+
};
|
|
1548
|
+
} else if (isElementType(target, "input")) {
|
|
1549
|
+
const form = target.form;
|
|
1550
|
+
const submit = form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
|
|
1551
|
+
if (submit) {
|
|
1552
|
+
return () => dispatchUIEvent(config, submit, "click");
|
|
1553
|
+
} else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll("input").length === 1) {
|
|
1554
|
+
return () => dispatchUIEvent(config, form, "submit");
|
|
1555
|
+
} else {
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
if (isEditable(target)) {
|
|
1561
|
+
const inputType = event.key === "Enter" ? isContentEditable(target) && !config.keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak" : "insertText";
|
|
1562
|
+
const inputData = event.key === "Enter" ? "\n" : event.key;
|
|
1563
|
+
return () => input(config, target, inputData, inputType);
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1566
|
+
var ClickInputOnEnter = [
|
|
1567
|
+
"button",
|
|
1568
|
+
"color",
|
|
1569
|
+
"file",
|
|
1570
|
+
"image",
|
|
1571
|
+
"reset",
|
|
1572
|
+
"submit"
|
|
1573
|
+
];
|
|
1574
|
+
var SubmitSingleInputOnEnter = [
|
|
1575
|
+
"email",
|
|
1576
|
+
"month",
|
|
1577
|
+
"password",
|
|
1578
|
+
"search",
|
|
1579
|
+
"tel",
|
|
1580
|
+
"text",
|
|
1581
|
+
"url",
|
|
1582
|
+
"week"
|
|
1583
|
+
];
|
|
1584
|
+
|
|
1585
|
+
// src/event/behavior/keyup.ts
|
|
1586
|
+
behavior.keyup = (event, target, config) => {
|
|
1587
|
+
var _a;
|
|
1588
|
+
return (_a = keyupBehavior[event.key]) == null ? void 0 : _a.call(keyupBehavior, event, target, config);
|
|
1589
|
+
};
|
|
1590
|
+
var keyupBehavior = {
|
|
1591
|
+
" ": (event, target, config) => {
|
|
1592
|
+
if (isClickableInput(target)) {
|
|
1593
|
+
return () => dispatchUIEvent(config, target, "click");
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// src/event/behavior/paste.ts
|
|
1599
|
+
behavior.paste = (event, target, config) => {
|
|
1600
|
+
if (isEditable(target)) {
|
|
1601
|
+
return () => {
|
|
1602
|
+
var _a;
|
|
1603
|
+
const insertData = (_a = event.clipboardData) == null ? void 0 : _a.getData("text");
|
|
1604
|
+
if (insertData) {
|
|
1605
|
+
input(config, target, insertData, "insertFromPaste");
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
|
|
1611
|
+
// src/event/wrapEvent.ts
|
|
1612
|
+
var import_dom3 = require("@testing-library/dom");
|
|
1613
|
+
function wrapEvent(cb, _element) {
|
|
1614
|
+
return (0, import_dom3.getConfig)().eventWrapper(cb);
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
// src/event/dispatchEvent.ts
|
|
1618
|
+
function dispatchEvent(config, target, event, preventDefault = false) {
|
|
1619
|
+
var _a, _b;
|
|
1620
|
+
const type3 = event.type;
|
|
1621
|
+
const behaviorImplementation = preventDefault ? () => {
|
|
1622
|
+
} : (_b = (_a = behavior)[type3]) == null ? void 0 : _b.call(_a, event, target, config);
|
|
1623
|
+
if (behaviorImplementation) {
|
|
1624
|
+
event.preventDefault();
|
|
1625
|
+
let defaultPrevented = false;
|
|
1626
|
+
Object.defineProperty(event, "defaultPrevented", {
|
|
1627
|
+
get: () => defaultPrevented
|
|
1628
|
+
});
|
|
1629
|
+
Object.defineProperty(event, "preventDefault", {
|
|
1630
|
+
value: () => {
|
|
1631
|
+
defaultPrevented = event.cancelable;
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
wrapEvent(() => target.dispatchEvent(event), target);
|
|
1635
|
+
if (!defaultPrevented) {
|
|
1636
|
+
behaviorImplementation();
|
|
1637
|
+
}
|
|
1638
|
+
return !defaultPrevented;
|
|
1639
|
+
}
|
|
1640
|
+
return wrapEvent(() => target.dispatchEvent(event), target);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// src/event/index.ts
|
|
1644
|
+
function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
|
|
1645
|
+
if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
|
|
1646
|
+
init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
|
|
1647
|
+
}
|
|
1648
|
+
const event = createEvent(type3, target, init);
|
|
1649
|
+
return dispatchEvent(config, target, event, preventDefault);
|
|
1650
|
+
}
|
|
1651
|
+
function bindDispatchUIEvent(config) {
|
|
1652
|
+
return dispatchUIEvent.bind(void 0, config);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// src/document/interceptor.ts
|
|
1656
|
+
var Interceptor = Symbol("Interceptor for programmatical calls");
|
|
1657
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
1658
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
1659
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1660
|
+
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1661
|
+
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1662
|
+
return;
|
|
1663
|
+
}
|
|
1664
|
+
function intercept(...args) {
|
|
1665
|
+
const { applyNative = true, realArgs } = interceptorImpl.call(this, ...args);
|
|
1666
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
1667
|
+
if (target === "set") {
|
|
1668
|
+
realFunc.call(this, realArgs);
|
|
1669
|
+
} else {
|
|
1670
|
+
realFunc.call(this, ...realArgs);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
;
|
|
1674
|
+
intercept[Interceptor] = Interceptor;
|
|
1675
|
+
Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
|
|
1676
|
+
[target]: intercept
|
|
1677
|
+
}));
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
// src/document/selection.ts
|
|
1681
|
+
var UISelection = Symbol("Displayed selection in UI");
|
|
1682
|
+
function prepareSelectionInterceptor(element) {
|
|
1683
|
+
prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
|
|
1684
|
+
const isUI = start && typeof start === "object" && start[UISelection];
|
|
1685
|
+
if (!isUI) {
|
|
1686
|
+
this[UISelection] = void 0;
|
|
1687
|
+
}
|
|
1688
|
+
return {
|
|
1689
|
+
realArgs: [Number(start), end, direction]
|
|
1690
|
+
};
|
|
1691
|
+
});
|
|
1692
|
+
prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
|
|
1693
|
+
this[UISelection] = void 0;
|
|
1694
|
+
return { realArgs: v };
|
|
1695
|
+
});
|
|
1696
|
+
prepareInterceptor(element, "selectionEnd", function interceptorImpl(v) {
|
|
1697
|
+
this[UISelection] = void 0;
|
|
1698
|
+
return { realArgs: v };
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
function setUISelection(element, {
|
|
1702
|
+
focusOffset: focusOffsetParam,
|
|
1703
|
+
anchorOffset: anchorOffsetParam = focusOffsetParam
|
|
1704
|
+
}, mode = "replace") {
|
|
1705
|
+
const valueLength = getUIValue(element).length;
|
|
1706
|
+
const sanitizeOffset = (o) => Math.max(0, Math.min(valueLength, o));
|
|
1707
|
+
const anchorOffset = mode === "replace" || element[UISelection] === void 0 ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
|
|
1708
|
+
const focusOffset = sanitizeOffset(focusOffsetParam);
|
|
1709
|
+
const startOffset = Math.min(anchorOffset, focusOffset);
|
|
1710
|
+
const endOffset = Math.max(anchorOffset, focusOffset);
|
|
1711
|
+
element[UISelection] = {
|
|
1712
|
+
anchorOffset,
|
|
1713
|
+
focusOffset
|
|
1714
|
+
};
|
|
1715
|
+
if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const startObj = new Number(startOffset);
|
|
1719
|
+
startObj[UISelection] = UISelection;
|
|
1720
|
+
try {
|
|
1721
|
+
element.setSelectionRange(startObj, endOffset);
|
|
1722
|
+
} catch {
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
function getUISelection(element) {
|
|
1726
|
+
var _a, _b, _c;
|
|
1727
|
+
const sel = (_c = element[UISelection]) != null ? _c : {
|
|
1728
|
+
anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
|
|
1729
|
+
focusOffset: (_b = element.selectionEnd) != null ? _b : 0
|
|
1730
|
+
};
|
|
1731
|
+
return __spreadProps(__spreadValues({}, sel), {
|
|
1732
|
+
startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
|
|
1733
|
+
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
// src/document/value.ts
|
|
1738
|
+
var UIValue = Symbol("Displayed value in UI");
|
|
1739
|
+
var InitialValue = Symbol("Initial value to compare on blur");
|
|
1740
|
+
var TrackChanges = Symbol("Track programmatic changes for React workaround");
|
|
1741
|
+
function valueInterceptor(v) {
|
|
1742
|
+
const isUI = typeof v === "object" && v[UIValue];
|
|
1743
|
+
if (isUI) {
|
|
1744
|
+
this[UIValue] = String(v);
|
|
1745
|
+
setPreviousValue(this, String(this.value));
|
|
1746
|
+
} else {
|
|
1747
|
+
trackOrSetValue(this, String(v));
|
|
1748
|
+
}
|
|
1749
|
+
return {
|
|
1750
|
+
applyNative: !!isUI,
|
|
1751
|
+
realArgs: sanitizeValue(this, v)
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
function sanitizeValue(element, v) {
|
|
1755
|
+
if (isElementType(element, "input", { type: "number" }) && String(v) !== "" && !Number.isNaN(Number(v))) {
|
|
1756
|
+
return String(Number(v));
|
|
1757
|
+
}
|
|
1758
|
+
return String(v);
|
|
1759
|
+
}
|
|
1760
|
+
function prepareValueInterceptor(element) {
|
|
1761
|
+
prepareInterceptor(element, "value", valueInterceptor);
|
|
1762
|
+
}
|
|
1763
|
+
function setUIValue(element, value) {
|
|
1764
|
+
element.value = {
|
|
1765
|
+
[UIValue]: UIValue,
|
|
1766
|
+
toString: () => value
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
function getUIValue(element) {
|
|
1770
|
+
return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
|
|
1771
|
+
}
|
|
1772
|
+
function setInitialValue(element) {
|
|
1773
|
+
element[InitialValue] = element.value;
|
|
1774
|
+
}
|
|
1775
|
+
function getInitialValue(element) {
|
|
1776
|
+
return element[InitialValue];
|
|
1777
|
+
}
|
|
1778
|
+
function setPreviousValue(element, v) {
|
|
1779
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
|
|
1780
|
+
}
|
|
1781
|
+
function startTrackValue(element) {
|
|
1782
|
+
element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
|
|
1783
|
+
nextValue: String(element.value),
|
|
1784
|
+
tracked: []
|
|
1569
1785
|
});
|
|
1570
1786
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
{
|
|
1575
|
-
|
|
1576
|
-
handle: (keyDef, element) => {
|
|
1577
|
-
if (hasOwnSelection(element)) {
|
|
1578
|
-
const selection = getUISelection(element);
|
|
1579
|
-
setSelection({
|
|
1580
|
-
focusNode: element,
|
|
1581
|
-
focusOffset: selection.startOffset === selection.endOffset ? selection.focusOffset + (keyDef.key === "ArrowLeft" ? -1 : 1) : keyDef.key === "ArrowLeft" ? selection.startOffset : selection.endOffset
|
|
1582
|
-
});
|
|
1583
|
-
} else {
|
|
1584
|
-
const selection = element.ownerDocument.getSelection();
|
|
1585
|
-
if (!selection) {
|
|
1586
|
-
return;
|
|
1587
|
-
}
|
|
1588
|
-
if (selection.isCollapsed) {
|
|
1589
|
-
const nextPosition = getNextCursorPosition(selection.focusNode, selection.focusOffset, keyDef.key === "ArrowLeft" ? -1 : 1);
|
|
1590
|
-
if (nextPosition) {
|
|
1591
|
-
setSelection({
|
|
1592
|
-
focusNode: nextPosition.node,
|
|
1593
|
-
focusOffset: nextPosition.offset
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
} else {
|
|
1597
|
-
selection[keyDef.key === "ArrowLeft" ? "collapseToStart" : "collapseToEnd"]();
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
];
|
|
1603
|
-
|
|
1604
|
-
// src/keyboard/plugins/control.ts
|
|
1605
|
-
var keydownBehavior2 = [
|
|
1606
|
-
{
|
|
1607
|
-
matches: (keyDef, element) => (keyDef.key === "Home" || keyDef.key === "End") && (isElementType(element, ["input", "textarea"]) || isContentEditable(element)),
|
|
1608
|
-
handle: (keyDef, element) => {
|
|
1609
|
-
var _a, _b;
|
|
1610
|
-
if (keyDef.key === "Home") {
|
|
1611
|
-
setSelectionRange(element, 0, 0);
|
|
1612
|
-
} else {
|
|
1613
|
-
const newPos = (_b = (_a = getValue(element)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
1614
|
-
setSelectionRange(element, newPos, newPos);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
},
|
|
1618
|
-
{
|
|
1619
|
-
matches: (keyDef, element) => (keyDef.key === "PageUp" || keyDef.key === "PageDown") && isElementType(element, ["input"]),
|
|
1620
|
-
handle: (keyDef, element) => {
|
|
1621
|
-
var _a, _b;
|
|
1622
|
-
if (keyDef.key === "PageUp") {
|
|
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 === "Delete" && isEditable(element),
|
|
1632
|
-
handle: (keDef, element) => {
|
|
1633
|
-
var _a;
|
|
1634
|
-
(_a = prepareInput("", element, "deleteContentForward")) == null ? void 0 : _a.commit();
|
|
1635
|
-
}
|
|
1787
|
+
function trackOrSetValue(element, v) {
|
|
1788
|
+
var _a, _b, _c;
|
|
1789
|
+
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1790
|
+
if (!((_c = element[TrackChanges]) == null ? void 0 : _c.tracked)) {
|
|
1791
|
+
setCleanValue(element, v);
|
|
1636
1792
|
}
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1793
|
+
}
|
|
1794
|
+
function setCleanValue(element, v) {
|
|
1795
|
+
element[UIValue] = void 0;
|
|
1796
|
+
element[InitialValue] = v;
|
|
1797
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1798
|
+
}
|
|
1799
|
+
function endTrackValue(element) {
|
|
1800
|
+
var _a, _b;
|
|
1801
|
+
const changes = element[TrackChanges];
|
|
1802
|
+
element[TrackChanges] = void 0;
|
|
1803
|
+
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;
|
|
1804
|
+
if (((_b = changes == null ? void 0 : changes.tracked) == null ? void 0 : _b.length) && !isJustReactStateUpdate) {
|
|
1805
|
+
setCleanValue(element, changes.tracked[changes.tracked.length - 1]);
|
|
1647
1806
|
}
|
|
1807
|
+
return isJustReactStateUpdate;
|
|
1648
1808
|
}
|
|
1649
1809
|
|
|
1650
|
-
// src/
|
|
1651
|
-
var
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "time", readOnly: false });
|
|
1656
|
-
},
|
|
1657
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1658
|
-
var _a;
|
|
1659
|
-
let newEntry = keyDef.key;
|
|
1660
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1661
|
-
const timeNewEntry = buildTimeValue(textToBeTyped);
|
|
1662
|
-
if (isValidInputTimeValue(element, timeNewEntry)) {
|
|
1663
|
-
newEntry = timeNewEntry;
|
|
1664
|
-
}
|
|
1665
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1666
|
-
const prevValue = getValue(element);
|
|
1667
|
-
if (prevValue !== newValue) {
|
|
1668
|
-
editInputElement(element, {
|
|
1669
|
-
newValue,
|
|
1670
|
-
newSelection: {
|
|
1671
|
-
node: element,
|
|
1672
|
-
offset: newOffset
|
|
1673
|
-
},
|
|
1674
|
-
eventOverrides: {
|
|
1675
|
-
data: keyDef.key,
|
|
1676
|
-
inputType: "insertText"
|
|
1677
|
-
}
|
|
1678
|
-
});
|
|
1679
|
-
}
|
|
1680
|
-
fireChangeForInputTimeIfValid(element, prevValue, timeNewEntry);
|
|
1681
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1682
|
-
}
|
|
1683
|
-
},
|
|
1684
|
-
{
|
|
1685
|
-
matches: (keyDef, element) => {
|
|
1686
|
-
var _a;
|
|
1687
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "date", readOnly: false });
|
|
1688
|
-
},
|
|
1689
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1690
|
-
var _a;
|
|
1691
|
-
let newEntry = keyDef.key;
|
|
1692
|
-
const textToBeTyped = ((_a = keyboardState.carryValue) != null ? _a : "") + newEntry;
|
|
1693
|
-
const isValidToBeTyped = isValidDateValue(element, textToBeTyped);
|
|
1694
|
-
if (isValidToBeTyped) {
|
|
1695
|
-
newEntry = textToBeTyped;
|
|
1696
|
-
}
|
|
1697
|
-
const { newValue, newOffset } = calculateNewValue(newEntry, element, getInputRange(element));
|
|
1698
|
-
const prevValue = getValue(element);
|
|
1699
|
-
if (prevValue !== newValue) {
|
|
1700
|
-
editInputElement(element, {
|
|
1701
|
-
newValue,
|
|
1702
|
-
newSelection: {
|
|
1703
|
-
node: element,
|
|
1704
|
-
offset: newOffset
|
|
1705
|
-
},
|
|
1706
|
-
eventOverrides: {
|
|
1707
|
-
data: keyDef.key,
|
|
1708
|
-
inputType: "insertText"
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
if (isValidToBeTyped) {
|
|
1713
|
-
import_dom7.fireEvent.change(element, {
|
|
1714
|
-
target: { value: textToBeTyped }
|
|
1715
|
-
});
|
|
1716
|
-
}
|
|
1717
|
-
keyboardState.carryValue = textToBeTyped;
|
|
1718
|
-
}
|
|
1719
|
-
},
|
|
1720
|
-
{
|
|
1721
|
-
matches: (keyDef, element) => {
|
|
1722
|
-
var _a;
|
|
1723
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && isElementType(element, "input", { type: "number", readOnly: false });
|
|
1724
|
-
},
|
|
1725
|
-
handle: (keyDef, element) => {
|
|
1726
|
-
var _a, _b;
|
|
1727
|
-
if (!/[\d.\-e]/.test(keyDef.key)) {
|
|
1728
|
-
return;
|
|
1729
|
-
}
|
|
1730
|
-
const { getNewValue, commit } = prepareInput(keyDef.key, element);
|
|
1731
|
-
const newValue = getNewValue();
|
|
1732
|
-
const valueParts = newValue.split("e", 2);
|
|
1733
|
-
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])) {
|
|
1734
|
-
return;
|
|
1735
|
-
}
|
|
1736
|
-
commit();
|
|
1737
|
-
}
|
|
1738
|
-
},
|
|
1739
|
-
{
|
|
1740
|
-
matches: (keyDef, element) => {
|
|
1741
|
-
var _a;
|
|
1742
|
-
return ((_a = keyDef.key) == null ? void 0 : _a.length) === 1 && (isEditableInput(element) || isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0;
|
|
1743
|
-
},
|
|
1744
|
-
handle: (keyDef, element) => {
|
|
1745
|
-
var _a;
|
|
1746
|
-
(_a = prepareInput(keyDef.key, element)) == null ? void 0 : _a.commit();
|
|
1747
|
-
}
|
|
1748
|
-
},
|
|
1749
|
-
{
|
|
1750
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isElementType(element, "textarea", { readOnly: false }) || isContentEditable(element)) && getSpaceUntilMaxLength(element) !== 0,
|
|
1751
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1752
|
-
var _a;
|
|
1753
|
-
(_a = prepareInput("\n", element, isContentEditable(element) && !keyboardState.modifiers.Shift ? "insertParagraph" : "insertLineBreak")) == null ? void 0 : _a.commit();
|
|
1754
|
-
}
|
|
1810
|
+
// src/document/index.ts
|
|
1811
|
+
var isPrepared = Symbol("Node prepared with document state workarounds");
|
|
1812
|
+
function prepareDocument(document2) {
|
|
1813
|
+
if (document2[isPrepared]) {
|
|
1814
|
+
return;
|
|
1755
1815
|
}
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
(_a = prepareInput("", element, "deleteContentBackward")) == null ? void 0 : _a.commit();
|
|
1766
|
-
}
|
|
1767
|
-
},
|
|
1768
|
-
{
|
|
1769
|
-
matches: (keyDef) => keyDef.key === "Tab",
|
|
1770
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1771
|
-
const dest = getTabDestination(element, keyboardState.modifiers.Shift);
|
|
1772
|
-
if (dest === element.ownerDocument.body) {
|
|
1773
|
-
blur(element);
|
|
1774
|
-
} else {
|
|
1775
|
-
focus(dest);
|
|
1776
|
-
if (isElementType(dest, ["input", "textarea"])) {
|
|
1777
|
-
setUISelection(dest, {
|
|
1778
|
-
anchorOffset: 0,
|
|
1779
|
-
focusOffset: dest.value.length
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1816
|
+
document2.addEventListener("focus", (e) => {
|
|
1817
|
+
const el = e.target;
|
|
1818
|
+
prepareElement(el);
|
|
1819
|
+
}, {
|
|
1820
|
+
capture: true,
|
|
1821
|
+
passive: true
|
|
1822
|
+
});
|
|
1823
|
+
if (document2.activeElement) {
|
|
1824
|
+
prepareElement(document2.activeElement);
|
|
1784
1825
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
const form = element.form;
|
|
1791
|
-
if (hasFormSubmit(form)) {
|
|
1792
|
-
import_dom8.fireEvent.submit(form);
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
},
|
|
1796
|
-
{
|
|
1797
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && (isClickableInput(element) || isElementType(element, "a") && Boolean(element.href)),
|
|
1798
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1799
|
-
import_dom8.fireEvent.click(element, getUIEventModifiers(keyboardState));
|
|
1800
|
-
}
|
|
1801
|
-
},
|
|
1802
|
-
{
|
|
1803
|
-
matches: (keyDef, element) => keyDef.key === "Enter" && isElementType(element, "input"),
|
|
1804
|
-
handle: (keyDef, element) => {
|
|
1805
|
-
const form = element.form;
|
|
1806
|
-
if (form && (form.querySelectorAll("input").length === 1 || hasFormSubmit(form))) {
|
|
1807
|
-
import_dom8.fireEvent.submit(form);
|
|
1808
|
-
}
|
|
1826
|
+
document2.addEventListener("blur", (e) => {
|
|
1827
|
+
const el = e.target;
|
|
1828
|
+
const initialValue = getInitialValue(el);
|
|
1829
|
+
if (typeof initialValue === "string" && el.value !== initialValue) {
|
|
1830
|
+
dispatchUIEvent({}, el, "change");
|
|
1809
1831
|
}
|
|
1832
|
+
}, {
|
|
1833
|
+
capture: true,
|
|
1834
|
+
passive: true
|
|
1835
|
+
});
|
|
1836
|
+
document2[isPrepared] = isPrepared;
|
|
1837
|
+
}
|
|
1838
|
+
function prepareElement(el) {
|
|
1839
|
+
if ("value" in el) {
|
|
1840
|
+
setInitialValue(el);
|
|
1810
1841
|
}
|
|
1811
|
-
]
|
|
1812
|
-
|
|
1813
|
-
{
|
|
1814
|
-
matches: (keyDef, element) => keyDef.key === " " && isClickableInput(element),
|
|
1815
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1816
|
-
import_dom8.fireEvent.click(element, getUIEventModifiers(keyboardState));
|
|
1817
|
-
}
|
|
1842
|
+
if (el[isPrepared]) {
|
|
1843
|
+
return;
|
|
1818
1844
|
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
var keydownBehavior4 = [
|
|
1823
|
-
{
|
|
1824
|
-
matches: (keyDef, element, { keyboardState }) => keyDef.code === "KeyA" && keyboardState.modifiers.Control,
|
|
1825
|
-
handle: (keyDef, element) => selectAll(element)
|
|
1845
|
+
if ("value" in el) {
|
|
1846
|
+
prepareValueInterceptor(el);
|
|
1847
|
+
prepareSelectionInterceptor(el);
|
|
1826
1848
|
}
|
|
1827
|
-
];
|
|
1849
|
+
el[isPrepared] = isPrepared;
|
|
1850
|
+
}
|
|
1828
1851
|
|
|
1829
|
-
// src/keyboard/
|
|
1830
|
-
var import_dom9 = require("@testing-library/dom");
|
|
1852
|
+
// src/keyboard/modifiers.ts
|
|
1831
1853
|
var modifierKeys = [
|
|
1832
1854
|
"Alt",
|
|
1833
1855
|
"AltGraph",
|
|
@@ -1837,6 +1859,9 @@ var modifierKeys = [
|
|
|
1837
1859
|
"Shift",
|
|
1838
1860
|
"Symbol"
|
|
1839
1861
|
];
|
|
1862
|
+
function isModifierKey(key) {
|
|
1863
|
+
return modifierKeys.includes(key);
|
|
1864
|
+
}
|
|
1840
1865
|
var modifierLocks = [
|
|
1841
1866
|
"CapsLock",
|
|
1842
1867
|
"FnLock",
|
|
@@ -1844,78 +1869,40 @@ var modifierLocks = [
|
|
|
1844
1869
|
"ScrollLock",
|
|
1845
1870
|
"SymbolLock"
|
|
1846
1871
|
];
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1872
|
+
function isModifierLock(key) {
|
|
1873
|
+
return modifierLocks.includes(key);
|
|
1874
|
+
}
|
|
1875
|
+
function preKeydownBehavior(config, { key }, element) {
|
|
1876
|
+
var _a;
|
|
1877
|
+
if (isModifierKey(key)) {
|
|
1878
|
+
config.keyboardState.modifiers[key] = true;
|
|
1879
|
+
if (key === "AltGraph") {
|
|
1880
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1881
|
+
dispatchUIEvent(config, element, "keydown", getKeyEventProps(ctrlKeyDef));
|
|
1857
1882
|
}
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
const key = keyDef.key;
|
|
1863
|
-
keyboardState.modifierPhase[key] = keyboardState.modifiers[key];
|
|
1864
|
-
if (!keyboardState.modifierPhase[key]) {
|
|
1865
|
-
keyboardState.modifiers[key] = true;
|
|
1866
|
-
}
|
|
1883
|
+
} else if (isModifierLock(key)) {
|
|
1884
|
+
config.keyboardState.modifierPhase[key] = config.keyboardState.modifiers[key];
|
|
1885
|
+
if (!config.keyboardState.modifierPhase[key]) {
|
|
1886
|
+
config.keyboardState.modifiers[key] = true;
|
|
1867
1887
|
}
|
|
1868
1888
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
{
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
},
|
|
1877
|
-
{
|
|
1878
|
-
matches: (keyDef) => modifierLocks.includes(keyDef.key),
|
|
1879
|
-
handle: (keyDef, element, { keyboardState }) => {
|
|
1880
|
-
const key = keyDef.key;
|
|
1881
|
-
if (keyboardState.modifierPhase[key]) {
|
|
1882
|
-
keyboardState.modifiers[key] = false;
|
|
1883
|
-
}
|
|
1889
|
+
}
|
|
1890
|
+
function preKeyupBehavior(config, { key }) {
|
|
1891
|
+
if (isModifierKey(key)) {
|
|
1892
|
+
config.keyboardState.modifiers[key] = false;
|
|
1893
|
+
} else if (isModifierLock(key)) {
|
|
1894
|
+
if (config.keyboardState.modifierPhase[key]) {
|
|
1895
|
+
config.keyboardState.modifiers[key] = false;
|
|
1884
1896
|
}
|
|
1885
1897
|
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
const ctrlKeyDef = (_a = keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1893
|
-
import_dom9.fireEvent.keyUp(element, getKeyEventProps(ctrlKeyDef, keyboardState));
|
|
1894
|
-
}
|
|
1898
|
+
}
|
|
1899
|
+
function postKeyupBehavior(config, { key }, element) {
|
|
1900
|
+
var _a;
|
|
1901
|
+
if (key === "AltGraph") {
|
|
1902
|
+
const ctrlKeyDef = (_a = config.keyboardMap.find((k) => k.key === "Control")) != null ? _a : { key: "Control", code: "Control" };
|
|
1903
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(ctrlKeyDef));
|
|
1895
1904
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
// src/keyboard/plugins/index.ts
|
|
1899
|
-
var preKeydownBehavior2 = [
|
|
1900
|
-
...preKeydownBehavior
|
|
1901
|
-
];
|
|
1902
|
-
var keydownBehavior5 = [
|
|
1903
|
-
...keydownBehavior,
|
|
1904
|
-
...keydownBehavior2,
|
|
1905
|
-
...keydownBehavior3,
|
|
1906
|
-
...keydownBehavior4
|
|
1907
|
-
];
|
|
1908
|
-
var keypressBehavior3 = [
|
|
1909
|
-
...keypressBehavior2,
|
|
1910
|
-
...keypressBehavior
|
|
1911
|
-
];
|
|
1912
|
-
var preKeyupBehavior2 = [
|
|
1913
|
-
...preKeyupBehavior
|
|
1914
|
-
];
|
|
1915
|
-
var keyupBehavior2 = [...keyupBehavior];
|
|
1916
|
-
var postKeyupBehavior2 = [
|
|
1917
|
-
...postKeyupBehavior
|
|
1918
|
-
];
|
|
1905
|
+
}
|
|
1919
1906
|
|
|
1920
1907
|
// src/keyboard/keyboardAction.ts
|
|
1921
1908
|
async function keyboardAction(config, actions) {
|
|
@@ -1966,39 +1953,23 @@ async function keydown(keyDef, getCurrentElement, config) {
|
|
|
1966
1953
|
config.keyboardState.carryChar = "";
|
|
1967
1954
|
}
|
|
1968
1955
|
config.keyboardState.activeElement = element;
|
|
1969
|
-
|
|
1970
|
-
const unpreventedDefault =
|
|
1956
|
+
preKeydownBehavior(config, keyDef, element);
|
|
1957
|
+
const unpreventedDefault = dispatchUIEvent(config, element, "keydown", getKeyEventProps(keyDef));
|
|
1971
1958
|
config.keyboardState.pressed.push({ keyDef, unpreventedDefault });
|
|
1972
|
-
if (unpreventedDefault) {
|
|
1973
|
-
applyPlugins(keydownBehavior5, keyDef, getCurrentElement(), config);
|
|
1974
|
-
}
|
|
1975
1959
|
return unpreventedDefault;
|
|
1976
1960
|
}
|
|
1977
1961
|
async function keypress(keyDef, getCurrentElement, config) {
|
|
1978
1962
|
const element = getCurrentElement();
|
|
1979
|
-
|
|
1963
|
+
dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
|
|
1980
1964
|
charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
|
|
1981
1965
|
}));
|
|
1982
|
-
if (unpreventedDefault) {
|
|
1983
|
-
applyPlugins(keypressBehavior3, keyDef, getCurrentElement(), config);
|
|
1984
|
-
}
|
|
1985
1966
|
}
|
|
1986
1967
|
async function keyup(keyDef, getCurrentElement, config, unprevented) {
|
|
1987
1968
|
const element = getCurrentElement();
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
if (unprevented && unpreventedDefault) {
|
|
1991
|
-
applyPlugins(keyupBehavior2, keyDef, getCurrentElement(), config);
|
|
1992
|
-
}
|
|
1969
|
+
preKeyupBehavior(config, keyDef);
|
|
1970
|
+
dispatchUIEvent(config, element, "keyup", getKeyEventProps(keyDef), !unprevented);
|
|
1993
1971
|
config.keyboardState.pressed = config.keyboardState.pressed.filter((k) => k.keyDef !== keyDef);
|
|
1994
|
-
|
|
1995
|
-
}
|
|
1996
|
-
function applyPlugins(pluginCollection, keyDef, element, config) {
|
|
1997
|
-
const plugin = pluginCollection.find((p) => p.matches(keyDef, element, config));
|
|
1998
|
-
if (plugin) {
|
|
1999
|
-
plugin.handle(keyDef, element, config);
|
|
2000
|
-
}
|
|
2001
|
-
return !!plugin;
|
|
1972
|
+
postKeyupBehavior(config, keyDef, element);
|
|
2002
1973
|
}
|
|
2003
1974
|
function hasKeyPress(keyDef, config) {
|
|
2004
1975
|
var _a;
|
|
@@ -2017,7 +1988,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2017
1988
|
releasePrevious,
|
|
2018
1989
|
releaseSelf = true,
|
|
2019
1990
|
repeat
|
|
2020
|
-
} = readNextDescriptor(text);
|
|
1991
|
+
} = readNextDescriptor(text, "keyboard");
|
|
2021
1992
|
const keyDef = (_a = keyboardMap.find((def) => {
|
|
2022
1993
|
var _a2, _b;
|
|
2023
1994
|
if (type3 === "[") {
|
|
@@ -2039,8 +2010,7 @@ function parseKeyDef(keyboardMap, text) {
|
|
|
2039
2010
|
|
|
2040
2011
|
// src/keyboard/index.ts
|
|
2041
2012
|
async function keyboard(text) {
|
|
2042
|
-
const
|
|
2043
|
-
const actions = parseKeyDef(keyboardMap, text);
|
|
2013
|
+
const actions = parseKeyDef(this[Config].keyboardMap, text);
|
|
2044
2014
|
return keyboardAction(this[Config], actions);
|
|
2045
2015
|
}
|
|
2046
2016
|
function createKeyboardState() {
|
|
@@ -2075,7 +2045,7 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2075
2045
|
consumedLength,
|
|
2076
2046
|
releasePrevious,
|
|
2077
2047
|
releaseSelf = true
|
|
2078
|
-
} = readNextDescriptor(keys);
|
|
2048
|
+
} = readNextDescriptor(keys, "pointer");
|
|
2079
2049
|
const keyDef = pointerMap.find((p) => p.name === descriptor);
|
|
2080
2050
|
if (keyDef) {
|
|
2081
2051
|
defs.push({ keyDef, releasePrevious, releaseSelf });
|
|
@@ -2085,6 +2055,34 @@ function parseKeyDef2(pointerMap, keys) {
|
|
|
2085
2055
|
return defs;
|
|
2086
2056
|
}
|
|
2087
2057
|
|
|
2058
|
+
// src/pointer/firePointerEvents.ts
|
|
2059
|
+
function firePointerEvent(config, target, type3, {
|
|
2060
|
+
pointerType,
|
|
2061
|
+
button,
|
|
2062
|
+
coords,
|
|
2063
|
+
pointerId,
|
|
2064
|
+
isPrimary,
|
|
2065
|
+
clickCount
|
|
2066
|
+
}) {
|
|
2067
|
+
const init = __spreadValues({}, coords);
|
|
2068
|
+
if (type3 === "click" || type3.startsWith("pointer")) {
|
|
2069
|
+
init.pointerId = pointerId;
|
|
2070
|
+
init.pointerType = pointerType;
|
|
2071
|
+
}
|
|
2072
|
+
if (["pointerdown", "pointerup"].includes(type3)) {
|
|
2073
|
+
init.isPrimary = isPrimary;
|
|
2074
|
+
}
|
|
2075
|
+
init.button = getMouseButton(button != null ? button : 0);
|
|
2076
|
+
init.buttons = getMouseButtons(...config.pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).map((p) => {
|
|
2077
|
+
var _a;
|
|
2078
|
+
return (_a = p.keyDef.button) != null ? _a : 0;
|
|
2079
|
+
}));
|
|
2080
|
+
if (["mousedown", "mouseup", "click", "dblclick", "contextmenu"].includes(type3)) {
|
|
2081
|
+
init.detail = clickCount;
|
|
2082
|
+
}
|
|
2083
|
+
return dispatchUIEvent(config, target, type3, init);
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2088
2086
|
// src/pointer/resolveSelectionTarget.ts
|
|
2089
2087
|
function resolveSelectionTarget({
|
|
2090
2088
|
target,
|
|
@@ -2131,7 +2129,7 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
2131
2129
|
|
|
2132
2130
|
// src/pointer/pointerMove.ts
|
|
2133
2131
|
async function pointerMove(config, { pointerName = "mouse", target, coords, node, offset }) {
|
|
2134
|
-
const { pointerState
|
|
2132
|
+
const { pointerState } = config;
|
|
2135
2133
|
if (!(pointerName in pointerState.position)) {
|
|
2136
2134
|
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
2137
2135
|
}
|
|
@@ -2206,9 +2204,7 @@ async function pointerMove(config, { pointerName = "mouse", target, coords, node
|
|
|
2206
2204
|
}
|
|
2207
2205
|
}
|
|
2208
2206
|
function fire(eventTarget, type3, eventCoords) {
|
|
2209
|
-
return firePointerEvent(eventTarget, type3, {
|
|
2210
|
-
pointerState,
|
|
2211
|
-
keyboardState,
|
|
2207
|
+
return firePointerEvent(config, eventTarget, type3, {
|
|
2212
2208
|
coords: eventCoords,
|
|
2213
2209
|
pointerId,
|
|
2214
2210
|
pointerType
|
|
@@ -2240,7 +2236,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2240
2236
|
var _a, _b, _c;
|
|
2241
2237
|
setLevelRef(config, 2 /* Trigger */);
|
|
2242
2238
|
assertPointerEvents(config, target);
|
|
2243
|
-
const { pointerState
|
|
2239
|
+
const { pointerState } = config;
|
|
2244
2240
|
const { name, pointerType, button } = keyDef;
|
|
2245
2241
|
const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
|
|
2246
2242
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
@@ -2302,9 +2298,7 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
|
|
|
2302
2298
|
}
|
|
2303
2299
|
return pressObj;
|
|
2304
2300
|
function fire(type3) {
|
|
2305
|
-
return firePointerEvent(target, type3, {
|
|
2306
|
-
pointerState,
|
|
2307
|
-
keyboardState,
|
|
2301
|
+
return firePointerEvent(config, target, type3, {
|
|
2308
2302
|
button,
|
|
2309
2303
|
clickCount,
|
|
2310
2304
|
coords,
|
|
@@ -2321,10 +2315,9 @@ function up(config, pointerName, {
|
|
|
2321
2315
|
node,
|
|
2322
2316
|
offset
|
|
2323
2317
|
}, pressed, targetIsDisabled) {
|
|
2324
|
-
var _a;
|
|
2325
2318
|
setLevelRef(config, 2 /* Trigger */);
|
|
2326
2319
|
assertPointerEvents(config, target);
|
|
2327
|
-
const { pointerState
|
|
2320
|
+
const { pointerState } = config;
|
|
2328
2321
|
pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
|
|
2329
2322
|
const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
|
|
2330
2323
|
let { unpreventedDefault } = pressed;
|
|
@@ -2365,21 +2358,15 @@ function up(config, pointerName, {
|
|
|
2365
2358
|
unpreventedDefault = fire("mouseup") && unpreventedDefault;
|
|
2366
2359
|
const canClick = pointerType !== "mouse" || button === "primary";
|
|
2367
2360
|
if (canClick && target === pressed.downTarget) {
|
|
2368
|
-
|
|
2361
|
+
fire("click");
|
|
2369
2362
|
if (clickCount === 2) {
|
|
2370
2363
|
fire("dblclick");
|
|
2371
2364
|
}
|
|
2372
|
-
const control = (_a = target.closest("label")) == null ? void 0 : _a.control;
|
|
2373
|
-
if (unpreventedClick && control && isFocusable(control)) {
|
|
2374
|
-
focus(control);
|
|
2375
|
-
}
|
|
2376
2365
|
}
|
|
2377
2366
|
}
|
|
2378
2367
|
}
|
|
2379
2368
|
function fire(type3) {
|
|
2380
|
-
return firePointerEvent(target, type3, {
|
|
2381
|
-
pointerState,
|
|
2382
|
-
keyboardState,
|
|
2369
|
+
return firePointerEvent(config, target, type3, {
|
|
2383
2370
|
button,
|
|
2384
2371
|
clickCount,
|
|
2385
2372
|
coords,
|
|
@@ -2475,10 +2462,10 @@ function getPrevTarget(pointerName, state) {
|
|
|
2475
2462
|
}
|
|
2476
2463
|
|
|
2477
2464
|
// src/pointer/index.ts
|
|
2478
|
-
async function pointer(
|
|
2465
|
+
async function pointer(input2) {
|
|
2479
2466
|
const { pointerMap } = this[Config];
|
|
2480
2467
|
const actions = [];
|
|
2481
|
-
(Array.isArray(
|
|
2468
|
+
(Array.isArray(input2) ? input2 : [input2]).forEach((actionInput) => {
|
|
2482
2469
|
if (typeof actionInput === "string") {
|
|
2483
2470
|
actions.push(...parseKeyDef2(pointerMap, actionInput));
|
|
2484
2471
|
} else if ("keys" in actionInput) {
|
|
@@ -2569,7 +2556,6 @@ async function tab({
|
|
|
2569
2556
|
}
|
|
2570
2557
|
|
|
2571
2558
|
// src/clipboard/copy.ts
|
|
2572
|
-
var import_dom11 = require("@testing-library/dom");
|
|
2573
2559
|
async function copy() {
|
|
2574
2560
|
var _a;
|
|
2575
2561
|
const doc = this[Config].document;
|
|
@@ -2578,59 +2564,42 @@ async function copy() {
|
|
|
2578
2564
|
if (clipboardData.items.length === 0) {
|
|
2579
2565
|
return;
|
|
2580
2566
|
}
|
|
2581
|
-
|
|
2567
|
+
if (this.dispatchUIEvent(target, "copy", {
|
|
2582
2568
|
clipboardData
|
|
2583
|
-
})
|
|
2584
|
-
if (this[Config].writeToClipboard) {
|
|
2569
|
+
}) && this[Config].writeToClipboard) {
|
|
2585
2570
|
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2586
2571
|
}
|
|
2587
2572
|
return clipboardData;
|
|
2588
2573
|
}
|
|
2589
2574
|
|
|
2590
2575
|
// src/clipboard/cut.ts
|
|
2591
|
-
var import_dom12 = require("@testing-library/dom");
|
|
2592
2576
|
async function cut() {
|
|
2593
|
-
var _a
|
|
2577
|
+
var _a;
|
|
2594
2578
|
const doc = this[Config].document;
|
|
2595
2579
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2596
2580
|
const clipboardData = copySelection(target);
|
|
2597
2581
|
if (clipboardData.items.length === 0) {
|
|
2598
2582
|
return;
|
|
2599
2583
|
}
|
|
2600
|
-
|
|
2584
|
+
if (this.dispatchUIEvent(target, "cut", {
|
|
2601
2585
|
clipboardData
|
|
2602
|
-
})
|
|
2603
|
-
|
|
2604
|
-
(_b = prepareInput("", target, "deleteByCut")) == null ? void 0 : _b.commit();
|
|
2605
|
-
}
|
|
2606
|
-
if (this[Config].writeToClipboard) {
|
|
2607
|
-
await writeDataTransferToClipboard(doc, clipboardData);
|
|
2586
|
+
}) && this[Config].writeToClipboard) {
|
|
2587
|
+
await writeDataTransferToClipboard(target.ownerDocument, clipboardData);
|
|
2608
2588
|
}
|
|
2609
2589
|
return clipboardData;
|
|
2610
2590
|
}
|
|
2611
2591
|
|
|
2612
2592
|
// src/clipboard/paste.ts
|
|
2613
|
-
var import_dom13 = require("@testing-library/dom");
|
|
2614
2593
|
async function paste(clipboardData) {
|
|
2615
2594
|
var _a, _b;
|
|
2616
2595
|
const doc = this[Config].document;
|
|
2617
2596
|
const target = (_a = doc.activeElement) != null ? _a : doc.body;
|
|
2618
|
-
const
|
|
2597
|
+
const dataTransfer = (_b = typeof clipboardData === "string" ? getClipboardDataFromString(clipboardData) : clipboardData) != null ? _b : await readDataTransferFromClipboard(doc).catch(() => {
|
|
2619
2598
|
throw new Error("`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.");
|
|
2620
2599
|
});
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
function pasteImpl(target, clipboardData) {
|
|
2624
|
-
var _a;
|
|
2625
|
-
import_dom13.fireEvent.paste(target, {
|
|
2626
|
-
clipboardData
|
|
2600
|
+
this.dispatchUIEvent(target, "paste", {
|
|
2601
|
+
clipboardData: dataTransfer
|
|
2627
2602
|
});
|
|
2628
|
-
if (isEditable(target)) {
|
|
2629
|
-
const data = clipboardData.getData("text").substr(0, getSpaceUntilMaxLength(target));
|
|
2630
|
-
if (data) {
|
|
2631
|
-
(_a = prepareInput(data, target, "insertFromPaste")) == null ? void 0 : _a.commit();
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
2603
|
}
|
|
2635
2604
|
function getClipboardDataFromString(text) {
|
|
2636
2605
|
const dt = createDataTransfer();
|
|
@@ -2640,7 +2609,6 @@ function getClipboardDataFromString(text) {
|
|
|
2640
2609
|
|
|
2641
2610
|
// src/utility/clear.ts
|
|
2642
2611
|
async function clear(element) {
|
|
2643
|
-
var _a;
|
|
2644
2612
|
if (!isEditable(element) || isDisabled(element)) {
|
|
2645
2613
|
throw new Error("clear()` is only supported on editable elements.");
|
|
2646
2614
|
}
|
|
@@ -2652,11 +2620,11 @@ async function clear(element) {
|
|
|
2652
2620
|
if (!isAllSelected(element)) {
|
|
2653
2621
|
throw new Error("The element content to be cleared could not be selected.");
|
|
2654
2622
|
}
|
|
2655
|
-
(
|
|
2623
|
+
input(this[Config], element, "", "deleteContentBackward");
|
|
2656
2624
|
}
|
|
2657
2625
|
|
|
2658
2626
|
// src/utility/selectOptions.ts
|
|
2659
|
-
var
|
|
2627
|
+
var import_dom4 = require("@testing-library/dom");
|
|
2660
2628
|
async function selectOptions(select, values) {
|
|
2661
2629
|
return selectOptionsBase.call(this, true, select, values);
|
|
2662
2630
|
}
|
|
@@ -2665,7 +2633,7 @@ async function deselectOptions(select, values) {
|
|
|
2665
2633
|
}
|
|
2666
2634
|
async function selectOptionsBase(newValue, select, values) {
|
|
2667
2635
|
if (!newValue && !select.multiple) {
|
|
2668
|
-
throw (0,
|
|
2636
|
+
throw (0, import_dom4.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
|
|
2669
2637
|
}
|
|
2670
2638
|
const valArray = Array.isArray(values) ? values : [values];
|
|
2671
2639
|
const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
|
|
@@ -2677,34 +2645,43 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2677
2645
|
if (matchingOption) {
|
|
2678
2646
|
return matchingOption;
|
|
2679
2647
|
} else {
|
|
2680
|
-
throw (0,
|
|
2648
|
+
throw (0, import_dom4.getConfig)().getElementError(`Value "${String(val)}" not found in options`, select);
|
|
2681
2649
|
}
|
|
2682
2650
|
}
|
|
2683
2651
|
}).filter((option) => !isDisabled(option));
|
|
2684
2652
|
if (isDisabled(select) || !selectedOptions.length)
|
|
2685
2653
|
return;
|
|
2654
|
+
const selectOption = (option) => {
|
|
2655
|
+
option.selected = newValue;
|
|
2656
|
+
this.dispatchUIEvent(select, "input", {
|
|
2657
|
+
bubbles: true,
|
|
2658
|
+
cancelable: false,
|
|
2659
|
+
composed: true
|
|
2660
|
+
});
|
|
2661
|
+
this.dispatchUIEvent(select, "change");
|
|
2662
|
+
};
|
|
2686
2663
|
if (isElementType(select, "select")) {
|
|
2687
2664
|
if (select.multiple) {
|
|
2688
2665
|
for (const option of selectedOptions) {
|
|
2689
2666
|
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2690
2667
|
if (withPointerEvents) {
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2668
|
+
this.dispatchUIEvent(option, "pointerover");
|
|
2669
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2670
|
+
this.dispatchUIEvent(option, "mouseover");
|
|
2671
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2672
|
+
this.dispatchUIEvent(option, "pointermove");
|
|
2673
|
+
this.dispatchUIEvent(option, "mousemove");
|
|
2674
|
+
this.dispatchUIEvent(option, "pointerdown");
|
|
2675
|
+
this.dispatchUIEvent(option, "mousedown");
|
|
2699
2676
|
}
|
|
2700
2677
|
focus(select);
|
|
2701
2678
|
if (withPointerEvents) {
|
|
2702
|
-
|
|
2703
|
-
|
|
2679
|
+
this.dispatchUIEvent(option, "pointerup");
|
|
2680
|
+
this.dispatchUIEvent(option, "mouseup");
|
|
2704
2681
|
}
|
|
2705
2682
|
selectOption(option);
|
|
2706
2683
|
if (withPointerEvents) {
|
|
2707
|
-
|
|
2684
|
+
this.dispatchUIEvent(option, "click");
|
|
2708
2685
|
}
|
|
2709
2686
|
}
|
|
2710
2687
|
} else if (selectedOptions.length === 1) {
|
|
@@ -2716,16 +2693,16 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2716
2693
|
}
|
|
2717
2694
|
selectOption(selectedOptions[0]);
|
|
2718
2695
|
if (withPointerEvents) {
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2696
|
+
this.dispatchUIEvent(select, "pointerover");
|
|
2697
|
+
this.dispatchUIEvent(select, "pointerenter");
|
|
2698
|
+
this.dispatchUIEvent(select, "mouseover");
|
|
2699
|
+
this.dispatchUIEvent(select, "mouseenter");
|
|
2700
|
+
this.dispatchUIEvent(select, "pointerup");
|
|
2701
|
+
this.dispatchUIEvent(select, "mouseup");
|
|
2702
|
+
this.dispatchUIEvent(select, "click");
|
|
2726
2703
|
}
|
|
2727
2704
|
} else {
|
|
2728
|
-
throw (0,
|
|
2705
|
+
throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
2729
2706
|
}
|
|
2730
2707
|
} else if (select.getAttribute("role") === "listbox") {
|
|
2731
2708
|
for (const option of selectedOptions) {
|
|
@@ -2733,16 +2710,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2733
2710
|
await this.unhover(option);
|
|
2734
2711
|
}
|
|
2735
2712
|
} else {
|
|
2736
|
-
throw (0,
|
|
2737
|
-
}
|
|
2738
|
-
function selectOption(option) {
|
|
2739
|
-
option.selected = newValue;
|
|
2740
|
-
(0, import_dom14.fireEvent)(select, (0, import_dom14.createEvent)("input", select, {
|
|
2741
|
-
bubbles: true,
|
|
2742
|
-
cancelable: false,
|
|
2743
|
-
composed: true
|
|
2744
|
-
}));
|
|
2745
|
-
import_dom14.fireEvent.change(select);
|
|
2713
|
+
throw (0, import_dom4.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
2746
2714
|
}
|
|
2747
2715
|
}
|
|
2748
2716
|
|
|
@@ -2768,28 +2736,29 @@ async function type(element, text, {
|
|
|
2768
2736
|
}
|
|
2769
2737
|
|
|
2770
2738
|
// src/utility/upload.ts
|
|
2771
|
-
var import_dom15 = require("@testing-library/dom");
|
|
2772
2739
|
async function upload(element, fileOrFiles) {
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
throw new TypeError(`The ${input === element ? "given" : "associated"} ${input == null ? void 0 : input.tagName} element does not accept file uploads`);
|
|
2740
|
+
const input2 = isElementType(element, "label") ? element.control : element;
|
|
2741
|
+
if (!input2 || !isElementType(input2, "input", { type: "file" })) {
|
|
2742
|
+
throw new TypeError(`The ${input2 === element ? "given" : "associated"} ${input2 == null ? void 0 : input2.tagName} element does not accept file uploads`);
|
|
2777
2743
|
}
|
|
2778
2744
|
if (isDisabled(element))
|
|
2779
2745
|
return;
|
|
2746
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).filter((file) => !this[Config].applyAccept || isAcceptableFile(file, input2.accept)).slice(0, input2.multiple ? void 0 : 1);
|
|
2747
|
+
const fileDialog = () => {
|
|
2748
|
+
var _a;
|
|
2749
|
+
if (files.length === ((_a = input2.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2750
|
+
var _a2;
|
|
2751
|
+
return f === ((_a2 = input2.files) == null ? void 0 : _a2.item(i));
|
|
2752
|
+
})) {
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
setFiles(input2, createFileList(files));
|
|
2756
|
+
this.dispatchUIEvent(input2, "input");
|
|
2757
|
+
this.dispatchUIEvent(input2, "change");
|
|
2758
|
+
};
|
|
2759
|
+
input2.addEventListener("fileDialog", fileDialog);
|
|
2780
2760
|
await this.click(element);
|
|
2781
|
-
|
|
2782
|
-
blur(input);
|
|
2783
|
-
focus(input);
|
|
2784
|
-
if (files.length === ((_a = input.files) == null ? void 0 : _a.length) && files.every((f, i) => {
|
|
2785
|
-
var _a2;
|
|
2786
|
-
return f === ((_a2 = input.files) == null ? void 0 : _a2.item(i));
|
|
2787
|
-
})) {
|
|
2788
|
-
return;
|
|
2789
|
-
}
|
|
2790
|
-
setFiles(input, createFileList(files));
|
|
2791
|
-
import_dom15.fireEvent.input(input);
|
|
2792
|
-
import_dom15.fireEvent.change(input);
|
|
2761
|
+
input2.removeEventListener("fileDialog", fileDialog);
|
|
2793
2762
|
}
|
|
2794
2763
|
function isAcceptableFile(file, accept) {
|
|
2795
2764
|
if (!accept) {
|
|
@@ -2807,30 +2776,35 @@ function isAcceptableFile(file, accept) {
|
|
|
2807
2776
|
}
|
|
2808
2777
|
|
|
2809
2778
|
// src/setup/wrapAsync.ts
|
|
2810
|
-
var
|
|
2779
|
+
var import_dom5 = require("@testing-library/dom");
|
|
2811
2780
|
function wrapAsync(implementation) {
|
|
2812
|
-
return (0,
|
|
2781
|
+
return (0, import_dom5.getConfig)().asyncWrapper(implementation);
|
|
2813
2782
|
}
|
|
2814
2783
|
|
|
2815
2784
|
// src/setup/setup.ts
|
|
2785
|
+
function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
|
|
2786
|
+
const document2 = getDocument(options, node);
|
|
2787
|
+
const {
|
|
2788
|
+
keyboardState = createKeyboardState(),
|
|
2789
|
+
pointerState = createPointerState(document2)
|
|
2790
|
+
} = options;
|
|
2791
|
+
return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
|
|
2792
|
+
document: document2,
|
|
2793
|
+
keyboardState,
|
|
2794
|
+
pointerState
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2816
2797
|
function setupMain(options = {}) {
|
|
2817
2798
|
var _a;
|
|
2818
|
-
const
|
|
2819
|
-
prepareDocument(
|
|
2820
|
-
const view = (_a =
|
|
2799
|
+
const config = createConfig(options);
|
|
2800
|
+
prepareDocument(config.document);
|
|
2801
|
+
const view = (_a = config.document.defaultView) != null ? _a : window;
|
|
2821
2802
|
attachClipboardStubToView(view);
|
|
2822
|
-
return doSetup(
|
|
2823
|
-
keyboardState: createKeyboardState(),
|
|
2824
|
-
pointerState: createPointerState(doc)
|
|
2825
|
-
}));
|
|
2803
|
+
return doSetup(config);
|
|
2826
2804
|
}
|
|
2827
2805
|
function setupDirect(options = {}, node) {
|
|
2828
|
-
const
|
|
2829
|
-
prepareDocument(
|
|
2830
|
-
const config = __spreadValues(__spreadValues({
|
|
2831
|
-
keyboardState: createKeyboardState(),
|
|
2832
|
-
pointerState: createPointerState(doc)
|
|
2833
|
-
}, defaultOptionsDirect), options);
|
|
2806
|
+
const config = createConfig(options, defaultOptionsDirect, node);
|
|
2807
|
+
prepareDocument(config.document);
|
|
2834
2808
|
return {
|
|
2835
2809
|
config,
|
|
2836
2810
|
api: doSetup(config)
|
|
@@ -2849,7 +2823,8 @@ function wrapAndBindImpl(instance, impl) {
|
|
|
2849
2823
|
}
|
|
2850
2824
|
function doSetup(config) {
|
|
2851
2825
|
const instance = __spreadValues({
|
|
2852
|
-
[Config]: config
|
|
2826
|
+
[Config]: config,
|
|
2827
|
+
dispatchUIEvent: bindDispatchUIEvent(config)
|
|
2853
2828
|
}, api_exports);
|
|
2854
2829
|
return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
|
|
2855
2830
|
name,
|
|
@@ -2908,9 +2883,9 @@ async function keyboard2(text, options = {}) {
|
|
|
2908
2883
|
const { config, api } = setupDirect(options);
|
|
2909
2884
|
return api.keyboard(text).then(() => config.keyboardState);
|
|
2910
2885
|
}
|
|
2911
|
-
async function pointer2(
|
|
2886
|
+
async function pointer2(input2, options = {}) {
|
|
2912
2887
|
const { config, api } = setupDirect(options);
|
|
2913
|
-
return api.pointer(
|
|
2888
|
+
return api.pointer(input2).then(() => config.pointerState);
|
|
2914
2889
|
}
|
|
2915
2890
|
function paste2(clipboardData, options) {
|
|
2916
2891
|
return setupDirect(options).api.paste(clipboardData);
|
|
@@ -2940,4 +2915,3 @@ function tab2(options = {}) {
|
|
|
2940
2915
|
var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
|
|
2941
2916
|
setup: setupMain
|
|
2942
2917
|
});
|
|
2943
|
-
module.exports = __toCommonJS(src_exports);
|