@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.cjs
CHANGED
|
@@ -58,7 +58,7 @@ const isIOS = isBrowser && ((_a = window == null ? void 0 : window.navigator) ==
|
|
|
58
58
|
!React__default["default"].useId;
|
|
59
59
|
|
|
60
60
|
function guessSerializerType(rawInit) {
|
|
61
|
-
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";
|
|
61
|
+
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";
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
@@ -81,6 +81,283 @@ function useEvent(fn) {
|
|
|
81
81
|
}, []);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
const defaultOptions = {};
|
|
85
|
+
const defaultOnError = (e) => {
|
|
86
|
+
console.error(e);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const StorageSerializers = {
|
|
90
|
+
boolean: {
|
|
91
|
+
read: (v) => v === "true",
|
|
92
|
+
write: (v) => String(v)
|
|
93
|
+
},
|
|
94
|
+
object: {
|
|
95
|
+
read: (v) => JSON.parse(v),
|
|
96
|
+
write: (v) => JSON.stringify(v)
|
|
97
|
+
},
|
|
98
|
+
number: {
|
|
99
|
+
read: (v) => Number.parseFloat(v),
|
|
100
|
+
write: (v) => String(v)
|
|
101
|
+
},
|
|
102
|
+
any: {
|
|
103
|
+
read: (v) => v,
|
|
104
|
+
write: (v) => String(v)
|
|
105
|
+
},
|
|
106
|
+
string: {
|
|
107
|
+
read: (v) => v,
|
|
108
|
+
write: (v) => String(v)
|
|
109
|
+
},
|
|
110
|
+
map: {
|
|
111
|
+
read: (v) => new Map(JSON.parse(v)),
|
|
112
|
+
write: (v) => JSON.stringify(Array.from(v.entries()))
|
|
113
|
+
},
|
|
114
|
+
set: {
|
|
115
|
+
read: (v) => new Set(JSON.parse(v)),
|
|
116
|
+
write: (v) => JSON.stringify(Array.from(v))
|
|
117
|
+
},
|
|
118
|
+
date: {
|
|
119
|
+
read: (v) => new Date(v),
|
|
120
|
+
write: (v) => v.toISOString()
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const getInitialState$3 = (key, defaultValue, storage, serializer, onError) => {
|
|
124
|
+
if (defaultValue !== void 0) {
|
|
125
|
+
return defaultValue;
|
|
126
|
+
}
|
|
127
|
+
if (isBrowser) {
|
|
128
|
+
try {
|
|
129
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
130
|
+
if (raw !== void 0 && raw !== null) {
|
|
131
|
+
return serializer == null ? void 0 : serializer.read(raw);
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
onError == null ? void 0 : onError(error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (process.env.NODE_ENV !== "production") {
|
|
138
|
+
console.warn(
|
|
139
|
+
"`createStorage` When server side rendering, defaultValue should be defined to prevent a hydration mismatches."
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
function useStorage(key, defaultValue, getStorage = () => isBrowser ? sessionStorage : void 0, options = defaultOptions) {
|
|
145
|
+
let storage;
|
|
146
|
+
const { onError = defaultOnError, csrData } = options;
|
|
147
|
+
try {
|
|
148
|
+
storage = getStorage();
|
|
149
|
+
} catch (err) {
|
|
150
|
+
onError(err);
|
|
151
|
+
}
|
|
152
|
+
const type = guessSerializerType(defaultValue);
|
|
153
|
+
const serializer = React.useMemo(() => {
|
|
154
|
+
var _a;
|
|
155
|
+
return (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
156
|
+
}, [options.serializer, type]);
|
|
157
|
+
const [state, setState] = React.useState(
|
|
158
|
+
getInitialState$3(key, defaultValue, storage, serializer, onError)
|
|
159
|
+
);
|
|
160
|
+
React.useEffect(() => {
|
|
161
|
+
const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : defaultValue;
|
|
162
|
+
const getStoredValue = () => {
|
|
163
|
+
try {
|
|
164
|
+
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
165
|
+
if (raw !== void 0 && raw !== null) {
|
|
166
|
+
return serializer.read(raw);
|
|
167
|
+
} else {
|
|
168
|
+
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
169
|
+
return data;
|
|
170
|
+
}
|
|
171
|
+
} catch (e) {
|
|
172
|
+
onError(e);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
setState(getStoredValue());
|
|
176
|
+
}, [key, defaultValue, serializer, storage, onError, csrData]);
|
|
177
|
+
const updateState = useEvent(
|
|
178
|
+
(valOrFunc) => {
|
|
179
|
+
const currentState = isFunction$1(valOrFunc) ? valOrFunc(state) : valOrFunc;
|
|
180
|
+
setState(currentState);
|
|
181
|
+
if (currentState === null) {
|
|
182
|
+
storage == null ? void 0 : storage.removeItem(key);
|
|
183
|
+
} else {
|
|
184
|
+
try {
|
|
185
|
+
storage == null ? void 0 : storage.setItem(key, serializer.write(currentState));
|
|
186
|
+
} catch (e) {
|
|
187
|
+
onError(e);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
return [state, updateState];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function useLocalStorage(key, defaultValue, options = defaultOptions) {
|
|
196
|
+
return useStorage(
|
|
197
|
+
key,
|
|
198
|
+
defaultValue,
|
|
199
|
+
() => isBrowser ? localStorage : void 0,
|
|
200
|
+
options
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function useSessionStorage(key, defaultValue, options = defaultOptions) {
|
|
205
|
+
return useStorage(
|
|
206
|
+
key,
|
|
207
|
+
defaultValue,
|
|
208
|
+
() => isBrowser ? sessionStorage : void 0,
|
|
209
|
+
options
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const toggleReducer = (state, nextValue) => typeof nextValue === "boolean" ? nextValue : !state;
|
|
214
|
+
function useToggle(initialValue) {
|
|
215
|
+
return React.useReducer(toggleReducer, initialValue);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function useInterval(callback, delay, options = defaultOptions) {
|
|
219
|
+
const immediate = options.immediate;
|
|
220
|
+
const savedCallback = useLatest(callback);
|
|
221
|
+
React.useEffect(() => {
|
|
222
|
+
if (immediate) {
|
|
223
|
+
savedCallback.current();
|
|
224
|
+
}
|
|
225
|
+
if (delay !== null) {
|
|
226
|
+
const interval = setInterval(() => savedCallback.current(), delay || 0);
|
|
227
|
+
return () => clearInterval(interval);
|
|
228
|
+
}
|
|
229
|
+
return void 0;
|
|
230
|
+
}, [delay, immediate]);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function useDarkMode(options) {
|
|
234
|
+
const {
|
|
235
|
+
selector = "html",
|
|
236
|
+
attribute = "class",
|
|
237
|
+
classNameDark = "",
|
|
238
|
+
classNameLight = "",
|
|
239
|
+
storageKey = "reactuses-color-scheme",
|
|
240
|
+
storage = () => isBrowser ? localStorage : void 0,
|
|
241
|
+
defaultValue = false
|
|
242
|
+
} = options;
|
|
243
|
+
const value = () => {
|
|
244
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
245
|
+
};
|
|
246
|
+
const [dark, setDark] = useStorage(
|
|
247
|
+
storageKey,
|
|
248
|
+
defaultValue,
|
|
249
|
+
storage,
|
|
250
|
+
{
|
|
251
|
+
csrData: value
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
React.useEffect(() => {
|
|
255
|
+
const element = window == null ? void 0 : window.document.querySelector(selector);
|
|
256
|
+
if (!element) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (attribute === "class") {
|
|
260
|
+
dark && classNameDark && element.classList.add(classNameDark);
|
|
261
|
+
!dark && classNameLight && element.classList.add(classNameLight);
|
|
262
|
+
} else {
|
|
263
|
+
dark && classNameDark && element.setAttribute(attribute, classNameDark);
|
|
264
|
+
!dark && classNameLight && element.setAttribute(attribute, classNameLight);
|
|
265
|
+
}
|
|
266
|
+
return () => {
|
|
267
|
+
if (!element) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (attribute === "class") {
|
|
271
|
+
dark && classNameDark && element.classList.remove(classNameDark);
|
|
272
|
+
!dark && classNameLight && element.classList.remove(classNameLight);
|
|
273
|
+
} else {
|
|
274
|
+
dark && classNameDark && element.removeAttribute(attribute);
|
|
275
|
+
!dark && classNameLight && element.removeAttribute(attribute);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}, [attribute, classNameDark, classNameLight, dark, selector]);
|
|
279
|
+
return [dark, () => setDark((dark2) => !dark2), setDark];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const getInitialState$2 = (query, defaultState) => {
|
|
283
|
+
if (defaultState !== void 0) {
|
|
284
|
+
return defaultState;
|
|
285
|
+
}
|
|
286
|
+
if (isBrowser) {
|
|
287
|
+
return window.matchMedia(query).matches;
|
|
288
|
+
}
|
|
289
|
+
if (process.env.NODE_ENV !== "production") {
|
|
290
|
+
console.warn(
|
|
291
|
+
"`useMediaQuery` When server side rendering, defaultState should be defined to prevent a hydration mismatches."
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
return false;
|
|
295
|
+
};
|
|
296
|
+
function useMediaQuery(query, defaultState) {
|
|
297
|
+
const [state, setState] = React.useState(getInitialState$2(query, defaultState));
|
|
298
|
+
React.useEffect(() => {
|
|
299
|
+
var _a;
|
|
300
|
+
let mounted = true;
|
|
301
|
+
const mql = window.matchMedia(query);
|
|
302
|
+
const onChange = () => {
|
|
303
|
+
if (!mounted) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
setState(!!mql.matches);
|
|
307
|
+
};
|
|
308
|
+
if ("addEventListener" in mql) {
|
|
309
|
+
mql.addEventListener("change", onChange);
|
|
310
|
+
} else {
|
|
311
|
+
(_a = mql.addListener) == null ? void 0 : _a.call(mql, onChange);
|
|
312
|
+
}
|
|
313
|
+
setState(mql.matches);
|
|
314
|
+
return () => {
|
|
315
|
+
var _a2;
|
|
316
|
+
mounted = false;
|
|
317
|
+
if ("removeEventListener" in mql) {
|
|
318
|
+
mql.removeEventListener("change", onChange);
|
|
319
|
+
} else {
|
|
320
|
+
(_a2 = mql.removeListener) == null ? void 0 : _a2.call(mql, onChange);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}, [query]);
|
|
324
|
+
return state;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function usePreferredDark(defaultState) {
|
|
328
|
+
return useMediaQuery("(prefers-color-scheme: dark)", defaultState);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function useMount(fn) {
|
|
332
|
+
if (isDev) {
|
|
333
|
+
if (!isFunction$1(fn)) {
|
|
334
|
+
console.error(
|
|
335
|
+
`useMount: parameter \`fn\` expected to be a function, but got "${typeof fn}".`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
React.useEffect(() => {
|
|
340
|
+
fn == null ? void 0 : fn();
|
|
341
|
+
}, []);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function useUnmount(fn) {
|
|
345
|
+
if (isDev) {
|
|
346
|
+
if (!isFunction$1(fn)) {
|
|
347
|
+
console.error(
|
|
348
|
+
`useUnmount expected parameter is a function, got ${typeof fn}`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const fnRef = useLatest(fn);
|
|
353
|
+
React.useEffect(
|
|
354
|
+
() => () => {
|
|
355
|
+
fnRef.current();
|
|
356
|
+
},
|
|
357
|
+
[fnRef]
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
84
361
|
/** Detect free variable `global` from Node.js. */
|
|
85
362
|
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
|
86
363
|
|
|
@@ -2396,390 +2673,95 @@ function debounce(func, wait, options) {
|
|
|
2396
2673
|
*
|
|
2397
2674
|
* **Note:** This method supports comparing arrays, array buffers, booleans,
|
|
2398
2675
|
* date objects, error objects, maps, numbers, `Object` objects, regexes,
|
|
2399
|
-
* sets, strings, symbols, and typed arrays. `Object` objects are compared
|
|
2400
|
-
* by their own, not inherited, enumerable properties. Functions and DOM
|
|
2401
|
-
* nodes are compared by strict equality, i.e. `===`.
|
|
2402
|
-
*
|
|
2403
|
-
* @static
|
|
2404
|
-
* @memberOf _
|
|
2405
|
-
* @since 0.1.0
|
|
2406
|
-
* @category Lang
|
|
2407
|
-
* @param {*} value The value to compare.
|
|
2408
|
-
* @param {*} other The other value to compare.
|
|
2409
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
2410
|
-
* @example
|
|
2411
|
-
*
|
|
2412
|
-
* var object = { 'a': 1 };
|
|
2413
|
-
* var other = { 'a': 1 };
|
|
2414
|
-
*
|
|
2415
|
-
* _.isEqual(object, other);
|
|
2416
|
-
* // => true
|
|
2417
|
-
*
|
|
2418
|
-
* object === other;
|
|
2419
|
-
* // => false
|
|
2420
|
-
*/
|
|
2421
|
-
function isEqual(value, other) {
|
|
2422
|
-
return baseIsEqual(value, other);
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
|
-
/** Error message constants. */
|
|
2426
|
-
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
2427
|
-
|
|
2428
|
-
/**
|
|
2429
|
-
* Creates a throttled function that only invokes `func` at most once per
|
|
2430
|
-
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
2431
|
-
* method to cancel delayed `func` invocations and a `flush` method to
|
|
2432
|
-
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
2433
|
-
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
2434
|
-
* timeout. The `func` is invoked with the last arguments provided to the
|
|
2435
|
-
* throttled function. Subsequent calls to the throttled function return the
|
|
2436
|
-
* result of the last `func` invocation.
|
|
2437
|
-
*
|
|
2438
|
-
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
2439
|
-
* invoked on the trailing edge of the timeout only if the throttled function
|
|
2440
|
-
* is invoked more than once during the `wait` timeout.
|
|
2441
|
-
*
|
|
2442
|
-
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
2443
|
-
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
2444
|
-
*
|
|
2445
|
-
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
2446
|
-
* for details over the differences between `_.throttle` and `_.debounce`.
|
|
2447
|
-
*
|
|
2448
|
-
* @static
|
|
2449
|
-
* @memberOf _
|
|
2450
|
-
* @since 0.1.0
|
|
2451
|
-
* @category Function
|
|
2452
|
-
* @param {Function} func The function to throttle.
|
|
2453
|
-
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
|
2454
|
-
* @param {Object} [options={}] The options object.
|
|
2455
|
-
* @param {boolean} [options.leading=true]
|
|
2456
|
-
* Specify invoking on the leading edge of the timeout.
|
|
2457
|
-
* @param {boolean} [options.trailing=true]
|
|
2458
|
-
* Specify invoking on the trailing edge of the timeout.
|
|
2459
|
-
* @returns {Function} Returns the new throttled function.
|
|
2460
|
-
* @example
|
|
2461
|
-
*
|
|
2462
|
-
* // Avoid excessively updating the position while scrolling.
|
|
2463
|
-
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|
2464
|
-
*
|
|
2465
|
-
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
|
2466
|
-
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
|
2467
|
-
* jQuery(element).on('click', throttled);
|
|
2468
|
-
*
|
|
2469
|
-
* // Cancel the trailing throttled invocation.
|
|
2470
|
-
* jQuery(window).on('popstate', throttled.cancel);
|
|
2471
|
-
*/
|
|
2472
|
-
function throttle(func, wait, options) {
|
|
2473
|
-
var leading = true,
|
|
2474
|
-
trailing = true;
|
|
2475
|
-
|
|
2476
|
-
if (typeof func != 'function') {
|
|
2477
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
2478
|
-
}
|
|
2479
|
-
if (isObject(options)) {
|
|
2480
|
-
leading = 'leading' in options ? !!options.leading : leading;
|
|
2481
|
-
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
2482
|
-
}
|
|
2483
|
-
return debounce(func, wait, {
|
|
2484
|
-
'leading': leading,
|
|
2485
|
-
'maxWait': wait,
|
|
2486
|
-
'trailing': trailing
|
|
2487
|
-
});
|
|
2488
|
-
}
|
|
2489
|
-
|
|
2490
|
-
const isPrimitive$1 = (val) => val !== Object(val);
|
|
2491
|
-
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
2492
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2493
|
-
if (!Array.isArray(deps) || !deps.length) {
|
|
2494
|
-
console.warn(
|
|
2495
|
-
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
2496
|
-
);
|
|
2497
|
-
}
|
|
2498
|
-
if (deps.every(isPrimitive$1)) {
|
|
2499
|
-
console.warn(
|
|
2500
|
-
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
2501
|
-
);
|
|
2502
|
-
}
|
|
2503
|
-
if (typeof depsEqual !== "function") {
|
|
2504
|
-
console.warn(
|
|
2505
|
-
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
2506
|
-
);
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
const ref = React.useRef(void 0);
|
|
2510
|
-
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
2511
|
-
ref.current = deps;
|
|
2512
|
-
}
|
|
2513
|
-
React.useEffect(effect, ref.current);
|
|
2514
|
-
}
|
|
2515
|
-
|
|
2516
|
-
const isPrimitive = (val) => val !== Object(val);
|
|
2517
|
-
function useDeepCompareEffect(effect, deps) {
|
|
2518
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2519
|
-
if (!Array.isArray(deps) || !deps.length) {
|
|
2520
|
-
console.warn(
|
|
2521
|
-
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
2522
|
-
);
|
|
2523
|
-
}
|
|
2524
|
-
if (deps.every(isPrimitive)) {
|
|
2525
|
-
console.warn(
|
|
2526
|
-
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
2527
|
-
);
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
useCustomCompareEffect(effect, deps, isEqual);
|
|
2531
|
-
}
|
|
2532
|
-
|
|
2533
|
-
const StorageSerializers = {
|
|
2534
|
-
boolean: {
|
|
2535
|
-
read: (v) => v === "true",
|
|
2536
|
-
write: (v) => String(v)
|
|
2537
|
-
},
|
|
2538
|
-
object: {
|
|
2539
|
-
read: (v) => JSON.parse(v),
|
|
2540
|
-
write: (v) => JSON.stringify(v)
|
|
2541
|
-
},
|
|
2542
|
-
number: {
|
|
2543
|
-
read: (v) => Number.parseFloat(v),
|
|
2544
|
-
write: (v) => String(v)
|
|
2545
|
-
},
|
|
2546
|
-
any: {
|
|
2547
|
-
read: (v) => v,
|
|
2548
|
-
write: (v) => String(v)
|
|
2549
|
-
},
|
|
2550
|
-
string: {
|
|
2551
|
-
read: (v) => v,
|
|
2552
|
-
write: (v) => String(v)
|
|
2553
|
-
},
|
|
2554
|
-
map: {
|
|
2555
|
-
read: (v) => new Map(JSON.parse(v)),
|
|
2556
|
-
write: (v) => JSON.stringify(Array.from(v.entries()))
|
|
2557
|
-
},
|
|
2558
|
-
set: {
|
|
2559
|
-
read: (v) => new Set(JSON.parse(v)),
|
|
2560
|
-
write: (v) => JSON.stringify(Array.from(v))
|
|
2561
|
-
},
|
|
2562
|
-
date: {
|
|
2563
|
-
read: (v) => new Date(v),
|
|
2564
|
-
write: (v) => v.toISOString()
|
|
2565
|
-
}
|
|
2566
|
-
};
|
|
2567
|
-
function useStorage(key, defaults, getStorage, options = {}) {
|
|
2568
|
-
const defaultOnError = React.useCallback((e) => {
|
|
2569
|
-
console.error(e);
|
|
2570
|
-
}, []);
|
|
2571
|
-
let storage;
|
|
2572
|
-
const { onError = defaultOnError, csrData } = options;
|
|
2573
|
-
try {
|
|
2574
|
-
storage = getStorage();
|
|
2575
|
-
} catch (err) {
|
|
2576
|
-
onError(err);
|
|
2577
|
-
}
|
|
2578
|
-
const type = guessSerializerType(defaults);
|
|
2579
|
-
const serializer = React.useMemo(() => {
|
|
2580
|
-
var _a;
|
|
2581
|
-
return (_a = options.serializer) != null ? _a : StorageSerializers[type];
|
|
2582
|
-
}, [options.serializer, type]);
|
|
2583
|
-
const [state, setState] = React.useState(defaults);
|
|
2584
|
-
useDeepCompareEffect(() => {
|
|
2585
|
-
const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : defaults;
|
|
2586
|
-
const getStoredValue = () => {
|
|
2587
|
-
try {
|
|
2588
|
-
const raw = storage == null ? void 0 : storage.getItem(key);
|
|
2589
|
-
if (raw !== void 0 && raw !== null) {
|
|
2590
|
-
return serializer.read(raw);
|
|
2591
|
-
} else {
|
|
2592
|
-
storage == null ? void 0 : storage.setItem(key, serializer.write(data));
|
|
2593
|
-
return data;
|
|
2594
|
-
}
|
|
2595
|
-
} catch (e) {
|
|
2596
|
-
onError(e);
|
|
2597
|
-
}
|
|
2598
|
-
};
|
|
2599
|
-
setState(getStoredValue());
|
|
2600
|
-
}, [key, defaults, serializer, storage, onError]);
|
|
2601
|
-
const updateState = useEvent(
|
|
2602
|
-
(valOrFunc) => {
|
|
2603
|
-
const currentState = isFunction$1(valOrFunc) ? valOrFunc(state) : valOrFunc;
|
|
2604
|
-
setState(currentState);
|
|
2605
|
-
if (currentState === null) {
|
|
2606
|
-
storage == null ? void 0 : storage.removeItem(key);
|
|
2607
|
-
} else {
|
|
2608
|
-
try {
|
|
2609
|
-
storage == null ? void 0 : storage.setItem(key, serializer.write(currentState));
|
|
2610
|
-
} catch (e) {
|
|
2611
|
-
onError(e);
|
|
2612
|
-
}
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
);
|
|
2616
|
-
return [state, updateState];
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
function useLocalStorage(key, defaults, options = {}) {
|
|
2620
|
-
return useStorage(
|
|
2621
|
-
key,
|
|
2622
|
-
defaults,
|
|
2623
|
-
() => isBrowser ? localStorage : void 0,
|
|
2624
|
-
options
|
|
2625
|
-
);
|
|
2626
|
-
}
|
|
2627
|
-
|
|
2628
|
-
function useSessionStorage(key, defaults, options = {}) {
|
|
2629
|
-
return useStorage(
|
|
2630
|
-
key,
|
|
2631
|
-
defaults,
|
|
2632
|
-
() => isBrowser ? sessionStorage : void 0,
|
|
2633
|
-
options
|
|
2634
|
-
);
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
|
-
const toggleReducer = (state, nextValue) => typeof nextValue === "boolean" ? nextValue : !state;
|
|
2638
|
-
function useToggle(initialValue) {
|
|
2639
|
-
return React.useReducer(toggleReducer, initialValue);
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
function useInterval(callback, delay, options) {
|
|
2643
|
-
const immediate = options == null ? void 0 : options.immediate;
|
|
2644
|
-
const savedCallback = useLatest(callback);
|
|
2645
|
-
React.useEffect(() => {
|
|
2646
|
-
if (immediate) {
|
|
2647
|
-
savedCallback.current();
|
|
2648
|
-
}
|
|
2649
|
-
if (delay !== null) {
|
|
2650
|
-
const interval = setInterval(() => savedCallback.current(), delay || 0);
|
|
2651
|
-
return () => clearInterval(interval);
|
|
2652
|
-
}
|
|
2653
|
-
return void 0;
|
|
2654
|
-
}, [delay, immediate]);
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
function useDarkMode(options) {
|
|
2658
|
-
const {
|
|
2659
|
-
selector = "html",
|
|
2660
|
-
attribute = "class",
|
|
2661
|
-
classNameDark = "",
|
|
2662
|
-
classNameLight = "",
|
|
2663
|
-
storageKey = "reactuses-color-scheme",
|
|
2664
|
-
storage = () => isBrowser ? localStorage : void 0,
|
|
2665
|
-
defaultValue = false
|
|
2666
|
-
} = options;
|
|
2667
|
-
const value = () => {
|
|
2668
|
-
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
2669
|
-
};
|
|
2670
|
-
const [dark, setDark] = useStorage(
|
|
2671
|
-
storageKey,
|
|
2672
|
-
defaultValue,
|
|
2673
|
-
storage,
|
|
2674
|
-
{
|
|
2675
|
-
csrData: value
|
|
2676
|
-
}
|
|
2677
|
-
);
|
|
2678
|
-
React.useEffect(() => {
|
|
2679
|
-
const element = window == null ? void 0 : window.document.querySelector(selector);
|
|
2680
|
-
if (!element) {
|
|
2681
|
-
return;
|
|
2682
|
-
}
|
|
2683
|
-
if (attribute === "class") {
|
|
2684
|
-
dark && classNameDark && element.classList.add(classNameDark);
|
|
2685
|
-
!dark && classNameLight && element.classList.add(classNameLight);
|
|
2686
|
-
} else {
|
|
2687
|
-
dark && classNameDark && element.setAttribute(attribute, classNameDark);
|
|
2688
|
-
!dark && classNameLight && element.setAttribute(attribute, classNameLight);
|
|
2689
|
-
}
|
|
2690
|
-
return () => {
|
|
2691
|
-
if (!element) {
|
|
2692
|
-
return;
|
|
2693
|
-
}
|
|
2694
|
-
if (attribute === "class") {
|
|
2695
|
-
dark && classNameDark && element.classList.remove(classNameDark);
|
|
2696
|
-
!dark && classNameLight && element.classList.remove(classNameLight);
|
|
2697
|
-
} else {
|
|
2698
|
-
dark && classNameDark && element.removeAttribute(attribute);
|
|
2699
|
-
!dark && classNameLight && element.removeAttribute(attribute);
|
|
2700
|
-
}
|
|
2701
|
-
};
|
|
2702
|
-
}, [attribute, classNameDark, classNameLight, dark, selector]);
|
|
2703
|
-
return [dark, () => setDark((dark2) => !dark2), setDark];
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
const getInitialState = (query, defaultState) => {
|
|
2707
|
-
if (defaultState !== void 0) {
|
|
2708
|
-
return defaultState;
|
|
2709
|
-
}
|
|
2710
|
-
if (isBrowser) {
|
|
2711
|
-
return window.matchMedia(query).matches;
|
|
2712
|
-
}
|
|
2713
|
-
if (process.env.NODE_ENV !== "production") {
|
|
2714
|
-
console.warn(
|
|
2715
|
-
"`useMediaQuery` When server side rendering, defaultState should be defined to prevent a hydration mismatches."
|
|
2716
|
-
);
|
|
2717
|
-
}
|
|
2718
|
-
return false;
|
|
2719
|
-
};
|
|
2720
|
-
function useMediaQuery(query, defaultState) {
|
|
2721
|
-
const [state, setState] = React.useState(getInitialState(query, defaultState));
|
|
2722
|
-
React.useEffect(() => {
|
|
2723
|
-
var _a;
|
|
2724
|
-
let mounted = true;
|
|
2725
|
-
const mql = window.matchMedia(query);
|
|
2726
|
-
const onChange = () => {
|
|
2727
|
-
if (!mounted) {
|
|
2728
|
-
return;
|
|
2729
|
-
}
|
|
2730
|
-
setState(!!mql.matches);
|
|
2731
|
-
};
|
|
2732
|
-
if ("addEventListener" in mql) {
|
|
2733
|
-
mql.addEventListener("change", onChange);
|
|
2734
|
-
} else {
|
|
2735
|
-
(_a = mql.addListener) == null ? void 0 : _a.call(mql, onChange);
|
|
2736
|
-
}
|
|
2737
|
-
setState(mql.matches);
|
|
2738
|
-
return () => {
|
|
2739
|
-
var _a2;
|
|
2740
|
-
mounted = false;
|
|
2741
|
-
if ("removeEventListener" in mql) {
|
|
2742
|
-
mql.removeEventListener("change", onChange);
|
|
2743
|
-
} else {
|
|
2744
|
-
(_a2 = mql.removeListener) == null ? void 0 : _a2.call(mql, onChange);
|
|
2745
|
-
}
|
|
2746
|
-
};
|
|
2747
|
-
}, [query]);
|
|
2748
|
-
return state;
|
|
2676
|
+
* sets, strings, symbols, and typed arrays. `Object` objects are compared
|
|
2677
|
+
* by their own, not inherited, enumerable properties. Functions and DOM
|
|
2678
|
+
* nodes are compared by strict equality, i.e. `===`.
|
|
2679
|
+
*
|
|
2680
|
+
* @static
|
|
2681
|
+
* @memberOf _
|
|
2682
|
+
* @since 0.1.0
|
|
2683
|
+
* @category Lang
|
|
2684
|
+
* @param {*} value The value to compare.
|
|
2685
|
+
* @param {*} other The other value to compare.
|
|
2686
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
2687
|
+
* @example
|
|
2688
|
+
*
|
|
2689
|
+
* var object = { 'a': 1 };
|
|
2690
|
+
* var other = { 'a': 1 };
|
|
2691
|
+
*
|
|
2692
|
+
* _.isEqual(object, other);
|
|
2693
|
+
* // => true
|
|
2694
|
+
*
|
|
2695
|
+
* object === other;
|
|
2696
|
+
* // => false
|
|
2697
|
+
*/
|
|
2698
|
+
function isEqual(value, other) {
|
|
2699
|
+
return baseIsEqual(value, other);
|
|
2749
2700
|
}
|
|
2750
2701
|
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
}
|
|
2702
|
+
/** Error message constants. */
|
|
2703
|
+
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
2754
2704
|
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2705
|
+
/**
|
|
2706
|
+
* Creates a throttled function that only invokes `func` at most once per
|
|
2707
|
+
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
2708
|
+
* method to cancel delayed `func` invocations and a `flush` method to
|
|
2709
|
+
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
2710
|
+
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
2711
|
+
* timeout. The `func` is invoked with the last arguments provided to the
|
|
2712
|
+
* throttled function. Subsequent calls to the throttled function return the
|
|
2713
|
+
* result of the last `func` invocation.
|
|
2714
|
+
*
|
|
2715
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
2716
|
+
* invoked on the trailing edge of the timeout only if the throttled function
|
|
2717
|
+
* is invoked more than once during the `wait` timeout.
|
|
2718
|
+
*
|
|
2719
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
2720
|
+
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
2721
|
+
*
|
|
2722
|
+
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
|
|
2723
|
+
* for details over the differences between `_.throttle` and `_.debounce`.
|
|
2724
|
+
*
|
|
2725
|
+
* @static
|
|
2726
|
+
* @memberOf _
|
|
2727
|
+
* @since 0.1.0
|
|
2728
|
+
* @category Function
|
|
2729
|
+
* @param {Function} func The function to throttle.
|
|
2730
|
+
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
|
2731
|
+
* @param {Object} [options={}] The options object.
|
|
2732
|
+
* @param {boolean} [options.leading=true]
|
|
2733
|
+
* Specify invoking on the leading edge of the timeout.
|
|
2734
|
+
* @param {boolean} [options.trailing=true]
|
|
2735
|
+
* Specify invoking on the trailing edge of the timeout.
|
|
2736
|
+
* @returns {Function} Returns the new throttled function.
|
|
2737
|
+
* @example
|
|
2738
|
+
*
|
|
2739
|
+
* // Avoid excessively updating the position while scrolling.
|
|
2740
|
+
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|
2741
|
+
*
|
|
2742
|
+
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
|
|
2743
|
+
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
|
|
2744
|
+
* jQuery(element).on('click', throttled);
|
|
2745
|
+
*
|
|
2746
|
+
* // Cancel the trailing throttled invocation.
|
|
2747
|
+
* jQuery(window).on('popstate', throttled.cancel);
|
|
2748
|
+
*/
|
|
2749
|
+
function throttle(func, wait, options) {
|
|
2750
|
+
var leading = true,
|
|
2751
|
+
trailing = true;
|
|
2767
2752
|
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
if (!isFunction$1(fn)) {
|
|
2771
|
-
console.error(
|
|
2772
|
-
`useUnmount expected parameter is a function, got ${typeof fn}`
|
|
2773
|
-
);
|
|
2774
|
-
}
|
|
2753
|
+
if (typeof func != 'function') {
|
|
2754
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
2775
2755
|
}
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2756
|
+
if (isObject(options)) {
|
|
2757
|
+
leading = 'leading' in options ? !!options.leading : leading;
|
|
2758
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
2759
|
+
}
|
|
2760
|
+
return debounce(func, wait, {
|
|
2761
|
+
'leading': leading,
|
|
2762
|
+
'maxWait': wait,
|
|
2763
|
+
'trailing': trailing
|
|
2764
|
+
});
|
|
2783
2765
|
}
|
|
2784
2766
|
|
|
2785
2767
|
function useThrottleFn(fn, wait, options) {
|
|
@@ -2799,8 +2781,7 @@ function useThrottleFn(fn, wait, options) {
|
|
|
2799
2781
|
wait,
|
|
2800
2782
|
options
|
|
2801
2783
|
),
|
|
2802
|
-
|
|
2803
|
-
[]
|
|
2784
|
+
[wait, options]
|
|
2804
2785
|
);
|
|
2805
2786
|
useUnmount(() => {
|
|
2806
2787
|
throttled.cancel();
|
|
@@ -2844,8 +2825,7 @@ function useDebounceFn(fn, wait, options) {
|
|
|
2844
2825
|
wait,
|
|
2845
2826
|
options
|
|
2846
2827
|
),
|
|
2847
|
-
|
|
2848
|
-
[]
|
|
2828
|
+
[options, wait]
|
|
2849
2829
|
);
|
|
2850
2830
|
useUnmount(() => {
|
|
2851
2831
|
debounced.cancel();
|
|
@@ -2893,7 +2873,7 @@ function useUpdate() {
|
|
|
2893
2873
|
return update;
|
|
2894
2874
|
}
|
|
2895
2875
|
|
|
2896
|
-
function useTimeoutFn(cb, interval, options =
|
|
2876
|
+
function useTimeoutFn(cb, interval, options = defaultOptions) {
|
|
2897
2877
|
const { immediate = true } = options;
|
|
2898
2878
|
const [pending, setPending] = React.useState(false);
|
|
2899
2879
|
const savedCallback = useLatest(cb);
|
|
@@ -2983,10 +2963,10 @@ function useLatestElement(target, defaultElement) {
|
|
|
2983
2963
|
return latestElement;
|
|
2984
2964
|
}
|
|
2985
2965
|
|
|
2986
|
-
function useEventListener(eventName, handler, element, options) {
|
|
2966
|
+
function useEventListener(eventName, handler, element, options = defaultOptions) {
|
|
2987
2967
|
const savedHandler = useLatest(handler);
|
|
2988
2968
|
const targetElement = useLatestElement(element, defaultWindow);
|
|
2989
|
-
|
|
2969
|
+
React.useEffect(() => {
|
|
2990
2970
|
if (!(targetElement && targetElement.addEventListener)) {
|
|
2991
2971
|
return;
|
|
2992
2972
|
}
|
|
@@ -3140,7 +3120,7 @@ function useFavicon(href, baseUrl = "", rel = "icon") {
|
|
|
3140
3120
|
}, [baseUrl, href, rel]);
|
|
3141
3121
|
}
|
|
3142
3122
|
|
|
3143
|
-
function useMutationObserver(callback, target, options =
|
|
3123
|
+
function useMutationObserver(callback, target, options = defaultOptions) {
|
|
3144
3124
|
const callbackRef = useLatest(callback);
|
|
3145
3125
|
const observerRef = React.useRef();
|
|
3146
3126
|
const element = useLatestElement(target);
|
|
@@ -3149,7 +3129,7 @@ function useMutationObserver(callback, target, options = {}) {
|
|
|
3149
3129
|
observerRef.current.disconnect();
|
|
3150
3130
|
}
|
|
3151
3131
|
}, []);
|
|
3152
|
-
|
|
3132
|
+
React.useEffect(() => {
|
|
3153
3133
|
if (!element) {
|
|
3154
3134
|
return;
|
|
3155
3135
|
}
|
|
@@ -3160,13 +3140,56 @@ function useMutationObserver(callback, target, options = {}) {
|
|
|
3160
3140
|
return stop;
|
|
3161
3141
|
}
|
|
3162
3142
|
|
|
3143
|
+
const isPrimitive$1 = (val) => val !== Object(val);
|
|
3144
|
+
function useCustomCompareEffect(effect, deps, depsEqual) {
|
|
3145
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3146
|
+
if (!Array.isArray(deps) || !deps.length) {
|
|
3147
|
+
console.warn(
|
|
3148
|
+
"`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
3149
|
+
);
|
|
3150
|
+
}
|
|
3151
|
+
if (deps.every(isPrimitive$1)) {
|
|
3152
|
+
console.warn(
|
|
3153
|
+
"`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
3154
|
+
);
|
|
3155
|
+
}
|
|
3156
|
+
if (typeof depsEqual !== "function") {
|
|
3157
|
+
console.warn(
|
|
3158
|
+
"`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list"
|
|
3159
|
+
);
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
const ref = React.useRef(void 0);
|
|
3163
|
+
if (!ref.current || !depsEqual(deps, ref.current)) {
|
|
3164
|
+
ref.current = deps;
|
|
3165
|
+
}
|
|
3166
|
+
React.useEffect(effect, ref.current);
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
const isPrimitive = (val) => val !== Object(val);
|
|
3170
|
+
function useDeepCompareEffect(effect, deps) {
|
|
3171
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3172
|
+
if (!Array.isArray(deps) || !deps.length) {
|
|
3173
|
+
console.warn(
|
|
3174
|
+
"`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead."
|
|
3175
|
+
);
|
|
3176
|
+
}
|
|
3177
|
+
if (deps.every(isPrimitive)) {
|
|
3178
|
+
console.warn(
|
|
3179
|
+
"`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead."
|
|
3180
|
+
);
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
useCustomCompareEffect(effect, deps, isEqual);
|
|
3184
|
+
}
|
|
3185
|
+
|
|
3163
3186
|
function useTitle(title) {
|
|
3164
3187
|
React.useEffect(() => {
|
|
3165
3188
|
document.title = title;
|
|
3166
3189
|
}, [title]);
|
|
3167
3190
|
}
|
|
3168
3191
|
|
|
3169
|
-
function useScriptTag(src, onLoaded = noop, options =
|
|
3192
|
+
function useScriptTag(src, onLoaded = noop, options = defaultOptions) {
|
|
3170
3193
|
const {
|
|
3171
3194
|
immediate = true,
|
|
3172
3195
|
manual = false,
|
|
@@ -3320,7 +3343,7 @@ const preventDefault$1 = (ev) => {
|
|
|
3320
3343
|
ev.preventDefault();
|
|
3321
3344
|
}
|
|
3322
3345
|
};
|
|
3323
|
-
function useLongPress(callback, { isPreventDefault = true, delay = 300 } =
|
|
3346
|
+
function useLongPress(callback, { isPreventDefault = true, delay = 300 } = defaultOptions) {
|
|
3324
3347
|
const timeout = React.useRef();
|
|
3325
3348
|
const target = React.useRef();
|
|
3326
3349
|
const start = React.useCallback(
|
|
@@ -3441,8 +3464,9 @@ var __async$4 = (__this, __arguments, generator) => {
|
|
|
3441
3464
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
3442
3465
|
});
|
|
3443
3466
|
};
|
|
3467
|
+
const defaultConstints = { audio: true, video: true };
|
|
3444
3468
|
function useMediaDevices(options = {}) {
|
|
3445
|
-
const { requestPermissions, constraints =
|
|
3469
|
+
const { requestPermissions, constraints = defaultConstints } = options;
|
|
3446
3470
|
const [state, setState] = React.useState({ devices: [] });
|
|
3447
3471
|
const isSupported = useSupported(
|
|
3448
3472
|
() => navigator && navigator.mediaDevices && navigator.mediaDevices.enumerateDevices
|
|
@@ -3472,7 +3496,7 @@ function useMediaDevices(options = {}) {
|
|
|
3472
3496
|
if (permissionGranted.current) {
|
|
3473
3497
|
return true;
|
|
3474
3498
|
}
|
|
3475
|
-
let state2
|
|
3499
|
+
let state2;
|
|
3476
3500
|
try {
|
|
3477
3501
|
state2 = (yield navigator.permissions.query({
|
|
3478
3502
|
name: "camera"
|
|
@@ -3505,7 +3529,7 @@ function useMediaDevices(options = {}) {
|
|
|
3505
3529
|
return [state, ensurePermissions];
|
|
3506
3530
|
}
|
|
3507
3531
|
|
|
3508
|
-
function useTextDirection(options =
|
|
3532
|
+
function useTextDirection(options = defaultOptions) {
|
|
3509
3533
|
const { selector = "html", initialValue = "ltr" } = options;
|
|
3510
3534
|
const getValue = () => {
|
|
3511
3535
|
var _a, _b;
|
|
@@ -3582,10 +3606,10 @@ function useMouse(target) {
|
|
|
3582
3606
|
return state;
|
|
3583
3607
|
}
|
|
3584
3608
|
|
|
3585
|
-
function useFps(options) {
|
|
3609
|
+
function useFps(options = defaultOptions) {
|
|
3586
3610
|
var _a;
|
|
3587
3611
|
const [fps, setFps] = React.useState(0);
|
|
3588
|
-
const every = (_a = options
|
|
3612
|
+
const every = (_a = options.every) != null ? _a : 10;
|
|
3589
3613
|
const last = React.useRef(performance.now());
|
|
3590
3614
|
const ticks = React.useRef(0);
|
|
3591
3615
|
useRafFn(() => {
|
|
@@ -3612,7 +3636,7 @@ const initCoord = {
|
|
|
3612
3636
|
heading: null,
|
|
3613
3637
|
speed: null
|
|
3614
3638
|
};
|
|
3615
|
-
function useGeolocation(options =
|
|
3639
|
+
function useGeolocation(options = defaultOptions) {
|
|
3616
3640
|
const {
|
|
3617
3641
|
enableHighAccuracy = true,
|
|
3618
3642
|
maximumAge = 3e4,
|
|
@@ -3838,20 +3862,17 @@ var screenfull$1 = {exports: {}};
|
|
|
3838
3862
|
|
|
3839
3863
|
var screenfull = screenfull$1.exports;
|
|
3840
3864
|
|
|
3841
|
-
function useFullscreen(target, options) {
|
|
3842
|
-
const { onExit, onEnter } = options
|
|
3843
|
-
const onExitRef = useLatest(onExit);
|
|
3844
|
-
const onEnterRef = useLatest(onEnter);
|
|
3865
|
+
function useFullscreen(target, options = defaultOptions) {
|
|
3866
|
+
const { onExit, onEnter } = options;
|
|
3845
3867
|
const [state, setState] = React.useState(false);
|
|
3846
3868
|
const onChange = () => {
|
|
3847
|
-
var _a, _b;
|
|
3848
3869
|
if (screenfull.isEnabled) {
|
|
3849
3870
|
const { isFullscreen } = screenfull;
|
|
3850
3871
|
if (isFullscreen) {
|
|
3851
|
-
|
|
3872
|
+
onEnter == null ? void 0 : onEnter();
|
|
3852
3873
|
} else {
|
|
3853
3874
|
screenfull.off("change", onChange);
|
|
3854
|
-
|
|
3875
|
+
onExit == null ? void 0 : onExit();
|
|
3855
3876
|
}
|
|
3856
3877
|
setState(isFullscreen);
|
|
3857
3878
|
}
|
|
@@ -3993,7 +4014,7 @@ function useOrientation(initialState = defaultState$1) {
|
|
|
3993
4014
|
return [state, lockOrientation, unlockOrientation];
|
|
3994
4015
|
}
|
|
3995
4016
|
|
|
3996
|
-
function useIntersectionObserver(target, callback, options =
|
|
4017
|
+
function useIntersectionObserver(target, callback, options = defaultOptions) {
|
|
3997
4018
|
const savedCallback = useLatest(callback);
|
|
3998
4019
|
const observerRef = React.useRef();
|
|
3999
4020
|
const element = useLatestElement(target);
|
|
@@ -4002,7 +4023,7 @@ function useIntersectionObserver(target, callback, options = {}) {
|
|
|
4002
4023
|
observerRef.current.disconnect();
|
|
4003
4024
|
}
|
|
4004
4025
|
}, []);
|
|
4005
|
-
|
|
4026
|
+
React.useEffect(() => {
|
|
4006
4027
|
if (!element) {
|
|
4007
4028
|
return;
|
|
4008
4029
|
}
|
|
@@ -4031,14 +4052,24 @@ function usePageLeave() {
|
|
|
4031
4052
|
return isLeft;
|
|
4032
4053
|
}
|
|
4033
4054
|
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4055
|
+
const getInitialState$1 = (defaultValue) => {
|
|
4056
|
+
if (defaultValue !== void 0) {
|
|
4057
|
+
return defaultValue;
|
|
4058
|
+
}
|
|
4059
|
+
if (isBrowser) {
|
|
4060
|
+
return document.visibilityState;
|
|
4061
|
+
}
|
|
4062
|
+
if (process.env.NODE_ENV !== "production") {
|
|
4063
|
+
console.warn(
|
|
4064
|
+
"`useDocumentVisibility` When server side rendering, defaultValue should be defined to prevent a hydration mismatches."
|
|
4065
|
+
);
|
|
4066
|
+
}
|
|
4067
|
+
return "visible";
|
|
4068
|
+
};
|
|
4069
|
+
function useDocumentVisibility(defaultValue) {
|
|
4070
|
+
const [visible, setVisible] = React.useState(
|
|
4071
|
+
getInitialState$1(defaultValue)
|
|
4072
|
+
);
|
|
4042
4073
|
useEventListener(
|
|
4043
4074
|
"visibilitychange",
|
|
4044
4075
|
() => {
|
|
@@ -4049,7 +4080,7 @@ function useDocumentVisibility() {
|
|
|
4049
4080
|
return visible;
|
|
4050
4081
|
}
|
|
4051
4082
|
|
|
4052
|
-
function useResizeObserver(target, callback, options =
|
|
4083
|
+
function useResizeObserver(target, callback, options = defaultOptions) {
|
|
4053
4084
|
const savedCallback = useLatest(callback);
|
|
4054
4085
|
const observerRef = React.useRef();
|
|
4055
4086
|
const element = useLatestElement(target);
|
|
@@ -4058,7 +4089,7 @@ function useResizeObserver(target, callback, options = {}) {
|
|
|
4058
4089
|
observerRef.current.disconnect();
|
|
4059
4090
|
}
|
|
4060
4091
|
}, []);
|
|
4061
|
-
|
|
4092
|
+
React.useEffect(() => {
|
|
4062
4093
|
if (!element) {
|
|
4063
4094
|
return;
|
|
4064
4095
|
}
|
|
@@ -4115,17 +4146,17 @@ function useDropZone(target, onDrop) {
|
|
|
4115
4146
|
}
|
|
4116
4147
|
|
|
4117
4148
|
var __defProp$2 = Object.defineProperty;
|
|
4118
|
-
var __getOwnPropSymbols$
|
|
4119
|
-
var __hasOwnProp$
|
|
4120
|
-
var __propIsEnum$
|
|
4149
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
4150
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
4151
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
4121
4152
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4122
4153
|
var __spreadValues$2 = (a, b) => {
|
|
4123
4154
|
for (var prop in b || (b = {}))
|
|
4124
|
-
if (__hasOwnProp$
|
|
4155
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
4125
4156
|
__defNormalProp$2(a, prop, b[prop]);
|
|
4126
|
-
if (__getOwnPropSymbols$
|
|
4127
|
-
for (var prop of __getOwnPropSymbols$
|
|
4128
|
-
if (__propIsEnum$
|
|
4157
|
+
if (__getOwnPropSymbols$2)
|
|
4158
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
4159
|
+
if (__propIsEnum$2.call(b, prop))
|
|
4129
4160
|
__defNormalProp$2(a, prop, b[prop]);
|
|
4130
4161
|
}
|
|
4131
4162
|
return a;
|
|
@@ -4134,7 +4165,7 @@ const DEFAULT_OPTIONS = {
|
|
|
4134
4165
|
multiple: true,
|
|
4135
4166
|
accept: "*"
|
|
4136
4167
|
};
|
|
4137
|
-
function useFileDialog(options =
|
|
4168
|
+
function useFileDialog(options = defaultOptions) {
|
|
4138
4169
|
const [files, setFiles] = React.useState(null);
|
|
4139
4170
|
const inputRef = React.useRef();
|
|
4140
4171
|
const initFn = React.useCallback(() => {
|
|
@@ -4170,7 +4201,11 @@ function useFileDialog(options = {}) {
|
|
|
4170
4201
|
}
|
|
4171
4202
|
|
|
4172
4203
|
const ARRIVED_STATE_THRESHOLD_PIXELS = 1;
|
|
4173
|
-
|
|
4204
|
+
const defaultListerOptions = {
|
|
4205
|
+
capture: false,
|
|
4206
|
+
passive: true
|
|
4207
|
+
};
|
|
4208
|
+
function useScroll(target, options = defaultOptions) {
|
|
4174
4209
|
const {
|
|
4175
4210
|
throttle = 0,
|
|
4176
4211
|
idle = 200,
|
|
@@ -4182,10 +4217,7 @@ function useScroll(target, options = {}) {
|
|
|
4182
4217
|
top: 0,
|
|
4183
4218
|
bottom: 0
|
|
4184
4219
|
},
|
|
4185
|
-
eventListenerOptions =
|
|
4186
|
-
capture: false,
|
|
4187
|
-
passive: true
|
|
4188
|
-
}
|
|
4220
|
+
eventListenerOptions = defaultListerOptions
|
|
4189
4221
|
} = options;
|
|
4190
4222
|
const [x, setX] = React.useState(0);
|
|
4191
4223
|
const [y, setY] = React.useState(0);
|
|
@@ -4244,17 +4276,17 @@ function useScroll(target, options = {}) {
|
|
|
4244
4276
|
var __defProp$1 = Object.defineProperty;
|
|
4245
4277
|
var __defProps = Object.defineProperties;
|
|
4246
4278
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4247
|
-
var __getOwnPropSymbols$
|
|
4248
|
-
var __hasOwnProp$
|
|
4249
|
-
var __propIsEnum$
|
|
4279
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
4280
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
4281
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
4250
4282
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4251
4283
|
var __spreadValues$1 = (a, b) => {
|
|
4252
4284
|
for (var prop in b || (b = {}))
|
|
4253
|
-
if (__hasOwnProp$
|
|
4285
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
4254
4286
|
__defNormalProp$1(a, prop, b[prop]);
|
|
4255
|
-
if (__getOwnPropSymbols$
|
|
4256
|
-
for (var prop of __getOwnPropSymbols$
|
|
4257
|
-
if (__propIsEnum$
|
|
4287
|
+
if (__getOwnPropSymbols$1)
|
|
4288
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
4289
|
+
if (__propIsEnum$1.call(b, prop))
|
|
4258
4290
|
__defNormalProp$1(a, prop, b[prop]);
|
|
4259
4291
|
}
|
|
4260
4292
|
return a;
|
|
@@ -4280,7 +4312,7 @@ var __async$3 = (__this, __arguments, generator) => {
|
|
|
4280
4312
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
4281
4313
|
});
|
|
4282
4314
|
};
|
|
4283
|
-
function useInfiniteScroll(target, onLoadMore, options =
|
|
4315
|
+
function useInfiniteScroll(target, onLoadMore, options = defaultOptions) {
|
|
4284
4316
|
var _a, _b;
|
|
4285
4317
|
const savedLoadMore = useLatest(onLoadMore);
|
|
4286
4318
|
const direction = (_a = options.direction) != null ? _a : "bottom";
|
|
@@ -4290,10 +4322,8 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
|
|
|
4290
4322
|
}, options.offset)
|
|
4291
4323
|
}));
|
|
4292
4324
|
const element = useLatestElement(target);
|
|
4293
|
-
const latestOptions = useLatest(options);
|
|
4294
4325
|
const di = state[3][direction];
|
|
4295
4326
|
useUpdateEffect(() => {
|
|
4296
|
-
const opts = latestOptions.current;
|
|
4297
4327
|
const fn = () => __async$3(this, null, function* () {
|
|
4298
4328
|
var _a2, _b2;
|
|
4299
4329
|
const previous = {
|
|
@@ -4301,7 +4331,7 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
|
|
|
4301
4331
|
width: (_b2 = element == null ? void 0 : element.scrollWidth) != null ? _b2 : 0
|
|
4302
4332
|
};
|
|
4303
4333
|
yield savedLoadMore.current(state);
|
|
4304
|
-
if (
|
|
4334
|
+
if (options.preserveScrollPosition && element) {
|
|
4305
4335
|
element.scrollTo({
|
|
4306
4336
|
top: element.scrollHeight - previous.height,
|
|
4307
4337
|
left: element.scrollWidth - previous.width
|
|
@@ -4309,7 +4339,7 @@ function useInfiniteScroll(target, onLoadMore, options = {}) {
|
|
|
4309
4339
|
}
|
|
4310
4340
|
});
|
|
4311
4341
|
fn();
|
|
4312
|
-
}, [di]);
|
|
4342
|
+
}, [di, options.preserveScrollPosition]);
|
|
4313
4343
|
}
|
|
4314
4344
|
|
|
4315
4345
|
const defaultEvents = [
|
|
@@ -4318,7 +4348,7 @@ const defaultEvents = [
|
|
|
4318
4348
|
"keydown",
|
|
4319
4349
|
"keyup"
|
|
4320
4350
|
];
|
|
4321
|
-
function useKeyModifier(modifier, options =
|
|
4351
|
+
function useKeyModifier(modifier, options = defaultOptions) {
|
|
4322
4352
|
const { events = defaultEvents, initial = false } = options;
|
|
4323
4353
|
const [state, setState] = React.useState(initial);
|
|
4324
4354
|
useMount(() => {
|
|
@@ -4342,7 +4372,8 @@ function useKeyModifier(modifier, options = {}) {
|
|
|
4342
4372
|
return state;
|
|
4343
4373
|
}
|
|
4344
4374
|
|
|
4345
|
-
|
|
4375
|
+
const listenerOptions$2 = { passive: true };
|
|
4376
|
+
function useMousePressed(target, options = defaultOptions) {
|
|
4346
4377
|
const { touch = true, drag = true, initialValue = false } = options;
|
|
4347
4378
|
const [pressed, setPressed] = React.useState(initialValue);
|
|
4348
4379
|
const [sourceType, setSourceType] = React.useState(null);
|
|
@@ -4358,31 +4389,27 @@ function useMousePressed(target, options = {}) {
|
|
|
4358
4389
|
setPressed(false);
|
|
4359
4390
|
setSourceType(null);
|
|
4360
4391
|
}, []);
|
|
4361
|
-
useEventListener("mousedown", onPressed("mouse"), target,
|
|
4362
|
-
useEventListener("mouseleave", onReleased, () => window,
|
|
4363
|
-
useEventListener("mouseup", onReleased, () => window,
|
|
4392
|
+
useEventListener("mousedown", onPressed("mouse"), target, listenerOptions$2);
|
|
4393
|
+
useEventListener("mouseleave", onReleased, () => window, listenerOptions$2);
|
|
4394
|
+
useEventListener("mouseup", onReleased, () => window, listenerOptions$2);
|
|
4364
4395
|
React.useEffect(() => {
|
|
4365
4396
|
if (drag) {
|
|
4366
|
-
element == null ? void 0 : element.addEventListener(
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
element == null ? void 0 : element.addEventListener("dragend", onReleased,
|
|
4373
|
-
passive: true
|
|
4374
|
-
});
|
|
4397
|
+
element == null ? void 0 : element.addEventListener(
|
|
4398
|
+
"dragstart",
|
|
4399
|
+
onPressed("mouse"),
|
|
4400
|
+
listenerOptions$2
|
|
4401
|
+
);
|
|
4402
|
+
element == null ? void 0 : element.addEventListener("drop", onReleased, listenerOptions$2);
|
|
4403
|
+
element == null ? void 0 : element.addEventListener("dragend", onReleased, listenerOptions$2);
|
|
4375
4404
|
}
|
|
4376
4405
|
if (touch) {
|
|
4377
|
-
element == null ? void 0 : element.addEventListener(
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
element == null ? void 0 : element.addEventListener("touchcancel", onReleased,
|
|
4384
|
-
passive: true
|
|
4385
|
-
});
|
|
4406
|
+
element == null ? void 0 : element.addEventListener(
|
|
4407
|
+
"touchstart",
|
|
4408
|
+
onPressed("touch"),
|
|
4409
|
+
listenerOptions$2
|
|
4410
|
+
);
|
|
4411
|
+
element == null ? void 0 : element.addEventListener("touchend", onReleased, listenerOptions$2);
|
|
4412
|
+
element == null ? void 0 : element.addEventListener("touchcancel", onReleased, listenerOptions$2);
|
|
4386
4413
|
}
|
|
4387
4414
|
return () => {
|
|
4388
4415
|
if (drag) {
|
|
@@ -4453,7 +4480,7 @@ function useScrollLock(target, initialState = false) {
|
|
|
4453
4480
|
return [locked, set];
|
|
4454
4481
|
}
|
|
4455
4482
|
|
|
4456
|
-
function useElementSize(target, options =
|
|
4483
|
+
function useElementSize(target, options = defaultOptions) {
|
|
4457
4484
|
const { box = "content-box" } = options;
|
|
4458
4485
|
const [width, setWidth] = React.useState(0);
|
|
4459
4486
|
const [height, setHeight] = React.useState(0);
|
|
@@ -4480,44 +4507,38 @@ function useVirtualList(list = [], options) {
|
|
|
4480
4507
|
const [currentList, setCurrentList] = React.useState([]);
|
|
4481
4508
|
const { itemHeight, overscan = 5, containerHeight = 300 } = options;
|
|
4482
4509
|
const state = React.useRef({ start: 0, end: 10 });
|
|
4483
|
-
const getViewCapacity =
|
|
4484
|
-
(
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
break;
|
|
4497
|
-
}
|
|
4510
|
+
const getViewCapacity = (containerHeight2) => {
|
|
4511
|
+
if (typeof itemHeight === "number") {
|
|
4512
|
+
return Math.ceil(containerHeight2 / itemHeight);
|
|
4513
|
+
}
|
|
4514
|
+
const { start = 0 } = state.current;
|
|
4515
|
+
let sum = 0;
|
|
4516
|
+
let capacity = 0;
|
|
4517
|
+
for (let i = start; i < list.length; i++) {
|
|
4518
|
+
const height2 = itemHeight(i);
|
|
4519
|
+
sum += height2;
|
|
4520
|
+
if (sum >= containerHeight2) {
|
|
4521
|
+
capacity = i;
|
|
4522
|
+
break;
|
|
4498
4523
|
}
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
)
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
offset = i;
|
|
4514
|
-
break;
|
|
4515
|
-
}
|
|
4524
|
+
}
|
|
4525
|
+
return capacity - start;
|
|
4526
|
+
};
|
|
4527
|
+
const getOffset = (scrollTop) => {
|
|
4528
|
+
if (typeof itemHeight === "number")
|
|
4529
|
+
return Math.floor(scrollTop / itemHeight) + 1;
|
|
4530
|
+
let sum = 0;
|
|
4531
|
+
let offset = 0;
|
|
4532
|
+
for (let i = 0; i < list.length; i++) {
|
|
4533
|
+
const height2 = itemHeight(i);
|
|
4534
|
+
sum += height2;
|
|
4535
|
+
if (sum >= scrollTop) {
|
|
4536
|
+
offset = i;
|
|
4537
|
+
break;
|
|
4516
4538
|
}
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
);
|
|
4539
|
+
}
|
|
4540
|
+
return offset + 1;
|
|
4541
|
+
};
|
|
4521
4542
|
const calculateRange = useEvent(() => {
|
|
4522
4543
|
const element = containerRef.current;
|
|
4523
4544
|
if (element != null) {
|
|
@@ -4529,17 +4550,18 @@ function useVirtualList(list = [], options) {
|
|
|
4529
4550
|
start: from < 0 ? 0 : from,
|
|
4530
4551
|
end: to > list.length ? list.length : to
|
|
4531
4552
|
};
|
|
4553
|
+
const { start, end } = state.current;
|
|
4532
4554
|
setCurrentList(
|
|
4533
|
-
list.slice(
|
|
4555
|
+
list.slice(start, end).map((ele, index) => ({
|
|
4534
4556
|
data: ele,
|
|
4535
|
-
index: index +
|
|
4557
|
+
index: index + start
|
|
4536
4558
|
}))
|
|
4537
4559
|
);
|
|
4538
4560
|
}
|
|
4539
4561
|
});
|
|
4540
4562
|
React.useEffect(() => {
|
|
4541
4563
|
calculateRange();
|
|
4542
|
-
}, [width, height, list
|
|
4564
|
+
}, [width, height, list]);
|
|
4543
4565
|
const totalHeight = React.useMemo(() => {
|
|
4544
4566
|
if (typeof itemHeight === "number") {
|
|
4545
4567
|
return list.length * itemHeight;
|
|
@@ -4557,16 +4579,7 @@ function useVirtualList(list = [], options) {
|
|
|
4557
4579
|
},
|
|
4558
4580
|
[itemHeight, list]
|
|
4559
4581
|
);
|
|
4560
|
-
const
|
|
4561
|
-
if (containerRef.current) {
|
|
4562
|
-
containerRef.current.scrollTop = getDistanceTop(index);
|
|
4563
|
-
calculateRange();
|
|
4564
|
-
}
|
|
4565
|
-
});
|
|
4566
|
-
const offsetTop = React.useMemo(
|
|
4567
|
-
() => getDistanceTop(state.current.start),
|
|
4568
|
-
[getDistanceTop]
|
|
4569
|
-
);
|
|
4582
|
+
const offsetTop = getDistanceTop(state.current.start);
|
|
4570
4583
|
const wrapperProps = React.useMemo(() => {
|
|
4571
4584
|
return {
|
|
4572
4585
|
style: {
|
|
@@ -4575,7 +4588,13 @@ function useVirtualList(list = [], options) {
|
|
|
4575
4588
|
marginTop: `${offsetTop}px`
|
|
4576
4589
|
}
|
|
4577
4590
|
};
|
|
4578
|
-
}, [
|
|
4591
|
+
}, [totalHeight, offsetTop]);
|
|
4592
|
+
const scrollTo = (index) => {
|
|
4593
|
+
if (containerRef.current) {
|
|
4594
|
+
containerRef.current.scrollTop = getDistanceTop(index);
|
|
4595
|
+
calculateRange();
|
|
4596
|
+
}
|
|
4597
|
+
};
|
|
4579
4598
|
const containerStyle = React.useMemo(() => {
|
|
4580
4599
|
return { overflowY: "auto", height: containerHeight };
|
|
4581
4600
|
}, [containerHeight]);
|
|
@@ -4701,7 +4720,7 @@ function useDraggable(target, options = {}) {
|
|
|
4701
4720
|
return [position.x, position.y, !!pressedDelta];
|
|
4702
4721
|
}
|
|
4703
4722
|
|
|
4704
|
-
function useElementBounding(target, options =
|
|
4723
|
+
function useElementBounding(target, options = defaultOptions) {
|
|
4705
4724
|
const {
|
|
4706
4725
|
reset = true,
|
|
4707
4726
|
windowResize = true,
|
|
@@ -4776,7 +4795,7 @@ function useElementBounding(target, options = {}) {
|
|
|
4776
4795
|
};
|
|
4777
4796
|
}
|
|
4778
4797
|
|
|
4779
|
-
function useElementVisibility(target, options =
|
|
4798
|
+
function useElementVisibility(target, options = defaultOptions) {
|
|
4780
4799
|
const [visible, setVisible] = React.useState(false);
|
|
4781
4800
|
const callback = React.useCallback((entries) => {
|
|
4782
4801
|
const rect = entries[0].boundingClientRect;
|
|
@@ -4788,13 +4807,11 @@ function useElementVisibility(target, options = {}) {
|
|
|
4788
4807
|
return [visible, stop];
|
|
4789
4808
|
}
|
|
4790
4809
|
|
|
4791
|
-
function useWindowsFocus() {
|
|
4792
|
-
const [focused, setFocused] = React.useState(
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
return window.document.hasFocus();
|
|
4797
|
-
});
|
|
4810
|
+
function useWindowsFocus(defauleValue = false) {
|
|
4811
|
+
const [focused, setFocused] = React.useState(defauleValue);
|
|
4812
|
+
React.useEffect(() => {
|
|
4813
|
+
setFocused(window.document.hasFocus());
|
|
4814
|
+
}, []);
|
|
4798
4815
|
useEventListener("blur", () => {
|
|
4799
4816
|
setFocused(false);
|
|
4800
4817
|
});
|
|
@@ -4822,6 +4839,10 @@ function useWindowSize() {
|
|
|
4822
4839
|
return windowSize;
|
|
4823
4840
|
}
|
|
4824
4841
|
|
|
4842
|
+
const listenerOptions$1 = {
|
|
4843
|
+
capture: false,
|
|
4844
|
+
passive: true
|
|
4845
|
+
};
|
|
4825
4846
|
function useWindowScroll() {
|
|
4826
4847
|
const [state, setState] = useRafState(() => ({
|
|
4827
4848
|
x: 0,
|
|
@@ -4830,10 +4851,7 @@ function useWindowScroll() {
|
|
|
4830
4851
|
const handleScroll = () => {
|
|
4831
4852
|
setState({ x: window.scrollX, y: window.scrollY });
|
|
4832
4853
|
};
|
|
4833
|
-
useEventListener("scroll", handleScroll, window,
|
|
4834
|
-
capture: false,
|
|
4835
|
-
passive: true
|
|
4836
|
-
});
|
|
4854
|
+
useEventListener("scroll", handleScroll, window, listenerOptions$1);
|
|
4837
4855
|
useIsomorphicLayoutEffect(() => {
|
|
4838
4856
|
handleScroll();
|
|
4839
4857
|
}, []);
|
|
@@ -5105,17 +5123,16 @@ const getRelativePosition = ({
|
|
|
5105
5123
|
return 0;
|
|
5106
5124
|
};
|
|
5107
5125
|
|
|
5108
|
-
|
|
5126
|
+
const listenerOptions = { passive: true };
|
|
5127
|
+
function useScrollIntoView(targetElement, {
|
|
5109
5128
|
duration = 1250,
|
|
5110
5129
|
axis = "y",
|
|
5111
5130
|
onScrollFinish,
|
|
5112
5131
|
easing = easeInOutQuad,
|
|
5113
5132
|
offset = 0,
|
|
5114
5133
|
cancelable = true,
|
|
5115
|
-
isList = false
|
|
5116
|
-
|
|
5117
|
-
scrollElement
|
|
5118
|
-
}) {
|
|
5134
|
+
isList = false
|
|
5135
|
+
} = defaultOptions, scrollElement) {
|
|
5119
5136
|
const frameID = React.useRef(0);
|
|
5120
5137
|
const startTime = React.useRef(0);
|
|
5121
5138
|
const shouldStop = React.useRef(false);
|
|
@@ -5173,8 +5190,8 @@ function useScrollIntoView({
|
|
|
5173
5190
|
shouldStop.current = true;
|
|
5174
5191
|
}
|
|
5175
5192
|
};
|
|
5176
|
-
useEventListener("wheel", handleStop, null,
|
|
5177
|
-
useEventListener("touchmove", handleStop, null,
|
|
5193
|
+
useEventListener("wheel", handleStop, null, listenerOptions);
|
|
5194
|
+
useEventListener("touchmove", handleStop, null, listenerOptions);
|
|
5178
5195
|
React.useEffect(() => cancel, []);
|
|
5179
5196
|
return {
|
|
5180
5197
|
scrollIntoView,
|
|
@@ -5182,12 +5199,7 @@ function useScrollIntoView({
|
|
|
5182
5199
|
};
|
|
5183
5200
|
}
|
|
5184
5201
|
|
|
5185
|
-
const useSticky = ({
|
|
5186
|
-
targetElement,
|
|
5187
|
-
scrollElement,
|
|
5188
|
-
axis = "y",
|
|
5189
|
-
nav = 0
|
|
5190
|
-
}) => {
|
|
5202
|
+
const useSticky = (targetElement, { axis = "y", nav = 0 }, scrollElement) => {
|
|
5191
5203
|
const [isSticky, setSticky] = React.useState(false);
|
|
5192
5204
|
const element = useLatestElement(targetElement);
|
|
5193
5205
|
const { run: scrollHandler } = useThrottleFn(() => {
|
|
@@ -5471,54 +5483,51 @@ function init (converter, defaultAttributes) {
|
|
|
5471
5483
|
|
|
5472
5484
|
var api = init(defaultConverter, { path: '/' });
|
|
5473
5485
|
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
return target;
|
|
5486
|
+
const getInitialState = (key, defaultValue) => {
|
|
5487
|
+
if (defaultValue !== void 0) {
|
|
5488
|
+
return defaultValue;
|
|
5489
|
+
}
|
|
5490
|
+
if (isBrowser) {
|
|
5491
|
+
return api.get(key);
|
|
5492
|
+
}
|
|
5493
|
+
if (process.env.NODE_ENV !== "production") {
|
|
5494
|
+
console.warn(
|
|
5495
|
+
"`useCookie` When server side rendering, defaultValue should be defined to prevent a hydration mismatches."
|
|
5496
|
+
);
|
|
5497
|
+
}
|
|
5498
|
+
return "";
|
|
5488
5499
|
};
|
|
5489
|
-
function useCookie(key, options = {
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
useDeepCompareEffect(() => {
|
|
5495
|
-
const data = csrData ? isFunction$1(csrData) ? csrData() : csrData : isFunction$1(defaultValue) ? defaultValue() : defaultValue;
|
|
5500
|
+
function useCookie(key, options = defaultOptions, defaultValue) {
|
|
5501
|
+
const [cookieValue, setCookieValue] = React.useState(
|
|
5502
|
+
getInitialState(key, defaultValue)
|
|
5503
|
+
);
|
|
5504
|
+
React.useEffect(() => {
|
|
5496
5505
|
const getStoredValue = () => {
|
|
5497
5506
|
const raw = api.get(key);
|
|
5498
5507
|
if (raw !== void 0 && raw !== null) {
|
|
5499
5508
|
return raw;
|
|
5500
5509
|
} else {
|
|
5501
|
-
if (
|
|
5510
|
+
if (defaultValue === void 0) {
|
|
5502
5511
|
api.remove(key);
|
|
5503
5512
|
} else {
|
|
5504
|
-
api.set(key,
|
|
5513
|
+
api.set(key, defaultValue, options);
|
|
5505
5514
|
}
|
|
5506
|
-
return
|
|
5515
|
+
return defaultValue;
|
|
5507
5516
|
}
|
|
5508
5517
|
};
|
|
5509
5518
|
setCookieValue(getStoredValue());
|
|
5510
|
-
}, [
|
|
5519
|
+
}, [defaultValue, key, options]);
|
|
5511
5520
|
const updateCookie = React.useCallback(
|
|
5512
5521
|
(newValue) => {
|
|
5513
5522
|
const value = isFunction$1(newValue) ? newValue(cookieValue) : newValue;
|
|
5514
5523
|
if (value === void 0) {
|
|
5515
5524
|
api.remove(key);
|
|
5516
5525
|
} else {
|
|
5517
|
-
api.set(key, value,
|
|
5526
|
+
api.set(key, value, options);
|
|
5518
5527
|
}
|
|
5519
5528
|
setCookieValue(value);
|
|
5520
5529
|
},
|
|
5521
|
-
[key, cookieValue]
|
|
5530
|
+
[key, cookieValue, options]
|
|
5522
5531
|
);
|
|
5523
5532
|
const refreshCookie = React.useCallback(() => {
|
|
5524
5533
|
const cookieValue2 = api.get(key);
|
|
@@ -5526,7 +5535,7 @@ function useCookie(key, options = {
|
|
|
5526
5535
|
setCookieValue(cookieValue2);
|
|
5527
5536
|
}
|
|
5528
5537
|
}, [key]);
|
|
5529
|
-
return
|
|
5538
|
+
return [cookieValue, updateCookie, refreshCookie];
|
|
5530
5539
|
}
|
|
5531
5540
|
|
|
5532
5541
|
function useDoubleClick({
|
|
@@ -5600,7 +5609,7 @@ const defaultState = {
|
|
|
5600
5609
|
bottom: 0,
|
|
5601
5610
|
right: 0
|
|
5602
5611
|
};
|
|
5603
|
-
function useMeasure(target, options =
|
|
5612
|
+
function useMeasure(target, options = defaultOptions) {
|
|
5604
5613
|
const [rect, setRect] = React.useState(defaultState);
|
|
5605
5614
|
const stop = useResizeObserver(
|
|
5606
5615
|
target,
|