@scalar/use-codemirror 0.11.4 → 0.11.5
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/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,8 @@ type BaseParameters = {
|
|
|
19
19
|
lineNumbers?: MaybeRefOrGetter<boolean | undefined>;
|
|
20
20
|
withVariables?: MaybeRefOrGetter<boolean | undefined>;
|
|
21
21
|
disableEnter?: MaybeRefOrGetter<boolean | undefined>;
|
|
22
|
+
/** Option to lint and show error in the editor */
|
|
23
|
+
lint?: MaybeRefOrGetter<boolean | undefined>;
|
|
22
24
|
onBlur?: (v: string) => void;
|
|
23
25
|
onFocus?: (v: string) => void;
|
|
24
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCodeMirror.d.ts","sourceRoot":"","sources":["../../src/hooks/useCodeMirror.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCodeMirror.d.ts","sourceRoot":"","sources":["../../src/hooks/useCodeMirror.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EACL,UAAU,EAKX,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,GAAG,EAMT,MAAM,KAAK,CAAA;AAGZ,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAGlD,KAAK,cAAc,GAAG;IACpB,yCAAyC;IACzC,aAAa,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACzC,mDAAmD;IACnD,UAAU,CAAC,EAAE,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAA;IAC1C,8BAA8B;IAC9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;IACpD,mDAAmD;IACnD,QAAQ,EAAE,gBAAgB,CAAC,kBAAkB,GAA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AU,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAgInC,CAAA"}
|
|
@@ -1,82 +1,84 @@
|
|
|
1
|
-
import { autocompletion as
|
|
2
|
-
import { indentWithTab as
|
|
3
|
-
import { css as
|
|
4
|
-
import { html as
|
|
5
|
-
import { json as
|
|
6
|
-
import { yaml as
|
|
7
|
-
import { syntaxHighlighting as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
1
|
+
import { autocompletion as C, closeBrackets as w, completionKeymap as H, closeBracketsKeymap as N } from "@codemirror/autocomplete";
|
|
2
|
+
import { indentWithTab as j } from "@codemirror/commands";
|
|
3
|
+
import { css as O } from "@codemirror/lang-css";
|
|
4
|
+
import { html as T } from "@codemirror/lang-html";
|
|
5
|
+
import { json as V } from "@codemirror/lang-json";
|
|
6
|
+
import { yaml as K } from "@codemirror/lang-yaml";
|
|
7
|
+
import { syntaxHighlighting as L, defaultHighlightStyle as R, indentOnInput as A, bracketMatching as B } from "@codemirror/language";
|
|
8
|
+
import { linter as I } from "@codemirror/lint";
|
|
9
|
+
import { StateEffect as z } from "@codemirror/state";
|
|
10
|
+
import { EditorView as d, highlightSpecialChars as J, keymap as v, lineNumbers as P } from "@codemirror/view";
|
|
11
|
+
import { ref as U, watch as m, onBeforeUnmount as W, toValue as r, computed as q } from "vue";
|
|
12
|
+
import { customTheme as D } from "../themes/index.js";
|
|
13
|
+
import { variables as G } from "./variables.js";
|
|
14
|
+
const u = (e) => "provider" in e && !!r(e.provider), Q = {
|
|
14
15
|
key: "Mod-a",
|
|
15
16
|
run: (e) => (e.dispatch({
|
|
16
17
|
selection: { anchor: 0, head: e.state.doc.length },
|
|
17
18
|
scrollIntoView: !1
|
|
18
19
|
}), !0)
|
|
19
|
-
},
|
|
20
|
-
const o =
|
|
21
|
-
|
|
20
|
+
}, le = (e) => {
|
|
21
|
+
const o = U(null);
|
|
22
|
+
m(
|
|
22
23
|
e.codeMirrorRef,
|
|
23
24
|
() => {
|
|
24
25
|
var t;
|
|
25
|
-
(t = o.value) == null || t.destroy(),
|
|
26
|
+
(t = o.value) == null || t.destroy(), s();
|
|
26
27
|
},
|
|
27
28
|
{ immediate: !0 }
|
|
28
|
-
),
|
|
29
|
+
), W(() => {
|
|
29
30
|
var t;
|
|
30
31
|
return (t = o.value) == null ? void 0 : t.destroy();
|
|
31
32
|
});
|
|
32
|
-
function
|
|
33
|
+
function s() {
|
|
33
34
|
if (e.codeMirrorRef.value) {
|
|
34
|
-
const t = u(e) ?
|
|
35
|
-
...
|
|
35
|
+
const t = u(e) ? r(e.provider) : null, h = b({
|
|
36
|
+
...l.value,
|
|
36
37
|
provider: t
|
|
37
38
|
});
|
|
38
|
-
o.value = new
|
|
39
|
+
o.value = new d({
|
|
39
40
|
parent: e.codeMirrorRef.value,
|
|
40
|
-
extensions:
|
|
41
|
-
}), u(e) || r(
|
|
41
|
+
extensions: h
|
|
42
|
+
}), u(e) || n(r(e.content));
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
const
|
|
45
|
+
const l = q(() => ({
|
|
45
46
|
onChange: e.onChange,
|
|
46
47
|
onBlur: e.onBlur,
|
|
47
48
|
onFocus: e.onFocus,
|
|
48
|
-
language:
|
|
49
|
-
classes:
|
|
50
|
-
readOnly:
|
|
51
|
-
lineNumbers:
|
|
52
|
-
withVariables:
|
|
53
|
-
disableEnter:
|
|
54
|
-
withoutTheme:
|
|
55
|
-
|
|
49
|
+
language: r(e.language),
|
|
50
|
+
classes: r(e.classes),
|
|
51
|
+
readOnly: r(e.readOnly),
|
|
52
|
+
lineNumbers: r(e.lineNumbers),
|
|
53
|
+
withVariables: r(e.withVariables),
|
|
54
|
+
disableEnter: r(e.withVariables),
|
|
55
|
+
withoutTheme: r(e.withoutTheme),
|
|
56
|
+
lint: r(e.lint),
|
|
57
|
+
additionalExtensions: r(e.extensions)
|
|
56
58
|
}));
|
|
57
|
-
|
|
58
|
-
() => u(e) ?
|
|
59
|
+
m(
|
|
60
|
+
() => u(e) ? r(e.provider) : null,
|
|
59
61
|
() => {
|
|
60
62
|
var t;
|
|
61
|
-
u(e) && ((t = o.value) == null || t.destroy(),
|
|
63
|
+
u(e) && ((t = o.value) == null || t.destroy(), s());
|
|
62
64
|
}
|
|
63
|
-
),
|
|
64
|
-
|
|
65
|
+
), m(
|
|
66
|
+
l,
|
|
65
67
|
() => {
|
|
66
68
|
if (o.value) {
|
|
67
|
-
const t = u(e) ?
|
|
68
|
-
...
|
|
69
|
+
const t = u(e) ? r(e.provider) : null, h = b({
|
|
70
|
+
...l.value,
|
|
69
71
|
provider: t
|
|
70
72
|
});
|
|
71
73
|
o.value.dispatch({
|
|
72
|
-
effects:
|
|
74
|
+
effects: z.reconfigure.of(h)
|
|
73
75
|
});
|
|
74
76
|
} else
|
|
75
77
|
return;
|
|
76
78
|
},
|
|
77
79
|
{ immediate: !0 }
|
|
78
80
|
);
|
|
79
|
-
const
|
|
81
|
+
const n = (t = "") => {
|
|
80
82
|
o.value && o.value.state.doc.toString() !== t && o.value.dispatch({
|
|
81
83
|
changes: {
|
|
82
84
|
from: 0,
|
|
@@ -91,78 +93,107 @@ const u = (e) => "provider" in e && !!i(e.provider), z = {
|
|
|
91
93
|
}
|
|
92
94
|
});
|
|
93
95
|
};
|
|
94
|
-
return
|
|
95
|
-
() =>
|
|
96
|
+
return m(
|
|
97
|
+
() => r(e.content),
|
|
96
98
|
() => {
|
|
97
|
-
u(e) || r(
|
|
99
|
+
u(e) || n(r(e.content));
|
|
98
100
|
},
|
|
99
101
|
{ immediate: !0 }
|
|
100
102
|
), {
|
|
101
103
|
/** Replaces the current content with the given value. */
|
|
102
|
-
setCodeMirrorContent:
|
|
104
|
+
setCodeMirrorContent: n,
|
|
103
105
|
/** Codemirror instance */
|
|
104
106
|
codeMirror: o
|
|
105
107
|
};
|
|
106
|
-
},
|
|
107
|
-
html:
|
|
108
|
-
json:
|
|
109
|
-
yaml:
|
|
110
|
-
css:
|
|
108
|
+
}, p = {
|
|
109
|
+
html: T,
|
|
110
|
+
json: V,
|
|
111
|
+
yaml: K,
|
|
112
|
+
css: O
|
|
111
113
|
};
|
|
112
|
-
function
|
|
114
|
+
function b({
|
|
113
115
|
onChange: e,
|
|
114
116
|
onBlur: o,
|
|
115
|
-
onFocus:
|
|
116
|
-
provider:
|
|
117
|
-
language:
|
|
117
|
+
onFocus: s,
|
|
118
|
+
provider: l,
|
|
119
|
+
language: n,
|
|
118
120
|
classes: t = [],
|
|
119
|
-
readOnly:
|
|
120
|
-
lineNumbers:
|
|
121
|
-
withVariables:
|
|
122
|
-
disableEnter:
|
|
123
|
-
withoutTheme:
|
|
124
|
-
|
|
121
|
+
readOnly: h = !1,
|
|
122
|
+
lineNumbers: y = !1,
|
|
123
|
+
withVariables: x = !1,
|
|
124
|
+
disableEnter: E = !1,
|
|
125
|
+
withoutTheme: M = !1,
|
|
126
|
+
lint: S = !1,
|
|
127
|
+
additionalExtensions: k = []
|
|
125
128
|
}) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
const i = [
|
|
130
|
+
J(),
|
|
131
|
+
L(R, { fallback: !0 }),
|
|
132
|
+
d.theme({
|
|
130
133
|
".cm-line": {
|
|
131
134
|
lineHeight: "20px"
|
|
132
135
|
},
|
|
133
136
|
".cm-gutterElement": {
|
|
134
137
|
lineHeight: "20px"
|
|
138
|
+
},
|
|
139
|
+
".cm-tooltip": {
|
|
140
|
+
border: "1px solid #f5c6cb",
|
|
141
|
+
fontSize: "12px"
|
|
142
|
+
},
|
|
143
|
+
".cm-tooltip-lint": {
|
|
144
|
+
backgroundColor: "#ffffff"
|
|
145
|
+
},
|
|
146
|
+
".cm-diagnostic-error": {
|
|
147
|
+
borderLeft: "0",
|
|
148
|
+
color: "#dc1b19"
|
|
135
149
|
}
|
|
136
150
|
}),
|
|
137
151
|
// Listen to updates
|
|
138
|
-
|
|
139
|
-
|
|
152
|
+
d.updateListener.of((c) => {
|
|
153
|
+
c.docChanged && (e == null || e(c.state.doc.toString()));
|
|
140
154
|
}),
|
|
141
|
-
|
|
142
|
-
blur: (
|
|
143
|
-
o == null || o(
|
|
155
|
+
d.domEventHandlers({
|
|
156
|
+
blur: (c, f) => {
|
|
157
|
+
o == null || o(f.state.doc.toString());
|
|
144
158
|
},
|
|
145
|
-
focus: (
|
|
146
|
-
|
|
159
|
+
focus: (c, f) => {
|
|
160
|
+
s == null || s(f.state.doc.toString());
|
|
147
161
|
}
|
|
148
162
|
}),
|
|
149
163
|
// Add Classes
|
|
150
|
-
|
|
151
|
-
...
|
|
164
|
+
d.editorAttributes.of({ class: t.join(" ") }),
|
|
165
|
+
...k
|
|
152
166
|
];
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
...
|
|
160
|
-
...
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
if (l && i.push(l), M || i.push(D), h ? i.push(d.editable.of(!1)) : i.push(
|
|
168
|
+
A(),
|
|
169
|
+
B(),
|
|
170
|
+
C(),
|
|
171
|
+
w(),
|
|
172
|
+
v.of([
|
|
173
|
+
...H,
|
|
174
|
+
...N,
|
|
175
|
+
j,
|
|
176
|
+
Q
|
|
163
177
|
])
|
|
164
|
-
),
|
|
165
|
-
|
|
178
|
+
), n && p[n] && i.push(p[n]()), S && n === "json") {
|
|
179
|
+
const c = I((f) => {
|
|
180
|
+
const a = [];
|
|
181
|
+
try {
|
|
182
|
+
JSON.parse(f.state.doc.toString());
|
|
183
|
+
} catch (g) {
|
|
184
|
+
g instanceof Error && a.push({
|
|
185
|
+
from: 0,
|
|
186
|
+
to: f.state.doc.length,
|
|
187
|
+
severity: "error",
|
|
188
|
+
message: g.message
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return a;
|
|
192
|
+
});
|
|
193
|
+
i.push(c);
|
|
194
|
+
}
|
|
195
|
+
return y && i.push(P()), x && i.push(G()), E && i.push(
|
|
196
|
+
v.of([
|
|
166
197
|
{
|
|
167
198
|
key: "Enter",
|
|
168
199
|
run: () => !0
|
|
@@ -177,8 +208,8 @@ function v({
|
|
|
177
208
|
run: () => !0
|
|
178
209
|
}
|
|
179
210
|
])
|
|
180
|
-
),
|
|
211
|
+
), i;
|
|
181
212
|
}
|
|
182
213
|
export {
|
|
183
|
-
|
|
214
|
+
le as useCodeMirror
|
|
184
215
|
};
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"vue",
|
|
17
17
|
"vue3"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.11.
|
|
19
|
+
"version": "0.11.5",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
],
|
|
32
32
|
"module": "dist/index.js",
|
|
33
33
|
"optionalDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"y-codemirror.next": "^0.3.2",
|
|
35
|
+
"yjs": "^13.6.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@codemirror/autocomplete": "^6.12.0",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"@codemirror/lang-json": "^6.0.0",
|
|
43
43
|
"@codemirror/lang-yaml": "^6.0.0",
|
|
44
44
|
"@codemirror/language": "^6.10.1",
|
|
45
|
+
"@codemirror/lint": "^6.8.1",
|
|
45
46
|
"@codemirror/state": "^6.4.0",
|
|
46
47
|
"@codemirror/view": "^6.23.1",
|
|
47
48
|
"@lezer/common": "^1.2.1",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"vue-tsc": "^2.0.13",
|
|
63
64
|
"y-codemirror.next": "^0.3.2",
|
|
64
65
|
"yjs": "^13.6.0",
|
|
65
|
-
"@scalar/build-tooling": "0.1.
|
|
66
|
+
"@scalar/build-tooling": "0.1.9"
|
|
66
67
|
},
|
|
67
68
|
"scripts": {
|
|
68
69
|
"build": "vite build && pnpm types:build && tsc-alias -p tsconfig.build.json",
|