@scalar/use-codemirror 0.11.9 → 0.11.10
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 +6 -0
- package/dist/hooks/useCodeMirror.js +87 -86
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { autocompletion as
|
|
2
|
-
import { indentWithTab as
|
|
3
|
-
import { css as
|
|
4
|
-
import { html as
|
|
5
|
-
import { json as
|
|
6
|
-
import { xml as
|
|
7
|
-
import { yaml as
|
|
8
|
-
import { syntaxHighlighting as
|
|
9
|
-
import { linter as
|
|
10
|
-
import { StateEffect as
|
|
11
|
-
import { EditorView as h, highlightSpecialChars as
|
|
12
|
-
import { ref as
|
|
13
|
-
import { customTheme as
|
|
14
|
-
import { variables as
|
|
15
|
-
const d = (e) => "provider" in e && !!t(e.provider),
|
|
1
|
+
import { autocompletion as j, completionKeymap as B, closeBrackets as I, closeBracketsKeymap as O } from "@codemirror/autocomplete";
|
|
2
|
+
import { indentWithTab as K, insertNewline as L } from "@codemirror/commands";
|
|
3
|
+
import { css as R } from "@codemirror/lang-css";
|
|
4
|
+
import { html as V } from "@codemirror/lang-html";
|
|
5
|
+
import { json as A } from "@codemirror/lang-json";
|
|
6
|
+
import { xml as z } from "@codemirror/lang-xml";
|
|
7
|
+
import { yaml as J } from "@codemirror/lang-yaml";
|
|
8
|
+
import { syntaxHighlighting as P, defaultHighlightStyle as U, indentOnInput as W, bracketMatching as y } from "@codemirror/language";
|
|
9
|
+
import { linter as q } from "@codemirror/lint";
|
|
10
|
+
import { StateEffect as D } from "@codemirror/state";
|
|
11
|
+
import { EditorView as h, highlightSpecialChars as G, keymap as u, placeholder as Q, lineNumbers as X } from "@codemirror/view";
|
|
12
|
+
import { ref as Y, watch as m, onBeforeUnmount as Z, toValue as t, computed as _ } from "vue";
|
|
13
|
+
import { customTheme as $ } from "../themes/index.js";
|
|
14
|
+
import { variables as F } from "./variables.js";
|
|
15
|
+
const d = (e) => "provider" in e && !!t(e.provider), ee = {
|
|
16
16
|
key: "Mod-a",
|
|
17
17
|
run: (e) => (e.dispatch({
|
|
18
18
|
selection: { anchor: 0, head: e.state.doc.length },
|
|
19
19
|
scrollIntoView: !1
|
|
20
20
|
}), !0)
|
|
21
|
-
},
|
|
22
|
-
const
|
|
21
|
+
}, ge = (e) => {
|
|
22
|
+
const i = Y(null);
|
|
23
23
|
m(
|
|
24
24
|
e.codeMirrorRef,
|
|
25
25
|
() => {
|
|
26
26
|
var o;
|
|
27
|
-
(o =
|
|
27
|
+
(o = i.value) == null || o.destroy(), s();
|
|
28
28
|
},
|
|
29
29
|
{ immediate: !0 }
|
|
30
|
-
),
|
|
30
|
+
), Z(() => {
|
|
31
31
|
var o;
|
|
32
|
-
return (o =
|
|
32
|
+
return (o = i.value) == null ? void 0 : o.destroy();
|
|
33
33
|
});
|
|
34
|
-
function
|
|
34
|
+
function s() {
|
|
35
35
|
if (e.codeMirrorRef.value) {
|
|
36
|
-
const o = d(e) ? t(e.provider) : null, a =
|
|
37
|
-
...
|
|
36
|
+
const o = d(e) ? t(e.provider) : null, a = E({
|
|
37
|
+
...l.value,
|
|
38
38
|
provider: o
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
i.value = new h({
|
|
41
41
|
parent: e.codeMirrorRef.value,
|
|
42
42
|
extensions: a
|
|
43
43
|
}), d(e) || n(t(e.content));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const l = _(() => ({
|
|
47
47
|
onChange: e.onChange,
|
|
48
48
|
onBlur: e.onBlur,
|
|
49
49
|
onFocus: e.onFocus,
|
|
@@ -64,18 +64,18 @@ const d = (e) => "provider" in e && !!t(e.provider), F = {
|
|
|
64
64
|
() => d(e) ? t(e.provider) : null,
|
|
65
65
|
() => {
|
|
66
66
|
var o;
|
|
67
|
-
d(e) && ((o =
|
|
67
|
+
d(e) && ((o = i.value) == null || o.destroy(), s());
|
|
68
68
|
}
|
|
69
69
|
), m(
|
|
70
|
-
|
|
70
|
+
l,
|
|
71
71
|
() => {
|
|
72
|
-
if (
|
|
73
|
-
const o = d(e) ? t(e.provider) : null, a =
|
|
74
|
-
...
|
|
72
|
+
if (i.value) {
|
|
73
|
+
const o = d(e) ? t(e.provider) : null, a = E({
|
|
74
|
+
...l.value,
|
|
75
75
|
provider: o
|
|
76
76
|
});
|
|
77
|
-
|
|
78
|
-
effects:
|
|
77
|
+
i.value.dispatch({
|
|
78
|
+
effects: D.reconfigure.of(a)
|
|
79
79
|
});
|
|
80
80
|
} else
|
|
81
81
|
return;
|
|
@@ -83,15 +83,15 @@ const d = (e) => "provider" in e && !!t(e.provider), F = {
|
|
|
83
83
|
{ immediate: !0 }
|
|
84
84
|
);
|
|
85
85
|
const n = (o = "") => {
|
|
86
|
-
|
|
86
|
+
i.value && i.value.state.doc.toString() !== o && i.value.dispatch({
|
|
87
87
|
changes: {
|
|
88
88
|
from: 0,
|
|
89
|
-
to:
|
|
89
|
+
to: i.value.state.doc.length,
|
|
90
90
|
insert: o
|
|
91
91
|
},
|
|
92
92
|
selection: {
|
|
93
93
|
anchor: Math.min(
|
|
94
|
-
|
|
94
|
+
i.value.state.selection.main.anchor,
|
|
95
95
|
o.length
|
|
96
96
|
)
|
|
97
97
|
}
|
|
@@ -107,36 +107,36 @@ const d = (e) => "provider" in e && !!t(e.provider), F = {
|
|
|
107
107
|
/** Replaces the current content with the given value. */
|
|
108
108
|
setCodeMirrorContent: n,
|
|
109
109
|
/** Codemirror instance */
|
|
110
|
-
codeMirror:
|
|
110
|
+
codeMirror: i
|
|
111
111
|
};
|
|
112
|
-
},
|
|
113
|
-
html:
|
|
114
|
-
json:
|
|
115
|
-
yaml:
|
|
116
|
-
css:
|
|
117
|
-
xml:
|
|
112
|
+
}, x = {
|
|
113
|
+
html: V,
|
|
114
|
+
json: A,
|
|
115
|
+
yaml: J,
|
|
116
|
+
css: R,
|
|
117
|
+
xml: z
|
|
118
118
|
};
|
|
119
|
-
function
|
|
119
|
+
function E({
|
|
120
120
|
onChange: e,
|
|
121
|
-
onBlur:
|
|
122
|
-
onFocus:
|
|
123
|
-
provider:
|
|
121
|
+
onBlur: i,
|
|
122
|
+
onFocus: s,
|
|
123
|
+
provider: l,
|
|
124
124
|
language: n,
|
|
125
125
|
classes: o = [],
|
|
126
126
|
readOnly: a = !1,
|
|
127
|
-
lineNumbers:
|
|
128
|
-
withVariables:
|
|
129
|
-
disableEnter:
|
|
130
|
-
disableCloseBrackets:
|
|
131
|
-
disableTabIndent:
|
|
132
|
-
withoutTheme:
|
|
133
|
-
lint:
|
|
134
|
-
additionalExtensions:
|
|
127
|
+
lineNumbers: k = !1,
|
|
128
|
+
withVariables: C = !1,
|
|
129
|
+
disableEnter: M = !1,
|
|
130
|
+
disableCloseBrackets: S = !1,
|
|
131
|
+
disableTabIndent: T = !1,
|
|
132
|
+
withoutTheme: N = !1,
|
|
133
|
+
lint: w = !1,
|
|
134
|
+
additionalExtensions: H = [],
|
|
135
135
|
placeholder: g
|
|
136
136
|
}) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
const r = [
|
|
138
|
+
G(),
|
|
139
|
+
P(U, { fallback: !0 }),
|
|
140
140
|
h.theme({
|
|
141
141
|
".cm-line": {
|
|
142
142
|
lineHeight: "20px"
|
|
@@ -162,23 +162,23 @@ function x({
|
|
|
162
162
|
}),
|
|
163
163
|
h.domEventHandlers({
|
|
164
164
|
blur: (f, c) => {
|
|
165
|
-
|
|
165
|
+
i == null || i(c.state.doc.toString());
|
|
166
166
|
},
|
|
167
167
|
focus: (f, c) => {
|
|
168
|
-
|
|
168
|
+
s == null || s(c.state.doc.toString());
|
|
169
169
|
}
|
|
170
170
|
}),
|
|
171
171
|
// Add Classes
|
|
172
172
|
h.editorAttributes.of({ class: o.join(" ") }),
|
|
173
|
-
...
|
|
173
|
+
...H
|
|
174
174
|
];
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
u.of([...
|
|
180
|
-
|
|
181
|
-
),
|
|
175
|
+
if (l && r.push(l), N || r.push($), a ? r.push(h.editable.of(!1)) : (r.push(
|
|
176
|
+
W(),
|
|
177
|
+
y(),
|
|
178
|
+
j(),
|
|
179
|
+
u.of([...B, ee]),
|
|
180
|
+
y()
|
|
181
|
+
), S || r.push(I(), u.of([...O])), T ? r.push(
|
|
182
182
|
u.of([
|
|
183
183
|
{
|
|
184
184
|
key: "Tab",
|
|
@@ -188,24 +188,25 @@ function x({
|
|
|
188
188
|
// Prevent default Shift+Tab behavior
|
|
189
189
|
}
|
|
190
190
|
])
|
|
191
|
-
) :
|
|
192
|
-
const f =
|
|
193
|
-
const p = [];
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
) : r.push(u.of([K]))), g && r.push(Q(g)), n && x[n] && r.push(x[n]()), w && n === "json") {
|
|
192
|
+
const f = q((c) => {
|
|
193
|
+
const p = [], b = c.state.doc.toString();
|
|
194
|
+
if (b.trim())
|
|
195
|
+
try {
|
|
196
|
+
JSON.parse(b);
|
|
197
|
+
} catch (v) {
|
|
198
|
+
v instanceof Error && p.push({
|
|
199
|
+
from: 0,
|
|
200
|
+
to: c.state.doc.length,
|
|
201
|
+
severity: "error",
|
|
202
|
+
message: v.message
|
|
203
|
+
});
|
|
204
|
+
}
|
|
204
205
|
return p;
|
|
205
206
|
});
|
|
206
|
-
|
|
207
|
+
r.push(f);
|
|
207
208
|
}
|
|
208
|
-
return
|
|
209
|
+
return k && r.push(X()), C && r.push(F()), M ? r.push(
|
|
209
210
|
u.of([
|
|
210
211
|
{
|
|
211
212
|
key: "Enter",
|
|
@@ -221,15 +222,15 @@ function x({
|
|
|
221
222
|
run: () => !0
|
|
222
223
|
}
|
|
223
224
|
])
|
|
224
|
-
) :
|
|
225
|
+
) : r.push(
|
|
225
226
|
u.of([
|
|
226
227
|
{
|
|
227
228
|
key: "Enter",
|
|
228
|
-
run:
|
|
229
|
+
run: L
|
|
229
230
|
}
|
|
230
231
|
])
|
|
231
|
-
),
|
|
232
|
+
), r;
|
|
232
233
|
}
|
|
233
234
|
export {
|
|
234
|
-
|
|
235
|
+
ge as useCodeMirror
|
|
235
236
|
};
|