This module contains functions to validate and reduce editor state. These methods are used every time a command is applied.
reduce : RichText.Model.State.State -> RichText.Model.State.State
Reduces the state with the following rules:
before : State
before =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <| Array.fromList [ plainText "te", plainText "xt" ])
]
)
)
(Just <| caret [ 0, 1 ] 2)
after : State
after =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <| Array.fromList [ plainText "text" ])
]
)
)
(Just <| caret [ 0, 0 ] 4)
reduce before == after
--> True
validate : RichText.Config.Spec.Spec -> RichText.Model.State.State -> Result String RichText.Model.State.State
Validates the state against the spec and returns the valid state if everything is okay, otherwise returns a comma separated string of error messages.
example : State
example =
state
(block
(Element.element doc [])
(blockChildren <|
Array.fromList
[ block
(Element.element paragraph [])
(inlineChildren <| Array.fromList [ plainText "text" ])
]
)
)
(Just <| caret [ 0, 0 ] 2)
(Ok example) == (validate markdown example)
--> True
translateReducedTextBlockSelection : RichText.Model.Node.Block -> RichText.Model.State.State -> RichText.Model.State.State
Just the selection translation function that gets called in reduce
. Note that this is really only
useful if you're creating transforms that merge or remove inline nodes and you can't find a way
to easily figure out the new selection state.