Skip to content

Nested sv-root containers #140

@ornic

Description

@ornic

I have a list of elements. Some elements may have children elements. And so on. Basically, I have a tree. :)

I show this tree as nested lists, and I want user to be able to rearrange items in one dimension (before-after) and move elements freely between any levels of sub-lists.

Physically I render list as recursive component: if element have sub-list, the same component is called. All components have the same sv-root value.

The problem I stumbled upon was that sv always choose element from root list as target. The reason is this part of code:
https://github.com/kamilkp/angular-sortable-view/blob/master/src/angular-sortable-view.js#L196-L255

getDistance is used to store distance to elements. But getDistance returns 0 if mouse is inside element. So the first element from several nested elements is selected as best candidate and this first element is always from the root list.

  1. I added field .s with square (width * height) of element/container.
  2. In sort function, if both elements .q are equal, I sort them using their squares.

This way smallest (innermost!) element is placed first among candidates. Exactly what was needed! Hope this helps someone :)

And many thanks to @kamilkp for such great module!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions