ThinkAlexandria / elm-html-in-elm / ElmHtml.InternalTypes

Internal types used to represent Elm Html in pure Elm


type ElmHtml msg
    = TextTag TextTagRecord
    | NodeEntry (NodeRecord msg)
    | CustomNode (CustomNodeRecord msg)
    | MarkdownNode (MarkdownNodeRecord msg)
    | NoOp

Type tree for representing Elm's Html


type alias TextTagRecord =
{ text : String }

Text tags just contain text


type alias NodeRecord msg =
{ tag : String
, children : List (ElmHtml msg)
, facts : Facts msg
, descendantsCount : Basics.Int 
}

A node contains the tag as a string, the children, the facts (e.g attributes) and descendantsCount


type alias CustomNodeRecord msg =
{ facts : Facts msg
, model : Json.Decode.Value 
}

Custom nodes contain facts (e.g attributes) and a json value for the model


type alias MarkdownNodeRecord msg =
{ facts : Facts msg
, model : ElmHtml.Markdown.MarkdownModel 
}

A markdown node contains facts (e.g attributes) and the model used by markdown


type alias Facts msg =
{ styles : Dict String String
, events : Dict String (Json.Decode.Decoder msg)
, attributeNamespace : Maybe Json.Decode.Value
, stringAttributes : Dict String String
, boolAttributes : Dict String Basics.Bool 
}

Facts contain various dictionaries and values for a node


type alias Tagger =
Json.Decode.Value

Tagger holds the map function when Html.Map is used, the tagger should then be applied to events comming from descendant nodes, it is basically a javascript function.


type alias EventHandler =
Json.Decode.Value

EventHandler holds the function that is called when an event is triggered, it is basically a javascript object like this:

{ decoder: [Function] }


type ElementKind
    = VoidElements
    | RawTextElements
    | EscapableRawTextElements
    | ForeignElements
    | NormalElements

Type for representing the five kinds of elements according to HTML 5 spec. Used to handle different rendering behavior depending on the type of element.


type Attribute
    = Attribute AttributeRecord
    | NamespacedAttribute NamespacedAttributeRecord
    | Property PropertyRecord
    | Styles (List ( String, String ))
    | Event EventRecord

Type for representing Elm's Attributes


type alias AttributeRecord =
{ key : String
, value : String 
}

Attribute contains a string key and a string value


type alias NamespacedAttributeRecord =
{ key : String
, value : String
, namespace : String 
}

NamespacedAttribute contains a string key, string namespace and string value


type alias PropertyRecord =
{ key : String
, value : Json.Decode.Value 
}

Property contains a string key and a value with an arbitrary type


type alias EventRecord =
{ key : String
, decoder : Json.Decode.Value
, options : { stopPropagation : Basics.Bool
, preventDefault : Basics.Bool } 
}

Event contains a string key, a decoder for a msg and event options

decodeElmHtml : (List Tagger -> EventHandler -> Json.Decode.Decoder msg) -> Json.Decode.Decoder (ElmHtml msg)

decode a json object into ElmHtml, you have to pass a function that decodes events from Html Nodes. If you don't want to decode event msgs, you can ignore it:

decodeElmHtml (_ _ -> ()) jsonHtml

if you do want to decode them, you will probably need to write some native code like elm-html-test does to extract the function inside those.

emptyFacts : Facts msg

Just empty facts

toElementKind : String -> ElementKind

Identify the kind of element. Helper to convert an tag name into a type for pattern matching.

decodeAttribute : Json.Decode.Decoder Attribute

Decode a JSON object into an Attribute. You have to pass a function that decodes events from event attributes. If you don't want to decode event msgs, you can ignore it:

decodeAttribute (\_ -> ()) jsonHtml

If you do want to decode them, you will probably need to write some native code like elm-html-test does to extract the function inside those.