@scalar/use-codemirror 0.11.5 → 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,11 @@
1
1
  # @scalar/use-codemirror
2
2
 
3
+ ## 0.11.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 9e3348a: feat: set placeholder usage
8
+
3
9
  ## 0.11.5
4
10
 
5
11
  ### Patch Changes
@@ -15,14 +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>;
22
25
  /** Option to lint and show error in the editor */
23
26
  lint?: MaybeRefOrGetter<boolean | undefined>;
24
27
  onBlur?: (v: string) => void;
25
28
  onFocus?: (v: string) => void;
29
+ placeholder?: MaybeRefOrGetter<string | undefined>;
26
30
  };
27
31
  export type UseCodeMirrorParameters = (BaseParameters & {
28
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":"AAoBA,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,MA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AO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAChD,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAmInC,CAAA"}
@@ -1,134 +1,140 @@
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 = {
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
+ import { yaml as V } from "@codemirror/lang-yaml";
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), _ = {
15
15
  key: "Mod-a",
16
16
  run: (e) => (e.dispatch({
17
17
  selection: { anchor: 0, head: e.state.doc.length },
18
18
  scrollIntoView: !1
19
19
  }), !0)
20
- }, le = (e) => {
21
- const o = U(null);
20
+ }, de = (e) => {
21
+ const i = G(null);
22
22
  m(
23
23
  e.codeMirrorRef,
24
24
  () => {
25
- var t;
26
- (t = o.value) == null || t.destroy(), s();
25
+ var o;
26
+ (o = i.value) == null || o.destroy(), l();
27
27
  },
28
28
  { immediate: !0 }
29
- ), W(() => {
30
- var t;
31
- return (t = o.value) == null ? void 0 : t.destroy();
29
+ ), Q(() => {
30
+ var o;
31
+ return (o = i.value) == null ? void 0 : o.destroy();
32
32
  });
33
- function s() {
33
+ function l() {
34
34
  if (e.codeMirrorRef.value) {
35
- const t = u(e) ? r(e.provider) : null, h = b({
36
- ...l.value,
37
- provider: t
35
+ const o = u(e) ? t(e.provider) : null, h = x({
36
+ ...s.value,
37
+ provider: o
38
38
  });
39
- o.value = new d({
39
+ i.value = new d({
40
40
  parent: e.codeMirrorRef.value,
41
41
  extensions: h
42
- }), u(e) || n(r(e.content));
42
+ }), u(e) || n(t(e.content));
43
43
  }
44
44
  }
45
- const l = q(() => ({
45
+ const s = X(() => ({
46
46
  onChange: e.onChange,
47
47
  onBlur: e.onBlur,
48
48
  onFocus: e.onFocus,
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)
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)
58
61
  }));
59
62
  m(
60
- () => u(e) ? r(e.provider) : null,
63
+ () => u(e) ? t(e.provider) : null,
61
64
  () => {
62
- var t;
63
- u(e) && ((t = o.value) == null || t.destroy(), s());
65
+ var o;
66
+ u(e) && ((o = i.value) == null || o.destroy(), l());
64
67
  }
65
68
  ), m(
66
- l,
69
+ s,
67
70
  () => {
68
- if (o.value) {
69
- const t = u(e) ? r(e.provider) : null, h = b({
70
- ...l.value,
71
- provider: t
71
+ if (i.value) {
72
+ const o = u(e) ? t(e.provider) : null, h = x({
73
+ ...s.value,
74
+ provider: o
72
75
  });
73
- o.value.dispatch({
74
- effects: z.reconfigure.of(h)
76
+ i.value.dispatch({
77
+ effects: U.reconfigure.of(h)
75
78
  });
76
79
  } else
77
80
  return;
78
81
  },
79
82
  { immediate: !0 }
80
83
  );
81
- const n = (t = "") => {
82
- 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({
83
86
  changes: {
84
87
  from: 0,
85
- to: o.value.state.doc.length,
86
- insert: t
88
+ to: i.value.state.doc.length,
89
+ insert: o
87
90
  },
88
91
  selection: {
89
92
  anchor: Math.min(
90
- o.value.state.selection.main.anchor,
91
- t.length
93
+ i.value.state.selection.main.anchor,
94
+ o.length
92
95
  )
93
96
  }
94
97
  });
95
98
  };
96
99
  return m(
97
- () => r(e.content),
100
+ () => t(e.content),
98
101
  () => {
99
- u(e) || n(r(e.content));
102
+ u(e) || n(t(e.content));
100
103
  },
101
104
  { immediate: !0 }
102
105
  ), {
103
106
  /** Replaces the current content with the given value. */
104
107
  setCodeMirrorContent: n,
105
108
  /** Codemirror instance */
106
- codeMirror: o
109
+ codeMirror: i
107
110
  };
108
- }, p = {
109
- html: T,
110
- json: V,
111
- yaml: K,
112
- css: O
111
+ }, y = {
112
+ html: L,
113
+ json: R,
114
+ yaml: V,
115
+ css: K
113
116
  };
114
- function b({
117
+ function x({
115
118
  onChange: e,
116
- onBlur: o,
117
- onFocus: s,
118
- provider: l,
119
+ onBlur: i,
120
+ onFocus: l,
121
+ provider: s,
119
122
  language: n,
120
- classes: t = [],
123
+ classes: o = [],
121
124
  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
+ 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
128
134
  }) {
129
- const i = [
130
- J(),
131
- L(R, { fallback: !0 }),
135
+ const r = [
136
+ W(),
137
+ A(z, { fallback: !0 }),
132
138
  d.theme({
133
139
  ".cm-line": {
134
140
  lineHeight: "20px"
@@ -154,46 +160,51 @@ function b({
154
160
  }),
155
161
  d.domEventHandlers({
156
162
  blur: (c, f) => {
157
- o == null || o(f.state.doc.toString());
163
+ i == null || i(f.state.doc.toString());
158
164
  },
159
165
  focus: (c, f) => {
160
- s == null || s(f.state.doc.toString());
166
+ l == null || l(f.state.doc.toString());
161
167
  }
162
168
  }),
163
169
  // Add Classes
164
- d.editorAttributes.of({ class: t.join(" ") }),
165
- ...k
170
+ d.editorAttributes.of({ class: o.join(" ") }),
171
+ ...N
166
172
  ];
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
173
+ if (s && r.push(s), T || r.push(Y), h ? r.push(d.editable.of(!1)) : (r.push(
174
+ J(),
175
+ v(),
176
+ j(),
177
+ a.of([...w, _]),
178
+ v()
179
+ ), M || r.push(B(), a.of([...I])), S ? r.push(
180
+ a.of([
181
+ {
182
+ key: "Tab",
183
+ run: () => !1,
184
+ // Prevent default Tab behavior
185
+ shift: () => !1
186
+ // Prevent default Shift+Tab behavior
187
+ }
177
188
  ])
178
- ), n && p[n] && i.push(p[n]()), S && n === "json") {
179
- const c = I((f) => {
180
- const a = [];
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 = [];
181
192
  try {
182
193
  JSON.parse(f.state.doc.toString());
183
- } catch (g) {
184
- g instanceof Error && a.push({
194
+ } catch (p) {
195
+ p instanceof Error && b.push({
185
196
  from: 0,
186
197
  to: f.state.doc.length,
187
198
  severity: "error",
188
- message: g.message
199
+ message: p.message
189
200
  });
190
201
  }
191
- return a;
202
+ return b;
192
203
  });
193
- i.push(c);
204
+ r.push(c);
194
205
  }
195
- return y && i.push(P()), x && i.push(G()), E && i.push(
196
- v.of([
206
+ return E && r.push(D()), k && r.push(Z()), C && r.push(
207
+ a.of([
197
208
  {
198
209
  key: "Enter",
199
210
  run: () => !0
@@ -208,8 +219,8 @@ function b({
208
219
  run: () => !0
209
220
  }
210
221
  ])
211
- ), i;
222
+ ), r;
212
223
  }
213
224
  export {
214
- le as useCodeMirror
225
+ de as useCodeMirror
215
226
  };
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "vue",
17
17
  "vue3"
18
18
  ],
19
- "version": "0.11.5",
19
+ "version": "0.11.6",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },