<commit_before>/*
 * select.js
 * @author <NAME> <<EMAIL>>
 * @copyright 2017
 * @license MIT
 *
 * JavaScript file for ui-component-select
 */

import List from 'list';
import { CoreElementMixin, extractType } from 'core';

const SelectMixin = {
  // Overrides the List version
  select (opt) {
    if (extractType(opt) === 'Number') {
      let option = this.options[opt];
      if (option) {
        this.options.forEach(o => {
          o.removeAttribute('selected');
        });
        option.setAttribute('selected', true);
        this.selected = option;
      }

      return this.close();
    } else {
      return this.select(this.options.indexOf(opt));
    }
  },

  open () {
    this.removeAttribute('collapsed')
    return this;
  },

  close () {
    this.setAttribute('collapsed', true);
    return this;
  },

  selected: null
};

const Select = function Select(el=document.createElement('div')) {
  el.classList.add('ui-component-select');
  el.options = Array.from(el.querySelectorAll('.ui-component-option'));
  el.options.forEach((x, i) => {
    x.classList.add('ui-component-list-item');
    let arrow = document.createElement('div');
    arrow.classList.add('ui-component-down-arrow');
    x.appendChild(arrow);
    x.addEventListener('click', e => {
      if (!el.getAttribute('collapsed')) {
        el.select(i);
        setTimeout(_ => { el.close() }, 500);
      }
    });
  });

  let pendingClose = null;
  el.addEventListener('click', () => el.open());
  el.addEventListener('mouseleave', () => pendingClose = setTimeout(() => { el.close(); }, 700));
  el.addEventListener('mouseenter', () => clearTimeout(pendingClose));

  Object.assign(List(el), SelectMixin);
  if (!el.selected) el.select(0);
  return el;
};

document.querySelectorAll('.ui-component-select').forEach(Select);

Select.fromArray = ls => {

};

export default Select<commit_msg>Fleshed out Select.fromArray<commit_after>/*
 * select.js
 * @author <NAME> <<EMAIL>>
 * @copyright 2017
 * @license MIT
 *
 * JavaScript file for ui-component-select
 */

import List from 'list';
import { CoreElementMixin, extractType } from 'core';

const SelectMixin = {
  // Overrides the List version
  select (opt) {
    if (extractType(opt) === 'Number') {
      let option = this.options[opt];
      if (option) {
        this.options.forEach(o => {
          o.removeAttribute('selected');
        });
        option.setAttribute('selected', true);
        this.selected = option;
      }

      return this.close();
    } else {
      return this.select(this.options.indexOf(opt));
    }
  },

  open () {
    this.removeAttribute('collapsed')
    return this;
  },

  close () {
    this.setAttribute('collapsed', true);
    return this;
  },

  selected: null
};

const Option = function Option(parent, el=document.createElement('div')) {
  el.classList.add('ui-component-list-item');
  let arrow = document.createElement('div');
  arrow.classList.add('ui-component-down-arrow');
  el.appendChild(arrow);
  el.addEventListener('click', e => {
    if (!parent.getAttribute('collapsed')) {
      parent.select(i);
      setTimeout(_ => { parent.close() }, 500);
    }
  });
};

const Select = function Select(el=document.createElement('div')) {
  el.classList.add('ui-component-select');
  el.options = Array.from(el.querySelectorAll('.ui-component-option'));
  el.options.forEach(Option);

  let pendingClose = null;
  el.addEventListener('click', () => el.open());
  el.addEventListener('mouseleave', () => pendingClose = setTimeout(() => { el.close(); }, 700));
  el.addEventListener('mouseenter', () => clearTimeout(pendingClose));

  Object.assign(List(el), SelectMixin);
  if (!el.selected) el.select(0);
  return el;
};

document.querySelectorAll('.ui-component-select').forEach(Select);

Select.fromArray = ls => {
  let select = Select();
  select.options = ls.map(item => {
    if (extractType(item).match(/html/i)) {
      return Option(item);
    } else {
      let div = document.createElement('div');
      div.textContent = item;
      return Option(div);
    }
  });

  return select;
};

export default Select
{'fraction_non_alphanumeric': 0.17375455650060753, 'fraction_numerical': 0.0053462940461725394, 'mean_word_length': 3.3099476439790574, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '5591540', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1252, 'n_words': 240}