From 6e51d977e398969e3cb4182853f2d7d48ecbcb69 Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:50:25 +0800 Subject: [PATCH 1/4] add core-js and polyfill entry on usage to fix test --- .babelrc | 12 ++++++++++-- package.json | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.babelrc b/.babelrc index 1320b9a3..601d3370 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,11 @@ { - "presets": ["@babel/preset-env"] -} + "presets": [ + [ + "@babel/preset-env", + { + "corejs": 3, + "useBuiltIns": "usage" + } + ] + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 9788f041..4b9e8928 100644 --- a/package.json +++ b/package.json @@ -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", From 7f41f0901daa6b7267e8bef21c1019de9196e826 Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:50:40 +0800 Subject: [PATCH 2/4] some overhaul on simple property --- lib/mixins/SimpleProperty.js | 55 +++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/mixins/SimpleProperty.js b/lib/mixins/SimpleProperty.js index 9c6cc0f0..fc7eefac 100644 --- a/lib/mixins/SimpleProperty.js +++ b/lib/mixins/SimpleProperty.js @@ -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: { @@ -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) @@ -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' From 27dffbc69d824c3bbe21538bc5638acb4c05ef9f Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:55:48 +0800 Subject: [PATCH 3/4] add vuetify as peer dependencies --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 4b9e8928..103d6468 100644 --- a/package.json +++ b/package.json @@ -92,5 +92,8 @@ "webpack-cli": "^3.3.6", "webpack-dev-server": "^3.7.2", "yaml": "^1.7.1" + }, + "peerDependencies": { + "vuetify": ">=2" } } From bfd29d537dc37ab68c9959fb829a8c6e995fcbad Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Fri, 26 Jun 2020 18:13:31 +0800 Subject: [PATCH 4/4] overhaul file props --- lib/mixins/FileProperty.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/mixins/FileProperty.js b/lib/mixins/FileProperty.js index c775d010..df8c11fd 100644 --- a/lib/mixins/FileProperty.js +++ b/lib/mixins/FileProperty.js @@ -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 } },