UNPKG

@aegenet/au2-code-mirror

Version:

DRAFT - Aurelia 2 - CodeMirror (6) plugin

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