vue-codemirror6 0.3.1 → 0.3.5

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
@@ -8,6 +8,8 @@
8
8
 
9
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.
10
10
 
11
+ If you are using Vue2, please use `0.1.x`. (The component itself supports both, but the script generated by vue-demi can only output one)
12
+
11
13
  ## Usage
12
14
 
13
15
  This component can handle bidirectional binding by `v-model` like a general Vue component.
@@ -60,7 +62,7 @@ Mark up as follows to make it work at a minimum.
60
62
  <script>
61
63
  import { ref, defineComponent } from 'vue';
62
64
 
63
- import CodeMirror from 'vue-codeMirror6';
65
+ import CodeMirror from 'vue-codemirror6';
64
66
 
65
67
  export default defineComponent({
66
68
  components: {
@@ -97,7 +99,7 @@ import { ref, defineComponent } from 'vue';
97
99
 
98
100
  import { json } from '@codemirror/lang-json';
99
101
 
100
- import CodeMirror from '@/components/CodeMirror.vue';
102
+ import CodeMirror from 'vue-codemirror6';
101
103
 
102
104
  export default defineComponent({
103
105
  components: {
@@ -212,6 +214,38 @@ export default defineComponent({
212
214
  </script>
213
215
  ```
214
216
 
217
+ ## Recommendations
218
+
219
+ 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.
220
+
221
+ ```ts
222
+ const config: UserConfig = {
223
+ // ...
224
+ build: {
225
+ rollupOptions: {
226
+ output: {
227
+ manualChunks: {
228
+ // ...
229
+ codemirror: [
230
+ // Split CodeMirror code.
231
+ 'vue-codemirror6',
232
+ '@codemirror/state',
233
+ '@codemirror/view',
234
+ // Add the following as needed.
235
+ '@codemirror/basic-setup',
236
+ '@codemirror/lang-html',
237
+ '@codemirror/lang-javascript',
238
+ '@codemirror/lang-markdown',
239
+ ],
240
+ // ...
241
+ },
242
+ },
243
+ },
244
+ },
245
+ // ...
246
+ };
247
+ ```
248
+
215
249
  ## LICENSE
216
250
 
217
251
  [MIT](LICENSE)
@@ -1,4 +1,4 @@
1
- import type { Ref, PropType, SetupContext } from 'vue-demi';
1
+ import { type Ref, type PropType, type SetupContext } from 'vue-demi';
2
2
  import type { Extension } from '@codemirror/state';
3
3
  import type { LanguageSupport } from '@codemirror/language';
4
4
  import type { Diagnostic } from '@codemirror/lint';
@@ -18,7 +18,7 @@ declare const _default: import("vue-demi").DefineComponent<{
18
18
  type: PropType<{
19
19
  [selector: string]: StyleSpec;
20
20
  }>;
21
- default: undefined;
21
+ default: () => void;
22
22
  };
23
23
  /** Dark Mode */
24
24
  dark: {
@@ -97,7 +97,7 @@ declare const _default: import("vue-demi").DefineComponent<{
97
97
  type: PropType<{
98
98
  [selector: string]: StyleSpec;
99
99
  }>;
100
- default: undefined;
100
+ default: () => void;
101
101
  };
102
102
  /** Dark Mode */
103
103
  dark: {
@@ -159,12 +159,12 @@ declare const _default: import("vue-demi").DefineComponent<{
159
159
  default: undefined;
160
160
  };
161
161
  }>>, {
162
+ readonly: boolean;
162
163
  modelValue: string;
163
164
  theme: {
164
165
  [selector: string]: StyleSpec;
165
166
  };
166
167
  dark: boolean;
167
- readonly: boolean;
168
168
  editable: boolean;
169
169
  extensions: Extension[];
170
170
  phrases: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAe,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAKzE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;;IAavC,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IApEH,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;;;;;;;;;;AA/EP,2BAA2B;AAC3B,wBA+MG"}
1
+ {"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAOlB,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;;IAavC,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IApEH,kBAAkB;;;;;IAKlB;;;;OAIG;;;;;;;IAKH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;;;;;;;;;;AA/EP,2BAA2B;AAC3B,wBAqNG"}
package/dist/index.d.ts CHANGED
@@ -7,7 +7,8 @@
7
7
  * @see {@link https://github.com/logue/vue-codemirror6}
8
8
  */
9
9
  import CodeMirror from './components/CodeMirror.vue';
10
- import { App } from 'vue-demi';
10
+ import { type App } from 'vue-demi';
11
11
  declare const installCodeMirror: (app: App) => void;
12
12
  export { CodeMirror, installCodeMirror as install };
13
+ export default CodeMirror;
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAW,GAAG,EAAE,MAAM,UAAU,CAAC;AAIxC,QAAA,MAAM,iBAAiB,QAAS,GAAG,SAElC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAW,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAI7C,QAAA,MAAM,iBAAiB,QAAS,GAAG,SAElC,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC;AACpD,eAAe,UAAU,CAAC"}
@@ -1,4 +1,4 @@
1
- import { defineComponent, ref, computed, watch, onMounted, onUnmounted, install } from "vue-demi";
1
+ import { defineComponent, ref, computed, watch, nextTick, onMounted, onUnmounted, install } from "vue-demi";
2
2
  import { EditorState } from "@codemirror/state";
3
3
  import { EditorView } from "@codemirror/view";
4
4
  import { merge, compact } from "lodash";
@@ -23,7 +23,8 @@ const _sfc_main = defineComponent({
23
23
  },
24
24
  theme: {
25
25
  type: Object,
26
- default: void 0
26
+ default: () => {
27
+ }
27
28
  },
28
29
  dark: {
29
30
  type: Boolean,
@@ -62,10 +63,8 @@ const _sfc_main = defineComponent({
62
63
  const emit = context.emit;
63
64
  const extensions = computed(() => {
64
65
  const ext = [
65
- EditorView.updateListener.of((update) => {
66
- emit("update", update);
67
- }),
68
- EditorView.theme(props.theme || {}, { dark: dark.value }),
66
+ EditorView.updateListener.of((update) => emit("update", update)),
67
+ EditorView.theme(props.theme, { dark: dark.value }),
69
68
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
70
69
  props.lang,
71
70
  props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
@@ -91,13 +90,14 @@ const _sfc_main = defineComponent({
91
90
  selection: previous
92
91
  }));
93
92
  });
94
- watch(dark, () => {
93
+ watch(extensions, async (value) => {
95
94
  view.setState(EditorState.create({
96
95
  doc: modelValue.value,
97
- extensions: extensions.value
96
+ extensions: value
98
97
  }));
99
- });
100
- onMounted(() => {
98
+ await nextTick();
99
+ }, { deep: true });
100
+ onMounted(async () => {
101
101
  const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
102
102
  view = new EditorView({
103
103
  state: EditorState.create({
@@ -113,6 +113,7 @@ const _sfc_main = defineComponent({
113
113
  emit("update:modelValue", modelValue.value);
114
114
  }
115
115
  });
116
+ await nextTick();
116
117
  });
117
118
  onUnmounted(() => view.destroy());
118
119
  return {
@@ -147,4 +148,4 @@ install();
147
148
  const installCodeMirror = (app) => {
148
149
  app.component("CodeMirror", CodeMirror);
149
150
  };
150
- export { CodeMirror, installCodeMirror as install };
151
+ export { CodeMirror, CodeMirror as default, installCodeMirror as install };
@@ -1,8 +1,8 @@
1
- (function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.lodash,o.Vue))})(this,function(o,t,s,f,m,i){"use strict";var h=(e,u)=>{const d=e.__vccOpts||e;for(const[r,c]of u)d[r]=c;return d};const V=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:void 0},dark:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:void 0},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Array,default:void 0}},emits:["update:modelValue","update"],setup(e,u){const d=t.ref(),r=t.ref(e.modelValue),c=t.ref(e.dark),v=u.emit,p=t.computed(()=>{const a=[f.EditorView.updateListener.of(l=>{v("update",l)}),f.EditorView.theme(e.theme||{},{dark:c.value}),e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?f.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(a,e.linter),e.extensions&&m.merge(a,e.extensions),m.compact(a)});let n;return t.watch(r,a=>{if(n.composing)return;const l=n.state.selection;n.setState(s.EditorState.create({doc:a,extensions:p.value,selection:l}))}),t.watch(c,()=>{n.setState(s.EditorState.create({doc:r.value,extensions:p.value}))}),t.onMounted(()=>{const a=!r.value&&d.value?d.value.childNodes[0].innerText:r.value;n=new f.EditorView({state:s.EditorState.create({doc:a,extensions:p.value}),parent:d.value,dispatch:l=>{n.update([l]),!l.changes.empty&&(r.value=n.state.doc.toString(),v("update:modelValue",r.value))}})}),t.onUnmounted(()=>n.destroy()),{context:u,editor:d}}}),S={ref:"editor",class:"vue-codemirror"};function _(e,u,d,r,c,v){return i.openBlock(),i.createElementBlock("div",S,[i.withDirectives(i.createElementVNode("aside",null,[i.renderSlot(e.$slots,"default")],512),[[i.vShow,!e.context.slots.default]])],512)}var y=h(V,[["render",_]]);/**
1
+ (function(o,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.lodash,o.Vue))})(this,function(o,t,s,c,m,i){"use strict";var v=(e,u)=>{const a=e.__vccOpts||e;for(const[r,f]of u)a[r]=f;return a};const V=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>{}},dark:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:void 0},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Array,default:void 0}},emits:["update:modelValue","update"],setup(e,u){const a=t.ref(),r=t.ref(e.modelValue),f=t.ref(e.dark),p=u.emit,h=t.computed(()=>{const d=[c.EditorView.updateListener.of(l=>p("update",l)),c.EditorView.theme(e.theme,{dark:f.value}),e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?c.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(d,e.linter),e.extensions&&m.merge(d,e.extensions),m.compact(d)});let n;return t.watch(r,d=>{if(n.composing)return;const l=n.state.selection;n.setState(s.EditorState.create({doc:d,extensions:h.value,selection:l}))}),t.watch(h,async d=>{n.setState(s.EditorState.create({doc:r.value,extensions:d})),await t.nextTick()},{deep:!0}),t.onMounted(async()=>{const d=!r.value&&a.value?a.value.childNodes[0].innerText:r.value;n=new c.EditorView({state:s.EditorState.create({doc:d,extensions:h.value}),parent:a.value,dispatch:l=>{n.update([l]),!l.changes.empty&&(r.value=n.state.doc.toString(),p("update:modelValue",r.value))}}),await t.nextTick()}),t.onUnmounted(()=>n.destroy()),{context:u,editor:a}}}),S={ref:"editor",class:"vue-codemirror"};function w(e,u,a,r,f,p){return i.openBlock(),i.createElementBlock("div",S,[i.withDirectives(i.createElementVNode("aside",null,[i.renderSlot(e.$slots,"default")],512),[[i.vShow,!e.context.slots.default]])],512)}var y=v(V,[["render",w]]);/**
2
2
  * Vue CodeMirror6 Component
3
3
  *
4
4
  * @license MIT
5
5
  * @author Logue {@link logue@hotmail.co.jp}
6
6
  * @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
7
7
  * @see {@link https://github.com/logue/vue-codemirror6}
8
- */t.install();const E=e=>{e.component("CodeMirror",y)};o.CodeMirror=y,o.install=E,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
8
+ */t.install();const _=e=>{e.component("CodeMirror",y)};o.CodeMirror=y,o.default=y,o.install=_,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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.3.1",
4
+ "version": "0.3.5",
5
5
  "description": "CodeMirror6 Component for vue3",
6
6
  "keywords": [
7
7
  "vuejs",
@@ -33,7 +33,8 @@
33
33
  "url": "https://github.com/logue/vue-codemirror6/issues"
34
34
  },
35
35
  "engines": {
36
- "node": ">=16"
36
+ "node": ">=16.15.0",
37
+ "yarn": "^1.22.18"
37
38
  },
38
39
  "license": "MIT",
39
40
  "main": "./dist/vue-codemirror6.umd.js",
@@ -56,11 +57,15 @@
56
57
  "scripts": {
57
58
  "dev": "vite",
58
59
  "clean": "rimraf node_modules/.vite",
59
- "build": "vite build & vue-tsc",
60
+ "build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
61
+ "build:analyze": "vue-tsc --noEmit && vite build --mode analyze",
62
+ "build:docs": "vite build --config vite.config.docs.ts",
60
63
  "build:clean": "rimraf dist",
61
- "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
62
- "switch:2": "vue-demi-switch 2 & npx vue-demi-fix & rimraf node_modules/.vite",
63
- "switch:3": "vue-demi-switch 3 & npx vue-demi-fix & rimraf node_modules/.vite",
64
+ "lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
65
+ "lint:markup": "vue-tsc --noEmit",
66
+ "switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
67
+ "switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
68
+ "preview": "vite preview --config vite.config.docs.ts",
64
69
  "prepare": "husky install",
65
70
  "postinstall": "npx vue-demi-fix"
66
71
  },
@@ -68,8 +73,10 @@
68
73
  "vue-demi": "latest"
69
74
  },
70
75
  "peerDependencies": {
71
- "@vue/composition-api": "^1.4.9",
72
- "vue": "^2.6.14 || ^3.2.31"
76
+ "@codemirror/state": "latest",
77
+ "@codemirror/view": "latest",
78
+ "@vue/composition-api": "latest",
79
+ "vue": "^2.6.14 || ^3.2.33"
73
80
  },
74
81
  "peerDependenciesMeta": {
75
82
  "@vue/composition-api": {
@@ -77,43 +84,43 @@
77
84
  }
78
85
  },
79
86
  "devDependencies": {
80
- "@codemirror/basic-setup": "^0.19.3",
81
- "@codemirror/lang-markdown": "^0.19.6",
82
- "@codemirror/language": "^0.19.10",
83
- "@codemirror/lint": "^0.19.6",
84
- "@codemirror/view": "^0.19.48",
85
- "@modyqyw/vite-plugin-eslint": "^1.2.0",
86
- "@types/lodash": "^4.14.181",
87
- "@types/node": "^17.0.23",
88
- "@typescript-eslint/eslint-plugin": "^5.17.0",
89
- "@typescript-eslint/parser": "^5.17.0",
90
- "@vitejs/plugin-vue": "^2.3.1",
87
+ "@codemirror/basic-setup": "^0.20.0",
88
+ "@codemirror/lang-markdown": "^0.20.0",
89
+ "@codemirror/language": "^0.20.0",
90
+ "@codemirror/lint": "^0.20.2",
91
+ "@modyqyw/vite-plugin-eslint": "^1.3.2",
92
+ "@types/lodash": "^4.14.182",
93
+ "@types/node": "^17.0.32",
94
+ "@typescript-eslint/eslint-plugin": "^5.23.0",
95
+ "@typescript-eslint/parser": "^5.23.0",
96
+ "@vitejs/plugin-vue": "^2.3.3",
91
97
  "@vue/eslint-config-typescript": "^10.0.0",
92
- "eslint": "^8.12.0",
98
+ "eslint": "^8.15.0",
93
99
  "eslint-config-google": "^0.14.0",
94
100
  "eslint-config-prettier": "^8.5.0",
95
101
  "eslint-import-resolver-alias": "^1.1.2",
96
- "eslint-import-resolver-typescript": "^2.7.0",
97
- "eslint-plugin-import": "^2.25.4",
102
+ "eslint-import-resolver-typescript": "^2.7.1",
103
+ "eslint-plugin-import": "^2.26.0",
98
104
  "eslint-plugin-prettier": "^4.0.0",
99
105
  "eslint-plugin-prettier-vue": "^3.1.0",
100
- "eslint-plugin-tsdoc": "^0.2.14",
101
- "eslint-plugin-vue": "^8.5.0",
106
+ "eslint-plugin-tsdoc": "^0.2.16",
107
+ "eslint-plugin-vue": "^8.7.1",
102
108
  "eslint-plugin-vuejs-accessibility": "^1.1.1",
103
- "husky": "^7.0.4",
104
- "lint-staged": "^12.3.7",
109
+ "husky": "^8.0.1",
110
+ "lint-staged": "^12.4.1",
105
111
  "lodash": "^4.17.21",
106
112
  "prettier": "^2.6.2",
107
- "prettier-plugin-jsdoc": "^0.3.36",
113
+ "prettier-plugin-jsdoc": "^0.3.38",
108
114
  "prettier-plugin-md-nocjsp": "^1.2.0",
109
115
  "prettier-plugin-sort-imports": "^1.6.0",
110
116
  "rimraf": "^3.0.2",
111
- "typescript": "^4.6.3",
112
- "vite": "^2.9.1",
113
- "vue": "^3.2.31",
114
- "vue-eslint-parser": "^8.3.0",
117
+ "rollup-plugin-visualizer": "^5.6.0",
118
+ "typescript": "^4.6.4",
119
+ "vite": "^2.9.9",
120
+ "vue": "^3.2.33",
121
+ "vue-eslint-parser": "^9.0.1",
115
122
  "vue-template-compiler": "^2.6.14",
116
- "vue-tsc": "^0.33.9"
123
+ "vue-tsc": "^0.34.13"
117
124
  },
118
125
  "husky": {
119
126
  "hooks": {
@@ -12,14 +12,16 @@ import {
12
12
  onMounted,
13
13
  onUnmounted,
14
14
  defineComponent,
15
+ nextTick,
16
+ type ComputedRef,
17
+ type Ref,
18
+ type PropType,
19
+ type SetupContext,
15
20
  } from 'vue-demi';
16
21
  import { EditorState } from '@codemirror/state';
17
22
  import { EditorView } from '@codemirror/view';
18
23
  import { compact, merge } from 'lodash';
19
24
 
20
- import type { ComputedRef, Ref, PropType, SetupContext } from 'vue-demi';
21
-
22
- import type CodeMirrorPropsInterface from '@/interfaces/CodeMirrorPropsInterface';
23
25
  import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
24
26
 
25
27
  import type { Extension, Transaction } from '@codemirror/state';
@@ -51,7 +53,7 @@ export default defineComponent({
51
53
  */
52
54
  theme: {
53
55
  type: Object as PropType<{ [selector: string]: StyleSpec }>,
54
- default: undefined,
56
+ default: () => {},
55
57
  },
56
58
  /** Dark Mode */
57
59
  dark: {
@@ -120,9 +122,9 @@ export default defineComponent({
120
122
  * @param props - Props
121
123
  * @param context - Context
122
124
  */
123
- setup(props: CodeMirrorPropsInterface, context: SetupContext) {
125
+ setup(props, context: SetupContext) {
124
126
  /** Editor DOM */
125
- const editor: Ref<Element | undefined> = ref<Element>();
127
+ const editor: Ref<Element | undefined> = ref();
126
128
 
127
129
  /** Model */
128
130
  const modelValue: Ref<string> = ref(props.modelValue);
@@ -138,11 +140,11 @@ export default defineComponent({
138
140
  /** Default extension */
139
141
  const ext = [
140
142
  // ViewUpdate event listener
141
- EditorView.updateListener.of((update: ViewUpdate) => {
142
- emit('update', update);
143
- }),
143
+ EditorView.updateListener.of((update: ViewUpdate) =>
144
+ emit('update', update)
145
+ ),
144
146
  // Toggle light/dark mode.
145
- EditorView.theme(props.theme || {}, { dark: dark.value }),
147
+ EditorView.theme(props.theme, { dark: dark.value }),
146
148
  // locale settings
147
149
  props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
148
150
  // Parser language setting
@@ -192,18 +194,23 @@ export default defineComponent({
192
194
  );
193
195
  });
194
196
 
195
- /** Toggle Dark mode */
196
- watch(dark, () => {
197
- view.setState(
198
- EditorState.create({
199
- doc: modelValue.value,
200
- extensions: extensions.value,
201
- })
202
- );
203
- });
197
+ /** Apply extensions */
198
+ watch(
199
+ extensions,
200
+ async value => {
201
+ view.setState(
202
+ EditorState.create({
203
+ doc: modelValue.value,
204
+ extensions: value,
205
+ })
206
+ );
207
+ await nextTick();
208
+ },
209
+ { deep: true }
210
+ );
204
211
 
205
212
  /** When loaded */
206
- onMounted(() => {
213
+ onMounted(async () => {
207
214
  /** Initial Value */
208
215
  const value =
209
216
  !modelValue.value && editor.value
@@ -226,6 +233,7 @@ export default defineComponent({
226
233
  emit('update:modelValue', modelValue.value);
227
234
  },
228
235
  });
236
+ await nextTick();
229
237
  });
230
238
 
231
239
  /** Destroy */
@@ -1,56 +0,0 @@
1
- import type { LanguageSupport } from '@codemirror/language';
2
- import type { Extension } from '@codemirror/state';
3
- import type { Diagnostic } from '@codemirror/lint';
4
- import type { StyleSpec } from 'style-mod';
5
- /** Prop Interface */
6
- export default interface CodeMirrorPropsInterface {
7
- /** Model value */
8
- modelValue: string;
9
- /**
10
- * Theme
11
- *
12
- * @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
13
- */
14
- theme?: {
15
- [selector: string]: StyleSpec;
16
- };
17
- /** Dark Mode */
18
- dark?: boolean;
19
- /**
20
- * Readonly
21
- *
22
- * @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
23
- */
24
- readonly?: boolean;
25
- /**
26
- * Editable
27
- *
28
- * @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
29
- */
30
- editable?: boolean;
31
- /**
32
- * Additional Extension
33
- *
34
- * @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
35
- */
36
- extensions?: Extension[];
37
- /**
38
- * Language Phreses
39
- *
40
- * @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
41
- */
42
- phrases?: Record<string, string>;
43
- /**
44
- * CodeMirror Language
45
- *
46
- * @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
47
- */
48
- lang?: LanguageSupport;
49
- /**
50
- * CodeMirror Linter
51
- *
52
- * @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
53
- */
54
- linter?: Diagnostic[];
55
- }
56
- //# sourceMappingURL=CodeMirrorPropsInterface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CodeMirrorPropsInterface.d.ts","sourceRoot":"","sources":["../../src/interfaces/CodeMirrorPropsInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAqB;AACrB,MAAM,CAAC,OAAO,WAAW,wBAAwB;IAC/C,kBAAkB;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,KAAK,CAAC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAC1C,gBAAgB;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;OAIG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;CACvB"}