This module contains definitions, commands, and transforms related to lists.
A list definition defines which elements represents ordered, unordered, and list items.
Represents if a list is ordered or unordered.
listDefinition : { ordered : RichText.Model.Element.Element, unordered : RichText.Model.Element.Element, item : RichText.Model.Element.Element } -> ListDefinition
Creates a list definition
defaultListDefinition : ListDefinition
The default list definition, which uses RichText.Definitions
orderedList
, unorderedList
and listItem
element definitions.
ordered : ListDefinition -> RichText.Model.Element.Element
Retrieves the element template for ordered lists
unordered : ListDefinition -> RichText.Model.Element.Element
Retrieves the element template for unordered lists
item : ListDefinition -> RichText.Model.Element.Element
Retrieves the element template for list items
defaultCommandMap : ListDefinition -> RichText.Config.Command.CommandMap
Creates a predefined command map related to lists. You can combine this command map with others
using RichText.Model.Command.combine
:
listCommandMap : CommandMap
listCommandMap = RichText.List.defaultCommandMap defaultListDefinition
combine listCommandMap RichText.Commands.defaultCommandMap
joinBackward : ListDefinition -> RichText.Model.State.State -> Result String RichText.Model.State.State
Joins a list item backwards if the selection is at the beginning of a list item, otherwise fails with an error.
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
]
)
, block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 1, 0, 0 ] 0)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
, block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0, 1, 0 ] 0)
joinBackward defaultListDefinition before == Ok after
--> True
joinForward : ListDefinition -> RichText.Model.State.State -> Result String RichText.Model.State.State
Joins a list item if the selection is at the end of a list item, otherwise fails with an error.
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
]
)
, block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0, 0, 0 ] 4)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
, block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0, 0, 0 ] 4)
joinForward defaultListDefinition before == Ok after
--> True
lift : ListDefinition -> RichText.Model.State.State -> Result String RichText.Model.State.State
Lifts a list item's contents out of its parent list.
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
]
)
, block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0, 0, 0 ] 4)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
, block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0 ] 4)
lift defaultListDefinition before == Ok after
--> True
liftEmpty : ListDefinition -> RichText.Model.State.State -> Result String RichText.Model.State.State
Same as lift
but only will succeed if the list item is empty.
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText ""
]
)
]
)
, block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0, 0, 0 ] 0)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText ""
]
)
, block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0 ] 0)
liftEmpty defaultListDefinition before == Ok after
--> True
split : ListDefinition -> RichText.Config.Command.Transform
Same as RichText.Commands.splitTextBlock
, but searches for a list item ancestor instead of a text block
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 0, 0, 0 ] 2)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "te"
]
)
]
)
, block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "xt"
]
)
]
)
]
)
]
)
)
(Just <| caret [ 0, 1, 0, 0 ] 0)
split defaultListDefinition before == Ok after
--> True
wrap : ListDefinition -> ListType -> RichText.Model.State.State -> Result String RichText.Model.State.State
Wraps the selection in a list.
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
, block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
)
(Just <| range [ 0, 0 ] 0 [ 1, 0 ] 0)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block (Element.element orderedList [])
(blockChildren <|
Array.fromList <|
[ block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text"
]
)
]
)
, block
(Element.element listItem [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <|
Array.fromList
[ plainText "text2"
]
)
]
)
]
)
]
)
)
(Just <| range [ 0, 0, 0, 0 ] 0 [ 0, 1, 0, 0 ] 0)
wrap defaultListDefinition Ordered before == Ok after
--> True
findListItemAncestor : RichText.Model.Element.Element -> RichText.Model.Node.Path -> RichText.Model.Node.Block -> Maybe ( RichText.Model.Node.Path, RichText.Model.Node.Block )
Finds the closest list item ancestor and path if one exists, otherwise returns Nothing
.
isBeginningOfListItem : ListDefinition -> RichText.Model.Selection.Selection -> RichText.Model.Node.Block -> Basics.Bool
True if the selection is collapsed at the beginning of a list item, false otherwise.
isEndOfListItem : ListDefinition -> RichText.Model.Selection.Selection -> RichText.Model.Node.Block -> Basics.Bool
True if the selection is collapsed at the end of a list item, false otherwise.
isListNode : ListDefinition -> RichText.Node.Node -> Basics.Bool
Returns true if the current node is a ordered or unordered list, false otherwise.