@cp949/mui-react19 2.3.1 → 2.3.2
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/components/DebouncedRender.cjs.map +1 -1
- package/dist/components/DebouncedRender.js.map +1 -1
- package/dist/components/ListPagination.cjs.map +1 -1
- package/dist/components/ListPagination.js.map +1 -1
- package/dist/components/SegmentedControl/components.cjs.map +1 -1
- package/dist/components/SegmentedControl/components.js.map +1 -1
- package/dist/eventemitter/eventemitter3.cjs.map +1 -1
- package/dist/eventemitter/eventemitter3.js.map +1 -1
- package/dist/hooks/useCallbackRef.cjs.map +1 -1
- package/dist/hooks/useCallbackRef.js.map +1 -1
- package/dist/hooks/useClosableEffect.cjs.map +1 -1
- package/dist/hooks/useClosableEffect.js.map +1 -1
- package/dist/hooks/useComposedRefs.cjs.map +1 -1
- package/dist/hooks/useComposedRefs.js.map +1 -1
- package/dist/hooks/useCustomCompareEffect.cjs.map +1 -1
- package/dist/hooks/useCustomCompareEffect.js.map +1 -1
- package/dist/hooks/useCustomCompareMemo.cjs.map +1 -1
- package/dist/hooks/useCustomCompareMemo.js.map +1 -1
- package/dist/hooks/useDebounceEffect.cjs.map +1 -1
- package/dist/hooks/useDebounceEffect.js.map +1 -1
- package/dist/hooks/useDebounceFn.cjs.map +1 -1
- package/dist/hooks/useDebounceFn.js.map +1 -1
- package/dist/hooks/useDebouncedCallback.cjs.map +1 -1
- package/dist/hooks/useDebouncedCallback.js.map +1 -1
- package/dist/hooks/useDebouncedState.cjs.map +1 -1
- package/dist/hooks/useDebouncedState.js.map +1 -1
- package/dist/hooks/useDebouncedValue.cjs.map +1 -1
- package/dist/hooks/useDebouncedValue.js.map +1 -1
- package/dist/hooks/useDidUpdate.cjs.map +1 -1
- package/dist/hooks/useDidUpdate.js.map +1 -1
- package/dist/hooks/useEffectOnce.cjs.map +1 -1
- package/dist/hooks/useEffectOnce.js.map +1 -1
- package/dist/hooks/useEventListener.cjs.map +1 -1
- package/dist/hooks/useEventListener.js.map +1 -1
- package/dist/hooks/useIdle.cjs.map +1 -1
- package/dist/hooks/useIdle.js.map +1 -1
- package/dist/hooks/useImageLoadCallback.cjs.map +1 -1
- package/dist/hooks/useImageLoadCallback.js.map +1 -1
- package/dist/hooks/useImageUpload.cjs.map +1 -1
- package/dist/hooks/useImageUpload.js.map +1 -1
- package/dist/hooks/useInterval.cjs.map +1 -1
- package/dist/hooks/useInterval.js.map +1 -1
- package/dist/hooks/useLifecycleLogger.cjs.map +1 -1
- package/dist/hooks/useLifecycleLogger.js.map +1 -1
- package/dist/hooks/useLocalStorageState.cjs.map +1 -1
- package/dist/hooks/useLocalStorageState.js.map +1 -1
- package/dist/hooks/useMutationObserver.cjs.map +1 -1
- package/dist/hooks/useMutationObserver.js.map +1 -1
- package/dist/hooks/useObservableLocalStorage.cjs.map +1 -1
- package/dist/hooks/useObservableLocalStorage.js.map +1 -1
- package/dist/hooks/useObservableSessionStorage.cjs.map +1 -1
- package/dist/hooks/useObservableSessionStorage.js.map +1 -1
- package/dist/hooks/useRefEffect.cjs.map +1 -1
- package/dist/hooks/useRefEffect.js.map +1 -1
- package/dist/hooks/useResizeObserver.cjs.map +1 -1
- package/dist/hooks/useResizeObserver.js.map +1 -1
- package/dist/hooks/useSessionStorageState.cjs.map +1 -1
- package/dist/hooks/useSessionStorageState.js.map +1 -1
- package/dist/hooks/useThrottledCallback.cjs.map +1 -1
- package/dist/hooks/useThrottledCallback.js.map +1 -1
- package/dist/hooks/useThrottledCallbackWithClearTimeout.cjs.map +1 -1
- package/dist/hooks/useThrottledCallbackWithClearTimeout.js.map +1 -1
- package/dist/hooks/useThrottledState.cjs.map +1 -1
- package/dist/hooks/useThrottledState.js.map +1 -1
- package/dist/hooks/useThrottledValue.cjs.map +1 -1
- package/dist/hooks/useThrottledValue.js.map +1 -1
- package/dist/hooks/useUpdateEffect.cjs.map +1 -1
- package/dist/hooks/useUpdateEffect.js.map +1 -1
- package/dist/hooks/useUpdateLayoutEffect.cjs.map +1 -1
- package/dist/hooks/useUpdateLayoutEffect.js.map +1 -1
- package/dist/hooks/useWindowEvent.cjs.map +1 -1
- package/dist/hooks/useWindowEvent.js.map +1 -1
- package/dist/hooks/useWindowSize.cjs.map +1 -1
- package/dist/hooks/useWindowSize.js.map +1 -1
- package/dist/persistence/useStorageState.cjs.map +1 -1
- package/dist/persistence/useStorageState.js.map +1 -1
- package/dist/util/event-utils.cjs.map +1 -1
- package/dist/util/event-utils.js.map +1 -1
- package/dist/util/override-props.cjs.map +1 -1
- package/dist/util/override-props.js.map +1 -1
- package/package.json +19 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObservableSessionStorage.js","names":["EventEmitter","useSessionStorage","useCallback","useEffect","useMemo","useState","emitters","getOrCreateEmitter","key","getDefaultValue","value","useObservableSessionStorage","initialValue","defaultValue","setValue","removeValue","emitter","setValueAndNotify","next","onChange"],"sources":["../../src/hooks/useObservableSessionStorage.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { EventEmitter } from '../eventemitter/eventemitter3.js';\nimport { useSessionStorage } from './useSessionStorage.js';\n\ntype SetStateFn<T> = (value: T | undefined) => void;\n\ntype GetFn<T> = () => T;\n\
|
|
1
|
+
{"version":3,"file":"useObservableSessionStorage.js","names":["EventEmitter","useSessionStorage","useCallback","useEffect","useMemo","useState","emitters","getOrCreateEmitter","key","getDefaultValue","value","useObservableSessionStorage","initialValue","defaultValue","setValue","removeValue","emitter","setValueAndNotify","next","onChange"],"sources":["../../src/hooks/useObservableSessionStorage.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { EventEmitter } from '../eventemitter/eventemitter3.js';\nimport { useSessionStorage } from './useSessionStorage.js';\n\ntype SetStateFn<T> = (value: T | undefined) => void;\n\ntype GetFn<T> = () => T;\n\nconst emitters: Record<string, EventEmitter<any>> = {};\n\nconst getOrCreateEmitter = (key: string): EventEmitter<any> => {\n const instance = emitters[key];\n if (instance) {\n return instance;\n }\n emitters[key] = new EventEmitter();\n return emitters[key];\n};\n\nfunction getDefaultValue<T>(value: T | GetFn<T>): T {\n if (typeof value === 'function') {\n return (value as () => T)();\n }\n return value;\n}\n\nexport function useObservableSessionStorage<T>(\n key: string,\n initialValue: T | GetFn<T>,\n): [T, SetStateFn<T | null>] {\n const [defaultValue] = useState<T>(() => getDefaultValue(initialValue));\n const [value, setValue, removeValue] = useSessionStorage<T | null>(key, defaultValue);\n const emitter = useMemo(() => getOrCreateEmitter(key), [key]);\n\n const setValueAndNotify = useCallback(\n (next: T | null | undefined) => {\n emitter.emit(key, next ?? null);\n },\n [emitter, key],\n );\n\n useEffect(() => {\n const onChange = (next: T | null) => {\n if (typeof next === 'undefined' || next === null) {\n removeValue();\n return;\n }\n setValue(next);\n };\n emitter.on(key, onChange);\n return () => {\n emitter.off(key, onChange);\n };\n }, [key, emitter, removeValue, setValue]);\n\n return [value ?? defaultValue, setValueAndNotify];\n}\n"],"mappings":"A,sNAUA,MAAMM,EAA8C,CAAC,EAE/CC,EAAsBC,GACTF,EAASE,KAI1BF,EAASE,GAAO,IAAIR,EACbM,EAASE,IAGlB,SAASC,EAAmBC,EAAwB,CAIlD,OAHI,OAAOA,GAAU,WACXA,EAAkB,EAErBA,CACT,CAEA,SAAgBC,EACdH,EACAI,EAC2B,CAC3B,GAAM,CAACC,GAAgBR,MAAkBI,EAAgBG,CAAY,CAAC,EAChE,CAACF,EAAOI,EAAUC,GAAed,EAA4BO,EAAKK,CAAY,EAC9EG,EAAUZ,MAAcG,EAAmBC,CAAG,EAAG,CAACA,CAAG,CAAC,EAEtDS,EAAoBf,EACvBgB,GAA+B,CAC9BF,EAAQ,KAAKR,EAAKU,GAAQ,IAAI,CAChC,EACA,CAACF,EAASR,CAAG,CACf,EAgBA,OAdAL,MAAgB,CACd,IAAMgB,EAAYD,GAAmB,CACxBA,GAAiC,KAC1CH,EAAY,EAGdD,EAASI,CAAI,CACf,EAEA,OADAF,EAAQ,GAAGR,EAAKW,CAAQ,MACX,CACXH,EAAQ,IAAIR,EAAKW,CAAQ,CAC3B,CACF,EAAG,CAACX,EAAKQ,EAASD,EAAaD,CAAQ,CAAC,EAEjC,CAACJ,GAASG,EAAcI,CAAiB,CAClD,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRefEffect.cjs","names":["useCallbackRef","useRef","useCallback","require_useCallbackRef","react","useRefEffect","callback","deps","stableCallback","cleanupCallbackRef","element","cleanup"],"sources":["../../src/hooks/useRefEffect.ts"],"sourcesContent":["'use client';\n\nimport { type DependencyList, useCallback, useRef } from 'react';\
|
|
1
|
+
{"version":3,"file":"useRefEffect.cjs","names":["useCallbackRef","useRef","useCallback","require_useCallbackRef","react","useRefEffect","callback","deps","stableCallback","cleanupCallbackRef","element","cleanup"],"sources":["../../src/hooks/useRefEffect.ts"],"sourcesContent":["'use client';\n\nimport { type DependencyList, useCallback, useRef } from 'react';\nimport { useCallbackRef } from './useCallbackRef.js';\n\nexport type CleanupCallback = () => void;\n\n/**\n * DOM ref가 연결되거나 변경될 때 콜백을 실행하고, 이전 요소에 대한 정리 함수를 자동으로 호출하는 훅입니다.\n *\n * @template RefElement - ref로 연결할 HTML 요소 타입. 기본값은 `HTMLElement`입니다.\n * @param callback - 요소가 연결될 때 실행할 함수. 정리 함수가 필요하면 반환할 수 있습니다.\n * @param deps - ref 콜백을 다시 생성할 의존성 목록입니다.\n * @returns React `ref` prop에 전달할 수 있는 콜백 ref 함수입니다.\n *\n * @example\n * ```tsx\n * const ref = useRefEffect<HTMLDivElement>((element) => {\n * console.log('mounted', element);\n *\n * return () => {\n * console.log('unmounted', element);\n * };\n * }, []);\n *\n * return <div ref={ref} />;\n * ```\n */\nexport function useRefEffect<RefElement extends HTMLElement = HTMLElement>(\n callback: (element: RefElement) => CleanupCallback | undefined,\n deps: DependencyList,\n): (element: RefElement | null) => void {\n const stableCallback = useCallbackRef(callback);\n const cleanupCallbackRef = useRef<CleanupCallback>(() => {});\n\n return useCallback(\n (element: RefElement | null) => {\n cleanupCallbackRef.current();\n cleanupCallbackRef.current = () => {};\n\n if (element == null) {\n return;\n }\n\n const cleanup = stableCallback(element);\n\n if (typeof cleanup === 'function') {\n cleanupCallbackRef.current = cleanup;\n }\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- deps는 호출자가 넘긴 의존성 목록이라 정적으로 검사할 수 없습니다.\n [stableCallback, ...deps],\n );\n}\n"],"mappings":"A,4EA4BA,SAAgBK,EACdC,EACAC,EACsC,CACtC,IAAMC,EAAiBR,EAAAA,eAAeM,CAAQ,EACxCG,GAAA,EAAqBR,EAAAA,OAAAA,KAA8B,CAAC,CAAC,EAE3D,OAAA,EAAOC,EAAAA,YAAAA,CACJQ,GAA+B,CAI9B,GAHAD,EAAmB,QAAQ,EAC3BA,EAAmB,YAAgB,CAAC,EAEhCC,GAAW,KACb,OAGF,IAAMC,EAAUH,EAAeE,CAAO,EAElC,OAAOC,GAAY,aACrBF,EAAmB,QAAUE,EAEjC,EAEA,CAACH,EAAgB,GAAGD,CAAI,CAC1B,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRefEffect.js","names":["useCallbackRef","useCallback","useRef","useRefEffect","callback","deps","stableCallback","cleanupCallbackRef","element","cleanup"],"sources":["../../src/hooks/useRefEffect.ts"],"sourcesContent":["'use client';\n\nimport { type DependencyList, useCallback, useRef } from 'react';\
|
|
1
|
+
{"version":3,"file":"useRefEffect.js","names":["useCallbackRef","useCallback","useRef","useRefEffect","callback","deps","stableCallback","cleanupCallbackRef","element","cleanup"],"sources":["../../src/hooks/useRefEffect.ts"],"sourcesContent":["'use client';\n\nimport { type DependencyList, useCallback, useRef } from 'react';\nimport { useCallbackRef } from './useCallbackRef.js';\n\nexport type CleanupCallback = () => void;\n\n/**\n * DOM ref가 연결되거나 변경될 때 콜백을 실행하고, 이전 요소에 대한 정리 함수를 자동으로 호출하는 훅입니다.\n *\n * @template RefElement - ref로 연결할 HTML 요소 타입. 기본값은 `HTMLElement`입니다.\n * @param callback - 요소가 연결될 때 실행할 함수. 정리 함수가 필요하면 반환할 수 있습니다.\n * @param deps - ref 콜백을 다시 생성할 의존성 목록입니다.\n * @returns React `ref` prop에 전달할 수 있는 콜백 ref 함수입니다.\n *\n * @example\n * ```tsx\n * const ref = useRefEffect<HTMLDivElement>((element) => {\n * console.log('mounted', element);\n *\n * return () => {\n * console.log('unmounted', element);\n * };\n * }, []);\n *\n * return <div ref={ref} />;\n * ```\n */\nexport function useRefEffect<RefElement extends HTMLElement = HTMLElement>(\n callback: (element: RefElement) => CleanupCallback | undefined,\n deps: DependencyList,\n): (element: RefElement | null) => void {\n const stableCallback = useCallbackRef(callback);\n const cleanupCallbackRef = useRef<CleanupCallback>(() => {});\n\n return useCallback(\n (element: RefElement | null) => {\n cleanupCallbackRef.current();\n cleanupCallbackRef.current = () => {};\n\n if (element == null) {\n return;\n }\n\n const cleanup = stableCallback(element);\n\n if (typeof cleanup === 'function') {\n cleanupCallbackRef.current = cleanup;\n }\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- deps는 호출자가 넘긴 의존성 목록이라 정적으로 검사할 수 없습니다.\n [stableCallback, ...deps],\n );\n}\n"],"mappings":"A,kHA4BA,SAAgBG,EACdC,EACAC,EACsC,CACtC,IAAMC,EAAiBN,EAAeI,CAAQ,EACxCG,EAAqBL,MAA8B,CAAC,CAAC,EAE3D,OAAOD,EACJO,GAA+B,CAI9B,GAHAD,EAAmB,QAAQ,EAC3BA,EAAmB,YAAgB,CAAC,EAEhCC,GAAW,KACb,OAGF,IAAMC,EAAUH,EAAeE,CAAO,EAElC,OAAOC,GAAY,aACrBF,EAAmB,QAAUE,EAEjC,EAEA,CAACH,EAAgB,GAAGD,CAAI,CAC1B,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeObserver.cjs","names":["useRef","useState","useMemo","useEffect","react","defaultState","useResizeObserver","options","frameID","ref","rect","setRect","observer","entries","entry"],"sources":["../../src/hooks/useResizeObserver.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\ntype ObserverRect = Omit<DOMRectReadOnly, 'toJSON'>;\n\nconst defaultState: ObserverRect = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n};\n\n/**\n * 요소에 대한 `ref`를 제공하고 크기 조정(resize) 이벤트를 관찰하는 커스텀 React 훅.\n * 이 훅은 요소의 크기와 위치(DOMRect)를 반환합니다.\n *\n * @template T - 관찰할 HTML 요소의 타입. 기본값은 `HTMLElement`입니다.\n * @param options - 관찰을 설정하기 위한 선택적인 `ResizeObserverOptions` 객체.\n * @returns 튜플 형태의 반환값:\n * - `ref`: 관찰할 요소에 연결하기 위한 React 참조 객체.\n * - `rect`: 관찰된 요소의 DOMRect 속성(크기와 위치).\n *\n * @example\n * ```tsx\n * const [ref, rect] = useResizeObserver();\n *\n * return (\n * <div ref={ref} style={{ resize: \"both\", overflow: \"auto\" }}>\n * Width: {rect.width}, Height: {rect.height}\n * </div>\n * );\n * ```\n */\nexport function useResizeObserver<T extends HTMLElement = HTMLElement>(\n options?: ResizeObserverOptions,\n) {\n // Reference to the animation frame ID for cleanup\n const frameID = useRef(0);\n\n // Reference to the observed element\n const ref = useRef<T>(null);\n\n // State to store the DOMRect of the observed element\n const [rect, setRect] = useState<ObserverRect>(defaultState);\n\n // Memoized ResizeObserver instance to track element size changes\n const observer = useMemo(\n () =>\n typeof window !== 'undefined'\n ? new ResizeObserver((entries: ResizeObserverEntry[]) => {\n const entry = entries[0];\n\n if (entry) {\n // Cancel any ongoing animation frame\n cancelAnimationFrame(frameID.current);\n\n // Schedule an update for the next animation frame\n frameID.current = requestAnimationFrame(() => {\n if (ref.current) {\n setRect(entry.contentRect);\n }\n });\n }\n })\n : null,\n [],\n );\n\n
|
|
1
|
+
{"version":3,"file":"useResizeObserver.cjs","names":["useRef","useState","useMemo","useEffect","react","defaultState","useResizeObserver","options","frameID","ref","rect","setRect","observer","entries","entry"],"sources":["../../src/hooks/useResizeObserver.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\ntype ObserverRect = Omit<DOMRectReadOnly, 'toJSON'>;\n\nconst defaultState: ObserverRect = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n};\n\n/**\n * 요소에 대한 `ref`를 제공하고 크기 조정(resize) 이벤트를 관찰하는 커스텀 React 훅.\n * 이 훅은 요소의 크기와 위치(DOMRect)를 반환합니다.\n *\n * @template T - 관찰할 HTML 요소의 타입. 기본값은 `HTMLElement`입니다.\n * @param options - 관찰을 설정하기 위한 선택적인 `ResizeObserverOptions` 객체.\n * @returns 튜플 형태의 반환값:\n * - `ref`: 관찰할 요소에 연결하기 위한 React 참조 객체.\n * - `rect`: 관찰된 요소의 DOMRect 속성(크기와 위치).\n *\n * @example\n * ```tsx\n * const [ref, rect] = useResizeObserver();\n *\n * return (\n * <div ref={ref} style={{ resize: \"both\", overflow: \"auto\" }}>\n * Width: {rect.width}, Height: {rect.height}\n * </div>\n * );\n * ```\n */\nexport function useResizeObserver<T extends HTMLElement = HTMLElement>(\n options?: ResizeObserverOptions,\n) {\n // Reference to the animation frame ID for cleanup\n const frameID = useRef(0);\n\n // Reference to the observed element\n const ref = useRef<T>(null);\n\n // State to store the DOMRect of the observed element\n const [rect, setRect] = useState<ObserverRect>(defaultState);\n\n // Memoized ResizeObserver instance to track element size changes\n const observer = useMemo(\n () =>\n typeof window !== 'undefined'\n ? new ResizeObserver((entries: ResizeObserverEntry[]) => {\n const entry = entries[0];\n\n if (entry) {\n // Cancel any ongoing animation frame\n cancelAnimationFrame(frameID.current);\n\n // Schedule an update for the next animation frame\n frameID.current = requestAnimationFrame(() => {\n if (ref.current) {\n setRect(entry.contentRect);\n }\n });\n }\n })\n : null,\n [],\n );\n\n useEffect(() => {\n // Start observing the element if it's available\n if (ref.current) {\n observer?.observe(ref.current, options);\n }\n\n return () => {\n // Cleanup: disconnect observer and cancel animation frame\n observer?.disconnect();\n\n if (frameID.current) {\n cancelAnimationFrame(frameID.current);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref.current]);\n\n // Return the ref and the current DOMRect state\n return [ref, rect] as const;\n}\n"],"mappings":"A,oCAQA,MAAMK,EAA6B,CACjC,EAAG,EACH,EAAG,EACH,MAAO,EACP,OAAQ,EACR,IAAK,EACL,KAAM,EACN,OAAQ,EACR,MAAO,CACT,EAuBA,SAAgBC,EACdC,EACA,CAEA,IAAMC,GAAA,EAAUR,EAAAA,OAAAA,CAAO,CAAC,EAGlBS,GAAA,EAAMT,EAAAA,OAAAA,CAAU,IAAI,EAGpB,CAACU,EAAMC,IAAA,EAAWV,EAAAA,SAAAA,CAAuBI,CAAY,EAGrDO,GAAA,EAAWV,EAAAA,QAAAA,KAEb,OAAO,OAAW,IACd,IAAI,eAAgBW,GAAmC,CACrD,IAAMC,EAAQD,EAAQ,GAElBC,IAEF,qBAAqBN,EAAQ,OAAO,EAGpCA,EAAQ,QAAU,0BAA4B,CACxCC,EAAI,SACNE,EAAQG,EAAM,WAAW,CAE7B,CAAC,EAEL,CAAC,EACD,KACN,CAAC,CACH,EAoBA,OAlBAX,EAAAA,EAAAA,UAAAA,MAEMM,EAAI,SACNG,GAAU,QAAQH,EAAI,QAASF,CAAO,MAG3B,CAEXK,GAAU,WAAW,EAEjBJ,EAAQ,SACV,qBAAqBA,EAAQ,OAAO,CAExC,GAEC,CAACC,EAAI,OAAO,CAAC,EAGT,CAACA,EAAKC,CAAI,CACnB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeObserver.js","names":["useEffect","useMemo","useRef","useState","defaultState","useResizeObserver","options","frameID","ref","rect","setRect","observer","entries","entry"],"sources":["../../src/hooks/useResizeObserver.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\ntype ObserverRect = Omit<DOMRectReadOnly, 'toJSON'>;\n\nconst defaultState: ObserverRect = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n};\n\n/**\n * 요소에 대한 `ref`를 제공하고 크기 조정(resize) 이벤트를 관찰하는 커스텀 React 훅.\n * 이 훅은 요소의 크기와 위치(DOMRect)를 반환합니다.\n *\n * @template T - 관찰할 HTML 요소의 타입. 기본값은 `HTMLElement`입니다.\n * @param options - 관찰을 설정하기 위한 선택적인 `ResizeObserverOptions` 객체.\n * @returns 튜플 형태의 반환값:\n * - `ref`: 관찰할 요소에 연결하기 위한 React 참조 객체.\n * - `rect`: 관찰된 요소의 DOMRect 속성(크기와 위치).\n *\n * @example\n * ```tsx\n * const [ref, rect] = useResizeObserver();\n *\n * return (\n * <div ref={ref} style={{ resize: \"both\", overflow: \"auto\" }}>\n * Width: {rect.width}, Height: {rect.height}\n * </div>\n * );\n * ```\n */\nexport function useResizeObserver<T extends HTMLElement = HTMLElement>(\n options?: ResizeObserverOptions,\n) {\n // Reference to the animation frame ID for cleanup\n const frameID = useRef(0);\n\n // Reference to the observed element\n const ref = useRef<T>(null);\n\n // State to store the DOMRect of the observed element\n const [rect, setRect] = useState<ObserverRect>(defaultState);\n\n // Memoized ResizeObserver instance to track element size changes\n const observer = useMemo(\n () =>\n typeof window !== 'undefined'\n ? new ResizeObserver((entries: ResizeObserverEntry[]) => {\n const entry = entries[0];\n\n if (entry) {\n // Cancel any ongoing animation frame\n cancelAnimationFrame(frameID.current);\n\n // Schedule an update for the next animation frame\n frameID.current = requestAnimationFrame(() => {\n if (ref.current) {\n setRect(entry.contentRect);\n }\n });\n }\n })\n : null,\n [],\n );\n\n
|
|
1
|
+
{"version":3,"file":"useResizeObserver.js","names":["useEffect","useMemo","useRef","useState","defaultState","useResizeObserver","options","frameID","ref","rect","setRect","observer","entries","entry"],"sources":["../../src/hooks/useResizeObserver.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\n\ntype ObserverRect = Omit<DOMRectReadOnly, 'toJSON'>;\n\nconst defaultState: ObserverRect = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n};\n\n/**\n * 요소에 대한 `ref`를 제공하고 크기 조정(resize) 이벤트를 관찰하는 커스텀 React 훅.\n * 이 훅은 요소의 크기와 위치(DOMRect)를 반환합니다.\n *\n * @template T - 관찰할 HTML 요소의 타입. 기본값은 `HTMLElement`입니다.\n * @param options - 관찰을 설정하기 위한 선택적인 `ResizeObserverOptions` 객체.\n * @returns 튜플 형태의 반환값:\n * - `ref`: 관찰할 요소에 연결하기 위한 React 참조 객체.\n * - `rect`: 관찰된 요소의 DOMRect 속성(크기와 위치).\n *\n * @example\n * ```tsx\n * const [ref, rect] = useResizeObserver();\n *\n * return (\n * <div ref={ref} style={{ resize: \"both\", overflow: \"auto\" }}>\n * Width: {rect.width}, Height: {rect.height}\n * </div>\n * );\n * ```\n */\nexport function useResizeObserver<T extends HTMLElement = HTMLElement>(\n options?: ResizeObserverOptions,\n) {\n // Reference to the animation frame ID for cleanup\n const frameID = useRef(0);\n\n // Reference to the observed element\n const ref = useRef<T>(null);\n\n // State to store the DOMRect of the observed element\n const [rect, setRect] = useState<ObserverRect>(defaultState);\n\n // Memoized ResizeObserver instance to track element size changes\n const observer = useMemo(\n () =>\n typeof window !== 'undefined'\n ? new ResizeObserver((entries: ResizeObserverEntry[]) => {\n const entry = entries[0];\n\n if (entry) {\n // Cancel any ongoing animation frame\n cancelAnimationFrame(frameID.current);\n\n // Schedule an update for the next animation frame\n frameID.current = requestAnimationFrame(() => {\n if (ref.current) {\n setRect(entry.contentRect);\n }\n });\n }\n })\n : null,\n [],\n );\n\n useEffect(() => {\n // Start observing the element if it's available\n if (ref.current) {\n observer?.observe(ref.current, options);\n }\n\n return () => {\n // Cleanup: disconnect observer and cancel animation frame\n observer?.disconnect();\n\n if (frameID.current) {\n cancelAnimationFrame(frameID.current);\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref.current]);\n\n // Return the ref and the current DOMRect state\n return [ref, rect] as const;\n}\n"],"mappings":"A,sFAQA,MAAMI,EAA6B,CACjC,EAAG,EACH,EAAG,EACH,MAAO,EACP,OAAQ,EACR,IAAK,EACL,KAAM,EACN,OAAQ,EACR,MAAO,CACT,EAuBA,SAAgBC,EACdC,EACA,CAEA,IAAMC,EAAUL,EAAO,CAAC,EAGlBM,EAAMN,EAAU,IAAI,EAGpB,CAACO,EAAMC,GAAWP,EAAuBC,CAAY,EAGrDO,EAAWV,MAEb,OAAO,OAAW,IACd,IAAI,eAAgBW,GAAmC,CACrD,IAAMC,EAAQD,EAAQ,GAElBC,IAEF,qBAAqBN,EAAQ,OAAO,EAGpCA,EAAQ,QAAU,0BAA4B,CACxCC,EAAI,SACNE,EAAQG,EAAM,WAAW,CAE7B,CAAC,EAEL,CAAC,EACD,KACN,CAAC,CACH,EAoBA,OAlBAb,OAEMQ,EAAI,SACNG,GAAU,QAAQH,EAAI,QAASF,CAAO,MAG3B,CAEXK,GAAU,WAAW,EAEjBJ,EAAQ,SACV,qBAAqBA,EAAQ,OAAO,CAExC,GAEC,CAACC,EAAI,OAAO,CAAC,EAGT,CAACA,EAAKC,CAAI,CACnB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionStorageState.cjs","names":["useStorageState","useStorageStateServer","require_useStorageState","useSessionStorageState","args"],"sources":["../../src/hooks/useSessionStorageState.ts"],"sourcesContent":["'use client';\n\n// copy from https://github.com/mui/toolpad\n\nimport type { UseStorageState } from '../persistence/index.js';\nimport { useStorageState, useStorageStateServer } from '../persistence/index.js';\n\n/**\n * Sync state to session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\
|
|
1
|
+
{"version":3,"file":"useSessionStorageState.cjs","names":["useStorageState","useStorageStateServer","require_useStorageState","useSessionStorageState","args"],"sources":["../../src/hooks/useSessionStorageState.ts"],"sourcesContent":["'use client';\n\n// copy from https://github.com/mui/toolpad\n\nimport type { UseStorageState } from '../persistence/index.js';\nimport { useStorageState, useStorageStateServer } from '../persistence/index.js';\n\n/**\n * Sync state to session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\nconst useSessionStorageStateBrowser: UseStorageState = (...args: [any, any, any]) =>\n useStorageState(window.sessionStorage, ...args);\n\n/**\n * @deprecated use useSessionStorage()\n */\nexport const useSessionStorageState: UseStorageState =\n typeof window === 'undefined' ? useStorageStateServer : useSessionStorageStateBrowser;\n"],"mappings":"A,mEAqBaG,EACX,OAAO,OAAW,IAAcF,EAAAA,uBAPsB,GAAGG,IACzDJ,EAAAA,gBAAgB,OAAO,eAAgB,GAAGI,CAAI,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionStorageState.js","names":["useStorageState","useStorageStateServer","useSessionStorageState","args"],"sources":["../../src/hooks/useSessionStorageState.ts"],"sourcesContent":["'use client';\n\n// copy from https://github.com/mui/toolpad\n\nimport type { UseStorageState } from '../persistence/index.js';\nimport { useStorageState, useStorageStateServer } from '../persistence/index.js';\n\n/**\n * Sync state to session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\
|
|
1
|
+
{"version":3,"file":"useSessionStorageState.js","names":["useStorageState","useStorageStateServer","useSessionStorageState","args"],"sources":["../../src/hooks/useSessionStorageState.ts"],"sourcesContent":["'use client';\n\n// copy from https://github.com/mui/toolpad\n\nimport type { UseStorageState } from '../persistence/index.js';\nimport { useStorageState, useStorageStateServer } from '../persistence/index.js';\n\n/**\n * Sync state to session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\nconst useSessionStorageStateBrowser: UseStorageState = (...args: [any, any, any]) =>\n useStorageState(window.sessionStorage, ...args);\n\n/**\n * @deprecated use useSessionStorage()\n */\nexport const useSessionStorageState: UseStorageState =\n typeof window === 'undefined' ? useStorageStateServer : useSessionStorageStateBrowser;\n"],"mappings":"A,4GAqBA,MAAaE,EACX,OAAO,OAAW,IAAcD,GAPsB,GAAGE,IACzDH,EAAgB,OAAO,eAAgB,GAAGG,CAAI,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledCallback.cjs","names":["useThrottledCallbackWithClearTimeout","require_useThrottledCallbackWithClearTimeout","useThrottledCallback","callback","wait"],"sources":["../../src/hooks/useThrottledCallback.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하도록 제한하는 간단한 쓰로틀링 React 훅.\n *\n * 내부적으로 `useThrottledCallbackWithClearTimeout`을 사용하며, 타이머 정리 기능 없이 쓰로틀링된 콜백 함수만 반환합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 쓰로틀링된 콜백 함수.\n *\n * @example\n * ```tsx\n * const throttledClick = useThrottledCallback(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return <button onClick={throttledClick}>클릭</button>;\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"useThrottledCallback.cjs","names":["useThrottledCallbackWithClearTimeout","require_useThrottledCallbackWithClearTimeout","useThrottledCallback","callback","wait"],"sources":["../../src/hooks/useThrottledCallback.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하도록 제한하는 간단한 쓰로틀링 React 훅.\n *\n * 내부적으로 `useThrottledCallbackWithClearTimeout`을 사용하며, 타이머 정리 기능 없이 쓰로틀링된 콜백 함수만 반환합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 쓰로틀링된 콜백 함수.\n *\n * @example\n * ```tsx\n * const throttledClick = useThrottledCallback(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return <button onClick={throttledClick}>클릭</button>;\n * ```\n */\nexport function useThrottledCallback<T extends (...args: any[]) => any>(\n callback: T, // 쓰로틀링할 콜백 함수\n wait: number, // 호출 간격 (밀리초 단위)\n) {\n // `useThrottledCallbackWithClearTimeout` 훅을 사용하여 쓰로틀링된 콜백을 생성\n // 반환값 중 첫 번째 요소(쓰로틀링된 콜백 함수)만 반환\n return useThrottledCallbackWithClearTimeout(callback, wait)[0];\n}\n"],"mappings":"A,2EAwBA,SAAgBE,EACdC,EACAC,EACA,CAGA,OAAOJ,EAAAA,qCAAqCG,EAAUC,CAAI,CAAC,CAAC,EAC9D,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledCallback.js","names":["useThrottledCallbackWithClearTimeout","useThrottledCallback","callback","wait"],"sources":["../../src/hooks/useThrottledCallback.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하도록 제한하는 간단한 쓰로틀링 React 훅.\n *\n * 내부적으로 `useThrottledCallbackWithClearTimeout`을 사용하며, 타이머 정리 기능 없이 쓰로틀링된 콜백 함수만 반환합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 쓰로틀링된 콜백 함수.\n *\n * @example\n * ```tsx\n * const throttledClick = useThrottledCallback(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return <button onClick={throttledClick}>클릭</button>;\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"useThrottledCallback.js","names":["useThrottledCallbackWithClearTimeout","useThrottledCallback","callback","wait"],"sources":["../../src/hooks/useThrottledCallback.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하도록 제한하는 간단한 쓰로틀링 React 훅.\n *\n * 내부적으로 `useThrottledCallbackWithClearTimeout`을 사용하며, 타이머 정리 기능 없이 쓰로틀링된 콜백 함수만 반환합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 쓰로틀링된 콜백 함수.\n *\n * @example\n * ```tsx\n * const throttledClick = useThrottledCallback(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return <button onClick={throttledClick}>클릭</button>;\n * ```\n */\nexport function useThrottledCallback<T extends (...args: any[]) => any>(\n callback: T, // 쓰로틀링할 콜백 함수\n wait: number, // 호출 간격 (밀리초 단위)\n) {\n // `useThrottledCallbackWithClearTimeout` 훅을 사용하여 쓰로틀링된 콜백을 생성\n // 반환값 중 첫 번째 요소(쓰로틀링된 콜백 함수)만 반환\n return useThrottledCallbackWithClearTimeout(callback, wait)[0];\n}\n"],"mappings":"A,8GAwBA,SAAgBC,EACdC,EACAC,EACA,CAGA,OAAOH,EAAqCE,EAAUC,CAAI,CAAC,CAAC,EAC9D,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledCallbackWithClearTimeout.cjs","names":["useCallbackRef","useRef","useCallback","useEffect","require_useCallbackRef","react","useThrottledCallbackWithClearTimeout","callback","wait","handleCallback","latestInArgsRef","latestOutArgsRef","active","waitRef","timeoutRef","clearTimeout","callThrottledCallback","args","timerCallback","timerCallbackImpl","throttled"],"sources":["../../src/hooks/useThrottledCallbackWithClearTimeout.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useCallbackRef } from './useCallbackRef.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하는 커스텀 React 훅.\n *\n * 이 훅은 마지막 호출 이후 일정 시간이 지나야 콜백이 다시 호출되도록 제한합니다(Throttle).\n * 또한 타이머를 수동으로 정리할 수 있는 기능을 제공합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `throttled`: 쓰로틀링된 콜백 함수.\n * - `clearTimeout`: 현재 실행 중인 타이머를 취소하는 함수.\n *\n * @example\n * ```tsx\n * const [throttledClick, clearThrottle] = useThrottledCallbackWithClearTimeout(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return (\n * <button onClick={throttledClick}>클릭</button>\n * <button onClick={clearThrottle}>쓰로틀링 취소</button>\n * );\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"useThrottledCallbackWithClearTimeout.cjs","names":["useCallbackRef","useRef","useCallback","useEffect","require_useCallbackRef","react","useThrottledCallbackWithClearTimeout","callback","wait","handleCallback","latestInArgsRef","latestOutArgsRef","active","waitRef","timeoutRef","clearTimeout","callThrottledCallback","args","timerCallback","timerCallbackImpl","throttled"],"sources":["../../src/hooks/useThrottledCallbackWithClearTimeout.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useCallbackRef } from './useCallbackRef.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하는 커스텀 React 훅.\n *\n * 이 훅은 마지막 호출 이후 일정 시간이 지나야 콜백이 다시 호출되도록 제한합니다(Throttle).\n * 또한 타이머를 수동으로 정리할 수 있는 기능을 제공합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `throttled`: 쓰로틀링된 콜백 함수.\n * - `clearTimeout`: 현재 실행 중인 타이머를 취소하는 함수.\n *\n * @example\n * ```tsx\n * const [throttledClick, clearThrottle] = useThrottledCallbackWithClearTimeout(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return (\n * <button onClick={throttledClick}>클릭</button>\n * <button onClick={clearThrottle}>쓰로틀링 취소</button>\n * );\n * ```\n */\nexport function useThrottledCallbackWithClearTimeout<T extends (...args: any[]) => any>(\n callback: T, // 쓰로틀링할 콜백 함수\n wait: number, // 호출 간격(밀리초 단위)\n) {\n // 최신 콜백 함수를 안전하게 참조하기 위해 useCallbackRef 사용\n const handleCallback = useCallbackRef(callback);\n\n // 마지막으로 입력된 인자를 저장하는 ref\n const latestInArgsRef = useRef<Parameters<T> | undefined>(undefined);\n\n // 마지막으로 실행된 인자를 저장하는 ref\n const latestOutArgsRef = useRef<Parameters<T> | undefined>(undefined);\n\n // 쓰로틀링 상태를 추적하는 ref\n const active = useRef(true);\n\n // 호출 간격을 저장하는 ref\n const waitRef = useRef(wait);\n\n // 타이머 ID를 저장하는 ref\n const timeoutRef = useRef<number>(-1);\n\n // 현재 타이머를 정리하는 함수\n const clearTimeout = () => window.clearTimeout(timeoutRef.current);\n\n // 쓰로틀링된 콜백을 호출하는 함수\n const callThrottledCallback = useCallback(\n (...args: Parameters<T>) => {\n handleCallback(...args); // 최신 콜백 호출\n latestInArgsRef.current = args; // 마지막 입력 인자 업데이트\n latestOutArgsRef.current = args; // 마지막 출력 인자 업데이트\n active.current = false; // 쓰로틀링 상태 비활성화\n },\n [handleCallback],\n );\n\n // 타이머가 동작하는 동안 실행되는 콜백\n const timerCallback = useCallback(\n function timerCallbackImpl() {\n if (latestInArgsRef.current && latestInArgsRef.current !== latestOutArgsRef.current) {\n callThrottledCallback(...latestInArgsRef.current); // 새로운 인자 기반으로 콜백 호출\n timeoutRef.current = window.setTimeout(timerCallbackImpl, waitRef.current); // 다음 타이머 설정\n } else {\n active.current = true; // 쓰로틀링 상태 활성화\n }\n },\n [callThrottledCallback],\n );\n\n // 쓰로틀링된 콜백 함수\n const throttled = useCallback(\n (...args: Parameters<T>) => {\n if (active.current) {\n // 활성 상태일 경우 콜백 즉시 호출\n callThrottledCallback(...args);\n // 쓰로틀링 타이머 설정\n timeoutRef.current = window.setTimeout(timerCallback, waitRef.current);\n } else {\n // 활성 상태가 아니면 마지막 입력 인자만 업데이트\n latestInArgsRef.current = args;\n }\n },\n [callThrottledCallback, timerCallback],\n );\n\n // `wait` 값이 변경될 때마다 ref에 업데이트\n useEffect(() => {\n waitRef.current = wait;\n }, [wait]);\n\n // 쓰로틀링된 콜백과 타이머 정리 함수를 반환\n return [throttled, clearTimeout] as const;\n}\n"],"mappings":"A,4EA+BA,SAAgBM,EACdC,EACAC,EACA,CAEA,IAAMC,EAAiBT,EAAAA,eAAeO,CAAQ,EAGxCG,GAAA,EAAkBT,EAAAA,OAAAA,CAAkC,IAAA,EAAS,EAG7DU,GAAA,EAAmBV,EAAAA,OAAAA,CAAkC,IAAA,EAAS,EAG9DW,GAAA,EAASX,EAAAA,OAAAA,CAAO,EAAI,EAGpBY,GAAA,EAAUZ,EAAAA,OAAAA,CAAOO,CAAI,EAGrBM,GAAA,EAAab,EAAAA,OAAAA,CAAe,EAAE,EAG9Bc,MAAqB,OAAO,aAAaD,EAAW,OAAO,EAG3DE,GAAA,EAAwBd,EAAAA,YAAAA,EAC3B,GAAGe,IAAwB,CAC1BR,EAAe,GAAGQ,CAAI,EACtBP,EAAgB,QAAUO,EAC1BN,EAAiB,QAAUM,EAC3BL,EAAO,QAAU,EACnB,EACA,CAACH,CAAc,CACjB,EAGMS,GAAA,EAAgBhB,EAAAA,YAAAA,CACpB,SAASiB,GAAoB,CACvBT,EAAgB,SAAWA,EAAgB,UAAYC,EAAiB,SAC1EK,EAAsB,GAAGN,EAAgB,OAAO,EAChDI,EAAW,QAAU,OAAO,WAAWK,EAAmBN,EAAQ,OAAO,GAEzED,EAAO,QAAU,EAErB,EACA,CAACI,CAAqB,CACxB,EAGMI,GAAA,EAAYlB,EAAAA,YAAAA,EACf,GAAGe,IAAwB,CACtBL,EAAO,SAETI,EAAsB,GAAGC,CAAI,EAE7BH,EAAW,QAAU,OAAO,WAAWI,EAAeL,EAAQ,OAAO,GAGrEH,EAAgB,QAAUO,CAE9B,EACA,CAACD,EAAuBE,CAAa,CACvC,EAQA,OALAf,EAAAA,EAAAA,UAAAA,KAAgB,CACdU,EAAQ,QAAUL,CACpB,EAAG,CAACA,CAAI,CAAC,EAGF,CAACY,EAAWL,CAAY,CACjC,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledCallbackWithClearTimeout.js","names":["useCallbackRef","useCallback","useEffect","useRef","useThrottledCallbackWithClearTimeout","callback","wait","handleCallback","latestInArgsRef","latestOutArgsRef","active","waitRef","timeoutRef","clearTimeout","callThrottledCallback","args","timerCallback","timerCallbackImpl","throttled"],"sources":["../../src/hooks/useThrottledCallbackWithClearTimeout.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useCallbackRef } from './useCallbackRef.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하는 커스텀 React 훅.\n *\n * 이 훅은 마지막 호출 이후 일정 시간이 지나야 콜백이 다시 호출되도록 제한합니다(Throttle).\n * 또한 타이머를 수동으로 정리할 수 있는 기능을 제공합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `throttled`: 쓰로틀링된 콜백 함수.\n * - `clearTimeout`: 현재 실행 중인 타이머를 취소하는 함수.\n *\n * @example\n * ```tsx\n * const [throttledClick, clearThrottle] = useThrottledCallbackWithClearTimeout(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return (\n * <button onClick={throttledClick}>클릭</button>\n * <button onClick={clearThrottle}>쓰로틀링 취소</button>\n * );\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"useThrottledCallbackWithClearTimeout.js","names":["useCallbackRef","useCallback","useEffect","useRef","useThrottledCallbackWithClearTimeout","callback","wait","handleCallback","latestInArgsRef","latestOutArgsRef","active","waitRef","timeoutRef","clearTimeout","callThrottledCallback","args","timerCallback","timerCallbackImpl","throttled"],"sources":["../../src/hooks/useThrottledCallbackWithClearTimeout.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useCallbackRef } from './useCallbackRef.js';\n\n/**\n * 주어진 콜백 함수를 지정된 시간 간격(`wait`)으로 호출하는 커스텀 React 훅.\n *\n * 이 훅은 마지막 호출 이후 일정 시간이 지나야 콜백이 다시 호출되도록 제한합니다(Throttle).\n * 또한 타이머를 수동으로 정리할 수 있는 기능을 제공합니다.\n *\n * @template T - 콜백 함수의 타입.\n * @param callback - 쓰로틀링할 콜백 함수.\n * @param wait - 호출 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `throttled`: 쓰로틀링된 콜백 함수.\n * - `clearTimeout`: 현재 실행 중인 타이머를 취소하는 함수.\n *\n * @example\n * ```tsx\n * const [throttledClick, clearThrottle] = useThrottledCallbackWithClearTimeout(() => {\n * console.log(\"클릭!\");\n * }, 1000);\n *\n * return (\n * <button onClick={throttledClick}>클릭</button>\n * <button onClick={clearThrottle}>쓰로틀링 취소</button>\n * );\n * ```\n */\nexport function useThrottledCallbackWithClearTimeout<T extends (...args: any[]) => any>(\n callback: T, // 쓰로틀링할 콜백 함수\n wait: number, // 호출 간격(밀리초 단위)\n) {\n // 최신 콜백 함수를 안전하게 참조하기 위해 useCallbackRef 사용\n const handleCallback = useCallbackRef(callback);\n\n // 마지막으로 입력된 인자를 저장하는 ref\n const latestInArgsRef = useRef<Parameters<T> | undefined>(undefined);\n\n // 마지막으로 실행된 인자를 저장하는 ref\n const latestOutArgsRef = useRef<Parameters<T> | undefined>(undefined);\n\n // 쓰로틀링 상태를 추적하는 ref\n const active = useRef(true);\n\n // 호출 간격을 저장하는 ref\n const waitRef = useRef(wait);\n\n // 타이머 ID를 저장하는 ref\n const timeoutRef = useRef<number>(-1);\n\n // 현재 타이머를 정리하는 함수\n const clearTimeout = () => window.clearTimeout(timeoutRef.current);\n\n // 쓰로틀링된 콜백을 호출하는 함수\n const callThrottledCallback = useCallback(\n (...args: Parameters<T>) => {\n handleCallback(...args); // 최신 콜백 호출\n latestInArgsRef.current = args; // 마지막 입력 인자 업데이트\n latestOutArgsRef.current = args; // 마지막 출력 인자 업데이트\n active.current = false; // 쓰로틀링 상태 비활성화\n },\n [handleCallback],\n );\n\n // 타이머가 동작하는 동안 실행되는 콜백\n const timerCallback = useCallback(\n function timerCallbackImpl() {\n if (latestInArgsRef.current && latestInArgsRef.current !== latestOutArgsRef.current) {\n callThrottledCallback(...latestInArgsRef.current); // 새로운 인자 기반으로 콜백 호출\n timeoutRef.current = window.setTimeout(timerCallbackImpl, waitRef.current); // 다음 타이머 설정\n } else {\n active.current = true; // 쓰로틀링 상태 활성화\n }\n },\n [callThrottledCallback],\n );\n\n // 쓰로틀링된 콜백 함수\n const throttled = useCallback(\n (...args: Parameters<T>) => {\n if (active.current) {\n // 활성 상태일 경우 콜백 즉시 호출\n callThrottledCallback(...args);\n // 쓰로틀링 타이머 설정\n timeoutRef.current = window.setTimeout(timerCallback, waitRef.current);\n } else {\n // 활성 상태가 아니면 마지막 입력 인자만 업데이트\n latestInArgsRef.current = args;\n }\n },\n [callThrottledCallback, timerCallback],\n );\n\n // `wait` 값이 변경될 때마다 ref에 업데이트\n useEffect(() => {\n waitRef.current = wait;\n }, [wait]);\n\n // 쓰로틀링된 콜백과 타이머 정리 함수를 반환\n return [throttled, clearTimeout] as const;\n}\n"],"mappings":"A,iIA+BA,SAAgBI,EACdC,EACAC,EACA,CAEA,IAAMC,EAAiBP,EAAeK,CAAQ,EAGxCG,EAAkBL,EAAkC,IAAA,EAAS,EAG7DM,EAAmBN,EAAkC,IAAA,EAAS,EAG9DO,EAASP,EAAO,EAAI,EAGpBQ,EAAUR,EAAOG,CAAI,EAGrBM,EAAaT,EAAe,EAAE,EAG9BU,MAAqB,OAAO,aAAaD,EAAW,OAAO,EAG3DE,EAAwBb,GAC3B,GAAGc,IAAwB,CAC1BR,EAAe,GAAGQ,CAAI,EACtBP,EAAgB,QAAUO,EAC1BN,EAAiB,QAAUM,EAC3BL,EAAO,QAAU,EACnB,EACA,CAACH,CAAc,CACjB,EAGMS,EAAgBf,EACpB,SAASgB,GAAoB,CACvBT,EAAgB,SAAWA,EAAgB,UAAYC,EAAiB,SAC1EK,EAAsB,GAAGN,EAAgB,OAAO,EAChDI,EAAW,QAAU,OAAO,WAAWK,EAAmBN,EAAQ,OAAO,GAEzED,EAAO,QAAU,EAErB,EACA,CAACI,CAAqB,CACxB,EAGMI,EAAYjB,GACf,GAAGc,IAAwB,CACtBL,EAAO,SAETI,EAAsB,GAAGC,CAAI,EAE7BH,EAAW,QAAU,OAAO,WAAWI,EAAeL,EAAQ,OAAO,GAGrEH,EAAgB,QAAUO,CAE9B,EACA,CAACD,EAAuBE,CAAa,CACvC,EAQA,OALAd,MAAgB,CACdS,EAAQ,QAAUL,CACpB,EAAG,CAACA,CAAI,CAAC,EAGF,CAACY,EAAWL,CAAY,CACjC,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledState.cjs","names":["useState","useThrottledCallbackWithClearTimeout","useEffect","require_useThrottledCallbackWithClearTimeout","react","useThrottledState","defaultValue","wait","value","setValue","setThrottledValue","clearTimeout"],"sources":["../../src/hooks/useThrottledState.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useEffect, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 쓰로틀링된 상태(state)와 상태를 업데이트하는 함수를 제공하는 React 커스텀 훅.\n *\n * 이 훅은 상태 업데이트를 지정된 시간 간격(`wait`)으로 제한하여, 불필요한 연속 업데이트를 방지합니다.\n *\n * @template T - 상태 값의 타입. 기본값은 `any`.\n * @param defaultValue - 초기 상태 값.\n * @param wait - 상태 업데이트 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `value`: 현재 상태 값.\n * - `setThrottledValue`: 상태를 쓰로틀링하여 업데이트하는 함수.\n *\n * @example\n * ```tsx\n * const [value, setValue] = useThrottledState(0, 1000);\n *\n * const handleClick = () => setValue(value + 1);\n *\n * return (\n * <div>\n * <p>값: {value}</p>\n * <button onClick={handleClick}>값 증가</button>\n * </div>\n * );\n * ```\n */\nexport function useThrottledState<T>(\n defaultValue: T, // 초기 상태 값\n wait: number, // 상태 업데이트 간격 (밀리초 단위)\n) {\n // 상태 값을 저장하는 state와 업데이트 함수\n const [value, setValue] = useState(defaultValue);\n\n // `setValue`를 쓰로틀링한 업데이트 함수와 타이머 정리 함수 생성\n const [setThrottledValue, clearTimeout] = useThrottledCallbackWithClearTimeout(setValue, wait);\n\n // 컴포넌트 언마운트 시 타이머를 정리\n //
|
|
1
|
+
{"version":3,"file":"useThrottledState.cjs","names":["useState","useThrottledCallbackWithClearTimeout","useEffect","require_useThrottledCallbackWithClearTimeout","react","useThrottledState","defaultValue","wait","value","setValue","setThrottledValue","clearTimeout"],"sources":["../../src/hooks/useThrottledState.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useEffect, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 쓰로틀링된 상태(state)와 상태를 업데이트하는 함수를 제공하는 React 커스텀 훅.\n *\n * 이 훅은 상태 업데이트를 지정된 시간 간격(`wait`)으로 제한하여, 불필요한 연속 업데이트를 방지합니다.\n *\n * @template T - 상태 값의 타입. 기본값은 `any`.\n * @param defaultValue - 초기 상태 값.\n * @param wait - 상태 업데이트 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `value`: 현재 상태 값.\n * - `setThrottledValue`: 상태를 쓰로틀링하여 업데이트하는 함수.\n *\n * @example\n * ```tsx\n * const [value, setValue] = useThrottledState(0, 1000);\n *\n * const handleClick = () => setValue(value + 1);\n *\n * return (\n * <div>\n * <p>값: {value}</p>\n * <button onClick={handleClick}>값 증가</button>\n * </div>\n * );\n * ```\n */\nexport function useThrottledState<T>(\n defaultValue: T, // 초기 상태 값\n wait: number, // 상태 업데이트 간격 (밀리초 단위)\n) {\n // 상태 값을 저장하는 state와 업데이트 함수\n const [value, setValue] = useState(defaultValue);\n\n // `setValue`를 쓰로틀링한 업데이트 함수와 타이머 정리 함수 생성\n const [setThrottledValue, clearTimeout] = useThrottledCallbackWithClearTimeout(setValue, wait);\n\n // 컴포넌트 언마운트 시 타이머를 정리\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n useEffect(() => clearTimeout, []);\n\n // 현재 상태 값과 쓰로틀링된 업데이트 함수 반환\n return [value, setThrottledValue] as const;\n}\n"],"mappings":"A,kGAgCA,SAAgBK,EACdC,EACAC,EACA,CAEA,GAAM,CAACC,EAAOC,IAAA,EAAYT,EAAAA,SAAAA,CAASM,CAAY,EAGzC,CAACI,EAAmBC,GAAgBV,EAAAA,qCAAqCQ,EAAUF,CAAI,EAO7F,OAHAL,EAAAA,EAAAA,UAAAA,KAAgBS,EAAc,CAAC,CAAC,EAGzB,CAACH,EAAOE,CAAiB,CAClC,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledState.js","names":["useThrottledCallbackWithClearTimeout","useEffect","useState","useThrottledState","defaultValue","wait","value","setValue","setThrottledValue","clearTimeout"],"sources":["../../src/hooks/useThrottledState.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useEffect, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 쓰로틀링된 상태(state)와 상태를 업데이트하는 함수를 제공하는 React 커스텀 훅.\n *\n * 이 훅은 상태 업데이트를 지정된 시간 간격(`wait`)으로 제한하여, 불필요한 연속 업데이트를 방지합니다.\n *\n * @template T - 상태 값의 타입. 기본값은 `any`.\n * @param defaultValue - 초기 상태 값.\n * @param wait - 상태 업데이트 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `value`: 현재 상태 값.\n * - `setThrottledValue`: 상태를 쓰로틀링하여 업데이트하는 함수.\n *\n * @example\n * ```tsx\n * const [value, setValue] = useThrottledState(0, 1000);\n *\n * const handleClick = () => setValue(value + 1);\n *\n * return (\n * <div>\n * <p>값: {value}</p>\n * <button onClick={handleClick}>값 증가</button>\n * </div>\n * );\n * ```\n */\nexport function useThrottledState<T>(\n defaultValue: T, // 초기 상태 값\n wait: number, // 상태 업데이트 간격 (밀리초 단위)\n) {\n // 상태 값을 저장하는 state와 업데이트 함수\n const [value, setValue] = useState(defaultValue);\n\n // `setValue`를 쓰로틀링한 업데이트 함수와 타이머 정리 함수 생성\n const [setThrottledValue, clearTimeout] = useThrottledCallbackWithClearTimeout(setValue, wait);\n\n // 컴포넌트 언마운트 시 타이머를 정리\n //
|
|
1
|
+
{"version":3,"file":"useThrottledState.js","names":["useThrottledCallbackWithClearTimeout","useEffect","useState","useThrottledState","defaultValue","wait","value","setValue","setThrottledValue","clearTimeout"],"sources":["../../src/hooks/useThrottledState.ts"],"sourcesContent":["'use client';\n\n// copy from mantine\nimport { useEffect, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 쓰로틀링된 상태(state)와 상태를 업데이트하는 함수를 제공하는 React 커스텀 훅.\n *\n * 이 훅은 상태 업데이트를 지정된 시간 간격(`wait`)으로 제한하여, 불필요한 연속 업데이트를 방지합니다.\n *\n * @template T - 상태 값의 타입. 기본값은 `any`.\n * @param defaultValue - 초기 상태 값.\n * @param wait - 상태 업데이트 간격(밀리초 단위).\n * @returns 배열 형태의 반환값:\n * - `value`: 현재 상태 값.\n * - `setThrottledValue`: 상태를 쓰로틀링하여 업데이트하는 함수.\n *\n * @example\n * ```tsx\n * const [value, setValue] = useThrottledState(0, 1000);\n *\n * const handleClick = () => setValue(value + 1);\n *\n * return (\n * <div>\n * <p>값: {value}</p>\n * <button onClick={handleClick}>값 증가</button>\n * </div>\n * );\n * ```\n */\nexport function useThrottledState<T>(\n defaultValue: T, // 초기 상태 값\n wait: number, // 상태 업데이트 간격 (밀리초 단위)\n) {\n // 상태 값을 저장하는 state와 업데이트 함수\n const [value, setValue] = useState(defaultValue);\n\n // `setValue`를 쓰로틀링한 업데이트 함수와 타이머 정리 함수 생성\n const [setThrottledValue, clearTimeout] = useThrottledCallbackWithClearTimeout(setValue, wait);\n\n // 컴포넌트 언마운트 시 타이머를 정리\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n useEffect(() => clearTimeout, []);\n\n // 현재 상태 값과 쓰로틀링된 업데이트 함수 반환\n return [value, setThrottledValue] as const;\n}\n"],"mappings":"A,8JAgCA,SAAgBG,EACdC,EACAC,EACA,CAEA,GAAM,CAACC,EAAOC,GAAYL,EAASE,CAAY,EAGzC,CAACI,EAAmBC,GAAgBT,EAAqCO,EAAUF,CAAI,EAO7F,OAHAJ,MAAgBQ,EAAc,CAAC,CAAC,EAGzB,CAACH,EAAOE,CAAiB,CAClC,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledValue.cjs","names":["useState","useRef","useThrottledCallbackWithClearTimeout","useEffect","require_useThrottledCallbackWithClearTimeout","react","useThrottledValue","value","wait","throttledValue","setThrottledValue","valueRef","throttledSetValue","clearTimeout"],"sources":["../../src/hooks/useThrottledValue.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 값을 쓰로틀링하여 지정된 시간 간격(`wait`) 후에 최신 값을 반환하는 커스텀 React 훅.\n *\n * 이 훅은 입력 값(`value`)이 변경될 때마다, 지정된 `wait` 시간 간격으로 업데이트된 값을 제공합니다.\n *\n * @template T - 쓰로틀링할 값의 타입.\n * @param value - 쓰로틀링할 값.\n * @param wait - 값 업데이트 간격(밀리초 단위).\n * @returns 쓰로틀링된 값을 반환.\n *\n * @example\n * ```tsx\n * const throttledValue = useThrottledValue(inputValue, 500);\n *\n * return <p>쓰로틀링된 값: {throttledValue}</p>;\n * ```\n */\nexport function useThrottledValue<T>(value: T, wait: number) {\n // 쓰로틀링된 값을 저장하는 상태와 업데이트 함수\n const [throttledValue, setThrottledValue] = useState(value);\n\n // 최신 값을 저장하는 ref\n const valueRef = useRef(value);\n\n // 쓰로틀링된 업데이트 함수와 타이머 정리 함수 생성\n const [throttledSetValue, clearTimeout] = useThrottledCallbackWithClearTimeout(\n setThrottledValue,\n wait,\n );\n\n // 값이 변경되었을 때 쓰로틀링된 업데이트 실행\n useEffect(() => {\n if (value !== valueRef.current) {\n valueRef.current = value; // 최신 값을 ref에 저장\n throttledSetValue(value); // 쓰로틀링된 업데이트 함수 호출\n }\n }, [throttledSetValue, value]);\n\n // 컴포넌트 언마운트 시 타이머 정리\n //
|
|
1
|
+
{"version":3,"file":"useThrottledValue.cjs","names":["useState","useRef","useThrottledCallbackWithClearTimeout","useEffect","require_useThrottledCallbackWithClearTimeout","react","useThrottledValue","value","wait","throttledValue","setThrottledValue","valueRef","throttledSetValue","clearTimeout"],"sources":["../../src/hooks/useThrottledValue.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 값을 쓰로틀링하여 지정된 시간 간격(`wait`) 후에 최신 값을 반환하는 커스텀 React 훅.\n *\n * 이 훅은 입력 값(`value`)이 변경될 때마다, 지정된 `wait` 시간 간격으로 업데이트된 값을 제공합니다.\n *\n * @template T - 쓰로틀링할 값의 타입.\n * @param value - 쓰로틀링할 값.\n * @param wait - 값 업데이트 간격(밀리초 단위).\n * @returns 쓰로틀링된 값을 반환.\n *\n * @example\n * ```tsx\n * const throttledValue = useThrottledValue(inputValue, 500);\n *\n * return <p>쓰로틀링된 값: {throttledValue}</p>;\n * ```\n */\nexport function useThrottledValue<T>(value: T, wait: number) {\n // 쓰로틀링된 값을 저장하는 상태와 업데이트 함수\n const [throttledValue, setThrottledValue] = useState(value);\n\n // 최신 값을 저장하는 ref\n const valueRef = useRef(value);\n\n // 쓰로틀링된 업데이트 함수와 타이머 정리 함수 생성\n const [throttledSetValue, clearTimeout] = useThrottledCallbackWithClearTimeout(\n setThrottledValue,\n wait,\n );\n\n // 값이 변경되었을 때 쓰로틀링된 업데이트 실행\n useEffect(() => {\n if (value !== valueRef.current) {\n valueRef.current = value; // 최신 값을 ref에 저장\n throttledSetValue(value); // 쓰로틀링된 업데이트 함수 호출\n }\n }, [throttledSetValue, value]);\n\n // 컴포넌트 언마운트 시 타이머 정리\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n useEffect(() => clearTimeout, []);\n\n // 쓰로틀링된 값 반환\n return throttledValue;\n}\n"],"mappings":"A,kGAsBA,SAAgBM,EAAqBC,EAAUC,EAAc,CAE3D,GAAM,CAACC,EAAgBC,IAAA,EAAqBV,EAAAA,SAAAA,CAASO,CAAK,EAGpDI,GAAA,EAAWV,EAAAA,OAAAA,CAAOM,CAAK,EAGvB,CAACK,EAAmBC,GAAgBX,EAAAA,qCACxCQ,EACAF,CACF,EAeA,OAZAL,EAAAA,EAAAA,UAAAA,KAAgB,CACVI,IAAUI,EAAS,UACrBA,EAAS,QAAUJ,EACnBK,EAAkBL,CAAK,EAE3B,EAAG,CAACK,EAAmBL,CAAK,CAAC,GAI7BJ,EAAAA,EAAAA,UAAAA,KAAgBU,EAAc,CAAC,CAAC,EAGzBJ,CACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottledValue.js","names":["useThrottledCallbackWithClearTimeout","useEffect","useRef","useState","useThrottledValue","value","wait","throttledValue","setThrottledValue","valueRef","throttledSetValue","clearTimeout"],"sources":["../../src/hooks/useThrottledValue.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 값을 쓰로틀링하여 지정된 시간 간격(`wait`) 후에 최신 값을 반환하는 커스텀 React 훅.\n *\n * 이 훅은 입력 값(`value`)이 변경될 때마다, 지정된 `wait` 시간 간격으로 업데이트된 값을 제공합니다.\n *\n * @template T - 쓰로틀링할 값의 타입.\n * @param value - 쓰로틀링할 값.\n * @param wait - 값 업데이트 간격(밀리초 단위).\n * @returns 쓰로틀링된 값을 반환.\n *\n * @example\n * ```tsx\n * const throttledValue = useThrottledValue(inputValue, 500);\n *\n * return <p>쓰로틀링된 값: {throttledValue}</p>;\n * ```\n */\nexport function useThrottledValue<T>(value: T, wait: number) {\n // 쓰로틀링된 값을 저장하는 상태와 업데이트 함수\n const [throttledValue, setThrottledValue] = useState(value);\n\n // 최신 값을 저장하는 ref\n const valueRef = useRef(value);\n\n // 쓰로틀링된 업데이트 함수와 타이머 정리 함수 생성\n const [throttledSetValue, clearTimeout] = useThrottledCallbackWithClearTimeout(\n setThrottledValue,\n wait,\n );\n\n // 값이 변경되었을 때 쓰로틀링된 업데이트 실행\n useEffect(() => {\n if (value !== valueRef.current) {\n valueRef.current = value; // 최신 값을 ref에 저장\n throttledSetValue(value); // 쓰로틀링된 업데이트 함수 호출\n }\n }, [throttledSetValue, value]);\n\n // 컴포넌트 언마운트 시 타이머 정리\n //
|
|
1
|
+
{"version":3,"file":"useThrottledValue.js","names":["useThrottledCallbackWithClearTimeout","useEffect","useRef","useState","useThrottledValue","value","wait","throttledValue","setThrottledValue","valueRef","throttledSetValue","clearTimeout"],"sources":["../../src/hooks/useThrottledValue.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useState } from 'react';\nimport { useThrottledCallbackWithClearTimeout } from './useThrottledCallbackWithClearTimeout.js';\n\n/**\n * 주어진 값을 쓰로틀링하여 지정된 시간 간격(`wait`) 후에 최신 값을 반환하는 커스텀 React 훅.\n *\n * 이 훅은 입력 값(`value`)이 변경될 때마다, 지정된 `wait` 시간 간격으로 업데이트된 값을 제공합니다.\n *\n * @template T - 쓰로틀링할 값의 타입.\n * @param value - 쓰로틀링할 값.\n * @param wait - 값 업데이트 간격(밀리초 단위).\n * @returns 쓰로틀링된 값을 반환.\n *\n * @example\n * ```tsx\n * const throttledValue = useThrottledValue(inputValue, 500);\n *\n * return <p>쓰로틀링된 값: {throttledValue}</p>;\n * ```\n */\nexport function useThrottledValue<T>(value: T, wait: number) {\n // 쓰로틀링된 값을 저장하는 상태와 업데이트 함수\n const [throttledValue, setThrottledValue] = useState(value);\n\n // 최신 값을 저장하는 ref\n const valueRef = useRef(value);\n\n // 쓰로틀링된 업데이트 함수와 타이머 정리 함수 생성\n const [throttledSetValue, clearTimeout] = useThrottledCallbackWithClearTimeout(\n setThrottledValue,\n wait,\n );\n\n // 값이 변경되었을 때 쓰로틀링된 업데이트 실행\n useEffect(() => {\n if (value !== valueRef.current) {\n valueRef.current = value; // 최신 값을 ref에 저장\n throttledSetValue(value); // 쓰로틀링된 업데이트 함수 호출\n }\n }, [throttledSetValue, value]);\n\n // 컴포넌트 언마운트 시 타이머 정리\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n useEffect(() => clearTimeout, []);\n\n // 쓰로틀링된 값 반환\n return throttledValue;\n}\n"],"mappings":"A,0KAsBA,SAAgBI,EAAqBC,EAAUC,EAAc,CAE3D,GAAM,CAACC,EAAgBC,GAAqBL,EAASE,CAAK,EAGpDI,EAAWP,EAAOG,CAAK,EAGvB,CAACK,EAAmBC,GAAgBX,EACxCQ,EACAF,CACF,EAeA,OAZAL,MAAgB,CACVI,IAAUI,EAAS,UACrBA,EAAS,QAAUJ,EACnBK,EAAkBL,CAAK,EAE3B,EAAG,CAACK,EAAmBL,CAAK,CAAC,EAI7BJ,MAAgBU,EAAc,CAAC,CAAC,EAGzBJ,CACT,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdateEffect.cjs","names":["useRef","useEffect","react","useUpdateEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport const useUpdateEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n //
|
|
1
|
+
{"version":3,"file":"useUpdateEffect.cjs","names":["useRef","useEffect","react","useUpdateEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport const useUpdateEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n }, deps);\n};\n"],"mappings":"A,oCAKA,MAAaG,GAAmBC,EAAwBC,IAA0B,CAChF,IAAMC,GAAA,EAAYN,EAAAA,OAAAA,CAAO,EAAK,GAE9BC,EAAAA,EAAAA,UAAAA,SACe,CACXK,EAAU,QAAU,EACtB,EACC,CAAC,CAAC,GAELL,EAAAA,EAAAA,UAAAA,KAAgB,CACd,GAAI,CAACK,EAAU,QACbA,EAAU,QAAU,QAEpB,OAAOF,EAAO,CAGlB,EAAGC,CAAI,CACT,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdateEffect.js","names":["useEffect","useRef","useUpdateEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport const useUpdateEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n //
|
|
1
|
+
{"version":3,"file":"useUpdateEffect.js","names":["useEffect","useRef","useUpdateEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport const useUpdateEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n }, deps);\n};\n"],"mappings":"A,2DAKA,MAAaE,GAAmBC,EAAwBC,IAA0B,CAChF,IAAMC,EAAYJ,EAAO,EAAK,EAE9BD,UACe,CACXK,EAAU,QAAU,EACtB,EACC,CAAC,CAAC,EAELL,MAAgB,CACd,GAAI,CAACK,EAAU,QACbA,EAAU,QAAU,QAEpB,OAAOF,EAAO,CAGlB,EAAGC,CAAI,CACT,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdateLayoutEffect.cjs","names":["useRef","useLayoutEffect","react","useUpdateLayoutEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateLayoutEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useLayoutEffect, useRef } from 'react';\n\nexport const useUpdateLayoutEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useLayoutEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n //
|
|
1
|
+
{"version":3,"file":"useUpdateLayoutEffect.cjs","names":["useRef","useLayoutEffect","react","useUpdateLayoutEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateLayoutEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useLayoutEffect, useRef } from 'react';\n\nexport const useUpdateLayoutEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useLayoutEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n }, deps);\n};\n"],"mappings":"A,oCAKA,MAAaG,GAAyBC,EAAwBC,IAA0B,CACtF,IAAMC,GAAA,EAAYN,EAAAA,OAAAA,CAAO,EAAK,GAE9BC,EAAAA,EAAAA,gBAAAA,SACe,CACXK,EAAU,QAAU,EACtB,EACC,CAAC,CAAC,GAELL,EAAAA,EAAAA,gBAAAA,KAAsB,CACpB,GAAI,CAACK,EAAU,QACbA,EAAU,QAAU,QAEpB,OAAOF,EAAO,CAGlB,EAAGC,CAAI,CACT,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpdateLayoutEffect.js","names":["useLayoutEffect","useRef","useUpdateLayoutEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateLayoutEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useLayoutEffect, useRef } from 'react';\n\nexport const useUpdateLayoutEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useLayoutEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n //
|
|
1
|
+
{"version":3,"file":"useUpdateLayoutEffect.js","names":["useLayoutEffect","useRef","useUpdateLayoutEffect","effect","deps","isMounted"],"sources":["../../src/hooks/useUpdateLayoutEffect.ts"],"sourcesContent":["'use client';\n\nimport type { DependencyList, EffectCallback } from 'react';\nimport { useLayoutEffect, useRef } from 'react';\n\nexport const useUpdateLayoutEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const isMounted = useRef(false);\n\n useLayoutEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (!isMounted.current) {\n isMounted.current = true;\n } else {\n return effect();\n }\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- 기존 훅의 의도된 의존성 및 실행 시점 계약을 유지합니다.\n }, deps);\n};\n"],"mappings":"A,iEAKA,MAAaE,GAAyBC,EAAwBC,IAA0B,CACtF,IAAMC,EAAYJ,EAAO,EAAK,EAE9BD,UACe,CACXK,EAAU,QAAU,EACtB,EACC,CAAC,CAAC,EAELL,MAAsB,CACpB,GAAI,CAACK,EAAU,QACbA,EAAU,QAAU,QAEpB,OAAOF,EAAO,CAGlB,EAAGC,CAAI,CACT,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowEvent.cjs","names":["useEffect","react","useWindowEvent","type","listener","options"],"sources":["../../src/hooks/useWindowEvent.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\n\n/**\n * 지정된 타입의 윈도우 이벤트를 등록하고 관리하는 React 커스텀 훅.\n *\n * @template K - 이벤트 타입을 나타내는 문자열 타입.\n * @param type - 등록할 윈도우 이벤트의 타입(예: \"resize\", \"click\").\n * @param listener - 이벤트가 발생했을 때 실행될 콜백 함수.\n * - 표준 이벤트 타입(`WindowEventMap`)의 경우 타입에 맞는 이벤트 객체를 전달받음.\n * - 사용자 정의 이벤트의 경우 `CustomEvent` 객체를 전달받음.\n * @param options - 이벤트 리스너 등록 시 사용할 옵션(선택 사항).\n * - `boolean` 또는 `AddEventListenerOptions`를 지원.\n *\n * @example\n * ```tsx\n * useWindowEvent(\"resize\", () => {\n * console.log(\"창 크기가 변경되었습니다.\");\n * });\n * ```\n */\nexport function useWindowEvent<K extends string>(\n type: K, // 등록할 윈도우 이벤트의 타입\n listener: K extends keyof WindowEventMap\n ? (this: Window, ev: WindowEventMap[K]) => void // 표준 이벤트 타입에 맞는 리스너\n : (this: Window, ev: CustomEvent) => void, // 사용자 정의 이벤트 리스너\n options?: boolean | AddEventListenerOptions, // 이벤트 리스너 옵션\n) {\n // 이벤트 리스너 등록 및 정리\n
|
|
1
|
+
{"version":3,"file":"useWindowEvent.cjs","names":["useEffect","react","useWindowEvent","type","listener","options"],"sources":["../../src/hooks/useWindowEvent.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\n\n/**\n * 지정된 타입의 윈도우 이벤트를 등록하고 관리하는 React 커스텀 훅.\n *\n * @template K - 이벤트 타입을 나타내는 문자열 타입.\n * @param type - 등록할 윈도우 이벤트의 타입(예: \"resize\", \"click\").\n * @param listener - 이벤트가 발생했을 때 실행될 콜백 함수.\n * - 표준 이벤트 타입(`WindowEventMap`)의 경우 타입에 맞는 이벤트 객체를 전달받음.\n * - 사용자 정의 이벤트의 경우 `CustomEvent` 객체를 전달받음.\n * @param options - 이벤트 리스너 등록 시 사용할 옵션(선택 사항).\n * - `boolean` 또는 `AddEventListenerOptions`를 지원.\n *\n * @example\n * ```tsx\n * useWindowEvent(\"resize\", () => {\n * console.log(\"창 크기가 변경되었습니다.\");\n * });\n * ```\n */\nexport function useWindowEvent<K extends string>(\n type: K, // 등록할 윈도우 이벤트의 타입\n listener: K extends keyof WindowEventMap\n ? (this: Window, ev: WindowEventMap[K]) => void // 표준 이벤트 타입에 맞는 리스너\n : (this: Window, ev: CustomEvent) => void, // 사용자 정의 이벤트 리스너\n options?: boolean | AddEventListenerOptions, // 이벤트 리스너 옵션\n) {\n // 이벤트 리스너 등록 및 정리\n useEffect(() => {\n // 윈도우 이벤트 리스너 등록\n window.addEventListener(type, listener as EventListener, options);\n return () => {\n // 컴포넌트 언마운트 시 이벤트 리스너 제거\n window.removeEventListener(type, listener as EventListener, options);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [type, listener]); // 의존성: 이벤트 타입과 리스너\n}\n"],"mappings":"A,oCAsBA,SAAgBE,EACdC,EACAC,EAGAC,EACA,EAEAL,EAAAA,EAAAA,UAAAA,MAEE,OAAO,iBAAiBG,EAAMC,EAA2BC,CAAO,MACnD,CAEX,OAAO,oBAAoBF,EAAMC,EAA2BC,CAAO,CACrE,GAEC,CAACF,EAAMC,CAAQ,CAAC,CACrB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowEvent.js","names":["useEffect","useWindowEvent","type","listener","options"],"sources":["../../src/hooks/useWindowEvent.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\n\n/**\n * 지정된 타입의 윈도우 이벤트를 등록하고 관리하는 React 커스텀 훅.\n *\n * @template K - 이벤트 타입을 나타내는 문자열 타입.\n * @param type - 등록할 윈도우 이벤트의 타입(예: \"resize\", \"click\").\n * @param listener - 이벤트가 발생했을 때 실행될 콜백 함수.\n * - 표준 이벤트 타입(`WindowEventMap`)의 경우 타입에 맞는 이벤트 객체를 전달받음.\n * - 사용자 정의 이벤트의 경우 `CustomEvent` 객체를 전달받음.\n * @param options - 이벤트 리스너 등록 시 사용할 옵션(선택 사항).\n * - `boolean` 또는 `AddEventListenerOptions`를 지원.\n *\n * @example\n * ```tsx\n * useWindowEvent(\"resize\", () => {\n * console.log(\"창 크기가 변경되었습니다.\");\n * });\n * ```\n */\nexport function useWindowEvent<K extends string>(\n type: K, // 등록할 윈도우 이벤트의 타입\n listener: K extends keyof WindowEventMap\n ? (this: Window, ev: WindowEventMap[K]) => void // 표준 이벤트 타입에 맞는 리스너\n : (this: Window, ev: CustomEvent) => void, // 사용자 정의 이벤트 리스너\n options?: boolean | AddEventListenerOptions, // 이벤트 리스너 옵션\n) {\n // 이벤트 리스너 등록 및 정리\n
|
|
1
|
+
{"version":3,"file":"useWindowEvent.js","names":["useEffect","useWindowEvent","type","listener","options"],"sources":["../../src/hooks/useWindowEvent.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\n\n/**\n * 지정된 타입의 윈도우 이벤트를 등록하고 관리하는 React 커스텀 훅.\n *\n * @template K - 이벤트 타입을 나타내는 문자열 타입.\n * @param type - 등록할 윈도우 이벤트의 타입(예: \"resize\", \"click\").\n * @param listener - 이벤트가 발생했을 때 실행될 콜백 함수.\n * - 표준 이벤트 타입(`WindowEventMap`)의 경우 타입에 맞는 이벤트 객체를 전달받음.\n * - 사용자 정의 이벤트의 경우 `CustomEvent` 객체를 전달받음.\n * @param options - 이벤트 리스너 등록 시 사용할 옵션(선택 사항).\n * - `boolean` 또는 `AddEventListenerOptions`를 지원.\n *\n * @example\n * ```tsx\n * useWindowEvent(\"resize\", () => {\n * console.log(\"창 크기가 변경되었습니다.\");\n * });\n * ```\n */\nexport function useWindowEvent<K extends string>(\n type: K, // 등록할 윈도우 이벤트의 타입\n listener: K extends keyof WindowEventMap\n ? (this: Window, ev: WindowEventMap[K]) => void // 표준 이벤트 타입에 맞는 리스너\n : (this: Window, ev: CustomEvent) => void, // 사용자 정의 이벤트 리스너\n options?: boolean | AddEventListenerOptions, // 이벤트 리스너 옵션\n) {\n // 이벤트 리스너 등록 및 정리\n useEffect(() => {\n // 윈도우 이벤트 리스너 등록\n window.addEventListener(type, listener as EventListener, options);\n return () => {\n // 컴포넌트 언마운트 시 이벤트 리스너 제거\n window.removeEventListener(type, listener as EventListener, options);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [type, listener]); // 의존성: 이벤트 타입과 리스너\n}\n"],"mappings":"A,+CAsBA,SAAgBC,EACdC,EACAC,EAGAC,EACA,CAEAJ,OAEE,OAAO,iBAAiBE,EAAMC,EAA2BC,CAAO,MACnD,CAEX,OAAO,oBAAoBF,EAAMC,EAA2BC,CAAO,CACrE,GAEC,CAACF,EAAMC,CAAQ,CAAC,CACrB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.cjs","names":["useRafState","isBrowser","useEffect","require_misc_utils","require_useRafState","react","useWindowSize","initialWidth","initialHeight","onChange","state","setState","handler","width","height"],"sources":["../../src/hooks/useWindowSize.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { isBrowser } from '../util/misc-utils.js';\nimport { useRafState } from './useRafState.js';\n\n// Define the type for options that can be passed to the hook\ninterface Options {\n initialWidth?: number; // Initial width of the window (Default value is Infinity)\n initialHeight?: number; // Initial height of the window (Default value is Infinity)\n onChange?: (width: number, height: number) => void; // Callback function to execute on window resize (optional)\n}\n\nexport const useWindowSize = ({\n initialWidth = Infinity,\n initialHeight = Infinity,\n onChange,\n}: Options = {}) => {\n // Use the useRafState hook to maintain the current window size (width and height)\n const [state, setState] = useRafState<{ width: number; height: number }>({\n width: isBrowser ? window.innerWidth : initialWidth,\n height: isBrowser ? window.innerHeight : initialHeight,\n });\n\n
|
|
1
|
+
{"version":3,"file":"useWindowSize.cjs","names":["useRafState","isBrowser","useEffect","require_misc_utils","require_useRafState","react","useWindowSize","initialWidth","initialHeight","onChange","state","setState","handler","width","height"],"sources":["../../src/hooks/useWindowSize.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { isBrowser } from '../util/misc-utils.js';\nimport { useRafState } from './useRafState.js';\n\n// Define the type for options that can be passed to the hook\ninterface Options {\n initialWidth?: number; // Initial width of the window (Default value is Infinity)\n initialHeight?: number; // Initial height of the window (Default value is Infinity)\n onChange?: (width: number, height: number) => void; // Callback function to execute on window resize (optional)\n}\n\nexport const useWindowSize = ({\n initialWidth = Infinity,\n initialHeight = Infinity,\n onChange,\n}: Options = {}) => {\n // Use the useRafState hook to maintain the current window size (width and height)\n const [state, setState] = useRafState<{ width: number; height: number }>({\n width: isBrowser ? window.innerWidth : initialWidth,\n height: isBrowser ? window.innerHeight : initialHeight,\n });\n\n useEffect((): (() => void) | undefined => {\n // Only run the effect on the browser (to avoid issues with SSR)\n if (isBrowser) {\n const handler = () => {\n const width = window.innerWidth;\n const height = window.innerHeight;\n\n // Update the state with the new window size\n setState({\n width,\n height,\n });\n\n // If an onChange callback is provided, call it with the new dimensions\n if (onChange) onChange(width, height);\n };\n\n // Add event listener for the resize event\n window.addEventListener('resize', handler);\n\n // Cleanup function to remove the event listener when the component is unmounted (it's for performance optimization)\n return () => {\n window.removeEventListener('resize', handler);\n };\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Return the current window size (width and height)\n return state;\n};\n"],"mappings":"A,6GAaA,MAAaM,GAAiB,CAC5BC,eAAe,IACfC,gBAAgB,IAChBC,YACW,CAAC,IAAM,CAElB,GAAM,CAACC,EAAOC,GAAYX,EAAAA,YAA+C,CACvE,MAAOC,EAAAA,UAAY,OAAO,WAAaM,EACvC,OAAQN,EAAAA,UAAY,OAAO,YAAcO,CAC3C,CAAC,EA+BD,OA7BAN,EAAAA,EAAAA,UAAAA,KAA0C,CAExC,GAAID,EAAAA,UAAW,CACb,IAAMW,MAAgB,CACpB,IAAMC,EAAQ,OAAO,WACfC,EAAS,OAAO,YAGtBH,EAAS,CACPE,QACAC,QACF,CAAC,EAGGL,GAAUA,EAASI,EAAOC,CAAM,CACtC,EAMA,OAHA,OAAO,iBAAiB,SAAUF,CAAO,MAG5B,CACX,OAAO,oBAAoB,SAAUA,CAAO,CAC9C,CACF,CAEF,EAAG,CAAC,CAAC,EAGEF,CACT,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.js","names":["isBrowser","useRafState","useEffect","useWindowSize","initialWidth","initialHeight","onChange","state","setState","handler","width","height"],"sources":["../../src/hooks/useWindowSize.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { isBrowser } from '../util/misc-utils.js';\nimport { useRafState } from './useRafState.js';\n\n// Define the type for options that can be passed to the hook\ninterface Options {\n initialWidth?: number; // Initial width of the window (Default value is Infinity)\n initialHeight?: number; // Initial height of the window (Default value is Infinity)\n onChange?: (width: number, height: number) => void; // Callback function to execute on window resize (optional)\n}\n\nexport const useWindowSize = ({\n initialWidth = Infinity,\n initialHeight = Infinity,\n onChange,\n}: Options = {}) => {\n // Use the useRafState hook to maintain the current window size (width and height)\n const [state, setState] = useRafState<{ width: number; height: number }>({\n width: isBrowser ? window.innerWidth : initialWidth,\n height: isBrowser ? window.innerHeight : initialHeight,\n });\n\n
|
|
1
|
+
{"version":3,"file":"useWindowSize.js","names":["isBrowser","useRafState","useEffect","useWindowSize","initialWidth","initialHeight","onChange","state","setState","handler","width","height"],"sources":["../../src/hooks/useWindowSize.ts"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { isBrowser } from '../util/misc-utils.js';\nimport { useRafState } from './useRafState.js';\n\n// Define the type for options that can be passed to the hook\ninterface Options {\n initialWidth?: number; // Initial width of the window (Default value is Infinity)\n initialHeight?: number; // Initial height of the window (Default value is Infinity)\n onChange?: (width: number, height: number) => void; // Callback function to execute on window resize (optional)\n}\n\nexport const useWindowSize = ({\n initialWidth = Infinity,\n initialHeight = Infinity,\n onChange,\n}: Options = {}) => {\n // Use the useRafState hook to maintain the current window size (width and height)\n const [state, setState] = useRafState<{ width: number; height: number }>({\n width: isBrowser ? window.innerWidth : initialWidth,\n height: isBrowser ? window.innerHeight : initialHeight,\n });\n\n useEffect((): (() => void) | undefined => {\n // Only run the effect on the browser (to avoid issues with SSR)\n if (isBrowser) {\n const handler = () => {\n const width = window.innerWidth;\n const height = window.innerHeight;\n\n // Update the state with the new window size\n setState({\n width,\n height,\n });\n\n // If an onChange callback is provided, call it with the new dimensions\n if (onChange) onChange(width, height);\n };\n\n // Add event listener for the resize event\n window.addEventListener('resize', handler);\n\n // Cleanup function to remove the event listener when the component is unmounted (it's for performance optimization)\n return () => {\n window.removeEventListener('resize', handler);\n };\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Return the current window size (width and height)\n return state;\n};\n"],"mappings":"A,gJAaA,MAAaG,GAAiB,CAC5BC,eAAe,IACfC,gBAAgB,IAChBC,YACW,CAAC,IAAM,CAElB,GAAM,CAACC,EAAOC,GAAYP,EAA+C,CACvE,MAAOD,EAAY,OAAO,WAAaI,EACvC,OAAQJ,EAAY,OAAO,YAAcK,CAC3C,CAAC,EA+BD,OA7BAH,MAA0C,CAExC,GAAIF,EAAW,CACb,IAAMS,MAAgB,CACpB,IAAMC,EAAQ,OAAO,WACfC,EAAS,OAAO,YAGtBH,EAAS,CACPE,QACAC,QACF,CAAC,EAGGL,GAAUA,EAASI,EAAOC,CAAM,CACtC,EAMA,OAHA,OAAO,iBAAiB,SAAUF,CAAO,MAG5B,CACX,OAAO,oBAAoB,SAAUA,CAAO,CAC9C,CACF,CAEF,EAAG,CAAC,CAAC,EAGEF,CACT,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorageState.cjs","names":["CODEC_STRING","useState","useMemo","useCallback","useSyncExternalStore","require_codec","react","currentTabChangeListeners","onCurrentTabStorageChange","key","handler","listeners","offCurrentTabStorageChange","emitCurrentTabStorageChange","listener","origSetItem","value","result","subscribe","area","callback","storageHandler","event","getSnapshot","setValue","serverValue","useStorageStateServer","encode","codec","decode","getKeyServerSnapshot","useStorageState","initializer","options","initialValue","encodedInitialValue","subscribeKey","getKeySnapshot","encodedStoredValue","storedValue","setStoredValue","valueToStore","nonStoredValue","setNonStoredValue"],"sources":["../../src/persistence/useStorageState.tsx"],"sourcesContent":["'use client';\n\nimport type { Dispatch, SetStateAction } from 'react';\nimport { useCallback, useMemo, useState, useSyncExternalStore } from 'react';\nimport type { Codec } from './codec.js';\nimport { CODEC_STRING } from './codec.js';\n\n// storage events only work across tabs, we'll use an event emitter to announce within the current tab\nconst currentTabChangeListeners = new Map<string, Set<() => void>>();\n\nfunction onCurrentTabStorageChange(key: string, handler: () => void) {\n let listeners = currentTabChangeListeners.get(key);\n\n if (!listeners) {\n listeners = new Set();\n currentTabChangeListeners.set(key, listeners);\n }\n\n listeners.add(handler);\n}\n\nfunction offCurrentTabStorageChange(key: string, handler: () => void) {\n const listeners = currentTabChangeListeners.get(key);\n if (!listeners) {\n return;\n }\n\n listeners.delete(handler);\n\n if (listeners.size === 0) {\n currentTabChangeListeners.delete(key);\n }\n}\n\nfunction emitCurrentTabStorageChange(key: string) {\n const listeners = currentTabChangeListeners.get(key);\n if (listeners) {\n listeners.forEach((listener) => {\n listener();\n });\n }\n}\n\nif (typeof window !== 'undefined') {\n const origSetItem = window.localStorage.setItem;\n window.localStorage.setItem = function setItem(key, value) {\n const result = origSetItem.call(this, key, value);\n emitCurrentTabStorageChange(key);\n return result;\n };\n}\n\nfunction subscribe(area: Storage, key: string | null, callback: () => void): () => void {\n if (!key) {\n return () => {};\n }\n const storageHandler = (event: StorageEvent) => {\n if (event.storageArea === area && event.key === key) {\n callback();\n }\n };\n window.addEventListener('storage', storageHandler);\n onCurrentTabStorageChange(key, callback);\n return () => {\n window.removeEventListener('storage', storageHandler);\n offCurrentTabStorageChange(key, callback);\n };\n}\n\nfunction getSnapshot(area: Storage, key: string | null): string | null {\n if (!key) {\n return null;\n }\n try {\n return area.getItem(key);\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return null;\n }\n}\n\nfunction setValue(area: Storage, key: string | null, value: string | null) {\n if (!key) {\n return;\n }\n try {\n if (value === null) {\n area.removeItem(key);\n } else {\n area.setItem(key, String(value));\n }\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return;\n }\n emitCurrentTabStorageChange(key);\n}\n\nexport type StorageStateInitializer<T> = () => T | null;\n\nexport type UseStorageStateHookResult<T> = [T | null, Dispatch<SetStateAction<T | null>>];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst serverValue: UseStorageStateHookResult<any> = [null, () => {}];\n\nexport function useStorageStateServer<T = string>(): UseStorageStateHookResult<T> {\n return serverValue;\n}\n\nexport interface DefaultStorageStateoptions<T = string> {\n codec?: Codec<T>;\n}\n\nexport interface StorageStateOptions<T> extends DefaultStorageStateoptions<T> {\n codec: Codec<T>;\n}\n\nfunction encode<V>(codec: Codec<V>, value: V | null): string | null {\n return value === null ? null : codec.stringify(value);\n}\n\nfunction decode<V>(codec: Codec<V>, value: string | null): V | null {\n return value === null ? null : codec.parse(value);\n}\n\n// Start with null for the hydration, and then switch to the actual value.\nconst getKeyServerSnapshot = () => null;\n\n/**\n * Sync state to local storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\nexport function useStorageState(\n area: Storage,\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n): UseStorageStateHookResult<string>;\n\nexport function useStorageState<T>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n): UseStorageStateHookResult<T>;\n\nexport function useStorageState<T = string>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T> = null,\n options?: DefaultStorageStateoptions | StorageStateOptions<T>,\n): UseStorageStateHookResult<T> {\n const codec = (options?.codec ?? CODEC_STRING) as Codec<T>;\n\n const [initialValue] = useState(initializer);\n const encodedInitialValue = useMemo(() => encode(codec, initialValue), [codec, initialValue]);\n\n const subscribeKey = useCallback(\n (callback: () => void) => subscribe(area, key, callback),\n [area, key],\n );\n\n const getKeySnapshot = useCallback<() => string | null>(\n () => getSnapshot(area, key) ?? encodedInitialValue,\n [area, encodedInitialValue, key],\n );\n\n const encodedStoredValue = useSyncExternalStore(\n subscribeKey,\n getKeySnapshot,\n getKeyServerSnapshot,\n );\n\n const storedValue = useMemo(() => decode(codec, encodedStoredValue), [codec, encodedStoredValue]);\n\n const setStoredValue = useCallback(\n (value: SetStateAction<T | null>) => {\n const valueToStore = value instanceof Function ? value(storedValue) : value;\n const encodedValueToStore = encode(codec, valueToStore);\n setValue(area, key, encodedValueToStore);\n },\n [area, codec, storedValue, key],\n );\n\n const [nonStoredValue, setNonStoredValue] = useState(initialValue);\n\n if (!key) {\n return [nonStoredValue, setNonStoredValue];\n }\n\n return [storedValue, setStoredValue];\n}\n\nexport interface UseStorageState {\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n (\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n ): UseStorageStateHookResult<string>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer?: T | null | StorageStateInitializer<T>,\n options?: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useStorageState.cjs","names":["CODEC_STRING","useState","useMemo","useCallback","useSyncExternalStore","require_codec","react","currentTabChangeListeners","onCurrentTabStorageChange","key","handler","listeners","offCurrentTabStorageChange","emitCurrentTabStorageChange","listener","origSetItem","value","result","subscribe","area","callback","storageHandler","event","getSnapshot","setValue","serverValue","useStorageStateServer","encode","codec","decode","getKeyServerSnapshot","useStorageState","initializer","options","initialValue","encodedInitialValue","subscribeKey","getKeySnapshot","encodedStoredValue","storedValue","setStoredValue","valueToStore","nonStoredValue","setNonStoredValue"],"sources":["../../src/persistence/useStorageState.tsx"],"sourcesContent":["'use client';\n\nimport type { Dispatch, SetStateAction } from 'react';\nimport { useCallback, useMemo, useState, useSyncExternalStore } from 'react';\nimport type { Codec } from './codec.js';\nimport { CODEC_STRING } from './codec.js';\n\n// storage events only work across tabs, we'll use an event emitter to announce within the current tab\nconst currentTabChangeListeners = new Map<string, Set<() => void>>();\n\nfunction onCurrentTabStorageChange(key: string, handler: () => void) {\n let listeners = currentTabChangeListeners.get(key);\n\n if (!listeners) {\n listeners = new Set();\n currentTabChangeListeners.set(key, listeners);\n }\n\n listeners.add(handler);\n}\n\nfunction offCurrentTabStorageChange(key: string, handler: () => void) {\n const listeners = currentTabChangeListeners.get(key);\n if (!listeners) {\n return;\n }\n\n listeners.delete(handler);\n\n if (listeners.size === 0) {\n currentTabChangeListeners.delete(key);\n }\n}\n\nfunction emitCurrentTabStorageChange(key: string) {\n const listeners = currentTabChangeListeners.get(key);\n if (listeners) {\n listeners.forEach((listener) => {\n listener();\n });\n }\n}\n\nif (typeof window !== 'undefined') {\n const origSetItem = window.localStorage.setItem;\n window.localStorage.setItem = function setItem(key, value) {\n const result = origSetItem.call(this, key, value);\n emitCurrentTabStorageChange(key);\n return result;\n };\n}\n\nfunction subscribe(area: Storage, key: string | null, callback: () => void): () => void {\n if (!key) {\n return () => {};\n }\n const storageHandler = (event: StorageEvent) => {\n if (event.storageArea === area && event.key === key) {\n callback();\n }\n };\n window.addEventListener('storage', storageHandler);\n onCurrentTabStorageChange(key, callback);\n return () => {\n window.removeEventListener('storage', storageHandler);\n offCurrentTabStorageChange(key, callback);\n };\n}\n\nfunction getSnapshot(area: Storage, key: string | null): string | null {\n if (!key) {\n return null;\n }\n try {\n return area.getItem(key);\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return null;\n }\n}\n\nfunction setValue(area: Storage, key: string | null, value: string | null) {\n if (!key) {\n return;\n }\n try {\n if (value === null) {\n area.removeItem(key);\n } else {\n area.setItem(key, String(value));\n }\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return;\n }\n emitCurrentTabStorageChange(key);\n}\n\nexport type StorageStateInitializer<T> = () => T | null;\n\nexport type UseStorageStateHookResult<T> = [T | null, Dispatch<SetStateAction<T | null>>];\n\nconst serverValue: UseStorageStateHookResult<any> = [null, () => {}];\n\nexport function useStorageStateServer<T = string>(): UseStorageStateHookResult<T> {\n return serverValue;\n}\n\nexport interface DefaultStorageStateoptions<T = string> {\n codec?: Codec<T>;\n}\n\nexport interface StorageStateOptions<T> extends DefaultStorageStateoptions<T> {\n codec: Codec<T>;\n}\n\nfunction encode<V>(codec: Codec<V>, value: V | null): string | null {\n return value === null ? null : codec.stringify(value);\n}\n\nfunction decode<V>(codec: Codec<V>, value: string | null): V | null {\n return value === null ? null : codec.parse(value);\n}\n\n// Start with null for the hydration, and then switch to the actual value.\nconst getKeyServerSnapshot = () => null;\n\n/**\n * Sync state to local storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\nexport function useStorageState(\n area: Storage,\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n): UseStorageStateHookResult<string>;\n\nexport function useStorageState<T>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n): UseStorageStateHookResult<T>;\n\nexport function useStorageState<T = string>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T> = null,\n options?: DefaultStorageStateoptions | StorageStateOptions<T>,\n): UseStorageStateHookResult<T> {\n const codec = (options?.codec ?? CODEC_STRING) as Codec<T>;\n\n const [initialValue] = useState(initializer);\n const encodedInitialValue = useMemo(() => encode(codec, initialValue), [codec, initialValue]);\n\n const subscribeKey = useCallback(\n (callback: () => void) => subscribe(area, key, callback),\n [area, key],\n );\n\n const getKeySnapshot = useCallback<() => string | null>(\n () => getSnapshot(area, key) ?? encodedInitialValue,\n [area, encodedInitialValue, key],\n );\n\n const encodedStoredValue = useSyncExternalStore(\n subscribeKey,\n getKeySnapshot,\n getKeyServerSnapshot,\n );\n\n const storedValue = useMemo(() => decode(codec, encodedStoredValue), [codec, encodedStoredValue]);\n\n const setStoredValue = useCallback(\n (value: SetStateAction<T | null>) => {\n const valueToStore = value instanceof Function ? value(storedValue) : value;\n const encodedValueToStore = encode(codec, valueToStore);\n setValue(area, key, encodedValueToStore);\n },\n [area, codec, storedValue, key],\n );\n\n const [nonStoredValue, setNonStoredValue] = useState(initialValue);\n\n if (!key) {\n return [nonStoredValue, setNonStoredValue];\n }\n\n return [storedValue, setStoredValue];\n}\n\nexport interface UseStorageState {\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n (\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n ): UseStorageStateHookResult<string>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer?: T | null | StorageStateInitializer<T>,\n options?: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorageState.js","names":["CODEC_STRING","useCallback","useMemo","useState","useSyncExternalStore","currentTabChangeListeners","onCurrentTabStorageChange","key","handler","listeners","offCurrentTabStorageChange","emitCurrentTabStorageChange","listener","origSetItem","value","result","subscribe","area","callback","storageHandler","event","getSnapshot","setValue","serverValue","useStorageStateServer","encode","codec","decode","getKeyServerSnapshot","useStorageState","initializer","options","initialValue","encodedInitialValue","subscribeKey","getKeySnapshot","encodedStoredValue","storedValue","setStoredValue","valueToStore","nonStoredValue","setNonStoredValue"],"sources":["../../src/persistence/useStorageState.tsx"],"sourcesContent":["'use client';\n\nimport type { Dispatch, SetStateAction } from 'react';\nimport { useCallback, useMemo, useState, useSyncExternalStore } from 'react';\nimport type { Codec } from './codec.js';\nimport { CODEC_STRING } from './codec.js';\n\n// storage events only work across tabs, we'll use an event emitter to announce within the current tab\nconst currentTabChangeListeners = new Map<string, Set<() => void>>();\n\nfunction onCurrentTabStorageChange(key: string, handler: () => void) {\n let listeners = currentTabChangeListeners.get(key);\n\n if (!listeners) {\n listeners = new Set();\n currentTabChangeListeners.set(key, listeners);\n }\n\n listeners.add(handler);\n}\n\nfunction offCurrentTabStorageChange(key: string, handler: () => void) {\n const listeners = currentTabChangeListeners.get(key);\n if (!listeners) {\n return;\n }\n\n listeners.delete(handler);\n\n if (listeners.size === 0) {\n currentTabChangeListeners.delete(key);\n }\n}\n\nfunction emitCurrentTabStorageChange(key: string) {\n const listeners = currentTabChangeListeners.get(key);\n if (listeners) {\n listeners.forEach((listener) => {\n listener();\n });\n }\n}\n\nif (typeof window !== 'undefined') {\n const origSetItem = window.localStorage.setItem;\n window.localStorage.setItem = function setItem(key, value) {\n const result = origSetItem.call(this, key, value);\n emitCurrentTabStorageChange(key);\n return result;\n };\n}\n\nfunction subscribe(area: Storage, key: string | null, callback: () => void): () => void {\n if (!key) {\n return () => {};\n }\n const storageHandler = (event: StorageEvent) => {\n if (event.storageArea === area && event.key === key) {\n callback();\n }\n };\n window.addEventListener('storage', storageHandler);\n onCurrentTabStorageChange(key, callback);\n return () => {\n window.removeEventListener('storage', storageHandler);\n offCurrentTabStorageChange(key, callback);\n };\n}\n\nfunction getSnapshot(area: Storage, key: string | null): string | null {\n if (!key) {\n return null;\n }\n try {\n return area.getItem(key);\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return null;\n }\n}\n\nfunction setValue(area: Storage, key: string | null, value: string | null) {\n if (!key) {\n return;\n }\n try {\n if (value === null) {\n area.removeItem(key);\n } else {\n area.setItem(key, String(value));\n }\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return;\n }\n emitCurrentTabStorageChange(key);\n}\n\nexport type StorageStateInitializer<T> = () => T | null;\n\nexport type UseStorageStateHookResult<T> = [T | null, Dispatch<SetStateAction<T | null>>];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst serverValue: UseStorageStateHookResult<any> = [null, () => {}];\n\nexport function useStorageStateServer<T = string>(): UseStorageStateHookResult<T> {\n return serverValue;\n}\n\nexport interface DefaultStorageStateoptions<T = string> {\n codec?: Codec<T>;\n}\n\nexport interface StorageStateOptions<T> extends DefaultStorageStateoptions<T> {\n codec: Codec<T>;\n}\n\nfunction encode<V>(codec: Codec<V>, value: V | null): string | null {\n return value === null ? null : codec.stringify(value);\n}\n\nfunction decode<V>(codec: Codec<V>, value: string | null): V | null {\n return value === null ? null : codec.parse(value);\n}\n\n// Start with null for the hydration, and then switch to the actual value.\nconst getKeyServerSnapshot = () => null;\n\n/**\n * Sync state to local storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\nexport function useStorageState(\n area: Storage,\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n): UseStorageStateHookResult<string>;\n\nexport function useStorageState<T>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n): UseStorageStateHookResult<T>;\n\nexport function useStorageState<T = string>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T> = null,\n options?: DefaultStorageStateoptions | StorageStateOptions<T>,\n): UseStorageStateHookResult<T> {\n const codec = (options?.codec ?? CODEC_STRING) as Codec<T>;\n\n const [initialValue] = useState(initializer);\n const encodedInitialValue = useMemo(() => encode(codec, initialValue), [codec, initialValue]);\n\n const subscribeKey = useCallback(\n (callback: () => void) => subscribe(area, key, callback),\n [area, key],\n );\n\n const getKeySnapshot = useCallback<() => string | null>(\n () => getSnapshot(area, key) ?? encodedInitialValue,\n [area, encodedInitialValue, key],\n );\n\n const encodedStoredValue = useSyncExternalStore(\n subscribeKey,\n getKeySnapshot,\n getKeyServerSnapshot,\n );\n\n const storedValue = useMemo(() => decode(codec, encodedStoredValue), [codec, encodedStoredValue]);\n\n const setStoredValue = useCallback(\n (value: SetStateAction<T | null>) => {\n const valueToStore = value instanceof Function ? value(storedValue) : value;\n const encodedValueToStore = encode(codec, valueToStore);\n setValue(area, key, encodedValueToStore);\n },\n [area, codec, storedValue, key],\n );\n\n const [nonStoredValue, setNonStoredValue] = useState(initialValue);\n\n if (!key) {\n return [nonStoredValue, setNonStoredValue];\n }\n\n return [storedValue, setStoredValue];\n}\n\nexport interface UseStorageState {\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n (\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n ): UseStorageStateHookResult<string>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer?: T | null | StorageStateInitializer<T>,\n options?: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useStorageState.js","names":["CODEC_STRING","useCallback","useMemo","useState","useSyncExternalStore","currentTabChangeListeners","onCurrentTabStorageChange","key","handler","listeners","offCurrentTabStorageChange","emitCurrentTabStorageChange","listener","origSetItem","value","result","subscribe","area","callback","storageHandler","event","getSnapshot","setValue","serverValue","useStorageStateServer","encode","codec","decode","getKeyServerSnapshot","useStorageState","initializer","options","initialValue","encodedInitialValue","subscribeKey","getKeySnapshot","encodedStoredValue","storedValue","setStoredValue","valueToStore","nonStoredValue","setNonStoredValue"],"sources":["../../src/persistence/useStorageState.tsx"],"sourcesContent":["'use client';\n\nimport type { Dispatch, SetStateAction } from 'react';\nimport { useCallback, useMemo, useState, useSyncExternalStore } from 'react';\nimport type { Codec } from './codec.js';\nimport { CODEC_STRING } from './codec.js';\n\n// storage events only work across tabs, we'll use an event emitter to announce within the current tab\nconst currentTabChangeListeners = new Map<string, Set<() => void>>();\n\nfunction onCurrentTabStorageChange(key: string, handler: () => void) {\n let listeners = currentTabChangeListeners.get(key);\n\n if (!listeners) {\n listeners = new Set();\n currentTabChangeListeners.set(key, listeners);\n }\n\n listeners.add(handler);\n}\n\nfunction offCurrentTabStorageChange(key: string, handler: () => void) {\n const listeners = currentTabChangeListeners.get(key);\n if (!listeners) {\n return;\n }\n\n listeners.delete(handler);\n\n if (listeners.size === 0) {\n currentTabChangeListeners.delete(key);\n }\n}\n\nfunction emitCurrentTabStorageChange(key: string) {\n const listeners = currentTabChangeListeners.get(key);\n if (listeners) {\n listeners.forEach((listener) => {\n listener();\n });\n }\n}\n\nif (typeof window !== 'undefined') {\n const origSetItem = window.localStorage.setItem;\n window.localStorage.setItem = function setItem(key, value) {\n const result = origSetItem.call(this, key, value);\n emitCurrentTabStorageChange(key);\n return result;\n };\n}\n\nfunction subscribe(area: Storage, key: string | null, callback: () => void): () => void {\n if (!key) {\n return () => {};\n }\n const storageHandler = (event: StorageEvent) => {\n if (event.storageArea === area && event.key === key) {\n callback();\n }\n };\n window.addEventListener('storage', storageHandler);\n onCurrentTabStorageChange(key, callback);\n return () => {\n window.removeEventListener('storage', storageHandler);\n offCurrentTabStorageChange(key, callback);\n };\n}\n\nfunction getSnapshot(area: Storage, key: string | null): string | null {\n if (!key) {\n return null;\n }\n try {\n return area.getItem(key);\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return null;\n }\n}\n\nfunction setValue(area: Storage, key: string | null, value: string | null) {\n if (!key) {\n return;\n }\n try {\n if (value === null) {\n area.removeItem(key);\n } else {\n area.setItem(key, String(value));\n }\n } catch {\n // ignore\n // See https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage\n return;\n }\n emitCurrentTabStorageChange(key);\n}\n\nexport type StorageStateInitializer<T> = () => T | null;\n\nexport type UseStorageStateHookResult<T> = [T | null, Dispatch<SetStateAction<T | null>>];\n\nconst serverValue: UseStorageStateHookResult<any> = [null, () => {}];\n\nexport function useStorageStateServer<T = string>(): UseStorageStateHookResult<T> {\n return serverValue;\n}\n\nexport interface DefaultStorageStateoptions<T = string> {\n codec?: Codec<T>;\n}\n\nexport interface StorageStateOptions<T> extends DefaultStorageStateoptions<T> {\n codec: Codec<T>;\n}\n\nfunction encode<V>(codec: Codec<V>, value: V | null): string | null {\n return value === null ? null : codec.stringify(value);\n}\n\nfunction decode<V>(codec: Codec<V>, value: string | null): V | null {\n return value === null ? null : codec.parse(value);\n}\n\n// Start with null for the hydration, and then switch to the actual value.\nconst getKeyServerSnapshot = () => null;\n\n/**\n * Sync state to local storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key so that we can default\n * to that value on page load instead of the specified initial value.\n *\n * Since the storage API isn't available in server-rendering environments, we\n * return null during SSR and hydration.\n */\nexport function useStorageState(\n area: Storage,\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n): UseStorageStateHookResult<string>;\n\nexport function useStorageState<T>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n): UseStorageStateHookResult<T>;\n\nexport function useStorageState<T = string>(\n area: Storage,\n key: string | null,\n initializer: T | null | StorageStateInitializer<T> = null,\n options?: DefaultStorageStateoptions | StorageStateOptions<T>,\n): UseStorageStateHookResult<T> {\n const codec = (options?.codec ?? CODEC_STRING) as Codec<T>;\n\n const [initialValue] = useState(initializer);\n const encodedInitialValue = useMemo(() => encode(codec, initialValue), [codec, initialValue]);\n\n const subscribeKey = useCallback(\n (callback: () => void) => subscribe(area, key, callback),\n [area, key],\n );\n\n const getKeySnapshot = useCallback<() => string | null>(\n () => getSnapshot(area, key) ?? encodedInitialValue,\n [area, encodedInitialValue, key],\n );\n\n const encodedStoredValue = useSyncExternalStore(\n subscribeKey,\n getKeySnapshot,\n getKeyServerSnapshot,\n );\n\n const storedValue = useMemo(() => decode(codec, encodedStoredValue), [codec, encodedStoredValue]);\n\n const setStoredValue = useCallback(\n (value: SetStateAction<T | null>) => {\n const valueToStore = value instanceof Function ? value(storedValue) : value;\n const encodedValueToStore = encode(codec, valueToStore);\n setValue(area, key, encodedValueToStore);\n },\n [area, codec, storedValue, key],\n );\n\n const [nonStoredValue, setNonStoredValue] = useState(initialValue);\n\n if (!key) {\n return [nonStoredValue, setNonStoredValue];\n }\n\n return [storedValue, setStoredValue];\n}\n\nexport interface UseStorageState {\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n (\n key: string | null,\n initializer?: string | null | StorageStateInitializer<string>,\n options?: DefaultStorageStateoptions,\n ): UseStorageStateHookResult<string>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer: T | null | StorageStateInitializer<T>,\n options: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n\n /**\n * Sync state to local or session storage so that it persists through a page refresh. Usage is\n * similar to useState except we pass in a storage key that uniquely identifies the value.\n * @param key The key to use for storing the value in local or session storage.\n * @param initializer The initial value to use if the key is not present in storage.\n * @param options Additional options for the storage state.\n */\n <T>(\n key: string | null,\n initializer?: T | null | StorageStateInitializer<T>,\n options?: StorageStateOptions<T>,\n ): UseStorageStateHookResult<T>;\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-utils.cjs","names":["isTabKeyEvent","isEnterOrTabKeyEvent","isEnterKeyEvent","isEscapeKeyEvent","isTouchEvent","event","isMouseEvent","blurEventTarget","delay","target"],"sources":["../../src/util/event-utils.ts"],"sourcesContent":["export const isTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return !e.shiftKey && e.key === 'Tab';\n};\n\nexport const isEnterOrTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter' || (!e.shiftKey && e.key === 'Tab');\n};\n\nexport const isEnterKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter';\n};\n\nexport const isEscapeKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Escape';\n};\n\nexport const isTouchEvent = (event: MouseEvent | TouchEvent): event is TouchEvent => {\n return Boolean((event as TouchEvent).touches?.length);\n};\n\nexport const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => {\n return Boolean(\n ((event as MouseEvent).clientX || (event as MouseEvent).clientX === 0) &&\n
|
|
1
|
+
{"version":3,"file":"event-utils.cjs","names":["isTabKeyEvent","isEnterOrTabKeyEvent","isEnterKeyEvent","isEscapeKeyEvent","isTouchEvent","event","isMouseEvent","blurEventTarget","delay","target"],"sources":["../../src/util/event-utils.ts"],"sourcesContent":["export const isTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return !e.shiftKey && e.key === 'Tab';\n};\n\nexport const isEnterOrTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter' || (!e.shiftKey && e.key === 'Tab');\n};\n\nexport const isEnterKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter';\n};\n\nexport const isEscapeKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Escape';\n};\n\nexport const isTouchEvent = (event: MouseEvent | TouchEvent): event is TouchEvent => {\n return Boolean((event as TouchEvent).touches?.length);\n};\n\nexport const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => {\n return Boolean(\n ((event as MouseEvent).clientX || (event as MouseEvent).clientX === 0) &&\n ((event as MouseEvent).clientY || (event as MouseEvent).clientY === 0),\n );\n};\n\nexport const blurEventTarget = (event: { target: EventTarget | null }, delay = -1) => {\n const target = event.target as HTMLElement | null;\n if (!target) return;\n if (typeof target.blur !== 'function') return;\n if (delay >= 0) {\n setTimeout(() => {\n target.blur();\n }, delay);\n } else {\n target.blur();\n }\n};\n"],"mappings":"AAAA,MAAaA,EAAiB,GACrB,CAAC,EAAE,UAAY,EAAE,MAAQ,MAGrBC,EAAwB,GAC5B,EAAE,MAAQ,SAAY,CAAC,EAAE,UAAY,EAAE,MAAQ,MAG3CC,EAAmB,GACvB,EAAE,MAAQ,QAGNC,EAAoB,GACxB,EAAE,MAAQ,SAGNC,EAAgBC,GACpB,EAASA,EAAqB,SAAS,OAGnCC,EAAgBD,GACpB,EACHA,GAAqB,SAAYA,EAAqB,UAAY,GAClEA,GAAqB,SAAYA,EAAqB,UAAY,GAI3DE,GAAmBF,EAAuCG,EAAQ,KAAO,CACpF,IAAMC,EAASJ,EAAM,OAChBI,GACD,OAAOA,EAAO,MAAS,aACvBD,GAAS,EACX,eAAiB,CACfC,EAAO,KAAK,CACd,EAAGD,CAAK,EAERC,EAAO,KAAK,EAEhB,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-utils.js","names":["isTabKeyEvent","isEnterOrTabKeyEvent","isEnterKeyEvent","isEscapeKeyEvent","isTouchEvent","event","isMouseEvent","blurEventTarget","delay","target"],"sources":["../../src/util/event-utils.ts"],"sourcesContent":["export const isTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return !e.shiftKey && e.key === 'Tab';\n};\n\nexport const isEnterOrTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter' || (!e.shiftKey && e.key === 'Tab');\n};\n\nexport const isEnterKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter';\n};\n\nexport const isEscapeKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Escape';\n};\n\nexport const isTouchEvent = (event: MouseEvent | TouchEvent): event is TouchEvent => {\n return Boolean((event as TouchEvent).touches?.length);\n};\n\nexport const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => {\n return Boolean(\n ((event as MouseEvent).clientX || (event as MouseEvent).clientX === 0) &&\n
|
|
1
|
+
{"version":3,"file":"event-utils.js","names":["isTabKeyEvent","isEnterOrTabKeyEvent","isEnterKeyEvent","isEscapeKeyEvent","isTouchEvent","event","isMouseEvent","blurEventTarget","delay","target"],"sources":["../../src/util/event-utils.ts"],"sourcesContent":["export const isTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return !e.shiftKey && e.key === 'Tab';\n};\n\nexport const isEnterOrTabKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter' || (!e.shiftKey && e.key === 'Tab');\n};\n\nexport const isEnterKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Enter';\n};\n\nexport const isEscapeKeyEvent = (e: React.KeyboardEvent): boolean => {\n return e.key === 'Escape';\n};\n\nexport const isTouchEvent = (event: MouseEvent | TouchEvent): event is TouchEvent => {\n return Boolean((event as TouchEvent).touches?.length);\n};\n\nexport const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => {\n return Boolean(\n ((event as MouseEvent).clientX || (event as MouseEvent).clientX === 0) &&\n ((event as MouseEvent).clientY || (event as MouseEvent).clientY === 0),\n );\n};\n\nexport const blurEventTarget = (event: { target: EventTarget | null }, delay = -1) => {\n const target = event.target as HTMLElement | null;\n if (!target) return;\n if (typeof target.blur !== 'function') return;\n if (delay >= 0) {\n setTimeout(() => {\n target.blur();\n }, delay);\n } else {\n target.blur();\n }\n};\n"],"mappings":"AAAA,MAAaA,EAAiB,GACrB,CAAC,EAAE,UAAY,EAAE,MAAQ,MAGrBC,EAAwB,GAC5B,EAAE,MAAQ,SAAY,CAAC,EAAE,UAAY,EAAE,MAAQ,MAG3CC,EAAmB,GACvB,EAAE,MAAQ,QAGNC,EAAoB,GACxB,EAAE,MAAQ,SAGNC,EAAgBC,GACpB,EAASA,EAAqB,SAAS,OAGnCC,EAAgBD,GACpB,EACHA,GAAqB,SAAYA,EAAqB,UAAY,GAClEA,GAAqB,SAAYA,EAAqB,UAAY,GAI3DE,GAAmBF,EAAuCG,EAAQ,KAAO,CACpF,IAAMC,EAASJ,EAAM,OAChBI,GACD,OAAOA,EAAO,MAAS,aACvBD,GAAS,EACX,eAAiB,CACfC,EAAO,KAAK,CACd,EAAGD,CAAK,EAERC,EAAO,KAAK,EAEhB,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"override-props.cjs","names":["overrideProps","targetProps","overrides","filteredTargetProps","_","value","filteredOverrides","acc","current","filteredCurrent"],"sources":["../../src/util/override-props.ts"],"sourcesContent":["/**\n * 기본 props 객체와 여러 오버라이드 props 객체를 병합하여 하나의 새로운 객체를 반환합니다.\n *\n * - `overrides`에 전달된 값들 중 `undefined`는 무시됩니다.\n * - 반환된 객체의 모든 프로퍼티에서 `undefined`가 제거됩니다.\n *\n * @template T - 기본 props 타입\n * @template R - 오버라이드할 props 타입 배열\n *\n * @param targetProps - 병합의 기준이 되는 기본 props 객체\n * @param overrides - 병합할 여러 오버라이드 props 객체 (가변인자)\n * @returns 병합된 새로운 객체로, `undefined` 값이 제거된 상태로 반환됩니다.\n *\n * @example\n * ```typescript\n * const defaultProps = {\n * label: \"기본값\",\n * onClick: () => console.log(\"기본 클릭\"),\n * };\n *\n * const override1 = {\n * label: \"오버라이드 1\",\n * onClick: undefined, // undefined는 무시\n * };\n *\n * const override2 = {\n * style: { color: \"red\" },\n * };\n *\n * const finalProps = overrideProps(defaultProps, override1, override2);\n *\n * // 결과:\n * // {\n * // label: \"오버라이드 1\",\n * // onClick: () => console.log(\"기본 클릭\"), // 기본값 유지\n * // style: { color: \"red\" }\n * // }\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"override-props.cjs","names":["overrideProps","targetProps","overrides","filteredTargetProps","_","value","filteredOverrides","acc","current","filteredCurrent"],"sources":["../../src/util/override-props.ts"],"sourcesContent":["/**\n * 기본 props 객체와 여러 오버라이드 props 객체를 병합하여 하나의 새로운 객체를 반환합니다.\n *\n * - `overrides`에 전달된 값들 중 `undefined`는 무시됩니다.\n * - 반환된 객체의 모든 프로퍼티에서 `undefined`가 제거됩니다.\n *\n * @template T - 기본 props 타입\n * @template R - 오버라이드할 props 타입 배열\n *\n * @param targetProps - 병합의 기준이 되는 기본 props 객체\n * @param overrides - 병합할 여러 오버라이드 props 객체 (가변인자)\n * @returns 병합된 새로운 객체로, `undefined` 값이 제거된 상태로 반환됩니다.\n *\n * @example\n * ```typescript\n * const defaultProps = {\n * label: \"기본값\",\n * onClick: () => console.log(\"기본 클릭\"),\n * };\n *\n * const override1 = {\n * label: \"오버라이드 1\",\n * onClick: undefined, // undefined는 무시\n * };\n *\n * const override2 = {\n * style: { color: \"red\" },\n * };\n *\n * const finalProps = overrideProps(defaultProps, override1, override2);\n *\n * // 결과:\n * // {\n * // label: \"오버라이드 1\",\n * // onClick: () => console.log(\"기본 클릭\"), // 기본값 유지\n * // style: { color: \"red\" }\n * // }\n * ```\n */\nexport function overrideProps<T extends Record<string, any>, R extends Record<string, any>[]>(\n targetProps: T,\n ...overrides: R\n): { [K in keyof (T & R[number])]: Exclude<(T & R[number])[K], undefined> } {\n // 기본 props를 필터링\n const filteredTargetProps = Object.fromEntries(\n Object.entries(targetProps).filter(([_, value]) => value !== undefined),\n );\n\n // 모든 overrides를 순차적으로 병합\n const filteredOverrides = overrides.reduce<Record<string, unknown>>((acc, current) => {\n const filteredCurrent = Object.fromEntries(\n Object.entries(current).filter(([_, value]) => value !== undefined),\n );\n Object.assign(acc, filteredCurrent);\n return acc;\n }, {});\n\n // 최종 병합된 결과 반환\n return {\n ...filteredTargetProps,\n ...filteredOverrides,\n } as { [K in keyof (T & R[number])]: Exclude<(T & R[number])[K], undefined> };\n}\n"],"mappings":"AAuCA,SAAgBA,EACdC,EACA,GAAGC,EACuE,CAE1E,IAAMC,EAAsB,OAAO,YACjC,OAAO,QAAQF,CAAW,CAAC,CAAC,QAAQ,CAACG,EAAGC,KAAWA,IAAU,IAAA,EAAS,CACxE,EAGMC,EAAoBJ,EAAU,QAAiCK,EAAKC,IAAY,CACpF,IAAMC,EAAkB,OAAO,YAC7B,OAAO,QAAQD,CAAO,CAAC,CAAC,QAAQ,CAACJ,EAAGC,KAAWA,IAAU,IAAA,EAAS,CACpE,EAEA,OADA,OAAO,OAAOE,EAAKE,CAAe,EAC3BF,CACT,EAAG,CAAC,CAAC,EAGL,MAAO,CACL,GAAGJ,EACH,GAAGG,CACL,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"override-props.js","names":["overrideProps","targetProps","overrides","filteredTargetProps","_","value","filteredOverrides","acc","current","filteredCurrent"],"sources":["../../src/util/override-props.ts"],"sourcesContent":["/**\n * 기본 props 객체와 여러 오버라이드 props 객체를 병합하여 하나의 새로운 객체를 반환합니다.\n *\n * - `overrides`에 전달된 값들 중 `undefined`는 무시됩니다.\n * - 반환된 객체의 모든 프로퍼티에서 `undefined`가 제거됩니다.\n *\n * @template T - 기본 props 타입\n * @template R - 오버라이드할 props 타입 배열\n *\n * @param targetProps - 병합의 기준이 되는 기본 props 객체\n * @param overrides - 병합할 여러 오버라이드 props 객체 (가변인자)\n * @returns 병합된 새로운 객체로, `undefined` 값이 제거된 상태로 반환됩니다.\n *\n * @example\n * ```typescript\n * const defaultProps = {\n * label: \"기본값\",\n * onClick: () => console.log(\"기본 클릭\"),\n * };\n *\n * const override1 = {\n * label: \"오버라이드 1\",\n * onClick: undefined, // undefined는 무시\n * };\n *\n * const override2 = {\n * style: { color: \"red\" },\n * };\n *\n * const finalProps = overrideProps(defaultProps, override1, override2);\n *\n * // 결과:\n * // {\n * // label: \"오버라이드 1\",\n * // onClick: () => console.log(\"기본 클릭\"), // 기본값 유지\n * // style: { color: \"red\" }\n * // }\n * ```\n */\
|
|
1
|
+
{"version":3,"file":"override-props.js","names":["overrideProps","targetProps","overrides","filteredTargetProps","_","value","filteredOverrides","acc","current","filteredCurrent"],"sources":["../../src/util/override-props.ts"],"sourcesContent":["/**\n * 기본 props 객체와 여러 오버라이드 props 객체를 병합하여 하나의 새로운 객체를 반환합니다.\n *\n * - `overrides`에 전달된 값들 중 `undefined`는 무시됩니다.\n * - 반환된 객체의 모든 프로퍼티에서 `undefined`가 제거됩니다.\n *\n * @template T - 기본 props 타입\n * @template R - 오버라이드할 props 타입 배열\n *\n * @param targetProps - 병합의 기준이 되는 기본 props 객체\n * @param overrides - 병합할 여러 오버라이드 props 객체 (가변인자)\n * @returns 병합된 새로운 객체로, `undefined` 값이 제거된 상태로 반환됩니다.\n *\n * @example\n * ```typescript\n * const defaultProps = {\n * label: \"기본값\",\n * onClick: () => console.log(\"기본 클릭\"),\n * };\n *\n * const override1 = {\n * label: \"오버라이드 1\",\n * onClick: undefined, // undefined는 무시\n * };\n *\n * const override2 = {\n * style: { color: \"red\" },\n * };\n *\n * const finalProps = overrideProps(defaultProps, override1, override2);\n *\n * // 결과:\n * // {\n * // label: \"오버라이드 1\",\n * // onClick: () => console.log(\"기본 클릭\"), // 기본값 유지\n * // style: { color: \"red\" }\n * // }\n * ```\n */\nexport function overrideProps<T extends Record<string, any>, R extends Record<string, any>[]>(\n targetProps: T,\n ...overrides: R\n): { [K in keyof (T & R[number])]: Exclude<(T & R[number])[K], undefined> } {\n // 기본 props를 필터링\n const filteredTargetProps = Object.fromEntries(\n Object.entries(targetProps).filter(([_, value]) => value !== undefined),\n );\n\n // 모든 overrides를 순차적으로 병합\n const filteredOverrides = overrides.reduce<Record<string, unknown>>((acc, current) => {\n const filteredCurrent = Object.fromEntries(\n Object.entries(current).filter(([_, value]) => value !== undefined),\n );\n Object.assign(acc, filteredCurrent);\n return acc;\n }, {});\n\n // 최종 병합된 결과 반환\n return {\n ...filteredTargetProps,\n ...filteredOverrides,\n } as { [K in keyof (T & R[number])]: Exclude<(T & R[number])[K], undefined> };\n}\n"],"mappings":"AAuCA,SAAgBA,EACdC,EACA,GAAGC,EACuE,CAE1E,IAAMC,EAAsB,OAAO,YACjC,OAAO,QAAQF,CAAW,CAAC,CAAC,QAAQ,CAACG,EAAGC,KAAWA,IAAU,IAAA,EAAS,CACxE,EAGMC,EAAoBJ,EAAU,QAAiCK,EAAKC,IAAY,CACpF,IAAMC,EAAkB,OAAO,YAC7B,OAAO,QAAQD,CAAO,CAAC,CAAC,QAAQ,CAACJ,EAAGC,KAAWA,IAAU,IAAA,EAAS,CACpE,EAEA,OADA,OAAO,OAAOE,EAAKE,CAAe,EAC3BF,CACT,EAAG,CAAC,CAAC,EAGL,MAAO,CACL,GAAGJ,EACH,GAAGG,CACL,CACF,C"}
|