()
| 62 | } |
| 63 | |
| 64 | async load () { |
| 65 | const fetchUrl = document.location.origin + document.location.pathname.toString() |
| 66 | const loader = new SchemaLoader(this.options) |
| 67 | |
| 68 | loader.onSchemaLoaded = (payload) => { |
| 69 | this.trigger('schemaLoaded', payload) |
| 70 | } |
| 71 | |
| 72 | loader.onAllSchemasLoaded = () => { |
| 73 | this.trigger('allSchemasLoaded') |
| 74 | } |
| 75 | |
| 76 | this.expandSchema = (schema) => loader.expandSchema(schema) |
| 77 | this.expandRefs = (schema, fileBase) => loader.expandRefs(schema, fileBase) |
| 78 | const location = document.location.toString() |
| 79 | const schema = await loader.load(this.schema, fetchUrl, location) |
| 80 | const validatorOptions = this.options.custom_validators ? { custom_validators: this.options.custom_validators } : {} |
| 81 | this.validator = new Validator(this, null, validatorOptions, JSONEditor.defaults) |
| 82 | const editorClass = this.getEditorClass(schema) |
| 83 | this.root = this.createEditor(editorClass, { |
| 84 | jsoneditor: this, |
| 85 | schema, |
| 86 | required: true, |
| 87 | container: this.root_container |
| 88 | }) |
| 89 | |
| 90 | this.root.preBuild() |
| 91 | this.root.build() |
| 92 | this.root.postBuild() |
| 93 | |
| 94 | /* Starting data */ |
| 95 | if (hasOwnProperty(this.options, 'startval')) this.root.setValue(this.options.startval) |
| 96 | |
| 97 | this.validation_results = this.validator.validate(this.root.getValue()) |
| 98 | this.root.showValidationErrors(this.validation_results) |
| 99 | this.ready = true |
| 100 | this.element.classList.remove('je-not-loaded') |
| 101 | this.element.classList.add('je-ready') |
| 102 | |
| 103 | /* Fire ready event asynchronously */ |
| 104 | window.requestAnimationFrame(() => { |
| 105 | if (!this.ready) return |
| 106 | this.validation_results = this.validator.validate(this.root.getValue()) |
| 107 | this.root.showValidationErrors(this.validation_results) |
| 108 | this.trigger('ready') |
| 109 | this.trigger('change') |
| 110 | }) |
| 111 | } |
| 112 | |
| 113 | getValue () { |
| 114 | if (!this.ready) throw new Error('JSON Editor not ready yet. Make sure the load method is complete') |
no test coverage detected