Add outerSync swap; WIP on htmax view engine module

This commit is contained in:
2026-06-14 17:23:41 -04:00
parent fa813ff0fe
commit c1441e0741
10 changed files with 404 additions and 113 deletions
+5
View File
@@ -49,6 +49,11 @@ module HxSwap =
[<Literal>] [<Literal>]
let OuterMorph = "outerMorph" let OuterMorph = "outerMorph"
/// <summary>Morph the outer HTML of the target to the new content, recreating all children</summary>
/// <remarks>This is used internally by the new history extension, but can be used by others if desired</remarks>
[<Literal>]
let OuterSync = "outerSync"
/// <summary>Replace the text content of the target without parsing the response as HTML</summary> /// <summary>Replace the text content of the target without parsing the response as HTML</summary>
[<Literal>] [<Literal>]
let TextContent = "textContent" let TextContent = "textContent"
+1 -1
View File
@@ -10,7 +10,7 @@
- [Common] Add htmax bundle to provided version - [Common] Add htmax bundle to provided version
- [Server] Update HX-Target header to return tag and ID (similar to HX-Source) - [Server] Update HX-Target header to return tag and ID (similar to HX-Source)
- [Server] Add support for HX-Request-Type header - [Server] Add support for HX-Request-Type header
- [View Engine] Add hx-status attribute - [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 - [View Engine] Updated script tags to pull htmx 4.0.0-beta4, added "max" bundle links for local and CDN
See package and prior alpha release READMEs; v2 to v4 is not an update-and-forget-it release See package and prior alpha release READMEs; v2 to v4 is not an update-and-forget-it release
+3
View File
@@ -24,6 +24,9 @@ let swap =
test "OuterMorph is correct" { test "OuterMorph is correct" {
Expect.equal HxSwap.OuterMorph "outerMorph" "Outer Morph swap value incorrect" Expect.equal HxSwap.OuterMorph "outerMorph" "Outer Morph swap value incorrect"
} }
test "OuterSync is correct" {
Expect.equal HxSwap.OuterSync "outerSync" "Outer Sync swap value incorrect"
}
test "TextContent is correct" { test "TextContent is correct" {
Expect.equal HxSwap.TextContent "textContent" "Text Content swap value incorrect" Expect.equal HxSwap.TextContent "textContent" "Text Content swap value incorrect"
} }
+1 -1
View File
@@ -1,6 +1,6 @@
open Expecto open Expecto
let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests ] let allTests = testList "Giraffe" [ Common.allTests; Htmx.allTests; ViewEngine.allTests; ViewEngineMax.allTests ]
[<EntryPoint>] [<EntryPoint>]
let main args = runTestsWithCLIArgs [] args allTests let main args = runTestsWithCLIArgs [] args allTests
+1
View File
@@ -8,6 +8,7 @@
<Compile Include="Common.fs" /> <Compile Include="Common.fs" />
<Compile Include="Htmx.fs" /> <Compile Include="Htmx.fs" />
<Compile Include="ViewEngine.fs" /> <Compile Include="ViewEngine.fs" />
<Compile Include="ViewEngineMax.fs" />
<Compile Include="Program.fs" /> <Compile Include="Program.fs" />
</ItemGroup> </ItemGroup>
+81 -81
View File
@@ -138,24 +138,6 @@ let hxEvent =
Expect.equal (AfterSettle.ToHxOnString()) "after:settle" "AfterSettle hx-on event name not correct" Expect.equal (AfterSettle.ToHxOnString()) "after:settle" "AfterSettle 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 "AfterSwap" [ testList "AfterSwap" [
test "ToString succeeds" { test "ToString succeeds" {
Expect.equal (string AfterSwap) "afterSwap" "AfterSwap event name not correct" Expect.equal (string AfterSwap) "afterSwap" "AfterSwap event name not correct"
@@ -232,38 +214,6 @@ let hxEvent =
(BeforeResponse.ToHxOnString()) "before:response" "BeforeResponse hx-on event name not correct" (BeforeResponse.ToHxOnString()) "before:response" "BeforeResponse 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 "BeforeSwap" [ testList "BeforeSwap" [
test "ToString succeeds" { test "ToString succeeds" {
Expect.equal (string BeforeSwap) "beforeSwap" "BeforeSwap event name not correct" Expect.equal (string BeforeSwap) "beforeSwap" "BeforeSwap event name not correct"
@@ -673,12 +623,6 @@ let attributes =
dt [ _hxVals """{ "extra": "values" }""" ] [] dt [ _hxVals """{ "extra": "values" }""" ] []
|> shouldRender """<dt hx-vals="{ &quot;extra&quot;: &quot;values&quot; }"></dt>""" |> shouldRender """<dt hx-vals="{ &quot;extra&quot;: &quot;values&quot; }"></dt>"""
} }
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>"""
}
] ]
/// Tests for the HxModifiers module /// Tests for the HxModifiers module
@@ -719,8 +663,6 @@ let hxTags =
} }
] ]
open Giraffe.Htmx.Common
/// Tests for the Script module /// Tests for the Script module
let script = let script =
testList "Script" [ testList "Script" [
@@ -731,13 +673,6 @@ let script =
$"""<script src="/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"></script>""" $"""<script src="/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"></script>"""
"Local script tag is incorrect" "Local script tag is incorrect"
} }
test "localMax succeeds" {
let html = RenderView.AsString.htmlNode Script.localMax
Expect.equal
html
$"""<script src="/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"></script>"""
"Local script tag is incorrect"
}
test "cdnMinified succeeds" { test "cdnMinified succeeds" {
let html = RenderView.AsString.htmlNode Script.cdnMinified let html = RenderView.AsString.htmlNode Script.cdnMinified
Expect.equal Expect.equal
@@ -752,20 +687,29 @@ let script =
$"""<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-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx" crossorigin="anonymous"></script>"""
"CDN unminified script tag is incorrect" "CDN unminified script tag is incorrect"
} }
test "cdnMaxMinified succeeds" { testList "Max" [
let html = RenderView.AsString.htmlNode Script.cdnMaxMinified test "localMax succeeds" {
Expect.equal let html = RenderView.AsString.htmlNode Script.Max.local
html Expect.equal
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js" integrity="sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF" crossorigin="anonymous"></script>""" html
"CDN minified script tag is incorrect" $"""<script src="/_content/Giraffe.Htmx.Common/htmax.min.js?ver={HtmxVersion}"></script>"""
} "Local script tag is incorrect"
test "cdnMaxUnminified succeeds" { }
let html = RenderView.AsString.htmlNode Script.cdnMaxUnminified test "cdnMaxMinified succeeds" {
Expect.equal let html = RenderView.AsString.htmlNode Script.Max.cdnMinified
html Expect.equal
$"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js" integrity="sha384-gGi3Urue6ZkE4NrJCmXWIZkfNkrt1IrdP3fr0kb/v06GWg3V1RnD9Pg/Ul3qhtAK" crossorigin="anonymous"></script>""" html
"CDN unminified script tag is incorrect" $"""<script src="https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js" integrity="sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF" 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>"""
"CDN unminified script tag is incorrect"
}
]
] ]
open System.Text open System.Text
@@ -936,6 +880,24 @@ let hxEventObs =
(AfterProcessNode.ToHxOnString()) "after:process" "AfterProcessNode hx-on event name not correct" (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" [ testList "BeforeCleanupElement" [
test "ToString succeeds" { test "ToString succeeds" {
Expect.equal Expect.equal
@@ -984,6 +946,38 @@ let hxEventObs =
Expect.equal (BeforeSend.ToHxOnString()) "before:request" "BeforeSend hx-on event name not correct" 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" [ testList "HistoryCacheError" [
test "ToString succeeds" { test "ToString succeeds" {
Expect.equal (string HistoryCacheError) "historyCacheError" "HistoryCacheError event name not correct" Expect.equal (string HistoryCacheError) "historyCacheError" "HistoryCacheError event name not correct"
@@ -1123,7 +1117,7 @@ let hxEventObs =
Expect.equal (string SseError) "sseError" "SseError event name not correct" Expect.equal (string SseError) "sseError" "SseError event name not correct"
} }
test "ToHxOnString succeeds" { test "ToHxOnString succeeds" {
Expect.equal (SseError.ToHxOnString()) "error" "SseError hx-on event name not correct" Expect.equal (SseError.ToHxOnString()) "sse:error" "SseError hx-on event name not correct"
} }
] ]
testList "SseOpen" [ testList "SseOpen" [
@@ -1131,7 +1125,7 @@ let hxEventObs =
Expect.equal (string SseOpen) "sseOpen" "SseOpen event name not correct" Expect.equal (string SseOpen) "sseOpen" "SseOpen event name not correct"
} }
test "ToHxOnString succeeds" { test "ToHxOnString succeeds" {
Expect.equal (SseOpen.ToHxOnString()) "sse-open" "SseOpen hx-on event name not correct" Expect.equal (SseOpen.ToHxOnString()) "after:sse:connection" "SseOpen hx-on event name not correct"
} }
] ]
testList "SwapError" [ testList "SwapError" [
@@ -1327,6 +1321,12 @@ let attributesObs =
test "_hxRequest succeeds" { test "_hxRequest succeeds" {
u [ _hxRequest "noHeaders" ] [] |> shouldRender """<u hx-request="noHeaders"></u>""" 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 ] let obsolete = testList "Obsolete" [ hxEventObs; hxParamsObs; hxRequestObs; attributesObs ]
+170
View File
@@ -0,0 +1,170 @@
module ViewEngineMax
open Expecto
open Giraffe.ViewEngine.Htmax
/// Tests for the HxEvent module
let hxEvent =
testList "HxEvent" [
testList "AfterSseConnection" [
test "ToString succeeds" {
Expect.equal
(string AfterSseConnection) "afterSseConnection" "AfterSseConnection event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(AfterSseConnection.ToHxOnString())
"after:sse:connection"
"AfterSseConnection 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 "AfterWsConnection" [
test "ToString succeeds" {
Expect.equal
(string AfterWsConnection) "afterWsConnection" "AfterWsConnection event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(AfterWsConnection.ToHxOnString())
"after:ws:connection"
"AfterWsConnection hx-on event name not correct"
}
]
testList "AfterWsMessage" [
test "ToString succeeds" {
Expect.equal (string AfterWsMessage) "afterWsMessage" "AfterWsMessage event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(AfterWsMessage.ToHxOnString()) "after:ws:message" "AfterWsMessage hx-on event name not correct"
}
]
testList "AfterWsRequest" [
test "ToString succeeds" {
Expect.equal (string AfterWsRequest) "afterWsRequest" "AfterWsRequest event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(AfterWsRequest.ToHxOnString()) "after:ws:request" "AfterWsRequest hx-on event name not correct"
}
]
testList "BeforeSseConnection" [
test "ToString succeeds" {
Expect.equal
(string BeforeSseConnection) "beforeSseConnection" "BeforeSseConnection event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(BeforeSseConnection.ToHxOnString())
"before:sse:connection"
"BeforeSseConnection 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 "BeforeWsConnection" [
test "ToString succeeds" {
Expect.equal
(string BeforeWsConnection) "beforeWsConnection" "BeforeWsConnection event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(BeforeWsConnection.ToHxOnString())
"before:ws:connection"
"BeforeWsConnection hx-on event name not correct"
}
]
testList "BeforeWsMessage" [
test "ToString succeeds" {
Expect.equal (string BeforeWsMessage) "beforeWsMessage" "BeforeWsMessage event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(BeforeWsMessage.ToHxOnString()) "before:ws:message" "BeforeWsMessage hx-on event name not correct"
}
]
testList "BeforeWsRequest" [
test "ToString succeeds" {
Expect.equal (string BeforeWsRequest) "beforeWsRequest" "BeforeWsRequest event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal
(BeforeWsRequest.ToHxOnString()) "before:ws:request" "BeforeWsRequest hx-on event name not correct"
}
]
testList "SseClose" [
test "ToString succeeds" {
Expect.equal (string SseClose) "sseClose" "SseClose event name not correct"
}
test "ToHxOnString succeeds" {
Expect.equal (SseClose.ToHxOnString()) "sse:close" "SseClose 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"
}
]
]
open Giraffe.ViewEngine
/// Pipe-able assertion for a rendered node
let shouldRender expected node =
Expect.equal (RenderView.AsString.htmlNode node) expected "Rendered HTML incorrect"
/// Tests for the HtmaxAttrs module
let attributes =
testList "Attributes" [
test "_hxOnMax succeeds" {
body [ _hxOnMax SseClose "alert(done)" ] []
|> shouldRender """<body hx-on:htmx:sse:close="alert(done)"></body>"""
}
test "_hxSseClose succeeds" {
form [ _hxSseClose "fin" ] [] |> shouldRender """<form hx-sse:close="fin"></form>"""
}
test "_hxSseConnect succeeds" {
div [ _hxSseConnect "/path/to/resource" ] []
|> shouldRender """<div hx-sse:connect="/path/to/resource"></div>"""
}
test "_hxWsConnect succeeds" {
p [ _hxWsConnect "/over/here" ] [] |> shouldRender """<p hx-ws:connect="/over/here"></p>"""
}
testList "_hxWsSend" [
test "succeeds when given a URL" {
span [ _hxWsSend (Some "/a/new/place") ] []
|> shouldRender """<span hx-ws:send="/a/new/place"></span>"""
}
test "succeeds when not given a URL" {
aside [ _hxWsSend None ] [] |> shouldRender """<aside hx-ws:send></aside>"""
}
]
]
let allTests =
testList "ViewEngine.Htmax" [
hxEvent
attributes
]
@@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Htmx.fs" /> <Compile Include="Htmx.fs" />
<Compile Include="Htmax.fs" />
<None Include="README.md" Pack="true" PackagePath="\" /> <None Include="README.md" Pack="true" PackagePath="\" />
<None Include="..\icon.png" Pack="true" PackagePath="\" /> <None Include="..\icon.png" Pack="true" PackagePath="\" />
</ItemGroup> </ItemGroup>
+105
View File
@@ -0,0 +1,105 @@
/// <summary>Types and functions supporting htmax-bundled extension attributes in Giraffe View Engine</summary>
module Giraffe.ViewEngine.Htmax
/// <summary>The events recognized by htmax-bundled extensions</summary>
[<Struct>]
type HxEvent =
/// <summary>Fired after an SSE connection is established</summary>
| AfterSseConnection
/// <summary>Fired after an SSE message is received</summary>
| AfterSseMessage
/// <summary>Fired after a WebSocket connection is established</summary>
| AfterWsConnection
/// <summary>Fired after a WebSocket message is received</summary>
| AfterWsMessage
/// <summary>Fired after a WebSocket request is sent</summary>
| AfterWsRequest
/// <summary>Fired before an SSE connection is established (cancelable)</summary>
| BeforeSseConnection
/// <summary>Fired before a received SSE message is processed (cancelable)</summary>
| BeforeSseMessage
/// <summary>Fired before a WebSocket connection is established (cancelable)</summary>
| BeforeWsConnection
/// <summary>Fired before a received WebSocket message is processed (cancelable)</summary>
| BeforeWsMessage
/// <summary>Fired before a WebSocket request is sent (cancelable)</summary>
| BeforeWsRequest
/// <summary>Fired when an SSE connection is closed</summary>
| SseClose
/// <summary>Fired when an SSE connection errors</summary>
| SseError
/// The htmx event name (fst) and kebab-case name (snd, for use with hx-on)
static member private Values = Map [
AfterSseConnection, ("afterSseConnection", "after:sse:connection")
AfterSseMessage, ("afterSseMessage", "after:sse:message")
AfterWsConnection, ("afterWsConnection", "after:ws:connection")
AfterWsMessage, ("afterWsMessage", "after:ws:message")
AfterWsRequest, ("afterWsRequest", "after:ws:request")
BeforeSseConnection, ("beforeSseConnection", "before:sse:connection")
BeforeSseMessage, ("beforeSseMessage", "before:sse:message")
BeforeWsConnection, ("beforeWsConnection", "before:ws:connection")
BeforeWsMessage, ("beforeWsMessage", "before:ws:message")
BeforeWsRequest, ("beforeWsRequest", "before:ws:request")
SseClose, ("sseClose", "sse:close")
SseError, ("sseError", "sse:error")
]
/// <summary>The htmx event name</summary>
override this.ToString() = fst HxEvent.Values[this]
/// <summary>The <c>hx-on</c> variant of the htmx event name</summary>
member this.ToHxOnString() = snd HxEvent.Values[this]
/// <summary>Attributes and flags for htmax-bundled extensions</summary>
[<AutoOpen>]
module HtmaxAttrs =
/// <summary>Generate an <c>hx-on:htmx</c> event for an htmax-bundled extension event</summary>
/// <param name="event">The <c>HxEvent</c> to be handled</param>
/// <param name="handler">The script to be executed when the event occurs</param>
/// <returns>A configured <c>hx-on:htmx:</c> attribute</returns>
/// <seealso href="https://htmx.org/attributes/hx-on/">Documentation</seealso>
let _hxOnMax (event: HxEvent) handler =
Htmx.HtmxAttrs._hxOnEvent $"htmx:{event.ToHxOnString()}" handler
/// <summary>Define an SSE message which indicates the connection should be closed</summary>
/// <param name="message">The text of the message which indicates the SSE connection should be closed</param>
/// <returns>A configured <c>hx-sse:close</c> attribute</returns>
/// <seealso href="https://four.htmx.org/extensions/hx-sse#hx-sseclose">Documentation</seealso>
let _hxSseClose message =
attr "hx-sse:close" message
/// <summary>Define a URL to which an SSE connection should be established</summary>
/// <param name="url">The URL to which an SSE connection should be established</param>
/// <returns>A configured <c>hx-sse:connect</c> attribute</returns>
/// <seealso href="https://four.htmx.org/extensions/hx-sse#hx-sseconnect">Documentation</seealso>
let _hxSseConnect url =
attr "hx-sse:connect" url
/// <summary>Connect to a WebSocket URL</summary>
/// <param name="url">The URL to which a WebSocket connection should be established</param>
/// <returns>A configured <c>hx-ws:connect</c> attribute</returns>
/// <seealso href="https://four.htmx.org/extensions/hx-ws#usage">Documentation</seealso>
let _hxWsConnect url =
attr "hx-ws:connect" url
/// <summary>Send data via a WebSocket connection</summary>
/// <param name="url">The URL to which the data should be sent (optional; default is connection URL)</param>
/// <returns>A configured <c>hx-ws:send</c> attribute</returns>
/// <seealso href="https://four.htmx.org/extensions/hx-ws#usage">Documentation</seealso>
let _hxWsSend url =
match url with Some it -> attr "hx-ws:send" it | None -> flag "hx-ws:send"
+36 -30
View File
@@ -90,10 +90,10 @@ type HxEvent =
| AfterSettle | AfterSettle
/// <summary>Triggered after a Server Sent Events (SSE) message is read</summary> /// <summary>Triggered after a Server Sent Events (SSE) message is read</summary>
| AfterSseMessage | [<System.Obsolete "Removed in v4; use Htmax.HxEvents.AfterSseMessage">] AfterSseMessage
/// <summary>Triggered after a Server Sent Events (SSE) stream is closed</summary> /// <summary>Triggered after a Server Sent Events (SSE) stream is closed</summary>
| AfterSseStream | [<System.Obsolete "Removed in v4; SSE streaming not a function of SSE extension">] AfterSseStream
/// <summary>Triggered after new content has been swapped in</summary> /// <summary>Triggered after new content has been swapped in</summary>
| AfterSwap | AfterSwap
@@ -138,13 +138,13 @@ type HxEvent =
| [<System.Obsolete "Removed in v4; use BeforeRequest">] BeforeSend | [<System.Obsolete "Removed in v4; use BeforeRequest">] BeforeSend
/// <summary>Triggered before a Server Sent Events (SSE) message is read</summary> /// <summary>Triggered before a Server Sent Events (SSE) message is read</summary>
| BeforeSseMessage | [<System.Obsolete "Removed in v4; use Htmax.HxEvents.BeforeSseMessage">] BeforeSseMessage
/// <summary>Triggered before a Server Sent Events (SSE) connection is reconnected</summary> /// <summary>Triggered before a Server Sent Events (SSE) connection is reconnected</summary>
| BeforeSseReconnect | [<System.Obsolete "Removed in v4; use fetch event handlers">] BeforeSseReconnect
/// <summary>Triggered before a Server Sent Events (SSE) stream is opened</summary> /// <summary>Triggered before a Server Sent Events (SSE) stream is opened</summary>
| BeforeSseStream | [<System.Obsolete "Removed in v4; SSE streaming not a function of SSE extension">] BeforeSseStream
/// <summary>Triggered before a swap is done, allows you to configure the swap</summary> /// <summary>Triggered before a swap is done, allows you to configure the swap</summary>
| BeforeSwap | BeforeSwap
@@ -214,10 +214,10 @@ type HxEvent =
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SendError | [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SendError
/// <summary>Triggered when an error occurs with a SSE source</summary> /// <summary>Triggered when an error occurs with a SSE source</summary>
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SseError | [<System.Obsolete "Removed in v4; use Htmax.HxEvents.SseError)">] SseError
/// <summary>Triggered when an SSE source is opened</summary> /// <summary>Triggered when an SSE source is opened</summary>
| [<System.Obsolete "Removed in v4; use fetch event listener">] SseOpen | [<System.Obsolete "Removed in v4; use Htmax.HxEvents.AfterSseConnection">] SseOpen
/// <summary>Triggered when an error occurs during the swap phase</summary> /// <summary>Triggered when an error occurs during the swap phase</summary>
| [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SwapError | [<System.Obsolete "Removed in v4; use Error (all errors consolidated)">] SwapError
@@ -301,8 +301,8 @@ type HxEvent =
PushedIntoHistory, ("pushedIntoHistory", "after:push:into:history") PushedIntoHistory, ("pushedIntoHistory", "after:push:into:history")
ResponseError, ("responseError", "response:error") ResponseError, ("responseError", "response:error")
SendError, ("sendError", "error") SendError, ("sendError", "error")
SseError, ("sseError", "error") SseError, ("sseError", "sse:error")
SseOpen, ("sseOpen", "sse-open") SseOpen, ("sseOpen", "after:sse:connection")
SwapError, ("swapError", "error") SwapError, ("swapError", "error")
TargetError, ("targetError", "error") TargetError, ("targetError", "error")
Timeout, ("timeout", "error") Timeout, ("timeout", "error")
@@ -621,12 +621,14 @@ module HtmxAttrs =
/// <summary>The URL which will receive the request (use with <c>_hxMethod</c>)</summary> /// <summary>The URL which will receive the request (use with <c>_hxMethod</c>)</summary>
/// <param name="url">The URL for the attribute</param> /// <param name="url">The URL for the attribute</param>
/// <seealso href="https://four.htmx.org/attributes/hx-action/">Documentation</seealso> /// <seealso href="https://four.htmx.org/attributes/hx-action/">Documentation</seealso>
let _hxAction url = attr "hx-action" url let _hxAction url =
attr "hx-action" url
/// <summary>Progressively enhances anchors and forms to use AJAX requests</summary> /// <summary>Progressively enhances anchors and forms to use AJAX requests</summary>
/// <remarks>Use <c>_hxNoBoost</c> to set to false</remarks> /// <remarks>Use <c>_hxNoBoost</c> to set to false</remarks>
/// <seealso href="https://htmx.org/attributes/hx-boost/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-boost/">Documentation</seealso>
let _hxBoost = attr "hx-boost" "true" let _hxBoost =
attr "hx-boost" "true"
/// <summary>Configure request behavior</summary> /// <summary>Configure request behavior</summary>
/// <param name="config">The configuration parameters to use for the request</param> /// <param name="config">The configuration parameters to use for the request</param>
@@ -764,7 +766,8 @@ module HtmxAttrs =
/// <summary>Attach an event handler for htmx events</summary> /// <summary>Attach an event handler for htmx events</summary>
/// <param name="hxEvent">The <c>HxEvent</c> to be handled</param> /// <param name="hxEvent">The <c>HxEvent</c> to be handled</param>
/// <param name="handler">The script to be executed when the event occurs</param> /// <param name="handler">The script to be executed when the event occurs</param>
/// <returns>A configured <c>hx-on::</c> attribute</returns> /// <returns>A configured <c>hx-on:htmx:</c> attribute</returns>
/// <remarks>For events defined in htmax, use <c>_hxOnMax</c></remarks>
/// <seealso cref="HxEvent" /> /// <seealso cref="HxEvent" />
/// <seealso href="https://htmx.org/attributes/hx-on/">Documentation</seealso> /// <seealso href="https://htmx.org/attributes/hx-on/">Documentation</seealso>
let _hxOnHxEvent (hxEvent: HxEvent) handler = let _hxOnHxEvent (hxEvent: HxEvent) handler =
@@ -963,14 +966,14 @@ module HtmxAttrs =
/// <param name="url">The URL from which events will be received</param> /// <param name="url">The URL from which events will be received</param>
/// <returns>A configured <c>sse-connect</c> attribute</returns> /// <returns>A configured <c>sse-connect</c> attribute</returns>
/// <seealso href="https://htmx.org/extensions/sse/#usage">Extension Docs</seealso> /// <seealso href="https://htmx.org/extensions/sse/#usage">Extension Docs</seealso>
let _sseConnect url = let [<System.Obsolete "Removed in v4; use Htmax._hxSseConnect">] _sseConnect url =
attr "sse-connect" url attr "sse-connect" url
/// <summary>The name(s) of the message(s) to swap into the DOM</summary> /// <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> /// <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> /// <returns>A configured <c>sse-swap</c> attribute</returns>
/// <seealso href="https://htmx.org/extensions/sse/#usage">Extension Docs</seealso> /// <seealso href="https://htmx.org/extensions/sse/#usage">Extension Docs</seealso>
let _sseSwap messages = let [<System.Obsolete "Removed in v4; use hx-swap on target element">] _sseSwap messages =
attr "sse-swap" messages attr "sse-swap" messages
@@ -1011,9 +1014,6 @@ module Script =
/// <summary>Script tag to load the package-provided version of htmx</summary> /// <summary>Script tag to load the package-provided version of htmx</summary>
let local = script [ _src htmxLocalScript ] [] let local = script [ _src htmxLocalScript ] []
/// <summary>Script tag to load the package-provided version of the htmx-plus-extensions bundle</summary>
let localMax = script [ _src htmaxLocalScript ] []
/// <summary>Script tag to load the minified version from jsdelivr.net</summary> /// <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> /// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnMinified = let cdnMinified =
@@ -1027,20 +1027,26 @@ module Script =
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js" script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmx.js"
_integrity "sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx" _integrity "sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx"
_crossorigin "anonymous" ] [] _crossorigin "anonymous" ] []
/// <summary>Script tags to load the htmax bundle</summary>
module Max =
/// <summary>Script tag to load the package-provided version of the htmx-plus-extensions bundle</summary>
let local = script [ _src htmaxLocalScript ] []
/// <summary>Script tag to load the minified htmx-plus-extensions bundle from jsdelivr.net</summary>
/// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnMinified =
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js"
_integrity "sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the minified htmx-plus-extensions bundle from jsdelivr.net</summary> /// <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> /// <remarks>Ensure <c>cdn.jsdelivr.net</c> is in your CSP <c>script-src</c> list (if applicable)</remarks>
let cdnMaxMinified = let cdnUnminified =
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.min.js" script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js"
_integrity "sha384-Qoqie5IRtOE79SDFFRSb/yKi+pkzpSnfjgwr1KksyP14OaHkLHar0KrLVxUwlsJF" _integrity "sha384-gGi3Urue6ZkE4NrJCmXWIZkfNkrt1IrdP3fr0kb/v06GWg3V1RnD9Pg/Ul3qhtAK"
_crossorigin "anonymous" ] [] _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 cdnMaxUnminified =
script [ _src $"https://cdn.jsdelivr.net/npm/htmx.org@{HtmxVersion}/dist/htmax.js"
_integrity "sha384-gGi3Urue6ZkE4NrJCmXWIZkfNkrt1IrdP3fr0kb/v06GWg3V1RnD9Pg/Ul3qhtAK"
_crossorigin "anonymous" ] []
/// <summary>Script tag to load the minified version from jsdelivr.net</summary> /// <summary>Script tag to load the minified version from jsdelivr.net</summary>
[<Obsolete "Use cdnMinified instead; this will be removed in v4">] [<Obsolete "Use cdnMinified instead; this will be removed in v4">]