@pie-element/extended-text-entry 6.5.4-next.467 → 6.5.4-next.477

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,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.14/module/index.js";
2
+ import {_dll_pie_lib__config_ui} from "../../../@pie-lib/config-module@^1.0.15/module/index.js";
3
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.15/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 = "/home/circleci/repo/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
+ });
@@ -0,0 +1,261 @@
1
+ import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_debug, _dll_lodash, _dll_pie_lib__render_ui, _dll_classnames, _dll_react_dom} from "../../../@pie-lib/shared-module@^1.2.14/module/index.js";
2
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.15/module/index.js";
3
+ import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.17/module/index.js";
4
+ const React$1 = _dll_react;
5
+ const PropTypes = _dll_prop_types;
6
+ const {Typography: Typography} = _dll_material_ui__core;
7
+ const {withStyles: withStyles} = _dll_material_ui__core_styles;
8
+ const debug$1 = _dll_debug;
9
+ const {debounce: debounce} = _dll_lodash;
10
+ const {color: color} = _dll_pie_lib__render_ui;
11
+ const {Feedback: Feedback} = _dll_pie_lib__render_ui;
12
+ const {Collapsible: Collapsible} = _dll_pie_lib__render_ui;
13
+ const classNames = _dll_classnames;
14
+ const EditableHTML = _dll_pie_lib__editable_html;
15
+ const {renderMath: renderMath} = _dll_pie_lib__math_rendering;
16
+ const _jsxFileName = "/home/circleci/repo/packages/extended-text-entry/src/main.jsx";
17
+ const log$1 = debug$1('@pie-ui:extended-text-entry');
18
+ const style = theme => ({
19
+ main: {
20
+ backgroundColor: color.background(),
21
+ color: color.text()
22
+ },
23
+ prompt: {
24
+ width: '100%',
25
+ color: color.text(),
26
+ marginBottom: theme.spacing.unit * 2,
27
+ fontSize: 'inherit'
28
+ }
29
+ });
30
+ class Main extends React$1.Component {
31
+ constructor(...args) {
32
+ super(...args);
33
+ Main.prototype.__init.call(this);
34
+ }
35
+ static __initStatic() {
36
+ this.propTypes = {
37
+ onChange: PropTypes.func.isRequired,
38
+ model: PropTypes.object,
39
+ classes: PropTypes.object.isRequired,
40
+ session: PropTypes.shape({
41
+ value: PropTypes.string
42
+ }).isRequired
43
+ };
44
+ }
45
+ componentDidUpdate() {
46
+ if (this.containerRef) {
47
+ renderMath(this.containerRef);
48
+ }
49
+ }
50
+ __init() {
51
+ this.changeSession = debounce(this.props.onChange, 1500);
52
+ }
53
+ render() {
54
+ const {model, classes, session} = this.props;
55
+ const {dimensions, disabled, feedback, teacherInstructions, mathInput, animationsDisabled} = model;
56
+ const {value} = session;
57
+ const {width, height} = dimensions || ({});
58
+ const maxHeight = '40vh';
59
+ log$1('[render] disabled? ', disabled);
60
+ const teacherInstructionsDiv = React$1.createElement('div', {
61
+ className: "teacher-instructions",
62
+ dangerouslySetInnerHTML: {
63
+ __html: teacherInstructions
64
+ },
65
+ __self: this,
66
+ __source: {
67
+ fileName: _jsxFileName,
68
+ lineNumber: 53
69
+ }
70
+ });
71
+ return React$1.createElement('div', {
72
+ className: classes.main,
73
+ ref: ref => {
74
+ this.containerRef = ref;
75
+ },
76
+ __self: this,
77
+ __source: {
78
+ fileName: _jsxFileName,
79
+ lineNumber: 59
80
+ }
81
+ }, teacherInstructions && React$1.createElement('div', {
82
+ __self: this,
83
+ __source: {
84
+ fileName: _jsxFileName,
85
+ lineNumber: 67
86
+ }
87
+ }, !animationsDisabled ? React$1.createElement(Collapsible, {
88
+ labels: {
89
+ hidden: 'Show Teacher Instructions',
90
+ visible: 'Hide Teacher Instructions'
91
+ },
92
+ className: classes.collapsible,
93
+ __self: this,
94
+ __source: {
95
+ fileName: _jsxFileName,
96
+ lineNumber: 69
97
+ }
98
+ }, teacherInstructionsDiv) : teacherInstructionsDiv, React$1.createElement('br', {
99
+ __self: this,
100
+ __source: {
101
+ fileName: _jsxFileName,
102
+ lineNumber: 76
103
+ }
104
+ })), model.prompt && React$1.createElement(Typography, {
105
+ className: classNames(classes.prompt, 'prompt'),
106
+ dangerouslySetInnerHTML: {
107
+ __html: model.prompt
108
+ },
109
+ __self: this,
110
+ __source: {
111
+ fileName: _jsxFileName,
112
+ lineNumber: 81
113
+ }
114
+ }), React$1.createElement(EditableHTML, {
115
+ onChange: this.changeSession,
116
+ markup: value || '',
117
+ width: width && width.toString(),
118
+ minHeight: height && height.toString(),
119
+ maxHeight: maxHeight,
120
+ disabled: disabled,
121
+ highlightShape: true,
122
+ pluginProps: {
123
+ math: {
124
+ disabled: !mathInput,
125
+ customKeys: this.props.model.customKeys,
126
+ keypadMode: this.props.model.equationEditor,
127
+ controlledKeypadMode: false
128
+ },
129
+ video: {
130
+ disabled: true
131
+ },
132
+ audio: {
133
+ disabled: true
134
+ }
135
+ },
136
+ __self: this,
137
+ __source: {
138
+ fileName: _jsxFileName,
139
+ lineNumber: 86
140
+ }
141
+ }), feedback && React$1.createElement('div', {
142
+ __self: this,
143
+ __source: {
144
+ fileName: _jsxFileName,
145
+ lineNumber: 110
146
+ }
147
+ }, React$1.createElement('br', {
148
+ __self: this,
149
+ __source: {
150
+ fileName: _jsxFileName,
151
+ lineNumber: 111
152
+ }
153
+ }), React$1.createElement(Feedback, {
154
+ correctness: "correct",
155
+ feedback: feedback,
156
+ __self: this,
157
+ __source: {
158
+ fileName: _jsxFileName,
159
+ lineNumber: 112
160
+ }
161
+ })));
162
+ }
163
+ }
164
+ Main.__initStatic();
165
+ var Main$1 = withStyles(style)(Main);
166
+ var lib = {};
167
+ Object.defineProperty(lib, "__esModule", {
168
+ value: true
169
+ });
170
+ class ModelSetEvent extends CustomEvent {
171
+ constructor(component, complete, hasModel) {
172
+ super(ModelSetEvent.TYPE, {
173
+ bubbles: true,
174
+ composed: true,
175
+ detail: {
176
+ complete,
177
+ component,
178
+ hasModel
179
+ }
180
+ });
181
+ this.component = component;
182
+ this.complete = complete;
183
+ }
184
+ }
185
+ ModelSetEvent.TYPE = 'model-set';
186
+ var ModelSetEvent_1 = lib.ModelSetEvent = ModelSetEvent;
187
+ class SessionChangedEvent extends CustomEvent {
188
+ constructor(component, complete) {
189
+ super(SessionChangedEvent.TYPE, {
190
+ bubbles: true,
191
+ composed: true,
192
+ detail: {
193
+ complete,
194
+ component
195
+ }
196
+ });
197
+ this.component = component;
198
+ this.complete = complete;
199
+ }
200
+ }
201
+ SessionChangedEvent.TYPE = 'session-changed';
202
+ var SessionChangedEvent_1 = lib.SessionChangedEvent = SessionChangedEvent;
203
+ const React = _dll_react;
204
+ const ReactDOM = _dll_react_dom;
205
+ const debug = _dll_debug;
206
+ const log = debug('@pie-ui:extended-text-entry');
207
+ const domParser = typeof window !== undefined ? new DOMParser() : {
208
+ parseFromString: v => v
209
+ };
210
+ function textContent(value) {
211
+ if (typeof value !== 'string') {
212
+ return undefined;
213
+ }
214
+ try {
215
+ const document = domParser.parseFromString(value, 'text/html');
216
+ const textContent = document.body.textContent;
217
+ return textContent;
218
+ } catch (err) {
219
+ log('tried to parse as dom and failed', value);
220
+ return value;
221
+ }
222
+ }
223
+ function isComplete(value) {
224
+ const tc = textContent(value);
225
+ const out = tc !== undefined && tc.length > 0;
226
+ return out;
227
+ }
228
+ class RootExtendedTextEntry extends HTMLElement {
229
+ constructor() {
230
+ super();
231
+ this._model = null;
232
+ this._session = null;
233
+ }
234
+ set model(m) {
235
+ this._model = m;
236
+ this.dispatchEvent(new ModelSetEvent_1(this.tagName.toLowerCase(), false, !!this._model));
237
+ this.render();
238
+ }
239
+ set session(s) {
240
+ this._session = s;
241
+ this.render();
242
+ }
243
+ handleChange(value) {
244
+ this._session.value = value;
245
+ this.dispatchEvent(new SessionChangedEvent_1(this.tagName.toLowerCase(), isComplete(value)));
246
+ }
247
+ connectedCallback() {
248
+ this.render();
249
+ }
250
+ render() {
251
+ if (this._model && this._session) {
252
+ let elem = React.createElement(Main$1, {
253
+ model: this._model,
254
+ session: this._session,
255
+ onChange: this.handleChange.bind(this)
256
+ });
257
+ ReactDOM.render(elem, this);
258
+ }
259
+ }
260
+ }
261
+ export {RootExtendedTextEntry as default, isComplete, textContent};
@@ -0,0 +1,21 @@
1
+
2
+ <!doctype html>
3
+ <html>
4
+ <head>
5
+ <title>@pie-element/extended-text-entry@6.7.0</title>
6
+ <script
7
+ type="module"
8
+ src="https://cdn.jsdelivr.net/npm/@pslb/demo-el@^1.0.0/dist/demo-el/demo-el.esm.js"></script>
9
+
10
+ <link
11
+ href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
12
+ rel="stylesheet"
13
+ />
14
+ <style>
15
+ html, body {
16
+ font-family: 'Roboto', sans-serif;
17
+ }
18
+ </style>
19
+ <script type="module" src="./demo.js"></script>
20
+ </head>
21
+ </html>
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@pie-element/extended-text-entry",
3
+ "version": "6.7.0",
4
+ "modules": [
5
+ {
6
+ "name": "@pie-lib/shared-module",
7
+ "version": "^1.2.14"
8
+ },
9
+ {
10
+ "name": "@pie-lib/math-rendering-module",
11
+ "version": "^1.0.17"
12
+ },
13
+ {
14
+ "name": "@pie-lib/editable-html-module",
15
+ "version": "^1.0.15"
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,74 @@
1
+ import PrintElement from './print.js';
2
+
3
+ var generate = {};
4
+
5
+ generate.model = (id, element) => ({
6
+ id,
7
+ element,
8
+ customKeys: [
9
+ '\\square'
10
+ ],
11
+ feedback: { type: 'default', default: 'this is default feedback' },
12
+ prompt: 'This is the question prompt',
13
+ promptEnabled: true,
14
+ mathInput: true,
15
+ toolbarEditorPosition: 'bottom',
16
+ });
17
+
18
+ const { model } = generate;
19
+ var config = {
20
+ elements: {
21
+ 'extended-text-entry': '../..'
22
+ },
23
+ models: [model('1', 'extended-text-entry')]
24
+ };
25
+
26
+ // new init - just shows off print!
27
+
28
+ const init = async () => {
29
+ console.log('define the element...');
30
+ await Promise.all(
31
+ config.models.map(async (m) => {
32
+ try {
33
+ const printTag = `${m.element}-print`;
34
+ if (customElements.get(printTag)) {
35
+ return true;
36
+ } else {
37
+ customElements.define(printTag, PrintElement);
38
+ await customElements.whenDefined(printTag);
39
+ return true;
40
+ }
41
+ } catch (e) {
42
+ return false;
43
+ }
44
+ })
45
+ );
46
+
47
+ console.log('now apply the model...');
48
+ config.models.forEach((m) => {
49
+ const printTag = `${m.element}-print`;
50
+ const h3s = document.createElement('h3');
51
+ h3s.textContent = 'student mode';
52
+ document.body.appendChild(h3s);
53
+ const de = document.createElement(printTag);
54
+ document.body.appendChild(de);
55
+ de.options = {};
56
+ de.model = m;
57
+
58
+ const h3 = document.createElement('h3');
59
+ h3.textContent = 'instructor mode';
60
+ document.body.appendChild(h3);
61
+ const instr = document.createElement(printTag);
62
+ document.body.appendChild(instr);
63
+ instr.options = { mode: 'instructor' };
64
+ instr.model = JSON.parse(JSON.stringify(m));
65
+ });
66
+ };
67
+
68
+ init()
69
+ .then(() => {
70
+ console.log('ready');
71
+ })
72
+ .catch((e) => {
73
+ console.error(e);
74
+ });
@@ -0,0 +1,18 @@
1
+
2
+ <!doctype html>
3
+ <html>
4
+ <head>
5
+ <title>@pie-element/extended-text-entry@6.7.0</title>
6
+ <link
7
+ href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
8
+ rel="stylesheet"
9
+ />
10
+ <style>
11
+ html, body {
12
+ font-family: 'Roboto', sans-serif;
13
+ }
14
+ </style>
15
+ <script type="module" src="./print-demo.js"></script>
16
+ </head>
17
+ <body></body>
18
+ </html>
@@ -0,0 +1,225 @@
1
+ import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_debug, _dll_lodash, _dll_pie_lib__render_ui, _dll_classnames, _dll_react_dom} from "../../../@pie-lib/shared-module@^1.2.14/module/index.js";
2
+ import {_dll_pie_lib__math_rendering} from "../../../@pie-lib/math-rendering-module@^1.0.17/module/index.js";
3
+ import {_dll_pie_lib__editable_html} from "../../../@pie-lib/editable-html-module@^1.0.15/module/index.js";
4
+ const React$1 = _dll_react;
5
+ const PropTypes = _dll_prop_types;
6
+ const {Typography: Typography} = _dll_material_ui__core;
7
+ const {withStyles: withStyles} = _dll_material_ui__core_styles;
8
+ const debug$1 = _dll_debug;
9
+ const {debounce: debounce$1} = _dll_lodash;
10
+ const {color: color} = _dll_pie_lib__render_ui;
11
+ const {Feedback: Feedback} = _dll_pie_lib__render_ui;
12
+ const {Collapsible: Collapsible} = _dll_pie_lib__render_ui;
13
+ const classNames = _dll_classnames;
14
+ const EditableHTML = _dll_pie_lib__editable_html;
15
+ const {renderMath: renderMath$1} = _dll_pie_lib__math_rendering;
16
+ const _jsxFileName = "/home/circleci/repo/packages/extended-text-entry/src/main.jsx";
17
+ const log$1 = debug$1('@pie-ui:extended-text-entry');
18
+ const style = theme => ({
19
+ main: {
20
+ backgroundColor: color.background(),
21
+ color: color.text()
22
+ },
23
+ prompt: {
24
+ width: '100%',
25
+ color: color.text(),
26
+ marginBottom: theme.spacing.unit * 2,
27
+ fontSize: 'inherit'
28
+ }
29
+ });
30
+ class Main extends React$1.Component {
31
+ constructor(...args) {
32
+ super(...args);
33
+ Main.prototype.__init.call(this);
34
+ }
35
+ static __initStatic() {
36
+ this.propTypes = {
37
+ onChange: PropTypes.func.isRequired,
38
+ model: PropTypes.object,
39
+ classes: PropTypes.object.isRequired,
40
+ session: PropTypes.shape({
41
+ value: PropTypes.string
42
+ }).isRequired
43
+ };
44
+ }
45
+ componentDidUpdate() {
46
+ if (this.containerRef) {
47
+ renderMath$1(this.containerRef);
48
+ }
49
+ }
50
+ __init() {
51
+ this.changeSession = debounce$1(this.props.onChange, 1500);
52
+ }
53
+ render() {
54
+ const {model, classes, session} = this.props;
55
+ const {dimensions, disabled, feedback, teacherInstructions, mathInput, animationsDisabled} = model;
56
+ const {value} = session;
57
+ const {width, height} = dimensions || ({});
58
+ const maxHeight = '40vh';
59
+ log$1('[render] disabled? ', disabled);
60
+ const teacherInstructionsDiv = React$1.createElement('div', {
61
+ className: "teacher-instructions",
62
+ dangerouslySetInnerHTML: {
63
+ __html: teacherInstructions
64
+ },
65
+ __self: this,
66
+ __source: {
67
+ fileName: _jsxFileName,
68
+ lineNumber: 53
69
+ }
70
+ });
71
+ return React$1.createElement('div', {
72
+ className: classes.main,
73
+ ref: ref => {
74
+ this.containerRef = ref;
75
+ },
76
+ __self: this,
77
+ __source: {
78
+ fileName: _jsxFileName,
79
+ lineNumber: 59
80
+ }
81
+ }, teacherInstructions && React$1.createElement('div', {
82
+ __self: this,
83
+ __source: {
84
+ fileName: _jsxFileName,
85
+ lineNumber: 67
86
+ }
87
+ }, !animationsDisabled ? React$1.createElement(Collapsible, {
88
+ labels: {
89
+ hidden: 'Show Teacher Instructions',
90
+ visible: 'Hide Teacher Instructions'
91
+ },
92
+ className: classes.collapsible,
93
+ __self: this,
94
+ __source: {
95
+ fileName: _jsxFileName,
96
+ lineNumber: 69
97
+ }
98
+ }, teacherInstructionsDiv) : teacherInstructionsDiv, React$1.createElement('br', {
99
+ __self: this,
100
+ __source: {
101
+ fileName: _jsxFileName,
102
+ lineNumber: 76
103
+ }
104
+ })), model.prompt && React$1.createElement(Typography, {
105
+ className: classNames(classes.prompt, 'prompt'),
106
+ dangerouslySetInnerHTML: {
107
+ __html: model.prompt
108
+ },
109
+ __self: this,
110
+ __source: {
111
+ fileName: _jsxFileName,
112
+ lineNumber: 81
113
+ }
114
+ }), React$1.createElement(EditableHTML, {
115
+ onChange: this.changeSession,
116
+ markup: value || '',
117
+ width: width && width.toString(),
118
+ minHeight: height && height.toString(),
119
+ maxHeight: maxHeight,
120
+ disabled: disabled,
121
+ highlightShape: true,
122
+ pluginProps: {
123
+ math: {
124
+ disabled: !mathInput,
125
+ customKeys: this.props.model.customKeys,
126
+ keypadMode: this.props.model.equationEditor,
127
+ controlledKeypadMode: false
128
+ },
129
+ video: {
130
+ disabled: true
131
+ },
132
+ audio: {
133
+ disabled: true
134
+ }
135
+ },
136
+ __self: this,
137
+ __source: {
138
+ fileName: _jsxFileName,
139
+ lineNumber: 86
140
+ }
141
+ }), feedback && React$1.createElement('div', {
142
+ __self: this,
143
+ __source: {
144
+ fileName: _jsxFileName,
145
+ lineNumber: 110
146
+ }
147
+ }, React$1.createElement('br', {
148
+ __self: this,
149
+ __source: {
150
+ fileName: _jsxFileName,
151
+ lineNumber: 111
152
+ }
153
+ }), React$1.createElement(Feedback, {
154
+ correctness: "correct",
155
+ feedback: feedback,
156
+ __self: this,
157
+ __source: {
158
+ fileName: _jsxFileName,
159
+ lineNumber: 112
160
+ }
161
+ })));
162
+ }
163
+ }
164
+ Main.__initStatic();
165
+ var Main$1 = withStyles(style)(Main);
166
+ const React = _dll_react;
167
+ const ReactDOM = _dll_react_dom;
168
+ const {debounce: debounce} = _dll_lodash;
169
+ const debug = _dll_debug;
170
+ const {renderMath: renderMath} = _dll_pie_lib__math_rendering;
171
+ const log = debug('pie-element:extended-text-entry:print');
172
+ const preparePrintModel = (model, opts) => {
173
+ const instr = opts.role === 'instructor';
174
+ model.teacherInstructions = instr ? model.teacherInstructions : undefined;
175
+ model.showTeacherInstructions = instr;
176
+ model.mode = instr ? 'evaluate' : model.mode;
177
+ const defaultDimensions = {
178
+ height: 100,
179
+ width: 500
180
+ };
181
+ model.dimensions = {
182
+ ...defaultDimensions,
183
+ ...model.dimensions
184
+ };
185
+ model.disabled = true;
186
+ model.feedback = undefined;
187
+ model.animationsDisabled = true;
188
+ return model;
189
+ };
190
+ class ExtendedTextEntryPrint extends HTMLElement {
191
+ constructor() {
192
+ super();
193
+ this._options = null;
194
+ this._model = null;
195
+ this._session = [];
196
+ this._rerender = debounce(() => {
197
+ if (this._model && this._session) {
198
+ const printModel = preparePrintModel(this._model, this._options);
199
+ const element = this._options && React.createElement(Main$1, {
200
+ model: printModel,
201
+ session: {},
202
+ onChange: () => {}
203
+ });
204
+ ReactDOM.render(element, this, () => {
205
+ log('render complete - render math');
206
+ renderMath(this);
207
+ });
208
+ } else {
209
+ log('skip');
210
+ }
211
+ }, 50, {
212
+ leading: false,
213
+ trailing: true
214
+ });
215
+ }
216
+ set options(o) {
217
+ this._options = o;
218
+ }
219
+ set model(s) {
220
+ this._model = s;
221
+ this._rerender();
222
+ }
223
+ connectedCallback() {}
224
+ }
225
+ export {ExtendedTextEntryPrint as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/extended-text-entry",
3
- "version": "6.5.4-next.467+864f4b55e",
3
+ "version": "6.5.4-next.477+7a8dd4c5b",
4
4
  "description": "",
5
5
  "repository": "pie-framework/pie-elements",
6
6
  "publishConfig": {
@@ -22,7 +22,7 @@
22
22
  "react": "^16.8.1",
23
23
  "react-dom": "^16.8.1"
24
24
  },
25
- "gitHead": "864f4b55ea71c0e0111ee29ad3b86a6140f15135",
25
+ "gitHead": "7a8dd4c5b0063891636d838559cd36112adfacf1",
26
26
  "scripts": {
27
27
  "postpublish": "../../scripts/postpublish"
28
28
  },