diff --git a/README.md b/README.md index 35eddac..645d001 100644 --- a/README.md +++ b/README.md @@ -318,7 +318,24 @@ Lets the user pick an image file from disk "type": "string", "gddType": "file-path/image-path", "gddOptions": { - "extensions": ["jpg", "png"] // [Optional, Array of strings] Limit which files can be chosen by the user. + // [Optional, Array of strings] Limit which files can be chosen by the user. + "extensions": ["jpg", "png"], + // [Optional] Put limits the size of the image. (Client could possibly resize an image to fit) + // This is using the same type of definitions used to define webcam inputs: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#examples + "size": { + "width": { + "min": 1024, + "ideal": 1280, + "max": 1920 + // "exact": 1280 // when used, `exact` equals to `min` === `max` + }, + "height": { + "min": 576, + "ideal": 720, + "max": 1080 + // "exact": 720 // when used, `exact` equals to `min` === `max` + } + } } } ``` diff --git a/gdd-meta-schema/v1/lib/gdd-types.json b/gdd-meta-schema/v1/lib/gdd-types.json index 1dce38a..5506b8e 100644 --- a/gdd-meta-schema/v1/lib/gdd-types.json +++ b/gdd-meta-schema/v1/lib/gdd-types.json @@ -71,6 +71,45 @@ "items": { "type": "string" } + }, + "size": { + "type": "object", + "properties": { + "width": { + "type": "object", + "properties": { + "min": { + "type": "integer" + }, + "ideal": { + "type": "integer" + }, + "max": { + "type": "integer" + }, + "exact": { + "type": "integer" + } + } + }, + "height": { + "type": "object", + "properties": { + "min": { + "type": "integer" + }, + "ideal": { + "type": "integer" + }, + "max": { + "type": "integer" + }, + "exact": { + "type": "integer" + } + } + } + } } } } diff --git a/lib/javascript-library/src/lib/types.ts b/lib/javascript-library/src/lib/types.ts index 6ae7dd3..f992d76 100644 --- a/lib/javascript-library/src/lib/types.ts +++ b/lib/javascript-library/src/lib/types.ts @@ -157,6 +157,20 @@ export interface GDDTypeFilePathImagePath extends GDDSchemaPropertyString { gddType: 'file-path/image-path' gddOptions?: { extensions?: string[] + size?: { + width?: { + min?: number + ideal?: number + max?: number + exact?: number + } + height?: { + min?: number + ideal?: number + max?: number + exact?: number + } + } } } export interface GDDTypeStringSelect extends GDDSchemaPropertyString { diff --git a/lib/unit-tests/__tests__/gddTypes/image-path.test.ts b/lib/unit-tests/__tests__/gddTypes/image-path.test.ts index 84799ab..1488bc9 100644 --- a/lib/unit-tests/__tests__/gddTypes/image-path.test.ts +++ b/lib/unit-tests/__tests__/gddTypes/image-path.test.ts @@ -53,4 +53,69 @@ test('gddType: image-file-path', async () => { }, }) ).toMatch(/is not of a type.*string/) + + expect( + validateSchema({ + type: 'object', + properties: { + f0: { + type: 'string', + gddType: 'file-path/image-path', + gddOptions: { + size: {}, + }, + }, + }, + }) + ).toBe(null) + expect( + validateSchema({ + type: 'object', + properties: { + f0: { + type: 'string', + gddType: 'file-path/image-path', + gddOptions: { + size: { + width: { + min: 100, + max: 200, + ideal: 150, + }, + height: { + min: 100, + max: 200, + ideal: 150, + }, + }, + }, + }, + }, + }) + ).toBe(null) + expect( + validateSchema({ + type: 'object', + properties: { + f0: { + type: 'string', + gddType: 'file-path/image-path', + gddOptions: { + size: { + width: { + min: 100, + max: 200, + ideal: 150, + }, + height: { + min: 100, + max: 200, + ideal: 150.5, + }, + }, + }, + }, + }, + }) + ).toMatch(/is not of a type.*integer/) })