@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
@@ -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.get('index'),
13
- },
12
+ index: n.data.get('index')
13
+ }
14
14
  });
15
15
 
16
16
  nodeProps.editor.props.onChange(change, () => {
@@ -21,12 +21,14 @@ 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((n) => n.data && n.data.get('index') === value.index);
24
+ const dragInTheBlank = val.document.findDescendant(
25
+ n => n.data && n.data.get('index') === value.index
26
+ );
25
27
 
26
28
  change.setNodeByKey(dragInTheBlank.key, {
27
29
  data: {
28
- index: dragInTheBlank.data.get('index'),
29
- },
30
+ index: dragInTheBlank.data.get('index')
31
+ }
30
32
  });
31
33
 
32
34
  nodeProps.editor.props.onChange(change, () => {
@@ -34,8 +36,8 @@ export const onRemoveResponse = (nodeProps, value) => {
34
36
  });
35
37
  };
36
38
 
37
- const DragDrop = (props) => {
38
- const { attributes, data, n, nodeProps, opts } = props;
39
+ const DragDrop = props => {
40
+ const { attributes, children, data, n, nodeProps, opts } = props;
39
41
  const { inTable } = data;
40
42
 
41
43
  return (
@@ -47,7 +49,7 @@ const DragDrop = (props) => {
47
49
  minWidth: '178px',
48
50
  position: 'relative',
49
51
  margin: inTable ? '10px' : '0 10px',
50
- cursor: 'pointer',
52
+ cursor: 'pointer'
51
53
  }}
52
54
  >
53
55
  <DragDropTile
@@ -56,10 +58,11 @@ const DragDrop = (props) => {
56
58
  targetId="0"
57
59
  value={data}
58
60
  duplicates={opts.options.duplicates}
59
- onChange={(value) => onValueChange(nodeProps, n, value)}
60
- removeResponse={(value) => onRemoveResponse(nodeProps, value)}
61
+ onChange={value => onValueChange(nodeProps, n, value)}
62
+ removeResponse={value => onRemoveResponse(nodeProps, value)}
61
63
  >
62
64
  {nodeProps.children}
65
+ {children}
63
66
  </DragDropTile>
64
67
  </span>
65
68
  );
@@ -70,7 +73,7 @@ DragDrop.propTypes = {
70
73
  data: PropTypes.object,
71
74
  n: PropTypes.object,
72
75
  nodeProps: PropTypes.object,
73
- opts: PropTypes.object,
76
+ opts: PropTypes.object
74
77
  };
75
78
 
76
79
  export default DragDrop;
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- const ExplicitConstructedResponse = (props) => {
5
- const { attributes, value, error } = props;
4
+ const ExplicitConstructedResponse = props => {
5
+ const { attributes, children, value, error } = props;
6
6
 
7
7
  return (
8
8
  <span
@@ -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,19 +27,20 @@ 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
+ {children}
36
37
  </span>
37
38
  );
38
39
  };
39
40
 
40
41
  ExplicitConstructedResponse.propTypes = {
41
42
  attributes: PropTypes.object,
42
- value: PropTypes.string,
43
+ value: PropTypes.string
43
44
  };
44
45
 
45
46
  export default ExplicitConstructedResponse;
@@ -4,23 +4,20 @@ 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
-
12
11
  case 'up':
13
12
  return -90;
14
-
15
13
  case 'left':
16
14
  return 180;
17
-
18
15
  default:
19
16
  return 0;
20
17
  }
21
18
  };
22
19
 
23
- export const Chevron = (props) => {
20
+ export const Chevron = props => {
24
21
  const { direction, style } = props;
25
22
  const rotate = getRotate(direction);
26
23
 
@@ -28,7 +25,7 @@ export const Chevron = (props) => {
28
25
  <ChevronRight
29
26
  style={{
30
27
  transform: `rotate(${rotate}deg)`,
31
- ...style,
28
+ ...style
32
29
  }}
33
30
  />
34
31
  );
@@ -36,7 +33,7 @@ export const Chevron = (props) => {
36
33
 
37
34
  Chevron.propTypes = {
38
35
  direction: PropTypes.string,
39
- style: PropTypes.object,
36
+ style: PropTypes.object
40
37
  };
41
38
 
42
39
  export const GripIcon = ({ style }) => {
@@ -44,7 +41,7 @@ export const GripIcon = ({ style }) => {
44
41
  <span style={style}>
45
42
  <MoreVert
46
43
  style={{
47
- margin: '0 -16px',
44
+ margin: '0 -16px'
48
45
  }}
49
46
  />
50
47
  <MoreVert />
@@ -53,19 +50,19 @@ export const GripIcon = ({ style }) => {
53
50
  };
54
51
 
55
52
  GripIcon.propTypes = {
56
- style: PropTypes.object,
53
+ style: PropTypes.object
57
54
  };
58
55
 
59
- export const ToolbarIcon = withStyles((theme) => ({
56
+ export const ToolbarIcon = withStyles({
60
57
  icon: {
61
58
  fontFamily: 'Cerebri Sans !important',
62
- fontSize: theme.typography.fontSize,
59
+ fontSize: '14px',
63
60
  fontWeight: 'bold',
64
61
  lineHeight: '14px',
65
62
  position: 'relative',
66
63
  top: '7px',
67
64
  width: '110px',
68
65
  height: '28px',
69
- whiteSpace: 'nowrap',
70
- },
71
- }))(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
66
+ whiteSpace: 'nowrap'
67
+ }
68
+ })(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
+ import { Node as SlateNode } from 'slate';
3
+ import { jsx } from 'slate-hyperscript';
2
4
  import debug from 'debug';
3
- import isUndefined from 'lodash/isUndefined';
4
5
 
6
+ import isUndefined from 'lodash/isUndefined';
5
7
  import InlineDropdown from './inline-dropdown';
6
8
  import DragInTheBlank from './drag-in-the-blank';
7
9
  import ExplicitConstructedResponse from './explicit-constructed-response';
@@ -14,36 +16,44 @@ const lastIndexMap = {};
14
16
  const elTypesMap = {
15
17
  'inline-dropdown': 'inline_dropdown',
16
18
  'explicit-constructed-response': 'explicit_constructed_response',
17
- 'drag-in-the-blank': 'drag_in_the_blank',
19
+ 'drag-in-the-blank': 'drag_in_the_blank'
18
20
  };
19
21
  const elTypesArray = Object.values(elTypesMap);
20
22
 
21
23
  export default function ResponseAreaPlugin(opts) {
22
- const isOfCurrentType = (d) => d.type === opts.type || d.type === elTypesMap[opts.type];
24
+ const isOfCurrentType = d => d.type === opts.type || d.type === elTypesMap[opts.type];
23
25
 
24
26
  const toolbar = {
25
27
  icon: <ToolbarIcon />,
26
28
  buttonStyles: {
27
- margin: '0 20px 0 auto',
29
+ margin: '0 20px 0 auto'
28
30
  },
29
- onClick: (value, onChange) => {
31
+ onClick: editor => {
30
32
  log('[toolbar] onClick');
31
- const change = value.change();
32
- const currentRespAreaList = change.value.document.filterDescendants(isOfCurrentType);
33
+ const currentRespAreaList = [];
34
+ const descendants = SlateNode.descendants(editor, {
35
+ reverse: true
36
+ });
37
+
38
+ for (const [descendant, descendantPath] of descendants) {
39
+ if (isOfCurrentType(descendant, descendantPath)) {
40
+ currentRespAreaList.push(descendant);
41
+ }
42
+ }
33
43
 
34
- if (currentRespAreaList.size >= opts.maxResponseAreas) {
44
+ if (currentRespAreaList.length >= opts.maxResponseAreas) {
35
45
  return;
36
46
  }
37
47
 
38
48
  const type = opts.type.replace(/-/g, '_');
39
49
  const prevIndex = lastIndexMap[type];
40
- const newIndex = prevIndex === 0 ? prevIndex : prevIndex + 1;
50
+ const newIndex = !prevIndex ? 0 : prevIndex + 1;
41
51
  const newInline = getDefaultElement(opts, newIndex);
42
52
 
43
53
  lastIndexMap[type] += 1;
44
54
 
45
55
  if (newInline) {
46
- if (change.value.selection.startKey || change.value.selection.endKey) {
56
+ /* if (change.value.selection.startKey || change.value.selection.endKey) {
47
57
  change.insertInline(newInline);
48
58
  } else {
49
59
  // If the markup is empty and there's no focus
@@ -69,25 +79,36 @@ export default function ResponseAreaPlugin(opts) {
69
79
  if (nextText) {
70
80
  change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);
71
81
  }
72
- }
73
-
74
- onChange(change);
82
+ }*/
83
+ editor.insertNode(newInline);
75
84
  }
76
85
  },
77
86
  customToolbar: opts.respAreaToolbar,
78
- supports: (node) => node.object === 'inline' && elTypesArray.indexOf(node.type) >= 0,
79
- showDone: false,
87
+ showDone: false
80
88
  };
81
89
 
82
90
  return {
83
91
  name: 'response_area',
84
92
  toolbar,
93
+ rules: editor => {
94
+ const { isVoid, isInline } = editor;
95
+
96
+ editor.isVoid = element => {
97
+ return elTypesArray.includes(element.type) ? true : isVoid(element);
98
+ };
99
+
100
+ editor.isInline = element => {
101
+ return elTypesArray.includes(element.type) ? true : isInline(element);
102
+ };
103
+
104
+ return editor;
105
+ },
85
106
  filterPlugins: (node, plugins) => {
86
107
  if (node.type === 'explicit_constructed_response' || node.type === 'drag_in_the_blank') {
87
108
  return [];
88
109
  }
89
110
 
90
- return plugins.filter((p) => p.name !== 'response_area');
111
+ return plugins.filter(p => p.name !== 'response_area');
91
112
  },
92
113
  deleteNode: (e, node, value, onChange) => {
93
114
  e.preventDefault();
@@ -96,11 +117,12 @@ export default function ResponseAreaPlugin(opts) {
96
117
 
97
118
  onChange(change);
98
119
  },
120
+ supports: node => elTypesArray.indexOf(node.type) >= 0,
99
121
  renderNode(props) {
100
- const { attributes, node: n } = props;
122
+ const { attributes, node } = props;
101
123
 
102
- if (n.type === 'explicit_constructed_response') {
103
- const data = n.data.toJSON();
124
+ if (node.type === 'explicit_constructed_response') {
125
+ const { data } = node;
104
126
  let error;
105
127
 
106
128
  if (opts.error) {
@@ -112,20 +134,36 @@ export default function ResponseAreaPlugin(opts) {
112
134
  attributes={attributes}
113
135
  value={data.value}
114
136
  error={error && error[data.index] && error[data.index][0]}
115
- />
137
+ >
138
+ {props.children}
139
+ </ExplicitConstructedResponse>
116
140
  );
117
141
  }
118
142
 
119
- if (n.type === 'drag_in_the_blank') {
120
- const data = n.data.toJSON();
143
+ if (node.type === 'drag_in_the_blank') {
144
+ const { data } = node;
121
145
 
122
- return <DragInTheBlank attributes={attributes} data={data} n={n} nodeProps={props} opts={opts} />;
146
+ return (
147
+ <DragInTheBlank
148
+ attributes={attributes}
149
+ data={data}
150
+ n={node}
151
+ nodeProps={props}
152
+ opts={opts}
153
+ >
154
+ {props.children}
155
+ </DragInTheBlank>
156
+ );
123
157
  }
124
158
 
125
- if (n.type === 'inline_dropdown') {
126
- const data = n.data.toJSON();
159
+ if (node.type === 'inline_dropdown') {
160
+ const { data } = node;
127
161
 
128
- return <InlineDropdown attributes={attributes} selectedItem={data.value} />;
162
+ return (
163
+ <InlineDropdown attributes={attributes} selectedItem={data.value}>
164
+ {props.children}
165
+ </InlineDropdown>
166
+ );
129
167
  }
130
168
  },
131
169
  onChange(change, editor) {
@@ -134,7 +172,7 @@ export default function ResponseAreaPlugin(opts) {
134
172
  if (isUndefined(lastIndexMap[type])) {
135
173
  lastIndexMap[type] = 0;
136
174
 
137
- change.value.document.forEachDescendant((d) => {
175
+ change.value.document.forEachDescendant(d => {
138
176
  if (d.type === type) {
139
177
  const newIndex = parseInt(d.data.get('index'), 10);
140
178
 
@@ -158,11 +196,13 @@ export default function ResponseAreaPlugin(opts) {
158
196
  toolbar.disabled = false;
159
197
  }
160
198
 
161
- const arrayToFilter = oldRespAreaList.size > currentRespAreaList.size ? oldRespAreaList : currentRespAreaList;
162
- const arrayToUseForFilter = arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
199
+ const arrayToFilter =
200
+ oldRespAreaList.size > currentRespAreaList.size ? oldRespAreaList : currentRespAreaList;
201
+ const arrayToUseForFilter =
202
+ arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
163
203
 
164
204
  const elementsWithChangedStatus = arrayToFilter.filter(
165
- (d) => !arrayToUseForFilter.find((e) => e.data.get('index') === d.data.get('index')),
205
+ d => !arrayToUseForFilter.find(e => e.data.get('index') === d.data.get('index'))
166
206
  );
167
207
 
168
208
  if (elementsWithChangedStatus.size && oldRespAreaList.size > currentRespAreaList.size) {
@@ -171,12 +211,12 @@ export default function ResponseAreaPlugin(opts) {
171
211
  },
172
212
  onDrop(event, change, editor) {
173
213
  const closestEl = event.target.closest('[data-key]');
174
- 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);
175
215
 
176
216
  if (inline.type === 'drag_in_the_blank') {
177
217
  return false;
178
218
  }
179
- },
219
+ }
180
220
  };
181
221
  }
182
222
 
@@ -186,37 +226,31 @@ export const serialization = {
186
226
 
187
227
  switch (type) {
188
228
  case 'inline_dropdown':
189
- return {
190
- object: 'inline',
229
+ return jsx('element', {
191
230
  type: 'inline_dropdown',
192
- isVoid: true,
193
231
  data: {
194
232
  index: el.dataset.index,
195
- value: el.dataset.value,
196
- },
197
- };
233
+ value: el.dataset.value
234
+ }
235
+ });
198
236
  case 'explicit_constructed_response':
199
- return {
200
- object: 'inline',
237
+ return jsx('element', {
201
238
  type: 'explicit_constructed_response',
202
- isVoid: true,
203
239
  data: {
204
240
  index: el.dataset.index,
205
- value: el.dataset.value,
206
- },
207
- };
241
+ value: el.dataset.value
242
+ }
243
+ });
208
244
  case 'drag_in_the_blank':
209
- return {
210
- object: 'inline',
245
+ return jsx('element', {
211
246
  type: 'drag_in_the_blank',
212
- isVoid: true,
213
247
  data: {
214
248
  index: el.dataset.index,
215
249
  id: el.dataset.id,
216
250
  value: el.dataset.value,
217
- inTable: el.dataset.inTable,
218
- },
219
- };
251
+ inTable: el.dataset.inTable
252
+ }
253
+ });
220
254
  }
221
255
  },
222
256
  serialize(object) {
@@ -233,7 +267,13 @@ export const serialization = {
233
267
  case 'explicit_constructed_response': {
234
268
  const data = object.data.toJSON();
235
269
 
236
- return <span data-type="explicit_constructed_response" data-index={data.index} data-value={data.value} />;
270
+ return (
271
+ <span
272
+ data-type="explicit_constructed_response"
273
+ data-index={data.index}
274
+ data-value={data.value}
275
+ />
276
+ );
237
277
  }
238
278
  case 'drag_in_the_blank': {
239
279
  const data = object.data.toJSON();
@@ -249,5 +289,5 @@ export const serialization = {
249
289
  );
250
290
  }
251
291
  }
252
- },
292
+ }
253
293
  };
@@ -2,19 +2,19 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Chevron } from '../icons';
4
4
 
5
- const InlineDropdown = ({ attributes, selectedItem }) => {
6
- // TODO: Investigate
5
+ const InlineDropdown = ({ attributes, children, selectedItem }) => {
7
6
  // Needed because items with values inside have different positioning for some reason
8
7
  const html = selectedItem || '<div>&nbsp</div>';
9
8
 
10
9
  return (
11
10
  <span
12
11
  {...attributes}
12
+ contentEditable={false}
13
13
  style={{
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,9 +26,10 @@ const InlineDropdown = ({ attributes, 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
+ {children}
32
33
  <div
33
34
  style={{
34
35
  flex: 1,
@@ -36,10 +37,10 @@ const InlineDropdown = ({ attributes, selectedItem }) => {
36
37
  padding: '0 25px 0 8px',
37
38
  whiteSpace: 'nowrap',
38
39
  textOverflow: 'ellipsis',
39
- lineHeight: '35px',
40
+ lineHeight: '35px'
40
41
  }}
41
42
  dangerouslySetInnerHTML={{
42
- __html: html,
43
+ __html: html
43
44
  }}
44
45
  />
45
46
  <Chevron
@@ -47,7 +48,7 @@ const InlineDropdown = ({ attributes, selectedItem }) => {
47
48
  style={{
48
49
  position: 'absolute',
49
50
  top: '5px',
50
- right: '5px',
51
+ right: '5px'
51
52
  }}
52
53
  />
53
54
  </div>
@@ -57,7 +58,7 @@ const InlineDropdown = ({ attributes, selectedItem }) => {
57
58
 
58
59
  InlineDropdown.propTypes = {
59
60
  attributes: PropTypes.object,
60
- selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
61
+ selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
61
62
  };
62
63
 
63
64
  export default InlineDropdown;
@@ -1,14 +1,11 @@
1
1
  import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
- import { Inline } from 'slate';
4
3
  import Snackbar from '@material-ui/core/Snackbar';
5
4
 
6
- export const isNumber = (val) => !isNaN(parseFloat(val)) && isFinite(val);
7
-
8
- export const insertSnackBar = (message) => {
5
+ export const insertSnackBar = message => {
9
6
  const prevSnacks = document.querySelectorAll('.response-area-alert');
10
7
 
11
- prevSnacks.forEach((s) => s.remove());
8
+ prevSnacks.forEach(s => s.remove());
12
9
 
13
10
  const newEl = document.createElement('div');
14
11
 
@@ -19,7 +16,7 @@ export const insertSnackBar = (message) => {
19
16
  anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
20
17
  open={true}
21
18
  ContentProps={{
22
- 'aria-describedby': 'message-id',
19
+ 'aria-describedby': 'message-id'
23
20
  }}
24
21
  message={<span id="message-id">{message}</span>}
25
22
  />
@@ -34,44 +31,38 @@ export const insertSnackBar = (message) => {
34
31
  }, 2000);
35
32
  };
36
33
 
37
- export const defaultECR = (index) =>
38
- Inline.create({
39
- type: 'explicit_constructed_response',
40
- isVoid: true,
41
- data: {
42
- index,
43
- },
44
- });
34
+ export const defaultECR = index => ({
35
+ type: 'explicit_constructed_response',
36
+ children: [{ text: '' }],
37
+ data: {
38
+ index
39
+ }
40
+ });
45
41
 
46
- export const defaultDIB = (opts, index) =>
47
- Inline.create({
48
- type: 'drag_in_the_blank',
49
- isVoid: true,
50
- data: {
51
- index,
52
- duplicates: opts.options.duplicates,
53
- value: null,
54
- },
55
- });
42
+ export const defaultDIB = (opts, index) => ({
43
+ type: 'drag_in_the_blank',
44
+ children: [{ text: '' }],
45
+ data: {
46
+ index,
47
+ duplicates: opts.options.duplicates,
48
+ value: null
49
+ }
50
+ });
56
51
 
57
- export const defaultIDD = (index) =>
58
- Inline.create({
59
- object: 'inline',
60
- type: 'inline_dropdown',
61
- isVoid: true,
62
- data: {
63
- index,
64
- },
65
- });
52
+ export const defaultIDD = index => ({
53
+ type: 'inline_dropdown',
54
+ children: [{ text: '' }],
55
+ data: {
56
+ index
57
+ }
58
+ });
66
59
 
67
60
  export const getDefaultElement = (opts, index) => {
68
61
  switch (opts.type) {
69
62
  case 'explicit-constructed-response':
70
63
  return defaultECR(index);
71
-
72
64
  case 'drag-in-the-blank':
73
65
  return defaultDIB(opts, index);
74
-
75
66
  default:
76
67
  // inline-dropdown
77
68
  return defaultIDD(index);