UNPKG

prism-code-editor

Version:

Lightweight, extensible code editor component for the web using Prism

65 lines (64 loc) 2.01 kB
import { g as getElement, c as createEditor, d as doc } from "../index-CKRNGLIi.js"; import { loadTheme } from "../themes/index.js"; const addStyles = (shadow, styles, id) => { let style = shadow.getElementById(id); if (!style) { style = doc.createElement("style"); style.id = id; shadow.append(style); } style.textContent = styles; }; const minimalEditor = (container, options, onLoad) => { const el = getElement(container); const shadow = el.shadowRoot || el.attachShadow({ mode: "open" }); const editor = createEditor(null, null, { update(_, options2) { if (theme != (theme = options2.theme)) loadTheme(theme).then((style) => { if (style && theme == options2.theme) addStyles(shadow, style, "theme"); }); } }); const remove = editor.remove; let removed; let theme = options.theme; editor.remove = () => { remove(); removed = true; }; Promise.all([import("../styles-pBF7Jo4d.js"), loadTheme(options.theme)]).then(([style, theme2]) => { if (!removed) { addStyles(shadow, style.default, "layout-style"); addStyles(shadow, theme2 || "", "theme"); shadow.append(editor.container); editor.setOptions(options); onLoad && onLoad(); } }); return editor; }; const basicEditor = (container, options, onLoad) => { import("../basic-CTpZlE3m.js").then((mod) => { addStyles(el.shadowRoot, mod.style, "search-style"); editor.addExtensions(...mod.basic()); }); const el = getElement(container); const editor = minimalEditor(el, options, onLoad); return editor; }; const readonlyEditor = (container, options, onLoad) => { import("../readonly-BqQCfSe6.js").then((mod) => { mod.addExtensions(editor); addStyles(el.shadowRoot, mod.style, "readonly-style"); }); const el = getElement(container); const editor = minimalEditor(el, options, onLoad); return editor; }; export { basicEditor, minimalEditor, readonlyEditor }; //# sourceMappingURL=index.js.map