UNPKG

@hey-web-components/monaco-editor

Version:
76 lines (75 loc) 2.56 kB
import { property as r, customElement as f } from "lit/decorators.js"; import { createRef as g } from "lit/directives/ref.js"; import { E as u } from "./editor-base-BMfCY17L.js"; var h = Object.defineProperty, m = Object.getOwnPropertyDescriptor, o = (i, d, s, a) => { for (var e = a > 1 ? void 0 : a ? m(d, s) : d, n = i.length - 1, l; n >= 0; n--) (l = i[n]) && (e = (a ? l(d, s, e) : l(e)) || e); return a && e && h(d, s, e), e; }; let t = class extends u { constructor() { super(...arguments), this.PROPERTY_CHANGE_HANDLER_DICT = { original: (i) => { i !== this.originalModel?.getValue() && this.originalModel?.setValue(i ?? ""); }, originalLanguage: (i) => { this.originalModel && this.monaco?.editor.setModelLanguage(this.originalModel, i ?? ""); }, modified: (i) => { i !== this.modifiedModel?.getValue() && this.modifiedModel?.setValue(i ?? ""); }, modifiedLanguage: (i) => { this.modifiedModel && this.monaco?.editor.setModelLanguage(this.modifiedModel, i ?? ""); }, options: (i) => this.editor?.updateOptions(i ?? {}) }, this.editorContainerRef = g(); } async loadEditor(i) { i && (this.originalModel = this.monaco?.editor.createModel( this.original ?? "", this.originalLanguage ), this.modifiedModel = this.monaco?.editor.createModel( this.modified ?? "", this.modifiedLanguage ), this.editor = this.monaco?.editor.createDiffEditor(i, { automaticLayout: !0, fontLigatures: "" // TODO This is temporary fix for the incorrect cursor position }), this.originalModel && this.modifiedModel && this.editor?.setModel({ original: this.originalModel, modified: this.modifiedModel }), this.editor?.updateOptions(this.options ?? {})); } defineEvents() { super.defineEvents(), this.editor?.onDidUpdateDiff(() => { this.dispatchEvent( new CustomEvent("didUpdateDiff", { bubbles: !0, composed: !0, cancelable: !0 }) ); }); } }; o([ r({ attribute: "original", reflect: !0 }) ], t.prototype, "original", 2); o([ r({ attribute: "original-language", reflect: !0 }) ], t.prototype, "originalLanguage", 2); o([ r({ attribute: "modified", reflect: !0 }) ], t.prototype, "modified", 2); o([ r({ attribute: "modified-language", reflect: !0 }) ], t.prototype, "modifiedLanguage", 2); o([ r() ], t.prototype, "options", 2); t = o([ f("hey-monaco-diff-editor") ], t); export { t as HeyMonacoDiffEditor };