vue-codemirror6 0.1.0 → 0.1.4
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 +91 -96
- package/dist/components/CodeMirror.vue.d.ts +102 -38
- package/dist/components/CodeMirror.vue.d.ts.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts +9 -0
- package/dist/interfaces/CodeMirrorEmitsInterface.d.ts.map +1 -0
- package/dist/vue-codemirror6.es.js +135 -127
- package/dist/vue-codemirror6.umd.js +8 -3
- package/package.json +43 -31
- package/src/components/CodeMirror.vue +221 -185
- package/dist/index.esm.d.ts +0 -6
- package/dist/index.esm.d.ts.map +0 -1
|
@@ -1,122 +1,133 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineComponent, ref, computed, watch, onMounted, onUnmounted, install } from "vue-demi";
|
|
2
2
|
import { EditorState } from "@codemirror/state";
|
|
3
3
|
import { EditorView } from "@codemirror/view";
|
|
4
|
-
import {
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
merge(ext, this.extensions);
|
|
4
|
+
import { merge, compact } from "lodash";
|
|
5
|
+
var __vue2_script = defineComponent({
|
|
6
|
+
name: "CodeMirror",
|
|
7
|
+
model: {
|
|
8
|
+
prop: "modelValue",
|
|
9
|
+
event: "update:modelValue"
|
|
10
|
+
},
|
|
11
|
+
props: {
|
|
12
|
+
modelValue: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: ""
|
|
15
|
+
},
|
|
16
|
+
theme: {
|
|
17
|
+
type: Object,
|
|
18
|
+
default: void 0
|
|
19
|
+
},
|
|
20
|
+
dark: {
|
|
21
|
+
type: Boolean,
|
|
22
|
+
default: false
|
|
23
|
+
},
|
|
24
|
+
readonly: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false
|
|
27
|
+
},
|
|
28
|
+
editable: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: true
|
|
31
|
+
},
|
|
32
|
+
extensions: {
|
|
33
|
+
type: Array,
|
|
34
|
+
default: void 0
|
|
35
|
+
},
|
|
36
|
+
phrases: {
|
|
37
|
+
type: Object,
|
|
38
|
+
default: void 0
|
|
39
|
+
},
|
|
40
|
+
lang: {
|
|
41
|
+
type: Object,
|
|
42
|
+
default: void 0
|
|
43
|
+
},
|
|
44
|
+
linter: {
|
|
45
|
+
type: Array,
|
|
46
|
+
default: void 0
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
},
|
|
49
|
+
emits: ["update:modelValue", "update"],
|
|
50
|
+
setup(props, context) {
|
|
51
|
+
const editor = ref();
|
|
52
|
+
const modelValue = ref(props.modelValue);
|
|
53
|
+
const dark = ref(props.dark);
|
|
54
|
+
const emit = context.emit;
|
|
55
|
+
const extensions = computed(() => {
|
|
56
|
+
const ext = [
|
|
57
|
+
EditorView.updateListener.of((update) => {
|
|
58
|
+
emit("update", update);
|
|
59
|
+
}),
|
|
60
|
+
EditorView.theme(props.theme || {}, { dark: dark.value }),
|
|
61
|
+
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
62
|
+
props.lang,
|
|
63
|
+
props.readonly ? EditorState.readOnly.of(props.readonly) : void 0,
|
|
64
|
+
props.editable ? EditorView.editable.of(props.editable) : void 0
|
|
65
|
+
];
|
|
66
|
+
if (props.linter) {
|
|
67
|
+
merge(ext, props.linter);
|
|
68
|
+
}
|
|
69
|
+
if (props.extensions) {
|
|
70
|
+
merge(ext, props.extensions);
|
|
68
71
|
}
|
|
72
|
+
return compact(ext);
|
|
69
73
|
});
|
|
74
|
+
let view;
|
|
75
|
+
watch(modelValue, (current) => {
|
|
76
|
+
if (view.composing) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const previous = view.state.selection;
|
|
80
|
+
view.setState(EditorState.create({
|
|
81
|
+
doc: current,
|
|
82
|
+
extensions: extensions.value,
|
|
83
|
+
selection: previous
|
|
84
|
+
}));
|
|
85
|
+
});
|
|
86
|
+
watch(dark, () => {
|
|
87
|
+
view.setState(EditorState.create({
|
|
88
|
+
doc: modelValue.value,
|
|
89
|
+
extensions: extensions.value
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
onMounted(() => {
|
|
93
|
+
const value = !modelValue.value && editor.value ? editor.value.childNodes[0].innerText : modelValue.value;
|
|
94
|
+
view = new EditorView({
|
|
95
|
+
state: EditorState.create({
|
|
96
|
+
doc: value,
|
|
97
|
+
extensions: extensions.value
|
|
98
|
+
}),
|
|
99
|
+
parent: editor.value,
|
|
100
|
+
dispatch: (tr) => {
|
|
101
|
+
view.update([tr]);
|
|
102
|
+
if (tr.changes.empty)
|
|
103
|
+
return;
|
|
104
|
+
modelValue.value = view.state.doc.toString();
|
|
105
|
+
emit("update:modelValue", modelValue.value);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
onUnmounted(() => view.destroy());
|
|
110
|
+
return {
|
|
111
|
+
context,
|
|
112
|
+
editor
|
|
113
|
+
};
|
|
70
114
|
}
|
|
71
|
-
|
|
72
|
-
this.editor.destroy();
|
|
73
|
-
}
|
|
74
|
-
getChildrenTextContent(children) {
|
|
75
|
-
return children.map((node) => node.children ? this.getChildrenTextContent(node.children) : node.text || "\n").join("");
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
__decorateClass([
|
|
79
|
-
Prop({ type: Object, default: () => {
|
|
80
|
-
} })
|
|
81
|
-
], CodeMirror.prototype, "theme", 2);
|
|
82
|
-
__decorateClass([
|
|
83
|
-
Prop({ type: Boolean, default: false })
|
|
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);
|
|
91
|
-
__decorateClass([
|
|
92
|
-
Prop({ type: Object })
|
|
93
|
-
], CodeMirror.prototype, "phrases", 2);
|
|
94
|
-
__decorateClass([
|
|
95
|
-
Prop({ type: Array, default: () => [] })
|
|
96
|
-
], CodeMirror.prototype, "extensions", 2);
|
|
97
|
-
__decorateClass([
|
|
98
|
-
Prop({ type: Object })
|
|
99
|
-
], CodeMirror.prototype, "lang", 2);
|
|
100
|
-
__decorateClass([
|
|
101
|
-
Prop({ type: Array, default: () => [] })
|
|
102
|
-
], CodeMirror.prototype, "linter", 2);
|
|
103
|
-
__decorateClass([
|
|
104
|
-
Prop({ type: String, default: "" })
|
|
105
|
-
], CodeMirror.prototype, "value", 2);
|
|
106
|
-
__decorateClass([
|
|
107
|
-
Watch("value")
|
|
108
|
-
], CodeMirror.prototype, "onValueChanged", 1);
|
|
109
|
-
__decorateClass([
|
|
110
|
-
Watch("dark")
|
|
111
|
-
], CodeMirror.prototype, "onToggleDarkMode", 1);
|
|
112
|
-
CodeMirror = __decorateClass([
|
|
113
|
-
Component({ name: "CodeMirror" })
|
|
114
|
-
], CodeMirror);
|
|
115
|
+
});
|
|
115
116
|
var render = function() {
|
|
116
117
|
var _vm = this;
|
|
117
118
|
var _h = _vm.$createElement;
|
|
118
119
|
var _c = _vm._self._c || _h;
|
|
119
|
-
return _c("
|
|
120
|
+
return _c("div", {
|
|
121
|
+
ref: "editor",
|
|
122
|
+
staticClass: "vue-codemirror"
|
|
123
|
+
}, [_c("aside", {
|
|
124
|
+
directives: [{
|
|
125
|
+
name: "show",
|
|
126
|
+
rawName: "v-show",
|
|
127
|
+
value: !_vm.context.slots.default,
|
|
128
|
+
expression: "!context.slots.default"
|
|
129
|
+
}]
|
|
130
|
+
}, [_vm._t("default")], 2)]);
|
|
120
131
|
};
|
|
121
132
|
var staticRenderFns = [];
|
|
122
133
|
function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
|
|
@@ -171,28 +182,25 @@ function normalizeComponent(scriptExports, render2, staticRenderFns2, functional
|
|
|
171
182
|
};
|
|
172
183
|
}
|
|
173
184
|
const __cssModules = {};
|
|
174
|
-
var __component__ = /* @__PURE__ */ normalizeComponent(
|
|
185
|
+
var __component__ = /* @__PURE__ */ normalizeComponent(__vue2_script, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
|
|
175
186
|
function __vue2_injectStyles(context) {
|
|
176
187
|
for (let o in __cssModules) {
|
|
177
188
|
this[o] = __cssModules[o];
|
|
178
189
|
}
|
|
179
190
|
}
|
|
180
|
-
var
|
|
191
|
+
var CodeMirror = /* @__PURE__ */ function() {
|
|
181
192
|
return __component__.exports;
|
|
182
193
|
}();
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
component[exportName] = exported;
|
|
197
|
-
});
|
|
198
|
-
export { component as default };
|
|
194
|
+
/**
|
|
195
|
+
* Vue CodeMirror6 Component
|
|
196
|
+
*
|
|
197
|
+
* @license MIT
|
|
198
|
+
* @author Logue {@link logue@hotmail.co.jp}
|
|
199
|
+
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
200
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
201
|
+
*/
|
|
202
|
+
install();
|
|
203
|
+
const installCodeMirror = (app) => {
|
|
204
|
+
app.component("CodeMirror", CodeMirror);
|
|
205
|
+
};
|
|
206
|
+
export { CodeMirror, CodeMirror as default, installCodeMirror as install };
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lodash))})(this,function(r,n,c,_,m){"use strict";var S=n.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,i){const d=n.ref(),s=n.ref(e.modelValue),u=n.ref(e.dark),v=i.emit,f=n.computed(()=>{const t=[_.EditorView.updateListener.of(o=>{v("update",o)}),_.EditorView.theme(e.theme||{},{dark:u.value}),e.phrases?c.EditorState.phrases.of(e.phrases):void 0,e.lang,e.readonly?c.EditorState.readOnly.of(e.readonly):void 0,e.editable?_.EditorView.editable.of(e.editable):void 0];return e.linter&&m.merge(t,e.linter),e.extensions&&m.merge(t,e.extensions),m.compact(t)});let a;return n.watch(s,t=>{if(a.composing)return;const o=a.state.selection;a.setState(c.EditorState.create({doc:t,extensions:f.value,selection:o}))}),n.watch(u,()=>{a.setState(c.EditorState.create({doc:s.value,extensions:f.value}))}),n.onMounted(()=>{const t=!s.value&&d.value?d.value.childNodes[0].innerText:s.value;a=new _.EditorView({state:c.EditorState.create({doc:t,extensions:f.value}),parent:d.value,dispatch:o=>{a.update([o]),!o.changes.empty&&(s.value=a.state.doc.toString(),v("update:modelValue",s.value))}})}),n.onUnmounted(()=>a.destroy()),{context:i,editor:d}}}),V=function(){var e=this,i=e.$createElement,d=e._self._c||i;return d("div",{ref:"editor",staticClass:"vue-codemirror"},[d("aside",{directives:[{name:"show",rawName:"v-show",value:!e.context.slots.default,expression:"!context.slots.default"}]},[e._t("default")],2)])},w=[];function E(e,i,d,s,u,v,f,a){var t=typeof e=="function"?e.options:e;i&&(t.render=i,t.staticRenderFns=d,t._compiled=!0),s&&(t.functional=!0),v&&(t._scopeId="data-v-"+v);var o;if(f?(o=function(l){l=l||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!l&&typeof __VUE_SSR_CONTEXT__<"u"&&(l=__VUE_SSR_CONTEXT__),u&&u.call(this,l),l&&l._registeredComponents&&l._registeredComponents.add(f)},t._ssrRegister=o):u&&(o=a?function(){u.call(this,(t.functional?this.parent:this).$root.$options.shadowRoot)}:u),o)if(t.functional){t._injectStyles=o;var T=t.render;t.render=function($,C){return o.call(C),T($,C)}}else{var y=t.beforeCreate;t.beforeCreate=y?[].concat(y,o):[o]}return{exports:e,options:t}}const p={};var M=E(S,V,w,!1,b,null,null,null);function b(e){for(let i in p)this[i]=p[i]}var h=function(){return M.exports}();/**
|
|
2
|
+
* Vue CodeMirror6 Component
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @author Logue {@link logue@hotmail.co.jp}
|
|
6
|
+
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
|
+
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
|
+
*/n.install();const g=e=>{e.component("CodeMirror",h)};r.CodeMirror=h,r.default=h,r.install=g,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.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "CodeMirror6 Component for vue2",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
@@ -54,56 +54,68 @@
|
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"scripts": {
|
|
56
56
|
"dev": "vite",
|
|
57
|
-
"
|
|
57
|
+
"clean": "rimraf node_modules/.vite",
|
|
58
|
+
"build": "vite build & vue-tsc --declaration --emitDeclarationOnly",
|
|
58
59
|
"build:clean": "rimraf dist",
|
|
59
60
|
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
60
61
|
"lint:markup": "vue-tsc --noEmit",
|
|
61
|
-
"
|
|
62
|
+
"switch:2": "vue-demi-switch 2 & npx vue-demi-fix",
|
|
63
|
+
"switch:3": "vue-demi-switch 3 vue3 & npx vue-demi-fix",
|
|
64
|
+
"prepare": "husky install",
|
|
65
|
+
"postinstall": "npx vue-demi-fix"
|
|
62
66
|
},
|
|
63
67
|
"dependencies": {
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"@codemirror/
|
|
68
|
-
"@codemirror/view": "
|
|
69
|
-
"
|
|
70
|
-
"vue": "^2.6.14"
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
"vue-demi": "latest"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@codemirror/state": "latest",
|
|
72
|
+
"@codemirror/view": "latest",
|
|
73
|
+
"@vue/composition-api": "latest",
|
|
74
|
+
"vue": "^2.6.14 || ^3.2.33"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"@vue/composition-api": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
73
80
|
},
|
|
74
81
|
"devDependencies": {
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@
|
|
82
|
+
"@codemirror/basic-setup": "^0.20.0",
|
|
83
|
+
"@codemirror/lang-markdown": "^0.20.0",
|
|
84
|
+
"@codemirror/language": "^0.20.0",
|
|
85
|
+
"@codemirror/lint": "^0.20.1",
|
|
86
|
+
"@modyqyw/vite-plugin-eslint": "^1.3.0",
|
|
87
|
+
"@types/lodash": "^4.14.182",
|
|
88
|
+
"@types/node": "^17.0.27",
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
|
90
|
+
"@typescript-eslint/parser": "^5.21.0",
|
|
91
|
+
"@vue/composition-api": "^1.5.0",
|
|
80
92
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
81
|
-
"eslint": "^8.
|
|
93
|
+
"eslint": "^8.14.0",
|
|
82
94
|
"eslint-config-google": "^0.14.0",
|
|
83
95
|
"eslint-config-prettier": "^8.5.0",
|
|
84
96
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
85
|
-
"eslint-import-resolver-typescript": "^2.
|
|
86
|
-
"eslint-plugin-import": "^2.
|
|
97
|
+
"eslint-import-resolver-typescript": "^2.7.1",
|
|
98
|
+
"eslint-plugin-import": "^2.26.0",
|
|
87
99
|
"eslint-plugin-prettier": "^4.0.0",
|
|
88
100
|
"eslint-plugin-prettier-vue": "^3.1.0",
|
|
89
|
-
"eslint-plugin-tsdoc": "^0.2.
|
|
90
|
-
"eslint-plugin-vue": "^8.
|
|
101
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
102
|
+
"eslint-plugin-vue": "^8.7.1",
|
|
91
103
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
92
104
|
"husky": "^7.0.4",
|
|
93
|
-
"lint-staged": "^12.
|
|
94
|
-
"
|
|
95
|
-
"prettier
|
|
105
|
+
"lint-staged": "^12.4.0",
|
|
106
|
+
"lodash": "^4.17.21",
|
|
107
|
+
"prettier": "^2.6.2",
|
|
108
|
+
"prettier-plugin-jsdoc": "^0.3.38",
|
|
96
109
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
97
110
|
"prettier-plugin-sort-imports": "^1.6.0",
|
|
98
111
|
"rimraf": "^3.0.2",
|
|
99
|
-
"typescript": "
|
|
100
|
-
"vite": "^2.
|
|
101
|
-
"vite-
|
|
102
|
-
"
|
|
103
|
-
"vite-plugin-vue2": "^1.9.3",
|
|
112
|
+
"typescript": "^4.6.3",
|
|
113
|
+
"vite": "^2.9.5",
|
|
114
|
+
"vite-plugin-vue2": "^2.0.0",
|
|
115
|
+
"vue": "^2.6.14",
|
|
104
116
|
"vue-eslint-parser": "^8.3.0",
|
|
105
117
|
"vue-template-compiler": "^2.6.14",
|
|
106
|
-
"vue-tsc": "^0.
|
|
118
|
+
"vue-tsc": "^0.34.10"
|
|
107
119
|
},
|
|
108
120
|
"husky": {
|
|
109
121
|
"hooks": {
|