|
|
@ -68,7 +68,7 @@ textmode.create = function (container, options = {}) {
|
|
|
|
// TODO: make the option options.ace deprecated, it's not needed anymore (see #309)
|
|
|
|
// TODO: make the option options.ace deprecated, it's not needed anymore (see #309)
|
|
|
|
|
|
|
|
|
|
|
|
// determine mode
|
|
|
|
// determine mode
|
|
|
|
this.mode = (options.mode === 'code') ? 'code' : ((options.mode === 'text') ? 'text' : 'text-plain')
|
|
|
|
this.mode = (options.mode === 'code') ? 'code' : 'text'
|
|
|
|
if (this.mode === 'code') {
|
|
|
|
if (this.mode === 'code') {
|
|
|
|
// verify whether Ace editor is available and supported
|
|
|
|
// verify whether Ace editor is available and supported
|
|
|
|
if (typeof _ace === 'undefined') {
|
|
|
|
if (typeof _ace === 'undefined') {
|
|
|
@ -132,7 +132,6 @@ textmode.create = function (container, options = {}) {
|
|
|
|
this.frame.appendChild(this.menu)
|
|
|
|
this.frame.appendChild(this.menu)
|
|
|
|
|
|
|
|
|
|
|
|
// create format button
|
|
|
|
// create format button
|
|
|
|
if(this.mode !== 'text-plain') {
|
|
|
|
|
|
|
|
const buttonFormat = document.createElement('button')
|
|
|
|
const buttonFormat = document.createElement('button')
|
|
|
|
buttonFormat.type = 'button'
|
|
|
|
buttonFormat.type = 'button'
|
|
|
|
buttonFormat.className = 'jsoneditor-format'
|
|
|
|
buttonFormat.className = 'jsoneditor-format'
|
|
|
@ -146,10 +145,8 @@ textmode.create = function (container, options = {}) {
|
|
|
|
me._onError(err)
|
|
|
|
me._onError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create compact button
|
|
|
|
// create compact button
|
|
|
|
if(this.mode !== 'text-plain') {
|
|
|
|
|
|
|
|
const buttonCompact = document.createElement('button')
|
|
|
|
const buttonCompact = document.createElement('button')
|
|
|
|
buttonCompact.type = 'button'
|
|
|
|
buttonCompact.type = 'button'
|
|
|
|
buttonCompact.className = 'jsoneditor-compact'
|
|
|
|
buttonCompact.className = 'jsoneditor-compact'
|
|
|
@ -163,10 +160,9 @@ textmode.create = function (container, options = {}) {
|
|
|
|
me._onError(err)
|
|
|
|
me._onError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create sort button
|
|
|
|
// create sort button
|
|
|
|
if (this.options.enableSort && this.mode !== 'text-plain') {
|
|
|
|
if (this.options.enableSort) {
|
|
|
|
const sort = document.createElement('button')
|
|
|
|
const sort = document.createElement('button')
|
|
|
|
sort.type = 'button'
|
|
|
|
sort.type = 'button'
|
|
|
|
sort.className = 'jsoneditor-sort'
|
|
|
|
sort.className = 'jsoneditor-sort'
|
|
|
@ -178,7 +174,7 @@ textmode.create = function (container, options = {}) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// create transform button
|
|
|
|
// create transform button
|
|
|
|
if (this.options.enableTransform && this.mode !== 'text-plain') {
|
|
|
|
if (this.options.enableTransform) {
|
|
|
|
const transform = document.createElement('button')
|
|
|
|
const transform = document.createElement('button')
|
|
|
|
transform.type = 'button'
|
|
|
|
transform.type = 'button'
|
|
|
|
transform.title = translate('transformTitleShort')
|
|
|
|
transform.title = translate('transformTitleShort')
|
|
|
@ -190,7 +186,6 @@ textmode.create = function (container, options = {}) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// create repair button
|
|
|
|
// create repair button
|
|
|
|
if(this.mode !== 'text-plain') {
|
|
|
|
|
|
|
|
const buttonRepair = document.createElement('button')
|
|
|
|
const buttonRepair = document.createElement('button')
|
|
|
|
buttonRepair.type = 'button'
|
|
|
|
buttonRepair.type = 'button'
|
|
|
|
buttonRepair.className = 'jsoneditor-repair'
|
|
|
|
buttonRepair.className = 'jsoneditor-repair'
|
|
|
@ -204,10 +199,9 @@ textmode.create = function (container, options = {}) {
|
|
|
|
me._onError(err)
|
|
|
|
me._onError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create undo/redo buttons
|
|
|
|
// create undo/redo buttons
|
|
|
|
if (this.mode === 'code' || this.mode === 'text-plain') {
|
|
|
|
if (this.mode === 'code') {
|
|
|
|
// create undo button
|
|
|
|
// create undo button
|
|
|
|
const undo = document.createElement('button')
|
|
|
|
const undo = document.createElement('button')
|
|
|
|
undo.type = 'button'
|
|
|
|
undo.type = 'button'
|
|
|
@ -240,7 +234,7 @@ textmode.create = function (container, options = {}) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.mode === 'code' || this.mode === 'text-plain') {
|
|
|
|
if (this.mode === 'code') {
|
|
|
|
const poweredBy = document.createElement('a')
|
|
|
|
const poweredBy = document.createElement('a')
|
|
|
|
poweredBy.appendChild(document.createTextNode('powered by ace'))
|
|
|
|
poweredBy.appendChild(document.createTextNode('powered by ace'))
|
|
|
|
poweredBy.href = 'https://ace.c9.io/'
|
|
|
|
poweredBy.href = 'https://ace.c9.io/'
|
|
|
@ -264,7 +258,7 @@ textmode.create = function (container, options = {}) {
|
|
|
|
this.frame.appendChild(this.content)
|
|
|
|
this.frame.appendChild(this.content)
|
|
|
|
this.container.appendChild(this.frame)
|
|
|
|
this.container.appendChild(this.frame)
|
|
|
|
|
|
|
|
|
|
|
|
if (this.mode === 'code' || this.mode === 'text-plain') {
|
|
|
|
if (this.mode === 'code') {
|
|
|
|
this.editorDom = document.createElement('div')
|
|
|
|
this.editorDom = document.createElement('div')
|
|
|
|
this.editorDom.style.height = '100%' // TODO: move to css
|
|
|
|
this.editorDom.style.height = '100%' // TODO: move to css
|
|
|
|
this.editorDom.style.width = '100%' // TODO: move to css
|
|
|
|
this.editorDom.style.width = '100%' // TODO: move to css
|
|
|
@ -277,12 +271,7 @@ textmode.create = function (container, options = {}) {
|
|
|
|
aceEditor.setOptions({ readOnly: isReadOnly })
|
|
|
|
aceEditor.setOptions({ readOnly: isReadOnly })
|
|
|
|
aceEditor.setShowPrintMargin(false)
|
|
|
|
aceEditor.setShowPrintMargin(false)
|
|
|
|
aceEditor.setFontSize('13px')
|
|
|
|
aceEditor.setFontSize('13px')
|
|
|
|
if(this.mode === 'text-plain') {
|
|
|
|
|
|
|
|
aceSession.setMode('ace/mode/text')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
aceSession.setMode('ace/mode/json')
|
|
|
|
aceSession.setMode('ace/mode/json')
|
|
|
|
}
|
|
|
|
|
|
|
|
aceSession.setTabSize(this.indentation)
|
|
|
|
aceSession.setTabSize(this.indentation)
|
|
|
|
aceSession.setUseSoftTabs(true)
|
|
|
|
aceSession.setUseSoftTabs(true)
|
|
|
|
aceSession.setUseWrapMode(true)
|
|
|
|
aceSession.setUseWrapMode(true)
|
|
|
@ -702,24 +691,17 @@ textmode.compact = function () {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
textmode.format = function () {
|
|
|
|
textmode.format = function () {
|
|
|
|
const json = this.get()
|
|
|
|
const json = this.get()
|
|
|
|
if(this.mode !== 'text-plain') {
|
|
|
|
|
|
|
|
const text = JSON.stringify(json, null, this.indentation)
|
|
|
|
const text = JSON.stringify(json, null, this.indentation)
|
|
|
|
this.updateText(text)
|
|
|
|
this.updateText(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
this.updateText(json)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Repair the code in the text editor
|
|
|
|
* Repair the code in the text editor
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
textmode.repair = function () {
|
|
|
|
textmode.repair = function () {
|
|
|
|
if(this.mode !== 'text-plain') {
|
|
|
|
|
|
|
|
const text = this.getText()
|
|
|
|
const text = this.getText()
|
|
|
|
const repairedText = repair(text)
|
|
|
|
const repairedText = repair(text)
|
|
|
|
this.updateText(repairedText)
|
|
|
|
this.updateText(repairedText)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -749,12 +731,7 @@ textmode.resize = function () {
|
|
|
|
* @param {*} json
|
|
|
|
* @param {*} json
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
textmode.set = function (json) {
|
|
|
|
textmode.set = function (json) {
|
|
|
|
if(this.mode !== 'text-plain') {
|
|
|
|
|
|
|
|
this.setText(JSON.stringify(json, null, this.indentation))
|
|
|
|
this.setText(JSON.stringify(json, null, this.indentation))
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
this.setText(json)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -852,9 +829,6 @@ textmode.updateText = function (jsonText) {
|
|
|
|
* Throws an exception when no JSON schema is configured
|
|
|
|
* Throws an exception when no JSON schema is configured
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
textmode.validate = function () {
|
|
|
|
textmode.validate = function () {
|
|
|
|
if(this.mode === 'text-plain') {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let schemaErrors = []
|
|
|
|
let schemaErrors = []
|
|
|
|
let parseErrors = []
|
|
|
|
let parseErrors = []
|
|
|
|
let json
|
|
|
|
let json
|
|
|
@ -1089,11 +1063,5 @@ export const textModeMixins = [
|
|
|
|
mixin: textmode,
|
|
|
|
mixin: textmode,
|
|
|
|
data: 'text',
|
|
|
|
data: 'text',
|
|
|
|
load: load
|
|
|
|
load: load
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mode: 'text-plain',
|
|
|
|
|
|
|
|
mixin: textmode,
|
|
|
|
|
|
|
|
data: 'text',
|
|
|
|
|
|
|
|
load: load
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|