@aigamo/route-sphere 2.1.0-2 → 2.1.0-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/useLocalStorageState.d.ts +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/react-router/useLocationState.d.ts +2 -2
- package/dist/react-router.cjs.js.map +1 -1
- package/dist/react-router.es.js.map +1 -1
- package/dist/stores/{IReactiveStateStore.d.ts → IStateStore.d.ts} +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/tanstack-router/useLocationState.d.ts +2 -2
- package/dist/tanstack-router.cjs.js.map +1 -1
- package/dist/tanstack-router.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const useLocalStorageState: <TState>(key: string, store:
|
|
1
|
+
import { IStateStore } from '../stores/IStateStore';
|
|
2
|
+
export declare const useLocalStorageState: <TState>(key: string, store: IStateStore<TState>) => void;
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/components/ScrollToTop.tsx","../src/components/useLocalStorageState.tsx","../src/helpers/includesAny.ts"],"sourcesContent":["import { useLayoutEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\nexport const ScrollToTop = (): null => {\n\tconst location = useLocation();\n\n\tuseLayoutEffect(() => {\n\t\twindow.scrollTo(0, 0);\n\t}, [location]);\n\n\treturn null;\n};\n","import type {
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/components/ScrollToTop.tsx","../src/components/useLocalStorageState.tsx","../src/helpers/includesAny.ts"],"sourcesContent":["import { useLayoutEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\nexport const ScrollToTop = (): null => {\n\tconst location = useLocation();\n\n\tuseLayoutEffect(() => {\n\t\twindow.scrollTo(0, 0);\n\t}, [location]);\n\n\treturn null;\n};\n","import type { IStateStore } from '@/stores/IStateStore';\nimport type { StateChangeEvent } from '@/stores/StateChangeEvent';\nimport { useCallback } from 'react';\n\nimport { useStateHandler } from './useStateHandler';\n\nconst useLocalStorageStateDeserializer = (key: string): (() => any) => {\n\treturn useCallback((): any => {\n\t\ttry {\n\t\t\treturn JSON.parse(\n\t\t\t\twindow.localStorage.getItem(key) ?? JSON.stringify({}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(error);\n\t\t\treturn {};\n\t\t}\n\t}, [key]);\n};\n\nconst useLocalStorageStateSerializer = <TState,>(\n\tkey: string,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState): void => {\n\t\t\twindow.localStorage.setItem(key, JSON.stringify(state));\n\t\t},\n\t\t[key],\n\t);\n};\n\nconst useLocalStorageStateHandler = <TState,>(\n\tkey: string,\n\tstateValidator: (state: any) => state is TState,\n\tstateSetter: (state: TState) => void,\n\tonStateChange: ((event: StateChangeEvent<TState>) => void) | undefined,\n\tstateGetter: () => TState,\n): void => {\n\tconst deserializer = useLocalStorageStateDeserializer(key);\n\tconst serializer = useLocalStorageStateSerializer(key);\n\tuseStateHandler(\n\t\tdeserializer,\n\t\tstateValidator,\n\t\tstateSetter,\n\t\tonStateChange,\n\t\tstateGetter,\n\t\tserializer,\n\t);\n};\n\nconst useLocalStorageStateSetter = <TState,>(\n\tstore: IStateStore<TState>,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState): void => {\n\t\t\tstore.state = state;\n\t\t},\n\t\t[store],\n\t);\n};\n\nconst useLocalStorageStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback((): TState => store.state, [store]);\n};\n\nexport const useLocalStorageState = <TState,>(\n\tkey: string,\n\tstore: IStateStore<TState>,\n): void => {\n\tconst stateSetter = useLocalStorageStateSetter(store);\n\tconst stateGetter = useLocalStorageStateGetter(store);\n\tuseLocalStorageStateHandler(\n\t\tkey,\n\t\tstore.validateState,\n\t\tstateSetter,\n\t\tstore.onStateChange,\n\t\tstateGetter,\n\t);\n};\n","export const includesAny = <T>(array: T[], values: T[]): boolean => {\n\treturn values.some((value) => array.includes(value));\n};\n"],"names":["ScrollToTop","location","useLocation","useLayoutEffect","useLocalStorageStateDeserializer","key","useCallback","error","useLocalStorageStateSerializer","state","useLocalStorageStateHandler","stateValidator","stateSetter","onStateChange","stateGetter","deserializer","serializer","useStateHandler","useLocalStorageStateSetter","store","useLocalStorageStateGetter","useLocalStorageState","includesAny","array","values","value"],"mappings":"mLAGaA,EAAc,IAAY,CACtC,MAAMC,EAAWC,EAAAA,YAAA,EAEjBC,OAAAA,EAAAA,gBAAgB,IAAM,CACrB,OAAO,SAAS,EAAG,CAAC,CACrB,EAAG,CAACF,CAAQ,CAAC,EAEN,IACR,ECLMG,EAAoCC,GAClCC,EAAAA,YAAY,IAAW,CAC7B,GAAI,CACH,OAAO,KAAK,MACX,OAAO,aAAa,QAAQD,CAAG,GAAK,KAAK,UAAU,CAAA,CAAE,CAAA,CAEvD,OAASE,EAAO,CACf,eAAQ,MAAMA,CAAK,EACZ,CAAA,CACR,CACD,EAAG,CAACF,CAAG,CAAC,EAGHG,EACLH,GAEOC,EAAAA,YACLG,GAAwB,CACxB,OAAO,aAAa,QAAQJ,EAAK,KAAK,UAAUI,CAAK,CAAC,CACvD,EACA,CAACJ,CAAG,CAAA,EAIAK,EAA8B,CACnCL,EACAM,EACAC,EACAC,EACAC,IACU,CACV,MAAMC,EAAeX,EAAiCC,CAAG,EACnDW,EAAaR,EAA+BH,CAAG,EACrDY,EAAAA,gBACCF,EACAJ,EACAC,EACAC,EACAC,EACAE,CAAA,CAEF,EAEME,EACLC,GAEOb,EAAAA,YACLG,GAAwB,CACxBU,EAAM,MAAQV,CACf,EACA,CAACU,CAAK,CAAA,EAIFC,EACLD,GAEOb,EAAAA,YAAY,IAAca,EAAM,MAAO,CAACA,CAAK,CAAC,EAGzCE,EAAuB,CACnChB,EACAc,IACU,CACV,MAAMP,EAAcM,EAA2BC,CAAK,EAC9CL,EAAcM,EAA2BD,CAAK,EACpDT,EACCL,EACAc,EAAM,cACNP,EACAO,EAAM,cACNL,CAAA,CAEF,EC/EaQ,EAAc,CAAIC,EAAYC,IACnCA,EAAO,KAAMC,GAAUF,EAAM,SAASE,CAAK,CAAC"}
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/components/ScrollToTop.tsx","../src/components/useLocalStorageState.tsx","../src/helpers/includesAny.ts"],"sourcesContent":["import { useLayoutEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\nexport const ScrollToTop = (): null => {\n\tconst location = useLocation();\n\n\tuseLayoutEffect(() => {\n\t\twindow.scrollTo(0, 0);\n\t}, [location]);\n\n\treturn null;\n};\n","import type {
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/components/ScrollToTop.tsx","../src/components/useLocalStorageState.tsx","../src/helpers/includesAny.ts"],"sourcesContent":["import { useLayoutEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\nexport const ScrollToTop = (): null => {\n\tconst location = useLocation();\n\n\tuseLayoutEffect(() => {\n\t\twindow.scrollTo(0, 0);\n\t}, [location]);\n\n\treturn null;\n};\n","import type { IStateStore } from '@/stores/IStateStore';\nimport type { StateChangeEvent } from '@/stores/StateChangeEvent';\nimport { useCallback } from 'react';\n\nimport { useStateHandler } from './useStateHandler';\n\nconst useLocalStorageStateDeserializer = (key: string): (() => any) => {\n\treturn useCallback((): any => {\n\t\ttry {\n\t\t\treturn JSON.parse(\n\t\t\t\twindow.localStorage.getItem(key) ?? JSON.stringify({}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(error);\n\t\t\treturn {};\n\t\t}\n\t}, [key]);\n};\n\nconst useLocalStorageStateSerializer = <TState,>(\n\tkey: string,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState): void => {\n\t\t\twindow.localStorage.setItem(key, JSON.stringify(state));\n\t\t},\n\t\t[key],\n\t);\n};\n\nconst useLocalStorageStateHandler = <TState,>(\n\tkey: string,\n\tstateValidator: (state: any) => state is TState,\n\tstateSetter: (state: TState) => void,\n\tonStateChange: ((event: StateChangeEvent<TState>) => void) | undefined,\n\tstateGetter: () => TState,\n): void => {\n\tconst deserializer = useLocalStorageStateDeserializer(key);\n\tconst serializer = useLocalStorageStateSerializer(key);\n\tuseStateHandler(\n\t\tdeserializer,\n\t\tstateValidator,\n\t\tstateSetter,\n\t\tonStateChange,\n\t\tstateGetter,\n\t\tserializer,\n\t);\n};\n\nconst useLocalStorageStateSetter = <TState,>(\n\tstore: IStateStore<TState>,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState): void => {\n\t\t\tstore.state = state;\n\t\t},\n\t\t[store],\n\t);\n};\n\nconst useLocalStorageStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback((): TState => store.state, [store]);\n};\n\nexport const useLocalStorageState = <TState,>(\n\tkey: string,\n\tstore: IStateStore<TState>,\n): void => {\n\tconst stateSetter = useLocalStorageStateSetter(store);\n\tconst stateGetter = useLocalStorageStateGetter(store);\n\tuseLocalStorageStateHandler(\n\t\tkey,\n\t\tstore.validateState,\n\t\tstateSetter,\n\t\tstore.onStateChange,\n\t\tstateGetter,\n\t);\n};\n","export const includesAny = <T>(array: T[], values: T[]): boolean => {\n\treturn values.some((value) => array.includes(value));\n};\n"],"names":["ScrollToTop","location","useLocation","useLayoutEffect","useLocalStorageStateDeserializer","key","useCallback","error","useLocalStorageStateSerializer","state","useLocalStorageStateHandler","stateValidator","stateSetter","onStateChange","stateGetter","deserializer","serializer","useStateHandler","useLocalStorageStateSetter","store","useLocalStorageStateGetter","useLocalStorageState","includesAny","array","values","value"],"mappings":";;;AAGO,MAAMA,IAAc,MAAY;AACtC,QAAMC,IAAWC,EAAA;AAEjB,SAAAC,EAAgB,MAAM;AACrB,WAAO,SAAS,GAAG,CAAC;AAAA,EACrB,GAAG,CAACF,CAAQ,CAAC,GAEN;AACR,GCLMG,IAAmC,CAACC,MAClCC,EAAY,MAAW;AAC7B,MAAI;AACH,WAAO,KAAK;AAAA,MACX,OAAO,aAAa,QAAQD,CAAG,KAAK,KAAK,UAAU,CAAA,CAAE;AAAA,IAAA;AAAA,EAEvD,SAASE,GAAO;AACf,mBAAQ,MAAMA,CAAK,GACZ,CAAA;AAAA,EACR;AACD,GAAG,CAACF,CAAG,CAAC,GAGHG,IAAiC,CACtCH,MAEOC;AAAA,EACN,CAACG,MAAwB;AACxB,WAAO,aAAa,QAAQJ,GAAK,KAAK,UAAUI,CAAK,CAAC;AAAA,EACvD;AAAA,EACA,CAACJ,CAAG;AAAA,GAIAK,IAA8B,CACnCL,GACAM,GACAC,GACAC,GACAC,MACU;AACV,QAAMC,IAAeX,EAAiCC,CAAG,GACnDW,IAAaR,EAA+BH,CAAG;AACrD,EAAAY;AAAA,IACCF;AAAA,IACAJ;AAAA,IACAC;AAAA,IACAC;AAAA,IACAC;AAAA,IACAE;AAAA,EAAA;AAEF,GAEME,IAA6B,CAClCC,MAEOb;AAAA,EACN,CAACG,MAAwB;AACxB,IAAAU,EAAM,QAAQV;AAAA,EACf;AAAA,EACA,CAACU,CAAK;AAAA,GAIFC,IAA6B,CAClCD,MAEOb,EAAY,MAAca,EAAM,OAAO,CAACA,CAAK,CAAC,GAGzCE,IAAuB,CACnChB,GACAc,MACU;AACV,QAAMP,IAAcM,EAA2BC,CAAK,GAC9CL,IAAcM,EAA2BD,CAAK;AACpD,EAAAT;AAAA,IACCL;AAAA,IACAc,EAAM;AAAA,IACNP;AAAA,IACAO,EAAM;AAAA,IACNL;AAAA,EAAA;AAEF,GC/EaQ,IAAc,CAAIC,GAAYC,MACnCA,EAAO,KAAK,CAACC,MAAUF,EAAM,SAASE,CAAK,CAAC;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IStateStore } from '../stores/IStateStore';
|
|
2
2
|
/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */
|
|
3
|
-
export declare const useLocationState: <TState>(store:
|
|
3
|
+
export declare const useLocationState: <TState>(store: IStateStore<TState>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-router.cjs.js","sources":["../src/react-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type {
|
|
1
|
+
{"version":3,"file":"react-router.cjs.js","sources":["../src/react-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport type { StateChangeEvent } from '@/stores/StateChangeEvent';\nimport { type ParsedQs, parse, stringify } from 'qs';\nimport { useCallback } from 'react';\nimport { useLocation, useNavigate } from 'react-router-dom';\n\nconst useLocationStateDeserializer = (): (() => ParsedQs) => {\n\tconst location = useLocation();\n\n\t// Pass `location` as deps instead of `location.search`.\n\treturn useCallback(\n\t\t(): ParsedQs => parse(location.search.slice(1)),\n\t\t[location],\n\t);\n};\n\nconst useLocationStateSerializer = <TState,>(): ((state: TState) => void) => {\n\tconst navigate = useNavigate();\n\n\treturn useCallback(\n\t\tasync (state: TState): Promise<void> => {\n\t\t\tconst newUrl = `?${stringify(state)}`;\n\t\t\tawait navigate(newUrl);\n\t\t},\n\t\t[navigate],\n\t);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tstateValidator: (state: any) => state is TState,\n\tstateSetter: (state: TState) => void,\n\tonStateChange: ((event: StateChangeEvent<TState>) => void) | undefined,\n\tstateGetter: () => TState,\n): void => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tuseStateHandler(\n\t\tdeserializer,\n\t\tstateValidator,\n\t\tstateSetter,\n\t\tonStateChange,\n\t\tstateGetter,\n\t\tserializer,\n\t);\n};\n\nconst useLocationStateSetter = <TState,>(\n\tstore: IStateStore<TState>,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState): void => {\n\t\t\tstore.state = state;\n\t\t},\n\t\t[store],\n\t);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback((): TState => store.state, [store]);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nexport const useLocationState = <TState,>(store: IStateStore<TState>): void => {\n\tconst stateSetter = useLocationStateSetter(store);\n\tconst stateGetter = useLocationStateGetter(store);\n\tuseLocationStateHandler(\n\t\tstore.validateState,\n\t\tstateSetter,\n\t\tstore.onStateChange,\n\t\tstateGetter,\n\t);\n};\n"],"names":["useLocationStateDeserializer","location","useLocation","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","state","newUrl","stringify","useLocationStateHandler","stateValidator","stateSetter","onStateChange","stateGetter","deserializer","serializer","useStateHandler","useLocationStateSetter","store","useLocationStateGetter","useLocationState"],"mappings":"mMAOMA,EAA+B,IAAwB,CAC5D,MAAMC,EAAWC,EAAAA,YAAA,EAGjB,OAAOC,EAAAA,YACN,IAAgBC,EAAAA,MAAMH,EAAS,OAAO,MAAM,CAAC,CAAC,EAC9C,CAACA,CAAQ,CAAA,CAEX,EAEMI,EAA6B,IAA0C,CAC5E,MAAMC,EAAWC,EAAAA,YAAA,EAEjB,OAAOJ,EAAAA,YACN,MAAOK,GAAiC,CACvC,MAAMC,EAAS,IAAIC,EAAAA,UAAUF,CAAK,CAAC,GACnC,MAAMF,EAASG,CAAM,CACtB,EACA,CAACH,CAAQ,CAAA,CAEX,EAGMK,EAA0B,CAC/BC,EACAC,EACAC,EACAC,IACU,CACV,MAAMC,EAAehB,EAAA,EACfiB,EAAaZ,EAAA,EACnBa,EAAAA,gBACCF,EACAJ,EACAC,EACAC,EACAC,EACAE,CAAA,CAEF,EAEME,EACLC,GAEOjB,EAAAA,YACLK,GAAwB,CACxBY,EAAM,MAAQZ,CACf,EACA,CAACY,CAAK,CAAA,EAIFC,EACLD,GAEOjB,EAAAA,YAAY,IAAciB,EAAM,MAAO,CAACA,CAAK,CAAC,EAIzCE,EAA6BF,GAAqC,CAC9E,MAAMP,EAAcM,EAAuBC,CAAK,EAC1CL,EAAcM,EAAuBD,CAAK,EAChDT,EACCS,EAAM,cACNP,EACAO,EAAM,cACNL,CAAA,CAEF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-router.es.js","sources":["../src/react-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type {
|
|
1
|
+
{"version":3,"file":"react-router.es.js","sources":["../src/react-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport type { StateChangeEvent } from '@/stores/StateChangeEvent';\nimport { type ParsedQs, parse, stringify } from 'qs';\nimport { useCallback } from 'react';\nimport { useLocation, useNavigate } from 'react-router-dom';\n\nconst useLocationStateDeserializer = (): (() => ParsedQs) => {\n\tconst location = useLocation();\n\n\t// Pass `location` as deps instead of `location.search`.\n\treturn useCallback(\n\t\t(): ParsedQs => parse(location.search.slice(1)),\n\t\t[location],\n\t);\n};\n\nconst useLocationStateSerializer = <TState,>(): ((state: TState) => void) => {\n\tconst navigate = useNavigate();\n\n\treturn useCallback(\n\t\tasync (state: TState): Promise<void> => {\n\t\t\tconst newUrl = `?${stringify(state)}`;\n\t\t\tawait navigate(newUrl);\n\t\t},\n\t\t[navigate],\n\t);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tstateValidator: (state: any) => state is TState,\n\tstateSetter: (state: TState) => void,\n\tonStateChange: ((event: StateChangeEvent<TState>) => void) | undefined,\n\tstateGetter: () => TState,\n): void => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tuseStateHandler(\n\t\tdeserializer,\n\t\tstateValidator,\n\t\tstateSetter,\n\t\tonStateChange,\n\t\tstateGetter,\n\t\tserializer,\n\t);\n};\n\nconst useLocationStateSetter = <TState,>(\n\tstore: IStateStore<TState>,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState): void => {\n\t\t\tstore.state = state;\n\t\t},\n\t\t[store],\n\t);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback((): TState => store.state, [store]);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nexport const useLocationState = <TState,>(store: IStateStore<TState>): void => {\n\tconst stateSetter = useLocationStateSetter(store);\n\tconst stateGetter = useLocationStateGetter(store);\n\tuseLocationStateHandler(\n\t\tstore.validateState,\n\t\tstateSetter,\n\t\tstore.onStateChange,\n\t\tstateGetter,\n\t);\n};\n"],"names":["useLocationStateDeserializer","location","useLocation","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","state","newUrl","stringify","useLocationStateHandler","stateValidator","stateSetter","onStateChange","stateGetter","deserializer","serializer","useStateHandler","useLocationStateSetter","store","useLocationStateGetter","useLocationState"],"mappings":";;;;AAOA,MAAMA,IAA+B,MAAwB;AAC5D,QAAMC,IAAWC,EAAA;AAGjB,SAAOC;AAAA,IACN,MAAgBC,EAAMH,EAAS,OAAO,MAAM,CAAC,CAAC;AAAA,IAC9C,CAACA,CAAQ;AAAA,EAAA;AAEX,GAEMI,IAA6B,MAA0C;AAC5E,QAAMC,IAAWC,EAAA;AAEjB,SAAOJ;AAAA,IACN,OAAOK,MAAiC;AACvC,YAAMC,IAAS,IAAIC,EAAUF,CAAK,CAAC;AACnC,YAAMF,EAASG,CAAM;AAAA,IACtB;AAAA,IACA,CAACH,CAAQ;AAAA,EAAA;AAEX,GAGMK,IAA0B,CAC/BC,GACAC,GACAC,GACAC,MACU;AACV,QAAMC,IAAehB,EAAA,GACfiB,IAAaZ,EAAA;AACnB,EAAAa;AAAA,IACCF;AAAA,IACAJ;AAAA,IACAC;AAAA,IACAC;AAAA,IACAC;AAAA,IACAE;AAAA,EAAA;AAEF,GAEME,IAAyB,CAC9BC,MAEOjB;AAAA,EACN,CAACK,MAAwB;AACxB,IAAAY,EAAM,QAAQZ;AAAA,EACf;AAAA,EACA,CAACY,CAAK;AAAA,GAIFC,IAAyB,CAC9BD,MAEOjB,EAAY,MAAciB,EAAM,OAAO,CAACA,CAAK,CAAC,GAIzCE,IAAmB,CAAUF,MAAqC;AAC9E,QAAMP,IAAcM,EAAuBC,CAAK,GAC1CL,IAAcM,EAAuBD,CAAK;AAChD,EAAAT;AAAA,IACCS,EAAM;AAAA,IACNP;AAAA,IACAO,EAAM;AAAA,IACNL;AAAA,EAAA;AAEF;"}
|
package/dist/stores/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './IStateStore';
|
|
2
2
|
export * from './StateChangeEvent';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IStateStore } from '../stores/IStateStore';
|
|
2
2
|
/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */
|
|
3
|
-
export declare const useLocationState: <TState>(store:
|
|
3
|
+
export declare const useLocationState: <TState>(store: IStateStore<TState>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-router.cjs.js","sources":["../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type {
|
|
1
|
+
{"version":3,"file":"tanstack-router.cjs.js","sources":["../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport type { StateChangeEvent } from '@/stores/StateChangeEvent';\nimport { useLocation, useNavigate } from '@tanstack/react-router';\nimport { type ParsedQs, parse } from 'qs';\nimport { useCallback } from 'react';\n\nconst useLocationStateDeserializer = (): (() => ParsedQs) => {\n\tconst location = useLocation();\n\n\t// Pass `location` as deps instead of `location.search`.\n\treturn useCallback(\n\t\t(): ParsedQs => parse(location.searchStr.slice(1)),\n\t\t[location],\n\t);\n};\n\nconst useLocationStateSerializer = <TState,>(): ((state: TState) => void) => {\n\tconst navigate = useNavigate();\n\n\treturn useCallback(\n\t\tasync (state: TState): Promise<void> => {\n\t\t\tawait navigate({ search: state as any /* FIXME */ });\n\t\t},\n\t\t[navigate],\n\t);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tstateValidator: (state: any) => state is TState,\n\tstateSetter: (state: TState) => void,\n\tonStateChange: ((event: StateChangeEvent<TState>) => void) | undefined,\n\tstateGetter: () => TState,\n): void => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tuseStateHandler(\n\t\tdeserializer,\n\t\tstateValidator,\n\t\tstateSetter,\n\t\tonStateChange,\n\t\tstateGetter,\n\t\tserializer,\n\t);\n};\n\nconst useLocationStateSetter = <TState,>(\n\tstore: IStateStore<TState>,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState) => {\n\t\t\tstore.state = state;\n\t\t},\n\t\t[store],\n\t);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback(() => store.state, [store]);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nexport const useLocationState = <TState,>(store: IStateStore<TState>): void => {\n\tconst stateSetter = useLocationStateSetter(store);\n\tconst stateGetter = useLocationStateGetter(store);\n\tuseLocationStateHandler(\n\t\tstore.validateState,\n\t\tstateSetter,\n\t\tstore.onStateChange,\n\t\tstateGetter,\n\t);\n};\n"],"names":["useLocationStateDeserializer","location","useLocation","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","state","useLocationStateHandler","stateValidator","stateSetter","onStateChange","stateGetter","deserializer","serializer","useStateHandler","useLocationStateSetter","store","useLocationStateGetter","useLocationState"],"mappings":"yMAOMA,EAA+B,IAAwB,CAC5D,MAAMC,EAAWC,EAAAA,YAAA,EAGjB,OAAOC,EAAAA,YACN,IAAgBC,EAAAA,MAAMH,EAAS,UAAU,MAAM,CAAC,CAAC,EACjD,CAACA,CAAQ,CAAA,CAEX,EAEMI,EAA6B,IAA0C,CAC5E,MAAMC,EAAWC,EAAAA,YAAA,EAEjB,OAAOJ,EAAAA,YACN,MAAOK,GAAiC,CACvC,MAAMF,EAAS,CAAE,OAAQE,CAAA,CAA0B,CACpD,EACA,CAACF,CAAQ,CAAA,CAEX,EAGMG,EAA0B,CAC/BC,EACAC,EACAC,EACAC,IACU,CACV,MAAMC,EAAed,EAAA,EACfe,EAAaV,EAAA,EACnBW,EAAAA,gBACCF,EACAJ,EACAC,EACAC,EACAC,EACAE,CAAA,CAEF,EAEME,EACLC,GAEOf,EAAAA,YACLK,GAAkB,CAClBU,EAAM,MAAQV,CACf,EACA,CAACU,CAAK,CAAA,EAIFC,EACLD,GAEOf,EAAAA,YAAY,IAAMe,EAAM,MAAO,CAACA,CAAK,CAAC,EAIjCE,EAA6BF,GAAqC,CAC9E,MAAMP,EAAcM,EAAuBC,CAAK,EAC1CL,EAAcM,EAAuBD,CAAK,EAChDT,EACCS,EAAM,cACNP,EACAO,EAAM,cACNL,CAAA,CAEF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tanstack-router.es.js","sources":["../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type {
|
|
1
|
+
{"version":3,"file":"tanstack-router.es.js","sources":["../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["import { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport type { StateChangeEvent } from '@/stores/StateChangeEvent';\nimport { useLocation, useNavigate } from '@tanstack/react-router';\nimport { type ParsedQs, parse } from 'qs';\nimport { useCallback } from 'react';\n\nconst useLocationStateDeserializer = (): (() => ParsedQs) => {\n\tconst location = useLocation();\n\n\t// Pass `location` as deps instead of `location.search`.\n\treturn useCallback(\n\t\t(): ParsedQs => parse(location.searchStr.slice(1)),\n\t\t[location],\n\t);\n};\n\nconst useLocationStateSerializer = <TState,>(): ((state: TState) => void) => {\n\tconst navigate = useNavigate();\n\n\treturn useCallback(\n\t\tasync (state: TState): Promise<void> => {\n\t\t\tawait navigate({ search: state as any /* FIXME */ });\n\t\t},\n\t\t[navigate],\n\t);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tstateValidator: (state: any) => state is TState,\n\tstateSetter: (state: TState) => void,\n\tonStateChange: ((event: StateChangeEvent<TState>) => void) | undefined,\n\tstateGetter: () => TState,\n): void => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tuseStateHandler(\n\t\tdeserializer,\n\t\tstateValidator,\n\t\tstateSetter,\n\t\tonStateChange,\n\t\tstateGetter,\n\t\tserializer,\n\t);\n};\n\nconst useLocationStateSetter = <TState,>(\n\tstore: IStateStore<TState>,\n): ((state: TState) => void) => {\n\treturn useCallback(\n\t\t(state: TState) => {\n\t\t\tstore.state = state;\n\t\t},\n\t\t[store],\n\t);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback(() => store.state, [store]);\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nexport const useLocationState = <TState,>(store: IStateStore<TState>): void => {\n\tconst stateSetter = useLocationStateSetter(store);\n\tconst stateGetter = useLocationStateGetter(store);\n\tuseLocationStateHandler(\n\t\tstore.validateState,\n\t\tstateSetter,\n\t\tstore.onStateChange,\n\t\tstateGetter,\n\t);\n};\n"],"names":["useLocationStateDeserializer","location","useLocation","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","state","useLocationStateHandler","stateValidator","stateSetter","onStateChange","stateGetter","deserializer","serializer","useStateHandler","useLocationStateSetter","store","useLocationStateGetter","useLocationState"],"mappings":";;;;AAOA,MAAMA,IAA+B,MAAwB;AAC5D,QAAMC,IAAWC,EAAA;AAGjB,SAAOC;AAAA,IACN,MAAgBC,EAAMH,EAAS,UAAU,MAAM,CAAC,CAAC;AAAA,IACjD,CAACA,CAAQ;AAAA,EAAA;AAEX,GAEMI,IAA6B,MAA0C;AAC5E,QAAMC,IAAWC,EAAA;AAEjB,SAAOJ;AAAA,IACN,OAAOK,MAAiC;AACvC,YAAMF,EAAS;AAAA,QAAE,QAAQE;AAAA;AAAA,MAAA,CAA0B;AAAA,IACpD;AAAA,IACA,CAACF,CAAQ;AAAA,EAAA;AAEX,GAGMG,IAA0B,CAC/BC,GACAC,GACAC,GACAC,MACU;AACV,QAAMC,IAAed,EAAA,GACfe,IAAaV,EAAA;AACnB,EAAAW;AAAA,IACCF;AAAA,IACAJ;AAAA,IACAC;AAAA,IACAC;AAAA,IACAC;AAAA,IACAE;AAAA,EAAA;AAEF,GAEME,IAAyB,CAC9BC,MAEOf;AAAA,EACN,CAACK,MAAkB;AAClB,IAAAU,EAAM,QAAQV;AAAA,EACf;AAAA,EACA,CAACU,CAAK;AAAA,GAIFC,IAAyB,CAC9BD,MAEOf,EAAY,MAAMe,EAAM,OAAO,CAACA,CAAK,CAAC,GAIjCE,IAAmB,CAAUF,MAAqC;AAC9E,QAAMP,IAAcM,EAAuBC,CAAK,GAC1CL,IAAcM,EAAuBD,CAAK;AAChD,EAAAT;AAAA,IACCS,EAAM;AAAA,IACNP;AAAA,IACAO,EAAM;AAAA,IACNL;AAAA,EAAA;AAEF;"}
|