vue-codemirror6 0.6.1 → 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 CHANGED
@@ -61,6 +61,7 @@ Notice: `lang` and `linter` can also be set together in `extensions`. This is de
61
61
 
62
62
  - [`@codemirror/theme-one-dark`](https://github.com/codemirror/theme-one-dark)
63
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)
64
65
 
65
66
  ## Example
66
67
 
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isVue2, h as h$1, defineComponent, ref, toRefs, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
1
+ import { isVue2, h as h$1, defineComponent, ref, computed, watch, onMounted, nextTick, onUnmounted, toRaw } from "vue-demi";
2
2
  import { StateEffect, EditorState, EditorSelection } from "@codemirror/state";
3
3
  import { EditorView, keymap } from "@codemirror/view";
4
4
  import { linter, lintGutter } from "@codemirror/lint";
@@ -41,7 +41,7 @@ var CodeMirror = defineComponent({
41
41
  },
42
42
  dark: {
43
43
  type: Boolean,
44
- default: false
44
+ default: window.matchMedia("(prefers-color-scheme: dark)").matches
45
45
  },
46
46
  basic: {
47
47
  type: Boolean,
@@ -93,7 +93,6 @@ var CodeMirror = defineComponent({
93
93
  emits: ["update:modelValue", "update"],
94
94
  setup(props, context) {
95
95
  const editor = ref();
96
- const { dark } = toRefs(props);
97
96
  const doc = ref(props.modelValue);
98
97
  const cursor = computed({
99
98
  get: () => view.state.selection.main.head,
@@ -114,9 +113,9 @@ var CodeMirror = defineComponent({
114
113
  changes: { from: 0, to: view.state.doc.length, insert: text },
115
114
  selection: { anchor: cursor.value }
116
115
  }));
117
- watch(dark, () => {
116
+ watch(() => props.dark, () => {
118
117
  view.dispatch({
119
- effects: StateEffect.appendConfig.of(EditorView.theme(props.theme, { dark: dark.value }))
118
+ effects: StateEffect.reconfigure.of(getExtensions())
120
119
  });
121
120
  });
122
121
  onMounted(async () => {
@@ -147,7 +146,7 @@ var CodeMirror = defineComponent({
147
146
  props.basic ? basicSetup : void 0,
148
147
  props.minimal && !props.basic ? minimalSetup : void 0,
149
148
  EditorView.updateListener.of((update) => emit("update", update)),
150
- EditorView.theme(props.theme, { dark: dark.value }),
149
+ EditorView.theme(props.theme, { dark: props.dark }),
151
150
  props.wrap ? EditorView.lineWrapping : void 0,
152
151
  props.tab ? keymap.of([indentWithTab]) : void 0,
153
152
  props.phrases ? EditorState.phrases.of(props.phrases) : void 0,
@@ -210,7 +209,7 @@ var CodeMirror = defineComponent({
210
209
  return h("div", {
211
210
  ref: "editor",
212
211
  class: "vue-codemirror"
213
- }, 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);
214
213
  }
215
214
  });
216
215
  /**
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
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,m,c,p,g,V,y){"use strict";const C=e=>e?Object.entries(e).reduce((d,[i,l])=>(i=i.charAt(0).toUpperCase()+i.slice(1),i=`on${i}`,{...d,[i]:l}),{}):null,S=(e,d={},i)=>{if(n.isVue2)return n.h(e,d,i);const{props:l,domProps:u,on:s,...h}=d,o=s?C(s):{};return n.h(e,{...h,...l,...u,...o},i)},w=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:!1},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,d){const i=n.ref(),{dark:l}=n.toRefs(e),u=n.ref(e.modelValue),s=n.computed({get:()=>o.state.selection.main.head,set:t=>o.dispatch({selection:{anchor:t}})}),h=d.emit;let o;n.watch(u,t=>{o.composing||o.dispatch({changes:{from:0,to:t.length,insert:t},selection:{anchor:s.value}})}),n.watch(()=>e.modelValue,t=>o.dispatch({changes:{from:0,to:o.state.doc.length,insert:t},selection:{anchor:s.value}})),n.watch(l,()=>{o.dispatch({effects:m.StateEffect.appendConfig.of(c.EditorView.theme(e.theme,{dark:l.value}))})}),n.onMounted(async()=>{let t=u.value;i.value&&i.value.childNodes[0]&&(u.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 c.EditorView({doc:t,extensions:E(),parent:i.value,dispatch:a=>{o.update([a]),!a.changes.empty&&(u.value=o.state.doc.toString(),h("update:modelValue",u.value))}}),await n.nextTick()}),n.onUnmounted(()=>o.destroy());const E=()=>y.compact([e.basic?g.basicSetup:void 0,e.minimal&&!e.basic?g.minimalSetup:void 0,c.EditorView.updateListener.of(a=>h("update",a)),c.EditorView.theme(e.theme,{dark:l.value}),e.wrap?c.EditorView.lineWrapping:void 0,e.tab?c.keymap.of([V.indentWithTab]):void 0,e.phrases?m.EditorState.phrases.of(e.phrases):void 0,e.readonly?m.EditorState.readOnly.of(e.readonly):void 0,e.editable?c.EditorView.editable.of(e.editable):void 0,e.lang?n.toRaw(e.lang):void 0,e.linter?p.linter(e.linter):void 0,e.linter&&e.lintGutter?p.lintGutter():void 0,...e.extensions]),f=()=>o.state.selection;return{context:d,editor:i,cursor:s,selection:f,getRange:(t,a)=>o.state.sliceDoc(t,a),getLine:t=>o.state.doc.line(t+1).text,lineCount:()=>o.state.doc.lines,getCursor:()=>s.value,listSelections:()=>f().ranges,getSelection:()=>o.state.sliceDoc(f().main.from,f().main.to),getSelections:()=>f().ranges.map(t=>o.state.sliceDoc(t.from,t.to)),somethingSelected:()=>f().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=>s.value=t,setSelection:(t,a)=>o.dispatch({selection:{anchor:t,head:a}}),setSelections:(t,a)=>o.dispatch({selection:m.EditorSelection.create(t,a)}),extendSelectionsBy:t=>o.dispatch({selection:m.EditorSelection.create(f().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;"},w(this.$slots.default)):void 0)}});/**
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