state-in-url 4.1.8 → 4.2.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.
@@ -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 l from"react";import{useRouter as C}from"next/navigation";import{parseSPObj as b}from"../../parseSPObj.mjs";import{useUrlStateBase as y}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as S,isSSR as H,filterUnknownParams as g,filterUnknownParamsClient as v}from"../../utils.mjs";function w(t,a){const r="defaultState"in t?t.defaultState:t,f="defaultState"in t?t.searchParams:a?.searchParams,s="defaultState"in t?t.useHistory:a?.useHistory,d="defaultState"in t?{scroll:t.scroll,replace:t.replace}:{scroll:a?.scroll,replace:a?.replace},o=C(),U=l.useMemo(()=>({push:(...e)=>{s===void 0||s?S.push(...e):o.push(...e)},replace:(...e)=>{s===void 0||s?S.replace(...e):o.replace(...e)}}),[o]),{state:u,updateState:p,updateUrl:c,reset:i,getState:h}=y(r,U,({parse:e})=>H?b(g(r,f),r):e(v(r))),m=l.useMemo(()=>({...M,...d}),[]),n=l.useCallback((e,k)=>c(e,{...m,...k}),[c]),P=l.useCallback(e=>{i({...m,...e})},[i]);return{setState:p,updateState:p,setUrl:n,updateUrl:n,urlState:u,state:u,reset:P,getState:h}}const M={replace:!0,scroll:!1};export{w as useUrlState};
@@ -1 +1 @@
1
- import u from"react";import{stateMap as n,subscribers as o}from"../subscribers.mjs";import{useInsertionEffect as g}from"../useInsertionEffect.mjs";import{isSSR as l,isEqual as b}from"../utils.mjs";function d(a,c){const t=u.useRef(a),[f,i]=u.useState(()=>{if(l)return c?c?.():t.current;const e=n.get(t.current);if(e)return e;{const r=c?.()||t.current;return n.set(t.current,r),r}}),m=u.useCallback(e=>{const r=n.get(t.current),s=typeof e=="function"?e(r):{...r,...e};b(r,s)||(n.set(t.current,s),o.get(t.current).forEach(p=>p()))},[]);g(()=>{const e=()=>{i(n.get(t.current)||t.current)},r=o.add(t.current,e);return()=>{r()}},[]);const S=u.useCallback(()=>n.get(t.current)||t.current,[]);return{state:f,getState:S,setState:m}}export{d as useSharedState};
1
+ import u from"react";import{stateMap as n,subscribers as s}from"../subscribers.mjs";import{useInsertionEffect as g}from"../useInsertionEffect.mjs";import{isSSR as l,isEqual as b}from"../utils.mjs";function d(a,c){const t=u.useRef(a),[f,i]=u.useState(()=>{if(l)return c?c?.():t.current;const e=n.get(t.current);if(e)return e;{const r=c?.()||t.current;return n.set(t.current,r),r}}),m=u.useCallback(e=>{const r=n.get(t.current),o=typeof e=="function"?e(r):{...r,...e};b(r,o)||(n.set(t.current,o),s.get(t.current).forEach(p=>p()))},[]);g(()=>{const e=()=>{i(n.get(t.current)||t.current)},r=s.add(t.current,e);return()=>{r()}},[]);const S=u.useCallback(()=>n.get(t.current)||t.current,[]);return{state:f,getState:S,setState:m}}export{d as useSharedState};
@@ -1 +1 @@
1
- import o from"react";import{encodeState as a,decodeState as n}from"../encodeState/encodeState.mjs";import{typeOf as s}from"../utils.mjs";function f(e){const c=o.useCallback((t,r)=>s(t)==="object"?a(t,e,r):"",[e]);return{parse:o.useCallback(t=>n(t,e),[e]),stringify:c}}export{f as useUrlEncode};
1
+ import o from"react";import{encodeState as a,decodeState as n}from"../encodeState/encodeState.mjs";import{typeOf as f}from"../utils.mjs";function i(e){const c=o.useCallback((t,r)=>f(t)==="object"?a(t,e,r):"",[e]);return{parse:o.useCallback(t=>n(t,e),[e]),stringify:c}}export{i as useUrlEncode};
@@ -1 +1 @@
1
- import i from"react";import{TIMEOUT as R}from"../constants/constants.mjs";import{useInsertionEffect as T}from"../useInsertionEffect.mjs";import{useSharedState as v}from"../useSharedState/useSharedState.mjs";import{useUrlEncode as L}from"../useUrlEncode/useUrlEncode.mjs";import{filterUnknownParamsClient as P}from"../utils.mjs";function b(t,o,u){const{parse:a,stringify:n}=L(t),{state:l,getState:r,setState:s}=v(t,()=>u?.({parse:a})||t),m=i.useRef(void 0);T(()=>{const e=()=>{const w=a(P(t));s(w)};return window.addEventListener($,e),()=>{window.removeEventListener($,e),clearTimeout(m.current)}},[s]);const c=i.useRef([]),p=i.useCallback((e,w)=>{const d=typeof e=="function"?e(r()):{...r(),...e},h=n(d,y(t)),S=`${window.location.pathname}${h.length?"?":""}${h}${window.location.hash}`,E=`${window.location.pathname}${window.location.search}${window.location.hash}`;if(S===E)return;s(d);const{replace:g,...k}=w||{};c.current.push([g?"replace":"push",S,k]),clearTimeout(m.current),queueMicrotask(()=>{c.current.length&&(m.current=setTimeout(()=>{const f=c.current.at(-1);c.current=[],o[f[0]](f[1],f[2])},R))})},[o,n,r]),U=i.useCallback(e=>{p(t,e)},[p]);return{updateState:s,updateUrl:p,state:l,reset:U,getState:r}}function y(t){const o=Object.keys(t),u=window.location.search,a=new URLSearchParams(u),n=new URLSearchParams;return a.forEach((l,r)=>!o.includes(r)&&n.set(r,l)),n}const $="popstate";export{b as useUrlStateBase};
1
+ import i from"react";import{TIMEOUT as R}from"../constants/constants.mjs";import{useInsertionEffect as T}from"../useInsertionEffect.mjs";import{useSharedState as v}from"../useSharedState/useSharedState.mjs";import{useUrlEncode as L}from"../useUrlEncode/useUrlEncode.mjs";import{filterUnknownParamsClient as P}from"../utils.mjs";function b(t,o,u){const{parse:a,stringify:n}=L(t),{state:l,getState:r,setState:s}=v(t,()=>u?.({parse:a})||t),m=i.useRef(void 0);T(()=>{const e=()=>{const w=a(P(t));s(w)};return window.addEventListener(U,e),()=>{window.removeEventListener(U,e),clearTimeout(m.current)}},[s]);const c=i.useRef([]),p=i.useCallback((e,w)=>{const d=typeof e=="function"?e(r()):{...r(),...e},h=n(d,y(t)),S=`${window.location.pathname}${h.length?"?":""}${h}${window.location.hash}`,$=`${window.location.pathname}${window.location.search}${window.location.hash}`;if(S===$)return;s(d);const{replace:g,...k}=w||{};c.current.push([g?"replace":"push",S,k]),clearTimeout(m.current),queueMicrotask(()=>{c.current.length&&(m.current=setTimeout(()=>{const f=c.current.at(-1);c.current=[],o[f[0]](f[1],f[2])},R))})},[o,n,r]),E=i.useCallback(e=>{p(t,e)},[p]);return{updateState:s,updateUrl:p,state:l,reset:E,getState:r}}function y(t){const o=Object.keys(t),u=window.location.search,a=new URLSearchParams(u),n=new URLSearchParams;return a.forEach((l,r)=>!o.includes(r)&&n.set(r,l)),n}const U="popstate";export{b as useUrlStateBase};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-in-url",
3
- "version": "4.1.8",
3
+ "version": "4.2.0",
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": {
@@ -14,8 +14,7 @@
14
14
  },
15
15
  "publishConfig": {
16
16
  "registry": "https://registry.npmjs.org/",
17
- "tag": "latest",
18
- "provenance": true
17
+ "tag": "latest"
19
18
  },
20
19
  "license": "MIT",
21
20
  "funding": {