@pie-element/drawing-response 10.3.4-next.3 → 11.0.0-beta.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.
- package/CHANGELOG.md +0 -11
- package/configure/CHANGELOG.md +0 -11
- package/configure/lib/button.js +23 -47
- package/configure/lib/button.js.map +1 -1
- package/configure/lib/defaults.js +2 -3
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/image-container.js +238 -327
- package/configure/lib/image-container.js.map +1 -1
- package/configure/lib/index.js +115 -182
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +195 -261
- package/configure/lib/root.js.map +1 -1
- package/configure/package.json +9 -7
- package/configure/src/__tests__/image-container.test.jsx +101 -37
- package/configure/src/__tests__/index.test.js +27 -5
- package/configure/src/__tests__/root.test.jsx +37 -21
- package/configure/src/button.jsx +14 -24
- package/configure/src/image-container.jsx +73 -77
- package/configure/src/index.js +12 -2
- package/configure/src/root.jsx +25 -26
- package/controller/lib/defaults.js +2 -3
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +39 -65
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +1 -1
- package/lib/drawing-response/button.js +35 -60
- package/lib/drawing-response/button.js.map +1 -1
- package/lib/drawing-response/constants.js +2 -3
- package/lib/drawing-response/constants.js.map +1 -1
- package/lib/drawing-response/container.js +270 -351
- package/lib/drawing-response/container.js.map +1 -1
- package/lib/drawing-response/drawable-circle.js +65 -104
- package/lib/drawing-response/drawable-circle.js.map +1 -1
- package/lib/drawing-response/drawable-eraser.js +50 -86
- package/lib/drawing-response/drawable-eraser.js.map +1 -1
- package/lib/drawing-response/drawable-free-path.js +56 -97
- package/lib/drawing-response/drawable-free-path.js.map +1 -1
- package/lib/drawing-response/drawable-helper.js +16 -28
- package/lib/drawing-response/drawable-helper.js.map +1 -1
- package/lib/drawing-response/drawable-image.js +30 -49
- package/lib/drawing-response/drawable-image.js.map +1 -1
- package/lib/drawing-response/drawable-line.js +60 -99
- package/lib/drawing-response/drawable-line.js.map +1 -1
- package/lib/drawing-response/drawable-main.js +273 -345
- package/lib/drawing-response/drawable-main.js.map +1 -1
- package/lib/drawing-response/drawable-palette.js +123 -166
- package/lib/drawing-response/drawable-palette.js.map +1 -1
- package/lib/drawing-response/drawable-rectangle.js +65 -104
- package/lib/drawing-response/drawable-rectangle.js.map +1 -1
- package/lib/drawing-response/drawable-text.js +201 -313
- package/lib/drawing-response/drawable-text.js.map +1 -1
- package/lib/drawing-response/drawable-transformer.js +36 -79
- package/lib/drawing-response/drawable-transformer.js.map +1 -1
- package/lib/drawing-response/factory.js +6 -19
- package/lib/drawing-response/factory.js.map +1 -1
- package/lib/drawing-response/icon.js +8 -24
- package/lib/drawing-response/icon.js.map +1 -1
- package/lib/drawing-response/index.js +74 -116
- package/lib/drawing-response/index.js.map +1 -1
- package/lib/index.js +51 -102
- package/lib/index.js.map +1 -1
- package/package.json +13 -12
- package/src/__tests__/drawing-index-test.jsx +90 -27
- package/src/drawing-response/__tests__/container.test.jsx +56 -36
- package/src/drawing-response/__tests__/drawing-main.test.jsx +158 -139
- package/src/drawing-response/button.jsx +23 -34
- package/src/drawing-response/container.jsx +39 -40
- package/src/drawing-response/drawable-image.jsx +17 -20
- package/src/drawing-response/drawable-main.jsx +67 -60
- package/src/drawing-response/drawable-palette.jsx +48 -54
- package/src/drawing-response/drawable-text.jsx +26 -38
- package/src/drawing-response/index.jsx +21 -20
- package/src/index.js +17 -2
- package/configure/src/__tests__/__snapshots__/image-container.test.jsx.snap +0 -45
- package/configure/src/__tests__/__snapshots__/root.test.jsx.snap +0 -185
- package/esm/configure.js +0 -16151
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -814
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -54130
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/drawing-index-test.jsx.snap +0 -23
- package/src/drawing-response/__tests__/__snapshots__/container.test.jsx.snap +0 -396
- package/src/drawing-response/__tests__/__snapshots__/drawing-main.test.jsx.snap +0 -247
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
4
|
|
|
5
5
|
import Button from './button';
|
|
6
6
|
|
|
@@ -9,6 +9,61 @@ const isImage = (file) => {
|
|
|
9
9
|
return file.type.match(imageType);
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
const BaseContainer = styled('div')(({ theme }) => ({
|
|
13
|
+
marginTop: theme.spacing(1),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const Box = styled('div')(({ active }) => ({
|
|
17
|
+
border: active ? '1px solid #0032C2' : '1px solid #E0E1E6',
|
|
18
|
+
borderRadius: '5px',
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
const CenteredDiv = styled('div')({
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
display: 'flex',
|
|
24
|
+
flexDirection: 'column',
|
|
25
|
+
justifyContent: 'center',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const DrawableHeight = styled('div')({
|
|
29
|
+
minHeight: 350,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const Image = styled('img')({
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
display: 'flex',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const StyledImageContainer = styled('div')({
|
|
39
|
+
position: 'relative',
|
|
40
|
+
width: 'fit-content',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const ResizeHandle = styled('div')({
|
|
44
|
+
borderBottom: '1px solid #727272',
|
|
45
|
+
borderRight: '1px solid #727272',
|
|
46
|
+
bottom: '-10px',
|
|
47
|
+
cursor: 'se-resize',
|
|
48
|
+
height: '10px',
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
right: '-10px',
|
|
51
|
+
width: '10px',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const HiddenInput = styled('input')({
|
|
55
|
+
display: 'none',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const Toolbar = styled('div')({
|
|
59
|
+
backgroundColor: '#ECEDF1',
|
|
60
|
+
borderBottom: '1px solid #E0E1E6',
|
|
61
|
+
borderTopLeftRadius: '5px',
|
|
62
|
+
borderTopRightRadius: '5px',
|
|
63
|
+
display: 'flex',
|
|
64
|
+
padding: '12px 8px',
|
|
65
|
+
});
|
|
66
|
+
|
|
12
67
|
export class ImageContainer extends Component {
|
|
13
68
|
|
|
14
69
|
static propTypes = {
|
|
@@ -176,14 +231,11 @@ export class ImageContainer extends Component {
|
|
|
176
231
|
};
|
|
177
232
|
|
|
178
233
|
renderUploadControl(label) {
|
|
179
|
-
const { classes } = this.props;
|
|
180
|
-
|
|
181
234
|
return (
|
|
182
235
|
<div>
|
|
183
236
|
<Button label={label} onClick={this.handleInputClick} />
|
|
184
|
-
<
|
|
237
|
+
<HiddenInput
|
|
185
238
|
accept="image/*"
|
|
186
|
-
className={classes.input}
|
|
187
239
|
onChange={this.handleUploadImage}
|
|
188
240
|
ref={(ref) => {
|
|
189
241
|
this.input = ref;
|
|
@@ -195,13 +247,13 @@ export class ImageContainer extends Component {
|
|
|
195
247
|
}
|
|
196
248
|
|
|
197
249
|
render() {
|
|
198
|
-
const {
|
|
250
|
+
const { imageUrl, imageDimensions } = this.props;
|
|
199
251
|
const { dropzoneActive, dragEnabled, maxImageHeight, maxImageWidth } = this.state;
|
|
200
252
|
|
|
201
253
|
return (
|
|
202
|
-
<
|
|
203
|
-
<
|
|
204
|
-
|
|
254
|
+
<BaseContainer>
|
|
255
|
+
<Box
|
|
256
|
+
active={dropzoneActive}
|
|
205
257
|
{...(dragEnabled
|
|
206
258
|
? {
|
|
207
259
|
onDragExit: this.handleOnDragExit,
|
|
@@ -211,18 +263,16 @@ export class ImageContainer extends Component {
|
|
|
211
263
|
}
|
|
212
264
|
: {})}
|
|
213
265
|
>
|
|
214
|
-
<
|
|
266
|
+
<Toolbar>{this.renderUploadControl(imageUrl ? 'Replace Image' : 'Upload Image')}</Toolbar>
|
|
215
267
|
|
|
216
|
-
<
|
|
268
|
+
<DrawableHeight
|
|
217
269
|
ref={(ref) => {
|
|
218
270
|
this.imageSection = ref;
|
|
219
271
|
}}
|
|
220
|
-
className={classes.drawableHeight}
|
|
221
272
|
>
|
|
222
273
|
{imageUrl ? (
|
|
223
|
-
<
|
|
224
|
-
<
|
|
225
|
-
className={classes.image}
|
|
274
|
+
<StyledImageContainer>
|
|
275
|
+
<Image
|
|
226
276
|
height="auto"
|
|
227
277
|
onLoad={this.handleOnImageLoad}
|
|
228
278
|
ref={(ref) => {
|
|
@@ -236,85 +286,31 @@ export class ImageContainer extends Component {
|
|
|
236
286
|
}}
|
|
237
287
|
alt=""
|
|
238
288
|
/>
|
|
239
|
-
<
|
|
289
|
+
<ResizeHandle
|
|
240
290
|
ref={(ref) => {
|
|
241
291
|
this.resize = ref;
|
|
242
292
|
}}
|
|
243
|
-
className={classes.resize}
|
|
244
293
|
/>
|
|
245
|
-
</
|
|
294
|
+
</StyledImageContainer>
|
|
246
295
|
) : (
|
|
247
|
-
<
|
|
296
|
+
<DrawableHeight as={CenteredDiv}>
|
|
248
297
|
<label>Drag and drop or upload image from computer</label>
|
|
249
298
|
<br />
|
|
250
299
|
{this.renderUploadControl('Upload Image')}
|
|
251
|
-
</
|
|
300
|
+
</DrawableHeight>
|
|
252
301
|
)}
|
|
253
|
-
</
|
|
254
|
-
</
|
|
255
|
-
</
|
|
302
|
+
</DrawableHeight>
|
|
303
|
+
</Box>
|
|
304
|
+
</BaseContainer>
|
|
256
305
|
);
|
|
257
306
|
}
|
|
258
307
|
}
|
|
259
308
|
|
|
260
|
-
const styles = (theme) => ({
|
|
261
|
-
base: {
|
|
262
|
-
marginTop: theme.spacing.unit,
|
|
263
|
-
},
|
|
264
|
-
box: {
|
|
265
|
-
border: '1px solid #E0E1E6',
|
|
266
|
-
borderRadius: '5px',
|
|
267
|
-
},
|
|
268
|
-
boxActive: {
|
|
269
|
-
border: '1px solid #0032C2',
|
|
270
|
-
},
|
|
271
|
-
centered: {
|
|
272
|
-
alignItems: 'center',
|
|
273
|
-
display: 'flex',
|
|
274
|
-
flexDirection: 'column',
|
|
275
|
-
justifyContent: 'center',
|
|
276
|
-
},
|
|
277
|
-
drawableHeight: {
|
|
278
|
-
minHeight: 350,
|
|
279
|
-
},
|
|
280
|
-
image: {
|
|
281
|
-
alignItems: 'center',
|
|
282
|
-
display: 'flex',
|
|
283
|
-
justifyContent: 'center',
|
|
284
|
-
},
|
|
285
|
-
imageContainer: {
|
|
286
|
-
position: 'relative',
|
|
287
|
-
width: 'fit-content',
|
|
288
|
-
},
|
|
289
|
-
resize: {
|
|
290
|
-
borderBottom: '1px solid #727272',
|
|
291
|
-
borderRight: '1px solid #727272',
|
|
292
|
-
bottom: '-10px',
|
|
293
|
-
cursor: 'se-resize',
|
|
294
|
-
height: '10px',
|
|
295
|
-
position: 'absolute',
|
|
296
|
-
right: '-10px',
|
|
297
|
-
width: '10px',
|
|
298
|
-
},
|
|
299
|
-
input: {
|
|
300
|
-
display: 'none',
|
|
301
|
-
},
|
|
302
|
-
toolbar: {
|
|
303
|
-
backgroundColor: '#ECEDF1',
|
|
304
|
-
borderBottom: '1px solid #E0E1E6',
|
|
305
|
-
borderTopLeftRadius: '5px',
|
|
306
|
-
borderTopRightRadius: '5px',
|
|
307
|
-
display: 'flex',
|
|
308
|
-
padding: '12px 8px',
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
|
|
312
309
|
ImageContainer.propTypes = {
|
|
313
|
-
classes: PropTypes.object.isRequired,
|
|
314
310
|
imageUrl: PropTypes.string.isRequired,
|
|
315
311
|
onImageUpload: PropTypes.func.isRequired,
|
|
316
312
|
onUpdateImageDimension: PropTypes.func.isRequired,
|
|
317
313
|
insertImage: PropTypes.func,
|
|
318
314
|
};
|
|
319
315
|
|
|
320
|
-
export default
|
|
316
|
+
export default ImageContainer;
|
package/configure/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@pie-framework/pie-configure-events';
|
|
8
8
|
|
|
9
9
|
import React from 'react';
|
|
10
|
-
import
|
|
10
|
+
import { createRoot } from 'react-dom/client';
|
|
11
11
|
import debug from 'debug';
|
|
12
12
|
|
|
13
13
|
import Root from './root';
|
|
@@ -33,6 +33,7 @@ export default class DrawableResponseConfigure extends HTMLElement {
|
|
|
33
33
|
|
|
34
34
|
constructor() {
|
|
35
35
|
super();
|
|
36
|
+
this._root = null;
|
|
36
37
|
this._configuration = sensibleDefaults.configuration;
|
|
37
38
|
|
|
38
39
|
// if configuration.withRubric.forceEnabled is true, then we
|
|
@@ -152,6 +153,15 @@ export default class DrawableResponseConfigure extends HTMLElement {
|
|
|
152
153
|
delete: this.onDeleteSound.bind(this),
|
|
153
154
|
},
|
|
154
155
|
});
|
|
155
|
-
|
|
156
|
+
if (!this._root) {
|
|
157
|
+
this._root = createRoot(this);
|
|
158
|
+
}
|
|
159
|
+
this._root.render(element);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
disconnectedCallback() {
|
|
163
|
+
if (this._root) {
|
|
164
|
+
this._root.unmount();
|
|
165
|
+
}
|
|
156
166
|
}
|
|
157
167
|
}
|
package/configure/src/root.jsx
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { settings, layout, InputContainer } from '@pie-lib/config-ui';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import EditableHtml from '@pie-lib/editable-html';
|
|
5
|
-
import Typography from '@material
|
|
6
|
-
import {
|
|
4
|
+
import EditableHtml from '@pie-lib/editable-html-tip-tap';
|
|
5
|
+
import Typography from '@mui/material/Typography';
|
|
6
|
+
import { styled } from '@mui/material/styles';
|
|
7
7
|
|
|
8
8
|
import ImageContainer from './image-container';
|
|
9
9
|
import cloneDeep from 'lodash/cloneDeep';
|
|
10
10
|
|
|
11
11
|
const { Panel, toggle, dropdown } = settings;
|
|
12
12
|
|
|
13
|
+
const PromptHolder = styled(InputContainer)(({ theme }) => ({
|
|
14
|
+
paddingTop: theme.spacing(1),
|
|
15
|
+
marginTop: theme.spacing(2),
|
|
16
|
+
marginBottom: theme.spacing(1),
|
|
17
|
+
width: '100%',
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const ErrorText = styled('div')(({ theme }) => ({
|
|
21
|
+
fontSize: theme.typography.fontSize - 2,
|
|
22
|
+
color: theme.palette.error.main,
|
|
23
|
+
paddingTop: theme.spacing(1),
|
|
24
|
+
}));
|
|
25
|
+
|
|
13
26
|
export class Root extends React.Component {
|
|
14
27
|
onPromptChanged = (prompt) => {
|
|
15
28
|
const { model, onModelChanged } = this.props;
|
|
@@ -37,7 +50,7 @@ export class Root extends React.Component {
|
|
|
37
50
|
};
|
|
38
51
|
|
|
39
52
|
render() {
|
|
40
|
-
const {
|
|
53
|
+
const { configuration, imageSupport, model, onConfigurationChanged, onModelChanged, uploadSoundSupport } =
|
|
41
54
|
this.props;
|
|
42
55
|
const {
|
|
43
56
|
baseInputConfiguration = {},
|
|
@@ -109,7 +122,7 @@ export class Root extends React.Component {
|
|
|
109
122
|
}
|
|
110
123
|
>
|
|
111
124
|
{teacherInstructionsEnabled && (
|
|
112
|
-
<
|
|
125
|
+
<PromptHolder label={teacherInstructions.label}>
|
|
113
126
|
<EditableHtml
|
|
114
127
|
markup={model.teacherInstructions || ''}
|
|
115
128
|
onChange={this.onTeacherInstructionsChanged}
|
|
@@ -125,12 +138,12 @@ export class Root extends React.Component {
|
|
|
125
138
|
languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}
|
|
126
139
|
mathMlOptions={mathMlOptions}
|
|
127
140
|
/>
|
|
128
|
-
{teacherInstructionsError && <
|
|
129
|
-
</
|
|
141
|
+
{teacherInstructionsError && <ErrorText>{teacherInstructionsError}</ErrorText>}
|
|
142
|
+
</PromptHolder>
|
|
130
143
|
)}
|
|
131
144
|
|
|
132
145
|
{promptEnabled && (
|
|
133
|
-
<
|
|
146
|
+
<PromptHolder label="Item Stem">
|
|
134
147
|
<EditableHtml
|
|
135
148
|
markup={model.prompt}
|
|
136
149
|
onChange={this.onPromptChanged}
|
|
@@ -145,13 +158,13 @@ export class Root extends React.Component {
|
|
|
145
158
|
languageCharactersProps={[{ language: 'spanish' }, { language: 'special' }]}
|
|
146
159
|
mathMlOptions={mathMlOptions}
|
|
147
160
|
/>
|
|
148
|
-
{promptError && <
|
|
149
|
-
</
|
|
161
|
+
{promptError && <ErrorText>{promptError}</ErrorText>}
|
|
162
|
+
</PromptHolder>
|
|
150
163
|
)}
|
|
151
164
|
|
|
152
165
|
{backgroundImageEnabled && (
|
|
153
166
|
<React.Fragment>
|
|
154
|
-
<Typography variant="
|
|
167
|
+
<Typography variant="h6">Define Background Image</Typography>
|
|
155
168
|
|
|
156
169
|
<ImageContainer
|
|
157
170
|
imageUrl={model.imageUrl}
|
|
@@ -167,21 +180,7 @@ export class Root extends React.Component {
|
|
|
167
180
|
}
|
|
168
181
|
}
|
|
169
182
|
|
|
170
|
-
const styles = (theme) => ({
|
|
171
|
-
promptHolder: {
|
|
172
|
-
paddingTop: theme.spacing.unit * 2,
|
|
173
|
-
marginBottom: theme.spacing.unit * 2,
|
|
174
|
-
width: '100%',
|
|
175
|
-
},
|
|
176
|
-
errorText: {
|
|
177
|
-
fontSize: theme.typography.fontSize - 2,
|
|
178
|
-
color: theme.palette.error.main,
|
|
179
|
-
paddingTop: theme.spacing.unit,
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
|
|
183
183
|
Root.propTypes = {
|
|
184
|
-
classes: PropTypes.object.isRequired,
|
|
185
184
|
configuration: PropTypes.object,
|
|
186
185
|
model: PropTypes.object.isRequired,
|
|
187
186
|
imageSupport: PropTypes.shape({
|
|
@@ -196,4 +195,4 @@ Root.propTypes = {
|
|
|
196
195
|
onConfigurationChanged: PropTypes.func.isRequired,
|
|
197
196
|
};
|
|
198
197
|
|
|
199
|
-
export default
|
|
198
|
+
export default Root;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
var _default = {
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
8
|
backgroundImageEnabled: true,
|
|
9
9
|
imageDimensions: {
|
|
10
10
|
height: 0,
|
|
@@ -19,5 +19,4 @@ var _default = {
|
|
|
19
19
|
teacherInstructionsEnabled: true,
|
|
20
20
|
toolbarEditorPosition: 'bottom'
|
|
21
21
|
};
|
|
22
|
-
exports["default"] = _default;
|
|
23
22
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"defaults.js","names":["backgroundImageEnabled","imageDimensions","height","width","imageUrl","prompt","promptEnabled","spellCheckEnabled","studentInstructionsEnabled","teacherInstructions","teacherInstructionsEnabled","toolbarEditorPosition"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n backgroundImageEnabled: true,\n imageDimensions: { height: 0, width: 0 },\n imageUrl: '',\n prompt: '',\n promptEnabled: true,\n spellCheckEnabled: true,\n studentInstructionsEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n};\n"],"mappings":";;;;;;iCAAe;EACbA,sBAAsB,EAAE,IAAI;EAC5BC,eAAe,EAAE;IAAEC,MAAM,EAAE,CAAC;IAAEC,KAAK,EAAE;EAAE,CAAC;EACxCC,QAAQ,EAAE,EAAE;EACZC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,iBAAiB,EAAE,IAAI;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,qBAAqB,EAAE;AACzB,CAAC","ignoreList":[]}
|
package/controller/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -10,69 +9,54 @@ exports.model = model;
|
|
|
10
9
|
exports.normalize = void 0;
|
|
11
10
|
exports.outcome = outcome;
|
|
12
11
|
exports.validate = void 0;
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
17
|
-
|
|
18
13
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var log = (0, _debug["default"])('pie-elements:drawing-response:controller');
|
|
25
|
-
|
|
26
|
-
var normalize = function normalize(question) {
|
|
27
|
-
return _objectSpread(_objectSpread({}, _defaults["default"]), question);
|
|
28
|
-
};
|
|
29
|
-
|
|
14
|
+
const log = (0, _debug.default)('pie-elements:drawing-response:controller');
|
|
15
|
+
const normalize = question => ({
|
|
16
|
+
..._defaults.default,
|
|
17
|
+
...question
|
|
18
|
+
});
|
|
30
19
|
exports.normalize = normalize;
|
|
31
|
-
|
|
32
20
|
function model(question, session, env) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
21
|
+
const normalizedQuestion = normalize(question);
|
|
22
|
+
const {
|
|
23
|
+
extraCSSRules,
|
|
24
|
+
imageUrl,
|
|
25
|
+
imageDimensions,
|
|
26
|
+
prompt,
|
|
27
|
+
promptEnabled,
|
|
28
|
+
backgroundImageEnabled,
|
|
29
|
+
language
|
|
30
|
+
} = normalizedQuestion;
|
|
31
|
+
return new Promise(resolve => {
|
|
32
|
+
const out = {
|
|
43
33
|
disabled: env.mode !== 'gather',
|
|
44
34
|
mode: env.mode,
|
|
45
|
-
imageDimensions
|
|
46
|
-
imageUrl
|
|
35
|
+
imageDimensions,
|
|
36
|
+
imageUrl,
|
|
47
37
|
prompt: promptEnabled ? prompt : null,
|
|
48
|
-
backgroundImageEnabled
|
|
49
|
-
language
|
|
50
|
-
extraCSSRules
|
|
38
|
+
backgroundImageEnabled,
|
|
39
|
+
language,
|
|
40
|
+
extraCSSRules
|
|
51
41
|
};
|
|
52
|
-
|
|
53
42
|
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
54
43
|
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
55
44
|
} else {
|
|
56
45
|
out.teacherInstructions = null;
|
|
57
46
|
}
|
|
58
|
-
|
|
59
47
|
resolve(out);
|
|
60
48
|
});
|
|
61
49
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
|
|
50
|
+
const createDefaultModel = (model = {}) => new Promise(resolve => {
|
|
51
|
+
resolve({
|
|
52
|
+
..._defaults.default,
|
|
53
|
+
...model
|
|
67
54
|
});
|
|
68
|
-
};
|
|
69
|
-
|
|
55
|
+
});
|
|
70
56
|
exports.createDefaultModel = createDefaultModel;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
outcome() {
|
|
75
|
-
return new Promise(function (resolve) {
|
|
57
|
+
function outcome(/*config, session*/
|
|
58
|
+
) {
|
|
59
|
+
return new Promise(resolve => {
|
|
76
60
|
log('outcome...');
|
|
77
61
|
resolve({
|
|
78
62
|
score: 0,
|
|
@@ -80,31 +64,21 @@ outcome() {
|
|
|
80
64
|
note: 'Requires manual scoring'
|
|
81
65
|
});
|
|
82
66
|
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var getInnerText = function getInnerText(html) {
|
|
87
|
-
return (html || '').replaceAll(/<[^>]*>/g, '');
|
|
88
|
-
}; // remove all html tags except img, iframe and source tag for audio
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var getContent = function getContent(html) {
|
|
92
|
-
return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
93
|
-
};
|
|
67
|
+
}
|
|
94
68
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
98
|
-
var errors = {};
|
|
99
|
-
['teacherInstructions', 'prompt'].forEach(function (field) {
|
|
100
|
-
var _config$field;
|
|
69
|
+
// remove all html tags
|
|
70
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
101
71
|
|
|
102
|
-
|
|
72
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
73
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
74
|
+
const validate = (model = {}, config = {}) => {
|
|
75
|
+
const errors = {};
|
|
76
|
+
['teacherInstructions', 'prompt'].forEach(field => {
|
|
77
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
103
78
|
errors[field] = 'This field is required.';
|
|
104
79
|
}
|
|
105
80
|
});
|
|
106
81
|
return errors;
|
|
107
82
|
};
|
|
108
|
-
|
|
109
83
|
exports.validate = validate;
|
|
110
84
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_defaults","log","debug","normalize","question","defaults","exports","model","session","env","normalizedQuestion","extraCSSRules","imageUrl","imageDimensions","prompt","promptEnabled","backgroundImageEnabled","language","Promise","resolve","out","disabled","mode","role","teacherInstructions","teacherInstructionsEnabled","createDefaultModel","outcome","score","completed","note","getInnerText","html","replaceAll","getContent","replace","validate","config","errors","forEach","field","required"],"sources":["../src/index.js"],"sourcesContent":["import debug from 'debug';\nimport defaults from './defaults';\n\nconst log = debug('pie-elements:drawing-response:controller');\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\nexport function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n const { extraCSSRules, imageUrl, imageDimensions, prompt, promptEnabled, backgroundImageEnabled, language } = normalizedQuestion;\n\n return new Promise((resolve) => {\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n imageDimensions,\n imageUrl,\n prompt: promptEnabled ? prompt : null,\n backgroundImageEnabled,\n language,\n extraCSSRules,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n}\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nexport function outcome(/*config, session*/) {\n return new Promise((resolve) => {\n log('outcome...');\n resolve({\n score: 0,\n completed: 'n/a',\n note: 'Requires manual scoring',\n });\n });\n}\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n\n ['teacherInstructions', 'prompt'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,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