Decorations are functions which add a list of Html.Attribute to rendered elements and marks. They're useful for adding things like event listeners and conditional styles/attributes outside of those defined in the spec.
ElementDecoration is a type alias for an element decoration function. The arguments
are as follows:
-- A decoration which adds an onclick listener to a checkbox in a custom checkbox item element
toggleCheckboxDecoration : Path -> Element -> Path -> List (Html.Attribute Msg)
toggleCheckboxDecoration editorNodePath element relativeHtmlNodePath =
let
checked =
Maybe.withDefault False (findBoolAttribute "checked" (Element.attributes element))
in
if relativeHtmlNodePath == [ 0, 0 ] then
[ Html.Events.onClick (ToggleCheckedTodoItem editorNodePath (not checked)) ]
else
[]MarkDecoration is a type alias for an mark decoration function. The arguments
are as follows:
-- A decoration that adds a highlight class attribute to rendered link marks
highlight : Path -> Mark -> Path -> List (Html.Attribute Msg)
highlight _ _ _ =
[ Html.Attributes.class "highlight" ]Empty decorations
A dictionary of element names to a list of mark decorations.
A dictionary of mark name to a list of mark decorations.
The extra attributes added to the node with contenteditable="true" set.
Creates a decorations object with the given mark decorations set
Creates a decorations object with the given element decorations set
Creates a decorations object with the given top level attributes, e.g. extra attributes that are added
to the editor node with contenteditable="true" set.
Adds an element decoration for a defined node.
decorations =
emptyDecorations
|> addElementDecoration image (selectableDecoration InternalMsg)
--> a collection of decorations that contains a single element decoration for imageAdds a mark decoration for a defined mark.
decorations =
emptyDecorations
|> addMarkDecoration link highlight
--> a collection of decorations that contains a single mark decoration for a linkUseful decoration for selectable elements. Adds an onclick listener that will select the element, as well as adds an rte-selected class if this item is selected.
Decorationsis a collection of mark and element decorators used in th editor view.