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