@pie-element/rubric 1.6.2 → 1.6.3-next.1008

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/src/main.jsx CHANGED
@@ -27,6 +27,7 @@ class Rubric extends React.Component {
27
27
 
28
28
  static propTypes = {
29
29
  classes: PropTypes.object.isRequired,
30
+ animationsDisabled: PropTypes.bool,
30
31
  value: RubricType,
31
32
  };
32
33
 
@@ -44,51 +45,60 @@ class Rubric extends React.Component {
44
45
  };
45
46
 
46
47
  render() {
47
- const { value, classes } = this.props;
48
+ const { value, classes, animationsDisabled } = this.props;
49
+
48
50
  if (value && value.points) {
49
51
  const { points, sampleAnswers } = value;
50
52
 
53
+ const rubricList = <List component="nav">
54
+ {points.slice(0).reverse().map(
55
+ (desc, index) => {
56
+ index = points.length - index - 1;
57
+ return this.shouldRenderPoint(index, value) && (
58
+ <React.Fragment key={index}>
59
+ <ListItem key={`P${index}`}>
60
+ <ListItemText
61
+ className={classes.rubricCol}
62
+ primary={index === 1 ? `${index} PT` : `${index} PTS`}
63
+ />
64
+ <ListItemText
65
+ primary={
66
+ <div dangerouslySetInnerHTML={{ __html: desc }} />
67
+ }
68
+ />
69
+ </ListItem>
70
+ {sampleAnswers && sampleAnswers[index] && (
71
+ <ListItem key={`S${index}`}>
72
+ <ListItemText
73
+ className={classes.rubricCol}
74
+ style={{marginLeft: '20px'}}
75
+ primary={'Sample Answer'}
76
+ />
77
+ <ListItemText
78
+ primary={
79
+ <div dangerouslySetInnerHTML={{ __html: sampleAnswers[index] }} />
80
+ }
81
+ />
82
+ </ListItem>
83
+ )}
84
+ </React.Fragment>
85
+ )
86
+ })}
87
+ </List>;
88
+
51
89
  return (
52
90
  <div className={classes.root}>
53
- <Link href={this.dudUrl} onClick={this.toggleRubric}>
54
- {this.state.linkPrefix} Rubric
55
- </Link>
56
- <Collapse in={this.state.rubricOpen} timeout="auto">
57
- <List component="nav">
58
- {points.map(
59
- (desc, index) =>
60
- this.shouldRenderPoint(index, value) && (
61
- <React.Fragment key={index}>
62
- <ListItem key={`P${index}`}>
63
- <ListItemText
64
- className={classes.rubricCol}
65
- primary={`${index} PTS`}
66
- />
67
- <ListItemText
68
- primary={
69
- <div dangerouslySetInnerHTML={{ __html: desc }} />
70
- }
71
- />
72
- </ListItem>
73
- {sampleAnswers && sampleAnswers[index] && (
74
- <ListItem key={`S${index}`}>
75
- <ListItemText
76
- className={classes.rubricCol}
77
- style={{marginLeft: '20px'}}
78
- primary={'Sample Answer'}
79
- />
80
- <ListItemText
81
- primary={
82
- <div dangerouslySetInnerHTML={{ __html: sampleAnswers[index] }} />
83
- }
84
- />
85
- </ListItem>
86
- )}
87
- </React.Fragment>
88
- )
89
- )}
90
- </List>
91
- </Collapse>
91
+ {!animationsDisabled ?
92
+ <React.Fragment>
93
+ <Link href={this.dudUrl} onClick={this.toggleRubric}>
94
+ {this.state.linkPrefix} Rubric
95
+ </Link>
96
+ <Collapse in={this.state.rubricOpen} timeout="auto">
97
+ {rubricList}
98
+ </Collapse>
99
+ </React.Fragment>
100
+ : rubricList
101
+ }
92
102
  </div>
93
103
  );
94
104
  } else {
@@ -100,6 +110,7 @@ class Rubric extends React.Component {
100
110
  const styles = () => ({
101
111
  rubricCol: {
102
112
  flex: '0 1 auto',
113
+ minWidth: 'fit-content'
103
114
  },
104
115
  });
105
116
 
package/src/print.js ADDED
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import debounce from 'lodash/debounce';
4
+ import Main from './main';
5
+ import { renderMath } from '@pie-lib/math-rendering';
6
+ import debug from 'debug';
7
+
8
+ const log = debug('pie-element:rubric:print');
9
+
10
+ const preparePrintModel = (model, opts) => {
11
+ const instr = opts.role === 'instructor';
12
+
13
+ if (!instr) {
14
+ return {};
15
+ }
16
+
17
+ model.value = { ...model };
18
+ model.mode = 'evaluate';
19
+ model.animationsDisabled = true;
20
+
21
+ return model;
22
+ };
23
+
24
+ export default class RubricPrint extends HTMLElement {
25
+ constructor() {
26
+ super();
27
+ this._options = null;
28
+ this._model = null;
29
+ this._session = [];
30
+ this._rerender = debounce(
31
+ () => {
32
+ if (this._model && this._session) {
33
+ const printModel = preparePrintModel(this._model, this._options);
34
+
35
+ const element =
36
+ this._options &&
37
+ React.createElement(Main, {
38
+ ...printModel,
39
+ });
40
+
41
+ ReactDOM.render(element, this, () => {
42
+ log('render complete - render math');
43
+ renderMath(this);
44
+ });
45
+ } else {
46
+ log('skip');
47
+ }
48
+ },
49
+ 50,
50
+ { leading: false, trailing: true }
51
+ );
52
+ }
53
+ set options(o) {
54
+ this._options = o;
55
+ }
56
+
57
+ set model(s) {
58
+ this._model = s;
59
+ this._rerender();
60
+ }
61
+
62
+ connectedCallback() {}
63
+ }