{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} ----------------------------------------------------------------------------- -- | -- Module : Miso.Html.Internal -- Copyright : (C) 2016-2018 David M. Johnson -- License : BSD3-style (see the file LICENSE) -- Maintainer : David M. Johnson -- Stability : experimental -- Portability : non-portable ---------------------------------------------------------------------------- module Miso.Html.Internal ( -- * Core types and interface VTree (..) , View (..) , ToView (..) , Attribute (..) -- * Smart `View` constructors , node , text , textRaw -- * Key patch internals , Key (..) , ToKey (..) -- * Namespace , NS (..) -- * Setting properties on virtual DOM nodes , prop -- * Setting CSS , style_ -- * Handling events , on , onWithOptions -- * Life cycle events , onCreated , onDestroyed , onBeforeDestroyed ) where import Data.Aeson (Value(..), ToJSON(..)) import qualified Data.Map as M import Data.Proxy import Data.String (IsString(..)) import qualified Data.Text as T import qualified Data.Vector as V import qualified Lucid as L import qualified Lucid.Base as L import Prelude hiding (null) import Servant.API import Miso.Event import Miso.String hiding (map) -- | Virtual DOM implemented as a Rose `Vector`. -- Used for diffing, patching and event delegation. -- Not meant to be constructed directly, see `View` instead. data VTree action where VNode :: { vType :: Text -- ^ Element type (i.e. "div", "a", "p") , vNs :: NS -- ^ HTML or SVG , vProps :: Props -- ^ Fields present on DOM Node , vKey :: Maybe Key -- ^ Key used for child swap patch , vChildren :: V.Vector (VTree action) -- ^ Child nodes } -> VTree action VText :: { vText :: Text -- ^ TextNode content } -> VTree action -- Invariant: To avoid complexity with collapsing mixed VText and -- VTextRaw nodes, VTextRaw node is always the only child. -- That's not a big limitation, since the intended purpose is to be able -- to use