vue-codemirror6 1.1.1 → 1.1.3

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.
@@ -3,15 +3,20 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.1
8
+ * @version 1.1.3
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
- var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, commands, lint) {
12
+ var CodeMirror = (function (exports, vueDemi, compact, trim, codemirror, state, view, commands, lint) {
13
13
  'use strict';
14
14
 
15
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var compact__default = /*#__PURE__*/_interopDefaultCompat(compact);
18
+ var trim__default = /*#__PURE__*/_interopDefaultCompat(trim);
19
+
15
20
  const adaptOnsV3 = (ons) => {
16
21
  if (!ons)
17
22
  return {};
@@ -35,7 +40,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
35
40
  };
36
41
  const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
37
42
 
38
- const CodeMirror = vueDemi.defineComponent({
43
+ var CodeMirror = vueDemi.defineComponent({
39
44
  name: "CodeMirror",
40
45
  model: {
41
46
  prop: "modelValue",
@@ -128,7 +133,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
128
133
  default: "div"
129
134
  }
130
135
  },
131
- emits: ["update:modelValue", "update", "ready", "focus", "change"],
136
+ emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
132
137
  setup(props, context) {
133
138
  const editor = vueDemi.ref();
134
139
  const doc = vueDemi.ref(props.modelValue);
@@ -157,7 +162,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
157
162
  () => view$1.value.state.doc.length
158
163
  );
159
164
  const extensions = vueDemi.computed(
160
- () => lodash.compact([
165
+ () => compact__default["default"]([
161
166
  props.basic ? codemirror.basicSetup : void 0,
162
167
  props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
163
168
  view.EditorView.updateListener.of(
@@ -202,8 +207,12 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
202
207
  vueDemi.onMounted(async () => {
203
208
  let value = doc.value;
204
209
  if (editor.value && editor.value.childNodes[0]) {
205
- if (doc.value !== "") ;
206
- value = lodash.trim(editor.value.childNodes[0].innerText);
210
+ if (doc.value !== "") {
211
+ console.warn(
212
+ "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
213
+ );
214
+ }
215
+ value = trim__default["default"](editor.value.childNodes[0].innerText);
207
216
  }
208
217
  view$1.value = new view.EditorView({
209
218
  doc: value,
@@ -215,20 +224,27 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
215
224
  return;
216
225
  const v = view$1.value.state.doc.toString();
217
226
  context.emit("update:modelValue", v);
218
- context.emit("change", v);
227
+ context.emit("change", view$1.value.state);
219
228
  }
220
229
  });
221
230
  await vueDemi.nextTick();
222
231
  context.emit("ready", {
223
232
  view: view$1,
224
- state: state$1.value,
233
+ state: view$1.value.state,
225
234
  container: editor.value
226
235
  });
227
236
  });
228
237
  vueDemi.onUnmounted(() => {
229
- view$1.value.destroy();
238
+ if (view$1.value) {
239
+ view$1.value.destroy();
240
+ context.emit("destroy");
241
+ }
230
242
  });
231
- const lint$1 = () => lint.forceLinting(view$1.value);
243
+ const lint$1 = () => {
244
+ if (props.linter) {
245
+ lint.forceLinting(view$1.value);
246
+ }
247
+ };
232
248
  const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
233
249
  const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
234
250
  const lineCount = () => view$1.value.state.doc.lines;
@@ -258,8 +274,7 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
258
274
  selection.value.ranges.map((r) => r.extend(f(r)))
259
275
  )
260
276
  });
261
- return {
262
- context,
277
+ context.expose({
263
278
  editor,
264
279
  cursor,
265
280
  selection,
@@ -281,6 +296,9 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
281
296
  setSelection,
282
297
  setSelections,
283
298
  extendSelectionsBy
299
+ });
300
+ return {
301
+ editor
284
302
  };
285
303
  },
286
304
  render() {
@@ -300,8 +318,8 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
300
318
  });
301
319
 
302
320
  const meta = {
303
- version: "1.1.1",
304
- date: "2022-11-07T00:40:00.830Z"
321
+ version: "1.1.3",
322
+ date: "2023-01-09T00:45:11.835Z"
305
323
  };
306
324
 
307
325
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -310,11 +328,11 @@ var CodeMirror = (function (exports, vueDemi, lodash, codemirror, state, view, c
310
328
  }
311
329
 
312
330
  exports.Meta = meta;
313
- exports.default = CodeMirror;
331
+ exports["default"] = CodeMirror;
314
332
  exports.install = installCodeMirror;
315
333
 
316
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
334
+ Object.defineProperty(exports, '__esModule', { value: true });
317
335
 
318
336
  return exports;
319
337
 
320
- })({}, VueDemi, lodash, codemirror, state, view, commands, lint);
338
+ })({}, VueDemi, compact, trim, codemirror, state, view, commands, lint);
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import CodeMirror from './components/CodeMirror';
2
+ import Meta from './Meta';
3
+ // TODO: Move phrases props to option.
4
+ const installCodeMirror = (app) => app.component('CodeMirror', CodeMirror);
5
+ export { CodeMirror as default, installCodeMirror as install, Meta };
6
+ // For CDN. (Maybe Vue2 only)
7
+ // @ts-ignore
8
+ if (typeof window !== 'undefined' && window.Vue) {
9
+ // @ts-ignore
10
+ window.Vue.use(CodeMirror);
11
+ }
package/dist/index.umd.js CHANGED
@@ -3,17 +3,22 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022 By Masashi Yoshikawa All rights reserved.
6
+ * @copyright 2022-2023 By Masashi Yoshikawa All rights reserved.
7
7
  * @license MIT
8
- * @version 1.1.1
8
+ * @version 1.1.3
9
9
  * @see {@link https://github.com/logue/vue-codemirror6}
10
10
  */
11
11
 
12
12
  (function (global, factory) {
13
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash'), require('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
14
- typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
15
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.lodash, global.codemirror, global.state, global.view, global.commands, global.lint));
16
- })(this, (function (exports, vueDemi, lodash, codemirror, state, view, commands, lint) { 'use strict';
13
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi'), require('lodash/compact'), require('lodash/trim'), require('codemirror'), require('@codemirror/state'), require('@codemirror/view'), require('@codemirror/commands'), require('@codemirror/lint')) :
14
+ typeof define === 'function' && define.amd ? define(['exports', 'vue-demi', 'lodash/compact', 'lodash/trim', 'codemirror', '@codemirror/state', '@codemirror/view', '@codemirror/commands', '@codemirror/lint'], factory) :
15
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CodeMirror = {}, global.VueDemi, global.compact, global.trim, global.codemirror, global.state, global.view, global.commands, global.lint));
16
+ })(this, (function (exports, vueDemi, compact, trim, codemirror, state, view, commands, lint) { 'use strict';
17
+
18
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
+
20
+ var compact__default = /*#__PURE__*/_interopDefaultCompat(compact);
21
+ var trim__default = /*#__PURE__*/_interopDefaultCompat(trim);
17
22
 
18
23
  const adaptOnsV3 = (ons) => {
19
24
  if (!ons)
@@ -38,7 +43,7 @@
38
43
  };
39
44
  const slot = (defaultSlots) => typeof defaultSlots == "function" ? defaultSlots() : defaultSlots;
40
45
 
41
- const CodeMirror = vueDemi.defineComponent({
46
+ var CodeMirror = vueDemi.defineComponent({
42
47
  name: "CodeMirror",
43
48
  model: {
44
49
  prop: "modelValue",
@@ -131,7 +136,7 @@
131
136
  default: "div"
132
137
  }
133
138
  },
134
- emits: ["update:modelValue", "update", "ready", "focus", "change"],
139
+ emits: ["update:modelValue", "update", "ready", "focus", "change", "destroy"],
135
140
  setup(props, context) {
136
141
  const editor = vueDemi.ref();
137
142
  const doc = vueDemi.ref(props.modelValue);
@@ -160,7 +165,7 @@
160
165
  () => view$1.value.state.doc.length
161
166
  );
162
167
  const extensions = vueDemi.computed(
163
- () => lodash.compact([
168
+ () => compact__default["default"]([
164
169
  props.basic ? codemirror.basicSetup : void 0,
165
170
  props.minimal && !props.basic ? codemirror.minimalSetup : void 0,
166
171
  view.EditorView.updateListener.of(
@@ -205,8 +210,12 @@
205
210
  vueDemi.onMounted(async () => {
206
211
  let value = doc.value;
207
212
  if (editor.value && editor.value.childNodes[0]) {
208
- if (doc.value !== "") ;
209
- value = lodash.trim(editor.value.childNodes[0].innerText);
213
+ if (doc.value !== "") {
214
+ console.warn(
215
+ "[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
216
+ );
217
+ }
218
+ value = trim__default["default"](editor.value.childNodes[0].innerText);
210
219
  }
211
220
  view$1.value = new view.EditorView({
212
221
  doc: value,
@@ -218,20 +227,27 @@
218
227
  return;
219
228
  const v = view$1.value.state.doc.toString();
220
229
  context.emit("update:modelValue", v);
221
- context.emit("change", v);
230
+ context.emit("change", view$1.value.state);
222
231
  }
223
232
  });
224
233
  await vueDemi.nextTick();
225
234
  context.emit("ready", {
226
235
  view: view$1,
227
- state: state$1.value,
236
+ state: view$1.value.state,
228
237
  container: editor.value
229
238
  });
230
239
  });
231
240
  vueDemi.onUnmounted(() => {
232
- view$1.value.destroy();
241
+ if (view$1.value) {
242
+ view$1.value.destroy();
243
+ context.emit("destroy");
244
+ }
233
245
  });
234
- const lint$1 = () => lint.forceLinting(view$1.value);
246
+ const lint$1 = () => {
247
+ if (props.linter) {
248
+ lint.forceLinting(view$1.value);
249
+ }
250
+ };
235
251
  const getRange = (from, to) => view$1.value.state.sliceDoc(from, to);
236
252
  const getLine = (number) => view$1.value.state.doc.line(number + 1).text;
237
253
  const lineCount = () => view$1.value.state.doc.lines;
@@ -261,8 +277,7 @@
261
277
  selection.value.ranges.map((r) => r.extend(f(r)))
262
278
  )
263
279
  });
264
- return {
265
- context,
280
+ context.expose({
266
281
  editor,
267
282
  cursor,
268
283
  selection,
@@ -284,6 +299,9 @@
284
299
  setSelection,
285
300
  setSelections,
286
301
  extendSelectionsBy
302
+ });
303
+ return {
304
+ editor
287
305
  };
288
306
  },
289
307
  render() {
@@ -303,8 +321,8 @@
303
321
  });
304
322
 
305
323
  const meta = {
306
- version: "1.1.1",
307
- date: "2022-11-07T00:40:00.830Z"
324
+ version: "1.1.3",
325
+ date: "2023-01-09T00:45:11.835Z"
308
326
  };
309
327
 
310
328
  const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
@@ -313,9 +331,9 @@
313
331
  }
314
332
 
315
333
  exports.Meta = meta;
316
- exports.default = CodeMirror;
334
+ exports["default"] = CodeMirror;
317
335
  exports.install = installCodeMirror;
318
336
 
319
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
337
+ Object.defineProperty(exports, '__esModule', { value: true });
320
338
 
321
339
  }));
@@ -1,8 +1,8 @@
1
- /** Build information meta data */
2
- export default interface MetaInterface {
3
- /** Version */
4
- version: string;
5
- /** Build date */
6
- date: string;
7
- }
1
+ /** Build information meta data */
2
+ export default interface MetaInterface {
3
+ /** Version */
4
+ version: string;
5
+ /** Build date */
6
+ date: string;
7
+ }
8
8
  //# sourceMappingURL=MetaInterface.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
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.1.1",
4
+ "version": "1.1.3",
5
5
  "license": "MIT",
6
6
  "description": "CodeMirror6 Component for vue2 and vue3.",
7
7
  "keywords": [
@@ -40,7 +40,8 @@
40
40
  "exports": {
41
41
  ".": {
42
42
  "import": "./dist/index.es.js",
43
- "require": "./dist/index.umd.js"
43
+ "require": "./dist/index.umd.js",
44
+ "types": "./dist/index.d.ts"
44
45
  }
45
46
  },
46
47
  "files": [
@@ -55,30 +56,31 @@
55
56
  "node": ">=18.12.1",
56
57
  "yarn": ">=1.22.10"
57
58
  },
58
- "packageManager": "yarn@3.2.4",
59
+ "packageManager": "yarn@3.3.1",
59
60
  "sideEffects": false,
60
61
  "scripts": {
61
62
  "dev": "vite",
62
- "clean": "rimraf ./node_modules/.vite",
63
- "type-check": "vue-tsc --noEmit --composite false",
64
- "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
65
- "lint:style": "stylelint \"./**/*.{css,sass,scss,htm,html,vue}\" --fix --cache-location ./node_modules/.vite/vite-plugin-stylelint && prettier \"./**/*.{css,sass,scss,htm,html,vue}\" -w -u",
66
- "build": "run-p type-check build-only build:declaration",
67
- "build:declaration": "vue-tsc --composite false --declaration --emitDeclarationOnly",
68
- "build:analyze": "vite build --mode analyze",
69
- "build:clean": "rimraf dist",
70
- "build:docs": "vite build --config vite.config.docs.ts",
63
+ "clean": "rimraf node_modules/.vite",
64
+ "type-check": "tsc --noEmit --composite false",
65
+ "build": "run-p type-check build-only build-declaration",
66
+ "build:analyze": "vite build --mode=analyze",
67
+ "build:clean": "rimraf dist docs",
68
+ "build:docs": "vite build --mode=docs",
71
69
  "build-only": "vite build",
72
- "preview": "vite preview --config vite.config.docs.ts",
70
+ "build-declaration": "tsc -p tsconfig.app.json --composite false --declaration --declarationMap --declarationDir dist",
71
+ "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
72
+ "preview": "vite preview --mode=docs",
73
73
  "prepare": "husky install",
74
74
  "version": "auto-changelog -p && git add CHANGELOG.md"
75
75
  },
76
76
  "dependencies": {
77
+ "codemirror": "^6.0.1",
78
+ "lodash.compact": "^3.0.1",
79
+ "lodash.trim": "^4.5.1",
77
80
  "vue-demi": "latest"
78
81
  },
79
82
  "peerDependencies": {
80
83
  "@vue/composition-api": "^1.7.1",
81
- "codemirror": "^6.0.1",
82
84
  "vue": "^2.6.14 || ^3.2.39"
83
85
  },
84
86
  "peerDependenciesMeta": {
@@ -87,45 +89,46 @@
87
89
  }
88
90
  },
89
91
  "devDependencies": {
90
- "@codemirror/lang-javascript": "^6.1.1",
92
+ "@codemirror/lang-javascript": "^6.1.2",
91
93
  "@codemirror/lang-json": "^6.0.1",
92
- "@codemirror/lang-markdown": "^6.0.4",
93
- "@types/lodash": "^4.14.188",
94
- "@types/node": "^18.11.9",
95
- "@typescript-eslint/eslint-plugin": "^5.42.0",
96
- "@typescript-eslint/parser": "^5.42.0",
97
- "@vitejs/plugin-vue": "^3.2.0",
94
+ "@codemirror/lang-markdown": "^6.0.5",
95
+ "@types/lodash": "^4.14.191",
96
+ "@types/node": "^18.11.18",
97
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
98
+ "@typescript-eslint/parser": "^5.48.0",
99
+ "@vitejs/plugin-vue": "^4.0.0",
98
100
  "@vue/eslint-config-prettier": "^7.0.0",
99
101
  "@vue/tsconfig": "^0.1.3",
100
- "codemirror": "^6.0.1",
101
- "eslint": "^8.27.0",
102
+ "@vueuse/core": "^9.10.0",
103
+ "eslint": "^8.31.0",
102
104
  "eslint-config-google": "^0.14.0",
103
- "eslint-config-prettier": "^8.5.0",
105
+ "eslint-config-prettier": "^8.6.0",
104
106
  "eslint-import-resolver-alias": "^1.1.2",
105
107
  "eslint-import-resolver-typescript": "^3.5.2",
106
- "eslint-linter-browserify": "^8.26.0",
108
+ "eslint-linter-browserify": "^8.31.0",
107
109
  "eslint-plugin-html": "^7.1.0",
108
110
  "eslint-plugin-import": "^2.26.0",
109
- "eslint-plugin-jsdoc": "^39.6.2",
111
+ "eslint-plugin-jsdoc": "^39.6.4",
112
+ "eslint-plugin-prettier": "^4.2.1",
110
113
  "eslint-plugin-tsdoc": "^0.2.17",
111
- "eslint-plugin-vue": "^9.7.0",
114
+ "eslint-plugin-vue": "^9.8.0",
112
115
  "eslint-plugin-vuejs-accessibility": "^2.0.0",
113
116
  "eslint-plugin-yaml": "^0.5.0",
114
- "husky": "^8.0.1",
115
- "lint-staged": "^13.0.3",
117
+ "husky": "^8.0.3",
118
+ "lint-staged": "^13.1.0",
116
119
  "lodash": "^4.17.21",
117
- "markdown-wasm": "^1.2.0",
118
120
  "npm-run-all": "^4.1.5",
119
- "prettier": "^2.7.1",
121
+ "prettier": "^2.8.2",
120
122
  "rimraf": "^3.0.2",
121
- "rollup-plugin-visualizer": "^5.8.3",
122
- "typescript": "^4.8.4",
123
- "vite": "^3.2.2",
124
- "vite-plugin-banner": "^0.6.1",
125
- "vite-plugin-checker": "^0.5.1",
126
- "vue": "^3.2.41",
123
+ "rollup-plugin-visualizer": "^5.9.0",
124
+ "typescript": "^4.9.4",
125
+ "vite": "^4.0.4",
126
+ "vite-plugin-banner": "^0.7.0",
127
+ "vite-plugin-checker": "^0.5.3",
128
+ "vue": "^3.2.45",
127
129
  "vue-eslint-parser": "^9.1.0",
128
- "vue-tsc": "^1.0.9"
130
+ "vue-markdown-wasm": "^0.2.0",
131
+ "vue-tsc": "^1.0.24"
129
132
  },
130
133
  "husky": {
131
134
  "hooks": {
@@ -135,9 +138,5 @@
135
138
  "lint-staged": {
136
139
  "*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
137
140
  "*": "prettier -w -u"
138
- },
139
- "resolutions": {
140
- "prettier": "^2.7.1",
141
- "@codemirror/language": "<6.3.0"
142
141
  }
143
142
  }
@@ -18,25 +18,34 @@ import {
18
18
 
19
19
  // Helpers
20
20
  import h, { slot } from '@/helpers/h-demi';
21
- import { compact, trim } from 'lodash';
21
+ import compact from 'lodash/compact';
22
+ import trim from 'lodash/trim';
22
23
 
23
24
  // CodeMirror
24
25
  import { basicSetup, minimalSetup } from 'codemirror';
25
- import { EditorSelection, EditorState, StateEffect } from '@codemirror/state';
26
- import { EditorView, keymap, placeholder } from '@codemirror/view';
27
- import { indentWithTab } from '@codemirror/commands';
28
- import { forceLinting, linter, lintGutter } from '@codemirror/lint';
29
-
30
- import type {
31
- Extension,
32
- SelectionRange,
33
- Text,
34
- Transaction,
26
+ import {
27
+ EditorSelection,
28
+ EditorState,
29
+ StateEffect,
30
+ type Extension,
31
+ type SelectionRange,
32
+ type Text,
35
33
  } from '@codemirror/state';
34
+ import {
35
+ EditorView,
36
+ keymap,
37
+ placeholder,
38
+ type ViewUpdate,
39
+ } from '@codemirror/view';
40
+ import { indentWithTab } from '@codemirror/commands';
41
+ import {
42
+ forceLinting,
43
+ linter,
44
+ lintGutter,
45
+ type LintSource,
46
+ } from '@codemirror/lint';
36
47
  import type { LanguageSupport } from '@codemirror/language';
37
- import type { LintSource } from '@codemirror/lint';
38
48
  import type { StyleSpec } from 'style-mod';
39
- import type { ViewUpdate } from '@codemirror/view';
40
49
 
41
50
  /** Emit Interface */
42
51
  export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
@@ -55,8 +64,10 @@ export interface CodeMirrorEmitsOptions extends ObjectEmitsOptions {
55
64
  container: HTMLElement;
56
65
  }
57
66
  ): void;
58
- /** onChange (same as update:modelValue) */
59
- (e: 'change', value: string | Text): void;
67
+ /** CodeMirror onDestroy */
68
+ (e: 'destroy'): void;
69
+ /** State Changed */
70
+ (e: 'change', value: EditorState): void;
60
71
  }
61
72
 
62
73
  /** CodeMirror Component */
@@ -252,7 +263,7 @@ export default defineComponent({
252
263
  },
253
264
  },
254
265
  /** Emits */
255
- emits: ['update:modelValue', 'update', 'ready', 'focus', 'change'],
266
+ emits: ['update:modelValue', 'update', 'ready', 'focus', 'change', 'destroy'],
256
267
  /**
257
268
  * Setup
258
269
  *
@@ -412,7 +423,7 @@ export default defineComponent({
412
423
  doc: value,
413
424
  extensions: extensions.value,
414
425
  parent: editor.value,
415
- dispatch: (tr: Transaction) => {
426
+ dispatch: tr => {
416
427
  view.value.update([tr]);
417
428
  // TODO: Emit lint error event
418
429
  // console.log(view.state.doc.toString(), tr);
@@ -420,20 +431,23 @@ export default defineComponent({
420
431
  // child-to-parent binding
421
432
  const v = view.value.state.doc.toString();
422
433
  context.emit('update:modelValue', v);
423
- context.emit('change', v);
434
+ context.emit('change', view.value.state);
424
435
  },
425
436
  });
426
437
  await nextTick();
427
438
  context.emit('ready', {
428
439
  view: view,
429
- state: state.value,
440
+ state: view.value.state,
430
441
  container: editor.value,
431
442
  });
432
443
  });
433
444
 
434
445
  /** Destroy */
435
446
  onUnmounted(() => {
436
- view.value.destroy();
447
+ if (view.value) {
448
+ view.value.destroy();
449
+ context.emit('destroy');
450
+ }
437
451
  });
438
452
 
439
453
  /**
@@ -441,9 +455,13 @@ export default defineComponent({
441
455
  *
442
456
  * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}
443
457
  */
444
- const lint = () => forceLinting(view.value);
458
+ const lint = () => {
459
+ if (props.linter) {
460
+ forceLinting(view.value);
461
+ }
462
+ };
445
463
 
446
- // Bellow is experimental.
464
+ /* ----- Bellow is experimental. ------ */
447
465
 
448
466
  /**
449
467
  * Get the text between the given points in the editor.
@@ -515,7 +533,7 @@ export default defineComponent({
515
533
  *
516
534
  * @param position - position.
517
535
  */
518
- const setCursor = (position: number) => (cursor.value = position);
536
+ const setCursor = (position: number): number => (cursor.value = position);
519
537
  /**
520
538
  * Set a single selection range.
521
539
  *
@@ -545,12 +563,12 @@ export default defineComponent({
545
563
  const extendSelectionsBy = (f: Function) =>
546
564
  view.value.dispatch({
547
565
  selection: EditorSelection.create(
548
- selection.value.ranges.map(r => r.extend(f(r)))
566
+ selection.value.ranges.map((r: SelectionRange) => r.extend(f(r)))
549
567
  ),
550
568
  });
551
569
 
552
- return {
553
- context,
570
+ /** Export properties and functions */
571
+ context.expose({
554
572
  editor,
555
573
  cursor,
556
574
  selection,
@@ -573,6 +591,10 @@ export default defineComponent({
573
591
  setSelection,
574
592
  setSelections,
575
593
  extendSelectionsBy,
594
+ });
595
+
596
+ return {
597
+ editor,
576
598
  };
577
599
  },
578
600
  render() {
@@ -588,7 +610,8 @@ export default defineComponent({
588
610
  class: 'vue-codemirror',
589
611
  },
590
612
  this.$slots.default
591
- ? h(
613
+ ? // Hide original content
614
+ h(
592
615
  'aside',
593
616
  { style: 'display: none;', 'aria-hidden': 'true' },
594
617
  slot(this.$slots.default)