@searpent/react-image-annotate 2.1.1 → 2.3.0-cand
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/exampleImages_bugdemo_15_1.js +80 -0
- package/Annotator/examplePhotos_repr.js +7052 -0
- package/Annotator/index.story_bugdemo_15_1.js +882 -0
- package/Annotator/index.story_repr.js +1075 -0
- package/Editor/index.js +6 -32
- package/Editor/index_bugdemo_15_1.js +147 -0
- package/Editor/readOnly.js +25 -373
- package/MainLayout/index_bugdemo_15_1.js +588 -0
- package/MetadataEditorSidebarBox/index_14_01_25.js +231 -0
- package/MetadataEditorSidebarBox/index_repr.js +271 -0
- package/package.json +7 -4
package/Editor/index.js
CHANGED
|
@@ -6,8 +6,7 @@ import { createReactEditorJS } from 'react-editor-js';
|
|
|
6
6
|
import blocksToArticle from '../utils/blocks-to-article';
|
|
7
7
|
import { EDITOR_JS_TOOLS } from './tools';
|
|
8
8
|
import ReadOnly from './readOnly';
|
|
9
|
-
import
|
|
10
|
-
import './editor.css';
|
|
9
|
+
import '../PageSelector/page-selector.css';
|
|
11
10
|
var ReactEditorJS = createReactEditorJS();
|
|
12
11
|
|
|
13
12
|
function Editor(_ref) {
|
|
@@ -22,11 +21,6 @@ function Editor(_ref) {
|
|
|
22
21
|
editMode = _useState2[0],
|
|
23
22
|
setEditMode = _useState2[1];
|
|
24
23
|
|
|
25
|
-
var _useState3 = useState(isSpellcheckEnabled()),
|
|
26
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
-
autoSpellcheck = _useState4[0],
|
|
28
|
-
setAutoSpellcheck = _useState4[1];
|
|
29
|
-
|
|
30
24
|
var handleChange = /*#__PURE__*/function () {
|
|
31
25
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(instance) {
|
|
32
26
|
var data;
|
|
@@ -63,14 +57,6 @@ function Editor(_ref) {
|
|
|
63
57
|
});
|
|
64
58
|
};
|
|
65
59
|
|
|
66
|
-
var toggleAutoSpellcheck = function toggleAutoSpellcheck() {
|
|
67
|
-
setAutoSpellcheck(function (prev) {
|
|
68
|
-
var next = !prev;
|
|
69
|
-
setSpellcheckEnabled(next);
|
|
70
|
-
return next;
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
|
|
74
60
|
if (blocks.length < 1) {
|
|
75
61
|
return /*#__PURE__*/React.createElement("div", {
|
|
76
62
|
className: "instructions"
|
|
@@ -78,28 +64,17 @@ function Editor(_ref) {
|
|
|
78
64
|
}
|
|
79
65
|
|
|
80
66
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
81
|
-
className: "show-metadata-wrapper
|
|
82
|
-
}, /*#__PURE__*/React.createElement("
|
|
83
|
-
className: "switch mr-2
|
|
84
|
-
}, /*#__PURE__*/React.createElement("input", {
|
|
85
|
-
id: "automatic-spellcheck",
|
|
86
|
-
type: "checkbox",
|
|
87
|
-
checked: autoSpellcheck,
|
|
88
|
-
onChange: toggleAutoSpellcheck
|
|
89
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
90
|
-
className: "slider round"
|
|
91
|
-
})), /*#__PURE__*/React.createElement("label", {
|
|
92
|
-
className: "mr-4"
|
|
93
|
-
}, "Spellcheck")), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
94
|
-
className: "switch mr-2 editor-switch"
|
|
67
|
+
className: "show-metadata-wrapper"
|
|
68
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
69
|
+
className: "switch mr-2"
|
|
95
70
|
}, /*#__PURE__*/React.createElement("input", {
|
|
96
71
|
id: "show-metadata",
|
|
97
72
|
type: "checkbox",
|
|
98
|
-
|
|
73
|
+
value: editMode,
|
|
99
74
|
onChange: toggleEditMode
|
|
100
75
|
}), /*#__PURE__*/React.createElement("span", {
|
|
101
76
|
className: "slider round"
|
|
102
|
-
})), /*#__PURE__*/React.createElement("label", null, "Edit mode"))
|
|
77
|
+
})), /*#__PURE__*/React.createElement("label", null, "Edit mode")), !editMode ? /*#__PURE__*/React.createElement(ReadOnly, {
|
|
103
78
|
article: blocksToArticle(blocks)
|
|
104
79
|
}) : /*#__PURE__*/React.createElement(ReactEditorJS, {
|
|
105
80
|
defaultValue: {
|
|
@@ -107,7 +82,6 @@ function Editor(_ref) {
|
|
|
107
82
|
},
|
|
108
83
|
tools: EDITOR_JS_TOOLS,
|
|
109
84
|
onChange: handleChange,
|
|
110
|
-
onInitialize: function onInitialize() {},
|
|
111
85
|
enableReInitialize: true,
|
|
112
86
|
key: selectedFrame
|
|
113
87
|
}));
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { createReactEditorJS } from 'react-editor-js';
|
|
6
|
+
import blocksToArticle from '../utils/blocks-to-article';
|
|
7
|
+
import { EDITOR_JS_TOOLS } from './tools';
|
|
8
|
+
import ReadOnly from './readOnly';
|
|
9
|
+
import { isSpellcheckEnabled, setSpellcheckEnabled } from '../utils/spellcheck-nspell';
|
|
10
|
+
import './editor.css';
|
|
11
|
+
var ReactEditorJS = createReactEditorJS();
|
|
12
|
+
|
|
13
|
+
function Editor(_ref) {
|
|
14
|
+
var _ref$blocks = _ref.blocks,
|
|
15
|
+
blocks = _ref$blocks === void 0 ? [] : _ref$blocks,
|
|
16
|
+
onChange = _ref.onChange,
|
|
17
|
+
imageIndex = _ref.imageIndex,
|
|
18
|
+
selectedFrame = _ref.selectedFrame,
|
|
19
|
+
_ref$selectedGroupId = _ref.selectedGroupId,
|
|
20
|
+
selectedGroupId = _ref$selectedGroupId === void 0 ? null : _ref$selectedGroupId,
|
|
21
|
+
_ref$originalSelected = _ref.originalSelectedGroupId,
|
|
22
|
+
originalSelectedGroupId = _ref$originalSelected === void 0 ? null : _ref$originalSelected;
|
|
23
|
+
|
|
24
|
+
var _useState = useState(false),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
editMode = _useState2[0],
|
|
27
|
+
setEditMode = _useState2[1];
|
|
28
|
+
|
|
29
|
+
var _useState3 = useState(isSpellcheckEnabled()),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
autoSpellcheck = _useState4[0],
|
|
32
|
+
setAutoSpellcheck = _useState4[1];
|
|
33
|
+
|
|
34
|
+
var handleChange = /*#__PURE__*/function () {
|
|
35
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(instance) {
|
|
36
|
+
var data;
|
|
37
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
38
|
+
while (1) {
|
|
39
|
+
switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
_context.next = 2;
|
|
42
|
+
return instance.saver.save();
|
|
43
|
+
|
|
44
|
+
case 2:
|
|
45
|
+
data = _context.sent;
|
|
46
|
+
onChange({
|
|
47
|
+
imageIndex: imageIndex,
|
|
48
|
+
data: data
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
case 4:
|
|
52
|
+
case "end":
|
|
53
|
+
return _context.stop();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, _callee);
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
return function handleChange(_x) {
|
|
60
|
+
return _ref2.apply(this, arguments);
|
|
61
|
+
};
|
|
62
|
+
}();
|
|
63
|
+
|
|
64
|
+
var toggleEditMode = function toggleEditMode() {
|
|
65
|
+
setEditMode(function (prev) {
|
|
66
|
+
return !prev;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
var toggleAutoSpellcheck = function toggleAutoSpellcheck() {
|
|
71
|
+
setAutoSpellcheck(function (prev) {
|
|
72
|
+
var next = !prev;
|
|
73
|
+
setSpellcheckEnabled(next);
|
|
74
|
+
return next;
|
|
75
|
+
});
|
|
76
|
+
}; // BUG SIMULATION: Only activate with ?bug=true parameter (not just localhost)
|
|
77
|
+
// This allows Storybook to test both the fix and the bug simulation
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
var isBugMode = typeof window !== 'undefined' && (window.location.search.includes('bug=true') || window.location.search.includes('bug=on')); // In bug mode: selectedGroupId is null (simulating the bug), but originalSelectedGroupId has the actual selection
|
|
81
|
+
// Use originalSelectedGroupId for filtering in read-only mode to show correct article
|
|
82
|
+
// Use selectedGroupId (null) for edit mode to reproduce the bug
|
|
83
|
+
|
|
84
|
+
var groupIdForReadOnly = isBugMode && originalSelectedGroupId != null ? originalSelectedGroupId // Use original selection for read-only filtering
|
|
85
|
+
: selectedGroupId; // Otherwise use selectedGroupId
|
|
86
|
+
|
|
87
|
+
var groupIdForEdit = selectedGroupId; // Always use selectedGroupId for edit mode (null in bug mode = bug)
|
|
88
|
+
// Filter blocks for read-only mode
|
|
89
|
+
|
|
90
|
+
var blocksForReadOnly = groupIdForReadOnly === null ? isBugMode ? blocks : [] : // In bug mode show all blocks, otherwise show empty
|
|
91
|
+
blocks.filter(function (i) {
|
|
92
|
+
var _i$data;
|
|
93
|
+
|
|
94
|
+
return (i === null || i === void 0 ? void 0 : (_i$data = i.data) === null || _i$data === void 0 ? void 0 : _i$data.groupId) === groupIdForReadOnly;
|
|
95
|
+
}); // Filter by selected article
|
|
96
|
+
// Filter blocks for edit mode - this is where the bug manifests
|
|
97
|
+
|
|
98
|
+
var blocksForEdit = groupIdForEdit === null ? blocks.filter(function (i) {
|
|
99
|
+
var _i$data2;
|
|
100
|
+
|
|
101
|
+
return (i === null || i === void 0 ? void 0 : (_i$data2 = i.data) === null || _i$data2 === void 0 ? void 0 : _i$data2.groupId) === groupIdForEdit;
|
|
102
|
+
}) // BUG: Filter to empty array when selectedGroupId is null
|
|
103
|
+
: blocks.filter(function (i) {
|
|
104
|
+
var _i$data3;
|
|
105
|
+
|
|
106
|
+
return (i === null || i === void 0 ? void 0 : (_i$data3 = i.data) === null || _i$data3 === void 0 ? void 0 : _i$data3.groupId) === groupIdForEdit;
|
|
107
|
+
}); // Normal: filter by selected article
|
|
108
|
+
|
|
109
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
110
|
+
className: "show-metadata-wrapper editor-toggle-wrapper"
|
|
111
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
112
|
+
className: "switch mr-2 editor-switch"
|
|
113
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
114
|
+
id: "automatic-spellcheck",
|
|
115
|
+
type: "checkbox",
|
|
116
|
+
checked: autoSpellcheck,
|
|
117
|
+
onChange: toggleAutoSpellcheck
|
|
118
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
119
|
+
className: "slider round"
|
|
120
|
+
})), /*#__PURE__*/React.createElement("label", {
|
|
121
|
+
className: "mr-4"
|
|
122
|
+
}, "Spellcheck")), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
123
|
+
className: "switch mr-2 editor-switch"
|
|
124
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
125
|
+
id: "show-metadata",
|
|
126
|
+
type: "checkbox",
|
|
127
|
+
checked: editMode,
|
|
128
|
+
onChange: toggleEditMode
|
|
129
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
130
|
+
className: "slider round"
|
|
131
|
+
})), /*#__PURE__*/React.createElement("label", null, "Edit mode"))), blocksForReadOnly.length < 1 ? /*#__PURE__*/React.createElement("div", {
|
|
132
|
+
className: "instructions"
|
|
133
|
+
}, /*#__PURE__*/React.createElement("h1", null, "Click article to display text.")) : !editMode ? /*#__PURE__*/React.createElement(ReadOnly, {
|
|
134
|
+
article: blocksToArticle(blocksForReadOnly)
|
|
135
|
+
}) : /*#__PURE__*/React.createElement(ReactEditorJS, {
|
|
136
|
+
defaultValue: {
|
|
137
|
+
blocks: blocksForEdit
|
|
138
|
+
},
|
|
139
|
+
tools: EDITOR_JS_TOOLS,
|
|
140
|
+
onChange: handleChange,
|
|
141
|
+
onInitialize: function onInitialize() {},
|
|
142
|
+
enableReInitialize: true,
|
|
143
|
+
key: selectedFrame
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default Editor;
|