@pie-element/extended-text-entry 15.1.2-next.2 → 15.1.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.
Files changed (100) hide show
  1. package/CHANGELOG.json +1282 -0
  2. package/CHANGELOG.md +2270 -0
  3. package/LICENSE.md +5 -0
  4. package/README.md +1 -0
  5. package/configure/CHANGELOG.json +922 -0
  6. package/configure/CHANGELOG.md +1959 -0
  7. package/configure/lib/defaults.js +224 -0
  8. package/configure/lib/defaults.js.map +1 -0
  9. package/configure/lib/index.js +125 -0
  10. package/configure/lib/index.js.map +1 -0
  11. package/configure/lib/main.js +247 -0
  12. package/configure/lib/main.js.map +1 -0
  13. package/configure/package.json +23 -0
  14. package/controller/CHANGELOG.json +362 -0
  15. package/controller/CHANGELOG.md +1183 -0
  16. package/controller/lib/defaults.js +91 -0
  17. package/controller/lib/defaults.js.map +1 -0
  18. package/controller/lib/index.js +101 -0
  19. package/controller/lib/index.js.map +1 -0
  20. package/controller/package.json +16 -0
  21. package/docs/config-schema.json +1782 -0
  22. package/docs/config-schema.json.md +1333 -0
  23. package/docs/demo/config.js +7 -0
  24. package/docs/demo/generate.js +14 -0
  25. package/docs/demo/index.html +3 -0
  26. package/docs/demo/session.js +7 -0
  27. package/docs/pie-schema.json +954 -0
  28. package/docs/pie-schema.json.md +717 -0
  29. package/lib/annotation/annotation-editor.js +636 -0
  30. package/lib/annotation/annotation-editor.js.map +1 -0
  31. package/lib/annotation/annotation-menu.js +147 -0
  32. package/lib/annotation/annotation-menu.js.map +1 -0
  33. package/lib/annotation/annotation-utils.js +205 -0
  34. package/lib/annotation/annotation-utils.js.map +1 -0
  35. package/lib/annotation/freeform-editor.js +241 -0
  36. package/lib/annotation/freeform-editor.js.map +1 -0
  37. package/lib/index.js +108 -0
  38. package/lib/index.js.map +1 -0
  39. package/lib/main.js +205 -0
  40. package/lib/main.js.map +1 -0
  41. package/lib/print.js +86 -0
  42. package/lib/print.js.map +1 -0
  43. package/module/configure.js +1 -0
  44. package/module/controller.js +139 -0
  45. package/module/demo.js +38 -0
  46. package/module/element.js +1 -0
  47. package/module/index.html +21 -0
  48. package/module/manifest.json +22 -0
  49. package/module/print-demo.js +76 -0
  50. package/module/print.html +18 -0
  51. package/module/print.js +1 -0
  52. package/package.json +22 -87
  53. package/configure.js +0 -2
  54. package/controller.js +0 -1
  55. package/dist/author/defaults.d.ts +0 -166
  56. package/dist/author/defaults.js +0 -209
  57. package/dist/author/index.d.ts +0 -52
  58. package/dist/author/index.js +0 -74
  59. package/dist/author/main.d.ts +0 -26
  60. package/dist/author/main.js +0 -166
  61. package/dist/browser/author/index.js +0 -495
  62. package/dist/browser/author/index.js.map +0 -1
  63. package/dist/browser/browser-kkT1XVKw.js +0 -219
  64. package/dist/browser/browser-kkT1XVKw.js.map +0 -1
  65. package/dist/browser/controller/index.js +0 -184
  66. package/dist/browser/controller/index.js.map +0 -1
  67. package/dist/browser/delivery/index.js +0 -98
  68. package/dist/browser/delivery/index.js.map +0 -1
  69. package/dist/browser/dist-BCJzhghM.js +0 -47879
  70. package/dist/browser/dist-BCJzhghM.js.map +0 -1
  71. package/dist/browser/extended-text-entry.css +0 -2
  72. package/dist/browser/main-VcQEFn-b.js +0 -714
  73. package/dist/browser/main-VcQEFn-b.js.map +0 -1
  74. package/dist/browser/print/index.js +0 -48
  75. package/dist/browser/print/index.js.map +0 -1
  76. package/dist/controller/defaults.d.ts +0 -33
  77. package/dist/controller/defaults.js +0 -104
  78. package/dist/controller/index.d.ts +0 -59
  79. package/dist/controller/index.js +0 -72
  80. package/dist/delivery/annotation/annotation-editor.d.ts +0 -47
  81. package/dist/delivery/annotation/annotation-editor.js +0 -296
  82. package/dist/delivery/annotation/annotation-menu.d.ts +0 -25
  83. package/dist/delivery/annotation/annotation-menu.js +0 -113
  84. package/dist/delivery/annotation/annotation-utils.d.ts +0 -20
  85. package/dist/delivery/annotation/annotation-utils.js +0 -65
  86. package/dist/delivery/annotation/freeform-editor.d.ts +0 -30
  87. package/dist/delivery/annotation/freeform-editor.js +0 -143
  88. package/dist/delivery/index.d.ts +0 -23
  89. package/dist/delivery/index.js +0 -68
  90. package/dist/delivery/main.d.ts +0 -27
  91. package/dist/delivery/main.js +0 -134
  92. package/dist/extended-text-entry.css +0 -2
  93. package/dist/index.d.ts +0 -1
  94. package/dist/index.iife.d.ts +0 -8
  95. package/dist/index.iife.js +0 -403
  96. package/dist/index.js +0 -2
  97. package/dist/print/index.d.ts +0 -15
  98. package/dist/print/index.js +0 -48
  99. package/dist/runtime-support.d.ts +0 -12
  100. package/dist/runtime-support.js +0 -12
@@ -0,0 +1,636 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _styles = require("@mui/material/styles");
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _annotationUtils = require("./annotation-utils");
13
+ var _freeformEditor = _interopRequireDefault(require("./freeform-editor"));
14
+ var _annotationMenu = _interopRequireDefault(require("./annotation-menu"));
15
+ var _editableHtmlTipTap = _interopRequireDefault(require("@pie-lib/editable-html-tip-tap"));
16
+ var _configUi = require("@pie-lib/config-ui");
17
+ const TextContainer = (0, _styles.styled)('div')({
18
+ padding: '10px 120px 10px 16px',
19
+ backgroundColor: 'rgba(0, 0, 0, 0.06)',
20
+ border: '1px solid #ccc',
21
+ borderRadius: '4px',
22
+ overflowY: 'scroll',
23
+ lineHeight: '36px',
24
+ whiteSpace: 'pre-wrap',
25
+ overflowWrap: 'break-word',
26
+ '& p': {
27
+ margin: 0
28
+ },
29
+ '& span[data-latex]': {
30
+ userSelect: 'none',
31
+ '-webkit-user-select': 'none',
32
+ '-moz-user-select': 'none',
33
+ '-ms-user-select': 'none'
34
+ }
35
+ });
36
+ const LabelsContainer = (0, _styles.styled)('div')({
37
+ width: '230px'
38
+ });
39
+ const Wrapper = (0, _styles.styled)('div')({
40
+ position: 'relative',
41
+ overflowX: 'hidden',
42
+ display: 'flex'
43
+ });
44
+ const CommentContainer = (0, _styles.styled)(_configUi.InputContainer)(({
45
+ theme
46
+ }) => ({
47
+ paddingTop: theme.spacing(2),
48
+ marginBottom: theme.spacing(2),
49
+ marginTop: theme.spacing(2),
50
+ width: '100%'
51
+ }));
52
+
53
+ // Global styles for pseudo-elements that can't be applied inline
54
+ const globalStyles = `
55
+ .sideAnnotation:before {
56
+ position: absolute;
57
+ right: var(--before-right, 100%);
58
+ top: var(--before-top, 5px);
59
+ border: solid transparent;
60
+ content: "";
61
+ height: 0;
62
+ width: 0;
63
+ pointer-events: none;
64
+ border-width: var(--before-border-width, 7px);
65
+ border-right-color: var(--before-border-color, rgb(153, 255, 153));
66
+ }
67
+ `;
68
+
69
+ // Inject styles if not already injected
70
+ if (!document.getElementById('annotation-editor-styles')) {
71
+ const styleElement = document.createElement('style');
72
+ styleElement.id = 'annotation-editor-styles';
73
+ styleElement.textContent = globalStyles;
74
+ document.head.appendChild(styleElement);
75
+ }
76
+ class AnnotationEditor extends _react.default.Component {
77
+ constructor(props) {
78
+ super(props);
79
+ (0, _defineProperty2.default)(this, "adjustAnnotationsPosition", () => {
80
+ if (this.textRef && this.labelsRef) {
81
+ const left = this.textRef.offsetLeft + this.textRef.offsetWidth + 8;
82
+ Array.from(this.labelsRef.children).forEach(label => {
83
+ const spans = (0, _annotationUtils.getAnnotationElements)(label.dataset.annId);
84
+ const spanOffset = spans[0].offsetTop ? spans[0].offsetTop : spans[0].offsetParent.offsetTop;
85
+ const top = spanOffset - this.textRef.scrollTop - 6;
86
+ label.style.top = `${top}px`;
87
+ label.style.left = `${left}px`;
88
+ });
89
+ }
90
+ });
91
+ (0, _defineProperty2.default)(this, "handleClick", event => {
92
+ const {
93
+ annotations
94
+ } = this.props;
95
+ const {
96
+ selectionDetails
97
+ } = this.state;
98
+ if (selectionDetails) {
99
+ // new selection was made inside another annotation and should not update that annotation
100
+ return;
101
+ }
102
+ const {
103
+ id,
104
+ annId
105
+ } = event.target.dataset;
106
+ const annotationId = id || annId;
107
+ const selectedElems = (0, _annotationUtils.getAnnotationElements)(annotationId);
108
+ const labelElem = (0, _annotationUtils.getLabelElement)(annotationId);
109
+ const annotationIndex = annotations.findIndex(annotation => annotation.id === annotationId);
110
+ const isSideLabel = labelElem.hasAttribute('data-freeform');
111
+ if (isSideLabel) {
112
+ labelElem.style.zIndex = '10';
113
+ }
114
+ this.setState({
115
+ anchorEl: selectedElems[0],
116
+ openedMenu: !!id || !!annId && !isSideLabel,
117
+ // true if the annotation or the label was clicked
118
+ openedEditor: !!annId && isSideLabel,
119
+ // true if the side label was clicked
120
+ selectedElems,
121
+ labelElem,
122
+ annotationIndex,
123
+ annotation: annotations[annotationIndex],
124
+ selectionDetails: null
125
+ });
126
+ });
127
+ (0, _defineProperty2.default)(this, "handleHover", event => {
128
+ const {
129
+ id,
130
+ annId
131
+ } = event.target.dataset;
132
+ const annotationId = id || annId;
133
+ const selectedElems = (0, _annotationUtils.getAnnotationElements)(annotationId);
134
+ const labelElem = (0, _annotationUtils.getLabelElement)(annotationId);
135
+ const isSideLabel = labelElem.hasAttribute('data-freeform');
136
+ selectedElems.forEach(elem => {
137
+ elem.style.zIndex = '20';
138
+ if (elem.classList.contains('positive')) {
139
+ elem.style.backgroundColor = 'rgb(51, 255, 51, 0.7)';
140
+ } else if (elem.classList.contains('negative')) {
141
+ elem.style.backgroundColor = 'rgba(255, 102, 204, 0.55)';
142
+ }
143
+ });
144
+ if (isSideLabel) {
145
+ labelElem.style.zIndex = '20';
146
+ if (labelElem.classList.contains('positive')) {
147
+ labelElem.style.backgroundColor = 'rgb(128, 255, 128)';
148
+ labelElem.style.setProperty('--before-border-color', 'rgb(153, 255, 153)');
149
+ } else if (labelElem.classList.contains('negative')) {
150
+ labelElem.style.backgroundColor = 'rgb(255, 179, 230)';
151
+ labelElem.style.setProperty('--before-border-color', 'rgb(255, 179, 230)');
152
+ }
153
+ } else {
154
+ labelElem.style.zIndex = '20';
155
+ if (labelElem.classList.contains('positive')) {
156
+ labelElem.style.color = 'rgb(0, 77, 0)';
157
+ } else if (labelElem.classList.contains('negative')) {
158
+ labelElem.style.color = 'rgb(153, 0, 102)';
159
+ }
160
+ }
161
+ });
162
+ (0, _defineProperty2.default)(this, "handleCancelHover", event => {
163
+ const {
164
+ id,
165
+ annId
166
+ } = event.target.dataset;
167
+ const annotationId = id || annId;
168
+ const selectedElems = (0, _annotationUtils.getAnnotationElements)(annotationId);
169
+ const labelElem = (0, _annotationUtils.getLabelElement)(annotationId);
170
+ const isSideLabel = labelElem.hasAttribute('data-freeform');
171
+ selectedElems.forEach(elem => {
172
+ elem.style.zIndex = '';
173
+ if (elem.classList.contains('positive')) {
174
+ elem.style.backgroundColor = 'rgb(51, 255, 51, 0.5)';
175
+ } else if (elem.classList.contains('negative')) {
176
+ elem.style.backgroundColor = 'rgba(255, 102, 204, 0.4)';
177
+ }
178
+ });
179
+ if (isSideLabel) {
180
+ labelElem.style.zIndex = '';
181
+ if (labelElem.classList.contains('positive')) {
182
+ labelElem.style.backgroundColor = 'rgb(153, 255, 153)';
183
+ labelElem.style.removeProperty('--before-border-color');
184
+ } else if (labelElem.classList.contains('negative')) {
185
+ labelElem.style.backgroundColor = 'rgb(255, 204, 238)';
186
+ labelElem.style.removeProperty('--before-border-color');
187
+ }
188
+ } else {
189
+ labelElem.style.zIndex = '';
190
+ if (labelElem.classList.contains('positive')) {
191
+ labelElem.style.color = 'rgb(0, 128, 0)';
192
+ } else if (labelElem.classList.contains('negative')) {
193
+ labelElem.style.color = 'rgb(204, 0, 136)';
194
+ }
195
+ }
196
+ });
197
+ (0, _defineProperty2.default)(this, "handleClose", event => {
198
+ const {
199
+ selectedElems,
200
+ labelElem
201
+ } = this.state;
202
+ if (selectedElems.length && !selectedElems[0].hasAttribute('data-id')) {
203
+ (0, _annotationUtils.removeElemsWrapping)(selectedElems, this.textRef);
204
+ }
205
+ if (labelElem) {
206
+ labelElem.style.zIndex = '';
207
+ }
208
+ this.setState({
209
+ anchorEl: null,
210
+ openedMenu: false,
211
+ openedEditor: false,
212
+ selectedElems: [],
213
+ labelElem: null,
214
+ selectionDetails: null,
215
+ annotationIndex: null,
216
+ annotation: null
217
+ });
218
+ (0, _annotationUtils.clearSelection)();
219
+ });
220
+ (0, _defineProperty2.default)(this, "handleSelection", event => {
221
+ const selection = window.getSelection();
222
+
223
+ // prevent unwanted selections
224
+ if (event.detail > 2) {
225
+ (0, _annotationUtils.clearSelection)();
226
+ return;
227
+ }
228
+ if (selection && selection.rangeCount > 0) {
229
+ const selectedRange = selection.getRangeAt(0);
230
+ const selectedText = selectedRange.toString();
231
+ const isSelectionInside = this.textRef.contains(selectedRange.commonAncestorContainer);
232
+ if (!selection.isCollapsed && selectedText !== '' && isSelectionInside) {
233
+ const selectionDetails = (0, _annotationUtils.getRangeDetails)(selectedRange, this.textRef);
234
+ const selectedElems = (0, _annotationUtils.wrapRange)(selectedRange);
235
+ this.setState({
236
+ anchorEl: selectedElems[0],
237
+ openedMenu: true,
238
+ selectedElems,
239
+ selectionDetails
240
+ });
241
+ }
242
+ }
243
+ });
244
+ (0, _defineProperty2.default)(this, "deleteAnnotation", () => {
245
+ const {
246
+ annotations,
247
+ onChange
248
+ } = this.props;
249
+ const {
250
+ selectedElems,
251
+ labelElem,
252
+ annotationIndex,
253
+ annotation
254
+ } = this.state;
255
+ const parentRef = (0, _annotationUtils.isSideLabel)(annotation.label) ? this.labelsRef : selectedElems[0];
256
+ parentRef.removeChild(labelElem);
257
+ (0, _annotationUtils.removeElemsWrapping)(selectedElems, this.textRef);
258
+ annotations.splice(annotationIndex, 1);
259
+ onChange(annotations);
260
+ this.handleClose();
261
+ });
262
+ (0, _defineProperty2.default)(this, "createDOMAnnotation", (elems, annotation) => {
263
+ const {
264
+ disabled
265
+ } = this.props;
266
+ const {
267
+ id,
268
+ label,
269
+ type
270
+ } = annotation;
271
+ (elems || []).forEach(elem => {
272
+ elem.dataset.id = id;
273
+ elem.className = `annotation ${type}`;
274
+ // Apply annotation styles directly
275
+ elem.style.position = 'relative';
276
+ elem.style.cursor = 'pointer';
277
+ if (type === 'positive') {
278
+ elem.style.backgroundColor = 'rgb(51, 255, 51, 0.5)';
279
+ } else if (type === 'negative') {
280
+ elem.style.backgroundColor = 'rgba(255, 102, 204, 0.4)';
281
+ }
282
+ elem.onclick = !disabled && this.handleClick;
283
+ elem.onmouseover = this.handleHover;
284
+ elem.onmouseout = this.handleCancelHover;
285
+ });
286
+ const firstSpan = elems && elems[0] || {};
287
+ const labelElem = document.createElement('SPAN');
288
+ labelElem.dataset.annId = id;
289
+ labelElem.innerHTML = label;
290
+ labelElem.onclick = !disabled && this.handleClick;
291
+ labelElem.onmouseover = this.handleHover;
292
+ labelElem.onmouseout = this.handleCancelHover;
293
+ if ((0, _annotationUtils.isSideLabel)(label)) {
294
+ const spanOffset = firstSpan.offsetTop ? firstSpan.offsetTop : firstSpan.offsetParent.offsetTop;
295
+ const top = spanOffset - this.textRef.scrollTop;
296
+ const left = this.textRef.offsetLeft + this.textRef.offsetWidth + 8;
297
+ labelElem.dataset.freeform = true;
298
+ labelElem.className = `sideAnnotation ${type}`;
299
+
300
+ // Apply side annotation styles directly
301
+ labelElem.style.position = 'absolute';
302
+ labelElem.style.padding = '4px';
303
+ labelElem.style.borderRadius = '4px';
304
+ labelElem.style.marginLeft = '8px';
305
+ labelElem.style.width = '180px';
306
+ labelElem.style.whiteSpace = 'pre-wrap';
307
+ labelElem.style.wordBreak = 'break-word';
308
+ labelElem.style.border = '2px solid #ffffff';
309
+ labelElem.style.fontSize = '14px';
310
+ labelElem.style.fontStyle = 'normal';
311
+ labelElem.style.fontWeight = 'normal';
312
+ labelElem.style.top = `${top}px`;
313
+ labelElem.style.left = `${left}px`;
314
+ if (type === 'negative') {
315
+ labelElem.style.backgroundColor = 'rgb(255, 204, 238)';
316
+ } else if (type === 'positive') {
317
+ labelElem.style.backgroundColor = 'rgb(153, 255, 153)';
318
+ }
319
+
320
+ // Add pseudo-element styles via CSS
321
+ labelElem.style.setProperty('--before-border-width', '7px');
322
+ labelElem.style.setProperty('--before-top', '5px');
323
+ labelElem.style.setProperty('--before-right', '100%');
324
+ if (type === 'negative') {
325
+ labelElem.style.setProperty('--before-border-color', 'rgb(255, 204, 238)');
326
+ } else if (type === 'positive') {
327
+ labelElem.style.setProperty('--before-border-color', 'rgb(153, 255, 153)');
328
+ }
329
+ this.labelsRef.appendChild(labelElem);
330
+ } else {
331
+ labelElem.className = `annotationLabel ${type}`;
332
+
333
+ // Apply annotation label styles directly
334
+ labelElem.style.backgroundColor = 'rgb(242, 242, 242)';
335
+ labelElem.style.padding = '2px';
336
+ labelElem.style.position = 'absolute';
337
+ labelElem.style.userSelect = 'none';
338
+ labelElem.style.whiteSpace = 'nowrap';
339
+ labelElem.style.top = '-10px';
340
+ labelElem.style.left = '-2px';
341
+ labelElem.style.fontSize = '12px';
342
+ labelElem.style.fontStyle = 'normal';
343
+ labelElem.style.fontWeight = 'normal';
344
+ labelElem.style.lineHeight = '6px';
345
+ labelElem.style.webkitUserSelect = 'none';
346
+ labelElem.style.mozUserSelect = 'none';
347
+ labelElem.style.msUserSelect = 'none';
348
+ if (type === 'positive') {
349
+ labelElem.style.color = 'rgb(0, 128, 0)';
350
+ } else if (type === 'negative') {
351
+ labelElem.style.color = 'rgb(204, 0, 136)';
352
+ }
353
+ firstSpan.appendChild(labelElem);
354
+ }
355
+ });
356
+ (0, _defineProperty2.default)(this, "createNewAnnotation", (label, type) => {
357
+ const {
358
+ selectedElems,
359
+ selectionDetails
360
+ } = this.state;
361
+ const annotation = {
362
+ id: [selectionDetails.start, selectionDetails.end, new Date().getTime()].join('-'),
363
+ label,
364
+ type,
365
+ ...selectionDetails
366
+ };
367
+ this.createDOMAnnotation(selectedElems, annotation);
368
+ return annotation;
369
+ });
370
+ (0, _defineProperty2.default)(this, "handleMenuClick", newAnnotation => {
371
+ const {
372
+ annotations,
373
+ onChange
374
+ } = this.props;
375
+ const {
376
+ annotation,
377
+ annotationIndex
378
+ } = this.state;
379
+ const {
380
+ type,
381
+ text: label
382
+ } = newAnnotation;
383
+ if (annotation) {
384
+ const updatedAnnotation = {
385
+ ...annotation,
386
+ label,
387
+ type
388
+ };
389
+ const {
390
+ type: oldType,
391
+ label: oldLabel
392
+ } = annotation;
393
+ this.updateLabel(oldLabel, updatedAnnotation, type !== oldType && oldType);
394
+ annotations.splice(annotationIndex, 1, updatedAnnotation);
395
+ } else {
396
+ const newAnnotation = this.createNewAnnotation(label, type);
397
+ annotations.push(newAnnotation);
398
+ }
399
+ onChange(annotations);
400
+ this.handleClose();
401
+ });
402
+ (0, _defineProperty2.default)(this, "editAnnotation", () => {
403
+ this.setState({
404
+ openedMenu: false,
405
+ openedEditor: true
406
+ });
407
+ });
408
+ (0, _defineProperty2.default)(this, "addAnnotation", type => {
409
+ const {
410
+ annotations,
411
+ onChange
412
+ } = this.props;
413
+ const annotation = this.createNewAnnotation('', type);
414
+ const labelElem = (0, _annotationUtils.getLabelElement)(annotation.id);
415
+ annotations.push(annotation);
416
+ this.setState({
417
+ openedMenu: false,
418
+ openedEditor: true,
419
+ annotationIndex: annotations.length - 1,
420
+ annotation,
421
+ labelElem
422
+ });
423
+ onChange(annotations);
424
+ });
425
+ (0, _defineProperty2.default)(this, "updateLabel", (oldLabel, annotation, oldType) => {
426
+ const {
427
+ selectedElems,
428
+ labelElem
429
+ } = this.state;
430
+ const {
431
+ label,
432
+ type
433
+ } = annotation;
434
+ if ((0, _annotationUtils.isSideLabel)(label) && (0, _annotationUtils.isSideLabel)(oldLabel) || !(0, _annotationUtils.isSideLabel)(label) && !(0, _annotationUtils.isSideLabel)(oldLabel)) {
435
+ labelElem.innerHTML = label;
436
+ if (oldType) {
437
+ labelElem.classList.remove(oldType);
438
+ labelElem.classList.add(type);
439
+ selectedElems.forEach(elem => {
440
+ elem.classList.remove(oldType);
441
+ elem.classList.add(type);
442
+ });
443
+ }
444
+ } else if ((0, _annotationUtils.isSideLabel)(label) && !(0, _annotationUtils.isSideLabel)(oldLabel)) {
445
+ selectedElems[0].removeChild(labelElem);
446
+ this.createDOMAnnotation(selectedElems, annotation);
447
+ } else if (!(0, _annotationUtils.isSideLabel)(label) && (0, _annotationUtils.isSideLabel)(oldLabel)) {
448
+ this.labelsRef.removeChild(labelElem);
449
+ this.createDOMAnnotation(selectedElems, annotation);
450
+ }
451
+ });
452
+ (0, _defineProperty2.default)(this, "changeAnnotationType", newLabel => {
453
+ const {
454
+ annotations,
455
+ onChange
456
+ } = this.props;
457
+ const {
458
+ annotationIndex,
459
+ selectedElems
460
+ } = this.state;
461
+ const {
462
+ type: oldType,
463
+ label: oldLabel
464
+ } = annotations[annotationIndex];
465
+ const type = oldType === 'positive' ? 'negative' : 'positive';
466
+ const updatedAnnotation = {
467
+ ...annotations[annotationIndex],
468
+ type,
469
+ label: newLabel
470
+ };
471
+ selectedElems.forEach(span => {
472
+ span.classList.remove(oldType);
473
+ span.classList.add(type);
474
+ });
475
+ this.updateLabel(oldLabel, updatedAnnotation, oldType);
476
+ annotations.splice(annotationIndex, 1, updatedAnnotation);
477
+ onChange(annotations);
478
+ this.handleClose();
479
+ });
480
+ (0, _defineProperty2.default)(this, "updateAnnotation", (oldLabel, newLabel) => {
481
+ const {
482
+ annotations,
483
+ onChange
484
+ } = this.props;
485
+ const {
486
+ annotationIndex
487
+ } = this.state;
488
+ const updatedAnnotation = {
489
+ ...annotations[annotationIndex],
490
+ label: newLabel
491
+ };
492
+ this.updateLabel(oldLabel, updatedAnnotation);
493
+ annotations.splice(annotationIndex, 1, updatedAnnotation);
494
+ onChange(annotations);
495
+ });
496
+ this.state = {
497
+ anchorEl: null,
498
+ openedMenu: false,
499
+ openedEditor: false,
500
+ selectedElems: [],
501
+ labelElem: null,
502
+ selectionDetails: null,
503
+ annotation: null,
504
+ annotationIndex: null
505
+ };
506
+ }
507
+ componentDidMount() {
508
+ const {
509
+ annotations,
510
+ text
511
+ } = this.props;
512
+ if (text) {
513
+ annotations.forEach(annotation => {
514
+ const [domStart, domEnd] = (0, _annotationUtils.getDOMNodes)(annotation.start, annotation.end, this.textRef);
515
+ if (domStart && domEnd) {
516
+ const range = document.createRange();
517
+ range.setStart(domStart.node, domStart.offset);
518
+ range.setEnd(domEnd.node, domEnd.offset);
519
+ const spans = (0, _annotationUtils.wrapRange)(range);
520
+ this.createDOMAnnotation(spans, annotation);
521
+ }
522
+ });
523
+ }
524
+ if (this.textRef) {
525
+ this.adjustAnnotationsPosition();
526
+ this.textRef.addEventListener('scroll', this.adjustAnnotationsPosition);
527
+ }
528
+ }
529
+ componentWillUnmount() {
530
+ this.textRef.removeEventListener('scroll', this.adjustAnnotationsPosition);
531
+ }
532
+ render() {
533
+ const {
534
+ comment,
535
+ customKeys,
536
+ disabled,
537
+ disabledMath,
538
+ keypadMode,
539
+ height,
540
+ width,
541
+ maxHeight,
542
+ onCommentChange,
543
+ predefinedAnnotations,
544
+ text
545
+ } = this.props;
546
+ const {
547
+ anchorEl,
548
+ annotation,
549
+ openedMenu,
550
+ openedEditor,
551
+ selectionDetails
552
+ } = this.state;
553
+ const anchorOffset = anchorEl && (anchorEl.offsetTop ? anchorEl.offsetTop : anchorEl.offsetParent.offsetTop);
554
+ const topOffset = this.textRef && anchorOffset ? anchorOffset - this.textRef.scrollTop - 8 : 0;
555
+ return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Wrapper, null, /*#__PURE__*/_react.default.createElement(TextContainer, {
556
+ style: {
557
+ width: width - 34,
558
+ minHeight: height,
559
+ maxHeight: maxHeight
560
+ },
561
+ ref: r => this.textRef = r,
562
+ onMouseDown: !disabled ? _annotationUtils.clearSelection : () => {},
563
+ onMouseUp: !disabled ? this.handleSelection : () => {},
564
+ dangerouslySetInnerHTML: {
565
+ __html: text
566
+ }
567
+ }), /*#__PURE__*/_react.default.createElement(LabelsContainer, {
568
+ ref: r => this.labelsRef = r
569
+ })), /*#__PURE__*/_react.default.createElement(CommentContainer, {
570
+ label: 'Comment'
571
+ }, /*#__PURE__*/_react.default.createElement(_editableHtmlTipTap.default, {
572
+ className: "prompt",
573
+ markup: comment || '',
574
+ onChange: onCommentChange,
575
+ width: width && (width + 104).toString(),
576
+ disabled: disabled,
577
+ pluginProps: {
578
+ math: {
579
+ disabled: disabledMath,
580
+ customKeys: customKeys,
581
+ keypadMode: keypadMode,
582
+ controlledKeypadMode: false
583
+ },
584
+ video: {
585
+ disabled: true
586
+ },
587
+ audio: {
588
+ disabled: true
589
+ },
590
+ textAlign: {
591
+ disabled: true
592
+ },
593
+ h3: {
594
+ disabled: true
595
+ }
596
+ }
597
+ })), /*#__PURE__*/_react.default.createElement(_annotationMenu.default, {
598
+ anchorEl: anchorEl,
599
+ open: openedMenu && !disabled,
600
+ annotations: predefinedAnnotations,
601
+ isNewAnnotation: !!selectionDetails,
602
+ onClose: this.handleClose,
603
+ onDelete: this.deleteAnnotation,
604
+ onEdit: this.editAnnotation,
605
+ onWrite: this.addAnnotation,
606
+ onAnnotate: this.handleMenuClick
607
+ }), /*#__PURE__*/_react.default.createElement(_freeformEditor.default, {
608
+ anchorEl: this.textRef,
609
+ open: openedEditor && !disabled,
610
+ offset: topOffset,
611
+ value: annotation && annotation.label || '',
612
+ type: annotation && annotation.type,
613
+ onClose: this.handleClose,
614
+ onDelete: this.deleteAnnotation,
615
+ onSave: this.updateAnnotation,
616
+ onTypeChange: this.changeAnnotationType
617
+ }));
618
+ }
619
+ }
620
+ (0, _defineProperty2.default)(AnnotationEditor, "propTypes", {
621
+ text: _propTypes.default.string,
622
+ comment: _propTypes.default.string,
623
+ annotations: _propTypes.default.array,
624
+ predefinedAnnotations: _propTypes.default.array,
625
+ onChange: _propTypes.default.func.isRequired,
626
+ onCommentChange: _propTypes.default.func.isRequired,
627
+ width: _propTypes.default.number,
628
+ height: _propTypes.default.number,
629
+ maxHeight: _propTypes.default.string,
630
+ disabled: _propTypes.default.bool,
631
+ disabledMath: _propTypes.default.bool,
632
+ customKeys: _propTypes.default.array,
633
+ keypadMode: _propTypes.default.string
634
+ });
635
+ var _default = exports.default = AnnotationEditor;
636
+ //# sourceMappingURL=annotation-editor.js.map