| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- data EventType
- eventTypeToText :: EventType -> Text
- data ElementPatchMode
- patchModeToText :: ElementPatchMode -> Text
- data ElementNamespace
- namespaceToText :: ElementNamespace -> Text
- data DatastarEvent = DatastarEvent {}
- defaultRetryDuration :: Int
- defaultPatchMode :: ElementPatchMode
- defaultUseViewTransition :: Bool
- defaultOnlyIfMissing :: Bool
- defaultAutoRemove :: Bool
- defaultNamespace :: ElementNamespace
Documentation
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 |
| EventPatchSignals | Sent as |
eventTypeToText :: EventType -> Text Source #
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. |
Instances
| Show ElementPatchMode Source # | |
Defined in Hypermedia.Datastar.Types Methods showsPrec :: Int -> ElementPatchMode -> ShowS # show :: ElementPatchMode -> String # showList :: [ElementPatchMode] -> ShowS # | |
| Eq ElementPatchMode Source # | |
Defined in Hypermedia.Datastar.Types Methods (==) :: ElementPatchMode -> ElementPatchMode -> Bool # (/=) :: ElementPatchMode -> ElementPatchMode -> Bool # | |
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 |
| MathmlNs | MathML namespace — use when patching |
Instances
| Show ElementNamespace Source # | |
Defined in Hypermedia.Datastar.Types Methods showsPrec :: Int -> ElementNamespace -> ShowS # show :: ElementNamespace -> String # showList :: [ElementNamespace] -> ShowS # | |
| Eq ElementNamespace Source # | |
Defined in Hypermedia.Datastar.Types Methods (==) :: ElementNamespace -> ElementNamespace -> Bool # (/=) :: ElementNamespace -> ElementNamespace -> Bool # | |
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.
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.