import { FolkShape } from "./folk-shape"; import { css, html } from "./tags"; const styles = css` :host { background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); min-width: 200px; min-height: 100px; } .header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: #14b8a6; color: white; border-radius: 8px 8px 0 0; font-size: 12px; font-weight: 600; cursor: move; } .header-title { display: flex; align-items: center; gap: 6px; } .header-actions { display: flex; gap: 4px; } .header-actions button { background: transparent; border: none; color: white; cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 14px; } .header-actions button:hover { background: rgba(255, 255, 255, 0.2); } .content { padding: 12px; height: calc(100% - 36px); overflow: auto; } .editor { width: 100%; height: 100%; border: none; outline: none; resize: none; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; line-height: 1.5; } .markdown-preview { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px; line-height: 1.6; } .markdown-preview h1 { font-size: 1.5em; margin: 0 0 0.5em; color: #14b8a6; } .markdown-preview h2 { font-size: 1.25em; margin: 0.5em 0; color: #14b8a6; } .markdown-preview p { margin: 0.5em 0; } .markdown-preview code { background: #f1f5f9; padding: 2px 4px; border-radius: 3px; font-family: monospace; } .markdown-preview pre { background: #f1f5f9; padding: 12px; border-radius: 6px; overflow-x: auto; } .markdown-preview pre code { background: none; padding: 0; } .markdown-preview ul, .markdown-preview ol { margin: 0.5em 0; padding-left: 1.5em; } .markdown-preview blockquote { border-left: 3px solid #14b8a6; margin: 0.5em 0; padding-left: 1em; color: #64748b; } `; declare global { interface HTMLElementTagNameMap { "folk-markdown": FolkMarkdown; } } export class FolkMarkdown extends FolkShape { static override tagName = "folk-markdown"; // Merge parent and child styles static { const sheet = new CSSStyleSheet(); const parentRules = Array.from(FolkShape.styles.cssRules).map((r) => r.cssText).join("\n"); const childRules = Array.from(styles.cssRules).map((r) => r.cssText).join("\n"); sheet.replaceSync(`${parentRules}\n${childRules}`); this.styles = sheet; } #content = ""; #isEditing = false; get content() { return this.#content; } set content(value: string) { this.#content = value; this.requestUpdate("content"); this.dispatchEvent(new CustomEvent("content-change", { detail: { content: value } })); } override createRenderRoot() { const root = super.createRenderRoot(); // Add markdown-specific UI const wrapper = document.createElement("div"); wrapper.innerHTML = html`
$1")
.replace(/^- (.+)$/gm, "$1") .replace(/\n\n/g, "
")
.replace(/^(.+)$/gm, (match) => {
if (
match.startsWith("