@yamada-ui/utils
Advanced tools
Comparing version 0.0.0-dev-20230716195657 to 0.0.0-dev-20230718011629
@@ -10,3 +10,3 @@ import { Dict } from './index.types.js'; | ||
declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string; | ||
declare const randomColor: ({ string, colors }?: { | ||
declare const randomColor: ({ string, colors, }?: { | ||
string?: string | undefined; | ||
@@ -13,0 +13,0 @@ colors?: string[] | undefined; |
@@ -72,7 +72,3 @@ "use strict"; | ||
var getColor = (color, fallback) => (theme, colorMode) => { | ||
const hex = getMemoizedObject( | ||
theme, | ||
`colors.${color}`, | ||
color | ||
); | ||
const hex = getMemoizedObject(theme, `colors.${color}`, color); | ||
try { | ||
@@ -121,3 +117,6 @@ if (isArray(hex)) { | ||
}; | ||
var randomColor = ({ string, colors } = {}) => { | ||
var randomColor = ({ | ||
string, | ||
colors | ||
} = {}) => { | ||
const fallback = randomHex(); | ||
@@ -124,0 +123,0 @@ if (string && colors) |
@@ -107,3 +107,5 @@ "use strict"; | ||
var getAllFocusable = (container) => { | ||
const focusableEls = Array.from(container.querySelectorAll(focusableElSelector)); | ||
const focusableEls = Array.from( | ||
container.querySelectorAll(focusableElSelector) | ||
); | ||
focusableEls.unshift(container); | ||
@@ -110,0 +112,0 @@ return focusableEls.filter((el) => isFocusable(el) && isVisible(el)); |
@@ -215,5 +215,7 @@ "use strict"; | ||
if (isObject(value)) { | ||
Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => { | ||
result[`${key}.${childKey}`] = childValue; | ||
}); | ||
Object.entries(flattenObject(value, maxDepth - 1)).forEach( | ||
([childKey, childValue]) => { | ||
result[`${key}.${childKey}`] = childValue; | ||
} | ||
); | ||
} else { | ||
@@ -319,3 +321,7 @@ result[key] = value; | ||
}; | ||
return [Context.Provider, useContext2, Context]; | ||
return [ | ||
Context.Provider, | ||
useContext2, | ||
Context | ||
]; | ||
}; | ||
@@ -378,6 +384,9 @@ var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect; | ||
}); | ||
return React.useCallback((...args) => { | ||
var _a; | ||
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args); | ||
}, deps); | ||
return React.useCallback( | ||
(...args) => { | ||
var _a; | ||
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args); | ||
}, | ||
deps | ||
); | ||
}; | ||
@@ -412,19 +421,23 @@ var useUpdateEffect = (callback, deps) => { | ||
const [state, setState] = React.useState(initialState); | ||
const callback = React.useCallback((...args) => { | ||
const callId = ++lastCallId.current; | ||
if (!state.loading) | ||
setState((prevState) => ({ ...prevState, loading: true })); | ||
return func(...args).then( | ||
(value) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ value, loading: false }); | ||
return value; | ||
}, | ||
(error) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
return error; | ||
} | ||
); | ||
}, deps); | ||
const callback = React.useCallback( | ||
(...args) => { | ||
const callId = ++lastCallId.current; | ||
if (!state.loading) | ||
setState((prevState) => ({ ...prevState, loading: true })); | ||
return func(...args).then( | ||
(value) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ value, loading: false }); | ||
return value; | ||
}, | ||
(error) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
return error; | ||
} | ||
); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
deps | ||
); | ||
return [state, callback]; | ||
@@ -502,3 +515,5 @@ }; | ||
var getAllFocusable = (container) => { | ||
const focusableEls = Array.from(container.querySelectorAll(focusableElSelector)); | ||
const focusableEls = Array.from( | ||
container.querySelectorAll(focusableElSelector) | ||
); | ||
focusableEls.unshift(container); | ||
@@ -572,7 +587,3 @@ return focusableEls.filter((el) => isFocusable(el) && isVisible(el)); | ||
var getColor = (color, fallback) => (theme, colorMode) => { | ||
const hex = getMemoizedObject( | ||
theme, | ||
`colors.${color}`, | ||
color | ||
); | ||
const hex = getMemoizedObject(theme, `colors.${color}`, color); | ||
try { | ||
@@ -621,3 +632,6 @@ if (isArray(hex)) { | ||
}; | ||
var randomColor = ({ string, colors } = {}) => { | ||
var randomColor = ({ | ||
string, | ||
colors | ||
} = {}) => { | ||
const fallback = randomHex(); | ||
@@ -624,0 +638,0 @@ if (string && colors) |
@@ -14,6 +14,6 @@ import { Dict } from './index.types.js'; | ||
declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any; | ||
declare const memoizeObject: (func: typeof getObject) => (obj: Dict, path: string | number, fallback?: any, i?: number) => any; | ||
declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any; | ||
declare const memoizeObject: (func: typeof getObject) => <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T; | ||
declare const getMemoizedObject: <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T; | ||
declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>; | ||
export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject }; |
@@ -106,5 +106,7 @@ "use strict"; | ||
if (isObject(value)) { | ||
Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => { | ||
result[`${key}.${childKey}`] = childValue; | ||
}); | ||
Object.entries(flattenObject(value, maxDepth - 1)).forEach( | ||
([childKey, childValue]) => { | ||
result[`${key}.${childKey}`] = childValue; | ||
} | ||
); | ||
} else { | ||
@@ -111,0 +113,0 @@ result[key] = value; |
@@ -64,6 +64,3 @@ import * as React from 'react'; | ||
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>; | ||
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [ | ||
StateFromFunctionReturningPromise<T>, | ||
T | ||
]; | ||
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T]; | ||
declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>; | ||
@@ -70,0 +67,0 @@ type AsyncStateRetry<T> = AsyncState<T> & { |
@@ -80,3 +80,7 @@ "use strict"; | ||
}; | ||
return [Context.Provider, useContext2, Context]; | ||
return [ | ||
Context.Provider, | ||
useContext2, | ||
Context | ||
]; | ||
}; | ||
@@ -139,6 +143,9 @@ var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect; | ||
}); | ||
return React.useCallback((...args) => { | ||
var _a; | ||
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args); | ||
}, deps); | ||
return React.useCallback( | ||
(...args) => { | ||
var _a; | ||
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args); | ||
}, | ||
deps | ||
); | ||
}; | ||
@@ -173,19 +180,23 @@ var useUpdateEffect = (callback, deps) => { | ||
const [state, setState] = React.useState(initialState); | ||
const callback = React.useCallback((...args) => { | ||
const callId = ++lastCallId.current; | ||
if (!state.loading) | ||
setState((prevState) => ({ ...prevState, loading: true })); | ||
return func(...args).then( | ||
(value) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ value, loading: false }); | ||
return value; | ||
}, | ||
(error) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
return error; | ||
} | ||
); | ||
}, deps); | ||
const callback = React.useCallback( | ||
(...args) => { | ||
const callId = ++lastCallId.current; | ||
if (!state.loading) | ||
setState((prevState) => ({ ...prevState, loading: true })); | ||
return func(...args).then( | ||
(value) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ value, loading: false }); | ||
return value; | ||
}, | ||
(error) => { | ||
if (isMounted.current && callId === lastCallId.current) | ||
setState({ error, loading: false }); | ||
return error; | ||
} | ||
); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
deps | ||
); | ||
return [state, callback]; | ||
@@ -192,0 +203,0 @@ }; |
{ | ||
"name": "@yamada-ui/utils", | ||
"version": "0.0.0-dev-20230716195657", | ||
"version": "0.0.0-dev-20230718011629", | ||
"description": "Yamada UI utils", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135127
3509