@pie-lib/mask-markup 1.13.47-next.1 → 1.13.47-next.1639

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 (60) hide show
  1. package/CHANGELOG.json +1 -871
  2. package/CHANGELOG.md +170 -17
  3. package/NEXT.CHANGELOG.json +1 -0
  4. package/lib/choices/choice.js +80 -17
  5. package/lib/choices/choice.js.map +1 -1
  6. package/lib/choices/index.js +11 -3
  7. package/lib/choices/index.js.map +1 -1
  8. package/lib/components/blank.js +146 -34
  9. package/lib/components/blank.js.map +1 -1
  10. package/lib/components/correct-input.js +8 -3
  11. package/lib/components/correct-input.js.map +1 -1
  12. package/lib/components/dropdown.js +340 -58
  13. package/lib/components/dropdown.js.map +1 -1
  14. package/lib/constructed-response.js +87 -23
  15. package/lib/constructed-response.js.map +1 -1
  16. package/lib/customizable.js +48 -0
  17. package/lib/customizable.js.map +1 -0
  18. package/lib/drag-in-the-blank.js +34 -8
  19. package/lib/drag-in-the-blank.js.map +1 -1
  20. package/lib/index.js +8 -0
  21. package/lib/index.js.map +1 -1
  22. package/lib/inline-dropdown.js +3 -1
  23. package/lib/inline-dropdown.js.map +1 -1
  24. package/lib/mask.js +45 -6
  25. package/lib/mask.js.map +1 -1
  26. package/lib/with-mask.js +34 -2
  27. package/lib/with-mask.js.map +1 -1
  28. package/package.json +10 -6
  29. package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +316 -0
  30. package/src/__tests__/__snapshots__/mask.test.js.snap +55 -0
  31. package/src/__tests__/__snapshots__/with-mask.test.js.snap +62 -0
  32. package/src/__tests__/drag-in-the-blank.test.js +71 -0
  33. package/src/__tests__/index.test.js +39 -0
  34. package/src/__tests__/mask.test.js +152 -0
  35. package/src/__tests__/serialization.test.js +54 -0
  36. package/src/__tests__/utils.js +1 -0
  37. package/src/__tests__/with-mask.test.js +51 -0
  38. package/src/choices/__tests__/__snapshots__/index.test.js.snap +209 -0
  39. package/src/choices/__tests__/index.test.js +62 -0
  40. package/src/choices/choice.jsx +60 -6
  41. package/src/choices/index.jsx +2 -2
  42. package/src/components/__tests__/__snapshots__/blank.test.js.snap +111 -0
  43. package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +64 -0
  44. package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +136 -0
  45. package/src/components/__tests__/__snapshots__/input.test.js.snap +34 -0
  46. package/src/components/__tests__/blank.test.js +202 -0
  47. package/src/components/__tests__/correct-input.test.js +49 -0
  48. package/src/components/__tests__/dropdown.test.js +51 -0
  49. package/src/components/__tests__/input.test.js +50 -0
  50. package/src/components/blank.jsx +139 -28
  51. package/src/components/correct-input.jsx +6 -1
  52. package/src/components/dropdown.jsx +313 -79
  53. package/src/constructed-response.jsx +76 -18
  54. package/src/customizable.jsx +35 -0
  55. package/src/drag-in-the-blank.jsx +26 -3
  56. package/src/index.js +10 -1
  57. package/src/inline-dropdown.jsx +2 -0
  58. package/src/mask.jsx +30 -5
  59. package/src/with-mask.jsx +39 -2
  60. package/README.md +0 -14
package/lib/with-mask.js CHANGED
@@ -21,6 +21,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
21
21
 
22
22
  var _react = _interopRequireDefault(require("react"));
23
23
 
24
+ var _reactDom = _interopRequireDefault(require("react-dom"));
25
+
24
26
  var _propTypes = _interopRequireDefault(require("prop-types"));
25
27
 
26
28
  var _mask = _interopRequireDefault(require("./mask"));
@@ -57,15 +59,43 @@ var withMask = function withMask(type, renderChildren) {
57
59
  }
58
60
 
59
61
  (0, _createClass2["default"])(WithMask, [{
62
+ key: "componentDidUpdate",
63
+ value: function componentDidUpdate(prevProps) {
64
+ if (this.props.markup !== prevProps.markup) {
65
+ // eslint-disable-next-line
66
+ var domNode = _reactDom["default"].findDOMNode(this); // Query all elements that may contain outdated MathJax renderings
67
+
68
+
69
+ var mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]'); // Clean up for fresh MathJax processing
70
+
71
+ (mathElements || []).forEach(function (el) {
72
+ // Remove the MathJax container to allow for clean updates
73
+ var mjxContainer = el.querySelector('mjx-container');
74
+
75
+ if (mjxContainer) {
76
+ el.removeChild(mjxContainer);
77
+ } // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly
78
+
79
+
80
+ var latexCode = el.getAttribute('data-raw');
81
+ el.innerHTML = latexCode; // Remove the attribute to signal that MathJax should reprocess this element
82
+
83
+ el.removeAttribute('data-math-handled');
84
+ });
85
+ }
86
+ }
87
+ }, {
60
88
  key: "render",
61
89
  value: function render() {
62
90
  var _this$props = this.props,
63
91
  markup = _this$props.markup,
64
92
  layout = _this$props.layout,
65
93
  value = _this$props.value,
66
- onChange = _this$props.onChange;
94
+ onChange = _this$props.onChange,
95
+ elementType = _this$props.elementType;
67
96
  var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
68
97
  return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
98
+ elementType: elementType,
69
99
  layout: maskLayout,
70
100
  value: value,
71
101
  onChange: onChange,
@@ -85,7 +115,9 @@ var withMask = function withMask(type, renderChildren) {
85
115
  */
86
116
  layout: _propTypes["default"].object,
87
117
  value: _propTypes["default"].object,
88
- onChange: _propTypes["default"].func
118
+ onChange: _propTypes["default"].func,
119
+ customMarkMarkupComponent: _propTypes["default"].func,
120
+ elementType: _propTypes["default"].string
89
121
  }), _class;
90
122
  };
91
123
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/with-mask.jsx"],"names":["buildLayoutFromMarkup","markup","type","processed","value","document","withMask","renderChildren","props","layout","onChange","maskLayout","React","Component","PropTypes","string","object","func"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,MAAD,EAASC,IAAT,EAAkB;AACrD,sBAA8B,+BAAaD,MAAb,EAAqBC,IAArB,CAA9B;AAAA,MAAgBC,SAAhB,iBAAQF,MAAR;;AACA,MAAMG,KAAK,GAAG,gCAAYD,SAAZ,CAAd;AACA,SAAOC,KAAK,CAACC,QAAb;AACD,CAJM;;;;AAMA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACJ,IAAD,EAAOK,cAAP,EAA0B;AAAA;;AAChD;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,aAcE,kBAAS;AACP,0BAA4C,KAAKC,KAAjD;AAAA,YAAQP,MAAR,eAAQA,MAAR;AAAA,YAAgBQ,MAAhB,eAAgBA,MAAhB;AAAA,YAAwBL,KAAxB,eAAwBA,KAAxB;AAAA,YAA+BM,QAA/B,eAA+BA,QAA/B;AAEA,YAAMC,UAAU,GAAGF,MAAM,GAAGA,MAAH,GAAYT,qBAAqB,CAACC,MAAD,EAASC,IAAT,CAA1D;AACA,4BAAO,gCAAC,gBAAD;AAAM,UAAA,MAAM,EAAES,UAAd;AAA0B,UAAA,KAAK,EAAEP,KAAjC;AAAwC,UAAA,QAAQ,EAAEM,QAAlD;AAA4D,UAAA,cAAc,EAAEH,cAAc,CAAC,KAAKC,KAAN;AAA1F,UAAP;AACD;AAnBH;AAAA;AAAA,IAA8BI,kBAAMC,SAApC,yDACqB;AACjB;AACN;AACA;AACMZ,IAAAA,MAAM,EAAEa,sBAAUC,MAJD;;AAKjB;AACN;AACA;AACMN,IAAAA,MAAM,EAAEK,sBAAUE,MARD;AASjBZ,IAAAA,KAAK,EAAEU,sBAAUE,MATA;AAUjBN,IAAAA,QAAQ,EAAEI,sBAAUG;AAVH,GADrB;AAqBD,CAtBM","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Mask from './mask';\nimport componentize from './componentize';\nimport { deserialize } from './serialization';\n\nexport const buildLayoutFromMarkup = (markup, type) => {\n const { markup: processed } = componentize(markup, type);\n const value = deserialize(processed);\n return value.document;\n};\n\nexport const withMask = (type, renderChildren) => {\n return class WithMask extends React.Component {\n static propTypes = {\n /**\n * At the start we'll probably work with markup\n */\n markup: PropTypes.string,\n /**\n * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.\n */\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n };\n\n render() {\n const { markup, layout, value, onChange } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return <Mask layout={maskLayout} value={value} onChange={onChange} renderChildren={renderChildren(this.props)} />;\n }\n };\n};\n"],"file":"with-mask.js"}
1
+ {"version":3,"sources":["../src/with-mask.jsx"],"names":["buildLayoutFromMarkup","markup","type","processed","value","document","withMask","renderChildren","prevProps","props","domNode","ReactDOM","findDOMNode","mathElements","querySelectorAll","forEach","el","mjxContainer","querySelector","removeChild","latexCode","getAttribute","innerHTML","removeAttribute","layout","onChange","elementType","maskLayout","React","Component","PropTypes","string","object","func","customMarkMarkupComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,MAAD,EAASC,IAAT,EAAkB;AACrD,sBAA8B,+BAAaD,MAAb,EAAqBC,IAArB,CAA9B;AAAA,MAAgBC,SAAhB,iBAAQF,MAAR;;AACA,MAAMG,KAAK,GAAG,gCAAYD,SAAZ,CAAd;AACA,SAAOC,KAAK,CAACC,QAAb;AACD,CAJM;;;;AAMA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACJ,IAAD,EAAOK,cAAP,EAA0B;AAAA;;AAChD;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,aAgBE,4BAAmBC,SAAnB,EAA8B;AAC5B,YAAI,KAAKC,KAAL,CAAWR,MAAX,KAAsBO,SAAS,CAACP,MAApC,EAA4C;AAC1C;AACA,cAAMS,OAAO,GAAGC,qBAASC,WAAT,CAAqB,IAArB,CAAhB,CAF0C,CAG1C;;;AACA,cAAMC,YAAY,GAAGH,OAAO,IAAIA,OAAO,CAACI,gBAAR,CAAyB,wCAAzB,CAAhC,CAJ0C,CAM1C;;AACA,WAACD,YAAY,IAAI,EAAjB,EAAqBE,OAArB,CAA6B,UAACC,EAAD,EAAQ;AACnC;AACA,gBAAMC,YAAY,GAAGD,EAAE,CAACE,aAAH,CAAiB,eAAjB,CAArB;;AAEA,gBAAID,YAAJ,EAAkB;AAChBD,cAAAA,EAAE,CAACG,WAAH,CAAeF,YAAf;AACD,aANkC,CAQnC;;;AACA,gBAAMG,SAAS,GAAGJ,EAAE,CAACK,YAAH,CAAgB,UAAhB,CAAlB;AACAL,YAAAA,EAAE,CAACM,SAAH,GAAeF,SAAf,CAVmC,CAYnC;;AACAJ,YAAAA,EAAE,CAACO,eAAH,CAAmB,mBAAnB;AACD,WAdD;AAeD;AACF;AAxCH;AAAA;AAAA,aA0CE,kBAAS;AACP,0BAAyD,KAAKd,KAA9D;AAAA,YAAQR,MAAR,eAAQA,MAAR;AAAA,YAAgBuB,MAAhB,eAAgBA,MAAhB;AAAA,YAAwBpB,KAAxB,eAAwBA,KAAxB;AAAA,YAA+BqB,QAA/B,eAA+BA,QAA/B;AAAA,YAAyCC,WAAzC,eAAyCA,WAAzC;AAEA,YAAMC,UAAU,GAAGH,MAAM,GAAGA,MAAH,GAAYxB,qBAAqB,CAACC,MAAD,EAASC,IAAT,CAA1D;AACA,4BACE,gCAAC,gBAAD;AACE,UAAA,WAAW,EAAEwB,WADf;AAEE,UAAA,MAAM,EAAEC,UAFV;AAGE,UAAA,KAAK,EAAEvB,KAHT;AAIE,UAAA,QAAQ,EAAEqB,QAJZ;AAKE,UAAA,cAAc,EAAElB,cAAc,CAAC,KAAKE,KAAN;AALhC,UADF;AASD;AAvDH;AAAA;AAAA,IAA8BmB,kBAAMC,SAApC,yDACqB;AACjB;AACN;AACA;AACM5B,IAAAA,MAAM,EAAE6B,sBAAUC,MAJD;;AAKjB;AACN;AACA;AACMP,IAAAA,MAAM,EAAEM,sBAAUE,MARD;AASjB5B,IAAAA,KAAK,EAAE0B,sBAAUE,MATA;AAUjBP,IAAAA,QAAQ,EAAEK,sBAAUG,IAVH;AAWjBC,IAAAA,yBAAyB,EAAEJ,sBAAUG,IAXpB;AAYjBP,IAAAA,WAAW,EAAEI,sBAAUC;AAZN,GADrB;AAyDD,CA1DM","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport Mask from './mask';\nimport componentize from './componentize';\nimport { deserialize } from './serialization';\n\nexport const buildLayoutFromMarkup = (markup, type) => {\n const { markup: processed } = componentize(markup, type);\n const value = deserialize(processed);\n return value.document;\n};\n\nexport const withMask = (type, renderChildren) => {\n return class WithMask extends React.Component {\n static propTypes = {\n /**\n * At the start we'll probably work with markup\n */\n markup: PropTypes.string,\n /**\n * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.\n */\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n customMarkMarkupComponent: PropTypes.func,\n elementType: PropTypes.string,\n };\n\n componentDidUpdate(prevProps) {\n if (this.props.markup !== prevProps.markup) {\n // eslint-disable-next-line\n const domNode = ReactDOM.findDOMNode(this);\n // Query all elements that may contain outdated MathJax renderings\n const mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled=\"true\"]');\n\n // Clean up for fresh MathJax processing\n (mathElements || []).forEach((el) => {\n // Remove the MathJax container to allow for clean updates\n const mjxContainer = el.querySelector('mjx-container');\n\n if (mjxContainer) {\n el.removeChild(mjxContainer);\n }\n\n // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly\n const latexCode = el.getAttribute('data-raw');\n el.innerHTML = latexCode;\n\n // Remove the attribute to signal that MathJax should reprocess this element\n el.removeAttribute('data-math-handled');\n });\n }\n }\n\n render() {\n const { markup, layout, value, onChange, elementType } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return (\n <Mask\n elementType={elementType}\n layout={maskLayout}\n value={value}\n onChange={onChange}\n renderChildren={renderChildren(this.props)}\n />\n );\n }\n };\n};\n"],"file":"with-mask.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/mask-markup",
3
- "version": "1.13.47-next.1+23991a09",
3
+ "version": "1.13.47-next.1639+4ac095ca",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -9,15 +9,19 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@material-ui/core": "^3.9.3",
12
- "@pie-lib/drag": "^2.2.10-next.1+23991a09",
13
- "@pie-lib/math-rendering": "2.5.18",
14
- "@pie-lib/render-ui": "^4.15.10-next.1+23991a09",
12
+ "@material-ui/icons": "^3.0.2",
13
+ "@pie-lib/drag": "^2.2.10-next.1639+4ac095ca",
14
+ "@pie-lib/editable-html": "^11.1.2-next.1595+4ac095ca",
15
+ "@pie-lib/math-rendering": "^3.2.2-next.1642+4ac095ca",
16
+ "@pie-lib/render-ui": "^4.15.10-next.1639+4ac095ca",
15
17
  "classnames": "^2.2.6",
16
18
  "debug": "^4.1.1",
17
- "immutable": ">=3.8.1",
19
+ "immutable": "^4.0.0-rc.12",
20
+ "lodash": "^4.17.11",
18
21
  "prop-types": "^15.7.2",
19
22
  "react": "^16.8.1",
20
23
  "react-dnd-html5-backend": "^14.0.2",
24
+ "react-dom": "^16.9.0",
21
25
  "slate": "^0.36.2",
22
26
  "slate-html-serializer": "^0.6.12",
23
27
  "slate-prop-types": "^0.4.38",
@@ -27,5 +31,5 @@
27
31
  "keywords": [],
28
32
  "author": "",
29
33
  "license": "ISC",
30
- "gitHead": "23991a09b77492c24dcb5235049667cdcc211d80"
34
+ "gitHead": "4ac095ca931e5fe8f131f28f41dd61093bd55d98"
31
35
  }
@@ -0,0 +1,316 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`DragInTheBlank render renders correctly with default props 1`] = `
4
+ <div
5
+ style={
6
+ Object {
7
+ "alignItems": undefined,
8
+ "display": "flex",
9
+ "flexDirection": "column-reverse",
10
+ "justifyContent": undefined,
11
+ "minWidth": "100px",
12
+ }
13
+ }
14
+ >
15
+ <Choices
16
+ choicePosition="below"
17
+ choices={
18
+ Array [
19
+ Object {
20
+ "id": "0",
21
+ "value": "Jumped",
22
+ },
23
+ Object {
24
+ "id": "1",
25
+ "value": "Laughed",
26
+ },
27
+ Object {
28
+ "id": "2",
29
+ "value": "Spoon",
30
+ },
31
+ Object {
32
+ "id": "3",
33
+ "value": "Fork",
34
+ },
35
+ Object {
36
+ "id": "4",
37
+ "value": "Bumped",
38
+ },
39
+ Object {
40
+ "id": "5",
41
+ "value": "Smiled",
42
+ },
43
+ ]
44
+ }
45
+ disabled={false}
46
+ value={
47
+ Object {
48
+ "0": undefined,
49
+ }
50
+ }
51
+ />
52
+ <WithMask
53
+ choices={
54
+ Array [
55
+ Object {
56
+ "id": "0",
57
+ "value": "Jumped",
58
+ },
59
+ Object {
60
+ "id": "1",
61
+ "value": "Laughed",
62
+ },
63
+ Object {
64
+ "id": "2",
65
+ "value": "Spoon",
66
+ },
67
+ Object {
68
+ "id": "3",
69
+ "value": "Fork",
70
+ },
71
+ Object {
72
+ "id": "4",
73
+ "value": "Bumped",
74
+ },
75
+ Object {
76
+ "id": "5",
77
+ "value": "Smiled",
78
+ },
79
+ ]
80
+ }
81
+ disabled={false}
82
+ elementType="drag-in-the-blank"
83
+ feedback={Object {}}
84
+ markup="<div>
85
+ <img src=\\"https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg\\"></img>
86
+ <h5>Hey Diddle Diddle <i>by ?</i></h5>
87
+ <p>1: Hey, diddle, diddle,</p>
88
+ <p>2: The cat and the fiddle,</p>
89
+ <p>3: The cow {{0}} over the moon;</p>
90
+ <p>4: The little dog {{1}},</p>
91
+ <p>5: To see such sport,</p>
92
+ <p>6: And the dish ran away with the {{2}}.</p>
93
+ </div>"
94
+ value={
95
+ Object {
96
+ "0": undefined,
97
+ }
98
+ }
99
+ />
100
+ </div>
101
+ `;
102
+
103
+ exports[`DragInTheBlank render renders correctly with disabled prop as true 1`] = `
104
+ <div
105
+ style={
106
+ Object {
107
+ "alignItems": undefined,
108
+ "display": "flex",
109
+ "flexDirection": "column-reverse",
110
+ "justifyContent": undefined,
111
+ "minWidth": "100px",
112
+ }
113
+ }
114
+ >
115
+ <Choices
116
+ choicePosition="below"
117
+ choices={
118
+ Array [
119
+ Object {
120
+ "id": "0",
121
+ "value": "Jumped",
122
+ },
123
+ Object {
124
+ "id": "1",
125
+ "value": "Laughed",
126
+ },
127
+ Object {
128
+ "id": "2",
129
+ "value": "Spoon",
130
+ },
131
+ Object {
132
+ "id": "3",
133
+ "value": "Fork",
134
+ },
135
+ Object {
136
+ "id": "4",
137
+ "value": "Bumped",
138
+ },
139
+ Object {
140
+ "id": "5",
141
+ "value": "Smiled",
142
+ },
143
+ ]
144
+ }
145
+ disabled={true}
146
+ value={
147
+ Object {
148
+ "0": undefined,
149
+ }
150
+ }
151
+ />
152
+ <WithMask
153
+ choices={
154
+ Array [
155
+ Object {
156
+ "id": "0",
157
+ "value": "Jumped",
158
+ },
159
+ Object {
160
+ "id": "1",
161
+ "value": "Laughed",
162
+ },
163
+ Object {
164
+ "id": "2",
165
+ "value": "Spoon",
166
+ },
167
+ Object {
168
+ "id": "3",
169
+ "value": "Fork",
170
+ },
171
+ Object {
172
+ "id": "4",
173
+ "value": "Bumped",
174
+ },
175
+ Object {
176
+ "id": "5",
177
+ "value": "Smiled",
178
+ },
179
+ ]
180
+ }
181
+ disabled={true}
182
+ elementType="drag-in-the-blank"
183
+ feedback={Object {}}
184
+ markup="<div>
185
+ <img src=\\"https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg\\"></img>
186
+ <h5>Hey Diddle Diddle <i>by ?</i></h5>
187
+ <p>1: Hey, diddle, diddle,</p>
188
+ <p>2: The cat and the fiddle,</p>
189
+ <p>3: The cow {{0}} over the moon;</p>
190
+ <p>4: The little dog {{1}},</p>
191
+ <p>5: To see such sport,</p>
192
+ <p>6: And the dish ran away with the {{2}}.</p>
193
+ </div>"
194
+ value={
195
+ Object {
196
+ "0": undefined,
197
+ }
198
+ }
199
+ />
200
+ </div>
201
+ `;
202
+
203
+ exports[`DragInTheBlank render renders correctly with feedback 1`] = `
204
+ <div
205
+ style={
206
+ Object {
207
+ "alignItems": undefined,
208
+ "display": "flex",
209
+ "flexDirection": "column-reverse",
210
+ "justifyContent": undefined,
211
+ "minWidth": "100px",
212
+ }
213
+ }
214
+ >
215
+ <Choices
216
+ choicePosition="below"
217
+ choices={
218
+ Array [
219
+ Object {
220
+ "id": "0",
221
+ "value": "Jumped",
222
+ },
223
+ Object {
224
+ "id": "1",
225
+ "value": "Laughed",
226
+ },
227
+ Object {
228
+ "id": "2",
229
+ "value": "Spoon",
230
+ },
231
+ Object {
232
+ "id": "3",
233
+ "value": "Fork",
234
+ },
235
+ Object {
236
+ "id": "4",
237
+ "value": "Bumped",
238
+ },
239
+ Object {
240
+ "id": "5",
241
+ "value": "Smiled",
242
+ },
243
+ ]
244
+ }
245
+ disabled={false}
246
+ value={
247
+ Object {
248
+ "0": undefined,
249
+ }
250
+ }
251
+ />
252
+ <WithMask
253
+ choices={
254
+ Array [
255
+ Object {
256
+ "id": "0",
257
+ "value": "Jumped",
258
+ },
259
+ Object {
260
+ "id": "1",
261
+ "value": "Laughed",
262
+ },
263
+ Object {
264
+ "id": "2",
265
+ "value": "Spoon",
266
+ },
267
+ Object {
268
+ "id": "3",
269
+ "value": "Fork",
270
+ },
271
+ Object {
272
+ "id": "4",
273
+ "value": "Bumped",
274
+ },
275
+ Object {
276
+ "id": "5",
277
+ "value": "Smiled",
278
+ },
279
+ ]
280
+ }
281
+ disabled={false}
282
+ elementType="drag-in-the-blank"
283
+ feedback={
284
+ Object {
285
+ "0": Object {
286
+ "correct": "Jumped",
287
+ "value": "Jumped",
288
+ },
289
+ "1": Object {
290
+ "correct": "Laughed",
291
+ "value": "Laughed",
292
+ },
293
+ "2": Object {
294
+ "correct": "Spoon",
295
+ "value": "Spoon",
296
+ },
297
+ }
298
+ }
299
+ markup="<div>
300
+ <img src=\\"https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg\\"></img>
301
+ <h5>Hey Diddle Diddle <i>by ?</i></h5>
302
+ <p>1: Hey, diddle, diddle,</p>
303
+ <p>2: The cat and the fiddle,</p>
304
+ <p>3: The cow {{0}} over the moon;</p>
305
+ <p>4: The little dog {{1}},</p>
306
+ <p>5: To see such sport,</p>
307
+ <p>6: And the dish ran away with the {{2}}.</p>
308
+ </div>"
309
+ value={
310
+ Object {
311
+ "0": undefined,
312
+ }
313
+ }
314
+ />
315
+ </div>
316
+ `;
@@ -0,0 +1,55 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Mask render renders correctly a div 1`] = `
4
+ <div>
5
+ <div
6
+ key="div-0"
7
+ >
8
+ <WithStyles(Component)
9
+ key="p-0"
10
+ >
11
+ Foo
12
+ </WithStyles(Component)>
13
+ </div>
14
+ </div>
15
+ `;
16
+
17
+ exports[`Mask render renders correctly a em 1`] = `
18
+ <WithStyles(Component)>
19
+ Foo
20
+ <em
21
+ key="1"
22
+ >
23
+ x
24
+ </em>
25
+ bar
26
+ </WithStyles(Component)>
27
+ `;
28
+
29
+ exports[`Mask render renders correctly a paragraph 1`] = `
30
+ <div>
31
+ <WithStyles(Component)
32
+ key="p-0"
33
+ >
34
+ Foo
35
+ </WithStyles(Component)>
36
+ </div>
37
+ `;
38
+
39
+ exports[`Mask render renders correctly with default props 1`] = `
40
+ <div>
41
+ Foo
42
+ </div>
43
+ `;
44
+
45
+ exports[`Mask render renders without space under tbody 1`] = `
46
+ <div>
47
+ <tbody
48
+ key="tbody-0"
49
+ >
50
+ <tr
51
+ key="tr-1"
52
+ />
53
+ </tbody>
54
+ </div>
55
+ `;
@@ -0,0 +1,62 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`WithMask render renders correctly with default props 1`] = `
4
+ <Mask
5
+ layout={
6
+ Object {
7
+ "data": Object {},
8
+ "nodes": Array [
9
+ Object {
10
+ "data": Object {
11
+ "attributes": Object {},
12
+ "dataset": Object {},
13
+ },
14
+ "nodes": Array [
15
+ Object {
16
+ "leaves": Array [
17
+ Object {
18
+ "text": "Foo bar ",
19
+ },
20
+ ],
21
+ "object": "text",
22
+ },
23
+ Object {
24
+ "data": Object {
25
+ "attributes": Object {
26
+ "data-component": "foo",
27
+ "data-id": "0",
28
+ },
29
+ "dataset": Object {
30
+ "component": "foo",
31
+ "id": "0",
32
+ },
33
+ },
34
+ "nodes": Array [],
35
+ "object": "inline",
36
+ "type": "span",
37
+ },
38
+ Object {
39
+ "leaves": Array [
40
+ Object {
41
+ "text": " over the moon;",
42
+ },
43
+ ],
44
+ "object": "text",
45
+ },
46
+ ],
47
+ "object": "block",
48
+ "type": "p",
49
+ },
50
+ ],
51
+ "object": "document",
52
+ }
53
+ }
54
+ onChange={[MockFunction]}
55
+ renderChildren={[Function]}
56
+ value={
57
+ Object {
58
+ "0": "blank",
59
+ }
60
+ }
61
+ />
62
+ `;
@@ -0,0 +1,71 @@
1
+ import * as React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import DragInTheBlank from '../drag-in-the-blank';
4
+
5
+ const markup = `<div>
6
+ <img src="https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg"></img>
7
+ <h5>Hey Diddle Diddle <i>by ?</i></h5>
8
+ <p>1: Hey, diddle, diddle,</p>
9
+ <p>2: The cat and the fiddle,</p>
10
+ <p>3: The cow {{0}} over the moon;</p>
11
+ <p>4: The little dog {{1}},</p>
12
+ <p>5: To see such sport,</p>
13
+ <p>6: And the dish ran away with the {{2}}.</p>
14
+ </div>`;
15
+ const choice = (v, id) => ({ value: v, id });
16
+
17
+ describe('DragInTheBlank', () => {
18
+ const defaultProps = {
19
+ disabled: false,
20
+ feedback: {},
21
+ markup,
22
+ choices: [
23
+ choice('Jumped', '0'),
24
+ choice('Laughed', '1'),
25
+ choice('Spoon', '2'),
26
+ choice('Fork', '3'),
27
+ choice('Bumped', '4'),
28
+ choice('Smiled', '5'),
29
+ ],
30
+
31
+ value: {
32
+ 0: undefined,
33
+ },
34
+ };
35
+ let wrapper;
36
+
37
+ beforeEach(() => {
38
+ wrapper = shallow(<DragInTheBlank {...defaultProps} />);
39
+ });
40
+
41
+ describe('render', () => {
42
+ it('renders correctly with default props', () => {
43
+ expect(wrapper).toMatchSnapshot();
44
+ });
45
+
46
+ it('renders correctly with disabled prop as true', () => {
47
+ wrapper.setProps({ disabled: true });
48
+ expect(wrapper).toMatchSnapshot();
49
+ });
50
+
51
+ it('renders correctly with feedback', () => {
52
+ wrapper.setProps({
53
+ feedback: {
54
+ 0: {
55
+ value: 'Jumped',
56
+ correct: 'Jumped',
57
+ },
58
+ 1: {
59
+ value: 'Laughed',
60
+ correct: 'Laughed',
61
+ },
62
+ 2: {
63
+ value: 'Spoon',
64
+ correct: 'Spoon',
65
+ },
66
+ },
67
+ });
68
+ expect(wrapper).toMatchSnapshot();
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ import componentize from '../componentize';
3
+ import { deserialize } from '../serialization';
4
+
5
+ describe('index', () => {
6
+ describe('componentize', () => {
7
+ it('should return an array with the appropriate markup', () => {
8
+ const dropDownMarkup = componentize('{{0}} foo {{1}}', 'dropdown');
9
+
10
+ expect(dropDownMarkup).toEqual({
11
+ markup:
12
+ '<span data-component="dropdown" data-id="0"></span> foo <span data-component="dropdown" data-id="1"></span>',
13
+ });
14
+ });
15
+ });
16
+
17
+ describe('serialization', () => {
18
+ it('should have default node a span', () => {
19
+ expect(deserialize('something')).toEqual(
20
+ expect.objectContaining({
21
+ object: 'value',
22
+ document: {
23
+ object: 'document',
24
+ data: {},
25
+ nodes: [
26
+ {
27
+ object: 'block',
28
+ data: {},
29
+ isVoid: false,
30
+ type: 'span',
31
+ nodes: [{ object: 'text', leaves: [{ text: 'something' }] }],
32
+ },
33
+ ],
34
+ },
35
+ }),
36
+ );
37
+ });
38
+ });
39
+ });