<commit_before>;(function(define){'use strict';define(function(require,exports,module){

/**
 * Dependencies
 */

var component = require('gaia-component');

/**
 * Simple logger (toggle 0)
 *
 * @type {Function}
 */
var debug = 1 ? console.log.bind(console) : function() {};

const NODE_TYPES = {
  1: 'element',
  3: 'text'
};

/**
 * Register the element.
 *
 * @return {Element} constructor
 */
module.exports = component.register('gaia-dom-tree', {

  /**
   * Called when the element is first created.
   *
   * Here we create the shadow-root and
   * inject our template into it.
   *
   * @private
   */
  created: function() {
    debug('created');
    this.setupShadowRoot();
    this.els = {
      inner: this.shadowRoot.querySelector('.inner'),
      tree: this.shadowRoot.querySelector('.tree')
    };

    this.selectedTreeNode = null;
    this.selectedNode = null;
    this.treeMap = new Map();
    this.els.inner.addEventListener('click', e => this.onInnerClick(e));
  },

  setRoot: function(el) {
    debug('set root', el);
    this.root = el;
  },

  render: function() {
    var tree = this.createTree(this.root);
    this.els.tree.innerHTML = '';
    this.els.tree.appendChild(tree);
    debug('rendered');
  },

  select: function(el) {
    debug('select', el);
    var treeNode = this.treeMap.get(el);
    if (!treeNode) return;
    this.selectNode(treeNode);
    this.expandNode(treeNode);
  },

  onInnerClick: function(e) {
    debug('inner click', e);
    var nodeTitle = e.target.closest('h3');
    if (nodeTitle) this.onNodeTitleClick(nodeTitle);
  },

  onNodeTitleClick: function(el) {
    var node = el.closest('li');
    this.toggleExpanded(node);
    this.selectNode(node);
  },

  expandNode: function(node) {
    debug('expand node', node);
    node.classList.add('expanded');
    var parent = node.parentNode.closest('li');
    if (parent) this.expandNode(parent);
  },

  contractNode: function(node) {
    node.classList.remove('expanded');
  },

  toggleExpanded: function(node) {
    var expanded = node.classList.contains('expanded');
    if (expanded) this.contractNode(node);
    else this.expandNode(node);
  },

  selectNode: function(treeNode) {
    var previous = this.selectedTreeNode;
    if (previous) previous.classList.remove('selected');
    treeNode.classList.add('selected');
    this.selectedTreeNode = treeNode;
    this.selectedNode = treeNode.sourceNode;
    this.despatch('selected');
  },

  despatch: function(name) {
    this.dispatchEvent(new Event('selected'));
  },

  createTree: function(node) {
    var treeNode = document.createElement('li');
    var title = document.createElement('h3');
    var children = document.createElement('ul');
    var type = NODE_TYPES[node.nodeType];
    var childNodes = node.childNodes;
    var stringified = stringify[type](node);

    if (!stringified) return;

    title.innerHTML = stringified;

    treeNode.appendChild(title);
    treeNode.appendChild(children);
    treeNode.sourceNode = node;
    treeNode.classList.add(type);

    // Flag when a node has children
    treeNode.classList.toggle('has-children', !!childNodes.length);

    [].map.call(childNodes, (node) => this.createTree(node))
      .filter(node => !!node)
      .forEach(children.appendChild, children);

    this.treeMap.set(node, treeNode);
    return treeNode;
  },
<commit_msg>Add contextmenu event to inner DOM tree<commit_after>;(function(define){'use strict';define(function(require,exports,module){

/**
 * Dependencies
 */

var component = require('gaia-component');

/**
 * Simple logger (toggle 0)
 *
 * @type {Function}
 */
var debug = 1 ? console.log.bind(console) : function() {};

const NODE_TYPES = {
  1: 'element',
  3: 'text'
};

/**
 * Register the element.
 *
 * @return {Element} constructor
 */
module.exports = component.register('gaia-dom-tree', {

  /**
   * Called when the element is first created.
   *
   * Here we create the shadow-root and
   * inject our template into it.
   *
   * @private
   */
  created: function() {
    debug('created');
    this.setupShadowRoot();
    this.els = {
      inner: this.shadowRoot.querySelector('.inner'),
      tree: this.shadowRoot.querySelector('.tree')
    };

    this.selectedTreeNode = null;
    this.selectedNode = null;
    this.treeMap = new Map();
    this.els.inner.addEventListener('click', e => this.onInnerClick(e));
    this.els.inner.addEventListener('contextmenu', e => this.onInnerClick(e));
  },

  setRoot: function(el) {
    debug('set root', el);
    this.root = el;
  },

  render: function() {
    var tree = this.createTree(this.root);
    this.els.tree.innerHTML = '';
    this.els.tree.appendChild(tree);
    debug('rendered');
  },

  select: function(el) {
    debug('select', el);
    var treeNode = this.treeMap.get(el);
    if (!treeNode) return;
    this.selectNode(treeNode);
    this.expandNode(treeNode);
  },

  onInnerClick: function(e) {
    debug('inner click', e);
    var nodeTitle = e.target.closest('h3');
    if (nodeTitle) this.onNodeTitleClick(e, nodeTitle);
  },

  onNodeTitleClick: function(e, el) {
    var node = el.closest('li');
    this.toggleExpanded(node);
    this.selectNode(e, node);
  },

  expandNode: function(node) {
    debug('expand node', node);
    node.classList.add('expanded');
    var parent = node.parentNode.closest('li');
    if (parent) this.expandNode(parent);
  },

  contractNode: function(node) {
    node.classList.remove('expanded');
  },

  toggleExpanded: function(node) {
    var expanded = node.classList.contains('expanded');
    if (expanded) this.contractNode(node);
    else this.expandNode(node);
  },

  selectNode: function(e, treeNode) {
    var previous = this.selectedTreeNode;
    if (previous) previous.classList.remove('selected');
    treeNode.classList.add('selected');
    this.selectedTreeNode = treeNode;
    this.selectedNode = treeNode.sourceNode;
    this.despatch(e.type === 'click' ? 'selected' : 'longpressed');
  },

  despatch: function(name) {
    this.dispatchEvent(new Event(name));
  },

  createTree: function(node) {
    var treeNode = document.createElement('li');
    var title = document.createElement('h3');
    var children = document.createElement('ul');
    var type = NODE_TYPES[node.nodeType];
    var childNodes = node.childNodes;
    var stringified = stringify[type](node);

    if (!stringified) return;

    title.innerHTML = stringified;

    treeNode.appendChild(title);
    treeNode.appendChild(children);
    treeNode.sourceNode = node;
    treeNode.classList.add(type);

    // Flag when a node has children
    treeNode.classList.toggle('has-children', !!childNodes.length);

    [].map.call(childNodes, (node) => this.createTree(node))
      .filter(node => !!node)
      .forEach(children.appendChild, children);

    this.treeMap.set(node, treeNode);
    return treeNode;
  },

{'fraction_non_alphanumeric': 0.1555037856726849, 'fraction_numerical': 0.0017472335468841002, 'mean_word_length': 3.483681462140992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '4577859', 'n_tokens_mistral': 2183, 'n_tokens_neox': 2158, 'n_words': 428}