@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.
Files changed (118) hide show
  1. package/CHANGELOG.json +1 -1
  2. package/CHANGELOG.md +81 -0
  3. package/LICENSE.md +5 -0
  4. package/lib/editor.js +410 -543
  5. package/lib/editor.js.map +1 -1
  6. package/lib/index.js +200 -101
  7. package/lib/index.js.map +1 -1
  8. package/lib/parse-html.js +5 -6
  9. package/lib/parse-html.js.map +1 -1
  10. package/lib/plugins/characters/custom-popper.js +12 -2
  11. package/lib/plugins/characters/custom-popper.js.map +1 -1
  12. package/lib/plugins/characters/index.js +71 -19
  13. package/lib/plugins/characters/index.js.map +1 -1
  14. package/lib/plugins/characters/utils.js.map +1 -1
  15. package/lib/plugins/html/icons/index.js +38 -0
  16. package/lib/plugins/html/icons/index.js.map +1 -0
  17. package/lib/plugins/html/index.js +75 -0
  18. package/lib/plugins/html/index.js.map +1 -0
  19. package/lib/plugins/image/alt-dialog.js +26 -0
  20. package/lib/plugins/image/alt-dialog.js.map +1 -1
  21. package/lib/plugins/image/component.js +124 -90
  22. package/lib/plugins/image/component.js.map +1 -1
  23. package/lib/plugins/image/image-toolbar.js +45 -7
  24. package/lib/plugins/image/image-toolbar.js.map +1 -1
  25. package/lib/plugins/image/index.js +91 -113
  26. package/lib/plugins/image/index.js.map +1 -1
  27. package/lib/plugins/image/insert-image-handler.js +54 -72
  28. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  29. package/lib/plugins/index.js +71 -31
  30. package/lib/plugins/index.js.map +1 -1
  31. package/lib/plugins/list/index.js +129 -58
  32. package/lib/plugins/list/index.js.map +1 -1
  33. package/lib/plugins/math/index.js +152 -118
  34. package/lib/plugins/math/index.js.map +1 -1
  35. package/lib/plugins/media/index.js +185 -168
  36. package/lib/plugins/media/index.js.map +1 -1
  37. package/lib/plugins/media/media-dialog.js +197 -110
  38. package/lib/plugins/media/media-dialog.js.map +1 -1
  39. package/lib/plugins/media/media-toolbar.js +24 -4
  40. package/lib/plugins/media/media-toolbar.js.map +1 -1
  41. package/lib/plugins/media/media-wrapper.js +65 -23
  42. package/lib/plugins/media/media-wrapper.js.map +1 -1
  43. package/lib/plugins/respArea/drag-in-the-blank/choice.js +50 -10
  44. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  45. package/lib/plugins/respArea/drag-in-the-blank/index.js +22 -9
  46. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  47. package/lib/plugins/respArea/explicit-constructed-response/index.js +9 -4
  48. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  49. package/lib/plugins/respArea/icons/index.js +18 -1
  50. package/lib/plugins/respArea/icons/index.js.map +1 -1
  51. package/lib/plugins/respArea/index.js +133 -122
  52. package/lib/plugins/respArea/index.js.map +1 -1
  53. package/lib/plugins/respArea/inline-dropdown/index.js +10 -4
  54. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  55. package/lib/plugins/respArea/utils.js +33 -15
  56. package/lib/plugins/respArea/utils.js.map +1 -1
  57. package/lib/plugins/table/icons/index.js +7 -0
  58. package/lib/plugins/table/icons/index.js.map +1 -1
  59. package/lib/plugins/table/index.js +279 -390
  60. package/lib/plugins/table/index.js.map +1 -1
  61. package/lib/plugins/table/table-toolbar.js +47 -14
  62. package/lib/plugins/table/table-toolbar.js.map +1 -1
  63. package/lib/plugins/toolbar/default-toolbar.js +63 -51
  64. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  65. package/lib/plugins/toolbar/done-button.js +9 -1
  66. package/lib/plugins/toolbar/done-button.js.map +1 -1
  67. package/lib/plugins/toolbar/editor-and-toolbar.js +140 -83
  68. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  69. package/lib/plugins/toolbar/index.js +5 -0
  70. package/lib/plugins/toolbar/index.js.map +1 -1
  71. package/lib/plugins/toolbar/toolbar-buttons.js +39 -8
  72. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  73. package/lib/plugins/toolbar/toolbar.js +261 -225
  74. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  75. package/lib/plugins/utils.js +16 -19
  76. package/lib/plugins/utils.js.map +1 -1
  77. package/lib/serialization.js +70 -11
  78. package/lib/serialization.js.map +1 -1
  79. package/lib/theme.js.map +1 -1
  80. package/package.json +18 -17
  81. package/src/editor.jsx +139 -434
  82. package/src/index.jsx +96 -62
  83. package/src/plugins/characters/index.jsx +17 -12
  84. package/src/plugins/html/icons/index.jsx +19 -0
  85. package/src/plugins/html/index.jsx +68 -0
  86. package/src/plugins/image/component.jsx +38 -60
  87. package/src/plugins/image/index.jsx +42 -95
  88. package/src/plugins/image/insert-image-handler.js +27 -62
  89. package/src/plugins/index.jsx +39 -21
  90. package/src/plugins/list/index.jsx +90 -62
  91. package/src/plugins/math/index.jsx +70 -93
  92. package/src/plugins/media/index.jsx +117 -146
  93. package/src/plugins/media/media-dialog.js +9 -10
  94. package/src/plugins/media/media-wrapper.jsx +27 -29
  95. package/src/plugins/respArea/drag-in-the-blank/index.jsx +4 -5
  96. package/src/plugins/respArea/explicit-constructed-response/index.jsx +1 -2
  97. package/src/plugins/respArea/index.jsx +84 -114
  98. package/src/plugins/respArea/inline-dropdown/index.jsx +2 -3
  99. package/src/plugins/respArea/utils.jsx +28 -23
  100. package/src/plugins/table/index.jsx +214 -334
  101. package/src/plugins/table/table-toolbar.jsx +4 -3
  102. package/src/plugins/toolbar/default-toolbar.jsx +30 -48
  103. package/src/plugins/toolbar/editor-and-toolbar.jsx +114 -114
  104. package/src/plugins/toolbar/toolbar.jsx +224 -254
  105. package/src/plugins/utils.js +0 -16
  106. package/src/serialization.jsx +1 -1
  107. package/lib/components.js +0 -92
  108. package/lib/components.js.map +0 -1
  109. package/lib/new-serialization.js +0 -280
  110. package/lib/new-serialization.js.map +0 -1
  111. package/lib/plugins/hotKeys/index.js +0 -60
  112. package/lib/plugins/hotKeys/index.js.map +0 -1
  113. package/lib/test-serializer.js +0 -138
  114. package/lib/test-serializer.js.map +0 -1
  115. package/src/components.js +0 -135
  116. package/src/new-serialization.jsx +0 -310
  117. package/src/plugins/hotKeys/index.js +0 -54
  118. package/src/test-serializer.js +0 -132
@@ -1,22 +1,23 @@
1
- import React, { useEffect } from 'react';
2
- import { Change, Editor, Element as SlateElement, Text, Node } from 'slate';
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, nodePath, editor, handleDone) => {
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, nodePath, editor, handleDone);
37
+ return plugin.toolbar.customToolbar(node, value, handleDone, onDataChange);
37
38
  }
38
39
  };
39
40
 
40
- const style = {
41
- toolbar: {
42
- position: 'absolute',
43
- zIndex: 10,
44
- cursor: 'pointer',
45
- justifyContent: 'space-between',
46
- background: 'var(--editable-html-toolbar-bg, #efefef)',
47
- minWidth: '280px',
48
- margin: '5px 0 0 0',
49
- padding: '2px',
50
- boxShadow:
51
- '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)',
52
- boxSizing: 'border-box',
53
- display: 'none',
54
- },
55
- toolbarWithNoDone: {
56
- minWidth: '265px',
57
- },
58
- toolbarTop: {
59
- top: '-45px',
60
- },
61
- toolbarRight: {
62
- right: 0,
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
- export const Toolbar = (props) => {
88
- useEffect(() => {
89
- return () => removeCharacterDialogs();
90
- }, []);
66
+ constructor(props) {
67
+ super(props);
68
+ this.state = {
69
+ change: null,
70
+ };
71
+ }
91
72
 
92
- const hasMark = (type) => {
93
- const { value } = props;
94
- return value.marks.some((mark) => mark.type === type);
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
- const hasBlock = (type) => {
98
- const { value } = props;
99
- return value.blocks.some((node) => node.type === type);
82
+ hasBlock = (type) => {
83
+ const { value } = this.props;
84
+ return value.blocks.some((node) => node.type == type);
100
85
  };
101
86
 
102
- const onToggle = (plugin) => {
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
- const onClick = (e) => {
96
+ onClick = (e) => {
112
97
  log('[onClick]');
113
98
  e.preventDefault();
114
99
  };
115
100
 
116
- const onButtonClick = (fn) => {
101
+ onButtonClick = (fn) => {
117
102
  return (e) => {
118
103
  e.preventDefault();
119
104
  fn();
120
105
  };
121
106
  };
122
107
 
123
- const onToolbarDone = (editor, finishEditing) => {
124
- log('[onToolbarDone] change: ', editor, 'finishEditing: ', finishEditing);
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 (editor) {
128
- onChange(editor, () => {
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
- const onDeleteClick = debounce(
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
- const onDeleteMouseDown = (e) => {
129
+ onDeleteMouseDown = (e, plugin, node, value, onChange) => {
147
130
  e.persist();
148
- onDeleteClick(e, plugin, node, nodePath, editor, onChange);
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
- const [node, nodePath] = getNode(editor, selection) || [];
192
- const [parentNode] = getParentNode(editor, nodePath) || [];
193
-
194
- log(' --------------> [render] node: ', node);
195
- log('[render] node: ', node);
196
-
197
- const plugin = plugins.find((p) => {
198
- if (!node) {
199
- return;
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
- if (p.toolbar) {
203
- return p.supports && p.supports(node, editor, value);
204
- }
205
- });
206
- const parentPlugin = plugins.find((p) => {
207
- if (!parentNode) {
208
- return;
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
- if (p.toolbar) {
212
- return p.supports && p.supports(parentNode, editor, value);
213
- }
214
- });
169
+ if (p.toolbar) {
170
+ return p.toolbar.supports && p.toolbar.supports(parentNode, value);
171
+ }
172
+ });
215
173
 
216
- log('[render] plugin: ', plugin);
174
+ log('[render] plugin: ', plugin);
217
175
 
218
- const handleDone = (done) => {
219
- const isDone = done ? editor : null;
220
- let handler = onDone;
176
+ const handleDone = (change, done) => {
177
+ let handler = onDone;
221
178
 
222
- if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
223
- handler = onToolbarDone;
224
- }
179
+ if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
180
+ handler = this.onToolbarDone;
181
+ }
225
182
 
226
- if (isDone) {
227
- editor.selection = null;
228
- }
183
+ handler(change, done);
229
184
 
230
- handler(isDone);
185
+ if (parentPlugin && parentPlugin.handleDone) {
186
+ parentPlugin.handleDone(value, node, plugin, onChange);
187
+ }
188
+ };
231
189
 
232
- if (parentPlugin && parentPlugin.handleDone) {
233
- parentPlugin.handleDone(isDone, node, plugin);
234
- }
235
- };
190
+ const handleDataChange = (key, data) => {
191
+ this.props.onDataChange(key, data);
192
+ };
236
193
 
237
- const CustomToolbar =
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
- const filteredPlugins = plugin && plugin.filterPlugins ? plugin.filterPlugins(node, plugins) : plugins;
196
+ const filteredPlugins = plugin && plugin.filterPlugins ? plugin.filterPlugins(node, plugins) : plugins;
242
197
 
243
- log('[render] CustomToolbar: ', CustomToolbar);
244
- const parentExtraStyles =
245
- parentPlugin && parentPlugin.pluginStyles ? parentPlugin.pluginStyles(node, parentNode, plugin) : {};
246
- const pluginExtraStyles = plugin && plugin.pluginStyles ? plugin.pluginStyles(node, parentNode, plugin) : {};
247
- const extraStyles = {
248
- ...pluginExtraStyles,
249
- ...parentExtraStyles,
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
- const deletable = node && plugin && typeof plugin.deleteNode === 'function';
253
- const customToolbarShowDone =
254
- node && plugin && plugin.toolbar && plugin.toolbar.showDone && !toolbarOpts.alwaysVisible;
255
-
256
- // If there is a toolbarOpts we check if the showDone is not equal to false
257
- const defaultToolbarShowDone = !toolbarOpts || toolbarOpts.showDone !== false;
258
-
259
- const hasDoneButton = defaultToolbarShowDone || customToolbarShowDone;
260
-
261
- const names = classNames(classes.toolbar, {
262
- [classes.toolbarWithNoDone]: !hasDoneButton,
263
- [classes.toolbarTop]: toolbarOpts.position === 'top',
264
- [classes.toolbarRight]: toolbarOpts.alignment === 'right',
265
- [classes.focused]: toolbarOpts.alwaysVisible || isFocused,
266
- [classes.autoWidth]: autoWidth,
267
- [classes.fullWidth]: !autoWidth,
268
- });
269
-
270
- return (
271
- <div className={names} style={extraStyles} onClick={onClick} ref={toolbarRef}>
272
- {CustomToolbar ? (
273
- <CustomToolbar
274
- editor={editor}
275
- node={node}
276
- nodePath={nodePath}
277
- value={value}
278
- onToolbarDone={onToolbarDone}
279
- pluginProps={pluginProps}
280
- />
281
- ) : (
282
- <DefaultToolbar
283
- editor={editor}
284
- nodePath={nodePath}
285
- plugins={filteredPlugins}
286
- pluginProps={pluginProps}
287
- value={value}
288
- onChange={onChange}
289
- getFocusedValue={getFocusedValue}
290
- showDone={defaultToolbarShowDone}
291
- onDone={handleDone}
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
- {customToolbarShowDone && <DoneButton onClick={handleDone} />}
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
- </div>
312
- );
313
- };
265
+ );
266
+ }
267
+ }
314
268
 
315
- Toolbar.propTypes = {
316
- editor: PropTypes.object.isRequired,
317
- zIndex: PropTypes.number,
318
- value: PropTypes.arrayOf(
319
- PropTypes.shape({
320
- type: PropTypes.string,
321
- children: PropTypes.array,
322
- data: PropTypes.object,
323
- }),
324
- ),
325
- plugins: PropTypes.array,
326
- plugin: PropTypes.object,
327
- onImageClick: PropTypes.func,
328
- onDone: PropTypes.func.isRequired,
329
- toolbarRef: PropTypes.func.isRequired,
330
- classes: PropTypes.object.isRequired,
331
- isFocused: PropTypes.bool,
332
- autoWidth: PropTypes.bool,
333
- onChange: PropTypes.func.isRequired,
334
- getFocusedValue: PropTypes.func.isRequired,
335
- pluginProps: PropTypes.object,
336
- toolbarOpts: PropTypes.shape({
337
- position: PropTypes.oneOf(['bottom', 'top']),
338
- alignment: PropTypes.oneOf(['left', 'right']),
339
- alwaysVisible: PropTypes.bool,
340
- ref: PropTypes.func,
341
- showDone: PropTypes.bool,
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);
@@ -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);
@@ -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;