@aigamo/route-sphere 2.2.4 → 2.2.6-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export declare const useStableLocation: () => {
2
+ location: string;
3
+ };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./useStateHandler-Ff_CnvN8.cjs"),c=require("@tanstack/react-router"),r=require("qs"),o=require("react"),i=()=>{const e=c.useLocation();return o.useCallback(()=>r.parse(e.searchStr.slice(1)),[e])},u=()=>{const e=c.useNavigate();return o.useCallback(async t=>{await e({search:t})},[e])},S=()=>{const e=i(),t=u();return o.useMemo(()=>({deserialize:e,serialize:t}),[e,t])},l=(e,t,a)=>{const s=S();n.useStateHandler(s,e,t,a)},d=e=>o.useCallback(()=>e.state,[e]),L=e=>o.useCallback(t=>{e.state=t},[e]),g=e=>{const t=d(e),a=L(e);return o.useMemo(()=>({get:t,set:a}),[t,a])},C=e=>{const t=g(e),a=o.useMemo(()=>({onStateRestore:e.onStateRestore,onStateChange:e.onStateChange,onStateSave:e.onStateSave}),[e]);l(e.validateState,t,a)};exports.useLocationState=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./useStateHandler-Ff_CnvN8.cjs"),c=require("@tanstack/react-router"),a=require("react"),r=require("qs"),i=()=>{const{isLoading:e,resolvedLocation:t,location:o}=c.useRouterState({select:n=>({isLoading:n.isLoading,resolvedLocation:n.resolvedLocation?.pathname,location:n.location.pathname})});return a.useMemo(()=>({location:e?t??o:o}),[e,t,o])},u=()=>{const{location:e}=i();return a.useCallback(()=>r.parse(e.slice(1)),[e])},l=()=>{const e=c.useNavigate();return a.useCallback(async t=>{await e({search:t})},[e])},S=()=>{const e=u(),t=l();return a.useMemo(()=>({deserialize:e,serialize:t}),[e,t])},d=(e,t,o)=>{const n=S();s.useStateHandler(n,e,t,o)},L=e=>a.useCallback(()=>e.state,[e]),g=e=>a.useCallback(t=>{e.state=t},[e]),v=e=>{const t=L(e),o=g(e);return a.useMemo(()=>({get:t,set:o}),[t,o])},b=e=>{const t=v(e),o=a.useMemo(()=>({onStateRestore:e.onStateRestore,onStateChange:e.onStateChange,onStateSave:e.onStateSave}),[e]);d(e.validateState,t,o)};exports.useLocationState=b;
2
2
  //# sourceMappingURL=tanstack-router.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tanstack-router.cjs.js","sources":["../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["import type { IStateAccessor } from '@/components/IStateAccessor';\nimport type { IStateCodec } from '@/components/IStateCodec';\nimport type { IStateHandlerOptions } from '@/components/IStateHandlerOptions';\nimport { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport { useLocation, useNavigate } from '@tanstack/react-router';\nimport { type ParsedQs, parse } from 'qs';\nimport { useCallback, useMemo } 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\nconst useLocationStateCodec = <TState,>(): IStateCodec<TState> => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tconst codec = useMemo(\n\t\t(): IStateCodec<TState> => ({\n\t\t\tdeserialize: deserializer,\n\t\t\tserialize: serializer,\n\t\t}),\n\t\t[deserializer, serializer],\n\t);\n\treturn codec;\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tvalidator: (state: unknown) => state is TState,\n\taccessor: IStateAccessor<TState>,\n\toptions: IStateHandlerOptions<TState>,\n): void => {\n\tconst codec = useLocationStateCodec();\n\tuseStateHandler(codec, validator, accessor, options);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback(() => store.state, [store]);\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 useLocationStateAccessor = <TState,>(\n\tstore: IStateStore<TState>,\n): IStateAccessor<TState> => {\n\tconst getter = useLocationStateGetter(store);\n\tconst setter = useLocationStateSetter(store);\n\tconst accessor = useMemo(\n\t\t(): IStateAccessor<TState> => ({ get: getter, set: setter }),\n\t\t[getter, setter],\n\t);\n\treturn accessor;\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 accessor = useLocationStateAccessor(store);\n\tconst options = useMemo(\n\t\t() => ({\n\t\t\tonStateRestore: store.onStateRestore,\n\t\t\tonStateChange: store.onStateChange,\n\t\t\tonStateSave: store.onStateSave,\n\t\t}),\n\t\t[store],\n\t);\n\tuseLocationStateHandler(store.validateState, accessor, options);\n};\n"],"names":["useLocationStateDeserializer","location","useLocation","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","state","useLocationStateCodec","deserializer","serializer","useMemo","useLocationStateHandler","validator","accessor","options","codec","useStateHandler","useLocationStateGetter","store","useLocationStateSetter","useLocationStateAccessor","getter","setter","useLocationState"],"mappings":"yMASMA,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,EAEMG,EAAwB,IAAoC,CACjE,MAAMC,EAAeV,EAAA,EACfW,EAAaN,EAAA,EAQnB,OAPcO,EAAAA,QACb,KAA4B,CAC3B,YAAaF,EACb,UAAWC,CAAA,GAEZ,CAACD,EAAcC,CAAU,CAAA,CAG3B,EAGME,EAA0B,CAC/BC,EACAC,EACAC,IACU,CACV,MAAMC,EAAQR,EAAA,EACdS,EAAAA,gBAAgBD,EAAOH,EAAWC,EAAUC,CAAO,CACpD,EAEMG,EACLC,GAEOjB,EAAAA,YAAY,IAAMiB,EAAM,MAAO,CAACA,CAAK,CAAC,EAGxCC,EACLD,GAEOjB,EAAAA,YACLK,GAAkB,CAClBY,EAAM,MAAQZ,CACf,EACA,CAACY,CAAK,CAAA,EAIFE,EACLF,GAC4B,CAC5B,MAAMG,EAASJ,EAAuBC,CAAK,EACrCI,EAASH,EAAuBD,CAAK,EAK3C,OAJiBR,EAAAA,QAChB,KAA+B,CAAE,IAAKW,EAAQ,IAAKC,CAAA,GACnD,CAACD,EAAQC,CAAM,CAAA,CAGjB,EAGaC,EAA6BL,GAAqC,CAC9E,MAAML,EAAWO,EAAyBF,CAAK,EACzCJ,EAAUJ,EAAAA,QACf,KAAO,CACN,eAAgBQ,EAAM,eACtB,cAAeA,EAAM,cACrB,YAAaA,EAAM,WAAA,GAEpB,CAACA,CAAK,CAAA,EAEPP,EAAwBO,EAAM,cAAeL,EAAUC,CAAO,CAC/D"}
1
+ {"version":3,"file":"tanstack-router.cjs.js","sources":["../src/tanstack-router/useStableLocation.tsx","../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["// https://github.com/TanStack/router/issues/3110#issuecomment-3958146041\nimport { useRouterState } from '@tanstack/react-router';\nimport { useMemo } from 'react';\n\nexport const useStableLocation = (): { location: string } => {\n\tconst { isLoading, resolvedLocation, location } = useRouterState({\n\t\tselect: (state) => ({\n\t\t\tisLoading: state.isLoading,\n\t\t\tresolvedLocation: state.resolvedLocation?.pathname,\n\t\t\tlocation: state.location.pathname,\n\t\t}),\n\t});\n\n\treturn useMemo(() => {\n\t\tconst currentLocation = isLoading\n\t\t\t? (resolvedLocation ?? location)\n\t\t\t: location;\n\n\t\treturn {\n\t\t\tlocation: currentLocation,\n\t\t};\n\t}, [isLoading, resolvedLocation, location]);\n};\n","import type { IStateAccessor } from '@/components/IStateAccessor';\nimport type { IStateCodec } from '@/components/IStateCodec';\nimport type { IStateHandlerOptions } from '@/components/IStateHandlerOptions';\nimport { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport { useStableLocation } from '@/tanstack-router/useStableLocation';\nimport { useNavigate } from '@tanstack/react-router';\nimport { type ParsedQs, parse } from 'qs';\nimport { useCallback, useMemo } from 'react';\n\nconst useLocationStateDeserializer = (): (() => ParsedQs) => {\n\tconst { location } = useStableLocation();\n\n\t// Pass `location` as deps instead of `location.search`.\n\treturn useCallback((): ParsedQs => parse(location.slice(1)), [location]);\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\nconst useLocationStateCodec = <TState,>(): IStateCodec<TState> => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tconst codec = useMemo(\n\t\t(): IStateCodec<TState> => ({\n\t\t\tdeserialize: deserializer,\n\t\t\tserialize: serializer,\n\t\t}),\n\t\t[deserializer, serializer],\n\t);\n\treturn codec;\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tvalidator: (state: unknown) => state is TState,\n\taccessor: IStateAccessor<TState>,\n\toptions: IStateHandlerOptions<TState>,\n): void => {\n\tconst codec = useLocationStateCodec();\n\tuseStateHandler(codec, validator, accessor, options);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback(() => store.state, [store]);\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 useLocationStateAccessor = <TState,>(\n\tstore: IStateStore<TState>,\n): IStateAccessor<TState> => {\n\tconst getter = useLocationStateGetter(store);\n\tconst setter = useLocationStateSetter(store);\n\tconst accessor = useMemo(\n\t\t(): IStateAccessor<TState> => ({ get: getter, set: setter }),\n\t\t[getter, setter],\n\t);\n\treturn accessor;\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 accessor = useLocationStateAccessor(store);\n\tconst options = useMemo(\n\t\t() => ({\n\t\t\tonStateRestore: store.onStateRestore,\n\t\t\tonStateChange: store.onStateChange,\n\t\t\tonStateSave: store.onStateSave,\n\t\t}),\n\t\t[store],\n\t);\n\tuseLocationStateHandler(store.validateState, accessor, options);\n};\n"],"names":["useStableLocation","isLoading","resolvedLocation","location","useRouterState","state","useMemo","useLocationStateDeserializer","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","useLocationStateCodec","deserializer","serializer","useLocationStateHandler","validator","accessor","options","codec","useStateHandler","useLocationStateGetter","store","useLocationStateSetter","useLocationStateAccessor","getter","setter","useLocationState"],"mappings":"yMAIaA,EAAoB,IAA4B,CAC5D,KAAM,CAAE,UAAAC,EAAW,iBAAAC,EAAkB,SAAAC,CAAA,EAAaC,EAAAA,eAAe,CAChE,OAASC,IAAW,CACnB,UAAWA,EAAM,UACjB,iBAAkBA,EAAM,kBAAkB,SAC1C,SAAUA,EAAM,SAAS,QAAA,EAC1B,CACA,EAED,OAAOC,EAAAA,QAAQ,KAKP,CACN,SALuBL,EACpBC,GAAoBC,EACrBA,CAGQ,GAET,CAACF,EAAWC,EAAkBC,CAAQ,CAAC,CAC3C,ECZMI,EAA+B,IAAwB,CAC5D,KAAM,CAAE,SAAAJ,CAAA,EAAaH,EAAA,EAGrB,OAAOQ,EAAAA,YAAY,IAAgBC,EAAAA,MAAMN,EAAS,MAAM,CAAC,CAAC,EAAG,CAACA,CAAQ,CAAC,CACxE,EAEMO,EAA6B,IAA0C,CAC5E,MAAMC,EAAWC,EAAAA,YAAA,EAEjB,OAAOJ,EAAAA,YACN,MAAOH,GAAiC,CACvC,MAAMM,EAAS,CAAE,OAAQN,CAAA,CAA0B,CACpD,EACA,CAACM,CAAQ,CAAA,CAEX,EAEME,EAAwB,IAAoC,CACjE,MAAMC,EAAeP,EAAA,EACfQ,EAAaL,EAAA,EAQnB,OAPcJ,EAAAA,QACb,KAA4B,CAC3B,YAAaQ,EACb,UAAWC,CAAA,GAEZ,CAACD,EAAcC,CAAU,CAAA,CAG3B,EAGMC,EAA0B,CAC/BC,EACAC,EACAC,IACU,CACV,MAAMC,EAAQP,EAAA,EACdQ,EAAAA,gBAAgBD,EAAOH,EAAWC,EAAUC,CAAO,CACpD,EAEMG,EACLC,GAEOf,EAAAA,YAAY,IAAMe,EAAM,MAAO,CAACA,CAAK,CAAC,EAGxCC,EACLD,GAEOf,EAAAA,YACLH,GAAkB,CAClBkB,EAAM,MAAQlB,CACf,EACA,CAACkB,CAAK,CAAA,EAIFE,EACLF,GAC4B,CAC5B,MAAMG,EAASJ,EAAuBC,CAAK,EACrCI,EAASH,EAAuBD,CAAK,EAK3C,OAJiBjB,EAAAA,QAChB,KAA+B,CAAE,IAAKoB,EAAQ,IAAKC,CAAA,GACnD,CAACD,EAAQC,CAAM,CAAA,CAGjB,EAGaC,EAA6BL,GAAqC,CAC9E,MAAML,EAAWO,EAAyBF,CAAK,EACzCJ,EAAUb,EAAAA,QACf,KAAO,CACN,eAAgBiB,EAAM,eACtB,cAAeA,EAAM,cACrB,YAAaA,EAAM,WAAA,GAEpB,CAACA,CAAK,CAAA,EAEPP,EAAwBO,EAAM,cAAeL,EAAUC,CAAO,CAC/D"}
@@ -1,16 +1,24 @@
1
- import { u as n } from "./useStateHandler-Dbkejxjm.js";
2
- import { useLocation as r, useNavigate as i } from "@tanstack/react-router";
3
- import { parse as S } from "qs";
4
- import { useMemo as s, useCallback as a } from "react";
5
- const u = () => {
6
- const t = r();
7
- return a(
8
- () => S(t.searchStr.slice(1)),
9
- [t]
10
- );
11
- }, l = () => {
1
+ import { u as s } from "./useStateHandler-Dbkejxjm.js";
2
+ import { useRouterState as r, useNavigate as i } from "@tanstack/react-router";
3
+ import { useMemo as n, useCallback as c } from "react";
4
+ import { parse as u } from "qs";
5
+ const l = () => {
6
+ const { isLoading: t, resolvedLocation: e, location: o } = r({
7
+ select: (a) => ({
8
+ isLoading: a.isLoading,
9
+ resolvedLocation: a.resolvedLocation?.pathname,
10
+ location: a.location.pathname
11
+ })
12
+ });
13
+ return n(() => ({
14
+ location: t ? e ?? o : o
15
+ }), [t, e, o]);
16
+ }, S = () => {
17
+ const { location: t } = l();
18
+ return c(() => u(t.slice(1)), [t]);
19
+ }, L = () => {
12
20
  const t = i();
13
- return a(
21
+ return c(
14
22
  async (e) => {
15
23
  await t({
16
24
  search: e
@@ -20,8 +28,8 @@ const u = () => {
20
28
  [t]
21
29
  );
22
30
  }, d = () => {
23
- const t = u(), e = l();
24
- return s(
31
+ const t = S(), e = L();
32
+ return n(
25
33
  () => ({
26
34
  deserialize: t,
27
35
  serialize: e
@@ -29,21 +37,21 @@ const u = () => {
29
37
  [t, e]
30
38
  );
31
39
  }, m = (t, e, o) => {
32
- const c = d();
33
- n(c, t, e, o);
34
- }, L = (t) => a(() => t.state, [t]), p = (t) => a(
40
+ const a = d();
41
+ s(a, t, e, o);
42
+ }, g = (t) => c(() => t.state, [t]), p = (t) => c(
35
43
  (e) => {
36
44
  t.state = e;
37
45
  },
38
46
  [t]
39
- ), g = (t) => {
40
- const e = L(t), o = p(t);
41
- return s(
47
+ ), v = (t) => {
48
+ const e = g(t), o = p(t);
49
+ return n(
42
50
  () => ({ get: e, set: o }),
43
51
  [e, o]
44
52
  );
45
- }, C = (t) => {
46
- const e = g(t), o = s(
53
+ }, R = (t) => {
54
+ const e = v(t), o = n(
47
55
  () => ({
48
56
  onStateRestore: t.onStateRestore,
49
57
  onStateChange: t.onStateChange,
@@ -54,6 +62,6 @@ const u = () => {
54
62
  m(t.validateState, e, o);
55
63
  };
56
64
  export {
57
- C as useLocationState
65
+ R as useLocationState
58
66
  };
59
67
  //# sourceMappingURL=tanstack-router.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tanstack-router.es.js","sources":["../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["import type { IStateAccessor } from '@/components/IStateAccessor';\nimport type { IStateCodec } from '@/components/IStateCodec';\nimport type { IStateHandlerOptions } from '@/components/IStateHandlerOptions';\nimport { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport { useLocation, useNavigate } from '@tanstack/react-router';\nimport { type ParsedQs, parse } from 'qs';\nimport { useCallback, useMemo } 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\nconst useLocationStateCodec = <TState,>(): IStateCodec<TState> => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tconst codec = useMemo(\n\t\t(): IStateCodec<TState> => ({\n\t\t\tdeserialize: deserializer,\n\t\t\tserialize: serializer,\n\t\t}),\n\t\t[deserializer, serializer],\n\t);\n\treturn codec;\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tvalidator: (state: unknown) => state is TState,\n\taccessor: IStateAccessor<TState>,\n\toptions: IStateHandlerOptions<TState>,\n): void => {\n\tconst codec = useLocationStateCodec();\n\tuseStateHandler(codec, validator, accessor, options);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback(() => store.state, [store]);\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 useLocationStateAccessor = <TState,>(\n\tstore: IStateStore<TState>,\n): IStateAccessor<TState> => {\n\tconst getter = useLocationStateGetter(store);\n\tconst setter = useLocationStateSetter(store);\n\tconst accessor = useMemo(\n\t\t(): IStateAccessor<TState> => ({ get: getter, set: setter }),\n\t\t[getter, setter],\n\t);\n\treturn accessor;\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 accessor = useLocationStateAccessor(store);\n\tconst options = useMemo(\n\t\t() => ({\n\t\t\tonStateRestore: store.onStateRestore,\n\t\t\tonStateChange: store.onStateChange,\n\t\t\tonStateSave: store.onStateSave,\n\t\t}),\n\t\t[store],\n\t);\n\tuseLocationStateHandler(store.validateState, accessor, options);\n};\n"],"names":["useLocationStateDeserializer","location","useLocation","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","state","useLocationStateCodec","deserializer","serializer","useMemo","useLocationStateHandler","validator","accessor","options","codec","useStateHandler","useLocationStateGetter","store","useLocationStateSetter","useLocationStateAccessor","getter","setter","useLocationState"],"mappings":";;;;AASA,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,GAEMG,IAAwB,MAAoC;AACjE,QAAMC,IAAeV,EAAA,GACfW,IAAaN,EAAA;AAQnB,SAPcO;AAAA,IACb,OAA4B;AAAA,MAC3B,aAAaF;AAAA,MACb,WAAWC;AAAA,IAAA;AAAA,IAEZ,CAACD,GAAcC,CAAU;AAAA,EAAA;AAG3B,GAGME,IAA0B,CAC/BC,GACAC,GACAC,MACU;AACV,QAAMC,IAAQR,EAAA;AACd,EAAAS,EAAgBD,GAAOH,GAAWC,GAAUC,CAAO;AACpD,GAEMG,IAAyB,CAC9BC,MAEOjB,EAAY,MAAMiB,EAAM,OAAO,CAACA,CAAK,CAAC,GAGxCC,IAAyB,CAC9BD,MAEOjB;AAAA,EACN,CAACK,MAAkB;AAClB,IAAAY,EAAM,QAAQZ;AAAA,EACf;AAAA,EACA,CAACY,CAAK;AAAA,GAIFE,IAA2B,CAChCF,MAC4B;AAC5B,QAAMG,IAASJ,EAAuBC,CAAK,GACrCI,IAASH,EAAuBD,CAAK;AAK3C,SAJiBR;AAAA,IAChB,OAA+B,EAAE,KAAKW,GAAQ,KAAKC,EAAA;AAAA,IACnD,CAACD,GAAQC,CAAM;AAAA,EAAA;AAGjB,GAGaC,IAAmB,CAAUL,MAAqC;AAC9E,QAAML,IAAWO,EAAyBF,CAAK,GACzCJ,IAAUJ;AAAA,IACf,OAAO;AAAA,MACN,gBAAgBQ,EAAM;AAAA,MACtB,eAAeA,EAAM;AAAA,MACrB,aAAaA,EAAM;AAAA,IAAA;AAAA,IAEpB,CAACA,CAAK;AAAA,EAAA;AAEP,EAAAP,EAAwBO,EAAM,eAAeL,GAAUC,CAAO;AAC/D;"}
1
+ {"version":3,"file":"tanstack-router.es.js","sources":["../src/tanstack-router/useStableLocation.tsx","../src/tanstack-router/useLocationState.tsx"],"sourcesContent":["// https://github.com/TanStack/router/issues/3110#issuecomment-3958146041\nimport { useRouterState } from '@tanstack/react-router';\nimport { useMemo } from 'react';\n\nexport const useStableLocation = (): { location: string } => {\n\tconst { isLoading, resolvedLocation, location } = useRouterState({\n\t\tselect: (state) => ({\n\t\t\tisLoading: state.isLoading,\n\t\t\tresolvedLocation: state.resolvedLocation?.pathname,\n\t\t\tlocation: state.location.pathname,\n\t\t}),\n\t});\n\n\treturn useMemo(() => {\n\t\tconst currentLocation = isLoading\n\t\t\t? (resolvedLocation ?? location)\n\t\t\t: location;\n\n\t\treturn {\n\t\t\tlocation: currentLocation,\n\t\t};\n\t}, [isLoading, resolvedLocation, location]);\n};\n","import type { IStateAccessor } from '@/components/IStateAccessor';\nimport type { IStateCodec } from '@/components/IStateCodec';\nimport type { IStateHandlerOptions } from '@/components/IStateHandlerOptions';\nimport { useStateHandler } from '@/components/useStateHandler';\nimport type { IStateStore } from '@/stores/IStateStore';\nimport { useStableLocation } from '@/tanstack-router/useStableLocation';\nimport { useNavigate } from '@tanstack/react-router';\nimport { type ParsedQs, parse } from 'qs';\nimport { useCallback, useMemo } from 'react';\n\nconst useLocationStateDeserializer = (): (() => ParsedQs) => {\n\tconst { location } = useStableLocation();\n\n\t// Pass `location` as deps instead of `location.search`.\n\treturn useCallback((): ParsedQs => parse(location.slice(1)), [location]);\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\nconst useLocationStateCodec = <TState,>(): IStateCodec<TState> => {\n\tconst deserializer = useLocationStateDeserializer();\n\tconst serializer = useLocationStateSerializer();\n\tconst codec = useMemo(\n\t\t(): IStateCodec<TState> => ({\n\t\t\tdeserialize: deserializer,\n\t\t\tserialize: serializer,\n\t\t}),\n\t\t[deserializer, serializer],\n\t);\n\treturn codec;\n};\n\n/** Updates a store that implements the {@link LocationStateStore} interface when a route changes, and vice versa. */\nconst useLocationStateHandler = <TState,>(\n\tvalidator: (state: unknown) => state is TState,\n\taccessor: IStateAccessor<TState>,\n\toptions: IStateHandlerOptions<TState>,\n): void => {\n\tconst codec = useLocationStateCodec();\n\tuseStateHandler(codec, validator, accessor, options);\n};\n\nconst useLocationStateGetter = <TState,>(\n\tstore: IStateStore<TState>,\n): (() => TState) => {\n\treturn useCallback(() => store.state, [store]);\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 useLocationStateAccessor = <TState,>(\n\tstore: IStateStore<TState>,\n): IStateAccessor<TState> => {\n\tconst getter = useLocationStateGetter(store);\n\tconst setter = useLocationStateSetter(store);\n\tconst accessor = useMemo(\n\t\t(): IStateAccessor<TState> => ({ get: getter, set: setter }),\n\t\t[getter, setter],\n\t);\n\treturn accessor;\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 accessor = useLocationStateAccessor(store);\n\tconst options = useMemo(\n\t\t() => ({\n\t\t\tonStateRestore: store.onStateRestore,\n\t\t\tonStateChange: store.onStateChange,\n\t\t\tonStateSave: store.onStateSave,\n\t\t}),\n\t\t[store],\n\t);\n\tuseLocationStateHandler(store.validateState, accessor, options);\n};\n"],"names":["useStableLocation","isLoading","resolvedLocation","location","useRouterState","state","useMemo","useLocationStateDeserializer","useCallback","parse","useLocationStateSerializer","navigate","useNavigate","useLocationStateCodec","deserializer","serializer","useLocationStateHandler","validator","accessor","options","codec","useStateHandler","useLocationStateGetter","store","useLocationStateSetter","useLocationStateAccessor","getter","setter","useLocationState"],"mappings":";;;;AAIO,MAAMA,IAAoB,MAA4B;AAC5D,QAAM,EAAE,WAAAC,GAAW,kBAAAC,GAAkB,UAAAC,EAAA,IAAaC,EAAe;AAAA,IAChE,QAAQ,CAACC,OAAW;AAAA,MACnB,WAAWA,EAAM;AAAA,MACjB,kBAAkBA,EAAM,kBAAkB;AAAA,MAC1C,UAAUA,EAAM,SAAS;AAAA,IAAA;AAAA,EAC1B,CACA;AAED,SAAOC,EAAQ,OAKP;AAAA,IACN,UALuBL,IACpBC,KAAoBC,IACrBA;AAAA,EAGQ,IAET,CAACF,GAAWC,GAAkBC,CAAQ,CAAC;AAC3C,GCZMI,IAA+B,MAAwB;AAC5D,QAAM,EAAE,UAAAJ,EAAA,IAAaH,EAAA;AAGrB,SAAOQ,EAAY,MAAgBC,EAAMN,EAAS,MAAM,CAAC,CAAC,GAAG,CAACA,CAAQ,CAAC;AACxE,GAEMO,IAA6B,MAA0C;AAC5E,QAAMC,IAAWC,EAAA;AAEjB,SAAOJ;AAAA,IACN,OAAOH,MAAiC;AACvC,YAAMM,EAAS;AAAA,QAAE,QAAQN;AAAA;AAAA,MAAA,CAA0B;AAAA,IACpD;AAAA,IACA,CAACM,CAAQ;AAAA,EAAA;AAEX,GAEME,IAAwB,MAAoC;AACjE,QAAMC,IAAeP,EAAA,GACfQ,IAAaL,EAAA;AAQnB,SAPcJ;AAAA,IACb,OAA4B;AAAA,MAC3B,aAAaQ;AAAA,MACb,WAAWC;AAAA,IAAA;AAAA,IAEZ,CAACD,GAAcC,CAAU;AAAA,EAAA;AAG3B,GAGMC,IAA0B,CAC/BC,GACAC,GACAC,MACU;AACV,QAAMC,IAAQP,EAAA;AACd,EAAAQ,EAAgBD,GAAOH,GAAWC,GAAUC,CAAO;AACpD,GAEMG,IAAyB,CAC9BC,MAEOf,EAAY,MAAMe,EAAM,OAAO,CAACA,CAAK,CAAC,GAGxCC,IAAyB,CAC9BD,MAEOf;AAAA,EACN,CAACH,MAAkB;AAClB,IAAAkB,EAAM,QAAQlB;AAAA,EACf;AAAA,EACA,CAACkB,CAAK;AAAA,GAIFE,IAA2B,CAChCF,MAC4B;AAC5B,QAAMG,IAASJ,EAAuBC,CAAK,GACrCI,IAASH,EAAuBD,CAAK;AAK3C,SAJiBjB;AAAA,IAChB,OAA+B,EAAE,KAAKoB,GAAQ,KAAKC,EAAA;AAAA,IACnD,CAACD,GAAQC,CAAM;AAAA,EAAA;AAGjB,GAGaC,IAAmB,CAAUL,MAAqC;AAC9E,QAAML,IAAWO,EAAyBF,CAAK,GACzCJ,IAAUb;AAAA,IACf,OAAO;AAAA,MACN,gBAAgBiB,EAAM;AAAA,MACtB,eAAeA,EAAM;AAAA,MACrB,aAAaA,EAAM;AAAA,IAAA;AAAA,IAEpB,CAACA,CAAK;AAAA,EAAA;AAEP,EAAAP,EAAwBO,EAAM,eAAeL,GAAUC,CAAO;AAC/D;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigamo/route-sphere",
3
- "version": "2.2.4",
3
+ "version": "2.2.6-0",
4
4
  "type": "module",
5
5
  "dependencies": {},
6
6
  "devDependencies": {