aboutsummaryrefslogtreecommitdiffstats
path: root/src/elements/Container.js
blob: cdf8495bff2cb6856ce7dc156e51e8834ce49cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Element from './Element.js'

export default class Container extends Element {
  flatten (parent) {
    this.each(function () {
      if (this instanceof Container) return this.flatten(parent).ungroup(parent)
      return this.toParent(parent)
    })

    // we need this so that Doc does not get removed
    this.node.firstElementChild || this.remove()

    return this
  }

  ungroup (parent) {
    parent = parent || this.parent()

    this.each(function () {
      return this.toParent(parent)
    })

    this.remove()

    return this
  }
}