{"size": 1628, "ext": "js", "max_stars_repo_path": "src/formats/list.js", "max_stars_repo_name": "acemaster/quill", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/formats/list.js", "max_issues_repo_name": "acemaster/quill", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/formats/list.js", "max_forks_repo_name": "acemaster/quill", "max_forks_repo_forks_event_min_datetime": "2016-04-12T21:47:31.000Z", "max_forks_repo_forks_event_max_datetime": "2016-04-12T21:47:31.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 22.6111111111, "max_line_length": 78, "alphanum_fraction": 0.6216216216}
import Block from '../blots/block';
import Delta from 'rich-text/lib/delta';
import Parchment from 'parchment';


class Bullet extends Parchment.Container {
  insertBefore(child, refBlot) {
    if (child instanceof Item) {
      super.insertBefore(child, refBlot);
    } else {
      if (this.children.length === 0) {
        this.appendChild(Parchment.create('item'));
      }
      this.children.head.appendChild(child);
      if (child instanceof Parchment.Block) {
        child.unwrap();
      }
    }
  }

  merge(target = this.next) {
    if (target != null && this.statics.blotName === target.statics.blotName) {
      // OL/UL should not have DOM attributes
      target.moveChildren(this);
      target.remove();
    }
    return false;
  }
}
Bullet.blotName = 'bullet';
Bullet.tagName = 'UL';


class List extends Bullet { }
List.blotName = 'list';
List.tagName = 'OL';


class Item extends Block {
  format(name, value) {
    if (Parchment.match(name, Parchment.Type.ATTRIBUTE)) {
      super.format(name, value);
    } else {
      let target = this.parent.isolate(this.offset(), this.getLength());
      if (value) {
        target.replace(name, value);
      } else {
        target.replace('block');
      }
      if (!(this.parent instanceof Bullet)) {
        this.unwrap();
      }
    }
  }

  getFormat() {
    let formats = super.getFormat();
    delete formats['item'];
    formats[this.parent.statics.blotName] = true;
    return formats;
  }
}
Item.blotName = 'item';
Item.tagName = 'LI';


Parchment.register(Bullet);
Parchment.register(List);
Parchment.register(Item);

export { Bullet, Item, List };
