1.0.9 • Published 5 months ago

elysia-htmx v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Elysia HTMX

Elysia plugin to create or forward Request IDs.

Installation

bun add --exact elysia-htmx

Usage

import { htmx } from "elysia-htmx"; // 1. Import
import Elysia from "elysia";

new Elysia()
  .use(htmx()) // 2. Use
  .get("/", ({ hx }) => {
    return {
      request: hx.request,
      boosted: hx.boosted,
      historyRestoreRequest: hx.historyRestoreRequest,
      currentURL: hx.currentURL,
      prompt: hx.prompt,
      target: hx.target,
      triggerName: hx.triggerName,
      trigger: hx.trigger,
      isHTMX: hx.isHTMX,
    }
  })
  .listen(3000);

API (Added Context)

type HtmxContext = {
    hx: {
        request: boolean;
        boosted: boolean;
        historyRestoreRequest: boolean;
        currentURL: string;
        prompt: string;
        target: string;
        triggerName: string;
        trigger: string;
        setLocation(url: string): void;
        pushURL(url: string): void;
        redirect(url: string): void;
        refresh(): void;
        replaceURL(url: string): void;
        reswap(value: HxSwap): void;
        retarget(elementSelector: string): void;
        reselect(elementSelector: string): void;
        triggerEvent(event: string | Record<string, unknown>): void;
        triggerEventAfterSettle(): void;
        triggerEventAfterSwap(): void;
        get isHTMX(): boolean;
        stopPolling(): void;
    };
};

For usage of the hx object, please refer to the htmx's Request and Response headers documentation.

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

8 months ago