From 9a7705701ea60dd407af8284f72b4e57f8272e04 Mon Sep 17 00:00:00 2001 From: nd0ut Date: Thu, 29 Feb 2024 14:50:10 +0300 Subject: [PATCH] feat: add `cameraCapture` option to specify inpit capture attribute value --- abstract/UploaderBlock.js | 1 + blocks/Config/initialConfig.js | 1 + blocks/Config/normalizeConfigValue.js | 10 ++++++++++ types/exported.d.ts | 1 + 4 files changed, 13 insertions(+) diff --git a/abstract/UploaderBlock.js b/abstract/UploaderBlock.js index 64a8b69d8..8a798651a 100644 --- a/abstract/UploaderBlock.js +++ b/abstract/UploaderBlock.js @@ -292,6 +292,7 @@ export class UploaderBlock extends ActivityBlock { this.fileInput.type = 'file'; this.fileInput.multiple = this.cfg.multiple; if (options.captureCamera) { + this.fileInput.capture = this.cfg.cameraCapture; this.fileInput.capture = ''; this.fileInput.accept = serializeCsv(IMAGE_ACCEPT_LIST); } else { diff --git a/blocks/Config/initialConfig.js b/blocks/Config/initialConfig.js index 33b6a6f1f..f834b7485 100644 --- a/blocks/Config/initialConfig.js +++ b/blocks/Config/initialConfig.js @@ -20,6 +20,7 @@ export const initialConfig = { externalSourcesPreferredTypes: '', store: 'auto', cameraMirror: false, + cameraCapture: '', sourceList: 'local, url, camera, dropbox, gdrive', cloudImageEditorTabs: serializeCsv(ALL_TABS), maxLocalFileSizeBytes: 0, diff --git a/blocks/Config/normalizeConfigValue.js b/blocks/Config/normalizeConfigValue.js index e238f4400..835e234d0 100644 --- a/blocks/Config/normalizeConfigValue.js +++ b/blocks/Config/normalizeConfigValue.js @@ -27,6 +27,15 @@ export const asBoolean = (value) => { /** @param {unknown} value */ const asStore = (value) => (value === 'auto' ? value : asBoolean(value)); +/** @param {unknown} value */ +const asCameraCapture = (value) => { + const strValue = asString(value); + if (strValue !== 'user' && strValue !== 'environment' && strValue !== '') { + throw new Error(`Invalid "cameraCapture" value: "${strValue}"`); + } + return strValue; +}; + /** * @type {{ * [Key in keyof import('../../types').ConfigPlainType]: ( @@ -46,6 +55,7 @@ const mapping = { externalSourcesPreferredTypes: asString, store: asStore, cameraMirror: asBoolean, + cameraCapture: asCameraCapture, sourceList: asString, maxLocalFileSizeBytes: asNumber, thumbSize: asNumber, diff --git a/types/exported.d.ts b/types/exported.d.ts index 1bde9d33c..d23a3bd48 100644 --- a/types/exported.d.ts +++ b/types/exported.d.ts @@ -15,6 +15,7 @@ export type ConfigType = { externalSourcesPreferredTypes: string; store: boolean | 'auto'; cameraMirror: boolean; + cameraCapture: 'user' | 'environment' | ''; sourceList: string; maxLocalFileSizeBytes: number; thumbSize: number;