@zayne-labs/toolkit-react 0.9.47 → 0.9.50
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/esm/hooks/index.d.ts +1 -1
- package/dist/esm/hooks-cJL0eNIo.js.map +1 -1
- package/dist/esm/{index-DeDvIi3X.d.ts → index-44MAU7Zb.d.ts} +9 -39
- package/dist/esm/utils/index.d.ts +0 -6
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/zustand/index.d.ts +9 -12
- package/dist/esm/zustand/index.js.map +1 -1
- package/package.json +11 -11
@@ -1,2 +1,2 @@
|
|
1
|
-
import { ContextError
|
1
|
+
import { ContextError, CustomContextOptions, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect } from "../index-44MAU7Zb.js";
|
2
2
|
export { ContextError, CustomContextOptions, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hooks-cJL0eNIo.js","names":["hook: string","provider: string","options: CustomContextOptions<TContextValue, TStrict>","callbackFn: TCallback | undefined","useAfterMountEffect: typeof useEffect","effect: () => Promise<ReturnType<React.EffectCallback>>","deps?: React.DependencyList","callBackFn: React.EffectCallback","callBackFn: () => void","cleanUpFn: Destructor","target: HTMLElement","className: string","elementsInfoArray: ElementsInfoArray<TTargetElement>","initCallbackFn: () => TResult","options: AnimationOptions","refOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>","callback: (event: MouseEvent | TouchEvent) => void","options?: UseClickOutsideOptions","value: string","callBackFn: CallbackFn<TParams>","delay: number | undefined","defaultValue: TValue","initialValue: InitialState","newValue?: TValue","options: DisclosureOptions","value?: TValue","x: TState","store: StoreApi<TState>","selector: SelectorFn<TState, TSlice>","options?: LocationStoreOptions","useLocationState","selector?: SelectorFn<LocationInfo, TSlice>","useAnimationPresence: UseSpecificPresence","value: boolean","newValue?: TValue","useTransitionPresence: UseSpecificPresence","value: boolean","newValue?: TValue","usePresence: UsePresence","options: ScrollObserverOptions","observedElementRef: RefCallback<TElement>","item: unknown","item: Record<string, unknown>","query: string","initialData: TData[]","delay?: number","options?: UseSearchParamsOptions","newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)","newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)","baseOptions: StorageOptions<TState>","useStorageState","selector?: SelectorFn<TState, TSlice>","key: string","initialValue?: TValue","options?: UseStorageStateOptions<TValue> & { select?: SelectorFn<TValue, TSlice> }","callbackFn: CallbackFn<TParams>","delay: number"],"sources":["../../src/hooks/createCustomContext.ts","../../src/hooks/useCallbackRef.ts","../../src/hooks/effects/useAfterMountEffect.ts","../../src/hooks/effects/useAsyncEffect.ts","../../src/hooks/effects/useEffectOnce.ts","../../src/hooks/effects/useLifeCycle.ts","../../src/hooks/effects/useMountEffect.ts","../../src/hooks/effects/useUnMountEffect.ts","../../src/hooks/useAnimateElementRefs.ts","../../src/hooks/useConstant.ts","../../src/hooks/useAnimationInterval.ts","../../src/hooks/useClickOutside.ts","../../src/hooks/useCopyToClipboard.ts","../../src/hooks/useDebounce.ts","../../src/hooks/useToggle.ts","../../src/hooks/useDisclosure.ts","../../src/hooks/useIsServer.ts","../../src/hooks/useStore.ts","../../src/hooks/useLocationState.ts","../../src/hooks/usePresence/useAnimationPresence.ts","../../src/hooks/usePresence/useTransitionPresence.ts","../../src/hooks/usePresence/usePresence.ts","../../src/hooks/useScrollObserver.ts","../../src/hooks/useSearch.ts","../../src/hooks/useSearchParams.ts","../../src/hooks/useStorageState.ts","../../src/hooks/useThrottle.ts"],"sourcesContent":["import { defineEnum } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createContext, use } from \"react\";\n\nexport class ContextError extends Error {\n\toverride name = \"ContextError\";\n\n\tconstructor(...args: Parameters<typeof Error>) {\n\t\tsuper(...args);\n\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n}\n\nexport const getErrorMessage = (hook: string, provider: string) => {\n\treturn `${hook} returned \"null\". Did you forget to wrap the necessary components within ${provider}?`;\n};\n\nexport type CustomContextOptions<TContextValue, TStrict extends boolean> = {\n\tdefaultValue?: TContextValue | null;\n\terrorMessage?: string;\n\textension?: (contextValue: NoInfer<TContextValue> | null) => TContextValue | null;\n\thookName?: string;\n\tname?: string;\n\tproviderName?: string;\n\tstrict?: TStrict;\n};\n\ntype UseCustomContextResult<TContextValue, TStrict extends boolean> = TStrict extends true\n\t? TContextValue\n\t: TContextValue | null;\n\nconst createCustomContext = <TContextValue, TStrict extends boolean = true>(\n\toptions: CustomContextOptions<TContextValue, TStrict> = {}\n) => {\n\tconst {\n\t\tdefaultValue = null,\n\t\terrorMessage,\n\t\textension,\n\t\thookName = \"useUnnamedContext\",\n\t\tproviderName = \"UnnamedContextProvider\",\n\t\tname = providerName.endsWith(\"Provider\") ? providerName.slice(0, -8) : \"UnnamedContext\",\n\t\tstrict = true,\n\t} = options;\n\n\tconst Context = createContext<TContextValue | null>(defaultValue);\n\n\tContext.displayName = name;\n\n\tconst useCustomContext = (): UseCustomContextResult<TContextValue, TStrict> => {\n\t\tconst contextValue = use(Context);\n\n\t\tconst extendedContextValue = extension?.(contextValue) ?? contextValue;\n\n\t\tif (strict && extendedContextValue === null) {\n\t\t\tthrow new ContextError(errorMessage ?? getErrorMessage(hookName, providerName));\n\t\t}\n\n\t\treturn extendedContextValue as NonNullable<typeof extendedContextValue>;\n\t};\n\n\treturn defineEnum([Context, useCustomContext]);\n};\n\nexport { createCustomContext };\n","import type { AnyFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Returns a stable function that always points to the latest version of the callback function.\n * @param callbackFn - The function to reference\n * @returns a stable function that always points to the latest version of the callback function\n */\n\nconst useCallbackRef = <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => {\n\tconst callbackRef = useRef(callbackFn);\n\n\tuseLayoutEffect(() => {\n\t\t// == Doing this instead updating it during render cuz according to Dan Abramov, render should be pure\n\t\tcallbackRef.current = callbackFn;\n\t}, [callbackFn]);\n\n\tconst savedCallback = useCallback(\n\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- callbackRef.current can be null in some cases\n\t\t(...params: unknown[]) => (callbackRef.current as AnyFunction)?.(...params) as unknown,\n\t\t[]\n\t);\n\n\treturn savedCallback as TCallback;\n};\n\nexport { useCallbackRef };\n","import { useEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nconst useAfterMountEffect: typeof useEffect = (callBackFn, deps) => {\n\tconst isFirstMount = useRef(true);\n\tconst stableCallback = useCallbackRef(callBackFn);\n\n\tuseEffect(() => {\n\t\tif (isFirstMount.current) {\n\t\t\tisFirstMount.current = false;\n\t\t\treturn;\n\t\t}\n\n\t\tstableCallback();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableCallback is stable\n\t}, deps);\n};\nexport { useAfterMountEffect };\n","import { useEffect, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nexport function useAsyncEffect(\n\teffect: () => Promise<ReturnType<React.EffectCallback>>,\n\tdeps?: React.DependencyList\n) {\n\tconst stableEffectCallback = useCallbackRef(effect);\n\tconst [destroy, setDestroy] = useState<ReturnType<React.EffectCallback>>();\n\n\tuseEffect(() => {\n\t\tconst e = stableEffectCallback();\n\n\t\tasync function execute() {\n\t\t\tsetDestroy(await e);\n\t\t}\n\n\t\tvoid execute();\n\n\t\treturn () => void destroy?.();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableEffectCallback is stable\n\t}, deps);\n}\n","import { useEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nconst useEffectOnce = (callBackFn: React.EffectCallback) => {\n\tconst stableCallback = useCallbackRef(callBackFn);\n\n\tconst effectGuard = useRef(false);\n\n\t// == savedCallback is always stable so no worries about re-execution of this effect\n\tuseEffect(() => {\n\t\tif (effectGuard.current) return;\n\n\t\teffectGuard.current = true;\n\n\t\treturn stableCallback();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableCallback is stable\n\t}, []);\n};\n\nexport { useEffectOnce };\n","import { useEffect } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nexport type Destructor = ReturnType<React.EffectCallback>;\n\ntype LifeCycleOptions = {\n\tonMount?: () => void;\n\tonUnmount?: Destructor;\n};\n\nconst useLifeCycle = ({ onMount, onUnmount }: LifeCycleOptions) => {\n\tconst stableOnMount = useCallbackRef(onMount);\n\tconst stableOnUnmount = useCallbackRef(onUnmount);\n\n\tuseEffect(() => {\n\t\tstableOnMount();\n\n\t\treturn stableOnUnmount;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnMount and stableOnUnmount are stable\n\t}, []);\n};\n\nexport { useLifeCycle };\n","import { useLifeCycle } from \"./useLifeCycle\";\n\nconst useMountEffect = (callBackFn: () => void) => {\n\tuseLifeCycle({ onMount: callBackFn });\n};\n\nexport { useMountEffect };\n","import { type Destructor, useLifeCycle } from \"./useLifeCycle\";\n\nconst useUnmountEffect = (cleanUpFn: Destructor) => useLifeCycle({ onUnmount: cleanUpFn });\n\nexport { useUnmountEffect };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { type NonEmptyArray, isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\ntype ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{\n\tanimationClass: string;\n\ttargetElement: TTargetElement;\n}>;\n\nconst removeClass = (target: HTMLElement, className: string) => () => target.classList.remove(className);\n\n/**\n * This is a custom React hook that adds and removes animation classes to specified HTML elements.\n * @param elementsInfoArray - An array of objects that contain information about the animation class and the target HTML element.\n * @returns - An object containing the refs of the animated elements and a function to handle the initiation and removal animation.\n */\n\nconst useAnimateElementRefs = <TTargetElement extends string>(\n\telementsInfoArray: ElementsInfoArray<TTargetElement>\n) => {\n\tconst elementsRef = useRef<Record<TTargetElement, HTMLElement | null>>({} as never);\n\n\tconst addAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\telementsRef.current[targetElement].classList.add(animationClass);\n\t\t}\n\t});\n\n\tconst removeAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ton(\n\t\t\t\t\"transitionend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\n\t\t\ton(\n\t\t\t\t\"animationend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\t\t}\n\t});\n\n\t// Add animation classes to elements and remove them after the animation ends\n\tconst handleElementsAnimation = useCallback(() => {\n\t\taddAnimationClasses();\n\n\t\tremoveAnimationClasses();\n\t}, [addAnimationClasses, removeAnimationClasses]);\n\n\treturn { animatedElements: elementsRef.current, handleElementsAnimation };\n};\n\nexport { useAnimateElementRefs };\n","import { useRef } from \"react\";\n\nconst useConstant = <TResult>(initCallbackFn: () => TResult) => {\n\tconst resultRef = useRef<TResult | null>(null);\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- The current case is justified since it's optimizable by the react compiler\n\tif (resultRef.current === null) {\n\t\tresultRef.current = initCallbackFn();\n\t}\n\n\treturn resultRef.current;\n};\n\nexport { useConstant };\n","import { type AnimationIntervalOptions, setAnimationInterval } from \"@zayne-labs/toolkit-core\";\nimport type { Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\ntype AnimationOptions = Prettify<\n\tAnimationIntervalOptions & {\n\t\tintervalDuration: number | null;\n\t\tonAnimation: () => void;\n\t}\n>;\n\nconst useAnimationInterval = (options: AnimationOptions) => {\n\tconst { intervalDuration, onAnimation, once } = options;\n\n\tconst latestCallback = useCallbackRef(onAnimation);\n\n\t// prettier-ignore\n\tconst { start, stop } = useConstant(() => setAnimationInterval(latestCallback, intervalDuration, { once }));\n\n\tuseEffect(() => {\n\t\tif (intervalDuration === null) return;\n\n\t\tstart();\n\n\t\treturn stop;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- start and stop are stable\n\t}, [intervalDuration]);\n\n\treturn { start, stop };\n};\n\nexport { useAnimationInterval };\n","import { onClickOutside, toArray } from \"@zayne-labs/toolkit-core\";\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\ntype UseClickOutsideOptions = {\n\tenabled?: boolean;\n};\n\nconst useClickOutside = <TElement extends HTMLElement>(\n\trefOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>,\n\tcallback: (event: MouseEvent | TouchEvent) => void,\n\toptions?: UseClickOutsideOptions\n) => {\n\tconst { enabled = true } = options ?? {};\n\n\tconst savedCallback = useCallbackRef(callback);\n\n\tuseEffect(() => {\n\t\tif (!enabled) return;\n\n\t\tconst controller = new AbortController();\n\n\t\tconst elementArray = toArray(refOrRefArray).map((ref) => ref.current);\n\n\t\tonClickOutside(elementArray, savedCallback, { signal: controller.signal });\n\n\t\treturn () => {\n\t\t\tcontroller.abort();\n\t\t};\n\t}, [enabled, refOrRefArray, savedCallback]);\n};\n\nexport { useClickOutside };\n","import { copyToClipboard } from \"@zayne-labs/toolkit-core\";\nimport { useState } from \"react\";\n\nconst useCopyToClipboard = () => {\n\tconst [state, setState] = useState(\"\");\n\n\tconst handleCopy = (value: string) => {\n\t\tsetState(value);\n\t\tvoid copyToClipboard(value);\n\t};\n\n\treturn { copiedValue: state, handleCopy };\n};\n\nexport { useCopyToClipboard };\n","import { debounce } from \"@zayne-labs/toolkit-core\";\nimport type { CallbackFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { useUnmountEffect } from \"./effects/useUnMountEffect\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nexport const useDebouncedFn = <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {\n\tconst latestCallback = useCallbackRef(callBackFn);\n\n\tconst debouncedFn = useConstant(() => debounce(latestCallback, delay));\n\n\tuseUnmountEffect(() => {\n\t\tdebouncedFn.cancel();\n\t\tdebouncedFn.cancelMaxWait();\n\t});\n\n\treturn debouncedFn;\n};\n\nexport const useDebouncedState = <TValue>(defaultValue: TValue, delay: number | undefined) => {\n\tconst [value, setValue] = useState(defaultValue);\n\n\tconst setDebouncedValue = useConstant(() => debounce(setValue, delay));\n\n\tuseUnmountEffect(() => {\n\t\tsetDebouncedValue.cancel();\n\t\tsetDebouncedValue.cancelMaxWait();\n\t});\n\n\treturn [value, setDebouncedValue, setValue] as const;\n};\n","import { useCallback, useState } from \"react\";\n\ntype InitialState = boolean | (() => boolean);\n\nconst useToggle = (initialValue: InitialState = false) => {\n\tconst [value, setValue] = useState(initialValue);\n\n\tconst toggle = useCallback(<TValue>(newValue?: TValue) => {\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetValue(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetValue((prev) => !prev);\n\t}, []);\n\n\treturn [value, toggle] as const;\n};\n\nexport { useToggle };\n","import { lockScroll } from \"@zayne-labs/toolkit-core\";\nimport { isBoolean } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useMemo } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useToggle } from \"./useToggle\";\n\ntype DisclosureOptions = {\n\thasScrollControl?: boolean;\n\tinitialState?: boolean | (() => boolean);\n};\n\nconst useDisclosure = (options: DisclosureOptions = {}) => {\n\tconst { hasScrollControl = false, initialState = false } = options;\n\tconst [isOpen, toggleIsOpen] = useToggle(initialState);\n\n\tconst onOpen = useCallbackRef(() => {\n\t\ttoggleIsOpen(true);\n\t\thasScrollControl && lockScroll({ lock: true });\n\t});\n\n\tconst onClose = useCallbackRef(() => {\n\t\ttoggleIsOpen(false);\n\t\thasScrollControl && lockScroll({ lock: false });\n\t});\n\n\tconst onToggle = useCallbackRef(<TValue>(value?: TValue) => {\n\t\tif (isBoolean(value)) {\n\t\t\ttoggleIsOpen(value);\n\t\t\thasScrollControl && lockScroll({ lock: value });\n\t\t\treturn;\n\t\t}\n\n\t\tisOpen ? onClose() : onOpen();\n\t});\n\n\tconst api = useMemo(() => ({ isOpen, onClose, onOpen, onToggle }), [isOpen, onClose, onOpen, onToggle]);\n\n\treturn api;\n};\nexport { useDisclosure };\n","import { useSyncExternalStore } from \"react\";\n\nconst noopStore = {\n\tgetServerSnapshot: () => true,\n\tgetSnapshot: () => false,\n\t// eslint-disable-next-line unicorn/consistent-function-scoping -- It's fine\n\tsubscribe: () => () => {},\n};\n\n/**\n * @description Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nconst useIsServer = () => {\n\tconst isServer = useSyncExternalStore(\n\t\tnoopStore.subscribe,\n\t\tnoopStore.getSnapshot,\n\t\tnoopStore.getServerSnapshot\n\t);\n\n\treturn isServer;\n};\n\nexport { useIsServer };\n","import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useDebugValue, useSyncExternalStore } from \"react\";\n\nconst identity = <TState>(x: TState) => x;\n\nconst useStore = <TState, TSlice>(\n\tstore: StoreApi<TState>,\n\tselector: SelectorFn<TState, TSlice> = identity as never\n) => {\n\tconst slice = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\t() => selector(store.getState()),\n\t\t() => selector(store.getInitialState())\n\t);\n\n\tuseDebugValue(slice);\n\n\treturn slice;\n};\n\nexport { useStore };\n","import {\n\ttype LocationInfo,\n\ttype LocationStoreApi,\n\ttype LocationStoreOptions,\n\tcreateLocationStore,\n} from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useConstant } from \"./useConstant\";\nimport { useStore } from \"./useStore\";\n\ntype UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];\n\nexport const createUseLocationState = (options?: LocationStoreOptions) => {\n\tconst locationStore = createLocationStore(options);\n\n\ttype UseBoundLocationState = LocationStoreApi & {\n\t\t<TSlice = LocationInfo>(selector?: SelectorFn<LocationInfo, TSlice>): UseLocationResult<TSlice>;\n\t};\n\n\tconst useLocationState = <TSlice = LocationInfo>(\n\t\tselector?: SelectorFn<LocationInfo, TSlice>\n\t): UseLocationResult<TSlice> => {\n\t\tconst stateSlice = useStore(locationStore as never, selector);\n\n\t\treturn [stateSlice, locationStore];\n\t};\n\n\tObject.assign(useLocationState, locationStore);\n\n\treturn useLocationState as UseBoundLocationState;\n};\n\nexport const useLocationState = <TSlice = LocationInfo>(\n\tselector?: SelectorFn<LocationInfo, TSlice>,\n\toptions?: LocationStoreOptions\n): UseLocationResult<TSlice> => {\n\tconst locationStore = useConstant(() => createLocationStore(options));\n\n\tconst stateSlice = useStore(locationStore as never, selector);\n\n\treturn [stateSlice, locationStore];\n};\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\nimport { useDebouncedState } from \"../useDebounce\";\nimport type { UseSpecificPresence } from \"./types\";\n\nconst useAnimationPresence: UseSpecificPresence = (options = {}) => {\n\tconst { defaultValue = true, duration, onExitComplete } = options;\n\n\tconst [isShown, setIsShown] = useState(defaultValue);\n\n\tconst [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(\n\t\tdefaultValue,\n\t\tduration\n\t);\n\tconst elementRef = useRef<HTMLElement>(null);\n\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tuseEffect(() => {\n\t\t!isMounted && stableOnExitComplete();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnExitComplete is stable\n\t}, [isMounted]);\n\n\tconst handleIsMountedWithoutRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetRegularIsMounted(true);\n\t\t\treturn;\n\t\t}\n\n\t\tsetDebouncedIsMounted(false);\n\t};\n\n\tconst handleIsMountedWithRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetRegularIsMounted(true);\n\t\t\treturn;\n\t\t}\n\n\t\ton(\"animationend\", elementRef.current, () => {\n\t\t\tsetDebouncedIsMounted.cancel();\n\t\t\tsetRegularIsMounted(false);\n\t\t});\n\t};\n\n\tconst toggleVisibility = useCallbackRef(<TValue>(newValue?: TValue) => {\n\t\tconst handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;\n\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetIsShown(newValue);\n\t\t\thandleSetIsMounted(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsShown(!isShown);\n\t\thandleSetIsMounted(!isShown);\n\t});\n\n\treturn {\n\t\tisPresent: isMounted,\n\t\tisVisible: isShown,\n\t\ttoggleVisibility,\n\t\t...(duration === undefined && { elementRef }),\n\t} as never;\n};\n\nexport { useAnimationPresence };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\nimport { useDebouncedState } from \"../useDebounce\";\nimport type { UseSpecificPresence } from \"./types\";\n\nconst useTransitionPresence: UseSpecificPresence = (options = {}) => {\n\tconst { defaultValue = true, duration, onExitComplete } = options;\n\n\tconst [isShown, setIsShown] = useState(defaultValue);\n\n\tconst [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(\n\t\tdefaultValue,\n\t\tduration\n\t);\n\tconst elementRef = useRef<HTMLElement>(null);\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tconst handleIsMountedWithoutRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetDebouncedIsMounted(value, { $delay: 0 });\n\t\t\treturn;\n\t\t}\n\n\t\tsetDebouncedIsMounted(false);\n\t};\n\n\tconst handleIsMountedWithRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetDebouncedIsMounted(value, { $delay: 0 });\n\t\t\treturn;\n\t\t}\n\n\t\ton(\"transitionend\", elementRef.current, () => {\n\t\t\tsetDebouncedIsMounted.cancel();\n\t\t\tsetRegularIsMounted(false);\n\t\t});\n\t};\n\n\tconst toggleVisibility = useCallbackRef(<TValue>(newValue?: TValue) => {\n\t\tconst handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;\n\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetIsShown(newValue);\n\t\t\thandleSetIsMounted(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsShown(!isShown);\n\t\thandleSetIsMounted(!isShown);\n\t});\n\n\tuseEffect(() => {\n\t\t!isMounted && stableOnExitComplete();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnExitComplete is stable\n\t}, [isMounted]);\n\n\treturn {\n\t\tisPresent: isMounted || isShown,\n\t\tisVisible: isMounted && isShown,\n\t\ttoggleVisibility,\n\t\t...(duration === undefined && { elementRef }),\n\t} as never;\n};\n\nexport { useTransitionPresence };\n","import type { UsePresence } from \"./types\";\nimport { useAnimationPresence } from \"./useAnimationPresence\";\nimport { useTransitionPresence } from \"./useTransitionPresence\";\n\n/**\n * usePresence hook provides a way to animate an element, before removing it from the DOM.\n * @param defaultValue - The default value for the presence state. Defaults to `true`.\n * @param options - The options for the usePresence hook.\n * @returns A object containing the boolean that should be used to conditionally render the element (isPresent), another boolean used to toggle the animation classes, and a function to toggle the state.\n */\n\nconst usePresence: UsePresence = (options = {}) => {\n\tconst { type = \"transition\", ...restOfOptions } = options;\n\n\tconst useSpecificPresence = type === \"transition\" ? useTransitionPresence : useAnimationPresence;\n\n\treturn useSpecificPresence(restOfOptions);\n};\n\nexport { usePresence };\n","import { type ScrollObserverOptions, createScrollObserver } from \"@zayne-labs/toolkit-core\";\nimport { type RefCallback, useState } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nconst useScrollObserver = <TElement extends HTMLElement>(options: ScrollObserverOptions = {}) => {\n\tconst { onIntersection, rootMargin = \"10px 0px 0px 0px\", ...restOfOptions } = options;\n\n\tconst [isScrolled, setIsScrolled] = useState(false);\n\n\tconst savedOnIntersection = useCallbackRef(onIntersection);\n\n\tconst { handleObservation } = useConstant(() => {\n\t\treturn createScrollObserver({\n\t\t\tonIntersection: (entry, observer) => {\n\t\t\t\tconst newIsScrolledState = !entry.isIntersecting;\n\n\t\t\t\tsetIsScrolled(newIsScrolledState);\n\n\t\t\t\t// eslint-disable-next-line no-param-reassign -- Mutation is fine here\n\t\t\t\t(entry.target as HTMLElement).dataset.scrolled = String(newIsScrolledState);\n\n\t\t\t\tsavedOnIntersection(entry, observer);\n\t\t\t},\n\t\t\trootMargin,\n\t\t\t...restOfOptions,\n\t\t});\n\t});\n\n\tconst observedElementRef: RefCallback<TElement> = useCallbackRef((element) => {\n\t\tconst cleanupFn = handleObservation(element);\n\n\t\t// == React 18 may not call the cleanup function so we need to call it manually on element unmount\n\t\tif (!element) {\n\t\t\tcleanupFn?.();\n\t\t\treturn;\n\t\t}\n\n\t\treturn cleanupFn;\n\t});\n\n\treturn { isScrolled, observedElementRef };\n};\n\nexport { useScrollObserver };\n","import { isPlainObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { useAfterMountEffect } from \"./effects/useAfterMountEffect\";\nimport { useDebouncedFn } from \"./useDebounce\";\n\nconst isSerializable = (item: unknown): item is boolean | number | string =>\n\ttypeof item === \"string\" || typeof item === \"number\" || typeof item === \"boolean\";\n\nconst checkObjectPropsForQuery = (item: Record<string, unknown>, query: string): boolean => {\n\tfor (const value of Object.values(item)) {\n\t\tif (isSerializable(value) && value.toString().toLowerCase().includes(query)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n};\n\nconst useSearch = <TData>(initialData: TData[], delay?: number) => {\n\tconst [searchQuery, setSearchQuery] = useState(\"\");\n\tconst [filteredData, setFilteredData] = useState(initialData);\n\tconst [isLoading, setIsLoading] = useState(false);\n\n\tconst handleDebouncedSearch = useDebouncedFn(() => {\n\t\tconst query = searchQuery.toLowerCase();\n\n\t\tconst filteredResults = initialData.filter((item) => {\n\t\t\tif (isSerializable(item)) {\n\t\t\t\treturn item.toString().toLowerCase().includes(query);\n\t\t\t}\n\n\t\t\tif (isPlainObject(item)) {\n\t\t\t\treturn checkObjectPropsForQuery(item, query);\n\t\t\t}\n\n\t\t\treturn false;\n\t\t});\n\n\t\tsetFilteredData(filteredResults);\n\t\tsetIsLoading(false);\n\t}, delay);\n\n\tuseAfterMountEffect(() => {\n\t\tsetIsLoading(true);\n\t\thandleDebouncedSearch();\n\t}, [searchQuery]);\n\n\treturn { data: filteredData, isLoading, query: searchQuery, setQuery: setSearchQuery };\n};\n\nexport { useSearch };\n","import {\n\ttype LocationStoreOptions,\n\ttype URLSearchParamsInit,\n\tcreateSearchParams,\n} from \"@zayne-labs/toolkit-core\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useLocationState } from \"./useLocationState\";\n\ntype UseSearchParamsOptions = LocationStoreOptions & {\n\taction?: \"push\" | \"replace\";\n};\n\nexport const useSearchParams = <TSearchParams extends URLSearchParamsInit>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst { action = \"push\", ...restOfOptions } = options ?? {};\n\n\tconst [searchParams, actions] = useLocationState((state) => state.search, restOfOptions);\n\n\tconst setSearchParams = (\n\t\tnewQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParams) : newQueryParams;\n\n\t\tconst nextSearchParams = createSearchParams(params);\n\n\t\tactions[action]({ search: nextSearchParams });\n\t};\n\n\tsetSearchParams.triggerPopstateEvent = actions.triggerPopstateEvent;\n\n\treturn [searchParams, setSearchParams] as const;\n};\n\nexport const useSearchParamsObject = <TSearchParams extends Record<string, string>>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst [searchParams, setSearchParams] = useSearchParams(options);\n\n\tconst searchParamsObject = Object.fromEntries(searchParams) as TSearchParams;\n\n\tconst setSearchParamsObject = (\n\t\tnewQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParamsObject) : newQueryParams;\n\n\t\tsetSearchParams(params);\n\t};\n\n\tsetSearchParamsObject.triggerPopstateEvent = setSearchParams.triggerPopstateEvent;\n\n\treturn [searchParamsObject, setSearchParamsObject] as const;\n};\n","import {\n\ttype StorageOptions,\n\ttype StorageStoreApi,\n\tcreateExternalStorageStore,\n} from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useConstant } from \"./useConstant\";\nimport { useStore } from \"./useStore\";\n\ntype UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: StorageStoreApi<TState>];\n\n/**\n * @description Creates a custom hook that returns a storage state and actions to modify it. You can use this if you need shared options.\n * @note You must use this if you want to be able to prevent syncing state across tabs.\n */\nexport const createUseStorageState = <TState>(baseOptions: StorageOptions<TState>) => {\n\tconst externalStore = createExternalStorageStore(baseOptions);\n\n\ttype UseBoundStorageState = StorageStoreApi<TState> & {\n\t\t<TSlice = TState>(selector?: SelectorFn<TState, TSlice>): UseStorageResult<TState, TSlice>;\n\t};\n\n\tconst useStorageState = <TSlice = TState>(\n\t\tselector?: SelectorFn<TState, TSlice>\n\t): UseStorageResult<TState, TSlice> => {\n\t\tconst stateInStorage = useStore(externalStore, selector);\n\n\t\treturn [stateInStorage, externalStore];\n\t};\n\n\tObject.assign(useStorageState, externalStore);\n\n\treturn useStorageState as UseBoundStorageState;\n};\n\ntype UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, \"initialValue\" | \"key\">;\n\nexport const useStorageState = <TValue, TSlice = TValue>(\n\tkey: string,\n\tinitialValue?: TValue,\n\toptions?: UseStorageStateOptions<TValue> & { select?: SelectorFn<TValue, TSlice> }\n): UseStorageResult<TValue, TSlice> => {\n\tconst { select, ...restOfOptions } = options ?? {};\n\n\tconst externalStore = useConstant(() => {\n\t\treturn createExternalStorageStore({ initialValue, key, ...restOfOptions });\n\t});\n\n\tconst stateInStorage = useStore(externalStore as never, select as never);\n\n\treturn [stateInStorage as never, externalStore];\n};\n","import { throttleByFrame, throttleBySetTimeout, throttleByTime } from \"@zayne-labs/toolkit-core\";\nimport type { CallbackFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useUnmountEffect } from \"./effects\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nexport const useThrottleBySetTimeout = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleBySetTimeout(latestCallback, delay));\n\n\tuseUnmountEffect(() => throttledCallback.cancelTimeout());\n\n\treturn throttledCallback;\n};\n\nexport const useThrottleByTimer = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleByTime(latestCallback, delay));\n\n\treturn throttledCallback;\n};\n\nexport const useThrottleByFrame = <TParams>(callbackFn: CallbackFn<TParams>) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleByFrame(latestCallback));\n\n\tuseUnmountEffect(() => throttledCallback.cancelAnimation());\n\n\treturn throttledCallback;\n};\n"],"mappings":";;;;;AAGA,IAAa,eAAb,cAAkC,MAAM;CACvC,AAAS,OAAO;CAEhB,YAAY,GAAG,MAAgC;AAC9C,QAAM,GAAG,KAAK;AAEd,QAAM,kBAAkB,MAAM,KAAK,YAAY;CAC/C;AACD;AAED,MAAa,kBAAkB,CAACA,MAAcC,aAAqB;AAClE,SAAQ,EAAE,KAAK,2EAA2E,SAAS;AACnG;AAgBD,MAAM,sBAAsB,CAC3BC,UAAwD,CAAE,MACtD;CACJ,MAAM,EACL,eAAe,MACf,cACA,WACA,WAAW,qBACX,eAAe,0BACf,OAAO,aAAa,SAAS,WAAW,GAAG,aAAa,MAAM,GAAG,GAAG,GAAG,kBACvE,SAAS,MACT,GAAG;CAEJ,MAAM,UAAU,cAAoC,aAAa;AAEjE,SAAQ,cAAc;CAEtB,MAAM,mBA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,eAAe,CAAC;AAEzD,QAAO;AACP;AAED,MAAa,qBAAqB,CAAUD,YAAiCC,UAAkB;CAC9F,MAAM,iBAAiB,eAAe,WAAW;CAEjD,MAAM,oBAAoB,YAAY,MAAM,eAAe,gBAAgB,MAAM,CAAC;AAElF,QAAO;AACP;AAED,MAAa,qBAAqB,CAAUD,eAAoC;CAC/E,MAAM,iBAAiB,eAAe,WAAW;CAEjD,MAAM,oBAAoB,YAAY,MAAM,gBAAgB,eAAe,CAAC;AAE5E,kBAAiB,MAAM,kBAAkB,iBAAiB,CAAC;AAE3D,QAAO;AACP"}
|
1
|
+
{"version":3,"file":"hooks-cJL0eNIo.js","names":["hook: string","provider: string","options: CustomContextOptions<TContextValue, TStrict>","callbackFn: TCallback | undefined","useAfterMountEffect: typeof useEffect","effect: () => Promise<ReturnType<React.EffectCallback>>","deps?: React.DependencyList","callBackFn: React.EffectCallback","callBackFn: () => void","cleanUpFn: Destructor","target: HTMLElement","className: string","elementsInfoArray: ElementsInfoArray<TTargetElement>","initCallbackFn: () => TResult","options: AnimationOptions","refOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>","callback: (event: MouseEvent | TouchEvent) => void","options?: UseClickOutsideOptions","value: string","callBackFn: CallbackFn<TParams>","delay: number | undefined","defaultValue: TValue","initialValue: InitialState","newValue?: TValue","options: DisclosureOptions","value?: TValue","x: TState","store: StoreApi<TState>","selector: SelectorFn<TState, TSlice>","options?: LocationStoreOptions","useLocationState","selector?: SelectorFn<LocationInfo, TSlice>","useAnimationPresence: UseSpecificPresence","value: boolean","newValue?: TValue","useTransitionPresence: UseSpecificPresence","value: boolean","newValue?: TValue","usePresence: UsePresence","options: ScrollObserverOptions","observedElementRef: RefCallback<TElement>","item: unknown","item: Record<string, unknown>","query: string","initialData: TData[]","delay?: number","options?: UseSearchParamsOptions","newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)","newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)","baseOptions: StorageOptions<TState>","useStorageState","selector?: SelectorFn<TState, TSlice>","key: string","initialValue?: TValue","options?: UseStorageStateOptions<TValue> & { select?: SelectorFn<TValue, TSlice> }","callbackFn: CallbackFn<TParams>","delay: number"],"sources":["../../src/hooks/createCustomContext.ts","../../src/hooks/useCallbackRef.ts","../../src/hooks/effects/useAfterMountEffect.ts","../../src/hooks/effects/useAsyncEffect.ts","../../src/hooks/effects/useEffectOnce.ts","../../src/hooks/effects/useLifeCycle.ts","../../src/hooks/effects/useMountEffect.ts","../../src/hooks/effects/useUnMountEffect.ts","../../src/hooks/useAnimateElementRefs.ts","../../src/hooks/useConstant.ts","../../src/hooks/useAnimationInterval.ts","../../src/hooks/useClickOutside.ts","../../src/hooks/useCopyToClipboard.ts","../../src/hooks/useDebounce.ts","../../src/hooks/useToggle.ts","../../src/hooks/useDisclosure.ts","../../src/hooks/useIsServer.ts","../../src/hooks/useStore.ts","../../src/hooks/useLocationState.ts","../../src/hooks/usePresence/useAnimationPresence.ts","../../src/hooks/usePresence/useTransitionPresence.ts","../../src/hooks/usePresence/usePresence.ts","../../src/hooks/useScrollObserver.ts","../../src/hooks/useSearch.ts","../../src/hooks/useSearchParams.ts","../../src/hooks/useStorageState.ts","../../src/hooks/useThrottle.ts"],"sourcesContent":["import { defineEnum } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createContext, use } from \"react\";\n\nexport class ContextError extends Error {\n\toverride name = \"ContextError\";\n\n\tconstructor(...args: Parameters<typeof Error>) {\n\t\tsuper(...args);\n\n\t\tError.captureStackTrace(this, this.constructor);\n\t}\n}\n\nexport const getErrorMessage = (hook: string, provider: string) => {\n\treturn `${hook} returned \"null\". Did you forget to wrap the necessary components within ${provider}?`;\n};\n\nexport type CustomContextOptions<TContextValue, TStrict extends boolean> = {\n\tdefaultValue?: TContextValue | null;\n\terrorMessage?: string;\n\textension?: (contextValue: NoInfer<TContextValue> | null) => TContextValue | null;\n\thookName?: string;\n\tname?: string;\n\tproviderName?: string;\n\tstrict?: TStrict;\n};\n\ntype UseCustomContextResult<TContextValue, TStrict extends boolean> =\n\tTStrict extends true ? TContextValue : TContextValue | null;\n\nconst createCustomContext = <TContextValue, TStrict extends boolean = true>(\n\toptions: CustomContextOptions<TContextValue, TStrict> = {}\n) => {\n\tconst {\n\t\tdefaultValue = null,\n\t\terrorMessage,\n\t\textension,\n\t\thookName = \"useUnnamedContext\",\n\t\tproviderName = \"UnnamedContextProvider\",\n\t\tname = providerName.endsWith(\"Provider\") ? providerName.slice(0, -8) : \"UnnamedContext\",\n\t\tstrict = true,\n\t} = options;\n\n\tconst Context = createContext<TContextValue | null>(defaultValue);\n\n\tContext.displayName = name;\n\n\tconst useCustomContext = (): UseCustomContextResult<TContextValue, TStrict> => {\n\t\tconst contextValue = use(Context);\n\n\t\tconst extendedContextValue = extension?.(contextValue) ?? contextValue;\n\n\t\tif (strict && extendedContextValue === null) {\n\t\t\tthrow new ContextError(errorMessage ?? getErrorMessage(hookName, providerName));\n\t\t}\n\n\t\treturn extendedContextValue as NonNullable<typeof extendedContextValue>;\n\t};\n\n\treturn defineEnum([Context, useCustomContext]);\n};\n\nexport { createCustomContext };\n","import type { AnyFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useLayoutEffect, useRef } from \"react\";\n\n/**\n * Returns a stable function that always points to the latest version of the callback function.\n * @param callbackFn - The function to reference\n * @returns a stable function that always points to the latest version of the callback function\n */\n\nconst useCallbackRef = <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => {\n\tconst callbackRef = useRef(callbackFn);\n\n\tuseLayoutEffect(() => {\n\t\t// == Doing this instead updating it during render cuz according to Dan Abramov, render should be pure\n\t\tcallbackRef.current = callbackFn;\n\t}, [callbackFn]);\n\n\tconst savedCallback = useCallback(\n\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- callbackRef.current can be null in some cases\n\t\t(...params: unknown[]) => (callbackRef.current as AnyFunction)?.(...params) as unknown,\n\t\t[]\n\t);\n\n\treturn savedCallback as TCallback;\n};\n\nexport { useCallbackRef };\n","import { useEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nconst useAfterMountEffect: typeof useEffect = (callBackFn, deps) => {\n\tconst isFirstMount = useRef(true);\n\tconst stableCallback = useCallbackRef(callBackFn);\n\n\tuseEffect(() => {\n\t\tif (isFirstMount.current) {\n\t\t\tisFirstMount.current = false;\n\t\t\treturn;\n\t\t}\n\n\t\tstableCallback();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableCallback is stable\n\t}, deps);\n};\nexport { useAfterMountEffect };\n","import { useEffect, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nexport function useAsyncEffect(\n\teffect: () => Promise<ReturnType<React.EffectCallback>>,\n\tdeps?: React.DependencyList\n) {\n\tconst stableEffectCallback = useCallbackRef(effect);\n\tconst [destroy, setDestroy] = useState<ReturnType<React.EffectCallback>>();\n\n\tuseEffect(() => {\n\t\tconst e = stableEffectCallback();\n\n\t\tasync function execute() {\n\t\t\tsetDestroy(await e);\n\t\t}\n\n\t\tvoid execute();\n\n\t\treturn () => void destroy?.();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableEffectCallback is stable\n\t}, deps);\n}\n","import { useEffect, useRef } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nconst useEffectOnce = (callBackFn: React.EffectCallback) => {\n\tconst stableCallback = useCallbackRef(callBackFn);\n\n\tconst effectGuard = useRef(false);\n\n\t// == savedCallback is always stable so no worries about re-execution of this effect\n\tuseEffect(() => {\n\t\tif (effectGuard.current) return;\n\n\t\teffectGuard.current = true;\n\n\t\treturn stableCallback();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableCallback is stable\n\t}, []);\n};\n\nexport { useEffectOnce };\n","import { useEffect } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\n\nexport type Destructor = ReturnType<React.EffectCallback>;\n\ntype LifeCycleOptions = {\n\tonMount?: () => void;\n\tonUnmount?: Destructor;\n};\n\nconst useLifeCycle = ({ onMount, onUnmount }: LifeCycleOptions) => {\n\tconst stableOnMount = useCallbackRef(onMount);\n\tconst stableOnUnmount = useCallbackRef(onUnmount);\n\n\tuseEffect(() => {\n\t\tstableOnMount();\n\n\t\treturn stableOnUnmount;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnMount and stableOnUnmount are stable\n\t}, []);\n};\n\nexport { useLifeCycle };\n","import { useLifeCycle } from \"./useLifeCycle\";\n\nconst useMountEffect = (callBackFn: () => void) => {\n\tuseLifeCycle({ onMount: callBackFn });\n};\n\nexport { useMountEffect };\n","import { type Destructor, useLifeCycle } from \"./useLifeCycle\";\n\nconst useUnmountEffect = (cleanUpFn: Destructor) => useLifeCycle({ onUnmount: cleanUpFn });\n\nexport { useUnmountEffect };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { type NonEmptyArray, isArray } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useCallback, useRef } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\ntype ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{\n\tanimationClass: string;\n\ttargetElement: TTargetElement;\n}>;\n\nconst removeClass = (target: HTMLElement, className: string) => () => target.classList.remove(className);\n\n/**\n * This is a custom React hook that adds and removes animation classes to specified HTML elements.\n * @param elementsInfoArray - An array of objects that contain information about the animation class and the target HTML element.\n * @returns - An object containing the refs of the animated elements and a function to handle the initiation and removal animation.\n */\n\nconst useAnimateElementRefs = <TTargetElement extends string>(\n\telementsInfoArray: ElementsInfoArray<TTargetElement>\n) => {\n\tconst elementsRef = useRef<Record<TTargetElement, HTMLElement | null>>({} as never);\n\n\tconst addAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\telementsRef.current[targetElement].classList.add(animationClass);\n\t\t}\n\t});\n\n\tconst removeAnimationClasses = useCallbackRef(() => {\n\t\tif (!isArray(elementsInfoArray)) {\n\t\t\tconsole.error(\"elementsInfo is not an Array\");\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const { animationClass, targetElement } of elementsInfoArray) {\n\t\t\tif (!elementsRef.current[targetElement]) {\n\t\t\t\tconsole.error(\"ElementError\", `\"${targetElement}\" element does not exist`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ton(\n\t\t\t\t\"transitionend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\n\t\t\ton(\n\t\t\t\t\"animationend\",\n\t\t\t\telementsRef.current[targetElement],\n\t\t\t\tremoveClass(elementsRef.current[targetElement], animationClass)\n\t\t\t);\n\t\t}\n\t});\n\n\t// Add animation classes to elements and remove them after the animation ends\n\tconst handleElementsAnimation = useCallback(() => {\n\t\taddAnimationClasses();\n\n\t\tremoveAnimationClasses();\n\t}, [addAnimationClasses, removeAnimationClasses]);\n\n\treturn { animatedElements: elementsRef.current, handleElementsAnimation };\n};\n\nexport { useAnimateElementRefs };\n","import { useRef } from \"react\";\n\nconst useConstant = <TResult>(initCallbackFn: () => TResult) => {\n\tconst resultRef = useRef<TResult | null>(null);\n\n\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- The current case is justified since it's optimizable by the react compiler\n\tif (resultRef.current === null) {\n\t\tresultRef.current = initCallbackFn();\n\t}\n\n\treturn resultRef.current;\n};\n\nexport { useConstant };\n","import { type AnimationIntervalOptions, setAnimationInterval } from \"@zayne-labs/toolkit-core\";\nimport type { Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\ntype AnimationOptions = Prettify<\n\tAnimationIntervalOptions & {\n\t\tintervalDuration: number | null;\n\t\tonAnimation: () => void;\n\t}\n>;\n\nconst useAnimationInterval = (options: AnimationOptions) => {\n\tconst { intervalDuration, onAnimation, once } = options;\n\n\tconst latestCallback = useCallbackRef(onAnimation);\n\n\t// prettier-ignore\n\tconst { start, stop } = useConstant(() => setAnimationInterval(latestCallback, intervalDuration, { once }));\n\n\tuseEffect(() => {\n\t\tif (intervalDuration === null) return;\n\n\t\tstart();\n\n\t\treturn stop;\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- start and stop are stable\n\t}, [intervalDuration]);\n\n\treturn { start, stop };\n};\n\nexport { useAnimationInterval };\n","import { onClickOutside, toArray } from \"@zayne-labs/toolkit-core\";\nimport { useEffect } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\n\ntype UseClickOutsideOptions = {\n\tenabled?: boolean;\n};\n\nconst useClickOutside = <TElement extends HTMLElement>(\n\trefOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>,\n\tcallback: (event: MouseEvent | TouchEvent) => void,\n\toptions?: UseClickOutsideOptions\n) => {\n\tconst { enabled = true } = options ?? {};\n\n\tconst savedCallback = useCallbackRef(callback);\n\n\tuseEffect(() => {\n\t\tif (!enabled) return;\n\n\t\tconst controller = new AbortController();\n\n\t\tconst elementArray = toArray(refOrRefArray).map((ref) => ref.current);\n\n\t\tonClickOutside(elementArray, savedCallback, { signal: controller.signal });\n\n\t\treturn () => {\n\t\t\tcontroller.abort();\n\t\t};\n\t}, [enabled, refOrRefArray, savedCallback]);\n};\n\nexport { useClickOutside };\n","import { copyToClipboard } from \"@zayne-labs/toolkit-core\";\nimport { useState } from \"react\";\n\nconst useCopyToClipboard = () => {\n\tconst [state, setState] = useState(\"\");\n\n\tconst handleCopy = (value: string) => {\n\t\tsetState(value);\n\t\tvoid copyToClipboard(value);\n\t};\n\n\treturn { copiedValue: state, handleCopy };\n};\n\nexport { useCopyToClipboard };\n","import { debounce } from \"@zayne-labs/toolkit-core\";\nimport type { CallbackFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { useUnmountEffect } from \"./effects/useUnMountEffect\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nexport const useDebouncedFn = <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {\n\tconst latestCallback = useCallbackRef(callBackFn);\n\n\tconst debouncedFn = useConstant(() => debounce(latestCallback, delay));\n\n\tuseUnmountEffect(() => {\n\t\tdebouncedFn.cancel();\n\t\tdebouncedFn.cancelMaxWait();\n\t});\n\n\treturn debouncedFn;\n};\n\nexport const useDebouncedState = <TValue>(defaultValue: TValue, delay: number | undefined) => {\n\tconst [value, setValue] = useState(defaultValue);\n\n\tconst setDebouncedValue = useConstant(() => debounce(setValue, delay));\n\n\tuseUnmountEffect(() => {\n\t\tsetDebouncedValue.cancel();\n\t\tsetDebouncedValue.cancelMaxWait();\n\t});\n\n\treturn [value, setDebouncedValue, setValue] as const;\n};\n","import { useCallback, useState } from \"react\";\n\ntype InitialState = boolean | (() => boolean);\n\nconst useToggle = (initialValue: InitialState = false) => {\n\tconst [value, setValue] = useState(initialValue);\n\n\tconst toggle = useCallback(<TValue>(newValue?: TValue) => {\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetValue(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetValue((prev) => !prev);\n\t}, []);\n\n\treturn [value, toggle] as const;\n};\n\nexport { useToggle };\n","import { lockScroll } from \"@zayne-labs/toolkit-core\";\nimport { isBoolean } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useMemo } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useToggle } from \"./useToggle\";\n\ntype DisclosureOptions = {\n\thasScrollControl?: boolean;\n\tinitialState?: boolean | (() => boolean);\n};\n\nconst useDisclosure = (options: DisclosureOptions = {}) => {\n\tconst { hasScrollControl = false, initialState = false } = options;\n\tconst [isOpen, toggleIsOpen] = useToggle(initialState);\n\n\tconst onOpen = useCallbackRef(() => {\n\t\ttoggleIsOpen(true);\n\t\thasScrollControl && lockScroll({ lock: true });\n\t});\n\n\tconst onClose = useCallbackRef(() => {\n\t\ttoggleIsOpen(false);\n\t\thasScrollControl && lockScroll({ lock: false });\n\t});\n\n\tconst onToggle = useCallbackRef(<TValue>(value?: TValue) => {\n\t\tif (isBoolean(value)) {\n\t\t\ttoggleIsOpen(value);\n\t\t\thasScrollControl && lockScroll({ lock: value });\n\t\t\treturn;\n\t\t}\n\n\t\tisOpen ? onClose() : onOpen();\n\t});\n\n\tconst api = useMemo(() => ({ isOpen, onClose, onOpen, onToggle }), [isOpen, onClose, onOpen, onToggle]);\n\n\treturn api;\n};\nexport { useDisclosure };\n","import { useSyncExternalStore } from \"react\";\n\nconst noopStore = {\n\tgetServerSnapshot: () => true,\n\tgetSnapshot: () => false,\n\t// eslint-disable-next-line unicorn/consistent-function-scoping -- It's fine\n\tsubscribe: () => () => {},\n};\n\n/**\n * @description Returns whether the component is currently being server side rendered or\n * hydrated on the client. Can be used to delay browser-specific rendering\n * until after hydration.\n */\nconst useIsServer = () => {\n\tconst isServer = useSyncExternalStore(\n\t\tnoopStore.subscribe,\n\t\tnoopStore.getSnapshot,\n\t\tnoopStore.getServerSnapshot\n\t);\n\n\treturn isServer;\n};\n\nexport { useIsServer };\n","import type { StoreApi } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useDebugValue, useSyncExternalStore } from \"react\";\n\nconst identity = <TState>(x: TState) => x;\n\nconst useStore = <TState, TSlice>(\n\tstore: StoreApi<TState>,\n\tselector: SelectorFn<TState, TSlice> = identity as never\n) => {\n\tconst slice = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\t() => selector(store.getState()),\n\t\t() => selector(store.getInitialState())\n\t);\n\n\tuseDebugValue(slice);\n\n\treturn slice;\n};\n\nexport { useStore };\n","import {\n\tcreateLocationStore,\n\ttype LocationInfo,\n\ttype LocationStoreApi,\n\ttype LocationStoreOptions,\n} from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useConstant } from \"./useConstant\";\nimport { useStore } from \"./useStore\";\n\ntype UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];\n\nexport const createUseLocationState = (options?: LocationStoreOptions) => {\n\tconst locationStore = createLocationStore(options);\n\n\ttype UseBoundLocationState = LocationStoreApi\n\t\t& (<TSlice = LocationInfo>(\n\t\t\tselector?: SelectorFn<LocationInfo, TSlice>\n\t\t) => UseLocationResult<TSlice>);\n\n\tconst useLocationState = <TSlice = LocationInfo>(\n\t\tselector?: SelectorFn<LocationInfo, TSlice>\n\t): UseLocationResult<TSlice> => {\n\t\tconst stateSlice = useStore(locationStore as never, selector);\n\n\t\treturn [stateSlice, locationStore];\n\t};\n\n\tObject.assign(useLocationState, locationStore);\n\n\treturn useLocationState as UseBoundLocationState;\n};\n\nexport const useLocationState = <TSlice = LocationInfo>(\n\tselector?: SelectorFn<LocationInfo, TSlice>,\n\toptions?: LocationStoreOptions\n): UseLocationResult<TSlice> => {\n\tconst locationStore = useConstant(() => createLocationStore(options));\n\n\tconst stateSlice = useStore(locationStore as never, selector);\n\n\treturn [stateSlice, locationStore];\n};\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\nimport { useDebouncedState } from \"../useDebounce\";\nimport type { UseSpecificPresence } from \"./types\";\n\nconst useAnimationPresence: UseSpecificPresence = (options = {}) => {\n\tconst { defaultValue = true, duration, onExitComplete } = options;\n\n\tconst [isShown, setIsShown] = useState(defaultValue);\n\n\tconst [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(\n\t\tdefaultValue,\n\t\tduration\n\t);\n\tconst elementRef = useRef<HTMLElement>(null);\n\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tuseEffect(() => {\n\t\t!isMounted && stableOnExitComplete();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnExitComplete is stable\n\t}, [isMounted]);\n\n\tconst handleIsMountedWithoutRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetRegularIsMounted(true);\n\t\t\treturn;\n\t\t}\n\n\t\tsetDebouncedIsMounted(false);\n\t};\n\n\tconst handleIsMountedWithRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetRegularIsMounted(true);\n\t\t\treturn;\n\t\t}\n\n\t\ton(\"animationend\", elementRef.current, () => {\n\t\t\tsetDebouncedIsMounted.cancel();\n\t\t\tsetRegularIsMounted(false);\n\t\t});\n\t};\n\n\tconst toggleVisibility = useCallbackRef(<TValue>(newValue?: TValue) => {\n\t\tconst handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;\n\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetIsShown(newValue);\n\t\t\thandleSetIsMounted(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsShown(!isShown);\n\t\thandleSetIsMounted(!isShown);\n\t});\n\n\treturn {\n\t\tisPresent: isMounted,\n\t\tisVisible: isShown,\n\t\ttoggleVisibility,\n\t\t...(duration === undefined && { elementRef }),\n\t} as never;\n};\n\nexport { useAnimationPresence };\n","import { on } from \"@zayne-labs/toolkit-core\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useCallbackRef } from \"../useCallbackRef\";\nimport { useDebouncedState } from \"../useDebounce\";\nimport type { UseSpecificPresence } from \"./types\";\n\nconst useTransitionPresence: UseSpecificPresence = (options = {}) => {\n\tconst { defaultValue = true, duration, onExitComplete } = options;\n\n\tconst [isShown, setIsShown] = useState(defaultValue);\n\n\tconst [isMounted, setDebouncedIsMounted, setRegularIsMounted] = useDebouncedState(\n\t\tdefaultValue,\n\t\tduration\n\t);\n\tconst elementRef = useRef<HTMLElement>(null);\n\tconst stableOnExitComplete = useCallbackRef(onExitComplete);\n\n\tconst handleIsMountedWithoutRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetDebouncedIsMounted(value, { $delay: 0 });\n\t\t\treturn;\n\t\t}\n\n\t\tsetDebouncedIsMounted(false);\n\t};\n\n\tconst handleIsMountedWithRef = (value: boolean) => {\n\t\tif (value) {\n\t\t\tsetDebouncedIsMounted(value, { $delay: 0 });\n\t\t\treturn;\n\t\t}\n\n\t\ton(\"transitionend\", elementRef.current, () => {\n\t\t\tsetDebouncedIsMounted.cancel();\n\t\t\tsetRegularIsMounted(false);\n\t\t});\n\t};\n\n\tconst toggleVisibility = useCallbackRef(<TValue>(newValue?: TValue) => {\n\t\tconst handleSetIsMounted = !duration ? handleIsMountedWithRef : handleIsMountedWithoutRef;\n\n\t\tif (typeof newValue === \"boolean\") {\n\t\t\tsetIsShown(newValue);\n\t\t\thandleSetIsMounted(newValue);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsShown(!isShown);\n\t\thandleSetIsMounted(!isShown);\n\t});\n\n\tuseEffect(() => {\n\t\t!isMounted && stableOnExitComplete();\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps -- stableOnExitComplete is stable\n\t}, [isMounted]);\n\n\treturn {\n\t\tisPresent: isMounted || isShown,\n\t\tisVisible: isMounted && isShown,\n\t\ttoggleVisibility,\n\t\t...(duration === undefined && { elementRef }),\n\t} as never;\n};\n\nexport { useTransitionPresence };\n","import type { UsePresence } from \"./types\";\nimport { useAnimationPresence } from \"./useAnimationPresence\";\nimport { useTransitionPresence } from \"./useTransitionPresence\";\n\n/**\n * usePresence hook provides a way to animate an element, before removing it from the DOM.\n * @param defaultValue - The default value for the presence state. Defaults to `true`.\n * @param options - The options for the usePresence hook.\n * @returns A object containing the boolean that should be used to conditionally render the element (isPresent), another boolean used to toggle the animation classes, and a function to toggle the state.\n */\n\nconst usePresence: UsePresence = (options = {}) => {\n\tconst { type = \"transition\", ...restOfOptions } = options;\n\n\tconst useSpecificPresence = type === \"transition\" ? useTransitionPresence : useAnimationPresence;\n\n\treturn useSpecificPresence(restOfOptions);\n};\n\nexport { usePresence };\n","import { type ScrollObserverOptions, createScrollObserver } from \"@zayne-labs/toolkit-core\";\nimport { type RefCallback, useState } from \"react\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nconst useScrollObserver = <TElement extends HTMLElement>(options: ScrollObserverOptions = {}) => {\n\tconst { onIntersection, rootMargin = \"10px 0px 0px 0px\", ...restOfOptions } = options;\n\n\tconst [isScrolled, setIsScrolled] = useState(false);\n\n\tconst savedOnIntersection = useCallbackRef(onIntersection);\n\n\tconst { handleObservation } = useConstant(() => {\n\t\treturn createScrollObserver({\n\t\t\tonIntersection: (entry, observer) => {\n\t\t\t\tconst newIsScrolledState = !entry.isIntersecting;\n\n\t\t\t\tsetIsScrolled(newIsScrolledState);\n\n\t\t\t\t// eslint-disable-next-line no-param-reassign -- Mutation is fine here\n\t\t\t\t(entry.target as HTMLElement).dataset.scrolled = String(newIsScrolledState);\n\n\t\t\t\tsavedOnIntersection(entry, observer);\n\t\t\t},\n\t\t\trootMargin,\n\t\t\t...restOfOptions,\n\t\t});\n\t});\n\n\tconst observedElementRef: RefCallback<TElement> = useCallbackRef((element) => {\n\t\tconst cleanupFn = handleObservation(element);\n\n\t\t// == React 18 may not call the cleanup function so we need to call it manually on element unmount\n\t\tif (!element) {\n\t\t\tcleanupFn?.();\n\t\t\treturn;\n\t\t}\n\n\t\treturn cleanupFn;\n\t});\n\n\treturn { isScrolled, observedElementRef };\n};\n\nexport { useScrollObserver };\n","import { isPlainObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useState } from \"react\";\nimport { useAfterMountEffect } from \"./effects/useAfterMountEffect\";\nimport { useDebouncedFn } from \"./useDebounce\";\n\nconst isSerializable = (item: unknown): item is boolean | number | string =>\n\ttypeof item === \"string\" || typeof item === \"number\" || typeof item === \"boolean\";\n\nconst checkObjectPropsForQuery = (item: Record<string, unknown>, query: string): boolean => {\n\tfor (const value of Object.values(item)) {\n\t\tif (isSerializable(value) && value.toString().toLowerCase().includes(query)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n};\n\nconst useSearch = <TData>(initialData: TData[], delay?: number) => {\n\tconst [searchQuery, setSearchQuery] = useState(\"\");\n\tconst [filteredData, setFilteredData] = useState(initialData);\n\tconst [isLoading, setIsLoading] = useState(false);\n\n\tconst handleDebouncedSearch = useDebouncedFn(() => {\n\t\tconst query = searchQuery.toLowerCase();\n\n\t\tconst filteredResults = initialData.filter((item) => {\n\t\t\tif (isSerializable(item)) {\n\t\t\t\treturn item.toString().toLowerCase().includes(query);\n\t\t\t}\n\n\t\t\tif (isPlainObject(item)) {\n\t\t\t\treturn checkObjectPropsForQuery(item, query);\n\t\t\t}\n\n\t\t\treturn false;\n\t\t});\n\n\t\tsetFilteredData(filteredResults);\n\t\tsetIsLoading(false);\n\t}, delay);\n\n\tuseAfterMountEffect(() => {\n\t\tsetIsLoading(true);\n\t\thandleDebouncedSearch();\n\t}, [searchQuery]);\n\n\treturn { data: filteredData, isLoading, query: searchQuery, setQuery: setSearchQuery };\n};\n\nexport { useSearch };\n","import {\n\ttype LocationStoreOptions,\n\ttype URLSearchParamsInit,\n\tcreateSearchParams,\n} from \"@zayne-labs/toolkit-core\";\nimport { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useLocationState } from \"./useLocationState\";\n\ntype UseSearchParamsOptions = LocationStoreOptions & {\n\taction?: \"push\" | \"replace\";\n};\n\nexport const useSearchParams = <TSearchParams extends URLSearchParamsInit>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst { action = \"push\", ...restOfOptions } = options ?? {};\n\n\tconst [searchParams, actions] = useLocationState((state) => state.search, restOfOptions);\n\n\tconst setSearchParams = (\n\t\tnewQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParams) : newQueryParams;\n\n\t\tconst nextSearchParams = createSearchParams(params);\n\n\t\tactions[action]({ search: nextSearchParams });\n\t};\n\n\tsetSearchParams.triggerPopstateEvent = actions.triggerPopstateEvent;\n\n\treturn [searchParams, setSearchParams] as const;\n};\n\nexport const useSearchParamsObject = <TSearchParams extends Record<string, string>>(\n\toptions?: UseSearchParamsOptions\n) => {\n\tconst [searchParams, setSearchParams] = useSearchParams(options);\n\n\tconst searchParamsObject = Object.fromEntries(searchParams) as TSearchParams;\n\n\tconst setSearchParamsObject = (\n\t\tnewQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)\n\t) => {\n\t\tconst params = isFunction(newQueryParams) ? newQueryParams(searchParamsObject) : newQueryParams;\n\n\t\tsetSearchParams(params);\n\t};\n\n\tsetSearchParamsObject.triggerPopstateEvent = setSearchParams.triggerPopstateEvent;\n\n\treturn [searchParamsObject, setSearchParamsObject] as const;\n};\n","import {\n\tcreateExternalStorageStore,\n\ttype StorageOptions,\n\ttype StorageStoreApi,\n} from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useConstant } from \"./useConstant\";\nimport { useStore } from \"./useStore\";\n\ntype UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: StorageStoreApi<TState>];\n\n/**\n * @description Creates a custom hook that returns a storage state and actions to modify it. You can use this if you need shared options.\n * @note You must use this if you want to be able to prevent syncing state across tabs.\n */\nexport const createUseStorageState = <TState>(baseOptions: StorageOptions<TState>) => {\n\tconst externalStore = createExternalStorageStore(baseOptions);\n\n\ttype UseBoundStorageState = StorageStoreApi<TState>\n\t\t& (<TSlice = TState>(selector?: SelectorFn<TState, TSlice>) => UseStorageResult<TState, TSlice>);\n\n\tconst useStorageState = <TSlice = TState>(\n\t\tselector?: SelectorFn<TState, TSlice>\n\t): UseStorageResult<TState, TSlice> => {\n\t\tconst stateInStorage = useStore(externalStore, selector);\n\n\t\treturn [stateInStorage, externalStore];\n\t};\n\n\tObject.assign(useStorageState, externalStore);\n\n\treturn useStorageState as UseBoundStorageState;\n};\n\ntype UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, \"initialValue\" | \"key\">;\n\nexport const useStorageState = <TValue, TSlice = TValue>(\n\tkey: string,\n\tinitialValue?: TValue,\n\toptions?: UseStorageStateOptions<TValue> & { select?: SelectorFn<TValue, TSlice> }\n): UseStorageResult<TValue, TSlice> => {\n\tconst { select, ...restOfOptions } = options ?? {};\n\n\tconst externalStore = useConstant(() => {\n\t\treturn createExternalStorageStore({ initialValue, key, ...restOfOptions });\n\t});\n\n\tconst stateInStorage = useStore(externalStore as never, select as never);\n\n\treturn [stateInStorage as never, externalStore];\n};\n","import { throttleByFrame, throttleBySetTimeout, throttleByTime } from \"@zayne-labs/toolkit-core\";\nimport type { CallbackFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { useUnmountEffect } from \"./effects\";\nimport { useCallbackRef } from \"./useCallbackRef\";\nimport { useConstant } from \"./useConstant\";\n\nexport const useThrottleBySetTimeout = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleBySetTimeout(latestCallback, delay));\n\n\tuseUnmountEffect(() => throttledCallback.cancelTimeout());\n\n\treturn throttledCallback;\n};\n\nexport const useThrottleByTimer = <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleByTime(latestCallback, delay));\n\n\treturn throttledCallback;\n};\n\nexport const useThrottleByFrame = <TParams>(callbackFn: CallbackFn<TParams>) => {\n\tconst latestCallback = useCallbackRef(callbackFn);\n\n\tconst throttledCallback = useConstant(() => throttleByFrame(latestCallback));\n\n\tuseUnmountEffect(() => throttledCallback.cancelAnimation());\n\n\treturn throttledCallback;\n};\n"],"mappings":";;;;;AAGA,IAAa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,mBAAiB,cAAc;AAE7C,QAAOA;AACP;AAID,MAAa,kBAAkB,CAC9BE,KACAC,cACAC,YACsC;CACtC,MAAM,EAAE,OAAQ,GAAG,eAAe,GAAG,WAAW,CAAE;CAElD,MAAM,gBAAgB,YAAY,MAAM;AACvC,SAAO,2BAA2B;GAAE;GAAc;GAAK,GAAG;EAAe,EAAC;CAC1E,EAAC;CAEF,MAAM,iBAAiB,SAAS,eAAwB,OAAgB;AAExE,QAAO,CAAC,gBAAyB,aAAc;AAC/C;;;;AC5CD,MAAa,0BAA0B,CAAUC,YAAiCC,UAAkB;CACnG,MAAM,iBAAiB,eAAe,WAAW;CAEjD,MAAM,oBAAoB,YAAY,MAAM,qBAAqB,gBAAgB,MAAM,CAAC;AAExF,kBAAiB,MAAM,kBAAkB,eAAe,CAAC;AAEzD,QAAO;AACP;AAED,MAAa,qBAAqB,CAAUD,YAAiCC,UAAkB;CAC9F,MAAM,iBAAiB,eAAe,WAAW;CAEjD,MAAM,oBAAoB,YAAY,MAAM,eAAe,gBAAgB,MAAM,CAAC;AAElF,QAAO;AACP;AAED,MAAa,qBAAqB,CAAUD,eAAoC;CAC/E,MAAM,iBAAiB,eAAe,WAAW;CAEjD,MAAM,oBAAoB,YAAY,MAAM,gBAAgB,eAAe,CAAC;AAE5E,kBAAiB,MAAM,kBAAkB,iBAAiB,CAAC;AAE3D,QAAO;AACP"}
|
@@ -1,11 +1,7 @@
|
|
1
1
|
import { AnyFunction, CallbackFn, NonEmptyArray, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
2
2
|
import * as react5 from "react";
|
3
|
-
import * as react12 from "react";
|
4
|
-
import * as react19 from "react";
|
5
3
|
import { RefCallback, useEffect } from "react";
|
6
4
|
import * as _zayne_labs_toolkit_core7 from "@zayne-labs/toolkit-core";
|
7
|
-
import * as _zayne_labs_toolkit_core17 from "@zayne-labs/toolkit-core";
|
8
|
-
import * as _zayne_labs_toolkit_core21 from "@zayne-labs/toolkit-core";
|
9
5
|
import { AnimationIntervalOptions, LocationInfo, LocationStoreApi, LocationStoreOptions, ScrollObserverOptions, StorageOptions, StorageStoreApi, StoreApi, URLSearchParamsInit } from "@zayne-labs/toolkit-core";
|
10
6
|
|
11
7
|
//#region src/hooks/createCustomContext.d.ts
|
@@ -27,19 +23,15 @@ type UseCustomContextResult<TContextValue, TStrict extends boolean> = TStrict ex
|
|
27
23
|
declare const createCustomContext: <TContextValue, TStrict extends boolean = true>(options?: CustomContextOptions<TContextValue, TStrict>) => [react5.Context<TContextValue | null>, () => UseCustomContextResult<TContextValue, TStrict>] & {
|
28
24
|
"~inferredUnion": react5.Context<TContextValue | null> | (() => UseCustomContextResult<TContextValue, TStrict>);
|
29
25
|
};
|
30
|
-
|
31
26
|
//#endregion
|
32
27
|
//#region src/hooks/effects/useAfterMountEffect.d.ts
|
33
28
|
declare const useAfterMountEffect: typeof useEffect;
|
34
|
-
|
35
29
|
//#endregion
|
36
30
|
//#region src/hooks/effects/useAsyncEffect.d.ts
|
37
31
|
declare function useAsyncEffect(effect: () => Promise<ReturnType<React.EffectCallback>>, deps?: React.DependencyList): void;
|
38
|
-
|
39
32
|
//#endregion
|
40
33
|
//#region src/hooks/effects/useEffectOnce.d.ts
|
41
34
|
declare const useEffectOnce: (callBackFn: React.EffectCallback) => void;
|
42
|
-
|
43
35
|
//#endregion
|
44
36
|
//#region src/hooks/effects/useLifeCycle.d.ts
|
45
37
|
type Destructor = ReturnType<React.EffectCallback>;
|
@@ -51,15 +43,12 @@ declare const useLifeCycle: ({
|
|
51
43
|
onMount,
|
52
44
|
onUnmount
|
53
45
|
}: LifeCycleOptions) => void;
|
54
|
-
|
55
46
|
//#endregion
|
56
47
|
//#region src/hooks/effects/useMountEffect.d.ts
|
57
48
|
declare const useMountEffect: (callBackFn: () => void) => void;
|
58
|
-
|
59
49
|
//#endregion
|
60
50
|
//#region src/hooks/effects/useUnMountEffect.d.ts
|
61
51
|
declare const useUnmountEffect: (cleanUpFn: Destructor) => void;
|
62
|
-
|
63
52
|
//#endregion
|
64
53
|
//#region src/hooks/useAnimateElementRefs.d.ts
|
65
54
|
type ElementsInfoArray<TTargetElement extends string> = NonEmptyArray<{
|
@@ -75,7 +64,6 @@ declare const useAnimateElementRefs: <TTargetElement extends string>(elementsInf
|
|
75
64
|
animatedElements: Record<TTargetElement, HTMLElement | null>;
|
76
65
|
handleElementsAnimation: () => void;
|
77
66
|
};
|
78
|
-
|
79
67
|
//#endregion
|
80
68
|
//#region src/hooks/useAnimationInterval.d.ts
|
81
69
|
type AnimationOptions = Prettify<AnimationIntervalOptions & {
|
@@ -86,7 +74,6 @@ declare const useAnimationInterval: (options: AnimationOptions) => {
|
|
86
74
|
start: () => void;
|
87
75
|
stop: () => void;
|
88
76
|
};
|
89
|
-
|
90
77
|
//#endregion
|
91
78
|
//#region src/hooks/useCallbackRef.d.ts
|
92
79
|
/**
|
@@ -95,25 +82,21 @@ declare const useAnimationInterval: (options: AnimationOptions) => {
|
|
95
82
|
* @returns a stable function that always points to the latest version of the callback function
|
96
83
|
*/
|
97
84
|
declare const useCallbackRef: <TCallback = AnyFunction>(callbackFn: TCallback | undefined) => TCallback;
|
98
|
-
|
99
85
|
//#endregion
|
100
86
|
//#region src/hooks/useClickOutside.d.ts
|
101
87
|
type UseClickOutsideOptions = {
|
102
88
|
enabled?: boolean;
|
103
89
|
};
|
104
90
|
declare const useClickOutside: <TElement extends HTMLElement>(refOrRefArray: Array<React.RefObject<TElement>> | React.RefObject<TElement>, callback: (event: MouseEvent | TouchEvent) => void, options?: UseClickOutsideOptions) => void;
|
105
|
-
|
106
91
|
//#endregion
|
107
92
|
//#region src/hooks/useConstant.d.ts
|
108
93
|
declare const useConstant: <TResult>(initCallbackFn: () => TResult) => TResult;
|
109
|
-
|
110
94
|
//#endregion
|
111
95
|
//#region src/hooks/useCopyToClipboard.d.ts
|
112
96
|
declare const useCopyToClipboard: () => {
|
113
97
|
copiedValue: string;
|
114
98
|
handleCopy: (value: string) => void;
|
115
99
|
};
|
116
|
-
|
117
100
|
//#endregion
|
118
101
|
//#region src/hooks/useDebounce.d.ts
|
119
102
|
declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay: number | undefined) => {
|
@@ -125,14 +108,13 @@ declare const useDebouncedFn: <TParams>(callBackFn: CallbackFn<TParams>, delay:
|
|
125
108
|
cancelMaxWait(): void;
|
126
109
|
};
|
127
110
|
declare const useDebouncedState: <TValue>(defaultValue: TValue, delay: number | undefined) => readonly [TValue, {
|
128
|
-
(...params:
|
129
|
-
(params:
|
111
|
+
(...params: react5.SetStateAction<TValue>[]): void;
|
112
|
+
(params: react5.SetStateAction<TValue> | react5.SetStateAction<TValue>[], overrideOptions: {
|
130
113
|
$delay: number;
|
131
114
|
}): void;
|
132
115
|
cancel: () => void;
|
133
116
|
cancelMaxWait(): void;
|
134
|
-
},
|
135
|
-
|
117
|
+
}, react5.Dispatch<react5.SetStateAction<TValue>>];
|
136
118
|
//#endregion
|
137
119
|
//#region src/hooks/useDisclosure.d.ts
|
138
120
|
type DisclosureOptions = {
|
@@ -145,7 +127,6 @@ declare const useDisclosure: (options?: DisclosureOptions) => {
|
|
145
127
|
onOpen: () => void;
|
146
128
|
onToggle: <TValue>(value?: TValue) => void;
|
147
129
|
};
|
148
|
-
|
149
130
|
//#endregion
|
150
131
|
//#region src/hooks/useIsServer.d.ts
|
151
132
|
/**
|
@@ -154,7 +135,6 @@ declare const useDisclosure: (options?: DisclosureOptions) => {
|
|
154
135
|
* until after hydration.
|
155
136
|
*/
|
156
137
|
declare const useIsServer: () => boolean;
|
157
|
-
|
158
138
|
//#endregion
|
159
139
|
//#region src/hooks/useLocationState.d.ts
|
160
140
|
type UseLocationResult<TSlice> = [state: TSlice, actions: LocationStoreApi];
|
@@ -166,12 +146,10 @@ declare const createUseLocationState: (options?: LocationStoreOptions) => Omit<_
|
|
166
146
|
triggerPopstateEvent: (nextLocationState?: LocationInfo["state"]) => void;
|
167
147
|
} & (<TSlice = _zayne_labs_toolkit_core7.URLInfoObject>(selector?: SelectorFn<LocationInfo, TSlice>) => UseLocationResult<TSlice>);
|
168
148
|
declare const useLocationState: <TSlice = LocationInfo>(selector?: SelectorFn<LocationInfo, TSlice>, options?: LocationStoreOptions) => UseLocationResult<TSlice>;
|
169
|
-
|
170
149
|
//#endregion
|
171
150
|
//#region src/hooks/useToggle.d.ts
|
172
151
|
type InitialState = boolean | (() => boolean);
|
173
152
|
declare const useToggle: (initialValue?: InitialState) => readonly [boolean, <TValue>(newValue?: TValue) => void];
|
174
|
-
|
175
153
|
//#endregion
|
176
154
|
//#region src/hooks/usePresence/types.d.ts
|
177
155
|
type UsePresenceOptions<TDuration extends number | undefined> = {
|
@@ -200,7 +178,6 @@ type TypeOption = {
|
|
200
178
|
type?: "animation" | "transition";
|
201
179
|
};
|
202
180
|
type UsePresence = <TElement extends HTMLElement, TDuration extends number | undefined = undefined>(options?: Prettify<TypeOption & UsePresenceOptions<TDuration>>) => UsePresenceResult<TElement, TDuration>;
|
203
|
-
|
204
181
|
//#endregion
|
205
182
|
//#region src/hooks/usePresence/usePresence.d.ts
|
206
183
|
/**
|
@@ -210,23 +187,20 @@ type UsePresence = <TElement extends HTMLElement, TDuration extends number | und
|
|
210
187
|
* @returns A object containing the boolean that should be used to conditionally render the element (isPresent), another boolean used to toggle the animation classes, and a function to toggle the state.
|
211
188
|
*/
|
212
189
|
declare const usePresence: UsePresence;
|
213
|
-
|
214
190
|
//#endregion
|
215
191
|
//#region src/hooks/useScrollObserver.d.ts
|
216
192
|
declare const useScrollObserver: <TElement extends HTMLElement>(options?: ScrollObserverOptions) => {
|
217
193
|
isScrolled: boolean;
|
218
194
|
observedElementRef: RefCallback<TElement>;
|
219
195
|
};
|
220
|
-
|
221
196
|
//#endregion
|
222
197
|
//#region src/hooks/useSearch.d.ts
|
223
198
|
declare const useSearch: <TData>(initialData: TData[], delay?: number) => {
|
224
199
|
data: TData[];
|
225
200
|
isLoading: boolean;
|
226
201
|
query: string;
|
227
|
-
setQuery:
|
202
|
+
setQuery: react5.Dispatch<react5.SetStateAction<string>>;
|
228
203
|
};
|
229
|
-
|
230
204
|
//#endregion
|
231
205
|
//#region src/hooks/useSearchParams.d.ts
|
232
206
|
type UseSearchParamsOptions = LocationStoreOptions & {
|
@@ -234,13 +208,12 @@ type UseSearchParamsOptions = LocationStoreOptions & {
|
|
234
208
|
};
|
235
209
|
declare const useSearchParams: <TSearchParams extends URLSearchParamsInit>(options?: UseSearchParamsOptions) => readonly [URLSearchParams, {
|
236
210
|
(newQueryParams: TSearchParams | ((prev: URLSearchParams) => TSearchParams)): void;
|
237
|
-
triggerPopstateEvent: (nextLocationState?:
|
211
|
+
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core7.LocationInfo["state"]) => void;
|
238
212
|
}];
|
239
213
|
declare const useSearchParamsObject: <TSearchParams extends Record<string, string>>(options?: UseSearchParamsOptions) => readonly [TSearchParams, {
|
240
214
|
(newQueryParams: TSearchParams | ((prev: TSearchParams) => TSearchParams)): void;
|
241
|
-
triggerPopstateEvent: (nextLocationState?:
|
215
|
+
triggerPopstateEvent: (nextLocationState?: _zayne_labs_toolkit_core7.LocationInfo["state"]) => void;
|
242
216
|
}];
|
243
|
-
|
244
217
|
//#endregion
|
245
218
|
//#region src/hooks/useStorageState.d.ts
|
246
219
|
type UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: StorageStoreApi<TState>];
|
@@ -248,18 +221,16 @@ type UseStorageResult<TState, TSlice = TState> = [state: TSlice, actions: Storag
|
|
248
221
|
* @description Creates a custom hook that returns a storage state and actions to modify it. You can use this if you need shared options.
|
249
222
|
* @note You must use this if you want to be able to prevent syncing state across tabs.
|
250
223
|
*/
|
251
|
-
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) =>
|
224
|
+
declare const createUseStorageState: <TState>(baseOptions: StorageOptions<TState>) => _zayne_labs_toolkit_core7.StoreApi<TState> & {
|
252
225
|
removeState: () => void;
|
253
226
|
} & (<TSlice = TState>(selector?: SelectorFn<TState, TSlice>) => UseStorageResult<TState, TSlice>);
|
254
227
|
type UseStorageStateOptions<TValue> = Omit<StorageOptions<TValue>, "initialValue" | "key">;
|
255
228
|
declare const useStorageState: <TValue, TSlice = TValue>(key: string, initialValue?: TValue, options?: UseStorageStateOptions<TValue> & {
|
256
229
|
select?: SelectorFn<TValue, TSlice>;
|
257
230
|
}) => UseStorageResult<TValue, TSlice>;
|
258
|
-
|
259
231
|
//#endregion
|
260
232
|
//#region src/hooks/useStore.d.ts
|
261
233
|
declare const useStore: <TState, TSlice>(store: StoreApi<TState>, selector?: SelectorFn<TState, TSlice>) => TSlice;
|
262
|
-
|
263
234
|
//#endregion
|
264
235
|
//#region src/hooks/useThrottle.d.ts
|
265
236
|
declare const useThrottleBySetTimeout: <TParams>(callbackFn: CallbackFn<TParams>, delay: number) => {
|
@@ -271,7 +242,6 @@ declare const useThrottleByFrame: <TParams>(callbackFn: CallbackFn<TParams>) =>
|
|
271
242
|
(...params: TParams[]): void;
|
272
243
|
cancelAnimation(): void;
|
273
244
|
};
|
274
|
-
|
275
245
|
//#endregion
|
276
|
-
export { ContextError
|
277
|
-
//# sourceMappingURL=index-
|
246
|
+
export { ContextError, CustomContextOptions, createCustomContext, createUseLocationState, createUseStorageState, getErrorMessage, useAfterMountEffect, useAnimateElementRefs, useAnimationInterval, useAsyncEffect, useCallbackRef, useClickOutside, useConstant, useCopyToClipboard, useDebouncedFn, useDebouncedState, useDisclosure, useEffectOnce, useIsServer, useLifeCycle, useLocationState, useMountEffect, usePresence, useScrollObserver, useSearch, useSearchParams, useSearchParamsObject, useStorageState, useStore, useThrottleByFrame, useThrottleBySetTimeout, useThrottleByTimer, useToggle, useUnmountEffect };
|
247
|
+
//# sourceMappingURL=index-44MAU7Zb.d.ts.map
|
@@ -14,12 +14,10 @@ declare const setRef: <TRef extends HTMLElement>(ref: PossibleRef<TRef>, node: T
|
|
14
14
|
*/
|
15
15
|
declare const composeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => RefCallback<TRef>;
|
16
16
|
declare const useComposeRefs: <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => () => RefCallback<TRef>;
|
17
|
-
|
18
17
|
//#endregion
|
19
18
|
//#region src/utils/composeEventHandlers.d.ts
|
20
19
|
declare const composeTwoEventHandlers: (formerHandler: AnyFunction | undefined, latterHandler: AnyFunction | undefined) => (event: unknown) => unknown;
|
21
20
|
declare const composeEventHandlers: (...eventHandlerArray: Array<AnyFunction | undefined>) => (event: unknown) => unknown;
|
22
|
-
|
23
21
|
//#endregion
|
24
22
|
//#region src/utils/mergeProps.d.ts
|
25
23
|
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : "") extends ((param: infer TParam) => void) ? TParam : "";
|
@@ -38,11 +36,9 @@ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) =>
|
|
38
36
|
* @returns the merged props.
|
39
37
|
*/
|
40
38
|
declare const mergeProps: <TProps extends Record<never, never>>(...propsObjectArray: Array<TProps | undefined>) => UnionToIntersection<TProps>;
|
41
|
-
|
42
39
|
//#endregion
|
43
40
|
//#region src/utils/mergeTwoProps.d.ts
|
44
41
|
declare const mergeTwoProps: <TProps extends Record<never, never>>(formerProps: TProps | undefined, latterProps: TProps | undefined) => TProps;
|
45
|
-
|
46
42
|
//#endregion
|
47
43
|
//#region src/utils/types/common.d.ts
|
48
44
|
type ForwardedRefType<TComponent extends HTMLElement | React.ElementType> = TComponent extends React.ElementType ? React.ForwardedRef<React.Ref<TComponent>> : React.ForwardedRef<TComponent>;
|
@@ -64,7 +60,6 @@ type DiscriminatedRenderProps<TRenderPropType, TErrorMessages extends Record<"ch
|
|
64
60
|
}, {
|
65
61
|
render: TRenderPropType;
|
66
62
|
}], TErrorMessages>;
|
67
|
-
|
68
63
|
//#endregion
|
69
64
|
//#region src/utils/types/polymorphism.d.ts
|
70
65
|
type AsProp<TElement extends React.ElementType> = {
|
@@ -73,7 +68,6 @@ type AsProp<TElement extends React.ElementType> = {
|
|
73
68
|
type InferRemainingProps<TElement extends React.ElementType, TProps> = Omit<InferProps<TElement>, keyof TProps>;
|
74
69
|
type MergedGivenPropsWithAs<TElement extends React.ElementType, TProps> = Prettify<Omit<AsProp<TElement>, keyof TProps> & TProps>;
|
75
70
|
type PolymorphicProps<TElement extends React.ElementType, TProps extends AnyObject = NonNullable<unknown>> = MergedGivenPropsWithAs<TElement, TProps> & InferRemainingProps<TElement, TProps>;
|
76
|
-
|
77
71
|
//#endregion
|
78
72
|
export { AsProp, CssWithCustomProperties, DiscriminatedRenderProps, ForwardedRefType, InferProps, PolymorphicProps, StateSetter, composeEventHandlers, composeRefs, composeTwoEventHandlers, mergeProps, mergeTwoProps, setRef, useComposeRefs };
|
79
73
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["ref: PossibleRef<TRef>","node: TRef | null","mergedRefCallBack: RefCallback<TRef>","event: unknown","formerHandler: AnyFunction | undefined","latterHandler: AnyFunction | undefined","result","accumulatedHandlers: AnyFunction | undefined","key: string","value: unknown","formerClassName: string | undefined","latterClassName: string | undefined","formerProps: TProps | undefined","latterProps: TProps | undefined","accumulatedProps: Record<string, unknown>"],"sources":["../../../src/utils/composeRefs.ts","../../../src/utils/composeEventHandlers.ts","../../../src/utils/mergeTwoProps.ts","../../../src/utils/mergeProps.ts"],"sourcesContent":["import { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type RefCallback, useCallback } from \"react\";\n\ntype PossibleRef<TRef extends HTMLElement> = React.Ref<TRef> | undefined;\n\n/**\n * @description Set a given ref to a given value.\n *\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nexport const setRef = <TRef extends HTMLElement>(\n\tref: PossibleRef<TRef>,\n\tnode: TRef | null\n): ReturnType<RefCallback<TRef>> => {\n\tif (!ref) return;\n\n\tif (isFunction(ref)) {\n\t\treturn ref(node);\n\t}\n\n\t// eslint-disable-next-line no-param-reassign -- Mutation is needed here\n\tref.current = node;\n};\n\n/**\n * @description A utility to combine refs. Accepts callback refs and RefObject(s)\n */\nexport const composeRefs = <TRef extends HTMLElement>(\n\t...refs: Array<PossibleRef<TRef>>\n): RefCallback<TRef> => {\n\tconst mergedRefCallBack: RefCallback<TRef> = (node) => {\n\t\tconst cleanupFnArray = refs.map((ref) => setRef(ref, node));\n\n\t\tconst cleanupFn = () => cleanupFnArray.forEach((cleanup) => cleanup?.());\n\n\t\treturn cleanupFn;\n\t};\n\n\treturn mergedRefCallBack;\n};\n\nexport const useComposeRefs = <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => {\n\t// eslint-disable-next-line react-hooks/exhaustive-deps -- Allow\n\tconst mergedRef = useCallback(() => composeRefs(...refs), refs);\n\n\treturn mergedRef;\n};\n","import { type AnyFunction, isObject } from \"@zayne-labs/toolkit-type-helpers\";\n\nconst isSyntheticEvent = (event: unknown): event is React.SyntheticEvent => {\n\treturn isObject(event) && Object.hasOwn(event, \"nativeEvent\");\n};\n\nexport const composeTwoEventHandlers = (\n\tformerHandler: AnyFunction | undefined,\n\tlatterHandler: AnyFunction | undefined\n) => {\n\tconst mergedEventHandler = (event: unknown) => {\n\t\tif (isSyntheticEvent(event)) {\n\t\t\tconst result = latterHandler?.(event) as unknown;\n\n\t\t\tif (!event.defaultPrevented) {\n\t\t\t\tformerHandler?.(event);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t}\n\n\t\tconst result = latterHandler?.(event) as unknown;\n\t\tformerHandler?.(event);\n\t\treturn result;\n\t};\n\n\treturn mergedEventHandler;\n};\n\nexport const composeEventHandlers = (...eventHandlerArray: Array<AnyFunction | undefined>) => {\n\tconst mergedEventHandler = (event: unknown) => {\n\t\tif (eventHandlerArray.length === 0) return;\n\n\t\tif (eventHandlerArray.length === 1) {\n\t\t\treturn eventHandlerArray[0]?.(event) as unknown;\n\t\t}\n\n\t\tlet accumulatedHandlers: AnyFunction | undefined;\n\n\t\tfor (const eventHandler of eventHandlerArray) {\n\t\t\tif (!eventHandler) continue;\n\n\t\t\taccumulatedHandlers = composeTwoEventHandlers(accumulatedHandlers, eventHandler);\n\t\t}\n\n\t\treturn accumulatedHandlers?.(event) as unknown;\n\t};\n\n\treturn mergedEventHandler;\n};\n","import { type AnyFunction, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { composeTwoEventHandlers } from \"./composeEventHandlers\";\n\n// == This approach is more efficient than using a regex.\nconst isEventHandler = (key: string, value: unknown): value is AnyFunction => {\n\tconst thirdCharCode = key.codePointAt(2);\n\n\tif (!isFunction(value) || thirdCharCode === undefined) {\n\t\treturn false;\n\t}\n\n\tconst isHandler = key.startsWith(\"on\") && thirdCharCode >= 65 /* A */ && thirdCharCode <= 90; /* Z */\n\n\treturn isHandler;\n};\n\nconst mergeTwoClassNames = (formerClassName: string | undefined, latterClassName: string | undefined) => {\n\tif (!latterClassName || !formerClassName) {\n\t\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- Logical OR is fit for this case\n\t\treturn latterClassName || formerClassName;\n\t}\n\n\t// eslint-disable-next-line prefer-template -- String concatenation is more performant than template literals in this case\n\treturn formerClassName + \" \" + latterClassName;\n};\n\nexport const mergeTwoProps = <TProps extends Record<never, never>>(\n\tformerProps: TProps | undefined,\n\tlatterProps: TProps | undefined\n): TProps => {\n\t// == If no props are provided, return an empty object\n\tif (!latterProps || !formerProps) {\n\t\treturn latterProps ?? formerProps ?? ({} as TProps);\n\t}\n\n\tconst propsAccumulator = { ...formerProps } as Record<string, unknown>;\n\n\tfor (const latterPropName of Object.keys(latterProps)) {\n\t\tconst formerPropValue = (formerProps as Record<string, unknown>)[latterPropName];\n\t\tconst latterPropValue = (latterProps as Record<string, unknown>)[latterPropName];\n\n\t\t// == If the prop is `className` or `class`, we merge them\n\t\tif (latterPropName === \"className\" || latterPropName === \"class\") {\n\t\t\tpropsAccumulator[latterPropName] = mergeTwoClassNames(\n\t\t\t\tformerPropValue as string,\n\t\t\t\tlatterPropValue as string\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == If the prop is `style`, we merge them\n\t\tif (latterPropName === \"style\") {\n\t\t\tpropsAccumulator[latterPropName] = {\n\t\t\t\t...(formerPropValue as object),\n\t\t\t\t...(latterPropValue as object),\n\t\t\t};\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == If the handler exists on both, we compose them\n\t\tif (isEventHandler(latterPropName, latterPropValue)) {\n\t\t\tpropsAccumulator[latterPropName] = composeTwoEventHandlers(\n\t\t\t\tformerPropValue as AnyFunction | undefined,\n\t\t\t\tlatterPropValue\n\t\t\t);\n\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == latterProps override by default\n\t\tpropsAccumulator[latterPropName] = latterPropValue;\n\t}\n\n\treturn propsAccumulator as TProps;\n};\n","import { mergeTwoProps } from \"./mergeTwoProps\";\n\ntype UnionToIntersection<TUnion>
|
1
|
+
{"version":3,"file":"index.js","names":["ref: PossibleRef<TRef>","node: TRef | null","mergedRefCallBack: RefCallback<TRef>","event: unknown","formerHandler: AnyFunction | undefined","latterHandler: AnyFunction | undefined","result","accumulatedHandlers: AnyFunction | undefined","key: string","value: unknown","formerClassName: string | undefined","latterClassName: string | undefined","formerProps: TProps | undefined","latterProps: TProps | undefined","accumulatedProps: Record<string, unknown>"],"sources":["../../../src/utils/composeRefs.ts","../../../src/utils/composeEventHandlers.ts","../../../src/utils/mergeTwoProps.ts","../../../src/utils/mergeProps.ts"],"sourcesContent":["import { isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type RefCallback, useCallback } from \"react\";\n\ntype PossibleRef<TRef extends HTMLElement> = React.Ref<TRef> | undefined;\n\n/**\n * @description Set a given ref to a given value.\n *\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */\nexport const setRef = <TRef extends HTMLElement>(\n\tref: PossibleRef<TRef>,\n\tnode: TRef | null\n): ReturnType<RefCallback<TRef>> => {\n\tif (!ref) return;\n\n\tif (isFunction(ref)) {\n\t\treturn ref(node);\n\t}\n\n\t// eslint-disable-next-line no-param-reassign -- Mutation is needed here\n\tref.current = node;\n};\n\n/**\n * @description A utility to combine refs. Accepts callback refs and RefObject(s)\n */\nexport const composeRefs = <TRef extends HTMLElement>(\n\t...refs: Array<PossibleRef<TRef>>\n): RefCallback<TRef> => {\n\tconst mergedRefCallBack: RefCallback<TRef> = (node) => {\n\t\tconst cleanupFnArray = refs.map((ref) => setRef(ref, node));\n\n\t\tconst cleanupFn = () => cleanupFnArray.forEach((cleanup) => cleanup?.());\n\n\t\treturn cleanupFn;\n\t};\n\n\treturn mergedRefCallBack;\n};\n\nexport const useComposeRefs = <TRef extends HTMLElement>(...refs: Array<PossibleRef<TRef>>) => {\n\t// eslint-disable-next-line react-hooks/exhaustive-deps -- Allow\n\tconst mergedRef = useCallback(() => composeRefs(...refs), refs);\n\n\treturn mergedRef;\n};\n","import { type AnyFunction, isObject } from \"@zayne-labs/toolkit-type-helpers\";\n\nconst isSyntheticEvent = (event: unknown): event is React.SyntheticEvent => {\n\treturn isObject(event) && Object.hasOwn(event, \"nativeEvent\");\n};\n\nexport const composeTwoEventHandlers = (\n\tformerHandler: AnyFunction | undefined,\n\tlatterHandler: AnyFunction | undefined\n) => {\n\tconst mergedEventHandler = (event: unknown) => {\n\t\tif (isSyntheticEvent(event)) {\n\t\t\tconst result = latterHandler?.(event) as unknown;\n\n\t\t\tif (!event.defaultPrevented) {\n\t\t\t\tformerHandler?.(event);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t}\n\n\t\tconst result = latterHandler?.(event) as unknown;\n\t\tformerHandler?.(event);\n\t\treturn result;\n\t};\n\n\treturn mergedEventHandler;\n};\n\nexport const composeEventHandlers = (...eventHandlerArray: Array<AnyFunction | undefined>) => {\n\tconst mergedEventHandler = (event: unknown) => {\n\t\tif (eventHandlerArray.length === 0) return;\n\n\t\tif (eventHandlerArray.length === 1) {\n\t\t\treturn eventHandlerArray[0]?.(event) as unknown;\n\t\t}\n\n\t\tlet accumulatedHandlers: AnyFunction | undefined;\n\n\t\tfor (const eventHandler of eventHandlerArray) {\n\t\t\tif (!eventHandler) continue;\n\n\t\t\taccumulatedHandlers = composeTwoEventHandlers(accumulatedHandlers, eventHandler);\n\t\t}\n\n\t\treturn accumulatedHandlers?.(event) as unknown;\n\t};\n\n\treturn mergedEventHandler;\n};\n","import { type AnyFunction, isFunction } from \"@zayne-labs/toolkit-type-helpers\";\nimport { composeTwoEventHandlers } from \"./composeEventHandlers\";\n\n// == This approach is more efficient than using a regex.\nconst isEventHandler = (key: string, value: unknown): value is AnyFunction => {\n\tconst thirdCharCode = key.codePointAt(2);\n\n\tif (!isFunction(value) || thirdCharCode === undefined) {\n\t\treturn false;\n\t}\n\n\tconst isHandler = key.startsWith(\"on\") && thirdCharCode >= 65 /* A */ && thirdCharCode <= 90; /* Z */\n\n\treturn isHandler;\n};\n\nconst mergeTwoClassNames = (formerClassName: string | undefined, latterClassName: string | undefined) => {\n\tif (!latterClassName || !formerClassName) {\n\t\t// eslint-disable-next-line ts-eslint/prefer-nullish-coalescing -- Logical OR is fit for this case\n\t\treturn latterClassName || formerClassName;\n\t}\n\n\t// eslint-disable-next-line prefer-template -- String concatenation is more performant than template literals in this case\n\treturn formerClassName + \" \" + latterClassName;\n};\n\nexport const mergeTwoProps = <TProps extends Record<never, never>>(\n\tformerProps: TProps | undefined,\n\tlatterProps: TProps | undefined\n): TProps => {\n\t// == If no props are provided, return an empty object\n\tif (!latterProps || !formerProps) {\n\t\treturn latterProps ?? formerProps ?? ({} as TProps);\n\t}\n\n\tconst propsAccumulator = { ...formerProps } as Record<string, unknown>;\n\n\tfor (const latterPropName of Object.keys(latterProps)) {\n\t\tconst formerPropValue = (formerProps as Record<string, unknown>)[latterPropName];\n\t\tconst latterPropValue = (latterProps as Record<string, unknown>)[latterPropName];\n\n\t\t// == If the prop is `className` or `class`, we merge them\n\t\tif (latterPropName === \"className\" || latterPropName === \"class\") {\n\t\t\tpropsAccumulator[latterPropName] = mergeTwoClassNames(\n\t\t\t\tformerPropValue as string,\n\t\t\t\tlatterPropValue as string\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == If the prop is `style`, we merge them\n\t\tif (latterPropName === \"style\") {\n\t\t\tpropsAccumulator[latterPropName] = {\n\t\t\t\t...(formerPropValue as object),\n\t\t\t\t...(latterPropValue as object),\n\t\t\t};\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == If the handler exists on both, we compose them\n\t\tif (isEventHandler(latterPropName, latterPropValue)) {\n\t\t\tpropsAccumulator[latterPropName] = composeTwoEventHandlers(\n\t\t\t\tformerPropValue as AnyFunction | undefined,\n\t\t\t\tlatterPropValue\n\t\t\t);\n\n\t\t\tcontinue;\n\t\t}\n\n\t\t// == latterProps override by default\n\t\tpropsAccumulator[latterPropName] = latterPropValue;\n\t}\n\n\treturn propsAccumulator as TProps;\n};\n","import { mergeTwoProps } from \"./mergeTwoProps\";\n\ntype UnionToIntersection<TUnion> =\n\t(TUnion extends unknown ? (param: TUnion) => void : \"\") extends (param: infer TParam) => void ? TParam\n\t:\t\"\";\n\n/**\n * Merges multiple sets of React props.\n *\n * - It follows the Object.assign pattern where the rightmost object's fields overwrite\n * the conflicting ones from others. This doesn't apply to event handlers, `className` and `style` props.\n * - Event handlers are merged such that they are called in sequence (the rightmost one being called first),\n * and allows the user to prevent the previous event handlers from being executed by calling the `preventDefault` method.\n * - It also merges the `className` and `style` props, whereby the classes are concatenated\n * and the rightmost styles overwrite the previous ones.\n *\n * @important **`ref` is not merged.**\n * @param props props to merge.\n * @returns the merged props.\n */\n\nconst mergeProps = <TProps extends Record<never, never>>(\n\t...propsObjectArray: Array<TProps | undefined>\n): UnionToIntersection<TProps> => {\n\tif (propsObjectArray.length === 0) {\n\t\treturn {} as never;\n\t}\n\n\tif (propsObjectArray.length === 1) {\n\t\treturn propsObjectArray[0] as never;\n\t}\n\n\tlet accumulatedProps: Record<string, unknown> = {};\n\n\tfor (const propsObject of propsObjectArray) {\n\t\tif (!propsObject) continue;\n\n\t\taccumulatedProps = mergeTwoProps(accumulatedProps, propsObject);\n\t}\n\n\treturn accumulatedProps as never;\n};\n\nexport { mergeProps };\n"],"mappings":";;;;;;;;;AAUA,MAAa,SAAS,CACrBA,KACAC,SACmC;AACnC,MAAK,IAAK;AAEV,KAAI,WAAW,IAAI,CAClB,QAAO,IAAI,KAAK;AAIjB,KAAI,UAAU;AACd;;;;AAKD,MAAa,cAAc,CAC1B,GAAG,SACoB;CACvB,MAAMC,oBAAuC,CAAC,SAAS;EACtD,MAAM,iBAAiB,KAAK,IAAI,CAAC,QAAQ,OAAO,KAAK,KAAK,CAAC;EAE3D,MAAM,YAAY,MAAM,eAAe,QAAQ,CAAC,YAAY,WAAW,CAAC;AAExE,SAAO;CACP;AAED,QAAO;AACP;AAED,MAAa,iBAAiB,CAA2B,GAAG,SAAmC;CAE9F,MAAM,YAAY,YAAY,MAAM,YAAY,GAAG,KAAK,EAAE,KAAK;AAE/D,QAAO;AACP;;;;AC5CD,MAAM,mBAAmB,CAACC,UAAkD;AAC3E,QAAO,SAAS,MAAM,IAAI,OAAO,OAAO,OAAO,cAAc;AAC7D;AAED,MAAa,0BAA0B,CACtCC,eACAC,kBACI;CACJ,MAAM,qBAAqB,CAACF,UAAmB;AAC9C,MAAI,iBAAiB,MAAM,EAAE;GAC5B,MAAMG,WAAS,gBAAgB,MAAM;AAErC,QAAK,MAAM,iBACV,iBAAgB,MAAM;AAGvB,UAAOA;EACP;EAED,MAAM,SAAS,gBAAgB,MAAM;AACrC,kBAAgB,MAAM;AACtB,SAAO;CACP;AAED,QAAO;AACP;AAED,MAAa,uBAAuB,CAAC,GAAG,sBAAsD;CAC7F,MAAM,qBAAqB,CAACH,UAAmB;AAC9C,MAAI,kBAAkB,WAAW,EAAG;AAEpC,MAAI,kBAAkB,WAAW,EAChC,QAAO,kBAAkB,KAAK,MAAM;EAGrC,IAAII;AAEJ,OAAK,MAAM,gBAAgB,mBAAmB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,YAAa;AAElB,qBAAmB,cAAc,kBAAkB,YAAY;CAC/D;AAED,QAAO;AACP"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { CustomContextOptions } from "../index-
|
1
|
+
import { CustomContextOptions } from "../index-44MAU7Zb.js";
|
2
2
|
import { AnyObject, Prettify, SelectorFn } from "@zayne-labs/toolkit-type-helpers";
|
3
3
|
import * as react0 from "react";
|
4
4
|
import { StoreApi } from "@zayne-labs/toolkit-core";
|
5
5
|
import * as zustand2 from "zustand";
|
6
|
-
import { Mutate, StateCreator, StoreApi as StoreApi$1, StoreMutatorIdentifier, UseBoundStore } from "zustand";
|
6
|
+
import { Mutate, StateCreator as StateCreator$1, StoreApi as StoreApi$1, StoreMutatorIdentifier, UseBoundStore } from "zustand";
|
7
7
|
|
8
8
|
//#region src/zustand/createZustandContext.d.ts
|
9
9
|
declare const createZustandContext: <TState extends Record<string, unknown>, TUseBoundStore extends UseBoundStore<StoreApi$1<TState>> = UseBoundStore<StoreApi$1<TState>>, TStore extends StoreApi$1<TState> = StoreApi$1<TState>>(options?: CustomContextOptions<TUseBoundStore, true>) => [ZustandProvider: (props: ({
|
@@ -21,31 +21,28 @@ declare const createZustandContext: <TState extends Record<string, unknown>, TUs
|
|
21
21
|
}) & {
|
22
22
|
children: React.ReactNode;
|
23
23
|
}) => react0.DetailedReactHTMLElement<react0.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, useBoundStore: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => TResult];
|
24
|
-
|
25
24
|
//#endregion
|
26
25
|
//#region src/zustand/createZustandStoreWithCombine.d.ts
|
27
26
|
type Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;
|
28
|
-
declare const combine: <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>) => StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs>;
|
27
|
+
declare const combine: <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, storeCreator: StateCreator$1<TInitialState, Mps, Mcs, TExtraState>) => StateCreator$1<Write<TInitialState, TExtraState>, Mps, Mcs>;
|
29
28
|
declare const createStoreWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand2.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key] } : never>;
|
30
29
|
declare const createWithCombine: <TInitialState extends AnyObject, TExtraState extends AnyObject>(...params: Parameters<typeof combine<TInitialState, TExtraState>>) => zustand2.UseBoundStore<zustand2.StoreApi<Omit<TInitialState, keyof TExtraState> & TExtraState extends infer T ? { [Key in keyof T]: (Omit<TInitialState, keyof TExtraState> & TExtraState)[Key] } : never>>;
|
31
|
-
|
32
30
|
//#endregion
|
33
31
|
//#region src/zustand/createZustandStoreWithSubscribe.d.ts
|
34
32
|
type Get<T, K, F> = K extends keyof T ? T[K] : F;
|
35
|
-
type StateCreator
|
33
|
+
type StateCreator<T, Mis extends Array<[StoreMutatorIdentifier, unknown]> = [], Mos extends Array<[StoreMutatorIdentifier, unknown]> = [], U = T> = {
|
36
34
|
$$storeMutators?: Mos;
|
37
35
|
} & ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U);
|
38
36
|
type CreateStoreWithSubscribe = {
|
39
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
40
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
37
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
|
38
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
|
41
39
|
};
|
42
40
|
declare const createStoreWithSubscribe: CreateStoreWithSubscribe;
|
43
41
|
type CreateWithSubscribe = {
|
44
|
-
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
45
|
-
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator
|
42
|
+
<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
43
|
+
<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
|
46
44
|
};
|
47
45
|
declare const createWithSubscribe: CreateWithSubscribe;
|
48
|
-
|
49
46
|
//#endregion
|
50
|
-
export { combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
47
|
+
export { StateCreator, combine, createStoreWithCombine, createStoreWithSubscribe, createWithCombine, createWithSubscribe, createZustandContext };
|
51
48
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["options?: CustomContextOptions<TUseBoundStore, true>","props: ZustandProviderProps","useBoundStore","selector: SelectorFn<TState, unknown>","selector?: SelectorFn<TState, TResult>","initialState: TInitialState","storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>","stateInitializer: StateCreator<TState> | undefined","createState: StateCreator<TState>","selector?: SelectorFn<TState, unknown>"],"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts","../../../src/zustand/createZustandStoreWithSubscribe.ts"],"sourcesContent":["import type { SelectorFn, UnionDiscriminator } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps = UnionDiscriminator<\n\t\t[{ store: TStore }, { storeCreator: () => TUseBoundStore }, { value: TUseBoundStore }]\n\t> & { children: React.ReactNode };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, store, storeCreator, value } = props;\n\n\t\tconst useZustandStore = useConstant(() => {\n\t\t\tswitch (true) {\n\t\t\t\tcase Boolean(storeCreator): {\n\t\t\t\t\treturn storeCreator();\n\t\t\t\t}\n\t\t\t\tcase Boolean(value): {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t\tcase Boolean(store): {\n\t\t\t\t\tconst useBoundStore = (selector: SelectorFn<TState, unknown>) => useStore(store, selector);\n\t\t\t\t\tObject.assign(useBoundStore, store);\n\t\t\t\t\treturn useBoundStore as TUseBoundStore;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"No store provided\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst useZustandStore = useCustomContext();\n\n\t\treturn useZustandStore(selector as never);\n\t};\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\ntype Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;\n\nexport const combine =\n\t<\n\t\tTInitialState extends AnyObject,\n\t\tTExtraState extends AnyObject,\n\t\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t>(\n\t\tinitialState: TInitialState,\n\t\tstoreCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n\t): StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs> =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n","import { useStore } from \"@/hooks\";\nimport { type StoreApi, createStore } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier, UseBoundStore } from \"zustand\";\n\ntype Get<T, K, F> = K extends keyof T ? T[K] : F;\n\
|
1
|
+
{"version":3,"file":"index.js","names":["options?: CustomContextOptions<TUseBoundStore, true>","props: ZustandProviderProps","useBoundStore","selector: SelectorFn<TState, unknown>","selector?: SelectorFn<TState, TResult>","initialState: TInitialState","storeCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>","stateInitializer: StateCreator<TState> | undefined","createState: StateCreator<TState>","selector?: SelectorFn<TState, unknown>"],"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts","../../../src/zustand/createZustandStoreWithSubscribe.ts"],"sourcesContent":["import type { SelectorFn, UnionDiscriminator } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n\tTStore extends StoreApi<TState> = StoreApi<TState>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps = UnionDiscriminator<\n\t\t[{ store: TStore }, { storeCreator: () => TUseBoundStore }, { value: TUseBoundStore }]\n\t> & { children: React.ReactNode };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, store, storeCreator, value } = props;\n\n\t\tconst useZustandStore = useConstant(() => {\n\t\t\tswitch (true) {\n\t\t\t\tcase Boolean(storeCreator): {\n\t\t\t\t\treturn storeCreator();\n\t\t\t\t}\n\t\t\t\tcase Boolean(value): {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t\tcase Boolean(store): {\n\t\t\t\t\tconst useBoundStore = (selector: SelectorFn<TState, unknown>) => useStore(store, selector);\n\t\t\t\t\tObject.assign(useBoundStore, store);\n\t\t\t\t\treturn useBoundStore as TUseBoundStore;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"No store provided\");\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult = TState>(selector?: SelectorFn<TState, TResult>): TResult => {\n\t\tconst useZustandStore = useCustomContext();\n\n\t\treturn useZustandStore(selector as never);\n\t};\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject, Prettify } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\ntype Write<TInitialState, TExtraState> = Prettify<Omit<TInitialState, keyof TExtraState> & TExtraState>;\n\nexport const combine =\n\t<\n\t\tTInitialState extends AnyObject,\n\t\tTExtraState extends AnyObject,\n\t\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\t>(\n\t\tinitialState: TInitialState,\n\t\tstoreCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n\t): StateCreator<Write<TInitialState, TExtraState>, Mps, Mcs> =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n","import { useStore } from \"@/hooks\";\nimport { type StoreApi, createStore } from \"@zayne-labs/toolkit-core\";\nimport type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport type { Mutate, StoreMutatorIdentifier, UseBoundStore } from \"zustand\";\n\ntype Get<T, K, F> = K extends keyof T ? T[K] : F;\n\nexport type StateCreator<\n\tT,\n\tMis extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMos extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tU = T,\n> = { $$storeMutators?: Mos } & ((\n\tsetState: Get<Mutate<StoreApi<T>, Mis>, \"setState\", never>,\n\tgetState: Get<Mutate<StoreApi<T>, Mis>, \"getState\", never>,\n\tstore: Mutate<StoreApi<T>, Mis>\n) => U);\n\ntype CreateStoreWithSubscribe = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): Mutate<StoreApi<T>, Mos>;\n\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => Mutate<StoreApi<T>, Mos>;\n};\n\nexport const createStoreWithSubscribe = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ? createStore(stateInitializer) : createStore) as CreateStoreWithSubscribe;\n\ntype CreateWithSubscribe = {\n\t<T, Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t): UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n\t<T>(): <Mos extends Array<[StoreMutatorIdentifier, unknown]> = []>(\n\t\tinitializer: StateCreator<T, [], Mos>\n\t) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;\n};\n\nconst createWithSubscribeImpl = <TState>(createState: StateCreator<TState>) => {\n\tconst store = createStore(createState);\n\n\tconst useBoundStore = (selector?: SelectorFn<TState, unknown>) => useStore(store, selector);\n\n\tObject.assign(useBoundStore, store);\n\n\treturn useBoundStore;\n};\n\nexport const createWithSubscribe = (<TState>(stateInitializer: StateCreator<TState> | undefined) =>\n\tstateInitializer ?\n\t\tcreateWithSubscribeImpl(stateInitializer)\n\t:\tcreateWithSubscribeImpl) as CreateWithSubscribe;\n"],"mappings":";;;;;;AAKA,MAAM,uBAAuB,CAK5BA,YACI;CACJ,MAAM,CAAC,UAAU,iBAAiB,GAAG,oBAAoB,QAAQ;CAMjE,SAAS,gBAAgBC,OAA6B;EACrD,MAAM,EAAE,UAAU,OAAO,cAAc,OAAO,GAA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"A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
|
6
6
|
"author": "Ryan Zayne",
|
7
7
|
"license": "MIT",
|
@@ -47,26 +47,26 @@
|
|
47
47
|
}
|
48
48
|
},
|
49
49
|
"dependencies": {
|
50
|
-
"@zayne-labs/toolkit-core": "0.9.
|
51
|
-
"@zayne-labs/toolkit-type-helpers": "0.9.
|
50
|
+
"@zayne-labs/toolkit-core": "0.9.50",
|
51
|
+
"@zayne-labs/toolkit-type-helpers": "0.9.50"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
|
-
"@arethetypeswrong/cli": "^0.18.
|
55
|
-
"@changesets/cli": "^2.29.
|
54
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
55
|
+
"@changesets/cli": "^2.29.5",
|
56
56
|
"@size-limit/esbuild-why": "^11.2.0",
|
57
57
|
"@size-limit/preset-small-lib": "^11.2.0",
|
58
58
|
"@total-typescript/ts-reset": "^0.6.1",
|
59
|
-
"@types/node": "^
|
60
|
-
"@types/react": "^19.1.
|
61
|
-
"@zayne-labs/tsconfig": "0.
|
62
|
-
"concurrently": "^9.
|
59
|
+
"@types/node": "^24.0.4",
|
60
|
+
"@types/react": "^19.1.8",
|
61
|
+
"@zayne-labs/tsconfig": "0.9.3",
|
62
|
+
"concurrently": "^9.2.0",
|
63
63
|
"cross-env": "^7.0.3",
|
64
64
|
"publint": "^0.3.12",
|
65
65
|
"react": "^19.1.0",
|
66
66
|
"size-limit": "^11.2.0",
|
67
|
-
"tsdown": "^0.12.
|
67
|
+
"tsdown": "^0.12.8",
|
68
68
|
"typescript": "5.8.3",
|
69
|
-
"zustand": "^5.0.
|
69
|
+
"zustand": "^5.0.5"
|
70
70
|
},
|
71
71
|
"publishConfig": {
|
72
72
|
"access": "public",
|