| author | Alexandre Segura <mex.zktk@gmail.com> |
| Tue, 06 Jun 2017 15:56:41 +0200 | |
| changeset 19 | f1b125b95fe9 |
| parent 17 | 877d8796b86d |
| child 21 | 284e866f55c7 |
| permissions | -rw-r--r-- |
| 15 | 1 |
import { Editor, Plain, Raw } from 'slate' |
| 5 | 2 |
import React from 'react' |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
3 |
import moment from 'moment'; |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
4 |
import HtmlSerializer from '../HtmlSerializer' |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
5 |
import AnnotationPlugin from '../AnnotationPlugin'; |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
6 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
7 |
const plugins = []; |
| 5 | 8 |
|
9 |
/** |
|
10 |
* Define the default node type. |
|
11 |
*/ |
|
12 |
||
13 |
const DEFAULT_NODE = 'paragraph' |
|
14 |
||
15 |
/** |
|
16 |
* Define a schema. |
|
17 |
* |
|
18 |
* @type {Object} |
|
19 |
*/ |
|
20 |
||
21 |
const schema = { |
|
22 |
nodes: { |
|
23 |
'bulleted-list': props => <ul {...props.attributes}>{props.children}</ul>, |
|
24 |
'list-item': props => <li {...props.attributes}>{props.children}</li>, |
|
25 |
'numbered-list': props => <ol {...props.attributes}>{props.children}</ol>, |
|
26 |
}, |
|
27 |
marks: { |
|
28 |
bold: { |
|
29 |
fontWeight: 'bold' |
|
30 |
}, |
|
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
31 |
// TODO Check if we can move this to the plugin using the schema option |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
32 |
// https://docs.slatejs.org/reference/plugins/plugin.html#schema |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
33 |
annotation: { |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
34 |
textDecoration: 'underline', |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
35 |
textDecorationStyle: 'dotted', |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
36 |
backgroundColor: 'yellow', |
| 5 | 37 |
}, |
38 |
italic: { |
|
39 |
fontStyle: 'italic' |
|
40 |
}, |
|
41 |
underlined: { |
|
42 |
textDecoration: 'underline' |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
||
47 |
/** |
|
48 |
* The rich text example. |
|
49 |
* |
|
50 |
* @type {Component} |
|
51 |
*/ |
|
52 |
||
| 8 | 53 |
class SlateEditor extends React.Component { |
| 5 | 54 |
|
55 |
/** |
|
56 |
* Deserialize the initial editor state. |
|
57 |
* |
|
58 |
* @type {Object} |
|
59 |
*/ |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
60 |
constructor(props) { |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
61 |
super(props); |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
62 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
63 |
const annotationPlugin = AnnotationPlugin({ |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
64 |
onChange: (text) => { |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
65 |
this.setState({ currentSelectionText: text }); |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
66 |
} |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
67 |
}); |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
68 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
69 |
plugins.push(annotationPlugin); |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
70 |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
71 |
this.state = { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
72 |
state: Plain.deserialize(''), |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
73 |
startedAt: null, |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
74 |
finishedAt: null, |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
75 |
currentSelectionText: '' |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
76 |
}; |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
77 |
} |
| 5 | 78 |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
79 |
componentDidMount() { |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
80 |
this.focus(); |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
81 |
} |
| 5 | 82 |
|
83 |
/** |
|
84 |
* Check if the current selection has a mark with `type` in it. |
|
85 |
* |
|
86 |
* @param {String} type |
|
87 |
* @return {Boolean} |
|
88 |
*/ |
|
89 |
||
90 |
hasMark = (type) => { |
|
91 |
const { state } = this.state |
|
92 |
return state.marks.some(mark => mark.type === type) |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Check if the any of the currently selected blocks are of `type`. |
|
97 |
* |
|
98 |
* @param {String} type |
|
99 |
* @return {Boolean} |
|
100 |
*/ |
|
101 |
||
102 |
hasBlock = (type) => { |
|
103 |
const { state } = this.state |
|
104 |
return state.blocks.some(node => node.type === type) |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* On change, save the new state. |
|
109 |
* |
|
110 |
* @param {State} state |
|
111 |
*/ |
|
112 |
||
113 |
onChange = (state) => { |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
114 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
115 |
let newState = { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
116 |
state: state, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
117 |
startedAt: this.state.startedAt |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
118 |
}; |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
119 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
120 |
const isEmpty = state.document.length === 0; |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
121 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
122 |
// Reset timers when the text is empty |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
123 |
if (isEmpty) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
124 |
Object.assign(newState, { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
125 |
startedAt: null, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
126 |
finishedAt: null |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
127 |
}); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
128 |
} else { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
129 |
Object.assign(newState, { finishedAt: moment().format('H:mm:ss') }); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
130 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
131 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
132 |
// Store start time once when the first character is typed |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
133 |
if (!isEmpty && this.state.startedAt === null) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
134 |
Object.assign(newState, { startedAt: moment().format('H:mm:ss') }); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
135 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
136 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
137 |
this.setState(newState) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
138 |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
139 |
if (typeof this.props.onChange === 'function') { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
140 |
this.props.onChange(newState); |
| 8 | 141 |
} |
| 5 | 142 |
} |
143 |
||
144 |
asPlain = () => { |
|
145 |
return Plain.serialize(this.state.state); |
|
146 |
} |
|
147 |
||
| 15 | 148 |
asRaw = () => { |
149 |
return Raw.serialize(this.state.state); |
|
150 |
} |
|
151 |
||
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
152 |
asHtml = () => { |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
153 |
return HtmlSerializer.serialize(this.state.state); |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
154 |
} |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
155 |
|
| 5 | 156 |
clear = () => { |
157 |
const state = Plain.deserialize(''); |
|
| 8 | 158 |
this.onChange(state); |
| 5 | 159 |
} |
160 |
||
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
161 |
focus = () => { |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
162 |
this.refs.editor.focus(); |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
163 |
} |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
164 |
|
| 5 | 165 |
/** |
166 |
* On key down, if it's a formatting command toggle a mark. |
|
167 |
* |
|
168 |
* @param {Event} e |
|
169 |
* @param {Object} data |
|
170 |
* @param {State} state |
|
171 |
* @return {State} |
|
172 |
*/ |
|
173 |
||
174 |
onKeyDown = (e, data, state) => { |
|
175 |
if (!data.isMod) return |
|
176 |
let mark |
|
177 |
||
178 |
switch (data.key) { |
|
179 |
case 'b': |
|
180 |
mark = 'bold' |
|
181 |
break |
|
182 |
case 'i': |
|
183 |
mark = 'italic' |
|
184 |
break |
|
185 |
case 'u': |
|
186 |
mark = 'underlined' |
|
187 |
break |
|
188 |
default: |
|
189 |
return |
|
190 |
} |
|
191 |
||
192 |
state = state |
|
193 |
.transform() |
|
194 |
.toggleMark(mark) |
|
195 |
.apply() |
|
196 |
||
197 |
e.preventDefault() |
|
198 |
return state |
|
199 |
} |
|
200 |
||
201 |
/** |
|
202 |
* When a mark button is clicked, toggle the current mark. |
|
203 |
* |
|
204 |
* @param {Event} e |
|
205 |
* @param {String} type |
|
206 |
*/ |
|
207 |
||
208 |
onClickMark = (e, type) => { |
|
209 |
e.preventDefault() |
|
210 |
let { state } = this.state |
|
211 |
||
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
212 |
let toggleMarkOptions; |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
213 |
if (type === 'annotation') { |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
214 |
toggleMarkOptions = { type: type, data: { text: this.state.currentSelectionText } } |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
215 |
} else { |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
216 |
toggleMarkOptions = type; |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
217 |
} |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
218 |
|
| 5 | 219 |
state = state |
220 |
.transform() |
|
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
221 |
.toggleMark(toggleMarkOptions) |
| 5 | 222 |
.apply() |
223 |
||
224 |
this.setState({ state }) |
|
225 |
} |
|
226 |
||
227 |
/** |
|
228 |
* When a block button is clicked, toggle the block type. |
|
229 |
* |
|
230 |
* @param {Event} e |
|
231 |
* @param {String} type |
|
232 |
*/ |
|
233 |
||
234 |
onClickBlock = (e, type) => { |
|
235 |
e.preventDefault() |
|
236 |
let { state } = this.state |
|
237 |
const transform = state.transform() |
|
238 |
const { document } = state |
|
239 |
||
240 |
// Handle everything but list buttons. |
|
241 |
if (type !== 'bulleted-list' && type !== 'numbered-list') { |
|
242 |
const isActive = this.hasBlock(type) |
|
243 |
const isList = this.hasBlock('list-item') |
|
244 |
||
245 |
if (isList) { |
|
246 |
transform |
|
247 |
.setBlock(isActive ? DEFAULT_NODE : type) |
|
248 |
.unwrapBlock('bulleted-list') |
|
249 |
.unwrapBlock('numbered-list') |
|
250 |
} |
|
251 |
||
252 |
else { |
|
253 |
transform |
|
254 |
.setBlock(isActive ? DEFAULT_NODE : type) |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
// Handle the extra wrapping required for list buttons. |
|
259 |
else { |
|
260 |
const isList = this.hasBlock('list-item') |
|
261 |
const isType = state.blocks.some((block) => { |
|
262 |
return !!document.getClosest(block.key, parent => parent.type === type) |
|
263 |
}) |
|
264 |
||
265 |
if (isList && isType) { |
|
266 |
transform |
|
267 |
.setBlock(DEFAULT_NODE) |
|
268 |
.unwrapBlock('bulleted-list') |
|
269 |
.unwrapBlock('numbered-list') |
|
270 |
} else if (isList) { |
|
271 |
transform |
|
272 |
.unwrapBlock(type === 'bulleted-list' ? 'numbered-list' : 'bulleted-list') |
|
273 |
.wrapBlock(type) |
|
274 |
} else { |
|
275 |
transform |
|
276 |
.setBlock('list-item') |
|
277 |
.wrapBlock(type) |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
state = transform.apply() |
|
282 |
this.setState({ state }) |
|
283 |
} |
|
284 |
||
| 8 | 285 |
/** |
| 5 | 286 |
* Render. |
287 |
* |
|
288 |
* @return {Element} |
|
289 |
*/ |
|
290 |
||
291 |
render = () => { |
|
292 |
return ( |
|
293 |
<div> |
|
294 |
{this.renderToolbar()} |
|
295 |
{this.renderEditor()} |
|
296 |
</div> |
|
297 |
) |
|
298 |
} |
|
299 |
||
300 |
/** |
|
301 |
* Render the toolbar. |
|
302 |
* |
|
303 |
* @return {Element} |
|
304 |
*/ |
|
305 |
||
306 |
renderToolbar = () => { |
|
307 |
return ( |
|
308 |
<div className="menu toolbar-menu"> |
|
309 |
{this.renderMarkButton('bold', 'format_bold')} |
|
310 |
{this.renderMarkButton('italic', 'format_italic')} |
|
311 |
{this.renderMarkButton('underlined', 'format_underlined')} |
|
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
312 |
{this.renderMarkButton('annotation', 'label')} |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
313 |
|
| 5 | 314 |
{this.renderBlockButton('numbered-list', 'format_list_numbered')} |
315 |
{this.renderBlockButton('bulleted-list', 'format_list_bulleted')} |
|
316 |
</div> |
|
317 |
) |
|
318 |
} |
|
319 |
||
320 |
/** |
|
321 |
* Render a mark-toggling toolbar button. |
|
322 |
* |
|
323 |
* @param {String} type |
|
324 |
* @param {String} icon |
|
325 |
* @return {Element} |
|
326 |
*/ |
|
327 |
||
328 |
renderMarkButton = (type, icon) => { |
|
329 |
const isActive = this.hasMark(type) |
|
330 |
const onMouseDown = e => this.onClickMark(e, type) |
|
331 |
||
332 |
return ( |
|
333 |
<span className="button" onMouseDown={onMouseDown} data-active={isActive}> |
|
334 |
<span className="material-icons">{icon}</span> |
|
335 |
</span> |
|
336 |
) |
|
337 |
} |
|
338 |
||
339 |
/** |
|
340 |
* Render a block-toggling toolbar button. |
|
341 |
* |
|
342 |
* @param {String} type |
|
343 |
* @param {String} icon |
|
344 |
* @return {Element} |
|
345 |
*/ |
|
346 |
||
347 |
renderBlockButton = (type, icon) => { |
|
348 |
const isActive = this.hasBlock(type) |
|
349 |
const onMouseDown = e => this.onClickBlock(e, type) |
|
350 |
||
351 |
return ( |
|
352 |
<span className="button" onMouseDown={onMouseDown} data-active={isActive}> |
|
353 |
<span className="material-icons">{icon}</span> |
|
354 |
</span> |
|
355 |
) |
|
356 |
} |
|
357 |
||
358 |
/** |
|
359 |
* Render the Slate editor. |
|
360 |
* |
|
361 |
* @return {Element} |
|
362 |
*/ |
|
363 |
||
364 |
renderEditor = () => { |
|
365 |
return ( |
|
366 |
<div className="editor"> |
|
367 |
<Editor |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
368 |
ref="editor" |
| 5 | 369 |
spellCheck |
370 |
placeholder={'Enter some rich text...'} |
|
371 |
schema={schema} |
|
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
372 |
plugins={plugins} |
| 5 | 373 |
state={this.state.state} |
374 |
onChange={this.onChange} |
|
375 |
onKeyDown={this.onKeyDown} |
|
376 |
/> |
|
377 |
</div> |
|
378 |
) |
|
379 |
} |
|
380 |
||
381 |
} |
|
382 |
||
383 |
/** |
|
384 |
* Export. |
|
385 |
*/ |
|
386 |
||
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
387 |
export default SlateEditor |