| author | ymh <ymh.work@gmail.com> |
| Tue, 13 Nov 2018 16:46:15 +0100 | |
| changeset 172 | 4b780ebbedc6 |
| parent 171 | 03334a31130a |
| child 173 | 0e6703cd0968 |
| permissions | -rw-r--r-- |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
1 |
import { Value } from 'slate'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
2 |
import Plain from 'slate-plain-serializer'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
3 |
import { Editor } from 'slate-react'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
4 |
import React from 'react'; |
| 172 | 5 |
import { PortalWithState } from 'react-portal'; |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
6 |
import { Trans, withNamespaces } from 'react-i18next'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
7 |
import * as R from 'ramda'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
8 |
import HtmlSerializer from './HtmlSerializer'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
9 |
import AnnotationPlugin from './AnnotationPlugin'; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
10 |
import CategoriesTooltip from './CategoriesTooltip'; |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
159
diff
changeset
|
11 |
import './SlateEditor.css'; |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
12 |
import { now } from '../../utils'; |
|
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
13 |
import { defaultAnnotationsCategories } from '../../constants'; |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
14 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
15 |
const plugins = []; |
| 5 | 16 |
|
17 |
/** |
|
18 |
* Define the default node type. |
|
19 |
*/ |
|
20 |
||
21 |
const DEFAULT_NODE = 'paragraph' |
|
22 |
||
23 |
/** |
|
24 |
* Define a schema. |
|
25 |
* |
|
26 |
* @type {Object} |
|
27 |
*/ |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
28 |
// TODO Check if we can move this to the plugin using the schema option |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
29 |
// https://docs.slatejs.org/reference/plugins/plugin.html#schema |
| 5 | 30 |
const schema = { |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
31 |
|
| 5 | 32 |
nodes: { |
33 |
'bulleted-list': props => <ul {...props.attributes}>{props.children}</ul>, |
|
34 |
'list-item': props => <li {...props.attributes}>{props.children}</li>, |
|
35 |
'numbered-list': props => <ol {...props.attributes}>{props.children}</ol>, |
|
36 |
}, |
|
37 |
marks: { |
|
38 |
bold: { |
|
39 |
fontWeight: 'bold' |
|
40 |
}, |
|
|
25
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
41 |
category: props => { |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
42 |
const data = props.mark.data; |
| 172 | 43 |
return <span style={{ backgroundColor: data.color }} {...props.attributes}>{props.children}</span> |
| 5 | 44 |
}, |
45 |
italic: { |
|
46 |
fontStyle: 'italic' |
|
47 |
}, |
|
48 |
underlined: { |
|
| 157 | 49 |
textDecoration: 'underlined' |
| 5 | 50 |
} |
51 |
} |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
52 |
|
| 5 | 53 |
} |
54 |
||
| 157 | 55 |
const initialValue = Value.fromJSON({ |
56 |
document: { |
|
57 |
nodes: [ |
|
58 |
{ |
|
59 |
object: 'block', |
|
60 |
type: 'paragraph', |
|
61 |
nodes: [ |
|
62 |
{ |
|
63 |
object: 'text', |
|
64 |
leaves: [ |
|
65 |
{ |
|
66 |
text: '', |
|
67 |
}, |
|
68 |
], |
|
69 |
}, |
|
70 |
], |
|
71 |
}, |
|
72 |
], |
|
73 |
}, |
|
74 |
}) |
|
75 |
||
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
76 |
|
| 5 | 77 |
/** |
78 |
* |
|
79 |
* @type {Component} |
|
80 |
*/ |
|
81 |
||
| 8 | 82 |
class SlateEditor extends React.Component { |
| 5 | 83 |
|
84 |
/** |
|
85 |
* Deserialize the initial editor state. |
|
86 |
* |
|
87 |
* @type {Object} |
|
88 |
*/ |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
89 |
constructor(props) { |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
90 |
super(props); |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
91 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
92 |
const annotationPlugin = AnnotationPlugin({ |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
93 |
onChange: (text, start, end) => { |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
94 |
this.setState({ |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
95 |
currentSelectionText: text, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
96 |
currentSelectionStart: start, |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
97 |
currentSelectionEnd: end, |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
98 |
}); |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
99 |
} |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
100 |
}); |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
101 |
|
| 172 | 102 |
// plugins.push(annotationPlugin); |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
103 |
|
| 157 | 104 |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
105 |
this.state = { |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
106 |
value: props.note ? Value.fromJSON(initialValue) : Plain.deserialize(''), |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
107 |
startedAt: null, |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
108 |
finishedAt: null, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
109 |
currentSelectionText: '', |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
110 |
currentSelectionStart: 0, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
111 |
currentSelectionEnd: 0, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
112 |
hoveringMenu: null, |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
113 |
isPortalOpen: false, |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
114 |
categories: [], |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
115 |
isCheckboxChecked: false, |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
116 |
enterKeyValue: 0, |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
117 |
}; |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
118 |
|
| 172 | 119 |
this.editorRef = React.createRef(); |
120 |
this.hoveringMenuRef = React.createRef(); |
|
121 |
} |
|
122 |
||
123 |
get editor() { |
|
124 |
if(this.editorRef) { |
|
125 |
return this.editorRef.current; |
|
126 |
} |
|
127 |
return null; |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
128 |
} |
| 5 | 129 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
130 |
componentDidMount = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
131 |
this.updateMenu(); |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
132 |
this.focus(); |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
133 |
} |
| 5 | 134 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
135 |
componentDidUpdate = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
136 |
this.updateMenu(); |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
137 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
138 |
|
| 172 | 139 |
getDocumentLength = (document) => { |
140 |
return document.getBlocks().reduce((l, b) => l + b.text.length, 0) |
|
141 |
} |
|
142 |
||
| 157 | 143 |
/** |
144 |
* On change, save the new state. |
|
| 5 | 145 |
* |
| 157 | 146 |
* @param {Change} change |
| 5 | 147 |
*/ |
148 |
||
| 172 | 149 |
onChange = (change) => { |
150 |
||
151 |
const operationTypes = (change && change.operations) ? change.operations.map((o) => o.type).toArray() : []; |
|
152 |
console.log("CHANGE", change, operationTypes); |
|
153 |
const { value } = change; |
|
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
154 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
155 |
let newState = { |
| 157 | 156 |
value: value, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
157 |
startedAt: this.state.startedAt |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
158 |
}; |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
159 |
|
| 172 | 160 |
const isEmpty = this.getDocumentLength(value.document) === 0; |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
161 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
162 |
// Reset timers when the text is empty |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
163 |
if (isEmpty) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
164 |
Object.assign(newState, { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
165 |
startedAt: null, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
166 |
finishedAt: null |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
167 |
}); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
168 |
} else { |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
169 |
Object.assign(newState, { finishedAt: now() }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
170 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
171 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
172 |
// 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
|
173 |
if (!isEmpty && this.state.startedAt === null) { |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
72
diff
changeset
|
174 |
Object.assign(newState, { startedAt: now() }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
175 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
176 |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
177 |
const oldState = R.clone(this.state); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
178 |
|
| 172 | 179 |
const categories = value.marks.reduce((acc, mark) => { |
180 |
if(mark.type === 'category') { |
|
181 |
acc.push({ |
|
182 |
key: mark.data.get('key'), |
|
183 |
name: mark.data.get('name'), |
|
184 |
color: mark.data.get('color'), |
|
185 |
text: mark.data.get('text'), |
|
186 |
selection: { |
|
187 |
start: mark.data.get('selection').start, |
|
188 |
end: mark.data.get('selection').end, |
|
189 |
}, |
|
190 |
comment: mark.data.get('comment') |
|
191 |
}) |
|
192 |
} |
|
193 |
return acc; |
|
194 |
}, |
|
195 |
[]); |
|
196 |
||
197 |
console.log("ON CHANGE categorie", categories); |
|
198 |
||
199 |
newState['categories'] = categories; |
|
200 |
||
201 |
this.setState(newState, () => { |
|
202 |
if (typeof this.props.onChange === 'function') { |
|
203 |
this.props.onChange(R.clone(this.state), oldState, newState); |
|
204 |
} |
|
205 |
}) |
|
206 |
||
| 5 | 207 |
} |
208 |
||
| 157 | 209 |
/** |
210 |
* Check if the current selection has a mark with `type` in it. |
|
211 |
* |
|
212 |
* @param {String} type |
|
213 |
* @return {Boolean} |
|
214 |
*/ |
|
215 |
||
216 |
hasMark = type => { |
|
| 172 | 217 |
const { value } = this.state; |
218 |
return value.activeMarks.some(mark => mark.type === type); |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
219 |
} |
| 157 | 220 |
|
221 |
/** |
|
222 |
* Check if the any of the currently selected blocks are of `type`. |
|
223 |
* |
|
224 |
* @param {String} type |
|
225 |
* @return {Boolean} |
|
226 |
*/ |
|
227 |
||
228 |
hasBlock = type => { |
|
229 |
const { value } = this.state |
|
230 |
return value.blocks.some(node => node.type === type) |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
231 |
} |
| 157 | 232 |
|
| 5 | 233 |
asPlain = () => { |
| 157 | 234 |
return Plain.serialize(this.state.value); |
| 5 | 235 |
} |
236 |
||
| 15 | 237 |
asRaw = () => { |
| 157 | 238 |
return JSON.stringify(this.state.value.toJSON()); |
| 15 | 239 |
} |
240 |
||
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
241 |
asHtml = () => { |
| 157 | 242 |
return HtmlSerializer.serialize(this.state.value); |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
243 |
} |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
244 |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
245 |
asCategories = () => { |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
246 |
return this.state.categories |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
247 |
} |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
248 |
|
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
249 |
removeCategory = (categories, key, text) => { |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
250 |
const categoryIndex = categories.findIndex(category => category.key === key && category.text === text) |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
251 |
return categories.delete(categoryIndex) |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
252 |
} |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
253 |
|
| 5 | 254 |
clear = () => { |
| 157 | 255 |
const value = Plain.deserialize(''); |
| 172 | 256 |
this.onChange({ |
257 |
value, |
|
258 |
}); |
|
| 5 | 259 |
} |
260 |
||
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
261 |
focus = () => { |
| 172 | 262 |
if(this.editor) { |
263 |
this.editor.focus(); |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
264 |
} |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
265 |
} |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
266 |
|
| 172 | 267 |
onClickCategoryButton = (openPortal, closePortal, isOpen, e) => { |
268 |
e.preventDefault(); |
|
269 |
const { categories, value } = this.state |
|
270 |
||
271 |
let newCategories = categories.slice(0); |
|
272 |
||
273 |
// Can't use toggleMark here, because it expects the same object |
|
274 |
// @see https://github.com/ianstormtaylor/slate/issues/873 |
|
275 |
if (this.hasMark('category')) { |
|
276 |
const categoryMarks = value.activeMarks.filter(mark => mark.type === 'category') |
|
277 |
categoryMarks.forEach(mark => { |
|
278 |
const key = mark.data.get('key'); |
|
279 |
const text = mark.data.get('text'); |
|
280 |
||
281 |
newCategories = R.reject(category => category.key === key && category.text === text, newCategories); |
|
282 |
this.editor.removeMark(mark) |
|
283 |
}) |
|
284 |
this.setState({ |
|
285 |
value: this.editor.value, |
|
286 |
categories: newCategories |
|
287 |
}); |
|
288 |
closePortal(); |
|
289 |
} else { |
|
290 |
openPortal(); |
|
291 |
} |
|
292 |
// } else { |
|
293 |
// isOpen ? closePortal() : openPortal(); |
|
294 |
// } |
|
295 |
} |
|
296 |
||
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
297 |
/** |
| 5 | 298 |
* When a mark button is clicked, toggle the current mark. |
299 |
* |
|
300 |
* @param {Event} e |
|
301 |
* @param {String} type |
|
302 |
*/ |
|
303 |
||
304 |
onClickMark = (e, type) => { |
|
| 172 | 305 |
this.editor.toggleMark(type) |
| 5 | 306 |
} |
307 |
||
308 |
/** |
|
309 |
* When a block button is clicked, toggle the block type. |
|
310 |
* |
|
311 |
* @param {Event} e |
|
312 |
* @param {String} type |
|
313 |
*/ |
|
314 |
||
315 |
onClickBlock = (e, type) => { |
|
316 |
e.preventDefault() |
|
| 172 | 317 |
|
318 |
const { editor } = this; |
|
319 |
const { value } = editor; |
|
320 |
const { document } = value; |
|
| 5 | 321 |
|
322 |
// Handle everything but list buttons. |
|
323 |
if (type !== 'bulleted-list' && type !== 'numbered-list') { |
|
324 |
const isActive = this.hasBlock(type) |
|
325 |
const isList = this.hasBlock('list-item') |
|
326 |
||
327 |
if (isList) { |
|
| 172 | 328 |
editor |
| 157 | 329 |
.setBlocks(isActive ? DEFAULT_NODE : type) |
| 5 | 330 |
.unwrapBlock('bulleted-list') |
331 |
.unwrapBlock('numbered-list') |
|
332 |
} |
|
333 |
||
334 |
else { |
|
| 172 | 335 |
editor |
| 157 | 336 |
.setBlocks(isActive ? DEFAULT_NODE : type) |
| 5 | 337 |
} |
338 |
} |
|
339 |
||
340 |
// Handle the extra wrapping required for list buttons. |
|
341 |
else { |
|
342 |
const isList = this.hasBlock('list-item') |
|
| 157 | 343 |
const isType = value.blocks.some((block) => { |
| 5 | 344 |
return !!document.getClosest(block.key, parent => parent.type === type) |
345 |
}) |
|
346 |
||
347 |
if (isList && isType) { |
|
| 172 | 348 |
editor |
| 157 | 349 |
.setBlocks(DEFAULT_NODE) |
| 5 | 350 |
.unwrapBlock('bulleted-list') |
351 |
.unwrapBlock('numbered-list') |
|
| 157 | 352 |
|
| 5 | 353 |
} else if (isList) { |
| 172 | 354 |
editor |
| 5 | 355 |
.unwrapBlock(type === 'bulleted-list' ? 'numbered-list' : 'bulleted-list') |
356 |
.wrapBlock(type) |
|
| 157 | 357 |
|
| 5 | 358 |
} else { |
| 172 | 359 |
editor |
| 157 | 360 |
.setBlocks('list-item') |
| 5 | 361 |
.wrapBlock(type) |
| 157 | 362 |
|
| 5 | 363 |
} |
364 |
} |
|
| 172 | 365 |
// this.onChange(change) |
| 5 | 366 |
} |
367 |
||
| 172 | 368 |
onPortalOpen = () => { |
369 |
console.log("onPORTAL OPEN", this); |
|
370 |
this.updateMenu(); |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
371 |
// When the portal opens, cache the menu element. |
| 172 | 372 |
// this.setState({ hoveringMenu: this.portal.firstChild }) |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
373 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
374 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
375 |
onPortalClose = (portal) => { |
| 172 | 376 |
console.log("onPORTAL CLOSE", this); |
377 |
// let { value } = this.state |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
378 |
|
| 172 | 379 |
// this.setState({ |
380 |
// value: value.change, |
|
381 |
// isPortalOpen: false |
|
382 |
// }) |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
383 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
384 |
|
| 172 | 385 |
getSelectionParams = () => { |
386 |
||
387 |
const { value } = this.editor |
|
388 |
const { selection } = value |
|
389 |
const { start, end} = selection |
|
390 |
||
391 |
if (selection.isCollapsed) { |
|
392 |
return {}; |
|
393 |
} |
|
394 |
||
395 |
const nodes = []; |
|
396 |
let hasStarted = false; |
|
397 |
let hasEnded = false; |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
398 |
|
| 172 | 399 |
// Keep only the relevant nodes, |
400 |
// i.e. nodes which are contained within selection |
|
401 |
value.document.nodes.forEach((node) => { |
|
402 |
if (start.isInNode(node)) { |
|
403 |
hasStarted = true; |
|
404 |
} |
|
405 |
if (hasStarted && !hasEnded) { |
|
406 |
nodes.push(node); |
|
407 |
} |
|
408 |
if (end.isAtEndOfNode(node)) { |
|
409 |
hasEnded = true; |
|
410 |
} |
|
411 |
}); |
|
412 |
||
413 |
// Concatenate the nodes text |
|
414 |
const text = nodes.map((node) => { |
|
415 |
let textStart = start.isInNode(node) ? start.offset : 0; |
|
416 |
let textEnd = end.isInNode(node) ? end.offset : node.text.length; |
|
417 |
return node.text.substring(textStart,textEnd); |
|
418 |
}).join('\n'); |
|
419 |
||
420 |
return { |
|
421 |
currentSelectionText: text, |
|
422 |
currentSelectionStart: start.offset, |
|
423 |
currentSelectionEnd: end.offset |
|
424 |
}; |
|
425 |
} |
|
426 |
||
427 |
onCategoryClick = (closePortal, category) => { |
|
428 |
||
429 |
console.log("ON CATEGORY CLICK"); |
|
430 |
const { value } = this.state; |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
431 |
let { categories } = this.state; |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
432 |
|
| 172 | 433 |
const { currentSelectionText, currentSelectionStart, currentSelectionEnd } = this.getSelectionParams(); |
434 |
||
435 |
if(!currentSelectionText) { |
|
436 |
closePortal(); |
|
437 |
return; |
|
438 |
} |
|
439 |
console.log("ACTIVE MARKS", category, currentSelectionText, currentSelectionStart, currentSelectionEnd) |
|
440 |
||
| 157 | 441 |
const categoryMarks = value.activeMarks.filter(mark => mark.type === 'category') |
| 172 | 442 |
categoryMarks.forEach(mark => this.editor.removeMark(mark)); |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
443 |
|
| 172 | 444 |
this.editor.addMark({ |
|
25
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
445 |
type: 'category', |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
446 |
data: { |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
447 |
text: currentSelectionText, |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
448 |
selection: { |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
449 |
start: currentSelectionStart, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
450 |
end: currentSelectionEnd, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
451 |
}, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
452 |
color: category.color, |
| 172 | 453 |
key: category.key, |
454 |
name: category.name, |
|
455 |
comment: category.comment |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
456 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
457 |
}) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
458 |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
459 |
Object.assign(category, { |
| 103 | 460 |
text: currentSelectionText, |
461 |
selection: { |
|
462 |
start: currentSelectionStart, |
|
463 |
end: currentSelectionEnd, |
|
464 |
}, |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
465 |
}); |
| 172 | 466 |
categories.push(category); |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
467 |
|
| 172 | 468 |
console.log("CATEGORIES", categories) |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
469 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
470 |
this.setState({ |
| 172 | 471 |
categories: categories, |
472 |
value: this.editor.value |
|
473 |
}, closePortal); |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
474 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
475 |
|
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
476 |
onButtonClick = () => { |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
477 |
if (typeof this.props.onButtonClick === 'function') { |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
478 |
this.props.onButtonClick(); |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
479 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
480 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
481 |
|
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
482 |
onCheckboxChange = (e) => { |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
483 |
if (typeof this.props.onCheckboxChange === 'function') { |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
484 |
this.props.onCheckboxChange(e); |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
485 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
486 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
487 |
|
| 8 | 488 |
/** |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
489 |
* On key down, if it's a formatting command toggle a mark. |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
490 |
* |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
491 |
* @param {Event} e |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
492 |
* @param {Change} change |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
493 |
* @return {Change} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
494 |
*/ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
495 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
496 |
onKeyDown = (e, change) => { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
497 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
498 |
const {value} = this.state; |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
499 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
500 |
if (e.key === 'Enter' && value.document.text !== '') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
501 |
this.setState({enterKeyValue: 1}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
502 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
503 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
504 |
if (e.key !== 'Enter') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
505 |
this.setState({ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
506 |
enterKeyValue: 0, |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
507 |
}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
508 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
509 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
510 |
|
| 169 | 511 |
//TODO review the double enter case. |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
512 |
if (e.key === 'Enter' && !this.props.isChecked && this.state.enterKeyValue === 1 && typeof this.props.onEnterKeyDown === 'function') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
513 |
e.preventDefault(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
514 |
this.props.onEnterKeyDown(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
515 |
this.setState({ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
516 |
enterKeyValue: 0, |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
517 |
}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
518 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
519 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
520 |
return change |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
521 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
522 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
523 |
else if (e.key === 'Enter' && value.document.text !== '' && this.props.isChecked && typeof this.props.onEnterKeyDown === 'function') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
524 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
525 |
e.preventDefault(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
526 |
this.props.onEnterKeyDown(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
527 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
528 |
return change |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
529 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
530 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
531 |
if (!e.ctrlKey) return |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
532 |
// Decide what to do based on the key code... |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
533 |
switch (e.key) { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
534 |
default: { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
535 |
break; |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
536 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
537 |
// When "B" is pressed, add a "bold" mark to the text. |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
538 |
case 'b': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
539 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
540 |
change.toggleMark('bold') |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
541 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
542 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
543 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
544 |
case 'i': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
545 |
// When "U" is pressed, add an "italic" mark to the text. |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
546 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
547 |
change.toggleMark('italic') |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
548 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
549 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
550 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
551 |
case 'u': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
552 |
// When "U" is pressed, add an "underline" mark to the text. |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
553 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
554 |
change.toggleMark('underlined') |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
555 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
556 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
557 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
558 |
case 'Enter': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
559 |
// When "ENTER" is pressed, autosubmit the note. |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
560 |
if (value.document.text !== '' && typeof this.props.onEnterKeyDown === 'function') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
561 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
562 |
this.props.onEnterKeyDown(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
563 |
this.setState({ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
564 |
enterKeyValue: 0, |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
565 |
}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
566 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
567 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
568 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
569 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
570 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
571 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
572 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
573 |
/** |
| 5 | 574 |
* Render. |
575 |
* |
|
576 |
* @return {Element} |
|
577 |
*/ |
|
578 |
||
579 |
render = () => { |
|
580 |
return ( |
|
| 157 | 581 |
<div className="bg-secondary mb-5"> |
582 |
<div className="sticky-top"> |
|
| 5 | 583 |
{this.renderToolbar()} |
| 157 | 584 |
</div> |
| 5 | 585 |
{this.renderEditor()} |
| 157 | 586 |
</div> |
| 5 | 587 |
) |
588 |
} |
|
589 |
||
590 |
/** |
|
591 |
* Render the toolbar. |
|
592 |
* |
|
593 |
* @return {Element} |
|
594 |
*/ |
|
595 |
||
596 |
renderToolbar = () => { |
|
597 |
return ( |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
598 |
<div className="menu toolbar-menu d-flex sticky-top bg-secondary"> |
| 157 | 599 |
{this.renderMarkButton('bold', 'format_bold')} |
600 |
{this.renderMarkButton('italic', 'format_italic')} |
|
601 |
{this.renderMarkButton('underlined', 'format_underlined')} |
|
| 172 | 602 |
{this.renderCategoryButton()} |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
603 |
|
| 157 | 604 |
{this.renderBlockButton('numbered-list', 'format_list_numbered')} |
605 |
{this.renderBlockButton('bulleted-list', 'format_list_bulleted')} |
|
606 |
||
607 |
{this.renderToolbarButtons()} |
|
| 5 | 608 |
</div> |
609 |
) |
|
610 |
} |
|
611 |
||
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
612 |
renderToolbarCheckbox = () => { |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
613 |
return ( |
| 157 | 614 |
<div className="checkbox float-right"> |
615 |
<label className="mr-2"> |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
616 |
<input type="checkbox" checked={this.props.isChecked} onChange={this.onCheckboxChange} /><small className="text-muted ml-1"><Trans i18nKey="slate_editor.press_enter_msg">Appuyer sur <kbd className="bg-irinotes-form text-muted ml-1">Entrée</kbd> pour ajouter une note</Trans></small> |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
617 |
</label> |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
618 |
</div> |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
619 |
) |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
620 |
} |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
621 |
|
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
622 |
renderToolbarButtons = () => { |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
623 |
const t = this.props.t; |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
624 |
return ( |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
625 |
<div> |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
626 |
<button type="button" id="btn-editor" className="btn btn-primary btn-sm text-secondary font-weight-bold float-right text-capitalize" disabled={this.props.isButtonDisabled} onClick={this.onButtonClick}> |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
627 |
{ this.props.note ? t('common.save') : t('common.add') } |
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
628 |
</button> |
| 157 | 629 |
{ !this.props.note && this.renderToolbarCheckbox() } |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
630 |
</div> |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
631 |
); |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
632 |
} |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
633 |
|
| 5 | 634 |
/** |
635 |
* Render a mark-toggling toolbar button. |
|
636 |
* |
|
637 |
* @param {String} type |
|
638 |
* @param {String} icon |
|
639 |
* @return {Element} |
|
640 |
*/ |
|
641 |
||
642 |
renderMarkButton = (type, icon) => { |
|
643 |
const isActive = this.hasMark(type) |
|
644 |
const onMouseDown = e => this.onClickMark(e, type) |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
645 |
const markActivation = "button sticky-top" + ((!isActive)?" text-primary":" text-dark"); |
| 157 | 646 |
|
| 5 | 647 |
return ( |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
648 |
// <span className="button text-primary" onMouseDown={onMouseDown} data-active={isActive}> |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
649 |
<span className={markActivation} onMouseDown={onMouseDown} data-active={isActive}> |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
650 |
|
| 5 | 651 |
<span className="material-icons">{icon}</span> |
652 |
</span> |
|
653 |
) |
|
654 |
} |
|
655 |
||
| 172 | 656 |
/** |
657 |
* Render a mark-toggling toolbar button. |
|
658 |
* |
|
659 |
* @param {String} type |
|
660 |
* @param {String} icon |
|
661 |
* @return {Element} |
|
662 |
*/ |
|
| 157 | 663 |
|
| 172 | 664 |
renderCategoryButton = () => { |
665 |
const isActive = this.hasMark('category'); |
|
666 |
//const onMouseDown = e => this.onClickMark(e, type) |
|
667 |
const markActivation = "button sticky-top" + ((!isActive)?" text-primary":" text-dark"); |
|
| 157 | 668 |
|
| 172 | 669 |
return ( |
670 |
<PortalWithState |
|
671 |
// closeOnOutsideClick |
|
672 |
closeOnEsc |
|
673 |
onOpen={this.onPortalOpen} |
|
674 |
onClose={this.onPortalClose} |
|
675 |
> |
|
676 |
{({ openPortal, closePortal, isOpen, portal }) => { |
|
677 |
console.log("PORTAL", isOpen); |
|
678 |
const onMouseDown = R.partial(this.onClickCategoryButton, [openPortal, closePortal, isOpen]); |
|
679 |
const onCategoryClick = R.partial(this.onCategoryClick, [closePortal,]); |
|
680 |
return ( |
|
681 |
<React.Fragment> |
|
682 |
<span className={markActivation} onMouseDown={onMouseDown} data-active={isActive}> |
|
683 |
<span className="material-icons">label</span> |
|
684 |
</span> |
|
685 |
{portal( |
|
686 |
<div className="hovering-menu" ref={this.hoveringMenuRef}> |
|
687 |
<CategoriesTooltip categories={this.props.annotationCategories || defaultAnnotationsCategories} onCategoryClick={onCategoryClick} /> |
|
688 |
</div> |
|
689 |
)} |
|
690 |
</React.Fragment> |
|
691 |
)} |
|
692 |
} |
|
693 |
</PortalWithState> |
|
694 |
) |
|
695 |
} |
|
696 |
||
697 |
// Add a `renderMark` method to render marks. |
|
698 |
||
699 |
renderMark = (props, editor, next) => { |
|
700 |
const { children, mark, attributes } = props |
|
701 |
||
702 |
console.log("renderMark", mark, mark.type, mark.data.color); |
|
703 |
switch (mark.type) { |
|
704 |
case 'bold': |
|
705 |
return <strong {...attributes}>{children}</strong> |
|
706 |
case 'code': |
|
707 |
return <code {...attributes}>{children}</code> |
|
708 |
case 'italic': |
|
709 |
return <em {...attributes}>{children}</em> |
|
710 |
case 'underlined': |
|
711 |
return <ins {...attributes}>{children}</ins> |
|
712 |
case 'category': |
|
713 |
let spanStyle = { |
|
714 |
backgroundColor: mark.data.get('color') |
|
715 |
}; |
|
716 |
return <span {...attributes} style={ spanStyle } >{children}</span> |
|
717 |
default: |
|
718 |
return next(); |
|
719 |
} |
|
| 157 | 720 |
} |
| 5 | 721 |
/** |
722 |
* Render a block-toggling toolbar button. |
|
723 |
* |
|
724 |
* @param {String} type |
|
725 |
* @param {String} icon |
|
726 |
* @return {Element} |
|
727 |
*/ |
|
728 |
||
729 |
renderBlockButton = (type, icon) => { |
|
| 157 | 730 |
let isActive = this.hasBlock(type) |
731 |
||
732 |
if (['numbered-list', 'bulleted-list'].includes(type)) { |
|
| 172 | 733 |
const { value } = this.state; |
734 |
const firstBlock = value.blocks.first(); |
|
735 |
if(firstBlock) { |
|
736 |
const parent = value.document.getParent(firstBlock.key); |
|
737 |
isActive = this.hasBlock('list-item') && parent && parent.type === type; |
|
738 |
} |
|
| 157 | 739 |
} |
| 5 | 740 |
const onMouseDown = e => this.onClickBlock(e, type) |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
741 |
const blockActivation = "button sticky-top" + ((!isActive)?" text-primary":" text-dark"); |
| 5 | 742 |
|
743 |
return ( |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
744 |
<span className={blockActivation} onMouseDown={onMouseDown} data-active={isActive}> |
| 5 | 745 |
<span className="material-icons">{icon}</span> |
746 |
</span> |
|
747 |
) |
|
748 |
} |
|
749 |
||
| 172 | 750 |
renderNode = (props, editor, next) => { |
| 157 | 751 |
const { attributes, children, node } = props |
752 |
||
753 |
switch (node.type) { |
|
754 |
case 'block-quote': |
|
755 |
return <blockquote {...attributes}>{children}</blockquote> |
|
756 |
case 'bulleted-list': |
|
757 |
return <ul {...attributes}>{children}</ul> |
|
758 |
case 'heading-one': |
|
759 |
return <h1 {...attributes}>{children}</h1> |
|
760 |
case 'heading-two': |
|
761 |
return <h2 {...attributes}>{children}</h2> |
|
762 |
case 'list-item': |
|
763 |
return <li {...attributes}>{children}</li> |
|
764 |
case 'numbered-list': |
|
765 |
return <ol {...attributes}>{children}</ol> |
|
|
168
ea92f4fe783d
- move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents:
161
diff
changeset
|
766 |
default: |
| 172 | 767 |
return next(); |
| 157 | 768 |
} |
769 |
} |
|
770 |
||
| 5 | 771 |
/** |
772 |
* Render the Slate editor. |
|
773 |
* |
|
774 |
* @return {Element} |
|
775 |
*/ |
|
776 |
||
777 |
renderEditor = () => { |
|
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
778 |
const t = this.props.t; |
| 5 | 779 |
return ( |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
780 |
<div className="editor-slatejs p-2"> |
| 172 | 781 |
{/* {this.renderHoveringMenu()} */} |
| 5 | 782 |
<Editor |
| 172 | 783 |
ref={this.editorRef} |
| 5 | 784 |
spellCheck |
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
785 |
placeholder={t('slate_editor.placeholder')} |
| 172 | 786 |
// schema={schema} |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
787 |
plugins={plugins} |
| 157 | 788 |
value={this.state.value} |
| 5 | 789 |
onChange={this.onChange} |
| 172 | 790 |
// onKeyDown={this.onKeyDown} |
| 157 | 791 |
renderMark={this.renderMark} |
792 |
renderNode = {this.renderNode} |
|
| 5 | 793 |
/> |
794 |
</div> |
|
795 |
) |
|
796 |
} |
|
797 |
||
| 172 | 798 |
// renderHoveringMenu = () => { |
799 |
// return ( |
|
800 |
// <Portal ref="portal" |
|
801 |
// isOpened={this.state.isPortalOpen} isOpen={this.state.isPortalOpen} |
|
802 |
// onOpen={this.onPortalOpen} |
|
803 |
// onClose={this.onPortalClose} |
|
804 |
// closeOnOutsideClick={false} closeOnEsc={true}> |
|
805 |
// <div className="hovering-menu"> |
|
806 |
// <CategoriesTooltip categories={this.props.annotationCategories || defaultAnnotationsCategories} onCategoryClick={this.onCategoryClick} /> |
|
807 |
// </div> |
|
808 |
// </Portal> |
|
809 |
// ) |
|
810 |
// } |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
811 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
812 |
updateMenu = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
813 |
|
| 172 | 814 |
// const { hoveringMenu } = this.state |
815 |
const hoveringMenu = this.hoveringMenuRef.current; |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
816 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
817 |
if (!hoveringMenu) return |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
818 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
819 |
// if (state.isBlurred || state.isCollapsed) { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
820 |
// hoveringMenu.removeAttribute('style') |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
821 |
// return |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
822 |
// } |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
823 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
824 |
const selection = window.getSelection() |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
825 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
826 |
if (selection.isCollapsed) { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
827 |
return |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
828 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
829 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
830 |
const range = selection.getRangeAt(0) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
831 |
const rect = range.getBoundingClientRect() |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
832 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
833 |
hoveringMenu.style.opacity = 1 |
| 172 | 834 |
hoveringMenu.style.top = `${rect.top + rect.height + window.scrollY + hoveringMenu.offsetHeight}px` |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
835 |
hoveringMenu.style.left = `${rect.left + window.scrollX - hoveringMenu.offsetWidth / 2 + rect.width / 2}px` |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
836 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
837 |
|
| 5 | 838 |
} |
839 |
||
840 |
/** |
|
841 |
* Export. |
|
842 |
*/ |
|
843 |
||
|
171
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
844 |
export default withNamespaces("", { |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
845 |
innerRef: (ref) => { |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
846 |
const editorRef = (ref && ref.props) ? ref.props.editorRef : null; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
847 |
if(editorRef && editorRef.hasOwnProperty('current')) { |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
848 |
editorRef.current = ref; |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
849 |
} |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
850 |
} |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
851 |
})(SlateEditor); |
|
03334a31130a
Add translation with react-i18next
ymh <ymh.work@gmail.com>
parents:
170
diff
changeset
|
852 |
// export default SlateEditor; |