From c0389838b6ad66d4d445f4f1e7f238379e82459a Mon Sep 17 00:00:00 2001 From: Garth Poitras <411908+gpoitch@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:53:50 -0500 Subject: [PATCH] [demo] Add rendering playground --- demo/demo.css | 25 + demo/demo.js | 22 + demo/index.html | 17 + demo/vendor/mobiledoc-dom-renderer.js | 1448 +++++++++++++++++++++++++ 4 files changed, 1512 insertions(+) create mode 100644 demo/vendor/mobiledoc-dom-renderer.js diff --git a/demo/demo.css b/demo/demo.css index 23315b687..37ef7fd86 100644 --- a/demo/demo.css +++ b/demo/demo.css @@ -172,3 +172,28 @@ table tr { background-color: #ffffff; border: 2px solid #cccccc; } + +#md-render-input { + width: 100%; + height: 300px; +} + +#md-render-output { + padding: 1rem; + background-color: #ffffff; + border: 2px solid #cccccc; +} + +.md-render-label { + margin: 0 0 0.5rem; + font-size: 0.8rem; + color: #5c5c5c; + text-transform: uppercase; + font-weight: 700; +} + +.md-output-error { + color: red; + opacity: 0.6; + font-size: 0.8rem; +} diff --git a/demo/demo.js b/demo/demo.js index 4a2234599..53a142d1a 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -131,9 +131,31 @@ const bootstrapCardEditor = () => { activateButtons('#editor-card-wrapper', editor) } +const bootstrapRenderer = () => { + const inputEl = document.querySelector('#md-render-input') + const outputEl = document.querySelector('#md-render-output') + const renderer = new window.MobiledocDOMRenderer() + inputEl.addEventListener('input', e => { + const text = e.target.value.trim() + if (!text) { + outputEl.innerHTML = '' + } else { + try { + const text = e.target.value.trim() + const json = JSON.parse(text) + outputEl.innerHTML = '' + outputEl.append(renderer.render(json).result) + } catch (e) { + outputEl.innerHTML = `${e.toString()}` + } + } + }) +} + document.addEventListener('DOMContentLoaded', () => { bootstrapEditor() bootstrapSimpleDemo() bootstrapToolbarEditor() bootstrapCardEditor() + bootstrapRenderer() }) diff --git a/demo/index.html b/demo/index.html index cb5c599d0..c1e8484b7 100644 --- a/demo/index.html +++ b/demo/index.html @@ -9,6 +9,7 @@
+