98 lines
3.8 KiB
Forth
98 lines
3.8 KiB
Forth
/// <summary>Common definitions shared between attribute values and response headers</summary>
|
|
[<AutoOpen>]
|
|
module Giraffe.Htmx.Common
|
|
|
|
/// <summary>The version of htmx embedded in the package</summary>
|
|
let HtmxVersion = "4.0.0-alpha6"
|
|
|
|
/// <summary>The path for the provided htmx script</summary>
|
|
let internal htmxLocalScript = $"/_content/Giraffe.Htmx.Common/htmx.min.js?ver={HtmxVersion}"
|
|
|
|
/// <summary>Serialize a list of key/value pairs to JSON (very rudimentary)</summary>
|
|
/// <param name="pairs">The key/value pairs to be serialized to JSON</param>
|
|
/// <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 "true" or "false"</summary>
|
|
/// <param name="boolValue">The boolean value to convert</param>
|
|
/// <returns>"true" for <c>true</c>, "false" for <c>false</c></returns>
|
|
let internal toLowerBool (boolValue: bool) =
|
|
(string boolValue).ToLowerInvariant()
|
|
|
|
|
|
/// <summary>Valid values for the <c>hx-swap</c> attribute / <c>HX-Reswap</c> header</summary>
|
|
/// <remarks>May be combined with <c>swap</c> / <c>scroll</c> / <c>show</c> config)</remarks>
|
|
/// <seealso href="https://four.htmx.org/attributes/hx-swap/">Documentation</seealso>
|
|
[<RequireQualifiedAccess>]
|
|
module HxSwap =
|
|
|
|
/// <summary>The default, replace the inner HTML of the target element</summary>
|
|
[<Literal>]
|
|
let InnerHtml = "innerHTML"
|
|
|
|
/// <summary>Replace the entire target element with the response</summary>
|
|
[<Literal>]
|
|
let OuterHtml = "outerHTML"
|
|
|
|
/// <summary>Morph the inner HTML of the target to the new content</summary>
|
|
[<Literal>]
|
|
let InnerMorph = "innerMorph"
|
|
|
|
/// <summary>Morph the outer HTML of the target to the new content</summary>
|
|
[<Literal>]
|
|
let OuterMorph = "innerMorph"
|
|
|
|
/// <summary>Replace the text content of the target without parsing the response as HTML</summary>
|
|
[<Literal>]
|
|
let TextContent = "textContent"
|
|
|
|
/// <summary>Insert the response before the target element</summary>
|
|
[<Literal>]
|
|
let Before = "before"
|
|
|
|
/// <summary>Insert the response before the target element (pre-v4 name)</summary>
|
|
[<Literal>]
|
|
let BeforeBegin = Before
|
|
|
|
/// <summary>Insert the response before the first child of the target element</summary>
|
|
[<Literal>]
|
|
let Prepend = "prepend"
|
|
|
|
/// <summary>Insert the response before the first child of the target element (pre-v4 name)</summary>
|
|
[<Literal>]
|
|
let AfterBegin = Prepend
|
|
|
|
/// <summary>Insert the response after the last child of the target element</summary>
|
|
[<Literal>]
|
|
let Append = "append"
|
|
|
|
/// <summary>Insert the response after the last child of the target element (pre-v4 name)</summary>
|
|
[<Literal>]
|
|
let BeforeEnd = Append
|
|
|
|
/// <summary>Insert the response after the target element</summary>
|
|
[<Literal>]
|
|
let After = "after"
|
|
|
|
/// <summary>Insert the response after the target element (pre-v4 name)</summary>
|
|
[<Literal>]
|
|
let AfterEnd = After
|
|
|
|
/// <summary>Delete the target element regardless of response</summary>
|
|
[<Literal>]
|
|
let Delete = "delete"
|
|
|
|
/// <summary>Does not append content from response (out of band items will still be processed)</summary>
|
|
[<Literal>]
|
|
let None = "none"
|
|
|
|
/// <summary>Update existing elements by <c>id</c> and add new ones</summary>
|
|
/// <remarks>This requires the <c>upsert</c> extension</remarks>
|
|
/// <seealso href="https://four.htmx.org/extensions/upsert">Extension</seealso>
|
|
[<Literal>]
|
|
let Upsert = "upsert"
|