| author | salimr <riwad.salim@yahoo.fr> |
| Mon, 08 Oct 2018 04:09:19 +0200 | |
| changeset 161 | a642639dbc07 |
| parent 159 | a4705c2b4544 |
| permissions | -rw-r--r-- |
| 157 | 1 |
import { Value } from 'slate' |
2 |
import Plain from 'slate-plain-serializer' |
|
3 |
import { Editor } from 'slate-react' |
|
| 5 | 4 |
import React from 'react' |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
5 |
import Portal from 'react-portal' |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
6 |
import Immutable from 'immutable' |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
7 |
import HtmlSerializer from '../HtmlSerializer' |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
8 |
import AnnotationPlugin from '../AnnotationPlugin' |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
9 |
import CategoriesTooltip from './CategoriesTooltip' |
|
161
a642639dbc07
Split scss files and adapt session page design
salimr <riwad.salim@yahoo.fr>
parents:
159
diff
changeset
|
10 |
import './SlateEditor.css'; |
|
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
|
11 |
import { now } from '../utils'; |
|
138
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
12 |
import { defaultAnnotationsCategories } from '../constants'; |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
13 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
14 |
const plugins = []; |
| 5 | 15 |
|
16 |
/** |
|
17 |
* Define the default node type. |
|
18 |
*/ |
|
19 |
||
20 |
const DEFAULT_NODE = 'paragraph' |
|
21 |
||
22 |
/** |
|
23 |
* Define a schema. |
|
24 |
* |
|
25 |
* @type {Object} |
|
26 |
*/ |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
27 |
// 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
|
28 |
// https://docs.slatejs.org/reference/plugins/plugin.html#schema |
| 5 | 29 |
const schema = { |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
30 |
|
| 5 | 31 |
nodes: { |
32 |
'bulleted-list': props => <ul {...props.attributes}>{props.children}</ul>, |
|
33 |
'list-item': props => <li {...props.attributes}>{props.children}</li>, |
|
34 |
'numbered-list': props => <ol {...props.attributes}>{props.children}</ol>, |
|
35 |
}, |
|
36 |
marks: { |
|
37 |
bold: { |
|
38 |
fontWeight: 'bold' |
|
39 |
}, |
|
|
25
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
40 |
category: props => { |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
41 |
const data = props.mark.data; |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
42 |
return <span style={{ backgroundColor: data.get('color') }}>{props.children}</span> |
| 5 | 43 |
}, |
44 |
italic: { |
|
45 |
fontStyle: 'italic' |
|
46 |
}, |
|
47 |
underlined: { |
|
| 157 | 48 |
textDecoration: 'underlined' |
| 5 | 49 |
} |
50 |
} |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
51 |
|
| 5 | 52 |
} |
53 |
||
| 157 | 54 |
const initialValue = Value.fromJSON({ |
55 |
document: { |
|
56 |
nodes: [ |
|
57 |
{ |
|
58 |
object: 'block', |
|
59 |
type: 'paragraph', |
|
60 |
nodes: [ |
|
61 |
{ |
|
62 |
object: 'text', |
|
63 |
leaves: [ |
|
64 |
{ |
|
65 |
text: '', |
|
66 |
}, |
|
67 |
], |
|
68 |
}, |
|
69 |
], |
|
70 |
}, |
|
71 |
], |
|
72 |
}, |
|
73 |
}) |
|
74 |
||
| 5 | 75 |
/** |
76 |
* The rich text example. |
|
77 |
* |
|
78 |
* @type {Component} |
|
79 |
*/ |
|
80 |
||
| 8 | 81 |
class SlateEditor extends React.Component { |
| 5 | 82 |
|
83 |
/** |
|
84 |
* Deserialize the initial editor state. |
|
85 |
* |
|
86 |
* @type {Object} |
|
87 |
*/ |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
88 |
constructor(props) { |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
89 |
super(props); |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
90 |
|
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
91 |
const annotationPlugin = AnnotationPlugin({ |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
92 |
onChange: (text, start, end) => { |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
93 |
this.setState({ |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
94 |
currentSelectionText: text, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
95 |
currentSelectionStart: start, |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
96 |
currentSelectionEnd: end, |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
97 |
}); |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
98 |
} |
|
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 |
plugins.push(annotationPlugin); |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
102 |
|
| 157 | 103 |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
104 |
this.state = { |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
105 |
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
|
106 |
startedAt: null, |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
107 |
finishedAt: null, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
108 |
currentSelectionText: '', |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
109 |
currentSelectionStart: 0, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
110 |
currentSelectionEnd: 0, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
111 |
hoveringMenu: null, |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
112 |
isPortalOpen: false, |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
113 |
categories: Immutable.List([]), |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
114 |
isCheckboxChecked: false, |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
115 |
enterKeyValue: 0, |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
116 |
}; |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
117 |
} |
| 5 | 118 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
119 |
componentDidMount = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
120 |
this.updateMenu(); |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
121 |
this.focus(); |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
122 |
} |
| 5 | 123 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
124 |
componentDidUpdate = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
125 |
this.updateMenu(); |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
126 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
127 |
|
| 157 | 128 |
/** |
129 |
* On change, save the new state. |
|
| 5 | 130 |
* |
| 157 | 131 |
* @param {Change} change |
| 5 | 132 |
*/ |
133 |
||
| 157 | 134 |
onChange = ({value}) => { |
|
16
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 |
let newState = { |
| 157 | 137 |
value: value, |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
138 |
startedAt: this.state.startedAt |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
139 |
}; |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
140 |
|
| 157 | 141 |
const isEmpty = value.document.length === 0; |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
142 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
143 |
// Reset timers when the text is empty |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
144 |
if (isEmpty) { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
145 |
Object.assign(newState, { |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
146 |
startedAt: null, |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
147 |
finishedAt: null |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
148 |
}); |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
149 |
} 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
|
150 |
Object.assign(newState, { finishedAt: now() }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
151 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
152 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
153 |
// 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
|
154 |
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
|
155 |
Object.assign(newState, { startedAt: now() }); |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
156 |
} |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
157 |
|
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
158 |
this.setState(newState) |
|
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
159 |
|
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
160 |
if (typeof this.props.onChange === 'function') { |
|
16
e67cd18cc594
Draft implementation of note timing.
Alexandre Segura <mex.zktk@gmail.com>
parents:
15
diff
changeset
|
161 |
this.props.onChange(newState); |
| 8 | 162 |
} |
| 5 | 163 |
} |
164 |
||
| 157 | 165 |
/** |
166 |
* Check if the current selection has a mark with `type` in it. |
|
167 |
* |
|
168 |
* @param {String} type |
|
169 |
* @return {Boolean} |
|
170 |
*/ |
|
171 |
||
172 |
hasMark = type => { |
|
173 |
const { value } = this.state |
|
174 |
return value.activeMarks.some(mark => mark.type === type) |
|
175 |
} |
|
176 |
||
177 |
/** |
|
178 |
* Check if the any of the currently selected blocks are of `type`. |
|
179 |
* |
|
180 |
* @param {String} type |
|
181 |
* @return {Boolean} |
|
182 |
*/ |
|
183 |
||
184 |
hasBlock = type => { |
|
185 |
const { value } = this.state |
|
186 |
return value.blocks.some(node => node.type === type) |
|
187 |
} |
|
188 |
||
| 5 | 189 |
asPlain = () => { |
| 157 | 190 |
return Plain.serialize(this.state.value); |
| 5 | 191 |
} |
192 |
||
| 15 | 193 |
asRaw = () => { |
| 157 | 194 |
return JSON.stringify(this.state.value.toJSON()); |
| 15 | 195 |
} |
196 |
||
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
197 |
asHtml = () => { |
| 157 | 198 |
return HtmlSerializer.serialize(this.state.value); |
|
17
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
199 |
} |
|
877d8796b86d
Store serialized HTML in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
16
diff
changeset
|
200 |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
201 |
asCategories = () => { |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
202 |
return this.state.categories |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
203 |
} |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
204 |
|
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
205 |
removeCategory = (categories, key, text) => { |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
206 |
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
|
207 |
return categories.delete(categoryIndex) |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
208 |
} |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
209 |
|
| 5 | 210 |
clear = () => { |
| 157 | 211 |
const value = Plain.deserialize(''); |
212 |
this.onChange({value}); |
|
| 5 | 213 |
} |
214 |
||
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
215 |
focus = () => { |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
216 |
this.refs.editor.focus(); |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
217 |
} |
|
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
218 |
|
| 157 | 219 |
/** |
| 5 | 220 |
* When a mark button is clicked, toggle the current mark. |
221 |
* |
|
222 |
* @param {Event} e |
|
223 |
* @param {String} type |
|
224 |
*/ |
|
225 |
||
226 |
onClickMark = (e, type) => { |
|
| 157 | 227 |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
228 |
e.preventDefault() |
| 157 | 229 |
const { value } = this.state |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
230 |
let { categories } = this.state |
| 5 | 231 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
232 |
let isPortalOpen = false; |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
233 |
|
|
25
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
234 |
if (type === 'category') { |
|
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
235 |
// Can't use toggleMark here, because it expects the same object |
|
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
236 |
// @see https://github.com/ianstormtaylor/slate/issues/873 |
|
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
237 |
if (this.hasMark('category')) { |
| 157 | 238 |
const categoryMarks = value.activeMarks.filter(mark => mark.type === 'category') |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
239 |
categoryMarks.forEach(mark => { |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
240 |
const key = mark.data.get('key'); |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
241 |
const text = mark.data.get('text'); |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
242 |
|
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
243 |
categories = this.removeCategory(categories, key, text) |
| 157 | 244 |
const change = value.change().removeMark(mark) |
245 |
this.onChange(change) |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
246 |
}) |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
247 |
|
|
25
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
248 |
} else { |
|
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
249 |
isPortalOpen = !this.state.isPortalOpen; |
|
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
250 |
} |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
251 |
} else { |
| 157 | 252 |
const change = value.change().toggleMark(type) |
253 |
this.onChange(change) |
|
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
254 |
} |
|
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
255 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
256 |
this.setState({ |
| 157 | 257 |
state: value.change, |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
258 |
isPortalOpen: isPortalOpen, |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
259 |
categories: categories |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
260 |
}) |
| 5 | 261 |
} |
262 |
||
263 |
/** |
|
264 |
* When a block button is clicked, toggle the block type. |
|
265 |
* |
|
266 |
* @param {Event} e |
|
267 |
* @param {String} type |
|
268 |
*/ |
|
269 |
||
270 |
onClickBlock = (e, type) => { |
|
271 |
e.preventDefault() |
|
| 157 | 272 |
const { value } = this.state |
273 |
const change = value.change() |
|
274 |
const { document } = value |
|
| 5 | 275 |
|
276 |
// Handle everything but list buttons. |
|
277 |
if (type !== 'bulleted-list' && type !== 'numbered-list') { |
|
278 |
const isActive = this.hasBlock(type) |
|
279 |
const isList = this.hasBlock('list-item') |
|
280 |
||
281 |
if (isList) { |
|
| 157 | 282 |
change |
283 |
.setBlocks(isActive ? DEFAULT_NODE : type) |
|
| 5 | 284 |
.unwrapBlock('bulleted-list') |
285 |
.unwrapBlock('numbered-list') |
|
286 |
} |
|
287 |
||
288 |
else { |
|
| 157 | 289 |
change |
290 |
.setBlocks(isActive ? DEFAULT_NODE : type) |
|
| 5 | 291 |
} |
292 |
} |
|
293 |
||
294 |
// Handle the extra wrapping required for list buttons. |
|
295 |
else { |
|
296 |
const isList = this.hasBlock('list-item') |
|
| 157 | 297 |
const isType = value.blocks.some((block) => { |
| 5 | 298 |
return !!document.getClosest(block.key, parent => parent.type === type) |
299 |
}) |
|
300 |
||
301 |
if (isList && isType) { |
|
| 157 | 302 |
change |
303 |
.setBlocks(DEFAULT_NODE) |
|
| 5 | 304 |
.unwrapBlock('bulleted-list') |
305 |
.unwrapBlock('numbered-list') |
|
| 157 | 306 |
|
| 5 | 307 |
} else if (isList) { |
| 157 | 308 |
change |
| 5 | 309 |
.unwrapBlock(type === 'bulleted-list' ? 'numbered-list' : 'bulleted-list') |
310 |
.wrapBlock(type) |
|
| 157 | 311 |
|
| 5 | 312 |
} else { |
| 157 | 313 |
change |
314 |
.setBlocks('list-item') |
|
| 5 | 315 |
.wrapBlock(type) |
| 157 | 316 |
|
| 5 | 317 |
} |
318 |
} |
|
319 |
||
| 157 | 320 |
|
321 |
this.onChange(change) |
|
| 5 | 322 |
} |
323 |
||
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
324 |
onPortalOpen = (portal) => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
325 |
// When the portal opens, cache the menu element. |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
326 |
this.setState({ hoveringMenu: portal.firstChild }) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
327 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
328 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
329 |
onPortalClose = (portal) => { |
| 157 | 330 |
let { value } = this.state |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
331 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
332 |
this.setState({ |
| 157 | 333 |
value: value.change, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
334 |
isPortalOpen: false |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
335 |
}) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
336 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
337 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
338 |
onCategoryClick = (category) => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
339 |
|
| 157 | 340 |
const { value, currentSelectionText, currentSelectionStart, currentSelectionEnd } = this.state; |
341 |
const change = value.change() |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
342 |
let { categories } = this.state; |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
343 |
|
| 157 | 344 |
const categoryMarks = value.activeMarks.filter(mark => mark.type === 'category') |
345 |
categoryMarks.forEach(mark => change.removeMark(mark)); |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
346 |
|
| 157 | 347 |
change.addMark({ |
|
25
e04714a1d4eb
Improve categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
21
diff
changeset
|
348 |
type: 'category', |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
349 |
data: { |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
350 |
text: currentSelectionText, |
|
102
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
351 |
selection: { |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
352 |
start: currentSelectionStart, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
353 |
end: currentSelectionEnd, |
|
b0e36664f1f2
Add TextPositionSelector.
Alexandre Segura <mex.zktk@gmail.com>
parents:
80
diff
changeset
|
354 |
}, |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
355 |
color: category.color, |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
356 |
key: category.key |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
357 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
358 |
}) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
359 |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
360 |
Object.assign(category, { |
| 103 | 361 |
text: currentSelectionText, |
362 |
selection: { |
|
363 |
start: currentSelectionStart, |
|
364 |
end: currentSelectionEnd, |
|
365 |
}, |
|
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
366 |
}); |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
367 |
categories = categories.push(category); |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
368 |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
369 |
this.onChange(change) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
370 |
|
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
371 |
this.setState({ |
|
26
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
372 |
isPortalOpen: false, |
|
930e486ad0a8
Store categories in note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
25
diff
changeset
|
373 |
categories: categories |
|
21
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 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
376 |
|
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
377 |
onButtonClick = () => { |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
378 |
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
|
379 |
this.props.onButtonClick(); |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
380 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
381 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
382 |
|
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
383 |
onCheckboxChange = (e) => { |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
384 |
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
|
385 |
this.props.onCheckboxChange(e); |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
386 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
387 |
} |
|
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
64
diff
changeset
|
388 |
|
| 8 | 389 |
/** |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
390 |
* 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
|
391 |
* |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
392 |
* @param {Event} e |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
393 |
* @param {Change} change |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
394 |
* @return {Change} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
395 |
*/ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
396 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
397 |
onKeyDown = (e, change) => { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
398 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
399 |
const {value} = this.state; |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
400 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
401 |
// if (e.key === 'Enter' && value.document.text === '') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
402 |
// change.removeChild() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
403 |
// } |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
404 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
405 |
if (e.key === 'Enter' && value.document.text !== '') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
406 |
this.setState({enterKeyValue: 1}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
407 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
408 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
409 |
if (e.key !== 'Enter') { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
410 |
this.setState({ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
411 |
enterKeyValue: 0, |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
412 |
}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
413 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
414 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
415 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
416 |
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
|
417 |
e.preventDefault(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
418 |
this.props.onEnterKeyDown(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
419 |
this.setState({ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
420 |
enterKeyValue: 0, |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
421 |
}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
422 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
423 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
424 |
return change |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
425 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
426 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
427 |
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
|
428 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
429 |
e.preventDefault(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
430 |
this.props.onEnterKeyDown(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
431 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
432 |
return change |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
433 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
434 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
435 |
if (!e.ctrlKey) return |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
436 |
// 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
|
437 |
switch (e.key) { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
438 |
default: { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
439 |
break; |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
440 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
441 |
// 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
|
442 |
case 'b': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
443 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
444 |
change.toggleMark('bold') |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
445 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
446 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
447 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
448 |
case 'i': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
449 |
// 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
|
450 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
451 |
change.toggleMark('italic') |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
452 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
453 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
454 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
455 |
case 'u': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
456 |
// 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
|
457 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
458 |
change.toggleMark('underlined') |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
459 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
460 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
461 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
462 |
case 'Enter': { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
463 |
// When "ENTER" is pressed, autosubmit the note. |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
464 |
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
|
465 |
e.preventDefault() |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
466 |
this.props.onEnterKeyDown(); |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
467 |
this.setState({ |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
468 |
enterKeyValue: 0, |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
469 |
}) |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
470 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
471 |
return true |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
472 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
473 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
474 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
475 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
476 |
|
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
477 |
/** |
| 5 | 478 |
* Render. |
479 |
* |
|
480 |
* @return {Element} |
|
481 |
*/ |
|
482 |
||
483 |
render = () => { |
|
484 |
return ( |
|
| 157 | 485 |
<div className="bg-secondary mb-5"> |
486 |
<div className="sticky-top"> |
|
| 5 | 487 |
{this.renderToolbar()} |
| 157 | 488 |
</div> |
| 5 | 489 |
{this.renderEditor()} |
| 157 | 490 |
</div> |
| 5 | 491 |
) |
492 |
} |
|
493 |
||
494 |
/** |
|
495 |
* Render the toolbar. |
|
496 |
* |
|
497 |
* @return {Element} |
|
498 |
*/ |
|
499 |
||
500 |
renderToolbar = () => { |
|
501 |
return ( |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
502 |
<div className="menu toolbar-menu d-flex sticky-top bg-secondary"> |
| 157 | 503 |
{this.renderMarkButton('bold', 'format_bold')} |
504 |
{this.renderMarkButton('italic', 'format_italic')} |
|
505 |
{this.renderMarkButton('underlined', 'format_underlined')} |
|
506 |
{this.renderMarkButton('category', 'label')} |
|
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
507 |
|
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
508 |
|
| 157 | 509 |
{this.renderBlockButton('numbered-list', 'format_list_numbered')} |
510 |
{this.renderBlockButton('bulleted-list', 'format_list_bulleted')} |
|
511 |
||
512 |
{this.renderToolbarButtons()} |
|
| 5 | 513 |
</div> |
514 |
) |
|
515 |
} |
|
516 |
||
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
517 |
renderToolbarCheckbox = () => { |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
518 |
return ( |
| 157 | 519 |
<div className="checkbox float-right"> |
520 |
<label className="mr-2"> |
|
521 |
<input type="checkbox" checked={this.props.isChecked} onChange={this.onCheckboxChange} /><small className="text-muted ml-1"> Appuyer sur <kbd className="bg-danger text-muted ml-1">Entrée</kbd> pour ajouter une note</small> |
|
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
522 |
</label> |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
523 |
</div> |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
524 |
) |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
525 |
} |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
526 |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
527 |
renderSaveButton = () => { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
528 |
if (this.props.note) { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
529 |
return <button type="button" id="btn-editor" className="btn btn-primary btn-sm text-secondary font-weight-bold mr-2" disabled={this.props.isButtonDisabled} onClick={this.onButtonClick}> |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
530 |
Sauvegarder</button> |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
531 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
532 |
} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
533 |
|
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
534 |
renderToolbarButtons = () => { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
535 |
return ( |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
536 |
<div> |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
537 |
{/* <button type="button" id="btn-editor" className="btn btn-primary btn-sm text-secondary font-weight-bold float-right" disabled={this.props.isButtonDisabled} onClick={this.onButtonClick}> */} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
538 |
{/* { this.props.note ? 'Sauvegarder' : 'Ajouter' } */} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
539 |
{this.renderSaveButton()} |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
540 |
{/* </button> */} |
| 157 | 541 |
{ !this.props.note && this.renderToolbarCheckbox() } |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
542 |
</div> |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
543 |
); |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
544 |
} |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
74
diff
changeset
|
545 |
|
| 5 | 546 |
/** |
547 |
* Render a mark-toggling toolbar button. |
|
548 |
* |
|
549 |
* @param {String} type |
|
550 |
* @param {String} icon |
|
551 |
* @return {Element} |
|
552 |
*/ |
|
553 |
||
554 |
renderMarkButton = (type, icon) => { |
|
555 |
const isActive = this.hasMark(type) |
|
556 |
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
|
557 |
const markActivation = "button sticky-top" + ((!isActive)?" text-primary":" text-dark"); |
| 157 | 558 |
|
| 5 | 559 |
return ( |
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
560 |
// <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
|
561 |
<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
|
562 |
|
| 5 | 563 |
<span className="material-icons">{icon}</span> |
564 |
</span> |
|
565 |
) |
|
566 |
} |
|
567 |
||
| 157 | 568 |
// Add a `renderMark` method to render marks. |
569 |
||
570 |
renderMark = props => { |
|
571 |
const { children, mark, attributes } = props |
|
572 |
||
573 |
switch (mark.type) { |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
574 |
default: { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
575 |
break; |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
576 |
} |
| 157 | 577 |
case 'bold': |
578 |
return <strong {...attributes}>{children}</strong> |
|
579 |
case 'code': |
|
580 |
return <code {...attributes}>{children}</code> |
|
581 |
case 'italic': |
|
582 |
return <em {...attributes}>{children}</em> |
|
583 |
case 'underlined': |
|
584 |
return <ins {...attributes}>{children}</ins> |
|
585 |
} |
|
586 |
} |
|
| 5 | 587 |
/** |
588 |
* Render a block-toggling toolbar button. |
|
589 |
* |
|
590 |
* @param {String} type |
|
591 |
* @param {String} icon |
|
592 |
* @return {Element} |
|
593 |
*/ |
|
594 |
||
595 |
renderBlockButton = (type, icon) => { |
|
| 157 | 596 |
let isActive = this.hasBlock(type) |
597 |
||
598 |
if (['numbered-list', 'bulleted-list'].includes(type)) { |
|
599 |
const { value } = this.state |
|
600 |
const parent = value.document.getParent(value.blocks.first().key) |
|
601 |
isActive = this.hasBlock('list-item') && parent && parent.type === type |
|
602 |
} |
|
| 5 | 603 |
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
|
604 |
const blockActivation = "button sticky-top" + ((!isActive)?" text-primary":" text-dark"); |
| 5 | 605 |
|
606 |
return ( |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
607 |
<span className={blockActivation} onMouseDown={onMouseDown} data-active={isActive}> |
| 5 | 608 |
<span className="material-icons">{icon}</span> |
609 |
</span> |
|
610 |
) |
|
611 |
} |
|
612 |
||
| 157 | 613 |
renderNode = props => { |
614 |
const { attributes, children, node } = props |
|
615 |
||
616 |
switch (node.type) { |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
617 |
default: { |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
618 |
break; |
|
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
619 |
} |
| 157 | 620 |
case 'block-quote': |
621 |
return <blockquote {...attributes}>{children}</blockquote> |
|
622 |
case 'bulleted-list': |
|
623 |
return <ul {...attributes}>{children}</ul> |
|
624 |
case 'heading-one': |
|
625 |
return <h1 {...attributes}>{children}</h1> |
|
626 |
case 'heading-two': |
|
627 |
return <h2 {...attributes}>{children}</h2> |
|
628 |
case 'list-item': |
|
629 |
return <li {...attributes}>{children}</li> |
|
630 |
case 'numbered-list': |
|
631 |
return <ol {...attributes}>{children}</ol> |
|
632 |
} |
|
633 |
} |
|
634 |
||
| 5 | 635 |
/** |
636 |
* Render the Slate editor. |
|
637 |
* |
|
638 |
* @return {Element} |
|
639 |
*/ |
|
640 |
||
641 |
renderEditor = () => { |
|
642 |
return ( |
|
|
159
a4705c2b4544
Add send note options to the editor
salimr <riwad.salim@yahoo.fr>
parents:
157
diff
changeset
|
643 |
<div className="editor-slatejs p-2"> |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
644 |
{this.renderHoveringMenu()} |
| 5 | 645 |
<Editor |
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
646 |
ref="editor" |
| 5 | 647 |
spellCheck |
| 157 | 648 |
placeholder={'Votre espace de prise de note...'} |
| 5 | 649 |
schema={schema} |
|
19
f1b125b95fe9
Introduce "annotation" plugin.
Alexandre Segura <mex.zktk@gmail.com>
parents:
17
diff
changeset
|
650 |
plugins={plugins} |
| 157 | 651 |
value={this.state.value} |
| 5 | 652 |
onChange={this.onChange} |
653 |
onKeyDown={this.onKeyDown} |
|
| 157 | 654 |
renderMark={this.renderMark} |
655 |
renderNode = {this.renderNode} |
|
| 5 | 656 |
/> |
657 |
</div> |
|
658 |
) |
|
659 |
} |
|
660 |
||
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
661 |
renderHoveringMenu = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
662 |
return ( |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
663 |
<Portal ref="portal" |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
664 |
isOpened={this.state.isPortalOpen} isOpen={this.state.isPortalOpen} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
665 |
onOpen={this.onPortalOpen} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
666 |
onClose={this.onPortalClose} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
667 |
closeOnOutsideClick={false} closeOnEsc={true}> |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
668 |
<div className="hovering-menu"> |
|
138
a1fb2ced3049
propagate annotations categories from session protocol definition
ymh <ymh.work@gmail.com>
parents:
103
diff
changeset
|
669 |
<CategoriesTooltip categories={this.props.annotationCategories || defaultAnnotationsCategories} onCategoryClick={this.onCategoryClick} /> |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
670 |
</div> |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
671 |
</Portal> |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
672 |
) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
673 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
674 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
675 |
updateMenu = () => { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
676 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
35
diff
changeset
|
677 |
const { hoveringMenu } = this.state |
|
21
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
678 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
679 |
if (!hoveringMenu) return |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
680 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
681 |
// if (state.isBlurred || state.isCollapsed) { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
682 |
// hoveringMenu.removeAttribute('style') |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
683 |
// return |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
684 |
// } |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
685 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
686 |
const selection = window.getSelection() |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
687 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
688 |
if (selection.isCollapsed) { |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
689 |
return |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
690 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
691 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
692 |
const range = selection.getRangeAt(0) |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
693 |
const rect = range.getBoundingClientRect() |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
694 |
|
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
695 |
hoveringMenu.style.opacity = 1 |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
696 |
hoveringMenu.style.top = `${rect.top + window.scrollY + hoveringMenu.offsetHeight}px` |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
697 |
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
|
698 |
} |
|
284e866f55c7
First version of categories tooltip.
Alexandre Segura <mex.zktk@gmail.com>
parents:
19
diff
changeset
|
699 |
|
| 5 | 700 |
} |
701 |
||
702 |
/** |
|
703 |
* Export. |
|
704 |
*/ |
|
705 |
||
|
11
6fb4de54acea
Delete default state, focus on textarea.
Alexandre Segura <mex.zktk@gmail.com>
parents:
8
diff
changeset
|
706 |
export default SlateEditor |