Spaces:
Sleeping
Sleeping
Commit ·
e5a3bec
1
Parent(s): 43d70fc
added live-editor link.
Browse filesFiles changed (4)
- app.py+70-7
- web/lyl-editor.css+15-5
- web/vendor/js-base64.jsAdded+3
- web/vendor/pako_deflate.min.jsAdded+3
349 unmodified lines350351352353354355154 unmodified lines510511512513514515516517518519520521522224 unmodified lines74774874975075175275375475575675775854 unmodified lines813814815816817818349 unmodified lines# the mount/bridge script that wires it to the hidden #ls-editor-state textbox.os.path.join(vendor, 'lyl-editor.bundle.js'),os.path.join(WEB_DIR, 'lyl-editor-mount.js'),# computes --ls-fill-h so the bottom Score List | editor row fills the height# left under Compose + Logs (robust against Gradio's flex-nesting quirks).os.path.join(WEB_DIR, 'layout-fit.js'),154 unmodified lines}'''# Render the editor text to SVG. The text is passed in by Gradio as the event's# input value (the hidden #ls-editor-state textbox, kept in sync with the embedded# CodeMirror editor) — taking the value as an argument gives the full text directly,# no DOM scraping needed._JS_RENDER = '''function (text) {if (window.LilyScore) window.LilyScore.render(text || '');return [];}'''224 unmodified lineswith gr.Column(scale=5, elem_id='editor-col'):with gr.Group():gr.Markdown('## Lilylet editor')# Share button: copies the current deep-link URL (#score=<file>)# to the clipboard. js-only handler (_JS_SHARE) — see its comment# for the iframe URL/clipboard caveats. A transient hint span next# to it shows the copy result.share_btn = gr.Button('🔗 Share link', elem_id='ls-share-btn',size='sm', scale=0, min_width=110)# Our own CodeMirror 6 editor (lyl-editor.bundle.js) mounts into# this div and bridges to the hidden textbox below — Gradio's# gr.Code can't be syntax-highlighted (its CM is sealed), so we54 unmodified lines# Share: copy the current deep-link URL (the #score hash kept current by the# select listener above) to the clipboard. js-only — see _JS_SHARE.share_btn.click(None, inputs=None, outputs=None, js=_JS_SHARE)return demo349 unmodified lines350351352353354355356357358359360154 unmodified lines515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576224 unmodified lines80180280380480580680780880981081181281381481581681781881954 unmodified lines874875876877878879880881349 unmodified lines# the mount/bridge script that wires it to the hidden #ls-editor-state textbox.os.path.join(vendor, 'lyl-editor.bundle.js'),os.path.join(WEB_DIR, 'lyl-editor-mount.js'),# pako (deflate) + js-base64: used by the "Open in live-editor" share link to# compress+url-safe-base64 the editor text into a ?code= param, matching# lilylet-live-editor's share.ts encoding exactly. Expose window.pako/Base64.os.path.join(vendor, 'pako_deflate.min.js'),os.path.join(vendor, 'js-base64.js'),# computes --ls-fill-h so the bottom Score List | editor row fills the height# left under Compose + Logs (robust against Gradio's flex-nesting quirks).os.path.join(WEB_DIR, 'layout-fit.js'),154 unmodified lines}'''# Open the current editor text in lilylet-live-editor. We compress the text exactly# as the editor's share.ts does — JSON.stringify({code}) -> pako.deflate(level 9) -># URL-safe base64 — and put it in ?code=<...>, then open the deployed editor in a new# tab. window.pako / window.Base64 come from the vendored UMD bundles (build_head).# Reads the text from the hidden #ls-editor-state <textarea> (the canonical editor# value). No-op with a hint if empty or the libs failed to load._LIVE_EDITOR_URL = 'https://k-l-lambda.github.io/lilylet-live-editor/'_JS_LIVE_EDITOR = '''function () {const flash = (msg, ok) => {const btn = document.getElementById('ls-live-btn');if (!btn) return;let hint = document.getElementById('ls-share-hint');if (!hint) {hint = document.createElement('span');hint.id = 'ls-share-hint';hint.className = 'ls-share-hint';const sb = document.getElementById('ls-share-btn');(sb || btn).insertAdjacentElement('afterend', hint);}hint.textContent = msg;hint.classList.toggle('ls-share-err', !ok);hint.classList.add('show');clearTimeout(hint._t);hint._t = setTimeout(() => hint.classList.remove('show'), 2200);};try {const ta = document.querySelector('#ls-editor-state textarea');const code = ta && ta.value;if (!code || !code.trim()) { flash('Editor is empty', false); return []; }if (!window.pako || !window.Base64) { flash('Encoder not loaded', false); return []; }const json = JSON.stringify({ code: code });const compressed = window.pako.deflate(json, { level: 9 });const encoded = window.Base64.fromUint8Array(compressed, true); // URL-safeconst url = '%s' + '?code=' + encoded;window.open(url, '_blank', 'noopener');} catch (e) {flash('Could not build link', false);}return [];}''' % _LIVE_EDITOR_URL# Render the editor text to SVG. The text is passed in by Gradio as the event's# input value (the hidden #ls-editor-state textbox, kept in sync with the embedded# CodeMirror editor) — taking the value as an argument gives the full text directly,# no DOM scraping needed. Also toggles the "Open in live-editor" button: shown only# when the editor has non-empty text (the link needs content to encode)._JS_RENDER = '''function (text) {if (window.LilyScore) window.LilyScore.render(text || '');try {const live = document.getElementById('ls-live-btn');if (live) live.classList.toggle('ls-hidden', !(text && text.trim()));} catch (e) {}return [];}'''224 unmodified lineswith gr.Column(scale=5, elem_id='editor-col'):with gr.Group():gr.Markdown('## Lilylet editor')with gr.Row(elem_id='ls-editor-actions'):# Share button: copies the current deep-link URL (#score=<file>)# to the clipboard. js-only handler (_JS_SHARE) — see its comment# for the iframe URL/clipboard caveats. A transient hint span next# to it shows the copy result.share_btn = gr.Button('🔗 Share link', elem_id='ls-share-btn',size='sm', scale=0, min_width=110)# Open the current editor text in lilylet-live-editor: builds a# ?code=<pako+base64> URL (matching the editor's share.ts) and# opens it in a new tab. Hidden via CSS until the editor has text# (toggled by _JS_RENDER, which receives the full text each change).live_btn = gr.Button('🎹 Open in live-editor', elem_id='ls-live-btn',size='sm', scale=0, min_width=150, elem_classes=['ls-hidden'])# Our own CodeMirror 6 editor (lyl-editor.bundle.js) mounts into# this div and bridges to the hidden textbox below — Gradio's# gr.Code can't be syntax-highlighted (its CM is sealed), so we54 unmodified lines# Share: copy the current deep-link URL (the #score hash kept current by the# select listener above) to the clipboard. js-only — see _JS_SHARE.share_btn.click(None, inputs=None, outputs=None, js=_JS_SHARE)# Open in live-editor: encode the editor text into a ?code= URL and open it.live_btn.click(None, inputs=None, outputs=None, js=_JS_LIVE_EDITOR)return demo
30 unmodified lines31323334353637383940414243444546474830 unmodified linesoutline: none;}/* Share button: a compact, unobtrusive button under the "Lilylet editor" title. */#ls-share-btn {flex: 0 0 auto;width: auto;min-width: 0;align-self: flex-start;margin: 0 0 6px 2px;font-size: 12px;padding: 3px 10px;}/* Transient "Link copied!" hint shown beside the share button. Fades in on .show. */.ls-share-hint {display: inline-block;margin-left: 8px;30 unmodified lines3132333435363738394041424344454647484950515253545556575830 unmodified linesoutline: none;}/* Editor action buttons row (Share link + Open in live-editor) under the title. */#ls-editor-actions {flex: 0 0 auto;gap: 6px;align-items: center;margin: 0 0 6px 2px;}/* Share / live-editor buttons: compact and unobtrusive. */#ls-share-btn,#ls-live-btn {flex: 0 0 auto;width: auto;min-width: 0;font-size: 12px;padding: 3px 10px;}/* "Open in live-editor" is hidden until the editor has content (toggled in JS). */#ls-live-btn.ls-hidden { display: none !important; }/* Transient "Link copied!" hint shown beside the buttons. Fades in on .show. */.ls-share-hint {display: inline-block;margin-left: 8px;
123version https://git-lfs.github.com/spec/v1oid sha256:cc4803fc4f373cbbeecac84bad8ccfefe791062191a6675141f7df870652989fsize 13006123version https://git-lfs.github.com/spec/v1oid sha256:9429785d1e7f805d46640c4155957fd0f286144dec05cea09f6f2eaa646adb21size 27876app.py+70-7
web/lyl-editor.css+15-5
web/vendor/js-base64.jsAdded+3
web/vendor/pako_deflate.min.jsAdded+3