Skip to content

Commit 36769c5

Browse files
feat: 添加codeEditor组件 (DevCloudFE#1587)
1 parent ff2dfb5 commit 36769c5

File tree

8 files changed

+690
-1
lines changed

8 files changed

+690
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { App } from 'vue';
2+
import CodeEditor from './src/code-editor';
3+
export * from './src/code-editor-types';
4+
5+
export { CodeEditor };
6+
7+
export default {
8+
title: 'Code Editor 代码编辑器',
9+
category: '数据录入',
10+
status: '100%',
11+
install(app: App): void {
12+
app.component(CodeEditor.name, CodeEditor);
13+
},
14+
};
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { ExtractPropTypes, PropType, Ref } from "vue";
2+
3+
export type Mode = 'normal' | 'diff' | 'review';
4+
export type Theme = 'light' | 'dark';
5+
6+
export interface Decoration {
7+
lineNumber: number;
8+
icon?: string;
9+
customClasses?: string;
10+
glyphClassName?: string;
11+
}
12+
export interface Comment {
13+
lineNumber: number;
14+
isExpanded: boolean;
15+
domNode?: HTMLElement;
16+
heightInPx?: number;
17+
allowEditorOverflow?: boolean;
18+
offserLeft?: number;
19+
}
20+
21+
export const codeEditorProps = {
22+
modelValue: {
23+
type: String,
24+
default: ''
25+
},
26+
mode: {
27+
type: String as PropType<Mode>,
28+
default: 'normal',
29+
},
30+
originalText: {
31+
type: String,
32+
default: ''
33+
},
34+
theme: {
35+
type: String as PropType<Theme>,
36+
default: 'light'
37+
},
38+
autoHeight: {
39+
type: Boolean,
40+
default: false
41+
},
42+
refreshAll: {
43+
type: Boolean,
44+
default: false
45+
},
46+
offsetLeft: {
47+
type: Number
48+
},
49+
addCommentIcon: {
50+
type: String,
51+
default: ''
52+
},
53+
expandCommentIcon: {
54+
type: String,
55+
default: ''
56+
},
57+
options: {
58+
type: Object,
59+
default: () => ({})
60+
},
61+
mouseTargetTypes: {
62+
type: Array as PropType<number[]>,
63+
default: () => [2, 4]
64+
},
65+
editorDecorations: {
66+
type: Array as PropType<Decoration[]>,
67+
default: () => []
68+
},
69+
comments: {
70+
type: Array as PropType<Comment[]>,
71+
default: () => []
72+
}
73+
}
74+
75+
export type CodeEditorProps = ExtractPropTypes<typeof codeEditorProps>;
76+
77+
export interface UseCodeEditor {
78+
editorEl: Ref;
79+
}
80+
81+
export interface PositionInfo {
82+
top?: number;
83+
height?: number;
84+
}
85+
86+
export interface LayoutInfo extends PositionInfo {
87+
minimapWidth?: number;
88+
offsetLeft?: number;
89+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.dp-code-editor {
2+
display: block;
3+
position: relative;
4+
width: 100%;
5+
height: 100%;
6+
7+
div.icon-pointer {
8+
cursor: pointer;
9+
}
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineComponent } from 'vue';
2+
import type { SetupContext } from 'vue';
3+
import { codeEditorProps, CodeEditorProps } from './code-editor-types';
4+
import { useCodeEditor } from './composables/use-code-editor';
5+
import './code-editor.scss'
6+
7+
export default defineComponent({
8+
name: 'DpCodeEditor',
9+
props: codeEditorProps,
10+
emits: ['update: modelValue', 'afterEditorInit', 'click'],
11+
setup(props: codeEditorProps, ctx: SetupContext) {
12+
const { editorEl } = useCodeEditor(props, ctx);
13+
14+
return () => <div ref={editorEl} class="devui-code-editor"></div>
15+
}
16+
})

0 commit comments

Comments
 (0)