A pure MoonBit implementation of the htmx client library. This library allows you to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext.
This implementation strives for feature parity with htmx 1.9.x, strictly typed and compiled to optimized JavaScript.
hx-get,hx-post,hx-put,hx-delete,hx-patch: AJAX requestshx-trigger: Granular event triggering (delay, throttle, once, changed, filters)hx-target: Swap target specificationhx-swap: Swap strategies (innerHTML,outerHTML, etc.)hx-select: Content filtering from responsehx-push-url: Browser history integrationhx-swap-oob: Out-of-Band swaps
- DOM Morphing:
hx-swap="morph"preserves element state (focus, cursor position) using a recursive DOM diffing algorithm. - Form Data: Automatic collection and submission of form values.
- Mutation Observer: Automatically processes content injected into the DOM.
- No Dependencies: Built on top of
mizchi/jsbindings.
moon add f4ah6o/htmxInitialize the library in your main entry point:
import f4ah6o/htmx/htmx
fn main {
htmx.htmx_init()
}Then use hx- attributes in your HTML:
<!-- Basic Request -->
<button hx-get="/api/clicked" hx-swap="outerHTML">
Click Me
</button>
<!-- Form Submission -->
<form hx-post="/api/user">
<input name="username">
<button type="submit">Save</button>
</form>
<!-- Morphing Swap (Preserves Input State) -->
<div hx-target="this" hx-swap="morph">
<input type="text" name="q" placeholder="Search...">
</div>innerHTML- Replace the inner HTML of the target elementouterHTML- Replace the entire target element with the responsebeforebegin- Insert the response before the target elementafterbegin- Insert the response before the first child of the target elementbeforeend- Insert the response after the last child of the target elementafterend- Insert the response after the target elementdelete- Deletes the target element regardless of the responsenone- Does not append content from response (out of band items will still be processed)morph- Morphs the target element to match the response, preserving focus and state
# Build for JavaScript target
moon build --target js
# Run tests
moon test --target jsThe upstream htmx test suite is vendored under test/ and runs in headless
Chrome via web-test-runner.
# Install test dependencies
npm install
# Build htmx.mbt and run the upstream suite in headless Chrome
npm run test:htmx