Skip to content

Commit 4d3e338

Browse files
committed
initialize mirror
0 parents  commit 4d3e338

12 files changed

+376
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
/node_modules
3+
/build
4+
/index.html
5+
/lib

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
/build
3+
/gulpfile.coffee
4+
/webpack.*
5+
/template.cirru
6+
/index.html

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
CoffeeScript Webpack Starter
3+
----
4+
5+
React project tempate at Talk.
6+
7+
Demo http://ui.talk.ai/<project-name>
8+
9+
### Usage
10+
11+
### Develop
12+
13+
```text
14+
npm i
15+
```
16+
17+
You need a static file server for the HTML files. Personally I suggest using Nginx.
18+
19+
Develop:
20+
21+
```bash
22+
gulp html # regenerate index.html
23+
webpack-dev-server --hot # enable live-reloading
24+
```
25+
26+
Build (Pack and optimize js, reivision js and add entry in `index.html`):
27+
28+
```bash
29+
gulp build
30+
```
31+
32+
### License
33+
34+
MIT

gulpfile.coffee

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
gulp = require('gulp')
3+
sequence = require('run-sequence')
4+
exec = require('child_process').exec
5+
env =
6+
dev: true
7+
main: 'http://localhost:8080/build/main.js'
8+
vendor: 'http://localhost:8080/build/vendor.js'
9+
10+
gulp.task 'script', ->
11+
coffee = require('gulp-coffee')
12+
gulp
13+
.src 'src/*.coffee'
14+
.pipe coffee()
15+
.pipe gulp.dest('lib/')
16+
17+
gulp.task 'rsync', (cb) ->
18+
wrapper = require 'rsyncwrapper'
19+
wrapper.rsync
20+
ssh: true
21+
src: ['index.html', 'build']
22+
recursive: true
23+
args: ['--verbose']
24+
dest: 'talk-ui:/teambition/server/talk-ui/react-lite-dropdown'
25+
deleteAll: true
26+
, (error, stdout, stderr, cmd) ->
27+
if error?
28+
throw error
29+
console.error stderr
30+
console.log cmd
31+
cb()
32+
33+
gulp.task 'html', (cb) ->
34+
require('cirru-script/lib/register')
35+
html = require('./template.cirru')
36+
fs = require('fs')
37+
assets = undefined
38+
unless env.dev
39+
assets = require('./build/assets.json')
40+
env.main = './build/' + assets.main
41+
env.vendor = './build/' + assets.vendor
42+
43+
fs.writeFile 'index.html', html(env), cb
44+
45+
gulp.task 'del', (cb) ->
46+
del = require('del')
47+
del [ 'build' ], cb
48+
49+
gulp.task 'webpack', (cb) ->
50+
if env.dev
51+
command = 'webpack'
52+
else
53+
command = 'webpack --config webpack.min.coffee --progress'
54+
exec command, (err, stdout, stderr) ->
55+
console.log stdout
56+
console.log stderr
57+
cb err
58+
59+
gulp.task 'build', (cb) ->
60+
env.dev = false
61+
sequence 'del', 'webpack', 'html', cb

package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "coffee-webpack-starter",
3+
"version": "0.0.1",
4+
"description": "Component starter kit for Talk by Teambition",
5+
"main": "lib/index.js",
6+
"dependencies": {
7+
"classnames": "^1.2.0",
8+
"react": "^0.13.1"
9+
},
10+
"devDependencies": {
11+
"cirru-script": "^0.2.3",
12+
"coffee-loader": "^0.7.2",
13+
"coffee-script": "^1.9.1",
14+
"css-loader": "^0.10.1",
15+
"del": "^1.1.1",
16+
"file-loader": "^0.8.4",
17+
"gulp": "^3.8.11",
18+
"gulp-coffee": "^2.3.1",
19+
"less": "^2.5.1",
20+
"less-loader": "^2.2.0",
21+
"rsyncwrapper": "^0.4.3",
22+
"run-sequence": "^1.0.2",
23+
"stir-template": "^0.1.4",
24+
"style-loader": "^0.10.2",
25+
"url-loader": "^0.5.6",
26+
"volubile-ui": "0.0.10",
27+
"webpack": "^1.8.4",
28+
"webpack-dev-server": "^1.8.0"
29+
},
30+
"scripts": {
31+
"test": "echo \"Error: no test specified\" && exit 1"
32+
},
33+
"keywords": [
34+
"react-component"
35+
],
36+
"author": "Teambition",
37+
"license": "MIT",
38+
"repository": {
39+
"type": "git",
40+
"url": "https://github.com/teambition/coffee-webpack-starter.git"
41+
},
42+
"bugs": {
43+
"url": "https://github.com/teambition/coffee-webpack-starter/issues"
44+
},
45+
"homepage": "https://github.com/teambition/coffee-webpack-starter"
46+
}

src/main.coffee

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
React = require 'react'
3+
4+
require 'volubile-ui/ui/index.less'
5+
6+
Textbox = React.createFactory require './textbox'
7+
div = React.createFactory 'div'
8+
9+
pageComponent = React.createClass
10+
displayName: 'app-page'
11+
12+
getInitialState: ->
13+
text: ''
14+
15+
onChange: (text) ->
16+
@setState text: text
17+
18+
render: ->
19+
20+
div className: 'app-page',
21+
Textbox
22+
text: @state.text, onChange: @onChange
23+
24+
Page = React.createFactory pageComponent
25+
26+
React.render Page(), document.querySelector('.demo')

src/main.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
@import url(textbox.css);

src/textbox.coffee

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
React = require 'react'
3+
4+
div = React.createFactory 'div'
5+
pre = React.createFactory 'pre'
6+
textarea = React.createFactory 'textarea'
7+
8+
module.exports = React.createClass
9+
displayName: 'lite-textbox'
10+
11+
propTypes:
12+
text: React.PropTypes.string.isRequired
13+
onChange: React.PropTypes.func.isRequired
14+
minHeight: React.PropTypes.number
15+
maxHeight: React.PropTypes.number
16+
specials: React.PropTypes.array
17+
18+
getDefaultProps: ->
19+
minHeight: 120
20+
maxHeight: 200
21+
specials: ['@', ':']
22+
23+
getInitialState: ->
24+
contentheight: 20
25+
26+
componentDidMount: ->
27+
@boxEl = @refs.box.getDOMNode()
28+
@preEl = @refs.pre.getDOMNode()
29+
@mirrorStyles()
30+
31+
32+
componentDidUpdate: ->
33+
@mirrorStyles()
34+
35+
getBoxStyles: ->
36+
if @boxEl?
37+
boxStyles = getComputedStyle @boxEl
38+
mirrorStyles = {}
39+
for key, value of boxStyles
40+
continue if key[0] is '-'
41+
continue if key.match /^webkit/
42+
continue if (typeof value) is 'function'
43+
continue if key.match /^\d+$/
44+
mirrorStyles[key] = value
45+
mirrorStyles
46+
else
47+
{}
48+
49+
getHeight: ->
50+
51+
mirrorHeight = @state.contentheight
52+
if @state.contentheight < @props.minHeight
53+
mirrorHeight = @props.minHeight
54+
if @state.contentheight > @props.maxHeight
55+
mirrorHeight = @props.maxHeight
56+
57+
mirrorHeight
58+
59+
mirrorStyles: ->
60+
61+
mirrorHeight = @getHeight()
62+
63+
styles = @getBoxStyles()
64+
styles.height = "#{mirrorHeight}px"
65+
styles.zIndex = -1
66+
for key, value of styles
67+
@preEl.style[key] = value
68+
@preEl.scrollTop = @boxEl.scrollTop
69+
70+
onChange: (event) ->
71+
@props.onChange event.target.value
72+
@setState contentheight: @boxEl.clientHeight
73+
74+
onScroll: ->
75+
@preEl.scrollTop = @boxEl.scrollTop
76+
77+
expandText: ->
78+
@props.text
79+
80+
render: ->
81+
div className: 'lite-textbox',
82+
pre
83+
ref: 'pre', className: 'textbox-mirror'
84+
@expandText()
85+
textarea
86+
ref: 'box', value: @props.text, onChange: @onChange
87+
onScroll: @onScroll, style: {height: @getHeight()}

src/textbox.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
.lite-textbox {
3+
position: relative;
4+
}
5+
6+
.lite-textbox pre {
7+
position: absolute !important;
8+
z-index: -1 !important;
9+
}
10+
.lite-textbox textarea {
11+
width: 100%;
12+
background: transparent;
13+
}

template.cirru

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
var
3+
stir $ require :stir-template
4+
5+
var
6+
(object~ html head title body meta script link div a span) stir
7+
8+
var
9+
line $ \ (text)
10+
return $ div null text
11+
12+
= module.exports $ \ (data)
13+
return $ stir.render
14+
stir.doctype
15+
html null
16+
head null
17+
title null ":Coffee Webpack Starter"
18+
meta $ object (:charset :utf-8)
19+
link $ object (:rel :icon)
20+
:href :http://tp4.sinaimg.cn/5592259015/180/5725970590/1
21+
link $ object (:rel :stylesheet)
22+
:href :src/main.css
23+
script $ object (:src data.vendor) (:defer true)
24+
script $ object (:src data.main) (:defer true)
25+
body null
26+
div
27+
object (:class :intro)
28+
div
29+
object (:class :title)
30+
, ":This is a demo of Webpack usage."
31+
line ":Open Console to see how it loads."
32+
div null
33+
span null ":Read more at "
34+
a
35+
object (:href :http://github.com/teambition/coffee-webpack-starter)
36+
, :github.com/teambition/coffee-webpack-starter
37+
span null :.
38+
div
39+
object (:class :demo)

webpack.config.coffee

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
fs = require('fs')
3+
fontName = 'fonts/[name].[ext]'
4+
webpack = require 'webpack'
5+
6+
module.exports =
7+
entry:
8+
vendor: [
9+
'webpack-dev-server/client?http://0.0.0.0:8080'
10+
'webpack/hot/dev-server'
11+
]
12+
main: [
13+
'./src/main'
14+
]
15+
output:
16+
path: 'build/'
17+
filename: '[name].js'
18+
publicPath: 'http://localhost:8080/build/'
19+
resolve: extensions: ['.js', '.coffee', '']
20+
module:
21+
loaders: [
22+
{test: /\.coffee$/, loader: 'coffee', ignore: /node_modules/}
23+
{test: /\.css$/, loader: 'style!css'}
24+
{test: /\.less$/, loader: 'style!css!less'}
25+
{test: /\.woff((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 100, minetype: 'application/font-woff', name: fontName}}
26+
{test: /\.woff2((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 100, minetype: 'application/font-woff2', name: fontName}}
27+
{test: /\.ttf((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 100, minetype: "application/octet-stream", name: fontName}}
28+
{test: /\.eot((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 100, name: fontName}}
29+
{test: /\.svg((\?|\#)[\?\#\w\d_-]+)?$/, loader: "url", query: {limit: 10000, minetype: "image/svg+xml", name: fontName}}
30+
31+
]
32+
plugins: [
33+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js')
34+
]

webpack.min.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
webpack = require('webpack')
3+
config = require('./webpack.config')
4+
fs = require('fs')
5+
6+
module.exports =
7+
entry:
8+
vendor: []
9+
main: [ './src/main' ]
10+
output:
11+
path: 'build/'
12+
filename: '[name].[chunkhash:8].js'
13+
publicPath: './build/'
14+
resolve: config.resolve
15+
module: config.module
16+
plugins: [
17+
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.[chunkhash:8].js')
18+
new (webpack.optimize.UglifyJsPlugin)(sourceMap: false)
19+
->
20+
@plugin 'done', (stats) ->
21+
content = JSON.stringify(stats.toJson().assetsByChunkName, null, 2)
22+
fs.writeFileSync 'build/assets.json', content
23+
]

0 commit comments

Comments
 (0)