jsoneditor/dist/jsoneditor-minimalist.min.js

35 lines
270 KiB
JavaScript
Raw Normal View History

2017-07-04 01:23:32 +08:00
/*!
* jsoneditor.js
*
* @brief
* JSONEditor is a web-based tool to view, edit, format, and validate JSON.
* It has various modes such as a tree editor, a code editor, and a plain text
* editor.
*
* Supported browsers: Chrome, Firefox, Safari, Opera, Internet Explorer 8+
*
* @license
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
* Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org
*
* @author Jos de Jong, <wjosdejong@gmail.com>
2018-10-30 03:31:10 +08:00
* @version 5.25.0
* @date 2018-10-29
2017-07-04 01:23:32 +08:00
*/
2018-10-30 03:31:10 +08:00
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JSONEditor=t():e.JSONEditor=t()}(this,function(){return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e,t,n){if(!(this instanceof i))throw new Error('JSONEditor constructor called without "new".');var o=c.getInternetExplorerVersion();if(-1!=o&&o<9)throw new Error("Unsupported browser, IE9 or newer required. Please install the newest version of your browser.");t&&(t.error&&(console.warn('Option "error" has been renamed to "onError"'),t.onError=t.error,delete t.error),t.change&&(console.warn('Option "change" has been renamed to "onChange"'),t.onChange=t.change,delete t.change),t.editable&&(console.warn('Option "editable" has been renamed to "onEditable"'),t.onEditable=t.editable,delete t.editable),t.onChangeJSON&&("text"===t.mode||"code"===t.mode||t.modes&&(-1!==t.modes.indexOf("text")||-1!==t.modes.indexOf("code")))&&console.warn('Option "onChangeJSON" is not applicable to modes "text" and "code". Use "onChangeText" or "onChange" instead.'),t&&Object.keys(t).forEach(function(e){-1===i.VALID_OPTIONS.indexOf(e)&&console.warn('Unknown option "'+e+'". This option will be ignored')})),arguments.length&&this._create(e,t,n)}var o;try{o=n(!function(){var e=new Error('Cannot find module "ajv"');throw e.code="MODULE_NOT_FOUND",e}())}catch(e){}var r=n(1),s=n(5),a=n(6),l=n(28),c=n(12);"undefined"==typeof Promise&&console.error("Promise undefined. Please load a Promise polyfill in the browser in order to use JSONEditor"),i.modes={},i.prototype.DEBOUNCE_INTERVAL=150,i.VALID_OPTIONS=["ajv","schema","schemaRefs","templates","ace","theme","autocomplete","onChange","onChangeJSON","onChangeText","onEditable","onError","onEvent","onModeChange","onValidate","onSelectionChange","onTextSelectionChange","colorPicker","onColorPicker","timestampTag","escapeUnicode","history","search","mode","modes","name","indentation","sortObjectKeys","navigationBar","statusBar","languages","language","enableSort","enableTransform"],i.prototype._create=function(e,t,n){this.container=e,this.options=t||{},this.json=n||{};var i=this.options.mode||this.options.modes&&this.options.modes[0]||"tree";this.setMode(i)},i.prototype.destroy=function(){},i.prototype.set=function(e){this.json=e},i.prototype.get=function(){return this.json},i.prototype.setText=function(e){this.json=c.parse(e)},i.prototype.getText=function(){return JSON.stringify(this.json)},i.prototype.setName=function(e){this.options||(this.options={}),this.options.name=e},i.prototype.getName=function(){return this.options&&this.options.name},i.prototype.setMode=function(e){if(e!==this.options.mode||!this.create){var t,n,o=this.container,r=c.extend({},this.options),s=r.mode;r.mode=e;var a=i.modes[e];if(!a)throw new Error('Unknown mode "'+r.mode+'"');try{var l="text"==a.data;if(n=this.getName(),t=this[l?"getText":"get"](),this.destroy(),c.clear(this),c.extend(this,a.mixin),this.create(o,r),this.setName(n),this[l?"setText":"set"](t),"function"==typeof a.load)try{a.load.call(this)}catch(e){console.error(e)}if("function"==typeof r.onModeChange&&e!==s)try{r.onModeChange(e,s)}catch(e){console.error(e)}}catch(e){this._onError(e)}}},i.prototype.getMode=function(){return this.options.mode},i.prototype._onError=function(e){if(!this.options||"function"!=typeof this.options.onError)throw e;this.options.onError(e)},i.prototype.setSchema=function(e,t){if(e){var n;try{n=this.options.ajv||o({allErrors:!0,verbose:!0})}catch(e){console.warn("Failed to create an instance of Ajv, JSON Schema validation is not available. Please use a JSONEditor bundle including Ajv, or pass an instance of Ajv as via the configuration option `ajv`.")}if(n){if(t){for(var i in t)n.removeSchema(i),t[i]&&n.addSchema(t[i],i);this.options.schemaRefs=t}this.validateSchema=n.compile(e),this.options.sc
wholeWord:this.wholeWordOption.checked}),t=!e&&this.searchInput.value;i.setCssClass(this.searchBox,"ace_nomatch",t),this.editor._emit("findSearchBox",{match:!t}),this.highlight(),this.hide()},this.replace=function(){this.editor.getReadOnly()||this.editor.replace(this.replaceInput.value)},this.replaceAndFindNext=function(){this.editor.getReadOnly()||(this.editor.replace(this.replaceInput.value),this.findNext())},this.replaceAll=function(){this.editor.getReadOnly()||this.editor.replaceAll(this.replaceInput.value)},this.hide=function(){this.active=!1,this.setSearchRange(null),this.editor.off("changeSession",this.setSession),this.element.style.display="none",this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb),this.editor.focus()},this.show=function(e,t){this.active=!0,this.editor.on("changeSession",this.setSession),this.element.style.display="",this.replaceOption.checked=t,e&&(this.searchInput.value=e),this.searchInput.focus(),this.searchInput.select(),this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb),this.$syncOptions(!0)},this.isFocused=function(){var e=document.activeElement;return e==this.searchInput||e==this.replaceInput}}).call(c.prototype),t.SearchBox=c,t.Search=function(e,t){(e.searchBox||new c(e)).show(e.session.getTextRange(),t)}}),function(){ace.acequire(["ace/ext/searchbox"],function(){})}()},function(e,t,n){var i;if(window.Picker)i=window.Picker;else try{i=n(!function(){var e=new Error('Cannot find module "vanilla-picker/dist/vanilla-picker"');throw e.code="MODULE_NOT_FOUND",e}())}catch(e){}e.exports=i},function(e,t,n){"use strict";var i=n(5),o=n(7),r=n(8),s=n(9),a=n(10),l=n(16),c=n(17),h=n(26),d=n(12),u=n(27),p=n(22),f=n(24),m=n(15).translate,g=n(15).setLanguages,v=n(15).setLanguage,y=document.body,b={};b.create=function(e,t){if(!e)throw new Error("No container element provided.");this.container=e,this.dom={},this.highlighter=new o,this.selection=void 0,this.multiselection={nodes:[]},this.validateSchema=null,this.validationSequence=0,this.errorNodes=[],this.node=null,this.focusTarget=null,this._setOptions(t),t.autocomplete&&(this.autocomplete=new u(t.autocomplete)),this.options.history&&"view"!==this.options.mode&&(this.history=new r(this)),this._createFrame(),this._createTable()},b.destroy=function(){this.frame&&this.container&&this.frame.parentNode==this.container&&(this.container.removeChild(this.frame),this.frame=null),this.container=null,this.dom=null,this.clear(),this.node=null,this.focusTarget=null,this.selection=null,this.multiselection=null,this.errorNodes=null,this.validateSchema=null,this._debouncedValidate=null,this.history&&(this.history.destroy(),this.history=null),this.searchBox&&(this.searchBox.destroy(),this.searchBox=null),this.modeSwitcher&&(this.modeSwitcher.destroy(),this.modeSwitcher=null)},b._setOptions=function(e){if(this.options={search:!0,history:!0,mode:"tree",name:void 0,schema:null,schemaRefs:null,autocomplete:null,navigationBar:!0,onSelectionChange:null,colorPicker:!0,onColorPicker:function(e,t,n){i?new i({parent:e,color:t,popup:"bottom",onDone:function(e){var t=e.rgba[3],i=1===t?e.hex.substr(0,7):e.hex;n(i)}}).show():console.warn("Cannot open color picker: the `vanilla-picker` library is not included in the bundle. Either use the full bundle or implement your own color picker using `onColorPicker`.")},timestampTag:!0,onEvent:null,enableSort:!0,enableTransform:!0},e)for(var t in e)e.hasOwnProperty(t)&&(this.options[t]=e[t]);this.setSchema(this.options.schema,this.options.schemaRefs),this._debouncedValidate=d.debounce(this.validate.bind(this),this.DEBOUNCE_INTERVAL),e.onSelectionChange&&this.onSelectionChange(e.onSelectionChange),g(this.options.languages),v(this.options.language)},b.set=function(e){if(e instanceof Function||void 0===e)this.clear();else{this.content.removeChild(this.table);var t={field:this.options.name,value:e},n=new c(this,t);this._setRoot(n),this.validate();this.node.expand(!1),this.content.appendChild(this.table)}this.history&&this.history.clear(),this.searchBox&&this.searchBox.clear()},b.update=function(e){if(!this.node.deepEqua
stringType:'Campo do tipo "string". Campo do tipo nao é determinado através do seu valor, mas sempre retornara um texto.'}},r="undefined"!=typeof navigator?navigator.language||navigator.userLanguage:void 0;n=i.find(function(e){return e===r}),n||(n="en"),e.exports={_locales:i,_defs:o,_lang:n,setLanguage:function(e){if(e){var t=i.find(function(t){return t===e});t?n=t:console.error("Language not found")}},setLanguages:function(e){if(e)for(var t in e){var n=i.find(function(e){return e===t});n||i.push(t),o[t]=Object.assign({},o.en,o[t],e[t])}},translate:function(e,t,i){i||(i=n);var r=o[i][e];if(t)for(e in t)r=r.replace("${"+e+"}",t[e]);return r||e}}},function(e,t,n){"use strict";function i(e,t){e&&(this.root=t,this.path=document.createElement("div"),this.path.className="jsoneditor-treepath",e.appendChild(this.path),this.reset())}var o=n(10),r=n(15).translate;i.prototype.reset=function(){this.path.innerHTML=r("selectNode")},i.prototype.setPath=function(e){function t(e){this.selectionCallback&&this.selectionCallback(e)}function n(e,t){this.contextMenuCallback&&this.contextMenuCallback(e,t)}var i=this;this.path.innerHTML="",e&&e.length&&e.forEach(function(r,s){var a,l=document.createElement("span");if(l.className="jsoneditor-treepath-element",l.innerText=r.name,l.onclick=t.bind(i,r),i.path.appendChild(l),r.children.length&&(a=document.createElement("span"),a.className="jsoneditor-treepath-seperator",a.innerHTML="&#9658;",a.onclick=function(){var t=[];r.children.forEach(function(o){t.push({text:o.name,className:"jsoneditor-type-modes"+(e[s+1]+1&&e[s+1].name===o.name?" jsoneditor-selected":""),click:n.bind(i,r,o.name)})}),new o(t).show(a,i.root)},i.path.appendChild(a)),s===e.length-1){var c=(a||l).getBoundingClientRect().left;i.path.offsetWidth<c&&(i.path.scrollLeft=c)}})},i.prototype.onSectionSelected=function(e){"function"==typeof e&&(this.selectionCallback=e)},i.prototype.onContextMenuItemSelected=function(e){"function"==typeof e&&(this.contextMenuCallback=e)},e.exports=i},function(e,t,n){"use strict";function i(e,t){this.editor=e,this.dom={},this.expanded=!1,t&&t instanceof Object?(this.setField(t.field,t.fieldEditable),"value"in t&&this.setValue(t.value,t.type),"internalValue"in t&&this.setInternalValue(t.internalValue)):(this.setField(""),this.setValue(null)),this._debouncedOnChangeValue=f.debounce(this._onChangeValue.bind(this),i.prototype.DEBOUNCE_INTERVAL),this._debouncedOnChangeField=f.debounce(this._onChangeField.bind(this),i.prototype.DEBOUNCE_INTERVAL)}function o(e){return e.getInternalPath()}function r(e){return e.getField()}var s=n(18),a=n(19),l=n(11).createAbsoluteAnchor,c=n(10),h=n(20),d=n(21),u=n(22),p=n(24),f=n(12),m=n(15).translate,g=document.body;i.prototype.DEBOUNCE_INTERVAL=150,i.prototype.MAX_SEARCH_RESULTS=999,i.prototype.MAX_VISIBLE_CHILDS=100,i.prototype.visibleChilds=i.prototype.MAX_VISIBLE_CHILDS,i.prototype._updateEditability=function(){if(this.editable={field:!0,value:!0},this.editor&&(this.editable.field="tree"===this.editor.options.mode,this.editable.value="view"!==this.editor.options.mode,("tree"===this.editor.options.mode||"form"===this.editor.options.mode)&&"function"==typeof this.editor.options.onEditable)){var e=this.editor.options.onEditable({field:this.field,value:this.value,path:this.getPath()});"boolean"==typeof e?(this.editable.field=e,this.editable.value=e):("boolean"==typeof e.field&&(this.editable.field=e.field),"boolean"==typeof e.value&&(this.editable.value=e.value))}},i.prototype.getPath=function(){for(var e=this,t=[];e;){var n=e.getName();void 0!==n&&t.unshift(n),e=e.parent}return t},i.prototype.getInternalPath=function(){for(var e=this,t=[];e;)e.parent&&t.unshift(e.getIndex()),e=e.parent;return t},i.prototype.getName=function(){return this.parent?"array"!=this.parent.type?this.field:this.index:void 0},i.prototype.findNodeByPath=function(e){if(e){if(0==e.length)return this;if(e.length&&this.childs&&this.childs.length)for(var t=0;t<this.childs.length;++t)if(""+e[0]==""+this.childs[t].getName())return this.childs[t].findNodeByPath(e.slice(1))}},i.prototype.findNodeByInternalPath=f
case"LT":case"LTE":return this._parseComparator(t,e);case"Lbracket":var l=this._lookaheadToken(0);return"Number"===l.type||"Colon"===l.type?(n=this._parseIndexExpression(),this._projectIfSlice(t,n)):(this._match("Star"),this._match("Rbracket"),n=this._parseProjectionRHS(N.Star),{type:"Projection",children:[t,n]});default:this._errorToken(this._lookaheadToken(0))}},_match:function(e){if(this._lookahead(0)!==e){var t=this._lookaheadToken(0),n=new Error("Expected "+e+", got: "+t.type);throw n.name="ParserError",n}this._advance()},_errorToken:function(e){var t=new Error("Invalid token ("+e.type+'): "'+e.value+'"');throw t.name="ParserError",t},_parseIndexExpression:function(){if("Colon"===this._lookahead(0)||"Colon"===this._lookahead(1))return this._parseSliceExpression();var e={type:"Index",value:this._lookaheadToken(0).value};return this._advance(),this._match("Rbracket"),e},_projectIfSlice:function(e,t){var n={type:"IndexExpression",children:[e,t]};return"Slice"===t.type?{type:"Projection",children:[n,this._parseProjectionRHS(N.Star)]}:n},_parseSliceExpression:function(){for(var e=[null,null,null],t=0,n=this._lookahead(0);"Rbracket"!==n&&t<3;){if("Colon"===n)t++,this._advance();else{if("Number"!==n){var i=this._lookahead(0),o=new Error("Syntax error, unexpected token: "+i.value+"("+i.type+")");throw o.name="Parsererror",o}e[t]=this._lookaheadToken(0).value,this._advance()}n=this._lookahead(0)}return this._match("Rbracket"),{type:"Slice",children:e}},_parseComparator:function(e,t){return{type:"Comparator",name:t,children:[e,this.expression(N[t])]}},_parseDotRHS:function(e){var t=this._lookahead(0);return["UnquotedIdentifier","QuotedIdentifier","Star"].indexOf(t)>=0?this.expression(e):"Lbracket"===t?(this._match("Lbracket"),this._parseMultiselectList()):"Lbrace"===t?(this._match("Lbrace"),this._parseMultiselectHash()):void 0},_parseProjectionRHS:function(e){var t;if(N[this._lookahead(0)]<10)t={type:"Identity"};else if("Lbracket"===this._lookahead(0))t=this.expression(e);else if("Filter"===this._lookahead(0))t=this.expression(e);else{if("Dot"!==this._lookahead(0)){var n=this._lookaheadToken(0),i=new Error("Sytanx error, unexpected token: "+n.value+"("+n.type+")");throw i.name="ParserError",i}this._match("Dot"),t=this._parseDotRHS(e)}return t},_parseMultiselectList:function(){for(var e=[];"Rbracket"!==this._lookahead(0);){var t=this.expression(0);if(e.push(t),"Comma"===this._lookahead(0)&&(this._match("Comma"),"Rbracket"===this._lookahead(0)))throw new Error("Unexpected token Rbracket")}return this._match("Rbracket"),{type:"MultiSelectList",children:e}},_parseMultiselectHash:function(){for(var e,t,n,i,o=[],r=["UnquotedIdentifier","QuotedIdentifier"];;){if(e=this._lookaheadToken(0),r.indexOf(e.type)<0)throw new Error("Expecting an identifier token, got: "+e.type);if(t=e.value,this._advance(),this._match("Colon"),n=this.expression(0),i={type:"KeyValuePair",name:t,value:n},o.push(i),"Comma"===this._lookahead(0))this._match("Comma");else if("Rbrace"===this._lookahead(0)){this._match("Rbrace");break}}return{type:"MultiSelectHash",children:o}}},d.prototype={search:function(e,t){return this.visit(e,t)},visit:function(e,s){var a,l,c,h,d,u,p,f,m;switch(e.type){case"Field":return null===s?null:n(s)?(u=s[e.name],void 0===u?null:u):null;case"Subexpression":for(c=this.visit(e.children[0],s),m=1;m<e.children.length;m++)if(null===(c=this.visit(e.children[1],c)))return null;return c;case"IndexExpression":return p=this.visit(e.children[0],s),this.visit(e.children[1],p);case"Index":if(!t(s))return null;var g=e.value;return g<0&&(g=s.length+g),c=s[g],void 0===c&&(c=null),c;case"Slice":if(!t(s))return null;var v=e.children.slice(0),y=this.computeSliceParams(s.length,v),b=y[0],x=y[1],w=y[2];if(c=[],w>0)for(m=b;m<x;m+=w)c.push(s[m]);else for(m=b;m>x;m+=w)c.push(s[m]);return c;case"Projection":var _=this.visit(e.children[0],s);if(!t(_))return null;for(f=[],m=0;m<_.length;m++)null!==(l=this.visit(e.children[1],_[m]))&&f.push(l);return f;case"ValueProjection":if(_=this.visit(e.children[0],s),!n(_))return null;f=[];var C=r(_);for(m=0;m<C.length;m++)n
var r=o.substring(this.startFrom),a=h.move(1);return""==a&&c.onArrowDown(),this.elementHint.innerText=l+r+a.substring(r.length),this.elementHint.realInnerText=l+a,n.preventDefault(),void n.stopPropagation()}if(38==i){var r=o.substring(this.startFrom),a=h.move(-1);return""==a&&c.onArrowUp(),this.elementHint.innerText=l+r+a.substring(r.length),this.elementHint.realInnerText=l+a,n.preventDefault(),void n.stopPropagation()}}else if(0==this.elementHint.innerText.length)c.onEnter();else{var d="hidden"==s.style.visibility;if(h.hide(),d)return c.hideDropDown(),c.element.focus(),void c.onEnter();this.element.innerText=this.elementHint.realInnerText,c.hideDropDown(),t(this.element),n.preventDefault(),n.stopPropagation()}}}.bind(c),u=function(e){c.hideDropDown()}.bind(c);return h.onmouseselection=function(e,n){n.element.innerText=n.elementHint.innerText=l+e,n.hideDropDown(),window.setTimeout(function(){n.element.focus(),t(n.element)},1)},c}e.exports=n},function(e,t,n){"use strict";function i(){try{this.format()}catch(e){}}var o=n(1),r=n(26),s=n(12),a={};a.create=function(e,t){t=t||{},void 0===t.statusBar&&(t.statusBar=!0),this.options=t,t.indentation?this.indentation=Number(t.indentation):this.indentation=2;var i=t.ace?t.ace:o;if(this.mode="code"==t.mode?"code":"text","code"==this.mode&&void 0===i&&(this.mode="text",console.warn("Failed to load Ace editor, falling back to plain text mode. Please use a JSONEditor bundle including Ace, or pass Ace as via the configuration option `ace`.")),this.theme=t.theme||"ace/theme/jsoneditor","ace/theme/jsoneditor"===this.theme&&i)try{n(29)}catch(e){console.error(e)}t.onTextSelectionChange&&this.onTextSelectionChange(t.onTextSelectionChange);var a=this;this.container=e,this.dom={},this.aceEditor=void 0,this.textarea=void 0,this.validateSchema=null,this.validationSequence=0,this.annotations=[],this._debouncedValidate=s.debounce(this.validate.bind(this),this.DEBOUNCE_INTERVAL),this.width=e.clientWidth,this.height=e.clientHeight,this.frame=document.createElement("div"),this.frame.className="jsoneditor jsoneditor-mode-"+this.options.mode,this.frame.onclick=function(e){e.preventDefault()},this.frame.onkeydown=function(e){a._onKeyDown(e)},this.menu=document.createElement("div"),this.menu.className="jsoneditor-menu",this.frame.appendChild(this.menu);var l=document.createElement("button");l.type="button",l.className="jsoneditor-format",l.title="Format JSON data, with proper indentation and line feeds (Ctrl+\\)",this.menu.appendChild(l),l.onclick=function(){try{a.format(),a._onChange()}catch(e){a._onError(e)}};var c=document.createElement("button");c.type="button",c.className="jsoneditor-compact",c.title="Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)",this.menu.appendChild(c),c.onclick=function(){try{a.compact(),a._onChange()}catch(e){a._onError(e)}};var h=document.createElement("button");h.type="button",h.className="jsoneditor-repair",h.title="Repair JSON: fix quotes and escape characters, remove comments and JSONP notation, turn JavaScript objects into JSON.",this.menu.appendChild(h),h.onclick=function(){try{a.repair(),a._onChange()}catch(e){a._onError(e)}},this.options&&this.options.modes&&this.options.modes.length&&(this.modeSwitcher=new r(this.menu,this.options.modes,this.options.mode,function(e){a.setMode(e),a.modeSwitcher.focus()}));var d={},u=this.options.onEditable&&typeof("function"===this.options.onEditable)&&!this.options.onEditable(d);if(this.content=document.createElement("div"),this.content.className="jsoneditor-outer",this.frame.appendChild(this.content),this.container.appendChild(this.frame),"code"==this.mode){this.editorDom=document.createElement("div"),this.editorDom.style.height="100%",this.editorDom.style.width="100%",this.content.appendChild(this.editorDom);var p=i.edit(this.editorDom),f=p.getSession();p.$blockScrolling=1/0,p.setTheme(this.theme),p.setOptions({readOnly:u}),p.setShowPrintMargin(!1),p.setFontSize(13),f.setMode("ace/mode/json"),f.setTabSize(this.indentation),f.setUseSoftTabs(!0),f.setUseWrapMode(!0);var m=f.setAnnotations;f.setAnnotations=function(e){m.cal
2017-07-04 01:23:32 +08:00
//# sourceMappingURL=jsoneditor-minimalist.map