@pie-lib/editable-html 10.0.0-beta.5 → 10.0.0-beta.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.
Files changed (144) hide show
  1. package/CHANGELOG.md +255 -152
  2. package/lib/components.js +15 -39
  3. package/lib/components.js.map +1 -1
  4. package/lib/editor.js +200 -356
  5. package/lib/editor.js.map +1 -1
  6. package/lib/index.js +25 -49
  7. package/lib/index.js.map +1 -1
  8. package/lib/new-serialization.js +6 -67
  9. package/lib/new-serialization.js.map +1 -1
  10. package/lib/parse-html.js +7 -6
  11. package/lib/parse-html.js.map +1 -1
  12. package/lib/plugins/characters/custom-popper.js +3 -13
  13. package/lib/plugins/characters/custom-popper.js.map +1 -1
  14. package/lib/plugins/characters/index.js +20 -59
  15. package/lib/plugins/characters/index.js.map +1 -1
  16. package/lib/plugins/characters/utils.js +1 -1
  17. package/lib/plugins/characters/utils.js.map +1 -1
  18. package/lib/plugins/hotKeys/index.js +9 -16
  19. package/lib/plugins/hotKeys/index.js.map +1 -1
  20. package/lib/plugins/image/alt-dialog.js +6 -27
  21. package/lib/plugins/image/alt-dialog.js.map +1 -1
  22. package/lib/plugins/image/component.js +42 -99
  23. package/lib/plugins/image/component.js.map +1 -1
  24. package/lib/plugins/image/image-toolbar.js +14 -50
  25. package/lib/plugins/image/image-toolbar.js.map +1 -1
  26. package/lib/plugins/image/index.js +16 -59
  27. package/lib/plugins/image/index.js.map +1 -1
  28. package/lib/plugins/image/insert-image-handler.js +13 -25
  29. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  30. package/lib/plugins/index.js +6 -36
  31. package/lib/plugins/index.js.map +1 -1
  32. package/lib/plugins/list/index.js +11 -46
  33. package/lib/plugins/list/index.js.map +1 -1
  34. package/lib/plugins/math/index.js +89 -93
  35. package/lib/plugins/math/index.js.map +1 -1
  36. package/lib/plugins/media/index.js +32 -109
  37. package/lib/plugins/media/index.js.map +1 -1
  38. package/lib/plugins/media/media-dialog.js +107 -195
  39. package/lib/plugins/media/media-dialog.js.map +1 -1
  40. package/lib/plugins/media/media-toolbar.js +7 -27
  41. package/lib/plugins/media/media-toolbar.js.map +1 -1
  42. package/lib/plugins/media/media-wrapper.js +9 -14
  43. package/lib/plugins/media/media-wrapper.js.map +1 -1
  44. package/lib/plugins/respArea/drag-in-the-blank/choice.js +13 -53
  45. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  46. package/lib/plugins/respArea/drag-in-the-blank/index.js +6 -20
  47. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  48. package/lib/plugins/respArea/explicit-constructed-response/index.js +5 -10
  49. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  50. package/lib/plugins/respArea/icons/index.js +16 -31
  51. package/lib/plugins/respArea/icons/index.js.map +1 -1
  52. package/lib/plugins/respArea/index.js +7 -54
  53. package/lib/plugins/respArea/index.js.map +1 -1
  54. package/lib/plugins/respArea/inline-dropdown/index.js +3 -10
  55. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  56. package/lib/plugins/respArea/utils.js +6 -21
  57. package/lib/plugins/respArea/utils.js.map +1 -1
  58. package/lib/plugins/table/icons/index.js +1 -8
  59. package/lib/plugins/table/icons/index.js.map +1 -1
  60. package/lib/plugins/table/index.js +54 -187
  61. package/lib/plugins/table/index.js.map +1 -1
  62. package/lib/plugins/table/table-toolbar.js +12 -44
  63. package/lib/plugins/table/table-toolbar.js.map +1 -1
  64. package/lib/plugins/toolbar/default-toolbar.js +17 -46
  65. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  66. package/lib/plugins/toolbar/done-button.js +2 -10
  67. package/lib/plugins/toolbar/done-button.js.map +1 -1
  68. package/lib/plugins/toolbar/editor-and-toolbar.js +134 -144
  69. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  70. package/lib/plugins/toolbar/index.js +2 -6
  71. package/lib/plugins/toolbar/index.js.map +1 -1
  72. package/lib/plugins/toolbar/toolbar-buttons.js +9 -40
  73. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  74. package/lib/plugins/toolbar/toolbar.js +29 -83
  75. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  76. package/lib/plugins/utils.js +8 -30
  77. package/lib/plugins/utils.js.map +1 -1
  78. package/lib/serialization.js +11 -69
  79. package/lib/serialization.js.map +1 -1
  80. package/lib/test-serializer.js +3 -46
  81. package/lib/test-serializer.js.map +1 -1
  82. package/lib/theme.js +1 -1
  83. package/lib/theme.js.map +1 -1
  84. package/package.json +7 -7
  85. package/playground/image/data.js +20 -20
  86. package/playground/image/index.html +20 -22
  87. package/playground/image/index.jsx +10 -12
  88. package/playground/index.html +23 -25
  89. package/playground/mathquill/index.html +20 -23
  90. package/playground/mathquill/index.jsx +22 -18
  91. package/playground/prod-test/index.html +20 -24
  92. package/playground/prod-test/index.jsx +3 -5
  93. package/playground/schema-override/data.js +10 -10
  94. package/playground/schema-override/image-plugin.jsx +4 -3
  95. package/playground/schema-override/index.html +19 -21
  96. package/playground/schema-override/index.jsx +14 -13
  97. package/playground/serialization/data.js +10 -10
  98. package/playground/serialization/image-plugin.jsx +4 -3
  99. package/playground/serialization/index.html +20 -22
  100. package/playground/table-examples.html +8 -5
  101. package/playground/webpack.config.js +10 -10
  102. package/src/components.js +7 -7
  103. package/src/editor.jsx +144 -155
  104. package/src/index.jsx +24 -17
  105. package/src/new-serialization.jsx +22 -22
  106. package/src/parse-html.js +1 -1
  107. package/src/plugins/characters/custom-popper.js +7 -7
  108. package/src/plugins/characters/index.jsx +36 -26
  109. package/src/plugins/characters/utils.js +81 -81
  110. package/src/plugins/hotKeys/index.js +3 -3
  111. package/src/plugins/image/alt-dialog.jsx +5 -4
  112. package/src/plugins/image/component.jsx +52 -53
  113. package/src/plugins/image/image-toolbar.jsx +19 -27
  114. package/src/plugins/image/index.jsx +41 -47
  115. package/src/plugins/image/insert-image-handler.js +23 -14
  116. package/src/plugins/index.jsx +8 -10
  117. package/src/plugins/list/index.jsx +21 -24
  118. package/src/plugins/math/index.jsx +93 -40
  119. package/src/plugins/media/index.jsx +42 -42
  120. package/src/plugins/media/media-dialog.js +63 -89
  121. package/src/plugins/media/media-toolbar.jsx +8 -8
  122. package/src/plugins/media/media-wrapper.jsx +10 -7
  123. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +19 -21
  124. package/src/plugins/respArea/drag-in-the-blank/index.jsx +10 -12
  125. package/src/plugins/respArea/explicit-constructed-response/index.jsx +6 -5
  126. package/src/plugins/respArea/icons/index.jsx +14 -11
  127. package/src/plugins/respArea/index.jsx +32 -56
  128. package/src/plugins/respArea/inline-dropdown/index.jsx +6 -6
  129. package/src/plugins/respArea/utils.jsx +15 -11
  130. package/src/plugins/table/icons/index.jsx +11 -17
  131. package/src/plugins/table/index.jsx +69 -69
  132. package/src/plugins/table/table-toolbar.jsx +8 -13
  133. package/src/plugins/toolbar/default-toolbar.jsx +15 -17
  134. package/src/plugins/toolbar/done-button.jsx +4 -4
  135. package/src/plugins/toolbar/editor-and-toolbar.jsx +50 -54
  136. package/src/plugins/toolbar/index.jsx +3 -2
  137. package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
  138. package/src/plugins/toolbar/toolbar.jsx +43 -42
  139. package/src/plugins/utils.js +7 -8
  140. package/src/serialization.jsx +34 -32
  141. package/src/test-serializer.js +13 -13
  142. package/lib/old-serialization.js +0 -330
  143. package/lib/slate-editor.js +0 -302
  144. package/package-lock.json +0 -3762
@@ -10,39 +10,39 @@ import { Editor } from 'slate';
10
10
 
11
11
  const log = debug('@pie-lib:editable-html:plugins:image:component');
12
12
 
13
- const size = s => (s ? `${s}px` : 'auto');
13
+ const size = (s) => (s ? `${s}px` : 'auto');
14
14
 
15
15
  export class Component extends React.Component {
16
16
  static propTypes = {
17
17
  node: PropTypes.shape({
18
18
  type: PropTypes.string,
19
19
  children: PropTypes.array,
20
- data: PropTypes.object
20
+ data: PropTypes.object,
21
21
  }).isRequired,
22
22
  focused: PropTypes.bool,
23
23
  editor: PropTypes.shape({
24
24
  change: PropTypes.func.isRequired,
25
- value: PropTypes.object
25
+ value: PropTypes.object,
26
26
  }).isRequired,
27
27
  classes: PropTypes.object.isRequired,
28
28
  attributes: PropTypes.object,
29
29
  onFocus: PropTypes.func,
30
30
  onBlur: PropTypes.func,
31
31
  maxImageWidth: PropTypes.number,
32
- maxImageHeight: PropTypes.number
32
+ maxImageHeight: PropTypes.number,
33
33
  };
34
34
 
35
- getWidth = percent => {
35
+ getWidth = (percent) => {
36
36
  const multiplier = percent / 100;
37
37
  return this.img.naturalWidth * multiplier;
38
38
  };
39
39
 
40
- getHeight = percent => {
40
+ getHeight = (percent) => {
41
41
  const multiplier = percent / 100;
42
42
  return this.img.naturalHeight * multiplier;
43
43
  };
44
44
 
45
- getPercentFromWidth = width => {
45
+ getPercentFromWidth = (width) => {
46
46
  var floored = (width / this.img.naturalWidth) * 4;
47
47
  return parseInt(floored.toFixed(0) * 25, 10);
48
48
  };
@@ -67,9 +67,9 @@ export class Component extends React.Component {
67
67
  type: 'set_node',
68
68
  path: nodePath,
69
69
  properties: {
70
- data: node.data
70
+ data: node.data,
71
71
  },
72
- newProperties: { data: update }
72
+ newProperties: { data: update },
73
73
  });
74
74
  }
75
75
  };
@@ -97,7 +97,7 @@ export class Component extends React.Component {
97
97
  return {
98
98
  width: size(data.width),
99
99
  height: size(data.height),
100
- objectFit: 'contain'
100
+ objectFit: 'contain',
101
101
  };
102
102
  }
103
103
 
@@ -112,23 +112,23 @@ export class Component extends React.Component {
112
112
  if (!box.style.width || box.style.width === 'auto') {
113
113
  const dimensions = {
114
114
  width: (box && box.naturalWidth) || 100,
115
- height: (box && box.naturalHeight) || 100
115
+ height: (box && box.naturalHeight) || 100,
116
116
  };
117
117
 
118
118
  const { width, height } = this.updateImageDimensions(
119
119
  dimensions,
120
120
  {
121
121
  width: dimensions.width < maxImageWidth ? dimensions.width : maxImageWidth,
122
- height: dimensions.height < maxImageHeight ? dimensions.height : maxImageHeight
122
+ height: dimensions.height < maxImageHeight ? dimensions.height : maxImageHeight,
123
123
  },
124
- true
124
+ true,
125
125
  );
126
126
 
127
127
  box.style.width = `${width}px`;
128
128
  box.style.height = `${height}px`;
129
129
 
130
130
  this.setState({
131
- dimensions: { height: height, width: width }
131
+ dimensions: { height: height, width: width },
132
132
  });
133
133
 
134
134
  const { node, editor } = this.props;
@@ -145,29 +145,29 @@ export class Component extends React.Component {
145
145
  type: 'set_node',
146
146
  path: nodePath,
147
147
  properties: {
148
- data: node.data
148
+ data: node.data,
149
149
  },
150
- newProperties: { data: update }
150
+ newProperties: { data: update },
151
151
  });
152
152
  }
153
153
  }
154
154
  };
155
155
 
156
- startResizing = e => {
156
+ startResizing = (e) => {
157
157
  const bounds = e.target.getBoundingClientRect();
158
158
  const box = this.img;
159
159
  const dimensions = {
160
160
  width: (box && box.naturalWidth) || 100,
161
- height: (box && box.naturalHeight) || 100
161
+ height: (box && box.naturalHeight) || 100,
162
162
  };
163
163
 
164
164
  const { width, height } = this.updateImageDimensions(
165
165
  dimensions,
166
166
  {
167
167
  width: e.clientX - bounds.left,
168
- height: e.clientY - bounds.top
168
+ height: e.clientY - bounds.top,
169
169
  },
170
- true
170
+ true,
171
171
  );
172
172
 
173
173
  const hasMinimumWidth = width > 50 && height > 50;
@@ -178,7 +178,7 @@ export class Component extends React.Component {
178
178
  box.style.height = `${height}px`;
179
179
 
180
180
  this.setState({
181
- dimensions: { height: height, width: width }
181
+ dimensions: { height: height, width: width },
182
182
  });
183
183
 
184
184
  const { node, editor } = this.props;
@@ -189,7 +189,7 @@ export class Component extends React.Component {
189
189
  update = update.set('height', height);
190
190
 
191
191
  if (!update.equals(node.data)) {
192
- editor.change(c => c.setNodeByKey(node.key, { data: update }));
192
+ editor.change((c) => c.setNodeByKey(node.key, { data: update }));
193
193
  }
194
194
  }
195
195
  };
@@ -208,21 +208,21 @@ export class Component extends React.Component {
208
208
  // if we want to change image height => we update the width accordingly
209
209
  return {
210
210
  width: nextDim.height * imageAspectRatio,
211
- height: nextDim.height
211
+ height: nextDim.height,
212
212
  };
213
213
  }
214
214
 
215
215
  // if we want to change image width => we update the height accordingly
216
216
  return {
217
217
  width: nextDim.width,
218
- height: nextDim.width / imageAspectRatio
218
+ height: nextDim.width / imageAspectRatio,
219
219
  };
220
220
  }
221
221
 
222
222
  // if we don't want to keep aspect ratio, we just update both values
223
223
  return {
224
224
  width: nextDim.width,
225
- height: nextDim.height
225
+ height: nextDim.height,
226
226
  };
227
227
  };
228
228
 
@@ -237,12 +237,15 @@ export class Component extends React.Component {
237
237
  case 'left':
238
238
  justifyContent = 'flex-start';
239
239
  break;
240
+
240
241
  case 'center':
241
242
  justifyContent = 'center';
242
243
  break;
244
+
243
245
  case 'right':
244
246
  justifyContent = 'flex-end';
245
247
  break;
248
+
246
249
  default:
247
250
  justifyContent = 'flex-start';
248
251
  break;
@@ -255,25 +258,21 @@ export class Component extends React.Component {
255
258
 
256
259
  const className = classNames(classes.root, {
257
260
  [classes.loading]: !isLoaded,
258
- [classes.pendingDelete]: deleteStatus === 'pending'
261
+ [classes.pendingDelete]: deleteStatus === 'pending',
259
262
  });
260
263
 
261
264
  const progressClasses = classNames(classes.progress, {
262
- [classes.hideProgress]: isLoaded
265
+ [classes.hideProgress]: isLoaded,
263
266
  });
264
267
 
265
268
  return (
266
269
  <div onFocus={onFocus} className={className} style={{ justifyContent }} {...attributes}>
267
270
  {children}
268
- <LinearProgress
269
- mode="determinate"
270
- value={percent > 0 ? percent : 0}
271
- className={progressClasses}
272
- />
271
+ <LinearProgress mode="determinate" value={percent > 0 ? percent : 0} className={progressClasses} />
273
272
  <div className={classes.imageContainer}>
274
273
  <img
275
274
  className={classNames(classes.image, { [classes.active]: active })}
276
- ref={ref => {
275
+ ref={(ref) => {
277
276
  this.img = ref;
278
277
  }}
279
278
  src={src}
@@ -282,7 +281,7 @@ export class Component extends React.Component {
282
281
  alt={alt}
283
282
  />
284
283
  <div
285
- ref={ref => {
284
+ ref={(ref) => {
286
285
  this.resize = ref;
287
286
  }}
288
287
  className={classNames(classes.resize, 'resize')}
@@ -293,47 +292,47 @@ export class Component extends React.Component {
293
292
  }
294
293
  }
295
294
 
296
- const styles = theme => ({
295
+ const styles = (theme) => ({
297
296
  portal: {
298
297
  position: 'absolute',
299
298
  opacity: 0,
300
- transition: 'opacity 200ms linear'
299
+ transition: 'opacity 200ms linear',
301
300
  },
302
301
  floatingButtonRow: {
303
- backgroundColor: 'white',
302
+ backgroundColor: theme.palette.background.paper,
304
303
  borderRadius: '1px',
305
304
  display: 'flex',
306
305
  padding: '10px',
307
- border: 'solid 1px #eeeeee',
306
+ border: `solid 1px ${theme.palette.grey[200]}`,
308
307
  boxShadow:
309
- '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)'
308
+ '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)',
310
309
  },
311
310
  progress: {
312
311
  position: 'absolute',
313
312
  left: '0',
314
313
  width: 'fit-content',
315
314
  top: '0%',
316
- transition: 'opacity 200ms linear'
315
+ transition: 'opacity 200ms linear',
317
316
  },
318
317
  hideProgress: {
319
- opacity: 0
318
+ opacity: 0,
320
319
  },
321
320
  loading: {
322
- opacity: 0.3
321
+ opacity: 0.3,
323
322
  },
324
323
  pendingDelete: {
325
- opacity: 0.3
324
+ opacity: 0.3,
326
325
  },
327
326
  root: {
328
327
  position: 'relative',
329
- border: 'solid 1px white',
330
- display: 'inline-flex',
328
+ border: `solid 1px ${theme.palette.common.white}`,
329
+ display: 'flex',
331
330
  transition: 'opacity 200ms linear',
332
- width: '100%'
331
+ width: '100%',
333
332
  },
334
333
  delete: {
335
334
  position: 'absolute',
336
- right: 0
335
+ right: 0,
337
336
  },
338
337
  imageContainer: {
339
338
  position: 'relative',
@@ -342,11 +341,11 @@ const styles = theme => ({
342
341
  alignItems: 'center',
343
342
 
344
343
  '&&:hover > .resize': {
345
- display: 'block'
346
- }
344
+ display: 'block',
345
+ },
347
346
  },
348
347
  active: {
349
- border: `solid 1px ${theme.palette.primary.main}`
348
+ border: `solid 1px ${theme.palette.primary.main}`,
350
349
  },
351
350
  resize: {
352
351
  backgroundColor: theme.palette.primary.main,
@@ -356,11 +355,11 @@ const styles = theme => ({
356
355
  borderRadius: 8,
357
356
  marginLeft: '5px',
358
357
  marginRight: '10px',
359
- display: 'none'
358
+ display: 'none',
360
359
  },
361
360
  drawableHeight: {
362
- minHeight: 350
363
- }
361
+ minHeight: 350,
362
+ },
364
363
  });
365
364
 
366
365
  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 {
@@ -30,16 +30,17 @@ export class ImageToolbar extends React.Component {
30
30
  classes: PropTypes.object.isRequired,
31
31
  alignment: PropTypes.string,
32
32
  alt: PropTypes.string,
33
- imageLoaded: PropTypes.bool
33
+ imageLoaded: PropTypes.bool,
34
+ disableImageAlignmentButtons: PropTypes.bool,
34
35
  };
35
36
 
36
- onAltTextDone = newAlt => {
37
+ onAltTextDone = (newAlt) => {
37
38
  log('[onAltTextDone]: alt:', newAlt);
38
39
 
39
- this.props.onChange({ alt: newAlt });
40
+ this.props.onChange({ alt: newAlt }, true);
40
41
  };
41
42
 
42
- onAlignmentClick = alignment => {
43
+ onAlignmentClick = (alignment) => {
43
44
  log('[onAlignmentClick]: alignment:', alignment);
44
45
  this.props.onChange({ alignment });
45
46
  };
@@ -56,31 +57,22 @@ export class ImageToolbar extends React.Component {
56
57
  };
57
58
 
58
59
  render() {
59
- const { classes, alignment, imageLoaded } = this.props;
60
-
60
+ const { classes, alignment, imageLoaded, disableImageAlignmentButtons } = this.props;
61
61
  return (
62
62
  <div className={classes.holder}>
63
- <AlignmentButton
64
- alignment={'left'}
65
- active={alignment === 'left'}
66
- onClick={this.onAlignmentClick}
67
- />
68
- <AlignmentButton
69
- alignment={'center'}
70
- active={alignment === 'center'}
71
- onClick={this.onAlignmentClick}
72
- />
73
- <AlignmentButton
74
- alignment={'right'}
75
- active={alignment === 'right'}
76
- onClick={this.onAlignmentClick}
77
- />
63
+ {!disableImageAlignmentButtons && (
64
+ <>
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} />
68
+ </>
69
+ )}
78
70
  <span
79
71
  className={classNames({
80
72
  [classes.disabled]: !imageLoaded,
81
- [classes.altButton]: true
73
+ [classes.altButton]: !disableImageAlignmentButtons,
82
74
  })}
83
- onMouseDown={event => imageLoaded && this.renderDialog(event)}
75
+ onMouseDown={(event) => imageLoaded && this.renderDialog(event)}
84
76
  >
85
77
  Alt text
86
78
  </span>
@@ -89,14 +81,14 @@ export class ImageToolbar extends React.Component {
89
81
  }
90
82
  }
91
83
 
92
- const styles = theme => ({
84
+ const styles = (theme) => ({
93
85
  holder: {
94
86
  paddingLeft: theme.spacing.unit,
95
87
  display: 'flex',
96
- alignItems: 'center'
88
+ alignItems: 'center',
97
89
  },
98
90
  disabled: {
99
- opacity: 0.5
91
+ opacity: 0.5,
100
92
  },
101
93
  altButton: {
102
94
  borderLeft: '1px solid grey',
@@ -15,16 +15,16 @@ const log = debug('@pie-lib:editable-html:plugins:image');
15
15
  export default function ImagePlugin(opts) {
16
16
  const toolbar = opts.insertImageRequested && {
17
17
  icon: <Image />,
18
- onClick: editor => {
18
+ onClick: (editor) => {
19
19
  log('[toolbar] onClick');
20
20
  const inline = {
21
21
  type: 'image',
22
22
  data: {
23
23
  newImage: true,
24
24
  loaded: false,
25
- src: undefined
25
+ src: undefined,
26
26
  },
27
- children: [{ text: '' }]
27
+ children: [{ text: '' }],
28
28
  };
29
29
 
30
30
  editor.insertNode(inline);
@@ -38,65 +38,71 @@ export default function ImagePlugin(opts) {
38
38
  const alignment = node.data.alignment;
39
39
  const alt = node.data.alt;
40
40
  const imageLoaded = node.data.loaded !== false;
41
- const onChange = newValues => {
41
+ const onChange = (newValues) => {
42
42
  const update = {
43
43
  ...node.data,
44
- ...newValues
44
+ ...newValues,
45
45
  };
46
46
 
47
47
  editor.apply({
48
48
  type: 'set_node',
49
49
  path: nodePath,
50
50
  properties: {
51
- data: node.data
51
+ data: node.data,
52
52
  },
53
- newProperties: { data: update }
53
+ newProperties: { data: update },
54
54
  });
55
55
 
56
56
  onToolbarDone(null, false);
57
57
  };
58
58
 
59
59
  const Tb = () => (
60
- <ImageToolbar alt={alt} imageLoaded={imageLoaded} alignment={alignment || 'left'} onChange={onChange} />
60
+ <ImageToolbar
61
+ disableImageAlignmentButtons={opts.disableImageAlignmentButtons}
62
+ alt={alt}
63
+ imageLoaded={imageLoaded}
64
+ alignment={alignment || 'left'}
65
+ onChange={onChange}
66
+ />
61
67
  );
62
68
  return Tb;
63
69
  },
64
- showDone: true
70
+ showDone: true,
65
71
  };
66
72
 
67
73
  return {
68
74
  name: 'image',
69
75
  toolbar,
70
- rules: editor => {
76
+ rules: (editor) => {
71
77
  const { isVoid, isInline } = editor;
72
78
 
73
- editor.isVoid = element => {
79
+ editor.isVoid = (element) => {
74
80
  return element.type === 'image' ? true : isVoid(element);
75
81
  };
76
82
 
77
- editor.isInline = element => {
83
+ editor.isInline = (element) => {
78
84
  return element.type === 'image' ? true : isInline(element);
79
85
  };
80
86
 
81
87
  return editor;
82
88
  },
83
- supports: node => node.type === 'image',
89
+ supports: (node) => node.type === 'image',
84
90
  deleteNode: (e, node, nodePath, editor, onChange) => {
85
91
  e.preventDefault();
86
92
 
87
93
  if (opts.onDelete) {
88
94
  const update = {
89
95
  ...node.data,
90
- deleteStatus: 'pending'
96
+ deleteStatus: 'pending',
91
97
  };
92
98
 
93
99
  editor.apply({
94
100
  type: 'set_node',
95
101
  path: nodePath,
96
102
  properties: {
97
- data: node.data
103
+ data: node.data,
98
104
  },
99
- newProperties: { data: update }
105
+ newProperties: { data: update },
100
106
  });
101
107
 
102
108
  editor.selection = null;
@@ -105,7 +111,7 @@ export default function ImagePlugin(opts) {
105
111
  if (!err) {
106
112
  editor.apply({
107
113
  type: 'remove_node',
108
- path: nodePath
114
+ path: nodePath,
109
115
  });
110
116
  } else {
111
117
  log('[error]: ', err);
@@ -113,9 +119,9 @@ export default function ImagePlugin(opts) {
113
119
  type: 'set_node',
114
120
  path: nodePath,
115
121
  properties: {
116
- data: node.data
122
+ data: node.data,
117
123
  },
118
- newProperties: { data: { ...node.data, deleteStatus: 'failed' } }
124
+ newProperties: { data: { ...node.data, deleteStatus: 'failed' } },
119
125
  });
120
126
  }
121
127
 
@@ -128,15 +134,15 @@ export default function ImagePlugin(opts) {
128
134
  editor.selection = null;
129
135
  editor.apply({
130
136
  type: 'remove_node',
131
- path: nodePath
137
+ path: nodePath,
132
138
  });
133
139
  onChange(editor, () => {
134
140
  setTimeout(() => ReactEditor.focus(editor), 50);
135
141
  });
136
142
  }
137
143
  },
138
- stopReset: value => {
139
- const imgPendingInsertion = value.document.findDescendant(n => {
144
+ stopReset: (value) => {
145
+ const imgPendingInsertion = value.document.findDescendant((n) => {
140
146
  if (n.type !== 'image') {
141
147
  return;
142
148
  }
@@ -153,25 +159,21 @@ export default function ImagePlugin(opts) {
153
159
  onFocus: opts.onFocus,
154
160
  onBlur: opts.onBlur,
155
161
  maxImageWidth: opts.maxImageWidth,
156
- maxImageHeight: opts.maxImageHeight
162
+ maxImageHeight: opts.maxImageHeight,
157
163
  },
158
- props
159
- );
160
- return (
161
- <ImageComponent {...all}>
162
- {props.children}
163
- </ImageComponent>
164
+ props,
164
165
  );
166
+ return <ImageComponent {...all}>{props.children}</ImageComponent>;
165
167
  }
166
168
  },
167
- normalizeNode: node => {
169
+ normalizeNode: (node) => {
168
170
  const textNodeMap = {};
169
171
  const updateNodesArray = [];
170
172
  let index = 0;
171
173
 
172
174
  if (node.object !== 'document') return;
173
175
 
174
- node.findDescendant(d => {
176
+ node.findDescendant((d) => {
175
177
  if (d.object === 'text') {
176
178
  textNodeMap[index] = d;
177
179
  }
@@ -187,12 +189,12 @@ export default function ImagePlugin(opts) {
187
189
 
188
190
  if (!updateNodesArray.length) return;
189
191
 
190
- return change => {
192
+ return (change) => {
191
193
  change.withoutNormalization(() => {
192
- updateNodesArray.forEach(n => change.insertTextByKey(n.key, 0, ' '));
194
+ updateNodesArray.forEach((n) => change.insertTextByKey(n.key, 0, ' '));
193
195
  });
194
196
  };
195
- }
197
+ },
196
198
  };
197
199
  }
198
200
 
@@ -215,8 +217,8 @@ export const serialization = {
215
217
  margin: el.style.margin,
216
218
  justifyContent: el.style.justifyContent,
217
219
  alignment: el.getAttribute('alignment'),
218
- alt: el.getAttribute('alt')
219
- }
220
+ alt: el.getAttribute('alt'),
221
+ },
220
222
  });
221
223
  log('return object: ', out);
222
224
  return out;
@@ -225,15 +227,7 @@ export const serialization = {
225
227
  if (object.type !== 'image') return;
226
228
 
227
229
  const { data } = object;
228
- const {
229
- alignment,
230
- alt,
231
- src,
232
- height,
233
- margin,
234
- justifyContent,
235
- width
236
- } = data;
230
+ const { alignment, alt, src, height, margin, justifyContent, width } = data;
237
231
  const style = {};
238
232
 
239
233
  if (width) {
@@ -273,9 +267,9 @@ export const serialization = {
273
267
  src,
274
268
  style,
275
269
  alignment,
276
- alt
270
+ alt,
277
271
  };
278
272
 
279
273
  return <img {...props} />;
280
- }
274
+ },
281
275
  };