fix: util code editor

parent 47ed7b37
...@@ -22,7 +22,7 @@ module.exports = { ...@@ -22,7 +22,7 @@ module.exports = {
// Uncomment any of the lines below to choose desired strictness, // Uncomment any of the lines below to choose desired strictness,
// but leave only one uncommented! // but leave only one uncommented!
// See https://eslint.vuejs.org/rules/#available-rules // See https://eslint.vuejs.org/rules/#available-rules
'plugin:vue/vue3-essential', // Priority A: Essential (Error Prevention) // 'plugin:vue/vue3-essential', // Priority A: Essential (Error Prevention)
'plugin:vue/vue3-strongly-recommended', // Priority B: Strongly Recommended (Improving Readability) 'plugin:vue/vue3-strongly-recommended', // Priority B: Strongly Recommended (Improving Readability)
// 'plugin:vue/vue3-recommended', // Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead) // 'plugin:vue/vue3-recommended', // Priority C: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead)
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
"lint": "eslint --ext .js,.vue ./" "lint": "eslint --ext .js,.vue ./"
}, },
"dependencies": { "dependencies": {
"@apollo/client": "3.6.4", "@apollo/client": "3.6.5",
"@codemirror/autocomplete": "0.20.1", "@codemirror/autocomplete": "0.20.2",
"@codemirror/basic-setup": "0.20.0", "@codemirror/basic-setup": "0.20.0",
"@codemirror/closebrackets": "0.19.2", "@codemirror/closebrackets": "0.19.2",
"@codemirror/commands": "0.20.0", "@codemirror/commands": "0.20.0",
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
"apollo-upload-client": "17.0.0", "apollo-upload-client": "17.0.0",
"browser-fs-access": "0.29.5", "browser-fs-access": "0.29.5",
"clipboard": "2.0.11", "clipboard": "2.0.11",
"filesize": "8.0.7", "filesize": "9.0.0",
"filesize-parser": "1.5.0", "filesize-parser": "1.5.0",
"graphql": "16.5.0", "graphql": "16.5.0",
"graphql-tag": "2.12.6", "graphql-tag": "2.12.6",
...@@ -71,10 +71,10 @@ ...@@ -71,10 +71,10 @@
"luxon": "2.4.0", "luxon": "2.4.0",
"pinia": "2.0.14", "pinia": "2.0.14",
"pug": "3.0.2", "pug": "3.0.2",
"quasar": "2.7.0", "quasar": "2.7.1",
"tippy.js": "6.3.7", "tippy.js": "6.3.7",
"uuid": "8.3.2", "uuid": "8.3.2",
"v-network-graph": "0.5.16", "v-network-graph": "0.5.17",
"vue": "3.2.31", "vue": "3.2.31",
"vue-codemirror": "5.0.1", "vue-codemirror": "5.0.1",
"vue-i18n": "9.1.10", "vue-i18n": "9.1.10",
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
}, },
"devDependencies": { "devDependencies": {
"@intlify/vite-plugin-vue-i18n": "3.4.0", "@intlify/vite-plugin-vue-i18n": "3.4.0",
"@quasar/app-vite": "1.0.0", "@quasar/app-vite": "1.0.1",
"@types/lodash": "4.14.182", "@types/lodash": "4.14.182",
"autoprefixer": "10.4.7", "autoprefixer": "10.4.7",
"eslint": "8.16.0", "eslint": "8.16.0",
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
"eslint-plugin-import": "2.26.0", "eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.2.0", "eslint-plugin-n": "15.2.0",
"eslint-plugin-promise": "6.0.0", "eslint-plugin-promise": "6.0.0",
"eslint-plugin-vue": "8.7.1" "eslint-plugin-vue": "9.0.1"
}, },
"engines": { "engines": {
"node": "^18 || ^16", "node": "^18 || ^16",
......
...@@ -414,9 +414,10 @@ q-layout(view='hHh lpR fFf', container) ...@@ -414,9 +414,10 @@ q-layout(view='hHh lpR fFf', container)
q-item q-item
q-item-section q-item-section
q-no-ssr(:placeholder='t(`common.loading`)') q-no-ssr(:placeholder='t(`common.loading`)')
codemirror.metadata-codemirror( util-code-editor.admin-theme-cm(
v-model='metadata' v-model='metadata'
:extensions='[json()]' language='json'
:min-height='500'
) )
q-page(v-else-if='route.params.section === `operations`') q-page(v-else-if='route.params.section === `operations`')
...@@ -504,9 +505,7 @@ import { useAdminStore } from 'src/stores/admin' ...@@ -504,9 +505,7 @@ import { useAdminStore } from 'src/stores/admin'
import { useDataStore } from 'src/stores/data' import { useDataStore } from 'src/stores/data'
import UserChangePwdDialog from './UserChangePwdDialog.vue' import UserChangePwdDialog from './UserChangePwdDialog.vue'
import { Codemirror } from 'vue-codemirror' import UtilCodeEditor from './UtilCodeEditor.vue'
import { json } from '@codemirror/lang-json'
// import { oneDark } from '@codemirror/theme-one-dark'
// QUASAR // QUASAR
...@@ -822,8 +821,7 @@ onMounted(() => { ...@@ -822,8 +821,7 @@ onMounted(() => {
<style lang="scss" scoped> <style lang="scss" scoped>
.metadata-codemirror { .metadata-codemirror {
&:deep(.cm-editor) { &:deep(.cm-editor) {
height: 150px; min-height: 150px;
min-height: 100px;
border-radius: 5px; border-radius: 5px;
border: 1px solid #CCC; border: 1px solid #CCC;
} }
......
<template lang="pug"> <template lang="pug">
.util-code-editor( .util-code-editor(
ref='editor' ref='editorRef'
) )
</template> </template>
<script> <script setup>
/* eslint no-unused-vars: "off" */ /* eslint no-unused-vars: "off" */
// import { keymap, EditorView } from '@codemirror/view' import { keymap, EditorView, lineNumbers } from '@codemirror/view'
// import { EditorState } from '@codemirror/state' import { EditorState } from '@codemirror/state'
// import { history, historyKeymap } from '@codemirror/history' import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands'
// import { defaultKeymap, indentWithTab } from '@codemirror/commands' import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language'
// import { lineNumbers } from '@codemirror/gutter' import { ref, shallowRef, onBeforeMount, onMounted, watch } from 'vue'
// import { defaultHighlightStyle } from '@codemirror/highlight' import { json } from '@codemirror/lang-json'
export default { // PROPS
props: {
const props = defineProps({
modelValue: { modelValue: {
type: String, type: String,
default: '' default: ''
...@@ -28,26 +29,35 @@ export default { ...@@ -28,26 +29,35 @@ export default {
type: Number, type: Number,
default: 150 default: 150
} }
}, })
emits: ['update:modelValue'],
data () { // EMITS
return {
editor: null const emit = defineEmits([
} 'update:modelValue'
}, ])
watch: {
modelValue (newVal) { // STATE
const editor = shallowRef(null)
const editorRef = ref(null)
// WATCHERS
watch(() => props.modelValue, (newVal) => {
// Ignore loopback changes while editing // Ignore loopback changes while editing
if (!this.editor.hasFocus) { if (!editor.value.hasFocus) {
this.editor.dispatch({ editor.value.dispatch({
changes: { from: 0, to: this.editor.state.length, insert: newVal } changes: { from: 0, to: editor.value.state.length, insert: newVal }
}) })
} }
} })
},
async mounted () { // MOUNTED
onMounted(async () => {
let langModule = null let langModule = null
switch (this.language) { switch (props.language) {
case 'css': { case 'css': {
langModule = (await import('@codemirror/lang-css')).css langModule = (await import('@codemirror/lang-css')).css
break break
...@@ -69,34 +79,34 @@ export default { ...@@ -69,34 +79,34 @@ export default {
break break
} }
} }
// this.editor = new EditorView({ editor.value = new EditorView({
// state: EditorState.create({ state: EditorState.create({
// doc: this.modelValue, doc: props.modelValue,
// extensions: [ extensions: [
// // history() history(),
// // keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]) keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
// lineNumbers() lineNumbers(),
// // EditorView.theme({ EditorView.theme({
// // '.cm-content, .cm-gutter': { minHeight: `${this.minHeight}px` } '.cm-content, .cm-gutter': { minHeight: `${props.minHeight}px` }
// // }), }),
// // ...langModule && [langModule()], ...langModule && [langModule()],
// // defaultHighlightStyle, syntaxHighlighting(defaultHighlightStyle),
// // EditorView.updateListener.of(v => { EditorView.updateListener.of(v => {
// // if (v.docChanged) { if (v.docChanged) {
// // this.$emit('update:modelValue', v.state.doc.toString()) emit('update:modelValue', v.state.doc.toString())
// // }
// // })
// ]
// }),
// parent: this.$refs.editor
// })
},
beforeUnmount () {
if (this.editor) {
this.editor.destroy()
} }
})
]
}),
parent: editorRef.value
})
})
onBeforeMount(() => {
if (editor.value) {
editor.value.destroy()
} }
} })
</script> </script>
<style lang="scss"> <style lang="scss">
......
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment