@pie-lib/editable-html 10.0.0-beta.7 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +1 -1
- package/CHANGELOG.md +81 -0
- package/LICENSE.md +5 -0
- package/lib/editor.js +410 -543
- package/lib/editor.js.map +1 -1
- package/lib/index.js +200 -101
- package/lib/index.js.map +1 -1
- package/lib/parse-html.js +5 -6
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +12 -2
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +71 -19
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/html/icons/index.js +38 -0
- package/lib/plugins/html/icons/index.js.map +1 -0
- package/lib/plugins/html/index.js +75 -0
- package/lib/plugins/html/index.js.map +1 -0
- package/lib/plugins/image/alt-dialog.js +26 -0
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +124 -90
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +45 -7
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +91 -113
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +54 -72
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +71 -31
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +129 -58
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +152 -118
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +185 -168
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +197 -110
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +24 -4
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +65 -23
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +50 -10
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +22 -9
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +9 -4
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +18 -1
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +133 -122
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +10 -4
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +33 -15
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +7 -0
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +279 -390
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +47 -14
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +63 -51
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +9 -1
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +140 -83
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +5 -0
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +39 -8
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +261 -225
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +16 -19
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +70 -11
- package/lib/serialization.js.map +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +18 -17
- package/src/editor.jsx +139 -434
- package/src/index.jsx +96 -62
- package/src/plugins/characters/index.jsx +17 -12
- package/src/plugins/html/icons/index.jsx +19 -0
- package/src/plugins/html/index.jsx +68 -0
- package/src/plugins/image/component.jsx +38 -60
- package/src/plugins/image/index.jsx +42 -95
- package/src/plugins/image/insert-image-handler.js +27 -62
- package/src/plugins/index.jsx +39 -21
- package/src/plugins/list/index.jsx +90 -62
- package/src/plugins/math/index.jsx +70 -93
- package/src/plugins/media/index.jsx +117 -146
- package/src/plugins/media/media-dialog.js +9 -10
- package/src/plugins/media/media-wrapper.jsx +27 -29
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +4 -5
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +1 -2
- package/src/plugins/respArea/index.jsx +84 -114
- package/src/plugins/respArea/inline-dropdown/index.jsx +2 -3
- package/src/plugins/respArea/utils.jsx +28 -23
- package/src/plugins/table/index.jsx +214 -334
- package/src/plugins/table/table-toolbar.jsx +4 -3
- package/src/plugins/toolbar/default-toolbar.jsx +30 -48
- package/src/plugins/toolbar/editor-and-toolbar.jsx +114 -114
- package/src/plugins/toolbar/toolbar.jsx +224 -254
- package/src/plugins/utils.js +0 -16
- package/src/serialization.jsx +1 -1
- package/lib/components.js +0 -92
- package/lib/components.js.map +0 -1
- package/lib/new-serialization.js +0 -280
- package/lib/new-serialization.js.map +0 -1
- package/lib/plugins/hotKeys/index.js +0 -60
- package/lib/plugins/hotKeys/index.js.map +0 -1
- package/lib/test-serializer.js +0 -138
- package/lib/test-serializer.js.map +0 -1
- package/src/components.js +0 -135
- package/src/new-serialization.jsx +0 -310
- package/src/plugins/hotKeys/index.js +0 -54
- package/src/test-serializer.js +0 -132
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { Change
|
|
3
|
-
import { useSlate, useSlateSelection } from 'slate-react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Change } from 'slate';
|
|
4
3
|
import Delete from '@material-ui/icons/Delete';
|
|
5
4
|
import IconButton from '@material-ui/core/IconButton';
|
|
6
5
|
import PropTypes from 'prop-types';
|
|
7
6
|
import classNames from 'classnames';
|
|
8
7
|
import debug from 'debug';
|
|
8
|
+
import SlatePropTypes from 'slate-prop-types';
|
|
9
9
|
import debounce from 'lodash/debounce';
|
|
10
10
|
|
|
11
11
|
import { DoneButton } from './done-button';
|
|
12
12
|
|
|
13
|
+
import { findSingleNode, findParentNode } from '../utils';
|
|
13
14
|
import { withStyles } from '@material-ui/core/styles';
|
|
14
15
|
import DefaultToolbar from './default-toolbar';
|
|
15
16
|
import { removeDialogs as removeCharacterDialogs } from '../characters';
|
|
16
17
|
|
|
17
18
|
const log = debug('@pie-lib:editable-html:plugins:toolbar');
|
|
18
19
|
|
|
19
|
-
const getCustomToolbar = (plugin, node,
|
|
20
|
+
const getCustomToolbar = (plugin, node, value, handleDone, onDataChange) => {
|
|
20
21
|
if (!plugin) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
@@ -33,74 +34,58 @@ const getCustomToolbar = (plugin, node, nodePath, editor, handleDone) => {
|
|
|
33
34
|
return plugin.toolbar.CustomToolbarComp;
|
|
34
35
|
} else if (typeof plugin.toolbar.customToolbar === 'function') {
|
|
35
36
|
log('deprecated - use CustomToolbarComp');
|
|
36
|
-
return plugin.toolbar.customToolbar(node,
|
|
37
|
+
return plugin.toolbar.customToolbar(node, value, handleDone, onDataChange);
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
fullWidth: {
|
|
65
|
-
width: '100%',
|
|
66
|
-
},
|
|
67
|
-
autoWidth: {
|
|
68
|
-
width: 'auto',
|
|
69
|
-
},
|
|
70
|
-
focused: {
|
|
71
|
-
display: 'flex',
|
|
72
|
-
},
|
|
73
|
-
iconRoot: {
|
|
74
|
-
width: '28px',
|
|
75
|
-
height: '28px',
|
|
76
|
-
padding: '4px',
|
|
77
|
-
verticalAlign: 'top',
|
|
78
|
-
},
|
|
79
|
-
label: {
|
|
80
|
-
color: 'var(--editable-html-toolbar-check, #00bb00)',
|
|
81
|
-
},
|
|
82
|
-
shared: {
|
|
83
|
-
display: 'flex',
|
|
84
|
-
},
|
|
85
|
-
};
|
|
41
|
+
export class Toolbar extends React.Component {
|
|
42
|
+
static propTypes = {
|
|
43
|
+
zIndex: PropTypes.number,
|
|
44
|
+
value: SlatePropTypes.value.isRequired,
|
|
45
|
+
plugins: PropTypes.array,
|
|
46
|
+
plugin: PropTypes.object,
|
|
47
|
+
onImageClick: PropTypes.func,
|
|
48
|
+
onDone: PropTypes.func.isRequired,
|
|
49
|
+
toolbarRef: PropTypes.func.isRequired,
|
|
50
|
+
classes: PropTypes.object.isRequired,
|
|
51
|
+
isFocused: PropTypes.bool,
|
|
52
|
+
autoWidth: PropTypes.bool,
|
|
53
|
+
onChange: PropTypes.func.isRequired,
|
|
54
|
+
getFocusedValue: PropTypes.func.isRequired,
|
|
55
|
+
pluginProps: PropTypes.object,
|
|
56
|
+
toolbarOpts: PropTypes.shape({
|
|
57
|
+
position: PropTypes.oneOf(['bottom', 'top']),
|
|
58
|
+
alignment: PropTypes.oneOf(['left', 'right']),
|
|
59
|
+
alwaysVisible: PropTypes.bool,
|
|
60
|
+
ref: PropTypes.func,
|
|
61
|
+
showDone: PropTypes.bool,
|
|
62
|
+
}),
|
|
63
|
+
onDataChange: PropTypes.func,
|
|
64
|
+
};
|
|
86
65
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
66
|
+
constructor(props) {
|
|
67
|
+
super(props);
|
|
68
|
+
this.state = {
|
|
69
|
+
change: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
91
72
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
componentWillUnmount() {
|
|
74
|
+
removeCharacterDialogs();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
hasMark = (type) => {
|
|
78
|
+
const { value } = this.props;
|
|
79
|
+
return value.marks.some((mark) => mark.type == type);
|
|
95
80
|
};
|
|
96
81
|
|
|
97
|
-
|
|
98
|
-
const { value } = props;
|
|
99
|
-
return value.blocks.some((node) => node.type
|
|
82
|
+
hasBlock = (type) => {
|
|
83
|
+
const { value } = this.props;
|
|
84
|
+
return value.blocks.some((node) => node.type == type);
|
|
100
85
|
};
|
|
101
86
|
|
|
102
|
-
|
|
103
|
-
const { value, onChange } = props;
|
|
87
|
+
onToggle = (plugin) => {
|
|
88
|
+
const { value, onChange } = this.props;
|
|
104
89
|
|
|
105
90
|
if (!plugin.onToggle) return;
|
|
106
91
|
|
|
@@ -108,24 +93,25 @@ export const Toolbar = (props) => {
|
|
|
108
93
|
onChange(change);
|
|
109
94
|
};
|
|
110
95
|
|
|
111
|
-
|
|
96
|
+
onClick = (e) => {
|
|
112
97
|
log('[onClick]');
|
|
113
98
|
e.preventDefault();
|
|
114
99
|
};
|
|
115
100
|
|
|
116
|
-
|
|
101
|
+
onButtonClick = (fn) => {
|
|
117
102
|
return (e) => {
|
|
118
103
|
e.preventDefault();
|
|
119
104
|
fn();
|
|
120
105
|
};
|
|
121
106
|
};
|
|
122
107
|
|
|
123
|
-
|
|
124
|
-
log('[onToolbarDone] change: ',
|
|
125
|
-
const { onChange, onDone } = props;
|
|
108
|
+
onToolbarDone = (change, finishEditing) => {
|
|
109
|
+
log('[onToolbarDone] change: ', change, 'finishEditing: ', finishEditing);
|
|
110
|
+
const { onChange, onDone } = this.props;
|
|
126
111
|
|
|
127
|
-
if
|
|
128
|
-
|
|
112
|
+
// use handler only if this is an actual Slate Change
|
|
113
|
+
if (change instanceof Change) {
|
|
114
|
+
onChange(change, () => {
|
|
129
115
|
if (finishEditing) {
|
|
130
116
|
onDone();
|
|
131
117
|
}
|
|
@@ -138,208 +124,192 @@ export const Toolbar = (props) => {
|
|
|
138
124
|
}
|
|
139
125
|
};
|
|
140
126
|
|
|
141
|
-
|
|
142
|
-
(e, plugin, node, nodePath, editor, onChange) => plugin.deleteNode(e, node, nodePath, editor, onChange),
|
|
143
|
-
500,
|
|
144
|
-
);
|
|
127
|
+
onDeleteClick = debounce((e, plugin, node, value, onChange) => plugin.deleteNode(e, node, value, onChange), 500);
|
|
145
128
|
|
|
146
|
-
|
|
129
|
+
onDeleteMouseDown = (e, plugin, node, value, onChange) => {
|
|
147
130
|
e.persist();
|
|
148
|
-
onDeleteClick(e, plugin, node,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const {
|
|
152
|
-
classes,
|
|
153
|
-
plugins,
|
|
154
|
-
pluginProps,
|
|
155
|
-
toolbarOpts,
|
|
156
|
-
value,
|
|
157
|
-
autoWidth,
|
|
158
|
-
onChange,
|
|
159
|
-
getFocusedValue,
|
|
160
|
-
isFocused,
|
|
161
|
-
onDone,
|
|
162
|
-
toolbarRef,
|
|
163
|
-
} = props;
|
|
164
|
-
|
|
165
|
-
const editor = useSlate();
|
|
166
|
-
const selection = useSlateSelection();
|
|
167
|
-
const getNode = (editor, selection, depth) => {
|
|
168
|
-
if (!selection) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// this means we have selected text
|
|
173
|
-
if (selection.anchor.offset !== selection.focus.offset) {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const [node, path] = Editor.node(editor, selection, depth ? { depth } : undefined);
|
|
178
|
-
|
|
179
|
-
if (!node) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (!Text.isText(node)) {
|
|
184
|
-
return [node, path];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return getNode(editor, selection, path.length - 1);
|
|
131
|
+
this.onDeleteClick(e, plugin, node, value, onChange);
|
|
188
132
|
};
|
|
189
|
-
const getParentNode = (editor, path) => Array.isArray(path) && path.length > 0 && Editor.parent(editor, path);
|
|
190
133
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
134
|
+
render() {
|
|
135
|
+
const {
|
|
136
|
+
classes,
|
|
137
|
+
plugins,
|
|
138
|
+
pluginProps,
|
|
139
|
+
toolbarOpts,
|
|
140
|
+
value,
|
|
141
|
+
autoWidth,
|
|
142
|
+
onChange,
|
|
143
|
+
getFocusedValue,
|
|
144
|
+
isFocused,
|
|
145
|
+
onDone,
|
|
146
|
+
toolbarRef,
|
|
147
|
+
} = this.props;
|
|
148
|
+
|
|
149
|
+
const node = findSingleNode(value);
|
|
150
|
+
const parentNode = findParentNode(value, node);
|
|
151
|
+
|
|
152
|
+
log(' --------------> [render] node: ', node);
|
|
153
|
+
log('[render] node: ', node);
|
|
154
|
+
|
|
155
|
+
const plugin = plugins.find((p) => {
|
|
156
|
+
if (!node) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
201
159
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
160
|
+
if (p.toolbar) {
|
|
161
|
+
return p.toolbar.supports && p.toolbar.supports(node, value);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const parentPlugin = plugins.find((p) => {
|
|
165
|
+
if (!parentNode) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
210
168
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
169
|
+
if (p.toolbar) {
|
|
170
|
+
return p.toolbar.supports && p.toolbar.supports(parentNode, value);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
215
173
|
|
|
216
|
-
|
|
174
|
+
log('[render] plugin: ', plugin);
|
|
217
175
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
let handler = onDone;
|
|
176
|
+
const handleDone = (change, done) => {
|
|
177
|
+
let handler = onDone;
|
|
221
178
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
179
|
+
if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
|
|
180
|
+
handler = this.onToolbarDone;
|
|
181
|
+
}
|
|
225
182
|
|
|
226
|
-
|
|
227
|
-
editor.selection = null;
|
|
228
|
-
}
|
|
183
|
+
handler(change, done);
|
|
229
184
|
|
|
230
|
-
|
|
185
|
+
if (parentPlugin && parentPlugin.handleDone) {
|
|
186
|
+
parentPlugin.handleDone(value, node, plugin, onChange);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
231
189
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
};
|
|
190
|
+
const handleDataChange = (key, data) => {
|
|
191
|
+
this.props.onDataChange(key, data);
|
|
192
|
+
};
|
|
236
193
|
|
|
237
|
-
|
|
238
|
-
getCustomToolbar(plugin, node, nodePath, editor, handleDone) ||
|
|
239
|
-
getCustomToolbar(parentPlugin, node, nodePath, editor, handleDone);
|
|
194
|
+
const CustomToolbar = getCustomToolbar(plugin, node, value, handleDone, this.props.onDataChange);
|
|
240
195
|
|
|
241
|
-
|
|
196
|
+
const filteredPlugins = plugin && plugin.filterPlugins ? plugin.filterPlugins(node, plugins) : plugins;
|
|
242
197
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
198
|
+
log('[render] CustomToolbar: ', CustomToolbar);
|
|
199
|
+
const parentExtraStyles =
|
|
200
|
+
parentPlugin && parentPlugin.pluginStyles ? parentPlugin.pluginStyles(node, parentNode, plugin) : {};
|
|
201
|
+
const pluginExtraStyles = plugin && plugin.pluginStyles ? plugin.pluginStyles(node, parentNode, plugin) : {};
|
|
202
|
+
const extraStyles = {
|
|
203
|
+
...pluginExtraStyles,
|
|
204
|
+
...parentExtraStyles,
|
|
205
|
+
};
|
|
251
206
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
deletable={deletable}
|
|
293
|
-
/>
|
|
294
|
-
)}
|
|
295
|
-
|
|
296
|
-
<div className={classes.shared}>
|
|
297
|
-
{deletable && (
|
|
298
|
-
<IconButton
|
|
299
|
-
aria-label="Delete"
|
|
300
|
-
className={classes.iconRoot}
|
|
301
|
-
onMouseDown={(e) => onDeleteMouseDown(e)}
|
|
302
|
-
classes={{
|
|
303
|
-
root: classes.iconRoot,
|
|
304
|
-
}}
|
|
305
|
-
>
|
|
306
|
-
<Delete />
|
|
307
|
-
</IconButton>
|
|
207
|
+
const deletable = node && plugin && plugin.deleteNode;
|
|
208
|
+
const customToolbarShowDone =
|
|
209
|
+
node && plugin && plugin.toolbar && plugin.toolbar.showDone && !toolbarOpts.alwaysVisible;
|
|
210
|
+
|
|
211
|
+
// If there is a toolbarOpts we check if the showDone is not equal to false
|
|
212
|
+
const defaultToolbarShowDone = !toolbarOpts || toolbarOpts.showDone !== false;
|
|
213
|
+
|
|
214
|
+
const hasDoneButton = defaultToolbarShowDone || customToolbarShowDone;
|
|
215
|
+
|
|
216
|
+
const names = classNames(classes.toolbar, {
|
|
217
|
+
[classes.toolbarWithNoDone]: !hasDoneButton,
|
|
218
|
+
[classes.toolbarTop]: toolbarOpts.position === 'top',
|
|
219
|
+
[classes.toolbarRight]: toolbarOpts.alignment === 'right',
|
|
220
|
+
[classes.focused]: toolbarOpts.alwaysVisible || isFocused,
|
|
221
|
+
[classes.autoWidth]: autoWidth,
|
|
222
|
+
[classes.fullWidth]: !autoWidth,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<div className={names} style={extraStyles} onClick={this.onClick} ref={toolbarRef}>
|
|
227
|
+
{CustomToolbar ? (
|
|
228
|
+
<CustomToolbar
|
|
229
|
+
node={node}
|
|
230
|
+
value={value}
|
|
231
|
+
onToolbarDone={this.onToolbarDone}
|
|
232
|
+
onDataChange={handleDataChange}
|
|
233
|
+
pluginProps={pluginProps}
|
|
234
|
+
/>
|
|
235
|
+
) : (
|
|
236
|
+
<DefaultToolbar
|
|
237
|
+
plugins={filteredPlugins}
|
|
238
|
+
pluginProps={pluginProps}
|
|
239
|
+
value={value}
|
|
240
|
+
onChange={onChange}
|
|
241
|
+
getFocusedValue={getFocusedValue}
|
|
242
|
+
showDone={defaultToolbarShowDone}
|
|
243
|
+
onDone={handleDone}
|
|
244
|
+
deletable={deletable}
|
|
245
|
+
isHtmlMode={toolbarOpts.isHtmlMode}
|
|
246
|
+
/>
|
|
308
247
|
)}
|
|
309
|
-
|
|
248
|
+
|
|
249
|
+
<div className={classes.shared}>
|
|
250
|
+
{deletable && (
|
|
251
|
+
<IconButton
|
|
252
|
+
aria-label="Delete"
|
|
253
|
+
className={classes.iconRoot}
|
|
254
|
+
onMouseDown={(e) => this.onDeleteMouseDown(e, plugin, node, value, onChange)}
|
|
255
|
+
classes={{
|
|
256
|
+
root: classes.iconRoot,
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
<Delete />
|
|
260
|
+
</IconButton>
|
|
261
|
+
)}
|
|
262
|
+
{customToolbarShowDone && <DoneButton onClick={handleDone} />}
|
|
263
|
+
</div>
|
|
310
264
|
</div>
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
314
268
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
269
|
+
const style = {
|
|
270
|
+
toolbar: {
|
|
271
|
+
position: 'absolute',
|
|
272
|
+
zIndex: 10,
|
|
273
|
+
cursor: 'pointer',
|
|
274
|
+
justifyContent: 'space-between',
|
|
275
|
+
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
276
|
+
minWidth: '280px',
|
|
277
|
+
margin: '5px 0 0 0',
|
|
278
|
+
padding: '2px',
|
|
279
|
+
boxShadow:
|
|
280
|
+
'0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',
|
|
281
|
+
boxSizing: 'border-box',
|
|
282
|
+
display: 'none',
|
|
283
|
+
},
|
|
284
|
+
toolbarWithNoDone: {
|
|
285
|
+
minWidth: '265px',
|
|
286
|
+
},
|
|
287
|
+
toolbarTop: {
|
|
288
|
+
top: '-45px',
|
|
289
|
+
},
|
|
290
|
+
toolbarRight: {
|
|
291
|
+
right: 0,
|
|
292
|
+
},
|
|
293
|
+
fullWidth: {
|
|
294
|
+
width: '100%',
|
|
295
|
+
},
|
|
296
|
+
autoWidth: {
|
|
297
|
+
width: 'auto',
|
|
298
|
+
},
|
|
299
|
+
focused: {
|
|
300
|
+
display: 'flex',
|
|
301
|
+
},
|
|
302
|
+
iconRoot: {
|
|
303
|
+
width: '28px',
|
|
304
|
+
height: '28px',
|
|
305
|
+
padding: '4px',
|
|
306
|
+
verticalAlign: 'top',
|
|
307
|
+
},
|
|
308
|
+
label: {
|
|
309
|
+
color: 'var(--editable-html-toolbar-check, #00bb00)',
|
|
310
|
+
},
|
|
311
|
+
shared: {
|
|
312
|
+
display: 'flex',
|
|
313
|
+
},
|
|
343
314
|
};
|
|
344
|
-
|
|
345
315
|
export default withStyles(style, { index: 1000 })(Toolbar);
|
package/src/plugins/utils.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Editor, Element as SlateElement } from 'slate';
|
|
2
|
-
|
|
3
1
|
export const findSingleNode = (value) => {
|
|
4
2
|
if (!value || !value.isCollapsed || !value.startKey) {
|
|
5
3
|
return;
|
|
@@ -30,18 +28,4 @@ export const hasMark = (value, type) => value && value.marks.some((mark) => mark
|
|
|
30
28
|
|
|
31
29
|
export const hasBlock = (value, type) => value && value.blocks.some((node) => node.type == type);
|
|
32
30
|
|
|
33
|
-
export const isBlockActive = (editor, format, blockType = 'type') => {
|
|
34
|
-
const { selection } = editor;
|
|
35
|
-
if (!selection) return false;
|
|
36
|
-
|
|
37
|
-
const [match] = Array.from(
|
|
38
|
-
Editor.nodes(editor, {
|
|
39
|
-
at: Editor.unhangRange(editor, selection),
|
|
40
|
-
match: (n) => !Editor.isEditor(n) && SlateElement.isElement(n) && n[blockType] === format,
|
|
41
|
-
}),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return !!match;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
31
|
export const hasNode = ({ document }, type) => document && document.nodes.some((node) => node.type == type);
|
package/src/serialization.jsx
CHANGED
|
@@ -119,7 +119,7 @@ const blocks = {
|
|
|
119
119
|
serialize: (object, children) => {
|
|
120
120
|
if (object.object !== 'block') return;
|
|
121
121
|
|
|
122
|
-
const jsonData = object.data;
|
|
122
|
+
const jsonData = object.data.toJSON();
|
|
123
123
|
|
|
124
124
|
log('[blocks:serialize] object: ', object, children);
|
|
125
125
|
let key;
|