vue-codemirror6 0.0.4 → 0.1.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 +132 -15
- package/dist/components/CodeMirror.vue.d.ts +46 -8
- package/dist/components/CodeMirror.vue.d.ts.map +1 -1
- package/dist/vue-codemirror6.es.js +38 -912
- package/dist/vue-codemirror6.umd.js +3 -1
- package/package.json +35 -28
- package/src/components/CodeMirror.vue +111 -34
|
@@ -1 +1,3 @@
|
|
|
1
|
-
(function(l,g){typeof exports=="object"&&typeof module<"u"?module.exports=g(require("vue-property-decorator"),require("@codemirror/state"),require("@codemirror/view")):typeof define=="function"&&define.amd?define(["vue-property-decorator","@codemirror/state","@codemirror/view"],g):(l=typeof globalThis<"u"?globalThis:l||self,l.CodeMirror=g(l.vuePropertyDecorator,l.state,l.view))})(this,function(l,g,F){"use strict";var w=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function xe(){this.__data__=[],this.size=0}var Ie=xe;function Me(e,t){return e===t||e!==e&&t!==t}var P=Me,Ee=P;function Le(e,t){for(var r=e.length;r--;)if(Ee(e[r][0],t))return r;return-1}var x=Le,Ge=x,Fe=Array.prototype,De=Fe.splice;function Re(e){var t=this.__data__,r=Ge(t,e);if(r<0)return!1;var a=t.length-1;return r==a?t.pop():De.call(t,r,1),--this.size,!0}var Ue=Re,He=x;function Ne(e){var t=this.__data__,r=He(t,e);return r<0?void 0:t[r][1]}var Ve=Ne,Be=x;function ze(e){return Be(this.__data__,e)>-1}var Ke=ze,qe=x;function We(e,t){var r=this.__data__,a=qe(r,e);return a<0?(++this.size,r.push([e,t])):r[a][1]=t,this}var Xe=We,Je=Ie,ke=Ue,Ye=Ve,Ze=Ke,Qe=Xe;function y(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}y.prototype.clear=Je,y.prototype.delete=ke,y.prototype.get=Ye,y.prototype.has=Ze,y.prototype.set=Qe;var I=y,et=I;function tt(){this.__data__=new et,this.size=0}var rt=tt;function at(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}var nt=at;function it(e){return this.__data__.get(e)}var ot=it;function st(e){return this.__data__.has(e)}var ct=st,ft=typeof w=="object"&&w&&w.Object===Object&&w,K=ft,ut=K,lt=typeof self=="object"&&self&&self.Object===Object&&self,vt=ut||lt||Function("return this")(),b=vt,pt=b,ht=pt.Symbol,q=ht,W=q,X=Object.prototype,dt=X.hasOwnProperty,_t=X.toString,j=W?W.toStringTag:void 0;function gt(e){var t=dt.call(e,j),r=e[j];try{e[j]=void 0;var a=!0}catch{}var n=_t.call(e);return a&&(t?e[j]=r:delete e[j]),n}var $t=gt,yt=Object.prototype,bt=yt.toString;function Ot(e){return bt.call(e)}var Tt=Ot,J=q,Ct=$t,jt=Tt,mt="[object Null]",At="[object Undefined]",k=J?J.toStringTag:void 0;function St(e){return e==null?e===void 0?At:mt:k&&k in Object(e)?Ct(e):jt(e)}var M=St;function wt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var $=wt,Pt=M,xt=$,It="[object AsyncFunction]",Mt="[object Function]",Et="[object GeneratorFunction]",Lt="[object Proxy]";function Gt(e){if(!xt(e))return!1;var t=Pt(e);return t==Mt||t==Et||t==It||t==Lt}var D=Gt,Ft=b,Dt=Ft["__core-js_shared__"],Rt=Dt,R=Rt,Y=function(){var e=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Ut(e){return!!Y&&Y in e}var Ht=Ut,Nt=Function.prototype,Vt=Nt.toString;function Bt(e){if(e!=null){try{return Vt.call(e)}catch{}try{return e+""}catch{}}return""}var zt=Bt,Kt=D,qt=Ht,Wt=$,Xt=zt,Jt=/[\\^$.*+?()[\]{}|]/g,kt=/^\[object .+?Constructor\]$/,Yt=Function.prototype,Zt=Object.prototype,Qt=Yt.toString,er=Zt.hasOwnProperty,tr=RegExp("^"+Qt.call(er).replace(Jt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function rr(e){if(!Wt(e)||qt(e))return!1;var t=Kt(e)?tr:kt;return t.test(Xt(e))}var ar=rr;function nr(e,t){return e==null?void 0:e[t]}var ir=nr,or=ar,sr=ir;function cr(e,t){var r=sr(e,t);return or(r)?r:void 0}var U=cr,fr=U,ur=b,lr=fr(ur,"Map"),Z=lr,vr=U,pr=vr(Object,"create"),E=pr,Q=E;function hr(){this.__data__=Q?Q(null):{},this.size=0}var dr=hr;function _r(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var gr=_r,$r=E,yr="__lodash_hash_undefined__",br=Object.prototype,Or=br.hasOwnProperty;function Tr(e){var t=this.__data__;if($r){var r=t[e];return r===yr?void 0:r}return Or.call(t,e)?t[e]:void 0}var Cr=Tr,jr=E,mr=Object.prototype,Ar=mr.hasOwnProperty;function Sr(e){var t=this.__data__;return jr?t[e]!==void 0:Ar.call(t,e)}var wr=Sr,Pr=E,xr="__lodash_hash_undefined__";function Ir(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Pr&&t===void 0?xr:t,this}var Mr=Ir,Er=dr,Lr=gr,Gr=Cr,Fr=wr,Dr=Mr;function O(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}O.prototype.clear=Er,O.prototype.delete=Lr,O.prototype.get=Gr,O.prototype.has=Fr,O.prototype.set=Dr;var Rr=O,ee=Rr,Ur=I,Hr=Z;function Nr(){this.size=0,this.__data__={hash:new ee,map:new(Hr||Ur),string:new ee}}var Vr=Nr;function Br(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var zr=Br,Kr=zr;function qr(e,t){var r=e.__data__;return Kr(t)?r[typeof t=="string"?"string":"hash"]:r.map}var L=qr,Wr=L;function Xr(e){var t=Wr(this,e).delete(e);return this.size-=t?1:0,t}var Jr=Xr,kr=L;function Yr(e){return kr(this,e).get(e)}var Zr=Yr,Qr=L;function ea(e){return Qr(this,e).has(e)}var ta=ea,ra=L;function aa(e,t){var r=ra(this,e),a=r.size;return r.set(e,t),this.size+=r.size==a?0:1,this}var na=aa,ia=Vr,oa=Jr,sa=Zr,ca=ta,fa=na;function T(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var a=e[t];this.set(a[0],a[1])}}T.prototype.clear=ia,T.prototype.delete=oa,T.prototype.get=sa,T.prototype.has=ca,T.prototype.set=fa;var ua=T,la=I,va=Z,pa=ua,ha=200;function da(e,t){var r=this.__data__;if(r instanceof la){var a=r.__data__;if(!va||a.length<ha-1)return a.push([e,t]),this.size=++r.size,this;r=this.__data__=new pa(a)}return r.set(e,t),this.size=r.size,this}var _a=da,ga=I,$a=rt,ya=nt,ba=ot,Oa=ct,Ta=_a;function C(e){var t=this.__data__=new ga(e);this.size=t.size}C.prototype.clear=$a,C.prototype.delete=ya,C.prototype.get=ba,C.prototype.has=Oa,C.prototype.set=Ta;var Ca=C,ja=U,ma=function(){try{var e=ja(Object,"defineProperty");return e({},"",{}),e}catch{}}(),te=ma,re=te;function Aa(e,t,r){t=="__proto__"&&re?re(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}var H=Aa,Sa=H,wa=P;function Pa(e,t,r){(r!==void 0&&!wa(e[t],r)||r===void 0&&!(t in e))&&Sa(e,t,r)}var ae=Pa;function xa(e){return function(t,r,a){for(var n=-1,s=Object(t),c=a(t),o=c.length;o--;){var i=c[e?o:++n];if(r(s[i],i,s)===!1)break}return t}}var Ia=xa,Ma=Ia,Ea=Ma(),La=Ea,N={exports:{}};(function(e,t){var r=b,a=t&&!t.nodeType&&t,n=a&&!0&&e&&!e.nodeType&&e,s=n&&n.exports===a,c=s?r.Buffer:void 0,o=c?c.allocUnsafe:void 0;function i(f,v){if(v)return f.slice();var d=f.length,p=o?o(d):new f.constructor(d);return f.copy(p),p}e.exports=i})(N,N.exports);var Ga=b,Fa=Ga.Uint8Array,Da=Fa,ne=Da;function Ra(e){var t=new e.constructor(e.byteLength);return new ne(t).set(new ne(e)),t}var Ua=Ra,Ha=Ua;function Na(e,t){var r=t?Ha(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}var Va=Na;function Ba(e,t){var r=-1,a=e.length;for(t||(t=Array(a));++r<a;)t[r]=e[r];return t}var za=Ba,Ka=$,ie=Object.create,qa=function(){function e(){}return function(t){if(!Ka(t))return{};if(ie)return ie(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}(),Wa=qa;function Xa(e,t){return function(r){return e(t(r))}}var Ja=Xa,ka=Ja,Ya=ka(Object.getPrototypeOf,Object),oe=Ya,Za=Object.prototype;function Qa(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||Za;return e===r}var se=Qa,en=Wa,tn=oe,rn=se;function an(e){return typeof e.constructor=="function"&&!rn(e)?en(tn(e)):{}}var nn=an;function on(e){return e!=null&&typeof e=="object"}var m=on,sn=M,cn=m,fn="[object Arguments]";function un(e){return cn(e)&&sn(e)==fn}var ln=un,ce=ln,vn=m,fe=Object.prototype,pn=fe.hasOwnProperty,hn=fe.propertyIsEnumerable,dn=ce(function(){return arguments}())?ce:function(e){return vn(e)&&pn.call(e,"callee")&&!hn.call(e,"callee")},ue=dn,_n=Array.isArray,le=_n,gn=9007199254740991;function $n(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=gn}var ve=$n,yn=D,bn=ve;function On(e){return e!=null&&bn(e.length)&&!yn(e)}var V=On,Tn=V,Cn=m;function jn(e){return Cn(e)&&Tn(e)}var mn=jn,G={exports:{}};function An(){return!1}var Sn=An;(function(e,t){var r=b,a=Sn,n=t&&!t.nodeType&&t,s=n&&!0&&e&&!e.nodeType&&e,c=s&&s.exports===n,o=c?r.Buffer:void 0,i=o?o.isBuffer:void 0,f=i||a;e.exports=f})(G,G.exports);var wn=M,Pn=oe,xn=m,In="[object Object]",Mn=Function.prototype,En=Object.prototype,pe=Mn.toString,Ln=En.hasOwnProperty,Gn=pe.call(Object);function Fn(e){if(!xn(e)||wn(e)!=In)return!1;var t=Pn(e);if(t===null)return!0;var r=Ln.call(t,"constructor")&&t.constructor;return typeof r=="function"&&r instanceof r&&pe.call(r)==Gn}var Dn=Fn,Rn=M,Un=ve,Hn=m,Nn="[object Arguments]",Vn="[object Array]",Bn="[object Boolean]",zn="[object Date]",Kn="[object Error]",qn="[object Function]",Wn="[object Map]",Xn="[object Number]",Jn="[object Object]",kn="[object RegExp]",Yn="[object Set]",Zn="[object String]",Qn="[object WeakMap]",ei="[object ArrayBuffer]",ti="[object DataView]",ri="[object Float32Array]",ai="[object Float64Array]",ni="[object Int8Array]",ii="[object Int16Array]",oi="[object Int32Array]",si="[object Uint8Array]",ci="[object Uint8ClampedArray]",fi="[object Uint16Array]",ui="[object Uint32Array]",u={};u[ri]=u[ai]=u[ni]=u[ii]=u[oi]=u[si]=u[ci]=u[fi]=u[ui]=!0,u[Nn]=u[Vn]=u[ei]=u[Bn]=u[ti]=u[zn]=u[Kn]=u[qn]=u[Wn]=u[Xn]=u[Jn]=u[kn]=u[Yn]=u[Zn]=u[Qn]=!1;function li(e){return Hn(e)&&Un(e.length)&&!!u[Rn(e)]}var vi=li;function pi(e){return function(t){return e(t)}}var hi=pi,B={exports:{}};(function(e,t){var r=K,a=t&&!t.nodeType&&t,n=a&&!0&&e&&!e.nodeType&&e,s=n&&n.exports===a,c=s&&r.process,o=function(){try{var i=n&&n.require&&n.require("util").types;return i||c&&c.binding&&c.binding("util")}catch{}}();e.exports=o})(B,B.exports);var di=vi,_i=hi,he=B.exports,de=he&&he.isTypedArray,gi=de?_i(de):di,_e=gi;function $i(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}var ge=$i,yi=H,bi=P,Oi=Object.prototype,Ti=Oi.hasOwnProperty;function Ci(e,t,r){var a=e[t];(!(Ti.call(e,t)&&bi(a,r))||r===void 0&&!(t in e))&&yi(e,t,r)}var ji=Ci,mi=ji,Ai=H;function Si(e,t,r,a){var n=!r;r||(r={});for(var s=-1,c=t.length;++s<c;){var o=t[s],i=a?a(r[o],e[o],o,r,e):void 0;i===void 0&&(i=e[o]),n?Ai(r,o,i):mi(r,o,i)}return r}var wi=Si;function Pi(e,t){for(var r=-1,a=Array(e);++r<e;)a[r]=t(r);return a}var xi=Pi,Ii=9007199254740991,Mi=/^(?:0|[1-9]\d*)$/;function Ei(e,t){var r=typeof e;return t=t??Ii,!!t&&(r=="number"||r!="symbol"&&Mi.test(e))&&e>-1&&e%1==0&&e<t}var $e=Ei,Li=xi,Gi=ue,Fi=le,Di=G.exports,Ri=$e,Ui=_e,Hi=Object.prototype,Ni=Hi.hasOwnProperty;function Vi(e,t){var r=Fi(e),a=!r&&Gi(e),n=!r&&!a&&Di(e),s=!r&&!a&&!n&&Ui(e),c=r||a||n||s,o=c?Li(e.length,String):[],i=o.length;for(var f in e)(t||Ni.call(e,f))&&!(c&&(f=="length"||n&&(f=="offset"||f=="parent")||s&&(f=="buffer"||f=="byteLength"||f=="byteOffset")||Ri(f,i)))&&o.push(f);return o}var Bi=Vi;function zi(e){var t=[];if(e!=null)for(var r in Object(e))t.push(r);return t}var Ki=zi,qi=$,Wi=se,Xi=Ki,Ji=Object.prototype,ki=Ji.hasOwnProperty;function Yi(e){if(!qi(e))return Xi(e);var t=Wi(e),r=[];for(var a in e)a=="constructor"&&(t||!ki.call(e,a))||r.push(a);return r}var Zi=Yi,Qi=Bi,eo=Zi,to=V;function ro(e){return to(e)?Qi(e,!0):eo(e)}var ye=ro,ao=wi,no=ye;function io(e){return ao(e,no(e))}var oo=io,be=ae,so=N.exports,co=Va,fo=za,uo=nn,Oe=ue,Te=le,lo=mn,vo=G.exports,po=D,ho=$,_o=Dn,go=_e,Ce=ge,$o=oo;function yo(e,t,r,a,n,s,c){var o=Ce(e,r),i=Ce(t,r),f=c.get(i);if(f){be(e,r,f);return}var v=s?s(o,i,r+"",e,t,c):void 0,d=v===void 0;if(d){var p=Te(i),A=!p&&vo(i),S=!p&&!A&&go(i);v=i,p||A||S?Te(o)?v=o:lo(o)?v=fo(o):A?(d=!1,v=so(i,!0)):S?(d=!1,v=co(i,!0)):v=[]:_o(i)||Oe(i)?(v=o,Oe(o)?v=$o(o):(!ho(o)||po(o))&&(v=uo(i))):d=!1}d&&(c.set(i,v),n(v,i,a,s,c),c.delete(i)),be(e,r,v)}var bo=yo,Oo=Ca,To=ae,Co=La,jo=bo,mo=$,Ao=ye,So=ge;function je(e,t,r,a,n){e!==t&&Co(t,function(s,c){if(n||(n=new Oo),mo(s))jo(e,t,c,r,je,a,n);else{var o=a?a(So(e,c),s,c+"",e,t,n):void 0;o===void 0&&(o=s),To(e,c,o)}},Ao)}var wo=je;function Po(e){return e}var me=Po;function xo(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}var Io=xo,Mo=Io,Ae=Math.max;function Eo(e,t,r){return t=Ae(t===void 0?e.length-1:t,0),function(){for(var a=arguments,n=-1,s=Ae(a.length-t,0),c=Array(s);++n<s;)c[n]=a[t+n];n=-1;for(var o=Array(t+1);++n<t;)o[n]=a[n];return o[t]=r(c),Mo(e,this,o)}}var Lo=Eo;function Go(e){return function(){return e}}var Fo=Go,Do=Fo,Se=te,Ro=me,Uo=Se?function(e,t){return Se(e,"toString",{configurable:!0,enumerable:!1,value:Do(t),writable:!0})}:Ro,Ho=Uo,No=800,Vo=16,Bo=Date.now;function zo(e){var t=0,r=0;return function(){var a=Bo(),n=Vo-(a-r);if(r=a,n>0){if(++t>=No)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var Ko=zo,qo=Ho,Wo=Ko,Xo=Wo(qo),Jo=Xo,ko=me,Yo=Lo,Zo=Jo;function Qo(e,t){return Zo(Yo(e,t,ko),e+"")}var es=Qo,ts=P,rs=V,as=$e,ns=$;function is(e,t,r){if(!ns(r))return!1;var a=typeof t;return(a=="number"?rs(r)&&as(t,r.length):a=="string"&&t in r)?ts(r[t],e):!1}var os=is,ss=es,cs=os;function fs(e){return ss(function(t,r){var a=-1,n=r.length,s=n>1?r[n-1]:void 0,c=n>2?r[2]:void 0;for(s=e.length>3&&typeof s=="function"?(n--,s):void 0,c&&cs(r[0],r[1],c)&&(s=n<3?void 0:s,n=1),t=Object(t);++a<n;){var o=r[a];o&&e(t,o,a,s)}return t})}var us=fs,ls=wo,vs=us,ps=vs(function(e,t,r){ls(e,t,r)}),we=ps,hs=Object.defineProperty,ds=Object.getOwnPropertyDescriptor,_=(e,t,r,a)=>{for(var n=a>1?void 0:a?ds(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(n=(a?c(t,r,n):c(n))||n);return a&&n&&hs(t,r,n),n};let h=class extends l.Vue{onValueChanged(){this.editor.dispatch({changes:{from:0,to:this.editor.state.doc.length,insert:this.value}})}onToggleDarkMode(){this.editor.setState(g.EditorState.create({doc:this.value,extensions:this.extension}))}get extension(){const e=[F.EditorView.updateListener.of(t=>this.$emit("update",t)),F.EditorView.theme(this.theme,{dark:this.dark})];return this.phrases&&e.push(g.EditorState.phrases.of(this.phrases)),this.lang&&e.push(this.lang),this.linter.length!==0&&we(e,this.linter),this.extensions.length!==0&&we(e,this.extensions),e}mounted(){this.editor=new F.EditorView({state:g.EditorState.create({doc:this.value,extensions:this.extension}),parent:this.$refs.editor,dispatch:e=>{this.editor.update([e]),!e.changes.empty&&this.$emit("input",this.editor.state.doc.toString())}})}beforeDestroy(){this.editor.destroy()}};_([l.Prop({type:Object,default:()=>{}})],h.prototype,"theme",2),_([l.Prop({type:Boolean,default:!1})],h.prototype,"dark",2),_([l.Prop({type:Object})],h.prototype,"phrases",2),_([l.Prop({type:Array,default:()=>[]})],h.prototype,"extensions",2),_([l.Prop({type:Object})],h.prototype,"lang",2),_([l.Prop({type:Array,default:()=>[]})],h.prototype,"linter",2),_([l.Prop({type:String,required:!0})],h.prototype,"value",2),_([l.Watch("value")],h.prototype,"onValueChanged",1),_([l.Watch("dark")],h.prototype,"onToggleDarkMode",1),h=_([l.Component({name:"CodeMirror"})],h);var _s=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",{ref:"editor"})},gs=[];function $s(e,t,r,a,n,s,c,o){var i=typeof e=="function"?e.options:e;t&&(i.render=t,i.staticRenderFns=r,i._compiled=!0),a&&(i.functional=!0),s&&(i._scopeId="data-v-"+s);var f;if(c?(f=function(p){p=p||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!p&&typeof __VUE_SSR_CONTEXT__<"u"&&(p=__VUE_SSR_CONTEXT__),n&&n.call(this,p),p&&p._registeredComponents&&p._registeredComponents.add(c)},i._ssrRegister=f):n&&(f=o?function(){n.call(this,(i.functional?this.parent:this).$root.$options.shadowRoot)}:n),f)if(i.functional){i._injectStyles=f;var v=i.render;i.render=function(A,S){return f.call(S),v(A,S)}}else{var d=i.beforeCreate;i.beforeCreate=d?[].concat(d,f):[f]}return{exports:e,options:i}}const Pe={};var ys=$s(h,_s,gs,!1,bs,null,null,null);function bs(e){for(let t in Pe)this[t]=Pe[t]}var Os=function(){return ys.exports}(),z=(()=>{const e=Os;return e.install=t=>{t.component("CodeMirror",e)},e})(),Ts=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",default:z});return Object.entries(Ts).forEach(([e,t])=>{e!=="default"&&(z[e]=t)}),z});
|
|
1
|
+
(function(i,d){typeof exports=="object"&&typeof module<"u"?module.exports=d(require("vue-property-decorator"),require("@codemirror/state"),require("@codemirror/view"),require("lodash")):typeof define=="function"&&define.amd?define(["vue-property-decorator","@codemirror/state","@codemirror/view","lodash"],d):(i=typeof globalThis<"u"?globalThis:i||self,i.CodeMirror=d(i.vuePropertyDecorator,i.state,i.view,i.lodash))})(this,function(i,d,c,_){"use strict";var g=Object.defineProperty,b=Object.getOwnPropertyDescriptor,s=(e,t,p,f)=>{for(var r=f>1?void 0:f?b(t,p):t,h=e.length-1,u;h>=0;h--)(u=e[h])&&(r=(f?u(t,p,r):u(r))||r);return f&&r&&g(t,p,r),r};let o=class extends i.Vue{onValueChanged(){if(this.editor.composing)return;const e=this.editor.state.selection;this.editor.setState(d.EditorState.create({doc:this.value,extensions:this.extension,selection:e}))}onToggleDarkMode(){this.editor.setState(d.EditorState.create({doc:this.value,extensions:this.extension}))}get extension(){const e=_.compact([c.EditorView.updateListener.of(t=>this.$emit("update",t)),c.EditorView.theme(this.theme,{dark:this.dark}),this.phrases?d.EditorState.phrases.of(this.phrases):void 0,this.lang?this.lang:void 0,d.EditorState.readOnly.of(this.readonly),c.EditorView.editable.of(this.editable)]);return this.linter.length!==0&&_.merge(e,this.linter),this.extensions.length!==0&&_.merge(e,this.extensions),console.debug("[CodeMirror.vue] Loaded extensions:",e),e}mounted(){let e=this.value;!this.value&&this.$slots.default!==void 0&&(e=this.getChildrenTextContent(this.$slots.default)),this.editor=new c.EditorView({state:d.EditorState.create({doc:e,extensions:this.extension}),parent:this.$refs.editor,dispatch:t=>{this.editor.update([t]),!t.changes.empty&&this.$emit("input",this.editor.state.doc.toString())}})}beforeDestroy(){this.editor.destroy()}getChildrenTextContent(e){return e.map(t=>t.children?this.getChildrenTextContent(t.children):t.text||`
|
|
2
|
+
`).join("")}};s([i.Prop({type:Object,default:()=>{}})],o.prototype,"theme",2),s([i.Prop({type:Boolean,default:!1})],o.prototype,"dark",2),s([i.Prop({type:Boolean,default:!1})],o.prototype,"readonly",2),s([i.Prop({type:Boolean,default:!0})],o.prototype,"editable",2),s([i.Prop({type:Object})],o.prototype,"phrases",2),s([i.Prop({type:Array,default:()=>[]})],o.prototype,"extensions",2),s([i.Prop({type:Object})],o.prototype,"lang",2),s([i.Prop({type:Array,default:()=>[]})],o.prototype,"linter",2),s([i.Prop({type:String,default:""})],o.prototype,"value",2),s([i.Watch("value")],o.prototype,"onValueChanged",1),s([i.Watch("dark")],o.prototype,"onToggleDarkMode",1),o=s([i.Component({name:"CodeMirror"})],o);var S=function(){var e=this,t=e.$createElement,p=e._self._c||t;return p("pre",{ref:"editor"},[e._v(" "),e.$slots.default?e._e():[e._t("default")],e._v(`
|
|
3
|
+
`)],2)},$=[];function E(e,t,p,f,r,h,u,M){var n=typeof e=="function"?e.options:e;t&&(n.render=t,n.staticRenderFns=p,n._compiled=!0),f&&(n.functional=!0),h&&(n._scopeId="data-v-"+h);var l;if(u?(l=function(a){a=a||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!a&&typeof __VUE_SSR_CONTEXT__<"u"&&(a=__VUE_SSR_CONTEXT__),r&&r.call(this,a),a&&a._registeredComponents&&a._registeredComponents.add(u)},n._ssrRegister=l):r&&(l=M?function(){r.call(this,(n.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(n.functional){n._injectStyles=l;var V=n.render;n.render=function(w,C){return l.call(C),V(w,C)}}else{var y=n.beforeCreate;n.beforeCreate=y?[].concat(y,l):[l]}return{exports:e,options:n}}const v={};var O=E(o,S,$,!1,x,null,null,null);function x(e){for(let t in v)this[t]=v[t]}var T=function(){return O.exports}(),m=(()=>{const e=T;return e.install=t=>{t.component("CodeMirror",e)},e})(),j=Object.freeze(Object.defineProperty({__proto__:null,default:m},Symbol.toStringTag,{value:"Module"}));return Object.entries(j).forEach(([e,t])=>{e!=="default"&&(m[e]=t)}),m});
|
package/package.json
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "vue-codemirror6",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "CodeMirror6 Component for vue2",
|
|
6
6
|
"keywords": [
|
|
7
|
-
"
|
|
8
|
-
"vue
|
|
9
|
-
"
|
|
10
|
-
"vue"
|
|
7
|
+
"vuejs",
|
|
8
|
+
"vue",
|
|
9
|
+
"vue-components",
|
|
10
|
+
"vue-codemirror",
|
|
11
|
+
"code-editor",
|
|
12
|
+
"text-editor",
|
|
13
|
+
"vue2",
|
|
14
|
+
"web-editor",
|
|
15
|
+
"vue-plugin",
|
|
16
|
+
"vue-component",
|
|
17
|
+
"codemirror-editor",
|
|
18
|
+
"vue-resource",
|
|
19
|
+
"codemirror6"
|
|
11
20
|
],
|
|
12
21
|
"author": {
|
|
13
22
|
"name": "Logue",
|
|
@@ -48,52 +57,53 @@
|
|
|
48
57
|
"build": "vite build & vue-tsc",
|
|
49
58
|
"build:clean": "rimraf dist",
|
|
50
59
|
"lint": "eslint . --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint && prettier . --write",
|
|
60
|
+
"lint:markup": "vue-tsc --noEmit",
|
|
51
61
|
"prepare": "husky install"
|
|
52
62
|
},
|
|
53
63
|
"dependencies": {
|
|
54
64
|
"@codemirror/basic-setup": "^0.19.1",
|
|
55
65
|
"@codemirror/lang-markdown": "^0.19.6",
|
|
56
|
-
"@codemirror/language": "^0.19.
|
|
57
|
-
"@codemirror/lint": "^0.19.
|
|
58
|
-
"@codemirror/view": "^0.19.
|
|
66
|
+
"@codemirror/language": "^0.19.8",
|
|
67
|
+
"@codemirror/lint": "^0.19.6",
|
|
68
|
+
"@codemirror/view": "^0.19.47",
|
|
59
69
|
"lodash": "^4.17.21",
|
|
60
70
|
"vue": "^2.6.14",
|
|
61
71
|
"vue-class-component": "^7.2.6",
|
|
62
72
|
"vue-property-decorator": "^9.1.2"
|
|
63
73
|
},
|
|
64
74
|
"devDependencies": {
|
|
65
|
-
"@types/lodash": "^4.14.
|
|
66
|
-
"@types/node": "^17.0.
|
|
67
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
68
|
-
"@typescript-eslint/parser": "^5.
|
|
75
|
+
"@types/lodash": "^4.14.180",
|
|
76
|
+
"@types/node": "^17.0.21",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
|
78
|
+
"@typescript-eslint/parser": "^5.15.0",
|
|
69
79
|
"@vue/compiler-sfc": "^3.2.31",
|
|
70
80
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
71
|
-
"eslint": "^8.
|
|
81
|
+
"eslint": "^8.11.0",
|
|
72
82
|
"eslint-config-google": "^0.14.0",
|
|
73
|
-
"eslint-config-prettier": "^8.
|
|
83
|
+
"eslint-config-prettier": "^8.5.0",
|
|
74
84
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
75
85
|
"eslint-import-resolver-typescript": "^2.5.0",
|
|
76
86
|
"eslint-plugin-import": "^2.25.4",
|
|
77
87
|
"eslint-plugin-prettier": "^4.0.0",
|
|
78
88
|
"eslint-plugin-prettier-vue": "^3.1.0",
|
|
79
89
|
"eslint-plugin-tsdoc": "^0.2.14",
|
|
80
|
-
"eslint-plugin-vue": "^8.
|
|
90
|
+
"eslint-plugin-vue": "^8.5.0",
|
|
81
91
|
"eslint-plugin-vuejs-accessibility": "^1.1.1",
|
|
82
92
|
"husky": "^7.0.4",
|
|
83
|
-
"lint-staged": "^12.3.
|
|
84
|
-
"prettier": "^2.
|
|
85
|
-
"prettier-plugin-jsdoc": "^0.3.
|
|
93
|
+
"lint-staged": "^12.3.7",
|
|
94
|
+
"prettier": "^2.6.0",
|
|
95
|
+
"prettier-plugin-jsdoc": "^0.3.31",
|
|
86
96
|
"prettier-plugin-md-nocjsp": "^1.2.0",
|
|
87
|
-
"prettier-plugin-sort-imports": "^1.
|
|
97
|
+
"prettier-plugin-sort-imports": "^1.6.0",
|
|
88
98
|
"rimraf": "^3.0.2",
|
|
89
|
-
"typescript": "
|
|
90
|
-
"vite": "^2.8.
|
|
99
|
+
"typescript": ">=3.3.1 <4.6.0",
|
|
100
|
+
"vite": "^2.8.6",
|
|
91
101
|
"vite-dts": "^1.0.4",
|
|
92
102
|
"vite-plugin-eslint": "^1.3.0",
|
|
93
103
|
"vite-plugin-vue2": "^1.9.3",
|
|
94
|
-
"vue-eslint-parser": "^8.
|
|
104
|
+
"vue-eslint-parser": "^8.3.0",
|
|
95
105
|
"vue-template-compiler": "^2.6.14",
|
|
96
|
-
"vue-tsc": "^0.
|
|
106
|
+
"vue-tsc": "^0.33.2"
|
|
97
107
|
},
|
|
98
108
|
"husky": {
|
|
99
109
|
"hooks": {
|
|
@@ -101,10 +111,7 @@
|
|
|
101
111
|
}
|
|
102
112
|
},
|
|
103
113
|
"lint-staged": {
|
|
104
|
-
"*.{
|
|
105
|
-
"eslint --fix --cache"
|
|
106
|
-
],
|
|
107
|
-
"*.{js,ts,json,yml,yaml,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
114
|
+
"*.{js,ts,json,htm,html}": "eslint --fix --cache --cache-location ./node_modules/.vite/vite-plugin-eslint",
|
|
108
115
|
"*": "prettier -w -u"
|
|
109
116
|
}
|
|
110
117
|
}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<pre ref="editor">
|
|
3
|
+
<template v-if="!$slots.default"><slot /></template>
|
|
4
|
+
</pre>
|
|
3
5
|
</template>
|
|
4
6
|
|
|
5
7
|
<script lang="ts">
|
|
6
8
|
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
import type { VNode } from 'vue';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
EditorState,
|
|
13
|
+
type Extension,
|
|
14
|
+
type Transaction,
|
|
15
|
+
} from '@codemirror/state';
|
|
16
|
+
import { EditorView, type ViewUpdate } from '@codemirror/view';
|
|
9
17
|
import type { LanguageSupport } from '@codemirror/language';
|
|
10
|
-
import type { ViewUpdate } from '@codemirror/view';
|
|
11
18
|
import type { Diagnostic } from '@codemirror/lint';
|
|
12
|
-
import { EditorState } from '@codemirror/state';
|
|
13
|
-
import { EditorView } from '@codemirror/view';
|
|
14
19
|
import type { StyleSpec } from 'style-mod';
|
|
15
|
-
|
|
20
|
+
|
|
21
|
+
import { compact, merge } from 'lodash';
|
|
16
22
|
|
|
17
23
|
@Component({ name: 'CodeMirror' })
|
|
18
24
|
/** CodeMirror Component */
|
|
@@ -20,7 +26,11 @@ export default class CodeMirror extends Vue {
|
|
|
20
26
|
/** Editor */
|
|
21
27
|
private editor!: EditorView;
|
|
22
28
|
|
|
23
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Theme
|
|
31
|
+
*
|
|
32
|
+
* @see {@link https://codemirror.net/6/examples/styling/ | Example: Styling}
|
|
33
|
+
*/
|
|
24
34
|
@Prop({ type: Object, default: () => {} })
|
|
25
35
|
readonly theme!: { [selector: string]: StyleSpec };
|
|
26
36
|
|
|
@@ -28,39 +38,81 @@ export default class CodeMirror extends Vue {
|
|
|
28
38
|
@Prop({ type: Boolean, default: false })
|
|
29
39
|
readonly dark!: boolean;
|
|
30
40
|
|
|
31
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Readonly
|
|
43
|
+
*
|
|
44
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.EditorState%5EreadOnly | readOnly}
|
|
45
|
+
*/
|
|
46
|
+
@Prop({ type: Boolean, default: false })
|
|
47
|
+
readonly readonly!: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Editable
|
|
51
|
+
*
|
|
52
|
+
* @see {@link https://codemirror.net/6/docs/ref/#view.EditorView%5Eeditable | editable}
|
|
53
|
+
*/
|
|
54
|
+
@Prop({ type: Boolean, default: true })
|
|
55
|
+
readonly editable!: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Language Phreses
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://codemirror.net/6/examples/translate/ | Example: Internationalization}
|
|
61
|
+
*/
|
|
32
62
|
@Prop({ type: Object })
|
|
33
63
|
readonly phrases!: Record<string, string>;
|
|
34
64
|
|
|
35
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Additional Extension
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://codemirror.net/6/docs/ref/#state.Extension | Extending Editor State}
|
|
69
|
+
*/
|
|
36
70
|
@Prop({ type: Array, default: () => [] })
|
|
37
71
|
readonly extensions!: Extension[];
|
|
38
72
|
|
|
39
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* CodeMirror Language
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://codemirror.net/6/docs/ref/#language | @codemirror/language}
|
|
77
|
+
*/
|
|
40
78
|
@Prop({ type: Object })
|
|
41
79
|
readonly lang!: LanguageSupport;
|
|
42
80
|
|
|
43
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* CodeMirror Linter
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://codemirror.net/6/docs/ref/#lint | @codemirror/lint}
|
|
85
|
+
*/
|
|
44
86
|
@Prop({ type: Array, default: () => [] })
|
|
45
87
|
readonly linter!: Diagnostic[];
|
|
46
88
|
|
|
47
89
|
/** Input */
|
|
48
|
-
@Prop({ type: String,
|
|
90
|
+
@Prop({ type: String, default: '' })
|
|
49
91
|
readonly value!: string;
|
|
50
92
|
|
|
51
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Input value changed
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://codemirror.net/6/docs/migration/#making-changes | Making Changes}
|
|
97
|
+
*/
|
|
52
98
|
@Watch('value')
|
|
53
99
|
onValueChanged() {
|
|
54
|
-
this.editor.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
100
|
+
if (this.editor.composing) {
|
|
101
|
+
// IME fix
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
/** Previous cursor location */
|
|
105
|
+
const previous = this.editor.state.selection;
|
|
106
|
+
this.editor.setState(
|
|
107
|
+
EditorState.create({
|
|
108
|
+
doc: this.value,
|
|
109
|
+
extensions: this.extension,
|
|
110
|
+
selection: previous,
|
|
111
|
+
})
|
|
112
|
+
);
|
|
61
113
|
}
|
|
62
114
|
|
|
63
|
-
/**
|
|
115
|
+
/** Toggle Dark mode */
|
|
64
116
|
@Watch('dark')
|
|
65
117
|
onToggleDarkMode() {
|
|
66
118
|
this.editor.setState(
|
|
@@ -74,37 +126,51 @@ export default class CodeMirror extends Vue {
|
|
|
74
126
|
/** CodeMirror Extension */
|
|
75
127
|
get extension(): Extension[] {
|
|
76
128
|
/** Default extension */
|
|
77
|
-
const ext = [
|
|
129
|
+
const ext: Extension[] = compact([
|
|
130
|
+
// ViewUpdate event listener
|
|
78
131
|
EditorView.updateListener.of((update: ViewUpdate) =>
|
|
79
132
|
this.$emit('update', update)
|
|
80
133
|
),
|
|
134
|
+
// Toggle light/dark mode.
|
|
81
135
|
EditorView.theme(this.theme, { dark: this.dark }),
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
136
|
+
// locale settings
|
|
137
|
+
this.phrases ? EditorState.phrases.of(this.phrases) : undefined,
|
|
138
|
+
// Parser language setting
|
|
139
|
+
this.lang ? this.lang : undefined,
|
|
140
|
+
// Readonly option
|
|
141
|
+
EditorState.readOnly.of(this.readonly),
|
|
142
|
+
// Editable option
|
|
143
|
+
EditorView.editable.of(this.editable),
|
|
144
|
+
]);
|
|
91
145
|
|
|
92
146
|
if (this.linter.length !== 0) {
|
|
147
|
+
// Append Linter settings
|
|
93
148
|
merge(ext, this.linter);
|
|
94
149
|
}
|
|
95
150
|
|
|
96
151
|
if (this.extensions.length !== 0) {
|
|
152
|
+
// Append Extensions (such as basic-setup)
|
|
97
153
|
merge(ext, this.extensions);
|
|
98
154
|
}
|
|
155
|
+
|
|
156
|
+
console.debug('[CodeMirror.vue] Loaded extensions:', ext);
|
|
157
|
+
|
|
99
158
|
return ext;
|
|
100
159
|
}
|
|
101
160
|
|
|
102
161
|
/** When loaded */
|
|
103
162
|
mounted() {
|
|
163
|
+
let value = this.value;
|
|
164
|
+
if (!this.value && this.$slots.default !== undefined) {
|
|
165
|
+
// override text node
|
|
166
|
+
// console.log(this.$slots.default);
|
|
167
|
+
value = this.getChildrenTextContent(this.$slots.default);
|
|
168
|
+
}
|
|
169
|
+
|
|
104
170
|
// Register Codemirror
|
|
105
171
|
this.editor = new EditorView({
|
|
106
172
|
state: EditorState.create({
|
|
107
|
-
doc:
|
|
173
|
+
doc: value,
|
|
108
174
|
extensions: this.extension,
|
|
109
175
|
}),
|
|
110
176
|
parent: this.$refs.editor as Element,
|
|
@@ -112,7 +178,7 @@ export default class CodeMirror extends Vue {
|
|
|
112
178
|
this.editor.update([tr]);
|
|
113
179
|
|
|
114
180
|
if (tr.changes.empty) return;
|
|
115
|
-
//
|
|
181
|
+
// to parent binding
|
|
116
182
|
this.$emit('input', this.editor.state.doc.toString());
|
|
117
183
|
},
|
|
118
184
|
});
|
|
@@ -122,5 +188,16 @@ export default class CodeMirror extends Vue {
|
|
|
122
188
|
beforeDestroy() {
|
|
123
189
|
this.editor.destroy();
|
|
124
190
|
}
|
|
191
|
+
|
|
192
|
+
/** Vue node to plain text */
|
|
193
|
+
private getChildrenTextContent(children: VNode[]): string {
|
|
194
|
+
return children
|
|
195
|
+
.map((node: VNode) =>
|
|
196
|
+
node.children
|
|
197
|
+
? this.getChildrenTextContent(node.children)
|
|
198
|
+
: node.text || '\n'
|
|
199
|
+
)
|
|
200
|
+
.join('');
|
|
201
|
+
}
|
|
125
202
|
}
|
|
126
203
|
</script>
|