@pie-element/drawing-response 3.7.2 → 3.7.3-next.1008

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 (72) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/configure/CHANGELOG.md +117 -0
  3. package/configure/lib/defaults.js +18 -3
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/image-container.js +23 -14
  6. package/configure/lib/image-container.js.map +1 -1
  7. package/configure/lib/index.js +3 -9
  8. package/configure/lib/index.js.map +1 -1
  9. package/configure/lib/root.js +44 -11
  10. package/configure/lib/root.js.map +1 -1
  11. package/configure/package.json +3 -3
  12. package/configure/src/__tests__/__snapshots__/image-container.test.jsx.snap +3 -2
  13. package/configure/src/__tests__/__snapshots__/root.test.jsx.snap +22 -14
  14. package/configure/src/defaults.js +17 -2
  15. package/configure/src/image-container.jsx +71 -45
  16. package/configure/src/index.js +0 -6
  17. package/configure/src/root.jsx +53 -24
  18. package/controller/CHANGELOG.md +24 -0
  19. package/controller/lib/index.js +13 -9
  20. package/controller/lib/index.js.map +1 -1
  21. package/controller/package.json +1 -1
  22. package/controller/src/__tests__/index.test.js +18 -9
  23. package/controller/src/index.js +4 -1
  24. package/docs/config-schema.json +79 -0
  25. package/docs/config-schema.json.md +61 -1
  26. package/docs/demo/generate.js +2 -0
  27. package/docs/pie-schema.json +43 -0
  28. package/docs/pie-schema.json.md +35 -0
  29. package/lib/drawing-response/container.js +65 -15
  30. package/lib/drawing-response/container.js.map +1 -1
  31. package/lib/drawing-response/drawable-circle.js +1 -1
  32. package/lib/drawing-response/drawable-circle.js.map +1 -1
  33. package/lib/drawing-response/drawable-eraser.js +1 -1
  34. package/lib/drawing-response/drawable-eraser.js.map +1 -1
  35. package/lib/drawing-response/drawable-free-path.js +1 -1
  36. package/lib/drawing-response/drawable-free-path.js.map +1 -1
  37. package/lib/drawing-response/drawable-helper.js.map +1 -1
  38. package/lib/drawing-response/drawable-image.js +1 -0
  39. package/lib/drawing-response/drawable-image.js.map +1 -1
  40. package/lib/drawing-response/drawable-line.js +1 -1
  41. package/lib/drawing-response/drawable-line.js.map +1 -1
  42. package/lib/drawing-response/drawable-main.js +37 -14
  43. package/lib/drawing-response/drawable-main.js.map +1 -1
  44. package/lib/drawing-response/drawable-palette.js +1 -1
  45. package/lib/drawing-response/drawable-palette.js.map +1 -1
  46. package/lib/drawing-response/drawable-rectangle.js +1 -1
  47. package/lib/drawing-response/drawable-rectangle.js.map +1 -1
  48. package/lib/drawing-response/drawable-text.js +15 -5
  49. package/lib/drawing-response/drawable-text.js.map +1 -1
  50. package/lib/drawing-response/drawable-transformer.js +1 -1
  51. package/lib/drawing-response/drawable-transformer.js.map +1 -1
  52. package/lib/drawing-response/index.js +9 -9
  53. package/lib/drawing-response/index.js.map +1 -1
  54. package/lib/index.js +4 -1
  55. package/lib/index.js.map +1 -1
  56. package/package.json +4 -4
  57. package/src/drawing-response/__tests__/__snapshots__/container.test.jsx.snap +18 -130
  58. package/src/drawing-response/__tests__/__snapshots__/drawing-main.test.jsx.snap +26 -2
  59. package/src/drawing-response/__tests__/container.test.jsx +7 -0
  60. package/src/drawing-response/__tests__/drawing-main.test.jsx +2 -1
  61. package/src/drawing-response/container.jsx +55 -15
  62. package/src/drawing-response/drawable-image.jsx +1 -0
  63. package/src/drawing-response/drawable-main.jsx +39 -15
  64. package/src/drawing-response/drawable-text.jsx +7 -1
  65. package/src/drawing-response/index.jsx +6 -4
  66. package/src/index.js +5 -0
  67. package/module/configure.js +0 -1099
  68. package/module/controller.js +0 -66
  69. package/module/demo.js +0 -38
  70. package/module/element.js +0 -1893
  71. package/module/index.html +0 -16
  72. package/module/manifest.json +0 -14
@@ -1,1099 +0,0 @@
1
- import {_dll_pie_lib__config_ui, _dll_pie_lib__editable_html, _dll_pie_framework__pie_configure_events} from "../../shared-config@^1.8.13/module/index.js";
2
- import {_dll_prop_types, _dll_material_ui__core_styles, _dll_react, _dll_material_ui__core, _dll_lodash, _dll_react_dom} from "../../../@pie-ui/shared-lib@^4.3.3/module/index.js";
3
- function createCommonjsModule(fn, module) {
4
- return (module = {
5
- exports: {}
6
- }, fn(module, module.exports), module.exports);
7
- }
8
- var s = 1000;
9
- var m = s * 60;
10
- var h = m * 60;
11
- var d = h * 24;
12
- var w = d * 7;
13
- var y = d * 365.25;
14
- var ms = function (val, options) {
15
- options = options || ({});
16
- var type = typeof val;
17
- if (type === 'string' && val.length > 0) {
18
- return parse(val);
19
- } else if (type === 'number' && isFinite(val)) {
20
- return options.long ? fmtLong(val) : fmtShort(val);
21
- }
22
- throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
23
- };
24
- function parse(str) {
25
- str = String(str);
26
- if (str.length > 100) {
27
- return;
28
- }
29
- 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);
30
- if (!match) {
31
- return;
32
- }
33
- var n = parseFloat(match[1]);
34
- var type = (match[2] || 'ms').toLowerCase();
35
- switch (type) {
36
- case 'years':
37
- case 'year':
38
- case 'yrs':
39
- case 'yr':
40
- case 'y':
41
- return n * y;
42
- case 'weeks':
43
- case 'week':
44
- case 'w':
45
- return n * w;
46
- case 'days':
47
- case 'day':
48
- case 'd':
49
- return n * d;
50
- case 'hours':
51
- case 'hour':
52
- case 'hrs':
53
- case 'hr':
54
- case 'h':
55
- return n * h;
56
- case 'minutes':
57
- case 'minute':
58
- case 'mins':
59
- case 'min':
60
- case 'm':
61
- return n * m;
62
- case 'seconds':
63
- case 'second':
64
- case 'secs':
65
- case 'sec':
66
- case 's':
67
- return n * s;
68
- case 'milliseconds':
69
- case 'millisecond':
70
- case 'msecs':
71
- case 'msec':
72
- case 'ms':
73
- return n;
74
- default:
75
- return undefined;
76
- }
77
- }
78
- function fmtShort(ms) {
79
- var msAbs = Math.abs(ms);
80
- if (msAbs >= d) {
81
- return Math.round(ms / d) + 'd';
82
- }
83
- if (msAbs >= h) {
84
- return Math.round(ms / h) + 'h';
85
- }
86
- if (msAbs >= m) {
87
- return Math.round(ms / m) + 'm';
88
- }
89
- if (msAbs >= s) {
90
- return Math.round(ms / s) + 's';
91
- }
92
- return ms + 'ms';
93
- }
94
- function fmtLong(ms) {
95
- var msAbs = Math.abs(ms);
96
- if (msAbs >= d) {
97
- return plural(ms, msAbs, d, 'day');
98
- }
99
- if (msAbs >= h) {
100
- return plural(ms, msAbs, h, 'hour');
101
- }
102
- if (msAbs >= m) {
103
- return plural(ms, msAbs, m, 'minute');
104
- }
105
- if (msAbs >= s) {
106
- return plural(ms, msAbs, s, 'second');
107
- }
108
- return ms + ' ms';
109
- }
110
- function plural(ms, msAbs, n, name) {
111
- var isPlural = msAbs >= n * 1.5;
112
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
113
- }
114
- function setup(env) {
115
- createDebug.debug = createDebug;
116
- createDebug.default = createDebug;
117
- createDebug.coerce = coerce;
118
- createDebug.disable = disable;
119
- createDebug.enable = enable;
120
- createDebug.enabled = enabled;
121
- createDebug.humanize = ms;
122
- Object.keys(env).forEach(function (key) {
123
- createDebug[key] = env[key];
124
- });
125
- createDebug.instances = [];
126
- createDebug.names = [];
127
- createDebug.skips = [];
128
- createDebug.formatters = {};
129
- function selectColor(namespace) {
130
- var hash = 0;
131
- for (var i = 0; i < namespace.length; i++) {
132
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
133
- hash |= 0;
134
- }
135
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
136
- }
137
- createDebug.selectColor = selectColor;
138
- function createDebug(namespace) {
139
- var prevTime;
140
- function debug() {
141
- if (!debug.enabled) {
142
- return;
143
- }
144
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
145
- args[_key] = arguments[_key];
146
- }
147
- var self = debug;
148
- var curr = Number(new Date());
149
- var ms = curr - (prevTime || curr);
150
- self.diff = ms;
151
- self.prev = prevTime;
152
- self.curr = curr;
153
- prevTime = curr;
154
- args[0] = createDebug.coerce(args[0]);
155
- if (typeof args[0] !== 'string') {
156
- args.unshift('%O');
157
- }
158
- var index = 0;
159
- args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
160
- if (match === '%%') {
161
- return match;
162
- }
163
- index++;
164
- var formatter = createDebug.formatters[format];
165
- if (typeof formatter === 'function') {
166
- var val = args[index];
167
- match = formatter.call(self, val);
168
- args.splice(index, 1);
169
- index--;
170
- }
171
- return match;
172
- });
173
- createDebug.formatArgs.call(self, args);
174
- var logFn = self.log || createDebug.log;
175
- logFn.apply(self, args);
176
- }
177
- debug.namespace = namespace;
178
- debug.enabled = createDebug.enabled(namespace);
179
- debug.useColors = createDebug.useColors();
180
- debug.color = selectColor(namespace);
181
- debug.destroy = destroy;
182
- debug.extend = extend;
183
- if (typeof createDebug.init === 'function') {
184
- createDebug.init(debug);
185
- }
186
- createDebug.instances.push(debug);
187
- return debug;
188
- }
189
- function destroy() {
190
- var index = createDebug.instances.indexOf(this);
191
- if (index !== -1) {
192
- createDebug.instances.splice(index, 1);
193
- return true;
194
- }
195
- return false;
196
- }
197
- function extend(namespace, delimiter) {
198
- return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
199
- }
200
- function enable(namespaces) {
201
- createDebug.save(namespaces);
202
- createDebug.names = [];
203
- createDebug.skips = [];
204
- var i;
205
- var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
206
- var len = split.length;
207
- for (i = 0; i < len; i++) {
208
- if (!split[i]) {
209
- continue;
210
- }
211
- namespaces = split[i].replace(/\*/g, '.*?');
212
- if (namespaces[0] === '-') {
213
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
214
- } else {
215
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
216
- }
217
- }
218
- for (i = 0; i < createDebug.instances.length; i++) {
219
- var instance = createDebug.instances[i];
220
- instance.enabled = createDebug.enabled(instance.namespace);
221
- }
222
- }
223
- function disable() {
224
- createDebug.enable('');
225
- }
226
- function enabled(name) {
227
- if (name[name.length - 1] === '*') {
228
- return true;
229
- }
230
- var i;
231
- var len;
232
- for ((i = 0, len = createDebug.skips.length); i < len; i++) {
233
- if (createDebug.skips[i].test(name)) {
234
- return false;
235
- }
236
- }
237
- for ((i = 0, len = createDebug.names.length); i < len; i++) {
238
- if (createDebug.names[i].test(name)) {
239
- return true;
240
- }
241
- }
242
- return false;
243
- }
244
- function coerce(val) {
245
- if (val instanceof Error) {
246
- return val.stack || val.message;
247
- }
248
- return val;
249
- }
250
- createDebug.enable(createDebug.load());
251
- return createDebug;
252
- }
253
- var common = setup;
254
- var browser = createCommonjsModule(function (module, exports) {
255
- function _typeof(obj) {
256
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
257
- _typeof = function _typeof(obj) {
258
- return typeof obj;
259
- };
260
- } else {
261
- _typeof = function _typeof(obj) {
262
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
263
- };
264
- }
265
- return _typeof(obj);
266
- }
267
- exports.log = log;
268
- exports.formatArgs = formatArgs;
269
- exports.save = save;
270
- exports.load = load;
271
- exports.useColors = useColors;
272
- exports.storage = localstorage();
273
- 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'];
274
- function useColors() {
275
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
276
- return true;
277
- }
278
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
279
- return false;
280
- }
281
- 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+)/);
282
- }
283
- function formatArgs(args) {
284
- args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
285
- if (!this.useColors) {
286
- return;
287
- }
288
- var c = 'color: ' + this.color;
289
- args.splice(1, 0, c, 'color: inherit');
290
- var index = 0;
291
- var lastC = 0;
292
- args[0].replace(/%[a-zA-Z%]/g, function (match) {
293
- if (match === '%%') {
294
- return;
295
- }
296
- index++;
297
- if (match === '%c') {
298
- lastC = index;
299
- }
300
- });
301
- args.splice(lastC, 0, c);
302
- }
303
- function log() {
304
- var _console;
305
- return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
306
- }
307
- function save(namespaces) {
308
- try {
309
- if (namespaces) {
310
- exports.storage.setItem('debug', namespaces);
311
- } else {
312
- exports.storage.removeItem('debug');
313
- }
314
- } catch (error) {}
315
- }
316
- function load() {
317
- var r;
318
- try {
319
- r = exports.storage.getItem('debug');
320
- } catch (error) {}
321
- if (!r && typeof process !== 'undefined' && ('env' in process)) {
322
- r = process.env.DEBUG;
323
- }
324
- return r;
325
- }
326
- function localstorage() {
327
- try {
328
- return localStorage;
329
- } catch (error) {}
330
- }
331
- module.exports = common(exports);
332
- var formatters = module.exports.formatters;
333
- formatters.j = function (v) {
334
- try {
335
- return JSON.stringify(v);
336
- } catch (error) {
337
- return '[UnexpectedJSONParseError]: ' + error.message;
338
- }
339
- };
340
- });
341
- browser.log;
342
- browser.formatArgs;
343
- browser.save;
344
- browser.load;
345
- browser.useColors;
346
- browser.storage;
347
- browser.colors;
348
- var classnames = createCommonjsModule(function (module) {
349
- (function () {
350
- var hasOwn = ({}).hasOwnProperty;
351
- function classNames() {
352
- var classes = [];
353
- for (var i = 0; i < arguments.length; i++) {
354
- var arg = arguments[i];
355
- if (!arg) continue;
356
- var argType = typeof arg;
357
- if (argType === 'string' || argType === 'number') {
358
- classes.push(arg);
359
- } else if (Array.isArray(arg) && arg.length) {
360
- var inner = classNames.apply(null, arg);
361
- if (inner) {
362
- classes.push(inner);
363
- }
364
- } else if (argType === 'object') {
365
- for (var key in arg) {
366
- if (hasOwn.call(arg, key) && arg[key]) {
367
- classes.push(key);
368
- }
369
- }
370
- }
371
- }
372
- return classes.join(' ');
373
- }
374
- if (module.exports) {
375
- classNames.default = classNames;
376
- module.exports = classNames;
377
- } else {
378
- window.classNames = classNames;
379
- }
380
- })();
381
- });
382
- const React = _dll_react;
383
- const PropTypes = _dll_prop_types;
384
- const {withStyles: withStyles} = _dll_material_ui__core_styles;
385
- const {Button: Button} = _dll_material_ui__core;
386
- const _jsxFileName = "/home/ede/dev/github/pie-framework/pie-elements/packages/drawing-response/configure/src/button.jsx";
387
- const RawButton = ({classes, className, label, onClick, disabled}) => React.createElement(Button, {
388
- onClick: onClick,
389
- disabled: disabled,
390
- className: classnames(classes.addButton, className),
391
- size: "small",
392
- variant: "contained",
393
- color: "default",
394
- __self: undefined,
395
- __source: {
396
- fileName: _jsxFileName,
397
- lineNumber: 8
398
- }
399
- }, label);
400
- RawButton.propTypes = {
401
- classes: PropTypes.object.isRequired,
402
- className: PropTypes.string,
403
- disabled: PropTypes.bool,
404
- label: PropTypes.string,
405
- onClick: PropTypes.func
406
- };
407
- RawButton.defaultProps = {
408
- className: '',
409
- disabled: false,
410
- label: 'Add',
411
- onClick: () => {}
412
- };
413
- const styles = () => ({
414
- addButton: {
415
- marginLeft: 8
416
- }
417
- });
418
- const ButtonStyled = withStyles(styles)(RawButton);
419
- const React$1 = _dll_react;
420
- const {Component: Component} = _dll_react;
421
- const PropTypes$1 = _dll_prop_types;
422
- const {withStyles: withStyles$1} = _dll_material_ui__core_styles;
423
- const _jsxFileName$1 = "/home/ede/dev/github/pie-framework/pie-elements/packages/drawing-response/configure/src/image-container.jsx";
424
- const isImage = file => {
425
- const imageType = /image.*/;
426
- return file.type.match(imageType);
427
- };
428
- class ImageContainer extends Component {
429
- constructor(props) {
430
- super(props);
431
- ImageContainer.prototype.__init.call(this);
432
- ImageContainer.prototype.__init2.call(this);
433
- ImageContainer.prototype.__init3.call(this);
434
- ImageContainer.prototype.__init4.call(this);
435
- ImageContainer.prototype.__init5.call(this);
436
- ImageContainer.prototype.__init6.call(this);
437
- ImageContainer.prototype.__init7.call(this);
438
- ImageContainer.prototype.__init8.call(this);
439
- ImageContainer.prototype.__init9.call(this);
440
- ImageContainer.prototype.__init10.call(this);
441
- ImageContainer.prototype.__init11.call(this);
442
- ImageContainer.prototype.__init12.call(this);
443
- ImageContainer.prototype.__init13.call(this);
444
- ImageContainer.prototype.__init14.call(this);
445
- this.state = {
446
- maxImageWidth: 0,
447
- maxImageHeight: 0,
448
- dragEnabled: true,
449
- dropzoneActive: false
450
- };
451
- }
452
- componentDidMount() {
453
- if (this.imageSection) {
454
- const positionInfo = this.imageSection.getBoundingClientRect();
455
- const {height, width} = positionInfo;
456
- this.setState({
457
- maxImageWidth: width,
458
- maxImageHeight: height
459
- });
460
- }
461
- }
462
- __init() {
463
- this.handleFileRead = file => {
464
- const {onImageUpload} = this.props;
465
- const reader = new FileReader();
466
- reader.onloadend = () => {
467
- onImageUpload(reader.result);
468
- };
469
- reader.readAsDataURL(file);
470
- };
471
- }
472
- __init2() {
473
- this.handleUploadImage = e => {
474
- e.preventDefault();
475
- const file = e.target.files[0];
476
- this.handleFileRead(file);
477
- };
478
- }
479
- __init3() {
480
- this.makeDropzoneActive = () => this.setState({
481
- dropzoneActive: true
482
- });
483
- }
484
- __init4() {
485
- this.makeDropzoneInactive = () => this.setState({
486
- dropzoneActive: false
487
- });
488
- }
489
- __init5() {
490
- this.handleOnDrop = e => {
491
- e.preventDefault();
492
- const {items, files} = e.dataTransfer;
493
- if (items && items[0].kind === 'file') {
494
- const file = items[0].getAsFile();
495
- if (isImage(file)) {
496
- this.handleFileRead(file);
497
- }
498
- } else if (isImage(files[0])) {
499
- this.handleFileRead(files[0]);
500
- }
501
- this.makeDropzoneInactive();
502
- };
503
- }
504
- __init6() {
505
- this.handleOnDragOver = e => {
506
- e.preventDefault();
507
- const {dropzoneActive} = this.state;
508
- if (!dropzoneActive) {
509
- this.makeDropzoneActive();
510
- }
511
- };
512
- }
513
- __init7() {
514
- this.handleOnDragExit = e => {
515
- e.preventDefault();
516
- this.makeDropzoneInactive();
517
- };
518
- }
519
- __init8() {
520
- this.handleEnableDrag = () => this.setState({
521
- dragEnabled: true
522
- });
523
- }
524
- __init9() {
525
- this.handleDisableDrag = () => this.setState({
526
- dragEnabled: false
527
- });
528
- }
529
- __init10() {
530
- this.handleInputClick = () => this.input.click();
531
- }
532
- __init11() {
533
- this.handleOnImageLoad = ({target: {offsetHeight, offsetWidth}}) => {
534
- const {onUpdateImageDimension} = this.props;
535
- const resizeHandle = this.resize;
536
- const dimensions = {
537
- height: offsetHeight,
538
- width: offsetWidth
539
- };
540
- this.setState({
541
- dimensions
542
- });
543
- onUpdateImageDimension(dimensions);
544
- resizeHandle.addEventListener('mousedown', this.initialiseResize, false);
545
- };
546
- }
547
- __init12() {
548
- this.initialiseResize = () => {
549
- window.addEventListener('mousemove', this.startResizing, false);
550
- window.addEventListener('mouseup', this.stopResizing, false);
551
- };
552
- }
553
- __init13() {
554
- this.stopResizing = () => {
555
- const {onUpdateImageDimension} = this.props;
556
- const {dimensions} = this.state;
557
- this.handleEnableDrag();
558
- onUpdateImageDimension(dimensions);
559
- window.removeEventListener('mousemove', this.startResizing, false);
560
- window.removeEventListener('mouseup', this.stopResizing, false);
561
- };
562
- }
563
- __init14() {
564
- this.startResizing = e => {
565
- const box = this.image;
566
- const {maxImageWidth} = this.state;
567
- const bounds = e.target.getBoundingClientRect();
568
- const x = e.clientX - bounds.left;
569
- const y = e.clientY - bounds.top;
570
- const fitsContainer = x <= maxImageWidth + 5;
571
- const hasMinimumWidth = x > 150 && y > 150;
572
- if (fitsContainer && hasMinimumWidth) {
573
- box.style.width = `${x}px`;
574
- box.style.height = `${y}px`;
575
- this.setState({
576
- dimensions: {
577
- height: y,
578
- width: x
579
- }
580
- });
581
- }
582
- this.handleDisableDrag();
583
- };
584
- }
585
- renderUploadControl(label) {
586
- const {classes} = this.props;
587
- return React$1.createElement('div', {
588
- __self: this,
589
- __source: {
590
- fileName: _jsxFileName$1,
591
- lineNumber: 143
592
- }
593
- }, React$1.createElement(ButtonStyled, {
594
- label: label,
595
- onClick: this.handleInputClick,
596
- __self: this,
597
- __source: {
598
- fileName: _jsxFileName$1,
599
- lineNumber: 144
600
- }
601
- }), React$1.createElement('input', {
602
- accept: "image/*",
603
- className: classes.input,
604
- onChange: this.handleUploadImage,
605
- ref: ref => {
606
- this.input = ref;
607
- },
608
- type: "file",
609
- __self: this,
610
- __source: {
611
- fileName: _jsxFileName$1,
612
- lineNumber: 148
613
- }
614
- }));
615
- }
616
- render() {
617
- const {classes, imageUrl} = this.props;
618
- const {dropzoneActive, dragEnabled, maxImageHeight, maxImageWidth} = this.state;
619
- return React$1.createElement('div', {
620
- className: classes.base,
621
- __self: this,
622
- __source: {
623
- fileName: _jsxFileName$1,
624
- lineNumber: 172
625
- }
626
- }, React$1.createElement('div', {
627
- className: `${classes.box} ${dropzoneActive ? classes.boxActive : ''}`,
628
- ...dragEnabled ? {
629
- onDragExit: this.handleOnDragExit,
630
- onDragLeave: this.handleOnDragExit,
631
- onDragOver: this.handleOnDragOver,
632
- onDrop: this.handleOnDrop
633
- } : {},
634
- __self: this,
635
- __source: {
636
- fileName: _jsxFileName$1,
637
- lineNumber: 173
638
- }
639
- }, React$1.createElement('div', {
640
- className: classes.toolbar,
641
- __self: this,
642
- __source: {
643
- fileName: _jsxFileName$1,
644
- lineNumber: 181
645
- }
646
- }, this.renderUploadControl(imageUrl ? 'Replace Image' : 'Upload Image')), React$1.createElement('div', {
647
- ref: ref => {
648
- this.imageSection = ref;
649
- },
650
- className: classes.drawableHeight,
651
- __self: this,
652
- __source: {
653
- fileName: _jsxFileName$1,
654
- lineNumber: 185
655
- }
656
- }, imageUrl ? React$1.createElement('div', {
657
- className: classes.imageContainer,
658
- __self: this,
659
- __source: {
660
- fileName: _jsxFileName$1,
661
- lineNumber: 187
662
- }
663
- }, React$1.createElement('img', {
664
- className: classes.image,
665
- height: "auto",
666
- onLoad: this.handleOnImageLoad,
667
- ref: ref => {
668
- this.image = ref;
669
- },
670
- src: imageUrl,
671
- style: {
672
- maxWidth: maxImageWidth,
673
- maxHeight: maxImageHeight
674
- },
675
- alt: "",
676
- __self: this,
677
- __source: {
678
- fileName: _jsxFileName$1,
679
- lineNumber: 188
680
- }
681
- }), React$1.createElement('div', {
682
- ref: ref => {
683
- this.resize = ref;
684
- },
685
- className: classes.resize,
686
- __self: this,
687
- __source: {
688
- fileName: _jsxFileName$1,
689
- lineNumber: 197
690
- }
691
- })) : React$1.createElement('div', {
692
- className: `${classes.drawableHeight} ${classes.centered}`,
693
- __self: this,
694
- __source: {
695
- fileName: _jsxFileName$1,
696
- lineNumber: 200
697
- }
698
- }, React$1.createElement('label', {
699
- __self: this,
700
- __source: {
701
- fileName: _jsxFileName$1,
702
- lineNumber: 201
703
- }
704
- }, "Drag and drop or upload image from computer"), React$1.createElement('br', {
705
- __self: this,
706
- __source: {
707
- fileName: _jsxFileName$1,
708
- lineNumber: 202
709
- }
710
- }), this.renderUploadControl('Upload Image')))));
711
- }
712
- }
713
- const styles$1 = theme => ({
714
- base: {
715
- marginTop: theme.spacing.unit * 2
716
- },
717
- box: {
718
- border: '1px solid #E0E1E6',
719
- borderRadius: '5px'
720
- },
721
- boxActive: {
722
- border: '1px solid #0032C2'
723
- },
724
- centered: {
725
- alignItems: 'center',
726
- display: 'flex',
727
- flexDirection: 'column',
728
- justifyContent: 'center'
729
- },
730
- drawableHeight: {
731
- minHeight: 350
732
- },
733
- image: {
734
- alignItems: 'center',
735
- display: 'flex',
736
- justifyContent: 'center'
737
- },
738
- imageContainer: {
739
- position: 'relative',
740
- width: 'fit-content'
741
- },
742
- resize: {
743
- borderBottom: '1px solid #727272',
744
- borderRight: '1px solid #727272',
745
- bottom: '-10px',
746
- cursor: 'se-resize',
747
- height: '10px',
748
- position: 'absolute',
749
- right: '-10px',
750
- width: '10px'
751
- },
752
- input: {
753
- display: 'none'
754
- },
755
- toolbar: {
756
- backgroundColor: '#ECEDF1',
757
- borderBottom: '1px solid #E0E1E6',
758
- borderTopLeftRadius: '5px',
759
- borderTopRightRadius: '5px',
760
- display: 'flex',
761
- padding: '12px 8px'
762
- }
763
- });
764
- ImageContainer.propTypes = {
765
- classes: PropTypes$1.object.isRequired,
766
- imageUrl: PropTypes$1.string.isRequired,
767
- onImageUpload: PropTypes$1.func.isRequired,
768
- onUpdateImageDimension: PropTypes$1.func.isRequired
769
- };
770
- var ImageContainer$1 = withStyles$1(styles$1)(ImageContainer);
771
- const React$2 = _dll_react;
772
- const PropTypes$2 = _dll_prop_types;
773
- const {Typography: Typography} = _dll_material_ui__core;
774
- const {withStyles: withStyles$2} = _dll_material_ui__core_styles;
775
- const {cloneDeep: cloneDeep} = _dll_lodash;
776
- const {settings: settings} = _dll_pie_lib__config_ui;
777
- const {layout: layout} = _dll_pie_lib__config_ui;
778
- const {InputContainer: InputContainer} = _dll_pie_lib__config_ui;
779
- const EditableHtml = _dll_pie_lib__editable_html;
780
- const _jsxFileName$2 = "/home/ede/dev/github/pie-framework/pie-elements/packages/drawing-response/configure/src/root.jsx";
781
- const {Panel, toggle} = settings;
782
- class Root extends React$2.Component {
783
- constructor(...args) {
784
- super(...args);
785
- Root.prototype.__init.call(this);
786
- Root.prototype.__init2.call(this);
787
- Root.prototype.__init3.call(this);
788
- Root.prototype.__init4.call(this);
789
- Root.prototype.__init5.call(this);
790
- }
791
- __init() {
792
- this.onPromptChanged = prompt => {
793
- const {model, onModelChanged} = this.props;
794
- const update = cloneDeep(model);
795
- onModelChanged({
796
- ...update,
797
- prompt
798
- });
799
- };
800
- }
801
- __init2() {
802
- this.onRationaleChanged = rationale => {
803
- const {model, onModelChanged} = this.props;
804
- onModelChanged({
805
- ...model,
806
- rationale
807
- });
808
- };
809
- }
810
- __init3() {
811
- this.onTeacherInstructionsChanged = teacherInstructions => {
812
- const {model, onModelChanged} = this.props;
813
- onModelChanged({
814
- ...model,
815
- teacherInstructions
816
- });
817
- };
818
- }
819
- __init4() {
820
- this.onUpdateImageDimension = dimensions => {
821
- const {model, onModelChanged} = this.props;
822
- onModelChanged({
823
- ...model,
824
- imageDimensions: dimensions
825
- });
826
- };
827
- }
828
- __init5() {
829
- this.onImageUpload = imageUrl => {
830
- const {model, onModelChanged} = this.props;
831
- onModelChanged({
832
- ...model,
833
- imageUrl
834
- });
835
- };
836
- }
837
- render() {
838
- const {classes, configuration, model, imageSupport, onConfigurationChanged, onModelChanged} = this.props;
839
- const {backgroundImage = {}, rationale = {}, prompt = {}, teacherInstructions = {}} = configuration || ({});
840
- const {teacherInstructionsEnabled, promptEnabled, rationaleEnabled} = model || ({});
841
- return React$2.createElement('div', {
842
- className: classes.base,
843
- __self: this,
844
- __source: {
845
- fileName: _jsxFileName$2,
846
- lineNumber: 75
847
- }
848
- }, React$2.createElement(layout.ConfigLayout, {
849
- settings: React$2.createElement(Panel, {
850
- model: model,
851
- onChangeModel: onModelChanged,
852
- configuration: configuration,
853
- onChangeConfiguration: onConfigurationChanged,
854
- groups: {
855
- Settings: {
856
- 'backgroundImage.enabled': backgroundImage.settings && toggle(backgroundImage.label, true),
857
- promptEnabled: prompt.settings && toggle(prompt.label)
858
- },
859
- Properties: {
860
- teacherInstructionsEnabled: teacherInstructions.settings && toggle(teacherInstructions.label),
861
- rationaleEnabled: rationale.settings && toggle(rationale.label)
862
- }
863
- },
864
- __self: this,
865
- __source: {
866
- fileName: _jsxFileName$2,
867
- lineNumber: 78
868
- }
869
- }),
870
- __self: this,
871
- __source: {
872
- fileName: _jsxFileName$2,
873
- lineNumber: 76
874
- }
875
- }, React$2.createElement('div', {
876
- className: classes.regular,
877
- __self: this,
878
- __source: {
879
- fileName: _jsxFileName$2,
880
- lineNumber: 101
881
- }
882
- }, teacherInstructionsEnabled && React$2.createElement(InputContainer, {
883
- label: teacherInstructions.label,
884
- className: classes.prompt,
885
- __self: this,
886
- __source: {
887
- fileName: _jsxFileName$2,
888
- lineNumber: 103
889
- }
890
- }, React$2.createElement(EditableHtml, {
891
- markup: model.teacherInstructions || '',
892
- onChange: this.onTeacherInstructionsChanged,
893
- imageSupport: imageSupport,
894
- nonEmpty: false,
895
- __self: this,
896
- __source: {
897
- fileName: _jsxFileName$2,
898
- lineNumber: 107
899
- }
900
- })), promptEnabled && React$2.createElement(InputContainer, {
901
- label: "Item Stem",
902
- className: classes.prompt,
903
- __self: this,
904
- __source: {
905
- fileName: _jsxFileName$2,
906
- lineNumber: 117
907
- }
908
- }, React$2.createElement(EditableHtml, {
909
- markup: model.prompt,
910
- onChange: this.onPromptChanged,
911
- __self: this,
912
- __source: {
913
- fileName: _jsxFileName$2,
914
- lineNumber: 118
915
- }
916
- })), rationaleEnabled && React$2.createElement(InputContainer, {
917
- label: rationale.label,
918
- className: classes.prompt,
919
- __self: this,
920
- __source: {
921
- fileName: _jsxFileName$2,
922
- lineNumber: 126
923
- }
924
- }, React$2.createElement(EditableHtml, {
925
- markup: model.rationale || '',
926
- onChange: this.onRationaleChanged,
927
- imageSupport: imageSupport,
928
- __self: this,
929
- __source: {
930
- fileName: _jsxFileName$2,
931
- lineNumber: 130
932
- }
933
- })), backgroundImage.enabled && React$2.createElement('div', {
934
- __self: this,
935
- __source: {
936
- fileName: _jsxFileName$2,
937
- lineNumber: 139
938
- }
939
- }, React$2.createElement(Typography, {
940
- className: classes.label,
941
- variant: "subheading",
942
- __self: this,
943
- __source: {
944
- fileName: _jsxFileName$2,
945
- lineNumber: 140
946
- }
947
- }, "Define Background Image"), React$2.createElement(ImageContainer$1, {
948
- imageUrl: model.imageUrl,
949
- onUpdateImageDimension: this.onUpdateImageDimension,
950
- onImageUpload: this.onImageUpload,
951
- __self: this,
952
- __source: {
953
- fileName: _jsxFileName$2,
954
- lineNumber: 144
955
- }
956
- })))));
957
- }
958
- }
959
- const styles$2 = theme => ({
960
- base: {
961
- marginTop: theme.spacing.unit * 3
962
- },
963
- label: {
964
- marginTop: theme.spacing.unit * 4
965
- },
966
- prompt: {
967
- paddingTop: theme.spacing.unit * 2,
968
- width: '100%'
969
- },
970
- regular: {
971
- marginBottom: theme.spacing.unit * 3
972
- }
973
- });
974
- Root.propTypes = {
975
- classes: PropTypes$2.object.isRequired,
976
- configuration: PropTypes$2.object,
977
- model: PropTypes$2.object.isRequired,
978
- imageSupport: PropTypes$2.shape({
979
- add: PropTypes$2.func,
980
- delete: PropTypes$2.func
981
- }),
982
- onModelChanged: PropTypes$2.func.isRequired,
983
- onConfigurationChanged: PropTypes$2.func.isRequired
984
- };
985
- var Root$1 = withStyles$2(styles$2)(Root);
986
- var sensibleDefaults = {
987
- model: {
988
- prompt: 'This is the question prompt',
989
- imageUrl: '',
990
- imageDimensions: {
991
- height: 0,
992
- width: 0
993
- },
994
- rationaleEnabled: true,
995
- promptEnabled: true,
996
- teacherInstructionsEnabled: true,
997
- studentInstructionsEnabled: true
998
- },
999
- configuration: {
1000
- backgroundImage: {
1001
- settings: true,
1002
- label: 'Background Image',
1003
- enabled: true
1004
- },
1005
- rationale: {
1006
- settings: true,
1007
- label: 'Rationale'
1008
- },
1009
- prompt: {
1010
- settings: true,
1011
- label: 'Prompt'
1012
- },
1013
- teacherInstructions: {
1014
- settings: true,
1015
- label: 'Teacher Instructions'
1016
- }
1017
- }
1018
- };
1019
- const {ModelUpdatedEvent: ModelUpdatedEvent} = _dll_pie_framework__pie_configure_events;
1020
- const {DeleteImageEvent: DeleteImageEvent} = _dll_pie_framework__pie_configure_events;
1021
- const {InsertImageEvent: InsertImageEvent} = _dll_pie_framework__pie_configure_events;
1022
- const React$3 = _dll_react;
1023
- const ReactDOM = _dll_react_dom;
1024
- const log = browser('hotspot:configure');
1025
- class DrawableResponseConfigure extends HTMLElement {
1026
- static __initStatic() {
1027
- this.createDefaultModel = (model = {}) => ({
1028
- ...sensibleDefaults.model,
1029
- ...model
1030
- });
1031
- }
1032
- constructor() {
1033
- super();
1034
- DrawableResponseConfigure.prototype.__init.call(this);
1035
- DrawableResponseConfigure.prototype.__init2.call(this);
1036
- DrawableResponseConfigure.prototype.__init3.call(this);
1037
- DrawableResponseConfigure.prototype.__init4.call(this);
1038
- this._model = DrawableResponseConfigure.createDefaultModel();
1039
- this._configuration = sensibleDefaults.configuration;
1040
- this.onModelChanged = this.onModelChanged.bind(this);
1041
- }
1042
- set model(s) {
1043
- this._model = DrawableResponseConfigure.createDefaultModel(s);
1044
- this._render();
1045
- }
1046
- set configuration(c) {
1047
- this._configuration = c;
1048
- this._render();
1049
- }
1050
- dispatchModelUpdated(reset) {
1051
- const resetValue = !!reset;
1052
- this.dispatchEvent(new ModelUpdatedEvent(this._model, resetValue));
1053
- }
1054
- __init() {
1055
- this.onModelChanged = (m, reset) => {
1056
- this._model = m;
1057
- this.dispatchModelUpdated(reset);
1058
- this._render();
1059
- };
1060
- }
1061
- __init2() {
1062
- this.onConfigurationChanged = c => {
1063
- if (!c.backgroundImage.enabled) {
1064
- this.onModelChanged({
1065
- ...this._model,
1066
- imageUrl: ''
1067
- });
1068
- }
1069
- this._configuration = c;
1070
- this._render();
1071
- };
1072
- }
1073
- __init3() {
1074
- this.insertImage = handler => {
1075
- this.dispatchEvent(new InsertImageEvent(handler));
1076
- };
1077
- }
1078
- __init4() {
1079
- this.onDeleteImage = (src, done) => {
1080
- this.dispatchEvent(new DeleteImageEvent(src, done));
1081
- };
1082
- }
1083
- _render() {
1084
- log('_render');
1085
- let element = React$3.createElement(Root$1, {
1086
- model: this._model,
1087
- configuration: this._configuration,
1088
- onModelChanged: this.onModelChanged,
1089
- onConfigurationChanged: this.onConfigurationChanged,
1090
- imageSupport: {
1091
- add: this.insertImage,
1092
- delete: this.onDeleteImage
1093
- }
1094
- });
1095
- ReactDOM.render(element, this);
1096
- }
1097
- }
1098
- DrawableResponseConfigure.__initStatic();
1099
- export default DrawableResponseConfigure;