Skip to content

Commit 485a9cb

Browse files
committed
Revert "vue 2 version of "@vue/repl" (#31)"
This reverts commit 65579f9.
1 parent 03bb289 commit 485a9cb

File tree

234 files changed

+551074
-3430
lines changed

Some content is hidden

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

234 files changed

+551074
-3430
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NODE_ENV = development
2+
VUE_APP_PUBLIC_PATH = /

.env.deploy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_ENV = production
2+
VUE_APP_PUBLIC_PATH = /vue-code-view
3+
VUE_APP_ENV = deploy

.env.play

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_ENV = development
2+
VUE_APP_PUBLIC_PATH = /
3+
VUE_APP_ENV = play

.env.production

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_ENV = production
2+
VUE_APP_PUBLIC_PATH = /
3+
VUE_APP_ENV = pub

.eslintignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
src/utils/popper.js
2+
src/utils/date.js
3+
node_modules
4+
lib
5+
coverage
6+
deploy
7+
*.md
8+
*.scss
9+
*.woff
10+
*.ttf
11+
12+
13+
output.js
14+
examples/pages

.eslintrc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true,
5+
},
6+
extends: [
7+
"eslint:recommended",
8+
"plugin:vue/essential",
9+
"@vue/eslint-config-typescript",
10+
"@vue/eslint-config-prettier",
11+
],
12+
parserOptions: {
13+
ecmaVersion: 2020,
14+
parser: "@typescript-eslint/parser",
15+
warnOnUnsupportedTypeScriptVersion: false, // Version of TypeScript not officially supported
16+
},
17+
rules: {
18+
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
19+
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
20+
"no-useless-escape": process.env.NODE_ENV === "production" ? "warn" : "off",
21+
"no-unused-vars": process.env.NODE_ENV === "production" ? "warn" : "off",
22+
},
23+
};

.gitignore

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# Logs
2-
logs
3-
*.log
1+
.DS_Store
2+
node_modules
3+
/dist
4+
/lib/*.html
5+
/lib/*.html.gz
6+
/deploy
7+
8+
# local env files
9+
.env.local
10+
.env.*.local
11+
12+
# Log files
413
npm-debug.log*
514
yarn-debug.log*
615
yarn-error.log*
7-
pnpm-debug.log*
8-
lerna-debug.log*
9-
10-
node_modules
11-
dist
12-
dist-ssr
13-
*.local
16+
*pnpm-debug.log*
1417

1518
# Editor directories and files
16-
.vscode/*
17-
!.vscode/extensions.json
1819
.idea
19-
.DS_Store
20+
.vscode
2021
*.suo
2122
*.ntvs*
2223
*.njsproj

.npmignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 忽略目录
2+
.vscode/
3+
examples/
4+
node_modules/
5+
public/
6+
build/
7+
src/
8+
dist/
9+
deploy/
10+
lib/*.html
11+
lib/*.html.gz
12+
13+
14+
# 忽略指定文件
15+
.browserslistrc
16+
.eslintignore
17+
.prettierignore
18+
.env
19+
.env.*
20+
*.js
21+
*.yml
22+
23+
CHANGELOG.zh-CN.md
24+
INSPIRED.zh-CN.md

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.md
2+
3+
node_modules
4+
lib
5+
output.js

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
endOfLine: 'auto',
3+
};

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: node_js
2+
node_js: 14
3+
install:
4+
- yarn
5+
6+
script: npm run deploy:build
7+
after_script:
8+
- mkdir temp_web
9+
- cd temp_web
10+
- git clone --depth 1 -b gh-pages --single-branch https://${TravisCI_Token}@${GH_REF} && cd vue-code-view
11+
- echo 'copy && commit'
12+
- rm -rf js fonts
13+
- cp -rf ../../deploy/** .
14+
- git config user.name "${U_NAME}"
15+
- git config user.email "${U_EMAIL}"
16+
- git add -A .
17+
- git commit -m ":construction_worker:- Build & Deploy by Travis CI"
18+
- git push origin gh-pages
19+
- echo "DONE, Bye~"
20+
- exit 0

README.md

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,83 @@
1414

1515
English | [简体中文](./README.zh-CN.md)
1616

17-
Vue SFC REPL as a Vue 2.7 component.
17+
A lightweight code interaction component based on `vue 2.x`, which can edit, run and preview the code effect display in real time on the web page.
1818

19-
## 💻 Simple Usage
19+
When reading docs that contain a lot of code, many project docs implement a `render` representation of the sample code via the `markdown loader`, but it is static. When we want to debug code, we generally need to open the local IDE or open online editor websites such as `codepen`, `codesandbox`, and it is also subject to whether the computer has a development environment installed or whether the network connection is smooth.
2020

21-
```vue
22-
<script setup>
23-
import { Repl } from 'vue-code-view'
24-
import 'vue-code-view/style.css'
25-
</script>
21+
So can there be such a component that can support editing code in the page, edit, run and preview the code effect display in real time in the web page?
2622

27-
<template>
28-
<Repl />
29-
</template>
23+
Special thanks to the component [react-code-view](https://github.com/simonguo/react-code-view), based on which the vue version of the component was written! Using this component, you can edit the running code and preview the effect in real time by using the multi-sample code in the `vue` page or the `markdown` document.
24+
25+
## ⚡ Online Demo
26+
27+
![示例][preview-ol-v03]
28+
29+
demo address: <https://andurils.github.io/vue-code-view/#/demo>
30+
31+
`codesandbox` example: [vue-code-view-example](https://codesandbox.io/s/vue-code-view-example-forked-nivmw?fontsize=14&hidenavigation=1&theme=dark)
32+
33+
## ✨ Features
34+
35+
- 💻 Code can be edited online and preview the effect in real time.
36+
- 🎨 Support sample code highlighting, configure themes.
37+
- 🌈 Support `<style>` parsing and rendering.
38+
- 📑 Support `Markdown` file example rendering
39+
40+
## 📦 Install
41+
42+
```bash
43+
npm i vue-code-view
44+
# or
45+
yarn add vue-code-view
46+
```
47+
48+
## 🔨 Configure
49+
50+
Using `vue cli` requires configuration in the `vue.config.js` file, which supports the use of Vue builds that include the runtime compiler.
51+
52+
```javascript
53+
module.exports = {
54+
runtimeCompiler: true,
55+
// or
56+
chainWebpack: (config) => {
57+
config.resolve.alias
58+
.set("vue$", "vue/dist/vue.esm.js");
59+
},
60+
};
3061
```
3162

63+
## 💻 Usage
64+
65+
Components are introduced in the entry file `main.js`, and there is no need to manually introduce styles.
66+
67+
```javascript
68+
import Vue from "vue";
69+
import App from "./App.vue";
70+
import CodeView from "vue-code-view";
71+
72+
Vue.use(CodeView);
73+
74+
new Vue({
75+
router,
76+
store,
77+
render: (h) => h(App),
78+
}).$mount("#app");
79+
```
80+
81+
## 📚 API
82+
83+
### Props
84+
85+
| Property | Description | Type | Default | Version |
86+
| --- | ----- | ---- | ----- | ---- |
87+
| themeMode | code editor theme mode,default `light` | `` \| `dark` | `` | |
88+
| showCode | show the code editor , only `layout` value is `top` takes effect | boolean | false | |
89+
| source | source code | string | - | |
90+
| layout | render view layout | `top` \| `right` \| `left` | `top` | `0.4.0+` |
91+
92+
<!-- ### Events -->
93+
3294
## 📋 Changelog
3395

3496
Detailed changes for each release are documented in the [release notes](./CHANGELOG.zh-CN.md).
@@ -43,4 +105,7 @@ VCV is licensed under the terms of the [MIT License](./LICENSE).
43105

44106
Copyright (c) 2021-present Anduril
45107

108+
[preview-ol]: https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/912bf867ef4c44d3a716e4bf723573ac~tplv-k3u1fbpfcp-watermark.image?
109+
[preview-ol-v01]:https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e056aef106b04752bde86e5bc48434c9~tplv-k3u1fbpfcp-watermark.image?
110+
[preview-ol-v02]:https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4550d42d98084cf99fe333fadb3f5983~tplv-k3u1fbpfcp-watermark.image?
46111
[preview-ol-v03]:https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/987ab9814e314f92a244fdf6510e6224~tplv-k3u1fbpfcp-watermark.image?

api-extractor.json

Lines changed: 0 additions & 56 deletions
This file was deleted.

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ["@vue/cli-plugin-babel/preset"],
3+
};

build/markdown-loader/index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const { escapeBackticks } = require("./util");
2+
const md = require("../markdown");
3+
4+
module.exports = function (source) {
5+
const content = md().render(source);
6+
const startTag = "<!--vcv-demo:";
7+
const startTagLen = startTag.length;
8+
const endTag = ":vcv-demo-->";
9+
const endTagLen = endTag.length;
10+
11+
let componenetsString = "";
12+
let id = 0;
13+
let output = [];
14+
let start = 0;
15+
16+
let commentStart = content.indexOf(startTag);
17+
let commentEnd = content.indexOf(endTag, commentStart + startTagLen);
18+
while (commentStart !== -1 && commentEnd !== -1) {
19+
output.push(content.slice(start, commentStart));
20+
const commentContent = content.slice(
21+
commentStart + startTagLen,
22+
commentEnd
23+
);
24+
const demoComponentName = `vcv${id}`;
25+
// output.push(
26+
// `<template slot="source"><code-viewer :source="${demoComponentName}"></code-viewer></template>`
27+
// ); // 使用slot插槽 运行组件
28+
output.push(
29+
`<template slot="source"><code-viewer :source="${demoComponentName}"></code-viewer></template>`
30+
); // 使用slot插槽 运行组件
31+
// output.push(`<template slot="source"><${demoComponentName} /></template>`); // 使用slot插槽 运行组件
32+
componenetsString += `${demoComponentName}: \`${escapeBackticks(
33+
commentContent
34+
)}\`,`;
35+
36+
id++;
37+
start = commentEnd + endTagLen;
38+
commentStart = content.indexOf(startTag, start);
39+
commentEnd = content.indexOf(endTag, commentStart + startTagLen);
40+
}
41+
42+
let pageScript = "";
43+
if (componenetsString) {
44+
pageScript = `<script>
45+
export default {
46+
name: 'component-doc',
47+
data() {
48+
return {
49+
${componenetsString}
50+
};
51+
},
52+
}
53+
</script>`;
54+
} else if (content.indexOf("<script>") === 0) {
55+
start = content.indexOf("</script>") + "</script>".length;
56+
pageScript = content.slice(0, start);
57+
}
58+
59+
output.push(content.slice(start));
60+
61+
return `
62+
<template>
63+
<section class="markdown-body">
64+
${output.join("")}
65+
</section>
66+
</template>
67+
${pageScript}
68+
`;
69+
};

build/markdown-loader/util.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// eslint-disable-next-line no-useless-escape
2+
var templateStringsEscaper = /\`/g;
3+
4+
// 模板字符串 反引号转义
5+
function escapeBackticks(content) {
6+
return content
7+
.replace(templateStringsEscaper, "<--backticks-->")
8+
.replace(/<\/script>/g, `<\\/script>`);
9+
}
10+
11+
module.exports = {
12+
escapeBackticks,
13+
};

0 commit comments

Comments
 (0)