Publish v5.25.0

This commit is contained in:
jos 2018-10-29 20:31:10 +01:00
parent d0b49fbf12
commit 4e24601823
8 changed files with 201 additions and 127 deletions

View File

@ -3,7 +3,7 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet released, version 5.25.0 ## 2018-10-29, version 5.25.0
- Implemented options `enableSort` and `enableTransform` so you can turn off - Implemented options `enableSort` and `enableTransform` so you can turn off
these features. Thanks @tanmayrajani. these features. Thanks @tanmayrajani.

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.24.7 * @version 5.25.0
* @date 2018-10-08 * @date 2018-10-29
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -252,7 +252,7 @@ return /******/ (function(modules) { // webpackBootstrap
'colorPicker', 'onColorPicker', 'colorPicker', 'onColorPicker',
'timestampTag', 'timestampTag',
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language' 'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language', 'enableSort', 'enableTransform'
]; ];
/** /**
@ -1614,7 +1614,9 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}, },
timestampTag: true, timestampTag: true,
onEvent: null onEvent: null,
enableSort: true,
enableTransform: true
}; };
// copy all options // copy all options
@ -1949,9 +1951,27 @@ return /******/ (function(modules) { // webpackBootstrap
return; return;
} }
// selection can be changed after undo/redo
this.selection = this.getDomSelection();
// validate JSON schema (if configured) // validate JSON schema (if configured)
this._debouncedValidate(); this._debouncedValidate();
if (this.treePath) {
var selectedNode = this.selection
? this.node.findNodeByInternalPath(this.selection.path)
: this.multiselection
? this.multiselection.nodes[0]
: undefined;
if (selectedNode) {
this._updateTreePath(selectedNode.getNodePath())
}
else {
this.treePath.reset()
}
}
// trigger the onChange callback // trigger the onChange callback
if (this.options.onChange) { if (this.options.onChange) {
try { try {
@ -2437,6 +2457,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.menu.appendChild(collapseAll); this.menu.appendChild(collapseAll);
// create sort button // create sort button
if (this.options.enableSort) {
var sort = document.createElement('button'); var sort = document.createElement('button');
sort.type = 'button'; sort.type = 'button';
sort.className = 'jsoneditor-sort'; sort.className = 'jsoneditor-sort';
@ -2446,8 +2467,10 @@ return /******/ (function(modules) { // webpackBootstrap
showSortModal(editor.node, anchor) showSortModal(editor.node, anchor)
}; };
this.menu.appendChild(sort); this.menu.appendChild(sort);
}
// create transform button // create transform button
if (this.options.enableTransform) {
var transform = document.createElement('button'); var transform = document.createElement('button');
transform.type = 'button'; transform.type = 'button';
transform.title = translate('transformTitleShort'); transform.title = translate('transformTitleShort');
@ -2457,6 +2480,7 @@ return /******/ (function(modules) { // webpackBootstrap
showTransformModal(editor.node, anchor) showTransformModal(editor.node, anchor)
}; };
this.menu.appendChild(transform); this.menu.appendChild(transform);
}
// create undo/redo buttons // create undo/redo buttons
if (this.history) { if (this.history) {
@ -2511,7 +2535,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.navBar.className = 'jsoneditor-navigation-bar nav-bar-empty'; this.navBar.className = 'jsoneditor-navigation-bar nav-bar-empty';
this.frame.appendChild(this.navBar); this.frame.appendChild(this.navBar);
this.treePath = new TreePath(this.navBar); this.treePath = new TreePath(this.navBar, this.frame);
this.treePath.onSectionSelected(this._onTreePathSectionSelected.bind(this)); this.treePath.onSectionSelected(this._onTreePathSectionSelected.bind(this));
this.treePath.onContextMenuItemSelected(this._onTreePathMenuItemSelected.bind(this)); this.treePath.onContextMenuItemSelected(this._onTreePathMenuItemSelected.bind(this));
} }
@ -2752,6 +2776,7 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
} }
event.preventDefault();
}; };
/** /**
@ -3081,7 +3106,7 @@ return /******/ (function(modules) { // webpackBootstrap
*/ */
treemode.showContextMenu = function (anchor, onClose) { treemode.showContextMenu = function (anchor, onClose) {
var items = []; var items = [];
var editor = this; var selectedNodes = this.multiselection.nodes.slice();
// create duplicate button // create duplicate button
items.push({ items.push({
@ -3089,7 +3114,7 @@ return /******/ (function(modules) { // webpackBootstrap
title: translate('duplicateTitle'), title: translate('duplicateTitle'),
className: 'jsoneditor-duplicate', className: 'jsoneditor-duplicate',
click: function () { click: function () {
Node.onDuplicate(editor.multiselection.nodes); Node.onDuplicate(selectedNodes );
} }
}); });
@ -3099,12 +3124,12 @@ return /******/ (function(modules) { // webpackBootstrap
title: translate('removeTitle'), title: translate('removeTitle'),
className: 'jsoneditor-remove', className: 'jsoneditor-remove',
click: function () { click: function () {
Node.onRemove(editor.multiselection.nodes); Node.onRemove(selectedNodes);
} }
}); });
var menu = new ContextMenu(items, {close: onClose}); var menu = new ContextMenu(items, {close: onClose});
menu.show(anchor, editor.frame); menu.show(anchor, this.frame);
}; };
/** /**
@ -6714,10 +6739,12 @@ return /******/ (function(modules) { // webpackBootstrap
/** /**
* Creates a component that visualize path selection in tree based editors * Creates a component that visualize path selection in tree based editors
* @param {HTMLElement} container * @param {HTMLElement} container
* @param {HTMLElement} root
* @constructor * @constructor
*/ */
function TreePath(container) { function TreePath(container, root) {
if (container) { if (container) {
this.root = root;
this.path = document.createElement('div'); this.path = document.createElement('div');
this.path.className = 'jsoneditor-treepath'; this.path.className = 'jsoneditor-treepath';
container.appendChild(this.path); container.appendChild(this.path);
@ -6767,10 +6794,10 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
}); });
var menu = new ContextMenu(items); var menu = new ContextMenu(items);
menu.show(sepEl); menu.show(sepEl, me.root);
}; };
me.path.appendChild(sepEl, me.container); me.path.appendChild(sepEl);
} }
if(idx === pathObjs.length - 1) { if(idx === pathObjs.length - 1) {
@ -10991,6 +11018,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
if (this._hasChilds()) { if (this._hasChilds()) {
if (this.editor.options.enableSort) {
items.push({ items.push({
text: translate('sort'), text: translate('sort'),
title: translate('sortTitle', {type: this.type}), title: translate('sortTitle', {type: this.type}),
@ -11000,7 +11028,9 @@ return /******/ (function(modules) { // webpackBootstrap
showSortModal(node, anchor) showSortModal(node, anchor)
} }
}); });
}
if (this.editor.options.enableTransform) {
items.push({ items.push({
text: translate('transform'), text: translate('transform'),
title: translate('transformTitle', {type: this.type}), title: translate('transformTitle', {type: this.type}),
@ -11011,6 +11041,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}); });
} }
}
if (this.parent && this.parent._hasChilds()) { if (this.parent && this.parent._hasChilds()) {
if (items.length) { if (items.length) {
@ -17897,19 +17928,25 @@ return /******/ (function(modules) { // webpackBootstrap
var json; var json;
try { try {
json = this.get(); // this can fail when there is no valid json json = this.get(); // this can fail when there is no valid json
if (this.parseErrorIndication) {
this.parseErrorIndication.style.display = 'none'; this.parseErrorIndication.style.display = 'none';
}
doValidate = true; doValidate = true;
} }
catch (err) { catch (err) {
if (this.getText()) { if (this.getText()) {
if (this.parseErrorIndication) {
this.parseErrorIndication.style.display = 'block'; this.parseErrorIndication.style.display = 'block';
}
// try to extract the line number from the jsonlint error message // try to extract the line number from the jsonlint error message
var match = /\w*line\s*(\d+)\w*/g.exec(err.message); var match = /\w*line\s*(\d+)\w*/g.exec(err.message);
var line; var line;
if (match) { if (match) {
line = +match[1]; line = +match[1];
} }
if (this.parseErrorIndication) {
this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid'; this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid';
}
parseErrors.push({ parseErrors.push({
type: 'error', type: 'error',
message: err.message.replace(/\n/g, '<br>'), message: err.message.replace(/\n/g, '<br>'),

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

61
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.24.7 * @version 5.25.0
* @date 2018-10-08 * @date 2018-10-29
*/ */
(function webpackUniversalModuleDefinition(root, factory) { (function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -252,7 +252,7 @@ return /******/ (function(modules) { // webpackBootstrap
'colorPicker', 'onColorPicker', 'colorPicker', 'onColorPicker',
'timestampTag', 'timestampTag',
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language' 'sortObjectKeys', 'navigationBar', 'statusBar', 'languages', 'language', 'enableSort', 'enableTransform'
]; ];
/** /**
@ -30256,7 +30256,9 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}, },
timestampTag: true, timestampTag: true,
onEvent: null onEvent: null,
enableSort: true,
enableTransform: true
}; };
// copy all options // copy all options
@ -30591,9 +30593,27 @@ return /******/ (function(modules) { // webpackBootstrap
return; return;
} }
// selection can be changed after undo/redo
this.selection = this.getDomSelection();
// validate JSON schema (if configured) // validate JSON schema (if configured)
this._debouncedValidate(); this._debouncedValidate();
if (this.treePath) {
var selectedNode = this.selection
? this.node.findNodeByInternalPath(this.selection.path)
: this.multiselection
? this.multiselection.nodes[0]
: undefined;
if (selectedNode) {
this._updateTreePath(selectedNode.getNodePath())
}
else {
this.treePath.reset()
}
}
// trigger the onChange callback // trigger the onChange callback
if (this.options.onChange) { if (this.options.onChange) {
try { try {
@ -31079,6 +31099,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.menu.appendChild(collapseAll); this.menu.appendChild(collapseAll);
// create sort button // create sort button
if (this.options.enableSort) {
var sort = document.createElement('button'); var sort = document.createElement('button');
sort.type = 'button'; sort.type = 'button';
sort.className = 'jsoneditor-sort'; sort.className = 'jsoneditor-sort';
@ -31088,8 +31109,10 @@ return /******/ (function(modules) { // webpackBootstrap
showSortModal(editor.node, anchor) showSortModal(editor.node, anchor)
}; };
this.menu.appendChild(sort); this.menu.appendChild(sort);
}
// create transform button // create transform button
if (this.options.enableTransform) {
var transform = document.createElement('button'); var transform = document.createElement('button');
transform.type = 'button'; transform.type = 'button';
transform.title = translate('transformTitleShort'); transform.title = translate('transformTitleShort');
@ -31099,6 +31122,7 @@ return /******/ (function(modules) { // webpackBootstrap
showTransformModal(editor.node, anchor) showTransformModal(editor.node, anchor)
}; };
this.menu.appendChild(transform); this.menu.appendChild(transform);
}
// create undo/redo buttons // create undo/redo buttons
if (this.history) { if (this.history) {
@ -31153,7 +31177,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.navBar.className = 'jsoneditor-navigation-bar nav-bar-empty'; this.navBar.className = 'jsoneditor-navigation-bar nav-bar-empty';
this.frame.appendChild(this.navBar); this.frame.appendChild(this.navBar);
this.treePath = new TreePath(this.navBar); this.treePath = new TreePath(this.navBar, this.frame);
this.treePath.onSectionSelected(this._onTreePathSectionSelected.bind(this)); this.treePath.onSectionSelected(this._onTreePathSectionSelected.bind(this));
this.treePath.onContextMenuItemSelected(this._onTreePathMenuItemSelected.bind(this)); this.treePath.onContextMenuItemSelected(this._onTreePathMenuItemSelected.bind(this));
} }
@ -31394,6 +31418,7 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
} }
event.preventDefault();
}; };
/** /**
@ -31723,7 +31748,7 @@ return /******/ (function(modules) { // webpackBootstrap
*/ */
treemode.showContextMenu = function (anchor, onClose) { treemode.showContextMenu = function (anchor, onClose) {
var items = []; var items = [];
var editor = this; var selectedNodes = this.multiselection.nodes.slice();
// create duplicate button // create duplicate button
items.push({ items.push({
@ -31731,7 +31756,7 @@ return /******/ (function(modules) { // webpackBootstrap
title: translate('duplicateTitle'), title: translate('duplicateTitle'),
className: 'jsoneditor-duplicate', className: 'jsoneditor-duplicate',
click: function () { click: function () {
Node.onDuplicate(editor.multiselection.nodes); Node.onDuplicate(selectedNodes );
} }
}); });
@ -31741,12 +31766,12 @@ return /******/ (function(modules) { // webpackBootstrap
title: translate('removeTitle'), title: translate('removeTitle'),
className: 'jsoneditor-remove', className: 'jsoneditor-remove',
click: function () { click: function () {
Node.onRemove(editor.multiselection.nodes); Node.onRemove(selectedNodes);
} }
}); });
var menu = new ContextMenu(items, {close: onClose}); var menu = new ContextMenu(items, {close: onClose});
menu.show(anchor, editor.frame); menu.show(anchor, this.frame);
}; };
/** /**
@ -35356,10 +35381,12 @@ return /******/ (function(modules) { // webpackBootstrap
/** /**
* Creates a component that visualize path selection in tree based editors * Creates a component that visualize path selection in tree based editors
* @param {HTMLElement} container * @param {HTMLElement} container
* @param {HTMLElement} root
* @constructor * @constructor
*/ */
function TreePath(container) { function TreePath(container, root) {
if (container) { if (container) {
this.root = root;
this.path = document.createElement('div'); this.path = document.createElement('div');
this.path.className = 'jsoneditor-treepath'; this.path.className = 'jsoneditor-treepath';
container.appendChild(this.path); container.appendChild(this.path);
@ -35409,10 +35436,10 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
}); });
var menu = new ContextMenu(items); var menu = new ContextMenu(items);
menu.show(sepEl); menu.show(sepEl, me.root);
}; };
me.path.appendChild(sepEl, me.container); me.path.appendChild(sepEl);
} }
if(idx === pathObjs.length - 1) { if(idx === pathObjs.length - 1) {
@ -39633,6 +39660,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
if (this._hasChilds()) { if (this._hasChilds()) {
if (this.editor.options.enableSort) {
items.push({ items.push({
text: translate('sort'), text: translate('sort'),
title: translate('sortTitle', {type: this.type}), title: translate('sortTitle', {type: this.type}),
@ -39642,7 +39670,9 @@ return /******/ (function(modules) { // webpackBootstrap
showSortModal(node, anchor) showSortModal(node, anchor)
} }
}); });
}
if (this.editor.options.enableTransform) {
items.push({ items.push({
text: translate('transform'), text: translate('transform'),
title: translate('transformTitle', {type: this.type}), title: translate('transformTitle', {type: this.type}),
@ -39653,6 +39683,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}); });
} }
}
if (this.parent && this.parent._hasChilds()) { if (this.parent && this.parent._hasChilds()) {
if (items.length) { if (items.length) {
@ -46539,19 +46570,25 @@ return /******/ (function(modules) { // webpackBootstrap
var json; var json;
try { try {
json = this.get(); // this can fail when there is no valid json json = this.get(); // this can fail when there is no valid json
if (this.parseErrorIndication) {
this.parseErrorIndication.style.display = 'none'; this.parseErrorIndication.style.display = 'none';
}
doValidate = true; doValidate = true;
} }
catch (err) { catch (err) {
if (this.getText()) { if (this.getText()) {
if (this.parseErrorIndication) {
this.parseErrorIndication.style.display = 'block'; this.parseErrorIndication.style.display = 'block';
}
// try to extract the line number from the jsonlint error message // try to extract the line number from the jsonlint error message
var match = /\w*line\s*(\d+)\w*/g.exec(err.message); var match = /\w*line\s*(\d+)\w*/g.exec(err.message);
var line; var line;
if (match) { if (match) {
line = +match[1]; line = +match[1];
} }
if (this.parseErrorIndication) {
this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid'; this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid';
}
parseErrors.push({ parseErrors.push({
type: 'error', type: 'error',
message: err.message.replace(/\n/g, '<br>'), message: err.message.replace(/\n/g, '<br>'),

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.24.7", "version": "5.25.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": [