You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2019/11/15 12:10:12 UTC
[incubator-echarts-doc] branch doc-rewrite updated: Add main
content. Optimize option loading.
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch doc-rewrite
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-doc.git
The following commit(s) were added to refs/heads/doc-rewrite by this push:
new faf5046 Add main content. Optimize option loading.
faf5046 is described below
commit faf5046ed11aa18d5d26379ec61f224d4f16654f
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Nov 15 20:09:53 2019 +0800
Add main content. Optimize option loading.
---
package-lock.json | 5 ++
package.json | 1 +
public/option.html | 3 +-
src/App.vue | 16 ++++-
src/DocContent.vue | 92 ++++++++++++++++++++++++
src/DocContentItemCard.vue | 172 +++++++++++++++++++++++++++++++++++++++++++++
src/DocMain.vue | 23 ------
src/DocNav.vue | 68 +++++++++++-------
src/OptionItemCard.vue | 0
src/directive/highlight.js | 13 ++++
src/docHelper.js | 71 ++++++++++++++++---
src/main.js | 4 +-
tool/extractDesc.js | 2 +-
tool/md2json.js | 4 ++
14 files changed, 409 insertions(+), 65 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 7c7ff81..316d1f9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4243,6 +4243,11 @@
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dev": true
},
+ "highlight.js": {
+ "version": "9.16.2",
+ "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.16.2.tgz",
+ "integrity": "sha512-feMUrVLZvjy0oC7FVJQcSQRqbBq9kwqnYE4+Kj9ZjbHh3g+BisiPgF49NyQbVLNdrL/qqZr3Ca9yOKwgn2i/tw=="
+ },
"hmac-drbg": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz",
diff --git a/package.json b/package.json
index 7181607..373a01a 100644
--- a/package.json
+++ b/package.json
@@ -42,6 +42,7 @@
},
"dependencies": {
"element-ui": "^2.12.0",
+ "highlight.js": "^9.16.2",
"vue": "^2.6.10",
"vue-custom-scrollbar": "^1.1.0",
"whatwg-fetch": "^3.0.0"
diff --git a/public/option.html b/public/option.html
index c388b27..45bfbf2 100644
--- a/public/option.html
+++ b/public/option.html
@@ -14,7 +14,8 @@
<script src="js/doc-bundle.js"></script>
<script>
echartsDoc.init('#app', {
- jsonUrl: 'documents/zh/option.json'
+ baseUrl: 'documents/zh/option-parts/',
+ rootName: 'option'
});
</script>
</body>
diff --git a/src/App.vue b/src/App.vue
index 4e08a4b..b49dc37 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -4,7 +4,7 @@
<DocNav></DocNav>
</el-aside>
<el-main>
- <DocMain></DocMain>
+ <DocContent></DocContent>
</el-main>
</el-container>
</template>
@@ -12,19 +12,29 @@
<script>
import DocNav from './DocNav.vue';
-import DocMain from './DocMain.vue';
+import DocContent from './DocContent.vue';
export default {
components: {
DocNav,
- DocMain
+ DocContent
}
};
</script>
<style lang="scss">
+@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
+
.doc-main {
+ // Reset
+ font-family: "Helvetica Neue", "Segoe UI", Tahoma, Arial, "Hiragino Sans GB", STHeiti, "Microsoft Yahei", "WenQuanYi Micro Hei", sans-serif;
+
+ ul {
+ margin: 0;
+ padding: 0;
+ }
+
height: 100%;
.el-aside {
diff --git a/src/DocContent.vue b/src/DocContent.vue
new file mode 100644
index 0000000..84eab45
--- /dev/null
+++ b/src/DocContent.vue
@@ -0,0 +1,92 @@
+<template>
+ <div class="doc-content">
+ <h2>{{pagePath}}</h2>
+ <div class="page-description" v-html="descMap[pagePath]"></div>
+
+ <h3>Properties</h3>
+ <DocContentItemCard
+ v-if="1 <= maxDepth"
+ v-for="child in pageOutline.children"
+ :key="child.path"
+ :node-data="child"
+ :desc-map="descMap"
+ :max-depth="maxDepth"
+ :depth="1"
+ ></DocContentItemCard>
+ </div>
+ </div>
+</template>
+
+<script>
+import {getPageTotalDescAsync, getPageOutlineAsync, getOutlineAsync} from './docHelper';
+import DocContentItemCard from './DocContentItemCard.vue'
+import store from './store';
+
+function getPagePathFromPath(val) {
+ return val.split('.')[0];
+}
+export default {
+ components: {
+ DocContentItemCard
+ },
+
+ data() {
+ return {
+ pagePath: '',
+
+ shared: store,
+
+ maxDepth: Infinity,
+
+ // Outline of this page
+ pageOutline: {},
+
+ descMap: Object.freeze({})
+ }
+ },
+
+ computed: {
+ },
+
+ watch: {
+ 'shared.currentPath'(newVal) {
+ let newPagePath = getPagePathFromPath(newVal);
+ if (newPagePath === this.pagePath) { // Use title as hash.
+ return;
+ }
+ this.pagePath = newPagePath;
+
+ // Fetch components.
+ Promise.all([
+ getPageOutlineAsync(newVal),
+ getPageTotalDescAsync(newVal)
+ ]).then(([pageOutline, descMap]) => {
+ this.pageOutline = Object.freeze(Object.assign({}, pageOutline));
+ this.descMap = Object.freeze(descMap);
+ this.maxDepth = this.pageOutline.isRoot // Root page
+ ? 0 : Infinity
+ });
+ }
+ }
+}
+</script>
+
+
+<style lang="scss">
+.doc-content {
+ h2 {
+ color: #B03A5B;
+ font-size: 34px;
+ border-bottom: 1px solid #ccc;
+ height: 40px;
+ line-height: 40px;
+ margin: 0;
+ }
+
+ h3 {
+ font-weight: normal;
+ color: #999;
+ font-size: 30px;
+ }
+}
+</style>
\ No newline at end of file
diff --git a/src/DocContentItemCard.vue b/src/DocContentItemCard.vue
new file mode 100644
index 0000000..e982feb
--- /dev/null
+++ b/src/DocContentItemCard.vue
@@ -0,0 +1,172 @@
+<template>
+<div class="doc-content-item-card">
+ <h4>
+ <span class="path-parent" v-if="parentPath">{{parentPath}}.</span>
+ <span class="path-base">{{baseName}}</span>
+ </h4>
+
+ <div class="item-description" v-html="desc" v-highlight></div>
+
+ <div class="children" v-if="!isLeaf">
+ <DocContentItemCard
+ v-if="(depth + 1) <= maxDepth && expanded"
+ v-for="child in nodeData.children"
+ :key="child.path"
+ :node-data="child"
+ :desc-map="descMap"
+ :depth="depth + 1"
+ :max-depth="maxDepth"
+ ></DocContentItemCard>
+ </div>
+</div>
+</template>
+
+<script>
+import './directive/highlight';
+
+export default {
+ name: 'DocContentItemCard',
+
+ props: ['nodeData', 'descMap', 'maxDepth', 'depth'],
+
+ data() {
+ return {
+ expanded: false
+ }
+ },
+
+ created() {
+ this.$el
+ },
+
+ computed: {
+ isLeaf() {
+ return !(this.nodeData.children && this.nodeData.children.length);
+ },
+
+ desc() {
+ let parts = this.nodeData.path.split('.');
+ if (parts.length > 1) {
+ // Remove the top page path.
+ // For example: `series-bar.itemStyle` will be `itemStyle`
+ parts = parts.slice(1);
+ }
+ return this.descMap[parts.join('.')];
+ },
+
+ parentPath() {
+ let parts = this.nodeData.path.split('.');
+ parts.pop();
+ return parts.join('.');
+ },
+
+ baseName() {
+ return this.nodeData.path.split('.').pop();
+ }
+ }
+}
+</script>
+
+<style lang="scss">
+
+.doc-content-item-card {
+
+ margin-top: 30px;
+ border-bottom: 1px solid #ddd;
+
+ padding: 15px;
+
+ h4 {
+ margin: 0;
+ padding: 0;
+
+ font-family: Montserrat, sans-serif;
+
+ .path-parent {
+ color: #C592A0;
+ font-size: 16px;
+ padding-right: 20px;
+ padding: 0;
+ font-style: italic;
+ font-weight: normal;
+ }
+ .path-base {
+ color: #B03A5B;
+ font-size: 24px;
+ padding-left: 5px;
+ padding: 0;
+ font-weight: normal;
+ }
+ }
+
+ .item-description {
+ margin: 0;
+ padding: 5px;
+
+ blockquote {
+ font-size: 12px;
+ color: #999;
+
+ p {
+ margin: 0;
+ }
+
+ pre {
+ font-size: 12px;
+ }
+ }
+
+ iframe {
+ border: 1px solid #ccc;
+ }
+
+ p {
+ line-height: 1.7em;
+ margin: 18px 0 0 0;
+ font-size: 14px;
+ }
+ pre {
+ margin: 5px 10px;
+ border-radius: 5px;
+ background-color: #f5f5f5;
+ border: none;
+ padding: 15px;
+ font-size: 13px;
+ }
+
+ .codespan {
+ padding: 2px 4px;
+ font-size: 14px;
+ color: #293C55;
+ background-color: #f9f2f4;
+ border-radius: 4px;
+ }
+
+ code *, code {
+ font-family: Monaco, Consolas, 'Courier New';
+ }
+
+ ul li {
+ list-style: disc;
+ margin: 10px 20px;
+ }
+ ol li {
+ list-style: decimal;
+ }
+
+ a {
+ color: #337ab7;
+ text-decoration: none;
+ margin: 0 3px;
+
+ &:hover {
+ text-decoration: underline;
+ }
+ }
+ }
+
+ .children {
+ padding: 10px;
+ }
+}
+</style>
\ No newline at end of file
diff --git a/src/DocMain.vue b/src/DocMain.vue
deleted file mode 100644
index 7caf6f8..0000000
--- a/src/DocMain.vue
+++ /dev/null
@@ -1,23 +0,0 @@
-<template>
-</template>
-
-<script>
-import {getComponentDescAsync} from './docHelper';
-import store from './store';
-
-export default {
- data() {
- return {
- shared: store
- }
- },
-
- computed: {
-
- }
-}
-</script>
-
-
-<style lang="scss">
-</style>
\ No newline at end of file
diff --git a/src/DocNav.vue b/src/DocNav.vue
index 2836ed2..9ea7fcb 100644
--- a/src/DocNav.vue
+++ b/src/DocNav.vue
@@ -10,7 +10,10 @@
:indent="10"
:expand-on-click-node="false"
:load="loadTreeNode"
- :data="treeData">
+ :data="treeData"
+
+ @current-change="selectNode"
+ >
<div class="doc-nav-item" slot-scope="{ node, data }">
<span>{{ node.expanded ? (data.labelExpanded || data.label) : data.label }}</span>
@@ -28,42 +31,44 @@
import {getOutlineAsync} from './docHelper';
import store from './store';
+function joinPath(a, b, connector) {
+ return a ? (a + connector + b) : b;
+}
+
export function createChildren(currentNode, currentSource) {
function createNode(source, parentNode) {
let childNode = {
- type: source.type || typeof source.default
+ type: source.type || typeof source.default,
+ path: source.path
};
+ childNode.path = source.path;
if (source.arrayItemType) {
- childNode.path = parentNode.path + '-' + source.arrayItemType;
childNode.label = `{type: ${source.arrayItemType}, ...}`;
childNode.labelExpanded = '{';
}
+ // Array also may has properties.
+ else if (source.default != null) {
+ childNode.defaultValue = source.default;
+ // Leave the space to show default value.
+ childNode.label = source.prop + ': ';
+ childNode.leaf = true;
+ }
+ else if (source.isArray) {
+ childNode.label = source.prop + ': [{...}]';
+ childNode.labelExpanded = source.prop + ': [{';
+ }
+ else if (source.isObject) {
+ childNode.label = source.prop + ': {...}';
+ childNode.labelExpanded = source.prop + ': {';
+ }
else {
- childNode.path = parentNode.path + '.' + source.prop;
-
- // Array also may has properties.
- if (source.default != null) {
- childNode.defaultValue = source.default;
- // Leave the space to show default value.
- childNode.label = source.prop + ': ';
- childNode.leaf = true;
- }
- else if (source.isArray) {
- childNode.label = source.prop + ': [{...}]';
- childNode.labelExpanded = source.prop + ': [{';
- }
- else if (source.isObject) {
- childNode.label = source.prop + ': {...}';
- childNode.labelExpanded = source.prop + ': {';
- }
- else {
- childNode.label = source.prop;
- childNode.leaf = true;
- }
+ childNode.label = source.prop;
+ childNode.leaf = true;
}
+ // TODO. A better way to query source. Avoid `ref` and `freeze`
childNode.$source = Object.freeze(source);
return childNode;
@@ -88,7 +93,10 @@ export default {
treeData: [],
+ expandedKeys: [],
+
loading: true,
+
shared: store
}
},
@@ -112,6 +120,10 @@ export default {
else {
resolve([]);
}
+ },
+
+ selectNode(nodeData, node) {
+ this.shared.currentPath = nodeData.path;
}
}
}
@@ -140,7 +152,7 @@ export default {
height: 24px;
}
- &.is-current, &:focus {
+ &.is-current {
&>.el-tree-node__content {
background-color: #B03A5B;
color: #fff;
@@ -150,6 +162,12 @@ export default {
}
}
}
+
+ // &:focus {
+ // &>.el-tree-node__content {
+ // background-color: #B03A5B;
+ // }
+ // }
}
.doc-nav-item {
diff --git a/src/OptionItemCard.vue b/src/OptionItemCard.vue
deleted file mode 100644
index e69de29..0000000
diff --git a/src/directive/highlight.js b/src/directive/highlight.js
new file mode 100644
index 0000000..7391cde
--- /dev/null
+++ b/src/directive/highlight.js
@@ -0,0 +1,13 @@
+import hljs from 'highlight.js/lib/highlight';
+import javascript from 'highlight.js/lib/languages/javascript';
+hljs.registerLanguage('javascript', javascript);
+import 'highlight.js/styles/github-gist.css';
+import Vue from 'vue';
+
+Vue.directive('highlight', {
+ inserted(el) {
+ el.querySelectorAll('pre').forEach((block) => {
+ hljs.highlightBlock(block);
+ });
+ }
+});
\ No newline at end of file
diff --git a/src/docHelper.js b/src/docHelper.js
index 374c20d..3e51cc8 100644
--- a/src/docHelper.js
+++ b/src/docHelper.js
@@ -11,6 +11,8 @@ let outlineFetcher;
let descStorage = {};
+let pageOutlines;
+
/**
* Get doc json async
*/
@@ -21,6 +23,38 @@ export function getOutlineAsync() {
return outlineFetcher;
}
+function processOutlines(json) {
+ pageOutlines = {};
+
+ function joinPath(a, b, connector) {
+ return a ? (a + connector + b) : b;
+ }
+ function processNode(node, parentNode) {
+ if (node.arrayItemType) {
+ node.path = joinPath(parentNode.path, node.arrayItemType, '-');
+ }
+ else {
+ node.path = joinPath(parentNode.path, node.prop, '.');
+ }
+ if (node.children) {
+ if (node.path.indexOf('.') < 0) {
+ pageOutlines[node.path] = node;
+ }
+
+ for (let i = 0; i < node.children.length; i++) {
+ processNode(node.children[i], node);
+ }
+ }
+ }
+
+ for (let i = 0; i < json.children.length; i++) {
+ processNode(json.children[i], {});
+ }
+
+ json.isRoot = true;
+
+ return json;
+}
/**
* Preload doc json
*/
@@ -32,26 +66,41 @@ export function preload(_baseUrl, _rootName) {
if (!outlineFetcher) {
outlineFetcher = fetch(outlineUrl)
- .then(response => response.json());
+ .then(response => response.json())
+ .then(_json => processOutlines(_json));
}
return outlineFetcher;
}
-export function extractComponentLevelPath(schemaPath) {
- let parts = schemaPath.split('.');
- let divider = parts.length > 2 ? 2 : 1;
- let componentLevelPath = parts.slice(0, divider).join('.');
- // let subKey = parts.slice(divider).join('.');
-
- return componentLevelPath;
+/**
+ * Get outline of page
+ */
+export function getPageOutlineAsync(targetPath) {
+ let pagePath = targetPath.split('.')[0];
+ return getOutlineAsync().then(() => {
+ return pageOutlines[pagePath]
+ // Use top outline for `option.color`, etc.
+ || getOutlineAsync();
+ });
}
+
+
/**
- * Get description from
+ * Get all description of page.
*/
-export function getComponentDescAsync(schemaPath) {
- let partionKey = extractComponentLevelPath(schemaPath);
+export function getPageTotalDescAsync(targetPath) {
+ if (!pageOutlines) {
+ throw new Error('Outline data is not loaded.');
+ }
+ let pagePath = targetPath.split('.')[0];
+
+ // Configuration like `option.color`, `option.backgroundColor` is in the `option` page.
+ // Configuration like `option.series-bar` is in the `option.series-bar` page.
+ let partionKey = pageOutlines[pagePath]
+ ? rootName + '.' + pagePath
+ : rootName;
if (!descStorage[partionKey]) {
let url = `${baseUrl}/${partionKey}.json`;
diff --git a/src/main.js b/src/main.js
index e442306..fc6d932 100644
--- a/src/main.js
+++ b/src/main.js
@@ -6,7 +6,8 @@ import {
Aside,
Main,
Tree,
- Loading
+ Loading,
+ Divider
} from 'element-ui';
import {preload} from './docHelper';
import 'element-ui/lib/theme-chalk/index.css';
@@ -17,6 +18,7 @@ Vue.use(Aside);
Vue.use(Main);
Vue.use(Tree);
Vue.use(Loading);
+Vue.use(Divider);
/**
*
diff --git a/tool/extractDesc.js b/tool/extractDesc.js
index da022fb..be7587c 100644
--- a/tool/extractDesc.js
+++ b/tool/extractDesc.js
@@ -70,7 +70,7 @@ function convertToTree(rootSchema, rootNode) {
function createArrayItemNode(schema, parentNode) {
let childNode = createNodeBase(schema, parentNode);
if (schema.properties && schema.properties.type && schema.properties.type.default) {
- childNode.arrayItemType = schema.properties.type.default;
+ childNode.arrayItemType = schema.properties.type.default.replace(/'/g, '');
}
else {
throw new Error('Some thing wrong happens', schema);
diff --git a/tool/md2json.js b/tool/md2json.js
index 6b25599..a4f6463 100644
--- a/tool/md2json.js
+++ b/tool/md2json.js
@@ -136,6 +136,10 @@ function mdToJsonSchema(mdStr, maxDepth, imagePath) {
}
};
+ renderer.codespan = function (code) {
+ return '<code class="codespan">' + code + '</code>';
+ };
+
var currentLevel = 0;
var result = {
'$schema': 'https://echarts.apache.org/doc/json-schem',
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org