From 390a51f60e74ef654992f1285dbc048143e3193f Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 28 Nov 2024 20:04:28 +0000 Subject: [PATCH] chore(release): 4.1.7 [skip ci] ## [4.1.7](https://github.com/asmyshlyaev177/state-in-url/compare/v4.1.6...v4.1.7) (2024-11-28) ### Bug Fixes * bump version ([c0bc971](https://github.com/asmyshlyaev177/state-in-url/commit/c0bc971e5a58b88f17d50523ecc1683406b11bce)) --- CHANGELOG.md | 7 +++++++ dist/useUrlStateBase/useUrlStateBase.mjs | 2 +- dist/utils.d.ts | 4 ++-- package.json | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65031ed..e9262d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [4.1.7](https://github.com/asmyshlyaev177/state-in-url/compare/v4.1.6...v4.1.7) (2024-11-28) + + +### Bug Fixes + +* bump version ([c0bc971](https://github.com/asmyshlyaev177/state-in-url/commit/c0bc971e5a58b88f17d50523ecc1683406b11bce)) + ## [4.1.6](https://github.com/asmyshlyaev177/state-in-url/compare/v4.1.5...v4.1.6) (2024-11-26) diff --git a/dist/useUrlStateBase/useUrlStateBase.mjs b/dist/useUrlStateBase/useUrlStateBase.mjs index 3f86220..0549293 100644 --- a/dist/useUrlStateBase/useUrlStateBase.mjs +++ b/dist/useUrlStateBase/useUrlStateBase.mjs @@ -1 +1 @@ -import u from"react";import{TIMEOUT as b}from"../constants/constants.mjs";import{useInsertionEffect as L}from"../useInsertionEffect.mjs";import{useSharedState as P}from"../useSharedState/useSharedState.mjs";import{useUrlEncode as y}from"../useUrlEncode/useUrlEncode.mjs";import{filterUnknownParamsClient as C}from"../utils.mjs";function O(t,a,l){const{parse:s,stringify:o}=y(t),{state:m,getState:r,setState:c}=P(t,()=>l?.({parse:s})||t),p=u.useRef(void 0);L(()=>{const e=()=>{const n=s(C(t));c(n)};return window.addEventListener(E,e),()=>{window.removeEventListener(E,e),clearTimeout(p.current)}},[c]);const f=u.useRef([]),w=u.useCallback((e,n)=>{const h=typeof e=="function"?e(r()):e?{...r(),...e}:r(),S=o(h,I(t)),U=`${window.location.pathname}${S.length?"?":""}${S}${window.location.hash}`,k=`${window.location.pathname}${window.location.search}${window.location.hash}`;if(U===k)return;let i;c(h);const T=n?.replace;delete n?.replace,f.current.push([T?"replace":"push",U,n]),clearTimeout(p.current),p.current=setTimeout(()=>{queueMicrotask(()=>{for(;f.current.length;){const d=f.current.shift();d&&d?.[1]!==i?.[1]&&(i=d)}const[$,v,R]=i||{};i=void 0,$&&a[$](v,R)})},b)},[a,o,r]),g=u.useCallback(e=>{w(t,e)},[w]);return{updateState:c,updateUrl:w,state:m,reset:g,getState:r}}function I(t){const a=Object.keys(t),l=window.location.search,s=new URLSearchParams(l),o=new URLSearchParams;return s.forEach((m,r)=>!a.includes(r)&&o.set(r,m)),o}const E="popstate";export{O as useUrlStateBase}; +import u from"react";import{TIMEOUT as b}from"../constants/constants.mjs";import{useInsertionEffect as v}from"../useInsertionEffect.mjs";import{useSharedState as y}from"../useSharedState/useSharedState.mjs";import{useUrlEncode as L}from"../useUrlEncode/useUrlEncode.mjs";import{filterUnknownParamsClient as P}from"../utils.mjs";function C(t,a,l){const{parse:c,stringify:n}=L(t),{state:m,getState:r,setState:s}=y(t,()=>l?.({parse:c})||t),p=u.useRef(void 0);v(()=>{const e=()=>{const o=c(P(t));s(o)};return window.addEventListener(S,e),()=>{window.removeEventListener(S,e),clearTimeout(p.current)}},[s]);const i=u.useRef([]),f=u.useCallback((e,o)=>{const w=typeof e=="function"?e(r()):e?{...r(),...e}:r(),d=n(w,I(t)),h=`${window.location.pathname}${d.length?"?":""}${d}${window.location.hash}`,$=`${window.location.pathname}${window.location.search}${window.location.hash}`;if(h===$)return;s(w);const E=o?.replace;delete o?.replace,i.current.push([E?"replace":"push",h,o]),clearTimeout(p.current),p.current=setTimeout(()=>{queueMicrotask(()=>{if(!i.current.length)return;const g=i.current.at(-1);i.current=[];const[T,k,R]=g||[];a[T](k,R)})},b)},[a,n,r]),U=u.useCallback(e=>{f(t,e)},[f]);return{updateState:s,updateUrl:f,state:m,reset:U,getState:r}}function I(t){const a=Object.keys(t),l=window.location.search,c=new URLSearchParams(l),n=new URLSearchParams;return c.forEach((m,r)=>!a.includes(r)&&n.set(r,m)),n}const S="popstate";export{C as useUrlStateBase}; diff --git a/dist/utils.d.ts b/dist/utils.d.ts index 296a114..50750f1 100644 --- a/dist/utils.d.ts +++ b/dist/utils.d.ts @@ -27,8 +27,8 @@ export declare function filterUnknownParams(shape: T, searchPa export declare function filterUnknown(shape: T, entries: [key: string, value: string][]): string[][]; export declare function assignValue(shape: T, newVal: Partial): T; export interface Router { - push: (href: string, opts: object) => void; - replace: (href: string, opts: object) => void; + push: (href: string, opts?: object) => void; + replace: (href: string, opts?: object) => void; } export declare const routerHistory: Router; export declare const isSafari: boolean; diff --git a/package.json b/package.json index 06f1a4e..65af0ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "state-in-url", - "version": "4.1.6", + "version": "4.1.7", "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.", "homepage": "https://state-in-url.dev", "repository": {