vue-codemirror6 0.5.5 → 0.6.2
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 +29 -2
- package/dist/index.es.js +39 -34
- package/dist/index.umd.js +2 -2
- package/dist/stats.html +2689 -0
- package/package.json +16 -20
- package/dist/components/CodeMirror.d.ts +0 -270
- package/dist/components/CodeMirror.d.ts.map +0 -1
- package/dist/helpers/h-demi.d.ts +0 -14
- package/dist/helpers/h-demi.d.ts.map +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ yarn add vue-codemirror6 @vue/composition-api
|
|
|
26
26
|
|
|
27
27
|
| Props | Type | Information |
|
|
28
28
|
| ---------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
-
| basic | boolean | Use [
|
|
29
|
+
| basic | boolean | Use [basicSetup](https://codemirror.net/docs/ref/#codemirror.basicSetup). |
|
|
30
|
+
| minimal | boolean | Use [miniSetup](https://codemirror.net/docs/ref/#codemirror.minimalSetup). If a `basic` prop is also specified, that setting will take precedence. |
|
|
30
31
|
| dark | boolean | Toggle Darkmode. It can be changed in real time, but the input value will return to the initial value. |
|
|
31
32
|
| wrap | boolean | Line text wrapping. see [lineWrapping](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping). |
|
|
32
33
|
| tab | boolean | Enables tab indentation. |
|
|
@@ -60,6 +61,7 @@ Notice: `lang` and `linter` can also be set together in `extensions`. This is de
|
|
|
60
61
|
|
|
61
62
|
- [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
|
|
62
63
|
- [`upleveled/theme-vs-code-dark-plus`](https://github.com/upleveled/theme-vs-code-dark-plus)
|
|
64
|
+
- ['codemirror6-bootstrap-theme'](https://github.com/logue/codemirror6-bootstrap-theme)
|
|
63
65
|
|
|
64
66
|
## Example
|
|
65
67
|
|
|
@@ -228,6 +230,28 @@ export default defineComponent({
|
|
|
228
230
|
</script>
|
|
229
231
|
```
|
|
230
232
|
|
|
233
|
+
## Methods
|
|
234
|
+
|
|
235
|
+
| Methods | Description |
|
|
236
|
+
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
237
|
+
| selection() | Get the [EditorSelection](https://codemirror.net/docs/ref/#state.EditorSelection) instance. |
|
|
238
|
+
| getRange(from?: number, to?: number) | Get the text between the given points in the editor. |
|
|
239
|
+
| getLine(number: number) | Get the content of line. |
|
|
240
|
+
| lineCount() | Get the number of lines in the editor. |
|
|
241
|
+
| getCursor() | Retrieve one end of the primary selection. |
|
|
242
|
+
| listSelections() | Retrieves a list of all current selections. |
|
|
243
|
+
| getSelection() | Get the currently selected code. |
|
|
244
|
+
| getSelections() | The length of the given array should be the same as the number of active selections. |
|
|
245
|
+
| somethingSelected() | Return true if any text is selected. |
|
|
246
|
+
| replaceRange(replacement: string \| Text, from: number, to: number) | Replace the part of the document between from and to with the given string. |
|
|
247
|
+
| replaceSelection(replacement: string \| Text) | Replace the selection(s) with the given string. |
|
|
248
|
+
| setCursor(position: number) | Set the cursor position. |
|
|
249
|
+
| setSelection(anchor: number, head?: number) | Set a single selection range. |
|
|
250
|
+
| setSelections(ranges: readonly SelectionRange[], primary?: number) | Sets a new set of selections. |
|
|
251
|
+
| extendSelectionsBy(f: Function) | Applies the given function to all existing selections, and calls extendSelections on the result. |
|
|
252
|
+
| focus() | Set focus |
|
|
253
|
+
| hasFocus() | is Focused |
|
|
254
|
+
|
|
231
255
|
## Recommendations
|
|
232
256
|
|
|
233
257
|
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.
|
|
@@ -242,10 +266,13 @@ const config: UserConfig = {
|
|
|
242
266
|
// ...
|
|
243
267
|
codemirror: [
|
|
244
268
|
// Split CodeMirror code.
|
|
245
|
-
'
|
|
269
|
+
'vue-codemirror6'
|
|
270
|
+
'codemirror',
|
|
271
|
+
'@codemirror/autocomplete',
|
|
246
272
|
'@codemirror/commands',
|
|
247
273
|
'@codemirror/language',
|
|
248
274
|
'@codemirror/lint',
|
|
275
|
+
'@codemirror/search',
|
|
249
276
|
'@codemirror/state',
|
|
250
277
|
'@codemirror/view',
|
|
251
278
|
// Add the following as needed.
|
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isVue2, h as h$1, defineComponent, ref,
|
|
2
|
-
import { EditorState, EditorSelection } from "@codemirror/state";
|
|
1
|
+
import { isVue2, h as h$1, defineComponent, ref, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
|
|
2
|
+
import { StateEffect, EditorState, EditorSelection } from "@codemirror/state";
|
|
3
3
|
import { EditorView, keymap } from "@codemirror/view";
|
|
4
4
|
import { linter, lintGutter } from "@codemirror/lint";
|
|
5
|
-
import { basicSetup } from "
|
|
5
|
+
import { basicSetup, minimalSetup } from "codemirror";
|
|
6
6
|
import { indentWithTab } from "@codemirror/commands";
|
|
7
7
|
import { trim, compact } from "lodash";
|
|
8
8
|
const adaptOnsV3 = (ons) => {
|
|
@@ -41,12 +41,16 @@ var CodeMirror = defineComponent({
|
|
|
41
41
|
},
|
|
42
42
|
dark: {
|
|
43
43
|
type: Boolean,
|
|
44
|
-
default:
|
|
44
|
+
default: window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
45
45
|
},
|
|
46
46
|
basic: {
|
|
47
47
|
type: Boolean,
|
|
48
48
|
default: false
|
|
49
49
|
},
|
|
50
|
+
minimal: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: false
|
|
53
|
+
},
|
|
50
54
|
wrap: {
|
|
51
55
|
type: Boolean,
|
|
52
56
|
default: false
|
|
@@ -89,42 +93,42 @@ var CodeMirror = defineComponent({
|
|
|
89
93
|
emits: ["update:modelValue", "update"],
|
|
90
94
|
setup(props, context) {
|
|
91
95
|
const editor = ref();
|
|
92
|
-
const { dark } = toRefs(props);
|
|
93
96
|
const doc = ref(props.modelValue);
|
|
97
|
+
const cursor = computed({
|
|
98
|
+
get: () => view.state.selection.main.head,
|
|
99
|
+
set: (p) => view.dispatch({ selection: { anchor: p } })
|
|
100
|
+
});
|
|
94
101
|
const emit = context.emit;
|
|
95
102
|
let view;
|
|
96
103
|
watch(doc, (value) => {
|
|
97
104
|
if (view.composing) {
|
|
98
105
|
return;
|
|
99
106
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
selection: previous
|
|
105
|
-
}));
|
|
107
|
+
view.dispatch({
|
|
108
|
+
changes: { from: 0, to: value.length, insert: value },
|
|
109
|
+
selection: { anchor: cursor.value }
|
|
110
|
+
});
|
|
106
111
|
});
|
|
107
112
|
watch(() => props.modelValue, (text) => view.dispatch({
|
|
108
|
-
changes: { from: 0, to: view.state.doc.length, insert: text }
|
|
113
|
+
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
114
|
+
selection: { anchor: cursor.value }
|
|
109
115
|
}));
|
|
110
|
-
watch(dark, () => {
|
|
111
|
-
view.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}));
|
|
116
|
+
watch(() => props.dark, () => {
|
|
117
|
+
view.dispatch({
|
|
118
|
+
effects: StateEffect.reconfigure.of(getExtensions())
|
|
119
|
+
});
|
|
115
120
|
});
|
|
116
121
|
onMounted(async () => {
|
|
122
|
+
let value = doc.value;
|
|
117
123
|
if (editor.value && editor.value.childNodes[0]) {
|
|
118
124
|
if (doc.value !== "") {
|
|
119
125
|
console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.");
|
|
120
126
|
}
|
|
121
|
-
|
|
127
|
+
value = trim(editor.value.childNodes[0].innerText);
|
|
122
128
|
}
|
|
123
129
|
view = new EditorView({
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
extensions: getExtensions()
|
|
127
|
-
}),
|
|
130
|
+
doc: value,
|
|
131
|
+
extensions: getExtensions(),
|
|
128
132
|
parent: editor.value,
|
|
129
133
|
dispatch: (tr) => {
|
|
130
134
|
view.update([tr]);
|
|
@@ -140,8 +144,9 @@ var CodeMirror = defineComponent({
|
|
|
140
144
|
const getExtensions = () => {
|
|
141
145
|
const extensions = compact([
|
|
142
146
|
props.basic ? basicSetup : void 0,
|
|
147
|
+
props.minimal && !props.basic ? minimalSetup : void 0,
|
|
143
148
|
EditorView.updateListener.of((update) => emit("update", update)),
|
|
144
|
-
EditorView.theme(props.theme, { dark: dark
|
|
149
|
+
EditorView.theme(props.theme, { dark: props.dark }),
|
|
145
150
|
props.wrap ? EditorView.lineWrapping : void 0,
|
|
146
151
|
props.tab ? keymap.of([indentWithTab]) : void 0,
|
|
147
152
|
props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
|
|
@@ -152,26 +157,25 @@ var CodeMirror = defineComponent({
|
|
|
152
157
|
props.linter && props.lintGutter ? lintGutter() : void 0,
|
|
153
158
|
...props.extensions
|
|
154
159
|
]);
|
|
155
|
-
console.debug("[CodeMirror.vue] Loaded extensions: ", extensions);
|
|
156
160
|
return extensions;
|
|
157
161
|
};
|
|
158
162
|
const selection = () => view.state.selection;
|
|
159
|
-
const getRange = (
|
|
160
|
-
const getLine = (
|
|
163
|
+
const getRange = (from, to) => view.state.sliceDoc(from, to);
|
|
164
|
+
const getLine = (number) => view.state.doc.line(number + 1).text;
|
|
161
165
|
const lineCount = () => view.state.doc.lines;
|
|
162
|
-
const getCursor = () =>
|
|
166
|
+
const getCursor = () => cursor.value;
|
|
163
167
|
const listSelections = () => selection().ranges;
|
|
164
168
|
const getSelection = () => view.state.sliceDoc(selection().main.from, selection().main.to);
|
|
165
169
|
const getSelections = () => selection().ranges.map((r) => view.state.sliceDoc(r.from, r.to));
|
|
166
170
|
const somethingSelected = () => selection().ranges.some((r) => !r.empty);
|
|
167
|
-
const replaceRange = (
|
|
168
|
-
changes: { from, to, insert:
|
|
171
|
+
const replaceRange = (replacement, from, to) => view.dispatch({
|
|
172
|
+
changes: { from, to, insert: replacement }
|
|
169
173
|
});
|
|
170
|
-
const replaceSelection = (
|
|
171
|
-
const setCursor = (
|
|
174
|
+
const replaceSelection = (replacement) => view.dispatch(view.state.replaceSelection(replacement));
|
|
175
|
+
const setCursor = (position) => cursor.value = position;
|
|
172
176
|
const setSelection = (anchor, head) => view.dispatch({ selection: { anchor, head } });
|
|
173
|
-
const setSelections = (ranges,
|
|
174
|
-
selection: EditorSelection.create(ranges,
|
|
177
|
+
const setSelections = (ranges, primary) => view.dispatch({
|
|
178
|
+
selection: EditorSelection.create(ranges, primary)
|
|
175
179
|
});
|
|
176
180
|
const extendSelectionsBy = (f) => view.dispatch({
|
|
177
181
|
selection: EditorSelection.create(selection().ranges.map((r) => r.extend(f(r))))
|
|
@@ -181,6 +185,7 @@ var CodeMirror = defineComponent({
|
|
|
181
185
|
return {
|
|
182
186
|
context,
|
|
183
187
|
editor,
|
|
188
|
+
cursor,
|
|
184
189
|
selection,
|
|
185
190
|
getRange,
|
|
186
191
|
getLine,
|
|
@@ -204,7 +209,7 @@ var CodeMirror = defineComponent({
|
|
|
204
209
|
return h("div", {
|
|
205
210
|
ref: "editor",
|
|
206
211
|
class: "vue-codemirror"
|
|
207
|
-
}, this.$slots.default ? h("aside", { style: "display: none;" }, slot(this.$slots.default)) : void 0);
|
|
212
|
+
}, this.$slots.default ? h("aside", { style: "display: none;", "aria-hidden": "true" }, slot(this.$slots.default)) : void 0);
|
|
208
213
|
}
|
|
209
214
|
});
|
|
210
215
|
/**
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("
|
|
1
|
+
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue-demi"),require("@codemirror/state"),require("@codemirror/view"),require("@codemirror/lint"),require("codemirror"),require("@codemirror/commands"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","vue-demi","@codemirror/state","@codemirror/view","@codemirror/lint","codemirror","@codemirror/commands","lodash"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.CodeMirror={},r.VueDemi,r.state,r.view,r.lint,r.codemirror,r.commands,r.lodash))})(this,function(r,n,f,u,g,p,w,y){"use strict";const V=e=>e?Object.entries(e).reduce((c,[i,s])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...c,[i]:s}),{}):null,S=(e,c={},i)=>{if(n.isVue2)return n.h(e,c,i);const{props:s,domProps:d,on:m,...o}=c,h=m?V(m):{};return n.h(e,{...o,...s,...d,...h},i)},C=e=>typeof e=="function"?e():e;var v=n.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:window.matchMedia("(prefers-color-scheme: dark)").matches},basic:{type:Boolean,default:!1},minimal:{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:Function,default:void 0},lintGutter:{type:Boolean,defalt:!1}},emits:["update:modelValue","update"],setup(e,c){const i=n.ref(),s=n.ref(e.modelValue),d=n.computed({get:()=>o.state.selection.main.head,set:t=>o.dispatch({selection:{anchor:t}})}),m=c.emit;let o;n.watch(s,t=>{o.composing||o.dispatch({changes:{from:0,to:t.length,insert:t},selection:{anchor:d.value}})}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:{anchor:d.value}})),n.watch(()=>e.dark,()=>{o.dispatch({effects:f.StateEffect.reconfigure.of(h())})}),n.onMounted(async()=>{let t=s.value;i.value&&i.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),t=y.trim(i.value.childNodes[0].innerText)),o=new u.EditorView({doc:t,extensions:h(),parent:i.value,dispatch:a=>{o.update([a]),!a.changes.empty&&(s.value=o.state.doc.toString(),m("update:modelValue",s.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const h=()=>y.compact([e.basic?p.basicSetup:void 0,e.minimal&&!e.basic?p.minimalSetup:void 0,u.EditorView.updateListener.of(a=>m("update",a)),u.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?u.EditorView.lineWrapping:void 0,e.tab?u.keymap.of([w.indentWithTab]):void 0,e.phrases?f.EditorState.phrases.of(e.phrases):void 0,e.readonly?f.EditorState.readOnly.of(e.readonly):void 0,e.editable?u.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?g.linter(e.linter):void 0,e.linter&&e.lintGutter?g.lintGutter():void 0,...e.extensions]),l=()=>o.state.selection;return{context:c,editor:i,cursor:d,selection:l,getRange:(t,a)=>o.state.sliceDoc(t,a),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>d.value,listSelections:()=>l().ranges,getSelection:()=>o.state.sliceDoc(l().main.from,l().main.to),getSelections:()=>l().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>l().ranges.some(t=>!t.empty),replaceRange:(t,a,b)=>o.dispatch({changes:{from:a,to:b,insert:t}}),replaceSelection:t=>o.dispatch(o.state.replaceSelection(t)),setCursor:t=>d.value=t,setSelection:(t,a)=>o.dispatch({selection:{anchor:t,head:a}}),setSelections:(t,a)=>o.dispatch({selection:f.EditorSelection.create(t,a)}),extendSelectionsBy:t=>o.dispatch({selection:f.EditorSelection.create(l().ranges.map(a=>a.extend(t(a))))}),focus:()=>o.focus(),hasFocus:()=>o.hasFocus}},render(){return S("div",{ref:"editor",class:"vue-codemirror"},this.$slots.default?S("aside",{style:"display: none;","aria-hidden":"true"},C(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 x=e=>e.component("CodeMirror",v);r.default=v,r.install=x,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|