@abidibo/react-cam-roi 0.0.13 → 0.1.0

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 (100) hide show
  1. package/README.md +8 -19
  2. package/package.json +28 -1
  3. package/dist/Components/BoolField/BoolField.module.css +0 -60
  4. package/dist/Components/BoolField/index.d.ts +0 -5
  5. package/dist/Components/BoolField/index.js +0 -13
  6. package/dist/Components/Button/Button.module.css +0 -29
  7. package/dist/Components/Button/index.d.ts +0 -8
  8. package/dist/Components/Button/index.js +0 -15
  9. package/dist/Components/EnumField/EnumField.module.css +0 -61
  10. package/dist/Components/EnumField/index.d.ts +0 -10
  11. package/dist/Components/EnumField/index.js +0 -16
  12. package/dist/Components/IconButton/IconButton.module.css +0 -20
  13. package/dist/Components/IconButton/index.d.ts +0 -7
  14. package/dist/Components/IconButton/index.js +0 -10
  15. package/dist/Components/Loader/Loader.module.css +0 -25
  16. package/dist/Components/Loader/index.d.ts +0 -1
  17. package/dist/Components/Loader/index.js +0 -9
  18. package/dist/Components/Modal/Modal.module.css +0 -92
  19. package/dist/Components/Modal/index.d.ts +0 -10
  20. package/dist/Components/Modal/index.js +0 -16
  21. package/dist/Components/NumberField/NumberField.module.css +0 -60
  22. package/dist/Components/NumberField/index.d.ts +0 -3
  23. package/dist/Components/NumberField/index.js +0 -13
  24. package/dist/Components/RoiEditor/Canvas.d.ts +0 -10
  25. package/dist/Components/RoiEditor/Canvas.js +0 -28
  26. package/dist/Components/RoiEditor/ColorPicker.d.ts +0 -5
  27. package/dist/Components/RoiEditor/ColorPicker.js +0 -12
  28. package/dist/Components/RoiEditor/ColorPicker.module.css +0 -17
  29. package/dist/Components/RoiEditor/Header.d.ts +0 -2
  30. package/dist/Components/RoiEditor/Header.js +0 -22
  31. package/dist/Components/RoiEditor/Header.module.css +0 -32
  32. package/dist/Components/RoiEditor/Hooks.d.ts +0 -35
  33. package/dist/Components/RoiEditor/Hooks.js +0 -321
  34. package/dist/Components/RoiEditor/ParameterField.d.ts +0 -9
  35. package/dist/Components/RoiEditor/ParameterField.js +0 -27
  36. package/dist/Components/RoiEditor/ParametersModalForm/ParametersModalForm.module.css +0 -5
  37. package/dist/Components/RoiEditor/ParametersModalForm/index.d.ts +0 -16
  38. package/dist/Components/RoiEditor/ParametersModalForm/index.js +0 -40
  39. package/dist/Components/RoiEditor/Polygon.d.ts +0 -18
  40. package/dist/Components/RoiEditor/Polygon.js +0 -77
  41. package/dist/Components/RoiEditor/Polyline.d.ts +0 -28
  42. package/dist/Components/RoiEditor/Polyline.js +0 -75
  43. package/dist/Components/RoiEditor/Rectangle.d.ts +0 -21
  44. package/dist/Components/RoiEditor/Rectangle.js +0 -73
  45. package/dist/Components/RoiEditor/RoiEditor.module.css +0 -5
  46. package/dist/Components/RoiEditor/RoisInfo.d.ts +0 -2
  47. package/dist/Components/RoiEditor/RoisInfo.js +0 -43
  48. package/dist/Components/RoiEditor/ShapesList.d.ts +0 -2
  49. package/dist/Components/RoiEditor/ShapesList.js +0 -77
  50. package/dist/Components/RoiEditor/ShapesList.module.css +0 -67
  51. package/dist/Components/RoiEditor/Toolbar.d.ts +0 -2
  52. package/dist/Components/RoiEditor/Toolbar.js +0 -25
  53. package/dist/Components/RoiEditor/Toolbar.module.css +0 -41
  54. package/dist/Components/RoiEditor/Types.d.ts +0 -119
  55. package/dist/Components/RoiEditor/Types.js +0 -15
  56. package/dist/Components/RoiEditor/Utils.d.ts +0 -22
  57. package/dist/Components/RoiEditor/Utils.js +0 -150
  58. package/dist/Components/RoiEditor/index.d.ts +0 -10
  59. package/dist/Components/RoiEditor/index.js +0 -78
  60. package/dist/Components/RoleField.d.ts +0 -7
  61. package/dist/Components/RoleField.js +0 -35
  62. package/dist/Components/TextField/TextField.module.css +0 -61
  63. package/dist/Components/TextField/index.d.ts +0 -6
  64. package/dist/Components/TextField/index.js +0 -13
  65. package/dist/Components/Typography/index.d.ts +0 -9
  66. package/dist/Components/Typography/index.js +0 -6
  67. package/dist/Icons/AnnotateIcon.d.ts +0 -6
  68. package/dist/Icons/AnnotateIcon.js +0 -5
  69. package/dist/Icons/CloseIcon.d.ts +0 -6
  70. package/dist/Icons/CloseIcon.js +0 -5
  71. package/dist/Icons/CopyIcon.d.ts +0 -6
  72. package/dist/Icons/CopyIcon.js +0 -5
  73. package/dist/Icons/DeleteIcon.d.ts +0 -6
  74. package/dist/Icons/DeleteIcon.js +0 -5
  75. package/dist/Icons/EditIcon.d.ts +0 -6
  76. package/dist/Icons/EditIcon.js +0 -5
  77. package/dist/Icons/PointerIcon.d.ts +0 -6
  78. package/dist/Icons/PointerIcon.js +0 -5
  79. package/dist/Icons/PolygonIcon.d.ts +0 -6
  80. package/dist/Icons/PolygonIcon.js +0 -5
  81. package/dist/Icons/PolylineIcon.d.ts +0 -6
  82. package/dist/Icons/PolylineIcon.js +0 -5
  83. package/dist/Icons/RectangleIcon.d.ts +0 -6
  84. package/dist/Icons/RectangleIcon.js +0 -5
  85. package/dist/Icons/SaveIcon.d.ts +0 -6
  86. package/dist/Icons/SaveIcon.js +0 -5
  87. package/dist/Icons/SelectIcon.d.ts +0 -6
  88. package/dist/Icons/SelectIcon.js +0 -5
  89. package/dist/Providers/EditorProvider.d.ts +0 -26
  90. package/dist/Providers/EditorProvider.js +0 -29
  91. package/dist/Providers/UiProvider.d.ts +0 -84
  92. package/dist/Providers/UiProvider.js +0 -107
  93. package/dist/Types.d.ts +0 -10
  94. package/dist/Types.js +0 -1
  95. package/dist/Utils/Dispatcher.d.ts +0 -16
  96. package/dist/Utils/Dispatcher.js +0 -65
  97. package/dist/Utils/index.d.ts +0 -4
  98. package/dist/Utils/index.js +0 -14
  99. package/dist/index.d.ts +0 -4
  100. package/dist/index.js +0 -4
@@ -1,12 +0,0 @@
1
- import { 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 { css } from '../../Utils';
6
- import styles from './ColorPicker.module.css';
7
- const ColorPicker = ({ style }) => {
8
- const { pickerColors, themeMode } = useContext(UiContext);
9
- const { activeColor, setActiveColor } = useEditorContext();
10
- return (_jsx("div", { style: style, className: styles.colorpickerWrapper, children: pickerColors.map((color) => (_jsx("div", { onClick: () => setActiveColor(color), className: `${css('colorpicker-button', styles, themeMode)} ${activeColor === color ? css('colorpicker-button-active', styles, themeMode) : ''}`, style: { backgroundColor: color } }, color))) }));
11
- };
12
- export default ColorPicker;
@@ -1,17 +0,0 @@
1
- .colorpickerWrapper {
2
- display: flex;
3
- flex-wrap: nowrap;
4
- gap: .2rem;
5
- }
6
-
7
- .colorpicker-button {
8
- box-sizing: border-box;
9
- width: 24px;
10
- height: 24px;
11
- border-radius: 50%;
12
- cursor: pointer;
13
- }
14
-
15
- .colorpicker-button-active {
16
- border: 2px solid red;
17
- }
@@ -1,2 +0,0 @@
1
- declare const Header: () => import("react/jsx-runtime").JSX.Element;
2
- export default Header;
@@ -1,22 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext, useState } from 'react';
3
- import { useEditorContext } from '../../Providers/EditorProvider';
4
- import { UiContext } from '../../Providers/UiProvider';
5
- import { css } from '../../Utils';
6
- import styles from './Header.module.css';
7
- import ParametersModalForm from './ParametersModalForm';
8
- import { enableMainMetadata } from './Utils';
9
- import RoisInfo from './RoisInfo';
10
- const Header = () => {
11
- var _a;
12
- const { themeMode, Typography, Button, strings, SaveIcon, primaryFgColor, AnnotateIcon } = useContext(UiContext);
13
- const { configuration, onSubmit, metadata, setMetadata } = useEditorContext();
14
- const [form, setForm] = useState({ isOpen: false });
15
- const iconColor = themeMode === 'light' ? 'black' : 'white';
16
- const handleSubmitMetadata = (data) => {
17
- setMetadata(Object.assign(Object.assign({}, metadata), { parameters: data }));
18
- setForm({ isOpen: false });
19
- };
20
- return (_jsxs("div", { className: css('header', styles, themeMode), children: [_jsxs("div", { className: css('header-info', styles, themeMode), children: [((_a = configuration.options) === null || _a === void 0 ? void 0 : _a.description) && _jsx(Typography, { children: configuration.options.description }), _jsx(RoisInfo, {})] }), _jsxs("div", { className: styles.headerButtons, children: [enableMainMetadata(configuration) && (_jsxs(Button, { onClick: () => setForm({ isOpen: true }), children: [_jsx(AnnotateIcon, { color: iconColor }), " ", strings.mainParametersMetadata] })), _jsxs(Button, { primary: true, onClick: onSubmit, children: [_jsx(SaveIcon, { color: primaryFgColor }), " ", strings.save] })] }), form.isOpen && (_jsx(ParametersModalForm, { parameters: configuration.parameters, data: metadata.parameters, title: strings.mainParametersMetadata, onClose: () => setForm({ isOpen: false }), onSubmit: handleSubmitMetadata }))] }));
21
- };
22
- export default Header;
@@ -1,32 +0,0 @@
1
- .header {
2
- align-items: flex-start;
3
- display: flex;
4
- justify-content: space-between;
5
- padding: .5rem;
6
- }
7
-
8
- .header-light {
9
- background-color: #ddd;;
10
- }
11
-
12
- .header-dark {
13
- background-color: #222;
14
- }
15
-
16
- .header-info {
17
- padding: .5rem;
18
- }
19
- .header-info-light {
20
- background-color: #ddd;;
21
- color: #000;
22
- }
23
- .header-info-dark {
24
- background-color: #222;
25
- color: #fff;
26
- }
27
-
28
- .headerButtons {
29
- display: flex;
30
- align-items: center;
31
- gap: .5rem
32
- }
@@ -1,35 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { Metadata, Output, OutputParameter, Shape, ShapeType } from './Types';
3
- export declare const useImageSize: (imageUrl: string) => {
4
- imageSize: {
5
- width: number;
6
- height: number;
7
- };
8
- isReady: boolean;
9
- };
10
- export declare const useCanvasSize: (imageUrl: string) => {
11
- imageSize: {
12
- width: number;
13
- height: number;
14
- };
15
- canvasSize: {
16
- width: number;
17
- height: number;
18
- };
19
- wrapperRef: import("react").RefObject<HTMLDivElement>;
20
- isReady: boolean;
21
- };
22
- export declare const initCanvasData: (canvasRef: React.MutableRefObject<fabric.Canvas | null>, addShapes: (shapes: {
23
- id: string;
24
- type: ShapeType;
25
- shape: Shape;
26
- }[]) => void, metadata: Metadata, setMetadata: (v: Metadata) => void, initialData?: Output, enableLogs?: boolean) => void;
27
- export declare const useTool: (canvas: fabric.Canvas | null) => void;
28
- export declare const useDispatcherEvents: (canvas: fabric.Canvas | null) => void;
29
- export declare const useParametersForm: (parameters: OutputParameter[]) => {
30
- fields: Record<string, unknown>;
31
- setField: <T>(key: string) => (value: T) => void;
32
- setFields: import("react").Dispatch<import("react").SetStateAction<Record<string, unknown>>>;
33
- errors: Record<string, string>;
34
- setErrors: import("react").Dispatch<import("react").SetStateAction<Record<string, string>>>;
35
- };
@@ -1,321 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { useCallback, useContext, useEffect, useRef, useState } from 'react';
3
- import { v4 as uuidv4 } from 'uuid';
4
- import { useEditorContext } from '../../Providers/EditorProvider';
5
- import { UiContext } from '../../Providers/UiProvider';
6
- import { log } from '../../Utils';
7
- import Dispatcher from '../../Utils/Dispatcher';
8
- import { copyPolygon, handleDoubleClickPolygon, handleMouseDownPolygon, handleMouseMovePolygon } from './Polygon';
9
- import { copyPolyline, handleDoubleClickPolyline, handleMouseDownPolyline, handleMouseMovePolyline } from './Polyline';
10
- import { copyRectangle, handleMouseDownRect, handleMouseMoveRect, handleMouseUpRect } from './Rectangle';
11
- import { canDrawShape } from './Utils';
12
- export const useImageSize = (imageUrl) => {
13
- const [imageSize, setImageSize] = useState({ width: 0, height: 0 });
14
- useEffect(() => {
15
- const image = new Image();
16
- image.src = imageUrl;
17
- image.onload = () => {
18
- setImageSize({ width: image.width, height: image.height });
19
- };
20
- }, [imageUrl]);
21
- return { imageSize, isReady: imageSize.width > 0 };
22
- };
23
- export const useCanvasSize = (imageUrl) => {
24
- const wrapperRef = useRef(null);
25
- const [canvasSize, setCanvasSize] = useState({ width: 0, height: 0 });
26
- const { imageSize, isReady } = useImageSize(imageUrl);
27
- useEffect(() => {
28
- if (wrapperRef.current) {
29
- const update = () => {
30
- const availableWidth = wrapperRef.current.offsetWidth;
31
- if (availableWidth < imageSize.width) {
32
- setCanvasSize({
33
- width: availableWidth,
34
- height: availableWidth * (imageSize.height / imageSize.width),
35
- });
36
- }
37
- else {
38
- setCanvasSize({
39
- width: imageSize.width,
40
- height: imageSize.height,
41
- });
42
- }
43
- };
44
- if (imageSize.width > 0 && wrapperRef.current) {
45
- update();
46
- }
47
- }
48
- }, [imageSize, wrapperRef.current]); // eslint-disable-line
49
- return { imageSize, canvasSize, wrapperRef, isReady };
50
- };
51
- export const initCanvasData = (canvasRef, addShapes, metadata, setMetadata, initialData, enableLogs) => {
52
- log('info', enableLogs !== null && enableLogs !== void 0 ? enableLogs : false, 'Loading initial shapes data', initialData, canvasRef.current);
53
- if (initialData === null || initialData === void 0 ? void 0 : initialData.rois) {
54
- const m = [];
55
- const s = [];
56
- initialData.rois.forEach((r) => {
57
- var _a, _b, _c;
58
- log('info', enableLogs !== null && enableLogs !== void 0 ? enableLogs : false, 'Loading initial shape', r);
59
- const id = uuidv4();
60
- let shape;
61
- switch (r.type) {
62
- case "rect" /* ToolEnum.Rectangle */:
63
- shape = new fabric.Rect({
64
- left: r.shape.left,
65
- top: r.shape.top,
66
- originX: 'left',
67
- originY: 'top',
68
- width: r.shape.width,
69
- height: r.shape.height,
70
- fill: 'transparent',
71
- stroke: r.shape.color,
72
- strokeWidth: 2,
73
- strokeUniform: true,
74
- selectable: false,
75
- hasControls: true,
76
- hoverCursor: 'default',
77
- id,
78
- });
79
- (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.add(shape);
80
- break;
81
- case "polygon" /* ToolEnum.Polygon */:
82
- shape = new fabric.Polygon(r.shape.points, {
83
- top: r.shape.top + 10,
84
- left: r.shape.left + 10,
85
- fill: 'transparent',
86
- stroke: r.shape.color,
87
- strokeWidth: 2,
88
- selectable: false,
89
- hasControls: true,
90
- hoverCursor: 'default',
91
- // @ts-expect-error id is not included in types but the property is added and it works
92
- id,
93
- });
94
- (_b = canvasRef.current) === null || _b === void 0 ? void 0 : _b.add(shape);
95
- break;
96
- case "polyline" /* ToolEnum.Polyline */:
97
- shape = new fabric.Polyline(r.shape.points, {
98
- top: r.shape.top + 10,
99
- left: r.shape.left + 10,
100
- fill: 'transparent',
101
- stroke: r.shape.color,
102
- strokeWidth: 2,
103
- selectable: false,
104
- hasControls: true,
105
- hoverCursor: 'default',
106
- id,
107
- });
108
- (_c = canvasRef.current) === null || _c === void 0 ? void 0 : _c.add(shape);
109
- break;
110
- }
111
- m.push({ id, parameters: r.parameters, name: r.name, role: r.role });
112
- s.push({ id, type: r.type, shape });
113
- });
114
- addShapes(s);
115
- setMetadata(Object.assign(Object.assign({}, metadata), { rois: m }));
116
- }
117
- };
118
- export const useTool = (canvas) => {
119
- const { editorId, configuration, activeTool, activeColor, shapes, addShape } = useEditorContext();
120
- const { notify, strings } = useContext(UiContext);
121
- const [isDrawing, setIsDrawing] = useState(false);
122
- const [shape, setShape] = useState(null);
123
- const [originX, setOriginX] = useState(0);
124
- const [originY, setOriginY] = useState(0);
125
- const [startPos] = useState({ x: 0, y: 0 });
126
- const [points, setPoints] = useState([]);
127
- const [lines, setLines] = useState([]);
128
- // Handler for object selected event to update style settings
129
- const handleObjectSelected = useCallback((event) => {
130
- var _a;
131
- Dispatcher.emit(`canvas:${editorId}:shapeSelected`, (_a = event.selected) !== null && _a !== void 0 ? _a : null);
132
- }, [editorId]);
133
- // Handler for selection cleared event to reset selected shapes state
134
- const handleSelectionCleared = useCallback(() => {
135
- Dispatcher.emit(`canvas:${editorId}:shapeSelected`, null);
136
- }, [editorId]);
137
- useEffect(() => {
138
- if (!canvas) {
139
- return;
140
- }
141
- if (activeTool === "pointer" /* ToolEnum.Pointer */) {
142
- // enable selection
143
- canvas.selection = true;
144
- canvas.getObjects().forEach((object) => {
145
- object.selectable = true;
146
- });
147
- canvas.renderAll();
148
- }
149
- else {
150
- // disable selection
151
- canvas.selection = false;
152
- canvas.discardActiveObject();
153
- Dispatcher.emit(`canvas:${editorId}:shapeSelected`, null);
154
- canvas.renderAll();
155
- }
156
- const handleMouseDown = (event) => {
157
- switch (activeTool) {
158
- case "rect" /* ToolEnum.Rectangle */:
159
- if (!canDrawShape(configuration, "rect" /* ToolEnum.Rectangle */, shapes, notify, strings.cannotDrawMoreRectangles))
160
- return;
161
- handleMouseDownRect(event, canvas, activeColor, setOriginX, setOriginY, setShape, setIsDrawing);
162
- break;
163
- case "polygon" /* ToolEnum.Polygon */:
164
- if (!canDrawShape(configuration, "polygon" /* ToolEnum.Polygon */, shapes, notify, strings.cannotDrawMorePolygons))
165
- return;
166
- handleMouseDownPolygon(event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
167
- break;
168
- case "polyline" /* ToolEnum.Polyline */:
169
- if (!canDrawShape(configuration, "polyline" /* ToolEnum.Polyline */, shapes, notify, strings.cannotDrawMorePolylines))
170
- return;
171
- handleMouseDownPolyline(event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
172
- break;
173
- default:
174
- break;
175
- }
176
- };
177
- const handleMouseMove = (event) => {
178
- switch (activeTool) {
179
- case "rect" /* ToolEnum.Rectangle */:
180
- handleMouseMoveRect(event, canvas, originX, originY, shape, isDrawing);
181
- break;
182
- case "polygon" /* ToolEnum.Polygon */:
183
- handleMouseMovePolygon(event, canvas, isDrawing, lines);
184
- break;
185
- case "polyline" /* ToolEnum.Polyline */:
186
- handleMouseMovePolyline(event, canvas, isDrawing, lines);
187
- break;
188
- default:
189
- break;
190
- }
191
- };
192
- const handleMouseUp = () => {
193
- switch (activeTool) {
194
- case "rect" /* ToolEnum.Rectangle */:
195
- handleMouseUpRect(editorId, canvas, setIsDrawing, shape, setShape);
196
- break;
197
- default:
198
- break;
199
- }
200
- };
201
- const handleDoubleClick = () => {
202
- switch (activeTool) {
203
- case "polygon" /* ToolEnum.Polygon */:
204
- handleDoubleClickPolygon(editorId, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
205
- break;
206
- case "polyline" /* ToolEnum.Polyline */:
207
- handleDoubleClickPolyline(editorId, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines);
208
- break;
209
- default:
210
- break;
211
- }
212
- };
213
- canvas.on('mouse:down', handleMouseDown);
214
- canvas.on('mouse:move', handleMouseMove);
215
- canvas.on('mouse:up', handleMouseUp);
216
- canvas.on('mouse:dblclick', handleDoubleClick);
217
- canvas.on('selection:created', handleObjectSelected);
218
- canvas.on('selection:updated', handleObjectSelected);
219
- canvas.on('selection:cleared', handleSelectionCleared);
220
- return () => {
221
- canvas.off('mouse:down', handleMouseDown);
222
- canvas.off('mouse:move', handleMouseMove);
223
- canvas.off('mouse:up', handleMouseUp);
224
- canvas.off('mouse:dblclick', handleDoubleClick);
225
- canvas.off('selection:created', handleObjectSelected);
226
- canvas.off('selection:updated', handleObjectSelected);
227
- canvas.off('selection:cleared', handleSelectionCleared);
228
- };
229
- }, [
230
- activeTool,
231
- activeColor,
232
- isDrawing,
233
- shape,
234
- originX,
235
- originY,
236
- startPos,
237
- lines,
238
- points,
239
- canvas,
240
- addShape,
241
- handleObjectSelected,
242
- handleSelectionCleared,
243
- configuration,
244
- notify,
245
- strings,
246
- shapes,
247
- editorId,
248
- ]);
249
- };
250
- export const useDispatcherEvents = (canvas) => {
251
- const { configuration, shapes, addShape, setActiveTool, editorId } = useEditorContext();
252
- const { notify, strings } = useContext(UiContext);
253
- useEffect(() => {
254
- const removeShape = (_, id) => {
255
- const obj = canvas === null || canvas === void 0 ? void 0 : canvas.getObjects().find((s) => s.id === id);
256
- if (obj) {
257
- canvas === null || canvas === void 0 ? void 0 : canvas.remove(obj);
258
- }
259
- };
260
- const copyShape = (_, id) => {
261
- const obj = canvas === null || canvas === void 0 ? void 0 : canvas.getObjects().find((s) => s.id === id);
262
- let copy;
263
- switch (obj === null || obj === void 0 ? void 0 : obj.type) {
264
- case "polygon" /* ToolEnum.Polygon */:
265
- if (!canDrawShape(configuration, "polygon" /* ToolEnum.Polygon */, shapes, notify, strings.cannotDrawMorePolygons))
266
- return;
267
- copy = copyPolygon(editorId, canvas, obj);
268
- // @ts-expect-error id exists but his stupid ts does not know
269
- Dispatcher.emit(`canvas:${editorId}:selectShape`, copy.id);
270
- break;
271
- case "polyline" /* ToolEnum.Polyline */:
272
- if (!canDrawShape(configuration, "polyline" /* ToolEnum.Polyline */, shapes, notify, strings.cannotDrawMorePolylines))
273
- return;
274
- copy = copyPolyline(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 "rect" /* ToolEnum.Rectangle */:
279
- if (!canDrawShape(configuration, "rect" /* ToolEnum.Rectangle */, shapes, notify, strings.cannotDrawMoreRectangles))
280
- return;
281
- copy = copyRectangle(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
- default:
286
- break;
287
- }
288
- };
289
- const selectShape = (_, id) => {
290
- const obj = canvas === null || canvas === void 0 ? void 0 : canvas.getObjects().find((s) => s.id === id);
291
- if (obj) {
292
- canvas === null || canvas === void 0 ? void 0 : canvas.discardActiveObject();
293
- canvas === null || canvas === void 0 ? void 0 : canvas.setActiveObject(obj);
294
- canvas === null || canvas === void 0 ? void 0 : canvas.requestRenderAll();
295
- setActiveTool("pointer" /* ToolEnum.Pointer */);
296
- }
297
- };
298
- Dispatcher.register(`canvas:${editorId}:removeShape`, removeShape);
299
- Dispatcher.register(`canvas:${editorId}:copyShape`, copyShape);
300
- Dispatcher.register(`canvas:${editorId}:selectShape`, selectShape);
301
- return () => {
302
- Dispatcher.unregister(`canvas:${editorId}:removeShape`, removeShape);
303
- Dispatcher.unregister(`canvas:${editorId}:copyShape`, copyShape);
304
- Dispatcher.unregister(`canvas:${editorId}:selectShape`, selectShape);
305
- };
306
- }, [setActiveTool, canvas, addShape, configuration, shapes, notify, strings, editorId]);
307
- };
308
- export const useParametersForm = (parameters) => {
309
- const [errors, setErrors] = useState({});
310
- const [fields, setFields] = useState(parameters.reduce((acc, p) => (Object.assign(Object.assign({}, acc), { [p.codename]: p.value })), {}));
311
- const setField = (key) => (value) => {
312
- setFields(Object.assign(Object.assign({}, fields), { [key]: value }));
313
- };
314
- return {
315
- fields,
316
- setField,
317
- setFields,
318
- errors,
319
- setErrors,
320
- };
321
- };
@@ -1,9 +0,0 @@
1
- import { ConfigurationParameter } from './Types';
2
- export type ParameterFieldProps<T> = {
3
- value: T;
4
- onChange: (value: T) => void;
5
- parameter: ConfigurationParameter;
6
- errors: Record<string, string>;
7
- };
8
- declare const ParameterField: <T>({ value, onChange, parameter, errors }: ParameterFieldProps<T>) => import("react/jsx-runtime").JSX.Element | null;
9
- export default ParameterField;
@@ -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,5 +0,0 @@
1
- .form {
2
- display: flex;
3
- flex-direction: column;
4
- gap: 1rem;
5
- }
@@ -1,16 +0,0 @@
1
- import { ConfigurationParameter, OutputParameter, ShapeType } from '../Types';
2
- export type ParametersModalFormProps = {
3
- onClose: () => void;
4
- title: string;
5
- parameters: ConfigurationParameter[];
6
- data: OutputParameter[];
7
- onSubmit: (data: OutputParameter[], properties?: {
8
- name: string;
9
- role: string;
10
- }) => void;
11
- shapeType?: ShapeType;
12
- shapeName?: string;
13
- shapeRole?: string;
14
- };
15
- declare const ParametersModalForm: React.FC<ParametersModalFormProps>;
16
- export default ParametersModalForm;
@@ -1,40 +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 = [...parameters.map((p) => ({ codename: p.codename, value: fields[p.codename] }))];
18
- if (shapeType) {
19
- onSubmit(data, { name, role });
20
- }
21
- else {
22
- onSubmit(data);
23
- }
24
- }
25
- };
26
- 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) => {
27
- switch (parameter.type) {
28
- case 'string':
29
- return (_jsx(ParameterField, { value: String(fields[parameter.codename]), onChange: setField(parameter.codename), parameter: parameter, errors: errors }, parameter.codename));
30
- case 'int':
31
- case 'float':
32
- return (_jsx(ParameterField, { value: fields[parameter.codename], onChange: setField(parameter.codename), parameter: parameter, errors: errors }, parameter.codename));
33
- case 'bool':
34
- return (_jsx(ParameterField, { value: fields[parameter.codename], onChange: setField(parameter.codename), parameter: parameter, errors: errors }, parameter.codename));
35
- default:
36
- return null;
37
- }
38
- })] }) }));
39
- };
40
- export default ParametersModalForm;
@@ -1,18 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { FabricEvent } from './Types';
3
- export declare const handleMouseDownPolygon: (event: FabricEvent, canvas: fabric.Canvas, activeColor: string, setIsDrawing: (v: boolean) => void, points: {
4
- x: number;
5
- y: number;
6
- }[], setPoints: (v: {
7
- x: number;
8
- y: number;
9
- }[]) => void, lines: fabric.Line[], setLines: (v: fabric.Line[]) => void) => void;
10
- export declare const handleMouseMovePolygon: (event: FabricEvent, canvas: fabric.Canvas, isDrawing: boolean, lines: fabric.Line[]) => void;
11
- export declare const handleDoubleClickPolygon: (editorId: string, canvas: fabric.Canvas, activeColor: string, setIsDrawing: (v: boolean) => void, points: {
12
- x: number;
13
- y: number;
14
- }[], setPoints: (v: {
15
- x: number;
16
- y: number;
17
- }[]) => void, lines: fabric.Line[], setLines: (v: fabric.Line[]) => void) => void;
18
- export declare const copyPolygon: (editorId: string, canvas: fabric.Canvas, polygon: fabric.Polygon) => fabric.Polygon;
@@ -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
- };