Released v5.5.4

This commit is contained in:
jos 2016-05-22 20:43:26 +02:00
parent b11dc3038f
commit b18537f976
7 changed files with 127 additions and 121 deletions

View File

@ -24,7 +24,7 @@
* Copyright (c) 2011-2016 Jos de Jong, http://jsoneditoronline.org * Copyright (c) 2011-2016 Jos de Jong, http://jsoneditoronline.org
* *
* @author Jos de Jong, <wjosdejong@gmail.com> * @author Jos de Jong, <wjosdejong@gmail.com>
* @version 5.5.3 * @version 5.5.4
* @date 2016-05-22 * @date 2016-05-22
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
@ -1295,7 +1295,7 @@ return /******/ (function(modules) { // webpackBootstrap
// drag a singe node // drag a singe node
Node.onDragStart(node, event); Node.onDragStart(node, event);
} }
else if (!node || (event.target != node.dom.field && event.target != node.dom.value)) { else if (!node || (event.target != node.dom.field && event.target != node.dom.value && event.target != node.dom.select)) {
// select multiple nodes // select multiple nodes
this._onMultiSelectStart(event); this._onMultiSelectStart(event);
} }
@ -5300,10 +5300,10 @@ return /******/ (function(modules) { // webpackBootstrap
this.dom.select.appendChild(this.dom.select.option); this.dom.select.appendChild(this.dom.select.option);
//Iterate all enum values and add them as options //Iterate all enum values and add them as options
for(var i = 0; i < this.enum.enum.length; i++) { for(var i = 0; i < this.enum.length; i++) {
this.dom.select.option = document.createElement('option'); this.dom.select.option = document.createElement('option');
this.dom.select.option.value = this.enum.enum[i]; this.dom.select.option.value = this.enum[i];
this.dom.select.option.innerHTML = this.enum.enum[i]; this.dom.select.option.innerHTML = this.enum[i];
if(this.dom.select.option.value == this.value){ if(this.dom.select.option.value == this.value){
this.dom.select.option.selected = true; this.dom.select.option.selected = true;
} }
@ -6006,59 +6006,61 @@ return /******/ (function(modules) { // webpackBootstrap
Node.prototype._updateSchema = function () { Node.prototype._updateSchema = function () {
//Locating the schema of the node and checking for any enum type //Locating the schema of the node and checking for any enum type
if(this.editor && this.editor.options) { if(this.editor && this.editor.options) {
var field = (this.index != undefined) ? this.index : this.field; // find the part of the json schema matching this nodes path
this.schema = Node._findSchema(this.editor.options.schema, this.getPath());
//Search for the schema element of the current node and store it in the schema attribute. if (this.schema) {
//Hereafter, wherever you have access in the node you will have also access in its own schema. this.enum = Node._findEnum(this.schema);
this.schema = this._getJsonObject(this.editor.options.schema, 'name', field)[0];
if(!this.schema) {
this.schema = this._getJsonObject(this.editor.options.schema, field)[0];
} }
else {
//Search for any enumeration type in the schema of the current node.
//Enum types can be also be part of a composite type.
if(this.schema){
if(this.schema.hasOwnProperty('enum')){
this.enum = {};
this.enum.enum = this.schema.enum;
} else if(this.schema.hasOwnProperty('oneOf')){
this.enum = this._getJsonObject(this.schema.oneOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('anyOf')){
this.enum = this._getJsonObject(this.schema.anyOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('allOf')){
this.enum = this._getJsonObject(this.schema.allOf, 'enum')[0];
} else {
delete this.enum;
}
} else {
delete this.enum; delete this.enum;
} }
} }
}; };
/** /**
* Get all sub-elements of the given object with the specified key and value. * find an enum definition in a JSON schema, as property `enum` or inside
* one of the schemas composites (`oneOf`, `anyOf`, `allOf`)
* @param {Object} schema
* @return {Array | null} Returns the enum when found, null otherwise.
* @private * @private
*/ */
Node.prototype._getJsonObject = function (obj, key, val) { Node._findEnum = function (schema) {
var objects = []; if (schema.enum) {
for (var i in obj) { return schema.enum;
if (!obj.hasOwnProperty(i)) continue; }
if (typeof obj[i] == 'object') {
if(i === key && val === undefined){ var composite = schema.oneOf || schema.anyOf || schema.allOf;
if(Array.isArray(obj[i])) { if (composite) {
objects.push(obj); var match = composite.filter(function (entry) {return entry.enum});
} else { if (match.length > 0) {
objects.push(obj[i]); return match[0].enum;
}
} else {
objects = objects.concat(this._getJsonObject(obj[i], key, val));
}
} else if (i == key && obj[key] == val) {
objects.push(obj);
} }
} }
return objects;
return null
};
/**
* Return the part of a JSON schema matching given path.
* @param {Object} schema
* @param {Array.<string | number>} path
* @return {Object | null}
* @private
*/
Node._findSchema = function (schema, path) {
var childSchema = schema;
for (var i = 0; i < path.length && childSchema; i++) {
var key = path[i];
if (typeof key === 'string' && childSchema.properties) {
childSchema = childSchema.properties[key] || null
}
else if (typeof key === 'number' && childSchema.items) {
childSchema = childSchema.items
}
}
return childSchema
}; };
/** /**
@ -6255,7 +6257,8 @@ return /******/ (function(modules) { // webpackBootstrap
this.dom.value.innerHTML = !this.value; this.dom.value.innerHTML = !this.value;
this._getDomValue(); this._getDomValue();
} }
//Update the value of the node based on the selected option
// update the value of the node based on the selected option
if (type == 'change' && target == dom.select) { if (type == 'change' && target == dom.select) {
this.dom.value.innerHTML = dom.select.value; this.dom.value.innerHTML = dom.select.value;
this._getDomValue(); this._getDomValue();
@ -6367,7 +6370,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
else { else {
if (domValue) { if (domValue && !this.enum) {
util.setEndOfContentEditable(domValue); util.setEndOfContentEditable(domValue);
domValue.focus(); domValue.focus();
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

101
dist/jsoneditor.js vendored
View File

@ -24,7 +24,7 @@
* Copyright (c) 2011-2016 Jos de Jong, http://jsoneditoronline.org * Copyright (c) 2011-2016 Jos de Jong, http://jsoneditoronline.org
* *
* @author Jos de Jong, <wjosdejong@gmail.com> * @author Jos de Jong, <wjosdejong@gmail.com>
* @version 5.5.3 * @version 5.5.4
* @date 2016-05-22 * @date 2016-05-22
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
@ -9194,7 +9194,7 @@ return /******/ (function(modules) { // webpackBootstrap
// drag a singe node // drag a singe node
Node.onDragStart(node, event); Node.onDragStart(node, event);
} }
else if (!node || (event.target != node.dom.field && event.target != node.dom.value)) { else if (!node || (event.target != node.dom.field && event.target != node.dom.value && event.target != node.dom.select)) {
// select multiple nodes // select multiple nodes
this._onMultiSelectStart(event); this._onMultiSelectStart(event);
} }
@ -13199,10 +13199,10 @@ return /******/ (function(modules) { // webpackBootstrap
this.dom.select.appendChild(this.dom.select.option); this.dom.select.appendChild(this.dom.select.option);
//Iterate all enum values and add them as options //Iterate all enum values and add them as options
for(var i = 0; i < this.enum.enum.length; i++) { for(var i = 0; i < this.enum.length; i++) {
this.dom.select.option = document.createElement('option'); this.dom.select.option = document.createElement('option');
this.dom.select.option.value = this.enum.enum[i]; this.dom.select.option.value = this.enum[i];
this.dom.select.option.innerHTML = this.enum.enum[i]; this.dom.select.option.innerHTML = this.enum[i];
if(this.dom.select.option.value == this.value){ if(this.dom.select.option.value == this.value){
this.dom.select.option.selected = true; this.dom.select.option.selected = true;
} }
@ -13905,59 +13905,61 @@ return /******/ (function(modules) { // webpackBootstrap
Node.prototype._updateSchema = function () { Node.prototype._updateSchema = function () {
//Locating the schema of the node and checking for any enum type //Locating the schema of the node and checking for any enum type
if(this.editor && this.editor.options) { if(this.editor && this.editor.options) {
var field = (this.index != undefined) ? this.index : this.field; // find the part of the json schema matching this nodes path
this.schema = Node._findSchema(this.editor.options.schema, this.getPath());
//Search for the schema element of the current node and store it in the schema attribute. if (this.schema) {
//Hereafter, wherever you have access in the node you will have also access in its own schema. this.enum = Node._findEnum(this.schema);
this.schema = this._getJsonObject(this.editor.options.schema, 'name', field)[0];
if(!this.schema) {
this.schema = this._getJsonObject(this.editor.options.schema, field)[0];
} }
else {
//Search for any enumeration type in the schema of the current node.
//Enum types can be also be part of a composite type.
if(this.schema){
if(this.schema.hasOwnProperty('enum')){
this.enum = {};
this.enum.enum = this.schema.enum;
} else if(this.schema.hasOwnProperty('oneOf')){
this.enum = this._getJsonObject(this.schema.oneOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('anyOf')){
this.enum = this._getJsonObject(this.schema.anyOf, 'enum')[0];
} else if(this.schema.hasOwnProperty('allOf')){
this.enum = this._getJsonObject(this.schema.allOf, 'enum')[0];
} else {
delete this.enum;
}
} else {
delete this.enum; delete this.enum;
} }
} }
}; };
/** /**
* Get all sub-elements of the given object with the specified key and value. * find an enum definition in a JSON schema, as property `enum` or inside
* one of the schemas composites (`oneOf`, `anyOf`, `allOf`)
* @param {Object} schema
* @return {Array | null} Returns the enum when found, null otherwise.
* @private * @private
*/ */
Node.prototype._getJsonObject = function (obj, key, val) { Node._findEnum = function (schema) {
var objects = []; if (schema.enum) {
for (var i in obj) { return schema.enum;
if (!obj.hasOwnProperty(i)) continue; }
if (typeof obj[i] == 'object') {
if(i === key && val === undefined){ var composite = schema.oneOf || schema.anyOf || schema.allOf;
if(Array.isArray(obj[i])) { if (composite) {
objects.push(obj); var match = composite.filter(function (entry) {return entry.enum});
} else { if (match.length > 0) {
objects.push(obj[i]); return match[0].enum;
}
} else {
objects = objects.concat(this._getJsonObject(obj[i], key, val));
}
} else if (i == key && obj[key] == val) {
objects.push(obj);
} }
} }
return objects;
return null
};
/**
* Return the part of a JSON schema matching given path.
* @param {Object} schema
* @param {Array.<string | number>} path
* @return {Object | null}
* @private
*/
Node._findSchema = function (schema, path) {
var childSchema = schema;
for (var i = 0; i < path.length && childSchema; i++) {
var key = path[i];
if (typeof key === 'string' && childSchema.properties) {
childSchema = childSchema.properties[key] || null
}
else if (typeof key === 'number' && childSchema.items) {
childSchema = childSchema.items
}
}
return childSchema
}; };
/** /**
@ -14154,7 +14156,8 @@ return /******/ (function(modules) { // webpackBootstrap
this.dom.value.innerHTML = !this.value; this.dom.value.innerHTML = !this.value;
this._getDomValue(); this._getDomValue();
} }
//Update the value of the node based on the selected option
// update the value of the node based on the selected option
if (type == 'change' && target == dom.select) { if (type == 'change' && target == dom.select) {
this.dom.value.innerHTML = dom.select.value; this.dom.value.innerHTML = dom.select.value;
this._getDomValue(); this._getDomValue();
@ -14266,7 +14269,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
else { else {
if (domValue) { if (domValue && !this.enum) {
util.setEndOfContentEditable(domValue); util.setEndOfContentEditable(domValue);
domValue.focus(); domValue.focus();
} }

2
dist/jsoneditor.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "jsoneditor", "name": "jsoneditor",
"version": "5.5.3", "version": "5.5.4",
"main": "./index", "main": "./index",
"description": "A web-based tool to view, edit, format, and validate JSON", "description": "A web-based tool to view, edit, format, and validate JSON",
"tags": [ "tags": [