@dxos/react-hooks 0.8.4-main.72ec0f3 → 0.8.4-main.765dc60934
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 +100 -93
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +100 -93
- 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 +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- 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 -2
- package/dist/types/src/useControlledState.d.ts.map +1 -1
- package/dist/types/src/useDebugDeps.d.ts +1 -1
- package/dist/types/src/useDebugDeps.d.ts.map +1 -1
- 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 +1 -1
- package/dist/types/src/useDynamicRef.d.ts.map +1 -1
- 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.map +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/useTimeout.d.ts.map +1 -1
- package/dist/types/src/useTransitions.d.ts.map +1 -1
- package/dist/types/src/useViewportResize.d.ts +1 -1
- package/dist/types/src/useViewportResize.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -16
- package/src/index.ts +4 -3
- package/src/useAtomState.ts +23 -0
- package/src/useControlledState.ts +6 -6
- package/src/useDebugDeps.ts +17 -8
- package/src/useDynamicRef.ts +4 -5
- package/src/useForwardedRef.ts +4 -2
- package/src/useId.ts +3 -2
- package/src/useIsFocused.ts +1 -1
- package/src/useMulticastObservable.test.ts +1 -1
- package/src/useViewportResize.ts +3 -3
- package/dist/types/src/useSignals.d.ts +0 -10
- package/dist/types/src/useSignals.d.ts.map +0 -1
- package/src/useSignals.ts +0 -27
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,3 +1,7 @@
|
|
|
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
7
|
var useAsyncEffect = (cb, deps) => {
|
|
@@ -17,10 +21,28 @@ var useAsyncEffect = (cb, deps) => {
|
|
|
17
21
|
}, deps ?? []);
|
|
18
22
|
};
|
|
19
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
|
+
]);
|
|
40
|
+
};
|
|
41
|
+
|
|
20
42
|
// src/useAsyncState.ts
|
|
21
|
-
import { useEffect as useEffect2, useState } from "react";
|
|
43
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
22
44
|
var useAsyncState = (cb, deps = []) => {
|
|
23
|
-
const [value, setValue] =
|
|
45
|
+
const [value, setValue] = useState2();
|
|
24
46
|
useEffect2(() => {
|
|
25
47
|
let disposed = false;
|
|
26
48
|
const t = setTimeout(async () => {
|
|
@@ -41,14 +63,13 @@ var useAsyncState = (cb, deps = []) => {
|
|
|
41
63
|
};
|
|
42
64
|
|
|
43
65
|
// src/useControlledState.ts
|
|
44
|
-
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as
|
|
66
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
|
|
45
67
|
|
|
46
68
|
// src/useDynamicRef.ts
|
|
47
|
-
import { useCallback } from "
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const valueRef = useRef(valueParam);
|
|
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);
|
|
52
73
|
const setter = useCallback((value2) => {
|
|
53
74
|
if (typeof value2 === "function") {
|
|
54
75
|
setValue((current) => {
|
|
@@ -77,15 +98,15 @@ var useDynamicRef = (value) => {
|
|
|
77
98
|
};
|
|
78
99
|
|
|
79
100
|
// src/useControlledState.ts
|
|
80
|
-
var useControlledState = (
|
|
81
|
-
const [value, setControlledValue] =
|
|
101
|
+
var useControlledState = (valueProp, onChange) => {
|
|
102
|
+
const [value, setControlledValue] = useState4(valueProp);
|
|
82
103
|
useEffect4(() => {
|
|
83
|
-
setControlledValue(
|
|
104
|
+
setControlledValue(valueProp);
|
|
84
105
|
}, [
|
|
85
|
-
|
|
106
|
+
valueProp
|
|
86
107
|
]);
|
|
87
108
|
const onChangeRef = useRef2(onChange);
|
|
88
|
-
const valueRef = useDynamicRef(
|
|
109
|
+
const valueRef = useDynamicRef(valueProp);
|
|
89
110
|
const setValue = useCallback2((nextValue) => {
|
|
90
111
|
const value2 = isFunction(nextValue) ? nextValue(valueRef.current) : nextValue;
|
|
91
112
|
setControlledValue(value2);
|
|
@@ -105,32 +126,38 @@ function isFunction(value) {
|
|
|
105
126
|
|
|
106
127
|
// src/useDebugDeps.ts
|
|
107
128
|
import { useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
108
|
-
|
|
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) => {
|
|
109
132
|
const lastDeps = useRef3([]);
|
|
110
133
|
useEffect5(() => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
134
|
+
if (!active) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const diff = {};
|
|
115
138
|
for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {
|
|
116
|
-
if (lastDeps.current[i] !== deps[i]
|
|
117
|
-
|
|
118
|
-
index: i,
|
|
139
|
+
if (lastDeps.current[i] !== deps[i] || i > lastDeps.current.length) {
|
|
140
|
+
diff[i] = {
|
|
119
141
|
previous: lastDeps.current[i],
|
|
120
142
|
current: deps[i]
|
|
121
|
-
}
|
|
143
|
+
};
|
|
122
144
|
}
|
|
123
145
|
}
|
|
124
|
-
|
|
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 });
|
|
148
|
+
}
|
|
125
149
|
lastDeps.current = deps;
|
|
126
|
-
},
|
|
150
|
+
}, [
|
|
151
|
+
...deps,
|
|
152
|
+
active
|
|
153
|
+
]);
|
|
127
154
|
};
|
|
128
155
|
|
|
129
156
|
// src/useDefaultValue.ts
|
|
130
|
-
import { useEffect as useEffect6, useMemo, useState as
|
|
157
|
+
import { useEffect as useEffect6, useMemo as useMemo2, useState as useState5 } from "react";
|
|
131
158
|
var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
132
|
-
const stableDefaultValue =
|
|
133
|
-
const [value, setValue] =
|
|
159
|
+
const stableDefaultValue = useMemo2(getDefaultValue, []);
|
|
160
|
+
const [value, setValue] = useState5(reactiveValue ?? stableDefaultValue);
|
|
134
161
|
useEffect6(() => {
|
|
135
162
|
setValue(reactiveValue ?? stableDefaultValue);
|
|
136
163
|
}, [
|
|
@@ -142,18 +169,18 @@ var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
|
142
169
|
|
|
143
170
|
// src/useDefaults.ts
|
|
144
171
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
145
|
-
import { useMemo as
|
|
172
|
+
import { useMemo as useMemo3 } from "react";
|
|
146
173
|
var useDefaults = (value, defaults) => {
|
|
147
|
-
return
|
|
174
|
+
return useMemo3(() => defaultsDeep({}, defaults, value), [
|
|
148
175
|
value,
|
|
149
176
|
defaults
|
|
150
177
|
]);
|
|
151
178
|
};
|
|
152
179
|
|
|
153
180
|
// src/useFileDownload.ts
|
|
154
|
-
import { useMemo as
|
|
181
|
+
import { useMemo as useMemo4 } from "react";
|
|
155
182
|
var useFileDownload = () => {
|
|
156
|
-
return
|
|
183
|
+
return useMemo4(() => (data, filename) => {
|
|
157
184
|
const url = typeof data === "string" ? data : URL.createObjectURL(data);
|
|
158
185
|
const element = document.createElement("a");
|
|
159
186
|
element.setAttribute("href", url);
|
|
@@ -164,7 +191,7 @@ var useFileDownload = () => {
|
|
|
164
191
|
};
|
|
165
192
|
|
|
166
193
|
// src/useForwardedRef.ts
|
|
167
|
-
import { useEffect as useEffect7, useMemo as
|
|
194
|
+
import { useEffect as useEffect7, useMemo as useMemo5, useRef as useRef4 } from "react";
|
|
168
195
|
var useForwardedRef = (forwardedRef) => {
|
|
169
196
|
const localRef = useRef4(null);
|
|
170
197
|
useEffect7(() => {
|
|
@@ -189,29 +216,35 @@ var mergeRefs = (refs) => {
|
|
|
189
216
|
cleanups.push(typeof cleanup === "function" ? cleanup : () => setRef(ref, null));
|
|
190
217
|
}
|
|
191
218
|
return () => {
|
|
192
|
-
for (const cleanup of cleanups)
|
|
219
|
+
for (const cleanup of cleanups) {
|
|
220
|
+
cleanup();
|
|
221
|
+
}
|
|
193
222
|
};
|
|
194
223
|
};
|
|
195
224
|
};
|
|
196
225
|
var useMergeRefs = (refs) => {
|
|
197
|
-
return
|
|
226
|
+
return useMemo5(() => mergeRefs(refs), [
|
|
227
|
+
...refs
|
|
228
|
+
]);
|
|
198
229
|
};
|
|
199
230
|
|
|
200
231
|
// src/useId.ts
|
|
201
232
|
import alea from "alea";
|
|
202
|
-
import { useMemo as
|
|
233
|
+
import { useMemo as useMemo6 } from "react";
|
|
203
234
|
var Alea = alea;
|
|
204
235
|
var prng = new Alea("@dxos/react-hooks");
|
|
205
236
|
var randomString = (n = 4) => prng().toString(16).slice(2, n + 2);
|
|
206
|
-
var useId = (namespace, propsId, opts) =>
|
|
207
|
-
propsId
|
|
208
|
-
|
|
237
|
+
var useId = (namespace, propsId, opts) => {
|
|
238
|
+
return useMemo6(() => makeId(namespace, propsId, opts), [
|
|
239
|
+
propsId
|
|
240
|
+
]);
|
|
241
|
+
};
|
|
209
242
|
var makeId = (namespace, propsId, opts) => propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;
|
|
210
243
|
|
|
211
244
|
// src/useIsFocused.ts
|
|
212
|
-
import { useEffect as useEffect8, useRef as useRef5, useState as
|
|
245
|
+
import { useEffect as useEffect8, useRef as useRef5, useState as useState6 } from "react";
|
|
213
246
|
var useIsFocused = (inputRef) => {
|
|
214
|
-
const [isFocused, setIsFocused] =
|
|
247
|
+
const [isFocused, setIsFocused] = useState6(void 0);
|
|
215
248
|
const isFocusedRef = useRef5(isFocused);
|
|
216
249
|
isFocusedRef.current = isFocused;
|
|
217
250
|
useEffect8(() => {
|
|
@@ -238,7 +271,7 @@ var useIsFocused = (inputRef) => {
|
|
|
238
271
|
};
|
|
239
272
|
|
|
240
273
|
// src/useMediaQuery.ts
|
|
241
|
-
import { useEffect as useEffect9, useState as
|
|
274
|
+
import { useEffect as useEffect9, useState as useState7 } from "react";
|
|
242
275
|
var breakpointMediaQueries = {
|
|
243
276
|
sm: "(min-width: 640px)",
|
|
244
277
|
md: "(min-width: 768px)",
|
|
@@ -255,7 +288,7 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
255
288
|
fallback
|
|
256
289
|
];
|
|
257
290
|
fallbackValues = fallbackValues.filter((v) => v != null);
|
|
258
|
-
const [value, setValue] =
|
|
291
|
+
const [value, setValue] = useState7(() => {
|
|
259
292
|
return queries.map((query2, index) => ({
|
|
260
293
|
media: query2,
|
|
261
294
|
matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query2).matches
|
|
@@ -303,9 +336,9 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
303
336
|
};
|
|
304
337
|
|
|
305
338
|
// src/useMulticastObservable.ts
|
|
306
|
-
import { useMemo as
|
|
339
|
+
import { useMemo as useMemo7, useSyncExternalStore } from "react";
|
|
307
340
|
var useMulticastObservable = (observable) => {
|
|
308
|
-
const subscribeFn =
|
|
341
|
+
const subscribeFn = useMemo7(() => (listener) => {
|
|
309
342
|
const subscription = observable.subscribe(listener);
|
|
310
343
|
return () => subscription.unsubscribe();
|
|
311
344
|
}, [
|
|
@@ -315,9 +348,9 @@ var useMulticastObservable = (observable) => {
|
|
|
315
348
|
};
|
|
316
349
|
|
|
317
350
|
// src/useRefCallback.ts
|
|
318
|
-
import { useState as
|
|
351
|
+
import { useState as useState8 } from "react";
|
|
319
352
|
var useRefCallback = () => {
|
|
320
|
-
const [value, setValue] =
|
|
353
|
+
const [value, setValue] = useState8(null);
|
|
321
354
|
return {
|
|
322
355
|
refCallback: (value2) => setValue(value2),
|
|
323
356
|
value
|
|
@@ -325,18 +358,18 @@ var useRefCallback = () => {
|
|
|
325
358
|
};
|
|
326
359
|
|
|
327
360
|
// src/useViewportResize.ts
|
|
328
|
-
import { useLayoutEffect, useMemo as
|
|
329
|
-
var useViewportResize = (
|
|
330
|
-
const debouncedHandler =
|
|
361
|
+
import { useLayoutEffect, useMemo as useMemo8 } from "react";
|
|
362
|
+
var useViewportResize = (cb, deps = [], delay = 800) => {
|
|
363
|
+
const debouncedHandler = useMemo8(() => {
|
|
331
364
|
let timeout;
|
|
332
365
|
return (event) => {
|
|
333
366
|
clearTimeout(timeout);
|
|
334
367
|
timeout = setTimeout(() => {
|
|
335
|
-
|
|
368
|
+
cb(event);
|
|
336
369
|
}, delay);
|
|
337
370
|
};
|
|
338
371
|
}, [
|
|
339
|
-
|
|
372
|
+
cb,
|
|
340
373
|
delay
|
|
341
374
|
]);
|
|
342
375
|
return useLayoutEffect(() => {
|
|
@@ -349,39 +382,16 @@ var useViewportResize = (handler, deps = [], delay = 800) => {
|
|
|
349
382
|
]);
|
|
350
383
|
};
|
|
351
384
|
|
|
352
|
-
// src/useSignals.ts
|
|
353
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
354
|
-
import { computed, effect } from "@preact-signals/safe-react";
|
|
355
|
-
import { useRef as useRef6 } from "@preact-signals/safe-react/react";
|
|
356
|
-
import { useEffect as useEffect10, useMemo as useMemo8 } from "react";
|
|
357
|
-
var useSignalsEffect = (cb, deps) => {
|
|
358
|
-
const callback = useRef6(cb);
|
|
359
|
-
callback.current = cb;
|
|
360
|
-
useEffect10(() => {
|
|
361
|
-
return effect(() => {
|
|
362
|
-
return callback.current();
|
|
363
|
-
});
|
|
364
|
-
}, deps ?? []);
|
|
365
|
-
};
|
|
366
|
-
var useSignalsMemo = (cb, deps) => {
|
|
367
|
-
var _effect = _useSignals();
|
|
368
|
-
try {
|
|
369
|
-
return useMemo8(() => computed(cb), deps ?? []).value;
|
|
370
|
-
} finally {
|
|
371
|
-
_effect.f();
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
385
|
// src/useTimeout.ts
|
|
376
|
-
import { useEffect as
|
|
386
|
+
import { useEffect as useEffect10, useRef as useRef6 } from "react";
|
|
377
387
|
var useTimeout = (callback, delay = 0, deps = []) => {
|
|
378
|
-
const callbackRef =
|
|
379
|
-
|
|
388
|
+
const callbackRef = useRef6(callback);
|
|
389
|
+
useEffect10(() => {
|
|
380
390
|
callbackRef.current = callback;
|
|
381
391
|
}, [
|
|
382
392
|
callback
|
|
383
393
|
]);
|
|
384
|
-
|
|
394
|
+
useEffect10(() => {
|
|
385
395
|
if (delay == null) {
|
|
386
396
|
return;
|
|
387
397
|
}
|
|
@@ -393,13 +403,13 @@ var useTimeout = (callback, delay = 0, deps = []) => {
|
|
|
393
403
|
]);
|
|
394
404
|
};
|
|
395
405
|
var useInterval = (callback, delay = 0, deps = []) => {
|
|
396
|
-
const callbackRef =
|
|
397
|
-
|
|
406
|
+
const callbackRef = useRef6(callback);
|
|
407
|
+
useEffect10(() => {
|
|
398
408
|
callbackRef.current = callback;
|
|
399
409
|
}, [
|
|
400
410
|
callback
|
|
401
411
|
]);
|
|
402
|
-
|
|
412
|
+
useEffect10(() => {
|
|
403
413
|
if (delay == null) {
|
|
404
414
|
return;
|
|
405
415
|
}
|
|
@@ -417,14 +427,14 @@ var useInterval = (callback, delay = 0, deps = []) => {
|
|
|
417
427
|
};
|
|
418
428
|
|
|
419
429
|
// src/useTransitions.ts
|
|
420
|
-
import { useEffect as
|
|
430
|
+
import { useEffect as useEffect11, useRef as useRef7, useState as useState9 } from "react";
|
|
421
431
|
var isFunction2 = (functionToCheck) => {
|
|
422
432
|
return functionToCheck instanceof Function;
|
|
423
433
|
};
|
|
424
434
|
var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
425
|
-
const [hasTransitioned, setHasTransitioned] =
|
|
426
|
-
const previousValue =
|
|
427
|
-
|
|
435
|
+
const [hasTransitioned, setHasTransitioned] = useState9(false);
|
|
436
|
+
const previousValue = useRef7(currentValue);
|
|
437
|
+
useEffect11(() => {
|
|
428
438
|
const toValueValid = isFunction2(toValue) ? toValue(currentValue) : toValue === currentValue;
|
|
429
439
|
const fromValueValid = isFunction2(fromValue) ? fromValue(previousValue.current) : fromValue === previousValue.current;
|
|
430
440
|
if (fromValueValid && toValueValid && !hasTransitioned) {
|
|
@@ -442,15 +452,15 @@ var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
|
442
452
|
return hasTransitioned;
|
|
443
453
|
};
|
|
444
454
|
var useOnTransition = (currentValue, fromValue, toValue, callback) => {
|
|
445
|
-
const dirty =
|
|
455
|
+
const dirty = useRef7(false);
|
|
446
456
|
const hasTransitioned = useDidTransition(currentValue, fromValue, toValue);
|
|
447
|
-
|
|
457
|
+
useEffect11(() => {
|
|
448
458
|
dirty.current = false;
|
|
449
459
|
}, [
|
|
450
460
|
currentValue,
|
|
451
461
|
dirty
|
|
452
462
|
]);
|
|
453
|
-
|
|
463
|
+
useEffect11(() => {
|
|
454
464
|
if (hasTransitioned && !dirty.current) {
|
|
455
465
|
callback();
|
|
456
466
|
dirty.current = true;
|
|
@@ -461,9 +471,6 @@ var useOnTransition = (currentValue, fromValue, toValue, callback) => {
|
|
|
461
471
|
callback
|
|
462
472
|
]);
|
|
463
473
|
};
|
|
464
|
-
|
|
465
|
-
// src/index.ts
|
|
466
|
-
import { useSize, useScroller } from "mini-virtual-list";
|
|
467
474
|
export {
|
|
468
475
|
makeId,
|
|
469
476
|
mergeRefs,
|
|
@@ -471,6 +478,8 @@ export {
|
|
|
471
478
|
setRef,
|
|
472
479
|
useAsyncEffect,
|
|
473
480
|
useAsyncState,
|
|
481
|
+
useAtomState,
|
|
482
|
+
useComposedRefs,
|
|
474
483
|
useControlledState,
|
|
475
484
|
useDebugDeps,
|
|
476
485
|
useDefaultValue,
|
|
@@ -488,8 +497,6 @@ export {
|
|
|
488
497
|
useOnTransition,
|
|
489
498
|
useRefCallback,
|
|
490
499
|
useScroller,
|
|
491
|
-
useSignalsEffect,
|
|
492
|
-
useSignalsMemo,
|
|
493
500
|
useSize,
|
|
494
501
|
useStateWithRef,
|
|
495
502
|
useTimeout,
|