@pie-lib/editable-html 9.2.6-next.2 → 9.2.7
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.md +16 -0
- package/lib/editor.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +1 -1
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js.map +1 -1
- package/package.json +6 -6
- package/playground/image/data.js +20 -20
- package/playground/image/index.html +20 -22
- package/playground/image/index.jsx +7 -12
- package/playground/index.html +23 -25
- package/playground/mathquill/index.html +20 -23
- package/playground/mathquill/index.jsx +7 -18
- package/playground/prod-test/index.html +20 -24
- package/playground/prod-test/index.jsx +2 -5
- package/playground/schema-override/data.js +10 -10
- package/playground/schema-override/image-plugin.jsx +3 -3
- package/playground/schema-override/index.html +19 -21
- package/playground/schema-override/index.jsx +12 -12
- package/playground/serialization/data.js +10 -10
- package/playground/serialization/image-plugin.jsx +3 -3
- package/playground/serialization/index.html +20 -22
- package/playground/table-examples.html +8 -5
- package/playground/webpack.config.js +10 -10
- package/src/editor.jsx +77 -101
- package/src/index.jsx +11 -18
- package/src/parse-html.js +1 -1
- package/src/plugins/characters/custom-popper.js +7 -7
- package/src/plugins/characters/index.jsx +19 -25
- package/src/plugins/characters/utils.js +81 -81
- package/src/plugins/image/alt-dialog.jsx +3 -3
- package/src/plugins/image/component.jsx +42 -46
- package/src/plugins/image/image-toolbar.jsx +14 -26
- package/src/plugins/image/index.jsx +21 -23
- package/src/plugins/index.jsx +10 -12
- package/src/plugins/list/index.jsx +10 -10
- package/src/plugins/math/index.jsx +28 -31
- package/src/plugins/media/index.jsx +21 -21
- package/src/plugins/media/media-dialog.js +60 -86
- package/src/plugins/media/media-toolbar.jsx +6 -6
- package/src/plugins/media/media-wrapper.jsx +6 -6
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +19 -21
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +10 -12
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +5 -5
- package/src/plugins/respArea/icons/index.jsx +8 -8
- package/src/plugins/respArea/index.jsx +21 -31
- package/src/plugins/respArea/inline-dropdown/index.jsx +6 -6
- package/src/plugins/respArea/utils.jsx +12 -12
- package/src/plugins/table/icons/index.jsx +11 -17
- package/src/plugins/table/index.jsx +43 -49
- package/src/plugins/table/table-toolbar.jsx +8 -13
- package/src/plugins/toolbar/default-toolbar.jsx +11 -19
- package/src/plugins/toolbar/done-button.jsx +4 -4
- package/src/plugins/toolbar/editor-and-toolbar.jsx +39 -47
- package/src/plugins/toolbar/index.jsx +2 -2
- package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
- package/src/plugins/toolbar/toolbar.jsx +34 -47
- package/src/plugins/utils.js +4 -5
- package/src/serialization.jsx +32 -32
|
@@ -8,34 +8,34 @@ import SlatePropTypes from 'slate-prop-types';
|
|
|
8
8
|
|
|
9
9
|
const log = debug('@pie-lib:editable-html:plugins:image:component');
|
|
10
10
|
|
|
11
|
-
const size = s => (s ? `${s}px` : 'auto');
|
|
11
|
+
const size = (s) => (s ? `${s}px` : 'auto');
|
|
12
12
|
|
|
13
13
|
export class Component extends React.Component {
|
|
14
14
|
static propTypes = {
|
|
15
15
|
node: SlatePropTypes.node.isRequired,
|
|
16
16
|
editor: PropTypes.shape({
|
|
17
17
|
change: PropTypes.func.isRequired,
|
|
18
|
-
value: PropTypes.object
|
|
18
|
+
value: PropTypes.object,
|
|
19
19
|
}).isRequired,
|
|
20
20
|
classes: PropTypes.object.isRequired,
|
|
21
21
|
attributes: PropTypes.object,
|
|
22
22
|
onFocus: PropTypes.func,
|
|
23
23
|
onBlur: PropTypes.func,
|
|
24
24
|
maxImageWidth: PropTypes.number,
|
|
25
|
-
maxImageHeight: PropTypes.number
|
|
25
|
+
maxImageHeight: PropTypes.number,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
getWidth = percent => {
|
|
28
|
+
getWidth = (percent) => {
|
|
29
29
|
const multiplier = percent / 100;
|
|
30
30
|
return this.img.naturalWidth * multiplier;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
getHeight = percent => {
|
|
33
|
+
getHeight = (percent) => {
|
|
34
34
|
const multiplier = percent / 100;
|
|
35
35
|
return this.img.naturalHeight * multiplier;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
getPercentFromWidth = width => {
|
|
38
|
+
getPercentFromWidth = (width) => {
|
|
39
39
|
var floored = (width / this.img.naturalWidth) * 4;
|
|
40
40
|
return parseInt(floored.toFixed(0) * 25, 10);
|
|
41
41
|
};
|
|
@@ -53,7 +53,7 @@ export class Component extends React.Component {
|
|
|
53
53
|
log('[applySizeData] update: ', update);
|
|
54
54
|
|
|
55
55
|
if (!update.equals(node.data)) {
|
|
56
|
-
editor.change(c => c.setNodeByKey(node.key, { data: update }));
|
|
56
|
+
editor.change((c) => c.setNodeByKey(node.key, { data: update }));
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
|
|
@@ -80,7 +80,7 @@ export class Component extends React.Component {
|
|
|
80
80
|
return {
|
|
81
81
|
width: size(data.get('width')),
|
|
82
82
|
height: size(data.get('height')),
|
|
83
|
-
objectFit: 'contain'
|
|
83
|
+
objectFit: 'contain',
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -95,23 +95,23 @@ export class Component extends React.Component {
|
|
|
95
95
|
if (!box.style.width || box.style.width === 'auto') {
|
|
96
96
|
const dimensions = {
|
|
97
97
|
width: (box && box.naturalWidth) || 100,
|
|
98
|
-
height: (box && box.naturalHeight) || 100
|
|
98
|
+
height: (box && box.naturalHeight) || 100,
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
const { width, height } = this.updateImageDimensions(
|
|
102
102
|
dimensions,
|
|
103
103
|
{
|
|
104
104
|
width: dimensions.width < maxImageWidth ? dimensions.width : maxImageWidth,
|
|
105
|
-
height: dimensions.height < maxImageHeight ? dimensions.height : maxImageHeight
|
|
105
|
+
height: dimensions.height < maxImageHeight ? dimensions.height : maxImageHeight,
|
|
106
106
|
},
|
|
107
|
-
true
|
|
107
|
+
true,
|
|
108
108
|
);
|
|
109
109
|
|
|
110
110
|
box.style.width = `${width}px`;
|
|
111
111
|
box.style.height = `${height}px`;
|
|
112
112
|
|
|
113
113
|
this.setState({
|
|
114
|
-
dimensions: { height: height, width: width }
|
|
114
|
+
dimensions: { height: height, width: width },
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
const { node, editor } = this.props;
|
|
@@ -122,26 +122,26 @@ export class Component extends React.Component {
|
|
|
122
122
|
update = update.set('height', height);
|
|
123
123
|
|
|
124
124
|
if (!update.equals(node.data)) {
|
|
125
|
-
editor.change(c => c.setNodeByKey(node.key, { data: update }));
|
|
125
|
+
editor.change((c) => c.setNodeByKey(node.key, { data: update }));
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
-
startResizing = e => {
|
|
130
|
+
startResizing = (e) => {
|
|
131
131
|
const bounds = e.target.getBoundingClientRect();
|
|
132
132
|
const box = this.img;
|
|
133
133
|
const dimensions = {
|
|
134
134
|
width: (box && box.naturalWidth) || 100,
|
|
135
|
-
height: (box && box.naturalHeight) || 100
|
|
135
|
+
height: (box && box.naturalHeight) || 100,
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
const { width, height } = this.updateImageDimensions(
|
|
139
139
|
dimensions,
|
|
140
140
|
{
|
|
141
141
|
width: e.clientX - bounds.left,
|
|
142
|
-
height: e.clientY - bounds.top
|
|
142
|
+
height: e.clientY - bounds.top,
|
|
143
143
|
},
|
|
144
|
-
true
|
|
144
|
+
true,
|
|
145
145
|
);
|
|
146
146
|
|
|
147
147
|
const hasMinimumWidth = width > 50 && height > 50;
|
|
@@ -152,7 +152,7 @@ export class Component extends React.Component {
|
|
|
152
152
|
box.style.height = `${height}px`;
|
|
153
153
|
|
|
154
154
|
this.setState({
|
|
155
|
-
dimensions: { height: height, width: width }
|
|
155
|
+
dimensions: { height: height, width: width },
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
const { node, editor } = this.props;
|
|
@@ -163,7 +163,7 @@ export class Component extends React.Component {
|
|
|
163
163
|
update = update.set('height', height);
|
|
164
164
|
|
|
165
165
|
if (!update.equals(node.data)) {
|
|
166
|
-
editor.change(c => c.setNodeByKey(node.key, { data: update }));
|
|
166
|
+
editor.change((c) => c.setNodeByKey(node.key, { data: update }));
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
};
|
|
@@ -182,21 +182,21 @@ export class Component extends React.Component {
|
|
|
182
182
|
// if we want to change image height => we update the width accordingly
|
|
183
183
|
return {
|
|
184
184
|
width: nextDim.height * imageAspectRatio,
|
|
185
|
-
height: nextDim.height
|
|
185
|
+
height: nextDim.height,
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// if we want to change image width => we update the height accordingly
|
|
190
190
|
return {
|
|
191
191
|
width: nextDim.width,
|
|
192
|
-
height: nextDim.width / imageAspectRatio
|
|
192
|
+
height: nextDim.width / imageAspectRatio,
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
// if we don't want to keep aspect ratio, we just update both values
|
|
197
197
|
return {
|
|
198
198
|
width: nextDim.width,
|
|
199
|
-
height: nextDim.height
|
|
199
|
+
height: nextDim.height,
|
|
200
200
|
};
|
|
201
201
|
};
|
|
202
202
|
|
|
@@ -239,7 +239,7 @@ export class Component extends React.Component {
|
|
|
239
239
|
const className = classNames(
|
|
240
240
|
classes.root,
|
|
241
241
|
!loaded && classes.loading,
|
|
242
|
-
deleteStatus === 'pending' && classes.pendingDelete
|
|
242
|
+
deleteStatus === 'pending' && classes.pendingDelete,
|
|
243
243
|
);
|
|
244
244
|
|
|
245
245
|
const progressClasses = classNames(classes.progress, loaded && classes.hideProgress);
|
|
@@ -247,16 +247,12 @@ export class Component extends React.Component {
|
|
|
247
247
|
return [
|
|
248
248
|
<span key={'sp1'}> </span>,
|
|
249
249
|
<div key={'comp'} onFocus={onFocus} className={className} style={{ justifyContent }}>
|
|
250
|
-
<LinearProgress
|
|
251
|
-
mode="determinate"
|
|
252
|
-
value={percent > 0 ? percent : 0}
|
|
253
|
-
className={progressClasses}
|
|
254
|
-
/>
|
|
250
|
+
<LinearProgress mode="determinate" value={percent > 0 ? percent : 0} className={progressClasses} />
|
|
255
251
|
<div className={classes.imageContainer}>
|
|
256
252
|
<img
|
|
257
253
|
{...attributes}
|
|
258
254
|
className={classNames(classes.image, active && classes.active)}
|
|
259
|
-
ref={ref => {
|
|
255
|
+
ref={(ref) => {
|
|
260
256
|
this.img = ref;
|
|
261
257
|
}}
|
|
262
258
|
src={src}
|
|
@@ -265,23 +261,23 @@ export class Component extends React.Component {
|
|
|
265
261
|
alt={alt}
|
|
266
262
|
/>
|
|
267
263
|
<div
|
|
268
|
-
ref={ref => {
|
|
264
|
+
ref={(ref) => {
|
|
269
265
|
this.resize = ref;
|
|
270
266
|
}}
|
|
271
267
|
className={classNames(classes.resize, 'resize')}
|
|
272
268
|
/>
|
|
273
269
|
</div>
|
|
274
270
|
</div>,
|
|
275
|
-
<span key={'sp2'}> </span
|
|
271
|
+
<span key={'sp2'}> </span>,
|
|
276
272
|
];
|
|
277
273
|
}
|
|
278
274
|
}
|
|
279
275
|
|
|
280
|
-
const styles = theme => ({
|
|
276
|
+
const styles = (theme) => ({
|
|
281
277
|
portal: {
|
|
282
278
|
position: 'absolute',
|
|
283
279
|
opacity: 0,
|
|
284
|
-
transition: 'opacity 200ms linear'
|
|
280
|
+
transition: 'opacity 200ms linear',
|
|
285
281
|
},
|
|
286
282
|
floatingButtonRow: {
|
|
287
283
|
backgroundColor: 'white',
|
|
@@ -290,33 +286,33 @@ const styles = theme => ({
|
|
|
290
286
|
padding: '10px',
|
|
291
287
|
border: 'solid 1px #eeeeee',
|
|
292
288
|
boxShadow:
|
|
293
|
-
'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)'
|
|
289
|
+
'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)',
|
|
294
290
|
},
|
|
295
291
|
progress: {
|
|
296
292
|
position: 'absolute',
|
|
297
293
|
left: '0',
|
|
298
294
|
width: 'fit-content',
|
|
299
295
|
top: '0%',
|
|
300
|
-
transition: 'opacity 200ms linear'
|
|
296
|
+
transition: 'opacity 200ms linear',
|
|
301
297
|
},
|
|
302
298
|
hideProgress: {
|
|
303
|
-
opacity: 0
|
|
299
|
+
opacity: 0,
|
|
304
300
|
},
|
|
305
301
|
loading: {
|
|
306
|
-
opacity: 0.3
|
|
302
|
+
opacity: 0.3,
|
|
307
303
|
},
|
|
308
304
|
pendingDelete: {
|
|
309
|
-
opacity: 0.3
|
|
305
|
+
opacity: 0.3,
|
|
310
306
|
},
|
|
311
307
|
root: {
|
|
312
308
|
position: 'relative',
|
|
313
309
|
border: 'solid 1px white',
|
|
314
310
|
display: 'flex',
|
|
315
|
-
transition: 'opacity 200ms linear'
|
|
311
|
+
transition: 'opacity 200ms linear',
|
|
316
312
|
},
|
|
317
313
|
delete: {
|
|
318
314
|
position: 'absolute',
|
|
319
|
-
right: 0
|
|
315
|
+
right: 0,
|
|
320
316
|
},
|
|
321
317
|
imageContainer: {
|
|
322
318
|
position: 'relative',
|
|
@@ -325,11 +321,11 @@ const styles = theme => ({
|
|
|
325
321
|
alignItems: 'center',
|
|
326
322
|
|
|
327
323
|
'&&:hover > .resize': {
|
|
328
|
-
display: 'block'
|
|
329
|
-
}
|
|
324
|
+
display: 'block',
|
|
325
|
+
},
|
|
330
326
|
},
|
|
331
327
|
active: {
|
|
332
|
-
border: `solid 1px ${theme.palette.primary.main}
|
|
328
|
+
border: `solid 1px ${theme.palette.primary.main}`,
|
|
333
329
|
},
|
|
334
330
|
resize: {
|
|
335
331
|
backgroundColor: theme.palette.primary.main,
|
|
@@ -339,11 +335,11 @@ const styles = theme => ({
|
|
|
339
335
|
borderRadius: 8,
|
|
340
336
|
marginLeft: '5px',
|
|
341
337
|
marginRight: '10px',
|
|
342
|
-
display: 'none'
|
|
338
|
+
display: 'none',
|
|
343
339
|
},
|
|
344
340
|
drawableHeight: {
|
|
345
|
-
minHeight: 350
|
|
346
|
-
}
|
|
341
|
+
minHeight: 350,
|
|
342
|
+
},
|
|
347
343
|
});
|
|
348
344
|
|
|
349
345
|
export default withStyles(styles)(Component);
|
|
@@ -21,7 +21,7 @@ const AlignmentButton = ({ alignment, active, onClick }) => {
|
|
|
21
21
|
AlignmentButton.propTypes = {
|
|
22
22
|
alignment: PropTypes.string.isRequired,
|
|
23
23
|
active: PropTypes.bool.isRequired,
|
|
24
|
-
onClick: PropTypes.func.isRequired
|
|
24
|
+
onClick: PropTypes.func.isRequired,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export class ImageToolbar extends React.Component {
|
|
@@ -31,16 +31,16 @@ export class ImageToolbar extends React.Component {
|
|
|
31
31
|
alignment: PropTypes.string,
|
|
32
32
|
alt: PropTypes.string,
|
|
33
33
|
imageLoaded: PropTypes.bool,
|
|
34
|
-
disableImageAlignmentButtons: PropTypes.bool
|
|
34
|
+
disableImageAlignmentButtons: PropTypes.bool,
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
onAltTextDone = newAlt => {
|
|
37
|
+
onAltTextDone = (newAlt) => {
|
|
38
38
|
log('[onAltTextDone]: alt:', newAlt);
|
|
39
39
|
|
|
40
40
|
this.props.onChange({ alt: newAlt });
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
onAlignmentClick = alignment => {
|
|
43
|
+
onAlignmentClick = (alignment) => {
|
|
44
44
|
log('[onAlignmentClick]: alignment:', alignment);
|
|
45
45
|
this.props.onChange({ alignment });
|
|
46
46
|
};
|
|
@@ -62,29 +62,17 @@ export class ImageToolbar extends React.Component {
|
|
|
62
62
|
<div className={classes.holder}>
|
|
63
63
|
{!disableImageAlignmentButtons && (
|
|
64
64
|
<>
|
|
65
|
-
<AlignmentButton
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
onClick={this.onAlignmentClick}
|
|
69
|
-
/>
|
|
70
|
-
<AlignmentButton
|
|
71
|
-
alignment={'center'}
|
|
72
|
-
active={alignment === 'center'}
|
|
73
|
-
onClick={this.onAlignmentClick}
|
|
74
|
-
/>
|
|
75
|
-
<AlignmentButton
|
|
76
|
-
alignment={'right'}
|
|
77
|
-
active={alignment === 'right'}
|
|
78
|
-
onClick={this.onAlignmentClick}
|
|
79
|
-
/>
|
|
65
|
+
<AlignmentButton alignment={'left'} active={alignment === 'left'} onClick={this.onAlignmentClick} />
|
|
66
|
+
<AlignmentButton alignment={'center'} active={alignment === 'center'} onClick={this.onAlignmentClick} />
|
|
67
|
+
<AlignmentButton alignment={'right'} active={alignment === 'right'} onClick={this.onAlignmentClick} />
|
|
80
68
|
</>
|
|
81
69
|
)}
|
|
82
70
|
<span
|
|
83
71
|
className={classNames({
|
|
84
72
|
[classes.disabled]: !imageLoaded,
|
|
85
|
-
[classes.altButton]: !disableImageAlignmentButtons
|
|
73
|
+
[classes.altButton]: !disableImageAlignmentButtons,
|
|
86
74
|
})}
|
|
87
|
-
onMouseDown={event => imageLoaded && this.renderDialog(event)}
|
|
75
|
+
onMouseDown={(event) => imageLoaded && this.renderDialog(event)}
|
|
88
76
|
>
|
|
89
77
|
Alt text
|
|
90
78
|
</span>
|
|
@@ -93,20 +81,20 @@ export class ImageToolbar extends React.Component {
|
|
|
93
81
|
}
|
|
94
82
|
}
|
|
95
83
|
|
|
96
|
-
const styles = theme => ({
|
|
84
|
+
const styles = (theme) => ({
|
|
97
85
|
holder: {
|
|
98
86
|
paddingLeft: theme.spacing.unit,
|
|
99
87
|
display: 'flex',
|
|
100
|
-
alignItems: 'center'
|
|
88
|
+
alignItems: 'center',
|
|
101
89
|
},
|
|
102
90
|
disabled: {
|
|
103
|
-
opacity: 0.5
|
|
91
|
+
opacity: 0.5,
|
|
104
92
|
},
|
|
105
93
|
altButton: {
|
|
106
94
|
borderLeft: '1px solid grey',
|
|
107
95
|
paddingLeft: 8,
|
|
108
|
-
marginLeft: 4
|
|
109
|
-
}
|
|
96
|
+
marginLeft: 4,
|
|
97
|
+
},
|
|
110
98
|
});
|
|
111
99
|
|
|
112
100
|
export default withStyles(styles)(ImageToolbar);
|
|
@@ -19,23 +19,23 @@ export default function ImagePlugin(opts) {
|
|
|
19
19
|
isVoid: true,
|
|
20
20
|
data: {
|
|
21
21
|
loaded: false,
|
|
22
|
-
src: undefined
|
|
23
|
-
}
|
|
22
|
+
src: undefined,
|
|
23
|
+
},
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
const change = value.change().insertInline(inline);
|
|
27
27
|
onChange(change);
|
|
28
|
-
opts.insertImageRequested(getValue => new InsertImageHandler(inline, getValue, onChange));
|
|
28
|
+
opts.insertImageRequested((getValue) => new InsertImageHandler(inline, getValue, onChange));
|
|
29
29
|
},
|
|
30
|
-
supports: node => node.object === 'inline' && node.type === 'image',
|
|
30
|
+
supports: (node) => node.object === 'inline' && node.type === 'image',
|
|
31
31
|
customToolbar: (node, value, onToolbarDone) => {
|
|
32
32
|
const alignment = node.data.get('alignment');
|
|
33
33
|
const alt = node.data.get('alt');
|
|
34
34
|
const imageLoaded = node.data.get('loaded') !== false;
|
|
35
|
-
const onChange = newValues => {
|
|
35
|
+
const onChange = (newValues) => {
|
|
36
36
|
const update = {
|
|
37
37
|
...node.data.toObject(),
|
|
38
|
-
...newValues
|
|
38
|
+
...newValues,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const change = value.change().setNodeByKey(node.key, { data: update });
|
|
@@ -53,7 +53,7 @@ export default function ImagePlugin(opts) {
|
|
|
53
53
|
);
|
|
54
54
|
return Tb;
|
|
55
55
|
},
|
|
56
|
-
showDone: true
|
|
56
|
+
showDone: true,
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
return {
|
|
@@ -72,9 +72,7 @@ export default function ImagePlugin(opts) {
|
|
|
72
72
|
change = v.change().removeNodeByKey(node.key);
|
|
73
73
|
} else {
|
|
74
74
|
log('[error]: ', err);
|
|
75
|
-
change = v
|
|
76
|
-
.change()
|
|
77
|
-
.setNodeByKey(node.key, node.data.merge(Data.create({ deleteStatus: 'failed' })));
|
|
75
|
+
change = v.change().setNodeByKey(node.key, node.data.merge(Data.create({ deleteStatus: 'failed' })));
|
|
78
76
|
}
|
|
79
77
|
onChange(change);
|
|
80
78
|
});
|
|
@@ -83,8 +81,8 @@ export default function ImagePlugin(opts) {
|
|
|
83
81
|
onChange(change);
|
|
84
82
|
}
|
|
85
83
|
},
|
|
86
|
-
stopReset: value => {
|
|
87
|
-
const imgPendingInsertion = value.document.findDescendant(n => {
|
|
84
|
+
stopReset: (value) => {
|
|
85
|
+
const imgPendingInsertion = value.document.findDescendant((n) => {
|
|
88
86
|
if (n.type !== 'image') {
|
|
89
87
|
return;
|
|
90
88
|
}
|
|
@@ -101,21 +99,21 @@ export default function ImagePlugin(opts) {
|
|
|
101
99
|
onFocus: opts.onFocus,
|
|
102
100
|
onBlur: opts.onBlur,
|
|
103
101
|
maxImageWidth: opts.maxImageWidth,
|
|
104
|
-
maxImageHeight: opts.maxImageHeight
|
|
102
|
+
maxImageHeight: opts.maxImageHeight,
|
|
105
103
|
},
|
|
106
|
-
props
|
|
104
|
+
props,
|
|
107
105
|
);
|
|
108
106
|
return <ImageComponent {...all} />;
|
|
109
107
|
}
|
|
110
108
|
},
|
|
111
|
-
normalizeNode: node => {
|
|
109
|
+
normalizeNode: (node) => {
|
|
112
110
|
const textNodeMap = {};
|
|
113
111
|
const updateNodesArray = [];
|
|
114
112
|
let index = 0;
|
|
115
113
|
|
|
116
114
|
if (node.object !== 'document') return;
|
|
117
115
|
|
|
118
|
-
node.findDescendant(d => {
|
|
116
|
+
node.findDescendant((d) => {
|
|
119
117
|
if (d.object === 'text') {
|
|
120
118
|
textNodeMap[index] = d;
|
|
121
119
|
}
|
|
@@ -131,12 +129,12 @@ export default function ImagePlugin(opts) {
|
|
|
131
129
|
|
|
132
130
|
if (!updateNodesArray.length) return;
|
|
133
131
|
|
|
134
|
-
return change => {
|
|
132
|
+
return (change) => {
|
|
135
133
|
change.withoutNormalization(() => {
|
|
136
|
-
updateNodesArray.forEach(n => change.insertTextByKey(n.key, 0, ' '));
|
|
134
|
+
updateNodesArray.forEach((n) => change.insertTextByKey(n.key, 0, ' '));
|
|
137
135
|
});
|
|
138
136
|
};
|
|
139
|
-
}
|
|
137
|
+
},
|
|
140
138
|
};
|
|
141
139
|
}
|
|
142
140
|
|
|
@@ -161,8 +159,8 @@ export const serialization = {
|
|
|
161
159
|
margin: el.style.margin,
|
|
162
160
|
justifyContent: el.style.justifyContent,
|
|
163
161
|
alignment: el.getAttribute('alignment'),
|
|
164
|
-
alt: el.getAttribute('alt')
|
|
165
|
-
}
|
|
162
|
+
alt: el.getAttribute('alt'),
|
|
163
|
+
},
|
|
166
164
|
};
|
|
167
165
|
log('return object: ', out);
|
|
168
166
|
return out;
|
|
@@ -216,9 +214,9 @@ export const serialization = {
|
|
|
216
214
|
src,
|
|
217
215
|
style,
|
|
218
216
|
alignment,
|
|
219
|
-
alt
|
|
217
|
+
alt,
|
|
220
218
|
};
|
|
221
219
|
|
|
222
220
|
return <img {...props} />;
|
|
223
|
-
}
|
|
221
|
+
},
|
|
224
222
|
};
|
package/src/plugins/index.jsx
CHANGED
|
@@ -29,10 +29,10 @@ function MarkHotkey(options) {
|
|
|
29
29
|
isMark: true,
|
|
30
30
|
type,
|
|
31
31
|
icon,
|
|
32
|
-
onToggle: change => {
|
|
32
|
+
onToggle: (change) => {
|
|
33
33
|
log('[onToggleMark] type: ', type);
|
|
34
34
|
return change.toggleMark(type);
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
36
|
},
|
|
37
37
|
renderMark(props) {
|
|
38
38
|
if (props.mark.type === type) {
|
|
@@ -50,7 +50,7 @@ function MarkHotkey(options) {
|
|
|
50
50
|
// Toggle the mark `type`.
|
|
51
51
|
change.toggleMark(type);
|
|
52
52
|
return true;
|
|
53
|
-
}
|
|
53
|
+
},
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -68,10 +68,10 @@ export const ALL_PLUGINS = [
|
|
|
68
68
|
'table',
|
|
69
69
|
'video',
|
|
70
70
|
'audio',
|
|
71
|
-
'responseArea'
|
|
71
|
+
'responseArea',
|
|
72
72
|
];
|
|
73
73
|
|
|
74
|
-
export const DEFAULT_PLUGINS = ALL_PLUGINS.filter(plug => plug !== 'responseArea');
|
|
74
|
+
export const DEFAULT_PLUGINS = ALL_PLUGINS.filter((plug) => plug !== 'responseArea');
|
|
75
75
|
|
|
76
76
|
export const buildPlugins = (activePlugins, opts) => {
|
|
77
77
|
log('[buildPlugins] opts: ', opts);
|
|
@@ -82,9 +82,7 @@ export const buildPlugins = (activePlugins, opts) => {
|
|
|
82
82
|
const imagePlugin = opts.image && opts.image.onDelete && ImagePlugin(opts.image);
|
|
83
83
|
const mathPlugin = MathPlugin(opts.math);
|
|
84
84
|
const respAreaPlugin =
|
|
85
|
-
opts.responseArea &&
|
|
86
|
-
opts.responseArea.type &&
|
|
87
|
-
RespAreaPlugin(opts.responseArea, compact([mathPlugin]));
|
|
85
|
+
opts.responseArea && opts.responseArea.type && RespAreaPlugin(opts.responseArea, compact([mathPlugin]));
|
|
88
86
|
|
|
89
87
|
return compact([
|
|
90
88
|
addIf('table', TablePlugin(opts.table, compact([imagePlugin, mathPlugin, respAreaPlugin]))),
|
|
@@ -97,19 +95,19 @@ export const buildPlugins = (activePlugins, opts) => {
|
|
|
97
95
|
key: '~',
|
|
98
96
|
type: 'strikethrough',
|
|
99
97
|
icon: <Strikethrough />,
|
|
100
|
-
tag: 'del'
|
|
101
|
-
})
|
|
98
|
+
tag: 'del',
|
|
99
|
+
}),
|
|
102
100
|
),
|
|
103
101
|
addIf('underline', MarkHotkey({ key: 'u', type: 'underline', icon: <Underline />, tag: 'u' })),
|
|
104
102
|
addIf('image', imagePlugin),
|
|
105
103
|
addIf('video', MediaPlugin('video', opts.media)),
|
|
106
104
|
addIf('audio', MediaPlugin('audio', opts.media)),
|
|
107
105
|
addIf('math', mathPlugin),
|
|
108
|
-
...opts.languageCharacters.map(config => addIf('languageCharacters', CharactersPlugin(config))),
|
|
106
|
+
...opts.languageCharacters.map((config) => addIf('languageCharacters', CharactersPlugin(config))),
|
|
109
107
|
addIf('bulleted-list', List({ key: 'l', type: 'ul_list', icon: <BulletedListIcon /> })),
|
|
110
108
|
addIf('numbered-list', List({ key: 'n', type: 'ol_list', icon: <NumberedListIcon /> })),
|
|
111
109
|
ToolbarPlugin(opts.toolbar),
|
|
112
110
|
SoftBreakPlugin({ shift: true }),
|
|
113
|
-
addIf('responseArea', respAreaPlugin)
|
|
111
|
+
addIf('responseArea', respAreaPlugin),
|
|
114
112
|
]);
|
|
115
113
|
};
|
|
@@ -10,7 +10,7 @@ const log = debug('@pie-lib:editable-html:plugins:list');
|
|
|
10
10
|
const b = (type, next, childNodes) => ({
|
|
11
11
|
object: 'block',
|
|
12
12
|
type,
|
|
13
|
-
nodes: next(childNodes)
|
|
13
|
+
nodes: next(childNodes),
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
export const serialization = {
|
|
@@ -43,17 +43,17 @@ export const serialization = {
|
|
|
43
43
|
if (object.type === 'ol_list') {
|
|
44
44
|
return <ol>{children}</ol>;
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
const createEditList = () => {
|
|
50
50
|
const core = EditList({
|
|
51
|
-
typeDefault: 'span'
|
|
51
|
+
typeDefault: 'span',
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
// fix outdated schema
|
|
55
55
|
if (core.schema && core.schema.blocks) {
|
|
56
|
-
Object.keys(core.schema.blocks).forEach(key => {
|
|
56
|
+
Object.keys(core.schema.blocks).forEach((key) => {
|
|
57
57
|
const block = core.schema.blocks[key];
|
|
58
58
|
|
|
59
59
|
if (block.parent) {
|
|
@@ -73,7 +73,7 @@ const createEditList = () => {
|
|
|
73
73
|
/**
|
|
74
74
|
* Returns the highest list of blocks that cover the current selection
|
|
75
75
|
*/
|
|
76
|
-
const getHighestSelectedBlocks = value => {
|
|
76
|
+
const getHighestSelectedBlocks = (value) => {
|
|
77
77
|
const range = value.selection;
|
|
78
78
|
const document = value.document;
|
|
79
79
|
|
|
@@ -111,7 +111,7 @@ const createEditList = () => {
|
|
|
111
111
|
});
|
|
112
112
|
} else if (node.type !== 'list_item') {
|
|
113
113
|
change.wrapBlockByKey(node.key, 'list_item', {
|
|
114
|
-
normalize: false
|
|
114
|
+
normalize: false,
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
});
|
|
@@ -122,13 +122,13 @@ const createEditList = () => {
|
|
|
122
122
|
return core;
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
-
export default options => {
|
|
125
|
+
export default (options) => {
|
|
126
126
|
const { type, icon } = options;
|
|
127
127
|
|
|
128
128
|
const core = createEditList();
|
|
129
129
|
|
|
130
130
|
// eslint-disable-next-line react/display-name
|
|
131
|
-
core.renderNode = props => {
|
|
131
|
+
core.renderNode = (props) => {
|
|
132
132
|
const { node, attributes, children } = props;
|
|
133
133
|
|
|
134
134
|
switch (node.type) {
|
|
@@ -162,13 +162,13 @@ export default options => {
|
|
|
162
162
|
const change = value.change().call(core.changes.wrapInList, type);
|
|
163
163
|
onChange(change);
|
|
164
164
|
}
|
|
165
|
-
}
|
|
165
|
+
},
|
|
166
166
|
};
|
|
167
167
|
|
|
168
168
|
core.renderNode.propTypes = {
|
|
169
169
|
node: PropTypes.object,
|
|
170
170
|
attributes: PropTypes.object,
|
|
171
|
-
children: PropTypes.func
|
|
171
|
+
children: PropTypes.func,
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
return core;
|