From 77f64d28625fc55b2c79267a940400aebe280ce9 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Feb 2026 15:15:53 -0600 Subject: [PATCH] Add Tailwind CSS toggle, Markdown/WASM modes, and npm import resolution - Tailwind CSS: toolbar checkbox injects Play CDN into preview, persisted per-fiddle via new options JSON column - Markdown mode: uses marked.js CDN, renders markdown to HTML preview with CSS tab for custom styling - WASM mode: starter template with inline WebAssembly add function, supports top-level await via module detection - npm imports: auto-detect bare import specifiers in module code and inject importmap pointing to esm.sh CDN - Module auto-detection for html-css-js mode (import/export statements) - DB migration adds options column, server passes through all API endpoints - All features work across preview, export, and embed --- db.js | 11 +++++--- public/browse.html | 2 ++ public/css/style.css | 12 +++++++++ public/index.html | 6 +++++ public/js/app.js | 51 ++++++++++++++++++++++++++++++----- public/js/browse.js | 2 ++ public/js/editors.js | 11 ++++++++ public/js/embed.js | 39 +++++++++++++++++++++------ public/js/export.js | 38 +++++++++++++++++++------- public/js/import-map.js | 43 +++++++++++++++++++++++++++++ public/js/js-preprocessors.js | 42 +++++++++++++++++++++++++++-- public/js/preview.js | 46 +++++++++++++++++++++++++------ server.js | 11 ++++---- 13 files changed, 273 insertions(+), 41 deletions(-) create mode 100644 public/js/import-map.js diff --git a/db.js b/db.js index 7e81ccb..fd7e44a 100644 --- a/db.js +++ b/db.js @@ -31,6 +31,11 @@ try { db.exec(`ALTER TABLE fiddles ADD COLUMN listed INTEGER NOT NULL DEFAULT 1`); } catch (_) { /* column already exists */ } +// Migration: add options column (JSON string for per-fiddle settings like tailwind) +try { + db.exec(`ALTER TABLE fiddles ADD COLUMN options TEXT NOT NULL DEFAULT '{}'`); +} catch (_) { /* column already exists */ } + // Tags tables db.exec(` CREATE TABLE IF NOT EXISTS tags ( @@ -51,14 +56,14 @@ db.exec(`CREATE INDEX IF NOT EXISTS idx_fiddles_listed_updated ON fiddles(listed export const stmts = { insert: db.prepare(` - INSERT INTO fiddles (id, title, html, css, css_type, js, js_type, listed) - VALUES (@id, @title, @html, @css, @css_type, @js, @js_type, @listed) + INSERT INTO fiddles (id, title, html, css, css_type, js, js_type, listed, options) + VALUES (@id, @title, @html, @css, @css_type, @js, @js_type, @listed, @options) `), get: db.prepare('SELECT * FROM fiddles WHERE id = ?'), update: db.prepare(` UPDATE fiddles SET title = @title, html = @html, css = @css, css_type = @css_type, js = @js, js_type = @js_type, listed = @listed, - updated_at = datetime('now') + options = @options, updated_at = datetime('now') WHERE id = @id `), list: db.prepare('SELECT id, title, css_type, js_type, created_at, updated_at FROM fiddles ORDER BY updated_at DESC LIMIT 50'), diff --git a/public/browse.html b/public/browse.html index ea4b7bc..dd6a40b 100644 --- a/public/browse.html +++ b/public/browse.html @@ -22,6 +22,8 @@ + + + Tailwind +