datastar-hs
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hypermedia.Datastar.Types

Description

This module defines the types that model the Datastar server-sent events protocol. Most users won't import this module directly — the types are re-exported from Hypermedia.Datastar.

Default values for protocol fields (defaultPatchMode, defaultRetryDuration, etc.) follow the Datastar ADR specification at https://data-star.dev/reference/action_plugins.

Synopsis

Documentation

data EventType Source #

The two SSE event types defined by the Datastar protocol.

Every event the server sends is one of these. EventPatchElements covers both DOM patching and script execution (the protocol encodes executeScript as a special case of element patching). EventPatchSignals updates the browser's reactive signal store.

Constructors

EventPatchElements

Sent as datastar-patch-elements on the wire. Used by both PatchElements and ExecuteScript.

EventPatchSignals

Sent as datastar-patch-signals on the wire. Used by PatchSignals.

Instances

Instances details
Show EventType Source # 
Instance details

Defined in Hypermedia.Datastar.Types

Eq EventType Source # 
Instance details

Defined in Hypermedia.Datastar.Types

data ElementPatchMode Source #

How the patched HTML should be applied to the DOM.

The default mode is Outer, which replaces the target element (matched by its id attribute) including the element itself. This works well with Datastar's morphing algorithm, which preserves focus, scroll position, and CSS transitions during the replacement.

Constructors

Outer

Replace the target element and its contents (the default).

Inner

Replace only the target element's children, keeping the element itself.

Remove

Remove the target element from the DOM entirely.

Replace

Replace the target element without morphing (a hard swap).

Prepend

Insert the new content as the first child of the target element.

Append

Insert the new content as the last child of the target element.

Before

Insert the new content immediately before the target element.

After

Insert the new content immediately after the target element.

data ElementNamespace Source #

The XML namespace for the patched elements.

Almost all content uses HtmlNs (the default). Use SvgNs or MathmlNs when patching inline SVG or MathML elements so that Datastar creates them in the correct namespace.

Constructors

HtmlNs

Standard HTML namespace (the default).

SvgNs

SVG namespace — use when patching <svg> content.

MathmlNs

MathML namespace — use when patching <math> content.

data DatastarEvent Source #

Internal representation of a rendered SSE event.

Users don't construct these directly. Instead, use patchElements, patchSignals, or executeScript to build events, and sendPatchElements (etc.) to send them.

Constructors

DatastarEvent 

defaultRetryDuration :: Int Source #

Default SSE retry duration in milliseconds.

If the connection drops, the browser waits this long before reconnecting. Per the Datastar ADR spec, the default is 1000 ms.

defaultPatchMode :: ElementPatchMode Source #

Default element patch mode: Outer.

Replaces the target element (matched by id) and its contents using Datastar's morphing algorithm.

defaultUseViewTransition :: Bool Source #

Default for the useViewTransition flag: False.

When True, Datastar wraps the DOM update in a View Transition, enabling CSS-animated transitions between states.

defaultOnlyIfMissing :: Bool Source #

Default for the onlyIfMissing flag: False.

When True, signal values are only set if they don't already exist in the browser's store. See psOnlyIfMissing.

defaultAutoRemove :: Bool Source #

Default for the autoRemove flag: True.

When True, scripts executed via executeScript are automatically removed from the DOM after running.

defaultNamespace :: ElementNamespace Source #

Default element namespace: HtmlNs.