@uxf/core-react 14.0.0 → 15.0.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 +5 -3
- 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 -8
- package/hooks/use-debounce.test.js +15 -3
- package/hooks/use-focus-return.js +55 -24
- package/hooks/use-focus-trap.js +87 -52
- package/hooks/use-increment.js +47 -5
- package/hooks/use-input-focus.js +65 -19
- package/hooks/use-is-hydrated.js +7 -1
- package/hooks/use-is-hydrated.test.js +13 -1
- package/hooks/use-is-mounted.js +15 -1
- package/hooks/use-key.js +53 -23
- package/hooks/use-key.test.js +88 -8
- package/hooks/use-media-query.js +77 -18
- package/hooks/use-media-query.test.js +29 -8
- package/hooks/use-min-window-width.js +39 -19
- 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.js +22 -3
- package/hooks/use-on-update.js +20 -8
- package/hooks/use-on-update.test.js +17 -2
- package/hooks/use-pagination.js +30 -14
- package/hooks/use-previous.js +14 -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 -13
- package/hooks/use-window-scroll.test.js +141 -41
- package/hooks/use-window-size.d.ts +7 -2
- package/hooks/use-window-size.js +34 -13
- package/hooks/use-window-size.test.js +147 -31
- package/package.json +7 -7
- package/swipeable/use-swipeable.test.js +31 -5
- package/translations/index.js +1 -1
|
@@ -1,40 +1,156 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
3
37
|
const react_1 = require("@testing-library/react");
|
|
38
|
+
const react_2 = __importStar(require("react"));
|
|
39
|
+
const client_1 = require("react-dom/client");
|
|
40
|
+
const server_1 = require("react-dom/server");
|
|
4
41
|
const use_window_size_1 = require("./use-window-size");
|
|
5
|
-
|
|
6
|
-
window
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
window.addEventListener = jest.fn((event, callback) => {
|
|
10
|
-
if (event === "resize") {
|
|
11
|
-
window.resizeHandler = callback;
|
|
12
|
-
}
|
|
42
|
+
function setWindowSize(width, height) {
|
|
43
|
+
Object.defineProperty(window, "innerWidth", {
|
|
44
|
+
configurable: true,
|
|
45
|
+
value: width
|
|
13
46
|
});
|
|
14
|
-
window
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
afterAll(() => {
|
|
26
|
-
jest.clearAllMocks();
|
|
47
|
+
Object.defineProperty(window, "innerHeight", {
|
|
48
|
+
configurable: true,
|
|
49
|
+
value: height
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
jest.useFakeTimers();
|
|
54
|
+
setWindowSize(1024, 768);
|
|
55
|
+
});
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
jest.useRealTimers();
|
|
27
58
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
test("returns the window size from the first render", () => {
|
|
60
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
|
|
61
|
+
expect(result.current).toEqual({
|
|
62
|
+
width: 1024,
|
|
63
|
+
height: 768
|
|
32
64
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
65
|
+
});
|
|
66
|
+
test("follows a resize after the next animation frame", () => {
|
|
67
|
+
const { result } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
|
|
68
|
+
(0, react_1.act)(() => {
|
|
69
|
+
setWindowSize(800, 600);
|
|
70
|
+
window.dispatchEvent(new Event("resize"));
|
|
71
|
+
jest.advanceTimersByTime(50);
|
|
72
|
+
});
|
|
73
|
+
expect(result.current).toEqual({
|
|
74
|
+
width: 800,
|
|
75
|
+
height: 600
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
test("keeps the same object while the size does not change", () => {
|
|
79
|
+
const { result, rerender } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
|
|
80
|
+
const first = result.current;
|
|
81
|
+
rerender();
|
|
82
|
+
expect(result.current).toBe(first);
|
|
83
|
+
});
|
|
84
|
+
test("stops listening on unmount", () => {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const addEventListener = jest.spyOn(window, "addEventListener");
|
|
87
|
+
const { unmount } = (0, react_1.renderHook)(() => (0, use_window_size_1.useWindowSize)());
|
|
88
|
+
unmount();
|
|
89
|
+
const listenerOptions = (_a = addEventListener.mock.calls.find(([type]) => type === "resize")) === null || _a === void 0 ? void 0 : _a[2];
|
|
90
|
+
expect((_b = listenerOptions === null || listenerOptions === void 0 ? void 0 : listenerOptions.signal) === null || _b === void 0 ? void 0 : _b.aborted).toBe(true);
|
|
91
|
+
addEventListener.mockRestore();
|
|
92
|
+
});
|
|
93
|
+
test("renders without a size on the server", () => {
|
|
94
|
+
function Probe() {
|
|
95
|
+
const $ = (0, compiler_runtime_1.c)(4);
|
|
96
|
+
const value = (0, use_window_size_1.useWindowSize)();
|
|
97
|
+
let t0;
|
|
98
|
+
if ($[0] !== value) {
|
|
99
|
+
t0 = value ? JSON.stringify(value) : "none";
|
|
100
|
+
$[0] = value;
|
|
101
|
+
$[1] = t0;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
t0 = $[1];
|
|
105
|
+
}
|
|
106
|
+
let t1;
|
|
107
|
+
if ($[2] !== t0) {
|
|
108
|
+
t1 = react_2.default.createElement("span", null, t0);
|
|
109
|
+
$[2] = t0;
|
|
110
|
+
$[3] = t1;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
t1 = $[3];
|
|
114
|
+
}
|
|
115
|
+
return t1;
|
|
116
|
+
}
|
|
117
|
+
expect((0, server_1.renderToString)(react_2.default.createElement(Probe, null))).toBe("<span>none</span>");
|
|
118
|
+
});
|
|
119
|
+
test("hydrates without a mismatch and shows the client value after hydration", () => {
|
|
120
|
+
function Probe() {
|
|
121
|
+
const $ = (0, compiler_runtime_1.c)(4);
|
|
122
|
+
const value = (0, use_window_size_1.useWindowSize)();
|
|
123
|
+
let t0;
|
|
124
|
+
if ($[0] !== value) {
|
|
125
|
+
t0 = value ? JSON.stringify(value) : "none";
|
|
126
|
+
$[0] = value;
|
|
127
|
+
$[1] = t0;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
t0 = $[1];
|
|
131
|
+
}
|
|
132
|
+
let t1;
|
|
133
|
+
if ($[2] !== t0) {
|
|
134
|
+
t1 = react_2.default.createElement("span", null, t0);
|
|
135
|
+
$[2] = t0;
|
|
136
|
+
$[3] = t1;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
t1 = $[3];
|
|
140
|
+
}
|
|
141
|
+
return t1;
|
|
142
|
+
}
|
|
143
|
+
const container = document.createElement("div");
|
|
144
|
+
container.innerHTML = (0, server_1.renderToString)(react_2.default.createElement(Probe, null));
|
|
145
|
+
document.body.append(container);
|
|
146
|
+
const onRecoverableError = jest.fn();
|
|
147
|
+
(0, react_1.act)(() => {
|
|
148
|
+
(0, client_1.hydrateRoot)(container, react_2.default.createElement(react_2.StrictMode, null,
|
|
149
|
+
react_2.default.createElement(Probe, null)), {
|
|
150
|
+
onRecoverableError
|
|
151
|
+
});
|
|
39
152
|
});
|
|
153
|
+
expect(onRecoverableError).not.toHaveBeenCalled();
|
|
154
|
+
expect(container.textContent).toBe('{"width":1024,"height":768}');
|
|
155
|
+
container.remove();
|
|
40
156
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/core-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"description": "UXF Core",
|
|
5
5
|
"author": "UX Fans s.r.o",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsc -P tsconfig.json",
|
|
11
|
+
"build": "tsc -P tsconfig.json && node ../../scripts/build-react-package.mjs",
|
|
12
12
|
"typecheck": "tsc --noEmit"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@uxf/core": "
|
|
16
|
-
"next": ">=16.
|
|
15
|
+
"@uxf/core": "15.0.0",
|
|
16
|
+
"next": ">=16.4.3",
|
|
17
17
|
"react": "^19.3.0",
|
|
18
18
|
"react-dom": "^19.3.0"
|
|
19
19
|
},
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/react": "19.3.0",
|
|
27
27
|
"@types/react-dom": "19.3.0",
|
|
28
|
-
"@uxf/core": "
|
|
29
|
-
"react": "19.3.
|
|
30
|
-
"react-dom": "19.3.
|
|
28
|
+
"@uxf/core": "15.0.0",
|
|
29
|
+
"react": "19.3.1",
|
|
30
|
+
"react-dom": "19.3.1"
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -3,19 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const compiler_runtime_1 = require("react/compiler-runtime");
|
|
6
7
|
const react_1 = require("@testing-library/react");
|
|
7
8
|
const react_2 = __importDefault(require("react"));
|
|
8
9
|
const use_swipeable_1 = require("./use-swipeable");
|
|
9
10
|
function Swipeable(props) {
|
|
11
|
+
const $ = (0, compiler_runtime_1.c)(3);
|
|
10
12
|
const handlers = (0, use_swipeable_1.useSwipeable)(props);
|
|
11
|
-
|
|
13
|
+
let t0;
|
|
14
|
+
if ($[0] !== handlers || $[1] !== props.isShown) {
|
|
15
|
+
t0 = props.isShown === false ? null : react_2.default.createElement("div", { ...handlers }, "swipe");
|
|
16
|
+
$[0] = handlers;
|
|
17
|
+
$[1] = props.isShown;
|
|
18
|
+
$[2] = t0;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
t0 = $[2];
|
|
22
|
+
}
|
|
23
|
+
return t0;
|
|
12
24
|
}
|
|
13
25
|
function swipeLeft(element) {
|
|
14
|
-
const touch =
|
|
26
|
+
const touch = clientX => ({
|
|
27
|
+
touches: [{
|
|
28
|
+
clientX,
|
|
29
|
+
clientY: 0
|
|
30
|
+
}],
|
|
31
|
+
timeStamp: 1
|
|
32
|
+
});
|
|
15
33
|
react_1.fireEvent.touchStart(element, touch(200));
|
|
16
34
|
react_1.fireEvent.touchMove(element, touch(100));
|
|
17
35
|
react_1.fireEvent.touchMove(element, touch(0));
|
|
18
|
-
react_1.fireEvent.touchEnd(element, {
|
|
36
|
+
react_1.fireEvent.touchEnd(element, {
|
|
37
|
+
touches: []
|
|
38
|
+
});
|
|
19
39
|
}
|
|
20
40
|
test("a swipe reaches the latest callback", () => {
|
|
21
41
|
const first = jest.fn();
|
|
@@ -29,9 +49,15 @@ test("a swipe reaches the latest callback", () => {
|
|
|
29
49
|
test("unmounting in the middle of a mouse drag stops tracking the mouse on the document", () => {
|
|
30
50
|
const onSwiping = jest.fn();
|
|
31
51
|
const { getByText, unmount } = (0, react_1.render)(react_2.default.createElement(Swipeable, { onSwiping: onSwiping, trackMouse: true }));
|
|
32
|
-
react_1.fireEvent.mouseDown(getByText("swipe"), {
|
|
52
|
+
react_1.fireEvent.mouseDown(getByText("swipe"), {
|
|
53
|
+
clientX: 0,
|
|
54
|
+
clientY: 0
|
|
55
|
+
});
|
|
33
56
|
unmount();
|
|
34
|
-
react_1.fireEvent.mouseMove(document, {
|
|
57
|
+
react_1.fireEvent.mouseMove(document, {
|
|
58
|
+
clientX: 100,
|
|
59
|
+
clientY: 0
|
|
60
|
+
});
|
|
35
61
|
expect(onSwiping).not.toHaveBeenCalled();
|
|
36
62
|
});
|
|
37
63
|
test("after unmounting, touches on the element no longer count", () => {
|
package/translations/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const react_1 = require("react");
|
|
|
7
7
|
const global_context_1 = require("../global-context");
|
|
8
8
|
/* intellisense and linting is broken with any other more specific type */
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
const translationsContext = (0, global_context_1.createGlobalContext)("core-react/translations",
|
|
10
|
+
const translationsContext = (0, global_context_1.createGlobalContext)("core-react/translations", key => key);
|
|
11
11
|
exports.TranslationsProvider = translationsContext.Provider;
|
|
12
12
|
function useUxfTranslation() {
|
|
13
13
|
return (0, react_1.useContext)(translationsContext);
|