@oneblink/apps-react 8.9.2-beta.4 → 8.10.0-alpha.1

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 (39) hide show
  1. package/dist/components/ImageCropper/CropModal.d.ts +9 -0
  2. package/dist/components/ImageCropper/CropModal.js +28 -0
  3. package/dist/components/ImageCropper/CropModal.js.map +1 -0
  4. package/dist/components/ImageCropper/index.d.ts +20 -0
  5. package/dist/components/ImageCropper/index.js +111 -0
  6. package/dist/components/ImageCropper/index.js.map +1 -0
  7. package/dist/components/ImageCropper/resource-components.d.ts +10 -0
  8. package/dist/components/ImageCropper/resource-components.js +30 -0
  9. package/dist/components/ImageCropper/resource-components.js.map +1 -0
  10. package/dist/components/downloadable-files/resource-components.js +2 -5
  11. package/dist/components/downloadable-files/resource-components.js.map +1 -1
  12. package/dist/components/renderer/AnnotationModal.d.ts +4 -0
  13. package/dist/components/renderer/AnnotationModal.js +26 -2
  14. package/dist/components/renderer/AnnotationModal.js.map +1 -1
  15. package/dist/components/renderer/LookupNotification.js +1 -1
  16. package/dist/components/renderer/LookupNotification.js.map +1 -1
  17. package/dist/components/renderer/attachments/DropdownMenu.d.ts +2 -0
  18. package/dist/components/renderer/attachments/DropdownMenu.js +14 -2
  19. package/dist/components/renderer/attachments/DropdownMenu.js.map +1 -1
  20. package/dist/components/renderer/attachments/FileCard.d.ts +3 -1
  21. package/dist/components/renderer/attachments/FileCard.js +2 -2
  22. package/dist/components/renderer/attachments/FileCard.js.map +1 -1
  23. package/dist/form-elements/FormElementCamera.js +66 -49
  24. package/dist/form-elements/FormElementCamera.js.map +1 -1
  25. package/dist/form-elements/FormElementFile.js +80 -2
  26. package/dist/form-elements/FormElementFile.js.map +1 -1
  27. package/dist/hooks/attachments/useAttachment.d.ts +1 -0
  28. package/dist/hooks/attachments/useAttachment.js +3 -0
  29. package/dist/hooks/attachments/useAttachment.js.map +1 -1
  30. package/dist/hooks/attachments/useAttachments.js +3 -3
  31. package/dist/hooks/attachments/useAttachments.js.map +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +1 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/styles/camera.scss +31 -1
  36. package/dist/styles/downloadable-files.scss +4 -4
  37. package/dist/styles/utils.scss +4 -0
  38. package/dist/styles.css +39 -5
  39. package/package.json +2 -1
@@ -7,6 +7,8 @@ interface Props {
7
7
  onDownload?: () => void;
8
8
  onRetry?: () => void;
9
9
  attachmentUrl: string | null | undefined;
10
+ onAnnotate?: () => void;
11
+ onCrop?: () => void;
10
12
  }
11
13
  declare const _default: React.NamedExoticComponent<Props>;
12
14
  export default _default;
@@ -3,7 +3,7 @@ import clsx from 'clsx';
3
3
  import useBooleanState from '../../../hooks/useBooleanState';
4
4
  import useClickOutsideElement from '../../../hooks/useClickOutsideElement';
5
5
  import MaterialIcon from '../../MaterialIcon';
6
- const DropdownMenu = ({ element, onRemove, onDownload, onRetry, attachmentUrl, }) => {
6
+ const DropdownMenu = ({ element, onRemove, onDownload, onRetry, attachmentUrl, onAnnotate, onCrop, }) => {
7
7
  const dropDownRef = React.useRef(null);
8
8
  const [isShowingMore, showMore, hideMore] = useBooleanState(false);
9
9
  useClickOutsideElement(dropDownRef, React.useCallback(() => {
@@ -41,7 +41,19 @@ const DropdownMenu = ({ element, onRemove, onDownload, onRetry, attachmentUrl, }
41
41
  }), onClick: () => {
42
42
  hideMore();
43
43
  onRemove();
44
- }, role: "menuitem" }, "Remove"))))));
44
+ }, role: "menuitem" }, "Remove")),
45
+ onAnnotate && (React.createElement("a", { className: clsx('dropdown-item cypress-file-annotate-button', {
46
+ 'ob-files__menu-annotate-hidden': element.readOnly,
47
+ }), onClick: () => {
48
+ hideMore();
49
+ onAnnotate();
50
+ }, role: "menuitem" }, "Annotate")),
51
+ onCrop && (React.createElement("a", { className: clsx('dropdown-item cypress-file-crop-button', {
52
+ 'ob-files__menu-crop-hidden': element.readOnly,
53
+ }), onClick: () => {
54
+ hideMore();
55
+ onCrop();
56
+ }, role: "menuitem" }, "Crop"))))));
45
57
  };
46
58
  export default React.memo(DropdownMenu);
47
59
  //# sourceMappingURL=DropdownMenu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownMenu.js","sourceRoot":"","sources":["../../../../src/components/renderer/attachments/DropdownMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,eAAe,MAAM,gCAAgC,CAAA;AAC5D,OAAO,sBAAsB,MAAM,uCAAuC,CAAA;AAC1E,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAW7C,MAAM,YAAY,GAAG,CAAC,EACpB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,OAAO,EACP,aAAa,GACP,EAAE,EAAE;IACV,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACtC,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IAElE,sBAAsB,CACpB,WAAW,EACX,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACrB,IAAI,aAAa,EAAE,CAAC;YAClB,QAAQ,EAAE,CAAA;QACZ,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAC9B,CAAA;IAED,OAAO,CACL,6BACE,SAAS,EAAE,IAAI,CAAC,kCAAkC,EAAE;YAClD,WAAW,EAAE,aAAa;SAC3B,CAAC,EACF,GAAG,EAAE,WAAW;QAEhB,6BAAK,SAAS,EAAC,kBAAkB;YAC/B,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,uDAAuD,mBACnD,MAAM,mBACN,eAAe,EAC7B,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;gBAE5C,oBAAC,YAAY,IAAC,SAA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'\nimport { FormTypes } from '@oneblink/types'\nimport useBooleanState from '../../../hooks/useBooleanState'\nimport useClickOutsideElement from '../../../hooks/useClickOutsideElement'\nimport MaterialIcon from '../../MaterialIcon'\n\ninterface Props {\n element: FormTypes.FilesElement\n /** If set to `undefined`, the remove button will be hidden */\n onRemove: (() => void) | undefined\n onDownload?: () => void\n onRetry?: () => void\n attachmentUrl: string | null | undefined\n}\n\nconst DropdownMenu = ({\n element,\n onRemove,\n onDownload,\n onRetry,\n attachmentUrl,\n}: Props) => {\n const dropDownRef = React.useRef(null)\n const [isShowingMore, showMore, hideMore] = useBooleanState(false)\n\n useClickOutsideElement(\n dropDownRef,\n React.useCallback(() => {\n if (isShowingMore) {\n hideMore()\n }\n }, [hideMore, isShowingMore]),\n )\n\n return (\n <div\n className={clsx('dropdown is-right ob-files__menu', {\n 'is-active': isShowingMore,\n })}\n ref={dropDownRef}\n >\n <div className=\"dropdown-trigger\">\n <button\n type=\"button\"\n className=\"button ob-files__menu-button cypress-file-menu-button\"\n aria-haspopup=\"true\"\n aria-controls=\"dropdown-menu\"\n onClick={isShowingMore ? hideMore : showMore}\n >\n <MaterialIcon className=\"ob-files__menu-icon\">more_vert</MaterialIcon>\n </button>\n </div>\n <div className=\"dropdown-menu\" role=\"menu\">\n <div className=\"dropdown-content\">\n {onRetry && (\n <a\n className=\"dropdown-item cypress-file-retry-button\"\n onClick={() => {\n hideMore()\n onRetry()\n }}\n role=\"menuitem\"\n >\n Retry\n </a>\n )}\n {onDownload && (\n <a\n className=\"dropdown-item cypress-file-download-button\"\n onClick={() => {\n hideMore()\n onDownload()\n }}\n role=\"menuitem\"\n >\n Download\n </a>\n )}\n {attachmentUrl && (\n <a\n href={attachmentUrl}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"dropdown-item cypress-file-open-button\"\n style={{\n display: 'flex',\n alignItems: 'center',\n gap: 2,\n }}\n onClick={() => {\n hideMore()\n }}\n >\n <span>Open</span>\n <MaterialIcon className=\"icon-small\">open_in_new</MaterialIcon>\n </a>\n )}\n {onRemove && (\n <a\n className={clsx('dropdown-item cypress-file-remove-button', {\n 'ob-files__menu-remove-hidden': element.readOnly,\n })}\n onClick={() => {\n hideMore()\n onRemove()\n }}\n role=\"menuitem\"\n >\n Remove\n </a>\n )}\n </div>\n </div>\n </div>\n )\n}\n\nexport default React.memo<Props>(DropdownMenu)\n"]}
1
+ {"version":3,"file":"DropdownMenu.js","sourceRoot":"","sources":["../../../../src/components/renderer/attachments/DropdownMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,eAAe,MAAM,gCAAgC,CAAA;AAC5D,OAAO,sBAAsB,MAAM,uCAAuC,CAAA;AAC1E,OAAO,YAAY,MAAM,oBAAoB,CAAA;AAa7C,MAAM,YAAY,GAAG,CAAC,EACpB,OAAO,EACP,QAAQ,EACR,UAAU,EACV,OAAO,EACP,aAAa,EACb,UAAU,EACV,MAAM,GACA,EAAE,EAAE;IACV,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACtC,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IAElE,sBAAsB,CACpB,WAAW,EACX,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACrB,IAAI,aAAa,EAAE,CAAC;YAClB,QAAQ,EAAE,CAAA;QACZ,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAC9B,CAAA;IAED,OAAO,CACL,6BACE,SAAS,EAAE,IAAI,CAAC,kCAAkC,EAAE;YAClD,WAAW,EAAE,aAAa;SAC3B,CAAC,EACF,GAAG,EAAE,WAAW;QAEhB,6BAAK,SAAS,EAAC,kBAAkB;YAC/B,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,uDAAuD,mB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ACA,UAAU,IAAI,CACb,2BACE,SAAS,EAAE,IAAI,CAAC,4CAA4C,EAAE;wBAC5D,gCAAgC,EAAE,OAAO,CAAC,QAAQ;qBACnD,CAAC,EACF,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAA;wBACV,UAAU,EAAE,CAAA;oBACd,CAAC,EACD,IAAI,EAAC,UAAU,eAGb,CACL;gBACA,MAAM,IAAI,CACT,2BACE,SAAS,EAAE,IAAI,CAAC,wCAAwC,EAAE;wBACxD,4BAA4B,EAAE,OAAO,CAAC,QAAQ;qBAC/C,CAAC,EACF,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAA;wBACV,MAAM,EAAE,CAAA;oBACV,CAAC,EACD,IAAI,EAAC,UAAU,WAGb,CACL,CACG,CACF,CACF,CACP,CAAA;AACH,CAAC,CAAA;AAED,eAAe,KAAK,CAAC,IAAI,CAAQ,YAAY,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport clsx from 'clsx'\nimport { FormTypes } from '@oneblink/types'\nimport useBooleanState from '../../../hooks/useBooleanState'\nimport useClickOutsideElement from '../../../hooks/useClickOutsideElement'\nimport MaterialIcon from '../../MaterialIcon'\n\ninterface Props {\n element: FormTypes.FilesElement\n /** If set to `undefined`, the remove button will be hidden */\n onRemove: (() => void) | undefined\n onDownload?: () => void\n onRetry?: () => void\n attachmentUrl: string | null | undefined\n onAnnotate?: () => void\n onCrop?: () => void\n}\n\nconst DropdownMenu = ({\n element,\n onRemove,\n onDownload,\n onRetry,\n attachmentUrl,\n onAnnotate,\n onCrop,\n}: Props) => {\n const dropDownRef = React.useRef(null)\n const [isShowingMore, showMore, hideMore] = useBooleanState(false)\n\n useClickOutsideElement(\n dropDownRef,\n React.useCallback(() => {\n if (isShowingMore) {\n hideMore()\n }\n }, [hideMore, isShowingMore]),\n )\n\n return (\n <div\n className={clsx('dropdown is-right ob-files__menu', {\n 'is-active': isShowingMore,\n })}\n ref={dropDownRef}\n >\n <div className=\"dropdown-trigger\">\n <button\n type=\"button\"\n className=\"button ob-files__menu-button cypress-file-menu-button\"\n aria-haspopup=\"true\"\n aria-controls=\"dropdown-menu\"\n onClick={isShowingMore ? hideMore : showMore}\n >\n <MaterialIcon className=\"ob-files__menu-icon\">more_vert</MaterialIcon>\n </button>\n </div>\n <div className=\"dropdown-menu\" role=\"menu\">\n <div className=\"dropdown-content\">\n {onRetry && (\n <a\n className=\"dropdown-item cypress-file-retry-button\"\n onClick={() => {\n hideMore()\n onRetry()\n }}\n role=\"menuitem\"\n >\n Retry\n </a>\n )}\n {onDownload && (\n <a\n className=\"dropdown-item cypress-file-download-button\"\n onClick={() => {\n hideMore()\n onDownload()\n }}\n role=\"menuitem\"\n >\n Download\n </a>\n )}\n {attachmentUrl && (\n <a\n href={attachmentUrl}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"dropdown-item cypress-file-open-button\"\n style={{\n display: 'flex',\n alignItems: 'center',\n gap: 2,\n }}\n onClick={() => {\n hideMore()\n }}\n >\n <span>Open</span>\n <MaterialIcon className=\"icon-small\">open_in_new</MaterialIcon>\n </a>\n )}\n {onRemove && (\n <a\n className={clsx('dropdown-item cypress-file-remove-button', {\n 'ob-files__menu-remove-hidden': element.readOnly,\n })}\n onClick={() => {\n hideMore()\n onRemove()\n }}\n role=\"menuitem\"\n >\n Remove\n </a>\n )}\n {onAnnotate && (\n <a\n className={clsx('dropdown-item cypress-file-annotate-button', {\n 'ob-files__menu-annotate-hidden': element.readOnly,\n })}\n onClick={() => {\n hideMore()\n onAnnotate()\n }}\n role=\"menuitem\"\n >\n Annotate\n </a>\n )}\n {onCrop && (\n <a\n className={clsx('dropdown-item cypress-file-crop-button', {\n 'ob-files__menu-crop-hidden': element.readOnly,\n })}\n onClick={() => {\n hideMore()\n onCrop()\n }}\n role=\"menuitem\"\n >\n Crop\n </a>\n )}\n </div>\n </div>\n </div>\n )\n}\n\nexport default React.memo<Props>(DropdownMenu)\n"]}
@@ -14,9 +14,11 @@ type Props = {
14
14
  onRemove: (() => void) | undefined;
15
15
  onDownload?: () => void;
16
16
  onRetry?: () => void;
17
+ onAnnotate?: () => void;
18
+ onCrop?: () => void;
17
19
  progress: undefined | number;
18
20
  index: number;
19
21
  };
20
- declare function FileCard({ element, isUploading, isUploadPaused, uploadErrorMessage, loadAttachmentUrlError, isLoadingAttachmentUrl, isContentTypeImage, attachmentUrl, fileName, onDownload, onRemove, onRetry, progress, index, }: Props): React.JSX.Element;
22
+ declare function FileCard({ element, isUploading, isUploadPaused, uploadErrorMessage, loadAttachmentUrlError, isLoadingAttachmentUrl, isContentTypeImage, attachmentUrl, fileName, onDownload, onRemove, onRetry, onAnnotate, onCrop, progress, index, }: Props): React.JSX.Element;
21
23
  declare const _default: React.MemoExoticComponent<typeof FileCard>;
22
24
  export default _default;
@@ -4,7 +4,7 @@ import AttachmentStatus from './AttachmentStatus';
4
4
  import { checkFileNameIsValid, checkFileNameExtensionIsValid, } from '../../../services/form-validation/validators';
5
5
  import ProgressBar from './ProgressBar';
6
6
  import DropdownMenu from './DropdownMenu';
7
- function FileCard({ element, isUploading, isUploadPaused, uploadErrorMessage, loadAttachmentUrlError, isLoadingAttachmentUrl, isContentTypeImage, attachmentUrl, fileName, onDownload, onRemove, onRetry, progress, index, }) {
7
+ function FileCard({ element, isUploading, isUploadPaused, uploadErrorMessage, loadAttachmentUrlError, isLoadingAttachmentUrl, isContentTypeImage, attachmentUrl, fileName, onDownload, onRemove, onRetry, onAnnotate, onCrop, progress, index, }) {
8
8
  const uploadError = React.useMemo(() => {
9
9
  if (!checkFileNameIsValid(element, fileName)) {
10
10
  return new Error(`${fileName.split('.').pop()} files are not allowed`);
@@ -21,7 +21,7 @@ function FileCard({ element, isUploading, isUploadPaused, uploadErrorMessage, lo
21
21
  React.createElement("div", { className: "ob-files__content" },
22
22
  React.createElement("a", { href: attachmentUrl || '', target: "_blank", rel: "noreferrer", className: "cypress-file-download-button", style: { pointerEvents: attachmentUrl ? 'auto' : 'none' } },
23
23
  React.createElement(FileCardContent, { attachmentUrl: attachmentUrl, alt: `${element.label}: Attachment ${index + 1}`, isContentTypeImage: isContentTypeImage }))),
24
- React.createElement(DropdownMenu, { element: element, onDownload: onDownload, onRetry: onRetry, onRemove: onRemove, attachmentUrl: attachmentUrl || '' }),
24
+ React.createElement(DropdownMenu, { element: element, onDownload: onDownload, onRetry: onRetry, onRemove: onRemove, attachmentUrl: attachmentUrl || '', onAnnotate: onAnnotate, onCrop: onCrop }),
25
25
  React.createElement("div", { className: "ob-files__file-name is-size-6" },
26
26
  React.createElement("span", { className: "ob-files__file-name-inner" }, fileName),
27
27
  React.createElement(AttachmentStatus, { isUploading: isUploading, isUploadPaused: isUploadPaused, uploadError: uploadError, loadAttachmentUrlError: loadAttachmentUrlError, isLoadingAttachmentUrl: isLoadingAttachmentUrl, attachmentUrl: attachmentUrl, progress: progress }),
@@ -1 +1 @@
1
- {"version":3,"file":"FileCard.js","sourceRoot":"","sources":["../../../../src/components/renderer/attachments/FileCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EACL,oBAAoB,EACpB,6BAA6B,GAC9B,MAAM,8CAA8C,CAAA;AACrD,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAoBzC,SAAS,QAAQ,CAAC,EAChB,OAAO,EACP,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,KAAK,GACC;IACN,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACrC,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAA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WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,EACxB,sBAAsB,EAAE,sBAAsB,EAC9C,sBAAsB,EAAE,sBAAsB,EAC9C,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,QAAQ,GAClB;gBACF,oBAAC,WAAW,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,WAAW,GAAI,CACzD,CACF,CACF,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes } from '@oneblink/types'\nimport FileCardContent from './FileCardContent'\nimport AttachmentStatus from './AttachmentStatus'\nimport {\n checkFileNameIsValid,\n checkFileNameExtensionIsValid,\n} from '../../../services/form-validation/validators'\nimport ProgressBar from './ProgressBar'\nimport DropdownMenu from './DropdownMenu'\n\ntype Props = {\n element: FormTypes.FilesElement\n isUploading?: boolean\n isUploadPaused?: boolean\n uploadErrorMessage?: string\n loadAttachmentUrlError?: Error\n isLoadingAttachmentUrl?: boolean\n isContentTypeImage?: boolean\n fileName: string\n attachmentUrl: string | undefined | null\n /** If set to `undefined`, the remove button will be hidden */\n onRemove: (() => void) | undefined\n onDownload?: () => void\n onRetry?: () => void\n progress: undefined | number\n index: number\n}\n\nfunction FileCard({\n element,\n isUploading,\n isUploadPaused,\n uploadErrorMessage,\n loadAttachmentUrlError,\n isLoadingAttachmentUrl,\n isContentTypeImage,\n attachmentUrl,\n fileName,\n onDownload,\n onRemove,\n onRetry,\n progress,\n index,\n}: Props) {\n const uploadError = React.useMemo(() => {\n if (!checkFileNameIsValid(element, fileName)) {\n return new Error(`${fileName.split('.').pop()} files are not allowed`)\n }\n if (!checkFileNameExtensionIsValid(element, fileName)) {\n return new Error(`${fileName} must have an extension`)\n }\n if (uploadErrorMessage) {\n return new Error(uploadErrorMessage)\n }\n }, [element, fileName, uploadErrorMessage])\n\n return (\n <div className=\"column is-one-quarter-ob\">\n <div className=\"ob-files__box\">\n <div className=\"ob-files__content\">\n <a\n href={attachmentUrl || ''}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"cypress-file-download-button\"\n style={{ pointerEvents: attachmentUrl ? 'auto' : 'none' }}\n >\n <FileCardContent\n attachmentUrl={attachmentUrl}\n alt={`${element.label}: Attachment ${index + 1}`}\n isContentTypeImage={isContentTypeImage}\n />\n </a>\n </div>\n <DropdownMenu\n element={element}\n onDownload={onDownload}\n onRetry={onRetry}\n onRemove={onRemove}\n attachmentUrl={attachmentUrl || ''}\n />\n\n <div className=\"ob-files__file-name is-size-6\">\n <span className=\"ob-files__file-name-inner\">{fileName}</span>\n <AttachmentStatus\n isUploading={isUploading}\n isUploadPaused={isUploadPaused}\n uploadError={uploadError}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isLoadingAttachmentUrl={isLoadingAttachmentUrl}\n attachmentUrl={attachmentUrl}\n progress={progress}\n />\n <ProgressBar progress={progress} isShowing={!!isUploading} />\n </div>\n </div>\n </div>\n )\n}\n\nexport default React.memo(FileCard)\n"]}
1
+ {"version":3,"file":"FileCard.js","sourceRoot":"","sources":["../../../../src/components/renderer/attachments/FileCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EACL,oBAAoB,EACpB,6BAA6B,GAC9B,MAAM,8CAA8C,CAAA;AACrD,OAAO,WAAW,MAAM,eAAe,CAAA;AACvC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAsBzC,SAAS,QAAQ,CAAC,EAChB,OAAO,EACP,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,UAAU,EACV,MAAM,EACN,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EAClC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACd;YAEF,6BAAK,SAAS,EAAC,+BAA+B;gBAC5C,8BAAM,SAAS,EAAC,2BAA2B,IAAE,QAAQ,CAAQ;gBAC7D,oBAAC,gBAAgB,IACf,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,EACxB,sBAAsB,EAAE,sBAAsB,EAC9C,sBAAsB,EAAE,sBAAsB,EAC9C,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,QAAQ,GAClB;gBACF,oBAAC,WAAW,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,WAAW,GAAI,CACzD,CACF,CACF,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes } from '@oneblink/types'\nimport FileCardContent from './FileCardContent'\nimport AttachmentStatus from './AttachmentStatus'\nimport {\n checkFileNameIsValid,\n checkFileNameExtensionIsValid,\n} from '../../../services/form-validation/validators'\nimport ProgressBar from './ProgressBar'\nimport DropdownMenu from './DropdownMenu'\n\ntype Props = {\n element: FormTypes.FilesElement\n isUploading?: boolean\n isUploadPaused?: boolean\n uploadErrorMessage?: string\n loadAttachmentUrlError?: Error\n isLoadingAttachmentUrl?: boolean\n isContentTypeImage?: boolean\n fileName: string\n attachmentUrl: string | undefined | null\n /** If set to `undefined`, the remove button will be hidden */\n onRemove: (() => void) | undefined\n onDownload?: () => void\n onRetry?: () => void\n onAnnotate?: () => void\n onCrop?: () => void\n progress: undefined | number\n index: number\n}\n\nfunction FileCard({\n element,\n isUploading,\n isUploadPaused,\n uploadErrorMessage,\n loadAttachmentUrlError,\n isLoadingAttachmentUrl,\n isContentTypeImage,\n attachmentUrl,\n fileName,\n onDownload,\n onRemove,\n onRetry,\n onAnnotate,\n onCrop,\n progress,\n index,\n}: Props) {\n const uploadError = React.useMemo(() => {\n if (!checkFileNameIsValid(element, fileName)) {\n return new Error(`${fileName.split('.').pop()} files are not allowed`)\n }\n if (!checkFileNameExtensionIsValid(element, fileName)) {\n return new Error(`${fileName} must have an extension`)\n }\n if (uploadErrorMessage) {\n return new Error(uploadErrorMessage)\n }\n }, [element, fileName, uploadErrorMessage])\n\n return (\n <div className=\"column is-one-quarter-ob\">\n <div className=\"ob-files__box\">\n <div className=\"ob-files__content\">\n <a\n href={attachmentUrl || ''}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"cypress-file-download-button\"\n style={{ pointerEvents: attachmentUrl ? 'auto' : 'none' }}\n >\n <FileCardContent\n attachmentUrl={attachmentUrl}\n alt={`${element.label}: Attachment ${index + 1}`}\n isContentTypeImage={isContentTypeImage}\n />\n </a>\n </div>\n <DropdownMenu\n element={element}\n onDownload={onDownload}\n onRetry={onRetry}\n onRemove={onRemove}\n attachmentUrl={attachmentUrl || ''}\n onAnnotate={onAnnotate}\n onCrop={onCrop}\n />\n\n <div className=\"ob-files__file-name is-size-6\">\n <span className=\"ob-files__file-name-inner\">{fileName}</span>\n <AttachmentStatus\n isUploading={isUploading}\n isUploadPaused={isUploadPaused}\n uploadError={uploadError}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isLoadingAttachmentUrl={isLoadingAttachmentUrl}\n attachmentUrl={attachmentUrl}\n progress={progress}\n />\n <ProgressBar progress={progress} isShowing={!!isUploading} />\n </div>\n </div>\n </div>\n )\n}\n\nexport default React.memo(FileCard)\n"]}
@@ -5,7 +5,7 @@ import OnLoading from '../components/renderer/OnLoading';
5
5
  import FormElementLabelContainer from '../components/renderer/FormElementLabelContainer';
6
6
  import drawTimestampOnCanvas from '../services/drawTimestampOnCanvas';
7
7
  import useAttachment from '../hooks/attachments/useAttachment';
8
- import AnnotationModal from '../components/renderer/AnnotationModal';
8
+ import AnnotationModal, { superimposeAnnotationOnImage, } from '../components/renderer/AnnotationModal';
9
9
  import Modal from '../components/renderer/Modal';
10
10
  import { checkIfContentTypeIsImage, prepareNewAttachment, correctFileOrientation, } from '../services/attachments';
11
11
  import AttachmentStatus from '../components/renderer/attachments/AttachmentStatus';
@@ -15,12 +15,15 @@ import ProgressBar from '../components/renderer/attachments/ProgressBar';
15
15
  import useElementAriaDescribedby from '../hooks/useElementAriaDescribedby';
16
16
  import MaterialIcon from '../components/MaterialIcon';
17
17
  import FormElementValidationMessage from '../components/renderer/FormElementValidationMessage';
18
+ import CropModal from '../components/ImageCropper/CropModal';
19
+ import { generateCroppedImageBlob } from '../components/ImageCropper';
18
20
  function FormElementCamera({ id, element, value, onChange, validationMessage, displayValidationMessage, isDirty, setIsDirty, }) {
19
21
  const ariaDescribedby = useElementAriaDescribedby(id, element);
20
22
  const [{ cameraError, isLoading }, setState] = React.useState({
21
23
  isLoading: false,
22
24
  });
23
25
  const [isAnnotating, setIsAnnotating, clearIsAnnotating] = useBooleanState(false);
26
+ const [isCropping, setIsCropping, clearIsCropping] = useBooleanState(false);
24
27
  const fileInputRef = React.useRef(null);
25
28
  const clearImage = React.useCallback(() => {
26
29
  onChange(element, {
@@ -118,7 +121,7 @@ function FormElementCamera({ id, element, value, onChange, validationMessage, di
118
121
  console.error('Could not find "input" element in Camera component template');
119
122
  }
120
123
  }, [element, onChange]);
121
- const { isUploading, uploadErrorMessage, isLoadingAttachmentUrl, attachmentUrl, loadAttachmentUrlError, canDownload, progress, } = useAttachment(value, element, React.useCallback((id, attachment) => {
124
+ const { isUploading, uploadErrorMessage, isLoadingAttachmentUrl, attachmentUrl, loadAttachmentUrlError, canDownload, progress, contentType, } = useAttachment(value, element, React.useCallback((id, attachment) => {
122
125
  onChange(element, {
123
126
  value: attachment,
124
127
  });
@@ -148,7 +151,7 @@ function FormElementCamera({ id, element, value, onChange, validationMessage, di
148
151
  await downloadAttachment(value);
149
152
  }
150
153
  }, [value, id]);
151
- const handleSaveAnnotation = React.useCallback((annotationDataUri) => {
154
+ const handleSaveAnnotation = React.useCallback(async (annotationDataUri) => {
152
155
  clearIsAnnotating();
153
156
  if (typeof attachmentUrl !== 'string') {
154
157
  return;
@@ -156,56 +159,65 @@ function FormElementCamera({ id, element, value, onChange, validationMessage, di
156
159
  setState({
157
160
  isLoading: true,
158
161
  });
159
- const canvas = document.createElement('canvas');
160
- const ctx = canvas.getContext('2d');
161
- if (!ctx) {
162
- return;
162
+ try {
163
+ const blob = await superimposeAnnotationOnImage({
164
+ annotationDataUri,
165
+ attachmentUrl,
166
+ });
167
+ setState({
168
+ isLoading: false,
169
+ });
170
+ if (blob) {
171
+ const attachment = prepareNewAttachment(blob, 'photo.png', element);
172
+ onChange(element, {
173
+ value: attachment,
174
+ });
175
+ }
176
+ }
177
+ catch (err) {
178
+ setState({
179
+ cameraError: err,
180
+ isLoading: false,
181
+ });
163
182
  }
164
- const image = new Image();
165
- image.onload = function () {
166
- canvas.width = image.width;
167
- canvas.height = image.height;
168
- ctx.drawImage(image, 0, 0);
169
- const annotationImage = new Image();
170
- annotationImage.onload = function () {
171
- ctx.drawImage(annotationImage, 0, 0, canvas.width, canvas.height);
172
- try {
173
- canvasToBlob(canvas)
174
- .then((blob) => {
175
- const attachment = prepareNewAttachment(blob, 'photo.png', element);
176
- onChange(element, {
177
- value: attachment,
178
- });
179
- setState({
180
- isLoading: false,
181
- });
182
- })
183
- .catch((error) => {
184
- setState({
185
- cameraError: error,
186
- isLoading: false,
187
- });
188
- });
189
- }
190
- catch (error) {
191
- setState({
192
- cameraError: error,
193
- isLoading: false,
194
- });
195
- }
196
- };
197
- annotationImage.src = annotationDataUri;
198
- };
199
- image.setAttribute('crossorigin', 'anonymous');
200
- image.src = attachmentUrl;
201
183
  }, [attachmentUrl, clearIsAnnotating, element, onChange]);
184
+ const handleSaveCrop = React.useCallback(async (croppedAreaPixels) => {
185
+ clearIsCropping();
186
+ if (!attachmentUrl)
187
+ return;
188
+ setState({
189
+ isLoading: true,
190
+ });
191
+ try {
192
+ const croppedImage = await generateCroppedImageBlob({
193
+ croppedAreaPixels,
194
+ imgSrc: attachmentUrl,
195
+ fileType: contentType,
196
+ });
197
+ if (!croppedImage)
198
+ throw new Error('Cropped image is null');
199
+ const attachment = prepareNewAttachment(croppedImage, 'photo.png', element);
200
+ onChange(element, {
201
+ value: attachment,
202
+ });
203
+ setState({
204
+ isLoading: false,
205
+ });
206
+ }
207
+ catch (error) {
208
+ setState({
209
+ cameraError: error,
210
+ isLoading: false,
211
+ });
212
+ }
213
+ }, [attachmentUrl, clearIsCropping, contentType, element, onChange]);
202
214
  const progressTooltipRef = React.useRef(null);
203
215
  return (React.createElement(React.Fragment, null,
204
216
  React.createElement(FormElementLabelContainer, { className: "ob-camera", element: element, id: id, required: element.required },
205
217
  React.createElement("div", { className: "control" },
206
218
  (value || isLoading) && (React.createElement(React.Fragment, null,
207
219
  React.createElement("figure", { className: "ob-figure", ref: progressTooltipRef },
208
- React.createElement(DisplayImage, { isUploading: isUploading, uploadErrorMessage: uploadErrorMessage, isLoadingAttachmentUrl: isLoadingAttachmentUrl, attachmentUrl: attachmentUrl, loadAttachmentUrlError: loadAttachmentUrlError, isLoading: isLoading, element: element, onAnnotate: setIsAnnotating, canDownload: canDownload, progress: progress }),
220
+ React.createElement(DisplayImage, { isUploading: isUploading, uploadErrorMessage: uploadErrorMessage, isLoadingAttachmentUrl: isLoadingAttachmentUrl, attachmentUrl: attachmentUrl, loadAttachmentUrlError: loadAttachmentUrlError, isLoading: isLoading, element: element, onAnnotate: setIsAnnotating, onCrop: setIsCropping, canDownload: canDownload, progress: progress }),
209
221
  React.createElement(ProgressBar, { isShowing: isUploading, progress: progress })))),
210
222
  React.createElement("input", { ref: fileInputRef, className: "ob-input ob-camera__input-hidden cypress-camera-control", type: "file", accept: "image/*", capture: "environment", id: id, name: element.name, required: element.required, disabled: element.readOnly, onChange: fileChange, "aria-required": element.required }),
211
223
  React.createElement("div", { className: "buttons ob-buttons" }, value ? (React.createElement(React.Fragment, null,
@@ -217,6 +229,7 @@ function FormElementCamera({ id, element, value, onChange, validationMessage, di
217
229
  React.createElement("span", null, "\u00A0Download"))))) : (React.createElement("button", { type: "button", className: "button ob-button ob-button__open is-primary cypress-open-camera", onClick: openCamera, disabled: element.readOnly || isLoading, "aria-describedby": ariaDescribedby, onBlur: setIsDirty }, "Open Camera")))),
218
230
  (isDirty || displayValidationMessage) && !!validationMessage && (React.createElement(FormElementValidationMessage, { message: validationMessage }))),
219
231
  isAnnotating && attachmentUrl && (React.createElement(AnnotationModal, { imageSrc: attachmentUrl, onClose: clearIsAnnotating, onSave: handleSaveAnnotation })),
232
+ isCropping && attachmentUrl && (React.createElement(CropModal, { imageSrc: attachmentUrl, onClose: clearIsCropping, onSave: handleSaveCrop })),
220
233
  cameraError && (React.createElement(Modal, { isOpen: true, title: "Whoops...", className: "cypress-error-modal", titleClassName: "cypress-error-title", actions: React.createElement("button", { type: "button", className: "button ob-button is-primary cypress-close-error-button", onClick: () => setState({ isLoading: false }), autoFocus: true }, "Okay") },
221
234
  React.createElement("p", null,
222
235
  "An error occurred while attempting to take a photo. Please click",
@@ -227,7 +240,7 @@ function FormElementCamera({ id, element, value, onChange, validationMessage, di
227
240
  React.createElement("blockquote", null, cameraError.toString()))))));
228
241
  }
229
242
  export default React.memo(FormElementCamera);
230
- const DisplayImage = React.memo(function DisplayImage({ uploadErrorMessage, isUploading, isLoadingAttachmentUrl, attachmentUrl, loadAttachmentUrlError, isLoading, element, onAnnotate, progress, }) {
243
+ const DisplayImage = React.memo(function DisplayImage({ uploadErrorMessage, isUploading, isLoadingAttachmentUrl, attachmentUrl, loadAttachmentUrlError, isLoading, element, onAnnotate, onCrop, progress, }) {
231
244
  if (uploadErrorMessage) {
232
245
  return (React.createElement("div", { className: "figure-content", role: "alert" },
233
246
  React.createElement("h3", { className: "title is-3" }, "Upload Failed"),
@@ -253,9 +266,13 @@ const DisplayImage = React.memo(function DisplayImage({ uploadErrorMessage, isUp
253
266
  React.createElement("span", { className: "ob-figure__status" },
254
267
  React.createElement(AttachmentStatus, { isLoadingAttachmentUrl: isLoadingAttachmentUrl, loadAttachmentUrlError: loadAttachmentUrlError, isUploading: isUploading, attachmentUrl: attachmentUrl, progress: progress })),
255
268
  React.createElement("img", { src: attachmentUrl, className: "cypress-camera-image ob-camera__img", crossOrigin: "anonymous", alt: `${element.label}: Attachment` }),
256
- React.createElement("button", { type: "button", className: "button is-primary ob-camera__annotate-button cypress-annotate-button", onClick: onAnnotate, disabled: element.readOnly },
257
- React.createElement("span", { className: "icon" },
258
- React.createElement(MaterialIcon, null, "brush")))));
269
+ React.createElement("div", { className: "ob-image-file__actions" },
270
+ React.createElement("button", { type: "button", className: "button is-primary ob-camera__crop-button cypress-crop-button", onClick: onCrop, disabled: element.readOnly },
271
+ React.createElement("span", { className: "icon" },
272
+ React.createElement(MaterialIcon, null, "crop"))),
273
+ React.createElement("button", { type: "button", className: "button is-primary ob-camera__annotate-button cypress-annotate-button", onClick: onAnnotate, disabled: element.readOnly },
274
+ React.createElement("span", { className: "icon" },
275
+ React.createElement(MaterialIcon, null, "brush"))))));
259
276
  }
260
277
  return (React.createElement("div", { className: "figure-content", role: "alert" },
261
278
  React.createElement(ImagePreviewUnavailable, null)));
@@ -1 +1 @@
1
- {"version":3,"file":"FormElementCamera.js","sourceRoot":"","sources":["../../src/form-elements/FormElementCamera.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,kBAAkB,EAAE,EACzB,kBAAkB,GACnB,MAAM,2BAA2B,CAAA;AAClC,OAAO,SAAS,MAAM,kCAAkC,CAAA;AAExD,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,qBAAqB,MAAM,mCAAmC,CAAA;AAErE,OAAO,aAAa,MAAM,oCAAoC,CAAA;AAC9D,OAAO,eAAe,MAAM,wCAAwC,CAAA;AACpE,OAAO,KAAK,MAAM,8BAA8B,CAAA;AAChD,OAAO,EACL,yBAAyB,EACzB,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AAW,EAAC,WAAW,EACvB,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,cAAc,GACnC;YACF,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,sEAAsE,EAChF,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAE1B,8BAAM,SAAS,EAAC,MAAM;oBACpB,oBAAC,YAAY,gBAAqB,CAC7B,CACA,CACR,CACJ,CAAA;IACH,CAAC;IAED,OAAO,CACL,6BAAK,SAAS,EAAC,gBAAgB,EAAC,IAAI,EAAC,OAAO;QAC1C,oBAAC,uBAAuB,OAAG,CACvB,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import * as React from 'react'\n\nimport useBooleanState from '../hooks/useBooleanState'\nimport downloadAttachment, {\n downloadFileLegacy,\n} from '../services/download-file'\nimport OnLoading from '../components/renderer/OnLoading'\nimport { FormTypes } from '@oneblink/types'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport drawTimestampOnCanvas from '../services/drawTimestampOnCanvas'\nimport { FormElementBinaryStorageValue } from '../types/attachments'\nimport useAttachment from '../hooks/attachments/useAttachment'\nimport AnnotationModal from '../components/renderer/AnnotationModal'\nimport Modal from '../components/renderer/Modal'\nimport {\n checkIfContentTypeIsImage,\n prepareNewAttachment,\n correctFileOrientation,\n} from '../services/attachments'\nimport AttachmentStatus from '../components/renderer/attachments/AttachmentStatus'\nimport { canvasToBlob, urlToBlobAsync } from '../services/blob-utils'\nimport ImagePreviewUnavailable from '../components/renderer/attachments/ImagePreviewUnavailable'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport ProgressBar from '../components/renderer/attachments/ProgressBar'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\n\ntype Props = {\n id: string\n element: FormTypes.CameraElement\n value: FormElementBinaryStorageValue\n onChange: FormElementValueChangeHandler<FormElementBinaryStorageValue>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n} & IsDirtyProps\n\nfunction FormElementCamera({\n id,\n element,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const [{ cameraError, isLoading }, setState] = React.useState<{\n isLoading: boolean\n cameraError?: Error\n }>({\n isLoading: false,\n })\n const [isAnnotating, setIsAnnotating, clearIsAnnotating] =\n useBooleanState(false)\n const fileInputRef = React.useRef<HTMLInputElement>(null)\n\n const clearImage = React.useCallback(() => {\n onChange(element, {\n value: undefined,\n })\n }, [element, onChange])\n\n const fileChange = React.useCallback(\n async (changeEvent: React.ChangeEvent<HTMLInputElement>) => {\n if (!changeEvent.target || !changeEvent.target.files) {\n return\n }\n\n const file = changeEvent.target.files[0]\n if (!file) {\n return\n }\n\n setState({\n isLoading: true,\n })\n\n console.log('File selected event', file)\n try {\n if (!file.size) {\n throw new Error('You cannot upload an empty file.')\n }\n\n if (!checkIfContentTypeIsImage(file.type)) {\n throw new Error(\n `Invalid file type \"${file.type}\". Please select an image.`,\n )\n }\n const result = await correctFileOrientation(\n file,\n element.includeTimestampWatermark ? drawTimestampOnCanvas : undefined,\n )\n\n if (result instanceof Blob) {\n onChange(element, {\n value: prepareNewAttachment(result, file.name, element),\n })\n } else {\n const blob = await canvasToBlob(result)\n onChange(element, {\n value: prepareNewAttachment(blob, file.name, element),\n })\n }\n\n setIsDirty()\n setState({\n isLoading: false,\n })\n } catch (error) {\n setState({\n isLoading: false,\n cameraError: error as Error,\n })\n }\n },\n [element, onChange, setIsDirty],\n )\n const openCamera = React.useCallback(() => {\n if (window.cordova && navigator.camera && navigator.camera.getPicture) {\n setState({\n isLoading: true,\n })\n navigator.camera.getPicture(\n (base64Data: string) => {\n urlToBlobAsync(`data:image/jpeg;base64,${base64Data}`)\n .then((blob) => {\n onChange(element, {\n value: prepareNewAttachment(blob, 'photo.jpeg', element),\n })\n setState({\n isLoading: false,\n })\n })\n .catch((error) => {\n setState({\n cameraError: error,\n isLoading: false,\n })\n })\n },\n (error: Error) => {\n console.warn(\n 'An error occurred while attempting to take a photo',\n error,\n )\n setState({\n isLoading: false,\n cameraError: error,\n })\n },\n {\n quality: 100,\n destinationType: window.Camera.DestinationType.DATA_URL,\n sourceType: window.Camera.PictureSourceType.CAMERA,\n allowEdit: false,\n encodingType: window.Camera.EncodingType.JPEG,\n mediaType: window.Camera.MediaType.PICTURE,\n correctOrientation: true,\n saveToPhotoAlbum: false,\n cameraDirection: window.Camera.Direction.BACK,\n },\n )\n } else if (fileInputRef.current) {\n // RESET HTML FILE INPUT VALUE SO FILES PREVIOUSLY ADDED AND REMOVED ARE RECOGNIZED\n fileInputRef.current.value = ''\n fileInputRef.current.click()\n } else {\n console.error(\n 'Could not find \"input\" element in Camera component template',\n )\n }\n }, [element, onChange])\n\n const {\n isUploading,\n uploadErrorMessage,\n isLoadingAttachmentUrl,\n attachmentUrl,\n loadAttachmentUrlError,\n canDownload,\n progress,\n } = useAttachment(\n value,\n element,\n React.useCallback(\n (id, attachment) => {\n onChange(element, {\n value: attachment,\n })\n },\n [element, onChange],\n ),\n )\n\n const handleRetry = React.useMemo(() => {\n if (!value || typeof value !== 'object') return\n\n if (value.type === 'ERROR' && value.data) {\n return () => {\n onChange(element, {\n value: {\n type: 'NEW',\n _id: value._id,\n data: value.data,\n fileName: value.fileName,\n isPrivate: value.isPrivate,\n },\n })\n }\n }\n }, [element, onChange, value])\n\n const handleDownload = React.useCallback(async () => {\n if (typeof value === 'string') {\n await downloadFileLegacy(value, id)\n } else if (value && value.type !== 'ERROR') {\n await downloadAttachment(value)\n }\n }, [value, id])\n\n const handleSaveAnnotation = React.useCallback(\n (annotationDataUri: string) => {\n clearIsAnnotating()\n\n if (typeof attachmentUrl !== 'string') {\n return\n }\n\n setState({\n isLoading: true,\n })\n\n const canvas = document.createElement('canvas')\n const ctx = canvas.getContext('2d')\n if (!ctx) {\n return\n }\n\n const image = new Image()\n image.onload = function () {\n canvas.width = image.width\n canvas.height = image.height\n\n ctx.drawImage(image, 0, 0)\n\n const annotationImage = new Image()\n annotationImage.onload = function () {\n ctx.drawImage(annotationImage, 0, 0, canvas.width, canvas.height)\n\n try {\n canvasToBlob(canvas)\n .then((blob) => {\n const attachment = prepareNewAttachment(\n blob,\n 'photo.png',\n element,\n )\n onChange(element, {\n value: attachment,\n })\n setState({\n isLoading: false,\n })\n })\n .catch((error) => {\n setState({\n cameraError: error,\n isLoading: false,\n })\n })\n } catch (error) {\n setState({\n cameraError: error as Error,\n isLoading: false,\n })\n }\n }\n annotationImage.src = annotationDataUri\n }\n image.setAttribute('crossorigin', 'anonymous')\n image.src = attachmentUrl\n },\n [attachmentUrl, clearIsAnnotating, element, onChange],\n )\n\n const progressTooltipRef = React.useRef<HTMLDivElement>(null)\n return (\n <>\n <FormElementLabelContainer\n className=\"ob-camera\"\n element={element}\n id={id}\n required={element.required}\n >\n <div className=\"control\">\n {(value || isLoading) && (\n <>\n <figure className=\"ob-figure\" ref={progressTooltipRef}>\n <DisplayImage\n isUploading={isUploading}\n uploadErrorMessage={uploadErrorMessage}\n isLoadingAttachmentUrl={isLoadingAttachmentUrl}\n attachmentUrl={attachmentUrl}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isLoading={isLoading}\n element={element}\n onAnnotate={setIsAnnotating}\n canDownload={canDownload}\n progress={progress}\n />\n <ProgressBar isShowing={isUploading} progress={progress} />\n </figure>\n </>\n )}\n\n <input\n ref={fileInputRef}\n className=\"ob-input ob-camera__input-hidden cypress-camera-control\"\n type=\"file\"\n accept=\"image/*\"\n capture=\"environment\"\n id={id}\n name={element.name}\n required={element.required}\n disabled={element.readOnly}\n onChange={fileChange}\n aria-required={element.required}\n />\n <div className=\"buttons ob-buttons\">\n {value ? (\n <>\n {uploadErrorMessage && handleRetry && (\n <button\n type=\"button\"\n className=\"button ob-button ob-button__retry is-light cypress-retry-file-button\"\n onClick={handleRetry}\n >\n Retry\n </button>\n )}\n <button\n type=\"button\"\n className=\"button ob-button ob-button__clear is-light cypress-clear-camera\"\n onClick={clearImage}\n disabled={element.readOnly || isLoading}\n >\n Clear\n </button>\n {canDownload && (\n <button\n type=\"button\"\n className=\"button ob-button ob-button__download is-primary cypress-download-file-button\"\n onClick={handleDownload}\n >\n <span className=\"icon\">\n <MaterialIcon>cloud_download</MaterialIcon>\n </span>\n <span>&nbsp;Download</span>\n </button>\n )}\n </>\n ) : (\n <button\n type=\"button\"\n className=\"button ob-button ob-button__open is-primary cypress-open-camera\"\n onClick={openCamera}\n disabled={element.readOnly || isLoading}\n aria-describedby={ariaDescribedby}\n onBlur={setIsDirty}\n >\n Open Camera\n </button>\n )}\n </div>\n </div>\n {(isDirty || displayValidationMessage) && !!validationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n\n {isAnnotating && attachmentUrl && (\n <AnnotationModal\n imageSrc={attachmentUrl}\n onClose={clearIsAnnotating}\n onSave={handleSaveAnnotation}\n />\n )}\n\n {cameraError && (\n <Modal\n isOpen\n title=\"Whoops...\"\n className=\"cypress-error-modal\"\n titleClassName=\"cypress-error-title\"\n actions={\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-close-error-button\"\n onClick={() => setState({ isLoading: false })}\n autoFocus\n >\n Okay\n </button>\n }\n >\n <p>\n An error occurred while attempting to take a photo. Please click{' '}\n <b>Okay</b> below to try again. If the problem persists, please\n contact support.\n </p>\n\n <div className=\"content has-margin-top-6\">\n <blockquote>{cameraError.toString()}</blockquote>\n </div>\n </Modal>\n )}\n </>\n )\n}\n\nexport default React.memo(FormElementCamera)\n\nconst DisplayImage = React.memo(function DisplayImage({\n uploadErrorMessage,\n isUploading,\n isLoadingAttachmentUrl,\n attachmentUrl,\n loadAttachmentUrlError,\n isLoading,\n element,\n onAnnotate,\n progress,\n}: ReturnType<typeof useAttachment> & {\n element: FormTypes.CameraElement\n isLoading: boolean\n onAnnotate: () => void\n progress: number | undefined\n}) {\n if (uploadErrorMessage) {\n return (\n <div className=\"figure-content\" role=\"alert\">\n <h3 className=\"title is-3\">Upload Failed</h3>\n <p>\n Your photo failed to upload, please use the <b>Retry</b> or{' '}\n <b>Clear</b> buttons below.\n </p>\n </div>\n )\n }\n\n if (loadAttachmentUrlError) {\n return (\n <div className=\"figure-content\" role=\"alert\">\n <h3 className=\"title is-3\">Preview Failed</h3>\n <p>{loadAttachmentUrlError.message}</p>\n </div>\n )\n }\n\n if (isLoadingAttachmentUrl || isLoading) {\n return (\n <div className=\"figure-content has-text-centered cypress-camera-loading-image\">\n <OnLoading small />\n </div>\n )\n }\n\n if (attachmentUrl) {\n return (\n <>\n <span className=\"ob-figure__status\">\n <AttachmentStatus\n isLoadingAttachmentUrl={isLoadingAttachmentUrl}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isUploading={isUploading}\n attachmentUrl={attachmentUrl}\n progress={progress}\n />\n </span>\n <img\n src={attachmentUrl}\n className=\"cypress-camera-image ob-camera__img\"\n crossOrigin=\"anonymous\"\n alt={`${element.label}: Attachment`}\n />\n <button\n type=\"button\"\n className=\"button is-primary ob-camera__annotate-button cypress-annotate-button\"\n onClick={onAnnotate}\n disabled={element.readOnly}\n >\n <span className=\"icon\">\n <MaterialIcon>brush</MaterialIcon>\n </span>\n </button>\n </>\n )\n }\n\n return (\n <div className=\"figure-content\" role=\"alert\">\n <ImagePreviewUnavailable />\n </div>\n )\n})\n"]}
1
+ {"version":3,"file":"FormElementCamera.js","sourceRoot":"","sources":["../../src/form-elements/FormElementCamera.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,kBAAkB,EAAE,EACzB,kBAAkB,GACnB,MAAM,2BAA2B,CAAA;AAClC,OAAO,SAAS,MAAM,kCAAkC,CAAA;AAExD,OAAO,yBAAyB,MAAM,kDAAkD,CAA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AO,CAAK,CACnC,CACP,CAAA;IACH,CAAC;IAED,IAAI,sBAAsB,IAAI,SAAS,EAAE,CAAC;QACxC,OAAO,CACL,6BAAK,SAAS,EAAC,+DAA+D;YAC5E,oBAAC,SAAS,IAAC,KAAK,SAAG,CACf,CACP,CAAA;IACH,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,CACL;YACE,8BAAM,SAAS,EAAC,mBAAmB;gBACjC,oBAAC,gBAAgB,IACf,sBAAsB,EAAE,sBAAsB,EAC9C,sBAAsB,EAAE,sBAAsB,EAC9C,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,QAAQ,GAClB,CACG;YACP,6BACE,GAAG,EAAE,aAAa,EAClB,SAAS,EAAC,qCAAqC,EAC/C,WAAW,EAAC,WAAW,EACvB,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,cAAc,GACnC;YACF,6BAAK,SAAS,EAAC,wBAAwB;gBACrC,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,8DAA8D,EACxE,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAE1B,8BAAM,SAAS,EAAC,MAAM;wBACpB,oBAAC,YAAY,eAAoB,CAC5B,CACA;gBACT,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,sEAAsE,EAChF,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAE1B,8BAAM,SAAS,EAAC,MAAM;wBACpB,oBAAC,YAAY,gBAAqB,CAC7B,CACA,CACL,CACL,CACJ,CAAA;IACH,CAAC;IAED,OAAO,CACL,6BAAK,SAAS,EAAC,gBAAgB,EAAC,IAAI,EAAC,OAAO;QAC1C,oBAAC,uBAAuB,OAAG,CACvB,CACP,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import * as React from 'react'\n\nimport useBooleanState from '../hooks/useBooleanState'\nimport downloadAttachment, {\n downloadFileLegacy,\n} from '../services/download-file'\nimport OnLoading from '../components/renderer/OnLoading'\nimport { FormTypes } from '@oneblink/types'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport drawTimestampOnCanvas from '../services/drawTimestampOnCanvas'\nimport { FormElementBinaryStorageValue } from '../types/attachments'\nimport useAttachment from '../hooks/attachments/useAttachment'\nimport AnnotationModal, {\n superimposeAnnotationOnImage,\n} from '../components/renderer/AnnotationModal'\nimport Modal from '../components/renderer/Modal'\nimport {\n checkIfContentTypeIsImage,\n prepareNewAttachment,\n correctFileOrientation,\n} from '../services/attachments'\nimport AttachmentStatus from '../components/renderer/attachments/AttachmentStatus'\nimport { canvasToBlob, urlToBlobAsync } from '../services/blob-utils'\nimport ImagePreviewUnavailable from '../components/renderer/attachments/ImagePreviewUnavailable'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\nimport ProgressBar from '../components/renderer/attachments/ProgressBar'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport MaterialIcon from '../components/MaterialIcon'\nimport FormElementValidationMessage from '../components/renderer/FormElementValidationMessage'\nimport CropModal from '../components/ImageCropper/CropModal'\nimport { Area } from 'react-easy-crop'\nimport { generateCroppedImageBlob } from '../components/ImageCropper'\n\ntype Props = {\n id: string\n element: FormTypes.CameraElement\n value: FormElementBinaryStorageValue\n onChange: FormElementValueChangeHandler<FormElementBinaryStorageValue>\n displayValidationMessage: boolean\n validationMessage: string | undefined\n} & IsDirtyProps\n\nfunction FormElementCamera({\n id,\n element,\n value,\n onChange,\n validationMessage,\n displayValidationMessage,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const [{ cameraError, isLoading }, setState] = React.useState<{\n isLoading: boolean\n cameraError?: Error\n }>({\n isLoading: false,\n })\n const [isAnnotating, setIsAnnotating, clearIsAnnotating] =\n useBooleanState(false)\n const [isCropping, setIsCropping, clearIsCropping] = useBooleanState(false)\n\n const fileInputRef = React.useRef<HTMLInputElement>(null)\n\n const clearImage = React.useCallback(() => {\n onChange(element, {\n value: undefined,\n })\n }, [element, onChange])\n\n const fileChange = React.useCallback(\n async (changeEvent: React.ChangeEvent<HTMLInputElement>) => {\n if (!changeEvent.target || !changeEvent.target.files) {\n return\n }\n\n const file = changeEvent.target.files[0]\n if (!file) {\n return\n }\n\n setState({\n isLoading: true,\n })\n\n console.log('File selected event', file)\n try {\n if (!file.size) {\n throw new Error('You cannot upload an empty file.')\n }\n\n if (!checkIfContentTypeIsImage(file.type)) {\n throw new Error(\n `Invalid file type \"${file.type}\". Please select an image.`,\n )\n }\n const result = await correctFileOrientation(\n file,\n element.includeTimestampWatermark ? drawTimestampOnCanvas : undefined,\n )\n\n if (result instanceof Blob) {\n onChange(element, {\n value: prepareNewAttachment(result, file.name, element),\n })\n } else {\n const blob = await canvasToBlob(result)\n onChange(element, {\n value: prepareNewAttachment(blob, file.name, element),\n })\n }\n\n setIsDirty()\n setState({\n isLoading: false,\n })\n } catch (error) {\n setState({\n isLoading: false,\n cameraError: error as Error,\n })\n }\n },\n [element, onChange, setIsDirty],\n )\n const openCamera = React.useCallback(() => {\n if (window.cordova && navigator.camera && navigator.camera.getPicture) {\n setState({\n isLoading: true,\n })\n navigator.camera.getPicture(\n (base64Data: string) => {\n urlToBlobAsync(`data:image/jpeg;base64,${base64Data}`)\n .then((blob) => {\n onChange(element, {\n value: prepareNewAttachment(blob, 'photo.jpeg', element),\n })\n setState({\n isLoading: false,\n })\n })\n .catch((error) => {\n setState({\n cameraError: error,\n isLoading: false,\n })\n })\n },\n (error: Error) => {\n console.warn(\n 'An error occurred while attempting to take a photo',\n error,\n )\n setState({\n isLoading: false,\n cameraError: error,\n })\n },\n {\n quality: 100,\n destinationType: window.Camera.DestinationType.DATA_URL,\n sourceType: window.Camera.PictureSourceType.CAMERA,\n allowEdit: false,\n encodingType: window.Camera.EncodingType.JPEG,\n mediaType: window.Camera.MediaType.PICTURE,\n correctOrientation: true,\n saveToPhotoAlbum: false,\n cameraDirection: window.Camera.Direction.BACK,\n },\n )\n } else if (fileInputRef.current) {\n // RESET HTML FILE INPUT VALUE SO FILES PREVIOUSLY ADDED AND REMOVED ARE RECOGNIZED\n fileInputRef.current.value = ''\n fileInputRef.current.click()\n } else {\n console.error(\n 'Could not find \"input\" element in Camera component template',\n )\n }\n }, [element, onChange])\n\n const {\n isUploading,\n uploadErrorMessage,\n isLoadingAttachmentUrl,\n attachmentUrl,\n loadAttachmentUrlError,\n canDownload,\n progress,\n contentType,\n } = useAttachment(\n value,\n element,\n React.useCallback(\n (id, attachment) => {\n onChange(element, {\n value: attachment,\n })\n },\n [element, onChange],\n ),\n )\n\n const handleRetry = React.useMemo(() => {\n if (!value || typeof value !== 'object') return\n\n if (value.type === 'ERROR' && value.data) {\n return () => {\n onChange(element, {\n value: {\n type: 'NEW',\n _id: value._id,\n data: value.data,\n fileName: value.fileName,\n isPrivate: value.isPrivate,\n },\n })\n }\n }\n }, [element, onChange, value])\n\n const handleDownload = React.useCallback(async () => {\n if (typeof value === 'string') {\n await downloadFileLegacy(value, id)\n } else if (value && value.type !== 'ERROR') {\n await downloadAttachment(value)\n }\n }, [value, id])\n\n const handleSaveAnnotation = React.useCallback(\n async (annotationDataUri: string) => {\n clearIsAnnotating()\n\n if (typeof attachmentUrl !== 'string') {\n return\n }\n\n setState({\n isLoading: true,\n })\n try {\n const blob = await superimposeAnnotationOnImage({\n annotationDataUri,\n attachmentUrl,\n })\n setState({\n isLoading: false,\n })\n if (blob) {\n const attachment = prepareNewAttachment(blob, 'photo.png', element)\n onChange(element, {\n value: attachment,\n })\n }\n } catch (err) {\n setState({\n cameraError: err as Error,\n isLoading: false,\n })\n }\n },\n [attachmentUrl, clearIsAnnotating, element, onChange],\n )\n\n const handleSaveCrop = React.useCallback(\n async (croppedAreaPixels: Area) => {\n clearIsCropping()\n if (!attachmentUrl) return\n\n setState({\n isLoading: true,\n })\n\n try {\n const croppedImage = await generateCroppedImageBlob({\n croppedAreaPixels,\n imgSrc: attachmentUrl,\n fileType: contentType,\n })\n\n if (!croppedImage) throw new Error('Cropped image is null')\n const attachment = prepareNewAttachment(\n croppedImage,\n 'photo.png',\n element,\n )\n onChange(element, {\n value: attachment,\n })\n setState({\n isLoading: false,\n })\n } catch (error) {\n setState({\n cameraError: error as Error,\n isLoading: false,\n })\n }\n },\n [attachmentUrl, clearIsCropping, contentType, element, onChange],\n )\n\n const progressTooltipRef = React.useRef<HTMLDivElement>(null)\n return (\n <>\n <FormElementLabelContainer\n className=\"ob-camera\"\n element={element}\n id={id}\n required={element.required}\n >\n <div className=\"control\">\n {(value || isLoading) && (\n <>\n <figure className=\"ob-figure\" ref={progressTooltipRef}>\n <DisplayImage\n isUploading={isUploading}\n uploadErrorMessage={uploadErrorMessage}\n isLoadingAttachmentUrl={isLoadingAttachmentUrl}\n attachmentUrl={attachmentUrl}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isLoading={isLoading}\n element={element}\n onAnnotate={setIsAnnotating}\n onCrop={setIsCropping}\n canDownload={canDownload}\n progress={progress}\n />\n <ProgressBar isShowing={isUploading} progress={progress} />\n </figure>\n </>\n )}\n\n <input\n ref={fileInputRef}\n className=\"ob-input ob-camera__input-hidden cypress-camera-control\"\n type=\"file\"\n accept=\"image/*\"\n capture=\"environment\"\n id={id}\n name={element.name}\n required={element.required}\n disabled={element.readOnly}\n onChange={fileChange}\n aria-required={element.required}\n />\n <div className=\"buttons ob-buttons\">\n {value ? (\n <>\n {uploadErrorMessage && handleRetry && (\n <button\n type=\"button\"\n className=\"button ob-button ob-button__retry is-light cypress-retry-file-button\"\n onClick={handleRetry}\n >\n Retry\n </button>\n )}\n <button\n type=\"button\"\n className=\"button ob-button ob-button__clear is-light cypress-clear-camera\"\n onClick={clearImage}\n disabled={element.readOnly || isLoading}\n >\n Clear\n </button>\n {canDownload && (\n <button\n type=\"button\"\n className=\"button ob-button ob-button__download is-primary cypress-download-file-button\"\n onClick={handleDownload}\n >\n <span className=\"icon\">\n <MaterialIcon>cloud_download</MaterialIcon>\n </span>\n <span>&nbsp;Download</span>\n </button>\n )}\n </>\n ) : (\n <button\n type=\"button\"\n className=\"button ob-button ob-button__open is-primary cypress-open-camera\"\n onClick={openCamera}\n disabled={element.readOnly || isLoading}\n aria-describedby={ariaDescribedby}\n onBlur={setIsDirty}\n >\n Open Camera\n </button>\n )}\n </div>\n </div>\n {(isDirty || displayValidationMessage) && !!validationMessage && (\n <FormElementValidationMessage message={validationMessage} />\n )}\n </FormElementLabelContainer>\n\n {isAnnotating && attachmentUrl && (\n <AnnotationModal\n imageSrc={attachmentUrl}\n onClose={clearIsAnnotating}\n onSave={handleSaveAnnotation}\n />\n )}\n\n {isCropping && attachmentUrl && (\n <CropModal\n imageSrc={attachmentUrl}\n onClose={clearIsCropping}\n onSave={handleSaveCrop}\n />\n )}\n\n {cameraError && (\n <Modal\n isOpen\n title=\"Whoops...\"\n className=\"cypress-error-modal\"\n titleClassName=\"cypress-error-title\"\n actions={\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-close-error-button\"\n onClick={() => setState({ isLoading: false })}\n autoFocus\n >\n Okay\n </button>\n }\n >\n <p>\n An error occurred while attempting to take a photo. Please click{' '}\n <b>Okay</b> below to try again. If the problem persists, please\n contact support.\n </p>\n\n <div className=\"content has-margin-top-6\">\n <blockquote>{cameraError.toString()}</blockquote>\n </div>\n </Modal>\n )}\n </>\n )\n}\n\nexport default React.memo(FormElementCamera)\n\nconst DisplayImage = React.memo(function DisplayImage({\n uploadErrorMessage,\n isUploading,\n isLoadingAttachmentUrl,\n attachmentUrl,\n loadAttachmentUrlError,\n isLoading,\n element,\n onAnnotate,\n onCrop,\n progress,\n}: Omit<ReturnType<typeof useAttachment>, 'contentType'> & {\n element: FormTypes.CameraElement\n isLoading: boolean\n onAnnotate: () => void\n onCrop: () => void\n progress: number | undefined\n}) {\n if (uploadErrorMessage) {\n return (\n <div className=\"figure-content\" role=\"alert\">\n <h3 className=\"title is-3\">Upload Failed</h3>\n <p>\n Your photo failed to upload, please use the <b>Retry</b> or{' '}\n <b>Clear</b> buttons below.\n </p>\n </div>\n )\n }\n\n if (loadAttachmentUrlError) {\n return (\n <div className=\"figure-content\" role=\"alert\">\n <h3 className=\"title is-3\">Preview Failed</h3>\n <p>{loadAttachmentUrlError.message}</p>\n </div>\n )\n }\n\n if (isLoadingAttachmentUrl || isLoading) {\n return (\n <div className=\"figure-content has-text-centered cypress-camera-loading-image\">\n <OnLoading small />\n </div>\n )\n }\n\n if (attachmentUrl) {\n return (\n <>\n <span className=\"ob-figure__status\">\n <AttachmentStatus\n isLoadingAttachmentUrl={isLoadingAttachmentUrl}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isUploading={isUploading}\n attachmentUrl={attachmentUrl}\n progress={progress}\n />\n </span>\n <img\n src={attachmentUrl}\n className=\"cypress-camera-image ob-camera__img\"\n crossOrigin=\"anonymous\"\n alt={`${element.label}: Attachment`}\n />\n <div className=\"ob-image-file__actions\">\n <button\n type=\"button\"\n className=\"button is-primary ob-camera__crop-button cypress-crop-button\"\n onClick={onCrop}\n disabled={element.readOnly}\n >\n <span className=\"icon\">\n <MaterialIcon>crop</MaterialIcon>\n </span>\n </button>\n <button\n type=\"button\"\n className=\"button is-primary ob-camera__annotate-button cypress-annotate-button\"\n onClick={onAnnotate}\n disabled={element.readOnly}\n >\n <span className=\"icon\">\n <MaterialIcon>brush</MaterialIcon>\n </span>\n </button>\n </div>\n </>\n )\n }\n\n return (\n <div className=\"figure-content\" role=\"alert\">\n <ImagePreviewUnavailable />\n </div>\n )\n})\n"]}
@@ -2,8 +2,20 @@ import * as React from 'react';
2
2
  import downloadAttachment from '../services/download-file';
3
3
  import useAttachment from '../hooks/attachments/useAttachment';
4
4
  import FileCard from '../components/renderer/attachments/FileCard';
5
+ import useBooleanState from '../hooks/useBooleanState';
6
+ import CropModal from '../components/ImageCropper/CropModal';
7
+ import AnnotationModal, { superimposeAnnotationOnImage, } from '../components/renderer/AnnotationModal';
8
+ import { generateCroppedImageBlob } from '../components/ImageCropper';
9
+ import { prepareNewAttachment } from '../services/attachments';
10
+ import Modal from '../components/renderer/Modal';
5
11
  const FormElementFile = ({ element, onRemove, file, onChange, disableUpload, index, }) => {
6
- const attachmentResult = useAttachment(file, element, onChange, disableUpload);
12
+ const [isAnnotating, setIsAnnotating, clearIsAnnotating] = useBooleanState(false);
13
+ const [isCropping, setIsCropping, clearIsCropping] = useBooleanState(false);
14
+ const [state, setState] = React.useState({
15
+ isLoading: false,
16
+ error: undefined,
17
+ });
18
+ const { attachmentUrl, contentType, isUploading, uploadErrorMessage, isLoadingAttachmentUrl, loadAttachmentUrlError, isContentTypeImage, canDownload, progress, } = useAttachment(file, element, onChange, disableUpload);
7
19
  const handleRemove = React.useMemo(() => {
8
20
  if (!onRemove) {
9
21
  return;
@@ -18,6 +30,61 @@ const FormElementFile = ({ element, onRemove, file, onChange, disableUpload, ind
18
30
  const handleDownload = React.useCallback(async () => {
19
31
  await downloadAttachment(file);
20
32
  }, [file]);
33
+ const handleAnnotate = React.useCallback(async (annotationDataUri) => {
34
+ if (!attachmentUrl || file.type)
35
+ return;
36
+ clearIsAnnotating();
37
+ setState({
38
+ isLoading: true,
39
+ });
40
+ try {
41
+ const blob = await superimposeAnnotationOnImage({
42
+ annotationDataUri,
43
+ attachmentUrl,
44
+ });
45
+ setState({
46
+ isLoading: false,
47
+ });
48
+ if (!blob)
49
+ return;
50
+ const attachment = prepareNewAttachment(blob, file.fileName, element);
51
+ onChange(file.id, attachment);
52
+ }
53
+ catch (error) {
54
+ setState({
55
+ error: error,
56
+ isLoading: false,
57
+ });
58
+ }
59
+ }, [attachmentUrl, clearIsAnnotating, element, file, onChange]);
60
+ const handleSaveCrop = React.useCallback(async (croppedAreaPixels) => {
61
+ if (!attachmentUrl || file.type)
62
+ return;
63
+ clearIsCropping();
64
+ setState({
65
+ isLoading: true,
66
+ });
67
+ try {
68
+ const croppedImage = await generateCroppedImageBlob({
69
+ croppedAreaPixels,
70
+ imgSrc: attachmentUrl,
71
+ fileType: contentType,
72
+ });
73
+ setState({
74
+ isLoading: false,
75
+ });
76
+ if (!croppedImage)
77
+ return;
78
+ const attachment = prepareNewAttachment(croppedImage, file.fileName, element);
79
+ onChange(file.id, attachment);
80
+ }
81
+ catch (error) {
82
+ setState({
83
+ error: error,
84
+ isLoading: false,
85
+ });
86
+ }
87
+ }, [attachmentUrl, clearIsCropping, contentType, element, file, onChange]);
21
88
  const handleRetry = React.useMemo(() => {
22
89
  if (file.type === 'ERROR' && file.data) {
23
90
  return () => {
@@ -31,7 +98,18 @@ const FormElementFile = ({ element, onRemove, file, onChange, disableUpload, ind
31
98
  };
32
99
  }
33
100
  }, [file, onChange]);
34
- return (React.createElement(FileCard, { element: element, isUploading: attachmentResult.isUploading, isUploadPaused: disableUpload, uploadErrorMessage: attachmentResult.uploadErrorMessage, loadAttachmentUrlError: attachmentResult.loadAttachmentUrlError, isLoadingAttachmentUrl: attachmentResult.isLoadingAttachmentUrl, attachmentUrl: attachmentResult.attachmentUrl, isContentTypeImage: attachmentResult.isContentTypeImage, fileName: file.fileName, onDownload: attachmentResult.canDownload ? handleDownload : undefined, onRemove: handleRemove, onRetry: handleRetry, progress: attachmentResult.progress, index: index }));
101
+ return (React.createElement(React.Fragment, null,
102
+ React.createElement(FileCard, { element: element, isUploading: isUploading, isUploadPaused: disableUpload, uploadErrorMessage: uploadErrorMessage, loadAttachmentUrlError: loadAttachmentUrlError, isLoadingAttachmentUrl: isLoadingAttachmentUrl || state.isLoading, attachmentUrl: attachmentUrl, isContentTypeImage: isContentTypeImage, fileName: file.fileName, onDownload: canDownload ? handleDownload : undefined, onRemove: handleRemove, onRetry: handleRetry, progress: progress, index: index, onAnnotate: setIsAnnotating, onCrop: setIsCropping }),
103
+ isCropping && attachmentUrl && (React.createElement(CropModal, { imageSrc: attachmentUrl, onClose: clearIsCropping, onSave: handleSaveCrop })),
104
+ isAnnotating && attachmentUrl && (React.createElement(AnnotationModal, { imageSrc: attachmentUrl, onClose: clearIsAnnotating, onSave: handleAnnotate })),
105
+ state.error && (React.createElement(Modal, { isOpen: true, title: "Whoops...", className: "cypress-error-modal", titleClassName: "cypress-error-title", actions: React.createElement("button", { type: "button", className: "button ob-button is-primary cypress-close-error-button", onClick: () => setState({ isLoading: false }), autoFocus: true }, "Okay") },
106
+ React.createElement("p", null,
107
+ "An error occurred while attempting to edit an image. Please click",
108
+ ' ',
109
+ React.createElement("b", null, "Okay"),
110
+ " below to try again. If the problem persists, please contact support."),
111
+ React.createElement("div", { className: "content has-margin-top-6" },
112
+ React.createElement("blockquote", null, state.error.toString()))))));
35
113
  };
36
114
  export default React.memo(FormElementFile);
37
115
  //# sourceMappingURL=FormElementFile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormElementFile.js","sourceRoot":"","sources":["../../src/form-elements/FormElementFile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAE1D,OAAO,aAA2B,MAAM,oCAAoC,CAAA;AAC5E,OAAO,QAAQ,MAAM,6CAA6C,CAAA;AAalE,MAAM,eAAe,GAAG,CAAC,EACvB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,KAAK,GACC,EAAE,EAAE;IACV,MAAM,gBAAgB,GAAG,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAA;IAE9E,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACtC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAM;QACR,CAAC;QACD,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC1B,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,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AAE,WAAW,EACpB,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EACnC,KAAK,EAAE,KAAK,GACZ,CACH,CAAA;AACH,CAAC,CAAA;AAED,eAAe,KAAK,CAAC,IAAI,CAAQ,eAAe,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport downloadAttachment from '../services/download-file'\nimport { FormTypes } from '@oneblink/types'\nimport useAttachment, { OnChange } from '../hooks/attachments/useAttachment'\nimport FileCard from '../components/renderer/attachments/FileCard'\nimport { attachmentsService } from '@oneblink/apps'\n\ntype Props = {\n element: FormTypes.FilesElement\n /** If set to `undefined`, the remove button will be hidden */\n onRemove: ((id: string) => void) | undefined\n file: attachmentsService.Attachment\n disableUpload: boolean\n onChange: OnChange\n index: number\n}\n\nconst FormElementFile = ({\n element,\n onRemove,\n file,\n onChange,\n disableUpload,\n index,\n}: Props) => {\n const attachmentResult = useAttachment(file, element, onChange, disableUpload)\n\n const handleRemove = React.useMemo(() => {\n if (!onRemove) {\n return\n }\n return () => {\n if (!file.type) {\n return onRemove(file.id)\n }\n return onRemove(file._id)\n }\n }, [file, onRemove])\n\n const handleDownload = React.useCallback(async () => {\n await downloadAttachment(file)\n }, [file])\n\n const handleRetry = React.useMemo(() => {\n if (file.type === 'ERROR' && file.data) {\n return () => {\n onChange(file._id, {\n type: 'NEW',\n _id: file._id,\n data: file.data,\n fileName: file.fileName,\n isPrivate: file.isPrivate,\n })\n }\n }\n }, [file, onChange])\n\n return (\n <FileCard\n element={element}\n isUploading={attachmentResult.isUploading}\n isUploadPaused={disableUpload}\n uploadErrorMessage={attachmentResult.uploadErrorMessage}\n loadAttachmentUrlError={attachmentResult.loadAttachmentUrlError}\n isLoadingAttachmentUrl={attachmentResult.isLoadingAttachmentUrl}\n attachmentUrl={attachmentResult.attachmentUrl}\n isContentTypeImage={attachmentResult.isContentTypeImage}\n fileName={file.fileName}\n onDownload={attachmentResult.canDownload ? handleDownload : undefined}\n onRemove={handleRemove}\n onRetry={handleRetry}\n progress={attachmentResult.progress}\n index={index}\n />\n )\n}\n\nexport default React.memo<Props>(FormElementFile)\n"]}
1
+ {"version":3,"file":"FormElementFile.js","sourceRoot":"","sources":["../../src/form-elements/FormElementFile.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,kBAAkB,MAAM,2BAA2B,CAAA;AAE1D,OAAO,aAA2B,MAAM,oCAAoC,CAAA;AAC5E,OAAO,QAAQ,MAAM,6CAA6C,CAAA;AAElE,OAAO,eAAe,MAAM,0BAA0B,CAAA;AACtD,OAAO,SAAS,MAAM,sCAAsC,CAAA;AAC5D,OAAO,eAAe,EAAE,EACtB,4BAA4B,GAC7B,MAAM,wCAAwC,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,MAAM,8BAA8B,CAAA;AAYhD,MAAM,eAAe,GAAG,CAAC,EACvB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,KAAK,GACC,EAAE,EAAE;IACV,MAAM,CAAC,YAAY,EAAE,eAAe,EAAE,iBAAiB,CAAC,GACtD,eAAe,CAAC,KAAK,CAAC,CAAA;IACxB,MAAM,CAAC,UAAU,EAAE,aAAa,EAAE,eAAe,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;IAC3E,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAGrC;QACD,SAAS,EAAE,KAAK;QAChB,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;IACF,MAAM,EACJ,aAAa,EACb,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,QAAQ,GACT,GAAG,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,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,EACpC,OAAO,EACL,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,wDAAwD,EAClE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAC7C,SAAS,iBAGF;YAGX;;gBACoE,GAAG;gBACrE,sCAAW;wFAET;YAEJ,6BAAK,SAAS,EAAC,0BAA0B;gBACvC,wCAAa,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAc,CAC7C,CACA,CACT,CACA,CACJ,CAAA;AACH,CAAC,CAAA;AAED,eAAe,KAAK,CAAC,IAAI,CAAQ,eAAe,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport downloadAttachment from '../services/download-file'\nimport { FormTypes } from '@oneblink/types'\nimport useAttachment, { OnChange } from '../hooks/attachments/useAttachment'\nimport FileCard from '../components/renderer/attachments/FileCard'\nimport { attachmentsService } from '@oneblink/apps'\nimport useBooleanState from '../hooks/useBooleanState'\nimport CropModal from '../components/ImageCropper/CropModal'\nimport AnnotationModal, {\n superimposeAnnotationOnImage,\n} from '../components/renderer/AnnotationModal'\nimport { Area } from 'react-easy-crop'\nimport { generateCroppedImageBlob } from '../components/ImageCropper'\nimport { prepareNewAttachment } from '../services/attachments'\nimport Modal from '../components/renderer/Modal'\n\ntype Props = {\n element: FormTypes.FilesElement\n /** If set to `undefined`, the remove button will be hidden */\n onRemove: ((id: string) => void) | undefined\n file: attachmentsService.Attachment\n disableUpload: boolean\n onChange: OnChange\n index: number\n}\n\nconst FormElementFile = ({\n element,\n onRemove,\n file,\n onChange,\n disableUpload,\n index,\n}: Props) => {\n const [isAnnotating, setIsAnnotating, clearIsAnnotating] =\n useBooleanState(false)\n const [isCropping, setIsCropping, clearIsCropping] = useBooleanState(false)\n const [state, setState] = React.useState<{\n isLoading: boolean\n error?: Error\n }>({\n isLoading: false,\n error: undefined,\n })\n const {\n attachmentUrl,\n contentType,\n isUploading,\n uploadErrorMessage,\n isLoadingAttachmentUrl,\n loadAttachmentUrlError,\n isContentTypeImage,\n canDownload,\n progress,\n } = useAttachment(file, element, onChange, disableUpload)\n\n const handleRemove = React.useMemo(() => {\n if (!onRemove) {\n return\n }\n return () => {\n if (!file.type) {\n return onRemove(file.id)\n }\n return onRemove(file._id)\n }\n }, [file, onRemove])\n\n const handleDownload = React.useCallback(async () => {\n await downloadAttachment(file)\n }, [file])\n\n const handleAnnotate = React.useCallback(\n async (annotationDataUri: string) => {\n if (!attachmentUrl || file.type) return\n clearIsAnnotating()\n\n setState({\n isLoading: true,\n })\n\n try {\n const blob = await superimposeAnnotationOnImage({\n annotationDataUri,\n attachmentUrl,\n })\n setState({\n isLoading: false,\n })\n if (!blob) return\n const attachment = prepareNewAttachment(blob, file.fileName, element)\n onChange(file.id, attachment)\n } catch (error) {\n setState({\n error: error as Error,\n isLoading: false,\n })\n }\n },\n [attachmentUrl, clearIsAnnotating, element, file, onChange],\n )\n const handleSaveCrop = React.useCallback(\n async (croppedAreaPixels: Area) => {\n if (!attachmentUrl || file.type) return\n clearIsCropping()\n\n setState({\n isLoading: true,\n })\n\n try {\n const croppedImage = await generateCroppedImageBlob({\n croppedAreaPixels,\n imgSrc: attachmentUrl,\n fileType: contentType,\n })\n setState({\n isLoading: false,\n })\n if (!croppedImage) return\n const attachment = prepareNewAttachment(\n croppedImage,\n file.fileName,\n element,\n )\n onChange(file.id, attachment)\n } catch (error) {\n setState({\n error: error as Error,\n isLoading: false,\n })\n }\n },\n [attachmentUrl, clearIsCropping, contentType, element, file, onChange],\n )\n const handleRetry = React.useMemo(() => {\n if (file.type === 'ERROR' && file.data) {\n return () => {\n onChange(file._id, {\n type: 'NEW',\n _id: file._id,\n data: file.data,\n fileName: file.fileName,\n isPrivate: file.isPrivate,\n })\n }\n }\n }, [file, onChange])\n\n return (\n <>\n <FileCard\n element={element}\n isUploading={isUploading}\n isUploadPaused={disableUpload}\n uploadErrorMessage={uploadErrorMessage}\n loadAttachmentUrlError={loadAttachmentUrlError}\n isLoadingAttachmentUrl={isLoadingAttachmentUrl || state.isLoading}\n attachmentUrl={attachmentUrl}\n isContentTypeImage={isContentTypeImage}\n fileName={file.fileName}\n onDownload={canDownload ? handleDownload : undefined}\n onRemove={handleRemove}\n onRetry={handleRetry}\n progress={progress}\n index={index}\n onAnnotate={setIsAnnotating}\n onCrop={setIsCropping}\n />\n {isCropping && attachmentUrl && (\n <CropModal\n imageSrc={attachmentUrl}\n onClose={clearIsCropping}\n onSave={handleSaveCrop}\n />\n )}\n {isAnnotating && attachmentUrl && (\n <AnnotationModal\n imageSrc={attachmentUrl}\n onClose={clearIsAnnotating}\n onSave={handleAnnotate}\n />\n )}\n {state.error && (\n <Modal\n isOpen\n title=\"Whoops...\"\n className=\"cypress-error-modal\"\n titleClassName=\"cypress-error-title\"\n actions={\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-close-error-button\"\n onClick={() => setState({ isLoading: false })}\n autoFocus\n >\n Okay\n </button>\n }\n >\n <p>\n An error occurred while attempting to edit an image. Please click{' '}\n <b>Okay</b> below to try again. If the problem persists, please\n contact support.\n </p>\n\n <div className=\"content has-margin-top-6\">\n <blockquote>{state.error.toString()}</blockquote>\n </div>\n </Modal>\n )}\n </>\n )\n}\n\nexport default React.memo<Props>(FormElementFile)\n"]}
@@ -5,6 +5,7 @@ export type OnChange = (id: string, attachment: attachmentsService.Attachment) =
5
5
  export default function useAttachment(value: FormElementBinaryStorageValue, element: FormTypes.FormElementBinaryStorage, onChange: OnChange, disableUpload?: boolean): {
6
6
  canDownload: boolean;
7
7
  progress: number | undefined;
8
+ contentType: string | undefined;
8
9
  attachmentUrl?: string | null;
9
10
  loadAttachmentUrlError?: Error;
10
11
  isContentTypeImage?: boolean;