From 0a8815ff0fcea387b92322f1dc4f9d44a1f3d6e1 Mon Sep 17 00:00:00 2001
From: Muyunyun <328375795@qq.com>
Date: Tue, 2 Apr 2019 17:21:04 +0800
Subject: [PATCH 1/8] feat: temp
---
docs/components/Button/README.md | 14 +++++++-------
docs/routes/components.ts | 4 ++--
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/docs/components/Button/README.md b/docs/components/Button/README.md
index 3acd273..b51b8b3 100644
--- a/docs/components/Button/README.md
+++ b/docs/components/Button/README.md
@@ -2,22 +2,22 @@
基础组件,触发业务逻辑时使用。
+```js
+12345677
+```
+
## 代码示例
:::demo
-
### 简单示例
-
各种类型的按钮
```require
./components/Button/simpleButton.tsx
```
-
:::
## Props
-
-| 参数 | 说明 | 类型 | 可选值 | 默认值 |
-| --------- | -------- | ------ | ------ | ------ |
-| className | 按钮类名 | string | - | - |
+| 参数 | 说明 | 类型 | 可选值 | 默认值 |
+| -------- | ----------------- | ------ | ------ | ------ |
+| className | 按钮类名 | string | - | - |
diff --git a/docs/routes/components.ts b/docs/routes/components.ts
index 9356809..b7e4351 100644
--- a/docs/routes/components.ts
+++ b/docs/routes/components.ts
@@ -3,12 +3,12 @@ export default [
key: 'button',
name: '按钮',
path: '/app/basic/button',
- component: require('../components/Button/simpleButton').default,
+ component: require('../components/Button').default,
},
{
key: 'breadcrumb',
name: '面包屑',
path: '/app/basic/breadcrumb',
- component: require('../components/Breadcrumb/simple').default,
+ component: require('../components/Breadcrumb').default,
},
]
From 0ac0403fb10f9eea9a474a48ba7eec950159f6f0 Mon Sep 17 00:00:00 2001
From: Muyunyun <328375795@qq.com>
Date: Thu, 4 Apr 2019 14:03:08 +0800
Subject: [PATCH 2/8] =?UTF-8?q?feat:=20markdown=20=E4=B8=AD=E5=8F=AF?=
=?UTF-8?q?=E4=BB=A5=E5=B1=95=E7=A4=BA=E7=BB=84=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/about/changeLog.tsx | 4 +-
docs/about/contribution.tsx | 4 +-
docs/about/install.tsx | 4 +-
docs/about/usage.tsx | 4 +-
docs/components/Breadcrumb/index.tsx | 4 +-
docs/components/Button/README.md | 12 +-
docs/components/Button/index.tsx | 6 +-
docs/routes/about.ts | 6 +-
docs/types/index.d.ts | 1 +
package.json | 10 +-
webpack/addImportLoader.js | 173 +++++++++++++++++++++++++++
webpack/docs.config.js | 6 +-
webpack/webpack.dev.conf.js | 8 +-
13 files changed, 220 insertions(+), 22 deletions(-)
create mode 100644 docs/types/index.d.ts
create mode 100644 webpack/addImportLoader.js
diff --git a/docs/about/changeLog.tsx b/docs/about/changeLog.tsx
index fd61ecd..824f932 100644
--- a/docs/about/changeLog.tsx
+++ b/docs/about/changeLog.tsx
@@ -1,6 +1,6 @@
import * as React from 'react'
-import MarkdownEle from '../layout/markdownEle'
+import CHANGELOG from './CHANGELOG.md'
export default function () {
- return
{ButtomDemoCode}
', '')
+
+ return highlight.fixMarkup(highlightedContent)
+ }
+ })
+
+const formatModule = (imports, js, jsx, state, method) => {
+ const moduleText = `
+ ${imports}
+
+ ${js}
+
+ class MarkdownItReactComponent extends React.Component {
+ constructor(props){
+ super(props);
+ this.state = ${state || '{}'};
+ Object.assign(this,props.methods)
+ }
+ handleToggleCode(flag){
+ const state = {};
+ state['showCode' + flag] = !this.state['showCode' + flag];
+ this.setState(state);
+ }
+ handleCopyCode (code) {
+ copy(code)
+ }
+ ${method || ''}
+ render(){
+
+ return (
+
+ ${jsx}
+
+ );
+ }
+ };
+
+ export default MarkdownItReactComponent;`
+
+ return moduleText
+}
+
+const formatOpening = () => `
+
+ `
+
+const formatClosing = () => `
+
+ `
+
+module.exports = function (source) {
+ this.cacheable()
+ // init options
+
+ const _options = loaderUtils.getOptions(this) || {}
+
+ Object.assign(
+ options,
+ _options.markdownItReact ? _options.markdownItReact() : {}
+ )
+
+ const {
+ body,
+ attributes: { imports: importMap }
+ } = frontMatter(source)
+
+ const imports = `import * as React from 'react'; import copy from 'copy-to-clipboard';${importMap}`
+
+ const moduleJS = []
+ const state = ''
+ // 放在这里应该没有问题, 反正是顺序执行的
+ let flag = ''
+
+ md.use(mdContainer, 'demo', {
+ validate: params => params.trim().match(/^demo\s*(.*)$/),
+ render: (tokens, idx) => {
+ // container 从开头到结尾把之间的token跑一遍,其中idx定位到具体的位置
+
+ // 获取描述
+ const m = tokens[idx].info.trim().match(/^demo\s*(.*)$/)
+
+ // 有此标记代表 ::: 开始
+ if (tokens[idx].nesting === 1) {
+ flag = idx
+
+ let codeText = ''
+ // let state = null
+ // let method = ''
+ let i = 1
+
+ // 从 ::: 下一个token开始
+ let token = tokens[idx + i]
+
+ // 如果没有到结尾
+ while (token.markup !== ':::') {
+ // 只认```,其他忽略
+ if (token.markup === '```') {
+ // 里面的内容都当代码文本输出
+ codeText = token.content
+ }
+ i++
+ token = tokens[idx + i]
+ }
+ // 描述也执行md
+ return formatOpening(codeText, md.render(m[1]), flag)
+ }
+ return formatClosing(flag)
+ }
+ })
+
+ // md 处理过后的字符串含有 class 和 style ,需要再次处理给到react
+ const content = md
+ .render(body)
+ .replace(/
/g, '
')
+ .replace(/
/g, '
')
+ .replace(/class=/g, 'className=')
+ .replace(/style="text-align:center"/g, 'style={{ textAlign: "center"}}')
+ .replace(/style="text-align:left"/g, 'style={{ textAlign: "left"}}')
+ .replace(/style="text-align:right"/g, 'style={{ textAlign: "right"}}')
+ return formatModule(imports, moduleJS.join('\n'), content, state)
+}
diff --git a/webpack/docs.config.js b/webpack/docs.config.js
index 3619fac..60db070 100644
--- a/webpack/docs.config.js
+++ b/webpack/docs.config.js
@@ -45,9 +45,13 @@ module.exports = {
loader: require.resolve('ts-loader'),
exclude: /node_modules/
},
+ // {
+ // test: /\.md$/,
+ // loader: require.resolve('raw-loader')
+ // },
{
test: /\.md$/,
- loader: require.resolve('raw-loader')
+ loader: `babel-loader!${path.join(__dirname, './addImportLoader.js')}`
},
{
test: /\.css$/,
diff --git a/webpack/webpack.dev.conf.js b/webpack/webpack.dev.conf.js
index 229a681..fc30b14 100644
--- a/webpack/webpack.dev.conf.js
+++ b/webpack/webpack.dev.conf.js
@@ -41,12 +41,16 @@ module.exports = {
rules: [
{
test: /\.tsx?$/,
- loader: require.resolve('ts-loader'),
+ loader: 'awesome-typescript-loader',
exclude: /node_modules/
},
+ // {
+ // test: /\.md$/,
+ // loader: require.resolve('raw-loader')
+ // },
{
test: /\.md$/,
- loader: require.resolve('raw-loader')
+ loader: `babel-loader!${path.join(__dirname, './addImportLoader.js')}`
},
{
test: /\.css$/,
From e8a187c525430b733a4eaae70f1775a3b42066e1 Mon Sep 17 00:00:00 2001
From: Muyunyun <328375795@qq.com>
Date: Thu, 4 Apr 2019 14:38:45 +0800
Subject: [PATCH 3/8] =?UTF-8?q?feat:=20snake-design=20=E6=A0=B7=E5=BC=8F?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/components/Breadcrumb/README.md | 19 +-
docs/components/Button/README.md | 17 +-
docs/layout/docs.scss | 147 ++++++
docs/layout/index.tsx | 3 +-
docs/layout/prism/index.tsx | 20 +
docs/layout/prism/prism.js | 641 +++++++++++++++++++++++++++
docs/layout/prism/prism.scss | 187 ++++++++
docs/types/index.d.ts | 3 +-
package.json | 2 +
9 files changed, 1022 insertions(+), 17 deletions(-)
create mode 100644 docs/layout/docs.scss
create mode 100644 docs/layout/prism/index.tsx
create mode 100644 docs/layout/prism/prism.js
create mode 100644 docs/layout/prism/prism.scss
diff --git a/docs/components/Breadcrumb/README.md b/docs/components/Breadcrumb/README.md
index cbbf08e..23342c2 100644
--- a/docs/components/Breadcrumb/README.md
+++ b/docs/components/Breadcrumb/README.md
@@ -1,18 +1,25 @@
+---
+imports:
+ import ButtomDemoCode from '!raw-loader!./simple.tsx';
+ import BreadCrumbDemo from './simple.tsx';
+ import Code from '../../layout/prism/index'
+---
+
# Breadcrumb 面包屑
导航类组件,便于在几个关联页面之间快速跳转
-## 代码示例
+### 简单示例
:::demo
+各种类型的按钮
-### 简单示例
+
+:::
-```require
-./components/Breadcrumb/simple.tsx
-```
+## 代码示例
-:::
+{ButtomDemoCode}
## Props
diff --git a/docs/components/Button/README.md b/docs/components/Button/README.md
index 77a4863..0df7dc5 100644
--- a/docs/components/Button/README.md
+++ b/docs/components/Button/README.md
@@ -2,28 +2,27 @@
imports:
import ButtomDemoCode from '!raw-loader!./simpleButton.tsx';
import ButtomDemo from './simpleButton.tsx';
+ import Code from '../../layout/prism/index'
---
# Button 按钮
基础组件,触发业务逻辑时使用。
-```js
-12345677
-```
-
-## 代码示例
-
-{ButtomDemoCode}
+### 简单示例
:::demo
-### 简单示例
各种类型的按钮
:::
+## 代码示例
+
+{ButtomDemoCode}
+
## Props
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| -------- | ----------------- | ------ | ------ | ------ |
-| className | 按钮类名 | string | - | - |
+| className | `按钮类名` | string | - | - |
+| className | `按钮类名` | string | - | - |
diff --git a/docs/layout/docs.scss b/docs/layout/docs.scss
new file mode 100644
index 0000000..7e1e8ce
--- /dev/null
+++ b/docs/layout/docs.scss
@@ -0,0 +1,147 @@
+@import '~highlight.js/styles/atom-one-light.css';
+@import '~at-ui-style/src/variables/index.scss';
+@import '~at-ui-style/src/mixins/index.scss';
+
+/* markdown */
+.at-markdown {
+ position: relative;
+ padding: 32px 48px 48px;
+ height: 100%;
+ overflow: auto;
+
+ &--demo {
+ padding-right: 420px;
+ }
+
+ img {
+ vertical-align: middle;
+ }
+
+ table {
+ width: 100%;
+ background-color: #fff;
+ color: #5e6d82;
+ font-size: 14px;
+ // margin-bottom: 45px;
+ border-collapse: collapse;
+ overflow: auto;
+ -webkit-overflow-scrolling: touch;
+
+ th {
+ text-align: left;
+ border-top: 1px solid $border-color-lightest;
+ background-color: #fafbfc;
+ }
+
+ td,
+ th {
+ border-bottom: 1px solid $border-color-lightest;
+ padding: 10px 8px;
+
+ &:first-child {
+ padding-left: 10px;
+ }
+ }
+ }
+
+ >div {
+ margin: 0 auto;
+
+ >h1,
+ >h2,
+ >h3,
+ >h4 {
+ margin: 16px 0;
+ line-height: 1.5;
+ }
+
+ >h1 {
+ margin-top: 0;
+ font-size: 24px;
+ }
+
+ >h2,
+ >h3 {
+ margin-top: 24px;
+ }
+
+ >hr {
+ margin: 1.2em 0;
+ border: 0;
+ border-bottom: 1px solid $border-color-base;
+ }
+
+ >p {
+ padding: 0;
+ line-height: 1.7;
+
+ +p {
+ margin-top: 8px;
+ }
+ }
+
+ code {
+ // padding: 0.3em 0.5em;
+ // font-size: 0.9em;
+ // vertical-align: middle;
+ // border: 1px solid $grey-100;
+ // border-radius: 2px;
+ // background-color: $grey-50;
+ //@at-root
+ padding: 3px;
+ // padding-top: 0.2em;
+ // padding-bottom: 0.2em;
+ margin: 0;
+ font-size: 85%;
+ // background-color: rgba(0,0,0,0.04);
+ border-radius: 3px;
+ background: rgba(255, 229, 100, 0.2);
+ color: #ffa7c4;
+ padding-top: 4px;
+ font-style: italic;
+ font-weight: bold;
+ }
+
+ pre {
+ margin: 16px 0;
+ padding: 16px;
+ background-color: #011627;
+ overflow: auto;
+ border-radius: 4px;
+
+ code {
+ padding: 0;
+ font-size: 1em;
+ border: none;
+ border-radius: 0;
+ background-color: transparent;
+ color: #ffa7c4;
+ }
+ }
+
+ >blockquote {
+ margin: 16px 0;
+ padding: 0 15px;
+ color: $grey-400;
+ border-left: 4px solid $grey-100;
+
+ p {
+ color: $grey-900;
+ }
+ }
+
+ >ul {
+ margin: 16px 0;
+ padding-left: 24px;
+ list-style: disc;
+
+ li {
+ line-height: 1.8;
+ }
+ }
+
+ >table {
+ margin: 24px 0;
+ }
+ }
+}
\ No newline at end of file
diff --git a/docs/layout/index.tsx b/docs/layout/index.tsx
index a057564..5af29df 100644
--- a/docs/layout/index.tsx
+++ b/docs/layout/index.tsx
@@ -1,6 +1,7 @@
import * as React from 'react'
import { Link } from 'react-router-dom'
import DocsNav from './docsNav'
+import './docs.scss'
export default class App extends React.Component {
@@ -25,7 +26,7 @@ export default class App extends React.Component {
basicCList={this.props.basicCList}
aboutSnakeDesignList={this.props.aboutSnakeDesignList}
/>
- {children}
+ {children}
]
diff --git a/docs/layout/prism/index.tsx b/docs/layout/prism/index.tsx
new file mode 100644
index 0000000..5e4ae8d
--- /dev/null
+++ b/docs/layout/prism/index.tsx
@@ -0,0 +1,20 @@
+import * as React from 'react'
+import { PrismCode } from 'react-prism'
+import './prism'
+import './prism.scss'
+
+class Code extends React.Component {
+ render() {
+ const { children } = this.props
+
+ return (
+
+
+ {children}
+
+
+ )
+ }
+}
+
+export default Code
diff --git a/docs/layout/prism/prism.js b/docs/layout/prism/prism.js
new file mode 100644
index 0000000..50ab8fc
--- /dev/null
+++ b/docs/layout/prism/prism.js
@@ -0,0 +1,641 @@
+/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+css+clike+javascript+json+jsx&plugins=previewer-base */
+var _self =
+ 'undefined' != typeof window
+ ? window
+ : 'undefined' != typeof WorkerGlobalScope &&
+ self instanceof WorkerGlobalScope
+ ? self
+ : {},
+ Prism = (function() {
+ var e = /\blang(?:uage)?-(\w+)\b/i,
+ t = 0,
+ n = (_self.Prism = {
+ manual: _self.Prism && _self.Prism.manual,
+ util: {
+ encode: function(e) {
+ return e instanceof a
+ ? new a(e.type, n.util.encode(e.content), e.alias)
+ : 'Array' === n.util.type(e)
+ ? e.map(n.util.encode)
+ : e
+ .replace(/&/g, '&')
+ .replace(/ e.length) return
+ if (!(w instanceof s)) {
+ h.lastIndex = 0
+ var _ = h.exec(w),
+ P = 1
+ if (!_ && m && b != t.length - 1) {
+ if (((h.lastIndex = k), (_ = h.exec(e)), !_)) break
+ for (
+ var A = _.index + (d ? _[1].length : 0),
+ j = _.index + _[0].length,
+ x = b,
+ O = k,
+ S = t.length;
+ S > x && (j > O || (!t[x].type && !t[x - 1].greedy));
+ ++x
+ )
+ (O += t[x].length), A >= O && (++b, (k = O))
+ if (t[b] instanceof s || t[x - 1].greedy) continue
+ ;(P = x - b), (w = e.slice(k, O)), (_.index -= k)
+ }
+ if (_) {
+ d && (p = _[1].length)
+ var A = _.index + p,
+ _ = _[0].slice(p),
+ j = A + _.length,
+ N = w.slice(0, A),
+ C = w.slice(j),
+ E = [b, P]
+ N && (++b, (k += N.length), E.push(N))
+ var L = new s(u, f ? n.tokenize(_, f) : _, y, _, m)
+ if (
+ (E.push(L),
+ C && E.push(C),
+ Array.prototype.splice.apply(t, E),
+ 1 != P && n.matchGrammar(e, t, a, b, k, !0, u),
+ l)
+ )
+ break
+ } else if (l) break
+ }
+ }
+ }
+ }
+ },
+ tokenize: function(e, t) {
+ var a = [e],
+ r = t.rest
+ if (r) {
+ for (var i in r) t[i] = r[i]
+ delete t.rest
+ }
+ return n.matchGrammar(e, a, t, 0, 0, !1), a
+ },
+ hooks: {
+ all: {},
+ add: function(e, t) {
+ var a = n.hooks.all
+ ;(a[e] = a[e] || []), a[e].push(t)
+ },
+ run: function(e, t) {
+ var a = n.hooks.all[e]
+ if (a && a.length) for (var r, i = 0; (r = a[i++]); ) r(t)
+ }
+ }
+ }),
+ a = (n.Token = function(e, t, n, a, r) {
+ ;(this.type = e),
+ (this.content = t),
+ (this.alias = n),
+ (this.length = 0 | (a || '').length),
+ (this.greedy = !!r)
+ })
+ if (
+ ((a.stringify = function(e, t, r) {
+ if ('string' == typeof e) return e
+ if ('Array' === n.util.type(e))
+ return e
+ .map(function(n) {
+ return a.stringify(n, t, e)
+ })
+ .join('')
+ var i = {
+ type: e.type,
+ content: a.stringify(e.content, t, r),
+ tag: 'span',
+ classes: ['token', e.type],
+ attributes: {},
+ language: t,
+ parent: r
+ }
+ if (
+ ('comment' == i.type && (i.attributes.spellcheck = 'true'), e.alias)
+ ) {
+ var l = 'Array' === n.util.type(e.alias) ? e.alias : [e.alias]
+ Array.prototype.push.apply(i.classes, l)
+ }
+ n.hooks.run('wrap', i)
+ var o = Object.keys(i.attributes)
+ .map(function(e) {
+ return (
+ e + '="' + (i.attributes[e] || '').replace(/"/g, '"') + '"'
+ )
+ })
+ .join(' ')
+ return (
+ '<' +
+ i.tag +
+ ' class="' +
+ i.classes.join(' ') +
+ '"' +
+ (o ? ' ' + o : '') +
+ '>' +
+ i.content +
+ '' +
+ i.tag +
+ '>'
+ )
+ }),
+ !_self.document)
+ )
+ return _self.addEventListener
+ ? (_self.addEventListener(
+ 'message',
+ function(e) {
+ var t = JSON.parse(e.data),
+ a = t.language,
+ r = t.code,
+ i = t.immediateClose
+ _self.postMessage(n.highlight(r, n.languages[a], a)),
+ i && _self.close()
+ },
+ !1
+ ),
+ _self.Prism)
+ : _self.Prism
+ var r =
+ document.currentScript ||
+ [].slice.call(document.getElementsByTagName('script')).pop()
+ return (
+ r &&
+ ((n.filename = r.src),
+ !document.addEventListener ||
+ n.manual ||
+ r.hasAttribute('data-manual') ||
+ ('loading' !== document.readyState
+ ? window.requestAnimationFrame
+ ? window.requestAnimationFrame(n.highlightAll)
+ : window.setTimeout(n.highlightAll, 16)
+ : document.addEventListener('DOMContentLoaded', n.highlightAll))),
+ _self.Prism
+ )
+ })()
+'undefined' != typeof module && module.exports && (module.exports = Prism),
+ 'undefined' != typeof global && (global.Prism = Prism)
+;(Prism.languages.markup = {
+ comment: //,
+ prolog: /<\?[\s\S]+?\?>/,
+ doctype: //i,
+ cdata: //i,
+ tag: {
+ pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\s\S])*\1|[^\s'">=]+))?)*\s*\/?>/i,
+ inside: {
+ tag: {
+ pattern: /^<\/?[^\s>\/]+/i,
+ inside: { punctuation: /^<\/?/, namespace: /^[^\s>\/:]+:/ }
+ },
+ 'attr-value': {
+ pattern: /=(?:('|")[\s\S]*?(\1)|[^\s>]+)/i,
+ inside: { punctuation: /[=>"']/ }
+ },
+ punctuation: /\/?>/,
+ 'attr-name': {
+ pattern: /[^\s>\/]+/,
+ inside: { namespace: /^[^\s>\/:]+:/ }
+ }
+ }
+ },
+ entity: /?[\da-z]{1,8};/i
+}),
+ (Prism.languages.markup.tag.inside['attr-value'].inside.entity =
+ Prism.languages.markup.entity),
+ Prism.hooks.add('wrap', function(a) {
+ 'entity' === a.type &&
+ (a.attributes.title = a.content.replace(/&/, '&'))
+ }),
+ (Prism.languages.xml = Prism.languages.markup),
+ (Prism.languages.html = Prism.languages.markup),
+ (Prism.languages.mathml = Prism.languages.markup),
+ (Prism.languages.svg = Prism.languages.markup)
+;(Prism.languages.css = {
+ comment: /\/\*[\s\S]*?\*\//,
+ atrule: { pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i, inside: { rule: /@[\w-]+/ } },
+ url: /url\((?:(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
+ selector: /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
+ string: {
+ pattern: /("|')(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
+ greedy: !0
+ },
+ property: /(\b|\B)[\w-]+(?=\s*:)/i,
+ important: /\B!important\b/i,
+ function: /[-a-z0-9]+(?=\()/i,
+ punctuation: /[(){};:]/
+}),
+ (Prism.languages.css.atrule.inside.rest = Prism.util.clone(
+ Prism.languages.css
+ )),
+ Prism.languages.markup &&
+ (Prism.languages.insertBefore('markup', 'tag', {
+ style: {
+ pattern: /(