UNPKG

@aegenet/au2-code-mirror

Version:

DRAFT - Aurelia 2 - CodeMirror (6) plugin

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