@abidibo/react-cam-roi 0.2.3 → 0.2.5
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/README.md +14 -3
- package/dist/index.cjs.css +2 -0
- package/dist/index.cjs.css.map +1 -0
- package/dist/index.cjs.js +1665 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.css +2 -0
- package/dist/index.esm.css.map +1 -0
- package/dist/index.esm.js +1659 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/{Components → types/Components}/RoiEditor/Canvas.d.ts +2 -0
- package/dist/{Components → types/Components}/RoiEditor/Types.d.ts +34 -0
- package/dist/{Components → types/Components}/RoiEditor/Utils.d.ts +24 -0
- package/dist/{Providers → types/Providers}/EditorProvider.d.ts +2 -1
- package/package.json +17 -6
- package/dist/Components/BoolField/index.js +0 -13
- package/dist/Components/Button/index.js +0 -15
- package/dist/Components/EnumField/index.js +0 -16
- package/dist/Components/IconButton/index.js +0 -10
- package/dist/Components/Loader/index.js +0 -9
- package/dist/Components/Modal/index.js +0 -16
- package/dist/Components/NumberField/index.js +0 -13
- package/dist/Components/RoiEditor/Canvas.js +0 -30
- package/dist/Components/RoiEditor/ColorPicker.js +0 -12
- package/dist/Components/RoiEditor/Header.js +0 -14
- package/dist/Components/RoiEditor/Hooks.js +0 -328
- package/dist/Components/RoiEditor/ParameterField.js +0 -27
- package/dist/Components/RoiEditor/ParametersModalForm/index.js +0 -42
- package/dist/Components/RoiEditor/Polygon.js +0 -77
- package/dist/Components/RoiEditor/Polyline.js +0 -75
- package/dist/Components/RoiEditor/Rectangle.js +0 -73
- package/dist/Components/RoiEditor/RoisInfo.js +0 -43
- package/dist/Components/RoiEditor/ShapesList.js +0 -77
- package/dist/Components/RoiEditor/Toolbar.js +0 -27
- package/dist/Components/RoiEditor/TopBar.js +0 -21
- package/dist/Components/RoiEditor/Types.js +0 -23
- package/dist/Components/RoiEditor/Utils.js +0 -161
- package/dist/Components/RoiEditor/index.js +0 -99
- package/dist/Components/RoleField.js +0 -49
- package/dist/Components/TextField/index.js +0 -13
- package/dist/Components/Typography/index.js +0 -6
- package/dist/Icons/AnnotateIcon.js +0 -5
- package/dist/Icons/CloseIcon.js +0 -5
- package/dist/Icons/CopyIcon.js +0 -5
- package/dist/Icons/DeleteIcon.js +0 -5
- package/dist/Icons/EditIcon.js +0 -5
- package/dist/Icons/PointerIcon.js +0 -5
- package/dist/Icons/PolygonIcon.js +0 -5
- package/dist/Icons/PolylineIcon.js +0 -5
- package/dist/Icons/RectangleIcon.js +0 -5
- package/dist/Icons/SaveIcon.js +0 -5
- package/dist/Providers/EditorProvider.js +0 -29
- package/dist/Providers/UiProvider.js +0 -104
- package/dist/Types.js +0 -1
- package/dist/Utils/Dispatcher.js +0 -65
- package/dist/Utils/index.js +0 -16
- package/dist/index.js +0 -4
- /package/dist/{Components → types/Components}/BoolField/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/Button/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/EnumField/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/IconButton/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/Loader/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/Modal/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/NumberField/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/ColorPicker.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/Header.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/Hooks.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/ParameterField.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/ParametersModalForm/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/Polygon.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/Polyline.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/Rectangle.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/RoisInfo.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/ShapesList.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/Toolbar.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/TopBar.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoiEditor/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/RoleField.d.ts +0 -0
- /package/dist/{Components → types/Components}/TextField/index.d.ts +0 -0
- /package/dist/{Components → types/Components}/Typography/index.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/AnnotateIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/CloseIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/CopyIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/DeleteIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/EditIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/PointerIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/PolygonIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/PolylineIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/RectangleIcon.d.ts +0 -0
- /package/dist/{Icons → types/Icons}/SaveIcon.d.ts +0 -0
- /package/dist/{Providers → types/Providers}/UiProvider.d.ts +0 -0
- /package/dist/{Types.d.ts → types/Types.d.ts} +0 -0
- /package/dist/{Utils → types/Utils}/Dispatcher.d.ts +0 -0
- /package/dist/{Utils → types/Utils}/index.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
@@ -1,328 +0,0 @@
|
|
1
|
-
import * as fabric from 'fabric';
|
2
|
-
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
3
|
-
import { useEditorContext } from '../../Providers/EditorProvider';
|
4
|
-
import { UiContext } from '../../Providers/UiProvider';
|
5
|
-
import { log, perc2Abs } from '../../Utils';
|
6
|
-
import Dispatcher from '../../Utils/Dispatcher';
|
7
|
-
import { copyPolygon, handleDoubleClickPolygon, handleMouseDownPolygon, handleMouseMovePolygon } from './Polygon';
|
8
|
-
import { copyPolyline, handleDoubleClickPolyline, handleMouseDownPolyline, handleMouseMovePolyline } from './Polyline';
|
9
|
-
import { copyRectangle, handleMouseDownRect, handleMouseMoveRect, handleMouseUpRect } from './Rectangle';
|
10
|
-
import { canDrawShape } from './Utils';
|
11
|
-
export const useImageSize = (imageUrl) => {
|
12
|
-
const [imageSize, setImageSize] = useState({ width: 0, height: 0 });
|
13
|
-
useEffect(() => {
|
14
|
-
const image = new Image();
|
15
|
-
image.src = imageUrl;
|
16
|
-
image.onload = () => {
|
17
|
-
setImageSize({ width: image.width, height: image.height });
|
18
|
-
};
|
19
|
-
}, [imageUrl]);
|
20
|
-
return { imageSize, isReady: imageSize.width > 0 };
|
21
|
-
};
|
22
|
-
export const useCanvasSize = (imageUrl) => {
|
23
|
-
console.log('before wrapper ref');
|
24
|
-
const wrapperRef = useRef(null);
|
25
|
-
console.log('after wrapper ref');
|
26
|
-
const [canvasSize, setCanvasSize] = useState({ width: 0, height: 0 });
|
27
|
-
const { imageSize, isReady } = useImageSize(imageUrl);
|
28
|
-
useEffect(() => {
|
29
|
-
if (wrapperRef.current) {
|
30
|
-
const update = () => {
|
31
|
-
const availableWidth = wrapperRef.current.offsetWidth;
|
32
|
-
if (availableWidth < imageSize.width) {
|
33
|
-
setCanvasSize({
|
34
|
-
width: availableWidth,
|
35
|
-
height: availableWidth * (imageSize.height / imageSize.width),
|
36
|
-
});
|
37
|
-
}
|
38
|
-
else {
|
39
|
-
setCanvasSize({
|
40
|
-
width: imageSize.width,
|
41
|
-
height: imageSize.height,
|
42
|
-
});
|
43
|
-
}
|
44
|
-
};
|
45
|
-
if (imageSize.width > 0 && wrapperRef.current) {
|
46
|
-
update();
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}, [imageSize, wrapperRef.current]); // eslint-disable-line
|
50
|
-
return { imageSize, canvasSize, wrapperRef, isReady };
|
51
|
-
};
|
52
|
-
export const initCanvasData = (canvasRef, imageSize, addShapes, metadata, setMetadata, initialData, enableLogs) => {
|
53
|
-
log('info', enableLogs !== null && enableLogs !== void 0 ? enableLogs : false, 'Loading initial shapes data', initialData, canvasRef.current);
|
54
|
-
if (initialData === null || initialData === void 0 ? void 0 : initialData.rois) {
|
55
|
-
const m = [];
|
56
|
-
const s = [];
|
57
|
-
initialData.rois.forEach((r) => {
|
58
|
-
var _a, _b, _c;
|
59
|
-
log('info', enableLogs !== null && enableLogs !== void 0 ? enableLogs : false, 'Loading initial shape', r);
|
60
|
-
const id = r.id;
|
61
|
-
let shape;
|
62
|
-
switch (r.type) {
|
63
|
-
case "rect" /* ToolEnum.Rectangle */:
|
64
|
-
shape = new fabric.Rect({
|
65
|
-
left: perc2Abs(r.shape.left, imageSize.width),
|
66
|
-
top: perc2Abs(r.shape.top, imageSize.height),
|
67
|
-
originX: 'left',
|
68
|
-
originY: 'top',
|
69
|
-
width: perc2Abs(r.shape.width, imageSize.width),
|
70
|
-
height: perc2Abs(r.shape.height, imageSize.height),
|
71
|
-
fill: 'transparent',
|
72
|
-
stroke: r.shape.color,
|
73
|
-
strokeWidth: 2,
|
74
|
-
strokeUniform: true,
|
75
|
-
selectable: false,
|
76
|
-
hasControls: true,
|
77
|
-
hoverCursor: 'default',
|
78
|
-
id,
|
79
|
-
});
|
80
|
-
(_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.add(shape);
|
81
|
-
break;
|
82
|
-
case "polygon" /* ToolEnum.Polygon */:
|
83
|
-
shape = new fabric.Polygon(r.shape.points.map(({ x, y }) => ({
|
84
|
-
x: perc2Abs(x, imageSize.width),
|
85
|
-
y: perc2Abs(y, imageSize.height),
|
86
|
-
})), {
|
87
|
-
top: perc2Abs(r.shape.top, imageSize.height),
|
88
|
-
left: perc2Abs(r.shape.left, imageSize.width),
|
89
|
-
fill: 'transparent',
|
90
|
-
stroke: r.shape.color,
|
91
|
-
strokeWidth: 2,
|
92
|
-
selectable: false,
|
93
|
-
hasControls: true,
|
94
|
-
hoverCursor: 'default',
|
95
|
-
// @ts-expect-error id is not included in types but the property is added and it works
|
96
|
-
id,
|
97
|
-
});
|
98
|
-
(_b = canvasRef.current) === null || _b === void 0 ? void 0 : _b.add(shape);
|
99
|
-
break;
|
100
|
-
case "polyline" /* ToolEnum.Polyline */:
|
101
|
-
shape = new fabric.Polyline(r.shape.points.map(({ x, y }) => ({
|
102
|
-
x: perc2Abs(x, imageSize.width),
|
103
|
-
y: perc2Abs(y, imageSize.height),
|
104
|
-
})), {
|
105
|
-
top: perc2Abs(r.shape.top, imageSize.height),
|
106
|
-
left: perc2Abs(r.shape.left, imageSize.width),
|
107
|
-
fill: 'transparent',
|
108
|
-
stroke: r.shape.color,
|
109
|
-
strokeWidth: 2,
|
110
|
-
selectable: false,
|
111
|
-
hasControls: true,
|
112
|
-
hoverCursor: 'default',
|
113
|
-
id,
|
114
|
-
});
|
115
|
-
(_c = canvasRef.current) === null || _c === void 0 ? void 0 : _c.add(shape);
|
116
|
-
break;
|
117
|
-
}
|
118
|
-
m.push({ id, parameters: r.parameters, name: r.name, role: r.role });
|
119
|
-
s.push({ id, type: r.type, shape });
|
120
|
-
});
|
121
|
-
addShapes(s);
|
122
|
-
setMetadata(Object.assign(Object.assign({}, metadata), { rois: m }));
|
123
|
-
}
|
124
|
-
};
|
125
|
-
export const useTool = (canvas) => {
|
126
|
-
const { editorId, configuration, activeTool, activeColor, shapes, addShape } = useEditorContext();
|
127
|
-
const { notify, strings } = useContext(UiContext);
|
128
|
-
const [isDrawing, setIsDrawing] = useState(false);
|
129
|
-
const [shape, setShape] = useState(null);
|
130
|
-
const [originX, setOriginX] = useState(0);
|
131
|
-
const [originY, setOriginY] = useState(0);
|
132
|
-
const [startPos] = useState({ x: 0, y: 0 });
|
133
|
-
const [points, setPoints] = useState([]);
|
134
|
-
const [lines, setLines] = useState([]);
|
135
|
-
// Handler for object selected event to update style settings
|
136
|
-
const handleObjectSelected = useCallback((event) => {
|
137
|
-
var _a;
|
138
|
-
Dispatcher.emit(`canvas:${editorId}:shapeSelected`, (_a = event.selected) !== null && _a !== void 0 ? _a : null);
|
139
|
-
}, [editorId]);
|
140
|
-
// Handler for selection cleared event to reset selected shapes state
|
141
|
-
const handleSelectionCleared = useCallback(() => {
|
142
|
-
Dispatcher.emit(`canvas:${editorId}:shapeSelected`, null);
|
143
|
-
}, [editorId]);
|
144
|
-
useEffect(() => {
|
145
|
-
if (!canvas) {
|
146
|
-
return;
|
147
|
-
}
|
148
|
-
if (activeTool === "pointer" /* ToolEnum.Pointer */) {
|
149
|
-
// enable selection
|
150
|
-
canvas.selection = true;
|
151
|
-
canvas.getObjects().forEach((object) => {
|
152
|
-
object.selectable = true;
|
153
|
-
});
|
154
|
-
canvas.renderAll();
|
155
|
-
}
|
156
|
-
else {
|
157
|
-
// disable selection
|
158
|
-
canvas.selection = false;
|
159
|
-
canvas.discardActiveObject();
|
160
|
-
Dispatcher.emit(`canvas:${editorId}:shapeSelected`, null);
|
161
|
-
canvas.renderAll();
|
162
|
-
}
|
163
|
-
const handleMouseDown = (event) => {
|
164
|
-
switch (activeTool) {
|
165
|
-
case "rect" /* ToolEnum.Rectangle */:
|
166
|
-
if (!canDrawShape(configuration, "rect" /* ToolEnum.Rectangle */, shapes, notify, strings.cannotDrawMoreRectangles))
|
167
|
-
return;
|
168
|
-
handleMouseDownRect(event, canvas, activeColor, setOriginX, setOriginY, setShape, setIsDrawing);
|
169
|
-
break;
|
170
|
-
case "polygon" /* ToolEnum.Polygon */:
|
171
|
-
if (!canDrawShape(configuration, "polygon" /* ToolEnum.Polygon */, shapes, notify, strings.cannotDrawMorePolygons))
|
172
|
-
return;
|
173
|
-
handleMouseDownPolygon(event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
|
174
|
-
break;
|
175
|
-
case "polyline" /* ToolEnum.Polyline */:
|
176
|
-
if (!canDrawShape(configuration, "polyline" /* ToolEnum.Polyline */, shapes, notify, strings.cannotDrawMorePolylines))
|
177
|
-
return;
|
178
|
-
handleMouseDownPolyline(event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
|
179
|
-
break;
|
180
|
-
default:
|
181
|
-
break;
|
182
|
-
}
|
183
|
-
};
|
184
|
-
const handleMouseMove = (event) => {
|
185
|
-
switch (activeTool) {
|
186
|
-
case "rect" /* ToolEnum.Rectangle */:
|
187
|
-
handleMouseMoveRect(event, canvas, originX, originY, shape, isDrawing);
|
188
|
-
break;
|
189
|
-
case "polygon" /* ToolEnum.Polygon */:
|
190
|
-
handleMouseMovePolygon(event, canvas, isDrawing, lines);
|
191
|
-
break;
|
192
|
-
case "polyline" /* ToolEnum.Polyline */:
|
193
|
-
handleMouseMovePolyline(event, canvas, isDrawing, lines);
|
194
|
-
break;
|
195
|
-
default:
|
196
|
-
break;
|
197
|
-
}
|
198
|
-
};
|
199
|
-
const handleMouseUp = () => {
|
200
|
-
switch (activeTool) {
|
201
|
-
case "rect" /* ToolEnum.Rectangle */:
|
202
|
-
handleMouseUpRect(editorId, canvas, setIsDrawing, shape, setShape);
|
203
|
-
break;
|
204
|
-
default:
|
205
|
-
break;
|
206
|
-
}
|
207
|
-
};
|
208
|
-
const handleDoubleClick = () => {
|
209
|
-
switch (activeTool) {
|
210
|
-
case "polygon" /* ToolEnum.Polygon */:
|
211
|
-
handleDoubleClickPolygon(editorId, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
|
212
|
-
break;
|
213
|
-
case "polyline" /* ToolEnum.Polyline */:
|
214
|
-
handleDoubleClickPolyline(editorId, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
|
215
|
-
break;
|
216
|
-
default:
|
217
|
-
break;
|
218
|
-
}
|
219
|
-
};
|
220
|
-
canvas.on('mouse:down', handleMouseDown);
|
221
|
-
canvas.on('mouse:move', handleMouseMove);
|
222
|
-
canvas.on('mouse:up', handleMouseUp);
|
223
|
-
canvas.on('mouse:dblclick', handleDoubleClick);
|
224
|
-
canvas.on('selection:created', handleObjectSelected);
|
225
|
-
canvas.on('selection:updated', handleObjectSelected);
|
226
|
-
canvas.on('selection:cleared', handleSelectionCleared);
|
227
|
-
return () => {
|
228
|
-
canvas.off('mouse:down', handleMouseDown);
|
229
|
-
canvas.off('mouse:move', handleMouseMove);
|
230
|
-
canvas.off('mouse:up', handleMouseUp);
|
231
|
-
canvas.off('mouse:dblclick', handleDoubleClick);
|
232
|
-
canvas.off('selection:created', handleObjectSelected);
|
233
|
-
canvas.off('selection:updated', handleObjectSelected);
|
234
|
-
canvas.off('selection:cleared', handleSelectionCleared);
|
235
|
-
};
|
236
|
-
}, [
|
237
|
-
activeTool,
|
238
|
-
activeColor,
|
239
|
-
isDrawing,
|
240
|
-
shape,
|
241
|
-
originX,
|
242
|
-
originY,
|
243
|
-
startPos,
|
244
|
-
lines,
|
245
|
-
points,
|
246
|
-
canvas,
|
247
|
-
addShape,
|
248
|
-
handleObjectSelected,
|
249
|
-
handleSelectionCleared,
|
250
|
-
configuration,
|
251
|
-
notify,
|
252
|
-
strings,
|
253
|
-
shapes,
|
254
|
-
editorId,
|
255
|
-
]);
|
256
|
-
};
|
257
|
-
export const useDispatcherEvents = (canvas) => {
|
258
|
-
const { configuration, shapes, addShape, setActiveTool, editorId } = useEditorContext();
|
259
|
-
const { notify, strings } = useContext(UiContext);
|
260
|
-
useEffect(() => {
|
261
|
-
const removeShape = (_, id) => {
|
262
|
-
const obj = canvas === null || canvas === void 0 ? void 0 : canvas.getObjects().find((s) => s.id === id);
|
263
|
-
if (obj) {
|
264
|
-
canvas === null || canvas === void 0 ? void 0 : canvas.remove(obj);
|
265
|
-
}
|
266
|
-
};
|
267
|
-
const copyShape = (_, id) => {
|
268
|
-
const obj = canvas === null || canvas === void 0 ? void 0 : canvas.getObjects().find((s) => s.id === id);
|
269
|
-
let copy;
|
270
|
-
switch (obj === null || obj === void 0 ? void 0 : obj.type) {
|
271
|
-
case "polygon" /* ToolEnum.Polygon */:
|
272
|
-
if (!canDrawShape(configuration, "polygon" /* ToolEnum.Polygon */, shapes, notify, strings.cannotDrawMorePolygons))
|
273
|
-
return;
|
274
|
-
copy = copyPolygon(editorId, canvas, obj);
|
275
|
-
// @ts-expect-error id exists but his stupid ts does not know
|
276
|
-
Dispatcher.emit(`canvas:${editorId}:selectShape`, copy.id);
|
277
|
-
break;
|
278
|
-
case "polyline" /* ToolEnum.Polyline */:
|
279
|
-
if (!canDrawShape(configuration, "polyline" /* ToolEnum.Polyline */, shapes, notify, strings.cannotDrawMorePolylines))
|
280
|
-
return;
|
281
|
-
copy = copyPolyline(editorId, canvas, obj);
|
282
|
-
// @ts-expect-error id exists but his stupid ts does not know
|
283
|
-
Dispatcher.emit(`canvas:${editorId}:selectShape`, copy.id);
|
284
|
-
break;
|
285
|
-
case "rect" /* ToolEnum.Rectangle */:
|
286
|
-
if (!canDrawShape(configuration, "rect" /* ToolEnum.Rectangle */, shapes, notify, strings.cannotDrawMoreRectangles))
|
287
|
-
return;
|
288
|
-
copy = copyRectangle(editorId, canvas, obj);
|
289
|
-
// @ts-expect-error id exists but his stupid ts does not know
|
290
|
-
Dispatcher.emit(`canvas:${editorId}:selectShape`, copy.id);
|
291
|
-
break;
|
292
|
-
default:
|
293
|
-
break;
|
294
|
-
}
|
295
|
-
};
|
296
|
-
const selectShape = (_, id) => {
|
297
|
-
const obj = canvas === null || canvas === void 0 ? void 0 : canvas.getObjects().find((s) => s.id === id);
|
298
|
-
if (obj) {
|
299
|
-
canvas === null || canvas === void 0 ? void 0 : canvas.discardActiveObject();
|
300
|
-
canvas === null || canvas === void 0 ? void 0 : canvas.setActiveObject(obj);
|
301
|
-
canvas === null || canvas === void 0 ? void 0 : canvas.requestRenderAll();
|
302
|
-
setActiveTool("pointer" /* ToolEnum.Pointer */);
|
303
|
-
}
|
304
|
-
};
|
305
|
-
Dispatcher.register(`canvas:${editorId}:removeShape`, removeShape);
|
306
|
-
Dispatcher.register(`canvas:${editorId}:copyShape`, copyShape);
|
307
|
-
Dispatcher.register(`canvas:${editorId}:selectShape`, selectShape);
|
308
|
-
return () => {
|
309
|
-
Dispatcher.unregister(`canvas:${editorId}:removeShape`, removeShape);
|
310
|
-
Dispatcher.unregister(`canvas:${editorId}:copyShape`, copyShape);
|
311
|
-
Dispatcher.unregister(`canvas:${editorId}:selectShape`, selectShape);
|
312
|
-
};
|
313
|
-
}, [setActiveTool, canvas, addShape, configuration, shapes, notify, strings, editorId]);
|
314
|
-
};
|
315
|
-
export const useParametersForm = (parameters) => {
|
316
|
-
const [errors, setErrors] = useState({});
|
317
|
-
const [fields, setFields] = useState(parameters.reduce((acc, p) => (Object.assign(Object.assign({}, acc), { [p.codename]: p.value })), {}));
|
318
|
-
const setField = (key) => (value) => {
|
319
|
-
setFields(Object.assign(Object.assign({}, fields), { [key]: value }));
|
320
|
-
};
|
321
|
-
return {
|
322
|
-
fields,
|
323
|
-
setField,
|
324
|
-
setFields,
|
325
|
-
errors,
|
326
|
-
setErrors,
|
327
|
-
};
|
328
|
-
};
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useContext } from 'react';
|
3
|
-
import { UiContext } from '../../Providers/UiProvider';
|
4
|
-
const ParameterField = ({ value, onChange, parameter, errors }) => {
|
5
|
-
var _a, _b;
|
6
|
-
const { TextField, NumberField, BoolField, EnumField, strings } = useContext(UiContext);
|
7
|
-
const props = {
|
8
|
-
required: parameter.required,
|
9
|
-
label: `${parameter.label}${parameter.unit ? ` (${parameter.unit})` : ''}`,
|
10
|
-
error: !!errors[parameter.codename],
|
11
|
-
helperText: errors[parameter.codename]
|
12
|
-
? strings[errors[parameter.codename]]
|
13
|
-
: parameter.description,
|
14
|
-
};
|
15
|
-
switch (parameter.type) {
|
16
|
-
case 'string':
|
17
|
-
return ((_a = parameter.options) === null || _a === void 0 ? void 0 : _a.length) ? (_jsx(EnumField, Object.assign({ value: value, onChange: (v) => onChange(v), options: parameter.options, multiple: parameter.multiple }, props))) : (_jsx(TextField, Object.assign({ type: "text", value: value, onChange: (v) => onChange(v) }, props)));
|
18
|
-
case 'int':
|
19
|
-
case 'float':
|
20
|
-
return ((_b = parameter.options) === null || _b === void 0 ? void 0 : _b.length) ? (_jsx(EnumField, Object.assign({ value: value, onChange: (v) => onChange(v), options: parameter.options, multiple: parameter.multiple }, props))) : (_jsx(NumberField, Object.assign({ value: value, onChange: (v) => onChange(v) }, props)));
|
21
|
-
case 'bool':
|
22
|
-
return _jsx(BoolField, Object.assign({ value: value, onChange: (v) => onChange(v) }, props));
|
23
|
-
default:
|
24
|
-
return null;
|
25
|
-
}
|
26
|
-
};
|
27
|
-
export default ParameterField;
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
-
import { useContext, useState } from 'react';
|
3
|
-
import { UiContext } from '../../../Providers/UiProvider';
|
4
|
-
import { css } from '../../../Utils';
|
5
|
-
import RoleField from '../../RoleField';
|
6
|
-
import { useParametersForm } from '../Hooks';
|
7
|
-
import ParameterField from '../ParameterField';
|
8
|
-
import { validateParametersForm } from '../Utils';
|
9
|
-
import styles from './ParametersModalForm.module.css';
|
10
|
-
const ParametersModalForm = ({ title, onClose, parameters, data, onSubmit, shapeType, shapeName, shapeRole, }) => {
|
11
|
-
const { Modal, TextField, strings } = useContext(UiContext);
|
12
|
-
const [name, setName] = useState(shapeName !== null && shapeName !== void 0 ? shapeName : '');
|
13
|
-
const [role, setRole] = useState(shapeRole !== null && shapeRole !== void 0 ? shapeRole : '');
|
14
|
-
const { fields, setField, errors, setErrors } = useParametersForm(data);
|
15
|
-
const handleSubmit = () => {
|
16
|
-
if (validateParametersForm(parameters, fields, setErrors)) {
|
17
|
-
const data = [
|
18
|
-
...parameters.map((p) => ({ codename: p.codename, value: fields[p.codename] })),
|
19
|
-
];
|
20
|
-
if (shapeType) {
|
21
|
-
onSubmit(data, { name, role });
|
22
|
-
}
|
23
|
-
else {
|
24
|
-
onSubmit(data);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
};
|
28
|
-
return (_jsx(Modal, { onClose: onClose, title: title, isOpen: true, maxWidth: "sm", onSubmit: handleSubmit, children: _jsxs("div", { className: css('form', styles, null), children: [shapeType && (_jsxs(_Fragment, { children: [_jsx(TextField, { required: true, label: strings.name, type: "text", value: name, onChange: setName, error: !!errors.name, helperText: errors.name }), _jsx(RoleField, { required: true, value: role, onChange: setRole, error: !!errors.name, helperText: errors.name, shapeType: shapeType })] })), parameters.map((parameter) => {
|
29
|
-
switch (parameter.type) {
|
30
|
-
case 'string':
|
31
|
-
return (_jsx(ParameterField, { value: String(fields[parameter.codename]), onChange: setField(parameter.codename), parameter: parameter, errors: errors }, parameter.codename));
|
32
|
-
case 'int':
|
33
|
-
case 'float':
|
34
|
-
return (_jsx(ParameterField, { value: fields[parameter.codename], onChange: setField(parameter.codename), parameter: parameter, errors: errors }, parameter.codename));
|
35
|
-
case 'bool':
|
36
|
-
return (_jsx(ParameterField, { value: fields[parameter.codename], onChange: setField(parameter.codename), parameter: parameter, errors: errors }, parameter.codename));
|
37
|
-
default:
|
38
|
-
return null;
|
39
|
-
}
|
40
|
-
})] }) }));
|
41
|
-
};
|
42
|
-
export default ParametersModalForm;
|
@@ -1,77 +0,0 @@
|
|
1
|
-
import * as fabric from 'fabric';
|
2
|
-
import { v4 as uuidv4 } from 'uuid';
|
3
|
-
import Dispatcher from '../../Utils/Dispatcher';
|
4
|
-
const addPoint = (event, canvas, color, points, setPoints, lines, setLines) => {
|
5
|
-
const pointer = canvas.getScenePoint(event.e);
|
6
|
-
const newPoint = { x: pointer.x, y: pointer.y };
|
7
|
-
const newPolygonPoints = [...points, newPoint];
|
8
|
-
setPoints(newPolygonPoints);
|
9
|
-
if (newPolygonPoints.length > 0) {
|
10
|
-
const line = new fabric.Line([
|
11
|
-
newPolygonPoints[newPolygonPoints.length - 1].x,
|
12
|
-
newPolygonPoints[newPolygonPoints.length - 1].y,
|
13
|
-
pointer.x,
|
14
|
-
pointer.y,
|
15
|
-
], {
|
16
|
-
stroke: color,
|
17
|
-
strokeWidth: 2,
|
18
|
-
strokeUniform: true,
|
19
|
-
selectable: false,
|
20
|
-
hasControls: false,
|
21
|
-
});
|
22
|
-
canvas.add(line);
|
23
|
-
setLines([...lines, line]);
|
24
|
-
}
|
25
|
-
};
|
26
|
-
export const handleMouseDownPolygon = (event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines) => {
|
27
|
-
setIsDrawing(true);
|
28
|
-
addPoint(event, canvas, activeColor, points, setPoints, lines, setLines);
|
29
|
-
};
|
30
|
-
export const handleMouseMovePolygon = (event, canvas, isDrawing, lines) => {
|
31
|
-
if (isDrawing && lines.length > 0) {
|
32
|
-
const pointer = canvas.getScenePoint(event.e);
|
33
|
-
lines[lines.length - 1].set({ x2: pointer.x, y2: pointer.y });
|
34
|
-
canvas.renderAll();
|
35
|
-
}
|
36
|
-
};
|
37
|
-
export const handleDoubleClickPolygon = (editorId, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines) => {
|
38
|
-
if (points.length > 2) {
|
39
|
-
const id = uuidv4();
|
40
|
-
const polygon = new fabric.Polygon(points, {
|
41
|
-
fill: 'transparent',
|
42
|
-
stroke: activeColor,
|
43
|
-
strokeWidth: 2,
|
44
|
-
selectable: false,
|
45
|
-
hasControls: true,
|
46
|
-
hoverCursor: 'default',
|
47
|
-
// @ts-expect-error id is not included in types but the property is added and it works
|
48
|
-
id,
|
49
|
-
});
|
50
|
-
canvas.add(polygon);
|
51
|
-
Dispatcher.emit(`canvas:${editorId}:shapeAdded`, { id, type: "polygon" /* ToolEnum.Polygon */, shape: polygon });
|
52
|
-
setPoints([]);
|
53
|
-
for (const line of lines) {
|
54
|
-
canvas.remove(line); // Remove temporary lines
|
55
|
-
}
|
56
|
-
setLines([]);
|
57
|
-
setIsDrawing(false);
|
58
|
-
}
|
59
|
-
};
|
60
|
-
export const copyPolygon = (editorId, canvas, polygon) => {
|
61
|
-
const id = uuidv4();
|
62
|
-
const copy = new fabric.Polygon(polygon.points, {
|
63
|
-
top: polygon.top + 10,
|
64
|
-
left: polygon.left + 10,
|
65
|
-
fill: 'transparent',
|
66
|
-
stroke: polygon.stroke,
|
67
|
-
strokeWidth: polygon.strokeWidth,
|
68
|
-
selectable: false,
|
69
|
-
hasControls: true,
|
70
|
-
hoverCursor: 'default',
|
71
|
-
// @ts-expect-error id is not included in types but the property is added and it works
|
72
|
-
id,
|
73
|
-
});
|
74
|
-
canvas.add(copy);
|
75
|
-
Dispatcher.emit(`canvas:${editorId}:shapeAdded`, { id, type: "polygon" /* ToolEnum.Polygon */, shape: copy });
|
76
|
-
return copy;
|
77
|
-
};
|
@@ -1,75 +0,0 @@
|
|
1
|
-
import * as fabric from 'fabric';
|
2
|
-
import { v4 as uuidv4 } from 'uuid';
|
3
|
-
import Dispatcher from '../../Utils/Dispatcher';
|
4
|
-
const addPoint = (event, canvas, color, points, setPoints, lines, setLines) => {
|
5
|
-
const pointer = canvas.getScenePoint(event.e);
|
6
|
-
const newPoint = { x: pointer.x, y: pointer.y };
|
7
|
-
const newPolylinePoints = [...points, newPoint];
|
8
|
-
setPoints(newPolylinePoints);
|
9
|
-
if (newPolylinePoints.length > 0) {
|
10
|
-
const line = new fabric.Line([
|
11
|
-
newPolylinePoints[newPolylinePoints.length - 1].x,
|
12
|
-
newPolylinePoints[newPolylinePoints.length - 1].y,
|
13
|
-
pointer.x,
|
14
|
-
pointer.y,
|
15
|
-
], {
|
16
|
-
stroke: color,
|
17
|
-
strokeWidth: 2,
|
18
|
-
strokeUniform: true,
|
19
|
-
selectable: false,
|
20
|
-
hasControls: false,
|
21
|
-
});
|
22
|
-
canvas.add(line);
|
23
|
-
setLines([...lines, line]);
|
24
|
-
}
|
25
|
-
};
|
26
|
-
export const handleMouseDownPolyline = (event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines) => {
|
27
|
-
setIsDrawing(true);
|
28
|
-
addPoint(event, canvas, activeColor, points, setPoints, lines, setLines);
|
29
|
-
};
|
30
|
-
export const handleMouseMovePolyline = (event, canvas, isDrawing, lines) => {
|
31
|
-
if (isDrawing && lines.length > 0) {
|
32
|
-
const pointer = canvas.getScenePoint(event.e);
|
33
|
-
lines[lines.length - 1].set({ x2: pointer.x, y2: pointer.y });
|
34
|
-
canvas.renderAll();
|
35
|
-
}
|
36
|
-
};
|
37
|
-
export const handleDoubleClickPolyline = (editorId, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines) => {
|
38
|
-
if (points.length > 2) {
|
39
|
-
const id = uuidv4();
|
40
|
-
const polyline = new fabric.Polyline(points, {
|
41
|
-
fill: 'transparent',
|
42
|
-
stroke: activeColor,
|
43
|
-
strokeWidth: 2,
|
44
|
-
selectable: false,
|
45
|
-
hasControls: true,
|
46
|
-
lockRotation: false,
|
47
|
-
id,
|
48
|
-
});
|
49
|
-
canvas.add(polyline);
|
50
|
-
Dispatcher.emit(`canvas:${editorId}:shapeAdded`, { id, type: "polyline" /* ToolEnum.Polyline */, shape: polyline });
|
51
|
-
setPoints([]);
|
52
|
-
for (const line of lines) {
|
53
|
-
canvas.remove(line); // Remove temporary lines
|
54
|
-
}
|
55
|
-
setLines([]);
|
56
|
-
setIsDrawing(false);
|
57
|
-
}
|
58
|
-
};
|
59
|
-
export const copyPolyline = (editorId, canvas, polyline) => {
|
60
|
-
const id = uuidv4();
|
61
|
-
const copy = new fabric.Polyline(polyline.points, {
|
62
|
-
top: polyline.top + 10,
|
63
|
-
left: polyline.left + 10,
|
64
|
-
fill: 'transparent',
|
65
|
-
stroke: polyline.stroke,
|
66
|
-
strokeWidth: polyline.strokeWidth,
|
67
|
-
selectable: false,
|
68
|
-
hasControls: true,
|
69
|
-
hoverCursor: 'default',
|
70
|
-
id,
|
71
|
-
});
|
72
|
-
canvas.add(copy);
|
73
|
-
Dispatcher.emit(`canvas:${editorId}:shapeAdded`, { id, type: "polyline" /* ToolEnum.Polyline */, shape: copy });
|
74
|
-
return copy;
|
75
|
-
};
|
@@ -1,73 +0,0 @@
|
|
1
|
-
import * as fabric from 'fabric';
|
2
|
-
import { v4 as uuidv4 } from 'uuid';
|
3
|
-
import Dispatcher from '../../Utils/Dispatcher';
|
4
|
-
export const handleMouseDownRect = (event, canvas, activeColor, setOriginX, setOriginY, setShape, setIsDrawing) => {
|
5
|
-
const pointer = canvas.getScenePoint(event.e);
|
6
|
-
setOriginX(pointer.x);
|
7
|
-
setOriginY(pointer.y);
|
8
|
-
const id = uuidv4();
|
9
|
-
const newRectangle = new fabric.Rect({
|
10
|
-
left: pointer.x,
|
11
|
-
top: pointer.y,
|
12
|
-
originX: 'left',
|
13
|
-
originY: 'top',
|
14
|
-
width: 0,
|
15
|
-
height: 0,
|
16
|
-
fill: 'transparent',
|
17
|
-
stroke: activeColor,
|
18
|
-
strokeWidth: 2,
|
19
|
-
strokeUniform: true,
|
20
|
-
selectable: false,
|
21
|
-
hasControls: true,
|
22
|
-
hoverCursor: 'default',
|
23
|
-
id,
|
24
|
-
});
|
25
|
-
canvas.add(newRectangle);
|
26
|
-
setShape(newRectangle);
|
27
|
-
setIsDrawing(true);
|
28
|
-
};
|
29
|
-
export const handleMouseMoveRect = (event, canvas, originX, originY, shape, isDrawing) => {
|
30
|
-
if (isDrawing && shape) {
|
31
|
-
const pointer = canvas.getScenePoint(event.e);
|
32
|
-
shape.set({
|
33
|
-
width: Math.abs(originX - pointer.x),
|
34
|
-
height: Math.abs(originY - pointer.y),
|
35
|
-
});
|
36
|
-
if (originX > pointer.x) {
|
37
|
-
shape.set({ left: pointer.x });
|
38
|
-
}
|
39
|
-
if (originY > pointer.y) {
|
40
|
-
shape.set({ top: pointer.y });
|
41
|
-
}
|
42
|
-
canvas.renderAll();
|
43
|
-
}
|
44
|
-
};
|
45
|
-
export const handleMouseUpRect = (editorId, canvas, setIsDrawing, shape, setShape) => {
|
46
|
-
setIsDrawing(false);
|
47
|
-
shape.setCoords();
|
48
|
-
Dispatcher.emit(`canvas:${editorId}:shapeAdded`, { id: shape.id, type: "rect" /* ToolEnum.Rectangle */, shape });
|
49
|
-
setShape(null);
|
50
|
-
canvas.defaultCursor = 'default';
|
51
|
-
};
|
52
|
-
export const copyRectangle = (editorId, canvas, rectangle) => {
|
53
|
-
const id = uuidv4();
|
54
|
-
const copy = new fabric.Rect({
|
55
|
-
left: rectangle.left + 10,
|
56
|
-
top: rectangle.top + 10,
|
57
|
-
originX: 'left',
|
58
|
-
originY: 'top',
|
59
|
-
width: rectangle.width,
|
60
|
-
height: rectangle.height,
|
61
|
-
fill: 'transparent',
|
62
|
-
stroke: rectangle.stroke,
|
63
|
-
strokeWidth: rectangle.strokeWidth,
|
64
|
-
strokeUniform: true,
|
65
|
-
selectable: false,
|
66
|
-
hasControls: true,
|
67
|
-
hoverCursor: 'default',
|
68
|
-
id,
|
69
|
-
});
|
70
|
-
canvas.add(copy);
|
71
|
-
Dispatcher.emit(`canvas:${editorId}:shapeAdded`, { id, type: "rect" /* ToolEnum.Rectangle */, shape: copy });
|
72
|
-
return copy;
|
73
|
-
};
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useContext } from 'react';
|
3
|
-
import { useEditorContext } from '../../Providers/EditorProvider';
|
4
|
-
import { UiContext } from '../../Providers/UiProvider';
|
5
|
-
import { formatString } from '../../Utils';
|
6
|
-
import { OperatorEnum } from './Types';
|
7
|
-
const RoisInfo = () => {
|
8
|
-
var _a;
|
9
|
-
const { strings, Typography } = useContext(UiContext);
|
10
|
-
const { configuration } = useEditorContext();
|
11
|
-
if (!((_a = configuration.rois) === null || _a === void 0 ? void 0 : _a.length))
|
12
|
-
return null;
|
13
|
-
return (_jsxs("div", { children: [_jsxs(Typography, { component: "div", children: [strings.roisToBeDrawn, ":"] }), _jsx("ul", { children: configuration.rois.map((r) => {
|
14
|
-
var _a, _b;
|
15
|
-
let rule;
|
16
|
-
const data = {
|
17
|
-
role: r.label,
|
18
|
-
type: r.type,
|
19
|
-
threshold: (_a = r.multiplicity) === null || _a === void 0 ? void 0 : _a.threshold,
|
20
|
-
};
|
21
|
-
switch ((_b = r.multiplicity) === null || _b === void 0 ? void 0 : _b.operator) {
|
22
|
-
case OperatorEnum.Eq:
|
23
|
-
rule = formatString(strings.roiMultiplicityEqRule, data);
|
24
|
-
break;
|
25
|
-
case OperatorEnum.Lt:
|
26
|
-
rule = formatString(strings.roiMultiplicityLtRule, data);
|
27
|
-
break;
|
28
|
-
case OperatorEnum.Lte:
|
29
|
-
rule = formatString(strings.roiMultiplicityLteRule, data);
|
30
|
-
break;
|
31
|
-
case OperatorEnum.Gt:
|
32
|
-
rule = formatString(strings.roiMultiplicityGtRule, data);
|
33
|
-
break;
|
34
|
-
case OperatorEnum.Gte:
|
35
|
-
rule = formatString(strings.roiMultiplicityGteRule, data);
|
36
|
-
break;
|
37
|
-
default:
|
38
|
-
rule = formatString(strings.roiMultiplicityNoRule, data);
|
39
|
-
}
|
40
|
-
return (_jsx("li", { children: _jsx(Typography, { children: rule }) }, r.role));
|
41
|
-
}) })] }));
|
42
|
-
};
|
43
|
-
export default RoisInfo;
|