diff --git a/abstract/ActivityBlock.js b/abstract/ActivityBlock.js index 929711a54..b1f5ad56d 100644 --- a/abstract/ActivityBlock.js +++ b/abstract/ActivityBlock.js @@ -191,7 +191,6 @@ export class ActivityBlock extends Block { } } -/** @enum {String} */ ActivityBlock.activities = Object.freeze({ START_FROM: 'start-from', CAMERA: 'camera', diff --git a/abstract/Block.js b/abstract/Block.js index fb3e293c4..ff553b4df 100644 --- a/abstract/Block.js +++ b/abstract/Block.js @@ -20,6 +20,8 @@ export class Block extends BaseComponent { static className = ''; requireCtxName = false; allowCustomTemplate = true; + /** @type {import('./ActivityBlock.js').ActivityType} */ + activityType = null; init$ = blockCtx(); @@ -57,8 +59,6 @@ export class Block extends BaseComponent { constructor() { super(); - /** @type {import('./ActivityBlock.js').ActivityType} */ - this.activityType = null; // @ts-ignore TODO: fix this this.addTemplateProcessor(l10nProcessor); // TODO: inspect template on lr-* elements diff --git a/abstract/UploaderBlock.js b/abstract/UploaderBlock.js index c839f1b6d..f66e474ea 100644 --- a/abstract/UploaderBlock.js +++ b/abstract/UploaderBlock.js @@ -408,22 +408,35 @@ export class UploaderBlock extends ActivityBlock { * @param {import('./TypedData.js').TypedData} [internalEntry] */ _validateUploadError(outputEntry, internalEntry) { - /** @type {Error} */ - const error = internalEntry?.getValue('uploadError'); - if (!error) { + /** @type {unknown} */ + const cause = internalEntry?.getValue('uploadError'); + if (!cause) { return; } - /** @type {import('../types').OutputFileErrorType} */ - const errorType = - error instanceof UploadError ? 'UPLOAD_ERROR' : error instanceof NetworkError ? 'NETWORK_ERROR' : 'UNKNOWN_ERROR'; - - return buildOutputFileError({ - type: errorType, - entry: outputEntry, - message: error.message, - error, - }); + if (cause instanceof UploadError) { + return buildOutputFileError({ + type: 'UPLOAD_ERROR', + message: cause.message, + entry: outputEntry, + error: cause, + }); + } else if (cause instanceof NetworkError) { + return buildOutputFileError({ + type: 'NETWORK_ERROR', + message: cause.message, + entry: outputEntry, + error: cause, + }); + } else { + const error = cause instanceof Error ? cause : new Error('Unknown error', { cause }); + return buildOutputFileError({ + type: 'UNKNOWN_ERROR', + message: error.message, + entry: outputEntry, + error, + }); + } } /** diff --git a/blocks/StartFrom/StartFrom.js b/blocks/StartFrom/StartFrom.js index 05d2e37a0..18ac4a098 100644 --- a/blocks/StartFrom/StartFrom.js +++ b/blocks/StartFrom/StartFrom.js @@ -2,6 +2,7 @@ import { ActivityBlock } from '../../abstract/ActivityBlock.js'; export class StartFrom extends ActivityBlock { historyTracked = true; + /** @type {import('../../abstract/ActivityBlock.js').ActivityType} */ activityType = 'start-from'; initCallback() { diff --git a/types/exported.d.ts b/types/exported.d.ts index d6cc74e36..1a50d1081 100644 --- a/types/exported.d.ts +++ b/types/exported.d.ts @@ -1,5 +1,7 @@ -import { UploadcareFile, UploadClientError, UploadcareNetworkError, UploadcareGroup } from '@uploadcare/upload-client'; - +export type UploadError = import('@uploadcare/upload-client').UploadError; +export type UploadcareFile = import('@uploadcare/upload-client').UploadcareFile; +export type NetworkError = import('@uploadcare/upload-client').NetworkError; +export type UploadcareGroup = import('@uploadcare/upload-client').UploadcareGroup; export type Metadata = import('@uploadcare/upload-client').Metadata; export type MetadataCallback = (fileEntry: OutputFileEntry) => Promise | Metadata; export type ConfigType = { @@ -89,10 +91,10 @@ export type OutputErrorTypePayload = { total: number; }; UPLOAD_ERROR: OutputFileErrorPayload & { - error: UploadClientError; + error: UploadError; }; NETWORK_ERROR: OutputFileErrorPayload & { - error: UploadcareNetworkError; + error: NetworkError; }; UNKNOWN_ERROR: OutputFileErrorPayload & { error?: Error; diff --git a/types/jsx.d.ts b/types/jsx.d.ts index b14a2c041..3e3d9689b 100644 --- a/types/jsx.d.ts +++ b/types/jsx.d.ts @@ -61,7 +61,7 @@ declare namespace JSX { CloudImageEditorBlock, JSX.IntrinsicElements['lr-cloud-image-editor-block'] & ShadowWrapperAttributes >; - 'lr-form-input': CustomElement, CtxAttributes>; + 'lr-form-input': CustomElement; 'lr-file-uploader-regular': CustomElement; 'lr-file-uploader-minimal': CustomElement; 'lr-file-uploader-inline': CustomElement;