@pie-lib/mask-markup 2.0.0-beta.1 → 2.0.0-beta.2

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 (52) hide show
  1. package/CHANGELOG.md +143 -35
  2. package/lib/choices/choice.js +22 -31
  3. package/lib/choices/choice.js.map +1 -1
  4. package/lib/choices/index.js +9 -33
  5. package/lib/choices/index.js.map +1 -1
  6. package/lib/componentize.js +1 -4
  7. package/lib/componentize.js.map +1 -1
  8. package/lib/components/blank.js +61 -86
  9. package/lib/components/blank.js.map +1 -1
  10. package/lib/components/correct-input.js +9 -25
  11. package/lib/components/correct-input.js.map +1 -1
  12. package/lib/components/dropdown.js +11 -37
  13. package/lib/components/dropdown.js.map +1 -1
  14. package/lib/components/input.js +14 -17
  15. package/lib/components/input.js.map +1 -1
  16. package/lib/constructed-response.js +11 -14
  17. package/lib/constructed-response.js.map +1 -1
  18. package/lib/drag-in-the-blank.js +21 -50
  19. package/lib/drag-in-the-blank.js.map +1 -1
  20. package/lib/index.js +1 -7
  21. package/lib/index.js.map +1 -1
  22. package/lib/inline-dropdown.js +6 -11
  23. package/lib/inline-dropdown.js.map +1 -1
  24. package/lib/mask.js +8 -49
  25. package/lib/mask.js.map +1 -1
  26. package/lib/new-serialization.js +6 -59
  27. package/lib/new-serialization.js.map +1 -0
  28. package/lib/parse-html.js +7 -6
  29. package/lib/parse-html.js.map +1 -0
  30. package/lib/serialization.js +9 -42
  31. package/lib/serialization.js.map +1 -1
  32. package/lib/test-serializer.js +4 -55
  33. package/lib/test-serializer.js.map +1 -0
  34. package/lib/with-mask.js +6 -30
  35. package/lib/with-mask.js.map +1 -1
  36. package/package.json +7 -7
  37. package/src/choices/choice.jsx +27 -13
  38. package/src/choices/index.jsx +17 -13
  39. package/src/components/blank.jsx +43 -31
  40. package/src/components/correct-input.jsx +18 -18
  41. package/src/components/dropdown.jsx +27 -38
  42. package/src/components/input.jsx +6 -3
  43. package/src/constructed-response.jsx +5 -4
  44. package/src/drag-in-the-blank.jsx +12 -12
  45. package/src/index.js +1 -8
  46. package/src/inline-dropdown.jsx +4 -3
  47. package/src/mask.jsx +13 -14
  48. package/src/new-serialization.jsx +19 -19
  49. package/src/parse-html.js +1 -1
  50. package/src/serialization.js +19 -14
  51. package/src/test-serializer.js +9 -9
  52. package/src/with-mask.jsx +2 -9
package/src/mask.jsx CHANGED
@@ -1,16 +1,15 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import get from 'lodash/get';
4
3
  import { Text } from 'slate';
5
4
  import { withStyles } from '@material-ui/core/styles';
6
5
  import { MARK_TAGS } from './serialization';
7
6
 
8
- const Paragraph = withStyles(theme => ({
7
+ const Paragraph = withStyles((theme) => ({
9
8
  para: {
10
9
  paddingTop: 2 * theme.spacing.unit,
11
- paddingBottom: 2 * theme.spacing.unit
12
- }
13
- }))(props => <div className={props.classes.para}>{props.children}</div>);
10
+ paddingBottom: 2 * theme.spacing.unit,
11
+ },
12
+ }))((props) => <div className={props.classes.para}>{props.children}</div>);
14
13
 
15
14
  const restrictWhitespaceTypes = ['tbody', 'tr'];
16
15
 
@@ -25,7 +24,7 @@ const addText = (parentNode, text) => {
25
24
  }
26
25
  };
27
26
 
28
- const getMark = n => {
27
+ const getMark = (n) => {
29
28
  const markTags = Object.values(MARK_TAGS);
30
29
 
31
30
  return markTags.includes(n.type);
@@ -43,7 +42,7 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
43
42
 
44
43
  if (n.isMath) {
45
44
  children.push(
46
- <span dangerouslySetInnerHTML={{ __html: `<math displaystyle="true">${n.children[0].innerHTML}</math>` }} />
45
+ <span dangerouslySetInnerHTML={{ __html: `<math displaystyle="true">${n.children[0].innerHTML}</math>` }} />,
47
46
  );
48
47
  return children;
49
48
  }
@@ -67,7 +66,7 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
67
66
  if (MARK_TAGS[markKey] === mark.type) {
68
67
  const Tag = markKey;
69
68
 
70
- children.push(<Tag>{content}</Tag>);
69
+ children.push(<Tag key={key}>{content}</Tag>);
71
70
  break;
72
71
  }
73
72
  }
@@ -80,11 +79,11 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
80
79
  children.push(<Paragraph key={key}>{subNodes}</Paragraph>);
81
80
  } else {
82
81
  const Tag = n.type;
83
- if (n.children && n.children.length > 0) {
82
+ if (Tag !== 'source' && n.children && n.children.length > 0) {
84
83
  children.push(
85
84
  <Tag key={key} {...n.data.attributes}>
86
85
  {subNodes}
87
- </Tag>
86
+ </Tag>,
88
87
  );
89
88
  } else {
90
89
  children.push(<Tag key={key} {...n.data.attributes} />);
@@ -97,9 +96,9 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
97
96
 
98
97
  const MaskContainer = withStyles(() => ({
99
98
  main: {
100
- display: 'initial'
101
- }
102
- }))(props => <div className={props.classes.main}>{props.children}</div>);
99
+ display: 'initial',
100
+ },
101
+ }))((props) => <div className={props.classes.main}>{props.children}</div>);
103
102
 
104
103
  /**
105
104
  * Renders a layout that uses the slate.js Value model structure.
@@ -109,7 +108,7 @@ export default class Mask extends React.Component {
109
108
  renderChildren: PropTypes.func,
110
109
  layout: PropTypes.object,
111
110
  value: PropTypes.object,
112
- onChange: PropTypes.func
111
+ onChange: PropTypes.func,
113
112
  };
114
113
 
115
114
  handleChange = (id, value) => {
@@ -31,7 +31,7 @@ export const BLOCK_TAGS = {
31
31
  h3: 'heading-three',
32
32
  h4: 'heading-four',
33
33
  h5: 'heading-five',
34
- h6: 'heading-six'
34
+ h6: 'heading-six',
35
35
  };
36
36
 
37
37
  /**
@@ -46,10 +46,10 @@ const MARK_TAGS = {
46
46
  u: 'underline',
47
47
  s: 'strikethrough',
48
48
  code: 'code',
49
- strong: 'bold'
49
+ strong: 'bold',
50
50
  };
51
51
 
52
- export const parseStyleString = s => {
52
+ export const parseStyleString = (s) => {
53
53
  const regex = /([\w-]*)\s*:\s*([^;]*)/g;
54
54
  let match;
55
55
  const result = {};
@@ -59,18 +59,18 @@ export const parseStyleString = s => {
59
59
  return result;
60
60
  };
61
61
 
62
- export const getBase64 = file => {
62
+ export const getBase64 = (file) => {
63
63
  return new Promise((resolve, reject) => {
64
64
  const reader = new FileReader();
65
65
  reader.readAsDataURL(file);
66
66
  reader.onload = () => resolve(reader.result);
67
- reader.onerror = error => reject(error);
67
+ reader.onerror = (error) => reject(error);
68
68
  });
69
69
  };
70
70
 
71
- export const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });
71
+ export const reactAttributes = (o) => toStyleObject(o, { camelize: true, addUnits: false });
72
72
 
73
- const attributesToMap = el => (acc, attribute) => {
73
+ const attributesToMap = (el) => (acc, attribute) => {
74
74
  const value = el.getAttribute(attribute);
75
75
  if (value) {
76
76
  if (attribute === 'style') {
@@ -114,9 +114,9 @@ const blocks = {
114
114
  /**
115
115
  * Here for rendering styles for all block elements
116
116
  */
117
- data: { attributes: attributes.reduce(attributesToMap(el), {}) }
117
+ data: { attributes: attributes.reduce(attributesToMap(el), {}) },
118
118
  },
119
- next(el.childNodes)
119
+ next(el.childNodes),
120
120
  );
121
121
  },
122
122
  serialize: (object, children) => {
@@ -134,7 +134,7 @@ const blocks = {
134
134
  return <Tag {...jsonData.attributes}>{children}</Tag>;
135
135
  }
136
136
  }
137
- }
137
+ },
138
138
  };
139
139
 
140
140
  const marks = {
@@ -156,10 +156,10 @@ const marks = {
156
156
  }
157
157
  }
158
158
  }*/
159
- }
159
+ },
160
160
  };
161
161
 
162
- const findPreviousText = el => {
162
+ const findPreviousText = (el) => {
163
163
  if (el.nodeName === '#text') {
164
164
  return el;
165
165
  }
@@ -198,7 +198,7 @@ export const TEXT_RULE = {
198
198
  return array;
199
199
  }, []);
200
200
  }
201
- }
201
+ },
202
202
  };
203
203
 
204
204
  const RULES = [
@@ -210,7 +210,7 @@ const RULES = [
210
210
  responseAreaSerialization,
211
211
  TEXT_RULE,
212
212
  blocks,
213
- marks
213
+ marks,
214
214
  ];
215
215
 
216
216
  function allWhitespace(node) {
@@ -221,7 +221,7 @@ function allWhitespace(node) {
221
221
  function defaultParseHtml(html) {
222
222
  if (typeof DOMParser === 'undefined') {
223
223
  throw new Error(
224
- 'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.'
224
+ 'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.',
225
225
  );
226
226
  }
227
227
 
@@ -245,14 +245,14 @@ function defaultParseHtml(html) {
245
245
  const parseHtml =
246
246
  typeof window === 'undefined'
247
247
  ? () => ({
248
- childNodes: []
248
+ childNodes: [],
249
249
  })
250
250
  : defaultParseHtml;
251
251
 
252
252
  const serializer = new TestSerializer({
253
253
  defaultBlock: 'div',
254
254
  rules: RULES,
255
- parseHtml
255
+ parseHtml,
256
256
  });
257
257
 
258
258
  const _extends =
@@ -271,7 +271,7 @@ const _extends =
271
271
  return target;
272
272
  };
273
273
 
274
- export const htmlToValue = html => {
274
+ export const htmlToValue = (html) => {
275
275
  try {
276
276
  return serializer.deserialize(html);
277
277
  } catch (e) {
@@ -280,7 +280,7 @@ export const htmlToValue = html => {
280
280
  }
281
281
  };
282
282
 
283
- export const valueToHtml = value => serializer.serialize(value);
283
+ export const valueToHtml = (value) => serializer.serialize(value);
284
284
 
285
285
  /**
286
286
  *
package/src/parse-html.js CHANGED
@@ -1,4 +1,4 @@
1
- export const parseDegrees = html =>
1
+ export const parseDegrees = (html) =>
2
2
  html
3
3
  // removes \( use case: 50°
4
4
  .replace(/\\[(]/g, '')
@@ -12,7 +12,7 @@ const MARK = ['em', 'strong', 'u'];
12
12
  const TEXT_NODE = 3;
13
13
  const COMMENT_NODE = 8;
14
14
 
15
- const attr = el => {
15
+ const attr = (el) => {
16
16
  if (!el.attributes || el.attributes.length <= 0) {
17
17
  return undefined;
18
18
  }
@@ -29,7 +29,7 @@ const attr = el => {
29
29
  return out;
30
30
  };
31
31
 
32
- const getObject = type => {
32
+ const getObject = (type) => {
33
33
  if (INLINE.includes(type)) {
34
34
  return 'inline';
35
35
  } else if (MARK.includes(type)) {
@@ -38,7 +38,7 @@ const getObject = type => {
38
38
  return 'block';
39
39
  };
40
40
 
41
- export const parseStyleString = s => {
41
+ export const parseStyleString = (s) => {
42
42
  const regex = /([\w-]*)\s*:\s*([^;]*)/g;
43
43
  let match;
44
44
  const result = {};
@@ -48,7 +48,7 @@ export const parseStyleString = s => {
48
48
  return result;
49
49
  };
50
50
 
51
- export const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });
51
+ export const reactAttributes = (o) => toStyleObject(o, { camelize: true, addUnits: false });
52
52
 
53
53
  const handleStyles = (el, attribute) => {
54
54
  const styleString = el.getAttribute(attribute);
@@ -64,7 +64,7 @@ const handleClass = (el, acc, attribute) => {
64
64
  return classNames;
65
65
  };
66
66
 
67
- const attributesToMap = el => (acc, attribute) => {
67
+ const attributesToMap = (el) => (acc, attribute) => {
68
68
  if (!el.getAttribute) {
69
69
  return acc;
70
70
  }
@@ -102,7 +102,7 @@ export const MARK_TAGS = {
102
102
  u: 'underline',
103
103
  s: 'strikethrough',
104
104
  code: 'code',
105
- strong: 'strong'
105
+ strong: 'strong',
106
106
  };
107
107
 
108
108
  const marks = {
@@ -115,7 +115,7 @@ const marks = {
115
115
 
116
116
  log('[deserialize] mark: ', mark);
117
117
  return jsx('text', { type: mark }, next(el.childNodes));
118
- }
118
+ },
119
119
  };
120
120
 
121
121
  const rules = [
@@ -136,14 +136,19 @@ const rules = [
136
136
  const type = el.tagName.toLowerCase();
137
137
 
138
138
  const normalAttrs = attr(el) || {};
139
+
140
+ if (type == 'audio' && normalAttrs.controls == '') {
141
+ normalAttrs.controls = true;
142
+ }
143
+
139
144
  const allAttrs = attributes.reduce(attributesToMap(el), { ...normalAttrs });
140
145
 
141
146
  if (el.tagName.toLowerCase() === 'math') {
142
147
  return jsx('element', {
143
148
  type: 'mathml',
144
149
  data: {
145
- html: el.innerHTML
146
- }
150
+ html: el.innerHTML,
151
+ },
147
152
  });
148
153
 
149
154
  // return {
@@ -160,12 +165,12 @@ const rules = [
160
165
  'element',
161
166
  {
162
167
  type,
163
- data: { dataset: { ...el.dataset }, attributes: { ...allAttrs } }
168
+ data: { dataset: { ...el.dataset }, attributes: { ...allAttrs } },
164
169
  },
165
- next(el.childNodes)
170
+ next(el.childNodes),
166
171
  );
167
- }
168
- }
172
+ },
173
+ },
169
174
  ];
170
175
 
171
176
  /**
@@ -174,4 +179,4 @@ const rules = [
174
179
  */
175
180
  const html = new Html({ rules, defaultBlock: 'span' });
176
181
 
177
- export const deserialize = s => html.deserialize(s, { toJSON: true });
182
+ export const deserialize = (s) => html.deserialize(s, { toJSON: true });
@@ -12,7 +12,7 @@ function allWhitespace(node) {
12
12
  function defaultParseHtml(html) {
13
13
  if (typeof DOMParser === 'undefined') {
14
14
  throw new Error(
15
- 'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.'
15
+ 'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.',
16
16
  );
17
17
  }
18
18
 
@@ -39,7 +39,7 @@ class Html {
39
39
  this.rules = props.rules;
40
40
  }
41
41
 
42
- serializeEls = node => {
42
+ serializeEls = (node) => {
43
43
  if (Text.isText(node)) {
44
44
  let string = escapeHtml(node.text);
45
45
  if (node.bold) {
@@ -48,7 +48,7 @@ class Html {
48
48
  return string;
49
49
  }
50
50
 
51
- let children = (node.children || []).map(n => this.serializeEls(n));
51
+ let children = (node.children || []).map((n) => this.serializeEls(n));
52
52
 
53
53
  const correctRule = this.rules.reduce((res, rule) => {
54
54
  return res || rule.serialize(node, children);
@@ -74,18 +74,18 @@ class Html {
74
74
  }
75
75
  };
76
76
 
77
- serialize = node => {
77
+ serialize = (node) => {
78
78
  const deserialized = this.serializeEls(node);
79
79
  const html = ReactServer.renderToStaticMarkup(React.createElement('body', null, deserialized));
80
80
  const inner = html.slice(6, -7);
81
81
  return inner;
82
82
  };
83
83
 
84
- deserialize = html => {
84
+ deserialize = (html) => {
85
85
  let body = this.parseHtml(html);
86
86
 
87
87
  if (body.firstChild && body.firstChild.nodeType === Node.TEXT_NODE) {
88
- body = this.parseHtml(`<p>${html}</p>`);
88
+ body = this.parseHtml(`<span>${html}</span>`);
89
89
  }
90
90
 
91
91
  return this.deserializeEls(body);
@@ -105,10 +105,10 @@ class Html {
105
105
  nodeAttributes.bold = true;
106
106
  }
107
107
 
108
- const nextFn = nodes => {
108
+ const nextFn = (nodes) => {
109
109
  const childNodes = Array.from(nodes);
110
110
  const children = Array.from(childNodes)
111
- .map(node => this.deserializeEls(node, nodeAttributes))
111
+ .map((node) => this.deserializeEls(node, nodeAttributes))
112
112
  .flat();
113
113
 
114
114
  if (children.length === 0) {
@@ -128,7 +128,7 @@ class Html {
128
128
 
129
129
  const childNodes = Array.from(element.childNodes);
130
130
  const children = Array.from(childNodes)
131
- .map(node => this.deserializeEls(node, nodeAttributes))
131
+ .map((node) => this.deserializeEls(node, nodeAttributes))
132
132
  .flat();
133
133
 
134
134
  if (children.length === 0) {
package/src/with-mask.jsx CHANGED
@@ -22,21 +22,14 @@ export const withMask = (type, renderChildren) => {
22
22
  */
23
23
  layout: PropTypes.object,
24
24
  value: PropTypes.object,
25
- onChange: PropTypes.func
25
+ onChange: PropTypes.func,
26
26
  };
27
27
 
28
28
  render() {
29
29
  const { markup, layout, value, onChange } = this.props;
30
30
 
31
31
  const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
32
- return (
33
- <Mask
34
- layout={maskLayout}
35
- value={value}
36
- onChange={onChange}
37
- renderChildren={renderChildren(this.props)}
38
- />
39
- );
32
+ return <Mask layout={maskLayout} value={value} onChange={onChange} renderChildren={renderChildren(this.props)} />;
40
33
  }
41
34
  };
42
35
  };