@aiao/code-editor-vue 0.0.19 → 0.0.21

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 CHANGED
@@ -1,30 +1,82 @@
1
1
  # @aiao/code-editor-vue
2
2
 
3
- Vue 代码编辑器组件,基于 CodeMirror 6。
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
- npm install @aiao/code-editor @aiao/code-editor-vue
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 setup lang="ts">
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 v-model="code" language="typescript" />
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
+ ```
@@ -1,36 +1,29 @@
1
- type __VLS_Props = {
2
- value?: string;
3
- theme?: 'light' | 'dark';
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 _default: 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
- }, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
18
- "onUpdate:value"?: ((value: string) => any) | undefined;
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
- value: string;
22
- theme: "light" | "dark";
23
- language: string;
24
- placeholder: string;
25
- readonly: boolean;
26
- disabled: boolean;
27
- setup: "basic" | "minimal";
28
- indentWithTab: boolean;
29
- indentUnit: string;
30
- lineWrapping: boolean;
31
- highlightWhitespace: boolean;
32
- }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
33
- editorRef: HTMLDivElement;
34
- }, HTMLDivElement>;
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;
26
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
27
+ declare const _default: typeof __VLS_export;
35
28
  export default _default;
36
29
  //# sourceMappingURL=CodeEditor.vue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.vue.d.ts","sourceRoot":"","sources":["../src/CodeEditor.vue"],"names":[],"mappings":"AAsPA,KAAK,WAAW,GAAG;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;;;;;;;;WAXQ,MAAM;WACN,OAAO,GAAG,MAAM;cACb,MAAM;iBACH,MAAM;cACT,OAAO;cACP,OAAO;WACV,OAAO,GAAG,SAAS;mBACX,OAAO;gBACV,MAAM;kBACJ,OAAO;yBACA,OAAO;;;;AA4PjC,wBAUG"}
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 +1,2 @@
1
- .cm-editor{height:100%}.cm-scroller{overflow:auto}
1
+ .aiao-code-editor[data-v-64632146]{width:100%;height:100%;font-size:.875rem;display:block;overflow:hidden}.aiao-code-editor[data-v-64632146] .cm-editor{height:100%}.aiao-code-editor[data-v-64632146] .cm-scroller{overflow:auto}
2
+ /*$vite$:1*/
package/dist/index.d.ts CHANGED
@@ -1,2 +1,18 @@
1
+ /**
2
+ * @aiao/code-editor-vue
3
+ *
4
+ * @example
5
+ * ```vue
6
+ * <script setup lang="ts">
7
+ * import { CodeEditor } from '@aiao/code-editor-vue';
8
+ * import '@aiao/code-editor-vue/style.css';
9
+ * </script>
10
+ *
11
+ * <template>
12
+ * <CodeEditor v-model:value="code" language="typescript" />
13
+ * </template>
14
+ * ```
15
+ */
16
+ export type { CodeEditorEmits, CodeEditorProps, CodeEditorSetup, CodeEditorTheme } from './code-editor.types.js';
1
17
  export { default as CodeEditor } from './CodeEditor.vue';
2
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
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,130 +1,169 @@
1
- import { defineComponent as P, ref as B, onMounted as q, onUnmounted as A, watch as i, openBlock as D, createElementBlock as G } from "vue";
2
- import { SUPPORT_LANGUAGES as N } from "@aiao/code-editor";
3
- import { indentWithTab as O } from "@codemirror/commands";
4
- import { indentUnit as H, LanguageDescription as I } from "@codemirror/language";
5
- import { Compartment as o, EditorState as L } from "@codemirror/state";
6
- import { oneDark as M } from "@codemirror/theme-one-dark";
7
- import { EditorView as l, placeholder as V, keymap as j, highlightWhitespace as z } from "@codemirror/view";
8
- import { basicSetup as F, minimalSetup as J } from "codemirror";
9
- const ne = /* @__PURE__ */ P({
10
- __name: "CodeEditor",
11
- props: {
12
- value: { default: "" },
13
- theme: { default: "light" },
14
- language: { default: "sql" },
15
- placeholder: { default: "" },
16
- readonly: { type: Boolean, default: !1 },
17
- disabled: { type: Boolean, default: !1 },
18
- setup: { default: "basic" },
19
- indentWithTab: { type: Boolean, default: !1 },
20
- indentUnit: { default: " " },
21
- lineWrapping: { type: Boolean, default: !1 },
22
- highlightWhitespace: { type: Boolean, default: !1 }
23
- },
24
- emits: ["update:value", "change"],
25
- setup(T, { emit: k }) {
26
- const t = T, f = k, r = B(null), a = B(null), c = new o(), s = new o(), d = new o(), u = new o(), p = new o(), h = new o(), g = new o(), m = new o(), v = new o(), x = async (e) => {
27
- const n = I.matchLanguageName(N, e, !0);
28
- return n ? await n.load() : [];
29
- };
30
- q(async () => {
31
- if (!r.value) return;
32
- const e = [
33
- c.of([]),
34
- s.of([]),
35
- d.of([]),
36
- u.of([]),
37
- p.of([]),
38
- h.of([]),
39
- g.of([]),
40
- m.of([]),
41
- v.of([]),
42
- l.updateListener.of((S) => {
43
- if (S.docChanged) {
44
- const _ = S.state.doc.toString();
45
- f("update:value", _), f("change", _);
46
- }
47
- })
48
- ];
49
- t.setup === "basic" ? e.unshift(F) : e.unshift(J);
50
- const n = L.create({
51
- doc: t.value,
52
- extensions: e
53
- }), R = new l({
54
- state: n,
55
- parent: r.value
56
- });
57
- a.value = R, w(), y(), W(), b(), C(), U(), E();
58
- }), A(() => {
59
- a.value?.destroy();
60
- }), i(
61
- () => t.value,
62
- (e) => {
63
- const n = a.value;
64
- n && n.state.doc.toString() !== e && n.dispatch({
65
- changes: { from: 0, to: n.state.doc.length, insert: e }
66
- });
67
- }
68
- ), i(() => t.theme, w), i(() => t.language, y), i(() => [t.readonly, t.disabled], W), i(() => t.placeholder, b), i(() => [t.indentWithTab, t.indentUnit], C), i(() => t.lineWrapping, U), i(() => t.highlightWhitespace, E);
69
- function w() {
70
- const e = a.value;
71
- if (!e) return;
72
- const n = t.theme === "dark" ? M : [];
73
- e.dispatch({
74
- effects: s.reconfigure(n)
75
- });
76
- }
77
- async function y() {
78
- const e = a.value;
79
- if (!e) return;
80
- const n = await x(t.language || "sql");
81
- e.dispatch({
82
- effects: c.reconfigure(n)
83
- });
84
- }
85
- function W() {
86
- const e = a.value;
87
- e && e.dispatch({
88
- effects: [
89
- d.reconfigure(L.readOnly.of(t.readonly || t.disabled)),
90
- u.reconfigure(l.editable.of(!t.readonly && !t.disabled))
91
- ]
92
- });
93
- }
94
- function b() {
95
- const e = a.value;
96
- e && e.dispatch({
97
- effects: p.reconfigure(t.placeholder ? V(t.placeholder) : [])
98
- });
99
- }
100
- function C() {
101
- const e = a.value;
102
- e && e.dispatch({
103
- effects: [
104
- h.reconfigure(t.indentWithTab ? j.of([O]) : []),
105
- g.reconfigure(t.indentUnit ? H.of(t.indentUnit) : [])
106
- ]
107
- });
108
- }
109
- function U() {
110
- const e = a.value;
111
- e && e.dispatch({
112
- effects: m.reconfigure(t.lineWrapping ? l.lineWrapping : [])
113
- });
114
- }
115
- function E() {
116
- const e = a.value;
117
- e && e.dispatch({
118
- effects: v.reconfigure(t.highlightWhitespace ? z() : [])
119
- });
120
- }
121
- return (e, n) => (D(), G("div", {
122
- ref_key: "editorRef",
123
- ref: r,
124
- class: "h-full w-full overflow-hidden text-sm"
125
- }, null, 512));
126
- }
127
- });
128
- export {
129
- ne as CodeEditor
130
- };
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
+ //#endregion
10
+ //#region src/CodeEditor.vue
11
+ var w = /*#__PURE__*/ ((e, t) => {
12
+ let n = e.__vccOpts || e;
13
+ for (let [e, r] of t) n[e] = r;
14
+ return n;
15
+ })(/* @__PURE__ */ n({
16
+ __name: "CodeEditor",
17
+ props: {
18
+ autoFocus: {
19
+ type: Boolean,
20
+ default: !1
21
+ },
22
+ disabled: {
23
+ type: Boolean,
24
+ default: !1
25
+ },
26
+ highlightWhitespace: {
27
+ type: Boolean,
28
+ default: !1
29
+ },
30
+ indentUnit: { default: " " },
31
+ indentWithTab: {
32
+ type: Boolean,
33
+ default: !1
34
+ },
35
+ language: { default: "sql" },
36
+ languages: { default: () => u },
37
+ lineWrapping: {
38
+ type: Boolean,
39
+ default: !1
40
+ },
41
+ placeholder: { default: "" },
42
+ readonly: {
43
+ type: Boolean,
44
+ default: !1
45
+ },
46
+ root: {},
47
+ setup: { default: "basic" },
48
+ theme: { default: "light" },
49
+ value: { default: "" }
50
+ },
51
+ emits: [
52
+ "blur",
53
+ "change",
54
+ "focus",
55
+ "update:value"
56
+ ],
57
+ setup(n, { emit: u }) {
58
+ let w = n, T = u, E = s(null), D = c(null), O = e(() => ({
59
+ "aria-disabled": w.disabled || void 0,
60
+ class: "aiao-code-editor"
61
+ })), 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 = new h(), R = new h(), z = m.define(), B = {
62
+ basic: S,
63
+ minimal: C
64
+ }, V = 0;
65
+ i(() => {
66
+ let e = E.value;
67
+ if (!e) return;
68
+ let t = new v({
69
+ parent: e,
70
+ state: g.create({
71
+ doc: w.value,
72
+ extensions: [
73
+ k.of(U()),
74
+ A.of([]),
75
+ j.of([]),
76
+ M.of([]),
77
+ N.of([]),
78
+ P.of([]),
79
+ F.of([]),
80
+ I.of([]),
81
+ L.of([]),
82
+ R.of([]),
83
+ v.domEventObservers({
84
+ blur: () => T("blur"),
85
+ focus: () => T("focus")
86
+ }),
87
+ v.updateListener.of((e) => {
88
+ let t = e.transactions.some((e) => e.annotation(z));
89
+ if (!e.docChanged || t) return;
90
+ let n = e.state.doc.toString();
91
+ T("update:value", n), T("change", n);
92
+ })
93
+ ]
94
+ }),
95
+ ...w.root ? { root: w.root } : {}
96
+ });
97
+ D.value = t, W(), G(), q(), J(), Y(), X(), Z(), w.autoFocus && t.focus();
98
+ }), a(() => {
99
+ V += 1;
100
+ let e = D.value;
101
+ D.value = null, e?.destroy();
102
+ }), l(() => w.value, (e) => {
103
+ let t = D.value;
104
+ !t || t.state.doc.toString() === e || t.dispatch({
105
+ annotations: z.of(!0),
106
+ changes: {
107
+ from: 0,
108
+ insert: e,
109
+ to: t.state.doc.length
110
+ }
111
+ });
112
+ }), l(() => w.setup, H), l(() => w.theme, W), l([() => w.language, () => w.languages], G), l([() => w.readonly, () => w.disabled], q), l(() => w.placeholder, J), l([() => w.indentWithTab, () => w.indentUnit], Y), l(() => w.lineWrapping, X), l(() => w.highlightWhitespace, Z);
113
+ function H() {
114
+ D.value?.dispatch({ effects: k.reconfigure(U()) });
115
+ }
116
+ function U() {
117
+ return w.setup === null ? [] : B[w.setup];
118
+ }
119
+ function W() {
120
+ D.value?.dispatch({ effects: j.reconfigure(w.theme === "dark" ? _ : []) });
121
+ }
122
+ function G() {
123
+ let e = ++V, t = D.value;
124
+ if (!t) return;
125
+ let n = w.language;
126
+ if (!n || n === "plaintext" || w.languages.length === 0) {
127
+ t.dispatch({ effects: A.reconfigure([]) });
128
+ return;
129
+ }
130
+ let r = d(n, w.languages);
131
+ if (!r) {
132
+ console.error(`[CodeEditor] Language '${n}' not found.`), t.dispatch({ effects: A.reconfigure([]) });
133
+ return;
134
+ }
135
+ r.load().then((n) => {
136
+ K(e, t) && t.dispatch({ effects: A.reconfigure(n.extension) });
137
+ }, (r) => {
138
+ K(e, t) && (console.error(`[CodeEditor] Failed to load language '${n}':`, r), t.dispatch({ effects: A.reconfigure([]) }));
139
+ });
140
+ }
141
+ function K(e, t) {
142
+ return e === V && D.value === t;
143
+ }
144
+ function q() {
145
+ let e = D.value;
146
+ if (!e) return;
147
+ let t = w.readonly || w.disabled;
148
+ e.dispatch({ effects: [M.reconfigure(g.readOnly.of(t)), N.reconfigure(v.editable.of(!t))] });
149
+ }
150
+ function J() {
151
+ D.value?.dispatch({ effects: P.reconfigure(w.placeholder ? x(w.placeholder) : []) });
152
+ }
153
+ function Y() {
154
+ D.value?.dispatch({ effects: [F.reconfigure(w.indentWithTab ? b.of([f]) : []), I.reconfigure(w.indentUnit ? p.of(w.indentUnit) : [])] });
155
+ }
156
+ function X() {
157
+ D.value?.dispatch({ effects: L.reconfigure(w.lineWrapping ? v.lineWrapping : []) });
158
+ }
159
+ function Z() {
160
+ D.value?.dispatch({ effects: R.reconfigure(w.highlightWhitespace ? y() : []) });
161
+ }
162
+ return (e, n) => (o(), t("div", r(O.value, {
163
+ ref_key: "editorRef",
164
+ ref: E
165
+ }), null, 16));
166
+ }
167
+ }), [["__scopeId", "data-v-64632146"]]);
168
+ //#endregion
169
+ export { w as CodeEditor };
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@aiao/code-editor-vue",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
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.2",
35
- "@codemirror/language": "^6.12.2",
36
- "@codemirror/state": "^6.5.4",
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.39.16",
40
+ "@codemirror/view": "^6.43.5",
39
41
  "codemirror": "^6.0.1",
40
- "@aiao/code-editor": "0.0.19"
42
+ "@aiao/code-editor": "0.0.21"
41
43
  }
42
44
  }