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