Skip to content

Commit 92056ab

Browse files
author
figo
committed
Generated dist files.
1 parent d6884ab commit 92056ab

File tree

2 files changed

+272
-11
lines changed

2 files changed

+272
-11
lines changed

dist/react-json-editor.js

Lines changed: 271 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
else if(typeof define === 'function' && define.amd)
55
define(["react"], factory);
66
else if(typeof exports === 'object')
7-
exports["PlexusForm"] = factory(require("react"));
7+
exports["react-json-editor"] = factory(require("react"));
88
else
9-
root["PlexusForm"] = factory(root["react"]);
9+
root["react-json-editor"] = factory(root["react"]);
1010
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
1111
return /******/ (function(modules) { // webpackBootstrap
1212
/******/ // The module cache
@@ -96,6 +96,7 @@ return /******/ (function(modules) { // webpackBootstrap
9696

9797
var fields = __webpack_require__(4);
9898
var normalise = __webpack_require__(17);
99+
var validator = __webpack_require__(18);
99100

100101

101102
module.exports = React.createClass({
@@ -144,7 +145,8 @@ return /******/ (function(modules) { // webpackBootstrap
144145
return this.state.errors[makeKey(path)];
145146
},
146147
validate: function(schema, values, context) {
147-
return hashedErrors(this.props.validate(schema, values, context));
148+
var validate = this.props.validate || validator;
149+
return hashedErrors(validate(schema, values, context));
148150
},
149151
preventSubmit: function(event) {
150152
event.preventDefault();
@@ -231,19 +233,15 @@ return /******/ (function(modules) { // webpackBootstrap
231233

232234
/*
233235
The MIT License (MIT)
234-
235236
Copyright (c) 2014 The Australian National University
236-
237237
Permission is hereby granted, free of charge, to any person obtaining a copy
238238
of this software and associated documentation files (the "Software"), to deal
239239
in the Software without restriction, including without limitation the rights
240240
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
241241
copies of the Software, and to permit persons to whom the Software is
242242
furnished to do so, subject to the following conditions:
243-
244243
The above copyright notice and this permission notice shall be included in all
245244
copies or substantial portions of the Software.
246-
247245
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
248246
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
249247
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -307,13 +305,25 @@ return /******/ (function(modules) { // webpackBootstrap
307305
};
308306

309307

308+
var without = function(obj) {
309+
var args = [].slice.call(arguments);
310+
var result = Array.isArray(obj) ? [] : {};
311+
312+
for (var key in obj)
313+
if (args.indexOf(key) < 0)
314+
result[key] = obj[key];
315+
316+
return result;
317+
};
318+
319+
310320
var prune = function(root) {
311321
var result, isArray, key, val
312322

313323
if (root == null || root === '')
314324
result = null;
315325
else if (root.constructor === Array || root.constructor === Object) {
316-
isArray = Array.isArray(root);
326+
isArray = Array.isArray(root);
317327
result = isArray ? [] : {};
318328
for (key in root) {
319329
val = prune(root[key]);
@@ -375,6 +385,7 @@ return /******/ (function(modules) { // webpackBootstrap
375385
module.exports = {
376386
object : object,
377387
merge : merge,
388+
without: without,
378389
getIn : getIn,
379390
setIn : setIn,
380391
prune : prune,
@@ -414,7 +425,7 @@ return /******/ (function(modules) { // webpackBootstrap
414425
displayName: 'CheckBox',
415426

416427
handleChange: function(event) {
417-
var val = event.target.checked ? true : null;
428+
var val = event.target.checked;
418429
this.props.update(this.props.path, val, val);
419430
},
420431
render: function() {
@@ -768,9 +779,9 @@ return /******/ (function(modules) { // webpackBootstrap
768779
}
769780
});
770781

771-
772782
var propsForWrapper = function(props, section) {
773783
var propsFW = {
784+
key : props.key,
774785
label : props.label,
775786
path : props.path,
776787
errors : props.errors,
@@ -1147,6 +1158,256 @@ return /******/ (function(modules) { // webpackBootstrap
11471158
}
11481159

11491160

1161+
/***/ },
1162+
/* 18 */
1163+
/***/ function(module, exports, __webpack_require__) {
1164+
1165+
/*
1166+
The MIT License (MIT)
1167+
Copyright (c) 2014 The Australian National University
1168+
Permission is hereby granted, free of charge, to any person obtaining a copy
1169+
of this software and associated documentation files (the "Software"), to deal
1170+
in the Software without restriction, including without limitation the rights
1171+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1172+
copies of the Software, and to permit persons to whom the Software is
1173+
furnished to do so, subject to the following conditions:
1174+
The above copyright notice and this permission notice shall be included in all
1175+
copies or substantial portions of the Software.
1176+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1177+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1178+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1179+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1180+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1181+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1182+
SOFTWARE.
1183+
*/
1184+
1185+
'use strict';
1186+
1187+
var ou = __webpack_require__(3);
1188+
1189+
var checkNumber = function(schema, instance) {
1190+
var errors = [];
1191+
1192+
if (schema.maximum !== null) {
1193+
if (instance > schema.maximum)
1194+
errors.push('may be at most ' + schema.maximum);
1195+
else if (schema.exclusiveMaximum && instance >= schema.maximum)
1196+
errors.push('must be less than ' + schema.maximum);
1197+
}
1198+
if (schema.minimum !== null) {
1199+
if (instance < schema.minimum)
1200+
errors.push('must be at least ' + schema.minimum);
1201+
else if (schema.exclusiveMinimum && instance <= schema.minimum)
1202+
errors.push('must be more than ' + schema.minimum);
1203+
}
1204+
if (schema.multipleOf != null) {
1205+
if ((instance / schema.multipleOf) % 1 != 0)
1206+
errors.push('must be a multiple of ' + schema.multipleOf);
1207+
}
1208+
1209+
return errors;
1210+
};
1211+
1212+
1213+
var fieldErrors = function(errors) {
1214+
if (errors.length > 0)
1215+
return [ { path: [], errors: errors } ];
1216+
else
1217+
return [];
1218+
};
1219+
1220+
1221+
var validator = {};
1222+
1223+
1224+
validator.boolean = function(schema, instance) {
1225+
var errors = [];
1226+
1227+
if (typeof instance != 'boolean')
1228+
errors.push('must be boolean');
1229+
1230+
return fieldErrors(errors);
1231+
};
1232+
1233+
1234+
validator.enum = function(schema, instance) {
1235+
var errors = [];
1236+
1237+
if (schema.enum.indexOf(instance) < 0)
1238+
errors.push('value not in list');
1239+
1240+
return fieldErrors(errors);
1241+
};
1242+
1243+
1244+
validator.number = function(schema, instance) {
1245+
var errors = [];
1246+
1247+
if (typeof instance != 'number')
1248+
errors.push('must be a number');
1249+
else
1250+
errors = checkNumber(schema, instance);
1251+
1252+
return fieldErrors(errors);
1253+
};
1254+
1255+
1256+
validator.integer = function(schema, instance) {
1257+
var errors = [];
1258+
1259+
if (typeof instance != 'number')
1260+
errors.push('must be a number');
1261+
else {
1262+
errors = checkNumber(schema, instance);
1263+
if (instance % 1 > 0)
1264+
errors.unshift('must be an integer');
1265+
}
1266+
1267+
return fieldErrors(errors);
1268+
};
1269+
1270+
1271+
validator.string = function(schema, instance) {
1272+
var errors = [];
1273+
1274+
if (typeof instance != 'string')
1275+
errors.push('must be a string');
1276+
else {
1277+
if (schema.maxLength != null && instance.length > schema.maxLength)
1278+
errors.push('may have at most ' + schema.maxLength + ' characters');
1279+
if (schema.minLength != null && instance.length < schema.minLength)
1280+
errors.push('must have at least ' + schema.minLength + ' characters');
1281+
if (schema.pattern != null && !(RegExp(schema.pattern).test(instance)))
1282+
errors.push('must match ' + schema.pattern);
1283+
}
1284+
1285+
return fieldErrors(errors);
1286+
};
1287+
1288+
1289+
validator.array = function(schema, instance, context) {
1290+
var errors = [];
1291+
var result, i, j;
1292+
1293+
if (!Array.isArray(instance))
1294+
return fieldErrors(['must be an array']);
1295+
else {
1296+
if (schema.maxItems != null && instance.length > schema.maxItems)
1297+
errors.push('may have at most ' + schema.maxItems + ' items');
1298+
if (schema.minItems != null && instance.length < schema.minItems)
1299+
errors.push('must have at least ' + schema.minItems + ' items');
1300+
result = fieldErrors(errors);
1301+
1302+
if (schema.items != null) {
1303+
for (i in instance) {
1304+
errors = validate(schema.items, instance[i], context);
1305+
for (j in errors) {
1306+
result.push({
1307+
path : [i].concat(errors[j].path),
1308+
errors: errors[j].errors
1309+
});
1310+
}
1311+
}
1312+
}
1313+
}
1314+
1315+
return result;
1316+
};
1317+
1318+
1319+
var requires = function(schema, key) {
1320+
var subschema;
1321+
1322+
if (schema.required != null && schema.required.indexOf(key) >= 0)
1323+
return 'must be present';
1324+
else {
1325+
subschema = schema.properties[key];
1326+
if (subschema.type == 'array' && subschema.minItems > 0)
1327+
return 'must have at least ' + subschema.minItems + ' items';
1328+
else
1329+
return null;
1330+
}
1331+
};
1332+
1333+
validator.object = function(schema, instance, context) {
1334+
var result = [];
1335+
var key, errors, i;
1336+
1337+
if (instance == null)
1338+
instance = {};
1339+
1340+
if (instance.constructor !== Object)
1341+
result.push({ path: [], errors: ['must be a plain object'] });
1342+
else {
1343+
for (key in schema.properties) {
1344+
if (instance.hasOwnProperty(key)) {
1345+
errors = validate(schema.properties[key], instance[key], context);
1346+
for (i = 0; i < errors.length; ++i)
1347+
result.push({
1348+
path : [key].concat(errors[i].path),
1349+
errors: errors[i].errors
1350+
});
1351+
}
1352+
else if (requires(schema, key)) {
1353+
result.push({
1354+
path : [key],
1355+
errors: [requires(schema, key)]
1356+
});
1357+
}
1358+
}
1359+
}
1360+
1361+
return result;
1362+
};
1363+
1364+
1365+
var cat = function(arrayOfArrays) {
1366+
return [].concat.apply([], arrayOfArrays);
1367+
};
1368+
1369+
1370+
var resolve = function(schema, context) {
1371+
var reference = schema['$ref'];
1372+
1373+
if (reference) {
1374+
if (!reference.match(/^#(\/([a-zA-Z_][a-zA-Z_0-9]*|[0-9]+))*$/))
1375+
throw new Error('reference '+reference+' has unsupported format');
1376+
1377+
return {
1378+
allOf: [
1379+
ou.without(schema, '$ref'),
1380+
ou.getIn(context, reference.split('/').slice(1))
1381+
]
1382+
};
1383+
} else
1384+
return schema;
1385+
};
1386+
1387+
1388+
var validate = function(schema, instance, context) {
1389+
var effectiveContext = context || schema;
1390+
var effectiveSchema = resolve(schema, effectiveContext);
1391+
1392+
if (effectiveSchema.allOf) {
1393+
var results = [ou.without(effectiveSchema, 'allOf')]
1394+
.concat(effectiveSchema.allOf)
1395+
.map(function(schema) {
1396+
return validate(schema, instance, effectiveContext);
1397+
});
1398+
return cat(results);
1399+
} else {
1400+
var type = effectiveSchema.enum ? 'enum' : effectiveSchema.type;
1401+
if (type)
1402+
return validator[type](effectiveSchema, instance, effectiveContext);
1403+
else
1404+
return [];
1405+
}
1406+
};
1407+
1408+
module.exports = validate;
1409+
1410+
11501411
/***/ }
11511412
/******/ ])
11521413
});

0 commit comments

Comments
 (0)