@dxos/react-hooks 0.8.4-main.b97322e → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/README.md +1 -0
- package/dist/lib/browser/index.mjs +217 -144
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +217 -144
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/index.d.ts +5 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useAsyncEffect.d.ts +5 -29
- package/dist/types/src/useAsyncEffect.d.ts.map +1 -1
- package/dist/types/src/useAsyncState.d.ts.map +1 -1
- package/dist/types/src/useAtomState.d.ts +12 -0
- package/dist/types/src/useAtomState.d.ts.map +1 -0
- package/dist/types/src/useControlledState.d.ts +2 -1
- package/dist/types/src/useControlledState.d.ts.map +1 -1
- package/dist/types/src/useDebugDeps.d.ts +6 -0
- package/dist/types/src/useDebugDeps.d.ts.map +1 -0
- package/dist/types/src/useDefaultValue.d.ts.map +1 -1
- package/dist/types/src/useDefaults.d.ts.map +1 -1
- package/dist/types/src/useDynamicRef.d.ts +6 -1
- package/dist/types/src/useDynamicRef.d.ts.map +1 -1
- package/dist/types/src/useForwardedRef.d.ts +23 -3
- package/dist/types/src/useForwardedRef.d.ts.map +1 -1
- package/dist/types/src/useId.d.ts.map +1 -1
- package/dist/types/src/useIsFocused.d.ts +1 -1
- package/dist/types/src/useIsFocused.d.ts.map +1 -1
- package/dist/types/src/useMediaQuery.d.ts +1 -1
- package/dist/types/src/useMediaQuery.d.ts.map +1 -1
- package/dist/types/src/useMulticastObservable.d.ts.map +1 -1
- package/dist/types/src/useMulticastObservable.test.d.ts.map +1 -1
- package/dist/types/src/useTimeout.d.ts +2 -1
- package/dist/types/src/useTimeout.d.ts.map +1 -1
- package/dist/types/src/useTransitions.d.ts +2 -1
- package/dist/types/src/useTransitions.d.ts.map +1 -1
- package/dist/types/src/useViewportResize.d.ts +3 -0
- package/dist/types/src/useViewportResize.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -15
- package/src/index.ts +6 -3
- package/src/useAsyncEffect.ts +19 -49
- package/src/useAtomState.ts +23 -0
- package/src/useControlledState.ts +22 -11
- package/src/useDebugDeps.ts +35 -0
- package/src/useDefaultValue.ts +1 -1
- package/src/useDynamicRef.ts +26 -5
- package/src/useForwardedRef.ts +50 -13
- package/src/useId.ts +3 -2
- package/src/useIsFocused.ts +3 -3
- package/src/useMediaQuery.ts +8 -9
- package/src/{useMulticastObservable.test.tsx → useMulticastObservable.test.ts} +1 -3
- package/src/useTimeout.ts +28 -3
- package/src/useTransitions.ts +4 -2
- package/src/{useResize.ts → useViewportResize.ts} +4 -4
- package/dist/types/src/useAsyncEffect.test.d.ts +0 -2
- package/dist/types/src/useAsyncEffect.test.d.ts.map +0 -1
- package/dist/types/src/useDebugReactDeps.d.ts +0 -6
- package/dist/types/src/useDebugReactDeps.d.ts.map +0 -1
- package/dist/types/src/useResize.d.ts +0 -3
- package/dist/types/src/useResize.d.ts.map +0 -1
- package/dist/types/src/useTrackProps.d.ts +0 -5
- package/dist/types/src/useTrackProps.d.ts.map +0 -1
- package/src/useAsyncEffect.test.tsx +0 -51
- package/src/useDebugReactDeps.ts +0 -27
- package/src/useTrackProps.ts +0 -40
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,32 +1,48 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
3
|
+
import { useSize, useScroller } from "mini-virtual-list";
|
|
4
|
+
|
|
1
5
|
// src/useAsyncEffect.ts
|
|
2
6
|
import { useEffect } from "react";
|
|
3
|
-
|
|
4
|
-
var useAsyncEffect = (callback, destructor, deps) => {
|
|
5
|
-
const [effectDestructor, effectDeps] = typeof destructor === "function" ? [
|
|
6
|
-
destructor,
|
|
7
|
-
deps
|
|
8
|
-
] : [
|
|
9
|
-
void 0,
|
|
10
|
-
destructor
|
|
11
|
-
];
|
|
7
|
+
var useAsyncEffect = (cb, deps) => {
|
|
12
8
|
useEffect(() => {
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const controller = new AbortController();
|
|
10
|
+
let cleanup;
|
|
11
|
+
const t = setTimeout(async () => {
|
|
12
|
+
if (!controller.signal.aborted) {
|
|
13
|
+
cleanup = await cb(controller);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
19
16
|
return () => {
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
clearTimeout(t);
|
|
18
|
+
controller.abort();
|
|
19
|
+
cleanup?.();
|
|
22
20
|
};
|
|
23
|
-
},
|
|
21
|
+
}, deps ?? []);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/useAtomState.ts
|
|
25
|
+
import { Atom, useAtomSet, useAtomValue } from "@effect-atom/atom-react";
|
|
26
|
+
import { useMemo, useState } from "react";
|
|
27
|
+
var useAtomState = (initialValue) => {
|
|
28
|
+
const [atom] = useState(() => Atom.make(initialValue));
|
|
29
|
+
const value = useAtomValue(atom);
|
|
30
|
+
const set = useAtomSet(atom);
|
|
31
|
+
return useMemo(() => ({
|
|
32
|
+
atom,
|
|
33
|
+
value,
|
|
34
|
+
set
|
|
35
|
+
}), [
|
|
36
|
+
atom,
|
|
37
|
+
value,
|
|
38
|
+
set
|
|
39
|
+
]);
|
|
24
40
|
};
|
|
25
41
|
|
|
26
42
|
// src/useAsyncState.ts
|
|
27
|
-
import { useEffect as useEffect2, useState } from "react";
|
|
43
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
28
44
|
var useAsyncState = (cb, deps = []) => {
|
|
29
|
-
const [value, setValue] =
|
|
45
|
+
const [value, setValue] = useState2();
|
|
30
46
|
useEffect2(() => {
|
|
31
47
|
let disposed = false;
|
|
32
48
|
const t = setTimeout(async () => {
|
|
@@ -47,55 +63,102 @@ var useAsyncState = (cb, deps = []) => {
|
|
|
47
63
|
};
|
|
48
64
|
|
|
49
65
|
// src/useControlledState.ts
|
|
50
|
-
import { useEffect as
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
|
|
67
|
+
|
|
68
|
+
// src/useDynamicRef.ts
|
|
69
|
+
import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
70
|
+
var useStateWithRef = (valueProp) => {
|
|
71
|
+
const [value, setValue] = useState3(valueProp);
|
|
72
|
+
const valueRef = useRef(valueProp);
|
|
73
|
+
const setter = useCallback((value2) => {
|
|
74
|
+
if (typeof value2 === "function") {
|
|
75
|
+
setValue((current) => {
|
|
76
|
+
valueRef.current = value2(current);
|
|
77
|
+
return valueRef.current;
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
valueRef.current = value2;
|
|
81
|
+
setValue(value2);
|
|
56
82
|
}
|
|
83
|
+
}, []);
|
|
84
|
+
return [
|
|
85
|
+
value,
|
|
86
|
+
setter,
|
|
87
|
+
valueRef
|
|
88
|
+
];
|
|
89
|
+
};
|
|
90
|
+
var useDynamicRef = (value) => {
|
|
91
|
+
const valueRef = useRef(value);
|
|
92
|
+
useEffect3(() => {
|
|
93
|
+
valueRef.current = value;
|
|
57
94
|
}, [
|
|
58
|
-
|
|
59
|
-
...deps
|
|
95
|
+
value
|
|
60
96
|
]);
|
|
61
|
-
|
|
62
|
-
|
|
97
|
+
return valueRef;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/useControlledState.ts
|
|
101
|
+
var useControlledState = (valueProp, onChange) => {
|
|
102
|
+
const [value, setControlledValue] = useState4(valueProp);
|
|
103
|
+
useEffect4(() => {
|
|
104
|
+
setControlledValue(valueProp);
|
|
63
105
|
}, [
|
|
64
|
-
|
|
65
|
-
|
|
106
|
+
valueProp
|
|
107
|
+
]);
|
|
108
|
+
const onChangeRef = useRef2(onChange);
|
|
109
|
+
const valueRef = useDynamicRef(valueProp);
|
|
110
|
+
const setValue = useCallback2((nextValue) => {
|
|
111
|
+
const value2 = isFunction(nextValue) ? nextValue(valueRef.current) : nextValue;
|
|
112
|
+
setControlledValue(value2);
|
|
113
|
+
onChangeRef.current?.(value2);
|
|
114
|
+
}, [
|
|
115
|
+
valueRef,
|
|
116
|
+
onChangeRef
|
|
66
117
|
]);
|
|
67
118
|
return [
|
|
68
119
|
value,
|
|
69
120
|
setValue
|
|
70
121
|
];
|
|
71
122
|
};
|
|
123
|
+
function isFunction(value) {
|
|
124
|
+
return typeof value === "function";
|
|
125
|
+
}
|
|
72
126
|
|
|
73
|
-
// src/
|
|
74
|
-
import { useEffect as
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
127
|
+
// src/useDebugDeps.ts
|
|
128
|
+
import { useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
129
|
+
import { log } from "@dxos/log";
|
|
130
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-primitives/react-hooks/src/useDebugDeps.ts";
|
|
131
|
+
var useDebugDeps = (deps = [], label = "useDebugDeps", active = true) => {
|
|
132
|
+
const lastDeps = useRef3([]);
|
|
133
|
+
useEffect5(() => {
|
|
134
|
+
if (!active) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const diff = {};
|
|
82
138
|
for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
139
|
+
if (lastDeps.current[i] !== deps[i] || i > lastDeps.current.length) {
|
|
140
|
+
diff[i] = {
|
|
141
|
+
previous: lastDeps.current[i],
|
|
142
|
+
current: deps[i]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (Object.keys(diff).length > 0) {
|
|
147
|
+
log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 24, S: void 0 });
|
|
87
148
|
}
|
|
88
|
-
console.groupEnd();
|
|
89
149
|
lastDeps.current = deps;
|
|
90
|
-
},
|
|
150
|
+
}, [
|
|
151
|
+
...deps,
|
|
152
|
+
active
|
|
153
|
+
]);
|
|
91
154
|
};
|
|
92
155
|
|
|
93
156
|
// src/useDefaultValue.ts
|
|
94
|
-
import { useEffect as
|
|
157
|
+
import { useEffect as useEffect6, useMemo as useMemo2, useState as useState5 } from "react";
|
|
95
158
|
var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
96
|
-
const stableDefaultValue =
|
|
97
|
-
const [value, setValue] =
|
|
98
|
-
|
|
159
|
+
const stableDefaultValue = useMemo2(getDefaultValue, []);
|
|
160
|
+
const [value, setValue] = useState5(reactiveValue ?? stableDefaultValue);
|
|
161
|
+
useEffect6(() => {
|
|
99
162
|
setValue(reactiveValue ?? stableDefaultValue);
|
|
100
163
|
}, [
|
|
101
164
|
reactiveValue,
|
|
@@ -106,30 +169,18 @@ var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
|
106
169
|
|
|
107
170
|
// src/useDefaults.ts
|
|
108
171
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
109
|
-
import { useMemo as
|
|
172
|
+
import { useMemo as useMemo3 } from "react";
|
|
110
173
|
var useDefaults = (value, defaults) => {
|
|
111
|
-
return
|
|
174
|
+
return useMemo3(() => defaultsDeep({}, defaults, value), [
|
|
112
175
|
value,
|
|
113
176
|
defaults
|
|
114
177
|
]);
|
|
115
178
|
};
|
|
116
179
|
|
|
117
|
-
// src/useDynamicRef.ts
|
|
118
|
-
import { useEffect as useEffect6, useRef as useRef2 } from "react";
|
|
119
|
-
var useDynamicRef = (value) => {
|
|
120
|
-
const ref = useRef2(value);
|
|
121
|
-
useEffect6(() => {
|
|
122
|
-
ref.current = value;
|
|
123
|
-
}, [
|
|
124
|
-
value
|
|
125
|
-
]);
|
|
126
|
-
return ref;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
180
|
// src/useFileDownload.ts
|
|
130
|
-
import { useMemo as
|
|
181
|
+
import { useMemo as useMemo4 } from "react";
|
|
131
182
|
var useFileDownload = () => {
|
|
132
|
-
return
|
|
183
|
+
return useMemo4(() => (data, filename) => {
|
|
133
184
|
const url = typeof data === "string" ? data : URL.createObjectURL(data);
|
|
134
185
|
const element = document.createElement("a");
|
|
135
186
|
element.setAttribute("href", url);
|
|
@@ -140,38 +191,61 @@ var useFileDownload = () => {
|
|
|
140
191
|
};
|
|
141
192
|
|
|
142
193
|
// src/useForwardedRef.ts
|
|
143
|
-
import {
|
|
144
|
-
var useForwardedRef = (
|
|
145
|
-
const
|
|
194
|
+
import { useEffect as useEffect7, useMemo as useMemo5, useRef as useRef4 } from "react";
|
|
195
|
+
var useForwardedRef = (forwardedRef) => {
|
|
196
|
+
const localRef = useRef4(null);
|
|
146
197
|
useEffect7(() => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
198
|
+
setRef(forwardedRef, localRef.current);
|
|
199
|
+
}, [
|
|
200
|
+
forwardedRef
|
|
201
|
+
]);
|
|
202
|
+
return localRef;
|
|
203
|
+
};
|
|
204
|
+
function setRef(ref, value) {
|
|
205
|
+
if (typeof ref === "function") {
|
|
206
|
+
return ref(value);
|
|
207
|
+
} else if (ref) {
|
|
208
|
+
ref.current = value;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
var mergeRefs = (refs) => {
|
|
212
|
+
return (value) => {
|
|
213
|
+
const cleanups = [];
|
|
214
|
+
for (const ref of refs) {
|
|
215
|
+
const cleanup = setRef(ref, value);
|
|
216
|
+
cleanups.push(typeof cleanup === "function" ? cleanup : () => setRef(ref, null));
|
|
154
217
|
}
|
|
155
|
-
|
|
156
|
-
|
|
218
|
+
return () => {
|
|
219
|
+
for (const cleanup of cleanups) {
|
|
220
|
+
cleanup();
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
var useMergeRefs = (refs) => {
|
|
226
|
+
return useMemo5(() => mergeRefs(refs), [
|
|
227
|
+
...refs
|
|
228
|
+
]);
|
|
157
229
|
};
|
|
158
230
|
|
|
159
231
|
// src/useId.ts
|
|
160
232
|
import alea from "alea";
|
|
161
|
-
import { useMemo as
|
|
233
|
+
import { useMemo as useMemo6 } from "react";
|
|
162
234
|
var Alea = alea;
|
|
163
235
|
var prng = new Alea("@dxos/react-hooks");
|
|
164
236
|
var randomString = (n = 4) => prng().toString(16).slice(2, n + 2);
|
|
165
|
-
var useId = (namespace, propsId, opts) =>
|
|
166
|
-
propsId
|
|
167
|
-
|
|
237
|
+
var useId = (namespace, propsId, opts) => {
|
|
238
|
+
return useMemo6(() => makeId(namespace, propsId, opts), [
|
|
239
|
+
propsId
|
|
240
|
+
]);
|
|
241
|
+
};
|
|
168
242
|
var makeId = (namespace, propsId, opts) => propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;
|
|
169
243
|
|
|
170
244
|
// src/useIsFocused.ts
|
|
171
|
-
import { useEffect as useEffect8, useRef as
|
|
245
|
+
import { useEffect as useEffect8, useRef as useRef5, useState as useState6 } from "react";
|
|
172
246
|
var useIsFocused = (inputRef) => {
|
|
173
|
-
const [isFocused, setIsFocused] =
|
|
174
|
-
const isFocusedRef =
|
|
247
|
+
const [isFocused, setIsFocused] = useState6(void 0);
|
|
248
|
+
const isFocusedRef = useRef5(isFocused);
|
|
175
249
|
isFocusedRef.current = isFocused;
|
|
176
250
|
useEffect8(() => {
|
|
177
251
|
const input = inputRef.current;
|
|
@@ -197,7 +271,7 @@ var useIsFocused = (inputRef) => {
|
|
|
197
271
|
};
|
|
198
272
|
|
|
199
273
|
// src/useMediaQuery.ts
|
|
200
|
-
import { useEffect as useEffect9, useState as
|
|
274
|
+
import { useEffect as useEffect9, useState as useState7 } from "react";
|
|
201
275
|
var breakpointMediaQueries = {
|
|
202
276
|
sm: "(min-width: 640px)",
|
|
203
277
|
md: "(min-width: 768px)",
|
|
@@ -206,7 +280,7 @@ var breakpointMediaQueries = {
|
|
|
206
280
|
"2xl": "(min-width: 1536px)"
|
|
207
281
|
};
|
|
208
282
|
var useMediaQuery = (query, options = {}) => {
|
|
209
|
-
const { ssr =
|
|
283
|
+
const { ssr = false, fallback } = options;
|
|
210
284
|
const queries = (Array.isArray(query) ? query : [
|
|
211
285
|
query
|
|
212
286
|
]).map((query2) => query2 in breakpointMediaQueries ? breakpointMediaQueries[query2] : query2);
|
|
@@ -214,7 +288,7 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
214
288
|
fallback
|
|
215
289
|
];
|
|
216
290
|
fallbackValues = fallbackValues.filter((v) => v != null);
|
|
217
|
-
const [value, setValue] =
|
|
291
|
+
const [value, setValue] = useState7(() => {
|
|
218
292
|
return queries.map((query2, index) => ({
|
|
219
293
|
media: query2,
|
|
220
294
|
matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query2).matches
|
|
@@ -262,9 +336,9 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
262
336
|
};
|
|
263
337
|
|
|
264
338
|
// src/useMulticastObservable.ts
|
|
265
|
-
import { useMemo as
|
|
339
|
+
import { useMemo as useMemo7, useSyncExternalStore } from "react";
|
|
266
340
|
var useMulticastObservable = (observable) => {
|
|
267
|
-
const subscribeFn =
|
|
341
|
+
const subscribeFn = useMemo7(() => (listener) => {
|
|
268
342
|
const subscription = observable.subscribe(listener);
|
|
269
343
|
return () => subscription.unsubscribe();
|
|
270
344
|
}, [
|
|
@@ -274,28 +348,28 @@ var useMulticastObservable = (observable) => {
|
|
|
274
348
|
};
|
|
275
349
|
|
|
276
350
|
// src/useRefCallback.ts
|
|
277
|
-
import { useState as
|
|
351
|
+
import { useState as useState8 } from "react";
|
|
278
352
|
var useRefCallback = () => {
|
|
279
|
-
const [value, setValue] =
|
|
353
|
+
const [value, setValue] = useState8(null);
|
|
280
354
|
return {
|
|
281
355
|
refCallback: (value2) => setValue(value2),
|
|
282
356
|
value
|
|
283
357
|
};
|
|
284
358
|
};
|
|
285
359
|
|
|
286
|
-
// src/
|
|
287
|
-
import { useLayoutEffect, useMemo as
|
|
288
|
-
var
|
|
289
|
-
const debouncedHandler =
|
|
360
|
+
// src/useViewportResize.ts
|
|
361
|
+
import { useLayoutEffect, useMemo as useMemo8 } from "react";
|
|
362
|
+
var useViewportResize = (cb, deps = [], delay = 800) => {
|
|
363
|
+
const debouncedHandler = useMemo8(() => {
|
|
290
364
|
let timeout;
|
|
291
365
|
return (event) => {
|
|
292
366
|
clearTimeout(timeout);
|
|
293
367
|
timeout = setTimeout(() => {
|
|
294
|
-
|
|
368
|
+
cb(event);
|
|
295
369
|
}, delay);
|
|
296
370
|
};
|
|
297
371
|
}, [
|
|
298
|
-
|
|
372
|
+
cb,
|
|
299
373
|
delay
|
|
300
374
|
]);
|
|
301
375
|
return useLayoutEffect(() => {
|
|
@@ -309,9 +383,9 @@ var useResize = (handler, deps = [], delay = 800) => {
|
|
|
309
383
|
};
|
|
310
384
|
|
|
311
385
|
// src/useTimeout.ts
|
|
312
|
-
import { useEffect as useEffect10, useRef as
|
|
386
|
+
import { useEffect as useEffect10, useRef as useRef6 } from "react";
|
|
313
387
|
var useTimeout = (callback, delay = 0, deps = []) => {
|
|
314
|
-
const callbackRef =
|
|
388
|
+
const callbackRef = useRef6(callback);
|
|
315
389
|
useEffect10(() => {
|
|
316
390
|
callbackRef.current = callback;
|
|
317
391
|
}, [
|
|
@@ -321,57 +395,48 @@ var useTimeout = (callback, delay = 0, deps = []) => {
|
|
|
321
395
|
if (delay == null) {
|
|
322
396
|
return;
|
|
323
397
|
}
|
|
324
|
-
const
|
|
325
|
-
return () => clearTimeout(
|
|
398
|
+
const t = setTimeout(() => callbackRef.current?.(), delay);
|
|
399
|
+
return () => clearTimeout(t);
|
|
326
400
|
}, [
|
|
327
401
|
delay,
|
|
328
402
|
...deps
|
|
329
403
|
]);
|
|
330
404
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (active) {
|
|
342
|
-
log2.info("props changed", {
|
|
343
|
-
componentName,
|
|
344
|
-
keys: changes.map(([key]) => key).join(","),
|
|
345
|
-
props: Object.fromEntries(changes.map(([key]) => [
|
|
346
|
-
key,
|
|
347
|
-
{
|
|
348
|
-
from: prevProps.current[key],
|
|
349
|
-
to: props[key]
|
|
350
|
-
}
|
|
351
|
-
]))
|
|
352
|
-
}, {
|
|
353
|
-
F: __dxlog_file,
|
|
354
|
-
L: 22,
|
|
355
|
-
S: void 0,
|
|
356
|
-
C: (f, a) => f(...a)
|
|
357
|
-
});
|
|
358
|
-
}
|
|
405
|
+
var useInterval = (callback, delay = 0, deps = []) => {
|
|
406
|
+
const callbackRef = useRef6(callback);
|
|
407
|
+
useEffect10(() => {
|
|
408
|
+
callbackRef.current = callback;
|
|
409
|
+
}, [
|
|
410
|
+
callback
|
|
411
|
+
]);
|
|
412
|
+
useEffect10(() => {
|
|
413
|
+
if (delay == null) {
|
|
414
|
+
return;
|
|
359
415
|
}
|
|
360
|
-
|
|
361
|
-
|
|
416
|
+
const i = setInterval(async () => {
|
|
417
|
+
const result = await callbackRef.current?.();
|
|
418
|
+
if (result === false) {
|
|
419
|
+
clearInterval(i);
|
|
420
|
+
}
|
|
421
|
+
}, delay);
|
|
422
|
+
return () => clearInterval(i);
|
|
423
|
+
}, [
|
|
424
|
+
delay,
|
|
425
|
+
...deps
|
|
426
|
+
]);
|
|
362
427
|
};
|
|
363
428
|
|
|
364
429
|
// src/useTransitions.ts
|
|
365
|
-
import {
|
|
366
|
-
var
|
|
430
|
+
import { useEffect as useEffect11, useRef as useRef7, useState as useState9 } from "react";
|
|
431
|
+
var isFunction2 = (functionToCheck) => {
|
|
367
432
|
return functionToCheck instanceof Function;
|
|
368
433
|
};
|
|
369
434
|
var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
370
|
-
const [hasTransitioned, setHasTransitioned] =
|
|
435
|
+
const [hasTransitioned, setHasTransitioned] = useState9(false);
|
|
371
436
|
const previousValue = useRef7(currentValue);
|
|
372
|
-
|
|
373
|
-
const toValueValid =
|
|
374
|
-
const fromValueValid =
|
|
437
|
+
useEffect11(() => {
|
|
438
|
+
const toValueValid = isFunction2(toValue) ? toValue(currentValue) : toValue === currentValue;
|
|
439
|
+
const fromValueValid = isFunction2(fromValue) ? fromValue(previousValue.current) : fromValue === previousValue.current;
|
|
375
440
|
if (fromValueValid && toValueValid && !hasTransitioned) {
|
|
376
441
|
setHasTransitioned(true);
|
|
377
442
|
} else if ((!fromValueValid || !toValueValid) && hasTransitioned) {
|
|
@@ -389,13 +454,13 @@ var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
|
389
454
|
var useOnTransition = (currentValue, fromValue, toValue, callback) => {
|
|
390
455
|
const dirty = useRef7(false);
|
|
391
456
|
const hasTransitioned = useDidTransition(currentValue, fromValue, toValue);
|
|
392
|
-
|
|
457
|
+
useEffect11(() => {
|
|
393
458
|
dirty.current = false;
|
|
394
459
|
}, [
|
|
395
460
|
currentValue,
|
|
396
461
|
dirty
|
|
397
462
|
]);
|
|
398
|
-
|
|
463
|
+
useEffect11(() => {
|
|
399
464
|
if (hasTransitioned && !dirty.current) {
|
|
400
465
|
callback();
|
|
401
466
|
dirty.current = true;
|
|
@@ -408,11 +473,15 @@ var useOnTransition = (currentValue, fromValue, toValue, callback) => {
|
|
|
408
473
|
};
|
|
409
474
|
export {
|
|
410
475
|
makeId,
|
|
476
|
+
mergeRefs,
|
|
411
477
|
randomString,
|
|
478
|
+
setRef,
|
|
412
479
|
useAsyncEffect,
|
|
413
480
|
useAsyncState,
|
|
481
|
+
useAtomState,
|
|
482
|
+
useComposedRefs,
|
|
414
483
|
useControlledState,
|
|
415
|
-
|
|
484
|
+
useDebugDeps,
|
|
416
485
|
useDefaultValue,
|
|
417
486
|
useDefaults,
|
|
418
487
|
useDidTransition,
|
|
@@ -420,13 +489,17 @@ export {
|
|
|
420
489
|
useFileDownload,
|
|
421
490
|
useForwardedRef,
|
|
422
491
|
useId,
|
|
492
|
+
useInterval,
|
|
423
493
|
useIsFocused,
|
|
424
494
|
useMediaQuery,
|
|
495
|
+
useMergeRefs,
|
|
425
496
|
useMulticastObservable,
|
|
426
497
|
useOnTransition,
|
|
427
498
|
useRefCallback,
|
|
428
|
-
|
|
499
|
+
useScroller,
|
|
500
|
+
useSize,
|
|
501
|
+
useStateWithRef,
|
|
429
502
|
useTimeout,
|
|
430
|
-
|
|
503
|
+
useViewportResize
|
|
431
504
|
};
|
|
432
505
|
//# sourceMappingURL=index.mjs.map
|