@pie-element/extended-text-entry 6.7.3 → 6.7.4

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/LICENSE.md ADDED
@@ -0,0 +1,5 @@
1
+ Copyright 2019 CoreSpring Inc
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/extended-text-entry-configure",
3
3
  "private": true,
4
- "version": "5.4.2",
4
+ "version": "5.4.4",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/extended-text-entry-controller",
3
3
  "private": true,
4
- "version": "4.1.15",
4
+ "version": "4.1.17",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -0,0 +1,386 @@
1
+ import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_react_dom} from "../../../@pie-lib/shared-module@^1.2.13/module/index.js";
2
+ import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.0.14/module/index.js";
3
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.14/module/index.js";
4
+ var lib = {};
5
+ Object.defineProperty(lib, "__esModule", {
6
+ value: true
7
+ });
8
+ class ModelUpdatedEvent extends CustomEvent {
9
+ constructor(update, reset = false) {
10
+ super(ModelUpdatedEvent.TYPE, {
11
+ bubbles: true,
12
+ detail: {
13
+ update,
14
+ reset
15
+ }
16
+ });
17
+ this.update = update;
18
+ this.reset = reset;
19
+ }
20
+ }
21
+ ModelUpdatedEvent.TYPE = 'model.updated';
22
+ var ModelUpdatedEvent_1 = lib.ModelUpdatedEvent = ModelUpdatedEvent;
23
+ class DeleteImageEvent extends CustomEvent {
24
+ constructor(src, done) {
25
+ super(DeleteImageEvent.TYPE, {
26
+ bubbles: true,
27
+ detail: {
28
+ src,
29
+ done
30
+ }
31
+ });
32
+ this.src = src;
33
+ this.done = done;
34
+ }
35
+ }
36
+ DeleteImageEvent.TYPE = 'delete.image';
37
+ var DeleteImageEvent_1 = lib.DeleteImageEvent = DeleteImageEvent;
38
+ class InsertImageEvent extends CustomEvent {
39
+ constructor(handler) {
40
+ super(InsertImageEvent.TYPE, {
41
+ bubbles: true,
42
+ detail: handler
43
+ });
44
+ this.handler = handler;
45
+ }
46
+ }
47
+ InsertImageEvent.TYPE = 'insert.image';
48
+ var InsertImageEvent_1 = lib.InsertImageEvent = InsertImageEvent;
49
+ const React$1 = _dll_react;
50
+ const PropTypes = _dll_prop_types;
51
+ const {Typography: Typography} = _dll_material_ui__core;
52
+ const {withStyles: withStyles} = _dll_material_ui__core_styles;
53
+ const {FeedbackSelector: FeedbackSelector} = _dll_pie_lib__config_ui;
54
+ const {InputContainer: InputContainer} = _dll_pie_lib__config_ui;
55
+ const {settings: settings} = _dll_pie_lib__config_ui;
56
+ const {layout: layout} = _dll_pie_lib__config_ui;
57
+ const EditableHtml = _dll_pie_lib__editable_html;
58
+ const {ALL_PLUGINS: ALL_PLUGINS} = _dll_pie_lib__editable_html;
59
+ const _jsxFileName = "/Users/andreeapescar/WORK/pie/new-pie/pie-elements/packages/extended-text-entry/configure/src/main.jsx";
60
+ const {Panel, toggle, numberFields, dropdown} = settings;
61
+ const defaultFeedback = {
62
+ type: 'default',
63
+ default: 'Your answer has been submitted'
64
+ };
65
+ class Main extends React$1.Component {
66
+ static __initStatic() {
67
+ this.propTypes = {
68
+ onModelChanged: PropTypes.func.isRequired,
69
+ onConfigurationChanged: PropTypes.func,
70
+ model: PropTypes.object.isRequired,
71
+ configuration: PropTypes.object.isRequired,
72
+ imageSupport: PropTypes.object.isRequired,
73
+ classes: PropTypes.object.isRequired
74
+ };
75
+ }
76
+ constructor(props) {
77
+ super(props);
78
+ Main.prototype.__init.call(this);
79
+ Main.prototype.__init2.call(this);
80
+ Main.prototype.__init3.call(this);
81
+ this.state = {
82
+ setDimensions: true
83
+ };
84
+ }
85
+ __init() {
86
+ this.onPromptChange = markup => {
87
+ const {onModelChanged, model} = this.props;
88
+ onModelChanged({
89
+ ...model,
90
+ prompt: markup
91
+ });
92
+ };
93
+ }
94
+ __init2() {
95
+ this.changeFeedback = feedback => {
96
+ const {model, onModelChanged} = this.props;
97
+ const update = {
98
+ ...model,
99
+ feedback
100
+ };
101
+ onModelChanged(update);
102
+ };
103
+ }
104
+ __init3() {
105
+ this.changeTeacherInstructions = teacherInstructions => {
106
+ const {model, onModelChanged} = this.props;
107
+ const update = {
108
+ ...model,
109
+ teacherInstructions
110
+ };
111
+ onModelChanged(update);
112
+ };
113
+ }
114
+ render() {
115
+ const {model, classes, onModelChanged, configuration, onConfigurationChanged, imageSupport} = this.props;
116
+ const {multiple = {}, feedback = {}, teacherInstructions = {}, prompt = {}, studentInstructions = {}, mathInput = {}, dimensions = {}, equationEditor = {}} = configuration || ({});
117
+ const {teacherInstructionsEnabled, promptEnabled, feedbackEnabled} = model || ({});
118
+ const toolbarOpts = {};
119
+ switch (model.toolbarEditorPosition) {
120
+ case 'top':
121
+ toolbarOpts.position = 'top';
122
+ break;
123
+ default:
124
+ toolbarOpts.position = 'bottom';
125
+ break;
126
+ }
127
+ return React$1.createElement(layout.ConfigLayout, {
128
+ settings: React$1.createElement(Panel, {
129
+ model: model,
130
+ configuration: configuration,
131
+ onChangeModel: model => onModelChanged(model),
132
+ onChangeConfiguration: config => onConfigurationChanged(config),
133
+ groups: {
134
+ 'Settings': {
135
+ mathInput: mathInput.settings && toggle(mathInput.label),
136
+ equationEditor: equationEditor.enabled && model.mathInput && dropdown(equationEditor.label, ['Grade 1 - 2', 'Grade 3 - 5', 'Grade 6 - 7', 'Grade 8 - HS', 'geometry', 'advanced-algebra', 'statistics', 'miscellaneous']),
137
+ dimensions: numberFields(dimensions.label, {
138
+ width: {
139
+ label: 'Width (px)',
140
+ suffix: 'px',
141
+ min: 100,
142
+ max: 500
143
+ },
144
+ height: {
145
+ label: 'Height (px)',
146
+ suffix: 'px',
147
+ min: 100,
148
+ max: 500
149
+ }
150
+ }),
151
+ 'multiple.enabled': multiple.settings && toggle(multiple.label, true),
152
+ promptEnabled: prompt.settings && toggle(prompt.label),
153
+ feedbackEnabled: feedback.settings && toggle(feedback.label)
154
+ },
155
+ 'Properties': {
156
+ teacherInstructionsEnabled: teacherInstructions.settings && toggle(teacherInstructions.label),
157
+ studentInstructionsEnabled: studentInstructions.settings && toggle(studentInstructions.label)
158
+ }
159
+ },
160
+ __self: this,
161
+ __source: {
162
+ fileName: _jsxFileName,
163
+ lineNumber: 84
164
+ }
165
+ }),
166
+ __self: this,
167
+ __source: {
168
+ fileName: _jsxFileName,
169
+ lineNumber: 82
170
+ }
171
+ }, React$1.createElement('div', {
172
+ __self: this,
173
+ __source: {
174
+ fileName: _jsxFileName,
175
+ lineNumber: 132
176
+ }
177
+ }, teacherInstructionsEnabled && React$1.createElement(InputContainer, {
178
+ label: teacherInstructions.label,
179
+ className: classes.promptContainer,
180
+ __self: this,
181
+ __source: {
182
+ fileName: _jsxFileName,
183
+ lineNumber: 135
184
+ }
185
+ }, React$1.createElement(EditableHtml, {
186
+ className: classes.prompt,
187
+ markup: model.teacherInstructions || '',
188
+ onChange: this.changeTeacherInstructions,
189
+ imageSupport: imageSupport,
190
+ nonEmpty: false,
191
+ toolbarOpts: toolbarOpts,
192
+ __self: this,
193
+ __source: {
194
+ fileName: _jsxFileName,
195
+ lineNumber: 136
196
+ }
197
+ })), React$1.createElement('br', {
198
+ __self: this,
199
+ __source: {
200
+ fileName: _jsxFileName,
201
+ lineNumber: 147
202
+ }
203
+ }), promptEnabled && React$1.createElement(InputContainer, {
204
+ label: prompt.label,
205
+ className: classes.promptContainer,
206
+ __self: this,
207
+ __source: {
208
+ fileName: _jsxFileName,
209
+ lineNumber: 150
210
+ }
211
+ }, React$1.createElement(EditableHtml, {
212
+ activePlugins: ALL_PLUGINS,
213
+ className: classes.prompt,
214
+ markup: model.prompt || '',
215
+ onChange: this.onPromptChange,
216
+ imageSupport: imageSupport,
217
+ nonEmpty: false,
218
+ toolbarOpts: toolbarOpts,
219
+ __self: this,
220
+ __source: {
221
+ fileName: _jsxFileName,
222
+ lineNumber: 151
223
+ }
224
+ })), feedbackEnabled && React$1.createElement(React$1.Fragment, {
225
+ __self: this,
226
+ __source: {
227
+ fileName: _jsxFileName,
228
+ lineNumber: 165
229
+ }
230
+ }, React$1.createElement(Typography, {
231
+ className: classes.header,
232
+ variant: "subheading",
233
+ __self: this,
234
+ __source: {
235
+ fileName: _jsxFileName,
236
+ lineNumber: 166
237
+ }
238
+ }, "Feedback"), React$1.createElement(FeedbackSelector, {
239
+ label: "When submitted, show",
240
+ feedback: model.feedback || defaultFeedback,
241
+ onChange: this.changeFeedback,
242
+ toolbarOpts: toolbarOpts,
243
+ __self: this,
244
+ __source: {
245
+ fileName: _jsxFileName,
246
+ lineNumber: 170
247
+ }
248
+ }))));
249
+ }
250
+ }
251
+ Main.__initStatic();
252
+ var Main$1 = withStyles(theme => ({
253
+ header: {
254
+ paddingBottom: theme.spacing.unit
255
+ },
256
+ promptContainer: {
257
+ paddingTop: theme.spacing.unit * 2,
258
+ marginBottom: theme.spacing.unit * 2,
259
+ width: '100%'
260
+ },
261
+ promptInput: {
262
+ width: '100%',
263
+ marginBottom: theme.spacing.unit
264
+ },
265
+ field: {
266
+ width: '200px'
267
+ }
268
+ }))(Main);
269
+ var defaults = {
270
+ model: {
271
+ dimensions: {
272
+ height: 100,
273
+ width: 500
274
+ },
275
+ prompt: 'This is the question prompt',
276
+ mathInput: false,
277
+ equationEditor: 'miscellaneous',
278
+ feedbackEnabled: true,
279
+ rationaleEnabled: true,
280
+ promptEnabled: true,
281
+ teacherInstructionsEnabled: true,
282
+ studentInstructionsEnabled: true,
283
+ toolbarEditorPosition: 'bottom'
284
+ },
285
+ configuration: {
286
+ dimensions: {
287
+ settings: true,
288
+ label: 'Text-Entry Display Size'
289
+ },
290
+ equationEditor: {
291
+ settings: false,
292
+ label: 'Equation Editor',
293
+ enabled: true
294
+ },
295
+ feedback: {
296
+ settings: true,
297
+ label: 'Feedback'
298
+ },
299
+ mathInput: {
300
+ settings: true,
301
+ label: 'Student response can include math notation',
302
+ enabled: false
303
+ },
304
+ multiple: {
305
+ settings: false,
306
+ label: 'Multiple Parts',
307
+ enabled: false
308
+ },
309
+ studentInstructions: {
310
+ settings: false,
311
+ label: 'Student Instructions'
312
+ },
313
+ prompt: {
314
+ settings: true,
315
+ label: 'Prompt'
316
+ },
317
+ teacherInstructions: {
318
+ settings: true,
319
+ label: 'Teacher Instructions'
320
+ }
321
+ }
322
+ };
323
+ const React = _dll_react;
324
+ const ReactDOM = _dll_react_dom;
325
+ class ExtendedTextEntry extends HTMLElement {
326
+ static __initStatic() {
327
+ this.createDefaultModel = (model = {}) => ({
328
+ ...defaults.model,
329
+ ...model
330
+ });
331
+ }
332
+ constructor() {
333
+ super();
334
+ this._model = ExtendedTextEntry.createDefaultModel();
335
+ this._configuration = defaults.configuration;
336
+ }
337
+ set model(m) {
338
+ this._model = ExtendedTextEntry.createDefaultModel(m);
339
+ this.render();
340
+ }
341
+ set configuration(c) {
342
+ this._configuration = {
343
+ ...defaults.configuration,
344
+ ...c
345
+ };
346
+ this.render();
347
+ }
348
+ onModelChanged(m) {
349
+ this._model = m;
350
+ this.render();
351
+ this.dispatchEvent(new ModelUpdatedEvent_1(this._model, false));
352
+ }
353
+ onConfigurationChanged(c) {
354
+ this._configuration = {
355
+ ...defaults.configuration,
356
+ ...c
357
+ };
358
+ if (this._model) {
359
+ this.onModelChanged(this._model);
360
+ }
361
+ this.render();
362
+ }
363
+ insertImage(handler) {
364
+ this.dispatchEvent(new InsertImageEvent_1(handler));
365
+ }
366
+ onDeleteImage(src, done) {
367
+ this.dispatchEvent(new DeleteImageEvent_1(src, done));
368
+ }
369
+ render() {
370
+ if (this._model) {
371
+ const element = React.createElement(Main$1, {
372
+ model: this._model,
373
+ configuration: this._configuration,
374
+ onModelChanged: this.onModelChanged.bind(this),
375
+ onConfigurationChanged: this.onConfigurationChanged.bind(this),
376
+ imageSupport: {
377
+ add: this.insertImage.bind(this),
378
+ delete: this.onDeleteImage.bind(this)
379
+ }
380
+ });
381
+ ReactDOM.render(element, this);
382
+ }
383
+ }
384
+ }
385
+ ExtendedTextEntry.__initStatic();
386
+ export {ExtendedTextEntry as default};
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Get the feedback from a {FeedbackConfig}
3
+ *
4
+ * @param {FeedbackConfig} feedback
5
+ * @param {string} fallback
6
+ */
7
+ const getFeedback = (feedback, fallback) =>
8
+ new Promise(resolve => {
9
+ if (!feedback || feedback.type === 'none') {
10
+ resolve(undefined);
11
+ return;
12
+ }
13
+ feedback = feedback || {};
14
+ const out = feedback[feedback.type] || fallback;
15
+ resolve(out);
16
+ });
17
+
18
+ var defaults = {
19
+ dimensions: {
20
+ height: 100,
21
+ width: 500,
22
+ }
23
+ };
24
+
25
+ async function createDefaultModel(model = {}) {
26
+
27
+ return {
28
+ ...defaults,
29
+ ...model,
30
+ };
31
+ }
32
+
33
+ const normalize = question => ({
34
+ ...defaults,
35
+ feedbackEnabled: true,
36
+ rationaleEnabled: true,
37
+ promptEnabled: true,
38
+ teacherInstructionsEnabled: true,
39
+ studentInstructionsEnabled: true,
40
+ ...question,
41
+ });
42
+
43
+
44
+ async function model(question, session, env) {
45
+ const normalizedQuestion = normalize(question);
46
+
47
+ const fb =
48
+ env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled
49
+ ? getFeedback(normalizedQuestion.feedback, 'Your answer has been submitted')
50
+ : Promise.resolve(undefined);
51
+
52
+ let teacherInstructions = null;
53
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
54
+ teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
55
+ } else {
56
+ teacherInstructions = null;
57
+ }
58
+
59
+ let equationEditor = normalizedQuestion.equationEditor || 'miscellaneous';
60
+
61
+ switch (normalizedQuestion.equationEditor) {
62
+ case 'Grade 1 - 2':
63
+ equationEditor = 1;
64
+ break;
65
+ case 'Grade 3 - 5':
66
+ equationEditor = 3;
67
+ break;
68
+ case 'Grade 6 - 7':
69
+ equationEditor = 6;
70
+ break;
71
+ case 'Grade 8 - HS':
72
+ equationEditor = 8;
73
+ break;
74
+ }
75
+
76
+ return fb.then(feedback => ({
77
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
78
+ dimensions: normalizedQuestion.dimensions,
79
+ customKeys: normalizedQuestion.customKeys || [],
80
+ disabled: env.mode !== 'gather',
81
+ feedback,
82
+ teacherInstructions,
83
+ mathInput: normalizedQuestion.mathInput,
84
+ equationEditor
85
+ }));
86
+ }
87
+
88
+ async function outcome(/*question, session, env*/) {
89
+ return {
90
+ score: 0,
91
+ completed: 'n/a',
92
+ note: 'Requires manual scoring'
93
+ };
94
+ }
95
+
96
+ export { createDefaultModel, model, normalize, outcome };
package/module/demo.js ADDED
@@ -0,0 +1,36 @@
1
+ import Configure from './configure.js';
2
+ import Element from './element.js';
3
+ import * as controller from './controller.js';
4
+
5
+ var generate = {};
6
+
7
+ generate.model = (id, element) => ({
8
+ id,
9
+ element,
10
+ customKeys: [
11
+ '\\square'
12
+ ],
13
+ feedback: { type: 'default', default: 'this is default feedback' },
14
+ prompt: 'This is the question prompt',
15
+ promptEnabled: true,
16
+ mathInput: true,
17
+ toolbarEditorPosition: 'bottom',
18
+ });
19
+
20
+ const { model } = generate;
21
+ var config = {
22
+ elements: {
23
+ 'extended-text-entry': '../..'
24
+ },
25
+ models: [model('1', 'extended-text-entry')]
26
+ };
27
+
28
+ //Note: demo-el is a custom element loaded in the markup.
29
+ customElements.whenDefined("demo-el").then(() => {
30
+ config.models.forEach((m) => {
31
+ const de = document.createElement("demo-el");
32
+ document.body.appendChild(de);
33
+ de.def = { tagName: m.element, Element, Configure, controller };
34
+ de.model = m;
35
+ });
36
+ });