@uxf/core-react 13.0.3 → 14.1.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/README.md +85 -56
- package/clickable/_use-simulated-button.js +9 -5
- package/clickable/use-button-props.js +108 -47
- package/global-context/index.test.js +23 -2
- package/hooks/use-body-scroll-lock.js +56 -27
- package/hooks/use-composed-refs.test.js +14 -2
- package/hooks/use-debounce.js +21 -6
- package/hooks/use-debounce.test.d.ts +1 -0
- package/hooks/use-debounce.test.js +75 -0
- package/hooks/use-focus-return.js +55 -23
- package/hooks/use-focus-trap.js +87 -53
- package/hooks/use-increment.js +47 -5
- package/hooks/use-input-focus.js +65 -19
- package/hooks/use-is-hydrated.d.ts +10 -0
- package/hooks/use-is-hydrated.js +24 -0
- package/hooks/use-is-hydrated.test.d.ts +1 -0
- package/hooks/use-is-hydrated.test.js +45 -0
- package/hooks/use-is-mounted.d.ts +5 -0
- package/hooks/use-is-mounted.js +20 -1
- package/hooks/use-isomorphic-layout-effect.d.ts +4 -0
- package/hooks/use-isomorphic-layout-effect.js +4 -0
- package/hooks/use-key.js +49 -18
- package/hooks/use-key.test.d.ts +1 -0
- package/hooks/use-key.test.js +145 -0
- package/hooks/use-latest.d.ts +5 -0
- package/hooks/use-latest.js +5 -0
- package/hooks/use-media-query.d.ts +10 -1
- package/hooks/use-media-query.js +77 -19
- package/hooks/use-media-query.test.d.ts +1 -0
- package/hooks/use-media-query.test.js +76 -0
- package/hooks/use-min-window-width.js +39 -18
- package/hooks/use-mouse-drag-to-scroll.js +116 -61
- package/hooks/use-mouse-drag-to-scroll.test.js +56 -10
- package/hooks/use-on-mount.js +20 -3
- package/hooks/use-on-unmount.d.ts +1 -0
- package/hooks/use-on-unmount.js +23 -7
- package/hooks/use-on-unmount.test.d.ts +1 -0
- package/hooks/use-on-unmount.test.js +16 -0
- package/hooks/use-on-update.d.ts +8 -0
- package/hooks/use-on-update.js +32 -8
- package/hooks/use-on-update.test.d.ts +1 -0
- package/hooks/use-on-update.test.js +90 -0
- package/hooks/use-pagination.js +30 -14
- package/hooks/use-previous.d.ts +5 -0
- package/hooks/use-previous.js +19 -3
- package/hooks/use-raf-state.js +35 -8
- package/hooks/use-toggle.js +42 -4
- package/hooks/use-window-scroll.d.ts +7 -2
- package/hooks/use-window-scroll.js +36 -15
- package/hooks/use-window-scroll.test.js +141 -39
- package/hooks/use-window-size.d.ts +7 -2
- package/hooks/use-window-size.js +34 -12
- package/hooks/use-window-size.test.js +147 -29
- package/package.json +10 -4
- package/swipeable/use-swipeable.test.js +31 -5
- package/translations/index.js +1 -1
- package/translations/replace-variables.js +4 -1
- package/translations/replace-variables.test.d.ts +1 -0
- package/translations/replace-variables.test.js +13 -0
- package/components/viewport-height-polyfill.d.ts +0 -2
- package/components/viewport-height-polyfill.js +0 -58
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useMouseDragToScroll = useMouseDragToScroll;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
// Further than this from where the mouse was pressed is a drag, not a click.
|
|
6
7
|
const DRAG_THRESHOLD_PX = 5;
|
|
@@ -12,70 +13,124 @@ const DRAG_THRESHOLD_PX = 5;
|
|
|
12
13
|
* Clicks from the keyboard (Enter, Space) are never swallowed.
|
|
13
14
|
*/
|
|
14
15
|
function useMouseDragToScroll(containerRef) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
(0
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// The document listeners live for one drag, from pressing the mouse to releasing it.
|
|
24
|
-
let dragController;
|
|
25
|
-
let hasDragged = false;
|
|
26
|
-
let isClickSwallowed = false;
|
|
27
|
-
let swallowTimeout;
|
|
28
|
-
const mouseMoveHandler = (e) => {
|
|
29
|
-
const dx = e.clientX - position.current.x;
|
|
30
|
-
const dy = e.clientY - position.current.y;
|
|
31
|
-
if (Math.abs(dx) > DRAG_THRESHOLD_PX || Math.abs(dy) > DRAG_THRESHOLD_PX) {
|
|
32
|
-
hasDragged = true;
|
|
33
|
-
}
|
|
34
|
-
node.scrollLeft = position.current.left - dx;
|
|
35
|
-
node.scrollTop = position.current.top - dy;
|
|
36
|
-
};
|
|
37
|
-
const mouseUpHandler = () => {
|
|
38
|
-
setStyle((prev) => ({ ...prev, cursor: "grab", userSelect: "unset" }));
|
|
39
|
-
dragController === null || dragController === void 0 ? void 0 : dragController.abort();
|
|
40
|
-
if (hasDragged) {
|
|
41
|
-
// Browsers dispatch the click that ends a drag right after `mouseup`, in the same task, so only that
|
|
42
|
-
// click is swallowed. Whatever comes later, a click from the keyboard included, goes through. Telling
|
|
43
|
-
// a keyboard click apart by the event does not work: Firefox gives Enter on a link `detail` 1, Safari
|
|
44
|
-
// gives it the last mouse position as `clientX`.
|
|
45
|
-
isClickSwallowed = true;
|
|
46
|
-
swallowTimeout = setTimeout(() => {
|
|
47
|
-
isClickSwallowed = false;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
16
|
+
const $ = (0, compiler_runtime_1.c)(4);
|
|
17
|
+
let t0;
|
|
18
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
19
|
+
t0 = {
|
|
20
|
+
left: 0,
|
|
21
|
+
top: 0,
|
|
22
|
+
x: 0,
|
|
23
|
+
y: 0
|
|
50
24
|
};
|
|
51
|
-
|
|
52
|
-
|
|
25
|
+
$[0] = t0;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
t0 = $[0];
|
|
29
|
+
}
|
|
30
|
+
const position = (0, react_1.useRef)(t0);
|
|
31
|
+
const [style, setStyle] = (0, react_1.useState)();
|
|
32
|
+
let t1;
|
|
33
|
+
let t2;
|
|
34
|
+
if ($[1] !== containerRef) {
|
|
35
|
+
t1 = () => {
|
|
36
|
+
const node = containerRef.current;
|
|
37
|
+
if (!node) {
|
|
53
38
|
return;
|
|
54
39
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
let dragController;
|
|
42
|
+
let hasDragged = false;
|
|
43
|
+
let isClickSwallowed = false;
|
|
44
|
+
let swallowTimeout;
|
|
45
|
+
const mouseMoveHandler = e => {
|
|
46
|
+
const dx = e.clientX - position.current.x;
|
|
47
|
+
const dy = e.clientY - position.current.y;
|
|
48
|
+
if (Math.abs(dx) > DRAG_THRESHOLD_PX || Math.abs(dy) > DRAG_THRESHOLD_PX) {
|
|
49
|
+
hasDragged = true;
|
|
50
|
+
}
|
|
51
|
+
node.scrollLeft = position.current.left - dx;
|
|
52
|
+
node.scrollTop = position.current.top - dy;
|
|
53
|
+
};
|
|
54
|
+
const mouseUpHandler = () => {
|
|
55
|
+
setStyle(_temp);
|
|
56
|
+
dragController === null || dragController === void 0 ? void 0 : dragController.abort();
|
|
57
|
+
if (hasDragged) {
|
|
58
|
+
isClickSwallowed = true;
|
|
59
|
+
swallowTimeout = setTimeout(() => {
|
|
60
|
+
isClickSwallowed = false;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const mouseDownHandler = e_0 => {
|
|
65
|
+
if (e_0.button !== 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
hasDragged = false;
|
|
69
|
+
position.current = {
|
|
70
|
+
left: node.scrollLeft,
|
|
71
|
+
top: node.scrollTop,
|
|
72
|
+
x: e_0.clientX,
|
|
73
|
+
y: e_0.clientY
|
|
74
|
+
};
|
|
75
|
+
setStyle(_temp2);
|
|
76
|
+
dragController === null || dragController === void 0 ? void 0 : dragController.abort();
|
|
77
|
+
dragController = new AbortController();
|
|
78
|
+
document.addEventListener("mousemove", mouseMoveHandler, {
|
|
79
|
+
signal: dragController.signal
|
|
80
|
+
});
|
|
81
|
+
document.addEventListener("mouseup", mouseUpHandler, {
|
|
82
|
+
signal: dragController.signal
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const clickHandler = e_1 => {
|
|
86
|
+
if (isClickSwallowed) {
|
|
87
|
+
isClickSwallowed = false;
|
|
88
|
+
e_1.preventDefault();
|
|
89
|
+
e_1.stopPropagation();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
node.addEventListener("mousedown", mouseDownHandler, {
|
|
93
|
+
signal: controller.signal
|
|
94
|
+
});
|
|
95
|
+
node.addEventListener("click", clickHandler, {
|
|
96
|
+
capture: true,
|
|
97
|
+
signal: controller.signal
|
|
98
|
+
});
|
|
99
|
+
node.addEventListener("dragstart", _temp3, {
|
|
100
|
+
signal: controller.signal
|
|
101
|
+
});
|
|
102
|
+
return () => {
|
|
103
|
+
controller.abort();
|
|
104
|
+
dragController === null || dragController === void 0 ? void 0 : dragController.abort();
|
|
105
|
+
clearTimeout(swallowTimeout);
|
|
106
|
+
};
|
|
78
107
|
};
|
|
79
|
-
|
|
108
|
+
t2 = [containerRef];
|
|
109
|
+
$[1] = containerRef;
|
|
110
|
+
$[2] = t1;
|
|
111
|
+
$[3] = t2;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
t1 = $[2];
|
|
115
|
+
t2 = $[3];
|
|
116
|
+
}
|
|
117
|
+
(0, react_1.useEffect)(t1, t2);
|
|
80
118
|
return style;
|
|
81
119
|
}
|
|
120
|
+
function _temp3(e_2) {
|
|
121
|
+
return e_2.preventDefault();
|
|
122
|
+
}
|
|
123
|
+
function _temp2(prev_0) {
|
|
124
|
+
return {
|
|
125
|
+
...prev_0,
|
|
126
|
+
cursor: "grabbing",
|
|
127
|
+
userSelect: "none"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function _temp(prev) {
|
|
131
|
+
return {
|
|
132
|
+
...prev,
|
|
133
|
+
cursor: "grab",
|
|
134
|
+
userSelect: "unset"
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -33,24 +33,53 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
36
37
|
const react_1 = require("@testing-library/react");
|
|
37
38
|
const react_2 = __importStar(require("react"));
|
|
38
39
|
const use_mouse_drag_to_scroll_1 = require("./use-mouse-drag-to-scroll");
|
|
39
40
|
function Row(props) {
|
|
41
|
+
const $ = (0, compiler_runtime_1.c)(5);
|
|
40
42
|
const ref = (0, react_2.useRef)(null);
|
|
41
43
|
const style = (0, use_mouse_drag_to_scroll_1.useMouseDragToScroll)(ref);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
let t0;
|
|
45
|
+
if ($[0] !== props.onClick) {
|
|
46
|
+
t0 = react_2.default.createElement("button", { onClick: props.onClick, type: "button" }, "Tab");
|
|
47
|
+
$[0] = props.onClick;
|
|
48
|
+
$[1] = t0;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
t0 = $[1];
|
|
52
|
+
}
|
|
53
|
+
let t1;
|
|
54
|
+
if ($[2] !== style || $[3] !== t0) {
|
|
55
|
+
t1 = react_2.default.createElement("div", { "data-testid": "row", ref: ref, style: style }, t0);
|
|
56
|
+
$[2] = style;
|
|
57
|
+
$[3] = t0;
|
|
58
|
+
$[4] = t1;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
t1 = $[4];
|
|
62
|
+
}
|
|
63
|
+
return t1;
|
|
44
64
|
}
|
|
45
65
|
function setup() {
|
|
46
66
|
const onClick = jest.fn();
|
|
47
67
|
const view = (0, react_1.render)(react_2.default.createElement(Row, { onClick: onClick }));
|
|
48
|
-
return {
|
|
68
|
+
return {
|
|
69
|
+
onClick,
|
|
70
|
+
row: react_1.screen.getByTestId("row"),
|
|
71
|
+
tab: react_1.screen.getByRole("button"),
|
|
72
|
+
view
|
|
73
|
+
};
|
|
49
74
|
}
|
|
50
75
|
// jsdom does not lay anything out, so its `scrollLeft` stays 0 whatever the hook sets.
|
|
51
76
|
function spyOnScrollLeft(element) {
|
|
52
77
|
const setScrollLeft = jest.fn();
|
|
53
|
-
Object.defineProperty(element, "scrollLeft", {
|
|
78
|
+
Object.defineProperty(element, "scrollLeft", {
|
|
79
|
+
configurable: true,
|
|
80
|
+
get: () => 0,
|
|
81
|
+
set: setScrollLeft
|
|
82
|
+
});
|
|
54
83
|
return setScrollLeft;
|
|
55
84
|
}
|
|
56
85
|
/**
|
|
@@ -58,16 +87,29 @@ function spyOnScrollLeft(element) {
|
|
|
58
87
|
* as it does in the browser. Anything a person does later (pressing Enter, clicking again) comes after `later()`.
|
|
59
88
|
*/
|
|
60
89
|
function press(target, x) {
|
|
61
|
-
react_1.fireEvent.mouseDown(target, {
|
|
90
|
+
react_1.fireEvent.mouseDown(target, {
|
|
91
|
+
button: 0,
|
|
92
|
+
clientX: x,
|
|
93
|
+
clientY: 0
|
|
94
|
+
});
|
|
62
95
|
}
|
|
63
96
|
function moveTo(x) {
|
|
64
|
-
react_1.fireEvent.mouseMove(document, {
|
|
97
|
+
react_1.fireEvent.mouseMove(document, {
|
|
98
|
+
clientX: x,
|
|
99
|
+
clientY: 0
|
|
100
|
+
});
|
|
65
101
|
}
|
|
66
102
|
function release(x) {
|
|
67
|
-
react_1.fireEvent.mouseUp(document, {
|
|
103
|
+
react_1.fireEvent.mouseUp(document, {
|
|
104
|
+
clientX: x,
|
|
105
|
+
clientY: 0
|
|
106
|
+
});
|
|
68
107
|
}
|
|
69
108
|
function click(target, x) {
|
|
70
|
-
react_1.fireEvent.click(target, {
|
|
109
|
+
react_1.fireEvent.click(target, {
|
|
110
|
+
clientX: x,
|
|
111
|
+
detail: 1
|
|
112
|
+
});
|
|
71
113
|
}
|
|
72
114
|
function later() {
|
|
73
115
|
jest.runAllTimers();
|
|
@@ -131,7 +173,7 @@ describe("useMouseDragToScroll", () => {
|
|
|
131
173
|
moveTo(40);
|
|
132
174
|
release(40);
|
|
133
175
|
later();
|
|
134
|
-
tab.addEventListener("mousedown",
|
|
176
|
+
tab.addEventListener("mousedown", e => e.stopPropagation());
|
|
135
177
|
press(tab, 40);
|
|
136
178
|
release(40);
|
|
137
179
|
click(tab, 40);
|
|
@@ -139,7 +181,11 @@ describe("useMouseDragToScroll", () => {
|
|
|
139
181
|
});
|
|
140
182
|
it("does not drag with other than the primary button", () => {
|
|
141
183
|
const { row, tab } = setup();
|
|
142
|
-
react_1.fireEvent.mouseDown(tab, {
|
|
184
|
+
react_1.fireEvent.mouseDown(tab, {
|
|
185
|
+
button: 2,
|
|
186
|
+
clientX: 100,
|
|
187
|
+
clientY: 0
|
|
188
|
+
});
|
|
143
189
|
expect(row.style.cursor).toBe("");
|
|
144
190
|
});
|
|
145
191
|
it("turns off the native drag of links and images", () => {
|
package/hooks/use-on-mount.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOnMount = useOnMount;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
function useOnMount(effect) {
|
|
6
|
-
(0,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const $ = (0, compiler_runtime_1.c)(3);
|
|
8
|
+
let t0;
|
|
9
|
+
if ($[0] !== effect) {
|
|
10
|
+
t0 = () => effect();
|
|
11
|
+
$[0] = effect;
|
|
12
|
+
$[1] = t0;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
t0 = $[1];
|
|
16
|
+
}
|
|
17
|
+
let t1;
|
|
18
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
19
|
+
t1 = [];
|
|
20
|
+
$[2] = t1;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
t1 = $[2];
|
|
24
|
+
}
|
|
25
|
+
(0, react_1.useEffect)(t0, t1);
|
|
9
26
|
}
|
package/hooks/use-on-unmount.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOnUnmount = useOnUnmount;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
6
|
+
/** Runs `effect` when the component unmounts, in the version from the latest render. */
|
|
5
7
|
function useOnUnmount(effect) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(0
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const $ = (0, compiler_runtime_1.c)(3);
|
|
9
|
+
const onUnmount = (0, react_1.useEffectEvent)(effect);
|
|
10
|
+
let t0;
|
|
11
|
+
if ($[0] !== onUnmount) {
|
|
12
|
+
t0 = () => () => {
|
|
13
|
+
onUnmount();
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
$[0] = onUnmount;
|
|
16
|
+
$[1] = t0;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
t0 = $[1];
|
|
20
|
+
}
|
|
21
|
+
let t1;
|
|
22
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
23
|
+
t1 = [];
|
|
24
|
+
$[2] = t1;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
t1 = $[2];
|
|
28
|
+
}
|
|
29
|
+
(0, react_1.useEffect)(t0, t1);
|
|
14
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("@testing-library/react");
|
|
4
|
+
const use_on_unmount_1 = require("./use-on-unmount");
|
|
5
|
+
test("runs the effect from the latest render, once, on unmount", () => {
|
|
6
|
+
const first = jest.fn();
|
|
7
|
+
const latest = jest.fn();
|
|
8
|
+
const { rerender, unmount } = (0, react_1.renderHook)((props) => (0, use_on_unmount_1.useOnUnmount)(props.effect), {
|
|
9
|
+
initialProps: { effect: first },
|
|
10
|
+
});
|
|
11
|
+
rerender({ effect: latest });
|
|
12
|
+
expect(latest).not.toHaveBeenCalled();
|
|
13
|
+
unmount();
|
|
14
|
+
expect(first).not.toHaveBeenCalled();
|
|
15
|
+
expect(latest).toHaveBeenCalledTimes(1);
|
|
16
|
+
});
|
package/hooks/use-on-update.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { DependencyList, EffectCallback } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Runs `effect` when `deps` change, not on mount.
|
|
4
|
+
*
|
|
5
|
+
* It compares the deps with those of the previous run instead of skipping "the first run": StrictMode runs a mount
|
|
6
|
+
* effect twice in development, and a first-run flag let the second one through. A consequence: an effect that is
|
|
7
|
+
* reconnected with the same deps (StrictMode, an `<Activity>` hidden and shown again) does not run either, and its
|
|
8
|
+
* cleanup has run. Work that must survive that, like a pending timer, belongs in a plain `useEffect`.
|
|
9
|
+
*/
|
|
2
10
|
export declare function useOnUpdate(effect: EffectCallback, deps: DependencyList): void;
|
package/hooks/use-on-update.js
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOnUpdate = useOnUpdate;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
6
|
+
function haveSameDeps(a, b) {
|
|
7
|
+
return a.length === b.length && a.every((dep, index) => Object.is(dep, b.at(index)));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runs `effect` when `deps` change, not on mount.
|
|
11
|
+
*
|
|
12
|
+
* It compares the deps with those of the previous run instead of skipping "the first run": StrictMode runs a mount
|
|
13
|
+
* effect twice in development, and a first-run flag let the second one through. A consequence: an effect that is
|
|
14
|
+
* reconnected with the same deps (StrictMode, an `<Activity>` hidden and shown again) does not run either, and its
|
|
15
|
+
* cleanup has run. Work that must survive that, like a pending timer, belongs in a plain `useEffect`.
|
|
16
|
+
*/
|
|
5
17
|
function useOnUpdate(effect, deps) {
|
|
6
|
-
const
|
|
7
|
-
(0, react_1.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
const $ = (0, compiler_runtime_1.c)(3);
|
|
19
|
+
const previousDeps = (0, react_1.useRef)(null);
|
|
20
|
+
let t0;
|
|
21
|
+
if ($[0] !== deps || $[1] !== effect) {
|
|
22
|
+
t0 = () => {
|
|
23
|
+
const previous = previousDeps.current;
|
|
24
|
+
previousDeps.current = deps;
|
|
25
|
+
if (previous === null || haveSameDeps(previous, deps)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return effect();
|
|
29
|
+
};
|
|
30
|
+
$[0] = deps;
|
|
31
|
+
$[1] = effect;
|
|
32
|
+
$[2] = t0;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
t0 = $[2];
|
|
36
|
+
}
|
|
37
|
+
(0, react_1.useEffect)(t0, deps);
|
|
14
38
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
37
|
+
const react_1 = require("@testing-library/react");
|
|
38
|
+
const react_2 = __importStar(require("react"));
|
|
39
|
+
const use_on_update_1 = require("./use-on-update");
|
|
40
|
+
function Probe(props) {
|
|
41
|
+
const $ = (0, compiler_runtime_1.c)(4);
|
|
42
|
+
const effect = props.effect;
|
|
43
|
+
const value = props.value;
|
|
44
|
+
let t0;
|
|
45
|
+
let t1;
|
|
46
|
+
if ($[0] !== effect || $[1] !== value) {
|
|
47
|
+
t0 = () => effect(value);
|
|
48
|
+
t1 = [effect, value];
|
|
49
|
+
$[0] = effect;
|
|
50
|
+
$[1] = value;
|
|
51
|
+
$[2] = t0;
|
|
52
|
+
$[3] = t1;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
t0 = $[2];
|
|
56
|
+
t1 = $[3];
|
|
57
|
+
}
|
|
58
|
+
(0, use_on_update_1.useOnUpdate)(t0, t1);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
test("does not run on mount", () => {
|
|
62
|
+
const effect = jest.fn();
|
|
63
|
+
(0, react_1.render)(react_2.default.createElement(Probe, { effect: effect, value: 1 }));
|
|
64
|
+
expect(effect).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
test("does not run on mount under StrictMode either", () => {
|
|
67
|
+
const effect = jest.fn();
|
|
68
|
+
(0, react_1.render)(react_2.default.createElement(react_2.StrictMode, null,
|
|
69
|
+
react_2.default.createElement(Probe, { effect: effect, value: 1 })));
|
|
70
|
+
expect(effect).not.toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
test("runs when a dependency changes, and cleans up before the next run", () => {
|
|
73
|
+
const cleanup = jest.fn();
|
|
74
|
+
const effect = jest.fn(() => cleanup);
|
|
75
|
+
const { rerender } = (0, react_1.render)(react_2.default.createElement(react_2.StrictMode, null,
|
|
76
|
+
react_2.default.createElement(Probe, { effect: effect, value: 1 })));
|
|
77
|
+
rerender(react_2.default.createElement(react_2.StrictMode, null,
|
|
78
|
+
react_2.default.createElement(Probe, { effect: effect, value: 2 })));
|
|
79
|
+
expect(effect).toHaveBeenCalledTimes(1);
|
|
80
|
+
rerender(react_2.default.createElement(react_2.StrictMode, null,
|
|
81
|
+
react_2.default.createElement(Probe, { effect: effect, value: 3 })));
|
|
82
|
+
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(effect).toHaveBeenCalledTimes(2);
|
|
84
|
+
});
|
|
85
|
+
test("does not run on a re-render with the same dependencies", () => {
|
|
86
|
+
const effect = jest.fn();
|
|
87
|
+
const { rerender } = (0, react_1.render)(react_2.default.createElement(Probe, { effect: effect, value: 1 }));
|
|
88
|
+
rerender(react_2.default.createElement(Probe, { effect: effect, value: 1 }));
|
|
89
|
+
expect(effect).not.toHaveBeenCalled();
|
|
90
|
+
});
|
package/hooks/use-pagination.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePagination = void 0;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const pagination_1 = require("@uxf/core/utils/pagination");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
const usePagination = config => {
|
|
7
|
+
const $ = (0, compiler_runtime_1.c)(9);
|
|
8
|
+
const { boundaryCount, siblingCount, count, page, hideNextButton, hidePrevButton, showFirstButton, showLastButton } = config;
|
|
9
|
+
let t0;
|
|
10
|
+
if ($[0] !== boundaryCount || $[1] !== count || $[2] !== hideNextButton || $[3] !== hidePrevButton || $[4] !== page || $[5] !== showFirstButton || $[6] !== showLastButton || $[7] !== siblingCount) {
|
|
11
|
+
t0 = (0, pagination_1.paginationGenerate)({
|
|
12
|
+
boundaryCount,
|
|
13
|
+
siblingCount,
|
|
14
|
+
count,
|
|
15
|
+
page,
|
|
16
|
+
hideNextButton,
|
|
17
|
+
hidePrevButton,
|
|
18
|
+
showFirstButton,
|
|
19
|
+
showLastButton
|
|
20
|
+
});
|
|
21
|
+
$[0] = boundaryCount;
|
|
22
|
+
$[1] = count;
|
|
23
|
+
$[2] = hideNextButton;
|
|
24
|
+
$[3] = hidePrevButton;
|
|
25
|
+
$[4] = page;
|
|
26
|
+
$[5] = showFirstButton;
|
|
27
|
+
$[6] = showLastButton;
|
|
28
|
+
$[7] = siblingCount;
|
|
29
|
+
$[8] = t0;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
t0 = $[8];
|
|
33
|
+
}
|
|
34
|
+
return t0;
|
|
19
35
|
};
|
|
20
36
|
exports.usePagination = usePagination;
|
package/hooks/use-previous.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Returns a ref whose only use is reading `.current` during render, which React 19 asks not to do.
|
|
3
|
+
* To react to a change, keep the previous value in state and compare during render
|
|
4
|
+
* (https://react.dev/reference/react/useState#storing-information-from-previous-renders).
|
|
5
|
+
*/
|
|
1
6
|
export declare function usePrevious<T>(current: T): import("react").RefObject<T>;
|
package/hooks/use-previous.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePrevious = usePrevious;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Returns a ref whose only use is reading `.current` during render, which React 19 asks not to do.
|
|
8
|
+
* To react to a change, keep the previous value in state and compare during render
|
|
9
|
+
* (https://react.dev/reference/react/useState#storing-information-from-previous-renders).
|
|
10
|
+
*/
|
|
5
11
|
function usePrevious(current) {
|
|
12
|
+
const $ = (0, compiler_runtime_1.c)(2);
|
|
6
13
|
const storedValue = (0, react_1.useRef)(current);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
let t0;
|
|
15
|
+
if ($[0] !== current) {
|
|
16
|
+
t0 = () => {
|
|
17
|
+
storedValue.current = current;
|
|
18
|
+
};
|
|
19
|
+
$[0] = current;
|
|
20
|
+
$[1] = t0;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
t0 = $[1];
|
|
24
|
+
}
|
|
25
|
+
(0, react_1.useEffect)(t0);
|
|
10
26
|
return storedValue;
|
|
11
27
|
}
|