@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
@@ -5,26 +5,29 @@ import { makeStyles } from '@material-ui/styles';
5
5
 
6
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
16
  const MediaWrapper = React.forwardRef((props, ref) => {
17
- const { children, width, attributes } = props;
17
+ const { children, width, attributes, ...rest } = props;
18
18
  const classes = useStyles(props);
19
19
 
20
20
  return (
21
21
  <span
22
- className={classNames(classes.root, classes.editor)}
22
+ className={classNames(classes.root, {
23
+ [classes.editor]: editor,
24
+ })}
23
25
  ref={ref}
26
+ {...rest}
24
27
  {...attributes}
25
28
  contentEditable={false}
26
29
  style={{
27
- width: width || 300
30
+ width: width || 300,
28
31
  }}
29
32
  >
30
33
  {children}
@@ -36,7 +39,7 @@ MediaWrapper.propTypes = {
36
39
  attributes: PropTypes.object,
37
40
  classes: PropTypes.object,
38
41
  children: PropTypes.array,
39
- width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
42
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
40
43
  };
41
44
 
42
45
  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 green'
20
+ border: `solid 1px ${color.correct()}`,
21
21
  },
22
22
  incorrect: {
23
- border: 'solid 1px red'
23
+ border: `solid 1px ${theme.palette.error.main}`,
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,9 +119,7 @@ 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 = (
123
- <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>
124
- );
122
+ const content = <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>;
125
123
 
126
124
  return connectDropTarget ? connectDropTarget(content) : content;
127
125
  });
@@ -139,20 +137,20 @@ export const tileTarget = {
139
137
  }
140
138
 
141
139
  return {
142
- dropped: shouldDrop
140
+ dropped: shouldDrop,
143
141
  };
144
142
  },
145
143
  canDrop(props, monitor) {
146
144
  const draggedItem = monitor.getItem();
147
145
 
148
146
  return draggedItem.instanceId === props.instanceId;
149
- }
147
+ },
150
148
  };
151
149
 
152
150
  const DropTile = DropTarget('drag-in-the-blank-choice', tileTarget, (connect, monitor) => ({
153
151
  connectDropTarget: connect.dropTarget(),
154
152
  isOver: monitor.isOver(),
155
- dragItem: monitor.getItem()
153
+ dragItem: monitor.getItem(),
156
154
  }))(connectedBlankContent);
157
155
 
158
156
  export const tileSource = {
@@ -164,7 +162,7 @@ export const tileSource = {
164
162
  id: props.targetId,
165
163
  value: props.value,
166
164
  instanceId: props.instanceId,
167
- fromChoice: true
165
+ fromChoice: true,
168
166
  };
169
167
  },
170
168
  endDrag(props, monitor) {
@@ -178,10 +176,10 @@ export const tileSource = {
178
176
  props.removeResponse(draggedItem.value);
179
177
  }
180
178
  }
181
- }
179
+ },
182
180
  };
183
181
 
184
182
  export default DragSource('drag-in-the-blank-choice', tileSource, (connect, monitor) => ({
185
183
  connectDragSource: connect.dragSource(),
186
- isDragging: monitor.isDragging()
184
+ isDragging: monitor.isDragging(),
187
185
  }))(DropTile);
@@ -9,8 +9,8 @@ export const onValueChange = (nodeProps, n, value) => {
9
9
  change.setNodeByKey(n.key, {
10
10
  data: {
11
11
  ...value,
12
- index: n.data.index
13
- }
12
+ index: n.data.index,
13
+ },
14
14
  });
15
15
 
16
16
  nodeProps.editor.props.onChange(change, () => {
@@ -21,14 +21,12 @@ export const onValueChange = (nodeProps, n, value) => {
21
21
  export const onRemoveResponse = (nodeProps, value) => {
22
22
  const val = nodeProps.editor.value;
23
23
  const change = val.change();
24
- const dragInTheBlank = val.document.findDescendant(
25
- n => n.data && n.data.index === value.index
26
- );
24
+ const dragInTheBlank = val.document.findDescendant((n) => n.data && n.data.index === value.index);
27
25
 
28
26
  change.setNodeByKey(dragInTheBlank.key, {
29
27
  data: {
30
- index: dragInTheBlank.data.index
31
- }
28
+ index: dragInTheBlank.data.index,
29
+ },
32
30
  });
33
31
 
34
32
  nodeProps.editor.props.onChange(change, () => {
@@ -36,7 +34,7 @@ export const onRemoveResponse = (nodeProps, value) => {
36
34
  });
37
35
  };
38
36
 
39
- const DragDrop = props => {
37
+ const DragDrop = (props) => {
40
38
  const { attributes, children, data, n, nodeProps, opts } = props;
41
39
  const { inTable } = data;
42
40
 
@@ -49,7 +47,7 @@ const DragDrop = props => {
49
47
  minWidth: '178px',
50
48
  position: 'relative',
51
49
  margin: inTable ? '10px' : '0 10px',
52
- cursor: 'pointer'
50
+ cursor: 'pointer',
53
51
  }}
54
52
  >
55
53
  <DragDropTile
@@ -58,8 +56,8 @@ const DragDrop = props => {
58
56
  targetId="0"
59
57
  value={data}
60
58
  duplicates={opts.options.duplicates}
61
- onChange={value => onValueChange(nodeProps, n, value)}
62
- removeResponse={value => onRemoveResponse(nodeProps, value)}
59
+ onChange={(value) => onValueChange(nodeProps, n, value)}
60
+ removeResponse={(value) => onRemoveResponse(nodeProps, value)}
63
61
  >
64
62
  {nodeProps.children}
65
63
  {children}
@@ -73,7 +71,7 @@ DragDrop.propTypes = {
73
71
  data: PropTypes.object,
74
72
  n: PropTypes.object,
75
73
  nodeProps: PropTypes.object,
76
- opts: PropTypes.object
74
+ opts: PropTypes.object,
77
75
  };
78
76
 
79
77
  export default DragDrop;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- const ExplicitConstructedResponse = props => {
4
+ const ExplicitConstructedResponse = (props) => {
5
5
  const { attributes, children, value, error } = props;
6
6
 
7
7
  return (
@@ -13,7 +13,7 @@ const ExplicitConstructedResponse = props => {
13
13
  minWidth: '178px',
14
14
  position: 'relative',
15
15
  margin: '0 5px',
16
- cursor: 'pointer'
16
+ cursor: 'pointer',
17
17
  }}
18
18
  >
19
19
  <div
@@ -27,10 +27,10 @@ const ExplicitConstructedResponse = props => {
27
27
  boxSizing: 'border-box',
28
28
  borderRadius: '3px',
29
29
  overflow: 'hidden',
30
- padding: '8px'
30
+ padding: '8px',
31
31
  }}
32
32
  dangerouslySetInnerHTML={{
33
- __html: value || '<div>&nbsp;</div>'
33
+ __html: value || '<div>&nbsp;</div>',
34
34
  }}
35
35
  />
36
36
  {children}
@@ -40,7 +40,8 @@ const ExplicitConstructedResponse = props => {
40
40
 
41
41
  ExplicitConstructedResponse.propTypes = {
42
42
  attributes: PropTypes.object,
43
- value: PropTypes.string
43
+ error: PropTypes.any,
44
+ value: PropTypes.string,
44
45
  };
45
46
 
46
47
  export default ExplicitConstructedResponse;
@@ -4,20 +4,23 @@ import ChevronRight from '@material-ui/icons/ChevronRight';
4
4
  import MoreVert from '@material-ui/icons/MoreVert';
5
5
  import { withStyles } from '@material-ui/core/styles';
6
6
 
7
- const getRotate = direction => {
7
+ const getRotate = (direction) => {
8
8
  switch (direction) {
9
9
  case 'down':
10
10
  return 90;
11
+
11
12
  case 'up':
12
13
  return -90;
14
+
13
15
  case 'left':
14
16
  return 180;
17
+
15
18
  default:
16
19
  return 0;
17
20
  }
18
21
  };
19
22
 
20
- export const Chevron = props => {
23
+ export const Chevron = (props) => {
21
24
  const { direction, style } = props;
22
25
  const rotate = getRotate(direction);
23
26
 
@@ -25,7 +28,7 @@ export const Chevron = props => {
25
28
  <ChevronRight
26
29
  style={{
27
30
  transform: `rotate(${rotate}deg)`,
28
- ...style
31
+ ...style,
29
32
  }}
30
33
  />
31
34
  );
@@ -33,7 +36,7 @@ export const Chevron = props => {
33
36
 
34
37
  Chevron.propTypes = {
35
38
  direction: PropTypes.string,
36
- style: PropTypes.object
39
+ style: PropTypes.object,
37
40
  };
38
41
 
39
42
  export const GripIcon = ({ style }) => {
@@ -41,7 +44,7 @@ export const GripIcon = ({ style }) => {
41
44
  <span style={style}>
42
45
  <MoreVert
43
46
  style={{
44
- margin: '0 -16px'
47
+ margin: '0 -16px',
45
48
  }}
46
49
  />
47
50
  <MoreVert />
@@ -50,19 +53,19 @@ export const GripIcon = ({ style }) => {
50
53
  };
51
54
 
52
55
  GripIcon.propTypes = {
53
- style: PropTypes.object
56
+ style: PropTypes.object,
54
57
  };
55
58
 
56
- export const ToolbarIcon = withStyles({
59
+ export const ToolbarIcon = withStyles((theme) => ({
57
60
  icon: {
58
61
  fontFamily: 'Cerebri Sans !important',
59
- fontSize: '14px',
62
+ fontSize: theme.typography.fontSize,
60
63
  fontWeight: 'bold',
61
64
  lineHeight: '14px',
62
65
  position: 'relative',
63
66
  top: '7px',
64
67
  width: '110px',
65
68
  height: '28px',
66
- whiteSpace: 'nowrap'
67
- }
68
- })(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
69
+ whiteSpace: 'nowrap',
70
+ },
71
+ }))(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
@@ -18,26 +18,24 @@ const lastIndexMap = {};
18
18
  const elTypesMap = {
19
19
  'inline-dropdown': 'inline_dropdown',
20
20
  'explicit-constructed-response': 'explicit_constructed_response',
21
- 'drag-in-the-blank': 'drag_in_the_blank'
21
+ 'drag-in-the-blank': 'drag_in_the_blank',
22
22
  };
23
23
  const elTypesArray = Object.values(elTypesMap);
24
24
 
25
25
  export default function ResponseAreaPlugin(opts) {
26
- const isOfCurrentType = d => d.type === opts.type || d.type === elTypesMap[opts.type];
26
+ const isOfCurrentType = (d) => d.type === opts.type || d.type === elTypesMap[opts.type];
27
27
 
28
28
  const toolbar = {
29
29
  icon: <ToolbarIcon />,
30
30
  buttonStyles: {
31
- margin: '0 20px 0 auto'
31
+ margin: '0 20px 0 auto',
32
32
  },
33
- onClick: editor => {
33
+ onClick: (editor) => {
34
34
  log('[toolbar] onClick');
35
35
  const currentRespAreaList = [];
36
- const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(
37
- ([d]) => d
38
- );
36
+ const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(([d]) => d);
39
37
 
40
- descendants.forEach(d => {
38
+ descendants.forEach((d) => {
41
39
  if (isOfCurrentType(d)) {
42
40
  currentRespAreaList.push(d);
43
41
  }
@@ -86,35 +84,33 @@ export default function ResponseAreaPlugin(opts) {
86
84
  }
87
85
  },
88
86
  customToolbar: opts.respAreaToolbar,
89
- showDone: false
87
+ showDone: false,
90
88
  };
91
89
 
92
90
  return {
93
91
  name: 'response_area',
94
92
  toolbar,
95
- rules: editor => {
93
+ rules: (editor) => {
96
94
  const { isVoid, isInline, onChange } = editor;
97
95
 
98
- editor.isVoid = element => {
96
+ editor.isVoid = (element) => {
99
97
  return elTypesArray.includes(element.type) ? true : isVoid(element);
100
98
  };
101
99
 
102
- editor.isInline = element => {
100
+ editor.isInline = (element) => {
103
101
  return elTypesArray.includes(element.type) ? true : isInline(element);
104
102
  };
105
103
 
106
104
  let oldEditor = cloneDeep(editor);
107
105
 
108
- editor.onChange = options => {
109
- const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(
110
- ([d]) => d
111
- );
106
+ editor.onChange = (options) => {
107
+ const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(([d]) => d);
112
108
  const type = opts.type.replace(/-/g, '_');
113
109
 
114
110
  if (isUndefined(lastIndexMap[type])) {
115
111
  lastIndexMap[type] = 0;
116
112
 
117
- descendants.forEach(d => {
113
+ descendants.forEach((d) => {
118
114
  if (d.type === type) {
119
115
  const newIndex = parseInt(d.data.index, 10);
120
116
 
@@ -129,29 +125,21 @@ export default function ResponseAreaPlugin(opts) {
129
125
  return;
130
126
  }
131
127
 
132
- const oldDescendants = Array.from(SlateNode.descendants(oldEditor, { reverse: true })).map(
133
- ([d]) => d
134
- );
128
+ const oldDescendants = Array.from(SlateNode.descendants(oldEditor, { reverse: true })).map(([d]) => d);
135
129
  const currentRespAreaList = descendants.filter(isOfCurrentType);
136
130
  const oldRespAreaList = oldDescendants.filter(isOfCurrentType);
137
131
 
138
132
  toolbar.disabled = currentRespAreaList.length >= opts.maxResponseAreas;
139
133
 
140
134
  const arrayToFilter =
141
- oldRespAreaList.length > currentRespAreaList.length
142
- ? oldRespAreaList
143
- : currentRespAreaList;
144
- const arrayToUseForFilter =
145
- arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
135
+ oldRespAreaList.length > currentRespAreaList.length ? oldRespAreaList : currentRespAreaList;
136
+ const arrayToUseForFilter = arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
146
137
 
147
138
  const elementsWithChangedStatus = arrayToFilter.filter(
148
- d => !arrayToUseForFilter.find(e => e.data.index === d.data.index)
139
+ (d) => !arrayToUseForFilter.find((e) => e.data.index === d.data.index),
149
140
  );
150
141
 
151
- if (
152
- elementsWithChangedStatus.length &&
153
- oldRespAreaList.length > currentRespAreaList.length
154
- ) {
142
+ if (elementsWithChangedStatus.length && oldRespAreaList.length > currentRespAreaList.length) {
155
143
  opts.onHandleAreaChange(elementsWithChangedStatus);
156
144
  }
157
145
 
@@ -166,19 +154,19 @@ export default function ResponseAreaPlugin(opts) {
166
154
  return [];
167
155
  }
168
156
 
169
- return plugins.filter(p => p.name !== 'response_area');
157
+ return plugins.filter((p) => p.name !== 'response_area');
170
158
  },
171
159
  deleteNode: (e, node, nodePath, editor, onChange) => {
172
160
  e.preventDefault();
173
161
 
174
162
  editor.apply({
175
163
  type: 'remove_node',
176
- path: nodePath
164
+ path: nodePath,
177
165
  });
178
166
 
179
167
  onChange(editor);
180
168
  },
181
- supports: node => elTypesArray.indexOf(node.type) >= 0,
169
+ supports: (node) => elTypesArray.indexOf(node.type) >= 0,
182
170
  renderNode(props) {
183
171
  const { attributes, node } = props;
184
172
 
@@ -205,13 +193,7 @@ export default function ResponseAreaPlugin(opts) {
205
193
  const { data } = node;
206
194
 
207
195
  return (
208
- <DragInTheBlank
209
- attributes={attributes}
210
- data={data}
211
- n={node}
212
- nodeProps={props}
213
- opts={opts}
214
- >
196
+ <DragInTheBlank attributes={attributes} data={data} n={node} nodeProps={props} opts={opts}>
215
197
  {props.children}
216
198
  </DragInTheBlank>
217
199
  );
@@ -229,12 +211,12 @@ export default function ResponseAreaPlugin(opts) {
229
211
  },
230
212
  onDrop(event, change, editor) {
231
213
  const closestEl = event.target.closest('[data-key]');
232
- const inline = editor.value.document.findDescendant(d => d.key === closestEl.dataset.key);
214
+ const inline = editor.value.document.findDescendant((d) => d.key === closestEl.dataset.key);
233
215
 
234
216
  if (inline.type === 'drag_in_the_blank') {
235
217
  return false;
236
218
  }
237
- }
219
+ },
238
220
  };
239
221
  }
240
222
 
@@ -248,16 +230,16 @@ export const serialization = {
248
230
  type: 'inline_dropdown',
249
231
  data: {
250
232
  index: el.dataset.index,
251
- value: el.dataset.value
252
- }
233
+ value: el.dataset.value,
234
+ },
253
235
  });
254
236
  case 'explicit_constructed_response':
255
237
  return jsx('element', {
256
238
  type: 'explicit_constructed_response',
257
239
  data: {
258
240
  index: el.dataset.index,
259
- value: el.dataset.value
260
- }
241
+ value: el.dataset.value,
242
+ },
261
243
  });
262
244
  case 'drag_in_the_blank':
263
245
  return jsx('element', {
@@ -266,8 +248,8 @@ export const serialization = {
266
248
  index: el.dataset.index,
267
249
  id: el.dataset.id,
268
250
  value: el.dataset.value,
269
- inTable: el.dataset.inTable
270
- }
251
+ inTable: el.dataset.inTable,
252
+ },
271
253
  });
272
254
  }
273
255
  },
@@ -281,13 +263,7 @@ export const serialization = {
281
263
  case 'explicit_constructed_response': {
282
264
  const data = object.data;
283
265
 
284
- return (
285
- <span
286
- data-type="explicit_constructed_response"
287
- data-index={data.index}
288
- data-value={data.value}
289
- />
290
- );
266
+ return <span data-type="explicit_constructed_response" data-index={data.index} data-value={data.value} />;
291
267
  }
292
268
  case 'drag_in_the_blank': {
293
269
  const data = object.data;
@@ -303,5 +279,5 @@ export const serialization = {
303
279
  );
304
280
  }
305
281
  }
306
- }
282
+ },
307
283
  };
@@ -14,7 +14,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
14
14
  display: 'inline-flex',
15
15
  height: '50px',
16
16
  margin: '0 5px',
17
- cursor: 'pointer'
17
+ cursor: 'pointer',
18
18
  }}
19
19
  >
20
20
  <div
@@ -26,7 +26,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
26
26
  border: '1px solid #C0C3CF',
27
27
  boxSizing: 'border-box',
28
28
  borderRadius: '3px',
29
- position: 'relative'
29
+ position: 'relative',
30
30
  }}
31
31
  >
32
32
  {children}
@@ -37,10 +37,10 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
37
37
  padding: '0 25px 0 8px',
38
38
  whiteSpace: 'nowrap',
39
39
  textOverflow: 'ellipsis',
40
- lineHeight: '35px'
40
+ lineHeight: '35px',
41
41
  }}
42
42
  dangerouslySetInnerHTML={{
43
- __html: html
43
+ __html: html,
44
44
  }}
45
45
  />
46
46
  <Chevron
@@ -48,7 +48,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
48
48
  style={{
49
49
  position: 'absolute',
50
50
  top: '5px',
51
- right: '5px'
51
+ right: '5px',
52
52
  }}
53
53
  />
54
54
  </div>
@@ -58,7 +58,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
58
58
 
59
59
  InlineDropdown.propTypes = {
60
60
  attributes: PropTypes.object,
61
- selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
61
+ selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
62
62
  };
63
63
 
64
64
  export default InlineDropdown;
@@ -2,10 +2,12 @@ import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import Snackbar from '@material-ui/core/Snackbar';
4
4
 
5
- export const insertSnackBar = message => {
5
+ export const isNumber = (val) => !isNaN(parseFloat(val)) && isFinite(val);
6
+
7
+ export const insertSnackBar = (message) => {
6
8
  const prevSnacks = document.querySelectorAll('.response-area-alert');
7
9
 
8
- prevSnacks.forEach(s => s.remove());
10
+ prevSnacks.forEach((s) => s.remove());
9
11
 
10
12
  const newEl = document.createElement('div');
11
13
 
@@ -16,7 +18,7 @@ export const insertSnackBar = message => {
16
18
  anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
17
19
  open={true}
18
20
  ContentProps={{
19
- 'aria-describedby': 'message-id'
21
+ 'aria-describedby': 'message-id',
20
22
  }}
21
23
  message={<span id="message-id">{message}</span>}
22
24
  />
@@ -31,12 +33,12 @@ export const insertSnackBar = message => {
31
33
  }, 2000);
32
34
  };
33
35
 
34
- export const defaultECR = index => ({
36
+ export const defaultECR = (index) => ({
35
37
  type: 'explicit_constructed_response',
36
38
  children: [{ text: '' }],
37
39
  data: {
38
- index
39
- }
40
+ index,
41
+ },
40
42
  });
41
43
 
42
44
  export const defaultDIB = (opts, index) => ({
@@ -45,24 +47,26 @@ export const defaultDIB = (opts, index) => ({
45
47
  data: {
46
48
  index,
47
49
  duplicates: opts.options.duplicates,
48
- value: null
49
- }
50
+ value: null,
51
+ },
50
52
  });
51
53
 
52
- export const defaultIDD = index => ({
54
+ export const defaultIDD = (index) => ({
53
55
  type: 'inline_dropdown',
54
56
  children: [{ text: '' }],
55
57
  data: {
56
- index
57
- }
58
+ index,
59
+ },
58
60
  });
59
61
 
60
62
  export const getDefaultElement = (opts, index) => {
61
63
  switch (opts.type) {
62
64
  case 'explicit-constructed-response':
63
65
  return defaultECR(index);
66
+
64
67
  case 'drag-in-the-blank':
65
68
  return defaultDIB(opts, index);
69
+
66
70
  default:
67
71
  // inline-dropdown
68
72
  return defaultIDD(index);