# Drag and drop editor for table of contents

**URL:** https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575
**Category:** Request Feedback
**Created:** [November 29, 2020, 4:07pm UTC](https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575 "2020-11-29T16:07:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jxxcarlson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jxxcarlson/32/866_2.png) [@jxxcarlson](https://discourse.elm-lang.org/u/jxxcarlson)
#### Post date: [November 29, 2020, 4:07pm UTC](https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575/1 "2020-11-29T16:07:23Z")

</div>

## TOC-Editor

This project demonstrates a drag-and-drop editor for a hierarchical table of contents (TOC). Items can be dragged vertically and the buttons \< and \> permit the user to change the indentation level. Numbering is automatic.

### Feedback

I’ve written this for use in another project, but am thinking it might be of some use to others. Thus I might make the module `TaggedItems` which manages the TOC into a library, with the app as an example of how it is used. Consequently comments on the code, API, bugs, etc. would be most welcome.

[(The Github Repo)](https://github.com/jxxcarlson/toc-editor)

### Example

By way of example, one might have a TOC that looks like this:

```auto
1 Mount Yadaax-Vor
2 The Kraken Roars
3 The Magic Stone
4 A Quiet Pool
5 Lost on the River
6 Crossing the Desert
7 A Strange Beast

```

The user can rearrange it be dragging items and using the buttons (not shown) to make it look like this.

```auto
1 A Quiet Pool
2 Mount Yadaax-Vor
  2.1 The Magic Stone
  2.2 A Strange Beast
      2.2.1 The Kraken Roars
3 Lost on the River
4 Crossing the Desert

```

The demo app uses the drag-and-drop library [annaghi/dnd-list](https://package.elm-lang.org/packages/annaghi/dnd-list/latest/) and the module `TaggedItems` in [the repo](https://github.com/jxxcarlson/toc-editor). The latter makes use of rose trees to number items in the list, specifically Ilias Van Peer’s [zwilias/elm-rosetree](https://package.elm-lang.org/packages/zwilias/elm-rosetree/latest/) and [jxxcarlson/htree](https://package.elm-lang.org/packages/jxxcarlson/htree/latest/)

### Screenshots

 ![toc1](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/a/a64e69f8ebaf7db26b36b35e69d7423768df086e.png)

 ![toc2](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/8/821a679f181880544a0d85e19a4a8ef91d5d07e1.png)

---

<div class="post-metadata">

### Author: ![FranzSkuffka](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FranzSkuffka](https://discourse.elm-lang.org/u/FranzSkuffka)
#### Post date: [November 29, 2020, 7:49pm UTC](https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575/2 "2020-11-29T19:49:29Z")

</div>

I realize now that you can not control the depth using the drag&drop interaction.

Did you try achieving this and got stuck or opted for the click-to-indent solution right away?

---

<div class="post-metadata">

### Author: ![jxxcarlson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jxxcarlson/32/866_2.png) [@jxxcarlson](https://discourse.elm-lang.org/u/jxxcarlson)
#### Post date: [November 29, 2020, 9:48pm UTC](https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575/3 "2020-11-29T21:48:17Z")

</div>

I did click-to-indent right away. It seemed to be the most natural for me in the context of a table of contents. Also, I wanted the horizontal movement to be quantized and the drag-and-drop motion to be constrained to the vertical.

---

<div class="post-metadata">

### Author: ![jxxcarlson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jxxcarlson/32/866_2.png) [@jxxcarlson](https://discourse.elm-lang.org/u/jxxcarlson)
#### Post date: [November 30, 2020, 7:56pm UTC](https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575/4 "2020-11-30T19:56:51Z")

</div>

I’ve published a [package for this](https://package.elm-lang.org/packages/jxxcarlson/toc-editor/latest/).

Here is an [Ellie which demonstrates the drag-and-drop-feature](https://ellie-app.com/bGzPy3BBWkCa1)

Quite a few changes in the API.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)
#### Post date: [December 10, 2020, 7:56pm UTC](https://discourse.elm-lang.org/t/drag-and-drop-editor-for-table-of-contents/6575/5 "2020-12-10T19:56:55Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
