@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
@@ -1,5 +1,17 @@
1
1
  # @scalar/use-codemirror
2
2
 
3
+ ## 0.11.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 9e3348a: feat: set placeholder usage
8
+
9
+ ## 0.11.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 6b32eee: feat: add json linter
14
+
3
15
  ## 0.11.4
4
16
 
5
17
  ### Patch Changes
@@ -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":"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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MAAM,KAAK,IAAI,CAAA;IAChD,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAmInC,CAAA"}
@@ -1,167 +1,209 @@
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";
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 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 = {
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
- }, oe = (e) => {
20
- const o = L(null);
21
- h(
20
+ }, de = (e) => {
21
+ const i = G(null);
22
+ m(
22
23
  e.codeMirrorRef,
23
24
  () => {
24
- var t;
25
- (t = o.value) == null || t.destroy(), l();
25
+ var o;
26
+ (o = i.value) == null || o.destroy(), l();
26
27
  },
27
28
  { immediate: !0 }
28
- ), P(() => {
29
- var t;
30
- return (t = o.value) == null ? void 0 : t.destroy();
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 t = u(e) ? i(e.provider) : null, f = v({
35
+ const o = u(e) ? t(e.provider) : null, h = x({
35
36
  ...s.value,
36
- provider: t
37
+ provider: o
37
38
  });
38
- o.value = new c({
39
+ i.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(t(e.content));
42
43
  }
43
44
  }
44
- const s = U(() => ({
45
+ const s = X(() => ({
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
+ 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
- h(
58
- () => u(e) ? i(e.provider) : null,
62
+ m(
63
+ () => u(e) ? t(e.provider) : null,
59
64
  () => {
60
- var t;
61
- u(e) && ((t = o.value) == null || t.destroy(), l());
65
+ var o;
66
+ u(e) && ((o = i.value) == null || o.destroy(), l());
62
67
  }
63
- ), h(
68
+ ), m(
64
69
  s,
65
70
  () => {
66
- if (o.value) {
67
- const t = u(e) ? i(e.provider) : null, f = v({
71
+ if (i.value) {
72
+ const o = u(e) ? t(e.provider) : null, h = x({
68
73
  ...s.value,
69
- provider: t
74
+ provider: o
70
75
  });
71
- o.value.dispatch({
72
- effects: A.reconfigure.of(f)
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 r = (t = "") => {
80
- o.value && o.value.state.doc.toString() !== t && o.value.dispatch({
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: o.value.state.doc.length,
84
- insert: t
88
+ to: i.value.state.doc.length,
89
+ insert: o
85
90
  },
86
91
  selection: {
87
92
  anchor: Math.min(
88
- o.value.state.selection.main.anchor,
89
- t.length
93
+ i.value.state.selection.main.anchor,
94
+ o.length
90
95
  )
91
96
  }
92
97
  });
93
98
  };
94
- return h(
95
- () => i(e.content),
99
+ return m(
100
+ () => t(e.content),
96
101
  () => {
97
- u(e) || r(i(e.content));
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: r,
107
+ setCodeMirrorContent: n,
103
108
  /** Codemirror instance */
104
- codeMirror: o
109
+ codeMirror: i
105
110
  };
106
- }, g = {
107
- html: N,
108
- json: T,
111
+ }, y = {
112
+ html: L,
113
+ json: R,
109
114
  yaml: V,
110
- css: H
115
+ css: K
111
116
  };
112
- function v({
117
+ function x({
113
118
  onChange: e,
114
- onBlur: o,
119
+ onBlur: i,
115
120
  onFocus: l,
116
121
  provider: s,
117
- language: r,
118
- 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 = []
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 n = [
127
- B(),
128
- K(O, { fallback: !0 }),
129
- c.theme({
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
- c.updateListener.of((d) => {
139
- d.docChanged && (e == null || e(d.state.doc.toString()));
158
+ d.updateListener.of((c) => {
159
+ c.docChanged && (e == null || e(c.state.doc.toString()));
140
160
  }),
141
- c.domEventHandlers({
142
- blur: (d, m) => {
143
- o == null || o(m.state.doc.toString());
161
+ d.domEventHandlers({
162
+ blur: (c, f) => {
163
+ i == null || i(f.state.doc.toString());
144
164
  },
145
- focus: (d, m) => {
146
- l == null || l(m.state.doc.toString());
165
+ focus: (c, f) => {
166
+ l == null || l(f.state.doc.toString());
147
167
  }
148
168
  }),
149
169
  // Add Classes
150
- c.editorAttributes.of({ class: t.join(" ") }),
151
- ...E
170
+ d.editorAttributes.of({ class: o.join(" ") }),
171
+ ...N
152
172
  ];
153
- return s && n.push(s), x || n.push(W), f ? n.push(c.editable.of(!1)) : n.push(
154
- R(),
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
- M(),
157
- k(),
177
+ a.of([...w, _]),
178
+ v()
179
+ ), M || r.push(B(), a.of([...I])), S ? r.push(
158
180
  a.of([
159
- ...C,
160
- ...S,
161
- w,
162
- z
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
- ), r && g[r] && n.push(g[r]()), p && n.push(I()), y && n.push(q()), b && n.push(
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
- ), n;
222
+ ), r;
181
223
  }
182
224
  export {
183
- oe as useCodeMirror
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.4",
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
- "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",