Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions LICENSE-binary
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,16 @@ is auto-generated by `pnpm licenses list --prod`.
├────────────────────────────────────┼──────────────┤
│ typescript │ Apache-2.0 │
├────────────────────────────────────┼──────────────┤
│ moo │ BSD-3-Clause │
├────────────────────────────────────┼──────────────┤
│ normalize-wheel-es │ BSD-3-Clause │
├────────────────────────────────────┼──────────────┤
│ source-map │ BSD-3-Clause │
├────────────────────────────────────┼──────────────┤
│ source-map-js │ BSD-3-Clause │
├────────────────────────────────────┼──────────────┤
│ railroad-diagrams │ CC0-1.0 │
├────────────────────────────────────┼──────────────┤
│ picocolors │ ISC │
├────────────────────────────────────┼──────────────┤
│ @babel/helper-string-parser │ MIT │
Expand Down Expand Up @@ -459,6 +463,8 @@ is auto-generated by `pnpm licenses list --prod`.
├────────────────────────────────────┼──────────────┤
│ combined-stream │ MIT │
├────────────────────────────────────┼──────────────┤
│ commander │ MIT │
├────────────────────────────────────┼──────────────┤
│ csstype │ MIT │
├────────────────────────────────────┼──────────────┤
│ date-fns │ MIT │
Expand All @@ -467,6 +473,8 @@ is auto-generated by `pnpm licenses list --prod`.
├────────────────────────────────────┼──────────────┤
│ delayed-stream │ MIT │
├────────────────────────────────────┼──────────────┤
│ discontinuous-range │ MIT │
├────────────────────────────────────┼──────────────┤
│ element-plus │ MIT │
├────────────────────────────────────┼──────────────┤
│ escape-html │ MIT │
Expand All @@ -477,6 +485,8 @@ is auto-generated by `pnpm licenses list --prod`.
├────────────────────────────────────┼──────────────┤
│ form-data │ MIT │
├────────────────────────────────────┼──────────────┤
│ get-stdin │ MIT │
├────────────────────────────────────┼──────────────┤
│ lodash │ MIT │
├────────────────────────────────────┼──────────────┤
│ lodash-es │ MIT │
Expand All @@ -491,16 +501,26 @@ is auto-generated by `pnpm licenses list --prod`.
├────────────────────────────────────┼──────────────┤
│ mime-types │ MIT │
├────────────────────────────────────┼──────────────┤
│ monaco-editor │ MIT │
├────────────────────────────────────┼──────────────┤
│ nanoid │ MIT │
├────────────────────────────────────┼──────────────┤
│ nearley │ MIT │
├────────────────────────────────────┼──────────────┤
│ pinia │ MIT │
├────────────────────────────────────┼──────────────┤
│ pinia-plugin-persistedstate │ MIT │
├────────────────────────────────────┼──────────────┤
│ postcss │ MIT │
├────────────────────────────────────┼──────────────┤
│ randexp │ MIT │
├────────────────────────────────────┼──────────────┤
│ ret │ MIT │
├────────────────────────────────────┼──────────────┤
│ sourcemap-codec │ MIT │
├────────────────────────────────────┼──────────────┤
│ sql-formatter │ MIT │
├────────────────────────────────────┼──────────────┤
│ to-fast-properties │ MIT │
├────────────────────────────────────┼──────────────┤
│ vue │ MIT │
Expand All @@ -510,4 +530,6 @@ is auto-generated by `pnpm licenses list --prod`.
│ vue-i18n │ MIT │
├────────────────────────────────────┼──────────────┤
│ vue-router │ MIT │
├────────────────────────────────────┼──────────────┤
│ argparse │ Python-2.0 │
└────────────────────────────────────┴──────────────┘
2 changes: 2 additions & 0 deletions kyuubi-server/web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"axios": "^0.27.2",
"date-fns": "^2.29.3",
"element-plus": "^2.2.12",
"monaco-editor": "^0.44.0",
"pinia": "^2.0.18",
"pinia-plugin-persistedstate": "^2.1.1",
"sql-formatter": "^13.0.1",
"swagger-ui-dist": "^4.9.1",
"vue": "^3.2.37",
"vue-i18n": "^9.2.2",
Expand Down
72 changes: 67 additions & 5 deletions kyuubi-server/web-ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 149 additions & 0 deletions kyuubi-server/web-ui/src/components/monaco-editor/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->

<template>
<div ref="codeEditBox" style="height: 100%" />
</template>

<script lang="ts" setup>
import * as monaco from 'monaco-editor'
import { format } from 'sql-formatter'
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import { editorProps } from './type'
import { useEditorStore } from '@/pinia/editor'
import { ref, toRaw, watch, onBeforeUnmount, onMounted } from 'vue'

// @ts-ignore: worker
self.MonacoEnvironment = {
getWorker() {
return new EditorWorker()
}
}

const props = defineProps(editorProps)
const emit = defineEmits([
'update:modelValue',
'change',
'editorMounted',
'editorSave'
])

const editorStore = useEditorStore()
const monacoEditorThemeRef = ref(
editorStore.getCurrentTheme === 'dark' ? 'vs-dark' : 'vs'
)
let editor: monaco.editor.IStandaloneCodeEditor
const codeEditBox = ref()
const init = () => {
monaco.languages.registerCompletionItemProvider('sql', {
provideCompletionItems: function (model: any, position: any) {
const word = model.getWordUntilPosition(position)
const range = {
startLineNumber: position.lineNumber,
endLineNumber: position.lineNumber,
startColumn: word.startColumn,
endColumn: word.endColumn
}
const suggestions = []
const keywords = [
'SELECT',
'FROM',
'WHERE',
'AND',
'OR',
'LIMIT',
'ORDER BY',
'GROUP BY'
]
for (const i in keywords) {
suggestions.push({
label: keywords[i],
kind: monaco.languages.CompletionItemKind['Function'],
insertText: keywords[i],
detail: '',
range: range
})
}
return {
suggestions: suggestions
}
}
})

editor = monaco.editor.create(codeEditBox.value, {
value: props.modelValue,
language: props.language,
theme: monacoEditorThemeRef.value,
...props.options
})

editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function () {
emit('editorSave')
})

editor.setValue(format(toRaw(editor).getValue()))

editor.onDidChangeModelContent(() => {
const value = editor.getValue()
emit('update:modelValue', value)
emit('change', value)
})
emit('editorMounted', editor)
}
watch(
() => props.modelValue,
(newValue) => {
if (editor) {
const value = editor.getValue()
if (newValue !== value) {
editor.setValue(newValue)
editor.setValue(format(toRaw(editor).getValue()))
}
}
}
)
watch(
() => props.options,
(newValue) => {
editor.updateOptions(newValue)
},
{ deep: true }
)
watch(
() => props.language,
(newValue) => {
monaco.editor.setModelLanguage(editor.getModel()!, newValue)
}
)
watch(
() => editorStore.getCurrentTheme,
() => {
editor?.dispose()
monacoEditorThemeRef.value =
editorStore.getCurrentTheme === 'dark' ? 'vs-dark' : 'vs'
init()
}
)

onBeforeUnmount(() => {
editor.dispose()
})
onMounted(() => {
init()
})
</script>
Loading