@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
|
@@ -0,0 +1,75 @@
|
|
|
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_debounce_1 = require("./use-debounce");
|
|
40
|
+
function Probe(props) {
|
|
41
|
+
const $ = (0, compiler_runtime_1.c)(2);
|
|
42
|
+
const debounced = (0, use_debounce_1.useDebounce)(props.value, 100);
|
|
43
|
+
let t0;
|
|
44
|
+
if ($[0] !== debounced) {
|
|
45
|
+
t0 = react_2.default.createElement("span", { "data-testid": "debounced" }, debounced);
|
|
46
|
+
$[0] = debounced;
|
|
47
|
+
$[1] = t0;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
t0 = $[1];
|
|
51
|
+
}
|
|
52
|
+
return t0;
|
|
53
|
+
}
|
|
54
|
+
function Host(props) {
|
|
55
|
+
"use no memo";
|
|
56
|
+
return react_2.default.createElement(react_2.Activity, { mode: props.isVisible ? "visible" : "hidden" },
|
|
57
|
+
react_2.default.createElement(Probe, { value: props.value }));
|
|
58
|
+
}
|
|
59
|
+
beforeEach(() => jest.useFakeTimers());
|
|
60
|
+
afterEach(() => jest.useRealTimers());
|
|
61
|
+
test("delivers the value after the delay", () => {
|
|
62
|
+
const { getByTestId, rerender } = (0, react_1.render)(react_2.default.createElement(Host, { isVisible: true, value: "a" }));
|
|
63
|
+
rerender(react_2.default.createElement(Host, { isVisible: true, value: "b" }));
|
|
64
|
+
expect(getByTestId("debounced").textContent).toBe("a");
|
|
65
|
+
(0, react_1.act)(() => jest.advanceTimersByTime(100));
|
|
66
|
+
expect(getByTestId("debounced").textContent).toBe("b");
|
|
67
|
+
});
|
|
68
|
+
test("delivers a value still pending when an Activity hid it, once it is shown again", () => {
|
|
69
|
+
const { getByTestId, rerender } = (0, react_1.render)(react_2.default.createElement(Host, { isVisible: true, value: "a" }));
|
|
70
|
+
rerender(react_2.default.createElement(Host, { isVisible: true, value: "b" }));
|
|
71
|
+
rerender(react_2.default.createElement(Host, { isVisible: false, value: "b" }));
|
|
72
|
+
rerender(react_2.default.createElement(Host, { isVisible: true, value: "b" }));
|
|
73
|
+
(0, react_1.act)(() => jest.advanceTimersByTime(100));
|
|
74
|
+
expect(getByTestId("debounced").textContent).toBe("b");
|
|
75
|
+
});
|
|
@@ -1,34 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useFocusReturn = useFocusReturn;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const use_on_update_1 = require("./use-on-update");
|
|
6
|
-
function useFocusReturn(opened,
|
|
7
|
+
function useFocusReturn(opened, t0, t1) {
|
|
8
|
+
const $ = (0, compiler_runtime_1.c)(6);
|
|
9
|
+
const transitionDuration = t0 === undefined ? 0 : t0;
|
|
10
|
+
const shouldReturnFocus = t1 === undefined ? true : t1;
|
|
7
11
|
const lastActiveElement = (0, react_1.useRef)(undefined);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
node.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(0, use_on_update_1.useOnUpdate)(() => {
|
|
15
|
-
let timeout = -1;
|
|
16
|
-
const clearFocusTimeout = (e) => {
|
|
17
|
-
if (e.key === "Tab") {
|
|
18
|
-
clearTimeout(timeout);
|
|
12
|
+
let t2;
|
|
13
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
14
|
+
t2 = () => {
|
|
15
|
+
const node = lastActiveElement.current;
|
|
16
|
+
if (node && "focus" in node && typeof node.focus === "function") {
|
|
17
|
+
node.focus();
|
|
19
18
|
}
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
$[0] = t2;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
t2 = $[0];
|
|
24
|
+
}
|
|
25
|
+
const returnFocus = t2;
|
|
26
|
+
let t3;
|
|
27
|
+
let t4;
|
|
28
|
+
if ($[1] !== opened || $[2] !== shouldReturnFocus || $[3] !== transitionDuration) {
|
|
29
|
+
t3 = () => {
|
|
30
|
+
let timeout = -1;
|
|
31
|
+
const clearFocusTimeout = e => {
|
|
32
|
+
if (e.key === "Tab") {
|
|
33
|
+
clearTimeout(timeout);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const controller = new AbortController();
|
|
37
|
+
document.addEventListener("keydown", clearFocusTimeout, {
|
|
38
|
+
signal: controller.signal
|
|
39
|
+
});
|
|
40
|
+
if (opened) {
|
|
41
|
+
lastActiveElement.current = document.activeElement;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (shouldReturnFocus) {
|
|
45
|
+
timeout = window.setTimeout(returnFocus, transitionDuration + 10);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return () => {
|
|
49
|
+
clearTimeout(timeout);
|
|
50
|
+
controller.abort();
|
|
51
|
+
};
|
|
31
52
|
};
|
|
32
|
-
|
|
53
|
+
t4 = [opened, shouldReturnFocus, transitionDuration];
|
|
54
|
+
$[1] = opened;
|
|
55
|
+
$[2] = shouldReturnFocus;
|
|
56
|
+
$[3] = transitionDuration;
|
|
57
|
+
$[4] = t3;
|
|
58
|
+
$[5] = t4;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
t3 = $[4];
|
|
62
|
+
t4 = $[5];
|
|
63
|
+
}
|
|
64
|
+
(0, use_on_update_1.useOnUpdate)(t3, t4);
|
|
33
65
|
return returnFocus;
|
|
34
66
|
}
|
package/hooks/use-focus-trap.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useFocusTrap = useFocusTrap;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const use_on_unmount_1 = require("./use-on-unmount");
|
|
6
7
|
const TABBABLE_NODES = /input|select|textarea|button|object/;
|
|
@@ -31,8 +32,7 @@ function getElementTabIndex(element) {
|
|
|
31
32
|
function focusable(element) {
|
|
32
33
|
const nodeName = element.nodeName.toLowerCase();
|
|
33
34
|
const isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
|
|
34
|
-
const res =
|
|
35
|
-
(element instanceof HTMLAnchorElement ? Boolean(element.href) || isTabIndexNotNaN : isTabIndexNotNaN);
|
|
35
|
+
const res = TABBABLE_NODES.test(nodeName) && !element.disabled || (element instanceof HTMLAnchorElement ? Boolean(element.href) || isTabIndexNotNaN : isTabIndexNotNaN);
|
|
36
36
|
return res && visible(element);
|
|
37
37
|
}
|
|
38
38
|
function tabbable(element) {
|
|
@@ -61,7 +61,7 @@ function scopeTab(node, event) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
function createAriaHider(containerNode, selector = "body > :not(script)") {
|
|
64
|
-
const rootNodes = Array.from(document.querySelectorAll(selector)).map(
|
|
64
|
+
const rootNodes = Array.from(document.querySelectorAll(selector)).map(node => {
|
|
65
65
|
if (node.contains(containerNode)) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
@@ -69,10 +69,13 @@ function createAriaHider(containerNode, selector = "body > :not(script)") {
|
|
|
69
69
|
if (ariaHidden === null || ariaHidden === "false") {
|
|
70
70
|
node.setAttribute("aria-hidden", "true");
|
|
71
71
|
}
|
|
72
|
-
return {
|
|
72
|
+
return {
|
|
73
|
+
node,
|
|
74
|
+
ariaHidden
|
|
75
|
+
};
|
|
73
76
|
});
|
|
74
77
|
return () => {
|
|
75
|
-
rootNodes.forEach(
|
|
78
|
+
rootNodes.forEach(item => {
|
|
76
79
|
if (!item) {
|
|
77
80
|
return;
|
|
78
81
|
}
|
|
@@ -85,61 +88,92 @@ function createAriaHider(containerNode, selector = "body > :not(script)") {
|
|
|
85
88
|
});
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
function useFocusTrap(
|
|
91
|
+
function useFocusTrap(t0) {
|
|
92
|
+
const $ = (0, compiler_runtime_1.c)(6);
|
|
93
|
+
const active = t0 === undefined ? true : t0;
|
|
89
94
|
const ref = (0, react_1.useRef)(null);
|
|
90
95
|
const restoreAria = (0, react_1.useRef)(undefined);
|
|
91
96
|
const timer = (0, react_1.useRef)(undefined);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
focusElement =
|
|
97
|
+
let t1;
|
|
98
|
+
if ($[0] !== active) {
|
|
99
|
+
t1 = node => {
|
|
100
|
+
if (!active) {
|
|
101
|
+
ref.current = null;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (restoreAria.current) {
|
|
105
|
+
restoreAria.current();
|
|
106
|
+
}
|
|
107
|
+
if (node) {
|
|
108
|
+
const processNode = _node => {
|
|
109
|
+
restoreAria.current = createAriaHider(_node);
|
|
110
|
+
let focusElement = node.querySelector("[data-autofocus]");
|
|
111
|
+
if (!focusElement) {
|
|
112
|
+
const children = Array.from(node.querySelectorAll(FOCUS_SELECTOR));
|
|
113
|
+
focusElement = children.find(tabbable) || children.find(focusable) || null;
|
|
114
|
+
if (!focusElement && focusable(node)) {
|
|
115
|
+
focusElement = node;
|
|
116
|
+
}
|
|
109
117
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
118
|
+
if (focusElement) {
|
|
119
|
+
focusElement.focus();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
timer.current = window.setTimeout(() => {
|
|
123
|
+
if (node.ownerDocument) {
|
|
124
|
+
processNode(node);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
ref.current = node;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
ref.current = null;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
$[0] = active;
|
|
134
|
+
$[1] = t1;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
t1 = $[1];
|
|
138
|
+
}
|
|
139
|
+
const setRef = t1;
|
|
140
|
+
let t2;
|
|
141
|
+
let t3;
|
|
142
|
+
if ($[2] !== active) {
|
|
143
|
+
t2 = () => {
|
|
144
|
+
if (!active) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const handler = e => {
|
|
148
|
+
const node_0 = ref.current;
|
|
149
|
+
if (e.key === "Tab" && node_0) {
|
|
150
|
+
scopeTab(node_0, e);
|
|
113
151
|
}
|
|
114
152
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (node.ownerDocument) {
|
|
119
|
-
processNode(node);
|
|
120
|
-
}
|
|
153
|
+
const controller = new AbortController();
|
|
154
|
+
document.addEventListener("keydown", handler, {
|
|
155
|
+
signal: controller.signal
|
|
121
156
|
});
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
ref.current = null;
|
|
126
|
-
}
|
|
127
|
-
}, [active]);
|
|
128
|
-
(0, react_1.useEffect)(() => {
|
|
129
|
-
if (!active) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const handler = (e) => {
|
|
133
|
-
const node = ref.current;
|
|
134
|
-
if (e.key === "Tab" && node) {
|
|
135
|
-
scopeTab(node, e);
|
|
136
|
-
}
|
|
157
|
+
return () => controller.abort();
|
|
137
158
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
159
|
+
t3 = [active];
|
|
160
|
+
$[2] = active;
|
|
161
|
+
$[3] = t2;
|
|
162
|
+
$[4] = t3;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
t2 = $[3];
|
|
166
|
+
t3 = $[4];
|
|
167
|
+
}
|
|
168
|
+
(0, react_1.useEffect)(t2, t3);
|
|
169
|
+
let t4;
|
|
170
|
+
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
171
|
+
t4 = () => clearTimeout(timer.current);
|
|
172
|
+
$[5] = t4;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
t4 = $[5];
|
|
176
|
+
}
|
|
177
|
+
(0, use_on_unmount_1.useOnUnmount)(t4);
|
|
144
178
|
return setRef;
|
|
145
179
|
}
|
package/hooks/use-increment.js
CHANGED
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useIncrement = useIncrement;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
|
-
function useIncrement(defaultValue,
|
|
6
|
+
function useIncrement(defaultValue, t0) {
|
|
7
|
+
const $ = (0, compiler_runtime_1.c)(11);
|
|
8
|
+
const step = t0 === undefined ? 1 : t0;
|
|
6
9
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
let t1;
|
|
11
|
+
if ($[0] !== step) {
|
|
12
|
+
t1 = () => setValue(prev => prev + step);
|
|
13
|
+
$[0] = step;
|
|
14
|
+
$[1] = t1;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
t1 = $[1];
|
|
18
|
+
}
|
|
19
|
+
const incrementHandler = t1;
|
|
20
|
+
let t2;
|
|
21
|
+
if ($[2] !== step) {
|
|
22
|
+
t2 = () => setValue(prev_0 => prev_0 - step);
|
|
23
|
+
$[2] = step;
|
|
24
|
+
$[3] = t2;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
t2 = $[3];
|
|
28
|
+
}
|
|
29
|
+
const decrementHandler = t2;
|
|
30
|
+
let t3;
|
|
31
|
+
if ($[4] !== defaultValue) {
|
|
32
|
+
t3 = () => setValue(defaultValue);
|
|
33
|
+
$[4] = defaultValue;
|
|
34
|
+
$[5] = t3;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
t3 = $[5];
|
|
38
|
+
}
|
|
39
|
+
const resetHandler = t3;
|
|
40
|
+
let t4;
|
|
41
|
+
if ($[6] !== decrementHandler || $[7] !== incrementHandler || $[8] !== resetHandler || $[9] !== value) {
|
|
42
|
+
t4 = [value, incrementHandler, decrementHandler, resetHandler];
|
|
43
|
+
$[6] = decrementHandler;
|
|
44
|
+
$[7] = incrementHandler;
|
|
45
|
+
$[8] = resetHandler;
|
|
46
|
+
$[9] = value;
|
|
47
|
+
$[10] = t4;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
t4 = $[10];
|
|
51
|
+
}
|
|
52
|
+
return t4;
|
|
11
53
|
}
|
package/hooks/use-input-focus.js
CHANGED
|
@@ -1,26 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useInputFocus = useInputFocus;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
function useInputFocus(focusRef, onBlur, onFocus) {
|
|
7
|
+
const $ = (0, compiler_runtime_1.c)(11);
|
|
6
8
|
const [focused, setFocused] = (0, react_1.useState)(false);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
node.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
let t0;
|
|
10
|
+
if ($[0] !== focusRef) {
|
|
11
|
+
t0 = () => {
|
|
12
|
+
const node = focusRef.current;
|
|
13
|
+
if (node) {
|
|
14
|
+
node.focus();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
$[0] = focusRef;
|
|
18
|
+
$[1] = t0;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
t0 = $[1];
|
|
22
|
+
}
|
|
23
|
+
const focus = t0;
|
|
24
|
+
let t1;
|
|
25
|
+
if ($[2] !== onFocus) {
|
|
26
|
+
t1 = e => {
|
|
27
|
+
setFocused(true);
|
|
28
|
+
if (onFocus) {
|
|
29
|
+
onFocus(e);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
$[2] = onFocus;
|
|
33
|
+
$[3] = t1;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
t1 = $[3];
|
|
37
|
+
}
|
|
38
|
+
const _onFocus = t1;
|
|
39
|
+
let t2;
|
|
40
|
+
if ($[4] !== onBlur) {
|
|
41
|
+
t2 = e_0 => {
|
|
42
|
+
setFocused(false);
|
|
43
|
+
if (onBlur) {
|
|
44
|
+
onBlur(e_0);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
$[4] = onBlur;
|
|
48
|
+
$[5] = t2;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
t2 = $[5];
|
|
52
|
+
}
|
|
53
|
+
const _onBlur = t2;
|
|
54
|
+
let t3;
|
|
55
|
+
if ($[6] !== _onBlur || $[7] !== _onFocus || $[8] !== focus || $[9] !== focused) {
|
|
56
|
+
t3 = {
|
|
57
|
+
focused,
|
|
58
|
+
focus,
|
|
59
|
+
onBlur: _onBlur,
|
|
60
|
+
onFocus: _onFocus
|
|
61
|
+
};
|
|
62
|
+
$[6] = _onBlur;
|
|
63
|
+
$[7] = _onFocus;
|
|
64
|
+
$[8] = focus;
|
|
65
|
+
$[9] = focused;
|
|
66
|
+
$[10] = t3;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
t3 = $[10];
|
|
70
|
+
}
|
|
71
|
+
return t3;
|
|
26
72
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* False on the server and during hydration, true in every other render, including the first render of a component
|
|
3
|
+
* that mounts later on the client. For rendering something only in the browser (it touches `window`, a portal
|
|
4
|
+
* into `document.body`, an editor), without the extra commit and the flash of fallback `useIsMounted` costs on
|
|
5
|
+
* every client-side mount.
|
|
6
|
+
*
|
|
7
|
+
* Unlike `useIsMounted`, it does not mean effects have run: refs are not attached yet in a render where it turns
|
|
8
|
+
* true. Code that reads refs or measures the DOM after mount still needs an effect.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useIsHydrated(): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsHydrated = useIsHydrated;
|
|
4
|
+
const noop_1 = require("@uxf/core/utils/noop");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const subscribeToNothing = () => noop_1.noop;
|
|
7
|
+
/**
|
|
8
|
+
* False on the server and during hydration, true in every other render, including the first render of a component
|
|
9
|
+
* that mounts later on the client. For rendering something only in the browser (it touches `window`, a portal
|
|
10
|
+
* into `document.body`, an editor), without the extra commit and the flash of fallback `useIsMounted` costs on
|
|
11
|
+
* every client-side mount.
|
|
12
|
+
*
|
|
13
|
+
* Unlike `useIsMounted`, it does not mean effects have run: refs are not attached yet in a render where it turns
|
|
14
|
+
* true. Code that reads refs or measures the DOM after mount still needs an effect.
|
|
15
|
+
*/
|
|
16
|
+
function useIsHydrated() {
|
|
17
|
+
return (0, react_1.useSyncExternalStore)(subscribeToNothing, _temp, _temp2);
|
|
18
|
+
}
|
|
19
|
+
function _temp2() {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
function _temp() {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
7
|
+
const react_1 = require("@testing-library/react");
|
|
8
|
+
const react_2 = __importDefault(require("react"));
|
|
9
|
+
const client_1 = require("react-dom/client");
|
|
10
|
+
const server_1 = require("react-dom/server");
|
|
11
|
+
const use_is_hydrated_1 = require("./use-is-hydrated");
|
|
12
|
+
function Probe(props) {
|
|
13
|
+
const $ = (0, compiler_runtime_1.c)(2);
|
|
14
|
+
const isHydrated = (0, use_is_hydrated_1.useIsHydrated)();
|
|
15
|
+
props.onRender(isHydrated);
|
|
16
|
+
const t0 = isHydrated ? "client" : "server";
|
|
17
|
+
let t1;
|
|
18
|
+
if ($[0] !== t0) {
|
|
19
|
+
t1 = react_2.default.createElement("span", null, t0);
|
|
20
|
+
$[0] = t0;
|
|
21
|
+
$[1] = t1;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
t1 = $[1];
|
|
25
|
+
}
|
|
26
|
+
return t1;
|
|
27
|
+
}
|
|
28
|
+
test("is false while rendering on the server", () => {
|
|
29
|
+
expect((0, server_1.renderToString)(react_2.default.createElement(Probe, { onRender: jest.fn() }))).toContain("server");
|
|
30
|
+
});
|
|
31
|
+
test("is false while hydrating, then true", async () => {
|
|
32
|
+
const container = document.createElement("div");
|
|
33
|
+
container.innerHTML = (0, server_1.renderToString)(react_2.default.createElement(Probe, { onRender: jest.fn() }));
|
|
34
|
+
const onRender = jest.fn();
|
|
35
|
+
await (0, react_1.act)(async () => {
|
|
36
|
+
(0, client_1.hydrateRoot)(container, react_2.default.createElement(Probe, { onRender: onRender }));
|
|
37
|
+
});
|
|
38
|
+
expect(onRender.mock.calls.map(([isHydrated]) => isHydrated)).toEqual([false, true]);
|
|
39
|
+
expect(container.textContent).toBe("client");
|
|
40
|
+
});
|
|
41
|
+
test("is true from the first render of a component mounted on the client", () => {
|
|
42
|
+
const onRender = jest.fn();
|
|
43
|
+
(0, react_1.render)(react_2.default.createElement(Probe, { onRender: onRender }));
|
|
44
|
+
expect(onRender.mock.calls.map(([isHydrated]) => isHydrated)).toEqual([true]);
|
|
45
|
+
});
|
|
@@ -1 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated Use `useIsHydrated` (`@uxf/core-react/hooks/use-is-hydrated`) to render something only in the browser:
|
|
3
|
+
* it is true from the first render of a component mounted on the client, where this costs an extra commit and a
|
|
4
|
+
* flash of the fallback. Keep this only where the code needs effects to have run, i.e. refs attached.
|
|
5
|
+
*/
|
|
1
6
|
export declare function useIsMounted(): boolean;
|
package/hooks/use-is-mounted.js
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useIsMounted = useIsMounted;
|
|
4
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
4
5
|
const react_1 = require("react");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use `useIsHydrated` (`@uxf/core-react/hooks/use-is-hydrated`) to render something only in the browser:
|
|
8
|
+
* it is true from the first render of a component mounted on the client, where this costs an extra commit and a
|
|
9
|
+
* flash of the fallback. Keep this only where the code needs effects to have run, i.e. refs attached.
|
|
10
|
+
*/
|
|
5
11
|
function useIsMounted() {
|
|
12
|
+
const $ = (0, compiler_runtime_1.c)(2);
|
|
6
13
|
const [isMounted, setIsMounted] = (0, react_1.useState)(false);
|
|
7
|
-
|
|
14
|
+
let t0;
|
|
15
|
+
let t1;
|
|
16
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
17
|
+
t0 = () => setIsMounted(true);
|
|
18
|
+
t1 = [];
|
|
19
|
+
$[0] = t0;
|
|
20
|
+
$[1] = t1;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
t0 = $[0];
|
|
24
|
+
t1 = $[1];
|
|
25
|
+
}
|
|
26
|
+
(0, react_1.useEffect)(t0, t1);
|
|
8
27
|
return isMounted;
|
|
9
28
|
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use `useLayoutEffect`. This existed only to silence React's server warning "useLayoutEffect does
|
|
4
|
+
* nothing on the server", which React 19 removed; on the server `useLayoutEffect` now simply does not run.
|
|
5
|
+
*/
|
|
2
6
|
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
@@ -3,4 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useIsomorphicLayoutEffect = void 0;
|
|
4
4
|
const is_browser_1 = require("@uxf/core/utils/is-browser");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use `useLayoutEffect`. This existed only to silence React's server warning "useLayoutEffect does
|
|
8
|
+
* nothing on the server", which React 19 removed; on the server `useLayoutEffect` now simply does not run.
|
|
9
|
+
*/
|
|
6
10
|
exports.useIsomorphicLayoutEffect = is_browser_1.isBrowser ? react_1.useLayoutEffect : react_1.useEffect;
|