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

Some simple overhauls #118

Closed
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
12 changes: 10 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"presets": ["@babel/preset-env"]
}
"presets": [
[
"@babel/preset-env",
{
"corejs": 3,
"useBuiltIns": "usage"
}
]
]
}
31 changes: 23 additions & 8 deletions lib/mixins/FileProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,29 @@ const getFileResult = async (file, schema, filesAsDataUrl) => {
export default {
computed: {
isFileProp() {
if (this.fullSchema.type === 'string' &&
(this.fullSchema.contentMediaType || this.display === 'file')) return true
if (this.fullSchema.type === 'array' && this.fullSchema.items && this.fullSchema.items.type === 'string' &&
(this.fullSchema.items.contentMediaType || this.display === 'file' || this.fullSchema.items['x-display'] === 'file')) return true
if (this.fullSchema.type === 'object' &&
(this.fullSchema.contentMediaType || this.display === 'file')) return true
if (this.fullSchema.type === 'array' && this.fullSchema.items && this.fullSchema.items.type === 'object' &&
(this.fullSchema.items.contentMediaType || this.display === 'file' || this.fullSchema.items['x-display'] === 'file')) return true
const isItemsOfType = (x) =>
this.fullSchema.items && this.fullSchema.items.type === x

const checkDisplayAndContentMedia = (shouldCheckItemsOnSchema) =>
this.display === 'file' || (
shouldCheckItemsOnSchema
? this.fullSchema.items
: this.fullSchema
).contentMediaType

switch (this.fullSchema.type) {
case 'string':
case 'object': {
return checkDisplayAndContentMedia(false)
}
case 'array': {
if (isItemsOfType('string') || isItemsOfType('object')) {
return checkDisplayAndContentMedia(true) || this.fullSchema.items['x-display'] === 'file'
}
break
}
default: break
}
return false
}
},
Expand Down
55 changes: 35 additions & 20 deletions lib/mixins/SimpleProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import schemaUtils from '../utils/schema'
export default {
computed: {
isSimpleProp() {
return this.fullSchema.type === 'string' ||
['number', 'integer'].includes(this.fullSchema.type) ||
this.fullSchema.type === 'boolean' ||
(this.fullSchema.type === 'array' && ['string', 'number', 'integer'].includes(this.fullSchema.items.type))
const isPrimitive = (x) => ['number', 'integer', 'string', 'boolean'].includes(x)
return isPrimitive(this.fullSchema.type) || (this.fullSchema.type === 'array' && isPrimitive(this.fullSchema.items.type))
}
},
methods: {
Expand Down Expand Up @@ -38,20 +36,29 @@ export default {
}

if (['number', 'integer'].includes(this.fullSchema.type)) {
tag = 'v-text-field'
if (this.display === 'slider') tag = 'v-slider'
tag = (() => {
switch (this.display) {
case 'slider': return 'v-slider'
default: return 'v-text-field'
}
})()

props.type = 'number'
if (this.fullSchema.minimum !== undefined) props.min = this.fullSchema.minimum
if (this.fullSchema.maximum !== undefined) props.max = this.fullSchema.maximum
props.min = this.fullSchema.minimum
props.max = this.fullSchema.maximum
props.step = this.fullSchema['x-step'] || (this.fullSchema.type === 'integer' ? 1 : 0.01)

on.input = value => this.input(this.fullSchema.type === 'integer' ? parseInt(value, 10) : parseFloat(value))
}

if (this.fullSchema.type === 'boolean') {
tag = 'v-checkbox'
if (this.display === 'switch') tag = 'v-switch'
tag = (() => {
switch (this.display) {
case 'switch': return 'v-switch'
default: return 'v-checkbox'
}
})()

on.change = value => {
this.input(value || false)
this.change(value || false)
Expand All @@ -66,16 +73,24 @@ export default {
props.appendIcon = ''
props.type = 'string'
const itemRules = getRules(schemaUtils.prepareFullSchema(this.fullSchema.items), this.fullOptions)
props.rules = props.rules.concat([(values) => {
const valuesMessages = values.map(value => {
const brokenRule = itemRules.find(rule => {
return typeof rule(value) === 'string'
})
return brokenRule && brokenRule(value)
})
const firstMessage = valuesMessages.find(m => !!m)
return firstMessage || true
}])
props.rules = [
...props.rules,
(values) => {
// for value, rule in values, itemRules
for (const value in values) {
for (const rule in itemRules) {
const ret = rule(value)
// if the rule execution returns something not true, this implies an error message kicks in
if (!ret) {
return ret
}
}
}
// at this point we let the validation pass, we had no valid messages to show anyway
// formally, this could have had been to just return undefined
return true
}
]

if (this.fullSchema.items.type !== 'string') {
props.type = 'number'
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"babel-jest": "^26.1.0",
"babel-loader": "^8.0.6",
"babel-polyfill": "^6.26.0",
"core-js": "3.6.5",
"eslint": "^6.1.0",
"eslint-config-standard": "^13.0.1",
"eslint-plugin-import": "^2.18.2",
Expand All @@ -91,5 +92,8 @@
"webpack-cli": "^3.3.6",
"webpack-dev-server": "^3.7.2",
"yaml": "^1.7.1"
},
"peerDependencies": {
"vuetify": ">=2"
}
}