peterszerzo/elm-arborist/1.1.0

NOTE: this package is not compatible with Elm 0.19.1

Arborist

Drag-and-drop interface to edit, dissect and-rearrange tree structures with arbitrary data sitting in their nodes.

The editor module

type Model item

Model, used for type annotation.

type alias Msg item =
Msg item

Msg type annotation for the program.

init : Tree item -> Model item

Initialize model from a tree.

update : Config item -> Msg item -> Model item -> Model item

Update method, with the global editor Config as its first argument.

updateWith : UpdateConfig -> Config item -> Msg item -> Model item -> Model item

A custom version of update, using a configuration.

type alias UpdateConfig =
{ centerAt : Float -> Float -> ( Float, Float ) }

A special update configuration object used in the custom updateWith method. It holds the following fields:

- `centerAt`: given the width and height of the canvas as float values, where should an activated node be centered. Defaults to `\width height -> ( width / 2, height / 2 )`
Config item
-> List (Attribute (Msg item))
-> Model item
-> Html (Msg item)

The view, as a function of the Config, some custom html attributes for the container, and the Model.

subscriptions : Model item -> Sub (Msg item)

Subscriptions responsible for obtaining animation frames used when animating a view centering. See example for usage.

Tree query and manipulations

tree : Model item -> Tree item

Access the current tree.

activeNode : Config item -> Model item -> Maybe ( Maybe item, ( Float, Float ) )

Returns the current active node. Returns a tuple of Maybe item (as the node maybe a placeholder for a new node), as well as its coordinates on the screen. Use these coordinates to position an active node-related pop-up (see example).

setActiveNode : item -> Model item -> Model item

Sets a new item at the active node. This may be adding a completely new item from scratch (in case the current node is a placeholder), or modifying an existing one. Typically, the modification is based off an original value provided by the activeNode method.

deleteActiveNode : Model item -> Model item

Delete the active node from a tree, including all of its children. If a placeholder is active, this method does nothing.