Skip to content

Commit b97071b

Browse files
committed
finish source code and demo
1 parent b773b0f commit b97071b

23 files changed

+14590
-0
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["env"],
3+
"plugins": ["transform-object-rest-spread"]
4+
}

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/*.js
2+
config/*.js
3+
example/modules/*.js

.eslintrc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
root: true,
3+
parser: 'babel-eslint',
4+
parserOptions: {
5+
sourceType: 'module'
6+
},
7+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
8+
extends: 'standard',
9+
// required to lint *.vue files
10+
plugins: [
11+
'html'
12+
],
13+
// add your custom rules here
14+
'rules': {
15+
// allow debugger during development
16+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
17+
'space-before-function-paren': 0
18+
}
19+
}

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
deploy/
7+
test/unit/coverage
8+
test/e2e/reports
9+
selenium-debug.log
10+
11+
# Test publish files
12+
cube-ui-*.tgz
13+
package/
14+
15+
# Editor directories and files
16+
.idea
17+
.vscode
18+
*.suo
19+
*.ntvs*
20+
*.njsproj
21+
*.sln

.idea/vcs.xml

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

examples/dialog/app.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'babel-polyfill'
2+
import Vue from 'vue'
3+
import App from './components/App.vue'
4+
import Dialog from './components/dialog.vue'
5+
import CreateAPI from 'create-api'
6+
7+
Vue.use(CreateAPI, {
8+
componentPrefix: 'z-'
9+
})
10+
11+
Vue.createAPI(Dialog, true)
12+
13+
Vue.config.debug = true
14+
15+
Dialog.$create({
16+
$props: {
17+
title: 'Hello',
18+
content: 'I am from pure JS'
19+
}
20+
}).show()
21+
22+
new Vue({
23+
el: '#app',
24+
render: h => h(App)
25+
})
26+

examples/dialog/components/App.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div id="app">
3+
<h1>Dialog Demo</h1>
4+
<button @click="show">Show Dialog</button>
5+
<button @click="change">Change content</button>
6+
<child></child>
7+
</div>
8+
</template>
9+
10+
<script>
11+
import Child from './child.vue'
12+
13+
export default {
14+
name: 'App',
15+
data() {
16+
return {
17+
content: 'I am from App'
18+
}
19+
},
20+
components: {Child},
21+
methods: {
22+
show() {
23+
this.dialog = this.dialog || this.$createDialog({
24+
$props: {
25+
title: 'Hello',
26+
content: 'content'
27+
}
28+
})
29+
this.dialog.show()
30+
},
31+
change() {
32+
this.content = 'I am from App and content changed!'
33+
}
34+
}
35+
}
36+
</script>
37+
<style>
38+
</style>

examples/dialog/components/child.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div>
3+
<h1>I am child</h1>
4+
<button @click="show">Show Dialog in child</button>
5+
<button @click="showPure">Show pure JS Dialog in child</button>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import Dialog from './dialog.vue'
11+
12+
export default {
13+
name: 'child',
14+
methods: {
15+
show() {
16+
this.dialog = this.dialog || this.$createDialog({
17+
$props: {
18+
title: 'Hi',
19+
content: 'I am from child'
20+
}
21+
})
22+
this.dialog.show()
23+
},
24+
showPure() {
25+
Dialog.$create({
26+
$props: {
27+
title: 'Hello',
28+
content: 'I am from pure JS in Child'
29+
}
30+
}).show()
31+
}
32+
}
33+
}
34+
</script>
35+
36+
<style>
37+
38+
</style>

examples/dialog/components/dialog.vue

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<template>
2+
<div v-show="visible" class="mask">
3+
<div class="dialog">
4+
<h1 class="title">{{title}}</h1>
5+
<div class="content">{{content}}</div>
6+
<div @click="hide" class="btn">confirm</div>
7+
</div>
8+
</div>
9+
</template>
10+
11+
<script>
12+
export default {
13+
name: 'z-dialog',
14+
props: {
15+
content: {
16+
type: String,
17+
default: 'I am content'
18+
},
19+
title: {
20+
type: String,
21+
default: 'I am title'
22+
}
23+
},
24+
data() {
25+
return {
26+
visible: false
27+
}
28+
},
29+
methods: {
30+
show() {
31+
this.visible = true
32+
},
33+
hide() {
34+
this.visible = false
35+
}
36+
}
37+
}
38+
</script>
39+
<style>
40+
.mask {
41+
position: fixed;
42+
top: 0;
43+
bottom: 0;
44+
left: 0;
45+
right: 0;
46+
z-index: 100;
47+
background: rgba(0, 0, 0, 0.6);
48+
}
49+
50+
.dialog {
51+
position: relative;
52+
top: 50%;
53+
left: 50%;
54+
z-index: 200;
55+
transform: translate(-50%, -50%);
56+
width: 200px;
57+
height: 120px;
58+
text-align: center;
59+
padding: 20px;
60+
background: white;
61+
}
62+
63+
.title {
64+
line-height: 20px;
65+
font-size: 16px;
66+
}
67+
68+
.content {
69+
line-height: 18px;
70+
font-size: 14px;
71+
margin-bottom: 20px;
72+
}
73+
74+
.btn {
75+
width: 100%;
76+
height: 40px;
77+
line-height: 40px;
78+
background: #fc8919;
79+
text-align: center;
80+
font-size: 16px;
81+
}
82+
</style>

examples/dialog/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Dialog example</title>
6+
<link href="http://fonts.googleapis.com/css?family=Muli" rel="stylesheet" type="text/css">
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script src="/__build__/shared.js"></script>
11+
<script src="/__build__/dialog.js"></script>
12+
</body>
13+
</html>

examples/global.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
html, body {
2+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
3+
color: #2c3e50;
4+
}
5+
6+
ul {
7+
line-height: 1.5em;
8+
padding-left: 1.5em;
9+
}
10+
11+
a {
12+
color: #7f8c8d;
13+
text-decoration: none;
14+
}
15+
16+
a:hover {
17+
color: #4fc08d;
18+
}

examples/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>create-api examples</title>
6+
<link rel="stylesheet" href="/global.css">
7+
</head>
8+
<body style="padding: 0 20px">
9+
<h1>create-api examples</h1>
10+
<ul>
11+
<li><a href="dialog">Dialog</a></li>
12+
</ul>
13+
</body>
14+
</html>

examples/server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const express = require('express')
2+
const webpack = require('webpack')
3+
const webpackDevMiddleware = require('webpack-dev-middleware')
4+
const webpackHotMiddleware = require('webpack-hot-middleware')
5+
const WebpackConfig = require('./webpack.config')
6+
7+
const app = express()
8+
const compiler = webpack(WebpackConfig)
9+
10+
app.use(webpackDevMiddleware(compiler, {
11+
publicPath: '/__build__/',
12+
stats: {
13+
colors: true,
14+
chunks: false
15+
}
16+
}))
17+
18+
app.use(webpackHotMiddleware(compiler))
19+
20+
app.use(express.static(__dirname))
21+
22+
const port = process.env.PORT || 8080
23+
module.exports = app.listen(port, () => {
24+
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`)
25+
})

examples/webpack.config.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const webpack = require('webpack')
4+
const VueLoaderPlugin = require('vue-loader/lib/plugin')
5+
6+
module.exports = {
7+
mode: 'development',
8+
9+
entry: fs.readdirSync(__dirname).reduce((entries, dir) => {
10+
const fullDir = path.join(__dirname, dir)
11+
const entry = path.join(fullDir, 'app.js')
12+
if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) {
13+
entries[dir] = ['webpack-hot-middleware/client', entry]
14+
}
15+
16+
return entries
17+
}, {}),
18+
19+
output: {
20+
path: path.join(__dirname, '__build__'),
21+
filename: '[name].js',
22+
chunkFilename: '[id].chunk.js',
23+
publicPath: '/__build__/'
24+
},
25+
26+
module: {
27+
rules: [
28+
{ test: /\.js$/, exclude: /node_modules/, use: ['babel-loader'] },
29+
{ test: /\.vue$/, use: ['vue-loader'] },
30+
{ test: /\.css$/, use: ['vue-style-loader', 'css-loader'] }
31+
]
32+
},
33+
34+
resolve: {
35+
alias: {
36+
'create-api': path.resolve(__dirname, '../src/index.js')
37+
}
38+
},
39+
40+
optimization: {
41+
splitChunks: {
42+
cacheGroups: {
43+
vendors: {
44+
name: 'shared',
45+
filename: 'shared.js',
46+
chunks: 'initial'
47+
}
48+
}
49+
}
50+
},
51+
52+
plugins: [
53+
new VueLoaderPlugin(),
54+
new webpack.HotModuleReplacementPlugin(),
55+
new webpack.NoEmitOnErrorsPlugin()
56+
]
57+
}

0 commit comments

Comments
 (0)