├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .postcssrc.js ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js └── webpack.prod.conf.js ├── config ├── dev.env.js ├── index.js └── prod.env.js ├── favicon.ico ├── index.html ├── package.json ├── src ├── App.vue ├── components │ ├── ContextMenu.vue │ ├── ContextMenuItem.vue │ ├── JsonSchemaEditor.vue │ ├── SplitPanel.vue │ ├── Toolbox.vue │ ├── ToolboxComponent.vue │ ├── Tree.vue │ ├── TreeNode.vue │ ├── account │ │ ├── ChangePassword.vue │ │ ├── SignIn.vue │ │ ├── SignUp.vue │ │ └── VerifyEmail.vue │ ├── context-menu-items │ │ ├── ButtonMenuItem.vue │ │ ├── CheckBoxMenuItem.vue │ │ ├── DividerMenuItem.vue │ │ ├── HeaderMenuItem.vue │ │ ├── SelectMenuItem.vue │ │ ├── TextInputMenuItem.vue │ │ └── index.js │ ├── icon-module │ │ ├── Thumbs.db │ │ ├── array16.png │ │ ├── array24.png │ │ ├── bookmark16.png │ │ ├── bookmark24.png │ │ ├── dependencies16.png │ │ ├── dependencies24.png │ │ ├── dependency16.png │ │ ├── dependency24.png │ │ ├── enum16.png │ │ ├── enum24.png │ │ ├── index.js │ │ ├── items-16.png │ │ ├── items-24.png │ │ ├── items16.png │ │ ├── items24.png │ │ ├── json_schema16.png │ │ ├── json_schema24.png │ │ ├── not16.png │ │ ├── not24.png │ │ ├── object16.png │ │ ├── object24.png │ │ ├── options16.png │ │ ├── options24.png │ │ ├── pen16.png │ │ ├── pen24.png │ │ ├── properties16.png │ │ ├── properties24.png │ │ ├── ref16.png │ │ ├── ref24.png │ │ ├── remark16.png │ │ ├── remark24.png │ │ ├── required16.png │ │ ├── required24.png │ │ ├── type16.png │ │ └── type24.png │ ├── json-schema-editor │ │ ├── PropertyInspector.vue │ │ ├── componentData.js │ │ ├── components │ │ │ ├── allOf.js │ │ │ ├── anyOf.js │ │ │ ├── array.js │ │ │ ├── boolean.js │ │ │ ├── definitions.js │ │ │ ├── dependencies.js │ │ │ ├── dependencyItem.js │ │ │ ├── enum.js │ │ │ ├── index.js │ │ │ ├── integer.js │ │ │ ├── items.js │ │ │ ├── jsonSchema.js │ │ │ ├── not.js │ │ │ ├── null.js │ │ │ ├── number.js │ │ │ ├── object.js │ │ │ ├── oneOf.js │ │ │ ├── properties.js │ │ │ ├── ref.js │ │ │ ├── required.js │ │ │ └── string.js │ │ ├── convertSchemaToTree.js │ │ ├── convertTreeToSchema.js │ │ ├── index.js │ │ ├── inspectors │ │ │ ├── BasicInspector.vue │ │ │ ├── DependencyItemInspector.vue │ │ │ ├── EnumInspector.vue │ │ │ ├── Property.js │ │ │ ├── RefInspector.vue │ │ │ ├── RequiredInspector.vue │ │ │ └── index.js │ │ ├── menuData.js │ │ ├── repository-firebase.js │ │ └── treeData.js │ └── tree │ │ └── store.js ├── firebase │ └── index.js ├── main.js └── router │ └── index.js └── static └── .gitkeep /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { "modules": false }], 4 | "stage-2" 5 | ], 6 | "plugins": ["transform-runtime"], 7 | "comments": false, 8 | "env": { 9 | "test": { 10 | "presets": ["env", "stage-2"], 11 | "plugins": [ "istanbul" ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | build/*.js 2 | config/*.js 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // http://eslint.org/docs/user-guide/configuring 2 | 3 | module.exports = { 4 | root: true, 5 | parser: 'babel-eslint', 6 | parserOptions: { 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | }, 12 | // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style 13 | extends: 'standard', 14 | // required to lint *.vue files 15 | plugins: [ 16 | 'html' 17 | ], 18 | // add your custom rules here 19 | 'rules': { 20 | // allow paren-less arrow functions 21 | 'arrow-parens': 0, 22 | // allow async-await 23 | 'generator-star-spacing': 0, 24 | // allow debugger during development 25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | dist/ 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | .idea 8 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Welcome for contribute 2 | JSON Schema Editor project welcomes for bug fixing and add new features, feel free to contribute. 3 | ## Install 4 | ``` bash 5 | git clone https://github.com/tangram-js/json-schema-editor.git 6 | ``` 7 | ## Build 8 | 9 | ``` bash 10 | # install dependencies 11 | npm install 12 | 13 | # serve with hot reload at localhost:8080 14 | npm run dev 15 | 16 | # build for production with minification 17 | npm run build 18 | 19 | # build for production and view the bundle analyzer report 20 | npm run build --report 21 | ``` 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # json-schema-editor 2 | 3 | > An intuitive editor for JSON schema which provides a tree view to present structure of schema and a property inspector to edit the properties of schema element. 4 | > Develop with Vue.js 2 and Firebase. Please reference the [project website](https://json-schema-editor.tangramjs.com) for detail. 5 | 6 | ## Features 7 | #### Pallet of schema elements 8 | List of all elements of JSON schema, could drag and drop to tree view. 9 | #### Pallet of user schemas 10 | List of all user schemas, which are stored in Firebase. User could save, load, delete and import schemas, schema could drag and drop to tree view. 11 | #### Tree View of schema elements 12 | The structure of schema, could expend or collapse at any level. 13 | #### Context Menu 14 | Right-click on the element in tree view could bring out the context menu for that element, and perform actions specific for that element. 15 | #### Property Inspector of schema elements 16 | A panel to edit properties of schema element. 17 | #### Text View of schema 18 | A text view to display content of schema. 19 | #### Drag and Drop 20 | The element of JSON schema could drag and drop from pallet to tree view or within tree view. 21 | #### Undo/Redo 22 | Undo and Redo could keep track of every update of schema. 23 | #### Schema Repository 24 | User could save/load schemas to/from Firebase repository, import schema from file. 25 | 26 | ## Install 27 | ``` bash 28 | git clone https://github.com/tangram-js/json-schema-editor.git 29 | ``` 30 | ## Build 31 | 32 | ``` bash 33 | # install dependencies 34 | npm install 35 | 36 | # serve with hot reload at localhost:8080 37 | npm run dev 38 | 39 | # build for production with minification 40 | npm run build 41 | 42 | # build for production and view the bundle analyzer report 43 | npm run build --report 44 | ``` 45 | ## About Firebase Configuration 46 | This project requires a valid Firebase configuration to function properly, please replace config in `/src/firebase/index.js` with your Firebase config: 47 | ``` js 48 | // Initialize firebase 49 | // Replace following config with your Firebase config 50 | var config = { 51 | apiKey: 'your firebase api key', 52 | authDomain: 'your firebase auth domain', 53 | databaseURL: 'your firebase database url', 54 | projectId: 'your firebase project id', 55 | storageBucket: 'your firebase storage bucket', 56 | messagingSenderId: 'your firebase message sender id' 57 | } 58 | ``` 59 | ## About JSON Editor 60 | [JSON Editor](https://github.com/tangram-js/json-editor) is successor of JSON Schema Editor, which is a schema-aware editor for JSON document including JSON schema. 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. They share user accounts and user schema repository, so user could use one account to login both editors and access schemas. 61 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | console.log(chalk.cyan(' Build complete.\n')) 30 | console.log(chalk.yellow( 31 | ' Tip: built files are meant to be served over an HTTP server.\n' + 32 | ' Opening index.html over file:// won\'t work.\n' 33 | )) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | var shell = require('shelljs') 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | ] 16 | 17 | if (shell.which('npm')) { 18 | versionRequirements.push({ 19 | name: 'npm', 20 | currentVersion: exec('npm --version'), 21 | versionRequirement: packageConfig.engines.npm 22 | }) 23 | } 24 | 25 | module.exports = function () { 26 | var warnings = [] 27 | for (var i = 0; i < versionRequirements.length; i++) { 28 | var mod = versionRequirements[i] 29 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 30 | warnings.push(mod.name + ': ' + 31 | chalk.red(mod.currentVersion) + ' should be ' + 32 | chalk.green(mod.versionRequirement) 33 | ) 34 | } 35 | } 36 | 37 | if (warnings.length) { 38 | console.log('') 39 | console.log(chalk.yellow('To use this template, you must update following to modules:')) 40 | console.log() 41 | for (var i = 0; i < warnings.length; i++) { 42 | var warning = warnings[i] 43 | console.log(' ' + warning) 44 | } 45 | console.log() 46 | process.exit(1) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = require('./webpack.dev.conf') 14 | 15 | // default port where dev server listens for incoming traffic 16 | var port = process.env.PORT || config.dev.port 17 | // automatically open browser, if not set will be false 18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 19 | // Define HTTP proxies to your custom API backend 20 | // https://github.com/chimurai/http-proxy-middleware 21 | var proxyTable = config.dev.proxyTable 22 | 23 | var app = express() 24 | var compiler = webpack(webpackConfig) 25 | 26 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 27 | publicPath: webpackConfig.output.publicPath, 28 | quiet: true 29 | }) 30 | 31 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 32 | log: () => {} 33 | }) 34 | // force page reload when html-webpack-plugin template changes 35 | compiler.plugin('compilation', function (compilation) { 36 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 37 | hotMiddleware.publish({ action: 'reload' }) 38 | cb() 39 | }) 40 | }) 41 | 42 | // proxy api requests 43 | Object.keys(proxyTable).forEach(function (context) { 44 | var options = proxyTable[context] 45 | if (typeof options === 'string') { 46 | options = { target: options } 47 | } 48 | app.use(proxyMiddleware(options.filter || context, options)) 49 | }) 50 | 51 | // handle fallback for HTML5 history API 52 | app.use(require('connect-history-api-fallback')()) 53 | 54 | // serve webpack bundle output 55 | app.use(devMiddleware) 56 | 57 | // enable hot-reload and state-preserving 58 | // compilation error display 59 | app.use(hotMiddleware) 60 | 61 | // serve pure static assets 62 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 63 | app.use(staticPath, express.static('./static')) 64 | 65 | var uri = 'http://localhost:' + port 66 | 67 | var _resolve 68 | var readyPromise = new Promise(resolve => { 69 | _resolve = resolve 70 | }) 71 | 72 | console.log('> Starting dev server...') 73 | devMiddleware.waitUntilValid(() => { 74 | console.log('> Listening at ' + uri + '\n') 75 | // when env is testing, don't need open it 76 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 77 | opn(uri) 78 | } 79 | _resolve() 80 | }) 81 | 82 | var server = app.listen(port) 83 | 84 | module.exports = { 85 | ready: readyPromise, 86 | close: () => { 87 | server.close() 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | vendors: [ 13 | 'webpack-material-design-icons' 14 | ], 15 | app: './src/main.js' 16 | }, 17 | output: { 18 | path: config.build.assetsRoot, 19 | filename: '[name].js', 20 | publicPath: process.env.NODE_ENV === 'production' 21 | ? config.build.assetsPublicPath 22 | : config.dev.assetsPublicPath 23 | }, 24 | resolve: { 25 | extensions: ['.js', '.vue', '.json'], 26 | alias: { 27 | 'vue$': 'vue/dist/vue.esm.js', 28 | '@': resolve('src') 29 | } 30 | }, 31 | module: { 32 | loaders: [ 33 | { test: /\.(jpe?g|png|gif|svg|eot|woff|ttf|svg|woff2)$/, loader: "file?name=[name].[ext]" } 34 | ], 35 | rules: [ 36 | { 37 | test: /\.(js|vue)$/, 38 | loader: 'eslint-loader', 39 | enforce: 'pre', 40 | include: [resolve('src'), resolve('test')], 41 | options: { 42 | formatter: require('eslint-friendly-formatter') 43 | } 44 | }, 45 | { 46 | test: /\.vue$/, 47 | loader: 'vue-loader', 48 | options: vueLoaderConfig 49 | }, 50 | { 51 | test: /\.js$/, 52 | loader: 'babel-loader', 53 | include: [resolve('src'), resolve('test')] 54 | }, 55 | { 56 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 57 | loader: 'url-loader', 58 | options: { 59 | limit: 10000, 60 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 61 | } 62 | }, 63 | { 64 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 65 | loader: 'url-loader', 66 | options: { 67 | limit: 10000, 68 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 69 | } 70 | } 71 | ] 72 | }, 73 | node: { 74 | fs: 'empty' 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | favicon: 'favicon.ico', 32 | inject: true 33 | }), 34 | new FriendlyErrorsPlugin() 35 | ] 36 | }) 37 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = config.build.env 13 | 14 | var webpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ 17 | sourceMap: config.build.productionSourceMap, 18 | extract: true 19 | }) 20 | }, 21 | devtool: config.build.productionSourceMap ? '#source-map' : false, 22 | output: { 23 | path: config.build.assetsRoot, 24 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 26 | }, 27 | plugins: [ 28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 29 | new webpack.DefinePlugin({ 30 | 'process.env': env 31 | }), 32 | new webpack.optimize.UglifyJsPlugin({ 33 | compress: { 34 | warnings: false 35 | }, 36 | sourceMap: true 37 | }), 38 | // extract css into its own file 39 | new ExtractTextPlugin({ 40 | filename: utils.assetsPath('css/[name].[contenthash].css') 41 | }), 42 | // Compress extracted CSS. We are using this plugin so that possible 43 | // duplicated CSS from different components can be deduped. 44 | new OptimizeCSSPlugin({ 45 | cssProcessorOptions: { 46 | safe: true 47 | } 48 | }), 49 | // generate dist index.html with correct asset hash for caching. 50 | // you can customize output by editing /index.html 51 | // see https://github.com/ampedandwired/html-webpack-plugin 52 | new HtmlWebpackPlugin({ 53 | filename: config.build.index, 54 | template: 'index.html', 55 | favicon: 'favicon.ico', 56 | inject: true, 57 | minify: { 58 | removeComments: true, 59 | collapseWhitespace: true, 60 | removeAttributeQuotes: true 61 | // more options: 62 | // https://github.com/kangax/html-minifier#options-quick-reference 63 | }, 64 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 65 | chunksSortMode: 'dependency' 66 | }), 67 | // split vendor js into its own file 68 | new webpack.optimize.CommonsChunkPlugin({ 69 | name: 'vendor', 70 | minChunks: function (module, count) { 71 | // any required modules inside node_modules are extracted to vendor 72 | return ( 73 | module.resource && 74 | /\.js$/.test(module.resource) && 75 | module.resource.indexOf( 76 | path.join(__dirname, '../node_modules') 77 | ) === 0 78 | ) 79 | } 80 | }), 81 | // extract webpack runtime and module manifest to its own file in order to 82 | // prevent vendor hash from being updated whenever app bundle is updated 83 | new webpack.optimize.CommonsChunkPlugin({ 84 | name: 'manifest', 85 | chunks: ['vendor'] 86 | }), 87 | // copy custom static assets 88 | new CopyWebpackPlugin([ 89 | { 90 | from: path.resolve(__dirname, '../static'), 91 | to: config.build.assetsSubDirectory, 92 | ignore: ['.*'] 93 | } 94 | ]) 95 | ] 96 | }) 97 | 98 | if (config.build.productionGzip) { 99 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 100 | 101 | webpackConfig.plugins.push( 102 | new CompressionWebpackPlugin({ 103 | asset: '[path].gz[query]', 104 | algorithm: 'gzip', 105 | test: new RegExp( 106 | '\\.(' + 107 | config.build.productionGzipExtensions.join('|') + 108 | ')$' 109 | ), 110 | threshold: 10240, 111 | minRatio: 0.8 112 | }) 113 | ) 114 | } 115 | 116 | if (config.build.bundleAnalyzerReport) { 117 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 118 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 119 | } 120 | 121 | module.exports = webpackConfig 122 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/favicon.ico -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | json-schema-editor 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "json-schema-editor", 3 | "version": "1.1.0", 4 | "description": "An intuitive editor for json schema which provides a tree view to present structure of schema and a property inspector to edit the properties of schema element. Develop with Vue 2.", 5 | "author": "James Huang ", 6 | "private": true, 7 | "scripts": { 8 | "dev": "node build/dev-server.js", 9 | "start": "node build/dev-server.js", 10 | "build": "node build/build.js", 11 | "lint": "eslint --ext .js,.vue src" 12 | }, 13 | "dependencies": { 14 | "ajv": "^4.11.3", 15 | "firebase": "^3.8.0", 16 | "json-schema-ref-parser": "^3.1.2", 17 | "material-icons": "^0.1.0", 18 | "vue": "^2.2.6", 19 | "vue-material": "^0.7.1", 20 | "vue-router": "^2.3.1" 21 | }, 22 | "devDependencies": { 23 | "autoprefixer": "^6.7.2", 24 | "babel-core": "^6.22.1", 25 | "babel-eslint": "^7.1.1", 26 | "babel-loader": "^6.2.10", 27 | "babel-plugin-transform-runtime": "^6.22.0", 28 | "babel-preset-env": "^1.3.2", 29 | "babel-preset-stage-2": "^6.22.0", 30 | "babel-register": "^6.22.0", 31 | "chalk": "^1.1.3", 32 | "connect-history-api-fallback": "^1.3.0", 33 | "copy-webpack-plugin": "^4.0.1", 34 | "css-loader": "^0.28.0", 35 | "eslint": "^4.19.1", 36 | "eslint-config-standard": "^6.2.1", 37 | "eslint-friendly-formatter": "^2.0.7", 38 | "eslint-loader": "^1.7.1", 39 | "eslint-plugin-html": "^2.0.0", 40 | "eslint-plugin-promise": "^3.4.0", 41 | "eslint-plugin-standard": "^2.0.1", 42 | "eventsource-polyfill": "^0.9.6", 43 | "express": "^4.14.1", 44 | "extract-text-webpack-plugin": "^2.0.0", 45 | "file-loader": "^0.11.1", 46 | "friendly-errors-webpack-plugin": "^1.1.3", 47 | "html-webpack-plugin": "^2.28.0", 48 | "http-proxy-middleware": "^0.17.3", 49 | "opn": "^4.0.2", 50 | "optimize-css-assets-webpack-plugin": "^1.3.0", 51 | "ora": "^1.2.0", 52 | "rimraf": "^2.6.0", 53 | "semver": "^5.3.0", 54 | "shelljs": "^0.7.6", 55 | "url-loader": "^0.5.8", 56 | "vue-loader": "^11.3.4", 57 | "vue-style-loader": "^2.0.5", 58 | "vue-template-compiler": "^2.2.6", 59 | "webpack": "^2.3.3", 60 | "webpack-bundle-analyzer": "^3.6.0", 61 | "webpack-dev-middleware": "^1.10.0", 62 | "webpack-hot-middleware": "^2.18.0", 63 | "webpack-material-design-icons": "^0.1.0", 64 | "webpack-merge": "^4.1.0" 65 | }, 66 | "engines": { 67 | "node": ">= 4.0.0", 68 | "npm": ">= 3.0.0" 69 | }, 70 | "browserslist": [ 71 | "> 1%", 72 | "last 2 versions", 73 | "not ie <= 8" 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 106 | 107 | 121 | -------------------------------------------------------------------------------- /src/components/ContextMenu.vue: -------------------------------------------------------------------------------- 1 | 36 | 129 | 166 | -------------------------------------------------------------------------------- /src/components/ContextMenuItem.vue: -------------------------------------------------------------------------------- 1 | 21 | 71 | 206 | -------------------------------------------------------------------------------- /src/components/SplitPanel.vue: -------------------------------------------------------------------------------- 1 | 18 | 211 | 239 | -------------------------------------------------------------------------------- /src/components/Toolbox.vue: -------------------------------------------------------------------------------- 1 | 12 | 118 | 125 | -------------------------------------------------------------------------------- /src/components/ToolboxComponent.vue: -------------------------------------------------------------------------------- 1 | 18 | 91 | 114 | -------------------------------------------------------------------------------- /src/components/Tree.vue: -------------------------------------------------------------------------------- 1 | 11 | 86 | 95 | -------------------------------------------------------------------------------- /src/components/TreeNode.vue: -------------------------------------------------------------------------------- 1 | 41 | 174 | 214 | -------------------------------------------------------------------------------- /src/components/account/ChangePassword.vue: -------------------------------------------------------------------------------- 1 | 36 | 75 | 85 | -------------------------------------------------------------------------------- /src/components/account/SignIn.vue: -------------------------------------------------------------------------------- 1 | 33 | 73 | 82 | -------------------------------------------------------------------------------- /src/components/account/SignUp.vue: -------------------------------------------------------------------------------- 1 | 36 | 84 | 94 | -------------------------------------------------------------------------------- /src/components/account/VerifyEmail.vue: -------------------------------------------------------------------------------- 1 | 33 | 72 | 82 | -------------------------------------------------------------------------------- /src/components/context-menu-items/ButtonMenuItem.vue: -------------------------------------------------------------------------------- 1 | 7 | 38 | 43 | -------------------------------------------------------------------------------- /src/components/context-menu-items/CheckBoxMenuItem.vue: -------------------------------------------------------------------------------- 1 | 8 | 49 | 54 | -------------------------------------------------------------------------------- /src/components/context-menu-items/DividerMenuItem.vue: -------------------------------------------------------------------------------- 1 | 3 | 17 | 19 | -------------------------------------------------------------------------------- /src/components/context-menu-items/HeaderMenuItem.vue: -------------------------------------------------------------------------------- 1 | 7 | 21 | 26 | -------------------------------------------------------------------------------- /src/components/context-menu-items/SelectMenuItem.vue: -------------------------------------------------------------------------------- 1 | 10 | 66 | 71 | -------------------------------------------------------------------------------- /src/components/context-menu-items/TextInputMenuItem.vue: -------------------------------------------------------------------------------- 1 | 8 | 50 | 55 | -------------------------------------------------------------------------------- /src/components/context-menu-items/index.js: -------------------------------------------------------------------------------- 1 | import ButtonMenuItem from './ButtonMenuItem.vue' 2 | import HeaderMenuItem from './HeaderMenuItem.vue' 3 | import DividerMenuItem from './DividerMenuItem.vue' 4 | import CheckBoxMenuItem from './CheckBoxMenuItem.vue' 5 | import TextInputMenuItem from './TextInputMenuItem.vue' 6 | import SelectMenuItem from './SelectMenuItem.vue' 7 | 8 | export default { 9 | ButtonMenuItem: ButtonMenuItem, 10 | HeaderMenuItem: HeaderMenuItem, 11 | DividerMenuItem: DividerMenuItem, 12 | CheckBoxMenuItem: CheckBoxMenuItem, 13 | TextInputMenuItem: TextInputMenuItem, 14 | SelectMenuItem: SelectMenuItem 15 | } 16 | -------------------------------------------------------------------------------- /src/components/icon-module/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/Thumbs.db -------------------------------------------------------------------------------- /src/components/icon-module/array16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/array16.png -------------------------------------------------------------------------------- /src/components/icon-module/array24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/array24.png -------------------------------------------------------------------------------- /src/components/icon-module/bookmark16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/bookmark16.png -------------------------------------------------------------------------------- /src/components/icon-module/bookmark24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/bookmark24.png -------------------------------------------------------------------------------- /src/components/icon-module/dependencies16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/dependencies16.png -------------------------------------------------------------------------------- /src/components/icon-module/dependencies24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/dependencies24.png -------------------------------------------------------------------------------- /src/components/icon-module/dependency16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/dependency16.png -------------------------------------------------------------------------------- /src/components/icon-module/dependency24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/dependency24.png -------------------------------------------------------------------------------- /src/components/icon-module/enum16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/enum16.png -------------------------------------------------------------------------------- /src/components/icon-module/enum24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/enum24.png -------------------------------------------------------------------------------- /src/components/icon-module/index.js: -------------------------------------------------------------------------------- 1 | export default { 2 | jsonSchema: require('./json_schema24.png'), 3 | type: require('./type24.png'), 4 | object: require('./object24.png'), 5 | array: require('./array24.png'), 6 | properties: require('./properties24.png'), 7 | items: require('./items24.png'), 8 | enum: require('./enum24.png'), 9 | required: require('./required24.png'), 10 | options: require('./options24.png'), 11 | not: require('./not24.png'), 12 | ref: require('./ref24.png'), 13 | remark: require('./remark24.png'), 14 | dependencies: require('./dependencies24.png'), 15 | dependency: require('./dependency24.png'), 16 | definitions: require('./object24.png'), 17 | icon (name) { 18 | if (name) { 19 | if (this[name]) return this[name] 20 | } 21 | return null 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/components/icon-module/items-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/items-16.png -------------------------------------------------------------------------------- /src/components/icon-module/items-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/items-24.png -------------------------------------------------------------------------------- /src/components/icon-module/items16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/items16.png -------------------------------------------------------------------------------- /src/components/icon-module/items24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/items24.png -------------------------------------------------------------------------------- /src/components/icon-module/json_schema16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/json_schema16.png -------------------------------------------------------------------------------- /src/components/icon-module/json_schema24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/json_schema24.png -------------------------------------------------------------------------------- /src/components/icon-module/not16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/not16.png -------------------------------------------------------------------------------- /src/components/icon-module/not24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/not24.png -------------------------------------------------------------------------------- /src/components/icon-module/object16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/object16.png -------------------------------------------------------------------------------- /src/components/icon-module/object24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/object24.png -------------------------------------------------------------------------------- /src/components/icon-module/options16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/options16.png -------------------------------------------------------------------------------- /src/components/icon-module/options24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/options24.png -------------------------------------------------------------------------------- /src/components/icon-module/pen16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/pen16.png -------------------------------------------------------------------------------- /src/components/icon-module/pen24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/pen24.png -------------------------------------------------------------------------------- /src/components/icon-module/properties16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/properties16.png -------------------------------------------------------------------------------- /src/components/icon-module/properties24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/properties24.png -------------------------------------------------------------------------------- /src/components/icon-module/ref16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/ref16.png -------------------------------------------------------------------------------- /src/components/icon-module/ref24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/ref24.png -------------------------------------------------------------------------------- /src/components/icon-module/remark16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/remark16.png -------------------------------------------------------------------------------- /src/components/icon-module/remark24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/remark24.png -------------------------------------------------------------------------------- /src/components/icon-module/required16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/required16.png -------------------------------------------------------------------------------- /src/components/icon-module/required24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/required24.png -------------------------------------------------------------------------------- /src/components/icon-module/type16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/type16.png -------------------------------------------------------------------------------- /src/components/icon-module/type24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/src/components/icon-module/type24.png -------------------------------------------------------------------------------- /src/components/json-schema-editor/PropertyInspector.vue: -------------------------------------------------------------------------------- 1 | 4 | 32 | 34 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/componentData.js: -------------------------------------------------------------------------------- 1 | import Components from './components' 2 | 3 | export var componentData = [ 4 | new Components.StringComponent('Type string'), 5 | new Components.IntegerComponent('Type integer'), 6 | new Components.NumberComponent('Type number'), 7 | new Components.BooleanComponent('Type boolean'), 8 | new Components.ObjectComponent('Type object'), 9 | new Components.ArrayComponent('Type array'), 10 | new Components.NullComponent('Type null'), 11 | new Components.PropertiesComponent('List properties of object'), 12 | new Components.RequiredComponent('List required properties of object'), 13 | new Components.DependenciesComponent('List dependencies between properties'), 14 | new Components.DependencyItemComponent('List of properties which specific property depend on'), 15 | new Components.ItemsComponent('List type of each item'), 16 | new Components.EnumComponent('List of valid values'), 17 | new Components.AllOfComponent('Data must be valid against all of the given subschemas'), 18 | new Components.AnyOfComponent('Data must be valid against any of the given subschemas'), 19 | new Components.OneOfComponent('Data must be valid against exactly one of the given subschemas'), 20 | new Components.NotComponent('Data must not be valid against all of the given subschemas'), 21 | new Components.RefComponent('Reference to external schema'), 22 | new Components.DefinitionsComponent('Definitions of reusable schema') 23 | ] 24 | 25 | export default componentData 26 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/allOf.js: -------------------------------------------------------------------------------- 1 | export class AllOfComponent { 2 | constructor (tooltip) { 3 | this.type = 'allOf' 4 | this.tooltip = tooltip 5 | this.icon = 'options' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | } 37 | } 38 | } 39 | } 40 | 41 | export default AllOfComponent 42 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/anyOf.js: -------------------------------------------------------------------------------- 1 | export class AnyOfComponent { 2 | constructor (tooltip) { 3 | this.type = 'anyOf' 4 | this.tooltip = tooltip 5 | this.icon = 'options' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | } 37 | } 38 | } 39 | } 40 | 41 | export default AnyOfComponent 42 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/array.js: -------------------------------------------------------------------------------- 1 | export class ArrayComponent { 2 | constructor (tooltip) { 3 | this.type = 'array' 4 | this.tooltip = tooltip 5 | this.icon = 'type' 6 | this.value = { 7 | type: 'array' 8 | } 9 | // missing patternProperties 10 | this.valueSchema = { 11 | type: 'object', 12 | properties: { 13 | additionalItems: { 14 | type: 'boolean' 15 | }, 16 | minItems: { 17 | type: 'integer', 18 | minimum: 0 19 | }, 20 | maxItems: { 21 | type: 'integer', 22 | minimum: 0 23 | }, 24 | uniqueItems: { 25 | type: 'boolean' 26 | } 27 | } 28 | } 29 | this.children = [] 30 | this.editable = false 31 | this.funcs = { 32 | accept (dest, node) { 33 | // could only has one child 34 | if (dest.children.length > 0) return false 35 | // list acceptable types 36 | switch (node.type) { 37 | case 'jsonSchema': 38 | case 'string': 39 | case 'integer': 40 | case 'number': 41 | case 'boolean': 42 | case 'object': 43 | case 'array': 44 | case 'null': 45 | case 'enum': 46 | case 'allOf': 47 | case 'anyOf': 48 | case 'oneOf': 49 | case 'not': 50 | case 'ref': 51 | case 'items': 52 | return true 53 | default: 54 | return false 55 | } 56 | }, 57 | acceptList (dest) { 58 | return (dest.children.length === 0) 59 | ? ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 60 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref', 'items'] : [] 61 | }, 62 | beforeAppend (dest, node) { 63 | // set name to 'items' 64 | if (node.type !== 'items') node.name = 'items' 65 | } 66 | } 67 | } 68 | } 69 | 70 | export default ArrayComponent 71 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/boolean.js: -------------------------------------------------------------------------------- 1 | export class BooleanComponent { 2 | constructor (tooltip) { 3 | this.type = 'boolean' 4 | this.tooltip = tooltip 5 | this.icon = 'type' 6 | this.value = { 7 | type: 'boolean' 8 | } 9 | this.valueSchema = { 10 | type: 'object' 11 | } 12 | this.editable = false 13 | this.funcs = { 14 | acceptList () { 15 | return [] 16 | } 17 | } 18 | } 19 | } 20 | 21 | export default BooleanComponent 22 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/definitions.js: -------------------------------------------------------------------------------- 1 | export class DefinitionsComponent { 2 | constructor (tooltip) { 3 | this.type = 'definitions' 4 | this.tooltip = tooltip 5 | this.icon = 'definitions' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | }, 37 | beforeAppend (dest, node) { 38 | node.name = 'definition' 39 | node.editable = true 40 | } 41 | } 42 | } 43 | } 44 | 45 | export default DefinitionsComponent 46 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/dependencies.js: -------------------------------------------------------------------------------- 1 | export class DependenciesComponent { 2 | constructor (tooltip) { 3 | this.type = 'dependencies' 4 | this.tooltip = tooltip 5 | this.icon = 'dependencies' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | return (node.type === 'dependencyItem') 13 | }, 14 | acceptList () { 15 | return ['dependencyItem'] 16 | }, 17 | beforeAppend (dest, node) { 18 | node.name = '' 19 | } 20 | } 21 | } 22 | } 23 | 24 | export default DependenciesComponent 25 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/dependencyItem.js: -------------------------------------------------------------------------------- 1 | export class DependencyItemComponent { 2 | constructor (tooltip) { 3 | this.type = 'dependencyItem' 4 | this.tooltip = tooltip 5 | this.icon = 'dependency' 6 | this.value = [] 7 | this.valueSchema = { 8 | type: 'array', 9 | items: { 10 | type: 'string', 11 | enum: [] 12 | }, 13 | additionalItems: false, 14 | uniqueItems: true 15 | } 16 | this.editable = false 17 | this.funcs = { 18 | acceptList () { 19 | return [] 20 | } 21 | } 22 | } 23 | } 24 | 25 | export default DependencyItemComponent 26 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/enum.js: -------------------------------------------------------------------------------- 1 | export class EnumComponent { 2 | constructor (tooltip) { 3 | this.type = 'enum' 4 | this.tooltip = tooltip 5 | this.icon = 'enum' 6 | this.value = { 7 | enum: [] 8 | } 9 | this.valueSchema = { 10 | type: 'object', 11 | properties: { 12 | enum: { 13 | type: 'array' 14 | } 15 | }, 16 | required: ['enum'], 17 | additionalProperties: false 18 | } 19 | this.editable = false 20 | this.funcs = { 21 | acceptList () { 22 | return [] 23 | } 24 | } 25 | } 26 | } 27 | 28 | export default EnumComponent 29 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/index.js: -------------------------------------------------------------------------------- 1 | import AllOfComponent from './allOf' 2 | import AnyOfComponent from './anyOf' 3 | import ArrayComponent from './array' 4 | import BooleanComponent from './boolean' 5 | import DefinitionsComponent from './definitions' 6 | import DependenciesComponent from './dependencies' 7 | import DependencyItemComponent from './dependencyItem' 8 | import EnumComponent from './enum' 9 | import IntegerComponent from './integer' 10 | import ItemsComponent from './items' 11 | import JsonSchemaComponent from './jsonSchema' 12 | import NotComponent from './not' 13 | import NullComponent from './null' 14 | import NumberComponent from './number' 15 | import ObjectComponent from './object' 16 | import OneOfComponent from './oneOf' 17 | import PropertiesComponent from './properties' 18 | import RefComponent from './ref' 19 | import RequiredComponent from './required' 20 | import StringComponent from './string' 21 | 22 | export default { 23 | AllOfComponent, 24 | AnyOfComponent, 25 | ArrayComponent, 26 | BooleanComponent, 27 | DefinitionsComponent, 28 | DependenciesComponent, 29 | DependencyItemComponent, 30 | EnumComponent, 31 | IntegerComponent, 32 | ItemsComponent, 33 | JsonSchemaComponent, 34 | NotComponent, 35 | NullComponent, 36 | NumberComponent, 37 | ObjectComponent, 38 | OneOfComponent, 39 | PropertiesComponent, 40 | RefComponent, 41 | RequiredComponent, 42 | StringComponent 43 | } 44 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/integer.js: -------------------------------------------------------------------------------- 1 | export class IntegerComponent { 2 | constructor (tooltip) { 3 | this.type = 'integer' 4 | this.tooltip = tooltip 5 | this.icon = 'type' 6 | this.value = { 7 | type: 'integer' 8 | } 9 | this.valueSchema = { 10 | type: 'object', 11 | properties: { 12 | multipleOf: { 13 | type: 'integer', 14 | minimum: 1 15 | }, 16 | minimum: { 17 | type: 'integer' 18 | }, 19 | excludeMinimum: { 20 | type: 'integer' 21 | }, 22 | maximum: { 23 | type: 'integer' 24 | }, 25 | excludeMaximum: { 26 | type: 'integer' 27 | } 28 | } 29 | } 30 | this.children = [] 31 | this.editable = false 32 | this.funcs = { 33 | accept (dest, node) { 34 | // only allow enum 35 | if (node.type === 'enum') { 36 | return true 37 | } else { 38 | return false 39 | } 40 | }, 41 | acceptList () { 42 | return ['enum'] 43 | } 44 | /* 45 | beforeAppend (dest, node) { 46 | if (node.type === 'enum') { 47 | // set enum's value schema 48 | node.valueSchema.properties.enum.items = dest.value 49 | node.valueSchema.properties.enum.additionalItems = false 50 | } 51 | } 52 | */ 53 | } 54 | } 55 | } 56 | 57 | export default IntegerComponent 58 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/items.js: -------------------------------------------------------------------------------- 1 | export class ItemsComponent { 2 | constructor (tooltip) { 3 | this.type = 'items' 4 | this.tooltip = tooltip 5 | this.icon = 'items' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | } 37 | } 38 | } 39 | } 40 | 41 | export default ItemsComponent 42 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/jsonSchema.js: -------------------------------------------------------------------------------- 1 | export class JsonSchemaComponent { 2 | constructor (tooltip) { 3 | this.type = 'jsonSchema' 4 | this.name = 'schema' 5 | this.tooltip = tooltip 6 | this.icon = 'jsonSchema' 7 | this.value = {} 8 | this.valueSchema = { 9 | type: 'object', 10 | properties: { 11 | description: { 12 | type: 'string', 13 | format: 'textarea' 14 | } 15 | } 16 | } 17 | this.children = [] 18 | this.editable = true 19 | this.funcs = { 20 | accept (dest, node) { 21 | // could only has one child 22 | if (dest.children.length > 0) { 23 | if (dest.children.length > 1) return false 24 | if ((dest.children[0].type === 'definitions' && node.type === 'definitions') || 25 | (dest.children[0].type !== 'definitions' && node.type !== 'definitions')) return false 26 | } 27 | 28 | // list acceptable types 29 | switch (node.type) { 30 | case 'jsonSchema': 31 | case 'string': 32 | case 'integer': 33 | case 'number': 34 | case 'boolean': 35 | case 'object': 36 | case 'array': 37 | case 'null': 38 | case 'enum': 39 | case 'allOf': 40 | case 'anyOf': 41 | case 'oneOf': 42 | case 'not': 43 | case 'definitions': 44 | return true 45 | default: 46 | return false 47 | } 48 | }, 49 | acceptList (dest) { 50 | if (dest.children.length > 0) { 51 | if (dest.children.length > 1) return [] 52 | if (dest.children[0].type === 'definitions') { 53 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 54 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 55 | } else { 56 | return ['definitions'] 57 | } 58 | } 59 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 60 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref', 'definitions'] 61 | }, 62 | dropped (dest, node) { 63 | // dest.expended = true 64 | } 65 | } 66 | } 67 | } 68 | 69 | export default JsonSchemaComponent 70 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/not.js: -------------------------------------------------------------------------------- 1 | export class NotComponent { 2 | constructor (tooltip) { 3 | this.type = 'not' 4 | this.tooltip = tooltip 5 | this.icon = 'not' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.editable = false 9 | this.children = [] 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | } 37 | } 38 | } 39 | } 40 | 41 | export default NotComponent 42 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/null.js: -------------------------------------------------------------------------------- 1 | export class NullComponent { 2 | constructor (tooltip) { 3 | this.type = 'null' 4 | this.tooltip = tooltip 5 | this.icon = 'type' 6 | this.value = { 7 | type: 'null' 8 | } 9 | this.valueSchema = { 10 | type: 'object' 11 | } 12 | this.editable = false 13 | this.funcs = { 14 | acceptList () { 15 | return [] 16 | } 17 | } 18 | } 19 | } 20 | 21 | export default NullComponent 22 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/number.js: -------------------------------------------------------------------------------- 1 | export class NumberComponent { 2 | constructor (tooltip) { 3 | this.type = 'number' 4 | this.tooltip = tooltip 5 | this.icon = 'type' 6 | this.value = { 7 | type: 'number' 8 | } 9 | this.valueSchema = { 10 | type: 'object', 11 | properties: { 12 | multipleOf: { 13 | type: 'number', 14 | minimum: 0, 15 | excludeMinimum: true 16 | }, 17 | minimum: { 18 | type: 'number' 19 | }, 20 | excludeMinimum: { 21 | type: 'number' 22 | }, 23 | maximum: { 24 | type: 'number' 25 | }, 26 | excludeMaximum: { 27 | type: 'number' 28 | } 29 | } 30 | } 31 | this.children = [] 32 | this.editable = false 33 | this.funcs = { 34 | accept (dest, node) { 35 | // only allow enum 36 | if (node.type === 'enum') { 37 | return true 38 | } else { 39 | return false 40 | } 41 | }, 42 | acceptList () { 43 | return ['enum'] 44 | } 45 | /* 46 | beforeAppend (dest, node) { 47 | if (node.type === 'enum') { 48 | // set enum's value schema 49 | node.valueSchema.properties.enum.items = dest.value 50 | node.valueSchema.properties.enum.additionalItems = false 51 | } 52 | } 53 | */ 54 | } 55 | } 56 | } 57 | 58 | export default NumberComponent 59 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/object.js: -------------------------------------------------------------------------------- 1 | // import convertTreeToSchema from '../convertTreeToSchema' 2 | 3 | function typeExist (children, type) { 4 | let result = false 5 | children.forEach(child => { 6 | if (child.type === type) result = true 7 | }) 8 | return result 9 | } 10 | 11 | export class ObjectComponent { 12 | constructor (tooltip) { 13 | this.type = 'object' 14 | this.tooltip = tooltip 15 | this.icon = 'type' 16 | this.value = { 17 | type: 'object' 18 | } 19 | // missing patternProperties 20 | this.valueSchema = { 21 | type: 'object', 22 | properties: { 23 | additionalProperties: { 24 | type: 'boolean' 25 | }, 26 | minProperties: { 27 | type: 'integer', 28 | minimum: 0 29 | }, 30 | maxProperties: { 31 | type: 'integer', 32 | minimum: 0 33 | } 34 | } 35 | } 36 | this.children = [] 37 | this.editable = false 38 | this.funcs = { 39 | accept (dest, node) { 40 | // children can not have duplicate type 41 | if (typeExist(dest.children, node.type)) return false 42 | // required only allow when properties exist 43 | if (node.type === 'required') { 44 | return typeExist(dest.children, 'properties') 45 | } 46 | // dependencies only allow when properties exist 47 | if (node.type === 'dependencies') { 48 | return typeExist(dest.children, 'properties') 49 | } 50 | // list acceptable types 51 | switch (node.type) { 52 | case 'properties': 53 | case 'required': 54 | case 'dependencies': 55 | case 'enum': 56 | return true 57 | default: 58 | return false 59 | } 60 | }, 61 | acceptList (dest) { 62 | let result = [] 63 | if (!typeExist(dest.children, 'properties')) { 64 | result.push('properties') 65 | } else { 66 | if (!typeExist(dest.children, 'required')) result.push('required') 67 | if (!typeExist(dest.children, 'dependencies')) result.push('dependencies') 68 | } 69 | if (!typeExist(dest.children, 'enum')) result.push('enum') 70 | return result 71 | } 72 | /* 73 | beforeAppend (dest, node) { 74 | if (node.type === 'enum') { 75 | // set enum's value schema 76 | node.valueSchema.properties.enum.items = convertTreeToSchema({ 77 | value: {}, 78 | children: [dest] 79 | }) 80 | node.valueSchema.properties.enum.additionalItems = false 81 | } 82 | } 83 | */ 84 | } 85 | } 86 | } 87 | 88 | export default ObjectComponent 89 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/oneOf.js: -------------------------------------------------------------------------------- 1 | export class OneOfComponent { 2 | constructor (tooltip) { 3 | this.type = 'oneOf' 4 | this.tooltip = tooltip 5 | this.icon = 'options' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | } 37 | } 38 | } 39 | } 40 | 41 | export default OneOfComponent 42 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/properties.js: -------------------------------------------------------------------------------- 1 | export class PropertiesComponent { 2 | constructor (tooltip) { 3 | this.type = 'properties' 4 | this.tooltip = tooltip 5 | this.icon = 'properties' 6 | this.value = undefined 7 | this.valueSchema = undefined 8 | this.children = [] 9 | this.editable = false 10 | this.funcs = { 11 | accept (dest, node) { 12 | // list acceptable types 13 | switch (node.type) { 14 | case 'jsonSchema': 15 | case 'string': 16 | case 'integer': 17 | case 'number': 18 | case 'boolean': 19 | case 'object': 20 | case 'array': 21 | case 'null': 22 | case 'enum': 23 | case 'allOf': 24 | case 'anyOf': 25 | case 'oneOf': 26 | case 'not': 27 | case 'ref': 28 | return true 29 | default: 30 | return false 31 | } 32 | }, 33 | acceptList () { 34 | return ['string', 'integer', 'number', 'boolean', 'object', 'array', 'null', 35 | 'enum', 'allOf', 'anyOf', 'oneOf', 'not', 'ref'] 36 | }, 37 | beforeAppend (dest, node) { 38 | node.name = 'prop' 39 | node.editable = true 40 | } 41 | } 42 | } 43 | } 44 | 45 | export default PropertiesComponent 46 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/ref.js: -------------------------------------------------------------------------------- 1 | export class RefComponent { 2 | constructor (tooltip) { 3 | this.type = 'ref' 4 | this.tooltip = tooltip 5 | this.icon = 'ref' 6 | this.value = { 7 | '$ref': '' 8 | } 9 | this.valueSchema = { 10 | type: 'object', 11 | properties: { 12 | '$ref': { 13 | type: 'string' 14 | } 15 | }, 16 | required: ['$ref'], 17 | additionalProperties: false 18 | } 19 | this.editable = false 20 | this.funcs = { 21 | acceptList () { 22 | return [] 23 | } 24 | } 25 | } 26 | } 27 | 28 | export default RefComponent 29 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/required.js: -------------------------------------------------------------------------------- 1 | export class RequiredComponent { 2 | constructor (tooltip) { 3 | this.type = 'required' 4 | this.tooltip = tooltip 5 | this.icon = 'required' 6 | this.value = [] 7 | this.valueSchema = { 8 | type: 'array', 9 | items: { 10 | type: 'string', 11 | enum: [] 12 | } 13 | } 14 | this.editable = false 15 | this.funcs = { 16 | acceptList () { 17 | return [] 18 | } 19 | } 20 | } 21 | } 22 | 23 | export default RequiredComponent 24 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/components/string.js: -------------------------------------------------------------------------------- 1 | export class StringComponent { 2 | constructor (tooltip) { 3 | this.type = 'string' 4 | this.tooltip = tooltip 5 | this.icon = 'type' 6 | this.value = { 7 | type: 'string' 8 | } 9 | this.valueSchema = { 10 | type: 'object', 11 | properties: { 12 | minLength: { 13 | type: 'integer', 14 | minimum: 0 15 | }, 16 | maxLength: { 17 | type: 'integer', 18 | minimum: 0 19 | }, 20 | pattern: { 21 | type: 'string' 22 | }, 23 | format: { 24 | type: 'string' 25 | } 26 | } 27 | } 28 | this.children = [] 29 | this.editable = false 30 | this.funcs = { 31 | accept (dest, node) { 32 | // only allow enum 33 | if (node.type === 'enum') { 34 | return true 35 | } else { 36 | return false 37 | } 38 | }, 39 | acceptList () { 40 | return ['enum'] 41 | } 42 | /* 43 | beforeAppend (dest, node) { 44 | if (node.type === 'enum') { 45 | // set enum's value schema 46 | node.valueSchema.properties.enum.items = dest.value 47 | node.valueSchema.properties.enum.additionalItems = false 48 | } 49 | } 50 | */ 51 | } 52 | } 53 | } 54 | 55 | export default StringComponent 56 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/convertSchemaToTree.js: -------------------------------------------------------------------------------- 1 | import Components from './components' 2 | 3 | function setNodeValue (node, schema, propertyList) { 4 | propertyList.forEach(property => { 5 | if (schema[property] || schema[property] === 0 || schema[property] === false) node.value[property] = schema[property] 6 | }) 7 | } 8 | 9 | function convertStringToTree (tree, schema) { 10 | let node = new Components.StringComponent() 11 | setNodeValue(node, schema, ['minLength', 'maxLength', 'pattern', 'format']) 12 | if (schema.enum) convertEnumToTree(node, schema.enum) 13 | tree.children.push(node) 14 | } 15 | 16 | function convertIntegerToTree (tree, schema) { 17 | let node = new Components.IntegerComponent() 18 | setNodeValue(node, schema, ['multipleOf', 'minimum', 'exclusiveMinimum', 'maximum', 'exclusiveMaximum']) 19 | if (schema.enum) convertEnumToTree(node, schema.enum) 20 | tree.children.push(node) 21 | } 22 | 23 | function convertNumberToTree (tree, schema) { 24 | let node = new Components.NumberComponent() 25 | setNodeValue(node, schema, ['multipleOf', 'minimum', 'exclusiveMinimum', 'maximum', 'exclusiveMaximum']) 26 | if (schema.enum) convertEnumToTree(node, schema.enum) 27 | tree.children.push(node) 28 | } 29 | 30 | function convertBooleanToTree (tree, schema) { 31 | let node = new Components.BooleanComponent() 32 | tree.children.push(node) 33 | } 34 | 35 | function convertNullToTree (tree, schema) { 36 | let node = new Components.NullComponent() 37 | tree.children.push(node) 38 | } 39 | 40 | function convertPropertiesToTree (tree, schema) { 41 | let node = new Components.PropertiesComponent() 42 | Object.keys(schema).forEach(p => { 43 | convertSubSchemaToTree(node, schema[p]) 44 | node.children[node.children.length - 1].name = p 45 | node.children[node.children.length - 1].editable = true 46 | }) 47 | tree.children.push(node) 48 | } 49 | 50 | function convertRequiredToTree (tree, schema) { 51 | let node = new Components.RequiredComponent() 52 | node.value = schema 53 | tree.children.push(node) 54 | } 55 | 56 | function convertDependencyItemToTree (tree, schema) { 57 | let node = new Components.DependencyItemComponent() 58 | node.value = schema 59 | tree.children.push(node) 60 | } 61 | 62 | function convertDependenciesToTree (tree, schema) { 63 | let node = new Components.DependenciesComponent() 64 | Object.keys(schema).forEach(p => { 65 | convertDependencyItemToTree(node, schema[p]) 66 | node.children[node.children.length - 1].name = p 67 | }) 68 | tree.children.push(node) 69 | } 70 | 71 | function convertObjectToTree (tree, schema) { 72 | let node = new Components.ObjectComponent() 73 | setNodeValue(node, schema, ['additionalProperties', 'minProperties', 'maxProperties']) 74 | if (schema.properties) convertPropertiesToTree(node, schema.properties) 75 | if (schema.required) convertRequiredToTree(node, schema.required) 76 | if (schema.dependencies) convertDependenciesToTree(node, schema.dependencies) 77 | if (schema.enum) convertEnumToTree(node, schema.enum) 78 | tree.children.push(node) 79 | } 80 | 81 | function convertItemsToTree (tree, schema) { 82 | if (Array.isArray(schema)) { 83 | let node = new Components.ItemsComponent() 84 | schema.forEach(s => { 85 | convertSubSchemaToTree(node, s) 86 | }) 87 | tree.children.push(node) 88 | } else { 89 | convertSubSchemaToTree(tree, schema) 90 | tree.children[tree.children.length - 1].name = 'items' 91 | } 92 | } 93 | 94 | function convertArrayToTree (tree, schema) { 95 | let node = new Components.ArrayComponent() 96 | setNodeValue(node, schema, ['additionalItems', 'minItems', 'maxItems', 'uniqueItems']) 97 | if (schema.items) convertItemsToTree(node, schema.items) 98 | tree.children.push(node) 99 | } 100 | 101 | function convertEnumToTree (tree, schema) { 102 | let node = new Components.EnumComponent() 103 | node.value = { 104 | enum: schema 105 | } 106 | tree.children.push(node) 107 | } 108 | 109 | function convertAllOfToTree (tree, schema) { 110 | let node = new Components.AllOfComponent() 111 | schema.forEach(s => { 112 | convertSubSchemaToTree(node, s) 113 | }) 114 | tree.children.push(node) 115 | } 116 | 117 | function convertAnyOfToTree (tree, schema) { 118 | let node = new Components.AnyOfComponent() 119 | schema.forEach(s => { 120 | convertSubSchemaToTree(node, s) 121 | }) 122 | tree.children.push(node) 123 | } 124 | 125 | function convertOneOfToTree (tree, schema) { 126 | let node = new Components.OneOfComponent() 127 | schema.forEach(s => { 128 | convertSubSchemaToTree(node, s) 129 | }) 130 | tree.children.push(node) 131 | } 132 | 133 | function convertNotToTree (tree, schema) { 134 | let node = new Components.NotComponent() 135 | schema.forEach(s => { 136 | convertSubSchemaToTree(node, s) 137 | }) 138 | tree.children.push(node) 139 | } 140 | 141 | function convertRefToTree (tree, schema) { 142 | let node = new Components.RefComponent() 143 | node.value['$ref'] = schema 144 | tree.children.push(node) 145 | } 146 | 147 | function convertDefinitionsToTree (tree, schema) { 148 | let node = new Components.DefinitionsComponent() 149 | Object.keys(schema).forEach(p => { 150 | convertSubSchemaToTree(node, schema[p]) 151 | node.children[node.children.length - 1].name = p 152 | node.children[node.children.length - 1].editable = true 153 | }) 154 | tree.children.push(node) 155 | } 156 | 157 | function convertSubSchemaToTree (tree, schema) { 158 | if (schema.type) { 159 | switch (schema.type) { 160 | case 'string': 161 | return convertStringToTree(tree, schema) 162 | case 'integer': 163 | return convertIntegerToTree(tree, schema) 164 | case 'number': 165 | return convertNumberToTree(tree, schema) 166 | case 'boolean': 167 | return convertBooleanToTree(tree, schema) 168 | case 'null': 169 | return convertNullToTree(tree, schema) 170 | case 'object': 171 | return convertObjectToTree(tree, schema) 172 | case 'array': 173 | return convertArrayToTree(tree, schema) 174 | } 175 | } 176 | if (schema.enum) return convertEnumToTree(tree, schema.enum) 177 | if (schema.allOf) return convertAllOfToTree(tree, schema.allOf) 178 | if (schema.anyOf) return convertAnyOfToTree(tree, schema.anyOf) 179 | if (schema.oneOf) return convertOneOfToTree(tree, schema.oneOf) 180 | if (schema.not) return convertNotToTree(tree, schema.not) 181 | if (schema['$ref']) return convertRefToTree(tree, schema['$ref']) 182 | if (schema.definitions) convertDefinitionsToTree(tree, schema.definitions) 183 | } 184 | 185 | export function convertSchemaToTree (schema, name) { 186 | let tree = new Components.JsonSchemaComponent() 187 | tree.name = schema.title || name 188 | tree.tooltip = schema.description 189 | tree.value.description = schema.description 190 | convertSubSchemaToTree(tree, schema) 191 | return tree 192 | } 193 | 194 | export default convertSchemaToTree 195 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/convertTreeToSchema.js: -------------------------------------------------------------------------------- 1 | function clone (source) { 2 | return JSON.parse(JSON.stringify(source)) 3 | } 4 | 5 | function convertTypeToSchema (node) { 6 | let schema = clone(node.value) 7 | if (node.children && node.children.length > 0) { 8 | schema.enum = clone(node.children[0].value) 9 | } 10 | return schema 11 | } 12 | 13 | function convertObjectToSchema (node) { 14 | let schema = clone(node.value) 15 | node.children.forEach(child => { 16 | switch (child.type) { 17 | case 'properties': 18 | schema.properties = convertPropertiesToSchema(child) 19 | break 20 | case 'required': 21 | schema.required = clone(child.value) 22 | break 23 | case 'dependencies': 24 | schema.dependencies = convertDependenciesToSchema(child) 25 | break 26 | case 'enum': 27 | schema.enum = clone(child.value.enum) 28 | break 29 | } 30 | }) 31 | return schema 32 | } 33 | 34 | function convertArrayToSchema (node) { 35 | let schema = clone(node.value) 36 | if (node.children.length > 0) { 37 | let child = node.children[0] 38 | switch (child.type) { 39 | case 'jsonSchema': 40 | schema.items = convertTreeToSchema(child) 41 | break 42 | case 'string': 43 | case 'integer': 44 | case 'number': 45 | case 'boolean': 46 | case 'null': 47 | case 'enum': 48 | case 'ref': 49 | schema.items = convertTypeToSchema(child) 50 | break 51 | case 'object': 52 | schema.items = convertObjectToSchema(child) 53 | break 54 | case 'array': 55 | schema.items = convertArrayToSchema(child) 56 | break 57 | case 'allOf': 58 | case 'anyOf': 59 | case 'oneOf': 60 | case 'not': 61 | schema.items = convertOptionToSchema(child) 62 | break 63 | case 'items': 64 | schema.items = convertItemsToSchema(child) 65 | break 66 | } 67 | } 68 | return schema 69 | } 70 | 71 | function convertPropertiesToSchema (node) { 72 | let schema = {} 73 | node.children.forEach(child => { 74 | switch (child.type) { 75 | case 'jsonSchema': 76 | schema[child.name] = convertTreeToSchema(child) 77 | break 78 | case 'string': 79 | case 'integer': 80 | case 'number': 81 | case 'boolean': 82 | case 'null': 83 | case 'enum': 84 | case 'ref': 85 | schema[child.name] = convertTypeToSchema(child) 86 | break 87 | case 'object': 88 | schema[child.name] = convertObjectToSchema(child) 89 | break 90 | case 'array': 91 | schema[child.name] = convertArrayToSchema(child) 92 | break 93 | case 'allOf': 94 | case 'anyOf': 95 | case 'oneOf': 96 | case 'not': 97 | schema[child.name] = convertOptionToSchema(child) 98 | break 99 | } 100 | }) 101 | return schema 102 | } 103 | 104 | function convertDependenciesToSchema (node) { 105 | let schema = {} 106 | node.children.forEach(child => { 107 | schema[child.name] = clone(child.value) 108 | }) 109 | return schema 110 | } 111 | 112 | function convertItemsToSchema (node) { 113 | let schema = [] 114 | node.children.forEach(child => { 115 | switch (child.type) { 116 | case 'jsonSchema': 117 | schema.push(convertTreeToSchema(child)) 118 | break 119 | case 'string': 120 | case 'integer': 121 | case 'number': 122 | case 'boolean': 123 | case 'null': 124 | case 'enum': 125 | case 'ref': 126 | schema.push(convertTypeToSchema(child)) 127 | break 128 | case 'object': 129 | schema.push(convertObjectToSchema(child)) 130 | break 131 | case 'array': 132 | schema.push(convertArrayToSchema(child)) 133 | break 134 | case 'allOf': 135 | case 'anyOf': 136 | case 'oneOf': 137 | case 'not': 138 | schema.push(convertOptionToSchema(child)) 139 | break 140 | } 141 | }) 142 | return schema 143 | } 144 | 145 | function convertOptionToSchema (node) { 146 | let schema = {} 147 | schema[node.type] = [] 148 | let list = schema[node.type] 149 | node.children.forEach(child => { 150 | switch (child.type) { 151 | case 'jsonSchema': 152 | list.push(convertTreeToSchema(child)) 153 | break 154 | case 'string': 155 | case 'integer': 156 | case 'number': 157 | case 'boolean': 158 | case 'null': 159 | case 'enum': 160 | case 'ref': 161 | list.push(convertTypeToSchema(child)) 162 | break 163 | case 'object': 164 | list.push(convertObjectToSchema(child)) 165 | break 166 | case 'array': 167 | list.push(convertArrayToSchema(child)) 168 | break 169 | case 'allOf': 170 | case 'anyOf': 171 | case 'oneOf': 172 | case 'not': 173 | list.push(convertOptionToSchema(child)) 174 | break 175 | } 176 | }) 177 | return schema 178 | } 179 | 180 | function convertDefinitionsToSchema (node) { 181 | let schema = {} 182 | node.children.forEach(child => { 183 | switch (child.type) { 184 | case 'jsonSchema': 185 | schema[child.name] = convertTreeToSchema(child) 186 | break 187 | case 'string': 188 | case 'integer': 189 | case 'number': 190 | case 'boolean': 191 | case 'null': 192 | case 'enum': 193 | case 'ref': 194 | schema[child.name] = convertTypeToSchema(child) 195 | break 196 | case 'object': 197 | schema[child.name] = convertObjectToSchema(child) 198 | break 199 | case 'array': 200 | schema[child.name] = convertArrayToSchema(child) 201 | break 202 | case 'allOf': 203 | case 'anyOf': 204 | case 'oneOf': 205 | case 'not': 206 | schema[child.name] = convertOptionToSchema(child) 207 | break 208 | } 209 | }) 210 | return schema 211 | } 212 | 213 | export function convertTreeToSchema (tree) { 214 | let schema = {} 215 | if (tree.children.length > 0) { 216 | let child = tree.children[0] 217 | switch (child.type) { 218 | case 'jsonSchema': 219 | schema = convertTreeToSchema(child) 220 | break 221 | case 'string': 222 | case 'integer': 223 | case 'number': 224 | case 'boolean': 225 | case 'null': 226 | case 'enum': 227 | schema = convertTypeToSchema(child) 228 | break 229 | case 'object': 230 | schema = convertObjectToSchema(child) 231 | break 232 | case 'array': 233 | schema = convertArrayToSchema(child) 234 | break 235 | case 'allOf': 236 | case 'anyOf': 237 | case 'oneOf': 238 | case 'not': 239 | schema = convertOptionToSchema(child) 240 | break 241 | case 'definitions': 242 | schema.definitions = convertDefinitionsToSchema(child) 243 | break 244 | } 245 | } 246 | if (!tree.parent) schema.title = tree.name 247 | if (tree.value.description) schema.description = tree.value.description 248 | return schema 249 | } 250 | 251 | export default convertTreeToSchema 252 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/index.js: -------------------------------------------------------------------------------- 1 | export { convertTreeToSchema } from './convertTreeToSchema' 2 | export { convertSchemaToTree } from './convertSchemaToTree' 3 | export { authentication } from '../../firebase' 4 | export { repository } from './repository-firebase' 5 | export { componentData } from './componentData' 6 | export { treeData } from './treeData' 7 | export { menuData } from './menuData' 8 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/BasicInspector.vue: -------------------------------------------------------------------------------- 1 | 18 | 89 | 106 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/DependencyItemInspector.vue: -------------------------------------------------------------------------------- 1 | 9 | 50 | 60 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/EnumInspector.vue: -------------------------------------------------------------------------------- 1 | 21 | 92 | 125 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/Property.js: -------------------------------------------------------------------------------- 1 | export class Property { 2 | constructor (type, name) { 3 | this.type = type 4 | this.name = name 5 | this.value = null 6 | this.exist = false 7 | this.errMsg = null 8 | } 9 | 10 | setValue (value) { 11 | this.exist = typeof value !== 'undefined' 12 | this.value = value 13 | this.errMsg = null 14 | } 15 | 16 | getValue () { 17 | if (this.type === 'integer') { 18 | return this.exist ? Number.parseInt(this.value) : undefined 19 | } 20 | if (this.type === 'number') { 21 | return this.exist ? Number.parseFloat(this.value) : undefined 22 | } 23 | return this.exist ? this.value : undefined 24 | } 25 | } 26 | 27 | export default Property 28 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/RefInspector.vue: -------------------------------------------------------------------------------- 1 | 10 | 33 | 43 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/RequiredInspector.vue: -------------------------------------------------------------------------------- 1 | 9 | 48 | 58 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/inspectors/index.js: -------------------------------------------------------------------------------- 1 | import requiredInspector from './RequiredInspector.vue' 2 | import dependencyItemInspector from './DependencyItemInspector.vue' 3 | import enumInspector from './EnumInspector.vue' 4 | import refInspector from './RefInspector.vue' 5 | import BasicInspector from './BasicInspector.vue' 6 | 7 | export default { 8 | requiredInspector, 9 | dependencyItemInspector, 10 | enumInspector, 11 | refInspector, 12 | BasicInspector 13 | } 14 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/menuData.js: -------------------------------------------------------------------------------- 1 | export var menuData = { 2 | menuItems: [ 3 | { 4 | name: 'remove', 5 | label: 'Remove', 6 | disabled (source) { 7 | return !(source.node.parent) 8 | }, 9 | action (source) { 10 | source.remove() 11 | } 12 | }, 13 | { 14 | name: 'moveUp', 15 | label: 'Move Up', 16 | disabled (source) { 17 | return !(source.node.parent) 18 | }, 19 | action: source => { 20 | source.moveUp() 21 | } 22 | }, 23 | { 24 | name: 'moveDown', 25 | label: 'Move Down', 26 | disabled (source) { 27 | return !(source.node.parent) 28 | }, 29 | action: source => { 30 | source.moveDown() 31 | } 32 | } 33 | ] 34 | } 35 | 36 | export default menuData 37 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/repository-firebase.js: -------------------------------------------------------------------------------- 1 | import * as firebase from 'firebase' 2 | import { Database, UserNotSignInError } from '../../firebase' 3 | import $RefParser from 'json-schema-ref-parser' 4 | 5 | // define custom error for repository has not initialized 6 | export function RepositoryNotInitError (message) { 7 | this.name = 'RepositoryNotInitError' 8 | this.message = message || 'Repository has not initialized.' 9 | this.stack = (new Error()).stack 10 | } 11 | RepositoryNotInitError.prototype = Object.create(Error.prototype) 12 | RepositoryNotInitError.prototype.constructor = RepositoryNotInitError 13 | 14 | // define custom error for schema not exist 15 | export function SchemaNotExistError (message) { 16 | this.name = 'SchemaNotExistError' 17 | this.message = message || 'Schema not exist.' 18 | this.stack = (new Error()).stack 19 | } 20 | SchemaNotExistError.prototype = Object.create(Error.prototype) 21 | SchemaNotExistError.prototype.constructor = SchemaNotExistError 22 | 23 | // encode key to URL Encoded string 24 | function EncodeSchema (schema) { 25 | var result = Array.isArray(schema) ? [] : {} 26 | for (var prop in schema) { 27 | var value = schema[prop] 28 | if (typeof value === 'object') { 29 | result[encodeURIComponent(prop)] = EncodeSchema(value) 30 | } else { 31 | result[encodeURIComponent(prop)] = value 32 | } 33 | } 34 | return result 35 | } 36 | 37 | // decode key from URL Encoded string 38 | function DecodeSchema (schema) { 39 | var result = Array.isArray(schema) ? [] : {} 40 | for (var prop in schema) { 41 | var value = schema[prop] 42 | if (typeof value === 'object') { 43 | result[decodeURIComponent(prop)] = DecodeSchema(value) 44 | } else { 45 | result[decodeURIComponent(prop)] = value 46 | } 47 | } 48 | return result 49 | } 50 | 51 | export class Repository { 52 | constructor () { 53 | this.database = new Database() 54 | this.uid = null 55 | // firebase resolver for json-schema-ref-parser 56 | this.firebaseResolver = { 57 | order: 1, 58 | canRead: /^repository:/i, 59 | read: async (file) => { 60 | let schemaName = file.url.substr(13) 61 | return await this.retrieveSchema(schemaName, false) 62 | } 63 | } 64 | } 65 | 66 | async init () { 67 | return new Promise((resolve, reject) => { 68 | if (firebase.auth().currentUser) { 69 | this.uid = firebase.auth().currentUser.uid 70 | resolve() 71 | } else { 72 | reject(new UserNotSignInError()) 73 | } 74 | }) 75 | } 76 | 77 | async retrieveSchema (schemaName, dereference) { 78 | if (!this.uid) throw new RepositoryNotInitError() 79 | let reference = `/schemas/${this.uid}/${schemaName}` 80 | let schema = await this.database.readValue(reference) 81 | if (schema) { 82 | schema = DecodeSchema(schema) // decode schema 83 | if (dereference || typeof dereference === 'undefined') { 84 | try { 85 | return await $RefParser.dereference(schema, { resolve: { firebase: this.firebaseResolver } }) 86 | } catch (err) { 87 | // return un-dereference schema 88 | } 89 | } 90 | return schema 91 | } else { 92 | throw new SchemaNotExistError() 93 | } 94 | } 95 | 96 | async retrieveAllSchemas () { 97 | if (!this.uid) throw new RepositoryNotInitError() 98 | let reference = `/schemas/${this.uid}` 99 | let queryResult = await this.database.readSnapshot(reference) 100 | let schemas = [] 101 | queryResult.forEach(item => { 102 | schemas.push(DecodeSchema(item.val())) // decode schema 103 | }) 104 | return schemas 105 | } 106 | 107 | async retrieveTypes () { 108 | if (!this.uid) throw new RepositoryNotInitError() 109 | let reference = `/schemas/${this.uid}` 110 | let types = await this.database.list(reference) 111 | return types 112 | } 113 | 114 | async saveSchema (schema, schemaName) { 115 | if (!this.uid) throw new RepositoryNotInitError() 116 | let reference = `/schemas/${this.uid}/${schemaName}` 117 | await this.database.write(reference, EncodeSchema(schema)) // encode schema 118 | } 119 | 120 | async deleteSchema (schemaName) { 121 | if (!this.uid) throw new RepositoryNotInitError() 122 | let reference = `/schemas/${this.uid}/${schemaName}` 123 | await this.database.delete(reference) 124 | } 125 | 126 | async deleteAllSchemas () { 127 | if (!this.uid) throw new RepositoryNotInitError() 128 | let reference = `/schemas/${this.uid}` 129 | await this.database.delete(reference) 130 | } 131 | } 132 | 133 | export var repository = new Repository() 134 | 135 | export default repository 136 | 137 | -------------------------------------------------------------------------------- /src/components/json-schema-editor/treeData.js: -------------------------------------------------------------------------------- 1 | import Components from './components' 2 | 3 | export var treeData = new Components.JsonSchemaComponent() 4 | 5 | export default treeData 6 | -------------------------------------------------------------------------------- /src/components/tree/store.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | function generateId () { 4 | return (new Date()).getTime() + ('000000000' + Math.floor((Math.random() * 10000) + 1)).substr(-4) 5 | } 6 | 7 | function resolveDupName (node, parent) { 8 | var origName = node.name 9 | var count = 0 10 | parent.children.forEach(child => { 11 | let reg = new RegExp(`^${RegExp.escape(origName)}(\\(\\d+\\))?$`, 'g') 12 | if (reg.test(child.name)) count++ 13 | }) 14 | if (count > 0) { 15 | node.name = `${origName}(${count})` 16 | } 17 | } 18 | 19 | function functionName (func) { 20 | // Match: 21 | // - ^ the beginning of the string 22 | // - function the word 'function' 23 | // - \s+ at least some white space 24 | // - ([\w\$]+) capture one or more valid JavaScript identifier characters 25 | // - \s* optionally followed by white space (in theory there won't be any here, 26 | // so if performance is an issue this can be omitted[1] 27 | // - \( followed by an opening brace 28 | // 29 | let result = /^function\s+([\w$]+)\s*\(/.exec(func.toString()) 30 | 31 | return result ? result[1] : '' // for an anonymous function there won't be a match 32 | } 33 | 34 | var selectedNode 35 | 36 | function populateTree (node, parent) { 37 | let root = new TreeNode(node.type, node.name, node.value, node.valueSchema, 38 | parent, node.icon, node.funcs, node.editable, node.draggable, node.droppable, 39 | node.expended, node.selected) 40 | if (root.selected) selectedNode = root 41 | if (node.children) { 42 | root.children = [] 43 | node.children.forEach(child => { 44 | root.children.push(populateTree(child, root)) 45 | }) 46 | } 47 | return root 48 | } 49 | 50 | class TreeNode { 51 | constructor (type, name, value, valueSchema, parent, icon, funcs, editable, draggable, droppable, expended, selected) { 52 | this.id = generateId() 53 | this.type = type 54 | this.name = name 55 | this.valueSchema = valueSchema || { type: 'object' } 56 | // consider use default of schema when value is null 57 | this.value = value 58 | this.parent = parent 59 | this.icon = icon 60 | this.funcs = funcs 61 | this.editable = typeof editable === 'undefined' ? true : editable 62 | this.draggable = typeof draggable === 'undefined' ? true : draggable 63 | this.droppable = typeof droppable === 'undefined' ? true : droppable 64 | this.expended = expended 65 | this.selected = selected 66 | this.editing = false 67 | } 68 | 69 | isAncestor (node) { 70 | if (this === node) return true 71 | if (this.parent) return this.parent.isAncestor(node) 72 | else return false 73 | } 74 | 75 | append (child) { 76 | // if child is not TreeNode, then create TreeNode 77 | let newNode = (child.prototype && functionName(child.prototype) === 'TreeNode') ? child : populateTree(child) 78 | if (newNode.name) resolveDupName(newNode, this) 79 | Vue.set(newNode, 'parent', this) 80 | this.children.push(newNode) 81 | Vue.set(this, 'expended', true) 82 | } 83 | 84 | remove () { 85 | if (this.parent) { 86 | let children = this.parent.children 87 | let index = children.indexOf(this) 88 | children.splice(index, 1) 89 | Vue.set(this, 'parent', null) 90 | } 91 | } 92 | 93 | moveUp () { 94 | if (this.parent) { 95 | let children = this.parent.children 96 | let index = children.indexOf(this) 97 | if (index <= 0) return 98 | children.splice(index, 1) 99 | children.splice(index - 1, 0, this) 100 | } 101 | } 102 | 103 | moveDown () { 104 | if (this.parent) { 105 | let children = this.parent.children 106 | let index = children.indexOf(this) 107 | if (index === -1 || index === children.length - 1) return 108 | children.splice(index, 1) 109 | children.splice(index + 1, 0, this) 110 | } 111 | } 112 | } 113 | 114 | class Store { 115 | constructor () { 116 | this.tree = null 117 | this.selectedNode = null 118 | } 119 | 120 | init (tree) { 121 | selectedNode = null 122 | this.tree = populateTree(tree) 123 | if (selectedNode) { 124 | this.selectedNode = selectedNode 125 | } else { 126 | this.tree.selected = true 127 | this.selectedNode = this.tree 128 | } 129 | } 130 | 131 | toggle (node) { 132 | node.expended = !node.expended 133 | } 134 | 135 | select (node) { 136 | if (this.selectedNode) { 137 | this.selectedNode.selected = false 138 | this.selectedNode.editing = false 139 | } 140 | this.selectedNode = node 141 | node.selected = true 142 | } 143 | 144 | startEdit (node) { 145 | node.editing = true 146 | } 147 | 148 | stopEdit (node) { 149 | node.editing = false 150 | } 151 | 152 | rename (node, name) { 153 | node.name = name 154 | node.editing = false 155 | } 156 | 157 | append (node, child) { 158 | node.append(child) 159 | } 160 | 161 | remove (node) { 162 | node.remove() 163 | } 164 | 165 | moveUp (node) { 166 | node.moveUp() 167 | } 168 | 169 | moveDown (node) { 170 | node.moveDown() 171 | } 172 | } 173 | 174 | export default Store 175 | -------------------------------------------------------------------------------- /src/firebase/index.js: -------------------------------------------------------------------------------- 1 | import * as firebase from 'firebase' 2 | 3 | // Initialize firebase 4 | // Replace following config with your Firebase config 5 | var config = { 6 | apiKey: 'your firebase api key', 7 | authDomain: 'your firebase auth domain', 8 | databaseURL: 'your firebase database url', 9 | projectId: 'your firebase project id', 10 | storageBucket: 'your firebase storage bucket', 11 | messagingSenderId: 'your firebase message sender id' 12 | } 13 | firebase.initializeApp(config) 14 | 15 | // define custom error for schema not exist 16 | export function UserNotSignInError (message) { 17 | this.name = 'UserNotSignInError' 18 | this.message = message || 'No sign in user.' 19 | this.stack = (new Error()).stack 20 | } 21 | UserNotSignInError.prototype = Object.create(Error.prototype) 22 | UserNotSignInError.prototype.constructor = UserNotSignInError 23 | 24 | export class Authentication { 25 | constructor () { 26 | this.service = firebase.auth() 27 | this.currentUser = null 28 | this.callbacks = [] 29 | this.service.onAuthStateChanged(user => { 30 | this.currentUser = user 31 | this.callbacks.forEach(callback => { 32 | callback(user) 33 | }) 34 | }) 35 | this.options = { 36 | requireVerifyEmail: false, 37 | sendVerifyEmailExplicitly: true, 38 | requireOldPassword: false 39 | } 40 | } 41 | 42 | addListener (callback) { 43 | this.callbacks.push(callback) 44 | } 45 | 46 | removeListener (callback) { 47 | let idx = this.callbacks.indexOf(callback) 48 | if (idx >= 0) this.callbacks.splice(idx, 1) 49 | } 50 | 51 | async signUp (email, password) { 52 | return new Promise((resolve, reject) => { 53 | this.service.createUserWithEmailAndPassword(email, password) 54 | .then(user => { 55 | resolve(user) 56 | }) 57 | .catch(error => { 58 | reject(error) 59 | }) 60 | }) 61 | } 62 | 63 | async sendVerificationEmail () { 64 | if (this.currentUser) { 65 | return new Promise((resolve, reject) => { 66 | this.currentUser.sendEmailVerification() 67 | .then(() => { 68 | resolve() 69 | }) 70 | .catch(error => { 71 | reject(error) 72 | }) 73 | }) 74 | } else { 75 | throw new UserNotSignInError() 76 | } 77 | } 78 | 79 | async verifyEmail (code) { 80 | return new Promise((resolve, reject) => { 81 | this.service.applyActionCode(code) 82 | .then(() => { 83 | resolve() 84 | }) 85 | .catch(error => { 86 | reject(error) 87 | }) 88 | }) 89 | } 90 | 91 | async signIn (email, password) { 92 | return new Promise((resolve, reject) => { 93 | this.service.signInWithEmailAndPassword(email, password) 94 | .then(user => { 95 | resolve(user) 96 | }) 97 | .catch(error => { 98 | reject(error) 99 | }) 100 | }) 101 | } 102 | 103 | async changePassword (newPassword) { 104 | if (this.currentUser) { 105 | return new Promise((resolve, reject) => { 106 | this.currentUser.updatePassword(newPassword) 107 | .then(() => { 108 | resolve() 109 | }) 110 | .catch(error => { 111 | reject(error) 112 | }) 113 | }) 114 | } else { 115 | throw new UserNotSignInError() 116 | } 117 | } 118 | 119 | async resetPassword (email) { 120 | return new Promise((resolve, reject) => { 121 | this.service.sendPasswordResetEmail(email) 122 | .then(() => { 123 | resolve() 124 | }) 125 | .catch(error => { 126 | reject(error) 127 | }) 128 | }) 129 | } 130 | 131 | async confirmPasswordReset (code, newPassword) { 132 | return new Promise((resolve, reject) => { 133 | this.service.confirmPasswordReset(code, newPassword) 134 | .then(() => { 135 | resolve() 136 | }) 137 | .catch(error => { 138 | reject(error) 139 | }) 140 | }) 141 | } 142 | 143 | async deleteUser () { 144 | if (this.currentUser) { 145 | return new Promise((resolve, reject) => { 146 | this.currentUser.delete() 147 | .then(() => { 148 | resolve() 149 | }) 150 | .catch(error => { 151 | reject(error) 152 | }) 153 | }) 154 | } else { 155 | throw new UserNotSignInError() 156 | } 157 | } 158 | 159 | async signOut () { 160 | return new Promise((resolve, reject) => { 161 | this.service.signOut() 162 | .then(() => { 163 | resolve() 164 | }) 165 | .catch(error => { 166 | reject(error) 167 | }) 168 | }) 169 | } 170 | 171 | async retrieveCurrentUser () { 172 | return new Promise((resolve, reject) => { 173 | this.currentUser = this.service.currentUser 174 | if (this.currentUser) { 175 | resolve(this.currentUser) 176 | } else { 177 | reject(new UserNotSignInError()) 178 | } 179 | }) 180 | } 181 | } 182 | 183 | export var authentication = new Authentication() 184 | 185 | export class Storage { 186 | constructor () { 187 | this.service = firebase.storage() 188 | } 189 | } 190 | 191 | export class Database { 192 | constructor () { 193 | this.service = firebase.database() 194 | } 195 | 196 | async readSnapshot (reference) { 197 | return new Promise((resolve, reject) => { 198 | this.service.ref(reference).orderByKey().once('value') 199 | .then((snapshot) => { 200 | resolve(snapshot) 201 | }) 202 | .catch(error => { 203 | reject(error) 204 | }) 205 | }) 206 | } 207 | 208 | async readValue (reference) { 209 | return new Promise((resolve, reject) => { 210 | this.service.ref(reference).orderByKey().once('value') 211 | .then((snapshot) => { 212 | resolve(snapshot.val()) 213 | }) 214 | .catch(error => { 215 | reject(error) 216 | }) 217 | }) 218 | } 219 | 220 | async list (reference) { 221 | return new Promise((resolve, reject) => { 222 | this.service.ref(reference).orderByKey().once('value') 223 | .then((snapshot) => { 224 | let list = [] 225 | snapshot.forEach(child => { 226 | list.push(child.key) 227 | }) 228 | resolve(list) 229 | }) 230 | .catch(error => { 231 | reject(error) 232 | }) 233 | }) 234 | } 235 | 236 | async write (reference, data) { 237 | return new Promise((resolve, reject) => { 238 | this.service.ref(reference).set(data) 239 | .then(() => { 240 | resolve() 241 | }) 242 | .catch(error => { 243 | reject(error) 244 | }) 245 | }) 246 | } 247 | 248 | async delete (reference) { 249 | return new Promise((resolve, reject) => { 250 | this.service.ref(reference).remove() 251 | .then(() => { 252 | resolve() 253 | }) 254 | .catch(error => { 255 | reject(error) 256 | }) 257 | }) 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | import VueMaterial from 'vue-material' 5 | import 'vue-material/dist/vue-material.css' 6 | import 'material-icons/css/material-icons.css' 7 | import App from './App' 8 | import router from './router' 9 | 10 | Vue.use(VueMaterial) 11 | Vue.material.registerTheme('default', { 12 | primary: 'blue' 13 | }) 14 | Vue.config.productionTip = false 15 | 16 | /* eslint-disable no-new */ 17 | new Vue({ 18 | el: '#app', 19 | router, 20 | template: '', 21 | components: { App } 22 | }) 23 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import SignIn from '@/components/account/SignIn' 4 | import SignUp from '@/components/account/SignUp.vue' 5 | import VerifyEmail from '@/components/account/VerifyEmail.vue' 6 | import ChangePassword from '@/components/account/ChangePassword' 7 | import JsonSchemaEditor from '@/components/JsonSchemaEditor' 8 | 9 | Vue.use(Router) 10 | 11 | export default new Router({ 12 | routes: [ 13 | { 14 | path: '/', 15 | name: 'home', 16 | component: JsonSchemaEditor 17 | }, 18 | { 19 | path: '/signIn', 20 | name: 'signIn', 21 | component: SignIn 22 | }, 23 | { 24 | path: '/signUp', 25 | name: 'signUp', 26 | component: SignUp 27 | }, 28 | { 29 | path: '/verifyEmail', 30 | name: 'verifyEmail', 31 | component: VerifyEmail 32 | }, 33 | { 34 | path: '/changePassword', 35 | name: 'changePassword', 36 | component: ChangePassword 37 | } 38 | ] 39 | }) 40 | -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tangram-js/json-schema-editor/417579141b2d022dbaed233ba59c0fb7f8e4a2a9/static/.gitkeep --------------------------------------------------------------------------------