From 427eec945b590e5ce9ee861aa3593fd4d45eadb8 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 10:56:19 +0800 Subject: [PATCH 01/10] fix: Support Chinese as Route path with `encodeURI` --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/client/index.tsx | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 290c1d0..472505d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [0.10.1] - 2022-07-07 + +### Fixed + +- Support Chinese as Route path with `encodeURI` + ## [0.10.0] - 2022-07-06 ### Changed diff --git a/package.json b/package.json index e5495ee..4455601 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blizzbolts/docit", - "version": "0.10.0", + "version": "0.10.1", "license": "MIT", "bin": { "docit": "bin/docit.js" diff --git a/src/client/index.tsx b/src/client/index.tsx index e27f02c..85bc3b3 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -40,7 +40,7 @@ const Root = () => { return ( From 033a34d3c2f900eb62c81edce4221646728b076c Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:08:29 +0800 Subject: [PATCH 02/10] feat: Change built-in components to default export --- CHANGELOG.md | 1 + src/client/built-in/ApiTable/index.tsx | 2 +- src/client/built-in/ShowCode/index.tsx | 2 +- src/client/components/Document/index.tsx | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 472505d..de032e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Support Chinese as Route path with `encodeURI` +- Change built-in components to default export ## [0.10.0] - 2022-07-06 diff --git a/src/client/built-in/ApiTable/index.tsx b/src/client/built-in/ApiTable/index.tsx index 9ef7ebb..1186f3e 100644 --- a/src/client/built-in/ApiTable/index.tsx +++ b/src/client/built-in/ApiTable/index.tsx @@ -123,4 +123,4 @@ const ApiTable: React.FC = (props) => { ); }; -export { ApiTable }; +export default ApiTable; diff --git a/src/client/built-in/ShowCode/index.tsx b/src/client/built-in/ShowCode/index.tsx index 490bf82..df49937 100644 --- a/src/client/built-in/ShowCode/index.tsx +++ b/src/client/built-in/ShowCode/index.tsx @@ -75,4 +75,4 @@ const ShowCode: React.FC = (props) => { ); }; -export { ShowCode }; +export default ShowCode; diff --git a/src/client/components/Document/index.tsx b/src/client/components/Document/index.tsx index efb2d17..f24cc91 100644 --- a/src/client/components/Document/index.tsx +++ b/src/client/components/Document/index.tsx @@ -1,8 +1,8 @@ import React, { Suspense } from "react"; import { MDXProvider } from "@mdx-js/react"; import { StyledMarkdown, StyledDocument } from "./styled"; -import { ShowCode } from "../../built-in/ShowCode"; -import { ApiTable } from "../../built-in/ApiTable"; +import ShowCode from "../../built-in/ShowCode"; +import ApiTable from "../../built-in/ApiTable"; import { useAnchors } from "../../hooks/useAnchors"; import { Toc } from "../Toc"; From 16f29ec3f6fcbbe24a1b9d581dfb75e182d2a253 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:09:42 +0800 Subject: [PATCH 03/10] v0.10.1-beta1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4455601..b2c2d9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blizzbolts/docit", - "version": "0.10.1", + "version": "0.10.1-beta1", "license": "MIT", "bin": { "docit": "bin/docit.js" From ffa178c1cc8792c3713509756d8b93c703d263d2 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:13:17 +0800 Subject: [PATCH 04/10] feat: change ShowCode to inline Component --- src/client/components/Document/index.tsx | 80 +++++++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/src/client/components/Document/index.tsx b/src/client/components/Document/index.tsx index f24cc91..1f6b738 100644 --- a/src/client/components/Document/index.tsx +++ b/src/client/components/Document/index.tsx @@ -1,11 +1,20 @@ -import React, { Suspense } from "react"; +import React, { Suspense, useEffect, useMemo, useRef, useState } from "react"; import { MDXProvider } from "@mdx-js/react"; import { StyledMarkdown, StyledDocument } from "./styled"; -import ShowCode from "../../built-in/ShowCode"; import ApiTable from "../../built-in/ApiTable"; import { useAnchors } from "../../hooks/useAnchors"; import { Toc } from "../Toc"; +import hljs from "highlight.js"; +import { + StyledRenderWindow, + StyledShowCodeContainer, + StyledButtonContainer, + StyledCodeWindow, +} from "../../built-in/ShowCode/styled"; +import { Loading } from "../../components/Loading"; +import sandboxes from "virtual:sandboxes"; + const Document: React.FC = (props) => { const { children } = props; useAnchors(); @@ -15,7 +24,72 @@ const Document: React.FC = (props) => { { + const { code, lang, mobileView, moduleId } = props; + + const ComponentRef = useRef(() => <>); + const [isLoading, setIsLoading] = useState(false); + const [isShowing, setIsShowing] = useState(false); + const [_, update] = useState({}); + + useEffect(() => { + if (sandboxes[moduleId] && !mobileView) { + setIsLoading(true); + sandboxes[moduleId]() + .then((res) => { + const { default: Component } = res; + ComponentRef.current = Component; + update({}); + }) + .finally(() => { + setIsLoading(false); + }); + } + }, []); + + const display = useMemo(() => { + return hljs.highlight(code.replace(/\n\n/g, "\n"), { + language: lang || "bash", + }); + }, [code]); + + const renderCode = () => { + return ( +
+                    
+                  
+ ); + }; + + return ( + + + + + + + + + + {renderCode()} + + + + ); + }, ApiTable, Suspense, code: (props) => { From 85cd97baf841cb62d7d251138663142daa0c1847 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:14:42 +0800 Subject: [PATCH 05/10] v0.10.1-beta2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b2c2d9d..1c46a21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blizzbolts/docit", - "version": "0.10.1-beta1", + "version": "0.10.1-beta2", "license": "MIT", "bin": { "docit": "bin/docit.js" From 1d8ca5bb201403049843bbf849ce8670988f06d0 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:33:35 +0800 Subject: [PATCH 06/10] feat: exclude @mdx-js/react from vite pre-bundling --- src/node/plugins/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node/plugins/index.ts b/src/node/plugins/index.ts index 10a7278..d88b3ff 100644 --- a/src/node/plugins/index.ts +++ b/src/node/plugins/index.ts @@ -36,6 +36,7 @@ export const docit = async (config: ResolvedUserConfig): Promise => { "highlight.js", "qrcode", ], + exclude: ["@mdx-js/react"], }, build: { outDir: path.resolve(process.cwd(), "./docs-dist"), From 213ced17b4fb0dd87ff14ee67d047f41e59f5566 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:36:43 +0800 Subject: [PATCH 07/10] feat: exclude @mdx-js/react from vite pre-bundling --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de032e2..59d5171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support Chinese as Route path with `encodeURI` - Change built-in components to default export +- exclude @mdx-js/react from vite pre-bundling + ## [0.10.0] - 2022-07-06 From f520e400a1952b617490edb688388ea74d8e52cd Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:38:50 +0800 Subject: [PATCH 08/10] v0.10.1-beta3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1c46a21..f0b361a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blizzbolts/docit", - "version": "0.10.1-beta2", + "version": "0.10.1-beta3", "license": "MIT", "bin": { "docit": "bin/docit.js" From 5e409978578f60cf16061ceea55c25108fe7f516 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:43:10 +0800 Subject: [PATCH 09/10] feat: change ShowCode to outside Component --- CHANGELOG.md | 2 - src/client/built-in/ApiTable/index.tsx | 2 +- src/client/built-in/ShowCode/index.tsx | 2 +- src/client/components/Document/index.tsx | 80 +----------------------- 4 files changed, 5 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59d5171..81e6ac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,10 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Support Chinese as Route path with `encodeURI` -- Change built-in components to default export - exclude @mdx-js/react from vite pre-bundling - ## [0.10.0] - 2022-07-06 ### Changed diff --git a/src/client/built-in/ApiTable/index.tsx b/src/client/built-in/ApiTable/index.tsx index 1186f3e..9ef7ebb 100644 --- a/src/client/built-in/ApiTable/index.tsx +++ b/src/client/built-in/ApiTable/index.tsx @@ -123,4 +123,4 @@ const ApiTable: React.FC = (props) => { ); }; -export default ApiTable; +export { ApiTable }; diff --git a/src/client/built-in/ShowCode/index.tsx b/src/client/built-in/ShowCode/index.tsx index df49937..490bf82 100644 --- a/src/client/built-in/ShowCode/index.tsx +++ b/src/client/built-in/ShowCode/index.tsx @@ -75,4 +75,4 @@ const ShowCode: React.FC = (props) => { ); }; -export default ShowCode; +export { ShowCode }; diff --git a/src/client/components/Document/index.tsx b/src/client/components/Document/index.tsx index 1f6b738..4dcbc11 100644 --- a/src/client/components/Document/index.tsx +++ b/src/client/components/Document/index.tsx @@ -1,20 +1,11 @@ import React, { Suspense, useEffect, useMemo, useRef, useState } from "react"; import { MDXProvider } from "@mdx-js/react"; import { StyledMarkdown, StyledDocument } from "./styled"; -import ApiTable from "../../built-in/ApiTable"; +import { ApiTable } from "../../built-in/ApiTable"; +import { ShowCode } from "../../built-in/ShowCode"; import { useAnchors } from "../../hooks/useAnchors"; import { Toc } from "../Toc"; -import hljs from "highlight.js"; -import { - StyledRenderWindow, - StyledShowCodeContainer, - StyledButtonContainer, - StyledCodeWindow, -} from "../../built-in/ShowCode/styled"; -import { Loading } from "../../components/Loading"; -import sandboxes from "virtual:sandboxes"; - const Document: React.FC = (props) => { const { children } = props; useAnchors(); @@ -24,72 +15,7 @@ const Document: React.FC = (props) => { { - const { code, lang, mobileView, moduleId } = props; - - const ComponentRef = useRef(() => <>); - const [isLoading, setIsLoading] = useState(false); - const [isShowing, setIsShowing] = useState(false); - const [_, update] = useState({}); - - useEffect(() => { - if (sandboxes[moduleId] && !mobileView) { - setIsLoading(true); - sandboxes[moduleId]() - .then((res) => { - const { default: Component } = res; - ComponentRef.current = Component; - update({}); - }) - .finally(() => { - setIsLoading(false); - }); - } - }, []); - - const display = useMemo(() => { - return hljs.highlight(code.replace(/\n\n/g, "\n"), { - language: lang || "bash", - }); - }, [code]); - - const renderCode = () => { - return ( -
-                    
-                  
- ); - }; - - return ( - - - - - - - - - - {renderCode()} - - - - ); - }, + ShowCode, ApiTable, Suspense, code: (props) => { From c0c2f3642a91739d601f8e9f59a6bcafea445955 Mon Sep 17 00:00:00 2001 From: phshy0607 Date: Thu, 7 Jul 2022 11:44:50 +0800 Subject: [PATCH 10/10] v0.10.1-beta4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0b361a..fb18f19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blizzbolts/docit", - "version": "0.10.1-beta3", + "version": "0.10.1-beta4", "license": "MIT", "bin": { "docit": "bin/docit.js"