state-in-url 8.0.1 → 8.0.2
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.
- package/dist/next/useUrlState/useUrlState.cjs +1 -1
- package/dist/next/useUrlState/useUrlState.mjs +1 -1
- package/dist/package.json +1 -1
- package/dist/useUrlStateBase/useUrlStateBase.cjs +1 -1
- package/dist/useUrlStateBase/useUrlStateBase.d.ts +3 -2
- package/dist/useUrlStateBase/useUrlStateBase.mjs +1 -1
- package/package.json +1 -1
- package/skills/astro-setup/SKILL.md +1 -1
- package/skills/feature-state-hook/SKILL.md +1 -1
- package/skills/form-library-integration/SKILL.md +1 -1
- package/skills/input-handling/SKILL.md +1 -1
- package/skills/nextjs-ssr/SKILL.md +1 -1
- package/skills/react-no-router/SKILL.md +1 -1
- package/skills/react-router-remix-setup/SKILL.md +1 -1
- package/skills/shared-state-no-url/SKILL.md +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=require("react");var g=require("next/navigation");var p=require("../../parseSPObj.cjs");var k=require("../../useUrlStateBase/useUrlStateBase.cjs");var a=require("../../utils.cjs");function q(t){return t&&t.__esModule?t:{default:t}}var s=q(h);function y(t,r){const c=s.default.useMemo(()=>r?.useHistory===void 0?true:!!r?.useHistory,[]);const u=g.useRouter();const d=s.default.useMemo(()=>({push:(...e)=>{if(c){a.routerHistory.push(...e)}else{u.push(...e)}},replace:(...e)=>{if(c){a.routerHistory.replace(...e)}else{u.replace(...e)}}}),[u]);const{state:S,updateState:n,updateUrl:i,reset:f,getState:U,pendingUrlUpdate:v}=k.useUrlStateBase(t,d,({parse:e})=>{return a.isSSR?p.parseSPObj(a.filterUnknownParams(t,r?.searchParams),t):e(a.filterUnknownParamsClient(t,r?.searchParams||a.getSearch()))},void 0,r?.searchParams!==void 0);const o=s.default.useCallback(()=>{if(v())return;n(a.filterUnknownParams(t,p.parseSPObj(Object.fromEntries(a.getParams(a.getSearch()).entries()),t)))},[]);s.default.useEffect(()=>{o();return a.subscribeToUrl(o)},[o]);const l=s.default.useMemo(()=>{const e={..._};if(r?.scroll!==void 0)e.scroll=r.scroll;if(r?.replace!==void 0)e.replace=r.replace;return e},[r?.scroll,r?.replace]);const m=s.default.useCallback((e,b)=>i(e,{...l,...b}),[i,l]);const P=s.default.useCallback(e=>{f({...l,...e})},[f,l]);return{setState:n,setUrl:m,urlState:S,reset:P,getState:U}}const _={replace:true,scroll:false};exports.useUrlState=y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"react";import{useRouter as
|
|
1
|
+
import r from"react";import{useRouter as v}from"next/navigation.js";import{parseSPObj as p}from"../../parseSPObj.mjs";import{useUrlStateBase as y}from"../../useUrlStateBase/useUrlStateBase.mjs";import{routerHistory as m,isSSR as C,filterUnknownParams as f,filterUnknownParamsClient as H,getSearch as S,getParams as M,subscribeToUrl as j}from"../../utils.mjs";function w(s,t){const c=r.useMemo(()=>t?.useHistory===void 0?true:!!t?.useHistory,[]);const a=v();const U=r.useMemo(()=>({push:(...e)=>{if(c){m.push(...e)}else{a.push(...e)}},replace:(...e)=>{if(c){m.replace(...e)}else{a.replace(...e)}}}),[a]);const{state:d,updateState:u,updateUrl:n,reset:i,getState:b,pendingUrlUpdate:h}=y(s,U,({parse:e})=>{return C?p(f(s,t?.searchParams),s):e(H(s,t?.searchParams||S()))},void 0,t?.searchParams!==void 0);const l=r.useCallback(()=>{if(h())return;u(f(s,p(Object.fromEntries(M(S()).entries()),s)))},[]);r.useEffect(()=>{l();return j(l)},[l]);const o=r.useMemo(()=>{const e={...E};if(t?.scroll!==void 0)e.scroll=t.scroll;if(t?.replace!==void 0)e.replace=t.replace;return e},[t?.scroll,t?.replace]);const P=r.useCallback((e,k)=>n(e,{...o,...k}),[n,o]);const g=r.useCallback(e=>{i({...o,...e})},[i,o]);return{setState:u,setUrl:P,urlState:d,reset:g,getState:b}}const E={replace:true,scroll:false};export{w as useUrlState};
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
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-16, react-router@6-7, remix@2, and Astro.",
|
|
5
5
|
"homepage": "https://state-in-url.dev",
|
|
6
6
|
"repository": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var R=require("react");var A=require("../constants/constants.cjs");var S=require("../subscribers.cjs");var D=require("../useIsomorphicLayoutEffect.cjs");var F=require("../useSharedState/useSharedState.cjs");var H=require("../useUrlEncode/useUrlEncode.cjs");var o=require("../utils.cjs");function J(t){return t&&t.__esModule?t:{default:t}}var i=J(R);let g;let a;let s;let E;let U=0;const b=()=>window.location.pathname+window.location.search;function f(){s=void 0;E?.();E=void 0}function d(){if(!s)return void 0;const t=b();if(t===s.from&&t!==s.to){return s}f();return void 0}function K(t,e){const n=d()?.from??b();if(n===t){f();return}s={from:n,to:t,search:e};E??=o.subscribeToUrl(f)}function N(t){if(t.pathname!==window.location.pathname)return;const e=d();const n=t.pathname+t.search;if(e?.to===n)return;const u=n===b();if(u&&!e)return;const h=u?"replace":t.method;t.router[h](t.url,t.opts);K(n,t.search)}function y(){return!!a&&a.pathname===window.location.pathname}function W(t,e,n,u,h=true){const{parse:p,stringify:q}=H.useUrlEncode(t);i.default.useState(()=>{if(o.isSSR||!n||!h)return;const r=!S.subscribers.get(t).length;if(!r||y()||d())return;const l=n({parse:p});if(!o.isEqual(S.stateMap.get(t),l))S.stateMap.set(t,l)});const{state:C,getState:c,setState:w}=F.useSharedState(t,()=>n?.({parse:p})||t);const m=i.default.useRef();if(m.current===void 0)m.current=o.getSearch();D.useIsomorphicLayoutEffect(()=>{const r=()=>{w(p(o.filterUnknownParamsClient(t,o.getSearch())))};window.addEventListener(o.popstateEv,r);if(m.current!==o.getSearch())r();return()=>{window.removeEventListener(o.popstateEv,r)}},[]);i.default.useEffect(()=>{U+=1;return()=>{U-=1;if(U===0)f()}},[]);const v=i.default.useCallback((r,l)=>{const $=typeof r==="function"?r(c(),t):{...c(),...r};w($);const T=a?.search??d()?.search??window.location.search;const L=q($,o.getOtherParams(t,T));const M=L.length?`?${L}`:"";const _=j(window.location.pathname,u);const k=`${_}${M}${window.location.hash}`;if(k===`${_}${T}${window.location.hash}`)return;const{replace:B,...O}=l||{};clearTimeout(g);a={router:e,method:B?"replace":"push",url:k,pathname:window.location.pathname,search:M,opts:O};g=setTimeout(()=>{g=void 0;if(!a)return;const P=a;a=void 0;N(P)},A.TIMEOUT)},[e,q,c]);const I=i.default.useCallback(r=>v(t,r),[v]);return{updateState:w,updateUrl:v,state:C,reset:I,getState:c,pendingUrlUpdate:y}}function j(t,e){if(!e||e==="/"){return t}return t.slice(e.length)}exports.useUrlStateBase=W;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useUrlEncode } from '../useUrlEncode';
|
|
2
2
|
import { type JSONCompatible, type Router } from '../utils';
|
|
3
|
+
declare function isWriteWaitingHere(): boolean;
|
|
3
4
|
export declare function useUrlStateBase<T extends JSONCompatible>(defaultState: T, router: Router, getInitialState?: ({ parse, }: {
|
|
4
5
|
parse: ReturnType<typeof useUrlEncode<T>>['parse'];
|
|
5
|
-
}) => T, basename?: string): {
|
|
6
|
+
}) => T, basename?: string, canSeedFromUrl?: boolean): {
|
|
6
7
|
updateState: (value: Partial<T> | ((currState: T, defaultState: T) => T)) => void;
|
|
7
8
|
updateUrl: (value?: Parameters<(value: Partial<T> | ((currState: T, defaultState: T) => T)) => void>[0], options?: Options) => void;
|
|
8
9
|
state: T;
|
|
9
10
|
reset: (options?: Options) => void;
|
|
10
11
|
getState: () => T;
|
|
11
|
-
pendingUrlUpdate:
|
|
12
|
+
pendingUrlUpdate: typeof isWriteWaitingHere;
|
|
12
13
|
};
|
|
13
14
|
interface OptionsObject {
|
|
14
15
|
[key: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import i from"react";import{TIMEOUT as A}from"../constants/constants.mjs";import{subscribers as F,stateMap as I}from"../subscribers.mjs";import{useIsomorphicLayoutEffect as H}from"../useIsomorphicLayoutEffect.mjs";import{useSharedState as J}from"../useSharedState/useSharedState.mjs";import{useUrlEncode as K}from"../useUrlEncode/useUrlEncode.mjs";import{isSSR as N,isEqual as W,getSearch as v,popstateEv as M,filterUnknownParamsClient as j,getOtherParams as z,subscribeToUrl as D}from"../utils.mjs";let g;let r;let a;let S;let E=0;const U=()=>window.location.pathname+window.location.search;function f(){a=void 0;S?.();S=void 0}function l(){if(!a)return void 0;const t=U();if(t===a.from&&t!==a.to){return a}f();return void 0}function G(t,o){const n=l()?.from??U();if(n===t){f();return}a={from:n,to:t,search:o};S??=D(f)}function Q(t){if(t.pathname!==window.location.pathname)return;const o=l();const n=t.pathname+t.search;if(o?.to===n)return;const s=n===U();if(s&&!o)return;const p=s?"replace":t.method;t.router[p](t.url,t.opts);G(n,t.search)}function q(){return!!r&&r.pathname===window.location.pathname}function V(t,o,n,s,p=true){const{parse:m,stringify:$}=K(t);i.useState(()=>{if(N||!n||!p)return;const e=!F.get(t).length;if(!e||q()||l())return;const u=n({parse:m});if(!W(I.get(t),u))I.set(t,u)});const{state:B,getState:c,setState:h}=J(t,()=>n?.({parse:m})||t);const d=i.useRef();if(d.current===void 0)d.current=v();H(()=>{const e=()=>{h(m(j(t,v())))};window.addEventListener(M,e);if(d.current!==v())e();return()=>{window.removeEventListener(M,e)}},[]);i.useEffect(()=>{E+=1;return()=>{E-=1;if(E===0)f()}},[]);const w=i.useCallback((e,u)=>{const b=typeof e==="function"?e(c(),t):{...c(),...e};h(b);const T=r?.search??l()?.search??window.location.search;const k=$(b,z(t,T));const C=k.length?`?${k}`:"";const L=X(window.location.pathname,s);const y=`${L}${C}${window.location.hash}`;if(y===`${L}${T}${window.location.hash}`)return;const{replace:P,...R}=u||{};clearTimeout(g);r={router:o,method:P?"replace":"push",url:y,pathname:window.location.pathname,search:C,opts:R};g=setTimeout(()=>{g=void 0;if(!r)return;const x=r;r=void 0;Q(x)},A)},[o,$,c]);const O=i.useCallback(e=>w(t,e),[w]);return{updateState:h,updateUrl:w,state:B,reset:O,getState:c,pendingUrlUpdate:q}}function X(t,o){if(!o||o==="/"){return t}return t.slice(o.length)}export{V as useUrlStateBase};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "state-in-url",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
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-16, react-router@6-7, remix@2, and Astro.",
|
|
5
5
|
"homepage": "https://state-in-url.dev",
|
|
6
6
|
"repository": {
|