| | |
| | | <template> |
| | | <div class="relative !h-full w-full overflow-hidden" ref="el"></div> |
| | | <div |
| | | class="relative !h-full w-full overflow-hidden" |
| | | :class="{ 'ant-input': props.bordered, 'css-dev-only-do-not-override-kqecok': props.bordered }" |
| | | ref="el" |
| | | ></div> |
| | | </template> |
| | | |
| | | <script lang="ts" setup> |
| | |
| | | import type { Nullable } from '@vben/types'; |
| | | import { useWindowSizeFn } from '@vben/hooks'; |
| | | import { useDebounceFn } from '@vueuse/core'; |
| | | import { useAppStore } from '/@/store/modules/app'; |
| | | import { useAppStore } from '@/store/modules/app'; |
| | | import CodeMirror from 'codemirror'; |
| | | import { MODE } from './../typing'; |
| | | import type { EditorConfiguration } from 'codemirror'; |
| | | import { MODE, parserDynamicImport } from './../typing'; |
| | | // css |
| | | import './codemirror.css'; |
| | | import 'codemirror/lib/codemirror.css'; |
| | | import 'codemirror/theme/idea.css'; |
| | | import 'codemirror/theme/material-palenight.css'; |
| | | // modes |
| | | import 'codemirror/mode/javascript/javascript'; |
| | | import 'codemirror/mode/css/css'; |
| | | import 'codemirror/mode/htmlmixed/htmlmixed'; |
| | | |
| | | // 代码段折叠功能 |
| | | import 'codemirror/addon/fold/foldgutter.css'; |
| | | import 'codemirror/addon/fold/foldcode.js'; |
| | | import 'codemirror/addon/fold/foldgutter'; |
| | | import 'codemirror/addon/fold/brace-fold'; |
| | | import 'codemirror/addon/fold/comment-fold'; |
| | | import 'codemirror/addon/fold/markdown-fold'; |
| | | import 'codemirror/addon/fold/xml-fold'; |
| | | import 'codemirror/addon/fold/indent-fold'; |
| | | |
| | | const props = defineProps({ |
| | | mode: { |
| | |
| | | }, |
| | | value: { type: String, default: '' }, |
| | | readonly: { type: Boolean, default: false }, |
| | | bordered: { type: Boolean, default: false }, |
| | | config: { type: Object as PropType<EditorConfiguration>, default: () => {} }, |
| | | }); |
| | | |
| | | const emit = defineEmits(['change']); |
| | |
| | | { flush: 'post' }, |
| | | ); |
| | | |
| | | watchEffect(() => { |
| | | watchEffect(async () => { |
| | | await parserDynamicImport(props.mode)(); |
| | | editor?.setOption('mode', props.mode); |
| | | }); |
| | | |
| | |
| | | autoCloseBrackets: true, |
| | | autoCloseTags: true, |
| | | foldGutter: true, |
| | | gutters: ['CodeMirror-linenumbers'], |
| | | gutters: ['CodeMirror-lint-markers', 'CodeMirror-linenumbers', 'CodeMirror-foldgutter'], |
| | | }; |
| | | |
| | | editor = CodeMirror(el.value!, { |
| | |
| | | lineWrapping: true, |
| | | lineNumbers: true, |
| | | ...addonOptions, |
| | | ...props.config, |
| | | }); |
| | | editor?.setValue(props.value); |
| | | setTheme(); |