@pie-element/extended-text-entry 13.4.1-next.0 → 13.4.1-next.3

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,905 @@
1
+ import { getFeedback } from '@pie-lib/feedback';
2
+
3
+ function _extends() {
4
+ _extends = Object.assign || function (target) {
5
+ for (var i = 1; i < arguments.length; i++) {
6
+ var source = arguments[i];
7
+
8
+ for (var key in source) {
9
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
10
+ target[key] = source[key];
11
+ }
12
+ }
13
+ }
14
+
15
+ return target;
16
+ };
17
+
18
+ return _extends.apply(this, arguments);
19
+ }
20
+
21
+ var browser = {exports: {}};
22
+
23
+ /**
24
+ * Helpers.
25
+ */
26
+
27
+ var s = 1000;
28
+ var m = s * 60;
29
+ var h = m * 60;
30
+ var d = h * 24;
31
+ var w = d * 7;
32
+ var y = d * 365.25;
33
+
34
+ /**
35
+ * Parse or format the given `val`.
36
+ *
37
+ * Options:
38
+ *
39
+ * - `long` verbose formatting [false]
40
+ *
41
+ * @param {String|Number} val
42
+ * @param {Object} [options]
43
+ * @throws {Error} throw an error if val is not a non-empty string or a number
44
+ * @return {String|Number}
45
+ * @api public
46
+ */
47
+
48
+ var ms = function(val, options) {
49
+ options = options || {};
50
+ var type = typeof val;
51
+ if (type === 'string' && val.length > 0) {
52
+ return parse(val);
53
+ } else if (type === 'number' && isFinite(val)) {
54
+ return options.long ? fmtLong(val) : fmtShort(val);
55
+ }
56
+ throw new Error(
57
+ 'val is not a non-empty string or a valid number. val=' +
58
+ JSON.stringify(val)
59
+ );
60
+ };
61
+
62
+ /**
63
+ * Parse the given `str` and return milliseconds.
64
+ *
65
+ * @param {String} str
66
+ * @return {Number}
67
+ * @api private
68
+ */
69
+
70
+ function parse(str) {
71
+ str = String(str);
72
+ if (str.length > 100) {
73
+ return;
74
+ }
75
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
76
+ str
77
+ );
78
+ if (!match) {
79
+ return;
80
+ }
81
+ var n = parseFloat(match[1]);
82
+ var type = (match[2] || 'ms').toLowerCase();
83
+ switch (type) {
84
+ case 'years':
85
+ case 'year':
86
+ case 'yrs':
87
+ case 'yr':
88
+ case 'y':
89
+ return n * y;
90
+ case 'weeks':
91
+ case 'week':
92
+ case 'w':
93
+ return n * w;
94
+ case 'days':
95
+ case 'day':
96
+ case 'd':
97
+ return n * d;
98
+ case 'hours':
99
+ case 'hour':
100
+ case 'hrs':
101
+ case 'hr':
102
+ case 'h':
103
+ return n * h;
104
+ case 'minutes':
105
+ case 'minute':
106
+ case 'mins':
107
+ case 'min':
108
+ case 'm':
109
+ return n * m;
110
+ case 'seconds':
111
+ case 'second':
112
+ case 'secs':
113
+ case 'sec':
114
+ case 's':
115
+ return n * s;
116
+ case 'milliseconds':
117
+ case 'millisecond':
118
+ case 'msecs':
119
+ case 'msec':
120
+ case 'ms':
121
+ return n;
122
+ default:
123
+ return undefined;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Short format for `ms`.
129
+ *
130
+ * @param {Number} ms
131
+ * @return {String}
132
+ * @api private
133
+ */
134
+
135
+ function fmtShort(ms) {
136
+ var msAbs = Math.abs(ms);
137
+ if (msAbs >= d) {
138
+ return Math.round(ms / d) + 'd';
139
+ }
140
+ if (msAbs >= h) {
141
+ return Math.round(ms / h) + 'h';
142
+ }
143
+ if (msAbs >= m) {
144
+ return Math.round(ms / m) + 'm';
145
+ }
146
+ if (msAbs >= s) {
147
+ return Math.round(ms / s) + 's';
148
+ }
149
+ return ms + 'ms';
150
+ }
151
+
152
+ /**
153
+ * Long format for `ms`.
154
+ *
155
+ * @param {Number} ms
156
+ * @return {String}
157
+ * @api private
158
+ */
159
+
160
+ function fmtLong(ms) {
161
+ var msAbs = Math.abs(ms);
162
+ if (msAbs >= d) {
163
+ return plural(ms, msAbs, d, 'day');
164
+ }
165
+ if (msAbs >= h) {
166
+ return plural(ms, msAbs, h, 'hour');
167
+ }
168
+ if (msAbs >= m) {
169
+ return plural(ms, msAbs, m, 'minute');
170
+ }
171
+ if (msAbs >= s) {
172
+ return plural(ms, msAbs, s, 'second');
173
+ }
174
+ return ms + ' ms';
175
+ }
176
+
177
+ /**
178
+ * Pluralization helper.
179
+ */
180
+
181
+ function plural(ms, msAbs, n, name) {
182
+ var isPlural = msAbs >= n * 1.5;
183
+ return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
184
+ }
185
+
186
+ /**
187
+ * This is the common logic for both the Node.js and web browser
188
+ * implementations of `debug()`.
189
+ */
190
+
191
+ function setup(env) {
192
+ createDebug.debug = createDebug;
193
+ createDebug.default = createDebug;
194
+ createDebug.coerce = coerce;
195
+ createDebug.disable = disable;
196
+ createDebug.enable = enable;
197
+ createDebug.enabled = enabled;
198
+ createDebug.humanize = ms;
199
+ createDebug.destroy = destroy;
200
+
201
+ Object.keys(env).forEach(key => {
202
+ createDebug[key] = env[key];
203
+ });
204
+
205
+ /**
206
+ * The currently active debug mode names, and names to skip.
207
+ */
208
+
209
+ createDebug.names = [];
210
+ createDebug.skips = [];
211
+
212
+ /**
213
+ * Map of special "%n" handling functions, for the debug "format" argument.
214
+ *
215
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
216
+ */
217
+ createDebug.formatters = {};
218
+
219
+ /**
220
+ * Selects a color for a debug namespace
221
+ * @param {String} namespace The namespace string for the debug instance to be colored
222
+ * @return {Number|String} An ANSI color code for the given namespace
223
+ * @api private
224
+ */
225
+ function selectColor(namespace) {
226
+ let hash = 0;
227
+
228
+ for (let i = 0; i < namespace.length; i++) {
229
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
230
+ hash |= 0; // Convert to 32bit integer
231
+ }
232
+
233
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
234
+ }
235
+ createDebug.selectColor = selectColor;
236
+
237
+ /**
238
+ * Create a debugger with the given `namespace`.
239
+ *
240
+ * @param {String} namespace
241
+ * @return {Function}
242
+ * @api public
243
+ */
244
+ function createDebug(namespace) {
245
+ let prevTime;
246
+ let enableOverride = null;
247
+ let namespacesCache;
248
+ let enabledCache;
249
+
250
+ function debug(...args) {
251
+ // Disabled?
252
+ if (!debug.enabled) {
253
+ return;
254
+ }
255
+
256
+ const self = debug;
257
+
258
+ // Set `diff` timestamp
259
+ const curr = Number(new Date());
260
+ const ms = curr - (prevTime || curr);
261
+ self.diff = ms;
262
+ self.prev = prevTime;
263
+ self.curr = curr;
264
+ prevTime = curr;
265
+
266
+ args[0] = createDebug.coerce(args[0]);
267
+
268
+ if (typeof args[0] !== 'string') {
269
+ // Anything else let's inspect with %O
270
+ args.unshift('%O');
271
+ }
272
+
273
+ // Apply any `formatters` transformations
274
+ let index = 0;
275
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
276
+ // If we encounter an escaped % then don't increase the array index
277
+ if (match === '%%') {
278
+ return '%';
279
+ }
280
+ index++;
281
+ const formatter = createDebug.formatters[format];
282
+ if (typeof formatter === 'function') {
283
+ const val = args[index];
284
+ match = formatter.call(self, val);
285
+
286
+ // Now we need to remove `args[index]` since it's inlined in the `format`
287
+ args.splice(index, 1);
288
+ index--;
289
+ }
290
+ return match;
291
+ });
292
+
293
+ // Apply env-specific formatting (colors, etc.)
294
+ createDebug.formatArgs.call(self, args);
295
+
296
+ const logFn = self.log || createDebug.log;
297
+ logFn.apply(self, args);
298
+ }
299
+
300
+ debug.namespace = namespace;
301
+ debug.useColors = createDebug.useColors();
302
+ debug.color = createDebug.selectColor(namespace);
303
+ debug.extend = extend;
304
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
305
+
306
+ Object.defineProperty(debug, 'enabled', {
307
+ enumerable: true,
308
+ configurable: false,
309
+ get: () => {
310
+ if (enableOverride !== null) {
311
+ return enableOverride;
312
+ }
313
+ if (namespacesCache !== createDebug.namespaces) {
314
+ namespacesCache = createDebug.namespaces;
315
+ enabledCache = createDebug.enabled(namespace);
316
+ }
317
+
318
+ return enabledCache;
319
+ },
320
+ set: v => {
321
+ enableOverride = v;
322
+ }
323
+ });
324
+
325
+ // Env-specific initialization logic for debug instances
326
+ if (typeof createDebug.init === 'function') {
327
+ createDebug.init(debug);
328
+ }
329
+
330
+ return debug;
331
+ }
332
+
333
+ function extend(namespace, delimiter) {
334
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
335
+ newDebug.log = this.log;
336
+ return newDebug;
337
+ }
338
+
339
+ /**
340
+ * Enables a debug mode by namespaces. This can include modes
341
+ * separated by a colon and wildcards.
342
+ *
343
+ * @param {String} namespaces
344
+ * @api public
345
+ */
346
+ function enable(namespaces) {
347
+ createDebug.save(namespaces);
348
+ createDebug.namespaces = namespaces;
349
+
350
+ createDebug.names = [];
351
+ createDebug.skips = [];
352
+
353
+ let i;
354
+ const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
355
+ const len = split.length;
356
+
357
+ for (i = 0; i < len; i++) {
358
+ if (!split[i]) {
359
+ // ignore empty strings
360
+ continue;
361
+ }
362
+
363
+ namespaces = split[i].replace(/\*/g, '.*?');
364
+
365
+ if (namespaces[0] === '-') {
366
+ createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
367
+ } else {
368
+ createDebug.names.push(new RegExp('^' + namespaces + '$'));
369
+ }
370
+ }
371
+ }
372
+
373
+ /**
374
+ * Disable debug output.
375
+ *
376
+ * @return {String} namespaces
377
+ * @api public
378
+ */
379
+ function disable() {
380
+ const namespaces = [
381
+ ...createDebug.names.map(toNamespace),
382
+ ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
383
+ ].join(',');
384
+ createDebug.enable('');
385
+ return namespaces;
386
+ }
387
+
388
+ /**
389
+ * Returns true if the given mode name is enabled, false otherwise.
390
+ *
391
+ * @param {String} name
392
+ * @return {Boolean}
393
+ * @api public
394
+ */
395
+ function enabled(name) {
396
+ if (name[name.length - 1] === '*') {
397
+ return true;
398
+ }
399
+
400
+ let i;
401
+ let len;
402
+
403
+ for (i = 0, len = createDebug.skips.length; i < len; i++) {
404
+ if (createDebug.skips[i].test(name)) {
405
+ return false;
406
+ }
407
+ }
408
+
409
+ for (i = 0, len = createDebug.names.length; i < len; i++) {
410
+ if (createDebug.names[i].test(name)) {
411
+ return true;
412
+ }
413
+ }
414
+
415
+ return false;
416
+ }
417
+
418
+ /**
419
+ * Convert regexp to namespace
420
+ *
421
+ * @param {RegExp} regxep
422
+ * @return {String} namespace
423
+ * @api private
424
+ */
425
+ function toNamespace(regexp) {
426
+ return regexp.toString()
427
+ .substring(2, regexp.toString().length - 2)
428
+ .replace(/\.\*\?$/, '*');
429
+ }
430
+
431
+ /**
432
+ * Coerce `val`.
433
+ *
434
+ * @param {Mixed} val
435
+ * @return {Mixed}
436
+ * @api private
437
+ */
438
+ function coerce(val) {
439
+ if (val instanceof Error) {
440
+ return val.stack || val.message;
441
+ }
442
+ return val;
443
+ }
444
+
445
+ /**
446
+ * XXX DO NOT USE. This is a temporary stub function.
447
+ * XXX It WILL be removed in the next major release.
448
+ */
449
+ function destroy() {
450
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
451
+ }
452
+
453
+ createDebug.enable(createDebug.load());
454
+
455
+ return createDebug;
456
+ }
457
+
458
+ var common = setup;
459
+
460
+ /* eslint-env browser */
461
+
462
+ (function (module, exports) {
463
+ /**
464
+ * This is the web browser implementation of `debug()`.
465
+ */
466
+
467
+ exports.formatArgs = formatArgs;
468
+ exports.save = save;
469
+ exports.load = load;
470
+ exports.useColors = useColors;
471
+ exports.storage = localstorage();
472
+ exports.destroy = (() => {
473
+ let warned = false;
474
+
475
+ return () => {
476
+ if (!warned) {
477
+ warned = true;
478
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
479
+ }
480
+ };
481
+ })();
482
+
483
+ /**
484
+ * Colors.
485
+ */
486
+
487
+ exports.colors = [
488
+ '#0000CC',
489
+ '#0000FF',
490
+ '#0033CC',
491
+ '#0033FF',
492
+ '#0066CC',
493
+ '#0066FF',
494
+ '#0099CC',
495
+ '#0099FF',
496
+ '#00CC00',
497
+ '#00CC33',
498
+ '#00CC66',
499
+ '#00CC99',
500
+ '#00CCCC',
501
+ '#00CCFF',
502
+ '#3300CC',
503
+ '#3300FF',
504
+ '#3333CC',
505
+ '#3333FF',
506
+ '#3366CC',
507
+ '#3366FF',
508
+ '#3399CC',
509
+ '#3399FF',
510
+ '#33CC00',
511
+ '#33CC33',
512
+ '#33CC66',
513
+ '#33CC99',
514
+ '#33CCCC',
515
+ '#33CCFF',
516
+ '#6600CC',
517
+ '#6600FF',
518
+ '#6633CC',
519
+ '#6633FF',
520
+ '#66CC00',
521
+ '#66CC33',
522
+ '#9900CC',
523
+ '#9900FF',
524
+ '#9933CC',
525
+ '#9933FF',
526
+ '#99CC00',
527
+ '#99CC33',
528
+ '#CC0000',
529
+ '#CC0033',
530
+ '#CC0066',
531
+ '#CC0099',
532
+ '#CC00CC',
533
+ '#CC00FF',
534
+ '#CC3300',
535
+ '#CC3333',
536
+ '#CC3366',
537
+ '#CC3399',
538
+ '#CC33CC',
539
+ '#CC33FF',
540
+ '#CC6600',
541
+ '#CC6633',
542
+ '#CC9900',
543
+ '#CC9933',
544
+ '#CCCC00',
545
+ '#CCCC33',
546
+ '#FF0000',
547
+ '#FF0033',
548
+ '#FF0066',
549
+ '#FF0099',
550
+ '#FF00CC',
551
+ '#FF00FF',
552
+ '#FF3300',
553
+ '#FF3333',
554
+ '#FF3366',
555
+ '#FF3399',
556
+ '#FF33CC',
557
+ '#FF33FF',
558
+ '#FF6600',
559
+ '#FF6633',
560
+ '#FF9900',
561
+ '#FF9933',
562
+ '#FFCC00',
563
+ '#FFCC33'
564
+ ];
565
+
566
+ /**
567
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
568
+ * and the Firebug extension (any Firefox version) are known
569
+ * to support "%c" CSS customizations.
570
+ *
571
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
572
+ */
573
+
574
+ // eslint-disable-next-line complexity
575
+ function useColors() {
576
+ // NB: In an Electron preload script, document will be defined but not fully
577
+ // initialized. Since we know we're in Chrome, we'll just detect this case
578
+ // explicitly
579
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
580
+ return true;
581
+ }
582
+
583
+ // Internet Explorer and Edge do not support colors.
584
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
585
+ return false;
586
+ }
587
+
588
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
589
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
590
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
591
+ // Is firebug? http://stackoverflow.com/a/398120/376773
592
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
593
+ // Is firefox >= v31?
594
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
595
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
596
+ // Double check webkit in userAgent just in case we are in a worker
597
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
598
+ }
599
+
600
+ /**
601
+ * Colorize log arguments if enabled.
602
+ *
603
+ * @api public
604
+ */
605
+
606
+ function formatArgs(args) {
607
+ args[0] = (this.useColors ? '%c' : '') +
608
+ this.namespace +
609
+ (this.useColors ? ' %c' : ' ') +
610
+ args[0] +
611
+ (this.useColors ? '%c ' : ' ') +
612
+ '+' + module.exports.humanize(this.diff);
613
+
614
+ if (!this.useColors) {
615
+ return;
616
+ }
617
+
618
+ const c = 'color: ' + this.color;
619
+ args.splice(1, 0, c, 'color: inherit');
620
+
621
+ // The final "%c" is somewhat tricky, because there could be other
622
+ // arguments passed either before or after the %c, so we need to
623
+ // figure out the correct index to insert the CSS into
624
+ let index = 0;
625
+ let lastC = 0;
626
+ args[0].replace(/%[a-zA-Z%]/g, match => {
627
+ if (match === '%%') {
628
+ return;
629
+ }
630
+ index++;
631
+ if (match === '%c') {
632
+ // We only are interested in the *last* %c
633
+ // (the user may have provided their own)
634
+ lastC = index;
635
+ }
636
+ });
637
+
638
+ args.splice(lastC, 0, c);
639
+ }
640
+
641
+ /**
642
+ * Invokes `console.debug()` when available.
643
+ * No-op when `console.debug` is not a "function".
644
+ * If `console.debug` is not available, falls back
645
+ * to `console.log`.
646
+ *
647
+ * @api public
648
+ */
649
+ exports.log = console.debug || console.log || (() => {});
650
+
651
+ /**
652
+ * Save `namespaces`.
653
+ *
654
+ * @param {String} namespaces
655
+ * @api private
656
+ */
657
+ function save(namespaces) {
658
+ try {
659
+ if (namespaces) {
660
+ exports.storage.setItem('debug', namespaces);
661
+ } else {
662
+ exports.storage.removeItem('debug');
663
+ }
664
+ } catch (error) {
665
+ // Swallow
666
+ // XXX (@Qix-) should we be logging these?
667
+ }
668
+ }
669
+
670
+ /**
671
+ * Load `namespaces`.
672
+ *
673
+ * @return {String} returns the previously persisted debug modes
674
+ * @api private
675
+ */
676
+ function load() {
677
+ let r;
678
+ try {
679
+ r = exports.storage.getItem('debug');
680
+ } catch (error) {
681
+ // Swallow
682
+ // XXX (@Qix-) should we be logging these?
683
+ }
684
+
685
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
686
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
687
+ r = process.env.DEBUG;
688
+ }
689
+
690
+ return r;
691
+ }
692
+
693
+ /**
694
+ * Localstorage attempts to return the localstorage.
695
+ *
696
+ * This is necessary because safari throws
697
+ * when a user disables cookies/localstorage
698
+ * and you attempt to access it.
699
+ *
700
+ * @return {LocalStorage}
701
+ * @api private
702
+ */
703
+
704
+ function localstorage() {
705
+ try {
706
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
707
+ // The Browser also has localStorage in the global context.
708
+ return localStorage;
709
+ } catch (error) {
710
+ // Swallow
711
+ // XXX (@Qix-) should we be logging these?
712
+ }
713
+ }
714
+
715
+ module.exports = common(exports);
716
+
717
+ const {formatters} = module.exports;
718
+
719
+ /**
720
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
721
+ */
722
+
723
+ formatters.j = function (v) {
724
+ try {
725
+ return JSON.stringify(v);
726
+ } catch (error) {
727
+ return '[UnexpectedJSONParseError]: ' + error.message;
728
+ }
729
+ };
730
+ }(browser, browser.exports));
731
+
732
+ var debug = browser.exports;
733
+
734
+ var defaults = {
735
+ annotationsEnabled: false,
736
+ dimensions: {
737
+ height: 100,
738
+ width: 500
739
+ },
740
+ equationEditor: 'Grade 8 - HS',
741
+ feedbackEnabled: false,
742
+ mathInput: false,
743
+ playerSpellCheckDisabled: true,
744
+ predefinedAnnotations: [{
745
+ label: 'good',
746
+ text: 'good',
747
+ type: 'positive'
748
+ }, {
749
+ label: '★',
750
+ text: '★',
751
+ type: 'positive'
752
+ }, {
753
+ label: ':-)',
754
+ text: ':-)',
755
+ type: 'positive'
756
+ }, {
757
+ label: 'creative',
758
+ text: 'creative',
759
+ type: 'positive'
760
+ }, {
761
+ label: 'run-on',
762
+ text: 'run-on',
763
+ type: 'negative'
764
+ }, {
765
+ label: 'frag',
766
+ text: 'fragment',
767
+ type: 'negative'
768
+ }, {
769
+ label: 'tran',
770
+ text: 'transition',
771
+ type: 'negative'
772
+ }, {
773
+ label: 'supp',
774
+ text: 'support needed',
775
+ type: 'negative'
776
+ }, {
777
+ label: 'punc',
778
+ text: 'punctuation',
779
+ type: 'negative'
780
+ }, {
781
+ label: 'agr',
782
+ text: 'agreement wrong',
783
+ type: 'negative'
784
+ }, {
785
+ label: 'unclear',
786
+ text: 'unclear',
787
+ type: 'negative'
788
+ }, {
789
+ label: 'cut',
790
+ text: 'cut',
791
+ type: 'negative'
792
+ }, {
793
+ label: 'sp',
794
+ text: 'spelling',
795
+ type: 'negative'
796
+ }, {
797
+ label: 'cap',
798
+ text: 'capitalization',
799
+ type: 'negative'
800
+ }, {
801
+ label: 'inf',
802
+ text: 'informal',
803
+ type: 'negative'
804
+ }, {
805
+ label: 'awk',
806
+ text: 'awkward',
807
+ type: 'negative'
808
+ }],
809
+ prompt: '',
810
+ promptEnabled: true,
811
+ rationale: '',
812
+ rationaleEnabled: true,
813
+ studentInstructionsEnabled: true,
814
+ teacherInstructions: '',
815
+ teacherInstructionsEnabled: true,
816
+ toolbarEditorPosition: 'bottom'
817
+ };
818
+
819
+ const log = debug('@pie-element:extended-text-entry:controller');
820
+ async function createDefaultModel(model = {}) {
821
+ log('[createDefaultModel]', model);
822
+ return _extends({}, defaults, model);
823
+ }
824
+ const normalize = question => _extends({}, defaults, question);
825
+ async function model(question, session, env) {
826
+ log('[question]', question);
827
+ const normalizedQuestion = normalize(question);
828
+ const fb = env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled ? getFeedback(normalizedQuestion.feedback, 'Your answer has been submitted') : Promise.resolve(undefined);
829
+ let teacherInstructions = null;
830
+
831
+ if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
832
+ teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
833
+ } else {
834
+ teacherInstructions = null;
835
+ }
836
+
837
+ let equationEditor = normalizedQuestion.equationEditor || 'miscellaneous';
838
+
839
+ switch (normalizedQuestion.equationEditor) {
840
+ case 'Grade 1 - 2':
841
+ equationEditor = 1;
842
+ break;
843
+
844
+ case 'Grade 3 - 5':
845
+ equationEditor = 3;
846
+ break;
847
+
848
+ case 'Grade 6 - 7':
849
+ equationEditor = 6;
850
+ break;
851
+
852
+ case 'Grade 8 - HS':
853
+ equationEditor = 8;
854
+ break;
855
+ }
856
+
857
+ const annotatorMode = normalizedQuestion.annotationsEnabled && (env.role === 'instructor' || env.mode === 'evaluate');
858
+ return fb.then(feedback => ({
859
+ prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
860
+ dimensions: normalizedQuestion.dimensions,
861
+ customKeys: normalizedQuestion.customKeys || [],
862
+ id: normalizedQuestion.id,
863
+ disabled: env.mode !== 'gather',
864
+ feedback,
865
+ teacherInstructions,
866
+ language: normalizedQuestion.language,
867
+ mathInput: normalizedQuestion.mathInput,
868
+ spanishInput: normalizedQuestion.spanishInput,
869
+ specialInput: normalizedQuestion.specialInput,
870
+ equationEditor,
871
+ spellCheckEnabled: !normalizedQuestion.playerSpellCheckDisabled,
872
+ playersToolbarPosition: normalizedQuestion.playersToolbarPosition || 'bottom',
873
+ annotatorMode,
874
+ disabledAnnotator: normalizedQuestion.annotationsEnabled ? env.role !== 'instructor' : true,
875
+ predefinedAnnotations: normalizedQuestion.annotationsEnabled ? normalizedQuestion.predefinedAnnotations : [],
876
+ extraCSSRules: normalizedQuestion.extraCSSRules
877
+ }));
878
+ }
879
+ async function
880
+ /*question, session, env*/
881
+ outcome() {
882
+ return {
883
+ score: 0,
884
+ completed: 'n/a',
885
+ note: 'Requires manual scoring'
886
+ };
887
+ } // remove all html tags
888
+
889
+
890
+ const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
891
+
892
+ const validate = (model = {}, config = {}) => {
893
+ const errors = {};
894
+ ['teacherInstructions', 'prompt'].forEach(field => {
895
+ var _config$field;
896
+
897
+ if ((_config$field = config[field]) != null && _config$field.required && !getContent(model[field])) {
898
+ errors[field] = 'This field is required.';
899
+ }
900
+ });
901
+ return errors;
902
+ };
903
+
904
+ export { createDefaultModel, model, normalize, outcome, validate };
905
+ //# sourceMappingURL=controller.js.map