@pie-element/extended-text-entry 6.6.4 → 6.7.0-annotations.2

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.
@@ -0,0 +1,704 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
+
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
20
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
22
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _styles = require("@material-ui/core/styles");
29
+
30
+ var _classnames = _interopRequireDefault(require("classnames"));
31
+
32
+ var _propTypes = _interopRequireDefault(require("prop-types"));
33
+
34
+ var _annotationUtils = require("./annotation-utils");
35
+
36
+ var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
37
+
38
+ var _configUi = require("@pie-lib/config-ui");
39
+
40
+ var _freeformEditor = _interopRequireDefault(require("./freeform-editor"));
41
+
42
+ var _annotationMenu = _interopRequireDefault(require("./annotation-menu"));
43
+
44
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
45
+
46
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
47
+
48
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
49
+
50
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
51
+
52
+ var style = {
53
+ textContainer: {
54
+ padding: '10px 170px 10px 16px',
55
+ backgroundColor: 'rgba(0, 0, 0, 0.06)',
56
+ border: '1px solid #ccc',
57
+ borderRadius: '4px',
58
+ overflowY: 'scroll',
59
+ lineHeight: '36px',
60
+ whiteSpace: 'pre-wrap',
61
+ overflowWrap: 'break-word',
62
+ '& p': {
63
+ margin: 0
64
+ },
65
+ '& span[data-latex]': {
66
+ userSelect: 'none',
67
+ '-webkit-user-select': 'none',
68
+ '-moz-user-select': 'none',
69
+ '-ms-user-select': 'none'
70
+ }
71
+ },
72
+ labelsContainer: {
73
+ width: '230px'
74
+ },
75
+ wrapper: {
76
+ position: 'relative',
77
+ overflowX: 'hidden',
78
+ display: 'flex'
79
+ },
80
+ commentContainer: {
81
+ paddingTop: 16,
82
+ marginBottom: 16,
83
+ marginTop: 16,
84
+ width: '100%'
85
+ },
86
+ annotation: {
87
+ position: 'relative',
88
+ cursor: 'pointer',
89
+ display: 'inline-block',
90
+ lineHeight: '19px',
91
+ '&.positive': {
92
+ backgroundColor: 'rgb(51, 255, 51, 0.5)'
93
+ },
94
+ '&.negative': {
95
+ backgroundColor: 'rgba(255, 102, 204, 0.4)'
96
+ }
97
+ },
98
+ annotationLabel: {
99
+ backgroundColor: 'rgb(242, 242, 242)',
100
+ padding: '2px',
101
+ position: 'absolute',
102
+ userSelect: 'none',
103
+ whiteSpace: 'nowrap',
104
+ top: '-10px',
105
+ left: '-2px',
106
+ fontSize: '12px',
107
+ fontStyle: 'normal',
108
+ fontWeight: 'normal',
109
+ lineHeight: '6px',
110
+ '-webkit-user-select': 'none',
111
+ '-moz-user-select': 'none',
112
+ '-ms-user-select': 'none',
113
+ '&.positive': {
114
+ color: 'rgb(0, 128, 0)'
115
+ },
116
+ '&.negative': {
117
+ color: 'rgb(204, 0, 136)'
118
+ }
119
+ },
120
+ labelHover: {
121
+ zIndex: 20,
122
+ '&.positive': {
123
+ color: 'rgb(0, 77, 0)'
124
+ },
125
+ '&.negative': {
126
+ color: 'rgb(153, 0, 102)'
127
+ }
128
+ },
129
+ highlight: {
130
+ zIndex: 10
131
+ },
132
+ hover: {
133
+ zIndex: 20,
134
+ '&.positive': {
135
+ backgroundColor: 'rgb(51, 255, 51, 0.7)'
136
+ },
137
+ '&.negative': {
138
+ backgroundColor: 'rgba(255, 102, 204, 0.55)'
139
+ }
140
+ },
141
+ sideAnnotationHover: {
142
+ zIndex: 20,
143
+ '&.negative': {
144
+ backgroundColor: 'rgb(255, 179, 230) !important',
145
+ '&:before': {
146
+ borderRightColor: 'rgb(255, 179, 230) !important'
147
+ }
148
+ },
149
+ '&.positive': {
150
+ backgroundColor: 'rgb(128, 255, 128) !important',
151
+ '&:before': {
152
+ borderRightColor: 'rgb(153, 255, 153) !important'
153
+ }
154
+ }
155
+ },
156
+ sideAnnotation: {
157
+ position: 'absolute',
158
+ padding: '4px',
159
+ borderRadius: '4px',
160
+ marginLeft: '8px',
161
+ width: '180px',
162
+ whiteSpace: 'pre-wrap',
163
+ wordBreak: 'break-word',
164
+ border: '2px solid #ffffff',
165
+ fontSize: '14px',
166
+ fontStyle: 'normal',
167
+ fontWeight: 'normal',
168
+ '&:before': {
169
+ position: 'absolute',
170
+ right: '100%',
171
+ top: '5px',
172
+ border: 'solid transparent',
173
+ content: '""',
174
+ height: 0,
175
+ width: 0,
176
+ pointerEvents: 'none',
177
+ borderWidth: '7px'
178
+ },
179
+ '&.negative': {
180
+ backgroundColor: 'rgb(255, 204, 238)',
181
+ '&:before': {
182
+ borderRightColor: 'rgb(255, 204, 238)'
183
+ }
184
+ },
185
+ '&.positive': {
186
+ backgroundColor: 'rgb(153, 255, 153)',
187
+ '&:before': {
188
+ borderRightColor: 'rgb(153, 255, 153)'
189
+ }
190
+ }
191
+ }
192
+ };
193
+
194
+ var AnnotationEditor = /*#__PURE__*/function (_React$Component) {
195
+ (0, _inherits2["default"])(AnnotationEditor, _React$Component);
196
+
197
+ var _super = _createSuper(AnnotationEditor);
198
+
199
+ function AnnotationEditor(props) {
200
+ var _this;
201
+
202
+ (0, _classCallCheck2["default"])(this, AnnotationEditor);
203
+ _this = _super.call(this, props);
204
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "adjustAnnotationsPosition", function () {
205
+ if (_this.textRef && _this.labelsRef) {
206
+ var left = _this.textRef.offsetLeft + _this.textRef.offsetWidth + 8;
207
+ Array.from(_this.labelsRef.children).forEach(function (label) {
208
+ var spans = (0, _annotationUtils.getAnnotationElements)(label.dataset.annId);
209
+ var spanOffset = spans[0].offsetTop ? spans[0].offsetTop : spans[0].offsetParent.offsetTop;
210
+ var top = spanOffset - _this.textRef.scrollTop - 6;
211
+ label.style.top = "".concat(top, "px");
212
+ label.style.left = "".concat(left, "px");
213
+ });
214
+ }
215
+ });
216
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function (event) {
217
+ var _this$props = _this.props,
218
+ annotations = _this$props.annotations,
219
+ classes = _this$props.classes;
220
+ var selectionDetails = _this.state.selectionDetails;
221
+
222
+ if (selectionDetails) {
223
+ // new selection was made inside another annotation and should not update that annotation
224
+ return;
225
+ }
226
+
227
+ var _event$target$dataset = event.target.dataset,
228
+ id = _event$target$dataset.id,
229
+ annId = _event$target$dataset.annId;
230
+ var annotationId = id || annId;
231
+ var selectedElems = (0, _annotationUtils.getAnnotationElements)(annotationId);
232
+ var labelElem = (0, _annotationUtils.getLabelElement)(annotationId);
233
+ var annotationIndex = annotations.findIndex(function (annotation) {
234
+ return annotation.id === annotationId;
235
+ });
236
+ var isSideLabel = labelElem.hasAttribute('data-freeform');
237
+
238
+ if (isSideLabel) {
239
+ labelElem.classList.add(classes.highlight);
240
+ }
241
+
242
+ _this.setState({
243
+ anchorEl: selectedElems[0],
244
+ openedMenu: !!id || !!annId && !isSideLabel,
245
+ // true if the annotation or the label was clicked
246
+ openedEditor: !!annId && isSideLabel,
247
+ // true if the side label was clicked
248
+ selectedElems: selectedElems,
249
+ labelElem: labelElem,
250
+ annotationIndex: annotationIndex,
251
+ annotation: annotations[annotationIndex],
252
+ selectionDetails: null
253
+ });
254
+ });
255
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleHover", function (event) {
256
+ var classes = _this.props.classes;
257
+ var _event$target$dataset2 = event.target.dataset,
258
+ id = _event$target$dataset2.id,
259
+ annId = _event$target$dataset2.annId;
260
+ var annotationId = id || annId;
261
+ var selectedElems = (0, _annotationUtils.getAnnotationElements)(annotationId);
262
+ var labelElem = (0, _annotationUtils.getLabelElement)(annotationId);
263
+ var isSideLabel = labelElem.hasAttribute('data-freeform');
264
+ selectedElems.forEach(function (elem) {
265
+ return elem.classList.add(classes.hover);
266
+ });
267
+ labelElem.classList.add(isSideLabel ? classes.sideAnnotationHover : classes.labelHover);
268
+ });
269
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleCancelHover", function (event) {
270
+ var classes = _this.props.classes;
271
+ var _event$target$dataset3 = event.target.dataset,
272
+ id = _event$target$dataset3.id,
273
+ annId = _event$target$dataset3.annId;
274
+ var annotationId = id || annId;
275
+ var selectedElems = (0, _annotationUtils.getAnnotationElements)(annotationId);
276
+ var labelElem = (0, _annotationUtils.getLabelElement)(annotationId);
277
+ var isSideLabel = labelElem.hasAttribute('data-freeform');
278
+ selectedElems.forEach(function (elem) {
279
+ return elem.classList.remove(classes.hover);
280
+ });
281
+ labelElem.classList.remove(isSideLabel ? classes.sideAnnotationHover : classes.labelHover);
282
+ });
283
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClose", function (event) {
284
+ var classes = _this.props.classes;
285
+ var _this$state = _this.state,
286
+ selectedElems = _this$state.selectedElems,
287
+ labelElem = _this$state.labelElem;
288
+
289
+ if (selectedElems.length && !selectedElems[0].hasAttribute('data-id')) {
290
+ (0, _annotationUtils.removeElemsWrapping)(selectedElems, _this.textRef);
291
+ }
292
+
293
+ if (labelElem) {
294
+ labelElem.classList.remove(classes.highlight);
295
+ }
296
+
297
+ _this.setState({
298
+ anchorEl: null,
299
+ openedMenu: false,
300
+ openedEditor: false,
301
+ selectedElems: [],
302
+ labelElem: null,
303
+ selectionDetails: null,
304
+ annotationIndex: null,
305
+ annotation: null
306
+ });
307
+
308
+ (0, _annotationUtils.clearSelection)();
309
+ });
310
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleSelection", function (event) {
311
+ var selection = window.getSelection(); // prevent unwanted selections
312
+
313
+ if (event.detail > 2) {
314
+ (0, _annotationUtils.clearSelection)();
315
+ return;
316
+ }
317
+
318
+ if (selection && selection.rangeCount > 0) {
319
+ var selectedRange = selection.getRangeAt(0);
320
+ var selectedText = selectedRange.toString();
321
+
322
+ var isSelectionInside = _this.textRef.contains(selectedRange.commonAncestorContainer);
323
+
324
+ if (!selection.isCollapsed && selectedText !== '' && isSelectionInside) {
325
+ var selectionDetails = (0, _annotationUtils.getRangeDetails)(selectedRange, _this.textRef);
326
+ var selectedElems = (0, _annotationUtils.wrapRange)(selectedRange);
327
+
328
+ _this.setState({
329
+ anchorEl: selectedElems[0],
330
+ openedMenu: true,
331
+ selectedElems: selectedElems,
332
+ selectionDetails: selectionDetails
333
+ });
334
+ }
335
+ }
336
+ });
337
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteAnnotation", function () {
338
+ var _this$props2 = _this.props,
339
+ annotations = _this$props2.annotations,
340
+ onChange = _this$props2.onChange;
341
+ var _this$state2 = _this.state,
342
+ selectedElems = _this$state2.selectedElems,
343
+ labelElem = _this$state2.labelElem,
344
+ annotationIndex = _this$state2.annotationIndex,
345
+ annotation = _this$state2.annotation;
346
+ var parentRef = (0, _annotationUtils.isSideLabel)(annotation.label) ? _this.labelsRef : selectedElems[0];
347
+ parentRef.removeChild(labelElem);
348
+ (0, _annotationUtils.removeElemsWrapping)(selectedElems, _this.textRef);
349
+ annotations.splice(annotationIndex, 1);
350
+ onChange(annotations);
351
+
352
+ _this.handleClose();
353
+ });
354
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "createDOMAnnotation", function (elems, annotation) {
355
+ var _this$props3 = _this.props,
356
+ classes = _this$props3.classes,
357
+ disabled = _this$props3.disabled;
358
+ var id = annotation.id,
359
+ label = annotation.label,
360
+ type = annotation.type;
361
+ (elems || []).forEach(function (elem) {
362
+ elem.dataset.id = id;
363
+ elem.className = (0, _classnames["default"])(classes.annotation, type);
364
+ elem.onclick = !disabled && _this.handleClick;
365
+ elem.onmouseover = _this.handleHover;
366
+ elem.onmouseout = _this.handleCancelHover;
367
+ });
368
+ var firstSpan = elems && elems[0] || {};
369
+ var labelElem = document.createElement('SPAN');
370
+ labelElem.dataset.annId = id;
371
+ labelElem.innerHTML = label;
372
+ labelElem.onclick = !disabled && _this.handleClick;
373
+ labelElem.onmouseover = _this.handleHover;
374
+ labelElem.onmouseout = _this.handleCancelHover;
375
+
376
+ if ((0, _annotationUtils.isSideLabel)(label)) {
377
+ var spanOffset = firstSpan.offsetTop ? firstSpan.offsetTop : firstSpan.offsetParent.offsetTop;
378
+ var top = spanOffset - _this.textRef.scrollTop;
379
+ var left = _this.textRef.offsetLeft + _this.textRef.offsetWidth + 8;
380
+ labelElem.dataset.freeform = true;
381
+ labelElem.className = (0, _classnames["default"])(classes.sideAnnotation, type);
382
+ labelElem.style.top = "".concat(top, "px");
383
+ labelElem.style.left = "".concat(left, "px");
384
+
385
+ _this.labelsRef.appendChild(labelElem);
386
+ } else {
387
+ labelElem.className = (0, _classnames["default"])(classes.annotationLabel, type);
388
+ firstSpan.insertBefore(labelElem, firstSpan.firstChild);
389
+ }
390
+ });
391
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "createNewAnnotation", function (label, type) {
392
+ var _this$state3 = _this.state,
393
+ selectedElems = _this$state3.selectedElems,
394
+ selectionDetails = _this$state3.selectionDetails;
395
+
396
+ var annotation = _objectSpread({
397
+ id: [selectionDetails.start, selectionDetails.end, new Date().getTime()].join('-'),
398
+ label: label,
399
+ type: type
400
+ }, selectionDetails);
401
+
402
+ _this.createDOMAnnotation(selectedElems, annotation);
403
+
404
+ return annotation;
405
+ });
406
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMenuClick", function (newAnnotation) {
407
+ var _this$props4 = _this.props,
408
+ annotations = _this$props4.annotations,
409
+ onChange = _this$props4.onChange;
410
+ var _this$state4 = _this.state,
411
+ annotation = _this$state4.annotation,
412
+ annotationIndex = _this$state4.annotationIndex;
413
+ var type = newAnnotation.type,
414
+ label = newAnnotation.text;
415
+
416
+ if (annotation) {
417
+ var updatedAnnotation = _objectSpread(_objectSpread({}, annotation), {}, {
418
+ label: label,
419
+ type: type
420
+ });
421
+
422
+ var oldType = annotation.type,
423
+ oldLabel = annotation.label;
424
+
425
+ _this.updateLabel(oldLabel, updatedAnnotation, type !== oldType && oldType);
426
+
427
+ annotations.splice(annotationIndex, 1, updatedAnnotation);
428
+ } else {
429
+ var _newAnnotation = _this.createNewAnnotation(label, type);
430
+
431
+ annotations.push(_newAnnotation);
432
+ }
433
+
434
+ onChange(annotations);
435
+
436
+ _this.handleClose();
437
+ });
438
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "editAnnotation", function () {
439
+ _this.setState({
440
+ openedMenu: false,
441
+ openedEditor: true
442
+ });
443
+ });
444
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addAnnotation", function (type) {
445
+ var _this$props5 = _this.props,
446
+ annotations = _this$props5.annotations,
447
+ onChange = _this$props5.onChange;
448
+
449
+ var annotation = _this.createNewAnnotation('', type);
450
+
451
+ var labelElem = (0, _annotationUtils.getLabelElement)(annotation.id);
452
+ annotations.push(annotation);
453
+
454
+ _this.setState({
455
+ openedMenu: false,
456
+ openedEditor: true,
457
+ annotationIndex: annotations.length - 1,
458
+ annotation: annotation,
459
+ labelElem: labelElem
460
+ });
461
+
462
+ onChange(annotations);
463
+ });
464
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateLabel", function (oldLabel, annotation, oldType) {
465
+ var _this$state5 = _this.state,
466
+ selectedElems = _this$state5.selectedElems,
467
+ labelElem = _this$state5.labelElem;
468
+ var label = annotation.label,
469
+ type = annotation.type;
470
+
471
+ if ((0, _annotationUtils.isSideLabel)(label) && (0, _annotationUtils.isSideLabel)(oldLabel) || !(0, _annotationUtils.isSideLabel)(label) && !(0, _annotationUtils.isSideLabel)(oldLabel)) {
472
+ labelElem.innerHTML = label;
473
+
474
+ if (oldType) {
475
+ labelElem.classList.remove(oldType);
476
+ labelElem.classList.add(type);
477
+ selectedElems.forEach(function (elem) {
478
+ elem.classList.remove(oldType);
479
+ elem.classList.add(type);
480
+ });
481
+ }
482
+ } else if ((0, _annotationUtils.isSideLabel)(label) && !(0, _annotationUtils.isSideLabel)(oldLabel)) {
483
+ selectedElems[0].removeChild(labelElem);
484
+
485
+ _this.createDOMAnnotation(selectedElems, annotation);
486
+ } else if (!(0, _annotationUtils.isSideLabel)(label) && (0, _annotationUtils.isSideLabel)(oldLabel)) {
487
+ _this.labelsRef.removeChild(labelElem);
488
+
489
+ _this.createDOMAnnotation(selectedElems, annotation);
490
+ }
491
+ });
492
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeAnnotationType", function (newLabel) {
493
+ var _this$props6 = _this.props,
494
+ annotations = _this$props6.annotations,
495
+ onChange = _this$props6.onChange;
496
+ var _this$state6 = _this.state,
497
+ annotationIndex = _this$state6.annotationIndex,
498
+ selectedElems = _this$state6.selectedElems;
499
+ var _annotations$annotati = annotations[annotationIndex],
500
+ oldType = _annotations$annotati.type,
501
+ oldLabel = _annotations$annotati.label;
502
+ var type = oldType === 'positive' ? 'negative' : 'positive';
503
+
504
+ var updatedAnnotation = _objectSpread(_objectSpread({}, annotations[annotationIndex]), {}, {
505
+ type: type,
506
+ label: newLabel
507
+ });
508
+
509
+ selectedElems.forEach(function (span) {
510
+ span.classList.remove(oldType);
511
+ span.classList.add(type);
512
+ });
513
+
514
+ _this.updateLabel(oldLabel, updatedAnnotation, oldType);
515
+
516
+ annotations.splice(annotationIndex, 1, updatedAnnotation);
517
+ onChange(annotations);
518
+
519
+ _this.handleClose();
520
+ });
521
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateAnnotation", function (oldLabel, newLabel) {
522
+ var _this$props7 = _this.props,
523
+ annotations = _this$props7.annotations,
524
+ onChange = _this$props7.onChange;
525
+ var annotationIndex = _this.state.annotationIndex;
526
+
527
+ var updatedAnnotation = _objectSpread(_objectSpread({}, annotations[annotationIndex]), {}, {
528
+ label: newLabel
529
+ });
530
+
531
+ _this.updateLabel(oldLabel, updatedAnnotation);
532
+
533
+ annotations.splice(annotationIndex, 1, updatedAnnotation);
534
+ onChange(annotations);
535
+ });
536
+ _this.state = {
537
+ anchorEl: null,
538
+ openedMenu: false,
539
+ openedEditor: false,
540
+ selectedElems: [],
541
+ labelElem: null,
542
+ selectionDetails: null,
543
+ annotation: null,
544
+ annotationIndex: null
545
+ };
546
+ return _this;
547
+ }
548
+
549
+ (0, _createClass2["default"])(AnnotationEditor, [{
550
+ key: "componentDidMount",
551
+ value: function componentDidMount() {
552
+ var _this2 = this;
553
+
554
+ var _this$props8 = this.props,
555
+ annotations = _this$props8.annotations,
556
+ text = _this$props8.text;
557
+
558
+ if (text) {
559
+ annotations.forEach(function (annotation) {
560
+ var _getDOMNodes = (0, _annotationUtils.getDOMNodes)(annotation.start, annotation.end, _this2.textRef),
561
+ _getDOMNodes2 = (0, _slicedToArray2["default"])(_getDOMNodes, 2),
562
+ domStart = _getDOMNodes2[0],
563
+ domEnd = _getDOMNodes2[1];
564
+
565
+ if (domStart && domEnd) {
566
+ var range = document.createRange();
567
+ range.setStart(domStart.node, domStart.offset);
568
+ range.setEnd(domEnd.node, domEnd.offset);
569
+ var spans = (0, _annotationUtils.wrapRange)(range);
570
+
571
+ _this2.createDOMAnnotation(spans, annotation);
572
+ }
573
+ });
574
+ }
575
+
576
+ if (this.textRef) {
577
+ this.adjustAnnotationsPosition();
578
+ this.textRef.addEventListener('scroll', this.adjustAnnotationsPosition);
579
+ }
580
+ }
581
+ }, {
582
+ key: "componentWillUnmount",
583
+ value: function componentWillUnmount() {
584
+ this.textRef.removeEventListener('scroll', this.adjustAnnotationsPosition);
585
+ }
586
+ }, {
587
+ key: "render",
588
+ value: function render() {
589
+ var _this3 = this;
590
+
591
+ var _this$props9 = this.props,
592
+ classes = _this$props9.classes,
593
+ comment = _this$props9.comment,
594
+ customKeys = _this$props9.customKeys,
595
+ disabled = _this$props9.disabled,
596
+ disabledMath = _this$props9.disabledMath,
597
+ keypadMode = _this$props9.keypadMode,
598
+ height = _this$props9.height,
599
+ width = _this$props9.width,
600
+ maxHeight = _this$props9.maxHeight,
601
+ onCommentChange = _this$props9.onCommentChange,
602
+ predefinedAnnotations = _this$props9.predefinedAnnotations,
603
+ text = _this$props9.text;
604
+ var _this$state7 = this.state,
605
+ anchorEl = _this$state7.anchorEl,
606
+ annotation = _this$state7.annotation,
607
+ openedMenu = _this$state7.openedMenu,
608
+ openedEditor = _this$state7.openedEditor,
609
+ selectionDetails = _this$state7.selectionDetails;
610
+ var anchorOffset = anchorEl && (anchorEl.offsetTop ? anchorEl.offsetTop : anchorEl.offsetParent.offsetTop);
611
+ var topOffset = this.textRef && anchorOffset ? anchorOffset - this.textRef.scrollTop - 8 : 0;
612
+ return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
613
+ className: classes.wrapper
614
+ }, /*#__PURE__*/_react["default"].createElement("div", {
615
+ className: classes.textContainer,
616
+ style: {
617
+ width: width - 34,
618
+ minHeight: height,
619
+ maxHeight: maxHeight
620
+ },
621
+ ref: function ref(r) {
622
+ return _this3.textRef = r;
623
+ },
624
+ onMouseDown: !disabled ? _annotationUtils.clearSelection : function () {},
625
+ onMouseUp: !disabled ? this.handleSelection : function () {},
626
+ dangerouslySetInnerHTML: {
627
+ __html: text
628
+ }
629
+ }), /*#__PURE__*/_react["default"].createElement("div", {
630
+ className: classes.labelsContainer,
631
+ ref: function ref(r) {
632
+ return _this3.labelsRef = r;
633
+ }
634
+ })), /*#__PURE__*/_react["default"].createElement(_configUi.InputContainer, {
635
+ label: 'Comment',
636
+ className: classes.commentContainer
637
+ }, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
638
+ className: classes.prompt,
639
+ markup: comment || '',
640
+ onChange: onCommentChange,
641
+ width: width && (width + 154).toString(),
642
+ disabled: disabled,
643
+ pluginProps: {
644
+ math: {
645
+ disabled: disabledMath,
646
+ customKeys: customKeys,
647
+ keypadMode: keypadMode,
648
+ controlledKeypadMode: false
649
+ },
650
+ video: {
651
+ disabled: true
652
+ },
653
+ audio: {
654
+ disabled: true
655
+ }
656
+ }
657
+ })), /*#__PURE__*/_react["default"].createElement(_annotationMenu["default"], {
658
+ anchorEl: anchorEl,
659
+ open: openedMenu && !disabled,
660
+ annotations: predefinedAnnotations,
661
+ isNewAnnotation: !!selectionDetails,
662
+ onClose: this.handleClose,
663
+ onDelete: this.deleteAnnotation,
664
+ onEdit: this.editAnnotation,
665
+ onWrite: this.addAnnotation,
666
+ onAnnotate: this.handleMenuClick
667
+ }), /*#__PURE__*/_react["default"].createElement(_freeformEditor["default"], {
668
+ anchorEl: this.textRef,
669
+ open: openedEditor && !disabled,
670
+ offset: topOffset,
671
+ value: annotation && annotation.label || '',
672
+ type: annotation && annotation.type,
673
+ onClose: this.handleClose,
674
+ onDelete: this.deleteAnnotation,
675
+ onSave: this.updateAnnotation,
676
+ onTypeChange: this.changeAnnotationType
677
+ }));
678
+ }
679
+ }]);
680
+ return AnnotationEditor;
681
+ }(_react["default"].Component);
682
+
683
+ (0, _defineProperty2["default"])(AnnotationEditor, "propTypes", {
684
+ text: _propTypes["default"].string,
685
+ comment: _propTypes["default"].string,
686
+ annotations: _propTypes["default"].array,
687
+ predefinedAnnotations: _propTypes["default"].array,
688
+ onChange: _propTypes["default"].func.isRequired,
689
+ onCommentChange: _propTypes["default"].func.isRequired,
690
+ width: _propTypes["default"].number,
691
+ height: _propTypes["default"].number,
692
+ maxHeight: _propTypes["default"].string,
693
+ disabled: _propTypes["default"].bool,
694
+ disabledMath: _propTypes["default"].bool,
695
+ customKeys: _propTypes["default"].array,
696
+ keypadMode: _propTypes["default"].string,
697
+ classes: _propTypes["default"].object.isRequired
698
+ });
699
+ ;
700
+
701
+ var _default = (0, _styles.withStyles)(style)(AnnotationEditor);
702
+
703
+ exports["default"] = _default;
704
+ //# sourceMappingURL=annotation-editor.js.map