vue-codemirror6 0.5.0 → 0.5.1
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 +27 -23
- package/dist/components/CodeMirror.d.ts +4 -4
- package/dist/components/CodeMirror.d.ts.map +1 -1
- package/dist/index.es.js +5 -5
- package/dist/index.umd.js +2 -2
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -24,19 +24,19 @@ yarn add vue-codemirror6 @vue/composition-api
|
|
|
24
24
|
|
|
25
25
|
### Props
|
|
26
26
|
|
|
27
|
-
| Props | Type | Information
|
|
28
|
-
| ---------- | --------------------------------- |
|
|
29
|
-
| basic | boolean | Use [basic-setup](https://codemirror.net/6/docs/ref/#basic-setup).
|
|
30
|
-
| dark | boolean | Toggle Darkmode. It can be changed in real time, but the input value will return to the initial value.
|
|
31
|
-
| wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping).
|
|
32
|
-
| tab | boolean | Enables tab indentation.
|
|
33
|
-
| 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.
|
|
34
|
-
| readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value.
|
|
35
|
-
| 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.
|
|
36
|
-
| lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages>
|
|
37
|
-
| phrases | Record<string, string> | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/>
|
|
38
|
-
| extensions | Extension[] | Includes enhancements to extend CodeMirror.
|
|
39
|
-
| linter |
|
|
27
|
+
| Props | Type | Information |
|
|
28
|
+
| ---------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| basic | boolean | Use [basic-setup](https://codemirror.net/6/docs/ref/#basic-setup). |
|
|
30
|
+
| dark | boolean | Toggle Darkmode. It can be changed in real time, but the input value will return to the initial value. |
|
|
31
|
+
| wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
|
|
32
|
+
| tab | boolean | Enables tab indentation. |
|
|
33
|
+
| 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. |
|
|
34
|
+
| readonly | boolean | Makes the cursor visible or you can drag the text but not edit the value. |
|
|
35
|
+
| 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. |
|
|
36
|
+
| lang | LanguageSupport | The language you want to have syntax highlighting. see <https://codemirror.net/6/#languages> |
|
|
37
|
+
| phrases | Record<string, string> | Specify here if you want to make the displayed character string multilingual. see <https://codemirror.net/6/examples/translate/> |
|
|
38
|
+
| extensions | Extension[] | Includes enhancements to extend CodeMirror. |
|
|
39
|
+
| 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. |
|
|
40
40
|
|
|
41
41
|
Notice: `lang` and `linter` can also be set together in `extensions`. This is defined for usability compatibility with past CodeMirrors.
|
|
42
42
|
|
|
@@ -95,7 +95,7 @@ Also, insert a `<pre>` tag to prevent the text in the slot from being automatica
|
|
|
95
95
|
|
|
96
96
|
```vue
|
|
97
97
|
<template>
|
|
98
|
-
<code-mirror :lang="lang" :
|
|
98
|
+
<code-mirror :lang="lang" :linter="linter">
|
|
99
99
|
<pre>
|
|
100
100
|
{
|
|
101
101
|
"key": "value"
|
|
@@ -107,7 +107,7 @@ Also, insert a `<pre>` tag to prevent the text in the slot from being automatica
|
|
|
107
107
|
<script>
|
|
108
108
|
import { ref, defineComponent } from 'vue';
|
|
109
109
|
|
|
110
|
-
import { json } from '@codemirror/lang-json';
|
|
110
|
+
import { json, jsonParseLinter } from '@codemirror/lang-json';
|
|
111
111
|
|
|
112
112
|
import CodeMirror from 'vue-codemirror6';
|
|
113
113
|
|
|
@@ -116,8 +116,9 @@ export default defineComponent({
|
|
|
116
116
|
CodeMirror,
|
|
117
117
|
},
|
|
118
118
|
setup() {
|
|
119
|
-
const lang =
|
|
120
|
-
|
|
119
|
+
const lang = json();
|
|
120
|
+
const linter = jsonParseLinter();
|
|
121
|
+
return { lang, linter };
|
|
121
122
|
},
|
|
122
123
|
});
|
|
123
124
|
</script>
|
|
@@ -125,7 +126,7 @@ export default defineComponent({
|
|
|
125
126
|
|
|
126
127
|
### Full Example
|
|
127
128
|
|
|
128
|
-
When using as a Markdown editor on [
|
|
129
|
+
When using as a Markdown editor on [vite-vue2-vuetify-ts-starter](https://github.com/logue/vite-vue2-vuetify-ts-starter ).
|
|
129
130
|
|
|
130
131
|
```vue
|
|
131
132
|
<template>
|
|
@@ -169,7 +170,7 @@ export default defineComponent({
|
|
|
169
170
|
*
|
|
170
171
|
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
171
172
|
*/
|
|
172
|
-
const lang:
|
|
173
|
+
const lang: LanguageSupport = md();
|
|
173
174
|
|
|
174
175
|
/** Dark mode **/
|
|
175
176
|
const dark = ref(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
@@ -180,6 +181,7 @@ export default defineComponent({
|
|
|
180
181
|
/**
|
|
181
182
|
* Internationalization Config.
|
|
182
183
|
* In this example, the display language to Japanese.
|
|
184
|
+
* Must be reactive when used in combination with vue-i18n.
|
|
183
185
|
*
|
|
184
186
|
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
185
187
|
*/
|
|
@@ -239,10 +241,12 @@ const config: UserConfig = {
|
|
|
239
241
|
// ...
|
|
240
242
|
codemirror: [
|
|
241
243
|
// Split CodeMirror code.
|
|
242
|
-
'
|
|
243
|
-
'@codemirror/
|
|
244
|
-
'@codemirror/
|
|
245
|
-
'@codemirror/
|
|
244
|
+
'@codemirror/basic-setup': 'basicSetup',
|
|
245
|
+
'@codemirror/commands': 'commands',
|
|
246
|
+
'@codemirror/language': 'language',
|
|
247
|
+
'@codemirror/lint': 'lint',
|
|
248
|
+
'@codemirror/state': 'state',
|
|
249
|
+
'@codemirror/view': 'view',
|
|
246
250
|
// Add the following as needed.
|
|
247
251
|
'@codemirror/lang-html',
|
|
248
252
|
'@codemirror/lang-javascript',
|
|
@@ -2,7 +2,7 @@ import { type PropType, type Ref, type SetupContext } from 'vue-demi';
|
|
|
2
2
|
import { EditorSelection } from '@codemirror/state';
|
|
3
3
|
import type { Extension, Text } from '@codemirror/state';
|
|
4
4
|
import type { LanguageSupport } from '@codemirror/language';
|
|
5
|
-
import type {
|
|
5
|
+
import type { LintSource } from '@codemirror/lint';
|
|
6
6
|
import type { StyleSpec } from 'style-mod';
|
|
7
7
|
/** CodeMirror Component */
|
|
8
8
|
declare const _default: import("vue-demi").DefineComponent<{
|
|
@@ -117,7 +117,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
117
117
|
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
118
118
|
*/
|
|
119
119
|
linter: {
|
|
120
|
-
type: PropType<
|
|
120
|
+
type: PropType<LintSource>;
|
|
121
121
|
default: () => undefined;
|
|
122
122
|
};
|
|
123
123
|
}, {
|
|
@@ -235,7 +235,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
235
235
|
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
236
236
|
*/
|
|
237
237
|
linter: {
|
|
238
|
-
type: PropType<
|
|
238
|
+
type: PropType<LintSource>;
|
|
239
239
|
default: () => undefined;
|
|
240
240
|
};
|
|
241
241
|
}>>, {
|
|
@@ -256,7 +256,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
256
256
|
extensions: Extension[];
|
|
257
257
|
phrases: Record<string, string>;
|
|
258
258
|
lang: LanguageSupport;
|
|
259
|
-
linter:
|
|
259
|
+
linter: LintSource;
|
|
260
260
|
}>;
|
|
261
261
|
export default _default;
|
|
262
262
|
//# 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,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeMirror.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AAWjE,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtE,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;AAE3C,2BAA2B;;IAWvB,kBAAkB;;;;;IAKlB;;;;OAIG;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;;IA9GH,kBAAkB;;;;;IAKlB;;;;OAIG;;;oBAG6B,MAAM;;;;;IAItC;;;;OAIG;;;;;;;IAOH,gBAAgB;;;;;IAKhB;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAOH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;IAKH;;;;OAIG;;;;;;;;gBAlG6B,MAAM;;;;;;;;;;;;;;;;;AAtB1C,wBA+QG"}
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isVue2, h as h$1, defineComponent, ref, toRefs, computed, toRaw, watch, onMounted, nextTick, onUnmounted } from "vue-demi";
|
|
2
2
|
import { EditorState } from "@codemirror/state";
|
|
3
3
|
import { EditorView, keymap } from "@codemirror/view";
|
|
4
|
+
import { linter, lintGutter } from "@codemirror/lint";
|
|
4
5
|
import { basicSetup } from "@codemirror/basic-setup";
|
|
5
6
|
import { indentWithTab } from "@codemirror/commands";
|
|
6
7
|
import { merge, compact, trim } from "lodash";
|
|
@@ -86,7 +87,7 @@ var CodeMirror = defineComponent({
|
|
|
86
87
|
default: () => void 0
|
|
87
88
|
},
|
|
88
89
|
linter: {
|
|
89
|
-
type:
|
|
90
|
+
type: Object,
|
|
90
91
|
default: () => void 0
|
|
91
92
|
}
|
|
92
93
|
},
|
|
@@ -106,11 +107,10 @@ var CodeMirror = defineComponent({
|
|
|
106
107
|
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
107
108
|
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
108
109
|
props.editable ? EditorView.editable.of(props.editable) : void 0,
|
|
109
|
-
props.lang ? toRaw(props.lang) : void 0
|
|
110
|
+
props.lang ? toRaw(props.lang) : void 0,
|
|
111
|
+
props.linter ? linter(props.linter) : void 0,
|
|
112
|
+
props.linter ? lintGutter() : void 0
|
|
110
113
|
];
|
|
111
|
-
if (props.linter) {
|
|
112
|
-
merge(ext, props.linter);
|
|
113
|
-
}
|
|
114
114
|
if (props.extensions) {
|
|
115
115
|
merge(ext, props.extensions);
|
|
116
116
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/basic-setup"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/basic-setup","@codemirror/commands","lodash"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.CodeMirror={},r.VueDemi,r.state,r.view,r.basicSetup,r.commands,r.lodash))})(this,function(r,t,l,
|
|
1
|
+
(function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("@codemirror/basic-setup"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","@codemirror/basic-setup","@codemirror/commands","lodash"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.basicSetup,r.commands,r.lodash))})(this,function(r,t,s,l,h,b,V,m){"use strict";const w=e=>e?Object.entries(e).reduce((a,[o,i])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...a,[o]:i}),{}):null,v=(e,a={},o)=>{if(t.isVue2)return t.h(e,a,o);const{props:i,domProps:f,on:u,...c}=a,n=u?w(u):{},d={...c,...i,...f,...n};return t.h(e,d,o)},x=e=>typeof e=="function"?e():e;var y=t.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},selection:{type:Object,default:()=>{}},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Object,default:()=>{}}},emits:["update:modelValue","update"],setup(e,a){const o=t.ref(),i=t.ref(e.modelValue),{dark:f}=t.toRefs(e),u=a.emit,c=t.computed(()=>{const d=[e.basic?b.basicSetup:void 0,l.EditorView.updateListener.of(p=>u("update",p)),l.EditorView.theme(e.theme,{dark:f.value}),e.wrap?l.EditorView.lineWrapping:void 0,e.tab?l.keymap.of([V.indentWithTab]):void 0,e.phrases?s.EditorState.phrases.of(e.phrases):void 0,e.readonly?s.EditorState.readOnly.of(e.readonly):void 0,e.editable?l.EditorView.editable.of(e.editable):void 0,e.lang?t.toRaw(e.lang):void 0,e.linter?h.linter(e.linter):void 0,e.linter?h.lintGutter():void 0];return e.extensions&&m.merge(d,e.extensions),m.compact(d)});let n;return t.watch(i,d=>{if(n.composing)return;const p=n.state.selection;n.setState(s.EditorState.create({doc:d,extensions:c.value,selection:p}))}),t.watch(f,()=>{n.setState(s.EditorState.create({doc:i.value,extensions:c.value}))}),t.onMounted(async()=>{i.value==""&&o.value&&(i.value=m.trim(o.value.childNodes[0].innerText)),n=new l.EditorView({state:s.EditorState.create({doc:i.value,selection:e.selection,extensions:c.value}),parent:o.value,dispatch:d=>{n.update([d]),!d.changes.empty&&(i.value=n.state.doc.toString(),u("update:modelValue",i.value))}}),await t.nextTick()}),t.onUnmounted(()=>n.destroy()),{context:a,editor:o}},render(){return v("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?v("aside",{style:"display: none;"},x(this.$slots.default)):void 0)}});/**
|
|
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
|
-
*/const
|
|
8
|
+
*/const S=e=>e.component("CodeMirror",y);r.default=y,r.install=S,Object.defineProperties(r,{__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.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "CodeMirror6 Component for vue2 and vue3",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
@@ -65,14 +65,15 @@
|
|
|
65
65
|
"lint": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
|
|
66
66
|
"lint:markup": "vue-tsc --noEmit",
|
|
67
67
|
"preview": "vite preview --config vite.config.docs.ts",
|
|
68
|
-
"prepare": "husky install"
|
|
69
|
-
"postinstall": "npx vue-demi-fix"
|
|
68
|
+
"prepare": "husky install"
|
|
70
69
|
},
|
|
71
70
|
"dependencies": {
|
|
72
|
-
"@codemirror/basic-setup": "
|
|
73
|
-
"@codemirror/
|
|
74
|
-
"@codemirror/
|
|
75
|
-
"
|
|
71
|
+
"@codemirror/basic-setup": "latest",
|
|
72
|
+
"@codemirror/commands": "latest",
|
|
73
|
+
"@codemirror/lint": "latest",
|
|
74
|
+
"@codemirror/state": "latest",
|
|
75
|
+
"@codemirror/view": "latest",
|
|
76
|
+
"vue-demi": "latest"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
|
78
79
|
"@vue/composition-api": "^1.6.2",
|
|
@@ -84,9 +85,10 @@
|
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
87
|
"devDependencies": {
|
|
88
|
+
"@codemirror/lang-javascript": "^0.20.0",
|
|
87
89
|
"@codemirror/lang-markdown": "^0.20.1",
|
|
88
90
|
"@types/lodash": "^4.14.182",
|
|
89
|
-
"@types/node": "^17.0.
|
|
91
|
+
"@types/node": "^17.0.36",
|
|
90
92
|
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
91
93
|
"@typescript-eslint/parser": "^5.26.0",
|
|
92
94
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
@@ -101,6 +103,7 @@
|
|
|
101
103
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
102
104
|
"eslint-plugin-vue": "^9.0.1",
|
|
103
105
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
106
|
+
"eslint4b-prebuilt": "^6.7.2",
|
|
104
107
|
"husky": "^8.0.1",
|
|
105
108
|
"lint-staged": "^12.4.2",
|
|
106
109
|
"lodash": "^4.17.21",
|
|
@@ -115,7 +118,7 @@
|
|
|
115
118
|
"vite-plugin-checker": "^0.4.6",
|
|
116
119
|
"vue": "^3.2.36",
|
|
117
120
|
"vue-eslint-parser": "^9.0.2",
|
|
118
|
-
"vue-tsc": "^0.34.
|
|
121
|
+
"vue-tsc": "^0.34.17"
|
|
119
122
|
},
|
|
120
123
|
"husky": {
|
|
121
124
|
"hooks": {
|