@pie-element/hotspot 4.8.3 → 4.8.4-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 (68) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/configure/CHANGELOG.md +135 -0
  3. package/configure/lib/defaults.js +17 -0
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/hotspot-container.js +18 -6
  6. package/configure/lib/hotspot-container.js.map +1 -1
  7. package/configure/lib/hotspot-drawable.js +11 -5
  8. package/configure/lib/hotspot-drawable.js.map +1 -1
  9. package/configure/lib/hotspot-palette.js +1 -1
  10. package/configure/lib/hotspot-palette.js.map +1 -1
  11. package/configure/lib/hotspot-polygon.js +1 -1
  12. package/configure/lib/hotspot-polygon.js.map +1 -1
  13. package/configure/lib/hotspot-rectangle.js +1 -1
  14. package/configure/lib/hotspot-rectangle.js.map +1 -1
  15. package/configure/lib/index.js +3 -3
  16. package/configure/lib/index.js.map +1 -1
  17. package/configure/lib/root.js +96 -13
  18. package/configure/lib/root.js.map +1 -1
  19. package/configure/lib/utils.js +18 -4
  20. package/configure/lib/utils.js.map +1 -1
  21. package/configure/package.json +3 -3
  22. package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +1 -0
  23. package/configure/src/__tests__/__snapshots__/root.test.js.snap +48 -4
  24. package/configure/src/defaults.js +17 -0
  25. package/configure/src/hotspot-container.jsx +10 -1
  26. package/configure/src/hotspot-drawable.jsx +8 -2
  27. package/configure/src/root.jsx +80 -9
  28. package/configure/src/utils.js +23 -1
  29. package/controller/CHANGELOG.md +16 -0
  30. package/controller/lib/index.js +44 -5
  31. package/controller/lib/index.js.map +1 -1
  32. package/controller/lib/utils.js.map +1 -1
  33. package/controller/package.json +1 -1
  34. package/controller/src/index.js +26 -0
  35. package/docs/config-schema.json +196 -0
  36. package/docs/config-schema.json.md +153 -0
  37. package/docs/demo/generate.js +1 -0
  38. package/docs/pie-schema.json +53 -0
  39. package/docs/pie-schema.json.md +43 -0
  40. package/lib/hotspot/container.js +33 -4
  41. package/lib/hotspot/container.js.map +1 -1
  42. package/lib/hotspot/image.js +35 -8
  43. package/lib/hotspot/image.js.map +1 -1
  44. package/lib/hotspot/index.js +61 -17
  45. package/lib/hotspot/index.js.map +1 -1
  46. package/lib/hotspot/polygon.js +16 -17
  47. package/lib/hotspot/polygon.js.map +1 -1
  48. package/lib/hotspot/rectangle.js +16 -17
  49. package/lib/hotspot/rectangle.js.map +1 -1
  50. package/lib/index.js +4 -1
  51. package/lib/index.js.map +1 -1
  52. package/lib/session-updater.js.map +1 -1
  53. package/package.json +4 -4
  54. package/src/__tests__/image-test.jsx +9 -1
  55. package/src/__tests__/polygon-test.jsx +2 -1
  56. package/src/__tests__/rectangle-test.jsx +2 -1
  57. package/src/hotspot/container.jsx +34 -2
  58. package/src/hotspot/image.jsx +29 -12
  59. package/src/hotspot/index.jsx +54 -6
  60. package/src/hotspot/polygon.jsx +11 -15
  61. package/src/hotspot/rectangle.jsx +11 -15
  62. package/src/index.js +5 -0
  63. package/module/configure.js +0 -2340
  64. package/module/controller.js +0 -19764
  65. package/module/demo.js +0 -94
  66. package/module/element.js +0 -717
  67. package/module/index.html +0 -16
  68. package/module/manifest.json +0 -14
@@ -1,2340 +0,0 @@
1
- import {_dll_react, _dll_prop_types, _dll_material_ui__core, _dll_material_ui__core_styles, _dll_lodash, _dll_react_dom} from "../../../@pie-ui/shared-lib@^4.3.3/module/index.js";
2
- 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";
3
- import {_dll_react_konva} from "../../../@pie-ui/shared-konva@^2.5.17/module/index.js";
4
- function unwrapExports(x) {
5
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6
- }
7
- function createCommonjsModule(fn, module) {
8
- return (module = {
9
- exports: {}
10
- }, fn(module, module.exports), module.exports);
11
- }
12
- var s = 1000;
13
- var m = s * 60;
14
- var h = m * 60;
15
- var d = h * 24;
16
- var w = d * 7;
17
- var y = d * 365.25;
18
- var ms = function (val, options) {
19
- options = options || ({});
20
- var type = typeof val;
21
- if (type === 'string' && val.length > 0) {
22
- return parse(val);
23
- } else if (type === 'number' && isFinite(val)) {
24
- return options.long ? fmtLong(val) : fmtShort(val);
25
- }
26
- throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
27
- };
28
- function parse(str) {
29
- str = String(str);
30
- if (str.length > 100) {
31
- return;
32
- }
33
- 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);
34
- if (!match) {
35
- return;
36
- }
37
- var n = parseFloat(match[1]);
38
- var type = (match[2] || 'ms').toLowerCase();
39
- switch (type) {
40
- case 'years':
41
- case 'year':
42
- case 'yrs':
43
- case 'yr':
44
- case 'y':
45
- return n * y;
46
- case 'weeks':
47
- case 'week':
48
- case 'w':
49
- return n * w;
50
- case 'days':
51
- case 'day':
52
- case 'd':
53
- return n * d;
54
- case 'hours':
55
- case 'hour':
56
- case 'hrs':
57
- case 'hr':
58
- case 'h':
59
- return n * h;
60
- case 'minutes':
61
- case 'minute':
62
- case 'mins':
63
- case 'min':
64
- case 'm':
65
- return n * m;
66
- case 'seconds':
67
- case 'second':
68
- case 'secs':
69
- case 'sec':
70
- case 's':
71
- return n * s;
72
- case 'milliseconds':
73
- case 'millisecond':
74
- case 'msecs':
75
- case 'msec':
76
- case 'ms':
77
- return n;
78
- default:
79
- return undefined;
80
- }
81
- }
82
- function fmtShort(ms) {
83
- var msAbs = Math.abs(ms);
84
- if (msAbs >= d) {
85
- return Math.round(ms / d) + 'd';
86
- }
87
- if (msAbs >= h) {
88
- return Math.round(ms / h) + 'h';
89
- }
90
- if (msAbs >= m) {
91
- return Math.round(ms / m) + 'm';
92
- }
93
- if (msAbs >= s) {
94
- return Math.round(ms / s) + 's';
95
- }
96
- return ms + 'ms';
97
- }
98
- function fmtLong(ms) {
99
- var msAbs = Math.abs(ms);
100
- if (msAbs >= d) {
101
- return plural(ms, msAbs, d, 'day');
102
- }
103
- if (msAbs >= h) {
104
- return plural(ms, msAbs, h, 'hour');
105
- }
106
- if (msAbs >= m) {
107
- return plural(ms, msAbs, m, 'minute');
108
- }
109
- if (msAbs >= s) {
110
- return plural(ms, msAbs, s, 'second');
111
- }
112
- return ms + ' ms';
113
- }
114
- function plural(ms, msAbs, n, name) {
115
- var isPlural = msAbs >= n * 1.5;
116
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
117
- }
118
- function setup(env) {
119
- createDebug.debug = createDebug;
120
- createDebug.default = createDebug;
121
- createDebug.coerce = coerce;
122
- createDebug.disable = disable;
123
- createDebug.enable = enable;
124
- createDebug.enabled = enabled;
125
- createDebug.humanize = ms;
126
- Object.keys(env).forEach(function (key) {
127
- createDebug[key] = env[key];
128
- });
129
- createDebug.instances = [];
130
- createDebug.names = [];
131
- createDebug.skips = [];
132
- createDebug.formatters = {};
133
- function selectColor(namespace) {
134
- var hash = 0;
135
- for (var i = 0; i < namespace.length; i++) {
136
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
137
- hash |= 0;
138
- }
139
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
140
- }
141
- createDebug.selectColor = selectColor;
142
- function createDebug(namespace) {
143
- var prevTime;
144
- function debug() {
145
- if (!debug.enabled) {
146
- return;
147
- }
148
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
149
- args[_key] = arguments[_key];
150
- }
151
- var self = debug;
152
- var curr = Number(new Date());
153
- var ms = curr - (prevTime || curr);
154
- self.diff = ms;
155
- self.prev = prevTime;
156
- self.curr = curr;
157
- prevTime = curr;
158
- args[0] = createDebug.coerce(args[0]);
159
- if (typeof args[0] !== 'string') {
160
- args.unshift('%O');
161
- }
162
- var index = 0;
163
- args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
164
- if (match === '%%') {
165
- return match;
166
- }
167
- index++;
168
- var formatter = createDebug.formatters[format];
169
- if (typeof formatter === 'function') {
170
- var val = args[index];
171
- match = formatter.call(self, val);
172
- args.splice(index, 1);
173
- index--;
174
- }
175
- return match;
176
- });
177
- createDebug.formatArgs.call(self, args);
178
- var logFn = self.log || createDebug.log;
179
- logFn.apply(self, args);
180
- }
181
- debug.namespace = namespace;
182
- debug.enabled = createDebug.enabled(namespace);
183
- debug.useColors = createDebug.useColors();
184
- debug.color = selectColor(namespace);
185
- debug.destroy = destroy;
186
- debug.extend = extend;
187
- if (typeof createDebug.init === 'function') {
188
- createDebug.init(debug);
189
- }
190
- createDebug.instances.push(debug);
191
- return debug;
192
- }
193
- function destroy() {
194
- var index = createDebug.instances.indexOf(this);
195
- if (index !== -1) {
196
- createDebug.instances.splice(index, 1);
197
- return true;
198
- }
199
- return false;
200
- }
201
- function extend(namespace, delimiter) {
202
- return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
203
- }
204
- function enable(namespaces) {
205
- createDebug.save(namespaces);
206
- createDebug.names = [];
207
- createDebug.skips = [];
208
- var i;
209
- var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
210
- var len = split.length;
211
- for (i = 0; i < len; i++) {
212
- if (!split[i]) {
213
- continue;
214
- }
215
- namespaces = split[i].replace(/\*/g, '.*?');
216
- if (namespaces[0] === '-') {
217
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
218
- } else {
219
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
220
- }
221
- }
222
- for (i = 0; i < createDebug.instances.length; i++) {
223
- var instance = createDebug.instances[i];
224
- instance.enabled = createDebug.enabled(instance.namespace);
225
- }
226
- }
227
- function disable() {
228
- createDebug.enable('');
229
- }
230
- function enabled(name) {
231
- if (name[name.length - 1] === '*') {
232
- return true;
233
- }
234
- var i;
235
- var len;
236
- for ((i = 0, len = createDebug.skips.length); i < len; i++) {
237
- if (createDebug.skips[i].test(name)) {
238
- return false;
239
- }
240
- }
241
- for ((i = 0, len = createDebug.names.length); i < len; i++) {
242
- if (createDebug.names[i].test(name)) {
243
- return true;
244
- }
245
- }
246
- return false;
247
- }
248
- function coerce(val) {
249
- if (val instanceof Error) {
250
- return val.stack || val.message;
251
- }
252
- return val;
253
- }
254
- createDebug.enable(createDebug.load());
255
- return createDebug;
256
- }
257
- var common = setup;
258
- var browser = createCommonjsModule(function (module, exports) {
259
- function _typeof(obj) {
260
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
261
- _typeof = function _typeof(obj) {
262
- return typeof obj;
263
- };
264
- } else {
265
- _typeof = function _typeof(obj) {
266
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
267
- };
268
- }
269
- return _typeof(obj);
270
- }
271
- exports.log = log;
272
- exports.formatArgs = formatArgs;
273
- exports.save = save;
274
- exports.load = load;
275
- exports.useColors = useColors;
276
- exports.storage = localstorage();
277
- 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'];
278
- function useColors() {
279
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
280
- return true;
281
- }
282
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
283
- return false;
284
- }
285
- 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+)/);
286
- }
287
- function formatArgs(args) {
288
- args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
289
- if (!this.useColors) {
290
- return;
291
- }
292
- var c = 'color: ' + this.color;
293
- args.splice(1, 0, c, 'color: inherit');
294
- var index = 0;
295
- var lastC = 0;
296
- args[0].replace(/%[a-zA-Z%]/g, function (match) {
297
- if (match === '%%') {
298
- return;
299
- }
300
- index++;
301
- if (match === '%c') {
302
- lastC = index;
303
- }
304
- });
305
- args.splice(lastC, 0, c);
306
- }
307
- function log() {
308
- var _console;
309
- return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
310
- }
311
- function save(namespaces) {
312
- try {
313
- if (namespaces) {
314
- exports.storage.setItem('debug', namespaces);
315
- } else {
316
- exports.storage.removeItem('debug');
317
- }
318
- } catch (error) {}
319
- }
320
- function load() {
321
- var r;
322
- try {
323
- r = exports.storage.getItem('debug');
324
- } catch (error) {}
325
- if (!r && typeof process !== 'undefined' && ('env' in process)) {
326
- r = process.env.DEBUG;
327
- }
328
- return r;
329
- }
330
- function localstorage() {
331
- try {
332
- return localStorage;
333
- } catch (error) {}
334
- }
335
- module.exports = common(exports);
336
- var formatters = module.exports.formatters;
337
- formatters.j = function (v) {
338
- try {
339
- return JSON.stringify(v);
340
- } catch (error) {
341
- return '[UnexpectedJSONParseError]: ' + error.message;
342
- }
343
- };
344
- });
345
- browser.log;
346
- browser.formatArgs;
347
- browser.save;
348
- browser.load;
349
- browser.useColors;
350
- browser.storage;
351
- browser.colors;
352
- const React = _dll_react;
353
- const PropTypes = _dll_prop_types;
354
- const {Select: Select} = _dll_material_ui__core;
355
- const {MenuItem: MenuItem} = _dll_material_ui__core;
356
- const {withStyles: withStyles} = _dll_material_ui__core_styles;
357
- const {InputContainer: InputContainer} = _dll_pie_lib__config_ui;
358
- const _jsxFileName = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/hotspot-palette.jsx";
359
- class Palette extends React.Component {
360
- constructor(...args) {
361
- super(...args);
362
- Palette.prototype.__init.call(this);
363
- }
364
- __init() {
365
- this.onChange = name => event => {
366
- const {value} = event.target;
367
- const {onHotspotColorChange, onOutlineColorChange} = this.props;
368
- if (name === 'hotspot') {
369
- onHotspotColorChange(value);
370
- } else {
371
- onOutlineColorChange(value);
372
- }
373
- };
374
- }
375
- render() {
376
- const {classes, hotspotColor, outlineColor, hotspotList, outlineList} = this.props;
377
- return React.createElement('div', {
378
- className: classes.base,
379
- __self: this,
380
- __source: {
381
- fileName: _jsxFileName,
382
- lineNumber: 24
383
- }
384
- }, React.createElement(InputContainer, {
385
- label: "Hot Spot",
386
- className: classes.input,
387
- __self: this,
388
- __source: {
389
- fileName: _jsxFileName,
390
- lineNumber: 25
391
- }
392
- }, React.createElement(Select, {
393
- className: classes.select,
394
- onChange: this.onChange('hotspot'),
395
- value: hotspotColor,
396
- __self: this,
397
- __source: {
398
- fileName: _jsxFileName,
399
- lineNumber: 26
400
- }
401
- }, hotspotList.map(hotspot => React.createElement(MenuItem, {
402
- key: hotspot,
403
- value: hotspot,
404
- className: classes.item,
405
- style: {
406
- backgroundColor: hotspot
407
- },
408
- __self: this,
409
- __source: {
410
- fileName: _jsxFileName,
411
- lineNumber: 32
412
- }
413
- }, hotspot)))), React.createElement(InputContainer, {
414
- label: "Response Outline",
415
- className: classes.input,
416
- __self: this,
417
- __source: {
418
- fileName: _jsxFileName,
419
- lineNumber: 44
420
- }
421
- }, React.createElement(Select, {
422
- className: classes.select,
423
- onChange: this.onChange('outline'),
424
- value: outlineColor,
425
- __self: this,
426
- __source: {
427
- fileName: _jsxFileName,
428
- lineNumber: 45
429
- }
430
- }, outlineList.map(outline => React.createElement(MenuItem, {
431
- key: outline,
432
- value: outline,
433
- className: classes.item,
434
- style: {
435
- border: `2px solid ${outline}`
436
- },
437
- __self: this,
438
- __source: {
439
- fileName: _jsxFileName,
440
- lineNumber: 51
441
- }
442
- }, outline)))));
443
- }
444
- }
445
- const styles = theme => ({
446
- base: {
447
- marginTop: theme.spacing.unit * 2,
448
- display: 'flex'
449
- },
450
- input: {
451
- flex: 1,
452
- width: '90%'
453
- },
454
- item: {
455
- borderRadius: '2px',
456
- height: '22px',
457
- marginLeft: theme.spacing.unit * 2,
458
- marginRight: theme.spacing.unit * 2,
459
- marginTop: theme.spacing.unit * 2
460
- }
461
- });
462
- Palette.propTypes = {
463
- classes: PropTypes.object.isRequired,
464
- hotspotColor: PropTypes.string.isRequired,
465
- hotspotList: PropTypes.array.isRequired,
466
- onHotspotColorChange: PropTypes.func.isRequired,
467
- onOutlineColorChange: PropTypes.func.isRequired,
468
- outlineColor: PropTypes.string.isRequired,
469
- outlineList: PropTypes.array.isRequired
470
- };
471
- var HotspotPalette = withStyles(styles)(Palette);
472
- var interopRequireDefault = createCommonjsModule(function (module) {
473
- function _interopRequireDefault(obj) {
474
- return obj && obj.__esModule ? obj : {
475
- "default": obj
476
- };
477
- }
478
- module.exports = _interopRequireDefault;
479
- });
480
- unwrapExports(interopRequireDefault);
481
- var setPrototypeOf = createCommonjsModule(function (module) {
482
- function _setPrototypeOf(o, p) {
483
- module.exports = _setPrototypeOf = Object.setPrototypeOf || (function _setPrototypeOf(o, p) {
484
- o.__proto__ = p;
485
- return o;
486
- });
487
- return _setPrototypeOf(o, p);
488
- }
489
- module.exports = _setPrototypeOf;
490
- });
491
- function _inheritsLoose(subClass, superClass) {
492
- subClass.prototype = Object.create(superClass.prototype);
493
- subClass.prototype.constructor = subClass;
494
- setPrototypeOf(subClass, superClass);
495
- }
496
- var inheritsLoose = _inheritsLoose;
497
- var setStatic_1 = createCommonjsModule(function (module, exports) {
498
- exports.__esModule = true;
499
- exports.default = void 0;
500
- var setStatic = function setStatic(key, value) {
501
- return function (BaseComponent) {
502
- BaseComponent[key] = value;
503
- return BaseComponent;
504
- };
505
- };
506
- var _default = setStatic;
507
- exports.default = _default;
508
- });
509
- unwrapExports(setStatic_1);
510
- var setDisplayName_1 = createCommonjsModule(function (module, exports) {
511
- exports.__esModule = true;
512
- exports.default = void 0;
513
- var _setStatic = interopRequireDefault(setStatic_1);
514
- var setDisplayName = function setDisplayName(displayName) {
515
- return (0, _setStatic.default)('displayName', displayName);
516
- };
517
- var _default = setDisplayName;
518
- exports.default = _default;
519
- });
520
- unwrapExports(setDisplayName_1);
521
- var getDisplayName_1 = createCommonjsModule(function (module, exports) {
522
- exports.__esModule = true;
523
- exports.default = void 0;
524
- var getDisplayName = function getDisplayName(Component) {
525
- if (typeof Component === 'string') {
526
- return Component;
527
- }
528
- if (!Component) {
529
- return undefined;
530
- }
531
- return Component.displayName || Component.name || 'Component';
532
- };
533
- var _default = getDisplayName;
534
- exports.default = _default;
535
- });
536
- unwrapExports(getDisplayName_1);
537
- var wrapDisplayName_1 = createCommonjsModule(function (module, exports) {
538
- exports.__esModule = true;
539
- exports.default = void 0;
540
- var _getDisplayName = interopRequireDefault(getDisplayName_1);
541
- var wrapDisplayName = function wrapDisplayName(BaseComponent, hocName) {
542
- return hocName + "(" + (0, _getDisplayName.default)(BaseComponent) + ")";
543
- };
544
- var _default = wrapDisplayName;
545
- exports.default = _default;
546
- });
547
- unwrapExports(wrapDisplayName_1);
548
- const _react = _dll_react;
549
- var shouldUpdate_1 = createCommonjsModule(function (module, exports) {
550
- exports.__esModule = true;
551
- exports.default = void 0;
552
- var _inheritsLoose2 = interopRequireDefault(inheritsLoose);
553
- var _setDisplayName = interopRequireDefault(setDisplayName_1);
554
- var _wrapDisplayName = interopRequireDefault(wrapDisplayName_1);
555
- var shouldUpdate = function shouldUpdate(test) {
556
- return function (BaseComponent) {
557
- var factory = (0, _react.createFactory)(BaseComponent);
558
- var ShouldUpdate = (function (_Component) {
559
- (0, _inheritsLoose2.default)(ShouldUpdate, _Component);
560
- function ShouldUpdate() {
561
- return _Component.apply(this, arguments) || this;
562
- }
563
- var _proto = ShouldUpdate.prototype;
564
- _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
565
- return test(this.props, nextProps);
566
- };
567
- _proto.render = function render() {
568
- return factory(this.props);
569
- };
570
- return ShouldUpdate;
571
- })(_react.Component);
572
- {
573
- return (0, _setDisplayName.default)((0, _wrapDisplayName.default)(BaseComponent, 'shouldUpdate'))(ShouldUpdate);
574
- }
575
- };
576
- };
577
- var _default = shouldUpdate;
578
- exports.default = _default;
579
- });
580
- unwrapExports(shouldUpdate_1);
581
- var hasOwnProperty = Object.prototype.hasOwnProperty;
582
- function is(x, y) {
583
- if (x === y) {
584
- return x !== 0 || y !== 0 || 1 / x === 1 / y;
585
- } else {
586
- return x !== x && y !== y;
587
- }
588
- }
589
- function shallowEqual(objA, objB) {
590
- if (is(objA, objB)) {
591
- return true;
592
- }
593
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
594
- return false;
595
- }
596
- var keysA = Object.keys(objA);
597
- var keysB = Object.keys(objB);
598
- if (keysA.length !== keysB.length) {
599
- return false;
600
- }
601
- for (var i = 0; i < keysA.length; i++) {
602
- if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
603
- return false;
604
- }
605
- }
606
- return true;
607
- }
608
- var shallowEqual_1 = shallowEqual;
609
- var shallowEqual$1 = createCommonjsModule(function (module, exports) {
610
- exports.__esModule = true;
611
- exports.default = void 0;
612
- var _shallowEqual = interopRequireDefault(shallowEqual_1);
613
- var _default = _shallowEqual.default;
614
- exports.default = _default;
615
- });
616
- unwrapExports(shallowEqual$1);
617
- var pure_1 = createCommonjsModule(function (module, exports) {
618
- exports.__esModule = true;
619
- exports.default = void 0;
620
- var _shouldUpdate = interopRequireDefault(shouldUpdate_1);
621
- var _shallowEqual = interopRequireDefault(shallowEqual$1);
622
- var _setDisplayName = interopRequireDefault(setDisplayName_1);
623
- var _wrapDisplayName = interopRequireDefault(wrapDisplayName_1);
624
- var pure = function pure(BaseComponent) {
625
- var hoc = (0, _shouldUpdate.default)(function (props, nextProps) {
626
- return !(0, _shallowEqual.default)(props, nextProps);
627
- });
628
- {
629
- return (0, _setDisplayName.default)((0, _wrapDisplayName.default)(BaseComponent, 'pure'))(hoc(BaseComponent));
630
- }
631
- };
632
- var _default = pure;
633
- exports.default = _default;
634
- });
635
- unwrapExports(pure_1);
636
- const require$$0 = _dll_react;
637
- const {SvgIcon: require$$2} = _dll_material_ui__core;
638
- var createSvgIcon_1 = createCommonjsModule(function (module, exports) {
639
- Object.defineProperty(exports, "__esModule", {
640
- value: true
641
- });
642
- exports.default = void 0;
643
- var _react = interopRequireDefault(require$$0);
644
- var _pure = interopRequireDefault(pure_1);
645
- var _SvgIcon = interopRequireDefault(require$$2);
646
- function createSvgIcon(path, displayName) {
647
- var Icon = function Icon(props) {
648
- return _react.default.createElement(_SvgIcon.default, props, path);
649
- };
650
- Icon.displayName = ("").concat(displayName, "Icon");
651
- Icon = (0, _pure.default)(Icon);
652
- Icon.muiName = 'SvgIcon';
653
- return Icon;
654
- }
655
- var _default = createSvgIcon;
656
- exports.default = _default;
657
- });
658
- unwrapExports(createSvgIcon_1);
659
- const require$$0$1 = _dll_react;
660
- var Help = createCommonjsModule(function (module, exports) {
661
- Object.defineProperty(exports, "__esModule", {
662
- value: true
663
- });
664
- exports.default = void 0;
665
- var _react = interopRequireDefault(require$$0$1);
666
- var _createSvgIcon = interopRequireDefault(createSvgIcon_1);
667
- var _default = (0, _createSvgIcon.default)(_react.default.createElement(_react.default.Fragment, null, _react.default.createElement("path", {
668
- fill: "none",
669
- d: "M0 0h24v24H0z"
670
- }), _react.default.createElement("path", {
671
- d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"
672
- })), 'Help');
673
- exports.default = _default;
674
- });
675
- var Help$1 = unwrapExports(Help);
676
- const React$1 = _dll_react;
677
- const PropTypes$1 = _dll_prop_types;
678
- const {withStyles: withStyles$1} = _dll_material_ui__core_styles;
679
- const {Rect: Rect} = _dll_react_konva;
680
- const {Group: Group} = _dll_react_konva;
681
- const _jsxFileName$1 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/hotspot-rectangle.jsx";
682
- class RectComponent extends React$1.Component {
683
- constructor(...args) {
684
- super(...args);
685
- RectComponent.prototype.__init.call(this);
686
- RectComponent.prototype.__init2.call(this);
687
- RectComponent.prototype.__init3.call(this);
688
- RectComponent.prototype.__init4.call(this);
689
- }
690
- __init() {
691
- this.handleClick = e => {
692
- const {width, height, isDrawing, onClick, id} = this.props;
693
- if (width < 0 && height < 0 && isDrawing) {
694
- return;
695
- }
696
- e.cancelBubble = true;
697
- onClick(id);
698
- };
699
- }
700
- __init2() {
701
- this.handleMouseEnter = () => {
702
- document.body.style.cursor = 'pointer';
703
- };
704
- }
705
- __init3() {
706
- this.handleMouseLeave = () => {
707
- document.body.style.cursor = 'default';
708
- };
709
- }
710
- __init4() {
711
- this.handleOnDragEnd = e => {
712
- const {onDragEnd, id} = this.props;
713
- onDragEnd(id, {
714
- x: e.target.x(),
715
- y: e.target.y()
716
- });
717
- };
718
- }
719
- render() {
720
- const {classes, correct, height, hotspotColor, outlineColor, width, x, y, strokeWidth = 5} = this.props;
721
- return React$1.createElement(Group, {
722
- __self: this,
723
- __source: {
724
- fileName: _jsxFileName$1,
725
- lineNumber: 47
726
- }
727
- }, React$1.createElement(Rect, {
728
- classes: classes.base,
729
- width: width,
730
- height: height,
731
- fill: hotspotColor,
732
- onClick: this.handleClick,
733
- onTap: this.handleClick,
734
- draggable: true,
735
- stroke: outlineColor,
736
- strokeWidth: correct ? strokeWidth : 0,
737
- onMouseLeave: this.handleMouseLeave,
738
- onMouseEnter: this.handleMouseEnter,
739
- onDragEnd: this.handleOnDragEnd,
740
- x: x,
741
- y: y,
742
- __self: this,
743
- __source: {
744
- fileName: _jsxFileName$1,
745
- lineNumber: 48
746
- }
747
- }));
748
- }
749
- }
750
- const styles$1 = () => ({
751
- base: {
752
- cursor: 'pointer',
753
- opacity: 0.5
754
- }
755
- });
756
- RectComponent.propTypes = {
757
- classes: PropTypes$1.object.isRequired,
758
- correct: PropTypes$1.bool,
759
- isDrawing: PropTypes$1.bool.isRequired,
760
- id: PropTypes$1.string.isRequired,
761
- height: PropTypes$1.number.isRequired,
762
- hotspotColor: PropTypes$1.string.isRequired,
763
- onClick: PropTypes$1.func.isRequired,
764
- onDragEnd: PropTypes$1.func.isRequired,
765
- outlineColor: PropTypes$1.string.isRequired,
766
- width: PropTypes$1.number.isRequired,
767
- x: PropTypes$1.number.isRequired,
768
- y: PropTypes$1.number.isRequired,
769
- strokeWidth: PropTypes$1.number
770
- };
771
- RectComponent.defaultProps = {
772
- correct: false
773
- };
774
- var Rectangle = withStyles$1(styles$1)(RectComponent);
775
- const React$2 = _dll_react;
776
- const PropTypes$2 = _dll_prop_types;
777
- const {withStyles: withStyles$2} = _dll_material_ui__core_styles;
778
- const {Group: Group$1} = _dll_react_konva;
779
- const {Line: Line} = _dll_react_konva;
780
- const _jsxFileName$2 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/hotspot-polygon.jsx";
781
- class PolComponent extends React$2.Component {
782
- constructor(...args) {
783
- super(...args);
784
- PolComponent.prototype.__init.call(this);
785
- PolComponent.prototype.__init2.call(this);
786
- PolComponent.prototype.__init3.call(this);
787
- PolComponent.prototype.__init4.call(this);
788
- PolComponent.prototype.__init5.call(this);
789
- }
790
- static getDerivedStateFromProps(nextProps) {
791
- const {points} = nextProps;
792
- const xList = points.map(p => p.x);
793
- const yList = points.map(p => p.y);
794
- const xOffset = Math.min(...xList);
795
- const yOffset = Math.max(...yList);
796
- if (points.length) {
797
- return {
798
- x: xOffset,
799
- y: yOffset,
800
- points: points.reduce((acc, point) => {
801
- return acc.concat([point.x - xOffset, point.y - yOffset]);
802
- }, [])
803
- };
804
- }
805
- return {
806
- x: 0,
807
- y: 0,
808
- points: []
809
- };
810
- }
811
- __init() {
812
- this.state = {};
813
- }
814
- __init2() {
815
- this.handleClick = e => {
816
- const {points} = this.props;
817
- const xList = points.map(p => p.x);
818
- const yList = points.map(p => p.y);
819
- const width = Math.max(...xList) - Math.min(...xList);
820
- const height = Math.max(...yList) - Math.min(...yList);
821
- const {isDrawing, onClick, id} = this.props;
822
- if (width < 0 && height < 0 && isDrawing) {
823
- return;
824
- }
825
- e.cancelBubble = true;
826
- onClick(id);
827
- };
828
- }
829
- __init3() {
830
- this.handleMouseEnter = () => {
831
- document.body.style.cursor = 'pointer';
832
- };
833
- }
834
- __init4() {
835
- this.handleMouseLeave = () => {
836
- document.body.style.cursor = 'default';
837
- };
838
- }
839
- __init5() {
840
- this.handleOnDragEnd = e => {
841
- const {onDragEnd, id} = this.props;
842
- const points = e.target.points() || this.state.points;
843
- const newPoints = points.reduce((acc, currentPointCoordinate, index) => {
844
- if (index % 2 === 0 && index + 1 < points.length) {
845
- acc.push({
846
- x: currentPointCoordinate + e.target.x(),
847
- y: points[index + 1] + e.target.y()
848
- });
849
- return acc;
850
- } else {
851
- return acc;
852
- }
853
- }, []);
854
- onDragEnd(id, {
855
- points: newPoints
856
- });
857
- };
858
- }
859
- render() {
860
- const {classes, correct, hotspotColor, outlineColor, strokeWidth = 5} = this.props;
861
- const {points, x, y} = this.state;
862
- return React$2.createElement(Group$1, {
863
- __self: this,
864
- __source: {
865
- fileName: _jsxFileName$2,
866
- lineNumber: 91
867
- }
868
- }, React$2.createElement(Line, {
869
- classes: classes.base,
870
- points: points,
871
- closed: true,
872
- fill: hotspotColor,
873
- onClick: this.handleClick,
874
- onTap: this.handleClick,
875
- draggable: true,
876
- stroke: outlineColor,
877
- strokeWidth: correct ? strokeWidth : 0,
878
- onMouseLeave: this.handleMouseLeave,
879
- onMouseEnter: this.handleMouseEnter,
880
- onDragEnd: this.handleOnDragEnd,
881
- x: x,
882
- y: y,
883
- __self: this,
884
- __source: {
885
- fileName: _jsxFileName$2,
886
- lineNumber: 92
887
- }
888
- }));
889
- }
890
- }
891
- const styles$2 = () => ({
892
- base: {
893
- cursor: 'pointer',
894
- opacity: 0.5
895
- }
896
- });
897
- PolComponent.propTypes = {
898
- classes: PropTypes$2.object.isRequired,
899
- correct: PropTypes$2.bool,
900
- isDrawing: PropTypes$2.bool.isRequired,
901
- id: PropTypes$2.string.isRequired,
902
- hotspotColor: PropTypes$2.string.isRequired,
903
- onClick: PropTypes$2.func.isRequired,
904
- onDragEnd: PropTypes$2.func.isRequired,
905
- outlineColor: PropTypes$2.string.isRequired,
906
- points: PropTypes$2.arrayOf(PropTypes$2.shape({
907
- x: PropTypes$2.number,
908
- y: PropTypes$2.number
909
- })).isRequired,
910
- strokeWidth: PropTypes$2.number
911
- };
912
- PolComponent.defaultProps = {
913
- correct: false
914
- };
915
- var Polygon = withStyles$2(styles$2)(PolComponent);
916
- const {cloneDeep: cloneDeep} = _dll_lodash;
917
- const updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {
918
- if (keepAspectRatio) {
919
- const imageAspectRatio = initialDim.width / initialDim.height;
920
- if (resizeType === 'height') {
921
- return {
922
- width: nextDim.height * imageAspectRatio,
923
- height: nextDim.height
924
- };
925
- }
926
- return {
927
- width: nextDim.width,
928
- height: nextDim.width / imageAspectRatio
929
- };
930
- }
931
- return {
932
- width: nextDim.width,
933
- height: nextDim.height
934
- };
935
- };
936
- const getDelta = (referenceInitialValue, referenceNextValue, currentValue) => referenceNextValue / referenceInitialValue * currentValue;
937
- const getUpdatedRectangle = (initialDim, nextDim, shape) => ({
938
- ...shape,
939
- width: getDelta(initialDim.width, nextDim.width, shape.width),
940
- height: getDelta(initialDim.height, nextDim.height, shape.height),
941
- x: getDelta(initialDim.width, nextDim.width, shape.x),
942
- y: getDelta(initialDim.height, nextDim.height, shape.y)
943
- });
944
- const getUpdatedPlygon = (initialDim, nextDim, shape) => ({
945
- ...shape,
946
- points: shape.points.map(point => ({
947
- x: getDelta(initialDim.width, nextDim.width, point.x),
948
- y: getDelta(initialDim.height, nextDim.height, point.y)
949
- }))
950
- });
951
- const getUpdatedShapes = (initialDim, nextDim, shapes) => {
952
- return shapes.map(shape => {
953
- if (shape.group === 'rectangles') {
954
- return getUpdatedRectangle(initialDim, nextDim, shape);
955
- }
956
- if (shape.group === 'polygons') {
957
- return getUpdatedPlygon(initialDim, nextDim, shape);
958
- }
959
- });
960
- };
961
- const getAllShapes = shapesMap => {
962
- shapesMap = shapesMap || ({});
963
- const shapesArray = [];
964
- const shapesKeys = Object.keys(shapesMap);
965
- return shapesKeys.length ? shapesKeys.reduce((acc, currentShapeKey) => acc.concat(shapesMap[currentShapeKey] ? shapesMap[currentShapeKey].map((shape, index) => ({
966
- ...shape,
967
- group: currentShapeKey,
968
- index: shape.index || acc.length + index
969
- })) : []), shapesArray) : shapesArray;
970
- };
971
- const groupShapes = shapesArray => {
972
- shapesArray = shapesArray || [];
973
- const shapesMap = {
974
- rectangles: [],
975
- polygons: []
976
- };
977
- if (shapesArray.length) {
978
- return shapesArray.reduce((acc, {group, ...shapeProps}) => {
979
- acc[group] = [...acc[group] || [], shapeProps];
980
- return acc;
981
- }, shapesMap);
982
- }
983
- return cloneDeep(shapesMap);
984
- };
985
- const React$3 = _dll_react;
986
- const PropTypes$3 = _dll_prop_types;
987
- const {max: max} = _dll_lodash;
988
- const {cloneDeep: cloneDeep$1} = _dll_lodash;
989
- const {withStyles: withStyles$3} = _dll_material_ui__core_styles;
990
- const {Layer: Layer} = _dll_react_konva;
991
- const {Stage: Stage} = _dll_react_konva;
992
- const _jsxFileName$3 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/hotspot-drawable.jsx";
993
- class Drawable extends React$3.Component {
994
- static getDerivedStateFromProps(nextProps, prevState) {
995
- let dimensions = nextProps.dimensions;
996
- if (prevState && prevState.resizing) {
997
- dimensions = prevState.dimensions;
998
- }
999
- return {
1000
- ...prevState,
1001
- dimensions: dimensions
1002
- };
1003
- }
1004
- constructor(props) {
1005
- super(props);
1006
- Drawable.prototype.__init.call(this);
1007
- Drawable.prototype.__init2.call(this);
1008
- Drawable.prototype.__init3.call(this);
1009
- Drawable.prototype.__init4.call(this);
1010
- Drawable.prototype.__init5.call(this);
1011
- Drawable.prototype.__init6.call(this);
1012
- Drawable.prototype.__init7.call(this);
1013
- Drawable.prototype.__init8.call(this);
1014
- Drawable.prototype.__init9.call(this);
1015
- this.state = {
1016
- isDrawing: false,
1017
- stateShapes: false,
1018
- resizing: false,
1019
- dimensions: {
1020
- height: 0,
1021
- width: 0
1022
- }
1023
- };
1024
- }
1025
- __init() {
1026
- this.handleOnMouseDown = e => {
1027
- if (e.target === e.currentTarget) {
1028
- const {onUpdateShapes, shapes} = this.props;
1029
- const newShapes = shapes.slice();
1030
- const value = max(newShapes.map(c => parseInt(c.id)).filter(id => !isNaN(id))) || 0;
1031
- newShapes.push({
1032
- id: `${value + 1}`,
1033
- height: 0,
1034
- width: 0,
1035
- x: e.evt.layerX,
1036
- y: e.evt.layerY,
1037
- group: 'rectangles',
1038
- index: shapes.length
1039
- });
1040
- this.setState({
1041
- isDrawing: true,
1042
- isDrawingShapeId: `${value + 1}`
1043
- });
1044
- onUpdateShapes(newShapes);
1045
- }
1046
- };
1047
- }
1048
- __init2() {
1049
- this.handleOnMouseUp = () => {
1050
- const {isDrawing, stateShapes} = this.state;
1051
- const {onUpdateShapes} = this.props;
1052
- if (isDrawing) {
1053
- this.setState({
1054
- isDrawing: !isDrawing,
1055
- stateShapes: false,
1056
- isDrawingShapeId: undefined
1057
- });
1058
- if (stateShapes) {
1059
- onUpdateShapes(stateShapes);
1060
- }
1061
- }
1062
- };
1063
- }
1064
- __init3() {
1065
- this.handleMouseMove = e => {
1066
- const {isDrawing, isDrawingShapeId} = this.state;
1067
- const {shapes} = this.props;
1068
- if (isDrawing && isDrawingShapeId) {
1069
- const mouseX = e.evt.layerX;
1070
- const mouseY = e.evt.layerY;
1071
- const currShapeIndex = shapes.findIndex(shape => shape.id === isDrawingShapeId);
1072
- const currShape = shapes[currShapeIndex];
1073
- if (currShape) {
1074
- const newWidth = mouseX - currShape.x;
1075
- const newHeight = mouseY - currShape.y;
1076
- const newShapesList = shapes.slice();
1077
- newShapesList[currShapeIndex] = {
1078
- ...newShapesList[currShapeIndex],
1079
- height: newHeight,
1080
- width: newWidth,
1081
- x: currShape.x,
1082
- y: currShape.y
1083
- };
1084
- this.setState({
1085
- stateShapes: newShapesList
1086
- });
1087
- }
1088
- }
1089
- };
1090
- }
1091
- __init4() {
1092
- this.handleOnDragEnd = (id, updatedProps) => {
1093
- const {shapes, onUpdateShapes} = this.props;
1094
- const newShapes = shapes.map(shape => {
1095
- if (shape.id === id) {
1096
- return {
1097
- ...shape,
1098
- ...updatedProps
1099
- };
1100
- }
1101
- return shape;
1102
- });
1103
- onUpdateShapes(cloneDeep$1(newShapes));
1104
- };
1105
- }
1106
- __init5() {
1107
- this.handleOnSetAsCorrect = shape => {
1108
- const {id} = shape;
1109
- const {multipleCorrect, shapes, onUpdateShapes} = this.props;
1110
- let newShapes = [];
1111
- if (multipleCorrect) {
1112
- newShapes = shapes.map(shape => {
1113
- if (shape.id === id) {
1114
- shape.correct = !shape.correct;
1115
- }
1116
- return shape;
1117
- });
1118
- } else {
1119
- newShapes = shapes.map(shape => {
1120
- shape.correct = shape.id === id;
1121
- return shape;
1122
- });
1123
- }
1124
- onUpdateShapes(cloneDeep$1(newShapes));
1125
- };
1126
- }
1127
- __init6() {
1128
- this.handleOnImageLoad = ({target}) => {
1129
- const {onUpdateImageDimension} = this.props;
1130
- const resizeHandle = this.resize;
1131
- const elementStyle = getComputedStyle(target);
1132
- const newHeight = parseFloat(elementStyle.height);
1133
- const newWidth = parseFloat(elementStyle.width);
1134
- const dimensions = {
1135
- height: newHeight,
1136
- width: newWidth
1137
- };
1138
- this.setState({
1139
- dimensions
1140
- }, () => onUpdateImageDimension(dimensions));
1141
- resizeHandle.addEventListener('mousedown', this.initialiseResize, false);
1142
- };
1143
- }
1144
- __init7() {
1145
- this.initialiseResize = () => {
1146
- window.addEventListener('mousemove', this.startResizing, false);
1147
- window.addEventListener('mouseup', this.stopResizing, false);
1148
- };
1149
- }
1150
- checkIfResizeValid(x, y) {
1151
- const {shapes} = this.state;
1152
- let drawable = true;
1153
- shapes && shapes.forEach(shape => {
1154
- const right = shape.x + shape.width + 5;
1155
- const bottom = shape.y + shape.height + 5;
1156
- if (x <= right || y <= bottom) {
1157
- drawable = false;
1158
- }
1159
- });
1160
- return drawable;
1161
- }
1162
- __init8() {
1163
- this.startResizing = e => {
1164
- const bounds = e.target.getBoundingClientRect();
1165
- const box = this.image;
1166
- const {disableDrag, preserveAspectRatioEnabled, dimensions, shapes} = this.props;
1167
- const {width, height} = updateImageDimensions(dimensions, {
1168
- width: e.clientX - bounds.left,
1169
- height: e.clientY - bounds.top
1170
- }, preserveAspectRatioEnabled);
1171
- const resizeValid = this.checkIfResizeValid(width, height);
1172
- const hasMinimumWidth = width > 150 && height > 150;
1173
- if (resizeValid && hasMinimumWidth) {
1174
- box.style.width = `${width}px`;
1175
- box.style.height = `${height}px`;
1176
- this.setState({
1177
- resizing: true,
1178
- dimensions: {
1179
- height: height,
1180
- width: width
1181
- },
1182
- stateShapes: getUpdatedShapes(dimensions, {
1183
- width,
1184
- height
1185
- }, shapes)
1186
- });
1187
- }
1188
- disableDrag();
1189
- };
1190
- }
1191
- __init9() {
1192
- this.stopResizing = () => {
1193
- const {enableDrag, onUpdateImageDimension, onUpdateShapes} = this.props;
1194
- const {dimensions, stateShapes} = this.state;
1195
- enableDrag();
1196
- if (stateShapes) {
1197
- onUpdateShapes(cloneDeep$1(stateShapes));
1198
- }
1199
- onUpdateImageDimension(dimensions);
1200
- window.removeEventListener('mousemove', this.startResizing, false);
1201
- window.removeEventListener('mouseup', this.stopResizing, false);
1202
- this.setState({
1203
- resizing: false,
1204
- stateShapes: false
1205
- });
1206
- };
1207
- }
1208
- render() {
1209
- const {classes, imageUrl, dimensions: {height, width}, hotspotColor, outlineColor, shapes, strokeWidth} = this.props;
1210
- const {stateShapes, isDrawing, dimensions: {height: heightFromState, width: widthFromState}} = this.state;
1211
- const shapesToUse = stateShapes || shapes;
1212
- return React$3.createElement('div', {
1213
- className: classes.base,
1214
- __self: this,
1215
- __source: {
1216
- fileName: _jsxFileName$3,
1217
- lineNumber: 263
1218
- }
1219
- }, imageUrl && React$3.createElement('div', {
1220
- className: classes.imageContainer,
1221
- __self: this,
1222
- __source: {
1223
- fileName: _jsxFileName$3,
1224
- lineNumber: 265
1225
- }
1226
- }, React$3.createElement('img', {
1227
- className: classes.image,
1228
- onLoad: this.handleOnImageLoad,
1229
- ref: ref => {
1230
- this.image = ref;
1231
- },
1232
- src: imageUrl,
1233
- ...height && width ? {
1234
- style: {
1235
- height,
1236
- width
1237
- }
1238
- } : {},
1239
- __self: this,
1240
- __source: {
1241
- fileName: _jsxFileName$3,
1242
- lineNumber: 266
1243
- }
1244
- }), React$3.createElement('div', {
1245
- ref: ref => {
1246
- this.resize = ref;
1247
- },
1248
- className: classes.resize,
1249
- __self: this,
1250
- __source: {
1251
- fileName: _jsxFileName$3,
1252
- lineNumber: 275
1253
- }
1254
- })), React$3.createElement(Stage, {
1255
- className: classes.stage,
1256
- height: heightFromState || height,
1257
- width: widthFromState || width,
1258
- onMouseDown: this.handleOnMouseDown,
1259
- onMouseUp: this.handleOnMouseUp,
1260
- onMouseMove: this.handleMouseMove,
1261
- __self: this,
1262
- __source: {
1263
- fileName: _jsxFileName$3,
1264
- lineNumber: 281
1265
- }
1266
- }, React$3.createElement(Layer, {
1267
- __self: this,
1268
- __source: {
1269
- fileName: _jsxFileName$3,
1270
- lineNumber: 289
1271
- }
1272
- }, shapesToUse.map((shape, index) => {
1273
- const Tag = shape.group === 'polygons' ? Polygon : Rectangle;
1274
- return React$3.createElement(Tag, {
1275
- correct: shape.correct,
1276
- isDrawing: isDrawing,
1277
- height: shape.height,
1278
- hotspotColor: hotspotColor,
1279
- id: shape.id,
1280
- key: index,
1281
- onClick: () => this.handleOnSetAsCorrect(shape),
1282
- onDragEnd: this.handleOnDragEnd,
1283
- outlineColor: outlineColor,
1284
- width: shape.width,
1285
- x: shape.x,
1286
- y: shape.y,
1287
- points: shape.points,
1288
- strokeWidth: strokeWidth,
1289
- __self: this,
1290
- __source: {
1291
- fileName: _jsxFileName$3,
1292
- lineNumber: 294
1293
- }
1294
- });
1295
- }))));
1296
- }
1297
- }
1298
- const styles$3 = () => ({
1299
- base: {
1300
- position: 'relative'
1301
- },
1302
- image: {
1303
- alignItems: 'center',
1304
- display: 'flex',
1305
- justifyContent: 'center'
1306
- },
1307
- imageContainer: {
1308
- position: 'relative',
1309
- width: 'fit-content'
1310
- },
1311
- resize: {
1312
- borderBottom: '1px solid #727272',
1313
- borderRight: '1px solid #727272',
1314
- bottom: '-10px',
1315
- cursor: 'se-resize',
1316
- height: '10px',
1317
- position: 'absolute',
1318
- right: '-10px',
1319
- width: '10px'
1320
- },
1321
- stage: {
1322
- left: 0,
1323
- top: 0,
1324
- position: 'absolute'
1325
- }
1326
- });
1327
- Drawable.propTypes = {
1328
- classes: PropTypes$3.object.isRequired,
1329
- disableDrag: PropTypes$3.func.isRequired,
1330
- dimensions: PropTypes$3.object.isRequired,
1331
- enableDrag: PropTypes$3.func.isRequired,
1332
- imageUrl: PropTypes$3.string.isRequired,
1333
- hotspotColor: PropTypes$3.string.isRequired,
1334
- multipleCorrect: PropTypes$3.bool.isRequired,
1335
- onUpdateImageDimension: PropTypes$3.func.isRequired,
1336
- onUpdateShapes: PropTypes$3.func.isRequired,
1337
- outlineColor: PropTypes$3.string.isRequired,
1338
- shapes: PropTypes$3.array.isRequired,
1339
- strokeWidth: PropTypes$3.number,
1340
- preserveAspectRatioEnabled: PropTypes$3.bool
1341
- };
1342
- var Drawable$1 = withStyles$3(styles$3)(Drawable);
1343
- var classnames = createCommonjsModule(function (module) {
1344
- (function () {
1345
- var hasOwn = ({}).hasOwnProperty;
1346
- function classNames() {
1347
- var classes = [];
1348
- for (var i = 0; i < arguments.length; i++) {
1349
- var arg = arguments[i];
1350
- if (!arg) continue;
1351
- var argType = typeof arg;
1352
- if (argType === 'string' || argType === 'number') {
1353
- classes.push(arg);
1354
- } else if (Array.isArray(arg) && arg.length) {
1355
- var inner = classNames.apply(null, arg);
1356
- if (inner) {
1357
- classes.push(inner);
1358
- }
1359
- } else if (argType === 'object') {
1360
- for (var key in arg) {
1361
- if (hasOwn.call(arg, key) && arg[key]) {
1362
- classes.push(key);
1363
- }
1364
- }
1365
- }
1366
- }
1367
- return classes.join(' ');
1368
- }
1369
- if (module.exports) {
1370
- classNames.default = classNames;
1371
- module.exports = classNames;
1372
- } else {
1373
- window.classNames = classNames;
1374
- }
1375
- })();
1376
- });
1377
- const React$4 = _dll_react;
1378
- const PropTypes$4 = _dll_prop_types;
1379
- const {withStyles: withStyles$4} = _dll_material_ui__core_styles;
1380
- const {Button: Button} = _dll_material_ui__core;
1381
- const _jsxFileName$4 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/button.jsx";
1382
- const RawButton = ({classes, className, label, onClick, disabled}) => React$4.createElement(Button, {
1383
- onClick: onClick,
1384
- disabled: disabled,
1385
- className: classnames(classes.addButton, className),
1386
- size: "small",
1387
- variant: "contained",
1388
- color: "default",
1389
- __self: undefined,
1390
- __source: {
1391
- fileName: _jsxFileName$4,
1392
- lineNumber: 8
1393
- }
1394
- }, label);
1395
- RawButton.propTypes = {
1396
- classes: PropTypes$4.object.isRequired,
1397
- className: PropTypes$4.string,
1398
- disabled: PropTypes$4.bool,
1399
- label: PropTypes$4.string,
1400
- onClick: PropTypes$4.func
1401
- };
1402
- RawButton.defaultProps = {
1403
- className: '',
1404
- disabled: false,
1405
- label: 'Add',
1406
- onClick: () => {}
1407
- };
1408
- const styles$4 = () => ({
1409
- addButton: {
1410
- marginLeft: 8
1411
- }
1412
- });
1413
- const ButtonStyled = withStyles$4(styles$4)(RawButton);
1414
- const React$5 = _dll_react;
1415
- const PropTypes$5 = _dll_prop_types;
1416
- const {withStyles: withStyles$5} = _dll_material_ui__core_styles;
1417
- const _jsxFileName$5 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/upload-control.jsx";
1418
- const UploadControl = ({classNameButton, classNameSection, classes, label, onInputClick, onUploadImage, setRef}) => React$5.createElement('div', {
1419
- className: classNameSection,
1420
- __self: undefined,
1421
- __source: {
1422
- fileName: _jsxFileName$5,
1423
- lineNumber: 16
1424
- }
1425
- }, React$5.createElement(ButtonStyled, {
1426
- className: classNameButton,
1427
- label: label,
1428
- onClick: onInputClick,
1429
- __self: undefined,
1430
- __source: {
1431
- fileName: _jsxFileName$5,
1432
- lineNumber: 17
1433
- }
1434
- }), React$5.createElement('input', {
1435
- accept: "image/*",
1436
- className: classes.input,
1437
- onChange: onUploadImage,
1438
- ref: ref => {
1439
- setRef(ref);
1440
- },
1441
- type: "file",
1442
- __self: undefined,
1443
- __source: {
1444
- fileName: _jsxFileName$5,
1445
- lineNumber: 22
1446
- }
1447
- }));
1448
- const styles$5 = () => ({
1449
- input: {
1450
- display: 'none'
1451
- }
1452
- });
1453
- UploadControl.propTypes = {
1454
- classes: PropTypes$5.object.isRequired,
1455
- classNameButton: PropTypes$5.string,
1456
- classNameSection: PropTypes$5.string,
1457
- label: PropTypes$5.string.isRequired,
1458
- onInputClick: PropTypes$5.func.isRequired,
1459
- onUploadImage: PropTypes$5.func.isRequired,
1460
- setRef: PropTypes$5.func.isRequired
1461
- };
1462
- UploadControl.defaultProps = {
1463
- classNameButton: '',
1464
- classNameSection: ''
1465
- };
1466
- var UploadControl$1 = withStyles$5(styles$5)(UploadControl);
1467
- const React$6 = _dll_react;
1468
- const {Component: Component} = _dll_react;
1469
- const PropTypes$6 = _dll_prop_types;
1470
- const {withStyles: withStyles$6} = _dll_material_ui__core_styles;
1471
- const _jsxFileName$6 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/hotspot-container.jsx";
1472
- const isImage = file => {
1473
- const imageType = /image.*/;
1474
- return file.type.match(imageType);
1475
- };
1476
- class Container extends Component {
1477
- static getDerivedStateFromProps(nextProps, prevState) {
1478
- return {
1479
- ...prevState,
1480
- shapes: getAllShapes(nextProps.shapes)
1481
- };
1482
- }
1483
- constructor(props) {
1484
- super(props);
1485
- Container.prototype.__init.call(this);
1486
- Container.prototype.__init2.call(this);
1487
- Container.prototype.__init3.call(this);
1488
- Container.prototype.__init4.call(this);
1489
- Container.prototype.__init5.call(this);
1490
- Container.prototype.__init6.call(this);
1491
- Container.prototype.__init7.call(this);
1492
- Container.prototype.__init8.call(this);
1493
- Container.prototype.__init9.call(this);
1494
- Container.prototype.__init10.call(this);
1495
- Container.prototype.__init11.call(this);
1496
- Container.prototype.__init12.call(this);
1497
- Container.prototype.__init13.call(this);
1498
- Container.prototype.__init14.call(this);
1499
- this.state = {
1500
- dragEnabled: true,
1501
- shapes: getAllShapes(props.shapes)
1502
- };
1503
- }
1504
- __init() {
1505
- this.handleFileRead = file => {
1506
- const {onImageUpload} = this.props;
1507
- const reader = new FileReader();
1508
- reader.onloadend = () => onImageUpload(reader.result);
1509
- reader.readAsDataURL(file);
1510
- };
1511
- }
1512
- __init2() {
1513
- this.handleUploadImage = e => {
1514
- e.preventDefault();
1515
- this.handleFileRead(e.target.files[0]);
1516
- };
1517
- }
1518
- __init3() {
1519
- this.enableDropzone = () => this.setState({
1520
- dropzoneActive: true
1521
- });
1522
- }
1523
- __init4() {
1524
- this.disableDropzone = () => this.setState({
1525
- dropzoneActive: false
1526
- });
1527
- }
1528
- __init5() {
1529
- this.handleOnDrop = e => {
1530
- e.preventDefault();
1531
- const {items, files} = e.dataTransfer;
1532
- if (items && items[0].kind === 'file') {
1533
- const file = items[0].getAsFile();
1534
- if (isImage(file)) {
1535
- this.handleFileRead(file);
1536
- }
1537
- } else if (isImage(files[0])) {
1538
- this.handleFileRead(files[0]);
1539
- }
1540
- this.disableDropzone();
1541
- };
1542
- }
1543
- __init6() {
1544
- this.handleOnDragOver = e => {
1545
- e.preventDefault();
1546
- const {dropzoneActive} = this.state;
1547
- if (!dropzoneActive) {
1548
- this.enableDropzone();
1549
- }
1550
- };
1551
- }
1552
- __init7() {
1553
- this.handleOnDragExit = e => {
1554
- e.preventDefault();
1555
- this.disableDropzone();
1556
- };
1557
- }
1558
- __init8() {
1559
- this.onUpdateShapes = newShapes => {
1560
- const {onUpdateShapes} = this.props;
1561
- this.setState({
1562
- shapes: newShapes
1563
- }, () => onUpdateShapes(groupShapes(newShapes)));
1564
- };
1565
- }
1566
- __init9() {
1567
- this.handleUndo = () => {
1568
- const {shapes} = this.state;
1569
- if (shapes && shapes.length) {
1570
- let newShapes = shapes.sort((a, b) => parseInt(a.index) - parseInt(b.index));
1571
- newShapes = newShapes ? newShapes.slice(0, newShapes.length - 1) : [];
1572
- this.onUpdateShapes(newShapes);
1573
- }
1574
- };
1575
- }
1576
- __init10() {
1577
- this.handleClearAll = () => this.onUpdateShapes([]);
1578
- }
1579
- __init11() {
1580
- this.handleEnableDrag = () => this.setState({
1581
- dragEnabled: true
1582
- });
1583
- }
1584
- __init12() {
1585
- this.handleDisableDrag = () => this.setState({
1586
- dragEnabled: false
1587
- });
1588
- }
1589
- __init13() {
1590
- this.handleInputClick = () => this.input.click();
1591
- }
1592
- __init14() {
1593
- this.toggleTooltip = () => this.setState({
1594
- showTooltip: !this.state.showTooltip
1595
- });
1596
- }
1597
- render() {
1598
- const {classes, dimensions, hotspotColor, imageUrl, multipleCorrect, onUpdateImageDimension, outlineColor, strokeWidth, preserveAspectRatioEnabled} = this.props;
1599
- const {dropzoneActive, dragEnabled, showTooltip} = this.state;
1600
- const {shapes} = this.state;
1601
- return React$6.createElement('div', {
1602
- className: classes.base,
1603
- __self: this,
1604
- __source: {
1605
- fileName: _jsxFileName$6,
1606
- lineNumber: 136
1607
- }
1608
- }, React$6.createElement('div', {
1609
- className: `${classes.box} ${dropzoneActive ? classes.boxActive : ''}`,
1610
- ...dragEnabled ? {
1611
- onDragExit: this.handleOnDragExit,
1612
- onDragLeave: this.handleOnDragExit,
1613
- onDragOver: this.handleOnDragOver,
1614
- onDrop: this.handleOnDrop
1615
- } : {},
1616
- __self: this,
1617
- __source: {
1618
- fileName: _jsxFileName$6,
1619
- lineNumber: 137
1620
- }
1621
- }, React$6.createElement('div', {
1622
- className: classes.toolbar,
1623
- __self: this,
1624
- __source: {
1625
- fileName: _jsxFileName$6,
1626
- lineNumber: 145
1627
- }
1628
- }, imageUrl && React$6.createElement(UploadControl$1, {
1629
- classNameButton: classes.replaceButton,
1630
- classNameSection: classes.replaceSection,
1631
- label: "Replace Image",
1632
- onInputClick: this.handleInputClick,
1633
- onUploadImage: this.handleUploadImage,
1634
- setRef: ref => {
1635
- this.input = ref;
1636
- },
1637
- __self: this,
1638
- __source: {
1639
- fileName: _jsxFileName$6,
1640
- lineNumber: 147
1641
- }
1642
- }), React$6.createElement(ButtonStyled, {
1643
- disabled: !(shapes && shapes.length),
1644
- onClick: this.handleUndo,
1645
- label: "Undo",
1646
- __self: this,
1647
- __source: {
1648
- fileName: _jsxFileName$6,
1649
- lineNumber: 158
1650
- }
1651
- }), React$6.createElement(ButtonStyled, {
1652
- disabled: !(shapes && shapes.length),
1653
- onClick: this.handleClearAll,
1654
- label: "Clear all",
1655
- __self: this,
1656
- __source: {
1657
- fileName: _jsxFileName$6,
1658
- lineNumber: 163
1659
- }
1660
- })), React$6.createElement('div', {
1661
- ref: ref => {
1662
- this.imageSection = ref;
1663
- },
1664
- className: classes.drawableHeight,
1665
- __self: this,
1666
- __source: {
1667
- fileName: _jsxFileName$6,
1668
- lineNumber: 170
1669
- }
1670
- }, imageUrl ? React$6.createElement(Drawable$1, {
1671
- dimensions: dimensions,
1672
- disableDrag: this.handleDisableDrag,
1673
- enableDrag: this.handleEnableDrag,
1674
- imageUrl: imageUrl,
1675
- hotspotColor: hotspotColor,
1676
- multipleCorrect: multipleCorrect,
1677
- onUpdateImageDimension: onUpdateImageDimension,
1678
- onUpdateShapes: this.onUpdateShapes,
1679
- outlineColor: outlineColor,
1680
- shapes: shapes,
1681
- strokeWidth: strokeWidth,
1682
- preserveAspectRatioEnabled: preserveAspectRatioEnabled,
1683
- __self: this,
1684
- __source: {
1685
- fileName: _jsxFileName$6,
1686
- lineNumber: 177
1687
- }
1688
- }) : React$6.createElement('div', {
1689
- className: `${classes.drawableHeight} ${classes.centered}`,
1690
- __self: this,
1691
- __source: {
1692
- fileName: _jsxFileName$6,
1693
- lineNumber: 193
1694
- }
1695
- }, React$6.createElement('label', {
1696
- __self: this,
1697
- __source: {
1698
- fileName: _jsxFileName$6,
1699
- lineNumber: 194
1700
- }
1701
- }, "Drag and drop or upload image from computer"), React$6.createElement('br', {
1702
- __self: this,
1703
- __source: {
1704
- fileName: _jsxFileName$6,
1705
- lineNumber: 195
1706
- }
1707
- }), React$6.createElement(UploadControl$1, {
1708
- label: "Upload Image",
1709
- onInputClick: this.handleInputClick,
1710
- onUploadImage: this.handleUploadImage,
1711
- setRef: ref => {
1712
- this.input = ref;
1713
- },
1714
- __self: this,
1715
- __source: {
1716
- fileName: _jsxFileName$6,
1717
- lineNumber: 196
1718
- }
1719
- }))), imageUrl && React$6.createElement('div', {
1720
- className: classes.tooltip,
1721
- __self: this,
1722
- __source: {
1723
- fileName: _jsxFileName$6,
1724
- lineNumber: 209
1725
- }
1726
- }, showTooltip && React$6.createElement('div', {
1727
- className: classes.tooltipContent,
1728
- __self: this,
1729
- __source: {
1730
- fileName: _jsxFileName$6,
1731
- lineNumber: 211
1732
- }
1733
- }, React$6.createElement('label', {
1734
- __self: this,
1735
- __source: {
1736
- fileName: _jsxFileName$6,
1737
- lineNumber: 212
1738
- }
1739
- }, "Click and drag to create a hotspot. Click the hotspot to mark correct. Click again to unmark."), React$6.createElement('div', {
1740
- className: classes.tooltipArrow,
1741
- __self: this,
1742
- __source: {
1743
- fileName: _jsxFileName$6,
1744
- lineNumber: 216
1745
- }
1746
- })), React$6.createElement(Help$1, {
1747
- className: classes.icon,
1748
- onMouseOut: this.toggleTooltip,
1749
- onMouseOver: this.toggleTooltip,
1750
- __self: this,
1751
- __source: {
1752
- fileName: _jsxFileName$6,
1753
- lineNumber: 219
1754
- }
1755
- }))));
1756
- }
1757
- }
1758
- const styles$6 = theme => ({
1759
- base: {
1760
- marginTop: theme.spacing.unit * 2
1761
- },
1762
- box: {
1763
- border: '1px solid #E0E1E6',
1764
- borderRadius: '5px'
1765
- },
1766
- boxActive: {
1767
- border: '1px solid #0032C2'
1768
- },
1769
- centered: {
1770
- alignItems: 'center',
1771
- display: 'flex',
1772
- flexDirection: 'column',
1773
- justifyContent: 'center'
1774
- },
1775
- drawableHeight: {
1776
- minHeight: 350,
1777
- paddingBottom: '40px',
1778
- paddingRight: '40px'
1779
- },
1780
- icon: {
1781
- '&:hover': {
1782
- color: '#333131',
1783
- cursor: 'help'
1784
- },
1785
- color: '#C1C1C1'
1786
- },
1787
- replaceButton: {
1788
- marginLeft: 0
1789
- },
1790
- replaceSection: {
1791
- marginRight: 'auto'
1792
- },
1793
- toolbar: {
1794
- backgroundColor: '#ECEDF1',
1795
- borderBottom: '1px solid #E0E1E6',
1796
- borderTopLeftRadius: '5px',
1797
- borderTopRightRadius: '5px',
1798
- display: 'flex',
1799
- justifyContent: 'flex-end',
1800
- padding: '12px 8px'
1801
- },
1802
- tooltip: {
1803
- position: 'relative',
1804
- textAlign: 'right',
1805
- padding: '5px 9px'
1806
- },
1807
- tooltipContent: {
1808
- background: '#333131',
1809
- borderRadius: '4px',
1810
- color: '#FFFFFF',
1811
- fontSize: '14px',
1812
- lineHeight: '18px',
1813
- marginTop: '-70px',
1814
- padding: '7px 16px',
1815
- position: 'absolute',
1816
- right: '5px',
1817
- textAlign: 'left',
1818
- width: '300px'
1819
- },
1820
- tooltipArrow: {
1821
- width: 0,
1822
- height: 0,
1823
- borderLeft: '10px solid transparent',
1824
- borderRight: '10px solid transparent',
1825
- borderTop: '10px solid #333131',
1826
- marginBottom: -10,
1827
- marginTop: '2px',
1828
- position: 'absolute',
1829
- right: '5px'
1830
- }
1831
- });
1832
- Container.propTypes = {
1833
- classes: PropTypes$6.object.isRequired,
1834
- dimensions: PropTypes$6.object.isRequired,
1835
- imageUrl: PropTypes$6.string.isRequired,
1836
- hotspotColor: PropTypes$6.string.isRequired,
1837
- multipleCorrect: PropTypes$6.bool.isRequired,
1838
- onImageUpload: PropTypes$6.func.isRequired,
1839
- onUpdateImageDimension: PropTypes$6.func.isRequired,
1840
- onUpdateShapes: PropTypes$6.func.isRequired,
1841
- outlineColor: PropTypes$6.string.isRequired,
1842
- shapes: PropTypes$6.shape({
1843
- rectangles: PropTypes$6.array,
1844
- polygons: PropTypes$6.array
1845
- }).isRequired,
1846
- strokeWidth: PropTypes$6.number,
1847
- preserveAspectRatioEnabled: PropTypes$6.bool
1848
- };
1849
- Container.defaultProps = {
1850
- strokeWidth: 5
1851
- };
1852
- var HotspotContainer = withStyles$6(styles$6)(Container);
1853
- const React$7 = _dll_react;
1854
- const PropTypes$7 = _dll_prop_types;
1855
- const {Typography: Typography} = _dll_material_ui__core;
1856
- const {withStyles: withStyles$7} = _dll_material_ui__core_styles;
1857
- const {settings: settings} = _dll_pie_lib__config_ui;
1858
- const {layout: layout} = _dll_pie_lib__config_ui;
1859
- const {InputContainer: InputContainer$1} = _dll_pie_lib__config_ui;
1860
- const {NumberTextField: NumberTextField} = _dll_pie_lib__config_ui;
1861
- const EditableHtml = _dll_pie_lib__editable_html;
1862
- const _jsxFileName$7 = "/home/ede/dev/github/pie-framework/pie-elements/packages/hotspot/configure/src/root.jsx";
1863
- const {Panel, toggle} = settings;
1864
- class Root extends React$7.Component {
1865
- constructor(...args) {
1866
- super(...args);
1867
- Root.prototype.__init.call(this);
1868
- Root.prototype.__init2.call(this);
1869
- }
1870
- __init() {
1871
- this.handleColorChange = (fieldType, color) => {
1872
- const {onColorChanged} = this.props;
1873
- const cType = `${fieldType}Color`;
1874
- onColorChanged(cType, color);
1875
- };
1876
- }
1877
- __init2() {
1878
- this.handleOnUpdateImageDimensions = (value, resizeType) => {
1879
- const {model: {dimensions, shapes}, configuration: {preserveAspectRatio = {}}, onUpdateImageDimension, onUpdateShapes} = this.props;
1880
- const nextImageDimensions = {
1881
- ...dimensions,
1882
- [resizeType]: value
1883
- };
1884
- const updatedDimensions = updateImageDimensions(dimensions, nextImageDimensions, preserveAspectRatio.enabled, resizeType);
1885
- const shapesArray = getAllShapes(shapes);
1886
- const updatedShapes = getUpdatedShapes(dimensions, updatedDimensions, shapesArray);
1887
- onUpdateShapes(groupShapes(updatedShapes));
1888
- onUpdateImageDimension(updatedDimensions);
1889
- };
1890
- }
1891
- render() {
1892
- const {classes, configuration, model, imageSupport, onConfigurationChanged, onImageUpload, onModelChangedByConfig, onPromptChanged, onRationaleChanged, onUpdateImageDimension, onTeacherInstructionsChanged, onUpdateShapes} = this.props;
1893
- const {multipleCorrect = {}, partialScoring = {}, prompt = {}, teacherInstructions = {}, rationale = {}, preserveAspectRatio = {}} = configuration || ({});
1894
- const {teacherInstructionsEnabled, promptEnabled, rationaleEnabled} = model || ({});
1895
- return React$7.createElement('div', {
1896
- className: classes.base,
1897
- __self: this,
1898
- __source: {
1899
- fileName: _jsxFileName$7,
1900
- lineNumber: 80
1901
- }
1902
- }, React$7.createElement(layout.ConfigLayout, {
1903
- settings: React$7.createElement(Panel, {
1904
- model: model,
1905
- onChangeModel: onModelChangedByConfig,
1906
- configuration: configuration,
1907
- onChangeConfiguration: onConfigurationChanged,
1908
- groups: {
1909
- 'Settings': {
1910
- multipleCorrect: multipleCorrect.settings && toggle(multipleCorrect.label),
1911
- partialScoring: partialScoring.settings && toggle(partialScoring.label),
1912
- promptEnabled: prompt.settings && toggle(prompt.label)
1913
- },
1914
- Properties: {
1915
- teacherInstructionsEnabled: teacherInstructions.settings && toggle(teacherInstructions.label),
1916
- rationaleEnabled: rationale.settings && toggle(rationale.label)
1917
- }
1918
- },
1919
- __self: this,
1920
- __source: {
1921
- fileName: _jsxFileName$7,
1922
- lineNumber: 83
1923
- }
1924
- }),
1925
- __self: this,
1926
- __source: {
1927
- fileName: _jsxFileName$7,
1928
- lineNumber: 81
1929
- }
1930
- }, React$7.createElement('div', {
1931
- className: classes.regular,
1932
- __self: this,
1933
- __source: {
1934
- fileName: _jsxFileName$7,
1935
- lineNumber: 106
1936
- }
1937
- }, teacherInstructionsEnabled && React$7.createElement(InputContainer$1, {
1938
- label: teacherInstructions.label,
1939
- className: classes.prompt,
1940
- __self: this,
1941
- __source: {
1942
- fileName: _jsxFileName$7,
1943
- lineNumber: 108
1944
- }
1945
- }, React$7.createElement(EditableHtml, {
1946
- markup: model.teacherInstructions || '',
1947
- onChange: onTeacherInstructionsChanged,
1948
- imageSupport: imageSupport,
1949
- nonEmpty: false,
1950
- __self: this,
1951
- __source: {
1952
- fileName: _jsxFileName$7,
1953
- lineNumber: 109
1954
- }
1955
- })), promptEnabled && React$7.createElement(InputContainer$1, {
1956
- label: prompt.label,
1957
- className: classes.prompt,
1958
- __self: this,
1959
- __source: {
1960
- fileName: _jsxFileName$7,
1961
- lineNumber: 118
1962
- }
1963
- }, React$7.createElement(EditableHtml, {
1964
- markup: model.prompt || '',
1965
- onChange: onPromptChanged,
1966
- imageSupport: imageSupport,
1967
- nonEmpty: false,
1968
- __self: this,
1969
- __source: {
1970
- fileName: _jsxFileName$7,
1971
- lineNumber: 119
1972
- }
1973
- })), rationaleEnabled && React$7.createElement(InputContainer$1, {
1974
- label: rationale.label,
1975
- className: classes.prompt,
1976
- __self: this,
1977
- __source: {
1978
- fileName: _jsxFileName$7,
1979
- lineNumber: 129
1980
- }
1981
- }, React$7.createElement(EditableHtml, {
1982
- markup: model.rationale || '',
1983
- onChange: onRationaleChanged,
1984
- imageSupport: imageSupport,
1985
- __self: this,
1986
- __source: {
1987
- fileName: _jsxFileName$7,
1988
- lineNumber: 133
1989
- }
1990
- })), React$7.createElement(Typography, {
1991
- className: classes.label,
1992
- variant: "subheading",
1993
- __self: this,
1994
- __source: {
1995
- fileName: _jsxFileName$7,
1996
- lineNumber: 141
1997
- }
1998
- }, "Define Hotspot"), React$7.createElement(HotspotPalette, {
1999
- hotspotColor: model.hotspotColor,
2000
- hotspotList: model.hotspotList,
2001
- outlineColor: model.outlineColor,
2002
- outlineList: model.outlineList,
2003
- onHotspotColorChange: color => this.handleColorChange('hotspot', color),
2004
- onOutlineColorChange: color => this.handleColorChange('outline', color),
2005
- __self: this,
2006
- __source: {
2007
- fileName: _jsxFileName$7,
2008
- lineNumber: 145
2009
- }
2010
- }), React$7.createElement(HotspotContainer, {
2011
- dimensions: model.dimensions,
2012
- imageUrl: model.imageUrl,
2013
- multipleCorrect: model.multipleCorrect,
2014
- hotspotColor: model.hotspotColor,
2015
- outlineColor: model.outlineColor,
2016
- onUpdateImageDimension: onUpdateImageDimension,
2017
- onUpdateShapes: onUpdateShapes,
2018
- onImageUpload: onImageUpload,
2019
- shapes: model.shapes,
2020
- strokeWidth: model.strokeWidth,
2021
- preserveAspectRatioEnabled: preserveAspectRatio.enabled,
2022
- __self: this,
2023
- __source: {
2024
- fileName: _jsxFileName$7,
2025
- lineNumber: 158
2026
- }
2027
- }), model.imageUrl && React$7.createElement('div', {
2028
- __self: this,
2029
- __source: {
2030
- fileName: _jsxFileName$7,
2031
- lineNumber: 173
2032
- }
2033
- }, React$7.createElement(Typography, {
2034
- className: classes.label,
2035
- variant: "subheading",
2036
- __self: this,
2037
- __source: {
2038
- fileName: _jsxFileName$7,
2039
- lineNumber: 174
2040
- }
2041
- }, "Image Dimensions"), React$7.createElement('div', {
2042
- className: classes.dimensions,
2043
- __self: this,
2044
- __source: {
2045
- fileName: _jsxFileName$7,
2046
- lineNumber: 178
2047
- }
2048
- }, React$7.createElement(NumberTextField, {
2049
- key: "hotspot-manual-width",
2050
- label: "Width",
2051
- value: model.dimensions.width,
2052
- min: 0,
2053
- onChange: (e, value) => this.handleOnUpdateImageDimensions(value, 'width'),
2054
- showErrorWhenOutsideRange: true,
2055
- className: classes.field,
2056
- __self: this,
2057
- __source: {
2058
- fileName: _jsxFileName$7,
2059
- lineNumber: 179
2060
- }
2061
- }), React$7.createElement(NumberTextField, {
2062
- key: "hotspot-manual-height",
2063
- label: "Height",
2064
- value: model.dimensions.height,
2065
- min: 0,
2066
- onChange: (e, value) => this.handleOnUpdateImageDimensions(value, 'height'),
2067
- showErrorWhenOutsideRange: true,
2068
- className: classes.field,
2069
- __self: this,
2070
- __source: {
2071
- fileName: _jsxFileName$7,
2072
- lineNumber: 188
2073
- }
2074
- }))))));
2075
- }
2076
- }
2077
- const styles$7 = theme => ({
2078
- base: {
2079
- marginTop: theme.spacing.unit * 3
2080
- },
2081
- container: {
2082
- display: 'flex',
2083
- marginTop: theme.spacing.unit
2084
- },
2085
- dimensions: {
2086
- display: 'flex'
2087
- },
2088
- field: {
2089
- flex: 1,
2090
- width: '90%'
2091
- },
2092
- label: {
2093
- marginTop: theme.spacing.unit * 4
2094
- },
2095
- prompt: {
2096
- paddingTop: theme.spacing.unit * 2,
2097
- width: '100%'
2098
- },
2099
- regular: {
2100
- marginBottom: theme.spacing.unit * 3
2101
- },
2102
- switchElement: {
2103
- justifyContent: 'space-between',
2104
- margin: 0
2105
- }
2106
- });
2107
- Root.propTypes = {
2108
- classes: PropTypes$7.object.isRequired,
2109
- configuration: PropTypes$7.object,
2110
- model: PropTypes$7.object.isRequired,
2111
- imageSupport: PropTypes$7.shape({
2112
- add: PropTypes$7.func,
2113
- delete: PropTypes$7.func
2114
- }),
2115
- onImageUpload: PropTypes$7.func.isRequired,
2116
- onColorChanged: PropTypes$7.func.isRequired,
2117
- onPromptChanged: PropTypes$7.func.isRequired,
2118
- onUpdateImageDimension: PropTypes$7.func.isRequired,
2119
- onUpdateShapes: PropTypes$7.func.isRequired,
2120
- onModelChangedByConfig: PropTypes$7.func.isRequired,
2121
- onRationaleChanged: PropTypes$7.func.isRequired,
2122
- onConfigurationChanged: PropTypes$7.func.isRequired,
2123
- onTeacherInstructionsChanged: PropTypes$7.func.isRequired
2124
- };
2125
- var Root$1 = withStyles$7(styles$7)(Root);
2126
- var sensibleDefaults = {
2127
- model: {
2128
- prompt: 'This is the question prompt',
2129
- promptEnabled: true,
2130
- imageUrl: '',
2131
- shapes: {
2132
- rectangles: [],
2133
- polygons: []
2134
- },
2135
- multipleCorrect: true,
2136
- partialScoring: false,
2137
- dimensions: {
2138
- height: 0,
2139
- width: 0
2140
- },
2141
- hotspotColor: 'rgba(137, 183, 244, 0.65)',
2142
- hotspotList: ['rgba(137, 183, 244, 0.65)'],
2143
- outlineColor: 'blue',
2144
- outlineList: ['blue'],
2145
- rationaleEnabled: true,
2146
- teacherInstructionsEnabled: true,
2147
- studentInstructionsEnabled: true,
2148
- strokeWidth: 5
2149
- },
2150
- configuration: {
2151
- multipleCorrect: {
2152
- settings: true,
2153
- label: 'Multiple Correct Responses'
2154
- },
2155
- partialScoring: {
2156
- settings: false,
2157
- label: 'Allow Partial Scoring'
2158
- },
2159
- rationale: {
2160
- settings: true,
2161
- label: 'Rationale'
2162
- },
2163
- prompt: {
2164
- settings: true,
2165
- label: 'Prompt'
2166
- },
2167
- teacherInstructions: {
2168
- settings: true,
2169
- label: 'Teacher Instructions'
2170
- },
2171
- preserveAspectRatio: {
2172
- settings: false,
2173
- enabled: true,
2174
- label: 'Preserve aspect ratio'
2175
- }
2176
- }
2177
- };
2178
- const React$8 = _dll_react;
2179
- const ReactDOM = _dll_react_dom;
2180
- const {ModelUpdatedEvent: ModelUpdatedEvent} = _dll_pie_framework__pie_configure_events;
2181
- const {DeleteImageEvent: DeleteImageEvent} = _dll_pie_framework__pie_configure_events;
2182
- const {InsertImageEvent: InsertImageEvent} = _dll_pie_framework__pie_configure_events;
2183
- const log = browser('hotspot:configure');
2184
- class HotspotConfigure extends HTMLElement {
2185
- static __initStatic() {
2186
- this.createDefaultModel = (model = {}) => ({
2187
- ...sensibleDefaults.model,
2188
- ...model,
2189
- hotspotList: model.hotspotList || [model.hotspotColor] || sensibleDefaults.model.hotspotList,
2190
- outlineList: model.outlineList || [model.outlineColor] || sensibleDefaults.model.outlineList,
2191
- shapes: model.shapes || sensibleDefaults.model.shapes || ({})
2192
- });
2193
- }
2194
- constructor() {
2195
- super();
2196
- HotspotConfigure.prototype.__init.call(this);
2197
- HotspotConfigure.prototype.__init2.call(this);
2198
- HotspotConfigure.prototype.__init3.call(this);
2199
- HotspotConfigure.prototype.__init4.call(this);
2200
- HotspotConfigure.prototype.__init5.call(this);
2201
- HotspotConfigure.prototype.__init6.call(this);
2202
- HotspotConfigure.prototype.__init7.call(this);
2203
- HotspotConfigure.prototype.__init8.call(this);
2204
- HotspotConfigure.prototype.__init9.call(this);
2205
- HotspotConfigure.prototype.__init10.call(this);
2206
- HotspotConfigure.prototype.__init11.call(this);
2207
- this._model = HotspotConfigure.createDefaultModel();
2208
- this._configuration = sensibleDefaults.configuration;
2209
- this.onModelChanged = this.onModelChanged.bind(this);
2210
- }
2211
- set model(s) {
2212
- this._model = HotspotConfigure.createDefaultModel(s);
2213
- this._render();
2214
- }
2215
- set configuration(c) {
2216
- this._configuration = c;
2217
- this._render();
2218
- }
2219
- dispatchModelUpdated(reset) {
2220
- const resetValue = !!reset;
2221
- this.dispatchEvent(new ModelUpdatedEvent(this._model, resetValue));
2222
- }
2223
- onModelChanged(m, reset) {
2224
- this._model = m;
2225
- this.dispatchModelUpdated(reset);
2226
- this._render();
2227
- }
2228
- __init() {
2229
- this.onConfigurationChanged = c => {
2230
- this._configuration = c;
2231
- this._render();
2232
- };
2233
- }
2234
- __init2() {
2235
- this.onModelChangedByConfig = (m, propertyType) => {
2236
- const _model = m;
2237
- if (propertyType === 'multipleCorrect') {
2238
- const {rectangles = [], polygons = []} = _model.shapes || ({});
2239
- _model.shapes.rectangles = rectangles.map(shape => ({
2240
- ...shape,
2241
- correct: false
2242
- }));
2243
- _model.shapes.polygons = polygons.map(shape => ({
2244
- ...shape,
2245
- correct: false
2246
- }));
2247
- }
2248
- this.onModelChanged(_model);
2249
- };
2250
- }
2251
- __init3() {
2252
- this.onColorChanged = (colorType, color) => {
2253
- this.onModelChanged({
2254
- ...this._model,
2255
- [colorType]: color
2256
- });
2257
- };
2258
- }
2259
- __init4() {
2260
- this.onPromptChanged = prompt => {
2261
- this.onModelChanged({
2262
- ...this._model,
2263
- prompt
2264
- });
2265
- };
2266
- }
2267
- __init5() {
2268
- this.onRationaleChanged = rationale => {
2269
- this.onModelChanged({
2270
- ...this._model,
2271
- rationale
2272
- });
2273
- };
2274
- }
2275
- __init6() {
2276
- this.onTeacherInstructionsChanged = teacherInstructions => {
2277
- this.onModelChanged({
2278
- ...this._model,
2279
- teacherInstructions
2280
- });
2281
- };
2282
- }
2283
- __init7() {
2284
- this.onUpdateImageDimension = dimensions => {
2285
- this.onModelChanged({
2286
- ...this._model,
2287
- dimensions
2288
- });
2289
- };
2290
- }
2291
- __init8() {
2292
- this.onUpdateShapes = shapes => {
2293
- this.onModelChanged({
2294
- ...this._model,
2295
- shapes
2296
- });
2297
- };
2298
- }
2299
- __init9() {
2300
- this.onImageUpload = imageUrl => {
2301
- this.onModelChanged({
2302
- ...this._model,
2303
- imageUrl
2304
- });
2305
- };
2306
- }
2307
- __init10() {
2308
- this.insertImage = handler => {
2309
- this.dispatchEvent(new InsertImageEvent(handler));
2310
- };
2311
- }
2312
- __init11() {
2313
- this.onDeleteImage = (src, done) => {
2314
- this.dispatchEvent(new DeleteImageEvent(src, done));
2315
- };
2316
- }
2317
- _render() {
2318
- log('_render');
2319
- let element = React$8.createElement(Root$1, {
2320
- configuration: this._configuration,
2321
- model: this._model,
2322
- onColorChanged: this.onColorChanged,
2323
- onImageUpload: this.onImageUpload,
2324
- onRationaleChanged: this.onRationaleChanged,
2325
- onConfigurationChanged: this.onConfigurationChanged,
2326
- onPromptChanged: this.onPromptChanged,
2327
- onUpdateImageDimension: this.onUpdateImageDimension,
2328
- imageSupport: {
2329
- add: this.insertImage,
2330
- delete: this.onDeleteImage
2331
- },
2332
- onUpdateShapes: this.onUpdateShapes,
2333
- onModelChangedByConfig: this.onModelChangedByConfig,
2334
- onTeacherInstructionsChanged: this.onTeacherInstructionsChanged
2335
- });
2336
- ReactDOM.render(element, this);
2337
- }
2338
- }
2339
- HotspotConfigure.__initStatic();
2340
- export default HotspotConfigure;