Repository navigation
Add live editing of pattern config in the UI - #11
Merged
Merged
Conversation
dchukhin
reviewed
Nov 3, 2026
dchukhin
left a comment
Collaborator
There was a problem hiding this comment.
I took a look, and it works pretty well. good job!
It's pretty cool to see the static export too.
Here are a few bugs I ran into:
A. server error while typing
- run the server (
django-admin runserver --settings=tests.settings.dev --pythonpath=.) - go to /pattern/patterns/molecules/button/button.html
- click "Toggle live mode"
- In the textarea, select all and type "context: t"
- observe the unhappy state, and a traceback in the terminal that is running the Django server
B. empty text renders default
- run the server (
django-admin runserver --settings=tests.settings.dev --pythonpath=.) - go to /pattern/patterns/molecules/button/button.html
- click "Toggle live mode"
- Make some changes, and observe them. Then, delete everything
- observe that the default renders, even though it is not now shown in the textarea
C. Another behavior I observed is that making edits, then clicking the browser's back button goes back to rendering the previous edit (not the previous page), while the editable textarea does not change. I'm not sure what the correct behavior is, so I'm pointing it out here.
lucianoratamero
force-pushed
the
live-config-editing
branch
from
November 3, 2026 17:30
2b75fc9 to
220b9f2
Compare
"Toggle live mode" in the "Template config" tab swaps the read-only YAML for an editor. Edits re-render the preview 500ms after typing stops, via a CSRF-protected POST to the render-pattern view, which keeps wrapping fragments in the base template. Toggling off restores the original. The toggle only appears when the backend answers an OPTIONS probe with X-Pattern-Library-Live-Edit, so static exports of the UI (GitHub Pages, Apache, etc.) keep the read-only view.
Drag handles on the sidebar's right edge and below the preview (also keyboard-operable separators) set --sidebar-width / --iframe-height. Sizes are kept in localStorage and restored before the body is parsed, so they carry across pattern pages without a layout jump. The preview's native resize grip is now horizontal-only, leaving height to the new handle.
lucianoratamero
force-pushed
the
live-config-editing
branch
from
November 3, 2026 18:43
220b9f2 to
dc5f397
Compare
- Validate that context/tags are mappings; a scalar (e.g. "context: t")
returned a 500 traceback when rendering tried to index it, now 400.
- An emptied editor POSTed {}, which render_pattern treated as "no config"
and fell back to the YAML default; only a missing config (None) should.
- Render live edits into the iframe via fetch + document.write instead of a
form submission targeting it, so edits no longer pile up in browser history.
- Add aria-valuenow to the resize separators (role="separator" requires it)
and keep it current as they resize.
- Stop echoing the YAML exception in the 400 response (CodeQL: information
exposure through an exception).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a Storybook-like way to try out pattern config: in the "Template config" tab, Toggle live mode swaps the read-only YAML for an editor, and the preview re-renders as you type (500ms after you stop). Toggling it off goes back to the read-only YAML and the original preview.
Stacked on #10 (
sync-upstream-v1.6.0). Merge that first, then retarget this PR tomain.How it works
RenderPatternViewnow also accepts POST with aconfigfield (YAML). It renders through the same path as GET, so fragments are still wrapped in the base template and context modifiers andtagsoverrides still apply.yaml.safe_load. Invalid YAML, or a top level that isn't a mapping, returns a plain-text 400, which shows as a readable message in the preview.render_pattern_api, which is untouched because storybook-django depends on it).xframe_options_sameoriginmoved todispatchso POST responses can still be framed.<form target="pattern-iframe">, so there's no fetch call and no YAML parsing in JS.config-editor.jshandles the debounce, the toggle (aria-pressed) and Reset.OPTIONSrequest to the render URL. The toggle only appears if the response has theX-Pattern-Library-Live-Editheader. We can't rely onAllow: POST, because Apache lists POST for static files too.iframe.js: the size label'sresizelistener is re-attached on each iframeload, since every navigation (including live re-renders) gets a new window.pattern_configis no longer affected by rendering:render_patternmutates the config'scontextin place, so the view now passes it a deep copy.Resizable sidebar and preview (second commit)
role="separator"elements, so the arrow keys work too.--sidebar-width/--iframe-height. The values are saved inlocalStorageand restored while the<head>script runs, so the sizes carry over between pattern pages without a visible jump.pointer-events: noneand the sidebar's grid transition is turned off, so the drag doesn't stall over the preview.resizegrip is nowhorizontalonly, so it doesn't fight the new height handle. The S/M/L/Full buttons are unchanged.Known limitations
Testing
python runtests.py: 53 tests pass. New tests cover POST rendering (context, tags, postednamein the base template,X-Frame-Options: SAMEORIGIN), invalid YAML (400), a missing CSRF token (403), the OPTIONS marker header, the editor markup on the index page, andpattern_confignot being mutated.npm run buildsucceeds.runserver: off by default, toggle on/off/on, debounce (no POST before 500ms, then one), invalid YAML message, Reset and Render buttons, a page-level pattern, the size label after a re-render, and no JS errors.wget --mirrorfromtests.settings.production: served by Python'shttp.server(OPTIONS → 501) and by Apache (OPTIONS → 200 withAllow: …POST…). In both, the toggle stays hidden and the read-only YAML shows, for a DTL fragment, a page pattern and a Jinja pattern. GitHub Pages answers OPTIONS with 405, so the toggle is hidden there too.runserverand the static export): dragging, including across the iframe; the tabs move with the preview; sizes persist across a reload and a different pattern; arrow keys; min clamps; S/M/L still work; handle hidden with the menu closed and on mobile; no JS errors.Checklist