@abidibo/react-cam-roi 0.0.7 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/README.md +588 -29
  2. package/dist/Components/BoolField/BoolField.module.css +60 -0
  3. package/dist/Components/BoolField/index.d.ts +5 -0
  4. package/dist/Components/BoolField/index.js +13 -0
  5. package/dist/Components/Button/Button.module.css +27 -0
  6. package/dist/Components/Button/index.d.ts +8 -0
  7. package/dist/Components/Button/index.js +15 -0
  8. package/dist/Components/EnumField/EnumField.module.css +61 -0
  9. package/dist/Components/EnumField/index.d.ts +10 -0
  10. package/dist/Components/EnumField/index.js +16 -0
  11. package/dist/Components/IconButton/IconButton.module.css +8 -3
  12. package/dist/Components/IconButton/index.d.ts +1 -0
  13. package/dist/Components/IconButton/index.js +3 -3
  14. package/dist/Components/Modal/Modal.module.css +92 -0
  15. package/dist/Components/Modal/index.d.ts +10 -0
  16. package/dist/Components/Modal/index.js +16 -0
  17. package/dist/Components/NumberField/NumberField.module.css +60 -0
  18. package/dist/Components/NumberField/index.d.ts +3 -0
  19. package/dist/Components/NumberField/index.js +13 -0
  20. package/dist/Components/RoiEditor/Canvas.d.ts +2 -0
  21. package/dist/Components/RoiEditor/Canvas.js +21 -11
  22. package/dist/Components/RoiEditor/Hooks.d.ts +16 -4
  23. package/dist/Components/RoiEditor/Hooks.js +148 -21
  24. package/dist/Components/RoiEditor/ParameterField.d.ts +9 -0
  25. package/dist/Components/RoiEditor/ParameterField.js +27 -0
  26. package/dist/Components/RoiEditor/ParametersModalForm/ParametersModalForm.module.css +5 -0
  27. package/dist/Components/RoiEditor/ParametersModalForm/index.d.ts +10 -0
  28. package/dist/Components/RoiEditor/ParametersModalForm/index.js +31 -0
  29. package/dist/Components/RoiEditor/Polygon.d.ts +3 -2
  30. package/dist/Components/RoiEditor/Polygon.js +18 -0
  31. package/dist/Components/RoiEditor/Polyline.d.ts +12 -1
  32. package/dist/Components/RoiEditor/Polyline.js +18 -0
  33. package/dist/Components/RoiEditor/Rectangle.d.ts +17 -1
  34. package/dist/Components/RoiEditor/Rectangle.js +23 -1
  35. package/dist/Components/RoiEditor/ShapesList.d.ts +2 -0
  36. package/dist/Components/RoiEditor/ShapesList.js +47 -0
  37. package/dist/Components/RoiEditor/ShapesList.module.css +36 -0
  38. package/dist/Components/RoiEditor/Toolbar.js +20 -6
  39. package/dist/Components/RoiEditor/Toolbar.module.css +40 -0
  40. package/dist/Components/RoiEditor/Types.d.ts +97 -1
  41. package/dist/Components/RoiEditor/Types.js +15 -1
  42. package/dist/Components/RoiEditor/Utils.d.ts +22 -0
  43. package/dist/Components/RoiEditor/Utils.js +143 -0
  44. package/dist/Components/RoiEditor/index.d.ts +4 -0
  45. package/dist/Components/RoiEditor/index.js +44 -7
  46. package/dist/Components/TextField/TextField.module.css +61 -0
  47. package/dist/Components/TextField/index.d.ts +6 -0
  48. package/dist/Components/TextField/index.js +13 -0
  49. package/dist/Components/Typography/index.d.ts +4 -0
  50. package/dist/Components/Typography/index.js +3 -2
  51. package/dist/Icons/AnnotateIcon.d.ts +6 -0
  52. package/dist/Icons/AnnotateIcon.js +5 -0
  53. package/dist/Icons/CloseIcon.d.ts +6 -0
  54. package/dist/Icons/CloseIcon.js +5 -0
  55. package/dist/Icons/CopyIcon.d.ts +6 -0
  56. package/dist/Icons/CopyIcon.js +5 -0
  57. package/dist/Icons/SaveIcon.d.ts +6 -0
  58. package/dist/Icons/SaveIcon.js +5 -0
  59. package/dist/Providers/EditorProvider.d.ts +12 -2
  60. package/dist/Providers/EditorProvider.js +16 -2
  61. package/dist/Providers/UiProvider.d.ts +44 -2
  62. package/dist/Providers/UiProvider.js +55 -2
  63. package/dist/Types.d.ts +10 -0
  64. package/dist/Types.js +1 -0
  65. package/dist/Utils/index.d.ts +1 -1
  66. package/dist/Utils/index.js +1 -1
  67. package/dist/index.d.ts +2 -1
  68. package/dist/index.js +2 -1
  69. package/package.json +13 -4
  70. package/dist/Components/RoiEditor/Metadata.d.ts +0 -2
  71. package/dist/Components/RoiEditor/Metadata.js +0 -31
  72. package/dist/Components/RoiEditor/Metadata.module.css +0 -34
@@ -0,0 +1,60 @@
1
+ /*
2
+ .bool-field-wrapper {
3
+ margin-bottom: 2rem;
4
+ }
5
+ .bool-field-wrapper-light {
6
+ }
7
+ .bool-field-wrapper-dark {
8
+ }
9
+ */
10
+
11
+ .bool-field {
12
+ border-radius: 0.25rem;
13
+ box-sizing: border-box;
14
+ padding: 0.5rem;
15
+ }
16
+ .bool-field:focus-visible {
17
+ outline: none;
18
+ border: 1px solid #1976d2;
19
+ }
20
+ .bool-field-light {
21
+ background-color: #fff;
22
+ color: #333;
23
+ border: 1px solid #ccc;
24
+ }
25
+ .bool-field-dark {
26
+ background-color: #333;
27
+ border: 1px solid #666;
28
+ color: #fff;
29
+ }
30
+ .bool-field-error {
31
+ border: 1px solid #d32f2f;
32
+ }
33
+ .bool-field-label {
34
+ font-weight: bold;
35
+ display: block;
36
+ margin: 0 0 1rem 0;
37
+ }
38
+ /*
39
+ .text-fiel-label-light {
40
+ }
41
+ .bool-field-label-dark {
42
+ }
43
+ */
44
+ .bool-field-label-error {
45
+ color: #d32f2f;
46
+ }
47
+ .bool-field-helper-text {
48
+ font-style: italic;
49
+ font-size: 0.9rem;
50
+ margin-top: 0.5rem;
51
+ }
52
+ /*
53
+ .bool-field-helper-text-light {
54
+ }
55
+ .bool-field-helper-text-dark {
56
+ }
57
+ */
58
+ .bool-field-helper-text-error {
59
+ color: #d32f2f;
60
+ }
@@ -0,0 +1,5 @@
1
+ import { FieldProps } from "../../Types";
2
+ declare const BoolField: React.FC<Omit<FieldProps<boolean>, 'onChange'> & {
3
+ onChange: (value: boolean) => void;
4
+ }>;
5
+ export default BoolField;
@@ -0,0 +1,13 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import { UiContext } from "../../Providers/UiProvider";
4
+ import { css } from "../../Utils";
5
+ import styles from './BoolField.module.css';
6
+ const BoolField = ({ onChange, value, label, helperText, error, readOnly = false, disabled = false, required = false, }) => {
7
+ const { themeMode, Typography } = useContext(UiContext);
8
+ const handleChange = (e) => {
9
+ onChange(e.target.checked);
10
+ };
11
+ return (_jsxs("div", { className: css('bool-field-wrapper', styles, themeMode), children: [_jsx("label", { className: `${css('bool-field-label', styles, themeMode)} ${error ? css('bool-field-label-error', styles, null) : ''}`, children: _jsxs(Typography, { children: [label, required && ' *'] }) }), _jsx("input", { type: 'checkbox', className: `${css('bool-field', styles, themeMode)} ${error ? css('bool-field-error', styles, null) : ''}`, onChange: handleChange, checked: value, readOnly: readOnly, disabled: disabled }), helperText && (_jsx(Typography, { component: 'div', className: `${css('bool-field-helper-text', styles, themeMode)} ${error ? css('bool-field-helper-text-error', styles, null) : ''}`, children: helperText }))] }));
12
+ };
13
+ export default BoolField;
@@ -0,0 +1,27 @@
1
+ .button {
2
+ border: none;
3
+ border-radius: 4px;
4
+ color: black;
5
+ padding: .5rem 1rem;
6
+ text-align: center;
7
+ text-decoration: none;
8
+ display: inline-block;
9
+ font-size: 16px;
10
+ margin: 4px 2px;
11
+ cursor: pointer;
12
+ }
13
+
14
+ .button-light {
15
+ background-color: #d7d7d7;
16
+ color: black;
17
+ }
18
+
19
+ .button-dark {
20
+ background-color: #383838;
21
+ color: white;
22
+ }
23
+
24
+ .button-disabled {
25
+ cursor: not-allowed;
26
+ opacity: 0.5;
27
+ }
@@ -0,0 +1,8 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export type ButtonProps = {
3
+ onClick: (event: React.MouseEvent) => void;
4
+ primary?: boolean;
5
+ disabled?: boolean;
6
+ };
7
+ declare const Button: ({ onClick, primary, disabled, children }: PropsWithChildren<ButtonProps>) => import("react/jsx-runtime").JSX.Element;
8
+ export default Button;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext } from 'react';
3
+ import { UiContext } from '../../Providers/UiProvider';
4
+ import { css } from '../../Utils';
5
+ import styles from './Button.module.css';
6
+ const Button = ({ onClick, primary, disabled, children }) => {
7
+ const { themeMode, primaryColor } = useContext(UiContext);
8
+ const style = {};
9
+ if (primary) {
10
+ style.backgroundColor = primaryColor;
11
+ style.color = 'white';
12
+ }
13
+ return (_jsx("button", { className: `${css('button', styles, themeMode)}${disabled ? ` ${css('button-disabled', styles, themeMode)}` : ''}`, style: style, onClick: onClick, disabled: disabled, children: children }));
14
+ };
15
+ export default Button;
@@ -0,0 +1,61 @@
1
+ /*
2
+ .enum-field-wrapper {
3
+ margin-bottom: 2rem;
4
+ }
5
+ .enum-field-wrapper-light {
6
+ }
7
+ .enum-field-wrapper-dark {
8
+ }
9
+ */
10
+
11
+ .enum-field {
12
+ border-radius: 0.25rem;
13
+ box-sizing: border-box;
14
+ padding: 0.5rem;
15
+ width: 100%;
16
+ }
17
+ .enum-field:focus-visible {
18
+ outline: none;
19
+ border: 1px solid #1976d2;
20
+ }
21
+ .enum-field-light {
22
+ background-color: #fff;
23
+ color: #333;
24
+ border: 1px solid #ccc;
25
+ }
26
+ .enum-field-dark {
27
+ background-color: #333;
28
+ border: 1px solid #666;
29
+ color: #fff;
30
+ }
31
+ .enum-field-error {
32
+ border: 1px solid #d32f2f;
33
+ }
34
+ .enum-field-label {
35
+ font-weight: bold;
36
+ display: block;
37
+ margin: 0 0 1rem 0;
38
+ }
39
+ /*
40
+ .text-fiel-label-light {
41
+ }
42
+ .enum-field-label-dark {
43
+ }
44
+ */
45
+ .enum-field-label-error {
46
+ color: #d32f2f;
47
+ }
48
+ .enum-field-helper-text {
49
+ font-style: italic;
50
+ font-size: 0.9rem;
51
+ margin-top: 0.5rem;
52
+ }
53
+ /*
54
+ .enum-field-helper-text-light {
55
+ }
56
+ .enum-field-helper-text-dark {
57
+ }
58
+ */
59
+ .enum-field-helper-text-error {
60
+ color: #d32f2f;
61
+ }
@@ -0,0 +1,10 @@
1
+ import { FieldProps } from '../../Types';
2
+ export type EnumOption = {
3
+ value: string | number;
4
+ label: string;
5
+ };
6
+ declare const EnumField: ({ onChange, value, label, helperText, error, options, disabled, required, multiple }: Omit<FieldProps<string | number | (string | number)[]>, "readOnly"> & {
7
+ options: EnumOption[];
8
+ multiple?: boolean;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ export default EnumField;
@@ -0,0 +1,16 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext } from 'react';
3
+ import { UiContext } from '../../Providers/UiProvider';
4
+ import { css } from '../../Utils';
5
+ import styles from './EnumField.module.css';
6
+ const EnumField = ({ onChange, value, label, helperText, error, options, disabled = false, required = false, multiple = false }) => {
7
+ const { themeMode, Typography } = useContext(UiContext);
8
+ const handleChange = (e) => {
9
+ const selectedValues = Array.from(e.target.selectedOptions, (option) => {
10
+ return isNaN(Number(option.value)) ? option.value : Number(option.value);
11
+ });
12
+ onChange(multiple ? selectedValues : selectedValues[0]);
13
+ };
14
+ return (_jsxs("div", { className: css('enum-field-wrapper', styles, themeMode), children: [_jsx("label", { className: `${css('enum-field-label', styles, themeMode)} ${error ? css('enum-field-label-error', styles, null) : ''}`, children: _jsxs(Typography, { children: [label, required && ' *'] }) }), _jsxs("select", { className: `${css('enum-field', styles, themeMode)} ${error ? css('enum-field-error', styles, null) : ''}`, onChange: handleChange, value: value, disabled: disabled, multiple: multiple, children: [!required && _jsx("option", { value: '' }), options.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value)))] }), helperText && (_jsx(Typography, { component: 'div', className: `${css('enum-field-helper-text', styles, themeMode)} ${error ? css('enum-field-helper-text-error', styles, null) : ''}`, children: helperText }))] }));
15
+ };
16
+ export default EnumField;
@@ -1,4 +1,4 @@
1
- .iconButton {
1
+ .icon-button {
2
2
  display: inline-block;
3
3
  border-radius: 50%;
4
4
  line-height: 0;
@@ -6,10 +6,15 @@
6
6
  cursor: pointer;
7
7
  }
8
8
 
9
- .iconButton-light:hover {
9
+ .icon-button-light:hover {
10
10
  background-color: rgba(0, 0, 0, 0.1);
11
11
  }
12
12
 
13
- .iconButton-dark:hover {
13
+ .icon-button-dark:hover {
14
14
  background-color: rgba(255, 255, 255, 0.1);
15
15
  }
16
+
17
+ .icon-button-disabled {
18
+ cursor: not-allowed;
19
+ opacity: 0.5;
20
+ }
@@ -1,5 +1,6 @@
1
1
  export type IconButtonProps = {
2
2
  children?: React.ReactNode;
3
+ disabled?: boolean;
3
4
  onClick?: (event: React.MouseEvent) => void;
4
5
  };
5
6
  declare const IconButton: React.FC<IconButtonProps>;
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext } from 'react';
3
+ import { UiContext } from '../../Providers/UiProvider';
3
4
  import { css } from '../../Utils';
4
5
  import styles from './IconButton.module.css';
5
- import { UiContext } from '../../Providers/UiProvider';
6
- const IconButton = ({ children, onClick }) => {
6
+ const IconButton = ({ children, disabled, onClick }) => {
7
7
  const { themeMode } = useContext(UiContext);
8
- return (_jsx("div", { className: css('iconButton', styles, themeMode), onClick: onClick, children: children }));
8
+ return (_jsx("div", { className: `${css('icon-button', styles, themeMode)} ${disabled ? css('icon-button-disabled', styles, themeMode) : ''}`, onClick: disabled ? undefined : onClick, children: children }));
9
9
  };
10
10
  export default IconButton;
@@ -0,0 +1,92 @@
1
+ .modal-overlay {
2
+ position: fixed;
3
+ top: 0;
4
+ left: 0;
5
+ width: 100%;
6
+ height: 100%;
7
+ display: flex;
8
+ justify-content: center;
9
+ align-items: center;
10
+ z-index: 9000;
11
+ }
12
+
13
+ .modal-overlay-light {
14
+ background-color: rgba(255, 255, 255, 0.7);
15
+ }
16
+
17
+ .modal-overlay-dark {
18
+ background-color: rgba(0, 0, 0, 0.7);
19
+ }
20
+
21
+ .modal {
22
+ max-width: 80%;
23
+ max-height: 80%;
24
+ overflow: auto;
25
+ padding: 20px;
26
+ border-radius: 5px;
27
+ }
28
+
29
+ .modal:focus-visible {
30
+ outline: none;
31
+ }
32
+
33
+ .modal-light {
34
+ background-color: #fff;
35
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
36
+ color: #000;
37
+ }
38
+
39
+ .modal-dark {
40
+ background-color: #333;
41
+ box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
42
+ color: #fff;
43
+ }
44
+
45
+ .modal-xs {
46
+ width: 400px;
47
+ }
48
+
49
+ .modal-sm {
50
+ width: 600px;
51
+ }
52
+
53
+ .modal-md {
54
+ width: 800px;
55
+ }
56
+
57
+ .modal-lg {
58
+ width: 1000px;
59
+ }
60
+
61
+ .modal-xl {
62
+ width: 1200px;
63
+ }
64
+
65
+ .modal-header {
66
+ display: flex;
67
+ justify-content: space-between;
68
+ align-items: center;
69
+ margin-bottom: 1rem;
70
+ }
71
+
72
+ .modal-title {
73
+ font-size: 1.5rem;
74
+ font-weight: bold;
75
+ margin: 0;
76
+ }
77
+
78
+ .modal-title-light {
79
+ color: #000;
80
+ }
81
+
82
+ .modal-title-dark {
83
+ color: #fff;
84
+ }
85
+
86
+ .modal-footer {
87
+ display: flex;
88
+ justify-content: flex-end;
89
+ margin-top: 1rem;
90
+ gap: .5rem;
91
+ }
92
+
@@ -0,0 +1,10 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export type ModalProps = {
3
+ isOpen: boolean;
4
+ onClose: () => void;
5
+ title: string;
6
+ maxWidth: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
7
+ onSubmit?: () => void;
8
+ };
9
+ declare const Modal: React.FC<PropsWithChildren<ModalProps>>;
10
+ export default Modal;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createPortal } from 'react-dom';
3
+ import { useContext } from 'react';
4
+ import CloseIcon from '../../Icons/CloseIcon';
5
+ import { UiContext } from '../../Providers/UiProvider';
6
+ import { css } from '../../Utils';
7
+ import styles from './Modal.module.css';
8
+ const Modal = ({ isOpen, onClose, children, title, maxWidth, onSubmit }) => {
9
+ const { themeMode, IconButton, Typography, Button, strings } = useContext(UiContext);
10
+ const iconColor = themeMode === 'light' ? 'black' : 'white';
11
+ if (!isOpen) {
12
+ return null;
13
+ }
14
+ return createPortal(_jsx("div", { className: css('modal-overlay', styles, themeMode), children: _jsxs("div", { className: `${css('modal', styles, themeMode)} ${css(`modal-${maxWidth}`, styles, themeMode)}`, children: [_jsxs("div", { className: css('modal-header', styles, themeMode), children: [_jsx(Typography, { component: 'h6', className: css('modal-title', styles, themeMode), children: title }), _jsx(IconButton, { onClick: onClose, children: _jsx(CloseIcon, { color: iconColor }) })] }), children, _jsxs("div", { className: css('modal-footer', styles, themeMode), children: [_jsx(Button, { onClick: onClose, children: strings.cancel }), onSubmit && _jsx(Button, { primary: true, onClick: onSubmit, children: strings.save })] })] }) }), document.body);
15
+ };
16
+ export default Modal;
@@ -0,0 +1,60 @@
1
+ /*
2
+ .number-field-wrapper {
3
+ }
4
+ .number-field-wrapper-light {
5
+ }
6
+ .number-field-wrapper-dark {
7
+ }
8
+ */
9
+
10
+ .number-field {
11
+ border-radius: 0.25rem;
12
+ box-sizing: border-box;
13
+ padding: 0.5rem;
14
+ width: 100%;
15
+ }
16
+ .number-field:focus-visible {
17
+ outline: none;
18
+ border: 1px solid #1976d2;
19
+ }
20
+ .number-field-light {
21
+ background-color: #fff;
22
+ color: #333;
23
+ border: 1px solid #ccc;
24
+ }
25
+ .number-field-dark {
26
+ background-color: #333;
27
+ border: 1px solid #666;
28
+ color: #fff;
29
+ }
30
+ .number-field-error {
31
+ border: 1px solid #d32f2f;
32
+ }
33
+ .number-field-label {
34
+ font-weight: bold;
35
+ display: block;
36
+ margin: 0 0 1rem 0;
37
+ }
38
+ /*
39
+ .text-fiel-label-light {
40
+ }
41
+ .number-field-label-dark {
42
+ }
43
+ */
44
+ .number-field-label-error {
45
+ color: #d32f2f;
46
+ }
47
+ .number-field-helper-text {
48
+ font-style: italic;
49
+ font-size: 0.9rem;
50
+ padding-top: 0.5rem;
51
+ }
52
+ /*
53
+ .number-field-helper-text-light {
54
+ }
55
+ .number-field-helper-text-dark {
56
+ }
57
+ */
58
+ .number-field-helper-text-error {
59
+ color: #d32f2f;
60
+ }
@@ -0,0 +1,3 @@
1
+ import { FieldProps } from '../../Types';
2
+ declare const NumberField: React.FC<FieldProps<number | null>>;
3
+ export default NumberField;
@@ -0,0 +1,13 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext } from 'react';
3
+ import { UiContext } from '../../Providers/UiProvider';
4
+ import { css } from '../../Utils';
5
+ import styles from './NumberField.module.css';
6
+ const NumberField = ({ onChange, value, label, required, helperText, error }) => {
7
+ const { themeMode, Typography } = useContext(UiContext);
8
+ const handleChange = (e) => {
9
+ onChange(parseFloat(e.target.value));
10
+ };
11
+ return (_jsxs("div", { className: css('number-field-wrapper', styles, themeMode), children: [_jsx("label", { className: `${css('number-field-label', styles, themeMode)} ${error ? css('number-field-label-error', styles, null) : ''}`, children: _jsxs(Typography, { children: [label, required && ' *'] }) }), _jsx("input", { type: 'number', className: `${css('number-field', styles, themeMode)} ${error ? css('number-field-error', styles, null) : ''}`, onChange: handleChange, value: value !== null && value !== void 0 ? value : '' }), helperText && (_jsx(Typography, { component: 'div', className: `${css('number-field-helper-text', styles, themeMode)} ${error ? css('number-field-helper-text-error', styles, null) : ''}`, children: helperText }))] }));
12
+ };
13
+ export default NumberField;
@@ -1,8 +1,10 @@
1
+ import { Output } from './Types';
1
2
  type CanvasProps = {
2
3
  canvasSize: {
3
4
  width: number;
4
5
  height: number;
5
6
  };
7
+ initialData?: Output;
6
8
  };
7
9
  declare const Canvas: React.FC<CanvasProps>;
8
10
  export default Canvas;
@@ -1,18 +1,28 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useRef, useEffect } from 'react';
3
2
  import * as fabric from 'fabric';
3
+ import { useRef, useEffect, useState, useContext } from 'react';
4
4
  import { useEditorContext } from '../../Providers/EditorProvider';
5
- import { useDispatcherEvents, useTool } from './Hooks';
6
- const Canvas = ({ canvasSize }) => {
7
- const { activeTool, setActiveTool, activeColor, addShape } = useEditorContext();
5
+ import { initCanvasData, useDispatcherEvents, useTool } from './Hooks';
6
+ import { UiContext } from '../../Providers/UiProvider';
7
+ const Canvas = ({ canvasSize, initialData }) => {
8
+ const { metadata, setMetadata, addShapes } = useEditorContext();
9
+ const { enableLogs } = useContext(UiContext);
10
+ const [initialized, setInitialized] = useState(false);
8
11
  const canvasRef = useRef(null);
9
- useTool(activeTool, activeColor, addShape, canvasRef.current);
10
- useDispatcherEvents(canvasRef.current, setActiveTool);
12
+ useTool(canvasRef.current);
13
+ useDispatcherEvents(canvasRef.current);
11
14
  useEffect(() => {
12
- canvasRef.current = new fabric.Canvas('react-cam-roi-canvas');
13
- canvasRef.current.setDimensions({ width: canvasSize.width, height: canvasSize.height });
14
- return () => { var _a; (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.dispose(); };
15
- }, [canvasSize.width, canvasSize.height]);
16
- return _jsx("canvas", { id: "react-cam-roi-canvas", style: { width: `${canvasSize.width}px`, height: `${canvasSize.height}px` } });
15
+ if (canvasSize.width !== 0 && canvasSize.height !== 0 && !initialized) {
16
+ canvasRef.current = new fabric.Canvas('react-cam-roi-canvas');
17
+ canvasRef.current.setDimensions({ width: canvasSize.width, height: canvasSize.height });
18
+ initCanvasData(canvasRef, addShapes, metadata, setMetadata, initialData, enableLogs);
19
+ setInitialized(true);
20
+ return () => {
21
+ var _a;
22
+ (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.dispose();
23
+ };
24
+ }
25
+ }, [canvasSize.width, canvasSize.height]); // eslint-disable-line
26
+ return (_jsx("canvas", { id: "react-cam-roi-canvas", style: { width: `${canvasSize.width}px`, height: `${canvasSize.height}px` } }));
17
27
  };
18
28
  export default Canvas;
@@ -1,5 +1,5 @@
1
1
  import * as fabric from 'fabric';
2
- import { Shape, ShapeType, ToolEnum } from './Types';
2
+ import { Metadata, Output, OutputParameter, Shape, ShapeType } from './Types';
3
3
  export declare const useImageSize: (imageUrl: string) => {
4
4
  imageSize: {
5
5
  width: number;
@@ -16,8 +16,20 @@ export declare const useCanvasSize: (imageUrl: string) => {
16
16
  width: number;
17
17
  height: number;
18
18
  };
19
- wrapperRef: import("react").RefObject<HTMLDivElement | null>;
19
+ wrapperRef: import("react").RefObject<HTMLDivElement>;
20
20
  isReady: boolean;
21
21
  };
22
- export declare const useTool: (tool: ToolEnum, activeColor: string, addShape: (id: string, type: ShapeType, shape: Shape) => void, canvas: fabric.Canvas | null) => void;
23
- export declare const useDispatcherEvents: (canvas: fabric.Canvas | null, setActiveTool: (tool: ToolEnum) => void) => void;
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
+ };