This module contains definitions, commands, and transforms related to lists.
Represents if a list is ordered or unordered.
Creates a list definition
The default list definition, which uses RichText.Definitions orderedList, unorderedList and listItem
element definitions.
Retrieves the element template for ordered lists
Retrieves the element template for unordered lists
Retrieves the element template for list items
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.defaultCommandMapJoins 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
--> TrueJoins 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
--> TrueLifts 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
--> TrueSame 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
--> TrueSame 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
--> TrueWraps 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
--> TrueFinds the closest list item ancestor and path if one exists, otherwise returns Nothing.
True if the selection is collapsed at the beginning of a list item, false otherwise.
True if the selection is collapsed at the end of a list item, false otherwise.
Returns true if the current node is a ordered or unordered list, false otherwise.
A list definition defines which elements represents ordered, unordered, and list items.