Skip to content

Commit de9a786

Browse files
authored
Upgrading RHF dependencies + Adding content layer (#978)
* chore: dependencies upgrade * chore: upgrading rhf deps * feat: adding content layer to generate all pages
1 parent 6fa9229 commit de9a786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2065
-1959
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ yarn-error.log*
3434
package-lock.json
3535
.vscode
3636
tsconfig.tsbuildinfo
37-
.next/
37+
.next/
38+
39+
# contentlayer
40+
.contentlayer

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

contentlayer.config.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { defineDocumentType, makeSource } from "contentlayer/source-files"
2+
import { remarkHeadingId } from "remark-custom-heading-id"
3+
import remarkGfm from "remark-gfm"
4+
import rehypeMdxCodeProps from "rehype-mdx-code-props"
5+
import emoji from "remark-emoji"
6+
7+
export const Doc = defineDocumentType(() => ({
8+
name: "Doc",
9+
contentType: "mdx",
10+
filePathPattern: "**/*.mdx",
11+
fields: {
12+
title: { type: "string", required: true },
13+
description: { type: "string", required: true },
14+
sidebar: { type: "string", required: true },
15+
},
16+
computedFields: {
17+
slug: {
18+
type: "string",
19+
resolve: (doc) => `/${doc._raw.flattenedPath}`,
20+
},
21+
slugAsParams: {
22+
type: "string",
23+
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
24+
},
25+
segment: {
26+
type: "list",
27+
resolve: (doc) => doc._raw.flattenedPath.split("/"),
28+
},
29+
},
30+
}))
31+
32+
export default makeSource({
33+
contentDirPath: "src/content",
34+
documentTypes: [Doc],
35+
mdx: {
36+
remarkPlugins: [remarkGfm, remarkHeadingId, emoji],
37+
rehypePlugins: [rehypeMdxCodeProps],
38+
},
39+
})

next.config.mjs

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import withMDX from "@next/mdx"
2-
import { remarkHeadingId } from "remark-custom-heading-id"
3-
import remarkGfm from "remark-gfm"
4-
import rehypeMdxCodeProps from "rehype-mdx-code-props"
5-
import emoji from "remark-emoji"
6-
1+
import { withContentlayer } from "next-contentlayer"
72
import withBundleAnalyzer from "@next/bundle-analyzer"
83

94
/** @type {import('next').NextConfig} */
@@ -19,14 +14,4 @@ const bundleAnalyzer = withBundleAnalyzer({
1914
enabled: process.env.ANALYZE === "true",
2015
})
2116

22-
export default bundleAnalyzer(
23-
withMDX({
24-
extension: /\.mdx?$/,
25-
options: {
26-
remarkPlugins: [remarkGfm, remarkHeadingId, emoji],
27-
rehypePlugins: [rehypeMdxCodeProps],
28-
// If you use `MDXProvider`, uncomment the following line.
29-
providerImportSource: "@mdx-js/react",
30-
},
31-
})(nextConfig)
32-
)
17+
export default bundleAnalyzer(withContentlayer(nextConfig))

package.json

+23-24
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,50 @@
44
"version": "6.0.1",
55
"author": "beier luo",
66
"dependencies": {
7-
"@hookform/devtools": "2.0.0-beta.1",
7+
"@hookform/devtools": "4.3.1",
88
"@mdx-js/loader": "^2.3.0",
99
"@mdx-js/react": "^2.3.0",
10-
"@next/mdx": "^13.4.4",
11-
"@types/node": "^20.2.5",
10+
"@next/mdx": "^13.4.5",
11+
"@types/node": "^20.3.1",
1212
"class-variance-authority": "^0.6.0",
1313
"clsx": "^1.2.1",
14+
"contentlayer": "^0.3.3",
15+
"date-fns": "^2.30.0",
1416
"little-state-machine": "^4.8.0",
15-
"next": "^13.4.4",
17+
"next": "^13.4.5",
18+
"next-contentlayer": "^0.3.3",
1619
"next-themes": "^0.2.1",
17-
"prism-react-renderer": "^2.0.4",
20+
"prism-react-renderer": "^2.0.5",
1821
"prismjs": "^1.29.0",
1922
"react": "18.2.0",
2023
"react-dom": "18.2.0",
2124
"react-github-btn": "1.4.0",
22-
"react-hook-form": "6.0.0",
25+
"react-hook-form": "7.44.3",
2326
"react-simple-animate": "^3.5.2",
2427
"react-simple-img": "3.0.0",
2528
"react-sortablejs": "1.5.1",
2629
"rehype-mdx-code-props": "^1.0.0",
2730
"remark-custom-heading-id": "^1.0.1",
28-
"remark-emoji": "^3.1.1",
31+
"remark-emoji": "^3.1.2",
2932
"remark-gfm": "^3.0.1",
3033
"sortablejs": "1.15.0"
3134
},
3235
"devDependencies": {
33-
"@next/bundle-analyzer": "^13.4.4",
36+
"@next/bundle-analyzer": "^13.4.5",
3437
"@types/react-helmet": "^6.1.6",
35-
"@typescript-eslint/eslint-plugin": "^5.59.8",
36-
"@typescript-eslint/parser": "^5.59.8",
38+
"@typescript-eslint/eslint-plugin": "^5.59.11",
39+
"@typescript-eslint/parser": "^5.59.11",
3740
"cross-env": "^7.0.3",
38-
"eslint": "^8.41.0",
39-
"eslint-config-next": "^13.4.4",
41+
"eslint": "^8.42.0",
42+
"eslint-config-next": "^13.4.5",
4043
"eslint-config-prettier": "^8.8.0",
4144
"eslint-plugin-jsx-a11y": "^6.7.1",
4245
"eslint-plugin-react": "^7.32.2",
4346
"eslint-plugin-react-hooks": "^4.6.0",
44-
"husky": "^4.3.8",
45-
"lint-staged": "^10.5.4",
47+
"husky": "^8.0.3",
48+
"lint-staged": "^13.2.2",
4649
"prettier": "^2.8.8",
47-
"typescript": "^5.0.4"
50+
"typescript": "^5.1.3"
4851
},
4952
"keywords": [
5053
"react-hook-form",
@@ -55,19 +58,15 @@
5558
"analyze": "cross-env ANALYZE=true next build",
5659
"build": "next build",
5760
"dev": "next dev",
58-
"format": "prettier --write \"src/**/*.{ts,tsx,mdx}\"",
61+
"format": "prettier --write",
5962
"lint": "next lint --fix",
6063
"now-build": "npm run build",
61-
"start": "npm run dev",
62-
"typecheck": "tsc --noEmit"
63-
},
64-
"husky": {
65-
"hooks": {
66-
"pre-commit": "lint-staged"
67-
}
64+
"start": "next start",
65+
"typecheck": "tsc --noEmit",
66+
"prepare": "husky install"
6867
},
6968
"lint-staged": {
70-
"*.{ts,tsx,mdx}": [
69+
"*.{ts,tsx,mdx,css,json}": [
7170
"npm run format"
7271
]
7372
}

src/actions/settingActions.ts

-14
This file was deleted.

src/components/AdvancedPage.tsx

-30
This file was deleted.

src/components/ApiGallery.tsx

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
import { useEffect } from "react"
2-
import { useStateMachine } from "little-state-machine"
32
import Link from "next/link"
43
import Footer from "./Footer"
54
import typographyStyles from "../styles/typography.module.css"
65
import styles from "./ApiGallery.module.css"
76
import containerStyles from "../styles/container.module.css"
87
import headerStyles from "./Header.module.css"
9-
import { updateSetting } from "../actions/settingActions"
108
import { useRouter } from "next/router"
119

1210
export default function ApiGallery() {
13-
const {
14-
actions,
15-
state: {
16-
setting = {
17-
version: 7,
18-
},
19-
},
20-
} = useStateMachine({
21-
updateSetting,
22-
})
2311
const router = useRouter()
2412

2513
const onChange = (e) => {
2614
const version = parseInt(e.target.value)
2715

28-
actions.updateSetting({
29-
version,
30-
})
31-
3216
if (version !== 7) {
33-
window.location.href = `https://legacy.react-hook-form.com/v${version}/api`
17+
router.push(`https://legacy.react-hook-form.com/v${version}/api`)
3418
} else {
3519
router.push(`/v${version}/docs/`)
3620
}
@@ -63,7 +47,7 @@ export default function ApiGallery() {
6347
) {
6448
router.push(`/docs/${name}`)
6549
}
66-
}, [setting, router])
50+
}, [router])
6751

6852
return (
6953
<div className={containerStyles.container}>

0 commit comments

Comments
 (0)