@uselets/ui 1.8.0 → 1.9.0
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/README.md +1 -0
- package/dist/{chart-DHS2QeM8.d.ts → chart-lqgodZYQ.d.ts} +11 -7
- package/dist/cli/uselets.mjs.map +1 -1
- package/dist/components/accordion.d.ts +5 -5
- package/dist/components/accordion.js +1 -1
- package/dist/components/accordion.js.map +1 -1
- package/dist/components/alert-dialog.d.ts +13 -13
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/alert.d.ts +5 -5
- package/dist/components/alert.js +1 -1
- package/dist/components/alert.js.map +1 -1
- package/dist/components/anchor.d.ts +2 -2
- package/dist/components/anchor.js +1 -1
- package/dist/components/anchor.js.map +1 -1
- package/dist/components/area-chart.d.ts +7 -3
- package/dist/components/area-chart.js +1 -1
- package/dist/components/area-chart.js.map +1 -1
- package/dist/components/avatar.d.ts +7 -7
- package/dist/components/avatar.js +1 -1
- package/dist/components/avatar.js.map +1 -1
- package/dist/components/badge.d.ts +2 -2
- package/dist/components/badge.js +1 -1
- package/dist/components/badge.js.map +1 -1
- package/dist/components/bar-chart.d.ts +7 -3
- package/dist/components/bar-chart.js +1 -1
- package/dist/components/bar-chart.js.map +1 -1
- package/dist/components/breadcrumb.d.ts +8 -8
- package/dist/components/breadcrumb.js +1 -1
- package/dist/components/breadcrumb.js.map +1 -1
- package/dist/components/button-group.d.ts +4 -4
- package/dist/components/button-group.js +1 -1
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/button.d.ts +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.d.ts +3 -3
- package/dist/components/calendar.js +1 -1
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/card.d.ts +8 -8
- package/dist/components/card.js +1 -1
- package/dist/components/card.js.map +1 -1
- package/dist/components/carousel.d.ts +7 -7
- package/dist/components/carousel.js +1 -1
- package/dist/components/carousel.js.map +1 -1
- package/dist/components/carousel.spec.js +1 -1
- package/dist/components/carousel.spec.js.map +1 -1
- package/dist/components/center.d.ts +2 -2
- package/dist/components/center.js +1 -1
- package/dist/components/center.js.map +1 -1
- package/dist/components/chart.d.ts +2 -2
- package/dist/components/chart.js +2 -2
- package/dist/components/chart.js.map +1 -1
- package/dist/components/checkbox.d.ts +2 -2
- package/dist/components/checkbox.js +1 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/code.d.ts +2 -2
- package/dist/components/code.js +1 -1
- package/dist/components/code.js.map +1 -1
- package/dist/components/collapsible.d.ts +4 -4
- package/dist/components/collapsible.js +1 -1
- package/dist/components/collapsible.js.map +1 -1
- package/dist/components/combobox.d.ts +16 -16
- package/dist/components/combobox.js +1 -1
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/command.d.ts +10 -10
- package/dist/components/command.js +1 -1
- package/dist/components/command.js.map +1 -1
- package/dist/components/container.d.ts +2 -2
- package/dist/components/container.js +1 -1
- package/dist/components/container.js.map +1 -1
- package/dist/components/data-table.d.ts +9 -9
- package/dist/components/data-table.js +1 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-range-picker.d.ts +12 -12
- package/dist/components/date-range-picker.js +1 -1
- package/dist/components/date-range-picker.js.map +1 -1
- package/dist/components/dialog.d.ts +12 -12
- package/dist/components/dialog.js +1 -1
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/donut-chart.d.ts +2 -2
- package/dist/components/donut-chart.js +1 -1
- package/dist/components/donut-chart.js.map +1 -1
- package/dist/components/drawer.d.ts +12 -12
- package/dist/components/drawer.js +1 -1
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/dropdown-menu.d.ts +16 -16
- package/dist/components/dropdown-menu.js +1 -1
- package/dist/components/dropdown-menu.js.map +1 -1
- package/dist/components/dropzone.d.ts +2 -2
- package/dist/components/dropzone.js +1 -1
- package/dist/components/dropzone.js.map +1 -1
- package/dist/components/empty.d.ts +7 -7
- package/dist/components/empty.js +1 -1
- package/dist/components/empty.js.map +1 -1
- package/dist/components/field.d.ts +11 -11
- package/dist/components/field.js +1 -1
- package/dist/components/field.js.map +1 -1
- package/dist/components/field.spec.js +1 -1
- package/dist/components/field.spec.js.map +1 -1
- package/dist/components/flex.d.ts +2 -2
- package/dist/components/flex.js +1 -1
- package/dist/components/flex.js.map +1 -1
- package/dist/components/grid.d.ts +3 -3
- package/dist/components/grid.js +1 -1
- package/dist/components/grid.js.map +1 -1
- package/dist/components/group.d.ts +2 -2
- package/dist/components/group.js +1 -1
- package/dist/components/group.js.map +1 -1
- package/dist/components/heading.d.ts +2 -2
- package/dist/components/heading.js +1 -1
- package/dist/components/heading.js.map +1 -1
- package/dist/components/hover-card.d.ts +4 -4
- package/dist/components/hover-card.js +1 -1
- package/dist/components/hover-card.js.map +1 -1
- package/dist/components/input-group.d.ts +7 -7
- package/dist/components/input-group.js +1 -1
- package/dist/components/input-group.js.map +1 -1
- package/dist/components/input-otp.d.ts +5 -5
- package/dist/components/input-otp.js +1 -1
- package/dist/components/input-otp.js.map +1 -1
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +1 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/kbd.d.ts +3 -3
- package/dist/components/kbd.js +1 -1
- package/dist/components/kbd.js.map +1 -1
- package/dist/components/label.d.ts +2 -2
- package/dist/components/label.js +1 -1
- package/dist/components/label.js.map +1 -1
- package/dist/components/list.d.ts +4 -4
- package/dist/components/list.js +1 -1
- package/dist/components/list.js.map +1 -1
- package/dist/components/mask-input.d.ts +2 -2
- package/dist/components/mask-input.js +1 -1
- package/dist/components/mask-input.js.map +1 -1
- package/dist/components/native-select.d.ts +4 -4
- package/dist/components/native-select.js +1 -1
- package/dist/components/native-select.js.map +1 -1
- package/dist/components/navigation-menu.d.ts +9 -9
- package/dist/components/navigation-menu.js +1 -1
- package/dist/components/navigation-menu.js.map +1 -1
- package/dist/components/pagination.d.ts +8 -8
- package/dist/components/pagination.js +1 -1
- package/dist/components/pagination.js.map +1 -1
- package/dist/components/pie-chart.d.ts +10 -4
- package/dist/components/pie-chart.js +1 -1
- package/dist/components/pie-chart.js.map +1 -1
- package/dist/components/popover.d.ts +8 -8
- package/dist/components/popover.js +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/progress.d.ts +2 -2
- package/dist/components/progress.js +1 -1
- package/dist/components/progress.js.map +1 -1
- package/dist/components/radio-group.d.ts +3 -3
- package/dist/components/radio-group.js +1 -1
- package/dist/components/radio-group.js.map +1 -1
- package/dist/components/resizable.d.ts +4 -4
- package/dist/components/resizable.js +1 -1
- package/dist/components/resizable.js.map +1 -1
- package/dist/components/scroll-area.d.ts +3 -3
- package/dist/components/scroll-area.js +1 -1
- package/dist/components/scroll-area.js.map +1 -1
- package/dist/components/select.d.ts +11 -11
- package/dist/components/select.js +1 -1
- package/dist/components/select.js.map +1 -1
- package/dist/components/separator.d.ts +2 -2
- package/dist/components/separator.js +1 -1
- package/dist/components/separator.js.map +1 -1
- package/dist/components/sidebar.d.ts +25 -25
- package/dist/components/sidebar.js +1 -1
- package/dist/components/sidebar.js.map +1 -1
- package/dist/components/simple-grid.d.ts +2 -2
- package/dist/components/simple-grid.js +1 -1
- package/dist/components/simple-grid.js.map +1 -1
- package/dist/components/skeleton.d.ts +2 -2
- package/dist/components/skeleton.js +1 -1
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/skeleton.spec.js +1 -1
- package/dist/components/skeleton.spec.js.map +1 -1
- package/dist/components/slider.d.ts +2 -2
- package/dist/components/slider.js +1 -1
- package/dist/components/slider.js.map +1 -1
- package/dist/components/sonner.d.ts +2 -2
- package/dist/components/sonner.js +1 -1
- package/dist/components/sonner.js.map +1 -1
- package/dist/components/spinner.d.ts +2 -2
- package/dist/components/spinner.js +1 -1
- package/dist/components/spinner.js.map +1 -1
- package/dist/components/stack.d.ts +2 -2
- package/dist/components/stack.js +1 -1
- package/dist/components/stack.js.map +1 -1
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +1 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/table.d.ts +10 -10
- package/dist/components/table.js +1 -1
- package/dist/components/table.js.map +1 -1
- package/dist/components/tabs.d.ts +5 -5
- package/dist/components/tabs.js +1 -1
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/text.d.ts +2 -2
- package/dist/components/text.js +1 -1
- package/dist/components/text.js.map +1 -1
- package/dist/components/textarea.d.ts +2 -2
- package/dist/components/textarea.js +1 -1
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/theme.d.ts +3 -3
- package/dist/components/theme.js +1 -1
- package/dist/components/theme.js.map +1 -1
- package/dist/components/timeline.d.ts +3 -3
- package/dist/components/timeline.js +1 -1
- package/dist/components/timeline.js.map +1 -1
- package/dist/components/toggle-group.d.ts +3 -3
- package/dist/components/toggle-group.js +1 -1
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle.d.ts +2 -2
- package/dist/components/toggle.js +1 -1
- package/dist/components/toggle.js.map +1 -1
- package/dist/components/tooltip.d.ts +6 -6
- package/dist/components/tooltip.js +1 -1
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/unstyled-button.d.ts +2 -2
- package/dist/components/unstyled-button.js +1 -1
- package/dist/components/unstyled-button.js.map +1 -1
- package/dist/components/visibility.d.ts +3 -3
- package/dist/components/visibility.js +1 -1
- package/dist/components/visibility.js.map +1 -1
- package/dist/{dist-C35vdEt2.js → dist-B-hwiqYg.js} +13 -13
- package/dist/dist-B-hwiqYg.js.map +1 -0
- package/dist/hooks/use-breakpoint-value.d.ts +1 -1
- package/dist/hooks/use-breakpoint-value.js +1 -1
- package/dist/hooks/use-breakpoint-value.js.map +1 -1
- package/dist/hooks/use-breakpoint-value.spec.js +1 -1
- package/dist/hooks/use-breakpoint-value.spec.js.map +1 -1
- package/dist/hooks/use-breakpoint.d.ts +1 -1
- package/dist/hooks/use-breakpoint.js +1 -1
- package/dist/hooks/use-breakpoint.js.map +1 -1
- package/dist/hooks/use-breakpoint.spec.js +1 -1
- package/dist/hooks/use-breakpoint.spec.js.map +1 -1
- package/dist/hooks/use-disclosure.d.ts +1 -1
- package/dist/hooks/use-disclosure.js +1 -1
- package/dist/hooks/use-disclosure.js.map +1 -1
- package/dist/hooks/use-disclosure.spec.js +1 -1
- package/dist/hooks/use-disclosure.spec.js.map +1 -1
- package/dist/hooks/use-document-visibility.d.ts +1 -1
- package/dist/hooks/use-document-visibility.js +1 -1
- package/dist/hooks/use-document-visibility.js.map +1 -1
- package/dist/hooks/use-document-visibility.spec.js +1 -1
- package/dist/hooks/use-document-visibility.spec.js.map +1 -1
- package/dist/hooks/use-idle.d.ts +1 -1
- package/dist/hooks/use-idle.js +1 -1
- package/dist/hooks/use-idle.js.map +1 -1
- package/dist/hooks/use-idle.spec.js +1 -1
- package/dist/hooks/use-idle.spec.js.map +1 -1
- package/dist/hooks/use-interval.d.ts +1 -1
- package/dist/hooks/use-interval.js +1 -1
- package/dist/hooks/use-interval.js.map +1 -1
- package/dist/hooks/use-interval.spec.js +1 -1
- package/dist/hooks/use-interval.spec.js.map +1 -1
- package/dist/hooks/use-local-storage.d.ts +1 -1
- package/dist/hooks/use-local-storage.js +1 -1
- package/dist/hooks/use-local-storage.js.map +1 -1
- package/dist/hooks/use-local-storage.spec.js +1 -1
- package/dist/hooks/use-local-storage.spec.js.map +1 -1
- package/dist/hooks/use-mask.d.ts +1 -1
- package/dist/hooks/use-mask.js +1 -1
- package/dist/hooks/use-mask.js.map +1 -1
- package/dist/hooks/use-mobile.d.ts +1 -1
- package/dist/hooks/use-mobile.js +1 -1
- package/dist/hooks/use-mobile.js.map +1 -1
- package/dist/hooks/use-mobile.spec.js +1 -1
- package/dist/hooks/use-mobile.spec.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/lib/badge.d.ts +1 -1
- package/dist/lib/button.d.ts +1 -1
- package/dist/lib/color.d.ts +1 -1
- package/dist/lib/compose-refs.d.ts +1 -1
- package/dist/lib/compose-refs.js +1 -1
- package/dist/lib/compose-refs.js.map +1 -1
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/{magic-string.es-C-uSEkg2.js → magic-string.es-DbBO8R0S.js} +2 -2
- package/dist/{magic-string.es-C-uSEkg2.js.map → magic-string.es-DbBO8R0S.js.map} +1 -1
- package/dist/{react.esm-BagSCtI3.js → react.esm-D88qr0ij.js} +12 -12
- package/dist/{react.esm-BagSCtI3.js.map → react.esm-D88qr0ij.js.map} +1 -1
- package/dist/skills/uselets-ui/references/component-catalog.md +6 -6
- package/package.json +17 -14
- package/skills/uselets-ui/references/component-catalog.md +6 -6
- package/dist/dist-C35vdEt2.js.map +0 -1
- /package/dist/{chunk-CHh1Zzun.js → rolldown-runtime-Bdj-bS2b.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useBreakpoint as e}from"./use-breakpoint.js";const t=[`base`,`sm`,`md`,`lg`,`xl`,`2xl`];function useBreakpointValue(n){let r={base:e(`base`),sm:e(`sm`),md:e(`md`),lg:e(`lg`),xl:e(`xl`),"2xl":e(`2xl`)},i=n.base;for(let e of t)r[e]&&n[e]!==void 0&&(i=n[e]);return i}export{useBreakpointValue};
|
|
2
2
|
//# sourceMappingURL=use-breakpoint-value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-value.js","names":[],"sources":["../../src/hooks/use-breakpoint-value.ts"],"sourcesContent":["import type { Breakpoint } from './use-breakpoint'\nimport { useBreakpoint } from './use-breakpoint'\n\nexport type ResponsiveValueMap<T> = Partial<Record<Breakpoint, T>>\n\nconst breakpointOrder = ['base', 'sm', 'md', 'lg', 'xl', '2xl'] as const satisfies readonly Breakpoint[]\n\nexport function useBreakpointValue<T>(values: ResponsiveValueMap<T>) {\n const activeBreakpoints = {\n base: useBreakpoint('base'),\n sm: useBreakpoint('sm'),\n md: useBreakpoint('md'),\n lg: useBreakpoint('lg'),\n xl: useBreakpoint('xl'),\n '2xl': useBreakpoint('2xl')\n }\n\n let value = values.base\n\n for (const breakpoint of breakpointOrder) {\n if (activeBreakpoints[breakpoint] && values[breakpoint] !== undefined) {\n value = values[breakpoint]\n }\n }\n\n return value\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-breakpoint-value.js","names":[],"sources":["../../src/hooks/use-breakpoint-value.ts"],"sourcesContent":["import type { Breakpoint } from './use-breakpoint'\nimport { useBreakpoint } from './use-breakpoint'\n\nexport type ResponsiveValueMap<T> = Partial<Record<Breakpoint, T>>\n\nconst breakpointOrder = ['base', 'sm', 'md', 'lg', 'xl', '2xl'] as const satisfies readonly Breakpoint[]\n\nexport function useBreakpointValue<T>(values: ResponsiveValueMap<T>) {\n const activeBreakpoints = {\n base: useBreakpoint('base'),\n sm: useBreakpoint('sm'),\n md: useBreakpoint('md'),\n lg: useBreakpoint('lg'),\n xl: useBreakpoint('xl'),\n '2xl': useBreakpoint('2xl')\n }\n\n let value = values.base\n\n for (const breakpoint of breakpointOrder) {\n if (activeBreakpoints[breakpoint] && values[breakpoint] !== undefined) {\n value = values[breakpoint]\n }\n }\n\n return value\n}\n"],"mappings":"4FAKA,MAAM,EAAkB,CAAC,OAAQ,KAAM,KAAM,KAAM,KAAM,KAAK,EAE9D,SAAgB,mBAAsB,EAA+B,CACnE,IAAM,EAAoB,CACxB,KAAM,EAAc,MAAM,EAC1B,GAAI,EAAc,IAAI,EACtB,GAAI,EAAc,IAAI,EACtB,GAAI,EAAc,IAAI,EACtB,GAAI,EAAc,IAAI,EACtB,MAAO,EAAc,KAAK,CAC5B,EAEI,EAAQ,EAAO,KAEnB,IAAK,IAAM,KAAc,EACnB,EAAkB,IAAe,EAAO,KAAgB,IAAA,KAC1D,EAAQ,EAAO,IAInB,OAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useBreakpointValue as e}from"./use-breakpoint-value.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";import{t as r}from"../dist-B-hwiqYg.js";describe(`useBreakpointValue`,()=>{it(`returns the base value below the first defined breakpoint`,()=>{globalThis.setTestViewportWidth(500);let{result:n}=t(()=>e({base:1,md:2}));expect(n.current).toBe(1)}),it(`returns the largest defined active breakpoint value`,()=>{globalThis.setTestViewportWidth(1200);let{result:n}=t(()=>e({base:1,md:2,lg:3,xl:4}));expect(n.current).toBe(3)}),it(`keeps the previous fallback when an active breakpoint has no value`,()=>{globalThis.setTestViewportWidth(900);let{result:n}=t(()=>e({base:`base`,lg:`large`}));expect(n.current).toBe(`base`)}),it(`updates when the active breakpoint changes`,()=>{globalThis.setTestViewportWidth(500);let{result:r}=t(()=>e({base:!1,md:!0}));expect(r.current).toBe(!1),n(()=>{globalThis.setTestViewportWidth(768)}),expect(r.current).toBe(!0)}),it(`infers value types from the values object`,()=>{(0,r.expectTypeOf)(void 0).toEqualTypeOf(),(0,r.expectTypeOf)(void 0).toEqualTypeOf(),(0,r.expectTypeOf)(void 0).toEqualTypeOf()}),it(`accepts an explicit generic value type`,()=>{(0,r.expectTypeOf)(void 0).toEqualTypeOf()})});
|
|
2
2
|
//# sourceMappingURL=use-breakpoint-value.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-value.spec.js","names":[],"sources":["../../src/hooks/use-breakpoint-value.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\nimport { expectTypeOf } from 'vitest'\n\nimport { useBreakpointValue } from './use-breakpoint-value'\n\nfunction inferBreakpointValue<T>(_values: Parameters<typeof useBreakpointValue<T>>[0]) {\n return undefined as ReturnType<typeof useBreakpointValue<T>>\n}\n\ndescribe('useBreakpointValue', () => {\n it('returns the base value below the first defined breakpoint', () => {\n globalThis.setTestViewportWidth(500)\n\n const { result } = renderHook(() => useBreakpointValue({ base: 1, md: 2 }))\n\n expect(result.current).toBe(1)\n })\n\n it('returns the largest defined active breakpoint value', () => {\n globalThis.setTestViewportWidth(1200)\n\n const { result } = renderHook(() => useBreakpointValue({ base: 1, md: 2, lg: 3, xl: 4 }))\n\n expect(result.current).toBe(3)\n })\n\n it('keeps the previous fallback when an active breakpoint has no value', () => {\n globalThis.setTestViewportWidth(900)\n\n const { result } = renderHook(() => useBreakpointValue({ base: 'base', lg: 'large' }))\n\n expect(result.current).toBe('base')\n })\n\n it('updates when the active breakpoint changes', () => {\n globalThis.setTestViewportWidth(500)\n const { result } = renderHook(() => useBreakpointValue({ base: false, md: true }))\n\n expect(result.current).toBe(false)\n\n act(() => {\n globalThis.setTestViewportWidth(768)\n })\n expect(result.current).toBe(true)\n })\n\n it('infers value types from the values object', () => {\n const numberValue = inferBreakpointValue({ base: 1, md: 2 })\n const stringValue = inferBreakpointValue({ base: 'base', md: 'medium' })\n const booleanValue = inferBreakpointValue({ base: false, md: true })\n\n expectTypeOf(numberValue).toEqualTypeOf<number | undefined>()\n expectTypeOf(stringValue).toEqualTypeOf<string | undefined>()\n expectTypeOf(booleanValue).toEqualTypeOf<boolean | undefined>()\n })\n\n it('accepts an explicit generic value type', () => {\n const value = inferBreakpointValue<number>({ base: 1, md: 2 })\n\n expectTypeOf(value).toEqualTypeOf<number | undefined>()\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-breakpoint-value.spec.js","names":[],"sources":["../../src/hooks/use-breakpoint-value.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\nimport { expectTypeOf } from 'vitest'\n\nimport { useBreakpointValue } from './use-breakpoint-value'\n\nfunction inferBreakpointValue<T>(_values: Parameters<typeof useBreakpointValue<T>>[0]) {\n return undefined as ReturnType<typeof useBreakpointValue<T>>\n}\n\ndescribe('useBreakpointValue', () => {\n it('returns the base value below the first defined breakpoint', () => {\n globalThis.setTestViewportWidth(500)\n\n const { result } = renderHook(() => useBreakpointValue({ base: 1, md: 2 }))\n\n expect(result.current).toBe(1)\n })\n\n it('returns the largest defined active breakpoint value', () => {\n globalThis.setTestViewportWidth(1200)\n\n const { result } = renderHook(() => useBreakpointValue({ base: 1, md: 2, lg: 3, xl: 4 }))\n\n expect(result.current).toBe(3)\n })\n\n it('keeps the previous fallback when an active breakpoint has no value', () => {\n globalThis.setTestViewportWidth(900)\n\n const { result } = renderHook(() => useBreakpointValue({ base: 'base', lg: 'large' }))\n\n expect(result.current).toBe('base')\n })\n\n it('updates when the active breakpoint changes', () => {\n globalThis.setTestViewportWidth(500)\n const { result } = renderHook(() => useBreakpointValue({ base: false, md: true }))\n\n expect(result.current).toBe(false)\n\n act(() => {\n globalThis.setTestViewportWidth(768)\n })\n expect(result.current).toBe(true)\n })\n\n it('infers value types from the values object', () => {\n const numberValue = inferBreakpointValue({ base: 1, md: 2 })\n const stringValue = inferBreakpointValue({ base: 'base', md: 'medium' })\n const booleanValue = inferBreakpointValue({ base: false, md: true })\n\n expectTypeOf(numberValue).toEqualTypeOf<number | undefined>()\n expectTypeOf(stringValue).toEqualTypeOf<string | undefined>()\n expectTypeOf(booleanValue).toEqualTypeOf<boolean | undefined>()\n })\n\n it('accepts an explicit generic value type', () => {\n const value = inferBreakpointValue<number>({ base: 1, md: 2 })\n\n expectTypeOf(value).toEqualTypeOf<number | undefined>()\n })\n})\n"],"mappings":"mMASA,SAAS,yBAA4B,CACnC,GAAG,gEAAmE,CACpE,WAAW,qBAAqB,GAAG,EAEnC,GAAM,CAAE,UAAW,MAAiB,EAAmB,CAAE,KAAM,EAAG,GAAI,CAAE,CAAC,CAAC,EAE1E,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,CAAC,CAC/B,CAAC,EAED,GAAG,0DAA6D,CAC9D,WAAW,qBAAqB,IAAI,EAEpC,GAAM,CAAE,UAAW,MAAiB,EAAmB,CAAE,KAAM,EAAG,GAAI,EAAG,GAAI,EAAG,GAAI,CAAE,CAAC,CAAC,EAExF,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,CAAC,CAC/B,CAAC,EAED,GAAG,yEAA4E,CAC7E,WAAW,qBAAqB,GAAG,EAEnC,GAAM,CAAE,UAAW,MAAiB,EAAmB,CAAE,KAAM,OAAQ,GAAI,OAAQ,CAAC,CAAC,EAErF,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,MAAM,CACpC,CAAC,EAED,GAAG,iDAAoD,CACrD,WAAW,qBAAqB,GAAG,EACnC,GAAM,CAAE,UAAW,MAAiB,EAAmB,CAAE,KAAM,GAAO,GAAI,EAAK,CAAC,CAAC,EAEjF,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAK,EAEjC,MAAU,CACR,WAAW,qBAAqB,GAAG,CACrC,CAAC,EACD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAI,CAClC,CAAC,EAED,GAAG,gDAAmD,EAKpD,EAAA,EAAA,aAAA,CAAa,MAAW,CAAC,CAAC,cAAkC,GAC5D,EAAA,EAAA,aAAA,CAAa,MAAW,CAAC,CAAC,cAAkC,GAC5D,EAAA,EAAA,aAAA,CAAa,MAAY,CAAC,CAAC,cAAmC,CAChE,CAAC,EAED,GAAG,6CAAgD,EAGjD,EAAA,EAAA,aAAA,CAAa,IAAA,EAAK,CAAC,CAAC,cAAkC,CACxD,CAAC,CACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import*as e from"react";const t={sm:640,md:768,lg:1024,xl:1280,"2xl":1536};function useBreakpoint(n){let[r,i]=e.useState(n===`base`);return e.useEffect(()=>{if(n===`base`){i(!0);return}let e=window.matchMedia(`(min-width: ${t[n]}px)`),onChange=()=>{i(e.matches)};return e.addEventListener(`change`,onChange),i(e.matches),()=>e.removeEventListener(`change`,onChange)},[n]),n===`base`||r}export{t as breakpointValues,useBreakpoint};
|
|
2
2
|
//# sourceMappingURL=use-breakpoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint.js","names":[],"sources":["../../src/hooks/use-breakpoint.ts"],"sourcesContent":["import * as React from 'react'\n\nexport type Breakpoint = 'base' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n\nexport const breakpointValues: Record<Exclude<Breakpoint, 'base'>, number> = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536\n}\n\nexport function useBreakpoint(breakpoint: Breakpoint) {\n const [matches, setMatches] = React.useState(breakpoint === 'base')\n\n React.useEffect(() => {\n if (breakpoint === 'base') {\n setMatches(true)\n return\n }\n\n const mql = window.matchMedia(`(min-width: ${breakpointValues[breakpoint]}px)`)\n const onChange = () => {\n setMatches(mql.matches)\n }\n\n mql.addEventListener('change', onChange)\n setMatches(mql.matches)\n\n return () => mql.removeEventListener('change', onChange)\n }, [breakpoint])\n\n return breakpoint === 'base' || matches\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-breakpoint.js","names":[],"sources":["../../src/hooks/use-breakpoint.ts"],"sourcesContent":["import * as React from 'react'\n\nexport type Breakpoint = 'base' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'\n\nexport const breakpointValues: Record<Exclude<Breakpoint, 'base'>, number> = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536\n}\n\nexport function useBreakpoint(breakpoint: Breakpoint) {\n const [matches, setMatches] = React.useState(breakpoint === 'base')\n\n React.useEffect(() => {\n if (breakpoint === 'base') {\n setMatches(true)\n return\n }\n\n const mql = window.matchMedia(`(min-width: ${breakpointValues[breakpoint]}px)`)\n const onChange = () => {\n setMatches(mql.matches)\n }\n\n mql.addEventListener('change', onChange)\n setMatches(mql.matches)\n\n return () => mql.removeEventListener('change', onChange)\n }, [breakpoint])\n\n return breakpoint === 'base' || matches\n}\n"],"mappings":"gEAIA,MAAa,EAAgE,CAC3E,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,MAAO,IACT,EAEA,SAAgB,cAAc,EAAwB,CACpD,GAAM,CAAC,EAAS,GAAc,EAAM,SAAS,IAAe,MAAM,EAmBlE,OAjBA,EAAM,cAAgB,CACpB,GAAI,IAAe,OAAQ,CACzB,EAAW,EAAI,EACf,MACF,CAEA,IAAM,EAAM,OAAO,WAAW,eAAe,EAAiB,GAAY,IAAI,EACxE,aAAiB,CACrB,EAAW,EAAI,OAAO,CACxB,EAKA,OAHA,EAAI,iBAAiB,SAAU,QAAQ,EACvC,EAAW,EAAI,OAAO,MAET,EAAI,oBAAoB,SAAU,QAAQ,CACzD,EAAG,CAAC,CAAU,CAAC,EAER,IAAe,QAAU,CAClC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useBreakpoint as e}from"./use-breakpoint.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";describe(`useBreakpoint`,()=>{it(`returns true for the base breakpoint`,()=>{globalThis.setTestViewportWidth(320);let{result:n}=t(()=>e(`base`));expect(n.current).toBe(!0)}),it(`returns false below the requested breakpoint`,()=>{globalThis.setTestViewportWidth(767);let{result:n}=t(()=>e(`md`));expect(n.current).toBe(!1)}),it(`returns true at the requested breakpoint`,()=>{globalThis.setTestViewportWidth(768);let{result:n}=t(()=>e(`md`));expect(n.current).toBe(!0)}),it(`returns true above the requested breakpoint`,()=>{globalThis.setTestViewportWidth(900);let{result:n}=t(()=>e(`md`));expect(n.current).toBe(!0)}),it(`updates when the media query changes`,()=>{globalThis.setTestViewportWidth(1024);let{result:r}=t(()=>e(`lg`));expect(r.current).toBe(!0),n(()=>{globalThis.setTestViewportWidth(900)}),expect(r.current).toBe(!1),n(()=>{globalThis.setTestViewportWidth(1200)}),expect(r.current).toBe(!0)}),it(`removes the media query listener on unmount`,()=>{let n=vi.fn();vi.spyOn(window,`matchMedia`).mockReturnValue({matches:!1,media:`(min-width: 768px)`,onchange:null,addEventListener:vi.fn(),removeEventListener:n,dispatchEvent:vi.fn(),addListener:vi.fn(),removeListener:vi.fn()});let{unmount:r}=t(()=>e(`md`));r(),expect(n).toHaveBeenCalledWith(`change`,expect.any(Function))})});
|
|
2
2
|
//# sourceMappingURL=use-breakpoint.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint.spec.js","names":[],"sources":["../../src/hooks/use-breakpoint.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useBreakpoint } from './use-breakpoint'\n\ndescribe('useBreakpoint', () => {\n it('returns true for the base breakpoint', () => {\n globalThis.setTestViewportWidth(320)\n\n const { result } = renderHook(() => useBreakpoint('base'))\n\n expect(result.current).toBe(true)\n })\n\n it('returns false below the requested breakpoint', () => {\n globalThis.setTestViewportWidth(767)\n\n const { result } = renderHook(() => useBreakpoint('md'))\n\n expect(result.current).toBe(false)\n })\n\n it('returns true at the requested breakpoint', () => {\n globalThis.setTestViewportWidth(768)\n\n const { result } = renderHook(() => useBreakpoint('md'))\n\n expect(result.current).toBe(true)\n })\n\n it('returns true above the requested breakpoint', () => {\n globalThis.setTestViewportWidth(900)\n\n const { result } = renderHook(() => useBreakpoint('md'))\n\n expect(result.current).toBe(true)\n })\n\n it('updates when the media query changes', () => {\n globalThis.setTestViewportWidth(1024)\n const { result } = renderHook(() => useBreakpoint('lg'))\n\n expect(result.current).toBe(true)\n\n act(() => {\n globalThis.setTestViewportWidth(900)\n })\n expect(result.current).toBe(false)\n\n act(() => {\n globalThis.setTestViewportWidth(1200)\n })\n expect(result.current).toBe(true)\n })\n\n it('removes the media query listener on unmount', () => {\n const removeEventListener = vi.fn()\n\n vi.spyOn(window, 'matchMedia').mockReturnValue({\n matches: false,\n media: '(min-width: 768px)',\n onchange: null,\n addEventListener: vi.fn(),\n removeEventListener,\n dispatchEvent: vi.fn(),\n addListener: vi.fn(),\n removeListener: vi.fn()\n })\n\n const { unmount } = renderHook(() => useBreakpoint('md'))\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('change', expect.any(Function))\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-breakpoint.spec.js","names":[],"sources":["../../src/hooks/use-breakpoint.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useBreakpoint } from './use-breakpoint'\n\ndescribe('useBreakpoint', () => {\n it('returns true for the base breakpoint', () => {\n globalThis.setTestViewportWidth(320)\n\n const { result } = renderHook(() => useBreakpoint('base'))\n\n expect(result.current).toBe(true)\n })\n\n it('returns false below the requested breakpoint', () => {\n globalThis.setTestViewportWidth(767)\n\n const { result } = renderHook(() => useBreakpoint('md'))\n\n expect(result.current).toBe(false)\n })\n\n it('returns true at the requested breakpoint', () => {\n globalThis.setTestViewportWidth(768)\n\n const { result } = renderHook(() => useBreakpoint('md'))\n\n expect(result.current).toBe(true)\n })\n\n it('returns true above the requested breakpoint', () => {\n globalThis.setTestViewportWidth(900)\n\n const { result } = renderHook(() => useBreakpoint('md'))\n\n expect(result.current).toBe(true)\n })\n\n it('updates when the media query changes', () => {\n globalThis.setTestViewportWidth(1024)\n const { result } = renderHook(() => useBreakpoint('lg'))\n\n expect(result.current).toBe(true)\n\n act(() => {\n globalThis.setTestViewportWidth(900)\n })\n expect(result.current).toBe(false)\n\n act(() => {\n globalThis.setTestViewportWidth(1200)\n })\n expect(result.current).toBe(true)\n })\n\n it('removes the media query listener on unmount', () => {\n const removeEventListener = vi.fn()\n\n vi.spyOn(window, 'matchMedia').mockReturnValue({\n matches: false,\n media: '(min-width: 768px)',\n onchange: null,\n addEventListener: vi.fn(),\n removeEventListener,\n dispatchEvent: vi.fn(),\n addListener: vi.fn(),\n removeListener: vi.fn()\n })\n\n const { unmount } = renderHook(() => useBreakpoint('md'))\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('change', expect.any(Function))\n })\n})\n"],"mappings":"gJAIA,SAAS,oBAAuB,CAC9B,GAAG,2C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AAM,CAAE,WAAY,MAAiB,EAAc,IAAI,CAAC,EAExD,EAAQ,EAER,OAAO,CAAmB,CAAC,CAAC,qBAAqB,SAAU,OAAO,IAAI,QAAQ,CAAC,CACjF,CAAC,CACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useCallback as e,useState as t}from"react";function useDisclosure(n=!1,r={}){let[i,a]=t(n),o=e(()=>{a(e=>e||(r.onOpen?.(),!0))},[r.onOpen]),s=e(()=>{a(e=>e&&(r.onClose?.(),!1))},[r.onClose]);return[i,{open:o,close:s,toggle:e(()=>{i?s():o()},[s,o,i]),set:a}]}export{useDisclosure};
|
|
2
2
|
//# sourceMappingURL=use-disclosure.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-disclosure.js","names":[],"sources":["../../src/hooks/use-disclosure.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\n\nexport type UseDisclosureOptions = {\n onOpen?: () => void\n onClose?: () => void\n}\n\nexport type UseDisclosureHandlers = {\n set: (value: boolean) => void\n open: () => void\n close: () => void\n toggle: () => void\n}\n\nexport type UseDisclosureReturnValue = [boolean, UseDisclosureHandlers]\n\nexport function useDisclosure(initialState = false, options: UseDisclosureOptions = {}): UseDisclosureReturnValue {\n const [opened, setOpened] = useState(initialState)\n\n const open = useCallback(() => {\n setOpened((isOpened) => {\n if (!isOpened) {\n options.onOpen?.()\n return true\n }\n return isOpened\n })\n }, [options.onOpen])\n\n const close = useCallback(() => {\n setOpened((isOpened) => {\n if (isOpened) {\n options.onClose?.()\n return false\n }\n return isOpened\n })\n }, [options.onClose])\n\n const toggle = useCallback(() => {\n opened ? close() : open()\n }, [close, open, opened])\n\n return [opened, { open, close, toggle, set: setOpened }]\n}\n\nexport namespace useDisclosure {\n export type Options = UseDisclosureOptions\n export type Handlers = UseDisclosureHandlers\n export type ReturnValue = UseDisclosureReturnValue\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-disclosure.js","names":[],"sources":["../../src/hooks/use-disclosure.ts"],"sourcesContent":["import { useCallback, useState } from 'react'\n\nexport type UseDisclosureOptions = {\n onOpen?: () => void\n onClose?: () => void\n}\n\nexport type UseDisclosureHandlers = {\n set: (value: boolean) => void\n open: () => void\n close: () => void\n toggle: () => void\n}\n\nexport type UseDisclosureReturnValue = [boolean, UseDisclosureHandlers]\n\nexport function useDisclosure(initialState = false, options: UseDisclosureOptions = {}): UseDisclosureReturnValue {\n const [opened, setOpened] = useState(initialState)\n\n const open = useCallback(() => {\n setOpened((isOpened) => {\n if (!isOpened) {\n options.onOpen?.()\n return true\n }\n return isOpened\n })\n }, [options.onOpen])\n\n const close = useCallback(() => {\n setOpened((isOpened) => {\n if (isOpened) {\n options.onClose?.()\n return false\n }\n return isOpened\n })\n }, [options.onClose])\n\n const toggle = useCallback(() => {\n opened ? close() : open()\n }, [close, open, opened])\n\n return [opened, { open, close, toggle, set: setOpened }]\n}\n\nexport namespace useDisclosure {\n export type Options = UseDisclosureOptions\n export type Handlers = UseDisclosureHandlers\n export type ReturnValue = UseDisclosureReturnValue\n}\n"],"mappings":"0FAgBA,SAAgB,cAAc,EAAe,GAAO,EAAgC,CAAC,EAA6B,CAChH,GAAM,CAAC,EAAQ,GAAa,EAAS,CAAY,EAE3C,EAAO,MAAkB,CAC7B,EAAW,GACJ,IACH,EAAQ,SAAS,EACV,GAGV,CACH,EAAG,CAAC,EAAQ,MAAM,CAAC,EAEb,EAAQ,MAAkB,CAC9B,EAAW,GACL,IACF,EAAQ,UAAU,EACX,GAGV,CACH,EAAG,CAAC,EAAQ,OAAO,CAAC,EAMpB,MAAO,CAAC,EAAQ,CAAE,OAAM,QAAO,OAJhB,MAAkB,CAC/B,EAAS,EAAM,EAAI,EAAK,CAC1B,EAAG,CAAC,EAAO,EAAM,CAAM,CAEa,EAAG,IAAK,CAAU,CAAC,CACzD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useDisclosure as e}from"./use-disclosure.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";describe(`useDisclosure`,()=>{it(`uses false as the default initial state`,()=>{let{result:n}=t(()=>e());expect(n.current[0]).toBe(!1)}),it(`uses the provided initial state`,()=>{let{result:n}=t(()=>e(!0));expect(n.current[0]).toBe(!0)}),it(`opens, closes, toggles, and sets the state`,()=>{let{result:r}=t(()=>e());n(()=>r.current[1].open()),expect(r.current[0]).toBe(!0),n(()=>r.current[1].close()),expect(r.current[0]).toBe(!1),n(()=>r.current[1].toggle()),expect(r.current[0]).toBe(!0),n(()=>r.current[1].set(!1)),expect(r.current[0]).toBe(!1)}),it(`calls callbacks only when state transitions happen`,()=>{let r=vi.fn(),i=vi.fn(),{result:a}=t(()=>e(!1,{onOpen:r,onClose:i}));n(()=>a.current[1].close()),expect(i).not.toHaveBeenCalled(),n(()=>a.current[1].open()),n(()=>a.current[1].open()),expect(r).toHaveBeenCalledTimes(1),n(()=>a.current[1].close()),n(()=>a.current[1].close()),expect(i).toHaveBeenCalledTimes(1)})});
|
|
2
2
|
//# sourceMappingURL=use-disclosure.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-disclosure.spec.js","names":[],"sources":["../../src/hooks/use-disclosure.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useDisclosure } from './use-disclosure'\n\ndescribe('useDisclosure', () => {\n it('uses false as the default initial state', () => {\n const { result } = renderHook(() => useDisclosure())\n\n expect(result.current[0]).toBe(false)\n })\n\n it('uses the provided initial state', () => {\n const { result } = renderHook(() => useDisclosure(true))\n\n expect(result.current[0]).toBe(true)\n })\n\n it('opens, closes, toggles, and sets the state', () => {\n const { result } = renderHook(() => useDisclosure())\n\n act(() => result.current[1].open())\n expect(result.current[0]).toBe(true)\n\n act(() => result.current[1].close())\n expect(result.current[0]).toBe(false)\n\n act(() => result.current[1].toggle())\n expect(result.current[0]).toBe(true)\n\n act(() => result.current[1].set(false))\n expect(result.current[0]).toBe(false)\n })\n\n it('calls callbacks only when state transitions happen', () => {\n const onOpen = vi.fn()\n const onClose = vi.fn()\n const { result } = renderHook(() => useDisclosure(false, { onOpen, onClose }))\n\n act(() => result.current[1].close())\n expect(onClose).not.toHaveBeenCalled()\n\n act(() => result.current[1].open())\n act(() => result.current[1].open())\n expect(onOpen).toHaveBeenCalledTimes(1)\n\n act(() => result.current[1].close())\n act(() => result.current[1].close())\n expect(onClose).toHaveBeenCalledTimes(1)\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-disclosure.spec.js","names":[],"sources":["../../src/hooks/use-disclosure.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useDisclosure } from './use-disclosure'\n\ndescribe('useDisclosure', () => {\n it('uses false as the default initial state', () => {\n const { result } = renderHook(() => useDisclosure())\n\n expect(result.current[0]).toBe(false)\n })\n\n it('uses the provided initial state', () => {\n const { result } = renderHook(() => useDisclosure(true))\n\n expect(result.current[0]).toBe(true)\n })\n\n it('opens, closes, toggles, and sets the state', () => {\n const { result } = renderHook(() => useDisclosure())\n\n act(() => result.current[1].open())\n expect(result.current[0]).toBe(true)\n\n act(() => result.current[1].close())\n expect(result.current[0]).toBe(false)\n\n act(() => result.current[1].toggle())\n expect(result.current[0]).toBe(true)\n\n act(() => result.current[1].set(false))\n expect(result.current[0]).toBe(false)\n })\n\n it('calls callbacks only when state transitions happen', () => {\n const onOpen = vi.fn()\n const onClose = vi.fn()\n const { result } = renderHook(() => useDisclosure(false, { onOpen, onClose }))\n\n act(() => result.current[1].close())\n expect(onClose).not.toHaveBeenCalled()\n\n act(() => result.current[1].open())\n act(() => result.current[1].open())\n expect(onOpen).toHaveBeenCalledTimes(1)\n\n act(() => result.current[1].close())\n act(() => result.current[1].close())\n expect(onClose).toHaveBeenCalledTimes(1)\n })\n})\n"],"mappings":"gJAIA,SA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EAAO,QAAQ,EAAE,CAAC,MAAM,CAAC,EACnC,OAAO,CAAO,CAAC,CAAC,sBAAsB,CAAC,CACzC,CAAC,CACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useEffect as e,useState as t}from"react";function useDocumentVisibility(){let[n,r]=t(`visible`);return e(()=>{r(document.visibilityState);let listener=()=>r(document.visibilityState);return document.addEventListener(`visibilitychange`,listener),()=>document.removeEventListener(`visibilitychange`,listener)},[]),n}export{useDocumentVisibility};
|
|
2
2
|
//# sourceMappingURL=use-document-visibility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-document-visibility.js","names":[],"sources":["../../src/hooks/use-document-visibility.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nexport function useDocumentVisibility(): DocumentVisibilityState {\n const [documentVisibility, setDocumentVisibility] = useState<DocumentVisibilityState>('visible')\n\n useEffect(() => {\n setDocumentVisibility(document.visibilityState)\n const listener = () => setDocumentVisibility(document.visibilityState)\n document.addEventListener('visibilitychange', listener)\n return () => document.removeEventListener('visibilitychange', listener)\n }, [])\n\n return documentVisibility\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-document-visibility.js","names":[],"sources":["../../src/hooks/use-document-visibility.ts"],"sourcesContent":["import { useEffect, useState } from 'react'\n\nexport function useDocumentVisibility(): DocumentVisibilityState {\n const [documentVisibility, setDocumentVisibility] = useState<DocumentVisibilityState>('visible')\n\n useEffect(() => {\n setDocumentVisibility(document.visibilityState)\n const listener = () => setDocumentVisibility(document.visibilityState)\n document.addEventListener('visibilitychange', listener)\n return () => document.removeEventListener('visibilitychange', listener)\n }, [])\n\n return documentVisibility\n}\n"],"mappings":"wFAEA,SAAgB,uBAAiD,CAC/D,GAAM,CAAC,EAAoB,GAAyB,EAAkC,SAAS,EAS/F,OAPA,MAAgB,CACd,EAAsB,SAAS,eAAe,EAC9C,IAAM,aAAiB,EAAsB,SAAS,eAAe,EAErE,OADA,SAAS,iBAAiB,mBAAoB,QAAQ,MACzC,SAAS,oBAAoB,mBAAoB,QAAQ,CACxE,EAAG,CAAC,CAAC,EAEE,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useDocumentVisibility as e}from"./use-document-visibility.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";function setDocumentVisibility(e){Object.defineProperty(document,"visibilityState",{configurable:!0,get:()=>e})}describe(`useDocumentVisibility`,()=>{it(`uses the current document visibility on mount`,()=>{setDocumentVisibility(`hidden`);let{result:n}=t(()=>e());expect(n.current).toBe(`hidden`)}),it(`updates when the document visibility changes`,()=>{setDocumentVisibility(`visible`);let{result:r}=t(()=>e());n(()=>{setDocumentVisibility(`hidden`),document.dispatchEvent(new Event(`visibilitychange`))}),expect(r.current).toBe(`hidden`)}),it(`removes the visibility listener on unmount`,()=>{let n=vi.spyOn(document,`removeEventListener`),{unmount:r}=t(()=>e());r(),expect(n).toHaveBeenCalledWith(`visibilitychange`,expect.any(Function))})});
|
|
2
2
|
//# sourceMappingURL=use-document-visibility.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-document-visibility.spec.js","names":[],"sources":["../../src/hooks/use-document-visibility.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useDocumentVisibility } from './use-document-visibility'\n\nfunction setDocumentVisibility(visibilityState: DocumentVisibilityState) {\n Object.defineProperty(document, 'visibilityState', {\n configurable: true,\n get: () => visibilityState\n })\n}\n\ndescribe('useDocumentVisibility', () => {\n it('uses the current document visibility on mount', () => {\n setDocumentVisibility('hidden')\n\n const { result } = renderHook(() => useDocumentVisibility())\n\n expect(result.current).toBe('hidden')\n })\n\n it('updates when the document visibility changes', () => {\n setDocumentVisibility('visible')\n const { result } = renderHook(() => useDocumentVisibility())\n\n act(() => {\n setDocumentVisibility('hidden')\n document.dispatchEvent(new Event('visibilitychange'))\n })\n\n expect(result.current).toBe('hidden')\n })\n\n it('removes the visibility listener on unmount', () => {\n const removeEventListener = vi.spyOn(document, 'removeEventListener')\n const { unmount } = renderHook(() => useDocumentVisibility())\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('visibilitychange', expect.any(Function))\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-document-visibility.spec.js","names":[],"sources":["../../src/hooks/use-document-visibility.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useDocumentVisibility } from './use-document-visibility'\n\nfunction setDocumentVisibility(visibilityState: DocumentVisibilityState) {\n Object.defineProperty(document, 'visibilityState', {\n configurable: true,\n get: () => visibilityState\n })\n}\n\ndescribe('useDocumentVisibility', () => {\n it('uses the current document visibility on mount', () => {\n setDocumentVisibility('hidden')\n\n const { result } = renderHook(() => useDocumentVisibility())\n\n expect(result.current).toBe('hidden')\n })\n\n it('updates when the document visibility changes', () => {\n setDocumentVisibility('visible')\n const { result } = renderHook(() => useDocumentVisibility())\n\n act(() => {\n setDocumentVisibility('hidden')\n document.dispatchEvent(new Event('visibilitychange'))\n })\n\n expect(result.current).toBe('hidden')\n })\n\n it('removes the visibility listener on unmount', () => {\n const removeEventListener = vi.spyOn(document, 'removeEventListener')\n const { unmount } = renderHook(() => useDocumentVisibility())\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('visibilitychange', expect.any(Function))\n })\n})\n"],"mappings":"iKAIA,SAAS,sBAAsB,EAA0C,CACvE,OAAO,eAAe,SAAU,kBAAmB,CACjD,aAAc,GACd,QAAW,CACb,CAAC,CACH,CAEA,SAAS,4BAA+B,CACtC,GAAG,oDAAuD,CACxD,sBAAsB,QAAQ,EAE9B,GAAM,CAAE,UAAW,MAAiB,EAAsB,CAAC,EAE3D,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,QAAQ,CACtC,CAAC,EAED,GAAG,mDAAsD,CACvD,sBAAsB,SAAS,EAC/B,GAAM,CAAE,UAAW,MAAiB,EAAsB,CAAC,EAE3D,MAAU,CACR,sBAAsB,QAAQ,EAC9B,SAAS,cAAc,IAAI,MAAM,kBAAkB,CAAC,CACtD,CAAC,EAED,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,QAAQ,CACtC,CAAC,EAED,GAAG,iDAAoD,CACrD,IAAM,EAAsB,GAAG,MAAM,SAAU,qBAAqB,EAC9D,CAAE,WAAY,MAAiB,EAAsB,CAAC,EAE5D,EAAQ,EAER,OAAO,CAAmB,CAAC,CAAC,qBAAqB,mBAAoB,OAAO,IAAI,QAAQ,CAAC,CAC3F,CAAC,CACH,CAAC"}
|
package/dist/hooks/use-idle.d.ts
CHANGED
package/dist/hooks/use-idle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useEffect as e,useRef as t,useState as n}from"react";const r={events:[`keydown`,`mousemove`,`touchmove`,`click`,`scroll`,`wheel`],initialState:!0};function useIdle(i,a){let{events:o,initialState:s}={...r,...a},[c,l]=n(s),u=t(-1);return e(()=>{let handleEvents=()=>{l(!1),u.current&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{l(!0)},i)};for(let e of o)document.addEventListener(e,handleEvents);return u.current=window.setTimeout(()=>{l(!0)},i),()=>{for(let e of o)document.removeEventListener(e,handleEvents);window.clearTimeout(u.current),u.current=-1}},[i]),c}export{useIdle};
|
|
2
2
|
//# sourceMappingURL=use-idle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-idle.js","names":[],"sources":["../../src/hooks/use-idle.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react'\n\nexport type UseIdleOptions = {\n events?: (keyof DocumentEventMap)[]\n initialState?: boolean\n}\n\nconst DEFAULT_OPTIONS: Required<UseIdleOptions> = {\n events: ['keydown', 'mousemove', 'touchmove', 'click', 'scroll', 'wheel'],\n initialState: true\n}\n\nexport function useIdle(timeout: number, options?: UseIdleOptions) {\n const { events, initialState } = { ...DEFAULT_OPTIONS, ...options }\n const [idle, setIdle] = useState(initialState)\n const timer = useRef(-1)\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: should not re-execute the effect when `events` changes\n useEffect(() => {\n const handleEvents = () => {\n setIdle(false)\n\n if (timer.current) {\n window.clearTimeout(timer.current)\n }\n\n timer.current = window.setTimeout(() => {\n setIdle(true)\n }, timeout)\n }\n\n for (const event of events) {\n document.addEventListener(event, handleEvents)\n }\n\n // Start the timer immediately instead of waiting for the first event to happen\n timer.current = window.setTimeout(() => {\n setIdle(true)\n }, timeout)\n\n return () => {\n for (const event of events) {\n document.removeEventListener(event, handleEvents)\n }\n\n window.clearTimeout(timer.current)\n timer.current = -1\n }\n }, [timeout])\n\n return idle\n}\n\nexport namespace useIdle {\n export type Options = UseIdleOptions\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-idle.js","names":[],"sources":["../../src/hooks/use-idle.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react'\n\nexport type UseIdleOptions = {\n events?: (keyof DocumentEventMap)[]\n initialState?: boolean\n}\n\nconst DEFAULT_OPTIONS: Required<UseIdleOptions> = {\n events: ['keydown', 'mousemove', 'touchmove', 'click', 'scroll', 'wheel'],\n initialState: true\n}\n\nexport function useIdle(timeout: number, options?: UseIdleOptions) {\n const { events, initialState } = { ...DEFAULT_OPTIONS, ...options }\n const [idle, setIdle] = useState(initialState)\n const timer = useRef(-1)\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: should not re-execute the effect when `events` changes\n useEffect(() => {\n const handleEvents = () => {\n setIdle(false)\n\n if (timer.current) {\n window.clearTimeout(timer.current)\n }\n\n timer.current = window.setTimeout(() => {\n setIdle(true)\n }, timeout)\n }\n\n for (const event of events) {\n document.addEventListener(event, handleEvents)\n }\n\n // Start the timer immediately instead of waiting for the first event to happen\n timer.current = window.setTimeout(() => {\n setIdle(true)\n }, timeout)\n\n return () => {\n for (const event of events) {\n document.removeEventListener(event, handleEvents)\n }\n\n window.clearTimeout(timer.current)\n timer.current = -1\n }\n }, [timeout])\n\n return idle\n}\n\nexport namespace useIdle {\n export type Options = UseIdleOptions\n}\n"],"mappings":"oGAOA,MAAM,EAA4C,CAChD,OAAQ,CAAC,UAAW,YAAa,YAAa,QAAS,SAAU,OAAO,EACxE,aAAc,EAChB,EAEA,SAAgB,QAAQ,EAAiB,EAA0B,CACjE,GAAM,CAAE,SAAQ,gBAAiB,CAAE,GAAG,EAAiB,GAAG,CAAQ,EAC5D,CAAC,EAAM,GAAW,EAAS,CAAY,EACvC,EAAQ,EAAO,EAAE,EAmCvB,OAhCA,MAAgB,CACd,IAAM,iBAAqB,CACzB,EAAQ,EAAK,EAET,EAAM,SACR,OAAO,aAAa,EAAM,OAAO,EAGnC,EAAM,QAAU,OAAO,eAAiB,CACtC,EAAQ,EAAI,CACd,EAAG,CAAO,CACZ,EAEA,IAAK,IAAM,KAAS,EAClB,SAAS,iBAAiB,EAAO,YAAY,EAQ/C,MAJA,GAAM,QAAU,OAAO,eAAiB,CACtC,EAAQ,EAAI,CACd,EAAG,CAAO,MAEG,CACX,IAAK,IAAM,KAAS,EAClB,SAAS,oBAAoB,EAAO,YAAY,EAGlD,OAAO,aAAa,EAAM,OAAO,EACjC,EAAM,QAAU,EAClB,CACF,EAAG,CAAC,CAAO,CAAC,EAEL,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useIdle as e}from"./use-idle.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";describe(`useIdle`,()=>{it(`starts idle by default`,()=>{vi.useFakeTimers();let{result:n}=t(()=>e(1e3));expect(n.current).toBe(!0)}),it(`supports a custom initial state and becomes idle after the timeout`,()=>{vi.useFakeTimers();let{result:r}=t(()=>e(1e3,{initialState:!1}));expect(r.current).toBe(!1),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r.current).toBe(!0)}),it(`becomes active on configured events and returns to idle after the timeout`,()=>{vi.useFakeTimers();let{result:r}=t(()=>e(1e3,{events:[`click`]}));n(()=>{document.dispatchEvent(new Event(`click`))}),expect(r.current).toBe(!1),n(()=>{vi.advanceTimersByTime(999)}),expect(r.current).toBe(!1),n(()=>{vi.advanceTimersByTime(1)}),expect(r.current).toBe(!0)}),it(`registers and removes only the configured event listeners`,()=>{vi.useFakeTimers();let n=vi.spyOn(document,`addEventListener`),r=vi.spyOn(document,`removeEventListener`),{unmount:i}=t(()=>e(1e3,{events:[`click`,`keydown`]}));expect(n).toHaveBeenCalledWith(`click`,expect.any(Function)),expect(n).toHaveBeenCalledWith(`keydown`,expect.any(Function)),expect(n).not.toHaveBeenCalledWith(`mousemove`,expect.any(Function)),i(),expect(r).toHaveBeenCalledWith(`click`,expect.any(Function)),expect(r).toHaveBeenCalledWith(`keydown`,expect.any(Function))}),it(`clears pending timers on unmount`,()=>{vi.useFakeTimers();let n=vi.spyOn(window,`clearTimeout`),{unmount:r}=t(()=>e(1e3));r(),expect(n).toHaveBeenCalled()})});
|
|
2
2
|
//# sourceMappingURL=use-idle.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-idle.spec.js","names":[],"sources":["../../src/hooks/use-idle.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useIdle } from './use-idle'\n\ndescribe('useIdle', () => {\n it('starts idle by default', () => {\n vi.useFakeTimers()\n\n const { result } = renderHook(() => useIdle(1000))\n\n expect(result.current).toBe(true)\n })\n\n it('supports a custom initial state and becomes idle after the timeout', () => {\n vi.useFakeTimers()\n\n const { result } = renderHook(() => useIdle(1000, { initialState: false }))\n\n expect(result.current).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(result.current).toBe(true)\n })\n\n it('becomes active on configured events and returns to idle after the timeout', () => {\n vi.useFakeTimers()\n\n const { result } = renderHook(() => useIdle(1000, { events: ['click'] }))\n\n act(() => {\n document.dispatchEvent(new Event('click'))\n })\n\n expect(result.current).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(999)\n })\n\n expect(result.current).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1)\n })\n\n expect(result.current).toBe(true)\n })\n\n it('registers and removes only the configured event listeners', () => {\n vi.useFakeTimers()\n const addEventListener = vi.spyOn(document, 'addEventListener')\n const removeEventListener = vi.spyOn(document, 'removeEventListener')\n\n const { unmount } = renderHook(() => useIdle(1000, { events: ['click', 'keydown'] }))\n\n expect(addEventListener).toHaveBeenCalledWith('click', expect.any(Function))\n expect(addEventListener).toHaveBeenCalledWith('keydown', expect.any(Function))\n expect(addEventListener).not.toHaveBeenCalledWith('mousemove', expect.any(Function))\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('click', expect.any(Function))\n expect(removeEventListener).toHaveBeenCalledWith('keydown', expect.any(Function))\n })\n\n it('clears pending timers on unmount', () => {\n vi.useFakeTimers()\n const clearTimeout = vi.spyOn(window, 'clearTimeout')\n const { unmount } = renderHook(() => useIdle(1000))\n\n unmount()\n\n expect(clearTimeout).toHaveBeenCalled()\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-idle.spec.js","names":[],"sources":["../../src/hooks/use-idle.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useIdle } from './use-idle'\n\ndescribe('useIdle', () => {\n it('starts idle by default', () => {\n vi.useFakeTimers()\n\n const { result } = renderHook(() => useIdle(1000))\n\n expect(result.current).toBe(true)\n })\n\n it('supports a custom initial state and becomes idle after the timeout', () => {\n vi.useFakeTimers()\n\n const { result } = renderHook(() => useIdle(1000, { initialState: false }))\n\n expect(result.current).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(result.current).toBe(true)\n })\n\n it('becomes active on configured events and returns to idle after the timeout', () => {\n vi.useFakeTimers()\n\n const { result } = renderHook(() => useIdle(1000, { events: ['click'] }))\n\n act(() => {\n document.dispatchEvent(new Event('click'))\n })\n\n expect(result.current).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(999)\n })\n\n expect(result.current).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1)\n })\n\n expect(result.current).toBe(true)\n })\n\n it('registers and removes only the configured event listeners', () => {\n vi.useFakeTimers()\n const addEventListener = vi.spyOn(document, 'addEventListener')\n const removeEventListener = vi.spyOn(document, 'removeEventListener')\n\n const { unmount } = renderHook(() => useIdle(1000, { events: ['click', 'keydown'] }))\n\n expect(addEventListener).toHaveBeenCalledWith('click', expect.any(Function))\n expect(addEventListener).toHaveBeenCalledWith('keydown', expect.any(Function))\n expect(addEventListener).not.toHaveBeenCalledWith('mousemove', expect.any(Function))\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('click', expect.any(Function))\n expect(removeEventListener).toHaveBeenCalledWith('keydown', expect.any(Function))\n })\n\n it('clears pending timers on unmount', () => {\n vi.useFakeTimers()\n const clearTimeout = vi.spyOn(window, 'clearTimeout')\n const { unmount } = renderHook(() => useIdle(1000))\n\n unmount()\n\n expect(clearTimeout).toHaveBeenCalled()\n })\n})\n"],"mappings":"oIAIA,SAAS,cAAiB,CACxB,GAAG,6BAAgC,CACjC,GAAG,cAAc,EAEjB,GAAM,CAAE,UAAW,MAAiB,EAAQ,GAAI,CAAC,EAEjD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAI,CAClC,CAAC,EAED,GAAG,yEAA4E,CAC7E,GAAG,cAAc,EAEjB,GAAM,CAAE,UAAW,MAAiB,EAAQ,IAAM,CAAE,aAAc,EAAM,CAAC,CAAC,EAE1E,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAK,EAEjC,MAAU,CACR,GAAG,oBAAoB,GAAI,CAC7B,CAAC,EAED,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAI,CAClC,CAAC,EAED,GAAG,gFAAmF,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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useCallback as e,useEffect as t,useRef as n,useState as r}from"react";function useInterval(i,a,{autoInvoke:o=!1}={}){let s=n(null),c=n(null),l=n(a),[u,d]=r(!1);l.current=a;let f=e(()=>{d(e=>(!e&&!s.current&&(s.current=window.setInterval(c.current,l.current)),!0))},[]),p=e(()=>{d(!1),s.current&&window.clearInterval(s.current),s.current=null},[]),m=e(()=>{d(e=>e?(s.current&&window.clearInterval(s.current),s.current=null,!1):(s.current||=window.setInterval(c.current,l.current),!0))},[]);return t(()=>(c.current=i,u&&f(),p),[i,u,a,f,p]),t(()=>{o&&f()},[f]),{start:f,stop:p,toggle:m,active:u}}export{useInterval};
|
|
2
2
|
//# sourceMappingURL=use-interval.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-interval.js","names":[],"sources":["../../src/hooks/use-interval.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\nexport type UseIntervalOptions = {\n /** If set, the interval will start automatically when the component is mounted, `false` by default */\n autoInvoke?: boolean\n}\n\nexport type UseIntervalReturnValue = {\n /** Starts the interval */\n start: () => void\n\n /** Stops the interval */\n stop: () => void\n\n /** Toggles the interval */\n toggle: () => void\n\n /** Indicates if the interval is active */\n active: boolean\n}\n\nexport function useInterval(\n fn: () => void,\n interval: number,\n { autoInvoke = false }: UseIntervalOptions = {}\n): UseIntervalReturnValue {\n const intervalRef = useRef<number | null>(null)\n const fnRef = useRef<() => void>(null)\n const intervalValueRef = useRef(interval)\n\n const [active, setActive] = useState(false)\n\n intervalValueRef.current = interval\n\n const start = useCallback(() => {\n setActive((old) => {\n if (!old && !intervalRef.current) {\n intervalRef.current = window.setInterval(fnRef.current!, intervalValueRef.current)\n }\n return true\n })\n }, [])\n\n const stop = useCallback(() => {\n setActive(false)\n if (intervalRef.current) {\n window.clearInterval(intervalRef.current)\n }\n intervalRef.current = null\n }, [])\n\n const toggle = useCallback(() => {\n setActive((current) => {\n if (current) {\n if (intervalRef.current) {\n window.clearInterval(intervalRef.current)\n }\n intervalRef.current = null\n return false\n }\n if (!intervalRef.current) {\n intervalRef.current = window.setInterval(fnRef.current!, intervalValueRef.current)\n }\n return true\n })\n }, [])\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: should includes the 'interval'\n useEffect(() => {\n fnRef.current = fn\n active && start()\n return stop\n }, [fn, active, interval, start, stop])\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: should execute only once\n useEffect(() => {\n if (autoInvoke) {\n start()\n }\n }, [start])\n\n return { start, stop, toggle, active }\n}\n\nexport namespace useInterval {\n export type Options = UseIntervalOptions\n export type ReturnValue = UseIntervalReturnValue\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-interval.js","names":[],"sources":["../../src/hooks/use-interval.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\nexport type UseIntervalOptions = {\n /** If set, the interval will start automatically when the component is mounted, `false` by default */\n autoInvoke?: boolean\n}\n\nexport type UseIntervalReturnValue = {\n /** Starts the interval */\n start: () => void\n\n /** Stops the interval */\n stop: () => void\n\n /** Toggles the interval */\n toggle: () => void\n\n /** Indicates if the interval is active */\n active: boolean\n}\n\nexport function useInterval(\n fn: () => void,\n interval: number,\n { autoInvoke = false }: UseIntervalOptions = {}\n): UseIntervalReturnValue {\n const intervalRef = useRef<number | null>(null)\n const fnRef = useRef<() => void>(null)\n const intervalValueRef = useRef(interval)\n\n const [active, setActive] = useState(false)\n\n intervalValueRef.current = interval\n\n const start = useCallback(() => {\n setActive((old) => {\n if (!old && !intervalRef.current) {\n intervalRef.current = window.setInterval(fnRef.current!, intervalValueRef.current)\n }\n return true\n })\n }, [])\n\n const stop = useCallback(() => {\n setActive(false)\n if (intervalRef.current) {\n window.clearInterval(intervalRef.current)\n }\n intervalRef.current = null\n }, [])\n\n const toggle = useCallback(() => {\n setActive((current) => {\n if (current) {\n if (intervalRef.current) {\n window.clearInterval(intervalRef.current)\n }\n intervalRef.current = null\n return false\n }\n if (!intervalRef.current) {\n intervalRef.current = window.setInterval(fnRef.current!, intervalValueRef.current)\n }\n return true\n })\n }, [])\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: should includes the 'interval'\n useEffect(() => {\n fnRef.current = fn\n active && start()\n return stop\n }, [fn, active, interval, start, stop])\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: should execute only once\n useEffect(() => {\n if (autoInvoke) {\n start()\n }\n }, [start])\n\n return { start, stop, toggle, active }\n}\n\nexport namespace useInterval {\n export type Options = UseIntervalOptions\n export type ReturnValue = UseIntervalReturnValue\n}\n"],"mappings":"qHAqBA,SAAgB,YACd,EACA,EACA,CAAE,aAAa,IAA8B,CAAC,EACtB,CACxB,IAAM,EAAc,EAAsB,IAAI,EACxC,EAAQ,EAAmB,IAAI,EAC/B,EAAmB,EAAO,CAAQ,EAElC,CAAC,EAAQ,GAAa,EAAS,EAAK,EAE1C,EAAiB,QAAU,EAE3B,IAAM,EAAQ,MAAkB,CAC9B,EAAW,IACL,CAAC,GAAO,CAAC,EAAY,UACvB,EAAY,QAAU,OAAO,YAAY,EAAM,QAAU,EAAiB,OAAO,GAE5E,GACR,CACH,EAAG,CAAC,CAAC,EAEC,EAAO,MAAkB,CAC7B,EAAU,EAAK,EACX,EAAY,SACd,OAAO,cAAc,EAAY,OAAO,EAE1C,EAAY,QAAU,IACxB,EAAG,CAAC,CAAC,EAEC,EAAS,MAAkB,CAC/B,EAAW,GACL,GACE,EAAY,SACd,OAAO,cAAc,EAAY,OAAO,EAE1C,EAAY,QAAU,KACf,KAET,AACE,EAAY,UAAU,OAAO,YAAY,EAAM,QAAU,EAAiB,OAAO,EAE5E,GACR,CACH,EAAG,CAAC,CAAC,EAgBL,OAbA,OACE,EAAM,QAAU,EAChB,GAAU,EAAM,EACT,GACN,CAAC,EAAI,EAAQ,EAAU,EAAO,CAAI,CAAC,EAGtC,MAAgB,CACV,GACF,EAAM,CAEV,EAAG,CAAC,CAAK,CAAC,EAEH,CAAE,QAAO,OAAM,SAAQ,QAAO,CACvC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useInterval as e}from"./use-interval.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";describe(`useInterval`,()=>{it(`does not start by default`,()=>{vi.useFakeTimers();let r=vi.fn(),{result:i}=t(()=>e(r,1e3));expect(i.current.active).toBe(!1),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).not.toHaveBeenCalled()}),it(`starts and stops the interval`,()=>{vi.useFakeTimers();let r=vi.fn(),{result:i}=t(()=>e(r,1e3));n(()=>i.current.start()),expect(i.current.active).toBe(!0),n(()=>{vi.advanceTimersByTime(3e3)}),expect(r).toHaveBeenCalledTimes(3),n(()=>i.current.stop()),expect(i.current.active).toBe(!1),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).toHaveBeenCalledTimes(3)}),it(`toggles the interval`,()=>{vi.useFakeTimers();let r=vi.fn(),{result:i}=t(()=>e(r,1e3));n(()=>i.current.toggle()),expect(i.current.active).toBe(!0),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).toHaveBeenCalledTimes(1),n(()=>i.current.toggle()),expect(i.current.active).toBe(!1),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).toHaveBeenCalledTimes(1)}),it(`starts automatically when autoInvoke is enabled`,()=>{vi.useFakeTimers();let r=vi.fn(),{result:i}=t(()=>e(r,1e3,{autoInvoke:!0}));expect(i.current.active).toBe(!0),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).toHaveBeenCalledTimes(1)}),it(`uses the latest callback after rerendering`,()=>{vi.useFakeTimers();let r=vi.fn(),i=vi.fn(),{result:a,rerender:o}=t(({callback:t})=>e(t,1e3),{initialProps:{callback:r}});n(()=>a.current.start()),n(()=>{vi.advanceTimersByTime(1e3)}),o({callback:i}),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).toHaveBeenCalledTimes(1),expect(i).toHaveBeenCalledTimes(1)}),it(`cleans the interval on unmount`,()=>{vi.useFakeTimers();let r=vi.fn(),{result:i,unmount:a}=t(()=>e(r,1e3));n(()=>i.current.start()),a(),n(()=>{vi.advanceTimersByTime(1e3)}),expect(r).not.toHaveBeenCalled()})});
|
|
2
2
|
//# sourceMappingURL=use-interval.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-interval.spec.js","names":[],"sources":["../../src/hooks/use-interval.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useInterval } from './use-interval'\n\ndescribe('useInterval', () => {\n it('does not start by default', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n\n const { result } = renderHook(() => useInterval(callback, 1000))\n\n expect(result.current.active).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).not.toHaveBeenCalled()\n })\n\n it('starts and stops the interval', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n const { result } = renderHook(() => useInterval(callback, 1000))\n\n act(() => result.current.start())\n expect(result.current.active).toBe(true)\n\n act(() => {\n vi.advanceTimersByTime(3000)\n })\n\n expect(callback).toHaveBeenCalledTimes(3)\n\n act(() => result.current.stop())\n expect(result.current.active).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(3)\n })\n\n it('toggles the interval', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n const { result } = renderHook(() => useInterval(callback, 1000))\n\n act(() => result.current.toggle())\n expect(result.current.active).toBe(true)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(1)\n\n act(() => result.current.toggle())\n expect(result.current.active).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(1)\n })\n\n it('starts automatically when autoInvoke is enabled', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n\n const { result } = renderHook(() => useInterval(callback, 1000, { autoInvoke: true }))\n\n expect(result.current.active).toBe(true)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(1)\n })\n\n it('uses the latest callback after rerendering', () => {\n vi.useFakeTimers()\n const firstCallback = vi.fn()\n const secondCallback = vi.fn()\n const { result, rerender } = renderHook(({ callback }) => useInterval(callback, 1000), {\n initialProps: { callback: firstCallback }\n })\n\n act(() => result.current.start())\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n rerender({ callback: secondCallback })\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(firstCallback).toHaveBeenCalledTimes(1)\n expect(secondCallback).toHaveBeenCalledTimes(1)\n })\n\n it('cleans the interval on unmount', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n const { result, unmount } = renderHook(() => useInterval(callback, 1000))\n\n act(() => result.current.start())\n unmount()\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).not.toHaveBeenCalled()\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-interval.spec.js","names":[],"sources":["../../src/hooks/use-interval.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useInterval } from './use-interval'\n\ndescribe('useInterval', () => {\n it('does not start by default', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n\n const { result } = renderHook(() => useInterval(callback, 1000))\n\n expect(result.current.active).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).not.toHaveBeenCalled()\n })\n\n it('starts and stops the interval', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n const { result } = renderHook(() => useInterval(callback, 1000))\n\n act(() => result.current.start())\n expect(result.current.active).toBe(true)\n\n act(() => {\n vi.advanceTimersByTime(3000)\n })\n\n expect(callback).toHaveBeenCalledTimes(3)\n\n act(() => result.current.stop())\n expect(result.current.active).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(3)\n })\n\n it('toggles the interval', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n const { result } = renderHook(() => useInterval(callback, 1000))\n\n act(() => result.current.toggle())\n expect(result.current.active).toBe(true)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(1)\n\n act(() => result.current.toggle())\n expect(result.current.active).toBe(false)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(1)\n })\n\n it('starts automatically when autoInvoke is enabled', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n\n const { result } = renderHook(() => useInterval(callback, 1000, { autoInvoke: true }))\n\n expect(result.current.active).toBe(true)\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).toHaveBeenCalledTimes(1)\n })\n\n it('uses the latest callback after rerendering', () => {\n vi.useFakeTimers()\n const firstCallback = vi.fn()\n const secondCallback = vi.fn()\n const { result, rerender } = renderHook(({ callback }) => useInterval(callback, 1000), {\n initialProps: { callback: firstCallback }\n })\n\n act(() => result.current.start())\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n rerender({ callback: secondCallback })\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(firstCallback).toHaveBeenCalledTimes(1)\n expect(secondCallback).toHaveBeenCalledTimes(1)\n })\n\n it('cleans the interval on unmount', () => {\n vi.useFakeTimers()\n const callback = vi.fn()\n const { result, unmount } = renderHook(() => useInterval(callback, 1000))\n\n act(() => result.current.start())\n unmount()\n\n act(() => {\n vi.advanceTimersByTime(1000)\n })\n\n expect(callback).not.toHaveBeenCalled()\n })\n})\n"],"mappings":"4IAIA,SAAS,kBAAqB,CAC5B,GAAG,gCAAmC,CACpC,GAAG,cAAc,EACjB,IAAM,EAAW,GAAG,GAAG,EAEjB,CAAE,UAAW,MAAiB,EAA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G,cAAc,EACjB,IAAM,EAAW,GAAG,GAAG,EAEjB,CAAE,UAAW,MAAiB,EAAY,EAAU,IAAM,CAAE,WAAY,EAAK,CAAC,CAAC,EAErF,OAAO,EAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,EAAI,EAEvC,MAAU,CACR,GAAG,oBAAoB,GAAI,CAC7B,CAAC,EAED,OAAO,CAAQ,CAAC,CAAC,sBAAsB,CAAC,CAC1C,CAAC,EAED,GAAG,iDAAoD,CACrD,GAAG,cAAc,EACjB,IAAM,EAAgB,GAAG,GAAG,EACtB,EAAiB,GAAG,GAAG,EACvB,CAAE,SAAQ,YAAa,GAAY,CAAE,cAAe,EAAY,EAAU,GAAI,EAAG,CACrF,aAAc,CAAE,SAAU,CAAc,CAC1C,CAAC,EAED,MAAU,EAAO,QAAQ,MAAM,CAAC,EAChC,MAAU,CACR,GAAG,oBAAoB,GAAI,CAC7B,CAAC,EAED,EAAS,CAAE,SAAU,CAAe,CAAC,EAErC,MAAU,CACR,GAAG,oBAAoB,GAAI,CAC7B,CAAC,EAED,OAAO,CAAa,CAAC,CAAC,sBAAsB,CAAC,EAC7C,OAAO,CAAc,CAAC,CAAC,sBAAsB,CAAC,CAChD,CAAC,EAED,GAAG,qCAAwC,CACzC,GAAG,cAAc,EACjB,IAAM,EAAW,GAAG,GAAG,EACjB,CAAE,SAAQ,WAAY,MAAiB,EAAY,EAAU,GAAI,CAAC,EAExE,MAAU,EAAO,QAAQ,MAAM,CAAC,EAChC,EAAQ,EAER,MAAU,CACR,GAAG,oBAAoB,GAAI,CAC7B,CAAC,EAED,OAAO,CAAQ,CAAC,CAAC,IAAI,iBAAiB,CACxC,CAAC,CACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useCallback as e,useEffect as t,useRef as n,useState as r}from"react";function parseStorageValue(e){try{return JSON.parse(e)}catch{return e}}function readStorageValue(e,t){if(typeof window>`u`)return t;try{let n=window.localStorage.getItem(e);return n===null?t:parseStorageValue(n)}catch{return t}}function writeStorageValue(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,String(JSON.stringify(t)))}catch{}}function useLocalStorage(i,a={}){let{defaultValue:o,sync:s=!0}=a,c=n(o),[l,u]=r(()=>readStorageValue(i,o)),d=n(l);c.current=o,d.current=l;let f=e(e=>{let t=typeof e==`function`?e(d.current):e;d.current=t,writeStorageValue(i,t),u(t)},[i]);return t(()=>{if(!s||typeof window>`u`)return;let handleStorage=e=>{if(e.storageArea!==window.localStorage||e.key!==i)return;let t=e.newValue===null?c.current:parseStorageValue(e.newValue);d.current=t,u(t)};return window.addEventListener(`storage`,handleStorage),()=>window.removeEventListener(`storage`,handleStorage)},[i,s]),[l,f]}export{useLocalStorage};
|
|
2
2
|
//# sourceMappingURL=use-local-storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.js","names":[],"sources":["../../src/hooks/use-local-storage.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\nexport type UseLocalStorageOptions<T> = {\n defaultValue?: T\n sync?: boolean\n}\n\nfunction parseStorageValue<T>(value: string) {\n try {\n return JSON.parse(value) as T\n } catch {\n return value as T\n }\n}\n\nfunction readStorageValue<T>(key: string, defaultValue: T | undefined) {\n if (typeof window === 'undefined') {\n return defaultValue\n }\n\n try {\n const item = window.localStorage.getItem(key)\n\n if (item === null) {\n return defaultValue\n }\n\n return parseStorageValue<T>(item)\n } catch {\n return defaultValue\n }\n}\n\nfunction writeStorageValue<T>(key: string, value: T) {\n if (typeof window === 'undefined') {\n return\n }\n\n try {\n window.localStorage.setItem(key, String(JSON.stringify(value)))\n } catch {}\n}\n\nexport function useLocalStorage<T>(\n key: string,\n options: UseLocalStorageOptions<T> & { defaultValue: T }\n): [T, React.Dispatch<React.SetStateAction<T>>]\n\nexport function useLocalStorage<T = undefined>(\n key: string,\n options?: UseLocalStorageOptions<T>\n): [T | undefined, React.Dispatch<React.SetStateAction<T | undefined>>]\n\nexport function useLocalStorage<T>(key: string, options: UseLocalStorageOptions<T> = {}) {\n const { defaultValue, sync = true } = options\n const defaultValueRef = useRef(defaultValue)\n const [storedValue, setStoredValue] = useState<T | undefined>(() => readStorageValue<T>(key, defaultValue))\n const storedValueRef = useRef(storedValue)\n\n defaultValueRef.current = defaultValue\n storedValueRef.current = storedValue\n\n const setValue = useCallback<React.Dispatch<React.SetStateAction<T | undefined>>>(\n (value) => {\n const nextValue =\n typeof value === 'function'\n ? (value as (previousValue: T | undefined) => T | undefined)(storedValueRef.current)\n : value\n\n storedValueRef.current = nextValue\n writeStorageValue(key, nextValue)\n setStoredValue(nextValue)\n },\n [key]\n )\n\n useEffect(() => {\n if (!sync || typeof window === 'undefined') {\n return\n }\n\n const handleStorage = (event: StorageEvent) => {\n if (event.storageArea !== window.localStorage || event.key !== key) {\n return\n }\n\n const nextValue = event.newValue === null ? defaultValueRef.current : parseStorageValue<T>(event.newValue)\n\n storedValueRef.current = nextValue\n setStoredValue(nextValue)\n }\n\n window.addEventListener('storage', handleStorage)\n\n return () => window.removeEventListener('storage', handleStorage)\n }, [key, sync])\n\n return [storedValue, setValue]\n}\n\nexport namespace useLocalStorage {\n export type Options<T> = UseLocalStorageOptions<T>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-local-storage.js","names":[],"sources":["../../src/hooks/use-local-storage.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\nexport type UseLocalStorageOptions<T> = {\n defaultValue?: T\n sync?: boolean\n}\n\nfunction parseStorageValue<T>(value: string) {\n try {\n return JSON.parse(value) as T\n } catch {\n return value as T\n }\n}\n\nfunction readStorageValue<T>(key: string, defaultValue: T | undefined) {\n if (typeof window === 'undefined') {\n return defaultValue\n }\n\n try {\n const item = window.localStorage.getItem(key)\n\n if (item === null) {\n return defaultValue\n }\n\n return parseStorageValue<T>(item)\n } catch {\n return defaultValue\n }\n}\n\nfunction writeStorageValue<T>(key: string, value: T) {\n if (typeof window === 'undefined') {\n return\n }\n\n try {\n window.localStorage.setItem(key, String(JSON.stringify(value)))\n } catch {}\n}\n\nexport function useLocalStorage<T>(\n key: string,\n options: UseLocalStorageOptions<T> & { defaultValue: T }\n): [T, React.Dispatch<React.SetStateAction<T>>]\n\nexport function useLocalStorage<T = undefined>(\n key: string,\n options?: UseLocalStorageOptions<T>\n): [T | undefined, React.Dispatch<React.SetStateAction<T | undefined>>]\n\nexport function useLocalStorage<T>(key: string, options: UseLocalStorageOptions<T> = {}) {\n const { defaultValue, sync = true } = options\n const defaultValueRef = useRef(defaultValue)\n const [storedValue, setStoredValue] = useState<T | undefined>(() => readStorageValue<T>(key, defaultValue))\n const storedValueRef = useRef(storedValue)\n\n defaultValueRef.current = defaultValue\n storedValueRef.current = storedValue\n\n const setValue = useCallback<React.Dispatch<React.SetStateAction<T | undefined>>>(\n (value) => {\n const nextValue =\n typeof value === 'function'\n ? (value as (previousValue: T | undefined) => T | undefined)(storedValueRef.current)\n : value\n\n storedValueRef.current = nextValue\n writeStorageValue(key, nextValue)\n setStoredValue(nextValue)\n },\n [key]\n )\n\n useEffect(() => {\n if (!sync || typeof window === 'undefined') {\n return\n }\n\n const handleStorage = (event: StorageEvent) => {\n if (event.storageArea !== window.localStorage || event.key !== key) {\n return\n }\n\n const nextValue = event.newValue === null ? defaultValueRef.current : parseStorageValue<T>(event.newValue)\n\n storedValueRef.current = nextValue\n setStoredValue(nextValue)\n }\n\n window.addEventListener('storage', handleStorage)\n\n return () => window.removeEventListener('storage', handleStorage)\n }, [key, sync])\n\n return [storedValue, setValue]\n}\n\nexport namespace useLocalStorage {\n export type Options<T> = UseLocalStorageOptions<T>\n}\n"],"mappings":"qHAOA,SAAS,kBAAqB,EAAe,CAC3C,GAAI,CACF,OAAO,KAAK,MAAM,CAAK,CACzB,MAAQ,CACN,OAAO,CACT,CACF,CAEA,SAAS,iBAAoB,EAAa,EAA6B,CACrE,GAAI,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}from"./use-local-storage.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";describe(`useLocalStorage`,()=>{it(`returns the default value when storage is empty`,()=>{let{result:n}=t(()=>e(`settings`,{defaultValue:{compact:!1}}));expect(n.current[0]).toEqual({compact:!1})}),it(`reads an existing JSON value from localStorage`,()=>{window.localStorage.setItem(`settings`,JSON.stringify({compact:!0}));let{result:n}=t(()=>e(`settings`,{defaultValue:{compact:!1}}));expect(n.current[0]).toEqual({compact:!0})}),it(`writes serialized values to localStorage`,()=>{let{result:r}=t(()=>e(`settings`,{defaultValue:{compact:!1}}));n(()=>r.current[1]({compact:!0})),expect(r.current[0]).toEqual({compact:!0}),expect(window.localStorage.getItem(`settings`)).toBe(JSON.stringify({compact:!0}))}),it(`supports functional updates`,()=>{let{result:r}=t(()=>e(`count`,{defaultValue:1}));n(()=>r.current[1](e=>e+1)),expect(r.current[0]).toBe(2),expect(window.localStorage.getItem(`count`)).toBe(`2`)}),it(`syncs updates from storage events for the same key`,()=>{let{result:r}=t(()=>e(`settings`,{defaultValue:{compact:!1}}));n(()=>{window.dispatchEvent(new StorageEvent(`storage`,{key:`settings`,newValue:JSON.stringify({compact:!0}),storageArea:window.localStorage}))}),expect(r.current[0]).toEqual({compact:!0})}),it(`ignores storage events for other keys`,()=>{let{result:r}=t(()=>e(`settings`,{defaultValue:{compact:!1}}));n(()=>{window.dispatchEvent(new StorageEvent(`storage`,{key:`profile`,newValue:JSON.stringify({compact:!0}),storageArea:window.localStorage}))}),expect(r.current[0]).toEqual({compact:!1})}),it(`does not subscribe to storage events when sync is disabled`,()=>{let{result:r}=t(()=>e(`settings`,{defaultValue:{compact:!1},sync:!1}));n(()=>{window.dispatchEvent(new StorageEvent(`storage`,{key:`settings`,newValue:JSON.stringify({compact:!0}),storageArea:window.localStorage}))}),expect(r.current[0]).toEqual({compact:!1})})});
|
|
2
2
|
//# sourceMappingURL=use-local-storage.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-local-storage.spec.js","names":[],"sources":["../../src/hooks/use-local-storage.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useLocalStorage } from './use-local-storage'\n\ndescribe('useLocalStorage', () => {\n it('returns the default value when storage is empty', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n expect(result.current[0]).toEqual({ compact: false })\n })\n\n it('reads an existing JSON value from localStorage', () => {\n window.localStorage.setItem('settings', JSON.stringify({ compact: true }))\n\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n expect(result.current[0]).toEqual({ compact: true })\n })\n\n it('writes serialized values to localStorage', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n act(() => result.current[1]({ compact: true }))\n\n expect(result.current[0]).toEqual({ compact: true })\n expect(window.localStorage.getItem('settings')).toBe(JSON.stringify({ compact: true }))\n })\n\n it('supports functional updates', () => {\n const { result } = renderHook(() => useLocalStorage('count', { defaultValue: 1 }))\n\n act(() => result.current[1]((current) => current + 1))\n\n expect(result.current[0]).toBe(2)\n expect(window.localStorage.getItem('count')).toBe('2')\n })\n\n it('syncs updates from storage events for the same key', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n act(() => {\n window.dispatchEvent(\n new StorageEvent('storage', {\n key: 'settings',\n newValue: JSON.stringify({ compact: true }),\n storageArea: window.localStorage\n })\n )\n })\n\n expect(result.current[0]).toEqual({ compact: true })\n })\n\n it('ignores storage events for other keys', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n act(() => {\n window.dispatchEvent(\n new StorageEvent('storage', {\n key: 'profile',\n newValue: JSON.stringify({ compact: true }),\n storageArea: window.localStorage\n })\n )\n })\n\n expect(result.current[0]).toEqual({ compact: false })\n })\n\n it('does not subscribe to storage events when sync is disabled', () => {\n const { result } = renderHook(() =>\n useLocalStorage('settings', {\n defaultValue: { compact: false },\n sync: false\n })\n )\n\n act(() => {\n window.dispatchEvent(\n new StorageEvent('storage', {\n key: 'settings',\n newValue: JSON.stringify({ compact: true }),\n storageArea: window.localStorage\n })\n )\n })\n\n expect(result.current[0]).toEqual({ compact: false })\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-local-storage.spec.js","names":[],"sources":["../../src/hooks/use-local-storage.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useLocalStorage } from './use-local-storage'\n\ndescribe('useLocalStorage', () => {\n it('returns the default value when storage is empty', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n expect(result.current[0]).toEqual({ compact: false })\n })\n\n it('reads an existing JSON value from localStorage', () => {\n window.localStorage.setItem('settings', JSON.stringify({ compact: true }))\n\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n expect(result.current[0]).toEqual({ compact: true })\n })\n\n it('writes serialized values to localStorage', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n act(() => result.current[1]({ compact: true }))\n\n expect(result.current[0]).toEqual({ compact: true })\n expect(window.localStorage.getItem('settings')).toBe(JSON.stringify({ compact: true }))\n })\n\n it('supports functional updates', () => {\n const { result } = renderHook(() => useLocalStorage('count', { defaultValue: 1 }))\n\n act(() => result.current[1]((current) => current + 1))\n\n expect(result.current[0]).toBe(2)\n expect(window.localStorage.getItem('count')).toBe('2')\n })\n\n it('syncs updates from storage events for the same key', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n act(() => {\n window.dispatchEvent(\n new StorageEvent('storage', {\n key: 'settings',\n newValue: JSON.stringify({ compact: true }),\n storageArea: window.localStorage\n })\n )\n })\n\n expect(result.current[0]).toEqual({ compact: true })\n })\n\n it('ignores storage events for other keys', () => {\n const { result } = renderHook(() => useLocalStorage('settings', { defaultValue: { compact: false } }))\n\n act(() => {\n window.dispatchEvent(\n new StorageEvent('storage', {\n key: 'profile',\n newValue: JSON.stringify({ compact: true }),\n storageArea: window.localStorage\n })\n )\n })\n\n expect(result.current[0]).toEqual({ compact: false })\n })\n\n it('does not subscribe to storage events when sync is disabled', () => {\n const { result } = renderHook(() =>\n useLocalStorage('settings', {\n defaultValue: { compact: false },\n sync: false\n })\n )\n\n act(() => {\n window.dispatchEvent(\n new StorageEvent('storage', {\n key: 'settings',\n newValue: JSON.stringify({ compact: true }),\n storageArea: window.localStorage\n })\n )\n })\n\n expect(result.current[0]).toEqual({ compact: false })\n })\n})\n"],"mappings":"qJAIA,SAAS,sBAAyB,CAChC,GAAG,sDAAyD,CAC1D,GAAM,CAAE,UAAW,MAAiB,EAAgB,WAAY,CAAE,aAAc,CAAE,QAAS,EAAM,CAAE,CAAC,CAAC,EAErG,OAAO,EAAO,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAE,QAAS,EAAM,CAAC,CACtD,CAAC,EAED,GAAG,qDAAwD,CACzD,OAAO,aAAa,QAAQ,WAAY,KAAK,UAAU,CAAE,QAAS,EAAK,CAAC,CAAC,EAEzE,GAAM,CAAE,UAAW,MAAiB,EAAgB,WAAY,CAAE,aAAc,CAAE,QAAS,EAAM,CAAE,CAAC,CAAC,EAErG,OAAO,EAAO,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAE,QAAS,EAAK,CAAC,CACrD,CAAC,EAED,GAAG,+CAAkD,CACnD,GAAM,CAAE,UAAW,MAAiB,EAAgB,WAAY,CAAE,aAAc,CAAE,QAAS,EAAM,CAAE,CAAC,CAAC,EAErG,MAAU,EAAO,QAAQ,EAAE,CAAC,CAAE,QAAS,EAAK,CAAC,CAAC,EAE9C,OAAO,EAAO,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAE,QAAS,EAAK,CAAC,EACnD,OAAO,OAAO,aAAa,QAAQ,UAAU,CAAC,CAAC,CAAC,KAAK,KAAK,UAAU,CAAE,QAAS,EAAK,CAAC,CAAC,CACxF,CAAC,EAED,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AO,YACtB,CAAC,CACH,CACF,CAAC,EAED,OAAO,EAAO,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAE,QAAS,EAAM,CAAC,CACtD,CAAC,CACH,CAAC"}
|
package/dist/hooks/use-mask.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as __name } from "../
|
|
1
|
+
import { n as __name } from "../rolldown-runtime-Bdj-bS2b.js";
|
|
2
2
|
import { MaskOptions, MaskOptions as MaskOptions$1, ModifiedData, Modify, Replacement, Track, TrackingData } from "@react-input/mask";
|
|
3
3
|
|
|
4
4
|
//#region src/hooks/use-mask.d.ts
|
package/dist/hooks/use-mask.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useMask as e}from"@react-input/mask";const t={9:/\d/,a:/[A-Za-z]/,"*":/./};function useMask(n={}){let{replacement:r,...i}=n;return e({...i,replacement:r??t})}export{useMask};
|
|
2
2
|
//# sourceMappingURL=use-mask.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mask.js","names":["useReactInputMask"],"sources":["../../src/hooks/use-mask.ts"],"sourcesContent":["import type { MaskOptions, Replacement } from '@react-input/mask'\nimport { useMask as useReactInputMask } from '@react-input/mask'\n\nexport type { MaskOptions, ModifiedData, Modify, Replacement, Track, TrackingData } from '@react-input/mask'\n\nconst DEFAULT_REPLACEMENT: Replacement = {\n 9: /\\d/,\n a: /[A-Za-z]/,\n '*': /./\n}\n\nexport type UseMaskOptions = MaskOptions\n\nexport function useMask(options: UseMaskOptions = {}) {\n const { replacement, ...rest } = options\n return useReactInputMask({\n ...rest,\n replacement: replacement ?? DEFAULT_REPLACEMENT\n })\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-mask.js","names":["useReactInputMask"],"sources":["../../src/hooks/use-mask.ts"],"sourcesContent":["import type { MaskOptions, Replacement } from '@react-input/mask'\nimport { useMask as useReactInputMask } from '@react-input/mask'\n\nexport type { MaskOptions, ModifiedData, Modify, Replacement, Track, TrackingData } from '@react-input/mask'\n\nconst DEFAULT_REPLACEMENT: Replacement = {\n 9: /\\d/,\n a: /[A-Za-z]/,\n '*': /./\n}\n\nexport type UseMaskOptions = MaskOptions\n\nexport function useMask(options: UseMaskOptions = {}) {\n const { replacement, ...rest } = options\n return useReactInputMask({\n ...rest,\n replacement: replacement ?? DEFAULT_REPLACEMENT\n })\n}\n"],"mappings":"oFAKA,MAAM,EAAmC,CACvC,EAAG,KACH,EAAG,WACH,IAAK,GACP,EAIA,SAAgB,QAAQ,EAA0B,CAAC,EAAG,CACpD,GAAM,CAAE,cAAa,GAAG,GAAS,EACjC,OAAOA,EAAkB,CACvB,GAAG,EACH,YAAa,GAAe,CAC9B,CAAC,CACH"}
|
package/dist/hooks/use-mobile.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import*as e from"react";function useIsMobile(){let[t,n]=e.useState(void 0);return e.useEffect(()=>{let e=window.matchMedia(`(max-width: 767px)`),onChange=()=>{n(window.innerWidth<768)};return e.addEventListener(`change`,onChange),n(window.innerWidth<768),()=>e.removeEventListener(`change`,onChange)},[]),!!t}export{useIsMobile};
|
|
2
2
|
//# sourceMappingURL=use-mobile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mobile.js","names":[],"sources":["../../src/hooks/use-mobile.ts"],"sourcesContent":["import * as React from 'react'\n\nconst MOBILE_BREAKPOINT = 768\n\nexport function useIsMobile() {\n const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)\n\n React.useEffect(() => {\n const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)\n const onChange = () => {\n setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)\n }\n mql.addEventListener('change', onChange)\n setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)\n return () => mql.removeEventListener('change', onChange)\n }, [])\n\n return !!isMobile\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-mobile.js","names":[],"sources":["../../src/hooks/use-mobile.ts"],"sourcesContent":["import * as React from 'react'\n\nconst MOBILE_BREAKPOINT = 768\n\nexport function useIsMobile() {\n const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)\n\n React.useEffect(() => {\n const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)\n const onChange = () => {\n setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)\n }\n mql.addEventListener('change', onChange)\n setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)\n return () => mql.removeEventListener('change', onChange)\n }, [])\n\n return !!isMobile\n}\n"],"mappings":"gEAIA,SAAgB,aAAc,CAC5B,GAAM,CAAC,EAAU,GAAe,EAAM,SAA8B,IAAA,EAAS,EAY7E,OAVA,EAAM,cAAgB,CACpB,IAAM,EAAM,OAAO,WAAW,oBAAyC,EACjE,aAAiB,CACrB,EAAY,OAAO,WAAa,GAAiB,CACnD,EAGA,OAFA,EAAI,iBAAiB,SAAU,QAAQ,EACvC,EAAY,OAAO,WAAa,GAAiB,MACpC,EAAI,oBAAoB,SAAU,QAAQ,CACzD,EAAG,CAAC,CAAC,EAEE,CAAC,CAAC,CACX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../
|
|
1
|
+
import"../rolldown-runtime-Bdj-bS2b.js";import{useIsMobile as e}from"./use-mobile.js";import{i as t,t as n}from"../react.esm-D88qr0ij.js";describe(`useIsMobile`,()=>{it(`returns true below the mobile breakpoint`,()=>{globalThis.setTestViewportWidth(767);let{result:n}=t(()=>e());expect(n.current).toBe(!0)}),it(`returns false at the mobile breakpoint`,()=>{globalThis.setTestViewportWidth(768);let{result:n}=t(()=>e());expect(n.current).toBe(!1)}),it(`updates when the media query changes`,()=>{globalThis.setTestViewportWidth(1024);let{result:r}=t(()=>e());expect(r.current).toBe(!1),n(()=>{globalThis.setTestViewportWidth(500)}),expect(r.current).toBe(!0),n(()=>{globalThis.setTestViewportWidth(900)}),expect(r.current).toBe(!1)}),it(`removes the media query listener on unmount`,()=>{let n=vi.fn();vi.spyOn(window,`matchMedia`).mockReturnValue({matches:!1,media:`(max-width: 767px)`,onchange:null,addEventListener:vi.fn(),removeEventListener:n,dispatchEvent:vi.fn(),addListener:vi.fn(),removeListener:vi.fn()});let{unmount:r}=t(()=>e());r(),expect(n).toHaveBeenCalledWith(`change`,expect.any(Function))})});
|
|
2
2
|
//# sourceMappingURL=use-mobile.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mobile.spec.js","names":[],"sources":["../../src/hooks/use-mobile.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useIsMobile } from './use-mobile'\n\ndescribe('useIsMobile', () => {\n it('returns true below the mobile breakpoint', () => {\n globalThis.setTestViewportWidth(767)\n\n const { result } = renderHook(() => useIsMobile())\n\n expect(result.current).toBe(true)\n })\n\n it('returns false at the mobile breakpoint', () => {\n globalThis.setTestViewportWidth(768)\n\n const { result } = renderHook(() => useIsMobile())\n\n expect(result.current).toBe(false)\n })\n\n it('updates when the media query changes', () => {\n globalThis.setTestViewportWidth(1024)\n const { result } = renderHook(() => useIsMobile())\n\n expect(result.current).toBe(false)\n\n act(() => {\n globalThis.setTestViewportWidth(500)\n })\n expect(result.current).toBe(true)\n\n act(() => {\n globalThis.setTestViewportWidth(900)\n })\n expect(result.current).toBe(false)\n })\n\n it('removes the media query listener on unmount', () => {\n const removeEventListener = vi.fn()\n\n vi.spyOn(window, 'matchMedia').mockReturnValue({\n matches: false,\n media: '(max-width: 767px)',\n onchange: null,\n addEventListener: vi.fn(),\n removeEventListener,\n dispatchEvent: vi.fn(),\n addListener: vi.fn(),\n removeListener: vi.fn()\n })\n\n const { unmount } = renderHook(() => useIsMobile())\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('change', expect.any(Function))\n })\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-mobile.spec.js","names":[],"sources":["../../src/hooks/use-mobile.spec.ts"],"sourcesContent":["import { act, renderHook } from '@testing-library/react'\n\nimport { useIsMobile } from './use-mobile'\n\ndescribe('useIsMobile', () => {\n it('returns true below the mobile breakpoint', () => {\n globalThis.setTestViewportWidth(767)\n\n const { result } = renderHook(() => useIsMobile())\n\n expect(result.current).toBe(true)\n })\n\n it('returns false at the mobile breakpoint', () => {\n globalThis.setTestViewportWidth(768)\n\n const { result } = renderHook(() => useIsMobile())\n\n expect(result.current).toBe(false)\n })\n\n it('updates when the media query changes', () => {\n globalThis.setTestViewportWidth(1024)\n const { result } = renderHook(() => useIsMobile())\n\n expect(result.current).toBe(false)\n\n act(() => {\n globalThis.setTestViewportWidth(500)\n })\n expect(result.current).toBe(true)\n\n act(() => {\n globalThis.setTestViewportWidth(900)\n })\n expect(result.current).toBe(false)\n })\n\n it('removes the media query listener on unmount', () => {\n const removeEventListener = vi.fn()\n\n vi.spyOn(window, 'matchMedia').mockReturnValue({\n matches: false,\n media: '(max-width: 767px)',\n onchange: null,\n addEventListener: vi.fn(),\n removeEventListener,\n dispatchEvent: vi.fn(),\n addListener: vi.fn(),\n removeListener: vi.fn()\n })\n\n const { unmount } = renderHook(() => useIsMobile())\n\n unmount()\n\n expect(removeEventListener).toHaveBeenCalledWith('change', expect.any(Function))\n })\n})\n"],"mappings":"0IAIA,SAAS,kBAAqB,CAC5B,GAAG,+CAAkD,CACnD,WAAW,qBAAqB,GAAG,EAEnC,GAAM,CAAE,UAAW,MAAiB,EAAY,CAAC,EAEjD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAI,CAClC,CAAC,EAED,GAAG,6CAAgD,CACjD,WAAW,qBAAqB,GAAG,EAEnC,GAAM,CAAE,UAAW,MAAiB,EAAY,CAAC,EAEjD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAK,CACnC,CAAC,EAED,GAAG,2CAA8C,CAC/C,WAAW,qBAAqB,IAAI,EACpC,GAAM,CAAE,UAAW,MAAiB,EAAY,CAAC,EAEjD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAK,EAEjC,MAAU,CACR,WAAW,qBAAqB,GAAG,CACrC,CAAC,EACD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAI,EAEhC,MAAU,CACR,WAAW,qBAAqB,GAAG,CACrC,CAAC,EACD,OAAO,EAAO,OAAO,CAAC,CAAC,KAAK,EAAK,CACnC,CAAC,EAED,GAAG,kDAAqD,CACtD,IAAM,EAAsB,GAAG,GAAG,EAElC,GAAG,MAAM,OAAQ,YAAY,CAAC,CAAC,gBAAgB,CAC7C,QAAS,GACT,MAAO,qBACP,SAAU,KACV,iBAAkB,GAAG,GAAG,EACxB,sBACA,cAAe,GAAG,GAAG,EACrB,YAAa,GAAG,GAAG,EACnB,eAAgB,GAAG,GAAG,CACxB,CAAC,EAED,GAAM,CAAE,WAAY,MAAiB,EAAY,CAAC,EAElD,EAAQ,EAER,OAAO,CAAmB,CAAC,CAAC,qBAAqB,SAAU,OAAO,IAAI,QAAQ,CAAC,CACjF,CAAC,CACH,CAAC"}
|