Released v5.7.0

This commit is contained in:
jos 2017-05-26 16:17:34 +02:00
parent c20e24366e
commit 5f8b90f35e
9 changed files with 306 additions and 230 deletions

View File

@ -3,7 +3,7 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet released, version 5.7.0 ## 2017-05-26, version 5.7.0
- Implemented support for template items. Thanks @israelito3000. - Implemented support for template items. Thanks @israelito3000.

View File

@ -24,8 +24,8 @@
* Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org * Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org
* *
* @author Jos de Jong, <wjosdejong@gmail.com> * @author Jos de Jong, <wjosdejong@gmail.com>
* @version 5.6.0 * @version 5.7.0
* @date 2017-04-15 * @date 2017-05-26
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -165,7 +165,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (options) { if (options) {
var VALID_OPTIONS = [ var VALID_OPTIONS = [
'ace', 'theme', 'ace', 'theme',
'ajv', 'schema', 'ajv', 'schema','templates',
'onChange', 'onEditable', 'onError', 'onModeChange', 'onChange', 'onEditable', 'onError', 'onModeChange',
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys' 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys'
]; ];
@ -3895,7 +3895,11 @@ return /******/ (function(modules) { // webpackBootstrap
var height = ul.clientHeight; // force a reflow in Firefox var height = ul.clientHeight; // force a reflow in Firefox
setTimeout(function () { setTimeout(function () {
if (me.expandedItem == domItem) { if (me.expandedItem == domItem) {
ul.style.height = (ul.childNodes.length * 24) + 'px'; var childsHeight = 0;
for (var i = 0; i < ul.childNodes.length; i++) {
childsHeight += ul.childNodes[i].clientHeight;
}
ul.style.height = childsHeight + 'px';
ul.style.padding = '5px 10px'; ul.style.padding = '5px 10px';
} }
}, 0); }, 0);
@ -7215,6 +7219,32 @@ return /******/ (function(modules) { // webpackBootstrap
'but always returned as string.' 'but always returned as string.'
}; };
Node.prototype.addTemplates = function (menu, append) {
var node = this;
var templates = node.editor.options.templates;
if (templates == null) return;
if (templates.length) {
// create a separator
menu.push({
'type': 'separator'
});
}
var appendData = function (name, data) {
node._onAppend(name, data);
};
var insertData = function (name, data) {
node._onInsertBefore(name, data);
};
templates.forEach(function (template) {
menu.push({
text: template.text,
className: (template.className || 'jsoneditor-type-object'),
title: template.title,
click: (append ? appendData.bind(this, template.field, template.value) : insertData.bind(this, template.field, template.value))
});
});
};
/** /**
* Show a contextmenu for this node * Show a contextmenu for this node
* @param {HTMLElement} anchor Anchor element to attach the context menu to * @param {HTMLElement} anchor Anchor element to attach the context menu to
@ -7314,15 +7344,7 @@ return /******/ (function(modules) { // webpackBootstrap
// create append button (for last child node only) // create append button (for last child node only)
var childs = node.parent.childs; var childs = node.parent.childs;
if (node == childs[childs.length - 1]) { if (node == childs[childs.length - 1]) {
items.push({ var appendSubmenu = [
text: 'Append',
title: 'Append a new field with type \'auto\' after this field (Ctrl+Shift+Ins)',
submenuTitle: 'Select the type of the field to be appended',
className: 'jsoneditor-append',
click: function () {
node._onAppend('', '', 'auto');
},
submenu: [
{ {
text: 'Auto', text: 'Auto',
className: 'jsoneditor-type-auto', className: 'jsoneditor-type-auto',
@ -7355,20 +7377,24 @@ return /******/ (function(modules) { // webpackBootstrap
node._onAppend('', '', 'string'); node._onAppend('', '', 'string');
} }
} }
] ];
node.addTemplates(appendSubmenu, true);
items.push({
text: 'Append',
title: 'Append a new field with type \'auto\' after this field (Ctrl+Shift+Ins)',
submenuTitle: 'Select the type of the field to be appended',
className: 'jsoneditor-append',
click: function () {
node._onAppend('', '', 'auto');
},
submenu: appendSubmenu
}); });
} }
// create insert button // create insert button
items.push({ var insertSubmenu = [
text: 'Insert',
title: 'Insert a new field with type \'auto\' before this field (Ctrl+Ins)',
submenuTitle: 'Select the type of the field to be inserted',
className: 'jsoneditor-insert',
click: function () {
node._onInsertBefore('', '', 'auto');
},
submenu: [
{ {
text: 'Auto', text: 'Auto',
className: 'jsoneditor-type-auto', className: 'jsoneditor-type-auto',
@ -7401,7 +7427,17 @@ return /******/ (function(modules) { // webpackBootstrap
node._onInsertBefore('', '', 'string'); node._onInsertBefore('', '', 'string');
} }
} }
] ];
node.addTemplates(insertSubmenu, false);
items.push({
text: 'Insert',
title: 'Insert a new field with type \'auto\' before this field (Ctrl+Ins)',
submenuTitle: 'Select the type of the field to be inserted',
className: 'jsoneditor-insert',
click: function () {
node._onInsertBefore('', '', 'auto');
},
submenu: insertSubmenu
}); });
if (this.editable.field) { if (this.editable.field) {
@ -7765,50 +7801,52 @@ return /******/ (function(modules) { // webpackBootstrap
AppendNode.prototype.showContextMenu = function (anchor, onClose) { AppendNode.prototype.showContextMenu = function (anchor, onClose) {
var node = this; var node = this;
var titles = Node.TYPE_TITLES; var titles = Node.TYPE_TITLES;
var appendSubmenu = [
{
text: 'Auto',
className: 'jsoneditor-type-auto',
title: titles.auto,
click: function () {
node._onAppend('', '', 'auto');
}
},
{
text: 'Array',
className: 'jsoneditor-type-array',
title: titles.array,
click: function () {
node._onAppend('', []);
}
},
{
text: 'Object',
className: 'jsoneditor-type-object',
title: titles.object,
click: function () {
node._onAppend('', {});
}
},
{
text: 'String',
className: 'jsoneditor-type-string',
title: titles.string,
click: function () {
node._onAppend('', '', 'string');
}
}
];
node.addTemplates(appendSubmenu, true);
var items = [ var items = [
// create append button // create append button
{ {
'text': 'Append', 'text': 'Append!',
'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)', 'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)',
'submenuTitle': 'Select the type of the field to be appended', 'submenuTitle': 'Select the type of the field to be appended',
'className': 'jsoneditor-insert', 'className': 'jsoneditor-insert',
'click': function () { 'click': function () {
node._onAppend('', '', 'auto'); node._onAppend('', '', 'auto');
}, },
'submenu': [ 'submenu': appendSubmenu
{
'text': 'Auto',
'className': 'jsoneditor-type-auto',
'title': titles.auto,
'click': function () {
node._onAppend('', '', 'auto');
}
},
{
'text': 'Array',
'className': 'jsoneditor-type-array',
'title': titles.array,
'click': function () {
node._onAppend('', []);
}
},
{
'text': 'Object',
'className': 'jsoneditor-type-object',
'title': titles.object,
'click': function () {
node._onAppend('', {});
}
},
{
'text': 'String',
'className': 'jsoneditor-type-string',
'title': titles.string,
'click': function () {
node._onAppend('', '', 'string');
}
}
]
} }
]; ];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

156
dist/jsoneditor.js vendored
View File

@ -24,8 +24,8 @@
* Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org * Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org
* *
* @author Jos de Jong, <wjosdejong@gmail.com> * @author Jos de Jong, <wjosdejong@gmail.com>
* @version 5.6.0 * @version 5.7.0
* @date 2017-04-15 * @date 2017-05-26
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -165,7 +165,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (options) { if (options) {
var VALID_OPTIONS = [ var VALID_OPTIONS = [
'ace', 'theme', 'ace', 'theme',
'ajv', 'schema', 'ajv', 'schema','templates',
'onChange', 'onEditable', 'onError', 'onModeChange', 'onChange', 'onEditable', 'onError', 'onModeChange',
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys' 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys'
]; ];
@ -11924,7 +11924,11 @@ return /******/ (function(modules) { // webpackBootstrap
var height = ul.clientHeight; // force a reflow in Firefox var height = ul.clientHeight; // force a reflow in Firefox
setTimeout(function () { setTimeout(function () {
if (me.expandedItem == domItem) { if (me.expandedItem == domItem) {
ul.style.height = (ul.childNodes.length * 24) + 'px'; var childsHeight = 0;
for (var i = 0; i < ul.childNodes.length; i++) {
childsHeight += ul.childNodes[i].clientHeight;
}
ul.style.height = childsHeight + 'px';
ul.style.padding = '5px 10px'; ul.style.padding = '5px 10px';
} }
}, 0); }, 0);
@ -15244,6 +15248,32 @@ return /******/ (function(modules) { // webpackBootstrap
'but always returned as string.' 'but always returned as string.'
}; };
Node.prototype.addTemplates = function (menu, append) {
var node = this;
var templates = node.editor.options.templates;
if (templates == null) return;
if (templates.length) {
// create a separator
menu.push({
'type': 'separator'
});
}
var appendData = function (name, data) {
node._onAppend(name, data);
};
var insertData = function (name, data) {
node._onInsertBefore(name, data);
};
templates.forEach(function (template) {
menu.push({
text: template.text,
className: (template.className || 'jsoneditor-type-object'),
title: template.title,
click: (append ? appendData.bind(this, template.field, template.value) : insertData.bind(this, template.field, template.value))
});
});
};
/** /**
* Show a contextmenu for this node * Show a contextmenu for this node
* @param {HTMLElement} anchor Anchor element to attach the context menu to * @param {HTMLElement} anchor Anchor element to attach the context menu to
@ -15343,15 +15373,7 @@ return /******/ (function(modules) { // webpackBootstrap
// create append button (for last child node only) // create append button (for last child node only)
var childs = node.parent.childs; var childs = node.parent.childs;
if (node == childs[childs.length - 1]) { if (node == childs[childs.length - 1]) {
items.push({ var appendSubmenu = [
text: 'Append',
title: 'Append a new field with type \'auto\' after this field (Ctrl+Shift+Ins)',
submenuTitle: 'Select the type of the field to be appended',
className: 'jsoneditor-append',
click: function () {
node._onAppend('', '', 'auto');
},
submenu: [
{ {
text: 'Auto', text: 'Auto',
className: 'jsoneditor-type-auto', className: 'jsoneditor-type-auto',
@ -15384,20 +15406,24 @@ return /******/ (function(modules) { // webpackBootstrap
node._onAppend('', '', 'string'); node._onAppend('', '', 'string');
} }
} }
] ];
node.addTemplates(appendSubmenu, true);
items.push({
text: 'Append',
title: 'Append a new field with type \'auto\' after this field (Ctrl+Shift+Ins)',
submenuTitle: 'Select the type of the field to be appended',
className: 'jsoneditor-append',
click: function () {
node._onAppend('', '', 'auto');
},
submenu: appendSubmenu
}); });
} }
// create insert button // create insert button
items.push({ var insertSubmenu = [
text: 'Insert',
title: 'Insert a new field with type \'auto\' before this field (Ctrl+Ins)',
submenuTitle: 'Select the type of the field to be inserted',
className: 'jsoneditor-insert',
click: function () {
node._onInsertBefore('', '', 'auto');
},
submenu: [
{ {
text: 'Auto', text: 'Auto',
className: 'jsoneditor-type-auto', className: 'jsoneditor-type-auto',
@ -15430,7 +15456,17 @@ return /******/ (function(modules) { // webpackBootstrap
node._onInsertBefore('', '', 'string'); node._onInsertBefore('', '', 'string');
} }
} }
] ];
node.addTemplates(insertSubmenu, false);
items.push({
text: 'Insert',
title: 'Insert a new field with type \'auto\' before this field (Ctrl+Ins)',
submenuTitle: 'Select the type of the field to be inserted',
className: 'jsoneditor-insert',
click: function () {
node._onInsertBefore('', '', 'auto');
},
submenu: insertSubmenu
}); });
if (this.editable.field) { if (this.editable.field) {
@ -15794,50 +15830,52 @@ return /******/ (function(modules) { // webpackBootstrap
AppendNode.prototype.showContextMenu = function (anchor, onClose) { AppendNode.prototype.showContextMenu = function (anchor, onClose) {
var node = this; var node = this;
var titles = Node.TYPE_TITLES; var titles = Node.TYPE_TITLES;
var appendSubmenu = [
{
text: 'Auto',
className: 'jsoneditor-type-auto',
title: titles.auto,
click: function () {
node._onAppend('', '', 'auto');
}
},
{
text: 'Array',
className: 'jsoneditor-type-array',
title: titles.array,
click: function () {
node._onAppend('', []);
}
},
{
text: 'Object',
className: 'jsoneditor-type-object',
title: titles.object,
click: function () {
node._onAppend('', {});
}
},
{
text: 'String',
className: 'jsoneditor-type-string',
title: titles.string,
click: function () {
node._onAppend('', '', 'string');
}
}
];
node.addTemplates(appendSubmenu, true);
var items = [ var items = [
// create append button // create append button
{ {
'text': 'Append', 'text': 'Append!',
'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)', 'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)',
'submenuTitle': 'Select the type of the field to be appended', 'submenuTitle': 'Select the type of the field to be appended',
'className': 'jsoneditor-insert', 'className': 'jsoneditor-insert',
'click': function () { 'click': function () {
node._onAppend('', '', 'auto'); node._onAppend('', '', 'auto');
}, },
'submenu': [ 'submenu': appendSubmenu
{
'text': 'Auto',
'className': 'jsoneditor-type-auto',
'title': titles.auto,
'click': function () {
node._onAppend('', '', 'auto');
}
},
{
'text': 'Array',
'className': 'jsoneditor-type-array',
'title': titles.array,
'click': function () {
node._onAppend('', []);
}
},
{
'text': 'Object',
'className': 'jsoneditor-type-object',
'title': titles.object,
'click': function () {
node._onAppend('', {});
}
},
{
'text': 'String',
'className': 'jsoneditor-type-string',
'title': titles.string,
'click': function () {
node._onAppend('', '', 'string');
}
}
]
} }
]; ];

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

@ -54,10 +54,10 @@
title: 'Insert a Address Node', title: 'Insert a Address Node',
field: 'AddressTemplate', field: 'AddressTemplate',
value: { value: {
'street': "", 'street': '',
'city': "", 'city': '',
'state': "", 'state': '',
'ZIP code': "" 'ZIP code': ''
} }
} }
] ]

View File

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