Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-rosetree-path
navigate rosetrees and forests
https://github.com/lue-bird/elm-rosetree-path
elm forest multiway-tree navigation path rosetree tree tree-path
Last synced: 26 days ago
JSON representation
navigate rosetrees and forests
- Host: GitHub
- URL: https://github.com/lue-bird/elm-rosetree-path
- Owner: lue-bird
- License: mit
- Created: 2021-06-28T19:51:45.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-26T08:41:38.000Z (over 1 year ago)
- Last Synced: 2024-12-09T18:02:08.613Z (about 1 month ago)
- Topics: elm, forest, multiway-tree, navigation, path, rosetree, tree, tree-path
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/lue-bird/elm-rosetree-path/latest/
- Size: 123 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
# rosetree-path
A path is the location of a branch in a tree (or forest).
With this package you can use paths to navigate and alter
a [zwilias/elm-rosetree](https://package.elm-lang.org/packages/zwilias/elm-rosetree/latest/) or a list of them, also called a "forest".An alternative way of
keeping track of one focus is a [`Tree.Zipper`](https://package.elm-lang.org/packages/zwilias/elm-rosetree/latest/Tree-Zipper).
However! Paths are nice if you want to
- keep track of many different locations
- easily deal with _potentially_ focussed nodes etc.
- don't want to pollute `Msg`es with potentially large, changing tree contentExample: A big tree on the screen where subtrees can be moved and deleted.
```elm
import Tree.Path exposing (TreePath)
import Tree.Navigatetype alias Model =
{ tree : Tree { translate : ( Float, Float ) }
, dragged : Maybe TreePath
}type Msg =
= RightClickedOn ForestPath
| MouseMoved ( Float, Float )
--| ...viewTree =
Tree.Navigate.restructure
(\sub ->
(...
|> onMouseDown (PressedOn sub.path)
|> (case sub.path |> Tree.Path.step of
Just childPath ->
onRightClick (RightClickedOn childPath)
Nothing ->
-- top level node should not be removable
identity
)
)
:: sub.children
|> group
|> shift sub.label.translate
)update msg model =
case msg of
RightClickedOn path ->
{ model
| tree =
model.tree
|> Tree.mapChildren
(Forest.Navigate.remove path)
}
MouseMoved mousePosition ->
case model.dragged of
Just path ->
{ model
| tree =
model.tree
|> Tree.Navigate.alter path
(Tree.mapLabel
(\l -> { l | translate = ... })
)
}Nothing ->
model
--...
```Complete implementation in [example/](https://github.com/lue-bird/rosetree-path/tree/master/example/).