Sync attrs/hdrs with upstream
This commit is contained in:
+42
-5
@@ -4,6 +4,14 @@ open Microsoft.AspNetCore.Http
|
||||
open Microsoft.Extensions.Primitives
|
||||
open System
|
||||
|
||||
/// <summary>The request types which may be set in the <c>HX-Request</c> header</summary>
|
||||
type HxRequestTypes =
|
||||
/// <summary>A request targeting the <c>body</c> tag or using an <c>hx-select</c> attribute</summary>
|
||||
| HxFullRequest
|
||||
|
||||
/// <summary>A request for partial content</summary>
|
||||
| HxPartialRequest
|
||||
|
||||
/// Determine if the given header is present
|
||||
let private hdr (headers : IHeaderDictionary) hdr =
|
||||
match headers[hdr] with it when it = StringValues.Empty -> None | it -> Some it[0]
|
||||
@@ -32,6 +40,16 @@ type IHeaderDictionary with
|
||||
member this.HxRequest
|
||||
with get () = hdr this "HX-Request" |> Option.map bool.Parse
|
||||
|
||||
/// <summary>The request type sent by htmx</summary>
|
||||
/// <seealso cref="HxRequestTypes" />
|
||||
member this.HxRequestType
|
||||
with get () =
|
||||
match hdr this "HX-Request-Type" with
|
||||
| Some typ when typ = "full" -> Some HxFullRequest
|
||||
| Some typ when typ = "partial" -> Some HxPartialRequest
|
||||
| Some _ -> None
|
||||
| None -> None
|
||||
|
||||
/// <summary>The tag name (fst) and <c>id</c> attribute (snd) of the element triggering this request</summary>
|
||||
member this.HxSource
|
||||
with get () =
|
||||
@@ -45,8 +63,23 @@ type IHeaderDictionary with
|
||||
| None -> None
|
||||
|
||||
/// <summary>The <c>id</c> attribute of the target element if it exists</summary>
|
||||
/// <remarks>
|
||||
/// In v4, this changed to tag name (fst) and <c>id</c> (snd); to resolve build errors, and restore the prior
|
||||
/// behavior of <c>[id] option</c>, replace
|
||||
/// <code>ctx.HxTarget</code>
|
||||
/// with
|
||||
/// <code>ctx.HxTarget |> Option.iter snd</code>
|
||||
/// </remarks>
|
||||
member this.HxTarget
|
||||
with get () = hdr this "HX-Target"
|
||||
with get () =
|
||||
match hdr this "HX-Target" 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 triggered element if it exists</summary>
|
||||
[<Obsolete "HX-Trigger is removed in v4; use the second item of HX-Source">]
|
||||
@@ -162,29 +195,33 @@ module Handlers =
|
||||
/// <param name="evt">The call to the event that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Settle</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
[<Obsolete "Removed in v4; use withHxTrigger">]
|
||||
let withHxTriggerAfterSettle (evt: string) : HttpHandler =
|
||||
setHttpHeader "HX-Trigger-After-Settle" evt
|
||||
setHttpHeader "HX-Trigger" evt
|
||||
|
||||
/// <summary>Allows you to trigger multiple client side events after changes have settled</summary>
|
||||
/// <param name="evts">The calls to events that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Settle</c> header set for all given events</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
[<Obsolete "Removed in v4; use withHxTrigger">]
|
||||
let withHxTriggerManyAfterSettle evts : HttpHandler =
|
||||
toJson evts |> setHttpHeader "HX-Trigger-After-Settle"
|
||||
toJson evts |> setHttpHeader "HX-Trigger"
|
||||
|
||||
/// <summary>Allows you to trigger a single client side event after DOM swapping occurs</summary>
|
||||
/// <param name="evt">The call to the event that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Swap</c> header set</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
[<Obsolete "Removed in v4; use withHxTrigger">]
|
||||
let withHxTriggerAfterSwap (evt: string) : HttpHandler =
|
||||
setHttpHeader "HX-Trigger-After-Swap" evt
|
||||
setHttpHeader "HX-Trigger" evt
|
||||
|
||||
/// <summary>Allows you to trigger multiple client side events after DOM swapping occurs</summary>
|
||||
/// <param name="evts">The calls to events that should be triggered</param>
|
||||
/// <returns>An HTTP handler with the <c>HX-Trigger-After-Swap</c> header set for all given events</returns>
|
||||
/// <seealso href="https://htmx.org/headers/hx-trigger/">Documentation</seealso>
|
||||
[<Obsolete "Removed in v4; use withHxTrigger">]
|
||||
let withHxTriggerManyAfterSwap evts : HttpHandler =
|
||||
toJson evts |> setHttpHeader "HX-Trigger-After-Swap"
|
||||
toJson evts |> setHttpHeader "HX-Trigger"
|
||||
|
||||
|
||||
/// <summary>Load the package-provided version of the htmx script</summary>
|
||||
|
||||
Reference in New Issue
Block a user