WIP on v4 conversion

This commit is contained in:
2026-01-06 12:04:11 -05:00
parent 121eb95d87
commit 915e291a4e
4 changed files with 207 additions and 41 deletions

View File

@@ -3,7 +3,7 @@
module Giraffe.Htmx.Common module Giraffe.Htmx.Common
/// <summary>The version of htmx embedded in the package</summary> /// <summary>The version of htmx embedded in the package</summary>
let HtmxVersion = "2.0.8" let HtmxVersion = "4.0.0-alpha6"
/// <summary>The path for the provided htmx script</summary> /// <summary>The path for the provided htmx script</summary>
let internal htmxLocalScript = $"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}" let internal htmxLocalScript = $"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"
@@ -25,8 +25,8 @@ let internal toLowerBool (boolValue: bool) =
/// <summary>Valid values for the <c>hx-swap</c> attribute / <c>HX-Reswap</c> header</summary> /// <summary>Valid values for the <c>hx-swap</c> attribute / <c>HX-Reswap</c> header</summary>
/// <remarks>May be combined with <c>swap</c> / <c>settle</c> / <c>scroll</c> / <c>show</c> config)</remarks> /// <remarks>May be combined with <c>swap</c> / <c>scroll</c> / <c>show</c> config)</remarks>
/// <seealso href="https://htmx.org/attributes/hx-swap/">Documentation</seealso> /// <seealso href="https://four.htmx.org/attributes/hx-swap/">Documentation</seealso>
[<RequireQualifiedAccess>] [<RequireQualifiedAccess>]
module HxSwap = module HxSwap =
@@ -38,22 +38,60 @@ module HxSwap =
[<Literal>] [<Literal>]
let OuterHtml = "outerHTML" let OuterHtml = "outerHTML"
/// <summary>Morph the inner HTML of the target to the new content</summary>
[<Literal>]
let InnerMorph = "innerMorph"
/// <summary>Morph the outer HTML of the target to the new content</summary>
[<Literal>]
let OuterMorph = "innerMorph"
/// <summary>Replace the text content of the target without parsing the response as HTML</summary>
[<Literal>]
let TextContent = "textContent"
/// <summary>Insert the response before the target element</summary> /// <summary>Insert the response before the target element</summary>
[<Literal>] [<Literal>]
let BeforeBegin = "beforebegin" let Before = "before"
/// <summary>Insert the response before the target element (pre-v4 name)</summary>
[<Literal>]
let BeforeBegin = Before
/// <summary>Insert the response before the first child of the target element</summary> /// <summary>Insert the response before the first child of the target element</summary>
[<Literal>] [<Literal>]
let AfterBegin = "afterbegin" let Prepend = "prepend"
/// <summary>Insert the response before the first child of the target element (pre-v4 name)</summary>
[<Literal>]
let AfterBegin = Prepend
/// <summary>Insert the response after the last child of the target element</summary> /// <summary>Insert the response after the last child of the target element</summary>
[<Literal>] [<Literal>]
let BeforeEnd = "beforeend" let Append = "append"
/// <summary>Insert the response after the last child of the target element (pre-v4 name)</summary>
[<Literal>]
let BeforeEnd = Append
/// <summary>Insert the response after the target element</summary> /// <summary>Insert the response after the target element</summary>
[<Literal>] [<Literal>]
let AfterEnd = "afterend" let After = "after"
/// <summary>Insert the response after the target element (pre-v4 name)</summary>
[<Literal>]
let AfterEnd = After
/// <summary>Does not append content from response (out of band items will still be processed).</summary> /// <summary>Delete the target element regardless of response</summary>
[<Literal>]
let Delete = "delete"
/// <summary>Does not append content from response (out of band items will still be processed)</summary>
[<Literal>] [<Literal>]
let None = "none" let None = "none"
/// <summary>Update existing elements by <c>id</c> and add new ones</summary>
/// <remarks>This requires the <c>upsert</c> extension</remarks>
/// <seealso href="https://four.htmx.org/extensions/upsert">Extension</seealso>
[<Literal>]
let Upsert = "upsert"

View File

@@ -24,6 +24,7 @@ type IHeaderDictionary with
with get () = hdr this "HX-History-Restore-Request" |> Option.map bool.Parse with get () = hdr this "HX-History-Restore-Request" |> Option.map bool.Parse
/// <summary>The user response to an <c>hx-prompt</c></summary> /// <summary>The user response to an <c>hx-prompt</c></summary>
[<Obsolete "hx-prompt is removed in v4">]
member this.HxPrompt member this.HxPrompt
with get () = hdr this "HX-Prompt" with get () = hdr this "HX-Prompt"
@@ -31,15 +32,29 @@ type IHeaderDictionary with
member this.HxRequest member this.HxRequest
with get () = hdr this "HX-Request" |> Option.map bool.Parse with get () = hdr this "HX-Request" |> Option.map bool.Parse
/// <summary>The tag name (fst) and <c>id</c> attribute (snd) of the element triggering this request</summary>
member this.HxSource
with get () =
match hdr this "HX-Source" with
| Some src ->
let parts = src.Split "#"
if parts.Length = 1 then
Some (parts[0], None)
else
Some (parts[0], if parts[1] <> "" then Some parts[1] else None)
| None -> None
/// <summary>The <c>id</c> attribute of the target element if it exists</summary> /// <summary>The <c>id</c> attribute of the target element if it exists</summary>
member this.HxTarget member this.HxTarget
with get () = hdr this "HX-Target" with get () = hdr this "HX-Target"
/// <summary>The <c>id</c> attribute of the triggered element if it exists</summary> /// <summary>The <c>id</c> attribute of the triggered element if it exists</summary>
[<Obsolete "HX-Trigger is removed in v4; use the second item of HX-Source">]
member this.HxTrigger member this.HxTrigger
with get () = hdr this "HX-Trigger" with get () = hdr this "HX-Trigger"
/// <summary>The <c>name</c> attribute of the triggered element if it exists</summary> /// <summary>The <c>name</c> attribute of the triggered element if it exists</summary>
[<Obsolete "HX-Trigger-Name is removed in v4; may be available via extension, but will be removed from this library">]
member this.HxTriggerName member this.HxTriggerName
with get () = hdr this "HX-Trigger-Name" with get () = hdr this "HX-Trigger-Name"

View File

@@ -6,7 +6,7 @@ open Giraffe.Htmx
/// Test to ensure the version was updated /// Test to ensure the version was updated
let version = let version =
test "HtmxVersion is correct" { test "HtmxVersion is correct" {
Expect.equal HtmxVersion "2.0.8" "htmx version incorrect" Expect.equal HtmxVersion "4.0.0-alpha6" "htmx version incorrect"
} }
/// Tests for the HxSwap module /// Tests for the HxSwap module
@@ -18,21 +18,48 @@ let swap =
test "OuterHtml is correct" { test "OuterHtml is correct" {
Expect.equal HxSwap.OuterHtml "outerHTML" "Outer HTML swap value incorrect" Expect.equal HxSwap.OuterHtml "outerHTML" "Outer HTML swap value incorrect"
} }
test "BeforeBegin is correct" { test "InnerMorph is correct" {
Expect.equal HxSwap.BeforeBegin "beforebegin" "Before Begin swap value incorrect" Expect.equal HxSwap.InnerMorph "innerMorph" "Inner Morph swap value incorrect"
} }
test "BeforeEnd is correct" { test "OuterMorph is correct" {
Expect.equal HxSwap.BeforeEnd "beforeend" "Before End swap value incorrect" Expect.equal HxSwap.OuterMorph "innerMorph" "Outer Morph swap value incorrect"
}
test "TextContent is correct" {
Expect.equal HxSwap.TextContent "textContent" "Text Content swap value incorrect"
}
test "Before is correct" {
Expect.equal HxSwap.Before "before" "Before swap value incorrect"
}
test "BeforeBegin is correct" {
Expect.equal HxSwap.BeforeBegin HxSwap.Before "Before Begin swap value incorrect"
}
test "Prepend is correct" {
Expect.equal HxSwap.Prepend "prepend" "Prepend swap value incorrect"
} }
test "AfterBegin is correct" { test "AfterBegin is correct" {
Expect.equal HxSwap.AfterBegin "afterbegin" "After Begin swap value incorrect" Expect.equal HxSwap.AfterBegin HxSwap.Prepend "Prepend swap value incorrect"
}
test "Append is correct" {
Expect.equal HxSwap.Append "append" "Append swap value incorrect"
}
test "BeforeEnd is correct" {
Expect.equal HxSwap.BeforeEnd HxSwap.Append "Before End swap value incorrect"
}
test "After is correct" {
Expect.equal HxSwap.After "after" "After swap value incorrect"
} }
test "AfterEnd is correct" { test "AfterEnd is correct" {
Expect.equal HxSwap.AfterEnd "afterend" "After End swap value incorrect" Expect.equal HxSwap.AfterEnd HxSwap.After "After End swap value incorrect"
}
test "Delete is correct" {
Expect.equal HxSwap.Delete "delete" "Delete swap value incorrect"
} }
test "None is correct" { test "None is correct" {
Expect.equal HxSwap.None "none" "None swap value incorrect" Expect.equal HxSwap.None "none" "None swap value incorrect"
} }
test "Upsert is correct" {
Expect.equal HxSwap.Upsert "upsert" "Upsert swap value incorrect"
}
] ]
/// All tests for this module /// All tests for this module

View File

@@ -1,6 +1,8 @@
/// <summary>Types and functions supporting htmx attributes in Giraffe View Engine</summary> /// <summary>Types and functions supporting htmx attributes in Giraffe View Engine</summary>
module Giraffe.ViewEngine.Htmx module Giraffe.ViewEngine.Htmx
open System.Net.Http
/// <summary>Valid values for the <c>hx-encoding</c> attribute</summary> /// <summary>Valid values for the <c>hx-encoding</c> attribute</summary>
[<RequireQualifiedAccess>] [<RequireQualifiedAccess>]
module HxEncoding = module HxEncoding =
@@ -21,17 +23,20 @@ type HxEvent =
/// <summary>Send this event to an element to abort a request</summary> /// <summary>Send this event to an element to abort a request</summary>
| Abort | Abort
/// <summary>Triggered after a request has initialized</summary>
| AfterInit
/// <summary>Triggered after an AJAX request has completed processing a successful response</summary> /// <summary>Triggered after an AJAX request has completed processing a successful response</summary>
| AfterOnLoad | [<System.Obsolete "Removed in v4; use AfterInit">] AfterOnLoad
/// <summary>Triggered after htmx has initialized a node</summary> /// <summary>Triggered after htmx has initialized a node</summary>
| AfterProcessNode | [<System.Obsolete "Removed in v4; use AfterInit">] AfterProcessNode
/// <summary>Triggered after an AJAX request has completed</summary> /// <summary>Triggered after an AJAX request has completed</summary>
| AfterRequest | AfterRequest
/// <summary>Triggered after the DOM has settled</summary> /// <summary>Triggered after the DOM has settled</summary>
| AfterSettle | [<System.Obsolete "Removed in v4; use AfterSwap">] AfterSettle
/// <summary>Triggered after new content has been swapped in</summary> /// <summary>Triggered after new content has been swapped in</summary>
| AfterSwap | AfterSwap
@@ -39,20 +44,32 @@ type HxEvent =
/// <summary>Triggered before htmx disables an element or removes it from the DOM</summary> /// <summary>Triggered before htmx disables an element or removes it from the DOM</summary>
| BeforeCleanupElement | BeforeCleanupElement
/// <summary>Triggered before content is saved to the history cache</summary>
| [<System.Obsolete "Removed in v4; use BeforeHistoryUpdate">] BeforeHistorySave
/// <summary>Triggered before content is saved to the history cache</summary>
| BeforeHistoryUpdate
/// <summary>Triggered before htmx initializes a node</summary>
| BeforeInit
/// <summary>Triggered before any response processing occurs</summary> /// <summary>Triggered before any response processing occurs</summary>
| BeforeOnLoad | [<System.Obsolete "Removed in v4; use BeforeInit">] BeforeOnLoad
/// <summary>Triggered before htmx initializes a node</summary> /// <summary>Triggered before htmx initializes a node</summary>
| BeforeProcessNode | BeforeProcessNode
/// <summary>Triggered before an AJAX request is made</summary> /// <summary>Triggered before an HTTP request is made</summary>
| BeforeRequest | BeforeRequest
/// <summary>Triggered just before an ajax request is sent</summary>
| [<System.Obsolete "Removed in v4; use BeforeRequest">] BeforeSend
/// <summary>Triggered before a swap is done, allows you to configure the swap</summary> /// <summary>Triggered before a swap is done, allows you to configure the swap</summary>
| BeforeSwap | BeforeSwap
/// <summary>Triggered just before an ajax request is sent</summary> /// <summary>Triggered before a CSS view transition starts</summary>
| BeforeSend | BeforeTransition
/// <summary>Triggered before the request, allows you to customize parameters, headers</summary> /// <summary>Triggered before the request, allows you to customize parameters, headers</summary>
| ConfigRequest | ConfigRequest
@@ -77,9 +94,6 @@ type HxEvent =
/// <summary>Triggered when htmx handles a history restoration action</summary> /// <summary>Triggered when htmx handles a history restoration action</summary>
| HistoryRestore | HistoryRestore
/// <summary>Triggered before content is saved to the history cache</summary>
| BeforeHistorySave
/// <summary>Triggered when new content is added to the DOM</summary> /// <summary>Triggered when new content is added to the DOM</summary>
| Load | Load
@@ -151,25 +165,29 @@ type HxEvent =
/// The htmx event name (fst) and kebab-case name (snd, for use with hx-on) /// The htmx event name (fst) and kebab-case name (snd, for use with hx-on)
static member private Values = Map [ static member private Values = Map [
Abort, ("abort", "abort") Abort, ("abort", "abort")
AfterOnLoad, ("afterOnLoad", "after-on-load") AfterInit, ("afterInit", "after:init")
AfterProcessNode, ("afterProcessNode", "after-process-node") AfterOnLoad, ("afterOnLoad", "after:init")
AfterRequest, ("afterRequest", "after-request") AfterProcessNode, ("afterProcessNode", "after:init")
AfterSettle, ("afterSettle", "after-settle") AfterRequest, ("afterRequest", "after:request")
AfterSwap, ("afterSwap", "after-swap") AfterSettle, ("afterSettle", "after:swap")
BeforeCleanupElement, ("beforeCleanupElement", "before-cleanup-element") AfterSwap, ("afterSwap", "after:swap")
BeforeOnLoad, ("beforeOnLoad", "before-on-load") BeforeCleanupElement, ("beforeCleanupElement", "before:cleanup:element")
BeforeProcessNode, ("beforeProcessNode", "before-process-node") BeforeHistorySave, ("beforeHistorySave", "before:history:update")
BeforeRequest, ("beforeRequest", "before-request") BeforeHistoryUpdate, ("beforeHistoryUpdate", "before:history:update")
BeforeSwap, ("beforeSwap", "before-swap") BeforeInit, ("beforeInit", "before:init")
BeforeSend, ("beforeSend", "before-send") BeforeOnLoad, ("beforeOnLoad", "before:init")
ConfigRequest, ("configRequest", "config-request") BeforeProcessNode, ("beforeProcessNode", "before:process")
BeforeRequest, ("beforeRequest", "before:request")
BeforeSend, ("beforeSend", "before:send")
BeforeSwap, ("beforeSwap", "before:swap")
BeforeTransition, ("beforeTransition", "before:viewTransition")
ConfigRequest, ("configRequest", "config:request")
Confirm, ("confirm", "confirm") Confirm, ("confirm", "confirm")
HistoryCacheError, ("historyCacheError", "history-cache-error") HistoryCacheError, ("historyCacheError", "history-cache-error")
HistoryCacheMiss, ("historyCacheMiss", "history-cache-miss") HistoryCacheMiss, ("historyCacheMiss", "history-cache-miss")
HistoryCacheMissError, ("historyCacheMissError", "history-cache-miss-error") HistoryCacheMissError, ("historyCacheMissError", "history-cache-miss-error")
HistoryCacheMissLoad, ("historyCacheMissLoad", "history-cache-miss-load") HistoryCacheMissLoad, ("historyCacheMissLoad", "history-cache-miss-load")
HistoryRestore, ("historyRestore", "history-restore") HistoryRestore, ("historyRestore", "history-restore")
BeforeHistorySave, ("beforeHistorySave", "before-history-save")
Load, ("load", "load") Load, ("load", "load")
NoSseSourceError, ("noSSESourceError", "no-sse-source-error") NoSseSourceError, ("noSSESourceError", "no-sse-source-error")
OnLoadError, ("onLoadError", "on-load-error") OnLoadError, ("onLoadError", "on-load-error")
@@ -493,11 +511,23 @@ open Giraffe.Htmx
[<AutoOpen>] [<AutoOpen>]
module HtmxAttrs = 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
/// <summary>Progressively enhances anchors and forms to use AJAX requests</summary> /// <summary>Progressively enhances anchors and forms to use AJAX requests</summary>
/// <remarks>Use <c>_hxNoBoost</c> to set to false</remarks> /// <remarks>Use <c>_hxNoBoost</c> to set to false</remarks>
/// <seealso href="https://htmx.org/attributes/hx-boost/">Documentation</seealso> /// <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>
/// <returns>A configured <c>hx-config</c> attribute</returns>
/// <seealso cref="https://four.htmx.org/attributes/hx-config/">Documentation</seealso>
let _hxConfig config =
attr "hx-config" (toJson config)
/// <summary>Shows a <c>confirm()</c> dialog before issuing a request</summary> /// <summary>Shows a <c>confirm()</c> dialog before issuing a request</summary>
/// <param name="prompt">The prompt to present to the user when seeking their confirmation</param> /// <param name="prompt">The prompt to present to the user when seeking their confirmation</param>
/// <returns>A configured <c>hx-confirm</c> attribute</returns> /// <returns>A configured <c>hx-confirm</c> attribute</returns>
@@ -512,14 +542,23 @@ module HtmxAttrs =
let _hxDelete url = let _hxDelete url =
attr "hx-delete" url attr "hx-delete" url
/// <summary>Disables htmx processing for the given node and any children nodes</summary> /// <summary>Specifies elements that should be disabled when an htmx request is in flight</summary>
/// <seealso href="https://htmx.org/attributes/hx-disable/">Documentation</seealso> /// <param name="elt">The element to disable when an htmx request is in flight</param>
let _hxDisable = flag "hx-disable" /// <returns>A configured <c>hx-disable</c> attribute</returns>
/// <remarks>This behavior changed in v4
/// <ul><li>For the v2 behavior of <c>hx-disable</c> (which will manifest as compile errors), change instances to
/// <c>_hxIgnore</c></li>
/// <li>For v4 behavior, changing <c>_hxDisabledElt</c> to <c>_hxDisable</c> should be sufficient</li></ul>
/// </remarks>
/// <seealso href="https://four.htmx.org/attributes/hx-disable/">Documentation</seealso>
let _hxDisable elt =
attr "hx-disable" elt
/// <summary>Specifies elements that should be disabled when an htmx request is in flight</summary> /// <summary>Specifies elements that should be disabled when an htmx request is in flight</summary>
/// <param name="elt">The element to disable when an htmx request is in flight</param> /// <param name="elt">The element to disable when an htmx request is in flight</param>
/// <returns>A configured <c>hx-disabled-elt</c> attribute</returns> /// <returns>A configured <c>hx-disabled-elt</c> attribute</returns>
/// <seealso href="https://htmx.org/attributes/hx-disabled-elt/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-disabled-elt/">Documentation</seealso>
[<System.Obsolete "hx-disabled-elt has become hx-disable in v4">]
let _hxDisabledElt elt = let _hxDisabledElt elt =
attr "hx-disabled-elt" elt attr "hx-disabled-elt" elt
@@ -527,6 +566,7 @@ module HtmxAttrs =
/// <param name="hxAttrs">The htmx attributes to disinherit (should start with "hx-")</param> /// <param name="hxAttrs">The htmx attributes to disinherit (should start with "hx-")</param>
/// <returns>A configured <c>hx-disinherit</c> attribute</returns> /// <returns>A configured <c>hx-disinherit</c> attribute</returns>
/// <seealso href="https://htmx.org/attributes/hx-disinherit/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-disinherit/">Documentation</seealso>
[<System.Obsolete "hx-disinherit removed in v4; use explicit inheritance">]
let _hxDisinherit hxAttrs = let _hxDisinherit hxAttrs =
attr "hx-disinherit" hxAttrs attr "hx-disinherit" hxAttrs
@@ -542,6 +582,7 @@ module HtmxAttrs =
/// <param name="exts">A list of extensions to apply to this element</param> /// <param name="exts">A list of extensions to apply to this element</param>
/// <returns>A configured <c>hx-ext</c> attribute</returns> /// <returns>A configured <c>hx-ext</c> attribute</returns>
/// <seealso href="https://htmx.org/attributes/hx-ext/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-ext/">Documentation</seealso>
[<System.Obsolete "hx-ext removed in v4; extensions register via JavaScript">]
let _hxExt exts = let _hxExt exts =
attr "hx-ext" exts attr "hx-ext" exts
@@ -565,14 +606,21 @@ module HtmxAttrs =
/// <param name="shouldStore">Whether the page should be stored in the history cache</param> /// <param name="shouldStore">Whether the page should be stored in the history cache</param>
/// <returns>A configured <c>hx-history</c> attribute</returns> /// <returns>A configured <c>hx-history</c> attribute</returns>
/// <seealso href="https://htmx.org/attributes/hx-history/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-history/">Documentation</seealso>
[<System.Obsolete "hx-history removed in v4; history does not use localStorage">]
let _hxHistory shouldStore = let _hxHistory shouldStore =
attr "hx-history" (toLowerBool shouldStore) attr "hx-history" (toLowerBool shouldStore)
/// <summary>The element to snapshot and restore during history navigation</summary> /// <summary>The element to snapshot and restore during history navigation</summary>
/// <seealso href="https://htmx.org/attributes/hx-history-elt/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-history-elt/">Documentation</seealso>
[<System.Obsolete "hx-history-elt removed in v4; history based on target element">]
let _hxHistoryElt = let _hxHistoryElt =
flag "hx-history-elt" flag "hx-history-elt"
/// <summary>Disables htmx processing for the given node and any children nodes</summary>
/// <seealso href="https://four.htmx.org/attributes/hx-ignore/">Documentation</seealso>
let _hxIgnore =
flag "hx-ignore"
/// <summary>Includes additional data in AJAX requests</summary> /// <summary>Includes additional data in AJAX requests</summary>
/// <param name="spec">The specification of what should be included in the request</param> /// <param name="spec">The specification of what should be included in the request</param>
/// <returns>A configured <c>hx-include</c> attribute</returns> /// <returns>A configured <c>hx-include</c> attribute</returns>
@@ -587,6 +635,12 @@ module HtmxAttrs =
let _hxIndicator selector = let _hxIndicator selector =
attr "hx-indicator" selector attr "hx-indicator" selector
/// <summary>The HTTP method to use for the request(use with <c>_hxAction</c>)</summary>
/// <param name="method">The method to use</param>
/// <seealso href="https://four.htmx.org/attributes/hx-method/">Documentation</seealso>
let _hxMethod (method: HttpMethod) =
attr "hx-method" (method.Method.ToLowerInvariant())
/// <summary>Overrides a previous <c>hx-boost</c> (hx-boost="false")</summary> /// <summary>Overrides a previous <c>hx-boost</c> (hx-boost="false")</summary>
/// <seealso href="https://htmx.org/attributes/hx-boost/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-boost/">Documentation</seealso>
let _hxNoBoost = let _hxNoBoost =
@@ -614,6 +668,7 @@ module HtmxAttrs =
/// <returns>A configured <c>hx-params</c> attribute</returns> /// <returns>A configured <c>hx-params</c> attribute</returns>
/// <seealso cref="HxParams" /> /// <seealso cref="HxParams" />
/// <seealso href="https://htmx.org/attributes/hx-params/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-params/">Documentation</seealso>
[<System.Obsolete "hx-params removed in v4; use htmx:config:request to filter parameter">]
let _hxParams toInclude = let _hxParams toInclude =
attr "hx-params" toInclude attr "hx-params" toInclude
@@ -641,6 +696,7 @@ module HtmxAttrs =
/// <returns>A configured <c>hx-prompt</c> attribute</returns> /// <returns>A configured <c>hx-prompt</c> attribute</returns>
/// <remarks>The value provided will be in the <c>HX-Prompt</c> request header</remarks> /// <remarks>The value provided will be in the <c>HX-Prompt</c> request header</remarks>
/// <seealso href="https://htmx.org/attributes/hx-prompt/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-prompt/">Documentation</seealso>
[<System.Obsolete "hx-prompt removed in v4; use hx-confirm with async JavaScript function">]
let _hxPrompt text = let _hxPrompt text =
attr "hx-prompt" text attr "hx-prompt" text
@@ -682,6 +738,7 @@ module HtmxAttrs =
/// <returns>A configured <c>hx-request</c> attribute</returns> /// <returns>A configured <c>hx-request</c> attribute</returns>
/// <seealso cref="HxRequest.Configure" /> /// <seealso cref="HxRequest.Configure" />
/// <seealso href="https://htmx.org/attributes/hx-request/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-request/">Documentation</seealso>
[<System.Obsolete "hx-request removed in v4; use hx-config instead">]
let _hxRequest spec = let _hxRequest spec =
attr "hx-request" spec attr "hx-request" spec
@@ -785,6 +842,35 @@ module HtmxAttrs =
attr "sse-swap" messages attr "sse-swap" messages
/// <summary>Modifiers for htmx attributes</summary>
[<AutoOpen>]
module HxModifiers =
/// <summary>Append this value to any inherited value of the attribute</summary>
/// <param name="attrib">The attribute to which <c>:append</c> should be applied</param>
/// <returns>The given attribute with <c>:append</c> applied</returns>
let hxAppend attrib =
match attrib with
| KeyValue (name, value) -> attr $"{name}:append" value
| Boolean name -> flag $"{name}:append"
/// <summary>Explicity inherit the value for this attribute</summary>
/// <param name="attrib">The attribute whose value should be inherited</param>
/// <returns>The given attribute with <c>:inherited</c> applied</returns>
let hxInherit attrib =
match attrib with
| KeyValue (name, value) -> attr $"{name}:inherited" value
| Boolean name -> flag $"{name}:inherited"
/// <summary>htmx-specific HTML tags</summary>
[<AutoOpen>]
module HxTags =
/// <summary>An <c>hx-partial</c> tag</summary>
let hxPartial = tag "hx-partial"
/// <summary>Script tags to pull htmx into a web page</summary> /// <summary>Script tags to pull htmx into a web page</summary>
module Script = module Script =