Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file-path/image-path extension property #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/)
})