@pie-lib/editable-html 9.5.13 → 10.0.0-beta.1

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 +0 -302
  2. package/lib/components.js +116 -0
  3. package/lib/components.js.map +1 -0
  4. package/lib/editor.js +418 -103
  5. package/lib/editor.js.map +1 -1
  6. package/lib/index.js +101 -155
  7. package/lib/index.js.map +1 -1
  8. package/lib/new-serialization.js +320 -0
  9. package/lib/new-serialization.js.map +1 -0
  10. package/lib/old-serialization.js +330 -0
  11. package/lib/parse-html.js +1 -1
  12. package/lib/parse-html.js.map +1 -1
  13. package/lib/plugins/characters/custom-popper.js +1 -1
  14. package/lib/plugins/characters/custom-popper.js.map +1 -1
  15. package/lib/plugins/characters/index.js +21 -19
  16. package/lib/plugins/characters/index.js.map +1 -1
  17. package/lib/plugins/characters/utils.js +1 -1
  18. package/lib/plugins/characters/utils.js.map +1 -1
  19. package/lib/plugins/hotKeys/index.js +67 -0
  20. package/lib/plugins/hotKeys/index.js.map +1 -0
  21. package/lib/plugins/image/alt-dialog.js +1 -6
  22. package/lib/plugins/image/alt-dialog.js.map +1 -1
  23. package/lib/plugins/image/component.js +70 -53
  24. package/lib/plugins/image/component.js.map +1 -1
  25. package/lib/plugins/image/image-toolbar.js +7 -9
  26. package/lib/plugins/image/image-toolbar.js.map +1 -1
  27. package/lib/plugins/image/index.js +83 -27
  28. package/lib/plugins/image/index.js.map +1 -1
  29. package/lib/plugins/image/insert-image-handler.js +72 -33
  30. package/lib/plugins/image/insert-image-handler.js.map +1 -1
  31. package/lib/plugins/index.js +23 -41
  32. package/lib/plugins/index.js.map +1 -1
  33. package/lib/plugins/list/index.js +64 -100
  34. package/lib/plugins/list/index.js.map +1 -1
  35. package/lib/plugins/math/index.js +86 -60
  36. package/lib/plugins/math/index.js.map +1 -1
  37. package/lib/plugins/media/index.js +202 -132
  38. package/lib/plugins/media/index.js.map +1 -1
  39. package/lib/plugins/media/media-dialog.js +17 -16
  40. package/lib/plugins/media/media-dialog.js.map +1 -1
  41. package/lib/plugins/media/media-toolbar.js +3 -3
  42. package/lib/plugins/media/media-toolbar.js.map +1 -1
  43. package/lib/plugins/media/media-wrapper.js +21 -58
  44. package/lib/plugins/media/media-wrapper.js.map +1 -1
  45. package/lib/plugins/respArea/drag-in-the-blank/choice.js +3 -3
  46. package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
  47. package/lib/plugins/respArea/drag-in-the-blank/index.js +3 -2
  48. package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
  49. package/lib/plugins/respArea/explicit-constructed-response/index.js +3 -2
  50. package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
  51. package/lib/plugins/respArea/icons/index.js +13 -15
  52. package/lib/plugins/respArea/icons/index.js.map +1 -1
  53. package/lib/plugins/respArea/index.js +87 -53
  54. package/lib/plugins/respArea/index.js.map +1 -1
  55. package/lib/plugins/respArea/inline-dropdown/index.js +4 -3
  56. package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
  57. package/lib/plugins/respArea/utils.js +17 -20
  58. package/lib/plugins/respArea/utils.js.map +1 -1
  59. package/lib/plugins/table/icons/index.js +1 -1
  60. package/lib/plugins/table/icons/index.js.map +1 -1
  61. package/lib/plugins/table/index.js +381 -212
  62. package/lib/plugins/table/index.js.map +1 -1
  63. package/lib/plugins/table/table-toolbar.js +5 -6
  64. package/lib/plugins/table/table-toolbar.js.map +1 -1
  65. package/lib/plugins/toolbar/default-toolbar.js +55 -11
  66. package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
  67. package/lib/plugins/toolbar/done-button.js +1 -1
  68. package/lib/plugins/toolbar/done-button.js.map +1 -1
  69. package/lib/plugins/toolbar/editor-and-toolbar.js +186 -232
  70. package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
  71. package/lib/plugins/toolbar/index.js +1 -2
  72. package/lib/plugins/toolbar/index.js.map +1 -1
  73. package/lib/plugins/toolbar/toolbar-buttons.js +1 -1
  74. package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
  75. package/lib/plugins/toolbar/toolbar.js +253 -239
  76. package/lib/plugins/toolbar/toolbar.js.map +1 -1
  77. package/lib/plugins/utils.js +27 -2
  78. package/lib/plugins/utils.js.map +1 -1
  79. package/lib/serialization.js +1 -1
  80. package/lib/serialization.js.map +1 -1
  81. package/lib/slate-editor.js +302 -0
  82. package/lib/test-serializer.js +189 -0
  83. package/lib/test-serializer.js.map +1 -0
  84. package/lib/theme.js +1 -1
  85. package/lib/theme.js.map +1 -1
  86. package/package.json +18 -14
  87. package/playground/image/data.js +20 -20
  88. package/playground/image/index.html +22 -20
  89. package/playground/image/index.jsx +12 -10
  90. package/playground/index.html +25 -23
  91. package/playground/mathquill/index.html +23 -20
  92. package/playground/mathquill/index.jsx +18 -22
  93. package/playground/prod-test/index.html +24 -20
  94. package/playground/prod-test/index.jsx +5 -3
  95. package/playground/schema-override/data.js +10 -10
  96. package/playground/schema-override/image-plugin.jsx +3 -4
  97. package/playground/schema-override/index.html +21 -19
  98. package/playground/schema-override/index.jsx +13 -14
  99. package/playground/serialization/data.js +10 -10
  100. package/playground/serialization/image-plugin.jsx +3 -4
  101. package/playground/serialization/index.html +22 -20
  102. package/playground/table-examples.html +5 -8
  103. package/playground/webpack.config.js +10 -10
  104. package/src/components.js +135 -0
  105. package/src/editor.jsx +478 -141
  106. package/src/index.jsx +71 -95
  107. package/src/new-serialization.jsx +291 -0
  108. package/src/parse-html.js +1 -1
  109. package/src/plugins/characters/custom-popper.js +7 -7
  110. package/src/plugins/characters/index.jsx +33 -34
  111. package/src/plugins/characters/utils.js +81 -81
  112. package/src/plugins/hotKeys/index.js +54 -0
  113. package/src/plugins/image/alt-dialog.jsx +4 -5
  114. package/src/plugins/image/component.jsx +106 -89
  115. package/src/plugins/image/image-toolbar.jsx +27 -19
  116. package/src/plugins/image/index.jsx +75 -43
  117. package/src/plugins/image/insert-image-handler.js +62 -27
  118. package/src/plugins/index.jsx +23 -41
  119. package/src/plugins/list/index.jsx +70 -95
  120. package/src/plugins/math/index.jsx +102 -82
  121. package/src/plugins/media/index.jsx +159 -124
  122. package/src/plugins/media/media-dialog.js +98 -71
  123. package/src/plugins/media/media-toolbar.jsx +8 -8
  124. package/src/plugins/media/media-wrapper.jsx +29 -30
  125. package/src/plugins/respArea/drag-in-the-blank/choice.jsx +21 -19
  126. package/src/plugins/respArea/drag-in-the-blank/index.jsx +14 -11
  127. package/src/plugins/respArea/explicit-constructed-response/index.jsx +7 -6
  128. package/src/plugins/respArea/icons/index.jsx +11 -14
  129. package/src/plugins/respArea/index.jsx +92 -52
  130. package/src/plugins/respArea/inline-dropdown/index.jsx +9 -8
  131. package/src/plugins/respArea/utils.jsx +26 -35
  132. package/src/plugins/table/icons/index.jsx +17 -11
  133. package/src/plugins/table/index.jsx +288 -231
  134. package/src/plugins/table/table-toolbar.jsx +15 -11
  135. package/src/plugins/toolbar/default-toolbar.jsx +65 -19
  136. package/src/plugins/toolbar/done-button.jsx +4 -4
  137. package/src/plugins/toolbar/editor-and-toolbar.jsx +150 -145
  138. package/src/plugins/toolbar/index.jsx +2 -3
  139. package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
  140. package/src/plugins/toolbar/toolbar.jsx +244 -221
  141. package/src/plugins/utils.js +21 -4
  142. package/src/serialization.jsx +32 -32
  143. package/src/test-serializer.js +139 -0
  144. package/src/test-serializer.js.rej +20 -0
@@ -18,7 +18,7 @@ import ActionDelete from '@material-ui/icons/Delete';
18
18
 
19
19
  const log = debug('@pie-lib:editable-html:plugins:media:dialog');
20
20
 
21
- const matchYoutubeUrl = (url) => {
21
+ const matchYoutubeUrl = url => {
22
22
  if (!url) {
23
23
  return false;
24
24
  }
@@ -30,13 +30,13 @@ const matchYoutubeUrl = (url) => {
30
30
  return false;
31
31
  };
32
32
 
33
- const matchVimeoUrl = (url) =>
33
+ const matchVimeoUrl = url =>
34
34
  url &&
35
35
  /(http|https)?:\/\/(www\.)?(player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|)(video\/)?(\d+)(?:|\/\?)/.test(
36
- url,
36
+ url
37
37
  );
38
38
 
39
- const matchSoundCloudUrl = (url) => {
39
+ const matchSoundCloudUrl = url => {
40
40
  if (!url) {
41
41
  return false;
42
42
  }
@@ -45,12 +45,12 @@ const matchSoundCloudUrl = (url) => {
45
45
  return url.match(regexp) && url.match(regexp)[2];
46
46
  };
47
47
 
48
- const makeApiRequest = (url) => {
49
- return new Promise((resolve) => {
48
+ const makeApiRequest = url => {
49
+ return new Promise(resolve => {
50
50
  try {
51
51
  fetch(`https://soundcloud.com/oembed?format=json&url=${url}`)
52
- .then((response) => response.json())
53
- .then((json) => {
52
+ .then(response => response.json())
53
+ .then(json => {
54
54
  const d = document.createElement('div');
55
55
 
56
56
  d.innerHTML = json.html;
@@ -59,7 +59,7 @@ const makeApiRequest = (url) => {
59
59
 
60
60
  resolve(iframe.src);
61
61
  })
62
- .catch((err) => {
62
+ .catch(err => {
63
63
  resolve('');
64
64
  log(err);
65
65
  });
@@ -71,7 +71,7 @@ const makeApiRequest = (url) => {
71
71
 
72
72
  const typeMap = {
73
73
  video: 'Video',
74
- audio: 'Audio',
74
+ audio: 'Audio'
75
75
  };
76
76
 
77
77
  export class MediaDialog extends React.Component {
@@ -83,7 +83,7 @@ export class MediaDialog extends React.Component {
83
83
  handleClose: PropTypes.func,
84
84
  uploadSoundSupport: PropTypes.shape({
85
85
  add: PropTypes.func,
86
- delete: PropTypes.func,
86
+ delete: PropTypes.func
87
87
  }),
88
88
  type: PropTypes.string,
89
89
  src: PropTypes.string,
@@ -92,7 +92,7 @@ export class MediaDialog extends React.Component {
92
92
  starts: PropTypes.number,
93
93
  ends: PropTypes.number,
94
94
  height: PropTypes.number,
95
- width: PropTypes.number,
95
+ width: PropTypes.number
96
96
  };
97
97
 
98
98
  constructor(props) {
@@ -102,19 +102,20 @@ export class MediaDialog extends React.Component {
102
102
 
103
103
  this.state = {
104
104
  ends: ends || 0,
105
- url: url,
106
- urlToUse: urlToUse,
107
- formattedUrl: src,
105
+ url: url || '',
106
+ urlToUse: urlToUse || '',
107
+ formattedUrl: src || '',
108
108
  height: height || 315,
109
109
  invalid: false,
110
110
  starts: starts || 0,
111
111
  width: width || 560,
112
112
  tabValue: 0,
113
+ updating: false,
113
114
  fileUpload: {
114
115
  loading: false,
115
116
  url: '',
116
- error: null,
117
- },
117
+ error: null
118
+ }
118
119
  };
119
120
  }
120
121
 
@@ -122,8 +123,8 @@ export class MediaDialog extends React.Component {
122
123
  if (this.props.url) {
123
124
  this.urlChange({
124
125
  target: {
125
- value: this.props.url,
126
- },
126
+ value: this.props.url
127
+ }
127
128
  });
128
129
  }
129
130
  }
@@ -132,7 +133,7 @@ export class MediaDialog extends React.Component {
132
133
  const { url, urlToUse, starts, ends } = this.state;
133
134
  const isYoutube = matchYoutubeUrl(url);
134
135
  const isVimeo = matchVimeoUrl(url);
135
- let formattedUrl = urlToUse;
136
+ let formattedUrl = urlToUse || '';
136
137
 
137
138
  if ((isYoutube || isVimeo) && urlToUse) {
138
139
  const params = [];
@@ -170,20 +171,20 @@ export class MediaDialog extends React.Component {
170
171
  this.setState({ formattedUrl: null, updating: true }, callback);
171
172
  };
172
173
 
173
- handleStateChange = (newState) => this.setState(newState, this.formatUrl);
174
+ handleStateChange = newState => this.setState(newState, this.formatUrl);
174
175
 
175
- urlChange = (e) => {
176
+ urlChange = e => {
176
177
  const { value } = e.target || {};
177
178
  const { type } = this.props;
178
179
 
179
180
  if (type && type === 'audio') {
180
181
  if (matchSoundCloudUrl(value)) {
181
182
  makeApiRequest(value)
182
- .then((urlToUse) => {
183
+ .then(urlToUse => {
183
184
  this.handleStateChange({
184
185
  urlToUse,
185
186
  invalid: !urlToUse,
186
- url: value,
187
+ url: value || ''
187
188
  });
188
189
  })
189
190
  .catch(log);
@@ -201,8 +202,8 @@ export class MediaDialog extends React.Component {
201
202
 
202
203
  this.handleStateChange({
203
204
  urlToUse,
204
- url: value,
205
- invalid: false,
205
+ url: value || '',
206
+ invalid: false
206
207
  });
207
208
 
208
209
  return;
@@ -216,9 +217,9 @@ export class MediaDialog extends React.Component {
216
217
 
217
218
  this.handleStateChange({
218
219
  urlToUse,
219
- url: value,
220
+ url: value || '',
220
221
  ends: null,
221
- invalid: false,
222
+ invalid: false
222
223
  });
223
224
 
224
225
  return;
@@ -226,15 +227,15 @@ export class MediaDialog extends React.Component {
226
227
  }
227
228
 
228
229
  this.handleStateChange({
229
- urlToUse: null,
230
- url: null,
231
- invalid: true,
230
+ urlToUse: '',
231
+ url: '',
232
+ invalid: true
232
233
  });
233
234
  };
234
235
 
235
- changeHandler = (type) => (e) => this.handleStateChange({ [type]: e.target.value });
236
+ changeHandler = type => e => this.handleStateChange({ [type]: e.target.value });
236
237
 
237
- handleDone = (val) => {
238
+ handleDone = val => {
238
239
  const { handleClose } = this.props;
239
240
  const { tabValue, fileUpload } = this.state;
240
241
  const isInsertURL = tabValue === 0;
@@ -256,25 +257,25 @@ export class MediaDialog extends React.Component {
256
257
  width,
257
258
  url,
258
259
  urlToUse,
259
- src: formattedUrl,
260
+ src: formattedUrl
260
261
  });
261
262
  } else {
262
263
  handleClose(val, {
263
264
  tag: 'audio',
264
- src: fileUpload.url,
265
+ src: fileUpload.url
265
266
  });
266
267
  }
267
268
  };
268
269
 
269
- handleUploadFile = async (e) => {
270
+ handleUploadFile = async e => {
270
271
  e.preventDefault();
271
272
 
272
273
  this.setState({
273
274
  fileUpload: {
274
275
  ...this.state.fileUpload,
275
276
  error: null,
276
- loading: true,
277
- },
277
+ loading: true
278
+ }
278
279
  });
279
280
 
280
281
  const fileChosen = e.target.files[0];
@@ -287,8 +288,8 @@ export class MediaDialog extends React.Component {
287
288
  this.setState({
288
289
  fileUpload: {
289
290
  ...this.state.fileUpload,
290
- url: dataURL,
291
- },
291
+ url: dataURL
292
+ }
292
293
  });
293
294
  };
294
295
  reader.readAsDataURL(fileChosen);
@@ -304,32 +305,32 @@ export class MediaDialog extends React.Component {
304
305
  fileUpload: {
305
306
  ...this.state.fileUpload,
306
307
  loading: false,
307
- error: err,
308
- },
308
+ error: err
309
+ }
309
310
  });
310
311
  } else {
311
312
  this.setState({
312
313
  fileUpload: {
313
314
  ...this.state.fileUpload,
314
315
  loading: false,
315
- url: src,
316
- },
316
+ url: src
317
+ }
317
318
  });
318
319
  }
319
- },
320
+ }
320
321
  });
321
322
  };
322
323
 
323
324
  handleRemoveFile = async () => {
324
- this.props.uploadSoundSupport.delete(this.state.fileUpload.url, (err) => {
325
+ this.props.uploadSoundSupport.delete(this.state.fileUpload.url, err => {
325
326
  if (err) {
326
327
  //eslint-disable-next-line
327
328
  console.log(err);
328
329
  this.setState({
329
330
  fileUpload: {
330
331
  ...this.state.fileUpload,
331
- error: err,
332
- },
332
+ error: err
333
+ }
333
334
  });
334
335
  }
335
336
  });
@@ -339,23 +340,36 @@ export class MediaDialog extends React.Component {
339
340
  fileUpload: {
340
341
  ...this.state.fileUpload,
341
342
  loading: false,
342
- url: '',
343
- },
343
+ url: ''
344
+ }
344
345
  });
345
346
  };
346
347
 
347
348
  render() {
348
349
  const { classes, open, disablePortal, type, edit, uploadSoundSupport } = this.props;
349
- const { ends, height, invalid, starts, width, url, formattedUrl, updating, tabValue, fileUpload } = this.state;
350
+ const {
351
+ ends,
352
+ height,
353
+ invalid,
354
+ starts,
355
+ width,
356
+ url,
357
+ formattedUrl,
358
+ updating,
359
+ tabValue,
360
+ fileUpload
361
+ } = this.state;
350
362
  const isYoutube = matchYoutubeUrl(url);
351
363
  const isInsertURL = tabValue === 0;
352
364
  const isUploadMedia = tabValue === 1;
353
- const submitIsDisabled = isInsertURL ? invalid || url === null || url === undefined : !fileUpload.url;
365
+ const submitIsDisabled = isInsertURL
366
+ ? invalid || url === null || url === undefined
367
+ : !fileUpload.url;
354
368
 
355
369
  return (
356
370
  <Dialog
357
371
  classes={{
358
- paper: classes.paper,
372
+ paper: classes.paper
359
373
  }}
360
374
  disablePortal={disablePortal}
361
375
  open={open}
@@ -373,7 +387,9 @@ export class MediaDialog extends React.Component {
373
387
  this.setState({ tabValue: value });
374
388
  }}
375
389
  >
376
- <MuiTab label={type === 'video' ? 'Insert YouTube or Vimeo URL' : 'Insert SoundCloud URL'} />
390
+ <MuiTab
391
+ label={type === 'video' ? 'Insert YouTube or Vimeo URL' : 'Insert SoundCloud URL'}
392
+ />
377
393
  {uploadSoundSupport?.add && uploadSoundSupport?.delete && type !== 'video' ? (
378
394
  <MuiTab label="Upload file" />
379
395
  ) : null}
@@ -397,7 +413,7 @@ export class MediaDialog extends React.Component {
397
413
  {type === 'video' && (
398
414
  <DialogContent
399
415
  classes={{
400
- root: classes.properties,
416
+ root: classes.properties
401
417
  }}
402
418
  >
403
419
  <DialogContentText>Video Properties</DialogContentText>
@@ -437,7 +453,7 @@ export class MediaDialog extends React.Component {
437
453
  <React.Fragment>
438
454
  <DialogContent
439
455
  classes={{
440
- root: classes.properties,
456
+ root: classes.properties
441
457
  }}
442
458
  >
443
459
  <TextField
@@ -476,14 +492,25 @@ export class MediaDialog extends React.Component {
476
492
  <audio controls="controls">
477
493
  <source type="audio/mp3" src={fileUpload.url} />
478
494
  </audio>
479
- <IconButton aria-label="delete" className={classes.deleteIcon} onClick={this.handleRemoveFile}>
495
+ <IconButton
496
+ aria-label="delete"
497
+ className={classes.deleteIcon}
498
+ onClick={this.handleRemoveFile}
499
+ >
480
500
  <ActionDelete />
481
501
  </IconButton>
482
502
  </div>
483
- {fileUpload.loading ? <Typography variant="subheading">Loading...</Typography> : null}
503
+ {fileUpload.loading ? (
504
+ <Typography variant="subheading">Loading...</Typography>
505
+ ) : null}
484
506
  </>
485
507
  ) : !fileUpload.loading ? (
486
- <input accept="audio/*" className={classes.input} onChange={this.handleUploadFile} type="file" />
508
+ <input
509
+ accept="audio/*"
510
+ className={classes.input}
511
+ onChange={this.handleUploadFile}
512
+ type="file"
513
+ />
487
514
  ) : null}
488
515
  {!!fileUpload.error && (
489
516
  <Typography className={classes.error} variant="caption">
@@ -508,35 +535,35 @@ export class MediaDialog extends React.Component {
508
535
  }
509
536
  }
510
537
 
511
- const styles = (theme) => ({
538
+ const styles = () => ({
512
539
  paper: {
513
- minWidth: '500px',
540
+ minWidth: '500px'
514
541
  },
515
542
  properties: {
516
- padding: 0,
543
+ padding: 0
517
544
  },
518
545
  row: {
519
546
  display: 'flex',
520
- flexDirection: 'space-between',
547
+ flexDirection: 'space-between'
521
548
  },
522
549
  rowItem: {
523
- marginRight: theme.spacing.unit * 1.5,
524
- cursor: 'pointer',
550
+ marginRight: '12px',
551
+ cursor: 'pointer'
525
552
  },
526
553
  active: {
527
554
  color: color.primary(),
528
- borderBottom: `2px solid ${color.primary()}`,
555
+ borderBottom: `2px solid ${color.primary()}`
529
556
  },
530
557
  uploadInput: {
531
- marginTop: theme.spacing.unit * 1.5,
558
+ marginTop: '12px'
532
559
  },
533
560
  error: {
534
- marginTop: theme.spacing.unit * 1.5,
535
- color: theme.palette.error.main,
561
+ marginTop: '12px',
562
+ color: 'red'
536
563
  },
537
564
  deleteIcon: {
538
- marginLeft: theme.spacing.unit * 1.5,
539
- },
565
+ marginLeft: '12px'
566
+ }
540
567
  });
541
568
 
542
569
  export default withStyles(styles)(MediaDialog);
@@ -2,29 +2,29 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { withStyles } from '@material-ui/core/styles';
4
4
 
5
- const useStyles = withStyles((theme) => ({
5
+ const useStyles = withStyles(theme => ({
6
6
  root: {
7
7
  position: 'relative',
8
8
  bottom: '5px',
9
9
  left: 0,
10
10
  width: '100%',
11
- background: theme.palette.common.white,
11
+ background: 'white',
12
12
  display: 'inline-flex',
13
13
  padding: '5px',
14
- boxShadow: '0px 4px 4px rgba(0, 0, 0, 0.25)',
14
+ boxShadow: '0px 4px 4px rgba(0, 0, 0, 0.25)'
15
15
  },
16
16
  editContainer: {
17
17
  cursor: 'pointer',
18
18
  flex: 3,
19
- border: `solid ${theme.palette.common.black}`,
19
+ border: 'solid black',
20
20
  textAlign: 'right',
21
21
  borderWidth: '0 2px 0 0',
22
22
  marginRight: '5px',
23
- paddingRight: '5px',
23
+ paddingRight: '5px'
24
24
  },
25
25
  removeContainer: {
26
- cursor: 'pointer',
27
- },
26
+ cursor: 'pointer'
27
+ }
28
28
  }));
29
29
 
30
30
  class MediaToolbar extends React.Component {
@@ -32,7 +32,7 @@ class MediaToolbar extends React.Component {
32
32
  classes: PropTypes.object,
33
33
  onEdit: PropTypes.func,
34
34
  hideEdit: PropTypes.bool,
35
- onRemove: PropTypes.func,
35
+ onRemove: PropTypes.func
36
36
  };
37
37
 
38
38
  render() {
@@ -1,43 +1,42 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import classNames from 'classnames';
4
- import { withStyles } from '@material-ui/core/styles';
4
+ import { makeStyles } from '@material-ui/styles';
5
5
 
6
- const useStyles = withStyles(() => ({
6
+ const useStyles = makeStyles(() => ({
7
7
  root: {
8
- position: 'relative',
8
+ position: 'relative'
9
9
  },
10
10
  editor: {
11
11
  display: 'inline-block',
12
- overflow: 'hidden',
13
- },
12
+ overflow: 'hidden'
13
+ }
14
14
  }));
15
15
 
16
- class MediaWrapper extends React.Component {
17
- static propTypes = {
18
- classes: PropTypes.object,
19
- children: PropTypes.array,
20
- editor: PropTypes.bool,
21
- width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
22
- };
16
+ const MediaWrapper = React.forwardRef((props, ref) => {
17
+ const { children, width, attributes } = props;
18
+ const classes = useStyles(props);
23
19
 
24
- render() {
25
- const { editor, classes, children, width, ...rest } = this.props;
20
+ return (
21
+ <span
22
+ className={classNames(classes.root, classes.editor)}
23
+ ref={ref}
24
+ {...attributes}
25
+ contentEditable={false}
26
+ style={{
27
+ width: width || 300
28
+ }}
29
+ >
30
+ {children}
31
+ </span>
32
+ );
33
+ });
26
34
 
27
- return (
28
- <span
29
- className={classNames(classes.root, {
30
- [classes.editor]: editor,
31
- })}
32
- {...rest}
33
- style={{
34
- width: width || 300,
35
- }}
36
- >
37
- {children}
38
- </span>
39
- );
40
- }
41
- }
35
+ MediaWrapper.propTypes = {
36
+ attributes: PropTypes.object,
37
+ classes: PropTypes.object,
38
+ children: PropTypes.array,
39
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
40
+ };
42
41
 
43
- export default useStyles(MediaWrapper);
42
+ export default MediaWrapper;
@@ -9,22 +9,22 @@ import classnames from 'classnames';
9
9
 
10
10
  import { GripIcon } from '../icons';
11
11
 
12
- const useStyles = withStyles((theme) => ({
12
+ const useStyles = withStyles(theme => ({
13
13
  content: {
14
- border: `solid 0px ${theme.palette.primary.main}`,
14
+ border: `solid 0px ${theme.palette.primary.main}`
15
15
  },
16
16
  chip: {
17
- minWidth: '90px',
17
+ minWidth: '90px'
18
18
  },
19
19
  correct: {
20
- border: `solid 1px ${color.correct()}`,
20
+ border: 'solid 1px green'
21
21
  },
22
22
  incorrect: {
23
- border: `solid 1px ${theme.palette.error.main}`,
23
+ border: 'solid 1px red'
24
24
  },
25
25
  selected: {
26
- border: `2px solid ${color.primaryDark()} !important`,
27
- },
26
+ border: `2px solid ${color.primaryDark()} !important`
27
+ }
28
28
  }));
29
29
 
30
30
  export class BlankContent extends React.Component {
@@ -35,7 +35,7 @@ export class BlankContent extends React.Component {
35
35
  isOver: PropTypes.bool,
36
36
  dragItem: PropTypes.object,
37
37
  value: PropTypes.object,
38
- classes: PropTypes.object,
38
+ classes: PropTypes.object
39
39
  };
40
40
 
41
41
  constructor(props) {
@@ -75,7 +75,7 @@ export class BlankContent extends React.Component {
75
75
 
76
76
  return (
77
77
  <div
78
- ref={(ref) => (this.elementRef = ref)}
78
+ ref={ref => (this.elementRef = ref)}
79
79
  style={{
80
80
  display: 'inline-flex',
81
81
  minWidth: '178px',
@@ -86,7 +86,7 @@ export class BlankContent extends React.Component {
86
86
  borderRadius: '3px',
87
87
  overflow: 'hidden',
88
88
  position: 'relative',
89
- padding: '8px 8px 8px 35px',
89
+ padding: '8px 8px 8px 35px'
90
90
  }}
91
91
  data-key={n.key}
92
92
  contentEditable={false}
@@ -97,14 +97,14 @@ export class BlankContent extends React.Component {
97
97
  position: 'absolute',
98
98
  top: '6px',
99
99
  left: '15px',
100
- color: '#9B9B9B',
100
+ color: '#9B9B9B'
101
101
  }}
102
102
  contentEditable={false}
103
103
  />
104
104
  )}
105
105
  <span
106
106
  dangerouslySetInnerHTML={{
107
- __html: finalLabel,
107
+ __html: finalLabel
108
108
  }}
109
109
  />
110
110
  {children}
@@ -119,7 +119,9 @@ const connectedBlankContent = useStyles(({ connectDropTarget, connectDragSource,
119
119
  const { classes, isOver, value } = props;
120
120
  const dragContent = <StyledBlankContent {...props} />;
121
121
  const dragEl = !value ? dragContent : connectDragSource(<span>{dragContent}</span>);
122
- const content = <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>;
122
+ const content = (
123
+ <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>
124
+ );
123
125
 
124
126
  return connectDropTarget ? connectDropTarget(content) : content;
125
127
  });
@@ -137,20 +139,20 @@ export const tileTarget = {
137
139
  }
138
140
 
139
141
  return {
140
- dropped: shouldDrop,
142
+ dropped: shouldDrop
141
143
  };
142
144
  },
143
145
  canDrop(props, monitor) {
144
146
  const draggedItem = monitor.getItem();
145
147
 
146
148
  return draggedItem.instanceId === props.instanceId;
147
- },
149
+ }
148
150
  };
149
151
 
150
152
  const DropTile = DropTarget('drag-in-the-blank-choice', tileTarget, (connect, monitor) => ({
151
153
  connectDropTarget: connect.dropTarget(),
152
154
  isOver: monitor.isOver(),
153
- dragItem: monitor.getItem(),
155
+ dragItem: monitor.getItem()
154
156
  }))(connectedBlankContent);
155
157
 
156
158
  export const tileSource = {
@@ -162,7 +164,7 @@ export const tileSource = {
162
164
  id: props.targetId,
163
165
  value: props.value,
164
166
  instanceId: props.instanceId,
165
- fromChoice: true,
167
+ fromChoice: true
166
168
  };
167
169
  },
168
170
  endDrag(props, monitor) {
@@ -176,10 +178,10 @@ export const tileSource = {
176
178
  props.removeResponse(draggedItem.value);
177
179
  }
178
180
  }
179
- },
181
+ }
180
182
  };
181
183
 
182
184
  export default DragSource('drag-in-the-blank-choice', tileSource, (connect, monitor) => ({
183
185
  connectDragSource: connect.dragSource(),
184
- isDragging: monitor.isDragging(),
186
+ isDragging: monitor.isDragging()
185
187
  }))(DropTile);