Skip to content

Commit dca8355

Browse files
committed
feat: 文档更新,支持配置生成案例
1 parent 5f1491a commit dca8355

File tree

11 files changed

+348
-8631
lines changed

11 files changed

+348
-8631
lines changed

docs/.vitepress/theme/styles/index.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
width: 100%;
88
max-width: 100% !important;
99
}
10+
11+

docs/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ declare module 'vue' {
1313
ElInput: typeof import('element-plus/es')['ElInput']
1414
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
1515
ElSlider: typeof import('element-plus/es')['ElSlider']
16+
ElTips: typeof import('element-plus/es')['ElTips']
1617
RouterLink: typeof import('vue-router')['RouterLink']
1718
RouterView: typeof import('vue-router')['RouterView']
1819
}

docs/demo/examples/Interactive/components/LangSelect.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<el-form-item label="Lang:" class="mr-4">
33
<ElSelect v-model="value" placeholder="Select" style="width: 240px" size="small" filterable>
4-
<el-option v-for="item in LANG_OPTIONS" :key="item.value" :label="item.label" :value="item.value"
5-
@click.native="onLangChange(item)" />
4+
<el-option v-for="item in LANG_OPTIONS" :disabled="item.disabled" :key="item.value" :label="item.label"
5+
:value="item.value" @click.native="onLangChange(item)" />
66
</ElSelect>
77
</el-form-item>
88

docs/demo/examples/Interactive/components/Layout.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@
4949
<script lang="ts" setup>
5050
import { ElSelect, ElOption, ElFormItem, ElCheckbox } from "element-plus";
5151
52-
import { ref, watch, } from "vue";
52+
import { ref, watch, inject } from "vue";
5353
import { useStore } from "../store";
5454
import { ThemeOption } from "../types";
5555
import { THEME_OPTIONS, } from "../config/themeOptions";
5656
import "../config/theme"
5757
5858
59-
59+
const provideHeight = inject<number>('height')
6060
6161
const store = useStore();
6262
const widthCount = ref(100);
63-
const heightCount = ref(400);
63+
const heightCount = ref(provideHeight || 400);
6464
const widthUnit = ref("%");
6565
const heightUnit = ref("px");
6666
@@ -76,6 +76,8 @@ watch([widthCount, widthUnit], () => {
7676
7777
watch([heightCount, heightUnit], () => {
7878
store.height = `${heightCount.value}${heightUnit.value}`;
79+
}, {
80+
immediate: true
7981
});
8082
8183

docs/demo/examples/Interactive/config/langOptions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ gen ← {' #'[(life ⍣ ⍵) board]}
142142
(gen 1) (gen 2) (gen 3)
143143
`,
144144
},
145+
// 更多语言正在添加中...
146+
{
147+
langPath: "",
148+
value: "moreLang",
149+
label: "More languages are being added...",
150+
code: "",
151+
disabled: true,
152+
}
145153
];
146154

147155
export const DEFAULT_LANG_OPT = LANG_OPTIONS[0];

docs/demo/examples/Interactive/demo.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</template>
55
<script lang="ts" setup>
66
import {
7-
ref, reactive, computed, watch, nextTick,
7+
ref, reactive, computed, watch, nextTick, inject
88
} from "vue";
99
import { Editor, EditorConfiguration } from "codemirror";
1010
import Codemirror from "codemirror-editor-vue3";
@@ -22,8 +22,10 @@ import "codemirror/addon/search/matchesonscrollbar.css";
2222
2323
import "./config/lang";
2424
import { useStore } from "./store";
25-
2625
const store = useStore();
26+
const provideHeight = inject<number>('height')
27+
28+
store.height = String(provideHeight) || store.height || "500";
2729
2830
const cmOptions: EditorConfiguration = reactive({
2931
mode: computed(() => (store.lang == "json" ? "javascript" : store.lang)),

docs/demo/examples/Interactive/index.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import 'element-plus/theme-chalk/dark/css-vars.css'
2929
3030
import { useStore } from "./store";
3131
32+
3233
const store = useStore();
3334
const jsTemp = ref(TemplateRaw.toString());
3435
@@ -37,6 +38,8 @@ watch(
3738
(val, oldVal) => {
3839
let temp = TemplateRaw;
3940
console.log(" watch store", val, oldVal, val.themePath?.length)
41+
42+
const transHeight = typeof val.height == "string" ? val.height : val.height + "";
4043
jsTemp.value = temp
4144
.replace(`%code%`, val.code)
4245
.replace(`%theme%`, val.theme)
@@ -58,4 +61,8 @@ watch(
5861
);
5962
</script>
6063

61-
<style scoped lang="less"></style>
64+
<style scoped lang="less">
65+
:deep(.el-form-item) {
66+
margin-bottom: 0;
67+
}
68+
</style>

docs/demo/examples/Interactive/template.pug

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ import { Editor, EditorConfiguration } from "codemirror";
1515
import Codemirror from "codemirror-editor-vue3";
1616
// mode
1717
%langPath%
18-
1918
%themePath%
20-
21-
2219
const code = ref(`%code%`);
2320
2421
const cmOptions: EditorConfiguration = reactive({
2522
mode: "%lang%",
2623
theme: "%theme%",
27-
readOnly: "%readOnly%",
24+
readOnly: %readOnly%,
2825
lineNumbers: true,
2926
lineWiseCopyCut: true,
3027
gutters: ["CodeMirror-lint-markers"],

docs/demo/examples/Interactive/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type LangOption = {
33
label: string;
44
code: string;
55
langPath: string;
6+
disabled?: boolean;
67
};
78

89
export type LayoutState = {

docs/demo/home.vue

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
11
<template>
2-
<div style="width: 60%; margin-left: 20vw">
3-
<Codemirror v-model:value="code" :options="cmOptions" border :height="300" />
2+
<div style="width: 100%; ">
3+
<Example></Example>
44
</div>
55
</template>
66

77
<script lang="ts" setup>
8-
import { ref } from "vue"
9-
import type { EditorConfiguration } from "codemirror"
10-
import Codemirror from "../../packages/index"
8+
import { provide } from "vue"
9+
import Example from "./examples/Interactive/index.vue"
1110
12-
// language
13-
import "codemirror/mode/javascript/javascript.js"
14-
15-
const code = ref(
16-
`var arr = [3, 10, 6, 2];
17-
for (var i = 0; i < arr.length - 1; i++) {
18-
for (var j = 0; j < arr.length - 1 - i; j++) {
19-
if (arr[j] > arr[j + 1]) {
20-
var num = arr[j];
21-
arr[j] = arr[j + 1];
22-
arr[j + 1] = num;
23-
}
24-
}
25-
}
26-
console.log(arr)`
27-
)
28-
29-
const cmOptions: EditorConfiguration = {
30-
mode: "text/javascript"
31-
}
11+
provide("height", 280)
3212
</script>

0 commit comments

Comments
 (0)