@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
@@ -1,5 +1,11 @@
1
1
  # @scalar/use-codemirror
2
2
 
3
+ ## 0.11.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 6b32eee: feat: add json linter
8
+
3
9
  ## 0.11.4
4
10
 
5
11
  ### Patch Changes
@@ -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":"AAmBA,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,GAAG,SAAS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E,MAAM,KAAK,IAAI,CAAA;CAC9B,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;CAgInC,CAAA"}
@@ -1,82 +1,84 @@
1
- import { autocompletion as M, closeBrackets as k, completionKeymap as C, closeBracketsKeymap as S } from "@codemirror/autocomplete";
2
- import { indentWithTab as w } from "@codemirror/commands";
3
- import { css as H } from "@codemirror/lang-css";
4
- import { html as N } from "@codemirror/lang-html";
5
- import { json as T } from "@codemirror/lang-json";
6
- import { yaml as V } from "@codemirror/lang-yaml";
7
- import { syntaxHighlighting as K, defaultHighlightStyle as O, indentOnInput as R, bracketMatching as j } from "@codemirror/language";
8
- import { StateEffect as A } from "@codemirror/state";
9
- import { EditorView as c, highlightSpecialChars as B, keymap as a, lineNumbers as I } from "@codemirror/view";
10
- import { ref as L, watch as h, onBeforeUnmount as P, toValue as i, computed as U } from "vue";
11
- import { customTheme as W } from "../themes/index.js";
12
- import { variables as q } from "./variables.js";
13
- const u = (e) => "provider" in e && !!i(e.provider), z = {
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
- }, oe = (e) => {
20
- const o = L(null);
21
- h(
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(), l();
26
+ (t = o.value) == null || t.destroy(), s();
26
27
  },
27
28
  { immediate: !0 }
28
- ), P(() => {
29
+ ), W(() => {
29
30
  var t;
30
31
  return (t = o.value) == null ? void 0 : t.destroy();
31
32
  });
32
- function l() {
33
+ function s() {
33
34
  if (e.codeMirrorRef.value) {
34
- const t = u(e) ? i(e.provider) : null, f = v({
35
- ...s.value,
35
+ const t = u(e) ? r(e.provider) : null, h = b({
36
+ ...l.value,
36
37
  provider: t
37
38
  });
38
- o.value = new c({
39
+ o.value = new d({
39
40
  parent: e.codeMirrorRef.value,
40
- extensions: f
41
- }), u(e) || r(i(e.content));
41
+ extensions: h
42
+ }), u(e) || n(r(e.content));
42
43
  }
43
44
  }
44
- const s = U(() => ({
45
+ const l = q(() => ({
45
46
  onChange: e.onChange,
46
47
  onBlur: e.onBlur,
47
48
  onFocus: e.onFocus,
48
- language: i(e.language),
49
- classes: i(e.classes),
50
- readOnly: i(e.readOnly),
51
- lineNumbers: i(e.lineNumbers),
52
- withVariables: i(e.withVariables),
53
- disableEnter: i(e.withVariables),
54
- withoutTheme: i(e.withoutTheme),
55
- additionalExtensions: i(e.extensions)
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
- h(
58
- () => u(e) ? i(e.provider) : null,
59
+ m(
60
+ () => u(e) ? r(e.provider) : null,
59
61
  () => {
60
62
  var t;
61
- u(e) && ((t = o.value) == null || t.destroy(), l());
63
+ u(e) && ((t = o.value) == null || t.destroy(), s());
62
64
  }
63
- ), h(
64
- s,
65
+ ), m(
66
+ l,
65
67
  () => {
66
68
  if (o.value) {
67
- const t = u(e) ? i(e.provider) : null, f = v({
68
- ...s.value,
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: A.reconfigure.of(f)
74
+ effects: z.reconfigure.of(h)
73
75
  });
74
76
  } else
75
77
  return;
76
78
  },
77
79
  { immediate: !0 }
78
80
  );
79
- const r = (t = "") => {
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 h(
95
- () => i(e.content),
96
+ return m(
97
+ () => r(e.content),
96
98
  () => {
97
- u(e) || r(i(e.content));
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: r,
104
+ setCodeMirrorContent: n,
103
105
  /** Codemirror instance */
104
106
  codeMirror: o
105
107
  };
106
- }, g = {
107
- html: N,
108
- json: T,
109
- yaml: V,
110
- css: H
108
+ }, p = {
109
+ html: T,
110
+ json: V,
111
+ yaml: K,
112
+ css: O
111
113
  };
112
- function v({
114
+ function b({
113
115
  onChange: e,
114
116
  onBlur: o,
115
- onFocus: l,
116
- provider: s,
117
- language: r,
117
+ onFocus: s,
118
+ provider: l,
119
+ language: n,
118
120
  classes: t = [],
119
- readOnly: f = !1,
120
- lineNumbers: p = !1,
121
- withVariables: y = !1,
122
- disableEnter: b = !1,
123
- withoutTheme: x = !1,
124
- additionalExtensions: E = []
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 n = [
127
- B(),
128
- K(O, { fallback: !0 }),
129
- c.theme({
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
- c.updateListener.of((d) => {
139
- d.docChanged && (e == null || e(d.state.doc.toString()));
152
+ d.updateListener.of((c) => {
153
+ c.docChanged && (e == null || e(c.state.doc.toString()));
140
154
  }),
141
- c.domEventHandlers({
142
- blur: (d, m) => {
143
- o == null || o(m.state.doc.toString());
155
+ d.domEventHandlers({
156
+ blur: (c, f) => {
157
+ o == null || o(f.state.doc.toString());
144
158
  },
145
- focus: (d, m) => {
146
- l == null || l(m.state.doc.toString());
159
+ focus: (c, f) => {
160
+ s == null || s(f.state.doc.toString());
147
161
  }
148
162
  }),
149
163
  // Add Classes
150
- c.editorAttributes.of({ class: t.join(" ") }),
151
- ...E
164
+ d.editorAttributes.of({ class: t.join(" ") }),
165
+ ...k
152
166
  ];
153
- return s && n.push(s), x || n.push(W), f ? n.push(c.editable.of(!1)) : n.push(
154
- R(),
155
- j(),
156
- M(),
157
- k(),
158
- a.of([
159
- ...C,
160
- ...S,
161
- w,
162
- z
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
- ), r && g[r] && n.push(g[r]()), p && n.push(I()), y && n.push(q()), b && n.push(
165
- a.of([
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
- ), n;
211
+ ), i;
181
212
  }
182
213
  export {
183
- oe as useCodeMirror
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.4",
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
- "yjs": "^13.6.0",
35
- "y-codemirror.next": "^0.3.2"
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.7"
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",