Skip to content

Commit cfc3b26

Browse files
committed
feat(navigation): 🚀 add hardNavigate and hardReplace functions
This commit introduces several improvements to the navigation module: - Renamed `UrlInfo` type to `URLInfo` for consistency with browser APIs - Added support for URL objects in navigation functions - Introduced two new functions: - `hardNavigate`: For full page navigation using `window.location.assign` - `hardReplace`: For full page replacement using `window.location.replace` - Updated dependencies across packages to latest versions - Removed tailwind-related prettier plugins and configs - Moved typescript from catalog to direct version dependency These changes enhance the navigation capabilities while maintaining better type consistency and modernizing the dependency structure.
1 parent 94da8f4 commit cfc3b26

17 files changed

+849
-814
lines changed

.github/workflows/autofix.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup pnpm
2222
uses: pnpm/action-setup@v4
2323
with:
24-
version: 9.15.0
24+
version: 9.15.4
2525

2626
- name: Setup Node.js
2727
uses: actions/setup-node@v4

.github/workflows/lint-and-type.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup pnpm
2222
uses: pnpm/action-setup@v4
2323
with:
24-
version: 9.15.0
24+
version: 9.15.4
2525

2626
- name: Setup Node.js
2727
uses: actions/setup-node@v4

.github/workflows/release-and-publish(pkg.pr.new).yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup pnpm
2323
uses: pnpm/action-setup@v4
2424
with:
25-
version: 9.15.0
25+
version: 9.15.4
2626

2727
- name: Setup Node.js 20.x
2828
uses: actions/setup-node@v4

.github/workflows/release-notes-and-publish(changelogithub).yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Setup pnpm
2929
uses: pnpm/action-setup@v4
3030
with:
31-
version: 9.15.0
31+
version: 9.15.4
3232

3333
- name: Setup Node.js
3434
uses: actions/setup-node@v4

.github/workflows/size-limit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup pnpm
2222
uses: pnpm/action-setup@v4
2323
with:
24-
version: 9.15.0
24+
version: 9.15.4
2525

2626
- name: Setup Node.js
2727
uses: actions/setup-node@v4

dev/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"react-dom": "19.0.0"
1818
},
1919
"devDependencies": {
20-
"@types/node": "^22.12.0",
21-
"@vitejs/plugin-react-swc": "^3.7.2",
20+
"@types/node": "^22.13.4",
21+
"@vitejs/plugin-react-swc": "^3.8.0",
2222
"@zayne-labs/tsconfig": "catalog:",
2323
"tsx": "^4.19.1",
24-
"typescript": "catalog:",
25-
"vite": "^6.0.11"
24+
"typescript": "5.7.3",
25+
"vite": "^6.1.0"
2626
}
2727
}

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@zayne-labs/toolkit-root",
33
"type": "module",
44
"version": "0.0.0",
5-
"packageManager": "[email protected].0",
5+
"packageManager": "[email protected].4",
66
"author": "Ryan Zayne",
77
"scripts": {
88
"build": "pnpm --filter \"./packages/*\" build",
@@ -24,17 +24,17 @@
2424
},
2525
"devDependencies": {
2626
"@changesets/cli": "^2.27.12",
27-
"@eslint-react/eslint-plugin": "^1.25.0",
28-
"@types/node": "^22.12.0",
27+
"@eslint-react/eslint-plugin": "^1.26.2",
28+
"@types/node": "^22.13.4",
2929
"@zayne-labs/eslint-config": "^0.5.1",
3030
"@zayne-labs/tsconfig": "catalog:",
31-
"bumpp": "^10.0.1",
32-
"eslint": "^9.19.0",
31+
"bumpp": "^10.0.3",
32+
"eslint": "^9.20.1",
3333
"eslint-plugin-react-hooks": "^5.1.0",
34-
"eslint-plugin-react-refresh": "^0.4.18",
34+
"eslint-plugin-react-refresh": "^0.4.19",
3535
"husky": "^9.1.7",
3636
"lint-staged": "^15.4.3",
37-
"prettier": "^3.4.2",
38-
"typescript": "catalog:"
37+
"prettier": "^3.5.1",
38+
"typescript": "5.7.3"
3939
}
4040
}

packages/toolkit-core/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@zayne-labs/toolkit-core",
33
"type": "module",
44
"version": "0.8.35",
5-
"packageManager": "[email protected].0",
5+
"packageManager": "[email protected].4",
66
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
77
"author": "Ryan Zayne",
88
"license": "MIT",
@@ -52,16 +52,16 @@
5252
"@size-limit/esbuild-why": "^11.1.6",
5353
"@size-limit/preset-small-lib": "^11.1.6",
5454
"@total-typescript/ts-reset": "^0.6.1",
55-
"@types/node": "^22.12.0",
55+
"@types/node": "^22.13.4",
5656
"@zayne-labs/tsconfig": "catalog:",
5757
"clsx": "^2.1.1",
5858
"concurrently": "^9.1.2",
5959
"cross-env": "^7.0.3",
60-
"publint": "^0.3.2",
60+
"publint": "^0.3.5",
6161
"size-limit": "^11.1.6",
62-
"terser": "^5.37.0",
62+
"terser": "^5.39.0",
6363
"tsup": "^8.3.6",
64-
"typescript": "catalog:"
64+
"typescript": "5.7.3"
6565
},
6666
"publishConfig": {
6767
"access": "public",

packages/toolkit-core/src/navigation.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ export type URLSearchParamsInit =
88
| Record<string, string | string[]>
99
| URLSearchParams;
1010

11-
export type UrlInfo = {
12-
hash: string;
13-
pathname: string;
14-
search: string | URLSearchParamsInit;
15-
state: NonNullable<unknown> | null;
16-
};
17-
1811
export const createSearchParams = (paramsInit: URLSearchParamsInit = ""): URLSearchParams => {
1912
if (isString(paramsInit) || isIterable(paramsInit)) {
2013
return new URLSearchParams(paramsInit);
@@ -35,14 +28,25 @@ export const createSearchParams = (paramsInit: URLSearchParamsInit = ""): URLSea
3528
return new URLSearchParams(keyValuePair);
3629
};
3730

31+
export type URLInfo = {
32+
hash: string;
33+
pathname: string;
34+
search: string | URLSearchParamsInit;
35+
state: NonNullable<unknown> | null;
36+
};
37+
3838
const questionMark = "?";
3939
const hashMark = "#";
4040

41-
const formatUrl = (url: string | Partial<UrlInfo>) => {
41+
const formatUrl = (url: string | Partial<URLInfo> | URL) => {
4242
if (isString(url)) {
4343
return { urlObject: null, urlString: url };
4444
}
4545

46+
if (url instanceof URL) {
47+
return { urlObject: null, urlString: url.toString() };
48+
}
49+
4650
const urlObject = {
4751
...url,
4852
hash: url.hash ?? "",
@@ -65,20 +69,22 @@ const formatUrl = (url: string | Partial<UrlInfo>) => {
6569

6670
/* eslint-disable unicorn/prefer-global-this -- It doesn't need globalThis since it only exists in window */
6771

68-
export const pushState = (url: string | Partial<UrlInfo>, state?: UrlInfo["state"]) => {
72+
export const pushState = (url: string | Partial<URLInfo> | URL, state?: URLInfo["state"]) => {
6973
const { urlObject, urlString } = formatUrl(url);
7074

7175
window.history.pushState(urlObject?.state ?? state, "", urlString);
7276
};
7377

74-
export const replaceState = (url: string | Partial<UrlInfo>, state?: UrlInfo["state"]) => {
78+
export const replaceState = (url: string | Partial<URLInfo>, state?: URLInfo["state"]) => {
7579
const { urlObject, urlString } = formatUrl(url);
7680

7781
window.history.replaceState(urlObject?.state ?? state, "", urlString);
7882
};
7983

80-
// type FullUrlInfo = Location & UrlInfo;
84+
export const hardNavigate = (url: string | Partial<URLInfo> | URL, type?: "assign" | "replace") => {
85+
const { urlString } = formatUrl(url);
8186

82-
// const hardNavigate = (url: string | Partial<UrlInfo>) => window.location.assign(formatUrl(url).urlString);
87+
window.location[type ?? "assign"](urlString);
88+
};
8389

8490
/* eslint-enable unicorn/prefer-global-this -- It doesn't need globalThis since it only exists in window */

packages/toolkit-react/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@zayne-labs/toolkit-react",
33
"type": "module",
44
"version": "0.8.35",
5-
"packageManager": "[email protected].0",
5+
"packageManager": "[email protected].4",
66
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
77
"author": "Ryan Zayne",
88
"license": "MIT",
@@ -71,19 +71,19 @@
7171
"@size-limit/esbuild-why": "^11.1.6",
7272
"@size-limit/preset-small-lib": "^11.1.6",
7373
"@total-typescript/ts-reset": "^0.6.1",
74-
"@types/node": "^22.12.0",
74+
"@types/node": "^22.13.4",
7575
"@types/react": "^19.0.8",
7676
"@types/react-dom": "^19.0.3",
7777
"@zayne-labs/tsconfig": "catalog:",
7878
"concurrently": "^9.1.2",
7979
"cross-env": "^7.0.3",
80-
"publint": "^0.3.2",
80+
"publint": "^0.3.5",
8181
"react": "^19.0.0",
8282
"react-dom": "^19.0.0",
8383
"size-limit": "^11.1.6",
84-
"terser": "^5.37.0",
84+
"terser": "^5.39.0",
8585
"tsup": "^8.3.6",
86-
"typescript": "catalog:",
86+
"typescript": "5.7.3",
8787
"zustand": "^5.0.3"
8888
},
8989
"publishConfig": {

packages/toolkit-react/src/hooks/createCustomContext.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { createContext, useContext } from "react";
1+
import { createContext, use } from "react";
22

33
export class ContextError extends Error {
44
override name = "ContextError";
55

6-
constructor(message: string) {
7-
super(message);
6+
constructor(...args: Parameters<typeof Error>) {
7+
super(...args);
88

99
Error.captureStackTrace(this, this.constructor);
1010
}
@@ -44,7 +44,7 @@ const createCustomContext = <TContextValue, TStrict extends boolean = true>(
4444
Context.displayName = name;
4545

4646
const useCustomContext = (): UseCustomContextResult<TContextValue, TStrict> => {
47-
const contextValue = useContext(Context);
47+
const contextValue = use(Context);
4848

4949
if (strict && contextValue === null) {
5050
throw new ContextError(errorMessage ?? getErrorMessage(hookName, providerName));

packages/toolkit-type-helpers/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@zayne-labs/toolkit-type-helpers",
33
"type": "module",
44
"version": "0.8.35",
5-
"packageManager": "[email protected].0",
5+
"packageManager": "[email protected].4",
66
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
77
"author": "Ryan Zayne",
88
"license": "MIT",
@@ -49,16 +49,16 @@
4949
"@size-limit/esbuild-why": "^11.1.6",
5050
"@size-limit/preset-small-lib": "^11.1.6",
5151
"@total-typescript/ts-reset": "^0.6.1",
52-
"@types/node": "^22.12.0",
52+
"@types/node": "^22.13.4",
5353
"@zayne-labs/tsconfig": "catalog:",
5454
"clsx": "^2.1.1",
5555
"concurrently": "^9.1.2",
5656
"cross-env": "^7.0.3",
57-
"publint": "^0.3.2",
57+
"publint": "^0.3.5",
5858
"size-limit": "^11.1.6",
59-
"terser": "^5.37.0",
59+
"terser": "^5.39.0",
6060
"tsup": "^8.3.6",
61-
"typescript": "catalog:"
61+
"typescript": "5.7.3"
6262
},
6363
"publishConfig": {
6464
"access": "public",

packages/toolkit/.prettierrc.json

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
{
2-
"plugins": ["prettier-plugin-tailwindcss", "prettier-plugin-classnames", "prettier-plugin-merge"],
3-
"tailwindFunctions": ["cnMerge", "cnJoin", "cn", "tv"],
4-
"tailwindStylesheet": "./src/react/tailwind.css",
5-
"tailwindConfig": "./tailwind.config.ts",
6-
"customFunctions": ["cnMerge", "cnJoin", "cn", "tv"],
7-
"tailwindAttributes": ["classNames"],
8-
"customAttributes": ["classNames"],
9-
"endingPosition": "absolute-with-indent",
102
"jsxSingleQuote": false,
113
"printWidth": 107,
124
"singleQuote": false,

packages/toolkit/package.json

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@zayne-labs/toolkit",
33
"type": "module",
44
"version": "0.8.35",
5-
"packageManager": "[email protected].0",
5+
"packageManager": "[email protected].4",
66
"description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
77
"author": "Ryan Zayne",
88
"license": "MIT",
@@ -72,22 +72,18 @@
7272
"@arethetypeswrong/cli": "^0.17.3",
7373
"@changesets/cli": "^2.27.12",
7474
"@total-typescript/ts-reset": "^0.6.1",
75-
"@types/node": "^22.12.0",
75+
"@types/node": "^22.13.4",
7676
"@types/react": "^19.0.8",
7777
"@types/react-dom": "^19.0.3",
7878
"@zayne-labs/tsconfig": "catalog:",
7979
"concurrently": "^9.1.2",
8080
"cross-env": "^7.0.3",
81-
"prettier-plugin-classnames": "^0.7.6",
82-
"prettier-plugin-merge": "^0.7.2",
83-
"prettier-plugin-tailwindcss": "^0.6.11",
84-
"publint": "^0.3.2",
81+
"publint": "^0.3.5",
8582
"react": "^19.0.0",
8683
"react-dom": "^19.0.0",
87-
"tailwindcss": "^3.4.17",
88-
"terser": "^5.37.0",
84+
"terser": "^5.39.0",
8985
"tsup": "^8.3.6",
90-
"typescript": "catalog:",
86+
"typescript": "5.7.3",
9187
"zustand": "^5.0.3"
9288
},
9389
"publishConfig": {

packages/toolkit/tailwind.config.ts

-33
This file was deleted.

0 commit comments

Comments
 (0)