|
@@ -4,6 +4,8 @@ import { basicSetup } from 'codemirror'
|
|
|
import { EditorView } from '@codemirror/view'
|
|
import { EditorView } from '@codemirror/view'
|
|
|
import { EditorState, StateEffect } from '@codemirror/state'
|
|
import { EditorState, StateEffect } from '@codemirror/state'
|
|
|
import { javascript } from '@codemirror/lang-javascript'
|
|
import { javascript } from '@codemirror/lang-javascript'
|
|
|
|
|
+import { sql } from '@codemirror/lang-sql'
|
|
|
|
|
+
|
|
|
import { useId } from '@/hooks'
|
|
import { useId } from '@/hooks'
|
|
|
|
|
|
|
|
export const CodeMirrorTsx = defineComponent({
|
|
export const CodeMirrorTsx = defineComponent({
|
|
@@ -16,6 +18,10 @@ export const CodeMirrorTsx = defineComponent({
|
|
|
bodyJson: {
|
|
bodyJson: {
|
|
|
type: String,
|
|
type: String,
|
|
|
default: ''
|
|
default: ''
|
|
|
|
|
+ },
|
|
|
|
|
+ numberOfRows: {
|
|
|
|
|
+ type: Number,
|
|
|
|
|
+ default: 6
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
setup (props, ctx) {
|
|
setup (props, ctx) {
|
|
@@ -28,13 +34,22 @@ export const CodeMirrorTsx = defineComponent({
|
|
|
const view = ref<EditorView>()
|
|
const view = ref<EditorView>()
|
|
|
|
|
|
|
|
const transDoc = () => {
|
|
const transDoc = () => {
|
|
|
|
|
+ if (props.numberOfRows && !props.bodyJson) {
|
|
|
|
|
+ return new Array(props.numberOfRows).fill(0).map(item => '\n').join('')
|
|
|
|
|
+ }
|
|
|
return props.bodyType === 'javascript' ? props.bodyJson : JSON.stringify(JSON.parse(props.bodyJson), null, '\t')
|
|
return props.bodyType === 'javascript' ? props.bodyJson : JSON.stringify(JSON.parse(props.bodyJson), null, '\t')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const createView = () => {
|
|
const createView = () => {
|
|
|
|
|
+ const extensions = [basicSetup]
|
|
|
|
|
+ if (props.bodyType === 'javascript') {
|
|
|
|
|
+ extensions.push(javascript())
|
|
|
|
|
+ } else if (props.bodyType === 'sql') {
|
|
|
|
|
+ extensions.push(sql())
|
|
|
|
|
+ }
|
|
|
const editorState = EditorState.create({
|
|
const editorState = EditorState.create({
|
|
|
doc: transDoc(),
|
|
doc: transDoc(),
|
|
|
- extensions: [basicSetup, javascript()]
|
|
|
|
|
|
|
+ extensions: extensions
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
view.value = new EditorView({
|
|
view.value = new EditorView({
|