MCPcopy Index your code
hub / github.com/json-editor/json-editor / preBuild

Method preBuild

src/editors/object.js:368–441  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

366 }
367
368 preBuild () {
369 super.preBuild()
370
371 this.editors = {}
372 this.cached_editors = {}
373
374 this.format = this.options.layout || this.options.object_layout || this.schema.format || this.jsoneditor.options.object_layout || 'normal'
375
376 this.schema.properties = this.schema.properties || {}
377
378 this.minwidth = 0
379 this.maxwidth = 0
380
381 /* If the object should be rendered as a table row */
382 if (this.options.table_row) {
383 Object.entries(this.schema.properties).forEach(([key, schema]) => {
384 const editor = this.jsoneditor.getEditorClass(schema)
385 this.editors[key] = this.jsoneditor.createEditor(editor, {
386 jsoneditor: this.jsoneditor,
387 schema,
388 path: `${this.path}.${key}`,
389 parent: this,
390 compact: true,
391 required: true
392 }, this.currentDepth + 1)
393 this.editors[key].preBuild()
394
395 const width = this.editors[key].options.hidden ? 0 : (this.editors[key].options.grid_columns || this.editors[key].getNumColumns())
396
397 this.minwidth += width
398 this.maxwidth += width
399 })
400 this.no_link_holder = true
401 /* If the object should be rendered as a table */
402 } else if (this.options.table) {
403 /* TODO: table display format */
404 throw new Error('Not supported yet')
405 /* If the object should be rendered as a div */
406 } else {
407 if (!this.schema.defaultProperties) {
408 if (this.jsoneditor.options.display_required_only || this.options.display_required_only) {
409 this.schema.defaultProperties = Object.keys(this.schema.properties).filter(k => this.isRequiredObject({ key: k, schema: this.schema.properties[k] }))
410 } else {
411 this.schema.defaultProperties = Object.keys(this.schema.properties)
412 }
413 }
414
415 /* Increase the grid width to account for padding */
416 this.maxwidth += 1
417
418 /* Check for array (eg. meta-schema options is an object) */
419 if (Array.isArray(this.schema.defaultProperties)) {
420 this.schema.defaultProperties.forEach(key => {
421 this.addObjectProperty(key, true)
422
423 if (this.editors[key]) {
424 this.minwidth = Math.max(this.minwidth, (this.editors[key].options.grid_columns || this.editors[key].getNumColumns()))
425 this.maxwidth += (this.editors[key].options.grid_columns || this.editors[key].getNumColumns())

Callers 1

addObjectPropertyMethod · 0.45

Calls 5

isRequiredObjectMethod · 0.95
addObjectPropertyMethod · 0.95
getEditorClassMethod · 0.80
createEditorMethod · 0.80
getNumColumnsMethod · 0.45

Tested by

no test coverage detected