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