Skip to content

Commit 70c4b91

Browse files
committed
docs: demo & docs
1 parent 14333ec commit 70c4b91

14 files changed

+371
-32
lines changed

docs/.vitepress/theme/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// https://vitepress.dev/guide/custom-theme
2-
import { h } from 'vue'
3-
import type { Theme } from 'vitepress'
4-
import DefaultTheme from 'vitepress/theme'
5-
import './style.css'
2+
import { h } from "vue";
3+
import type { Theme } from "vitepress";
4+
import DefaultTheme from "vitepress/theme";
5+
import "./style.css";
6+
import DemoIframe from "../../components/DemoIframe.vue";
67

78
export default {
89
extends: DefaultTheme,
910
Layout: () => {
1011
return h(DefaultTheme.Layout, null, {
1112
// https://vitepress.dev/guide/extending-default-theme#layout-slots
12-
})
13+
});
1314
},
1415
enhanceApp({ app, router, siteData }) {
1516
// ...
16-
}
17-
} satisfies Theme
17+
app.component("DemoIframe", DemoIframe);
18+
},
19+
} satisfies Theme;

docs/components/DemoIframe.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div>
3+
<iframe :src="fullUrl" />
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
props: {
10+
url: {},
11+
},
12+
computed: {
13+
fullUrl() {
14+
return `${import.meta.env.DEV ? 'http://localhost:3000' : ''}/he-tree-react#${this.url}`
15+
},
16+
},
17+
methods: {},
18+
}
19+
</script>
20+
21+
<style scoped>
22+
iframe {
23+
width: 100%;
24+
border: 0;
25+
min-height: 200px;
26+
}
27+
</style>

docs/markdown-examples.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This page demonstrates some of the built-in markdown extensions provided by Vite
66

77
VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting:
88

9+
<DemoIframe url="/base_tree_data" />
10+
911
**Input**
1012

1113
````md

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
"type-fest": "^4.10.2"
4747
},
4848
"devDependencies": {
49+
"@edge-runtime/vm": "^3.2.0",
4950
"@types/react": "^18.2.43",
5051
"@types/react-dom": "^18.2.17",
52+
"@types/react-test-renderer": "^18.0.7",
5153
"@typescript-eslint/eslint-plugin": "^6.14.0",
5254
"@typescript-eslint/parser": "^6.14.0",
5355
"@unocss/reset": "^0.58.4",
@@ -57,7 +59,9 @@
5759
"eslint": "^8.55.0",
5860
"eslint-plugin-react-hooks": "^4.6.0",
5961
"eslint-plugin-react-refresh": "^0.4.5",
62+
"happy-dom": "^13.6.2",
6063
"jsdom": "^24.0.0",
64+
"react-router-dom": "^6.22.2",
6165
"react-test-renderer": "^18.2.0",
6266
"typescript": "^5.2.2",
6367
"unocss": "^0.58.4",

pnpm-lock.yaml

Lines changed: 78 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import example_data from "./examples/example_data.json";
2-
import { sortFlatData, useHeTree, updateCheckedInFlatData } from "../lib/HeTree";
3-
import { useState } from "react";
4-
import { useImmer } from "use-immer";
1+
import React, { lazy, Suspense } from 'react';
2+
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
3+
54

65
function App() {
76
// const [flatData, setflatData] = useState(() => {

src/PageLayout.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from "react";
2+
export default function PageLayout(props: { children: React.ReactNode }) {
3+
return <div className="page-layout">
4+
{props.children}
5+
<style>{`
6+
body{
7+
margin: 0;
8+
background-color: #fff9e6;
9+
}
10+
`}</style>
11+
</div>
12+
}

src/main.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22
// import '@unocss/reset/tailwind.css'
33
// import '@unocss/reset/tailwind-compat.css'
44
import 'virtual:uno.css'
5-
import React from 'react'
5+
import React, { lazy, Suspense } from 'react';
66
import ReactDOM from 'react-dom/client'
7-
import App from './App.tsx'
7+
import { createHashRouter, RouterProvider } from "react-router-dom";
8+
import PageLayout from './PageLayout.tsx';
9+
10+
// router
11+
const Pages = {
12+
home: lazy(() => import("./pages/index.tsx")),
13+
base_tree_data: lazy(() => import("./pages/base_tree_data.tsx"))
14+
}
15+
const router = createHashRouter([
16+
{
17+
path: "/",
18+
element: <Pages.home />,
19+
},
20+
{
21+
path: "/base_tree_data",
22+
element: <Pages.base_tree_data />,
23+
},
24+
]);
825

926
ReactDOM.createRoot(document.getElementById('root')!).render(
1027
<React.StrictMode>
11-
<App />
28+
{/* <App /> */}
29+
<PageLayout>
30+
<Suspense fallback={<span>loading</span>}>
31+
<RouterProvider router={router} />
32+
</Suspense>
33+
</PageLayout>
1234
</React.StrictMode>,
1335
)

0 commit comments

Comments
 (0)