state-in-url 4.0.4 → 4.0.5

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/README.md CHANGED
@@ -24,6 +24,9 @@ English | [한국어](./README.KO.md) | [简体中文](./README.CN.md)
24
24
  [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)]([https://github.com/semantic-release/semantic-release](https://github.com/asmyshlyaev177/state-in-url))
25
25
  ![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/state-in-url.svg)
26
26
  [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/asmyshlyaev177/state-in-url/badge)](https://scorecard.dev/viewer/?uri=github.com/asmyshlyaev177/state-in-url)
27
+ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9679/badge)](https://www.bestpractices.dev/projects/9679)
28
+ <!-- or by embedding this in your HTML:
29
+ <a href="https://www.bestpractices.dev/projects/9679"><img src="https://www.bestpractices.dev/projects/9679/badge"></a> -->
27
30
 
28
31
  </div>
29
32
 
@@ -147,6 +150,7 @@ All components that use the same `state` object are automatically synchronized.
147
150
  // Only parameters with value different from default will go to the url.
148
151
  export const userState: UserState = { name: '', age: 0 }
149
152
 
153
+ // use `Type` not `Interface`!
150
154
  type UserState = { name: string, age: number }
151
155
  ```
152
156
 
@@ -163,9 +167,6 @@ function MyComponent() {
163
167
  // can pass `searchParams` from server components
164
168
  const { urlState, setUrl, setState } = useUrlState({ defaultState: userState });
165
169
 
166
- // won't let you to accidently mutate state directly, requires TS
167
- // urlState.name = 'John' // <- error
168
-
169
170
  return (
170
171
  <div>
171
172
  <input value={urlState.name}
@@ -1,5 +1,5 @@
1
1
  import { useRouter } from "next/navigation";
2
- import { type DeepReadonly, type JSONCompatible } from "../../utils";
2
+ import { type JSONCompatible } from "../../utils";
3
3
  /**
4
4
  * NextJS hook. Returns `urlState`, `setState`, and `setUrl` functions
5
5
  *
@@ -40,11 +40,11 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState, se
40
40
  *
41
41
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/next/useUrlState#updatestate}
42
42
  */
43
- setState: (value: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T)) => void;
43
+ setState: (value: Partial<T> | ((currState: T) => T)) => void;
44
44
  /**
45
45
  * @deprecated use `setState`
46
46
  */
47
- updateState: (value: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T)) => void;
47
+ updateState: (value: Partial<T> | ((currState: T) => T)) => void;
48
48
  /**
49
49
  * * Example:
50
50
  * ```ts
@@ -55,16 +55,19 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState, se
55
55
  *
56
56
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/next/useUrlState#updateurl}
57
57
  */
58
- setUrl: (value?: Parameters<(value?: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: Options) => void;
58
+ setUrl: (value?: Parameters<(value?: Partial<T> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: Options) => void;
59
59
  /**
60
60
  * @deprecated use `setUrl`
61
61
  */
62
- updateUrl: (value?: Parameters<(value?: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: Options) => void;
63
- urlState: DeepReadonly<DeepReadonly<T>>;
62
+ updateUrl: (value?: Parameters<(value?: Partial<T> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: Options) => void;
63
+ /**
64
+ * State object. Don't mutate directly, use `setState` or `setUrl`
65
+ */
66
+ urlState: T;
64
67
  /**
65
68
  * @deprecated use `urlState`
66
69
  */
67
- state: DeepReadonly<DeepReadonly<T>>;
70
+ state: T;
68
71
  getState: () => T;
69
72
  };
70
73
  type Router = ReturnType<typeof useRouter>;
@@ -1,5 +1,5 @@
1
1
  import { type NavigateOptions } from "react-router-dom";
2
- import { type DeepReadonly, type JSONCompatible } from "../../utils";
2
+ import { type JSONCompatible } from "../../utils";
3
3
  /**
4
4
  * React-router hook. Returns `urlState`, `setState`, and `setUrl` functions
5
5
  *
@@ -35,11 +35,11 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState, us
35
35
  *
36
36
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updatestate}
37
37
  */
38
- setState: (value: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T)) => void;
38
+ setState: (value: Partial<T> | ((currState: T) => T)) => void;
39
39
  /**
40
40
  * @deprecated use `setState`
41
41
  */
42
- updateState: (value: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T)) => void;
42
+ updateState: (value: Partial<T> | ((currState: T) => T)) => void;
43
43
  /**
44
44
  * * Example:
45
45
  * ```ts
@@ -52,15 +52,18 @@ export declare function useUrlState<T extends JSONCompatible>({ defaultState, us
52
52
  *
53
53
  * * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/react-router/useUrlState#updateurl}
54
54
  */
55
- setUrl: (value?: Parameters<(value?: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: NavigateOptions) => void;
55
+ setUrl: (value?: Parameters<(value?: Partial<T> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: NavigateOptions) => void;
56
56
  /**
57
57
  * @deprecated use `setUrl`
58
58
  */
59
- updateUrl: (value?: Parameters<(value?: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: NavigateOptions) => void;
60
- urlState: DeepReadonly<DeepReadonly<T>>;
59
+ updateUrl: (value?: Parameters<(value?: Partial<T> | ((currState: T) => T) | undefined, options?: import("../../useUrlStateBase/useUrlStateBase").Options) => void>[0], options?: NavigateOptions) => void;
60
+ /**
61
+ * State object. Don't mutate directly, use `setState` or `setUrl`
62
+ */
63
+ urlState: T;
61
64
  /**
62
65
  * @deprecated use `urlState`
63
66
  */
64
- state: DeepReadonly<DeepReadonly<T>>;
67
+ state: T;
65
68
  getState: () => T;
66
69
  };
@@ -1,4 +1,4 @@
1
- import { type DeepReadonly, type JSONCompatible } from "../utils";
1
+ import { type JSONCompatible } from "../utils";
2
2
  /**
3
3
  * Custom React hook for sharing state between unrelated components.
4
4
  *
@@ -20,5 +20,5 @@ import { type DeepReadonly, type JSONCompatible } from "../utils";
20
20
  export declare function useSharedState<T extends JSONCompatible>(defaultState: T, _getInitial?: () => T): {
21
21
  state: T;
22
22
  getState: () => T;
23
- setState: (value: (Partial<T> | Partial<DeepReadonly<T>>) | ((currState: T) => T)) => void;
23
+ setState: (value: Partial<T> | ((currState: T) => T)) => void;
24
24
  };
@@ -1,5 +1,5 @@
1
1
  import { useUrlEncode } from "../useUrlEncode";
2
- import { type DeepReadonly, type JSONCompatible, type Router } from "../utils";
2
+ import { type JSONCompatible, type Router } from "../utils";
3
3
  /**
4
4
  * A custom React hook to create custom hooks.
5
5
  *
@@ -24,9 +24,9 @@ import { type DeepReadonly, type JSONCompatible, type Router } from "../utils";
24
24
  export declare function useUrlStateBase<T extends JSONCompatible>(defaultState: T, router: Router, getInitialState?: ({ parse, }: {
25
25
  parse: ReturnType<typeof useUrlEncode<T>>["parse"];
26
26
  }) => T): {
27
- updateState: (value: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T)) => void;
28
- updateUrl: (value?: Parameters<(value: Partial<T> | Partial<DeepReadonly<T>> | ((currState: T) => T)) => void>[0], options?: Options) => void;
29
- state: DeepReadonly<T>;
27
+ updateState: (value: Partial<T> | ((currState: T) => T)) => void;
28
+ updateUrl: (value?: Parameters<(value: Partial<T> | ((currState: T) => T)) => void>[0], options?: Options) => void;
29
+ state: T;
30
30
  getState: () => T;
31
31
  };
32
32
  interface OptionsObject {
package/dist/utils.d.ts CHANGED
@@ -15,9 +15,6 @@ export type JSON = null | boolean | Date | number | string | {
15
15
  export type JSONCompatible = {
16
16
  [prop: string]: JSON | JSON[];
17
17
  };
18
- export type DeepReadonly<T> = T extends Map<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends Set<infer S> ? ReadonlySet<DeepReadonly<S>> : T extends object ? {
19
- readonly [K in keyof T]: DeepReadonly<T[K]>;
20
- } : T;
21
18
  export declare const getParams: (strOrSearchParams?: string | URLSearchParams) => URLSearchParams;
22
19
  export type UnknownObj = object | {
23
20
  [key: string]: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-in-url",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "description": "Easily share complex state objects between unrelated React components, preserve types and structure, with TS validation. Deep links and url state synchronization wthout any hasssle or boilerplate.",
5
5
  "homepage": "https://state-in-url.dev",
6
6
  "repository": {
@@ -103,6 +103,7 @@
103
103
  "reinstall": "npm run cleanup && npm install",
104
104
  "setup": "playwright install --with-deps",
105
105
  "prepack": "npm run build && cp package.json dist/package.json && npm run build:demo",
106
+ "pin-gh-deps": "pin-github-action .github/workflows/tests.yml",
106
107
  "prepare": "npx husky"
107
108
  },
108
109
  "wireit": {
@@ -363,6 +364,7 @@
363
364
  "jest-environment-jsdom": "^29.7.0",
364
365
  "lint-staged": "^15.2.9",
365
366
  "only-allow": "^1.2.1",
367
+ "pin-github-action": "^1.9.1",
366
368
  "playwright": "^1.48.2",
367
369
  "prettier": "^3.2.5",
368
370
  "prettier-plugin-tailwindcss": "^0.6.8",