MCPcopy
hub / github.com/json-editor/json-editor / constructor

Method constructor

src/core.js:15–62  ·  view source on GitHub ↗
(element, options = {})

Source from the content-addressed store, hash-verified

13
14export class JSONEditor {
15 constructor (element, options = {}) {
16 if (!(element instanceof Element)) throw new Error('element should be an instance of Element')
17
18 this.element = element
19 this.options = extend({}, JSONEditor.defaults.options, options)
20 this.ready = false
21 this.copyClipboard = null
22 this.schema = this.options.schema
23 this.template = this.options.template
24 this.translate = this.options.translate || JSONEditor.defaults.translate
25 this.translateProperty = this.options.translateProperty || JSONEditor.defaults.translateProperty
26 this.uuid = 0
27 this.__data = {}
28 const themeName = this.options.theme || JSONEditor.defaults.theme
29 const themeClass = JSONEditor.defaults.themes[themeName]
30
31 /* Load editors and selected theme style rules */
32 if (!themeClass) throw new Error(`Unknown theme ${themeName}`)
33 this.element.setAttribute('data-theme', themeName)
34 this.element.classList.add('je-not-loaded')
35 this.element.classList.remove('je-ready')
36 // eslint-disable-next-line new-cap
37 this.theme = new themeClass(this)
38 const rules = extend(styleRules, this.getEditorsRules())
39
40 /* Call addNewStyleRulesToShadowRoot if shadowRoot is found, otherwise call addNewStyleRules */
41 const addRules = (themeName, rules, shadowRoot) => shadowRoot
42 ? this.addNewStyleRulesToShadowRoot(themeName, rules, shadowRoot)
43 : this.addNewStyleRules(themeName, rules)
44
45 if (!this.theme.options.disable_theme_rules) {
46 /* Attempt to locate a shadowRoot parent (i.e. in Web Components) */
47 const shadowRoot = getShadowParent(this.element)
48 addRules('default', rules, shadowRoot)
49 if (typeof themeClass.rules !== 'undefined') {
50 addRules(themeName, themeClass.rules, shadowRoot)
51 }
52 }
53
54 /* Init icon class */
55 const iconClass = JSONEditor.defaults.iconlibs[this.options.iconlib || JSONEditor.defaults.iconlib]
56 // eslint-disable-next-line new-cap
57 if (iconClass) this.iconlib = new iconClass()
58
59 this.root_container = this.theme.getContainer()
60 this.element.appendChild(this.root_container)
61 this.promise = this.load()
62 }
63
64 async load () {
65 const fetchUrl = document.location.origin + document.location.pathname.toString()

Callers

nothing calls this directly

Calls 6

getEditorsRulesMethod · 0.95
loadMethod · 0.95
extendFunction · 0.90
getShadowParentFunction · 0.90
addMethod · 0.80
getContainerMethod · 0.45

Tested by

no test coverage detected