v4, beta4 (#19)

- Update with header/attribute changes between alpha8 and beta4
- Add support for htmax script, attributes, headers, and extension config

Reviewed-on: #19
This commit was merged in pull request #19.
This commit is contained in:
2026-06-15 01:07:38 +00:00
parent d4a7e0c9ce
commit 5c12ad7cef
22 changed files with 1066 additions and 214 deletions
+91 -32
View File
@@ -71,8 +71,11 @@ type HxEvent =
/// <summary>Triggered after an AJAX request has completed processing a successful response</summary>
| [<System.Obsolete "Removed in v4; use AfterInit">] AfterOnLoad
/// <summary>Triggered after htmx has initialized a DOM node or subtree</summary>
| AfterProcess
/// <summary>Triggered after htmx has initialized a node</summary>
| [<System.Obsolete "Removed in v4; use AfterInit">] AfterProcessNode
| [<System.Obsolete "Removed in v4; use AfterProcess">] AfterProcessNode
/// <summary>Triggered after new content is saved to the history cache</summary>
| AfterPushIntoHistory
@@ -84,13 +87,13 @@ type HxEvent =
| AfterRequest
/// <summary>Triggered after the DOM has settled</summary>
| [<System.Obsolete "Removed in v4; use AfterSwap">] AfterSettle
| AfterSettle
/// <summary>Triggered after a Server Sent Events (SSE) message is read</summary>
| AfterSseMessage
| [<System.Obsolete "Removed in v4; use Htmax.HxEvents.AfterSseMessage">] AfterSseMessage
/// <summary>Triggered after a Server Sent Events (SSE) stream is closed</summary>
| AfterSseStream
| [<System.Obsolete "Removed in v4; SSE is assumed to be a stream">] AfterSseStream
/// <summary>Triggered after new content has been swapped in</summary>
| AfterSwap
@@ -116,12 +119,18 @@ type HxEvent =
/// <summary>Triggered before any response processing occurs</summary>
| [<System.Obsolete "Removed in v4; use BeforeInit">] BeforeOnLoad
/// <summary>Triggered before htmx begins processing a DOM node or subtree</summary>
| BeforeProcess
/// <summary>Triggered before htmx initializes a node</summary>
| [<System.Obsolete "Removed in v4; use BeforeInit">] BeforeProcessNode
| [<System.Obsolete "Removed in v4; use BeforeProcess">] BeforeProcessNode
/// <summary>Triggered before an HTTP request is made</summary>
| BeforeRequest
/// <summary>Triggered before an HTTP response is processed (cancelable)</summary>
| BeforeResponse
/// <summary>Triggered before a history restore request is made</summary>
| BeforeRestoreHistory
@@ -129,13 +138,13 @@ type HxEvent =
| [<System.Obsolete "Removed in v4; use BeforeRequest">] BeforeSend
/// <summary>Triggered before a Server Sent Events (SSE) message is read</summary>
| BeforeSseMessage
| [<System.Obsolete "Removed in v4; use Htmax.HxEvents.BeforeSseMessage">] BeforeSseMessage
/// <summary>Triggered before a Server Sent Events (SSE) connection is reconnected</summary>
| BeforeSseReconnect
| [<System.Obsolete "Removed in v4; use fetch event handlers">] BeforeSseReconnect
/// <summary>Triggered before a Server Sent Events (SSE) stream is opened</summary>
| BeforeSseStream
| [<System.Obsolete "Removed in v4; SSE is assumed to be a stream">] BeforeSseStream
/// <summary>Triggered before a swap is done, allows you to configure the swap</summary>
| BeforeSwap
@@ -199,16 +208,16 @@ type HxEvent =
| [<System.Obsolete "Removed in v4; use AfterPushIntoHistory (or AfterHistoryUpdate to catch new and updated content)">] PushedIntoHistory
/// <summary>Triggered when an HTTP response error (non-200 or 300 response code) occurs</summary>
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] ResponseError
| ResponseError
/// <summary>Triggered when a network error prevents an HTTP request from happening</summary>
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SendError
/// <summary>Triggered when an error occurs with a SSE source</summary>
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SseError
| [<System.Obsolete "Removed in v4; use Htmax.HxEvents.SseError)">] SseError
/// <summary>Triggered when an SSE source is opened</summary>
| [<System.Obsolete "Removed in v4; use fetch event listener">] SseOpen
| [<System.Obsolete "Removed in v4; use Htmax.HxEvents.AfterSseConnection">] SseOpen
/// <summary>Triggered when an error occurs during the swap phase</summary>
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SwapError
@@ -229,10 +238,10 @@ type HxEvent =
| [<System.Obsolete "Removed in v4; use native validation API">] ValidationHalted
/// <summary>Triggered when an ajax request aborts</summary>
| [<System.Obsolete "Removed in v4; use fetch event listeners">] XhrAbort
| [<System.Obsolete "Removed in v4; use fetch event listeners or Error event">] XhrAbort
/// <summary>Triggered when an ajax request ends</summary>
| [<System.Obsolete "Removed in v4; use fetch event listeners">] XhrLoadEnd
| [<System.Obsolete "Removed in v4; use fetch event listeners or FinallyRequest event">] XhrLoadEnd
/// <summary>Triggered when an ajax request starts</summary>
| [<System.Obsolete "Removed in v4; use fetch event listeners">] XhrLoadStart
@@ -247,11 +256,11 @@ type HxEvent =
AfterHistoryUpdate, ("afterHistoryUpdate", "after:history:update")
AfterInit, ("afterInit", "after:init")
AfterOnLoad, ("afterOnLoad", "after:init")
AfterProcessNode, ("afterProcessNode", "after:init")
AfterProcessNode, ("afterProcessNode", "after:process")
AfterPushIntoHistory, ("afterPushIntoHistory", "after:push:into:history")
AfterReplaceIntoHistory, ("afterReplaceIntoHistory", "after:replace:into:history")
AfterRequest, ("afterRequest", "after:request")
AfterSettle, ("afterSettle", "after:swap")
AfterSettle, ("afterSettle", "after:settle")
AfterSseMessage, ("afterSseMessage", "after:sse:message")
AfterSseStream, ("afterSseStream", "after:sse:stream")
AfterSwap, ("afterSwap", "after:swap")
@@ -262,9 +271,11 @@ type HxEvent =
BeforeHistoryUpdate, ("beforeHistoryUpdate", "before:history:update")
BeforeInit, ("beforeInit", "before:init")
BeforeOnLoad, ("beforeOnLoad", "before:init")
BeforeProcessNode, ("beforeProcessNode", "before:init")
BeforeRestoreHistory, ("beforeRestoreHistory", "before:restore:history")
BeforeProcess, ("beforeProcess", "before:process")
BeforeProcessNode, ("beforeProcessNode", "before:process")
BeforeRequest, ("beforeRequest", "before:request")
BeforeResponse, ("beforeResponse", "before:response")
BeforeRestoreHistory, ("beforeRestoreHistory", "before:restore:history")
BeforeSend, ("beforeSend", "before:request")
BeforeSseMessage, ("beforeSseMessage", "before:sse:message")
BeforeSseReconnect, ("beforeSseReconnect", "before:sse:reconnect")
@@ -288,18 +299,18 @@ type HxEvent =
OobErrorNoTarget, ("oobErrorNoTarget", "error")
Prompt, ("prompt", "prompt")
PushedIntoHistory, ("pushedIntoHistory", "after:push:into:history")
ResponseError, ("responseError", "error")
ResponseError, ("responseError", "response:error")
SendError, ("sendError", "error")
SseError, ("sseError", "error")
SseOpen, ("sseOpen", "sse-open")
SseError, ("sseError", "sse:error")
SseOpen, ("sseOpen", "after:sse:connection")
SwapError, ("swapError", "error")
TargetError, ("targetError", "error")
Timeout, ("timeout", "error")
ValidationValidate, ("validation:validate", "validation:validate")
ValidationFailed, ("validation:failed", "validation:failed")
ValidationHalted, ("validation:halted", "validation:halted")
XhrAbort, ("xhr:abort", "xhr:abort")
XhrLoadEnd, ("xhr:loadend", "xhr:loadend")
XhrAbort, ("xhr:abort", "error")
XhrLoadEnd, ("xhr:loadend", "finally:request")
XhrLoadStart, ("xhr:loadstart", "xhr:loadstart")
XhrProgress, ("xhr:progress", "xhr:progress")
]
@@ -610,12 +621,14 @@ module HtmxAttrs =
/// <summary>The URL which will receive the request (use with <c>_hxMethod</c>)</summary>
/// <param name="url">The URL for the attribute</param>
/// <seealso href="https://four.htmx.org/attributes/hx-action/">Documentation</seealso>
let _hxAction url = attr "hx-action" url
let _hxAction url =
attr "hx-action" url
/// <summary>Progressively enhances anchors and forms to use AJAX requests</summary>
/// <remarks>Use <c>_hxNoBoost</c> to set to false</remarks>
/// <seealso href="https://htmx.org/attributes/hx-boost/">Documentation</seealso>
let _hxBoost = attr "hx-boost" "true"
let _hxBoost =
attr "hx-boost" "true"
/// <summary>Configure request behavior</summary>
/// <param name="config">The configuration parameters to use for the request</param>
@@ -753,11 +766,12 @@ module HtmxAttrs =
/// <summary>Attach an event handler for htmx events</summary>
/// <param name="hxEvent">The <c>HxEvent</c> to be handled</param>
/// <param name="handler">The script to be executed when the event occurs</param>
/// <returns>A configured <c>hx-on::</c> attribute</returns>
/// <returns>A configured <c>hx-on:htmx:</c> attribute</returns>
/// <remarks>For events defined in htmax, use <c>_hxOnMax</c></remarks>
/// <seealso cref="HxEvent" />
/// <seealso href="https://htmx.org/attributes/hx-on/">Documentation</seealso>
let _hxOnHxEvent (hxEvent: HxEvent) handler =
_hxOnEvent $":{hxEvent.ToHxOnString()}" handler
_hxOnEvent $"htmx:{hxEvent.ToHxOnString()}" handler
/// <summary>Filters the parameters that will be submitted with a request</summary>
/// <param name="toInclude">The fields to include (use <c>HxParams</c> to generate this value)</param>
@@ -852,6 +866,31 @@ module HtmxAttrs =
let _hxSelectOob selectors =
attr "hx-select-oob" selectors
/// <summary>Define a response to an HTTP status code or code range</summary>
/// <param name="code">
/// The code or code range; for a code, pass the full code as a string (ex. <c>404</c>), and for a range, pass a
/// string with one or two characters (ex. <c>5</c> for all 500s, <c>42</c> for 420-429)
/// </param>
/// <param name="swap">The swap style to use for this action(use <c>HxSwap</c> values)</param>
/// <param name="action">
/// The action which should be taken for responses matching the status code; can be a combination of the following,
/// with each item separated by a space:
/// <ul>
/// <li><c>target:</c> and a CSS selector for the swap target (overrides original <c>hx-target</c>)</li>
/// <li><c>select:</c> and a CSS selector for the content to be swapped (overrides original <c>hx-select</c>)</li>
/// <li><c>push:</c> and <c>true</c>, <c>false</c>, or a URL; <c>false</c> does not update URL history, <c>true</c>
/// updates with the current URL, and a string URL will be pushed into history as-is</li>
/// <li><c>replace:</c> and <c>true</c>, <c>false</c>, or a URL; same as <c>push:</c>, but replaces in history
/// instead</li>
/// <li><c>transition:</c> and <c>true</c> or <c>false</c>; whether to use view transitions</li>
/// </ul>
/// If only the type of swap is being changed, pass an empty string to this parameter.
/// </param>
/// <seealso href="https://four.htmx.org/reference/attributes/hx-status">Documentation</seealso>
let _hxStatus code swap action =
let range = $"%s{code}xx".Substring(0, 3)
attr $"hx-status:{range}" ($"swap:%s{swap} %s{action}".Trim())
/// <summary>
/// Controls how the response content is swapped into the DOM (e.g. <c>outerHTML</c> or <c>beforeEnd</c>)
/// </summary>
@@ -927,14 +966,14 @@ module HtmxAttrs =
/// <param name="url">The URL from which events will be received</param>
/// <returns>A configured <c>sse-connect</c> attribute</returns>
/// <seealso href="https://htmx.org/extensions/sse/#usage">Extension Docs</seealso>
let _sseConnect url =
let [<System.Obsolete "Removed in v4; use Htmax._hxSseConnect">] _sseConnect url =
attr "sse-connect" url
/// <summary>The name(s) of the message(s) to swap into the DOM</summary>
/// <param name="messages">The message names (comma-delimited) to swap (use "message" for unnamed events)</param>
/// <returns>A configured <c>sse-swap</c> attribute</returns>
/// <seealso href="https://htmx.org/extensions/sse/#usage">Extension Docs</seealso>
let _sseSwap messages =
let [<System.Obsolete "Removed in v4; use hx-swap on target element">] _sseSwap messages =
attr "sse-swap" messages
@@ -978,16 +1017,36 @@ module Script =
/// <summary>Script tag to load the minified version from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnMinified =
script [ _src "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha8/dist/htmx.min.js"
_integrity "sha384-hUj4cz/Dd2p+Dq0r8A6TAMS1u7gu2bTyisk8xCQX3nodazPP+fRmcAWJrTh4Ycwb"
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js"
_integrity "sha384-aWZK1NtOs/aWb/+YZdTM8q2JkWEshlMc9mgZ189numT9bwFhyAyYEoO4nO/2dTXt"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the unminified version from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnUnminified =
script [ _src "https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-alpha8/dist/htmx.js"
_integrity "sha384-CHKZYHwIgmpkwoWtoPaiFIiMxP1Up7yHcsZ2NeECzLxRTXCO0mqXlujZwdJgFsFC"
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js"
_integrity "sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx"
_crossorigin "anonymous" ] []
/// <summary>Script tags to load the htmax bundle</summary>
module Max =
/// <summary>Script tag to load the package-provided version of the htmx-plus-extensions bundle</summary>
let local = script [ _src htmaxLocalScript ] []
/// <summary>Script tag to load the minified htmx-plus-extensions bundle from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnMinified =
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js"
_integrity "sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the unminified htmx-plus-extensions bundle from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnUnminified =
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js"
_integrity "sha384-gGi3Urue6ZkE4NrJCmXWIZkfNkrt1IrdP3fr0kb/v06GWg3V1RnD9Pg/Ul3qhtAK"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the minified version from jsdelivr.net</summary>
[<Obsolete "Use cdnMinified instead; this will be removed in v4">]