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,26 +2457,30 @@ return /******/ (function(modules) { // webpackBootstrap
this.menu.appendChild(collapseAll); this.menu.appendChild(collapseAll);
// create sort button // create sort button
var sort = document.createElement('button'); if (this.options.enableSort) {
sort.type = 'button'; var sort = document.createElement('button');
sort.className = 'jsoneditor-sort'; sort.type = 'button';
sort.title = translate('sortTitleShort'); sort.className = 'jsoneditor-sort';
sort.onclick = function () { sort.title = translate('sortTitleShort');
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; sort.onclick = function () {
showSortModal(editor.node, anchor) var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
}; showSortModal(editor.node, anchor)
this.menu.appendChild(sort); };
this.menu.appendChild(sort);
}
// create transform button // create transform button
var transform = document.createElement('button'); if (this.options.enableTransform) {
transform.type = 'button'; var transform = document.createElement('button');
transform.title = translate('transformTitleShort'); transform.type = 'button';
transform.className = 'jsoneditor-transform'; transform.title = translate('transformTitleShort');
transform.onclick = function () { transform.className = 'jsoneditor-transform';
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; transform.onclick = function () {
showTransformModal(editor.node, anchor) var anchor = editor.options.modalAnchor || DEFAULT_MODAL_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,25 +11018,29 @@ return /******/ (function(modules) { // webpackBootstrap
} }
if (this._hasChilds()) { if (this._hasChilds()) {
items.push({ if (this.editor.options.enableSort) {
text: translate('sort'), items.push({
title: translate('sortTitle', {type: this.type}), text: translate('sort'),
className: 'jsoneditor-sort-asc', title: translate('sortTitle', {type: this.type}),
click: function () { className: 'jsoneditor-sort-asc',
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; click: function () {
showSortModal(node, anchor) var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
} showSortModal(node, anchor)
}); }
});
}
items.push({ if (this.editor.options.enableTransform) {
text: translate('transform'), items.push({
title: translate('transformTitle', {type: this.type}), text: translate('transform'),
className: 'jsoneditor-transform', title: translate('transformTitle', {type: this.type}),
click: function () { className: 'jsoneditor-transform',
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; click: function () {
showTransformModal(node, anchor) var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
} showTransformModal(node, anchor)
}); }
});
}
} }
if (this.parent && this.parent._hasChilds()) { if (this.parent && this.parent._hasChilds()) {
@ -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
this.parseErrorIndication.style.display = 'none'; if (this.parseErrorIndication) {
this.parseErrorIndication.style.display = 'none';
}
doValidate = true; doValidate = true;
} }
catch (err) { catch (err) {
if (this.getText()) { if (this.getText()) {
this.parseErrorIndication.style.display = 'block'; if (this.parseErrorIndication) {
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];
} }
this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid'; if (this.parseErrorIndication) {
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

139
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,26 +31099,30 @@ return /******/ (function(modules) { // webpackBootstrap
this.menu.appendChild(collapseAll); this.menu.appendChild(collapseAll);
// create sort button // create sort button
var sort = document.createElement('button'); if (this.options.enableSort) {
sort.type = 'button'; var sort = document.createElement('button');
sort.className = 'jsoneditor-sort'; sort.type = 'button';
sort.title = translate('sortTitleShort'); sort.className = 'jsoneditor-sort';
sort.onclick = function () { sort.title = translate('sortTitleShort');
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; sort.onclick = function () {
showSortModal(editor.node, anchor) var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
}; showSortModal(editor.node, anchor)
this.menu.appendChild(sort); };
this.menu.appendChild(sort);
}
// create transform button // create transform button
var transform = document.createElement('button'); if (this.options.enableTransform) {
transform.type = 'button'; var transform = document.createElement('button');
transform.title = translate('transformTitleShort'); transform.type = 'button';
transform.className = 'jsoneditor-transform'; transform.title = translate('transformTitleShort');
transform.onclick = function () { transform.className = 'jsoneditor-transform';
var anchor = editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; transform.onclick = function () {
showTransformModal(editor.node, anchor) var anchor = editor.options.modalAnchor || DEFAULT_MODAL_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,25 +39660,29 @@ return /******/ (function(modules) { // webpackBootstrap
} }
if (this._hasChilds()) { if (this._hasChilds()) {
items.push({ if (this.editor.options.enableSort) {
text: translate('sort'), items.push({
title: translate('sortTitle', {type: this.type}), text: translate('sort'),
className: 'jsoneditor-sort-asc', title: translate('sortTitle', {type: this.type}),
click: function () { className: 'jsoneditor-sort-asc',
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; click: function () {
showSortModal(node, anchor) var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
} showSortModal(node, anchor)
}); }
});
}
items.push({ if (this.editor.options.enableTransform) {
text: translate('transform'), items.push({
title: translate('transformTitle', {type: this.type}), text: translate('transform'),
className: 'jsoneditor-transform', title: translate('transformTitle', {type: this.type}),
click: function () { className: 'jsoneditor-transform',
var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR; click: function () {
showTransformModal(node, anchor) var anchor = node.editor.options.modalAnchor || DEFAULT_MODAL_ANCHOR;
} showTransformModal(node, anchor)
}); }
});
}
} }
if (this.parent && this.parent._hasChilds()) { if (this.parent && this.parent._hasChilds()) {
@ -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
this.parseErrorIndication.style.display = 'none'; if (this.parseErrorIndication) {
this.parseErrorIndication.style.display = 'none';
}
doValidate = true; doValidate = true;
} }
catch (err) { catch (err) {
if (this.getText()) { if (this.getText()) {
this.parseErrorIndication.style.display = 'block'; if (this.parseErrorIndication) {
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];
} }
this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid'; if (this.parseErrorIndication) {
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": [