@reactuses/core 3.0.2 → 4.0.0-beta.1
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/dist/index.cjs +579 -570
- package/dist/index.d.ts +9 -23
- package/dist/index.mjs +579 -570
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -50,7 +50,7 @@ const isIOS = isBrowser && ((_a = window == null ? void 0 : window.navigator) ==
|
|
|
50
50
|
!React.useId;
|
|
51
51
|
|
|
52
52
|
function guessSerializerType(rawInit) {
|
|
53
|
-
return rawInit == null ? "any" : rawInit instanceof Set ? "set" : rawInit instanceof Map ? "map" : rawInit instanceof Date ? "date" : typeof rawInit === "boolean" ? "boolean" : typeof rawInit === "string" ? "string" : typeof rawInit === "object" ? "object" : Array.isArray(rawInit) ? "object" : !Number.isNaN(rawInit) ? "number" : "any";
|
|
53
|
+
return rawInit == null || rawInit === void 0 ? "any" : rawInit instanceof Set ? "set" : rawInit instanceof Map ? "map" : rawInit instanceof Date ? "date" : typeof rawInit === "boolean" ? "boolean" : typeof rawInit === "string" ? "string" : typeof rawInit === "object" ? "object" : Array.isArray(rawInit) ? "object" : !Number.isNaN(rawInit) ? "number" : "any";
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
|
|
@@ -73,6 +73,283 @@ function useEvent(fn) {
|
|
|
73
73
|
}, []);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
const defaultOptions = {};
|
|
77
|
+
const defaultOnError = (e) => {
|
|
78
|
+
console.error(e);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const StorageSerializers = {
|
|
82
|
+
boolean: {
|
|
83
|
+
read: (v) => v === "true",
|
|
84
|
+
write: (v) => String(v)
|
|
85
|
+
},
|
|
86
|
+
object: {
|
|
87
|
+
read: (v) => JSON.parse(v),
|
|
88
|
+
write: (v) => JSON.stringify(v)
|
|
89
|
+
},
|
|
90
|
+
number: {
|
|
91
|
+
read: (v) => Number.parseFloat(v),
|
|
92
|
+
write: (v) => String(v)
|
|
93
|
+
},
|
|
94
|
+
any: {
|
|
95
|
+
read: (v) => v,
|
|
96
|
+
write: (v) => String(v)
|
|
97
|
+
},
|
|
98
|
+
string: {
|
|
99
|
+
read: (v) => v,
|
|
100
|
+
write: (v) => String(v)
|
|
101
|
+
},
|
|
102
|
+
map: {
|
|
103
|
+
read: (v) => new Map(JSON.parse(v)),
|
|
104
|
+
write: (v) => JSON.stringify(Array.from(v.entries()))
|
|
105
|
+
},
|
|
106
|
+
set: {
|
|
107
|
+
read: (v) => new Set(JSON.parse(v)),
|
|
108
|
+
write: (v) => JSON.stringify(Array.from(v))
|
|
109
|
+
},
|
|
110
|
+
date: {
|
|
111
|
+
read: (v) => new Date(v),
|
|
112
|
+
write: (v) => v.toISOString()
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const getInitialState$3 = (key, defaultValue, storage, serializer, onError) => {
|
|
116
|
+
if (defaultValue !== void 0) {
|
|
117
|
+
return defaultValue;
|
|
118
|
+
}
|
|
119
|
+
if (isBrowser) {
|
|
120
|
+
try {
|
|
121
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
122
|
+
if (raw !== void 0 && raw !== null) {
|
|
123
|
+
return serializer == null ? void 0 : serializer.read(raw);
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
onError == null ? void 0 : onError(error);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (process.env.NODE_ENV !== "production") {
|
|
130
|
+
console.warn(
|
|
131
|
+
"`createStorage` When server side rendering, defaultValue should be defined to prevent a hydration mismatches."
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
};
|
|
136
|
+
function useStorage(key, defaultValue, getStorage = () => isBrowser ? sessionStorage : void 0, options = defaultOptions) {
|
|
137
|
+
let storage;
|
|
138
|
+
const { onError = defaultOnError, csrData } = options;
|
|
139
|
+
try {
|
|
140
|
+
storage = getStorage();
|
|
141
|
+
} catch (err) {
|
|
142
|
+
onError(err);
|
|
143
|
+
}
|
|
144
|
+
const type = guessSerializerType(defaultValue);
|
|
145
|
+
const serializer = useMemo(() => {
|
|
146
|
+
var _a;
|
|
147
|
+
return (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
148
|
+
}, [options.serializer, type]);
|
|
149
|
+
const [state, setState] = useState(
|
|
150
|
+
getInitialState$3(key, defaultValue, storage, serializer, onError)
|
|
151
|
+
);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : defaultValue;
|
|
154
|
+
const getStoredValue = () => {
|
|
155
|
+
try {
|
|
156
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
157
|
+
if (raw !== void 0 && raw !== null) {
|
|
158
|
+
return serializer.read(raw);
|
|
159
|
+
} else {
|
|
160
|
+
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
161
|
+
return data;
|
|
162
|
+
}
|
|
163
|
+
} catch (e) {
|
|
164
|
+
onError(e);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
setState(getStoredValue());
|
|
168
|
+
}, [key, defaultValue, serializer, storage, onError, csrData]);
|
|
169
|
+
const updateState = useEvent(
|
|
170
|
+
(valOrFunc) => {
|
|
171
|
+
const currentState = isFunction$1(valOrFunc) ? valOrFunc(state) : valOrFunc;
|
|
172
|
+
setState(currentState);
|
|
173
|
+
if (currentState === null) {
|
|
174
|
+
storage == null ? void 0 : storage.removeItem(key);
|
|
175
|
+
} else {
|
|
176
|
+
try {
|
|
177
|
+
storage == null ? void 0 : storage.setItem(key, serializer.write(currentState));
|
|
178
|
+
} catch (e) {
|
|
179
|
+
onError(e);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
return [state, updateState];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function useLocalStorage(key, defaultValue, options = defaultOptions) {
|
|
188
|
+
return useStorage(
|
|
189
|
+
key,
|
|
190
|
+
defaultValue,
|
|
191
|
+
() => isBrowser ? localStorage : void 0,
|
|
192
|
+
options
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function useSessionStorage(key, defaultValue, options = defaultOptions) {
|
|
197
|
+
return useStorage(
|
|
198
|
+
key,
|
|
199
|
+
defaultValue,
|
|
200
|
+
() => isBrowser ? sessionStorage : void 0,
|
|
201
|
+
options
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const toggleReducer = (state, nextValue) => typeof nextValue === "boolean" ? nextValue : !state;
|
|
206
|
+
function useToggle(initialValue) {
|
|
207
|
+
return useReducer(toggleReducer, initialValue);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function useInterval(callback, delay, options = defaultOptions) {
|
|
211
|
+
const immediate = options.immediate;
|
|
212
|
+
const savedCallback = useLatest(callback);
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (immediate) {
|
|
215
|
+
savedCallback.current();
|
|
216
|
+
}
|
|
217
|
+
if (delay !== null) {
|
|
218
|
+
const interval = setInterval(() => savedCallback.current(), delay || 0);
|
|
219
|
+
return () => clearInterval(interval);
|
|
220
|
+
}
|
|
221
|
+
return void 0;
|
|
222
|
+
}, [delay, immediate]);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function useDarkMode(options) {
|
|
226
|
+
const {
|
|
227
|
+
selector = "html",
|
|
228
|
+
attribute = "class",
|
|
229
|
+
classNameDark = "",
|
|
230
|
+
classNameLight = "",
|
|
231
|
+
storageKey = "reactuses-color-scheme",
|
|
232
|
+
storage = () => isBrowser ? localStorage : void 0,
|
|
233
|
+
defaultValue = false
|
|
234
|
+
} = options;
|
|
235
|
+
const value = () => {
|
|
236
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
237
|
+
};
|
|
238
|
+
const [dark, setDark] = useStorage(
|
|
239
|
+
storageKey,
|
|
240
|
+
defaultValue,
|
|
241
|
+
storage,
|
|
242
|
+
{
|
|
243
|
+
csrData: value
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
const element = window == null ? void 0 : window.document.querySelector(selector);
|
|
248
|
+
if (!element) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (attribute === "class") {
|
|
252
|
+
dark && classNameDark && element.classList.add(classNameDark);
|
|
253
|
+
!dark && classNameLight && element.classList.add(classNameLight);
|
|
254
|
+
} else {
|
|
255
|
+
dark && classNameDark && element.setAttribute(attribute, classNameDark);
|
|
256
|
+
!dark && classNameLight && element.setAttribute(attribute, classNameLight);
|
|
257
|
+
}
|
|
258
|
+
return () => {
|
|
259
|
+
if (!element) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (attribute === "class") {
|
|
263
|
+
dark && classNameDark && element.classList.remove(classNameDark);
|
|
264
|
+
!dark && classNameLight && element.classList.remove(classNameLight);
|
|
265
|
+
} else {
|
|
266
|
+
dark && classNameDark && element.removeAttribute(attribute);
|
|
267
|
+
!dark && classNameLight && element.removeAttribute(attribute);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}, [attribute, classNameDark, classNameLight, dark, selector]);
|
|
271
|
+
return [dark, () => setDark((dark2) => !dark2), setDark];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const getInitialState$2 = (query, defaultState) => {
|
|
275
|
+
if (defaultState !== void 0) {
|
|
276
|
+
return defaultState;
|
|
277
|
+
}
|
|
278
|
+
if (isBrowser) {
|
|
279
|
+
return window.matchMedia(query).matches;
|
|
280
|
+
}
|
|
281
|
+
if (process.env.NODE_ENV !== "production") {
|
|
282
|
+
console.warn(
|
|
283
|
+
"`useMediaQuery` When server side rendering, defaultState should be defined to prevent a hydration mismatches."
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
return false;
|
|
287
|
+
};
|
|
288
|
+
function useMediaQuery(query, defaultState) {
|
|
289
|
+
const [state, setState] = useState(getInitialState$2(query, defaultState));
|
|
290
|
+
useEffect(() => {
|
|
291
|
+
var _a;
|
|
292
|
+
let mounted = true;
|
|
293
|
+
const mql = window.matchMedia(query);
|
|
294
|
+
const onChange = () => {
|
|
295
|
+
if (!mounted) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
setState(!!mql.matches);
|
|
299
|
+
};
|
|
300
|
+
if ("addEventListener" in mql) {
|
|
301
|
+
mql.addEventListener("change", onChange);
|
|
302
|
+
} else {
|
|
303
|
+
(_a = mql.addListener) == null ? void 0 : _a.call(mql, onChange);
|
|
304
|
+
}
|
|
305
|
+
setState(mql.matches);
|
|
306
|
+
return () => {
|
|
307
|
+
var _a2;
|
|
308
|
+
mounted = false;
|
|
309
|
+
if ("removeEventListener" in mql) {
|
|
310
|
+
mql.removeEventListener("change", onChange);
|
|
311
|
+
} else {
|
|
312
|
+
(_a2 = mql.removeListener) == null ? void 0 : _a2.call(mql, onChange);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}, [query]);
|
|
316
|
+
return state;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function usePreferredDark(defaultState) {
|
|
320
|
+
return useMediaQuery("(prefers-color-scheme: dark)", defaultState);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function useMount(fn) {
|
|
324
|
+
if (isDev) {
|
|
325
|
+
if (!isFunction$1(fn)) {
|
|
326
|
+
console.error(
|
|
327
|
+
`useMount: parameter \`fn\` expected to be a function, but got "${typeof fn}".`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
fn == null ? void 0 : fn();
|
|
333
|
+
}, []);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function useUnmount(fn) {
|
|
337
|
+
if (isDev) {
|
|
338
|
+
if (!isFunction$1(fn)) {
|
|
339
|
+
console.error(
|
|
340
|
+
`useUnmount expected parameter is a function, got ${typeof fn}`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const fnRef = useLatest(fn);
|
|
345
|
+
useEffect(
|
|
346
|
+
() => () => {
|
|
347
|
+
fnRef.current();
|
|
348
|
+
},
|
|
349
|
+
[fnRef]
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
76
353
|
/** Detect free variable `global` from Node.js. */
|
|
77
354
|
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|
78
355
|
|
|
@@ -2388,390 +2665,95 @@ function debounce(func, wait, options) {
|
|
|
2388
2665
|
*
|
|
2389
2666
|
* **Note:** This method supports comparing arrays, array buffers, booleans,
|
|
2390
2667
|
* date objects, error objects, maps, numbers, `Object` objects, regexes,
|
|
2391
|
-
* sets, strings, symbols, and typed arrays. `Object` objects are compared
|
|
2392
|
-
* by their own, not inherited, enumerable properties. Functions and DOM
|
|
2393
|
-
* nodes are compared by strict equality, i.e. `===`.
|
|
2394
|
-
*
|
|
2395
|
-
* @static
|
|
2396
|
-
* @memberOf _
|
|
2397
|
-
* @since 0.1.0
|
|
2398
|
-
* @category Lang
|
|
2399
|
-
* @param {*} value The value to compare.
|
|
2400
|
-
* @param {*} other The other value to compare.
|
|
2401
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
2402
|
-
* @example
|
|
2403
|
-
*
|
|
2404
|
-
* var object = { 'a': 1 };
|
|
2405
|
-
* var other = { 'a': 1 };
|
|
2406
|
-
*
|
|
2407
|
-
* _.isEqual(object, other);
|
|
2408
|
-
* // => true
|
|
2409
|
-
*
|
|
2410
|
-
* object === other;
|
|
2411
|
-
* // => false
|
|
2412
|
-
*/
|
|
2413
|
-
function isEqual(value, other) {
|
|
2414
|
-
return baseIsEqual(value, other);
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
/** Error message constants. */
|
|
2418
|
-
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
2419
|
-
|
|
2420
|
-
/**
|
|
2421
|
-
* Creates a throttled function that only invokes `func` at most once per
|
|
2422
|
-
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
2423
|
-
* method to cancel delayed `func` invocations and a `flush` method to
|
|
2424
|
-
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
2425
|
-
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
2426
|
-
* timeout. The `func` is invoked with the last arguments provided to the
|
|
2427
|
-
* throttled function. Subsequent calls to the throttled function return the
|
|
2428
|
-
* result of the last `func` invocation.
|
|
2429
|
-
*
|
|
2430
|
-
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
2431
|
-
* invoked on the trailing edge of the timeout only if the throttled function
|
|
2432
|
-
* is invoked more than once during the `wait` timeout.
|
|
2433
|
-
*
|
|
2434
|
-
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
2435
|
-
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
2436
|
-
*
|
|
2437
|
-
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
2438
|
-
* for details over the differences between `_.throttle` and `_.debounce`.
|
|
2439
|
-
*
|
|
2440
|
-
* @static
|
|
2441
|
-
* @memberOf _
|
|
2442
|
-
* @since 0.1.0
|
|
2443
|
-
* @category Function
|
|
2444
|
-
* @param {Function} func The function to throttle.
|
|
2445
|
-
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
|
2446
|
-
* @param {Object} [options={}] The options object.
|
|
2447
|
-
* @param {boolean} [options.leading=true]
|
|
2448
|
-
* Specify invoking on the leading edge of the timeout.
|
|
2449
|
-
* @param {boolean} [options.trailing=true]
|
|
2450
|
-
* Specify invoking on the trailing edge of the timeout.
|
|
2451
|
-
* @returns {Function} Returns the new throttled function.
|
|
2452
|
-
* @example
|
|
2453
|
-
*
|
|
2454
|
-
* // Avoid excessively updating the position while scrolling.
|
|
2455
|
-
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|
2456
|
-
*
|
|
2457
|
-
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
|
2458
|
-
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
|
2459
|
-
* jQuery(element).on('click', throttled);
|
|
2460
|
-
*
|
|
2461
|
-
* // Cancel the trailing throttled invocation.
|
|
2462
|
-
* jQuery(window).on('popstate', throttled.cancel);
|
|
2463
|
-
*/
|
|
2464
|
-
function throttle(func, wait, options) {
|
|
2465
|
-
var leading = true,
|
|
2466
|
-
trailing = true;
|
|
2467
|
-
|
|
2468
|
-
if (typeof func != 'function') {
|
|
2469
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
2470
|
-
}
|
|
2471
|
-
if (isObject(options)) {
|
|
2472
|
-
leading = 'leading' in options ? !!options.leading : leading;
|
|
2473
|
-
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
2474
|
-
}
|
|
2475
|
-
return debounce(func, wait, {
|
|
2476
|
-
'leading': leading,
|
|
2477
|
-
'maxWait': wait,
|
|
2478
|
-
'trailing': trailing
|
|
2479
|
-
});
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
const isPrimitive$1 = (val) => val !== Object(val);
|
|
2483
|
-
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
2484
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2485
|
-
if (!Array.isArray(deps) || !deps.length) {
|
|
2486
|
-
console.warn(
|
|
2487
|
-
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
2488
|
-
);
|
|
2489
|
-
}
|
|
2490
|
-
if (deps.every(isPrimitive$1)) {
|
|
2491
|
-
console.warn(
|
|
2492
|
-
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
2493
|
-
);
|
|
2494
|
-
}
|
|
2495
|
-
if (typeof depsEqual !== "function") {
|
|
2496
|
-
console.warn(
|
|
2497
|
-
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
2498
|
-
);
|
|
2499
|
-
}
|
|
2500
|
-
}
|
|
2501
|
-
const ref = useRef(void 0);
|
|
2502
|
-
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
2503
|
-
ref.current = deps;
|
|
2504
|
-
}
|
|
2505
|
-
useEffect(effect, ref.current);
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
const isPrimitive = (val) => val !== Object(val);
|
|
2509
|
-
function useDeepCompareEffect(effect, deps) {
|
|
2510
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2511
|
-
if (!Array.isArray(deps) || !deps.length) {
|
|
2512
|
-
console.warn(
|
|
2513
|
-
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
2514
|
-
);
|
|
2515
|
-
}
|
|
2516
|
-
if (deps.every(isPrimitive)) {
|
|
2517
|
-
console.warn(
|
|
2518
|
-
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
2519
|
-
);
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
useCustomCompareEffect(effect, deps, isEqual);
|
|
2523
|
-
}
|
|
2524
|
-
|
|
2525
|
-
const StorageSerializers = {
|
|
2526
|
-
boolean: {
|
|
2527
|
-
read: (v) => v === "true",
|
|
2528
|
-
write: (v) => String(v)
|
|
2529
|
-
},
|
|
2530
|
-
object: {
|
|
2531
|
-
read: (v) => JSON.parse(v),
|
|
2532
|
-
write: (v) => JSON.stringify(v)
|
|
2533
|
-
},
|
|
2534
|
-
number: {
|
|
2535
|
-
read: (v) => Number.parseFloat(v),
|
|
2536
|
-
write: (v) => String(v)
|
|
2537
|
-
},
|
|
2538
|
-
any: {
|
|
2539
|
-
read: (v) => v,
|
|
2540
|
-
write: (v) => String(v)
|
|
2541
|
-
},
|
|
2542
|
-
string: {
|
|
2543
|
-
read: (v) => v,
|
|
2544
|
-
write: (v) => String(v)
|
|
2545
|
-
},
|
|
2546
|
-
map: {
|
|
2547
|
-
read: (v) => new Map(JSON.parse(v)),
|
|
2548
|
-
write: (v) => JSON.stringify(Array.from(v.entries()))
|
|
2549
|
-
},
|
|
2550
|
-
set: {
|
|
2551
|
-
read: (v) => new Set(JSON.parse(v)),
|
|
2552
|
-
write: (v) => JSON.stringify(Array.from(v))
|
|
2553
|
-
},
|
|
2554
|
-
date: {
|
|
2555
|
-
read: (v) => new Date(v),
|
|
2556
|
-
write: (v) => v.toISOString()
|
|
2557
|
-
}
|
|
2558
|
-
};
|
|
2559
|
-
function useStorage(key, defaults, getStorage, options = {}) {
|
|
2560
|
-
const defaultOnError = useCallback((e) => {
|
|
2561
|
-
console.error(e);
|
|
2562
|
-
}, []);
|
|
2563
|
-
let storage;
|
|
2564
|
-
const { onError = defaultOnError, csrData } = options;
|
|
2565
|
-
try {
|
|
2566
|
-
storage = getStorage();
|
|
2567
|
-
} catch (err) {
|
|
2568
|
-
onError(err);
|
|
2569
|
-
}
|
|
2570
|
-
const type = guessSerializerType(defaults);
|
|
2571
|
-
const serializer = useMemo(() => {
|
|
2572
|
-
var _a;
|
|
2573
|
-
return (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
2574
|
-
}, [options.serializer, type]);
|
|
2575
|
-
const [state, setState] = useState(defaults);
|
|
2576
|
-
useDeepCompareEffect(() => {
|
|
2577
|
-
const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : defaults;
|
|
2578
|
-
const getStoredValue = () => {
|
|
2579
|
-
try {
|
|
2580
|
-
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
2581
|
-
if (raw !== void 0 && raw !== null) {
|
|
2582
|
-
return serializer.read(raw);
|
|
2583
|
-
} else {
|
|
2584
|
-
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
2585
|
-
return data;
|
|
2586
|
-
}
|
|
2587
|
-
} catch (e) {
|
|
2588
|
-
onError(e);
|
|
2589
|
-
}
|
|
2590
|
-
};
|
|
2591
|
-
setState(getStoredValue());
|
|
2592
|
-
}, [key, defaults, serializer, storage, onError]);
|
|
2593
|
-
const updateState = useEvent(
|
|
2594
|
-
(valOrFunc) => {
|
|
2595
|
-
const currentState = isFunction$1(valOrFunc) ? valOrFunc(state) : valOrFunc;
|
|
2596
|
-
setState(currentState);
|
|
2597
|
-
if (currentState === null) {
|
|
2598
|
-
storage == null ? void 0 : storage.removeItem(key);
|
|
2599
|
-
} else {
|
|
2600
|
-
try {
|
|
2601
|
-
storage == null ? void 0 : storage.setItem(key, serializer.write(currentState));
|
|
2602
|
-
} catch (e) {
|
|
2603
|
-
onError(e);
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
}
|
|
2607
|
-
);
|
|
2608
|
-
return [state, updateState];
|
|
2609
|
-
}
|
|
2610
|
-
|
|
2611
|
-
function useLocalStorage(key, defaults, options = {}) {
|
|
2612
|
-
return useStorage(
|
|
2613
|
-
key,
|
|
2614
|
-
defaults,
|
|
2615
|
-
() => isBrowser ? localStorage : void 0,
|
|
2616
|
-
options
|
|
2617
|
-
);
|
|
2618
|
-
}
|
|
2619
|
-
|
|
2620
|
-
function useSessionStorage(key, defaults, options = {}) {
|
|
2621
|
-
return useStorage(
|
|
2622
|
-
key,
|
|
2623
|
-
defaults,
|
|
2624
|
-
() => isBrowser ? sessionStorage : void 0,
|
|
2625
|
-
options
|
|
2626
|
-
);
|
|
2627
|
-
}
|
|
2628
|
-
|
|
2629
|
-
const toggleReducer = (state, nextValue) => typeof nextValue === "boolean" ? nextValue : !state;
|
|
2630
|
-
function useToggle(initialValue) {
|
|
2631
|
-
return useReducer(toggleReducer, initialValue);
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
function useInterval(callback, delay, options) {
|
|
2635
|
-
const immediate = options == null ? void 0 : options.immediate;
|
|
2636
|
-
const savedCallback = useLatest(callback);
|
|
2637
|
-
useEffect(() => {
|
|
2638
|
-
if (immediate) {
|
|
2639
|
-
savedCallback.current();
|
|
2640
|
-
}
|
|
2641
|
-
if (delay !== null) {
|
|
2642
|
-
const interval = setInterval(() => savedCallback.current(), delay || 0);
|
|
2643
|
-
return () => clearInterval(interval);
|
|
2644
|
-
}
|
|
2645
|
-
return void 0;
|
|
2646
|
-
}, [delay, immediate]);
|
|
2647
|
-
}
|
|
2648
|
-
|
|
2649
|
-
function useDarkMode(options) {
|
|
2650
|
-
const {
|
|
2651
|
-
selector = "html",
|
|
2652
|
-
attribute = "class",
|
|
2653
|
-
classNameDark = "",
|
|
2654
|
-
classNameLight = "",
|
|
2655
|
-
storageKey = "reactuses-color-scheme",
|
|
2656
|
-
storage = () => isBrowser ? localStorage : void 0,
|
|
2657
|
-
defaultValue = false
|
|
2658
|
-
} = options;
|
|
2659
|
-
const value = () => {
|
|
2660
|
-
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
2661
|
-
};
|
|
2662
|
-
const [dark, setDark] = useStorage(
|
|
2663
|
-
storageKey,
|
|
2664
|
-
defaultValue,
|
|
2665
|
-
storage,
|
|
2666
|
-
{
|
|
2667
|
-
csrData: value
|
|
2668
|
-
}
|
|
2669
|
-
);
|
|
2670
|
-
useEffect(() => {
|
|
2671
|
-
const element = window == null ? void 0 : window.document.querySelector(selector);
|
|
2672
|
-
if (!element) {
|
|
2673
|
-
return;
|
|
2674
|
-
}
|
|
2675
|
-
if (attribute === "class") {
|
|
2676
|
-
dark && classNameDark && element.classList.add(classNameDark);
|
|
2677
|
-
!dark && classNameLight && element.classList.add(classNameLight);
|
|
2678
|
-
} else {
|
|
2679
|
-
dark && classNameDark && element.setAttribute(attribute, classNameDark);
|
|
2680
|
-
!dark && classNameLight && element.setAttribute(attribute, classNameLight);
|
|
2681
|
-
}
|
|
2682
|
-
return () => {
|
|
2683
|
-
if (!element) {
|
|
2684
|
-
return;
|
|
2685
|
-
}
|
|
2686
|
-
if (attribute === "class") {
|
|
2687
|
-
dark && classNameDark && element.classList.remove(classNameDark);
|
|
2688
|
-
!dark && classNameLight && element.classList.remove(classNameLight);
|
|
2689
|
-
} else {
|
|
2690
|
-
dark && classNameDark && element.removeAttribute(attribute);
|
|
2691
|
-
!dark && classNameLight && element.removeAttribute(attribute);
|
|
2692
|
-
}
|
|
2693
|
-
};
|
|
2694
|
-
}, [attribute, classNameDark, classNameLight, dark, selector]);
|
|
2695
|
-
return [dark, () => setDark((dark2) => !dark2), setDark];
|
|
2696
|
-
}
|
|
2697
|
-
|
|
2698
|
-
const getInitialState = (query, defaultState) => {
|
|
2699
|
-
if (defaultState !== void 0) {
|
|
2700
|
-
return defaultState;
|
|
2701
|
-
}
|
|
2702
|
-
if (isBrowser) {
|
|
2703
|
-
return window.matchMedia(query).matches;
|
|
2704
|
-
}
|
|
2705
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2706
|
-
console.warn(
|
|
2707
|
-
"`useMediaQuery` When server side rendering, defaultState should be defined to prevent a hydration mismatches."
|
|
2708
|
-
);
|
|
2709
|
-
}
|
|
2710
|
-
return false;
|
|
2711
|
-
};
|
|
2712
|
-
function useMediaQuery(query, defaultState) {
|
|
2713
|
-
const [state, setState] = useState(getInitialState(query, defaultState));
|
|
2714
|
-
useEffect(() => {
|
|
2715
|
-
var _a;
|
|
2716
|
-
let mounted = true;
|
|
2717
|
-
const mql = window.matchMedia(query);
|
|
2718
|
-
const onChange = () => {
|
|
2719
|
-
if (!mounted) {
|
|
2720
|
-
return;
|
|
2721
|
-
}
|
|
2722
|
-
setState(!!mql.matches);
|
|
2723
|
-
};
|
|
2724
|
-
if ("addEventListener" in mql) {
|
|
2725
|
-
mql.addEventListener("change", onChange);
|
|
2726
|
-
} else {
|
|
2727
|
-
(_a = mql.addListener) == null ? void 0 : _a.call(mql, onChange);
|
|
2728
|
-
}
|
|
2729
|
-
setState(mql.matches);
|
|
2730
|
-
return () => {
|
|
2731
|
-
var _a2;
|
|
2732
|
-
mounted = false;
|
|
2733
|
-
if ("removeEventListener" in mql) {
|
|
2734
|
-
mql.removeEventListener("change", onChange);
|
|
2735
|
-
} else {
|
|
2736
|
-
(_a2 = mql.removeListener) == null ? void 0 : _a2.call(mql, onChange);
|
|
2737
|
-
}
|
|
2738
|
-
};
|
|
2739
|
-
}, [query]);
|
|
2740
|
-
return state;
|
|
2668
|
+
* sets, strings, symbols, and typed arrays. `Object` objects are compared
|
|
2669
|
+
* by their own, not inherited, enumerable properties. Functions and DOM
|
|
2670
|
+
* nodes are compared by strict equality, i.e. `===`.
|
|
2671
|
+
*
|
|
2672
|
+
* @static
|
|
2673
|
+
* @memberOf _
|
|
2674
|
+
* @since 0.1.0
|
|
2675
|
+
* @category Lang
|
|
2676
|
+
* @param {*} value The value to compare.
|
|
2677
|
+
* @param {*} other The other value to compare.
|
|
2678
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
2679
|
+
* @example
|
|
2680
|
+
*
|
|
2681
|
+
* var object = { 'a': 1 };
|
|
2682
|
+
* var other = { 'a': 1 };
|
|
2683
|
+
*
|
|
2684
|
+
* _.isEqual(object, other);
|
|
2685
|
+
* // => true
|
|
2686
|
+
*
|
|
2687
|
+
* object === other;
|
|
2688
|
+
* // => false
|
|
2689
|
+
*/
|
|
2690
|
+
function isEqual(value, other) {
|
|
2691
|
+
return baseIsEqual(value, other);
|
|
2741
2692
|
}
|
|
2742
2693
|
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
}
|
|
2694
|
+
/** Error message constants. */
|
|
2695
|
+
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
2746
2696
|
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2697
|
+
/**
|
|
2698
|
+
* Creates a throttled function that only invokes `func` at most once per
|
|
2699
|
+
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
2700
|
+
* method to cancel delayed `func` invocations and a `flush` method to
|
|
2701
|
+
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
2702
|
+
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
2703
|
+
* timeout. The `func` is invoked with the last arguments provided to the
|
|
2704
|
+
* throttled function. Subsequent calls to the throttled function return the
|
|
2705
|
+
* result of the last `func` invocation.
|
|
2706
|
+
*
|
|
2707
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
2708
|
+
* invoked on the trailing edge of the timeout only if the throttled function
|
|
2709
|
+
* is invoked more than once during the `wait` timeout.
|
|
2710
|
+
*
|
|
2711
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
2712
|
+
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
2713
|
+
*
|
|
2714
|
+
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
2715
|
+
* for details over the differences between `_.throttle` and `_.debounce`.
|
|
2716
|
+
*
|
|
2717
|
+
* @static
|
|
2718
|
+
* @memberOf _
|
|
2719
|
+
* @since 0.1.0
|
|
2720
|
+
* @category Function
|
|
2721
|
+
* @param {Function} func The function to throttle.
|
|
2722
|
+
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
|
2723
|
+
* @param {Object} [options={}] The options object.
|
|
2724
|
+
* @param {boolean} [options.leading=true]
|
|
2725
|
+
* Specify invoking on the leading edge of the timeout.
|
|
2726
|
+
* @param {boolean} [options.trailing=true]
|
|
2727
|
+
* Specify invoking on the trailing edge of the timeout.
|
|
2728
|
+
* @returns {Function} Returns the new throttled function.
|
|
2729
|
+
* @example
|
|
2730
|
+
*
|
|
2731
|
+
* // Avoid excessively updating the position while scrolling.
|
|
2732
|
+
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|
2733
|
+
*
|
|
2734
|
+
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
|
2735
|
+
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
|
2736
|
+
* jQuery(element).on('click', throttled);
|
|
2737
|
+
*
|
|
2738
|
+
* // Cancel the trailing throttled invocation.
|
|
2739
|
+
* jQuery(window).on('popstate', throttled.cancel);
|
|
2740
|
+
*/
|
|
2741
|
+
function throttle(func, wait, options) {
|
|
2742
|
+
var leading = true,
|
|
2743
|
+
trailing = true;
|
|
2759
2744
|
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
if (!isFunction$1(fn)) {
|
|
2763
|
-
console.error(
|
|
2764
|
-
`useUnmount expected parameter is a function, got ${typeof fn}`
|
|
2765
|
-
);
|
|
2766
|
-
}
|
|
2745
|
+
if (typeof func != 'function') {
|
|
2746
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
2767
2747
|
}
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2748
|
+
if (isObject(options)) {
|
|
2749
|
+
leading = 'leading' in options ? !!options.leading : leading;
|
|
2750
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
2751
|
+
}
|
|
2752
|
+
return debounce(func, wait, {
|
|
2753
|
+
'leading': leading,
|
|
2754
|
+
'maxWait': wait,
|
|
2755
|
+
'trailing': trailing
|
|
2756
|
+
});
|
|
2775
2757
|
}
|
|
2776
2758
|
|
|
2777
2759
|
function useThrottleFn(fn, wait, options) {
|
|
@@ -2791,8 +2773,7 @@ function useThrottleFn(fn, wait, options) {
|
|
|
2791
2773
|
wait,
|
|
2792
2774
|
options
|
|
2793
2775
|
),
|
|
2794
|
-
|
|
2795
|
-
[]
|
|
2776
|
+
[wait, options]
|
|
2796
2777
|
);
|
|
2797
2778
|
useUnmount(() => {
|
|
2798
2779
|
throttled.cancel();
|
|
@@ -2836,8 +2817,7 @@ function useDebounceFn(fn, wait, options) {
|
|
|
2836
2817
|
wait,
|
|
2837
2818
|
options
|
|
2838
2819
|
),
|
|
2839
|
-
|
|
2840
|
-
[]
|
|
2820
|
+
[options, wait]
|
|
2841
2821
|
);
|
|
2842
2822
|
useUnmount(() => {
|
|
2843
2823
|
debounced.cancel();
|
|
@@ -2885,7 +2865,7 @@ function useUpdate() {
|
|
|
2885
2865
|
return update;
|
|
2886
2866
|
}
|
|
2887
2867
|
|
|
2888
|
-
function useTimeoutFn(cb, interval, options =
|
|
2868
|
+
function useTimeoutFn(cb, interval, options = defaultOptions) {
|
|
2889
2869
|
const { immediate = true } = options;
|
|
2890
2870
|
const [pending, setPending] = useState(false);
|
|
2891
2871
|
const savedCallback = useLatest(cb);
|
|
@@ -2975,10 +2955,10 @@ function useLatestElement(target, defaultElement) {
|
|
|
2975
2955
|
return latestElement;
|
|
2976
2956
|
}
|
|
2977
2957
|
|
|
2978
|
-
function useEventListener(eventName, handler, element, options) {
|
|
2958
|
+
function useEventListener(eventName, handler, element, options = defaultOptions) {
|
|
2979
2959
|
const savedHandler = useLatest(handler);
|
|
2980
2960
|
const targetElement = useLatestElement(element, defaultWindow);
|
|
2981
|
-
|
|
2961
|
+
useEffect(() => {
|
|
2982
2962
|
if (!(targetElement && targetElement.addEventListener)) {
|
|
2983
2963
|
return;
|
|
2984
2964
|
}
|
|
@@ -3132,7 +3112,7 @@ function useFavicon(href, baseUrl = "", rel = "icon") {
|
|
|
3132
3112
|
}, [baseUrl, href, rel]);
|
|
3133
3113
|
}
|
|
3134
3114
|
|
|
3135
|
-
function useMutationObserver(callback, target, options =
|
|
3115
|
+
function useMutationObserver(callback, target, options = defaultOptions) {
|
|
3136
3116
|
const callbackRef = useLatest(callback);
|
|
3137
3117
|
const observerRef = useRef();
|
|
3138
3118
|
const element = useLatestElement(target);
|
|
@@ -3141,7 +3121,7 @@ function useMutationObserver(callback, target, options = {}) {
|
|
|
3141
3121
|
observerRef.current.disconnect();
|
|
3142
3122
|
}
|
|
3143
3123
|
}, []);
|
|
3144
|
-
|
|
3124
|
+
useEffect(() => {
|
|
3145
3125
|
if (!element) {
|
|
3146
3126
|
return;
|
|
3147
3127
|
}
|
|
@@ -3152,13 +3132,56 @@ function useMutationObserver(callback, target, options = {}) {
|
|
|
3152
3132
|
return stop;
|
|
3153
3133
|
}
|
|
3154
3134
|
|
|
3135
|
+
const isPrimitive$1 = (val) => val !== Object(val);
|
|
3136
|
+
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
3137
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3138
|
+
if (!Array.isArray(deps) || !deps.length) {
|
|
3139
|
+
console.warn(
|
|
3140
|
+
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
3141
|
+
);
|
|
3142
|
+
}
|
|
3143
|
+
if (deps.every(isPrimitive$1)) {
|
|
3144
|
+
console.warn(
|
|
3145
|
+
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
3146
|
+
);
|
|
3147
|
+
}
|
|
3148
|
+
if (typeof depsEqual !== "function") {
|
|
3149
|
+
console.warn(
|
|
3150
|
+
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
3151
|
+
);
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
const ref = useRef(void 0);
|
|
3155
|
+
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
3156
|
+
ref.current = deps;
|
|
3157
|
+
}
|
|
3158
|
+
useEffect(effect, ref.current);
|
|
3159
|
+
}
|
|
3160
|
+
|
|
3161
|
+
const isPrimitive = (val) => val !== Object(val);
|
|
3162
|
+
function useDeepCompareEffect(effect, deps) {
|
|
3163
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3164
|
+
if (!Array.isArray(deps) || !deps.length) {
|
|
3165
|
+
console.warn(
|
|
3166
|
+
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
3167
|
+
);
|
|
3168
|
+
}
|
|
3169
|
+
if (deps.every(isPrimitive)) {
|
|
3170
|
+
console.warn(
|
|
3171
|
+
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
3172
|
+
);
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
useCustomCompareEffect(effect, deps, isEqual);
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3155
3178
|
function useTitle(title) {
|
|
3156
3179
|
useEffect(() => {
|
|
3157
3180
|
document.title = title;
|
|
3158
3181
|
}, [title]);
|
|
3159
3182
|
}
|
|
3160
3183
|
|
|
3161
|
-
function useScriptTag(src, onLoaded = noop, options =
|
|
3184
|
+
function useScriptTag(src, onLoaded = noop, options = defaultOptions) {
|
|
3162
3185
|
const {
|
|
3163
3186
|
immediate = true,
|
|
3164
3187
|
manual = false,
|
|
@@ -3312,7 +3335,7 @@ const preventDefault$1 = (ev) => {
|
|
|
3312
3335
|
ev.preventDefault();
|
|
3313
3336
|
}
|
|
3314
3337
|
};
|
|
3315
|
-
function useLongPress(callback, { isPreventDefault = true, delay = 300 } =
|
|
3338
|
+
function useLongPress(callback, { isPreventDefault = true, delay = 300 } = defaultOptions) {
|
|
3316
3339
|
const timeout = useRef();
|
|
3317
3340
|
const target = useRef();
|
|
3318
3341
|
const start = useCallback(
|
|
@@ -3433,8 +3456,9 @@ var __async$4 = (__this, __arguments, generator) => {
|
|
|
3433
3456
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
3434
3457
|
});
|
|
3435
3458
|
};
|
|
3459
|
+
const defaultConstints = { audio: true, video: true };
|
|
3436
3460
|
function useMediaDevices(options = {}) {
|
|
3437
|
-
const { requestPermissions, constraints =
|
|
3461
|
+
const { requestPermissions, constraints = defaultConstints } = options;
|
|
3438
3462
|
const [state, setState] = useState({ devices: [] });
|
|
3439
3463
|
const isSupported = useSupported(
|
|
3440
3464
|
() => navigator && navigator.mediaDevices && navigator.mediaDevices.enumerateDevices
|
|
@@ -3464,7 +3488,7 @@ function useMediaDevices(options = {}) {
|
|
|
3464
3488
|
if (permissionGranted.current) {
|
|
3465
3489
|
return true;
|
|
3466
3490
|
}
|
|
3467
|
-
let state2
|
|
3491
|
+
let state2;
|
|
3468
3492
|
try {
|
|
3469
3493
|
state2 = (yield navigator.permissions.query({
|
|
3470
3494
|
name: "camera"
|
|
@@ -3497,7 +3521,7 @@ function useMediaDevices(options = {}) {
|
|
|
3497
3521
|
return [state, ensurePermissions];
|
|
3498
3522
|
}
|
|
3499
3523
|
|
|
3500
|
-
function useTextDirection(options =
|
|
3524
|
+
function useTextDirection(options = defaultOptions) {
|
|
3501
3525
|
const { selector = "html", initialValue = "ltr" } = options;
|
|
3502
3526
|
const getValue = () => {
|
|
3503
3527
|
var _a, _b;
|
|
@@ -3574,10 +3598,10 @@ function useMouse(target) {
|
|
|
3574
3598
|
return state;
|
|
3575
3599
|
}
|
|
3576
3600
|
|
|
3577
|
-
function useFps(options) {
|
|
3601
|
+
function useFps(options = defaultOptions) {
|
|
3578
3602
|
var _a;
|
|
3579
3603
|
const [fps, setFps] = useState(0);
|
|
3580
|
-
const every = (_a = options
|
|
3604
|
+
const every = (_a = options.every) != null ? _a : 10;
|
|
3581
3605
|
const last = useRef(performance.now());
|
|
3582
3606
|
const ticks = useRef(0);
|
|
3583
3607
|
useRafFn(() => {
|
|
@@ -3604,7 +3628,7 @@ const initCoord = {
|
|
|
3604
3628
|
heading: null,
|
|
3605
3629
|
speed: null
|
|
3606
3630
|
};
|
|
3607
|
-
function useGeolocation(options =
|
|
3631
|
+
function useGeolocation(options = defaultOptions) {
|
|
3608
3632
|
const {
|
|
3609
3633
|
enableHighAccuracy = true,
|
|
3610
3634
|
maximumAge = 3e4,
|
|
@@ -3830,20 +3854,17 @@ var screenfull$1 = {exports: {}};
|
|
|
3830
3854
|
|
|
3831
3855
|
var screenfull = screenfull$1.exports;
|
|
3832
3856
|
|
|
3833
|
-
function useFullscreen(target, options) {
|
|
3834
|
-
const { onExit, onEnter } = options
|
|
3835
|
-
const onExitRef = useLatest(onExit);
|
|
3836
|
-
const onEnterRef = useLatest(onEnter);
|
|
3857
|
+
function useFullscreen(target, options = defaultOptions) {
|
|
3858
|
+
const { onExit, onEnter } = options;
|
|
3837
3859
|
const [state, setState] = useState(false);
|
|
3838
3860
|
const onChange = () => {
|
|
3839
|
-
var _a, _b;
|
|
3840
3861
|
if (screenfull.isEnabled) {
|
|
3841
3862
|
const { isFullscreen } = screenfull;
|
|
3842
3863
|
if (isFullscreen) {
|
|
3843
|
-
|
|
3864
|
+
onEnter == null ? void 0 : onEnter();
|
|
3844
3865
|
} else {
|
|
3845
3866
|
screenfull.off("change", onChange);
|
|
3846
|
-
|
|
3867
|
+
onExit == null ? void 0 : onExit();
|
|
3847
3868
|
}
|
|
3848
3869
|
setState(isFullscreen);
|
|
3849
3870
|
}
|
|
@@ -3985,7 +4006,7 @@ function useOrientation(initialState = defaultState$1) {
|
|
|
3985
4006
|
return [state, lockOrientation, unlockOrientation];
|
|
3986
4007
|
}
|
|
3987
4008
|
|
|
3988
|
-
function useIntersectionObserver(target, callback, options =
|
|
4009
|
+
function useIntersectionObserver(target, callback, options = defaultOptions) {
|
|
3989
4010
|
const savedCallback = useLatest(callback);
|
|
3990
4011
|
const observerRef = useRef();
|
|
3991
4012
|
const element = useLatestElement(target);
|
|
@@ -3994,7 +4015,7 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
3994
4015
|
observerRef.current.disconnect();
|
|
3995
4016
|
}
|
|
3996
4017
|
}, []);
|
|
3997
|
-
|
|
4018
|
+
useEffect(() => {
|
|
3998
4019
|
if (!element) {
|
|
3999
4020
|
return;
|
|
4000
4021
|
}
|
|
@@ -4023,14 +4044,24 @@ function usePageLeave() {
|
|
|
4023
4044
|
return isLeft;
|
|
4024
4045
|
}
|
|
4025
4046
|
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4047
|
+
const getInitialState$1 = (defaultValue) => {
|
|
4048
|
+
if (defaultValue !== void 0) {
|
|
4049
|
+
return defaultValue;
|
|
4050
|
+
}
|
|
4051
|
+
if (isBrowser) {
|
|
4052
|
+
return document.visibilityState;
|
|
4053
|
+
}
|
|
4054
|
+
if (process.env.NODE_ENV !== "production") {
|
|
4055
|
+
console.warn(
|
|
4056
|
+
"`useDocumentVisibility` When server side rendering, defaultValue should be defined to prevent a hydration mismatches."
|
|
4057
|
+
);
|
|
4058
|
+
}
|
|
4059
|
+
return "visible";
|
|
4060
|
+
};
|
|
4061
|
+
function useDocumentVisibility(defaultValue) {
|
|
4062
|
+
const [visible, setVisible] = useState(
|
|
4063
|
+
getInitialState$1(defaultValue)
|
|
4064
|
+
);
|
|
4034
4065
|
useEventListener(
|
|
4035
4066
|
"visibilitychange",
|
|
4036
4067
|
() => {
|
|
@@ -4041,7 +4072,7 @@ function useDocumentVisibility() {
|
|
|
4041
4072
|
return visible;
|
|
4042
4073
|
}
|
|
4043
4074
|
|
|
4044
|
-
function useResizeObserver(target, callback, options =
|
|
4075
|
+
function useResizeObserver(target, callback, options = defaultOptions) {
|
|
4045
4076
|
const savedCallback = useLatest(callback);
|
|
4046
4077
|
const observerRef = useRef();
|
|
4047
4078
|
const element = useLatestElement(target);
|
|
@@ -4050,7 +4081,7 @@ function useResizeObserver(target, callback, options = {}) {
|
|
|
4050
4081
|
observerRef.current.disconnect();
|
|
4051
4082
|
}
|
|
4052
4083
|
}, []);
|
|
4053
|
-
|
|
4084
|
+
useEffect(() => {
|
|
4054
4085
|
if (!element) {
|
|
4055
4086
|
return;
|
|
4056
4087
|
}
|
|
@@ -4107,17 +4138,17 @@ function useDropZone(target, onDrop) {
|
|
|
4107
4138
|
}
|
|
4108
4139
|
|
|
4109
4140
|
var __defProp$2 = Object.defineProperty;
|
|
4110
|
-
var __getOwnPropSymbols$
|
|
4111
|
-
var __hasOwnProp$
|
|
4112
|
-
var __propIsEnum$
|
|
4141
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
4142
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
4143
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
4113
4144
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4114
4145
|
var __spreadValues$2 = (a, b) => {
|
|
4115
4146
|
for (var prop in b || (b = {}))
|
|
4116
|
-
if (__hasOwnProp$
|
|
4147
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
4117
4148
|
__defNormalProp$2(a, prop, b[prop]);
|
|
4118
|
-
if (__getOwnPropSymbols$
|
|
4119
|
-
for (var prop of __getOwnPropSymbols$
|
|
4120
|
-
if (__propIsEnum$
|
|
4149
|
+
if (__getOwnPropSymbols$2)
|
|
4150
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
4151
|
+
if (__propIsEnum$2.call(b, prop))
|
|
4121
4152
|
__defNormalProp$2(a, prop, b[prop]);
|
|
4122
4153
|
}
|
|
4123
4154
|
return a;
|
|
@@ -4126,7 +4157,7 @@ const DEFAULT_OPTIONS = {
|
|
|
4126
4157
|
multiple: true,
|
|
4127
4158
|
accept: "*"
|
|
4128
4159
|
};
|
|
4129
|
-
function useFileDialog(options =
|
|
4160
|
+
function useFileDialog(options = defaultOptions) {
|
|
4130
4161
|
const [files, setFiles] = useState(null);
|
|
4131
4162
|
const inputRef = useRef();
|
|
4132
4163
|
const initFn = useCallback(() => {
|
|
@@ -4162,7 +4193,11 @@ function useFileDialog(options = {}) {
|
|
|
4162
4193
|
}
|
|
4163
4194
|
|
|
4164
4195
|
const ARRIVED_STATE_THRESHOLD_PIXELS = 1;
|
|
4165
|
-
|
|
4196
|
+
const defaultListerOptions = {
|
|
4197
|
+
capture: false,
|
|
4198
|
+
passive: true
|
|
4199
|
+
};
|
|
4200
|
+
function useScroll(target, options = defaultOptions) {
|
|
4166
4201
|
const {
|
|
4167
4202
|
throttle = 0,
|
|
4168
4203
|
idle = 200,
|
|
@@ -4174,10 +4209,7 @@ function useScroll(target, options = {}) {
|
|
|
4174
4209
|
top: 0,
|
|
4175
4210
|
bottom: 0
|
|
4176
4211
|
},
|
|
4177
|
-
eventListenerOptions =
|
|
4178
|
-
capture: false,
|
|
4179
|
-
passive: true
|
|
4180
|
-
}
|
|
4212
|
+
eventListenerOptions = defaultListerOptions
|
|
4181
4213
|
} = options;
|
|
4182
4214
|
const [x, setX] = useState(0);
|
|
4183
4215
|
const [y, setY] = useState(0);
|
|
@@ -4236,17 +4268,17 @@ function useScroll(target, options = {}) {
|
|
|
4236
4268
|
var __defProp$1 = Object.defineProperty;
|
|
4237
4269
|
var __defProps = Object.defineProperties;
|
|
4238
4270
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4239
|
-
var __getOwnPropSymbols$
|
|
4240
|
-
var __hasOwnProp$
|
|
4241
|
-
var __propIsEnum$
|
|
4271
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
4272
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
4273
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
4242
4274
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4243
4275
|
var __spreadValues$1 = (a, b) => {
|
|
4244
4276
|
for (var prop in b || (b = {}))
|
|
4245
|
-
if (__hasOwnProp$
|
|
4277
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
4246
4278
|
__defNormalProp$1(a, prop, b[prop]);
|
|
4247
|
-
if (__getOwnPropSymbols$
|
|
4248
|
-
for (var prop of __getOwnPropSymbols$
|
|
4249
|
-
if (__propIsEnum$
|
|
4279
|
+
if (__getOwnPropSymbols$1)
|
|
4280
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
4281
|
+
if (__propIsEnum$1.call(b, prop))
|
|
4250
4282
|
__defNormalProp$1(a, prop, b[prop]);
|
|
4251
4283
|
}
|
|
4252
4284
|
return a;
|
|
@@ -4272,7 +4304,7 @@ var __async$3 = (__this, __arguments, generator) => {
|
|
|
4272
4304
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
4273
4305
|
});
|
|
4274
4306
|
};
|
|
4275
|
-
function useInfiniteScroll(target, onLoadMore, options =
|
|
4307
|
+
function useInfiniteScroll(target, onLoadMore, options = defaultOptions) {
|
|
4276
4308
|
var _a, _b;
|
|
4277
4309
|
const savedLoadMore = useLatest(onLoadMore);
|
|
4278
4310
|
const direction = (_a = options.direction) != null ? _a : "bottom";
|
|
@@ -4282,10 +4314,8 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
|
|
|
4282
4314
|
}, options.offset)
|
|
4283
4315
|
}));
|
|
4284
4316
|
const element = useLatestElement(target);
|
|
4285
|
-
const latestOptions = useLatest(options);
|
|
4286
4317
|
const di = state[3][direction];
|
|
4287
4318
|
useUpdateEffect(() => {
|
|
4288
|
-
const opts = latestOptions.current;
|
|
4289
4319
|
const fn = () => __async$3(this, null, function* () {
|
|
4290
4320
|
var _a2, _b2;
|
|
4291
4321
|
const previous = {
|
|
@@ -4293,7 +4323,7 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
|
|
|
4293
4323
|
width: (_b2 = element == null ? void 0 : element.scrollWidth) != null ? _b2 : 0
|
|
4294
4324
|
};
|
|
4295
4325
|
yield savedLoadMore.current(state);
|
|
4296
|
-
if (
|
|
4326
|
+
if (options.preserveScrollPosition && element) {
|
|
4297
4327
|
element.scrollTo({
|
|
4298
4328
|
top: element.scrollHeight - previous.height,
|
|
4299
4329
|
left: element.scrollWidth - previous.width
|
|
@@ -4301,7 +4331,7 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
|
|
|
4301
4331
|
}
|
|
4302
4332
|
});
|
|
4303
4333
|
fn();
|
|
4304
|
-
}, [di]);
|
|
4334
|
+
}, [di, options.preserveScrollPosition]);
|
|
4305
4335
|
}
|
|
4306
4336
|
|
|
4307
4337
|
const defaultEvents = [
|
|
@@ -4310,7 +4340,7 @@ const defaultEvents = [
|
|
|
4310
4340
|
"keydown",
|
|
4311
4341
|
"keyup"
|
|
4312
4342
|
];
|
|
4313
|
-
function useKeyModifier(modifier, options =
|
|
4343
|
+
function useKeyModifier(modifier, options = defaultOptions) {
|
|
4314
4344
|
const { events = defaultEvents, initial = false } = options;
|
|
4315
4345
|
const [state, setState] = useState(initial);
|
|
4316
4346
|
useMount(() => {
|
|
@@ -4334,7 +4364,8 @@ function useKeyModifier(modifier, options = {}) {
|
|
|
4334
4364
|
return state;
|
|
4335
4365
|
}
|
|
4336
4366
|
|
|
4337
|
-
|
|
4367
|
+
const listenerOptions$2 = { passive: true };
|
|
4368
|
+
function useMousePressed(target, options = defaultOptions) {
|
|
4338
4369
|
const { touch = true, drag = true, initialValue = false } = options;
|
|
4339
4370
|
const [pressed, setPressed] = useState(initialValue);
|
|
4340
4371
|
const [sourceType, setSourceType] = useState(null);
|
|
@@ -4350,31 +4381,27 @@ function useMousePressed(target, options = {}) {
|
|
|
4350
4381
|
setPressed(false);
|
|
4351
4382
|
setSourceType(null);
|
|
4352
4383
|
}, []);
|
|
4353
|
-
useEventListener("mousedown", onPressed("mouse"), target,
|
|
4354
|
-
useEventListener("mouseleave", onReleased, () => window,
|
|
4355
|
-
useEventListener("mouseup", onReleased, () => window,
|
|
4384
|
+
useEventListener("mousedown", onPressed("mouse"), target, listenerOptions$2);
|
|
4385
|
+
useEventListener("mouseleave", onReleased, () => window, listenerOptions$2);
|
|
4386
|
+
useEventListener("mouseup", onReleased, () => window, listenerOptions$2);
|
|
4356
4387
|
useEffect(() => {
|
|
4357
4388
|
if (drag) {
|
|
4358
|
-
element == null ? void 0 : element.addEventListener(
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
element == null ? void 0 : element.addEventListener("dragend", onReleased,
|
|
4365
|
-
passive: true
|
|
4366
|
-
});
|
|
4389
|
+
element == null ? void 0 : element.addEventListener(
|
|
4390
|
+
"dragstart",
|
|
4391
|
+
onPressed("mouse"),
|
|
4392
|
+
listenerOptions$2
|
|
4393
|
+
);
|
|
4394
|
+
element == null ? void 0 : element.addEventListener("drop", onReleased, listenerOptions$2);
|
|
4395
|
+
element == null ? void 0 : element.addEventListener("dragend", onReleased, listenerOptions$2);
|
|
4367
4396
|
}
|
|
4368
4397
|
if (touch) {
|
|
4369
|
-
element == null ? void 0 : element.addEventListener(
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
element == null ? void 0 : element.addEventListener("touchcancel", onReleased,
|
|
4376
|
-
passive: true
|
|
4377
|
-
});
|
|
4398
|
+
element == null ? void 0 : element.addEventListener(
|
|
4399
|
+
"touchstart",
|
|
4400
|
+
onPressed("touch"),
|
|
4401
|
+
listenerOptions$2
|
|
4402
|
+
);
|
|
4403
|
+
element == null ? void 0 : element.addEventListener("touchend", onReleased, listenerOptions$2);
|
|
4404
|
+
element == null ? void 0 : element.addEventListener("touchcancel", onReleased, listenerOptions$2);
|
|
4378
4405
|
}
|
|
4379
4406
|
return () => {
|
|
4380
4407
|
if (drag) {
|
|
@@ -4445,7 +4472,7 @@ function useScrollLock(target, initialState = false) {
|
|
|
4445
4472
|
return [locked, set];
|
|
4446
4473
|
}
|
|
4447
4474
|
|
|
4448
|
-
function useElementSize(target, options =
|
|
4475
|
+
function useElementSize(target, options = defaultOptions) {
|
|
4449
4476
|
const { box = "content-box" } = options;
|
|
4450
4477
|
const [width, setWidth] = useState(0);
|
|
4451
4478
|
const [height, setHeight] = useState(0);
|
|
@@ -4472,44 +4499,38 @@ function useVirtualList(list = [], options) {
|
|
|
4472
4499
|
const [currentList, setCurrentList] = useState([]);
|
|
4473
4500
|
const { itemHeight, overscan = 5, containerHeight = 300 } = options;
|
|
4474
4501
|
const state = useRef({ start: 0, end: 10 });
|
|
4475
|
-
const getViewCapacity =
|
|
4476
|
-
(
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
break;
|
|
4489
|
-
}
|
|
4502
|
+
const getViewCapacity = (containerHeight2) => {
|
|
4503
|
+
if (typeof itemHeight === "number") {
|
|
4504
|
+
return Math.ceil(containerHeight2 / itemHeight);
|
|
4505
|
+
}
|
|
4506
|
+
const { start = 0 } = state.current;
|
|
4507
|
+
let sum = 0;
|
|
4508
|
+
let capacity = 0;
|
|
4509
|
+
for (let i = start; i < list.length; i++) {
|
|
4510
|
+
const height2 = itemHeight(i);
|
|
4511
|
+
sum += height2;
|
|
4512
|
+
if (sum >= containerHeight2) {
|
|
4513
|
+
capacity = i;
|
|
4514
|
+
break;
|
|
4490
4515
|
}
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
)
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
offset = i;
|
|
4506
|
-
break;
|
|
4507
|
-
}
|
|
4516
|
+
}
|
|
4517
|
+
return capacity - start;
|
|
4518
|
+
};
|
|
4519
|
+
const getOffset = (scrollTop) => {
|
|
4520
|
+
if (typeof itemHeight === "number")
|
|
4521
|
+
return Math.floor(scrollTop / itemHeight) + 1;
|
|
4522
|
+
let sum = 0;
|
|
4523
|
+
let offset = 0;
|
|
4524
|
+
for (let i = 0; i < list.length; i++) {
|
|
4525
|
+
const height2 = itemHeight(i);
|
|
4526
|
+
sum += height2;
|
|
4527
|
+
if (sum >= scrollTop) {
|
|
4528
|
+
offset = i;
|
|
4529
|
+
break;
|
|
4508
4530
|
}
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
);
|
|
4531
|
+
}
|
|
4532
|
+
return offset + 1;
|
|
4533
|
+
};
|
|
4513
4534
|
const calculateRange = useEvent(() => {
|
|
4514
4535
|
const element = containerRef.current;
|
|
4515
4536
|
if (element != null) {
|
|
@@ -4521,17 +4542,18 @@ function useVirtualList(list = [], options) {
|
|
|
4521
4542
|
start: from < 0 ? 0 : from,
|
|
4522
4543
|
end: to > list.length ? list.length : to
|
|
4523
4544
|
};
|
|
4545
|
+
const { start, end } = state.current;
|
|
4524
4546
|
setCurrentList(
|
|
4525
|
-
list.slice(
|
|
4547
|
+
list.slice(start, end).map((ele, index) => ({
|
|
4526
4548
|
data: ele,
|
|
4527
|
-
index: index +
|
|
4549
|
+
index: index + start
|
|
4528
4550
|
}))
|
|
4529
4551
|
);
|
|
4530
4552
|
}
|
|
4531
4553
|
});
|
|
4532
4554
|
useEffect(() => {
|
|
4533
4555
|
calculateRange();
|
|
4534
|
-
}, [width, height, list
|
|
4556
|
+
}, [width, height, list]);
|
|
4535
4557
|
const totalHeight = useMemo(() => {
|
|
4536
4558
|
if (typeof itemHeight === "number") {
|
|
4537
4559
|
return list.length * itemHeight;
|
|
@@ -4549,16 +4571,7 @@ function useVirtualList(list = [], options) {
|
|
|
4549
4571
|
},
|
|
4550
4572
|
[itemHeight, list]
|
|
4551
4573
|
);
|
|
4552
|
-
const
|
|
4553
|
-
if (containerRef.current) {
|
|
4554
|
-
containerRef.current.scrollTop = getDistanceTop(index);
|
|
4555
|
-
calculateRange();
|
|
4556
|
-
}
|
|
4557
|
-
});
|
|
4558
|
-
const offsetTop = useMemo(
|
|
4559
|
-
() => getDistanceTop(state.current.start),
|
|
4560
|
-
[getDistanceTop]
|
|
4561
|
-
);
|
|
4574
|
+
const offsetTop = getDistanceTop(state.current.start);
|
|
4562
4575
|
const wrapperProps = useMemo(() => {
|
|
4563
4576
|
return {
|
|
4564
4577
|
style: {
|
|
@@ -4567,7 +4580,13 @@ function useVirtualList(list = [], options) {
|
|
|
4567
4580
|
marginTop: `${offsetTop}px`
|
|
4568
4581
|
}
|
|
4569
4582
|
};
|
|
4570
|
-
}, [
|
|
4583
|
+
}, [totalHeight, offsetTop]);
|
|
4584
|
+
const scrollTo = (index) => {
|
|
4585
|
+
if (containerRef.current) {
|
|
4586
|
+
containerRef.current.scrollTop = getDistanceTop(index);
|
|
4587
|
+
calculateRange();
|
|
4588
|
+
}
|
|
4589
|
+
};
|
|
4571
4590
|
const containerStyle = useMemo(() => {
|
|
4572
4591
|
return { overflowY: "auto", height: containerHeight };
|
|
4573
4592
|
}, [containerHeight]);
|
|
@@ -4693,7 +4712,7 @@ function useDraggable(target, options = {}) {
|
|
|
4693
4712
|
return [position.x, position.y, !!pressedDelta];
|
|
4694
4713
|
}
|
|
4695
4714
|
|
|
4696
|
-
function useElementBounding(target, options =
|
|
4715
|
+
function useElementBounding(target, options = defaultOptions) {
|
|
4697
4716
|
const {
|
|
4698
4717
|
reset = true,
|
|
4699
4718
|
windowResize = true,
|
|
@@ -4768,7 +4787,7 @@ function useElementBounding(target, options = {}) {
|
|
|
4768
4787
|
};
|
|
4769
4788
|
}
|
|
4770
4789
|
|
|
4771
|
-
function useElementVisibility(target, options =
|
|
4790
|
+
function useElementVisibility(target, options = defaultOptions) {
|
|
4772
4791
|
const [visible, setVisible] = useState(false);
|
|
4773
4792
|
const callback = useCallback((entries) => {
|
|
4774
4793
|
const rect = entries[0].boundingClientRect;
|
|
@@ -4780,13 +4799,11 @@ function useElementVisibility(target, options = {}) {
|
|
|
4780
4799
|
return [visible, stop];
|
|
4781
4800
|
}
|
|
4782
4801
|
|
|
4783
|
-
function useWindowsFocus() {
|
|
4784
|
-
const [focused, setFocused] = useState(
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
return window.document.hasFocus();
|
|
4789
|
-
});
|
|
4802
|
+
function useWindowsFocus(defauleValue = false) {
|
|
4803
|
+
const [focused, setFocused] = useState(defauleValue);
|
|
4804
|
+
useEffect(() => {
|
|
4805
|
+
setFocused(window.document.hasFocus());
|
|
4806
|
+
}, []);
|
|
4790
4807
|
useEventListener("blur", () => {
|
|
4791
4808
|
setFocused(false);
|
|
4792
4809
|
});
|
|
@@ -4814,6 +4831,10 @@ function useWindowSize() {
|
|
|
4814
4831
|
return windowSize;
|
|
4815
4832
|
}
|
|
4816
4833
|
|
|
4834
|
+
const listenerOptions$1 = {
|
|
4835
|
+
capture: false,
|
|
4836
|
+
passive: true
|
|
4837
|
+
};
|
|
4817
4838
|
function useWindowScroll() {
|
|
4818
4839
|
const [state, setState] = useRafState(() => ({
|
|
4819
4840
|
x: 0,
|
|
@@ -4822,10 +4843,7 @@ function useWindowScroll() {
|
|
|
4822
4843
|
const handleScroll = () => {
|
|
4823
4844
|
setState({ x: window.scrollX, y: window.scrollY });
|
|
4824
4845
|
};
|
|
4825
|
-
useEventListener("scroll", handleScroll, window,
|
|
4826
|
-
capture: false,
|
|
4827
|
-
passive: true
|
|
4828
|
-
});
|
|
4846
|
+
useEventListener("scroll", handleScroll, window, listenerOptions$1);
|
|
4829
4847
|
useIsomorphicLayoutEffect(() => {
|
|
4830
4848
|
handleScroll();
|
|
4831
4849
|
}, []);
|
|
@@ -5097,17 +5115,16 @@ const getRelativePosition = ({
|
|
|
5097
5115
|
return 0;
|
|
5098
5116
|
};
|
|
5099
5117
|
|
|
5100
|
-
|
|
5118
|
+
const listenerOptions = { passive: true };
|
|
5119
|
+
function useScrollIntoView(targetElement, {
|
|
5101
5120
|
duration = 1250,
|
|
5102
5121
|
axis = "y",
|
|
5103
5122
|
onScrollFinish,
|
|
5104
5123
|
easing = easeInOutQuad,
|
|
5105
5124
|
offset = 0,
|
|
5106
5125
|
cancelable = true,
|
|
5107
|
-
isList = false
|
|
5108
|
-
|
|
5109
|
-
scrollElement
|
|
5110
|
-
}) {
|
|
5126
|
+
isList = false
|
|
5127
|
+
} = defaultOptions, scrollElement) {
|
|
5111
5128
|
const frameID = useRef(0);
|
|
5112
5129
|
const startTime = useRef(0);
|
|
5113
5130
|
const shouldStop = useRef(false);
|
|
@@ -5165,8 +5182,8 @@ function useScrollIntoView({
|
|
|
5165
5182
|
shouldStop.current = true;
|
|
5166
5183
|
}
|
|
5167
5184
|
};
|
|
5168
|
-
useEventListener("wheel", handleStop, null,
|
|
5169
|
-
useEventListener("touchmove", handleStop, null,
|
|
5185
|
+
useEventListener("wheel", handleStop, null, listenerOptions);
|
|
5186
|
+
useEventListener("touchmove", handleStop, null, listenerOptions);
|
|
5170
5187
|
useEffect(() => cancel, []);
|
|
5171
5188
|
return {
|
|
5172
5189
|
scrollIntoView,
|
|
@@ -5174,12 +5191,7 @@ function useScrollIntoView({
|
|
|
5174
5191
|
};
|
|
5175
5192
|
}
|
|
5176
5193
|
|
|
5177
|
-
const useSticky = ({
|
|
5178
|
-
targetElement,
|
|
5179
|
-
scrollElement,
|
|
5180
|
-
axis = "y",
|
|
5181
|
-
nav = 0
|
|
5182
|
-
}) => {
|
|
5194
|
+
const useSticky = (targetElement, { axis = "y", nav = 0 }, scrollElement) => {
|
|
5183
5195
|
const [isSticky, setSticky] = useState(false);
|
|
5184
5196
|
const element = useLatestElement(targetElement);
|
|
5185
5197
|
const { run: scrollHandler } = useThrottleFn(() => {
|
|
@@ -5463,54 +5475,51 @@ function init (converter, defaultAttributes) {
|
|
|
5463
5475
|
|
|
5464
5476
|
var api = init(defaultConverter, { path: '/' });
|
|
5465
5477
|
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
return target;
|
|
5478
|
+
const getInitialState = (key, defaultValue) => {
|
|
5479
|
+
if (defaultValue !== void 0) {
|
|
5480
|
+
return defaultValue;
|
|
5481
|
+
}
|
|
5482
|
+
if (isBrowser) {
|
|
5483
|
+
return api.get(key);
|
|
5484
|
+
}
|
|
5485
|
+
if (process.env.NODE_ENV !== "production") {
|
|
5486
|
+
console.warn(
|
|
5487
|
+
"`useCookie` When server side rendering, defaultValue should be defined to prevent a hydration mismatches."
|
|
5488
|
+
);
|
|
5489
|
+
}
|
|
5490
|
+
return "";
|
|
5480
5491
|
};
|
|
5481
|
-
function useCookie(key, options = {
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
useDeepCompareEffect(() => {
|
|
5487
|
-
const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : isFunction$1(defaultValue) ? defaultValue() : defaultValue;
|
|
5492
|
+
function useCookie(key, options = defaultOptions, defaultValue) {
|
|
5493
|
+
const [cookieValue, setCookieValue] = useState(
|
|
5494
|
+
getInitialState(key, defaultValue)
|
|
5495
|
+
);
|
|
5496
|
+
useEffect(() => {
|
|
5488
5497
|
const getStoredValue = () => {
|
|
5489
5498
|
const raw = api.get(key);
|
|
5490
5499
|
if (raw !== void 0 && raw !== null) {
|
|
5491
5500
|
return raw;
|
|
5492
5501
|
} else {
|
|
5493
|
-
if (
|
|
5502
|
+
if (defaultValue === void 0) {
|
|
5494
5503
|
api.remove(key);
|
|
5495
5504
|
} else {
|
|
5496
|
-
api.set(key,
|
|
5505
|
+
api.set(key, defaultValue, options);
|
|
5497
5506
|
}
|
|
5498
|
-
return
|
|
5507
|
+
return defaultValue;
|
|
5499
5508
|
}
|
|
5500
5509
|
};
|
|
5501
5510
|
setCookieValue(getStoredValue());
|
|
5502
|
-
}, [
|
|
5511
|
+
}, [defaultValue, key, options]);
|
|
5503
5512
|
const updateCookie = useCallback(
|
|
5504
5513
|
(newValue) => {
|
|
5505
5514
|
const value = isFunction$1(newValue) ? newValue(cookieValue) : newValue;
|
|
5506
5515
|
if (value === void 0) {
|
|
5507
5516
|
api.remove(key);
|
|
5508
5517
|
} else {
|
|
5509
|
-
api.set(key, value,
|
|
5518
|
+
api.set(key, value, options);
|
|
5510
5519
|
}
|
|
5511
5520
|
setCookieValue(value);
|
|
5512
5521
|
},
|
|
5513
|
-
[key, cookieValue]
|
|
5522
|
+
[key, cookieValue, options]
|
|
5514
5523
|
);
|
|
5515
5524
|
const refreshCookie = useCallback(() => {
|
|
5516
5525
|
const cookieValue2 = api.get(key);
|
|
@@ -5518,7 +5527,7 @@ function useCookie(key, options = {
|
|
|
5518
5527
|
setCookieValue(cookieValue2);
|
|
5519
5528
|
}
|
|
5520
5529
|
}, [key]);
|
|
5521
|
-
return
|
|
5530
|
+
return [cookieValue, updateCookie, refreshCookie];
|
|
5522
5531
|
}
|
|
5523
5532
|
|
|
5524
5533
|
function useDoubleClick({
|
|
@@ -5592,7 +5601,7 @@ const defaultState = {
|
|
|
5592
5601
|
bottom: 0,
|
|
5593
5602
|
right: 0
|
|
5594
5603
|
};
|
|
5595
|
-
function useMeasure(target, options =
|
|
5604
|
+
function useMeasure(target, options = defaultOptions) {
|
|
5596
5605
|
const [rect, setRect] = useState(defaultState);
|
|
5597
5606
|
const stop = useResizeObserver(
|
|
5598
5607
|
target,
|