@testing-library/user-event 14.2.4 → 14.3.0
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/dist/index.cjs +124 -77
- package/dist/index.mjs +126 -78
- package/dist/types/document/index.d.ts +1 -1
- package/dist/types/document/interceptor.d.ts +1 -1
- package/dist/types/document/selection.d.ts +1 -0
- package/dist/types/document/value.d.ts +5 -6
- package/dist/types/utils/edit/walkRadio.d.ts +4 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +6 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -548,15 +548,8 @@ function calculateNewValue(inputData, node, {
|
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
550
|
function commitInput(config, element, newOffset, inputInit) {
|
|
551
|
-
startTrackValue(element);
|
|
552
551
|
dispatchUIEvent(config, element, "input", inputInit);
|
|
553
|
-
|
|
554
|
-
setSelection({
|
|
555
|
-
focusNode: element,
|
|
556
|
-
anchorOffset: newOffset,
|
|
557
|
-
focusOffset: newOffset
|
|
558
|
-
});
|
|
559
|
-
}
|
|
552
|
+
commitValueAfterInput(element, newOffset);
|
|
560
553
|
}
|
|
561
554
|
function isValidNumberInput(value) {
|
|
562
555
|
var _a, _b;
|
|
@@ -653,6 +646,18 @@ function eventWrapper(cb) {
|
|
|
653
646
|
return result;
|
|
654
647
|
}
|
|
655
648
|
|
|
649
|
+
// src/utils/misc/findClosest.ts
|
|
650
|
+
function findClosest(element, callback) {
|
|
651
|
+
let el = element;
|
|
652
|
+
do {
|
|
653
|
+
if (callback(el)) {
|
|
654
|
+
return el;
|
|
655
|
+
}
|
|
656
|
+
el = el.parentElement;
|
|
657
|
+
} while (el && el !== element.ownerDocument.body);
|
|
658
|
+
return void 0;
|
|
659
|
+
}
|
|
660
|
+
|
|
656
661
|
// src/utils/misc/isDisabled.ts
|
|
657
662
|
function isDisabled(element) {
|
|
658
663
|
var _a;
|
|
@@ -711,16 +716,6 @@ function isFocusable(element) {
|
|
|
711
716
|
return element.matches(FOCUSABLE_SELECTOR);
|
|
712
717
|
}
|
|
713
718
|
|
|
714
|
-
// src/utils/focus/blur.ts
|
|
715
|
-
function blur(element) {
|
|
716
|
-
if (!isFocusable(element))
|
|
717
|
-
return;
|
|
718
|
-
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
719
|
-
if (!wasActive)
|
|
720
|
-
return;
|
|
721
|
-
eventWrapper(() => element.blur());
|
|
722
|
-
}
|
|
723
|
-
|
|
724
719
|
// src/utils/focus/cursor.ts
|
|
725
720
|
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
726
721
|
if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
|
|
@@ -936,6 +931,49 @@ function moveSelection(node, direction) {
|
|
|
936
931
|
}
|
|
937
932
|
}
|
|
938
933
|
|
|
934
|
+
// src/utils/focus/focus.ts
|
|
935
|
+
function focus(element) {
|
|
936
|
+
const target = findClosest(element, isFocusable);
|
|
937
|
+
const activeElement = getActiveElement(element.ownerDocument);
|
|
938
|
+
if ((target != null ? target : element.ownerDocument.body) === activeElement) {
|
|
939
|
+
return;
|
|
940
|
+
} else if (target) {
|
|
941
|
+
eventWrapper(() => target.focus());
|
|
942
|
+
} else {
|
|
943
|
+
eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
|
|
944
|
+
}
|
|
945
|
+
updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/utils/edit/walkRadio.ts
|
|
949
|
+
function walkRadio(config, el, direction) {
|
|
950
|
+
const window = getWindow(el);
|
|
951
|
+
const group = Array.from(el.ownerDocument.querySelectorAll(el.name ? `input[type="radio"][name="${window.CSS.escape(el.name)}"]` : `input[type="radio"][name=""], input[type="radio"]:not([name])`));
|
|
952
|
+
for (let i = group.findIndex((e) => e === el) + direction; ; i += direction) {
|
|
953
|
+
if (!group[i]) {
|
|
954
|
+
i = direction > 0 ? 0 : group.length - 1;
|
|
955
|
+
}
|
|
956
|
+
if (group[i] === el) {
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (isDisabled(group[i])) {
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
focus(group[i]);
|
|
963
|
+
dispatchUIEvent(config, group[i], "click");
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/utils/focus/blur.ts
|
|
968
|
+
function blur(element) {
|
|
969
|
+
if (!isFocusable(element))
|
|
970
|
+
return;
|
|
971
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
972
|
+
if (!wasActive)
|
|
973
|
+
return;
|
|
974
|
+
eventWrapper(() => element.blur());
|
|
975
|
+
}
|
|
976
|
+
|
|
939
977
|
// src/utils/focus/copySelection.ts
|
|
940
978
|
function copySelection(target) {
|
|
941
979
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
@@ -953,32 +991,6 @@ function readSelectedValueFromInput(target) {
|
|
|
953
991
|
return val.substring(sel.startOffset, sel.endOffset);
|
|
954
992
|
}
|
|
955
993
|
|
|
956
|
-
// src/utils/misc/findClosest.ts
|
|
957
|
-
function findClosest(element, callback) {
|
|
958
|
-
let el = element;
|
|
959
|
-
do {
|
|
960
|
-
if (callback(el)) {
|
|
961
|
-
return el;
|
|
962
|
-
}
|
|
963
|
-
el = el.parentElement;
|
|
964
|
-
} while (el && el !== element.ownerDocument.body);
|
|
965
|
-
return void 0;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
// src/utils/focus/focus.ts
|
|
969
|
-
function focus(element) {
|
|
970
|
-
const target = findClosest(element, isFocusable);
|
|
971
|
-
const activeElement = getActiveElement(element.ownerDocument);
|
|
972
|
-
if ((target != null ? target : element.ownerDocument.body) === activeElement) {
|
|
973
|
-
return;
|
|
974
|
-
} else if (target) {
|
|
975
|
-
eventWrapper(() => target.focus());
|
|
976
|
-
} else {
|
|
977
|
-
eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
|
|
978
|
-
}
|
|
979
|
-
updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
|
|
980
|
-
}
|
|
981
|
-
|
|
982
994
|
// src/utils/misc/isVisible.ts
|
|
983
995
|
function isVisible(element) {
|
|
984
996
|
const window = getWindow(element);
|
|
@@ -1327,9 +1339,9 @@ var defaultOptionsSetup = {
|
|
|
1327
1339
|
};
|
|
1328
1340
|
|
|
1329
1341
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1330
|
-
function hasPointerEvents(element) {
|
|
1342
|
+
function hasPointerEvents(config, element) {
|
|
1331
1343
|
var _a;
|
|
1332
|
-
return ((_a =
|
|
1344
|
+
return ((_a = checkPointerEvents(config, element)) == null ? void 0 : _a.pointerEvents) !== "none";
|
|
1333
1345
|
}
|
|
1334
1346
|
function closestPointerEventsDeclaration(element) {
|
|
1335
1347
|
const window = getWindow(element);
|
|
@@ -1343,18 +1355,22 @@ function closestPointerEventsDeclaration(element) {
|
|
|
1343
1355
|
return void 0;
|
|
1344
1356
|
}
|
|
1345
1357
|
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1346
|
-
function
|
|
1358
|
+
function checkPointerEvents(config, element) {
|
|
1347
1359
|
const lastCheck = element[PointerEventsCheck];
|
|
1348
1360
|
const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
|
|
1349
1361
|
if (!needsCheck) {
|
|
1350
|
-
return;
|
|
1362
|
+
return lastCheck == null ? void 0 : lastCheck.result;
|
|
1351
1363
|
}
|
|
1352
1364
|
const declaration = closestPointerEventsDeclaration(element);
|
|
1353
1365
|
element[PointerEventsCheck] = {
|
|
1354
1366
|
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1355
1367
|
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1356
|
-
result:
|
|
1368
|
+
result: declaration
|
|
1357
1369
|
};
|
|
1370
|
+
return declaration;
|
|
1371
|
+
}
|
|
1372
|
+
function assertPointerEvents(config, element) {
|
|
1373
|
+
const declaration = checkPointerEvents(config, element);
|
|
1358
1374
|
if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
|
|
1359
1375
|
throw new Error([
|
|
1360
1376
|
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
@@ -1552,8 +1568,28 @@ behavior.keydown = (event, target, config) => {
|
|
|
1552
1568
|
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1553
1569
|
};
|
|
1554
1570
|
var keydownBehavior = {
|
|
1555
|
-
|
|
1556
|
-
|
|
1571
|
+
ArrowDown: (event, target, config) => {
|
|
1572
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1573
|
+
return () => walkRadio(config, target, -1);
|
|
1574
|
+
}
|
|
1575
|
+
},
|
|
1576
|
+
ArrowLeft: (event, target, config) => {
|
|
1577
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1578
|
+
return () => walkRadio(config, target, -1);
|
|
1579
|
+
}
|
|
1580
|
+
return () => moveSelection(target, -1);
|
|
1581
|
+
},
|
|
1582
|
+
ArrowRight: (event, target, config) => {
|
|
1583
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1584
|
+
return () => walkRadio(config, target, 1);
|
|
1585
|
+
}
|
|
1586
|
+
return () => moveSelection(target, 1);
|
|
1587
|
+
},
|
|
1588
|
+
ArrowUp: (event, target, config) => {
|
|
1589
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1590
|
+
return () => walkRadio(config, target, 1);
|
|
1591
|
+
}
|
|
1592
|
+
},
|
|
1557
1593
|
Backspace: (event, target, config) => {
|
|
1558
1594
|
if (isEditable(target)) {
|
|
1559
1595
|
return () => {
|
|
@@ -1742,7 +1778,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
1742
1778
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1743
1779
|
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1744
1780
|
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1745
|
-
|
|
1781
|
+
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
1746
1782
|
}
|
|
1747
1783
|
function intercept(...args) {
|
|
1748
1784
|
const {
|
|
@@ -1831,6 +1867,9 @@ function getUISelection(element) {
|
|
|
1831
1867
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1832
1868
|
};
|
|
1833
1869
|
}
|
|
1870
|
+
function hasUISelection(element) {
|
|
1871
|
+
return !!element[UISelection];
|
|
1872
|
+
}
|
|
1834
1873
|
function setUISelectionClean(element) {
|
|
1835
1874
|
element[UISelection] = void 0;
|
|
1836
1875
|
}
|
|
@@ -1843,7 +1882,7 @@ function valueInterceptor(v) {
|
|
|
1843
1882
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1844
1883
|
if (isUI) {
|
|
1845
1884
|
this[UIValue] = String(v);
|
|
1846
|
-
|
|
1885
|
+
startTrackValue(this);
|
|
1847
1886
|
}
|
|
1848
1887
|
return {
|
|
1849
1888
|
applyNative: !!isUI,
|
|
@@ -1881,36 +1920,42 @@ function clearInitialValue(element) {
|
|
|
1881
1920
|
function getInitialValue(element) {
|
|
1882
1921
|
return element[InitialValue];
|
|
1883
1922
|
}
|
|
1884
|
-
function
|
|
1885
|
-
element
|
|
1923
|
+
function isReact17Element(element) {
|
|
1924
|
+
return Object.getOwnPropertyNames(element).some((k) => k.startsWith("__react")) && getWindow(element).REACT_VERSION === 17;
|
|
1886
1925
|
}
|
|
1887
1926
|
function startTrackValue(element) {
|
|
1927
|
+
if (!isReact17Element(element)) {
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1888
1930
|
element[TrackChanges] = {
|
|
1889
|
-
|
|
1890
|
-
nextValue: String(element.value),
|
|
1931
|
+
previousValue: String(element.value),
|
|
1891
1932
|
tracked: []
|
|
1892
1933
|
};
|
|
1893
1934
|
}
|
|
1894
1935
|
function trackOrSetValue(element, v) {
|
|
1895
|
-
var _a, _b
|
|
1936
|
+
var _a, _b;
|
|
1896
1937
|
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1897
|
-
if (!
|
|
1898
|
-
|
|
1938
|
+
if (!element[TrackChanges]) {
|
|
1939
|
+
setUIValueClean(element);
|
|
1940
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1899
1941
|
}
|
|
1900
1942
|
}
|
|
1901
|
-
function
|
|
1902
|
-
|
|
1903
|
-
setUISelection(element, { focusOffset: v.length });
|
|
1904
|
-
}
|
|
1905
|
-
function endTrackValue(element) {
|
|
1906
|
-
var _a, _b;
|
|
1943
|
+
function commitValueAfterInput(element, cursorOffset) {
|
|
1944
|
+
var _a;
|
|
1907
1945
|
const changes = element[TrackChanges];
|
|
1908
1946
|
element[TrackChanges] = void 0;
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1947
|
+
if (!((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length)) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
1951
|
+
if (!isJustReactStateUpdate) {
|
|
1952
|
+
setUIValueClean(element);
|
|
1953
|
+
}
|
|
1954
|
+
if (hasUISelection(element)) {
|
|
1955
|
+
setUISelection(element, {
|
|
1956
|
+
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
|
|
1957
|
+
});
|
|
1912
1958
|
}
|
|
1913
|
-
return isJustReactStateUpdate;
|
|
1914
1959
|
}
|
|
1915
1960
|
|
|
1916
1961
|
// src/document/setRangeText.ts
|
|
@@ -1961,7 +2006,7 @@ function prepareElement(el) {
|
|
|
1961
2006
|
if (el[isPrepared]) {
|
|
1962
2007
|
return;
|
|
1963
2008
|
}
|
|
1964
|
-
if ("
|
|
2009
|
+
if (isElementType(el, ["input", "textarea"])) {
|
|
1965
2010
|
prepareValueInterceptor(el);
|
|
1966
2011
|
prepareSelectionInterceptor(el);
|
|
1967
2012
|
prepareRangeTextInterceptor(el);
|
|
@@ -2265,10 +2310,11 @@ async function pointerMove(config, { pointerName = "mouse", target, coords, node
|
|
|
2265
2310
|
} = pointerState.position[pointerName];
|
|
2266
2311
|
if (prevTarget && prevTarget !== target) {
|
|
2267
2312
|
setLevelRef(config, 2 /* Trigger */);
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2313
|
+
if (hasPointerEvents(config, prevTarget)) {
|
|
2314
|
+
fireMove(prevTarget, prevCoords);
|
|
2315
|
+
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
2316
|
+
fireLeave(prevTarget, prevCoords);
|
|
2317
|
+
}
|
|
2272
2318
|
}
|
|
2273
2319
|
}
|
|
2274
2320
|
setLevelRef(config, 2 /* Trigger */);
|
|
@@ -2672,6 +2718,7 @@ async function hover(element) {
|
|
|
2672
2718
|
return this.pointer({ target: element });
|
|
2673
2719
|
}
|
|
2674
2720
|
async function unhover(element) {
|
|
2721
|
+
assertPointerEvents(this[Config], this[Config].pointerState.position.mouse.target);
|
|
2675
2722
|
return this.pointer({ target: element.ownerDocument.body });
|
|
2676
2723
|
}
|
|
2677
2724
|
|
|
@@ -2790,7 +2837,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2790
2837
|
if (isElementType(select, "select")) {
|
|
2791
2838
|
if (select.multiple) {
|
|
2792
2839
|
for (const option of selectedOptions) {
|
|
2793
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2840
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option);
|
|
2794
2841
|
if (withPointerEvents) {
|
|
2795
2842
|
this.dispatchUIEvent(option, "pointerover");
|
|
2796
2843
|
this.dispatchUIEvent(select, "pointerenter");
|
|
@@ -2813,7 +2860,7 @@ async function selectOptionsBase(newValue, select, values) {
|
|
|
2813
2860
|
await wait(this[Config]);
|
|
2814
2861
|
}
|
|
2815
2862
|
} else if (selectedOptions.length === 1) {
|
|
2816
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2863
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select);
|
|
2817
2864
|
if (withPointerEvents) {
|
|
2818
2865
|
await this.click(select);
|
|
2819
2866
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -579,15 +579,8 @@ function calculateNewValue(inputData, node, {
|
|
|
579
579
|
};
|
|
580
580
|
}
|
|
581
581
|
function commitInput(config, element, newOffset, inputInit) {
|
|
582
|
-
startTrackValue(element);
|
|
583
582
|
dispatchUIEvent(config, element, "input", inputInit);
|
|
584
|
-
|
|
585
|
-
setSelection({
|
|
586
|
-
focusNode: element,
|
|
587
|
-
anchorOffset: newOffset,
|
|
588
|
-
focusOffset: newOffset
|
|
589
|
-
});
|
|
590
|
-
}
|
|
583
|
+
commitValueAfterInput(element, newOffset);
|
|
591
584
|
}
|
|
592
585
|
function isValidNumberInput(value) {
|
|
593
586
|
var _a, _b;
|
|
@@ -669,6 +662,18 @@ function eventWrapper(cb) {
|
|
|
669
662
|
return result;
|
|
670
663
|
}
|
|
671
664
|
|
|
665
|
+
// src/utils/misc/findClosest.ts
|
|
666
|
+
function findClosest(element, callback) {
|
|
667
|
+
let el = element;
|
|
668
|
+
do {
|
|
669
|
+
if (callback(el)) {
|
|
670
|
+
return el;
|
|
671
|
+
}
|
|
672
|
+
el = el.parentElement;
|
|
673
|
+
} while (el && el !== element.ownerDocument.body);
|
|
674
|
+
return void 0;
|
|
675
|
+
}
|
|
676
|
+
|
|
672
677
|
// src/utils/misc/isDisabled.ts
|
|
673
678
|
function isDisabled(element) {
|
|
674
679
|
var _a;
|
|
@@ -727,16 +732,6 @@ function isFocusable(element) {
|
|
|
727
732
|
return element.matches(FOCUSABLE_SELECTOR);
|
|
728
733
|
}
|
|
729
734
|
|
|
730
|
-
// src/utils/focus/blur.ts
|
|
731
|
-
function blur(element) {
|
|
732
|
-
if (!isFocusable(element))
|
|
733
|
-
return;
|
|
734
|
-
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
735
|
-
if (!wasActive)
|
|
736
|
-
return;
|
|
737
|
-
eventWrapper(() => element.blur());
|
|
738
|
-
}
|
|
739
|
-
|
|
740
735
|
// src/utils/focus/cursor.ts
|
|
741
736
|
function getNextCursorPosition(node, offset, direction, inputType) {
|
|
742
737
|
if (isTextNode(node) && offset + direction >= 0 && offset + direction <= node.nodeValue.length) {
|
|
@@ -952,6 +947,49 @@ function moveSelection(node, direction) {
|
|
|
952
947
|
}
|
|
953
948
|
}
|
|
954
949
|
|
|
950
|
+
// src/utils/focus/focus.ts
|
|
951
|
+
function focus(element) {
|
|
952
|
+
const target = findClosest(element, isFocusable);
|
|
953
|
+
const activeElement = getActiveElement(element.ownerDocument);
|
|
954
|
+
if ((target != null ? target : element.ownerDocument.body) === activeElement) {
|
|
955
|
+
return;
|
|
956
|
+
} else if (target) {
|
|
957
|
+
eventWrapper(() => target.focus());
|
|
958
|
+
} else {
|
|
959
|
+
eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
|
|
960
|
+
}
|
|
961
|
+
updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// src/utils/edit/walkRadio.ts
|
|
965
|
+
function walkRadio(config, el, direction) {
|
|
966
|
+
const window = getWindow(el);
|
|
967
|
+
const group = Array.from(el.ownerDocument.querySelectorAll(el.name ? `input[type="radio"][name="${window.CSS.escape(el.name)}"]` : `input[type="radio"][name=""], input[type="radio"]:not([name])`));
|
|
968
|
+
for (let i = group.findIndex((e) => e === el) + direction; ; i += direction) {
|
|
969
|
+
if (!group[i]) {
|
|
970
|
+
i = direction > 0 ? 0 : group.length - 1;
|
|
971
|
+
}
|
|
972
|
+
if (group[i] === el) {
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
if (isDisabled(group[i])) {
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
focus(group[i]);
|
|
979
|
+
dispatchUIEvent(config, group[i], "click");
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// src/utils/focus/blur.ts
|
|
984
|
+
function blur(element) {
|
|
985
|
+
if (!isFocusable(element))
|
|
986
|
+
return;
|
|
987
|
+
const wasActive = getActiveElement(element.ownerDocument) === element;
|
|
988
|
+
if (!wasActive)
|
|
989
|
+
return;
|
|
990
|
+
eventWrapper(() => element.blur());
|
|
991
|
+
}
|
|
992
|
+
|
|
955
993
|
// src/utils/focus/copySelection.ts
|
|
956
994
|
function copySelection(target) {
|
|
957
995
|
const data = hasOwnSelection(target) ? { "text/plain": readSelectedValueFromInput(target) } : { "text/plain": String(target.ownerDocument.getSelection()) };
|
|
@@ -969,32 +1007,6 @@ function readSelectedValueFromInput(target) {
|
|
|
969
1007
|
return val.substring(sel.startOffset, sel.endOffset);
|
|
970
1008
|
}
|
|
971
1009
|
|
|
972
|
-
// src/utils/misc/findClosest.ts
|
|
973
|
-
function findClosest(element, callback) {
|
|
974
|
-
let el = element;
|
|
975
|
-
do {
|
|
976
|
-
if (callback(el)) {
|
|
977
|
-
return el;
|
|
978
|
-
}
|
|
979
|
-
el = el.parentElement;
|
|
980
|
-
} while (el && el !== element.ownerDocument.body);
|
|
981
|
-
return void 0;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
// src/utils/focus/focus.ts
|
|
985
|
-
function focus(element) {
|
|
986
|
-
const target = findClosest(element, isFocusable);
|
|
987
|
-
const activeElement = getActiveElement(element.ownerDocument);
|
|
988
|
-
if ((target != null ? target : element.ownerDocument.body) === activeElement) {
|
|
989
|
-
return;
|
|
990
|
-
} else if (target) {
|
|
991
|
-
eventWrapper(() => target.focus());
|
|
992
|
-
} else {
|
|
993
|
-
eventWrapper(() => activeElement == null ? void 0 : activeElement.blur());
|
|
994
|
-
}
|
|
995
|
-
updateSelectionOnFocus(target != null ? target : element.ownerDocument.body);
|
|
996
|
-
}
|
|
997
|
-
|
|
998
1010
|
// src/utils/misc/isVisible.ts
|
|
999
1011
|
function isVisible(element) {
|
|
1000
1012
|
const window = getWindow(element);
|
|
@@ -1341,9 +1353,9 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
|
|
|
1341
1353
|
});
|
|
1342
1354
|
|
|
1343
1355
|
// src/utils/pointer/cssPointerEvents.ts
|
|
1344
|
-
function hasPointerEvents(element) {
|
|
1356
|
+
function hasPointerEvents(config, element) {
|
|
1345
1357
|
var _a;
|
|
1346
|
-
return ((_a =
|
|
1358
|
+
return ((_a = checkPointerEvents(config, element)) == null ? void 0 : _a.pointerEvents) !== "none";
|
|
1347
1359
|
}
|
|
1348
1360
|
function closestPointerEventsDeclaration(element) {
|
|
1349
1361
|
const window = getWindow(element);
|
|
@@ -1357,18 +1369,22 @@ function closestPointerEventsDeclaration(element) {
|
|
|
1357
1369
|
return void 0;
|
|
1358
1370
|
}
|
|
1359
1371
|
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1360
|
-
function
|
|
1372
|
+
function checkPointerEvents(config, element) {
|
|
1361
1373
|
const lastCheck = element[PointerEventsCheck];
|
|
1362
1374
|
const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
|
|
1363
1375
|
if (!needsCheck) {
|
|
1364
|
-
return;
|
|
1376
|
+
return lastCheck == null ? void 0 : lastCheck.result;
|
|
1365
1377
|
}
|
|
1366
1378
|
const declaration = closestPointerEventsDeclaration(element);
|
|
1367
1379
|
element[PointerEventsCheck] = {
|
|
1368
1380
|
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1369
1381
|
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1370
|
-
result:
|
|
1382
|
+
result: declaration
|
|
1371
1383
|
};
|
|
1384
|
+
return declaration;
|
|
1385
|
+
}
|
|
1386
|
+
function assertPointerEvents(config, element) {
|
|
1387
|
+
const declaration = checkPointerEvents(config, element);
|
|
1372
1388
|
if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
|
|
1373
1389
|
throw new Error([
|
|
1374
1390
|
`Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
|
|
@@ -1565,8 +1581,28 @@ behavior.keydown = (event, target, config) => {
|
|
|
1565
1581
|
return (_b = (_a = keydownBehavior[event.key]) == null ? void 0 : _a.call(keydownBehavior, event, target, config)) != null ? _b : combinationBehavior(event, target, config);
|
|
1566
1582
|
};
|
|
1567
1583
|
var keydownBehavior = {
|
|
1568
|
-
|
|
1569
|
-
|
|
1584
|
+
ArrowDown: (event, target, config) => {
|
|
1585
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1586
|
+
return () => walkRadio(config, target, -1);
|
|
1587
|
+
}
|
|
1588
|
+
},
|
|
1589
|
+
ArrowLeft: (event, target, config) => {
|
|
1590
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1591
|
+
return () => walkRadio(config, target, -1);
|
|
1592
|
+
}
|
|
1593
|
+
return () => moveSelection(target, -1);
|
|
1594
|
+
},
|
|
1595
|
+
ArrowRight: (event, target, config) => {
|
|
1596
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1597
|
+
return () => walkRadio(config, target, 1);
|
|
1598
|
+
}
|
|
1599
|
+
return () => moveSelection(target, 1);
|
|
1600
|
+
},
|
|
1601
|
+
ArrowUp: (event, target, config) => {
|
|
1602
|
+
if (isElementType(target, "input", { type: "radio" })) {
|
|
1603
|
+
return () => walkRadio(config, target, 1);
|
|
1604
|
+
}
|
|
1605
|
+
},
|
|
1570
1606
|
Backspace: (event, target, config) => {
|
|
1571
1607
|
if (isEditable(target)) {
|
|
1572
1608
|
return () => {
|
|
@@ -1752,7 +1788,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
|
|
|
1752
1788
|
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
1753
1789
|
const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
|
|
1754
1790
|
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
|
|
1755
|
-
|
|
1791
|
+
throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
|
|
1756
1792
|
}
|
|
1757
1793
|
function intercept(...args) {
|
|
1758
1794
|
const {
|
|
@@ -1839,6 +1875,9 @@ function getUISelection(element) {
|
|
|
1839
1875
|
endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
|
|
1840
1876
|
});
|
|
1841
1877
|
}
|
|
1878
|
+
function hasUISelection(element) {
|
|
1879
|
+
return !!element[UISelection];
|
|
1880
|
+
}
|
|
1842
1881
|
function setUISelectionClean(element) {
|
|
1843
1882
|
element[UISelection] = void 0;
|
|
1844
1883
|
}
|
|
@@ -1851,7 +1890,7 @@ function valueInterceptor(v) {
|
|
|
1851
1890
|
const isUI = typeof v === "object" && v[UIValue];
|
|
1852
1891
|
if (isUI) {
|
|
1853
1892
|
this[UIValue] = String(v);
|
|
1854
|
-
|
|
1893
|
+
startTrackValue(this);
|
|
1855
1894
|
}
|
|
1856
1895
|
return {
|
|
1857
1896
|
applyNative: !!isUI,
|
|
@@ -1889,35 +1928,42 @@ function clearInitialValue(element) {
|
|
|
1889
1928
|
function getInitialValue(element) {
|
|
1890
1929
|
return element[InitialValue];
|
|
1891
1930
|
}
|
|
1892
|
-
function
|
|
1893
|
-
element
|
|
1931
|
+
function isReact17Element(element) {
|
|
1932
|
+
return Object.getOwnPropertyNames(element).some((k) => k.startsWith("__react")) && getWindow(element).REACT_VERSION === 17;
|
|
1894
1933
|
}
|
|
1895
1934
|
function startTrackValue(element) {
|
|
1896
|
-
|
|
1897
|
-
|
|
1935
|
+
if (!isReact17Element(element)) {
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
element[TrackChanges] = {
|
|
1939
|
+
previousValue: String(element.value),
|
|
1898
1940
|
tracked: []
|
|
1899
|
-
}
|
|
1941
|
+
};
|
|
1900
1942
|
}
|
|
1901
1943
|
function trackOrSetValue(element, v) {
|
|
1902
|
-
var _a, _b
|
|
1944
|
+
var _a, _b;
|
|
1903
1945
|
(_b = (_a = element[TrackChanges]) == null ? void 0 : _a.tracked) == null ? void 0 : _b.push(v);
|
|
1904
|
-
if (!
|
|
1905
|
-
|
|
1946
|
+
if (!element[TrackChanges]) {
|
|
1947
|
+
setUIValueClean(element);
|
|
1948
|
+
setUISelection(element, { focusOffset: v.length });
|
|
1906
1949
|
}
|
|
1907
1950
|
}
|
|
1908
|
-
function
|
|
1909
|
-
|
|
1910
|
-
setUISelection(element, { focusOffset: v.length });
|
|
1911
|
-
}
|
|
1912
|
-
function endTrackValue(element) {
|
|
1913
|
-
var _a, _b;
|
|
1951
|
+
function commitValueAfterInput(element, cursorOffset) {
|
|
1952
|
+
var _a;
|
|
1914
1953
|
const changes = element[TrackChanges];
|
|
1915
1954
|
element[TrackChanges] = void 0;
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1955
|
+
if (!((_a = changes == null ? void 0 : changes.tracked) == null ? void 0 : _a.length)) {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
|
|
1959
|
+
if (!isJustReactStateUpdate) {
|
|
1960
|
+
setUIValueClean(element);
|
|
1961
|
+
}
|
|
1962
|
+
if (hasUISelection(element)) {
|
|
1963
|
+
setUISelection(element, {
|
|
1964
|
+
focusOffset: isJustReactStateUpdate ? cursorOffset : element.value.length
|
|
1965
|
+
});
|
|
1919
1966
|
}
|
|
1920
|
-
return isJustReactStateUpdate;
|
|
1921
1967
|
}
|
|
1922
1968
|
|
|
1923
1969
|
// src/document/setRangeText.ts
|
|
@@ -1968,7 +2014,7 @@ function prepareElement(el) {
|
|
|
1968
2014
|
if (el[isPrepared]) {
|
|
1969
2015
|
return;
|
|
1970
2016
|
}
|
|
1971
|
-
if ("
|
|
2017
|
+
if (isElementType(el, ["input", "textarea"])) {
|
|
1972
2018
|
prepareValueInterceptor(el);
|
|
1973
2019
|
prepareSelectionInterceptor(el);
|
|
1974
2020
|
prepareRangeTextInterceptor(el);
|
|
@@ -2284,10 +2330,11 @@ function pointerMove(_0, _1) {
|
|
|
2284
2330
|
} = pointerState.position[pointerName];
|
|
2285
2331
|
if (prevTarget && prevTarget !== target) {
|
|
2286
2332
|
setLevelRef(config, 2 /* Trigger */);
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2333
|
+
if (hasPointerEvents(config, prevTarget)) {
|
|
2334
|
+
fireMove(prevTarget, prevCoords);
|
|
2335
|
+
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
2336
|
+
fireLeave(prevTarget, prevCoords);
|
|
2337
|
+
}
|
|
2291
2338
|
}
|
|
2292
2339
|
}
|
|
2293
2340
|
setLevelRef(config, 2 /* Trigger */);
|
|
@@ -2701,6 +2748,7 @@ function hover(element) {
|
|
|
2701
2748
|
}
|
|
2702
2749
|
function unhover(element) {
|
|
2703
2750
|
return __async(this, null, function* () {
|
|
2751
|
+
assertPointerEvents(this[Config], this[Config].pointerState.position.mouse.target);
|
|
2704
2752
|
return this.pointer({ target: element.ownerDocument.body });
|
|
2705
2753
|
});
|
|
2706
2754
|
}
|
|
@@ -2835,7 +2883,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2835
2883
|
if (isElementType(select, "select")) {
|
|
2836
2884
|
if (select.multiple) {
|
|
2837
2885
|
for (const option of selectedOptions) {
|
|
2838
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2886
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], option);
|
|
2839
2887
|
if (withPointerEvents) {
|
|
2840
2888
|
this.dispatchUIEvent(option, "pointerover");
|
|
2841
2889
|
this.dispatchUIEvent(select, "pointerenter");
|
|
@@ -2858,7 +2906,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2858
2906
|
yield wait(this[Config]);
|
|
2859
2907
|
}
|
|
2860
2908
|
} else if (selectedOptions.length === 1) {
|
|
2861
|
-
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2909
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(this[Config], select);
|
|
2862
2910
|
if (withPointerEvents) {
|
|
2863
2911
|
yield this.click(select);
|
|
2864
2912
|
} else {
|
|
@@ -5,6 +5,6 @@ declare global {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare function prepareDocument(document: Document): void;
|
|
8
|
-
export { getUIValue, setUIValue,
|
|
8
|
+
export { getUIValue, setUIValue, commitValueAfterInput, clearInitialValue, } from './value';
|
|
9
9
|
export { getUISelection, setUISelection } from './selection';
|
|
10
10
|
export type { UISelectionRange } from './selection';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare type anyFunc = (...a: any[]) => any;
|
|
2
2
|
declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
|
|
3
3
|
declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
|
|
4
|
-
export declare function prepareInterceptor<ElementType extends
|
|
4
|
+
export declare function prepareInterceptor<ElementType extends Element, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
|
|
5
5
|
/**
|
|
6
6
|
* React tracks the changes on element properties.
|
|
7
7
|
* This workaround tries to alter the DOM element without React noticing,
|
|
@@ -23,6 +23,7 @@ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaE
|
|
|
23
23
|
anchorOffset: number;
|
|
24
24
|
focusOffset: number;
|
|
25
25
|
};
|
|
26
|
+
export declare function hasUISelection(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
26
27
|
/** Flag the IDL selection as clean. This does not change the selection. */
|
|
27
28
|
export declare function setUISelectionClean(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
28
29
|
export {};
|
|
@@ -2,6 +2,9 @@ declare const UIValue: unique symbol;
|
|
|
2
2
|
declare const InitialValue: unique symbol;
|
|
3
3
|
declare const TrackChanges: unique symbol;
|
|
4
4
|
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
REACT_VERSION?: number;
|
|
7
|
+
}
|
|
5
8
|
interface Element {
|
|
6
9
|
[UIValue]?: string;
|
|
7
10
|
[InitialValue]?: string;
|
|
@@ -12,16 +15,12 @@ declare global {
|
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
|
-
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
18
|
+
export declare function prepareValueInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
16
19
|
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
17
20
|
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
|
|
18
21
|
/** Flag the IDL value as clean. This does not change the value.*/
|
|
19
22
|
export declare function setUIValueClean(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
20
23
|
export declare function clearInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
21
24
|
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
22
|
-
export declare function
|
|
23
|
-
/**
|
|
24
|
-
* @returns `true` if we recognize a React state reset and update
|
|
25
|
-
*/
|
|
26
|
-
export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): boolean;
|
|
25
|
+
export declare function commitValueAfterInput(element: HTMLInputElement | HTMLTextAreaElement, cursorOffset: number): void;
|
|
27
26
|
export {};
|
|
@@ -8,6 +8,7 @@ export * from './edit/input';
|
|
|
8
8
|
export * from './edit/isContentEditable';
|
|
9
9
|
export * from './edit/isEditable';
|
|
10
10
|
export * from './edit/setFiles';
|
|
11
|
+
export * from './edit/walkRadio';
|
|
11
12
|
export * from './focus/blur';
|
|
12
13
|
export * from './focus/copySelection';
|
|
13
14
|
export * from './focus/cursor';
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Config } from '../../setup';
|
|
2
2
|
import { ApiLevel } from '..';
|
|
3
|
-
export declare function hasPointerEvents(element: Element): boolean;
|
|
3
|
+
export declare function hasPointerEvents(config: Config, element: Element): boolean;
|
|
4
|
+
declare function closestPointerEventsDeclaration(element: Element): {
|
|
5
|
+
pointerEvents: string;
|
|
6
|
+
tree: Element[];
|
|
7
|
+
} | undefined;
|
|
4
8
|
declare const PointerEventsCheck: unique symbol;
|
|
5
9
|
declare global {
|
|
6
10
|
interface Element {
|
|
7
11
|
[PointerEventsCheck]?: {
|
|
8
12
|
[k in ApiLevel]?: object;
|
|
9
13
|
} & {
|
|
10
|
-
result:
|
|
14
|
+
result: ReturnType<typeof closestPointerEventsDeclaration>;
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
17
|
}
|