@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scalar/use-codemirror
2
2
 
3
+ ## 0.11.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e5de89: fix: lint only if content is given
8
+
3
9
  ## 0.11.9
4
10
 
5
11
  ### Patch Changes
@@ -1,49 +1,49 @@
1
- import { autocompletion as H, completionKeymap as j, closeBrackets as B, closeBracketsKeymap as I } from "@codemirror/autocomplete";
2
- import { indentWithTab as O, insertNewline as K } from "@codemirror/commands";
3
- import { css as L } from "@codemirror/lang-css";
4
- import { html as R } from "@codemirror/lang-html";
5
- import { json as V } from "@codemirror/lang-json";
6
- import { xml as A } from "@codemirror/lang-xml";
7
- import { yaml as z } from "@codemirror/lang-yaml";
8
- import { syntaxHighlighting as J, defaultHighlightStyle as P, indentOnInput as U, bracketMatching as v } from "@codemirror/language";
9
- import { linter as W } from "@codemirror/lint";
10
- import { StateEffect as q } from "@codemirror/state";
11
- import { EditorView as h, highlightSpecialChars as D, keymap as u, placeholder as G, lineNumbers as Q } from "@codemirror/view";
12
- import { ref as X, watch as m, onBeforeUnmount as Y, toValue as t, computed as Z } from "vue";
13
- import { customTheme as _ } from "../themes/index.js";
14
- import { variables as $ } from "./variables.js";
15
- const d = (e) => "provider" in e && !!t(e.provider), F = {
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
- }, me = (e) => {
22
- const r = X(null);
21
+ }, ge = (e) => {
22
+ const i = Y(null);
23
23
  m(
24
24
  e.codeMirrorRef,
25
25
  () => {
26
26
  var o;
27
- (o = r.value) == null || o.destroy(), l();
27
+ (o = i.value) == null || o.destroy(), s();
28
28
  },
29
29
  { immediate: !0 }
30
- ), Y(() => {
30
+ ), Z(() => {
31
31
  var o;
32
- return (o = r.value) == null ? void 0 : o.destroy();
32
+ return (o = i.value) == null ? void 0 : o.destroy();
33
33
  });
34
- function l() {
34
+ function s() {
35
35
  if (e.codeMirrorRef.value) {
36
- const o = d(e) ? t(e.provider) : null, a = x({
37
- ...s.value,
36
+ const o = d(e) ? t(e.provider) : null, a = E({
37
+ ...l.value,
38
38
  provider: o
39
39
  });
40
- r.value = new h({
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 s = Z(() => ({
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 = r.value) == null || o.destroy(), l());
67
+ d(e) && ((o = i.value) == null || o.destroy(), s());
68
68
  }
69
69
  ), m(
70
- s,
70
+ l,
71
71
  () => {
72
- if (r.value) {
73
- const o = d(e) ? t(e.provider) : null, a = x({
74
- ...s.value,
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
- r.value.dispatch({
78
- effects: q.reconfigure.of(a)
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
- r.value && r.value.state.doc.toString() !== o && r.value.dispatch({
86
+ i.value && i.value.state.doc.toString() !== o && i.value.dispatch({
87
87
  changes: {
88
88
  from: 0,
89
- to: r.value.state.doc.length,
89
+ to: i.value.state.doc.length,
90
90
  insert: o
91
91
  },
92
92
  selection: {
93
93
  anchor: Math.min(
94
- r.value.state.selection.main.anchor,
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: r
110
+ codeMirror: i
111
111
  };
112
- }, y = {
113
- html: R,
114
- json: V,
115
- yaml: z,
116
- css: L,
117
- xml: A
112
+ }, x = {
113
+ html: V,
114
+ json: A,
115
+ yaml: J,
116
+ css: R,
117
+ xml: z
118
118
  };
119
- function x({
119
+ function E({
120
120
  onChange: e,
121
- onBlur: r,
122
- onFocus: l,
123
- provider: s,
121
+ onBlur: i,
122
+ onFocus: s,
123
+ provider: l,
124
124
  language: n,
125
125
  classes: o = [],
126
126
  readOnly: a = !1,
127
- lineNumbers: E = !1,
128
- withVariables: k = !1,
129
- disableEnter: C = !1,
130
- disableCloseBrackets: M = !1,
131
- disableTabIndent: S = !1,
132
- withoutTheme: T = !1,
133
- lint: N = !1,
134
- additionalExtensions: w = [],
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 i = [
138
- D(),
139
- J(P, { fallback: !0 }),
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
- r == null || r(c.state.doc.toString());
165
+ i == null || i(c.state.doc.toString());
166
166
  },
167
167
  focus: (f, c) => {
168
- l == null || l(c.state.doc.toString());
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
- ...w
173
+ ...H
174
174
  ];
175
- if (s && i.push(s), T || i.push(_), a ? i.push(h.editable.of(!1)) : (i.push(
176
- U(),
177
- v(),
178
- H(),
179
- u.of([...j, F]),
180
- v()
181
- ), M || i.push(B(), u.of([...I])), S ? i.push(
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
- ) : i.push(u.of([O]))), g && i.push(G(g)), n && y[n] && i.push(y[n]()), N && n === "json") {
192
- const f = W((c) => {
193
- const p = [];
194
- try {
195
- JSON.parse(c.state.doc.toString());
196
- } catch (b) {
197
- b instanceof Error && p.push({
198
- from: 0,
199
- to: c.state.doc.length,
200
- severity: "error",
201
- message: b.message
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
- i.push(f);
207
+ r.push(f);
207
208
  }
208
- return E && i.push(Q()), k && i.push($()), C ? i.push(
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
- ) : i.push(
225
+ ) : r.push(
225
226
  u.of([
226
227
  {
227
228
  key: "Enter",
228
- run: K
229
+ run: L
229
230
  }
230
231
  ])
231
- ), i;
232
+ ), r;
232
233
  }
233
234
  export {
234
- me as useCodeMirror
235
+ ge as useCodeMirror
235
236
  };
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "vue",
17
17
  "vue3"
18
18
  ],
19
- "version": "0.11.9",
19
+ "version": "0.11.10",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },