@blueking/bkui-form 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -465,6 +465,23 @@
465
465
  return obj;
466
466
  }
467
467
 
468
+ function _extends$1() {
469
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
470
+ for (var i = 1; i < arguments.length; i++) {
471
+ var source = arguments[i];
472
+
473
+ for (var key in source) {
474
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
475
+ target[key] = source[key];
476
+ }
477
+ }
478
+ }
479
+
480
+ return target;
481
+ };
482
+ return _extends$1.apply(this, arguments);
483
+ }
484
+
468
485
  function _objectWithoutPropertiesLoose(source, excluded) {
469
486
  if (source == null) return {};
470
487
  var target = {};
@@ -717,20 +734,6 @@
717
734
 
718
735
  return source;
719
736
  };
720
- function intersection(arr1, arr2) {
721
- return arr1.filter(function (item) {
722
- return arr2.includes(item);
723
- });
724
- } // 最大公约数
725
-
726
- function gcd(a, b) {
727
- if (b === 0) return a;
728
- return gcd(b, a % b);
729
- } // 最小公倍数
730
-
731
- function scm(a, b) {
732
- return a * b / gcd(a, b);
733
- } // 获取type对应的初始化值
734
737
 
735
738
  function initializationValue(type) {
736
739
  var defaultInitValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
@@ -1006,9 +1009,8 @@
1006
1009
  Registry.context = {};
1007
1010
  var registry = new Registry();
1008
1011
 
1009
- var _excluded$5 = ["allOf"],
1010
- _excluded2$1 = ["name"],
1011
- _excluded3 = ["name"];
1012
+ var _excluded$6 = ["name"],
1013
+ _excluded2$1 = ["name"];
1012
1014
 
1013
1015
  var Schema = /*#__PURE__*/function () {
1014
1016
  function Schema(rootSchema) {
@@ -1018,142 +1020,6 @@
1018
1020
  }
1019
1021
 
1020
1022
  _createClass(Schema, null, [{
1021
- key: "resolveAllOf",
1022
- value: function resolveAllOf(schema) {
1023
- var _schema$allOf,
1024
- _this = this;
1025
-
1026
- var allOfSchema = _objectSpread2(_objectSpread2({}, schema), {}, {
1027
- allOf: (_schema$allOf = schema.allOf) === null || _schema$allOf === void 0 ? void 0 : _schema$allOf.map(function (item) {
1028
- return _this.resolveSchema(item);
1029
- })
1030
- });
1031
-
1032
- try {
1033
- // const { allOf, ...reset } = allOfSchema;
1034
- return this.mergeSchemaAllOf();
1035
- } catch (e) {
1036
- console.warn(e);
1037
-
1038
- allOfSchema.allOf;
1039
- var reset = _objectWithoutProperties(allOfSchema, _excluded$5);
1040
-
1041
- return reset;
1042
- }
1043
- } // todo
1044
-
1045
- }, {
1046
- key: "mergeSchemaAllOf",
1047
- value: function mergeSchemaAllOf() {
1048
- var _this2 = this;
1049
-
1050
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1051
- args[_key] = arguments[_key];
1052
- }
1053
-
1054
- if (args.length < 2) return args[0];
1055
- var preVal = {};
1056
- var copyArgs = [].concat(args);
1057
-
1058
- var _loop = function _loop() {
1059
- var obj1 = isObj(copyArgs[0]) ? copyArgs[0] : {};
1060
- var obj2 = isObj(copyArgs[1]) ? copyArgs[1] : {};
1061
- preVal = Object.assign({}, obj1);
1062
- Object.keys(obj2).reduce(function (acc, key) {
1063
- var left = obj1[key];
1064
- var right = obj2[key]; // 左右一边为object
1065
-
1066
- if (isObj(left) || isObj(right)) {
1067
- // 两边同时为object
1068
- if (isObj(left) && isObj(right)) {
1069
- acc[key] = _this2.mergeSchemaAllOf(left, right);
1070
- } else {
1071
- // 其中一边为 object
1072
- var _ref = isObj(left) ? [left, right] : [right, left],
1073
- _ref2 = _slicedToArray(_ref, 2),
1074
- objTypeData = _ref2[0],
1075
- baseTypeData = _ref2[1];
1076
-
1077
- if (key === 'additionalProperties') {
1078
- acc[key] = baseTypeData === true ? objTypeData : false; // default false
1079
- } else {
1080
- acc[key] = objTypeData;
1081
- }
1082
- } // 一边为array
1083
-
1084
- } else if (Array.isArray(left) || Array.isArray(right)) {
1085
- // 同为数组取交集
1086
- if (Array.isArray(left) && Array.isArray(right)) {
1087
- // 数组里面嵌套对象不支持 因为我不知道该怎么合并
1088
- if (isObj(left[0]) || isObj(right[0])) {
1089
- throw new Error('暂不支持如上数组对象元素合并');
1090
- } // 交集
1091
-
1092
-
1093
- var intersectionArray = intersection(_toConsumableArray(left), _toConsumableArray(right)); // 没有交集
1094
-
1095
- if (intersectionArray.length <= 0) {
1096
- throw new Error('无法合并如上数据');
1097
- }
1098
-
1099
- if (intersectionArray.length === 0 && key === 'type') {
1100
- // 自己取出值
1101
- acc[key] = intersectionArray[0];
1102
- } else {
1103
- acc[key] = intersectionArray;
1104
- }
1105
- } else {
1106
- // 其中一边为 Array
1107
- // 查找包含关系
1108
- var _ref3 = Array.isArray(left) ? [left, right] : [right, left],
1109
- _ref4 = _slicedToArray(_ref3, 2),
1110
- arrayTypeData = _ref4[0],
1111
- _baseTypeData = _ref4[1]; // 空值直接合并另一边
1112
-
1113
-
1114
- if (_baseTypeData === undefined) {
1115
- acc[key] = arrayTypeData;
1116
- } else {
1117
- if (!arrayTypeData.includes(_baseTypeData)) {
1118
- throw new Error('无法合并如下数据');
1119
- }
1120
-
1121
- acc[key] = _baseTypeData;
1122
- }
1123
- }
1124
- } else if (left !== undefined && right !== undefined) {
1125
- // 两边都不是 undefined - 基础数据类型 string number boolean...
1126
- if (key === 'maxLength' || key === 'maximum' || key === 'maxItems' || key === 'exclusiveMaximum' || key === 'maxProperties') {
1127
- acc[key] = Math.min(left, right);
1128
- } else if (key === 'minLength' || key === 'minimum' || key === 'minItems' || key === 'exclusiveMinimum' || key === 'minProperties') {
1129
- acc[key] = Math.max(left, right);
1130
- } else if (key === 'multipleOf') {
1131
- // 获取最小公倍数
1132
- acc[key] = scm(left, right);
1133
- } else {
1134
- // if (left !== right) {
1135
- // throw new Error('无法合并如下数据');
1136
- // }
1137
- acc[key] = left;
1138
- }
1139
- } else {
1140
- // 一边为undefined
1141
- acc[key] = left === undefined ? right : left;
1142
- }
1143
-
1144
- return acc;
1145
- }, preVal); // 先进先出
1146
-
1147
- copyArgs.splice(0, 2, preVal);
1148
- };
1149
-
1150
- while (copyArgs.length >= 2) {
1151
- _loop();
1152
- }
1153
-
1154
- return preVal;
1155
- }
1156
- }, {
1157
1023
  key: "resolveRef",
1158
1024
  value: function resolveRef() {}
1159
1025
  }, {
@@ -1167,9 +1033,7 @@
1167
1033
  value: function resolveSchema(schema) {
1168
1034
  if (!isObj(schema)) return {};
1169
1035
 
1170
- if (hasOwnProperty(schema, 'allOf')) {
1171
- schema = this.resolveAllOf(schema);
1172
- }
1036
+ if (hasOwnProperty(schema, 'allOf')) ;
1173
1037
 
1174
1038
  if (hasOwnProperty(schema, '$ref')) ;
1175
1039
 
@@ -1179,7 +1043,7 @@
1179
1043
  }, {
1180
1044
  key: "getSchemaDefaultValue",
1181
1045
  value: function getSchemaDefaultValue(_schema) {
1182
- var _this3 = this;
1046
+ var _this = this;
1183
1047
 
1184
1048
  var schema = isObj(_schema) ? _schema : {};
1185
1049
 
@@ -1191,7 +1055,7 @@
1191
1055
  return Object.keys(schema.properties || {}).reduce(function (pre, key) {
1192
1056
  var _schema$properties;
1193
1057
 
1194
- var defaultValue = _this3.getSchemaDefaultValue((_schema$properties = schema.properties) === null || _schema$properties === void 0 ? void 0 : _schema$properties[key]);
1058
+ var defaultValue = _this.getSchemaDefaultValue((_schema$properties = schema.properties) === null || _schema$properties === void 0 ? void 0 : _schema$properties[key]);
1195
1059
 
1196
1060
  pre[key] = defaultValue;
1197
1061
  return pre;
@@ -1204,7 +1068,7 @@
1204
1068
  }
1205
1069
 
1206
1070
  return Array.isArray(schema.items) ? schema.items.map(function (item) {
1207
- return _this3.getSchemaDefaultValue(item);
1071
+ return _this.getSchemaDefaultValue(item);
1208
1072
  }) : [];
1209
1073
  }
1210
1074
 
@@ -1229,14 +1093,45 @@
1229
1093
 
1230
1094
  return type;
1231
1095
  }
1096
+ }, {
1097
+ key: "getUiProps",
1098
+ value: function getUiProps(props, schema) {
1099
+ if (!props || !props.startsWith('ui:')) {
1100
+ console.warn('ui props must start with ui:');
1101
+ }
1102
+
1103
+ return schema[props] || {};
1104
+ }
1232
1105
  }, {
1233
1106
  key: "getSchemaField",
1234
1107
  value: function getSchemaField(schema) {
1108
+ var _schema$oneOf, _schema$anyOf;
1109
+
1235
1110
  // 自定义Field组件
1236
1111
  var field = schema['ui:field'];
1237
1112
 
1238
1113
  if (field) {
1239
1114
  return field;
1115
+ } // oneOf field
1116
+
1117
+
1118
+ if ((_schema$oneOf = schema.oneOf) !== null && _schema$oneOf !== void 0 && _schema$oneOf.length) {
1119
+ return {
1120
+ name: registry.getField('composition'),
1121
+ props: {
1122
+ composition: 'oneOf'
1123
+ }
1124
+ };
1125
+ } // anyOf field
1126
+
1127
+
1128
+ if ((_schema$anyOf = schema.anyOf) !== null && _schema$anyOf !== void 0 && _schema$anyOf.length) {
1129
+ return {
1130
+ name: registry.getField('composition'),
1131
+ props: {
1132
+ composition: 'anyOf'
1133
+ }
1134
+ };
1240
1135
  } // default field
1241
1136
 
1242
1137
 
@@ -1282,9 +1177,9 @@
1282
1177
  }, {
1283
1178
  key: "getGroupWrap",
1284
1179
  value: function getGroupWrap(schema) {
1285
- var _ref5 = schema['ui:group'] || {},
1286
- name = _ref5.name,
1287
- groupVnode = _objectWithoutProperties(_ref5, _excluded2$1);
1180
+ var _ref = schema['ui:group'] || {},
1181
+ name = _ref.name,
1182
+ groupVnode = _objectWithoutProperties(_ref, _excluded$6);
1288
1183
 
1289
1184
  return _objectSpread2(_objectSpread2({}, groupVnode), {}, {
1290
1185
  name: registry.getComponent(name) || name || registry.getComponent('group')
@@ -1293,9 +1188,9 @@
1293
1188
  }, {
1294
1189
  key: "getUiComponent",
1295
1190
  value: function getUiComponent(schema) {
1296
- var _ref6 = schema['ui:component'] || {},
1297
- name = _ref6.name,
1298
- vnodeData = _objectWithoutProperties(_ref6, _excluded3);
1191
+ var _ref2 = schema['ui:component'] || {},
1192
+ name = _ref2.name,
1193
+ vnodeData = _objectWithoutProperties(_ref2, _excluded2$1);
1299
1194
 
1300
1195
  return _objectSpread2({
1301
1196
  name: registry.getComponent(name) || name
@@ -1304,6 +1199,8 @@
1304
1199
  }, {
1305
1200
  key: "getDefaultWidget",
1306
1201
  value: function getDefaultWidget(schema) {
1202
+ var _schema$oneOf2, _schema$oneOf3, _schema$anyOf2, _schema$anyOf3;
1203
+
1307
1204
  var type = this.getSchemaType(schema); // 默认转换策略
1308
1205
 
1309
1206
  var defaultComponent = null;
@@ -1318,6 +1215,14 @@
1318
1215
  defaultComponent = registry.getComponent('checkbox');
1319
1216
  }
1320
1217
 
1218
+ if (_typeof(type) !== 'object' && ((_schema$oneOf2 = schema.oneOf) !== null && _schema$oneOf2 !== void 0 && _schema$oneOf2.length && (_schema$oneOf3 = schema.oneOf) !== null && _schema$oneOf3 !== void 0 && _schema$oneOf3.every(function (item) {
1219
+ return item.const;
1220
+ }) || (_schema$anyOf2 = schema.anyOf) !== null && _schema$anyOf2 !== void 0 && _schema$anyOf2.length && (_schema$anyOf3 = schema.anyOf) !== null && _schema$anyOf3 !== void 0 && _schema$anyOf3.every(function (item) {
1221
+ return item.const;
1222
+ }))) {
1223
+ defaultComponent = registry.getComponent('select');
1224
+ }
1225
+
1321
1226
  if (defaultComponent) {
1322
1227
  return defaultComponent;
1323
1228
  } // 找不到对应组件就使用默认type对应的widget
@@ -1358,7 +1263,7 @@
1358
1263
 
1359
1264
  return _objectSpread2(_objectSpread2({}, options), {}, {
1360
1265
  // 0.1 兼容formItem设置 labelWidth 0 不生效问题
1361
- labelWidth: options.showTitle ? options.labelWidth || 150 : 0.1
1266
+ labelWidth: options.showTitle ? options.labelWidth : 0.1
1362
1267
  });
1363
1268
  } // 当前属性是否被依赖
1364
1269
 
@@ -1369,9 +1274,6 @@
1369
1274
  return Array.isArray(data[1]) && data[1].includes(name);
1370
1275
  });
1371
1276
  }
1372
- }, {
1373
- key: "orderProps",
1374
- value: function orderProps() {}
1375
1277
  }, {
1376
1278
  key: "resolveDefaultDatasource",
1377
1279
  value: function resolveDefaultDatasource(schema) {
@@ -1381,20 +1283,52 @@
1381
1283
  return schema['ui:component'].props.datasource;
1382
1284
  }
1383
1285
 
1384
- var data = [];
1385
-
1386
1286
  if (Array.isArray(schema.enum)) {
1387
- data = schema.enum;
1388
- } else if (Array.isArray((_schema$items2 = schema.items) === null || _schema$items2 === void 0 ? void 0 : _schema$items2.enum)) {
1389
- data = schema.items.enum || [];
1287
+ var data = schema.enum;
1288
+ return data.map(function (value) {
1289
+ return {
1290
+ value: value,
1291
+ label: value
1292
+ };
1293
+ });
1390
1294
  }
1391
1295
 
1392
- return data.map(function (value) {
1393
- return {
1394
- value: value,
1395
- label: value
1396
- };
1397
- });
1296
+ if (Array.isArray((_schema$items2 = schema.items) === null || _schema$items2 === void 0 ? void 0 : _schema$items2.enum)) {
1297
+ var _data = schema.items.enum || [];
1298
+
1299
+ return _data.map(function (value) {
1300
+ return {
1301
+ value: value,
1302
+ label: value
1303
+ };
1304
+ });
1305
+ }
1306
+
1307
+ if (_typeof(schema.type) !== 'object' && schema.oneOf && schema.oneOf.every(function (item) {
1308
+ return item.const;
1309
+ })) {
1310
+ var _data2 = schema.oneOf.map(function (item) {
1311
+ return {
1312
+ value: item.const,
1313
+ label: item.title || item.const
1314
+ };
1315
+ });
1316
+
1317
+ return _data2;
1318
+ }
1319
+
1320
+ if (_typeof(schema.type) !== 'object' && schema.anyOf && schema.anyOf.every(function (item) {
1321
+ return item.const;
1322
+ })) {
1323
+ var _data3 = schema.anyOf.map(function (item) {
1324
+ return {
1325
+ value: item.const,
1326
+ label: item.title || item.const
1327
+ };
1328
+ });
1329
+
1330
+ return _data3;
1331
+ }
1398
1332
  }
1399
1333
  }]);
1400
1334
 
@@ -1652,7 +1586,7 @@
1652
1586
 
1653
1587
  Path.separator = '.';
1654
1588
 
1655
- var _excluded$4 = ["params", "responseType", "method", "headers", "responseParse"];
1589
+ var _excluded$5 = ["params", "responseType", "method", "headers", "responseParse"];
1656
1590
  var methodsWithoutData = ['GET', 'HEAD', 'OPTIONS', 'DELETE'];
1657
1591
  var defaultConfig = {
1658
1592
  responseType: 'json',
@@ -1690,7 +1624,7 @@
1690
1624
  switch (_context.prev = _context.next) {
1691
1625
  case 0:
1692
1626
  config = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
1693
- _mergeDeep = mergeDeep(defaultConfig, config), params = _mergeDeep.params, _mergeDeep$responseTy = _mergeDeep.responseType, responseType = _mergeDeep$responseTy === void 0 ? 'json' : _mergeDeep$responseTy, _mergeDeep$method = _mergeDeep.method, method = _mergeDeep$method === void 0 ? 'GET' : _mergeDeep$method, _mergeDeep$headers = _mergeDeep.headers, headers = _mergeDeep$headers === void 0 ? {} : _mergeDeep$headers, responseParse = _mergeDeep.responseParse, reset = _objectWithoutProperties(_mergeDeep, _excluded$4);
1627
+ _mergeDeep = mergeDeep(defaultConfig, config), params = _mergeDeep.params, _mergeDeep$responseTy = _mergeDeep.responseType, responseType = _mergeDeep$responseTy === void 0 ? 'json' : _mergeDeep$responseTy, _mergeDeep$method = _mergeDeep.method, method = _mergeDeep$method === void 0 ? 'GET' : _mergeDeep$method, _mergeDeep$headers = _mergeDeep.headers, headers = _mergeDeep$headers === void 0 ? {} : _mergeDeep$headers, responseParse = _mergeDeep.responseParse, reset = _objectWithoutProperties(_mergeDeep, _excluded$5);
1694
1628
  requestURL = url; // 处理参数
1695
1629
 
1696
1630
  if (methodsWithoutData.includes(method.toUpperCase())) {
@@ -1868,6 +1802,10 @@
1868
1802
  validator: function validator(value) {
1869
1803
  return ['value', 'custom'].includes(value);
1870
1804
  }
1805
+ },
1806
+ labelWidth: {
1807
+ type: Number,
1808
+ default: 150
1871
1809
  }
1872
1810
  };
1873
1811
 
@@ -1987,7 +1925,7 @@
1987
1925
  }
1988
1926
  });
1989
1927
 
1990
- var _excluded$3 = ["name"];
1928
+ var _excluded$4 = ["name"];
1991
1929
  var ObjectField = Vue__default["default"].extend({
1992
1930
  name: 'ObjectField',
1993
1931
  functional: true,
@@ -2018,7 +1956,7 @@
2018
1956
 
2019
1957
  var _Schema$getGroupWrap = Schema.getGroupWrap(schema),
2020
1958
  name = _Schema$getGroupWrap.name,
2021
- vnodeData = _objectWithoutProperties(_Schema$getGroupWrap, _excluded$3); // todo: wrap组件不要透传ctx.data,不然会引起组件无限递归问题
1959
+ vnodeData = _objectWithoutProperties(_Schema$getGroupWrap, _excluded$4); // todo: wrap组件不要透传ctx.data,不然会引起组件无限递归问题
2022
1960
 
2023
1961
 
2024
1962
  return h(name, mergeDeep({
@@ -2321,7 +2259,9 @@
2321
2259
  }
2322
2260
  }
2323
2261
 
2324
- delete this.widgetMap[path];
2262
+ if (node.instance === instance) {
2263
+ delete this.widgetMap[path];
2264
+ }
2325
2265
  }
2326
2266
  }]);
2327
2267
 
@@ -9656,9 +9596,457 @@
9656
9596
 
9657
9597
  var Ajv = /*@__PURE__*/getDefaultExportFromCjs(ajv$1.exports);
9658
9598
 
9599
+ var dist = {exports: {}};
9600
+
9601
+ var formats = {};
9602
+
9603
+ (function (exports) {
9604
+ Object.defineProperty(exports, "__esModule", { value: true });
9605
+ exports.formatNames = exports.fastFormats = exports.fullFormats = void 0;
9606
+ function fmtDef(validate, compare) {
9607
+ return { validate, compare };
9608
+ }
9609
+ exports.fullFormats = {
9610
+ // date: http://tools.ietf.org/html/rfc3339#section-5.6
9611
+ date: fmtDef(date, compareDate),
9612
+ // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
9613
+ time: fmtDef(time, compareTime),
9614
+ "date-time": fmtDef(date_time, compareDateTime),
9615
+ // duration: https://tools.ietf.org/html/rfc3339#appendix-A
9616
+ duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
9617
+ uri,
9618
+ "uri-reference": /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,
9619
+ // uri-template: https://tools.ietf.org/html/rfc6570
9620
+ "uri-template": /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,
9621
+ // For the source: https://gist.github.com/dperini/729294
9622
+ // For test cases: https://mathiasbynens.be/demo/url-regex
9623
+ url: /^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,
9624
+ email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
9625
+ hostname: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,
9626
+ // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
9627
+ ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
9628
+ ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,
9629
+ regex,
9630
+ // uuid: http://tools.ietf.org/html/rfc4122
9631
+ uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,
9632
+ // JSON-pointer: https://tools.ietf.org/html/rfc6901
9633
+ // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
9634
+ "json-pointer": /^(?:\/(?:[^~/]|~0|~1)*)*$/,
9635
+ "json-pointer-uri-fragment": /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,
9636
+ // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
9637
+ "relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
9638
+ // the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types
9639
+ // byte: https://github.com/miguelmota/is-base64
9640
+ byte,
9641
+ // signed 32 bit integer
9642
+ int32: { type: "number", validate: validateInt32 },
9643
+ // signed 64 bit integer
9644
+ int64: { type: "number", validate: validateInt64 },
9645
+ // C-type float
9646
+ float: { type: "number", validate: validateNumber },
9647
+ // C-type double
9648
+ double: { type: "number", validate: validateNumber },
9649
+ // hint to the UI to hide input strings
9650
+ password: true,
9651
+ // unchecked string payload
9652
+ binary: true,
9653
+ };
9654
+ exports.fastFormats = {
9655
+ ...exports.fullFormats,
9656
+ date: fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\d$/, compareDate),
9657
+ time: fmtDef(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i, compareTime),
9658
+ "date-time": fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i, compareDateTime),
9659
+ // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
9660
+ uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
9661
+ "uri-reference": /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
9662
+ // email (sources from jsen validator):
9663
+ // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
9664
+ // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'wilful violation')
9665
+ email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
9666
+ };
9667
+ exports.formatNames = Object.keys(exports.fullFormats);
9668
+ function isLeapYear(year) {
9669
+ // https://tools.ietf.org/html/rfc3339#appendix-C
9670
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
9671
+ }
9672
+ const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
9673
+ const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
9674
+ function date(str) {
9675
+ // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
9676
+ const matches = DATE.exec(str);
9677
+ if (!matches)
9678
+ return false;
9679
+ const year = +matches[1];
9680
+ const month = +matches[2];
9681
+ const day = +matches[3];
9682
+ return (month >= 1 &&
9683
+ month <= 12 &&
9684
+ day >= 1 &&
9685
+ day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month]));
9686
+ }
9687
+ function compareDate(d1, d2) {
9688
+ if (!(d1 && d2))
9689
+ return undefined;
9690
+ if (d1 > d2)
9691
+ return 1;
9692
+ if (d1 < d2)
9693
+ return -1;
9694
+ return 0;
9695
+ }
9696
+ const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
9697
+ function time(str, withTimeZone) {
9698
+ const matches = TIME.exec(str);
9699
+ if (!matches)
9700
+ return false;
9701
+ const hour = +matches[1];
9702
+ const minute = +matches[2];
9703
+ const second = +matches[3];
9704
+ const timeZone = matches[5];
9705
+ return (((hour <= 23 && minute <= 59 && second <= 59) ||
9706
+ (hour === 23 && minute === 59 && second === 60)) &&
9707
+ (!withTimeZone || timeZone !== ""));
9708
+ }
9709
+ function compareTime(t1, t2) {
9710
+ if (!(t1 && t2))
9711
+ return undefined;
9712
+ const a1 = TIME.exec(t1);
9713
+ const a2 = TIME.exec(t2);
9714
+ if (!(a1 && a2))
9715
+ return undefined;
9716
+ t1 = a1[1] + a1[2] + a1[3] + (a1[4] || "");
9717
+ t2 = a2[1] + a2[2] + a2[3] + (a2[4] || "");
9718
+ if (t1 > t2)
9719
+ return 1;
9720
+ if (t1 < t2)
9721
+ return -1;
9722
+ return 0;
9723
+ }
9724
+ const DATE_TIME_SEPARATOR = /t|\s/i;
9725
+ function date_time(str) {
9726
+ // http://tools.ietf.org/html/rfc3339#section-5.6
9727
+ const dateTime = str.split(DATE_TIME_SEPARATOR);
9728
+ return dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1], true);
9729
+ }
9730
+ function compareDateTime(dt1, dt2) {
9731
+ if (!(dt1 && dt2))
9732
+ return undefined;
9733
+ const [d1, t1] = dt1.split(DATE_TIME_SEPARATOR);
9734
+ const [d2, t2] = dt2.split(DATE_TIME_SEPARATOR);
9735
+ const res = compareDate(d1, d2);
9736
+ if (res === undefined)
9737
+ return undefined;
9738
+ return res || compareTime(t1, t2);
9739
+ }
9740
+ const NOT_URI_FRAGMENT = /\/|:/;
9741
+ const URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
9742
+ function uri(str) {
9743
+ // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
9744
+ return NOT_URI_FRAGMENT.test(str) && URI.test(str);
9745
+ }
9746
+ const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
9747
+ function byte(str) {
9748
+ BYTE.lastIndex = 0;
9749
+ return BYTE.test(str);
9750
+ }
9751
+ const MIN_INT32 = -(2 ** 31);
9752
+ const MAX_INT32 = 2 ** 31 - 1;
9753
+ function validateInt32(value) {
9754
+ return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32;
9755
+ }
9756
+ function validateInt64(value) {
9757
+ // JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64
9758
+ return Number.isInteger(value);
9759
+ }
9760
+ function validateNumber() {
9761
+ return true;
9762
+ }
9763
+ const Z_ANCHOR = /[^\\]\\Z/;
9764
+ function regex(str) {
9765
+ if (Z_ANCHOR.test(str))
9766
+ return false;
9767
+ try {
9768
+ new RegExp(str);
9769
+ return true;
9770
+ }
9771
+ catch (e) {
9772
+ return false;
9773
+ }
9774
+ }
9775
+
9776
+ }(formats));
9777
+
9778
+ var limit = {};
9779
+
9780
+ (function (exports) {
9781
+ Object.defineProperty(exports, "__esModule", { value: true });
9782
+ exports.formatLimitDefinition = void 0;
9783
+ const ajv_1 = ajv$1.exports;
9784
+ const codegen_1 = codegen;
9785
+ const ops = codegen_1.operators;
9786
+ const KWDs = {
9787
+ formatMaximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
9788
+ formatMinimum: { okStr: ">=", ok: ops.GTE, fail: ops.LT },
9789
+ formatExclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
9790
+ formatExclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE },
9791
+ };
9792
+ const error = {
9793
+ message: ({ keyword, schemaCode }) => codegen_1.str `should be ${KWDs[keyword].okStr} ${schemaCode}`,
9794
+ params: ({ keyword, schemaCode }) => codegen_1._ `{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`,
9795
+ };
9796
+ exports.formatLimitDefinition = {
9797
+ keyword: Object.keys(KWDs),
9798
+ type: "string",
9799
+ schemaType: "string",
9800
+ $data: true,
9801
+ error,
9802
+ code(cxt) {
9803
+ const { gen, data, schemaCode, keyword, it } = cxt;
9804
+ const { opts, self } = it;
9805
+ if (!opts.validateFormats)
9806
+ return;
9807
+ const fCxt = new ajv_1.KeywordCxt(it, self.RULES.all.format.definition, "format");
9808
+ if (fCxt.$data)
9809
+ validate$DataFormat();
9810
+ else
9811
+ validateFormat();
9812
+ function validate$DataFormat() {
9813
+ const fmts = gen.scopeValue("formats", {
9814
+ ref: self.formats,
9815
+ code: opts.code.formats,
9816
+ });
9817
+ const fmt = gen.const("fmt", codegen_1._ `${fmts}[${fCxt.schemaCode}]`);
9818
+ cxt.fail$data(codegen_1.or(codegen_1._ `typeof ${fmt} != "object"`, codegen_1._ `${fmt} instanceof RegExp`, codegen_1._ `typeof ${fmt}.compare != "function"`, compareCode(fmt)));
9819
+ }
9820
+ function validateFormat() {
9821
+ const format = fCxt.schema;
9822
+ const fmtDef = self.formats[format];
9823
+ if (!fmtDef || fmtDef === true)
9824
+ return;
9825
+ if (typeof fmtDef != "object" ||
9826
+ fmtDef instanceof RegExp ||
9827
+ typeof fmtDef.compare != "function") {
9828
+ throw new Error(`"${keyword}": format "${format}" does not define "compare" function`);
9829
+ }
9830
+ const fmt = gen.scopeValue("formats", {
9831
+ key: format,
9832
+ ref: fmtDef,
9833
+ code: opts.code.formats ? codegen_1._ `${opts.code.formats}${codegen_1.getProperty(format)}` : undefined,
9834
+ });
9835
+ cxt.fail$data(compareCode(fmt));
9836
+ }
9837
+ function compareCode(fmt) {
9838
+ return codegen_1._ `${fmt}.compare(${data}, ${schemaCode}) ${KWDs[keyword].fail} 0`;
9839
+ }
9840
+ },
9841
+ dependencies: ["format"],
9842
+ };
9843
+ const formatLimitPlugin = (ajv) => {
9844
+ ajv.addKeyword(exports.formatLimitDefinition);
9845
+ return ajv;
9846
+ };
9847
+ exports.default = formatLimitPlugin;
9848
+
9849
+ }(limit));
9850
+
9851
+ (function (module, exports) {
9852
+ Object.defineProperty(exports, "__esModule", { value: true });
9853
+ const formats_1 = formats;
9854
+ const limit_1 = limit;
9855
+ const codegen_1 = codegen;
9856
+ const fullName = new codegen_1.Name("fullFormats");
9857
+ const fastName = new codegen_1.Name("fastFormats");
9858
+ const formatsPlugin = (ajv, opts = { keywords: true }) => {
9859
+ if (Array.isArray(opts)) {
9860
+ addFormats(ajv, opts, formats_1.fullFormats, fullName);
9861
+ return ajv;
9862
+ }
9863
+ const [formats, exportName] = opts.mode === "fast" ? [formats_1.fastFormats, fastName] : [formats_1.fullFormats, fullName];
9864
+ const list = opts.formats || formats_1.formatNames;
9865
+ addFormats(ajv, list, formats, exportName);
9866
+ if (opts.keywords)
9867
+ limit_1.default(ajv);
9868
+ return ajv;
9869
+ };
9870
+ formatsPlugin.get = (name, mode = "full") => {
9871
+ const formats = mode === "fast" ? formats_1.fastFormats : formats_1.fullFormats;
9872
+ const f = formats[name];
9873
+ if (!f)
9874
+ throw new Error(`Unknown format "${name}"`);
9875
+ return f;
9876
+ };
9877
+ function addFormats(ajv, list, fs, exportName) {
9878
+ var _a;
9879
+ var _b;
9880
+ (_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : (_b.formats = codegen_1._ `require("ajv-formats/dist/formats").${exportName}`);
9881
+ for (const f of list)
9882
+ ajv.addFormat(f, fs[f]);
9883
+ }
9884
+ module.exports = exports = formatsPlugin;
9885
+ Object.defineProperty(exports, "__esModule", { value: true });
9886
+ exports.default = formatsPlugin;
9887
+
9888
+ }(dist, dist.exports));
9889
+
9890
+ var addFormats = /*@__PURE__*/getDefaultExportFromCjs(dist.exports);
9891
+
9892
+ var zh = function localize_zh(errors) {
9893
+ if (!(errors && errors.length)) return
9894
+ for (const e of errors) {
9895
+ let out;
9896
+ switch (e.keyword) {
9897
+ case "additionalItems":
9898
+ case "items":
9899
+ out = "";
9900
+ var n = e.params.limit;
9901
+ out += "不允许超过" + n + "个元素";
9902
+ break
9903
+ case "additionalProperties":
9904
+ out = "不允许有额外的属性";
9905
+ break
9906
+ case "anyOf":
9907
+ out = "数据应为 anyOf 所指定的其中一个";
9908
+ break
9909
+ case "const":
9910
+ out = "应当等于常量";
9911
+ break
9912
+ case "contains":
9913
+ out = "应当包含一个有效项";
9914
+ break
9915
+ case "dependencies":
9916
+ case "dependentRequired":
9917
+ out = "";
9918
+ var n = e.params.depsCount;
9919
+ out += "应当拥有属性" + e.params.property + "的依赖属性" + e.params.deps;
9920
+ break
9921
+ case "discriminator":
9922
+ switch (e.params.error) {
9923
+ case "tag":
9924
+ out = '标签 "' + e.params.tag + '" 的类型必须为字符串';
9925
+ break
9926
+ case "mapping":
9927
+ out = '标签 "' + e.params.tag + '" 的值必须在 oneOf 之中';
9928
+ break
9929
+ default:
9930
+ out = '应当通过 "' + e.keyword + ' 关键词校验"';
9931
+ }
9932
+ break
9933
+ case "enum":
9934
+ out = "应当是预设定的枚举值之一";
9935
+ break
9936
+ case "false schema":
9937
+ out = "布尔模式出错";
9938
+ break
9939
+ case "format":
9940
+ out = '应当匹配格式 "' + e.params.format + '"';
9941
+ break
9942
+ case "formatMaximum":
9943
+ case "formatExclusiveMaximum":
9944
+ out = "";
9945
+ var cond = e.params.comparison + " " + e.params.limit;
9946
+ out += "应当是 " + cond;
9947
+ break
9948
+ case "formatMinimum":
9949
+ case "formatExclusiveMinimum":
9950
+ out = "";
9951
+ var cond = e.params.comparison + " " + e.params.limit;
9952
+ out += "应当是 " + cond;
9953
+ break
9954
+ case "if":
9955
+ out = '应当匹配模式 "' + e.params.failingKeyword + '" ';
9956
+ break
9957
+ case "maximum":
9958
+ case "exclusiveMaximum":
9959
+ out = "";
9960
+ var cond = e.params.comparison + " " + e.params.limit;
9961
+ out += "应当为 " + cond;
9962
+ break
9963
+ case "maxItems":
9964
+ out = "";
9965
+ var n = e.params.limit;
9966
+ out += "不应多于 " + n + " 个项";
9967
+ break
9968
+ case "maxLength":
9969
+ out = "";
9970
+ var n = e.params.limit;
9971
+ out += "不应多于 " + n + " 个字符";
9972
+ break
9973
+ case "maxProperties":
9974
+ out = "";
9975
+ var n = e.params.limit;
9976
+ out += "不应有多于 " + n + " 个属性";
9977
+ break
9978
+ case "minimum":
9979
+ case "exclusiveMinimum":
9980
+ out = "";
9981
+ var cond = e.params.comparison + " " + e.params.limit;
9982
+ out += "应当为 " + cond;
9983
+ break
9984
+ case "minItems":
9985
+ out = "";
9986
+ var n = e.params.limit;
9987
+ out += "不应少于 " + n + " 个项";
9988
+ break
9989
+ case "minLength":
9990
+ out = "";
9991
+ var n = e.params.limit;
9992
+ out += "不应少于 " + n + " 个字符";
9993
+ break
9994
+ case "minProperties":
9995
+ out = "";
9996
+ var n = e.params.limit;
9997
+ out += "不应有少于 " + n + " 个属性";
9998
+ break
9999
+ case "multipleOf":
10000
+ out = "应当是 " + e.params.multipleOf + " 的整数倍";
10001
+ break
10002
+ case "not":
10003
+ out = '不应当匹配 "not" schema';
10004
+ break
10005
+ case "oneOf":
10006
+ out = '只能匹配一个 "oneOf" 中的 schema';
10007
+ break
10008
+ case "pattern":
10009
+ out = '应当匹配模式 "' + e.params.pattern + '"';
10010
+ break
10011
+ case "patternRequired":
10012
+ out = "应当有属性匹配模式 " + e.params.missingPattern;
10013
+ break
10014
+ case "propertyNames":
10015
+ out = "属性名 无效";
10016
+ break
10017
+ case "required":
10018
+ out = "应当有必需属性 " + e.params.missingProperty;
10019
+ break
10020
+ case "type":
10021
+ out = "应当是 " + e.params.type + " 类型";
10022
+ break
10023
+ case "unevaluatedItems":
10024
+ out = "";
10025
+ var n = e.params.len;
10026
+ out += " 不允许有超过 " + n + " 个元素";
10027
+ break
10028
+ case "unevaluatedProperties":
10029
+ out = "不允许存在未求值的属性";
10030
+ break
10031
+ case "uniqueItems":
10032
+ out =
10033
+ "不应当含有重复项 (第 " +
10034
+ e.params.j +
10035
+ " 项与第 " +
10036
+ e.params.i +
10037
+ " 项是重复的)";
10038
+ break
10039
+ default:
10040
+ out = '应当通过 "' + e.keyword + ' 关键词校验"';
10041
+ }
10042
+ e.message = out;
10043
+ }
10044
+ };
10045
+
9659
10046
  var ajv = new Ajv({
9660
10047
  strict: false
9661
- }); // 校验器 key
10048
+ });
10049
+ addFormats(ajv); // 校验器 key
9662
10050
 
9663
10051
  var VALIDATOR = 'validator';
9664
10052
  var OWN_RULE_PROPERTY = 'ui:rules';
@@ -9804,16 +10192,14 @@
9804
10192
  var schemaValid = schemaValidate(value);
9805
10193
 
9806
10194
  if (!schemaValid) {
9807
- var _schemaValidate$error, _schemaValidate$error2;
9808
-
9809
- setWidgetErrorTips(path, true, (_schemaValidate$error = schemaValidate.errors) === null || _schemaValidate$error === void 0 ? void 0 : _schemaValidate$error.map(function (err) {
9810
- return err.message;
9811
- }));
10195
+ zh(schemaValidate.errors);
10196
+ var errorsText = ajv.errorsText(schemaValidate.errors, {
10197
+ separator: '\n'
10198
+ });
10199
+ setWidgetErrorTips(path, true, errorsText);
9812
10200
  return {
9813
10201
  result: false,
9814
- message: (_schemaValidate$error2 = schemaValidate.errors) === null || _schemaValidate$error2 === void 0 ? void 0 : _schemaValidate$error2.map(function (err) {
9815
- return err.message;
9816
- }).join(','),
10202
+ message: errorsText,
9817
10203
  path: path
9818
10204
  };
9819
10205
  } // 自定义规则校验
@@ -10035,7 +10421,7 @@
10035
10421
  }();
10036
10422
  var events = new FormEvent();
10037
10423
 
10038
- var _excluded$2 = ["url", "params"],
10424
+ var _excluded$3 = ["url", "params"],
10039
10425
  _excluded2 = ["name"];
10040
10426
  var Widget = Vue__default["default"].extend({
10041
10427
  name: 'Widget',
@@ -10059,7 +10445,9 @@
10059
10445
  return widgetTree.widgetMap[this.path];
10060
10446
  },
10061
10447
  parent: function parent() {
10062
- return this.widgetNode.parent;
10448
+ var _this$widgetNode;
10449
+
10450
+ return (_this$widgetNode = this.widgetNode) === null || _this$widgetNode === void 0 ? void 0 : _this$widgetNode.parent;
10063
10451
  }
10064
10452
  },
10065
10453
  watch: {
@@ -10141,7 +10529,7 @@
10141
10529
  break;
10142
10530
  }
10143
10531
 
10144
- url = xhrConfig.url, params = xhrConfig.params, reset = _objectWithoutProperties(xhrConfig, _excluded$2);
10532
+ url = xhrConfig.url, params = xhrConfig.params, reset = _objectWithoutProperties(xhrConfig, _excluded$3);
10145
10533
  _this3$httpAdapter = _this3.httpAdapter, _this3$httpAdapter$re = _this3$httpAdapter.request, http = _this3$httpAdapter$re === void 0 ? request : _this3$httpAdapter$re, responseParse = _this3$httpAdapter.responseParse;
10146
10534
  _context.prev = 4;
10147
10535
  _this3.loading = true;
@@ -10201,8 +10589,7 @@
10201
10589
  value: this.value
10202
10590
  });
10203
10591
 
10204
- var _self = this;
10205
-
10592
+ var self = this;
10206
10593
  var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.schema);
10207
10594
  var widgetEvents = ((_events$callbacks = events.callbacks) === null || _events$callbacks === void 0 ? void 0 : _events$callbacks[this.path]) || {}; // 当前state属性优先级最高
10208
10595
 
@@ -10211,16 +10598,19 @@
10211
10598
  })) !== null && _this$$scopedSlots$de !== void 0 ? _this$$scopedSlots$de : h(widgetName, mergeDeep({
10212
10599
  props: _objectSpread2({}, widgetProps),
10213
10600
  attrs: _objectSpread2({}, uiVnodeData.props || {}),
10601
+ class: {
10602
+ pr20: this.removeable
10603
+ },
10214
10604
  on: _objectSpread2(_objectSpread2({}, widgetEvents), {}, {
10215
10605
  input: [].concat(_toConsumableArray(widgetEvents.input || []), [function (value) {
10216
10606
  // 所有组件widget必须实现input事件,用于v-model时更新表单数据
10217
- _self.$emit('input', {
10218
- path: _self.path,
10607
+ self.$emit('input', {
10608
+ path: self.path,
10219
10609
  value: value
10220
10610
  });
10221
10611
  }]),
10222
10612
  click: function click() {
10223
- reactionDispatch(_self.path, 'effect/click');
10613
+ reactionDispatch(self.path, 'effect/click');
10224
10614
  }
10225
10615
  })
10226
10616
  }, mergeDeep(uiVnodeData, {
@@ -10238,12 +10628,12 @@
10238
10628
  return h('span', {
10239
10629
  class: ['bk-schema-form-group-delete'],
10240
10630
  style: {
10241
- right: '-20px',
10631
+ right: '0px',
10242
10632
  top: '0px'
10243
10633
  },
10244
10634
  on: {
10245
10635
  click: function click() {
10246
- _self.$emit('remove', _self.path);
10636
+ self.$emit('remove', self.path);
10247
10637
  }
10248
10638
  }
10249
10639
  }, [h('i', {
@@ -10321,7 +10711,7 @@
10321
10711
  }
10322
10712
  });
10323
10713
 
10324
- var _excluded$1 = ["name"];
10714
+ var _excluded$2 = ["name"];
10325
10715
 
10326
10716
  var ArrayWidget = Vue__default["default"].extend({
10327
10717
  name: 'ArrayWidget',
@@ -10334,13 +10724,14 @@
10334
10724
  handleFillItem: function handleFillItem() {
10335
10725
  var _this$schema$minItems = this.schema.minItems,
10336
10726
  minItems = _this$schema$minItems === void 0 ? 0 : _this$schema$minItems;
10727
+ var valueLen = this.value ? this.value.length : 0;
10337
10728
 
10338
- if (this.value.length < minItems) {
10729
+ if (valueLen < minItems) {
10339
10730
  var data = Schema.getSchemaDefaultValue(this.schema.items);
10340
- var remainData = new Array(minItems - this.value.length).fill(data);
10731
+ var remainData = new Array(minItems - valueLen).fill(data);
10341
10732
  this.$emit('input', {
10342
10733
  path: this.path,
10343
- value: [].concat(_toConsumableArray(this.value), _toConsumableArray(remainData))
10734
+ value: [].concat(_toConsumableArray(this.value || []), _toConsumableArray(remainData))
10344
10735
  });
10345
10736
  }
10346
10737
  },
@@ -10368,12 +10759,11 @@
10368
10759
  render: function render(h) {
10369
10760
  var _this = this;
10370
10761
 
10371
- var _self = this;
10372
-
10762
+ var self = this;
10373
10763
  var arrVnodeList = (Array.isArray(this.value) ? this.value : []).map(function (_, index) {
10374
10764
  var curPath = Path.getCurPath(_this.path, index);
10375
10765
  return h(SchemaField, {
10376
- key: curPath,
10766
+ key: "".concat(curPath, "-").concat(_this.value.length),
10377
10767
  props: _objectSpread2(_objectSpread2({}, _this.$props), {}, {
10378
10768
  schema: _this.schema.items,
10379
10769
  path: curPath,
@@ -10385,7 +10775,7 @@
10385
10775
  }),
10386
10776
  on: _objectSpread2(_objectSpread2({}, _this.$listeners), {}, {
10387
10777
  remove: function remove(path) {
10388
- _self.handleDeleteItem(path);
10778
+ self.handleDeleteItem(path);
10389
10779
  }
10390
10780
  })
10391
10781
  });
@@ -10393,7 +10783,7 @@
10393
10783
 
10394
10784
  var _Schema$getGroupWrap = Schema.getGroupWrap(this.schema),
10395
10785
  name = _Schema$getGroupWrap.name,
10396
- vnode = _objectWithoutProperties(_Schema$getGroupWrap, _excluded$1);
10786
+ vnode = _objectWithoutProperties(_Schema$getGroupWrap, _excluded$2);
10397
10787
 
10398
10788
  return h(name, mergeDeep({
10399
10789
  props: _objectSpread2(_objectSpread2({}, this.$props), {}, {
@@ -10402,20 +10792,24 @@
10402
10792
 
10403
10793
  }),
10404
10794
  style: _objectSpread2({}, this.layout.item || {})
10405
- }, vnode), [].concat(_toConsumableArray(arrVnodeList), [h('span', {
10795
+ }, vnode), [].concat(_toConsumableArray(arrVnodeList), [h(registry.getBaseWidget('form-item'), {
10796
+ class: {
10797
+ 'bk-schema-form-item-auto-height': true
10798
+ }
10799
+ }, [h('span', {
10406
10800
  class: ['bk-schema-form-group-add'],
10407
10801
  on: {
10408
10802
  click: function click() {
10409
- _self.handleAddItem();
10803
+ self.handleAddItem();
10410
10804
  }
10411
10805
  }
10412
10806
  }, [h('i', {
10413
10807
  class: ['bk-icon icon-plus-circle-shape mr5']
10414
- }), '添加'])]));
10808
+ }), '添加'])])]));
10415
10809
  }
10416
10810
  });
10417
10811
 
10418
- var _excluded = ["name"];
10812
+ var _excluded$1 = ["name"];
10419
10813
  var ArrayField = Vue__default["default"].extend({
10420
10814
  name: 'ArrayField',
10421
10815
  functional: true,
@@ -10445,7 +10839,7 @@
10445
10839
  if (Schema.isTupleArray(schema)) {
10446
10840
  var _Schema$getGroupWrap = Schema.getGroupWrap(schema),
10447
10841
  name = _Schema$getGroupWrap.name,
10448
- vnode = _objectWithoutProperties(_Schema$getGroupWrap, _excluded);
10842
+ vnode = _objectWithoutProperties(_Schema$getGroupWrap, _excluded$1);
10449
10843
 
10450
10844
  var tupleVnodeList = schema.items.map(function (item, index) {
10451
10845
  return h(SchemaField, _objectSpread2(_objectSpread2({}, ctx.data), {}, {
@@ -10511,6 +10905,136 @@
10511
10905
  }
10512
10906
  });
10513
10907
 
10908
+ var _excluded = ["name"];
10909
+ var CompositionField = Vue__default["default"].extend({
10910
+ name: 'CompositionField',
10911
+ props: _objectSpread2(_objectSpread2({}, props), {}, {
10912
+ composition: {
10913
+ type: String,
10914
+ default: 'oneOf',
10915
+ validator: function validator(value) {
10916
+ return ['oneOf', 'anyOf'].includes(value);
10917
+ }
10918
+ }
10919
+ }),
10920
+ data: function data() {
10921
+ return {
10922
+ activeIndex: -1
10923
+ };
10924
+ },
10925
+ created: function created() {
10926
+ var _this = this;
10927
+
10928
+ // 初始化默认 composition 选项
10929
+ var compositionList = this.schema[this.composition] || []; // todo 没有required选项时回显不成功
10930
+
10931
+ var index = compositionList.findIndex(function (item) {
10932
+ return ajv.validate(item, _this.value);
10933
+ });
10934
+ this.activeIndex = index > -1 ? index : 0;
10935
+ },
10936
+ render: function render(h) {
10937
+ var _this2 = this,
10938
+ _vnodeData$props;
10939
+
10940
+ var compositionList = this.schema[this.composition] || [];
10941
+ var schemaList = compositionList.map(function (item) {
10942
+ var data = mergeDeep({}, _this2.schema, item);
10943
+ delete data[_this2.composition];
10944
+ return data;
10945
+ });
10946
+
10947
+ var _Schema$getUiProps = Schema.getUiProps("ui:".concat(this.composition), this.schema),
10948
+ _Schema$getUiProps$na = _Schema$getUiProps.name,
10949
+ com = _Schema$getUiProps$na === void 0 ? 'radio' : _Schema$getUiProps$na,
10950
+ vnodeData = _objectWithoutProperties(_Schema$getUiProps, _excluded);
10951
+
10952
+ var isConst = _typeof(this.schema.type) !== 'object' && schemaList.every(function (item) {
10953
+ return item.const;
10954
+ });
10955
+
10956
+ if (isConst) {
10957
+ // 全是常量
10958
+ return h(Widget, {
10959
+ props: _objectSpread2({}, this.$props),
10960
+ scopedSlots: _objectSpread2({}, this.$scopedSlots),
10961
+ on: _objectSpread2({}, this.$listeners)
10962
+ });
10963
+ }
10964
+
10965
+ var _Schema$getUiProps2 = Schema.getUiProps('ui:composition', this.schema),
10966
+ compositionVnodeData = _extends$1({}, _Schema$getUiProps2);
10967
+
10968
+ return h(registry.getComponent('group'), mergeDeep({
10969
+ props: _objectSpread2(_objectSpread2({}, this.$props), {}, {
10970
+ rootData: this.rootData,
10971
+ schema: this.schema,
10972
+ value: Path.getPathVal(this.rootData, this.path),
10973
+ path: this.path
10974
+ }),
10975
+ on: {
10976
+ remove: function remove() {
10977
+ _this2.$emit('remove', _this2.path);
10978
+ }
10979
+ }
10980
+ }, compositionVnodeData), [// anyOf component
10981
+ h(registry.getBaseWidget('form-item'), {
10982
+ props: {
10983
+ label: (_vnodeData$props = vnodeData.props) === null || _vnodeData$props === void 0 ? void 0 : _vnodeData$props.title
10984
+ }
10985
+ }, [h(registry.getComponent(com), mergeDeep({
10986
+ props: {
10987
+ value: this.activeIndex,
10988
+ datasource: schemaList.map(function (item, index) {
10989
+ return {
10990
+ label: item.title || '',
10991
+ value: index
10992
+ };
10993
+ })
10994
+ },
10995
+ attrs: {
10996
+ clearable: false
10997
+ },
10998
+ on: {
10999
+ input: function input(index) {
11000
+ _this2.activeIndex = index; // todo 删除其他 composition 字段
11001
+
11002
+ if (isObj(_this2.value)) {
11003
+ var newValue = JSON.parse(JSON.stringify(_this2.value));
11004
+
11005
+ var _props = compositionList.filter(function (_, index) {
11006
+ return index !== _this2.activeIndex;
11007
+ }).reduce(function (pre, item) {
11008
+ var _item$properties = item.properties,
11009
+ properties = _item$properties === void 0 ? {} : _item$properties;
11010
+ pre.push.apply(pre, _toConsumableArray(Object.keys(properties)));
11011
+ return pre;
11012
+ }, []);
11013
+
11014
+ _props.forEach(function (prop) {
11015
+ delete newValue[prop];
11016
+ });
11017
+
11018
+ _this2.$emit('input', {
11019
+ path: _this2.path,
11020
+ value: newValue
11021
+ });
11022
+ }
11023
+ }
11024
+ }
11025
+ }, vnodeData || {}))]), // schema
11026
+ h(SchemaField, {
11027
+ key: this.activeIndex,
11028
+ props: _objectSpread2(_objectSpread2({}, this.$props), {}, {
11029
+ removeable: false,
11030
+ schema: schemaList[this.activeIndex]
11031
+ }),
11032
+ scopedSlots: _objectSpread2({}, this.$scopedSlots),
11033
+ on: _objectSpread2({}, this.$listeners)
11034
+ })]);
11035
+ }
11036
+ });
11037
+
10514
11038
  var CheckboxWidget = Vue__default["default"].extend({
10515
11039
  name: 'CheckboxWidget',
10516
11040
  props: {
@@ -10603,8 +11127,18 @@
10603
11127
  key: item.value,
10604
11128
  props: {
10605
11129
  name: item.label,
10606
- id: item.value
10607
- }
11130
+ id: item.value,
11131
+ disabled: item.disabled
11132
+ },
11133
+ directives: [{
11134
+ name: 'bk-tooltips',
11135
+ value: {
11136
+ content: item.tips,
11137
+ disabled: !item.tips,
11138
+ placement: 'right',
11139
+ boundary: 'window'
11140
+ }
11141
+ }]
10608
11142
  });
10609
11143
  }));
10610
11144
  }
@@ -10674,13 +11208,12 @@
10674
11208
  }
10675
11209
  },
10676
11210
  render: function render(h) {
10677
- var _self = this;
10678
-
11211
+ var self = this;
10679
11212
  return h(registry.getBaseWidget('button'), {
10680
11213
  props: _objectSpread2({}, this.$attrs),
10681
11214
  on: {
10682
11215
  click: function click() {
10683
- _self.handleClick();
11216
+ self.handleClick();
10684
11217
  }
10685
11218
  }
10686
11219
  }, this.word);
@@ -10783,7 +11316,7 @@
10783
11316
 
10784
11317
  });
10785
11318
 
10786
- var _self = this;
11319
+ var self = this;
10787
11320
 
10788
11321
  var renderDelete = function renderDelete() {
10789
11322
  return h('span', {
@@ -10794,7 +11327,7 @@
10794
11327
  },
10795
11328
  on: {
10796
11329
  click: function click() {
10797
- _self.$emit('remove', _self.path);
11330
+ self.$emit('remove', self.path);
10798
11331
  }
10799
11332
  }
10800
11333
  }, [h('i', {
@@ -10892,7 +11425,7 @@
10892
11425
 
10893
11426
  });
10894
11427
 
10895
- var _self = this;
11428
+ var self = this;
10896
11429
 
10897
11430
  var dealSchema = function dealSchema(schema) {
10898
11431
  return (// 处理当前控件默认Schema配置逻辑
@@ -10927,7 +11460,7 @@
10927
11460
  }),
10928
11461
  on: {
10929
11462
  input: function input(data) {
10930
- _self.handleInput(data);
11463
+ self.handleInput(data);
10931
11464
  }
10932
11465
  },
10933
11466
  style: {
@@ -11023,14 +11556,13 @@
11023
11556
  title: this.schema.title
11024
11557
  });
11025
11558
 
11026
- var _self = this;
11027
-
11559
+ var self = this;
11028
11560
  var properties = orderProperties(Object.keys(((_this$schema = this.schema) === null || _this$schema === void 0 ? void 0 : _this$schema.properties) || {}), this.schema['ui:order']);
11029
11561
  return h(FieldGroupWrap, {
11030
11562
  props: _objectSpread2({}, groupWrapProps),
11031
11563
  on: {
11032
11564
  remove: function remove(path) {
11033
- _self.$emit('remove', path);
11565
+ self.$emit('remove', path);
11034
11566
  }
11035
11567
  }
11036
11568
  }, [h(registry.getBaseWidget('tab'), {}, properties.map(function (key) {
@@ -11160,9 +11692,7 @@
11160
11692
  on: _objectSpread2({}, _this.$listeners)
11161
11693
  })])]);
11162
11694
  });
11163
-
11164
- var _self = this;
11165
-
11695
+ var self = this;
11166
11696
  return h(FieldGroupWrap, {
11167
11697
  props: _objectSpread2({}, groupWrapProps)
11168
11698
  }, [h(registry.getBaseWidget('collapse'), {
@@ -11172,7 +11702,7 @@
11172
11702
  },
11173
11703
  on: {
11174
11704
  input: function input(actives) {
11175
- _self.activeName = actives;
11705
+ self.activeName = actives;
11176
11706
  }
11177
11707
  }
11178
11708
  }, collapseItems)]);
@@ -11320,7 +11850,8 @@
11320
11850
  boolean: BooleanField,
11321
11851
  null: '',
11322
11852
  integer: NumberField,
11323
- number: NumberField
11853
+ number: NumberField,
11854
+ composition: CompositionField
11324
11855
  }
11325
11856
  };
11326
11857
  function createForm() {
@@ -11345,6 +11876,7 @@
11345
11876
  },
11346
11877
  watch: {
11347
11878
  schema: function schema() {
11879
+ this.validateSchema(this.schema);
11348
11880
  this.initFormData();
11349
11881
  },
11350
11882
  context: {
@@ -11392,13 +11924,13 @@
11392
11924
  validateSchema: validateSchema
11393
11925
  },
11394
11926
  render: function render(h) {
11395
- var _self = this;
11396
-
11927
+ var self = this;
11397
11928
  return h(registry.getBaseWidget('form'), {
11398
11929
  ref: 'bkui-form',
11399
11930
  props: {
11400
11931
  model: this.value,
11401
- formType: this.formType
11932
+ formType: this.formType,
11933
+ labelWidth: this.labelWidth
11402
11934
  },
11403
11935
  class: {
11404
11936
  'bk-schema-form': true
@@ -11421,14 +11953,13 @@
11421
11953
  value = _ref.value;
11422
11954
 
11423
11955
  if (!path) {
11424
- console.warn('widget path is empty');
11425
- return;
11426
- } // 双向绑定逻辑
11427
-
11428
-
11429
- var newValue = Path.setPathValue(_self.rootData, path, value);
11430
-
11431
- _self.emitFormValueChange(newValue, _self.value);
11956
+ // console.warn('set rootData');
11957
+ self.emitFormValueChange(value, self.value);
11958
+ } else {
11959
+ // 双向绑定逻辑
11960
+ var newValue = Path.setPathValue(self.rootData, path, value);
11961
+ self.emitFormValueChange(newValue, self.value);
11962
+ }
11432
11963
  }
11433
11964
  }
11434
11965
  })]);