@pie-element/extended-text-entry 6.5.4-next.419 → 6.5.4-next.428

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