|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="htmx-config" content='{"logAll":true,"historyCache":{"disable":false}}'> |
| 6 | + <script src="/htmax.js"></script> |
| 7 | + <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> |
| 8 | + <style> |
| 9 | + .htmx-indicator { opacity: 0; transition: opacity 200ms; } |
| 10 | + .htmx-request .htmx-indicator { opacity: 1; } |
| 11 | + </style> |
| 12 | +</head> |
| 13 | +<body class="max-w-3xl mx-auto p-6 my-8 space-y-12"> |
| 14 | + |
| 15 | +<h1 class="text-2xl font-bold">htmax bundle — manual test</h1> |
| 16 | +<p class="text-sm text-neutral-500"> |
| 17 | + Version: <code id="version"></code> |
| 18 | + <script>document.getElementById('version').textContent = htmx.version;</script> |
| 19 | +</p> |
| 20 | + |
| 21 | +<!-- ─── SSE ─────────────────────────────────────────────────────────────── --> |
| 22 | +<section class="space-y-3"> |
| 23 | + <h2 class="text-lg font-semibold">1. SSE (hx-sse)</h2> |
| 24 | + <p class="text-sm text-neutral-500">Connects to a stream and receives 5 messages then closes.</p> |
| 25 | + <div hx-sse:connect="/htmax/sse-stream"> |
| 26 | + <div hx-sse:swap="message" hx-sse:close="close" id="sse-out" class="p-3 bg-neutral-100 rounded min-h-8"> |
| 27 | + Waiting for stream… |
| 28 | + </div> |
| 29 | + </div> |
| 30 | +</section> |
| 31 | + |
| 32 | +<!-- ─── WebSockets ───────────────────────────────────────────────────────── --> |
| 33 | +<section class="space-y-3"> |
| 34 | + <h2 class="text-lg font-semibold">2. WebSockets (hx-ws)</h2> |
| 35 | + <p class="text-sm text-neutral-500">Checks the extension is registered (full WS test requires <code>ws-server.js</code>).</p> |
| 36 | + <button hx-get="/htmax/ws-status" hx-target="#ws-out" |
| 37 | + class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"> |
| 38 | + Check WS extension |
| 39 | + </button> |
| 40 | + <div id="ws-out" class="p-3 bg-neutral-100 rounded min-h-8"></div> |
| 41 | +</section> |
| 42 | + |
| 43 | +<!-- ─── Preload ──────────────────────────────────────────────────────────── --> |
| 44 | +<section class="space-y-3"> |
| 45 | + <h2 class="text-lg font-semibold">3. Preload (hx-preload)</h2> |
| 46 | + <p class="text-sm text-neutral-500">Hover the button to preload, then click to swap. Check Network tab — request fires on hover.</p> |
| 47 | + <button hx-get="/htmax/preload-target" hx-target="#preload-out" hx-preload |
| 48 | + class="px-4 py-2 bg-indigo-600 text-white rounded hover:bg-indigo-700"> |
| 49 | + Hover then Click |
| 50 | + </button> |
| 51 | + <div id="preload-out" class="p-3 bg-neutral-100 rounded min-h-8"></div> |
| 52 | +</section> |
| 53 | + |
| 54 | +<!-- ─── Browser Indicator ────────────────────────────────────────────────── --> |
| 55 | +<section class="space-y-3"> |
| 56 | + <h2 class="text-lg font-semibold">4. Browser Indicator (hx-browser-indicator)</h2> |
| 57 | + <p class="text-sm text-neutral-500">Browser's native loading spinner should appear during the 1.5s request.</p> |
| 58 | + <button hx-get="/htmax/indicator" hx-target="#indicator-out" hx-browser-indicator |
| 59 | + class="px-4 py-2 bg-yellow-600 text-white rounded hover:bg-yellow-700"> |
| 60 | + Trigger slow request |
| 61 | + </button> |
| 62 | + <div id="indicator-out" class="p-3 bg-neutral-100 rounded min-h-8"></div> |
| 63 | +</section> |
| 64 | + |
| 65 | +<!-- ─── Download ─────────────────────────────────────────────────────────── --> |
| 66 | +<section class="space-y-3"> |
| 67 | + <h2 class="text-lg font-semibold">5. Download (hx-download)</h2> |
| 68 | + <p class="text-sm text-neutral-500">Should trigger a file download without navigating away.</p> |
| 69 | + <button hx-get="/htmax/download" hx-download="htmax-test.txt" |
| 70 | + class="px-4 py-2 bg-teal-600 text-white rounded hover:bg-teal-700"> |
| 71 | + Download file |
| 72 | + </button> |
| 73 | +</section> |
| 74 | + |
| 75 | +<!-- ─── Optimistic ───────────────────────────────────────────────────────── --> |
| 76 | +<section class="space-y-3"> |
| 77 | + <h2 class="text-lg font-semibold">6. Optimistic (hx-optimistic)</h2> |
| 78 | + <p class="text-sm text-neutral-500">Template content shows immediately; server response replaces it after 1.5s.</p> |
| 79 | + <button hx-post="/htmax/optimistic" hx-target="#optimistic-out" |
| 80 | + hx-optimistic="#optimistic-template" |
| 81 | + class="px-4 py-2 bg-orange-600 text-white rounded hover:bg-orange-700"> |
| 82 | + Submit optimistically |
| 83 | + </button> |
| 84 | + <template id="optimistic-template"> |
| 85 | + <span class="text-orange-500 italic">⏳ Saving…</span> |
| 86 | + </template> |
| 87 | + <div id="optimistic-out" class="p-3 bg-neutral-100 rounded min-h-8"></div> |
| 88 | +</section> |
| 89 | + |
| 90 | +<!-- ─── Targets ──────────────────────────────────────────────────────────── --> |
| 91 | +<section class="space-y-3"> |
| 92 | + <h2 class="text-lg font-semibold">7. Targets (hx-targets)</h2> |
| 93 | + <p class="text-sm text-neutral-500">Same response swapped into two elements simultaneously.</p> |
| 94 | + <button hx-get="/htmax/targets" hx-targets="#targets-out-1, #targets-out-2" |
| 95 | + class="px-4 py-2 bg-pink-600 text-white rounded hover:bg-pink-700"> |
| 96 | + Swap two targets |
| 97 | + </button> |
| 98 | + <div class="flex gap-4"> |
| 99 | + <div id="targets-out-1" class="flex-1 p-3 bg-neutral-100 rounded min-h-8">Target 1</div> |
| 100 | + <div id="targets-out-2" class="flex-1 p-3 bg-neutral-100 rounded min-h-8">Target 2</div> |
| 101 | + </div> |
| 102 | +</section> |
| 103 | + |
| 104 | +<!-- ─── Live ─────────────────────────────────────────────────────────────── --> |
| 105 | +<section class="space-y-3"> |
| 106 | + <h2 class="text-lg font-semibold">8. Live (hx-live)</h2> |
| 107 | + <p class="text-sm text-neutral-500">Counter increments live as you type.</p> |
| 108 | + <div class="flex gap-4 items-center"> |
| 109 | + <input id="live-input" type="text" placeholder="Type here…" |
| 110 | + class="border rounded px-3 py-2 flex-1"> |
| 111 | + <span hx-live:text="document.getElementById('live-input').value.length + ' chars'" |
| 112 | + class="text-lg font-mono w-24 text-right">0 chars</span> |
| 113 | + </div> |
| 114 | +</section> |
| 115 | + |
| 116 | +<!-- ─── Upsert ───────────────────────────────────────────────────────────── --> |
| 117 | +<section class="space-y-3"> |
| 118 | + <h2 class="text-lg font-semibold">9. Upsert (hx-upsert)</h2> |
| 119 | + <p class="text-sm text-neutral-500">Item 1 updates in place, Item 3 is inserted. Item 2 is preserved.</p> |
| 120 | + <button hx-post="/htmax/upsert" hx-swap="none" |
| 121 | + class="px-4 py-2 bg-violet-600 text-white rounded hover:bg-violet-700"> |
| 122 | + Upsert items |
| 123 | + </button> |
| 124 | + <div id="upsert-list" class="space-y-2 mt-2"> |
| 125 | + <div id="item-1" class="p-2 bg-neutral-100 rounded">Item 1 (original)</div> |
| 126 | + <div id="item-2" class="p-2 bg-neutral-100 rounded">Item 2 (should stay)</div> |
| 127 | + </div> |
| 128 | +</section> |
| 129 | + |
| 130 | +<!-- ─── Alpine Compat ────────────────────────────────────────────────────── --> |
| 131 | +<section class="space-y-3"> |
| 132 | + <h2 class="text-lg font-semibold">10. Alpine Compat (hx-alpine-compat)</h2> |
| 133 | + <p class="text-sm text-neutral-500"> |
| 134 | + Alpine is not loaded here — extension should silently no-op. |
| 135 | + Check console for errors (there should be none). |
| 136 | + </p> |
| 137 | + <button hx-get="/htmax/clicked" hx-target="#alpine-out" |
| 138 | + class="px-4 py-2 bg-sky-600 text-white rounded hover:bg-sky-700"> |
| 139 | + Trigger swap (no Alpine errors) |
| 140 | + </button> |
| 141 | + <div id="alpine-out" class="p-3 bg-neutral-100 rounded min-h-8"></div> |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- ─── History Cache ────────────────────────────────────────────────────── --> |
| 145 | +<section class="space-y-3"> |
| 146 | + <h2 class="text-lg font-semibold">11. History Cache (hx-history-cache)</h2> |
| 147 | + <p class="text-sm text-neutral-500"> |
| 148 | + Navigate to page 2, then hit the browser back button. |
| 149 | + The restore should come from <code>sessionStorage</code> (no network request in DevTools). |
| 150 | + </p> |
| 151 | + <div id="history-content"> |
| 152 | + <p class="mb-2">Page 1 — initial content.</p> |
| 153 | + <a hx-get="/htmax/page2" hx-target="#history-content" hx-push-url="/htmax/page2" |
| 154 | + href="/htmax/page2" |
| 155 | + class="text-blue-600 underline cursor-pointer"> |
| 156 | + Go to page 2 |
| 157 | + </a> |
| 158 | + </div> |
| 159 | +</section> |
| 160 | + |
| 161 | +<footer class="pt-6 border-t border-neutral-200 text-sm text-neutral-400"> |
| 162 | + Check browser console — <code>htmx.config.logAll</code> is on. |
| 163 | + History cache is enabled via <code>historyCache.disable:false</code> in the meta tag. |
| 164 | +</footer> |
| 165 | + |
| 166 | +</body> |
| 167 | +</html> |
0 commit comments