@dxos/react-hooks 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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 +240 -136
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +240 -136
- 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 +7 -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 -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 +19 -15
- package/src/index.ts +6 -3
- package/src/useAsyncEffect.ts +24 -6
- package/src/useAtomState.ts +23 -0
- package/src/useControlledState.ts +22 -11
- package/src/useDebugDeps.ts +35 -0
- package/src/useDynamicRef.ts +26 -5
- package/src/useForwardedRef.ts +50 -13
- package/src/useId.ts +3 -2
- package/src/useIsFocused.ts +2 -2
- 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 +3 -1
- package/src/useViewportResize.ts +52 -0
- 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/useDebugReactDeps.ts +0 -27
- package/src/useResize.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,18 +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
|
-
var useAsyncEffect = (
|
|
7
|
+
var useAsyncEffect = (cb, deps) => {
|
|
4
8
|
useEffect(() => {
|
|
5
|
-
const
|
|
6
|
-
|
|
9
|
+
const controller = new AbortController();
|
|
10
|
+
let cleanup;
|
|
11
|
+
const t = setTimeout(async () => {
|
|
12
|
+
if (!controller.signal.aborted) {
|
|
13
|
+
cleanup = await cb(controller);
|
|
14
|
+
}
|
|
7
15
|
});
|
|
8
|
-
return () =>
|
|
9
|
-
|
|
16
|
+
return () => {
|
|
17
|
+
clearTimeout(t);
|
|
18
|
+
controller.abort();
|
|
19
|
+
cleanup?.();
|
|
20
|
+
};
|
|
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
|
+
]);
|
|
10
40
|
};
|
|
11
41
|
|
|
12
42
|
// src/useAsyncState.ts
|
|
13
|
-
import { useEffect as useEffect2, useState } from "react";
|
|
43
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
14
44
|
var useAsyncState = (cb, deps = []) => {
|
|
15
|
-
const [value, setValue] =
|
|
45
|
+
const [value, setValue] = useState2();
|
|
16
46
|
useEffect2(() => {
|
|
17
47
|
let disposed = false;
|
|
18
48
|
const t = setTimeout(async () => {
|
|
@@ -33,55 +63,101 @@ var useAsyncState = (cb, deps = []) => {
|
|
|
33
63
|
};
|
|
34
64
|
|
|
35
65
|
// src/useControlledState.ts
|
|
36
|
-
import { useEffect as
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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);
|
|
42
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;
|
|
43
94
|
}, [
|
|
44
|
-
|
|
45
|
-
...deps
|
|
95
|
+
value
|
|
46
96
|
]);
|
|
47
|
-
|
|
48
|
-
|
|
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);
|
|
49
105
|
}, [
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
52
117
|
]);
|
|
53
118
|
return [
|
|
54
119
|
value,
|
|
55
120
|
setValue
|
|
56
121
|
];
|
|
57
122
|
};
|
|
123
|
+
function isFunction(value) {
|
|
124
|
+
return typeof value === "function";
|
|
125
|
+
}
|
|
58
126
|
|
|
59
|
-
// src/
|
|
60
|
-
import { useEffect as
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
127
|
+
// src/useDebugDeps.ts
|
|
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 = {};
|
|
68
137
|
for (let i = 0; i < Math.max(lastDeps.current.length ?? 0, deps.length ?? 0); i++) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
138
|
+
if (lastDeps.current[i] !== deps[i] || i > lastDeps.current.length) {
|
|
139
|
+
diff[i] = {
|
|
140
|
+
previous: lastDeps.current[i],
|
|
141
|
+
current: deps[i]
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (Object.keys(diff).length > 0) {
|
|
146
|
+
log.warn(`Updated: ${label} [${lastDeps.current.length}/${deps.length}]`, diff);
|
|
73
147
|
}
|
|
74
|
-
console.groupEnd();
|
|
75
148
|
lastDeps.current = deps;
|
|
76
|
-
},
|
|
149
|
+
}, [
|
|
150
|
+
...deps,
|
|
151
|
+
active
|
|
152
|
+
]);
|
|
77
153
|
};
|
|
78
154
|
|
|
79
155
|
// src/useDefaultValue.ts
|
|
80
|
-
import { useEffect as
|
|
156
|
+
import { useEffect as useEffect6, useMemo as useMemo2, useState as useState5 } from "react";
|
|
81
157
|
var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
82
|
-
const stableDefaultValue =
|
|
83
|
-
const [value, setValue] =
|
|
84
|
-
|
|
158
|
+
const stableDefaultValue = useMemo2(getDefaultValue, []);
|
|
159
|
+
const [value, setValue] = useState5(reactiveValue ?? stableDefaultValue);
|
|
160
|
+
useEffect6(() => {
|
|
85
161
|
setValue(reactiveValue ?? stableDefaultValue);
|
|
86
162
|
}, [
|
|
87
163
|
reactiveValue,
|
|
@@ -92,30 +168,18 @@ var useDefaultValue = (reactiveValue, getDefaultValue) => {
|
|
|
92
168
|
|
|
93
169
|
// src/useDefaults.ts
|
|
94
170
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
95
|
-
import { useMemo as
|
|
171
|
+
import { useMemo as useMemo3 } from "react";
|
|
96
172
|
var useDefaults = (value, defaults) => {
|
|
97
|
-
return
|
|
173
|
+
return useMemo3(() => defaultsDeep({}, defaults, value), [
|
|
98
174
|
value,
|
|
99
175
|
defaults
|
|
100
176
|
]);
|
|
101
177
|
};
|
|
102
178
|
|
|
103
|
-
// src/useDynamicRef.ts
|
|
104
|
-
import { useEffect as useEffect6, useRef as useRef2 } from "react";
|
|
105
|
-
var useDynamicRef = (value) => {
|
|
106
|
-
const ref = useRef2(value);
|
|
107
|
-
useEffect6(() => {
|
|
108
|
-
ref.current = value;
|
|
109
|
-
}, [
|
|
110
|
-
value
|
|
111
|
-
]);
|
|
112
|
-
return ref;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
179
|
// src/useFileDownload.ts
|
|
116
|
-
import { useMemo as
|
|
180
|
+
import { useMemo as useMemo4 } from "react";
|
|
117
181
|
var useFileDownload = () => {
|
|
118
|
-
return
|
|
182
|
+
return useMemo4(() => (data, filename) => {
|
|
119
183
|
const url = typeof data === "string" ? data : URL.createObjectURL(data);
|
|
120
184
|
const element = document.createElement("a");
|
|
121
185
|
element.setAttribute("href", url);
|
|
@@ -126,38 +190,61 @@ var useFileDownload = () => {
|
|
|
126
190
|
};
|
|
127
191
|
|
|
128
192
|
// src/useForwardedRef.ts
|
|
129
|
-
import { useEffect as useEffect7, useRef as
|
|
130
|
-
var useForwardedRef = (
|
|
131
|
-
const
|
|
193
|
+
import { useEffect as useEffect7, useMemo as useMemo5, useRef as useRef4 } from "react";
|
|
194
|
+
var useForwardedRef = (forwardedRef) => {
|
|
195
|
+
const localRef = useRef4(null);
|
|
132
196
|
useEffect7(() => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
197
|
+
setRef(forwardedRef, localRef.current);
|
|
198
|
+
}, [
|
|
199
|
+
forwardedRef
|
|
200
|
+
]);
|
|
201
|
+
return localRef;
|
|
202
|
+
};
|
|
203
|
+
function setRef(ref, value) {
|
|
204
|
+
if (typeof ref === "function") {
|
|
205
|
+
return ref(value);
|
|
206
|
+
} else if (ref) {
|
|
207
|
+
ref.current = value;
|
|
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));
|
|
140
216
|
}
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
]);
|
|
143
228
|
};
|
|
144
229
|
|
|
145
230
|
// src/useId.ts
|
|
146
231
|
import alea from "alea";
|
|
147
|
-
import { useMemo as
|
|
232
|
+
import { useMemo as useMemo6 } from "react";
|
|
148
233
|
var Alea = alea;
|
|
149
234
|
var prng = new Alea("@dxos/react-hooks");
|
|
150
235
|
var randomString = (n = 4) => prng().toString(16).slice(2, n + 2);
|
|
151
|
-
var useId = (namespace, propsId, opts) =>
|
|
152
|
-
propsId
|
|
153
|
-
|
|
236
|
+
var useId = (namespace, propsId, opts) => {
|
|
237
|
+
return useMemo6(() => makeId(namespace, propsId, opts), [
|
|
238
|
+
propsId
|
|
239
|
+
]);
|
|
240
|
+
};
|
|
154
241
|
var makeId = (namespace, propsId, opts) => propsId ?? `${namespace}-${randomString(opts?.n ?? 4)}`;
|
|
155
242
|
|
|
156
243
|
// src/useIsFocused.ts
|
|
157
|
-
import { useEffect as useEffect8, useRef as
|
|
244
|
+
import { useEffect as useEffect8, useRef as useRef5, useState as useState6 } from "react";
|
|
158
245
|
var useIsFocused = (inputRef) => {
|
|
159
|
-
const [isFocused, setIsFocused] =
|
|
160
|
-
const isFocusedRef =
|
|
246
|
+
const [isFocused, setIsFocused] = useState6(void 0);
|
|
247
|
+
const isFocusedRef = useRef5(isFocused);
|
|
161
248
|
isFocusedRef.current = isFocused;
|
|
162
249
|
useEffect8(() => {
|
|
163
250
|
const input = inputRef.current;
|
|
@@ -183,7 +270,7 @@ var useIsFocused = (inputRef) => {
|
|
|
183
270
|
};
|
|
184
271
|
|
|
185
272
|
// src/useMediaQuery.ts
|
|
186
|
-
import { useEffect as useEffect9, useState as
|
|
273
|
+
import { useEffect as useEffect9, useState as useState7 } from "react";
|
|
187
274
|
var breakpointMediaQueries = {
|
|
188
275
|
sm: "(min-width: 640px)",
|
|
189
276
|
md: "(min-width: 768px)",
|
|
@@ -192,7 +279,7 @@ var breakpointMediaQueries = {
|
|
|
192
279
|
"2xl": "(min-width: 1536px)"
|
|
193
280
|
};
|
|
194
281
|
var useMediaQuery = (query, options = {}) => {
|
|
195
|
-
const { ssr =
|
|
282
|
+
const { ssr = false, fallback } = options;
|
|
196
283
|
const queries = (Array.isArray(query) ? query : [
|
|
197
284
|
query
|
|
198
285
|
]).map((query2) => query2 in breakpointMediaQueries ? breakpointMediaQueries[query2] : query2);
|
|
@@ -200,7 +287,7 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
200
287
|
fallback
|
|
201
288
|
];
|
|
202
289
|
fallbackValues = fallbackValues.filter((v) => v != null);
|
|
203
|
-
const [value, setValue] =
|
|
290
|
+
const [value, setValue] = useState7(() => {
|
|
204
291
|
return queries.map((query2, index) => ({
|
|
205
292
|
media: query2,
|
|
206
293
|
matches: ssr ? !!fallbackValues[index] : document.defaultView?.matchMedia(query2).matches
|
|
@@ -248,9 +335,9 @@ var useMediaQuery = (query, options = {}) => {
|
|
|
248
335
|
};
|
|
249
336
|
|
|
250
337
|
// src/useMulticastObservable.ts
|
|
251
|
-
import { useMemo as
|
|
338
|
+
import { useMemo as useMemo7, useSyncExternalStore } from "react";
|
|
252
339
|
var useMulticastObservable = (observable) => {
|
|
253
|
-
const subscribeFn =
|
|
340
|
+
const subscribeFn = useMemo7(() => (listener) => {
|
|
254
341
|
const subscription = observable.subscribe(listener);
|
|
255
342
|
return () => subscription.unsubscribe();
|
|
256
343
|
}, [
|
|
@@ -260,44 +347,62 @@ var useMulticastObservable = (observable) => {
|
|
|
260
347
|
};
|
|
261
348
|
|
|
262
349
|
// src/useRefCallback.ts
|
|
263
|
-
import { useState as
|
|
350
|
+
import { useState as useState8 } from "react";
|
|
264
351
|
var useRefCallback = () => {
|
|
265
|
-
const [value, setValue] =
|
|
352
|
+
const [value, setValue] = useState8(null);
|
|
266
353
|
return {
|
|
267
354
|
refCallback: (value2) => setValue(value2),
|
|
268
355
|
value
|
|
269
356
|
};
|
|
270
357
|
};
|
|
271
358
|
|
|
272
|
-
// src/
|
|
273
|
-
import { useLayoutEffect, useMemo as
|
|
274
|
-
var
|
|
275
|
-
const debouncedHandler =
|
|
359
|
+
// src/useViewportResize.ts
|
|
360
|
+
import { useLayoutEffect, useMemo as useMemo8 } from "react";
|
|
361
|
+
var useViewportResize = (cb, deps = [], delay = 800) => {
|
|
362
|
+
const { handler: debouncedHandler, cancel } = useMemo8(() => {
|
|
276
363
|
let timeout;
|
|
277
|
-
return
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
364
|
+
return {
|
|
365
|
+
handler: (event) => {
|
|
366
|
+
if (timeout !== void 0) {
|
|
367
|
+
clearTimeout(timeout);
|
|
368
|
+
}
|
|
369
|
+
timeout = setTimeout(() => {
|
|
370
|
+
timeout = void 0;
|
|
371
|
+
if (typeof document === "undefined" || typeof getComputedStyle === "undefined") {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
cb(event);
|
|
375
|
+
}, delay);
|
|
376
|
+
},
|
|
377
|
+
cancel: () => {
|
|
378
|
+
if (timeout !== void 0) {
|
|
379
|
+
clearTimeout(timeout);
|
|
380
|
+
timeout = void 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
282
383
|
};
|
|
283
384
|
}, [
|
|
284
|
-
|
|
385
|
+
cb,
|
|
285
386
|
delay
|
|
286
387
|
]);
|
|
287
388
|
return useLayoutEffect(() => {
|
|
288
389
|
window.visualViewport?.addEventListener("resize", debouncedHandler);
|
|
289
390
|
debouncedHandler();
|
|
290
|
-
return () =>
|
|
391
|
+
return () => {
|
|
392
|
+
window.visualViewport?.removeEventListener("resize", debouncedHandler);
|
|
393
|
+
cancel();
|
|
394
|
+
};
|
|
291
395
|
}, [
|
|
292
396
|
debouncedHandler,
|
|
397
|
+
cancel,
|
|
293
398
|
...deps
|
|
294
399
|
]);
|
|
295
400
|
};
|
|
296
401
|
|
|
297
402
|
// src/useTimeout.ts
|
|
298
|
-
import { useEffect as useEffect10, useRef as
|
|
403
|
+
import { useEffect as useEffect10, useRef as useRef6 } from "react";
|
|
299
404
|
var useTimeout = (callback, delay = 0, deps = []) => {
|
|
300
|
-
const callbackRef =
|
|
405
|
+
const callbackRef = useRef6(callback);
|
|
301
406
|
useEffect10(() => {
|
|
302
407
|
callbackRef.current = callback;
|
|
303
408
|
}, [
|
|
@@ -307,57 +412,48 @@ var useTimeout = (callback, delay = 0, deps = []) => {
|
|
|
307
412
|
if (delay == null) {
|
|
308
413
|
return;
|
|
309
414
|
}
|
|
310
|
-
const
|
|
311
|
-
return () => clearTimeout(
|
|
415
|
+
const t = setTimeout(() => callbackRef.current?.(), delay);
|
|
416
|
+
return () => clearTimeout(t);
|
|
312
417
|
}, [
|
|
313
418
|
delay,
|
|
314
419
|
...deps
|
|
315
420
|
]);
|
|
316
421
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (active) {
|
|
328
|
-
log.info("props changed", {
|
|
329
|
-
componentName,
|
|
330
|
-
keys: changes.map(([key]) => key).join(","),
|
|
331
|
-
props: Object.fromEntries(changes.map(([key]) => [
|
|
332
|
-
key,
|
|
333
|
-
{
|
|
334
|
-
from: prevProps.current[key],
|
|
335
|
-
to: props[key]
|
|
336
|
-
}
|
|
337
|
-
]))
|
|
338
|
-
}, {
|
|
339
|
-
F: __dxlog_file,
|
|
340
|
-
L: 22,
|
|
341
|
-
S: void 0,
|
|
342
|
-
C: (f, a) => f(...a)
|
|
343
|
-
});
|
|
344
|
-
}
|
|
422
|
+
var useInterval = (callback, delay = 0, deps = []) => {
|
|
423
|
+
const callbackRef = useRef6(callback);
|
|
424
|
+
useEffect10(() => {
|
|
425
|
+
callbackRef.current = callback;
|
|
426
|
+
}, [
|
|
427
|
+
callback
|
|
428
|
+
]);
|
|
429
|
+
useEffect10(() => {
|
|
430
|
+
if (delay == null) {
|
|
431
|
+
return;
|
|
345
432
|
}
|
|
346
|
-
|
|
347
|
-
|
|
433
|
+
const i = setInterval(async () => {
|
|
434
|
+
const result = await callbackRef.current?.();
|
|
435
|
+
if (result === false) {
|
|
436
|
+
clearInterval(i);
|
|
437
|
+
}
|
|
438
|
+
}, delay);
|
|
439
|
+
return () => clearInterval(i);
|
|
440
|
+
}, [
|
|
441
|
+
delay,
|
|
442
|
+
...deps
|
|
443
|
+
]);
|
|
348
444
|
};
|
|
349
445
|
|
|
350
446
|
// src/useTransitions.ts
|
|
351
|
-
import { useEffect as
|
|
352
|
-
var
|
|
447
|
+
import { useEffect as useEffect11, useRef as useRef7, useState as useState9 } from "react";
|
|
448
|
+
var isFunction2 = (functionToCheck) => {
|
|
353
449
|
return functionToCheck instanceof Function;
|
|
354
450
|
};
|
|
355
451
|
var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
356
|
-
const [hasTransitioned, setHasTransitioned] =
|
|
452
|
+
const [hasTransitioned, setHasTransitioned] = useState9(false);
|
|
357
453
|
const previousValue = useRef7(currentValue);
|
|
358
|
-
|
|
359
|
-
const toValueValid =
|
|
360
|
-
const fromValueValid =
|
|
454
|
+
useEffect11(() => {
|
|
455
|
+
const toValueValid = isFunction2(toValue) ? toValue(currentValue) : toValue === currentValue;
|
|
456
|
+
const fromValueValid = isFunction2(fromValue) ? fromValue(previousValue.current) : fromValue === previousValue.current;
|
|
361
457
|
if (fromValueValid && toValueValid && !hasTransitioned) {
|
|
362
458
|
setHasTransitioned(true);
|
|
363
459
|
} else if ((!fromValueValid || !toValueValid) && hasTransitioned) {
|
|
@@ -375,13 +471,13 @@ var useDidTransition = (currentValue, fromValue, toValue) => {
|
|
|
375
471
|
var useOnTransition = (currentValue, fromValue, toValue, callback) => {
|
|
376
472
|
const dirty = useRef7(false);
|
|
377
473
|
const hasTransitioned = useDidTransition(currentValue, fromValue, toValue);
|
|
378
|
-
|
|
474
|
+
useEffect11(() => {
|
|
379
475
|
dirty.current = false;
|
|
380
476
|
}, [
|
|
381
477
|
currentValue,
|
|
382
478
|
dirty
|
|
383
479
|
]);
|
|
384
|
-
|
|
480
|
+
useEffect11(() => {
|
|
385
481
|
if (hasTransitioned && !dirty.current) {
|
|
386
482
|
callback();
|
|
387
483
|
dirty.current = true;
|
|
@@ -394,11 +490,15 @@ var useOnTransition = (currentValue, fromValue, toValue, callback) => {
|
|
|
394
490
|
};
|
|
395
491
|
export {
|
|
396
492
|
makeId,
|
|
493
|
+
mergeRefs,
|
|
397
494
|
randomString,
|
|
495
|
+
setRef,
|
|
398
496
|
useAsyncEffect,
|
|
399
497
|
useAsyncState,
|
|
498
|
+
useAtomState,
|
|
499
|
+
useComposedRefs,
|
|
400
500
|
useControlledState,
|
|
401
|
-
|
|
501
|
+
useDebugDeps,
|
|
402
502
|
useDefaultValue,
|
|
403
503
|
useDefaults,
|
|
404
504
|
useDidTransition,
|
|
@@ -406,13 +506,17 @@ export {
|
|
|
406
506
|
useFileDownload,
|
|
407
507
|
useForwardedRef,
|
|
408
508
|
useId,
|
|
509
|
+
useInterval,
|
|
409
510
|
useIsFocused,
|
|
410
511
|
useMediaQuery,
|
|
512
|
+
useMergeRefs,
|
|
411
513
|
useMulticastObservable,
|
|
412
514
|
useOnTransition,
|
|
413
515
|
useRefCallback,
|
|
414
|
-
|
|
516
|
+
useScroller,
|
|
517
|
+
useSize,
|
|
518
|
+
useStateWithRef,
|
|
415
519
|
useTimeout,
|
|
416
|
-
|
|
520
|
+
useViewportResize
|
|
417
521
|
};
|
|
418
522
|
//# sourceMappingURL=index.mjs.map
|