@pie-element/placement-ordering 7.5.2 → 7.5.3-next.1016

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +195 -0
  2. package/configure/CHANGELOG.md +169 -0
  3. package/configure/lib/choice-editor.js +229 -54
  4. package/configure/lib/choice-editor.js.map +1 -1
  5. package/configure/lib/choice-tile.js +69 -9
  6. package/configure/lib/choice-tile.js.map +1 -1
  7. package/configure/lib/defaults.js +20 -1
  8. package/configure/lib/defaults.js.map +1 -1
  9. package/configure/lib/design.js +131 -13
  10. package/configure/lib/design.js.map +1 -1
  11. package/configure/lib/index.js +3 -3
  12. package/configure/lib/utils.js +14 -0
  13. package/configure/lib/utils.js.map +1 -0
  14. package/configure/package.json +5 -4
  15. package/controller/CHANGELOG.md +49 -0
  16. package/controller/lib/index.js +42 -9
  17. package/controller/lib/index.js.map +1 -1
  18. package/controller/lib/scoring.js +11 -4
  19. package/controller/lib/scoring.js.map +1 -1
  20. package/controller/package.json +1 -1
  21. package/docs/config-schema.json +124 -0
  22. package/docs/config-schema.json.md +97 -1
  23. package/docs/demo/generate.js +3 -2
  24. package/docs/pie-schema.json +85 -26
  25. package/docs/pie-schema.json.md +62 -27
  26. package/lib/index.js +5 -2
  27. package/lib/index.js.map +1 -1
  28. package/lib/main.js +1 -1
  29. package/lib/main.js.map +1 -1
  30. package/lib/ordering.js +2 -1
  31. package/lib/ordering.js.map +1 -1
  32. package/lib/placement-ordering.js +12 -15
  33. package/lib/placement-ordering.js.map +1 -1
  34. package/lib/tile.js +1 -1
  35. package/lib/tile.js.map +1 -1
  36. package/lib/tiler.js +3 -3
  37. package/lib/tiler.js.map +1 -1
  38. package/package.json +5 -5
  39. package/module/configure.js +0 -1525
  40. package/module/controller.js +0 -20249
  41. package/module/demo.js +0 -79
  42. package/module/element.js +0 -1249
  43. package/module/index.html +0 -16
  44. package/module/manifest.json +0 -10
package/module/element.js DELETED
@@ -1,1249 +0,0 @@
1
- import {_dll_react_dnd, _dll_prop_types, _dll_react, _dll_material_ui__core_styles, _dll_pie_lib__drag, _dll_pie_lib__render_ui, _dll_lodash, _dll_pie_lib__correct_answer_toggle, _dll_react_dom, _dll_pie_lib__math_rendering} from "../../../@pie-ui/shared-lib@^4.3.3/module/index.js";
2
- function createCommonjsModule(fn, module) {
3
- return (module = {
4
- exports: {}
5
- }, fn(module, module.exports), module.exports);
6
- }
7
- var classnames = createCommonjsModule(function (module) {
8
- (function () {
9
- var hasOwn = ({}).hasOwnProperty;
10
- function classNames() {
11
- var classes = [];
12
- for (var i = 0; i < arguments.length; i++) {
13
- var arg = arguments[i];
14
- if (!arg) continue;
15
- var argType = typeof arg;
16
- if (argType === 'string' || argType === 'number') {
17
- classes.push(arg);
18
- } else if (Array.isArray(arg) && arg.length) {
19
- var inner = classNames.apply(null, arg);
20
- if (inner) {
21
- classes.push(inner);
22
- }
23
- } else if (argType === 'object') {
24
- for (var key in arg) {
25
- if (hasOwn.call(arg, key) && arg[key]) {
26
- classes.push(key);
27
- }
28
- }
29
- }
30
- }
31
- return classes.join(' ');
32
- }
33
- if (module.exports) {
34
- classNames.default = classNames;
35
- module.exports = classNames;
36
- } else {
37
- window.classNames = classNames;
38
- }
39
- })();
40
- });
41
- var s = 1000;
42
- var m = s * 60;
43
- var h = m * 60;
44
- var d = h * 24;
45
- var w = d * 7;
46
- var y = d * 365.25;
47
- var ms = function (val, options) {
48
- options = options || ({});
49
- var type = typeof val;
50
- if (type === 'string' && val.length > 0) {
51
- return parse(val);
52
- } else if (type === 'number' && isFinite(val)) {
53
- return options.long ? fmtLong(val) : fmtShort(val);
54
- }
55
- throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
56
- };
57
- function parse(str) {
58
- str = String(str);
59
- if (str.length > 100) {
60
- return;
61
- }
62
- 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(str);
63
- if (!match) {
64
- return;
65
- }
66
- var n = parseFloat(match[1]);
67
- var type = (match[2] || 'ms').toLowerCase();
68
- switch (type) {
69
- case 'years':
70
- case 'year':
71
- case 'yrs':
72
- case 'yr':
73
- case 'y':
74
- return n * y;
75
- case 'weeks':
76
- case 'week':
77
- case 'w':
78
- return n * w;
79
- case 'days':
80
- case 'day':
81
- case 'd':
82
- return n * d;
83
- case 'hours':
84
- case 'hour':
85
- case 'hrs':
86
- case 'hr':
87
- case 'h':
88
- return n * h;
89
- case 'minutes':
90
- case 'minute':
91
- case 'mins':
92
- case 'min':
93
- case 'm':
94
- return n * m;
95
- case 'seconds':
96
- case 'second':
97
- case 'secs':
98
- case 'sec':
99
- case 's':
100
- return n * s;
101
- case 'milliseconds':
102
- case 'millisecond':
103
- case 'msecs':
104
- case 'msec':
105
- case 'ms':
106
- return n;
107
- default:
108
- return undefined;
109
- }
110
- }
111
- function fmtShort(ms) {
112
- var msAbs = Math.abs(ms);
113
- if (msAbs >= d) {
114
- return Math.round(ms / d) + 'd';
115
- }
116
- if (msAbs >= h) {
117
- return Math.round(ms / h) + 'h';
118
- }
119
- if (msAbs >= m) {
120
- return Math.round(ms / m) + 'm';
121
- }
122
- if (msAbs >= s) {
123
- return Math.round(ms / s) + 's';
124
- }
125
- return ms + 'ms';
126
- }
127
- function fmtLong(ms) {
128
- var msAbs = Math.abs(ms);
129
- if (msAbs >= d) {
130
- return plural(ms, msAbs, d, 'day');
131
- }
132
- if (msAbs >= h) {
133
- return plural(ms, msAbs, h, 'hour');
134
- }
135
- if (msAbs >= m) {
136
- return plural(ms, msAbs, m, 'minute');
137
- }
138
- if (msAbs >= s) {
139
- return plural(ms, msAbs, s, 'second');
140
- }
141
- return ms + ' ms';
142
- }
143
- function plural(ms, msAbs, n, name) {
144
- var isPlural = msAbs >= n * 1.5;
145
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
146
- }
147
- function setup(env) {
148
- createDebug.debug = createDebug;
149
- createDebug.default = createDebug;
150
- createDebug.coerce = coerce;
151
- createDebug.disable = disable;
152
- createDebug.enable = enable;
153
- createDebug.enabled = enabled;
154
- createDebug.humanize = ms;
155
- createDebug.destroy = destroy;
156
- Object.keys(env).forEach(key => {
157
- createDebug[key] = env[key];
158
- });
159
- createDebug.names = [];
160
- createDebug.skips = [];
161
- createDebug.formatters = {};
162
- function selectColor(namespace) {
163
- let hash = 0;
164
- for (let i = 0; i < namespace.length; i++) {
165
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
166
- hash |= 0;
167
- }
168
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
169
- }
170
- createDebug.selectColor = selectColor;
171
- function createDebug(namespace) {
172
- let prevTime;
173
- let enableOverride = null;
174
- function debug(...args) {
175
- if (!debug.enabled) {
176
- return;
177
- }
178
- const self = debug;
179
- const curr = Number(new Date());
180
- const ms = curr - (prevTime || curr);
181
- self.diff = ms;
182
- self.prev = prevTime;
183
- self.curr = curr;
184
- prevTime = curr;
185
- args[0] = createDebug.coerce(args[0]);
186
- if (typeof args[0] !== 'string') {
187
- args.unshift('%O');
188
- }
189
- let index = 0;
190
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
191
- if (match === '%%') {
192
- return '%';
193
- }
194
- index++;
195
- const formatter = createDebug.formatters[format];
196
- if (typeof formatter === 'function') {
197
- const val = args[index];
198
- match = formatter.call(self, val);
199
- args.splice(index, 1);
200
- index--;
201
- }
202
- return match;
203
- });
204
- createDebug.formatArgs.call(self, args);
205
- const logFn = self.log || createDebug.log;
206
- logFn.apply(self, args);
207
- }
208
- debug.namespace = namespace;
209
- debug.useColors = createDebug.useColors();
210
- debug.color = createDebug.selectColor(namespace);
211
- debug.extend = extend;
212
- debug.destroy = createDebug.destroy;
213
- Object.defineProperty(debug, 'enabled', {
214
- enumerable: true,
215
- configurable: false,
216
- get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
217
- set: v => {
218
- enableOverride = v;
219
- }
220
- });
221
- if (typeof createDebug.init === 'function') {
222
- createDebug.init(debug);
223
- }
224
- return debug;
225
- }
226
- function extend(namespace, delimiter) {
227
- const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
228
- newDebug.log = this.log;
229
- return newDebug;
230
- }
231
- function enable(namespaces) {
232
- createDebug.save(namespaces);
233
- createDebug.names = [];
234
- createDebug.skips = [];
235
- let i;
236
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
237
- const len = split.length;
238
- for (i = 0; i < len; i++) {
239
- if (!split[i]) {
240
- continue;
241
- }
242
- namespaces = split[i].replace(/\*/g, '.*?');
243
- if (namespaces[0] === '-') {
244
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
245
- } else {
246
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
247
- }
248
- }
249
- }
250
- function disable() {
251
- const namespaces = [...createDebug.names.map(toNamespace), ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)].join(',');
252
- createDebug.enable('');
253
- return namespaces;
254
- }
255
- function enabled(name) {
256
- if (name[name.length - 1] === '*') {
257
- return true;
258
- }
259
- let i;
260
- let len;
261
- for ((i = 0, len = createDebug.skips.length); i < len; i++) {
262
- if (createDebug.skips[i].test(name)) {
263
- return false;
264
- }
265
- }
266
- for ((i = 0, len = createDebug.names.length); i < len; i++) {
267
- if (createDebug.names[i].test(name)) {
268
- return true;
269
- }
270
- }
271
- return false;
272
- }
273
- function toNamespace(regexp) {
274
- return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
275
- }
276
- function coerce(val) {
277
- if (val instanceof Error) {
278
- return val.stack || val.message;
279
- }
280
- return val;
281
- }
282
- function destroy() {
283
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
284
- }
285
- createDebug.enable(createDebug.load());
286
- return createDebug;
287
- }
288
- var common = setup;
289
- var browser = createCommonjsModule(function (module, exports) {
290
- exports.formatArgs = formatArgs;
291
- exports.save = save;
292
- exports.load = load;
293
- exports.useColors = useColors;
294
- exports.storage = localstorage();
295
- exports.destroy = (() => {
296
- let warned = false;
297
- return () => {
298
- if (!warned) {
299
- warned = true;
300
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
301
- }
302
- };
303
- })();
304
- exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
305
- function useColors() {
306
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
307
- return true;
308
- }
309
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
310
- return false;
311
- }
312
- return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
313
- }
314
- function formatArgs(args) {
315
- args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
316
- if (!this.useColors) {
317
- return;
318
- }
319
- const c = 'color: ' + this.color;
320
- args.splice(1, 0, c, 'color: inherit');
321
- let index = 0;
322
- let lastC = 0;
323
- args[0].replace(/%[a-zA-Z%]/g, match => {
324
- if (match === '%%') {
325
- return;
326
- }
327
- index++;
328
- if (match === '%c') {
329
- lastC = index;
330
- }
331
- });
332
- args.splice(lastC, 0, c);
333
- }
334
- exports.log = console.debug || console.log || (() => {});
335
- function save(namespaces) {
336
- try {
337
- if (namespaces) {
338
- exports.storage.setItem('debug', namespaces);
339
- } else {
340
- exports.storage.removeItem('debug');
341
- }
342
- } catch (error) {}
343
- }
344
- function load() {
345
- let r;
346
- try {
347
- r = exports.storage.getItem('debug');
348
- } catch (error) {}
349
- if (!r && typeof process !== 'undefined' && ('env' in process)) {
350
- r = process.env.DEBUG;
351
- }
352
- return r;
353
- }
354
- function localstorage() {
355
- try {
356
- return localStorage;
357
- } catch (error) {}
358
- }
359
- module.exports = common(exports);
360
- const {formatters} = module.exports;
361
- formatters.j = function (v) {
362
- try {
363
- return JSON.stringify(v);
364
- } catch (error) {
365
- return '[UnexpectedJSONParseError]: ' + error.message;
366
- }
367
- };
368
- });
369
- browser.formatArgs;
370
- browser.save;
371
- browser.load;
372
- browser.useColors;
373
- browser.storage;
374
- browser.destroy;
375
- browser.colors;
376
- browser.log;
377
- const {DragSource: DragSource} = _dll_react_dnd;
378
- const {DropTarget: DropTarget} = _dll_react_dnd;
379
- const PropTypes = _dll_prop_types;
380
- const React = _dll_react;
381
- const {withStyles: withStyles} = _dll_material_ui__core_styles;
382
- const {PlaceHolder: PlaceHolder} = _dll_pie_lib__drag;
383
- const {color: color} = _dll_pie_lib__render_ui;
384
- const _jsxFileName = "/home/ede/dev/github/pie-framework/pie-elements/node_modules/@pie-ui/placement-ordering/src/tile.jsx";
385
- const log = browser('pie-elements:placement-ordering:tile');
386
- const Holder = withStyles(() => ({
387
- number: {
388
- width: '100%',
389
- fontSize: '18px',
390
- textAlign: 'center',
391
- color: 'rgba(0,0,0,0.6)'
392
- }
393
- }))(({classes, type, index, isOver, disabled}) => React.createElement(PlaceHolder, {
394
- isOver: isOver,
395
- disabled: disabled,
396
- __self: undefined,
397
- __source: {
398
- fileName: _jsxFileName,
399
- lineNumber: 21
400
- }
401
- }, type === 'target' && index !== undefined && React.createElement('div', {
402
- className: classes.number,
403
- __self: undefined,
404
- __source: {
405
- fileName: _jsxFileName,
406
- lineNumber: 23
407
- }
408
- }, index)));
409
- Holder.propTypes = {
410
- type: PropTypes.string,
411
- index: PropTypes.number,
412
- isOver: PropTypes.bool,
413
- disabled: PropTypes.bool
414
- };
415
- const TileContent = withStyles({
416
- over: {
417
- opacity: 0.2
418
- },
419
- tileContent: {
420
- cursor: 'pointer',
421
- width: '100%',
422
- height: '100%',
423
- padding: '10px',
424
- boxSizing: 'border-box',
425
- overflow: 'hidden',
426
- border: '1px solid #c2c2c2',
427
- backgroundColor: color.background(),
428
- transition: 'opacity 200ms linear',
429
- '&:hover': {
430
- backgroundColor: color.secondary()
431
- }
432
- },
433
- dragging: {
434
- backgroundColor: color.secondaryLight(),
435
- opacity: 0.5
436
- },
437
- disabled: {
438
- opacity: 0.6,
439
- cursor: 'not-allowed',
440
- '&:hover': {
441
- backgroundColor: color.background()
442
- }
443
- },
444
- incorrect: {
445
- border: `1px solid ${color.incorrect()}`
446
- },
447
- correct: {
448
- border: `1px solid ${color.correct()}`
449
- }
450
- })(props => {
451
- const {type, classes, isDragging, empty, isOver, label, disabled, outcome, guideIndex} = props;
452
- if (empty) {
453
- return React.createElement(Holder, {
454
- type: type,
455
- index: guideIndex,
456
- isOver: isOver,
457
- disabled: disabled,
458
- __self: undefined,
459
- __source: {
460
- fileName: _jsxFileName,
461
- lineNumber: 84
462
- }
463
- });
464
- } else {
465
- const names = classnames(classes.tileContent, isDragging && !disabled && classes.dragging, isOver && !disabled && classes.over, disabled && classes.disabled, outcome && classes[outcome]);
466
- return React.createElement('div', {
467
- className: names,
468
- dangerouslySetInnerHTML: {
469
- __html: label
470
- },
471
- __self: undefined,
472
- __source: {
473
- fileName: _jsxFileName,
474
- lineNumber: 100
475
- }
476
- });
477
- }
478
- });
479
- class Tile extends React.Component {
480
- static __initStatic() {
481
- this.propTypes = {
482
- connectDragSource: PropTypes.func.isRequired,
483
- connectDropTarget: PropTypes.func.isRequired,
484
- isDragging: PropTypes.bool.isRequired,
485
- id: PropTypes.any,
486
- label: PropTypes.string,
487
- isOver: PropTypes.bool,
488
- classes: PropTypes.object.isRequired,
489
- type: PropTypes.string,
490
- empty: PropTypes.bool,
491
- disabled: PropTypes.bool,
492
- outcome: PropTypes.string,
493
- index: PropTypes.number,
494
- guideIndex: PropTypes.number
495
- };
496
- }
497
- render() {
498
- const {label, isDragging, connectDragSource, connectDropTarget, classes, isOver, type, id, empty, disabled, outcome, index, guideIndex} = this.props;
499
- log('[render], props: ', this.props);
500
- const name = classnames(classes.title);
501
- const dragSourceOpts = {};
502
- return connectDragSource(connectDropTarget(React.createElement('div', {
503
- className: name,
504
- __self: this,
505
- __source: {
506
- fileName: _jsxFileName,
507
- lineNumber: 149
508
- }
509
- }, React.createElement(TileContent, {
510
- label: label,
511
- id: id,
512
- empty: empty,
513
- index: index,
514
- guideIndex: guideIndex,
515
- isOver: isOver,
516
- isDragging: isDragging,
517
- disabled: disabled,
518
- outcome: outcome,
519
- type: type,
520
- __self: this,
521
- __source: {
522
- fileName: _jsxFileName,
523
- lineNumber: 150
524
- }
525
- }))), dragSourceOpts);
526
- }
527
- }
528
- Tile.__initStatic();
529
- const StyledTile = withStyles({
530
- title: {
531
- boxSizing: 'border-box',
532
- overflow: 'hidden',
533
- margin: '0px',
534
- padding: '0px',
535
- textAlign: 'center'
536
- }
537
- })(Tile);
538
- const tileTarget = {
539
- drop(props, monitor) {
540
- const draggedItem = monitor.getItem();
541
- log('props.instanceId', props.instanceId, 'draggedItem.instanceId:', draggedItem.instanceId);
542
- if (draggedItem.instanceId === props.instanceId) {
543
- props.onDropChoice(draggedItem, props.index);
544
- }
545
- },
546
- canDrop(props, monitor) {
547
- const draggedItem = monitor.getItem();
548
- const canDrop = draggedItem.instanceId === props.instanceId;
549
- return canDrop;
550
- }
551
- };
552
- const DropTile = DropTarget('Tile', tileTarget, (connect, monitor) => ({
553
- connectDropTarget: connect.dropTarget(),
554
- isOver: monitor.isOver()
555
- }))(StyledTile);
556
- const tileSource = {
557
- canDrag(props) {
558
- return props.draggable && !props.disabled;
559
- },
560
- beginDrag(props) {
561
- return {
562
- id: props.id,
563
- type: props.type,
564
- instanceId: props.instanceId
565
- };
566
- },
567
- endDrag(props, monitor) {
568
- if (!monitor.didDrop()) {
569
- if (props.type === 'target') {
570
- props.onRemoveChoice(monitor.getItem());
571
- }
572
- }
573
- }
574
- };
575
- const DragDropTile = DragSource('Tile', tileSource, (connect, monitor) => ({
576
- connectDragSource: connect.dragSource(),
577
- isDragging: monitor.isDragging()
578
- }))(DropTile);
579
- const PropTypes$1 = _dll_prop_types;
580
- const React$1 = _dll_react;
581
- const {withStyles: withStyles$1} = _dll_material_ui__core_styles;
582
- const _jsxFileName$1 = "/home/ede/dev/github/pie-framework/pie-elements/node_modules/@pie-ui/placement-ordering/src/tiler.jsx";
583
- const common$1 = {
584
- tiler: {
585
- display: 'grid',
586
- gridGap: '10px'
587
- }
588
- };
589
- const types = {
590
- choiceLabel: PropTypes$1.string,
591
- targetLabel: PropTypes$1.string,
592
- disabled: PropTypes$1.bool,
593
- onDropChoice: PropTypes$1.func.isRequired,
594
- tiles: PropTypes$1.array.isRequired,
595
- tileSize: PropTypes$1.string,
596
- addGuide: PropTypes$1.bool
597
- };
598
- const defaults = {
599
- tileSize: '1fr',
600
- disabled: false,
601
- addGuide: false
602
- };
603
- const buildTiles = props => {
604
- const T = (tile, index) => {
605
- tile.onDropChoice = (source, index) => props.onDropChoice(tile, source, index);
606
- tile.onRemoveChoice = () => props.onRemoveChoice(tile);
607
- tile.instanceId = props.instanceId;
608
- tile.disabled = props.disabled;
609
- tile.guideIndex = props.addGuide ? tile.index + 1 : undefined;
610
- return React$1.createElement(DragDropTile, {
611
- ...tile,
612
- key: index,
613
- __self: undefined,
614
- __source: {
615
- fileName: _jsxFileName$1,
616
- lineNumber: 37
617
- }
618
- });
619
- };
620
- T.propTypes = {
621
- ...types
622
- };
623
- return T;
624
- };
625
- class HTiler extends React$1.Component {
626
- static __initStatic() {
627
- this.propTypes = {
628
- ...types
629
- };
630
- }
631
- static __initStatic2() {
632
- this.defaultProps = {
633
- ...defaults
634
- };
635
- }
636
- render() {
637
- const {includeTargets, choiceLabel, targetLabel, tiles, classes, tileSize} = this.props;
638
- const rows = includeTargets ? `auto ${tileSize} auto ${tileSize}` : `auto ${tileSize} auto`;
639
- const columns = includeTargets ? tiles.length / 2 : tiles.length;
640
- const style = {
641
- gridTemplateColumns: `repeat(${columns}, ${tileSize})`,
642
- gridTemplateRows: rows
643
- };
644
- const labelStyle = {
645
- gridColumn: `1/${columns + 1}`
646
- };
647
- return React$1.createElement('div', {
648
- className: classes.htiler,
649
- style: style,
650
- __self: this,
651
- __source: {
652
- fileName: _jsxFileName$1,
653
- lineNumber: 72
654
- }
655
- }, React$1.createElement('div', {
656
- className: classes.choiceLabel,
657
- style: labelStyle,
658
- dangerouslySetInnerHTML: {
659
- __html: choiceLabel
660
- },
661
- __self: this,
662
- __source: {
663
- fileName: _jsxFileName$1,
664
- lineNumber: 73
665
- }
666
- }), includeTargets && React$1.createElement('div', {
667
- className: classes.targetLabel,
668
- style: labelStyle,
669
- dangerouslySetInnerHTML: {
670
- __html: targetLabel
671
- },
672
- __self: this,
673
- __source: {
674
- fileName: _jsxFileName$1,
675
- lineNumber: 80
676
- }
677
- }), tiles.map(buildTiles(this.props)));
678
- }
679
- }
680
- HTiler.__initStatic();
681
- HTiler.__initStatic2();
682
- const horizontalStyles = {
683
- htiler: common$1.tiler,
684
- choiceLabel: {
685
- textAlign: 'center'
686
- },
687
- targetLabel: {
688
- textAlign: 'center',
689
- gridRow: '3/4'
690
- }
691
- };
692
- const HorizontalTiler = withStyles$1(horizontalStyles)(HTiler);
693
- class VTiler extends React$1.Component {
694
- static __initStatic3() {
695
- this.propTypes = {
696
- ...types
697
- };
698
- }
699
- static __initStatic4() {
700
- this.defaultProps = {
701
- ...defaults
702
- };
703
- }
704
- render() {
705
- const {includeTargets, choiceLabel, targetLabel, tiles, classes, tileSize} = this.props;
706
- const columns = includeTargets ? 2 : 1;
707
- const rows = includeTargets ? tiles.length / 2 : tiles.length;
708
- const style = {
709
- gridTemplateColumns: `repeat(${columns}, ${tileSize})`,
710
- gridTemplateRows: `auto repeat(${rows}, ${tileSize})`
711
- };
712
- return React$1.createElement('div', {
713
- className: classes.vtiler,
714
- style: style,
715
- __self: this,
716
- __source: {
717
- fileName: _jsxFileName$1,
718
- lineNumber: 127
719
- }
720
- }, React$1.createElement('div', {
721
- className: classes.choiceLabel,
722
- dangerouslySetInnerHTML: {
723
- __html: choiceLabel
724
- },
725
- __self: this,
726
- __source: {
727
- fileName: _jsxFileName$1,
728
- lineNumber: 128
729
- }
730
- }), includeTargets && React$1.createElement('div', {
731
- className: classes.targetLabel,
732
- dangerouslySetInnerHTML: {
733
- __html: targetLabel
734
- },
735
- __self: this,
736
- __source: {
737
- fileName: _jsxFileName$1,
738
- lineNumber: 134
739
- }
740
- }), tiles.map(buildTiles(this.props)));
741
- }
742
- }
743
- VTiler.__initStatic3();
744
- VTiler.__initStatic4();
745
- const verticalStyles = {
746
- vtiler: {
747
- gridAutoFlow: 'column',
748
- ...common$1.tiler
749
- },
750
- choiceLabel: {
751
- gridColumn: '1/2',
752
- textAlign: 'center'
753
- },
754
- targetLabel: {
755
- gridColumn: '2/3',
756
- textAlign: 'center'
757
- }
758
- };
759
- const VerticalTiler = withStyles$1(verticalStyles)(VTiler);
760
- const {cloneDeep: cloneDeep} = _dll_lodash;
761
- const {isEmpty: isEmpty} = _dll_lodash;
762
- const {map: map} = _dll_lodash;
763
- const {assign: assign} = _dll_lodash;
764
- const log$1 = browser('pie-elements:placement-ordering:ordering');
765
- const swap = (arr, fromIndex, toIndex) => {
766
- log$1('[swap]', arr, fromIndex, toIndex);
767
- if (!arr || arr.length <= 1 || fromIndex === undefined || toIndex === undefined) {
768
- throw new Error(`swap requires a non-empty array, fromIndex, toIndex: ${arr}, ${fromIndex} ${toIndex}`);
769
- }
770
- const update = cloneDeep(arr);
771
- const tmp = arr[toIndex];
772
- update[toIndex] = update[fromIndex];
773
- update[fromIndex] = tmp;
774
- return update;
775
- };
776
- function removeResponse(state, targetTile) {
777
- const update = cloneDeep(state.response);
778
- if (update[targetTile.index] === targetTile.id) {
779
- update[targetTile.index] = undefined;
780
- } else {
781
- throw new Error(`Tried to remove from index: ${targetTile.index}, but the id doesn't match: array: ${update}, target: ${targetTile.id}`);
782
- }
783
- return update;
784
- }
785
- function updateResponse(state, from, to) {
786
- const {response, opts} = state;
787
- const update = cloneDeep(response);
788
- if (opts.includeTargets) {
789
- if (from.type === 'choice' && to.type === 'target') {
790
- update[to.index] = from.id;
791
- return update;
792
- } else if (from.type === 'target' && to.type === 'choice') {
793
- update[from.index] = undefined;
794
- return update;
795
- } else if (from.type === 'target' && to.type === 'target') {
796
- return swap(response, from.index, to.index);
797
- } else {
798
- log$1('do nothing to the response');
799
- return response;
800
- }
801
- } else {
802
- const fromIndex = state.response.findIndex(r => r !== undefined && r === from.id);
803
- const toIndex = state.response.findIndex(r => r !== undefined && r === to.id);
804
- log$1('fromIndex: ', fromIndex, 'toIndex:', toIndex);
805
- return swap(state.response, fromIndex, toIndex);
806
- }
807
- }
808
- function buildTiles$1(choices, response, outcomes, opts) {
809
- if (opts.includeTargets) {
810
- const targets = [];
811
- for (var i = 0; i < response.length; i++) {
812
- const r = response[i];
813
- const choice = choices.find(c => r !== undefined && r !== null && c.id === r);
814
- const outcome = outcomes[i];
815
- const out = Object.assign({
816
- type: 'target',
817
- index: i,
818
- empty: choice === undefined
819
- }, choice, outcome, {
820
- draggable: choice !== undefined
821
- });
822
- targets.push(out);
823
- }
824
- const processedChoices = choices.map(m => {
825
- if (response.indexOf(m.id) !== -1 && !opts.allowSameChoiceInTargets) {
826
- return {
827
- type: 'choice',
828
- empty: true,
829
- droppable: true,
830
- draggable: false
831
- };
832
- } else {
833
- return Object.assign({}, m, {
834
- type: 'choice',
835
- droppable: false,
836
- draggable: true
837
- });
838
- }
839
- });
840
- return processedChoices.concat(targets);
841
- } else {
842
- return response.map((id, index) => {
843
- return Object.assign({
844
- type: 'choice',
845
- draggable: true,
846
- droppable: true
847
- }, choices.find(m => m.id === id), outcomes[index]);
848
- });
849
- }
850
- }
851
- function buildState(choices, response, outcomes, opts) {
852
- opts = assign({
853
- includeTargets: true
854
- }, opts);
855
- outcomes = outcomes || [];
856
- response = !response || isEmpty(response) ? opts.includeTargets ? new Array(choices.length) : map(choices, c => c.id) : response;
857
- return {
858
- choices,
859
- response,
860
- opts,
861
- outcomes,
862
- tiles: buildTiles$1(choices, response, outcomes, opts)
863
- };
864
- }
865
- function reducer(action, state) {
866
- switch (action.type) {
867
- case 'move':
868
- {
869
- const {from, to} = action;
870
- const response = updateResponse(state, from, to);
871
- const tiles = buildTiles$1(state.choices, response, state.outcomes, state.opts);
872
- return Object.assign({}, state, {
873
- response,
874
- tiles
875
- });
876
- }
877
- case 'remove':
878
- {
879
- const {target} = action;
880
- const response = removeResponse(state, target);
881
- const tiles = buildTiles$1(state.choices, response, state.outcomes, state.opts);
882
- return Object.assign({}, state, {
883
- response,
884
- tiles
885
- });
886
- }
887
- }
888
- return state;
889
- }
890
- const {color: color$1} = _dll_pie_lib__render_ui;
891
- const {Feedback: Feedback} = _dll_pie_lib__render_ui;
892
- const {Collapsible: Collapsible} = _dll_pie_lib__render_ui;
893
- const {hasText: hasText} = _dll_pie_lib__render_ui;
894
- const CorrectAnswerToggle = _dll_pie_lib__correct_answer_toggle;
895
- const PropTypes$2 = _dll_prop_types;
896
- const React$2 = _dll_react;
897
- const {cloneDeep: cloneDeep$1} = _dll_lodash;
898
- const {compact: compact} = _dll_lodash;
899
- const {uniqueId: uniqueId} = _dll_lodash;
900
- const {withStyles: withStyles$2} = _dll_material_ui__core_styles;
901
- const _jsxFileName$2 = "/home/ede/dev/github/pie-framework/pie-elements/node_modules/@pie-ui/placement-ordering/src/placement-ordering.jsx";
902
- const log$2 = browser('pie-elements:placement-ordering');
903
- const OrderingTiler = props => {
904
- const {tiler: Comp, ordering, onDropChoice, onRemoveChoice, ...compProps} = props;
905
- return React$2.createElement(Comp, {
906
- ...compProps,
907
- tiles: ordering.tiles,
908
- onDropChoice: (t, s) => onDropChoice(t, s, ordering),
909
- onRemoveChoice: t => onRemoveChoice(t, ordering),
910
- __self: undefined,
911
- __source: {
912
- fileName: _jsxFileName$2,
913
- lineNumber: 25
914
- }
915
- });
916
- };
917
- OrderingTiler.propTypes = {
918
- tiler: PropTypes$2.func,
919
- ordering: PropTypes$2.any,
920
- onDropChoice: PropTypes$2.func,
921
- onRemoveChoice: PropTypes$2.func
922
- };
923
- class PlacementOrdering extends React$2.Component {
924
- static __initStatic() {
925
- this.propTypes = {
926
- onSessionChange: PropTypes$2.func.isRequired,
927
- model: PropTypes$2.object.isRequired,
928
- session: PropTypes$2.oneOfType([PropTypes$2.array.isRequired, PropTypes$2.object.isRequired]),
929
- classes: PropTypes$2.object.isRequired
930
- };
931
- }
932
- constructor(props) {
933
- super(props);
934
- PlacementOrdering.prototype.__init.call(this);
935
- PlacementOrdering.prototype.__init2.call(this);
936
- PlacementOrdering.prototype.__init3.call(this);
937
- this.state = {
938
- showingCorrect: false
939
- };
940
- this.instanceId = uniqueId();
941
- this.toggleCorrect = showingCorrect => {
942
- this.setState({
943
- showingCorrect
944
- });
945
- };
946
- }
947
- componentDidMount() {
948
- this.initSessionIfNeeded(this.props);
949
- }
950
- UNSAFE_componentWillReceiveProps(nextProps) {
951
- const newState = {};
952
- if (!nextProps.model.correctResponse) {
953
- newState.showingCorrect = false;
954
- }
955
- const includeTargetsChanged = nextProps.model.config.includeTargets !== this.props.model.config.includeTargets;
956
- const choicesNumberChanged = nextProps.model.choices.length !== this.props.model.choices.length;
957
- if (includeTargetsChanged || choicesNumberChanged) {
958
- this.initSessionIfNeeded(nextProps);
959
- }
960
- this.setState(newState);
961
- }
962
- initSessionIfNeeded(props) {
963
- const {model, session, onSessionChange} = props;
964
- const {config: newConfig} = model;
965
- const compactSessionValues = session && compact(session.value) || [];
966
- if (!newConfig.includeTargets && compactSessionValues.length !== model.choices.length) {
967
- log$2('[initSessionIfNeeded] initing session...', newConfig.includeTargets);
968
- const update = cloneDeep$1(session);
969
- update.value = model.choices.map(m => m.id);
970
- onSessionChange(update);
971
- } else if (newConfig.includeTargets) {
972
- const update = cloneDeep$1(session);
973
- delete update.value;
974
- onSessionChange(update);
975
- }
976
- }
977
- __init() {
978
- this.onDropChoice = (target, source, ordering) => {
979
- const {onSessionChange, session} = this.props;
980
- const from = ordering.tiles.find(t => t.id === source.id && t.type === source.type);
981
- const to = target;
982
- log$2('[onDropChoice] ', from, to);
983
- const update = reducer({
984
- type: 'move',
985
- from,
986
- to
987
- }, ordering);
988
- const sessionUpdate = Object.assign({}, session, {
989
- value: update.response
990
- });
991
- onSessionChange(sessionUpdate);
992
- };
993
- }
994
- __init2() {
995
- this.onRemoveChoice = (target, ordering) => {
996
- const {onSessionChange, session} = this.props;
997
- log$2('[onRemoveChoice]', target);
998
- const update = reducer({
999
- type: 'remove',
1000
- target
1001
- }, ordering);
1002
- const sessionUpdate = Object.assign({}, session, {
1003
- value: update.response
1004
- });
1005
- onSessionChange(sessionUpdate);
1006
- };
1007
- }
1008
- __init3() {
1009
- this.createOrdering = () => {
1010
- const {model, session} = this.props;
1011
- const {showingCorrect} = this.state;
1012
- const config = model.config || ({
1013
- orientation: 'vertical',
1014
- includeTargets: true
1015
- });
1016
- const {includeTargets} = config;
1017
- return showingCorrect ? buildState(model.choices, model.correctResponse, model.correctResponse.map(id => ({
1018
- id,
1019
- outcome: 'correct'
1020
- })), {
1021
- includeTargets,
1022
- allowSameChoiceInTargets: model.config.allowSameChoiceInTargets
1023
- }) : buildState(model.choices, session.value, model.outcomes, {
1024
- includeTargets,
1025
- allowSameChoiceInTargets: model.config.allowSameChoiceInTargets
1026
- });
1027
- };
1028
- }
1029
- render() {
1030
- const {classes, model} = this.props;
1031
- const showToggle = model.correctResponse && model.correctResponse.length > 0;
1032
- const {showingCorrect} = this.state;
1033
- const config = model.config || ({
1034
- orientation: 'vertical',
1035
- includeTargets: true
1036
- });
1037
- const {orientation, includeTargets} = config;
1038
- const vertical = orientation === 'vertical';
1039
- const ordering = this.createOrdering();
1040
- const Tiler = vertical ? VerticalTiler : HorizontalTiler;
1041
- return React$2.createElement('div', {
1042
- className: classes.placementOrdering,
1043
- __self: this,
1044
- __source: {
1045
- fileName: _jsxFileName$2,
1046
- lineNumber: 178
1047
- }
1048
- }, model.teacherInstructions && hasText(model.teacherInstructions) && React$2.createElement(Collapsible, {
1049
- labels: {
1050
- hidden: 'Show Teacher Instructions',
1051
- visible: 'Hide Teacher Instructions'
1052
- },
1053
- className: classes.collapsible,
1054
- __self: this,
1055
- __source: {
1056
- fileName: _jsxFileName$2,
1057
- lineNumber: 181
1058
- }
1059
- }, React$2.createElement('div', {
1060
- dangerouslySetInnerHTML: {
1061
- __html: model.teacherInstructions
1062
- },
1063
- __self: this,
1064
- __source: {
1065
- fileName: _jsxFileName$2,
1066
- lineNumber: 185
1067
- }
1068
- })), React$2.createElement('br', {
1069
- __self: this,
1070
- __source: {
1071
- fileName: _jsxFileName$2,
1072
- lineNumber: 189
1073
- }
1074
- }), React$2.createElement(CorrectAnswerToggle, {
1075
- show: showToggle,
1076
- toggled: this.state.showingCorrect,
1077
- onToggle: this.toggleCorrect,
1078
- __self: this,
1079
- __source: {
1080
- fileName: _jsxFileName$2,
1081
- lineNumber: 190
1082
- }
1083
- }), React$2.createElement('div', {
1084
- className: classes.prompt,
1085
- dangerouslySetInnerHTML: {
1086
- __html: model.prompt
1087
- },
1088
- __self: this,
1089
- __source: {
1090
- fileName: _jsxFileName$2,
1091
- lineNumber: 195
1092
- }
1093
- }), React$2.createElement(OrderingTiler, {
1094
- instanceId: this.instanceId,
1095
- choiceLabel: config.choiceLabel,
1096
- targetLabel: config.targetLabel,
1097
- ordering: ordering,
1098
- tiler: Tiler,
1099
- disabled: model.disabled,
1100
- addGuide: model.config.showOrdering,
1101
- tileSize: model.config && model.config.tileSize,
1102
- includeTargets: includeTargets,
1103
- onDropChoice: this.onDropChoice,
1104
- onRemoveChoice: this.onRemoveChoice,
1105
- __self: this,
1106
- __source: {
1107
- fileName: _jsxFileName$2,
1108
- lineNumber: 199
1109
- }
1110
- }), React$2.createElement('br', {
1111
- __self: this,
1112
- __source: {
1113
- fileName: _jsxFileName$2,
1114
- lineNumber: 212
1115
- }
1116
- }), model.rationale && hasText(model.rationale) && React$2.createElement(Collapsible, {
1117
- labels: {
1118
- hidden: 'Show Rationale',
1119
- visible: 'Hide Rationale'
1120
- },
1121
- className: classes.collapsible,
1122
- __self: this,
1123
- __source: {
1124
- fileName: _jsxFileName$2,
1125
- lineNumber: 215
1126
- }
1127
- }, React$2.createElement('div', {
1128
- dangerouslySetInnerHTML: {
1129
- __html: model.rationale
1130
- },
1131
- __self: this,
1132
- __source: {
1133
- fileName: _jsxFileName$2,
1134
- lineNumber: 219
1135
- }
1136
- })), !showingCorrect && React$2.createElement(Feedback, {
1137
- correctness: model.correctness,
1138
- feedback: model.feedback,
1139
- __self: this,
1140
- __source: {
1141
- fileName: _jsxFileName$2,
1142
- lineNumber: 224
1143
- }
1144
- }));
1145
- }
1146
- }
1147
- PlacementOrdering.__initStatic();
1148
- const styles = theme => ({
1149
- placementOrdering: {
1150
- color: color$1.text(),
1151
- backgroundColor: color$1.background(),
1152
- display: 'flex',
1153
- flexDirection: 'column',
1154
- alignItems: 'center',
1155
- boxSizing: 'border-box',
1156
- paddingBottom: theme.spacing.unit
1157
- },
1158
- prompt: {
1159
- padding: '5px',
1160
- paddingBottom: '15px'
1161
- },
1162
- collapsible: {
1163
- paddingTop: theme.spacing.unit * 2,
1164
- paddingBottom: theme.spacing.unit * 2,
1165
- alignSelf: 'flex-start'
1166
- }
1167
- });
1168
- var PlacementOrdering$1 = withStyles$2(styles)(PlacementOrdering);
1169
- const React$3 = _dll_react;
1170
- const {withDragContext: withDragContext} = _dll_pie_lib__drag;
1171
- const PropTypes$3 = _dll_prop_types;
1172
- const _jsxFileName$3 = "/home/ede/dev/github/pie-framework/pie-elements/node_modules/@pie-ui/placement-ordering/src/main.jsx";
1173
- class Main extends React$3.Component {
1174
- static __initStatic() {
1175
- this.propTypes = {
1176
- model: PropTypes$3.object.isRequired,
1177
- session: PropTypes$3.oneOfType([PropTypes$3.array.isRequired, PropTypes$3.object.isRequired]),
1178
- onSessionChange: PropTypes$3.func.isRequired
1179
- };
1180
- }
1181
- render() {
1182
- const {model, session, onSessionChange} = this.props;
1183
- return React$3.createElement(PlacementOrdering$1, {
1184
- model: model,
1185
- session: session,
1186
- onSessionChange: onSessionChange,
1187
- __self: this,
1188
- __source: {
1189
- fileName: _jsxFileName$3,
1190
- lineNumber: 20
1191
- }
1192
- });
1193
- }
1194
- }
1195
- Main.__initStatic();
1196
- const out = withDragContext(Main);
1197
- const React$4 = _dll_react;
1198
- const ReactDOM = _dll_react_dom;
1199
- const {compact: compact$1} = _dll_lodash;
1200
- const {renderMath: renderMath} = _dll_pie_lib__math_rendering;
1201
- const {withDragContext: withDragContext$1} = _dll_pie_lib__drag;
1202
- const log$3 = browser('pie-elements:placement-ordering');
1203
- class Ordering extends HTMLElement {
1204
- constructor() {
1205
- super();
1206
- this.sessionChange = this.sessionChange.bind(this);
1207
- }
1208
- render() {
1209
- if (this._model && this._session) {
1210
- log$3('[render] session: ', this._session);
1211
- log$3('[render] model: ', this._model);
1212
- const element = React$4.createElement(out, {
1213
- model: this._model,
1214
- session: this._session,
1215
- onSessionChange: this.sessionChange
1216
- });
1217
- ReactDOM.render(element, this, () => {
1218
- renderMath(this);
1219
- });
1220
- }
1221
- }
1222
- sessionChange(session) {
1223
- this._session.value = session.value;
1224
- this.render();
1225
- this.dispatchEvent(new CustomEvent('session-changed', {
1226
- bubbles: true,
1227
- detail: {
1228
- component: this.tagName.toLowerCase(),
1229
- complete: this._session && this._session.value && compact$1(this._session.value).length === this._model.completeLength
1230
- }
1231
- }));
1232
- }
1233
- set model(newModel) {
1234
- this._model = newModel;
1235
- this.render();
1236
- this.dispatchEvent(new CustomEvent('model-set', {
1237
- bubbles: true,
1238
- detail: {
1239
- complete: false
1240
- }
1241
- }));
1242
- }
1243
- set session(newSession) {
1244
- this._session = newSession;
1245
- this.render();
1246
- }
1247
- }
1248
- export default Ordering;
1249
- export {swap, withDragContext$1 as withDragContext};