@aiao/code-editor-vue 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -12
- package/dist/CodeEditor.vue.d.ts +22 -28
- package/dist/CodeEditor.vue.d.ts.map +1 -1
- package/dist/code-editor.types.d.ts +29 -0
- package/dist/code-editor.types.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +7 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +214 -94
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -1,30 +1,82 @@
|
|
|
1
1
|
# @aiao/code-editor-vue
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## 功能特性
|
|
6
|
-
|
|
7
|
-
- **Vue 组件**: 开箱即用的 Vue 3 组件
|
|
8
|
-
- **v-model 支持**: 支持 v-model 双向绑定
|
|
9
|
-
- **主题支持**: 支持亮色和暗色主题
|
|
3
|
+
基于 CodeMirror 6 的 Vue 3 代码编辑器组件。
|
|
10
4
|
|
|
11
5
|
## 安装
|
|
12
6
|
|
|
13
7
|
```bash
|
|
14
|
-
|
|
15
|
-
# 或
|
|
16
|
-
pnpm add @aiao/code-editor @aiao/code-editor-vue
|
|
8
|
+
pnpm add @aiao/code-editor-vue
|
|
17
9
|
```
|
|
18
10
|
|
|
19
11
|
## 使用
|
|
20
12
|
|
|
21
13
|
```vue
|
|
22
|
-
<script
|
|
14
|
+
<script lang="ts" setup>
|
|
15
|
+
import { ref } from 'vue';
|
|
23
16
|
import { CodeEditor } from '@aiao/code-editor-vue';
|
|
17
|
+
import '@aiao/code-editor-vue/style.css';
|
|
18
|
+
|
|
19
|
+
const code = ref('const answer = 42;');
|
|
24
20
|
</script>
|
|
25
21
|
|
|
26
22
|
<template>
|
|
27
|
-
<CodeEditor
|
|
23
|
+
<CodeEditor
|
|
24
|
+
v-model:value="code"
|
|
25
|
+
@blur="console.log('blur')"
|
|
26
|
+
@focus="console.log('focus')"
|
|
27
|
+
language="typescript"
|
|
28
|
+
theme="dark"
|
|
29
|
+
/>
|
|
28
30
|
</template>
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
`v-model:value` 同步 `value` / `update:value`。`change` 只在用户修改文档时触发,外部 `value` 更新不会反向触发。
|
|
34
|
+
|
|
35
|
+
## Props
|
|
36
|
+
|
|
37
|
+
| Prop | 类型 | 默认值 | 行为 |
|
|
38
|
+
| --------------------- | ------------------------------------------ | ------------------- | -------------------- |
|
|
39
|
+
| `value` | `string` | `''` | 动态同步 |
|
|
40
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | 动态重配置 |
|
|
41
|
+
| `language` | `string` | `'sql'` | 动态异步加载 |
|
|
42
|
+
| `languages` | `readonly CodeEditorLanguageDescription[]` | `SUPPORT_LANGUAGES` | 动态替换语言列表 |
|
|
43
|
+
| `placeholder` | `string` | `''` | 动态重配置 |
|
|
44
|
+
| `readonly` | `boolean` | `false` | 动态重配置 |
|
|
45
|
+
| `disabled` | `boolean` | `false` | 动态重配置 |
|
|
46
|
+
| `setup` | `'basic' \| 'minimal'` | `'basic'` | 动态重配置 |
|
|
47
|
+
| `indentWithTab` | `boolean` | `false` | 动态重配置 |
|
|
48
|
+
| `indentUnit` | `string` | `' '` | 动态重配置 |
|
|
49
|
+
| `lineWrapping` | `boolean` | `false` | 动态重配置 |
|
|
50
|
+
| `highlightWhitespace` | `boolean` | `false` | 动态重配置 |
|
|
51
|
+
| `autoFocus` | `boolean` | `false` | 仅初始化时读取 |
|
|
52
|
+
| `root` | `Document \| ShadowRoot` | `undefined` | 仅初始化时传给编辑器 |
|
|
53
|
+
|
|
54
|
+
空字符串或 `plaintext` 会清空语言扩展。未知语言和加载失败会报告错误并保持纯文本状态。快速切换语言时,只有最后一次请求可以更新当前编辑器。
|
|
55
|
+
|
|
56
|
+
自定义语言列表使用核心包的公开类型:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import type { CodeEditorLanguageDescription } from '@aiao/code-editor';
|
|
60
|
+
|
|
61
|
+
declare const myLanguage: CodeEditorLanguageDescription;
|
|
62
|
+
const languages: readonly CodeEditorLanguageDescription[] = [myLanguage];
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<CodeEditor v-model:value="code" :languages="languages" language="my-language" />
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Events
|
|
70
|
+
|
|
71
|
+
| 事件 | 参数 | 触发时机 |
|
|
72
|
+
| -------------- | ----------------- | ---------------------- |
|
|
73
|
+
| `update:value` | `(value: string)` | 用户修改文档 |
|
|
74
|
+
| `change` | `(value: string)` | 用户修改文档 |
|
|
75
|
+
| `focus` | `()` | 编辑器内容区域获得焦点 |
|
|
76
|
+
| `blur` | `()` | 编辑器内容区域失去焦点 |
|
|
77
|
+
|
|
78
|
+
## 公开类型
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import type { CodeEditorEmits, CodeEditorProps, CodeEditorSetup, CodeEditorTheme } from '@aiao/code-editor-vue';
|
|
82
|
+
```
|
package/dist/CodeEditor.vue.d.ts
CHANGED
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
language?: string;
|
|
5
|
-
placeholder?: string;
|
|
6
|
-
readonly?: boolean;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
setup?: 'basic' | 'minimal';
|
|
9
|
-
indentWithTab?: boolean;
|
|
10
|
-
indentUnit?: string;
|
|
11
|
-
lineWrapping?: boolean;
|
|
12
|
-
highlightWhitespace?: boolean;
|
|
13
|
-
};
|
|
14
|
-
declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
15
|
-
"update:value": (value: string) => any;
|
|
1
|
+
import { CodeEditorProps, CodeEditorSetup } from './code-editor.types.js';
|
|
2
|
+
declare const __VLS_export: import('vue').DefineComponent<CodeEditorProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
3
|
+
blur: () => any;
|
|
16
4
|
change: (value: string) => any;
|
|
17
|
-
|
|
18
|
-
"
|
|
5
|
+
focus: () => any;
|
|
6
|
+
"update:value": (value: string) => any;
|
|
7
|
+
}, string, import('vue').PublicProps, Readonly<CodeEditorProps> & Readonly<{
|
|
8
|
+
onBlur?: (() => any) | undefined;
|
|
19
9
|
onChange?: ((value: string) => any) | undefined;
|
|
10
|
+
onFocus?: (() => any) | undefined;
|
|
11
|
+
"onUpdate:value"?: ((value: string) => any) | undefined;
|
|
20
12
|
}>, {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
readonly: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
readonly autoFocus: boolean;
|
|
14
|
+
readonly disabled: boolean;
|
|
15
|
+
readonly highlightWhitespace: boolean;
|
|
16
|
+
readonly indentUnit: string;
|
|
17
|
+
readonly indentWithTab: boolean;
|
|
18
|
+
readonly language: string;
|
|
19
|
+
readonly languages: readonly import('@aiao/code-editor').CodeEditorLanguageDescription[];
|
|
20
|
+
readonly lineWrapping: boolean;
|
|
21
|
+
readonly placeholder: string;
|
|
22
|
+
readonly readonly: boolean;
|
|
23
|
+
readonly setup: CodeEditorSetup;
|
|
24
|
+
readonly theme: import('@aiao/code-editor').CodeEditorTheme;
|
|
25
|
+
readonly value: string;
|
|
32
26
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
33
27
|
declare const _default: typeof __VLS_export;
|
|
34
28
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.vue.d.ts","sourceRoot":"","sources":["../src/CodeEditor.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeEditor.vue.d.ts","sourceRoot":"","sources":["../src/CodeEditor.vue"],"names":[],"mappings":"AAuQA,OAAO,KAAK,EAAmB,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAkQhG,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;6EAIhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CodeEditorLanguageDescription, CodeEditorTheme } from '@aiao/code-editor';
|
|
2
|
+
/** CodeMirror 预置扩展集合。 */
|
|
3
|
+
export type CodeEditorSetup = 'basic' | 'minimal' | null;
|
|
4
|
+
/** Vue CodeEditor 的公开属性。 */
|
|
5
|
+
export interface CodeEditorProps {
|
|
6
|
+
readonly autoFocus?: boolean;
|
|
7
|
+
readonly disabled?: boolean;
|
|
8
|
+
readonly highlightWhitespace?: boolean;
|
|
9
|
+
readonly indentUnit?: string;
|
|
10
|
+
readonly indentWithTab?: boolean;
|
|
11
|
+
readonly language?: string;
|
|
12
|
+
readonly languages?: readonly CodeEditorLanguageDescription[];
|
|
13
|
+
readonly lineWrapping?: boolean;
|
|
14
|
+
readonly placeholder?: string;
|
|
15
|
+
readonly readonly?: boolean;
|
|
16
|
+
readonly root?: Document | ShadowRoot;
|
|
17
|
+
readonly setup?: CodeEditorSetup;
|
|
18
|
+
readonly theme?: CodeEditorTheme;
|
|
19
|
+
readonly value?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Vue CodeEditor 的公开事件。 */
|
|
22
|
+
export interface CodeEditorEmits {
|
|
23
|
+
blur: [];
|
|
24
|
+
change: [value: string];
|
|
25
|
+
focus: [];
|
|
26
|
+
'update:value': [value: string];
|
|
27
|
+
}
|
|
28
|
+
export type { CodeEditorTheme } from '@aiao/code-editor';
|
|
29
|
+
//# sourceMappingURL=code-editor.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-editor.types.d.ts","sourceRoot":"","sources":["../src/code-editor.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAExF,yBAAyB;AACzB,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;AAEzD,4BAA4B;AAC5B,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IACvC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,6BAA6B,EAAE,CAAC;IAC9D,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,4BAA4B;AAC5B,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,EAAE,CAAC;IACT,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACxB,KAAK,EAAE,EAAE,CAAC;IACV,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
.cm-editor{height:100%}.cm-scroller{overflow:auto}
|
|
1
|
+
.aiao-code-editor[data-v-9b1829ca]{width:100%;height:100%;font-size:.875rem;display:block;overflow:hidden}.aiao-code-editor[data-v-9b1829ca] .cm-editor{height:100%}.aiao-code-editor[data-v-9b1829ca] .cm-scroller{overflow:auto}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @aiao/code-editor-vue
|
|
3
3
|
*
|
|
4
|
-
* Vue CodeMirror 代码编辑器组件
|
|
5
|
-
*
|
|
6
4
|
* @example
|
|
7
5
|
* ```vue
|
|
8
|
-
* <
|
|
9
|
-
* <CodeEditor
|
|
10
|
-
* v-model:value="code"
|
|
11
|
-
* language="typescript"
|
|
12
|
-
* theme="dark"
|
|
13
|
-
* @change="onCodeChange"
|
|
14
|
-
* />
|
|
15
|
-
* </template>
|
|
16
|
-
*
|
|
17
|
-
* <script setup>
|
|
6
|
+
* <script setup lang="ts">
|
|
18
7
|
* import { CodeEditor } from '@aiao/code-editor-vue';
|
|
8
|
+
* import '@aiao/code-editor-vue/style.css';
|
|
19
9
|
* </script>
|
|
10
|
+
*
|
|
11
|
+
* <template>
|
|
12
|
+
* <CodeEditor v-model:value="code" language="typescript" />
|
|
13
|
+
* </template>
|
|
20
14
|
* ```
|
|
21
15
|
*/
|
|
16
|
+
export type { CodeEditorEmits, CodeEditorProps, CodeEditorSetup, CodeEditorTheme } from './code-editor.types.js';
|
|
22
17
|
export { default as CodeEditor } from './CodeEditor.vue';
|
|
23
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACjH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,131 +1,251 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SUPPORT_LANGUAGES as
|
|
3
|
-
import { indentWithTab as
|
|
4
|
-
import {
|
|
5
|
-
import { Annotation as
|
|
6
|
-
import { oneDark as
|
|
7
|
-
import { EditorView as
|
|
8
|
-
import { basicSetup as
|
|
9
|
-
//#
|
|
10
|
-
|
|
11
|
-
var x = /* @__PURE__ */ t({
|
|
1
|
+
import { computed as e, createElementBlock as t, defineComponent as n, mergeProps as r, onMounted as i, onUnmounted as a, openBlock as o, ref as s, shallowRef as c, watch as l } from "vue";
|
|
2
|
+
import { SUPPORT_LANGUAGES as u, findLanguageByName as d } from "@aiao/code-editor";
|
|
3
|
+
import { indentWithTab as f } from "@codemirror/commands";
|
|
4
|
+
import { indentUnit as p } from "@codemirror/language";
|
|
5
|
+
import { Annotation as m, Compartment as h, EditorState as g } from "@codemirror/state";
|
|
6
|
+
import { oneDark as _ } from "@codemirror/theme-one-dark";
|
|
7
|
+
import { EditorView as v, highlightWhitespace as y, keymap as b, placeholder as x } from "@codemirror/view";
|
|
8
|
+
import { basicSetup as S, minimalSetup as C } from "codemirror";
|
|
9
|
+
//#region src/CodeEditor.vue?vue&type=script&setup=true&lang.ts
|
|
10
|
+
var w = /*@__PURE__*/ n({
|
|
12
11
|
__name: "CodeEditor",
|
|
13
12
|
props: {
|
|
14
|
-
|
|
15
|
-
theme: { default: "light" },
|
|
16
|
-
language: { default: "sql" },
|
|
17
|
-
placeholder: { default: "" },
|
|
18
|
-
readonly: {
|
|
13
|
+
autoFocus: {
|
|
19
14
|
type: Boolean,
|
|
15
|
+
required: !1,
|
|
20
16
|
default: !1
|
|
21
17
|
},
|
|
22
18
|
disabled: {
|
|
23
19
|
type: Boolean,
|
|
20
|
+
required: !1,
|
|
21
|
+
default: !1
|
|
22
|
+
},
|
|
23
|
+
highlightWhitespace: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
required: !1,
|
|
24
26
|
default: !1
|
|
25
27
|
},
|
|
26
|
-
|
|
28
|
+
indentUnit: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: !1,
|
|
31
|
+
default: " "
|
|
32
|
+
},
|
|
27
33
|
indentWithTab: {
|
|
28
34
|
type: Boolean,
|
|
35
|
+
required: !1,
|
|
29
36
|
default: !1
|
|
30
37
|
},
|
|
31
|
-
|
|
38
|
+
language: {
|
|
39
|
+
type: String,
|
|
40
|
+
required: !1,
|
|
41
|
+
default: "sql"
|
|
42
|
+
},
|
|
43
|
+
languages: {
|
|
44
|
+
type: Array,
|
|
45
|
+
required: !1,
|
|
46
|
+
default: () => u
|
|
47
|
+
},
|
|
32
48
|
lineWrapping: {
|
|
33
49
|
type: Boolean,
|
|
50
|
+
required: !1,
|
|
34
51
|
default: !1
|
|
35
52
|
},
|
|
36
|
-
|
|
53
|
+
placeholder: {
|
|
54
|
+
type: String,
|
|
55
|
+
required: !1,
|
|
56
|
+
default: ""
|
|
57
|
+
},
|
|
58
|
+
readonly: {
|
|
37
59
|
type: Boolean,
|
|
60
|
+
required: !1,
|
|
38
61
|
default: !1
|
|
62
|
+
},
|
|
63
|
+
root: {
|
|
64
|
+
type: null,
|
|
65
|
+
required: !1
|
|
66
|
+
},
|
|
67
|
+
setup: {
|
|
68
|
+
type: [String, null],
|
|
69
|
+
required: !1,
|
|
70
|
+
default: "basic"
|
|
71
|
+
},
|
|
72
|
+
theme: {
|
|
73
|
+
type: String,
|
|
74
|
+
required: !1,
|
|
75
|
+
default: "light"
|
|
76
|
+
},
|
|
77
|
+
value: {
|
|
78
|
+
type: String,
|
|
79
|
+
required: !1,
|
|
80
|
+
default: ""
|
|
39
81
|
}
|
|
40
82
|
},
|
|
41
|
-
emits: [
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
emits: [
|
|
84
|
+
"blur",
|
|
85
|
+
"change",
|
|
86
|
+
"focus",
|
|
87
|
+
"update:value"
|
|
88
|
+
],
|
|
89
|
+
setup(t, { expose: n, emit: r }) {
|
|
90
|
+
n();
|
|
91
|
+
let o = t, u = r, w = s(null), T = c(null), E = e(() => ({
|
|
92
|
+
"aria-disabled": o.disabled || void 0,
|
|
93
|
+
class: "aiao-code-editor"
|
|
94
|
+
})), D = new h(), O = new h(), k = new h(), A = new h(), j = new h(), M = new h(), N = new h(), P = new h(), F = new h(), I = new h(), L = m.define(), R = {
|
|
95
|
+
basic: S,
|
|
96
|
+
minimal: C
|
|
97
|
+
}, z = 0;
|
|
98
|
+
i(() => {
|
|
99
|
+
let e = w.value;
|
|
100
|
+
if (!e) return;
|
|
101
|
+
let t = new v({
|
|
102
|
+
parent: e,
|
|
103
|
+
state: g.create({
|
|
104
|
+
doc: o.value,
|
|
105
|
+
extensions: [
|
|
106
|
+
D.of(V()),
|
|
107
|
+
O.of([]),
|
|
108
|
+
k.of([]),
|
|
109
|
+
A.of([]),
|
|
110
|
+
j.of([]),
|
|
111
|
+
M.of([]),
|
|
112
|
+
N.of([]),
|
|
113
|
+
P.of([]),
|
|
114
|
+
F.of([]),
|
|
115
|
+
I.of([]),
|
|
116
|
+
v.domEventObservers({
|
|
117
|
+
blur: () => u("blur"),
|
|
118
|
+
focus: () => u("focus")
|
|
119
|
+
}),
|
|
120
|
+
v.updateListener.of((e) => {
|
|
121
|
+
let t = e.transactions.some((e) => e.annotation(L));
|
|
122
|
+
if (!e.docChanged || t) return;
|
|
123
|
+
let n = e.state.doc.toString();
|
|
124
|
+
u("update:value", n), u("change", n);
|
|
125
|
+
})
|
|
126
|
+
]
|
|
75
127
|
}),
|
|
76
|
-
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
128
|
+
...o.root ? { root: o.root } : {}
|
|
129
|
+
});
|
|
130
|
+
T.value = t, H(), U(), G(), K(), q(), J(), Y(), o.autoFocus && t.focus();
|
|
131
|
+
}), a(() => {
|
|
132
|
+
z += 1;
|
|
133
|
+
let e = T.value;
|
|
134
|
+
T.value = null, e?.destroy();
|
|
135
|
+
}), l(() => o.value, (e) => {
|
|
81
136
|
let t = T.value;
|
|
82
|
-
t
|
|
137
|
+
!t || t.state.doc.toString() === e || t.dispatch({
|
|
138
|
+
annotations: L.of(!0),
|
|
83
139
|
changes: {
|
|
84
140
|
from: 0,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
annotations: F.of(!0)
|
|
141
|
+
insert: e,
|
|
142
|
+
to: t.state.doc.length
|
|
143
|
+
}
|
|
89
144
|
});
|
|
90
|
-
}), o(() =>
|
|
91
|
-
function L() {
|
|
92
|
-
let e = T.value;
|
|
93
|
-
if (!e) return;
|
|
94
|
-
let t = S.theme === "dark" ? m : [];
|
|
95
|
-
e.dispatch({ effects: D.reconfigure(t) });
|
|
96
|
-
}
|
|
97
|
-
async function R() {
|
|
98
|
-
let e = T.value;
|
|
99
|
-
if (!e) return;
|
|
100
|
-
let t = await I(S.language || "sql");
|
|
101
|
-
e.dispatch({ effects: E.reconfigure(t) });
|
|
102
|
-
}
|
|
103
|
-
function z() {
|
|
104
|
-
let e = T.value;
|
|
105
|
-
e && e.dispatch({ effects: [O.reconfigure(p.readOnly.of(S.readonly || S.disabled)), k.reconfigure(h.editable.of(!S.readonly && !S.disabled))] });
|
|
106
|
-
}
|
|
145
|
+
}), l(() => o.setup, B), l(() => o.theme, H), l([() => o.language, () => o.languages], U), l([() => o.readonly, () => o.disabled], G), l(() => o.placeholder, K), l([() => o.indentWithTab, () => o.indentUnit], q), l(() => o.lineWrapping, J), l(() => o.highlightWhitespace, Y);
|
|
107
146
|
function B() {
|
|
108
|
-
|
|
109
|
-
e && e.dispatch({ effects: A.reconfigure(S.placeholder ? v(S.placeholder) : []) });
|
|
147
|
+
T.value?.dispatch({ effects: D.reconfigure(V()) });
|
|
110
148
|
}
|
|
111
149
|
function V() {
|
|
112
|
-
|
|
113
|
-
e && e.dispatch({ effects: [j.reconfigure(S.indentWithTab ? _.of([c]) : []), M.reconfigure(S.indentUnit ? u.of(S.indentUnit) : [])] });
|
|
150
|
+
return o.setup === null ? [] : R[o.setup];
|
|
114
151
|
}
|
|
115
152
|
function H() {
|
|
116
|
-
|
|
117
|
-
e && e.dispatch({ effects: N.reconfigure(S.lineWrapping ? h.lineWrapping : []) });
|
|
153
|
+
T.value?.dispatch({ effects: k.reconfigure(o.theme === "dark" ? _ : []) });
|
|
118
154
|
}
|
|
119
155
|
function U() {
|
|
156
|
+
let e = ++z, t = T.value;
|
|
157
|
+
if (!t) return;
|
|
158
|
+
let n = o.language;
|
|
159
|
+
if (!n || n === "plaintext" || o.languages.length === 0) {
|
|
160
|
+
t.dispatch({ effects: O.reconfigure([]) });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let r = d(n, o.languages);
|
|
164
|
+
if (!r) {
|
|
165
|
+
console.error(`[CodeEditor] Language '${n}' not found.`), t.dispatch({ effects: O.reconfigure([]) });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
r.load().then((n) => {
|
|
169
|
+
W(e, t) && t.dispatch({ effects: O.reconfigure(n.extension) });
|
|
170
|
+
}, (r) => {
|
|
171
|
+
W(e, t) && (console.error(`[CodeEditor] Failed to load language '${n}':`, r), t.dispatch({ effects: O.reconfigure([]) }));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function W(e, t) {
|
|
175
|
+
return e === z && T.value === t;
|
|
176
|
+
}
|
|
177
|
+
function G() {
|
|
120
178
|
let e = T.value;
|
|
121
|
-
|
|
179
|
+
if (!e) return;
|
|
180
|
+
let t = o.readonly || o.disabled;
|
|
181
|
+
e.dispatch({ effects: [A.reconfigure(g.readOnly.of(t)), j.reconfigure(v.editable.of(!t))] });
|
|
182
|
+
}
|
|
183
|
+
function K() {
|
|
184
|
+
T.value?.dispatch({ effects: M.reconfigure(o.placeholder ? x(o.placeholder) : []) });
|
|
185
|
+
}
|
|
186
|
+
function q() {
|
|
187
|
+
T.value?.dispatch({ effects: [N.reconfigure(o.indentWithTab ? b.of([f]) : []), P.reconfigure(o.indentUnit ? p.of(o.indentUnit) : [])] });
|
|
122
188
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
189
|
+
function J() {
|
|
190
|
+
T.value?.dispatch({ effects: F.reconfigure(o.lineWrapping ? v.lineWrapping : []) });
|
|
191
|
+
}
|
|
192
|
+
function Y() {
|
|
193
|
+
T.value?.dispatch({ effects: I.reconfigure(o.highlightWhitespace ? y() : []) });
|
|
194
|
+
}
|
|
195
|
+
let X = {
|
|
196
|
+
props: o,
|
|
197
|
+
emit: u,
|
|
198
|
+
editorRef: w,
|
|
199
|
+
viewRef: T,
|
|
200
|
+
hostAttributes: E,
|
|
201
|
+
setupConf: D,
|
|
202
|
+
languageConf: O,
|
|
203
|
+
themeConf: k,
|
|
204
|
+
readonlyConf: A,
|
|
205
|
+
editableConf: j,
|
|
206
|
+
placeholderConf: M,
|
|
207
|
+
indentWithTabConf: N,
|
|
208
|
+
indentUnitConf: P,
|
|
209
|
+
lineWrappingConf: F,
|
|
210
|
+
highlightWhitespaceConf: I,
|
|
211
|
+
External: L,
|
|
212
|
+
setupExtensions: R,
|
|
213
|
+
get languageRequest() {
|
|
214
|
+
return z;
|
|
215
|
+
},
|
|
216
|
+
set languageRequest(e) {
|
|
217
|
+
z = e;
|
|
218
|
+
},
|
|
219
|
+
updateSetup: B,
|
|
220
|
+
getSetupExtension: V,
|
|
221
|
+
updateTheme: H,
|
|
222
|
+
updateLanguage: U,
|
|
223
|
+
isCurrentLanguageRequest: W,
|
|
224
|
+
updateReadonly: G,
|
|
225
|
+
updatePlaceholder: K,
|
|
226
|
+
updateIndent: q,
|
|
227
|
+
updateLineWrapping: J,
|
|
228
|
+
updateHighlightWhitespace: Y
|
|
229
|
+
};
|
|
230
|
+
return Object.defineProperty(X, "__isScriptSetup", {
|
|
231
|
+
enumerable: !1,
|
|
232
|
+
value: !0
|
|
233
|
+
}), X;
|
|
128
234
|
}
|
|
129
|
-
})
|
|
235
|
+
}), T = (e, t) => {
|
|
236
|
+
let n = e.__vccOpts || e;
|
|
237
|
+
for (let [e, r] of t) n[e] = r;
|
|
238
|
+
return n;
|
|
239
|
+
};
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/CodeEditor.vue
|
|
242
|
+
function E(e, n, i, a, s, c) {
|
|
243
|
+
return o(), t("div", r(a.hostAttributes, { ref: "editorRef" }), null, 16);
|
|
244
|
+
}
|
|
245
|
+
var D = /*#__PURE__*/ T(w, [
|
|
246
|
+
["render", E],
|
|
247
|
+
["__scopeId", "data-v-9b1829ca"],
|
|
248
|
+
["__file", "/private/tmp/aiao-release-027.kcmOWl/aiao/packages/code-editor-vue/src/CodeEditor.vue"]
|
|
249
|
+
]);
|
|
130
250
|
//#endregion
|
|
131
|
-
export {
|
|
251
|
+
export { D as CodeEditor };
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/code-editor-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"style": "./dist/index.css",
|
|
8
9
|
"exports": {
|
|
9
10
|
"./package.json": "./package.json",
|
|
11
|
+
"./style.css": "./dist/index.css",
|
|
10
12
|
".": {
|
|
11
13
|
"@aiao/source": "./src/index.ts",
|
|
12
14
|
"types": "./dist/index.d.ts",
|
|
@@ -31,12 +33,12 @@
|
|
|
31
33
|
"vue": ">=3.5.0"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@codemirror/commands": "^6.10.
|
|
35
|
-
"@codemirror/language": "^6.12.
|
|
36
|
-
"@codemirror/state": "
|
|
36
|
+
"@codemirror/commands": "^6.10.4",
|
|
37
|
+
"@codemirror/language": "^6.12.4",
|
|
38
|
+
"@codemirror/state": "6.7.1",
|
|
37
39
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
38
|
-
"@codemirror/view": "6.
|
|
40
|
+
"@codemirror/view": "^6.43.5",
|
|
39
41
|
"codemirror": "^6.0.1",
|
|
40
|
-
"@aiao/code-editor": "0.0.
|
|
42
|
+
"@aiao/code-editor": "0.0.22"
|
|
41
43
|
}
|
|
42
44
|
}
|