Skip to content

Commit c54a65c

Browse files
committed
website: update code preview.
1 parent 0204f98 commit c54a65c

File tree

13 files changed

+178
-210
lines changed

13 files changed

+178
-210
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
windows:
1111
runs-on: windows-2019
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-node@v2
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
1515
with:
16-
node-version: 14
16+
node-version: 16
1717

1818
- name: Look Changelog
1919
uses: jaywcjlove/changelog-generator@v1.4.8
@@ -23,18 +23,17 @@ jobs:
2323
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
2424

2525
- run: npm install --unsafe-perm
26-
- run: npm run hoist
2726
- run: npm run build
2827
- run: npm run coverage
2928
- run: npm run doc
3029

3130
build:
3231
runs-on: ubuntu-18.04
3332
steps:
34-
- uses: actions/checkout@v2
35-
- uses: actions/setup-node@v2
33+
- uses: actions/checkout@v3
34+
- uses: actions/setup-node@v3
3635
with:
37-
node-version: 14
36+
node-version: 16
3837

3938
- name: Look Changelog
4039
uses: jaywcjlove/changelog-generator@v1.4.8
@@ -43,8 +42,7 @@ jobs:
4342
filter-author: (小弟调调™|Renovate Bot|renovate-bot)
4443
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
4544

46-
- run: npm install --unsafe-perm
47-
- run: npm run hoist
45+
- run: npm install
4846
- run: npm run build
4947
- run: npm run bundle
5048
- run: npm run bundle:min
@@ -75,7 +73,7 @@ jobs:
7573

7674
# - name: get tag version
7775
# id: tag_version
78-
# uses: jaywcjlove/changelog-generator@v1.5.0
76+
# uses: jaywcjlove/changelog-generator@v1.5.3
7977

8078
# - name: Deploy
8179
# uses: peaceiris/actions-gh-pages@v3
@@ -86,7 +84,7 @@ jobs:
8684

8785
# - name: Generate Changelog
8886
# id: changelog
89-
# uses: jaywcjlove/changelog-generator@v1.5.0
87+
# uses: jaywcjlove/changelog-generator@v1.5.3
9088
# if: steps.create_tag.outputs.successful
9189
# with:
9290
# head-ref: ${{ steps.create_tag.outputs.version }}

core/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
<!--rehype:ignore:start-->
12
Layout
23
===
4+
<!--rehype:ignore:end-->
35

46
[![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-layout.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-layout)
57
[![Build & Deploy](https://github.com/uiwjs/react-layout/actions/workflows/ci.yml/badge.svg)](https://github.com/uiwjs/react-layout/actions/workflows/ci.yml)
@@ -29,8 +31,7 @@ Layout.Footer = LayoutFooter
2931

3032
## Basic Usage
3133

32-
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true&noScroll=true-->
33-
```jsx
34+
```jsx mdx:preview
3435
import React from 'react';
3536
import ReactDOM from 'react-dom';
3637
import Layout, { LayoutHeader, LayoutContent, LayoutSider, LayoutFooter } from '@uiw/react-layout';
@@ -79,8 +80,7 @@ export default Demo;
7980

8081
## Layout top-middle-bottom
8182

82-
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true&noScroll=true-->
83-
```jsx
83+
```jsx mdx:preview
8484
import React from 'react';
8585
import ReactDOM from 'react-dom';
8686
import Layout from '@uiw/react-layout';
@@ -105,8 +105,7 @@ export default Demo;
105105

106106
## Layout left-right
107107

108-
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true&noScroll=true-->
109-
```jsx
108+
```jsx mdx:preview
110109
import React from 'react';
111110
import ReactDOM from 'react-dom';
112111
import Layout from '@uiw/react-layout';

lerna.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"version": "4.10.1",
3-
"packages": ["website", "core"]
3+
"packages": ["website", "core"],
4+
"useWorkspaces": true
45
}

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
]
4040
},
4141
"license": "MIT",
42+
"workspaces": [
43+
"core",
44+
"website"
45+
],
46+
"engines": {
47+
"node": ">=16.0.0"
48+
},
4249
"devDependencies": {
4350
"@kkt/ncc": "~1.0.8",
4451
"compile-less-cli": "~1.8.11",
@@ -47,6 +54,8 @@
4754
"lint-staged": "~12.3.5",
4855
"prettier": "~2.5.1",
4956
"pretty-quick": "~3.1.3",
57+
"react": "~17.0.2",
58+
"react-dom": "~17.0.2",
5059
"tsbb": "~3.7.0"
5160
}
5261
}

website/.kktrc.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import path from 'path';
2+
import webpack from 'webpack';
23
import { Configuration } from 'webpack';
34
import lessModules from '@kkt/less-modules';
4-
import rawModules from '@kkt/raw-modules';
5+
// import rawModules from '@kkt/raw-modules';
56
import scopePluginOptions from '@kkt/scope-plugin-options';
7+
import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader';
68
import { LoaderConfOptions } from 'kkt';
9+
import pkg from './package.json';
710

811
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
912
conf = lessModules(conf, env, options);
10-
conf = rawModules(conf, env, options);
13+
// conf = rawModules(conf, env, options);
14+
conf = mdCodeModulesLoader(conf);
1115
conf = scopePluginOptions(conf, env, {
1216
...options,
1317
allowedFiles: [path.resolve(process.cwd(), 'README.md'), path.resolve(process.cwd(), 'src')],
1418
});
1519

20+
conf.plugins!.push(
21+
new webpack.DefinePlugin({
22+
VERSION: JSON.stringify(pkg.version),
23+
}),
24+
);
25+
1626
if (env === 'production') {
1727
/** https://github.com/uiwjs/react-code-preview/issues/94 */
1828
conf.module!.exprContextCritical = false;

website/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
"build": "kkt build"
99
},
1010
"dependencies": {
11-
"@uiw/react-code-preview": "~4.0.5",
11+
"@uiw/react-codepen": "~1.0.2",
12+
"@uiw/react-codesandbox": "~1.1.5",
1213
"@uiw/react-github-corners": "~1.5.3",
1314
"@uiw/react-layout": "~4.10.1",
14-
"@uiw/react-markdown-preview": "~3.5.1",
15+
"@uiw/react-markdown-preview": "^4.0.16",
16+
"@wcj/dark-mode": "^1.0.14",
17+
"rehype-ignore": "^1.0.1",
18+
"react-code-preview-layout": "^2.0.3",
1519
"react": "~17.0.2",
1620
"react-dom": "~17.0.2"
1721
},
@@ -21,7 +25,8 @@
2125
"@kkt/scope-plugin-options": "~7.1.1",
2226
"@types/react": "~17.0.39",
2327
"@types/react-dom": "~17.0.13",
24-
"kkt": "~7.1.5"
28+
"kkt": "~7.1.5",
29+
"markdown-react-code-preview-loader": "2.1.2"
2530
},
2631
"eslintConfig": {
2732
"extends": [

website/src/App.module.less

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
.app {
22
padding-bottom: 70px;
3-
background-color: #fff;
3+
}
4+
5+
dark-mode {
6+
position: absolute;
7+
left: 10px;
8+
top: 10px;
49
}
510

611
.header {
7-
background-color: #282c34;
12+
background-color: var(--color-canvas-subtle);
813
min-height: calc(100vh - 80px);
914
display: flex;
1015
flex-direction: column;
1116
align-items: center;
1217
justify-content: center;
1318
padding-bottom: 30px;
1419
text-align: center;
15-
color: white;
1620
sup {
17-
background-color: #ffffff21;
1821
border-radius: 3px;
19-
color: #fff;
2022
font-size: 12px;
2123
padding: 1px 5px;
2224
}
@@ -29,15 +31,14 @@
2931
.info {
3032
font-size: 21px;
3133
max-width: 520px;
32-
color: #969ca7;
3334
}
3435

35-
.markdown {
36-
margin: 0 auto;
37-
text-align: left;
36+
.footer {
3837
max-width: 750px;
39-
overflow: auto;
40-
background-color: #fff;
41-
padding: 16px 20px;
42-
border-radius: 5px;
38+
margin: 0 auto;
39+
text-align: center;
40+
padding-top: 64px;
41+
a + a {
42+
margin-left: 10px;
43+
}
4344
}

website/src/App.tsx

Lines changed: 116 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
import React from 'react';
21
import GitHubCorners from '@uiw/react-github-corners';
3-
import Layout from '@uiw/react-layout';
4-
import Markdown from './Markdown';
2+
import MarkdownPreview from '@uiw/react-markdown-preview';
3+
import { getMetaId, isMeta, getURLParameters } from 'markdown-react-code-preview-loader';
4+
import CodeLayout from 'react-code-preview-layout';
5+
import data from '@uiw/react-layout/README.md';
6+
import pkg from '@uiw/react-layout/package.json';
7+
// import Codepen from '@uiw/react-codepen';
8+
import CodeSandbox from '@uiw/react-codesandbox';
9+
import rehypeIgnore from 'rehype-ignore';
10+
import '@wcj/dark-mode';
511
import styles from './App.module.less';
612
import logo from './logo.svg';
7-
import pkg from '@uiw/react-layout/package.json';
13+
import Footer from './Footer';
14+
import { Fragment } from 'react';
15+
16+
// @ts-ignore
17+
const version = VERSION;
818

919
export default function App() {
1020
return (
1121
<div className={styles.app}>
22+
<dark-mode permanent></dark-mode>
1223
<GitHubCorners fixed target="__blank" zIndex={10} href="https://github.com/uiwjs/react-layout" />
1324
<header className={styles.header}>
1425
<img src={logo} className={styles.logo} alt="react logo" />
@@ -17,15 +28,109 @@ export default function App() {
1728
</h1>
1829
<p className={styles.info}>{pkg.description}</p>
1930
</header>
20-
<Markdown
21-
className={styles.markdown}
22-
path="https://github.com/uiwjs/uiw/tree/master/packages/react-alert/README.md"
23-
dependencies={{ Layout }}
24-
renderPage={async () => {
25-
const md = await import('@uiw/react-layout/README.md');
26-
return md.default;
31+
<MarkdownPreview
32+
style={{ maxWidth: 750, margin: '0 auto', paddingTop: 21 }}
33+
disableCopy={true}
34+
source={data.source}
35+
rehypePlugins={[rehypeIgnore]}
36+
components={{
37+
code: ({ inline, node, ...props }) => {
38+
const { 'data-meta': meta, ...rest } = props as any;
39+
if (inline || !isMeta(meta)) {
40+
return <code {...props} />;
41+
}
42+
const line = node.position?.start.line;
43+
const metaId = getMetaId(meta) || String(line);
44+
const Child = data.components[`${metaId}`];
45+
if (metaId && typeof Child === 'function') {
46+
const code = data.data[metaId].value || '';
47+
const param = getURLParameters(meta);
48+
49+
// const codePenOption = {
50+
// title: `@uiw/react-layout${version} - demo`,
51+
// // includeModule: ['@uiw/react-layout'],
52+
// js: (code || '').replace('_mount_', 'document.getElementById("container")'),
53+
// html: '<div id="container" style="padding: 24px"></div>',
54+
// css_external: `https://unpkg.com/@uiw/react-layout@${version}/dist/layout.min.css`,
55+
// js_external: `https://unpkg.com/react@17.x/umd/react.development.js;https://unpkg.com/react-dom@17.x/umd/react-dom.development.js;https://unpkg.com/classnames@2.2.6/index.js;https://unpkg.com/@uiw/react-layout@${version}/dist/layout.min.js;https://unpkg.com/@uiw/codepen-require-polyfill@1.1.3/index.js`,
56+
// };
57+
const codeSandboxOption = {
58+
files: {
59+
'sandbox.config.json': {
60+
content: `{
61+
"template": "node",
62+
"container": {
63+
"startScript": "start",
64+
"node": "14"
65+
}
66+
}`,
67+
},
68+
'public/index.html': {
69+
content: `<div id="container"></div>`,
70+
},
71+
'src/app.js': {
72+
content: code,
73+
},
74+
'src/index.js': {
75+
content: `import React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './app';\nReactDOM.render(<App />, document.getElementById('container'));`,
76+
},
77+
'.kktrc.js': {
78+
content: `import lessModules from "@kkt/less-modules";\nexport default (conf, env, options) => {\n conf = lessModules(conf, env, options);\n return conf;\n};`,
79+
},
80+
'package.json': {
81+
content: {
82+
name: 'uiw-demo',
83+
description: `uiw v${version} - demo`,
84+
dependencies: {
85+
react: '^17.0.2',
86+
'react-dom': '^17.0.2',
87+
uiw: 'latest',
88+
},
89+
devDependencies: {
90+
'@kkt/less-modules': '~7.1.1',
91+
kkt: '~7.1.5',
92+
},
93+
license: 'MIT',
94+
scripts: {
95+
start: 'kkt start',
96+
build: 'kkt build',
97+
},
98+
browserslist: ['>0.2%', 'not dead', 'not ie <= 11', 'not op_mini all'],
99+
},
100+
},
101+
},
102+
};
103+
104+
return (
105+
<CodeLayout
106+
toolbar={param.title || 'Example'}
107+
code={<code {...rest} />}
108+
text={code}
109+
toolbarExtra={
110+
<Fragment>
111+
{/* <Codepen {...codePenOption}>
112+
<svg viewBox="0 0 1024 1024" width="18" height="18" fill="currentColor">
113+
<path
114+
d="M123.428571 668l344.571429 229.714286v-205.142857L277.142857 565.142857z m-35.428571-82.285714l110.285714-73.714286-110.285714-73.714286v147.428572z m468 312l344.571429-229.714286-153.714286-102.857143-190.857143 127.428572v205.142857z m-44-281.714286l155.428571-104-155.428571-104-155.428571 104zM277.142857 458.857143l190.857143-127.428572V126.285714L123.428571 356z m548.571429 53.142857l110.285714 73.714286V438.285714z m-78.857143-53.142857l153.714286-102.857143-344.571429-229.714286v205.142857z m277.142857-102.857143v312q0 23.428571-19.428571 36.571429l-468 312q-12 7.428571-24.571429 7.428571t-24.571429-7.428571L19.428571 704.571429q-19.428571-13.142857-19.428571-36.571429V356q0-23.428571 19.428571-36.571429L487.428571 7.428571q12-7.428571 24.571429-7.428571t24.571429 7.428571l468 312q19.428571 13.142857 19.428571 36.571429z"
115+
p-id="2071"
116+
/>
117+
</svg>
118+
</Codepen> */}
119+
<CodeSandbox {...codeSandboxOption}>Open in CodeSandbox</CodeSandbox>
120+
</Fragment>
121+
}
122+
>
123+
<Child />
124+
</CodeLayout>
125+
);
126+
}
127+
return <code {...rest} />;
128+
},
27129
}}
28130
/>
131+
<div className={styles.footer}>
132+
<Footer />
133+
</div>
29134
</div>
30135
);
31136
}

website/src/Markdown/Footer.tsx renamed to website/src/Footer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { Fragment } from 'react';
2-
// import { Divider } from 'uiw';
1+
import { Fragment } from 'react';
32

43
export type FooterProps = {
54
path?: string;

0 commit comments

Comments
 (0)