@scalar/use-codemirror 0.11.4 → 0.11.6
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
|
@@ -15,12 +15,18 @@ type BaseParameters = {
|
|
|
15
15
|
classes?: MaybeRefOrGetter<string[] | undefined>;
|
|
16
16
|
/** Put the editor into read-only mode */
|
|
17
17
|
readOnly?: MaybeRefOrGetter<boolean | undefined>;
|
|
18
|
+
/** Disable indent with tab */
|
|
19
|
+
disableTabIndent?: MaybeRefOrGetter<boolean | undefined>;
|
|
18
20
|
/** Option to show line numbers in the editor */
|
|
19
21
|
lineNumbers?: MaybeRefOrGetter<boolean | undefined>;
|
|
20
22
|
withVariables?: MaybeRefOrGetter<boolean | undefined>;
|
|
21
23
|
disableEnter?: MaybeRefOrGetter<boolean | undefined>;
|
|
24
|
+
disableCloseBrackets?: MaybeRefOrGetter<boolean | undefined>;
|
|
25
|
+
/** Option to lint and show error in the editor */
|
|
26
|
+
lint?: MaybeRefOrGetter<boolean | undefined>;
|
|
22
27
|
onBlur?: (v: string) => void;
|
|
23
28
|
onFocus?: (v: string) => void;
|
|
29
|
+
placeholder?: MaybeRefOrGetter<string | undefined>;
|
|
24
30
|
};
|
|
25
31
|
export type UseCodeMirrorParameters = (BaseParameters & {
|
|
26
32
|
/** Prefill the content. Will be ignored when a provider is given. */
|
|
@@ -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,EAMX,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,GAAG,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AAC,MAAM,GAAG,SAAS,CAAC,CAAA;CACnD,CAAA;AAED,MAAM,MAAM,uBAAuB,GAC/B,CAAC,cAAc,GAAG;IAChB,qEAAqE;IACrE,OAAO,EAAE,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC7C,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9B,CAAC,GACF,CAAC,cAAc,GAAG;IAChB,QAAQ,EAAE,gBAAgB,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IAC5C,OAAO,CAAC,EAAE,gBAAgB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAC9C,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC/B,CAAC,CAAA;AAsBN,sCAAsC;AACtC,eAAO,MAAM,aAAa,WAChB,uBAAuB,KAC9B;IACD,oBAAoB,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAmInC,CAAA"}
|
|
@@ -1,167 +1,209 @@
|
|
|
1
|
-
import { autocompletion as
|
|
2
|
-
import { indentWithTab as
|
|
3
|
-
import { css as
|
|
4
|
-
import { html as
|
|
5
|
-
import { json as
|
|
1
|
+
import { autocompletion as j, completionKeymap as w, closeBrackets as B, closeBracketsKeymap as I } from "@codemirror/autocomplete";
|
|
2
|
+
import { indentWithTab as O } from "@codemirror/commands";
|
|
3
|
+
import { css as K } from "@codemirror/lang-css";
|
|
4
|
+
import { html as L } from "@codemirror/lang-html";
|
|
5
|
+
import { json as R } from "@codemirror/lang-json";
|
|
6
6
|
import { yaml as V } from "@codemirror/lang-yaml";
|
|
7
|
-
import { syntaxHighlighting as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
7
|
+
import { syntaxHighlighting as A, defaultHighlightStyle as z, indentOnInput as J, bracketMatching as v } from "@codemirror/language";
|
|
8
|
+
import { linter as P } from "@codemirror/lint";
|
|
9
|
+
import { StateEffect as U } from "@codemirror/state";
|
|
10
|
+
import { EditorView as d, highlightSpecialChars as W, keymap as a, placeholder as q, lineNumbers as D } from "@codemirror/view";
|
|
11
|
+
import { ref as G, watch as m, onBeforeUnmount as Q, toValue as t, computed as X } from "vue";
|
|
12
|
+
import { customTheme as Y } from "../themes/index.js";
|
|
13
|
+
import { variables as Z } from "./variables.js";
|
|
14
|
+
const u = (e) => "provider" in e && !!t(e.provider), _ = {
|
|
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
|
|
21
|
-
|
|
20
|
+
}, de = (e) => {
|
|
21
|
+
const i = G(null);
|
|
22
|
+
m(
|
|
22
23
|
e.codeMirrorRef,
|
|
23
24
|
() => {
|
|
24
|
-
var
|
|
25
|
-
(
|
|
25
|
+
var o;
|
|
26
|
+
(o = i.value) == null || o.destroy(), l();
|
|
26
27
|
},
|
|
27
28
|
{ immediate: !0 }
|
|
28
|
-
),
|
|
29
|
-
var
|
|
30
|
-
return (
|
|
29
|
+
), Q(() => {
|
|
30
|
+
var o;
|
|
31
|
+
return (o = i.value) == null ? void 0 : o.destroy();
|
|
31
32
|
});
|
|
32
33
|
function l() {
|
|
33
34
|
if (e.codeMirrorRef.value) {
|
|
34
|
-
const
|
|
35
|
+
const o = u(e) ? t(e.provider) : null, h = x({
|
|
35
36
|
...s.value,
|
|
36
|
-
provider:
|
|
37
|
+
provider: o
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
+
i.value = new d({
|
|
39
40
|
parent: e.codeMirrorRef.value,
|
|
40
|
-
extensions:
|
|
41
|
-
}), u(e) ||
|
|
41
|
+
extensions: h
|
|
42
|
+
}), u(e) || n(t(e.content));
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
const s =
|
|
45
|
+
const s = X(() => ({
|
|
45
46
|
onChange: e.onChange,
|
|
46
47
|
onBlur: e.onBlur,
|
|
47
48
|
onFocus: e.onFocus,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
disableTabIndent: t(e.disableTabIndent),
|
|
50
|
+
language: t(e.language),
|
|
51
|
+
classes: t(e.classes),
|
|
52
|
+
readOnly: t(e.readOnly),
|
|
53
|
+
lineNumbers: t(e.lineNumbers),
|
|
54
|
+
withVariables: t(e.withVariables),
|
|
55
|
+
disableEnter: t(e.disableEnter),
|
|
56
|
+
disableCloseBrackets: t(e.disableCloseBrackets),
|
|
57
|
+
withoutTheme: t(e.withoutTheme),
|
|
58
|
+
lint: t(e.lint),
|
|
59
|
+
additionalExtensions: t(e.extensions),
|
|
60
|
+
placeholder: t(e.placeholder)
|
|
56
61
|
}));
|
|
57
|
-
|
|
58
|
-
() => u(e) ?
|
|
62
|
+
m(
|
|
63
|
+
() => u(e) ? t(e.provider) : null,
|
|
59
64
|
() => {
|
|
60
|
-
var
|
|
61
|
-
u(e) && ((
|
|
65
|
+
var o;
|
|
66
|
+
u(e) && ((o = i.value) == null || o.destroy(), l());
|
|
62
67
|
}
|
|
63
|
-
),
|
|
68
|
+
), m(
|
|
64
69
|
s,
|
|
65
70
|
() => {
|
|
66
|
-
if (
|
|
67
|
-
const
|
|
71
|
+
if (i.value) {
|
|
72
|
+
const o = u(e) ? t(e.provider) : null, h = x({
|
|
68
73
|
...s.value,
|
|
69
|
-
provider:
|
|
74
|
+
provider: o
|
|
70
75
|
});
|
|
71
|
-
|
|
72
|
-
effects:
|
|
76
|
+
i.value.dispatch({
|
|
77
|
+
effects: U.reconfigure.of(h)
|
|
73
78
|
});
|
|
74
79
|
} else
|
|
75
80
|
return;
|
|
76
81
|
},
|
|
77
82
|
{ immediate: !0 }
|
|
78
83
|
);
|
|
79
|
-
const
|
|
80
|
-
|
|
84
|
+
const n = (o = "") => {
|
|
85
|
+
i.value && i.value.state.doc.toString() !== o && i.value.dispatch({
|
|
81
86
|
changes: {
|
|
82
87
|
from: 0,
|
|
83
|
-
to:
|
|
84
|
-
insert:
|
|
88
|
+
to: i.value.state.doc.length,
|
|
89
|
+
insert: o
|
|
85
90
|
},
|
|
86
91
|
selection: {
|
|
87
92
|
anchor: Math.min(
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
i.value.state.selection.main.anchor,
|
|
94
|
+
o.length
|
|
90
95
|
)
|
|
91
96
|
}
|
|
92
97
|
});
|
|
93
98
|
};
|
|
94
|
-
return
|
|
95
|
-
() =>
|
|
99
|
+
return m(
|
|
100
|
+
() => t(e.content),
|
|
96
101
|
() => {
|
|
97
|
-
u(e) ||
|
|
102
|
+
u(e) || n(t(e.content));
|
|
98
103
|
},
|
|
99
104
|
{ immediate: !0 }
|
|
100
105
|
), {
|
|
101
106
|
/** Replaces the current content with the given value. */
|
|
102
|
-
setCodeMirrorContent:
|
|
107
|
+
setCodeMirrorContent: n,
|
|
103
108
|
/** Codemirror instance */
|
|
104
|
-
codeMirror:
|
|
109
|
+
codeMirror: i
|
|
105
110
|
};
|
|
106
|
-
},
|
|
107
|
-
html:
|
|
108
|
-
json:
|
|
111
|
+
}, y = {
|
|
112
|
+
html: L,
|
|
113
|
+
json: R,
|
|
109
114
|
yaml: V,
|
|
110
|
-
css:
|
|
115
|
+
css: K
|
|
111
116
|
};
|
|
112
|
-
function
|
|
117
|
+
function x({
|
|
113
118
|
onChange: e,
|
|
114
|
-
onBlur:
|
|
119
|
+
onBlur: i,
|
|
115
120
|
onFocus: l,
|
|
116
121
|
provider: s,
|
|
117
|
-
language:
|
|
118
|
-
classes:
|
|
119
|
-
readOnly:
|
|
120
|
-
lineNumbers:
|
|
121
|
-
withVariables:
|
|
122
|
-
disableEnter:
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
language: n,
|
|
123
|
+
classes: o = [],
|
|
124
|
+
readOnly: h = !1,
|
|
125
|
+
lineNumbers: E = !1,
|
|
126
|
+
withVariables: k = !1,
|
|
127
|
+
disableEnter: C = !1,
|
|
128
|
+
disableCloseBrackets: M = !1,
|
|
129
|
+
disableTabIndent: S = !1,
|
|
130
|
+
withoutTheme: T = !1,
|
|
131
|
+
lint: H = !1,
|
|
132
|
+
additionalExtensions: N = [],
|
|
133
|
+
placeholder: g
|
|
125
134
|
}) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
const r = [
|
|
136
|
+
W(),
|
|
137
|
+
A(z, { fallback: !0 }),
|
|
138
|
+
d.theme({
|
|
130
139
|
".cm-line": {
|
|
131
140
|
lineHeight: "20px"
|
|
132
141
|
},
|
|
133
142
|
".cm-gutterElement": {
|
|
134
143
|
lineHeight: "20px"
|
|
144
|
+
},
|
|
145
|
+
".cm-tooltip": {
|
|
146
|
+
border: "1px solid #f5c6cb",
|
|
147
|
+
fontSize: "12px"
|
|
148
|
+
},
|
|
149
|
+
".cm-tooltip-lint": {
|
|
150
|
+
backgroundColor: "#ffffff"
|
|
151
|
+
},
|
|
152
|
+
".cm-diagnostic-error": {
|
|
153
|
+
borderLeft: "0",
|
|
154
|
+
color: "#dc1b19"
|
|
135
155
|
}
|
|
136
156
|
}),
|
|
137
157
|
// Listen to updates
|
|
138
|
-
|
|
139
|
-
|
|
158
|
+
d.updateListener.of((c) => {
|
|
159
|
+
c.docChanged && (e == null || e(c.state.doc.toString()));
|
|
140
160
|
}),
|
|
141
|
-
|
|
142
|
-
blur: (
|
|
143
|
-
|
|
161
|
+
d.domEventHandlers({
|
|
162
|
+
blur: (c, f) => {
|
|
163
|
+
i == null || i(f.state.doc.toString());
|
|
144
164
|
},
|
|
145
|
-
focus: (
|
|
146
|
-
l == null || l(
|
|
165
|
+
focus: (c, f) => {
|
|
166
|
+
l == null || l(f.state.doc.toString());
|
|
147
167
|
}
|
|
148
168
|
}),
|
|
149
169
|
// Add Classes
|
|
150
|
-
|
|
151
|
-
...
|
|
170
|
+
d.editorAttributes.of({ class: o.join(" ") }),
|
|
171
|
+
...N
|
|
152
172
|
];
|
|
153
|
-
|
|
154
|
-
|
|
173
|
+
if (s && r.push(s), T || r.push(Y), h ? r.push(d.editable.of(!1)) : (r.push(
|
|
174
|
+
J(),
|
|
175
|
+
v(),
|
|
155
176
|
j(),
|
|
156
|
-
|
|
157
|
-
|
|
177
|
+
a.of([...w, _]),
|
|
178
|
+
v()
|
|
179
|
+
), M || r.push(B(), a.of([...I])), S ? r.push(
|
|
158
180
|
a.of([
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
181
|
+
{
|
|
182
|
+
key: "Tab",
|
|
183
|
+
run: () => !1,
|
|
184
|
+
// Prevent default Tab behavior
|
|
185
|
+
shift: () => !1
|
|
186
|
+
// Prevent default Shift+Tab behavior
|
|
187
|
+
}
|
|
163
188
|
])
|
|
164
|
-
)
|
|
189
|
+
) : r.push(a.of([O]))), g && r.push(q(g)), n && y[n] && r.push(y[n]()), H && n === "json") {
|
|
190
|
+
const c = P((f) => {
|
|
191
|
+
const b = [];
|
|
192
|
+
try {
|
|
193
|
+
JSON.parse(f.state.doc.toString());
|
|
194
|
+
} catch (p) {
|
|
195
|
+
p instanceof Error && b.push({
|
|
196
|
+
from: 0,
|
|
197
|
+
to: f.state.doc.length,
|
|
198
|
+
severity: "error",
|
|
199
|
+
message: p.message
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return b;
|
|
203
|
+
});
|
|
204
|
+
r.push(c);
|
|
205
|
+
}
|
|
206
|
+
return E && r.push(D()), k && r.push(Z()), C && r.push(
|
|
165
207
|
a.of([
|
|
166
208
|
{
|
|
167
209
|
key: "Enter",
|
|
@@ -177,8 +219,8 @@ function v({
|
|
|
177
219
|
run: () => !0
|
|
178
220
|
}
|
|
179
221
|
])
|
|
180
|
-
),
|
|
222
|
+
), r;
|
|
181
223
|
}
|
|
182
224
|
export {
|
|
183
|
-
|
|
225
|
+
de as useCodeMirror
|
|
184
226
|
};
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"vue",
|
|
17
17
|
"vue3"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.11.
|
|
19
|
+
"version": "0.11.6",
|
|
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",
|