@siberiacancode/reactuse 0.2.27 → 0.2.29
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/useOffsetPagination/useOffsetPagination.cjs +1 -1
- package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.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/useOffsetPagination/useOffsetPagination.mjs +34 -41
- package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.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/dist/types/hooks/useObject/useObject.d.ts +34 -0
- package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +11 -24
- 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,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 u=require("react"),I=({total:g=Number.POSITIVE_INFINITY,initialPage:p=1,initialPageSize:f=10,onChange:e=()=>{}}={})=>{const[a,c]=u.useState(p),[t,P]=u.useState(f),S=u.useRef(e);S.current=e;const n=Math.max(1,Math.ceil(g/t)),i=a===1,o=a===n;return{page:a,setPage:s=>{c(s),e({page:s,pageSize:t})},setPageSize:P,pageSize:t,isFirstPage:i,isLastPage:o,pageCount:n,next:()=>{if(o)return e({page:n,pageSize:t});c(s=>{const r=s+1;return e({page:r,pageSize:t}),r})},prev:()=>{if(i)return e({page:1,pageSize:t});c(s=>{const r=s-1;return e({page:r,pageSize:t}),r})}}};exports.useOffsetPagination=I;
|
|
2
2
|
//# sourceMappingURL=useOffsetPagination.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOffsetPagination.cjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useOffsetPagination.cjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationOptions {\n /** The initial page number */\n initialPage?: number;\n /** The number of items per page */\n initialPageSize?: number;\n /** The total number of items */\n total?: number;\n /** The callback function to be invoked when page changes */\n onChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n}\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationReturn {\n /** Whether the current page is the first page */\n isFirstPage: boolean;\n /** Whether the current page is the last page */\n isLastPage: boolean;\n /** The current page number */\n page: number;\n /** The total number of pages */\n pageCount: number;\n /** The number of items per page */\n pageSize: number;\n /** The callback function to go to the next page */\n next: () => void;\n /** The callback function to go to the previous page */\n prev: () => void;\n /** The callback function to set the current page */\n setPage: (page: number) => void;\n /** The callback function to set the page size */\n setPageSize: (pageSize: number) => void;\n}\n\n/**\n * @name useOffsetPagination\n * @description - Hook that defines the logic when pagination\n * @category State\n *\n * @param {UseOffsetPaginationOptions} options - The options for the hook\n * @param {number} [options.total] - The total number of items\n * @param {number} [options.pageSize] - The number of items per page\n * @param {number} [options.initialPage] - The current page\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onChange] - The callback function to be invoked when page changes\n * @returns {UseOffsetPaginationReturn} - The state of the hook\n *\n * @example\n * const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({\n * total: 100,\n * initialPageSize: 10,\n * initialPage: 1\n * });\n */\nexport const useOffsetPagination = ({\n total = Number.POSITIVE_INFINITY,\n initialPage = 1,\n initialPageSize = 10,\n onChange = () => {}\n}: UseOffsetPaginationOptions = {}): UseOffsetPaginationReturn => {\n const [page, setPage] = useState(initialPage);\n const [pageSize, setPageSize] = useState(initialPageSize);\n\n const onChangeRef = useRef(onChange);\n onChangeRef.current = onChange;\n\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n const isFirstPage = page === 1;\n const isLastPage = page === pageCount;\n\n const next = () => {\n if (isLastPage) return onChange({ page: pageCount, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage + 1;\n onChange({ page, pageSize });\n return page;\n });\n };\n\n const prev = () => {\n if (isFirstPage) return onChange({ page: 1, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage - 1;\n onChange({ page, pageSize });\n return page;\n });\n };\n\n const set = (page: number) => {\n setPage(page);\n onChange({ page, pageSize });\n };\n\n return {\n page,\n setPage: set,\n setPageSize,\n pageSize,\n isFirstPage,\n isLastPage,\n pageCount,\n next,\n prev\n };\n};\n"],"names":["useOffsetPagination","total","initialPage","initialPageSize","onChange","page","setPage","useState","pageSize","setPageSize","onChangeRef","useRef","pageCount","isFirstPage","isLastPage","prevPage"],"mappings":"yGAuDaA,EAAsB,CAAC,CAClC,MAAAC,EAAQ,OAAO,kBACf,YAAAC,EAAc,EACd,gBAAAC,EAAkB,GAClB,SAAAC,EAAW,IAAM,CAAA,CACnB,EAAgC,KAAkC,CAChE,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAAA,SAASL,CAAW,EACtC,CAACM,EAAUC,CAAW,EAAIF,EAAAA,SAASJ,CAAe,EAElDO,EAAcC,EAAAA,OAAOP,CAAQ,EACnCM,EAAY,QAAUN,EAEtB,MAAMQ,EAAY,KAAK,IAAI,EAAG,KAAK,KAAKX,EAAQO,CAAQ,CAAC,EAEnDK,EAAcR,IAAS,EACvBS,EAAaT,IAASO,EA2B5B,MAAO,CACL,KAAAP,EACA,QAPWA,GAAiB,CAC5BC,EAAQD,CAAI,EACZD,EAAS,CAAE,KAAAC,EAAM,SAAAG,CAAA,CAAU,CAAA,EAM3B,YAAAC,EACA,SAAAD,EACA,YAAAK,EACA,WAAAC,EACA,UAAAF,EACA,KAjCW,IAAM,CACjB,GAAIE,EAAY,OAAOV,EAAS,CAAE,KAAMQ,EAAW,SAAAJ,EAAU,EAE7DF,EAASS,GAAa,CACpB,MAAMV,EAAOU,EAAW,EACxB,OAAAX,EAAS,CAAE,KAAAC,EAAM,SAAAG,CAAA,CAAU,EACpBH,CAAA,CACR,CAAA,EA2BD,KAxBW,IAAM,CACjB,GAAIQ,EAAa,OAAOT,EAAS,CAAE,KAAM,EAAG,SAAAI,EAAU,EAEtDF,EAASS,GAAa,CACpB,MAAMV,EAAOU,EAAW,EACxB,OAAAX,EAAS,CAAE,KAAAC,EAAM,SAAAG,CAAA,CAAU,EACpBH,CAAA,CACR,CAAA,CAiBD,CAEJ"}
|
|
@@ -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,48 +1,41 @@
|
|
|
1
|
-
import { useState as i, useRef as
|
|
2
|
-
const
|
|
3
|
-
total:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
onPageCountChange: f = () => {
|
|
9
|
-
},
|
|
10
|
-
onPageSizeChange: I = () => {
|
|
1
|
+
import { useState as i, useRef as m } from "react";
|
|
2
|
+
const z = ({
|
|
3
|
+
total: u = Number.POSITIVE_INFINITY,
|
|
4
|
+
initialPage: g = 1,
|
|
5
|
+
initialPageSize: f = 10,
|
|
6
|
+
onChange: e = () => {
|
|
11
7
|
}
|
|
12
8
|
} = {}) => {
|
|
13
|
-
const [
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
pageCount: u,
|
|
41
|
-
next: O,
|
|
42
|
-
prev: T
|
|
9
|
+
const [a, c] = i(g), [t, P] = i(f), I = m(e);
|
|
10
|
+
I.current = e;
|
|
11
|
+
const n = Math.max(1, Math.ceil(u / t)), p = a === 1, o = a === n;
|
|
12
|
+
return {
|
|
13
|
+
page: a,
|
|
14
|
+
setPage: (s) => {
|
|
15
|
+
c(s), e({ page: s, pageSize: t });
|
|
16
|
+
},
|
|
17
|
+
setPageSize: P,
|
|
18
|
+
pageSize: t,
|
|
19
|
+
isFirstPage: p,
|
|
20
|
+
isLastPage: o,
|
|
21
|
+
pageCount: n,
|
|
22
|
+
next: () => {
|
|
23
|
+
if (o) return e({ page: n, pageSize: t });
|
|
24
|
+
c((s) => {
|
|
25
|
+
const r = s + 1;
|
|
26
|
+
return e({ page: r, pageSize: t }), r;
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
prev: () => {
|
|
30
|
+
if (p) return e({ page: 1, pageSize: t });
|
|
31
|
+
c((s) => {
|
|
32
|
+
const r = s - 1;
|
|
33
|
+
return e({ page: r, pageSize: t }), r;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
43
36
|
};
|
|
44
37
|
};
|
|
45
38
|
export {
|
|
46
|
-
|
|
39
|
+
z as useOffsetPagination
|
|
47
40
|
};
|
|
48
41
|
//# sourceMappingURL=useOffsetPagination.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOffsetPagination.mjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useOffsetPagination.mjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationOptions {\n /** The initial page number */\n initialPage?: number;\n /** The number of items per page */\n initialPageSize?: number;\n /** The total number of items */\n total?: number;\n /** The callback function to be invoked when page changes */\n onChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n}\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationReturn {\n /** Whether the current page is the first page */\n isFirstPage: boolean;\n /** Whether the current page is the last page */\n isLastPage: boolean;\n /** The current page number */\n page: number;\n /** The total number of pages */\n pageCount: number;\n /** The number of items per page */\n pageSize: number;\n /** The callback function to go to the next page */\n next: () => void;\n /** The callback function to go to the previous page */\n prev: () => void;\n /** The callback function to set the current page */\n setPage: (page: number) => void;\n /** The callback function to set the page size */\n setPageSize: (pageSize: number) => void;\n}\n\n/**\n * @name useOffsetPagination\n * @description - Hook that defines the logic when pagination\n * @category State\n *\n * @param {UseOffsetPaginationOptions} options - The options for the hook\n * @param {number} [options.total] - The total number of items\n * @param {number} [options.pageSize] - The number of items per page\n * @param {number} [options.initialPage] - The current page\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onChange] - The callback function to be invoked when page changes\n * @returns {UseOffsetPaginationReturn} - The state of the hook\n *\n * @example\n * const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({\n * total: 100,\n * initialPageSize: 10,\n * initialPage: 1\n * });\n */\nexport const useOffsetPagination = ({\n total = Number.POSITIVE_INFINITY,\n initialPage = 1,\n initialPageSize = 10,\n onChange = () => {}\n}: UseOffsetPaginationOptions = {}): UseOffsetPaginationReturn => {\n const [page, setPage] = useState(initialPage);\n const [pageSize, setPageSize] = useState(initialPageSize);\n\n const onChangeRef = useRef(onChange);\n onChangeRef.current = onChange;\n\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n const isFirstPage = page === 1;\n const isLastPage = page === pageCount;\n\n const next = () => {\n if (isLastPage) return onChange({ page: pageCount, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage + 1;\n onChange({ page, pageSize });\n return page;\n });\n };\n\n const prev = () => {\n if (isFirstPage) return onChange({ page: 1, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage - 1;\n onChange({ page, pageSize });\n return page;\n });\n };\n\n const set = (page: number) => {\n setPage(page);\n onChange({ page, pageSize });\n };\n\n return {\n page,\n setPage: set,\n setPageSize,\n pageSize,\n isFirstPage,\n isLastPage,\n pageCount,\n next,\n prev\n };\n};\n"],"names":["useOffsetPagination","total","initialPage","initialPageSize","onChange","page","setPage","useState","pageSize","setPageSize","onChangeRef","useRef","pageCount","isFirstPage","isLastPage","prevPage"],"mappings":";AAuDO,MAAMA,IAAsB,CAAC;AAAA,EAClC,OAAAC,IAAQ,OAAO;AAAA,EACf,aAAAC,IAAc;AAAA,EACd,iBAAAC,IAAkB;AAAA,EAClB,UAAAC,IAAW,MAAM;AAAA,EAAA;AACnB,IAAgC,OAAkC;AAChE,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASL,CAAW,GACtC,CAACM,GAAUC,CAAW,IAAIF,EAASJ,CAAe,GAElDO,IAAcC,EAAOP,CAAQ;AACnC,EAAAM,EAAY,UAAUN;AAEtB,QAAMQ,IAAY,KAAK,IAAI,GAAG,KAAK,KAAKX,IAAQO,CAAQ,CAAC,GAEnDK,IAAcR,MAAS,GACvBS,IAAaT,MAASO;AA2B5B,SAAO;AAAA,IACL,MAAAP;AAAA,IACA,SAPU,CAACA,MAAiB;AAC5B,MAAAC,EAAQD,CAAI,GACZD,EAAS,EAAE,MAAAC,GAAM,UAAAG,EAAA,CAAU;AAAA,IAAA;AAAA,IAM3B,aAAAC;AAAA,IACA,UAAAD;AAAA,IACA,aAAAK;AAAA,IACA,YAAAC;AAAA,IACA,WAAAF;AAAA,IACA,MAjCW,MAAM;AACjB,UAAIE,EAAY,QAAOV,EAAS,EAAE,MAAMQ,GAAW,UAAAJ,GAAU;AAE7D,MAAAF,EAAQ,CAACS,MAAa;AACpB,cAAMV,IAAOU,IAAW;AACxB,eAAAX,EAAS,EAAE,MAAAC,GAAM,UAAAG,EAAA,CAAU,GACpBH;AAAAA,MAAA,CACR;AAAA,IAAA;AAAA,IA2BD,MAxBW,MAAM;AACjB,UAAIQ,EAAa,QAAOT,EAAS,EAAE,MAAM,GAAG,UAAAI,GAAU;AAEtD,MAAAF,EAAQ,CAACS,MAAa;AACpB,cAAMV,IAAOU,IAAW;AACxB,eAAAX,EAAS,EAAE,MAAAC,GAAM,UAAAG,EAAA,CAAU,GACpBH;AAAAA,MAAA,CACR;AAAA,IAAA;AAAA,EAiBD;AAEJ;"}
|
|
@@ -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>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The use object return type */
|
|
2
|
+
export interface UseObjectReturn<Value extends object> {
|
|
3
|
+
/** Checks if the object is empty */
|
|
4
|
+
empty: boolean;
|
|
5
|
+
/** Gets the keys of the object */
|
|
6
|
+
keys: Array<keyof Value>;
|
|
7
|
+
/** Gets the number of properties */
|
|
8
|
+
size: number;
|
|
9
|
+
/** The current object state */
|
|
10
|
+
value: Value;
|
|
11
|
+
/** Clears all properties from the object */
|
|
12
|
+
clear: () => void;
|
|
13
|
+
/** Checks if a property exists */
|
|
14
|
+
has: (key: keyof Value) => boolean;
|
|
15
|
+
/** Removes a property from the object */
|
|
16
|
+
remove: (key: keyof Value) => void;
|
|
17
|
+
/** Resets the object to its initial value */
|
|
18
|
+
reset: () => void;
|
|
19
|
+
/** Sets a property on the object */
|
|
20
|
+
set: (value: Partial<Value>) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @name useObject
|
|
24
|
+
* @description - Hook that provides state and helper methods to manage an object
|
|
25
|
+
* @category State
|
|
26
|
+
*
|
|
27
|
+
* @template Value The type of the object
|
|
28
|
+
* @param {Value} initialValue The initial object value
|
|
29
|
+
* @returns {UseObjectReturn<Value>} An object containing the current state and functions to interact with the object
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const { value, set, reset, remove, update, merge, clear, toggle, has, keys, isEmpty, size } = useObject({ name: 'John', age: 30, isActive: true });
|
|
33
|
+
*/
|
|
34
|
+
export declare function useObject<Value extends object>(initialValue: Value): UseObjectReturn<Value>;
|
|
@@ -3,29 +3,17 @@ export interface UseOffsetPaginationOptions {
|
|
|
3
3
|
/** The initial page number */
|
|
4
4
|
initialPage?: number;
|
|
5
5
|
/** The number of items per page */
|
|
6
|
-
|
|
6
|
+
initialPageSize?: number;
|
|
7
7
|
/** The total number of items */
|
|
8
8
|
total?: number;
|
|
9
9
|
/** The callback function to be invoked when page changes */
|
|
10
|
-
|
|
11
|
-
page: number;
|
|
12
|
-
pageSize: number;
|
|
13
|
-
}) => void;
|
|
14
|
-
/** The callback function to be invoked when page count changes */
|
|
15
|
-
onPageCountChange?: ({ page, pageSize }: {
|
|
16
|
-
page: number;
|
|
17
|
-
pageSize: number;
|
|
18
|
-
}) => void;
|
|
19
|
-
/** The callback function to be invoked when page size changes */
|
|
20
|
-
onPageSizeChange?: ({ page, pageSize }: {
|
|
10
|
+
onChange?: ({ page, pageSize }: {
|
|
21
11
|
page: number;
|
|
22
12
|
pageSize: number;
|
|
23
13
|
}) => void;
|
|
24
14
|
}
|
|
25
15
|
/** The use offset pagination return type */
|
|
26
16
|
export interface UseOffsetPaginationReturn {
|
|
27
|
-
/** The number of items per page */
|
|
28
|
-
currentPageSize: number;
|
|
29
17
|
/** Whether the current page is the first page */
|
|
30
18
|
isFirstPage: boolean;
|
|
31
19
|
/** Whether the current page is the last page */
|
|
@@ -34,12 +22,16 @@ export interface UseOffsetPaginationReturn {
|
|
|
34
22
|
page: number;
|
|
35
23
|
/** The total number of pages */
|
|
36
24
|
pageCount: number;
|
|
25
|
+
/** The number of items per page */
|
|
26
|
+
pageSize: number;
|
|
37
27
|
/** The callback function to go to the next page */
|
|
38
28
|
next: () => void;
|
|
39
29
|
/** The callback function to go to the previous page */
|
|
40
30
|
prev: () => void;
|
|
41
31
|
/** The callback function to set the current page */
|
|
42
|
-
|
|
32
|
+
setPage: (page: number) => void;
|
|
33
|
+
/** The callback function to set the page size */
|
|
34
|
+
setPageSize: (pageSize: number) => void;
|
|
43
35
|
}
|
|
44
36
|
/**
|
|
45
37
|
* @name useOffsetPagination
|
|
@@ -50,19 +42,14 @@ export interface UseOffsetPaginationReturn {
|
|
|
50
42
|
* @param {number} [options.total] - The total number of items
|
|
51
43
|
* @param {number} [options.pageSize] - The number of items per page
|
|
52
44
|
* @param {number} [options.initialPage] - The current page
|
|
53
|
-
* @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.
|
|
54
|
-
* @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageCountChange] - The callback function to be invoked when page count changes
|
|
55
|
-
* @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageSizeChange] - The callback function to be invoked when page size changes
|
|
45
|
+
* @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onChange] - The callback function to be invoked when page changes
|
|
56
46
|
* @returns {UseOffsetPaginationReturn} - The state of the hook
|
|
57
47
|
*
|
|
58
48
|
* @example
|
|
59
49
|
* const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({
|
|
60
50
|
* total: 100,
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* onPageChange: (page) => {},
|
|
64
|
-
* onPageCountChange: (pageCount) => {},
|
|
65
|
-
* onPageSizeChange: (pageSize) => {}
|
|
51
|
+
* initialPageSize: 10,
|
|
52
|
+
* initialPage: 1
|
|
66
53
|
* });
|
|
67
54
|
*/
|
|
68
|
-
export declare const useOffsetPagination: ({ total,
|
|
55
|
+
export declare const useOffsetPagination: ({ total, initialPage, initialPageSize, onChange }?: UseOffsetPaginationOptions) => UseOffsetPaginationReturn;
|