@siberiacancode/reactuse 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/helpers/createContext/createContext.cjs +2 -0
- package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -0
- package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs +2 -0
- package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs.map +1 -0
- package/dist/cjs/helpers/createStore/createStore.cjs +2 -0
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -0
- package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
- package/dist/cjs/hooks/useField/useField.cjs +1 -1
- package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +2 -0
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createContext/createContext.mjs +34 -0
- package/dist/esm/helpers/createContext/createContext.mjs.map +1 -0
- package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs +54 -0
- package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs.map +1 -0
- package/dist/esm/helpers/createStore/createStore.mjs +25 -0
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -0
- package/dist/esm/hooks/useClipboard/useClipboard.mjs.map +1 -1
- package/dist/esm/hooks/useField/useField.mjs +1 -3
- package/dist/esm/hooks/useField/useField.mjs.map +1 -1
- package/dist/esm/hooks/useGamepad/useGamepad.mjs +7 -2
- package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useMemory/useMemory.mjs +14 -10
- package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +63 -0
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -0
- package/dist/esm/index.mjs +330 -319
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/helpers/createContext/createContext.d.ts +48 -0
- package/dist/types/helpers/createReactiveContext/createReactiveContext.d.ts +46 -0
- package/dist/types/helpers/createStore/createStore.d.ts +31 -0
- package/dist/types/helpers/index.d.ts +3 -0
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useClipboard/useClipboard.d.ts +1 -1
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +1 -1
- package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +39 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +19 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 siberiacancode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),n=require("react"),d=(s=void 0,o={})=>{const t=n.createContext({value:s,set:()=>{}});t.displayName=o.name;function c(r){const e=n.use(t);if(!e&&o.strict)throw new Error(`Context hook ${o.name} must be used inside a Provider`);return r?r(e.value):e}return{useSelect:c,instance:t,Provider:({children:r,initialValue:e})=>{const[u,i]=n.useState(e??s),a=n.useMemo(()=>({value:u,set:i}),[u]);return v.jsx(t,{value:a,children:r})}}};exports.createContext=d;
|
|
2
|
+
//# sourceMappingURL=createContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContext.cjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, use, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = use(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","use","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":"wIAsDaA,EAAgB,CAC3BC,EAAkC,OAClCC,EAAgC,CAAA,IACD,CAC/B,MAAMC,EAAUC,EAAAA,cAGb,CACD,MAAOH,EACP,IAAK,IAAM,CAAA,CAAC,CACb,EAEDE,EAAQ,YAAcD,EAAQ,KAI9B,SAASG,EAAoBC,EAAuC,CAC5D,MAAAC,EAAUC,MAAIL,CAAO,EAEvB,GAAA,CAACI,GAAWL,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,OAAKI,EAIEA,EAASC,EAAQ,KAAc,EAH7BA,CAG6B,CAiBjC,MAAA,CACL,UAAAF,EACA,SAAUF,EACV,SAjBe,CAAC,CAAE,SAAAM,EAAU,aAAAC,KAAyC,CACrE,KAAM,CAACC,EAASC,CAAU,EAAIC,EAAAA,SAA4BH,GAAgBT,CAAY,EAEhFa,EAAQC,EAAA,QACZ,KAAO,CACL,MAAOJ,EACP,IAAKC,CAAA,GAEP,CAACD,CAAO,CACV,EAEO,OAAAK,EAAA,IAACb,EAAQ,CAAA,MAAAW,EAAe,SAAAL,CAAS,CAAA,CAC1C,CAMA,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),v=require("../../hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),d=require("../../hooks/useEvent/useEvent.cjs"),f=s=>e=>{const t=r.useRef(e.value),c=r.useMemo(()=>({value:t,listeners:new Set}),[]);return v.useIsomorphicLayoutEffect(()=>{Object.is(t.current,e.value)||(t.current=e.value,r.startTransition(()=>{c.listeners.forEach(u=>{u(t.current)})}))},[e.value]),r.createElement(s,{value:c},e.children)},m=(s,n,e={})=>{const t=r.use(s);if(!t&&e.strict)throw new Error(`Context hook ${e.name} must be used inside a Provider`);const[c,u]=r.useState({selected:n(t.value.current),value:t.value.current}),o=d.useEvent(a=>{u(i=>{if(Object.is(i.value,a))return i;const l=n(a);return Object.is(i.selected,l)?i:{value:a,selected:l}})});return v.useIsomorphicLayoutEffect(()=>(t.listeners.add(o),()=>{t.listeners.delete(o)}),[t.listeners]),c.selected},h=(s=void 0,n={})=>{const e=r.createContext({value:{current:s},listeners:new Set}),t=f(e.Provider);e.displayName=n.name;function c(u){return m(e,u??(o=>o),n)}return{instance:e,Provider:t,useSelector:c}};exports.createReactiveContext=h;
|
|
2
|
+
//# sourceMappingURL=createReactiveContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReactiveContext.cjs","sources":["../../../../src/helpers/createReactiveContext/createReactiveContext.ts"],"sourcesContent":["import type { Context, FC, Provider, ProviderProps, RefObject } from 'react';\n\nimport {\n createContext,\n createElement,\n startTransition,\n use,\n useMemo,\n useRef,\n useState\n} from 'react';\n\nimport { useEvent, useIsomorphicLayoutEffect } from '@/hooks';\n\n/** The create reactive context options type */\nexport interface CreateReactiveContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The create reactive context return type */\nexport interface CreateReactiveContextReturn<Value> {\n /** The context instance */\n instance: Context<ReactiveContextValue<Value>>;\n /** The Provider component for the context */\n Provider: Provider<Value>;\n /** A hook to select a part of the context state */\n useSelector: <Selected>(selector?: (state: Value) => Selected) => Selected;\n}\n\ntype ContextListener<Value> = (value: Value) => void;\n\ninterface ReactiveContextValue<Value> {\n /** The listeners for the context */\n listeners: Set<ContextListener<Value>>;\n /** The value for the context */\n value: RefObject<Value>;\n}\n\nconst createProvider = <Value>(originalProvider: Provider<ReactiveContextValue<Value>>) => {\n const Provider: FC<ProviderProps<Value>> = (props) => {\n const valueRef = useRef(props.value);\n const contextValue = useMemo<ReactiveContextValue<Value>>(\n () => ({\n value: valueRef,\n listeners: new Set()\n }),\n []\n );\n\n useIsomorphicLayoutEffect(() => {\n if (!Object.is(valueRef.current, props.value)) {\n valueRef.current = props.value;\n\n startTransition(() => {\n contextValue.listeners.forEach((listener) => {\n listener(valueRef.current);\n });\n });\n }\n }, [props.value]);\n\n return createElement(originalProvider, { value: contextValue }, props.children);\n };\n\n return Provider as unknown as Provider<ReactiveContextValue<Value>>;\n};\n\nconst createReactiveContextSelector = <Value, Selected>(\n Context: Context<ReactiveContextValue<Value>>,\n selector: (state: Value) => Selected,\n options: CreateReactiveContextOptions = {}\n) => {\n const context = use(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n const [value, setValue] = useState({\n selected: selector(context.value.current),\n value: context.value.current\n });\n\n const dispatch = useEvent((newValue: Value) => {\n setValue((prevValue) => {\n if (Object.is(prevValue.value, newValue)) return prevValue;\n\n const newSelected = selector(newValue);\n if (Object.is(prevValue.selected, newSelected)) return prevValue;\n\n return { value: newValue, selected: newSelected };\n });\n });\n\n useIsomorphicLayoutEffect(() => {\n context.listeners.add(dispatch);\n return () => {\n context.listeners.delete(dispatch);\n };\n }, [context.listeners]);\n\n return value.selected;\n};\n\n/**\n * @name createReactiveContext\n * @description - Creates a typed context selector with optimized updates for state selection\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateReactiveContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateReactiveContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { Provider, useSelector, instance } = createReactiveContext<number>(0);\n */\nexport const createReactiveContext = <Value extends Record<string, any>>(\n defaultValue: Value | undefined = undefined,\n options: CreateReactiveContextOptions = {}\n) => {\n const Context = createContext<ReactiveContextValue<Value>>({\n value: { current: defaultValue as Value },\n listeners: new Set()\n });\n\n const Provider = createProvider(Context.Provider) as unknown as Provider<Value>;\n\n Context.displayName = options.name;\n\n function useSelector(): Value;\n function useSelector<SelectedValue>(selector: (state: Value) => SelectedValue): SelectedValue;\n function useSelector<SelectedValue>(selector?: (state: Value) => SelectedValue) {\n return createReactiveContextSelector(\n Context as unknown as Context<ReactiveContextValue<Value>>,\n selector ?? ((state) => state as unknown as SelectedValue),\n options\n );\n }\n\n return { instance: Context, Provider, useSelector };\n};\n"],"names":["createProvider","originalProvider","props","valueRef","useRef","contextValue","useMemo","useIsomorphicLayoutEffect","startTransition","listener","createElement","createReactiveContextSelector","Context","selector","options","context","use","value","setValue","useState","dispatch","useEvent","newValue","prevValue","newSelected","createReactiveContext","defaultValue","createContext","Provider","useSelector","state"],"mappings":"yOAyCMA,EAAyBC,GACeC,GAAU,CAC9C,MAAAC,EAAWC,EAAAA,OAAOF,EAAM,KAAK,EAC7BG,EAAeC,EAAA,QACnB,KAAO,CACL,MAAOH,EACP,cAAe,GAAI,GAErB,CAAA,CACF,EAEAI,OAAAA,EAAAA,0BAA0B,IAAM,CACzB,OAAO,GAAGJ,EAAS,QAASD,EAAM,KAAK,IAC1CC,EAAS,QAAUD,EAAM,MAEzBM,EAAAA,gBAAgB,IAAM,CACPH,EAAA,UAAU,QAASI,GAAa,CAC3CA,EAASN,EAAS,OAAO,CAAA,CAC1B,CAAA,CACF,EACH,EACC,CAACD,EAAM,KAAK,CAAC,EAETQ,EAAAA,cAAcT,EAAkB,CAAE,MAAOI,CAAa,EAAGH,EAAM,QAAQ,CAChF,EAKIS,EAAgC,CACpCC,EACAC,EACAC,EAAwC,CAAA,IACrC,CACG,MAAAC,EAAUC,MAAIJ,CAAO,EAEvB,GAAA,CAACG,GAAWD,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,KAAM,CAACG,EAAOC,CAAQ,EAAIC,WAAS,CACjC,SAAUN,EAASE,EAAQ,MAAM,OAAO,EACxC,MAAOA,EAAQ,MAAM,OAAA,CACtB,EAEKK,EAAWC,WAAUC,GAAoB,CAC7CJ,EAAUK,GAAc,CACtB,GAAI,OAAO,GAAGA,EAAU,MAAOD,CAAQ,EAAU,OAAAC,EAE3C,MAAAC,EAAcX,EAASS,CAAQ,EACrC,OAAI,OAAO,GAAGC,EAAU,SAAUC,CAAW,EAAUD,EAEhD,CAAE,MAAOD,EAAU,SAAUE,CAAY,CAAA,CACjD,CAAA,CACF,EAEDjB,OAAAA,EAAAA,0BAA0B,KAChBQ,EAAA,UAAU,IAAIK,CAAQ,EACvB,IAAM,CACHL,EAAA,UAAU,OAAOK,CAAQ,CACnC,GACC,CAACL,EAAQ,SAAS,CAAC,EAEfE,EAAM,QACf,EAeaQ,EAAwB,CACnCC,EAAkC,OAClCZ,EAAwC,CAAA,IACrC,CACH,MAAMF,EAAUe,EAAAA,cAA2C,CACzD,MAAO,CAAE,QAASD,CAAsB,EACxC,cAAe,GAAI,CACpB,EAEKE,EAAW5B,EAAeY,EAAQ,QAAQ,EAEhDA,EAAQ,YAAcE,EAAQ,KAI9B,SAASe,EAA2BhB,EAA4C,CACvE,OAAAF,EACLC,EACAC,IAAciB,GAAUA,GACxBhB,CACF,CAAA,CAGF,MAAO,CAAE,SAAUF,EAAS,SAAAgB,EAAU,YAAAC,CAAY,CACpD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),l=s=>{let t;const n=new Set,r=e=>{const u=typeof e=="function"?e(t):e;if(!Object.is(u,t)){const i=t;t=u,n.forEach(a=>a(t,i))}},o=()=>t,S=()=>t,c=e=>(n.add(e),()=>n.delete(e));return typeof s=="function"?t=s(r,o):t=s,{set:r,get:o,use:e=>f.useSyncExternalStore(c,()=>e(o()),()=>e(S())),subscribe:c}};exports.createStore=l;
|
|
2
|
+
//# sourceMappingURL=createStore.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n *\n * @template Value - The type of the store state\n *\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => selector(getState()),\n () => selector(getInitialState())\n );\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":"yGA+BaA,EAAsBC,GAA6C,CAE1E,IAAAC,EACE,MAAAC,MAA+B,IAE/BC,EAAYC,GAAkC,CAClD,MAAMC,EACJ,OAAOD,GAAW,WAAcA,EAAmCH,CAAK,EAAIG,EAE9E,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EACVA,EAAAI,EACRH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAE9D,EAEME,EAAW,IAAMP,EACjBQ,EAAkB,IAAMR,EAExBS,EAAaH,IACjBL,EAAU,IAAIK,CAAQ,EACf,IAAML,EAAU,OAAOK,CAAQ,GAEpC,OAAA,OAAOP,GAAgB,WAChBC,EAAAD,EAAoCG,EAAUK,CAAQ,EAEvDP,EAAAD,EAUH,CACL,IAAKG,EACL,IAAKK,EACL,IAV0BG,GAC1BC,EAAA,qBACEF,EACA,IAAMC,EAASH,GAAU,EACzB,IAAMG,EAASF,EAAiB,CAAA,CAClC,EAMA,UAAAC,CACF,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClipboard.cjs","sources":["../../../../src/hooks/useClipboard/useClipboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy to clipboard return type */\nexport interface UseCopyToClipboardReturn {\n /** The copied value */\n value: string | null;\n /** Function to copy to clipboard */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy to clipboard params type */\nexport interface UseCopyToClipboardParams {\n /** Whether the copy to clipboard is enabled */\n enabled: boolean;\n}\n\n/**\n * @name useClipboard\n * @description - Hook that manages a copy to clipboard\n * @category Browser\n *\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled\n * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const {
|
|
1
|
+
{"version":3,"file":"useClipboard.cjs","sources":["../../../../src/hooks/useClipboard/useClipboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy to clipboard return type */\nexport interface UseCopyToClipboardReturn {\n /** The copied value */\n value: string | null;\n /** Function to copy to clipboard */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy to clipboard params type */\nexport interface UseCopyToClipboardParams {\n /** Whether the copy to clipboard is enabled */\n enabled: boolean;\n}\n\n/**\n * @name useClipboard\n * @description - Hook that manages a copy to clipboard\n * @category Browser\n *\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled\n * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const { value, copy } = useClipboard();\n */\nexport const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipboardReturn => {\n const [value, setValue] = useState<string | null>(null);\n const enabled = params?.enabled ?? false;\n\n const set = async () => {\n try {\n const value = await navigator.clipboard.readText();\n setValue(value);\n } catch {\n setValue(document.getSelection?.()?.toString() ?? '');\n }\n };\n\n useEffect(() => {\n if (!enabled) return;\n\n document.addEventListener('copy', set);\n document.addEventListener('cut', set);\n return () => {\n document.removeEventListener('copy', set);\n document.removeEventListener('cut', set);\n };\n }, [enabled]);\n\n const copyToClipboard = async (value: string) => {\n copy(value);\n setValue(value);\n };\n\n return { value, copy: copyToClipboard };\n};\n"],"names":["useClipboard","params","value","setValue","useState","enabled","set","_b","_a","useEffect","copy"],"mappings":"mJA+BaA,EAAgBC,GAAgE,CAC3F,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAwB,IAAI,EAChDC,GAAUJ,GAAA,YAAAA,EAAQ,UAAW,GAE7BK,EAAM,SAAY,SAClB,GAAA,CACF,MAAMJ,EAAQ,MAAM,UAAU,UAAU,SAAS,EACjDC,EAASD,CAAK,CAAA,MACR,CACNC,IAASI,GAAAC,EAAA,SAAS,eAAT,YAAAA,EAAA,6BAAAD,EAA2B,aAAc,EAAE,CAAA,CAExD,EAEAE,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAKJ,EAEI,gBAAA,iBAAiB,OAAQC,CAAG,EAC5B,SAAA,iBAAiB,MAAOA,CAAG,EAC7B,IAAM,CACF,SAAA,oBAAoB,OAAQA,CAAG,EAC/B,SAAA,oBAAoB,MAAOA,CAAG,CACzC,CAAA,EACC,CAACD,CAAO,CAAC,EAOL,CAAE,MAAAH,EAAO,KALQ,MAAOA,GAAkB,CAC/CQ,EAAAA,KAAKR,CAAK,EACVC,EAASD,CAAK,CAChB,CAEsC,CACxC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),R=require("../useRerender/useRerender.cjs"),S=t=>{const r=(t==null?void 0:t.initialValue)??"",u=l.useRef(null),o=l.useRef(!1),f=R.useRerender(),[h,d]=l.useState(!1),[b,g]=l.useState((t==null?void 0:t.initialTouched)??!1),[k,c]=l.useState(void 0),y=()=>{var e,n,i;return((e=u.current)==null?void 0:e.type)==="radio"||((n=u.current)==null?void 0:n.type)==="checkbox"?u.current.checked:((i=u.current)==null?void 0:i.value)??r},x=e=>{var n,i;if(((n=u.current)==null?void 0:n.type)==="radio"||((i=u.current)==null?void 0:i.type)==="checkbox")return u.current.checked=e,o.current?f():void 0;if(u.current.value=e,o.current)return f()},V=()=>{x(r),d(!1),g(!1),c(void 0)},L=()=>
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),R=require("../useRerender/useRerender.cjs"),S=t=>{const r=(t==null?void 0:t.initialValue)??"",u=l.useRef(null),o=l.useRef(!1),f=R.useRerender(),[h,d]=l.useState(!1),[b,g]=l.useState((t==null?void 0:t.initialTouched)??!1),[k,c]=l.useState(void 0),y=()=>{var e,n,i;return((e=u.current)==null?void 0:e.type)==="radio"||((n=u.current)==null?void 0:n.type)==="checkbox"?u.current.checked:((i=u.current)==null?void 0:i.value)??r},x=e=>{var n,i;if(((n=u.current)==null?void 0:n.type)==="radio"||((i=u.current)==null?void 0:i.type)==="checkbox")return u.current.checked=e,o.current?f():void 0;if(u.current.value=e,o.current)return f()},V=()=>{x(r),d(!1),g(!1),c(void 0)},L=()=>u.current.focus(),v=e=>{if(e.required&&!u.current.value)return c(e.required);if(e.minLength&&u.current.value.length<e.minLength.value)return c(e.minLength.message);if(e.maxLength&&u.current.value.length>e.maxLength.value)return c(e.maxLength.message);if(e.min&&Number(u.current.value)<e.min.value)return c(e.min.message);if(e.max&&Number(u.current.value)>e.max.value)return c(e.max.message);if(e.pattern&&!e.pattern.value.test(u.current.value))return c(e.pattern.message);if(e.validate){const n=e.validate(u.current.value);if(typeof n=="string")return c(n)}c(void 0)};return{register:e=>({ref:n=>{if(!u.current&&n){if(t!=null&&t.autoFocus&&n.focus(),u.current=n,u.current.type==="radio"){u.current.defaultChecked=(t==null?void 0:t.initialValue)===n.value;return}if(u.current.type==="checkbox"){u.current.defaultChecked=!!(t!=null&&t.initialValue);return}u.current.defaultValue=String(r),e&&(t!=null&&t.validateOnMount)&&v(e)}},onChange:async()=>{if(o.current)return f();u.current.value!==r&&d(!0),h&&u.current.value===r&&d(!1),e&&(t!=null&&t.validateOnChange)&&await v(e),e&&(t!=null&&t.validateOnBlur)&&c(void 0)},onBlur:async()=>{e&&(t!=null&&t.validateOnBlur)&&await v(e),g(!0)}}),dirty:h,touched:b,error:k,setError:c,clearError:()=>c(void 0),getValue:y,setValue:x,reset:V,watch:()=>(o.current=!0,y()),focus:L}};exports.useField=S;
|
|
2
2
|
//# sourceMappingURL=useField.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.cjs","sources":["../../../../src/hooks/useField/useField.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useRerender } from '../useRerender/useRerender';\n\n/** The use field params type */\nexport interface UseFieldParams<Value> {\n /** The auto focus */\n autoFocus?: boolean;\n /** The initial touched */\n initialTouched?: boolean;\n /** The initial value */\n initialValue?: Value;\n /** The validate on blur */\n validateOnBlur?: boolean;\n /** The validate on mount */\n validateOnChange?: boolean;\n /** The validate on mount */\n validateOnMount?: boolean;\n}\n\n/** The use field register params type */\nexport interface UseFieldRegisterParams {\n /** The required validation */\n required?: string;\n /** The custom validation */\n validate?: (value: string) => Promise<string | true>;\n /** The min value validation */\n max?: {\n value: number;\n message: string;\n };\n /** The max length validation */\n maxLength?: {\n value: number;\n message: string;\n };\n /** The max value validation */\n min?: {\n value: number;\n message: string;\n };\n /** The min length validation */\n minLength?: {\n value: number;\n message: string;\n };\n /** The pattern validation */\n pattern?: {\n value: RegExp;\n message: string;\n };\n}\n\n/** The use field return type */\nexport interface UseFieldReturn<Value> {\n /** The dirty state */\n dirty: boolean;\n /** The error state */\n error?: string;\n /** The set error function */\n touched: boolean;\n /** The set error function */\n clearError: () => void;\n /** The focus function */\n focus: () => void;\n /** The get value function */\n getValue: () => Value;\n /** The register function */\n register: (params?: UseFieldRegisterParams) => {\n onBlur: () => void;\n onChange: () => void;\n ref: (\n node: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | undefined\n ) => void;\n };\n /** The reset function */\n reset: () => void;\n /** The set error function */\n setError: (error: string) => void;\n /** The set value function */\n setValue: (value: Value) => void;\n /** The watch function */\n watch: () => Value;\n}\n\n/**\n * @name useField\n * @description - Hook to manage a form field\n * @category Utilities\n *\n * @template Value The input value\n * @template Type The input value type\n * @param {Value} [params.initialValue] Initial value\n * @param {boolean} [params.initialTouched=false] Initial touched state\n * @param {boolean} [params.autoFocus=false] Auto focus\n * @param {boolean} [params.validateOnChange=false] Validate on change\n * @param {boolean} [params.validateOnBlur=false] Validate on blur\n * @param {boolean} [params.validateOnMount=false] Validate on mount\n * @returns {UseFieldReturn<Value>} An object containing input information\n *\n * @example\n * const { register, getValue, setValue, reset, dirty, error, setError, clearError, touched, focus, watch } = useField();\n */\nexport const useField = <\n Value extends boolean | number | string = string,\n Type = Value extends string ? string : Value extends boolean ? boolean : number\n>(\n params?: UseFieldParams<Value>\n): UseFieldReturn<Type> => {\n const initialValue = (params?.initialValue ?? '') as Value;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const watchingRef = useRef(false);\n const rerender = useRerender();\n\n const [dirty, setDirty] = useState(false);\n const [touched, setTouched] = useState(params?.initialTouched ?? false);\n const [error, setError] = useState<string | undefined>(undefined);\n\n const getValue = () => {\n if (inputRef.current?.type === 'radio' || inputRef.current?.type === 'checkbox')\n return inputRef.current.checked as Type;\n return (inputRef.current?.value ?? initialValue) as Type;\n };\n\n const setValue = (value: Type) => {\n if (inputRef.current?.type === 'radio' || inputRef.current?.type === 'checkbox') {\n inputRef.current.checked = value as boolean;\n if (watchingRef.current) return rerender();\n return;\n }\n\n inputRef.current!.value = value as string;\n if (watchingRef.current) return rerender();\n };\n\n const reset = () => {\n setValue(initialValue as unknown as Type);\n setDirty(false);\n setTouched(false);\n setError(undefined);\n };\n\n const focus = () =>
|
|
1
|
+
{"version":3,"file":"useField.cjs","sources":["../../../../src/hooks/useField/useField.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useRerender } from '../useRerender/useRerender';\n\n/** The use field params type */\nexport interface UseFieldParams<Value> {\n /** The auto focus */\n autoFocus?: boolean;\n /** The initial touched */\n initialTouched?: boolean;\n /** The initial value */\n initialValue?: Value;\n /** The validate on blur */\n validateOnBlur?: boolean;\n /** The validate on mount */\n validateOnChange?: boolean;\n /** The validate on mount */\n validateOnMount?: boolean;\n}\n\n/** The use field register params type */\nexport interface UseFieldRegisterParams {\n /** The required validation */\n required?: string;\n /** The custom validation */\n validate?: (value: string) => Promise<string | true>;\n /** The min value validation */\n max?: {\n value: number;\n message: string;\n };\n /** The max length validation */\n maxLength?: {\n value: number;\n message: string;\n };\n /** The max value validation */\n min?: {\n value: number;\n message: string;\n };\n /** The min length validation */\n minLength?: {\n value: number;\n message: string;\n };\n /** The pattern validation */\n pattern?: {\n value: RegExp;\n message: string;\n };\n}\n\n/** The use field return type */\nexport interface UseFieldReturn<Value> {\n /** The dirty state */\n dirty: boolean;\n /** The error state */\n error?: string;\n /** The set error function */\n touched: boolean;\n /** The set error function */\n clearError: () => void;\n /** The focus function */\n focus: () => void;\n /** The get value function */\n getValue: () => Value;\n /** The register function */\n register: (params?: UseFieldRegisterParams) => {\n onBlur: () => void;\n onChange: () => void;\n ref: (\n node: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | undefined\n ) => void;\n };\n /** The reset function */\n reset: () => void;\n /** The set error function */\n setError: (error: string) => void;\n /** The set value function */\n setValue: (value: Value) => void;\n /** The watch function */\n watch: () => Value;\n}\n\n/**\n * @name useField\n * @description - Hook to manage a form field\n * @category Utilities\n *\n * @template Value The input value\n * @template Type The input value type\n * @param {Value} [params.initialValue] Initial value\n * @param {boolean} [params.initialTouched=false] Initial touched state\n * @param {boolean} [params.autoFocus=false] Auto focus\n * @param {boolean} [params.validateOnChange=false] Validate on change\n * @param {boolean} [params.validateOnBlur=false] Validate on blur\n * @param {boolean} [params.validateOnMount=false] Validate on mount\n * @returns {UseFieldReturn<Value>} An object containing input information\n *\n * @example\n * const { register, getValue, setValue, reset, dirty, error, setError, clearError, touched, focus, watch } = useField();\n */\nexport const useField = <\n Value extends boolean | number | string = string,\n Type = Value extends string ? string : Value extends boolean ? boolean : number\n>(\n params?: UseFieldParams<Value>\n): UseFieldReturn<Type> => {\n const initialValue = (params?.initialValue ?? '') as Value;\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const watchingRef = useRef(false);\n const rerender = useRerender();\n\n const [dirty, setDirty] = useState(false);\n const [touched, setTouched] = useState(params?.initialTouched ?? false);\n const [error, setError] = useState<string | undefined>(undefined);\n\n const getValue = () => {\n if (inputRef.current?.type === 'radio' || inputRef.current?.type === 'checkbox')\n return inputRef.current.checked as Type;\n return (inputRef.current?.value ?? initialValue) as Type;\n };\n\n const setValue = (value: Type) => {\n if (inputRef.current?.type === 'radio' || inputRef.current?.type === 'checkbox') {\n inputRef.current.checked = value as boolean;\n if (watchingRef.current) return rerender();\n return;\n }\n\n inputRef.current!.value = value as string;\n if (watchingRef.current) return rerender();\n };\n\n const reset = () => {\n setValue(initialValue as unknown as Type);\n setDirty(false);\n setTouched(false);\n setError(undefined);\n };\n\n const focus = () => inputRef.current!.focus();\n\n const validate = (params: UseFieldRegisterParams) => {\n if (params.required && !inputRef.current!.value) {\n return setError(params.required);\n }\n\n if (params.minLength && inputRef.current!.value.length < params.minLength.value) {\n return setError(params.minLength.message);\n }\n\n if (params.maxLength && inputRef.current!.value.length > params.maxLength.value) {\n return setError(params.maxLength.message);\n }\n\n if (params.min && Number(inputRef.current!.value) < params.min.value) {\n return setError(params.min.message);\n }\n\n if (params.max && Number(inputRef.current!.value) > params.max.value) {\n return setError(params.max.message);\n }\n\n if (params.pattern && !params.pattern.value.test(inputRef.current!.value)) {\n return setError(params.pattern.message);\n }\n\n if (params.validate) {\n const error = params.validate(inputRef.current!.value);\n if (typeof error === 'string') return setError(error);\n }\n\n setError(undefined);\n };\n\n const register = (registerParams?: UseFieldRegisterParams) => ({\n ref: (node: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | undefined) => {\n if (!inputRef.current && node) {\n if (params?.autoFocus) node.focus();\n inputRef.current = node as HTMLInputElement;\n if (inputRef.current.type === 'radio') {\n inputRef.current.defaultChecked = params?.initialValue === node.value;\n return;\n }\n if (inputRef.current.type === 'checkbox') {\n inputRef.current.defaultChecked = !!params?.initialValue;\n return;\n }\n inputRef.current.defaultValue = String(initialValue);\n\n if (registerParams && params?.validateOnMount) validate(registerParams);\n }\n },\n onChange: async () => {\n if (watchingRef.current) return rerender();\n if (inputRef.current!.value !== initialValue) setDirty(true);\n if (dirty && inputRef.current!.value === initialValue) setDirty(false);\n if (registerParams && params?.validateOnChange) await validate(registerParams);\n if (registerParams && params?.validateOnBlur) setError(undefined);\n },\n onBlur: async () => {\n if (registerParams && params?.validateOnBlur) await validate(registerParams);\n setTouched(true);\n }\n });\n\n const watch = () => {\n watchingRef.current = true;\n return getValue();\n };\n\n const clearError = () => setError(undefined);\n\n return {\n register,\n dirty,\n touched,\n error,\n setError,\n clearError,\n getValue,\n setValue,\n reset,\n watch,\n focus\n };\n};\n"],"names":["useField","params","initialValue","inputRef","useRef","watchingRef","rerender","useRerender","dirty","setDirty","useState","touched","setTouched","error","setError","getValue","_a","_b","_c","setValue","value","reset","focus","validate","registerParams","node"],"mappings":"qJAuGaA,EAIXC,GACyB,CACnB,MAAAC,GAAgBD,GAAA,YAAAA,EAAQ,eAAgB,GAExCE,EAAWC,SAAgC,IAAI,EAC/CC,EAAcD,SAAO,EAAK,EAC1BE,EAAWC,EAAAA,YAAY,EAEvB,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAS,EAAK,EAClC,CAACC,EAASC,CAAU,EAAIF,EAAS,UAAAT,GAAA,YAAAA,EAAQ,iBAAkB,EAAK,EAChE,CAACY,EAAOC,CAAQ,EAAIJ,EAAAA,SAA6B,MAAS,EAE1DK,EAAW,IAAM,WACrB,QAAIC,EAAAb,EAAS,UAAT,YAAAa,EAAkB,QAAS,WAAWC,EAAAd,EAAS,UAAT,YAAAc,EAAkB,QAAS,WAC5Dd,EAAS,QAAQ,UAClBe,EAAAf,EAAS,UAAT,YAAAe,EAAkB,QAAShB,CACrC,EAEMiB,EAAYC,GAAgB,SAChC,KAAIJ,EAAAb,EAAS,UAAT,YAAAa,EAAkB,QAAS,WAAWC,EAAAd,EAAS,UAAT,YAAAc,EAAkB,QAAS,WAE/D,OADJd,EAAS,QAAQ,QAAUiB,EACvBf,EAAY,QAAgBC,EAAS,EACzC,OAIE,GADJH,EAAS,QAAS,MAAQiB,EACtBf,EAAY,QAAS,OAAOC,EAAS,CAC3C,EAEMe,EAAQ,IAAM,CAClBF,EAASjB,CAA+B,EACxCO,EAAS,EAAK,EACdG,EAAW,EAAK,EAChBE,EAAS,MAAS,CACpB,EAEMQ,EAAQ,IAAMnB,EAAS,QAAS,MAAM,EAEtCoB,EAAYtB,GAAmC,CACnD,GAAIA,EAAO,UAAY,CAACE,EAAS,QAAS,MACjC,OAAAW,EAASb,EAAO,QAAQ,EAG7BA,GAAAA,EAAO,WAAaE,EAAS,QAAS,MAAM,OAASF,EAAO,UAAU,MACjE,OAAAa,EAASb,EAAO,UAAU,OAAO,EAGtCA,GAAAA,EAAO,WAAaE,EAAS,QAAS,MAAM,OAASF,EAAO,UAAU,MACjE,OAAAa,EAASb,EAAO,UAAU,OAAO,EAGtCA,GAAAA,EAAO,KAAO,OAAOE,EAAS,QAAS,KAAK,EAAIF,EAAO,IAAI,MACtD,OAAAa,EAASb,EAAO,IAAI,OAAO,EAGhCA,GAAAA,EAAO,KAAO,OAAOE,EAAS,QAAS,KAAK,EAAIF,EAAO,IAAI,MACtD,OAAAa,EAASb,EAAO,IAAI,OAAO,EAGhCA,GAAAA,EAAO,SAAW,CAACA,EAAO,QAAQ,MAAM,KAAKE,EAAS,QAAS,KAAK,EAC/D,OAAAW,EAASb,EAAO,QAAQ,OAAO,EAGxC,GAAIA,EAAO,SAAU,CACnB,MAAMY,EAAQZ,EAAO,SAASE,EAAS,QAAS,KAAK,EACrD,GAAI,OAAOU,GAAU,SAAU,OAAOC,EAASD,CAAK,CAAA,CAGtDC,EAAS,MAAS,CACpB,EAwCO,MAAA,CACL,SAvCgBU,IAA6C,CAC7D,IAAMC,GAAwF,CACxF,GAAA,CAACtB,EAAS,SAAWsB,EAAM,CAGzB,GAFAxB,GAAA,MAAAA,EAAQ,WAAWwB,EAAK,MAAM,EAClCtB,EAAS,QAAUsB,EACftB,EAAS,QAAQ,OAAS,QAAS,CACrCA,EAAS,QAAQ,gBAAiBF,GAAA,YAAAA,EAAQ,gBAAiBwB,EAAK,MAChE,MAAA,CAEE,GAAAtB,EAAS,QAAQ,OAAS,WAAY,CACxCA,EAAS,QAAQ,eAAiB,CAAC,EAACF,GAAA,MAAAA,EAAQ,cAC5C,MAAA,CAEOE,EAAA,QAAQ,aAAe,OAAOD,CAAY,EAE/CsB,IAAkBvB,GAAA,MAAAA,EAAQ,kBAAiBsB,EAASC,CAAc,CAAA,CAE1E,EACA,SAAU,SAAY,CAChB,GAAAnB,EAAY,QAAS,OAAOC,EAAS,EACrCH,EAAS,QAAS,QAAUD,KAAuB,EAAI,EACvDM,GAASL,EAAS,QAAS,QAAUD,KAAuB,EAAK,EACjEsB,IAAkBvB,GAAA,MAAAA,EAAQ,mBAAkB,MAAMsB,EAASC,CAAc,EACzEA,IAAkBvB,GAAA,MAAAA,EAAQ,iBAAgBa,EAAS,MAAS,CAClE,EACA,OAAQ,SAAY,CACdU,IAAkBvB,GAAA,MAAAA,EAAQ,iBAAgB,MAAMsB,EAASC,CAAc,EAC3EZ,EAAW,EAAI,CAAA,CACjB,GAYA,MAAAJ,EACA,QAAAG,EACA,MAAAE,EACA,SAAAC,EACA,WARiB,IAAMA,EAAS,MAAS,EASzC,SAAAC,EACA,SAAAI,EACA,MAAAE,EACA,MAjBY,KACZhB,EAAY,QAAU,GACfU,EAAS,GAgBhB,MAAAO,CACF,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGamepad.cjs","sources":["../../../../src/hooks/useGamepad/useGamepad.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useRaf } from '../useRaf/useRaf';\n\ndeclare global {\n interface Gamepad {\n hapticActuators?: GamepadHapticActuator[];\n }\n}\n\n/** The use gamepad return type */\nexport interface UseGamepadStateReturn {\n /** The gamepad active status */\n active: boolean;\n /** The gamepad state */\n gamepads: Gamepad[];\n /** The gamepad supported status */\n supported: boolean;\n}\n\n/**\n * @name useGamepad\n * @description - Hook for getting information about gamepad\n * @category Browser\n *\n * @browserapi navigator.getGamepads https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getGamepads\n *\n * @returns {UseGamepadStateReturn} An object containing the gamepad information\n *\n * @example\n * const { supported, gamepads, active } = useGamepad();\n */\nexport const useGamepad = () => {\n const supported = typeof navigator !== 'undefined' && 'getGamepads' in navigator;\n const [gamepads, setGamepads] = useState<Record<number, Gamepad>>({});\n\n const createGamepad = (gamepad: Gamepad) => {\n const hapticActuators = [];\n const vibrationActuator = 'vibrationActuator' in gamepad ? gamepad.vibrationActuator : null;\n\n if (vibrationActuator) hapticActuators.push(vibrationActuator);\n if (gamepad.hapticActuators) hapticActuators.push(...gamepad.hapticActuators);\n\n return {\n ...gamepad,\n hapticActuators\n } as Gamepad;\n };\n\n const updateGamepadState = () => {\n for (const gamepad of navigator.getGamepads() ?? []) {\n if (gamepad && gamepads[gamepad.index]) gamepads[gamepad.index] = createGamepad(gamepad);\n }\n };\n\n const { active } = useRaf(updateGamepadState, {
|
|
1
|
+
{"version":3,"file":"useGamepad.cjs","sources":["../../../../src/hooks/useGamepad/useGamepad.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useRaf } from '../useRaf/useRaf';\n\ndeclare global {\n interface Gamepad {\n hapticActuators?: GamepadHapticActuator[];\n }\n}\n\n/** The use gamepad return type */\nexport interface UseGamepadStateReturn {\n /** The gamepad active status */\n active: boolean;\n /** The gamepad state */\n gamepads: Gamepad[];\n /** The gamepad supported status */\n supported: boolean;\n}\n\n/**\n * @name useGamepad\n * @description - Hook for getting information about gamepad\n * @category Browser\n *\n * @browserapi navigator.getGamepads https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getGamepads\n *\n * @returns {UseGamepadStateReturn} An object containing the gamepad information\n *\n * @example\n * const { supported, gamepads, active } = useGamepad();\n */\nexport const useGamepad = () => {\n const supported = typeof navigator !== 'undefined' && 'getGamepads' in navigator;\n const [gamepads, setGamepads] = useState<Record<number, Gamepad>>({});\n\n const createGamepad = (gamepad: Gamepad) => {\n const hapticActuators = [];\n const vibrationActuator = 'vibrationActuator' in gamepad ? gamepad.vibrationActuator : null;\n\n if (vibrationActuator) hapticActuators.push(vibrationActuator);\n if (gamepad.hapticActuators) hapticActuators.push(...gamepad.hapticActuators);\n\n return {\n ...gamepad,\n hapticActuators\n } as Gamepad;\n };\n\n const updateGamepadState = () => {\n for (const gamepad of navigator.getGamepads() ?? []) {\n if (gamepad && gamepads[gamepad.index]) gamepads[gamepad.index] = createGamepad(gamepad);\n }\n };\n\n const { active } = useRaf(updateGamepadState, {\n enabled: !!Object.keys(gamepads).length\n });\n\n useEffect(() => {\n if (!supported) return;\n const gamepads = navigator.getGamepads();\n setGamepads(\n gamepads.reduce(\n (acc, gamepad) => ({\n ...acc,\n ...(gamepad && { [gamepad.index]: createGamepad(gamepad) })\n }),\n {}\n )\n );\n }, []);\n\n useEffect(() => {\n const onConnected = (event: Event) => {\n const { gamepad } = event as GamepadEvent;\n setGamepads({ ...gamepads, [gamepad.index]: createGamepad(gamepad) });\n };\n\n const onDisconnected = (event: Event) => {\n const { gamepad } = event as GamepadEvent;\n const updatedGamepads = { ...gamepads };\n delete updatedGamepads[gamepad.index];\n setGamepads(updatedGamepads);\n };\n\n document.addEventListener('gamepadconnected', onConnected);\n document.addEventListener('gamepaddisconnected', onDisconnected);\n\n return () => {\n document.removeEventListener('gamepadconnected', onConnected);\n document.removeEventListener('gamepaddisconnected', onDisconnected);\n };\n }, []);\n\n return {\n active,\n supported,\n gamepads: Object.values(gamepads)\n };\n};\n\nexport const mapGamepadToXbox360Controller = (gamepad: Gamepad) => ({\n buttons: {\n a: gamepad.buttons[0],\n b: gamepad.buttons[1],\n x: gamepad.buttons[2],\n y: gamepad.buttons[3]\n },\n bumper: {\n left: gamepad.buttons[4],\n right: gamepad.buttons[5]\n },\n triggers: {\n left: gamepad.buttons[6],\n right: gamepad.buttons[7]\n },\n stick: {\n left: {\n horizontal: gamepad.axes[0],\n vertical: gamepad.axes[1],\n button: gamepad.buttons[10]\n },\n right: {\n horizontal: gamepad.axes[2],\n vertical: gamepad.axes[3],\n button: gamepad.buttons[11]\n }\n },\n dpad: {\n up: gamepad.buttons[12],\n down: gamepad.buttons[13],\n left: gamepad.buttons[14],\n right: gamepad.buttons[15]\n },\n back: gamepad.buttons[8],\n start: gamepad.buttons[9]\n});\n"],"names":["useGamepad","supported","gamepads","setGamepads","useState","createGamepad","gamepad","hapticActuators","vibrationActuator","updateGamepadState","active","useRaf","useEffect","acc","onConnected","event","onDisconnected","updatedGamepads","mapGamepadToXbox360Controller"],"mappings":"2IAgCaA,EAAa,IAAM,CAC9B,MAAMC,EAAY,OAAO,UAAc,KAAe,gBAAiB,UACjE,CAACC,EAAUC,CAAW,EAAIC,EAAAA,SAAkC,CAAA,CAAE,EAE9DC,EAAiBC,GAAqB,CAC1C,MAAMC,EAAkB,CAAC,EACnBC,EAAoB,sBAAuBF,EAAUA,EAAQ,kBAAoB,KAEnF,OAAAE,GAAmCD,EAAA,KAAKC,CAAiB,EACzDF,EAAQ,iBAAiBC,EAAgB,KAAK,GAAGD,EAAQ,eAAe,EAErE,CACL,GAAGA,EACH,gBAAAC,CACF,CACF,EAEME,EAAqB,IAAM,CAC/B,UAAWH,KAAW,UAAU,YAAY,GAAK,CAAA,EAC3CA,GAAWJ,EAASI,EAAQ,KAAK,MAAYA,EAAQ,KAAK,EAAID,EAAcC,CAAO,EAE3F,EAEM,CAAE,OAAAI,CAAA,EAAWC,EAAA,OAAOF,EAAoB,CAC5C,QAAS,CAAC,CAAC,OAAO,KAAKP,CAAQ,EAAE,MAAA,CAClC,EAEDU,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACX,EAAW,OACVC,MAAAA,EAAW,UAAU,YAAY,EACvCC,EACED,EAAS,OACP,CAACW,EAAKP,KAAa,CACjB,GAAGO,EACH,GAAIP,GAAW,CAAE,CAACA,EAAQ,KAAK,EAAGD,EAAcC,CAAO,CAAE,CAAA,GAE3D,CAAA,CAAC,CAEL,CACF,EAAG,EAAE,EAELM,EAAAA,UAAU,IAAM,CACR,MAAAE,EAAeC,GAAiB,CAC9B,KAAA,CAAE,QAAAT,GAAYS,EACRZ,EAAA,CAAE,GAAGD,EAAU,CAACI,EAAQ,KAAK,EAAGD,EAAcC,CAAO,EAAG,CACtE,EAEMU,EAAkBD,GAAiB,CACjC,KAAA,CAAE,QAAAT,GAAYS,EACdE,EAAkB,CAAE,GAAGf,CAAS,EAC/B,OAAAe,EAAgBX,EAAQ,KAAK,EACpCH,EAAYc,CAAe,CAC7B,EAES,gBAAA,iBAAiB,mBAAoBH,CAAW,EAChD,SAAA,iBAAiB,sBAAuBE,CAAc,EAExD,IAAM,CACF,SAAA,oBAAoB,mBAAoBF,CAAW,EACnD,SAAA,oBAAoB,sBAAuBE,CAAc,CACpE,CACF,EAAG,EAAE,EAEE,CACL,OAAAN,EACA,UAAAT,EACA,SAAU,OAAO,OAAOC,CAAQ,CAClC,CACF,EAEagB,EAAiCZ,IAAsB,CAClE,QAAS,CACP,EAAGA,EAAQ,QAAQ,CAAC,EACpB,EAAGA,EAAQ,QAAQ,CAAC,EACpB,EAAGA,EAAQ,QAAQ,CAAC,EACpB,EAAGA,EAAQ,QAAQ,CAAC,CACtB,EACA,OAAQ,CACN,KAAMA,EAAQ,QAAQ,CAAC,EACvB,MAAOA,EAAQ,QAAQ,CAAC,CAC1B,EACA,SAAU,CACR,KAAMA,EAAQ,QAAQ,CAAC,EACvB,MAAOA,EAAQ,QAAQ,CAAC,CAC1B,EACA,MAAO,CACL,KAAM,CACJ,WAAYA,EAAQ,KAAK,CAAC,EAC1B,SAAUA,EAAQ,KAAK,CAAC,EACxB,OAAQA,EAAQ,QAAQ,EAAE,CAC5B,EACA,MAAO,CACL,WAAYA,EAAQ,KAAK,CAAC,EAC1B,SAAUA,EAAQ,KAAK,CAAC,EACxB,OAAQA,EAAQ,QAAQ,EAAE,CAAA,CAE9B,EACA,KAAM,CACJ,GAAIA,EAAQ,QAAQ,EAAE,EACtB,KAAMA,EAAQ,QAAQ,EAAE,EACxB,KAAMA,EAAQ,QAAQ,EAAE,EACxB,MAAOA,EAAQ,QAAQ,EAAE,CAC3B,EACA,KAAMA,EAAQ,QAAQ,CAAC,EACvB,MAAOA,EAAQ,QAAQ,CAAC,CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntersectionObserver.cjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n root?: HookTarget;\n onChange?: (entry: IntersectionObserverEntry) => void;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Browser\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state
|
|
1
|
+
{"version":3,"file":"useIntersectionObserver.cjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n root?: HookTarget;\n onChange?: (entry: IntersectionObserverEntry) => void;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Browser\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(ref);\n */\nexport const useIntersectionObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseIntersectionObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseIntersectionObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setEntry(entry);\n internalOnChangeRef.current?.(entry);\n },\n {\n ...options,\n root: options?.root ? (getElement(options.root) as Document | Element) : document\n }\n );\n\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { entry, inView: !!entry?.isIntersecting };\n return {\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseIntersectionObserver;\n"],"names":["useIntersectionObserver","params","target","isTarget","options","enabled","entry","setEntry","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":"mPA2DaA,EAA2B,IAAIC,IAAkB,CACtD,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAWF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACxCI,GAAUD,GAAA,YAAAA,EAAS,UAAW,GAE9B,CAACE,EAAOC,CAAQ,EAAIC,WAAoC,EAExDC,EAAcC,EAAAA,YAAqB,EACnCC,EAAsBC,EAAAA,OAAmDR,GAAA,YAAAA,EAAS,QAAQ,EA2B5F,OA1BJO,EAAoB,QAAUP,GAAA,YAAAA,EAAS,SAEvCS,EAAAA,UAAU,IAAM,CACd,GAAI,CAACR,GAAW,CAACH,GAAU,CAACO,EAAY,MAAO,OAE/C,MAAMK,EAAUZ,EAASa,EAAAA,WAAWb,CAAM,EAAIO,EAAY,QAC1D,GAAI,CAACK,EAAS,OAEd,MAAME,EAAW,IAAI,qBACnB,CAAC,CAACV,CAAK,IAAM,OACXC,EAASD,CAAK,GACdW,EAAAN,EAAoB,UAApB,MAAAM,EAAA,KAAAN,EAA8BL,EAChC,EACA,CACE,GAAGF,EACH,KAAMA,GAAA,MAAAA,EAAS,KAAQW,EAAW,WAAAX,EAAQ,IAAI,EAA2B,QAAA,CAE7E,EAEA,OAAAY,EAAS,QAAQF,CAAkB,EAE5B,IAAM,CACXE,EAAS,WAAW,CACtB,CACC,EAAA,CAACd,EAAQO,EAAY,MAAOL,GAAA,YAAAA,EAAS,WAAYA,GAAA,YAAAA,EAAS,UAAWA,GAAA,YAAAA,EAAS,KAAMC,CAAO,CAAC,EAE3FH,EAAe,CAAE,MAAAI,EAAO,OAAQ,CAAC,EAACA,GAAA,MAAAA,EAAO,eAAe,EACrD,CACL,IAAKG,EACL,MAAAH,EACA,OAAQ,CAAC,EAACA,GAAA,MAAAA,EAAO,eACnB,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),m=require("../useInterval/useInterval.cjs"),a=()=>{const e=performance&&"memory"in performance&&!!performance.memory,[r,t]=o.useState((performance==null?void 0:performance.memory)??{jsHeapSizeLimit:0,totalJSHeapSize:0,usedJSHeapSize:0});return m.useInterval(()=>t(performance.memory),1e3,{immediately:e}),{supported:e,value:r}};exports.useMemory=a;
|
|
2
2
|
//# sourceMappingURL=useMemory.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMemory.cjs","sources":["../../../../src/hooks/useMemory/useMemory.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useInterval } from '../useInterval/useInterval';\n\ndeclare global {\n interface Performance {\n memory: {\n readonly jsHeapSizeLimit: number;\n readonly totalJSHeapSize: number;\n readonly usedJSHeapSize: number;\n };\n }\n}\n\n/** The use memory return type */\nexport interface UseMemoryReturn {\n /** The memory supported status */\n supported: boolean;\n /** The current memory usage */\n value: Performance['memory'];\n}\n\n/**\n * @name useMemory\n * @description - Hook that gives you current memory usage\n * @category Browser\n *\n * @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory\n *\n * @returns {UseMemoryReturn} An object containing the current memory usage\n *\n * @example\n * const { supported, value } = useMemory();\n */\nexport const useMemory = (): UseMemoryReturn => {\n const supported = performance && 'memory' in performance;\n const [value, setValue] = useState<Performance['memory']>({\n
|
|
1
|
+
{"version":3,"file":"useMemory.cjs","sources":["../../../../src/hooks/useMemory/useMemory.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useInterval } from '../useInterval/useInterval';\n\ndeclare global {\n interface Performance {\n memory: {\n readonly jsHeapSizeLimit: number;\n readonly totalJSHeapSize: number;\n readonly usedJSHeapSize: number;\n };\n }\n}\n\n/** The use memory return type */\nexport interface UseMemoryReturn {\n /** The memory supported status */\n supported: boolean;\n /** The current memory usage */\n value: Performance['memory'];\n}\n\n/**\n * @name useMemory\n * @description - Hook that gives you current memory usage\n * @category Browser\n *\n * @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory\n *\n * @returns {UseMemoryReturn} An object containing the current memory usage\n *\n * @example\n * const { supported, value } = useMemory();\n */\nexport const useMemory = (): UseMemoryReturn => {\n const supported = performance && 'memory' in performance && !!performance.memory;\n const [value, setValue] = useState<Performance['memory']>(\n performance?.memory ?? {\n jsHeapSizeLimit: 0,\n totalJSHeapSize: 0,\n usedJSHeapSize: 0\n }\n );\n\n useInterval(() => setValue(performance.memory), 1000, {\n immediately: supported\n });\n\n return { supported, value };\n};\n"],"names":["useMemory","supported","value","setValue","useState","useInterval"],"mappings":"qJAkCaA,EAAY,IAAuB,CAC9C,MAAMC,EAAY,aAAe,WAAY,aAAe,CAAC,CAAC,YAAY,OACpE,CAACC,EAAOC,CAAQ,EAAIC,EAAA,UACxB,qCAAa,SAAU,CACrB,gBAAiB,EACjB,gBAAiB,EACjB,eAAgB,CAAA,CAEpB,EAEAC,OAAAA,EAAAA,YAAY,IAAMF,EAAS,YAAY,MAAM,EAAG,IAAM,CACpD,YAAaF,CAAA,CACd,EAEM,CAAE,UAAAA,EAAW,MAAAC,CAAM,CAC5B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),d=(n="history")=>{const{search:i,hash:e}=window.location;let r="";if(n==="history"&&(r=i),n==="hash-params"&&(r=e.replace(/^#/,"")),n==="hash"){const s=e.indexOf("?");r=~s?e.slice(s):""}return new URLSearchParams(r)},w=(n,i)=>{const e=n.toString(),{search:r,hash:t}=window.location;if(i==="history")return`${e?`?${e}`:""}${t}`;if(i==="hash-params")return`${r}${e?`#${e}`:""}`;if(i==="hash"){const s=t.indexOf("?"),c=s>-1?t.slice(0,s):t;return`${r}${c}${e?`?${e}`:""}`}throw new Error("Invalid mode")},S=(n,i,e="replace")=>{const r=new URLSearchParams;Object.entries(i).forEach(([s,c])=>{Array.isArray(c)?c.forEach(h=>r.set(s,String(h))):r.set(s,String(c))});const t=w(r,n);return e==="replace"&&window.history.replaceState({},"",t),e==="push"&&window.history.pushState({},"",t),r},p=(n,i={})=>{const{mode:e="history",write:r="replace"}=i,t=a=>typeof a=="string"?t(new URLSearchParams(a)):a instanceof URLSearchParams?Array.from(a.entries()).reduce((o,[u,f])=>{if(f==="undefined")return o;try{o[u]=JSON.parse(f)}catch{o[u]=f}return o},{}):a,[s,c]=l.useState(t(n??{})),h=(a,o="replace")=>{const u=S(e,{...s,...a},o??r);c(t(u))};return l.useEffect(()=>{h(s);const a=()=>{const o=d(e);h(t(o))};return window.addEventListener("popstate",a),e!=="history"&&window.addEventListener("hashchange",a),()=>{window.removeEventListener("popstate",a),e!=="history"&&window.removeEventListener("hashchange",a)}},[e]),{value:s,set:h}};exports.createQueryString=w;exports.getUrlSearchParams=d;exports.setUrlSearchParams=S;exports.useUrlSearchParams=p;
|
|
2
|
+
//# sourceMappingURL=useUrlSearchParams.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUrlSearchParams.cjs","sources":["../../../../src/hooks/useUrlSearchParams/useUrlSearchParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport const getUrlSearchParams = (mode: UrlSearchParamsMode = 'history') => {\n const { search, hash } = window.location;\n\n let path = '';\n\n if (mode === 'history') path = search;\n if (mode === 'hash-params') path = hash.replace(/^#/, '');\n if (mode === 'hash') {\n const index = hash.indexOf('?');\n path = ~index ? hash.slice(index) : '';\n }\n\n const searchParams = new URLSearchParams(path);\n\n return searchParams;\n};\n\nexport const createQueryString = (searchParams: URLSearchParams, mode: UrlSearchParamsMode) => {\n const searchParamsString = searchParams.toString();\n const { search, hash } = window.location;\n\n if (mode === 'history') return `${searchParamsString ? `?${searchParamsString}` : ''}${hash}`;\n if (mode === 'hash-params')\n return `${search}${searchParamsString ? `#${searchParamsString}` : ''}`;\n\n if (mode === 'hash') {\n const index = hash.indexOf('?');\n const base = index > -1 ? hash.slice(0, index) : hash;\n\n return `${search}${base}${searchParamsString ? `?${searchParamsString}` : ''}`;\n }\n\n throw new Error('Invalid mode');\n};\n\nexport const setUrlSearchParams = <Params extends UrlParams>(\n mode: UrlSearchParamsMode,\n params: Partial<Params>,\n write: 'push' | 'replace' = 'replace'\n) => {\n const searchParams = new URLSearchParams();\n\n Object.entries(params).forEach(([key, param]) => {\n if (Array.isArray(param)) {\n param.forEach((value) => searchParams.set(key, String(value)));\n } else {\n searchParams.set(key, String(param));\n }\n });\n\n const query = createQueryString(searchParams, mode);\n if (write === 'replace') window.history.replaceState({}, '', query);\n if (write === 'push') window.history.pushState({}, '', query);\n\n return searchParams;\n};\n\n/** The url params type */\nexport type UrlParams = Record<string, any>;\n\n/** The url search params mod */\nexport type UrlSearchParamsMode = 'hash-params' | 'hash' | 'history';\n\n/** The use url search params set options type */\nexport interface UseUrlSearchParamsSetOptions {\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/** The use url search params options type */\nexport interface UseUrlSearchParamsOptions {\n /** The mode to use for writing to the URL */\n mode?: UrlSearchParamsMode;\n /** The mode to use for writing to the URL */\n write?: 'push' | 'replace';\n}\n\n/** The use url search params return type */\nexport interface UseUrlSearchParamsReturn<Params extends UrlParams> {\n value: Params;\n set: (params: Partial<Params>) => void;\n}\n\n/**\n * @name useUrlSearchParams\n * @description - Hook that provides reactive URLSearchParams\n * @category Browser\n *\n * @overload\n * @template Value The type of the url param values\n * @param {UrlSearchParamsMode} mode The URL mode\n * @param {UseUrlSearchParamsOptions<Value>} [options] The URL mode\n * @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value\n *\n * @example\n * const { value, set } = useUrlSearchParams('history');\n */\nexport const useUrlSearchParams = <\n Params extends UrlParams,\n SearchParams extends string | UrlParams | URLSearchParams = UrlParams\n>(\n initialValue?: SearchParams,\n options: UseUrlSearchParamsOptions = {}\n): UseUrlSearchParamsReturn<Params> => {\n const { mode = 'history', write: writeMode = 'replace' } = options;\n\n const deserializer = (searchParams: string | UrlParams | URLSearchParams) => {\n if (typeof searchParams === 'string') {\n return deserializer(new URLSearchParams(searchParams));\n }\n\n if (searchParams instanceof URLSearchParams) {\n return Array.from(searchParams.entries()).reduce(\n (acc, [key, value]) => {\n if (value === 'undefined') return acc;\n try {\n acc[key] = JSON.parse(value);\n } catch {\n acc[key] = value;\n }\n return acc;\n },\n {} as Record<string, any>\n );\n }\n\n return searchParams;\n };\n\n const [value, setValue] = useState(deserializer(initialValue ?? {}) as Params);\n\n const set = (params: Partial<Params>, write: 'push' | 'replace' = 'replace') => {\n const searchParams = setUrlSearchParams(mode, { ...value, ...params }, write ?? writeMode);\n setValue(deserializer(searchParams) as Params);\n };\n\n useEffect(() => {\n set(value);\n\n const onParamsChange = () => {\n const searchParams = getUrlSearchParams(mode);\n set(deserializer(searchParams) as Params);\n };\n\n window.addEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.addEventListener('hashchange', onParamsChange);\n\n return () => {\n window.removeEventListener('popstate', onParamsChange);\n if (mode !== 'history') window.removeEventListener('hashchange', onParamsChange);\n };\n }, [mode]);\n\n return {\n value,\n set\n };\n};\n"],"names":["getUrlSearchParams","mode","search","hash","path","index","createQueryString","searchParams","searchParamsString","base","setUrlSearchParams","params","write","key","param","value","query","useUrlSearchParams","initialValue","options","writeMode","deserializer","acc","setValue","useState","set","useEffect","onParamsChange"],"mappings":"yGAEaA,EAAqB,CAACC,EAA4B,YAAc,CAC3E,KAAM,CAAE,OAAAC,EAAQ,KAAAC,CAAK,EAAI,OAAO,SAEhC,IAAIC,EAAO,GAIX,GAFIH,IAAS,YAAkBG,EAAAF,GAC3BD,IAAS,gBAAeG,EAAOD,EAAK,QAAQ,KAAM,EAAE,GACpDF,IAAS,OAAQ,CACb,MAAAI,EAAQF,EAAK,QAAQ,GAAG,EAC9BC,EAAO,CAACC,EAAQF,EAAK,MAAME,CAAK,EAAI,EAAA,CAK/B,OAFc,IAAI,gBAAgBD,CAAI,CAG/C,EAEaE,EAAoB,CAACC,EAA+BN,IAA8B,CACvF,MAAAO,EAAqBD,EAAa,SAAS,EAC3C,CAAE,OAAAL,EAAQ,KAAAC,CAAK,EAAI,OAAO,SAE5B,GAAAF,IAAS,UAAW,MAAO,GAAGO,EAAqB,IAAIA,CAAkB,GAAK,EAAE,GAAGL,CAAI,GAC3F,GAAIF,IAAS,cACX,MAAO,GAAGC,CAAM,GAAGM,EAAqB,IAAIA,CAAkB,GAAK,EAAE,GAEvE,GAAIP,IAAS,OAAQ,CACb,MAAAI,EAAQF,EAAK,QAAQ,GAAG,EACxBM,EAAOJ,EAAQ,GAAKF,EAAK,MAAM,EAAGE,CAAK,EAAIF,EAE1C,MAAA,GAAGD,CAAM,GAAGO,CAAI,GAAGD,EAAqB,IAAIA,CAAkB,GAAK,EAAE,EAAA,CAGxE,MAAA,IAAI,MAAM,cAAc,CAChC,EAEaE,EAAqB,CAChCT,EACAU,EACAC,EAA4B,YACzB,CACG,MAAAL,EAAe,IAAI,gBAElB,OAAA,QAAQI,CAAM,EAAE,QAAQ,CAAC,CAACE,EAAKC,CAAK,IAAM,CAC3C,MAAM,QAAQA,CAAK,EACfA,EAAA,QAASC,GAAUR,EAAa,IAAIM,EAAK,OAAOE,CAAK,CAAC,CAAC,EAE7DR,EAAa,IAAIM,EAAK,OAAOC,CAAK,CAAC,CACrC,CACD,EAEK,MAAAE,EAAQV,EAAkBC,EAAcN,CAAI,EAC9C,OAAAW,IAAU,WAAkB,OAAA,QAAQ,aAAa,CAAC,EAAG,GAAII,CAAK,EAC9DJ,IAAU,QAAe,OAAA,QAAQ,UAAU,CAAC,EAAG,GAAII,CAAK,EAErDT,CACT,EA0CaU,EAAqB,CAIhCC,EACAC,EAAqC,KACA,CACrC,KAAM,CAAE,KAAAlB,EAAO,UAAW,MAAOmB,EAAY,WAAcD,EAErDE,EAAgBd,GAChB,OAAOA,GAAiB,SACnBc,EAAa,IAAI,gBAAgBd,CAAY,CAAC,EAGnDA,aAAwB,gBACnB,MAAM,KAAKA,EAAa,QAAA,CAAS,EAAE,OACxC,CAACe,EAAK,CAACT,EAAKE,CAAK,IAAM,CACjBA,GAAAA,IAAU,YAAoB,OAAAO,EAC9B,GAAA,CACFA,EAAIT,CAAG,EAAI,KAAK,MAAME,CAAK,CAAA,MACrB,CACNO,EAAIT,CAAG,EAAIE,CAAA,CAEN,OAAAO,CACT,EACA,CAAA,CACF,EAGKf,EAGH,CAACQ,EAAOQ,CAAQ,EAAIC,WAASH,EAAaH,GAAgB,CAAA,CAAE,CAAW,EAEvEO,EAAM,CAACd,EAAyBC,EAA4B,YAAc,CACxE,MAAAL,EAAeG,EAAmBT,EAAM,CAAE,GAAGc,EAAO,GAAGJ,CAAA,EAAUC,GAASQ,CAAS,EAChFG,EAAAF,EAAad,CAAY,CAAW,CAC/C,EAEAmB,OAAAA,EAAAA,UAAU,IAAM,CACdD,EAAIV,CAAK,EAET,MAAMY,EAAiB,IAAM,CACrB,MAAApB,EAAeP,EAAmBC,CAAI,EACxCwB,EAAAJ,EAAad,CAAY,CAAW,CAC1C,EAEO,cAAA,iBAAiB,WAAYoB,CAAc,EAC9C1B,IAAS,WAAkB,OAAA,iBAAiB,aAAc0B,CAAc,EAErE,IAAM,CACJ,OAAA,oBAAoB,WAAYA,CAAc,EACjD1B,IAAS,WAAkB,OAAA,oBAAoB,aAAc0B,CAAc,CACjF,CAAA,EACC,CAAC1B,CAAI,CAAC,EAEF,CACL,MAAAc,EACA,IAAAU,CACF,CACF"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./hooks/useActiveElement/useActiveElement.cjs"),C=require("./hooks/useAsync/useAsync.cjs"),E=require("./hooks/useBattery/useBattery.cjs"),p=require("./hooks/useBluetooth/useBluetooth.cjs"),m=require("./hooks/useBoolean/useBoolean.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),y=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),R=require("./hooks/useClickOutside/useClickOutside.cjs"),O=require("./hooks/useClipboard/useClipboard.cjs"),k=require("./hooks/useConst/useConst.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),u=require("./hooks/useCookies/useCookies.cjs"),I=require("./hooks/useCopy/useCopy.cjs"),v=require("./hooks/useCounter/useCounter.cjs"),D=require("./hooks/useCssVar/useCssVar.cjs"),b=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),A=require("./hooks/useDebounceValue/useDebounceValue.cjs"),L=require("./hooks/useDefault/useDefault.cjs"),M=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),f=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),h=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),_=require("./hooks/useDidUpdate/useDidUpdate.cjs"),N=require("./hooks/useDisclosure/useDisclosure.cjs"),B=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),K=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),F=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),V=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),w=require("./hooks/useDoubleClick/useDoubleClick.cjs"),W=require("./hooks/useDropZone/useDropZone.cjs"),x=require("./hooks/useElementSize/useElementSize.cjs"),H=require("./hooks/useEvent/useEvent.cjs"),U=require("./hooks/useEventListener/useEventListener.cjs"),z=require("./hooks/useEventSource/useEventSource.cjs"),G=require("./hooks/useEyeDropper/useEyeDropper.cjs"),Q=require("./hooks/useFavicon/useFavicon.cjs"),X=require("./hooks/useField/useField.cjs"),Z=require("./hooks/useFileDialog/useFileDialog.cjs"),j=require("./hooks/useFocus/useFocus.cjs"),J=require("./hooks/useFps/useFps.cjs"),Y=require("./hooks/useFul/useFul.cjs"),$=require("./hooks/useFullscreen/useFullscreen.cjs"),i=require("./hooks/useGamepad/useGamepad.cjs"),ee=require("./hooks/useGeolocation/useGeolocation.cjs"),se=require("./hooks/useHash/useHash.cjs"),n=require("./hooks/useHotkeys/useHotkeys.cjs"),ue=require("./hooks/useHover/useHover.cjs"),re=require("./hooks/useIdle/useIdle.cjs"),te=require("./hooks/useImage/useImage.cjs"),oe=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),ie=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),ne=require("./hooks/useInterval/useInterval.cjs"),ce=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),ae=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),le=require("./hooks/useKeyboard/useKeyboard.cjs"),qe=require("./hooks/useKeyPress/useKeyPress.cjs"),Se=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),de=require("./hooks/useKeysPressed/useKeysPressed.cjs"),ge=require("./hooks/useLastChanged/useLastChanged.cjs"),Te=require("./hooks/useLatest/useLatest.cjs"),Pe=require("./hooks/useLess/useLess.cjs"),Ce=require("./hooks/useList/useList.cjs"),Ee=require("./hooks/useLocalStorage/useLocalStorage.cjs"),pe=require("./hooks/useLockCallback/useLockCallback.cjs"),me=require("./hooks/useLogger/useLogger.cjs"),ye=require("./hooks/useLongPress/useLongPress.cjs"),Re=require("./hooks/useMap/useMap.cjs"),Oe=require("./hooks/useMeasure/useMeasure.cjs"),ke=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Ie=require("./hooks/useMemory/useMemory.cjs"),ve=require("./hooks/useMount/useMount.cjs"),De=require("./hooks/useMouse/useMouse.cjs"),be=require("./hooks/useMutation/useMutation.cjs"),Ae=require("./hooks/useMutationObserver/useMutationObserver.cjs"),c=require("./hooks/useNetwork/useNetwork.cjs"),Le=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),Me=require("./hooks/useOnce/useOnce.cjs"),fe=require("./hooks/useOnline/useOnline.cjs"),a=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),he=require("./hooks/useOptimistic/useOptimistic.cjs"),_e=require("./hooks/useOrientation/useOrientation.cjs"),Ne=require("./hooks/useOtpCredential/useOtpCredential.cjs"),Be=require("./hooks/usePageLeave/usePageLeave.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),Ke=require("./hooks/useParallax/useParallax.cjs"),Fe=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),Ve=require("./hooks/usePermission/usePermission.cjs"),we=require("./hooks/usePointerLock/usePointerLock.cjs"),We=require("./hooks/usePostMessage/usePostMessage.cjs"),xe=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),He=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Ue=require("./hooks/usePreferredDark/usePreferredDark.cjs"),ze=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),Ge=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Qe=require("./hooks/usePrevious/usePrevious.cjs"),Xe=require("./hooks/useQuery/useQuery.cjs"),Ze=require("./hooks/useQueue/useQueue.cjs"),je=require("./hooks/useRaf/useRaf.cjs"),Je=require("./hooks/useRafValue/useRafValue.cjs"),Ye=require("./hooks/useRefState/useRefState.cjs"),$e=require("./hooks/useRenderCount/useRenderCount.cjs"),es=require("./hooks/useRenderInfo/useRenderInfo.cjs"),ss=require("./hooks/useRerender/useRerender.cjs"),us=require("./hooks/useResizeObserver/useResizeObserver.cjs"),rs=require("./hooks/useScreenOrientation/useScreenOrientation.cjs"),l=require("./hooks/useScript/useScript.cjs"),ts=require("./hooks/useScroll/useScroll.cjs"),os=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),is=require("./hooks/useScrollTo/useScrollTo.cjs"),ns=require("./hooks/useSessionStorage/useSessionStorage.cjs"),cs=require("./hooks/useSet/useSet.cjs"),as=require("./hooks/useShare/useShare.cjs"),q=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),ls=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),qs=require("./hooks/useStateHistory/useStateHistory.cjs"),Ss=require("./hooks/useStep/useStep.cjs"),ds=require("./hooks/useSticky/useSticky.cjs"),gs=require("./hooks/useStopwatch/useStopwatch.cjs"),t=require("./hooks/useStorage/useStorage.cjs"),Ts=require("./hooks/useTextDirection/useTextDirection.cjs"),S=require("./hooks/useTextSelection/useTextSelection.cjs"),Ps=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),Cs=require("./hooks/useThrottleValue/useThrottleValue.cjs"),Es=require("./hooks/useTime/useTime.cjs"),ps=require("./hooks/useTimeout/useTimeout.cjs"),d=require("./hooks/useTimer/useTimer.cjs"),ms=require("./hooks/useToggle/useToggle.cjs"),ys=require("./hooks/useUnmount/useUnmount.cjs"),Rs=require("./hooks/useVibrate/useVibrate.cjs"),Os=require("./hooks/useWakeLock/useWakeLock.cjs"),ks=require("./hooks/useWebSocket/useWebSocket.cjs"),Is=require("./hooks/useWindowEvent/useWindowEvent.cjs"),vs=require("./hooks/useWindowFocus/useWindowFocus.cjs"),g=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Ds=require("./hooks/useWindowSize/useWindowSize.cjs"),bs=require("./hooks/useWizard/useWizard.cjs"),T=require("./utils/helpers/copy.cjs"),As=require("./utils/helpers/debounce.cjs"),Ls=require("./utils/helpers/getDate.cjs"),o=require("./utils/helpers/getElement.cjs"),Ms=require("./utils/helpers/getRetry.cjs"),fs=require("./utils/helpers/isTarget.cjs"),hs=require("./utils/helpers/throttle.cjs");exports.useActiveElement=P.useActiveElement;exports.useAsync=C.useAsync;exports.useBattery=E.useBattery;exports.useBluetooth=p.useBluetooth;exports.useBoolean=m.useBoolean;exports.BREAKPOINTS_ANT_DESIGN=e.BREAKPOINTS_ANT_DESIGN;exports.BREAKPOINTS_BOOTSTRAP_V5=e.BREAKPOINTS_BOOTSTRAP_V5;exports.BREAKPOINTS_MANTINE=e.BREAKPOINTS_MANTINE;exports.BREAKPOINTS_MASTER_CSS=e.BREAKPOINTS_MASTER_CSS;exports.BREAKPOINTS_MATERIAL_UI=e.BREAKPOINTS_MATERIAL_UI;exports.BREAKPOINTS_PRIME_FLEX=e.BREAKPOINTS_PRIME_FLEX;exports.BREAKPOINTS_QUASAR_V2=e.BREAKPOINTS_QUASAR_V2;exports.BREAKPOINTS_SEMANTIC=e.BREAKPOINTS_SEMANTIC;exports.BREAKPOINTS_TAILWIND=e.BREAKPOINTS_TAILWIND;exports.useBreakpoints=e.useBreakpoints;exports.useBrowserLanguage=y.useBrowserLanguage;exports.useClickOutside=R.useClickOutside;exports.useClipboard=O.useClipboard;exports.useConst=k.useConst;exports.COOKIE_EVENT=s.COOKIE_EVENT;exports.dispatchCookieEvent=s.dispatchCookieEvent;exports.getCookie=s.getCookie;exports.getCookies=s.getCookies;exports.removeCookie=s.removeCookie;exports.removeCookieItem=s.removeCookieItem;exports.setCookie=s.setCookie;exports.setCookieItem=s.setCookieItem;exports.useCookie=s.useCookie;exports.clearCookies=u.clearCookies;exports.getParsedCookies=u.getParsedCookies;exports.useCookies=u.useCookies;exports.useCopy=I.useCopy;exports.useCounter=v.useCounter;exports.useCssVar=D.useCssVar;exports.useDebounceCallback=b.useDebounceCallback;exports.useDebounceValue=A.useDebounceValue;exports.useDefault=L.useDefault;exports.useDeviceMotion=M.useDeviceMotion;exports.useDeviceOrientation=f.useDeviceOrientation;exports.useDevicePixelRatio=h.useDevicePixelRatio;exports.useDidUpdate=_.useDidUpdate;exports.useDisclosure=N.useDisclosure;exports.useDisplayMedia=B.useDisplayMedia;exports.useDocumentEvent=K.useDocumentEvent;exports.useDocumentTitle=F.useDocumentTitle;exports.useDocumentVisibility=V.useDocumentVisibility;exports.useDoubleClick=w.useDoubleClick;exports.useDropZone=W.useDropZone;exports.useElementSize=x.useElementSize;exports.useEvent=H.useEvent;exports.useEventListener=U.useEventListener;exports.useEventSource=z.useEventSource;exports.useEyeDropper=G.useEyeDropper;exports.useFavicon=Q.useFavicon;exports.useField=X.useField;exports.useFileDialog=Z.useFileDialog;exports.useFocus=j.useFocus;exports.useFps=J.useFps;exports.useFul=Y.useFul;exports.useFullscreen=$.useFullscreen;exports.mapGamepadToXbox360Controller=i.mapGamepadToXbox360Controller;exports.useGamepad=i.useGamepad;exports.useGeolocation=ee.useGeolocation;exports.useHash=se.useHash;exports.isHotkeyMatch=n.isHotkeyMatch;exports.useHotkeys=n.useHotkeys;exports.useHover=ue.useHover;exports.useIdle=re.useIdle;exports.useImage=te.useImage;exports.useInfiniteScroll=oe.useInfiniteScroll;exports.useIntersectionObserver=ie.useIntersectionObserver;exports.useInterval=ne.useInterval;exports.useIsFirstRender=ce.useIsFirstRender;exports.useIsomorphicLayoutEffect=ae.useIsomorphicLayoutEffect;exports.useKeyboard=le.useKeyboard;exports.useKeyPress=qe.useKeyPress;exports.useKeyPressEvent=Se.useKeyPressEvent;exports.useKeysPressed=de.useKeysPressed;exports.useLastChanged=ge.useLastChanged;exports.useLatest=Te.useLatest;exports.useLess=Pe.useLess;exports.useList=Ce.useList;exports.useLocalStorage=Ee.useLocalStorage;exports.useLockCallback=pe.useLockCallback;exports.useLogger=me.useLogger;exports.useLongPress=ye.useLongPress;exports.useMap=Re.useMap;exports.useMeasure=Oe.useMeasure;exports.useMediaQuery=ke.useMediaQuery;exports.useMemory=Ie.useMemory;exports.useMount=ve.useMount;exports.useMouse=De.useMouse;exports.useMutation=be.useMutation;exports.useMutationObserver=Ae.useMutationObserver;exports.getConnection=c.getConnection;exports.useNetwork=c.useNetwork;exports.useOffsetPagination=Le.useOffsetPagination;exports.useOnce=Me.useOnce;exports.useOnline=fe.useOnline;exports.getOperatingSystem=a.getOperatingSystem;exports.useOperatingSystem=a.useOperatingSystem;exports.useOptimistic=he.useOptimistic;exports.useOrientation=_e.useOrientation;exports.useOtpCredential=Ne.useOtpCredential;exports.usePageLeave=Be.usePageLeave;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useParallax=Ke.useParallax;exports.usePerformanceObserver=Fe.usePerformanceObserver;exports.usePermission=Ve.usePermission;exports.usePointerLock=we.usePointerLock;exports.usePostMessage=We.usePostMessage;exports.usePreferredColorScheme=xe.usePreferredColorScheme;exports.usePreferredContrast=He.usePreferredContrast;exports.usePreferredDark=Ue.usePreferredDark;exports.usePreferredLanguages=ze.usePreferredLanguages;exports.usePreferredReducedMotion=Ge.usePreferredReducedMotion;exports.usePrevious=Qe.usePrevious;exports.useQuery=Xe.useQuery;exports.useQueue=Ze.useQueue;exports.useRaf=je.useRaf;exports.useRafValue=Je.useRafValue;exports.useRefState=Ye.useRefState;exports.useRenderCount=$e.useRenderCount;exports.useRenderInfo=es.useRenderInfo;exports.useRerender=ss.useRerender;exports.useResizeObserver=us.useResizeObserver;exports.useScreenOrientation=rs.useScreenOrientation;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=l.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=l.useScript;exports.useScroll=ts.useScroll;exports.useScrollIntoView=os.useScrollIntoView;exports.useScrollTo=is.useScrollTo;exports.useSessionStorage=ns.useSessionStorage;exports.useSet=cs.useSet;exports.useShare=as.useShare;exports.getSpeechRecognition=q.getSpeechRecognition;exports.useSpeechRecognition=q.useSpeechRecognition;exports.useSpeechSynthesis=ls.useSpeechSynthesis;exports.useStateHistory=qs.useStateHistory;exports.useStep=Ss.useStep;exports.useSticky=ds.useSticky;exports.useStopwatch=gs.useStopwatch;exports.STORAGE_EVENT=t.STORAGE_EVENT;exports.dispatchStorageEvent=t.dispatchStorageEvent;exports.useStorage=t.useStorage;exports.useTextDirection=Ts.useTextDirection;exports.getRangesSelection=S.getRangesSelection;exports.useTextSelection=S.useTextSelection;exports.useThrottleCallback=Ps.useThrottleCallback;exports.useThrottleValue=Cs.useThrottleValue;exports.useTime=Es.useTime;exports.useTimeout=ps.useTimeout;exports.getTimeFromSeconds=d.getTimeFromSeconds;exports.useTimer=d.useTimer;exports.useToggle=ms.useToggle;exports.useUnmount=ys.useUnmount;exports.useVibrate=Rs.useVibrate;exports.useWakeLock=Os.useWakeLock;exports.useWebSocket=ks.useWebSocket;exports.useWindowEvent=Is.useWindowEvent;exports.useWindowFocus=vs.useWindowFocus;exports.scrollTo=g.scrollTo;exports.useWindowScroll=g.useWindowScroll;exports.useWindowSize=Ds.useWindowSize;exports.useWizard=bs.useWizard;exports.copy=T.copy;exports.legacyCopyToClipboard=T.legacyCopyToClipboard;exports.debounce=As.debounce;exports.getDate=Ls.getDate;exports.getElement=o.getElement;exports.target=o.target;exports.targetSymbol=o.targetSymbol;exports.getRetry=Ms.getRetry;exports.isTarget=fs.isTarget;exports.throttle=hs.throttle;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("./helpers/createContext/createContext.cjs"),m=require("./helpers/createReactiveContext/createReactiveContext.cjs"),E=require("./helpers/createStore/createStore.cjs"),p=require("./hooks/useActiveElement/useActiveElement.cjs"),y=require("./hooks/useAsync/useAsync.cjs"),R=require("./hooks/useBattery/useBattery.cjs"),O=require("./hooks/useBluetooth/useBluetooth.cjs"),k=require("./hooks/useBoolean/useBoolean.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),I=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),v=require("./hooks/useClickOutside/useClickOutside.cjs"),D=require("./hooks/useClipboard/useClipboard.cjs"),b=require("./hooks/useConst/useConst.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),r=require("./hooks/useCookies/useCookies.cjs"),h=require("./hooks/useCopy/useCopy.cjs"),A=require("./hooks/useCounter/useCounter.cjs"),L=require("./hooks/useCssVar/useCssVar.cjs"),M=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),f=require("./hooks/useDebounceValue/useDebounceValue.cjs"),_=require("./hooks/useDefault/useDefault.cjs"),N=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),B=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),K=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),F=require("./hooks/useDidUpdate/useDidUpdate.cjs"),V=require("./hooks/useDisclosure/useDisclosure.cjs"),w=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),W=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),U=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),x=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),H=require("./hooks/useDoubleClick/useDoubleClick.cjs"),Q=require("./hooks/useDropZone/useDropZone.cjs"),z=require("./hooks/useElementSize/useElementSize.cjs"),G=require("./hooks/useEvent/useEvent.cjs"),X=require("./hooks/useEventListener/useEventListener.cjs"),Z=require("./hooks/useEventSource/useEventSource.cjs"),j=require("./hooks/useEyeDropper/useEyeDropper.cjs"),J=require("./hooks/useFavicon/useFavicon.cjs"),Y=require("./hooks/useField/useField.cjs"),$=require("./hooks/useFileDialog/useFileDialog.cjs"),ee=require("./hooks/useFocus/useFocus.cjs"),se=require("./hooks/useFps/useFps.cjs"),ue=require("./hooks/useFul/useFul.cjs"),re=require("./hooks/useFullscreen/useFullscreen.cjs"),n=require("./hooks/useGamepad/useGamepad.cjs"),te=require("./hooks/useGeolocation/useGeolocation.cjs"),oe=require("./hooks/useHash/useHash.cjs"),c=require("./hooks/useHotkeys/useHotkeys.cjs"),ie=require("./hooks/useHover/useHover.cjs"),ne=require("./hooks/useIdle/useIdle.cjs"),ce=require("./hooks/useImage/useImage.cjs"),ae=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),le=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),Se=require("./hooks/useInterval/useInterval.cjs"),qe=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),ge=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),de=require("./hooks/useKeyboard/useKeyboard.cjs"),Pe=require("./hooks/useKeyPress/useKeyPress.cjs"),Te=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),Ce=require("./hooks/useKeysPressed/useKeysPressed.cjs"),me=require("./hooks/useLastChanged/useLastChanged.cjs"),Ee=require("./hooks/useLatest/useLatest.cjs"),pe=require("./hooks/useLess/useLess.cjs"),ye=require("./hooks/useList/useList.cjs"),Re=require("./hooks/useLocalStorage/useLocalStorage.cjs"),Oe=require("./hooks/useLockCallback/useLockCallback.cjs"),ke=require("./hooks/useLogger/useLogger.cjs"),Ie=require("./hooks/useLongPress/useLongPress.cjs"),ve=require("./hooks/useMap/useMap.cjs"),De=require("./hooks/useMeasure/useMeasure.cjs"),be=require("./hooks/useMediaQuery/useMediaQuery.cjs"),he=require("./hooks/useMemory/useMemory.cjs"),Ae=require("./hooks/useMount/useMount.cjs"),Le=require("./hooks/useMouse/useMouse.cjs"),Me=require("./hooks/useMutation/useMutation.cjs"),fe=require("./hooks/useMutationObserver/useMutationObserver.cjs"),a=require("./hooks/useNetwork/useNetwork.cjs"),_e=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),Ne=require("./hooks/useOnce/useOnce.cjs"),Be=require("./hooks/useOnline/useOnline.cjs"),l=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Ke=require("./hooks/useOptimistic/useOptimistic.cjs"),Fe=require("./hooks/useOrientation/useOrientation.cjs"),Ve=require("./hooks/useOtpCredential/useOtpCredential.cjs"),we=require("./hooks/usePageLeave/usePageLeave.cjs"),t=require("./hooks/usePaint/usePaint.cjs"),We=require("./hooks/useParallax/useParallax.cjs"),Ue=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),xe=require("./hooks/usePermission/usePermission.cjs"),He=require("./hooks/usePointerLock/usePointerLock.cjs"),Qe=require("./hooks/usePostMessage/usePostMessage.cjs"),ze=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),Ge=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Xe=require("./hooks/usePreferredDark/usePreferredDark.cjs"),Ze=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),je=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Je=require("./hooks/usePrevious/usePrevious.cjs"),Ye=require("./hooks/useQuery/useQuery.cjs"),$e=require("./hooks/useQueue/useQueue.cjs"),es=require("./hooks/useRaf/useRaf.cjs"),ss=require("./hooks/useRafValue/useRafValue.cjs"),us=require("./hooks/useRefState/useRefState.cjs"),rs=require("./hooks/useRenderCount/useRenderCount.cjs"),ts=require("./hooks/useRenderInfo/useRenderInfo.cjs"),os=require("./hooks/useRerender/useRerender.cjs"),is=require("./hooks/useResizeObserver/useResizeObserver.cjs"),ns=require("./hooks/useScreenOrientation/useScreenOrientation.cjs"),S=require("./hooks/useScript/useScript.cjs"),cs=require("./hooks/useScroll/useScroll.cjs"),as=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),ls=require("./hooks/useScrollTo/useScrollTo.cjs"),Ss=require("./hooks/useSessionStorage/useSessionStorage.cjs"),qs=require("./hooks/useSet/useSet.cjs"),gs=require("./hooks/useShare/useShare.cjs"),q=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),ds=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),Ps=require("./hooks/useStateHistory/useStateHistory.cjs"),Ts=require("./hooks/useStep/useStep.cjs"),Cs=require("./hooks/useSticky/useSticky.cjs"),ms=require("./hooks/useStopwatch/useStopwatch.cjs"),o=require("./hooks/useStorage/useStorage.cjs"),Es=require("./hooks/useTextDirection/useTextDirection.cjs"),g=require("./hooks/useTextSelection/useTextSelection.cjs"),ps=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),ys=require("./hooks/useThrottleValue/useThrottleValue.cjs"),Rs=require("./hooks/useTime/useTime.cjs"),Os=require("./hooks/useTimeout/useTimeout.cjs"),d=require("./hooks/useTimer/useTimer.cjs"),ks=require("./hooks/useToggle/useToggle.cjs"),Is=require("./hooks/useUnmount/useUnmount.cjs"),u=require("./hooks/useUrlSearchParams/useUrlSearchParams.cjs"),vs=require("./hooks/useVibrate/useVibrate.cjs"),Ds=require("./hooks/useWakeLock/useWakeLock.cjs"),bs=require("./hooks/useWebSocket/useWebSocket.cjs"),hs=require("./hooks/useWindowEvent/useWindowEvent.cjs"),As=require("./hooks/useWindowFocus/useWindowFocus.cjs"),P=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Ls=require("./hooks/useWindowSize/useWindowSize.cjs"),Ms=require("./hooks/useWizard/useWizard.cjs"),T=require("./utils/helpers/copy.cjs"),fs=require("./utils/helpers/debounce.cjs"),_s=require("./utils/helpers/getDate.cjs"),i=require("./utils/helpers/getElement.cjs"),Ns=require("./utils/helpers/getRetry.cjs"),Bs=require("./utils/helpers/isTarget.cjs"),Ks=require("./utils/helpers/throttle.cjs");exports.createContext=C.createContext;exports.createReactiveContext=m.createReactiveContext;exports.createStore=E.createStore;exports.useActiveElement=p.useActiveElement;exports.useAsync=y.useAsync;exports.useBattery=R.useBattery;exports.useBluetooth=O.useBluetooth;exports.useBoolean=k.useBoolean;exports.BREAKPOINTS_ANT_DESIGN=e.BREAKPOINTS_ANT_DESIGN;exports.BREAKPOINTS_BOOTSTRAP_V5=e.BREAKPOINTS_BOOTSTRAP_V5;exports.BREAKPOINTS_MANTINE=e.BREAKPOINTS_MANTINE;exports.BREAKPOINTS_MASTER_CSS=e.BREAKPOINTS_MASTER_CSS;exports.BREAKPOINTS_MATERIAL_UI=e.BREAKPOINTS_MATERIAL_UI;exports.BREAKPOINTS_PRIME_FLEX=e.BREAKPOINTS_PRIME_FLEX;exports.BREAKPOINTS_QUASAR_V2=e.BREAKPOINTS_QUASAR_V2;exports.BREAKPOINTS_SEMANTIC=e.BREAKPOINTS_SEMANTIC;exports.BREAKPOINTS_TAILWIND=e.BREAKPOINTS_TAILWIND;exports.useBreakpoints=e.useBreakpoints;exports.useBrowserLanguage=I.useBrowserLanguage;exports.useClickOutside=v.useClickOutside;exports.useClipboard=D.useClipboard;exports.useConst=b.useConst;exports.COOKIE_EVENT=s.COOKIE_EVENT;exports.dispatchCookieEvent=s.dispatchCookieEvent;exports.getCookie=s.getCookie;exports.getCookies=s.getCookies;exports.removeCookie=s.removeCookie;exports.removeCookieItem=s.removeCookieItem;exports.setCookie=s.setCookie;exports.setCookieItem=s.setCookieItem;exports.useCookie=s.useCookie;exports.clearCookies=r.clearCookies;exports.getParsedCookies=r.getParsedCookies;exports.useCookies=r.useCookies;exports.useCopy=h.useCopy;exports.useCounter=A.useCounter;exports.useCssVar=L.useCssVar;exports.useDebounceCallback=M.useDebounceCallback;exports.useDebounceValue=f.useDebounceValue;exports.useDefault=_.useDefault;exports.useDeviceMotion=N.useDeviceMotion;exports.useDeviceOrientation=B.useDeviceOrientation;exports.useDevicePixelRatio=K.useDevicePixelRatio;exports.useDidUpdate=F.useDidUpdate;exports.useDisclosure=V.useDisclosure;exports.useDisplayMedia=w.useDisplayMedia;exports.useDocumentEvent=W.useDocumentEvent;exports.useDocumentTitle=U.useDocumentTitle;exports.useDocumentVisibility=x.useDocumentVisibility;exports.useDoubleClick=H.useDoubleClick;exports.useDropZone=Q.useDropZone;exports.useElementSize=z.useElementSize;exports.useEvent=G.useEvent;exports.useEventListener=X.useEventListener;exports.useEventSource=Z.useEventSource;exports.useEyeDropper=j.useEyeDropper;exports.useFavicon=J.useFavicon;exports.useField=Y.useField;exports.useFileDialog=$.useFileDialog;exports.useFocus=ee.useFocus;exports.useFps=se.useFps;exports.useFul=ue.useFul;exports.useFullscreen=re.useFullscreen;exports.mapGamepadToXbox360Controller=n.mapGamepadToXbox360Controller;exports.useGamepad=n.useGamepad;exports.useGeolocation=te.useGeolocation;exports.useHash=oe.useHash;exports.isHotkeyMatch=c.isHotkeyMatch;exports.useHotkeys=c.useHotkeys;exports.useHover=ie.useHover;exports.useIdle=ne.useIdle;exports.useImage=ce.useImage;exports.useInfiniteScroll=ae.useInfiniteScroll;exports.useIntersectionObserver=le.useIntersectionObserver;exports.useInterval=Se.useInterval;exports.useIsFirstRender=qe.useIsFirstRender;exports.useIsomorphicLayoutEffect=ge.useIsomorphicLayoutEffect;exports.useKeyboard=de.useKeyboard;exports.useKeyPress=Pe.useKeyPress;exports.useKeyPressEvent=Te.useKeyPressEvent;exports.useKeysPressed=Ce.useKeysPressed;exports.useLastChanged=me.useLastChanged;exports.useLatest=Ee.useLatest;exports.useLess=pe.useLess;exports.useList=ye.useList;exports.useLocalStorage=Re.useLocalStorage;exports.useLockCallback=Oe.useLockCallback;exports.useLogger=ke.useLogger;exports.useLongPress=Ie.useLongPress;exports.useMap=ve.useMap;exports.useMeasure=De.useMeasure;exports.useMediaQuery=be.useMediaQuery;exports.useMemory=he.useMemory;exports.useMount=Ae.useMount;exports.useMouse=Le.useMouse;exports.useMutation=Me.useMutation;exports.useMutationObserver=fe.useMutationObserver;exports.getConnection=a.getConnection;exports.useNetwork=a.useNetwork;exports.useOffsetPagination=_e.useOffsetPagination;exports.useOnce=Ne.useOnce;exports.useOnline=Be.useOnline;exports.getOperatingSystem=l.getOperatingSystem;exports.useOperatingSystem=l.useOperatingSystem;exports.useOptimistic=Ke.useOptimistic;exports.useOrientation=Fe.useOrientation;exports.useOtpCredential=Ve.useOtpCredential;exports.usePageLeave=we.usePageLeave;exports.Paint=t.Paint;exports.Pointer=t.Pointer;exports.usePaint=t.usePaint;exports.useParallax=We.useParallax;exports.usePerformanceObserver=Ue.usePerformanceObserver;exports.usePermission=xe.usePermission;exports.usePointerLock=He.usePointerLock;exports.usePostMessage=Qe.usePostMessage;exports.usePreferredColorScheme=ze.usePreferredColorScheme;exports.usePreferredContrast=Ge.usePreferredContrast;exports.usePreferredDark=Xe.usePreferredDark;exports.usePreferredLanguages=Ze.usePreferredLanguages;exports.usePreferredReducedMotion=je.usePreferredReducedMotion;exports.usePrevious=Je.usePrevious;exports.useQuery=Ye.useQuery;exports.useQueue=$e.useQueue;exports.useRaf=es.useRaf;exports.useRafValue=ss.useRafValue;exports.useRefState=us.useRefState;exports.useRenderCount=rs.useRenderCount;exports.useRenderInfo=ts.useRenderInfo;exports.useRerender=os.useRerender;exports.useResizeObserver=is.useResizeObserver;exports.useScreenOrientation=ns.useScreenOrientation;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=S.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=S.useScript;exports.useScroll=cs.useScroll;exports.useScrollIntoView=as.useScrollIntoView;exports.useScrollTo=ls.useScrollTo;exports.useSessionStorage=Ss.useSessionStorage;exports.useSet=qs.useSet;exports.useShare=gs.useShare;exports.getSpeechRecognition=q.getSpeechRecognition;exports.useSpeechRecognition=q.useSpeechRecognition;exports.useSpeechSynthesis=ds.useSpeechSynthesis;exports.useStateHistory=Ps.useStateHistory;exports.useStep=Ts.useStep;exports.useSticky=Cs.useSticky;exports.useStopwatch=ms.useStopwatch;exports.STORAGE_EVENT=o.STORAGE_EVENT;exports.dispatchStorageEvent=o.dispatchStorageEvent;exports.useStorage=o.useStorage;exports.useTextDirection=Es.useTextDirection;exports.getRangesSelection=g.getRangesSelection;exports.useTextSelection=g.useTextSelection;exports.useThrottleCallback=ps.useThrottleCallback;exports.useThrottleValue=ys.useThrottleValue;exports.useTime=Rs.useTime;exports.useTimeout=Os.useTimeout;exports.getTimeFromSeconds=d.getTimeFromSeconds;exports.useTimer=d.useTimer;exports.useToggle=ks.useToggle;exports.useUnmount=Is.useUnmount;exports.createQueryString=u.createQueryString;exports.getUrlSearchParams=u.getUrlSearchParams;exports.setUrlSearchParams=u.setUrlSearchParams;exports.useUrlSearchParams=u.useUrlSearchParams;exports.useVibrate=vs.useVibrate;exports.useWakeLock=Ds.useWakeLock;exports.useWebSocket=bs.useWebSocket;exports.useWindowEvent=hs.useWindowEvent;exports.useWindowFocus=As.useWindowFocus;exports.scrollTo=P.scrollTo;exports.useWindowScroll=P.useWindowScroll;exports.useWindowSize=Ls.useWindowSize;exports.useWizard=Ms.useWizard;exports.copy=T.copy;exports.legacyCopyToClipboard=T.legacyCopyToClipboard;exports.debounce=fs.debounce;exports.getDate=_s.getDate;exports.getElement=i.getElement;exports.target=i.target;exports.targetSymbol=i.targetSymbol;exports.getRetry=Ns.getRetry;exports.isTarget=Bs.isTarget;exports.throttle=Ks.throttle;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as m, use as v, useState as x, useMemo as d } from "react";
|
|
3
|
+
const P = (n = void 0, o = {}) => {
|
|
4
|
+
const t = m({
|
|
5
|
+
value: n,
|
|
6
|
+
set: () => {
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
t.displayName = o.name;
|
|
10
|
+
function i(r) {
|
|
11
|
+
const e = v(t);
|
|
12
|
+
if (!e && o.strict)
|
|
13
|
+
throw new Error(`Context hook ${o.name} must be used inside a Provider`);
|
|
14
|
+
return r ? r(e.value) : e;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
useSelect: i,
|
|
18
|
+
instance: t,
|
|
19
|
+
Provider: ({ children: r, initialValue: e }) => {
|
|
20
|
+
const [s, a] = x(e ?? n), c = d(
|
|
21
|
+
() => ({
|
|
22
|
+
value: s,
|
|
23
|
+
set: a
|
|
24
|
+
}),
|
|
25
|
+
[s]
|
|
26
|
+
);
|
|
27
|
+
return /* @__PURE__ */ u(t, { value: c, children: r });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
P as createContext
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=createContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContext.mjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, use, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = use(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","use","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":";;AAsDO,MAAMA,IAAgB,CAC3BC,IAAkC,QAClCC,IAAgC,CAAA,MACD;AAC/B,QAAMC,IAAUC,EAGb;AAAA,IACD,OAAOH;AAAA,IACP,KAAK,MAAM;AAAA,IAAA;AAAA,EAAC,CACb;AAED,EAAAE,EAAQ,cAAcD,EAAQ;AAI9B,WAASG,EAAoBC,GAAuC;AAC5D,UAAAC,IAAUC,EAAIL,CAAO;AAEvB,QAAA,CAACI,KAAWL,EAAQ;AACtB,YAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC;AAG/E,WAAKI,IAIEA,EAASC,EAAQ,KAAc,IAH7BA;AAAA,EAG6B;AAiBjC,SAAA;AAAA,IACL,WAAAF;AAAA,IACA,UAAUF;AAAA,IACV,UAjBe,CAAC,EAAE,UAAAM,GAAU,cAAAC,QAAyC;AACrE,YAAM,CAACC,GAASC,CAAU,IAAIC,EAA4BH,KAAgBT,CAAY,GAEhFa,IAAQC;AAAA,QACZ,OAAO;AAAA,UACL,OAAOJ;AAAA,UACP,KAAKC;AAAA,QAAA;AAAA,QAEP,CAACD,CAAO;AAAA,MACV;AAEO,aAAA,gBAAAK,EAACb,GAAQ,EAAA,OAAAW,GAAe,UAAAL,EAAS,CAAA;AAAA,IAC1C;AAAA,EAMA;AACF;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createContext as v, useRef as d, useMemo as f, startTransition as m, createElement as x, use as h, useState as P } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect as l } from "../../hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
+
import { useEvent as S } from "../../hooks/useEvent/useEvent.mjs";
|
|
4
|
+
const C = (c) => (e) => {
|
|
5
|
+
const t = d(e.value), n = f(
|
|
6
|
+
() => ({
|
|
7
|
+
value: t,
|
|
8
|
+
listeners: /* @__PURE__ */ new Set()
|
|
9
|
+
}),
|
|
10
|
+
[]
|
|
11
|
+
);
|
|
12
|
+
return l(() => {
|
|
13
|
+
Object.is(t.current, e.value) || (t.current = e.value, m(() => {
|
|
14
|
+
n.listeners.forEach((s) => {
|
|
15
|
+
s(t.current);
|
|
16
|
+
});
|
|
17
|
+
}));
|
|
18
|
+
}, [e.value]), x(c, { value: n }, e.children);
|
|
19
|
+
}, E = (c, r, e = {}) => {
|
|
20
|
+
const t = h(c);
|
|
21
|
+
if (!t && e.strict)
|
|
22
|
+
throw new Error(`Context hook ${e.name} must be used inside a Provider`);
|
|
23
|
+
const [n, s] = P({
|
|
24
|
+
selected: r(t.value.current),
|
|
25
|
+
value: t.value.current
|
|
26
|
+
}), o = S((i) => {
|
|
27
|
+
s((u) => {
|
|
28
|
+
if (Object.is(u.value, i)) return u;
|
|
29
|
+
const a = r(i);
|
|
30
|
+
return Object.is(u.selected, a) ? u : { value: i, selected: a };
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
return l(() => (t.listeners.add(o), () => {
|
|
34
|
+
t.listeners.delete(o);
|
|
35
|
+
}), [t.listeners]), n.selected;
|
|
36
|
+
}, w = (c = void 0, r = {}) => {
|
|
37
|
+
const e = v({
|
|
38
|
+
value: { current: c },
|
|
39
|
+
listeners: /* @__PURE__ */ new Set()
|
|
40
|
+
}), t = C(e.Provider);
|
|
41
|
+
e.displayName = r.name;
|
|
42
|
+
function n(s) {
|
|
43
|
+
return E(
|
|
44
|
+
e,
|
|
45
|
+
s ?? ((o) => o),
|
|
46
|
+
r
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return { instance: e, Provider: t, useSelector: n };
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
w as createReactiveContext
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=createReactiveContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createReactiveContext.mjs","sources":["../../../../src/helpers/createReactiveContext/createReactiveContext.ts"],"sourcesContent":["import type { Context, FC, Provider, ProviderProps, RefObject } from 'react';\n\nimport {\n createContext,\n createElement,\n startTransition,\n use,\n useMemo,\n useRef,\n useState\n} from 'react';\n\nimport { useEvent, useIsomorphicLayoutEffect } from '@/hooks';\n\n/** The create reactive context options type */\nexport interface CreateReactiveContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The create reactive context return type */\nexport interface CreateReactiveContextReturn<Value> {\n /** The context instance */\n instance: Context<ReactiveContextValue<Value>>;\n /** The Provider component for the context */\n Provider: Provider<Value>;\n /** A hook to select a part of the context state */\n useSelector: <Selected>(selector?: (state: Value) => Selected) => Selected;\n}\n\ntype ContextListener<Value> = (value: Value) => void;\n\ninterface ReactiveContextValue<Value> {\n /** The listeners for the context */\n listeners: Set<ContextListener<Value>>;\n /** The value for the context */\n value: RefObject<Value>;\n}\n\nconst createProvider = <Value>(originalProvider: Provider<ReactiveContextValue<Value>>) => {\n const Provider: FC<ProviderProps<Value>> = (props) => {\n const valueRef = useRef(props.value);\n const contextValue = useMemo<ReactiveContextValue<Value>>(\n () => ({\n value: valueRef,\n listeners: new Set()\n }),\n []\n );\n\n useIsomorphicLayoutEffect(() => {\n if (!Object.is(valueRef.current, props.value)) {\n valueRef.current = props.value;\n\n startTransition(() => {\n contextValue.listeners.forEach((listener) => {\n listener(valueRef.current);\n });\n });\n }\n }, [props.value]);\n\n return createElement(originalProvider, { value: contextValue }, props.children);\n };\n\n return Provider as unknown as Provider<ReactiveContextValue<Value>>;\n};\n\nconst createReactiveContextSelector = <Value, Selected>(\n Context: Context<ReactiveContextValue<Value>>,\n selector: (state: Value) => Selected,\n options: CreateReactiveContextOptions = {}\n) => {\n const context = use(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n const [value, setValue] = useState({\n selected: selector(context.value.current),\n value: context.value.current\n });\n\n const dispatch = useEvent((newValue: Value) => {\n setValue((prevValue) => {\n if (Object.is(prevValue.value, newValue)) return prevValue;\n\n const newSelected = selector(newValue);\n if (Object.is(prevValue.selected, newSelected)) return prevValue;\n\n return { value: newValue, selected: newSelected };\n });\n });\n\n useIsomorphicLayoutEffect(() => {\n context.listeners.add(dispatch);\n return () => {\n context.listeners.delete(dispatch);\n };\n }, [context.listeners]);\n\n return value.selected;\n};\n\n/**\n * @name createReactiveContext\n * @description - Creates a typed context selector with optimized updates for state selection\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateReactiveContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateReactiveContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { Provider, useSelector, instance } = createReactiveContext<number>(0);\n */\nexport const createReactiveContext = <Value extends Record<string, any>>(\n defaultValue: Value | undefined = undefined,\n options: CreateReactiveContextOptions = {}\n) => {\n const Context = createContext<ReactiveContextValue<Value>>({\n value: { current: defaultValue as Value },\n listeners: new Set()\n });\n\n const Provider = createProvider(Context.Provider) as unknown as Provider<Value>;\n\n Context.displayName = options.name;\n\n function useSelector(): Value;\n function useSelector<SelectedValue>(selector: (state: Value) => SelectedValue): SelectedValue;\n function useSelector<SelectedValue>(selector?: (state: Value) => SelectedValue) {\n return createReactiveContextSelector(\n Context as unknown as Context<ReactiveContextValue<Value>>,\n selector ?? ((state) => state as unknown as SelectedValue),\n options\n );\n }\n\n return { instance: Context, Provider, useSelector };\n};\n"],"names":["createProvider","originalProvider","props","valueRef","useRef","contextValue","useMemo","useIsomorphicLayoutEffect","startTransition","listener","createElement","createReactiveContextSelector","Context","selector","options","context","use","value","setValue","useState","dispatch","useEvent","newValue","prevValue","newSelected","createReactiveContext","defaultValue","createContext","Provider","useSelector","state"],"mappings":";;;AAyCA,MAAMA,IAAiB,CAAQC,MACc,CAACC,MAAU;AAC9C,QAAAC,IAAWC,EAAOF,EAAM,KAAK,GAC7BG,IAAeC;AAAA,IACnB,OAAO;AAAA,MACL,OAAOH;AAAA,MACP,+BAAe,IAAI;AAAA,IAAA;AAAA,IAErB,CAAA;AAAA,EACF;AAEA,SAAAI,EAA0B,MAAM;AAC9B,IAAK,OAAO,GAAGJ,EAAS,SAASD,EAAM,KAAK,MAC1CC,EAAS,UAAUD,EAAM,OAEzBM,EAAgB,MAAM;AACP,MAAAH,EAAA,UAAU,QAAQ,CAACI,MAAa;AAC3C,QAAAA,EAASN,EAAS,OAAO;AAAA,MAAA,CAC1B;AAAA,IAAA,CACF;AAAA,EACH,GACC,CAACD,EAAM,KAAK,CAAC,GAETQ,EAAcT,GAAkB,EAAE,OAAOI,EAAa,GAAGH,EAAM,QAAQ;AAChF,GAKIS,IAAgC,CACpCC,GACAC,GACAC,IAAwC,CAAA,MACrC;AACG,QAAAC,IAAUC,EAAIJ,CAAO;AAEvB,MAAA,CAACG,KAAWD,EAAQ;AACtB,UAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC;AAG/E,QAAM,CAACG,GAAOC,CAAQ,IAAIC,EAAS;AAAA,IACjC,UAAUN,EAASE,EAAQ,MAAM,OAAO;AAAA,IACxC,OAAOA,EAAQ,MAAM;AAAA,EAAA,CACtB,GAEKK,IAAWC,EAAS,CAACC,MAAoB;AAC7C,IAAAJ,EAAS,CAACK,MAAc;AACtB,UAAI,OAAO,GAAGA,EAAU,OAAOD,CAAQ,EAAU,QAAAC;AAE3C,YAAAC,IAAcX,EAASS,CAAQ;AACrC,aAAI,OAAO,GAAGC,EAAU,UAAUC,CAAW,IAAUD,IAEhD,EAAE,OAAOD,GAAU,UAAUE,EAAY;AAAA,IAAA,CACjD;AAAA,EAAA,CACF;AAED,SAAAjB,EAA0B,OAChBQ,EAAA,UAAU,IAAIK,CAAQ,GACvB,MAAM;AACH,IAAAL,EAAA,UAAU,OAAOK,CAAQ;AAAA,EACnC,IACC,CAACL,EAAQ,SAAS,CAAC,GAEfE,EAAM;AACf,GAeaQ,IAAwB,CACnCC,IAAkC,QAClCZ,IAAwC,CAAA,MACrC;AACH,QAAMF,IAAUe,EAA2C;AAAA,IACzD,OAAO,EAAE,SAASD,EAAsB;AAAA,IACxC,+BAAe,IAAI;AAAA,EAAA,CACpB,GAEKE,IAAW5B,EAAeY,EAAQ,QAAQ;AAEhD,EAAAA,EAAQ,cAAcE,EAAQ;AAI9B,WAASe,EAA2BhB,GAA4C;AACvE,WAAAF;AAAA,MACLC;AAAA,MACAC,MAAa,CAACiB,MAAUA;AAAA,MACxBhB;AAAA,IACF;AAAA,EAAA;AAGF,SAAO,EAAE,UAAUF,GAAS,UAAAgB,GAAU,aAAAC,EAAY;AACpD;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useSyncExternalStore as a } from "react";
|
|
2
|
+
const b = (s) => {
|
|
3
|
+
let t;
|
|
4
|
+
const n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
5
|
+
const u = typeof e == "function" ? e(t) : e;
|
|
6
|
+
if (!Object.is(u, t)) {
|
|
7
|
+
const f = t;
|
|
8
|
+
t = u, n.forEach((i) => i(t, f));
|
|
9
|
+
}
|
|
10
|
+
}, o = () => t, S = () => t, c = (e) => (n.add(e), () => n.delete(e));
|
|
11
|
+
return typeof s == "function" ? t = s(r, o) : t = s, {
|
|
12
|
+
set: r,
|
|
13
|
+
get: o,
|
|
14
|
+
use: (e) => a(
|
|
15
|
+
c,
|
|
16
|
+
() => e(o()),
|
|
17
|
+
() => e(S())
|
|
18
|
+
),
|
|
19
|
+
subscribe: c
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
b as createStore
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=createStore.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n *\n * @template Value - The type of the store state\n *\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => selector(getState()),\n () => selector(getInitialState())\n );\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":";AA+Ba,MAAAA,IAAc,CAAQC,MAA6C;AAE1E,MAAAC;AACE,QAAAC,wBAA+B,IAAI,GAEnCC,IAAW,CAACC,MAAkC;AAClD,UAAMC,IACJ,OAAOD,KAAW,aAAcA,EAAmCH,CAAK,IAAIG;AAE9E,QAAI,CAAC,OAAO,GAAGC,GAAWJ,CAAK,GAAG;AAChC,YAAMK,IAAYL;AACV,MAAAA,IAAAI,GACRH,EAAU,QAAQ,CAACK,MAAaA,EAASN,GAAOK,CAAS,CAAC;AAAA,IAAA;AAAA,EAE9D,GAEME,IAAW,MAAMP,GACjBQ,IAAkB,MAAMR,GAExBS,IAAY,CAACH,OACjBL,EAAU,IAAIK,CAAQ,GACf,MAAML,EAAU,OAAOK,CAAQ;AAEpC,SAAA,OAAOP,KAAgB,aAChBC,IAAAD,EAAoCG,GAAUK,CAAQ,IAEvDP,IAAAD,GAUH;AAAA,IACL,KAAKG;AAAA,IACL,KAAKK;AAAA,IACL,KAVe,CAAWG,MAC1BC;AAAA,MACEF;AAAA,MACA,MAAMC,EAASH,GAAU;AAAA,MACzB,MAAMG,EAASF,EAAiB,CAAA;AAAA,IAClC;AAAA,IAMA,WAAAC;AAAA,EACF;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClipboard.mjs","sources":["../../../../src/hooks/useClipboard/useClipboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy to clipboard return type */\nexport interface UseCopyToClipboardReturn {\n /** The copied value */\n value: string | null;\n /** Function to copy to clipboard */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy to clipboard params type */\nexport interface UseCopyToClipboardParams {\n /** Whether the copy to clipboard is enabled */\n enabled: boolean;\n}\n\n/**\n * @name useClipboard\n * @description - Hook that manages a copy to clipboard\n * @category Browser\n *\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled\n * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const {
|
|
1
|
+
{"version":3,"file":"useClipboard.mjs","sources":["../../../../src/hooks/useClipboard/useClipboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy to clipboard return type */\nexport interface UseCopyToClipboardReturn {\n /** The copied value */\n value: string | null;\n /** Function to copy to clipboard */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy to clipboard params type */\nexport interface UseCopyToClipboardParams {\n /** Whether the copy to clipboard is enabled */\n enabled: boolean;\n}\n\n/**\n * @name useClipboard\n * @description - Hook that manages a copy to clipboard\n * @category Browser\n *\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled\n * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const { value, copy } = useClipboard();\n */\nexport const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipboardReturn => {\n const [value, setValue] = useState<string | null>(null);\n const enabled = params?.enabled ?? false;\n\n const set = async () => {\n try {\n const value = await navigator.clipboard.readText();\n setValue(value);\n } catch {\n setValue(document.getSelection?.()?.toString() ?? '');\n }\n };\n\n useEffect(() => {\n if (!enabled) return;\n\n document.addEventListener('copy', set);\n document.addEventListener('cut', set);\n return () => {\n document.removeEventListener('copy', set);\n document.removeEventListener('cut', set);\n };\n }, [enabled]);\n\n const copyToClipboard = async (value: string) => {\n copy(value);\n setValue(value);\n };\n\n return { value, copy: copyToClipboard };\n};\n"],"names":["useClipboard","params","value","setValue","useState","enabled","set","_b","_a","useEffect","copy"],"mappings":";;AA+Ba,MAAAA,IAAe,CAACC,MAAgE;AAC3F,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAwB,IAAI,GAChDC,KAAUJ,KAAA,gBAAAA,EAAQ,YAAW,IAE7BK,IAAM,YAAY;;AAClB,QAAA;AACF,YAAMJ,IAAQ,MAAM,UAAU,UAAU,SAAS;AACjD,MAAAC,EAASD,CAAK;AAAA,IAAA,QACR;AACN,MAAAC,IAASI,KAAAC,IAAA,SAAS,iBAAT,gBAAAA,EAAA,mCAAAD,EAA2B,eAAc,EAAE;AAAA,IAAA;AAAA,EAExD;AAEA,SAAAE,EAAU,MAAM;AACd,QAAKJ;AAEI,sBAAA,iBAAiB,QAAQC,CAAG,GAC5B,SAAA,iBAAiB,OAAOA,CAAG,GAC7B,MAAM;AACF,iBAAA,oBAAoB,QAAQA,CAAG,GAC/B,SAAA,oBAAoB,OAAOA,CAAG;AAAA,MACzC;AAAA,EAAA,GACC,CAACD,CAAO,CAAC,GAOL,EAAE,OAAAH,GAAO,MALQ,OAAOA,MAAkB;AAC/C,IAAAQ,EAAKR,CAAK,GACVC,EAASD,CAAK;AAAA,EAChB,EAEsC;AACxC;"}
|
|
@@ -11,9 +11,7 @@ const F = (t) => {
|
|
|
11
11
|
if (n.current.value = e, l.current) return o();
|
|
12
12
|
}, b = () => {
|
|
13
13
|
x(i), f(!1), g(!1), c(void 0);
|
|
14
|
-
}, w = () => {
|
|
15
|
-
n.current.focus();
|
|
16
|
-
}, d = (e) => {
|
|
14
|
+
}, w = () => n.current.focus(), d = (e) => {
|
|
17
15
|
if (e.required && !n.current.value)
|
|
18
16
|
return c(e.required);
|
|
19
17
|
if (e.minLength && n.current.value.length < e.minLength.value)
|