htmx-lucid 0.2.0.0 → 0.2.0.1
raw patch · 5 files changed
+56/−7 lines, 5 filesdep ~htmx
Dependency ranges changed: htmx
Files
- htmx-lucid.cabal +3/−2
- src/Htmx/Lucid/Core.hs +3/−1
- src/Htmx/Lucid/Extension/ServerSentEvents.hs +40/−0
- src/Htmx/Lucid/Extra.hs +4/−0
- src/Htmx/Lucid/Head.hs +6/−4
htmx-lucid.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.6 name: htmx-lucid-version: 0.2.0.0+version: 0.2.0.1 synopsis: Use htmx with lucid description: Please see the README on GitHub at <https://github.com/JonathanLorimer/htmx#readme>@@ -28,13 +28,14 @@ exposed-modules: Htmx.Lucid.Core Htmx.Lucid.Extension.IncludeVals+ Htmx.Lucid.Extension.ServerSentEvents Htmx.Lucid.Extra Htmx.Lucid.Head hs-source-dirs: src build-depends: , base >=4.7 && <5- , htmx+ , htmx == 0.1.0.2 , lucid2 >=0.0.20221012 , text >=2 && <3
src/Htmx/Lucid/Core.hs view
@@ -45,7 +45,7 @@ hxSwap_ :: Text -> Attributes hxSwap_ = makeAttributes "hx-swap" --- | Like 'hxSwap' but takes a strongly typed swap style.+-- | Like 'hxSwap_' but takes a strongly typed swap style. -- This doesn't allow [modifiers](https://htmx.org/attributes/hx-swap/#modifiers) to be applied. hxSwapS_ :: Swap -> Attributes hxSwapS_ = makeAttributes "hx-swap" . render@@ -70,6 +70,8 @@ hxVals_ :: Text -> Attributes hxVals_ = makeAttributes "hx-vals" +-- | Indicates whether you are handling an arbitrary DOM event+-- or on of the bespoke 'HtmxEvent' (defined by the htmx js bundle) data OnEvent = DomOnEvent Text | HtmxOnEvent HtmxEvent -- | <https://htmx.org/attributes/hx-on/>
+ src/Htmx/Lucid/Extension/ServerSentEvents.hs view
@@ -0,0 +1,40 @@+{- |+Module : Htmx.Lucid.Extension.ServerSentEvents+Description : Attribute for connecting to an sse stream++The Server Sent Events extension connects to an EventSource directly from HTML.+It manages the connections to your web server, listens for server events, and+then swaps their contents into your htmx webpage in real-time.+<https://github.com/bigskysoftware/htmx-extensions/blob/main/src/sse/README.md>+-}+module Htmx.Lucid.Extension.ServerSentEvents where++import Data.Text (Text)+import Lucid.Base (makeAttributes, Attributes)++-- | <https://github.com/bigskysoftware/htmx-extensions/tree/main/src/sse#connecting-to-an-sse-server>+-- Provide the url to connect to, in order to establish an SSE channel.+sseConnect_ :: Text -> Attributes+sseConnect_ = makeAttributes "sse-connect"++-- | A stronger type for the different kinds of events permitted by 'sseSwap_'+data SseEventKind = Named Text | UnNamed++-- | <https://github.com/bigskysoftware/htmx-extensions/tree/main/src/sse#receiving-named-events>+-- event name to listen for in an SSE message, the contents of the message will+-- be swapped into the tag this attribute is on. For named events the message structure is as follows:+-- +-- @+-- event: EventName+-- data: <div>Content to swap into your HTML page.</div>sseSwap_ :: Text -> Attributes+-- @+--+-- For unnamed events the message structure should look like this:+--+-- @+-- data: <div>Content to swap into your HTML page.</div>sseSwap_ :: Text -> Attributes+-- @+sseSwap_ :: SseEventKind -> Attributes+sseSwap_ = \case + Named eventName -> makeAttributes "sse-swap" eventName+ UnNamed -> makeAttributes "sse-swap" "message"
src/Htmx/Lucid/Extra.hs view
@@ -90,6 +90,8 @@ hxIndicator_ :: Text -> Attributes hxIndicator_ = makeAttributes "hx-indicator" +-- | An enumeration of the filter types based on the documentation here:+-- <https://htmx.org/attributes/hx-params/> data ParamsFilter = -- | Include all parameters (default) All@@ -149,6 +151,8 @@ hxSse_ :: Text -> Attributes hxSse_ = makeAttributes "hx-sse" +-- | An enumeration of the sync strategies based on the documentation here:+-- <https://htmx.org/attributes/hx-sync/> data SyncStrategy = -- | drop (ignore) this request if an existing request is in flight (the default) SyncDrop
src/Htmx/Lucid/Head.hs view
@@ -32,18 +32,17 @@ useHtmxExtension :: (Monad m) => HtmxExtension -> HtmlT m () useHtmxExtension = useHtmxExtensionV recommendedVersion --- | Same as 'useHtmxExt' but lets you choose the version url+-- | Same as 'useHtmxExtension' but lets you choose the version url useHtmxExtensionV :: (Monad m) => (Natural, Natural, Natural) -> HtmxExtension -> HtmlT m () useHtmxExtensionV v ext = script_ [src_ $ htmxExtSrc v (render ext)] ("" :: Html ()) --- | A typesafe version of 'useHtmxExtension' based on the "included" extensions--- that the htmx codebase is tested against+-- | A version of 'useHtmxExtension' that works on a list of extensions -- NOTE: This uses 'recommendedVersion' as the version section of the URL useHtmxExtensions :: (Monad m) => [HtmxExtension] -> HtmlT m () useHtmxExtensions exts = forM_ exts useHtmxExtension --- | Same as 'useHtmxExts' but with a versioned url+-- | Same as 'useHtmxExtensions' but with a versioned url useHtmxExtensionsV :: (Monad m) => (Natural, Natural, Natural) -> [HtmxExtension] -> HtmlT m () useHtmxExtensionsV v exts = forM_ exts (useHtmxExtensionV v)@@ -62,6 +61,7 @@ recommendedVersion :: (Natural, Natural, Natural) recommendedVersion = (2, 0, 0) +-- | constant for the htmx cdn htmxSrc :: Text htmxSrc = "https://unpkg.com/htmx.org" @@ -77,10 +77,12 @@ <> "." <> showT patch +-- | Creates a string with the htmx CDN specified to version htmxSrcWithSemVer :: (Natural, Natural, Natural) -> Text htmxSrcWithSemVer ver = htmxSrc <> showSemVer ver +-- | Creates a string with the htmx extension CDN specified to version htmxExtSrc :: (Natural, Natural, Natural) -> Text -> Text htmxExtSrc ver ext = "https://unpkg.com/htmx-ext-"