lost-sia 0.7.0 → 1.0.0

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.
package/dist/index.js CHANGED
@@ -6,16 +6,17 @@ var React = require('react');
6
6
  var React__default = _interopDefault(React);
7
7
  var semanticUiReact = require('semantic-ui-react');
8
8
  var _ = _interopDefault(require('lodash'));
9
+ var reactDom = _interopDefault(require('react-dom'));
9
10
 
10
11
  function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
11
12
 
12
- function toSia(data, image, type) {
13
+ function toSia(data, image, type, imgOffset) {
13
14
  switch (type) {
14
15
  case 'bBox':
15
16
  var w = image.width * data.w;
16
17
  var h = image.height * data.h;
17
- var x0 = image.width * data.x - w / 2.0;
18
- var y0 = image.height * data.y - h / 2.0;
18
+ var x0 = imgOffset.x + image.width * data.x - w / 2.0;
19
+ var y0 = imgOffset.y + image.height * data.y - h / 2.0;
19
20
  return [{
20
21
  x: x0,
21
22
  y: y0
@@ -31,15 +32,15 @@ function toSia(data, image, type) {
31
32
  }];
32
33
  case 'point':
33
34
  return [{
34
- x: image.width * data.x,
35
- y: image.height * data.y
35
+ x: imgOffset.x + image.width * data.x,
36
+ y: imgOffset.y + image.height * data.y
36
37
  }];
37
38
  case 'line':
38
39
  case 'polygon':
39
40
  return data.map(function (e) {
40
41
  return {
41
- x: image.width * e.x,
42
- y: image.height * e.y
42
+ x: imgOffset.x + image.width * e.x,
43
+ y: imgOffset.y + image.height * e.y
43
44
  };
44
45
  });
45
46
  default:
@@ -51,17 +52,21 @@ function toSia(data, image, type) {
51
52
  * Transform a sia annotation to backend format.
52
53
  *
53
54
  * @param {Array} data Annotation data
54
- * @param {*} image Image object {width, height}
55
+ * @param {*} svg Image object {width, height}
55
56
  * @param {String} type Type of the annotation bBox, point, line, polygon
56
57
  * @returns Annotation data in backend style (relative, centered)
57
58
  */
58
- function toBackend(data, image, type) {
59
+ function toBackend(data, svg, type) {
60
+ var imgOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { x: 0, y: 0 };
61
+
62
+ var imgWidth = svg.width - 2 * imgOffset.x;
63
+ var imgHeight = svg.height - 2 * imgOffset.y;
59
64
  switch (type) {
60
65
  case 'bBox':
61
- // const w = image.width * data.w
62
- // const h = image.height * data.h
63
- // const x0 = image.width * data.x - w/2.0
64
- // const y0 = image.height * data.y - h/2.0
66
+ // const w = svg.width * data.w
67
+ // const h = svg.height * data.h
68
+ // const x0 = svg.width * data.x - w/2.0
69
+ // const y0 = svg.height * data.y - h/2.0
65
70
 
66
71
  // console.error('GO On Here! w = max_x - min_x; h = max_y - min_y')
67
72
  var xList = data.map(function (e) {
@@ -70,30 +75,30 @@ function toBackend(data, image, type) {
70
75
  var yList = data.map(function (e) {
71
76
  return e.y;
72
77
  });
73
- var minX = Math.min.apply(Math, _toConsumableArray(xList));
74
- var maxX = Math.max.apply(Math, _toConsumableArray(xList));
75
- var minY = Math.min.apply(Math, _toConsumableArray(yList));
76
- var maxY = Math.max.apply(Math, _toConsumableArray(yList));
78
+ var minX = Math.min.apply(Math, _toConsumableArray(xList)) - imgOffset.x;
79
+ var maxX = Math.max.apply(Math, _toConsumableArray(xList)) - imgOffset.x;
80
+ var minY = Math.min.apply(Math, _toConsumableArray(yList)) - imgOffset.y;
81
+ var maxY = Math.max.apply(Math, _toConsumableArray(yList)) - imgOffset.y;
77
82
  var w = maxX - minX;
78
83
  var h = maxY - minY;
79
84
  var x = minX + w / 2.0;
80
85
  var y = minY + h / 2.0;
81
86
  return {
82
- x: x / image.width,
83
- y: y / image.height,
84
- w: w / image.width,
85
- h: h / image.height };
87
+ x: x / imgWidth,
88
+ y: y / imgHeight,
89
+ w: w / imgWidth,
90
+ h: h / imgHeight };
86
91
  case 'point':
87
92
  return {
88
- x: data[0].x / image.width,
89
- y: data[0].y / image.height
93
+ x: (data[0].x - imgOffset.x) / imgWidth,
94
+ y: (data[0].y - imgOffset.y) / imgHeight
90
95
  };
91
96
  case 'line':
92
97
  case 'polygon':
93
98
  return data.map(function (e) {
94
99
  return {
95
- x: e.x / image.width,
96
- y: e.y / image.height
100
+ x: (e.x - imgOffset.x) / imgWidth,
101
+ y: (e.y - imgOffset.y) / imgHeight
97
102
  };
98
103
  });
99
104
  default:
@@ -195,20 +200,23 @@ function getTopPoint(data) {
195
200
  * correct the annotation
196
201
  * @param {object} data
197
202
  * @param {object} image
203
+ * @param {object} imageOffset
198
204
  */
199
- function correctAnnotation(data, image) {
205
+ function correctAnnotation(data, image, imageOffset) {
206
+ var imgWidth = image.width - 2 * imageOffset.x;
207
+ var imgHeight = image.height - 2 * imageOffset.y;
200
208
  var corrected = data.map(function (el) {
201
209
  var x = el.x;
202
210
  var y = el.y;
203
- if (el.x <= 0) {
204
- x = 0;
205
- } else if (el.x > image.width) {
206
- x = image.width;
211
+ if (el.x <= imageOffset.x) {
212
+ x = imageOffset.x;
213
+ } else if (el.x > imgWidth + imageOffset.x) {
214
+ x = imgWidth + imageOffset.x;
207
215
  }
208
- if (el.y < 0) {
209
- y = 0;
210
- } else if (el.y > image.height) {
211
- y = image.height;
216
+ if (el.y < imageOffset.y) {
217
+ y = imageOffset.y;
218
+ } else if (el.y > imgHeight + imageOffset.y) {
219
+ y = imgHeight + imageOffset.y;
212
220
  }
213
221
  return { x: x, y: y };
214
222
  });
@@ -520,7 +528,7 @@ function styleInject(css, ref) {
520
528
  }
521
529
  }
522
530
 
523
- var css = ".Annotation_sel-area-off__3caGM {\n fill: none; }\n\n.Annotation_sel-area-on__fPaTl {\n fill: blue;\n fill-opacity: 0.001; }\n\n.Annotation_selected__36wA1 {\n fill-opacity: 0.01;\n cursor: grab; }\n\ncircle.Annotation_selected__36wA1 {\n fill-opacity: 1.0; }\n\n.Annotation_not-selected__1QCgV {\n fill-opacity: 0.3; }\n\ncircle.Annotation_not-selected__1QCgV {\n fill-opacity: 1.0; }\n\n.Annotation_node-halo-on__1ala6 {\n fill: orange;\n stroke: orange;\n fill-opacity: 0.5;\n stroke-opacity: 0.5;\n cursor: grab; }\n\n.Annotation_node-halo-off__1tASR {\n fill: none;\n stroke: none; }\n";
531
+ var css = ".Annotation_sel-area-off__3caGM {\n fill: none; }\n\n.Annotation_sel-area-on__fPaTl {\n fill: blue;\n fill-opacity: 0.001; }\n\n.Annotation_selected__36wA1 {\n fill-opacity: 0.01;\n cursor: grab; }\n\ncircle.Annotation_selected__36wA1 {\n fill-opacity: 1.0; }\n\n.Annotation_not-selected__1QCgV {\n fill-opacity: 0.3; }\n\ncircle.Annotation_not-selected__1QCgV {\n fill-opacity: 1.0; }\n\n.Annotation_node-halo-on__1ala6 {\n fill: orange;\n stroke: orange;\n fill-opacity: 0.1;\n stroke-opacity: 0.2;\n cursor: grab; }\n\n.Annotation_node-halo-off__1tASR {\n fill: none;\n stroke: none; }\n";
524
532
  styleInject(css);
525
533
 
526
534
  var CREATE_NODE = "crosshair";
@@ -873,6 +881,15 @@ var ANNO_LABEL_UPDATE = 'annoLabelUpdate';
873
881
  var ANNO_CREATED_NODE = 'annoCreatedNode';
874
882
  var ANNO_CREATED_FINAL_NODE = 'annoCreatedFinalNode';
875
883
  var ANNO_START_CREATING = 'annoStartCreating';
884
+ var ANNO_COMMENT_UPDATE = 'annoCommentUpdate';
885
+ var ANNO_MARK_EXAMPLE = 'annoMarkExample';
886
+
887
+ var CANVAS_SVG_UPDATE = 'canvasSvgUpdate';
888
+ var CANVAS_UI_CONFIG_UPDATE = 'canvasUiConfigUpdate';
889
+ var CANVAS_AUTO_SAVE = 'canvasAutoSave';
890
+ var CANVAS_LABEL_INPUT_CLOSE = 'canvasLabelInputClose';
891
+ var CANVAS_IMG_LOADED = 'canvasImgLoaded';
892
+ var CANVAS_IMGBAR_CLOSE = 'canvasImgbarClose';
876
893
 
877
894
  //Image actions
878
895
  var IMG_LABEL_UPDATE = 'imgLabelUpdate';
@@ -2264,6 +2281,15 @@ var Annotation$1 = function (_Component) {
2264
2281
  }
2265
2282
  }
2266
2283
  }
2284
+ if (this.props.showSingleAnno === undefined) {
2285
+ if (this.state.anno.visible !== undefined) {
2286
+ if (this.state.anno.visible) {
2287
+ this.setVisible(true);
2288
+ } else {
2289
+ this.setVisible(false);
2290
+ }
2291
+ }
2292
+ }
2267
2293
  }
2268
2294
 
2269
2295
  /*************
@@ -2341,7 +2367,7 @@ var Annotation$1 = function (_Component) {
2341
2367
  case ANNO_MOVED:
2342
2368
  case ANNO_CREATED:
2343
2369
  // Check if annoation is within image bounds
2344
- var corrected = correctAnnotation(anno.data, this.props.svg);
2370
+ var corrected = correctAnnotation(anno.data, this.props.svg, this.props.imageOffset);
2345
2371
  var newAnno = _extends$5({}, anno, { data: corrected });
2346
2372
  var area = getArea(corrected, this.props.svg, anno.type, this.props.image);
2347
2373
  if (area !== undefined) {
@@ -3158,14 +3184,27 @@ var ImgBar = function (_Component) {
3158
3184
  return null;
3159
3185
  }
3160
3186
  }
3187
+ }, {
3188
+ key: 'renderImgDescription',
3189
+ value: function renderImgDescription() {
3190
+ if (this.props.imageMeta.description) {
3191
+ return React__default.createElement(
3192
+ semanticUiReact.Menu.Item,
3193
+ null,
3194
+ this.props.imageMeta.description
3195
+ );
3196
+ } else {
3197
+ return null;
3198
+ }
3199
+ }
3161
3200
  }, {
3162
3201
  key: 'render',
3163
3202
  value: function render() {
3164
3203
  var _this3 = this;
3165
3204
 
3166
3205
  if (!this.props.visible) return null;
3167
- if (!this.props.annos.image) return null;
3168
- if (!this.props.annos.image.url) return null;
3206
+ if (!this.props.imageMeta) return null;
3207
+ // if (!this.props.annos.image.url) return null
3169
3208
  return React__default.createElement(
3170
3209
  'div',
3171
3210
  { style: {
@@ -3182,15 +3221,16 @@ var ImgBar = function (_Component) {
3182
3221
  React__default.createElement(
3183
3222
  semanticUiReact.Menu,
3184
3223
  { inverted: true, style: { opacity: 0.9, justifyContent: 'center', alignItems: 'center' } },
3224
+ this.renderImgDescription(),
3185
3225
  React__default.createElement(
3186
3226
  semanticUiReact.Menu.Item,
3187
3227
  null,
3188
- this.props.annos.image.url.split('/').pop() + " (ID: " + this.props.annos.image.id + ")"
3228
+ "ID: " + this.props.imageMeta.id
3189
3229
  ),
3190
3230
  React__default.createElement(
3191
3231
  semanticUiReact.Menu.Item,
3192
3232
  null,
3193
- this.props.annos.image.number + " / " + this.props.annos.image.amount
3233
+ this.props.imageMeta.number + " / " + this.props.imageMeta.amount
3194
3234
  ),
3195
3235
  this.renderImgLabels()
3196
3236
  )
@@ -3251,7 +3291,7 @@ var Prompt = function (_Component) {
3251
3291
  semanticUiReact.Dimmer,
3252
3292
  { page: true,
3253
3293
  active: this.state.active,
3254
- style: { zIndex: 2000 },
3294
+ style: { zIndex: 7000 },
3255
3295
  onClick: function onClick(e) {
3256
3296
  return _this2.handleClick(e);
3257
3297
  }
@@ -3437,7 +3477,7 @@ function fixBackendAnnos(backendAnnos) {
3437
3477
  return annos;
3438
3478
  }
3439
3479
 
3440
- function backendAnnosToCanvas(backendAnnos, imgSize) {
3480
+ function backendAnnosToCanvas(backendAnnos, imgSize, imgOffset) {
3441
3481
  var annos = [].concat(_toConsumableArray$3(backendAnnos.bBoxes.map(function (element) {
3442
3482
  return _extends$8({}, element, { type: 'bBox',
3443
3483
  mode: element.mode ? element.mode : VIEW,
@@ -3458,7 +3498,7 @@ function backendAnnosToCanvas(backendAnnos, imgSize) {
3458
3498
  })));
3459
3499
  annos = annos.map(function (el) {
3460
3500
  return _extends$8({}, el, {
3461
- data: toSia(el.data, imgSize, el.type) });
3501
+ data: toSia(el.data, imgSize, el.type, imgOffset) });
3462
3502
  });
3463
3503
  // this.setState({annos: [...annos]})
3464
3504
  return annos;
@@ -3466,6 +3506,7 @@ function backendAnnosToCanvas(backendAnnos, imgSize) {
3466
3506
 
3467
3507
  function canvasToBackendAnnos(annos, imgSize) {
3468
3508
  var forBackendPost = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3509
+ var imgOffset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : { x: 0, y: 0 };
3469
3510
 
3470
3511
  var myAnnos = annos;
3471
3512
  var bAnnos = myAnnos.map(function (el) {
@@ -3481,7 +3522,7 @@ function canvasToBackendAnnos(annos, imgSize) {
3481
3522
  return _extends$8({}, el, {
3482
3523
  id: annoId,
3483
3524
  mode: VIEW,
3484
- data: toBackend(el.data, imgSize, el.type)
3525
+ data: toBackend(el.data, imgSize, el.type, imgOffset)
3485
3526
  });
3486
3527
  });
3487
3528
 
@@ -3521,6 +3562,8 @@ var CAM_MOVE_STOP = 'camMoveStop';
3521
3562
  var COPY_ANNOTATION = 'copyAnnotation';
3522
3563
  var PASTE_ANNOTATION = 'pasteAnnotation';
3523
3564
  var RECREATE_ANNO = 'recreateAnnotation';
3565
+ var DELETE_ANNO_IN_CREATION = 'deleteAnnoInCreation';
3566
+ var TOGGLE_ANNO_COMMENT_INPUT = 'toggleAnnoCommentInput';
3524
3567
 
3525
3568
  var KeyMapper = function () {
3526
3569
  function KeyMapper() {
@@ -3580,6 +3623,8 @@ var KeyMapper = function () {
3580
3623
  case 'c':
3581
3624
  if (this.controlDown) {
3582
3625
  this.triggerKeyAction(COPY_ANNOTATION);
3626
+ } else {
3627
+ this.triggerKeyAction(TOGGLE_ANNO_COMMENT_INPUT);
3583
3628
  }
3584
3629
  break;
3585
3630
  case 'v':
@@ -3587,6 +3632,9 @@ var KeyMapper = function () {
3587
3632
  this.triggerKeyAction(PASTE_ANNOTATION);
3588
3633
  }
3589
3634
  break;
3635
+ case 'Escape':
3636
+ this.triggerKeyAction(DELETE_ANNO_IN_CREATION);
3637
+ break;
3590
3638
  default:
3591
3639
  break;
3592
3640
  }
@@ -3740,21 +3788,2975 @@ function getZoomTranslation(w0, svg, s1) {
3740
3788
  return translation;
3741
3789
  }
3742
3790
 
3743
- var css$1 = ".SIA_sia-fullscreen__1P3FS {\n position: fixed;\n top: 0;\n left: 0;\n z-index: 9999;\n width: 100%;\n height: 100%;\n background-color: #FFFF; }\n";
3791
+ var css$1 = ".SIA_sia-fullscreen__1P3FS {\n position: fixed;\n top: 0;\n left: 0;\n z-index: 6000;\n width: 100%;\n height: 100%;\n background-color: #FFFF; }\n";
3744
3792
  styleInject(css$1);
3745
3793
 
3794
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3795
+
3796
+ function createCommonjsModule(fn, module) {
3797
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
3798
+ }
3799
+
3800
+ var reactDraggable = createCommonjsModule(function (module, exports) {
3801
+ (function (global, factory) {
3802
+ module.exports = factory(reactDom, React__default);
3803
+ })(commonjsGlobal, function (ReactDOM, React$$1) {
3804
+
3805
+ ReactDOM = ReactDOM && ReactDOM.hasOwnProperty('default') ? ReactDOM['default'] : ReactDOM;
3806
+ React$$1 = React$$1 && React$$1.hasOwnProperty('default') ? React$$1['default'] : React$$1;
3807
+
3808
+ function createCommonjsModule$$1(fn, module) {
3809
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
3810
+ }
3811
+
3812
+ /**
3813
+ * Copyright (c) 2013-present, Facebook, Inc.
3814
+ *
3815
+ * This source code is licensed under the MIT license found in the
3816
+ * LICENSE file in the root directory of this source tree.
3817
+ *
3818
+ *
3819
+ */
3820
+
3821
+ function makeEmptyFunction(arg) {
3822
+ return function () {
3823
+ return arg;
3824
+ };
3825
+ }
3826
+
3827
+ /**
3828
+ * This function accepts and discards inputs; it has no side effects. This is
3829
+ * primarily useful idiomatically for overridable function endpoints which
3830
+ * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
3831
+ */
3832
+ var emptyFunction = function emptyFunction() {};
3833
+
3834
+ emptyFunction.thatReturns = makeEmptyFunction;
3835
+ emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
3836
+ emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
3837
+ emptyFunction.thatReturnsNull = makeEmptyFunction(null);
3838
+ emptyFunction.thatReturnsThis = function () {
3839
+ return this;
3840
+ };
3841
+ emptyFunction.thatReturnsArgument = function (arg) {
3842
+ return arg;
3843
+ };
3844
+
3845
+ var emptyFunction_1 = emptyFunction;
3846
+
3847
+ /**
3848
+ * Copyright (c) 2013-present, Facebook, Inc.
3849
+ *
3850
+ * This source code is licensed under the MIT license found in the
3851
+ * LICENSE file in the root directory of this source tree.
3852
+ *
3853
+ */
3854
+
3855
+ /**
3856
+ * Use invariant() to assert state which your program assumes to be true.
3857
+ *
3858
+ * Provide sprintf-style format (only %s is supported) and arguments
3859
+ * to provide information about what broke and what you were
3860
+ * expecting.
3861
+ *
3862
+ * The invariant message will be stripped in production, but the invariant
3863
+ * will remain to ensure logic does not differ in production.
3864
+ */
3865
+
3866
+ var validateFormat = function validateFormat(format) {};
3867
+
3868
+ {
3869
+ validateFormat = function validateFormat(format) {
3870
+ if (format === undefined) {
3871
+ throw new Error('invariant requires an error message argument');
3872
+ }
3873
+ };
3874
+ }
3875
+
3876
+ function invariant(condition, format, a, b, c, d, e, f) {
3877
+ validateFormat(format);
3878
+
3879
+ if (!condition) {
3880
+ var error;
3881
+ if (format === undefined) {
3882
+ error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
3883
+ } else {
3884
+ var args = [a, b, c, d, e, f];
3885
+ var argIndex = 0;
3886
+ error = new Error(format.replace(/%s/g, function () {
3887
+ return args[argIndex++];
3888
+ }));
3889
+ error.name = 'Invariant Violation';
3890
+ }
3891
+
3892
+ error.framesToPop = 1; // we don't care about invariant's own frame
3893
+ throw error;
3894
+ }
3895
+ }
3896
+
3897
+ var invariant_1 = invariant;
3898
+
3899
+ /**
3900
+ * Similar to invariant but only logs a warning if the condition is not met.
3901
+ * This can be used to log issues in development environments in critical
3902
+ * paths. Removing the logging code for production environments will keep the
3903
+ * same logic and follow the same code paths.
3904
+ */
3905
+
3906
+ var warning = emptyFunction_1;
3907
+
3908
+ {
3909
+ var printWarning = function printWarning(format) {
3910
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3911
+ args[_key - 1] = arguments[_key];
3912
+ }
3913
+
3914
+ var argIndex = 0;
3915
+ var message = 'Warning: ' + format.replace(/%s/g, function () {
3916
+ return args[argIndex++];
3917
+ });
3918
+ if (typeof console !== 'undefined') {
3919
+ console.error(message);
3920
+ }
3921
+ try {
3922
+ // --- Welcome to debugging React ---
3923
+ // This error was thrown as a convenience so that you can use this stack
3924
+ // to find the callsite that caused this warning to fire.
3925
+ throw new Error(message);
3926
+ } catch (x) {}
3927
+ };
3928
+
3929
+ warning = function warning(condition, format) {
3930
+ if (format === undefined) {
3931
+ throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
3932
+ }
3933
+
3934
+ if (format.indexOf('Failed Composite propType: ') === 0) {
3935
+ return; // Ignore CompositeComponent proptype check.
3936
+ }
3937
+
3938
+ if (!condition) {
3939
+ for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
3940
+ args[_key2 - 2] = arguments[_key2];
3941
+ }
3942
+
3943
+ printWarning.apply(undefined, [format].concat(args));
3944
+ }
3945
+ };
3946
+ }
3947
+
3948
+ var warning_1 = warning;
3949
+
3950
+ /*
3951
+ object-assign
3952
+ (c) Sindre Sorhus
3953
+ @license MIT
3954
+ */
3955
+ /* eslint-disable no-unused-vars */
3956
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
3957
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
3958
+ var propIsEnumerable = Object.prototype.propertyIsEnumerable;
3959
+
3960
+ function toObject(val) {
3961
+ if (val === null || val === undefined) {
3962
+ throw new TypeError('Object.assign cannot be called with null or undefined');
3963
+ }
3964
+
3965
+ return Object(val);
3966
+ }
3967
+
3968
+ function shouldUseNative() {
3969
+ try {
3970
+ if (!Object.assign) {
3971
+ return false;
3972
+ }
3973
+
3974
+ // Detect buggy property enumeration order in older V8 versions.
3975
+
3976
+ // https://bugs.chromium.org/p/v8/issues/detail?id=4118
3977
+ var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
3978
+ test1[5] = 'de';
3979
+ if (Object.getOwnPropertyNames(test1)[0] === '5') {
3980
+ return false;
3981
+ }
3982
+
3983
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
3984
+ var test2 = {};
3985
+ for (var i = 0; i < 10; i++) {
3986
+ test2['_' + String.fromCharCode(i)] = i;
3987
+ }
3988
+ var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
3989
+ return test2[n];
3990
+ });
3991
+ if (order2.join('') !== '0123456789') {
3992
+ return false;
3993
+ }
3994
+
3995
+ // https://bugs.chromium.org/p/v8/issues/detail?id=3056
3996
+ var test3 = {};
3997
+ 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
3998
+ test3[letter] = letter;
3999
+ });
4000
+ if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
4001
+ return false;
4002
+ }
4003
+
4004
+ return true;
4005
+ } catch (err) {
4006
+ // We don't expect any of the above to throw, but better to be safe.
4007
+ return false;
4008
+ }
4009
+ }
4010
+
4011
+ var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
4012
+ var from;
4013
+ var to = toObject(target);
4014
+ var symbols;
4015
+
4016
+ for (var s = 1; s < arguments.length; s++) {
4017
+ from = Object(arguments[s]);
4018
+
4019
+ for (var key in from) {
4020
+ if (hasOwnProperty.call(from, key)) {
4021
+ to[key] = from[key];
4022
+ }
4023
+ }
4024
+
4025
+ if (getOwnPropertySymbols) {
4026
+ symbols = getOwnPropertySymbols(from);
4027
+ for (var i = 0; i < symbols.length; i++) {
4028
+ if (propIsEnumerable.call(from, symbols[i])) {
4029
+ to[symbols[i]] = from[symbols[i]];
4030
+ }
4031
+ }
4032
+ }
4033
+ }
4034
+
4035
+ return to;
4036
+ };
4037
+
4038
+ /**
4039
+ * Copyright (c) 2013-present, Facebook, Inc.
4040
+ *
4041
+ * This source code is licensed under the MIT license found in the
4042
+ * LICENSE file in the root directory of this source tree.
4043
+ */
4044
+
4045
+ var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
4046
+
4047
+ var ReactPropTypesSecret_1 = ReactPropTypesSecret;
4048
+
4049
+ {
4050
+ var invariant$1 = invariant_1;
4051
+ var warning$1 = warning_1;
4052
+ var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
4053
+ var loggedTypeFailures = {};
4054
+ }
4055
+
4056
+ /**
4057
+ * Assert that the values match with the type specs.
4058
+ * Error messages are memorized and will only be shown once.
4059
+ *
4060
+ * @param {object} typeSpecs Map of name to a ReactPropType
4061
+ * @param {object} values Runtime values that need to be type-checked
4062
+ * @param {string} location e.g. "prop", "context", "child context"
4063
+ * @param {string} componentName Name of the component for error messages.
4064
+ * @param {?Function} getStack Returns the component stack.
4065
+ * @private
4066
+ */
4067
+ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
4068
+ {
4069
+ for (var typeSpecName in typeSpecs) {
4070
+ if (typeSpecs.hasOwnProperty(typeSpecName)) {
4071
+ var error;
4072
+ // Prop type validation may throw. In case they do, we don't want to
4073
+ // fail the render phase where it didn't fail before. So we log it.
4074
+ // After these have been cleaned up, we'll let them throw.
4075
+ try {
4076
+ // This is intentionally an invariant that gets caught. It's the same
4077
+ // behavior as without this statement except with a better message.
4078
+ invariant$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]);
4079
+ error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
4080
+ } catch (ex) {
4081
+ error = ex;
4082
+ }
4083
+ warning$1(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
4084
+ if (error instanceof Error && !(error.message in loggedTypeFailures)) {
4085
+ // Only monitor this failure once because there tends to be a lot of the
4086
+ // same error.
4087
+ loggedTypeFailures[error.message] = true;
4088
+
4089
+ var stack = getStack ? getStack() : '';
4090
+
4091
+ warning$1(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
4092
+ }
4093
+ }
4094
+ }
4095
+ }
4096
+ }
4097
+
4098
+ var checkPropTypes_1 = checkPropTypes;
4099
+
4100
+ var factoryWithTypeCheckers = function (isValidElement, throwOnDirectAccess) {
4101
+ /* global Symbol */
4102
+ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
4103
+ var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
4104
+
4105
+ /**
4106
+ * Returns the iterator method function contained on the iterable object.
4107
+ *
4108
+ * Be sure to invoke the function with the iterable as context:
4109
+ *
4110
+ * var iteratorFn = getIteratorFn(myIterable);
4111
+ * if (iteratorFn) {
4112
+ * var iterator = iteratorFn.call(myIterable);
4113
+ * ...
4114
+ * }
4115
+ *
4116
+ * @param {?object} maybeIterable
4117
+ * @return {?function}
4118
+ */
4119
+ function getIteratorFn(maybeIterable) {
4120
+ var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
4121
+ if (typeof iteratorFn === 'function') {
4122
+ return iteratorFn;
4123
+ }
4124
+ }
4125
+
4126
+ /**
4127
+ * Collection of methods that allow declaration and validation of props that are
4128
+ * supplied to React components. Example usage:
4129
+ *
4130
+ * var Props = require('ReactPropTypes');
4131
+ * var MyArticle = React.createClass({
4132
+ * propTypes: {
4133
+ * // An optional string prop named "description".
4134
+ * description: Props.string,
4135
+ *
4136
+ * // A required enum prop named "category".
4137
+ * category: Props.oneOf(['News','Photos']).isRequired,
4138
+ *
4139
+ * // A prop named "dialog" that requires an instance of Dialog.
4140
+ * dialog: Props.instanceOf(Dialog).isRequired
4141
+ * },
4142
+ * render: function() { ... }
4143
+ * });
4144
+ *
4145
+ * A more formal specification of how these methods are used:
4146
+ *
4147
+ * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
4148
+ * decl := ReactPropTypes.{type}(.isRequired)?
4149
+ *
4150
+ * Each and every declaration produces a function with the same signature. This
4151
+ * allows the creation of custom validation functions. For example:
4152
+ *
4153
+ * var MyLink = React.createClass({
4154
+ * propTypes: {
4155
+ * // An optional string or URI prop named "href".
4156
+ * href: function(props, propName, componentName) {
4157
+ * var propValue = props[propName];
4158
+ * if (propValue != null && typeof propValue !== 'string' &&
4159
+ * !(propValue instanceof URI)) {
4160
+ * return new Error(
4161
+ * 'Expected a string or an URI for ' + propName + ' in ' +
4162
+ * componentName
4163
+ * );
4164
+ * }
4165
+ * }
4166
+ * },
4167
+ * render: function() {...}
4168
+ * });
4169
+ *
4170
+ * @internal
4171
+ */
4172
+
4173
+ var ANONYMOUS = '<<anonymous>>';
4174
+
4175
+ // Important!
4176
+ // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
4177
+ var ReactPropTypes = {
4178
+ array: createPrimitiveTypeChecker('array'),
4179
+ bool: createPrimitiveTypeChecker('boolean'),
4180
+ func: createPrimitiveTypeChecker('function'),
4181
+ number: createPrimitiveTypeChecker('number'),
4182
+ object: createPrimitiveTypeChecker('object'),
4183
+ string: createPrimitiveTypeChecker('string'),
4184
+ symbol: createPrimitiveTypeChecker('symbol'),
4185
+
4186
+ any: createAnyTypeChecker(),
4187
+ arrayOf: createArrayOfTypeChecker,
4188
+ element: createElementTypeChecker(),
4189
+ instanceOf: createInstanceTypeChecker,
4190
+ node: createNodeChecker(),
4191
+ objectOf: createObjectOfTypeChecker,
4192
+ oneOf: createEnumTypeChecker,
4193
+ oneOfType: createUnionTypeChecker,
4194
+ shape: createShapeTypeChecker,
4195
+ exact: createStrictShapeTypeChecker
4196
+ };
4197
+
4198
+ /**
4199
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
4200
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
4201
+ */
4202
+ /*eslint-disable no-self-compare*/
4203
+ function is(x, y) {
4204
+ // SameValue algorithm
4205
+ if (x === y) {
4206
+ // Steps 1-5, 7-10
4207
+ // Steps 6.b-6.e: +0 != -0
4208
+ return x !== 0 || 1 / x === 1 / y;
4209
+ } else {
4210
+ // Step 6.a: NaN == NaN
4211
+ return x !== x && y !== y;
4212
+ }
4213
+ }
4214
+ /*eslint-enable no-self-compare*/
4215
+
4216
+ /**
4217
+ * We use an Error-like object for backward compatibility as people may call
4218
+ * PropTypes directly and inspect their output. However, we don't use real
4219
+ * Errors anymore. We don't inspect their stack anyway, and creating them
4220
+ * is prohibitively expensive if they are created too often, such as what
4221
+ * happens in oneOfType() for any type before the one that matched.
4222
+ */
4223
+ function PropTypeError(message) {
4224
+ this.message = message;
4225
+ this.stack = '';
4226
+ }
4227
+ // Make `instanceof Error` still work for returned errors.
4228
+ PropTypeError.prototype = Error.prototype;
4229
+
4230
+ function createChainableTypeChecker(validate) {
4231
+ {
4232
+ var manualPropTypeCallCache = {};
4233
+ var manualPropTypeWarningCount = 0;
4234
+ }
4235
+ function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
4236
+ componentName = componentName || ANONYMOUS;
4237
+ propFullName = propFullName || propName;
4238
+
4239
+ if (secret !== ReactPropTypesSecret_1) {
4240
+ if (throwOnDirectAccess) {
4241
+ // New behavior only for users of `prop-types` package
4242
+ invariant_1(false, 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use `PropTypes.checkPropTypes()` to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
4243
+ } else if (typeof console !== 'undefined') {
4244
+ // Old behavior for people using React.PropTypes
4245
+ var cacheKey = componentName + ':' + propName;
4246
+ if (!manualPropTypeCallCache[cacheKey] &&
4247
+ // Avoid spamming the console because they are often not actionable except for lib authors
4248
+ manualPropTypeWarningCount < 3) {
4249
+ warning_1(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will throw in the standalone `prop-types` package. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName);
4250
+ manualPropTypeCallCache[cacheKey] = true;
4251
+ manualPropTypeWarningCount++;
4252
+ }
4253
+ }
4254
+ }
4255
+ if (props[propName] == null) {
4256
+ if (isRequired) {
4257
+ if (props[propName] === null) {
4258
+ return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
4259
+ }
4260
+ return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
4261
+ }
4262
+ return null;
4263
+ } else {
4264
+ return validate(props, propName, componentName, location, propFullName);
4265
+ }
4266
+ }
4267
+
4268
+ var chainedCheckType = checkType.bind(null, false);
4269
+ chainedCheckType.isRequired = checkType.bind(null, true);
4270
+
4271
+ return chainedCheckType;
4272
+ }
4273
+
4274
+ function createPrimitiveTypeChecker(expectedType) {
4275
+ function validate(props, propName, componentName, location, propFullName, secret) {
4276
+ var propValue = props[propName];
4277
+ var propType = getPropType(propValue);
4278
+ if (propType !== expectedType) {
4279
+ // `propValue` being instance of, say, date/regexp, pass the 'object'
4280
+ // check, but we can offer a more precise error message here rather than
4281
+ // 'of type `object`'.
4282
+ var preciseType = getPreciseType(propValue);
4283
+
4284
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
4285
+ }
4286
+ return null;
4287
+ }
4288
+ return createChainableTypeChecker(validate);
4289
+ }
4290
+
4291
+ function createAnyTypeChecker() {
4292
+ return createChainableTypeChecker(emptyFunction_1.thatReturnsNull);
4293
+ }
4294
+
4295
+ function createArrayOfTypeChecker(typeChecker) {
4296
+ function validate(props, propName, componentName, location, propFullName) {
4297
+ if (typeof typeChecker !== 'function') {
4298
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
4299
+ }
4300
+ var propValue = props[propName];
4301
+ if (!Array.isArray(propValue)) {
4302
+ var propType = getPropType(propValue);
4303
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
4304
+ }
4305
+ for (var i = 0; i < propValue.length; i++) {
4306
+ var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
4307
+ if (error instanceof Error) {
4308
+ return error;
4309
+ }
4310
+ }
4311
+ return null;
4312
+ }
4313
+ return createChainableTypeChecker(validate);
4314
+ }
4315
+
4316
+ function createElementTypeChecker() {
4317
+ function validate(props, propName, componentName, location, propFullName) {
4318
+ var propValue = props[propName];
4319
+ if (!isValidElement(propValue)) {
4320
+ var propType = getPropType(propValue);
4321
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
4322
+ }
4323
+ return null;
4324
+ }
4325
+ return createChainableTypeChecker(validate);
4326
+ }
4327
+
4328
+ function createInstanceTypeChecker(expectedClass) {
4329
+ function validate(props, propName, componentName, location, propFullName) {
4330
+ if (!(props[propName] instanceof expectedClass)) {
4331
+ var expectedClassName = expectedClass.name || ANONYMOUS;
4332
+ var actualClassName = getClassName(props[propName]);
4333
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
4334
+ }
4335
+ return null;
4336
+ }
4337
+ return createChainableTypeChecker(validate);
4338
+ }
4339
+
4340
+ function createEnumTypeChecker(expectedValues) {
4341
+ if (!Array.isArray(expectedValues)) {
4342
+ warning_1(false, 'Invalid argument supplied to oneOf, expected an instance of array.');
4343
+ return emptyFunction_1.thatReturnsNull;
4344
+ }
4345
+
4346
+ function validate(props, propName, componentName, location, propFullName) {
4347
+ var propValue = props[propName];
4348
+ for (var i = 0; i < expectedValues.length; i++) {
4349
+ if (is(propValue, expectedValues[i])) {
4350
+ return null;
4351
+ }
4352
+ }
4353
+
4354
+ var valuesString = JSON.stringify(expectedValues);
4355
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
4356
+ }
4357
+ return createChainableTypeChecker(validate);
4358
+ }
4359
+
4360
+ function createObjectOfTypeChecker(typeChecker) {
4361
+ function validate(props, propName, componentName, location, propFullName) {
4362
+ if (typeof typeChecker !== 'function') {
4363
+ return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
4364
+ }
4365
+ var propValue = props[propName];
4366
+ var propType = getPropType(propValue);
4367
+ if (propType !== 'object') {
4368
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
4369
+ }
4370
+ for (var key in propValue) {
4371
+ if (propValue.hasOwnProperty(key)) {
4372
+ var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
4373
+ if (error instanceof Error) {
4374
+ return error;
4375
+ }
4376
+ }
4377
+ }
4378
+ return null;
4379
+ }
4380
+ return createChainableTypeChecker(validate);
4381
+ }
4382
+
4383
+ function createUnionTypeChecker(arrayOfTypeCheckers) {
4384
+ if (!Array.isArray(arrayOfTypeCheckers)) {
4385
+ warning_1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.');
4386
+ return emptyFunction_1.thatReturnsNull;
4387
+ }
4388
+
4389
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
4390
+ var checker = arrayOfTypeCheckers[i];
4391
+ if (typeof checker !== 'function') {
4392
+ warning_1(false, 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 'received %s at index %s.', getPostfixForTypeWarning(checker), i);
4393
+ return emptyFunction_1.thatReturnsNull;
4394
+ }
4395
+ }
4396
+
4397
+ function validate(props, propName, componentName, location, propFullName) {
4398
+ for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
4399
+ var checker = arrayOfTypeCheckers[i];
4400
+ if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
4401
+ return null;
4402
+ }
4403
+ }
4404
+
4405
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
4406
+ }
4407
+ return createChainableTypeChecker(validate);
4408
+ }
4409
+
4410
+ function createNodeChecker() {
4411
+ function validate(props, propName, componentName, location, propFullName) {
4412
+ if (!isNode(props[propName])) {
4413
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
4414
+ }
4415
+ return null;
4416
+ }
4417
+ return createChainableTypeChecker(validate);
4418
+ }
4419
+
4420
+ function createShapeTypeChecker(shapeTypes) {
4421
+ function validate(props, propName, componentName, location, propFullName) {
4422
+ var propValue = props[propName];
4423
+ var propType = getPropType(propValue);
4424
+ if (propType !== 'object') {
4425
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
4426
+ }
4427
+ for (var key in shapeTypes) {
4428
+ var checker = shapeTypes[key];
4429
+ if (!checker) {
4430
+ continue;
4431
+ }
4432
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
4433
+ if (error) {
4434
+ return error;
4435
+ }
4436
+ }
4437
+ return null;
4438
+ }
4439
+ return createChainableTypeChecker(validate);
4440
+ }
4441
+
4442
+ function createStrictShapeTypeChecker(shapeTypes) {
4443
+ function validate(props, propName, componentName, location, propFullName) {
4444
+ var propValue = props[propName];
4445
+ var propType = getPropType(propValue);
4446
+ if (propType !== 'object') {
4447
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
4448
+ }
4449
+ // We need to check all keys in case some are required but missing from
4450
+ // props.
4451
+ var allKeys = objectAssign({}, props[propName], shapeTypes);
4452
+ for (var key in allKeys) {
4453
+ var checker = shapeTypes[key];
4454
+ if (!checker) {
4455
+ return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' '));
4456
+ }
4457
+ var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
4458
+ if (error) {
4459
+ return error;
4460
+ }
4461
+ }
4462
+ return null;
4463
+ }
4464
+
4465
+ return createChainableTypeChecker(validate);
4466
+ }
4467
+
4468
+ function isNode(propValue) {
4469
+ switch (typeof propValue) {
4470
+ case 'number':
4471
+ case 'string':
4472
+ case 'undefined':
4473
+ return true;
4474
+ case 'boolean':
4475
+ return !propValue;
4476
+ case 'object':
4477
+ if (Array.isArray(propValue)) {
4478
+ return propValue.every(isNode);
4479
+ }
4480
+ if (propValue === null || isValidElement(propValue)) {
4481
+ return true;
4482
+ }
4483
+
4484
+ var iteratorFn = getIteratorFn(propValue);
4485
+ if (iteratorFn) {
4486
+ var iterator = iteratorFn.call(propValue);
4487
+ var step;
4488
+ if (iteratorFn !== propValue.entries) {
4489
+ while (!(step = iterator.next()).done) {
4490
+ if (!isNode(step.value)) {
4491
+ return false;
4492
+ }
4493
+ }
4494
+ } else {
4495
+ // Iterator will provide entry [k,v] tuples rather than values.
4496
+ while (!(step = iterator.next()).done) {
4497
+ var entry = step.value;
4498
+ if (entry) {
4499
+ if (!isNode(entry[1])) {
4500
+ return false;
4501
+ }
4502
+ }
4503
+ }
4504
+ }
4505
+ } else {
4506
+ return false;
4507
+ }
4508
+
4509
+ return true;
4510
+ default:
4511
+ return false;
4512
+ }
4513
+ }
4514
+
4515
+ function isSymbol(propType, propValue) {
4516
+ // Native Symbol.
4517
+ if (propType === 'symbol') {
4518
+ return true;
4519
+ }
4520
+
4521
+ // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
4522
+ if (propValue['@@toStringTag'] === 'Symbol') {
4523
+ return true;
4524
+ }
4525
+
4526
+ // Fallback for non-spec compliant Symbols which are polyfilled.
4527
+ if (typeof Symbol === 'function' && propValue instanceof Symbol) {
4528
+ return true;
4529
+ }
4530
+
4531
+ return false;
4532
+ }
4533
+
4534
+ // Equivalent of `typeof` but with special handling for array and regexp.
4535
+ function getPropType(propValue) {
4536
+ var propType = typeof propValue;
4537
+ if (Array.isArray(propValue)) {
4538
+ return 'array';
4539
+ }
4540
+ if (propValue instanceof RegExp) {
4541
+ // Old webkits (at least until Android 4.0) return 'function' rather than
4542
+ // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
4543
+ // passes PropTypes.object.
4544
+ return 'object';
4545
+ }
4546
+ if (isSymbol(propType, propValue)) {
4547
+ return 'symbol';
4548
+ }
4549
+ return propType;
4550
+ }
4551
+
4552
+ // This handles more types than `getPropType`. Only used for error messages.
4553
+ // See `createPrimitiveTypeChecker`.
4554
+ function getPreciseType(propValue) {
4555
+ if (typeof propValue === 'undefined' || propValue === null) {
4556
+ return '' + propValue;
4557
+ }
4558
+ var propType = getPropType(propValue);
4559
+ if (propType === 'object') {
4560
+ if (propValue instanceof Date) {
4561
+ return 'date';
4562
+ } else if (propValue instanceof RegExp) {
4563
+ return 'regexp';
4564
+ }
4565
+ }
4566
+ return propType;
4567
+ }
4568
+
4569
+ // Returns a string that is postfixed to a warning about an invalid type.
4570
+ // For example, "undefined" or "of type array"
4571
+ function getPostfixForTypeWarning(value) {
4572
+ var type = getPreciseType(value);
4573
+ switch (type) {
4574
+ case 'array':
4575
+ case 'object':
4576
+ return 'an ' + type;
4577
+ case 'boolean':
4578
+ case 'date':
4579
+ case 'regexp':
4580
+ return 'a ' + type;
4581
+ default:
4582
+ return type;
4583
+ }
4584
+ }
4585
+
4586
+ // Returns class name of the object, if any.
4587
+ function getClassName(propValue) {
4588
+ if (!propValue.constructor || !propValue.constructor.name) {
4589
+ return ANONYMOUS;
4590
+ }
4591
+ return propValue.constructor.name;
4592
+ }
4593
+
4594
+ ReactPropTypes.checkPropTypes = checkPropTypes_1;
4595
+ ReactPropTypes.PropTypes = ReactPropTypes;
4596
+
4597
+ return ReactPropTypes;
4598
+ };
4599
+
4600
+ var propTypes = createCommonjsModule$$1(function (module) {
4601
+ /**
4602
+ * Copyright (c) 2013-present, Facebook, Inc.
4603
+ *
4604
+ * This source code is licensed under the MIT license found in the
4605
+ * LICENSE file in the root directory of this source tree.
4606
+ */
4607
+
4608
+ {
4609
+ var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element') || 0xeac7;
4610
+
4611
+ var isValidElement = function (object) {
4612
+ return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
4613
+ };
4614
+
4615
+ // By explicitly using `prop-types` you are opting into new development behavior.
4616
+ // http://fb.me/prop-types-in-prod
4617
+ var throwOnDirectAccess = true;
4618
+ module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess);
4619
+ }
4620
+ });
4621
+
4622
+ var classnames = createCommonjsModule$$1(function (module) {
4623
+ /*!
4624
+ Copyright (c) 2016 Jed Watson.
4625
+ Licensed under the MIT License (MIT), see
4626
+ http://jedwatson.github.io/classnames
4627
+ */
4628
+ /* global define */
4629
+
4630
+ (function () {
4631
+
4632
+ var hasOwn = {}.hasOwnProperty;
4633
+
4634
+ function classNames() {
4635
+ var classes = [];
4636
+
4637
+ for (var i = 0; i < arguments.length; i++) {
4638
+ var arg = arguments[i];
4639
+ if (!arg) continue;
4640
+
4641
+ var argType = typeof arg;
4642
+
4643
+ if (argType === 'string' || argType === 'number') {
4644
+ classes.push(arg);
4645
+ } else if (Array.isArray(arg)) {
4646
+ classes.push(classNames.apply(null, arg));
4647
+ } else if (argType === 'object') {
4648
+ for (var key in arg) {
4649
+ if (hasOwn.call(arg, key) && arg[key]) {
4650
+ classes.push(key);
4651
+ }
4652
+ }
4653
+ }
4654
+ }
4655
+
4656
+ return classes.join(' ');
4657
+ }
4658
+
4659
+ if (module.exports) {
4660
+ module.exports = classNames;
4661
+ } else {
4662
+ window.classNames = classNames;
4663
+ }
4664
+ })();
4665
+ });
4666
+
4667
+ // @credits https://gist.github.com/rogozhnikoff/a43cfed27c41e4e68cdc
4668
+ function findInArray(array /*: Array<any> | TouchList*/, callback /*: Function*/) /*: any*/{
4669
+ for (var i = 0, length = array.length; i < length; i++) {
4670
+ if (callback.apply(callback, [array[i], i, array])) return array[i];
4671
+ }
4672
+ }
4673
+
4674
+ function isFunction(func /*: any*/) /*: boolean*/{
4675
+ return typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]';
4676
+ }
4677
+
4678
+ function isNum(num /*: any*/) /*: boolean*/{
4679
+ return typeof num === 'number' && !isNaN(num);
4680
+ }
4681
+
4682
+ function int(a /*: string*/) /*: number*/{
4683
+ return parseInt(a, 10);
4684
+ }
4685
+
4686
+ function dontSetMe(props /*: Object*/, propName /*: string*/, componentName /*: string*/) {
4687
+ if (props[propName]) {
4688
+ return new Error('Invalid prop ' + propName + ' passed to ' + componentName + ' - do not set this, set it on the child.');
4689
+ }
4690
+ }
4691
+
4692
+ var prefixes = ['Moz', 'Webkit', 'O', 'ms'];
4693
+ function getPrefix() /*: string*/{
4694
+ var prop /*: string*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'transform';
4695
+
4696
+ // Checking specifically for 'window.document' is for pseudo-browser server-side
4697
+ // environments that define 'window' as the global context.
4698
+ // E.g. React-rails (see https://github.com/reactjs/react-rails/pull/84)
4699
+ if (typeof window === 'undefined' || typeof window.document === 'undefined') return '';
4700
+
4701
+ var style = window.document.documentElement.style;
4702
+
4703
+ if (prop in style) return '';
4704
+
4705
+ for (var i = 0; i < prefixes.length; i++) {
4706
+ if (browserPrefixToKey(prop, prefixes[i]) in style) return prefixes[i];
4707
+ }
4708
+
4709
+ return '';
4710
+ }
4711
+
4712
+ function browserPrefixToKey(prop /*: string*/, prefix /*: string*/) /*: string*/{
4713
+ return prefix ? '' + prefix + kebabToTitleCase(prop) : prop;
4714
+ }
4715
+
4716
+ function kebabToTitleCase(str /*: string*/) /*: string*/{
4717
+ var out = '';
4718
+ var shouldCapitalize = true;
4719
+ for (var i = 0; i < str.length; i++) {
4720
+ if (shouldCapitalize) {
4721
+ out += str[i].toUpperCase();
4722
+ shouldCapitalize = false;
4723
+ } else if (str[i] === '-') {
4724
+ shouldCapitalize = true;
4725
+ } else {
4726
+ out += str[i];
4727
+ }
4728
+ }
4729
+ return out;
4730
+ }
4731
+
4732
+ // Default export is the prefix itself, like 'Moz', 'Webkit', etc
4733
+ // Note that you may have to re-test for certain things; for instance, Chrome 50
4734
+ // can handle unprefixed `transform`, but not unprefixed `user-select`
4735
+ var browserPrefix = getPrefix();
4736
+
4737
+ var classCallCheck = function (instance, Constructor) {
4738
+ if (!(instance instanceof Constructor)) {
4739
+ throw new TypeError("Cannot call a class as a function");
4740
+ }
4741
+ };
4742
+
4743
+ var createClass = function () {
4744
+ function defineProperties(target, props) {
4745
+ for (var i = 0; i < props.length; i++) {
4746
+ var descriptor = props[i];
4747
+ descriptor.enumerable = descriptor.enumerable || false;
4748
+ descriptor.configurable = true;
4749
+ if ("value" in descriptor) descriptor.writable = true;
4750
+ Object.defineProperty(target, descriptor.key, descriptor);
4751
+ }
4752
+ }
4753
+
4754
+ return function (Constructor, protoProps, staticProps) {
4755
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
4756
+ if (staticProps) defineProperties(Constructor, staticProps);
4757
+ return Constructor;
4758
+ };
4759
+ }();
4760
+
4761
+ var defineProperty = function (obj, key, value) {
4762
+ if (key in obj) {
4763
+ Object.defineProperty(obj, key, {
4764
+ value: value,
4765
+ enumerable: true,
4766
+ configurable: true,
4767
+ writable: true
4768
+ });
4769
+ } else {
4770
+ obj[key] = value;
4771
+ }
4772
+
4773
+ return obj;
4774
+ };
4775
+
4776
+ var _extends = Object.assign || function (target) {
4777
+ for (var i = 1; i < arguments.length; i++) {
4778
+ var source = arguments[i];
4779
+
4780
+ for (var key in source) {
4781
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
4782
+ target[key] = source[key];
4783
+ }
4784
+ }
4785
+ }
4786
+
4787
+ return target;
4788
+ };
4789
+
4790
+ var inherits = function (subClass, superClass) {
4791
+ if (typeof superClass !== "function" && superClass !== null) {
4792
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
4793
+ }
4794
+
4795
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
4796
+ constructor: {
4797
+ value: subClass,
4798
+ enumerable: false,
4799
+ writable: true,
4800
+ configurable: true
4801
+ }
4802
+ });
4803
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
4804
+ };
4805
+
4806
+ var possibleConstructorReturn = function (self, call) {
4807
+ if (!self) {
4808
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4809
+ }
4810
+
4811
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
4812
+ };
4813
+
4814
+ var slicedToArray = function () {
4815
+ function sliceIterator(arr, i) {
4816
+ var _arr = [];
4817
+ var _n = true;
4818
+ var _d = false;
4819
+ var _e = undefined;
4820
+
4821
+ try {
4822
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
4823
+ _arr.push(_s.value);
4824
+
4825
+ if (i && _arr.length === i) break;
4826
+ }
4827
+ } catch (err) {
4828
+ _d = true;
4829
+ _e = err;
4830
+ } finally {
4831
+ try {
4832
+ if (!_n && _i["return"]) _i["return"]();
4833
+ } finally {
4834
+ if (_d) throw _e;
4835
+ }
4836
+ }
4837
+
4838
+ return _arr;
4839
+ }
4840
+
4841
+ return function (arr, i) {
4842
+ if (Array.isArray(arr)) {
4843
+ return arr;
4844
+ } else if (Symbol.iterator in Object(arr)) {
4845
+ return sliceIterator(arr, i);
4846
+ } else {
4847
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
4848
+ }
4849
+ };
4850
+ }();
4851
+
4852
+ /*:: import type {ControlPosition, PositionOffsetControlPosition, MouseTouchEvent} from './types';*/
4853
+
4854
+ var matchesSelectorFunc = '';
4855
+ function matchesSelector(el /*: Node*/, selector /*: string*/) /*: boolean*/{
4856
+ if (!matchesSelectorFunc) {
4857
+ matchesSelectorFunc = findInArray(['matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector', 'oMatchesSelector'], function (method) {
4858
+ // $FlowIgnore: Doesn't think elements are indexable
4859
+ return isFunction(el[method]);
4860
+ });
4861
+ }
4862
+
4863
+ // Might not be found entirely (not an Element?) - in that case, bail
4864
+ // $FlowIgnore: Doesn't think elements are indexable
4865
+ if (!isFunction(el[matchesSelectorFunc])) return false;
4866
+
4867
+ // $FlowIgnore: Doesn't think elements are indexable
4868
+ return el[matchesSelectorFunc](selector);
4869
+ }
4870
+
4871
+ // Works up the tree to the draggable itself attempting to match selector.
4872
+ function matchesSelectorAndParentsTo(el /*: Node*/, selector /*: string*/, baseNode /*: Node*/) /*: boolean*/{
4873
+ var node = el;
4874
+ do {
4875
+ if (matchesSelector(node, selector)) return true;
4876
+ if (node === baseNode) return false;
4877
+ node = node.parentNode;
4878
+ } while (node);
4879
+
4880
+ return false;
4881
+ }
4882
+
4883
+ function addEvent(el /*: ?Node*/, event /*: string*/, handler /*: Function*/) /*: void*/{
4884
+ if (!el) {
4885
+ return;
4886
+ }
4887
+ if (el.attachEvent) {
4888
+ el.attachEvent('on' + event, handler);
4889
+ } else if (el.addEventListener) {
4890
+ el.addEventListener(event, handler, true);
4891
+ } else {
4892
+ // $FlowIgnore: Doesn't think elements are indexable
4893
+ el['on' + event] = handler;
4894
+ }
4895
+ }
4896
+
4897
+ function removeEvent(el /*: ?Node*/, event /*: string*/, handler /*: Function*/) /*: void*/{
4898
+ if (!el) {
4899
+ return;
4900
+ }
4901
+ if (el.detachEvent) {
4902
+ el.detachEvent('on' + event, handler);
4903
+ } else if (el.removeEventListener) {
4904
+ el.removeEventListener(event, handler, true);
4905
+ } else {
4906
+ // $FlowIgnore: Doesn't think elements are indexable
4907
+ el['on' + event] = null;
4908
+ }
4909
+ }
4910
+
4911
+ function outerHeight(node /*: HTMLElement*/) /*: number*/{
4912
+ // This is deliberately excluding margin for our calculations, since we are using
4913
+ // offsetTop which is including margin. See getBoundPosition
4914
+ var height = node.clientHeight;
4915
+ var computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
4916
+ height += int(computedStyle.borderTopWidth);
4917
+ height += int(computedStyle.borderBottomWidth);
4918
+ return height;
4919
+ }
4920
+
4921
+ function outerWidth(node /*: HTMLElement*/) /*: number*/{
4922
+ // This is deliberately excluding margin for our calculations, since we are using
4923
+ // offsetLeft which is including margin. See getBoundPosition
4924
+ var width = node.clientWidth;
4925
+ var computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
4926
+ width += int(computedStyle.borderLeftWidth);
4927
+ width += int(computedStyle.borderRightWidth);
4928
+ return width;
4929
+ }
4930
+ function innerHeight(node /*: HTMLElement*/) /*: number*/{
4931
+ var height = node.clientHeight;
4932
+ var computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
4933
+ height -= int(computedStyle.paddingTop);
4934
+ height -= int(computedStyle.paddingBottom);
4935
+ return height;
4936
+ }
4937
+
4938
+ function innerWidth(node /*: HTMLElement*/) /*: number*/{
4939
+ var width = node.clientWidth;
4940
+ var computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
4941
+ width -= int(computedStyle.paddingLeft);
4942
+ width -= int(computedStyle.paddingRight);
4943
+ return width;
4944
+ }
4945
+
4946
+ // Get from offsetParent
4947
+ function offsetXYFromParent(evt /*: {clientX: number, clientY: number}*/, offsetParent /*: HTMLElement*/) /*: ControlPosition*/{
4948
+ var isBody = offsetParent === offsetParent.ownerDocument.body;
4949
+ var offsetParentRect = isBody ? { left: 0, top: 0 } : offsetParent.getBoundingClientRect();
4950
+
4951
+ var x = evt.clientX + offsetParent.scrollLeft - offsetParentRect.left;
4952
+ var y = evt.clientY + offsetParent.scrollTop - offsetParentRect.top;
4953
+
4954
+ return { x: x, y: y };
4955
+ }
4956
+
4957
+ function createCSSTransform(controlPos /*: ControlPosition*/, positionOffset /*: PositionOffsetControlPosition*/) /*: Object*/{
4958
+ var translation = getTranslation(controlPos, positionOffset, 'px');
4959
+ return defineProperty({}, browserPrefixToKey('transform', browserPrefix), translation);
4960
+ }
4961
+
4962
+ function createSVGTransform(controlPos /*: ControlPosition*/, positionOffset /*: PositionOffsetControlPosition*/) /*: string*/{
4963
+ var translation = getTranslation(controlPos, positionOffset, '');
4964
+ return translation;
4965
+ }
4966
+ function getTranslation(_ref2, positionOffset /*: PositionOffsetControlPosition*/, unitSuffix /*: string*/) /*: string*/{
4967
+ var x = _ref2.x,
4968
+ y = _ref2.y;
4969
+
4970
+ var translation = 'translate(' + x + unitSuffix + ',' + y + unitSuffix + ')';
4971
+ if (positionOffset) {
4972
+ var defaultX = '' + (typeof positionOffset.x === 'string' ? positionOffset.x : positionOffset.x + unitSuffix);
4973
+ var defaultY = '' + (typeof positionOffset.y === 'string' ? positionOffset.y : positionOffset.y + unitSuffix);
4974
+ translation = 'translate(' + defaultX + ', ' + defaultY + ')' + translation;
4975
+ }
4976
+ return translation;
4977
+ }
4978
+
4979
+ function getTouch(e /*: MouseTouchEvent*/, identifier /*: number*/) /*: ?{clientX: number, clientY: number}*/{
4980
+ return e.targetTouches && findInArray(e.targetTouches, function (t) {
4981
+ return identifier === t.identifier;
4982
+ }) || e.changedTouches && findInArray(e.changedTouches, function (t) {
4983
+ return identifier === t.identifier;
4984
+ });
4985
+ }
4986
+
4987
+ function getTouchIdentifier(e /*: MouseTouchEvent*/) /*: ?number*/{
4988
+ if (e.targetTouches && e.targetTouches[0]) return e.targetTouches[0].identifier;
4989
+ if (e.changedTouches && e.changedTouches[0]) return e.changedTouches[0].identifier;
4990
+ }
4991
+
4992
+ // User-select Hacks:
4993
+ //
4994
+ // Useful for preventing blue highlights all over everything when dragging.
4995
+
4996
+ // Note we're passing `document` b/c we could be iframed
4997
+ function addUserSelectStyles(doc /*: ?Document*/) {
4998
+ if (!doc) return;
4999
+ var styleEl = doc.getElementById('react-draggable-style-el');
5000
+ if (!styleEl) {
5001
+ styleEl = doc.createElement('style');
5002
+ styleEl.type = 'text/css';
5003
+ styleEl.id = 'react-draggable-style-el';
5004
+ styleEl.innerHTML = '.react-draggable-transparent-selection *::-moz-selection {all: inherit;}\n';
5005
+ styleEl.innerHTML += '.react-draggable-transparent-selection *::selection {all: inherit;}\n';
5006
+ doc.getElementsByTagName('head')[0].appendChild(styleEl);
5007
+ }
5008
+ if (doc.body) addClassName(doc.body, 'react-draggable-transparent-selection');
5009
+ }
5010
+
5011
+ function removeUserSelectStyles(doc /*: ?Document*/) {
5012
+ try {
5013
+ if (doc && doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection');
5014
+ // $FlowIgnore: IE
5015
+ if (doc.selection) {
5016
+ // $FlowIgnore: IE
5017
+ doc.selection.empty();
5018
+ } else {
5019
+ window.getSelection().removeAllRanges(); // remove selection caused by scroll
5020
+ }
5021
+ } catch (e) {
5022
+ // probably IE
5023
+ }
5024
+ }
5025
+
5026
+ function styleHacks() /*: Object*/{
5027
+ var childStyle /*: Object*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
5028
+
5029
+ // Workaround IE pointer events; see #51
5030
+ // https://github.com/mzabriskie/react-draggable/issues/51#issuecomment-103488278
5031
+ return _extends({
5032
+ touchAction: 'none'
5033
+ }, childStyle);
5034
+ }
5035
+
5036
+ function addClassName(el /*: HTMLElement*/, className /*: string*/) {
5037
+ if (el.classList) {
5038
+ el.classList.add(className);
5039
+ } else {
5040
+ if (!el.className.match(new RegExp('(?:^|\\s)' + className + '(?!\\S)'))) {
5041
+ el.className += ' ' + className;
5042
+ }
5043
+ }
5044
+ }
5045
+
5046
+ function removeClassName(el /*: HTMLElement*/, className /*: string*/) {
5047
+ if (el.classList) {
5048
+ el.classList.remove(className);
5049
+ } else {
5050
+ el.className = el.className.replace(new RegExp('(?:^|\\s)' + className + '(?!\\S)', 'g'), '');
5051
+ }
5052
+ }
5053
+
5054
+ /*:: import type Draggable from '../Draggable';*/
5055
+ /*:: import type {Bounds, ControlPosition, DraggableData, MouseTouchEvent} from './types';*/
5056
+ /*:: import type DraggableCore from '../DraggableCore';*/
5057
+
5058
+ function getBoundPosition(draggable /*: Draggable*/, x /*: number*/, y /*: number*/) /*: [number, number]*/{
5059
+ // If no bounds, short-circuit and move on
5060
+ if (!draggable.props.bounds) return [x, y];
5061
+
5062
+ // Clone new bounds
5063
+ var bounds = draggable.props.bounds;
5064
+
5065
+ bounds = typeof bounds === 'string' ? bounds : cloneBounds(bounds);
5066
+ var node = findDOMNode(draggable);
5067
+
5068
+ if (typeof bounds === 'string') {
5069
+ var ownerDocument = node.ownerDocument;
5070
+
5071
+ var ownerWindow = ownerDocument.defaultView;
5072
+ var boundNode = void 0;
5073
+ if (bounds === 'parent') {
5074
+ boundNode = node.parentNode;
5075
+ } else {
5076
+ boundNode = ownerDocument.querySelector(bounds);
5077
+ }
5078
+ if (!(boundNode instanceof ownerWindow.HTMLElement)) {
5079
+ throw new Error('Bounds selector "' + bounds + '" could not find an element.');
5080
+ }
5081
+ var nodeStyle = ownerWindow.getComputedStyle(node);
5082
+ var boundNodeStyle = ownerWindow.getComputedStyle(boundNode);
5083
+ // Compute bounds. This is a pain with padding and offsets but this gets it exactly right.
5084
+ bounds = {
5085
+ left: -node.offsetLeft + int(boundNodeStyle.paddingLeft) + int(nodeStyle.marginLeft),
5086
+ top: -node.offsetTop + int(boundNodeStyle.paddingTop) + int(nodeStyle.marginTop),
5087
+ right: innerWidth(boundNode) - outerWidth(node) - node.offsetLeft + int(boundNodeStyle.paddingRight) - int(nodeStyle.marginRight),
5088
+ bottom: innerHeight(boundNode) - outerHeight(node) - node.offsetTop + int(boundNodeStyle.paddingBottom) - int(nodeStyle.marginBottom)
5089
+ };
5090
+ }
5091
+
5092
+ // Keep x and y below right and bottom limits...
5093
+ if (isNum(bounds.right)) x = Math.min(x, bounds.right);
5094
+ if (isNum(bounds.bottom)) y = Math.min(y, bounds.bottom);
5095
+
5096
+ // But above left and top limits.
5097
+ if (isNum(bounds.left)) x = Math.max(x, bounds.left);
5098
+ if (isNum(bounds.top)) y = Math.max(y, bounds.top);
5099
+
5100
+ return [x, y];
5101
+ }
5102
+
5103
+ function snapToGrid(grid /*: [number, number]*/, pendingX /*: number*/, pendingY /*: number*/) /*: [number, number]*/{
5104
+ var x = Math.round(pendingX / grid[0]) * grid[0];
5105
+ var y = Math.round(pendingY / grid[1]) * grid[1];
5106
+ return [x, y];
5107
+ }
5108
+
5109
+ function canDragX(draggable /*: Draggable*/) /*: boolean*/{
5110
+ return draggable.props.axis === 'both' || draggable.props.axis === 'x';
5111
+ }
5112
+
5113
+ function canDragY(draggable /*: Draggable*/) /*: boolean*/{
5114
+ return draggable.props.axis === 'both' || draggable.props.axis === 'y';
5115
+ }
5116
+
5117
+ // Get {x, y} positions from event.
5118
+ function getControlPosition(e /*: MouseTouchEvent*/, touchIdentifier /*: ?number*/, draggableCore /*: DraggableCore*/) /*: ?ControlPosition*/{
5119
+ var touchObj = typeof touchIdentifier === 'number' ? getTouch(e, touchIdentifier) : null;
5120
+ if (typeof touchIdentifier === 'number' && !touchObj) return null; // not the right touch
5121
+ var node = findDOMNode(draggableCore);
5122
+ // User can provide an offsetParent if desired.
5123
+ var offsetParent = draggableCore.props.offsetParent || node.offsetParent || node.ownerDocument.body;
5124
+ return offsetXYFromParent(touchObj || e, offsetParent);
5125
+ }
5126
+
5127
+ // Create an data object exposed by <DraggableCore>'s events
5128
+ function createCoreData(draggable /*: DraggableCore*/, x /*: number*/, y /*: number*/) /*: DraggableData*/{
5129
+ var state = draggable.state;
5130
+ var isStart = !isNum(state.lastX);
5131
+ var node = findDOMNode(draggable);
5132
+
5133
+ if (isStart) {
5134
+ // If this is our first move, use the x and y as last coords.
5135
+ return {
5136
+ node: node,
5137
+ deltaX: 0, deltaY: 0,
5138
+ lastX: x, lastY: y,
5139
+ x: x, y: y
5140
+ };
5141
+ } else {
5142
+ // Otherwise calculate proper values.
5143
+ return {
5144
+ node: node,
5145
+ deltaX: x - state.lastX, deltaY: y - state.lastY,
5146
+ lastX: state.lastX, lastY: state.lastY,
5147
+ x: x, y: y
5148
+ };
5149
+ }
5150
+ }
5151
+
5152
+ // Create an data exposed by <Draggable>'s events
5153
+ function createDraggableData(draggable /*: Draggable*/, coreData /*: DraggableData*/) /*: DraggableData*/{
5154
+ var scale = draggable.props.scale;
5155
+ return {
5156
+ node: coreData.node,
5157
+ x: draggable.state.x + coreData.deltaX / scale,
5158
+ y: draggable.state.y + coreData.deltaY / scale,
5159
+ deltaX: coreData.deltaX / scale,
5160
+ deltaY: coreData.deltaY / scale,
5161
+ lastX: draggable.state.x,
5162
+ lastY: draggable.state.y
5163
+ };
5164
+ }
5165
+
5166
+ // A lot faster than stringify/parse
5167
+ function cloneBounds(bounds /*: Bounds*/) /*: Bounds*/{
5168
+ return {
5169
+ left: bounds.left,
5170
+ top: bounds.top,
5171
+ right: bounds.right,
5172
+ bottom: bounds.bottom
5173
+ };
5174
+ }
5175
+
5176
+ function findDOMNode(draggable /*: Draggable | DraggableCore*/) /*: HTMLElement*/{
5177
+ var node = ReactDOM.findDOMNode(draggable);
5178
+ if (!node) {
5179
+ throw new Error('<DraggableCore>: Unmounted during event!');
5180
+ }
5181
+ // $FlowIgnore we can't assert on HTMLElement due to tests... FIXME
5182
+ return node;
5183
+ }
5184
+
5185
+ /*eslint no-console:0*/
5186
+ function log() {}
5187
+
5188
+ /*:: import type {EventHandler, MouseTouchEvent} from './utils/types';*/
5189
+
5190
+ // Simple abstraction for dragging events names.
5191
+ /*:: import type {Element as ReactElement} from 'react';*/
5192
+ var eventsFor = {
5193
+ touch: {
5194
+ start: 'touchstart',
5195
+ move: 'touchmove',
5196
+ stop: 'touchend'
5197
+ },
5198
+ mouse: {
5199
+ start: 'mousedown',
5200
+ move: 'mousemove',
5201
+ stop: 'mouseup'
5202
+ }
5203
+ };
5204
+
5205
+ // Default to mouse events.
5206
+ var dragEventFor = eventsFor.mouse;
5207
+
5208
+ /*:: type DraggableCoreState = {
5209
+ dragging: boolean,
5210
+ lastX: number,
5211
+ lastY: number,
5212
+ touchIdentifier: ?number
5213
+ };*/
5214
+ /*:: export type DraggableBounds = {
5215
+ left: number,
5216
+ right: number,
5217
+ top: number,
5218
+ bottom: number,
5219
+ };*/
5220
+ /*:: export type DraggableData = {
5221
+ node: HTMLElement,
5222
+ x: number, y: number,
5223
+ deltaX: number, deltaY: number,
5224
+ lastX: number, lastY: number,
5225
+ };*/
5226
+ /*:: export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void;*/
5227
+ /*:: export type ControlPosition = {x: number, y: number};*/
5228
+ /*:: export type PositionOffsetControlPosition = {x: number|string, y: number|string};*/
5229
+
5230
+ //
5231
+ // Define <DraggableCore>.
5232
+ //
5233
+ // <DraggableCore> is for advanced usage of <Draggable>. It maintains minimal internal state so it can
5234
+ // work well with libraries that require more control over the element.
5235
+ //
5236
+
5237
+ /*:: export type DraggableCoreProps = {
5238
+ allowAnyClick: boolean,
5239
+ cancel: string,
5240
+ children: ReactElement<any>,
5241
+ disabled: boolean,
5242
+ enableUserSelectHack: boolean,
5243
+ offsetParent: HTMLElement,
5244
+ grid: [number, number],
5245
+ handle: string,
5246
+ onStart: DraggableEventHandler,
5247
+ onDrag: DraggableEventHandler,
5248
+ onStop: DraggableEventHandler,
5249
+ onMouseDown: (e: MouseEvent) => void,
5250
+ };*/
5251
+
5252
+ var DraggableCore = function (_React$Component) {
5253
+ inherits(DraggableCore, _React$Component);
5254
+
5255
+ function DraggableCore() {
5256
+ var _ref;
5257
+
5258
+ var _temp, _this, _ret;
5259
+
5260
+ classCallCheck(this, DraggableCore);
5261
+
5262
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
5263
+ args[_key] = arguments[_key];
5264
+ }
5265
+
5266
+ return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = DraggableCore.__proto__ || Object.getPrototypeOf(DraggableCore)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
5267
+ dragging: false,
5268
+ // Used while dragging to determine deltas.
5269
+ lastX: NaN, lastY: NaN,
5270
+ touchIdentifier: null
5271
+ }, _this.handleDragStart = function (e) {
5272
+ // Make it possible to attach event handlers on top of this one.
5273
+ _this.props.onMouseDown(e);
5274
+
5275
+ // Only accept left-clicks.
5276
+ if (!_this.props.allowAnyClick && typeof e.button === 'number' && e.button !== 0) return false;
5277
+
5278
+ // Get nodes. Be sure to grab relative document (could be iframed)
5279
+ var thisNode = ReactDOM.findDOMNode(_this);
5280
+ if (!thisNode || !thisNode.ownerDocument || !thisNode.ownerDocument.body) {
5281
+ throw new Error('<DraggableCore> not mounted on DragStart!');
5282
+ }
5283
+ var ownerDocument = thisNode.ownerDocument;
5284
+
5285
+ // Short circuit if handle or cancel prop was provided and selector doesn't match.
5286
+
5287
+ if (_this.props.disabled || !(e.target instanceof ownerDocument.defaultView.Node) || _this.props.handle && !matchesSelectorAndParentsTo(e.target, _this.props.handle, thisNode) || _this.props.cancel && matchesSelectorAndParentsTo(e.target, _this.props.cancel, thisNode)) {
5288
+ return;
5289
+ }
5290
+
5291
+ // Set touch identifier in component state if this is a touch event. This allows us to
5292
+ // distinguish between individual touches on multitouch screens by identifying which
5293
+ // touchpoint was set to this element.
5294
+ var touchIdentifier = getTouchIdentifier(e);
5295
+ _this.setState({ touchIdentifier: touchIdentifier });
5296
+
5297
+ // Get the current drag point from the event. This is used as the offset.
5298
+ var position = getControlPosition(e, touchIdentifier, _this);
5299
+ if (position == null) return; // not possible but satisfies flow
5300
+ var x = position.x,
5301
+ y = position.y;
5302
+
5303
+ // Create an event object with all the data parents need to make a decision here.
5304
+
5305
+ var coreEvent = createCoreData(_this, x, y);
5306
+
5307
+ // Call event handler. If it returns explicit false, cancel.
5308
+ log('calling', _this.props.onStart);
5309
+ var shouldUpdate = _this.props.onStart(e, coreEvent);
5310
+ if (shouldUpdate === false) return;
5311
+
5312
+ // Add a style to the body to disable user-select. This prevents text from
5313
+ // being selected all over the page.
5314
+ if (_this.props.enableUserSelectHack) addUserSelectStyles(ownerDocument);
5315
+
5316
+ // Initiate dragging. Set the current x and y as offsets
5317
+ // so we know how much we've moved during the drag. This allows us
5318
+ // to drag elements around even if they have been moved, without issue.
5319
+ _this.setState({
5320
+ dragging: true,
5321
+
5322
+ lastX: x,
5323
+ lastY: y
5324
+ });
5325
+
5326
+ // Add events to the document directly so we catch when the user's mouse/touch moves outside of
5327
+ // this element. We use different events depending on whether or not we have detected that this
5328
+ // is a touch-capable device.
5329
+ addEvent(ownerDocument, dragEventFor.move, _this.handleDrag);
5330
+ addEvent(ownerDocument, dragEventFor.stop, _this.handleDragStop);
5331
+ }, _this.handleDrag = function (e) {
5332
+
5333
+ // Prevent scrolling on mobile devices, like ipad/iphone.
5334
+ if (e.type === 'touchmove') e.preventDefault();
5335
+
5336
+ // Get the current drag point from the event. This is used as the offset.
5337
+ var position = getControlPosition(e, _this.state.touchIdentifier, _this);
5338
+ if (position == null) return;
5339
+ var x = position.x,
5340
+ y = position.y;
5341
+
5342
+ // Snap to grid if prop has been provided
5343
+
5344
+ if (Array.isArray(_this.props.grid)) {
5345
+ var _deltaX = x - _this.state.lastX,
5346
+ _deltaY = y - _this.state.lastY;
5347
+
5348
+ var _snapToGrid = snapToGrid(_this.props.grid, _deltaX, _deltaY);
5349
+
5350
+ var _snapToGrid2 = slicedToArray(_snapToGrid, 2);
5351
+
5352
+ _deltaX = _snapToGrid2[0];
5353
+ _deltaY = _snapToGrid2[1];
5354
+
5355
+ if (!_deltaX && !_deltaY) return; // skip useless drag
5356
+ x = _this.state.lastX + _deltaX, y = _this.state.lastY + _deltaY;
5357
+ }
5358
+
5359
+ var coreEvent = createCoreData(_this, x, y);
5360
+
5361
+ // Call event handler. If it returns explicit false, trigger end.
5362
+ var shouldUpdate = _this.props.onDrag(e, coreEvent);
5363
+ if (shouldUpdate === false) {
5364
+ try {
5365
+ // $FlowIgnore
5366
+ _this.handleDragStop(new MouseEvent('mouseup'));
5367
+ } catch (err) {
5368
+ // Old browsers
5369
+ var event = document.createEvent('MouseEvents') /*: any*/;
5370
+ // I see why this insanity was deprecated
5371
+ // $FlowIgnore
5372
+ event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
5373
+ _this.handleDragStop(event);
5374
+ }
5375
+ return;
5376
+ }
5377
+
5378
+ _this.setState({
5379
+ lastX: x,
5380
+ lastY: y
5381
+ });
5382
+ }, _this.handleDragStop = function (e) {
5383
+ if (!_this.state.dragging) return;
5384
+
5385
+ var position = getControlPosition(e, _this.state.touchIdentifier, _this);
5386
+ if (position == null) return;
5387
+ var x = position.x,
5388
+ y = position.y;
5389
+
5390
+ var coreEvent = createCoreData(_this, x, y);
5391
+
5392
+ var thisNode = ReactDOM.findDOMNode(_this);
5393
+ if (thisNode) {
5394
+ // Remove user-select hack
5395
+ if (_this.props.enableUserSelectHack) removeUserSelectStyles(thisNode.ownerDocument);
5396
+ }
5397
+
5398
+ // Reset the el.
5399
+ _this.setState({
5400
+ dragging: false,
5401
+ lastX: NaN,
5402
+ lastY: NaN
5403
+ });
5404
+
5405
+ // Call event handler
5406
+ _this.props.onStop(e, coreEvent);
5407
+
5408
+ if (thisNode) {
5409
+ removeEvent(thisNode.ownerDocument, dragEventFor.move, _this.handleDrag);
5410
+ removeEvent(thisNode.ownerDocument, dragEventFor.stop, _this.handleDragStop);
5411
+ }
5412
+ }, _this.onMouseDown = function (e) {
5413
+ dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
5414
+
5415
+ return _this.handleDragStart(e);
5416
+ }, _this.onMouseUp = function (e) {
5417
+ dragEventFor = eventsFor.mouse;
5418
+
5419
+ return _this.handleDragStop(e);
5420
+ }, _this.onTouchStart = function (e) {
5421
+ // We're on a touch device now, so change the event handlers
5422
+ dragEventFor = eventsFor.touch;
5423
+
5424
+ return _this.handleDragStart(e);
5425
+ }, _this.onTouchEnd = function (e) {
5426
+ // We're on a touch device now, so change the event handlers
5427
+ dragEventFor = eventsFor.touch;
5428
+
5429
+ return _this.handleDragStop(e);
5430
+ }, _temp), possibleConstructorReturn(_this, _ret);
5431
+ }
5432
+
5433
+ createClass(DraggableCore, [{
5434
+ key: 'componentWillUnmount',
5435
+ value: function componentWillUnmount() {
5436
+ // Remove any leftover event handlers. Remove both touch and mouse handlers in case
5437
+ // some browser quirk caused a touch event to fire during a mouse move, or vice versa.
5438
+ var thisNode = ReactDOM.findDOMNode(this);
5439
+ if (thisNode) {
5440
+ var ownerDocument = thisNode.ownerDocument;
5441
+
5442
+ removeEvent(ownerDocument, eventsFor.mouse.move, this.handleDrag);
5443
+ removeEvent(ownerDocument, eventsFor.touch.move, this.handleDrag);
5444
+ removeEvent(ownerDocument, eventsFor.mouse.stop, this.handleDragStop);
5445
+ removeEvent(ownerDocument, eventsFor.touch.stop, this.handleDragStop);
5446
+ if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument);
5447
+ }
5448
+ }
5449
+
5450
+ // Same as onMouseDown (start drag), but now consider this a touch device.
5451
+
5452
+ }, {
5453
+ key: 'render',
5454
+ value: function render() {
5455
+ // Reuse the child provided
5456
+ // This makes it flexible to use whatever element is wanted (div, ul, etc)
5457
+ return React$$1.cloneElement(React$$1.Children.only(this.props.children), {
5458
+ style: styleHacks(this.props.children.props.style),
5459
+
5460
+ // Note: mouseMove handler is attached to document so it will still function
5461
+ // when the user drags quickly and leaves the bounds of the element.
5462
+ onMouseDown: this.onMouseDown,
5463
+ onTouchStart: this.onTouchStart,
5464
+ onMouseUp: this.onMouseUp,
5465
+ onTouchEnd: this.onTouchEnd
5466
+ });
5467
+ }
5468
+ }]);
5469
+ return DraggableCore;
5470
+ }(React$$1.Component);
5471
+
5472
+ DraggableCore.displayName = 'DraggableCore';
5473
+ DraggableCore.propTypes = {
5474
+ /**
5475
+ * `allowAnyClick` allows dragging using any mouse button.
5476
+ * By default, we only accept the left button.
5477
+ *
5478
+ * Defaults to `false`.
5479
+ */
5480
+ allowAnyClick: propTypes.bool,
5481
+
5482
+ /**
5483
+ * `disabled`, if true, stops the <Draggable> from dragging. All handlers,
5484
+ * with the exception of `onMouseDown`, will not fire.
5485
+ */
5486
+ disabled: propTypes.bool,
5487
+
5488
+ /**
5489
+ * By default, we add 'user-select:none' attributes to the document body
5490
+ * to prevent ugly text selection during drag. If this is causing problems
5491
+ * for your app, set this to `false`.
5492
+ */
5493
+ enableUserSelectHack: propTypes.bool,
5494
+
5495
+ /**
5496
+ * `offsetParent`, if set, uses the passed DOM node to compute drag offsets
5497
+ * instead of using the parent node.
5498
+ */
5499
+ offsetParent: function offsetParent(props /*: DraggableCoreProps*/, propName /*: $Keys<DraggableCoreProps>*/) {
5500
+ if (props[propName] && props[propName].nodeType !== 1) {
5501
+ throw new Error('Draggable\'s offsetParent must be a DOM Node.');
5502
+ }
5503
+ },
5504
+
5505
+ /**
5506
+ * `grid` specifies the x and y that dragging should snap to.
5507
+ */
5508
+ grid: propTypes.arrayOf(propTypes.number),
5509
+
5510
+ /**
5511
+ * `scale` specifies the scale of the area you are dragging inside of. It allows
5512
+ * the drag deltas to scale correctly with how far zoomed in/out you are.
5513
+ */
5514
+ scale: propTypes.number,
5515
+
5516
+ /**
5517
+ * `handle` specifies a selector to be used as the handle that initiates drag.
5518
+ *
5519
+ * Example:
5520
+ *
5521
+ * ```jsx
5522
+ * let App = React.createClass({
5523
+ * render: function () {
5524
+ * return (
5525
+ * <Draggable handle=".handle">
5526
+ * <div>
5527
+ * <div className="handle">Click me to drag</div>
5528
+ * <div>This is some other content</div>
5529
+ * </div>
5530
+ * </Draggable>
5531
+ * );
5532
+ * }
5533
+ * });
5534
+ * ```
5535
+ */
5536
+ handle: propTypes.string,
5537
+
5538
+ /**
5539
+ * `cancel` specifies a selector to be used to prevent drag initialization.
5540
+ *
5541
+ * Example:
5542
+ *
5543
+ * ```jsx
5544
+ * let App = React.createClass({
5545
+ * render: function () {
5546
+ * return(
5547
+ * <Draggable cancel=".cancel">
5548
+ * <div>
5549
+ * <div className="cancel">You can't drag from here</div>
5550
+ * <div>Dragging here works fine</div>
5551
+ * </div>
5552
+ * </Draggable>
5553
+ * );
5554
+ * }
5555
+ * });
5556
+ * ```
5557
+ */
5558
+ cancel: propTypes.string,
5559
+
5560
+ /**
5561
+ * Called when dragging starts.
5562
+ * If this function returns the boolean false, dragging will be canceled.
5563
+ */
5564
+ onStart: propTypes.func,
5565
+
5566
+ /**
5567
+ * Called while dragging.
5568
+ * If this function returns the boolean false, dragging will be canceled.
5569
+ */
5570
+ onDrag: propTypes.func,
5571
+
5572
+ /**
5573
+ * Called when dragging stops.
5574
+ * If this function returns the boolean false, the drag will remain active.
5575
+ */
5576
+ onStop: propTypes.func,
5577
+
5578
+ /**
5579
+ * A workaround option which can be passed if onMouseDown needs to be accessed,
5580
+ * since it'll always be blocked (as there is internal use of onMouseDown)
5581
+ */
5582
+ onMouseDown: propTypes.func,
5583
+
5584
+ /**
5585
+ * These properties should be defined on the child, not here.
5586
+ */
5587
+ className: dontSetMe,
5588
+ style: dontSetMe,
5589
+ transform: dontSetMe
5590
+ };
5591
+ DraggableCore.defaultProps = {
5592
+ allowAnyClick: false, // by default only accept left click
5593
+ cancel: null,
5594
+ disabled: false,
5595
+ enableUserSelectHack: true,
5596
+ offsetParent: null,
5597
+ handle: null,
5598
+ grid: null,
5599
+ transform: null,
5600
+ onStart: function onStart() {},
5601
+ onDrag: function onDrag() {},
5602
+ onStop: function onStop() {},
5603
+ onMouseDown: function onMouseDown() {}
5604
+ };
5605
+
5606
+ /*:: import type {DraggableEventHandler} from './utils/types';*/
5607
+ /*:: import type {Element as ReactElement} from 'react';*/
5608
+ /*:: type DraggableState = {
5609
+ dragging: boolean,
5610
+ dragged: boolean,
5611
+ x: number, y: number,
5612
+ slackX: number, slackY: number,
5613
+ isElementSVG: boolean
5614
+ };*/
5615
+
5616
+ //
5617
+ // Define <Draggable>
5618
+ //
5619
+
5620
+ /*:: export type DraggableProps = {
5621
+ ...$Exact<DraggableCoreProps>,
5622
+ axis: 'both' | 'x' | 'y' | 'none',
5623
+ bounds: DraggableBounds | string | false,
5624
+ defaultClassName: string,
5625
+ defaultClassNameDragging: string,
5626
+ defaultClassNameDragged: string,
5627
+ defaultPosition: ControlPosition,
5628
+ positionOffset: PositionOffsetControlPosition,
5629
+ position: ControlPosition,
5630
+ scale: number
5631
+ };*/
5632
+
5633
+ var Draggable = function (_React$Component) {
5634
+ inherits(Draggable, _React$Component);
5635
+
5636
+ function Draggable(props /*: DraggableProps*/) {
5637
+ classCallCheck(this, Draggable);
5638
+
5639
+ var _this = possibleConstructorReturn(this, (Draggable.__proto__ || Object.getPrototypeOf(Draggable)).call(this, props));
5640
+
5641
+ _this.onDragStart = function (e, coreData) {
5642
+
5643
+ // Short-circuit if user's callback killed it.
5644
+ var shouldStart = _this.props.onStart(e, createDraggableData(_this, coreData));
5645
+ // Kills start event on core as well, so move handlers are never bound.
5646
+ if (shouldStart === false) return false;
5647
+
5648
+ _this.setState({ dragging: true, dragged: true });
5649
+ };
5650
+
5651
+ _this.onDrag = function (e, coreData) {
5652
+ if (!_this.state.dragging) return false;
5653
+
5654
+ var uiData = createDraggableData(_this, coreData);
5655
+
5656
+ var newState /*: $Shape<DraggableState>*/ = {
5657
+ x: uiData.x,
5658
+ y: uiData.y
5659
+ };
5660
+
5661
+ // Keep within bounds.
5662
+ if (_this.props.bounds) {
5663
+ // Save original x and y.
5664
+ var _x = newState.x,
5665
+ _y = newState.y;
5666
+
5667
+ // Add slack to the values used to calculate bound position. This will ensure that if
5668
+ // we start removing slack, the element won't react to it right away until it's been
5669
+ // completely removed.
5670
+
5671
+ newState.x += _this.state.slackX;
5672
+ newState.y += _this.state.slackY;
5673
+
5674
+ // Get bound position. This will ceil/floor the x and y within the boundaries.
5675
+
5676
+ var _getBoundPosition = getBoundPosition(_this, newState.x, newState.y),
5677
+ _getBoundPosition2 = slicedToArray(_getBoundPosition, 2),
5678
+ newStateX = _getBoundPosition2[0],
5679
+ newStateY = _getBoundPosition2[1];
5680
+
5681
+ newState.x = newStateX;
5682
+ newState.y = newStateY;
5683
+
5684
+ // Recalculate slack by noting how much was shaved by the boundPosition handler.
5685
+ newState.slackX = _this.state.slackX + (_x - newState.x);
5686
+ newState.slackY = _this.state.slackY + (_y - newState.y);
5687
+
5688
+ // Update the event we fire to reflect what really happened after bounds took effect.
5689
+ uiData.x = newState.x;
5690
+ uiData.y = newState.y;
5691
+ uiData.deltaX = newState.x - _this.state.x;
5692
+ uiData.deltaY = newState.y - _this.state.y;
5693
+ }
5694
+
5695
+ // Short-circuit if user's callback killed it.
5696
+ var shouldUpdate = _this.props.onDrag(e, uiData);
5697
+ if (shouldUpdate === false) return false;
5698
+
5699
+ _this.setState(newState);
5700
+ };
5701
+
5702
+ _this.onDragStop = function (e, coreData) {
5703
+ if (!_this.state.dragging) return false;
5704
+
5705
+ // Short-circuit if user's callback killed it.
5706
+ var shouldStop = _this.props.onStop(e, createDraggableData(_this, coreData));
5707
+ if (shouldStop === false) return false;
5708
+
5709
+ var newState /*: $Shape<DraggableState>*/ = {
5710
+ dragging: false,
5711
+ slackX: 0,
5712
+ slackY: 0
5713
+ };
5714
+
5715
+ // If this is a controlled component, the result of this operation will be to
5716
+ // revert back to the old position. We expect a handler on `onDragStop`, at the least.
5717
+ var controlled = Boolean(_this.props.position);
5718
+ if (controlled) {
5719
+ var _this$props$position = _this.props.position,
5720
+ _x2 = _this$props$position.x,
5721
+ _y2 = _this$props$position.y;
5722
+
5723
+ newState.x = _x2;
5724
+ newState.y = _y2;
5725
+ }
5726
+
5727
+ _this.setState(newState);
5728
+ };
5729
+
5730
+ _this.state = {
5731
+ // Whether or not we are currently dragging.
5732
+ dragging: false,
5733
+
5734
+ // Whether or not we have been dragged before.
5735
+ dragged: false,
5736
+
5737
+ // Current transform x and y.
5738
+ x: props.position ? props.position.x : props.defaultPosition.x,
5739
+ y: props.position ? props.position.y : props.defaultPosition.y,
5740
+
5741
+ // Used for compensating for out-of-bounds drags
5742
+ slackX: 0, slackY: 0,
5743
+
5744
+ // Can only determine if SVG after mounting
5745
+ isElementSVG: false
5746
+ };
5747
+
5748
+ if (props.position && !(props.onDrag || props.onStop)) {
5749
+ // eslint-disable-next-line no-console
5750
+ console.warn('A `position` was applied to this <Draggable>, without drag handlers. This will make this ' + 'component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the ' + '`position` of this element.');
5751
+ }
5752
+ return _this;
5753
+ }
5754
+
5755
+ createClass(Draggable, [{
5756
+ key: 'componentDidMount',
5757
+ value: function componentDidMount() {
5758
+ // Check to see if the element passed is an instanceof SVGElement
5759
+ if (typeof window.SVGElement !== 'undefined' && ReactDOM.findDOMNode(this) instanceof window.SVGElement) {
5760
+ this.setState({ isElementSVG: true });
5761
+ }
5762
+ }
5763
+ }, {
5764
+ key: 'componentWillReceiveProps',
5765
+ value: function componentWillReceiveProps(nextProps /*: Object*/) {
5766
+ // Set x/y if position has changed
5767
+ if (nextProps.position && (!this.props.position || nextProps.position.x !== this.props.position.x || nextProps.position.y !== this.props.position.y)) {
5768
+ this.setState({ x: nextProps.position.x, y: nextProps.position.y });
5769
+ }
5770
+ }
5771
+ }, {
5772
+ key: 'componentWillUnmount',
5773
+ value: function componentWillUnmount() {
5774
+ this.setState({ dragging: false }); // prevents invariant if unmounted while dragging
5775
+ }
5776
+ }, {
5777
+ key: 'render',
5778
+ value: function render() /*: ReactElement<any>*/{
5779
+ var _classNames;
5780
+
5781
+ var style = {},
5782
+ svgTransform = null;
5783
+
5784
+ // If this is controlled, we don't want to move it - unless it's dragging.
5785
+ var controlled = Boolean(this.props.position);
5786
+ var draggable = !controlled || this.state.dragging;
5787
+
5788
+ var position = this.props.position || this.props.defaultPosition;
5789
+ var transformOpts = {
5790
+ // Set left if horizontal drag is enabled
5791
+ x: canDragX(this) && draggable ? this.state.x : position.x,
5792
+
5793
+ // Set top if vertical drag is enabled
5794
+ y: canDragY(this) && draggable ? this.state.y : position.y
5795
+ };
5796
+
5797
+ // If this element was SVG, we use the `transform` attribute.
5798
+ if (this.state.isElementSVG) {
5799
+ svgTransform = createSVGTransform(transformOpts, this.props.positionOffset);
5800
+ } else {
5801
+ // Add a CSS transform to move the element around. This allows us to move the element around
5802
+ // without worrying about whether or not it is relatively or absolutely positioned.
5803
+ // If the item you are dragging already has a transform set, wrap it in a <span> so <Draggable>
5804
+ // has a clean slate.
5805
+ style = createCSSTransform(transformOpts, this.props.positionOffset);
5806
+ }
5807
+
5808
+ var _props = this.props,
5809
+ defaultClassName = _props.defaultClassName,
5810
+ defaultClassNameDragging = _props.defaultClassNameDragging,
5811
+ defaultClassNameDragged = _props.defaultClassNameDragged;
5812
+
5813
+ var children = React$$1.Children.only(this.props.children);
5814
+
5815
+ // Mark with class while dragging
5816
+ var className = classnames(children.props.className || '', defaultClassName, (_classNames = {}, defineProperty(_classNames, defaultClassNameDragging, this.state.dragging), defineProperty(_classNames, defaultClassNameDragged, this.state.dragged), _classNames));
5817
+
5818
+ // Reuse the child provided
5819
+ // This makes it flexible to use whatever element is wanted (div, ul, etc)
5820
+ return React$$1.createElement(DraggableCore, _extends({}, this.props, { onStart: this.onDragStart, onDrag: this.onDrag, onStop: this.onDragStop }), React$$1.cloneElement(children, {
5821
+ className: className,
5822
+ style: _extends({}, children.props.style, style),
5823
+ transform: svgTransform
5824
+ }));
5825
+ }
5826
+ }]);
5827
+ return Draggable;
5828
+ }(React$$1.Component);
5829
+
5830
+ Draggable.displayName = 'Draggable';
5831
+ Draggable.propTypes = _extends({}, DraggableCore.propTypes, {
5832
+
5833
+ /**
5834
+ * `axis` determines which axis the draggable can move.
5835
+ *
5836
+ * Note that all callbacks will still return data as normal. This only
5837
+ * controls flushing to the DOM.
5838
+ *
5839
+ * 'both' allows movement horizontally and vertically.
5840
+ * 'x' limits movement to horizontal axis.
5841
+ * 'y' limits movement to vertical axis.
5842
+ * 'none' limits all movement.
5843
+ *
5844
+ * Defaults to 'both'.
5845
+ */
5846
+ axis: propTypes.oneOf(['both', 'x', 'y', 'none']),
5847
+
5848
+ /**
5849
+ * `bounds` determines the range of movement available to the element.
5850
+ * Available values are:
5851
+ *
5852
+ * 'parent' restricts movement within the Draggable's parent node.
5853
+ *
5854
+ * Alternatively, pass an object with the following properties, all of which are optional:
5855
+ *
5856
+ * {left: LEFT_BOUND, right: RIGHT_BOUND, bottom: BOTTOM_BOUND, top: TOP_BOUND}
5857
+ *
5858
+ * All values are in px.
5859
+ *
5860
+ * Example:
5861
+ *
5862
+ * ```jsx
5863
+ * let App = React.createClass({
5864
+ * render: function () {
5865
+ * return (
5866
+ * <Draggable bounds={{right: 300, bottom: 300}}>
5867
+ * <div>Content</div>
5868
+ * </Draggable>
5869
+ * );
5870
+ * }
5871
+ * });
5872
+ * ```
5873
+ */
5874
+ bounds: propTypes.oneOfType([propTypes.shape({
5875
+ left: propTypes.number,
5876
+ right: propTypes.number,
5877
+ top: propTypes.number,
5878
+ bottom: propTypes.number
5879
+ }), propTypes.string, propTypes.oneOf([false])]),
5880
+
5881
+ defaultClassName: propTypes.string,
5882
+ defaultClassNameDragging: propTypes.string,
5883
+ defaultClassNameDragged: propTypes.string,
5884
+
5885
+ /**
5886
+ * `defaultPosition` specifies the x and y that the dragged item should start at
5887
+ *
5888
+ * Example:
5889
+ *
5890
+ * ```jsx
5891
+ * let App = React.createClass({
5892
+ * render: function () {
5893
+ * return (
5894
+ * <Draggable defaultPosition={{x: 25, y: 25}}>
5895
+ * <div>I start with transformX: 25px and transformY: 25px;</div>
5896
+ * </Draggable>
5897
+ * );
5898
+ * }
5899
+ * });
5900
+ * ```
5901
+ */
5902
+ defaultPosition: propTypes.shape({
5903
+ x: propTypes.number,
5904
+ y: propTypes.number
5905
+ }),
5906
+ positionOffset: propTypes.shape({
5907
+ x: propTypes.oneOfType([propTypes.number, propTypes.string]),
5908
+ y: propTypes.oneOfType([propTypes.number, propTypes.string])
5909
+ }),
5910
+
5911
+ /**
5912
+ * `position`, if present, defines the current position of the element.
5913
+ *
5914
+ * This is similar to how form elements in React work - if no `position` is supplied, the component
5915
+ * is uncontrolled.
5916
+ *
5917
+ * Example:
5918
+ *
5919
+ * ```jsx
5920
+ * let App = React.createClass({
5921
+ * render: function () {
5922
+ * return (
5923
+ * <Draggable position={{x: 25, y: 25}}>
5924
+ * <div>I start with transformX: 25px and transformY: 25px;</div>
5925
+ * </Draggable>
5926
+ * );
5927
+ * }
5928
+ * });
5929
+ * ```
5930
+ */
5931
+ position: propTypes.shape({
5932
+ x: propTypes.number,
5933
+ y: propTypes.number
5934
+ }),
5935
+
5936
+ /**
5937
+ * These properties should be defined on the child, not here.
5938
+ */
5939
+ className: dontSetMe,
5940
+ style: dontSetMe,
5941
+ transform: dontSetMe
5942
+ });
5943
+ Draggable.defaultProps = _extends({}, DraggableCore.defaultProps, {
5944
+ axis: 'both',
5945
+ bounds: false,
5946
+ defaultClassName: 'react-draggable',
5947
+ defaultClassNameDragging: 'react-draggable-dragging',
5948
+ defaultClassNameDragged: 'react-draggable-dragged',
5949
+ defaultPosition: { x: 0, y: 0 },
5950
+ position: null,
5951
+ scale: 1
5952
+ });
5953
+
5954
+ // Previous versions of this lib exported <Draggable> as the root export. As to not break
5955
+ // them, or TypeScript, we export *both* as the root and as 'default'.
5956
+ // See https://github.com/mzabriskie/react-draggable/pull/254
5957
+ // and https://github.com/mzabriskie/react-draggable/issues/266
5958
+ Draggable.default = Draggable;
5959
+ Draggable.DraggableCore = DraggableCore;
5960
+
5961
+ return Draggable;
5962
+ });
5963
+
5964
+ });
5965
+
3746
5966
  var _extends$9 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
3747
5967
 
3748
5968
  var _createClass$g = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
3749
5969
 
3750
- function _toConsumableArray$4(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
3751
-
3752
5970
  function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3753
5971
 
3754
5972
  function _possibleConstructorReturn$e(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
3755
5973
 
3756
5974
  function _inherits$e(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
3757
5975
 
5976
+ var InfoBox = function (_Component) {
5977
+ _inherits$e(InfoBox, _Component);
5978
+
5979
+ function InfoBox(props) {
5980
+ _classCallCheck$g(this, InfoBox);
5981
+
5982
+ var _this = _possibleConstructorReturn$e(this, (InfoBox.__proto__ || Object.getPrototypeOf(InfoBox)).call(this, props));
5983
+
5984
+ _this.state = {
5985
+ style: {
5986
+ position: 'fixed',
5987
+ top: 200,
5988
+ left: 200,
5989
+ width: 250
5990
+ }
5991
+ };
5992
+ return _this;
5993
+ }
5994
+
5995
+ _createClass$g(InfoBox, [{
5996
+ key: 'componentDidMount',
5997
+ value: function componentDidMount() {
5998
+ this.updateStyle();
5999
+ }
6000
+ }, {
6001
+ key: 'componentDidUpdate',
6002
+ value: function componentDidUpdate(prevProps) {
6003
+ if (this.props.defaultPos !== prevProps.defaultPos) {
6004
+ this.updateStyle();
6005
+ }
6006
+ }
6007
+ }, {
6008
+ key: 'handleOnStop',
6009
+ value: function handleOnStop(e) {
6010
+ if (this.props.onStop) {
6011
+ this.props.onStop(e);
6012
+ }
6013
+ }
6014
+ }, {
6015
+ key: 'updateStyle',
6016
+ value: function updateStyle() {
6017
+ this.setState({
6018
+ style: _extends$9({}, this.state.style, this.props.defaultPos)
6019
+ });
6020
+ }
6021
+ }, {
6022
+ key: 'onDismiss',
6023
+ value: function onDismiss(e) {
6024
+ if (this.props.onDismiss) {
6025
+ this.props.onDismiss(e);
6026
+ }
6027
+ }
6028
+ }, {
6029
+ key: 'render',
6030
+ value: function render() {
6031
+ var _this2 = this;
6032
+
6033
+ if (!this.props.visible) return null;
6034
+ return React__default.createElement(
6035
+ reactDraggable,
6036
+ { handle: '.handle', onStop: function onStop(e) {
6037
+ return _this2.handleOnStop(e);
6038
+ }
6039
+ },
6040
+ React__default.createElement(
6041
+ 'div',
6042
+ {
6043
+ style: this.state.style },
6044
+ React__default.createElement(
6045
+ semanticUiReact.Message,
6046
+ {
6047
+ style: { opacity: 0.98 },
6048
+ onDismiss: function onDismiss(e) {
6049
+ _this2.onDismiss(e);
6050
+ },
6051
+ size: 'small'
6052
+ },
6053
+ React__default.createElement(
6054
+ semanticUiReact.Header,
6055
+ { textAlign: 'center', as: 'h5', className: 'handle', style: { cursor: 'grab' } },
6056
+ this.props.header
6057
+ ),
6058
+ React__default.createElement(semanticUiReact.Divider, null),
6059
+ React__default.createElement(
6060
+ semanticUiReact.Message.Content,
6061
+ null,
6062
+ this.props.content
6063
+ )
6064
+ )
6065
+ )
6066
+ );
6067
+ }
6068
+ }]);
6069
+
6070
+ return InfoBox;
6071
+ }(React.Component);
6072
+
6073
+ var SiaPopup = function SiaPopup(_ref) {
6074
+ var content = _ref.content,
6075
+ trigger = _ref.trigger;
6076
+
6077
+
6078
+ return React__default.createElement(semanticUiReact.Popup, { inverted: true, style: { opacity: 0.9 }, content: content, trigger: trigger });
6079
+ };
6080
+
6081
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
6082
+
6083
+ var AnnoDetails = function AnnoDetails(props) {
6084
+ var _useState = React.useState(''),
6085
+ _useState2 = _slicedToArray(_useState, 2),
6086
+ comment = _useState2[0],
6087
+ setComment = _useState2[1];
6088
+
6089
+ var _useState3 = React.useState(false),
6090
+ _useState4 = _slicedToArray(_useState3, 2),
6091
+ example = _useState4[0],
6092
+ setExample = _useState4[1];
6093
+
6094
+ var _useState5 = React.useState(false),
6095
+ _useState6 = _slicedToArray(_useState5, 2),
6096
+ showSaveBtn = _useState6[0],
6097
+ setShowSaveBtn = _useState6[1];
6098
+
6099
+ var tARef = React.useRef();
6100
+ React.useEffect(function () {
6101
+ if (props.anno) {
6102
+ if (props.anno.comment) {
6103
+ setComment(props.anno.comment);
6104
+ } else {
6105
+ setComment('');
6106
+ }
6107
+ }
6108
+ }, [props.anno]);
6109
+
6110
+ React.useEffect(function () {
6111
+ if (tARef.current) {
6112
+ tARef.current.focus();
6113
+ }
6114
+ }, [props.commentInputTrigger]);
6115
+
6116
+ var _onDismiss = function _onDismiss() {
6117
+ if (props.onDismiss) {
6118
+ props.onDismiss();
6119
+ }
6120
+ };
6121
+
6122
+ var onCommentUpdate = function onCommentUpdate() {
6123
+ if (props.onCommentUpdate) {
6124
+ props.onCommentUpdate(comment);
6125
+ }
6126
+ setShowSaveBtn(false);
6127
+ };
6128
+
6129
+ var onMarkExampleClick = function onMarkExampleClick() {
6130
+ // setExample(!example)
6131
+ if (props.onMarkExample) {
6132
+ props.onMarkExample(props.anno);
6133
+ }
6134
+ };
6135
+
6136
+ var renderSaveBtn = function renderSaveBtn() {
6137
+ if (showSaveBtn) {
6138
+ return React__default.createElement(semanticUiReact.Label, { as: 'a', corner: 'right', icon: 'save', color: 'red' });
6139
+ }
6140
+ };
6141
+
6142
+ var renderComment = function renderComment() {
6143
+ return React__default.createElement(
6144
+ 'div',
6145
+ null,
6146
+ React__default.createElement(
6147
+ semanticUiReact.Form,
6148
+ { onClick: function onClick() {} },
6149
+ renderSaveBtn(),
6150
+ React__default.createElement(semanticUiReact.TextArea, {
6151
+ placeholder: 'Write a comment',
6152
+ ref: tARef,
6153
+ value: comment,
6154
+ rows: 2,
6155
+ onBlur: function onBlur() {
6156
+ return onCommentUpdate();
6157
+ },
6158
+ onFocus: function onFocus() {
6159
+ return setShowSaveBtn(true);
6160
+ },
6161
+ onChange: function onChange(e) {
6162
+ return setComment(e.target.value);
6163
+ }
6164
+ })
6165
+ )
6166
+ );
6167
+ };
6168
+ var renderLabels = function renderLabels() {
6169
+ if (props.anno) {
6170
+ var selectedLabelIds = props.anno.labelIds;
6171
+ if (!selectedLabelIds) return 'No Label';
6172
+
6173
+ var lbls = '';
6174
+ props.anno.labelIds.forEach(function (lbl, idx) {
6175
+ var labelObject = props.possibleLabels.find(function (el) {
6176
+ return el.id === lbl;
6177
+ });
6178
+ if (idx > 0) lbls += ', ';
6179
+ lbls += labelObject.label;
6180
+ });
6181
+ if (!lbls) return 'No Label';
6182
+ return lbls;
6183
+ } else {
6184
+ return 'No Label';
6185
+ }
6186
+ };
6187
+
6188
+ var renderExampleMark = function renderExampleMark() {
6189
+ if (!props.allowedToMarkExample) return null;
6190
+ var color = 'grey';
6191
+ var iconName = 'bookmark outline';
6192
+ if (props.anno) {
6193
+ if (props.anno.isExample) {
6194
+ color = 'yellow';
6195
+ iconName = 'bookmark';
6196
+ }
6197
+ }
6198
+ var mark = React__default.createElement(
6199
+ semanticUiReact.Label,
6200
+ {
6201
+ as: 'a',
6202
+ color: color,
6203
+ style: { opacity: 0.8 },
6204
+ size: 'medium',
6205
+ corner: 'left',
6206
+ onClick: function onClick() {
6207
+ onMarkExampleClick();
6208
+ }
6209
+ },
6210
+ React__default.createElement(semanticUiReact.Icon, { name: iconName })
6211
+ );
6212
+ return React__default.createElement(SiaPopup, {
6213
+ content: 'Mark this annotation as example for other annotators',
6214
+ trigger: mark
6215
+ });
6216
+ };
6217
+
6218
+ var renderDescription = function renderDescription() {
6219
+ if (props.anno) {
6220
+ return React__default.createElement(
6221
+ 'div',
6222
+ null,
6223
+ renderExampleMark(),
6224
+ React__default.createElement(
6225
+ semanticUiReact.List,
6226
+ null,
6227
+ React__default.createElement(semanticUiReact.List.Item, { icon: 'at', content: props.anno.id }),
6228
+ React__default.createElement(semanticUiReact.List.Item, { icon: 'tag', content: renderLabels() }),
6229
+ React__default.createElement(semanticUiReact.List.Item, {
6230
+ icon: 'time',
6231
+ content: props.anno.annoTime.toLocaleString('us', {
6232
+ minimumFractionDigits: 2,
6233
+ maximumFractionDigits: 2
6234
+ }) + ' seconds'
6235
+ })
6236
+ ),
6237
+ renderComment()
6238
+ );
6239
+ } else {
6240
+ return 'No annotation selected!';
6241
+ }
6242
+ };
6243
+
6244
+ return React__default.createElement(InfoBox, {
6245
+ header: 'Annotation Details',
6246
+ content: renderDescription(),
6247
+ visible: props.visible,
6248
+ defaultPos: props.defaultPos,
6249
+ onDismiss: function onDismiss(e) {
6250
+ return _onDismiss();
6251
+ }
6252
+ });
6253
+ };
6254
+
6255
+ var _slicedToArray$1 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
6256
+
6257
+ function _toConsumableArray$4(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
6258
+ // import actions from '../../../../actions'
6259
+ // import * as transform from '../utils/transform'
6260
+ // const { siaShowImgBar } = actions
6261
+
6262
+ var AnnoStats = function AnnoStats(props) {
6263
+ var _useState = React.useState([]),
6264
+ _useState2 = _slicedToArray$1(_useState, 2),
6265
+ hideList = _useState2[0],
6266
+ setHideList = _useState2[1];
6267
+
6268
+ React.useEffect(function () {
6269
+ setHideList([]);
6270
+ }, [props.imgLoadCount]);
6271
+
6272
+ var _onDismiss = function _onDismiss() {
6273
+ if (props.onDismiss) {
6274
+ props.onDismiss();
6275
+ }
6276
+ };
6277
+
6278
+ var onLblClick = function onLblClick(lbl) {
6279
+ var hideLbl = false;
6280
+ if (hideList.includes(lbl.id)) {
6281
+ setHideList(hideList.filter(function (e) {
6282
+ return e !== lbl.id;
6283
+ }));
6284
+ hideLbl = false;
6285
+ } else {
6286
+ // hideList.push(lbl.id)
6287
+ setHideList([].concat(_toConsumableArray$4(hideList), [lbl.id]));
6288
+ hideLbl = true;
6289
+ }
6290
+ if (props.onHideLbl) {
6291
+ props.onHideLbl(lbl, hideLbl);
6292
+ }
6293
+ };
6294
+
6295
+ var renderRow = function renderRow(s) {
6296
+
6297
+ var opacity = hideList.includes(s.id) ? 0.5 : 1.0;
6298
+ return React__default.createElement(
6299
+ semanticUiReact.List.Item,
6300
+ { key: s.id },
6301
+ React__default.createElement(
6302
+ semanticUiReact.List.Content,
6303
+ null,
6304
+ React__default.createElement(
6305
+ semanticUiReact.Label,
6306
+ { as: 'a', tag: true, style: { background: s.color, opacity: opacity },
6307
+ onClick: function onClick() {
6308
+ return onLblClick(s);
6309
+ }
6310
+ },
6311
+ s.label,
6312
+ React__default.createElement(
6313
+ semanticUiReact.Label.Detail,
6314
+ null,
6315
+ s.amount
6316
+ )
6317
+ )
6318
+ )
6319
+ );
6320
+ };
6321
+
6322
+ var renderRows = function renderRows() {
6323
+ var stats = {};
6324
+ props.annos.forEach(function (a) {
6325
+ // console.log('render rows', a)
6326
+ if (a.status !== 'deleted') {
6327
+ a.labelIds.forEach(function (lblId) {
6328
+ if (lblId in stats) {
6329
+ stats[lblId] += 1;
6330
+ } else {
6331
+ stats[lblId] = 1;
6332
+ }
6333
+ });
6334
+ if (a.labelIds.length === 0) {
6335
+ if (-1 in stats) {
6336
+ stats[-1] += 1;
6337
+ } else {
6338
+ stats[-1] = 1;
6339
+ }
6340
+ }
6341
+ }
6342
+ });
6343
+ var res = Object.entries(stats).map(function (_ref) {
6344
+ var _ref2 = _slicedToArray$1(_ref, 2),
6345
+ key = _ref2[0],
6346
+ value = _ref2[1];
6347
+
6348
+ var lbl = props.possibleLabels.find(function (e) {
6349
+ return e.id === parseInt(key);
6350
+ });
6351
+ if (!lbl) {
6352
+ lbl = { 'id': -1, 'label': 'No Label', 'color': getDefaultColor() };
6353
+ }
6354
+
6355
+ lbl.amount = value;
6356
+ // return renderRow({class:idToLbl[key], amount:value, color:idToColor[key]})
6357
+ return renderRow(lbl);
6358
+ });
6359
+ return res;
6360
+ };
6361
+ var renderDescription = function renderDescription() {
6362
+ return React__default.createElement(
6363
+ semanticUiReact.List,
6364
+ null,
6365
+ renderRows()
6366
+ );
6367
+ };
6368
+
6369
+ return React__default.createElement(InfoBox, {
6370
+ header: 'Annotations per Label',
6371
+ content: renderDescription(),
6372
+ visible: props.visible,
6373
+ defaultPos: props.defaultPos,
6374
+ onDismiss: function onDismiss(e) {
6375
+ return _onDismiss();
6376
+ }
6377
+ });
6378
+ };
6379
+
6380
+ var LabelExampleViewer = function LabelExampleViewer(props) {
6381
+
6382
+ var requestExample = function requestExample(e) {
6383
+ e.stopPropagation();
6384
+ if (props.onRequestExample) {
6385
+ props.onRequestExample();
6386
+ }
6387
+ };
6388
+ var renderContent = function renderContent() {
6389
+ if (!props.lbl) return null;
6390
+ if (!props.exampleImg) return null;
6391
+ var description = React__default.createElement(
6392
+ 'div',
6393
+ null,
6394
+ props.lbl.description,
6395
+ React__default.createElement(
6396
+ semanticUiReact.Divider,
6397
+ { horizontal: true },
6398
+ ' comment '
6399
+ ),
6400
+ props.exampleImg.anno ? props.exampleImg.anno.comment : "no comment"
6401
+ );
6402
+ return React__default.createElement(
6403
+ 'div',
6404
+ null,
6405
+ React__default.createElement(
6406
+ semanticUiReact.Card
6407
+
6408
+ // image={props.exampleImg.img}
6409
+ // description={props.lbl.description}
6410
+ // header={props.lbl.label}
6411
+ // // description={props.exampleImg.anno.comment}
6412
+ // extra={props.exampleImg.anno.comment}
6413
+ ,
6414
+ null,
6415
+ React__default.createElement(semanticUiReact.Image, { onClick: function onClick(e) {
6416
+ return requestExample(e);
6417
+ }, src: props.exampleImg.img, wrapped: true, ui: false }),
6418
+ React__default.createElement(
6419
+ semanticUiReact.Card.Content,
6420
+ null,
6421
+ React__default.createElement(
6422
+ semanticUiReact.Card.Header,
6423
+ null,
6424
+ props.lbl.label
6425
+ ),
6426
+ React__default.createElement(
6427
+ semanticUiReact.Card.Description,
6428
+ null,
6429
+ description
6430
+ )
6431
+ )
6432
+ )
6433
+ );
6434
+ };
6435
+
6436
+ var handlePromptClick = function handlePromptClick() {
6437
+ if (props.onClose) {
6438
+ props.onClose();
6439
+ }
6440
+ };
6441
+
6442
+ return React__default.createElement(Prompt, { onClick: function onClick() {
6443
+ handlePromptClick();
6444
+ },
6445
+ active: props.active, content: renderContent()
6446
+ });
6447
+ };
6448
+
6449
+ var _slicedToArray$2 = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
6450
+ var LabelInfo = function LabelInfo(props) {
6451
+ var _useState = React.useState(false),
6452
+ _useState2 = _slicedToArray$2(_useState, 2),
6453
+ showExampleViewer = _useState2[0],
6454
+ setShowExampleViewer = _useState2[1];
6455
+
6456
+ var _useState3 = React.useState(undefined),
6457
+ _useState4 = _slicedToArray$2(_useState3, 2),
6458
+ myLbl = _useState4[0],
6459
+ setMyLbl = _useState4[1];
6460
+ // const { data: exampleImg, mutate: getAnnoExample } = exampleApi.useGetAnnoExampleImg({})
6461
+
6462
+
6463
+ React.useEffect(function () {
6464
+ if (props.selectedAnno) {
6465
+ var selectedLabelIds = props.selectedAnno.labelIds;
6466
+ if (selectedLabelIds) {
6467
+ var lbl = props.possibleLabels.find(function (e) {
6468
+ return selectedLabelIds[0] === e.id;
6469
+ });
6470
+ if (lbl) {
6471
+ if (lbl !== myLbl) {
6472
+ setMyLbl(lbl);
6473
+ if (props.visible)
6474
+ // getAnnoExample({llId:lbl.id, type:'annoBased', drawAnno: true, addContext:0.05})
6475
+ requestImg(lbl, props.selectedAnno);
6476
+ }
6477
+ }
6478
+ }
6479
+ }
6480
+ }, [props.selectedAnno]);
6481
+ var _onDismiss = function _onDismiss() {
6482
+ if (props.onDismiss) {
6483
+ props.onDismiss();
6484
+ }
6485
+ };
6486
+
6487
+ var requestImg = function requestImg(lbl, anno) {
6488
+ if (props.onGetAnnoExample) {
6489
+ props.onGetAnnoExample({ lbl: lbl, anno: anno });
6490
+ }
6491
+ };
6492
+
6493
+ var handleImgClick = function handleImgClick() {
6494
+ console.log('clicked img');
6495
+ // setShowExampleViewer(true)
6496
+ // requestImg(myLbl, props.selectedAnno)
6497
+
6498
+ setShowExampleViewer(true);
6499
+ // getAnnoExample({llId:myLbl.id, type:'annoBased', drawAnno: true, addContext:0.05})
6500
+ };
6501
+
6502
+ var renderExampleImg = function renderExampleImg() {
6503
+ if (!props.exampleImg) return null;
6504
+ return React__default.createElement(
6505
+ 'div',
6506
+ null,
6507
+ React__default.createElement(
6508
+ semanticUiReact.Divider,
6509
+ { onClick: function onClick() {
6510
+ return handleImgClick();
6511
+ }, horizontal: true },
6512
+ ' Example '
6513
+ ),
6514
+ React__default.createElement(SiaPopup, { trigger: React__default.createElement(semanticUiReact.Image, { src: props.exampleImg.img, rounded: true, centered: true, size: 'medium',
6515
+ onClick: function onClick() {
6516
+ return handleImgClick();
6517
+ }
6518
+ }),
6519
+ content: 'Click on image to view more examples' })
6520
+ );
6521
+ };
6522
+
6523
+ var renderDescription = function renderDescription() {
6524
+ // if (props.selectedAnno){
6525
+ // if (myLbl){
6526
+ // const selectedLabelIds = props.selectedAnno.labelIds
6527
+ // if (!selectedLabelIds) return 'No Label'
6528
+ // const lbl = props.possibleLabels.find( e => {
6529
+ // return selectedLabelIds[0] === e.id
6530
+ // })
6531
+ if (!myLbl) return "No Label";
6532
+ return React__default.createElement(
6533
+ 'div',
6534
+ null,
6535
+ React__default.createElement(
6536
+ semanticUiReact.Header,
6537
+ null,
6538
+ myLbl.label
6539
+ ),
6540
+ React__default.createElement('div', { dangerouslySetInnerHTML: { __html: myLbl.description } }),
6541
+ renderExampleImg(),
6542
+ React__default.createElement(LabelExampleViewer, { onRequestExample: function onRequestExample() {
6543
+ return requestImg(myLbl, props.selectedAnno);
6544
+ }, onClose: function onClose() {
6545
+ setShowExampleViewer(false);
6546
+ }, active: showExampleViewer, lbl: myLbl, exampleImg: props.exampleImg })
6547
+ );
6548
+ // } else {
6549
+ // return 'No Label'
6550
+ // }
6551
+ };
6552
+
6553
+ return React__default.createElement(InfoBox, {
6554
+ header: 'Label Info',
6555
+ content: renderDescription(),
6556
+ visible: props.visible,
6557
+ defaultPos: props.defaultPos,
6558
+ onDismiss: function onDismiss() {
6559
+ return _onDismiss();
6560
+ }
6561
+ });
6562
+ };
6563
+
6564
+ var _extends$a = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6565
+
6566
+ var _createClass$h = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6567
+
6568
+ function _classCallCheck$h(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6569
+
6570
+ function _possibleConstructorReturn$f(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6571
+
6572
+ function _inherits$f(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
6573
+ // import actions from '../../../../actions'
6574
+ // const { siaShowImgBar, siaSetUIConfig } = actions
6575
+
6576
+ var InfoBoxes = function (_Component) {
6577
+ _inherits$f(InfoBoxes, _Component);
6578
+
6579
+ function InfoBoxes(props) {
6580
+ _classCallCheck$h(this, InfoBoxes);
6581
+
6582
+ var _this = _possibleConstructorReturn$f(this, (InfoBoxes.__proto__ || Object.getPrototypeOf(InfoBoxes)).call(this, props));
6583
+
6584
+ _this.state = {
6585
+ position: {
6586
+ top: 0,
6587
+ left: 0
6588
+ }
6589
+ };
6590
+ return _this;
6591
+ }
6592
+
6593
+ _createClass$h(InfoBoxes, [{
6594
+ key: 'componentDidMount',
6595
+ value: function componentDidMount() {
6596
+ this.updateLayout();
6597
+ }
6598
+ }, {
6599
+ key: 'componentDidUpdate',
6600
+ value: function componentDidUpdate(prevProps) {
6601
+
6602
+ if (this.props.layoutUpdate !== prevProps.layoutUpdate) {
6603
+ this.updateLayout();
6604
+ }
6605
+ if (this.props.commentInputTrigger !== prevProps.commentInputTrigger) {
6606
+ if (!this.props.uiConfig.annoDetails.visible) {
6607
+ this.showAnnoDetails(true);
6608
+ }
6609
+ }
6610
+ }
6611
+ }, {
6612
+ key: 'updateLayout',
6613
+ value: function updateLayout() {
6614
+ if (this.props.container.current) {
6615
+ var container = this.props.container.current.getBoundingClientRect();
6616
+ this.setState({
6617
+ position: _extends$a({}, this.state.position, {
6618
+ left: container.right - 250,
6619
+ top: container.top
6620
+ })
6621
+ });
6622
+ }
6623
+ }
6624
+ }, {
6625
+ key: 'showAnnoDetails',
6626
+ value: function showAnnoDetails() {
6627
+ var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6628
+
6629
+ this.props.onUiConfigUpdate(_extends$a({}, this.props.uiConfig, {
6630
+ annoDetails: _extends$a({}, this.props.uiConfig.annoDetails, {
6631
+ visible: show
6632
+ })
6633
+ }));
6634
+ }
6635
+ }, {
6636
+ key: 'onDismiss',
6637
+ value: function onDismiss(type) {
6638
+ if (this.props.onUiConfigUpdate) {
6639
+ switch (type) {
6640
+ case 'AnnoDetails':
6641
+ this.showAnnoDetails(false);
6642
+ break;
6643
+ case 'LabelInfo':
6644
+ this.props.onUiConfigUpdate(_extends$a({}, this.props.uiConfig, {
6645
+ labelInfo: _extends$a({}, this.props.uiConfig.labelInfo, {
6646
+ visible: false
6647
+ })
6648
+ }));
6649
+ break;
6650
+ case 'AnnoStats':
6651
+ this.props.onUiConfigUpdate(_extends$a({}, this.props.uiConfig, {
6652
+ annoStats: _extends$a({}, this.props.uiConfig.annoStats, {
6653
+ visible: false
6654
+ })
6655
+ }));
6656
+ break;
6657
+ default:
6658
+ break;
6659
+ }
6660
+ }
6661
+ }
6662
+ }, {
6663
+ key: 'onCommentUpdate',
6664
+ value: function onCommentUpdate(comment) {
6665
+ if (this.props.onCommentUpdate) {
6666
+ this.props.onCommentUpdate(comment);
6667
+ }
6668
+ }
6669
+ }, {
6670
+ key: 'onMarkExample',
6671
+ value: function onMarkExample(anno) {
6672
+ if (this.props.onMarkExample) {
6673
+ this.props.onMarkExample(anno);
6674
+ }
6675
+ }
6676
+ }, {
6677
+ key: 'onHideLbl',
6678
+ value: function onHideLbl(lbl, hide) {
6679
+ if (this.props.onHideLbl) {
6680
+ this.props.onHideLbl(lbl, hide);
6681
+ }
6682
+ }
6683
+ }, {
6684
+ key: 'render',
6685
+ value: function render() {
6686
+ var _this2 = this;
6687
+
6688
+ if (!this.props.annos) return null;
6689
+ // if (!this.props.selectedAnno) return null
6690
+ return React__default.createElement(
6691
+ 'div',
6692
+ null,
6693
+ React__default.createElement(LabelInfo, { selectedAnno: this.props.selectedAnno,
6694
+ possibleLabels: this.props.possibleLabels,
6695
+ defaultPos: this.state.position,
6696
+ onDismiss: function onDismiss() {
6697
+ return _this2.onDismiss('LabelInfo');
6698
+ },
6699
+ visible: this.props.uiConfig.labelInfo.visible,
6700
+ onGetAnnoExample: function onGetAnnoExample(exampleArgs) {
6701
+ return _this2.props.onGetAnnoExample ? _this2.props.onGetAnnoExample(exampleArgs) : {};
6702
+ },
6703
+ exampleImg: this.props.exampleImg
6704
+ }),
6705
+ React__default.createElement(AnnoDetails, { anno: this.props.selectedAnno,
6706
+ possibleLabels: this.props.possibleLabels,
6707
+ defaultPos: {
6708
+ left: this.state.position.left - 300,
6709
+ top: this.state.position.top
6710
+ },
6711
+ onDismiss: function onDismiss() {
6712
+ return _this2.onDismiss('AnnoDetails');
6713
+ },
6714
+ onCommentUpdate: function onCommentUpdate(comment) {
6715
+ return _this2.onCommentUpdate(comment);
6716
+ },
6717
+ onMarkExample: function onMarkExample(anno) {
6718
+ return _this2.onMarkExample(anno);
6719
+ },
6720
+ allowedToMarkExample: this.props.allowedToMarkExample,
6721
+ commentInputTrigger: this.props.commentInputTrigger,
6722
+ visible: this.props.uiConfig.annoDetails.visible
6723
+ }),
6724
+ React__default.createElement(AnnoStats, { selectedAnno: this.props.selectedAnno,
6725
+ annos: this.props.annos,
6726
+ possibleLabels: this.props.possibleLabels,
6727
+ defaultPos: {
6728
+ left: this.state.position.left,
6729
+ top: this.state.position.top + 400
6730
+ }
6731
+ // defaultPos={this.state.position}
6732
+ , onDismiss: function onDismiss() {
6733
+ return _this2.onDismiss('AnnoStats');
6734
+ },
6735
+ onHideLbl: function onHideLbl(lbl, hide) {
6736
+ return _this2.onHideLbl(lbl, hide);
6737
+ },
6738
+ visible: this.props.uiConfig.annoStats.visible,
6739
+ imgLoadCount: this.props.imgLoadCount
6740
+ })
6741
+ );
6742
+ }
6743
+ }]);
6744
+
6745
+ return InfoBoxes;
6746
+ }(React.Component);
6747
+
6748
+ var _extends$b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6749
+
6750
+ var _createClass$i = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6751
+
6752
+ function _toConsumableArray$5(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
6753
+
6754
+ function _classCallCheck$i(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6755
+
6756
+ function _possibleConstructorReturn$g(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6757
+
6758
+ function _inherits$g(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
6759
+
3758
6760
  /**
3759
6761
  * SIA Canvas element that handles annotations within an image
3760
6762
  *
@@ -3765,11 +6767,11 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3765
6767
  * {
3766
6768
  * image : {
3767
6769
  * id: int,
3768
- * url: string,
3769
6770
  * number: int,
3770
6771
  * amount: int,
3771
6772
  * isFirst: bool,
3772
- * isLast: bool
6773
+ * isLast: bool,
6774
+ * description: string, // -> optional
3773
6775
  * },
3774
6776
  * annotations: {
3775
6777
  * bBoxes: [{
@@ -3792,10 +6794,16 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3792
6794
  * label: str, (name of the label)
3793
6795
  * color: str (color is optional)
3794
6796
  * }
3795
- * @param {object} image - The actual image blob that will be displayed
3796
- * {id: int, data: blob}
6797
+ * @param {blob} imageBlob - The actual image blob that will be displayed
3797
6798
  * @param {object} uiConfig - User interface configs
3798
- * {nodesRadius: int, strokeWidth: int}
6799
+ * {
6800
+ * nodesRadius: int, strokeWidth: int,
6801
+ * layoutOffset: {left:int, top:int, right:int, bottom:int}, -> Offset of the canvas inside the container
6802
+ * imgBarVisible: bool,
6803
+ * imgLabelInputVisible: bool,
6804
+ * centerCanvasInContainer: bool, -> Center the canvas in the middle of the container.
6805
+ * maxCanvas: bool -> Maximize Canvas Size. Do not fit canvas to image size.
6806
+ * }
3799
6807
  * @param {int} layoutUpdate - A counter that triggers a layout update
3800
6808
  * everytime it is incremented.
3801
6809
  * @param {string} selectedTool - The tool that is selected to draw an
@@ -3823,41 +6831,43 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3823
6831
  * actions: {
3824
6832
  * label: bool,
3825
6833
  * }
3826
- * }
6834
+ * },
6835
+ * allowedToMarkExample: bool, -> Indicates wether the current user is allowed to mark an annotation as example.
6836
+ * autoSaveInterval: int -> Interval in seconds when an autosave will be requested by canvas
3827
6837
  * }
3828
- * @param {bool} imgBarVisible - Controls visibility of the ImgBar
3829
- * @param {bool} imgLabelInputVisible - Controls visibility of the ImgLabelInputPrompt
3830
- * @param {object} layoutOffset - Offset of the canvas inside the container:
3831
- * {left:int, top:int, right:int, bottom:int} values in pixels.
3832
- * @param {bool} centerCanvasInContainer - Center the canvas in the
3833
- * middle of the container.
3834
6838
  * @param {str or int} defaultLabel (optional) - Name or ID of the default label that is used
3835
6839
  * when no label was selected by the annotator. If not set "no label" will be used.
3836
6840
  * If ID is used, it needs to be one of the possible label ids.
3837
6841
  * @param {bool} blocked Block canvas view with loading dimmer.
3838
- * @event onSVGUpdate - Fires when the svg in canvas changed.
3839
- * args: {width: int, height: int, scale: float, translateX: float,
3840
- * translateY:float}
3841
- * @event onImageLoaded - Fires when an image was loaded into the canvas
3842
- * @event onAnnoSelect - Fires when an annotation was selected or if the
3843
- * selected annotation was updated.
3844
- * @event onImgBarClose - Fires when close button on ImgBar was hit.
3845
- * @event onImgLabelInputClose - ImgLabelInput requests to be closed.
6842
+ * @param {int} nextAnnoId Id that will be used for the next annotation that
6843
+ * will be created. If undefined, the canvas will create its own ids.
6844
+ * @param {bool} lockedAnnos A list of AnnoIds of annos that should only be displayed.
6845
+ * Such annos can not be edited in any way.
3846
6846
  * @event onNotification - Callback for Notification messages
3847
6847
  * args: {title: str, message: str, type: str}
3848
6848
  * @event onKeyDown - Fires for keyDown on canvas
3849
6849
  * @event onKeyUp - Fires for keyUp on canvas
3850
- * @event onAnnoPerformedAction - Fires when an anno performed an action
3851
- * args: {annoId: int, newAnnos: list of annoObjects, pAction: str}
6850
+ * @event onAnnoEvent - Fires when an anno performed an action
6851
+ * args: {anno: annoObject, newAnnos: list of annoObjects, pAction: str}
6852
+ * @event onCanvasEvent - Fires on canvas event
6853
+ * args: {action: action, data: dataObject}
6854
+ * action -> CANVAS_SVG_UPDATE
6855
+ * data: {width: int, height: int, scale: float, translateX: float,
6856
+ * translateY:float}
6857
+ * action -> CANVAS_UI_CONFIG_UPDATE
6858
+ * action -> CANVAS_LABEL_INPUT_CLOSE
6859
+ * action -> CANVAS_IMG_LOADED
6860
+ * action -> CANVAS_IMGBAR_CLOSE
6861
+ * @event onImgBarClose - Fires when close button on ImgBar was hit.
3852
6862
  */
3853
6863
 
3854
6864
  var Canvas = function (_Component) {
3855
- _inherits$e(Canvas, _Component);
6865
+ _inherits$g(Canvas, _Component);
3856
6866
 
3857
6867
  function Canvas(props) {
3858
- _classCallCheck$g(this, Canvas);
6868
+ _classCallCheck$i(this, Canvas);
3859
6869
 
3860
- var _this = _possibleConstructorReturn$e(this, (Canvas.__proto__ || Object.getPrototypeOf(Canvas)).call(this, props));
6870
+ var _this = _possibleConstructorReturn$g(this, (Canvas.__proto__ || Object.getPrototypeOf(Canvas)).call(this, props));
3861
6871
 
3862
6872
  _this.state = {
3863
6873
 
@@ -3872,6 +6882,10 @@ var Canvas = function (_Component) {
3872
6882
  width: undefined,
3873
6883
  height: undefined
3874
6884
  },
6885
+ imageOffset: {
6886
+ x: 0,
6887
+ y: 0
6888
+ },
3875
6889
  annos: [],
3876
6890
  mode: VIEW,
3877
6891
  // selectedAnnoId: {id:undefined},
@@ -3886,11 +6900,13 @@ var Canvas = function (_Component) {
3886
6900
  imgLoadTimestamp: 0,
3887
6901
  performedImageInit: false,
3888
6902
  prevLabel: [],
3889
- imageData: undefined,
6903
+ imageBlob: undefined,
3890
6904
  isJunk: false,
3891
6905
  imgBarVisible: false,
3892
6906
  annoToolBarVisible: false,
3893
- possibleLabels: undefined
6907
+ possibleLabels: undefined,
6908
+ annoCommentInputTrigger: 0
6909
+ // showAnnoCommentInput: false
3894
6910
  };
3895
6911
  _this.img = React__default.createRef();
3896
6912
  _this.svg = React__default.createRef();
@@ -3901,17 +6917,52 @@ var Canvas = function (_Component) {
3901
6917
  });
3902
6918
  _this.mousePosAbs = undefined;
3903
6919
  _this.clipboard = undefined;
6920
+ _this.autoSaveI = undefined;
3904
6921
  return _this;
3905
6922
  }
3906
6923
 
3907
- _createClass$g(Canvas, [{
6924
+ _createClass$i(Canvas, [{
3908
6925
  key: 'componentDidMount',
3909
6926
  value: function componentDidMount() {
6927
+ var _this2 = this;
6928
+
3910
6929
  this.updatePossibleLabels();
3911
6930
  if (Number.isInteger(this.props.defaultLabel)) {
3912
6931
 
3913
6932
  this.setState({ prevLabel: [this.props.defaultLabel] });
3914
6933
  }
6934
+ if (this.props.canvasConfig.autoSaveInterval) {
6935
+ this.autoSaveI = setInterval(function () {
6936
+ // console.log('AutoSave')
6937
+ // this.props.onAutoSave()
6938
+ _this2.triggerCanvasEvent(CANVAS_AUTO_SAVE);
6939
+ }, this.props.canvasConfig.autoSaveInterval * 1000);
6940
+ }
6941
+ if (this.props.onGetFunction) {
6942
+ this.props.onGetFunction({
6943
+ 'deleteAllAnnos': function deleteAllAnnos() {
6944
+ return _this2.deleteAllAnnos();
6945
+ },
6946
+ 'unloadImage': function unloadImage() {
6947
+ return _this2.unloadImage();
6948
+ },
6949
+ 'resetZoom': function resetZoom() {
6950
+ return _this2.resetZoom();
6951
+ },
6952
+ 'getAnnos': function getAnnos(annos, removeFrontendIds) {
6953
+ return _this2.getAnnos(annos, removeFrontendIds);
6954
+ }
6955
+ });
6956
+ // this.props.onGetFunction(
6957
+ // () => this.deleteAllAnnos()
6958
+ // )
6959
+ }
6960
+ }
6961
+ }, {
6962
+ key: 'componentWillUnmount',
6963
+ value: function componentWillUnmount() {
6964
+ clearInterval(this.autoSaveI);
6965
+ console.log('Cleard auto save interval!');
3915
6966
  }
3916
6967
  }, {
3917
6968
  key: 'componentDidUpdate',
@@ -3919,19 +6970,21 @@ var Canvas = function (_Component) {
3919
6970
  // if (this.props.image.id !== prevProps.image.id){
3920
6971
 
3921
6972
  // }
3922
- if (prevProps.annos !== this.props.annos) {
6973
+ if (prevProps.imageMeta !== this.props.imageMeta) {
3923
6974
  this.setState({
3924
- imgLabelIds: this.props.annos.image.labelIds,
3925
- imgAnnoTime: this.props.annos.image.annoTime,
6975
+ imgLabelIds: this.props.imageMeta.labelIds,
6976
+ imgAnnoTime: this.props.imageMeta.annoTime,
3926
6977
  imgLoadTimestamp: performance.now()
3927
6978
  // isJunk: this.props.annos.image.isJunk
3928
6979
  });
3929
- if (this.state.imageData) {
3930
- this.updateCanvasView(fixBackendAnnos(this.props.annos.annotations));
6980
+ }
6981
+ if (prevProps.annos !== this.props.annos) {
6982
+ if (this.state.imageBlob) {
6983
+ this.updateCanvasView(fixBackendAnnos(this.props.annos));
3931
6984
  }
3932
6985
  // this.setState({
3933
6986
  // imageLoaded: false,
3934
- // // imageData: undefined
6987
+ // // imageBlob: undefined
3935
6988
  // })
3936
6989
  }
3937
6990
  if (prevProps.isJunk !== this.props.isJunk) {
@@ -3941,8 +6994,8 @@ var Canvas = function (_Component) {
3941
6994
  });
3942
6995
  }
3943
6996
  }
3944
- if (this.state.imageData !== this.props.image.data) {
3945
- this.setState({ imageData: this.props.image.data });
6997
+ if (this.state.imageBlob !== this.props.imageBlob) {
6998
+ this.setState({ imageBlob: this.props.imageBlob });
3946
6999
  }
3947
7000
  // if (!this.state.imageLoaded){
3948
7001
  // if(this.props.annos.image.id === this.props.image.id){
@@ -3963,11 +7016,11 @@ var Canvas = function (_Component) {
3963
7016
  performedImageInit: false,
3964
7017
  annoToolBarVisible: false
3965
7018
  });
3966
- if (this.props.imgBarVisible) {
7019
+ if (this.props.uiConfig.imgBarVisible) {
3967
7020
  this.setState({ imgBarVisible: true });
3968
7021
  }
3969
7022
  this.hist.clearHist();
3970
- this.hist.push(_extends$9({}, this.getAnnos(), {
7023
+ this.hist.push(_extends$b({}, this.getAnnos(), {
3971
7024
  selectedAnnoId: undefined
3972
7025
  }), 'init');
3973
7026
  }
@@ -3975,16 +7028,19 @@ var Canvas = function (_Component) {
3975
7028
  // Selected annotation should be on top
3976
7029
  this.putSelectedOnTop(prevState);
3977
7030
  if (prevState.imgLoadCount !== this.state.imgLoadCount) {
3978
- this.updateCanvasView(fixBackendAnnos(this.props.annos.annotations));
3979
- this.setImageLabels(this.props.annos.image.labelIds);
3980
- this.setState({
3981
- performedImageInit: true
3982
- });
7031
+ this.updateCanvasView(fixBackendAnnos(this.props.annos));
7032
+ if (this.props.imageMeta) {
7033
+ this.setImageLabels(this.props.imageMeta.labelIds);
7034
+ this.setState({
7035
+ performedImageInit: true
7036
+ });
7037
+ }
3983
7038
  }
3984
7039
  if (prevProps.layoutUpdate !== this.props.layoutUpdate) {
3985
7040
  this.selectAnnotation(undefined);
3986
7041
  // this.updateCanvasView(this.getAnnoBackendFormat())
3987
- this.updateCanvasView(canvasToBackendAnnos(this.state.annos, this.state.svg));
7042
+ // const {imageOffset} = this.updateImageSize()
7043
+ this.updateCanvasView(canvasToBackendAnnos(this.state.annos, this.state.svg, false, this.state.imageOffset));
3988
7044
  }
3989
7045
  }
3990
7046
  }
@@ -3998,9 +7054,10 @@ var Canvas = function (_Component) {
3998
7054
  showSingleAnno: undefined,
3999
7055
  selectedAnnoId: undefined
4000
7056
  });
4001
- if (this.props.onImageLoaded) {
4002
- this.props.onImageLoaded();
4003
- }
7057
+ this.triggerCanvasEvent(CANVAS_IMG_LOADED);
7058
+ // if (this.props.onImageLoaded){
7059
+ // this.props.onImageLoaded()
7060
+ // }
4004
7061
  }
4005
7062
  }, {
4006
7063
  key: 'onMouseOver',
@@ -4033,7 +7090,7 @@ var Canvas = function (_Component) {
4033
7090
  } else {
4034
7091
  newTranslation = getZoomTranslation(mousePos, this.state.svg, nextScale);
4035
7092
  }
4036
- this.setState({ svg: _extends$9({}, this.state.svg, {
7093
+ this.setState({ svg: _extends$b({}, this.state.svg, {
4037
7094
  scale: nextScale,
4038
7095
  // translateX: -1*(mousePos.x * nextScale - mousePos.x)/nextScale,
4039
7096
  // translateY: -1*(mousePos.y * nextScale - mousePos.y)/nextScale
@@ -4088,6 +7145,24 @@ var Canvas = function (_Component) {
4088
7145
  break;
4089
7146
  }
4090
7147
  }
7148
+
7149
+ // handleAnnoCommentInputClose(comment){
7150
+ // const anno = this.findAnno(this.state.selectedAnnoId)
7151
+ // anno.comment = comment
7152
+ // this.stopAnnotimeMeasure(anno)
7153
+ // this.updateSelectedAnno(anno, modes.VIEW)
7154
+ // console.log('handleAnnoCommentInputClose', comment)
7155
+ // }
7156
+
7157
+ }, {
7158
+ key: 'updateAnnoComment',
7159
+ value: function updateAnnoComment(comment) {
7160
+ var anno = this.findAnno(this.state.selectedAnnoId);
7161
+ anno.comment = comment;
7162
+ this.handleAnnoEvent(anno, ANNO_COMMENT_UPDATE);
7163
+ // this.stopAnnotimeMeasure(anno)
7164
+ // console.log('updateAnnoComment', comment)
7165
+ }
4091
7166
  }, {
4092
7167
  key: 'handleKeyAction',
4093
7168
  value: function handleKeyAction(action) {
@@ -4110,6 +7185,16 @@ var Canvas = function (_Component) {
4110
7185
  case DELETE_ANNO:
4111
7186
  this.deleteAnnotation(anno);
4112
7187
  break;
7188
+ case TOGGLE_ANNO_COMMENT_INPUT:
7189
+ if (this.state.selectedAnnoId) {
7190
+ this.setState({ annoCommentInputTrigger: this.state.annoCommentInputTrigger + 1 });
7191
+ // this.startAnnotimeMeasure(anno)
7192
+ // this.showSingleAnno(this.state.selectedAnnoId)
7193
+ }
7194
+ break;
7195
+ case DELETE_ANNO_IN_CREATION:
7196
+ this.deleteAnnoInCreationMode(anno);
7197
+ break;
4113
7198
  case ENTER_ANNO_ADD_MODE:
4114
7199
  if (anno) {
4115
7200
  this.updateSelectedAnno(anno, ADD);
@@ -4193,6 +7278,20 @@ var Canvas = function (_Component) {
4193
7278
  this.removeSelectedAnno();
4194
7279
  }
4195
7280
 
7281
+ /**
7282
+ * Trigger canvas event
7283
+ * @param {String} action Action that was performed
7284
+ * @param {Object} data Data object of the action
7285
+ */
7286
+
7287
+ }, {
7288
+ key: 'triggerCanvasEvent',
7289
+ value: function triggerCanvasEvent(action, data) {
7290
+ if (this.props.onCanvasEvent) {
7291
+ this.props.onCanvasEvent(action, data);
7292
+ }
7293
+ }
7294
+
4196
7295
  /**
4197
7296
  * Handle actions that have been performed by an annotation
4198
7297
  * @param {Number} anno Id of the annotation
@@ -4200,12 +7299,20 @@ var Canvas = function (_Component) {
4200
7299
  */
4201
7300
 
4202
7301
  }, {
4203
- key: 'onAnnoPerformedAction',
4204
- value: function onAnnoPerformedAction(anno, pAction) {
7302
+ key: 'handleAnnoEvent',
7303
+ value: function handleAnnoEvent(anno, pAction) {
4205
7304
  var newAnnos = undefined;
4206
7305
  switch (pAction) {
7306
+ case ANNO_MARK_EXAMPLE:
7307
+ newAnnos = this.updateSelectedAnno(anno, VIEW);
7308
+ this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
7309
+ break;
4207
7310
  case ANNO_SELECTED:
4208
7311
  this.selectAnnotation(anno.id);
7312
+ // this.pushHist(
7313
+ // this.state.annos, anno.id,
7314
+ // pAction, this.state.showSingleAnno
7315
+ // )
4209
7316
  break;
4210
7317
  case ANNO_START_CREATING:
4211
7318
  newAnnos = this.updateSelectedAnno(anno);
@@ -4262,6 +7369,18 @@ var Canvas = function (_Component) {
4262
7369
  this.showSingleAnno(undefined);
4263
7370
  this.pushHist(newAnnos, undefined, pAction, this.state.showSingleAnno);
4264
7371
  break;
7372
+ case ANNO_COMMENT_UPDATE:
7373
+ newAnnos = this.updateSelectedAnno(anno, VIEW);
7374
+ // newAnnos = this.updateSelectedAnno(anno, modes.DELETED)
7375
+ // this.selectAnnotation(undefined)
7376
+ // this.showSingleAnno(undefined)
7377
+ this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
7378
+ this.handleNotification({
7379
+ title: "Saved comment",
7380
+ message: 'Saved comment: ' + anno.comment,
7381
+ type: SUCCESS
7382
+ });
7383
+ break;
4265
7384
  case ANNO_LABEL_UPDATE:
4266
7385
  anno = this.stopAnnotimeMeasure(anno);
4267
7386
  if (!this.checkAnnoLength(anno)) {
@@ -4288,8 +7407,8 @@ var Canvas = function (_Component) {
4288
7407
  console.warn('Action not handeled', pAction);
4289
7408
  break;
4290
7409
  }
4291
- if (this.props.onAnnoPerformedAction) {
4292
- this.props.onAnnoPerformedAction(anno.id, newAnnos, pAction);
7410
+ if (this.props.onAnnoEvent) {
7411
+ this.props.onAnnoEvent(anno, newAnnos, pAction);
4293
7412
  }
4294
7413
  }
4295
7414
  }, {
@@ -4304,14 +7423,15 @@ var Canvas = function (_Component) {
4304
7423
  this.showLabelInput(false);
4305
7424
  this.showSingleAnno(undefined);
4306
7425
  var anno = this.findAnno(this.state.selectedAnnoId);
4307
- this.onAnnoPerformedAction(anno, ANNO_LABEL_UPDATE);
7426
+ this.handleAnnoEvent(anno, ANNO_LABEL_UPDATE);
4308
7427
  }
4309
7428
  }, {
4310
7429
  key: 'handleImgBarClose',
4311
7430
  value: function handleImgBarClose() {
4312
- if (this.props.onImgBarClose) {
4313
- this.props.onImgBarClose();
4314
- }
7431
+ this.triggerCanvasEvent(CANVAS_IMGBAR_CLOSE);
7432
+ // if (this.props.onImgBarClose){
7433
+ // this.props.onImgBarClose()
7434
+ // }
4315
7435
  }
4316
7436
  }, {
4317
7437
  key: 'handleImgLabelUpdate',
@@ -4325,7 +7445,7 @@ var Canvas = function (_Component) {
4325
7445
  }, {
4326
7446
  key: 'handleCanvasClick',
4327
7447
  value: function handleCanvasClick(e) {
4328
- if (this.props.imgBarVisible) {
7448
+ if (this.props.uiConfig.imgBarVisible) {
4329
7449
  this.setState({ imgBarVisible: true });
4330
7450
  }
4331
7451
  }
@@ -4337,10 +7457,16 @@ var Canvas = function (_Component) {
4337
7457
  }, {
4338
7458
  key: 'handleImgLabelInputClose',
4339
7459
  value: function handleImgLabelInputClose() {
4340
- if (this.props.onImgLabelInputClose) {
4341
- this.props.onImgLabelInputClose();
4342
- }
7460
+ this.triggerCanvasEvent(CANVAS_LABEL_INPUT_CLOSE);
7461
+ // if (this.props.onImgLabelInputClose){
7462
+ // this.props.onImgLabelInputClose()
7463
+ // }
4343
7464
  }
7465
+
7466
+ // handleAnnoCommentInputClose(e){
7467
+ // this.showAnnoCommentInputField(false)
7468
+ // }
7469
+
4344
7470
  }, {
4345
7471
  key: 'handleSvgMouseMove',
4346
7472
  value: function handleSvgMouseMove(e) {
@@ -4353,6 +7479,48 @@ var Canvas = function (_Component) {
4353
7479
  this.props.onNotification(messageObj);
4354
7480
  }
4355
7481
  }
7482
+ }, {
7483
+ key: 'handleHideLbl',
7484
+ value: function handleHideLbl(lbl, hide) {
7485
+ var _this3 = this;
7486
+
7487
+ // console.log('hide lbl', lbl, hide)
7488
+ var hiddenSelected = false;
7489
+ var newAnnos = this.state.annos.map(function (anno) {
7490
+ // console.log('map annos', anno)
7491
+ var newAnno = _extends$b({}, anno);
7492
+ if (anno.labelIds.includes(lbl.id)) {
7493
+ newAnno.visible = !hide;
7494
+ if (anno.id === _this3.state.selectedAnnoId) hiddenSelected = true;
7495
+ } else if (anno.labelIds.length === 0) {
7496
+ // no label case
7497
+ if (lbl.id === -1) {
7498
+ // -1 indicates no label
7499
+ newAnno.visible = !hide;
7500
+ if (anno.id === _this3.state.selectedAnnoId) hiddenSelected = true;
7501
+ }
7502
+ }
7503
+ return newAnno;
7504
+ });
7505
+ // console.log('newAnnos', newAnnos)
7506
+ this.setState({ annos: newAnnos });
7507
+ if (hiddenSelected) {
7508
+ this.selectAnnotation(undefined);
7509
+ }
7510
+ }
7511
+ }, {
7512
+ key: 'handleMarkExample',
7513
+ value: function handleMarkExample(anno) {
7514
+ var newAnno = _extends$b({}, anno);
7515
+ if (newAnno.isExample == undefined) {
7516
+ newAnno.isExample = true;
7517
+ } else if (newAnno.isExample) {
7518
+ newAnno.isExample = false;
7519
+ } else {
7520
+ newAnno.isExample = true;
7521
+ }
7522
+ this.handleAnnoEvent(newAnno, ANNO_MARK_EXAMPLE);
7523
+ }
4356
7524
 
4357
7525
  /*************
4358
7526
  * LOGIC *
@@ -4374,9 +7542,9 @@ var Canvas = function (_Component) {
4374
7542
  var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
4375
7543
 
4376
7544
  if (this.clipboard) {
4377
- var annos = [].concat(_toConsumableArray$4(this.state.annos));
7545
+ var annos = [].concat(_toConsumableArray$5(this.state.annos));
4378
7546
  var uid = _.uniqueId('new');
4379
- annos.push(_extends$9({}, this.clipboard, {
7547
+ annos.push(_extends$b({}, this.clipboard, {
4380
7548
  id: uid,
4381
7549
  annoTime: 0,
4382
7550
  status: NEW,
@@ -4438,13 +7606,15 @@ var Canvas = function (_Component) {
4438
7606
  if (!this.props.possibleLabels) return;
4439
7607
  if (this.props.possibleLabels.length <= 0) return;
4440
7608
  var lbls = this.props.possibleLabels;
4441
- if (!('color' in lbls[0])) {
4442
- lbls = lbls.map(function (e) {
4443
- return _extends$9({}, e, { color: getColor(e.id) });
4444
- });
4445
- }
7609
+ lbls = lbls.map(function (e) {
7610
+ if (!('color' in e)) {
7611
+ return _extends$b({}, e, { color: getColor(e.id) });
7612
+ } else {
7613
+ return _extends$b({}, e);
7614
+ }
7615
+ });
4446
7616
  this.setState({
4447
- possibleLabels: [].concat(_toConsumableArray$4(lbls))
7617
+ possibleLabels: [].concat(_toConsumableArray$5(lbls))
4448
7618
  });
4449
7619
  }
4450
7620
  }, {
@@ -4455,7 +7625,7 @@ var Canvas = function (_Component) {
4455
7625
  if (anno === undefined) {
4456
7626
  myAnno = this.findAnno(this.state.selectedAnnoId);
4457
7627
  } else {
4458
- myAnno = _extends$9({}, anno);
7628
+ myAnno = _extends$b({}, anno);
4459
7629
  }
4460
7630
  myAnno = this.startAnnotimeMeasure(myAnno);
4461
7631
  this.showLabelInput();
@@ -4499,7 +7669,7 @@ var Canvas = function (_Component) {
4499
7669
  value: function pushHist(annos, selectedAnnoId, pAction, showSingleAnno) {
4500
7670
  var imgLabelIds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.state.imgLabelIds;
4501
7671
 
4502
- this.hist.push(_extends$9({}, this.getAnnos(annos, false), {
7672
+ this.hist.push(_extends$b({}, this.getAnnos(annos, false), {
4503
7673
  selectedAnnoId: selectedAnnoId,
4504
7674
  showSingleAnno: showSingleAnno,
4505
7675
  imgLabelIds: imgLabelIds
@@ -4529,7 +7699,18 @@ var Canvas = function (_Component) {
4529
7699
  var ar = this.findAnnoRef(this.state.selectedAnnoId);
4530
7700
  if (ar !== undefined) ar.current.myAnno.current.removeLastNode();
4531
7701
  } else {
4532
- this.onAnnoPerformedAction(anno, ANNO_DELETED);
7702
+ this.handleAnnoEvent(anno, ANNO_DELETED);
7703
+ }
7704
+ }
7705
+ }
7706
+ }, {
7707
+ key: 'deleteAnnoInCreationMode',
7708
+ value: function deleteAnnoInCreationMode(anno) {
7709
+ if (anno) {
7710
+ if (anno.mode === CREATE) {
7711
+ // const ar = this.findAnnoRef(this.state.selectedAnnoId)
7712
+ // if (ar !== undefined) ar.current.myAnno.current.removeLastNode()
7713
+ this.handleAnnoEvent(anno, ANNO_DELETED);
4533
7714
  }
4534
7715
  }
4535
7716
  }
@@ -4539,7 +7720,7 @@ var Canvas = function (_Component) {
4539
7720
  var newAnnos = [];
4540
7721
  this.state.annos.forEach(function (e) {
4541
7722
  if (typeof e.id !== "string") {
4542
- newAnnos.push(_extends$9({}, e, { status: DELETED$1 }));
7723
+ newAnnos.push(_extends$b({}, e, { status: DELETED$1 }));
4543
7724
  }
4544
7725
  });
4545
7726
  this.pushHist(newAnnos, undefined, 'deletedAllAnnos', this.state.showSingleAnno, this.state.imgLabelIds);
@@ -4561,14 +7742,32 @@ var Canvas = function (_Component) {
4561
7742
  }, {
4562
7743
  key: 'setCanvasState',
4563
7744
  value: function setCanvasState(annotations, imgLabelIds, selectedAnnoId, showSingleAnno) {
4564
- this.updateCanvasView(_extends$9({}, annotations));
4565
- this.setImageLabels([].concat(_toConsumableArray$4(imgLabelIds)));
7745
+ this.updateCanvasView(_extends$b({}, annotations));
7746
+ this.setImageLabels([].concat(_toConsumableArray$5(imgLabelIds)));
4566
7747
  this.selectAnnotation(selectedAnnoId);
4567
7748
  this.setState({ showSingleAnno: showSingleAnno });
4568
7749
  }
7750
+ }, {
7751
+ key: 'isLocked',
7752
+ value: function isLocked(annoId) {
7753
+ if (this.props.lockedAnnos) {
7754
+ if (this.props.lockedAnnos.includes(annoId)) {
7755
+ return true;
7756
+ }
7757
+ }
7758
+ return false;
7759
+ }
4569
7760
  }, {
4570
7761
  key: 'selectAnnotation',
4571
7762
  value: function selectAnnotation(annoId) {
7763
+ if (this.isLocked(annoId)) {
7764
+ this.handleNotification({
7765
+ title: "Annotation locked",
7766
+ message: 'Annotation with id ' + annoId + ' is locked and can not be edited',
7767
+ type: WARNING
7768
+ });
7769
+ return;
7770
+ }
4572
7771
  if (annoId) {
4573
7772
  var anno = this.findAnno(annoId);
4574
7773
  this.setState({
@@ -4590,10 +7789,10 @@ var Canvas = function (_Component) {
4590
7789
  this.onAnnoLabelInputClose();
4591
7790
  }
4592
7791
  }
4593
- if (this.props.onAnnoSelect) {
4594
- var _anno = this.findAnno(annoId);
4595
- this.props.onAnnoSelect(_anno);
4596
- }
7792
+ // if(this.props.onAnnoSelect){
7793
+ // const anno = this.findAnno(annoId)
7794
+ // this.props.onAnnoSelect(anno)
7795
+ // }
4597
7796
  }
4598
7797
 
4599
7798
  /**
@@ -4603,18 +7802,18 @@ var Canvas = function (_Component) {
4603
7802
  }, {
4604
7803
  key: 'traverseAnnos',
4605
7804
  value: function traverseAnnos() {
4606
- var _this2 = this;
7805
+ var _this4 = this;
4607
7806
 
4608
7807
  if (this.state.annos.length > 0) {
4609
7808
  var myAnnos = this.state.annos.filter(function (e) {
4610
- return e.status !== DELETED$1;
7809
+ return e.status !== DELETED$1 && !_this4.isLocked(e.id) && !(e.visible === false);
4611
7810
  });
4612
7811
  if (myAnnos.length > 0) {
4613
7812
  if (!this.state.selectedAnnoId) {
4614
7813
  this.selectAnnotation(myAnnos[0].id);
4615
7814
  } else {
4616
7815
  var currentIdx = myAnnos.findIndex(function (e) {
4617
- return e.id === _this2.state.selectedAnnoId;
7816
+ return e.id === _this4.state.selectedAnnoId;
4618
7817
  });
4619
7818
  if (currentIdx + 1 < myAnnos.length) {
4620
7819
  this.selectAnnotation(myAnnos[currentIdx + 1].id);
@@ -4633,14 +7832,14 @@ var Canvas = function (_Component) {
4633
7832
 
4634
7833
  var myAnnos = annos ? annos : this.state.annos;
4635
7834
  // const backendFormat = this.getAnnoBackendFormat(removeFrontedIds, myAnnos)
4636
- var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds);
7835
+ var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds, this.state.imageOffset);
4637
7836
  var finalData = {
4638
- imgId: this.props.annos.image.id,
7837
+ imgId: this.props.imageMeta.id,
4639
7838
  imgLabelIds: this.state.imgLabelIds,
4640
7839
  imgLabelChanged: this.state.imgLabelChanged,
4641
7840
  annotations: backendFormat,
4642
7841
  isJunk: this.state.isJunk,
4643
- annoTime: this.props.annos.image.annoTime + (performance.now() - this.state.imgLoadTimestamp) / 1000
7842
+ annoTime: this.props.imageMeta.annoTime + (performance.now() - this.state.imgLoadTimestamp) / 1000
4644
7843
  };
4645
7844
  return finalData;
4646
7845
  }
@@ -4652,7 +7851,7 @@ var Canvas = function (_Component) {
4652
7851
  }, {
4653
7852
  key: 'resetZoom',
4654
7853
  value: function resetZoom() {
4655
- this.setState({ svg: _extends$9({}, this.state.svg, {
7854
+ this.setState({ svg: _extends$b({}, this.state.svg, {
4656
7855
  translateX: 0,
4657
7856
  translateY: 0,
4658
7857
  scale: 1.0
@@ -4679,7 +7878,7 @@ var Canvas = function (_Component) {
4679
7878
  } else if (vRight.vY <= yXMax) {
4680
7879
  trans_y = this.state.svg.translateY + 5;
4681
7880
  }
4682
- this.setState({ svg: _extends$9({}, this.state.svg, {
7881
+ this.setState({ svg: _extends$b({}, this.state.svg, {
4683
7882
  translateX: trans_x,
4684
7883
  translateY: trans_y
4685
7884
  }) });
@@ -4754,7 +7953,7 @@ var Canvas = function (_Component) {
4754
7953
  var mousePos = this.getMousePosition(e);
4755
7954
  // const selAnno = this.findAnno(this.state.selectedAnnoId)
4756
7955
  var newAnno = {
4757
- id: _.uniqueId('new'),
7956
+ id: this.props.nextAnnoId ? this.props.nextAnnoId : _.uniqueId('new'),
4758
7957
  type: this.props.selectedTool,
4759
7958
  data: [{
4760
7959
  x: mousePos.x,
@@ -4771,7 +7970,7 @@ var Canvas = function (_Component) {
4771
7970
  };
4772
7971
  newAnno = this.startAnnotimeMeasure(newAnno);
4773
7972
  this.setState({
4774
- annos: [].concat(_toConsumableArray$4(this.state.annos), [newAnno]),
7973
+ annos: [].concat(_toConsumableArray$5(this.state.annos), [newAnno]),
4775
7974
  selectedAnnoId: newAnno.id,
4776
7975
  showSingleAnno: newAnno.id,
4777
7976
  annoToolBarVisible: false
@@ -4824,7 +8023,7 @@ var Canvas = function (_Component) {
4824
8023
 
4825
8024
  newAnno = this.startAnnotimeMeasure(newAnno);
4826
8025
  this.setState({
4827
- annos: [].concat(_toConsumableArray$4(this.state.annos), [newAnno]),
8026
+ annos: [].concat(_toConsumableArray$5(this.state.annos), [newAnno]),
4828
8027
  selectedAnnoId: newAnno.id,
4829
8028
  showSingleAnno: newAnno.id,
4830
8029
  annoToolBarVisible: false
@@ -4835,20 +8034,20 @@ var Canvas = function (_Component) {
4835
8034
  }, {
4836
8035
  key: 'putSelectedOnTop',
4837
8036
  value: function putSelectedOnTop(prevState) {
4838
- var _this3 = this;
8037
+ var _this5 = this;
4839
8038
 
4840
8039
  // The selected annotation need to be rendered as last one in
4841
8040
  // oder to be above all other annotations.
4842
8041
  if (this.state.selectedAnnoId) {
4843
8042
  if (prevState.selectedAnnoId !== this.state.selectedAnnoId) {
4844
8043
  var annos = this.state.annos.filter(function (el) {
4845
- return el.id !== _this3.state.selectedAnnoId;
8044
+ return el.id !== _this5.state.selectedAnnoId;
4846
8045
  });
4847
8046
  var lastAnno = this.state.annos.find(function (el) {
4848
- return el.id === _this3.state.selectedAnnoId;
8047
+ return el.id === _this5.state.selectedAnnoId;
4849
8048
  });
4850
8049
  annos.push(lastAnno);
4851
- this.setState({ annos: [].concat(_toConsumableArray$4(annos)) });
8050
+ this.setState({ annos: [].concat(_toConsumableArray$5(annos)) });
4852
8051
  }
4853
8052
  }
4854
8053
  }
@@ -4898,11 +8097,11 @@ var Canvas = function (_Component) {
4898
8097
  selectedAnnoId: anno.id,
4899
8098
  prevLabel: anno.labelIds
4900
8099
  });
4901
- if (this.props.onAnnoSelect) {
4902
- if (newAnno !== null) {
4903
- this.props.onAnnoSelect(newAnno);
4904
- }
4905
- }
8100
+ // if(this.props.onAnnoSelect){
8101
+ // if (newAnno !== null){
8102
+ // this.props.onAnnoSelect(newAnno)
8103
+ // }
8104
+ // }
4906
8105
  return newAnnos;
4907
8106
  }
4908
8107
  }, {
@@ -4915,27 +8114,27 @@ var Canvas = function (_Component) {
4915
8114
  });
4916
8115
  var newAnno = void 0;
4917
8116
  if (mode) {
4918
- newAnno = _extends$9({}, anno, { mode: mode });
8117
+ newAnno = _extends$b({}, anno, { mode: mode });
4919
8118
  if (mode === DELETED) {
4920
8119
  if (anno.status !== NEW) {
4921
- newAnno = _extends$9({}, newAnno, {
8120
+ newAnno = _extends$b({}, newAnno, {
4922
8121
  status: DELETED$1
4923
8122
  });
4924
8123
  } else {
4925
8124
  newAnno = null;
4926
8125
  }
4927
8126
  } else {
4928
- newAnno = _extends$9({}, newAnno, {
8127
+ newAnno = _extends$b({}, newAnno, {
4929
8128
  status: anno.status !== NEW ? CHANGED : NEW
4930
8129
  });
4931
8130
  }
4932
8131
  } else {
4933
- newAnno = _extends$9({}, anno);
8132
+ newAnno = _extends$b({}, anno);
4934
8133
  }
4935
8134
  if (newAnno !== null) {
4936
8135
  filtered.push(newAnno);
4937
8136
  }
4938
- var newAnnos = [].concat(_toConsumableArray$4(filtered));
8137
+ var newAnnos = [].concat(_toConsumableArray$5(filtered));
4939
8138
  return { newAnnos: newAnnos, newAnno: newAnno };
4940
8139
  }
4941
8140
  }, {
@@ -4962,11 +8161,12 @@ var Canvas = function (_Component) {
4962
8161
  var canvasLeft;
4963
8162
  var maxImgHeight;
4964
8163
  var maxImgWidth;
4965
- if (this.props.layoutOffset) {
4966
- canvasTop = container.top + this.props.layoutOffset.top;
4967
- canvasLeft = container.left + this.props.layoutOffset.left;
4968
- maxImgHeight = clientHeight - container.top - this.props.layoutOffset.bottom - this.props.layoutOffset.top;
4969
- maxImgWidth = container.right - canvasLeft - this.props.layoutOffset.right;
8164
+ var layoutOffset = this.props.uiConfig.layoutOffset;
8165
+ if (layoutOffset) {
8166
+ canvasTop = container.top + layoutOffset.top;
8167
+ canvasLeft = container.left + layoutOffset.left;
8168
+ maxImgHeight = clientHeight - container.top - layoutOffset.bottom - layoutOffset.top;
8169
+ maxImgWidth = container.right - canvasLeft - layoutOffset.right;
4970
8170
  } else {
4971
8171
  canvasTop = container.top;
4972
8172
  canvasLeft = container.left;
@@ -4984,35 +8184,48 @@ var Canvas = function (_Component) {
4984
8184
  imgWidth = maxImgHeight * ratio;
4985
8185
  imgHeight = maxImgHeight;
4986
8186
  }
4987
- if (this.props.centerCanvasInContainer) {
4988
- var resSpaceX = maxImgWidth - imgWidth;
4989
- if (resSpaceX > 2) {
4990
- canvasLeft = canvasLeft + resSpaceX / 2;
4991
- }
4992
- var resSpaceY = maxImgHeight - imgHeight;
4993
- if (resSpaceY > 2) {
4994
- canvasTop = canvasTop + resSpaceY / 2;
8187
+ var svg;
8188
+ var imgOffset = { x: 0, y: 0 };
8189
+ if (this.props.uiConfig.maxCanvas) {
8190
+ imgOffset.x = (maxImgWidth - imgWidth) / 2;
8191
+ imgOffset.y = (maxImgHeight - imgHeight) / 2;
8192
+ console.log('imgOffset: ', imgOffset);
8193
+ svg = _extends$b({}, this.state.svg, { width: maxImgWidth, height: maxImgHeight,
8194
+ left: canvasLeft, top: canvasTop
8195
+ });
8196
+ } else {
8197
+ if (this.props.uiConfig.centerCanvasInContainer) {
8198
+ var resSpaceX = maxImgWidth - imgWidth;
8199
+ if (resSpaceX > 2) {
8200
+ canvasLeft = canvasLeft + resSpaceX / 2;
8201
+ }
8202
+ var resSpaceY = maxImgHeight - imgHeight;
8203
+ if (resSpaceY > 2) {
8204
+ canvasTop = canvasTop + resSpaceY / 2;
8205
+ }
4995
8206
  }
8207
+ svg = _extends$b({}, this.state.svg, { width: imgWidth, height: imgHeight,
8208
+ left: canvasLeft, top: canvasTop
8209
+ });
4996
8210
  }
4997
- var svg = _extends$9({}, this.state.svg, { width: imgWidth, height: imgHeight,
4998
- left: canvasLeft, top: canvasTop
4999
- });
5000
8211
  this.setState({
5001
8212
  svg: svg,
5002
8213
  image: {
5003
8214
  width: this.img.current.naturalWidth,
5004
8215
  height: this.img.current.naturalHeight
5005
- }
8216
+ },
8217
+ imageOffset: imgOffset
5006
8218
  });
5007
8219
  this.svgUpdate(svg);
5008
- return { imgWidth: imgWidth, imgHeight: imgHeight };
8220
+ return { imgWidth: imgWidth, imgHeight: imgHeight, imgOffset: imgOffset };
5009
8221
  }
5010
8222
  }, {
5011
8223
  key: 'svgUpdate',
5012
8224
  value: function svgUpdate(svg) {
5013
- if (this.props.onSVGUpdate) {
5014
- this.props.onSVGUpdate(svg);
5015
- }
8225
+ this.triggerCanvasEvent(CANVAS_SVG_UPDATE, svg);
8226
+ // if(this.props.onSVGUpdate){
8227
+ // this.props.onSVGUpdate(svg)
8228
+ // }
5016
8229
  }
5017
8230
  }, {
5018
8231
  key: 'setImageLabels',
@@ -5030,40 +8243,41 @@ var Canvas = function (_Component) {
5030
8243
  //for svg should be calculated
5031
8244
  if (annotations) {
5032
8245
  var imgSize = this.updateImageSize();
5033
- this.setState({ annos: [].concat(_toConsumableArray$4(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }))) });
8246
+ this.setState({ annos: [].concat(_toConsumableArray$5(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }, imgSize.imgOffset))) });
5034
8247
  }
5035
8248
  }
5036
8249
  }, {
5037
8250
  key: 'renderAnnotations',
5038
8251
  value: function renderAnnotations() {
5039
- var _this4 = this;
8252
+ var _this6 = this;
5040
8253
 
5041
8254
  // Do not render annotations while moving the camera!
5042
8255
  if (this.state.mode !== CAMERA_MOVE) {
5043
8256
  this.annoRefs = [];
5044
8257
  var annos = this.state.annos.map(function (el) {
5045
- _this4.annoRefs.push(React__default.createRef());
8258
+ _this6.annoRefs.push(React__default.createRef());
5046
8259
  return React__default.createElement(Annotation$1, { type: el.type,
5047
- data: el, key: el.id, svg: _extends$9({}, _this4.state.svg),
5048
- ref: _this4.annoRefs[_this4.annoRefs.length - 1],
8260
+ data: el, key: el.id, svg: _extends$b({}, _this6.state.svg),
8261
+ imageOffset: _this6.state.imageOffset,
8262
+ ref: _this6.annoRefs[_this6.annoRefs.length - 1],
5049
8263
  onMouseDown: function onMouseDown(e) {
5050
- return _this4.onAnnoMouseDown(e);
8264
+ return _this6.onAnnoMouseDown(e);
5051
8265
  },
5052
8266
  onAction: function onAction(anno, pAction) {
5053
- return _this4.onAnnoPerformedAction(anno, pAction);
8267
+ return _this6.handleAnnoEvent(anno, pAction);
5054
8268
  },
5055
- selectedAnno: _this4.state.selectedAnnoId
8269
+ selectedAnno: _this6.state.selectedAnnoId
5056
8270
  // onModeChange={(anno) => this.onAnnoModeChange(anno)}
5057
- , showSingleAnno: _this4.state.showSingleAnno,
5058
- uiConfig: _this4.props.uiConfig,
5059
- allowedActions: _this4.props.canvasConfig.annos.actions,
5060
- possibleLabels: _this4.state.possibleLabels,
5061
- image: _this4.state.image,
5062
- canvasConfig: _this4.props.canvasConfig,
8271
+ , showSingleAnno: _this6.state.showSingleAnno,
8272
+ uiConfig: _this6.props.uiConfig,
8273
+ allowedActions: _this6.props.canvasConfig.annos.actions,
8274
+ possibleLabels: _this6.state.possibleLabels,
8275
+ image: _this6.state.image,
8276
+ canvasConfig: _this6.props.canvasConfig,
5063
8277
  onNotification: function onNotification(messageObj) {
5064
- return _this4.handleNotification(messageObj);
8278
+ return _this6.handleNotification(messageObj);
5065
8279
  },
5066
- defaultLabel: _this4.props.defaultLabel
8280
+ defaultLabel: _this6.props.defaultLabel
5067
8281
  });
5068
8282
  });
5069
8283
  return React__default.createElement(
@@ -5078,14 +8292,14 @@ var Canvas = function (_Component) {
5078
8292
  }, {
5079
8293
  key: 'renderImgLabelInput',
5080
8294
  value: function renderImgLabelInput() {
5081
- var _this5 = this;
8295
+ var _this7 = this;
5082
8296
 
5083
- if (!this.props.annos.image) return null;
8297
+ if (!this.props.imageMeta) return null;
5084
8298
  return React__default.createElement(Prompt, {
5085
8299
  onClick: function onClick() {
5086
- return _this5.handleImgLabelInputClose();
8300
+ return _this7.handleImgLabelInputClose();
5087
8301
  },
5088
- active: this.props.imgLabelInputVisible,
8302
+ active: this.props.uiConfig.imgLabelInputVisible,
5089
8303
  header: React__default.createElement(
5090
8304
  'div',
5091
8305
  null,
@@ -5100,11 +8314,11 @@ var Canvas = function (_Component) {
5100
8314
  // relatedId={this.props.annos.image.id}
5101
8315
  , visible: true,
5102
8316
  onLabelUpdate: function onLabelUpdate(label) {
5103
- return _this5.handleImgLabelUpdate(label);
8317
+ return _this7.handleImgLabelUpdate(label);
5104
8318
  },
5105
8319
  possibleLabels: this.state.possibleLabels,
5106
8320
  initLabelIds: this.state.imgLabelIds,
5107
- relatedId: this.props.annos.image.id,
8321
+ relatedId: this.props.imageMeta.id,
5108
8322
  defaultLabel: this.props.defaultLabel
5109
8323
  // disabled={!this.props.allowedActions.label}
5110
8324
  // renderPopup
@@ -5113,7 +8327,7 @@ var Canvas = function (_Component) {
5113
8327
  semanticUiReact.Button,
5114
8328
  { basic: true, color: 'green', inverted: true,
5115
8329
  onClick: function onClick() {
5116
- return _this5.handleImgLabelInputClose();
8330
+ return _this7.handleImgLabelInputClose();
5117
8331
  }
5118
8332
  },
5119
8333
  React__default.createElement(semanticUiReact.Icon, { name: 'check' }),
@@ -5125,7 +8339,7 @@ var Canvas = function (_Component) {
5125
8339
  }, {
5126
8340
  key: 'renderAnnoToolBar',
5127
8341
  value: function renderAnnoToolBar(selectedAnno) {
5128
- var _this6 = this;
8342
+ var _this8 = this;
5129
8343
 
5130
8344
  var visible = this.state.annoToolBarVisible;
5131
8345
  if (this.state.mode === CAMERA_MOVE) visible = false;
@@ -5133,7 +8347,7 @@ var Canvas = function (_Component) {
5133
8347
  selectedAnno: selectedAnno,
5134
8348
  svg: this.state.svg,
5135
8349
  onClick: function onClick() {
5136
- return _this6.editAnnoLabel();
8350
+ return _this8.editAnnoLabel();
5137
8351
  },
5138
8352
  color: this.getAnnoColor()
5139
8353
  });
@@ -5141,22 +8355,22 @@ var Canvas = function (_Component) {
5141
8355
  }, {
5142
8356
  key: 'renderAnnoLabelInpput',
5143
8357
  value: function renderAnnoLabelInpput(selectedAnno) {
5144
- var _this7 = this;
8358
+ var _this9 = this;
5145
8359
 
5146
8360
  var visible = this.state.showLabelInput;
5147
8361
  if (this.state.mode === CAMERA_MOVE) visible = false;
5148
8362
  return React__default.createElement(AnnoLabelInput, { svg: this.state.svg
5149
8363
  // svgRef={this.svg}
5150
8364
  , onClose: function onClose() {
5151
- return _this7.onAnnoLabelInputClose();
8365
+ return _this9.onAnnoLabelInputClose();
5152
8366
  },
5153
8367
  onDeleteClick: function onDeleteClick(annoId) {
5154
- return _this7.onLabelInputDeleteClick(annoId);
8368
+ return _this9.onLabelInputDeleteClick(annoId);
5155
8369
  },
5156
8370
  selectedAnno: selectedAnno,
5157
8371
  visible: visible,
5158
8372
  onLabelUpdate: function onLabelUpdate(anno) {
5159
- return _this7.onAnnoLabelInputUpdate(anno);
8373
+ return _this9.onAnnoLabelInputUpdate(anno);
5160
8374
  },
5161
8375
  possibleLabels: this.state.possibleLabels,
5162
8376
  allowedActions: this.props.canvasConfig.annos.actions,
@@ -5166,10 +8380,19 @@ var Canvas = function (_Component) {
5166
8380
  // multilabels={true}
5167
8381
  });
5168
8382
  }
8383
+
8384
+ // renderAnnoCommentInput(selectedAnno){
8385
+ // return <AnnoCommentInput
8386
+ // triggerInput={this.state.annoCommentInputTrigger}
8387
+ // onClose={comment => this.handleAnnoCommentInputClose(comment)}
8388
+ // iniComment={selectedAnno ? selectedAnno.comment : ''}
8389
+ // />
8390
+ // }
8391
+
5169
8392
  }, {
5170
8393
  key: 'render',
5171
8394
  value: function render() {
5172
- var _this8 = this;
8395
+ var _this10 = this;
5173
8396
 
5174
8397
  var selectedAnno = this.findAnno(this.state.selectedAnnoId);
5175
8398
  return React__default.createElement(
@@ -5186,8 +8409,9 @@ var Canvas = function (_Component) {
5186
8409
  possibleLabels: this.state.possibleLabels,
5187
8410
  annos: this.props.annos,
5188
8411
  svg: this.state.svg,
8412
+ imageMeta: this.props.imageMeta,
5189
8413
  onClose: function onClose() {
5190
- return _this8.handleImgBarClose();
8414
+ return _this10.handleImgBarClose();
5191
8415
  },
5192
8416
  imgLabelIds: this.state.imgLabelIds
5193
8417
  // onLabelUpdate={label => this.handleImgLabelUpdate(label)}
@@ -5195,7 +8419,7 @@ var Canvas = function (_Component) {
5195
8419
  // multilabels={this.props.canvasConfig.img.multilabels}
5196
8420
  // allowedActions={this.props.canvasConfig.img.actions}
5197
8421
  , onMouseEnter: function onMouseEnter(e) {
5198
- return _this8.handleImgBarMouseEnter(e);
8422
+ return _this10.handleImgBarMouseEnter(e);
5199
8423
  }
5200
8424
  }),
5201
8425
  React__default.createElement(
@@ -5219,21 +8443,47 @@ var Canvas = function (_Component) {
5219
8443
  ),
5220
8444
  this.renderAnnoToolBar(selectedAnno),
5221
8445
  this.renderAnnoLabelInpput(selectedAnno),
8446
+ React__default.createElement(InfoBoxes, { container: this.props.container,
8447
+ layoutUpdate: this.props.layoutUpdate,
8448
+ annos: this.state.annos,
8449
+ selectedAnno: selectedAnno,
8450
+ possibleLabels: this.state.possibleLabels,
8451
+ allowedToMarkExample: this.props.canvasConfig.allowedToMarkExample,
8452
+ uiConfig: this.props.uiConfig,
8453
+ imgLoadCount: this.state.imgLoadCount,
8454
+ onCommentUpdate: function onCommentUpdate(comment) {
8455
+ return _this10.updateAnnoComment(comment);
8456
+ },
8457
+ onUiConfigUpdate: function onUiConfigUpdate(e) {
8458
+ return _this10.triggerCanvasEvent(CANVAS_UI_CONFIG_UPDATE, e);
8459
+ },
8460
+ onHideLbl: function onHideLbl(lbl, hide) {
8461
+ return _this10.handleHideLbl(lbl, hide);
8462
+ },
8463
+ onMarkExample: function onMarkExample(anno) {
8464
+ return _this10.handleMarkExample(anno);
8465
+ },
8466
+ commentInputTrigger: this.state.annoCommentInputTrigger,
8467
+ onGetAnnoExample: function onGetAnnoExample(exampleArgs) {
8468
+ return _this10.props.onGetAnnoExample ? _this10.props.onGetAnnoExample(exampleArgs) : {};
8469
+ },
8470
+ exampleImg: this.props.exampleImg
8471
+ }),
5222
8472
  React__default.createElement(
5223
8473
  'svg',
5224
8474
  { ref: this.svg, width: this.state.svg.width,
5225
8475
  height: this.state.svg.height,
5226
8476
  onKeyDown: function onKeyDown(e) {
5227
- return _this8.onKeyDown(e);
8477
+ return _this10.onKeyDown(e);
5228
8478
  },
5229
8479
  onKeyUp: function onKeyUp(e) {
5230
- return _this8.onKeyUp(e);
8480
+ return _this10.onKeyUp(e);
5231
8481
  },
5232
8482
  onClick: function onClick(e) {
5233
- return _this8.handleCanvasClick(e);
8483
+ return _this10.handleCanvasClick(e);
5234
8484
  },
5235
8485
  onMouseMove: function onMouseMove(e) {
5236
- return _this8.handleSvgMouseMove(e);
8486
+ return _this10.handleSvgMouseMove(e);
5237
8487
  },
5238
8488
  tabIndex: '0'
5239
8489
  },
@@ -5242,26 +8492,27 @@ var Canvas = function (_Component) {
5242
8492
  {
5243
8493
  transform: 'scale(' + this.state.svg.scale + ') translate(' + this.state.svg.translateX + ', ' + this.state.svg.translateY + ')',
5244
8494
  onMouseOver: function onMouseOver() {
5245
- _this8.onMouseOver();
5246
- },
5247
- onMouseUp: function onMouseUp(e) {
5248
- _this8.onMouseUp(e);
8495
+ _this10.onMouseOver();
8496
+ }
8497
+ // onMouseEnter={() => this.svg.current.focus()}
8498
+ , onMouseUp: function onMouseUp(e) {
8499
+ _this10.onMouseUp(e);
5249
8500
  },
5250
8501
  onWheel: function onWheel(e) {
5251
- return _this8.onWheel(e);
8502
+ return _this10.onWheel(e);
5252
8503
  },
5253
8504
  onMouseMove: function onMouseMove(e) {
5254
- _this8.onMouseMove(e);
8505
+ _this10.onMouseMove(e);
5255
8506
  }
5256
8507
  },
5257
8508
  React__default.createElement('image', {
5258
8509
  onContextMenu: function onContextMenu(e) {
5259
- return _this8.onRightClick(e);
8510
+ return _this10.onRightClick(e);
5260
8511
  },
5261
8512
  onMouseDown: function onMouseDown(e) {
5262
- return _this8.onMouseDown(e);
8513
+ return _this10.onMouseDown(e);
5263
8514
  },
5264
- href: this.props.image.data,
8515
+ href: this.props.imageBlob,
5265
8516
  width: this.state.svg.width,
5266
8517
  height: this.state.svg.height
5267
8518
  }),
@@ -5271,8 +8522,8 @@ var Canvas = function (_Component) {
5271
8522
  React__default.createElement('img', {
5272
8523
  alt: 'sia', style: { display: 'none' }, ref: this.img,
5273
8524
  onLoad: function onLoad() {
5274
- _this8.onImageLoad();
5275
- }, src: this.state.imageData,
8525
+ _this10.onImageLoad();
8526
+ }, src: this.state.imageBlob,
5276
8527
  width: '100%', height: '100%'
5277
8528
  })
5278
8529
  ),