Compare commits
2
Commits
v4.0.0-beta4
...
v4.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a762fbdd5 | ||
|
|
59b64ed834 |
@@ -11,14 +11,14 @@ htmx uses attributes and HTTP headers to attain its interactivity; the libraries
|
||||
`Giraffe.Htmx` provides extensions that facilitate using htmx on the server side, primarily reading and setting headers. `Giraffe.ViewEngine.Htmx` provides attributes and helpers to produce views that utilize htmx. Both can be installed from NuGet via standard methods.
|
||||
|
||||
| Server Side | View Engine |
|
||||
|---|---|
|
||||
|[](https://www.nuget.org/packages/Giraffe.Htmx/)|[](https://www.nuget.org/packages/Giraffe.ViewEngine.Htmx/)|
|
||||
|------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| [](https://www.nuget.org/packages/Giraffe.Htmx/) | [](https://www.nuget.org/packages/Giraffe.ViewEngine.Htmx/) |
|
||||
|
||||
Both of these packages will also install `Giraffe.Htmx.Common`, which has some common definitions and provides a local-to-your-project version of the htmx JavaScript _(as of v2.0.8)_.
|
||||
Both of these packages will also install `Giraffe.Htmx.Common`, which has some common definitions and provides a local-to-your-project version of the htmx JavaScript _(as of v2.0.8)_ and htmax htmx-plus-extensions bundle _(as of v4.0.0-beta4)_.
|
||||
|
||||
## Server Side (`Giraffe.Htmx`)
|
||||
|
||||
In addition to the regular HTTP request payloads, htmx sets [one or more headers](https://htmx.org/docs/#request_headers) along with the request. Once `Giraffe.Htmx` is opened, these are available as properties on `HttpContext.Request.Headers`. These consist of the header name, translated to a .NET name (ex. `HX-Current-URL` becomes `HxCurrentUrl`), and a strongly-typed property based on the expected value of that header. Additionally, they are all exposed as `Option`s, as they may or may not be present for any given request.
|
||||
In addition to the regular HTTP request payloads, htmx sets [one or more headers](https://four.htmx.org/reference/headers#request) along with the request. Once `Giraffe.Htmx` is opened, these are available as properties on `HttpContext.Request.Headers`. These consist of the header name, translated to a .NET name (ex. `HX-Current-URL` becomes `HxCurrentUrl`), and a strongly-typed property based on the expected value of that header. Additionally, they are all exposed as `Option`s, as they may or may not be present for any given request.
|
||||
|
||||
A server may want to respond to a request that originated from htmx differently than a regular request. One way htmx can provide the same feel as a Single Page Application (SPA) is by swapping out the `body` content (or an element within it) instead of reloading the entire page. In this case, the developer can provide a partial layout to be used for these responses, while returning the full page for regular requests. The `IsHtmx` property makes this easy...
|
||||
|
||||
@@ -33,7 +33,7 @@ let result view : HttpHandler =
|
||||
full view
|
||||
```
|
||||
|
||||
htmx also utilizes [response headers](https://htmx.org/docs/#response_headers) to affect client-side behavior. For each of these, this library provides `HttpHandler`s that can be chained along with the response. As an example, if the server returns a redirect response (301, 302, 303, 307), the `XMLHttpRequest` handler on the client will follow the redirection before htmx can do anything with it. To redirect to a new page, you would return an OK (200) response with an `HX-Redirect` header set in the response.
|
||||
htmx also utilizes [response headers](https://four.htmx.org/reference/headers#response) to affect client-side behavior. For each of these, this library provides `HttpHandler`s that can be chained along with the response. As an example, if the server returns a redirect response (301, 302, 303, 307), the `fetch` handler on the client may follow the redirection before htmx can do anything with it. To redirect to a new page, you would return an OK (200) response with an `HX-Redirect` header set in the response.
|
||||
|
||||
```fsharp
|
||||
let theHandler : HttpHandler =
|
||||
@@ -44,11 +44,11 @@ let theHandler : HttpHandler =
|
||||
|
||||
Of note is that the `HX-Trigger` headers can take either one or more events. For a single event with no parameters, use `withHxTrigger`; for a single event with parameters, or multiple events, use `withHxTriggerMany`. Both these have `AfterSettle` and `AfterSwap` versions as well.
|
||||
|
||||
`HtmxScript.local` provides an `HtmlString` with a script tag to load the package-provided htmx library. This can be used in code, Razor templates, etc. (If you're using Giraffe.ViewEngine, see below.)
|
||||
`HtmxScript.local` provides an `HtmlString` with a script tag to load the package-provided htmx library, along with `localMax` to load the htmx-plus-extensions bundle. This can be used in code, Razor templates, etc. (If you're using Giraffe.ViewEngine, see below.)
|
||||
|
||||
## View Engine (`Giraffe.ViewEngine.Htmx`)
|
||||
|
||||
As htmx uses [attributes](https://htmx.org/docs/#attributes) to extend HTML, the primary part of this library defines attributes that can be used within Giraffe views. Simply open `Giraffe.ViewEngine.Htmx`, and these attributes, along with support modules, will be visible.
|
||||
As htmx uses [attributes](https://four.htmx.org/reference/attributes) to extend HTML, the primary part of this library defines attributes that can be used within Giraffe views. Simply open `Giraffe.ViewEngine.Htmx`, and these attributes, along with support modules, will be visible.
|
||||
|
||||
As an example, creating a `div` that loads data once the HTML is rendered:
|
||||
|
||||
@@ -70,11 +70,11 @@ let shiftClick =
|
||||
]
|
||||
```
|
||||
|
||||
If you want to use the package-provided htmx library, `Htmx.Script.local` will create the `script` tag for you. To load htmx from jsDelivr, `Htmx.Script.cdnMinified` or `Htmx.Script.cdnUnminified` can be used to load the script in your HTML trees. In this case, if you are using a Content Security Policy (CSP) header, `cdn.jsdelivr.net` will need to be added to the `script-src` list.
|
||||
If you want to use the package-provided htmx library, `Htmx.Script.local` will create the `script` tag for you (as well as `Htmx.Script.Max.local` to load the htmax bundle). To load htmx from jsDelivr, `Htmx.Script.cdnMinified` or `Htmx.Script.cdnUnminified` can be used to load the script in your HTML trees (these also have `.Max` variants). In this case, if you are using a Content Security Policy (CSP) header, `cdn.jsdelivr.net` will need to be added to the `script-src` list.
|
||||
|
||||
## Feedback / Help
|
||||
|
||||
The author hangs out in the #dotnet-htmx channel (and most others) of the [htmx Discord server](https://htmx.org/discord) and the #web channel of the [F# Software Foundation's Slack server](https://fsharp.org/guides/slack/).
|
||||
The author hangs out in the #dotnet-htmx channel (and most others) of the [htmx Discord server](https://htmx.org/discord) and the #web channel (and most others) of the [F# Community Discord server](https://discord.gg/R6n7c54).
|
||||
|
||||
## Thanks
|
||||
|[<img src="https://giraffe.wiki/giraffe.png" alt="Giraffe logo" width="200">](https://giraffe.wiki)| [<img src="https://bitbadger.solutions/upload/bit-badger/2024/01/htmx-black-transparent.svg" alt="htmx logo" width="200">](https://htmx.org) |[<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main)" width="200">](https://jb.gg/OpenSource)|
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
module Giraffe.Htmx.Common
|
||||
|
||||
/// <summary>The version of htmx embedded in the package</summary>
|
||||
let HtmxVersion = "4.0.0-beta4"
|
||||
let HtmxVersion = "4.0.0"
|
||||
|
||||
/// <summary>The path for the provided htmx script</summary>
|
||||
let internal htmxLocalScript = $"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"
|
||||
/// <summary>URLs for the included htmx library static web assets</summary>
|
||||
module StaticAssetUrl =
|
||||
/// <summary>The path for the provided htmx script</summary>
|
||||
let htmx = $"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"
|
||||
|
||||
/// <summary>The path for the provided htmax script</summary>
|
||||
let internal htmaxLocalScript = $"/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"
|
||||
/// <summary>The path for the provided htmax script</summary>
|
||||
let htmax = $"/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"
|
||||
|
||||
/// <summary>Serialize a list of key/value pairs to JSON (very rudimentary)</summary>
|
||||
/// <param name="pairs">The key/value pairs to be serialized to JSON</param>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Giraffe.Htmx.Common
|
||||
|
||||
This package contains common code shared between [`Giraffe.Htmx`](https://www.nuget.org/packages/Giraffe.Htmx) and [`Giraffe.ViewEngine.Htmx`](https://www.nuget.org/packages/Giraffe.ViewEngine.Htmx), and will be automatically installed when you install either one. It also contains htmx as a static web asset, allowing it to be loaded from your local (or published) project.
|
||||
This package contains common code shared between [`Giraffe.Htmx`](https://www.nuget.org/packages/Giraffe.Htmx) and [`Giraffe.ViewEngine.Htmx`](https://www.nuget.org/packages/Giraffe.ViewEngine.Htmx), and will be automatically installed when you install either one. It also contains htmx and htmax as static web assets, allowing them to be loaded from your local (or published) project.
|
||||
|
||||
**htmx version: 4.0.0-beta4**
|
||||
**htmx version: 4.0.0**
|
||||
|
||||
_**NOTE:** Pay special attention to breaking changes highlighted in the packages listed above._
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -3,17 +3,10 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
|
||||
<VersionPrefix>4.0.0</VersionPrefix>
|
||||
<VersionSuffix>beta4</VersionSuffix>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<PackageReleaseNotes>Update htmx 4 to beta4
|
||||
- [Common] Update provided htmx 4 to 4.0.0-beta4
|
||||
- [Common] Add htmax bundle to provided version
|
||||
- [Server] Update HX-Target header to return tag and ID (similar to HX-Source)
|
||||
- [Server] Add support for HX-Request-Type header
|
||||
- [View Engine] Add hx-status attribute, outerSync swap
|
||||
- [View Engine] Updated script tags to pull htmx 4.0.0-beta4, added "max" bundle links for local and CDN
|
||||
<PackageReleaseNotes>htmx 4.0.0 Initial Release
|
||||
|
||||
See package and prior alpha release READMEs; v2 to v4 is not an update-and-forget-it release
|
||||
See package and prior alpha/beta release READMEs; v2 to v4 is not an update-and-forget-it release. If you encounter build errors after installing this, install v4.0.0-beta5 instead; obsolete elements will generate a warning with suggestions of what to use instead.
|
||||
</PackageReleaseNotes>
|
||||
<Authors>danieljsummers</Authors>
|
||||
<Company>Bit Badger Solutions</Company>
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Expecto" Version="11.0.0" />
|
||||
<PackageVersion Include="Giraffe" Version="8.2.0" />
|
||||
<PackageVersion Include="Expecto" Version="11.1.0" />
|
||||
<PackageVersion Include="Giraffe" Version="8.3.0" />
|
||||
<PackageVersion Include="Giraffe.ViewEngine" Version="1.4.0" />
|
||||
<PackageVersion Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageVersion Include="FSharp.Core" Version="10.1.301" />
|
||||
<PackageVersion Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageVersion Include="FSharp.Core" Version="10.1.400" />
|
||||
<!-- <PackageVersion Update="FSharp.Core" Version="10.0.0" /> -->
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+4
-44
@@ -37,7 +37,7 @@ type IHeaderDictionary with
|
||||
with get () = hdr this "HX-Preloaded" |> Option.map bool.Parse
|
||||
|
||||
/// <summary>The user response to an <c>hx-prompt</c></summary>
|
||||
[<Obsolete "hx-prompt is removed in v4">]
|
||||
/// <remarks><b>NEW IN v4:</b> This functionality is dependent on the hx-prompt extension being loaded</remarks>
|
||||
member this.HxPrompt
|
||||
with get () = hdr this "HX-Prompt"
|
||||
|
||||
@@ -91,16 +91,6 @@ type IHeaderDictionary with
|
||||
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">]
|
||||
member this.HxTrigger
|
||||
with get () = hdr this "HX-Trigger"
|
||||
|
||||
/// <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
|
||||
with get () = hdr this "HX-Trigger-Name"
|
||||
|
||||
|
||||
/// Extensions for the request object
|
||||
type HttpRequest with
|
||||
@@ -209,38 +199,6 @@ module Handlers =
|
||||
let withHxTriggerMany evts : HttpHandler =
|
||||
toJson evts |> setHttpHeader "HX-Trigger"
|
||||
|
||||
/// <summary>Allows you to trigger a single client side event after changes have settled</summary>
|
||||
/// <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" 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"
|
||||
|
||||
/// <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" 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"
|
||||
|
||||
|
||||
/// <summary>Load the package-provided version of the htmx script</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
@@ -250,5 +208,7 @@ module HtmxScript =
|
||||
open Microsoft.AspNetCore.Html
|
||||
|
||||
/// <summary><c>script</c> tag to load the package-provided version of the htmx script</summary>
|
||||
let local = HtmlString $"""<script src="{htmxLocalScript}"></script>"""
|
||||
let local = HtmlString $"""<script src="{StaticAssetUrl.htmx}"></script>"""
|
||||
|
||||
/// <summary><c>script</c> tag to load the package-provided version of the htmax script</summary>
|
||||
let localMax = HtmlString $"""<script src="{StaticAssetUrl.htmax}"></script>"""
|
||||
|
||||
+3
-3
@@ -2,9 +2,9 @@
|
||||
|
||||
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
|
||||
|
||||
**htmx version: 4.0.0-beta4**
|
||||
**htmx version: 4.0.0**
|
||||
|
||||
_Upgrading from v2.x: the [migration guide](https://four.htmx.org/docs/get-started/migration) lists changes for v4. For this package, the `HX-Trigger` and `HX-Trigger-Name` headers are marked obsolete. They are replaced by `HX-Source`, which provides the triggering tag name and `id` attribute. The `HX-Prompt` header has also been marked as obsolete, as the `hx-prompt` attribute which generated its content has been removed._
|
||||
_Upgrading from v2.x: the [migration guide](https://four.htmx.org/docs#migrating-from-htmx-2x-to-4x) lists changes for v4. For this package, the `HX-Trigger` and `HX-Trigger-Name` headers are marked obsolete. They are replaced by `HX-Source`, which provides the triggering tag name and `id` attribute. The `HX-Prompt` header has also been marked as obsolete, as the `hx-prompt` attribute which generated its content has been removed._
|
||||
|
||||
_Obsolete elements will be removed in the first production v4 release._
|
||||
|
||||
@@ -36,7 +36,7 @@ let myHandler : HttpHander =
|
||||
|
||||
The `HxSwap` module has constants to use for the `HX-Reswap` header. These may be extended with settle, show, and other qualifiers; see the htmx documentation for the `hx-swap` attribute for more information.
|
||||
|
||||
To load the package-provided htmx library without using Giraffe.ViewEngine, use `HtmxScript.local`.
|
||||
To load the package-provided htmx library without using Giraffe.ViewEngine, use `HtmxScript.local`; to load the htmax bundle, use `HtmxScript.localMax`.
|
||||
|
||||
### Learn
|
||||
|
||||
|
||||
+18
-2
@@ -6,9 +6,25 @@ open Giraffe.Htmx
|
||||
/// Test to ensure the version was updated
|
||||
let version =
|
||||
test "HtmxVersion is correct" {
|
||||
Expect.equal HtmxVersion "4.0.0-beta4" "htmx version incorrect"
|
||||
Expect.equal HtmxVersion "4.0.0" "htmx version incorrect"
|
||||
}
|
||||
|
||||
let staticAssetUrl =
|
||||
testList "StaticAssetUrl" [
|
||||
test "htmx is correct" {
|
||||
Expect.equal
|
||||
StaticAssetUrl.htmx
|
||||
$"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"
|
||||
"Static htmx URL incorrect"
|
||||
}
|
||||
test "htmax is correct" {
|
||||
Expect.equal
|
||||
StaticAssetUrl.htmax
|
||||
$"/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"
|
||||
"Static htmx URL incorrect"
|
||||
}
|
||||
]
|
||||
|
||||
/// Tests for the HxSwap module
|
||||
let swap =
|
||||
testList "HxSwap" [
|
||||
@@ -69,4 +85,4 @@ let swap =
|
||||
]
|
||||
|
||||
/// All tests for this module
|
||||
let allTests = testList "Htmx.Common" [ version; swap ]
|
||||
let allTests = testList "Htmx.Common" [ version; staticAssetUrl; swap ]
|
||||
|
||||
+21
-86
@@ -97,6 +97,21 @@ let dictExtensions =
|
||||
Expect.isFalse ctx.Request.Headers.HxPreloaded.Value "The header should have been false"
|
||||
}
|
||||
]
|
||||
testList "HxPrompt" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxPrompt "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Prompt", "of course")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxPrompt "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxPrompt.Value "of course" "The header value was incorrect"
|
||||
}
|
||||
]
|
||||
testList "HxRequest" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
@@ -418,93 +433,13 @@ let script =
|
||||
$"""<script src="/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"></script>"""
|
||||
"htmx script link is incorrect"
|
||||
}
|
||||
]
|
||||
|
||||
#nowarn 44 // Obsolete items still have tests
|
||||
let dictExtensionsObs =
|
||||
testList "IHeaderDictionaryExtensions (Obsolete)" [
|
||||
testList "HxPrompt" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxPrompt "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Prompt", "of course")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxPrompt "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxPrompt.Value "of course" "The header value was incorrect"
|
||||
}
|
||||
]
|
||||
testList "HxTrigger" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs (HeaderDictionary ()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxTrigger "There should not have been a header returned"
|
||||
}
|
||||
test "succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Trigger", "#trig")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxTrigger "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxTrigger.Value "#trig" "The header value was incorrect"
|
||||
}
|
||||
]
|
||||
testList "HxTriggerName" [
|
||||
test "succeeds when the header is not present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
ctx.Request.Headers.ReturnsForAnyArgs(HeaderDictionary()) |> ignore
|
||||
Expect.isNone ctx.Request.Headers.HxTriggerName "There should not have been a header returned"
|
||||
}
|
||||
test "HxTriggerName succeeds when the header is present" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
dic.Add("HX-Trigger-Name", "click")
|
||||
ctx.Request.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
Expect.isSome ctx.Request.Headers.HxTriggerName "There should be a header present"
|
||||
Expect.equal ctx.Request.Headers.HxTriggerName.Value "click" "The header value was incorrect"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
let handlerObs =
|
||||
testList "Handler Tests (Obsolete)" [
|
||||
testTask "withHxTriggerAfterSettle succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerAfterSettle "byTheWay" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger") "The HX-Trigger header should be present"
|
||||
Expect.equal dic["HX-Trigger"].[0] "byTheWay" "The HX-Trigger value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerManyAfterSettle succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerManyAfterSettle [ "oof", "ouch"; "hmm", "uh" ] next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger") "The HX-Trigger header should be present"
|
||||
Expect.equal dic["HX-Trigger"].[0] """{ "oof": "ouch", "hmm": "uh" }""" "The HX-Trigger value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerAfterSwap succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerAfterSwap "justASec" next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger") "The HX-Trigger header should be present"
|
||||
Expect.equal dic["HX-Trigger"].[0] "justASec" "The HX-Trigger value was incorrect"
|
||||
}
|
||||
testTask "withHxTriggerManyAfterSwap succeeds" {
|
||||
let ctx = Substitute.For<HttpContext>()
|
||||
let dic = HeaderDictionary()
|
||||
ctx.Response.Headers.ReturnsForAnyArgs dic |> ignore
|
||||
let! _ = withHxTriggerManyAfterSwap [ "this", "1"; "that", "2" ] next ctx
|
||||
Expect.isTrue (dic.ContainsKey "HX-Trigger") "The HX-Trigger header should be present"
|
||||
Expect.equal dic["HX-Trigger"].[0] """{ "this": "1", "that": "2" }""" "The HX-Trigger value was incorrect"
|
||||
test "localMax generates correct link" {
|
||||
Expect.equal
|
||||
(string HtmxScript.localMax)
|
||||
$"""<script src="/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"></script>"""
|
||||
"htmx script link is incorrect"
|
||||
}
|
||||
]
|
||||
|
||||
/// All tests for this module
|
||||
let allTests = testList "Htmx" [ dictExtensions; reqExtensions; handlers; script; dictExtensionsObs; handlerObs ]
|
||||
let allTests = testList "Htmx" [ dictExtensions; reqExtensions; handlers; script ]
|
||||
|
||||
+8
-477
@@ -569,6 +569,10 @@ let attributes =
|
||||
test "_hxPreserve succeeds" {
|
||||
img [ _hxPreserve ] |> shouldRender """<img hx-preserve>"""
|
||||
}
|
||||
test "_hxPrompt succeeds" {
|
||||
strong [ _hxPrompt "Who goes there?" ] []
|
||||
|> shouldRender """<strong hx-prompt="Who goes there?"></strong>"""
|
||||
}
|
||||
test "_hxPushUrl succeeds" {
|
||||
dl [ _hxPushUrl "/a-b-c" ] [] |> shouldRender """<dl hx-push-url="/a-b-c"></dl>"""
|
||||
}
|
||||
@@ -677,14 +681,14 @@ let script =
|
||||
let html = RenderView.AsString.htmlNode Script.cdnMinified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha384-aWZK1NtOs/aWb/+YZdTM8q2JkWEshlMc9mgZ189numT9bwFhyAyYEoO4nO/2dTXt" crossorigin="anonymous"></script>"""
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.min.js" integrity="sha384-BvJpBiO8Kh31EqtJe5DRIeWrHWnCGkwytKs9NKFi86Hhw96dEqdEMzZDeK9iEGTc" crossorigin="anonymous"></script>"""
|
||||
"CDN minified script tag is incorrect"
|
||||
}
|
||||
test "cdnUnminified succeeds" {
|
||||
let html = RenderView.AsString.htmlNode Script.cdnUnminified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" integrity="sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx" crossorigin="anonymous"></script>"""
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" integrity="sha384-ESzWv77gBOAGtF3d7B8QiQ786cghRRsyhuYVVJGsrFGxwT0Dj1fLxReX9Ul6t4n9" crossorigin="anonymous"></script>"""
|
||||
"CDN unminified script tag is incorrect"
|
||||
}
|
||||
testList "Max" [
|
||||
@@ -699,14 +703,14 @@ let script =
|
||||
let html = RenderView.AsString.htmlNode Script.Max.cdnMinified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js" integrity="sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF" crossorigin="anonymous"></script>"""
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js" integrity="sha384-F2+P/m0g8+he+KLpgsCVZlZGvOx2z83bU4rmmISSNt7br4A0RTcJ7ddMrz0v45Nv" crossorigin="anonymous"></script>"""
|
||||
"CDN minified script tag is incorrect"
|
||||
}
|
||||
test "cdnMaxUnminified succeeds" {
|
||||
let html = RenderView.AsString.htmlNode Script.Max.cdnUnminified
|
||||
Expect.equal
|
||||
html
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js" integrity="sha384-gGi3Urue6ZkE4NrJCmXWIZkfNkrt1IrdP3fr0kb/v06GWg3V1RnD9Pg/Ul3qhtAK" crossorigin="anonymous"></script>"""
|
||||
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js" integrity="sha384-wrTFbAj755gAdIPPR9n4aAVMkLWkzxjr1Zj+8D4kgr2App4h9doO6SXBH9wpivij" crossorigin="anonymous"></script>"""
|
||||
"CDN unminified script tag is incorrect"
|
||||
}
|
||||
]
|
||||
@@ -859,478 +863,6 @@ let renderFragment =
|
||||
]
|
||||
]
|
||||
|
||||
#nowarn 44 // Obsolete events still have tests
|
||||
|
||||
let hxEventObs =
|
||||
testList "HxEvent (Obsolete)" [
|
||||
testList "AfterOnLoad" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterOnLoad) "afterOnLoad" "AfterOnLoad event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (AfterOnLoad.ToHxOnString()) "after:init" "AfterOnLoad hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterProcessNode" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterProcessNode) "afterProcessNode" "AfterProcessNode event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterProcessNode.ToHxOnString()) "after:process" "AfterProcessNode hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSseMessage" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterSseMessage) "afterSseMessage" "AfterSseMessage event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterSseMessage.ToHxOnString()) "after:sse:message" "AfterSseMessage hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "AfterSseStream" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string AfterSseStream) "afterSseStream" "AfterSseStream event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(AfterSseStream.ToHxOnString()) "after:sse:stream" "AfterSseStream hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeCleanupElement" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string BeforeCleanupElement) "beforeCleanupElement" "BeforeCleanupElement event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeCleanupElement.ToHxOnString())
|
||||
"before:cleanup"
|
||||
"BeforeCleanupElement hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeHistorySave" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeHistorySave) "beforeHistorySave" "BeforeHistorySave event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeHistorySave.ToHxOnString())
|
||||
"before:history:update"
|
||||
"BeforeHistorySave hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeOnLoad" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeOnLoad) "beforeOnLoad" "BeforeOnLoad event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (BeforeOnLoad.ToHxOnString()) "before:init" "BeforeOnLoad hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeProcessNode" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeProcessNode) "beforeProcessNode" "BeforeProcessNode event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeProcessNode.ToHxOnString()) "before:process" "BeforeProcessNode hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSend" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSend) "beforeSend" "BeforeSend event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (BeforeSend.ToHxOnString()) "before:request" "BeforeSend hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseMessage" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSseMessage) "beforeSseMessage" "BeforeSseMessage event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseMessage.ToHxOnString())
|
||||
"before:sse:message"
|
||||
"BeforeSseMessage hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseReconnect" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string BeforeSseReconnect) "beforeSseReconnect" "BeforeSseReconnect event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseReconnect.ToHxOnString())
|
||||
"before:sse:reconnect"
|
||||
"BeforeSseReconnect hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "BeforeSseStream" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string BeforeSseStream) "beforeSseStream" "BeforeSseStream event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(BeforeSseStream.ToHxOnString()) "before:sse:stream" "BeforeSseStream hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "HistoryCacheError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string HistoryCacheError) "historyCacheError" "HistoryCacheError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(HistoryCacheError.ToHxOnString())
|
||||
"history-cache-error"
|
||||
"HistoryCacheError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "HistoryCacheMiss" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string HistoryCacheMiss) "historyCacheMiss" "HistoryCacheMiss event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(HistoryCacheMiss.ToHxOnString())
|
||||
"before:history:restore"
|
||||
"HistoryCacheMiss hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "HistoryCacheMissError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string HistoryCacheMissError)
|
||||
"historyCacheMissError"
|
||||
"HistoryCacheMissError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(HistoryCacheMissError.ToHxOnString())
|
||||
"history-cache-miss-error"
|
||||
"HistoryCacheMissError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "HistoryCacheMissLoad" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string HistoryCacheMissLoad) "historyCacheMissLoad" "HistoryCacheMissLoad event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(HistoryCacheMissLoad.ToHxOnString())
|
||||
"before:history:restore"
|
||||
"HistoryCacheMissLoad hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "HistoryRestore" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string HistoryRestore) "historyRestore" "HistoryRestore event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(HistoryRestore.ToHxOnString())
|
||||
"before:history:restore"
|
||||
"HistoryRestore hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "Load" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string Load) "load" "Load event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (Load.ToHxOnString()) "after:init" "Load hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "NoSseSourceError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string NoSseSourceError) "noSSESourceError" "NoSseSourceError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (NoSseSourceError.ToHxOnString()) "error" "NoSseSourceError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "OnLoadError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string OnLoadError) "onLoadError" "OnLoadError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (OnLoadError.ToHxOnString()) "error" "OnLoadError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "OobAfterSwap" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string OobAfterSwap) "oobAfterSwap" "OobAfterSwap event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (OobAfterSwap.ToHxOnString()) "after:swap" "OobAfterSwap hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "OobBeforeSwap" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string OobBeforeSwap) "oobBeforeSwap" "OobBeforeSwap event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (OobBeforeSwap.ToHxOnString()) "before:swap" "OobBeforeSwap hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "OobErrorNoTarget" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string OobErrorNoTarget) "oobErrorNoTarget" "OobErrorNoTarget event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (OobErrorNoTarget.ToHxOnString()) "error" "OobErrorNoTarget hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "Prompt" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string Prompt) "prompt" "Prompt event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (Prompt.ToHxOnString()) "prompt" "Prompt hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "PushedIntoHistory" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string PushedIntoHistory) "pushedIntoHistory" "PushedIntoHistory event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(PushedIntoHistory.ToHxOnString())
|
||||
"after:push:into:history"
|
||||
"PushedIntoHistory hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SendError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string SendError) "sendError" "SendError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (SendError.ToHxOnString()) "error" "SendError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SseError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string SseError) "sseError" "SseError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (SseError.ToHxOnString()) "sse:error" "SseError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SseOpen" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string SseOpen) "sseOpen" "SseOpen event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (SseOpen.ToHxOnString()) "after:sse:connection" "SseOpen hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "SwapError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string SwapError) "swapError" "SwapError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (SwapError.ToHxOnString()) "error" "SwapError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "TargetError" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string TargetError) "targetError" "TargetError event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (TargetError.ToHxOnString()) "error" "TargetError hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "Timeout" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string Timeout) "timeout" "Timeout event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (Timeout.ToHxOnString()) "error" "Timeout hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "ValidationValidate" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal
|
||||
(string ValidationValidate) "validation:validate" "ValidationValidate event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(ValidationValidate.ToHxOnString())
|
||||
"validation:validate"
|
||||
"ValidationValidate hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "ValidationFailed" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string ValidationFailed) "validation:failed" "ValidationFailed event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(ValidationFailed.ToHxOnString())
|
||||
"validation:failed"
|
||||
"ValidationFailed hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "ValidationHalted" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string ValidationHalted) "validation:halted" "ValidationHalted event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal
|
||||
(ValidationHalted.ToHxOnString())
|
||||
"validation:halted"
|
||||
"ValidationHalted hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "XhrAbort" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string XhrAbort) "xhr:abort" "XhrAbort event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (XhrAbort.ToHxOnString()) "error" "XhrAbort hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "XhrLoadEnd" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string XhrLoadEnd) "xhr:loadend" "XhrLoadEnd event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (XhrLoadEnd.ToHxOnString()) "finally:request" "XhrLoadEnd hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "XhrLoadStart" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string XhrLoadStart) "xhr:loadstart" "XhrLoadStart event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (XhrLoadStart.ToHxOnString()) "xhr:loadstart" "XhrLoadStart hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
testList "XhrProgress" [
|
||||
test "ToString succeeds" {
|
||||
Expect.equal (string XhrProgress) "xhr:progress" "XhrProgress event name not correct"
|
||||
}
|
||||
test "ToHxOnString succeeds" {
|
||||
Expect.equal (XhrProgress.ToHxOnString()) "xhr:progress" "XhrProgress hx-on event name not correct"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the HxParams module
|
||||
let hxParamsObs =
|
||||
testList "HxParams" [
|
||||
test "All is correct" {
|
||||
Expect.equal HxParams.All "*" "All is not correct"
|
||||
}
|
||||
test "None is correct" {
|
||||
Expect.equal HxParams.None "none" "None is not correct"
|
||||
}
|
||||
testList "With" [
|
||||
test "succeeds with empty list" {
|
||||
Expect.equal (HxParams.With []) "" "With with empty list should have been blank"
|
||||
}
|
||||
test "succeeds with one list item" {
|
||||
Expect.equal (HxParams.With [ "boo" ]) "boo" "With single item incorrect"
|
||||
}
|
||||
test "succeeds with multiple list items" {
|
||||
Expect.equal (HxParams.With [ "foo"; "bar"; "baz" ]) "foo,bar,baz" "With multiple items incorrect"
|
||||
}
|
||||
]
|
||||
testList "Except" [
|
||||
test "succeeds with empty list" {
|
||||
Expect.equal (HxParams.Except []) "not " "Except with empty list incorrect"
|
||||
}
|
||||
test "succeeds with one list item" {
|
||||
Expect.equal (HxParams.Except [ "that" ]) "not that" "Except single item incorrect"
|
||||
}
|
||||
test "succeeds with multiple list items" {
|
||||
Expect.equal (HxParams.Except [ "blue"; "green" ]) "not blue,green" "Except multiple items incorrect"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
/// Tests for the HxConfig module
|
||||
let hxRequestObs =
|
||||
testList "HxRequest (Obsolete)" [
|
||||
testList "Configure" [
|
||||
test "succeeds with an empty list" {
|
||||
Expect.equal (HxRequest.Configure []) "{ }" "Configure with empty list incorrect"
|
||||
}
|
||||
test "succeeds with a non-empty list" {
|
||||
Expect.equal
|
||||
(HxRequest.Configure [ "\"a\": \"b\""; "\"c\": \"d\"" ]) """{ "a": "b", "c": "d" }"""
|
||||
"Configure with a non-empty list incorrect"
|
||||
}
|
||||
test "succeeds with all known params configured" {
|
||||
Expect.equal
|
||||
(HxRequest.Configure
|
||||
[ HxRequest.Timeout 1000; HxRequest.Credentials false; HxRequest.NoHeaders true ])
|
||||
"""{ "timeout": 1000, "credentials": false, "noHeaders": true }"""
|
||||
"Configure with all known params incorrect"
|
||||
}
|
||||
]
|
||||
test "Timeout succeeds" {
|
||||
Expect.equal (HxRequest.Timeout 50) "\"timeout\": 50" "Timeout value incorrect"
|
||||
}
|
||||
testList "Credentials" [
|
||||
test "succeeds when set to true" {
|
||||
Expect.equal (HxRequest.Credentials true) "\"credentials\": true" "Credentials value incorrect"
|
||||
}
|
||||
test "succeeds when set to false" {
|
||||
Expect.equal (HxRequest.Credentials false) "\"credentials\": false" "Credentials value incorrect"
|
||||
}
|
||||
]
|
||||
testList "NoHeaders" [
|
||||
test "succeeds when set to true" {
|
||||
Expect.equal (HxRequest.NoHeaders true) "\"noHeaders\": true" "NoHeaders value incorrect"
|
||||
}
|
||||
test "succeeds when set to false" {
|
||||
Expect.equal (HxRequest.NoHeaders false) "\"noHeaders\": false" "NoHeaders value incorrect"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
let attributesObs =
|
||||
testList "Attributes (Obsolete)" [
|
||||
test "_hxDisabledElt succeeds" {
|
||||
button [ _hxDisabledElt "this" ] [] |> shouldRender """<button hx-disabled-elt="this"></button>"""
|
||||
}
|
||||
test "_hxDisinherit succeeds" {
|
||||
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
|
||||
}
|
||||
test "_hxExt succeeds" {
|
||||
section [ _hxExt "extendme" ] [] |> shouldRender """<section hx-ext="extendme"></section>"""
|
||||
}
|
||||
test "_hxHistory succeeds" {
|
||||
span [ _hxHistory false ] [] |> shouldRender """<span hx-history="false"></span>"""
|
||||
}
|
||||
test "_hxHistoryElt succeeds" {
|
||||
table [ _hxHistoryElt ] [] |> shouldRender """<table hx-history-elt></table>"""
|
||||
}
|
||||
test "_hxParams succeeds" {
|
||||
br [ _hxParams "[p1,p2]" ] |> shouldRender """<br hx-params="[p1,p2]">"""
|
||||
}
|
||||
test "_hxPrompt succeeds" {
|
||||
strong [ _hxPrompt "Who goes there?" ] []
|
||||
|> shouldRender """<strong hx-prompt="Who goes there?"></strong>"""
|
||||
}
|
||||
test "_hxRequest succeeds" {
|
||||
u [ _hxRequest "noHeaders" ] [] |> shouldRender """<u hx-request="noHeaders"></u>"""
|
||||
}
|
||||
test "_sseConnect succeeds" {
|
||||
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
||||
}
|
||||
test "_sseSwap succeeds" {
|
||||
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
||||
}
|
||||
]
|
||||
|
||||
let obsolete = testList "Obsolete" [ hxEventObs; hxParamsObs; hxRequestObs; attributesObs ]
|
||||
|
||||
/// All tests in this module
|
||||
let allTests =
|
||||
testList "ViewEngine.Htmx" [
|
||||
@@ -1345,5 +877,4 @@ let allTests =
|
||||
hxTags
|
||||
script
|
||||
renderFragment
|
||||
obsolete
|
||||
]
|
||||
|
||||
+12
-310
@@ -50,7 +50,6 @@ module HxEncoding =
|
||||
let MultipartForm = "multipart/form-data"
|
||||
|
||||
|
||||
#nowarn 44 // Obsolete elements still have entries in the conversion map; will be removed for v4 final
|
||||
/// <summary>The events recognized by htmx</summary>
|
||||
/// <seealso href="https://four.htmx.org/events/">Documentation</seealso>
|
||||
[<Struct>]
|
||||
@@ -68,15 +67,9 @@ type HxEvent =
|
||||
/// <summary>Triggered after a request has initialized</summary>
|
||||
| AfterInit
|
||||
|
||||
/// <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 AfterProcess">] AfterProcessNode
|
||||
|
||||
/// <summary>Triggered after new content is saved to the history cache</summary>
|
||||
| AfterPushIntoHistory
|
||||
|
||||
@@ -89,12 +82,6 @@ type HxEvent =
|
||||
/// <summary>Triggered after the DOM has settled</summary>
|
||||
| AfterSettle
|
||||
|
||||
/// <summary>Triggered after a Server Sent Events (SSE) message is read</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Htmax.HxEvents.AfterSseMessage">] AfterSseMessage
|
||||
|
||||
/// <summary>Triggered after a Server Sent Events (SSE) stream is closed</summary>
|
||||
| [<System.Obsolete "Removed in v4; SSE is assumed to be a stream">] AfterSseStream
|
||||
|
||||
/// <summary>Triggered after new content has been swapped in</summary>
|
||||
| AfterSwap
|
||||
|
||||
@@ -104,27 +91,15 @@ type HxEvent =
|
||||
/// <summary>Triggered before htmx disables an element or removes it from the DOM</summary>
|
||||
| BeforeCleanup
|
||||
|
||||
/// <summary>Triggered before htmx disables an element or removes it from the DOM</summary>
|
||||
| [<System.Obsolete "Removed in v4; use BeforeCleanup">] 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>
|
||||
| [<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 BeforeProcess">] BeforeProcessNode
|
||||
|
||||
/// <summary>Triggered before an HTTP request is made</summary>
|
||||
| BeforeRequest
|
||||
|
||||
@@ -134,18 +109,6 @@ type HxEvent =
|
||||
/// <summary>Triggered before a history restore request is made</summary>
|
||||
| BeforeRestoreHistory
|
||||
|
||||
/// <summary>Triggered just before an ajax request is sent</summary>
|
||||
| [<System.Obsolete "Removed in v4; use BeforeRequest">] BeforeSend
|
||||
|
||||
/// <summary>Triggered before a Server Sent Events (SSE) message is read</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Htmax.HxEvents.BeforeSseMessage">] BeforeSseMessage
|
||||
|
||||
/// <summary>Triggered before a Server Sent Events (SSE) connection is reconnected</summary>
|
||||
| [<System.Obsolete "Removed in v4; use fetch event handlers">] BeforeSseReconnect
|
||||
|
||||
/// <summary>Triggered before a Server Sent Events (SSE) stream is opened</summary>
|
||||
| [<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
|
||||
|
||||
@@ -166,153 +129,35 @@ type HxEvent =
|
||||
/// <summary>Triggered after an HTTP request is made, whether it was successful or not</summary>
|
||||
| FinallyRequest
|
||||
|
||||
/// <summary>Triggered on an error during cache writing</summary>
|
||||
| [<System.Obsolete "Removed in v4; history no longer uses localStorage">] HistoryCacheError
|
||||
|
||||
/// <summary>Triggered on a cache miss in the history subsystem</summary>
|
||||
| [<System.Obsolete "Removed in v4; use BeforeRestoreHistory">] HistoryCacheMiss
|
||||
|
||||
/// <summary>Triggered on a unsuccessful remote retrieval</summary>
|
||||
| [<System.Obsolete "Removed in v4; history no longer uses localStorage">] HistoryCacheMissError
|
||||
|
||||
/// <summary>Triggered on a successful remote retrieval</summary>
|
||||
| [<System.Obsolete "Removed in v4; use BeforeRestoreHistory">] HistoryCacheMissLoad
|
||||
|
||||
/// <summary>Triggered when htmx handles a history restoration action</summary>
|
||||
| [<System.Obsolete "Removed in v4; use BeforeRestoreHistory">] HistoryRestore
|
||||
|
||||
/// <summary>Triggered when new content is added to the DOM</summary>
|
||||
| [<System.Obsolete "Removed in v4; use AfterInit">] Load
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when an element refers to a SSE event in its trigger, but no parent SSE source has been defined
|
||||
/// </summary>
|
||||
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] NoSseSourceError
|
||||
|
||||
/// <summary>Triggered when an exception occurs during the onLoad handling in htmx</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] OnLoadError
|
||||
|
||||
/// <summary>Triggered after an out of band element as been swapped in</summary>
|
||||
| [<System.Obsolete "Removed in v4; use AfterSwap (no separate OOB event)">] OobAfterSwap
|
||||
|
||||
/// <summary>Triggered before an out of band element swap is done, allows you to configure the swap</summary>
|
||||
| [<System.Obsolete "Removed in v4; use BeforeSwap (no separate OOB event)">] OobBeforeSwap
|
||||
|
||||
/// <summary>Triggered when an out of band element does not have a matching ID in the current DOM</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] OobErrorNoTarget
|
||||
|
||||
/// <summary>Triggered after a prompt is shown</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Confirm with custom JavaScript">] Prompt
|
||||
|
||||
/// <summary>Triggered after an url is pushed into history</summary>
|
||||
| [<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>
|
||||
| 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 Htmax.HxEvents.SseError)">] SseError
|
||||
|
||||
/// <summary>Triggered when an SSE source is opened</summary>
|
||||
| [<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
|
||||
|
||||
/// <summary>Triggered when an invalid target is specified</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] TargetError
|
||||
|
||||
/// <summary>Triggered when a request timeout occurs</summary>
|
||||
| [<System.Obsolete "Removed in v4; use Error (timeout is exposed as an error)">] Timeout
|
||||
|
||||
/// <summary>Triggered before an element is validated</summary>
|
||||
| [<System.Obsolete "Removed in v4; use native validation API">] ValidationValidate
|
||||
|
||||
/// <summary>Triggered when an element fails validation</summary>
|
||||
| [<System.Obsolete "Removed in v4; use native validation API">] ValidationFailed
|
||||
|
||||
/// <summary>Triggered when a request is halted due to validation errors</summary>
|
||||
| [<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 or Error event">] XhrAbort
|
||||
|
||||
/// <summary>Triggered when an ajax request ends</summary>
|
||||
| [<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
|
||||
|
||||
/// <summary>Triggered periodically during an ajax request that supports progress events</summary>
|
||||
| [<System.Obsolete "Removed in v4; use fetch event listeners">] XhrProgress
|
||||
|
||||
/// The htmx event name (fst) and kebab-case name (snd, for use with hx-on)
|
||||
static member private Values = Map [
|
||||
Abort, ("abort", "abort")
|
||||
AfterCleanup, ("afterCleanup", "after:cleanup")
|
||||
AfterHistoryUpdate, ("afterHistoryUpdate", "after:history:update")
|
||||
AfterInit, ("afterInit", "after:init")
|
||||
AfterOnLoad, ("afterOnLoad", "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:settle")
|
||||
AfterSseMessage, ("afterSseMessage", "after:sse:message")
|
||||
AfterSseStream, ("afterSseStream", "after:sse:stream")
|
||||
AfterSwap, ("afterSwap", "after:swap")
|
||||
AfterViewTransition, ("afterViewTransition", "after:viewTransition")
|
||||
BeforeCleanup, ("beforeCleanup", "before:cleanup")
|
||||
BeforeCleanupElement, ("beforeCleanupElement", "before:cleanup")
|
||||
BeforeHistorySave, ("beforeHistorySave", "before:history:update")
|
||||
BeforeHistoryUpdate, ("beforeHistoryUpdate", "before:history:update")
|
||||
BeforeInit, ("beforeInit", "before:init")
|
||||
BeforeOnLoad, ("beforeOnLoad", "before:init")
|
||||
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")
|
||||
BeforeSseStream, ("beforeSseStream", "before:sse:stream")
|
||||
BeforeSwap, ("beforeSwap", "before:swap")
|
||||
BeforeViewTransition, ("beforeTransition", "before:viewTransition")
|
||||
ConfigRequest, ("configRequest", "config:request")
|
||||
Confirm, ("confirm", "confirm")
|
||||
Error, ("error", "error")
|
||||
FinallyRequest, ("finallyRequest", "finally:request")
|
||||
HistoryCacheError, ("historyCacheError", "history-cache-error")
|
||||
HistoryCacheMiss, ("historyCacheMiss", "before:history:restore")
|
||||
HistoryCacheMissError, ("historyCacheMissError", "history-cache-miss-error")
|
||||
HistoryCacheMissLoad, ("historyCacheMissLoad", "before:history:restore")
|
||||
HistoryRestore, ("historyRestore", "before:history:restore")
|
||||
Load, ("load", "after:init")
|
||||
NoSseSourceError, ("noSSESourceError", "error")
|
||||
OnLoadError, ("onLoadError", "error")
|
||||
OobAfterSwap, ("oobAfterSwap", "after:swap")
|
||||
OobBeforeSwap, ("oobBeforeSwap", "before:swap")
|
||||
OobErrorNoTarget, ("oobErrorNoTarget", "error")
|
||||
Prompt, ("prompt", "prompt")
|
||||
PushedIntoHistory, ("pushedIntoHistory", "after:push:into:history")
|
||||
ResponseError, ("responseError", "response:error")
|
||||
SendError, ("sendError", "error")
|
||||
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", "error")
|
||||
XhrLoadEnd, ("xhr:loadend", "finally:request")
|
||||
XhrLoadStart, ("xhr:loadstart", "xhr:loadstart")
|
||||
XhrProgress, ("xhr:progress", "xhr:progress")
|
||||
]
|
||||
|
||||
/// <summary>The htmx event name</summary>
|
||||
@@ -320,7 +165,6 @@ type HxEvent =
|
||||
|
||||
/// <summary>The <c>hx-on</c> variant of the htmx event name</summary>
|
||||
member this.ToHxOnString() = snd HxEvent.Values[this]
|
||||
#warn 44 // restore obsolete warning
|
||||
|
||||
|
||||
/// <summary>Helper to create the <c>hx-headers</c> attribute</summary>
|
||||
@@ -331,70 +175,6 @@ module HxHeaders =
|
||||
let From = Giraffe.Htmx.Common.toJson
|
||||
|
||||
|
||||
/// <summary>Values / helpers for the <c>hx-params</c> attribute</summary>
|
||||
/// <seealso href="https://htmx.org/attributes/hx-params/">Documentation</seealso>
|
||||
[<RequireQualifiedAccess>]
|
||||
[<System.Obsolete "Removed in v4; filter parameters via JavaScript in configRequest event">]
|
||||
module HxParams =
|
||||
|
||||
/// <summary>Include all parameters</summary>
|
||||
[<Literal>]
|
||||
let All = "*"
|
||||
|
||||
/// <summary>Include no parameters</summary>
|
||||
[<Literal>]
|
||||
let None = "none"
|
||||
|
||||
/// <summary>Include the specified parameters</summary>
|
||||
/// <param name="fields">One or more fields to include in the request</param>
|
||||
/// <returns>The list of fields for the <c>hx-params</c> attribute value</returns>
|
||||
let With fields =
|
||||
match fields with [] -> "" | _ -> fields |> List.reduce (fun acc it -> $"{acc},{it}")
|
||||
|
||||
/// <summary>Exclude the specified parameters</summary>
|
||||
/// <param name="fields">One or more fields to exclude from the request</param>
|
||||
/// <returns>The list of fields for the <c>hx-params</c> attribute value prefixed with "not"</returns>
|
||||
let Except fields =
|
||||
With fields |> sprintf "not %s"
|
||||
|
||||
|
||||
/// <summary>Helpers to define <c>hx-request</c> attribute values</summary>
|
||||
/// <seealso href="https://htmx.org/attributes/hx-request/">Documentation</seealso>
|
||||
[<RequireQualifiedAccess>]
|
||||
[<System.Obsolete "Removed in v4; change to HxConfig">]
|
||||
module HxRequest =
|
||||
|
||||
open Giraffe.Htmx.Common
|
||||
|
||||
/// <summary>Configure the request with various options</summary>
|
||||
/// <param name="opts">The options to configure</param>
|
||||
/// <returns>A string with the configured options</returns>
|
||||
let Configure (opts: string list) =
|
||||
opts
|
||||
|> String.concat ", "
|
||||
|> sprintf "{ %s }"
|
||||
|
||||
/// <summary>Set a timeout (in milliseconds)</summary>
|
||||
/// <param name="ms">The milliseconds for the request timeout</param>
|
||||
/// <returns>A string with the configured request timeout</returns>
|
||||
let Timeout (ms: int) =
|
||||
$"\"timeout\": {ms}"
|
||||
|
||||
/// <summary>Include or exclude credentials from the request</summary>
|
||||
/// <param name="send"><c>true</c> if credentials should be sent, <c>false</c> if not</param>
|
||||
/// <returns>A string with the configured credential options</returns>
|
||||
let Credentials send =
|
||||
(toLowerBool >> sprintf "\"credentials\": %s") send
|
||||
|
||||
/// <summary>Exclude or include headers from the request</summary>
|
||||
/// <param name="exclude">
|
||||
/// <c>true</c> if no headers should be sent; <c>false</c> if headers should be sent
|
||||
/// </param>
|
||||
/// <returns>A string with the configured header options</returns>
|
||||
let NoHeaders exclude =
|
||||
(toLowerBool >> sprintf "\"noHeaders\": %s") exclude
|
||||
|
||||
|
||||
/// <summary>Helpers for the <c>hx-sync</c> attribute</summary>
|
||||
/// <seealso href="https://htmx.org/attributes/hx-sync/">Documentation</seealso>
|
||||
[<RequireQualifiedAccess>]
|
||||
@@ -663,22 +443,6 @@ module HtmxAttrs =
|
||||
let _hxDisable elt =
|
||||
attr "hx-disable" elt
|
||||
|
||||
/// <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>
|
||||
/// <returns>A configured <c>hx-disabled-elt</c> attribute</returns>
|
||||
/// <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 =
|
||||
attr "hx-disabled-elt" elt
|
||||
|
||||
/// <summary>Disinherit all ("*") or specific htmx attributes</summary>
|
||||
/// <param name="hxAttrs">The htmx attributes to disinherit (should start with "hx-")</param>
|
||||
/// <returns>A configured <c>hx-disinherit</c> attribute</returns>
|
||||
/// <seealso href="https://htmx.org/attributes/hx-disinherit/">Documentation</seealso>
|
||||
[<System.Obsolete "hx-disinherit removed in v4; use explicit inheritance">]
|
||||
let _hxDisinherit hxAttrs =
|
||||
attr "hx-disinherit" hxAttrs
|
||||
|
||||
/// <summary>Changes the request encoding type</summary>
|
||||
/// <param name="enc">The encoding type (use <c>HxEncoding</c> constants)</param>
|
||||
/// <returns>A configured <c>hx-encoding</c> attribute</returns>
|
||||
@@ -687,14 +451,6 @@ module HtmxAttrs =
|
||||
let _hxEncoding enc =
|
||||
attr "hx-encoding" enc
|
||||
|
||||
/// <summary>Extensions to use for this element</summary>
|
||||
/// <param name="exts">A list of extensions to apply to this element</param>
|
||||
/// <returns>A configured <c>hx-ext</c> attribute</returns>
|
||||
/// <seealso href="https://htmx.org/attributes/hx-ext/">Documentation</seealso>
|
||||
[<System.Obsolete "hx-ext removed in v4; extensions register via JavaScript">]
|
||||
let _hxExt exts =
|
||||
attr "hx-ext" exts
|
||||
|
||||
/// <summary>Issues a <c>GET</c> to the specified URL</summary>
|
||||
/// <param name="url">The URL to which the <c>GET</c> request should be sent</param>
|
||||
/// <returns>A configured <c>hx-get</c> attribute</returns>
|
||||
@@ -709,22 +465,6 @@ module HtmxAttrs =
|
||||
let _hxHeaders hdrs =
|
||||
attr "hx-headers" hdrs
|
||||
|
||||
/// <summary>
|
||||
/// Set to "false" to prevent pages with sensitive information from being stored in the history cache
|
||||
/// </summary>
|
||||
/// <param name="shouldStore">Whether the page should be stored in the history cache</param>
|
||||
/// <returns>A configured <c>hx-history</c> attribute</returns>
|
||||
/// <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 =
|
||||
attr "hx-history" (toLowerBool shouldStore)
|
||||
|
||||
/// <summary>The element to snapshot and restore during history navigation</summary>
|
||||
/// <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 =
|
||||
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 =
|
||||
@@ -773,15 +513,6 @@ module HtmxAttrs =
|
||||
let _hxOnHxEvent (hxEvent: HxEvent) 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>
|
||||
/// <returns>A configured <c>hx-params</c> attribute</returns>
|
||||
/// <seealso cref="HxParams" />
|
||||
/// <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 =
|
||||
attr "hx-params" toInclude
|
||||
|
||||
/// <summary>Issues a <c>PATCH</c> to the specified URL</summary>
|
||||
/// <param name="url">The URL to which the request should be directed</param>
|
||||
/// <returns>A configured <c>hx-patch</c> attribute</returns>
|
||||
@@ -804,9 +535,13 @@ module HtmxAttrs =
|
||||
/// <summary>Shows a <c>prompt()</c> dialog before submitting a request</summary>
|
||||
/// <param name="text">The text for the prompt</param>
|
||||
/// <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>
|
||||
/// <ul>
|
||||
/// <li><b>NEW IN v4:</b> This functionality is dependent on the hx-prompt extension being loaded</li>
|
||||
/// <li>The value provided will be in the <c>HX-Prompt</c> request header</li>
|
||||
/// </ul>
|
||||
/// </remarks>
|
||||
/// <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 =
|
||||
attr "hx-prompt" text
|
||||
|
||||
@@ -843,15 +578,6 @@ module HtmxAttrs =
|
||||
let _hxReplaceUrl spec =
|
||||
attr "hx-replace-url" spec
|
||||
|
||||
/// <summary>Configures various aspects of the request</summary>
|
||||
/// <param name="spec">The configuration spec (use <c>HxRequest.Configure</c> to create value)</param>
|
||||
/// <returns>A configured <c>hx-request</c> attribute</returns>
|
||||
/// <seealso cref="HxRequest.Configure" />
|
||||
/// <seealso href="https://htmx.org/attributes/hx-request/">Documentation</seealso>
|
||||
[<System.Obsolete "hx-request removed in v4; use hx-config instead">]
|
||||
let _hxRequest spec =
|
||||
attr "hx-request" spec
|
||||
|
||||
/// <summary>Selects a subset of the server response to process</summary>
|
||||
/// <param name="selector">A CSS selector for the content to be selected</param>
|
||||
/// <returns>A configured <c>hx-select</c> attribute</returns>
|
||||
@@ -962,20 +688,6 @@ module HtmxAttrs =
|
||||
let _hxVals values =
|
||||
attr "hx-vals" values
|
||||
|
||||
/// <summary>The URL of the SSE server</summary>
|
||||
/// <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 [<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 [<System.Obsolete "Removed in v4; use hx-swap on target element">] _sseSwap messages =
|
||||
attr "sse-swap" messages
|
||||
|
||||
|
||||
/// <summary>Modifiers for htmx attributes</summary>
|
||||
[<AutoOpen>]
|
||||
@@ -1009,53 +721,43 @@ module HxTags =
|
||||
/// <summary>Script tags to pull htmx into a web page</summary>
|
||||
module Script =
|
||||
|
||||
open System
|
||||
|
||||
/// <summary>Script tag to load the package-provided version of htmx</summary>
|
||||
let local = script [ _src htmxLocalScript ] []
|
||||
let local = script [ _src StaticAssetUrl.htmx ] []
|
||||
|
||||
/// <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@{HtmxVersion}/dist/htmx.min.js"
|
||||
_integrity "sha384-aWZK1NtOs/aWb/+YZdTM8q2JkWEshlMc9mgZ189numT9bwFhyAyYEoO4nO/2dTXt"
|
||||
_integrity "sha384-BvJpBiO8Kh31EqtJe5DRIeWrHWnCGkwytKs9NKFi86Hhw96dEqdEMzZDeK9iEGTc"
|
||||
_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@{HtmxVersion}/dist/htmx.js"
|
||||
_integrity "sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx"
|
||||
_integrity "sha384-ESzWv77gBOAGtF3d7B8QiQ786cghRRsyhuYVVJGsrFGxwT0Dj1fLxReX9Ul6t4n9"
|
||||
_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 ] []
|
||||
let local = script [ _src StaticAssetUrl.htmax ] []
|
||||
|
||||
/// <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"
|
||||
_integrity "sha384-F2+P/m0g8+he+KLpgsCVZlZGvOx2z83bU4rmmISSNt7br4A0RTcJ7ddMrz0v45Nv"
|
||||
_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"
|
||||
_integrity "sha384-wrTFbAj755gAdIPPR9n4aAVMkLWkzxjr1Zj+8D4kgr2App4h9doO6SXBH9wpivij"
|
||||
_crossorigin "anonymous" ] []
|
||||
|
||||
/// <summary>Script tag to load the minified version from jsdelivr.net</summary>
|
||||
[<Obsolete "Use cdnMinified instead; this will be removed in v4">]
|
||||
let minified = cdnMinified
|
||||
|
||||
/// <summary>Script tag to load the unminified version from jsdelivr.net</summary>
|
||||
[<Obsolete "Use cdnUnminified instead; this will be removed in v4">]
|
||||
let unminified = cdnUnminified
|
||||
|
||||
|
||||
/// <summary>Functions to extract and render an HTML fragment from a document</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
||||
|
||||
**htmx version: 4.0.0-beta4**
|
||||
**htmx version: 4.0.0**
|
||||
|
||||
_Upgrading from v2.x: see [the migration guide](https://four.htmx.org/docs/get-started/migration) for changes, which are plentiful. htmx switches from `XMLHTTPRequest` to `fetch`, and many changes are related to the new event cycle._
|
||||
_Upgrading from v2.x: see [the migration guide](https://four.htmx.org/docs#migrating-from-htmx-2x-to-4x) for changes, which are plentiful. htmx switches from `XMLHTTPRequest` to `fetch`, and many changes are related to the new event cycle._
|
||||
|
||||
_Inheritance is now explicit; to have an attribute's value inherited to its children, wrap the attribute in `hxInherited` (ex. `hxInherited (_hxTarget "#main")`). Values can be appended to inherited values as well using the `hxAppend` modifier._
|
||||
|
||||
_Several constructs have been marked obsolete in this release, and will be removed from the first production release of v4. With the exception of `_hxDisable`, though (which now functions as the deprecated `_hxDisabledElt` did), this should not introduce compile errors. Rather, this package will raise warnings for deprecated constructs, along with suggestions of what to use instead._
|
||||
_Several constructs have been removed in this release. If you encounter compile errors, install version `4.0.0-beta5`; it will instead flag these with warnings and suggestions on how to mitigate them. Once the warnings are gone, you can reinstall this version._
|
||||
|
||||
### Setup
|
||||
|
||||
@@ -26,11 +26,9 @@ let autoload =
|
||||
```
|
||||
|
||||
Support modules include:
|
||||
- `HxConfig` _(new in v4)_
|
||||
- `HxConfig` _(new in v4, replaces `HxRequest`)_
|
||||
- `HxEncoding`
|
||||
- `HxHeaders`
|
||||
- ~~`HxParams`~~ _(removed in v4)_
|
||||
- ~~`HxRequest`~~ _(renamed to `HxConfig`)_
|
||||
- `HxSwap` (requires `open Giraffe.Htmx`)
|
||||
- `HxTrigger`
|
||||
- `HxVals`
|
||||
|
||||
Reference in New Issue
Block a user