state-in-url 4.1.11 → 4.1.12

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.
@@ -1 +1 @@
1
- import{encode as f,decode as m}from"../encoder/encoder.mjs";import{getParams as c}from"../utils.mjs";function a(r,e,n){const o=c(n);for(const[t,i]of Object.entries(r||{})){const s=e?.[t];JSON.stringify(i)!==JSON.stringify(s)&&o.set(t,f(i))}return o.toString()}function d(r,e){return{...e||{},...Object.fromEntries([...c(r).entries()].map(([n,o])=>{const t=e?.[n];return[n,m(o,t)??t]}))}}export{d as decodeState,a as encodeState};
1
+ import{decode as f,encode as m}from"../encoder/encoder.mjs";import{getParams as c}from"../utils.mjs";function a(r,e,n){const o=c(n);for(const[t,i]of Object.entries(r||{})){const s=e?.[t];JSON.stringify(i)!==JSON.stringify(s)&&o.set(t,m(i))}return o.toString()}function d(r,e){return{...e||{},...Object.fromEntries([...c(r).entries()].map(([n,o])=>{const t=e?.[n];return[n,f(o,t)??t]}))}}export{d as decodeState,a as encodeState};
@@ -1 +1 @@
1
- import r from"react";import{useRouter as C,useSearchParams as H}from"next/navigation";import{parseSPObj as f}from"../../parseSPObj.mjs";import{useUrlStateBase as g}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as d,isSSR as v,filterUnknownParams as P,filterUnknownParamsClient as w}from"../../utils.mjs";function E(t,s){const a="defaultState"in t?t.defaultState:t,U="defaultState"in t?t.searchParams:s?.searchParams,l="defaultState"in t?t.useHistory:s?.useHistory,h="defaultState"in t?{scroll:t.scroll,replace:t.replace}:{scroll:s?.scroll,replace:s?.replace},o=C(),b=r.useMemo(()=>({push:(...e)=>{l===void 0||l?d.push(...e):o.push(...e)},replace:(...e)=>{l===void 0||l?d.replace(...e):o.replace(...e)}}),[o]),{state:c,updateState:u,updateUrl:p,reset:i,getState:k}=g(a,b,({parse:e})=>v?f(P(a,U),a):e(w(a))),n=r.useMemo(()=>({...M,...h}),[]),m=r.useCallback((e,j)=>p(e,{...n,...j}),[p]),S=H();r.useLayoutEffect(()=>{u(P(a,f(Object.fromEntries([...S.entries()]),a)))},[S]);const y=r.useCallback(e=>{i({...n,...e})},[i]);return{setState:u,updateState:u,setUrl:m,updateUrl:m,urlState:c,state:c,reset:y,getState:k}}const M={replace:!0,scroll:!1};export{E as useUrlState};
1
+ import r from"react";import{useRouter as C,useSearchParams as H}from"next/navigation";import{parseSPObj as S}from"../../parseSPObj.mjs";import{useUrlStateBase as g}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as d,filterUnknownParams as P,isSSR as v,filterUnknownParamsClient as w}from"../../utils.mjs";function E(t,s){const a="defaultState"in t?t.defaultState:t,U="defaultState"in t?t.searchParams:s?.searchParams,l="defaultState"in t?t.useHistory:s?.useHistory,h="defaultState"in t?{scroll:t.scroll,replace:t.replace}:{scroll:s?.scroll,replace:s?.replace},u=C(),b=r.useMemo(()=>({push:(...e)=>{l===void 0||l?d.push(...e):u.push(...e)},replace:(...e)=>{l===void 0||l?d.replace(...e):u.replace(...e)}}),[u]),{state:c,updateState:o,updateUrl:p,reset:i,getState:k}=g(a,b,({parse:e})=>v?S(P(a,U),a):e(w(a))),n=r.useMemo(()=>({...M,...h}),[]),m=r.useCallback((e,j)=>p(e,{...n,...j}),[p]),f=H();r.useLayoutEffect(()=>{o(P(a,S(Object.fromEntries([...f.entries()]),a)))},[f]);const y=r.useCallback(e=>{i({...n,...e})},[i]);return{setState:o,updateState:o,setUrl:m,updateUrl:m,urlState:c,state:c,reset:y,getState:k}}const M={replace:!0,scroll:!1};export{E as useUrlState};
@@ -6,6 +6,6 @@ export declare const subscribers: {
6
6
  };
7
7
  export declare const stateMap: {
8
8
  get: <T extends JSONCompatible | undefined>(objKey: T) => T | undefined;
9
- set: <T_1 extends JSONCompatible>(objKey: T_1, value: T_1) => void;
9
+ set: <T extends JSONCompatible>(objKey: T, value: T) => void;
10
10
  };
11
11
  export type Cb = () => void;
@@ -30,7 +30,7 @@ console.log(state); // Output: { name: 'Tom' }
30
30
  *
31
31
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/useUrlEncode#parse}
32
32
  */
33
- parse: (strOrSearchParams: string | URLSearchParams) => T;
33
+ parse: (strOrSearchParams: string | URLSearchParams) => typeof stateShape;
34
34
  /**
35
35
  Converts a state object to a URL query string.
36
36
  * * Example:
@@ -37,7 +37,7 @@ export declare function useUrlStateBase<T extends JSONCompatible>(defaultState:
37
37
  parse: ReturnType<typeof useUrlEncode<T>>["parse"];
38
38
  }) => T): {
39
39
  updateState: (value: Partial<T> | ((currState: T) => T)) => void;
40
- updateUrl: (value?: Partial<T> | ((currState: T) => T) | undefined, options?: Options) => void;
40
+ updateUrl: (value?: Parameters<(value: Partial<T> | ((currState: T) => T)) => void>[0], options?: Options) => void;
41
41
  state: T;
42
42
  reset: (options?: Options) => void;
43
43
  getState: () => T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-in-url",
3
- "version": "4.1.11",
3
+ "version": "4.1.12",
4
4
  "description": "Store state in URL as in object, types and structure are preserved, with TS validation. Same API as React.useState, wthout any hasssle or boilerplate. Next.js@14-15 and react-router@6-7.",
5
5
  "homepage": "https://state-in-url.dev",
6
6
  "repository": {
@@ -353,7 +353,7 @@
353
353
  "@vitest/coverage-istanbul": "^2.1.5",
354
354
  "auto-changelog": "^2.4.0",
355
355
  "babel-plugin-module-resolver": "^5.0.2",
356
- "chokidar": "^4.0.1",
356
+ "chokidar": "^4.0.3",
357
357
  "commitizen": "^4.3.0",
358
358
  "commitlint": "^19.8.0",
359
359
  "conventional-recommended-bump": "^10.0.0",
@@ -376,18 +376,18 @@
376
376
  "prettier": "^3.2.5",
377
377
  "prettier-plugin-tailwindcss": "^0.6.8",
378
378
  "release-it": "^17.6.0",
379
- "rollup": "^4.23.0",
380
- "rollup-plugin-esbuild": "^6.1.1",
379
+ "rollup": "^4.39.0",
380
+ "rollup-plugin-esbuild": "^6.2.1",
381
381
  "rollup-plugin-filesize": "^10.0.0",
382
382
  "rollup-plugin-sourcemaps": "^0.6.3",
383
383
  "semantic-release": "^24.1.0",
384
384
  "standard-version": "^9.5.0",
385
385
  "ts-node": "^10.9.2",
386
- "typescript": "^5.3.3",
386
+ "typescript": "^5.8.2",
387
387
  "unplugin-auto-import": "^0.18.5",
388
388
  "vitest": "^2.1.5",
389
389
  "wait-on": "^8.0.1",
390
- "wireit": "^0.14.9"
390
+ "wireit": "^0.14.11"
391
391
  },
392
392
  "keywords": [
393
393
  "state in url",