-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Html.Types
-- Copyright   :  (C) 2016-2025 David M. Johnson
-- License     :  BSD3-style (see the file LICENSE)
-- Maintainer  :  David M. Johnson <code@dmj.io>
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Construct custom properties on DOM elements
--
-- > div_ [ prop "id" "foo" ] [ ]
--
----------------------------------------------------------------------------
module Miso.Html.Types
  ( -- *** Types
    VTree     (..)
  , View      (..)
  , Attribute (..)
  , Key       (..)
  , NS        (..)
  -- *** Classes
  , ToView    (..)
  -- *** Combinators
  , node
  , text
  , textRaw
  , rawHtml
  ) where
-----------------------------------------------------------------------------
import           Language.Javascript.JSaddle (Object)
-----------------------------------------------------------------------------
import           Miso.String hiding (reverse)
import           Miso.Types
-----------------------------------------------------------------------------
-- | Create a new @Miso.Html.Types.TextRaw@.
--
-- @expandable@
-- a 'rawHtml' node takes raw HTML and attempts to convert it to a 'VTree'
-- at runtime. This is a way to dynamically populate the virtual DOM from
-- HTML received at runtime. If rawHtml cannot parse the HTML it will not render.
rawHtml
  :: MisoString
  -> View action
rawHtml :: forall action. MisoString -> View action
rawHtml = MisoString -> View action
forall action. MisoString -> View action
TextRaw
-----------------------------------------------------------------------------
-- | Create a new @Miso.Html.Types.Node@.
--
-- @node ns tag key attrs children@ creates a new node with tag @tag@
-- and 'Key' @key@ in the namespace @ns@. All @attrs@ are called when
-- the node is created and its children are initialized to @children@.
node :: NS
     -> MisoString
     -> Maybe Key
     -> [Attribute action]
     -> [View action]
     -> View action
node :: forall action.
NS
-> MisoString
-> Maybe Key
-> [Attribute action]
-> [View action]
-> View action
node = NS
-> MisoString
-> Maybe Key
-> [Attribute action]
-> [View action]
-> View action
forall action.
NS
-> MisoString
-> Maybe Key
-> [Attribute action]
-> [View action]
-> View action
Node
-----------------------------------------------------------------------------
-- | Create a new @Text@ with the given content.
text :: MisoString -> View action
text :: forall action. MisoString -> View action
text = MisoString -> View action
forall action. MisoString -> View action
Text
-----------------------------------------------------------------------------
-- | `TextRaw` creation. Don't use directly
textRaw :: MisoString -> View action
textRaw :: forall action. MisoString -> View action
textRaw = MisoString -> View action
forall action. MisoString -> View action
TextRaw
-----------------------------------------------------------------------------
-- | Virtual DOM implemented as a JavaScript `Object`.
--   Used for diffing, patching and event delegation.
--   Not meant to be constructed directly, see `View` instead.
newtype VTree = VTree { VTree -> Object
getTree :: Object }
-----------------------------------------------------------------------------