dkodaj/rte/2.1.8

NOTE: the latest version is 10.0.1

MiniRte.Styled

Same as MiniRte except it uses Html.Styled.

Init and update

init : Parameters msg -> ( Rte msg, Cmd msg )
type alias Rte msg =
{ emojiBox : Bool
, inputBox : Maybe InputBox
, styling :
{ active : List (Attribute msg)
, inactive : List (Attribute msg)
}
, tagger : Msg -> msg
, textarea : Editor
}
type alias Parameters msg =
{ id : String
, content : Maybe String
, fontSizeUnit : Maybe String
, highlighter : Maybe (Content -> Content)
, indentUnit : Maybe ( Float, String )
, selectionStyle : List ( String, String )
, styling :
{ active : List (Attribute msg)
, inactive : List (Attribute msg)
}
, tagger : Msg -> msg
}

id must be unique; it is used to monitor the position of characters.

content is the initial content of the textarea. It can be Just some plain text or a json string generated by encodedContent.

fontSizeUnit defaults to "px".

highlighter runs before each view update and it re-styles the text. See the Content type and the example.

indentUnit defaults to (50,"px").

selectionStyle controls the appearance of selected text. It defaults to [("background", "hsl(217,71%,53%)"), ("color", "white")].

styling.active styles the textarea div in active mode (when editing). Use update (Active True/False) to switch between modes.

tagger turns the package's own Msg type into your app's msg.

subscriptions : Rte msg -> Sub msg
update : Msg -> Rte msg -> ( Rte msg, Cmd msg )

View

textarea : Rte msg -> Html msg

Displays the edited text plus the cursor. This object must not be the child of a position: relative node. It screws up cursor placement.

display : (Msg -> msg) -> DisplayParams msg -> Html msg

Display formatted text, without an editor.

If you want to preserve the option of editing it, create an editor with init and put it in passive mode with update (Active False).

type alias DisplayParams msg =
{ content : String
, fontSizeUnit : Maybe String
, highlighter : Maybe (Content -> Content)
, indentUnit : Maybe ( Float, String )
, styling : List (Attribute msg)
}

content can be plain text or a json string created with encodedContent.

fontSizeUnit defaults to "px".

indentUnit defaults to (50,"px").

The attributes in styling will be attached to the div that contains the text.

Toolbar

emojiBox : Rte msg -> EmojiBoxParams msg -> Html msg

Make it appear/disappear with update ToggleEmojiBox. Each x in params.emojis turns into a clickable div that triggers update AddText events.

type alias EmojiBoxParams msg =
{ styling :
{ active : List (Attribute msg)
, inactive : List (Attribute msg)
}
, emojis : List String
}
fontSelector : Rte msg -> FontSelectorParams msg -> Html msg

A Html.select element that triggers update Font events.

type alias FontSelectorParams msg =
{ styling : List (Attribute msg)
, fonts : List (List String)
}
fontSizeSelector : Rte msg -> FontSizeSelectorParams msg -> Html msg

A Html.select element that triggers update FontSize events.

type alias FontSizeSelectorParams msg =
{ styling : List (Attribute msg)
, sizes : List Float
}
inputBox : Rte msg -> InputBoxParams msg -> Html msg

Input box for adding hyperlinks and image links. Make it appear/disappear with update ToggleImageBox or update ToggleLinkBox. It contains an OK button that triggers update ImageAdd or update LinkAdd.

type alias InputBoxParams msg =
{ styling :
{ active : List (Attribute msg)
, inactive : List (Attribute msg)
}
}
onOffSwitch : Rte msg -> SwitchParams -> Html msg

A switch that turns editing on/off. The params.width field controls its width in px.

type alias SwitchParams =
{ activeColor : String
, inactiveColor : String
, width : Float
}

Info

encodedContent : Rte msg -> String

Serialize the content of the textarea, including formatting, links, and images. You can write the result into a database and use it later with init or display.

isActive : Rte msg -> Bool

Checks if the editor is active. Suitable for both Rte and Rte.

textContent : Rte msg -> String

The plain text content of the textarea. Suitable for both Rte and Rte.