{- | Module : Htmx.Lucid.Extra Description : Provides extra htmx tags This module defines additional attributes that can be used to get additional behaviour -} module Htmx.Lucid.Extra where import Data.Foldable import Data.List (intersperse) import Data.Text (Text, pack) import Htmx.Extension import Htmx.Render import Lucid (Html, HtmlT, script_, src_) import Lucid.Base (Attributes, makeAttributes) -- | -- add progressive enhancement for links and forms hxBoost_ :: Text -> Attributes hxBoost_ = makeAttributes "hx-boost" -- | -- shows a confirm() dialog before issuing a request hxConfirm_ :: Text -> Attributes hxConfirm_ = makeAttributes "hx-confirm" -- | -- issues a DELETE to the specified URL hxDelete_ :: Text -> Attributes hxDelete_ = makeAttributes "hx-delete" -- | -- disables htmx processing for the given node and any children nodes hxDisable_ :: Attributes hxDisable_ = makeAttributes "hx-disable" mempty -- | -- adds the disabled attribute to the specified elements while a request is in flight hxDisabledElt_ :: Text -> Attributes hxDisabledElt_ = makeAttributes "hx-disabled-elt" -- | -- control and disable automatic attribute inheritance for child nodes hxDisinherit_ :: Text -> Attributes hxDisinherit_ = makeAttributes "hx-disinherit" -- | -- changes the request encoding type hxEncoding_ :: Text -> Attributes hxEncoding_ = makeAttributes "hx-encoding" -- | -- extensions to use for this element hxExt_ :: Text -> Attributes hxExt_ = makeAttributes "hx-ext" -- | A typesafe version of 'hxExt_' that works with the "included" extensions -- that the htmx codebase is tested against hxExtension_ :: HtmxExtension -> Attributes hxExtension_ = makeAttributes "hx-ext" . render -- | Include multiple extensions in one declaration hxExtensions_ :: [HtmxExtension] -> Attributes hxExtensions_ = makeAttributes "hx-ext" . fold . intersperse "," . fmap render -- | -- adds to the headers that will be submitted with the request hxHeaders_ :: Text -> Attributes hxHeaders_ = makeAttributes "hx-headers" -- | -- prevent sensitive data being saved to the history cache hxHistory_ :: Text -> Attributes hxHistory_ = makeAttributes "hx-history" -- | -- the element to snapshot and restore during history navigation hxHistoryElt_ :: Attributes hxHistoryElt_ = makeAttributes "hx-history-elt" mempty -- | -- include additional data in requests hxInclude_ :: Text -> Attributes hxInclude_ = makeAttributes "hx-include" -- | -- the element to put the htmx-request class on during the request hxIndicator_ :: Text -> Attributes hxIndicator_ = makeAttributes "hx-indicator" -- | An enumeration of the filter types based on the documentation here: -- data ParamsFilter = -- | Include all parameters (default) All | -- | Include no parameters None | -- | Include all except the list of parameter names Exclude [Text] | -- | Include all the list of parameter names Include [Text] -- | -- filters the parameters that will be submitted with a request hxParams_ :: ParamsFilter -> Attributes hxParams_ = \case All -> makeAttributes "hx-params" "*" None -> makeAttributes "hx-params" "none" Exclude ps -> makeAttributes "hx-params" $ "not " <> (fold . intersperse "," $ ps) Include ps -> makeAttributes "hx-params" $ fold . intersperse "," $ ps -- | -- issues a PATCH to the specified URL hxPatch_ :: Text -> Attributes hxPatch_ = makeAttributes "hx-patch" -- | -- specifies elements to keep unchanged between requests hxPreserve_ :: Attributes hxPreserve_ = makeAttributes "hx-preserve" mempty -- | -- shows a prompt() before submitting a request hxPrompt_ :: Text -> Attributes hxPrompt_ = makeAttributes "hx-prompt" -- | -- issues a PUT to the specified URL hxPut_ :: Text -> Attributes hxPut_ = makeAttributes "hx-put" -- | -- replace the URL in the browser location bar hxReplaceUrl_ :: Text -> Attributes hxReplaceUrl_ = makeAttributes "hx-replace-url" -- | -- configures various aspects of the request hxRequest_ :: Text -> Attributes hxRequest_ = makeAttributes "hx-request" {-# DEPRECATED hxSse_ "Don't use hx-sse directly, please use the server sent events extension instead https://htmx.org/extensions/server-sent-events/" #-} -- | -- has been moved to an extension. Documentation for older versions hxSse_ :: Text -> Attributes hxSse_ = makeAttributes "hx-sse" -- | An enumeration of the sync strategies based on the documentation here: -- data SyncStrategy = -- | drop (ignore) this request if an existing request is in flight (the default) SyncDrop | -- | drop (ignore) this request if an existing request is in flight, and, if -- that is not the case, abort this request if another request occurs while it is -- still in flight SyncAbort | -- | abort the current request, if any, and replace it with this request SyncReplace | -- | queue the first request to show up while a request is in flight SyncQueueFirst | -- | queue the last request to show up while a request is in flight SyncQueueLast | -- | queue all requests that show up while a request is in flight SyncQueueAll -- | -- control how requests made by different elements are synchronized hxSync_ :: Text -> Attributes hxSync_ = makeAttributes "hx-sync" -- | -- the same as 'hxSync_' but accepts a strongly typed htmx 'SyncStrategy' hxSyncStrategy_ :: Text -> SyncStrategy -> Attributes hxSyncStrategy_ selector = \case SyncDrop -> makeAttributes "hx-sync" $ selector <> ":" <> "drop" SyncAbort -> makeAttributes "hx-sync" $ selector <> ":" <> "abort" SyncReplace -> makeAttributes "hx-sync" $ selector <> ":" <> "replace" SyncQueueFirst -> makeAttributes "hx-sync" $ selector <> ":" <> "queue first" SyncQueueLast -> makeAttributes "hx-sync" $ selector <> ":" <> "queue last" SyncQueueAll -> makeAttributes "hx-sync" $ selector <> ":" <> "queue all" -- | -- force elements to validate themselves before a request hxValidate_ :: Text -> Attributes hxValidate_ = makeAttributes "hx-validate" -- | -- adds values dynamically to the parameters to submit with the request (deprecated, please use hx-vals) hxVars_ :: Text -> Attributes hxVars_ = makeAttributes "hx-vars" {-# DEPRECATED hxWs_ "Don't use hx-ws directly, please use the web sockets extension instead https://htmx.org/extensions/server-sent-events/https://htmx.org/extensions/web-sockets/" #-} -- | -- has been moved to an extension. Documentation for older versions hxWs_ :: Text -> Attributes hxWs_ = makeAttributes "hx-ws"