@siberiacancode/reactuse 0.2.27 → 0.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
- package/dist/cjs/hooks/useAsync/useAsync.cjs +1 -1
- package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs.map +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs +20 -16
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useImage/useImage.mjs +22 -8
- package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs.map +1 -1
- package/dist/types/helpers/createStore/createStore.d.ts +12 -8
- package/dist/types/hooks/useAsync/useAsync.d.ts +2 -2
- package/dist/types/hooks/useImage/useImage.d.ts +6 -6
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),l=o=>{let e;const r=new Set,c=t=>{const n=typeof t=="function"?t(e):t;if(!Object.is(n,e)){const a=e;e=typeof n!="object"||n===null?n:Object.assign({},e,n),r.forEach(f=>f(e,a))}},u=t=>(r.add(t),()=>r.delete(t)),s=()=>e,i=()=>e;typeof o=="function"?e=o(c,s):e=o;function S(t){return b.useSyncExternalStore(u,()=>t?t(s()):s(),()=>t?t(i()):i())}return{set:c,get:s,use:S,subscribe:u}};exports.createStore=l;
|
|
2
2
|
//# sourceMappingURL=createStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype
|
|
1
|
+
{"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => 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 * @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: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state =\n typeof nextState !== 'object' || nextState === null\n ? nextState\n : Object.assign({}, state, nextState);\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n if (typeof createState === 'function') {\n state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\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","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":"yGAiCaA,EAAsBC,GAA6C,CAC9E,IAAIC,EACJ,MAAMC,MAA2C,IAE3CC,EAAyCC,GAAkC,CAC/E,MAAMC,EAAY,OAAOD,GAAW,WAAaA,EAAOH,CAAK,EAAIG,EAEjE,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EAClBA,EACE,OAAOI,GAAc,UAAYA,IAAc,KAC3CA,EACA,OAAO,OAAO,GAAIJ,EAAOI,CAAS,EAExCH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAaD,IACjBL,EAAU,IAAIK,CAAQ,EAEf,IAAML,EAAU,OAAOK,CAAQ,GAGlCE,EAAW,IAAMR,EACjBS,EAAkB,IAAMT,EAE1B,OAAOD,GAAgB,WACzBC,EAASD,EAAoCG,EAAUM,CAAQ,EAE/DR,EAAQD,EAKV,SAASW,EAAmBC,EAAyD,CACnF,OAAOC,EAAAA,qBACLL,EACA,IAAOI,EAAWA,EAASH,EAAA,CAAU,EAAIA,EAAA,EACzC,IAAOG,EAAWA,EAASF,EAAA,CAAiB,EAAIA,EAAA,CAAgB,CAClE,CAGF,MAAO,CACL,IAAKP,EACL,IAAKM,EACL,IAAKE,EACL,UAAAH,CAAA,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),f=(a,n)=>{const[u,s]=e.useState(!0),[c,r]=e.useState(!1),[i,o]=e.useState(void 0),[d,l]=e.useState(void 0);return e.useEffect(()=>{s(!0),a().then(t=>{l(t),o(void 0),r(!1)}).catch(t=>{o(t),r(!0)}).finally(()=>{s(!1)})},n),{data:d,isLoading:u,isError:c,error:i}};exports.useAsync=f;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),f=(a,n=[])=>{const[u,s]=e.useState(!0),[c,r]=e.useState(!1),[i,o]=e.useState(void 0),[d,l]=e.useState(void 0);return e.useEffect(()=>{s(!0),a().then(t=>{l(t),o(void 0),r(!1)}).catch(t=>{o(t),r(!0)}).finally(()=>{s(!1)})},n),{data:d,isLoading:u,isError:c,error:i}};exports.useAsync=f;
|
|
2
2
|
//# sourceMappingURL=useAsync.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,
|
|
1
|
+
{"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} [deps=[]] The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList = []\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,EAAuB,KACE,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACjBH,EAAA,EACG,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,CAAA,EACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CAAA,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../useQuery/useQuery.cjs"),t=async(s,e={})=>new Promise((o,f)=>{const r=new Image,{srcset:c,sizes:a,class:l,loading:i,crossorigin:g,referrerPolicy:n}=e;r.src=s,c&&(r.srcset=c),a&&(r.sizes=a),l&&(r.className=l),i&&(r.loading=i),g&&(r.crossOrigin=g),n&&(r.referrerPolicy=n),r.onload=()=>o(r),r.onerror=f}),u=(s,e)=>y.useQuery(()=>t(s,{alt:e?.alt,class:e?.class,crossorigin:e?.crossorigin,loading:e?.loading,referrerPolicy:e?.referrerPolicy,sizes:e?.sizes,srcset:e?.srcset}),{keys:[s,...e?.keys??[]],onSuccess:e?.onSuccess,onError:e?.onError,refetchInterval:e?.refetchInterval,retry:e?.retry});exports.useImage=u;
|
|
2
2
|
//# sourceMappingURL=useImage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImage.cjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [
|
|
1
|
+
{"version":3,"file":"useImage.cjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [options.keys] The dependencies for the hook\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @param {number} [options.refetchInterval] The refetch interval\n * @param {boolean | number} [options.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions &\n Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n >\n) =>\n useQuery(\n () =>\n loadImage(src, {\n alt: options?.alt,\n class: options?.class,\n crossorigin: options?.crossorigin,\n loading: options?.loading,\n referrerPolicy: options?.referrerPolicy,\n sizes: options?.sizes,\n srcset: options?.srcset\n }),\n {\n keys: [src, ...(options?.keys ?? [])],\n onSuccess: options?.onSuccess,\n onError: options?.onError,\n refetchInterval: options?.refetchInterval,\n retry: options?.retry\n }\n );\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQuery"],"mappings":"4HAyBMA,EAAY,MAAOC,EAAaC,EAA2B,CAAA,IAC/D,IAAI,QAAQ,CAACC,EAASC,IAAW,CAC/B,MAAMC,EAAM,IAAI,MACV,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAOC,EAAW,QAAAC,EAAS,YAAAC,EAAa,eAAAC,GAAmBT,EAElFG,EAAI,IAAMJ,EACNK,MAAY,OAASA,GACrBC,MAAW,MAAQA,GACnBC,MAAe,UAAYA,GAC3BC,MAAa,QAAUA,GACvBC,MAAiB,YAAcA,GAE/BC,MAAoB,eAAiBA,GAEzCN,EAAI,OAAS,IAAMF,EAAQE,CAAG,EAC9BA,EAAI,QAAUD,CAChB,CAAC,EAyBUQ,EAAW,CACtBX,EACAC,IAMAW,EAAAA,SACE,IACEb,EAAUC,EAAK,CACb,IAAKC,GAAS,IACd,MAAOA,GAAS,MAChB,YAAaA,GAAS,YACtB,QAASA,GAAS,QAClB,eAAgBA,GAAS,eACzB,MAAOA,GAAS,MAChB,OAAQA,GAAS,MAAA,CAClB,EACH,CACE,KAAM,CAACD,EAAK,GAAIC,GAAS,MAAQ,CAAA,CAAG,EACpC,UAAWA,GAAS,UACpB,QAASA,GAAS,QAClB,gBAAiBA,GAAS,gBAC1B,MAAOA,GAAS,KAAA,CAEpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualKeyboard.cjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface Navigator {\n virtualKeyboard?: {\n boundingRect: DOMRect;\n overlaysContent: boolean;\n show: () => void;\n hide: () => void;\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\n };\n }\n}\n\n/** The use virtual keyboard return type */\nexport interface UseVirtualKeyboardReturn {\n /** Whether the virtual keyboard is currently open */\n opened: boolean;\n /** Whether the VirtualKeyboard API is supported */\n supported: boolean;\n /** Change the overlays content */\n changeOverlaysContent: (overlaysContent: boolean) => void;\n /** Hide the virtual keyboard */\n hide: () => void;\n /** Show the virtual keyboard */\n show: () => void;\n}\n\n/**\n * @name useVirtualKeyboard\n * @description - Hook that manages virtual keyboard state\n * @category Browser\n *\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\n *\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\n *\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\n *\n * @example\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\n */\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\n const supported =\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\n\n const [opened, setOpened] = useState(initialValue);\n\n const hide = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.hide();\n setOpened(false);\n };\n\n const show = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.show();\n setOpened(true);\n };\n\n const changeOverlaysContent = (overlaysContent: boolean) => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\n\n const onGeometryChange = (event: Event) => {\n const { height } = (event.target as any).boundingRect as DOMRect;\n setOpened(height > 0);\n };\n\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\n\n return () => {\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\n };\n }, []);\n\n return {\n opened,\n show,\n hide,\n changeOverlaysContent,\n supported\n };\n};\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":"yGA4CaA,EAAqB,CAACC,EAAe,KAAoC,CACpF,MAAMC,EACH,OAAO,OAAW,KAAe,mBAAoB,QACrD,OAAO,UAAc,KAAe,oBAAqB,UAEtD,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,CAAY,EAE3CK,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BF,EAAU,EAAK,EAAA,EAGXG,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BH,EAAU,EAAI,EAAA,EAGVI,EAAyBC,GAA6B,CACrD,UAAU,kBACf,UAAU,gBAAgB,gBAAkBA,EAAA,EAG9CC,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACR,EAAW,OAEhB,MAAMS,EAAW,IAAMP,EAAU,OAAO,OAAO,OAAS,IAAM,OAAO,eAAgB,MAAM,EAErFQ,EAAoBC,GAAiB,CACzC,KAAM,CAAE,OAAAC,CAAA,EAAYD,EAAM,OAAe,aACzCT,EAAUU,EAAS,CAAC,CAAA,EAGtB,iBAAU,iBACR,UAAU,gBAAgB,iBAAiB,iBAAkBF,CAAgB,EAC/E,OAAO,gBAAkB,OAAO,eAAe,iBAAiB,SAAUD,CAAQ,EAE3E,IAAM,CACX,UAAU,iBACR,UAAU,gBAAgB,oBAAoB,iBAAkBC,CAAgB,EAClF,OAAO,gBAAkB,OAAO,eAAe,oBAAoB,SAAUD,CAAQ,CAAA,CACvF,EACC,EAAE,EAEE,CACL,OAAAR,EACA,KAAAI,EACA,KAAAD,EACA,sBAAAE,EACA,UAAAN,CAAA,CAEJ"}
|
|
1
|
+
{"version":3,"file":"useVirtualKeyboard.cjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\r\n\r\ndeclare global {\r\n interface Navigator {\r\n virtualKeyboard?: {\r\n boundingRect: DOMRect;\r\n overlaysContent: boolean;\r\n show: () => void;\r\n hide: () => void;\r\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n };\r\n }\r\n}\r\n\r\n/** The use virtual keyboard return type */\r\nexport interface UseVirtualKeyboardReturn {\r\n /** Whether the virtual keyboard is currently open */\r\n opened: boolean;\r\n /** Whether the VirtualKeyboard API is supported */\r\n supported: boolean;\r\n /** Change the overlays content */\r\n changeOverlaysContent: (overlaysContent: boolean) => void;\r\n /** Hide the virtual keyboard */\r\n hide: () => void;\r\n /** Show the virtual keyboard */\r\n show: () => void;\r\n}\r\n\r\n/**\r\n * @name useVirtualKeyboard\r\n * @description - Hook that manages virtual keyboard state\r\n * @category Browser\r\n *\r\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\r\n *\r\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\r\n *\r\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\r\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\r\n *\r\n * @example\r\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\r\n */\r\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\r\n const supported =\r\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\r\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\r\n\r\n const [opened, setOpened] = useState(initialValue);\r\n\r\n const hide = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.hide();\r\n setOpened(false);\r\n };\r\n\r\n const show = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.show();\r\n setOpened(true);\r\n };\r\n\r\n const changeOverlaysContent = (overlaysContent: boolean) => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\r\n };\r\n\r\n useEffect(() => {\r\n if (!supported) return;\r\n\r\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\r\n\r\n const onGeometryChange = (event: Event) => {\r\n const { height } = (event.target as any).boundingRect as DOMRect;\r\n setOpened(height > 0);\r\n };\r\n\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\r\n\r\n return () => {\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\r\n };\r\n }, []);\r\n\r\n return {\r\n opened,\r\n show,\r\n hide,\r\n changeOverlaysContent,\r\n supported\r\n };\r\n};\r\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":"yGA4CaA,EAAqB,CAACC,EAAe,KAAoC,CACpF,MAAMC,EACH,OAAO,OAAW,KAAe,mBAAoB,QACrD,OAAO,UAAc,KAAe,oBAAqB,UAEtD,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,CAAY,EAE3CK,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BF,EAAU,EAAK,EAAA,EAGXG,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BH,EAAU,EAAI,EAAA,EAGVI,EAAyBC,GAA6B,CACrD,UAAU,kBACf,UAAU,gBAAgB,gBAAkBA,EAAA,EAG9CC,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACR,EAAW,OAEhB,MAAMS,EAAW,IAAMP,EAAU,OAAO,OAAO,OAAS,IAAM,OAAO,eAAgB,MAAM,EAErFQ,EAAoBC,GAAiB,CACzC,KAAM,CAAE,OAAAC,CAAA,EAAYD,EAAM,OAAe,aACzCT,EAAUU,EAAS,CAAC,CAAA,EAGtB,iBAAU,iBACR,UAAU,gBAAgB,iBAAiB,iBAAkBF,CAAgB,EAC/E,OAAO,gBAAkB,OAAO,eAAe,iBAAiB,SAAUD,CAAQ,EAE3E,IAAM,CACX,UAAU,iBACR,UAAU,gBAAgB,oBAAoB,iBAAkBC,CAAgB,EAClF,OAAO,gBAAkB,OAAO,eAAe,oBAAoB,SAAUD,CAAQ,CAAA,CACvF,EACC,EAAE,EAEE,CACL,OAAAR,EACA,KAAAI,EACA,KAAAD,EACA,sBAAAE,EACA,UAAAN,CAAA,CAEJ"}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { useSyncExternalStore as
|
|
2
|
-
const
|
|
1
|
+
import { useSyncExternalStore as p } from "react";
|
|
2
|
+
const g = (o) => {
|
|
3
3
|
let e;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
if (!Object.is(
|
|
7
|
-
const
|
|
8
|
-
e =
|
|
4
|
+
const r = /* @__PURE__ */ new Set(), c = (t) => {
|
|
5
|
+
const n = typeof t == "function" ? t(e) : t;
|
|
6
|
+
if (!Object.is(n, e)) {
|
|
7
|
+
const S = e;
|
|
8
|
+
e = typeof n != "object" || n === null ? n : Object.assign({}, e, n), r.forEach((a) => a(e, S));
|
|
9
9
|
}
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
use: (t) => a(
|
|
10
|
+
}, u = (t) => (r.add(t), () => r.delete(t)), s = () => e, f = () => e;
|
|
11
|
+
typeof o == "function" ? e = o(c, s) : e = o;
|
|
12
|
+
function i(t) {
|
|
13
|
+
return p(
|
|
15
14
|
u,
|
|
16
|
-
() => t ? t(
|
|
17
|
-
() => t ? t(
|
|
18
|
-
)
|
|
15
|
+
() => t ? t(s()) : s(),
|
|
16
|
+
() => t ? t(f()) : f()
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
set: c,
|
|
21
|
+
get: s,
|
|
22
|
+
use: i,
|
|
19
23
|
subscribe: u
|
|
20
24
|
};
|
|
21
25
|
};
|
|
22
26
|
export {
|
|
23
|
-
|
|
27
|
+
g as createStore
|
|
24
28
|
};
|
|
25
29
|
//# sourceMappingURL=createStore.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype
|
|
1
|
+
{"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => 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 * @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: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state =\n typeof nextState !== 'object' || nextState === null\n ? nextState\n : Object.assign({}, state, nextState);\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n if (typeof createState === 'function') {\n state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\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","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":";AAiCO,MAAMA,IAAc,CAAQC,MAA6C;AAC9E,MAAIC;AACJ,QAAMC,wBAA2C,IAAA,GAE3CC,IAAwC,CAACC,MAAkC;AAC/E,UAAMC,IAAY,OAAOD,KAAW,aAAaA,EAAOH,CAAK,IAAIG;AAEjE,QAAI,CAAC,OAAO,GAAGC,GAAWJ,CAAK,GAAG;AAChC,YAAMK,IAAYL;AAClB,MAAAA,IACE,OAAOI,KAAc,YAAYA,MAAc,OAC3CA,IACA,OAAO,OAAO,IAAIJ,GAAOI,CAAS,GAExCH,EAAU,QAAQ,CAACK,MAAaA,EAASN,GAAOK,CAAS,CAAC;AAAA,IAAA;AAAA,EAC5D,GAGIE,IAAY,CAACD,OACjBL,EAAU,IAAIK,CAAQ,GAEf,MAAML,EAAU,OAAOK,CAAQ,IAGlCE,IAAW,MAAMR,GACjBS,IAAkB,MAAMT;AAE9B,EAAI,OAAOD,KAAgB,aACzBC,IAASD,EAAoCG,GAAUM,CAAQ,IAE/DR,IAAQD;AAKV,WAASW,EAAmBC,GAAyD;AACnF,WAAOC;AAAA,MACLL;AAAA,MACA,MAAOI,IAAWA,EAASH,EAAA,CAAU,IAAIA,EAAA;AAAA,MACzC,MAAOG,IAAWA,EAASF,EAAA,CAAiB,IAAIA,EAAA;AAAA,IAAgB;AAAA,EAClE;AAGF,SAAO;AAAA,IACL,KAAKP;AAAA,IACL,KAAKM;AAAA,IACL,KAAKE;AAAA,IACL,WAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.mjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":";AA4BO,MAAMA,IAAW,CACtBC,GACAC,
|
|
1
|
+
{"version":3,"file":"useAsync.mjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} [deps=[]] The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList = []\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":";AA4BO,MAAMA,IAAW,CACtBC,GACAC,IAAuB,OACE;AACzB,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAI,GACzC,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GAEtC,CAACG,GAAOC,CAAQ,IAAIJ,EAA4B,MAAS,GACzD,CAACK,GAAMC,CAAO,IAAIN,EAA2B,MAAS;AAE5D,SAAAO,EAAU,MAAM;AACd,IAAAR,EAAa,EAAI,GACjBH,EAAA,EACG,KAAK,CAACY,MAAa;AAClB,MAAAF,EAAQE,CAAQ,GAChBJ,EAAS,MAAS,GAClBF,EAAW,EAAK;AAAA,IAAA,CACjB,EACA,MAAM,CAACC,MAAiB;AACvB,MAAAC,EAASD,CAAK,GACdD,EAAW,EAAI;AAAA,IAAA,CAChB,EACA,QAAQ,MAAM;AACb,MAAAH,EAAa,EAAK;AAAA,IAAA,CACnB;AAAA,EAAA,GACFF,CAAI,GAEA;AAAA,IACL,MAAAQ;AAAA,IACA,WAAAP;AAAA,IACA,SAAAG;AAAA,IACA,OAAAE;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import { useQuery as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
}), d = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { useQuery as y } from "../useQuery/useQuery.mjs";
|
|
2
|
+
const m = async (s, r = {}) => new Promise((n, o) => {
|
|
3
|
+
const e = new Image(), { srcset: c, sizes: a, class: l, loading: i, crossorigin: f, referrerPolicy: g } = r;
|
|
4
|
+
e.src = s, c && (e.srcset = c), a && (e.sizes = a), l && (e.className = l), i && (e.loading = i), f && (e.crossOrigin = f), g && (e.referrerPolicy = g), e.onload = () => n(e), e.onerror = o;
|
|
5
|
+
}), d = (s, r) => y(
|
|
6
|
+
() => m(s, {
|
|
7
|
+
alt: r?.alt,
|
|
8
|
+
class: r?.class,
|
|
9
|
+
crossorigin: r?.crossorigin,
|
|
10
|
+
loading: r?.loading,
|
|
11
|
+
referrerPolicy: r?.referrerPolicy,
|
|
12
|
+
sizes: r?.sizes,
|
|
13
|
+
srcset: r?.srcset
|
|
14
|
+
}),
|
|
15
|
+
{
|
|
16
|
+
keys: [s, ...r?.keys ?? []],
|
|
17
|
+
onSuccess: r?.onSuccess,
|
|
18
|
+
onError: r?.onError,
|
|
19
|
+
refetchInterval: r?.refetchInterval,
|
|
20
|
+
retry: r?.retry
|
|
21
|
+
}
|
|
22
|
+
);
|
|
9
23
|
export {
|
|
10
24
|
d as useImage
|
|
11
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useImage.mjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [
|
|
1
|
+
{"version":3,"file":"useImage.mjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [options.keys] The dependencies for the hook\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @param {number} [options.refetchInterval] The refetch interval\n * @param {boolean | number} [options.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions &\n Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n >\n) =>\n useQuery(\n () =>\n loadImage(src, {\n alt: options?.alt,\n class: options?.class,\n crossorigin: options?.crossorigin,\n loading: options?.loading,\n referrerPolicy: options?.referrerPolicy,\n sizes: options?.sizes,\n srcset: options?.srcset\n }),\n {\n keys: [src, ...(options?.keys ?? [])],\n onSuccess: options?.onSuccess,\n onError: options?.onError,\n refetchInterval: options?.refetchInterval,\n retry: options?.retry\n }\n );\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQuery"],"mappings":";AAyBA,MAAMA,IAAY,OAAOC,GAAaC,IAA2B,CAAA,MAC/D,IAAI,QAAQ,CAACC,GAASC,MAAW;AAC/B,QAAMC,IAAM,IAAI,MAAA,GACV,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAOC,GAAW,SAAAC,GAAS,aAAAC,GAAa,gBAAAC,MAAmBT;AAElF,EAAAG,EAAI,MAAMJ,GACNK,QAAY,SAASA,IACrBC,QAAW,QAAQA,IACnBC,QAAe,YAAYA,IAC3BC,QAAa,UAAUA,IACvBC,QAAiB,cAAcA,IAE/BC,QAAoB,iBAAiBA,IAEzCN,EAAI,SAAS,MAAMF,EAAQE,CAAG,GAC9BA,EAAI,UAAUD;AAChB,CAAC,GAyBUQ,IAAW,CACtBX,GACAC,MAMAW;AAAA,EACE,MACEb,EAAUC,GAAK;AAAA,IACb,KAAKC,GAAS;AAAA,IACd,OAAOA,GAAS;AAAA,IAChB,aAAaA,GAAS;AAAA,IACtB,SAASA,GAAS;AAAA,IAClB,gBAAgBA,GAAS;AAAA,IACzB,OAAOA,GAAS;AAAA,IAChB,QAAQA,GAAS;AAAA,EAAA,CAClB;AAAA,EACH;AAAA,IACE,MAAM,CAACD,GAAK,GAAIC,GAAS,QAAQ,CAAA,CAAG;AAAA,IACpC,WAAWA,GAAS;AAAA,IACpB,SAASA,GAAS;AAAA,IAClB,iBAAiBA,GAAS;AAAA,IAC1B,OAAOA,GAAS;AAAA,EAAA;AAEpB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVirtualKeyboard.mjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface Navigator {\n virtualKeyboard?: {\n boundingRect: DOMRect;\n overlaysContent: boolean;\n show: () => void;\n hide: () => void;\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\n };\n }\n}\n\n/** The use virtual keyboard return type */\nexport interface UseVirtualKeyboardReturn {\n /** Whether the virtual keyboard is currently open */\n opened: boolean;\n /** Whether the VirtualKeyboard API is supported */\n supported: boolean;\n /** Change the overlays content */\n changeOverlaysContent: (overlaysContent: boolean) => void;\n /** Hide the virtual keyboard */\n hide: () => void;\n /** Show the virtual keyboard */\n show: () => void;\n}\n\n/**\n * @name useVirtualKeyboard\n * @description - Hook that manages virtual keyboard state\n * @category Browser\n *\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\n *\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\n *\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\n *\n * @example\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\n */\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\n const supported =\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\n\n const [opened, setOpened] = useState(initialValue);\n\n const hide = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.hide();\n setOpened(false);\n };\n\n const show = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.show();\n setOpened(true);\n };\n\n const changeOverlaysContent = (overlaysContent: boolean) => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\n\n const onGeometryChange = (event: Event) => {\n const { height } = (event.target as any).boundingRect as DOMRect;\n setOpened(height > 0);\n };\n\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\n\n return () => {\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\n };\n }, []);\n\n return {\n opened,\n show,\n hide,\n changeOverlaysContent,\n supported\n };\n};\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":";AA4CO,MAAMA,IAAqB,CAACC,IAAe,OAAoC;AACpF,QAAMC,IACH,OAAO,SAAW,OAAe,oBAAoB,UACrD,OAAO,YAAc,OAAe,qBAAqB,WAEtD,CAACC,GAAQC,CAAS,IAAIC,EAASJ,CAAY,GAE3CK,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BF,EAAU,EAAK;AAAA,EAAA,GAGXG,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BH,EAAU,EAAI;AAAA,EAAA,GAGVI,IAAwB,CAACC,MAA6B;AAC1D,IAAK,UAAU,oBACf,UAAU,gBAAgB,kBAAkBA;AAAA,EAAA;AAG9C,SAAAC,EAAU,MAAM;AACd,QAAI,CAACR,EAAW;AAEhB,UAAMS,IAAW,MAAMP,EAAU,OAAO,OAAO,SAAS,MAAM,OAAO,eAAgB,MAAM,GAErFQ,IAAmB,CAACC,MAAiB;AACzC,YAAM,EAAE,QAAAC,EAAA,IAAYD,EAAM,OAAe;AACzC,MAAAT,EAAUU,IAAS,CAAC;AAAA,IAAA;AAGtB,qBAAU,mBACR,UAAU,gBAAgB,iBAAiB,kBAAkBF,CAAgB,GAC/E,OAAO,kBAAkB,OAAO,eAAe,iBAAiB,UAAUD,CAAQ,GAE3E,MAAM;AACX,gBAAU,mBACR,UAAU,gBAAgB,oBAAoB,kBAAkBC,CAAgB,GAClF,OAAO,kBAAkB,OAAO,eAAe,oBAAoB,UAAUD,CAAQ;AAAA,IAAA;AAAA,EACvF,GACC,EAAE,GAEE;AAAA,IACL,QAAAR;AAAA,IACA,MAAAI;AAAA,IACA,MAAAD;AAAA,IACA,uBAAAE;AAAA,IACA,WAAAN;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"useVirtualKeyboard.mjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\r\n\r\ndeclare global {\r\n interface Navigator {\r\n virtualKeyboard?: {\r\n boundingRect: DOMRect;\r\n overlaysContent: boolean;\r\n show: () => void;\r\n hide: () => void;\r\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n };\r\n }\r\n}\r\n\r\n/** The use virtual keyboard return type */\r\nexport interface UseVirtualKeyboardReturn {\r\n /** Whether the virtual keyboard is currently open */\r\n opened: boolean;\r\n /** Whether the VirtualKeyboard API is supported */\r\n supported: boolean;\r\n /** Change the overlays content */\r\n changeOverlaysContent: (overlaysContent: boolean) => void;\r\n /** Hide the virtual keyboard */\r\n hide: () => void;\r\n /** Show the virtual keyboard */\r\n show: () => void;\r\n}\r\n\r\n/**\r\n * @name useVirtualKeyboard\r\n * @description - Hook that manages virtual keyboard state\r\n * @category Browser\r\n *\r\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\r\n *\r\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\r\n *\r\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\r\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\r\n *\r\n * @example\r\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\r\n */\r\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\r\n const supported =\r\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\r\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\r\n\r\n const [opened, setOpened] = useState(initialValue);\r\n\r\n const hide = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.hide();\r\n setOpened(false);\r\n };\r\n\r\n const show = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.show();\r\n setOpened(true);\r\n };\r\n\r\n const changeOverlaysContent = (overlaysContent: boolean) => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\r\n };\r\n\r\n useEffect(() => {\r\n if (!supported) return;\r\n\r\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\r\n\r\n const onGeometryChange = (event: Event) => {\r\n const { height } = (event.target as any).boundingRect as DOMRect;\r\n setOpened(height > 0);\r\n };\r\n\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\r\n\r\n return () => {\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\r\n };\r\n }, []);\r\n\r\n return {\r\n opened,\r\n show,\r\n hide,\r\n changeOverlaysContent,\r\n supported\r\n };\r\n};\r\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":";AA4CO,MAAMA,IAAqB,CAACC,IAAe,OAAoC;AACpF,QAAMC,IACH,OAAO,SAAW,OAAe,oBAAoB,UACrD,OAAO,YAAc,OAAe,qBAAqB,WAEtD,CAACC,GAAQC,CAAS,IAAIC,EAASJ,CAAY,GAE3CK,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BF,EAAU,EAAK;AAAA,EAAA,GAGXG,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BH,EAAU,EAAI;AAAA,EAAA,GAGVI,IAAwB,CAACC,MAA6B;AAC1D,IAAK,UAAU,oBACf,UAAU,gBAAgB,kBAAkBA;AAAA,EAAA;AAG9C,SAAAC,EAAU,MAAM;AACd,QAAI,CAACR,EAAW;AAEhB,UAAMS,IAAW,MAAMP,EAAU,OAAO,OAAO,SAAS,MAAM,OAAO,eAAgB,MAAM,GAErFQ,IAAmB,CAACC,MAAiB;AACzC,YAAM,EAAE,QAAAC,EAAA,IAAYD,EAAM,OAAe;AACzC,MAAAT,EAAUU,IAAS,CAAC;AAAA,IAAA;AAGtB,qBAAU,mBACR,UAAU,gBAAgB,iBAAiB,kBAAkBF,CAAgB,GAC/E,OAAO,kBAAkB,OAAO,eAAe,iBAAiB,UAAUD,CAAQ,GAE3E,MAAM;AACX,gBAAU,mBACR,UAAU,gBAAgB,oBAAoB,kBAAkBC,CAAgB,GAClF,OAAO,kBAAkB,OAAO,eAAe,oBAAoB,UAAUD,CAAQ;AAAA,IAAA;AAAA,EACvF,GACC,EAAE,GAEE;AAAA,IACL,QAAAR;AAAA,IACA,MAAAI;AAAA,IACA,MAAAD;AAAA,IACA,uBAAAE;AAAA,IACA,WAAAN;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
1
|
+
type StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;
|
|
2
|
+
type StoreListener<Value> = (state: Value, prevState: Value) => void;
|
|
3
|
+
type StoreCreator<Value> = (set: (action: StoreSetAction<Value>) => void, get: () => Value) => Value;
|
|
3
4
|
export interface StoreApi<Value> {
|
|
4
5
|
getInitialState: () => Value;
|
|
5
6
|
getState: () => Value;
|
|
6
|
-
setState: (action:
|
|
7
|
-
subscribe: (listener:
|
|
7
|
+
setState: (action: StoreSetAction<Value>) => void;
|
|
8
|
+
subscribe: (listener: StoreListener<Value>) => () => void;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* @name createStore
|
|
@@ -21,10 +22,13 @@ export interface StoreApi<Value> {
|
|
|
21
22
|
* increment: () => set(state => ({ count: state.count + 1 }))
|
|
22
23
|
* }));
|
|
23
24
|
*/
|
|
24
|
-
export declare const createStore: <Value>(createState:
|
|
25
|
-
set: (action:
|
|
25
|
+
export declare const createStore: <Value>(createState: StoreCreator<Value> | Value) => {
|
|
26
|
+
set: (action: StoreSetAction<Value>) => void;
|
|
26
27
|
get: () => Value;
|
|
27
|
-
use:
|
|
28
|
-
|
|
28
|
+
use: {
|
|
29
|
+
(): Value;
|
|
30
|
+
<Selected>(selector: (state: Value) => Selected): Selected;
|
|
31
|
+
};
|
|
32
|
+
subscribe: (listener: StoreListener<Value>) => () => boolean;
|
|
29
33
|
};
|
|
30
34
|
export {};
|
|
@@ -11,10 +11,10 @@ export interface UseAsyncReturn<Data> {
|
|
|
11
11
|
* @category Async
|
|
12
12
|
*
|
|
13
13
|
* @param {() => Promise<Data>} callback The async callback
|
|
14
|
-
* @param {DependencyList} deps The dependencies of the callback
|
|
14
|
+
* @param {DependencyList} [deps=[]] The dependencies of the callback
|
|
15
15
|
* @returns {UseAsyncReturn<Data>} The state of the async callback
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);
|
|
19
19
|
*/
|
|
20
|
-
export declare const useAsync: <Data>(callback: () => Promise<Data>, deps
|
|
20
|
+
export declare const useAsync: <Data>(callback: () => Promise<Data>, deps?: DependencyList) => UseAsyncReturn<Data>;
|
|
@@ -31,14 +31,14 @@ export type UseImageReturn = UseQueryReturn<HTMLImageElement>;
|
|
|
31
31
|
* @param {HTMLImageElement['loading']} [options.loading] The loading of the image
|
|
32
32
|
* @param {string} [options.crossorigin] The crossorigin of the image
|
|
33
33
|
* @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image
|
|
34
|
-
* @param {DependencyList} [
|
|
35
|
-
* @param {(data: Data) => void} [
|
|
36
|
-
* @param {(error: Error) => void} [
|
|
37
|
-
* @param {number} [
|
|
38
|
-
* @param {boolean | number} [
|
|
34
|
+
* @param {DependencyList} [options.keys] The dependencies for the hook
|
|
35
|
+
* @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success
|
|
36
|
+
* @param {(error: Error) => void} [options.onError] The callback function to be invoked on error
|
|
37
|
+
* @param {number} [options.refetchInterval] The refetch interval
|
|
38
|
+
* @param {boolean | number} [options.retry] The retry count of requests
|
|
39
39
|
* @returns {UseImageReturn} An object with the state of the image
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');
|
|
43
43
|
*/
|
|
44
|
-
export declare const useImage: (src: string, options?: UseImageOptions
|
|
44
|
+
export declare const useImage: (src: string, options?: UseImageOptions & Omit<UseQueryOptions<HTMLImageElement, HTMLImageElement>, "initialData" | "placeholderData" | "select">) => UseQueryReturn<HTMLImageElement>;
|