vue-codemirror6 1.2.5 → 1.3.2

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/README.md CHANGED
@@ -51,6 +51,7 @@ This component can handle bidirectional binding by `v-model` like a general Vue
51
51
  | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
52
52
  | linter | LintSource | Set Linter. Enter a linter (eg `esLint([arbitrary rule])` function for `@codemirror/lang-javascript`, `jsonParseLinter()`function for`@codemirror/json`). See the sources for various language libraries for more information. |
53
53
  | linterConfig | Object | see <https://codemirror.net/docs/ref/#lint.linter^config> |
54
+ | forceLinting | boolean | see <https://codemirror.net/docs/ref/#lint.forceLinting> |
54
55
  | gutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
55
56
  | gutterConfig | Object | see <https://codemirror.net/docs/ref/#lint.lintGutter^config> |
56
57
  | tag | string | HTML tags used in the component. (Default is `div` tag.) |
@@ -201,20 +202,10 @@ export default defineComponent({
201
202
 
202
203
  ### Full Example
203
204
 
204
- When using as a Markdown editor on [vite-vue2-vuetify-ts-starter](https://github.com/logue/vite-vue2-vuetify-ts-starter).
205
+ When using as a Markdown editor on [https://github.com/logue/vite-vue3-ts-starter](vite-vue3-ts-starter).
205
206
 
206
207
  ```vue
207
- <template>
208
- <code-mirror
209
- v-model="value"
210
- basic
211
- :dark="dark"
212
- :lang="lang"
213
- :phrases="phreses"
214
- />
215
- </template>
216
-
217
- <script lang="ts">
208
+ <script lang="ts" setup>
218
209
  import { ref, defineComponent, type Ref } from 'vue';
219
210
 
220
211
  // Load component
@@ -226,90 +217,76 @@ import type { LanguageSupport } from '@codemirror/language';
226
217
  import type { Extension } from '@codemirror/state';
227
218
  import type { ViewUpdate } from '@codemirror/view';
228
219
 
229
- export default defineComponent({
230
- components: {
231
- CodeMirror,
232
- },
233
- setup() {
234
- /**
235
- * Get Vuetify instance
236
- *
237
- * @see {@link https://github.com/logue/vite-vue2-vuetify-ts-starter | vite-vue2-vuetify-ts-starter}
238
- */
239
- const vuetify = useVuetify();
240
-
241
- /** text */
242
- const value: Ref<string> = ref('');
243
-
244
- /** Dark mode **/
245
- const dark: Ref<boolean> = ref(
246
- window.matchMedia('(prefers-color-scheme: dark)').matches
247
- );
248
-
249
- /**
250
- * CodeMirror Language
251
- *
252
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
253
- */
254
- const lang: LanguageSupport = md();
255
-
256
- /**
257
- * Internationalization Config.
258
- * In this example, the display language to Japanese.
259
- * Must be reactive when used in combination with vue-i18n.
260
- *
261
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
262
- */
263
- const phrases: Ref<Record<string, string>> = ref({
264
- // @codemirror/view
265
- 'Control character': '制御文字',
266
- // @codemirror/commands
267
- 'Selection deleted': '選択を削除',
268
- // @codemirror/language
269
- 'Folded lines': '折り畳まれた行',
270
- 'Unfolded lines': '折り畳める行',
271
- to: '行き先',
272
- 'folded code': '折り畳まれたコード',
273
- unfold: '折り畳みを解除',
274
- 'Fold line': '行を折り畳む',
275
- 'Unfold line': '行の折り畳む解除',
276
- // @codemirror/search
277
- 'Go to line': '行き先の行',
278
- go: 'OK',
279
- Find: '検索',
280
- Replace: '置き換え',
281
- next: '▼',
282
- previous: '▲',
283
- all: 'すべて',
284
- 'match case': '一致条件',
285
- 'by word': '全文検索',
286
- regexp: '正規表現',
287
- replace: '置き換え',
288
- 'replace all': 'すべてを置き換え',
289
- close: '閉じる',
290
- 'current match': '現在の一致',
291
- 'replaced $ matches': '$ 件の一致を置き換え',
292
- 'replaced match on line $': '$ 行の一致を置き換え',
293
- 'on line': 'した行',
294
- // @codemirror/autocomplete
295
- Completions: '自動補完',
296
- // @codemirror/lint
297
- Diagnostics: 'エラー',
298
- 'No diagnostics': 'エラーなし',
299
- });
300
-
301
- /** When dark value changed, sync vuetify's dark mode */
302
- watch(dark, v => (vuetify.theme.dark = v));
303
-
304
- return {
305
- dark,
306
- value,
307
- lang,
308
- phrases,
309
- };
310
- },
311
- });
220
+ /** text */
221
+ const value: Ref<string> = ref('');
222
+
223
+ /** Dark mode **/
224
+ const dark: Ref<boolean> = ref(
225
+ window.matchMedia('(prefers-color-scheme: dark)').matches
226
+ );
227
+
228
+ /**
229
+ * CodeMirror Language
230
+ *
231
+ * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
232
+ */
233
+ const lang: LanguageSupport = md();
234
+
235
+ /**
236
+ * Internationalization Config.
237
+ * In this example, the display language to Japanese.
238
+ * Must be reactive when used in combination with vue-i18n.
239
+ *
240
+ * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
241
+ */
242
+ const phrases: Record<string, string> = {
243
+ // @codemirror/view
244
+ 'Control character': '制御文字',
245
+ // @codemirror/commands
246
+ 'Selection deleted': '選択を削除',
247
+ // @codemirror/language
248
+ 'Folded lines': '折り畳まれた行',
249
+ 'Unfolded lines': '折り畳める行',
250
+ to: '行き先',
251
+ 'folded code': '折り畳まれたコード',
252
+ unfold: '折り畳みを解除',
253
+ 'Fold line': '行を折り畳む',
254
+ 'Unfold line': '行の折り畳む解除',
255
+ // @codemirror/search
256
+ 'Go to line': '行き先の行',
257
+ go: 'OK',
258
+ Find: '検索',
259
+ Replace: '置き換え',
260
+ next: '▼',
261
+ previous: '▲',
262
+ all: 'すべて',
263
+ 'match case': '一致条件',
264
+ 'by word': '全文検索',
265
+ regexp: '正規表現',
266
+ replace: '置き換え',
267
+ 'replace all': 'すべてを置き換え',
268
+ close: '閉じる',
269
+ 'current match': '現在の一致',
270
+ 'replaced $ matches': '$ 件の一致を置き換え',
271
+ 'replaced match on line $': '$ 行の一致を置き換え',
272
+ 'on line': 'した行',
273
+ // @codemirror/autocomplete
274
+ Completions: '自動補完',
275
+ // @codemirror/lint
276
+ Diagnostics: 'エラー',
277
+ 'No diagnostics': 'エラーなし',
278
+ };
312
279
  </script>
280
+
281
+ <template>
282
+ <code-mirror
283
+ v-model="value"
284
+ basic
285
+ :dark="dark"
286
+ :lang="lang"
287
+ :phrases="phrases"
288
+ />
289
+ </template>
313
290
  ```
314
291
 
315
292
  ## Events
@@ -412,4 +389,5 @@ const config: UserConfig = {
412
389
 
413
390
  ## LICENSE
414
391
 
415
- ©2022-2023 by Logue. Licensed under the [MIT License](LICENSE).
392
+ ©2022-2024 by Logue.
393
+ Licensed under the [MIT License](LICENSE).
package/dist/Meta.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type MetaInterface from './interfaces/MetaInterface';
1
+ import { default as MetaInterface } from './interfaces/MetaInterface';
2
+
2
3
  declare const meta: MetaInterface;
3
4
  export default meta;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import CodeMirror from './components/CodeMirror';
2
- import Meta from './Meta';
1
+ import { default as Meta } from './Meta';
2
+ import { default as CodeMirror } from './components/CodeMirror';
3
+
3
4
  declare const installCodeMirror: (app: any) => void;
4
5
  export { CodeMirror as default, installCodeMirror as install, Meta };
package/dist/index.es.js CHANGED
@@ -5,29 +5,35 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.5
8
+ * @version 1.3.2
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- import { isVue2 as G, h as b, defineComponent as I, ref as v, shallowRef as P, computed as c, watch as C, onMounted as Z, nextTick as k, onUnmounted as q } from "vue-demi";
13
- import { basicSetup as H, minimalSetup as K } from "codemirror";
14
- import { EditorView as r, keymap as Q, placeholder as X } from "@codemirror/view";
15
- import { EditorState as s, Compartment as w, StateEffect as y, EditorSelection as O } from "@codemirror/state";
16
- import { forceLinting as $, linter as Y, lintGutter as ee, diagnosticCount as te } from "@codemirror/lint";
17
- import { indentWithTab as ae } from "@codemirror/commands";
18
- const le = (e) => e ? Object.entries(e).reduce((o, [n, u]) => (n = n.charAt(0).toUpperCase() + n.slice(1), n = `on${n}`, { ...o, [n]: u }), {}) : {};
19
- function B(e, o = {}, n) {
20
- if (G)
21
- return b(e, o, n);
22
- const { props: u, domProps: t, on: d, ...f } = o, m = d ? le(d) : {};
23
- return b(
12
+ import { indentWithTab as G } from "@codemirror/commands";
13
+ import { indentUnit as I } from "@codemirror/language";
14
+ import { forceLinting as b, linter as P, lintGutter as Z, diagnosticCount as k } from "@codemirror/lint";
15
+ import { EditorState as s, Compartment as C, StateEffect as y, EditorSelection as w } from "@codemirror/state";
16
+ import { EditorView as r, keymap as q, placeholder as H } from "@codemirror/view";
17
+ import { basicSetup as K, minimalSetup as Q } from "codemirror";
18
+ import { isVue2 as X, h as O, defineComponent as Y, ref as v, shallowRef as ee, computed as d, watch as $, onMounted as te, nextTick as ae, onUnmounted as ne } from "vue-demi";
19
+ const ie = {
20
+ version: "1.3.2",
21
+ date: "2024-06-10T11:57:17.342Z"
22
+ };
23
+ var ge = ie;
24
+ const le = (e) => e ? Object.entries(e).reduce((l, [i, u]) => (i = i.charAt(0).toUpperCase() + i.slice(1), i = `on${i}`, { ...l, [i]: u }), {}) : {};
25
+ function B(e, l = {}, i) {
26
+ if (X)
27
+ return O(e, l, i);
28
+ const { props: u, domProps: t, on: f, ...c } = l, m = f ? le(f) : {};
29
+ return O(
24
30
  e,
25
- { ...f, ...u, ...t, ...m },
26
- n
31
+ { ...c, ...u, ...t, ...m },
32
+ i
27
33
  );
28
34
  }
29
- const ne = (e) => typeof e == "function" ? e() : e;
30
- var oe = I({
35
+ const oe = (e) => typeof e == "function" ? e() : e;
36
+ var se = Y({
31
37
  /** Component Name */
32
38
  name: "CodeMirror",
33
39
  /** Model Definition */
@@ -49,8 +55,7 @@ var oe = I({
49
55
  */
50
56
  theme: {
51
57
  type: Object,
52
- default: () => {
53
- }
58
+ default: () => ({})
54
59
  },
55
60
  /** Dark Mode */
56
61
  dark: {
@@ -104,6 +109,13 @@ var oe = I({
104
109
  type: Boolean,
105
110
  default: !1
106
111
  },
112
+ /**
113
+ * Tab character
114
+ */
115
+ indentUnit: {
116
+ type: String,
117
+ default: void 0
118
+ },
107
119
  /**
108
120
  * Allow Multiple Selection.
109
121
  *
@@ -218,7 +230,7 @@ var oe = I({
218
230
  */
219
231
  gutter: {
220
232
  type: Boolean,
221
- defalt: !1
233
+ default: !1
222
234
  },
223
235
  /**
224
236
  * Gutter Config
@@ -259,44 +271,48 @@ var oe = I({
259
271
  * @param props - Props
260
272
  * @param context - Context
261
273
  */
262
- setup(e, o) {
263
- const n = v(), u = v(e.modelValue), t = P(new r()), d = c({
274
+ setup(e, l) {
275
+ const i = v(), u = v(e.modelValue), t = ee(new r()), f = d({
264
276
  get: () => t.value.hasFocus,
265
277
  set: (a) => {
266
278
  a && t.value.focus();
267
279
  }
268
- }), f = c({
280
+ }), c = d({
269
281
  get: () => t.value.state.selection,
270
282
  set: (a) => t.value.dispatch({ selection: a })
271
- }), m = c({
283
+ }), m = d({
272
284
  get: () => t.value.state.selection.main.head,
273
285
  set: (a) => t.value.dispatch({ selection: { anchor: a } })
274
- }), M = c(
286
+ }), M = d(
275
287
  {
276
288
  get: () => t.value.state.toJSON(),
277
289
  set: (a) => t.value.setState(s.fromJSON(a))
278
290
  }
279
- ), p = v(0), g = v(0), h = c(() => {
280
- const a = new w(), l = new w();
291
+ ), S = v(0), g = v(0), h = d(() => {
292
+ const a = new C(), n = new C();
293
+ if (e.basic && e.minimal)
294
+ throw "[Vue CodeMirror] Both basic and minimal cannot be specified.";
281
295
  return [
282
296
  // Toggle basic setup
283
- e.basic ? H : void 0,
297
+ e.basic && !e.minimal ? K : void 0,
284
298
  // Toggle minimal setup
285
- e.minimal && !e.basic ? K : void 0,
299
+ e.minimal && !e.basic ? Q : void 0,
286
300
  // ViewUpdate event listener
287
- r.updateListener.of((i) => {
288
- o.emit("focus", t.value.hasFocus), p.value = t.value.state.doc?.length, !(i.changes.empty || !i.docChanged) && (e.linter && (e.forceLinting && $(t.value), g.value = e.linter(t.value).length), o.emit("update", i));
301
+ r.updateListener.of((o) => {
302
+ l.emit("focus", t.value.hasFocus), S.value = t.value.state.doc?.length, !(o.changes.empty || !o.docChanged) && (e.linter && (e.forceLinting && b(t.value), g.value = e.linter(t.value).length), l.emit("update", o));
289
303
  }),
290
304
  // Toggle light/dark mode.
291
305
  r.theme(e.theme, { dark: e.dark }),
292
306
  // Toggle line wrapping
293
307
  e.wrap ? r.lineWrapping : void 0,
294
308
  // Indent with tab
295
- e.tab ? Q.of([ae]) : void 0,
309
+ e.tab ? q.of([G]) : void 0,
310
+ // Tab character
311
+ e.indentUnit ? I.of(e.indentUnit) : void 0,
296
312
  // Allow Multiple Selections
297
313
  s.allowMultipleSelections.of(e.allowMultipleSelections),
298
314
  // Indent tab size
299
- e.tabSize ? l.of(s.tabSize.of(e.tabSize)) : void 0,
315
+ e.tabSize ? n.of(s.tabSize.of(e.tabSize)) : void 0,
300
316
  // locale settings
301
317
  e.phrases ? s.phrases.of(e.phrases) : void 0,
302
318
  // Readonly option
@@ -308,16 +324,16 @@ var oe = I({
308
324
  // Lang
309
325
  e.lang ? a.of(e.lang) : void 0,
310
326
  // Append Linter settings
311
- e.linter ? Y(e.linter, e.linterConfig) : void 0,
327
+ e.linter ? P(e.linter, e.linterConfig) : void 0,
312
328
  // Show 🔴 to error line when linter enabled.
313
- e.linter && e.gutter ? ee(e.gutterConfig) : void 0,
329
+ e.linter && e.gutter ? Z(e.gutterConfig) : void 0,
314
330
  // Placeholder
315
- e.placeholder ? X(e.placeholder) : void 0,
331
+ e.placeholder ? H(e.placeholder) : void 0,
316
332
  // Append Extensions
317
333
  ...e.extensions
318
- ].filter((i) => !!i);
334
+ ].filter((o) => !!o);
319
335
  });
320
- C(
336
+ $(
321
337
  h,
322
338
  (a) => {
323
339
  t.value?.dispatch({
@@ -325,76 +341,77 @@ var oe = I({
325
341
  });
326
342
  },
327
343
  { immediate: !0 }
328
- ), C(
344
+ ), $(
329
345
  () => e.modelValue,
330
346
  async (a) => {
331
347
  t.value.composing || // IME fix
332
348
  t.value.state.doc.toJSON().join(e.lineSeparator ?? `
333
- `) === a || t.value.dispatch({
349
+ `) === a || c.value.ranges.every(
350
+ (n) => n.anchor < a.length && n.head < a.length
351
+ ) && t.value.dispatch({
334
352
  changes: { from: 0, to: t.value.state.doc.length, insert: a },
335
353
  selection: t.value.state.selection,
336
354
  scrollIntoView: !0
337
355
  });
338
356
  },
339
357
  { immediate: !0 }
340
- ), Z(async () => {
358
+ ), te(async () => {
341
359
  let a = u.value;
342
- n.value && (n.value.childNodes[0] && (u.value !== "" && console.warn(
360
+ i.value && (i.value.childNodes[0] && (u.value !== "" && console.warn(
343
361
  "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
344
- ), a = n.value.childNodes[0].innerText.trim()), t.value = new r({
345
- parent: n.value,
362
+ ), a = i.value.childNodes[0].innerText.trim()), t.value = new r({
363
+ parent: i.value,
346
364
  state: s.create({ doc: a, extensions: h.value }),
347
- dispatch: (l) => {
348
- t.value.update([l]), !(l.changes.empty || !l.docChanged) && (o.emit("update:modelValue", l.state.doc.toString() ?? ""), o.emit("change", l.state));
365
+ dispatch: (n) => {
366
+ t.value.update([n]), !(n.changes.empty || !n.docChanged) && (l.emit("update:modelValue", n.state.doc.toString() ?? ""), l.emit("change", n.state));
349
367
  }
350
- }), await k(), o.emit("ready", {
368
+ }), await ae(), l.emit("ready", {
351
369
  view: t.value,
352
370
  state: t.value.state,
353
- container: n.value
371
+ container: i.value
354
372
  }));
355
- }), q(() => {
356
- t.value.destroy(), o.emit("destroy");
373
+ }), ne(() => {
374
+ t.value.destroy(), l.emit("destroy");
357
375
  });
358
376
  const V = () => {
359
- !e.linter || !t.value || (e.forceLinting && $(t.value), g.value = te(t.value.state));
377
+ !e.linter || !t.value || (e.forceLinting && b(t.value), g.value = k(t.value.state));
360
378
  }, j = () => {
361
379
  t.value?.dispatch({
362
380
  effects: y.reconfigure.of([])
363
381
  }), t.value?.dispatch({
364
382
  effects: y.appendConfig.of(h.value)
365
383
  });
366
- }, x = (a, l) => t.value.state.sliceDoc(a, l), L = (a) => t.value.state.doc.line(a + 1).text, N = () => t.value.state.doc.lines, z = () => t.value.state.selection.main.head, T = () => {
384
+ }, x = (a, n) => t.value.state.sliceDoc(a, n), _ = (a) => t.value.state.doc.line(a + 1).text, L = () => t.value.state.doc.lines, N = () => t.value.state.selection.main.head, U = () => {
367
385
  let a;
368
386
  return (a = t.value.state.selection.ranges) !== null && a !== void 0 ? a : [];
369
- }, D = () => {
387
+ }, z = () => {
370
388
  let a;
371
389
  return (a = t.value.state.sliceDoc(
372
390
  t.value.state.selection.main.from,
373
391
  t.value.state.selection.main.to
374
392
  )) !== null && a !== void 0 ? a : "";
375
- }, E = () => {
393
+ }, T = () => {
376
394
  const a = t.value.state;
377
395
  return a ? a.selection.ranges.map(
378
- (l) => a.sliceDoc(l.from, l.to)
396
+ (n) => a.sliceDoc(n.from, n.to)
379
397
  ) : [];
380
- }, R = () => t.value.state.selection.ranges.some(
398
+ }, D = () => t.value.state.selection.ranges.some(
381
399
  (a) => !a.empty
382
- ), F = (a, l, i) => t.value.dispatch({
383
- changes: { from: l, to: i, insert: a }
384
- }), J = (a) => t.value.dispatch(t.value.state.replaceSelection(a)), A = (a) => t.value.dispatch({ selection: { anchor: a } }), U = (a, l) => t.value.dispatch({ selection: { anchor: a, head: l } }), W = (a, l) => t.value.dispatch({
385
- selection: O.create(a, l)
386
- }), _ = (a) => t.value.dispatch({
387
- selection: O.create(
388
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
389
- f.value.ranges.map((l) => l.extend(a(l)))
400
+ ), E = (a, n, o) => t.value.dispatch({
401
+ changes: { from: n, to: o, insert: a }
402
+ }), R = (a) => t.value.dispatch(t.value.state.replaceSelection(a)), F = (a) => t.value.dispatch({ selection: { anchor: a } }), J = (a, n) => t.value.dispatch({ selection: { anchor: a, head: n } }), A = (a, n) => t.value.dispatch({
403
+ selection: w.create(a, n)
404
+ }), W = (a) => t.value.dispatch({
405
+ selection: w.create(
406
+ c.value.ranges.map((n) => n.extend(a(n)))
390
407
  )
391
- }), S = {
392
- editor: n,
408
+ }), p = {
409
+ editor: i,
393
410
  view: t,
394
411
  cursor: m,
395
- selection: f,
396
- focus: d,
397
- length: p,
412
+ selection: c,
413
+ focus: f,
414
+ length: S,
398
415
  json: M,
399
416
  diagnosticCount: g,
400
417
  dom: t.value.contentDOM,
@@ -402,21 +419,21 @@ var oe = I({
402
419
  forceReconfigure: j,
403
420
  // Bellow is CodeMirror5's function
404
421
  getRange: x,
405
- getLine: L,
406
- lineCount: N,
407
- getCursor: z,
408
- listSelections: T,
409
- getSelection: D,
410
- getSelections: E,
411
- somethingSelected: R,
412
- replaceRange: F,
413
- replaceSelection: J,
414
- setCursor: A,
415
- setSelection: U,
416
- setSelections: W,
417
- extendSelectionsBy: _
422
+ getLine: _,
423
+ lineCount: L,
424
+ getCursor: N,
425
+ listSelections: U,
426
+ getSelection: z,
427
+ getSelections: T,
428
+ somethingSelected: D,
429
+ replaceRange: E,
430
+ replaceSelection: R,
431
+ setCursor: F,
432
+ setSelection: J,
433
+ setSelections: A,
434
+ extendSelectionsBy: W
418
435
  };
419
- return o.expose(S), S;
436
+ return l.expose(p), p;
420
437
  },
421
438
  render() {
422
439
  return B(
@@ -430,20 +447,15 @@ var oe = I({
430
447
  B(
431
448
  "aside",
432
449
  { style: "display: none;", "aria-hidden": "true" },
433
- ne(this.$slots.default)
450
+ oe(this.$slots.default)
434
451
  )
435
452
  ) : void 0
436
453
  );
437
454
  }
438
455
  });
439
- const ie = {
440
- version: "1.2.5",
441
- date: "2024-02-05T00:38:11.929Z"
442
- };
443
- var ve = ie;
444
- const me = (e) => e.component("CodeMirror", oe);
456
+ const he = (e) => e.component("CodeMirror", se);
445
457
  export {
446
- ve as Meta,
447
- oe as default,
448
- me as install
458
+ ge as Meta,
459
+ se as default,
460
+ he as install
449
461
  };
@@ -5,9 +5,9 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.5
8
+ * @version 1.3.2
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror=function(u,n,y,r,i,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((c,[o,d])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...c,[o]:d}),{}):{};function p(e,c={},o){if(n.isVue2)return n.h(e,c,o);const{props:d,domProps:t,on:v,...g}=c,h=v?V(v):{};return n.h(e,{...g,...d,...t,...h},o)}const O=e=>typeof e=="function"?e():e;var b=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,c){const o=n.ref(),d=n.ref(e.modelValue),t=n.shallowRef(new r.EditorView),v=n.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),g=n.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=n.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=n.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),C=n.ref(0),m=n.ref(0),S=n.computed(()=>{const a=new i.Compartment,l=new i.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,r.EditorView.updateListener.of(s=>{c.emit("focus",t.value.hasFocus),C.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),c.emit("update",s))}),r.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?r.EditorView.lineWrapping:void 0,e.tab?r.keymap.of([E.indentWithTab]):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?l.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),r.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?r.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});n.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),n.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),n.onMounted(async()=>{let a=d.value;o.value&&(o.value.childNodes[0]&&(d.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new r.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:l=>{t.value.update([l]),!(l.changes.empty||!l.docChanged)&&(c.emit("update:modelValue",l.state.doc.toString()??""),c.emit("change",l.state))}}),await n.nextTick(),c.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),n.onUnmounted(()=>{t.value.destroy(),c.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,l)=>t.value.state.sliceDoc(a,l),z=a=>t.value.state.doc.line(a+1).text,T=()=>t.value.state.doc.lines,R=()=>t.value.state.selection.main.head,_=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(l=>a.sliceDoc(l.from,l.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,l,s)=>t.value.dispatch({changes:{from:l,to:s,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),U=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,l)=>t.value.dispatch({selection:{anchor:a,head:l}}),G=(a,l)=>t.value.dispatch({selection:i.EditorSelection.create(a,l)}),I=a=>t.value.dispatch({selection:i.EditorSelection.create(g.value.ranges.map(l=>l.extend(a(l))))}),w={editor:o,view:t,cursor:h,selection:g,focus:v,length:C,json:B,diagnosticCount:m,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:N,getLine:z,lineCount:T,getCursor:R,listSelections:_,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:U,setSelection:W,setSelections:G,extendSelectionsBy:I};return c.expose(w),w},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.5",date:"2024-02-05T00:38:11.929Z"};const $=e=>e.component("CodeMirror",b);return u.Meta=M,u.default=b,u.install=$,Object.defineProperty(u,"__esModule",{value:!0}),u}({},VueDemi,codemirror,view,state,lint,commands);
12
+ var CodeMirror=function(u,E,V,f,i,c,y,l){"use strict";var M={version:"1.3.2",date:"2024-06-10T11:57:17.342Z"};const O=e=>e?Object.entries(e).reduce((r,[o,s])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...r,[o]:s}),{}):{};function b(e,r={},o){if(l.isVue2)return l.h(e,r,o);const{props:s,domProps:t,on:g,...v}=r,h=g?O(g):{};return l.h(e,{...v,...s,...t,...h},o)}const $=e=>typeof e=="function"?e():e;var C=l.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,r){const o=l.ref(),s=l.ref(e.modelValue),t=l.shallowRef(new c.EditorView),g=l.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),v=l.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=l.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),j=l.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),w=l.ref(0),m=l.ref(0),S=l.computed(()=>{const a=new i.Compartment,n=new i.Compartment;if(e.basic&&e.minimal)throw"[Vue CodeMirror] Both basic and minimal cannot be specified.";return[e.basic&&!e.minimal?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(d=>{r.emit("focus",t.value.hasFocus),w.value=t.value.state.doc?.length,!(d.changes.empty||!d.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),r.emit("update",d))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,e.indentUnit?V.indentUnit.of(e.indentUnit):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(d=>!!d)});l.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),l.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
+ `)===a||v.value.ranges.every(n=>n.anchor<a.length&&n.head<a.length)&&t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),l.onMounted(async()=>{let a=s.value;o.value&&(o.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(r.emit("update:modelValue",n.state.doc.toString()??""),r.emit("change",n.state))}}),await l.nextTick(),r.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),l.onUnmounted(()=>{t.value.destroy(),r.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,n)=>t.value.state.sliceDoc(a,n),U=a=>t.value.state.doc.line(a+1).text,z=()=>t.value.state.doc.lines,T=()=>t.value.state.selection.main.head,R=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,n,d)=>t.value.dispatch({changes:{from:n,to:d,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),W=a=>t.value.dispatch({selection:{anchor:a}}),G=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),I=(a,n)=>t.value.dispatch({selection:i.EditorSelection.create(a,n)}),Z=a=>t.value.dispatch({selection:i.EditorSelection.create(v.value.ranges.map(n=>n.extend(a(n))))}),p={editor:o,view:t,cursor:h,selection:v,focus:g,length:w,json:j,diagnosticCount:m,dom:t.value.contentDOM,lint:_,forceReconfigure:L,getRange:N,getLine:U,lineCount:z,getCursor:T,listSelections:R,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:W,setSelection:G,setSelections:I,extendSelectionsBy:Z};return r.expose(p),p},render(){return b(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?b("aside",{style:"display: none;","aria-hidden":"true"},$(this.$slots.default)):void 0)}});const B=e=>e.component("CodeMirror",C);return u.Meta=M,u.default=C,u.install=B,Object.defineProperty(u,"__esModule",{value:!0}),u}({},commands,language,lint,state,view,codemirror,VueDemi);
package/dist/index.umd.js CHANGED
@@ -5,9 +5,9 @@
5
5
  * @author Logue <logue@hotmail.co.jp>
6
6
  * @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.2.5
8
+ * @version 1.3.2
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- (function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue-demi"),require("codemirror"),require("@codemirror/view"),require("@codemirror/state"),require("@codemirror/lint"),require("@codemirror/commands")):typeof define=="function"&&define.amd?define(["exports","vue-demi","codemirror","@codemirror/view","@codemirror/state","@codemirror/lint","@codemirror/commands"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.CodeMirror={},l.VueDemi,l.codemirror,l.view,l.state,l.lint,l.commands))})(this,function(l,o,y,c,r,f,E){"use strict";const V=e=>e?Object.entries(e).reduce((d,[i,u])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:u}),{}):{};function p(e,d={},i){if(o.isVue2)return o.h(e,d,i);const{props:u,domProps:t,on:v,...m}=d,h=v?V(v):{};return o.h(e,{...m,...u,...t,...h},i)}const O=e=>typeof e=="function"?e():e;var w=o.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,defalt:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const i=o.ref(),u=o.ref(e.modelValue),t=o.shallowRef(new c.EditorView),v=o.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=o.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=o.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),B=o.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),C=o.ref(0),g=o.ref(0),S=o.computed(()=>{const a=new r.Compartment,n=new r.Compartment;return[e.basic?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),C.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),g.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});o.watch(S,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),o.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),o.onMounted(async()=>{let a=u.value;i.value&&(i.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=i.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:i.value,state:r.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()??""),d.emit("change",n.state))}}),await o.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:i.value}))}),o.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const j=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),g.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(S.value)})},T=(a,n)=>t.value.state.sliceDoc(a,n),q=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,z=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},R=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},_=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),U=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),W=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),G=a=>t.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))}),b={editor:i,view:t,cursor:h,selection:m,focus:v,length:C,json:B,diagnosticCount:g,dom:t.value.contentDOM,lint:j,forceReconfigure:L,getRange:T,getLine:q,lineCount:x,getCursor:N,listSelections:z,getSelection:R,getSelections:_,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:U,setSelections:W,extendSelectionsBy:G};return d.expose(b),b},render(){return p(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?p("aside",{style:"display: none;","aria-hidden":"true"},O(this.$slots.default)):void 0)}}),M={version:"1.2.5",date:"2024-02-05T00:38:11.929Z"};const $=e=>e.component("CodeMirror",w);l.Meta=M,l.default=w,l.install=$,Object.defineProperty(l,"__esModule",{value:!0})});
12
+ (function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,function(l,f,V,v,r,c,p,i){"use strict";var M={version:"1.3.2",date:"2024-06-10T11:57:17.342Z"};const O=e=>e?Object.entries(e).reduce((d,[o,u])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...d,[o]:u}),{}):{};function w(e,d={},o){if(i.isVue2)return i.h(e,d,o);const{props:u,domProps:t,on:h,...m}=d,g=h?O(h):{};return i.h(e,{...m,...u,...t,...g},o)}const $=e=>typeof e=="function"?e():e;var C=i.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const o=i.ref(),u=i.ref(e.modelValue),t=i.shallowRef(new c.EditorView),h=i.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=i.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),g=i.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),j=i.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),b=i.ref(0),S=i.ref(0),y=i.computed(()=>{const a=new r.Compartment,n=new r.Compartment;if(e.basic&&e.minimal)throw"[Vue CodeMirror] Both basic and minimal cannot be specified.";return[e.basic&&!e.minimal?p.basicSetup:void 0,e.minimal&&!e.basic?p.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),b.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&v.forceLinting(t.value),S.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([f.indentWithTab]):void 0,e.indentUnit?V.indentUnit.of(e.indentUnit):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?v.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?v.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});i.watch(y,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),i.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
13
+ `)===a||m.value.ranges.every(n=>n.anchor<a.length&&n.head<a.length)&&t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),i.onMounted(async()=>{let a=u.value;o.value&&(o.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:o.value,state:r.EditorState.create({doc:a,extensions:y.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()??""),d.emit("change",n.state))}}),await i.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),i.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&v.forceLinting(t.value),S.value=v.diagnosticCount(t.value.state))},q=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(y.value)})},L=(a,n)=>t.value.state.sliceDoc(a,n),T=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,U=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},z=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},R=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),G=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),I=a=>t.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))}),E={editor:o,view:t,cursor:g,selection:m,focus:h,length:b,json:j,diagnosticCount:S,dom:t.value.contentDOM,lint:_,forceReconfigure:q,getRange:L,getLine:T,lineCount:x,getCursor:N,listSelections:U,getSelection:z,getSelections:R,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:W,setSelections:G,extendSelectionsBy:I};return d.expose(E),E},render(){return w(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?w("aside",{style:"display: none;","aria-hidden":"true"},$(this.$slots.default)):void 0)}});const B=e=>e.component("CodeMirror",C);l.Meta=M,l.default=C,l.install=B,Object.defineProperty(l,"__esModule",{value:!0})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "vue-codemirror6",
4
- "version": "1.2.5",
4
+ "version": "1.3.2",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -55,7 +55,7 @@
55
55
  "engines": {
56
56
  "yarn": ">=1.22.19"
57
57
  },
58
- "packageManager": "yarn@4.1.0",
58
+ "packageManager": "yarn@4.2.2",
59
59
  "sideEffects": false,
60
60
  "scripts": {
61
61
  "dev": "vite",
@@ -79,48 +79,46 @@
79
79
  "vue": "^2.7.14 || ^3.4"
80
80
  },
81
81
  "devDependencies": {
82
- "@codemirror/lang-javascript": "^6.2.1",
82
+ "@codemirror/lang-javascript": "^6.2.2",
83
83
  "@codemirror/lang-json": "^6.0.1",
84
- "@codemirror/lang-markdown": "^6.2.4",
84
+ "@codemirror/lang-markdown": "^6.2.5",
85
85
  "@codemirror/lang-vue": "0.1.2",
86
- "@tsconfig/node-lts": "^20.1.1",
87
- "@types/node": "^20.11.16",
88
- "@typescript-eslint/eslint-plugin": "^6.20.0",
89
- "@vitejs/plugin-vue": "^5.0.3",
90
- "@vue/compiler-sfc": "^3.4.15",
86
+ "@eslint/js": "^9.4.0",
87
+ "@tsconfig/node-lts": "^20.1.3",
88
+ "@types/node": "^20.14.2",
89
+ "@typescript-eslint/eslint-plugin": "^7.12.0",
90
+ "@vitejs/plugin-vue": "^5.0.5",
91
+ "@vue/compiler-sfc": "^3.4.27",
91
92
  "@vue/eslint-config-prettier": "^9.0.0",
92
93
  "@vue/tsconfig": "^0.5.1",
93
- "@vueuse/core": "^10.7.2",
94
- "bootstrap": "^5.3.2",
95
- "eslint": "^8.56.0",
96
- "eslint-config-standard-with-typescript": "^43.0.1",
94
+ "@vueuse/core": "^10.10.0",
95
+ "bootstrap": "^5.3.3",
96
+ "eslint": "^9.4.0",
97
97
  "eslint-import-resolver-alias": "^1.1.2",
98
98
  "eslint-import-resolver-typescript": "^3.6.1",
99
- "eslint-linter-browserify": "^8.56.0",
100
- "eslint-plugin-html": "^7.1.0",
99
+ "eslint-linter-browserify": "^9.4.0",
101
100
  "eslint-plugin-import": "^2.29.1",
102
- "eslint-plugin-n": "^16.6.2",
103
- "eslint-plugin-promise": "^6.1.1",
104
- "eslint-plugin-tsdoc": "^0.2.17",
105
- "eslint-plugin-vue": "latest",
106
- "eslint-plugin-vuejs-accessibility": "^2.2.1",
101
+ "eslint-plugin-tsdoc": "^0.3.0",
102
+ "eslint-plugin-vue": "^9.26.0",
103
+ "eslint-plugin-vuejs-accessibility": "^2.3.0",
107
104
  "eslint-plugin-yaml": "^0.5.0",
108
- "husky": "^9.0.10",
109
- "lint-staged": "^15.2.1",
105
+ "husky": "^9.0.11",
106
+ "lint-staged": "^15.2.5",
110
107
  "npm-run-all": "^4.1.5",
111
- "prettier": "^3.2.5",
112
- "rimraf": "^5.0.5",
108
+ "prettier": "^3.3.1",
109
+ "rimraf": "^5.0.7",
113
110
  "rollup-plugin-visualizer": "^5.12.0",
114
- "sass": "^1.70.0",
115
- "typescript": "^5.3.3",
116
- "vite": "^5.0.12",
111
+ "sass": "^1.77.4",
112
+ "typescript": "^5.4.5",
113
+ "typescript-eslint": "^7.12.0",
114
+ "vite": "^5.2.13",
117
115
  "vite-plugin-banner": "^0.7.1",
118
116
  "vite-plugin-checker": "^0.6.4",
119
- "vite-plugin-dts": "^3.7.2",
120
- "vue": "^3.4.15",
121
- "vue-eslint-parser": "^9.4.2",
117
+ "vite-plugin-dts": "^3.9.1",
118
+ "vue": "^3.4.27",
119
+ "vue-eslint-parser": "^9.4.3",
122
120
  "vue-markdown-wasm": "^0.4.0",
123
- "vue-tsc": "^1.8.27"
121
+ "vue-tsc": "^2.0.21"
124
122
  },
125
123
  "husky": {
126
124
  "hooks": {
@@ -132,10 +130,12 @@
132
130
  "*": "prettier -w -u"
133
131
  },
134
132
  "resolutions": {
135
- "json5": "^2.2.3",
136
- "postcss": "^8.4.31",
137
- "semver": "^7.5.3",
138
- "yaml": "^2.3.2",
139
- "vite": ">5.0.5"
133
+ "json5": ">=2.2.3",
134
+ "ip": ">=2.0.1",
135
+ "lodash": ">=4.17.21",
136
+ "postcss": ">=8.4.31",
137
+ "semver": ">=7.5.3",
138
+ "tar": ">=6.2.1",
139
+ "yaml": ">=2.3.2"
140
140
  }
141
- }
141
+ }
@@ -1,30 +1,16 @@
1
- import {
2
- computed,
3
- defineComponent,
4
- nextTick,
5
- onMounted,
6
- onUnmounted,
7
- ref,
8
- shallowRef,
9
- watch,
10
- type ComputedRef,
11
- type PropType,
12
- type Ref,
13
- type ShallowRef,
14
- type WritableComputedRef,
15
- } from 'vue-demi';
16
-
17
1
  // Helpers
18
- import h, { slot } from '@/helpers/h-demi';
19
2
 
20
3
  // CodeMirror
21
- import { basicSetup, minimalSetup } from 'codemirror';
4
+ import { indentWithTab } from '@codemirror/commands';
5
+ import { indentUnit, type LanguageSupport } from '@codemirror/language';
22
6
  import {
23
- EditorView,
24
- keymap,
25
- placeholder,
26
- type ViewUpdate,
27
- } from '@codemirror/view';
7
+ diagnosticCount as linterDagnosticCount,
8
+ forceLinting,
9
+ linter,
10
+ lintGutter,
11
+ type Diagnostic,
12
+ type LintSource,
13
+ } from '@codemirror/lint';
28
14
  import {
29
15
  Compartment,
30
16
  EditorSelection,
@@ -37,17 +23,32 @@ import {
37
23
  type Text,
38
24
  } from '@codemirror/state';
39
25
  import {
40
- diagnosticCount as linterDagnosticCount,
41
- forceLinting,
42
- linter,
43
- lintGutter,
44
- type Diagnostic,
45
- type LintSource,
46
- } from '@codemirror/lint';
47
- import { indentWithTab } from '@codemirror/commands';
48
- import type { LanguageSupport } from '@codemirror/language';
26
+ EditorView,
27
+ keymap,
28
+ placeholder,
29
+ type ViewUpdate,
30
+ } from '@codemirror/view';
31
+ import { basicSetup, minimalSetup } from 'codemirror';
32
+ import {
33
+ computed,
34
+ defineComponent,
35
+ nextTick,
36
+ onMounted,
37
+ onUnmounted,
38
+ ref,
39
+ shallowRef,
40
+ watch,
41
+ type ComputedRef,
42
+ type PropType,
43
+ type Ref,
44
+ type ShallowRef,
45
+ type WritableComputedRef,
46
+ } from 'vue-demi';
47
+
49
48
  import type { StyleSpec } from 'style-mod';
50
49
 
50
+ import h, { slot } from '@/helpers/h-demi';
51
+
51
52
  /** CodeMirror Component */
52
53
  export default defineComponent({
53
54
  /** Component Name */
@@ -71,7 +72,9 @@ export default defineComponent({
71
72
  */
72
73
  theme: {
73
74
  type: Object as PropType<Record<string, StyleSpec>>,
74
- default: () => {},
75
+ default: () => {
76
+ return {};
77
+ },
75
78
  },
76
79
  /** Dark Mode */
77
80
  dark: {
@@ -125,6 +128,13 @@ export default defineComponent({
125
128
  type: Boolean,
126
129
  default: false,
127
130
  },
131
+ /**
132
+ * Tab character
133
+ */
134
+ indentUnit: {
135
+ type: String,
136
+ default: undefined,
137
+ },
128
138
  /**
129
139
  * Allow Multiple Selection.
130
140
  *
@@ -208,7 +218,7 @@ export default defineComponent({
208
218
  * @see {@link https://codemirror.net/docs/ref/#lint.linter}
209
219
  */
210
220
  linter: {
211
- type: Function as PropType<LintSource>,
221
+ type: Function as PropType<LintSource | any>,
212
222
  default: undefined,
213
223
  },
214
224
  /**
@@ -241,7 +251,7 @@ export default defineComponent({
241
251
  */
242
252
  gutter: {
243
253
  type: Boolean,
244
- defalt: false,
254
+ default: false,
245
255
  },
246
256
  /**
247
257
  * Gutter Config
@@ -263,19 +273,19 @@ export default defineComponent({
263
273
  /** Emits */
264
274
  emits: {
265
275
  /** Model Update */
266
- 'update:modelValue': (value: string | Text = '') => true,
276
+ 'update:modelValue': (_value: string | Text = '') => true,
267
277
  /** CodeMirror ViewUpdate */
268
- update: (value: ViewUpdate) => true,
278
+ update: (_value: ViewUpdate) => true,
269
279
  /** CodeMirror onReady */
270
- ready: (value: {
280
+ ready: (_value: {
271
281
  view: EditorView;
272
282
  state: EditorState;
273
283
  container: HTMLElement;
274
284
  }) => true,
275
285
  /** CodeMirror onFocus */
276
- focus: (value: boolean) => true,
286
+ focus: (_value: boolean) => true,
277
287
  /** State Changed */
278
- change: (value: EditorState) => true,
288
+ change: (_value: EditorState) => true,
279
289
  /** CodeMirror onDestroy */
280
290
  destroy: () => true,
281
291
  },
@@ -353,11 +363,13 @@ export default defineComponent({
353
363
  // @see https://codemirror.net/examples/config/
354
364
  const language = new Compartment();
355
365
  const tabSize = new Compartment();
356
-
366
+ if (props.basic && props.minimal) {
367
+ throw '[Vue CodeMirror] Both basic and minimal cannot be specified.';
368
+ }
357
369
  // TODO: Ignore previous prop was not changed.
358
370
  return [
359
371
  // Toggle basic setup
360
- props.basic ? basicSetup : undefined,
372
+ props.basic && !props.minimal ? basicSetup : undefined,
361
373
  // Toggle minimal setup
362
374
  props.minimal && !props.basic ? minimalSetup : undefined,
363
375
  // ViewUpdate event listener
@@ -391,6 +403,8 @@ export default defineComponent({
391
403
  props.wrap ? EditorView.lineWrapping : undefined,
392
404
  // Indent with tab
393
405
  props.tab ? keymap.of([indentWithTab]) : undefined,
406
+ // Tab character
407
+ props.indentUnit ? indentUnit.of(props.indentUnit) : undefined,
394
408
  // Allow Multiple Selections
395
409
  EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
396
410
  // Indent tab size
@@ -446,6 +460,16 @@ export default defineComponent({
446
460
  return;
447
461
  }
448
462
 
463
+ // Range Fix ?
464
+ // https://github.com/logue/vue-codemirror6/issues/27
465
+ if (
466
+ !selection.value.ranges.every(
467
+ range => range.anchor < value.length && range.head < value.length
468
+ )
469
+ ) {
470
+ return;
471
+ }
472
+
449
473
  // Update
450
474
  view.value.dispatch({
451
475
  changes: { from: 0, to: view.value.state.doc.length, insert: value },
@@ -656,7 +680,6 @@ export default defineComponent({
656
680
  const extendSelectionsBy = (f: any): void =>
657
681
  view.value.dispatch({
658
682
  selection: EditorSelection.create(
659
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
660
683
  selection.value.ranges.map((r: SelectionRange) => r.extend(f(r)))
661
684
  ),
662
685
  });