# YPY
> YPY is a hypermedia framework: HTML attributes ask the server for HTML and say where the answer goes. One script, no build step, no dependency. Version 0.1.1, MIT licence.
Source code: https://github.com/ypy-develop/ypy
## Docs
- [Docs](https://ypy.dev/docs): One page on YPY, from the first attribute to security and configuration: install it, make requests, swap HTML, handle errors and history, serve it.
- [Reference](https://ypy.dev/reference): Every YPY attribute, CSS class, header, event, JavaScript method, setting and extension in one place, generated from the same table of names the library uses.
- [Migration from the older library](https://ypy.dev/migration): Move a project written for the older library to YPY: the path, what is different, the ypy migrate conversion and the ypy check worklist, rule by rule.
## Examples
- [Examples](https://ypy.dev/examples): Interface patterns built with YPY attributes, from click to edit to infinite scroll, each with the HTML, what the server answers and a demo you can use.
- [Click to edit](https://ypy.dev/examples/click-to-edit): Show a contact as text, swap in an edit form on click, and swap the text back after Save or Cancel, with no page reload and no script of your own.
- [Bulk update](https://ypy.dev/examples/bulk-update): Tick rows in a table, press Activate or Deactivate, and one request updates every ticked row and shows a message, with no page reload.
- [Click to load](https://ypy.dev/examples/click-to-load): A table shows five orders and a Load more button. Each click adds the next five rows and moves the button down, until the list ends.
- [Delete row](https://ypy.dev/examples/delete-row): Ask for confirmation, send a DELETE request for one table row, and remove that row from the page when the server says it is gone.
- [Edit row](https://ypy.dev/examples/edit-row): A table row turns into inputs on Edit and back into text on Save or Cancel, and the server checks the values before it keeps them.
- [Lazy loading](https://ypy.dev/examples/lazy-loading): Draw the page at once with a placeholder, then load a slow report on its own request and swap it in when it is ready, with no script of your own.
- [Inline validation](https://ypy.dev/examples/inline-validation): Check an email address on the server when the visitor leaves the field, show the message under it, and check the whole form again on submit.
- [Active search](https://ypy.dev/examples/active-search): Filter a table while the visitor types, with a short delay between keystrokes, and show a message when nothing matches the search.
- [Infinite scroll](https://ypy.dev/examples/infinite-scroll): Fetch the next page of rows when the last row scrolls into view. Each answer carries its own next trigger, so the server decides when to stop.
- [Progress bar](https://ypy.dev/examples/progress-bar): Start a job with a button, then let each answer ask for the next progress value after a short delay, until the server answers that the job is done.
- [Dependent selects](https://ypy.dev/examples/value-select): Fill a model select from the make chosen in the first one: the server returns the options and owns the rule that links the two.
- [Animations](https://ypy.dev/examples/animations): Fade a swap in and out, animate a class that changed, or use view transitions. YPY adds classes during a swap and plain CSS does the motion.
- [File upload](https://ypy.dev/examples/file-upload): Send a file with a multipart form and fill a progress bar while it uploads, using the ypy-upload extension and a server that reads an ordinary form.
- [Keep file inputs after a form error](https://ypy.dev/examples/preserve-file-inputs): Return a 422 with validation errors without clearing the file the user chose, by keeping the file input in place with ypy-preserve.
- [Reset the form after a save](https://ypy.dev/examples/reset-user-input): Empty a comment form after a successful save and keep the typed text after a rejection, with a partial that swaps in a fresh form.
- [Confirm and prompt](https://ypy.dev/examples/confirm-and-prompt): Ask yes or no with ypy-confirm, or collect a reason with ypy-prompt that reaches the server in a header. A cancel sends no request.
- [Dialogs with layers](https://ypy.dev/examples/dialogs-layers): Open a form in a native modal dialog with ypy-layers, keep 422 errors inside it, and close it when the server fires a saved event.
- [Tabs](https://ypy.dev/examples/tabs): Tabs that ask the server for one panel at a time, with the strip and the panel updated by a single answer so the selected tab is never stored twice.
- [Keyboard shortcuts](https://ypy.dev/examples/keyboard-shortcuts): Start a request from Alt+N or the slash key with a ypy-trigger event filter, or use the HTML accesskey attribute when you want no script at all.
- [Drag and drop sorting](https://ypy.dev/examples/drag-and-drop-sort): Reorder a task list by dragging or with Space and the arrow keys. One POST saves the whole order, and a failed save puts the list back.
- [Updating other content](https://ypy.dev/examples/updating-other-content): Update the cart, the item count and a message from one response, with partials, a retarget header, or an event that the server fires.
- [Session expired](https://ypy.dev/examples/session-expired): Send the user to the sign-in page with a YPY-Redirect header when a background request finds the session gone, or keep the page and show a 401 message.
- [Live updates](https://ypy.dev/examples/live-updates): A chat room where every open page receives new messages over one ypy-stream response, and a reconnecting page gets the current state first.
- [Optimistic UI](https://ypy.dev/examples/optimistic-ui): Show a like, a comment or a deleted row before the server answers, and restore the page if the request fails, with ypy-optimistic.
- [Polling](https://ypy.dev/examples/polling): Poll a background job every second, let the server change the interval, and stop the polling with a 286 status when the job is done.
## Extensions
- [Extensions](https://ypy.dev/extensions): The 48 official YPY extensions: what each one adds to the core, how to load them, how to restrict which ones may run and how to write your own.
- [Alpine.js: the ypy-alpine-compat extension](https://ypy.dev/extensions/alpine-compat): Keeps Alpine.js state alive across a YPY swap or a restored page by moving it from the old node to the new one. Needed only when both run on one page.
- [Start-up and dependencies: the ypy-boot extension](https://ypy.dev/extensions/boot): Checks dependencies between extensions, fires ypy:ready once, makes ypy-ignore work on live elements and moves keyboard focus to the #fragment of a request.
- [Browser loading indicator: the ypy-browser-indicator extension](https://ypy.dev/extensions/browser-indicator): Shows the browser's own tab spinner and stop button while a YPY request runs, using the Navigation API. Does nothing where the API is missing.
- [Cache with revalidation: the ypy-cache extension](https://ypy.dev/extensions/cache): Shows the saved copy of a response at once, asks the server whether it is still current and swaps again only if it is not (stale-while-revalidate).
- [Client commands from the server: the ypy-commands extension](https://ypy.dev/extensions/commands): The server sends small client-side effects (highlight a row, move focus, hide a banner, fire an event) in one YPY-Commands header, from a fixed set.
- [Content Security Policy: the ypy-csp extension](https://ypy.dev/extensions/csp): Strips ypy attributes from markup that carries no page nonce, enforces Trusted Types and runs author code without unsafe-eval, so a strict CSP stays strict.
- [CSRF token on every request: the ypy-csrf extension](https://ypy.dev/extensions/csrf): Sends the CSRF token from one meta tag with every request except GET and HEAD to your own origin, so no element can fail with a silent 403.
- [One request for identical GETs: the ypy-dedupe extension](https://ypy.dev/extensions/dedupe): Joins identical GET requests that are in flight at the same moment into one network request and gives every element the same answer.
- [Development mode: the ypy-dev extension](https://ypy.dev/extensions/dev): For development only: errors that name the element and request, a latency and offline simulator, warnings for markup that does nothing, an error overlay.
- [Disable while loading: the ypy-disable extension](https://ypy.dev/extensions/disable): Disables buttons and fields, or makes the target inert, while a request runs, so a visitor cannot send the same form twice.
- [File downloads: the ypy-download extension](https://ypy.dev/extensions/download): Reads a response as a stream, reports progress events for a progress bar and hands the finished file to the browser as a download.
- [Author code without eval: the ypy-expr extension](https://ypy.dev/extensions/expr): Parses trigger filters, ypy-on handlers and js: values itself, so author code runs under script-src 'self' without eval or new Function.
- [Page head: the ypy-head extension](https://ypy.dev/extensions/head): When YPY swaps the body for a full page, merges that page's title, styles and scripts into the current head. A head inside a fragment is never merged.
- [Pages kept for back and forward: the ypy-history-cache extension](https://ypy.dev/extensions/history-cache): Saves a snapshot of each page in sessionStorage so back and forward show it at once with no request, keeping typed values and scroll position.
- [The inspector: the ypy-inspector extension](https://ypy.dev/extensions/inspector): A floating panel for development that records requests, swaps, ypy events, signals and stream events as they happen. Open it with Alt+Shift+Y.
- [Layers: the ypy-layers extension](https://ypy.dev/extensions/layers): Modals, drawers and popups on the native