Skip to content

Commit

Permalink
feat: add cameraCapture option to specify inpit capture attribute v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
nd0ut committed Feb 29, 2024
1 parent f73a5c8 commit 9a77057
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions blocks/Config/initialConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions blocks/Config/normalizeConfigValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]: (
Expand All @@ -46,6 +55,7 @@ const mapping = {
externalSourcesPreferredTypes: asString,
store: asStore,
cameraMirror: asBoolean,
cameraCapture: asCameraCapture,
sourceList: asString,
maxLocalFileSizeBytes: asNumber,
thumbSize: asNumber,
Expand Down
1 change: 1 addition & 0 deletions types/exported.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ConfigType = {
externalSourcesPreferredTypes: string;
store: boolean | 'auto';
cameraMirror: boolean;
cameraCapture: 'user' | 'environment' | '';
sourceList: string;
maxLocalFileSizeBytes: number;
thumbSize: number;
Expand Down

0 comments on commit 9a77057

Please sign in to comment.