@aiao/code-editor-vue 0.0.25 → 0.0.28
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 +16 -16
- package/dist/CodeEditor.vue.d.ts.map +1 -1
- package/dist/index.js +23 -17
- package/package.json +25 -8
- package/src/CodeEditor.vue +19 -2
package/dist/CodeEditor.vue.d.ts
CHANGED
|
@@ -12,22 +12,22 @@ declare const __VLS_export: import('vue').DefineComponent<CodeEditorProps, CodeE
|
|
|
12
12
|
"onLanguage-error"?: ((error: import('@aiao/code-editor').CodeEditorLanguageError) => any) | undefined;
|
|
13
13
|
"onUpdate:value"?: ((value: string) => any) | undefined;
|
|
14
14
|
}>, {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
autoFocus: boolean;
|
|
16
|
+
describedBy: string;
|
|
17
|
+
disabled: boolean;
|
|
18
|
+
highlightWhitespace: boolean;
|
|
19
|
+
indentUnit: string;
|
|
20
|
+
indentWithTab: boolean;
|
|
21
|
+
language: string;
|
|
22
|
+
languages: readonly import('@aiao/code-editor').CodeEditorLanguageDescription[];
|
|
23
|
+
label: string;
|
|
24
|
+
labelledBy: string;
|
|
25
|
+
lineWrapping: boolean;
|
|
26
|
+
placeholder: string;
|
|
27
|
+
readonly: boolean;
|
|
28
|
+
setup: CodeEditorSetup;
|
|
29
|
+
theme: import('@aiao/code-editor').CodeEditorTheme;
|
|
30
|
+
value: string;
|
|
31
31
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
32
32
|
declare const _default: typeof __VLS_export;
|
|
33
33
|
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":"AAwWA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAwVlH,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6EAKhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { computed as e, createElementBlock as t, defineComponent as n, mergeProps as r, onMounted as
|
|
2
|
-
import { SUPPORT_LANGUAGES as
|
|
1
|
+
import { computed as e, createElementBlock as t, defineComponent as n, mergeProps as r, onMounted as i, onUnmounted as ee, openBlock as a, ref as o, shallowRef as te, watch as s } from "vue";
|
|
2
|
+
import { SUPPORT_LANGUAGES as c, buildCodeEditorContentAttributes as ne, codeEditorLanguageLoadFailed as re, codeEditorLanguageNotFound as l, computeMinimalDocumentChange as ie, isSameResolvedLanguage as ae, resolveCodeEditorLanguage as u, shouldAutoFocusCodeEditor as d } from "@aiao/code-editor";
|
|
3
3
|
import { indentWithTab as f } from "@codemirror/commands";
|
|
4
4
|
import { indentUnit as oe } from "@codemirror/language";
|
|
5
5
|
import { Annotation as se, Compartment as p, EditorState as m, Transaction as h } from "@codemirror/state";
|
|
@@ -30,7 +30,7 @@ var C = /* @__PURE__ */ n({
|
|
|
30
30
|
default: !1
|
|
31
31
|
},
|
|
32
32
|
language: { default: "sql" },
|
|
33
|
-
languages: { default: () =>
|
|
33
|
+
languages: { default: () => c },
|
|
34
34
|
label: { default: "" },
|
|
35
35
|
labelledBy: { default: "" },
|
|
36
36
|
lineWrapping: {
|
|
@@ -54,8 +54,8 @@ var C = /* @__PURE__ */ n({
|
|
|
54
54
|
"language-error",
|
|
55
55
|
"update:value"
|
|
56
56
|
],
|
|
57
|
-
setup(n, { expose:
|
|
58
|
-
let w = n, T = C, E =
|
|
57
|
+
setup(n, { expose: c, emit: C }) {
|
|
58
|
+
let w = n, T = C, E = o(null), D = te(null), ce = e(() => ({
|
|
59
59
|
"aria-disabled": w.disabled || void 0,
|
|
60
60
|
class: "aiao-code-editor",
|
|
61
61
|
style: {
|
|
@@ -69,7 +69,7 @@ var C = /* @__PURE__ */ n({
|
|
|
69
69
|
basic: x,
|
|
70
70
|
minimal: S
|
|
71
71
|
}, V = 0, H;
|
|
72
|
-
|
|
72
|
+
i(() => {
|
|
73
73
|
let e = E.value;
|
|
74
74
|
if (!e) return;
|
|
75
75
|
let t = m.create({
|
|
@@ -118,20 +118,20 @@ var C = /* @__PURE__ */ n({
|
|
|
118
118
|
...w.root ? { root: w.root } : {}
|
|
119
119
|
});
|
|
120
120
|
D.value = n, G(), K(), J(), X(), Z(), Q(), $(), Y(), w.autoFocus && d(w) && n.focus();
|
|
121
|
-
}),
|
|
121
|
+
}), ee(() => {
|
|
122
122
|
V += 1;
|
|
123
123
|
let e = D.value;
|
|
124
124
|
D.value = null, e?.destroy();
|
|
125
|
-
}),
|
|
125
|
+
}), s(() => w.value, (e) => {
|
|
126
126
|
let t = D.value;
|
|
127
127
|
if (!t) return;
|
|
128
|
-
let n =
|
|
128
|
+
let n = ie(t.state.doc.toString(), e ?? "");
|
|
129
129
|
n && t.dispatch({
|
|
130
130
|
annotations: [z.of(!0), h.addToHistory.of(!1)],
|
|
131
131
|
changes: n,
|
|
132
132
|
scrollIntoView: !1
|
|
133
133
|
});
|
|
134
|
-
}),
|
|
134
|
+
}), s(() => w.setup, U), s(() => w.theme, G), s([() => w.language, () => w.languages], le), s([() => w.readonly, () => w.disabled], J), s(() => w.placeholder, X), s([() => w.indentWithTab, () => w.indentUnit], Z), s(() => w.lineWrapping, Q), s(() => w.highlightWhitespace, $), s([
|
|
135
135
|
() => w.describedBy,
|
|
136
136
|
() => w.disabled,
|
|
137
137
|
() => w.label,
|
|
@@ -148,20 +148,26 @@ var C = /* @__PURE__ */ n({
|
|
|
148
148
|
}
|
|
149
149
|
function le() {
|
|
150
150
|
let e = u(w.language, w.languages);
|
|
151
|
-
|
|
151
|
+
ae(H, e) || K();
|
|
152
152
|
}
|
|
153
153
|
function K() {
|
|
154
154
|
let e = ++V, t = D.value;
|
|
155
155
|
if (!t) return;
|
|
156
156
|
let n = w.language, r = u(n, w.languages);
|
|
157
157
|
if (H = r, r.kind !== "found") {
|
|
158
|
-
t.dispatch({ effects: k.reconfigure([]) }), r.kind === "not-found" && (console.error(`[CodeEditor] Language '${n}' not found.`), T("language-error",
|
|
158
|
+
t.dispatch({ effects: k.reconfigure([]) }), r.kind === "not-found" && (console.error(`[CodeEditor] Language '${n}' not found.`), T("language-error", l(n)));
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
let i;
|
|
162
|
+
try {
|
|
163
|
+
i = Promise.resolve(r.description.load());
|
|
164
|
+
} catch (e) {
|
|
165
|
+
i = Promise.reject(e);
|
|
166
|
+
}
|
|
167
|
+
i.then((n) => {
|
|
162
168
|
q(e, t) && t.dispatch({ effects: k.reconfigure(n.extension) });
|
|
163
169
|
}, (r) => {
|
|
164
|
-
q(e, t) && (t.dispatch({ effects: k.reconfigure([]) }), console.error(`[CodeEditor] Failed to load language '${n}':`, r), T("language-error",
|
|
170
|
+
q(e, t) && (t.dispatch({ effects: k.reconfigure([]) }), console.error(`[CodeEditor] Failed to load language '${n}':`, r), T("language-error", re(n, r)));
|
|
165
171
|
});
|
|
166
172
|
}
|
|
167
173
|
function q(e, t) {
|
|
@@ -174,7 +180,7 @@ var C = /* @__PURE__ */ n({
|
|
|
174
180
|
e.dispatch({ effects: [j.reconfigure(m.readOnly.of(t)), M.reconfigure(_.editable.of(!t))] });
|
|
175
181
|
}
|
|
176
182
|
function Y() {
|
|
177
|
-
let e =
|
|
183
|
+
let e = ne(w);
|
|
178
184
|
D.value?.dispatch({ effects: R.reconfigure(_.contentAttributes.of(e)) });
|
|
179
185
|
}
|
|
180
186
|
function X() {
|
|
@@ -189,7 +195,7 @@ var C = /* @__PURE__ */ n({
|
|
|
189
195
|
function $() {
|
|
190
196
|
D.value?.dispatch({ effects: L.reconfigure(w.highlightWhitespace ? v() : []) });
|
|
191
197
|
}
|
|
192
|
-
return
|
|
198
|
+
return c({
|
|
193
199
|
get view() {
|
|
194
200
|
return D.value;
|
|
195
201
|
},
|
|
@@ -198,7 +204,7 @@ var C = /* @__PURE__ */ n({
|
|
|
198
204
|
},
|
|
199
205
|
blur: () => D.value?.contentDOM.blur(),
|
|
200
206
|
focus: () => D.value?.focus()
|
|
201
|
-
}), (e, n) => (
|
|
207
|
+
}), (e, n) => (a(), t("div", r(ce.value, {
|
|
202
208
|
ref_key: "editorRef",
|
|
203
209
|
ref: E
|
|
204
210
|
}), null, 16));
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/code-editor-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
|
+
"description": "Vue integration for the Aiao CodeMirror 6 editor.",
|
|
5
|
+
"homepage": "https://rxdb.aiao.io/docs/code-editor",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/aiao-io/rxdb/issues"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"aiao",
|
|
11
|
+
"rxdb",
|
|
12
|
+
"vue",
|
|
13
|
+
"codemirror",
|
|
14
|
+
"code-editor",
|
|
15
|
+
"typescript"
|
|
16
|
+
],
|
|
4
17
|
"license": "MIT",
|
|
5
18
|
"repository": {
|
|
6
19
|
"type": "git",
|
|
@@ -8,6 +21,7 @@
|
|
|
8
21
|
"directory": "packages/code-editor-vue"
|
|
9
22
|
},
|
|
10
23
|
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
11
25
|
"main": "./dist/index.js",
|
|
12
26
|
"module": "./dist/index.js",
|
|
13
27
|
"types": "./dist/index.d.ts",
|
|
@@ -37,15 +51,18 @@
|
|
|
37
51
|
]
|
|
38
52
|
},
|
|
39
53
|
"peerDependencies": {
|
|
40
|
-
"vue": "^3.5.
|
|
54
|
+
"vue": "^3.5.43"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"vue": "^3.5.44"
|
|
41
58
|
},
|
|
42
59
|
"dependencies": {
|
|
43
|
-
"@codemirror/commands": "^6.
|
|
44
|
-
"@codemirror/language": "6.
|
|
45
|
-
"@codemirror/state": "6.7.
|
|
60
|
+
"@codemirror/commands": "^6.11.1",
|
|
61
|
+
"@codemirror/language": "^6.13.1",
|
|
62
|
+
"@codemirror/state": "^6.7.6",
|
|
46
63
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
47
|
-
"@codemirror/view": "6.43.
|
|
48
|
-
"codemirror": "^6.0.
|
|
49
|
-
"@aiao/code-editor": "0.0.
|
|
64
|
+
"@codemirror/view": "^6.43.14",
|
|
65
|
+
"codemirror": "^6.0.2",
|
|
66
|
+
"@aiao/code-editor": "^0.0.28"
|
|
50
67
|
}
|
|
51
68
|
}
|
package/src/CodeEditor.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import type { ResolvedCodeEditorLanguage } from '@aiao/code-editor';
|
|
2
|
+
import type { CodeEditorLanguageSupport, ResolvedCodeEditorLanguage } from '@aiao/code-editor';
|
|
3
3
|
import {
|
|
4
4
|
buildCodeEditorContentAttributes,
|
|
5
5
|
codeEditorLanguageLoadFailed,
|
|
@@ -224,7 +224,24 @@ function updateLanguage() {
|
|
|
224
224
|
|
|
225
225
|
// 解析结果里已经带着命中的 description —— 早先这里又 `findLanguageByName` 查了一遍,
|
|
226
226
|
// 同一份查找逻辑跑两次,两处结果分叉时没有任何信号。
|
|
227
|
-
|
|
227
|
+
//
|
|
228
|
+
// RV-056:`description.load()` 承诺返回 Promise,但不保证工厂函数在创建 Promise
|
|
229
|
+
// 前不抛同步异常——`.then(success, failure)` 的第二个 handler 只接 Promise
|
|
230
|
+
// rejection,接不到这种同步 throw。`updateLanguage()` 在 `onMounted` 里是同步调用
|
|
231
|
+
// 的一环,异常会中断后面 updateReadonly/placeholder/indent 等访问状态初始化,
|
|
232
|
+
// 真实 createApp 的 errorHandler 才收到它。用 try/catch 把「调用本身」同步兜住,
|
|
233
|
+
// 捕到的同步异常转成已 reject 的 Promise,与 `load()` 正常返回的 Promise 走
|
|
234
|
+
// 同一个 `.then(success, failure)`,`updateLanguage()` 本身永远同步正常返回。
|
|
235
|
+
// 不能像 `Promise.resolve().then(() => resolved.description.load())` 那样多包一层
|
|
236
|
+
// ——`load()` 内部自己还会再 `.then()` 一次(见 CodeMirror 源码),多包的那层会让
|
|
237
|
+
// 本就要经过两次微任务才能结算的 rejection 再推迟两轮才报出去。
|
|
238
|
+
let loadPromise: Promise<CodeEditorLanguageSupport>;
|
|
239
|
+
try {
|
|
240
|
+
loadPromise = Promise.resolve(resolved.description.load());
|
|
241
|
+
} catch (error) {
|
|
242
|
+
loadPromise = Promise.reject(error);
|
|
243
|
+
}
|
|
244
|
+
void loadPromise.then(
|
|
228
245
|
support => {
|
|
229
246
|
if (!isCurrentLanguageRequest(request, view)) return;
|
|
230
247
|
view.dispatch({ effects: languageConf.reconfigure(support.extension as Extension) });
|