vue-codemirror6 0.0.6 → 0.1.0

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
@@ -1,28 +1,129 @@
1
1
  # vue-codemirror6
2
2
 
3
- A component for using [CodeMirror6](https://codemirror.net/6/) with Vue. Unlike [surmon-china's vue-codemirror](https://github.com/surmon-china/vue-codemirror), it is for CodeMirror6.
3
+ [![jsdelivr CDN](https://data.jsdelivr.com/v1/package/npm/vue-codemirror6/badge)](https://www.jsdelivr.com/package/npm/vue-codemirror6)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/vue-codemirror6.svg?style=flat)](https://www.npmjs.com/package/vue-codemirror6)
5
+ [![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/vue-codemirror6/file/README.md)
6
+ [![npm version](https://img.shields.io/npm/v/vue-codemirror6.svg)](https://www.npmjs.com/package/@uiw/react-codemirror)
7
+ [![Open in Gitpod](https://shields.io/badge/Open%20in-Gitpod-green?logo=Gitpod)](https://gitpod.io/#https://github.com/logue/vue-codemirror6)
8
+
9
+ A component for using [CodeMirror6](https://codemirror.net/6/) with Vue. Unrelated to [surmon-china's vue-codemirror](https://github.com/surmon-china/vue-codemirror), it is for CodeMirror6.
4
10
 
5
11
  ## Usage
6
12
 
7
13
  This component can handle bidirectional binding by `v-model` like a general Vue component.
8
14
 
9
- Other options are currently as follows:
10
-
11
- | attribute | information |
12
- | ---------- | -------------------------------------------------------------------------------------------------------------------------------- |
13
- | lang | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
14
- | phrases | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
15
- | extensions | Includes enhancements to extend CodeMirror. Such as [@codemirror/basic-setup](https://github.com/codemirror/basic-setup). |
16
- | dark | Toggle Darkmode. |
17
- | linter | Set Linter. see example <https://codesandbox.io/s/f6nb0?file=/src/index.js> |
15
+ ### Props
16
+
17
+ | Props | Type | Information |
18
+ | ---------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
+ | value | string? | Initial text value. |
20
+ | dark | boolean | Toggle Darkmode. If you use Vuetify, I recommend that you enter `$vuetify.theme.dark`. |
21
+ | 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. |
22
+ | readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
23
+ | 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. |
24
+ | lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
25
+ | 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/> |
26
+ | extensions | Extension[] | Includes enhancements to extend CodeMirror. Such as [@codemirror/basic-setup](https://github.com/codemirror/basic-setup). |
27
+ | linter | Diagnostic[] | Set Linter. see example <https://codesandbox.io/s/f6nb0?file=/src/index.js> |
28
+
29
+ Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
30
+
31
+ ### Events
32
+
33
+ | name | Information |
34
+ | ------ | ------------------------------------------------------------------------------------- |
35
+ | input | When value changed. |
36
+ | update | CodeMirror ViewUpdate event. see <https://codemirror.net/6/docs/ref/#view.ViewUpdate> |
37
+
38
+ ### Support Languages
39
+
40
+ - [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
41
+ - [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
42
+ - [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
43
+ - [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
44
+ - [`@codemirror/lang-json`](https://www.npmjs.com/package/@codemirror/lang-json)
45
+ - [`@codemirror/lang-lezer`](https://www.npmjs.com/package/@codemirror/lang-lezer)
46
+ - [`@codemirror/lang-markdown`](https://www.npmjs.com/package/@codemirror/lang-markdown)
47
+ - [`@codemirror/lang-php`](https://www.npmjs.com/package/@codemirror/lang-php)
48
+ - [`@codemirror/lang-python`](https://www.npmjs.com/package/@codemirror/lang-python)
49
+ - [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
50
+ - [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
51
+ - [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
52
+
53
+ ### Supported Themes
54
+
55
+ - [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
56
+ - [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
18
57
 
19
58
  ## Example
20
59
 
60
+ Mark up as follows to make it work at a minimum.
61
+
62
+ ```vue
63
+ <template>
64
+ <code-mirror v-model="value" />
65
+ </template>
66
+
67
+ <script>
68
+ import Vue from 'vue';
69
+
70
+ import CodeMirror from '@/components/CodeMirror.vue';
71
+
72
+ export default Vue.extend({
73
+ components: {
74
+ CodeMirror,
75
+ },
76
+ data() {
77
+ return {
78
+ value: 'The quick brown fox jumps over the lazy dog.',
79
+ };
80
+ },
81
+ });
82
+ </script>
83
+ ```
84
+
85
+ ### Example using Slots
86
+
87
+ The contents of the slot will overwrite the existing `value`. For this reason, it is recommended to use it when simply displaying with a `readonly` prop without using `v-model` or `value`.
88
+
89
+ Also, insert a `<pre>` tag to prevent the text in the slot from being automatically formatted.
90
+
91
+ ```vue
92
+ <template>
93
+ <code-mirror :lang="lang" :editable="false">
94
+ <pre>
95
+ {
96
+ "key": "value"
97
+ }</pre
98
+ >
99
+ </code-mirror>
100
+ </template>
101
+
102
+ <script>
103
+ import { Component, Vue } from 'vue-property-decorator';
104
+
105
+ import { json } from '@codemirror/lang-json';
106
+
107
+ export default Vue.extend({
108
+ components: {
109
+ CodeMirror,
110
+ },
111
+ data() {
112
+ return {
113
+ lang: json(),
114
+ };
115
+ },
116
+ });
117
+ </script>
118
+ ```
119
+
120
+ ### Full Example
121
+
21
122
  When using as a Markdown editor on [Vuetify](https://vuetifyjs.com/).
22
123
 
23
124
  ```vue
24
125
  <template>
25
- <codemirror
126
+ <code-mirror
26
127
  v-model="value"
27
128
  :lang="lang"
28
129
  :phrases="phreses"
@@ -39,11 +140,11 @@ import { Component, Vue } from 'vue-property-decorator';
39
140
  import CodeMirror from 'vue-codemirror6';
40
141
 
41
142
  // CodeMirror extensions
42
- import { basicSetup } from '@codemirror/basic-setup';
143
+ import type { LanguageSupport } from '@codemirror/language';
43
144
  import { markdown } from '@codemirror/lang-markdown';
44
- import type { ViewUpdate } from '@codemirror/view';
145
+ import { basicSetup } from '@codemirror/basic-setup';
45
146
  import type { Extension } from '@codemirror/state';
46
- import type { LanguageSupport } from '@codemirror/language';
147
+ import type { ViewUpdate } from '@codemirror/view';
47
148
 
48
149
  @Component({ components: { CodeMirror } })
49
150
  export default class Home extends Vue {
@@ -58,7 +159,8 @@ export default class Home extends Vue {
58
159
  lang: LanguageSupport = markdown();
59
160
 
60
161
  /**
61
- * Internationalization Config. In this example, the display language is Japanese.
162
+ * Internationalization Config.
163
+ * In this example, the display language to Japanese.
62
164
  *
63
165
  * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
64
166
  */
@@ -91,7 +193,7 @@ export default class Home extends Vue {
91
193
  // @codemirror/lint
92
194
  Diagnostics: 'エラー',
93
195
  'No diagnostics': 'エラーなし',
94
- }
196
+ };
95
197
 
96
198
  /**
97
199
  * CodeMirror Extensions
@@ -100,20 +202,21 @@ export default class Home extends Vue {
100
202
  */
101
203
  extensions: Extension[] = [
102
204
  /** @see {@link:https://codemirror.net/6/docs/ref/#basic-setup | basic-setup} */
103
- basicSetup
104
- ]
205
+ basicSetup,
206
+ ];
105
207
 
106
208
  /**
107
209
  * CodeMirror Hook View update event
108
210
  *
109
- * @param update View Update
211
+ * @param update - View Update
110
212
  *
111
213
  * @see {@link https://codemirror.net/6/docs/ref/#view.ViewUpdate|class ViewUpdate}
112
214
  */
113
215
  onCmUpdate(update: ViewUpdate) {
114
- console.log(update)
216
+ console.log(update);
115
217
  }
116
218
  }
219
+ </script>
117
220
  ```
118
221
 
119
222
  ## LICENSE
@@ -17,6 +17,18 @@ export default class CodeMirror extends Vue {
17
17
  };
18
18
  /** Dark Mode */
19
19
  readonly dark: boolean;
20
+ /**
21
+ * Readonly
22
+ *
23
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
24
+ */
25
+ readonly readonly: boolean;
26
+ /**
27
+ * Editable
28
+ *
29
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
30
+ */
31
+ readonly editable: boolean;
20
32
  /**
21
33
  * Language Phreses
22
34
  *
@@ -49,7 +61,7 @@ export default class CodeMirror extends Vue {
49
61
  * @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
50
62
  */
51
63
  onValueChanged(): void;
52
- /** Darkmode */
64
+ /** Toggle Dark mode */
53
65
  onToggleDarkMode(): void;
54
66
  /** CodeMirror Extension */
55
67
  get extension(): Extension[];
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,GAAG,EAAS,MAAM,wBAAwB,CAAC;AAGrE,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAK3C,2BAA2B;AAC3B,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,GAAG;IACzC,aAAa;IACb,OAAO,CAAC,MAAM,CAAc;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,KAAK,EAAG;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAEnD,gBAAgB;IAEhB,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAC;IAExB;;;;OAIG;IAEH,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1C;;;;OAIG;IAEH,QAAQ,CAAC,UAAU,EAAG,SAAS,EAAE,CAAC;IAElC;;;;OAIG;IAEH,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAC;IAEhC;;;;OAIG;IAEH,QAAQ,CAAC,MAAM,EAAG,UAAU,EAAE,CAAC;IAE/B,YAAY;IAEZ,QAAQ,CAAC,KAAK,EAAG,MAAM,CAAC;IAExB;;;;OAIG;IAEH,cAAc;IAqBd,eAAe;IAEf,gBAAgB;IAShB,2BAA2B;IAC3B,IAAI,SAAS,IAAI,SAAS,EAAE,CA4B3B;IAED,kBAAkB;IAClB,OAAO;IAwBP,cAAc;IACd,aAAa;IAIb,6BAA6B;IAC7B,OAAO,CAAC,sBAAsB;CAS/B"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,GAAG,EAAS,MAAM,wBAAwB,CAAC;AAGrE,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAK3C,2BAA2B;AAC3B,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,GAAG;IACzC,aAAa;IACb,OAAO,CAAC,MAAM,CAAc;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,KAAK,EAAG;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAEnD,gBAAgB;IAEhB,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAC;IAExB;;;;OAIG;IAEH,QAAQ,CAAC,QAAQ,EAAG,OAAO,CAAC;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,QAAQ,EAAG,OAAO,CAAC;IAE5B;;;;OAIG;IAEH,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1C;;;;OAIG;IAEH,QAAQ,CAAC,UAAU,EAAG,SAAS,EAAE,CAAC;IAElC;;;;OAIG;IAEH,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAC;IAEhC;;;;OAIG;IAEH,QAAQ,CAAC,MAAM,EAAG,UAAU,EAAE,CAAC;IAE/B,YAAY;IAEZ,QAAQ,CAAC,KAAK,EAAG,MAAM,CAAC;IAExB;;;;OAIG;IAEH,cAAc;IAgBd,uBAAuB;IAEvB,gBAAgB;IAShB,2BAA2B;IAC3B,IAAI,SAAS,IAAI,SAAS,EAAE,CAgC3B;IAED,kBAAkB;IAClB,OAAO;IAyBP,cAAc;IACd,aAAa;IAIb,6BAA6B;IAC7B,OAAO,CAAC,sBAAsB;CAS/B"}
@@ -15,6 +15,9 @@ var __decorateClass = (decorators, target, key, kind) => {
15
15
  };
16
16
  let CodeMirror = class extends Vue {
17
17
  onValueChanged() {
18
+ if (this.editor.composing) {
19
+ return;
20
+ }
18
21
  const previous = this.editor.state.selection;
19
22
  this.editor.setState(EditorState.create({
20
23
  doc: this.value,
@@ -33,7 +36,9 @@ let CodeMirror = class extends Vue {
33
36
  EditorView.updateListener.of((update) => this.$emit("update", update)),
34
37
  EditorView.theme(this.theme, { dark: this.dark }),
35
38
  this.phrases ? EditorState.phrases.of(this.phrases) : void 0,
36
- this.lang ? this.lang : void 0
39
+ this.lang ? this.lang : void 0,
40
+ EditorState.readOnly.of(this.readonly),
41
+ EditorView.editable.of(this.editable)
37
42
  ]);
38
43
  if (this.linter.length !== 0) {
39
44
  merge(ext, this.linter);
@@ -77,6 +82,12 @@ __decorateClass([
77
82
  __decorateClass([
78
83
  Prop({ type: Boolean, default: false })
79
84
  ], CodeMirror.prototype, "dark", 2);
85
+ __decorateClass([
86
+ Prop({ type: Boolean, default: false })
87
+ ], CodeMirror.prototype, "readonly", 2);
88
+ __decorateClass([
89
+ Prop({ type: Boolean, default: true })
90
+ ], CodeMirror.prototype, "editable", 2);
80
91
  __decorateClass([
81
92
  Prop({ type: Object })
82
93
  ], CodeMirror.prototype, "phrases", 2);
@@ -105,7 +116,7 @@ var render = function() {
105
116
  var _vm = this;
106
117
  var _h = _vm.$createElement;
107
118
  var _c = _vm._self._c || _h;
108
- return _c("div", { ref: "editor" }, [!_vm.$slots.default ? [_vm._t("default")] : _vm._e()], 2);
119
+ return _c("pre", { ref: "editor" }, [_vm._v(" "), !_vm.$slots.default ? [_vm._t("default")] : _vm._e(), _vm._v("\n")], 2);
109
120
  };
110
121
  var staticRenderFns = [];
111
122
  function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
@@ -1,2 +1,3 @@
1
- (function(i,a){typeof exports=="object"&&typeof module<"u"?module.exports=a(require("vue-property-decorator"),require("@codemirror/state"),require("@codemirror/view"),require("lodash")):typeof define=="function"&&define.amd?define(["vue-property-decorator","@codemirror/state","@codemirror/view","lodash"],a):(i=typeof globalThis<"u"?globalThis:i||self,i.CodeMirror=a(i.vuePropertyDecorator,i.state,i.view,i.lodash))})(this,function(i,a,c,_){"use strict";var y=Object.defineProperty,$=Object.getOwnPropertyDescriptor,s=(e,t,h,f)=>{for(var o=f>1?void 0:f?$(t,h):t,p=e.length-1,u;p>=0;p--)(u=e[p])&&(o=(f?u(t,h,o):u(o))||o);return f&&o&&y(t,h,o),o};let r=class extends i.Vue{onValueChanged(){const e=this.editor.state.selection;this.editor.setState(a.EditorState.create({doc:this.value,extensions:this.extension,selection:e}))}onToggleDarkMode(){this.editor.setState(a.EditorState.create({doc:this.value,extensions:this.extension}))}get extension(){const e=_.compact([c.EditorView.updateListener.of(t=>this.$emit("update",t)),c.EditorView.theme(this.theme,{dark:this.dark}),this.phrases?a.EditorState.phrases.of(this.phrases):void 0,this.lang?this.lang:void 0]);return this.linter.length!==0&&_.merge(e,this.linter),this.extensions.length!==0&&_.merge(e,this.extensions),console.debug("[CodeMirror.vue] Loaded extensions:",e),e}mounted(){let e=this.value;!this.value&&this.$slots.default!==void 0&&(e=this.getChildrenTextContent(this.$slots.default)),this.editor=new c.EditorView({state:a.EditorState.create({doc:e,extensions:this.extension}),parent:this.$refs.editor,dispatch:t=>{this.editor.update([t]),!t.changes.empty&&this.$emit("input",this.editor.state.doc.toString())}})}beforeDestroy(){this.editor.destroy()}getChildrenTextContent(e){return e.map(t=>t.children?this.getChildrenTextContent(t.children):t.text||`
2
- `).join("")}};s([i.Prop({type:Object,default:()=>{}})],r.prototype,"theme",2),s([i.Prop({type:Boolean,default:!1})],r.prototype,"dark",2),s([i.Prop({type:Object})],r.prototype,"phrases",2),s([i.Prop({type:Array,default:()=>[]})],r.prototype,"extensions",2),s([i.Prop({type:Object})],r.prototype,"lang",2),s([i.Prop({type:Array,default:()=>[]})],r.prototype,"linter",2),s([i.Prop({type:String,default:""})],r.prototype,"value",2),s([i.Watch("value")],r.prototype,"onValueChanged",1),s([i.Watch("dark")],r.prototype,"onToggleDarkMode",1),r=s([i.Component({name:"CodeMirror"})],r);var S=function(){var e=this,t=e.$createElement,h=e._self._c||t;return h("div",{ref:"editor"},[e.$slots.default?e._e():[e._t("default")]],2)},x=[];function O(e,t,h,f,o,p,u,M){var n=typeof e=="function"?e.options:e;t&&(n.render=t,n.staticRenderFns=h,n._compiled=!0),f&&(n.functional=!0),p&&(n._scopeId="data-v-"+p);var l;if(u?(l=function(d){d=d||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!d&&typeof __VUE_SSR_CONTEXT__<"u"&&(d=__VUE_SSR_CONTEXT__),o&&o.call(this,d),d&&d._registeredComponents&&d._registeredComponents.add(u)},n._ssrRegister=l):o&&(l=M?function(){o.call(this,(n.functional?this.parent:this).$root.$options.shadowRoot)}:o),l)if(n.functional){n._injectStyles=l;var w=n.render;n.render=function(V,g){return l.call(g),w(V,g)}}else{var C=n.beforeCreate;n.beforeCreate=C?[].concat(C,l):[l]}return{exports:e,options:n}}const m={};var T=O(r,S,x,!1,b,null,null,null);function b(e){for(let t in m)this[t]=m[t]}var E=function(){return T.exports}(),v=(()=>{const e=E;return e.install=t=>{t.component("CodeMirror",e)},e})(),j=Object.freeze(Object.defineProperty({__proto__:null,default:v},Symbol.toStringTag,{value:"Module"}));return Object.entries(j).forEach(([e,t])=>{e!=="default"&&(v[e]=t)}),v});
1
+ (function(i,d){typeof exports=="object"&&typeof module<"u"?module.exports=d(require("vue-property-decorator"),require("@codemirror/state"),require("@codemirror/view"),require("lodash")):typeof define=="function"&&define.amd?define(["vue-property-decorator","@codemirror/state","@codemirror/view","lodash"],d):(i=typeof globalThis<"u"?globalThis:i||self,i.CodeMirror=d(i.vuePropertyDecorator,i.state,i.view,i.lodash))})(this,function(i,d,c,_){"use strict";var g=Object.defineProperty,b=Object.getOwnPropertyDescriptor,s=(e,t,p,f)=>{for(var r=f>1?void 0:f?b(t,p):t,h=e.length-1,u;h>=0;h--)(u=e[h])&&(r=(f?u(t,p,r):u(r))||r);return f&&r&&g(t,p,r),r};let o=class extends i.Vue{onValueChanged(){if(this.editor.composing)return;const e=this.editor.state.selection;this.editor.setState(d.EditorState.create({doc:this.value,extensions:this.extension,selection:e}))}onToggleDarkMode(){this.editor.setState(d.EditorState.create({doc:this.value,extensions:this.extension}))}get extension(){const e=_.compact([c.EditorView.updateListener.of(t=>this.$emit("update",t)),c.EditorView.theme(this.theme,{dark:this.dark}),this.phrases?d.EditorState.phrases.of(this.phrases):void 0,this.lang?this.lang:void 0,d.EditorState.readOnly.of(this.readonly),c.EditorView.editable.of(this.editable)]);return this.linter.length!==0&&_.merge(e,this.linter),this.extensions.length!==0&&_.merge(e,this.extensions),console.debug("[CodeMirror.vue] Loaded extensions:",e),e}mounted(){let e=this.value;!this.value&&this.$slots.default!==void 0&&(e=this.getChildrenTextContent(this.$slots.default)),this.editor=new c.EditorView({state:d.EditorState.create({doc:e,extensions:this.extension}),parent:this.$refs.editor,dispatch:t=>{this.editor.update([t]),!t.changes.empty&&this.$emit("input",this.editor.state.doc.toString())}})}beforeDestroy(){this.editor.destroy()}getChildrenTextContent(e){return e.map(t=>t.children?this.getChildrenTextContent(t.children):t.text||`
2
+ `).join("")}};s([i.Prop({type:Object,default:()=>{}})],o.prototype,"theme",2),s([i.Prop({type:Boolean,default:!1})],o.prototype,"dark",2),s([i.Prop({type:Boolean,default:!1})],o.prototype,"readonly",2),s([i.Prop({type:Boolean,default:!0})],o.prototype,"editable",2),s([i.Prop({type:Object})],o.prototype,"phrases",2),s([i.Prop({type:Array,default:()=>[]})],o.prototype,"extensions",2),s([i.Prop({type:Object})],o.prototype,"lang",2),s([i.Prop({type:Array,default:()=>[]})],o.prototype,"linter",2),s([i.Prop({type:String,default:""})],o.prototype,"value",2),s([i.Watch("value")],o.prototype,"onValueChanged",1),s([i.Watch("dark")],o.prototype,"onToggleDarkMode",1),o=s([i.Component({name:"CodeMirror"})],o);var S=function(){var e=this,t=e.$createElement,p=e._self._c||t;return p("pre",{ref:"editor"},[e._v(" "),e.$slots.default?e._e():[e._t("default")],e._v(`
3
+ `)],2)},$=[];function E(e,t,p,f,r,h,u,M){var n=typeof e=="function"?e.options:e;t&&(n.render=t,n.staticRenderFns=p,n._compiled=!0),f&&(n.functional=!0),h&&(n._scopeId="data-v-"+h);var l;if(u?(l=function(a){a=a||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!a&&typeof __VUE_SSR_CONTEXT__<"u"&&(a=__VUE_SSR_CONTEXT__),r&&r.call(this,a),a&&a._registeredComponents&&a._registeredComponents.add(u)},n._ssrRegister=l):r&&(l=M?function(){r.call(this,(n.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(n.functional){n._injectStyles=l;var V=n.render;n.render=function(w,C){return l.call(C),V(w,C)}}else{var y=n.beforeCreate;n.beforeCreate=y?[].concat(y,l):[l]}return{exports:e,options:n}}const v={};var O=E(o,S,$,!1,x,null,null,null);function x(e){for(let t in v)this[t]=v[t]}var T=function(){return O.exports}(),m=(()=>{const e=T;return e.install=t=>{t.component("CodeMirror",e)},e})(),j=Object.freeze(Object.defineProperty({__proto__:null,default:m},Symbol.toStringTag,{value:"Module"}));return Object.entries(j).forEach(([e,t])=>{e!=="default"&&(m[e]=t)}),m});
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": "0.0.6",
4
+ "version": "0.1.0",
5
5
  "description": "CodeMirror6 Component for vue2",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -90,7 +90,7 @@
90
90
  "eslint-plugin-vue": "^8.5.0",
91
91
  "eslint-plugin-vuejs-accessibility": "^1.1.1",
92
92
  "husky": "^7.0.4",
93
- "lint-staged": "^12.3.6",
93
+ "lint-staged": "^12.3.7",
94
94
  "prettier": "^2.6.0",
95
95
  "prettier-plugin-jsdoc": "^0.3.31",
96
96
  "prettier-plugin-md-nocjsp": "^1.2.0",
@@ -1,7 +1,7 @@
1
1
  <template>
2
- <div ref="editor">
2
+ <pre ref="editor">
3
3
  <template v-if="!$slots.default"><slot /></template>
4
- </div>
4
+ </pre>
5
5
  </template>
6
6
 
7
7
  <script lang="ts">
@@ -38,6 +38,22 @@ export default class CodeMirror extends Vue {
38
38
  @Prop({ type: Boolean, default: false })
39
39
  readonly dark!: boolean;
40
40
 
41
+ /**
42
+ * Readonly
43
+ *
44
+ * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
45
+ */
46
+ @Prop({ type: Boolean, default: false })
47
+ readonly readonly!: boolean;
48
+
49
+ /**
50
+ * Editable
51
+ *
52
+ * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
53
+ */
54
+ @Prop({ type: Boolean, default: true })
55
+ readonly editable!: boolean;
56
+
41
57
  /**
42
58
  * Language Phreses
43
59
  *
@@ -81,17 +97,12 @@ export default class CodeMirror extends Vue {
81
97
  */
82
98
  @Watch('value')
83
99
  onValueChanged() {
100
+ if (this.editor.composing) {
101
+ // IME fix
102
+ return;
103
+ }
84
104
  /** Previous cursor location */
85
105
  const previous = this.editor.state.selection;
86
- /*
87
- this.editor.dispatch({
88
- changes: {
89
- from: 0,
90
- to: this.editor.state.doc.length,
91
- insert: this.value,
92
- },
93
- });
94
- */
95
106
  this.editor.setState(
96
107
  EditorState.create({
97
108
  doc: this.value,
@@ -101,7 +112,7 @@ export default class CodeMirror extends Vue {
101
112
  );
102
113
  }
103
114
 
104
- /** Darkmode */
115
+ /** Toggle Dark mode */
105
116
  @Watch('dark')
106
117
  onToggleDarkMode() {
107
118
  this.editor.setState(
@@ -126,6 +137,10 @@ export default class CodeMirror extends Vue {
126
137
  this.phrases ? EditorState.phrases.of(this.phrases) : undefined,
127
138
  // Parser language setting
128
139
  this.lang ? this.lang : undefined,
140
+ // Readonly option
141
+ EditorState.readOnly.of(this.readonly),
142
+ // Editable option
143
+ EditorView.editable.of(this.editable),
129
144
  ]);
130
145
 
131
146
  if (this.linter.length !== 0) {
@@ -148,6 +163,7 @@ export default class CodeMirror extends Vue {
148
163
  let value = this.value;
149
164
  if (!this.value && this.$slots.default !== undefined) {
150
165
  // override text node
166
+ // console.log(this.$slots.default);
151
167
  value = this.getChildrenTextContent(this.$slots.default);
152
168
  }
153
169