Module

FPO.Dto.DocumentDto.MetaTree

This module defines the meta map structure for TOC trees.

The meta map specifies the allowed structure of documents, including which types of elements can contain which other elements, how children are ordered and which can be added, whether headers are editable, and if children can be deleted.

This is imperative for enforcing document structure rules in a flexible and extensible manner, and is used extensively in the TOC component and related logic.

#KindName

type KindName = String

Specifies the kind; e.g., "document", "section", "appendix-section", ...

#TypeName

type TypeName = String

Specifies the type; e.g., "fpo-maindoc", "section", "supersection", ...

#getKindName

#getTypeName

#getDisplayNameAsString

#TreeSyntax

data TreeSyntax a

Constructors

Instances

#ChildrenOrder

data ChildrenOrder a

Constructors

Instances

#isStarOrder

isStarOrder :: forall a. ChildrenOrder a -> Boolean

Returns true iff the ChildrenOrder is a StarOrder.

#Disjunction

#isAtLeastAsGeneral

isAtLeastAsGeneral :: forall a. Eq a => Disjunction a -> Disjunction a -> Boolean

Checks if the first Disjunction is at least as general as the second, i.e., if all items in the first are also present in the second.

#getAllowedItems

getAllowedItems :: forall a. Disjunction a -> Array a

#MetaMap

type MetaMap = Array (Tuple FullTypeName ProperTypeMeta)

Type alias for the complete meta map

#emptyMetaMap

emptyMetaMap :: MetaMap

An empty meta map.

#lookupWithHeader

lookupWithHeader :: TreeHeader -> MetaMap -> Maybe ProperTypeMeta

Lookup a ProperTypeMeta in the MetaMap using a TreeHeader.

#lookupWithFullTypeName

lookupWithFullTypeName :: FullTypeName -> MetaMap -> Maybe ProperTypeMeta

Lookup a ProperTypeMeta in the MetaMap using a FullTypeName.

#findAllowedChildren

findAllowedChildren :: TreeHeader -> MetaMap -> Array (Tuple FullTypeName ProperTypeMeta)

For a given TreeHeader, find all allowed child types based on the MetaMap. Returns an array of tuples containing the FullTypeName and corresponding ProperTypeMeta.

#isAllowedChild

isAllowedChild :: forall a. RepresentsFullTypeName a => a -> TreeHeader -> MetaMap -> Boolean

Checks whether a given FullTypeName is an allowed child of the specified parent TreeHeader according to the MetaMap.

This can be used to check if a certain element can be added as a child to a parent element (e.g., via a drag-and-drop interface).

#allowsChildDeletion

allowsChildDeletion :: forall a. RepresentsFullTypeName a => a -> MetaMap -> Boolean

Determines if children of the given FullTypeName can be deleted. This is true if the element exists and has a tree syntax with StarOrder, allowing for any number of children (including zero).

#hasEditableHeader

hasEditableHeader :: forall a. RepresentsFullTypeName a => a -> MetaMap -> Boolean

Determines if the header of the given FullTypeName is editable. This is true if the element exists and has a tree syntax with HasEditableHeader true.

#applyPredicateForTreeSyntax

applyPredicateForTreeSyntax :: (TreeSyntax FullTypeName -> Boolean) -> FullTypeName -> MetaMap -> Boolean

Generic lookup function that applies a predicate to the TreeSyntax of the ProperTypeMeta associated with the given FullTypeName. Returns false if the FullTypeName is not found in the MetaMap, otherwise applies the predicate to the TreeSyntax.

#getMandatoryChildren

getMandatoryChildren :: ProperTypeMeta -> MetaMap -> Array (Tuple FullTypeName ProperTypeMeta)

Returns all direct children that must be present according to a sequence order.

#getDisjunction

getDisjunction :: forall a. RepresentsFullTypeName a => a -> MetaMap -> Maybe (Disjunction FullTypeName)

If the FullTypeName corresponds to a StarOrder in the MetaMap, returns the associated Disjunction FullTypeName.

This can be viewed as the pendant to findAllowedChildren for StarOrder types. It returns, if applicable, the Disjunction that specifies which children may be added in any quantity and order.

#decodeMetaMap

decodeMetaMap :: Json -> Either JsonDecodeError MetaMap

Helper function to decode the entire meta map

#DocumentTreeWithMetaMap

newtype DocumentTreeWithMetaMap a

Wrapper type to hold both the document tree and its associated meta map.

Constructors

#decodeDocumentWithMetaMap

decodeDocumentWithMetaMap :: forall a. DecodeJson a => Json -> Either JsonDecodeError (DocumentTreeWithMetaMap a)

This is an extended version of decodeDocument that also extracts the metaMap, see DocumentTreeWithMetaMap. It would be wise to, at some point, refactor the documentDto system and everything related to RootTree. For now, this is a quick solution to get the meta map alongside the document tree.

#prettyPrintMetaMap

prettyPrintMetaMap :: MetaMap -> String

Pretty print with nice formatting and indentation

#indent

#RepresentsFullTypeName

class RepresentsFullTypeName a  where

Anything that can represent a full type name (i.e., has kind and type) can implement this type class to provide a way to extract the FullTypeName, i.e., implicitly convert itself to a FullTypeName.

This way, one can use TreeHeader or other wrappers directly in query/interfacing functions, rather than always having to convert manually to FullTypeName.

Members

Instances

Modules