Skip to content

Commit 4d75e3a

Browse files
committed
Update README,
Update some source code
1 parent 9b56806 commit 4d75e3a

File tree

7 files changed

+37
-125
lines changed

7 files changed

+37
-125
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# json-editor
22

3-
> A schema awareable JSON editor.
3+
> A schema-aware editor for JSON document. It provides a tree view to present the structure of JSON document, user could manipulate the JSON from context menu. There is a text view to present the content of JSON document, user may edit JSON within.
44
> Develop with Vue.js 2.
5+
> Please reference the [project website](https://json-editor.tangramjs.com) fro detail.
6+
7+
## Features
8+
#### Pallet of user schemas
9+
List of all user schemas, user could select one of them as current schema of JSON document. User could save or update custom schema, load custom schema for editing, and delete custom schema.
10+
#### Tree View of JSON document
11+
The structure of JSON document, could expend or collapse at any level.
12+
#### Context Menu
13+
Right-click on the element in tree view could bring out the context menu for that element, and perform actions specific for that element.
14+
#### Text View of JSON document
15+
A text view to display content of schema. User could also edit the document directly in text view.
16+
#### Schema validation
17+
The JSON document would validate with current selected schema after every update.
18+
#### Undo/Redo
19+
Undo and Redo could keep track of every update of JSON document.
20+
#### Copy JSON document to clipboard
21+
Copy JSON document to system clipboard.
22+
#### Download JSON document to file
23+
Download JSON document as a json file.
24+
#### Load JSON document from file
25+
Load JSON document from a json schema file.
526

627
## Install
728
``` bash
@@ -22,3 +43,5 @@ npm run build
2243
# build for production and view the bundle analyzer report
2344
npm run build --report
2445
```
46+
## Live demo
47+
Live demo of source code: [https://tangram-js.github.io/json-editor/](https://tangram-js.github.io/json-editor/)

docs/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<html>
33
<head>
44
<meta charset=utf-8>
5-
<title>Demo of json-editor</title>
5+
<title>Demo of JSON Editor</title>
66
</head>
77
<body>
88
<div>
9-
<a href="demo">JSON editor with JSON schema meta schema (JSON schema editor)</a>
9+
<a href="demo">JSON editor with JSON schema meta-schema (JSON schema editor)</a>
1010
</div>
1111
<div>
1212
<a href="demo/#/?schema=sample_order">JSON editor with sample order schema</a>
1313
</div>
1414
</body>
15-
</html>
15+
</html>

src/components/json-editor/defaultData.js

Lines changed: 0 additions & 93 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export { defaultSchema } from './defaultData'
2-
export { defaultValue } from './defaultData'
31
export { menuData } from './menuData'

src/components/json-editor/menuData.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@ export var menuData = {
2020
action (source) {
2121
source.remove()
2222
}
23-
},
24-
{
25-
name: 'moveUp',
26-
label: 'Move Up',
27-
disabled (source) {
28-
return !(source.node.parent)
29-
},
30-
action: source => {
31-
source.moveUp()
32-
}
33-
},
34-
{
35-
name: 'moveDown',
36-
label: 'Move Down',
37-
disabled (source) {
38-
return !(source.node.parent)
39-
},
40-
action: source => {
41-
source.moveDown()
42-
}
4323
}
4424
]
4525
}

src/components/json-tree/schemas/json_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "JSON schema meta-schema",
2+
"title": "JSON schema meta-schema",
33
"definitions": {
44
"schemaArray": {
55
"type": "array",

src/components/json-tree/store.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import schemaFunctions from './schemaFunctions'
88

99
var selectedNode
1010
var repository
11+
var jsonSchema
1112

1213
function generateId () {
1314
return (new Date()).getTime() + ('000000000' + Math.floor((Math.random() * 10000) + 1)).substr(-4)
@@ -90,7 +91,9 @@ async function retrieveSchemaByName (schemaName) {
9091
if (repository) {
9192
try {
9293
schema = await repository.retrieveSchema(schemaName)
93-
} catch (err) {}
94+
} catch (err) {
95+
console.log(`Retrieve schema (${schemaName}) failure: ${err.message}`)
96+
}
9497
}
9598
if (schema !== null) return schema
9699
return await defaultRepository.retrieveSchema(schemaName)
@@ -580,7 +583,8 @@ async function retrieveChildSchema (schema, childName, childValue) {
580583
if (!childName) return await retrieveSchemaFromValue(childValue)
581584
if (typeof schema === 'undefined' || schema === null) return await retrieveSchemaFromValue(childValue)
582585
if (schema.type === 'object') {
583-
if (schema.properties) return schema.properties[childName]
586+
if (schema.properties && schema.properties[childName]) return schema.properties[childName]
587+
if (typeof schema.additionalProperties === 'object') return schema.additionalProperties
584588
}
585589
if (schema.type === 'array') {
586590
if (schema.items) {
@@ -689,9 +693,9 @@ class Store {
689693

690694
async setValue (value, schema, name, renamable) {
691695
this.schema = schema
692-
let srcSchema = await dereferenceSchema(schema)
693-
if (value === null) value = generateDefault(srcSchema)
694-
this.tree = await populateJsonTree(value, srcSchema, name, renamable)
696+
jsonSchema = await dereferenceSchema(schema)
697+
if (value === null) value = generateDefault(jsonSchema)
698+
this.tree = await populateJsonTree(value, jsonSchema, name, renamable)
695699
this.tree.selected = true
696700
this.selectedNode = this.tree
697701
this.alertMessage = validateWithSchema(this.schema, this.tree.value)

0 commit comments

Comments
 (0)