Skip to content

Data-bound list and form screen in ui, composed by init --with ui,store (refs #262) - #328

Merged
jimhoyd merged 2 commits into
mainfrom
feat/ui-store-crud-262
Sep 20, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
feat/ui-store-crud-262

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #262 (does not close it). Follows the maintainer decision: extend @jimhoyd/urlcode-ui, no new core handler, host wiring through init --with.

Spike: can a non-operator project render a bound list today?

Ran in a scratch project (no host file) with a trusted function importing @jimhoyd/urlcode-ui.

  • Works: the bare import resolves from the project's node_modules, and renderDocument + table return kit-styled static HTML (200, escaped).
  • Does not work without the operator host: kit assets (createKit links /assets/ui/..., nothing serves them), the nonce CSP (the function response carried no CSP header; renderDocument inlines ~35 KB of style), and any data binding (no helper reads a data source). So a bound screen needs the host, which is what the scaffold now generates.

What this adds

  • crudScreen / crudMarkup / crudFields: a create form, inline edit and delete for a collection declared like the store's ({mount, fields}), plus a crud kit script (content-hashed asset, loaded with the page nonce, connect-src 'self', no inline script).
  • extensions.ui.config.screens (/todos: {collection, title}): the ui extension reads the store's collection from extensions.store at activation, so fields are declared once for API and screen. Routes are /todos/* with extension: ui.
  • init --with ui,store writes the screen entry and route (auth: true when auth is composed).
  • Client fixes, each with a test: an edit in progress survives any re-render (per-record drafts, focus and caret restored); an optimistic checkbox is rolled back with a message when the update fails (also on network failure).
  • All record values are written with textContent/value; the shell is escaped. Tests assert no innerHTML-style sinks.

Composition bugs found and fixed on the way

  • init --with ui,store produced a host with a duplicate import {fileURLToPath} (SyntaxError). src/init-with.ts now writes an identical import line once.
  • ui and store described PROJECT_SHA256 differently, which init refuses. Store's text now matches ui/auth.

Verification

  • npm ci, npm run verify (includes verify:workspaces), npm run docs:llms, npm run check:docs all pass; no llms-full.txt change was needed.
  • New: packages/ui/test/crud.test.ts (client behaviour against a small fake DOM in test/support/fake-dom.ts, extension activation and refusals, scaffold), and an integration test in test/workspace-scaffold.integration.ts that runs init --with ui,store, loads the generated host and serves /todos, the script asset and the API. Paths use join/tmpdir, no POSIX-only assumptions.
  • By hand in the Browser pane against a served init --with ui,store site: created a record, hostile markup rendered as text, edit text and focus survived Refresh, a forced 500 on PATCH reverted the checkbox, no console errors, CSP header has nonce script-src and no unsafe-inline. Not run in CI (no browser tests there) and not tried on Windows or in other browsers.

Open decisions (also in docs/OPEN-DECISIONS.md)

Per-field labels/columns config, filtering and sorting, per-record ownership before multi-user use, recipes/ entry and release wiring (#323/#324), a browser test in CI. packages/ui unpacked size was about 3 KB over its package-audit budget; I kept scripts/package-audit.ts untouched and shrank the generated .d.ts instead, so that budget has almost no headroom left.

🤖 Generated with Claude Code

Comment thread packages/ui/test/crud.test.ts Fixed
…init --with ui,store (refs #262)

The ui extension gains screens config, reads the store's collection
declaration at activation and serves a list/create/edit/delete screen driven
by a nonce-loaded crud kit script. Edit drafts survive re-renders and failed
optimistic toggles roll back. init dedupes identical host imports and the
store scaffold's PROJECT_SHA256 description now matches ui and auth so the
extensions compose.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jimhoyd
jimhoyd force-pushed the feat/ui-store-crud-262 branch from d8c5cf5 to f47c5ab Compare September 20, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants