jsoneditor/dist/jsoneditor-minimalist.js

33 lines
81 KiB
JavaScript
Raw Normal View History

2016-01-15 04:26:39 +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-2016 Jos de Jong, http://jsoneditoronline.org
*
* @author Jos de Jong, <wjosdejong@gmail.com>
* @version 6.0.0-BETA
* @date 2016-08-13
2016-01-15 04:26:39 +08:00
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jsoneditor=e():t.jsoneditor=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){var n=(0,r.render)((0,r.h)(a["default"],{options:e}),t);return n._component}var r=n(1),s=n(4),a=o(s);n(14),t.exports=i},function(t,e,n){(function(t){!function(t,n){n(e)}(this,function(t){function e(t,e,n){this.nodeName=t,this.attributes=e,this.children=n,this.key=e&&e.key}function n(t,e){if(e)for(var n in e)void 0!==e[n]&&(t[n]=e[n]);return t}function o(t){return n({},t)}function i(t,e){for(var n=e.split("."),o=0;o<n.length&&t;o++)t=t[n[o]];return t}function r(t,e){return[].slice.call(t,e)}function s(t){return"function"==typeof t}function a(t){return"string"==typeof t}function l(t){return void 0===t||null===t}function c(t){return t===!1||l(t)}function d(t){var e="";for(var n in t)t[n]&&(e&&(e+=" "),e+=n);return e}function p(t,n,o){var i,r,l,u=arguments.length;if(u>2){var f=typeof o;if(3===u&&"object"!==f&&"function"!==f)c(o)||(i=[String(o)]);else{i=[];for(var h=2;u>h;h++){var y=arguments[h];if(!c(y)){y.join?r=y:(r=Q)[0]=y;for(var m=0;m<r.length;m++){var v=r[m],k=!(c(v)||s(v)||v instanceof e);k&&!a(v)&&(v=String(v)),k&&l?i[i.length-1]+=v:c(v)||(i.push(v),l=k)}}}}}else if(n&&n.children)return p(t,n,n.children);n&&(n.children&&delete n.children,s(t)||("className"in n&&(n["class"]=n.className,delete n.className),l=n["class"],l&&!a(l)&&(n["class"]=d(l))));var g=new e(t,n||void 0,i);return X.vnode&&X.vnode(g),g}function u(t,e){return p(t.nodeName,n(o(t.attributes),e),arguments.length>2?r(arguments,2):t.children)}function f(t,e,n){var o=e.split("."),r=o[0];return function(e){var c,d,p,u=e&&e.currentTarget||this,f=t.state,h=f;if(a(n)?(d=i(e,n),l(d)&&(u=u._component)&&(d=i(u,n))):d=u.nodeName?(u.nodeName+u.type).match(/^input(check|rad)/i)?u.checked:u.value:e,s(d)&&(d=d.call(u)),o.length>1){for(p=0;p<o.length-1;p++)h=h[o[p]]||(h[o[p]]={});h[o[p]]=d,d=f[r]}t.setState((c={},c[r]=d,c))}}function h(t){1===nt.push(t)&&(X.debounceRendering||q)(y)}function y(){if(nt.length){var t,e=nt;for(nt=ot,ot=e;t=e.pop();)t._dirty&&F(t)}}function m(t){var e=t&&t.nodeName;return e&&s(e)&&!(e.prototype&&e.prototype.render)}function v(t,e){return t.nodeName(S(t),e||Y)}function k(t,e){return t[tt]||(t[tt]=e||{})}function g(t){return t instanceof Text?3:t instanceof Element?1:0}function b(t){var e=t.parentNode;e&&e.removeChild(t)}function x(t,e,n,o,i){if(k(t)[e]=n,"key"!==e&&"children"!==e)if("class"!==e||i)if("style"===e){if((!n||a(n)||a(o))&&(t.style.cssText=n||""),n&&"object"==typeof n){if(!a(o))for(var r in o)r in n||(t.style[r]="");for(var r in n)t.style[r]="number"!=typeof n[r]||et[r]?n[r]:n[r]+"px"}}else if("dangerouslySetInnerHTML"===e)n&&(t.innerHTML=n.__html);else if("o"===e[0]&&"n"===e[1]){var d=t._listeners||(t._listeners={});e=Z(e.substring(2)),n?d[e]||t.addEventListener(e,w):d[e]&&t.removeEventListener(e,w),d[e]=n}else if("type"!==e&&!i&&e in t)j(t,e,l(n)?"":n),c(n)&&t.removeAttribute(e);else{var p=i&&e.match(/^xlink\:?(.+)/);c(n)?p?t.removeAttributeNS("http://www.w3.org/1999/xlink",Z(p[1])):t.removeAttribute(e):"object"==typeof n||s(n)||(p?t.setAttributeNS("http://www.w3.org/1999/xlink",Z(p[1]),n):t.setAttribute(e,n))}else t.className=n||""}function j(t,e,n){try{t[e]=n}catch(o){}}function w(t){return this._listeners[t.type](X.event&&X.event(t)||t)}function C(t){for(var e={},n=t.attributes.length;n--;)e[t.attributes[n].name]=t.attributes[n].value;return e}function E(t,e){return a(e)?3===g(t):a(e.nodeName)?_(t,e.nodeName):s(e.nodeName)?t._componentConstructor===e.nodeName||m(e):void 0}function _(t,e){return t.normalizedNodeName===e||Z(t.nodeName)===Z(e)}function S(t){var e=t.nodeName.defaultProps,i=o(e||t.attributes);return e&&n
}),(0,l.h)(d["default"],{anchor:e,root:n,items:r})}},{key:"shouldComponentUpdate",value:function(t,e){var n=void 0;for(n in t)if(t.hasOwnProperty(n)&&this.props[n]!==t[n])return!0;for(n in e)if(e.hasOwnProperty(n)&&this.state[n]!==e[n])return!0;return!1}},{key:"handleChangeProperty",value:function(t){var e=this.props.parent.getPath(),n=this.props.prop,o=(0,p.unescapeHTML)((0,u.getInnerText)(t.target));this.props.events.onChangeProperty(e,n,o)}},{key:"handleChangeValue",value:function(t){var e=this._getValueFromEvent(t);this.props.events.onChangeValue(this.getPath(),e)}},{key:"handleClickValue",value:function(t){t.ctrlKey&&0===t.button&&this._openLinkIfUrl(t)}},{key:"handleKeyDownValue",value:function(t){t.ctrlKey&&13===t.which&&this._openLinkIfUrl(t)}},{key:"handleExpand",value:function(t){this.props.events.onExpand(this.getPath(),!this.props.data.expanded)}},{key:"handleContextMenu",value:function(t){t.stopPropagation(),this.state.menu?e.hideContextMenu():(e.hideContextMenu(),this.setState({menu:{anchor:t.target,root:e._findRootElement(t)}}),y=this)}},{key:"handleAppendContextMenu",value:function(t){t.stopPropagation(),this.state.appendMenu?e.hideContextMenu():(e.hideContextMenu(),this.setState({appendMenu:{anchor:t.target,root:e._findRootElement(t)}}),y=this)}},{key:"_openLinkIfUrl",value:function(t){var e=this._getValueFromEvent(t);(0,f.isUrl)(e)&&(t.preventDefault(),t.stopPropagation(),window.open(e,"_blank"))}},{key:"getPath",value:function(){var t=this.props.parent?this.props.parent.getPath():[];return null!==this.props.prop&&t.push(this.props.prop),t}},{key:"_getValueFromEvent",value:function(t){var e=(0,p.unescapeHTML)((0,u.getInnerText)(t.target));return"string"===this.props.data.type?e:(0,f.stringConvert)(e)}}],[{key:"_rootName",value:function(t,e){return"string"==typeof e.name?e.name:"object"===t.type||"array"===t.type?t.type:(0,f.valueType)(t.value)}},{key:"hideContextMenu",value:function(){y&&(y.setState({menu:null,appendMenu:null}),y=null)}},{key:"_findRootElement",value:function(t){function e(t){return-1!==t.className.split(" ").indexOf("jsoneditor")}for(var n=t.target;n;){if(e(n))return n;n=n.parentNode}return null}}]),e}(l.Component);e["default"]=m},function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0}),e.CONTEXT_MENU_HEIGHT=void 0;var s=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),a=n(1),l=e.CONTEXT_MENU_HEIGHT=240,c=function(t){function e(t){o(this,e);var n=i(this,Object.getPrototypeOf(e).call(this,t)),r=n.props.anchor.getBoundingClientRect(),s=n.props.root.getBoundingClientRect(),a=s.bottom-r.bottom<l&&r.top-s.top>l?"top":"bottom";return n.state={orientation:a,expanded:null,expanding:null,collapsing:null},n.renderMenuItem=n.renderMenuItem.bind(n),n}return r(e,t),s(e,[{key:"render",value:function(){if(!this.props.items)return null;var t="jsoneditor-contextmenu "+("top"===this.state.orientation?"jsoneditor-contextmenu-top":"jsoneditor-contextmenu-bottom");return(0,a.h)("div",{"class":t},this.props.items.map(this.renderMenuItem))}},{key:"renderMenuItem",value:function(t,e){return"separator"===t.type?(0,a.h)("div",{"class":"jsoneditor-menu-separator"}):t.click&&t.submenu?(0,a.h)("div",{"class":"jsoneditor-menu-item"},[(0,a.h)("button",{"class":"jsoneditor-menu-button jsoneditor-menu-default "+t.className,title:t.title,onClick:
},function(t,e,n){function o(t,e){for(var n=0;n<t.length;n++){var o=t[n],i=f[o.id];if(i){i.refs++;for(var r=0;r<i.parts.length;r++)i.parts[r](o.parts[r]);for(;r<o.parts.length;r++)i.parts.push(c(o.parts[r],e))}else{for(var s=[],r=0;r<o.parts.length;r++)s.push(c(o.parts[r],e));f[o.id]={id:o.id,refs:1,parts:s}}}}function i(t){for(var e=[],n={},o=0;o<t.length;o++){var i=t[o],r=i[0],s=i[1],a=i[2],l=i[3],c={css:s,media:a,sourceMap:l};n[r]?n[r].parts.push(c):e.push(n[r]={id:r,parts:[c]})}return e}function r(t,e){var n=m(),o=g[g.length-1];if("top"===t.insertAt)o?o.nextSibling?n.insertBefore(e,o.nextSibling):n.appendChild(e):n.insertBefore(e,n.firstChild),g.push(e);else{if("bottom"!==t.insertAt)throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");n.appendChild(e)}}function s(t){t.parentNode.removeChild(t);var e=g.indexOf(t);e>=0&&g.splice(e,1)}function a(t){var e=document.createElement("style");return e.type="text/css",r(t,e),e}function l(t){var e=document.createElement("link");return e.rel="stylesheet",r(t,e),e}function c(t,e){var n,o,i;if(e.singleton){var r=k++;n=v||(v=a(e)),o=d.bind(null,n,r,!1),i=d.bind(null,n,r,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=l(e),o=u.bind(null,n),i=function(){s(n),n.href&&URL.revokeObjectURL(n.href)}):(n=a(e),o=p.bind(null,n),i=function(){s(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else i()}}function d(t,e,n,o){var i=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=b(e,i);else{var r=document.createTextNode(i),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(r,s[e]):t.appendChild(r)}}function p(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function u(t,e){var n=e.css,o=e.sourceMap;o&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var i=new Blob([n],{type:"text/css"}),r=t.href;t.href=URL.createObjectURL(i),r&&URL.revokeObjectURL(r)}var f={},h=function(t){var e;return function(){return"undefined"==typeof e&&(e=t.apply(this,arguments)),e}},y=h(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),m=h(function(){return document.head||document.getElementsByTagName("head")[0]}),v=null,k=0,g=[];t.exports=function(t,e){e=e||{},"undefined"==typeof e.singleton&&(e.singleton=y()),"undefined"==typeof e.insertAt&&(e.insertAt="bottom");var n=i(t);return o(n,e),function(t){for(var r=[],s=0;s<n.length;s++){var a=n[s],l=f[a.id];l.refs--,r.push(l)}if(t){var c=i(t);o(c,e)}for(var s=0;s<r.length;s++){var l=r[s];if(0===l.refs){for(var d=0;d<l.parts.length;d++)l.parts[d]();delete f[l.id]}}}};var b=function(){var t=[];return function(e,n){return t[e]=n,t.filter(Boolean).join("\n")}}()}])});
//# sourceMappingURL=jsoneditor-minimalist.js.map