Skip to content

Commit

Permalink
chore(release): 3.0.0 [skip ci]
Browse files Browse the repository at this point in the history
# [3.0.0](v2.6.0...v3.0.0) (2024-09-30)

### Code Refactoring

* **useurlstate:** remove deprecated things ([87c8c7c](87c8c7c))

### Features

* **useurlstate:** useUrlState hook for react-router@6 ([1c7cd02](1c7cd02))

### BREAKING CHANGES

* **useurlstate:** 1. `useUrlState` for Next.js now accept only object, eg. `useUrlState({
defaultState: {}})`
 2. urls encoded with versions prior to v2.3.0 could stop working
  • Loading branch information
semantic-release-bot committed Sep 30, 2024
1 parent 535e0bf commit 38d09e2
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 1 deletion.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# [3.0.0](https://github.com/asmyshlyaev177/state-in-url/compare/v2.6.0...v3.0.0) (2024-09-30)


### Code Refactoring

* **useurlstate:** remove deprecated things ([87c8c7c](https://github.com/asmyshlyaev177/state-in-url/commit/87c8c7c995c5cd7d9e7aa039c30bfe64b24abe4b))


### Features

* **useurlstate:** useUrlState hook for react-router@6 ([1c7cd02](https://github.com/asmyshlyaev177/state-in-url/commit/1c7cd0227a261dd7594f63cada63a73808df90d2))


### BREAKING CHANGES

* **useurlstate:** 1. `useUrlState` for Next.js now accept only object, eg. `useUrlState({
defaultState: {}})`
2. urls encoded with versions prior to v2.3.0 could stop working

# [2.6.0](https://github.com/asmyshlyaev177/state-in-url/compare/v2.5.2...v2.6.0) (2024-09-19)


Expand Down
1 change: 1 addition & 0 deletions dist/constants/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const e={date:"⏲",undefined:"∙undefined"};export{e as SYMBOLS};
1 change: 1 addition & 0 deletions dist/constants/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{SYMBOLS}from"./constants.mjs";
1 change: 1 addition & 0 deletions dist/encodeState/encodeState.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{encode as t,decode as n}from"../encoder/encoder.mjs";import{getParams as o}from"../utils.mjs";function r(t){let n,o=t[0],r=1;for(;r<t.length;){const e=t[r],c=t[r+1];if(r+=2,("optionalAccess"===e||"optionalCall"===e)&&null==o)return;"access"===e||"optionalAccess"===e?(n=o,o=c(o)):"call"!==e&&"optionalCall"!==e||(o=c(((...t)=>o.call(n,...t))),n=void 0)}return o}function e(n,e,c){const s=o(c);return Object.entries(n||{}).forEach((([n,o])=>{const c=r([e,"optionalAccess",t=>t[n]]);JSON.stringify(o)!==JSON.stringify(c)&&s.set(n,t(o))})),s.toString()}function c(t,e){return{...e||{},...Object.fromEntries([...o(t).entries()].map((([t,o])=>{const c=r([e,"optionalAccess",n=>n[t]]);return[t,(s=n(o,c),i=()=>c,null!=s?s:i())];var s,i})))}}export{c as decodeState,e as encodeState};
1 change: 1 addition & 0 deletions dist/encodeState/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{decodeState,encodeState}from"./encodeState.mjs";
1 change: 1 addition & 0 deletions dist/encoder/encoder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{SYMBOLS as t}from"../constants/constants.mjs";import{typeOf as n}from"../utils.mjs";function e(e){if(l(e))return e;switch(n(e)){case"function":case"symbol":return"";case"date":return r=e,t.date+new Date(r).toISOString();case"undefined":return t.undefined;default:return JSON.stringify(e).replaceAll('"',"'")}var r}function r(t,n){return a(t.replaceAll("'",'"'),n)}const o=n=>{if(n!==t.undefined)return function(t){let n,e=t[0],r=1;for(;r<t.length;){const o=t[r],s=t[r+1];if(r+=2,("optionalAccess"===o||"optionalCall"===o)&&null==e)return;"access"===o||"optionalAccess"===o?(n=e,e=s(e)):"call"!==o&&"optionalCall"!==o||(e=s(((...t)=>e.call(n,...t))),n=void 0)}return e}([n,"optionalAccess",t=>t.startsWith,"optionalCall",n=>n(t.date)])?new Date(n.slice(1)):s},s=Symbol("isError"),c=(t,n)=>{const e="string"==typeof n,r=e&&o(n);return r===s?n:e?r:n};function a(t,n){try{return JSON.parse(t,c)}catch(e){const r=o(t);return r!==s?r:n}}const i=new RegExp(`^(${t.undefined}|${t.date})`),l=t=>i.test(String(t));export{r as decode,o as decodePrimitive,e as encode,s as errorSym,a as parseJSON,c as reviver};
1 change: 1 addition & 0 deletions dist/encoder/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{decode,encode}from"./encoder.mjs";
1 change: 1 addition & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{decode,encode}from"./encoder/encoder.mjs";export{decodeState,encodeState}from"./encodeState/encodeState.mjs";export{useUrlState}from"./next/useUrlState/useUrlState.mjs";export{useSharedState}from"./useSharedState/useSharedState.mjs";export{useUrlEncode}from"./useUrlEncode/useUrlEncode.mjs";export{useUrlStateBase}from"./useUrlStateBase/useUrlStateBase.mjs";export{isSSR,typeOf}from"./utils.mjs";
1 change: 1 addition & 0 deletions dist/next/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useUrlState}from"./useUrlState/useUrlState.mjs";
1 change: 1 addition & 0 deletions dist/next/useUrlState/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useUrlState}from"./useUrlState.mjs";
1 change: 1 addition & 0 deletions dist/next/useUrlState/useUrlState.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{useRouter as t,useSearchParams as e}from"next/navigation";import a from"react";import{parseSPObj as r}from"../../parseSPObj.mjs";import{useUrlStateBase as s}from"../../useUrlStateBase/useUrlStateBase.mjs";import{filterUnknownParams as o,isSSR as m,filterUnknownParamsClient as p}from"../../utils.mjs";function u({defaultState:u,searchParams:i,...l}){const n=t(),{state:f,updateState:S,updateUrl:d,getState:j}=s(u,n,(({parse:t})=>m()?r(o(u,i),u):t(p(u)))),U=a.useCallback(((t,e)=>{const a={...c,...l,...e};d(t,a)}),[d,l]),b=e();return a.useEffect((()=>{S(o(u,r(Object.fromEntries([...b.entries()]),u)))}),[b]),{updateState:S,updateUrl:U,state:f,getState:j}}const c={replace:!0,scroll:!1};export{u as useUrlState};
1 change: 1 addition & 0 deletions dist/parseSPObj.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{decodePrimitive as n,errorSym as t,decode as o}from"./encoder/encoder.mjs";function l(n,t){return{...t,...r(JSON.stringify(n),t)}}function r(o,l){try{return JSON.parse(o,c)}catch(r){const c=n(o);return c!==t?c:l}}const c=(n,t)=>{const l="string"==typeof t,r=l&&o(function(n){let t,o=n[0],l=1;for(;l<n.length;){const r=n[l],c=n[l+1];if(l+=2,("optionalAccess"===r||"optionalCall"===r)&&null==o)return;"access"===r||"optionalAccess"===r?(t=o,o=c(o)):"call"!==r&&"optionalCall"!==r||(o=c(((...n)=>o.call(t,...n))),t=void 0)}return o}([t,"optionalAccess",n=>n.replaceAll,"optionalCall",n=>n("'",'"')]));return n&&l?r:t};export{l as parseSPObj};
1 change: 1 addition & 0 deletions dist/react-router/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useUrlState}from"./useUrlState/useUrlState.mjs";
1 change: 1 addition & 0 deletions dist/react-router/useUrlState/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useUrlState}from"./useUrlState.mjs";
1 change: 1 addition & 0 deletions dist/react-router/useUrlState/useUrlState.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import t from"react";import{useNavigate as e,useSearchParams as r}from"react-router-dom";import{parseSPObj as a}from"../../parseSPObj.mjs";import{useUrlStateBase as s}from"../../useUrlStateBase/useUrlStateBase.mjs";import{assignValue as o,filterUnknownParams as m,filterUnknownParamsClient as p}from"../../utils.mjs";function u({defaultState:u,...l}){const f=e(),i=t.useMemo((()=>({replace:(t,e)=>f(t,{...c,...l,...e}),push:(t,e)=>f(t,{...c,...l,...e})})),[f,l]),{state:n,updateState:S,updateUrl:d,getState:j}=s(u,i,(({parse:t})=>t(p(u)))),U=t.useCallback(((t,e)=>{const r={...c,...l,...e};d(t,r)}),[l]),[b]=r();return t.useEffect((()=>{S(o(u,n,m(u,a(Object.fromEntries([...b.entries()]),u))))}),[b]),{updateState:S,updateUrl:U,state:n,getState:j}}const c={replace:!0,preventScrollReset:!0};export{u as useUrlState};
1 change: 1 addition & 0 deletions dist/subscribers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const e=new WeakMap,t=new WeakMap,n={get:e=>t.get(e)||[],add(e,n){const s=this.get(e);return t.set(e,s.concat(n)),()=>this.remove(e,n)},remove(e,n){const s=this.get(e).filter((e=>e!==n));s.length?t.set(e,s):t.delete(e)}},s={get:function(t){return e.get(t)},set:function(t,n){e.set(t,n)}};export{s as stateMap,n as subscribers};
1 change: 1 addition & 0 deletions dist/useInsertionEffect.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import e from"react";const t=e.useInsertionEffect||e.useEffect;export{t as useInsertionEffect};
1 change: 1 addition & 0 deletions dist/useSharedState/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useSharedState}from"./useSharedState.mjs";
1 change: 1 addition & 0 deletions dist/useSharedState/useSharedState.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import t from"react";import{stateMap as r,subscribers as e}from"../subscribers.mjs";import{useInsertionEffect as n}from"../useInsertionEffect.mjs";import{isSSR as c,isEqual as o}from"../utils.mjs";function u(t){let r,e=t[0],n=1;for(;n<t.length;){const c=t[n],o=t[n+1];if(n+=2,("optionalAccess"===c||"optionalCall"===c)&&null==e)return;"access"===c||"optionalAccess"===c?(r=e,e=o(e)):"call"!==c&&"optionalCall"!==c||(e=o(((...t)=>e.call(r,...t))),r=void 0)}return e}function s(s,l){const a=t.useRef(s),[i,f]=t.useState((()=>{if(c())return l?u([l,"optionalCall",t=>t()]):a.current;const t=r.get(a.current);if(t)return t;{const t=u([l,"optionalCall",t=>t()])||a.current;return r.set(a.current,t),t}})),p=t.useCallback((t=>{const n=r.get(a.current),c="function"==typeof t?t(n):{...n,...t};o(n,c)||(r.set(a.current,c),e.get(a.current).forEach((t=>{t()})))}),[]);n((()=>{const t=e.add(a.current,(()=>{f(r.get(a.current)||a.current)}));return()=>{t()}}),[]);return{state:i,getState:t.useCallback((()=>r.get(a.current)||a.current),[]),setState:p}}export{s as useSharedState};
1 change: 1 addition & 0 deletions dist/useUrlEncode/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useUrlEncode}from"./useUrlEncode.mjs";
1 change: 1 addition & 0 deletions dist/useUrlEncode/useUrlEncode.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import t from"react";import{encodeState as r,decodeState as e}from"../encodeState/encodeState.mjs";import{typeOf as o}from"../utils.mjs";function n(n){const c=t.useCallback((function(t,e){return"object"===o(t)?r(t,n,e):""}),[n]);return{parse:t.useCallback((function(t){return e(t,n)}),[n]),stringify:c}}export{n as useUrlEncode};
1 change: 1 addition & 0 deletions dist/useUrlStateBase/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export{useUrlStateBase}from"./useUrlStateBase.mjs";
1 change: 1 addition & 0 deletions dist/useUrlStateBase/useUrlStateBase.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import t from"react";import{useInsertionEffect as e}from"../useInsertionEffect.mjs";import{useSharedState as o}from"../useSharedState/useSharedState.mjs";import{useUrlEncode as n}from"../useUrlEncode/useUrlEncode.mjs";import{filterUnknownParamsClient as a}from"../utils.mjs";function s(s,c,i){const{parse:l,stringify:p}=n(s),{state:u,getState:m,setState:d}=o(s,(()=>function(t){let e,o=t[0],n=1;for(;n<t.length;){const a=t[n],s=t[n+1];if(n+=2,("optionalAccess"===a||"optionalCall"===a)&&null==o)return;"access"===a||"optionalAccess"===a?(e=o,o=s(o)):"call"!==a&&"optionalCall"!==a||(o=s(((...t)=>o.call(e,...t))),e=void 0)}return o}([i,"optionalCall",t=>t({parse:l})])||s));e((()=>{const t=()=>{const t=l(a(s));d(t)};return window.addEventListener(r,t),()=>{window.removeEventListener(r,t)}}),[d]);const w=t.useCallback(((t,e)=>{const o=`${window.location.pathname}${window.location.search}${window.location.hash}`,n="function"==typeof t,a=function(t){const e=Object.keys(t),o=window.location.search,n=new URLSearchParams(o),a=new URLSearchParams;return n.forEach(((t,o)=>!e.includes(o)&&a.set(o,t))),a}(s),r=n?t(m()):t?{...m(),...t}:m(),i=p(r,a);d(r);const l=`${window.location.pathname}${i.length?"?":""}${i}${window.location.hash}`;if(o!==l){const{replace:t,...o}=e||{};c[t?"replace":"push"](l,{...o})}}),[c,p,m]);return{updateState:d,updateUrl:w,state:u,getState:m}}const r="popstate";export{s as useUrlStateBase};
1 change: 1 addition & 0 deletions dist/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function t(t){let n,e=t[0],o=1;for(;o<t.length;){const c=t[o],r=t[o+1];if(o+=2,("optionalAccess"===c||"optionalCall"===c)&&null==e)return;"access"===c||"optionalAccess"===c?(n=e,e=r(e)):"call"!==c&&"optionalCall"!==c||(e=r(((...t)=>e.call(n,...t))),n=void 0)}return e}const n=t=>{const n=typeof t,e=null===t,o=Array.isArray(t),c=t instanceof Date;return(e?"null":c&&"date")||o&&"array"||!e&&!c&&!o&&"object"===n&&"object"||n},e=()=>"undefined"==typeof window,o=n=>new URLSearchParams("string"==typeof n?c(n):t([n,"optionalAccess",t=>t.toString,"optionalCall",t=>t()])||""),c=n=>t([n,"access",t=>t.split,"call",t=>t("?"),"optionalAccess",t=>t[1]])||n||"",r=(t,n)=>JSON.stringify(t)===JSON.stringify(n);function a(t){const n=new URLSearchParams;return i(t,[...new URLSearchParams(window.location.search).entries()]).forEach((([t,e])=>n.set(t,e))),n.toString()}function s(t,n){return Object.fromEntries(i(t,Object.entries(n||{})))}function i(t,n){const e=Object.keys(t);return n.filter((([t])=>e.includes(t))).map((([t,n])=>[t.replaceAll("+"," "),n]))}function l(t,n,e){const o=Object.assign({},t,n);return Object.entries(t).forEach((([n])=>{const c=n,r=void 0!==e[c];o[c]=r?e[c]:t[c]})),o}export{l as assignValue,s as filterUnknownParams,a as filterUnknownParamsClient,o as getParams,r as isEqual,e as isSSR,n as typeOf};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "state-in-url",
"version": "2.6.0",
"version": "3.0.0",
"description": "Library to store complex state in browser URL, includes hook for NextJS, hook for pure React, and low level helpers. https://state-in-url-asmyshlyaev177.vercel.app/",
"homepage": "https://github.com/asmyshlyaev177/state-in-url",
"keywords": [
Expand Down

0 comments on commit 38d09e2

Please sign in to comment.