Skip to content

Commit e21139d

Browse files
committed
lots of react fixes, also drag-n-drop images!
1 parent 9f7825a commit e21139d

File tree

12 files changed

+108
-50
lines changed

12 files changed

+108
-50
lines changed

plugins/collapse/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
return <div className={cx({
3737
'm_Collapser': true,
3838
'm_Collapser-collapsed': node.collapsed
39-
})} onClick={actions.toggleCollapse.bind(actions, node.id)}/>
39+
})} key="collapser" onClick={actions.toggleCollapse.bind(actions, node.id)}/>
4040
}
4141
},
4242
}

plugins/image/index.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var React = require('react/addons')
33
, cx = React.addons.classSet
44
, PT = React.PropTypes
5+
, classnames = require('classnames')
56
, DefaultEditor = require('../../views/body/default-editor')
67
, DefaultRenderer = require('../../views/body/default-renderer')
78
, Uploader = require('./uploader')
@@ -13,11 +14,56 @@ var ImageBase = React.createClass({
1314
onUpload: PT.func,
1415
onClick: PT.func,
1516
},
17+
18+
getInitialState() {
19+
return {dragging: false}
20+
},
21+
22+
_dragOver(e) {
23+
e.preventDefault()
24+
if (!this.state.dragging) {
25+
this.setState({dragging: true})
26+
}
27+
},
28+
29+
_dragEnd(e) {
30+
e.preventDefault()
31+
this.setState({dragging: false})
32+
},
33+
34+
_drop(e) {
35+
e.preventDefault()
36+
this.setState({dragging: false})
37+
let files = e.dataTransfer.files
38+
if (!files.length) return
39+
const file = files[0]
40+
if (!file.type.match(/^image\//)) {
41+
return console.warn('not an image file')
42+
}
43+
getSrc(file, this.props.onUpload)
44+
},
45+
1646
render: function () {
1747
if (!this.props.src) {
18-
return <Uploader onUpload={this.props.onUpload}/>
48+
return <div
49+
className={classnames('ImageBase', this.state.dragging && 'ImageBase-dragging')}
50+
onClick={this.props.onClick}
51+
onDragEnter={this._dragOver}
52+
onDragOver={this._dragOver}
53+
onDragLeave={this._dragEnd}
54+
onDragEnd={this._dragEnd}
55+
onDrop={this._drop}>
56+
<Uploader onUpload={this.props.onUpload}/>
57+
</div>
1958
}
20-
return <div onClick={this.props.onClick} className='ImageBase'>
59+
return <div
60+
className={classnames('ImageBase', this.state.dragging && 'ImageBase-dragging')}
61+
onClick={this.props.onClick}
62+
onDragEnter={this._dragOver}
63+
onDragOver={this._dragOver}
64+
onDragLeave={this._dragEnd}
65+
onDragEnd={this._dragEnd}
66+
onDrop={this._drop}>
2167
<img src={this.props.src} title={this.props.title}/>
2268
<div onClick={e => {
2369
e.stopPropagation()

plugins/image/index.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
.ImageBase {
3232
position: relative;
3333

34+
&-dragging {
35+
opacity: .5;
36+
outline: 10px dotted black;
37+
}
38+
3439
&_close {
3540
position: absolute;
3641
top: 0;

plugins/image/uploader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var React = require('react/addons')
33
, cx = React.addons.classSet
44
, PT = React.PropTypes
5+
, classnames = require('classnames')
56
, getSrc = require('./get-src')
67

78
var Uploader = React.createClass({

plugins/rebase/breadcrumb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var Breadcrumb = React.createClass({
3030
render: function () {
3131
return <ul className='Breadcrumb'>
3232
{this.state.pedigree.map(item =>
33-
<li onClick={this.props.rebase.bind(null, item.id)} className="Breadcrumb_item">
33+
<li key={item.id} onClick={this.props.rebase.bind(null, item.id)} className="Breadcrumb_item">
3434
{item.content.slice(0, 25)}
3535
</li>
3636
)}

plugins/rebase/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ module.exports = {
1111
view: {
1212
statusbar: function (store) {
1313
var actions = store.actions
14-
return Breadcrumb({
15-
rebase: actions.rebase.bind(actions),
16-
reload: store.getters.getPedigree.bind(store.getters, true),
17-
store: store,
18-
})
14+
return <Breadcrumb
15+
key="rebase-breadcrumb"
16+
rebase={actions.rebase.bind(actions)}
17+
reload={store.getters.getPedigree.bind(store.getters, true)}
18+
store={store}
19+
/>
1920
},
2021

2122
blocks: {
2223
top: function (actions, state, store) {
23-
return Breadcrumb({
24-
rebase: actions.rebase.bind(actions),
25-
reload: store.getters.getPedigree.bind(store.getters, true),
26-
store: store,
27-
})
24+
return <Breadcrumb
25+
key="rebase-breadcrumb"
26+
rebase={actions.rebase.bind(actions)}
27+
reload={store.getters.getPedigree.bind(store.getters, true)}
28+
store={store}
29+
/>
2830
},
2931
},
3032
},

plugins/todo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
return <div className={cx({
5050
'm_Todo': true,
5151
'm_Todo-done': node.done,
52-
})} onClick={actions.toggleTodoDone.bind(actions, node.id)}/>
52+
})} key="todo" onClick={actions.toggleTodoDone.bind(actions, node.id)}/>
5353
}
5454
},
5555
},

views/body/default-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ renderer.link = function (href, title, text) {
1111

1212
marked.setOptions({
1313
gfm: true,
14-
sanitize: true,
14+
// sanitize: true,
1515
tables: true,
1616
breaks: true,
1717
pedantic: false,

views/body/simple.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,23 @@ var SimpleBody = React.createClass({
9090

9191
editor: function () {
9292
var Ctrl = this.props.editor || DefaultEditor
93-
return <Ctrl
94-
ref="text"
95-
value={this.state.content}
96-
node={this.props.node}
97-
store={this.props.store}
98-
goDown={this.props.actions.goDown.bind(this.props.actions)}
99-
goUp={this.props.actions.goUp.bind(this.props.actions)}
100-
joinUp={this.props.actions.joinUp.bind(this.props.actions)}
101-
createAfter={this.props.actions.createAfter.bind(this.props.actions)}
102-
removeEmpty={this.props.actions.removeEmpty.bind(this.props.actions)}
103-
onChange={this._onChange}
104-
onBlur={this._onBlur}/>
93+
const props = {
94+
ref: "text",
95+
value: this.state.content,
96+
node: this.props.node,
97+
store: this.props.store,
98+
goDown: this.props.actions.goDown.bind(this.props.actions),
99+
goUp: this.props.actions.goUp.bind(this.props.actions),
100+
joinUp: this.props.actions.joinUp.bind(this.props.actions),
101+
createAfter: this.props.actions.createAfter.bind(this.props.actions),
102+
removeEmpty: this.props.actions.removeEmpty.bind(this.props.actions),
103+
onChange: this._onChange,
104+
onBlur: this._onBlur
105+
}
106+
if (Ctrl.isReactLegacyFactory) {
107+
return <Ctrl {...props}/>
108+
}
109+
return Ctrl(props)
105110
},
106111

107112
renderer: function () {

views/body/textarea-grow.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,11 @@ var Textarea = React.createClass({
110110
return <div className={
111111
'textarea-grow ' + this.props.className
112112
}>
113-
{
114-
this.transferPropsTo(<textarea
115-
ref='area'
116-
className='body_input'
117-
/>)
118-
}
113+
<textarea
114+
ref='area'
115+
className='body_input'
116+
{...this.props}
117+
/>
119118
<div
120119
ref='shadow'
121120
className='shadow'>

0 commit comments

Comments
 (0)