├── .gitignore ├── .npmignore ├── README.md ├── babel.config.js ├── examples ├── App.vue ├── assets │ └── logo.png ├── components │ └── HelloWorld.vue └── main.js ├── jsconfig.json ├── lib ├── demo.html ├── json-schema-editor-vue3.common.js ├── json-schema-editor-vue3.common.js.map ├── json-schema-editor-vue3.css ├── json-schema-editor-vue3.umd.js ├── json-schema-editor-vue3.umd.js.map ├── json-schema-editor-vue3.umd.min.js └── json-schema-editor-vue3.umd.min.js.map ├── package-lock.json ├── package.json ├── packages ├── index.js └── json-schema-editor │ ├── LocalProvider │ └── index.js │ ├── index.js │ ├── main.vue │ ├── type │ ├── array.js │ ├── boolean.js │ ├── integer.js │ ├── number.js │ ├── object.js │ ├── string.js │ └── type.js │ └── util.js ├── public ├── favicon.ico └── index.html └── vue.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | node_modules/.bin/ 5 | build/ 6 | config/ 7 | static/ 8 | .babelrc 9 | .editorconfig 10 | .gitignore 11 | .npmignore 12 | .postcssrc.js 13 | index.html 14 | package-lock.json 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | 19 | #Editordirectoriesandfiles 20 | .idea 21 | .vscode 22 | *.suo 23 | *.ntvs* 24 | *.njsproj 25 | *.sln 26 | #忽略目录 27 | examples/ 28 | packages/ 29 | public/ 30 | #忽略指定文件 31 | vue.config.js 32 | babel.config.js 33 | *.map -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | json-schema-editor-vue 3 |

4 | 5 | [![Start](https://img.shields.io/github/stars/zyqwst/json-schema-editor-vue?style=social)](https://github.com/zyqwst/json-schema-editor-vue/stargazers) 6 | [![Fork](https://img.shields.io/github/forks/zyqwst/json-schema-editor-vue?style=social)](https://github.com/zyqwst/json-schema-editor-vue/fork) 7 | [![GitHub open issues](https://img.shields.io/github/issues/zyqwst/json-schema-editor-vue.svg)](https://github.com/zyqwst/json-schema-editor-vue/issues?q=is%3Aopen+is%3Aissue) 8 | [![npm download](https://img.shields.io/npm/dt/json-schema-editor-vue.svg?maxAge=30)](https://www.npmjs.com/package/json-schema-editor-vue) 9 | [![npm download per month](https://img.shields.io/npm/dm/json-schema-editor-vue.svg)](https://www.npmjs.com/package/json-schema-editor-vue) 10 | [![npm version](https://img.shields.io/npm/v/json-schema-editor-vue.svg)](https://www.npmjs.com/package/json-schema-editor-vue) 11 | [![MIT License](https://img.shields.io/github/license/zyqwst/json-schema-editor-vue.svg)](https://github.com/zyqwst/json-schema-editor-vue/blob/master/LICENSE) 12 | 13 | A json-schema editor of high efficient and easy-to-use, base on Vue3 14 | 15 | ### 如果你使用Vue2,请查看 [json-schema-editor base on Vue2](https://github.com/zyqwst/json-schema-editor-vue) 16 | 17 |

18 | 19 |

20 | 21 | **支持自定义属性,满足特殊的需求** 22 |

23 | 24 |

25 | 26 | ### Example 27 | **Demo** [http://json-schema.sviip.com](http://json-schema.sviip.com) 28 | 29 | **[国内Demo](http://json-schema-editor.sviip.com)** 30 | ### Usage 31 | 32 | ```bash 33 | # vue2 34 | npm install json-schema-editor-vue 35 | # vue3 36 | npm install json-schema-editor-vue3 37 | ``` 38 | 39 | ```vue 40 | import JsonSchemaEditor from 'json-schema-editor-vue' 41 | import 'json-schema-editor-vue/lib/json-schema-editor-vue.css' 42 | Vue.use(JsonSchemaEditor) 43 | ``` 44 | 45 | ```vue 46 | 53 | 54 | 69 | ``` 70 | ### json-schema-editor-vue属性说明如下: 71 | 72 | |属性|说明|类型|是否必须|默认值| 73 | :-|:-|:-|:-|:- 74 | |value|传入一个默认的树节点,用来接收编辑后的json schema结果|Object|是|| 75 | |disabled|节点名称不可编辑|Boolean||`false`| 76 | |disabledType|节点类型不可选择|Boolean||`false`| 77 | |root|是否是根节点|Boolean||`true`| 78 | |custom|是否允许添加自定义属性|Boolean||`false`| 79 | |lang|国际化(可选zh_CN和en_US)|String||`zh_CN`| 80 | 81 | Don't forget to star if it helped! 82 | 如果对您有帮助,别忘记给个星哦 83 | 84 | ### Links 85 | 86 | - [json-schema-editor-visual](https://github.com/YMFE/json-schema-editor-visual) 87 | - [vue-json-schema-editor-visual](https://github.com/giscafer/vue-json-schema-editor-visual) 88 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ], 5 | plugins: [ 6 | [ 7 | "import", 8 | { 9 | libraryName: "ant-design-vue", 10 | libraryDirectory: "es", 11 | "style": "css" 12 | } 13 | ] 14 | ] 15 | } -------------------------------------------------------------------------------- /examples/App.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 77 | 142 | -------------------------------------------------------------------------------- /examples/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyqwst/json-schema-editor-vue3/80fa20948645ea27d2350b7485f54d3e6d23d6a0/examples/assets/logo.png -------------------------------------------------------------------------------- /examples/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 41 | 42 | 43 | 59 | -------------------------------------------------------------------------------- /examples/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | import JsonSchemaEditor from '../packages/index' 4 | import { Modal} from 'ant-design-vue' 5 | createApp(App).use(JsonSchemaEditor).use(Modal).mount('#app') 6 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "esnext", 5 | "baseUrl": "./", 6 | "moduleResolution": "node", 7 | "paths": { 8 | "@/*": [ 9 | "examples/*" 10 | ] 11 | }, 12 | "lib": [ 13 | "esnext", 14 | "dom", 15 | "dom.iterable", 16 | "scripthost" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/demo.html: -------------------------------------------------------------------------------- 1 | json-schema-editor-vue3 demo -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "json-schema-editor-vue3", 3 | "version": "1.2.0", 4 | "author": "zhangyq", 5 | "description": "A json-schema editor of high efficient and easy-to-use, base on Vue3", 6 | "keywords": [ 7 | "jsonschema", 8 | "jsonschemavue", 9 | "jsonschemaeditor", 10 | "json", 11 | "jsoneditor" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/zyqwst/json-schema-editor-vue3" 16 | }, 17 | "homepage": "http://json-schema.sviip.com/", 18 | "license": " Apache-2.0 License", 19 | "main": "lib/json-schema-editor-vue3.umd.min.js", 20 | "private": false, 21 | "scripts": { 22 | "serve": "vue-cli-service serve", 23 | "build": "vue-cli-service build", 24 | "lint": "vue-cli-service lint", 25 | "lib": "vue-cli-service build --target lib --name json-schema-editor-vue3 --dest lib packages/index.js" 26 | }, 27 | "dependencies": { 28 | "@ant-design/icons-vue": "^6.1.0", 29 | "core-js": "^3.8.3", 30 | "vue": "^3.2.13" 31 | }, 32 | "devDependencies": { 33 | "@babel/core": "^7.12.16", 34 | "@babel/eslint-parser": "^7.12.16", 35 | "@vue/cli-plugin-babel": "~5.0.0", 36 | "@vue/cli-plugin-eslint": "~5.0.0", 37 | "@vue/cli-service": "~5.0.0", 38 | "ant-design-vue": "^3.2.10", 39 | "babel-plugin-import": "^1.13.5", 40 | "eslint": "^7.32.0", 41 | "eslint-plugin-vue": "^8.0.3", 42 | "generate-schema": "^2.6.0" 43 | }, 44 | "eslintConfig": { 45 | "root": true, 46 | "env": { 47 | "node": true 48 | }, 49 | "extends": [ 50 | "plugin:vue/vue3-essential", 51 | "eslint:recommended" 52 | ], 53 | "parserOptions": { 54 | "parser": "@babel/eslint-parser" 55 | }, 56 | "rules": {} 57 | }, 58 | "browserslist": [ 59 | "> 1%", 60 | "last 2 versions", 61 | "not dead", 62 | "not ie 11" 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /packages/index.js: -------------------------------------------------------------------------------- 1 | import JsonSchemaEditor from './json-schema-editor/index' 2 | const components = [ 3 | JsonSchemaEditor 4 | ] 5 | 6 | // 定义 install 方法 7 | const install = function (Vue) { 8 | if (install.installed) return 9 | install.installed = true 10 | // 遍历并注册全局组件 11 | components.map(component => { 12 | Vue.component(component.name, component) 13 | }) 14 | } 15 | 16 | if (typeof window !== 'undefined' && window.Vue) { 17 | install(window.Vue) 18 | } 19 | 20 | export default { 21 | // 导出的对象必须具备一个 install 方法 22 | install, 23 | // 组件列表 24 | ...components 25 | } -------------------------------------------------------------------------------- /packages/json-schema-editor/LocalProvider/index.js: -------------------------------------------------------------------------------- 1 | const langs = { 2 | en_US: { 3 | 'title': 'Title', 4 | 'import_json': 'Import JSON', 5 | 'base_setting': 'Base Setting', 6 | 'all_setting': 'Source Code', 7 | 'default': 'Default', 8 | 'description':'Description', 9 | "adv_setting": "Advanced Settings", 10 | "add_child_node": "Add child node", 11 | 'add_sibling_node': 'Add sibling nodes', 12 | 'add_node':'Add sibling/child nodes', 13 | 'remove_node': 'Remove node', 14 | 'child_node': 'Child node', 15 | 'sibling_node':'Sibling node', 16 | 'ok':'OK', 17 | 'cancel':'Cancel', 18 | 'minLength':'Min length', 19 | 'maxLength': 'Max length', 20 | 'pattern':'MUST be a valid regular expression.', 21 | 'exclusiveMinimum': 'Value strictly less than', 22 | 'exclusiveMaximum': 'Value strictly more than', 23 | 'minimum': 'Min', 24 | 'maximum': 'Max', 25 | 'uniqueItems': 'Unique Items', 26 | 'minItems':'MinItems', 27 | 'maxItems': 'MaxItems', 28 | 'minProperties':'MinProperties', 29 | 'maxProperties': 'MaxProperties', 30 | 'checked_all': 'Checked All', 31 | 'valid_json': 'Not valid json', 32 | 'enum': 'Enum', 33 | 'enum_msg': 'One value per line', 34 | 'enum_desc': 'desc', 35 | 'enum_desc_msg': 'enum description', 36 | 'required': 'Required', 37 | 'mock': 'mock', 38 | 'mockLink': 'Help', 39 | 'format': 'Format', 40 | 'nothing': 'Nothing', 41 | 'preview': 'Preview', 42 | 'add_custom': 'Add Custom Prop', 43 | }, 44 | zh_CN: { 45 | 'title': '标题', 46 | 'import_json': '导入 json', 47 | 'base_setting': '基础设置', 48 | 'all_setting': '编辑源码', 49 | 'default': '默认值', 50 | 'description':'描述', 51 | 'adv_setting': '高级设置', 52 | "add_child_node": "添加子节点", 53 | 'add_sibling_node': '添加兄弟节点', 54 | 'add_node':'添加兄弟/子节点', 55 | 'remove_node': '删除节点', 56 | 'child_node': '子节点', 57 | 'sibling_node':'兄弟节点', 58 | 'ok':'确定', 59 | 'cancel':'取消', 60 | 'minLength':'最小长度', 61 | 'maxLength': '最大长度', 62 | 'pattern': '用正则表达式约束字符串', 63 | 'exclusiveMinimum': '开启后,数据必须大于最小值', 64 | 'exclusiveMaximum': '开启后,数据必须小于最大值', 65 | 'minimum': '最小值', 66 | 'maximum': '最大值', 67 | 'uniqueItems': '开启后,每个元素都不相同', 68 | 'minItems':'最小元素个数', 69 | 'maxItems': '最大元素个数', 70 | 'minProperties':'最小元素个数', 71 | 'maxProperties': '最大元素个数', 72 | 'checked_all': '全选', 73 | 'valid_json': '不是合法的json字符串', 74 | 'enum': '枚举', 75 | 'enum_msg': '每行写一个值', 76 | 'enum_desc': '备注', 77 | 'enum_desc_msg': '备注描述信息', 78 | 'required': '是否必须', 79 | 'mock': 'mock', 80 | 'mockLink': '查看文档', 81 | 'format': '格式化', 82 | 'nothing': '无', 83 | 'preview': '预览', 84 | 'add_custom': '添加自定义属性' 85 | } 86 | } 87 | 88 | export default (lang) => { 89 | return langs[lang] 90 | } 91 | -------------------------------------------------------------------------------- /packages/json-schema-editor/index.js: -------------------------------------------------------------------------------- 1 | import JsonSchemaEditor from './main.vue' 2 | 3 | JsonSchemaEditor.install = function (Vue) { 4 | Vue.component(JsonSchemaEditor.name, JsonSchemaEditor) 5 | } 6 | 7 | export default JsonSchemaEditor -------------------------------------------------------------------------------- /packages/json-schema-editor/main.vue: -------------------------------------------------------------------------------- 1 | 132 | 434 | 470 | -------------------------------------------------------------------------------- /packages/json-schema-editor/type/array.js: -------------------------------------------------------------------------------- 1 | const value = { 2 | description: null, 3 | minItems:null, 4 | maxItems:null, 5 | uniqueItems:false 6 | } 7 | const attr = { 8 | description: { 9 | name: '描述', 10 | type: 'string' 11 | }, 12 | maxItems:{ 13 | name: '最大元素个数', 14 | type: 'integer' 15 | }, 16 | minItems:{ 17 | name: '最小元素个数', 18 | type: 'integer' 19 | }, 20 | uniqueItems:{ 21 | name:'元素不可重复', 22 | type: 'boolean' 23 | } 24 | } 25 | const wrapper = {value, attr} 26 | export default wrapper -------------------------------------------------------------------------------- /packages/json-schema-editor/type/boolean.js: -------------------------------------------------------------------------------- 1 | const value = { 2 | description: null 3 | } 4 | const attr = { 5 | description: { 6 | name: '描述', 7 | type: 'string' 8 | } 9 | } 10 | const wrapper = {value, attr} 11 | export default wrapper -------------------------------------------------------------------------------- /packages/json-schema-editor/type/integer.js: -------------------------------------------------------------------------------- 1 | const value = { 2 | description: null, 3 | maximum: null, 4 | minimum: null, 5 | exclusiveMaximum:null, 6 | exclusiveMinimum:null, 7 | enum:null 8 | } 9 | const attr = { 10 | description: { 11 | name: '描述', 12 | type: 'string', 13 | }, 14 | maximum:{ 15 | name:'最大值', 16 | type:'integer' 17 | }, 18 | minimum:{ 19 | name:'最小值', 20 | type:'integer' 21 | }, 22 | exclusiveMaximum:{ 23 | name:'不包含最大值', 24 | type:'boolean' 25 | }, 26 | exclusiveMinimum:{ 27 | name:'不包含最小值', 28 | type:'boolean' 29 | }, 30 | enum:{ 31 | name:'枚举', 32 | type:'array' 33 | } 34 | } 35 | const wrapper = {value, attr} 36 | export default wrapper -------------------------------------------------------------------------------- /packages/json-schema-editor/type/number.js: -------------------------------------------------------------------------------- 1 | const value = { 2 | description: null, 3 | maximum: null, 4 | minimum: null, 5 | exclusiveMaximum:null, 6 | exclusiveMinimum:null, 7 | enum:null 8 | } 9 | const attr = { 10 | description: { 11 | name: '描述', 12 | type: 'string', 13 | }, 14 | maximum:{ 15 | name:'最大值', 16 | type:'number' 17 | }, 18 | minimum:{ 19 | name:'最小值', 20 | type:'number' 21 | }, 22 | exclusiveMaximum:{ 23 | name:'不包含最大值', 24 | type:'boolean' 25 | }, 26 | exclusiveMinimum:{ 27 | name:'不包含最小值', 28 | type:'boolean' 29 | }, 30 | enum:{ 31 | name:'枚举', 32 | type:'array' 33 | } 34 | } 35 | const wrapper = {value, attr} 36 | export default wrapper -------------------------------------------------------------------------------- /packages/json-schema-editor/type/object.js: -------------------------------------------------------------------------------- 1 | const value = { 2 | description: null, 3 | maxProperties: null, 4 | minProperties: null 5 | } 6 | const attr = { 7 | description: { 8 | name: '描述', 9 | type: 'string', 10 | }, 11 | maxProperties:{ 12 | name:'最大元素个数', 13 | type:'integer' 14 | }, 15 | minProperties:{ 16 | name:'最小元素个数', 17 | type:'integer' 18 | } 19 | } 20 | const wrapper = {value, attr} 21 | export default wrapper -------------------------------------------------------------------------------- /packages/json-schema-editor/type/string.js: -------------------------------------------------------------------------------- 1 | const value = { 2 | description: null, 3 | maxLength: null, 4 | minLength: null, 5 | pattern: null, 6 | format:undefined, 7 | enum:undefined 8 | } 9 | const attr = { 10 | description: { 11 | name: '描述', 12 | type: 'string', 13 | }, 14 | maxLength:{ 15 | name:'最大字符数', 16 | type:'integer' 17 | }, 18 | minLength:{ 19 | name:'最小字符数', 20 | type:'integer' 21 | }, 22 | pattern: { 23 | name: '正则表达式', 24 | type:'string' 25 | }, 26 | format: { 27 | name:'格式', 28 | type:'array', 29 | enums:['date','date-time','email','hostname','ipv4','ipv6','uri'] 30 | }, 31 | enum:{ 32 | name:'枚举', 33 | type:'array' 34 | } 35 | } 36 | const wrapper = {value, attr} 37 | export default wrapper -------------------------------------------------------------------------------- /packages/json-schema-editor/type/type.js: -------------------------------------------------------------------------------- 1 | import _object from './object' 2 | import _string from './string' 3 | import _array from './array' 4 | import _boolean from './boolean' 5 | import _integer from './integer' 6 | import _number from './number' 7 | const TYPE_NAME = ['string', 'number', 'integer','object', 'array', 'boolean'] 8 | 9 | const TYPE = { 10 | 'object': _object, 11 | 'string': _string, 12 | 'array': _array, 13 | 'boolean': _boolean, 14 | 'integer': _integer, 15 | 'number': _number 16 | } 17 | export {TYPE ,TYPE_NAME} 18 | -------------------------------------------------------------------------------- /packages/json-schema-editor/util.js: -------------------------------------------------------------------------------- 1 | export function clearAttr(obj) { 2 | for(let key in obj){ 3 | delete obj[key] 4 | } 5 | } 6 | /** 7 | * 快速拷贝两个对象的属性值 8 | * @param {*} source 9 | * @param {*} target 10 | */ 11 | export function copyAttr(source, target){ 12 | Object.keys(target).forEach(key=>{target[key]=source[key]}) 13 | } 14 | 15 | export function isNull(ele){ 16 | if(typeof ele==='undefined'){ 17 | return true; 18 | }else if(ele===null){ 19 | return true; 20 | }else if(ele===''){ 21 | return true; 22 | } 23 | return false; 24 | } 25 | export function renamePropertyAndKeepKeyPrecedence(obj, [oldKey, newKey]) { 26 | const descriptors = Object.getOwnPropertyDescriptors(obj) 27 | if (Object.prototype.hasOwnProperty.call(descriptors, oldKey)) { 28 | Object.entries(descriptors) 29 | .reduce((target, [key, descriptor]) => { 30 | Reflect.deleteProperty(target, key) 31 | if (key === oldKey) { 32 | key = newKey 33 | } 34 | Reflect.defineProperty(target, key, descriptor) 35 | return target; 36 | }, obj) 37 | } 38 | return obj 39 | } 40 | 41 | export function _debounce (callback, delay = 1000) { 42 | let timer = null; 43 | return function () { 44 | let self = this; 45 | let args = arguments; 46 | timer && clearTimeout(timer) 47 | timer = setTimeout(function () { 48 | callback.apply(self, args) 49 | }, delay); 50 | } 51 | } -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zyqwst/json-schema-editor-vue3/80fa20948645ea27d2350b7485f54d3e6d23d6a0/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require('@vue/cli-service') 2 | module.exports = defineConfig({ 3 | transpileDependencies: true, 4 | pages: { 5 | index: { 6 | entry: 'examples/main.js', 7 | template: 'public/index.html', 8 | filename: 'index.html' 9 | } 10 | }, 11 | devServer: { 12 | port: 8080 13 | } 14 | }) 15 | --------------------------------------------------------------------------------