@pie-element/explicit-constructed-response 6.12.1-next.1 → 6.12.1-next.11

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.
package/lib/index.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
23
+
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _reactDom = _interopRequireDefault(require("react-dom"));
29
+
30
+ var _piePlayerEvents = require("@pie-framework/pie-player-events");
31
+
32
+ var _mathRenderingAccessible = require("@pie-lib/pie-toolbox/math-rendering-accessible");
33
+
34
+ var _main = _interopRequireDefault(require("./main"));
35
+
36
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
37
+
38
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
39
+
40
+ var InlineDropdown = /*#__PURE__*/function (_HTMLElement) {
41
+ (0, _inherits2["default"])(InlineDropdown, _HTMLElement);
42
+
43
+ var _super = _createSuper(InlineDropdown);
44
+
45
+ function InlineDropdown() {
46
+ var _this;
47
+
48
+ (0, _classCallCheck2["default"])(this, InlineDropdown);
49
+ _this = _super.call(this);
50
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_render", function () {
51
+ if (_this._model && _this._session) {
52
+ var elem = /*#__PURE__*/_react["default"].createElement(_main["default"], {
53
+ teacherInstructions: _this._model.teacherInstructions,
54
+ prompt: _this._model.prompt,
55
+ note: _this._model.note,
56
+ showNote: _this._model.showNote,
57
+ env: _this._model.env,
58
+ rationale: _this._model.rationale,
59
+ disabled: _this._model.disabled,
60
+ choices: _this._model.choices,
61
+ markup: _this._model.markup,
62
+ mode: _this._model.mode,
63
+ maxLengthPerChoice: _this._model.maxLengthPerChoice,
64
+ maxLengthPerChoiceEnabled: _this._model.maxLengthPerChoiceEnabled,
65
+ playerSpellCheckEnabled: _this._model.playerSpellCheckEnabled,
66
+ value: _this._session.value,
67
+ feedback: _this._model.feedback,
68
+ displayType: _this._model.displayType,
69
+ language: _this._model.language,
70
+ onChange: _this.changeSession
71
+ });
72
+
73
+ _reactDom["default"].render(elem, (0, _assertThisInitialized2["default"])(_this), function () {
74
+ (0, _mathRenderingAccessible.renderMath)((0, _assertThisInitialized2["default"])(_this));
75
+ });
76
+ }
77
+ });
78
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "dispatchChangedEvent", function () {
79
+ _this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(_this.tagName.toLowerCase(), _this.session && !!_this.session.value));
80
+ });
81
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeSession", function (value) {
82
+ _this.session.value = value;
83
+
84
+ _this.dispatchChangedEvent();
85
+
86
+ _this._render();
87
+ });
88
+ _this._model = null;
89
+ _this._session = null;
90
+ return _this;
91
+ }
92
+
93
+ (0, _createClass2["default"])(InlineDropdown, [{
94
+ key: "model",
95
+ set: function set(m) {
96
+ this._model = m;
97
+ this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model));
98
+
99
+ this._render();
100
+ }
101
+ }, {
102
+ key: "session",
103
+ get: function get() {
104
+ return this._session;
105
+ },
106
+ set: function set(s) {
107
+ this._session = s;
108
+
109
+ this._render();
110
+ }
111
+ }, {
112
+ key: "connectedCallback",
113
+ value: function connectedCallback() {
114
+ this.setAttribute('aria-label', 'Fill in the Blank Question');
115
+ this.setAttribute('role', 'region');
116
+
117
+ this._render();
118
+ }
119
+ }]);
120
+ return InlineDropdown;
121
+ }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
122
+
123
+ exports["default"] = InlineDropdown;
124
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"names":["InlineDropdown","_model","_session","elem","React","createElement","Main","teacherInstructions","prompt","note","showNote","env","rationale","disabled","choices","markup","mode","maxLengthPerChoice","maxLengthPerChoiceEnabled","playerSpellCheckEnabled","value","feedback","displayType","language","onChange","changeSession","ReactDOM","render","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","session","dispatchChangedEvent","_render","m","ModelSetEvent","s","setAttribute","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;;;IAEqBA,c;;;;;AACnB,4BAAc;AAAA;;AAAA;AACZ;AADY,gGAwBJ,YAAM;AACd,UAAI,MAAKC,MAAL,IAAe,MA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mB,IAAIC,oCAAJ,CAAwB,MAAKC,OAAL,CAAaC,WAAb,EAAxB,EAAoD,MAAKC,OAAL,IAAgB,CAAC,CAAC,MAAKA,OAAL,CAAaZ,KAAnF,CAAnB;AACD,KAvDa;AAAA,sGAyDE,UAACA,KAAD,EAAW;AACzB,YAAKY,OAAL,CAAaZ,KAAb,GAAqBA,KAArB;;AACA,YAAKa,oBAAL;;AACA,YAAKC,OAAL;AACD,KA7Da;AAEZ,UAAKjC,MAAL,GAAc,IAAd;AACA,UAAKC,QAAL,GAAgB,IAAhB;AAHY;AAIb;;;;SAED,aAAUiC,CAAV,EAAa;AACX,WAAKlC,MAAL,GAAckC,CAAd;AACA,WAAKP,aAAL,CACE,IAAIQ,8BAAJ,CAAkB,KAAKN,OAAL,CAAaC,WAAb,EAAlB,EAA8C,KAAKC,OAAL,IAAgB,CAAC,CAAC,KAAKA,OAAL,CAAaZ,KAA7E,EAAoF,CAAC,CAAC,KAAKnB,MAA3F,CADF;;AAIA,WAAKiC,OAAL;AACD;;;SAOD,eAAc;AACZ,aAAO,KAAKhC,QAAZ;AACD,K;SAPD,aAAYmC,CAAZ,EAAe;AACb,WAAKnC,QAAL,GAAgBmC,CAAhB;;AACA,WAAKH,OAAL;AACD;;;WA6CD,6BAAoB;AAClB,WAAKI,YAAL,CAAkB,YAAlB,EAAgC,4BAAhC;AACA,WAAKA,YAAL,CAAkB,MAAlB,EAA0B,QAA1B;;AAEA,WAAKJ,OAAL;AACD;;;kDArEyCK,W","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/pie-toolbox/math-rendering-accessible';\n\nimport Main from './main';\n\nexport default class InlineDropdown extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n }\n\n set model(m) {\n this._model = m;\n this.dispatchEvent(\n new ModelSetEvent(this.tagName.toLowerCase(), this.session && !!this.session.value, !!this._model),\n );\n\n this._render();\n }\n\n set session(s) {\n this._session = s;\n this._render();\n }\n\n get session() {\n return this._session;\n }\n\n _render = () => {\n if (this._model && this._session) {\n let elem = React.createElement(Main, {\n teacherInstructions: this._model.teacherInstructions,\n prompt: this._model.prompt,\n note: this._model.note,\n showNote: this._model.showNote,\n env: this._model.env,\n rationale: this._model.rationale,\n disabled: this._model.disabled,\n choices: this._model.choices,\n markup: this._model.markup,\n mode: this._model.mode,\n maxLengthPerChoice: this._model.maxLengthPerChoice,\n maxLengthPerChoiceEnabled: this._model.maxLengthPerChoiceEnabled,\n playerSpellCheckEnabled: this._model.playerSpellCheckEnabled,\n value: this._session.value,\n feedback: this._model.feedback,\n displayType: this._model.displayType,\n language: this._model.language,\n onChange: this.changeSession,\n });\n\n ReactDOM.render(elem, this, () => {\n renderMath(this);\n });\n }\n };\n\n dispatchChangedEvent = () => {\n this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), this.session && !!this.session.value));\n };\n\n changeSession = (value) => {\n this.session.value = value;\n this.dispatchChangedEvent();\n this._render();\n };\n\n connectedCallback() {\n this.setAttribute('aria-label', 'Fill in the Blank Question');\n this.setAttribute('role', 'region');\n\n this._render();\n }\n}\n"],"file":"index.js"}
package/lib/main.js ADDED
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.Main = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
+
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
20
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
22
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _propTypes = _interopRequireDefault(require("prop-types"));
29
+
30
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
31
+
32
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
33
+
34
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
35
+
36
+ var _correctAnswerToggle = require("@pie-lib/pie-toolbox/correct-answer-toggle");
37
+
38
+ var _maskMarkup = require("@pie-lib/pie-toolbox/mask-markup");
39
+
40
+ var _renderUi = require("@pie-lib/pie-toolbox/render-ui");
41
+
42
+ var _styles = require("@material-ui/core/styles");
43
+
44
+ var _classnames = _interopRequireDefault(require("classnames"));
45
+
46
+ var _translator = _interopRequireDefault(require("@pie-lib/pie-toolbox/translator"));
47
+
48
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
49
+
50
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
51
+
52
+ var translator = _translator["default"].translator;
53
+
54
+ var Main = /*#__PURE__*/function (_React$Component) {
55
+ (0, _inherits2["default"])(Main, _React$Component);
56
+
57
+ var _super = _createSuper(Main);
58
+
59
+ function Main() {
60
+ var _this;
61
+
62
+ (0, _classCallCheck2["default"])(this, Main);
63
+
64
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
65
+ args[_key] = arguments[_key];
66
+ }
67
+
68
+ _this = _super.call.apply(_super, [this].concat(args));
69
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
70
+ showCorrectAnswer: _this.props.alwaysShowCorrect || false,
71
+ value: _this.props.value
72
+ });
73
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getChangeSession", function (maxLengthPerChoice) {
74
+ return maxLengthPerChoice && maxLengthPerChoice.every(function (val, i, arr) {
75
+ return val === arr[0] && val === 1;
76
+ }) ? _this.props.onChange : (0, _debounce["default"])(_this.props.onChange, 1500, {
77
+ maxWait: 1500
78
+ });
79
+ });
80
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleShowCorrect", function () {
81
+ _this.setState({
82
+ showCorrectAnswer: !_this.state.showCorrectAnswer
83
+ });
84
+ });
85
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeSession", _this.getChangeSession(_this.props.maxLengthPerChoice));
86
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (value) {
87
+ _this.setState({
88
+ value: value
89
+ });
90
+
91
+ _this.changeSession(value);
92
+ });
93
+ return _this;
94
+ }
95
+
96
+ (0, _createClass2["default"])(Main, [{
97
+ key: "UNSAFE_componentWillReceiveProps",
98
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
99
+ var _this$props = this.props,
100
+ maxLengthPerChoice = _this$props.maxLengthPerChoice,
101
+ language = _this$props.language;
102
+ var note = this.props.note;
103
+
104
+ if ((0, _isEmpty["default"])(nextProps.feedback)) {
105
+ this.setState({
106
+ showCorrectAnswer: false
107
+ });
108
+ }
109
+
110
+ if (nextProps.alwaysShowCorrect) {
111
+ this.setState({
112
+ showCorrectAnswer: true
113
+ });
114
+ }
115
+
116
+ if (maxLengthPerChoice && !(0, _isEqual["default"])(maxLengthPerChoice, nextProps.maxLengthPerChoice)) {
117
+ this.changeSession = this.getChangeSession(nextProps.maxLengthPerChoice);
118
+ } // check if the note is the default one for prev language and change to the default one for new language
119
+ // this check is necessary in order to diferanciate between default and authour defined note
120
+ // and only change between languages for default ones
121
+
122
+
123
+ if (note && language && language !== nextProps.language && note === translator.t('common:commonCorrectAnswerWithAlternates', {
124
+ lng: language
125
+ })) {
126
+ note = translator.t('common:commonCorrectAnswerWithAlternates', {
127
+ lng: nextProps.language
128
+ });
129
+ }
130
+ }
131
+ }, {
132
+ key: "render",
133
+ value: function render() {
134
+ var _this$state = this.state,
135
+ showCorrectAnswer = _this$state.showCorrectAnswer,
136
+ value = _this$state.value;
137
+ var _this$props2 = this.props,
138
+ classes = _this$props2.classes,
139
+ mode = _this$props2.mode,
140
+ prompt = _this$props2.prompt,
141
+ rationale = _this$props2.rationale,
142
+ teacherInstructions = _this$props2.teacherInstructions,
143
+ note = _this$props2.note,
144
+ showNote = _this$props2.showNote,
145
+ env = _this$props2.env,
146
+ animationsDisabled = _this$props2.animationsDisabled,
147
+ alwaysShowCorrect = _this$props2.alwaysShowCorrect,
148
+ maxLengthPerChoice = _this$props2.maxLengthPerChoice,
149
+ maxLengthPerChoiceEnabled = _this$props2.maxLengthPerChoiceEnabled,
150
+ displayType = _this$props2.displayType,
151
+ playerSpellCheckEnabled = _this$props2.playerSpellCheckEnabled,
152
+ language = _this$props2.language;
153
+
154
+ var _ref = env || {},
155
+ role = _ref.role;
156
+
157
+ var displayNote = (showCorrectAnswer || mode === 'view' && role === 'instructor') && showNote && note;
158
+ var mainClasses = (0, _classnames["default"])([classes.mainContainer, (0, _defineProperty2["default"])({}, classes.noBorderColor, alwaysShowCorrect)]);
159
+
160
+ var teacherInstructionsDiv = /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
161
+ defaultClassName: "teacher-instructions",
162
+ prompt: teacherInstructions
163
+ });
164
+
165
+ var rationaleDiv = /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
166
+ prompt: rationale
167
+ });
168
+
169
+ return /*#__PURE__*/_react["default"].createElement("div", {
170
+ className: mainClasses,
171
+ style: {
172
+ display: "".concat(displayType)
173
+ }
174
+ }, mode === 'gather' && /*#__PURE__*/_react["default"].createElement("h2", {
175
+ className: classes.srOnly
176
+ }, "Fill in the Blank Question"), teacherInstructions && (0, _renderUi.hasText)(teacherInstructions) && /*#__PURE__*/_react["default"].createElement("div", {
177
+ className: classes.collapsible
178
+ }, !animationsDisabled ? /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
179
+ labels: {
180
+ hidden: 'Show Teacher Instructions',
181
+ visible: 'Hide Teacher Instructions'
182
+ }
183
+ }, teacherInstructionsDiv) : teacherInstructionsDiv), prompt && /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
184
+ prompt: prompt
185
+ }), !alwaysShowCorrect && /*#__PURE__*/_react["default"].createElement(_correctAnswerToggle.CorrectAnswerToggle, {
186
+ show: mode === 'evaluate',
187
+ toggled: showCorrectAnswer,
188
+ onToggle: this.toggleShowCorrect,
189
+ language: language
190
+ }), /*#__PURE__*/_react["default"].createElement(_maskMarkup.ConstructedResponse, (0, _extends2["default"])({}, this.props, {
191
+ onChange: this.onChange,
192
+ showCorrectAnswer: showCorrectAnswer,
193
+ value: value,
194
+ maxLength: maxLengthPerChoice,
195
+ adjustedLimit: maxLengthPerChoiceEnabled,
196
+ spellCheck: playerSpellCheckEnabled
197
+ })), displayNote && /*#__PURE__*/_react["default"].createElement("div", {
198
+ className: (0, _classnames["default"])(classes.note, 'note'),
199
+ dangerouslySetInnerHTML: {
200
+ __html: note
201
+ }
202
+ }), rationale && (0, _renderUi.hasText)(rationale) && /*#__PURE__*/_react["default"].createElement("div", {
203
+ className: classes.collapsible
204
+ }, !animationsDisabled ? /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
205
+ labels: {
206
+ hidden: 'Show Rationale',
207
+ visible: 'Hide Rationale'
208
+ }
209
+ }, rationaleDiv) : rationaleDiv));
210
+ }
211
+ }]);
212
+ return Main;
213
+ }(_react["default"].Component);
214
+
215
+ exports.Main = Main;
216
+ (0, _defineProperty2["default"])(Main, "propTypes", {
217
+ classes: _propTypes["default"].object.isRequired,
218
+ prompt: _propTypes["default"].string,
219
+ note: _propTypes["default"].string,
220
+ showNote: _propTypes["default"].bool,
221
+ env: _propTypes["default"].object,
222
+ rationale: _propTypes["default"].string,
223
+ disabled: _propTypes["default"].bool,
224
+ displayType: _propTypes["default"].string,
225
+ markup: _propTypes["default"].string,
226
+ mode: _propTypes["default"].string,
227
+ teacherInstructions: _propTypes["default"].string,
228
+ value: _propTypes["default"].object,
229
+ feedback: _propTypes["default"].object,
230
+ onChange: _propTypes["default"].func,
231
+ alwaysShowCorrect: _propTypes["default"].bool,
232
+ animationsDisabled: _propTypes["default"].bool,
233
+ maxLengthPerChoice: _propTypes["default"].array,
234
+ maxLengthPerChoiceEnabled: _propTypes["default"].bool,
235
+ playerSpellCheckEnabled: _propTypes["default"].bool,
236
+ language: _propTypes["default"].string
237
+ });
238
+ (0, _defineProperty2["default"])(Main, "defaultProps", {
239
+ value: {}
240
+ });
241
+
242
+ var styles = function styles(theme) {
243
+ return {
244
+ mainContainer: {
245
+ color: _renderUi.color.text(),
246
+ backgroundColor: _renderUi.color.background()
247
+ },
248
+ inlineDisplay: {
249
+ display: 'inline-block'
250
+ },
251
+ blockDisplay: {
252
+ display: 'block'
253
+ },
254
+ note: {
255
+ marginBottom: theme.spacing.unit * 2
256
+ },
257
+ collapsible: {
258
+ marginBottom: theme.spacing.unit * 2
259
+ },
260
+ noBorderColor: {
261
+ '& *': {
262
+ borderColor: "".concat(_renderUi.color.text(), " !important")
263
+ }
264
+ },
265
+ srOnly: {
266
+ position: 'absolute',
267
+ left: '-10000px',
268
+ top: 'auto',
269
+ width: '1px',
270
+ height: '1px',
271
+ overflow: 'hidden'
272
+ }
273
+ };
274
+ };
275
+
276
+ var _default = (0, _styles.withStyles)(styles)(Main);
277
+
278
+ exports["default"] = _default;
279
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/main.js"],"names":["translator","Translator","Main","showCorrectAnswer","props","alwaysShowCorrect","value","maxLengthPerChoice","every","val","i","arr","onChange","maxWait","setState","state","getChangeSession","changeSession","nextProps","language","note","feedback","t","lng","classes","mode","prompt","rationale","teacherInstructions","showNote","env","animationsDisabled","maxLengthPerChoiceEnabled","displayType","playerSpellCheckEnabled","role","displayNote","mainClasses","mainContainer","noBorderColor","teacherInstructionsDiv","rationaleDiv","display","srOnly","collapsible","hidden","visible","toggleShowCorrect","__html","React","Component","PropTypes","object","isRequired","string","bool","disabled","markup","func","array","styles","theme","color","text","backgroundColor","background","inlineDisplay","blockDisplay","marginBottom","spacing","unit","borderColor","position","left","top","width","height","overflow"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAQA,UAAR,GAAuBC,sBAAvB,CAAQD,UAAR;;IAEaE,I;;;;;;;;;;;;;;;8FA4BH;AACNC,MAAAA,iBAAiB,EAAE,MAAKC,KAAL,CAAWC,iBAAX,IAAgC,KAD7C;AAENC,MAAAA,KAAK,EAAE,MAAKF,KAAL,CAAWE;AAFZ,K;yGAMW,UAACC,kBAAD;AAAA,aACjBA,kBAAkB,IAAIA,kBAAkB,CAACC,KAAnB,CAAyB,UAACC,GAAD,EAAMC,CAAN,EAASC,GAAT;AAAA,eAAiBF,GAAG,KAAKE,GAAG,CAAC,CAAD,CAAX,IAAkBF,GAAG,KAAK,CAA3C;AAAA,OAAzB,CAAtB,GACI,MAAKL,KAAL,CAAWQ,QADf,GAEI,0BAAS,MAAKR,KAAL,CAAWQ,QAApB,EAA8B,IAA9B,EAAoC;AAAEC,QAAAA,OAAO,EA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BW;AACpBI,EAAAA,KAAK,EAAE;AADa,C;;AAiJxB,IAAMsD,MAAM,GAAG,SAATA,MAAS,CAACC,KAAD;AAAA,SAAY;AACzBvB,IAAAA,aAAa,EAAE;AACbwB,MAAAA,KAAK,EAAEA,gBAAMC,IAAN,EADM;AAEbC,MAAAA,eAAe,EAAEF,gBAAMG,UAAN;AAFJ,KADU;AAKzBC,IAAAA,aAAa,EAAE;AACbxB,MAAAA,OAAO,EAAE;AADI,KALU;AAQzByB,IAAAA,YAAY,EAAE;AACZzB,MAAAA,OAAO,EAAE;AADG,KARW;AAWzBtB,IAAAA,IAAI,EAAE;AACJgD,MAAAA,YAAY,EAAEP,KAAK,CAACQ,OAAN,CAAcC,IAAd,GAAqB;AAD/B,KAXmB;AAczB1B,IAAAA,WAAW,EAAE;AACXwB,MAAAA,YAAY,EAAEP,KAAK,CAACQ,OAAN,CAAcC,IAAd,GAAqB;AADxB,KAdY;AAiBzB/B,IAAAA,aAAa,EAAE;AACb,aAAO;AACLgC,QAAAA,WAAW,YAAKT,gBAAMC,IAAN,EAAL;AADN;AADM,KAjBU;AAsBzBpB,IAAAA,MAAM,EAAE;AACN6B,MAAAA,QAAQ,EAAE,UADJ;AAENC,MAAAA,IAAI,EAAE,UAFA;AAGNC,MAAAA,GAAG,EAAE,MAHC;AAINC,MAAAA,KAAK,EAAE,KAJD;AAKNC,MAAAA,MAAM,EAAE,KALF;AAMNC,MAAAA,QAAQ,EAAE;AANJ;AAtBiB,GAAZ;AAAA,CAAf;;eAgCe,wBAAWjB,MAAX,EAAmB1D,IAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport debounce from 'lodash/debounce';\nimport isEmpty from 'lodash/isEmpty';\nimport isEqual from 'lodash/isEqual';\nimport {CorrectAnswerToggle} from '@pie-lib/pie-toolbox/correct-answer-toggle';\nimport { ConstructedResponse } from '@pie-lib/pie-toolbox/mask-markup';\nimport { color, Collapsible, hasText, PreviewPrompt } from '@pie-lib/pie-toolbox/render-ui';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport Translator from '@pie-lib/pie-toolbox/translator';\n\nconst { translator } = Translator;\n\nexport class Main extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n prompt: PropTypes.string,\n note: PropTypes.string,\n showNote: PropTypes.bool,\n env: PropTypes.object,\n rationale: PropTypes.string,\n disabled: PropTypes.bool,\n displayType: PropTypes.string,\n markup: PropTypes.string,\n mode: PropTypes.string,\n teacherInstructions: PropTypes.string,\n value: PropTypes.object,\n feedback: PropTypes.object,\n onChange: PropTypes.func,\n alwaysShowCorrect: PropTypes.bool,\n animationsDisabled: PropTypes.bool,\n maxLengthPerChoice: PropTypes.array,\n maxLengthPerChoiceEnabled: PropTypes.bool,\n playerSpellCheckEnabled: PropTypes.bool,\n language: PropTypes.string,\n };\n\n static defaultProps = {\n value: {},\n };\n\n state = {\n showCorrectAnswer: this.props.alwaysShowCorrect || false,\n value: this.props.value,\n };\n\n // if for all responses max length is 1, call onChange for each keystroke\n getChangeSession = (maxLengthPerChoice) =>\n maxLengthPerChoice && maxLengthPerChoice.every((val, i, arr) => val === arr[0] && val === 1)\n ? this.props.onChange\n : debounce(this.props.onChange, 1500, { maxWait: 1500 });\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n const { maxLengthPerChoice, language } = this.props;\n let { note } = this.props;\n\n if (isEmpty(nextProps.feedback)) {\n this.setState({ showCorrectAnswer: false });\n }\n\n if (nextProps.alwaysShowCorrect) {\n this.setState({ showCorrectAnswer: true });\n }\n\n if (maxLengthPerChoice && !isEqual(maxLengthPerChoice, nextProps.maxLengthPerChoice)) {\n this.changeSession = this.getChangeSession(nextProps.maxLengthPerChoice);\n }\n\n // check if the note is the default one for prev language and change to the default one for new language\n // this check is necessary in order to diferanciate between default and authour defined note\n // and only change between languages for default ones\n if (note && language && language !== nextProps.language &&\n note === translator.t('common:commonCorrectAnswerWithAlternates', { lng: language })) {\n note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: nextProps.language });\n }\n }\n\n toggleShowCorrect = () => {\n this.setState({ showCorrectAnswer: !this.state.showCorrectAnswer });\n };\n\n changeSession = this.getChangeSession(this.props.maxLengthPerChoice);\n\n onChange = (value) => {\n this.setState({ value });\n\n this.changeSession(value);\n };\n\n render() {\n const { showCorrectAnswer, value } = this.state;\n const {\n classes,\n mode,\n prompt,\n rationale,\n teacherInstructions,\n note,\n showNote,\n env,\n animationsDisabled,\n alwaysShowCorrect,\n maxLengthPerChoice,\n maxLengthPerChoiceEnabled,\n displayType,\n playerSpellCheckEnabled,\n language\n } = this.props;\n\n const { role } = env || {};\n const displayNote = (showCorrectAnswer || (mode === 'view' && role === 'instructor')) && showNote && note;\n const mainClasses = classNames([\n classes.mainContainer,\n {\n [classes.noBorderColor]: alwaysShowCorrect,\n },\n ]);\n\n const teacherInstructionsDiv = (\n <PreviewPrompt defaultClassName=\"teacher-instructions\" prompt={teacherInstructions} />\n );\n\n const rationaleDiv = <PreviewPrompt prompt={rationale} />;\n\n return (\n <div className={mainClasses} style={{ display: `${displayType}` }}>\n {mode === 'gather' && <h2 className={classes.srOnly}>Fill in the Blank Question</h2>}\n\n {teacherInstructions && hasText(teacherInstructions) && (\n <div className={classes.collapsible}>\n {!animationsDisabled ? (\n <Collapsible labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}>\n {teacherInstructionsDiv}\n </Collapsible>\n ) : (\n teacherInstructionsDiv\n )}\n </div>\n )}\n\n {prompt && <PreviewPrompt prompt={prompt} />}\n\n {!alwaysShowCorrect && (\n <CorrectAnswerToggle\n show={mode === 'evaluate'}\n toggled={showCorrectAnswer}\n onToggle={this.toggleShowCorrect}\n language={language}\n />\n )}\n\n <ConstructedResponse\n {...this.props}\n onChange={this.onChange}\n showCorrectAnswer={showCorrectAnswer}\n value={value}\n maxLength={maxLengthPerChoice}\n adjustedLimit={maxLengthPerChoiceEnabled}\n spellCheck={playerSpellCheckEnabled}\n />\n\n {displayNote && (\n <div\n className={classNames(classes.note, 'note')}\n dangerouslySetInnerHTML={{ __html: note }}\n />\n )}\n\n {rationale && hasText(rationale) && (\n <div className={classes.collapsible}>\n {!animationsDisabled ? (\n <Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>{rationaleDiv}</Collapsible>\n ) : (\n rationaleDiv\n )}\n </div>\n )}\n </div>\n );\n }\n}\n\nconst styles = (theme) => ({\n mainContainer: {\n color: color.text(),\n backgroundColor: color.background(),\n },\n inlineDisplay: {\n display: 'inline-block',\n },\n blockDisplay: {\n display: 'block',\n },\n note: {\n marginBottom: theme.spacing.unit * 2,\n },\n collapsible: {\n marginBottom: theme.spacing.unit * 2,\n },\n noBorderColor: {\n '& *': {\n borderColor: `${color.text()} !important`,\n },\n },\n srOnly: {\n position: 'absolute',\n left: '-10000px',\n top: 'auto',\n width: '1px',\n height: '1px',\n overflow: 'hidden',\n },\n});\n\nexport default withStyles(styles)(Main);\n"],"file":"main.js"}
package/lib/print.js ADDED
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
+
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
20
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
22
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
24
+ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _reactDom = _interopRequireDefault(require("react-dom"));
29
+
30
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
31
+
32
+ var _main = _interopRequireDefault(require("./main"));
33
+
34
+ var _mathRenderingAccessible = require("@pie-lib/pie-toolbox/math-rendering-accessible");
35
+
36
+ var _debug = _interopRequireDefault(require("debug"));
37
+
38
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
+
40
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
41
+
42
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
43
+
44
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
45
+
46
+ var log = (0, _debug["default"])('pie-element:explicit-constructed-response:print');
47
+
48
+ var preparePrintModel = function preparePrintModel(model, opts) {
49
+ var instr = opts.role === 'instructor';
50
+ model.prompt = model.promptEnabled !== false ? model.prompt : undefined;
51
+ model.teacherInstructions = instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;
52
+ model.rationale = instr && model.rationaleEnabled !== false ? model.rationale : undefined;
53
+ model.alwaysShowCorrect = instr;
54
+ model.mode = instr ? 'evaluate' : model.mode;
55
+ model.disabled = true;
56
+ model.animationsDisabled = true;
57
+ return model;
58
+ };
59
+
60
+ var ExplicitConstructedResponsePrint = /*#__PURE__*/function (_HTMLElement) {
61
+ (0, _inherits2["default"])(ExplicitConstructedResponsePrint, _HTMLElement);
62
+
63
+ var _super = _createSuper(ExplicitConstructedResponsePrint);
64
+
65
+ function ExplicitConstructedResponsePrint() {
66
+ var _this;
67
+
68
+ (0, _classCallCheck2["default"])(this, ExplicitConstructedResponsePrint);
69
+ _this = _super.call(this);
70
+ _this._options = null;
71
+ _this._model = null;
72
+ _this._session = [];
73
+ _this._rerender = (0, _debounce["default"])(function () {
74
+ if (_this._model && _this._session) {
75
+ var printModel = preparePrintModel(_this._model, _this._options);
76
+
77
+ var element = _this._options && /*#__PURE__*/_react["default"].createElement(_main["default"], _objectSpread(_objectSpread({}, printModel), {}, {
78
+ onChange: function onChange() {}
79
+ }));
80
+
81
+ _reactDom["default"].render(element, (0, _assertThisInitialized2["default"])(_this), function () {
82
+ log('render complete - render math');
83
+ (0, _mathRenderingAccessible.renderMath)((0, _assertThisInitialized2["default"])(_this));
84
+ });
85
+ } else {
86
+ log('skip');
87
+ }
88
+ }, 50, {
89
+ leading: false,
90
+ trailing: true
91
+ });
92
+ return _this;
93
+ }
94
+
95
+ (0, _createClass2["default"])(ExplicitConstructedResponsePrint, [{
96
+ key: "options",
97
+ set: function set(o) {
98
+ this._options = o;
99
+ }
100
+ }, {
101
+ key: "model",
102
+ set: function set(s) {
103
+ this._model = s;
104
+
105
+ this._rerender();
106
+ }
107
+ }, {
108
+ key: "connectedCallback",
109
+ value: function connectedCallback() {}
110
+ }]);
111
+ return ExplicitConstructedResponsePrint;
112
+ }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
113
+
114
+ exports["default"] = ExplicitConstructedResponsePrint;
115
+ //# sourceMappingURL=print.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/print.js"],"names":["log","preparePrintModel","model","opts","instr","role","prompt","promptEnabled","undefined","teacherInstructions","teacherInstructionsEnabled","rationale","rationaleEnabled","alwaysShowCorrect","mode","disabled","animationsDisabled","ExplicitConstructedResponsePrint","_options","_model","_session","_rerender","printModel","element","React","createElement","Main","onChange","ReactDOM","render","leading","trailing","o","s","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,iDAAN,CAAZ;;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,KAAD,EAAQC,IAAR,EAAiB;AACzC,MAAMC,KAAK,GAAGD,IAAI,CAACE,IAAL,KAAc,YAA5B;AAEAH,EAAAA,KAAK,CAACI,MAAN,GAAeJ,KAAK,CAACK,aAAN,KAAwB,KAAxB,GAAgCL,KAAK,CAACI,MAAtC,GAA+CE,SAA9D;AACAN,EAAAA,KAAK,CAACO,mBAAN,GACEL,KAAK,IAAIF,KAAK,CAACQ,0BAAN,KAAqC,KAA9C,GAAsDR,KAAK,CAACO,mBAA5D,GAAkFD,SADpF;AAEAN,EAAAA,KAAK,CAACS,SAAN,GAAkBP,KAAK,IAAIF,KAAK,CAACU,gBAAN,KAA2B,KAApC,GAA4CV,KAAK,CAACS,SAAlD,GAA8DH,SAAhF;AAEAN,EAAAA,KAAK,CAACW,iBAAN,GAA0BT,KAA1B;AACAF,EAAAA,KAAK,CAACY,IAAN,GAAaV,KAAK,GAAG,UAAH,GAAgBF,KAAK,CAACY,IAAxC;AAEAZ,EAAAA,KAAK,CAACa,QAAN,GAAiB,IAAjB;AACAb,EAAAA,KAAK,CAACc,kBAAN,GAA2B,IAA3B;AAEA,SAAOd,KAAP;AACD,CAfD;;IAiBqBe,gC;;;;;AACnB,8CAAc;AAAA;;AAAA;AACZ;AACA,UAAKC,QAAL,GAAgB,IAAhB;AACA,UAAKC,MAAL,GAAc,IAAd;AACA,UAAKC,QAAL,GAAgB,EAAhB;AACA,UAAKC,SAAL,GAAiB,0BACf,YAAM;AACJ,UAAI,MAAKF,MAAL,IAAe,MAAKC,QAAxB,EAAkC;AAChC,YAAME,UAAU,GAAGrB,iBAAiB,CAAC,MAAKkB,MAAN,EAAc,MAAKD,QAAnB,CAApC;;AAEA,YAAMK,OAAO,GACX,MAAKL,QAAL,iBACAM,kBAAMC,aAAN,CAAoBC,gBAApB,kCACKJ,UADL;AAEEK,UAAAA,QAAQ,EAAE,oBAAM,CAAE;AAFpB,WAFF;;AAOAC,6BAASC,MAAT,CAAgBN,OAAhB,kDAA+B,YAAM;AACnCvB,UAAAA,GAAG,CAAC,+BAAD,CAAH;AACA;AACD,SAHD;AAID,OAdD,MAcO;AACLA,QAAAA,GAAG,CAAC,MAAD,CAAH;AACD;AACF,KAnBc,EAoBf,EApBe,EAqBf;AAAE8B,MAAAA,OAAO,EAAE,KAAX;AAAkBC,MAAAA,QAAQ,EAAE;AAA5B,KArBe,CAAjB;AALY;AA4Bb;;;;SACD,aAAYC,CAAZ,EAAe;AACb,WAAKd,QAAL,GAAgBc,CAAhB;AACD;;;SAED,aAAUC,CAAV,EAAa;AACX,WAAKd,MAAL,GAAcc,CAAd;;AACA,WAAKZ,SAAL;AACD;;;WAED,6BAAoB,CAAE;;;kDAvCsCa,W","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport debounce from 'lodash/debounce';\nimport Main from './main';\nimport { renderMath } from '@pie-lib/pie-toolbox/math-rendering-accessible';\nimport debug from 'debug';\n\nconst log = debug('pie-element:explicit-constructed-response:print');\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n model.prompt = model.promptEnabled !== false ? model.prompt : undefined;\n model.teacherInstructions =\n instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;\n model.rationale = instr && model.rationaleEnabled !== false ? model.rationale : undefined;\n\n model.alwaysShowCorrect = instr;\n model.mode = instr ? 'evaluate' : model.mode;\n\n model.disabled = true;\n model.animationsDisabled = true;\n\n return model;\n};\n\nexport default class ExplicitConstructedResponsePrint extends HTMLElement {\n constructor() {\n super();\n this._options = null;\n this._model = null;\n this._session = [];\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n const printModel = preparePrintModel(this._model, this._options);\n\n const element =\n this._options &&\n React.createElement(Main, {\n ...printModel,\n onChange: () => {},\n });\n\n ReactDOM.render(element, this, () => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n set options(o) {\n this._options = o;\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n }\n\n connectedCallback() {}\n}\n"],"file":"print.js"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "repository": "pie-framework/pie-elements",
7
- "version": "6.12.1-next.1+b15abe678",
7
+ "version": "6.12.1-next.11+347beebe7",
8
8
  "description": "",
9
9
  "scripts": {
10
10
  "postpublish": "../../scripts/postpublish"
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "author": "",
23
23
  "license": "ISC",
24
- "gitHead": "b15abe678bf81101440641728f578317e11a58c1",
24
+ "gitHead": "347beebe7a41434553edf124bb6a45ba139e5064",
25
25
  "main": "lib/index.js",
26
26
  "module": "src/index.js",
27
27
  "exports": {