@abidibo/react-cam-roi 0.10.0 → 0.12.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.
package/README.md CHANGED
@@ -332,6 +332,7 @@ type UiContextType = {
332
332
  primaryColor: string // primary color for internal components
333
333
  primaryFgColor: string // text color above primary bg for internal components
334
334
  Typography: React.FC<TypographyProps> // component used to surround text
335
+ Tooltip: React.FC<TooltipProps> // component used to show tooltips
335
336
  Modal: React.FC<ModalProps> // modal dialog component (it displays metadata forms)
336
337
  IconButton: React.FC<IconButtonProps> // wrapper for icon buttons
337
338
  DeleteIcon: React.FC<DeleteIconProps> // delete icon
@@ -352,6 +353,7 @@ type UiContextType = {
352
353
  cannotDrawMorePolygons: string
353
354
  cannotDrawMorePolylines: string
354
355
  cannotDrawMoreRectangles: string
356
+ fullImage: string
355
357
  id: string
356
358
  invalidSubmission: string
357
359
  mainParametersMetadata: string
@@ -382,6 +384,7 @@ type UiContextType = {
382
384
  roisToBeDrawn: string
383
385
  role: string
384
386
  save: string
387
+ selection: string
385
388
  shapeParametersMetadata: string
386
389
  shapesOfRoleShouldBeEqualToThreshold: string // with {role} and {threshold} placeholders
387
390
  shapesOfRoleShouldBeGreaterThanThreshold: string // with {role} and {threshold} placeholders
@@ -457,6 +460,17 @@ type TypographyProps = {
457
460
  }
458
461
  ```
459
462
 
463
+ #### Tooltip
464
+
465
+ ##### Interface
466
+
467
+ ```ts
468
+ type TooltipProps = {
469
+ children?: React.ReactNode
470
+ title: string
471
+ }
472
+ ```
473
+
460
474
  #### IconButton
461
475
 
462
476
  ##### Interface
@@ -801,7 +815,7 @@ After cloning the repository and install dependencies (`yarn install`), you can
801
815
 
802
816
  In order to start developing just run the storybook, then make changes to code and the storybook will be updated.
803
817
 
804
- In order to test the library in onother local react project you can:
818
+ In order to test the library in another local react project you can:
805
819
 
806
820
  ```bash
807
821
  cd react-cam-roi
package/dist/index.cjs.js CHANGED
@@ -487,6 +487,11 @@ var TextField = function (_a) {
487
487
  return (jsxRuntime.jsxs("div", { className: css('text-field-wrapper', styles$8, themeMode), style: { width: fullWidth ? '100%' : 'auto' }, children: [label && (jsxRuntime.jsx("label", { className: "".concat(css('text-field-label', styles$8, themeMode), " ").concat(error ? css('text-field-label-error', styles$8, null) : ''), children: jsxRuntime.jsxs(Typography, { children: [label, required && ' *'] }) })), jsxRuntime.jsx("input", { type: type, className: "".concat(css('text-field', styles$8, themeMode), " ").concat(error ? css('text-field-error', styles$8, null) : ''), onChange: handleChange, value: value, readOnly: readOnly, disabled: disabled }), helperText && (jsxRuntime.jsx(Typography, { component: 'div', className: "".concat(css('text-field-helper-text', styles$8, themeMode), " ").concat(error ? css('text-field-helper-text-error', styles$8, null) : ''), children: helperText }))] }));
488
488
  };
489
489
 
490
+ var Tooltip = function (_a) {
491
+ var title = _a.title, children = _a.children;
492
+ return jsxRuntime.jsx("div", { title: title, children: children });
493
+ };
494
+
490
495
  var Typography = function (_a) {
491
496
  var children = _a.children, _b = _a.style, style = _b === void 0 ? {} : _b, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.component, component = _d === void 0 ? 'span' : _d;
492
497
  var Tag = component;
@@ -525,6 +530,7 @@ var DefaultUiContext = {
525
530
  primaryColor: '#1976d2',
526
531
  primaryFgColor: '#fff',
527
532
  Typography: Typography,
533
+ Tooltip: Tooltip,
528
534
  IconButton: IconButton,
529
535
  Modal: Modal,
530
536
  DeleteIcon: DeleteIcon,
@@ -546,6 +552,7 @@ var DefaultUiContext = {
546
552
  cannotDrawMorePolygons: 'You cannot draw more polygons',
547
553
  cannotDrawMorePolylines: 'You cannot draw more polylines',
548
554
  cannotDrawMoreRectangles: 'You cannot draw more rectangles',
555
+ fullImage: 'Full image',
549
556
  id: 'ID',
550
557
  invalidSubmission: 'Invalid submission',
551
558
  mainParametersMetadata: 'Main parameters',
@@ -561,10 +568,10 @@ var DefaultUiContext = {
561
568
  polylineHelpText: 'click to draw all the polyline points, double click on the last point to stop drawing',
562
569
  presetDescription: 'Preset description',
563
570
  presetName: 'Image preset',
564
- rect: 'Rectangle',
565
- rectHelpText: 'click and drag to draw the rectangle',
566
571
  pointer: 'Selection',
567
572
  pointerHelpText: 'click a shape to select it',
573
+ rect: 'Rectangle',
574
+ rectHelpText: 'click and drag to draw the rectangle',
568
575
  requiredField: 'This field is required',
569
576
  roiMultiplicityEqRule: 'a number of "{role}" ({type}) equal to {threshold}',
570
577
  roiMultiplicityGtRule: 'a number of "{role}" ({type}) greater than {threshold}',
@@ -575,6 +582,7 @@ var DefaultUiContext = {
575
582
  roisToBeDrawn: 'ROIs to be drawn',
576
583
  role: 'Role',
577
584
  save: 'Save',
585
+ selection: 'Selection',
578
586
  shapeParametersMetadata: 'Shape parameters',
579
587
  shapesOfRoleShouldBeEqualToThreshold: 'Shapes of role {role} should be equal to {threshold}',
580
588
  shapesOfRoleShouldBeGreaterThanThreshold: 'Shapes of role {role} should be greater than {threshold}',
@@ -586,10 +594,11 @@ var DefaultUiContext = {
586
594
  };
587
595
  var UiContext = React.createContext(DefaultUiContext); // eslint-disable-line
588
596
  var UiProvider = function (_a) {
589
- var children = _a.children, enableLogs = _a.enableLogs, themeMode = _a.themeMode, primaryColor = _a.primaryColor, primaryFgColor = _a.primaryFgColor, Typography = _a.Typography, Modal = _a.Modal, IconButton = _a.IconButton, DeleteIcon = _a.DeleteIcon, EditIcon = _a.EditIcon, CopyIcon = _a.CopyIcon, AnnotateIcon = _a.AnnotateIcon, SaveIcon = _a.SaveIcon, CloseIcon = _a.CloseIcon, TextField = _a.TextField, NumberField = _a.NumberField, BoolField = _a.BoolField, EnumField = _a.EnumField, Button = _a.Button, pickerColors = _a.pickerColors, notify = _a.notify, strings = _a.strings;
597
+ var children = _a.children, enableLogs = _a.enableLogs, themeMode = _a.themeMode, primaryColor = _a.primaryColor, primaryFgColor = _a.primaryFgColor, Typography = _a.Typography, Tooltip = _a.Tooltip, Modal = _a.Modal, IconButton = _a.IconButton, DeleteIcon = _a.DeleteIcon, EditIcon = _a.EditIcon, CopyIcon = _a.CopyIcon, AnnotateIcon = _a.AnnotateIcon, SaveIcon = _a.SaveIcon, CloseIcon = _a.CloseIcon, TextField = _a.TextField, NumberField = _a.NumberField, BoolField = _a.BoolField, EnumField = _a.EnumField, Button = _a.Button, pickerColors = _a.pickerColors, notify = _a.notify, strings = _a.strings;
590
598
  var ctx = {
591
599
  enableLogs: enableLogs !== null && enableLogs !== void 0 ? enableLogs : DefaultUiContext.enableLogs,
592
600
  Typography: Typography !== null && Typography !== void 0 ? Typography : DefaultUiContext.Typography,
601
+ Tooltip: Tooltip !== null && Tooltip !== void 0 ? Tooltip : DefaultUiContext.Tooltip,
593
602
  Modal: Modal !== null && Modal !== void 0 ? Modal : DefaultUiContext.Modal,
594
603
  IconButton: IconButton !== null && IconButton !== void 0 ? IconButton : DefaultUiContext.IconButton,
595
604
  DeleteIcon: DeleteIcon !== null && DeleteIcon !== void 0 ? DeleteIcon : DefaultUiContext.DeleteIcon,
@@ -813,12 +822,13 @@ var handleDoubleClickPolygon = function (editorId, canvas, activeColor, setIsDra
813
822
  }
814
823
  };
815
824
  var renderFullImagePolygon = function (editorId, canvas, activeColor, imageSize) {
825
+ var OFFSET = 5;
816
826
  var id = v4();
817
827
  var points = [
818
- { x: 1, y: 1 },
819
- { x: imageSize.width - 1, y: 0 },
820
- { x: imageSize.width - 1, y: imageSize.height - 1 },
821
- { x: 0, y: imageSize.height - 1 },
828
+ { x: OFFSET, y: OFFSET },
829
+ { x: imageSize.width - OFFSET, y: OFFSET },
830
+ { x: imageSize.width - OFFSET, y: imageSize.height - OFFSET },
831
+ { x: OFFSET, y: imageSize.height - OFFSET },
822
832
  ];
823
833
  var polygon = new oo(points, {
824
834
  fill: 'transparent',
@@ -1549,11 +1559,17 @@ var ParametersModalForm = function (_a) {
1549
1559
  var _a;
1550
1560
  return (__assign(__assign({}, acc), (_a = {}, _a[p.codename] = p.value, _a)));
1551
1561
  }, {});
1562
+ // if not in modal we save at every field change
1563
+ React.useEffect(function () {
1564
+ if (noModal) {
1565
+ handleSubmit();
1566
+ }
1567
+ }, [fields]);
1552
1568
  var handleSubmit = function () {
1553
1569
  if (shapeType && name === '') {
1554
1570
  setErrors({ name: strings.requiredField });
1555
1571
  }
1556
- else if (validateParametersForm(parameters, fields, setErrors, strings)) {
1572
+ else if (!noModal || validateParametersForm(parameters, fields, setErrors, strings)) {
1557
1573
  var data_1 = __spreadArray([], parameters.map(function (p) { return ({ codename: p.codename, value: fields[p.codename] }); }), true);
1558
1574
  if (shapeType) {
1559
1575
  onSubmit(data_1, { name: name, role: role });
@@ -1695,7 +1711,7 @@ var styles$1 = {"toolbar":"Toolbar-module_toolbar__ywNcv","toolbar-light":"Toolb
1695
1711
  var Toolbar = function (_a) {
1696
1712
  var _b;
1697
1713
  var canvasRef = _a.canvasRef, imageSize = _a.imageSize;
1698
- var _c = React.useContext(UiContext), IconButton = _c.IconButton, themeMode = _c.themeMode, primaryColor = _c.primaryColor, Typography = _c.Typography, strings = _c.strings;
1714
+ var _c = React.useContext(UiContext), IconButton = _c.IconButton, themeMode = _c.themeMode, primaryColor = _c.primaryColor, Typography = _c.Typography, strings = _c.strings, Tooltip = _c.Tooltip;
1699
1715
  var _d = useEditorContext(), activeTool = _d.activeTool, setActiveTool = _d.setActiveTool, configuration = _d.configuration, shapes = _d.shapes, editorId = _d.editorId, activeColor = _d.activeColor;
1700
1716
  var iconColor = function (tool) { return (tool === activeTool ? primaryColor : themeMode === 'light' ? 'black' : 'white'); };
1701
1717
  var setTool = function (tool) { return function () { return setActiveTool(tool); }; };
@@ -1709,7 +1725,7 @@ var Toolbar = function (_a) {
1709
1725
  var handleRenderFullImagePolygon = function () {
1710
1726
  renderFullImagePolygon(editorId, canvasRef.current, activeColor, imageSize);
1711
1727
  };
1712
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: css('toolbar', styles$1, themeMode), children: enableRois(configuration) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(IconButton, { onClick: setTool("pointer" /* ToolEnum.Pointer */), children: jsxRuntime.jsx(PointerIcon, { color: iconColor("pointer" /* ToolEnum.Pointer */) }) }), (!hideForbiddenTools || pointEnabled) && (jsxRuntime.jsx(IconButton, { onClick: setTool("point" /* ToolEnum.Point */), disabled: !pointEnabled, children: jsxRuntime.jsx(PointIcon, { color: iconColor("point" /* ToolEnum.Point */) }) })), (!hideForbiddenTools || polylineEnabled) && (jsxRuntime.jsx(IconButton, { onClick: setTool("polyline" /* ToolEnum.Polyline */), disabled: !polylineEnabled, children: jsxRuntime.jsx(PolylineIcon, { color: iconColor("polyline" /* ToolEnum.Polyline */) }) })), (!hideForbiddenTools || polygonEnabled) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(IconButton, { onClick: setTool("polygon" /* ToolEnum.Polygon */), disabled: !polygonEnabled, children: jsxRuntime.jsx(PolygonIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) }), jsxRuntime.jsx(IconButton, { onClick: handleRenderFullImagePolygon, disabled: !polygonEnabled, children: jsxRuntime.jsx(FullRoiIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) })] })), (!hideForbiddenTools || rectangleEnabled) && (jsxRuntime.jsx(IconButton, { onClick: setTool("rect" /* ToolEnum.Rectangle */), disabled: !rectangleEnabled, children: jsxRuntime.jsx(RectangleIcon, { color: iconColor("rect" /* ToolEnum.Rectangle */) }) })), jsxRuntime.jsx(ColorPicker, { style: { marginLeft: 'auto', marginRight: '.5rem' } })] })) }), enableRois(configuration) && (jsxRuntime.jsx("div", { className: css('toolbar-helper', styles$1, themeMode), children: jsxRuntime.jsxs(Typography, { children: [strings[activeTool], ": ", strings["".concat(activeTool, "HelpText")]] }) }))] }));
1728
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: css('toolbar', styles$1, themeMode), children: enableRois(configuration) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, { title: strings.selection, children: jsxRuntime.jsx(IconButton, { onClick: setTool("pointer" /* ToolEnum.Pointer */), children: jsxRuntime.jsx(PointerIcon, { color: iconColor("pointer" /* ToolEnum.Pointer */) }) }) }), (!hideForbiddenTools || pointEnabled) && (jsxRuntime.jsx(Tooltip, { title: strings.point, children: jsxRuntime.jsx(IconButton, { onClick: setTool("point" /* ToolEnum.Point */), disabled: !pointEnabled, children: jsxRuntime.jsx(PointIcon, { color: iconColor("point" /* ToolEnum.Point */) }) }) })), (!hideForbiddenTools || polylineEnabled) && (jsxRuntime.jsx(Tooltip, { title: strings.polyline, children: jsxRuntime.jsx(IconButton, { onClick: setTool("polyline" /* ToolEnum.Polyline */), disabled: !polylineEnabled, children: jsxRuntime.jsx(PolylineIcon, { color: iconColor("polyline" /* ToolEnum.Polyline */) }) }) })), (!hideForbiddenTools || polygonEnabled) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, { title: strings.polygon, children: jsxRuntime.jsx(IconButton, { onClick: setTool("polygon" /* ToolEnum.Polygon */), disabled: !polygonEnabled, children: jsxRuntime.jsx(PolygonIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) }) }), jsxRuntime.jsx(Tooltip, { title: strings.fullImage, children: jsxRuntime.jsx(IconButton, { onClick: handleRenderFullImagePolygon, disabled: !polygonEnabled, children: jsxRuntime.jsx(FullRoiIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) }) })] })), (!hideForbiddenTools || rectangleEnabled) && (jsxRuntime.jsx(Tooltip, { title: strings.rect, children: jsxRuntime.jsx(IconButton, { onClick: setTool("rect" /* ToolEnum.Rectangle */), disabled: !rectangleEnabled, children: jsxRuntime.jsx(RectangleIcon, { color: iconColor("rect" /* ToolEnum.Rectangle */) }) }) })), jsxRuntime.jsx(ColorPicker, { style: { marginLeft: 'auto', marginRight: '.5rem' } })] })) }), enableRois(configuration) && (jsxRuntime.jsx("div", { className: css('toolbar-helper', styles$1, themeMode), children: jsxRuntime.jsxs(Typography, { children: [strings[activeTool], ": ", strings["".concat(activeTool, "HelpText")]] }) }))] }));
1713
1729
  };
1714
1730
 
1715
1731
  var styles = {"top-bar":"TopBar-module_top-bar__9oCUR","main-parameters-view":"TopBar-module_main-parameters-view__f-0SX","main-parameters-view-light":"TopBar-module_main-parameters-view-light__o-dbi","main-parameters-view-dark":"TopBar-module_main-parameters-view-dark__FnEnj","main-parameters-button":"TopBar-module_main-parameters-button__9JX--"};
@@ -1724,7 +1740,7 @@ var TopBar = function () {
1724
1740
  setMetadata(__assign(__assign({}, metadata), { parameters: data }));
1725
1741
  setForm({ isOpen: false });
1726
1742
  };
1727
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: css('top-bar', styles, themeMode), children: [enableMainMetadata(configuration) && !((_a = configuration.options) === null || _a === void 0 ? void 0 : _a.viewMainParameters) && (jsxRuntime.jsxs(Button, { onClick: function () { return setForm({ isOpen: true }); }, children: [jsxRuntime.jsx(AnnotateIcon, { color: iconColor }), " ", strings.mainParametersMetadata] })), jsxRuntime.jsxs(Button, { primary: true, onClick: onSubmit, children: [jsxRuntime.jsx(SaveIcon, { color: primaryFgColor }), " ", strings.save] }), form.isOpen && (jsxRuntime.jsx(ParametersModalForm, { parameters: configuration.parameters, data: metadata.parameters, title: strings.mainParametersMetadata, onClose: function () { return setForm({ isOpen: false }); }, onSubmit: handleSubmitMetadata }))] }), enableMainMetadata(configuration) && ((_b = configuration.options) === null || _b === void 0 ? void 0 : _b.viewMainParameters) && (jsxRuntime.jsxs("div", { className: css('main-parameters-view', styles, themeMode), children: [jsxRuntime.jsx("div", { className: css('main-parameters-button', styles, themeMode), children: jsxRuntime.jsxs(Button, { onClick: function () { return setForm({ isOpen: true }); }, children: [jsxRuntime.jsx(AnnotateIcon, { color: iconColor }), " ", strings.mainParametersMetadata] }) }), jsxRuntime.jsx(ParametersModalForm, { parameters: configuration.parameters, data: metadata.parameters, title: strings.mainParametersMetadata, onClose: function () { return setForm({ isOpen: false }); }, onSubmit: handleSubmitMetadata, readOnly: true, noModal: true })] }))] }));
1743
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: css('top-bar', styles, themeMode), children: [enableMainMetadata(configuration) && !((_a = configuration.options) === null || _a === void 0 ? void 0 : _a.viewMainParameters) && (jsxRuntime.jsxs(Button, { onClick: function () { return setForm({ isOpen: true }); }, children: [jsxRuntime.jsx(AnnotateIcon, { color: iconColor }), " ", strings.mainParametersMetadata] })), jsxRuntime.jsxs(Button, { primary: true, onClick: onSubmit, children: [jsxRuntime.jsx(SaveIcon, { color: primaryFgColor }), " ", strings.save] }), form.isOpen && (jsxRuntime.jsx(ParametersModalForm, { parameters: configuration.parameters, data: metadata.parameters, title: strings.mainParametersMetadata, onClose: function () { return setForm({ isOpen: false }); }, onSubmit: handleSubmitMetadata }))] }), enableMainMetadata(configuration) && ((_b = configuration.options) === null || _b === void 0 ? void 0 : _b.viewMainParameters) && (jsxRuntime.jsx("div", { className: css('main-parameters-view', styles, themeMode), children: jsxRuntime.jsx(ParametersModalForm, { parameters: configuration.parameters, data: metadata.parameters, title: strings.mainParametersMetadata, onClose: function () { return setForm({ isOpen: false }); }, onSubmit: handleSubmitMetadata, noModal: true }) }))] }));
1728
1744
  };
1729
1745
 
1730
1746
  // https://github.com/n-mazaheri/image-editor