Skip to content

Commit

Permalink
Add file-path/image-path extension property
Browse files Browse the repository at this point in the history
As suggested in #22
  • Loading branch information
nytamin committed Oct 24, 2023
1 parent aeab98b commit 3f2a092
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
}
}
}
```
Expand Down
39 changes: 39 additions & 0 deletions gdd-meta-schema/v1/lib/gdd-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions lib/javascript-library/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
65 changes: 65 additions & 0 deletions lib/unit-tests/__tests__/gddTypes/image-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
})

0 comments on commit 3f2a092

Please sign in to comment.