@pie-element/rubric 3.5.1-next.13 → 3.5.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.
@@ -0,0 +1,412 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { withStyles } from '@material-ui/core/styles';
4
+ import classNames from 'classnames';
5
+ import OutlinedInput from '@material-ui/core/OutlinedInput';
6
+ import InputLabel from '@material-ui/core/InputLabel';
7
+ import Select from '@material-ui/core/Select';
8
+ import FormControl from '@material-ui/core/FormControl';
9
+ import MenuItem from '@material-ui/core/MenuItem';
10
+ import times from 'lodash/times';
11
+ import Checkbox from '@material-ui/core/Checkbox';
12
+ import FormGroup from '@material-ui/core/FormGroup';
13
+ import FormControlLabel from '@material-ui/core/FormControlLabel';
14
+ import grey from '@material-ui/core/colors/grey';
15
+ import Typography from '@material-ui/core/Typography';
16
+ import DragIndicator from '@material-ui/icons/DragIndicator';
17
+ import EditableHtml from '@pie-lib/pie-toolbox/editable-html';
18
+ import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
19
+ import debug from 'debug';
20
+ import takeRight from 'lodash/takeRight';
21
+ import PointMenu from './point-menu';
22
+
23
+ import range from 'lodash/range';
24
+ import { InputContainer } from '@pie-lib/pie-toolbox/config-ui';
25
+
26
+ const log = debug('pie-lib:rubric:authoring');
27
+
28
+ const reorder = (list, startIndex, endIndex) => {
29
+ const result = Array.from(list);
30
+ const [removed] = result.splice(startIndex, 1);
31
+
32
+ result.splice(endIndex, 0, removed);
33
+
34
+ return result;
35
+ };
36
+
37
+ export const RubricType = PropTypes.shape({
38
+ excludeZero: PropTypes.bool,
39
+ points: PropTypes.arrayOf(PropTypes.string),
40
+ sampleAnswers: PropTypes.arrayOf(PropTypes.string),
41
+ maxPoints: PropTypes.number,
42
+ rubriclessInstruction: PropTypes.string,
43
+ });
44
+
45
+ const MaxPoints = withStyles((theme) => ({
46
+ formControl: {
47
+ minWidth: '120px',
48
+ margin: theme.spacing.unit,
49
+ },
50
+ }))((props) => {
51
+ const { value, onChange, max, classes } = props;
52
+
53
+ return (
54
+ <FormControl className={classes.formControl} variant="outlined">
55
+ <InputLabel width={100} htmlFor="...">
56
+ Max Points
57
+ </InputLabel>
58
+ <Select value={value} onChange={(e) => onChange(e.target.value)} input={<OutlinedInput labelWidth={80} />}>
59
+ {range(1, max + 1).map((v) => (
60
+ <MenuItem key={`${v}`} value={v}>
61
+ {v}
62
+ </MenuItem>
63
+ ))}
64
+ </Select>
65
+ </FormControl>
66
+ );
67
+ });
68
+
69
+ // if the value is null or 'null', the Sample Answer input field for that point will not be dispalyed
70
+ // if the value is '', the Sample Answer input field will be empty
71
+ const checkSampleAnswer = (sampleAnswer) => sampleAnswer === null || sampleAnswer === 'null';
72
+
73
+ export const PointConfig = withStyles((theme) => ({
74
+ pointConfig: {},
75
+ row: {
76
+ display: 'flex',
77
+ width: '100%',
78
+ position: 'relative',
79
+ },
80
+ editor: {
81
+ width: '100%',
82
+ backgroundColor: `${theme.palette.common.white} !important`,
83
+ },
84
+ dragIndicator: {
85
+ paddingTop: theme.spacing.unit,
86
+ color: grey[500],
87
+ },
88
+ pointsLabel: {
89
+ color: grey[500],
90
+ paddingBottom: theme.spacing.unit,
91
+ textTransform: 'uppercase',
92
+ },
93
+ sampleAnswersEditor: {
94
+ paddingLeft: theme.spacing.unit * 3,
95
+ },
96
+ pointMenu: {
97
+ position: 'absolute',
98
+ right: 0,
99
+ },
100
+ errorText: {
101
+ fontSize: theme.typography.fontSize - 2,
102
+ color: theme.palette.error.main,
103
+ paddingLeft: theme.spacing.unit * 3,
104
+ paddingTop: theme.spacing.unit,
105
+ },
106
+ }))((props) => {
107
+ const { points, content, classes, sampleAnswer, mathMlOptions = {}, error, pluginOpts = {}, excludeZero } = props;
108
+ const pointsCount = excludeZero ? points + 1 : points;
109
+ const pointsLabel = `${pointsCount} ${pointsCount <= 1 ? 'pt' : 'pts'}`;
110
+ const showSampleAnswer = checkSampleAnswer(sampleAnswer);
111
+
112
+ return (
113
+ <div className={classes.pointConfig}>
114
+ <Typography variant="overline" className={classes.pointsLabel}>
115
+ {pointsLabel}
116
+ </Typography>
117
+
118
+ <div className={classes.row}>
119
+ <DragIndicator className={classes.dragIndicator} />
120
+ <EditableHtml
121
+ className={classes.editor}
122
+ error={error}
123
+ pluginProps={pluginOpts}
124
+ markup={content}
125
+ onChange={props.onChange}
126
+ mathMlOptions={mathMlOptions}
127
+ />
128
+ <PointMenu
129
+ classes={{
130
+ icon: classes.pointMenu,
131
+ }}
132
+ showSampleAnswer={showSampleAnswer}
133
+ onChange={props.onMenuChange}
134
+ />
135
+ </div>
136
+ {error && <div className={classes.errorText}>{error}</div>}
137
+ {!showSampleAnswer && (
138
+ <div className={classes.sampleAnswersEditor}>
139
+ <Typography variant="overline" className={classes.dragIndicator}>
140
+ Sample Response
141
+ </Typography>
142
+ <EditableHtml
143
+ className={classes.editor}
144
+ markup={sampleAnswer}
145
+ pluginProps={pluginOpts}
146
+ onChange={props.onSampleChange}
147
+ mathMlOptions={mathMlOptions}
148
+ />
149
+ </div>
150
+ )}
151
+ </div>
152
+ );
153
+ });
154
+
155
+ export class RawAuthoring extends React.Component {
156
+ static propTypes = {
157
+ classes: PropTypes.object.isRequired,
158
+ className: PropTypes.string,
159
+ value: RubricType,
160
+ config: PropTypes.object,
161
+ pluginOpts: PropTypes.object,
162
+ rubricless: PropTypes.bool,
163
+ onChange: PropTypes.func,
164
+ };
165
+
166
+ static defaultProps = {};
167
+
168
+ dragEnd = (result) => {
169
+ if (!result.destination) {
170
+ return;
171
+ }
172
+
173
+ const { value, onChange } = this.props;
174
+
175
+ const points = reorder(value.points, result.source.index, result.destination.index);
176
+ const sampleAnswers = reorder(value.sampleAnswers, result.source.index, result.destination.index);
177
+
178
+ onChange({ ...value, points, sampleAnswers });
179
+ };
180
+
181
+ changeRubriclessInstruction = (input) => {
182
+ const { value, onChange } = this.props;
183
+ onChange({ ...value, rubriclessInstruction: input });
184
+ };
185
+
186
+ changeMaxPoints = (maxPoints) => {
187
+ const { value, onChange } = this.props;
188
+
189
+ onChange({ ...value, maxPoints });
190
+ };
191
+
192
+ changeContent = (index, content, type) => {
193
+ // type could be 'points' or 'sampleAnswers'
194
+ log(`changeModel[${type}]:`, index, content);
195
+
196
+ if (type !== 'points' && type !== 'sampleAnswers') {
197
+ return;
198
+ }
199
+
200
+ const { value, onChange } = this.props;
201
+ const items = value[type] && Array.from(value[type]);
202
+
203
+ items.splice(index, 1, content);
204
+ log(`changeModel[${type}]:`, items);
205
+
206
+ onChange({ ...value, [type]: items });
207
+ };
208
+
209
+ excludeZeros = () => {
210
+ const { value, onChange } = this.props;
211
+
212
+ onChange({ ...value, excludeZero: !value.excludeZero });
213
+ };
214
+
215
+ onPointMenuChange = (index, clickedItem) => {
216
+ if (clickedItem === 'sample') {
217
+ const { value } = this.props;
218
+ const sampleAnswers = Array.from(value.sampleAnswers || []);
219
+
220
+ if (checkSampleAnswer(sampleAnswers[index])) {
221
+ // an empty string will display an empty Sample Answer input field
222
+ this.changeContent(index, '', 'sampleAnswers');
223
+ } else {
224
+ // when the content is null or 'null', the Sample Answer input field will not be displayed
225
+ this.changeContent(index, null, 'sampleAnswers');
226
+ }
227
+ }
228
+ };
229
+
230
+ render() {
231
+ const {
232
+ classes,
233
+ className,
234
+ value,
235
+ mathMlOptions = {},
236
+ config = {},
237
+ rubricless = false,
238
+ pluginOpts = {},
239
+ } = this.props;
240
+ let {
241
+ excludeZeroEnabled = true,
242
+ maxPointsEnabled = true,
243
+ errors = {},
244
+ rubriclessInstructionEnabled = false,
245
+ maxPoints = 10,
246
+ } = value || {};
247
+ // rubric will contain a max value for maxPoints
248
+ const { rubriclessInstruction = {}, maxMaxPoints = 10 } = config || {};
249
+ const { pointsDescriptorsErrors } = errors || {};
250
+ if (value && Number.isFinite(value.maxPoints)) {
251
+ // eslint-disable-next-line no-console
252
+ console.warn('maxPoints is deprecated - remove from model');
253
+ }
254
+
255
+ // for rubric value is computed based on points
256
+ const maxPointsValue = maxPoints;
257
+
258
+ return (
259
+ <div className={classNames(classes.class, className)}>
260
+ <Typography variant="h5" className={classes.rubricTitle}>
261
+ Rubric
262
+ </Typography>
263
+ <FormGroup row>
264
+ {maxPointsEnabled && (
265
+ <MaxPoints
266
+ max={maxMaxPoints < 100 ? maxMaxPoints : 100}
267
+ value={maxPointsValue}
268
+ onChange={this.changeMaxPoints}
269
+ pluginOpts={pluginOpts}
270
+ />
271
+ )}
272
+ {excludeZeroEnabled && (
273
+ <FormControlLabel
274
+ label="Exclude zeros"
275
+ control={<Checkbox checked={value.excludeZero} onChange={this.excludeZeros} />}
276
+ />
277
+ )}
278
+ </FormGroup>
279
+
280
+ {rubriclessInstructionEnabled && rubricless && (
281
+ <InputContainer label={rubriclessInstruction.label} className={classes.inputContainer}>
282
+ <EditableHtml
283
+ className={classes.input}
284
+ markup={value.rubriclessInstruction || ''}
285
+ onChange={this.changeRubriclessInstruction}
286
+ pluginProps={pluginOpts}
287
+ nonEmpty={false}
288
+ disableUnderline
289
+ languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}
290
+ mathMlOptions={mathMlOptions}
291
+ />
292
+ </InputContainer>
293
+ )}
294
+
295
+ <div className={rubricless ? classes.rubricless : classes.container}>
296
+ <DragDropContext onDragEnd={this.dragEnd}>
297
+ <Droppable droppableId="droppable">
298
+ {(provided) => (
299
+ <div {...provided.droppableProps} ref={provided.innerRef}>
300
+ {value.points.map(
301
+ (p, index) => {
302
+ return (
303
+ <Draggable key={`${p.points}-${index}`} index={index} draggableId={index.toString()}>
304
+ {(provided) => (
305
+ <div
306
+ className={classes.configHolder}
307
+ ref={provided.innerRef}
308
+ {...provided.draggableProps}
309
+ {...provided.dragHandleProps}
310
+ >
311
+ <PointConfig
312
+ points={value.points.length - 1 - index}
313
+ content={p}
314
+ error={
315
+ pointsDescriptorsErrors && pointsDescriptorsErrors[value.points.length - 1 - index]
316
+ }
317
+ sampleAnswer={value.sampleAnswers && value.sampleAnswers[index]}
318
+ onChange={(content) => this.changeContent(index, content, 'points')}
319
+ onSampleChange={(content) => this.changeContent(index, content, 'sampleAnswers')}
320
+ onMenuChange={(clickedItem) => this.onPointMenuChange(index, clickedItem)}
321
+ mathMlOptions={mathMlOptions}
322
+ pluginOpts={pluginOpts}
323
+ excludeZero={value.excludeZero}
324
+ />
325
+ </div>
326
+ )}
327
+ </Draggable>
328
+ );
329
+ },
330
+ )}
331
+ {provided.placeholder}
332
+ </div>
333
+ )}
334
+ </Droppable>
335
+ </DragDropContext>
336
+ </div>
337
+ </div>
338
+ );
339
+ }
340
+ }
341
+
342
+ const styles = (theme) => ({
343
+ container: {
344
+ backgroundColor: grey[200],
345
+ borderWidth: 1,
346
+ borderStyle: 'solid',
347
+ borderColor: grey[300],
348
+ padding: theme.spacing.unit * 2,
349
+ margin: theme.spacing.unit,
350
+ },
351
+ inputContainer: {
352
+ width: '100%',
353
+ paddingTop: theme.spacing.unit * 2,
354
+ marginBottom: theme.spacing.unit * 2,
355
+ },
356
+ rubricless: {
357
+ display: 'none',
358
+ },
359
+ configHolder: {
360
+ paddingTop: theme.spacing.unit,
361
+ paddingBottom: theme.spacing.unit,
362
+ },
363
+ rubricTitle: {
364
+ paddingLeft: theme.spacing.unit,
365
+ margin: theme.spacing.unit,
366
+ },
367
+ });
368
+
369
+ const StyledRawAuthoring = withStyles(styles)(RawAuthoring);
370
+
371
+ const Reverse = (props) => {
372
+ const { rubricless = false, config = {}, pluginOpts = {} } = props || {};
373
+ const points = Array.from(props.value.points || []).reverse();
374
+ let sampleAnswers = Array.from(props.value.sampleAnswers || []).reverse();
375
+
376
+ if (points.length > sampleAnswers.length) {
377
+ sampleAnswers = times(points.length - sampleAnswers.length)
378
+ .map(() => null)
379
+ .concat(sampleAnswers);
380
+ }
381
+
382
+ const value = { ...props.value, points, sampleAnswers };
383
+
384
+ const onChange = (value) => {
385
+ props.onChange({
386
+ ...value,
387
+ points: Array.from(value.points || []).reverse(),
388
+ sampleAnswers: Array.from(value.sampleAnswers || []).reverse(),
389
+ });
390
+ };
391
+
392
+ return (
393
+ <StyledRawAuthoring
394
+ value={value}
395
+ config={config}
396
+ onChange={onChange}
397
+ rubricless={rubricless}
398
+ pluginOpts={pluginOpts}
399
+ />
400
+ );
401
+ };
402
+
403
+ Reverse.propTypes = {
404
+ value: RubricType,
405
+ config: PropTypes.object,
406
+ pluginOpts: PropTypes.object,
407
+ rubricless: PropTypes.bool,
408
+ getIndex: PropTypes.func,
409
+ onChange: PropTypes.func,
410
+ };
411
+
412
+ export default Reverse;
@@ -0,0 +1,9 @@
1
+ import Authoring from './authoring';
2
+
3
+ const RUBRIC_TYPES = {
4
+ SIMPLE_RUBRIC: 'simpleRubric',
5
+ MULTI_TRAIT_RUBRIC: 'multiTraitRubric',
6
+ RUBRICLESS: 'rubricless',
7
+ };
8
+
9
+ export { Authoring, RUBRIC_TYPES };
@@ -0,0 +1,94 @@
1
+ import Menu from '@material-ui/core/Menu';
2
+ import MenuItem from '@material-ui/core/MenuItem';
3
+ import MoreVertIcon from '@material-ui/icons/MoreVert';
4
+ import MoreHorizIcon from '@material-ui/icons/MoreHoriz';
5
+ import IconButton from '@material-ui/core/IconButton';
6
+ import PropTypes from 'prop-types';
7
+ import React from 'react';
8
+
9
+ export class IconMenu extends React.Component {
10
+ static propTypes = {
11
+ opts: PropTypes.object,
12
+ onClick: PropTypes.func.isRequired,
13
+ classes: PropTypes.object.isRequired,
14
+ };
15
+
16
+ constructor(props) {
17
+ super(props);
18
+ this.state = {
19
+ anchorEl: undefined,
20
+ open: false,
21
+ };
22
+ }
23
+
24
+ handleClick = (event) => this.setState({ open: true, anchorEl: event.currentTarget });
25
+
26
+ handleRequestClose = () => this.setState({ open: false });
27
+
28
+ render() {
29
+ const { opts, onClick, classes } = this.props;
30
+ const { open, anchorEl } = this.state;
31
+ const keys = Object.keys(opts) || [];
32
+
33
+ const handleMenuClick = (key) => () => {
34
+ onClick(key);
35
+ this.handleRequestClose();
36
+ };
37
+
38
+ const iconColor = open ? 'inherit' : 'disabled';
39
+
40
+ return (
41
+ <div>
42
+ <div onClick={this.handleClick}>
43
+ <IconButton className={classes.icon}>
44
+ {open ? <MoreVertIcon color={iconColor} /> : <MoreHorizIcon color={iconColor} />}
45
+ </IconButton>
46
+ </div>
47
+ <Menu
48
+ id="point-menu"
49
+ anchorEl={anchorEl}
50
+ open={open}
51
+ onClose={this.handleRequestClose}
52
+ style={{ transform: 'translate(-15px, -15px)' }}
53
+ transformOrigin={{
54
+ vertical: 'center',
55
+ horizontal: 'right',
56
+ }}
57
+ >
58
+ {keys.map((k, index) => (
59
+ <MenuItem key={index} onClick={handleMenuClick(k)}>
60
+ {opts[k]}
61
+ </MenuItem>
62
+ ))}
63
+ </Menu>
64
+ </div>
65
+ );
66
+ }
67
+ }
68
+
69
+ export default class PointMenu extends React.Component {
70
+ static propTypes = {
71
+ onChange: PropTypes.func.isRequired,
72
+ classes: PropTypes.object.isRequired,
73
+ showSampleAnswer: PropTypes.bool.isRequired,
74
+ };
75
+
76
+ static defaultProps = {
77
+ classes: {},
78
+ };
79
+
80
+ render() {
81
+ const { onChange, classes, showSampleAnswer } = this.props;
82
+ const sampleText = showSampleAnswer ? 'Provide Sample Response' : 'Remove Sample Response';
83
+
84
+ return (
85
+ <IconMenu
86
+ onClick={(key) => onChange(key)}
87
+ opts={{
88
+ sample: sampleText,
89
+ }}
90
+ classes={classes}
91
+ />
92
+ );
93
+ }
94
+ }
@@ -7,7 +7,7 @@
7
7
  "test": "./node_modules/.bin/jest"
8
8
  },
9
9
  "dependencies": {
10
- "@pie-lib/pie-toolbox": "1.12.0",
10
+ "@pie-lib/pie-toolbox": "1.11.1",
11
11
  "lodash": "^4.17.15"
12
12
  }
13
13
  }
package/lib/print.js CHANGED
@@ -31,7 +31,7 @@ var _debounce = _interopRequireDefault(require("lodash/debounce"));
31
31
 
32
32
  var _main = _interopRequireDefault(require("./main"));
33
33
 
34
- var _mathRenderingAccessible = require("@pie-lib/pie-toolbox/math-rendering-accessible");
34
+ var _mathRendering = require("@pie-lib/pie-toolbox/math-rendering");
35
35
 
36
36
  var _debug = _interopRequireDefault(require("debug"));
37
37
 
@@ -79,7 +79,7 @@ var RubricPrint = /*#__PURE__*/function (_HTMLElement) {
79
79
 
80
80
  _reactDom["default"].render(element, (0, _assertThisInitialized2["default"])(_this), function () {
81
81
  log('render complete - render math');
82
- (0, _mathRenderingAccessible.renderMath)((0, _assertThisInitialized2["default"])(_this));
82
+ (0, _mathRendering.renderMath)((0, _assertThisInitialized2["default"])(_this));
83
83
  });
84
84
  } else {
85
85
  log('skip');
package/lib/print.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/print.js"],"names":["log","preparePrintModel","model","opts","instr","role","value","mode","animationsDisabled","RubricPrint","_options","_model","_session","_rerender","printModel","element","React","createElement","Main","ReactDOM","render","leading","trailing","o","s","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,0BAAN,CAAZ;;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,KAAD,EAAQC,IAAR,EAAiB;AACzC,MAAMC,KAAK,GAAGD,IAAI,CAACE,IAAL,KAAc,YAA5B;;AAEA,MAAI,CAACD,KAAL,EAAY;AACV,WAAO,EAAP;AACD;;AAEDF,EAAAA,KAAK,CAACI,KAAN,qBAAmBJ,KAAnB;AACAA,EAAAA,KAAK,CAACK,IAAN,GAAa,UAAb;AACAL,EAAAA,KAAK,CAACM,kBAAN,GAA2B,IAA3B;AAEA,SAAON,KAAP;AACD,CAZD;;IAcqBO,W;;;;;AACnB,yBAAc;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,GAAGb,iBAAiB,CAAC,MAAKU,MAAN,EAAc,MAAKD,QAAnB,CAApC;;AAEA,YAAMK,OAAO,GACX,MAAKL,QAAL,iBACAM,kBAAMC,aAAN,CAAoBC,gBAApB,oBACKJ,UADL,EAFF;;AAMAK,6BAASC,MAAT,CAAgBL,OAAhB,kDAA+B,YAAM;AACnCf,UAAAA,GAAG,CAAC,+BAAD,CAAH;AACA;AACD,SAHD;AAID,OAbD,MAaO;AACLA,QAAAA,GAAG,CAAC,MAAD,CAAH;AACD;AACF,KAlBc,EAmBf,EAnBe,EAoBf;AAAEqB,MAAAA,OAAO,EAAE,KAAX;AAAkBC,MAAAA,QAAQ,EAAE;AAA5B,KApBe,CAAjB;AALY;AA2Bb;;;;SACD,aAAYC,CAAZ,EAAe;AACb,WAAKb,QAAL,GAAgBa,CAAhB;AACD;;;SAED,aAAUC,CAAV,EAAa;AACX,WAAKb,MAAL,GAAca,CAAd;;AACA,WAAKX,SAAL;AACD;;;WAED,6BAAoB,CAAE;;;kDAtCiBY,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:rubric:print');\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n if (!instr) {\n return {};\n }\n\n model.value = { ...model };\n model.mode = 'evaluate';\n model.animationsDisabled = true;\n\n return model;\n};\n\nexport default class RubricPrint 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 });\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"}
1
+ {"version":3,"sources":["../src/print.js"],"names":["log","preparePrintModel","model","opts","instr","role","value","mode","animationsDisabled","RubricPrint","_options","_model","_session","_rerender","printModel","element","React","createElement","Main","ReactDOM","render","leading","trailing","o","s","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,0BAAN,CAAZ;;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,KAAD,EAAQC,IAAR,EAAiB;AACzC,MAAMC,KAAK,GAAGD,IAAI,CAACE,IAAL,KAAc,YAA5B;;AAEA,MAAI,CAACD,KAAL,EAAY;AACV,WAAO,EAAP;AACD;;AAEDF,EAAAA,KAAK,CAACI,KAAN,qBAAmBJ,KAAnB;AACAA,EAAAA,KAAK,CAACK,IAAN,GAAa,UAAb;AACAL,EAAAA,KAAK,CAACM,kBAAN,GAA2B,IAA3B;AAEA,SAAON,KAAP;AACD,CAZD;;IAcqBO,W;;;;;AACnB,yBAAc;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,GAAGb,iBAAiB,CAAC,MAAKU,MAAN,EAAc,MAAKD,QAAnB,CAApC;;AAEA,YAAMK,OAAO,GACX,MAAKL,QAAL,iBACAM,kBAAMC,aAAN,CAAoBC,gBAApB,oBACKJ,UADL,EAFF;;AAMAK,6BAASC,MAAT,CAAgBL,OAAhB,kDAA+B,YAAM;AACnCf,UAAAA,GAAG,CAAC,+BAAD,CAAH;AACA;AACD,SAHD;AAID,OAbD,MAaO;AACLA,QAAAA,GAAG,CAAC,MAAD,CAAH;AACD;AACF,KAlBc,EAmBf,EAnBe,EAoBf;AAAEqB,MAAAA,OAAO,EAAE,KAAX;AAAkBC,MAAAA,QAAQ,EAAE;AAA5B,KApBe,CAAjB;AALY;AA2Bb;;;;SACD,aAAYC,CAAZ,EAAe;AACb,WAAKb,QAAL,GAAgBa,CAAhB;AACD;;;SAED,aAAUC,CAAV,EAAa;AACX,WAAKb,MAAL,GAAca,CAAd;;AACA,WAAKX,SAAL;AACD;;;WAED,6BAAoB,CAAE;;;kDAtCiBY,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';\nimport debug from 'debug';\n\nconst log = debug('pie-element:rubric:print');\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n if (!instr) {\n return {};\n }\n\n model.value = { ...model };\n model.mode = 'evaluate';\n model.animationsDisabled = true;\n\n return model;\n};\n\nexport default class RubricPrint 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 });\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"}