vue-codemirror6 0.3.3 → 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 +32 -0
- package/dist/components/CodeMirror.vue.d.ts +3 -3
- package/dist/components/CodeMirror.vue.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/vue-codemirror6.es.js +11 -10
- package/dist/vue-codemirror6.umd.js +2 -2
- package/package.json +21 -16
- package/src/components/CodeMirror.vue +27 -18
package/README.md
CHANGED
|
@@ -214,6 +214,38 @@ export default defineComponent({
|
|
|
214
214
|
</script>
|
|
215
215
|
```
|
|
216
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
|
+
|
|
217
249
|
## LICENSE
|
|
218
250
|
|
|
219
251
|
[MIT](LICENSE)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
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:
|
|
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:
|
|
100
|
+
default: () => void;
|
|
101
101
|
};
|
|
102
102
|
/** Dark Mode */
|
|
103
103
|
dark: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"
|
|
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,7 @@
|
|
|
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
13
|
export default CodeMirror;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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:
|
|
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
|
-
|
|
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(
|
|
93
|
+
watch(extensions, async (value) => {
|
|
95
94
|
view.setState(EditorState.create({
|
|
96
95
|
doc: modelValue.value,
|
|
97
|
-
extensions:
|
|
96
|
+
extensions: value
|
|
98
97
|
}));
|
|
99
|
-
|
|
100
|
-
|
|
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 {
|
|
@@ -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,
|
|
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
|
|
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.
|
|
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",
|
|
@@ -57,11 +58,14 @@
|
|
|
57
58
|
"dev": "vite",
|
|
58
59
|
"clean": "rimraf node_modules/.vite",
|
|
59
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 .
|
|
64
|
+
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . -w -u",
|
|
62
65
|
"lint:markup": "vue-tsc --noEmit",
|
|
63
66
|
"switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
|
|
64
67
|
"switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
|
|
68
|
+
"preview": "vite preview --config vite.config.docs.ts",
|
|
65
69
|
"prepare": "husky install",
|
|
66
70
|
"postinstall": "npx vue-demi-fix"
|
|
67
71
|
},
|
|
@@ -83,15 +87,15 @@
|
|
|
83
87
|
"@codemirror/basic-setup": "^0.20.0",
|
|
84
88
|
"@codemirror/lang-markdown": "^0.20.0",
|
|
85
89
|
"@codemirror/language": "^0.20.0",
|
|
86
|
-
"@codemirror/lint": "^0.20.
|
|
87
|
-
"@modyqyw/vite-plugin-eslint": "^1.3.
|
|
90
|
+
"@codemirror/lint": "^0.20.2",
|
|
91
|
+
"@modyqyw/vite-plugin-eslint": "^1.3.2",
|
|
88
92
|
"@types/lodash": "^4.14.182",
|
|
89
|
-
"@types/node": "^17.0.
|
|
90
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
91
|
-
"@typescript-eslint/parser": "^5.
|
|
92
|
-
"@vitejs/plugin-vue": "^2.3.
|
|
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",
|
|
93
97
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
94
|
-
"eslint": "^8.
|
|
98
|
+
"eslint": "^8.15.0",
|
|
95
99
|
"eslint-config-google": "^0.14.0",
|
|
96
100
|
"eslint-config-prettier": "^8.5.0",
|
|
97
101
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
@@ -102,20 +106,21 @@
|
|
|
102
106
|
"eslint-plugin-tsdoc": "^0.2.16",
|
|
103
107
|
"eslint-plugin-vue": "^8.7.1",
|
|
104
108
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
105
|
-
"husky": "^
|
|
106
|
-
"lint-staged": "^12.4.
|
|
109
|
+
"husky": "^8.0.1",
|
|
110
|
+
"lint-staged": "^12.4.1",
|
|
107
111
|
"lodash": "^4.17.21",
|
|
108
112
|
"prettier": "^2.6.2",
|
|
109
113
|
"prettier-plugin-jsdoc": "^0.3.38",
|
|
110
114
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
111
115
|
"prettier-plugin-sort-imports": "^1.6.0",
|
|
112
116
|
"rimraf": "^3.0.2",
|
|
113
|
-
"
|
|
114
|
-
"
|
|
117
|
+
"rollup-plugin-visualizer": "^5.6.0",
|
|
118
|
+
"typescript": "^4.6.4",
|
|
119
|
+
"vite": "^2.9.9",
|
|
115
120
|
"vue": "^3.2.33",
|
|
116
|
-
"vue-eslint-parser": "^
|
|
121
|
+
"vue-eslint-parser": "^9.0.1",
|
|
117
122
|
"vue-template-compiler": "^2.6.14",
|
|
118
|
-
"vue-tsc": "^0.34.
|
|
123
|
+
"vue-tsc": "^0.34.13"
|
|
119
124
|
},
|
|
120
125
|
"husky": {
|
|
121
126
|
"hooks": {
|
|
@@ -12,13 +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
25
|
import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
|
|
23
26
|
|
|
24
27
|
import type { Extension, Transaction } from '@codemirror/state';
|
|
@@ -50,7 +53,7 @@ export default defineComponent({
|
|
|
50
53
|
*/
|
|
51
54
|
theme: {
|
|
52
55
|
type: Object as PropType<{ [selector: string]: StyleSpec }>,
|
|
53
|
-
default:
|
|
56
|
+
default: () => {},
|
|
54
57
|
},
|
|
55
58
|
/** Dark Mode */
|
|
56
59
|
dark: {
|
|
@@ -121,7 +124,7 @@ export default defineComponent({
|
|
|
121
124
|
*/
|
|
122
125
|
setup(props, context: SetupContext) {
|
|
123
126
|
/** Editor DOM */
|
|
124
|
-
const editor: Ref<Element | undefined> = ref
|
|
127
|
+
const editor: Ref<Element | undefined> = ref();
|
|
125
128
|
|
|
126
129
|
/** Model */
|
|
127
130
|
const modelValue: Ref<string> = ref(props.modelValue);
|
|
@@ -137,11 +140,11 @@ export default defineComponent({
|
|
|
137
140
|
/** Default extension */
|
|
138
141
|
const ext = [
|
|
139
142
|
// ViewUpdate event listener
|
|
140
|
-
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
141
|
-
emit('update', update)
|
|
142
|
-
|
|
143
|
+
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
144
|
+
emit('update', update)
|
|
145
|
+
),
|
|
143
146
|
// Toggle light/dark mode.
|
|
144
|
-
EditorView.theme(props.theme
|
|
147
|
+
EditorView.theme(props.theme, { dark: dark.value }),
|
|
145
148
|
// locale settings
|
|
146
149
|
props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
|
|
147
150
|
// Parser language setting
|
|
@@ -191,18 +194,23 @@ export default defineComponent({
|
|
|
191
194
|
);
|
|
192
195
|
});
|
|
193
196
|
|
|
194
|
-
/**
|
|
195
|
-
watch(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
+
);
|
|
203
211
|
|
|
204
212
|
/** When loaded */
|
|
205
|
-
onMounted(() => {
|
|
213
|
+
onMounted(async () => {
|
|
206
214
|
/** Initial Value */
|
|
207
215
|
const value =
|
|
208
216
|
!modelValue.value && editor.value
|
|
@@ -225,6 +233,7 @@ export default defineComponent({
|
|
|
225
233
|
emit('update:modelValue', modelValue.value);
|
|
226
234
|
},
|
|
227
235
|
});
|
|
236
|
+
await nextTick();
|
|
228
237
|
});
|
|
229
238
|
|
|
230
239
|
/** Destroy */
|