@pie-element/drawing-response 6.0.1-next.6 → 6.0.1-next.66

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.
@@ -17,7 +17,7 @@ export class DrawableMain extends React.Component {
17
17
  this.state = {
18
18
  drawables: [],
19
19
  newDrawable: [],
20
- textIsSelected: false
20
+ textIsSelected: false,
21
21
  };
22
22
  }
23
23
 
@@ -29,27 +29,20 @@ export class DrawableMain extends React.Component {
29
29
  if (nextProps.session.drawables) {
30
30
  const newDrawables = cloneDeep(nextProps.session.drawables);
31
31
  const drawablesString = JSON.stringify(currentDrawables);
32
- const sessionDrawableString = JSON.stringify(
33
- (newDrawables || []).map(drawable => omit(drawable, 'type'))
34
- );
32
+ const sessionDrawableString = JSON.stringify((newDrawables || []).map((drawable) => omit(drawable, 'type')));
35
33
 
36
34
  if (drawablesString !== sessionDrawableString) {
37
35
  const drawableArray = nextProps.session.drawables;
38
36
 
39
37
  this.setState({
40
- drawables: drawableArray.map(drawable =>
41
- factory(drawable.type, drawable)
42
- )
38
+ drawables: drawableArray.map((drawable) => factory(drawable.type, drawable)),
43
39
  });
44
40
  }
45
41
 
46
- const currentTexts = TextEntry.all.map(text => ({
42
+ const currentTexts = TextEntry.all.map((text) => ({
47
43
  ...text,
48
- ...(TextEntry[`text_${text.id}`] &&
49
- TextEntry[`text_${text.id}`].attrs),
50
- value:
51
- TextEntry[`textarea_${text.id}`] &&
52
- TextEntry[`textarea_${text.id}`].value
44
+ ...(TextEntry[`text_${text.id}`] && TextEntry[`text_${text.id}`].attrs),
45
+ value: TextEntry[`textarea_${text.id}`] && TextEntry[`textarea_${text.id}`].value,
53
46
  }));
54
47
 
55
48
  if (!isEqual(currentTexts, nextProps.session.texts)) {
@@ -66,20 +59,18 @@ export class DrawableMain extends React.Component {
66
59
  const { drawables } = this.state;
67
60
 
68
61
  const newSession = {
69
- drawables: drawables.map(d => d.toJson()),
70
- texts: TextEntry.all.map(text => ({
62
+ drawables: drawables.map((d) => d.toJson()),
63
+ texts: TextEntry.all.map((text) => ({
71
64
  ...text,
72
65
  ...(TextEntry[`text_${text.id}`] && TextEntry[`text_${text.id}`].attrs),
73
- value:
74
- TextEntry[`textarea_${text.id}`] &&
75
- TextEntry[`textarea_${text.id}`].value
76
- }))
66
+ value: TextEntry[`textarea_${text.id}`] && TextEntry[`textarea_${text.id}`].value,
67
+ })),
77
68
  };
78
69
 
79
70
  if (!isEqual(newSession, session)) {
80
71
  onSessionChange({
81
72
  ...session,
82
- ...newSession
73
+ ...newSession,
83
74
  });
84
75
  }
85
76
  };
@@ -88,7 +79,7 @@ export class DrawableMain extends React.Component {
88
79
 
89
80
  onMouseOutElement = () => this.setState({ isOver: false });
90
81
 
91
- handleMouseDown = e => {
82
+ handleMouseDown = (e) => {
92
83
  // ONLY IF MOBILE?
93
84
  document.body.style.overflow = 'hidden';
94
85
 
@@ -103,16 +94,16 @@ export class DrawableMain extends React.Component {
103
94
  starty: y / scale,
104
95
  fillColor,
105
96
  outlineColor,
106
- createdAt: new Date()
97
+ createdAt: new Date(),
107
98
  });
108
99
 
109
100
  this.setState({
110
- newDrawable: [newDrawable]
101
+ newDrawable: [newDrawable],
111
102
  });
112
103
  }
113
104
  };
114
105
 
115
- handleMouseUp = e => {
106
+ handleMouseUp = (e) => {
116
107
  // ONLY IF MOBILE?
117
108
  document.body.style.overflow = 'initial';
118
109
 
@@ -129,14 +120,14 @@ export class DrawableMain extends React.Component {
129
120
  this.setState(
130
121
  {
131
122
  newDrawable: [],
132
- drawables
123
+ drawables,
133
124
  },
134
- this.handleSessionChange.bind(this, drawableToAdd)
125
+ this.handleSessionChange.bind(this, drawableToAdd),
135
126
  );
136
127
  }
137
128
  };
138
129
 
139
- handleMouseMove = e => {
130
+ handleMouseMove = (e) => {
140
131
  const { newDrawable } = this.state;
141
132
  const { scale } = this.props;
142
133
 
@@ -147,7 +138,7 @@ export class DrawableMain extends React.Component {
147
138
  updatedNewDrawable.registerMovement(x / scale, y / scale);
148
139
 
149
140
  this.setState({
150
- newDrawable: [updatedNewDrawable]
141
+ newDrawable: [updatedNewDrawable],
151
142
  });
152
143
  }
153
144
  };
@@ -175,13 +166,10 @@ export class DrawableMain extends React.Component {
175
166
  const { TextEntry } = this.props;
176
167
 
177
168
  TextEntry.all = [];
178
- this.setState(
179
- { drawables: [], updatedAt: new Date() },
180
- this.handleSessionChange
181
- );
169
+ this.setState({ drawables: [], updatedAt: new Date() }, this.handleSessionChange);
182
170
  };
183
171
 
184
- toggleTextSelected = textIsSelected => this.setState({ textIsSelected });
172
+ toggleTextSelected = (textIsSelected) => this.setState({ textIsSelected });
185
173
 
186
174
  render() {
187
175
  const {
@@ -196,7 +184,7 @@ export class DrawableMain extends React.Component {
196
184
  TextEntry,
197
185
  backgroundImageEnabled = true,
198
186
  toolActive: { type },
199
- scale
187
+ scale,
200
188
  } = this.props;
201
189
  const { isOver, newDrawable } = this.state;
202
190
 
@@ -217,7 +205,7 @@ export class DrawableMain extends React.Component {
217
205
  stage: this.stage,
218
206
  onMouseOverElement: this.onMouseOverElement,
219
207
  onMouseOutElement: this.onMouseOutElement,
220
- scale
208
+ scale,
221
209
  };
222
210
 
223
211
  let listeners = {};
@@ -242,14 +230,12 @@ export class DrawableMain extends React.Component {
242
230
  return (
243
231
  <div className={classes.wrapper}>
244
232
  <div className={classes.undoControls}>
245
- <Button disabled={disabled} onClick={this.handleUndo} label="Undo"/>
246
- <Button disabled={disabled} onClick={this.handleClearAll} label="Clear all"/>
233
+ <Button disabled={disabled} onClick={this.handleUndo} label="Undo" />
234
+ <Button disabled={disabled} onClick={this.handleClearAll} label="Clear all" />
247
235
  </div>
248
236
  <div className={classes.base}>
249
237
  {backgroundImageEnabled && imageUrl && (
250
- <ImageBackground
251
- dimensions={{ height: imageHeight, width: imageWidth }}
252
- url={imageUrl}/>
238
+ <ImageBackground dimensions={{ height: imageHeight, width: imageWidth }} url={imageUrl} />
253
239
  )}
254
240
 
255
241
  {TextEntry.renderTextareas()}
@@ -257,26 +243,22 @@ export class DrawableMain extends React.Component {
257
243
  <Stage
258
244
  scaleX={scale}
259
245
  scaleY={scale}
260
- ref={ref => {
246
+ ref={(ref) => {
261
247
  this.stage = ref;
262
248
  }}
263
249
  className={classnames(classes.stage, {
264
- [classes.active]:
265
- draggable &&
266
- (isOver || (newDrawable && newDrawable.length === 1))
250
+ [classes.active]: draggable && (isOver || (newDrawable && newDrawable.length === 1)),
267
251
  })}
268
252
  height={drawableDimensions.height}
269
253
  width={drawableDimensions.width}
270
254
  {...listeners}
271
255
  >
272
256
  <Layer
273
- ref={ref => {
257
+ ref={(ref) => {
274
258
  this.layer = ref;
275
259
  }}
276
260
  >
277
- {drawables.map((drawable, key) =>
278
- drawable.render({ ...drawableProps, key })
279
- )}
261
+ {drawables.map((drawable, key) => drawable.render({ ...drawableProps, key }))}
280
262
  {/* Text Entry is a special case */}
281
263
  {TextEntry.render(drawableProps)}
282
264
  </Layer>
@@ -291,25 +273,25 @@ const styles = () => ({
291
273
  wrapper: {
292
274
  display: 'flex',
293
275
  flexWrap: 'wrap',
294
- justifyContent: 'flex-end'
276
+ justifyContent: 'flex-end',
295
277
  },
296
278
  base: {
297
279
  position: 'relative',
298
- width: '100%'
280
+ width: '100%',
299
281
  },
300
282
  stage: {
301
283
  left: 0,
302
284
  position: 'absolute',
303
285
  touchAction: 'none',
304
- top: 0
286
+ top: 0,
305
287
  },
306
288
  active: {
307
- cursor: 'pointer'
289
+ cursor: 'pointer',
308
290
  },
309
291
  undoControls: {
310
292
  marginTop: -43,
311
- width: 163
312
- }
293
+ width: 172,
294
+ },
313
295
  });
314
296
 
315
297
  DrawableMain.propTypes = {
@@ -326,7 +308,7 @@ DrawableMain.propTypes = {
326
308
  toolActive: PropTypes.object.isRequired,
327
309
  session: PropTypes.object.isRequired,
328
310
  backgroundImageEnabled: PropTypes.bool.isRequired,
329
- scale: PropTypes.number.isRequired
311
+ scale: PropTypes.number.isRequired,
330
312
  };
331
313
 
332
314
  export default withStyles(styles)(DrawableMain);
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import Typography from '@material-ui/core/Typography';
4
3
  import { Collapsible, PreviewPrompt } from '@pie-lib/render-ui';
5
4
  import { withStyles } from '@material-ui/core/styles';
6
5
 
@@ -34,22 +33,18 @@ class DrawingResponseComponent extends React.Component {
34
33
  ) : (
35
34
  <div>
36
35
  {teacherInstructions && (
37
- <React.Fragment>
38
- <Collapsible
39
- labels={{
40
- hidden: 'Show Teacher Instructions',
41
- visible: 'Hide Teacher Instructions',
42
- }}
43
- >
44
- <PreviewPrompt prompt={teacherInstructions} />
45
- </Collapsible>
46
- <br />
47
- </React.Fragment>
36
+ <Collapsible
37
+ className={classes.collapsible}
38
+ labels={{
39
+ hidden: 'Show Teacher Instructions',
40
+ visible: 'Hide Teacher Instructions',
41
+ }}
42
+ >
43
+ <PreviewPrompt prompt={teacherInstructions} />
44
+ </Collapsible>
48
45
  )}
49
46
 
50
- <Typography className={classes.prompt}>
51
- <PreviewPrompt tagName="span" prompt={prompt} />
52
- </Typography>
47
+ {prompt && <PreviewPrompt tagName="span" prompt={prompt} />}
53
48
 
54
49
  <Container
55
50
  session={session}
@@ -72,9 +67,9 @@ DrawingResponseComponent.propTypes = {
72
67
  session: PropTypes.object.isRequired,
73
68
  };
74
69
 
75
- const styles = () => ({
76
- prompt: {
77
- fontSize: 'inherit',
70
+ const styles = (theme) => ({
71
+ collapsible: {
72
+ marginBottom: theme.spacing.unit * 2,
78
73
  },
79
74
  });
80
75