Compare commits
31 Commits
v1.9.4
...
5e28714215
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e28714215 | |||
| 28cec1cb70 | |||
| 10c31d77b5 | |||
| f4cd184a15 | |||
| 5626031593 | |||
| f0de18845f | |||
| 961307fd99 | |||
| a2960a79c6 | |||
| 541384a92f | |||
| 8cb5d6bfa7 | |||
| 1a11e3511a | |||
| 32e962416d | |||
| 29839fa795 | |||
| 7f9b3a6234 | |||
| a8d2b819dc | |||
| 1ea05b79ed | |||
| 4f6bb8367a | |||
| b3665a4b72 | |||
| bdb7255a1c | |||
| 9276db7ffe | |||
| 94b68f76c9 | |||
| 90de16529c | |||
| 452f15b2d4 | |||
| 59246ae7f5 | |||
| 16355e8f58 | |||
| 71286b9064 | |||
| 85ac22877c | |||
| dea2323499 | |||
| fcaaa693bc | |||
| 8fd6af8c26 | |||
| 69a4034661 |
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
@@ -2,9 +2,10 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: [ "main", "htmx-version-2" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
build-and-test:
|
||||||
@@ -13,12 +14,12 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
dotnet-version: [ "6.0", "7.0" ]
|
dotnet-version: [ "6.0", "7.0", "8.0" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Setup .NET ${{ matrix.dotnet-version }}.x
|
- name: Setup .NET ${{ matrix.dotnet-version }}.x
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: ${{ matrix.dotnet-version }}.x
|
dotnet-version: ${{ matrix.dotnet-version }}.x
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
@@ -31,11 +32,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build-and-test
|
needs: build-and-test
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Setup .NET
|
- name: Setup .NET
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: "7.0"
|
dotnet-version: "8.0"
|
||||||
- name: Package Common library
|
- name: Package Common library
|
||||||
run: dotnet pack src/Common/Giraffe.Htmx.Common.fsproj -c Release
|
run: dotnet pack src/Common/Giraffe.Htmx.Common.fsproj -c Release
|
||||||
- name: Move Common package
|
- name: Move Common package
|
||||||
@@ -49,7 +50,7 @@ jobs:
|
|||||||
- name: Move View Engine package
|
- name: Move View Engine package
|
||||||
run: cp src/ViewEngine.Htmx/bin/Release/Giraffe.ViewEngine.Htmx.*.nupkg .
|
run: cp src/ViewEngine.Htmx/bin/Release/Giraffe.ViewEngine.Htmx.*.nupkg .
|
||||||
- name: Save Packages
|
- name: Save Packages
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: packages
|
name: packages
|
||||||
path: |
|
path: |
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,3 +6,6 @@
|
|||||||
.idea
|
.idea
|
||||||
*.user
|
*.user
|
||||||
.vscode
|
.vscode
|
||||||
|
src/*.nupkg
|
||||||
|
src/tests*.txt
|
||||||
|
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -25,9 +25,10 @@ A server may want to respond to a request that originated from htmx differently
|
|||||||
// "view" can be whatever your view engine needs for the body of the page
|
// "view" can be whatever your view engine needs for the body of the page
|
||||||
let result view : HttpHandler =
|
let result view : HttpHandler =
|
||||||
fun next ctx ->
|
fun next ctx ->
|
||||||
match ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh with
|
if ctx.Request.IsHtmx && not ctx.Request.IsHtmxRefresh then
|
||||||
| true -> partial view
|
partial view
|
||||||
| false -> full view
|
else
|
||||||
|
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://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.
|
||||||
@@ -49,7 +50,9 @@ As an example, creating a `div` that loads data once the HTML is rendered:
|
|||||||
|
|
||||||
```fsharp
|
```fsharp
|
||||||
let autoload =
|
let autoload =
|
||||||
div [ _hxGet "/lazy-load-data"; _hxTrigger "load" ] [ str "Loading..." ]
|
div [ _hxGet "/lazy-load-data"; _hxTrigger HxTrigger.Load ] [
|
||||||
|
str "Loading..."
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
_(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true. To disable it for an element, use `_hxNoBoost` instead.)_
|
_(As `hx-boost="true"` is the usual desire for boosting, `_hxBoost` implies true. To disable it for an element, use `_hxNoBoost` instead.)_
|
||||||
@@ -67,10 +70,10 @@ If you want to load htmx from unpkg, `Htmx.Script.minified` or `Htmx.Script.unmi
|
|||||||
|
|
||||||
## Feedback / Help
|
## Feedback / Help
|
||||||
|
|
||||||
The author hangs out in the #htmx-general channel 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 of the [F# Software Foundation's Slack server](https://fsharp.org/guides/slack/).
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|[<img src="https://giraffe.wiki/giraffe.png" alt="Giraffe logo" width="200">](https://giraffe.wiki)|[<img src="https://bitbadger.solutions/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)|
|
|[<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)|
|
||||||
| :---: | :---: | :---: |
|
| :---: |:------------------------------------------------------------------------------------------------------------------------------------:| :---: |
|
||||||
|for making ASP.NET Core functional| for making HTML cool again |for licensing their tools to this project|
|
|for making ASP.NET Core functional| for making HTML cool again |for licensing their tools to this project|
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,45 @@
|
|||||||
/// Common definitions shared between attribute values and response headers
|
/// <summary>Common definitions shared between attribute values and response headers</summary>
|
||||||
[<AutoOpen>]
|
[<AutoOpen>]
|
||||||
module Giraffe.Htmx.Common
|
module Giraffe.Htmx.Common
|
||||||
|
|
||||||
/// Valid values for the `hx-swap` attribute / `HX-Reswap` header (may be combined with swap/settle/scroll/show config)
|
/// <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>
|
||||||
|
/// <returns>A string with the key/value pairs serialized to JSON</returns>
|
||||||
|
let internal toJson (pairs: (string * string) list) =
|
||||||
|
pairs
|
||||||
|
|> List.map (fun pair -> sprintf "\"%s\": \"%s\"" (fst pair) ((snd pair).Replace ("\"", "\\\"")))
|
||||||
|
|> String.concat ", "
|
||||||
|
|> sprintf "{ %s }"
|
||||||
|
|
||||||
|
/// <summary>Convert a boolean to lowercase <tt>true</tt> or <tt>false</tt></summary>
|
||||||
|
/// <param name="boolValue">The boolean value to convert</param>
|
||||||
|
/// <returns>"true" for <tt>true</tt>, "false" for <tt>false</tt></returns>
|
||||||
|
let internal toLowerBool (boolValue: bool) =
|
||||||
|
(string boolValue).ToLowerInvariant()
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>Valid values for the <tt>hx-swap</tt> attribute / <tt>HX-Reswap</tt> header</summary>
|
||||||
|
/// <remarks>May be combined with <tt>swap</tt> / <tt>settle</tt> / <tt>scroll</tt> / <tt>show</tt> config)</remarks>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxSwap =
|
module HxSwap =
|
||||||
|
|
||||||
/// The default, replace the inner html of the target element
|
/// <summary>The default, replace the inner HTML of the target element</summary>
|
||||||
let InnerHtml = "innerHTML"
|
let InnerHtml = "innerHTML"
|
||||||
|
|
||||||
/// Replace the entire target element with the response
|
/// <summary>Replace the entire target element with the response</summary>
|
||||||
let OuterHtml = "outerHTML"
|
let OuterHtml = "outerHTML"
|
||||||
|
|
||||||
/// Insert the response before the target element
|
/// <summary>Insert the response before the target element</summary>
|
||||||
let BeforeBegin = "beforebegin"
|
let BeforeBegin = "beforebegin"
|
||||||
|
|
||||||
/// Insert the response before the first child of the target element
|
/// <summary>Insert the response before the first child of the target element</summary>
|
||||||
let AfterBegin = "afterbegin"
|
let AfterBegin = "afterbegin"
|
||||||
|
|
||||||
/// Insert the response after the last child of the target element
|
/// <summary>Insert the response after the last child of the target element</summary>
|
||||||
let BeforeEnd = "beforeend"
|
let BeforeEnd = "beforeend"
|
||||||
|
|
||||||
/// Insert the response after the target element
|
/// <summary>Insert the response after the target element</summary>
|
||||||
let AfterEnd = "afterend"
|
let AfterEnd = "afterend"
|
||||||
|
|
||||||
/// Does not append content from response (out of band items will still be processed).
|
/// <summary>Does not append content from response (out of band items will still be processed).</summary>
|
||||||
let None = "none"
|
let None = "none"
|
||||||
|
|||||||
@@ -4,11 +4,21 @@
|
|||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<Description>Common definitions for Giraffe.Htmx</Description>
|
<Description>Common definitions for Giraffe.Htmx</Description>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Common.fs" />
|
<Compile Include="Common.fs" />
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
|
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<InternalsVisibleTo Include="Giraffe.Htmx" />
|
||||||
|
<InternalsVisibleTo Include="Giraffe.ViewEngine.Htmx" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
**htmx version: 1.9.4**
|
**htmx version: 2.0.4**
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||||
<VersionPrefix>1.9.4</VersionPrefix>
|
<VersionPrefix>2.0.5</VersionPrefix>
|
||||||
<PackageReleaseNotes>Update script tags to pull htmx 1.9.4</PackageReleaseNotes>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<PackageReleaseNotes>Add full packaged XML documentation; update script tags to pull htmx 2.0.5 (no header or attribute changes)</PackageReleaseNotes>
|
||||||
<Authors>danieljsummers</Authors>
|
<Authors>danieljsummers</Authors>
|
||||||
<Company>Bit Badger Solutions</Company>
|
<Company>Bit Badger Solutions</Company>
|
||||||
<PackageProjectUrl>https://github.com/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
<PackageProjectUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</PackageProjectUrl>
|
||||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
<RepositoryUrl>https://github.com/bit-badger/Giraffe.Htmx</RepositoryUrl>
|
<RepositoryUrl>https://git.bitbadger.solutions/bit-badger/Giraffe.Htmx</RepositoryUrl>
|
||||||
<RepositoryType>Git</RepositoryType>
|
<RepositoryType>Git</RepositoryType>
|
||||||
<Copyright>MIT License</Copyright>
|
<Copyright>MIT License</Copyright>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -4,15 +4,18 @@
|
|||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<Description>htmx header extensions and helpers for Giraffe</Description>
|
<Description>htmx header extensions and helpers for Giraffe</Description>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Htmx.fs" />
|
<Compile Include="Htmx.fs" />
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
|
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Giraffe" Version="5.0.0" />
|
<PackageReference Include="Giraffe" Version="6.4.0" />
|
||||||
|
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
165
src/Htmx/Htmx.fs
165
src/Htmx/Htmx.fs
@@ -11,62 +11,67 @@ let private hdr (headers : IHeaderDictionary) hdr =
|
|||||||
/// Extensions to the header dictionary
|
/// Extensions to the header dictionary
|
||||||
type IHeaderDictionary with
|
type IHeaderDictionary with
|
||||||
|
|
||||||
/// Indicates that the request is via an element using `hx-boost`
|
/// <summary>Indicates that the request is via an element using <tt>hx-boost</tt></summary>
|
||||||
member this.HxBoosted with get () = hdr this "HX-Boosted" |> Option.map bool.Parse
|
member this.HxBoosted
|
||||||
|
with get () = hdr this "HX-Boosted" |> Option.map bool.Parse
|
||||||
|
|
||||||
/// The current URL of the browser _(note that this does not update until after settle)_
|
/// <summary>The current URL of the browser <em>(note that this does not update until after settle)</em></summary>
|
||||||
member this.HxCurrentUrl with get () = hdr this "HX-Current-URL" |> Option.map Uri
|
member this.HxCurrentUrl
|
||||||
|
with get () = hdr this "HX-Current-URL" |> Option.map Uri
|
||||||
|
|
||||||
/// `true` if the request is for history restoration after a miss in the local history cache
|
/// <summary>
|
||||||
member this.HxHistoryRestoreRequest with get () = hdr this "HX-History-Restore-Request" |> Option.map bool.Parse
|
/// <tt>true</tt> if the request is for history restoration after a miss in the local history cache
|
||||||
|
/// </summary>
|
||||||
|
member this.HxHistoryRestoreRequest
|
||||||
|
with get () = hdr this "HX-History-Restore-Request" |> Option.map bool.Parse
|
||||||
|
|
||||||
/// The user response to an `hx-prompt`
|
/// <summary>The user response to an <tt>hx-prompt</tt></summary>
|
||||||
member this.HxPrompt with get () = hdr this "HX-Prompt"
|
member this.HxPrompt
|
||||||
|
with get () = hdr this "HX-Prompt"
|
||||||
|
|
||||||
/// `true` if the request came from HTMX
|
/// <summary><tt>true</tt> if the request came from htmx</summary>
|
||||||
member this.HxRequest with get () = hdr this "HX-Request" |> Option.map bool.Parse
|
member this.HxRequest
|
||||||
|
with get () = hdr this "HX-Request" |> Option.map bool.Parse
|
||||||
|
|
||||||
/// The `id` of the target element if it exists
|
/// <summary>The <tt>id</tt> attribute of the target element if it exists</summary>
|
||||||
member this.HxTarget with get () = hdr this "HX-Target"
|
member this.HxTarget
|
||||||
|
with get () = hdr this "HX-Target"
|
||||||
|
|
||||||
/// The `id` of the triggered element if it exists
|
/// <summary>The <tt>id</tt> attribute of the triggered element if it exists</summary>
|
||||||
member this.HxTrigger with get () = hdr this "HX-Trigger"
|
member this.HxTrigger
|
||||||
|
with get () = hdr this "HX-Trigger"
|
||||||
|
|
||||||
/// The `name` of the triggered element if it exists
|
/// <summary>The <tt>name</tt> attribute of the triggered element if it exists</summary>
|
||||||
member this.HxTriggerName with get () = hdr this "HX-Trigger-Name"
|
member this.HxTriggerName
|
||||||
|
with get () = hdr this "HX-Trigger-Name"
|
||||||
|
|
||||||
|
|
||||||
/// Extensions for the request object
|
/// Extensions for the request object
|
||||||
type HttpRequest with
|
type HttpRequest with
|
||||||
|
|
||||||
/// Whether this request was initiated from htmx
|
/// <summary>Whether this request was initiated from htmx</summary>
|
||||||
member this.IsHtmx with get () = this.Headers.HxRequest |> Option.defaultValue false
|
member this.IsHtmx
|
||||||
|
with get () = this.Headers.HxRequest |> Option.defaultValue false
|
||||||
|
|
||||||
/// Whether this request is an htmx history-miss refresh request
|
/// <summary>Whether this request is an htmx history-miss refresh request</summary>
|
||||||
member this.IsHtmxRefresh with get () =
|
member this.IsHtmxRefresh
|
||||||
this.IsHtmx && (this.Headers.HxHistoryRestoreRequest |> Option.defaultValue false)
|
with get () = this.IsHtmx && (this.Headers.HxHistoryRestoreRequest |> Option.defaultValue false)
|
||||||
|
|
||||||
|
|
||||||
/// HTTP handlers for setting output headers
|
/// <summary>HTTP handlers for setting output headers</summary>
|
||||||
[<AutoOpen>]
|
[<AutoOpen>]
|
||||||
module Handlers =
|
module Handlers =
|
||||||
|
|
||||||
/// Convert a boolean to lowercase `true` or `false`
|
open Giraffe.Htmx.Common
|
||||||
let private toLowerBool (trueOrFalse : bool) =
|
|
||||||
(string trueOrFalse).ToLowerInvariant ()
|
|
||||||
|
|
||||||
/// Serialize a list of key/value pairs to JSON (very rudimentary)
|
/// <summary>Pushes a new url into the history stack</summary>
|
||||||
let private toJson (evts : (string * string) list) =
|
/// <param name="url">The URL to be pushed</param>
|
||||||
evts
|
/// <returns>An HTTP handler with the <tt>HX-Push-Url</tt> header set</returns>
|
||||||
|> List.map (fun evt -> sprintf "\"%s\": \"%s\"" (fst evt) ((snd evt).Replace ("\"", "\\\"")))
|
let withHxPushUrl (url: string) : HttpHandler =
|
||||||
|> String.concat ", "
|
setHttpHeader "HX-Push-Url" url
|
||||||
|> sprintf "{ %s }"
|
|
||||||
|
|
||||||
/// Pushes a new url into the history stack
|
/// <summary>Explicitly do not push a new URL into the history stack</summary>
|
||||||
let withHxPushUrl : string -> HttpHandler =
|
/// <returns>An HTTP handler with the <tt>HX-Push-Url</tt> header set to <tt>false</tt></returns>
|
||||||
setHttpHeader "HX-Push-Url"
|
|
||||||
|
|
||||||
/// Explicitly do not push a new URL into the history stack
|
|
||||||
let withHxNoPushUrl : HttpHandler =
|
let withHxNoPushUrl : HttpHandler =
|
||||||
toLowerBool false |> withHxPushUrl
|
toLowerBool false |> withHxPushUrl
|
||||||
|
|
||||||
@@ -78,54 +83,80 @@ module Handlers =
|
|||||||
[<Obsolete "Use withHxNoPushUrl; HX-Push was replaced by HX-Push-Url in v1.8.0">]
|
[<Obsolete "Use withHxNoPushUrl; HX-Push was replaced by HX-Push-Url in v1.8.0">]
|
||||||
let withHxNoPush = withHxNoPushUrl
|
let withHxNoPush = withHxNoPushUrl
|
||||||
|
|
||||||
/// Can be used to do a client-side redirect to a new location
|
/// <summary>Can be used to do a client-side redirect to a new location</summary>
|
||||||
let withHxRedirect : string -> HttpHandler =
|
/// <param name="url">The URL to which the client should be redirected</param>
|
||||||
setHttpHeader "HX-Redirect"
|
/// <returns>An HTTP handler with the <tt>HX-Redirect</tt> header set</returns>
|
||||||
|
let withHxRedirect (url: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Redirect" url
|
||||||
|
|
||||||
/// If set to `true` the client side will do a a full refresh of the page
|
/// <summary>If set to <tt>true</tt> the client side will do a full refresh of the page</summary>
|
||||||
let withHxRefresh : bool -> HttpHandler =
|
/// <param name="shouldRefresh">Whether the client should refresh their page</param>
|
||||||
toLowerBool >> setHttpHeader "HX-Refresh"
|
/// <returns>An HTTP handler with the <tt>HX-Refresh</tt> header set</returns>
|
||||||
|
let withHxRefresh shouldRefresh : HttpHandler =
|
||||||
|
(toLowerBool >> setHttpHeader "HX-Refresh") shouldRefresh
|
||||||
|
|
||||||
/// Replaces the current URL in the history stack
|
/// <summary>Replaces the current URL in the history stack</summary>
|
||||||
let withHxReplaceUrl : string -> HttpHandler =
|
/// <param name="url">The URL to place in the history stack in place of the current one</param>
|
||||||
setHttpHeader "HX-Replace-Url"
|
/// <returns>An HTTP handler with the <tt>HX-Replace-URL</tt> header set</returns>
|
||||||
|
let withHxReplaceUrl url : HttpHandler =
|
||||||
|
setHttpHeader "HX-Replace-Url" url
|
||||||
|
|
||||||
/// Explicitly do not replace the current URL in the history stack
|
/// <summary>Explicitly do not replace the current URL in the history stack</summary>
|
||||||
|
/// <returns>An HTTP handler with the <tt>HX-Replace-URL</tt> header set to <tt>false</tt></returns>
|
||||||
let withHxNoReplaceUrl : HttpHandler =
|
let withHxNoReplaceUrl : HttpHandler =
|
||||||
toLowerBool false |> withHxReplaceUrl
|
toLowerBool false |> withHxReplaceUrl
|
||||||
|
|
||||||
/// Override which portion of the response will be swapped into the target document
|
/// <summary>Override which portion of the response will be swapped into the target document</summary>
|
||||||
let withHxReselect : string -> HttpHandler =
|
/// <param name="target">The selector for the new response target</param>
|
||||||
setHttpHeader "HX-Reselect"
|
/// <returns>An HTTP handler with the <tt>HX-Reselect</tt> header set</returns>
|
||||||
|
let withHxReselect (target: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Reselect" target
|
||||||
|
|
||||||
/// Override the `hx-swap` attribute from the initiating element
|
/// <summary>Override the <tt>hx-swap</tt> attribute from the initiating element</summary>
|
||||||
let withHxReswap : string -> HttpHandler =
|
/// <param name="swap">The swap value to override</param>
|
||||||
setHttpHeader "HX-Reswap"
|
/// <returns>An HTTP handler with the <tt>HX-Reswap</tt> header set</returns>
|
||||||
|
/// <remarks>Use <see cref="T:Giraffe.Htmx.Common.HxSwap">HxSwap</see> constants for best results</remarks>
|
||||||
|
let withHxReswap (swap: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Reswap" swap
|
||||||
|
|
||||||
/// Allows you to override the `hx-target` attribute
|
/// <summary>Allows you to override the <tt>hx-target</tt> attribute</summary>
|
||||||
let withHxRetarget : string -> HttpHandler =
|
/// <param name="target">The new target for the response</param>
|
||||||
setHttpHeader "HX-Retarget"
|
/// <returns>An HTTP handler with the <tt>HX-Retarget</tt> header set</returns>
|
||||||
|
let withHxRetarget (target: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Retarget" target
|
||||||
|
|
||||||
/// Allows you to trigger a single client side event
|
/// <summary>Allows you to trigger a single client side event</summary>
|
||||||
let withHxTrigger : string -> HttpHandler =
|
/// <param name="evt">The call to the event that should be triggered</param>
|
||||||
setHttpHeader "HX-Trigger"
|
/// <returns>An HTTP handler with the <tt>HX-Trigger</tt> header set</returns>
|
||||||
|
let withHxTrigger (evt: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Trigger" evt
|
||||||
|
|
||||||
/// Allows you to trigger multiple client side events
|
/// <summary>Allows you to trigger multiple client side events</summary>
|
||||||
|
/// <param name="evts">The calls to events that should be triggered</param>
|
||||||
|
/// <returns>An HTTP handler with the <tt>HX-Trigger</tt> header set for all given events</returns>
|
||||||
let withHxTriggerMany evts : HttpHandler =
|
let withHxTriggerMany evts : HttpHandler =
|
||||||
toJson evts |> setHttpHeader "HX-Trigger"
|
toJson evts |> setHttpHeader "HX-Trigger"
|
||||||
|
|
||||||
/// Allows you to trigger a single client side event after changes have settled
|
/// <summary>Allows you to trigger a single client side event after changes have settled</summary>
|
||||||
let withHxTriggerAfterSettle : string -> HttpHandler =
|
/// <param name="evt">The call to the event that should be triggered</param>
|
||||||
setHttpHeader "HX-Trigger-After-Settle"
|
/// <returns>An HTTP handler with the <tt>HX-Trigger-After-Settle</tt> header set</returns>
|
||||||
|
let withHxTriggerAfterSettle (evt: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Trigger-After-Settle" evt
|
||||||
|
|
||||||
/// Allows you to trigger multiple client side events after changes have settled
|
/// <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 <tt>HX-Trigger-After-Settle</tt> header set for all given events</returns>
|
||||||
let withHxTriggerManyAfterSettle evts : HttpHandler =
|
let withHxTriggerManyAfterSettle evts : HttpHandler =
|
||||||
toJson evts |> setHttpHeader "HX-Trigger-After-Settle"
|
toJson evts |> setHttpHeader "HX-Trigger-After-Settle"
|
||||||
|
|
||||||
/// Allows you to trigger a single client side event after DOM swapping occurs
|
/// <summary>Allows you to trigger a single client side event after DOM swapping occurs</summary>
|
||||||
let withHxTriggerAfterSwap : string -> HttpHandler =
|
/// <param name="evt">The call to the event that should be triggered</param>
|
||||||
setHttpHeader "HX-Trigger-After-Swap"
|
/// <returns>An HTTP handler with the <tt>HX-Trigger-After-Swap</tt> header set</returns>
|
||||||
|
let withHxTriggerAfterSwap (evt: string) : HttpHandler =
|
||||||
|
setHttpHeader "HX-Trigger-After-Swap" evt
|
||||||
|
|
||||||
/// Allows you to trigger multiple client side events after DOM swapping occurs
|
/// <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 <tt>HX-Trigger-After-Swap</tt> header set for all given events</returns>
|
||||||
let withHxTriggerManyAfterSwap evts : HttpHandler =
|
let withHxTriggerManyAfterSwap evts : HttpHandler =
|
||||||
toJson evts |> setHttpHeader "HX-Trigger-After-Swap"
|
toJson evts |> setHttpHeader "HX-Trigger-After-Swap"
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
|
This package enables server-side support for [htmx](https://htmx.org) within [Giraffe](https://giraffe.wiki) and ASP.NET's `HttpContext`.
|
||||||
|
|
||||||
**htmx version: 1.9.4**
|
**htmx version: 2.0.4**
|
||||||
|
|
||||||
|
_Upgrading from v1.x: the [migration guide](https://htmx.org/migration-guide-htmx-1/) does not currently specify any request or response header changes. This means that there are no required code changes in moving from v1.* to v2.*._
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ open Expecto
|
|||||||
let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests ]
|
let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests ]
|
||||||
|
|
||||||
[<EntryPoint>]
|
[<EntryPoint>]
|
||||||
let main args = runTestsWithArgs defaultConfig args allTests
|
let main args = runTestsWithCLIArgs [] args allTests
|
||||||
|
|||||||
@@ -18,8 +18,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Expecto" Version="9.0.4" />
|
<PackageReference Include="Expecto" Version="10.2.1" />
|
||||||
<PackageReference Include="NSubstitute" Version="5.0.0" />
|
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||||
|
<PackageReference Update="FSharp.Core" Version="8.0.300" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -15,6 +15,399 @@ let hxEncoding =
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
let hxEvent =
|
||||||
|
testList "HxEvent" [
|
||||||
|
testList "Abort" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string Abort) "abort" "Abort event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (Abort.ToHxOnString()) "abort" "Abort hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "AfterOnLoad" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string AfterOnLoad) "afterOnLoad" "AfterOnLoad event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (AfterOnLoad.ToHxOnString()) "after-on-load" "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-node"
|
||||||
|
"AfterProcessNode hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "AfterRequest" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string AfterRequest) "afterRequest" "AfterRequest event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (AfterRequest.ToHxOnString()) "after-request" "AfterRequest hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "AfterSettle" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string AfterSettle) "afterSettle" "AfterSettle event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (AfterSettle.ToHxOnString()) "after-settle" "AfterSettle hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "AfterSwap" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string AfterSwap) "afterSwap" "AfterSwap event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (AfterSwap.ToHxOnString()) "after-swap" "AfterSwap 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-element"
|
||||||
|
"BeforeCleanupElement 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-on-load" "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-node"
|
||||||
|
"BeforeProcessNode hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "BeforeRequest" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string BeforeRequest) "beforeRequest" "BeforeRequest event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal
|
||||||
|
(BeforeRequest.ToHxOnString()) "before-request" "BeforeRequest hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "BeforeSwap" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string BeforeSwap) "beforeSwap" "BeforeSwap event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (BeforeSwap.ToHxOnString()) "before-swap" "BeforeSwap 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-send" "BeforeSend hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "ConfigRequest" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string ConfigRequest) "configRequest" "ConfigRequest event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal
|
||||||
|
(ConfigRequest.ToHxOnString()) "config-request" "ConfigRequest hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "Confirm" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string Confirm) "confirm" "Confirm event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal (Confirm.ToHxOnString()) "confirm" "Confirm 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())
|
||||||
|
"history-cache-miss"
|
||||||
|
"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())
|
||||||
|
"history-cache-miss-load"
|
||||||
|
"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()) "history-restore" "HistoryRestore 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-save"
|
||||||
|
"BeforeHistorySave 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()) "load" "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())
|
||||||
|
"no-sse-source-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()) "on-load-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()) "oob-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()) "oob-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())
|
||||||
|
"oob-error-no-target"
|
||||||
|
"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())
|
||||||
|
"pushed-into-history"
|
||||||
|
"PushedIntoHistory hx-on event name not correct"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
testList "ResponseError" [
|
||||||
|
test "ToString succeeds" {
|
||||||
|
Expect.equal (string ResponseError) "responseError" "ResponseError event name not correct"
|
||||||
|
}
|
||||||
|
test "ToHxOnString succeeds" {
|
||||||
|
Expect.equal
|
||||||
|
(ResponseError.ToHxOnString()) "response-error" "ResponseError 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()) "send-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()) "sse-open" "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()) "swap-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()) "target-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()) "timeout" "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()) "xhr:abort" "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()) "xhr:loadend" "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 HxHeaders module
|
/// Tests for the HxHeaders module
|
||||||
let hxHeaders =
|
let hxHeaders =
|
||||||
testList "HxHeaders" [
|
testList "HxHeaders" [
|
||||||
@@ -293,14 +686,14 @@ let hxVals =
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Tests for the HtmxAttrs module
|
|
||||||
let attributes =
|
|
||||||
testList "Attributes" [
|
|
||||||
|
|
||||||
/// Pipe-able assertion for a rendered node
|
/// Pipe-able assertion for a rendered node
|
||||||
let shouldRender expected node =
|
let shouldRender expected node =
|
||||||
Expect.equal (RenderView.AsString.htmlNode node) expected "Rendered HTML incorrect"
|
Expect.equal (RenderView.AsString.htmlNode node) expected "Rendered HTML incorrect"
|
||||||
|
|
||||||
|
/// Tests for the HtmxAttrs module
|
||||||
|
let attributes =
|
||||||
|
testList "Attributes" [
|
||||||
|
|
||||||
test "_hxBoost succeeds" {
|
test "_hxBoost succeeds" {
|
||||||
div [ _hxBoost ] [] |> shouldRender """<div hx-boost="true"></div>"""
|
div [ _hxBoost ] [] |> shouldRender """<div hx-boost="true"></div>"""
|
||||||
}
|
}
|
||||||
@@ -313,6 +706,9 @@ let attributes =
|
|||||||
test "_hxDisable succeeds" {
|
test "_hxDisable succeeds" {
|
||||||
p [ _hxDisable ] [] |> shouldRender """<p hx-disable></p>"""
|
p [ _hxDisable ] [] |> shouldRender """<p hx-disable></p>"""
|
||||||
}
|
}
|
||||||
|
test "_hxDisabledElt succeeds" {
|
||||||
|
button [ _hxDisabledElt "this" ] [] |> shouldRender """<button hx-disabled-elt="this"></button>"""
|
||||||
|
}
|
||||||
test "_hxDisinherit succeeds" {
|
test "_hxDisinherit succeeds" {
|
||||||
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
|
strong [ _hxDisinherit "*" ] [] |> shouldRender """<strong hx-disinherit="*"></strong>"""
|
||||||
}
|
}
|
||||||
@@ -344,10 +740,12 @@ let attributes =
|
|||||||
test "_hxNoBoost succeeds" {
|
test "_hxNoBoost succeeds" {
|
||||||
td [ _hxNoBoost ] [] |> shouldRender """<td hx-boost="false"></td>"""
|
td [ _hxNoBoost ] [] |> shouldRender """<td hx-boost="false"></td>"""
|
||||||
}
|
}
|
||||||
test "_hxOn succeeds" {
|
test "_hxOnEvent succeeds" {
|
||||||
let newLine = "\n"
|
a [ _hxOnEvent "click" "doThis()" ] [] |> shouldRender """<a hx-on:click="doThis()"></a>"""
|
||||||
strong [ _hxOn "submit: alert('oops')\nclick: alert('howdy!')" ] []
|
}
|
||||||
|> shouldRender $"""<strong hx-on="submit: alert('oops'){newLine}click: alert('howdy!')"></strong>"""
|
test "_hxOnHxEvent succeeds" {
|
||||||
|
strong [ _hxOnHxEvent BeforeSwap "changeStuff()" ] []
|
||||||
|
|> shouldRender """<strong hx-on::before-swap="changeStuff()"></strong>"""
|
||||||
}
|
}
|
||||||
test "_hxParams succeeds" {
|
test "_hxParams succeeds" {
|
||||||
br [ _hxParams "[p1,p2]" ] |> shouldRender """<br hx-params="[p1,p2]">"""
|
br [ _hxParams "[p1,p2]" ] |> shouldRender """<br hx-params="[p1,p2]">"""
|
||||||
@@ -383,10 +781,6 @@ let attributes =
|
|||||||
test "_hxSelectOob succeeds" {
|
test "_hxSelectOob succeeds" {
|
||||||
section [ _hxSelectOob "#oob" ] [] |> shouldRender """<section hx-select-oob="#oob"></section>"""
|
section [ _hxSelectOob "#oob" ] [] |> shouldRender """<section hx-select-oob="#oob"></section>"""
|
||||||
}
|
}
|
||||||
test "_hxSse succeeds" {
|
|
||||||
footer [ _hxSse "connect:/my-events" ] []
|
|
||||||
|> shouldRender """<footer hx-sse="connect:/my-events"></footer>"""
|
|
||||||
}
|
|
||||||
test "_hxSwap succeeds" {
|
test "_hxSwap succeeds" {
|
||||||
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
|
del [ _hxSwap "innerHTML" ] [] |> shouldRender """<del hx-swap="innerHTML"></del>"""
|
||||||
}
|
}
|
||||||
@@ -410,8 +804,11 @@ let attributes =
|
|||||||
dt [ _hxVals """{ "extra": "values" }""" ] []
|
dt [ _hxVals """{ "extra": "values" }""" ] []
|
||||||
|> shouldRender """<dt hx-vals="{ "extra": "values" }"></dt>"""
|
|> shouldRender """<dt hx-vals="{ "extra": "values" }"></dt>"""
|
||||||
}
|
}
|
||||||
test "_hxWs succeeds" {
|
test "_sseSwap succeeds" {
|
||||||
ul [ _hxWs "connect:/web-socket" ] [] |> shouldRender """<ul hx-ws="connect:/web-socket"></ul>"""
|
ul [ _sseSwap "sseMessageName" ] [] |> shouldRender """<ul sse-swap="sseMessageName"></ul>"""
|
||||||
|
}
|
||||||
|
test "_sseConnect succeeds" {
|
||||||
|
div [ _sseConnect "/gps/sse" ] [] |> shouldRender """<div sse-connect="/gps/sse"></div>"""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -422,14 +819,14 @@ let script =
|
|||||||
let html = RenderView.AsString.htmlNode Script.minified
|
let html = RenderView.AsString.htmlNode Script.minified
|
||||||
Expect.equal
|
Expect.equal
|
||||||
html
|
html
|
||||||
"""<script src="https://unpkg.com/htmx.org@1.9.4" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script>"""
|
"""<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>"""
|
||||||
"Minified script tag is incorrect"
|
"Minified script tag is incorrect"
|
||||||
}
|
}
|
||||||
test "unminified succeeds" {
|
test "unminified succeeds" {
|
||||||
let html = RenderView.AsString.htmlNode Script.unminified
|
let html = RenderView.AsString.htmlNode Script.unminified
|
||||||
Expect.equal
|
Expect.equal
|
||||||
html
|
html
|
||||||
"""<script src="https://unpkg.com/htmx.org@1.9.4/dist/htmx.js" integrity="sha384-2caa3Jf+wayjuHAc9J3mR3xz191GzmIDNYVBsE8LetbkJn4wjLrO6Ht9rRMuEjIo" crossorigin="anonymous"></script>"""
|
"""<script src="https://unpkg.com/htmx.org@2.0.4/dist/htmx.js" integrity="sha384-oeUn82QNXPuVkGCkcrInrS1twIxKhkZiFfr2TdiuObZ3n3yIeMiqcRzkIcguaof1" crossorigin="anonymous"></script>"""
|
||||||
"Unminified script tag is incorrect"
|
"Unminified script tag is incorrect"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -583,5 +980,15 @@ let renderFragment =
|
|||||||
|
|
||||||
/// All tests in this module
|
/// All tests in this module
|
||||||
let allTests =
|
let allTests =
|
||||||
testList "ViewEngine.Htmx"
|
testList "ViewEngine.Htmx" [
|
||||||
[ hxEncoding; hxHeaders; hxParams; hxRequest; hxTrigger; hxVals; attributes; script; renderFragment ]
|
hxEncoding
|
||||||
|
hxEvent
|
||||||
|
hxHeaders
|
||||||
|
hxParams
|
||||||
|
hxRequest
|
||||||
|
hxTrigger
|
||||||
|
hxVals
|
||||||
|
attributes
|
||||||
|
script
|
||||||
|
renderFragment
|
||||||
|
]
|
||||||
|
|||||||
@@ -4,15 +4,18 @@
|
|||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<Description>Extensions to Giraffe View Engine to support htmx attributes and their values</Description>
|
<Description>Extensions to Giraffe View Engine to support htmx attributes and their values</Description>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Htmx.fs" />
|
<Compile Include="Htmx.fs" />
|
||||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||||
|
<None Include="..\icon.png" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Giraffe.ViewEngine" Version="1.4.0" />
|
<PackageReference Include="Giraffe.ViewEngine" Version="1.4.0" />
|
||||||
|
<PackageReference Update="FSharp.Core" Version="6.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,71 +1,268 @@
|
|||||||
|
/// <summary>Types and functions supporting htmx attributes in Giraffe View Engine</summary>
|
||||||
module Giraffe.ViewEngine.Htmx
|
module Giraffe.ViewEngine.Htmx
|
||||||
|
|
||||||
/// Serialize a list of key/value pairs to JSON (very rudimentary)
|
/// <summary>Valid values for the <tt>hx-encoding</tt> attribute</summary>
|
||||||
let private toJson (kvps : (string * string) list) =
|
|
||||||
kvps
|
|
||||||
|> List.map (fun kvp -> sprintf "\"%s\": \"%s\"" (fst kvp) ((snd kvp).Replace ("\"", "\\\"")))
|
|
||||||
|> String.concat ", "
|
|
||||||
|> sprintf "{ %s }"
|
|
||||||
|
|
||||||
|
|
||||||
/// Valid values for the `hx-encoding` attribute
|
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxEncoding =
|
module HxEncoding =
|
||||||
|
|
||||||
/// A standard HTTP form
|
/// <summary>A standard HTTP form</summary>
|
||||||
let Form = "application/x-www-form-urlencoded"
|
let Form = "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
/// A multipart form (used for file uploads)
|
/// <summary>A multipart form (used for file uploads)</summary>
|
||||||
let MultipartForm = "multipart/form-data"
|
let MultipartForm = "multipart/form-data"
|
||||||
|
|
||||||
|
|
||||||
/// Helper to create the `hx-headers` attribute
|
/// <summary>The events recognized by htmx</summary>
|
||||||
|
[<Struct>]
|
||||||
|
type HxEvent =
|
||||||
|
|
||||||
|
/// <summary>Send this event to an element to abort a request</summary>
|
||||||
|
| Abort
|
||||||
|
|
||||||
|
/// <summary>Triggered after an AJAX request has completed processing a successful response</summary>
|
||||||
|
| AfterOnLoad
|
||||||
|
|
||||||
|
/// <summary>Triggered after htmx has initialized a node</summary>
|
||||||
|
| AfterProcessNode
|
||||||
|
|
||||||
|
/// <summary>Triggered after an AJAX request has completed</summary>
|
||||||
|
| AfterRequest
|
||||||
|
|
||||||
|
/// <summary>Triggered after the DOM has settled</summary>
|
||||||
|
| AfterSettle
|
||||||
|
|
||||||
|
/// <summary>Triggered after new content has been swapped in</summary>
|
||||||
|
| AfterSwap
|
||||||
|
|
||||||
|
/// <summary>Triggered before htmx disables an element or removes it from the DOM</summary>
|
||||||
|
| BeforeCleanupElement
|
||||||
|
|
||||||
|
/// <summary>Triggered before any response processing occurs</summary>
|
||||||
|
| BeforeOnLoad
|
||||||
|
|
||||||
|
/// <summary>Triggered before htmx initializes a node</summary>
|
||||||
|
| BeforeProcessNode
|
||||||
|
|
||||||
|
/// <summary>Triggered before an AJAX request is made</summary>
|
||||||
|
| BeforeRequest
|
||||||
|
|
||||||
|
/// <summary>Triggered before a swap is done, allows you to configure the swap</summary>
|
||||||
|
| BeforeSwap
|
||||||
|
|
||||||
|
/// <summary>Triggered just before an ajax request is sent</summary>
|
||||||
|
| BeforeSend
|
||||||
|
|
||||||
|
/// <summary>Triggered before the request, allows you to customize parameters, headers</summary>
|
||||||
|
| ConfigRequest
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Triggered after a trigger occurs on an element, allows you to cancel (or delay) issuing the AJAX request
|
||||||
|
/// </summary>
|
||||||
|
| Confirm
|
||||||
|
|
||||||
|
/// <summary>Triggered on an error during cache writing</summary>
|
||||||
|
| HistoryCacheError
|
||||||
|
|
||||||
|
/// <summary>Triggered on a cache miss in the history subsystem</summary>
|
||||||
|
| HistoryCacheMiss
|
||||||
|
|
||||||
|
/// <summary>Triggered on a unsuccessful remote retrieval</summary>
|
||||||
|
| HistoryCacheMissError
|
||||||
|
|
||||||
|
/// <summary>Triggered on a successful remote retrieval</summary>
|
||||||
|
| HistoryCacheMissLoad
|
||||||
|
|
||||||
|
/// <summary>Triggered when htmx handles a history restoration action</summary>
|
||||||
|
| HistoryRestore
|
||||||
|
|
||||||
|
/// <summary>Triggered before content is saved to the history cache</summary>
|
||||||
|
| BeforeHistorySave
|
||||||
|
|
||||||
|
/// <summary>Triggered when new content is added to the DOM</summary>
|
||||||
|
| Load
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Triggered when an element refers to a SSE event in its trigger, but no parent SSE source has been defined
|
||||||
|
/// </summary>
|
||||||
|
| NoSseSourceError
|
||||||
|
|
||||||
|
/// <summary>Triggered when an exception occurs during the onLoad handling in htmx</summary>
|
||||||
|
| OnLoadError
|
||||||
|
|
||||||
|
/// <summary>Triggered after an out of band element as been swapped in</summary>
|
||||||
|
| OobAfterSwap
|
||||||
|
|
||||||
|
/// <summary>Triggered before an out of band element swap is done, allows you to configure the swap</summary>
|
||||||
|
| OobBeforeSwap
|
||||||
|
|
||||||
|
/// <summary>Triggered when an out of band element does not have a matching ID in the current DOM</summary>
|
||||||
|
| OobErrorNoTarget
|
||||||
|
|
||||||
|
/// <summary>Triggered after a prompt is shown</summary>
|
||||||
|
| Prompt
|
||||||
|
|
||||||
|
/// <summary>Triggered after an url is pushed into history</summary>
|
||||||
|
| 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>
|
||||||
|
| SendError
|
||||||
|
|
||||||
|
/// <summary>Triggered when an error occurs with a SSE source</summary>
|
||||||
|
| SseError
|
||||||
|
|
||||||
|
/// <summary>Triggered when a SSE source is opened</summary>
|
||||||
|
| SseOpen
|
||||||
|
|
||||||
|
/// <summary>Triggered when an error occurs during the swap phase</summary>
|
||||||
|
| SwapError
|
||||||
|
|
||||||
|
/// <summary>Triggered when an invalid target is specified</summary>
|
||||||
|
| TargetError
|
||||||
|
|
||||||
|
/// <summary>Triggered when a request timeout occurs</summary>
|
||||||
|
| Timeout
|
||||||
|
|
||||||
|
/// <summary>Triggered before an element is validated</summary>
|
||||||
|
| ValidationValidate
|
||||||
|
|
||||||
|
/// <summary>Triggered when an element fails validation</summary>
|
||||||
|
| ValidationFailed
|
||||||
|
|
||||||
|
/// <summary>Triggered when a request is halted due to validation errors</summary>
|
||||||
|
| ValidationHalted
|
||||||
|
|
||||||
|
/// <summary>Triggered when an ajax request aborts</summary>
|
||||||
|
| XhrAbort
|
||||||
|
|
||||||
|
/// <summary>Triggered when an ajax request ends</summary>
|
||||||
|
| XhrLoadEnd
|
||||||
|
|
||||||
|
/// <summary>Triggered when an ajax request starts</summary>
|
||||||
|
| XhrLoadStart
|
||||||
|
|
||||||
|
/// <summary>Triggered periodically during an ajax request that supports progress events</summary>
|
||||||
|
| XhrProgress
|
||||||
|
|
||||||
|
/// The htmx event name (fst) and kebab-case name (snd, for use with hx-on)
|
||||||
|
static member private Values = Map [
|
||||||
|
Abort, ("abort", "abort")
|
||||||
|
AfterOnLoad, ("afterOnLoad", "after-on-load")
|
||||||
|
AfterProcessNode, ("afterProcessNode", "after-process-node")
|
||||||
|
AfterRequest, ("afterRequest", "after-request")
|
||||||
|
AfterSettle, ("afterSettle", "after-settle")
|
||||||
|
AfterSwap, ("afterSwap", "after-swap")
|
||||||
|
BeforeCleanupElement, ("beforeCleanupElement", "before-cleanup-element")
|
||||||
|
BeforeOnLoad, ("beforeOnLoad", "before-on-load")
|
||||||
|
BeforeProcessNode, ("beforeProcessNode", "before-process-node")
|
||||||
|
BeforeRequest, ("beforeRequest", "before-request")
|
||||||
|
BeforeSwap, ("beforeSwap", "before-swap")
|
||||||
|
BeforeSend, ("beforeSend", "before-send")
|
||||||
|
ConfigRequest, ("configRequest", "config-request")
|
||||||
|
Confirm, ("confirm", "confirm")
|
||||||
|
HistoryCacheError, ("historyCacheError", "history-cache-error")
|
||||||
|
HistoryCacheMiss, ("historyCacheMiss", "history-cache-miss")
|
||||||
|
HistoryCacheMissError, ("historyCacheMissError", "history-cache-miss-error")
|
||||||
|
HistoryCacheMissLoad, ("historyCacheMissLoad", "history-cache-miss-load")
|
||||||
|
HistoryRestore, ("historyRestore", "history-restore")
|
||||||
|
BeforeHistorySave, ("beforeHistorySave", "before-history-save")
|
||||||
|
Load, ("load", "load")
|
||||||
|
NoSseSourceError, ("noSSESourceError", "no-sse-source-error")
|
||||||
|
OnLoadError, ("onLoadError", "on-load-error")
|
||||||
|
OobAfterSwap, ("oobAfterSwap", "oob-after-swap")
|
||||||
|
OobBeforeSwap, ("oobBeforeSwap", "oob-before-swap")
|
||||||
|
OobErrorNoTarget, ("oobErrorNoTarget", "oob-error-no-target")
|
||||||
|
Prompt, ("prompt", "prompt")
|
||||||
|
PushedIntoHistory, ("pushedIntoHistory", "pushed-into-history")
|
||||||
|
ResponseError, ("responseError", "response-error")
|
||||||
|
SendError, ("sendError", "send-error")
|
||||||
|
SseError, ("sseError", "sse-error")
|
||||||
|
SseOpen, ("sseOpen", "sse-open")
|
||||||
|
SwapError, ("swapError", "swap-error")
|
||||||
|
TargetError, ("targetError", "target-error")
|
||||||
|
Timeout, ("timeout", "timeout")
|
||||||
|
ValidationValidate, ("validation:validate", "validation:validate")
|
||||||
|
ValidationFailed, ("validation:failed", "validation:failed")
|
||||||
|
ValidationHalted, ("validation:halted", "validation:halted")
|
||||||
|
XhrAbort, ("xhr:abort", "xhr:abort")
|
||||||
|
XhrLoadEnd, ("xhr:loadend", "xhr:loadend")
|
||||||
|
XhrLoadStart, ("xhr:loadstart", "xhr:loadstart")
|
||||||
|
XhrProgress, ("xhr:progress", "xhr:progress")
|
||||||
|
]
|
||||||
|
|
||||||
|
/// <summary>The htmx event name</summary>
|
||||||
|
override this.ToString() = fst HxEvent.Values[this]
|
||||||
|
|
||||||
|
/// <summary>The <tt>hx-on</tt> variant of the htmx event name</summary>
|
||||||
|
member this.ToHxOnString() = snd HxEvent.Values[this]
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>Helper to create the <tt>hx-headers</tt> attribute</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxHeaders =
|
module HxHeaders =
|
||||||
|
|
||||||
/// Create headers from a list of key/value pairs
|
/// <summary>Create headers from a list of key/value pairs</summary>
|
||||||
let From = toJson
|
let From = Giraffe.Htmx.Common.toJson
|
||||||
|
|
||||||
|
|
||||||
/// Values / helpers for the `hx-params` attribute
|
/// <summary>Values / helpers for the <tt>hx-params</tt> attribute</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxParams =
|
module HxParams =
|
||||||
|
|
||||||
/// Include all parameters
|
/// <summary>Include all parameters</summary>
|
||||||
let All = "*"
|
let All = "*"
|
||||||
|
|
||||||
/// Include no parameters
|
/// <summary>Include no parameters</summary>
|
||||||
let None = "none"
|
let None = "none"
|
||||||
|
|
||||||
/// Include the specified parameters
|
/// <summary>Include the specified parameters</summary>
|
||||||
let With fields = match fields with [] -> "" | _ -> fields |> List.reduce (fun acc it -> $"{acc},{it}")
|
/// <param name="fields">One or more fields to include in the request</param>
|
||||||
|
/// <returns>The list of fields for the <tt>hx-params</tt> attribute value</returns>
|
||||||
|
let With fields =
|
||||||
|
match fields with [] -> "" | _ -> fields |> List.reduce (fun acc it -> $"{acc},{it}")
|
||||||
|
|
||||||
/// Exclude the specified parameters
|
/// <summary>Exclude the specified parameters</summary>
|
||||||
let Except fields = With fields |> sprintf "not %s"
|
/// <param name="fields">One or more fields to exclude from the request</param>
|
||||||
|
/// <returns>The list of fields for the <tt>hx-params</tt> attribute value prefixed with "not"</returns>
|
||||||
|
let Except fields =
|
||||||
|
With fields |> sprintf "not %s"
|
||||||
|
|
||||||
|
|
||||||
/// Helpers to define `hx-request` attribute values
|
/// <summary>Helpers to define <tt>hx-request</tt> attribute values</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxRequest =
|
module HxRequest =
|
||||||
|
|
||||||
/// Convert a boolean to its lowercase string equivalent
|
open Giraffe.Htmx.Common
|
||||||
let private toLowerBool (it : bool) =
|
|
||||||
(string it).ToLowerInvariant ()
|
|
||||||
|
|
||||||
/// Configure the request with various options
|
/// <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) =
|
let Configure (opts: string list) =
|
||||||
opts
|
opts
|
||||||
|> String.concat ", "
|
|> String.concat ", "
|
||||||
|> sprintf "{ %s }"
|
|> sprintf "{ %s }"
|
||||||
|
|
||||||
/// Set a timeout (in milliseconds)
|
/// <summary>Set a timeout (in milliseconds)</summary>
|
||||||
let Timeout (ms : int) = $"\"timeout\": {ms}"
|
/// <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}"
|
||||||
|
|
||||||
/// Include or exclude credentials from the request
|
/// <summary>Include or exclude credentials from the request</summary>
|
||||||
let Credentials = toLowerBool >> sprintf "\"credentials\": %s"
|
/// <param name="send"><tt>true</tt> if credentials should be sent, <tt>false</tt> if not</param>
|
||||||
|
/// <returns>A string with the configured credential options</returns>
|
||||||
|
let Credentials send =
|
||||||
|
(toLowerBool >> sprintf "\"credentials\": %s") send
|
||||||
|
|
||||||
/// Exclude or include headers from the request
|
/// <summary>Exclude or include headers from the request</summary>
|
||||||
let NoHeaders = toLowerBool >> sprintf "\"noHeaders\": %s"
|
/// <param name="exclude">
|
||||||
|
/// <tt>true</tt> if no headers should be sent; <tt>false</tt> if headers should be sent
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A string with the configured header options</returns>
|
||||||
|
let NoHeaders exclude =
|
||||||
|
(toLowerBool >> sprintf "\"noHeaders\": %s") exclude
|
||||||
|
|
||||||
|
|
||||||
/// Helpers for the `hx-trigger` attribute
|
/// Helpers for the `hx-trigger` attribute
|
||||||
@@ -169,43 +366,69 @@ module HxTrigger =
|
|||||||
let QueueNone = Queue "none"
|
let QueueNone = Queue "none"
|
||||||
|
|
||||||
|
|
||||||
/// Helper to create the `hx-vals` attribute
|
/// <summary>Helper to create the `hx-vals` attribute</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module HxVals =
|
module HxVals =
|
||||||
|
|
||||||
/// Create values from a list of key/value pairs
|
/// <summary>Create values from a list of key/value pairs</summary>
|
||||||
let From = toJson
|
let From = Giraffe.Htmx.Common.toJson
|
||||||
|
|
||||||
|
|
||||||
/// Attributes and flags for htmx
|
/// <summary>Attributes and flags for htmx</summary>
|
||||||
[<AutoOpen>]
|
[<AutoOpen>]
|
||||||
module HtmxAttrs =
|
module HtmxAttrs =
|
||||||
|
|
||||||
/// Progressively enhances anchors and forms to use AJAX requests (use `_hxNoBoost` to set to false)
|
/// <summary>Progressively enhances anchors and forms to use AJAX requests</summary>
|
||||||
|
/// <remarks>Use <tt>_hxNoBoost</tt> to set to false</remarks>
|
||||||
let _hxBoost = attr "hx-boost" "true"
|
let _hxBoost = attr "hx-boost" "true"
|
||||||
|
|
||||||
/// Shows a confirm() dialog before issuing a request
|
/// <summary>Shows a <tt>confirm()</tt> dialog before issuing a request</summary>
|
||||||
let _hxConfirm = attr "hx-confirm"
|
/// <param name="prompt">The prompt to present to the user when seeking their confirmation</param>
|
||||||
|
/// <returns>A configured <tt>hx-confirm</tt> attribute</returns>
|
||||||
|
let _hxConfirm prompt =
|
||||||
|
attr "hx-confirm" prompt
|
||||||
|
|
||||||
/// Issues a DELETE to the specified URL
|
/// <summary>Issues a <tt>DELETE</tt> to the specified URL</summary>
|
||||||
let _hxDelete = attr "hx-delete"
|
/// <param name="url">The URL to which the <tt>DELETE</tt> request should be sent</param>
|
||||||
|
/// <returns>A configured <tt>hx-delete</tt> attribute</returns>
|
||||||
|
let _hxDelete url =
|
||||||
|
attr "hx-delete" url
|
||||||
|
|
||||||
/// Disables htmx processing for the given node and any children nodes
|
/// <summary>Disables htmx processing for the given node and any children nodes</summary>
|
||||||
let _hxDisable = flag "hx-disable"
|
let _hxDisable = flag "hx-disable"
|
||||||
|
|
||||||
/// Disinherit all ("*") or specific htmx attributes
|
/// <summary>Specifies elements that should be disabled when an htmx request is in flight</summary>
|
||||||
let _hxDisinherit = attr "hx-disinherit"
|
/// <param name="elt">The element to disable when an htmx request is in flight</param>
|
||||||
|
/// <returns>A configured <tt>hx-disabled-elt</tt> attribute</returns>
|
||||||
|
let _hxDisabledElt elt =
|
||||||
|
attr "hx-disabled-elt" elt
|
||||||
|
|
||||||
/// Changes the request encoding type
|
/// <summary>Disinherit all ("*") or specific htmx attributes</summary>
|
||||||
let _hxEncoding = attr "hx-encoding"
|
/// <param name="hxAttrs">The htmx attributes to disinherit (should start with "hx-")</param>
|
||||||
|
/// <returns>A configured <tt>hx-disinherit</tt> attribute</returns>
|
||||||
|
let _hxDisinherit hxAttrs =
|
||||||
|
attr "hx-disinherit" hxAttrs
|
||||||
|
|
||||||
/// Extensions to use for this element
|
/// <summary>Changes the request encoding type</summary>
|
||||||
let _hxExt = attr "hx-ext"
|
/// <param name="enc">The encoding type (use <tt>HxEncoding</tt> constants)</param>
|
||||||
|
/// <returns>A configured <tt>hx-encoding</tt> attribute</returns>
|
||||||
|
let _hxEncoding enc =
|
||||||
|
attr "hx-encoding" enc
|
||||||
|
|
||||||
/// Issues a GET to the specified URL
|
/// <summary>Extensions to use for this element</summary>
|
||||||
let _hxGet = attr "hx-get"
|
/// <param name="exts">A list of extensions to apply to this element</param>
|
||||||
|
/// <returns>A configured <tt>hx-ext</tt> attribute</returns>
|
||||||
|
let _hxExt exts =
|
||||||
|
attr "hx-ext" exts
|
||||||
|
|
||||||
/// Adds to the headers that will be submitted with the request
|
/// <summary>Issues a <tt>GET</tt> to the specified URL</summary>
|
||||||
|
/// <param name="url">The URL to which the <tt>GET</tt> request should be sent</param>
|
||||||
|
/// <returns>A configured <tt>hx-get</tt> attribute</returns>
|
||||||
|
let _hxGet url =
|
||||||
|
attr "hx-get" url
|
||||||
|
|
||||||
|
/// <summary>Adds to the headers that will be submitted with the request</summary>
|
||||||
|
[<System.Obsolete "Convert this parameter">]
|
||||||
let _hxHeaders = attr "hx-headers"
|
let _hxHeaders = attr "hx-headers"
|
||||||
|
|
||||||
/// Set to "false" to prevent pages with sensitive information from being stored in the history cache
|
/// Set to "false" to prevent pages with sensitive information from being stored in the history cache
|
||||||
@@ -223,8 +446,13 @@ module HtmxAttrs =
|
|||||||
/// Overrides a previous `hx-boost`
|
/// Overrides a previous `hx-boost`
|
||||||
let _hxNoBoost = attr "hx-boost" "false"
|
let _hxNoBoost = attr "hx-boost" "false"
|
||||||
|
|
||||||
/// Attach an event handler for DOM or htmx events
|
/// Attach an event handler for DOM events
|
||||||
let _hxOn = attr "hx-on"
|
let _hxOnEvent evtName =
|
||||||
|
attr $"hx-on:%s{evtName}"
|
||||||
|
|
||||||
|
/// Attach an event handler for htmx events
|
||||||
|
let _hxOnHxEvent (hxEvent: HxEvent) =
|
||||||
|
_hxOnEvent $":{hxEvent.ToHxOnString()}"
|
||||||
|
|
||||||
/// Filters the parameters that will be submitted with a request
|
/// Filters the parameters that will be submitted with a request
|
||||||
let _hxParams = attr "hx-params"
|
let _hxParams = attr "hx-params"
|
||||||
@@ -259,9 +487,6 @@ module HtmxAttrs =
|
|||||||
/// Selects a subset of an out-of-band server response
|
/// Selects a subset of an out-of-band server response
|
||||||
let _hxSelectOob = attr "hx-select-oob"
|
let _hxSelectOob = attr "hx-select-oob"
|
||||||
|
|
||||||
/// Establishes and listens to Server Sent Event (SSE) sources for events
|
|
||||||
let _hxSse = attr "hx-sse"
|
|
||||||
|
|
||||||
/// Controls how the response content is swapped into the DOM (e.g. 'outerHTML' or 'beforeEnd')
|
/// Controls how the response content is swapped into the DOM (e.g. 'outerHTML' or 'beforeEnd')
|
||||||
let _hxSwap = attr "hx-swap"
|
let _hxSwap = attr "hx-swap"
|
||||||
|
|
||||||
@@ -287,23 +512,26 @@ module HtmxAttrs =
|
|||||||
/// Adds to the parameters that will be submitted with the request
|
/// Adds to the parameters that will be submitted with the request
|
||||||
let _hxVals = attr "hx-vals"
|
let _hxVals = attr "hx-vals"
|
||||||
|
|
||||||
/// Establishes a WebSocket or sends information to one
|
/// The name of the message to swap into the DOM.
|
||||||
let _hxWs = attr "hx-ws"
|
let _sseSwap = attr "sse-swap"
|
||||||
|
|
||||||
|
/// The URL of the SSE server.
|
||||||
|
let _sseConnect = attr "sse-connect"
|
||||||
|
|
||||||
|
|
||||||
/// Script tags to pull htmx into an web page
|
/// Script tags to pull htmx into a web page
|
||||||
module Script =
|
module Script =
|
||||||
|
|
||||||
/// Script tag to load the minified version from unpkg.com
|
/// Script tag to load the minified version from unpkg.com
|
||||||
let minified =
|
let minified =
|
||||||
script [ _src "https://unpkg.com/htmx.org@1.9.4"
|
script [ _src "https://unpkg.com/htmx.org@2.0.4"
|
||||||
_integrity "sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV"
|
_integrity "sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+"
|
||||||
_crossorigin "anonymous" ] []
|
_crossorigin "anonymous" ] []
|
||||||
|
|
||||||
/// Script tag to load the unminified version from unpkg.com
|
/// Script tag to load the unminified version from unpkg.com
|
||||||
let unminified =
|
let unminified =
|
||||||
script [ _src "https://unpkg.com/htmx.org@1.9.4/dist/htmx.js"
|
script [ _src "https://unpkg.com/htmx.org@2.0.4/dist/htmx.js"
|
||||||
_integrity "sha384-2caa3Jf+wayjuHAc9J3mR3xz191GzmIDNYVBsE8LetbkJn4wjLrO6Ht9rRMuEjIo"
|
_integrity "sha384-oeUn82QNXPuVkGCkcrInrS1twIxKhkZiFfr2TdiuObZ3n3yIeMiqcRzkIcguaof1"
|
||||||
_crossorigin "anonymous" ] []
|
_crossorigin "anonymous" ] []
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
This package enables [htmx](https://htmx.org) support within the [Giraffe](https://giraffe.wiki) view engine.
|
||||||
|
|
||||||
**htmx version: 1.9.4**
|
**htmx version: 2.0.4**
|
||||||
|
|
||||||
|
_Upgrading from v1.x: see [the migration guide](https://htmx.org/migration-guide-htmx-1/) for changes_
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|
||||||
|
|||||||
BIN
src/icon.png
Normal file
BIN
src/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
7
src/pack.sh
Executable file
7
src/pack.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
dotnet pack Common/Giraffe.Htmx.Common.fsproj -c Release
|
||||||
|
dotnet pack Htmx/Giraffe.Htmx.fsproj -c Release
|
||||||
|
dotnet pack ViewEngine.Htmx/Giraffe.ViewEngine.Htmx.fsproj -c Release
|
||||||
|
cp Common/bin/Release/Giraffe.Htmx.Common.*.nupkg .
|
||||||
|
cp Htmx/bin/Release/Giraffe.Htmx.*.nupkg .
|
||||||
|
cp ViewEngine.Htmx/bin/Release/Giraffe.ViewEngine.Htmx.*.nupkg .
|
||||||
Reference in New Issue
Block a user