@pie-lib/editable-html-tip-tap 1.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 +32 -0
- package/CHANGELOG.md +2280 -0
- package/lib/__tests__/editor.test.js +470 -0
- package/lib/__tests__/serialization.test.js +246 -0
- package/lib/__tests__/utils.js +106 -0
- package/lib/block-tags.js +25 -0
- package/lib/constants.js +16 -0
- package/lib/editor.js +1356 -0
- package/lib/extensions/MediaView.js +112 -0
- package/lib/extensions/characters.js +65 -0
- package/lib/extensions/component.js +325 -0
- package/lib/extensions/css.js +252 -0
- package/lib/extensions/custom-toolbar-wrapper.js +124 -0
- package/lib/extensions/image.js +106 -0
- package/lib/extensions/math.js +330 -0
- package/lib/extensions/media.js +276 -0
- package/lib/extensions/responseArea.js +278 -0
- package/lib/index.js +1213 -0
- package/lib/old-index.js +269 -0
- package/lib/parse-html.js +16 -0
- package/lib/plugins/characters/custom-popper.js +73 -0
- package/lib/plugins/characters/index.js +305 -0
- package/lib/plugins/characters/utils.js +381 -0
- package/lib/plugins/css/icons/index.js +37 -0
- package/lib/plugins/css/index.js +390 -0
- package/lib/plugins/customPlugin/index.js +114 -0
- package/lib/plugins/html/icons/index.js +38 -0
- package/lib/plugins/html/index.js +81 -0
- package/lib/plugins/image/__tests__/component.test.js +51 -0
- package/lib/plugins/image/__tests__/image-toolbar-logic.test.js +56 -0
- package/lib/plugins/image/__tests__/image-toolbar.test.js +26 -0
- package/lib/plugins/image/__tests__/index.test.js +98 -0
- package/lib/plugins/image/__tests__/insert-image-handler.test.js +125 -0
- package/lib/plugins/image/__tests__/mock-change.js +25 -0
- package/lib/plugins/image/alt-dialog.js +129 -0
- package/lib/plugins/image/component.js +419 -0
- package/lib/plugins/image/image-toolbar.js +177 -0
- package/lib/plugins/image/index.js +263 -0
- package/lib/plugins/image/insert-image-handler.js +117 -0
- package/lib/plugins/index.js +413 -0
- package/lib/plugins/list/__tests__/index.test.js +79 -0
- package/lib/plugins/list/index.js +334 -0
- package/lib/plugins/math/__tests__/index.test.js +300 -0
- package/lib/plugins/math/index.js +454 -0
- package/lib/plugins/media/__tests__/index.test.js +71 -0
- package/lib/plugins/media/index.js +387 -0
- package/lib/plugins/media/media-dialog.js +709 -0
- package/lib/plugins/media/media-toolbar.js +101 -0
- package/lib/plugins/media/media-wrapper.js +93 -0
- package/lib/plugins/rendering/index.js +46 -0
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +289 -0
- package/lib/plugins/respArea/drag-in-the-blank/index.js +94 -0
- package/lib/plugins/respArea/explicit-constructed-response/index.js +120 -0
- package/lib/plugins/respArea/icons/index.js +95 -0
- package/lib/plugins/respArea/index.js +341 -0
- package/lib/plugins/respArea/inline-dropdown/index.js +126 -0
- package/lib/plugins/respArea/math-templated/index.js +130 -0
- package/lib/plugins/respArea/utils.js +125 -0
- package/lib/plugins/table/CustomTablePlugin.js +133 -0
- package/lib/plugins/table/__tests__/index.test.js +442 -0
- package/lib/plugins/table/__tests__/table-toolbar.test.js +54 -0
- package/lib/plugins/table/icons/index.js +69 -0
- package/lib/plugins/table/index.js +483 -0
- package/lib/plugins/table/table-toolbar.js +187 -0
- package/lib/plugins/textAlign/icons/index.js +194 -0
- package/lib/plugins/textAlign/index.js +34 -0
- package/lib/plugins/toolbar/__tests__/default-toolbar.test.js +128 -0
- package/lib/plugins/toolbar/__tests__/editor-and-toolbar.test.js +51 -0
- package/lib/plugins/toolbar/__tests__/toolbar-buttons.test.js +54 -0
- package/lib/plugins/toolbar/__tests__/toolbar.test.js +120 -0
- package/lib/plugins/toolbar/default-toolbar.js +229 -0
- package/lib/plugins/toolbar/done-button.js +53 -0
- package/lib/plugins/toolbar/editor-and-toolbar.js +286 -0
- package/lib/plugins/toolbar/index.js +34 -0
- package/lib/plugins/toolbar/toolbar-buttons.js +194 -0
- package/lib/plugins/toolbar/toolbar.js +376 -0
- package/lib/plugins/utils.js +62 -0
- package/lib/serialization.js +677 -0
- package/lib/shared/alert-dialog.js +75 -0
- package/lib/theme.js +9 -0
- package/package.json +69 -0
- package/src/__tests__/editor.test.jsx +363 -0
- package/src/__tests__/serialization.test.js +291 -0
- package/src/__tests__/utils.js +36 -0
- package/src/block-tags.js +17 -0
- package/src/constants.js +7 -0
- package/src/editor.jsx +1197 -0
- package/src/extensions/characters.js +46 -0
- package/src/extensions/component.jsx +294 -0
- package/src/extensions/css.js +217 -0
- package/src/extensions/custom-toolbar-wrapper.jsx +100 -0
- package/src/extensions/image.js +55 -0
- package/src/extensions/math.js +259 -0
- package/src/extensions/media.js +182 -0
- package/src/extensions/responseArea.js +205 -0
- package/src/index.jsx +1462 -0
- package/src/old-index.jsx +162 -0
- package/src/parse-html.js +8 -0
- package/src/plugins/README.md +27 -0
- package/src/plugins/characters/custom-popper.js +48 -0
- package/src/plugins/characters/index.jsx +284 -0
- package/src/plugins/characters/utils.js +447 -0
- package/src/plugins/css/icons/index.jsx +17 -0
- package/src/plugins/css/index.jsx +340 -0
- package/src/plugins/customPlugin/index.jsx +85 -0
- package/src/plugins/html/icons/index.jsx +19 -0
- package/src/plugins/html/index.jsx +72 -0
- package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +51 -0
- package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +27 -0
- package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +44 -0
- package/src/plugins/image/__tests__/component.test.jsx +41 -0
- package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +42 -0
- package/src/plugins/image/__tests__/image-toolbar.test.jsx +11 -0
- package/src/plugins/image/__tests__/index.test.js +95 -0
- package/src/plugins/image/__tests__/insert-image-handler.test.js +113 -0
- package/src/plugins/image/__tests__/mock-change.js +15 -0
- package/src/plugins/image/alt-dialog.jsx +82 -0
- package/src/plugins/image/component.jsx +343 -0
- package/src/plugins/image/image-toolbar.jsx +100 -0
- package/src/plugins/image/index.jsx +227 -0
- package/src/plugins/image/insert-image-handler.js +79 -0
- package/src/plugins/index.jsx +377 -0
- package/src/plugins/list/__tests__/index.test.js +54 -0
- package/src/plugins/list/index.jsx +305 -0
- package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +48 -0
- package/src/plugins/math/__tests__/index.test.jsx +245 -0
- package/src/plugins/math/index.jsx +379 -0
- package/src/plugins/media/__tests__/index.test.js +75 -0
- package/src/plugins/media/index.jsx +325 -0
- package/src/plugins/media/media-dialog.js +624 -0
- package/src/plugins/media/media-toolbar.jsx +56 -0
- package/src/plugins/media/media-wrapper.jsx +43 -0
- package/src/plugins/rendering/index.js +31 -0
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +215 -0
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +70 -0
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +92 -0
- package/src/plugins/respArea/icons/index.jsx +71 -0
- package/src/plugins/respArea/index.jsx +299 -0
- package/src/plugins/respArea/inline-dropdown/index.jsx +108 -0
- package/src/plugins/respArea/math-templated/index.jsx +104 -0
- package/src/plugins/respArea/utils.jsx +90 -0
- package/src/plugins/table/CustomTablePlugin.js +113 -0
- package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +44 -0
- package/src/plugins/table/__tests__/index.test.jsx +401 -0
- package/src/plugins/table/__tests__/table-toolbar.test.jsx +42 -0
- package/src/plugins/table/icons/index.jsx +53 -0
- package/src/plugins/table/index.jsx +427 -0
- package/src/plugins/table/table-toolbar.jsx +136 -0
- package/src/plugins/textAlign/icons/index.jsx +114 -0
- package/src/plugins/textAlign/index.jsx +23 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +923 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +20 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +36 -0
- package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +46 -0
- package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +94 -0
- package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +37 -0
- package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +51 -0
- package/src/plugins/toolbar/__tests__/toolbar.test.jsx +106 -0
- package/src/plugins/toolbar/default-toolbar.jsx +206 -0
- package/src/plugins/toolbar/done-button.jsx +38 -0
- package/src/plugins/toolbar/editor-and-toolbar.jsx +257 -0
- package/src/plugins/toolbar/index.jsx +23 -0
- package/src/plugins/toolbar/toolbar-buttons.jsx +138 -0
- package/src/plugins/toolbar/toolbar.jsx +338 -0
- package/src/plugins/utils.js +31 -0
- package/src/serialization.jsx +621 -0
- package/src/theme.js +1 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Change } from 'slate';
|
|
3
|
+
import Delete from '@material-ui/icons/Delete';
|
|
4
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import debug from 'debug';
|
|
8
|
+
import SlatePropTypes from 'slate-prop-types';
|
|
9
|
+
import debounce from 'lodash/debounce';
|
|
10
|
+
|
|
11
|
+
import { DoneButton } from './done-button';
|
|
12
|
+
|
|
13
|
+
import { findSingleNode, findParentNode } from '../utils';
|
|
14
|
+
import { withStyles } from '@material-ui/core/styles';
|
|
15
|
+
import DefaultToolbar from './default-toolbar';
|
|
16
|
+
import { removeDialogs as removeCharacterDialogs } from '../characters';
|
|
17
|
+
import { PIE_TOOLBAR__CLASS } from '../../constants';
|
|
18
|
+
|
|
19
|
+
const log = debug('@pie-lib:editable-html:plugins:toolbar');
|
|
20
|
+
|
|
21
|
+
const getCustomToolbar = (plugin, node, value, handleDone, getFocusedValue, onDataChange) => {
|
|
22
|
+
if (!plugin) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!plugin.toolbar) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (plugin.toolbar.CustomToolbarComp) {
|
|
31
|
+
/**
|
|
32
|
+
* Using a pre-defined Component should be preferred
|
|
33
|
+
* as the rendering of it (and it's children) can be optimized by React.
|
|
34
|
+
* If you keep re-defining the comp with an inline function
|
|
35
|
+
* then react will have to re-render.
|
|
36
|
+
*/
|
|
37
|
+
return plugin.toolbar.CustomToolbarComp;
|
|
38
|
+
} else if (typeof plugin.toolbar.customToolbar === 'function') {
|
|
39
|
+
log('deprecated - use CustomToolbarComp');
|
|
40
|
+
return plugin.toolbar.customToolbar(node, value, handleDone, getFocusedValue, onDataChange);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export class Toolbar extends React.Component {
|
|
45
|
+
static propTypes = {
|
|
46
|
+
zIndex: PropTypes.number,
|
|
47
|
+
value: SlatePropTypes.value.isRequired,
|
|
48
|
+
plugins: PropTypes.array,
|
|
49
|
+
plugin: PropTypes.object,
|
|
50
|
+
onImageClick: PropTypes.func,
|
|
51
|
+
onDone: PropTypes.func.isRequired,
|
|
52
|
+
toolbarRef: PropTypes.func.isRequired,
|
|
53
|
+
classes: PropTypes.object.isRequired,
|
|
54
|
+
isFocused: PropTypes.bool,
|
|
55
|
+
autoWidth: PropTypes.bool,
|
|
56
|
+
onChange: PropTypes.func.isRequired,
|
|
57
|
+
getFocusedValue: PropTypes.func.isRequired,
|
|
58
|
+
pluginProps: PropTypes.object,
|
|
59
|
+
toolbarOpts: PropTypes.shape({
|
|
60
|
+
position: PropTypes.oneOf(['bottom', 'top']),
|
|
61
|
+
alignment: PropTypes.oneOf(['left', 'right']),
|
|
62
|
+
alwaysVisible: PropTypes.bool,
|
|
63
|
+
ref: PropTypes.func,
|
|
64
|
+
showDone: PropTypes.bool,
|
|
65
|
+
minWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
66
|
+
isHidden: PropTypes.bool,
|
|
67
|
+
}),
|
|
68
|
+
onDataChange: PropTypes.func,
|
|
69
|
+
doneButtonRef: PropTypes.func,
|
|
70
|
+
onBlur: PropTypes.func,
|
|
71
|
+
onFocus: PropTypes.func,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
constructor(props) {
|
|
75
|
+
super(props);
|
|
76
|
+
this.state = {
|
|
77
|
+
change: null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
componentWillUnmount() {
|
|
82
|
+
removeCharacterDialogs();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
hasMark = (type) => {
|
|
86
|
+
const { value } = this.props;
|
|
87
|
+
return value.marks.some((mark) => mark.type == type);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
hasBlock = (type) => {
|
|
91
|
+
const { value } = this.props;
|
|
92
|
+
return value.blocks.some((node) => node.type == type);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
onToggle = (plugin) => {
|
|
96
|
+
const { value, onChange } = this.props;
|
|
97
|
+
|
|
98
|
+
if (!plugin.onToggle) return;
|
|
99
|
+
|
|
100
|
+
const change = plugin.onToggle(value.change());
|
|
101
|
+
onChange(change);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
onClick = (e) => {
|
|
105
|
+
log('[onClick]');
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
onButtonClick = (fn) => {
|
|
110
|
+
return (e) => {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
fn();
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
onToolbarDone = (change, finishEditing) => {
|
|
117
|
+
log('[onToolbarDone] change: ', change, 'finishEditing: ', finishEditing);
|
|
118
|
+
const { onChange, onDone } = this.props;
|
|
119
|
+
|
|
120
|
+
// use handler only if this is an actual Slate Change
|
|
121
|
+
if (change instanceof Change) {
|
|
122
|
+
onChange(change, () => {
|
|
123
|
+
if (finishEditing) {
|
|
124
|
+
onDone();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
if (finishEditing) {
|
|
129
|
+
log('[onToolbarChange] call onDone');
|
|
130
|
+
onDone();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
onDeleteClick = debounce((e, plugin, node, value, onChange) => plugin.deleteNode(e, node, value, onChange), 500);
|
|
136
|
+
|
|
137
|
+
onDeleteMouseDown = (e, plugin, node, value, onChange) => {
|
|
138
|
+
e.persist();
|
|
139
|
+
this.onDeleteClick(e, plugin, node, value, onChange);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
render() {
|
|
143
|
+
const {
|
|
144
|
+
classes,
|
|
145
|
+
plugins,
|
|
146
|
+
pluginProps,
|
|
147
|
+
toolbarOpts,
|
|
148
|
+
value,
|
|
149
|
+
autoWidth,
|
|
150
|
+
onChange,
|
|
151
|
+
getFocusedValue,
|
|
152
|
+
isFocused,
|
|
153
|
+
onDone,
|
|
154
|
+
toolbarRef,
|
|
155
|
+
doneButtonRef,
|
|
156
|
+
onBlur,
|
|
157
|
+
onFocus,
|
|
158
|
+
} = this.props;
|
|
159
|
+
|
|
160
|
+
const node = findSingleNode(value);
|
|
161
|
+
const parentNode = findParentNode(value, node);
|
|
162
|
+
|
|
163
|
+
log(' --------------> [render] node: ', node);
|
|
164
|
+
log('[render] node: ', node);
|
|
165
|
+
|
|
166
|
+
const plugin = plugins.find((p) => {
|
|
167
|
+
if (!node) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (p.toolbar) {
|
|
172
|
+
return p.toolbar.supports && p.toolbar.supports(node, value);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
const parentPlugin = plugins.find((p) => {
|
|
176
|
+
if (!parentNode) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (p.toolbar) {
|
|
181
|
+
return p.toolbar.supports && p.toolbar.supports(parentNode, value);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
log('[render] plugin: ', plugin);
|
|
186
|
+
|
|
187
|
+
const handleDone = (change, done) => {
|
|
188
|
+
let handler = onDone;
|
|
189
|
+
|
|
190
|
+
if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
|
|
191
|
+
handler = this.onToolbarDone;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
handler(change, done);
|
|
195
|
+
|
|
196
|
+
if (parentPlugin && parentPlugin.handleDone) {
|
|
197
|
+
parentPlugin.handleDone(value, node, plugin, onChange);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const handleDataChange = (key, data) => {
|
|
202
|
+
this.props.onDataChange(key, data);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const CustomToolbar = getCustomToolbar(plugin, node, value, handleDone, getFocusedValue, this.props.onDataChange);
|
|
206
|
+
|
|
207
|
+
const filteredPlugins = plugin && plugin.filterPlugins ? plugin.filterPlugins(node, plugins) : plugins;
|
|
208
|
+
|
|
209
|
+
log('[render] CustomToolbar: ', CustomToolbar);
|
|
210
|
+
const parentExtraStyles =
|
|
211
|
+
parentPlugin && parentPlugin.pluginStyles ? parentPlugin.pluginStyles(node, parentNode, plugin) : {};
|
|
212
|
+
const pluginExtraStyles = plugin && plugin.pluginStyles ? plugin.pluginStyles(node, parentNode, plugin) : {};
|
|
213
|
+
const extraStyles = {
|
|
214
|
+
...pluginExtraStyles,
|
|
215
|
+
...parentExtraStyles,
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const deletable = node && plugin && plugin.deleteNode;
|
|
219
|
+
const customToolbarShowDone =
|
|
220
|
+
node && plugin && plugin.toolbar && plugin.toolbar.showDone && !toolbarOpts.alwaysVisible;
|
|
221
|
+
|
|
222
|
+
// If there is a toolbarOpts we check if the showDone is not equal to false
|
|
223
|
+
const defaultToolbarShowDone = !toolbarOpts || toolbarOpts.showDone !== false;
|
|
224
|
+
|
|
225
|
+
const hasDoneButton = defaultToolbarShowDone || customToolbarShowDone;
|
|
226
|
+
|
|
227
|
+
const names = classNames(classes.toolbar, PIE_TOOLBAR__CLASS, {
|
|
228
|
+
[classes.toolbarWithNoDone]: !hasDoneButton,
|
|
229
|
+
[classes.toolbarTop]: toolbarOpts.position === 'top',
|
|
230
|
+
[classes.toolbarRight]: toolbarOpts.alignment === 'right',
|
|
231
|
+
[classes.focused]: toolbarOpts.alwaysVisible || isFocused,
|
|
232
|
+
[classes.autoWidth]: autoWidth,
|
|
233
|
+
[classes.fullWidth]: !autoWidth,
|
|
234
|
+
[classes.hidden]: toolbarOpts.isHidden === true,
|
|
235
|
+
});
|
|
236
|
+
const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<div className={names} style={{ ...extraStyles, ...customStyles }} onClick={this.onClick} ref={toolbarRef}>
|
|
240
|
+
{CustomToolbar ? (
|
|
241
|
+
<CustomToolbar
|
|
242
|
+
node={node}
|
|
243
|
+
value={value}
|
|
244
|
+
getFocusedValue={getFocusedValue}
|
|
245
|
+
onToolbarDone={this.onToolbarDone}
|
|
246
|
+
onDataChange={handleDataChange}
|
|
247
|
+
pluginProps={pluginProps}
|
|
248
|
+
/>
|
|
249
|
+
) : (
|
|
250
|
+
<DefaultToolbar
|
|
251
|
+
plugins={filteredPlugins}
|
|
252
|
+
pluginProps={pluginProps}
|
|
253
|
+
value={value}
|
|
254
|
+
onChange={onChange}
|
|
255
|
+
getFocusedValue={getFocusedValue}
|
|
256
|
+
showDone={defaultToolbarShowDone}
|
|
257
|
+
onDone={handleDone}
|
|
258
|
+
deletable={deletable}
|
|
259
|
+
isHtmlMode={toolbarOpts.isHtmlMode}
|
|
260
|
+
onFocus={onFocus}
|
|
261
|
+
doneButtonRef={doneButtonRef}
|
|
262
|
+
onBlur={onBlur}
|
|
263
|
+
/>
|
|
264
|
+
)}
|
|
265
|
+
|
|
266
|
+
<div className={classes.shared}>
|
|
267
|
+
{deletable && (
|
|
268
|
+
<IconButton
|
|
269
|
+
aria-label="Delete"
|
|
270
|
+
className={classes.iconRoot}
|
|
271
|
+
onMouseDown={(e) => this.onDeleteMouseDown(e, plugin, node, value, onChange)}
|
|
272
|
+
classes={{
|
|
273
|
+
root: classes.iconRoot,
|
|
274
|
+
}}
|
|
275
|
+
>
|
|
276
|
+
<Delete />
|
|
277
|
+
</IconButton>
|
|
278
|
+
)}
|
|
279
|
+
{customToolbarShowDone && <DoneButton doneButtonRef={doneButtonRef} onClick={handleDone} />}
|
|
280
|
+
</div>
|
|
281
|
+
</div>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const style = {
|
|
287
|
+
toolbar: {
|
|
288
|
+
position: 'absolute',
|
|
289
|
+
zIndex: 10,
|
|
290
|
+
cursor: 'pointer',
|
|
291
|
+
justifyContent: 'space-between',
|
|
292
|
+
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
293
|
+
minWidth: '280px',
|
|
294
|
+
margin: '5px 0 0 0',
|
|
295
|
+
padding: '2px',
|
|
296
|
+
boxShadow:
|
|
297
|
+
'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)',
|
|
298
|
+
boxSizing: 'border-box',
|
|
299
|
+
display: 'flex',
|
|
300
|
+
opacity: 0,
|
|
301
|
+
pointerEvents: 'none',
|
|
302
|
+
},
|
|
303
|
+
toolbarWithNoDone: {
|
|
304
|
+
minWidth: '265px',
|
|
305
|
+
},
|
|
306
|
+
toolbarTop: {
|
|
307
|
+
top: '-45px',
|
|
308
|
+
},
|
|
309
|
+
toolbarRight: {
|
|
310
|
+
right: 0,
|
|
311
|
+
},
|
|
312
|
+
fullWidth: {
|
|
313
|
+
width: '100%',
|
|
314
|
+
},
|
|
315
|
+
hidden: {
|
|
316
|
+
visibility: 'hidden',
|
|
317
|
+
},
|
|
318
|
+
autoWidth: {
|
|
319
|
+
width: 'auto',
|
|
320
|
+
},
|
|
321
|
+
focused: {
|
|
322
|
+
opacity: 1,
|
|
323
|
+
pointerEvents: 'auto',
|
|
324
|
+
},
|
|
325
|
+
iconRoot: {
|
|
326
|
+
width: '28px',
|
|
327
|
+
height: '28px',
|
|
328
|
+
padding: '4px',
|
|
329
|
+
verticalAlign: 'top',
|
|
330
|
+
},
|
|
331
|
+
label: {
|
|
332
|
+
color: 'var(--editable-html-toolbar-check, #00bb00)',
|
|
333
|
+
},
|
|
334
|
+
shared: {
|
|
335
|
+
display: 'flex',
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
export default withStyles(style, { index: 1000 })(Toolbar);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const findSingleNode = (value) => {
|
|
2
|
+
if (!value || !value.isCollapsed || !value.startKey) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const inline = value.document.getClosestInline(value.startKey);
|
|
7
|
+
|
|
8
|
+
if (inline) {
|
|
9
|
+
return inline;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const block = value.document.getClosestBlock(value.startKey);
|
|
13
|
+
|
|
14
|
+
if (block) {
|
|
15
|
+
return block;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const findParentNode = (value, node) => {
|
|
20
|
+
if (!value || !node) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return value.document.getParent(node.key);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const hasMark = (value, type) => value && value.marks.some((mark) => mark.type == type);
|
|
28
|
+
|
|
29
|
+
export const hasBlock = (value, type) => value && value.blocks.some((node) => node.type == type);
|
|
30
|
+
|
|
31
|
+
export const hasNode = ({ document }, type) => document && document.nodes.some((node) => node.type == type);
|