@fibery/react 1.5.2 → 1.5.4
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/package.json +6 -9
- package/src/create-context.ts +1 -1
- package/src/get-ref-value.ts +1 -1
- package/src/react-node-to-string.ts +2 -1
- package/src/shared-query-client-provider.tsx +2 -1
- package/src/use-composed-refs.ts +2 -1
- package/src/use-controllable-state/use-controllable-state.test.ts +4 -3
- package/src/use-controllable-state/use-controllable-state.ts +14 -6
- package/src/use-focus-outside.ts +1 -0
- package/src/use-pointer-down-outside.tsx +2 -1
- package/src/use-resize-observer.ts +5 -2
- package/src/use-size.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"files": [
|
|
@@ -8,16 +8,13 @@
|
|
|
8
8
|
],
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@tanstack/react-query": "5.62.7",
|
|
11
|
-
"@fibery/helpers": "
|
|
11
|
+
"@fibery/helpers": "3.1.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@testing-library/react": "16.3.1",
|
|
15
15
|
"@testing-library/react-hooks": "8.0.1",
|
|
16
|
-
"@types/jest": "30.0.0",
|
|
17
16
|
"@types/react": "18.3.12",
|
|
18
17
|
"@types/react-dom": "18.3.1",
|
|
19
|
-
"jest": "30.2.0",
|
|
20
|
-
"jest-junit": "16.0.0",
|
|
21
18
|
"react": "18.3.1",
|
|
22
19
|
"react-dom": "18.3.1",
|
|
23
20
|
"react-test-renderer": "18.3.1",
|
|
@@ -29,9 +26,9 @@
|
|
|
29
26
|
},
|
|
30
27
|
"scripts": {
|
|
31
28
|
"check": "../../scripts/check.sh",
|
|
32
|
-
"lint": "
|
|
33
|
-
"test": "
|
|
34
|
-
"test:ci": "
|
|
35
|
-
"test:coverage": "
|
|
29
|
+
"lint": "pnpm -w lint .",
|
|
30
|
+
"test": "../../scripts/test.sh",
|
|
31
|
+
"test:ci": "../../scripts/test.sh --ci",
|
|
32
|
+
"test:coverage": "../../scripts/test.sh --ci --coverage"
|
|
36
33
|
}
|
|
37
34
|
}
|
package/src/create-context.ts
CHANGED
package/src/get-ref-value.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {ReactElement, ReactNode} from "react";
|
|
2
|
+
import {Children, isValidElement} from "react";
|
|
2
3
|
|
|
3
4
|
const nodeToString = (child?: React.ReactNode): string => {
|
|
4
5
|
if (typeof child === "string" || typeof child === "number") {
|
package/src/use-composed-refs.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {act, renderHook} from "@testing-library/react-hooks";
|
|
2
|
+
|
|
2
3
|
import {useControllableState} from "./use-controllable-state";
|
|
3
4
|
|
|
4
5
|
describe("useControllableState", () => {
|
|
5
6
|
describe("uncontrolled", () => {
|
|
6
7
|
it("should work for uncontrolled", () => {
|
|
7
|
-
const onChange =
|
|
8
|
+
const onChange = vi.fn();
|
|
8
9
|
const {result} = renderHook(() => useControllableState({onChange}));
|
|
9
10
|
expect(result.current[0]).toBe(undefined);
|
|
10
11
|
|
|
@@ -16,7 +17,7 @@ describe("useControllableState", () => {
|
|
|
16
17
|
expect(onChange).toHaveBeenCalledWith(true);
|
|
17
18
|
});
|
|
18
19
|
it("should work for uncontrolled with default value", () => {
|
|
19
|
-
const onChange =
|
|
20
|
+
const onChange = vi.fn();
|
|
20
21
|
const {result} = renderHook(() => useControllableState({defaultValue: true, onChange}));
|
|
21
22
|
expect(result.current[0]).toBe(true);
|
|
22
23
|
|
|
@@ -30,7 +31,7 @@ describe("useControllableState", () => {
|
|
|
30
31
|
});
|
|
31
32
|
describe("controlled", () => {
|
|
32
33
|
it("should not change internal state. It's controlled by 'value'", () => {
|
|
33
|
-
const onChange =
|
|
34
|
+
const onChange = vi.fn();
|
|
34
35
|
const {result} = renderHook(() => useControllableState({value: true, onChange}));
|
|
35
36
|
expect(result.current[0]).toEqual(true);
|
|
36
37
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {Dispatch, SetStateAction
|
|
1
|
+
import type {Dispatch, SetStateAction} from "react";
|
|
2
|
+
import {useCallback, useEffect, useRef, useState} from "react";
|
|
3
|
+
|
|
2
4
|
import {useCallbackRef} from "../use-callback-ref";
|
|
3
5
|
|
|
4
6
|
type UseControllableStateProps<TState> = {
|
|
@@ -25,6 +27,17 @@ export const useControllableState = <TState>({
|
|
|
25
27
|
const isControlled = value !== undefined;
|
|
26
28
|
const state = isControlled ? value : uncontrolledState;
|
|
27
29
|
|
|
30
|
+
// Call onChange after uncontrolled state changes via useEffect to avoid calling
|
|
31
|
+
// setState on another component during a state updater (which React flags as
|
|
32
|
+
// "setState during render" warning in development mode).
|
|
33
|
+
const prevUncontrolledStateRef = useRef(uncontrolledState);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (prevUncontrolledStateRef.current !== uncontrolledState) {
|
|
36
|
+
onChangeState(uncontrolledState);
|
|
37
|
+
prevUncontrolledStateRef.current = uncontrolledState;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
28
41
|
const setState = useCallback<Dispatch<SetStateAction<TState>>>(
|
|
29
42
|
(nextValue) => {
|
|
30
43
|
if (isControlled) {
|
|
@@ -37,11 +50,6 @@ export const useControllableState = <TState>({
|
|
|
37
50
|
} else {
|
|
38
51
|
setUncontrolledState((prevValue) => {
|
|
39
52
|
const nextState = nextValue instanceof Function ? nextValue(prevValue) : nextValue;
|
|
40
|
-
|
|
41
|
-
// should it be in effect to be more predictable?
|
|
42
|
-
if (prevValue !== nextState) {
|
|
43
|
-
onChangeState(nextState as TState);
|
|
44
|
-
}
|
|
45
53
|
return nextState as TState;
|
|
46
54
|
});
|
|
47
55
|
}
|
package/src/use-focus-outside.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {useCallbackRef} from "./use-callback-ref";
|
|
2
1
|
import {useEffect, useRef} from "react";
|
|
3
2
|
|
|
3
|
+
import {useCallbackRef} from "./use-callback-ref";
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Inspired by radix
|
|
6
7
|
* https://github.com/radix-ui/primitives/blob/c31c97274ff357aea99afe6c01c1c8c58b6356e0/packages/react/dismissable-layer/src/DismissableLayer.tsx#L223
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {ResizeListenerCallback} from "@fibery/helpers/utils/resize-listener";
|
|
2
|
+
import {getResizeListener} from "@fibery/helpers/utils/resize-listener";
|
|
3
|
+
import type {RefObject} from "react";
|
|
4
|
+
import {useLayoutEffect} from "react";
|
|
2
5
|
import {flushSync} from "react-dom";
|
|
6
|
+
|
|
3
7
|
import {getRefValue} from "./get-ref-value";
|
|
4
8
|
import {useCallbackRef} from "./use-callback-ref";
|
|
5
|
-
import {getResizeListener, ResizeListenerCallback} from "@fibery/helpers/utils/resize-listener";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* React hook to observe provided element with ResizeObserver
|
package/src/use-size.ts
CHANGED