Publish v5.32.0

This commit is contained in:
jos 2019-03-20 17:46:49 +01:00
parent 3e7e1cebfd
commit 0fbe7eee9a
11 changed files with 531 additions and 366 deletions

View File

@ -3,7 +3,7 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet published, version 5.32.0 ## 2019-03-20, version 5.32.0
- Implemented support for reckoning with JSON schema default values: custom - Implemented support for reckoning with JSON schema default values: custom
styling can be applied for default and non-default values. Thanks @AdamVig. styling can be applied for default and non-default values. Thanks @AdamVig.

View File

@ -24,8 +24,8 @@
* Copyright (c) 2011-2019 Jos de Jong, http://jsoneditoronline.org * Copyright (c) 2011-2019 Jos de Jong, http://jsoneditoronline.org
* *
* @author Jos de Jong, <wjosdejong@gmail.com> * @author Jos de Jong, <wjosdejong@gmail.com>
* @version 5.31.1 * @version 5.32.0
* @date 2019-03-14 * @date 2019-03-20
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -5366,43 +5366,75 @@ return /******/ (function(modules) { // webpackBootstrap
* @return {Array} * @return {Array}
*/ */
exports.parsePath = function parsePath(jsonPath) { exports.parsePath = function parsePath(jsonPath) {
var prop, remainder; var path = [];
var i = 0;
if (jsonPath.length === 0) { function parseProperty () {
return []; var prop = ''
while (jsonPath[i] !== undefined && /[\w$]/.test(jsonPath[i])) {
prop += jsonPath[i];
i++;
} }
// find a match like '.prop' if (prop === '') {
var match = jsonPath.match(/^\.([\w$]+)/); throw new Error('Invalid JSON path: property name expected at index ' + i);
if (match) {
prop = match[1];
remainder = jsonPath.substr(prop.length + 1);
}
else if (jsonPath[0] === '[') {
// find a match like
var end = jsonPath.indexOf(']');
if (end === -1) {
throw new SyntaxError('Character ] expected in path');
}
if (end === 1) {
throw new SyntaxError('Index expected after [');
} }
var value = jsonPath.substring(1, end); return prop;
if (value[0] === '\'') {
// ajv produces string prop names with single quotes, so we need
// to reformat them into valid double-quoted JSON strings
value = '\"' + value.substring(1, value.length - 1) + '\"';
} }
prop = value === '*' ? value : JSON.parse(value); // parse string and number function parseIndex (end) {
remainder = jsonPath.substr(end + 1); var name = ''
while (jsonPath[i] !== undefined && jsonPath[i] !== end) {
name += jsonPath[i];
i++;
}
if (jsonPath[i] !== end) {
throw new Error('Invalid JSON path: unexpected end, character ' + end + ' expected')
}
return name;
}
while (jsonPath[i] !== undefined) {
if (jsonPath[i] === '.') {
i++;
path.push(parseProperty());
}
else if (i > 0 && jsonPath[i] === '[') {
i++;
if (jsonPath[i] === '\'' || jsonPath[i] === '"') {
var end = jsonPath[i]
i++;
path.push(parseIndex(end));
if (jsonPath[i] !== end) {
throw new Error('Invalid JSON path: closing quote \' expected at index ' + i)
}
i++;
} }
else { else {
throw new SyntaxError('Failed to parse path'); var index = parseIndex(']').trim()
if (index.length === 0) {
throw new Error('Invalid JSON path: array value expected at index ' + i)
}
path.push(index);
} }
return [prop].concat(parsePath(remainder)) if (jsonPath[i] !== ']') {
throw new Error('Invalid JSON path: closing bracket ] expected at index ' + i)
}
i++;
}
else {
throw new Error('Invalid JSON path: unexpected character "' + jsonPath[i] + '" at index ' + i);
}
}
return path;
}; };
/** /**
@ -5711,13 +5743,24 @@ return /******/ (function(modules) { // webpackBootstrap
tooltip += schema.description; tooltip += schema.description;
} }
if (schema.default) {
if (tooltip.length > 0) {
tooltip += '\n\n';
}
tooltip += translate('default', undefined, locale) + '\n';
tooltip += JSON.stringify(schema.default, null, 2);
}
if (Array.isArray(schema.examples) && schema.examples.length > 0) { if (Array.isArray(schema.examples) && schema.examples.length > 0) {
if (tooltip.length > 0) { if (tooltip.length > 0) {
tooltip += '\n\n'; tooltip += '\n\n';
} }
tooltip += translate('examples', undefined, locale) + '\n'; tooltip += translate('examples', undefined, locale) + '\n';
schema.examples.forEach(function (example) { schema.examples.forEach(function (example, index) {
tooltip += JSON.stringify(example, null, 2) + '\n'; tooltip += JSON.stringify(example, null, 2);
if (index !== schema.examples.length - 1) {
tooltip += '\n';
}
}); });
} }
@ -5775,6 +5818,13 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
// Polyfill for String.trim
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
/***/ }, /***/ },
/* 14 */ /* 14 */
@ -6707,6 +6757,7 @@ return /******/ (function(modules) { // webpackBootstrap
modeViewText: 'View', modeViewText: 'View',
modeViewTitle: 'Switch to tree view', modeViewTitle: 'Switch to tree view',
examples: 'Examples', examples: 'Examples',
default: 'Default',
}, },
'zh-CN': { 'zh-CN': {
array: '数组', array: '数组',
@ -6790,6 +6841,7 @@ return /******/ (function(modules) { // webpackBootstrap
modeViewText: '视图', modeViewText: '视图',
modeViewTitle: '切换至树视图', modeViewTitle: '切换至树视图',
examples: '例子', examples: '例子',
default: '缺省',
}, },
'pt-BR': { 'pt-BR': {
array: 'Lista', array: 'Lista',
@ -6885,6 +6937,7 @@ return /******/ (function(modules) { // webpackBootstrap
'Campo do tipo nao é determinado através do seu valor, ' + 'Campo do tipo nao é determinado através do seu valor, ' +
'mas sempre retornara um texto.', 'mas sempre retornara um texto.',
examples: 'Exemplos', examples: 'Exemplos',
default: 'Revelia',
}, },
tr: { tr: {
array: 'Dizin', array: 'Dizin',
@ -6968,6 +7021,7 @@ return /******/ (function(modules) { // webpackBootstrap
modeViewText: 'Görünüm', modeViewText: 'Görünüm',
modeViewTitle: 'Ağaç görünümüne geç', modeViewTitle: 'Ağaç görünümüne geç',
examples: 'Örnekler', examples: 'Örnekler',
default: 'Varsayılan',
} }
}; };
@ -9004,6 +9058,8 @@ return /******/ (function(modules) { // webpackBootstrap
// strip formatting from the contents of the editable div // strip formatting from the contents of the editable div
util.stripFormatting(domValue); util.stripFormatting(domValue);
this._updateDomDefault();
} }
}; };
@ -9090,6 +9146,32 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}; };
/**
* Update the value of the schema default element in the DOM.
* @private
* @returns {undefined}
*/
Node.prototype._updateDomDefault = function () {
// Short-circuit if schema is missing, has no default, or if Node has children
if (!this.schema || this.schema.default === undefined || this._hasChilds()) {
return;
}
if (this.value === this.schema.default) {
if (this.dom.select) {
this.dom.value.removeAttribute('title');
} else {
this.dom.value.title = translate('default');
this.dom.value.classList.add('jsoneditor-is-default');
this.dom.value.classList.remove('jsoneditor-is-not-default');
}
} else {
this.dom.value.removeAttribute('title');
this.dom.value.classList.remove('jsoneditor-is-default');
this.dom.value.classList.add('jsoneditor-is-not-default');
}
};
/** /**
* Validate this node and all it's childs * Validate this node and all it's childs
* @return {Array.<{node: Node, error: {message: string}}>} Returns a list with duplicates * @return {Array.<{node: Node, error: {message: string}}>} Returns a list with duplicates
@ -9791,18 +9873,18 @@ return /******/ (function(modules) { // webpackBootstrap
for (var j = 0; j < allSchemas.length; j++) { for (var j = 0; j < allSchemas.length; j++) {
childSchema = allSchemas[j]; childSchema = allSchemas[j];
if ('$ref' in childSchema && typeof childSchema['$ref'] === 'string') {
childSchema = schemaRefs[childSchema['$ref']];
if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, path);
}
}
for (var i = 0; i < path.length && childSchema; i++) { for (var i = 0; i < path.length && childSchema; i++) {
var nextPath = path.slice(i + 1, path.length); var nextPath = path.slice(i + 1, path.length);
var key = path[i]; var key = path[i];
// fix childSchema with $ref, and not display the select element on the child schema because of not found enum if (typeof key === 'string' && childSchema.patternProperties && !(childSchema.properties && key in childSchema.properties)) {
if (typeof key === 'string' && childSchema['$ref']) {
childSchema = schemaRefs[childSchema['$ref']];
if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath);
}
}
else if (typeof key === 'string' && childSchema.patternProperties && !(childSchema.properties && key in childSchema.properties)) {
for (var prop in childSchema.patternProperties) { for (var prop in childSchema.patternProperties) {
if (key.match(prop)) { if (key.match(prop)) {
foundSchema = Node._findSchema(childSchema.patternProperties[prop], schemaRefs, nextPath); foundSchema = Node._findSchema(childSchema.patternProperties[prop], schemaRefs, nextPath);
@ -9816,11 +9898,15 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
else if (typeof key === 'string' && childSchema.properties) { else if (typeof key === 'string' && childSchema.properties) {
childSchema = childSchema.properties[key] || null; if (!(key in childSchema.properties)) {
foundSchema = null;
} else {
childSchema = childSchema.properties[key];
if (childSchema) { if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath); foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath);
} }
} }
}
else if (typeof key === 'number' && childSchema.items) { else if (typeof key === 'number' && childSchema.items) {
childSchema = childSchema.items; childSchema = childSchema.items;
if (childSchema) { if (childSchema) {
@ -9830,6 +9916,12 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
// If the found schema is the input schema, the schema does not have the given path
if (foundSchema === schema && path.length > 0) {
return null;
}
return foundSchema return foundSchema
}; };
@ -10035,6 +10127,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (type == 'change' && target == dom.checkbox) { if (type == 'change' && target == dom.checkbox) {
this.dom.value.innerHTML = !this.value; this.dom.value.innerHTML = !this.value;
this._getDomValue(); this._getDomValue();
this._updateDomDefault();
} }
// update the value of the node based on the selected option // update the value of the node based on the selected option

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

11
dist/jsoneditor.css vendored
View File

@ -27,7 +27,8 @@ div.jsoneditor th {
div.jsoneditor-field, div.jsoneditor-field,
div.jsoneditor-value, div.jsoneditor-value,
div.jsoneditor-readonly { div.jsoneditor-readonly,
div.jsoneditor-default {
border: 1px solid transparent; border: 1px solid transparent;
min-height: 16px; min-height: 16px;
min-width: 32px; min-width: 32px;
@ -120,13 +121,12 @@ div.jsoneditor-value.jsoneditor-highlight-active:hover {
} }
div.jsoneditor-value.jsoneditor-string { div.jsoneditor-value.jsoneditor-string {
color: #008000; color: #006000;
} }
div.jsoneditor-value.jsoneditor-object, div.jsoneditor-value.jsoneditor-object,
div.jsoneditor-value.jsoneditor-array { div.jsoneditor-value.jsoneditor-array {
min-width: 16px; min-width: 16px;
color: #808080;
} }
div.jsoneditor-value.jsoneditor-number { div.jsoneditor-value.jsoneditor-number {
@ -145,6 +145,11 @@ div.jsoneditor-value.jsoneditor-invalid {
color: #000000; color: #000000;
} }
div.jsoneditor-default {
color: #808080;
padding-left: 10px;
}
div.jsoneditor-tree button.jsoneditor-button { div.jsoneditor-tree button.jsoneditor-button {
width: 24px; width: 24px;
height: 24px; height: 24px;

171
dist/jsoneditor.js vendored
View File

@ -24,8 +24,8 @@
* Copyright (c) 2011-2019 Jos de Jong, http://jsoneditoronline.org * Copyright (c) 2011-2019 Jos de Jong, http://jsoneditoronline.org
* *
* @author Jos de Jong, <wjosdejong@gmail.com> * @author Jos de Jong, <wjosdejong@gmail.com>
* @version 5.31.1 * @version 5.32.0
* @date 2019-03-14 * @date 2019-03-20
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -34008,43 +34008,75 @@ return /******/ (function(modules) { // webpackBootstrap
* @return {Array} * @return {Array}
*/ */
exports.parsePath = function parsePath(jsonPath) { exports.parsePath = function parsePath(jsonPath) {
var prop, remainder; var path = [];
var i = 0;
if (jsonPath.length === 0) { function parseProperty () {
return []; var prop = ''
while (jsonPath[i] !== undefined && /[\w$]/.test(jsonPath[i])) {
prop += jsonPath[i];
i++;
} }
// find a match like '.prop' if (prop === '') {
var match = jsonPath.match(/^\.([\w$]+)/); throw new Error('Invalid JSON path: property name expected at index ' + i);
if (match) {
prop = match[1];
remainder = jsonPath.substr(prop.length + 1);
}
else if (jsonPath[0] === '[') {
// find a match like
var end = jsonPath.indexOf(']');
if (end === -1) {
throw new SyntaxError('Character ] expected in path');
}
if (end === 1) {
throw new SyntaxError('Index expected after [');
} }
var value = jsonPath.substring(1, end); return prop;
if (value[0] === '\'') {
// ajv produces string prop names with single quotes, so we need
// to reformat them into valid double-quoted JSON strings
value = '\"' + value.substring(1, value.length - 1) + '\"';
} }
prop = value === '*' ? value : JSON.parse(value); // parse string and number function parseIndex (end) {
remainder = jsonPath.substr(end + 1); var name = ''
while (jsonPath[i] !== undefined && jsonPath[i] !== end) {
name += jsonPath[i];
i++;
}
if (jsonPath[i] !== end) {
throw new Error('Invalid JSON path: unexpected end, character ' + end + ' expected')
}
return name;
}
while (jsonPath[i] !== undefined) {
if (jsonPath[i] === '.') {
i++;
path.push(parseProperty());
}
else if (i > 0 && jsonPath[i] === '[') {
i++;
if (jsonPath[i] === '\'' || jsonPath[i] === '"') {
var end = jsonPath[i]
i++;
path.push(parseIndex(end));
if (jsonPath[i] !== end) {
throw new Error('Invalid JSON path: closing quote \' expected at index ' + i)
}
i++;
} }
else { else {
throw new SyntaxError('Failed to parse path'); var index = parseIndex(']').trim()
if (index.length === 0) {
throw new Error('Invalid JSON path: array value expected at index ' + i)
}
path.push(index);
} }
return [prop].concat(parsePath(remainder)) if (jsonPath[i] !== ']') {
throw new Error('Invalid JSON path: closing bracket ] expected at index ' + i)
}
i++;
}
else {
throw new Error('Invalid JSON path: unexpected character "' + jsonPath[i] + '" at index ' + i);
}
}
return path;
}; };
/** /**
@ -34353,13 +34385,24 @@ return /******/ (function(modules) { // webpackBootstrap
tooltip += schema.description; tooltip += schema.description;
} }
if (schema.default) {
if (tooltip.length > 0) {
tooltip += '\n\n';
}
tooltip += translate('default', undefined, locale) + '\n';
tooltip += JSON.stringify(schema.default, null, 2);
}
if (Array.isArray(schema.examples) && schema.examples.length > 0) { if (Array.isArray(schema.examples) && schema.examples.length > 0) {
if (tooltip.length > 0) { if (tooltip.length > 0) {
tooltip += '\n\n'; tooltip += '\n\n';
} }
tooltip += translate('examples', undefined, locale) + '\n'; tooltip += translate('examples', undefined, locale) + '\n';
schema.examples.forEach(function (example) { schema.examples.forEach(function (example, index) {
tooltip += JSON.stringify(example, null, 2) + '\n'; tooltip += JSON.stringify(example, null, 2);
if (index !== schema.examples.length - 1) {
tooltip += '\n';
}
}); });
} }
@ -34417,6 +34460,13 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
// Polyfill for String.trim
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
/***/ }, /***/ },
/* 67 */ /* 67 */
@ -35349,6 +35399,7 @@ return /******/ (function(modules) { // webpackBootstrap
modeViewText: 'View', modeViewText: 'View',
modeViewTitle: 'Switch to tree view', modeViewTitle: 'Switch to tree view',
examples: 'Examples', examples: 'Examples',
default: 'Default',
}, },
'zh-CN': { 'zh-CN': {
array: '数组', array: '数组',
@ -35432,6 +35483,7 @@ return /******/ (function(modules) { // webpackBootstrap
modeViewText: '视图', modeViewText: '视图',
modeViewTitle: '切换至树视图', modeViewTitle: '切换至树视图',
examples: '例子', examples: '例子',
default: '缺省',
}, },
'pt-BR': { 'pt-BR': {
array: 'Lista', array: 'Lista',
@ -35527,6 +35579,7 @@ return /******/ (function(modules) { // webpackBootstrap
'Campo do tipo nao é determinado através do seu valor, ' + 'Campo do tipo nao é determinado através do seu valor, ' +
'mas sempre retornara um texto.', 'mas sempre retornara um texto.',
examples: 'Exemplos', examples: 'Exemplos',
default: 'Revelia',
}, },
tr: { tr: {
array: 'Dizin', array: 'Dizin',
@ -35610,6 +35663,7 @@ return /******/ (function(modules) { // webpackBootstrap
modeViewText: 'Görünüm', modeViewText: 'Görünüm',
modeViewTitle: 'Ağaç görünümüne geç', modeViewTitle: 'Ağaç görünümüne geç',
examples: 'Örnekler', examples: 'Örnekler',
default: 'Varsayılan',
} }
}; };
@ -37646,6 +37700,8 @@ return /******/ (function(modules) { // webpackBootstrap
// strip formatting from the contents of the editable div // strip formatting from the contents of the editable div
util.stripFormatting(domValue); util.stripFormatting(domValue);
this._updateDomDefault();
} }
}; };
@ -37732,6 +37788,32 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}; };
/**
* Update the value of the schema default element in the DOM.
* @private
* @returns {undefined}
*/
Node.prototype._updateDomDefault = function () {
// Short-circuit if schema is missing, has no default, or if Node has children
if (!this.schema || this.schema.default === undefined || this._hasChilds()) {
return;
}
if (this.value === this.schema.default) {
if (this.dom.select) {
this.dom.value.removeAttribute('title');
} else {
this.dom.value.title = translate('default');
this.dom.value.classList.add('jsoneditor-is-default');
this.dom.value.classList.remove('jsoneditor-is-not-default');
}
} else {
this.dom.value.removeAttribute('title');
this.dom.value.classList.remove('jsoneditor-is-default');
this.dom.value.classList.add('jsoneditor-is-not-default');
}
};
/** /**
* Validate this node and all it's childs * Validate this node and all it's childs
* @return {Array.<{node: Node, error: {message: string}}>} Returns a list with duplicates * @return {Array.<{node: Node, error: {message: string}}>} Returns a list with duplicates
@ -38433,18 +38515,18 @@ return /******/ (function(modules) { // webpackBootstrap
for (var j = 0; j < allSchemas.length; j++) { for (var j = 0; j < allSchemas.length; j++) {
childSchema = allSchemas[j]; childSchema = allSchemas[j];
if ('$ref' in childSchema && typeof childSchema['$ref'] === 'string') {
childSchema = schemaRefs[childSchema['$ref']];
if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, path);
}
}
for (var i = 0; i < path.length && childSchema; i++) { for (var i = 0; i < path.length && childSchema; i++) {
var nextPath = path.slice(i + 1, path.length); var nextPath = path.slice(i + 1, path.length);
var key = path[i]; var key = path[i];
// fix childSchema with $ref, and not display the select element on the child schema because of not found enum if (typeof key === 'string' && childSchema.patternProperties && !(childSchema.properties && key in childSchema.properties)) {
if (typeof key === 'string' && childSchema['$ref']) {
childSchema = schemaRefs[childSchema['$ref']];
if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath);
}
}
else if (typeof key === 'string' && childSchema.patternProperties && !(childSchema.properties && key in childSchema.properties)) {
for (var prop in childSchema.patternProperties) { for (var prop in childSchema.patternProperties) {
if (key.match(prop)) { if (key.match(prop)) {
foundSchema = Node._findSchema(childSchema.patternProperties[prop], schemaRefs, nextPath); foundSchema = Node._findSchema(childSchema.patternProperties[prop], schemaRefs, nextPath);
@ -38458,11 +38540,15 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
else if (typeof key === 'string' && childSchema.properties) { else if (typeof key === 'string' && childSchema.properties) {
childSchema = childSchema.properties[key] || null; if (!(key in childSchema.properties)) {
foundSchema = null;
} else {
childSchema = childSchema.properties[key];
if (childSchema) { if (childSchema) {
foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath); foundSchema = Node._findSchema(childSchema, schemaRefs, nextPath);
} }
} }
}
else if (typeof key === 'number' && childSchema.items) { else if (typeof key === 'number' && childSchema.items) {
childSchema = childSchema.items; childSchema = childSchema.items;
if (childSchema) { if (childSchema) {
@ -38472,6 +38558,12 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
// If the found schema is the input schema, the schema does not have the given path
if (foundSchema === schema && path.length > 0) {
return null;
}
return foundSchema return foundSchema
}; };
@ -38677,6 +38769,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (type == 'change' && target == dom.checkbox) { if (type == 'change' && target == dom.checkbox) {
this.dom.value.innerHTML = !this.value; this.dom.value.innerHTML = !this.value;
this._getDomValue(); this._getDomValue();
this._updateDomDefault();
} }
// update the value of the node based on the selected option // update the value of the node based on the selected option

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

File diff suppressed because one or more lines are too long

486
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "jsoneditor", "name": "jsoneditor",
"version": "5.31.1", "version": "5.32.0",
"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": [