@abidibo/react-cam-roi 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -51,10 +51,15 @@ The `RoiEditor` props and the `Output` interface used both in import and export:
51
51
 
52
52
  ``` ts
53
53
  export type RoiEditorProps = {
54
+ // id of this editor instance, should be unique
55
+ id: string
54
56
  // the url of the image we want to annotate
55
57
  imageUrl: string
58
+ // configuration object
56
59
  configuration: Configuration
60
+ // callback called when exporting data
57
61
  onSubmit: (data: Output) => void
62
+ // initial imported data
58
63
  initialData?: Output
59
64
  }
60
65
 
@@ -2,10 +2,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as fabric from 'fabric';
3
3
  import { useRef, useEffect, useState, useContext } from 'react';
4
4
  import { useEditorContext } from '../../Providers/EditorProvider';
5
- import { initCanvasData, useDispatcherEvents, useTool } from './Hooks';
6
5
  import { UiContext } from '../../Providers/UiProvider';
6
+ import { initCanvasData, useDispatcherEvents, useTool } from './Hooks';
7
7
  const Canvas = ({ canvasSize, initialData }) => {
8
- const { metadata, setMetadata, addShapes } = useEditorContext();
8
+ const { metadata, setMetadata, addShapes, id } = useEditorContext();
9
9
  const { enableLogs } = useContext(UiContext);
10
10
  const [initialized, setInitialized] = useState(false);
11
11
  const canvasRef = useRef(null);
@@ -17,12 +17,12 @@ const Canvas = ({ canvasSize, initialData }) => {
17
17
  canvasRef.current.setDimensions({ width: canvasSize.width, height: canvasSize.height });
18
18
  initCanvasData(canvasRef, addShapes, metadata, setMetadata, initialData, enableLogs);
19
19
  setInitialized(true);
20
- return () => {
21
- var _a;
22
- (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.dispose();
23
- };
24
20
  }
21
+ return () => {
22
+ var _a;
23
+ (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.dispose();
24
+ };
25
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` } }));
26
+ return (_jsx("canvas", { id: `react-cam-roi-canvas-${id}`, style: { width: `${canvasSize.width}px`, height: `${canvasSize.height}px` } }));
27
27
  };
28
28
  export default Canvas;
@@ -4,6 +4,7 @@ export type RoiEditorProps = {
4
4
  configuration: Configuration;
5
5
  onSubmit: (data: Output) => void;
6
6
  initialData?: Output;
7
+ id: string;
7
8
  };
8
9
  declare const RoiEditor: React.FC<RoiEditorProps>;
9
10
  export default RoiEditor;
@@ -11,7 +11,7 @@ import ShapesList from './ShapesList';
11
11
  import Toolbar from './Toolbar';
12
12
  import { fabricShapeToOutputShape, validate } from './Utils';
13
13
  // https://github.com/n-mazaheri/image-editor
14
- const RoiEditor = ({ imageUrl, configuration, onSubmit, initialData }) => {
14
+ const RoiEditor = ({ imageUrl, configuration, onSubmit, initialData, id }) => {
15
15
  var _a, _b, _c;
16
16
  const { themeMode, enableLogs, pickerColors, strings, notify } = useContext(UiContext);
17
17
  const { imageSize, canvasSize, wrapperRef, isReady } = useCanvasSize(imageUrl);
@@ -65,7 +65,7 @@ const RoiEditor = ({ imageUrl, configuration, onSubmit, initialData }) => {
65
65
  if (!isReady) {
66
66
  return _jsx(Loader, {});
67
67
  }
68
- return (_jsx(EditorProvider, { hideForbiddenTools: (_c = (_b = configuration.options) === null || _b === void 0 ? void 0 : _b.hideForbiddenTools) !== null && _c !== void 0 ? _c : false, activeTool: activeTool, setActiveTool: setActiveTool, activeColor: activeColor, setActiveColor: setActiveColor, shapes: shapes, addShape: addShape, addShapes: addShapes, removeShape: removeShape, configuration: configuration, metadata: metadata, setMetadata: setMetadata, onSubmit: handleSubmit, children: _jsxs("div", { style: { maxWidth: '100%', width: `${imageSize.width}px` }, ref: wrapperRef, children: [_jsx(Toolbar, {}), _jsx("div", { className: css('canvasWrapper', styles, themeMode), style: {
68
+ return (_jsx(EditorProvider, { id: id, hideForbiddenTools: (_c = (_b = configuration.options) === null || _b === void 0 ? void 0 : _b.hideForbiddenTools) !== null && _c !== void 0 ? _c : false, activeTool: activeTool, setActiveTool: setActiveTool, activeColor: activeColor, setActiveColor: setActiveColor, shapes: shapes, addShape: addShape, addShapes: addShapes, removeShape: removeShape, configuration: configuration, metadata: metadata, setMetadata: setMetadata, onSubmit: handleSubmit, children: _jsxs("div", { style: { maxWidth: '100%', width: `${imageSize.width}px` }, ref: wrapperRef, children: [_jsx(Toolbar, {}), _jsx("div", { className: css('canvasWrapper', styles, themeMode), style: {
69
69
  width: `${canvasSize.width}px`,
70
70
  height: `${canvasSize.height}px`,
71
71
  backgroundImage: `url(${imageUrl})`,
@@ -18,8 +18,9 @@ type EditorContextType = {
18
18
  metadata: Metadata;
19
19
  setMetadata: (data: Metadata) => void;
20
20
  onSubmit: () => void;
21
+ id: string;
21
22
  };
22
23
  export declare const EditorContext: import("react").Context<EditorContextType | undefined>;
23
24
  export declare function useEditorContext(): EditorContextType;
24
- declare const EditorProvider: ({ children, hideForbiddenTools, activeTool, setActiveTool, activeColor, setActiveColor, shapes, addShape, addShapes, removeShape, configuration, metadata, setMetadata, onSubmit, }: PropsWithChildren<EditorContextType>) => import("react/jsx-runtime").JSX.Element;
25
+ declare const EditorProvider: ({ children, id, hideForbiddenTools, activeTool, setActiveTool, activeColor, setActiveColor, shapes, addShape, addShapes, removeShape, configuration, metadata, setMetadata, onSubmit, }: PropsWithChildren<EditorContextType>) => import("react/jsx-runtime").JSX.Element;
25
26
  export default EditorProvider;
@@ -8,8 +8,9 @@ export function useEditorContext() {
8
8
  }
9
9
  return context;
10
10
  }
11
- const EditorProvider = ({ children, hideForbiddenTools, activeTool, setActiveTool, activeColor, setActiveColor, shapes, addShape, addShapes, removeShape, configuration, metadata, setMetadata, onSubmit, }) => {
11
+ const EditorProvider = ({ children, id, hideForbiddenTools, activeTool, setActiveTool, activeColor, setActiveColor, shapes, addShape, addShapes, removeShape, configuration, metadata, setMetadata, onSubmit, }) => {
12
12
  return (_jsx(EditorContext.Provider, { value: {
13
+ id,
13
14
  hideForbiddenTools,
14
15
  activeTool,
15
16
  setActiveTool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abidibo/react-cam-roi",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "A react component for drawing ROI over images and managing metadata",
5
5
  "repository": {
6
6
  "type": "git",