vue-codemirror6 1.3.0 → 1.3.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 +73 -96
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +37 -33
- package/dist/index.iife.js +3 -3
- package/dist/index.umd.js +3 -3
- package/package.json +22 -26
- package/src/components/CodeMirror.ts +14 -2
package/README.md
CHANGED
|
@@ -202,20 +202,10 @@ export default defineComponent({
|
|
|
202
202
|
|
|
203
203
|
### Full Example
|
|
204
204
|
|
|
205
|
-
When using as a Markdown editor on [
|
|
205
|
+
When using as a Markdown editor on [https://github.com/logue/vite-vue3-ts-starter](vite-vue3-ts-starter).
|
|
206
206
|
|
|
207
207
|
```vue
|
|
208
|
-
<
|
|
209
|
-
<code-mirror
|
|
210
|
-
v-model="value"
|
|
211
|
-
basic
|
|
212
|
-
:dark="dark"
|
|
213
|
-
:lang="lang"
|
|
214
|
-
:phrases="phreses"
|
|
215
|
-
/>
|
|
216
|
-
</template>
|
|
217
|
-
|
|
218
|
-
<script lang="ts">
|
|
208
|
+
<script lang="ts" setup>
|
|
219
209
|
import { ref, defineComponent, type Ref } from 'vue';
|
|
220
210
|
|
|
221
211
|
// Load component
|
|
@@ -227,90 +217,76 @@ import type { LanguageSupport } from '@codemirror/language';
|
|
|
227
217
|
import type { Extension } from '@codemirror/state';
|
|
228
218
|
import type { ViewUpdate } from '@codemirror/view';
|
|
229
219
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
'replace all': 'すべてを置き換え',
|
|
290
|
-
close: '閉じる',
|
|
291
|
-
'current match': '現在の一致',
|
|
292
|
-
'replaced $ matches': '$ 件の一致を置き換え',
|
|
293
|
-
'replaced match on line $': '$ 行の一致を置き換え',
|
|
294
|
-
'on line': 'した行',
|
|
295
|
-
// @codemirror/autocomplete
|
|
296
|
-
Completions: '自動補完',
|
|
297
|
-
// @codemirror/lint
|
|
298
|
-
Diagnostics: 'エラー',
|
|
299
|
-
'No diagnostics': 'エラーなし',
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
/** When dark value changed, sync vuetify's dark mode */
|
|
303
|
-
watch(dark, v => (vuetify.theme.dark = v));
|
|
304
|
-
|
|
305
|
-
return {
|
|
306
|
-
dark,
|
|
307
|
-
value,
|
|
308
|
-
lang,
|
|
309
|
-
phrases,
|
|
310
|
-
};
|
|
311
|
-
},
|
|
312
|
-
});
|
|
220
|
+
/** text */
|
|
221
|
+
const value: Ref<string> = ref('');
|
|
222
|
+
|
|
223
|
+
/** Dark mode **/
|
|
224
|
+
const dark: Ref<boolean> = ref(
|
|
225
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* CodeMirror Language
|
|
230
|
+
*
|
|
231
|
+
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
232
|
+
*/
|
|
233
|
+
const lang: LanguageSupport = md();
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Internationalization Config.
|
|
237
|
+
* In this example, the display language to Japanese.
|
|
238
|
+
* Must be reactive when used in combination with vue-i18n.
|
|
239
|
+
*
|
|
240
|
+
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
241
|
+
*/
|
|
242
|
+
const phrases: Record<string, string> = {
|
|
243
|
+
// @codemirror/view
|
|
244
|
+
'Control character': '制御文字',
|
|
245
|
+
// @codemirror/commands
|
|
246
|
+
'Selection deleted': '選択を削除',
|
|
247
|
+
// @codemirror/language
|
|
248
|
+
'Folded lines': '折り畳まれた行',
|
|
249
|
+
'Unfolded lines': '折り畳める行',
|
|
250
|
+
to: '行き先',
|
|
251
|
+
'folded code': '折り畳まれたコード',
|
|
252
|
+
unfold: '折り畳みを解除',
|
|
253
|
+
'Fold line': '行を折り畳む',
|
|
254
|
+
'Unfold line': '行の折り畳む解除',
|
|
255
|
+
// @codemirror/search
|
|
256
|
+
'Go to line': '行き先の行',
|
|
257
|
+
go: 'OK',
|
|
258
|
+
Find: '検索',
|
|
259
|
+
Replace: '置き換え',
|
|
260
|
+
next: '▼',
|
|
261
|
+
previous: '▲',
|
|
262
|
+
all: 'すべて',
|
|
263
|
+
'match case': '一致条件',
|
|
264
|
+
'by word': '全文検索',
|
|
265
|
+
regexp: '正規表現',
|
|
266
|
+
replace: '置き換え',
|
|
267
|
+
'replace all': 'すべてを置き換え',
|
|
268
|
+
close: '閉じる',
|
|
269
|
+
'current match': '現在の一致',
|
|
270
|
+
'replaced $ matches': '$ 件の一致を置き換え',
|
|
271
|
+
'replaced match on line $': '$ 行の一致を置き換え',
|
|
272
|
+
'on line': 'した行',
|
|
273
|
+
// @codemirror/autocomplete
|
|
274
|
+
Completions: '自動補完',
|
|
275
|
+
// @codemirror/lint
|
|
276
|
+
Diagnostics: 'エラー',
|
|
277
|
+
'No diagnostics': 'エラーなし',
|
|
278
|
+
};
|
|
313
279
|
</script>
|
|
280
|
+
|
|
281
|
+
<template>
|
|
282
|
+
<code-mirror
|
|
283
|
+
v-model="value"
|
|
284
|
+
basic
|
|
285
|
+
:dark="dark"
|
|
286
|
+
:lang="lang"
|
|
287
|
+
:phrases="phrases"
|
|
288
|
+
/>
|
|
289
|
+
</template>
|
|
314
290
|
```
|
|
315
291
|
|
|
316
292
|
## Events
|
|
@@ -413,4 +389,5 @@ const config: UserConfig = {
|
|
|
413
389
|
|
|
414
390
|
## LICENSE
|
|
415
391
|
|
|
416
|
-
©2022-
|
|
392
|
+
©2022-2024 by Logue.
|
|
393
|
+
Licensed under the [MIT License](LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { default as CodeMirror } from './components/CodeMirror';
|
|
2
1
|
import { default as Meta } from './Meta';
|
|
2
|
+
import { default as CodeMirror } from './components/CodeMirror';
|
|
3
3
|
|
|
4
4
|
declare const installCodeMirror: (app: any) => void;
|
|
5
5
|
export { CodeMirror as default, installCodeMirror as install, Meta };
|
package/dist/index.es.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.3.
|
|
8
|
+
* @version 1.3.2
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -15,21 +15,21 @@ import { forceLinting as b, linter as P, lintGutter as Z, diagnosticCount as k }
|
|
|
15
15
|
import { EditorState as s, Compartment as C, StateEffect as y, EditorSelection as w } from "@codemirror/state";
|
|
16
16
|
import { EditorView as r, keymap as q, placeholder as H } from "@codemirror/view";
|
|
17
17
|
import { basicSetup as K, minimalSetup as Q } from "codemirror";
|
|
18
|
-
import { isVue2 as X, h as O, defineComponent as Y, ref as v, shallowRef as ee, computed as
|
|
19
|
-
const
|
|
20
|
-
version: "1.3.
|
|
21
|
-
date: "2024-
|
|
18
|
+
import { isVue2 as X, h as O, defineComponent as Y, ref as v, shallowRef as ee, computed as d, watch as $, onMounted as te, nextTick as ae, onUnmounted as ne } from "vue-demi";
|
|
19
|
+
const ie = {
|
|
20
|
+
version: "1.3.2",
|
|
21
|
+
date: "2024-06-10T11:57:17.342Z"
|
|
22
22
|
};
|
|
23
|
-
var ge =
|
|
24
|
-
const
|
|
25
|
-
function B(e,
|
|
23
|
+
var ge = ie;
|
|
24
|
+
const le = (e) => e ? Object.entries(e).reduce((l, [i, u]) => (i = i.charAt(0).toUpperCase() + i.slice(1), i = `on${i}`, { ...l, [i]: u }), {}) : {};
|
|
25
|
+
function B(e, l = {}, i) {
|
|
26
26
|
if (X)
|
|
27
|
-
return O(e,
|
|
28
|
-
const { props: u, domProps: t, on:
|
|
27
|
+
return O(e, l, i);
|
|
28
|
+
const { props: u, domProps: t, on: f, ...c } = l, m = f ? le(f) : {};
|
|
29
29
|
return O(
|
|
30
30
|
e,
|
|
31
|
-
{ ...
|
|
32
|
-
|
|
31
|
+
{ ...c, ...u, ...t, ...m },
|
|
32
|
+
i
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
35
|
const oe = (e) => typeof e == "function" ? e() : e;
|
|
@@ -271,33 +271,35 @@ var se = Y({
|
|
|
271
271
|
* @param props - Props
|
|
272
272
|
* @param context - Context
|
|
273
273
|
*/
|
|
274
|
-
setup(e,
|
|
275
|
-
const
|
|
274
|
+
setup(e, l) {
|
|
275
|
+
const i = v(), u = v(e.modelValue), t = ee(new r()), f = d({
|
|
276
276
|
get: () => t.value.hasFocus,
|
|
277
277
|
set: (a) => {
|
|
278
278
|
a && t.value.focus();
|
|
279
279
|
}
|
|
280
|
-
}),
|
|
280
|
+
}), c = d({
|
|
281
281
|
get: () => t.value.state.selection,
|
|
282
282
|
set: (a) => t.value.dispatch({ selection: a })
|
|
283
|
-
}), m =
|
|
283
|
+
}), m = d({
|
|
284
284
|
get: () => t.value.state.selection.main.head,
|
|
285
285
|
set: (a) => t.value.dispatch({ selection: { anchor: a } })
|
|
286
|
-
}), M =
|
|
286
|
+
}), M = d(
|
|
287
287
|
{
|
|
288
288
|
get: () => t.value.state.toJSON(),
|
|
289
289
|
set: (a) => t.value.setState(s.fromJSON(a))
|
|
290
290
|
}
|
|
291
|
-
), S = v(0), g = v(0), h =
|
|
291
|
+
), S = v(0), g = v(0), h = d(() => {
|
|
292
292
|
const a = new C(), n = new C();
|
|
293
|
+
if (e.basic && e.minimal)
|
|
294
|
+
throw "[Vue CodeMirror] Both basic and minimal cannot be specified.";
|
|
293
295
|
return [
|
|
294
296
|
// Toggle basic setup
|
|
295
|
-
e.basic ? K : void 0,
|
|
297
|
+
e.basic && !e.minimal ? K : void 0,
|
|
296
298
|
// Toggle minimal setup
|
|
297
299
|
e.minimal && !e.basic ? Q : void 0,
|
|
298
300
|
// ViewUpdate event listener
|
|
299
301
|
r.updateListener.of((o) => {
|
|
300
|
-
|
|
302
|
+
l.emit("focus", t.value.hasFocus), S.value = t.value.state.doc?.length, !(o.changes.empty || !o.docChanged) && (e.linter && (e.forceLinting && b(t.value), g.value = e.linter(t.value).length), l.emit("update", o));
|
|
301
303
|
}),
|
|
302
304
|
// Toggle light/dark mode.
|
|
303
305
|
r.theme(e.theme, { dark: e.dark }),
|
|
@@ -344,7 +346,9 @@ var se = Y({
|
|
|
344
346
|
async (a) => {
|
|
345
347
|
t.value.composing || // IME fix
|
|
346
348
|
t.value.state.doc.toJSON().join(e.lineSeparator ?? `
|
|
347
|
-
`) === a ||
|
|
349
|
+
`) === a || c.value.ranges.every(
|
|
350
|
+
(n) => n.anchor < a.length && n.head < a.length
|
|
351
|
+
) && t.value.dispatch({
|
|
348
352
|
changes: { from: 0, to: t.value.state.doc.length, insert: a },
|
|
349
353
|
selection: t.value.state.selection,
|
|
350
354
|
scrollIntoView: !0
|
|
@@ -353,21 +357,21 @@ var se = Y({
|
|
|
353
357
|
{ immediate: !0 }
|
|
354
358
|
), te(async () => {
|
|
355
359
|
let a = u.value;
|
|
356
|
-
|
|
360
|
+
i.value && (i.value.childNodes[0] && (u.value !== "" && console.warn(
|
|
357
361
|
"[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."
|
|
358
|
-
), a =
|
|
359
|
-
parent:
|
|
362
|
+
), a = i.value.childNodes[0].innerText.trim()), t.value = new r({
|
|
363
|
+
parent: i.value,
|
|
360
364
|
state: s.create({ doc: a, extensions: h.value }),
|
|
361
365
|
dispatch: (n) => {
|
|
362
|
-
t.value.update([n]), !(n.changes.empty || !n.docChanged) && (
|
|
366
|
+
t.value.update([n]), !(n.changes.empty || !n.docChanged) && (l.emit("update:modelValue", n.state.doc.toString() ?? ""), l.emit("change", n.state));
|
|
363
367
|
}
|
|
364
|
-
}), await ae(),
|
|
368
|
+
}), await ae(), l.emit("ready", {
|
|
365
369
|
view: t.value,
|
|
366
370
|
state: t.value.state,
|
|
367
|
-
container:
|
|
371
|
+
container: i.value
|
|
368
372
|
}));
|
|
369
373
|
}), ne(() => {
|
|
370
|
-
t.value.destroy(),
|
|
374
|
+
t.value.destroy(), l.emit("destroy");
|
|
371
375
|
});
|
|
372
376
|
const V = () => {
|
|
373
377
|
!e.linter || !t.value || (e.forceLinting && b(t.value), g.value = k(t.value.state));
|
|
@@ -399,14 +403,14 @@ var se = Y({
|
|
|
399
403
|
selection: w.create(a, n)
|
|
400
404
|
}), W = (a) => t.value.dispatch({
|
|
401
405
|
selection: w.create(
|
|
402
|
-
|
|
406
|
+
c.value.ranges.map((n) => n.extend(a(n)))
|
|
403
407
|
)
|
|
404
408
|
}), p = {
|
|
405
|
-
editor:
|
|
409
|
+
editor: i,
|
|
406
410
|
view: t,
|
|
407
411
|
cursor: m,
|
|
408
|
-
selection:
|
|
409
|
-
focus:
|
|
412
|
+
selection: c,
|
|
413
|
+
focus: f,
|
|
410
414
|
length: S,
|
|
411
415
|
json: M,
|
|
412
416
|
diagnosticCount: g,
|
|
@@ -429,7 +433,7 @@ var se = Y({
|
|
|
429
433
|
setSelections: A,
|
|
430
434
|
extendSelectionsBy: W
|
|
431
435
|
};
|
|
432
|
-
return
|
|
436
|
+
return l.expose(p), p;
|
|
433
437
|
},
|
|
434
438
|
render() {
|
|
435
439
|
return B(
|
package/dist/index.iife.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.3.
|
|
8
|
+
* @version 1.3.2
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
var CodeMirror=function(u,E,V,f,i,c,y,l){"use strict";var
|
|
13
|
-
`)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),l.onMounted(async()=>{let a=s.value;o.value&&(o.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(r.emit("update:modelValue",n.state.doc.toString()??""),r.emit("change",n.state))}}),await l.nextTick(),r.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),l.onUnmounted(()=>{t.value.destroy(),r.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,n)=>t.value.state.sliceDoc(a,n),U=a=>t.value.state.doc.line(a+1).text,z=()=>t.value.state.doc.lines,T=()=>t.value.state.selection.main.head,R=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,n,d)=>t.value.dispatch({changes:{from:n,to:d,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),W=a=>t.value.dispatch({selection:{anchor:a}}),G=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),I=(a,n)=>t.value.dispatch({selection:i.EditorSelection.create(a,n)}),Z=a=>t.value.dispatch({selection:i.EditorSelection.create(
|
|
12
|
+
var CodeMirror=function(u,E,V,f,i,c,y,l){"use strict";var M={version:"1.3.2",date:"2024-06-10T11:57:17.342Z"};const O=e=>e?Object.entries(e).reduce((r,[o,s])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...r,[o]:s}),{}):{};function b(e,r={},o){if(l.isVue2)return l.h(e,r,o);const{props:s,domProps:t,on:g,...v}=r,h=g?O(g):{};return l.h(e,{...v,...s,...t,...h},o)}const $=e=>typeof e=="function"?e():e;var C=l.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,r){const o=l.ref(),s=l.ref(e.modelValue),t=l.shallowRef(new c.EditorView),g=l.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),v=l.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),h=l.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),j=l.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(i.EditorState.fromJSON(a))}),w=l.ref(0),m=l.ref(0),S=l.computed(()=>{const a=new i.Compartment,n=new i.Compartment;if(e.basic&&e.minimal)throw"[Vue CodeMirror] Both basic and minimal cannot be specified.";return[e.basic&&!e.minimal?y.basicSetup:void 0,e.minimal&&!e.basic?y.minimalSetup:void 0,c.EditorView.updateListener.of(d=>{r.emit("focus",t.value.hasFocus),w.value=t.value.state.doc?.length,!(d.changes.empty||!d.docChanged)&&(e.linter&&(e.forceLinting&&f.forceLinting(t.value),m.value=e.linter(t.value).length),r.emit("update",d))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([E.indentWithTab]):void 0,e.indentUnit?V.indentUnit.of(e.indentUnit):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?f.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?f.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(d=>!!d)});l.watch(S,a=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of(a)})},{immediate:!0}),l.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
|
|
13
|
+
`)===a||v.value.ranges.every(n=>n.anchor<a.length&&n.head<a.length)&&t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),l.onMounted(async()=>{let a=s.value;o.value&&(o.value.childNodes[0]&&(s.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:o.value,state:i.EditorState.create({doc:a,extensions:S.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(r.emit("update:modelValue",n.state.doc.toString()??""),r.emit("change",n.state))}}),await l.nextTick(),r.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),l.onUnmounted(()=>{t.value.destroy(),r.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&f.forceLinting(t.value),m.value=f.diagnosticCount(t.value.state))},L=()=>{t.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:i.StateEffect.appendConfig.of(S.value)})},N=(a,n)=>t.value.state.sliceDoc(a,n),U=a=>t.value.state.doc.line(a+1).text,z=()=>t.value.state.doc.lines,T=()=>t.value.state.selection.main.head,R=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},F=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},J=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},x=()=>t.value.state.selection.ranges.some(a=>!a.empty),A=(a,n,d)=>t.value.dispatch({changes:{from:n,to:d,insert:a}}),P=a=>t.value.dispatch(t.value.state.replaceSelection(a)),W=a=>t.value.dispatch({selection:{anchor:a}}),G=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),I=(a,n)=>t.value.dispatch({selection:i.EditorSelection.create(a,n)}),Z=a=>t.value.dispatch({selection:i.EditorSelection.create(v.value.ranges.map(n=>n.extend(a(n))))}),p={editor:o,view:t,cursor:h,selection:v,focus:g,length:w,json:j,diagnosticCount:m,dom:t.value.contentDOM,lint:_,forceReconfigure:L,getRange:N,getLine:U,lineCount:z,getCursor:T,listSelections:R,getSelection:F,getSelections:J,somethingSelected:x,replaceRange:A,replaceSelection:P,setCursor:W,setSelection:G,setSelections:I,extendSelectionsBy:Z};return r.expose(p),p},render(){return b(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?b("aside",{style:"display: none;","aria-hidden":"true"},$(this.$slots.default)):void 0)}});const B=e=>e.component("CodeMirror",C);return u.Meta=M,u.default=C,u.install=B,Object.defineProperty(u,"__esModule",{value:!0}),u}({},commands,language,lint,state,view,codemirror,VueDemi);
|
package/dist/index.umd.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* @author Logue <logue@hotmail.co.jp>
|
|
6
6
|
* @copyright 2022-2024 By Masashi Yoshikawa All rights reserved.
|
|
7
7
|
* @license MIT
|
|
8
|
-
* @version 1.3.
|
|
8
|
+
* @version 1.3.2
|
|
9
9
|
* @see {@link https://github.com/logue/vue-codemirror6}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,function(l,f,V,v,r,c,p,
|
|
13
|
-
`)===a||t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),
|
|
12
|
+
(function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@codemirror/commands"),require("@codemirror/language"),require("@codemirror/lint"),require("@codemirror/state"),require("@codemirror/view"),require("codemirror"),require("vue-demi")):typeof define=="function"&&define.amd?define(["exports","@codemirror/commands","@codemirror/language","@codemirror/lint","@codemirror/state","@codemirror/view","codemirror","vue-demi"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.CodeMirror={},l.commands,l.language,l.lint,l.state,l.view,l.codemirror,l.VueDemi))})(this,function(l,f,V,v,r,c,p,i){"use strict";var M={version:"1.3.2",date:"2024-06-10T11:57:17.342Z"};const O=e=>e?Object.entries(e).reduce((d,[o,u])=>(o=o.charAt(0).toUpperCase()+o.slice(1),o=`on${o}`,{...d,[o]:u}),{}):{};function w(e,d={},o){if(i.isVue2)return i.h(e,d,o);const{props:u,domProps:t,on:h,...m}=d,g=h?O(h):{};return i.h(e,{...m,...u,...t,...g},o)}const $=e=>typeof e=="function"?e():e;var C=i.defineComponent({name:"CodeMirror",model:{prop:"modelValue",event:"update:modelValue"},props:{modelValue:{type:String,default:""},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:()=>{}},lang:{type:Object,default:()=>{}},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:()=>{}},tag:{type:String,default:"div"}},emits:{"update:modelValue":(e="")=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,d){const o=i.ref(),u=i.ref(e.modelValue),t=i.shallowRef(new c.EditorView),h=i.computed({get:()=>t.value.hasFocus,set:a=>{a&&t.value.focus()}}),m=i.computed({get:()=>t.value.state.selection,set:a=>t.value.dispatch({selection:a})}),g=i.computed({get:()=>t.value.state.selection.main.head,set:a=>t.value.dispatch({selection:{anchor:a}})}),j=i.computed({get:()=>t.value.state.toJSON(),set:a=>t.value.setState(r.EditorState.fromJSON(a))}),b=i.ref(0),S=i.ref(0),y=i.computed(()=>{const a=new r.Compartment,n=new r.Compartment;if(e.basic&&e.minimal)throw"[Vue CodeMirror] Both basic and minimal cannot be specified.";return[e.basic&&!e.minimal?p.basicSetup:void 0,e.minimal&&!e.basic?p.minimalSetup:void 0,c.EditorView.updateListener.of(s=>{d.emit("focus",t.value.hasFocus),b.value=t.value.state.doc?.length,!(s.changes.empty||!s.docChanged)&&(e.linter&&(e.forceLinting&&v.forceLinting(t.value),S.value=e.linter(t.value).length),d.emit("update",s))}),c.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([f.indentWithTab]):void 0,e.indentUnit?V.indentUnit.of(e.indentUnit):void 0,r.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?n.of(r.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?r.EditorState.phrases.of(e.phrases):void 0,r.EditorState.readOnly.of(e.readonly),c.EditorView.editable.of(!e.disabled),e.lineSeparator?r.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?a.of(e.lang):void 0,e.linter?v.linter(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?v.lintGutter(e.gutterConfig):void 0,e.placeholder?c.placeholder(e.placeholder):void 0,...e.extensions].filter(s=>!!s)});i.watch(y,a=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of(a)})},{immediate:!0}),i.watch(()=>e.modelValue,async a=>{t.value.composing||t.value.state.doc.toJSON().join(e.lineSeparator??`
|
|
13
|
+
`)===a||m.value.ranges.every(n=>n.anchor<a.length&&n.head<a.length)&&t.value.dispatch({changes:{from:0,to:t.value.state.doc.length,insert:a},selection:t.value.state.selection,scrollIntoView:!0})},{immediate:!0}),i.onMounted(async()=>{let a=u.value;o.value&&(o.value.childNodes[0]&&(u.value!==""&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),a=o.value.childNodes[0].innerText.trim()),t.value=new c.EditorView({parent:o.value,state:r.EditorState.create({doc:a,extensions:y.value}),dispatch:n=>{t.value.update([n]),!(n.changes.empty||!n.docChanged)&&(d.emit("update:modelValue",n.state.doc.toString()??""),d.emit("change",n.state))}}),await i.nextTick(),d.emit("ready",{view:t.value,state:t.value.state,container:o.value}))}),i.onUnmounted(()=>{t.value.destroy(),d.emit("destroy")});const _=()=>{!e.linter||!t.value||(e.forceLinting&&v.forceLinting(t.value),S.value=v.diagnosticCount(t.value.state))},q=()=>{t.value?.dispatch({effects:r.StateEffect.reconfigure.of([])}),t.value?.dispatch({effects:r.StateEffect.appendConfig.of(y.value)})},L=(a,n)=>t.value.state.sliceDoc(a,n),T=a=>t.value.state.doc.line(a+1).text,x=()=>t.value.state.doc.lines,N=()=>t.value.state.selection.main.head,U=()=>{let a;return(a=t.value.state.selection.ranges)!==null&&a!==void 0?a:[]},z=()=>{let a;return(a=t.value.state.sliceDoc(t.value.state.selection.main.from,t.value.state.selection.main.to))!==null&&a!==void 0?a:""},R=()=>{const a=t.value.state;return a?a.selection.ranges.map(n=>a.sliceDoc(n.from,n.to)):[]},F=()=>t.value.state.selection.ranges.some(a=>!a.empty),J=(a,n,s)=>t.value.dispatch({changes:{from:n,to:s,insert:a}}),A=a=>t.value.dispatch(t.value.state.replaceSelection(a)),P=a=>t.value.dispatch({selection:{anchor:a}}),W=(a,n)=>t.value.dispatch({selection:{anchor:a,head:n}}),G=(a,n)=>t.value.dispatch({selection:r.EditorSelection.create(a,n)}),I=a=>t.value.dispatch({selection:r.EditorSelection.create(m.value.ranges.map(n=>n.extend(a(n))))}),E={editor:o,view:t,cursor:g,selection:m,focus:h,length:b,json:j,diagnosticCount:S,dom:t.value.contentDOM,lint:_,forceReconfigure:q,getRange:L,getLine:T,lineCount:x,getCursor:N,listSelections:U,getSelection:z,getSelections:R,somethingSelected:F,replaceRange:J,replaceSelection:A,setCursor:P,setSelection:W,setSelections:G,extendSelectionsBy:I};return d.expose(E),E},render(){return w(this.$props.tag,{ref:"editor",class:"vue-codemirror"},this.$slots.default?w("aside",{style:"display: none;","aria-hidden":"true"},$(this.$slots.default)):void 0)}});const B=e=>e.component("CodeMirror",C);l.Meta=M,l.default=C,l.install=B,Object.defineProperty(l,"__esModule",{value:!0})});
|
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": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "CodeMirror6 Component for vue2 and vue3.",
|
|
7
7
|
"keywords": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"engines": {
|
|
56
56
|
"yarn": ">=1.22.19"
|
|
57
57
|
},
|
|
58
|
-
"packageManager": "yarn@4.
|
|
58
|
+
"packageManager": "yarn@4.2.2",
|
|
59
59
|
"sideEffects": false,
|
|
60
60
|
"scripts": {
|
|
61
61
|
"dev": "vite",
|
|
@@ -83,46 +83,42 @@
|
|
|
83
83
|
"@codemirror/lang-json": "^6.0.1",
|
|
84
84
|
"@codemirror/lang-markdown": "^6.2.5",
|
|
85
85
|
"@codemirror/lang-vue": "0.1.2",
|
|
86
|
-
"@eslint/js": "^9.
|
|
86
|
+
"@eslint/js": "^9.4.0",
|
|
87
87
|
"@tsconfig/node-lts": "^20.1.3",
|
|
88
|
-
"@types/node": "^20.
|
|
89
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
90
|
-
"@vitejs/plugin-vue": "^5.0.
|
|
91
|
-
"@vue/compiler-sfc": "^3.4.
|
|
88
|
+
"@types/node": "^20.14.2",
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
|
90
|
+
"@vitejs/plugin-vue": "^5.0.5",
|
|
91
|
+
"@vue/compiler-sfc": "^3.4.27",
|
|
92
92
|
"@vue/eslint-config-prettier": "^9.0.0",
|
|
93
93
|
"@vue/tsconfig": "^0.5.1",
|
|
94
|
-
"@vueuse/core": "^10.
|
|
94
|
+
"@vueuse/core": "^10.10.0",
|
|
95
95
|
"bootstrap": "^5.3.3",
|
|
96
|
-
"eslint": "^9.
|
|
97
|
-
"eslint-config-standard-with-typescript": "^43.0.1",
|
|
96
|
+
"eslint": "^9.4.0",
|
|
98
97
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
99
98
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
100
|
-
"eslint-linter-browserify": "^9.
|
|
101
|
-
"eslint-plugin-html": "^8.1.1",
|
|
99
|
+
"eslint-linter-browserify": "^9.4.0",
|
|
102
100
|
"eslint-plugin-import": "^2.29.1",
|
|
103
|
-
"eslint-plugin-
|
|
104
|
-
"eslint-plugin-
|
|
105
|
-
"eslint-plugin-tsdoc": "^0.2.17",
|
|
106
|
-
"eslint-plugin-vue": "latest",
|
|
101
|
+
"eslint-plugin-tsdoc": "^0.3.0",
|
|
102
|
+
"eslint-plugin-vue": "^9.26.0",
|
|
107
103
|
"eslint-plugin-vuejs-accessibility": "^2.3.0",
|
|
108
104
|
"eslint-plugin-yaml": "^0.5.0",
|
|
109
105
|
"husky": "^9.0.11",
|
|
110
|
-
"lint-staged": "^15.2.
|
|
106
|
+
"lint-staged": "^15.2.5",
|
|
111
107
|
"npm-run-all": "^4.1.5",
|
|
112
|
-
"prettier": "^3.
|
|
113
|
-
"rimraf": "^5.0.
|
|
108
|
+
"prettier": "^3.3.1",
|
|
109
|
+
"rimraf": "^5.0.7",
|
|
114
110
|
"rollup-plugin-visualizer": "^5.12.0",
|
|
115
|
-
"sass": "^1.
|
|
111
|
+
"sass": "^1.77.4",
|
|
116
112
|
"typescript": "^5.4.5",
|
|
117
|
-
"typescript-eslint": "^7.
|
|
118
|
-
"vite": "^5.2.
|
|
113
|
+
"typescript-eslint": "^7.12.0",
|
|
114
|
+
"vite": "^5.2.13",
|
|
119
115
|
"vite-plugin-banner": "^0.7.1",
|
|
120
116
|
"vite-plugin-checker": "^0.6.4",
|
|
121
|
-
"vite-plugin-dts": "^3.9.
|
|
122
|
-
"vue": "^3.4.
|
|
123
|
-
"vue-eslint-parser": "^9.4.
|
|
117
|
+
"vite-plugin-dts": "^3.9.1",
|
|
118
|
+
"vue": "^3.4.27",
|
|
119
|
+
"vue-eslint-parser": "^9.4.3",
|
|
124
120
|
"vue-markdown-wasm": "^0.4.0",
|
|
125
|
-
"vue-tsc": "^2.0.
|
|
121
|
+
"vue-tsc": "^2.0.21"
|
|
126
122
|
},
|
|
127
123
|
"husky": {
|
|
128
124
|
"hooks": {
|
|
@@ -363,11 +363,13 @@ export default defineComponent({
|
|
|
363
363
|
// @see https://codemirror.net/examples/config/
|
|
364
364
|
const language = new Compartment();
|
|
365
365
|
const tabSize = new Compartment();
|
|
366
|
-
|
|
366
|
+
if (props.basic && props.minimal) {
|
|
367
|
+
throw '[Vue CodeMirror] Both basic and minimal cannot be specified.';
|
|
368
|
+
}
|
|
367
369
|
// TODO: Ignore previous prop was not changed.
|
|
368
370
|
return [
|
|
369
371
|
// Toggle basic setup
|
|
370
|
-
props.basic ? basicSetup : undefined,
|
|
372
|
+
props.basic && !props.minimal ? basicSetup : undefined,
|
|
371
373
|
// Toggle minimal setup
|
|
372
374
|
props.minimal && !props.basic ? minimalSetup : undefined,
|
|
373
375
|
// ViewUpdate event listener
|
|
@@ -458,6 +460,16 @@ export default defineComponent({
|
|
|
458
460
|
return;
|
|
459
461
|
}
|
|
460
462
|
|
|
463
|
+
// Range Fix ?
|
|
464
|
+
// https://github.com/logue/vue-codemirror6/issues/27
|
|
465
|
+
if (
|
|
466
|
+
!selection.value.ranges.every(
|
|
467
|
+
range => range.anchor < value.length && range.head < value.length
|
|
468
|
+
)
|
|
469
|
+
) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
461
473
|
// Update
|
|
462
474
|
view.value.dispatch({
|
|
463
475
|
changes: { from: 0, to: view.value.state.doc.length, insert: value },
|