Loading assets Ace Editor and JSONLint via npm. Auto build assets.
This commit is contained in:
parent
85100e9fb4
commit
4eae0cff1f
|
@ -1,5 +1,4 @@
|
|||
.idea
|
||||
build
|
||||
dist
|
||||
downloads
|
||||
node_modules
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
app
|
||||
bower.json
|
||||
build
|
||||
dist
|
||||
downloads
|
||||
jsoneditor
|
||||
misc
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
http://jsoneditoronline.org
|
||||
|
||||
|
||||
## not yet released, version 3.0.0
|
||||
|
||||
- Large code reorganization.
|
||||
|
||||
|
||||
## 2014-01-03, version 2.3.6
|
||||
|
||||
- Fixed positioning issue of the action menu.
|
||||
|
|
47
Jakefile.js
47
Jakefile.js
|
@ -9,26 +9,29 @@ var jake = require('jake'),
|
|||
require('jake-utils');
|
||||
|
||||
// constants
|
||||
var JSONEDITOR = './jsoneditor.js',
|
||||
JSONEDITOR_CSS = './jsoneditor.css',
|
||||
JSONEDITOR_MIN = './jsoneditor-min.js',
|
||||
JSONEDITOR_CSS_MIN = './jsoneditor-min.css',
|
||||
DIST = './dist';
|
||||
var BUILD = './',
|
||||
ASSET = BUILD + 'asset/',
|
||||
BUILD_ACE = BUILD + 'asset/ace/',
|
||||
BUILD_JSONLINT = BUILD + 'asset/jsonlint/',
|
||||
JSONEDITOR = BUILD +'jsoneditor.js',
|
||||
JSONEDITOR_CSS = BUILD + 'jsoneditor.css',
|
||||
JSONEDITOR_MIN = BUILD + 'jsoneditor.min.js',
|
||||
JSONEDITOR_CSS_MIN = BUILD + 'jsoneditor.min.css';
|
||||
|
||||
/**
|
||||
* default task
|
||||
*/
|
||||
desc('Execute all tasks');
|
||||
task('default', ['clear', 'build', 'minify', 'zip'], function () {
|
||||
task('default', ['clear', 'build', 'minify'], function () {
|
||||
console.log('Done');
|
||||
});
|
||||
|
||||
/**
|
||||
* build the library
|
||||
*/
|
||||
desc('Clear the build directory');
|
||||
desc('Clear the asset directory');
|
||||
task('clear', function () {
|
||||
jake.rmRf(DIST);
|
||||
jake.rmRf(ASSET);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -84,6 +87,30 @@ task('build', ['clear'], function () {
|
|||
jake.mkdirP('./img');
|
||||
jake.cpR(jsoneditorSrc + 'css/img/jsoneditor-icons.png', './img/');
|
||||
console.log('Copied jsoneditor-icons.png to ./img/');
|
||||
|
||||
// copy assets
|
||||
// concatenate and copy ace files
|
||||
var aceSrc = './node_modules/ace/build/src-min/';
|
||||
jake.mkdirP(BUILD_ACE);
|
||||
concat({
|
||||
src: [
|
||||
aceSrc + 'ace.js',
|
||||
aceSrc + 'ext-searchbox.js',
|
||||
aceSrc + 'mode-json.js',
|
||||
aceSrc + 'theme-textmate.js',
|
||||
jsoneditorSrc + 'js/ace/theme-jsoneditor.js'
|
||||
],
|
||||
dest: BUILD_ACE + 'ace.js',
|
||||
separator: '\n'
|
||||
});
|
||||
jake.cpR(aceSrc + 'worker-json.js', BUILD_ACE);
|
||||
|
||||
// copy and minify json lint file
|
||||
jake.mkdirP(BUILD_JSONLINT);
|
||||
minify({
|
||||
src: './node_modules/jsonlint/lib/jsonlint.js',
|
||||
dest: BUILD_JSONLINT + 'jsonlint.js'
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -111,8 +138,8 @@ task('minify', ['build'], function () {
|
|||
desc('Zip the library');
|
||||
task('zip', ['build', 'minify'], {async: true}, function () {
|
||||
var pkg = 'jsoneditor-' + version();
|
||||
var zipfile = DIST + '/' + pkg + '.zip';
|
||||
jake.mkdirP(DIST);
|
||||
var zipfile = BUILD + pkg + '.zip';
|
||||
jake.mkdirP(BUILD);
|
||||
|
||||
var output = fs.createWriteStream(zipfile);
|
||||
var archive = archiver('zip');
|
||||
|
|
28
README.md
28
README.md
|
@ -96,12 +96,26 @@ download:
|
|||
|
||||
### Build
|
||||
|
||||
The code of the JSON Editor is located in the folder `jsoneditor`.
|
||||
The code for the web application in `app/web`.
|
||||
To build the library from sourcecode, run
|
||||
The code of the JSON Editor is located in the folder `jsoneditor`. To build
|
||||
jsoneditor:
|
||||
|
||||
jake
|
||||
- Install dependencies:
|
||||
|
||||
in the root of the project. This will generate the files `jsoneditor.js`,
|
||||
`jsoneditor.css`, and minified versions, and will create a folder `build`
|
||||
containing the zipped library and the built web application.
|
||||
npm install
|
||||
|
||||
- Build Ace editor:
|
||||
|
||||
cd node_modules/ace
|
||||
npm install
|
||||
node ./Makefile.dryice.js -m
|
||||
cd ../..
|
||||
|
||||
This generates the ace editor files in the folder `node_modules/ace/build`.
|
||||
|
||||
- Build JSON Editor:
|
||||
|
||||
npm run build
|
||||
|
||||
This will generate the files `jsoneditor.js`,
|
||||
`jsoneditor.css`, and minified versions, and will create a folder `build`
|
||||
containing the zipped library and the built web application.
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jsoneditor",
|
||||
"version": "2.3.7-SNAPSHOT",
|
||||
"version": "3.0.0-SNAPSHOT",
|
||||
"description": "A web-based tool to view, edit and format JSON",
|
||||
"tags": [
|
||||
"json",
|
||||
|
|
|
@ -23,8 +23,8 @@ To implement JSONEditor in a web application, load the javascript and css file
|
|||
in the head of the HTML page:
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor-min.css">
|
||||
<script type="text/javascript" src="jsoneditor/jsoneditor-min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.min.css">
|
||||
<script type="text/javascript" src="jsoneditor/jsoneditor.min.js"></script>
|
||||
```
|
||||
|
||||
### Detailed error messages
|
||||
|
@ -33,21 +33,21 @@ Optionally, [jsonlint](https://github.com/zaach/jsonlint) can be loaded to get
|
|||
more detailed error messages.
|
||||
|
||||
```html
|
||||
<script type="text/javascript" src="jsoneditor/lib/jsonlint/jsonlint.js"></script>
|
||||
<script type="text/javascript" src="jsoneditor/asset/jsonlint/jsonlint.js"></script>
|
||||
```
|
||||
|
||||
### Code editor
|
||||
|
||||
The mode 'code' requires the [Ace editor](http://ace.ajax.org/) to be loaded.
|
||||
Also, the content type must be specified on the page.
|
||||
JSON Editor comes with a custom built version of Ace containing the ace modules
|
||||
`ace.js`, `ext-searchbox.js`, `mode-json.js`, `theme-textmate.js`, and a custom
|
||||
theme `theme-jsoneditor.js`.
|
||||
Besides loading ace, the content type must be specified on the page.
|
||||
|
||||
```html
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
|
||||
<script type="text/javascript" src="jsoneditor/lib/ace/ace.js"></script>
|
||||
<script type="text/javascript" src="jsoneditor/lib/ace/mode-json.js"></script>
|
||||
<script type="text/javascript" src="jsoneditor/lib/ace/theme-textmate.js"></script>
|
||||
<script type="text/javascript" src="jsoneditor/lib/ace/theme-jsoneditor.js"></script>
|
||||
<script type="text/javascript" src="jsoneditor/asset/ace/ace.js"></script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
@ -95,8 +95,8 @@ var json = editor.get();
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor-min.css">
|
||||
<script type="text/javascript" src="jsoneditor/jsoneditor-min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="jsoneditor/jsoneditor.min.css">
|
||||
<script type="text/javascript" src="jsoneditor/jsoneditor.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
|
|
|
@ -8,13 +8,10 @@
|
|||
<script type="text/javascript" src="../jsoneditor.js"></script>
|
||||
|
||||
<!-- ace code editor -->
|
||||
<script type="text/javascript" src="../lib/ace/ace.js"></script>
|
||||
<script type="text/javascript" src="../lib/ace/mode-json.js"></script>
|
||||
<script type="text/javascript" src="../lib/ace/theme-textmate.js"></script>
|
||||
<script type="text/javascript" src="../lib/ace/theme-jsoneditor.js"></script>
|
||||
<script type="text/javascript" src="../asset/ace/ace.js"></script>
|
||||
|
||||
<!-- json lint -->
|
||||
<script type="text/javascript" src="../lib/jsonlint/jsonlint.js"></script>
|
||||
<script type="text/javascript" src="../asset/jsonlint/jsonlint.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
* Copyright (c) 2011-2013 Jos de Jong, http://jsoneditoronline.org
|
||||
*
|
||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||
* @version 2.3.7-SNAPSHOT
|
||||
* @version 3.0.0-SNAPSHOT
|
||||
* @date 2014-05-29
|
||||
*/
|
||||
(function () {
|
||||
|
@ -5990,7 +5990,7 @@ var jsoneditor = {
|
|||
* load jsoneditor.css
|
||||
*/
|
||||
var loadCss = function () {
|
||||
// find the script named 'jsoneditor.js' or 'jsoneditor-min.js' or
|
||||
// find the script named 'jsoneditor.js' or 'jsoneditor.min.js' or
|
||||
// 'jsoneditor.min.js', and use its path to find the css file to be
|
||||
// loaded.
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -13,7 +13,7 @@ var jsoneditor = {
|
|||
* load jsoneditor.css
|
||||
*/
|
||||
var loadCss = function () {
|
||||
// find the script named 'jsoneditor.js' or 'jsoneditor-min.js' or
|
||||
// find the script named 'jsoneditor.js' or 'jsoneditor.min.js' or
|
||||
// 'jsoneditor.min.js', and use its path to find the css file to be
|
||||
// loaded.
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
define("ace/theme/textmate",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-tm",t.cssText='.ace-tm .ace_gutter {background: #f0f0f0;color: #333;}.ace-tm .ace_print-margin {width: 1px;background: #e8e8e8;}.ace-tm .ace_fold {background-color: #6B72E6;}.ace-tm {background-color: #FFFFFF;color: black;}.ace-tm .ace_cursor {color: black;}.ace-tm .ace_invisible {color: rgb(191, 191, 191);}.ace-tm .ace_storage,.ace-tm .ace_keyword {color: blue;}.ace-tm .ace_constant {color: rgb(197, 6, 11);}.ace-tm .ace_constant.ace_buildin {color: rgb(88, 72, 246);}.ace-tm .ace_constant.ace_language {color: rgb(88, 92, 246);}.ace-tm .ace_constant.ace_library {color: rgb(6, 150, 14);}.ace-tm .ace_invalid {background-color: rgba(255, 0, 0, 0.1);color: red;}.ace-tm .ace_support.ace_function {color: rgb(60, 76, 114);}.ace-tm .ace_support.ace_constant {color: rgb(6, 150, 14);}.ace-tm .ace_support.ace_type,.ace-tm .ace_support.ace_class {color: rgb(109, 121, 222);}.ace-tm .ace_keyword.ace_operator {color: rgb(104, 118, 135);}.ace-tm .ace_string {color: rgb(3, 106, 7);}.ace-tm .ace_comment {color: rgb(76, 136, 107);}.ace-tm .ace_comment.ace_doc {color: rgb(0, 102, 255);}.ace-tm .ace_comment.ace_doc.ace_tag {color: rgb(128, 159, 191);}.ace-tm .ace_constant.ace_numeric {color: rgb(0, 0, 205);}.ace-tm .ace_variable {color: rgb(49, 132, 149);}.ace-tm .ace_xml-pe {color: rgb(104, 104, 91);}.ace-tm .ace_entity.ace_name.ace_function {color: #0000A2;}.ace-tm .ace_heading {color: rgb(12, 7, 255);}.ace-tm .ace_list {color:rgb(185, 6, 144);}.ace-tm .ace_meta.ace_tag {color:rgb(0, 22, 142);}.ace-tm .ace_string.ace_regex {color: rgb(255, 0, 0)}.ace-tm .ace_marker-layer .ace_selection {background: rgb(181, 213, 255);}.ace-tm.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px white;border-radius: 2px;}.ace-tm .ace_marker-layer .ace_step {background: rgb(252, 255, 0);}.ace-tm .ace_marker-layer .ace_stack {background: rgb(164, 229, 101);}.ace-tm .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgb(192, 192, 192);}.ace-tm .ace_marker-layer .ace_active-line {background: rgba(0, 0, 0, 0.07);}.ace-tm .ace_gutter-active-line {background-color : #dcdcdc;}.ace-tm .ace_marker-layer .ace_selected-word {background: rgb(250, 250, 255);border: 1px solid rgb(200, 200, 250);}.ace-tm .ace_indent-guide {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y;}';var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)})
|
File diff suppressed because one or more lines are too long
|
@ -1,62 +0,0 @@
|
|||
JSON Lint
|
||||
=========
|
||||
|
||||
A pure [JavaScript version](http://zaach.github.com/jsonlint/) of the service provided at [jsonlint.com](http://jsonlint.com).
|
||||
|
||||
## Command line interface
|
||||
Install jsonlint with npm to use the command line interface:
|
||||
|
||||
npm install jsonlint -g
|
||||
|
||||
Validate a file like so:
|
||||
|
||||
jsonlint myfile.json
|
||||
|
||||
or pipe input into stdin:
|
||||
|
||||
cat myfile.json | jsonlint
|
||||
|
||||
jsonlint will either report a syntax error with details or pretty print the source if it is valid.
|
||||
|
||||
### Options
|
||||
|
||||
$ jsonlint -h
|
||||
|
||||
usage: jsonlint <file> [options]
|
||||
|
||||
file file to parse; otherwise uses stdin
|
||||
|
||||
options:
|
||||
-v, --version print version and exit
|
||||
-s, --sort-keys sort object keys
|
||||
-i, --in-place overwrite the file
|
||||
-t CHAR, --indent CHAR character(s) to use for indentation
|
||||
-c, --compact compact error display
|
||||
-V, --validate a JSON schema to use for validation
|
||||
-e, --environment which specification of JSON Schema the validation file uses
|
||||
|
||||
|
||||
## Module interface
|
||||
|
||||
I'm not sure why you wouldn't use the built in `JSON.parse` but you can use jsonlint from a CommonJS module:
|
||||
|
||||
var jsonlint = require("jsonlint");
|
||||
|
||||
jsonlint.parse('{"creative?": false}');
|
||||
|
||||
It returns the parsed object or throws an `Error`.
|
||||
|
||||
## Vim Plugins
|
||||
|
||||
* [Syntastic](http://www.vim.org/scripts/script.php?script_id=2736)
|
||||
* [sourcebeautify](http://www.vim.org/scripts/script.php?script_id=4079)
|
||||
|
||||
## MIT License
|
||||
|
||||
Copyright (C) 2012 Zachary Carter
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,432 +0,0 @@
|
|||
/* Jison generated parser */
|
||||
var jsonlint = (function(){
|
||||
var parser = {trace: function trace() { },
|
||||
yy: {},
|
||||
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
|
||||
terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},
|
||||
productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],
|
||||
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
|
||||
|
||||
var $0 = $$.length - 1;
|
||||
switch (yystate) {
|
||||
case 1: // replace escaped characters with actual character
|
||||
this.$ = yytext.replace(/\\(\\|")/g, "$"+"1")
|
||||
.replace(/\\n/g,'\n')
|
||||
.replace(/\\r/g,'\r')
|
||||
.replace(/\\t/g,'\t')
|
||||
.replace(/\\v/g,'\v')
|
||||
.replace(/\\f/g,'\f')
|
||||
.replace(/\\b/g,'\b');
|
||||
|
||||
break;
|
||||
case 2:this.$ = Number(yytext);
|
||||
break;
|
||||
case 3:this.$ = null;
|
||||
break;
|
||||
case 4:this.$ = true;
|
||||
break;
|
||||
case 5:this.$ = false;
|
||||
break;
|
||||
case 6:return this.$ = $$[$0-1];
|
||||
break;
|
||||
case 13:this.$ = {};
|
||||
break;
|
||||
case 14:this.$ = $$[$0-1];
|
||||
break;
|
||||
case 15:this.$ = [$$[$0-2], $$[$0]];
|
||||
break;
|
||||
case 16:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
|
||||
break;
|
||||
case 17:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1];
|
||||
break;
|
||||
case 18:this.$ = [];
|
||||
break;
|
||||
case 19:this.$ = $$[$0-1];
|
||||
break;
|
||||
case 20:this.$ = [$$[$0]];
|
||||
break;
|
||||
case 21:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
|
||||
break;
|
||||
}
|
||||
},
|
||||
table: [{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}],
|
||||
defaultActions: {16:[2,6]},
|
||||
parseError: function parseError(str, hash) {
|
||||
throw new Error(str);
|
||||
},
|
||||
parse: function parse(input) {
|
||||
var self = this,
|
||||
stack = [0],
|
||||
vstack = [null], // semantic value stack
|
||||
lstack = [], // location stack
|
||||
table = this.table,
|
||||
yytext = '',
|
||||
yylineno = 0,
|
||||
yyleng = 0,
|
||||
recovering = 0,
|
||||
TERROR = 2,
|
||||
EOF = 1;
|
||||
|
||||
//this.reductionCount = this.shiftCount = 0;
|
||||
|
||||
this.lexer.setInput(input);
|
||||
this.lexer.yy = this.yy;
|
||||
this.yy.lexer = this.lexer;
|
||||
if (typeof this.lexer.yylloc == 'undefined')
|
||||
this.lexer.yylloc = {};
|
||||
var yyloc = this.lexer.yylloc;
|
||||
lstack.push(yyloc);
|
||||
|
||||
if (typeof this.yy.parseError === 'function')
|
||||
this.parseError = this.yy.parseError;
|
||||
|
||||
function popStack (n) {
|
||||
stack.length = stack.length - 2*n;
|
||||
vstack.length = vstack.length - n;
|
||||
lstack.length = lstack.length - n;
|
||||
}
|
||||
|
||||
function lex() {
|
||||
var token;
|
||||
token = self.lexer.lex() || 1; // $end = 1
|
||||
// if token isn't its numeric value, convert
|
||||
if (typeof token !== 'number') {
|
||||
token = self.symbols_[token] || token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
|
||||
while (true) {
|
||||
// retreive state number from top of stack
|
||||
state = stack[stack.length-1];
|
||||
|
||||
// use default actions if available
|
||||
if (this.defaultActions[state]) {
|
||||
action = this.defaultActions[state];
|
||||
} else {
|
||||
if (symbol == null)
|
||||
symbol = lex();
|
||||
// read action for current state and first input
|
||||
action = table[state] && table[state][symbol];
|
||||
}
|
||||
|
||||
// handle parse error
|
||||
_handle_error:
|
||||
if (typeof action === 'undefined' || !action.length || !action[0]) {
|
||||
|
||||
if (!recovering) {
|
||||
// Report error
|
||||
expected = [];
|
||||
for (p in table[state]) if (this.terminals_[p] && p > 2) {
|
||||
expected.push("'"+this.terminals_[p]+"'");
|
||||
}
|
||||
var errStr = '';
|
||||
if (this.lexer.showPosition) {
|
||||
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
|
||||
} else {
|
||||
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
|
||||
(symbol == 1 /*EOF*/ ? "end of input" :
|
||||
("'"+(this.terminals_[symbol] || symbol)+"'"));
|
||||
}
|
||||
this.parseError(errStr,
|
||||
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
|
||||
}
|
||||
|
||||
// just recovered from another error
|
||||
if (recovering == 3) {
|
||||
if (symbol == EOF) {
|
||||
throw new Error(errStr || 'Parsing halted.');
|
||||
}
|
||||
|
||||
// discard current lookahead and grab another
|
||||
yyleng = this.lexer.yyleng;
|
||||
yytext = this.lexer.yytext;
|
||||
yylineno = this.lexer.yylineno;
|
||||
yyloc = this.lexer.yylloc;
|
||||
symbol = lex();
|
||||
}
|
||||
|
||||
// try to recover from error
|
||||
while (1) {
|
||||
// check for error recovery rule in this state
|
||||
if ((TERROR.toString()) in table[state]) {
|
||||
break;
|
||||
}
|
||||
if (state == 0) {
|
||||
throw new Error(errStr || 'Parsing halted.');
|
||||
}
|
||||
popStack(1);
|
||||
state = stack[stack.length-1];
|
||||
}
|
||||
|
||||
preErrorSymbol = symbol; // save the lookahead token
|
||||
symbol = TERROR; // insert generic error symbol as new lookahead
|
||||
state = stack[stack.length-1];
|
||||
action = table[state] && table[state][TERROR];
|
||||
recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
|
||||
}
|
||||
|
||||
// this shouldn't happen, unless resolve defaults are off
|
||||
if (action[0] instanceof Array && action.length > 1) {
|
||||
throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
|
||||
}
|
||||
|
||||
switch (action[0]) {
|
||||
|
||||
case 1: // shift
|
||||
//this.shiftCount++;
|
||||
|
||||
stack.push(symbol);
|
||||
vstack.push(this.lexer.yytext);
|
||||
lstack.push(this.lexer.yylloc);
|
||||
stack.push(action[1]); // push state
|
||||
symbol = null;
|
||||
if (!preErrorSymbol) { // normal execution/no error
|
||||
yyleng = this.lexer.yyleng;
|
||||
yytext = this.lexer.yytext;
|
||||
yylineno = this.lexer.yylineno;
|
||||
yyloc = this.lexer.yylloc;
|
||||
if (recovering > 0)
|
||||
recovering--;
|
||||
} else { // error just occurred, resume old lookahead f/ before error
|
||||
symbol = preErrorSymbol;
|
||||
preErrorSymbol = null;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // reduce
|
||||
//this.reductionCount++;
|
||||
|
||||
len = this.productions_[action[1]][1];
|
||||
|
||||
// perform semantic action
|
||||
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
|
||||
// default location, uses first token for firsts, last for lasts
|
||||
yyval._$ = {
|
||||
first_line: lstack[lstack.length-(len||1)].first_line,
|
||||
last_line: lstack[lstack.length-1].last_line,
|
||||
first_column: lstack[lstack.length-(len||1)].first_column,
|
||||
last_column: lstack[lstack.length-1].last_column
|
||||
};
|
||||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
|
||||
|
||||
if (typeof r !== 'undefined') {
|
||||
return r;
|
||||
}
|
||||
|
||||
// pop off stack
|
||||
if (len) {
|
||||
stack = stack.slice(0,-1*len*2);
|
||||
vstack = vstack.slice(0, -1*len);
|
||||
lstack = lstack.slice(0, -1*len);
|
||||
}
|
||||
|
||||
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
|
||||
vstack.push(yyval.$);
|
||||
lstack.push(yyval._$);
|
||||
// goto new state = table[STATE][NONTERMINAL]
|
||||
newState = table[stack[stack.length-2]][stack[stack.length-1]];
|
||||
stack.push(newState);
|
||||
break;
|
||||
|
||||
case 3: // accept
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}};
|
||||
/* Jison generated lexer */
|
||||
var lexer = (function(){
|
||||
var lexer = ({EOF:1,
|
||||
parseError:function parseError(str, hash) {
|
||||
if (this.yy.parseError) {
|
||||
this.yy.parseError(str, hash);
|
||||
} else {
|
||||
throw new Error(str);
|
||||
}
|
||||
},
|
||||
setInput:function (input) {
|
||||
this._input = input;
|
||||
this._more = this._less = this.done = false;
|
||||
this.yylineno = this.yyleng = 0;
|
||||
this.yytext = this.matched = this.match = '';
|
||||
this.conditionStack = ['INITIAL'];
|
||||
this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
|
||||
return this;
|
||||
},
|
||||
input:function () {
|
||||
var ch = this._input[0];
|
||||
this.yytext+=ch;
|
||||
this.yyleng++;
|
||||
this.match+=ch;
|
||||
this.matched+=ch;
|
||||
var lines = ch.match(/\n/);
|
||||
if (lines) this.yylineno++;
|
||||
this._input = this._input.slice(1);
|
||||
return ch;
|
||||
},
|
||||
unput:function (ch) {
|
||||
this._input = ch + this._input;
|
||||
return this;
|
||||
},
|
||||
more:function () {
|
||||
this._more = true;
|
||||
return this;
|
||||
},
|
||||
less:function (n) {
|
||||
this._input = this.match.slice(n) + this._input;
|
||||
},
|
||||
pastInput:function () {
|
||||
var past = this.matched.substr(0, this.matched.length - this.match.length);
|
||||
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
|
||||
},
|
||||
upcomingInput:function () {
|
||||
var next = this.match;
|
||||
if (next.length < 20) {
|
||||
next += this._input.substr(0, 20-next.length);
|
||||
}
|
||||
return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
|
||||
},
|
||||
showPosition:function () {
|
||||
var pre = this.pastInput();
|
||||
var c = new Array(pre.length + 1).join("-");
|
||||
return pre + this.upcomingInput() + "\n" + c+"^";
|
||||
},
|
||||
next:function () {
|
||||
if (this.done) {
|
||||
return this.EOF;
|
||||
}
|
||||
if (!this._input) this.done = true;
|
||||
|
||||
var token,
|
||||
match,
|
||||
tempMatch,
|
||||
index,
|
||||
col,
|
||||
lines;
|
||||
if (!this._more) {
|
||||
this.yytext = '';
|
||||
this.match = '';
|
||||
}
|
||||
var rules = this._currentRules();
|
||||
for (var i=0;i < rules.length; i++) {
|
||||
tempMatch = this._input.match(this.rules[rules[i]]);
|
||||
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
|
||||
match = tempMatch;
|
||||
index = i;
|
||||
if (!this.options.flex) break;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
lines = match[0].match(/\n.*/g);
|
||||
if (lines) this.yylineno += lines.length;
|
||||
this.yylloc = {first_line: this.yylloc.last_line,
|
||||
last_line: this.yylineno+1,
|
||||
first_column: this.yylloc.last_column,
|
||||
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
|
||||
this.yytext += match[0];
|
||||
this.match += match[0];
|
||||
this.yyleng = this.yytext.length;
|
||||
this._more = false;
|
||||
this._input = this._input.slice(match[0].length);
|
||||
this.matched += match[0];
|
||||
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
|
||||
if (this.done && this._input) this.done = false;
|
||||
if (token) return token;
|
||||
else return;
|
||||
}
|
||||
if (this._input === "") {
|
||||
return this.EOF;
|
||||
} else {
|
||||
this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
|
||||
{text: "", token: null, line: this.yylineno});
|
||||
}
|
||||
},
|
||||
lex:function lex() {
|
||||
var r = this.next();
|
||||
if (typeof r !== 'undefined') {
|
||||
return r;
|
||||
} else {
|
||||
return this.lex();
|
||||
}
|
||||
},
|
||||
begin:function begin(condition) {
|
||||
this.conditionStack.push(condition);
|
||||
},
|
||||
popState:function popState() {
|
||||
return this.conditionStack.pop();
|
||||
},
|
||||
_currentRules:function _currentRules() {
|
||||
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
|
||||
},
|
||||
topState:function () {
|
||||
return this.conditionStack[this.conditionStack.length-2];
|
||||
},
|
||||
pushState:function begin(condition) {
|
||||
this.begin(condition);
|
||||
}});
|
||||
lexer.options = {};
|
||||
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
|
||||
|
||||
var YYSTATE=YY_START
|
||||
switch($avoiding_name_collisions) {
|
||||
case 0:/* skip whitespace */
|
||||
break;
|
||||
case 1:return 6
|
||||
break;
|
||||
case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4
|
||||
break;
|
||||
case 3:return 17
|
||||
break;
|
||||
case 4:return 18
|
||||
break;
|
||||
case 5:return 23
|
||||
break;
|
||||
case 6:return 24
|
||||
break;
|
||||
case 7:return 22
|
||||
break;
|
||||
case 8:return 21
|
||||
break;
|
||||
case 9:return 10
|
||||
break;
|
||||
case 10:return 11
|
||||
break;
|
||||
case 11:return 8
|
||||
break;
|
||||
case 12:return 14
|
||||
break;
|
||||
case 13:return 'INVALID'
|
||||
break;
|
||||
}
|
||||
};
|
||||
lexer.rules = [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/];
|
||||
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}};
|
||||
|
||||
|
||||
;
|
||||
return lexer;})()
|
||||
parser.lexer = lexer;
|
||||
return parser;
|
||||
})();
|
||||
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
|
||||
exports.parser = jsonlint;
|
||||
exports.parse = function () { return jsonlint.parse.apply(jsonlint, arguments); }
|
||||
exports.main = function commonjsMain(args) {
|
||||
if (!args[1])
|
||||
throw new Error('Usage: '+args[0]+' FILE');
|
||||
if (typeof process !== 'undefined') {
|
||||
var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
|
||||
} else {
|
||||
var cwd = require("file").path(require("file").cwd());
|
||||
var source = cwd.join(args[1]).read({charset: "utf-8"});
|
||||
}
|
||||
return exports.parser.parse(source);
|
||||
}
|
||||
if (typeof module !== 'undefined' && require.main === module) {
|
||||
exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
|
||||
}
|
||||
}
|
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jsoneditor",
|
||||
"version": "2.3.7-SNAPSHOT",
|
||||
"version": "3.0.0-SNAPSHOT",
|
||||
"main": "jsoneditor.js",
|
||||
"description": "A web-based tool to view, edit and format JSON",
|
||||
"tags": [
|
||||
|
@ -16,12 +16,16 @@
|
|||
"url": "https://github.com/josdejong/jsoneditor.git"
|
||||
},
|
||||
"bugs": "https://github.com/josdejong/jsoneditor/issues",
|
||||
"scripts": {},
|
||||
"scripts": {
|
||||
"build": "jake"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"jake": "latest",
|
||||
"jake-utils": "latest",
|
||||
"archiver": "latest",
|
||||
"clean-css": "latest"
|
||||
"clean-css": "latest",
|
||||
"jsonlint": "latest",
|
||||
"ace": "git://github.com/ajaxorg/ace.git"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
|
||||
<!-- jsoneditor -->
|
||||
<link rel="stylesheet" type="text/css" href="../jsoneditor.css">
|
||||
<script type="text/javascript" src="../jsoneditor.js"></script>
|
||||
|
||||
<!-- ace code editor -->
|
||||
<script type="text/javascript" src="../node_modules/ace/build/src-min/ace.js"></script>
|
||||
<script type="text/javascript" src="../node_modules/ace/build/src-min/mode-json.js"></script>
|
||||
<script type="text/javascript" src="../node_modules/ace/build/src-min/theme-textmate.js"></script>
|
||||
<script type="text/javascript" src="../jsoneditor/js/ace/theme-jsoneditor.js"></script>
|
||||
|
||||
<!-- json lint -->
|
||||
<script type="text/javascript" src="../node_modules/jsonlint/lib/jsonlint.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
font: 10.5pt arial;
|
||||
color: #4d4d4d;
|
||||
line-height: 150%;
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
#jsoneditor {
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
Switch editor mode using the mode box.
|
||||
Note that the mode can be changed programmatically as well using the method
|
||||
<code>editor.setMode(mode)</code>, try it in the console of your browser.
|
||||
</p>
|
||||
|
||||
<div id="jsoneditor"></div>
|
||||
|
||||
<script type="text/javascript" >
|
||||
var container = document.getElementById('jsoneditor');
|
||||
|
||||
var options = {
|
||||
mode: 'tree',
|
||||
modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
|
||||
error: function (err) {
|
||||
alert(err.toString());
|
||||
}
|
||||
};
|
||||
|
||||
var json = {
|
||||
"array": [1, 2, 3],
|
||||
"boolean": true,
|
||||
"null": null,
|
||||
"number": 123,
|
||||
"object": {"a": "b", "c": "d"},
|
||||
"string": "Hello World"
|
||||
};
|
||||
|
||||
var editor = new jsoneditor.JSONEditor(container, options, json);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Loading…
Reference in New Issue