@searpent/react-image-annotate 2.0.5 → 2.0.8

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 (195) hide show
  1. package/Annotator/examplePhotos.js +6976 -0
  2. package/Annotator/index.js +268 -0
  3. package/Annotator/reducers/combine-reducers.js +14 -0
  4. package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
  5. package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
  6. package/Annotator/reducers/general-reducer.js +1152 -0
  7. package/Annotator/reducers/get-active-image.js +27 -0
  8. package/Annotator/reducers/get-implied-video-regions.js +180 -0
  9. package/Annotator/reducers/history-handler.js +38 -0
  10. package/Annotator/reducers/image-reducer.js +20 -0
  11. package/Annotator/reducers/video-reducer.js +88 -0
  12. package/ClassSelectionMenu/index.js +135 -0
  13. package/Crosshairs/index.js +53 -0
  14. package/DebugSidebarBox/index.js +20 -0
  15. package/DemoSite/Editor.js +194 -0
  16. package/DemoSite/ErrorBoundaryDialog.js +64 -0
  17. package/DemoSite/index.js +40 -0
  18. package/{src/Editor → Editor}/annotation-plugin/annotation.css +0 -0
  19. package/Editor/annotation-plugin/annotation.js +613 -0
  20. package/Editor/index.js +57 -0
  21. package/{src/Editor → Editor}/tools.js +2 -3
  22. package/FullImageSegmentationAnnotator/index.js +7 -0
  23. package/GroupSelectorSidebarBox/index.js +63 -0
  24. package/HighlightBox/index.js +99 -0
  25. package/HistorySidebarBox/index.js +71 -0
  26. package/ImageCanvas/index.js +429 -0
  27. package/ImageCanvas/region-tools.js +165 -0
  28. package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
  29. package/ImageCanvas/use-mouse.js +180 -0
  30. package/ImageCanvas/use-project-box.js +27 -0
  31. package/ImageCanvas/use-wasd-mode.js +62 -0
  32. package/ImageMask/index.js +133 -0
  33. package/ImageMask/load-image.js +25 -0
  34. package/ImageSelectorSidebarBox/index.js +60 -0
  35. package/KeyframeTimeline/get-time-string.js +27 -0
  36. package/KeyframeTimeline/index.js +233 -0
  37. package/KeyframesSelectorSidebarBox/index.js +93 -0
  38. package/LandingPage/index.js +159 -0
  39. package/MainLayout/icon-dictionary.js +104 -0
  40. package/MainLayout/index.js +469 -0
  41. package/{src/MainLayout → MainLayout}/styles.js +6 -7
  42. package/MainLayout/types.js +0 -0
  43. package/MainLayout/use-implied-video-regions.js +13 -0
  44. package/MetadataEditorSidebarBox/index.js +126 -0
  45. package/PageSelector/index.js +69 -0
  46. package/{src/PageSelector → PageSelector}/page-selector.css +18 -0
  47. package/PointDistances/index.js +73 -0
  48. package/PreventScrollToParents/index.js +51 -0
  49. package/RegionLabel/index.js +205 -0
  50. package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
  51. package/RegionSelectAndTransformBoxes/index.js +167 -0
  52. package/RegionSelectorSidebarBox/index.js +248 -0
  53. package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
  54. package/RegionShapes/index.js +294 -0
  55. package/RegionTags/index.js +142 -0
  56. package/SettingsDialog/index.js +52 -0
  57. package/SettingsProvider/index.js +58 -0
  58. package/Shortcuts/ShortcutField.js +46 -0
  59. package/Shortcuts/index.js +133 -0
  60. package/ShortcutsManager/index.js +155 -0
  61. package/Sidebar/index.js +69 -0
  62. package/SidebarBoxContainer/index.js +93 -0
  63. package/SmallToolButton/index.js +42 -0
  64. package/TagsSidebarBox/index.js +105 -0
  65. package/TaskDescriptionSidebarBox/index.js +58 -0
  66. package/Theme/index.js +30 -0
  67. package/VideoOrImageCanvasBackground/index.js +151 -0
  68. package/colors.js +14 -0
  69. package/hooks/use-colors.js +101 -0
  70. package/hooks/use-event-callback.js +10 -0
  71. package/hooks/use-exclude-pattern.js +24 -0
  72. package/hooks/use-load-image.js +26 -0
  73. package/hooks/use-window-size.js +46 -0
  74. package/{src/hooks → hooks}/xpattern.js +1 -1
  75. package/index.js +3 -0
  76. package/lib.js +3 -0
  77. package/package.json +1 -1
  78. package/stories.js +5 -0
  79. package/{src/utils → utils}/filter-only-unique.js +1 -1
  80. package/utils/get-from-local-storage.js +7 -0
  81. package/utils/get-hotkey-help-text.js +9 -0
  82. package/utils/get-landmarks-with-transform.js +40 -0
  83. package/utils/photosToImages.js +53 -0
  84. package/utils/regions-to-blocks.js +16 -0
  85. package/utils/set-in-local-storage.js +3 -0
  86. package/.babelrc +0 -6
  87. package/.env +0 -1
  88. package/.flowconfig +0 -2
  89. package/.github/workflows/release-on-master.yml +0 -32
  90. package/.github/workflows/test.yml +0 -16
  91. package/.prettierrc +0 -3
  92. package/.releaserc.js +0 -18
  93. package/.storybook/addons.js +0 -2
  94. package/.storybook/config.js +0 -16
  95. package/LICENSE +0 -21
  96. package/public/favicon.ico +0 -0
  97. package/public/index.html +0 -38
  98. package/src/Annotator/bike-pic.png +0 -0
  99. package/src/Annotator/bike-pic2.png +0 -0
  100. package/src/Annotator/dab-keyframes.story.json +0 -1
  101. package/src/Annotator/examplePhotos.js +0 -7601
  102. package/src/Annotator/index.js +0 -291
  103. package/src/Annotator/index.story.js +0 -807
  104. package/src/Annotator/poses.story.js +0 -150
  105. package/src/Annotator/reducers/combine-reducers.js +0 -7
  106. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
  107. package/src/Annotator/reducers/general-reducer.js +0 -996
  108. package/src/Annotator/reducers/get-active-image.js +0 -21
  109. package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
  110. package/src/Annotator/reducers/history-handler.js +0 -60
  111. package/src/Annotator/reducers/image-reducer.js +0 -23
  112. package/src/Annotator/reducers/video-reducer.js +0 -85
  113. package/src/Annotator/video.story.js +0 -51
  114. package/src/ClassSelectionMenu/index.js +0 -108
  115. package/src/Crosshairs/index.js +0 -64
  116. package/src/DebugSidebarBox/index.js +0 -36
  117. package/src/DemoSite/Editor.js +0 -235
  118. package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
  119. package/src/DemoSite/index.js +0 -41
  120. package/src/DemoSite/index.story.js +0 -10
  121. package/src/DemoSite/simple-segmentation-example.json +0 -572
  122. package/src/Editor/annotation-plugin/annotation.js +0 -515
  123. package/src/Editor/index.js +0 -24
  124. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  125. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  126. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  127. package/src/FullImageSegmentationAnnotator/index.js +0 -7
  128. package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
  129. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  130. package/src/GroupSelectorSidebarBox/index.js +0 -48
  131. package/src/HighlightBox/index.js +0 -143
  132. package/src/HistorySidebarBox/index.js +0 -78
  133. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  134. package/src/ImageCanvas/index.js +0 -494
  135. package/src/ImageCanvas/index.story.js +0 -314
  136. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  137. package/src/ImageCanvas/region-tools.js +0 -171
  138. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  139. package/src/ImageCanvas/use-mouse.js +0 -168
  140. package/src/ImageCanvas/use-project-box.js +0 -23
  141. package/src/ImageCanvas/use-wasd-mode.js +0 -50
  142. package/src/ImageMask/index.js +0 -127
  143. package/src/ImageMask/load-image.js +0 -32
  144. package/src/ImageSelectorSidebarBox/index.js +0 -54
  145. package/src/KeyframeTimeline/get-time-string.js +0 -25
  146. package/src/KeyframeTimeline/index.js +0 -223
  147. package/src/KeyframesSelectorSidebarBox/index.js +0 -93
  148. package/src/LandingPage/content.md +0 -57
  149. package/src/LandingPage/github-markdown.css +0 -964
  150. package/src/LandingPage/index.js +0 -147
  151. package/src/MainLayout/icon-dictionary.js +0 -79
  152. package/src/MainLayout/index.js +0 -510
  153. package/src/MainLayout/index.story.js +0 -240
  154. package/src/MainLayout/types.js +0 -164
  155. package/src/MainLayout/use-implied-video-regions.js +0 -17
  156. package/src/MetadataEditorSidebarBox/index.js +0 -98
  157. package/src/PageSelector/index.js +0 -76
  158. package/src/PointDistances/index.js +0 -90
  159. package/src/PreventScrollToParents/index.js +0 -48
  160. package/src/PreventScrollToParents/index.story.js +0 -23
  161. package/src/RegionLabel/index.js +0 -222
  162. package/src/RegionSelectAndTransformBoxes/index.js +0 -234
  163. package/src/RegionSelectorSidebarBox/index.js +0 -216
  164. package/src/RegionShapes/index.js +0 -254
  165. package/src/RegionTags/index.js +0 -134
  166. package/src/SettingsDialog/index.js +0 -58
  167. package/src/SettingsProvider/index.js +0 -48
  168. package/src/Shortcuts/ShortcutField.js +0 -44
  169. package/src/Shortcuts/index.js +0 -129
  170. package/src/ShortcutsManager/index.js +0 -162
  171. package/src/Sidebar/index.js +0 -117
  172. package/src/SidebarBoxContainer/index.js +0 -93
  173. package/src/SmallToolButton/index.js +0 -57
  174. package/src/TagsSidebarBox/index.js +0 -93
  175. package/src/TaskDescriptionSidebarBox/index.js +0 -43
  176. package/src/Theme/index.js +0 -36
  177. package/src/VideoOrImageCanvasBackground/index.js +0 -170
  178. package/src/colors.js +0 -32
  179. package/src/hooks/use-colors.js +0 -74
  180. package/src/hooks/use-event-callback.js +0 -11
  181. package/src/hooks/use-exclude-pattern.js +0 -27
  182. package/src/hooks/use-load-image.js +0 -21
  183. package/src/hooks/use-window-size.js +0 -46
  184. package/src/hooks/xpattern.png +0 -0
  185. package/src/index.js +0 -18
  186. package/src/lib.js +0 -7
  187. package/src/screenshot.png +0 -0
  188. package/src/site.css +0 -5
  189. package/src/stories.js +0 -2
  190. package/src/utils/get-from-local-storage.js +0 -7
  191. package/src/utils/get-hotkey-help-text.js +0 -11
  192. package/src/utils/get-landmarks-with-transform.js +0 -23
  193. package/src/utils/photosToImages.js +0 -40
  194. package/src/utils/regions-to-blocks.js +0 -14
  195. package/src/utils/set-in-local-storage.js +0 -6
@@ -0,0 +1,613 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+
4
+ /**
5
+ * Build styles
6
+ */
7
+ require('./annotation.css').toString(); // Possible classes
8
+ // ================
9
+
10
+
11
+ var Annotation =
12
+ /*#__PURE__*/
13
+ function () {
14
+ /**
15
+ * Render plugin`s main Element and fill it with saved data
16
+ *
17
+ * @param {{data: HeaderData, config: HeaderConfig, api: object}}
18
+ * data — previously saved data
19
+ * config - user config for Tool
20
+ * api - Editor.js API
21
+ * readOnly - read only mode flag
22
+ */
23
+ function Annotation(_ref) {
24
+ var data = _ref.data,
25
+ config = _ref.config,
26
+ api = _ref.api,
27
+ readOnly = _ref.readOnly;
28
+
29
+ _classCallCheck(this, Annotation);
30
+
31
+ this.api = api;
32
+ this.readOnly = readOnly;
33
+ /**
34
+ * Styles
35
+ *
36
+ * @type {object}
37
+ */
38
+
39
+ this._CSS = {
40
+ block: this.api.styles.block,
41
+ settingsButton: this.api.styles.settingsButton,
42
+ settingsButtonActive: this.api.styles.settingsButtonActive,
43
+ wrapper: 'ce-header'
44
+ };
45
+ /**
46
+ * Tool's settings passed from Editor
47
+ *
48
+ * @type {HeaderConfig}
49
+ * @private
50
+ */
51
+
52
+ this._settings = config;
53
+ /**
54
+ * Block's data
55
+ *
56
+ * @type {HeaderData}
57
+ * @private
58
+ */
59
+
60
+ this._data = this.normalizeData(data);
61
+ /**
62
+ * List of settings buttons
63
+ *
64
+ * @type {HTMLElement[]}
65
+ */
66
+
67
+ this.settingsButtons = [];
68
+ /**
69
+ * Main Block wrapper
70
+ *
71
+ * @type {HTMLElement}
72
+ * @private
73
+ */
74
+
75
+ this._element = this.getTag();
76
+ }
77
+ /**
78
+ * Normalize input data
79
+ *
80
+ * @param {HeaderData} data - saved data to process
81
+ *
82
+ * @returns {HeaderData}
83
+ * @private
84
+ */
85
+
86
+
87
+ _createClass(Annotation, [{
88
+ key: "normalizeData",
89
+ value: function normalizeData(data) {
90
+ var newData = {};
91
+
92
+ if (typeof data !== 'object') {
93
+ data = {};
94
+ }
95
+
96
+ newData.text = data.text || '';
97
+ newData.labelName = data.labelName || this.defaultLabel.labelName;
98
+ return newData;
99
+ }
100
+ /**
101
+ * Return Tool's view
102
+ *
103
+ * @returns {HTMLHeadingElement}
104
+ * @public
105
+ */
106
+
107
+ }, {
108
+ key: "render",
109
+ value: function render() {
110
+ return this._element;
111
+ }
112
+ /**
113
+ * Create Block's settings block
114
+ *
115
+ * @returns {HTMLElement}
116
+ */
117
+
118
+ }, {
119
+ key: "renderSettings",
120
+ value: function renderSettings() {
121
+ var _this = this;
122
+
123
+ var holder = document.createElement('DIV'); // do not add settings button, when only one label is configured
124
+
125
+ if (this.labels.length <= 1) {
126
+ return holder;
127
+ }
128
+ /** Add type selectors */
129
+
130
+
131
+ this.labels.forEach(function (label) {
132
+ var selectTypeButton = document.createElement('DIV');
133
+ selectTypeButton.classList.add(_this._CSS.settingsButton);
134
+ /**
135
+ * Highlight current label button
136
+ */
137
+
138
+ if (_this.currentLabel.labelName === label.labelName) {
139
+ selectTypeButton.classList.add(_this._CSS.settingsButtonActive);
140
+ }
141
+ /**
142
+ * Add SVG icon
143
+ */
144
+
145
+
146
+ selectTypeButton.innerHTML = "".concat(label.labelName);
147
+ /**
148
+ * Save label to its button
149
+ */
150
+
151
+ selectTypeButton.dataset.labelName = label.labelName;
152
+ /**
153
+ * Set up click handler
154
+ */
155
+
156
+ selectTypeButton.addEventListener('click', function () {
157
+ _this.setLabelName(label.labelName);
158
+ });
159
+ /**
160
+ * Append settings button to holder
161
+ */
162
+
163
+ holder.appendChild(selectTypeButton);
164
+ /**
165
+ * Save settings buttons
166
+ */
167
+
168
+ _this.settingsButtons.push(selectTypeButton);
169
+ });
170
+ return holder;
171
+ }
172
+ /**
173
+ * Callback for Block's settings buttons
174
+ *
175
+ * @param {labelName} labelName - labelName to set
176
+ */
177
+
178
+ }, {
179
+ key: "setLabelName",
180
+ value: function setLabelName(labelName) {
181
+ var _this2 = this;
182
+
183
+ this.data = {
184
+ labelName: labelName,
185
+ text: this.data.text
186
+ };
187
+ /**
188
+ * Highlight button by selected labelName
189
+ */
190
+
191
+ this.settingsButtons.forEach(function (button) {
192
+ button.classList.toggle(_this2._CSS.settingsButtonActive, button.dataset.labelName === labelName);
193
+ });
194
+ }
195
+ /**
196
+ * Method that specified how to merge two Text blocks.
197
+ * Called by Editor.js by backspace at the beginning of the Block
198
+ *
199
+ * @param {HeaderData} data - saved data to merger with current block
200
+ * @public
201
+ */
202
+
203
+ }, {
204
+ key: "merge",
205
+ value: function merge(data) {
206
+ var newData = {
207
+ text: this.data.text + data.text,
208
+ labelName: this.data.labelName
209
+ };
210
+ this.data = newData;
211
+ }
212
+ /**
213
+ * Validate Text block data:
214
+ * - check for emptiness
215
+ *
216
+ * @param {HeaderData} blockData — data received after saving
217
+ * @returns {boolean} false if saved data is not correct, otherwise true
218
+ * @public
219
+ */
220
+
221
+ }, {
222
+ key: "validate",
223
+ value: function validate(blockData) {
224
+ return blockData.text.trim() !== '';
225
+ }
226
+ /**
227
+ * Extract Tool's data from the view
228
+ *
229
+ * @param {HTMLHeadingElement} toolsContent - Text tools rendered view
230
+ * @returns {HeaderData} - saved data
231
+ * @public
232
+ */
233
+
234
+ }, {
235
+ key: "save",
236
+ value: function save(toolsContent) {
237
+ return {
238
+ text: toolsContent.innerHTML,
239
+ labelName: this.currentLabel.labelName
240
+ };
241
+ }
242
+ /**
243
+ * Allow Header to be converted to/from other blocks
244
+ */
245
+
246
+ }, {
247
+ key: "getTag",
248
+
249
+ /**
250
+ * Get tag for target label
251
+ * By default returns second-labelled header
252
+ *
253
+ * @returns {HTMLElement}
254
+ */
255
+ value: function getTag() {
256
+ /**
257
+ * Create element for current Block's label
258
+ */
259
+ var tag = document.createElement(this.currentLabel.tag);
260
+
261
+ if (this.currentLabel.backgroundColor) {
262
+ tag.style.backgroundColor = this.currentLabel.backgroundColor;
263
+ }
264
+ /**
265
+ * Add text to block
266
+ */
267
+
268
+
269
+ tag.innerHTML = this._data.text || '';
270
+ /**
271
+ * Add styles class
272
+ */
273
+
274
+ tag.classList.add(this._CSS.wrapper);
275
+ /**
276
+ * Make tag editable
277
+ */
278
+
279
+ tag.contentEditable = this.readOnly ? 'false' : 'true';
280
+ /**
281
+ * Add Placeholder
282
+ */
283
+
284
+ tag.dataset.placeholder = this.api.i18n.t(this._settings.placeholder || '');
285
+ return tag;
286
+ }
287
+ /**
288
+ * Get current label
289
+ *
290
+ * @returns {label}
291
+ */
292
+
293
+ }, {
294
+ key: "onPaste",
295
+
296
+ /**
297
+ * Handle H1-H6 tags on paste to substitute it with header Tool
298
+ *
299
+ * @param {PasteEvent} event - event with pasted content
300
+ */
301
+ value: function onPaste(event) {
302
+ var content = event.detail.data;
303
+ /**
304
+ * Define default label value
305
+ *
306
+ * @type {labelName}
307
+ */
308
+
309
+ var labelName = this.defaultLabel.labelName;
310
+
311
+ switch (content.tagName) {
312
+ case 'H1':
313
+ labelName = 1;
314
+ break;
315
+
316
+ case 'H2':
317
+ labelName = 2;
318
+ break;
319
+
320
+ case 'H3':
321
+ labelName = 3;
322
+ break;
323
+
324
+ case 'H4':
325
+ labelName = 4;
326
+ break;
327
+
328
+ case 'H5':
329
+ labelName = 5;
330
+ break;
331
+
332
+ case 'H6':
333
+ labelName = 6;
334
+ break;
335
+ } // if (this._settings.labels) {
336
+ // // Fallback to nearest label when specified not available
337
+ // label = this._settings.labels.reduce((prevLabel, currLabel) => {
338
+ // return Math.abs(currLabel - label) < Math.abs(prevLabel - label)
339
+ // ? currLabel
340
+ // : prevLabel;
341
+ // });
342
+ // }
343
+
344
+
345
+ this.data = {
346
+ labelName: labelName,
347
+ text: content.innerHTML
348
+ };
349
+ }
350
+ /**
351
+ * Used by Editor.js paste handling API.
352
+ * Provides configuration to handle H1-H6 tags.
353
+ *
354
+ * @returns {{handler: (function(HTMLElement): {text: string}), tags: string[]}}
355
+ */
356
+
357
+ }, {
358
+ key: "data",
359
+
360
+ /**
361
+ * Get current Tools`s data
362
+ *
363
+ * @returns {HeaderData} Current data
364
+ * @private
365
+ */
366
+ get: function get() {
367
+ this._data.text = this._element.innerHTML;
368
+ this._data.labelName = this.currentLabel.labelName;
369
+ return this._data;
370
+ }
371
+ /**
372
+ * Store data in plugin:
373
+ * - at the this._data property
374
+ * - at the HTML
375
+ *
376
+ * @param {HeaderData} data — data to set
377
+ * @private
378
+ */
379
+ ,
380
+ set: function set(data) {
381
+ this._data = this.normalizeData(data);
382
+ /**
383
+ * If labelName is set and block in DOM
384
+ * then replace it to a new block
385
+ */
386
+
387
+ if (data.labelName !== undefined && this._element.parentNode) {
388
+ /**
389
+ * Create a new tag
390
+ *
391
+ * @type {HTMLHeadingElement}
392
+ */
393
+ var newHeader = this.getTag();
394
+ /**
395
+ * Save Block's content
396
+ */
397
+
398
+ newHeader.innerHTML = this._element.innerHTML;
399
+ /**
400
+ * Replace blocks
401
+ */
402
+
403
+ this._element.parentNode.replaceChild(newHeader, this._element);
404
+ /**
405
+ * Save new block to private variable
406
+ *
407
+ * @type {HTMLHeadingElement}
408
+ * @private
409
+ */
410
+
411
+
412
+ this._element = newHeader;
413
+ }
414
+ /**
415
+ * If data.text was passed then update block's content
416
+ */
417
+
418
+
419
+ if (data.text !== undefined) {
420
+ this._element.innerHTML = this._data.text || '';
421
+ }
422
+ }
423
+ }, {
424
+ key: "currentLabel",
425
+ get: function get() {
426
+ var _this3 = this;
427
+
428
+ var label = this.labels.find(function (labelItem) {
429
+ return labelItem.labelName === _this3._data.labelName;
430
+ });
431
+
432
+ if (!label) {
433
+ label = this.defaultLabel;
434
+ }
435
+
436
+ return label;
437
+ }
438
+ /**
439
+ * Return default label
440
+ *
441
+ * @returns {label}
442
+ */
443
+
444
+ }, {
445
+ key: "defaultLabel",
446
+ get: function get() {
447
+ var _this4 = this;
448
+
449
+ /**
450
+ * User can specify own default label value
451
+ */
452
+ if (this._settings.defaultLabel) {
453
+ var userSpecified = this.labels.find(function (labelItem) {
454
+ return labelItem.labelName === _this4._settings.defaultLabel;
455
+ });
456
+
457
+ if (userSpecified) {
458
+ return userSpecified;
459
+ }
460
+
461
+ console.warn("(ง'̀-'́)ง Annotation Tool: the default label specified was not found in available labels");
462
+ }
463
+ /**
464
+ * With no additional options, there will be H2 by default
465
+ *
466
+ * @type {label}
467
+ */
468
+
469
+
470
+ return this.labels[1];
471
+ }
472
+ /**
473
+ * @typedef {object} label
474
+ * @property {labelName} labelName - label labelName
475
+ * @property {string} tag - tag corresponds with label labelName
476
+ * @property {string} svg - icon
477
+ */
478
+
479
+ /**
480
+ * Available header labels
481
+ *
482
+ * @returns {label[]}
483
+ */
484
+
485
+ }, {
486
+ key: "labels",
487
+ get: function get() {
488
+ var _this5 = this;
489
+
490
+ var availableLabels = [{
491
+ labelName: 'title',
492
+ tag: 'h1',
493
+ name: 'title' // backgroundColor: '#d0fffe'
494
+
495
+ }, {
496
+ labelName: 'subtitle',
497
+ tag: 'h2',
498
+ name: 'subtitle'
499
+ }, {
500
+ labelName: 'text',
501
+ tag: 'p',
502
+ name: 'text'
503
+ }, {
504
+ labelName: 'author',
505
+ tag: 'i',
506
+ name: 'author'
507
+ }, {
508
+ labelName: 'appendix',
509
+ tag: 'p',
510
+ name: 'appendix'
511
+ }, {
512
+ labelName: 'photo_author',
513
+ tag: 'p',
514
+ name: 'photo_author'
515
+ }, {
516
+ labelName: 'photo_caption',
517
+ tag: 'p',
518
+ name: 'photo_caption'
519
+ }, {
520
+ labelName: 'advertisement',
521
+ tag: 'p',
522
+ name: 'advertisement'
523
+ }, {
524
+ labelName: 'other_graphics',
525
+ tag: 'p',
526
+ name: 'other_graphics'
527
+ }, {
528
+ labelName: 'unknown',
529
+ tag: 's',
530
+ name: 'unknown'
531
+ }, {
532
+ labelName: 'about_author',
533
+ tag: 'p',
534
+ name: 'about_author'
535
+ }, {
536
+ labelName: 'image',
537
+ tag: 'p',
538
+ name: 'image'
539
+ }, {
540
+ labelName: 'interview',
541
+ tag: 'p',
542
+ name: 'interview'
543
+ }, {
544
+ labelName: 'table',
545
+ tag: 'p',
546
+ name: 'table'
547
+ }];
548
+ return this._settings.labels ? availableLabels.filter(function (l) {
549
+ return _this5._settings.labels.includes(l.labelName);
550
+ }) : availableLabels;
551
+ }
552
+ }], [{
553
+ key: "conversionConfig",
554
+ get: function get() {
555
+ return {
556
+ export: 'text',
557
+ // use 'text' property for other blocks
558
+ import: 'text' // fill 'text' property from other block's export string
559
+
560
+ };
561
+ }
562
+ /**
563
+ * Sanitizer Rules
564
+ */
565
+
566
+ }, {
567
+ key: "sanitize",
568
+ get: function get() {
569
+ return {
570
+ labelName: false,
571
+ text: {}
572
+ };
573
+ }
574
+ /**
575
+ * Returns true to notify core that read-only is supported
576
+ *
577
+ * @returns {boolean}
578
+ */
579
+
580
+ }, {
581
+ key: "isReadOnlySupported",
582
+ get: function get() {
583
+ return true;
584
+ }
585
+ }, {
586
+ key: "pasteConfig",
587
+ get: function get() {
588
+ return {
589
+ tags: ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']
590
+ };
591
+ }
592
+ /**
593
+ * Get Tool toolbox settings
594
+ * icon - Tool icon's SVG
595
+ * title - title to show in toolbox
596
+ *
597
+ * @returns {{icon: string, title: string}}
598
+ */
599
+
600
+ }, {
601
+ key: "toolbox",
602
+ get: function get() {
603
+ return {
604
+ icon: '<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>',
605
+ title: 'Annotation'
606
+ };
607
+ }
608
+ }]);
609
+
610
+ return Annotation;
611
+ }();
612
+
613
+ export default Annotation;
@@ -0,0 +1,57 @@
1
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import React from 'react';
4
+ import { createReactEditorJS } from 'react-editor-js';
5
+ import { EDITOR_JS_TOOLS } from './tools';
6
+ var ReactEditorJS = createReactEditorJS();
7
+
8
+ function Editor(_ref) {
9
+ var blocks = _ref.blocks,
10
+ onChange = _ref.onChange,
11
+ imageIndex = _ref.imageIndex;
12
+
13
+ var handleChange =
14
+ /*#__PURE__*/
15
+ function () {
16
+ var _ref2 = _asyncToGenerator(
17
+ /*#__PURE__*/
18
+ _regeneratorRuntime.mark(function _callee(instance) {
19
+ var data;
20
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
21
+ while (1) {
22
+ switch (_context.prev = _context.next) {
23
+ case 0:
24
+ _context.next = 2;
25
+ return instance.saver.save();
26
+
27
+ case 2:
28
+ data = _context.sent;
29
+ onChange({
30
+ imageIndex: imageIndex,
31
+ data: data
32
+ });
33
+
34
+ case 4:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }
39
+ }, _callee);
40
+ }));
41
+
42
+ return function handleChange(_x) {
43
+ return _ref2.apply(this, arguments);
44
+ };
45
+ }();
46
+
47
+ return React.createElement(ReactEditorJS, {
48
+ defaultValue: {
49
+ blocks: blocks
50
+ },
51
+ tools: EDITOR_JS_TOOLS,
52
+ onChange: handleChange,
53
+ enableReInitialize: true
54
+ });
55
+ }
56
+
57
+ export default Editor;
@@ -1,6 +1,5 @@
1
1
  // tools.js
2
2
  import Annotation from './annotation-plugin/annotation';
3
-
4
- export const EDITOR_JS_TOOLS = {
3
+ export var EDITOR_JS_TOOLS = {
5
4
  annotation: Annotation
6
- }
5
+ };
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ import Annotator from "../Annotator";
3
+ export default (function (props) {
4
+ return React.createElement(Annotator, Object.assign({}, props, {
5
+ fullImageSegmentationMode: true
6
+ }));
7
+ });