@searpent/react-image-annotate 2.0.14 → 2.0.16

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.
@@ -17,7 +17,7 @@ import videoReducer from "./reducers/video-reducer.js";
17
17
  function extractAllowedGroups(images) {
18
18
  var allowedGroups = [];
19
19
  images.forEach(function (image) {
20
- return image.regions.forEach(function (_ref) {
20
+ return image.regions && image.regions.forEach(function (_ref) {
21
21
  var groupId = _ref.groupId;
22
22
 
23
23
  if (!allowedGroups.includes(groupId)) {
@@ -84,7 +84,8 @@ export var Annotator = function Annotator(_ref2) {
84
84
  hideNotEditingLabel = _ref2.hideNotEditingLabel,
85
85
  showEditor = _ref2.showEditor,
86
86
  showPageSelector = _ref2.showPageSelector,
87
- clsColors = _ref2.clsColors,
87
+ _ref2$clsColors = _ref2.clsColors,
88
+ clsColors = _ref2$clsColors === void 0 ? {} : _ref2$clsColors,
88
89
  groupColors = _ref2.groupColors,
89
90
  onRecalc = _ref2.onRecalc,
90
91
  onSave = _ref2.onSave,
@@ -109,6 +109,7 @@ export var ClassSelectionMenu = function ClassSelectionMenu(_ref6) {
109
109
  expandedByDefault: true
110
110
  }, regionClsList.map(function (label, index) {
111
111
  return React.createElement(LabelContainer, {
112
+ key: label,
112
113
  className: classnames({
113
114
  selected: label === selectedCls
114
115
  }),
@@ -4,10 +4,9 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  /**
5
5
  * Build styles
6
6
  */
7
- require('./annotation.css').toString(); // Possible classes
7
+ import './annotation.css'; // Possible classes
8
8
  // ================
9
9
 
10
-
11
10
  var Annotation =
12
11
  /*#__PURE__*/
13
12
  function () {
@@ -27,9 +27,9 @@ var GroupItem = function GroupItem(_ref2) {
27
27
 
28
28
  var GroupList = function GroupList(_ref3) {
29
29
  var groups = _ref3.groups;
30
- return React.createElement("div", null, React.createElement("h2", null, "Groups"), groups.map(function (g) {
30
+ return React.createElement("div", null, React.createElement("h2", null, "Groups"), groups.map(function (g, idx) {
31
31
  return React.createElement(GroupItem, {
32
- key: g,
32
+ key: "".concat(g, "-").concat(idx),
33
33
  group: g
34
34
  });
35
35
  }));
@@ -276,7 +276,7 @@ export var MainLayout = function MainLayout(_ref4) {
276
276
  var _i$metadata;
277
277
 
278
278
  return {
279
- id: idx,
279
+ id: "".concat(idx),
280
280
  src: i.src,
281
281
  isActive: idx === state.selectedImage,
282
282
  pageNumber: (i === null || i === void 0 ? void 0 : (_i$metadata = i.metadata) === null || _i$metadata === void 0 ? void 0 : _i$metadata.find(function (md) {
@@ -405,19 +405,23 @@ export var MainLayout = function MainLayout(_ref4) {
405
405
  }),
406
406
  rightSidebarItems: [debugModeOn && React.createElement(DebugBox, {
407
407
  state: debugModeOn,
408
- lastAction: state.lastAction
408
+ lastAction: state.lastAction,
409
+ key: "debug-box"
409
410
  }), state.taskDescription && React.createElement(TaskDescription, {
410
- description: state.taskDescription
411
+ description: state.taskDescription,
412
+ key: "task-description"
411
413
  }), state.regionClsList && React.createElement(ClassSelectionMenu, {
412
414
  selectedCls: state.selectedCls,
413
415
  regionClsList: state.regionClsList,
414
- onSelectCls: action("SELECT_CLASSIFICATION", "cls")
416
+ onSelectCls: action("SELECT_CLASSIFICATION", "cls"),
417
+ key: "class-selection-menu"
415
418
  }), state.labelImages && React.createElement(TagsSidebarBox, {
416
419
  currentImage: activeImage,
417
420
  imageClsList: state.imageClsList,
418
421
  imageTagList: state.imageTagList,
419
422
  onChangeImage: action("CHANGE_IMAGE", "delta"),
420
- expandedByDefault: true
423
+ expandedByDefault: true,
424
+ key: "tags-sidebar-box"
421
425
  }),, // (state.images?.length || 0) > 1 && (
422
426
  // <ImageSelector
423
427
  // onSelect={action("SELECT_REGION", "region")}
@@ -436,23 +440,28 @@ export var MainLayout = function MainLayout(_ref4) {
436
440
  regions: activeImage ? activeImage.regions : emptyArr,
437
441
  onSelectRegion: action("SELECT_REGION", "region"),
438
442
  onDeleteRegion: action("DELETE_REGION", "region"),
439
- onChangeRegion: action("CHANGE_REGION", "region")
443
+ onChangeRegion: action("CHANGE_REGION", "region"),
444
+ key: "region-selector"
440
445
  }), state.keyframes && React.createElement(KeyframesSelector, {
441
446
  onChangeVideoTime: action("CHANGE_VIDEO_TIME", "newTime"),
442
447
  onDeleteKeyframe: action("DELETE_KEYFRAME", "time"),
443
448
  onChangeCurrentTime: action("CHANGE_VIDEO_TIME", "newTime"),
444
449
  currentTime: state.currentVideoTime,
445
450
  duration: state.videoDuration,
446
- keyframes: state.keyframes
451
+ keyframes: state.keyframes,
452
+ key: "key-frame-selector"
447
453
  }), !hideHistory && React.createElement(HistorySidebarBox, {
448
454
  history: state.history,
449
- onRestoreHistory: action("RESTORE_HISTORY")
455
+ onRestoreHistory: action("RESTORE_HISTORY"),
456
+ key: "history-sidebar"
450
457
  }), React.createElement(MetadataEditor, {
451
458
  state: state,
452
- onMetadataChange: onMetadataChange
459
+ onMetadataChange: onMetadataChange,
460
+ key: "metadata-editor"
453
461
  }), React.createElement(GroupsEditor, {
454
462
  groups: state.allowedGroups,
455
- onAddGroup: onAddGroup
463
+ onAddGroup: onAddGroup,
464
+ key: "groups-editor"
456
465
  })].filter(Boolean)
457
466
  }, canvas), showEditor && React.createElement(EditorWrapper, {
458
467
  id: "editor-wrapper"
@@ -51,7 +51,7 @@ var MetadataList = function MetadataList(_ref3) {
51
51
  metadata = _ref3.metadata,
52
52
  imageIndex = _ref3.imageIndex,
53
53
  onMetadataChange = _ref3.onMetadataChange;
54
- return React.createElement("div", null, React.createElement("h2", null, title), metadata.map(function (_ref4) {
54
+ return React.createElement("div", null, React.createElement("h2", null, title), metadata && metadata.map(function (_ref4) {
55
55
  var key = _ref4.key,
56
56
  value = _ref4.value;
57
57
  return React.createElement(MetadataItem, {
@@ -1,8 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useState } from 'react';
3
3
  import classnames from "classnames";
4
-
5
- require('./page-selector.css').toString();
4
+ import './page-selector.css';
6
5
 
7
6
  function PageThumbnail(_ref) {
8
7
  var src = _ref.src,
@@ -77,7 +76,7 @@ function PageSelector(_ref2) {
77
76
  return React.createElement("div", {
78
77
  className: "page-thumbnail__wrapper"
79
78
  }, React.createElement(PageThumbnail, {
80
- key: page.id,
79
+ key: "".concat(page.id),
81
80
  src: page.src,
82
81
  isActive: page.isActive,
83
82
  onClick: function onClick() {
@@ -88,7 +87,9 @@ function PageSelector(_ref2) {
88
87
  }, React.createElement("h5", null, "Metadata"), page === null || page === void 0 ? void 0 : (_page$metadata = page.metadata) === null || _page$metadata === void 0 ? void 0 : _page$metadata.map(function (_ref3) {
89
88
  var key = _ref3.key,
90
89
  value = _ref3.value;
91
- return React.createElement(React.Fragment, null, React.createElement("label", {
90
+ return React.createElement("div", {
91
+ key: key
92
+ }, React.createElement("label", {
92
93
  htmlFor: key
93
94
  }, key), React.createElement("input", {
94
95
  id: key,
@@ -43,12 +43,12 @@ export var RegionLabel = function RegionLabel(_ref) {
43
43
  };
44
44
 
45
45
  if (hideNotEditingLabel && !editing) return null;
46
- var allowedGroupsForSelect = allowedGroups.map(function (g) {
46
+ var allowedGroupsForSelect = allowedGroups ? allowedGroups.map(function (g) {
47
47
  return {
48
48
  value: "".concat(g),
49
49
  label: "".concat(g)
50
50
  };
51
- });
51
+ }) : [];
52
52
  return React.createElement(ThemeProvider, {
53
53
  theme: theme
54
54
  }, React.createElement(Paper, {
@@ -249,7 +249,7 @@ export var WrappedRegionList = memo(function (_ref19) {
249
249
  }).map(function (r) {
250
250
  var Component = RegionComponents[r.type];
251
251
  return React.createElement(Component, {
252
- key: r.regionId,
252
+ key: r.id,
253
253
  region: r,
254
254
  iw: iw,
255
255
  ih: ih,
@@ -7,6 +7,7 @@ var defaultSettings = {
7
7
  showHighlightBox: true,
8
8
  wasdMode: true
9
9
  };
10
+ var DEFAULT_GROUP_COLORS = ["#3853F1", "#F6E54C", "#39D33C", "#CF24CF", "#22E3ED", "#EF3029"];
10
11
  export var SettingsContext = createContext(defaultSettings);
11
12
 
12
13
  var pullSettingsFromLocalStorage = function pullSettingsFromLocalStorage() {
@@ -32,7 +33,8 @@ export var useSettings = function useSettings() {
32
33
  export var SettingsProvider = function SettingsProvider(_ref) {
33
34
  var children = _ref.children,
34
35
  clsColors = _ref.clsColors,
35
- groupColors = _ref.groupColors;
36
+ _ref$groupColors = _ref.groupColors,
37
+ groupColors = _ref$groupColors === void 0 ? DEFAULT_GROUP_COLORS : _ref$groupColors;
36
38
 
37
39
  var _useState = useState(_objectSpread({}, function () {
38
40
  return pullSettingsFromLocalStorage();
@@ -56,6 +56,10 @@ var useColors = function useColors() {
56
56
  groupColors = _useSettings.groupColors;
57
57
 
58
58
  var clsColor = function clsColor(cls) {
59
+ if (!clsColors) {
60
+ return DEFAULT_GROUP_COLOR;
61
+ }
62
+
59
63
  if (clsColors[cls]) {
60
64
  return clsColors[cls];
61
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searpent/react-image-annotate",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "dependencies": {
5
5
  "@editorjs/editorjs": "^2.25.0",
6
6
  "@editorjs/paragraph": "^2.8.0",
@@ -1,46 +0,0 @@
1
- /**
2
- * Plugin styles
3
- */
4
- .ce-header {
5
- padding: 0.6em 0 3px;
6
- margin: 0;
7
- line-height: 1.25em;
8
- outline: none;
9
- }
10
-
11
- .ce-header p,
12
- .ce-header div {
13
- padding: 0 !important;
14
- margin: 0 !important;
15
- }
16
-
17
- /**
18
- * Styles for Plugin icon in Toolbar
19
- */
20
- .ce-header__icon {}
21
-
22
- .ce-header[contentEditable=true][data-placeholder]::before {
23
- position: absolute;
24
- content: attr(data-placeholder);
25
- color: #707684;
26
- font-weight: normal;
27
- display: none;
28
- cursor: text;
29
- }
30
-
31
- .ce-header[contentEditable=true][data-placeholder]:empty::before {
32
- display: block;
33
- }
34
-
35
- .ce-header[contentEditable=true][data-placeholder]:empty:focus::before {
36
- display: none;
37
- }
38
-
39
- /* Custom overwrite */
40
- .cdx-settings-button {
41
- width: 100% !important;
42
- }
43
-
44
- .ce-settings__plugin-zone {
45
- padding: 0 .25rem;
46
- }
@@ -1,198 +0,0 @@
1
- .page-selector {
2
- height: 100vh;
3
- overflow-y: scroll;
4
- max-width: 10%;
5
- transition: max-width .5s;
6
- }
7
-
8
- .page-selector--opened {
9
- max-width: 20%;
10
- }
11
-
12
- .pages {
13
- list-style: none;
14
- padding: 1rem;
15
- }
16
-
17
- .page-thumbnail__wrapper {
18
- display: flex;
19
- flex-direction: row;
20
- align-items: flex-start;
21
- }
22
-
23
- .page-thumbnail {
24
- margin-bottom: 1rem;
25
- border-radius: .25rem !important;
26
- overflow: hidden;
27
- filter: grayscale(1);
28
- transition: transform .2s;
29
- opacity: .5;
30
- }
31
-
32
- .page-thumbnail:hover {
33
- box-shadow: 0 0 2rem 0 #8898aa !important;
34
- filter: grayscale(0);
35
- transform: scale(1.015);
36
- cursor: pointer;
37
- opacity: 1;
38
- }
39
-
40
- .page-thumbnail-is-active {
41
- filter: grayscale(0);
42
- opacity: 1;
43
- }
44
-
45
- .page-thumbnail img {
46
- width: 100%;
47
- }
48
-
49
- .page-thumbnail__metadata {
50
- padding: 1rem;
51
- }
52
-
53
- .page-thumbnail__metadata * {
54
- display: block;
55
- }
56
-
57
- .top-buttons {
58
- background: linear-gradient(#8898aa, rgba(255, 255, 255, 0));
59
- position: sticky;
60
- top: 0;
61
- display: flex;
62
- flex-direction: column;
63
- padding: 1rem;
64
- margin-bottom: 1rem;
65
- z-index: 100;
66
- }
67
-
68
- .top-buttons button {
69
- margin-bottom: 1rem;
70
- width: 100%;
71
- }
72
-
73
- .top-buttons button:hover {
74
- cursor: pointer;
75
- }
76
-
77
- .top-buttons button:disabled {
78
- pointer-events: none;
79
- opacity: .5;
80
- }
81
-
82
- .top-buttons button.info {
83
- background-color: transparent;
84
- border-radius: 0.5rem;
85
- background-image: linear-gradient(310deg, #627594, #a8b8d8);
86
- color: white;
87
- border: none;
88
- padding: 0.5rem 0;
89
- }
90
-
91
- .top-buttons button.success {
92
- color: white;
93
- background-image: linear-gradient(310deg, #2dce89, #2dcecc);
94
- border-radius: 0.5rem;
95
- border: none;
96
- padding: 0.5rem 0;
97
- }
98
-
99
- .bottom-buttons {
100
- background: linear-gradient(rgba(255, 255, 255, 0), #8898aa);
101
- position: sticky;
102
- bottom: 0;
103
- display: flex;
104
- flex-direction: column;
105
- padding: 1rem;
106
- margin-bottom: 1rem;
107
- z-index: 100;
108
- }
109
-
110
-
111
- .page-number-wrapper {
112
- position: absolute;
113
- bottom: 0;
114
- width: 100%;
115
- height: 10%;
116
- z-index: 100;
117
- display: flex;
118
- justify-content: center;
119
- align-items: center;
120
- background: linear-gradient(rgba(255, 255, 255, 0), #8898aa);
121
- padding: .5rem 0;
122
- }
123
-
124
- .page-number {
125
- font-size: 1.5rem;
126
- font-weight: 800;
127
- }
128
-
129
- /* toggle */
130
- .switch {
131
- position: relative;
132
- display: inline-block;
133
- width: 60px;
134
- height: 34px;
135
- }
136
-
137
- .switch input {
138
- opacity: 0;
139
- width: 0;
140
- height: 0;
141
- }
142
-
143
- .slider {
144
- position: absolute;
145
- cursor: pointer;
146
- top: 0;
147
- left: 0;
148
- right: 0;
149
- bottom: 0;
150
- background-color: #ccc;
151
- -webkit-transition: .4s;
152
- transition: .4s;
153
- }
154
-
155
- .slider:before {
156
- position: absolute;
157
- content: "";
158
- height: 26px;
159
- width: 26px;
160
- left: 4px;
161
- bottom: 4px;
162
- background-color: white;
163
- -webkit-transition: .4s;
164
- transition: .4s;
165
- }
166
-
167
- input:checked+.slider {
168
- background-color: #2196F3;
169
- }
170
-
171
- input:focus+.slider {
172
- box-shadow: 0 0 1px #2196F3;
173
- }
174
-
175
- input:checked+.slider:before {
176
- -webkit-transform: translateX(26px);
177
- -ms-transform: translateX(26px);
178
- transform: translateX(26px);
179
- }
180
-
181
- /* Rounded sliders */
182
- .slider.round {
183
- border-radius: 34px;
184
- }
185
-
186
- .slider.round:before {
187
- border-radius: 50%;
188
- }
189
-
190
- .show-metadata-wrapper {
191
- display: flex;
192
- flex-direction: row;
193
- align-items: center;
194
- }
195
-
196
- .mr-2 {
197
- margin-right: 1rem;
198
- }