lost-sia 0.9.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,6 +1,7 @@
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
 
@@ -194,20 +195,23 @@ function getTopPoint(data) {
194
195
  * correct the annotation
195
196
  * @param {object} data
196
197
  * @param {object} image
198
+ * @param {object} imageOffset
197
199
  */
198
- 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;
199
203
  var corrected = data.map(function (el) {
200
204
  var x = el.x;
201
205
  var y = el.y;
202
- if (el.x <= 0) {
203
- x = 0;
204
- } else if (el.x > image.width) {
205
- 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;
206
210
  }
207
- if (el.y < 0) {
208
- y = 0;
209
- } else if (el.y > image.height) {
210
- 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;
211
215
  }
212
216
  return { x: x, y: y };
213
217
  });
@@ -519,7 +523,7 @@ function styleInject(css, ref) {
519
523
  }
520
524
  }
521
525
 
522
- 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";
523
527
  styleInject(css);
524
528
 
525
529
  var CREATE_NODE = "crosshair";
@@ -872,6 +876,15 @@ var ANNO_LABEL_UPDATE = 'annoLabelUpdate';
872
876
  var ANNO_CREATED_NODE = 'annoCreatedNode';
873
877
  var ANNO_CREATED_FINAL_NODE = 'annoCreatedFinalNode';
874
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';
875
888
 
876
889
  //Image actions
877
890
  var IMG_LABEL_UPDATE = 'imgLabelUpdate';
@@ -2263,6 +2276,15 @@ var Annotation$1 = function (_Component) {
2263
2276
  }
2264
2277
  }
2265
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
+ }
2266
2288
  }
2267
2289
 
2268
2290
  /*************
@@ -2340,7 +2362,7 @@ var Annotation$1 = function (_Component) {
2340
2362
  case ANNO_MOVED:
2341
2363
  case ANNO_CREATED:
2342
2364
  // Check if annoation is within image bounds
2343
- var corrected = correctAnnotation(anno.data, this.props.svg);
2365
+ var corrected = correctAnnotation(anno.data, this.props.svg, this.props.imageOffset);
2344
2366
  var newAnno = _extends$5({}, anno, { data: corrected });
2345
2367
  var area = getArea(corrected, this.props.svg, anno.type, this.props.image);
2346
2368
  if (area !== undefined) {
@@ -3160,11 +3182,11 @@ var ImgBar = function (_Component) {
3160
3182
  }, {
3161
3183
  key: 'renderImgDescription',
3162
3184
  value: function renderImgDescription() {
3163
- if (this.props.annos.image.description) {
3185
+ if (this.props.imageMeta.description) {
3164
3186
  return React.createElement(
3165
3187
  Menu.Item,
3166
3188
  null,
3167
- this.props.annos.image.description
3189
+ this.props.imageMeta.description
3168
3190
  );
3169
3191
  } else {
3170
3192
  return null;
@@ -3176,7 +3198,7 @@ var ImgBar = function (_Component) {
3176
3198
  var _this3 = this;
3177
3199
 
3178
3200
  if (!this.props.visible) return null;
3179
- if (!this.props.annos.image) return null;
3201
+ if (!this.props.imageMeta) return null;
3180
3202
  // if (!this.props.annos.image.url) return null
3181
3203
  return React.createElement(
3182
3204
  'div',
@@ -3198,12 +3220,12 @@ var ImgBar = function (_Component) {
3198
3220
  React.createElement(
3199
3221
  Menu.Item,
3200
3222
  null,
3201
- "ID: " + this.props.annos.image.id
3223
+ "ID: " + this.props.imageMeta.id
3202
3224
  ),
3203
3225
  React.createElement(
3204
3226
  Menu.Item,
3205
3227
  null,
3206
- this.props.annos.image.number + " / " + this.props.annos.image.amount
3228
+ this.props.imageMeta.number + " / " + this.props.imageMeta.amount
3207
3229
  ),
3208
3230
  this.renderImgLabels()
3209
3231
  )
@@ -3264,7 +3286,7 @@ var Prompt = function (_Component) {
3264
3286
  Dimmer,
3265
3287
  { page: true,
3266
3288
  active: this.state.active,
3267
- style: { zIndex: 2000 },
3289
+ style: { zIndex: 7000 },
3268
3290
  onClick: function onClick(e) {
3269
3291
  return _this2.handleClick(e);
3270
3292
  }
@@ -3536,6 +3558,7 @@ var COPY_ANNOTATION = 'copyAnnotation';
3536
3558
  var PASTE_ANNOTATION = 'pasteAnnotation';
3537
3559
  var RECREATE_ANNO = 'recreateAnnotation';
3538
3560
  var DELETE_ANNO_IN_CREATION = 'deleteAnnoInCreation';
3561
+ var TOGGLE_ANNO_COMMENT_INPUT = 'toggleAnnoCommentInput';
3539
3562
 
3540
3563
  var KeyMapper = function () {
3541
3564
  function KeyMapper() {
@@ -3595,6 +3618,8 @@ var KeyMapper = function () {
3595
3618
  case 'c':
3596
3619
  if (this.controlDown) {
3597
3620
  this.triggerKeyAction(COPY_ANNOTATION);
3621
+ } else {
3622
+ this.triggerKeyAction(TOGGLE_ANNO_COMMENT_INPUT);
3598
3623
  }
3599
3624
  break;
3600
3625
  case 'v':
@@ -3758,21 +3783,2975 @@ function getZoomTranslation(w0, svg, s1) {
3758
3783
  return translation;
3759
3784
  }
3760
3785
 
3761
- 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";
3762
3787
  styleInject(css$1);
3763
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
+
3764
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; };
3765
5962
 
3766
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; }; }();
3767
5964
 
3768
- 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); } }
3769
-
3770
5965
  function _classCallCheck$g(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3771
5966
 
3772
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; }
3773
5968
 
3774
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; }
3775
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
+
3776
6755
  /**
3777
6756
  * SIA Canvas element that handles annotations within an image
3778
6757
  *
@@ -3810,10 +6789,16 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3810
6789
  * label: str, (name of the label)
3811
6790
  * color: str (color is optional)
3812
6791
  * }
3813
- * @param {object} image - The actual image blob that will be displayed
3814
- * {id: int, data: blob}
6792
+ * @param {blob} imageBlob - The actual image blob that will be displayed
3815
6793
  * @param {object} uiConfig - User interface configs
3816
- * {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
+ * }
3817
6802
  * @param {int} layoutUpdate - A counter that triggers a layout update
3818
6803
  * everytime it is incremented.
3819
6804
  * @param {string} selectedTool - The tool that is selected to draw an
@@ -3841,44 +6826,43 @@ function _inherits$e(subClass, superClass) { if (typeof superClass !== "function
3841
6826
  * actions: {
3842
6827
  * label: bool,
3843
6828
  * }
3844
- * }
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
3845
6832
  * }
3846
- * @param {bool} imgBarVisible - Controls visibility of the ImgBar
3847
- * @param {bool} imgLabelInputVisible - Controls visibility of the ImgLabelInputPrompt
3848
- * @param {object} layoutOffset - Offset of the canvas inside the container:
3849
- * {left:int, top:int, right:int, bottom:int} values in pixels.
3850
- * @param {bool} centerCanvasInContainer - Center the canvas in the
3851
- * middle of the container.
3852
- * @param {bool} maxCanvas - Maximize Canvas Size. Do not fit canvas to image size
3853
6833
  * @param {str or int} defaultLabel (optional) - Name or ID of the default label that is used
3854
6834
  * when no label was selected by the annotator. If not set "no label" will be used.
3855
6835
  * If ID is used, it needs to be one of the possible label ids.
3856
6836
  * @param {bool} blocked Block canvas view with loading dimmer.
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.
3857
6839
  * @param {bool} lockedAnnos A list of AnnoIds of annos that should only be displayed.
3858
6840
  * Such annos can not be edited in any way.
3859
- * @event onSVGUpdate - Fires when the svg in canvas changed.
3860
- * args: {width: int, height: int, scale: float, translateX: float,
3861
- * translateY:float}
3862
- * @event onImageLoaded - Fires when an image was loaded into the canvas
3863
- * @event onAnnoSelect - Fires when an annotation was selected or if the
3864
- * selected annotation was updated.
3865
- * @event onImgBarClose - Fires when close button on ImgBar was hit.
3866
- * @event onImgLabelInputClose - ImgLabelInput requests to be closed.
3867
6841
  * @event onNotification - Callback for Notification messages
3868
6842
  * args: {title: str, message: str, type: str}
3869
6843
  * @event onKeyDown - Fires for keyDown on canvas
3870
6844
  * @event onKeyUp - Fires for keyUp on canvas
3871
- * @event onAnnoPerformedAction - Fires when an anno performed an action
3872
- * 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.
3873
6857
  */
3874
6858
 
3875
6859
  var Canvas = function (_Component) {
3876
- _inherits$e(Canvas, _Component);
6860
+ _inherits$g(Canvas, _Component);
3877
6861
 
3878
6862
  function Canvas(props) {
3879
- _classCallCheck$g(this, Canvas);
6863
+ _classCallCheck$i(this, Canvas);
3880
6864
 
3881
- 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));
3882
6866
 
3883
6867
  _this.state = {
3884
6868
 
@@ -3911,11 +6895,13 @@ var Canvas = function (_Component) {
3911
6895
  imgLoadTimestamp: 0,
3912
6896
  performedImageInit: false,
3913
6897
  prevLabel: [],
3914
- imageData: undefined,
6898
+ imageBlob: undefined,
3915
6899
  isJunk: false,
3916
6900
  imgBarVisible: false,
3917
6901
  annoToolBarVisible: false,
3918
- possibleLabels: undefined
6902
+ possibleLabels: undefined,
6903
+ annoCommentInputTrigger: 0
6904
+ // showAnnoCommentInput: false
3919
6905
  };
3920
6906
  _this.img = React.createRef();
3921
6907
  _this.svg = React.createRef();
@@ -3926,17 +6912,52 @@ var Canvas = function (_Component) {
3926
6912
  });
3927
6913
  _this.mousePosAbs = undefined;
3928
6914
  _this.clipboard = undefined;
6915
+ _this.autoSaveI = undefined;
3929
6916
  return _this;
3930
6917
  }
3931
6918
 
3932
- _createClass$g(Canvas, [{
6919
+ _createClass$i(Canvas, [{
3933
6920
  key: 'componentDidMount',
3934
6921
  value: function componentDidMount() {
6922
+ var _this2 = this;
6923
+
3935
6924
  this.updatePossibleLabels();
3936
6925
  if (Number.isInteger(this.props.defaultLabel)) {
3937
6926
 
3938
6927
  this.setState({ prevLabel: [this.props.defaultLabel] });
3939
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!');
3940
6961
  }
3941
6962
  }, {
3942
6963
  key: 'componentDidUpdate',
@@ -3944,19 +6965,21 @@ var Canvas = function (_Component) {
3944
6965
  // if (this.props.image.id !== prevProps.image.id){
3945
6966
 
3946
6967
  // }
3947
- if (prevProps.annos !== this.props.annos) {
6968
+ if (prevProps.imageMeta !== this.props.imageMeta) {
3948
6969
  this.setState({
3949
- imgLabelIds: this.props.annos.image.labelIds,
3950
- imgAnnoTime: this.props.annos.image.annoTime,
6970
+ imgLabelIds: this.props.imageMeta.labelIds,
6971
+ imgAnnoTime: this.props.imageMeta.annoTime,
3951
6972
  imgLoadTimestamp: performance.now()
3952
6973
  // isJunk: this.props.annos.image.isJunk
3953
6974
  });
3954
- if (this.state.imageData) {
3955
- 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));
3956
6979
  }
3957
6980
  // this.setState({
3958
6981
  // imageLoaded: false,
3959
- // // imageData: undefined
6982
+ // // imageBlob: undefined
3960
6983
  // })
3961
6984
  }
3962
6985
  if (prevProps.isJunk !== this.props.isJunk) {
@@ -3966,8 +6989,8 @@ var Canvas = function (_Component) {
3966
6989
  });
3967
6990
  }
3968
6991
  }
3969
- if (this.state.imageData !== this.props.image.data) {
3970
- this.setState({ imageData: this.props.image.data });
6992
+ if (this.state.imageBlob !== this.props.imageBlob) {
6993
+ this.setState({ imageBlob: this.props.imageBlob });
3971
6994
  }
3972
6995
  // if (!this.state.imageLoaded){
3973
6996
  // if(this.props.annos.image.id === this.props.image.id){
@@ -3988,11 +7011,11 @@ var Canvas = function (_Component) {
3988
7011
  performedImageInit: false,
3989
7012
  annoToolBarVisible: false
3990
7013
  });
3991
- if (this.props.imgBarVisible) {
7014
+ if (this.props.uiConfig.imgBarVisible) {
3992
7015
  this.setState({ imgBarVisible: true });
3993
7016
  }
3994
7017
  this.hist.clearHist();
3995
- this.hist.push(_extends$9({}, this.getAnnos(), {
7018
+ this.hist.push(_extends$b({}, this.getAnnos(), {
3996
7019
  selectedAnnoId: undefined
3997
7020
  }), 'init');
3998
7021
  }
@@ -4000,11 +7023,13 @@ var Canvas = function (_Component) {
4000
7023
  // Selected annotation should be on top
4001
7024
  this.putSelectedOnTop(prevState);
4002
7025
  if (prevState.imgLoadCount !== this.state.imgLoadCount) {
4003
- this.updateCanvasView(fixBackendAnnos(this.props.annos.annotations));
4004
- this.setImageLabels(this.props.annos.image.labelIds);
4005
- this.setState({
4006
- performedImageInit: true
4007
- });
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
+ }
4008
7033
  }
4009
7034
  if (prevProps.layoutUpdate !== this.props.layoutUpdate) {
4010
7035
  this.selectAnnotation(undefined);
@@ -4024,9 +7049,10 @@ var Canvas = function (_Component) {
4024
7049
  showSingleAnno: undefined,
4025
7050
  selectedAnnoId: undefined
4026
7051
  });
4027
- if (this.props.onImageLoaded) {
4028
- this.props.onImageLoaded();
4029
- }
7052
+ this.triggerCanvasEvent(CANVAS_IMG_LOADED);
7053
+ // if (this.props.onImageLoaded){
7054
+ // this.props.onImageLoaded()
7055
+ // }
4030
7056
  }
4031
7057
  }, {
4032
7058
  key: 'onMouseOver',
@@ -4059,7 +7085,7 @@ var Canvas = function (_Component) {
4059
7085
  } else {
4060
7086
  newTranslation = getZoomTranslation(mousePos, this.state.svg, nextScale);
4061
7087
  }
4062
- this.setState({ svg: _extends$9({}, this.state.svg, {
7088
+ this.setState({ svg: _extends$b({}, this.state.svg, {
4063
7089
  scale: nextScale,
4064
7090
  // translateX: -1*(mousePos.x * nextScale - mousePos.x)/nextScale,
4065
7091
  // translateY: -1*(mousePos.y * nextScale - mousePos.y)/nextScale
@@ -4114,6 +7140,24 @@ var Canvas = function (_Component) {
4114
7140
  break;
4115
7141
  }
4116
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
+ }
4117
7161
  }, {
4118
7162
  key: 'handleKeyAction',
4119
7163
  value: function handleKeyAction(action) {
@@ -4136,6 +7180,13 @@ var Canvas = function (_Component) {
4136
7180
  case DELETE_ANNO:
4137
7181
  this.deleteAnnotation(anno);
4138
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;
4139
7190
  case DELETE_ANNO_IN_CREATION:
4140
7191
  this.deleteAnnoInCreationMode(anno);
4141
7192
  break;
@@ -4222,6 +7273,20 @@ var Canvas = function (_Component) {
4222
7273
  this.removeSelectedAnno();
4223
7274
  }
4224
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
+
4225
7290
  /**
4226
7291
  * Handle actions that have been performed by an annotation
4227
7292
  * @param {Number} anno Id of the annotation
@@ -4229,12 +7294,20 @@ var Canvas = function (_Component) {
4229
7294
  */
4230
7295
 
4231
7296
  }, {
4232
- key: 'onAnnoPerformedAction',
4233
- value: function onAnnoPerformedAction(anno, pAction) {
7297
+ key: 'handleAnnoEvent',
7298
+ value: function handleAnnoEvent(anno, pAction) {
4234
7299
  var newAnnos = undefined;
4235
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;
4236
7305
  case ANNO_SELECTED:
4237
7306
  this.selectAnnotation(anno.id);
7307
+ // this.pushHist(
7308
+ // this.state.annos, anno.id,
7309
+ // pAction, this.state.showSingleAnno
7310
+ // )
4238
7311
  break;
4239
7312
  case ANNO_START_CREATING:
4240
7313
  newAnnos = this.updateSelectedAnno(anno);
@@ -4291,6 +7364,18 @@ var Canvas = function (_Component) {
4291
7364
  this.showSingleAnno(undefined);
4292
7365
  this.pushHist(newAnnos, undefined, pAction, this.state.showSingleAnno);
4293
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;
4294
7379
  case ANNO_LABEL_UPDATE:
4295
7380
  anno = this.stopAnnotimeMeasure(anno);
4296
7381
  if (!this.checkAnnoLength(anno)) {
@@ -4317,8 +7402,8 @@ var Canvas = function (_Component) {
4317
7402
  console.warn('Action not handeled', pAction);
4318
7403
  break;
4319
7404
  }
4320
- if (this.props.onAnnoPerformedAction) {
4321
- this.props.onAnnoPerformedAction(anno.id, newAnnos, pAction);
7405
+ if (this.props.onAnnoEvent) {
7406
+ this.props.onAnnoEvent(anno, newAnnos, pAction);
4322
7407
  }
4323
7408
  }
4324
7409
  }, {
@@ -4333,14 +7418,15 @@ var Canvas = function (_Component) {
4333
7418
  this.showLabelInput(false);
4334
7419
  this.showSingleAnno(undefined);
4335
7420
  var anno = this.findAnno(this.state.selectedAnnoId);
4336
- this.onAnnoPerformedAction(anno, ANNO_LABEL_UPDATE);
7421
+ this.handleAnnoEvent(anno, ANNO_LABEL_UPDATE);
4337
7422
  }
4338
7423
  }, {
4339
7424
  key: 'handleImgBarClose',
4340
7425
  value: function handleImgBarClose() {
4341
- if (this.props.onImgBarClose) {
4342
- this.props.onImgBarClose();
4343
- }
7426
+ this.triggerCanvasEvent(CANVAS_IMGBAR_CLOSE);
7427
+ // if (this.props.onImgBarClose){
7428
+ // this.props.onImgBarClose()
7429
+ // }
4344
7430
  }
4345
7431
  }, {
4346
7432
  key: 'handleImgLabelUpdate',
@@ -4354,7 +7440,7 @@ var Canvas = function (_Component) {
4354
7440
  }, {
4355
7441
  key: 'handleCanvasClick',
4356
7442
  value: function handleCanvasClick(e) {
4357
- if (this.props.imgBarVisible) {
7443
+ if (this.props.uiConfig.imgBarVisible) {
4358
7444
  this.setState({ imgBarVisible: true });
4359
7445
  }
4360
7446
  }
@@ -4366,10 +7452,16 @@ var Canvas = function (_Component) {
4366
7452
  }, {
4367
7453
  key: 'handleImgLabelInputClose',
4368
7454
  value: function handleImgLabelInputClose() {
4369
- if (this.props.onImgLabelInputClose) {
4370
- this.props.onImgLabelInputClose();
4371
- }
7455
+ this.triggerCanvasEvent(CANVAS_LABEL_INPUT_CLOSE);
7456
+ // if (this.props.onImgLabelInputClose){
7457
+ // this.props.onImgLabelInputClose()
7458
+ // }
4372
7459
  }
7460
+
7461
+ // handleAnnoCommentInputClose(e){
7462
+ // this.showAnnoCommentInputField(false)
7463
+ // }
7464
+
4373
7465
  }, {
4374
7466
  key: 'handleSvgMouseMove',
4375
7467
  value: function handleSvgMouseMove(e) {
@@ -4382,6 +7474,48 @@ var Canvas = function (_Component) {
4382
7474
  this.props.onNotification(messageObj);
4383
7475
  }
4384
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
+ }
4385
7519
 
4386
7520
  /*************
4387
7521
  * LOGIC *
@@ -4403,9 +7537,9 @@ var Canvas = function (_Component) {
4403
7537
  var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
4404
7538
 
4405
7539
  if (this.clipboard) {
4406
- var annos = [].concat(_toConsumableArray$4(this.state.annos));
7540
+ var annos = [].concat(_toConsumableArray$5(this.state.annos));
4407
7541
  var uid = _.uniqueId('new');
4408
- annos.push(_extends$9({}, this.clipboard, {
7542
+ annos.push(_extends$b({}, this.clipboard, {
4409
7543
  id: uid,
4410
7544
  annoTime: 0,
4411
7545
  status: NEW,
@@ -4469,13 +7603,13 @@ var Canvas = function (_Component) {
4469
7603
  var lbls = this.props.possibleLabels;
4470
7604
  lbls = lbls.map(function (e) {
4471
7605
  if (!('color' in e)) {
4472
- return _extends$9({}, e, { color: getColor(e.id) });
7606
+ return _extends$b({}, e, { color: getColor(e.id) });
4473
7607
  } else {
4474
- return _extends$9({}, e);
7608
+ return _extends$b({}, e);
4475
7609
  }
4476
7610
  });
4477
7611
  this.setState({
4478
- possibleLabels: [].concat(_toConsumableArray$4(lbls))
7612
+ possibleLabels: [].concat(_toConsumableArray$5(lbls))
4479
7613
  });
4480
7614
  }
4481
7615
  }, {
@@ -4486,7 +7620,7 @@ var Canvas = function (_Component) {
4486
7620
  if (anno === undefined) {
4487
7621
  myAnno = this.findAnno(this.state.selectedAnnoId);
4488
7622
  } else {
4489
- myAnno = _extends$9({}, anno);
7623
+ myAnno = _extends$b({}, anno);
4490
7624
  }
4491
7625
  myAnno = this.startAnnotimeMeasure(myAnno);
4492
7626
  this.showLabelInput();
@@ -4530,7 +7664,7 @@ var Canvas = function (_Component) {
4530
7664
  value: function pushHist(annos, selectedAnnoId, pAction, showSingleAnno) {
4531
7665
  var imgLabelIds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.state.imgLabelIds;
4532
7666
 
4533
- this.hist.push(_extends$9({}, this.getAnnos(annos, false), {
7667
+ this.hist.push(_extends$b({}, this.getAnnos(annos, false), {
4534
7668
  selectedAnnoId: selectedAnnoId,
4535
7669
  showSingleAnno: showSingleAnno,
4536
7670
  imgLabelIds: imgLabelIds
@@ -4560,7 +7694,7 @@ var Canvas = function (_Component) {
4560
7694
  var ar = this.findAnnoRef(this.state.selectedAnnoId);
4561
7695
  if (ar !== undefined) ar.current.myAnno.current.removeLastNode();
4562
7696
  } else {
4563
- this.onAnnoPerformedAction(anno, ANNO_DELETED);
7697
+ this.handleAnnoEvent(anno, ANNO_DELETED);
4564
7698
  }
4565
7699
  }
4566
7700
  }
@@ -4571,7 +7705,7 @@ var Canvas = function (_Component) {
4571
7705
  if (anno.mode === CREATE) {
4572
7706
  // const ar = this.findAnnoRef(this.state.selectedAnnoId)
4573
7707
  // if (ar !== undefined) ar.current.myAnno.current.removeLastNode()
4574
- this.onAnnoPerformedAction(anno, ANNO_DELETED);
7708
+ this.handleAnnoEvent(anno, ANNO_DELETED);
4575
7709
  }
4576
7710
  }
4577
7711
  }
@@ -4581,7 +7715,7 @@ var Canvas = function (_Component) {
4581
7715
  var newAnnos = [];
4582
7716
  this.state.annos.forEach(function (e) {
4583
7717
  if (typeof e.id !== "string") {
4584
- newAnnos.push(_extends$9({}, e, { status: DELETED$1 }));
7718
+ newAnnos.push(_extends$b({}, e, { status: DELETED$1 }));
4585
7719
  }
4586
7720
  });
4587
7721
  this.pushHist(newAnnos, undefined, 'deletedAllAnnos', this.state.showSingleAnno, this.state.imgLabelIds);
@@ -4603,8 +7737,8 @@ var Canvas = function (_Component) {
4603
7737
  }, {
4604
7738
  key: 'setCanvasState',
4605
7739
  value: function setCanvasState(annotations, imgLabelIds, selectedAnnoId, showSingleAnno) {
4606
- this.updateCanvasView(_extends$9({}, annotations));
4607
- this.setImageLabels([].concat(_toConsumableArray$4(imgLabelIds)));
7740
+ this.updateCanvasView(_extends$b({}, annotations));
7741
+ this.setImageLabels([].concat(_toConsumableArray$5(imgLabelIds)));
4608
7742
  this.selectAnnotation(selectedAnnoId);
4609
7743
  this.setState({ showSingleAnno: showSingleAnno });
4610
7744
  }
@@ -4650,10 +7784,10 @@ var Canvas = function (_Component) {
4650
7784
  this.onAnnoLabelInputClose();
4651
7785
  }
4652
7786
  }
4653
- if (this.props.onAnnoSelect) {
4654
- var _anno = this.findAnno(annoId);
4655
- this.props.onAnnoSelect(_anno);
4656
- }
7787
+ // if(this.props.onAnnoSelect){
7788
+ // const anno = this.findAnno(annoId)
7789
+ // this.props.onAnnoSelect(anno)
7790
+ // }
4657
7791
  }
4658
7792
 
4659
7793
  /**
@@ -4663,18 +7797,18 @@ var Canvas = function (_Component) {
4663
7797
  }, {
4664
7798
  key: 'traverseAnnos',
4665
7799
  value: function traverseAnnos() {
4666
- var _this2 = this;
7800
+ var _this4 = this;
4667
7801
 
4668
7802
  if (this.state.annos.length > 0) {
4669
7803
  var myAnnos = this.state.annos.filter(function (e) {
4670
- return e.status !== DELETED$1 && !_this2.isLocked(e.id);
7804
+ return e.status !== DELETED$1 && !_this4.isLocked(e.id) && !(e.visible === false);
4671
7805
  });
4672
7806
  if (myAnnos.length > 0) {
4673
7807
  if (!this.state.selectedAnnoId) {
4674
7808
  this.selectAnnotation(myAnnos[0].id);
4675
7809
  } else {
4676
7810
  var currentIdx = myAnnos.findIndex(function (e) {
4677
- return e.id === _this2.state.selectedAnnoId;
7811
+ return e.id === _this4.state.selectedAnnoId;
4678
7812
  });
4679
7813
  if (currentIdx + 1 < myAnnos.length) {
4680
7814
  this.selectAnnotation(myAnnos[currentIdx + 1].id);
@@ -4695,12 +7829,12 @@ var Canvas = function (_Component) {
4695
7829
  // const backendFormat = this.getAnnoBackendFormat(removeFrontedIds, myAnnos)
4696
7830
  var backendFormat = canvasToBackendAnnos(myAnnos, this.state.svg, removeFrontedIds, this.state.imageOffset);
4697
7831
  var finalData = {
4698
- imgId: this.props.annos.image.id,
7832
+ imgId: this.props.imageMeta.id,
4699
7833
  imgLabelIds: this.state.imgLabelIds,
4700
7834
  imgLabelChanged: this.state.imgLabelChanged,
4701
7835
  annotations: backendFormat,
4702
7836
  isJunk: this.state.isJunk,
4703
- annoTime: this.props.annos.image.annoTime + (performance.now() - this.state.imgLoadTimestamp) / 1000
7837
+ annoTime: this.props.imageMeta.annoTime + (performance.now() - this.state.imgLoadTimestamp) / 1000
4704
7838
  };
4705
7839
  return finalData;
4706
7840
  }
@@ -4712,7 +7846,7 @@ var Canvas = function (_Component) {
4712
7846
  }, {
4713
7847
  key: 'resetZoom',
4714
7848
  value: function resetZoom() {
4715
- this.setState({ svg: _extends$9({}, this.state.svg, {
7849
+ this.setState({ svg: _extends$b({}, this.state.svg, {
4716
7850
  translateX: 0,
4717
7851
  translateY: 0,
4718
7852
  scale: 1.0
@@ -4739,7 +7873,7 @@ var Canvas = function (_Component) {
4739
7873
  } else if (vRight.vY <= yXMax) {
4740
7874
  trans_y = this.state.svg.translateY + 5;
4741
7875
  }
4742
- this.setState({ svg: _extends$9({}, this.state.svg, {
7876
+ this.setState({ svg: _extends$b({}, this.state.svg, {
4743
7877
  translateX: trans_x,
4744
7878
  translateY: trans_y
4745
7879
  }) });
@@ -4814,7 +7948,7 @@ var Canvas = function (_Component) {
4814
7948
  var mousePos = this.getMousePosition(e);
4815
7949
  // const selAnno = this.findAnno(this.state.selectedAnnoId)
4816
7950
  var newAnno = {
4817
- id: _.uniqueId('new'),
7951
+ id: this.props.nextAnnoId ? this.props.nextAnnoId : _.uniqueId('new'),
4818
7952
  type: this.props.selectedTool,
4819
7953
  data: [{
4820
7954
  x: mousePos.x,
@@ -4831,7 +7965,7 @@ var Canvas = function (_Component) {
4831
7965
  };
4832
7966
  newAnno = this.startAnnotimeMeasure(newAnno);
4833
7967
  this.setState({
4834
- annos: [].concat(_toConsumableArray$4(this.state.annos), [newAnno]),
7968
+ annos: [].concat(_toConsumableArray$5(this.state.annos), [newAnno]),
4835
7969
  selectedAnnoId: newAnno.id,
4836
7970
  showSingleAnno: newAnno.id,
4837
7971
  annoToolBarVisible: false
@@ -4884,7 +8018,7 @@ var Canvas = function (_Component) {
4884
8018
 
4885
8019
  newAnno = this.startAnnotimeMeasure(newAnno);
4886
8020
  this.setState({
4887
- annos: [].concat(_toConsumableArray$4(this.state.annos), [newAnno]),
8021
+ annos: [].concat(_toConsumableArray$5(this.state.annos), [newAnno]),
4888
8022
  selectedAnnoId: newAnno.id,
4889
8023
  showSingleAnno: newAnno.id,
4890
8024
  annoToolBarVisible: false
@@ -4895,20 +8029,20 @@ var Canvas = function (_Component) {
4895
8029
  }, {
4896
8030
  key: 'putSelectedOnTop',
4897
8031
  value: function putSelectedOnTop(prevState) {
4898
- var _this3 = this;
8032
+ var _this5 = this;
4899
8033
 
4900
8034
  // The selected annotation need to be rendered as last one in
4901
8035
  // oder to be above all other annotations.
4902
8036
  if (this.state.selectedAnnoId) {
4903
8037
  if (prevState.selectedAnnoId !== this.state.selectedAnnoId) {
4904
8038
  var annos = this.state.annos.filter(function (el) {
4905
- return el.id !== _this3.state.selectedAnnoId;
8039
+ return el.id !== _this5.state.selectedAnnoId;
4906
8040
  });
4907
8041
  var lastAnno = this.state.annos.find(function (el) {
4908
- return el.id === _this3.state.selectedAnnoId;
8042
+ return el.id === _this5.state.selectedAnnoId;
4909
8043
  });
4910
8044
  annos.push(lastAnno);
4911
- this.setState({ annos: [].concat(_toConsumableArray$4(annos)) });
8045
+ this.setState({ annos: [].concat(_toConsumableArray$5(annos)) });
4912
8046
  }
4913
8047
  }
4914
8048
  }
@@ -4958,11 +8092,11 @@ var Canvas = function (_Component) {
4958
8092
  selectedAnnoId: anno.id,
4959
8093
  prevLabel: anno.labelIds
4960
8094
  });
4961
- if (this.props.onAnnoSelect) {
4962
- if (newAnno !== null) {
4963
- this.props.onAnnoSelect(newAnno);
4964
- }
4965
- }
8095
+ // if(this.props.onAnnoSelect){
8096
+ // if (newAnno !== null){
8097
+ // this.props.onAnnoSelect(newAnno)
8098
+ // }
8099
+ // }
4966
8100
  return newAnnos;
4967
8101
  }
4968
8102
  }, {
@@ -4975,27 +8109,27 @@ var Canvas = function (_Component) {
4975
8109
  });
4976
8110
  var newAnno = void 0;
4977
8111
  if (mode) {
4978
- newAnno = _extends$9({}, anno, { mode: mode });
8112
+ newAnno = _extends$b({}, anno, { mode: mode });
4979
8113
  if (mode === DELETED) {
4980
8114
  if (anno.status !== NEW) {
4981
- newAnno = _extends$9({}, newAnno, {
8115
+ newAnno = _extends$b({}, newAnno, {
4982
8116
  status: DELETED$1
4983
8117
  });
4984
8118
  } else {
4985
8119
  newAnno = null;
4986
8120
  }
4987
8121
  } else {
4988
- newAnno = _extends$9({}, newAnno, {
8122
+ newAnno = _extends$b({}, newAnno, {
4989
8123
  status: anno.status !== NEW ? CHANGED : NEW
4990
8124
  });
4991
8125
  }
4992
8126
  } else {
4993
- newAnno = _extends$9({}, anno);
8127
+ newAnno = _extends$b({}, anno);
4994
8128
  }
4995
8129
  if (newAnno !== null) {
4996
8130
  filtered.push(newAnno);
4997
8131
  }
4998
- var newAnnos = [].concat(_toConsumableArray$4(filtered));
8132
+ var newAnnos = [].concat(_toConsumableArray$5(filtered));
4999
8133
  return { newAnnos: newAnnos, newAnno: newAnno };
5000
8134
  }
5001
8135
  }, {
@@ -5022,11 +8156,12 @@ var Canvas = function (_Component) {
5022
8156
  var canvasLeft;
5023
8157
  var maxImgHeight;
5024
8158
  var maxImgWidth;
5025
- if (this.props.layoutOffset) {
5026
- canvasTop = container.top + this.props.layoutOffset.top;
5027
- canvasLeft = container.left + this.props.layoutOffset.left;
5028
- maxImgHeight = clientHeight - container.top - this.props.layoutOffset.bottom - this.props.layoutOffset.top;
5029
- 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;
5030
8165
  } else {
5031
8166
  canvasTop = container.top;
5032
8167
  canvasLeft = container.left;
@@ -5046,15 +8181,15 @@ var Canvas = function (_Component) {
5046
8181
  }
5047
8182
  var svg;
5048
8183
  var imgOffset = { x: 0, y: 0 };
5049
- if (this.props.maxCanvas) {
8184
+ if (this.props.uiConfig.maxCanvas) {
5050
8185
  imgOffset.x = (maxImgWidth - imgWidth) / 2;
5051
8186
  imgOffset.y = (maxImgHeight - imgHeight) / 2;
5052
8187
  console.log('imgOffset: ', imgOffset);
5053
- svg = _extends$9({}, this.state.svg, { width: maxImgWidth, height: maxImgHeight,
8188
+ svg = _extends$b({}, this.state.svg, { width: maxImgWidth, height: maxImgHeight,
5054
8189
  left: canvasLeft, top: canvasTop
5055
8190
  });
5056
8191
  } else {
5057
- if (this.props.centerCanvasInContainer) {
8192
+ if (this.props.uiConfig.centerCanvasInContainer) {
5058
8193
  var resSpaceX = maxImgWidth - imgWidth;
5059
8194
  if (resSpaceX > 2) {
5060
8195
  canvasLeft = canvasLeft + resSpaceX / 2;
@@ -5064,7 +8199,7 @@ var Canvas = function (_Component) {
5064
8199
  canvasTop = canvasTop + resSpaceY / 2;
5065
8200
  }
5066
8201
  }
5067
- svg = _extends$9({}, this.state.svg, { width: imgWidth, height: imgHeight,
8202
+ svg = _extends$b({}, this.state.svg, { width: imgWidth, height: imgHeight,
5068
8203
  left: canvasLeft, top: canvasTop
5069
8204
  });
5070
8205
  }
@@ -5082,9 +8217,10 @@ var Canvas = function (_Component) {
5082
8217
  }, {
5083
8218
  key: 'svgUpdate',
5084
8219
  value: function svgUpdate(svg) {
5085
- if (this.props.onSVGUpdate) {
5086
- this.props.onSVGUpdate(svg);
5087
- }
8220
+ this.triggerCanvasEvent(CANVAS_SVG_UPDATE, svg);
8221
+ // if(this.props.onSVGUpdate){
8222
+ // this.props.onSVGUpdate(svg)
8223
+ // }
5088
8224
  }
5089
8225
  }, {
5090
8226
  key: 'setImageLabels',
@@ -5102,40 +8238,41 @@ var Canvas = function (_Component) {
5102
8238
  //for svg should be calculated
5103
8239
  if (annotations) {
5104
8240
  var imgSize = this.updateImageSize();
5105
- this.setState({ annos: [].concat(_toConsumableArray$4(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }, imgSize.imgOffset))) });
8241
+ this.setState({ annos: [].concat(_toConsumableArray$5(backendAnnosToCanvas(annotations, { width: imgSize.imgWidth, height: imgSize.imgHeight }, imgSize.imgOffset))) });
5106
8242
  }
5107
8243
  }
5108
8244
  }, {
5109
8245
  key: 'renderAnnotations',
5110
8246
  value: function renderAnnotations() {
5111
- var _this4 = this;
8247
+ var _this6 = this;
5112
8248
 
5113
8249
  // Do not render annotations while moving the camera!
5114
8250
  if (this.state.mode !== CAMERA_MOVE) {
5115
8251
  this.annoRefs = [];
5116
8252
  var annos = this.state.annos.map(function (el) {
5117
- _this4.annoRefs.push(React.createRef());
8253
+ _this6.annoRefs.push(React.createRef());
5118
8254
  return React.createElement(Annotation$1, { type: el.type,
5119
- data: el, key: el.id, svg: _extends$9({}, _this4.state.svg),
5120
- 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],
5121
8258
  onMouseDown: function onMouseDown(e) {
5122
- return _this4.onAnnoMouseDown(e);
8259
+ return _this6.onAnnoMouseDown(e);
5123
8260
  },
5124
8261
  onAction: function onAction(anno, pAction) {
5125
- return _this4.onAnnoPerformedAction(anno, pAction);
8262
+ return _this6.handleAnnoEvent(anno, pAction);
5126
8263
  },
5127
- selectedAnno: _this4.state.selectedAnnoId
8264
+ selectedAnno: _this6.state.selectedAnnoId
5128
8265
  // onModeChange={(anno) => this.onAnnoModeChange(anno)}
5129
- , showSingleAnno: _this4.state.showSingleAnno,
5130
- uiConfig: _this4.props.uiConfig,
5131
- allowedActions: _this4.props.canvasConfig.annos.actions,
5132
- possibleLabels: _this4.state.possibleLabels,
5133
- image: _this4.state.image,
5134
- 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,
5135
8272
  onNotification: function onNotification(messageObj) {
5136
- return _this4.handleNotification(messageObj);
8273
+ return _this6.handleNotification(messageObj);
5137
8274
  },
5138
- defaultLabel: _this4.props.defaultLabel
8275
+ defaultLabel: _this6.props.defaultLabel
5139
8276
  });
5140
8277
  });
5141
8278
  return React.createElement(
@@ -5150,14 +8287,14 @@ var Canvas = function (_Component) {
5150
8287
  }, {
5151
8288
  key: 'renderImgLabelInput',
5152
8289
  value: function renderImgLabelInput() {
5153
- var _this5 = this;
8290
+ var _this7 = this;
5154
8291
 
5155
- if (!this.props.annos.image) return null;
8292
+ if (!this.props.imageMeta) return null;
5156
8293
  return React.createElement(Prompt, {
5157
8294
  onClick: function onClick() {
5158
- return _this5.handleImgLabelInputClose();
8295
+ return _this7.handleImgLabelInputClose();
5159
8296
  },
5160
- active: this.props.imgLabelInputVisible,
8297
+ active: this.props.uiConfig.imgLabelInputVisible,
5161
8298
  header: React.createElement(
5162
8299
  'div',
5163
8300
  null,
@@ -5172,11 +8309,11 @@ var Canvas = function (_Component) {
5172
8309
  // relatedId={this.props.annos.image.id}
5173
8310
  , visible: true,
5174
8311
  onLabelUpdate: function onLabelUpdate(label) {
5175
- return _this5.handleImgLabelUpdate(label);
8312
+ return _this7.handleImgLabelUpdate(label);
5176
8313
  },
5177
8314
  possibleLabels: this.state.possibleLabels,
5178
8315
  initLabelIds: this.state.imgLabelIds,
5179
- relatedId: this.props.annos.image.id,
8316
+ relatedId: this.props.imageMeta.id,
5180
8317
  defaultLabel: this.props.defaultLabel
5181
8318
  // disabled={!this.props.allowedActions.label}
5182
8319
  // renderPopup
@@ -5185,7 +8322,7 @@ var Canvas = function (_Component) {
5185
8322
  Button,
5186
8323
  { basic: true, color: 'green', inverted: true,
5187
8324
  onClick: function onClick() {
5188
- return _this5.handleImgLabelInputClose();
8325
+ return _this7.handleImgLabelInputClose();
5189
8326
  }
5190
8327
  },
5191
8328
  React.createElement(Icon, { name: 'check' }),
@@ -5197,7 +8334,7 @@ var Canvas = function (_Component) {
5197
8334
  }, {
5198
8335
  key: 'renderAnnoToolBar',
5199
8336
  value: function renderAnnoToolBar(selectedAnno) {
5200
- var _this6 = this;
8337
+ var _this8 = this;
5201
8338
 
5202
8339
  var visible = this.state.annoToolBarVisible;
5203
8340
  if (this.state.mode === CAMERA_MOVE) visible = false;
@@ -5205,7 +8342,7 @@ var Canvas = function (_Component) {
5205
8342
  selectedAnno: selectedAnno,
5206
8343
  svg: this.state.svg,
5207
8344
  onClick: function onClick() {
5208
- return _this6.editAnnoLabel();
8345
+ return _this8.editAnnoLabel();
5209
8346
  },
5210
8347
  color: this.getAnnoColor()
5211
8348
  });
@@ -5213,22 +8350,22 @@ var Canvas = function (_Component) {
5213
8350
  }, {
5214
8351
  key: 'renderAnnoLabelInpput',
5215
8352
  value: function renderAnnoLabelInpput(selectedAnno) {
5216
- var _this7 = this;
8353
+ var _this9 = this;
5217
8354
 
5218
8355
  var visible = this.state.showLabelInput;
5219
8356
  if (this.state.mode === CAMERA_MOVE) visible = false;
5220
8357
  return React.createElement(AnnoLabelInput, { svg: this.state.svg
5221
8358
  // svgRef={this.svg}
5222
8359
  , onClose: function onClose() {
5223
- return _this7.onAnnoLabelInputClose();
8360
+ return _this9.onAnnoLabelInputClose();
5224
8361
  },
5225
8362
  onDeleteClick: function onDeleteClick(annoId) {
5226
- return _this7.onLabelInputDeleteClick(annoId);
8363
+ return _this9.onLabelInputDeleteClick(annoId);
5227
8364
  },
5228
8365
  selectedAnno: selectedAnno,
5229
8366
  visible: visible,
5230
8367
  onLabelUpdate: function onLabelUpdate(anno) {
5231
- return _this7.onAnnoLabelInputUpdate(anno);
8368
+ return _this9.onAnnoLabelInputUpdate(anno);
5232
8369
  },
5233
8370
  possibleLabels: this.state.possibleLabels,
5234
8371
  allowedActions: this.props.canvasConfig.annos.actions,
@@ -5238,10 +8375,19 @@ var Canvas = function (_Component) {
5238
8375
  // multilabels={true}
5239
8376
  });
5240
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
+
5241
8387
  }, {
5242
8388
  key: 'render',
5243
8389
  value: function render() {
5244
- var _this8 = this;
8390
+ var _this10 = this;
5245
8391
 
5246
8392
  var selectedAnno = this.findAnno(this.state.selectedAnnoId);
5247
8393
  return React.createElement(
@@ -5258,8 +8404,9 @@ var Canvas = function (_Component) {
5258
8404
  possibleLabels: this.state.possibleLabels,
5259
8405
  annos: this.props.annos,
5260
8406
  svg: this.state.svg,
8407
+ imageMeta: this.props.imageMeta,
5261
8408
  onClose: function onClose() {
5262
- return _this8.handleImgBarClose();
8409
+ return _this10.handleImgBarClose();
5263
8410
  },
5264
8411
  imgLabelIds: this.state.imgLabelIds
5265
8412
  // onLabelUpdate={label => this.handleImgLabelUpdate(label)}
@@ -5267,7 +8414,7 @@ var Canvas = function (_Component) {
5267
8414
  // multilabels={this.props.canvasConfig.img.multilabels}
5268
8415
  // allowedActions={this.props.canvasConfig.img.actions}
5269
8416
  , onMouseEnter: function onMouseEnter(e) {
5270
- return _this8.handleImgBarMouseEnter(e);
8417
+ return _this10.handleImgBarMouseEnter(e);
5271
8418
  }
5272
8419
  }),
5273
8420
  React.createElement(
@@ -5291,21 +8438,47 @@ var Canvas = function (_Component) {
5291
8438
  ),
5292
8439
  this.renderAnnoToolBar(selectedAnno),
5293
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
+ }),
5294
8467
  React.createElement(
5295
8468
  'svg',
5296
8469
  { ref: this.svg, width: this.state.svg.width,
5297
8470
  height: this.state.svg.height,
5298
8471
  onKeyDown: function onKeyDown(e) {
5299
- return _this8.onKeyDown(e);
8472
+ return _this10.onKeyDown(e);
5300
8473
  },
5301
8474
  onKeyUp: function onKeyUp(e) {
5302
- return _this8.onKeyUp(e);
8475
+ return _this10.onKeyUp(e);
5303
8476
  },
5304
8477
  onClick: function onClick(e) {
5305
- return _this8.handleCanvasClick(e);
8478
+ return _this10.handleCanvasClick(e);
5306
8479
  },
5307
8480
  onMouseMove: function onMouseMove(e) {
5308
- return _this8.handleSvgMouseMove(e);
8481
+ return _this10.handleSvgMouseMove(e);
5309
8482
  },
5310
8483
  tabIndex: '0'
5311
8484
  },
@@ -5314,26 +8487,27 @@ var Canvas = function (_Component) {
5314
8487
  {
5315
8488
  transform: 'scale(' + this.state.svg.scale + ') translate(' + this.state.svg.translateX + ', ' + this.state.svg.translateY + ')',
5316
8489
  onMouseOver: function onMouseOver() {
5317
- _this8.onMouseOver();
5318
- },
5319
- onMouseUp: function onMouseUp(e) {
5320
- _this8.onMouseUp(e);
8490
+ _this10.onMouseOver();
8491
+ }
8492
+ // onMouseEnter={() => this.svg.current.focus()}
8493
+ , onMouseUp: function onMouseUp(e) {
8494
+ _this10.onMouseUp(e);
5321
8495
  },
5322
8496
  onWheel: function onWheel(e) {
5323
- return _this8.onWheel(e);
8497
+ return _this10.onWheel(e);
5324
8498
  },
5325
8499
  onMouseMove: function onMouseMove(e) {
5326
- _this8.onMouseMove(e);
8500
+ _this10.onMouseMove(e);
5327
8501
  }
5328
8502
  },
5329
8503
  React.createElement('image', {
5330
8504
  onContextMenu: function onContextMenu(e) {
5331
- return _this8.onRightClick(e);
8505
+ return _this10.onRightClick(e);
5332
8506
  },
5333
8507
  onMouseDown: function onMouseDown(e) {
5334
- return _this8.onMouseDown(e);
8508
+ return _this10.onMouseDown(e);
5335
8509
  },
5336
- href: this.props.image.data,
8510
+ href: this.props.imageBlob,
5337
8511
  width: this.state.svg.width,
5338
8512
  height: this.state.svg.height
5339
8513
  }),
@@ -5343,8 +8517,8 @@ var Canvas = function (_Component) {
5343
8517
  React.createElement('img', {
5344
8518
  alt: 'sia', style: { display: 'none' }, ref: this.img,
5345
8519
  onLoad: function onLoad() {
5346
- _this8.onImageLoad();
5347
- }, src: this.state.imageData,
8520
+ _this10.onImageLoad();
8521
+ }, src: this.state.imageBlob,
5348
8522
  width: '100%', height: '100%'
5349
8523
  })
5350
8524
  ),