<commit_before>import DropdownIcon from '../assets/icons/dropdown.svg';


class Picker {
  constructor(select) {
    this.select = select;
    this.container = document.createElement('span');
    this.buildPicker();
    this.select.style.display = 'none';
    this.select.parentNode.insertBefore(this.container, this.select);
    ['mousedown', 'touchstart'].forEach((name) => {
      this.label.addEventListener(name, (event) => {
        this.container.classList.toggle('ql-expanded');
        event.preventDefault();   // prevent focus loss
      });
    });
    this.select.addEventListener('change', this.update.bind(this));
  }

  buildItem(option) {
    let item = document.createElement('span');
    item.classList.add('ql-picker-item');
    if (option.hasAttribute('value')) {
      item.dataset.value = option.getAttribute('value');
    }
    if (option.textContent) {
      item.dataset.label = option.textContent;
    }
    ['mousedown', 'touchstart'].forEach((name) => {
      item.addEventListener(name, (event) => {
        this.selectItem(item, true);
        event.preventDefault();
      });
    });
    return item;
  }

  buildLabel() {
    let label = document.createElement('span');
    label.classList.add('ql-picker-label');
    label.innerHTML = DropdownIcon;
    this.container.appendChild(label);
    return label;
  }

  buildOptions() {
    let options = document.createElement('span');
    options.classList.add('ql-picker-options');
    [].slice.call(this.select.options).forEach((option) => {
      let item = this.buildItem(option);
      options.appendChild(item);
      if (option.hasAttribute('selected')) {
        this.selectItem(item);
      }
    });
    this.container.appendChild(options);
  }

  buildPicker() {
    [].slice.call(this.select.attributes).forEach((item) => {
      this.container.setAttribute(item.name, item.value);
    });
    this.container.classList.add('ql-picker');
    this.label = this.buildLabel();
    this.buildOptions();
  }

  close() {
    this.container.classList.remove('ql-expanded');
  }

  selectItem(item, trigger = false) {
    let selected = this.container.querySelector('.ql-selected');
    if (selected != null) {
      selected.classList.remove('ql-selected');
    }
    if (item != null) {
      item.classList.add('ql-selected');
      this.select.selectedIndex = [].indexOf.call(item.parentNode.children, item);
      if (item.dataset.value) {
        this.label.dataset.value = item.dataset.value;
      } else if (this.label.dataset.label) {
        delete this.label.dataset.value;
      }
      if (item.dataset.label) {<commit_msg>fix typo<commit_after>import DropdownIcon from '../assets/icons/dropdown.svg';


class Picker {
  constructor(select) {
    this.select = select;
    this.container = document.createElement('span');
    this.buildPicker();
    this.select.style.display = 'none';
    this.select.parentNode.insertBefore(this.container, this.select);
    ['mousedown', 'touchstart'].forEach((name) => {
      this.label.addEventListener(name, (event) => {
        this.container.classList.toggle('ql-expanded');
        event.preventDefault();   // prevent focus loss
      });
    });
    this.select.addEventListener('change', this.update.bind(this));
  }

  buildItem(option) {
    let item = document.createElement('span');
    item.classList.add('ql-picker-item');
    if (option.hasAttribute('value')) {
      item.dataset.value = option.getAttribute('value');
    }
    if (option.textContent) {
      item.dataset.label = option.textContent;
    }
    ['mousedown', 'touchstart'].forEach((name) => {
      item.addEventListener(name, (event) => {
        this.selectItem(item, true);
        event.preventDefault();
      });
    });
    return item;
  }

  buildLabel() {
    let label = document.createElement('span');
    label.classList.add('ql-picker-label');
    label.innerHTML = DropdownIcon;
    this.container.appendChild(label);
    return label;
  }

  buildOptions() {
    let options = document.createElement('span');
    options.classList.add('ql-picker-options');
    [].slice.call(this.select.options).forEach((option) => {
      let item = this.buildItem(option);
      options.appendChild(item);
      if (option.hasAttribute('selected')) {
        this.selectItem(item);
      }
    });
    this.container.appendChild(options);
  }

  buildPicker() {
    [].slice.call(this.select.attributes).forEach((item) => {
      this.container.setAttribute(item.name, item.value);
    });
    this.container.classList.add('ql-picker');
    this.label = this.buildLabel();
    this.buildOptions();
  }

  close() {
    this.container.classList.remove('ql-expanded');
  }

  selectItem(item, trigger = false) {
    let selected = this.container.querySelector('.ql-selected');
    if (selected != null) {
      selected.classList.remove('ql-selected');
    }
    if (item != null) {
      item.classList.add('ql-selected');
      this.select.selectedIndex = [].indexOf.call(item.parentNode.children, item);
      if (item.dataset.value) {
        this.label.dataset.value = item.dataset.value;
      } else if (this.label.dataset.value) {
        delete this.label.dataset.value;
      }
      if (item.dataset.label) {
{'fraction_non_alphanumeric': 0.16421615428680542, 'fraction_numerical': 0.0, 'mean_word_length': 3.047913446676971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '51222', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1558, 'n_words': 223}