UNPKG

@aegenet/au2-code-mirror

Version:

DRAFT - Aurelia 2 - CodeMirror (6) plugin

3 lines (2 loc) 3.06 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("aurelia"),J=require("@codemirror/state"),q=require("codemirror"),L=require("@codemirror/lang-json"),N="",B='<div ref="codeArea" style="height: auto;"></div>';var K=Object.create,O=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,R=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),f=e=>{throw TypeError(e)},j=(e,t,r)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,I=(e,t)=>O(e,"name",{value:t,configurable:!0}),U=e=>[,,,K(null)],D=["class","method","getter","setter","accessor","field","value","get","set"],p=e=>e!==void 0&&typeof e!="function"?f("Function expected"):e,W=(e,t,r,n,o)=>({kind:D[e],name:t,metadata:n,addInitializer:s=>r._?f("Already initialized"):o.push(p(s||null))}),X=(e,t)=>j(t,R("metadata"),e[3]),E=(e,t,r,n)=>{for(var o=0,s=e[t>>1],l=s&&s.length;o<l;o++)t&1?s[o].call(r):n=s[o].call(r,n);return n},k=(e,t,r,n,o,s)=>{var l,d,A,v,M,i=t&7,g=!!(t&8),_=!!(t&16),C=i>3?e.length+1:i?g?1:2:0,P=D[i+5],z=i>3&&(e[C-1]=[]),H=e[C]||(e[C]=[]),a=i&&(!_&&!g&&(o=o.prototype),i<5&&(i>3||!_)&&Q(i<4?o:{get[r](){return F(this,s)},set[r](c){return T(this,s,c)}},r));i?_&&i<4&&I(s,(i>2?"set ":i>1?"get ":"")+r):I(o,r);for(var m=n.length-1;m>=0;m--)v=W(i,r,A={},e[3],H),i&&(v.static=g,v.private=_,M=v.access={has:_?c=>Y(o,c):c=>r in c},i^3&&(M.get=_?c=>(i^1?F:Z)(c,o,i^4?s:a.get):c=>c[r]),i>2&&(M.set=_?(c,y)=>T(c,o,y,i^4?s:a.set):(c,y)=>c[r]=y)),d=(0,n[m])(i?i<4?_?s:a[P]:i>4?void 0:{get:a.get,set:a.set}:o,v),A._=1,i^4||d===void 0?p(d)&&(i>4?z.unshift(d):i?_?s=d:a[P]=d:o=d):typeof d!="object"||d===null?f("Object expected"):(p(l=d.get)&&(a.get=l),p(l=d.set)&&(a.set=l),p(l=d.init)&&z.unshift(l));return i||X(e,o),a&&O(o,r,a),_?i^4?s:a:o},b=(e,t,r)=>j(e,typeof t!="symbol"?t+"":t,r),w=(e,t,r)=>t.has(e)||f("Cannot "+r),Y=(e,t)=>Object(t)!==t?f('Cannot use the "in" operator on this value'):e.has(t),F=(e,t,r)=>(w(e,t,"read from private field"),r?r.call(e):t.get(e)),T=(e,t,r,n)=>(w(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),Z=(e,t,r)=>(w(e,t,"access private method"),r),x,G,h;G=[S.inject(HTMLElement),S.customElement({name:"code-mirror",template:B})],x=[S.bindable()];class u{constructor(t){this._element=t,b(this,"_codeMirror"),b(this,"codeArea"),b(this,"code",E(h,8,this)),E(h,11,this);const r=document.createElement("style");r.textContent=N,this._element.appendChild(r)}attached(){const t=this.code;this._codeMirror=new q.EditorView({state:J.EditorState.create({doc:t,extensions:[q.basicSetup,L.json()]}),parent:this.codeArea})}codeChanged(t,r){t!==r&&t!==this._codeMirror.state.doc.toString()&&(this._codeMirror.dispatch({changes:{from:0,to:this._codeMirror.state.doc.length,insert:t}}),this._setCursorAtEnd())}_setCursorAtEnd(){this._codeMirror.dispatch({selection:{anchor:this._codeMirror.state.doc.lines}})}detaching(){this._codeMirror&&(this._codeMirror.destroy(),this._codeMirror=void 0)}}h=U();k(h,5,"code",x,u);u=k(h,0,"CodeMirror",G,u);E(h,1,u);exports.CodeMirror=u; //# sourceMappingURL=index.cjs.map