jxxcarlson / toc-editor / HTOC

This library facilitates editing of multi-level tables of contents and can be used, as in the demo, to construct a drag-and-drop editor for such tables.

Types


type alias Item =
{ levels : Levels
, title : String
, id : Id
, sectionNumber : String 
}

The type for tables of content.


type alias SimpleItem a =
{ a | level : Basics.Int
, title : String
, id : Id 
}

This is the type of items that the init function operates on to produce a list of Item. If the table editor must operate on a list of items from "outside," those items must have the fields level, title, and id.

API for drag-and-drop editor

init : List (SimpleItem a) -> List Item

Transform a list of SimpleItems to a list of items. The essential point is to compute a levels field, which is used internally to ensure that the TOC is well-formed.

update : List Item -> List Item

Update the levels and section numbers of each item. These change if the items or reordered or their levels are changed. The update function repairs lists that are not well-formed.

increment : Id -> List Item -> List Item

Increment the level of the item in a list with given id.

decrement : Id -> List Item -> List Item

Decrement the level of the item in a list with given id.

Helpers for exporting computed information

These helpers are useful if a List Item must be transformed to a List SomeOtherKindOfItem.

getLevel : Item -> Basics.Int

Return the updated level of an item.

getSectionNumber : Item -> String

Return the updated section number of an item.