@aiao/code-editor-vue 0.0.19 → 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.
@@ -11,7 +11,7 @@ type __VLS_Props = {
11
11
  lineWrapping?: boolean;
12
12
  highlightWhitespace?: boolean;
13
13
  };
14
- declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
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
- editorRef: HTMLDivElement;
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":"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":"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
@@ -1 +1,2 @@
1
1
  .cm-editor{height:100%}.cm-scroller{overflow:auto}
2
+ /*$vite$:1*/
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
@@ -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 { 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
- }
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
- export {
129
- ne as CodeEditor
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.19",
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.2",
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": "^6.39.16",
38
+ "@codemirror/view": "6.42.1",
39
39
  "codemirror": "^6.0.1",
40
- "@aiao/code-editor": "0.0.19"
40
+ "@aiao/code-editor": "0.0.20"
41
41
  }
42
42
  }