@aiao/code-editor-vue 0.0.18 → 0.0.20
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/dist/CodeEditor.vue.d.ts +3 -4
- package/dist/CodeEditor.vue.d.ts.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +130 -129
- package/package.json +4 -4
package/dist/CodeEditor.vue.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ type __VLS_Props = {
|
|
|
11
11
|
lineWrapping?: boolean;
|
|
12
12
|
highlightWhitespace?: boolean;
|
|
13
13
|
};
|
|
14
|
-
declare const
|
|
14
|
+
declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
15
15
|
"update:value": (value: string) => any;
|
|
16
16
|
change: (value: string) => any;
|
|
17
17
|
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
@@ -29,8 +29,7 @@ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {
|
|
|
29
29
|
indentUnit: string;
|
|
30
30
|
lineWrapping: boolean;
|
|
31
31
|
highlightWhitespace: boolean;
|
|
32
|
-
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
|
|
33
|
-
|
|
34
|
-
}, HTMLDivElement>;
|
|
32
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
33
|
+
declare const _default: typeof __VLS_export;
|
|
35
34
|
export default _default;
|
|
36
35
|
//# sourceMappingURL=CodeEditor.vue.d.ts.map
|
|
@@ -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":"AAuRA,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;AAqPJ,QAAA,MAAM,YAAY;;;;;;;WAhQN,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;6EA0P/B,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
package/dist/index.css
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aiao/code-editor-vue
|
|
3
|
+
*
|
|
4
|
+
* Vue CodeMirror 代码编辑器组件
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```vue
|
|
8
|
+
* <template>
|
|
9
|
+
* <CodeEditor
|
|
10
|
+
* v-model:value="code"
|
|
11
|
+
* language="typescript"
|
|
12
|
+
* theme="dark"
|
|
13
|
+
* @change="onCodeChange"
|
|
14
|
+
* />
|
|
15
|
+
* </template>
|
|
16
|
+
*
|
|
17
|
+
* <script setup>
|
|
18
|
+
* import { CodeEditor } from '@aiao/code-editor-vue';
|
|
19
|
+
* </script>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
1
22
|
export { default as CodeEditor } from './CodeEditor.vue';
|
|
2
23
|
//# 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,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,130 +1,131 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SUPPORT_LANGUAGES as
|
|
3
|
-
import { indentWithTab as
|
|
4
|
-
import {
|
|
5
|
-
import { Compartment as
|
|
6
|
-
import { oneDark as
|
|
7
|
-
import { EditorView as
|
|
8
|
-
import { basicSetup as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
1
|
+
import { createElementBlock as e, defineComponent as t, onMounted as n, onUnmounted as r, openBlock as i, ref as a, watch as o } from "vue";
|
|
2
|
+
import { SUPPORT_LANGUAGES as s } from "@aiao/code-editor";
|
|
3
|
+
import { indentWithTab as c } from "@codemirror/commands";
|
|
4
|
+
import { LanguageDescription as l, indentUnit as u } from "@codemirror/language";
|
|
5
|
+
import { Annotation as d, Compartment as f, EditorState as p } from "@codemirror/state";
|
|
6
|
+
import { oneDark as m } from "@codemirror/theme-one-dark";
|
|
7
|
+
import { EditorView as h, highlightWhitespace as g, keymap as _, placeholder as v } from "@codemirror/view";
|
|
8
|
+
import { basicSetup as y, minimalSetup as b } from "codemirror";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/CodeEditor.vue
|
|
11
|
+
var x = /* @__PURE__ */ t({
|
|
12
|
+
__name: "CodeEditor",
|
|
13
|
+
props: {
|
|
14
|
+
value: { default: "" },
|
|
15
|
+
theme: { default: "light" },
|
|
16
|
+
language: { default: "sql" },
|
|
17
|
+
placeholder: { default: "" },
|
|
18
|
+
readonly: {
|
|
19
|
+
type: Boolean,
|
|
20
|
+
default: !1
|
|
21
|
+
},
|
|
22
|
+
disabled: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
default: !1
|
|
25
|
+
},
|
|
26
|
+
setup: { default: "basic" },
|
|
27
|
+
indentWithTab: {
|
|
28
|
+
type: Boolean,
|
|
29
|
+
default: !1
|
|
30
|
+
},
|
|
31
|
+
indentUnit: { default: " " },
|
|
32
|
+
lineWrapping: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: !1
|
|
35
|
+
},
|
|
36
|
+
highlightWhitespace: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: !1
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
emits: ["update:value", "change"],
|
|
42
|
+
setup(t, { emit: x }) {
|
|
43
|
+
let S = t, C = x, w = a(null), T = a(null), E = new f(), D = new f(), O = new f(), k = new f(), A = new f(), j = new f(), M = new f(), N = new f(), P = new f(), F = d.define(), I = async (e) => {
|
|
44
|
+
let t = l.matchLanguageName(s, e, !0);
|
|
45
|
+
if (!t) return console.error(`[CodeEditor] Language '${e}' not found.`), [];
|
|
46
|
+
try {
|
|
47
|
+
return await t.load();
|
|
48
|
+
} catch (t) {
|
|
49
|
+
return console.error(`[CodeEditor] Failed to load language '${e}':`, t), [];
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
n(async () => {
|
|
53
|
+
if (!w.value) return;
|
|
54
|
+
let e = [
|
|
55
|
+
E.of([]),
|
|
56
|
+
D.of([]),
|
|
57
|
+
O.of([]),
|
|
58
|
+
k.of([]),
|
|
59
|
+
A.of([]),
|
|
60
|
+
j.of([]),
|
|
61
|
+
M.of([]),
|
|
62
|
+
N.of([]),
|
|
63
|
+
P.of([]),
|
|
64
|
+
h.updateListener.of((e) => {
|
|
65
|
+
if (e.docChanged && !e.transactions.some((e) => e.annotation(F))) {
|
|
66
|
+
let t = e.state.doc.toString();
|
|
67
|
+
C("update:value", t), C("change", t);
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
];
|
|
71
|
+
S.setup === "basic" ? e.unshift(y) : e.unshift(b), T.value = new h({
|
|
72
|
+
state: p.create({
|
|
73
|
+
doc: S.value,
|
|
74
|
+
extensions: e
|
|
75
|
+
}),
|
|
76
|
+
parent: w.value
|
|
77
|
+
}), L(), R(), z(), B(), V(), H(), U();
|
|
78
|
+
}), r(() => {
|
|
79
|
+
T.value?.destroy();
|
|
80
|
+
}), o(() => S.value, (e) => {
|
|
81
|
+
let t = T.value;
|
|
82
|
+
t && t.state.doc.toString() !== e && t.dispatch({
|
|
83
|
+
changes: {
|
|
84
|
+
from: 0,
|
|
85
|
+
to: t.state.doc.length,
|
|
86
|
+
insert: e
|
|
87
|
+
},
|
|
88
|
+
annotations: F.of(!0)
|
|
89
|
+
});
|
|
90
|
+
}), o(() => S.theme, L), o(() => S.language, R), o(() => [S.readonly, S.disabled], z), o(() => S.placeholder, B), o(() => [S.indentWithTab, S.indentUnit], V), o(() => S.lineWrapping, H), o(() => S.highlightWhitespace, U);
|
|
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
|
+
}
|
|
107
|
+
function B() {
|
|
108
|
+
let e = T.value;
|
|
109
|
+
e && e.dispatch({ effects: A.reconfigure(S.placeholder ? v(S.placeholder) : []) });
|
|
110
|
+
}
|
|
111
|
+
function V() {
|
|
112
|
+
let e = T.value;
|
|
113
|
+
e && e.dispatch({ effects: [j.reconfigure(S.indentWithTab ? _.of([c]) : []), M.reconfigure(S.indentUnit ? u.of(S.indentUnit) : [])] });
|
|
114
|
+
}
|
|
115
|
+
function H() {
|
|
116
|
+
let e = T.value;
|
|
117
|
+
e && e.dispatch({ effects: N.reconfigure(S.lineWrapping ? h.lineWrapping : []) });
|
|
118
|
+
}
|
|
119
|
+
function U() {
|
|
120
|
+
let e = T.value;
|
|
121
|
+
e && e.dispatch({ effects: P.reconfigure(S.highlightWhitespace ? g() : []) });
|
|
122
|
+
}
|
|
123
|
+
return (t, n) => (i(), e("div", {
|
|
124
|
+
class: "h-full w-full overflow-hidden text-sm",
|
|
125
|
+
ref_key: "editorRef",
|
|
126
|
+
ref: w
|
|
127
|
+
}, null, 512));
|
|
128
|
+
}
|
|
127
129
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
130
|
+
//#endregion
|
|
131
|
+
export { x as CodeEditor };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/code-editor-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@codemirror/commands": "^6.10.2",
|
|
35
|
-
"@codemirror/language": "^6.12.
|
|
35
|
+
"@codemirror/language": "^6.12.3",
|
|
36
36
|
"@codemirror/state": "^6.5.4",
|
|
37
37
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
38
|
-
"@codemirror/view": "
|
|
38
|
+
"@codemirror/view": "6.42.1",
|
|
39
39
|
"codemirror": "^6.0.1",
|
|
40
|
-
"@aiao/code-editor": "0.0.
|
|
40
|
+
"@aiao/code-editor": "0.0.20"
|
|
41
41
|
}
|
|
42
42
|
}
|