@searpent/react-image-annotate 2.0.3 → 2.0.6
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/Annotator/examplePhotos.js +6976 -0
- package/Annotator/index.js +104 -11
- package/Annotator/reducers/general-reducer.js +95 -1
- package/Editor/annotation-plugin/annotation.js +613 -0
- package/Editor/index.js +57 -0
- package/Editor/tools.js +5 -0
- package/ImageCanvas/index.js +7 -2
- package/MainLayout/index.js +146 -43
- package/MetadataEditorSidebarBox/index.js +126 -0
- package/PageSelector/index.js +67 -0
- package/RegionLabel/index.js +16 -2
- package/RegionShapes/index.js +31 -11
- package/RegionTags/index.js +6 -2
- package/SettingsProvider/index.js +8 -3
- package/hooks/use-colors.js +101 -0
- package/package.json +4 -1
- package/utils/filter-only-unique.js +5 -0
- package/utils/photosToImages.js +53 -0
- package/utils/regions-to-blocks.js +16 -0
package/MainLayout/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import RegionSelector from "../RegionSelectorSidebarBox";
|
|
|
17
17
|
import SettingsDialog from "../SettingsDialog";
|
|
18
18
|
import TagsSidebarBox from "../TagsSidebarBox";
|
|
19
19
|
import TaskDescription from "../TaskDescriptionSidebarBox";
|
|
20
|
+
import MetadataEditor from "../MetadataEditorSidebarBox";
|
|
20
21
|
import Workspace from "react-material-workspace-layout/Workspace";
|
|
21
22
|
import classnames from "classnames";
|
|
22
23
|
import getActiveImage from "../Annotator/reducers/get-active-image";
|
|
@@ -28,7 +29,10 @@ import useEventCallback from "use-event-callback";
|
|
|
28
29
|
import useImpliedVideoRegions from "./use-implied-video-regions";
|
|
29
30
|
import useKey from "use-key-hook";
|
|
30
31
|
import { useSettings } from "../SettingsProvider";
|
|
31
|
-
import { withHotKeys } from "react-hotkeys";
|
|
32
|
+
import { withHotKeys } from "react-hotkeys";
|
|
33
|
+
import Editor from "../Editor";
|
|
34
|
+
import regionsToBlocks from '../utils/regions-to-blocks';
|
|
35
|
+
import PagesSelector from "../PageSelector"; // import Fullscreen from "../Fullscreen"
|
|
32
36
|
|
|
33
37
|
var emptyArr = [];
|
|
34
38
|
var theme = createTheme();
|
|
@@ -56,37 +60,62 @@ var FullScreenContainer = styled("div")(function (_ref2) {
|
|
|
56
60
|
}
|
|
57
61
|
};
|
|
58
62
|
});
|
|
59
|
-
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
63
|
+
var EditorWrapper = styled("div")(function (_ref3) {
|
|
64
|
+
var theme = _ref3.theme;
|
|
65
|
+
return {
|
|
66
|
+
width: "45%",
|
|
67
|
+
padding: "1rem",
|
|
68
|
+
paddingLeft: "2rem"
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
export var MainLayout = function MainLayout(_ref4) {
|
|
72
|
+
var _state$images$state$s, _state$images$state$s2;
|
|
73
|
+
|
|
74
|
+
var state = _ref4.state,
|
|
75
|
+
dispatch = _ref4.dispatch,
|
|
76
|
+
_ref4$alwaysShowNextB = _ref4.alwaysShowNextButton,
|
|
77
|
+
alwaysShowNextButton = _ref4$alwaysShowNextB === void 0 ? false : _ref4$alwaysShowNextB,
|
|
78
|
+
_ref4$alwaysShowPrevB = _ref4.alwaysShowPrevButton,
|
|
79
|
+
alwaysShowPrevButton = _ref4$alwaysShowPrevB === void 0 ? false : _ref4$alwaysShowPrevB,
|
|
80
|
+
RegionEditLabel = _ref4.RegionEditLabel,
|
|
81
|
+
onRegionClassAdded = _ref4.onRegionClassAdded,
|
|
82
|
+
hideHeader = _ref4.hideHeader,
|
|
83
|
+
hideHeaderText = _ref4.hideHeaderText,
|
|
84
|
+
_ref4$hideNext = _ref4.hideNext,
|
|
85
|
+
hideNext = _ref4$hideNext === void 0 ? false : _ref4$hideNext,
|
|
86
|
+
_ref4$hidePrev = _ref4.hidePrev,
|
|
87
|
+
hidePrev = _ref4$hidePrev === void 0 ? false : _ref4$hidePrev,
|
|
88
|
+
_ref4$hideClone = _ref4.hideClone,
|
|
89
|
+
hideClone = _ref4$hideClone === void 0 ? false : _ref4$hideClone,
|
|
90
|
+
_ref4$hideSettings = _ref4.hideSettings,
|
|
91
|
+
hideSettings = _ref4$hideSettings === void 0 ? false : _ref4$hideSettings,
|
|
92
|
+
_ref4$hideFullScreen = _ref4.hideFullScreen,
|
|
93
|
+
hideFullScreen = _ref4$hideFullScreen === void 0 ? false : _ref4$hideFullScreen,
|
|
94
|
+
_ref4$hideSave = _ref4.hideSave,
|
|
95
|
+
hideSave = _ref4$hideSave === void 0 ? false : _ref4$hideSave,
|
|
96
|
+
_ref4$groups = _ref4.groups,
|
|
97
|
+
groups = _ref4$groups === void 0 ? [] : _ref4$groups,
|
|
98
|
+
_ref4$onGroupSelect = _ref4.onGroupSelect,
|
|
99
|
+
onGroupSelect = _ref4$onGroupSelect === void 0 ? function () {} : _ref4$onGroupSelect,
|
|
100
|
+
_ref4$hideHistory = _ref4.hideHistory,
|
|
101
|
+
hideHistory = _ref4$hideHistory === void 0 ? false : _ref4$hideHistory,
|
|
102
|
+
_ref4$hideNotEditingL = _ref4.hideNotEditingLabel,
|
|
103
|
+
hideNotEditingLabel = _ref4$hideNotEditingL === void 0 ? false : _ref4$hideNotEditingL,
|
|
104
|
+
_ref4$showEditor = _ref4.showEditor,
|
|
105
|
+
showEditor = _ref4$showEditor === void 0 ? false : _ref4$showEditor,
|
|
106
|
+
_ref4$showPageSelecto = _ref4.showPageSelector,
|
|
107
|
+
showPageSelector = _ref4$showPageSelecto === void 0 ? false : _ref4$showPageSelecto,
|
|
108
|
+
_ref4$onRecalc = _ref4.onRecalc,
|
|
109
|
+
onRecalc = _ref4$onRecalc === void 0 ? function () {} : _ref4$onRecalc,
|
|
110
|
+
_ref4$onSave = _ref4.onSave,
|
|
111
|
+
onSave = _ref4$onSave === void 0 ? function () {} : _ref4$onSave,
|
|
112
|
+
_ref4$recalcActive = _ref4.recalcActive,
|
|
113
|
+
recalcActive = _ref4$recalcActive === void 0 ? false : _ref4$recalcActive,
|
|
114
|
+
_ref4$saveActive = _ref4.saveActive,
|
|
115
|
+
saveActive = _ref4$saveActive === void 0 ? false : _ref4$saveActive,
|
|
116
|
+
_ref4$allowedGroups = _ref4.allowedGroups,
|
|
117
|
+
allowedGroups = _ref4$allowedGroups === void 0 ? {} : _ref4$allowedGroups,
|
|
118
|
+
onMetadataChange = _ref4.onMetadataChange;
|
|
90
119
|
var classes = useStyles();
|
|
91
120
|
var settings = useSettings();
|
|
92
121
|
var fullScreenHandle = useFullScreenHandle();
|
|
@@ -192,7 +221,9 @@ export var MainLayout = function MainLayout(_ref3) {
|
|
|
192
221
|
onChangeVideoTime: action("CHANGE_VIDEO_TIME", "newTime"),
|
|
193
222
|
onChangeVideoPlaying: action("CHANGE_VIDEO_PLAYING", "isPlaying"),
|
|
194
223
|
onRegionClassAdded: onRegionClassAdded,
|
|
195
|
-
allowComments: state.allowComments
|
|
224
|
+
allowComments: state.allowComments,
|
|
225
|
+
hideNotEditingLabel: hideNotEditingLabel,
|
|
226
|
+
allowedGroups: allowedGroups
|
|
196
227
|
}));
|
|
197
228
|
var onClickIconSidebarItem = useEventCallback(function (item) {
|
|
198
229
|
dispatch({
|
|
@@ -213,7 +244,53 @@ export var MainLayout = function MainLayout(_ref3) {
|
|
|
213
244
|
});
|
|
214
245
|
});
|
|
215
246
|
var debugModeOn = Boolean(window.localStorage.$ANNOTATE_DEBUG_MODE && state);
|
|
216
|
-
var nextImageHasRegions = !nextImage || nextImage.regions && nextImage.regions.length > 0;
|
|
247
|
+
var nextImageHasRegions = !nextImage || nextImage.regions && nextImage.regions.length > 0; // Editor.js blocks
|
|
248
|
+
|
|
249
|
+
var selectedGroupId = ((_state$images$state$s = state.images[state.selectedImage]) === null || _state$images$state$s === void 0 ? void 0 : _state$images$state$s.selectedGroupId) || null;
|
|
250
|
+
var editorBlocks = regionsToBlocks(((_state$images$state$s2 = state.images[state.selectedImage]) === null || _state$images$state$s2 === void 0 ? void 0 : _state$images$state$s2.regions) || []);
|
|
251
|
+
var blocks = editorBlocks.filter(function (i) {
|
|
252
|
+
var _i$data;
|
|
253
|
+
|
|
254
|
+
return (i === null || i === void 0 ? void 0 : (_i$data = i.data) === null || _i$data === void 0 ? void 0 : _i$data.groupId) === selectedGroupId;
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
var handleEditorChange = function handleEditorChange(_ref5) {
|
|
258
|
+
var imageIndex = _ref5.imageIndex,
|
|
259
|
+
data = _ref5.data;
|
|
260
|
+
var newRegions = data.blocks.map(function (i) {
|
|
261
|
+
return {
|
|
262
|
+
id: i.id,
|
|
263
|
+
cls: i.data.labelName,
|
|
264
|
+
text: i.data.text
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
dispatch({
|
|
268
|
+
type: "UPDATE_REGIONS",
|
|
269
|
+
regions: newRegions,
|
|
270
|
+
imageIndex: imageIndex
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
var pages = state.images.map(function (i, idx) {
|
|
275
|
+
var _i$metadata;
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
id: idx,
|
|
279
|
+
src: i.src,
|
|
280
|
+
isActive: idx === state.selectedImage,
|
|
281
|
+
pageNumber: (i === null || i === void 0 ? void 0 : (_i$metadata = i.metadata) === null || _i$metadata === void 0 ? void 0 : _i$metadata.find(function (md) {
|
|
282
|
+
return md.key === "page";
|
|
283
|
+
}).value) || null
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
var handlePageClick = function handlePageClick(pageIndex) {
|
|
288
|
+
dispatch({
|
|
289
|
+
type: "SELECT_IMAGE",
|
|
290
|
+
imageIndex: pageIndex
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
|
|
217
294
|
return React.createElement(ThemeProvider, {
|
|
218
295
|
theme: theme
|
|
219
296
|
}, React.createElement(FullScreenContainer, null, React.createElement(FullScreen, {
|
|
@@ -232,7 +309,19 @@ export var MainLayout = function MainLayout(_ref3) {
|
|
|
232
309
|
allowChanges: true,
|
|
233
310
|
handlers: hotkeyHandlers,
|
|
234
311
|
className: classnames(classes.container, state.fullScreen && "Fullscreen")
|
|
235
|
-
}, React.createElement(
|
|
312
|
+
}, React.createElement("div", {
|
|
313
|
+
style: {
|
|
314
|
+
display: 'flex',
|
|
315
|
+
flexDirection: 'row'
|
|
316
|
+
}
|
|
317
|
+
}, showPageSelector && React.createElement(PagesSelector, {
|
|
318
|
+
pages: pages,
|
|
319
|
+
onPageClick: handlePageClick,
|
|
320
|
+
onRecalc: onRecalc,
|
|
321
|
+
onSave: onSave,
|
|
322
|
+
saveActive: saveActive,
|
|
323
|
+
recalcActive: recalcActive
|
|
324
|
+
}), React.createElement(Workspace, {
|
|
236
325
|
allowFullscreen: true,
|
|
237
326
|
iconDictionary: iconDictionary,
|
|
238
327
|
hideHeader: hideHeader,
|
|
@@ -326,18 +415,21 @@ export var MainLayout = function MainLayout(_ref3) {
|
|
|
326
415
|
imageTagList: state.imageTagList,
|
|
327
416
|
onChangeImage: action("CHANGE_IMAGE", "delta"),
|
|
328
417
|
expandedByDefault: true
|
|
329
|
-
})
|
|
418
|
+
}),, // (state.images?.length || 0) > 1 && (
|
|
330
419
|
// <ImageSelector
|
|
331
420
|
// onSelect={action("SELECT_REGION", "region")}
|
|
332
421
|
// images={state.images}
|
|
333
422
|
// />
|
|
334
423
|
// ),
|
|
335
|
-
groups &&
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
424
|
+
// groups && (
|
|
425
|
+
// <GroupSelector
|
|
426
|
+
// title="Articles"
|
|
427
|
+
// groups={groups}
|
|
428
|
+
// selectedGroupId={selectedGroupId}
|
|
429
|
+
// onSelect={onGroupSelect}
|
|
430
|
+
// />
|
|
431
|
+
// )
|
|
432
|
+
React.createElement(RegionSelector, {
|
|
341
433
|
regions: activeImage ? activeImage.regions : emptyArr,
|
|
342
434
|
onSelectRegion: action("SELECT_REGION", "region"),
|
|
343
435
|
onDeleteRegion: action("DELETE_REGION", "region"),
|
|
@@ -352,8 +444,19 @@ export var MainLayout = function MainLayout(_ref3) {
|
|
|
352
444
|
}), !hideHistory && React.createElement(HistorySidebarBox, {
|
|
353
445
|
history: state.history,
|
|
354
446
|
onRestoreHistory: action("RESTORE_HISTORY")
|
|
447
|
+
}), React.createElement(MetadataEditor, {
|
|
448
|
+
state: state,
|
|
449
|
+
onMetadataChange: onMetadataChange
|
|
355
450
|
})].filter(Boolean)
|
|
356
|
-
}, canvas), React.createElement(
|
|
451
|
+
}, canvas), showEditor && React.createElement(EditorWrapper, {
|
|
452
|
+
id: "editor-wrapper"
|
|
453
|
+
}, React.createElement(Editor, {
|
|
454
|
+
id: "editor",
|
|
455
|
+
blocks: blocks,
|
|
456
|
+
imageIndex: state.selectedImage,
|
|
457
|
+
key: "".concat(state.selectedImage, "#").concat(selectedGroupId),
|
|
458
|
+
onChange: handleEditorChange
|
|
459
|
+
}))), React.createElement(SettingsDialog, {
|
|
357
460
|
open: state.settingsOpen,
|
|
358
461
|
onClose: function onClose() {
|
|
359
462
|
return dispatch({
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React, { memo } from "react";
|
|
2
|
+
import SidebarBoxContainer from "../SidebarBoxContainer";
|
|
3
|
+
import DescriptionIcon from "@mui/icons-material/Description";
|
|
4
|
+
import { styled } from "@mui/material/styles";
|
|
5
|
+
import { createTheme, ThemeProvider } from "@mui/material/styles";
|
|
6
|
+
import { grey } from "@mui/material/colors";
|
|
7
|
+
var MetadataItemDiv = styled("div")(function (_ref) {
|
|
8
|
+
var theme = _ref.theme;
|
|
9
|
+
return {
|
|
10
|
+
display: "flex",
|
|
11
|
+
flexDirection: "column",
|
|
12
|
+
marginBottom: "1rem",
|
|
13
|
+
"& > label": {
|
|
14
|
+
fontSize: "1rem",
|
|
15
|
+
marginBottom: ".5rem",
|
|
16
|
+
textTransform: "capitalize"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var MetadataItem = function MetadataItem(_ref2) {
|
|
22
|
+
var name = _ref2.name,
|
|
23
|
+
value = _ref2.value,
|
|
24
|
+
imageIndex = _ref2.imageIndex,
|
|
25
|
+
onChange = _ref2.onChange;
|
|
26
|
+
|
|
27
|
+
var handleChange = function handleChange(e) {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
var _e$target = e.target,
|
|
30
|
+
name = _e$target.name,
|
|
31
|
+
value = _e$target.value;
|
|
32
|
+
onChange({
|
|
33
|
+
name: name,
|
|
34
|
+
value: value,
|
|
35
|
+
imageIndex: imageIndex
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return React.createElement(MetadataItemDiv, null, React.createElement("label", {
|
|
40
|
+
for: name
|
|
41
|
+
}, name), React.createElement("input", {
|
|
42
|
+
type: "text",
|
|
43
|
+
value: value,
|
|
44
|
+
name: name,
|
|
45
|
+
onChange: handleChange
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var MetadataList = function MetadataList(_ref3) {
|
|
50
|
+
var title = _ref3.title,
|
|
51
|
+
metadata = _ref3.metadata,
|
|
52
|
+
imageIndex = _ref3.imageIndex,
|
|
53
|
+
onMetadataChange = _ref3.onMetadataChange;
|
|
54
|
+
return React.createElement("div", null, React.createElement("h2", null, title), metadata.map(function (_ref4) {
|
|
55
|
+
var key = _ref4.key,
|
|
56
|
+
value = _ref4.value;
|
|
57
|
+
return React.createElement(MetadataItem, {
|
|
58
|
+
name: key,
|
|
59
|
+
value: value,
|
|
60
|
+
imageIndex: imageIndex,
|
|
61
|
+
onChange: onMetadataChange
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var theme = createTheme();
|
|
67
|
+
var DivContainer = styled("div")(function (_ref5) {
|
|
68
|
+
var theme = _ref5.theme;
|
|
69
|
+
return {
|
|
70
|
+
paddingLeft: 16,
|
|
71
|
+
paddingRight: 16,
|
|
72
|
+
fontSize: 12,
|
|
73
|
+
"& h1": {
|
|
74
|
+
fontSize: 18
|
|
75
|
+
},
|
|
76
|
+
"& h2": {
|
|
77
|
+
fontSize: 14
|
|
78
|
+
},
|
|
79
|
+
"& h3": {
|
|
80
|
+
fontSize: 12
|
|
81
|
+
},
|
|
82
|
+
"& h4": {
|
|
83
|
+
fontSize: 12
|
|
84
|
+
},
|
|
85
|
+
"& h5": {
|
|
86
|
+
fontSize: 12
|
|
87
|
+
},
|
|
88
|
+
"& h6": {
|
|
89
|
+
fontSize: 12
|
|
90
|
+
},
|
|
91
|
+
"& p": {
|
|
92
|
+
fontSize: 12
|
|
93
|
+
},
|
|
94
|
+
"& a": {},
|
|
95
|
+
"& img": {
|
|
96
|
+
width: "100%"
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
export var MetadataEditorSidebarBox = function MetadataEditorSidebarBox(_ref6) {
|
|
101
|
+
var _state$images$state$s;
|
|
102
|
+
|
|
103
|
+
var state = _ref6.state,
|
|
104
|
+
onMetadataChange = _ref6.onMetadataChange;
|
|
105
|
+
return React.createElement(ThemeProvider, {
|
|
106
|
+
theme: theme
|
|
107
|
+
}, React.createElement(SidebarBoxContainer, {
|
|
108
|
+
title: "Metadata",
|
|
109
|
+
icon: React.createElement(DescriptionIcon, {
|
|
110
|
+
style: {
|
|
111
|
+
color: grey[700]
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
expandedByDefault: true
|
|
115
|
+
}, React.createElement(DivContainer, null, React.createElement(MetadataList, {
|
|
116
|
+
title: "Global",
|
|
117
|
+
metadata: state.metadata,
|
|
118
|
+
onMetadataChange: onMetadataChange
|
|
119
|
+
}), (state === null || state === void 0 ? void 0 : (_state$images$state$s = state.images[state.selectedImage]) === null || _state$images$state$s === void 0 ? void 0 : _state$images$state$s.metadata) && React.createElement(MetadataList, {
|
|
120
|
+
title: "Local",
|
|
121
|
+
metadata: state.images[state.selectedImage].metadata,
|
|
122
|
+
imageIndex: state.selectedImage,
|
|
123
|
+
onMetadataChange: onMetadataChange
|
|
124
|
+
}))));
|
|
125
|
+
};
|
|
126
|
+
export default memo(MetadataEditorSidebarBox);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
|
|
4
|
+
require('./page-selector.css').toString();
|
|
5
|
+
|
|
6
|
+
function PageThumbnail(_ref) {
|
|
7
|
+
var src = _ref.src,
|
|
8
|
+
isActive = _ref.isActive,
|
|
9
|
+
onClick = _ref.onClick,
|
|
10
|
+
pageNumber = _ref.pageNumber;
|
|
11
|
+
return React.createElement("div", {
|
|
12
|
+
role: "button",
|
|
13
|
+
tabIndex: 0,
|
|
14
|
+
className: classnames('page-thumbnail', {
|
|
15
|
+
'page-thumbnail-is-active': isActive
|
|
16
|
+
}),
|
|
17
|
+
onClick: onClick
|
|
18
|
+
}, React.createElement("img", {
|
|
19
|
+
src: src,
|
|
20
|
+
alt: ""
|
|
21
|
+
}), pageNumber !== undefined && React.createElement("div", {
|
|
22
|
+
className: "page-number-wrapper"
|
|
23
|
+
}, React.createElement("span", {
|
|
24
|
+
className: "page-number"
|
|
25
|
+
}, pageNumber)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function PagesSelector(_ref2) {
|
|
29
|
+
var pages = _ref2.pages,
|
|
30
|
+
onPageClick = _ref2.onPageClick,
|
|
31
|
+
onRecalc = _ref2.onRecalc,
|
|
32
|
+
onSave = _ref2.onSave,
|
|
33
|
+
recalcActive = _ref2.recalcActive,
|
|
34
|
+
saveActive = _ref2.saveActive;
|
|
35
|
+
return React.createElement("div", {
|
|
36
|
+
className: "page-selector"
|
|
37
|
+
}, React.createElement("div", {
|
|
38
|
+
className: "bottom-buttons"
|
|
39
|
+
}, React.createElement("button", {
|
|
40
|
+
onClick: onRecalc,
|
|
41
|
+
disabled: !recalcActive
|
|
42
|
+
}, "Recalc"), React.createElement("button", {
|
|
43
|
+
onClick: onSave,
|
|
44
|
+
disabled: !saveActive
|
|
45
|
+
}, "Save")), React.createElement("div", {
|
|
46
|
+
className: "pages"
|
|
47
|
+
}, pages.map(function (page, idx) {
|
|
48
|
+
return React.createElement(PageThumbnail, {
|
|
49
|
+
key: page.id,
|
|
50
|
+
src: page.src,
|
|
51
|
+
isActive: page.isActive,
|
|
52
|
+
onClick: function onClick() {
|
|
53
|
+
return onPageClick(idx);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
PagesSelector.defaultProps = {
|
|
60
|
+
onPageClick: function onPageClick() {},
|
|
61
|
+
onRecalc: function onRecalc() {},
|
|
62
|
+
onSave: function onSave() {},
|
|
63
|
+
recalcActive: false,
|
|
64
|
+
saveActive: false,
|
|
65
|
+
pageNumber: undefined
|
|
66
|
+
};
|
|
67
|
+
export default PagesSelector;
|
package/RegionLabel/index.js
CHANGED
|
@@ -27,7 +27,9 @@ export var RegionLabel = function RegionLabel(_ref) {
|
|
|
27
27
|
onClose = _ref.onClose,
|
|
28
28
|
onOpen = _ref.onOpen,
|
|
29
29
|
onRegionClassAdded = _ref.onRegionClassAdded,
|
|
30
|
-
allowComments = _ref.allowComments
|
|
30
|
+
allowComments = _ref.allowComments,
|
|
31
|
+
hideNotEditingLabel = _ref.hideNotEditingLabel,
|
|
32
|
+
allowedGroups = _ref.allowedGroups;
|
|
31
33
|
var classes = useStyles();
|
|
32
34
|
var commentInputRef = useRef(null);
|
|
33
35
|
|
|
@@ -37,6 +39,7 @@ export var RegionLabel = function RegionLabel(_ref) {
|
|
|
37
39
|
if (commentInput) return commentInput.focus();
|
|
38
40
|
};
|
|
39
41
|
|
|
42
|
+
if (hideNotEditingLabel && !editing) return null;
|
|
40
43
|
return React.createElement(ThemeProvider, {
|
|
41
44
|
theme: theme
|
|
42
45
|
}, React.createElement(Paper, {
|
|
@@ -127,7 +130,18 @@ export var RegionLabel = function RegionLabel(_ref) {
|
|
|
127
130
|
label: c
|
|
128
131
|
};
|
|
129
132
|
}))
|
|
130
|
-
})), (
|
|
133
|
+
})), (allowedGroups || []).length > 0 && React.createElement(Select, {
|
|
134
|
+
onChange: function onChange(newGroup) {
|
|
135
|
+
return _onChange(_objectSpread({}, region, {
|
|
136
|
+
groupId: newGroup.value
|
|
137
|
+
}));
|
|
138
|
+
},
|
|
139
|
+
placeholder: "Group",
|
|
140
|
+
value: allowedGroups.filter(function (g) {
|
|
141
|
+
return g.value === region.groupId;
|
|
142
|
+
}),
|
|
143
|
+
options: allowedGroups
|
|
144
|
+
}), (allowedTags || []).length > 0 && React.createElement("div", {
|
|
131
145
|
style: {
|
|
132
146
|
marginTop: 4
|
|
133
147
|
}
|
package/RegionShapes/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React, { memo } from "react";
|
|
3
3
|
import colorAlpha from "color-alpha";
|
|
4
|
+
import useColors from '../hooks/use-colors';
|
|
4
5
|
|
|
5
6
|
function clamp(num, min, max) {
|
|
6
7
|
return num <= min ? min : num >= max ? max : num;
|
|
@@ -40,17 +41,36 @@ var RegionComponents = {
|
|
|
40
41
|
var region = _ref3.region,
|
|
41
42
|
iw = _ref3.iw,
|
|
42
43
|
ih = _ref3.ih;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
|
|
45
|
+
var _useColors = useColors(),
|
|
46
|
+
clsColor = _useColors.clsColor,
|
|
47
|
+
groupColor = _useColors.groupColor;
|
|
48
|
+
|
|
49
|
+
if (region.groupId !== undefined) {
|
|
50
|
+
return React.createElement("g", {
|
|
51
|
+
transform: "translate(".concat(region.x * iw, " ").concat(region.y * ih, ")")
|
|
52
|
+
}, React.createElement("rect", {
|
|
53
|
+
strokeWidth: region.groupHighlighted ? 3 : 0,
|
|
54
|
+
x: 0,
|
|
55
|
+
y: 0,
|
|
56
|
+
width: Math.max(region.w * iw, 0),
|
|
57
|
+
height: Math.max(region.h * ih, 0),
|
|
58
|
+
stroke: colorAlpha(clsColor(region.cls), 0.85),
|
|
59
|
+
fill: region.groupHighlighted ? colorAlpha(groupColor(region.groupId), 0.5) : colorAlpha(groupColor(region.groupId), 0.25)
|
|
60
|
+
}));
|
|
61
|
+
} else {
|
|
62
|
+
return React.createElement("g", {
|
|
63
|
+
transform: "translate(".concat(region.x * iw, " ").concat(region.y * ih, ")")
|
|
64
|
+
}, React.createElement("rect", {
|
|
65
|
+
strokeWidth: 2,
|
|
66
|
+
x: 0,
|
|
67
|
+
y: 0,
|
|
68
|
+
width: Math.max(region.w * iw, 0),
|
|
69
|
+
height: Math.max(region.h * ih, 0),
|
|
70
|
+
stroke: colorAlpha(clsColor(region.cls), 0.85),
|
|
71
|
+
fill: colorAlpha(clsColor(region.cls), 0.25)
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
54
74
|
}),
|
|
55
75
|
polygon: memo(function (_ref4) {
|
|
56
76
|
var region = _ref4.region,
|
package/RegionTags/index.js
CHANGED
|
@@ -33,7 +33,9 @@ export var RegionTags = function RegionTags(_ref) {
|
|
|
33
33
|
imageSrc = _ref.imageSrc,
|
|
34
34
|
RegionEditLabel = _ref.RegionEditLabel,
|
|
35
35
|
onRegionClassAdded = _ref.onRegionClassAdded,
|
|
36
|
-
allowComments = _ref.allowComments
|
|
36
|
+
allowComments = _ref.allowComments,
|
|
37
|
+
hideNotEditingLabel = _ref.hideNotEditingLabel,
|
|
38
|
+
allowedGroups = _ref.allowedGroups;
|
|
37
39
|
var RegionLabel = RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel;
|
|
38
40
|
return regions.filter(function (r) {
|
|
39
41
|
return r.visible || r.visible === undefined;
|
|
@@ -131,7 +133,9 @@ export var RegionTags = function RegionTags(_ref) {
|
|
|
131
133
|
regions: regions,
|
|
132
134
|
imageSrc: imageSrc,
|
|
133
135
|
onRegionClassAdded: onRegionClassAdded,
|
|
134
|
-
allowComments: allowComments
|
|
136
|
+
allowComments: allowComments,
|
|
137
|
+
hideNotEditingLabel: hideNotEditingLabel,
|
|
138
|
+
allowedGroups: allowedGroups
|
|
135
139
|
})));
|
|
136
140
|
});
|
|
137
141
|
};
|
|
@@ -30,11 +30,16 @@ export var useSettings = function useSettings() {
|
|
|
30
30
|
return useContext(SettingsContext);
|
|
31
31
|
};
|
|
32
32
|
export var SettingsProvider = function SettingsProvider(_ref) {
|
|
33
|
-
var children = _ref.children
|
|
33
|
+
var children = _ref.children,
|
|
34
|
+
clsColors = _ref.clsColors,
|
|
35
|
+
groupColors = _ref.groupColors;
|
|
34
36
|
|
|
35
|
-
var _useState = useState(function () {
|
|
37
|
+
var _useState = useState(_objectSpread({}, function () {
|
|
36
38
|
return pullSettingsFromLocalStorage();
|
|
37
|
-
}
|
|
39
|
+
}, {
|
|
40
|
+
clsColors: clsColors,
|
|
41
|
+
groupColors: groupColors
|
|
42
|
+
})),
|
|
38
43
|
_useState2 = _slicedToArray(_useState, 2),
|
|
39
44
|
state = _useState2[0],
|
|
40
45
|
changeState = _useState2[1];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useSettings } from "../SettingsProvider";
|
|
2
|
+
|
|
3
|
+
function defaultClsColor(cls) {
|
|
4
|
+
switch (cls) {
|
|
5
|
+
case 'title':
|
|
6
|
+
return '#f70202';
|
|
7
|
+
|
|
8
|
+
case 'subtitle':
|
|
9
|
+
return "#ffb405";
|
|
10
|
+
|
|
11
|
+
case 'text':
|
|
12
|
+
return "#14deef";
|
|
13
|
+
|
|
14
|
+
case 'author':
|
|
15
|
+
return "#f8d51e";
|
|
16
|
+
|
|
17
|
+
case 'appendix':
|
|
18
|
+
return "#bfede2";
|
|
19
|
+
|
|
20
|
+
case 'photo_author':
|
|
21
|
+
return "#9a17bb";
|
|
22
|
+
|
|
23
|
+
case 'photo_caption':
|
|
24
|
+
return "#ff84f6";
|
|
25
|
+
|
|
26
|
+
case 'advertisement':
|
|
27
|
+
return "#ffb201";
|
|
28
|
+
|
|
29
|
+
case 'other_graphics':
|
|
30
|
+
return "#ff5400";
|
|
31
|
+
|
|
32
|
+
case 'unknown':
|
|
33
|
+
return "#bfede2";
|
|
34
|
+
|
|
35
|
+
case 'about_author':
|
|
36
|
+
return "#9a17bb";
|
|
37
|
+
|
|
38
|
+
case 'image':
|
|
39
|
+
return "#14deef";
|
|
40
|
+
|
|
41
|
+
case 'interview':
|
|
42
|
+
return "#23b20f";
|
|
43
|
+
|
|
44
|
+
case 'table':
|
|
45
|
+
return "#02b4ba";
|
|
46
|
+
|
|
47
|
+
default:
|
|
48
|
+
return "#02b4ba";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function defaultGroupColor(groupId) {
|
|
53
|
+
switch (groupId) {
|
|
54
|
+
case "0":
|
|
55
|
+
return "#FDDFDF";
|
|
56
|
+
|
|
57
|
+
case "1":
|
|
58
|
+
return "#FCF7DE";
|
|
59
|
+
|
|
60
|
+
case "2":
|
|
61
|
+
return "#DEFDE0";
|
|
62
|
+
|
|
63
|
+
case "3":
|
|
64
|
+
return "#DEF3FD";
|
|
65
|
+
|
|
66
|
+
case "4":
|
|
67
|
+
return "#F0DEFD";
|
|
68
|
+
|
|
69
|
+
default:
|
|
70
|
+
return "#F0DEFD";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var useColors = function useColors() {
|
|
75
|
+
var _useSettings = useSettings(),
|
|
76
|
+
clsColors = _useSettings.clsColors,
|
|
77
|
+
groupColors = _useSettings.groupColors;
|
|
78
|
+
|
|
79
|
+
var clsColor = function clsColor(cls) {
|
|
80
|
+
if (clsColors[cls]) {
|
|
81
|
+
return clsColors[cls];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return defaultClsColor(cls);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var groupColor = function groupColor(groupId) {
|
|
88
|
+
if (groupColors[groupId]) {
|
|
89
|
+
return groupColors[groupId];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return defaultGroupColor(groupId);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
clsColor: clsColor,
|
|
97
|
+
groupColor: groupColor
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default useColors;
|