vue-codemirror6 1.0.1 → 1.0.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
@@ -11,12 +11,12 @@ A component for using [CodeMirror6](https://codemirror.net/6/) with Vue. Unrelat
11
11
  ## Usage
12
12
 
13
13
  ```sh
14
- yarn add vue-codemirror6
14
+ yarn add vue-codemirror6 codemirror
15
15
  ```
16
16
 
17
17
  This component can handle bidirectional binding by `v-model` like a general Vue component.
18
18
 
19
- When using with Vue 2.6, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
19
+ When using with Vue <2.6, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
20
20
 
21
21
  ```sh
22
22
  yarn add vue-codemirror6 @vue/composition-api
@@ -26,21 +26,22 @@ For Vue 2.7 or later, import vue directly like Vue3.
26
26
 
27
27
  ### Props
28
28
 
29
- | Props | Type | Information |
30
- | ---------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
31
- | basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
32
- | minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
33
- | dark | boolean | Toggle Darkmode. |
34
- | wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
35
- | tab | boolean | Enables tab indentation. |
36
- | theme | { [selector: string]: StyleSpec } | Specify the theme. For example, if you use [@codemirror/theme-one-dark](https://github.com/codemirror/theme-one-dark), import `oneDark` and put it in this prop. |
37
- | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
38
- | editable | boolean | When this is set to false, it is similar to `readonly`, except that the cursor is not displayed like the normal pre tag. |
39
- | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
40
- | phrases | Record&lt;string, string&gt; | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
41
- | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
42
- | 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. |
43
- | lintGutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
29
+ | Props | Type | Information |
30
+ | ---------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
31
+ | basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
32
+ | minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
33
+ | dark | boolean | Toggle Darkmode. |
34
+ | wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
35
+ | tab | boolean | Enables tab indentation. |
36
+ | theme | { [selector: string]: StyleSpec } | Specify the theme. For example, if you use [@codemirror/theme-one-dark](https://github.com/codemirror/theme-one-dark), import `oneDark` and put it in this prop. |
37
+ | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
38
+ | editable | boolean | When this is set to false, it is similar to `readonly`, except that the cursor is not displayed like the normal pre tag. |
39
+ | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
40
+ | phrases | Record&lt;string, string&gt; | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
41
+ | extensions | Extension[] | Includes enhancements to extend CodeMirror. |
42
+ | 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. |
43
+ | lintGutter | boolean | Display 🔴 on the line where there was an error when `linter` was specified. It will not work if `linter` is not specified. |
44
+ | tag | string | HTML tags used in the component. (Default is `div` tag.) |
44
45
 
45
46
  Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
46
47
 
@@ -192,12 +193,14 @@ export default defineComponent({
192
193
  const phrases: Ref<Record<string, string>> = ref({
193
194
  // @codemirror/view
194
195
  'Control character': '制御文字',
195
- // @codemirror/fold
196
+ // @codemirror/commands
197
+ 'Selection deleted': '選択を削除',
198
+ // @codemirror/language
196
199
  'Folded lines': '折り畳まれた行',
197
200
  'Unfolded lines': '折り畳める行',
198
201
  to: '行き先',
199
202
  'folded code': '折り畳まれたコード',
200
- unfold: '折り畳む解除',
203
+ unfold: '折り畳みを解除',
201
204
  'Fold line': '行を折り畳む',
202
205
  'Unfold line': '行の折り畳む解除',
203
206
  // @codemirror/search
@@ -209,12 +212,17 @@ export default defineComponent({
209
212
  previous: '▲',
210
213
  all: 'すべて',
211
214
  'match case': '一致条件',
215
+ 'by word': '全文検索',
212
216
  regexp: '正規表現',
213
217
  replace: '置き換え',
214
218
  'replace all': 'すべてを置き換え',
215
219
  close: '閉じる',
216
220
  'current match': '現在の一致',
221
+ 'replaced $ matches': '$ 件の一致を置き換え',
222
+ 'replaced match on line $': '$ 行の一致を置き換え',
217
223
  'on line': 'した行',
224
+ // @codemirror/autocomplete
225
+ Completions: '自動補完',
218
226
  // @codemirror/lint
219
227
  Diagnostics: 'エラー',
220
228
  'No diagnostics': 'エラーなし',
@@ -236,39 +244,44 @@ export default defineComponent({
236
244
 
237
245
  ## Events
238
246
 
239
- | Event | Description |
240
- | ------- | ---------------------------------------------------------------------------------- |
241
- | ready | When CodeMirror loaded. |
242
- | focus | When focus changed. |
243
- | update | When CodeMirror state changed |
244
- | changed | Value changed. (Please implement with `v-model` unless there is a special reason.) |
247
+ | Event | Description |
248
+ | ------- | ------------------------------------------------------------------------------------------------------------- |
249
+ | ready | When CodeMirror loaded. |
250
+ | focus | When focus changed. |
251
+ | update | When CodeMirror state changed. Returns [ViewUpdate](https://codemirror.net/docs/ref/#view.ViewUpdate) object. |
252
+ | changed | Value changed. (Please implement with `v-model` unless there is a special reason.) |
245
253
 
246
254
  ## Methods
247
255
 
248
- | Method | Description |
249
- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
250
- | selection | Get and set the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
251
- | cursor | Get and set the cursor location. |
252
- | state | Get and set [EditorState](https://codemirror.net/docs/ref/#state.EditorState). |
253
- | focus | Get and set focus. |
254
- | getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
255
- | getLine(number: number) | Get the content of line. |
256
- | lineCount() | Get the number of lines in the editor. |
257
- | getCursor() | Retrieve one end of the primary selection. |
258
- | listSelections() | Retrieves a list of all current selections. |
259
- | getSelection() | Get the currently selected code. |
260
- | getSelections() | The length of the given array should be the same as the number of active selections. |
261
- | somethingSelected() | Return true if any text is selected. |
262
- | replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
263
- | replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
264
- | setCursor(position: number) | Set the cursor position. |
265
- | setSelection(anchor: number, head?: number) | Set a single selection range. |
266
- | setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
267
- | extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
256
+ | Method | Description |
257
+ | --------- | --------------------------------------------------------------------------------------------------- |
258
+ | selection | Get and set the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
259
+ | cursor | Get and set the [cursor](https://codemirror.net/docs/ref/#state.EditorSelection^cursor) location. |
260
+ | state | Get and set [EditorState](https://codemirror.net/docs/ref/#state.EditorState). |
261
+ | focus | Get and set [focus](https://codemirror.net/docs/ref/#view.EditorView.focus). |
262
+
263
+ The instructions below are compatible methods for those familiar with [codemirror5](https://codemirror.net/5/). Since the above method is usually sufficient, its active use is not recommended.
264
+
265
+ | Method | Description |
266
+ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
267
+ | getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
268
+ | getLine(number: number) | Get the content of line. |
269
+ | lineCount() | Get the number of lines in the editor. |
270
+ | getCursor() | Retrieve one end of the primary selection. |
271
+ | listSelections() | Retrieves a list of all current selections. |
272
+ | getSelection() | Get the currently selected code. |
273
+ | getSelections() | The length of the given array should be the same as the number of active selections. |
274
+ | somethingSelected() | Return true if any text is selected. |
275
+ | replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
276
+ | replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
277
+ | setCursor(position: number) | Set the cursor position. |
278
+ | setSelection(anchor: number, head?: number) | Set a single selection range. |
279
+ | setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
280
+ | extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
268
281
 
269
282
  ## Recommendations
270
283
 
271
- Since CodeMirror has a relatively large capacity, when using vite, it is recommended to set it to output as a separate file using the [`manualChunks`](https://vitejs.dev/guide/build.html#chunking-strategy) option at build time as shown below.
284
+ Since CodeMirror has a relatively large capacity, when using [vite](https://vitejs.dev), it is recommended to set it to output as a separate file using the [`manualChunks`](https://vitejs.dev/guide/build.html#chunking-strategy) option at build time as shown below.
272
285
 
273
286
  ```ts
274
287
  const config: UserConfig = {
@@ -141,9 +141,14 @@ declare const _default: import("vue-demi").DefineComponent<{
141
141
  type: BooleanConstructor;
142
142
  defalt: boolean;
143
143
  };
144
+ /** Using tag */
145
+ tag: {
146
+ type: StringConstructor;
147
+ default: string;
148
+ };
144
149
  }, {
145
150
  context: SetupContext<CodeMirrorEmitsOptions>;
146
- editor: Ref<Element | undefined>;
151
+ editor: Ref<HTMLElement | undefined>;
147
152
  cursor: Ref<number>;
148
153
  selection: Ref<EditorSelection>;
149
154
  state: Ref<EditorState>;
@@ -279,6 +284,11 @@ declare const _default: import("vue-demi").DefineComponent<{
279
284
  type: BooleanConstructor;
280
285
  defalt: boolean;
281
286
  };
287
+ /** Using tag */
288
+ tag: {
289
+ type: StringConstructor;
290
+ default: string;
291
+ };
282
292
  }>> & {
283
293
  [x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
284
294
  }, {
@@ -298,6 +308,7 @@ declare const _default: import("vue-demi").DefineComponent<{
298
308
  lang: LanguageSupport;
299
309
  linter: LintSource;
300
310
  lintGutter: boolean;
311
+ tag: string;
301
312
  }>;
302
313
  export default _default;
303
314
  //# sourceMappingURL=CodeMirror.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAElB,MAAM,UAAU,CAAC;AAOlB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAU,MAAM,kBAAkB,CAAC;AAKtD,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,IAAI,EAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAqB;AACrB,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE,mBAAmB;IACnB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACrD,4BAA4B;IAC5B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACvC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license MIT
8
- * @version 1.0.1
8
+ * @version 1.0.2
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- import { isVue2 as C, Vue2 as V, h as p, defineComponent as B, ref as g, shallowRef as x, computed as u, toRaw as O, watch as m, onMounted as M, nextTick as R, onUnmounted as j } from "vue-demi";
13
- import { compact as E, trim as T } from "lodash";
14
- import { EditorState as y, StateEffect as $, EditorSelection as S } from "@codemirror/state";
15
- import { EditorView as c, keymap as D } from "@codemirror/view";
16
- import { linter as G, lintGutter as L } from "@codemirror/lint";
17
- import { basicSetup as A, minimalSetup as F } from "codemirror";
18
- import { indentWithTab as N } from "@codemirror/commands";
19
- const U = (a) => a ? Object.entries(a).reduce((l, [o, s]) => (o = o.charAt(0).toUpperCase() + o.slice(1), o = `on${o}`, { ...l, [o]: s }), {}) : {}, w = (a, l = {}, o) => {
20
- if (C && parseInt(V.version) < 2.7)
21
- return p(a, l, o);
22
- const { props: s, domProps: t, on: i, ...r } = l, d = i ? U(i) : {};
23
- return p(
24
- a,
25
- { ...r, ...s, ...t, ...d },
26
- o
12
+ import { isVue2, Vue2, h as h$1, defineComponent, ref, shallowRef, computed, toRaw, watch, onMounted, nextTick, onUnmounted } from 'vue-demi';
13
+ import { compact, trim } from 'lodash';
14
+ import { EditorState, StateEffect, EditorSelection } from '@codemirror/state';
15
+ import { EditorView, keymap } from '@codemirror/view';
16
+ import { linter, lintGutter } from '@codemirror/lint';
17
+ import { basicSetup, minimalSetup } from 'codemirror';
18
+ import { indentWithTab } from '@codemirror/commands';
19
+
20
+ const adaptOnsV3 = (ons) => {
21
+ if (!ons)
22
+ return {};
23
+ return Object.entries(ons).reduce((ret, [key, handler]) => {
24
+ key = key.charAt(0).toUpperCase() + key.slice(1);
25
+ key = `on${key}`;
26
+ return { ...ret, [key]: handler };
27
+ }, {});
28
+ };
29
+ const h = (type, options = {}, chidren) => {
30
+ if (isVue2 && parseInt(Vue2.version) < 2.7) {
31
+ return h$1(type, options, chidren);
32
+ }
33
+ const { props, domProps, on, ...extraOptions } = options;
34
+ const ons = on ? adaptOnsV3(on) : {};
35
+ return h$1(
36
+ type,
37
+ { ...extraOptions, ...props, ...domProps, ...ons },
38
+ chidren
27
39
  );
28
- }, W = (a) => typeof a == "function" ? a() : a, b = B({
40
+ };
41
+ const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
42
+
43
+ const CodeMirror = defineComponent({
29
44
  name: "CodeMirror",
30
45
  model: {
31
46
  prop: "modelValue",
@@ -38,49 +53,51 @@ const U = (a) => a ? Object.entries(a).reduce((l, [o, s]) => (o = o.charAt(0).to
38
53
  },
39
54
  theme: {
40
55
  type: Object,
41
- default: () => ({})
56
+ default: () => {
57
+ return {};
58
+ }
42
59
  },
43
60
  dark: {
44
61
  type: Boolean,
45
- default: !1
62
+ default: false
46
63
  },
47
64
  basic: {
48
65
  type: Boolean,
49
- default: !1
66
+ default: false
50
67
  },
51
68
  minimal: {
52
69
  type: Boolean,
53
- default: !1
70
+ default: false
54
71
  },
55
72
  wrap: {
56
73
  type: Boolean,
57
- default: !1
74
+ default: false
58
75
  },
59
76
  tab: {
60
77
  type: Boolean,
61
- default: !1
78
+ default: false
62
79
  },
63
80
  readonly: {
64
81
  type: Boolean,
65
- default: !1
82
+ default: false
66
83
  },
67
84
  editable: {
68
85
  type: Boolean,
69
- default: !0
86
+ default: true
70
87
  },
71
88
  extensions: {
72
89
  type: Array,
73
- default: () => []
90
+ default: () => {
91
+ return [];
92
+ }
74
93
  },
75
94
  phrases: {
76
95
  type: Object,
77
- default: () => {
78
- }
96
+ default: () => void 0
79
97
  },
80
98
  lang: {
81
99
  type: Object,
82
- default: () => {
83
- }
100
+ default: () => void 0
84
101
  },
85
102
  linter: {
86
103
  type: Function,
@@ -88,133 +105,181 @@ const U = (a) => a ? Object.entries(a).reduce((l, [o, s]) => (o = o.charAt(0).to
88
105
  },
89
106
  lintGutter: {
90
107
  type: Boolean,
91
- defalt: !1
108
+ defalt: false
109
+ },
110
+ tag: {
111
+ type: String,
112
+ default: "div"
92
113
  }
93
114
  },
94
115
  emits: ["update:modelValue", "update", "ready", "focus", "changed"],
95
- setup(a, l) {
96
- const o = g(), s = g(a.modelValue), t = x(new c()), i = u({
97
- get: () => t.value.state.selection,
98
- set: (e) => t.value.dispatch({ selection: e })
99
- }), r = u({
100
- get: () => i.value.main.head || 0,
101
- set: (e) => t.value.dispatch({ selection: { anchor: e } })
102
- }), d = u({
103
- get: () => t.value.state,
104
- set: (e) => t.value.setState(e)
105
- }), f = u({
106
- get: () => t.value.hasFocus,
107
- set: (e) => {
108
- e && t.value.focus();
116
+ setup(props, context) {
117
+ const editor = ref();
118
+ const doc = ref(props.modelValue);
119
+ const view = shallowRef(new EditorView());
120
+ const selection = computed({
121
+ get: () => view.value.state.selection,
122
+ set: (s) => view.value.dispatch({ selection: s })
123
+ });
124
+ const cursor = computed({
125
+ get: () => selection.value.main.head || 0,
126
+ set: (a) => view.value.dispatch({ selection: { anchor: a } })
127
+ });
128
+ const state = computed({
129
+ get: () => view.value.state,
130
+ set: (s) => view.value.setState(s)
131
+ });
132
+ const focus = computed({
133
+ get: () => view.value.hasFocus,
134
+ set: (f) => {
135
+ if (f) {
136
+ view.value.focus();
137
+ }
109
138
  }
110
- }), h = u(
111
- () => E([
112
- a.basic ? A : void 0,
113
- a.minimal && !a.basic ? F : void 0,
114
- c.updateListener.of(
115
- (e) => l.emit("update", e)
139
+ });
140
+ const extensions = computed(
141
+ () => compact([
142
+ props.basic ? basicSetup : void 0,
143
+ props.minimal && !props.basic ? minimalSetup : void 0,
144
+ EditorView.updateListener.of(
145
+ (update) => context.emit("update", update)
116
146
  ),
117
- c.theme(a.theme, { dark: a.dark }),
118
- a.wrap ? c.lineWrapping : void 0,
119
- a.tab ? D.of([N]) : void 0,
120
- a.phrases ? y.phrases.of(a.phrases) : void 0,
121
- y.readOnly.of(a.readonly),
122
- c.editable.of(a.editable),
123
- a.lang ? O(a.lang) : void 0,
124
- a.linter ? G(a.linter) : void 0,
125
- a.linter && a.lintGutter ? L() : void 0,
126
- ...a.extensions
147
+ EditorView.theme(props.theme, { dark: props.dark }),
148
+ props.wrap ? EditorView.lineWrapping : void 0,
149
+ props.tab ? keymap.of([indentWithTab]) : void 0,
150
+ props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
151
+ EditorState.readOnly.of(props.readonly),
152
+ EditorView.editable.of(props.editable),
153
+ props.lang ? toRaw(props.lang) : void 0,
154
+ props.linter ? linter(props.linter) : void 0,
155
+ props.linter && props.lintGutter ? lintGutter() : void 0,
156
+ ...props.extensions
127
157
  ])
128
158
  );
129
- return m(
130
- () => a.modelValue,
131
- (e) => {
132
- !t.value || t.value.composing || t.value.dispatch({
133
- changes: { from: 0, to: t.value.state.doc.length, insert: e },
134
- selection: i.value
159
+ watch(
160
+ () => props.modelValue,
161
+ (value) => {
162
+ if (!view.value || view.value.composing) {
163
+ return;
164
+ }
165
+ const previous = view.value.state.selection;
166
+ view.value.dispatch({
167
+ changes: { from: 0, to: view.value.state.doc.length, insert: value },
168
+ selection: previous
135
169
  });
136
170
  },
137
- { immediate: !0 }
138
- ), m(h, (e) => {
139
- t.value.dispatch({
140
- effects: $.reconfigure.of(e)
171
+ { immediate: true }
172
+ );
173
+ watch(extensions, (e) => {
174
+ view.value.dispatch({
175
+ effects: StateEffect.reconfigure.of(e)
141
176
  });
142
- }), m(f, (e) => {
143
- l.emit("focus", e);
144
- }), M(async () => {
145
- let e = s.value;
146
- o.value && o.value.childNodes[0] && (s.value !== "" && console.warn(
147
- "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
148
- ), e = T(o.value.childNodes[0].innerText)), t.value = new c({
149
- doc: e,
150
- extensions: h.value,
151
- parent: o.value,
152
- dispatch: (n) => {
153
- if (t.value.update([n]), n.changes.empty)
177
+ });
178
+ watch(focus, (isFocus) => {
179
+ context.emit("focus", isFocus);
180
+ });
181
+ onMounted(async () => {
182
+ let value = doc.value;
183
+ if (editor.value && editor.value.childNodes[0]) {
184
+ if (doc.value !== "") {
185
+ console.warn(
186
+ "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
187
+ );
188
+ }
189
+ value = trim(editor.value.childNodes[0].innerText);
190
+ }
191
+ view.value = new EditorView({
192
+ doc: value,
193
+ extensions: extensions.value,
194
+ parent: editor.value,
195
+ dispatch: (tr) => {
196
+ view.value.update([tr]);
197
+ if (tr.changes.empty)
154
198
  return;
155
- const v = t.value.state.doc.toString();
156
- l.emit("update:modelValue", v), l.emit("changed", v);
199
+ const v = view.value.state.doc.toString();
200
+ context.emit("update:modelValue", v);
201
+ context.emit("changed", v);
157
202
  }
158
- }), await R(), l.emit("ready", {
159
- view: t,
160
- state: d.value,
161
- container: o.value
162
203
  });
163
- }), j(() => t.value.destroy()), {
164
- context: l,
165
- editor: o,
166
- cursor: r,
167
- selection: i,
168
- state: d,
169
- focus: f,
170
- getRange: (e, n) => t.value.state.sliceDoc(e, n),
171
- getLine: (e) => t.value.state.doc.line(e + 1).text,
172
- lineCount: () => t.value.state.doc.lines,
173
- getCursor: () => r.value,
174
- listSelections: () => t.value.state.selection.ranges,
175
- getSelection: () => t.value.state.sliceDoc(
176
- t.value.state.selection.main.from,
177
- t.value.state.selection.main.to
178
- ),
179
- getSelections: () => t.value.state.selection.ranges.map(
180
- (e) => t.value.state.sliceDoc(e.from, e.to)
181
- ),
182
- somethingSelected: () => t.value.state.selection.ranges.some(
183
- (e) => !e.empty
184
- ),
185
- replaceRange: (e, n, v) => t.value.dispatch({
186
- changes: { from: n, to: v, insert: e }
187
- }),
188
- replaceSelection: (e) => t.value.dispatch(t.value.state.replaceSelection(e)),
189
- setCursor: (e) => r.value = e,
190
- setSelection: (e, n) => t.value.dispatch({ selection: { anchor: e, head: n } }),
191
- setSelections: (e, n) => t.value.dispatch({
192
- selection: S.create(e, n)
193
- }),
194
- extendSelectionsBy: (e) => t.value.dispatch({
195
- selection: S.create(
196
- i.value.ranges.map((n) => n.extend(e(n)))
197
- )
198
- })
204
+ await nextTick();
205
+ context.emit("ready", {
206
+ view,
207
+ state: state.value,
208
+ container: editor.value
209
+ });
210
+ });
211
+ onUnmounted(() => view.value.destroy());
212
+ const getRange = (from, to) => view.value.state.sliceDoc(from, to);
213
+ const getLine = (number) => view.value.state.doc.line(number + 1).text;
214
+ const lineCount = () => view.value.state.doc.lines;
215
+ const getCursor = () => cursor.value;
216
+ const listSelections = () => view.value.state.selection.ranges;
217
+ const getSelection = () => view.value.state.sliceDoc(
218
+ view.value.state.selection.main.from,
219
+ view.value.state.selection.main.to
220
+ );
221
+ const getSelections = () => view.value.state.selection.ranges.map(
222
+ (r) => view.value.state.sliceDoc(r.from, r.to)
223
+ );
224
+ const somethingSelected = () => view.value.state.selection.ranges.some(
225
+ (r) => !r.empty
226
+ );
227
+ const replaceRange = (replacement, from, to) => view.value.dispatch({
228
+ changes: { from, to, insert: replacement }
229
+ });
230
+ const replaceSelection = (replacement) => view.value.dispatch(view.value.state.replaceSelection(replacement));
231
+ const setCursor = (position) => cursor.value = position;
232
+ const setSelection = (anchor, head) => view.value.dispatch({ selection: { anchor, head } });
233
+ const setSelections = (ranges, primary) => view.value.dispatch({
234
+ selection: EditorSelection.create(ranges, primary)
235
+ });
236
+ const extendSelectionsBy = (f) => view.value.dispatch({
237
+ selection: EditorSelection.create(
238
+ selection.value.ranges.map((r) => r.extend(f(r)))
239
+ )
240
+ });
241
+ return {
242
+ context,
243
+ editor,
244
+ cursor,
245
+ selection,
246
+ state,
247
+ focus,
248
+ getRange,
249
+ getLine,
250
+ lineCount,
251
+ getCursor,
252
+ listSelections,
253
+ getSelection,
254
+ getSelections,
255
+ somethingSelected,
256
+ replaceRange,
257
+ replaceSelection,
258
+ setCursor,
259
+ setSelection,
260
+ setSelections,
261
+ extendSelectionsBy
199
262
  };
200
263
  },
201
264
  render() {
202
- return w(
203
- "div",
265
+ return h(
266
+ this.$props.tag,
204
267
  {
205
268
  ref: "editor",
206
269
  class: "vue-codemirror"
207
270
  },
208
- this.$slots.default ? w(
271
+ this.$slots.default ? h(
209
272
  "aside",
210
273
  { style: "display: none;", "aria-hidden": "true" },
211
- W(this.$slots.default)
274
+ slot(this.$slots.default)
212
275
  ) : void 0
213
276
  );
214
277
  }
215
- }), ce = (a) => a.component("CodeMirror", b);
216
- typeof window < "u" && window.Vue && window.Vue.use(b);
217
- export {
218
- b as default,
219
- ce as install
220
- };
278
+ });
279
+
280
+ const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
281
+ if (typeof window !== "undefined" && window.Vue) {
282
+ window.Vue.use(CodeMirror);
283
+ }
284
+
285
+ export { CodeMirror as default, installCodeMirror as install };