1
- /** @license @lljj /vue-json-schema-form (c) 2020-2021 Liu.Jun License: Apache-2.0 */
1
+ /** @license @lljj /vue-json-schema-form (c) 2020-2022 Liu.Jun License: Apache-2.0 */
2
2
import Vue from 'vue' ;
3
3
4
4
function _typeof ( obj ) {
@@ -9214,6 +9214,7 @@ function mergeDefaultsWithFormData(defaults, formData) {
9214
9214
function computeDefaults ( _schema , parentDefaults , rootSchema ) {
9215
9215
var rawFormData = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : { } ;
9216
9216
var includeUndefinedValues = arguments . length > 4 && arguments [ 4 ] !== undefined ? arguments [ 4 ] : false ;
9217
+ var haveAllFields = arguments . length > 5 && arguments [ 5 ] !== undefined ? arguments [ 5 ] : false ;
9217
9218
var schema = isObject ( _schema ) ? _schema : { } ;
9218
9219
var formData = isObject ( rawFormData ) ? rawFormData : { } ; // allOf 处理合并数据
9219
9220
@@ -9234,7 +9235,7 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9234
9235
} else if ( '$ref' in schema ) {
9235
9236
// Use referenced schema defaults for this node.
9236
9237
var refSchema = findSchemaDefinition ( schema . $ref , rootSchema ) ;
9237
- return computeDefaults ( refSchema , defaults , rootSchema , formData , includeUndefinedValues ) ;
9238
+ return computeDefaults ( refSchema , defaults , rootSchema , formData , includeUndefinedValues , haveAllFields ) ;
9238
9239
} else if (
9239
9240
/* ('dependencies' in schema) {
9240
9241
const resolvedSchema = resolveDependencies(schema, rootSchema, formData);
@@ -9243,15 +9244,16 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9243
9244
defaults,
9244
9245
rootSchema,
9245
9246
formData,
9246
- includeUndefinedValues
9247
+ includeUndefinedValues,
9248
+ haveAllFields
9247
9249
);
9248
9250
} else if */
9249
9251
isFixedItems ( schema ) ) {
9250
9252
defaults = schema . items . map ( function ( itemSchema , idx ) {
9251
- return computeDefaults ( itemSchema , Array . isArray ( parentDefaults ) ? parentDefaults [ idx ] : undefined , rootSchema , formData , includeUndefinedValues ) ;
9253
+ return computeDefaults ( itemSchema , Array . isArray ( parentDefaults ) ? parentDefaults [ idx ] : undefined , rootSchema , formData , includeUndefinedValues , haveAllFields ) ;
9252
9254
} ) ;
9253
9255
} else if ( 'oneOf' in schema ) {
9254
- var matchSchema = retrieveSchema ( schema . oneOf [ getMatchingOption ( formData , schema . oneOf , rootSchema ) ] , rootSchema , formData ) ;
9256
+ var matchSchema = retrieveSchema ( schema . oneOf [ getMatchingOption ( formData , schema . oneOf , rootSchema , haveAllFields ) ] , rootSchema , formData ) ;
9255
9257
schema = mergeObjects ( schema , matchSchema ) ;
9256
9258
delete schema . oneOf ; // if (schema.properties && matchSchema.properties) {
9257
9259
// // 对象 oneOf 需要合并原属性和 oneOf 属性
@@ -9262,7 +9264,7 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9262
9264
// schema = matchSchema;
9263
9265
// }
9264
9266
} else if ( 'anyOf' in schema ) {
9265
- var _matchSchema = retrieveSchema ( schema . anyOf [ getMatchingOption ( formData , schema . anyOf , rootSchema ) ] , rootSchema , formData ) ;
9267
+ var _matchSchema = retrieveSchema ( schema . anyOf [ getMatchingOption ( formData , schema . anyOf , rootSchema , haveAllFields ) ] , rootSchema , formData ) ;
9266
9268
9267
9269
schema = mergeObjects ( schema , _matchSchema ) ;
9268
9270
delete schema . anyOf ; // if (schema.properties && matchSchema.properties) {
@@ -9290,7 +9292,7 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9290
9292
return Object . keys ( schema . properties || { } ) . reduce ( function ( acc , key ) {
9291
9293
// Compute the defaults for this node, with the parent defaults we might
9292
9294
// have from a previous run: defaults[key].
9293
- var computedDefault = computeDefaults ( schema . properties [ key ] , ( defaults || { } ) [ key ] , rootSchema , ( formData || { } ) [ key ] , includeUndefinedValues ) ;
9295
+ var computedDefault = computeDefaults ( schema . properties [ key ] , ( defaults || { } ) [ key ] , rootSchema , ( formData || { } ) [ key ] , includeUndefinedValues , haveAllFields ) ;
9294
9296
9295
9297
if ( includeUndefinedValues || computedDefault !== undefined ) {
9296
9298
acc [ key ] = computedDefault ;
@@ -9303,14 +9305,14 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9303
9305
// Inject defaults into existing array defaults
9304
9306
if ( Array . isArray ( defaults ) ) {
9305
9307
defaults = defaults . map ( function ( item , idx ) {
9306
- return computeDefaults ( schema . items [ idx ] || schema . additionalItems || { } , item , rootSchema , { } , includeUndefinedValues ) ;
9308
+ return computeDefaults ( schema . items [ idx ] || schema . additionalItems || { } , item , rootSchema , { } , includeUndefinedValues , haveAllFields ) ;
9307
9309
} ) ;
9308
9310
} // Deeply inject defaults into already existing form data
9309
9311
9310
9312
9311
9313
if ( Array . isArray ( rawFormData ) ) {
9312
9314
defaults = rawFormData . map ( function ( item , idx ) {
9313
- return computeDefaults ( schema . items , ( defaults || { } ) [ idx ] , rootSchema , item , { } , includeUndefinedValues ) ;
9315
+ return computeDefaults ( schema . items , ( defaults || { } ) [ idx ] , rootSchema , item , { } , includeUndefinedValues , haveAllFields ) ;
9314
9316
} ) ;
9315
9317
}
9316
9318
@@ -9322,7 +9324,7 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9322
9324
var defaultEntries = defaults || [ ] ; // populate the array with the defaults
9323
9325
9324
9326
var fillerSchema = Array . isArray ( schema . items ) ? schema . additionalItems : schema . items ;
9325
- var fillerEntries = fillObj ( new Array ( schema . minItems - defaultsLength ) , computeDefaults ( fillerSchema , fillerSchema . defaults , rootSchema , { } , includeUndefinedValues ) ) ;
9327
+ var fillerEntries = fillObj ( new Array ( schema . minItems - defaultsLength ) , computeDefaults ( fillerSchema , fillerSchema . defaults , rootSchema , { } , includeUndefinedValues , haveAllFields ) ) ;
9326
9328
return defaultEntries . concat ( fillerEntries ) ;
9327
9329
}
9328
9330
} else {
@@ -9341,13 +9343,14 @@ function computeDefaults(_schema, parentDefaults, rootSchema) {
9341
9343
function getDefaultFormState ( _schema , formData ) {
9342
9344
var rootSchema = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
9343
9345
var includeUndefinedValues = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : true ;
9346
+ var haveAllFields = arguments . length > 4 && arguments [ 4 ] !== undefined ? arguments [ 4 ] : false ;
9344
9347
9345
9348
if ( ! isObject ( _schema ) ) {
9346
9349
throw new Error ( "Invalid schema: " . concat ( _schema ) ) ;
9347
9350
}
9348
9351
9349
9352
var schema = retrieveSchema ( _schema , rootSchema , formData ) ;
9350
- var defaults = computeDefaults ( schema , _schema . default , rootSchema , formData , includeUndefinedValues ) ;
9353
+ var defaults = computeDefaults ( schema , _schema . default , rootSchema , formData , includeUndefinedValues , haveAllFields ) ;
9351
9354
9352
9355
if ( typeof formData === 'undefined' ) {
9353
9356
// No form data? Use schema defaults.
@@ -9427,6 +9430,10 @@ var vueProps = {
9427
9430
type : Boolean ,
9428
9431
default : false
9429
9432
} ,
9433
+ strictMode : {
9434
+ type : Boolean ,
9435
+ default : false
9436
+ } ,
9430
9437
schema : {
9431
9438
type : Object ,
9432
9439
default : function _default ( ) {
@@ -11698,7 +11705,7 @@ function createForm() {
11698
11705
} ;
11699
11706
} ,
11700
11707
data : function data ( ) {
11701
- var formData = getDefaultFormState ( this . $props . schema , this . $props . value , this . $props . schema ) ; // 保持v-model双向数据及时性
11708
+ var formData = getDefaultFormState ( this . $props . schema , this . $props . value , this . $props . schema , this . $props . strictMode ) ; // 保持v-model双向数据及时性
11702
11709
11703
11710
this . emitFormDataChange ( formData , this . value ) ;
11704
11711
return {
@@ -11747,7 +11754,7 @@ function createForm() {
11747
11754
// 避免用于双向绑定v-model 可能导致的循环调用
11748
11755
willReceiveProps : function willReceiveProps ( newVal , oldVal ) {
11749
11756
if ( ! deepEquals ( newVal , oldVal ) ) {
11750
- var formData = getDefaultFormState ( this . $props . schema , this . $props . value , this . $props . schema ) ;
11757
+ var formData = getDefaultFormState ( this . $props . schema , this . $props . value , this . $props . schema , this . $props . strictMode ) ;
11751
11758
11752
11759
if ( ! deepEquals ( this . formData , formData ) ) {
11753
11760
this . formData = formData ;
@@ -11827,6 +11834,11 @@ function createForm() {
11827
11834
formInlineFooter : inlineFooter ,
11828
11835
formInline : inline
11829
11836
} , _defineProperty ( _class , "genFromComponent_" . concat ( this . schema . id , "Form" ) , ! ! this . schema . id ) , _defineProperty ( _class , "layoutColumn" , ! inline ) , _defineProperty ( _class , "layoutColumn-" . concat ( layoutColumn ) , ! inline ) , _class ) ,
11837
+ nativeOn : {
11838
+ submit : function submit ( e ) {
11839
+ e . preventDefault ( ) ;
11840
+ }
11841
+ } ,
11830
11842
ref : 'genEditForm' ,
11831
11843
props : _objectSpread2 ( {
11832
11844
model : self . formData
0 commit comments