vue-codemirror6 0.3.7 → 0.5.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 +9 -2
- package/dist/components/{CodeMirror.vue.d.ts → CodeMirror.d.ts} +2 -2
- package/dist/components/CodeMirror.d.ts.map +1 -0
- package/dist/helpers/h-demi.d.ts +14 -0
- package/dist/helpers/h-demi.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/{vue-codemirror6.es.js → index.es.js} +30 -24
- package/dist/index.umd.js +8 -0
- package/package.json +13 -11
- package/dist/components/CodeMirror.vue.d.ts.map +0 -1
- package/dist/vue-codemirror6.umd.js +0 -8
- package/src/components/CodeMirror.vue +0 -297
package/README.md
CHANGED
|
@@ -8,13 +8,20 @@
|
|
|
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
|
-
|
|
13
11
|
## Usage
|
|
14
12
|
|
|
13
|
+
```sh
|
|
14
|
+
yarn add vue-codemirror6
|
|
15
|
+
```
|
|
16
|
+
|
|
15
17
|
This component can handle bidirectional binding by `v-model` like a general Vue component.
|
|
18
|
+
|
|
16
19
|
When using with Vue2, [@vue/composition-api](https://www.npmjs.com/package/@vue/composition-api) is required separately.
|
|
17
20
|
|
|
21
|
+
```sh
|
|
22
|
+
yarn add vue-codemirror6 @vue/composition-api
|
|
23
|
+
```
|
|
24
|
+
|
|
18
25
|
### Props
|
|
19
26
|
|
|
20
27
|
| Props | Type | Information |
|
|
@@ -239,7 +239,6 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
239
239
|
default: () => undefined;
|
|
240
240
|
};
|
|
241
241
|
}>>, {
|
|
242
|
-
readonly: boolean;
|
|
243
242
|
modelValue: string | Text;
|
|
244
243
|
selection: EditorSelection | {
|
|
245
244
|
anchor: number;
|
|
@@ -252,6 +251,7 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
252
251
|
basic: boolean;
|
|
253
252
|
wrap: boolean;
|
|
254
253
|
tab: boolean;
|
|
254
|
+
readonly: boolean;
|
|
255
255
|
editable: boolean;
|
|
256
256
|
extensions: Extension[];
|
|
257
257
|
phrases: Record<string, string>;
|
|
@@ -259,4 +259,4 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
259
259
|
linter: Diagnostic[];
|
|
260
260
|
}>;
|
|
261
261
|
export default _default;
|
|
262
|
-
//# sourceMappingURL=CodeMirror.
|
|
262
|
+
//# sourceMappingURL=CodeMirror.d.ts.map
|
|
@@ -0,0 +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;AAUjE,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,wBAiRG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
domProps?: Record<any, any>;
|
|
3
|
+
on?: Record<any, any>;
|
|
4
|
+
props?: Record<any, any>;
|
|
5
|
+
ref?: string;
|
|
6
|
+
class?: string;
|
|
7
|
+
style?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const h: (type: string | Record<any, any>, options?: Options, chidren?: any) => import("vue-demi").VNode<import("vue-demi").RendererNode, import("vue-demi").RendererElement, {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}>;
|
|
12
|
+
declare const slot: (defaultSlots: any) => any;
|
|
13
|
+
export { slot, h as default };
|
|
14
|
+
//# sourceMappingURL=h-demi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"h-demi.d.ts","sourceRoot":"","sources":["../../src/helpers/h-demi.ts"],"names":[],"mappings":"AAEA,UAAU,OAAO;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAWD,QAAA,MAAM,CAAC,SACC,MAAM,GAAG,OAAO,GAAG,EAAE,GAAG,CAAC,YACtB,OAAO,YACN,GAAG;;EASd,CAAC;AAEF,QAAA,MAAM,IAAI,iBAAkB,GAAG,QAG9B,CAAC;AACF,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
7
7
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
8
8
|
*/
|
|
9
|
-
import CodeMirror from './components/CodeMirror
|
|
10
|
-
declare const installCodeMirror:
|
|
9
|
+
import CodeMirror from './components/CodeMirror';
|
|
10
|
+
declare const installCodeMirror: (app: any) => any;
|
|
11
11
|
export { CodeMirror as default, installCodeMirror as install };
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAGjD,QAAA,MAAM,iBAAiB,mBAAiD,CAAC;AAEzE,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import { defineComponent, ref, toRefs, computed, toRaw, watch, onMounted, nextTick, onUnmounted
|
|
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
4
|
import { basicSetup } from "@codemirror/basic-setup";
|
|
5
5
|
import { indentWithTab } from "@codemirror/commands";
|
|
6
6
|
import { merge, compact, trim } from "lodash";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const adaptOnsV3 = (ons) => {
|
|
8
|
+
if (!ons)
|
|
9
|
+
return null;
|
|
10
|
+
return Object.entries(ons).reduce((ret, [key, handler]) => {
|
|
11
|
+
key = key.charAt(0).toUpperCase() + key.slice(1);
|
|
12
|
+
key = `on${key}`;
|
|
13
|
+
return { ...ret, [key]: handler };
|
|
14
|
+
}, {});
|
|
15
|
+
};
|
|
16
|
+
const h = (type, options = {}, chidren) => {
|
|
17
|
+
if (isVue2)
|
|
18
|
+
return h$1(type, options, chidren);
|
|
19
|
+
const { props, domProps, on, ...extraOptions } = options;
|
|
20
|
+
const ons = on ? adaptOnsV3(on) : {};
|
|
21
|
+
const params = { ...extraOptions, ...props, ...domProps, ...ons };
|
|
22
|
+
return h$1(type, params, chidren);
|
|
23
|
+
};
|
|
24
|
+
const slot = (defaultSlots) => {
|
|
25
|
+
if (typeof defaultSlots == "function")
|
|
26
|
+
return defaultSlots();
|
|
27
|
+
return defaultSlots;
|
|
14
28
|
};
|
|
15
|
-
|
|
29
|
+
var CodeMirror = defineComponent({
|
|
16
30
|
name: "CodeMirror",
|
|
17
31
|
model: {
|
|
18
32
|
prop: "modelValue",
|
|
@@ -146,22 +160,14 @@ const _sfc_main = defineComponent({
|
|
|
146
160
|
context,
|
|
147
161
|
editor
|
|
148
162
|
};
|
|
163
|
+
},
|
|
164
|
+
render() {
|
|
165
|
+
return h("div", {
|
|
166
|
+
ref: "editor",
|
|
167
|
+
class: "vue-codemirror"
|
|
168
|
+
}, this.$slots.default ? h("aside", { style: "display: none;" }, slot(this.$slots.default)) : void 0);
|
|
149
169
|
}
|
|
150
170
|
});
|
|
151
|
-
const _hoisted_1 = {
|
|
152
|
-
ref: "editor",
|
|
153
|
-
class: "vue-codemirror"
|
|
154
|
-
};
|
|
155
|
-
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
156
|
-
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
157
|
-
withDirectives(createElementVNode("aside", null, [
|
|
158
|
-
renderSlot(_ctx.$slots, "default")
|
|
159
|
-
], 512), [
|
|
160
|
-
[vShow, !_ctx.context.slots.default]
|
|
161
|
-
])
|
|
162
|
-
], 512);
|
|
163
|
-
}
|
|
164
|
-
var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
165
171
|
/**
|
|
166
172
|
* Vue CodeMirror6 Component
|
|
167
173
|
*
|
|
@@ -170,5 +176,5 @@ var CodeMirror = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]
|
|
|
170
176
|
* @copyright 2022 Masashi Yoshikawa {@link https://logue.dev/} All rights reserved.
|
|
171
177
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
172
178
|
*/
|
|
173
|
-
const installCodeMirror =
|
|
179
|
+
const installCodeMirror = (app) => app.component("CodeMirror", CodeMirror);
|
|
174
180
|
export { CodeMirror as default, installCodeMirror as install };
|
|
@@ -0,0 +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,s,v,b,f){"use strict";const V=e=>e?Object.entries(e).reduce((i,[o,a])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...i,[o]:a}),{}):null,y=(e,i={},o)=>{if(t.isVue2)return t.h(e,i,o);const{props:a,domProps:m,on:u,...c}=i,n=u?V(u):{},d={...c,...a,...m,...n};return t.h(e,d,o)},w=e=>typeof e=="function"?e():e;var h=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:Array,default:()=>{}}},emits:["update:modelValue","update"],setup(e,i){const o=t.ref(),a=t.ref(e.modelValue),{dark:m}=t.toRefs(e),u=i.emit,c=t.computed(()=>{const d=[e.basic?v.basicSetup:void 0,s.EditorView.updateListener.of(p=>u("update",p)),s.EditorView.theme(e.theme,{dark:m.value}),e.wrap?s.EditorView.lineWrapping:void 0,e.tab?s.keymap.of([b.indentWithTab]):void 0,e.phrases?l.EditorState.phrases.of(e.phrases):void 0,e.readonly?l.EditorState.readOnly.of(e.readonly):void 0,e.editable?s.EditorView.editable.of(e.editable):void 0,e.lang?t.toRaw(e.lang):void 0];return e.linter&&f.merge(d,e.linter),e.extensions&&f.merge(d,e.extensions),f.compact(d)});let n;return t.watch(a,d=>{if(n.composing)return;const p=n.state.selection;n.setState(l.EditorState.create({doc:d,extensions:c.value,selection:p}))}),t.watch(m,()=>{n.setState(l.EditorState.create({doc:a.value,extensions:c.value}))}),t.onMounted(async()=>{a.value==""&&o.value&&(a.value=f.trim(o.value.childNodes[0].innerText)),n=new s.EditorView({state:l.EditorState.create({doc:a.value,selection:e.selection,extensions:c.value}),parent:o.value,dispatch:d=>{n.update([d]),!d.changes.empty&&(a.value=n.state.doc.toString(),u("update:modelValue",a.value))}}),await t.nextTick()}),t.onUnmounted(()=>n.destroy()),{context:i,editor:o}},render(){return y("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?y("aside",{style:"display: none;"},w(this.$slots.default)):void 0)}});/**
|
|
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
|
+
*/const x=e=>e.component("CodeMirror",h);r.default=h,r.install=x,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "vue-codemirror6",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "CodeMirror6 Component for vue3",
|
|
4
|
+
"version": "0.5.0",
|
|
5
|
+
"description": "CodeMirror6 Component for vue2 and vue3",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"vuejs",
|
|
8
8
|
"vue",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"vue-codemirror",
|
|
11
11
|
"code-editor",
|
|
12
12
|
"text-editor",
|
|
13
|
+
"vue2",
|
|
13
14
|
"vue3",
|
|
14
15
|
"web-editor",
|
|
15
16
|
"vue-plugin",
|
|
@@ -35,16 +36,17 @@
|
|
|
35
36
|
"node": ">=16.15.0",
|
|
36
37
|
"yarn": ">=1.22.4"
|
|
37
38
|
},
|
|
39
|
+
"packageManager": "yarn@3.2.1",
|
|
38
40
|
"license": "MIT",
|
|
39
|
-
"main": "./dist/
|
|
40
|
-
"module": "./dist/
|
|
41
|
+
"main": "./dist/index.umd.js",
|
|
42
|
+
"module": "./dist/index.es.js",
|
|
41
43
|
"browser": {
|
|
42
44
|
"./sfc": "./src/components/CodeMirror.vue"
|
|
43
45
|
},
|
|
44
46
|
"exports": {
|
|
45
47
|
".": {
|
|
46
|
-
"import": "./dist/
|
|
47
|
-
"require": "./dist/
|
|
48
|
+
"import": "./dist/index.es.js",
|
|
49
|
+
"require": "./dist/index.umd.js"
|
|
48
50
|
}
|
|
49
51
|
},
|
|
50
52
|
"types": "./dist/index.d.ts",
|
|
@@ -67,12 +69,13 @@
|
|
|
67
69
|
"postinstall": "npx vue-demi-fix"
|
|
68
70
|
},
|
|
69
71
|
"dependencies": {
|
|
70
|
-
"
|
|
72
|
+
"@codemirror/basic-setup": "^0.20.0",
|
|
73
|
+
"@codemirror/state": "^0.20.0",
|
|
74
|
+
"@codemirror/view": "^0.20.6",
|
|
75
|
+
"vue-demi": "^0.12.5"
|
|
71
76
|
},
|
|
72
77
|
"peerDependencies": {
|
|
73
|
-
"@
|
|
74
|
-
"@codemirror/state": ">=0.20",
|
|
75
|
-
"@codemirror/view": ">=0.20",
|
|
78
|
+
"@vue/composition-api": "^1.6.2",
|
|
76
79
|
"vue": "^2.6.14 || ^3.2.36"
|
|
77
80
|
},
|
|
78
81
|
"peerDependenciesMeta": {
|
|
@@ -81,7 +84,6 @@
|
|
|
81
84
|
}
|
|
82
85
|
},
|
|
83
86
|
"devDependencies": {
|
|
84
|
-
"@codemirror/basic-setup": "^0.20.0",
|
|
85
87
|
"@codemirror/lang-markdown": "^0.20.1",
|
|
86
88
|
"@types/lodash": "^4.14.182",
|
|
87
89
|
"@types/node": "^17.0.35",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CodeMirror.vue.d.ts","sourceRoot":"","sources":["../../src/components/CodeMirror.vue.ts"],"names":[],"mappings":"AACA,OAAO,EAWL,KAAK,QAAQ,EACb,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAe,MAAM,mBAAmB,CAAC;AASjE,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,wBAgQG"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
(function(o,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"),require("vue")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/basic-setup","@codemirror/commands","lodash","vue"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.CodeMirror={},o.VueDemi,o.state,o.view,o.basicSetup,o.commands,o.lodash,o.Vue))})(this,function(o,t,s,n,h,S,f,l){"use strict";var V=(e,c)=>{const a=e.__vccOpts||e;for(const[r,u]of c)a[r]=u;return a};const b=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:Array,default:()=>{}}},emits:["update:modelValue","update"],setup(e,c){const a=t.ref(),r=t.ref(e.modelValue),{dark:u}=t.toRefs(e),m=c.emit,y=t.computed(()=>{const i=[e.basic?h.basicSetup:void 0,n.EditorView.updateListener.of(p=>m("update",p)),n.EditorView.theme(e.theme,{dark:u.value}),e.wrap?n.EditorView.lineWrapping:void 0,e.tab?n.keymap.of([S.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?n.EditorView.editable.of(e.editable):void 0,e.lang?t.toRaw(e.lang):void 0];return e.linter&&f.merge(i,e.linter),e.extensions&&f.merge(i,e.extensions),f.compact(i)});let d;return t.watch(r,i=>{if(d.composing)return;const p=d.state.selection;d.setState(s.EditorState.create({doc:i,extensions:y.value,selection:p}))}),t.watch(u,()=>{d.setState(s.EditorState.create({doc:r.value,extensions:y.value}))}),t.onMounted(async()=>{r.value==""&&a.value&&(r.value=f.trim(a.value.childNodes[0].innerText)),d=new n.EditorView({state:s.EditorState.create({doc:r.value,selection:e.selection,extensions:y.value}),parent:a.value,dispatch:i=>{d.update([i]),!i.changes.empty&&(r.value=d.state.doc.toString(),m("update:modelValue",r.value))}}),await t.nextTick()}),t.onUnmounted(()=>d.destroy()),{context:c,editor:a}}}),w={ref:"editor",class:"vue-codemirror"};function E(e,c,a,r,u,m){return l.openBlock(),l.createElementBlock("div",w,[l.withDirectives(l.createElementVNode("aside",null,[l.renderSlot(e.$slots,"default")],512),[[l.vShow,!e.context.slots.default]])],512)}var v=V(b,[["render",E]]);/**
|
|
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
|
-
*/const _=t.isVue2?e=>e.component("CodeMirror",v):t.install();o.default=v,o.install=_,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div ref="editor" class="vue-codemirror">
|
|
3
|
-
<aside v-show="!context.slots.default"><slot /></aside>
|
|
4
|
-
</div>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script lang="ts">
|
|
8
|
-
import {
|
|
9
|
-
computed,
|
|
10
|
-
defineComponent,
|
|
11
|
-
nextTick,
|
|
12
|
-
onMounted,
|
|
13
|
-
onUnmounted,
|
|
14
|
-
ref,
|
|
15
|
-
toRaw,
|
|
16
|
-
toRefs,
|
|
17
|
-
watch,
|
|
18
|
-
type ComputedRef,
|
|
19
|
-
type PropType,
|
|
20
|
-
type Ref,
|
|
21
|
-
type SetupContext,
|
|
22
|
-
} from 'vue-demi';
|
|
23
|
-
|
|
24
|
-
import { EditorSelection, EditorState } from '@codemirror/state';
|
|
25
|
-
import { EditorView, keymap } from '@codemirror/view';
|
|
26
|
-
import { basicSetup } from '@codemirror/basic-setup';
|
|
27
|
-
import { indentWithTab } from '@codemirror/commands';
|
|
28
|
-
|
|
29
|
-
import { compact, merge, trim } from 'lodash';
|
|
30
|
-
|
|
31
|
-
import type CodeMirrorEmitsInterface from '@/interfaces/CodeMirrorEmitsInterface';
|
|
32
|
-
|
|
33
|
-
import type { Extension, Text, Transaction } from '@codemirror/state';
|
|
34
|
-
import type { LanguageSupport } from '@codemirror/language';
|
|
35
|
-
import type { ViewUpdate } from '@codemirror/view';
|
|
36
|
-
import type { Diagnostic } from '@codemirror/lint';
|
|
37
|
-
import type { StyleSpec } from 'style-mod';
|
|
38
|
-
|
|
39
|
-
/** CodeMirror Component */
|
|
40
|
-
export default defineComponent({
|
|
41
|
-
/** Component Name */
|
|
42
|
-
name: 'CodeMirror',
|
|
43
|
-
/** Model Definition */
|
|
44
|
-
model: {
|
|
45
|
-
prop: 'modelValue',
|
|
46
|
-
event: 'update:modelValue',
|
|
47
|
-
},
|
|
48
|
-
/** Props Definition */
|
|
49
|
-
props: {
|
|
50
|
-
/** Model value */
|
|
51
|
-
modelValue: {
|
|
52
|
-
type: String as PropType<string | Text>,
|
|
53
|
-
default: '',
|
|
54
|
-
},
|
|
55
|
-
/**
|
|
56
|
-
* Selection
|
|
57
|
-
*
|
|
58
|
-
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorSelection | EditorSelection}
|
|
59
|
-
*/
|
|
60
|
-
selection: {
|
|
61
|
-
type: Object as PropType<
|
|
62
|
-
EditorSelection | { anchor: number; head?: number }
|
|
63
|
-
>,
|
|
64
|
-
default: () => undefined,
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* Theme
|
|
68
|
-
*
|
|
69
|
-
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
70
|
-
*/
|
|
71
|
-
theme: {
|
|
72
|
-
type: Object as PropType<{ [selector: string]: StyleSpec }>,
|
|
73
|
-
default: () => {
|
|
74
|
-
return {};
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
/** Dark Mode */
|
|
78
|
-
dark: {
|
|
79
|
-
type: Boolean,
|
|
80
|
-
default: false,
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Use Basic Setup
|
|
84
|
-
*
|
|
85
|
-
* @see {@link https://codemirror.net/6/docs/ref/#basic-setup | basic-setup}
|
|
86
|
-
*/
|
|
87
|
-
basic: {
|
|
88
|
-
type: Boolean,
|
|
89
|
-
default: false,
|
|
90
|
-
},
|
|
91
|
-
/**
|
|
92
|
-
* Line wrapping
|
|
93
|
-
*
|
|
94
|
-
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5ElineWrapping | LineWrapping}
|
|
95
|
-
*/
|
|
96
|
-
wrap: {
|
|
97
|
-
type: Boolean,
|
|
98
|
-
default: false,
|
|
99
|
-
},
|
|
100
|
-
/**
|
|
101
|
-
* Tab handling
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://codemirror.net/6/examples/tab/ | Tab Handling}
|
|
104
|
-
*/
|
|
105
|
-
tab: {
|
|
106
|
-
type: Boolean,
|
|
107
|
-
default: false,
|
|
108
|
-
},
|
|
109
|
-
/**
|
|
110
|
-
* Readonly
|
|
111
|
-
*
|
|
112
|
-
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
113
|
-
*/
|
|
114
|
-
readonly: {
|
|
115
|
-
type: Boolean,
|
|
116
|
-
default: false,
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* Editable
|
|
120
|
-
*
|
|
121
|
-
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
|
|
122
|
-
*/
|
|
123
|
-
editable: {
|
|
124
|
-
type: Boolean,
|
|
125
|
-
default: true,
|
|
126
|
-
},
|
|
127
|
-
/**
|
|
128
|
-
* Additional Extension
|
|
129
|
-
*
|
|
130
|
-
* @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
131
|
-
*/
|
|
132
|
-
extensions: {
|
|
133
|
-
type: Array as PropType<Extension[]>,
|
|
134
|
-
default: () => {
|
|
135
|
-
return [];
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
/**
|
|
139
|
-
* Language Phreses
|
|
140
|
-
*
|
|
141
|
-
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
142
|
-
*/
|
|
143
|
-
phrases: {
|
|
144
|
-
type: Object as PropType<Record<string, string>>,
|
|
145
|
-
default: () => undefined,
|
|
146
|
-
},
|
|
147
|
-
/**
|
|
148
|
-
* CodeMirror Language
|
|
149
|
-
*
|
|
150
|
-
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
151
|
-
*/
|
|
152
|
-
lang: {
|
|
153
|
-
type: Object as PropType<LanguageSupport>,
|
|
154
|
-
default: () => undefined,
|
|
155
|
-
},
|
|
156
|
-
/**
|
|
157
|
-
* CodeMirror Linter
|
|
158
|
-
*
|
|
159
|
-
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
160
|
-
*/
|
|
161
|
-
linter: {
|
|
162
|
-
type: Array as PropType<Diagnostic[]>,
|
|
163
|
-
default: () => undefined,
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
/** Emits */
|
|
167
|
-
emits: ['update:modelValue', 'update'],
|
|
168
|
-
/**
|
|
169
|
-
* Setup
|
|
170
|
-
*
|
|
171
|
-
* @param props - Props
|
|
172
|
-
* @param context - Context
|
|
173
|
-
*/
|
|
174
|
-
setup(props, context: SetupContext) {
|
|
175
|
-
/** Editor DOM */
|
|
176
|
-
const editor: Ref<Element | undefined> = ref();
|
|
177
|
-
|
|
178
|
-
/** Internal value */
|
|
179
|
-
const doc: Ref<string | Text | undefined> = ref(props.modelValue);
|
|
180
|
-
|
|
181
|
-
/** Dark mode */
|
|
182
|
-
const { dark } = toRefs(props);
|
|
183
|
-
|
|
184
|
-
/** Emits */
|
|
185
|
-
const emit = context.emit as CodeMirrorEmitsInterface;
|
|
186
|
-
|
|
187
|
-
/** CodeMirror Extension */
|
|
188
|
-
const exts: ComputedRef<Extension[]> = computed(() => {
|
|
189
|
-
/** Default extension */
|
|
190
|
-
const ext = [
|
|
191
|
-
// Toggle basic setup
|
|
192
|
-
props.basic ? basicSetup : undefined,
|
|
193
|
-
// ViewUpdate event listener
|
|
194
|
-
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
195
|
-
emit('update', update)
|
|
196
|
-
),
|
|
197
|
-
// Toggle light/dark mode.
|
|
198
|
-
EditorView.theme(props.theme, { dark: dark.value }),
|
|
199
|
-
// Toggle line wrapping
|
|
200
|
-
props.wrap ? EditorView.lineWrapping : undefined,
|
|
201
|
-
// Indent with tab
|
|
202
|
-
props.tab ? keymap.of([indentWithTab]) : undefined,
|
|
203
|
-
// locale settings
|
|
204
|
-
props.phrases ? EditorState.phrases.of(props.phrases) : undefined,
|
|
205
|
-
// Readonly option
|
|
206
|
-
props.readonly ? EditorState.readOnly.of(props.readonly) : undefined,
|
|
207
|
-
// Editable option
|
|
208
|
-
props.editable ? EditorView.editable.of(props.editable) : undefined,
|
|
209
|
-
// Lang
|
|
210
|
-
props.lang ? toRaw(props.lang) : undefined,
|
|
211
|
-
];
|
|
212
|
-
|
|
213
|
-
if (props.linter) {
|
|
214
|
-
// Append Linter settings
|
|
215
|
-
merge(ext, props.linter);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (props.extensions) {
|
|
219
|
-
// Append Extensions (such as basic-setup)
|
|
220
|
-
merge(ext, props.extensions);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// console.debug('[CodeMirror.vue] Loaded extensions:', compact(ext));
|
|
224
|
-
return compact(ext);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
/** CodeMirror Editor View */
|
|
228
|
-
let view: EditorView;
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Input value changed
|
|
232
|
-
*
|
|
233
|
-
* @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
|
|
234
|
-
*/
|
|
235
|
-
watch(doc, current => {
|
|
236
|
-
if (view.composing) {
|
|
237
|
-
// IME fix
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/** Previous cursor location */
|
|
242
|
-
const previous = view.state.selection;
|
|
243
|
-
view.setState(
|
|
244
|
-
EditorState.create({
|
|
245
|
-
doc: current,
|
|
246
|
-
extensions: exts.value,
|
|
247
|
-
selection: previous,
|
|
248
|
-
})
|
|
249
|
-
);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
watch(dark, () => {
|
|
253
|
-
view.setState(
|
|
254
|
-
EditorState.create({
|
|
255
|
-
doc: doc.value,
|
|
256
|
-
extensions: exts.value,
|
|
257
|
-
})
|
|
258
|
-
);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
/** When loaded */
|
|
262
|
-
onMounted(async () => {
|
|
263
|
-
// overwrite initial value
|
|
264
|
-
if (doc.value == '' && editor.value) {
|
|
265
|
-
doc.value = trim((editor.value.childNodes[0] as HTMLElement).innerText);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// Register Codemirror
|
|
269
|
-
view = new EditorView({
|
|
270
|
-
state: EditorState.create({
|
|
271
|
-
doc: doc.value,
|
|
272
|
-
selection: props.selection,
|
|
273
|
-
extensions: exts.value,
|
|
274
|
-
}),
|
|
275
|
-
parent: editor.value,
|
|
276
|
-
dispatch: (tr: Transaction) => {
|
|
277
|
-
view.update([tr]);
|
|
278
|
-
|
|
279
|
-
if (tr.changes.empty) return;
|
|
280
|
-
// to parent binding
|
|
281
|
-
doc.value = view.state.doc.toString();
|
|
282
|
-
emit('update:modelValue', doc.value);
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
await nextTick();
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
/** Destroy */
|
|
289
|
-
onUnmounted(() => view.destroy());
|
|
290
|
-
|
|
291
|
-
return {
|
|
292
|
-
context,
|
|
293
|
-
editor,
|
|
294
|
-
};
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
</script>
|