<commit_before>'use strict';

class XibleEditor extends EventEmitter {
  constructor(xibleWrapper) {
    super();

    this.xibleWrapper = xibleWrapper;

    // remove all editor statuses when connection closes
    xibleWrapper.on('close', () => {
      if (!this.loadedFlow) {
        return;
      }
      this.loadedFlow.removeAllStatuses();
    });

    xibleWrapper.on('message', (message) => {
      this.messageHandler(message);
    });

    // stage element
    this.element = document.createElement('div');
    this.element.classList.add('xible');
    this.element.appendChild(document.createElement('div'));
    this.element.firstChild.classList.add('editor');
    this.element.firstChild.style.transformOrigin = '0 0';

    // check for browser support
    this.browserSupportItems = {
      attachShadow: typeof this.element.attachShadow === 'function'
    };
    this.browserSupport = true;
    for (const item in this.browserSupportItems) {
      if (!this.browserSupportItems[item]) {
        this.browserSupport = false;
        break;
      }
    }

    this.selection = [];
    this.copySelection = null;

    this.nodeDragHasFired = false;
    this.nodeDragListener = null;
    this.nodeDragSpliceConnector = false;

    this.areaMoveListener = null;

    this.dummyXibleConnectors = null;
    this.dummyXibleNode = null;
    this.dummyIo = null;

    this.flows = {};
    this.loadedFlow = null;

    this.typeDefStyleEl = null;

    // check how far the clocks of server and client are off from eachother
    // in ms
    this.serverClientDateDifference = 0;
    xibleWrapper.getServerClientDateDifference()
    .then(ms => this.serverClientDateDifference = ms);

    this.enableNodeSelector();
    this.enableZoom();
    this.enableHook();
    this.enableSelection();
    this.enablePan();
  }

  describeNode(node) {
    if (!(node instanceof XibleEditorNode)) {
      throw new Error('1st argument must be a XibleEditorNode');
    }

    node = node.duplicate(true);

    node.emit('beforeAppend');

    const describeEl = this.element.appendChild(document.createElement('div'));
    describeEl.classList.add('describe');

    // close button
    const closeButton = describeEl.appendChild(document.createElement('button'));
    closeButton.setAttribute('type', 'button');
    closeButton.appendChild(document.createTextNode('X'));
    closeButton.onclick = () => {
      this.element.removeChild(describeEl);
    };

    // ignore default xible container event handlers
    describeEl.addEventListener('wheel', (event) => {
      event.stopPropagation();
    });

    describeEl.addEventListener('mousedown', (event) => {
      event.stopPropagation();
    });

    describeEl.addEventListener('mouseup', (event) => {
      event.stopPropagation();
    });

    describeEl.addEventListener('click', (event) => {
      event.stopPropagation();
    });

    // append the node descriptionEl
    const descriptionEl = describeEl.appendChild(document.createElement('p'));
    descriptionEl.appendChild(document.createTextNode(node.description || 'not described'));

    if (!node.description) {
      descriptionEl.classList.add('none');
    }

    // append the node
    node.setPosition(0, 0);
    node.element.style.transform = '';

    // append the node type information
    /*
    let typeEl = node.element.querySelector('h1').appendChild(document.createElement('p'));
    typeEl.appendChild(document.createElement('span')).appendChild(document.createTextNode(node.type));

    if(node.type === 'action') {
      typeEl.appendChild(document.createTextNode('Double-click this header in the flow overview to start it in directed mode.'));
    }
    */

    // we need to append early because the offsetHeight/scrollHeight of
    // the description els are required to check for overflow
    describeEl.appendChild(node.element);

    // add the description for each io
    node.getInputs()
    .concat(node.getOutputs())
    .forEach((io) => {
      // get rid of event listeners
      const clonedNode = io.element.cloneNode(true);
      io.element.parentNode.replaceChild(clonedNode, io.element);
      io.element = clonedNode;

      // add description
      const descriptionEl = io.element.appendChild(document.createElement('p'));
      descriptionEl.appendChild(document.createElement('span')).appendChild(document.createTextNode(io.structureType || 'any'));
      descriptionEl.appendChild(document.createTextNode(io.description || 'not described'));

      if (!io.description) {
        descriptionEl.classList.add('none');
      }

      if (descriptionEl.scrollHeight > descriptionEl.offsetHeight) {
        descriptionEl.classList.add('overflow');
      }
    });

    // handle descriptions for input elements and labels
    node.on('editorContentLoad', () => {
      if (!node.editorContentEl) {
        return;
      }

      // add the description for each input element
      node.getRootLabelElements()
      .forEach((label) => {
        const description = label.getAttribute('data-description');

        // this is actually not allowed
        // a label may not contain a block element
        const descriptionEl = label.appendChild(document.createElement('p'));
        descriptionEl.appendChild(document.createTextNode(description || 'not described'));

        if (!description) {
          descriptionEl.classList.add('none');
        }

        if (descriptionEl.scrollHeight > descriptionEl.offsetHeight) {
          descriptionEl.classList.add('overflow');<commit_msg>linter fixes<commit_after>'use strict';

class XibleEditor extends EventEmitter {
  constructor(xibleWrapper) {
    super();

    this.xibleWrapper = xibleWrapper;

    // remove all editor statuses when connection closes
    xibleWrapper.on('close', () => {
      if (!this.loadedFlow) {
        return;
      }
      this.loadedFlow.removeAllStatuses();
    });

    xibleWrapper.on('message', (message) => {
      this.messageHandler(message);
    });

    // stage element
    this.element = document.createElement('div');
    this.element.classList.add('xible');
    this.element.appendChild(document.createElement('div'));
    this.element.firstChild.classList.add('editor');
    this.element.firstChild.style.transformOrigin = '0 0';

    // check for browser support
    this.browserSupportItems = {
      attachShadow: typeof this.element.attachShadow === 'function'
    };
    this.browserSupport = true;
    for (const item in this.browserSupportItems) {
      if (!this.browserSupportItems[item]) {
        this.browserSupport = false;
        break;
      }
    }

    this.selection = [];
    this.copySelection = null;

    this.nodeDragHasFired = false;
    this.nodeDragListener = null;
    this.nodeDragSpliceConnector = false;

    this.areaMoveListener = null;

    this.dummyXibleConnectors = null;
    this.dummyXibleNode = null;
    this.dummyIo = null;

    this.flows = {};
    this.loadedFlow = null;

    this.typeDefStyleEl = null;

    // check how far the clocks of server and client are off from eachother
    // in ms
    this.serverClientDateDifference = 0;
    xibleWrapper.getServerClientDateDifference()
    .then(ms => this.serverClientDateDifference = ms);

    this.enableNodeSelector();
    this.enableZoom();
    this.enableHook();
    this.enableSelection();
    this.enablePan();
  }

  describeNode(node) {
    if (!(node instanceof XibleEditorNode)) {
      throw new Error('1st argument must be a XibleEditorNode');
    }

    node = node.duplicate(true);

    node.emit('beforeAppend');

    const describeEl = this.element.appendChild(document.createElement('div'));
    describeEl.classList.add('describe');

    // close button
    const closeButton = describeEl.appendChild(document.createElement('button'));
    closeButton.setAttribute('type', 'button');
    closeButton.appendChild(document.createTextNode('X'));
    closeButton.onclick = () => {
      this.element.removeChild(describeEl);
    };

    // ignore default xible container event handlers
    describeEl.addEventListener('wheel', (event) => {
      event.stopPropagation();
    });

    describeEl.addEventListener('mousedown', (event) => {
      event.stopPropagation();
    });

    describeEl.addEventListener('mouseup', (event) => {
      event.stopPropagation();
    });

    describeEl.addEventListener('click', (event) => {
      event.stopPropagation();
    });

    // append the node descriptionEl
    const descriptionEl = describeEl.appendChild(document.createElement('p'));
    descriptionEl.appendChild(document.createTextNode(node.description || 'not described'));

    if (!node.description) {
      descriptionEl.classList.add('none');
    }

    // append the node
    node.setPosition(0, 0);
    node.element.style.transform = '';

    // append the node type information
    /*
    let typeEl = node.element.querySelector('h1').appendChild(document.createElement('p'));
    typeEl.appendChild(document.createElement('span')).appendChild(document.createTextNode(node.type));

    if(node.type === 'action') {
      typeEl.appendChild(document.createTextNode('Double-click this header in the flow overview to start it in directed mode.'));
    }
    */

    // we need to append early because the offsetHeight/scrollHeight of
    // the description els are required to check for overflow
    describeEl.appendChild(node.element);

    // add the description for each io
    node.getInputs()
    .concat(node.getOutputs())
    .forEach((io) => {
      // get rid of event listeners
      const clonedNode = io.element.cloneNode(true);
      io.element.parentNode.replaceChild(clonedNode, io.element);
      io.element = clonedNode;

      // add description
      const ioDescriptionEl = io.element.appendChild(document.createElement('p'));
      ioDescriptionEl.appendChild(document.createElement('span')).appendChild(document.createTextNode(io.structureType || 'any'));
      ioDescriptionEl.appendChild(document.createTextNode(io.description || 'not described'));

      if (!io.description) {
        ioDescriptionEl.classList.add('none');
      }

      if (ioDescriptionEl.scrollHeight > ioDescriptionEl.offsetHeight) {
        ioDescriptionEl.classList.add('overflow');
      }
    });

    // handle descriptions for input elements and labels
    node.on('editorContentLoad', () => {
      if (!node.editorContentEl) {
        return;
      }

      // add the description for each input element
      node.getRootLabelElements()
      .forEach((label) => {
        const description = label.getAttribute('data-description');

        // this is actually not allowed
        // a label may not contain a block element
        const labelDescriptionEl = label.appendChild(document.createElement('p'));
        labelDescriptionEl.appendChild(document.createTextNode(description || 'not described'));

        if (!description) {
          labelDescriptionEl.classList.add('none');
        }

        if (labelDescriptionEl.scrollHeight > labelDescriptionEl.offsetHeight) {
          labelDescriptionEl.classList.add('overflow');
{'fraction_non_alphanumeric': 0.1258451275579194, 'fraction_numerical': 0.0012620571531596501, 'mean_word_length': 3.1769578313253013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '2065476', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2941, 'n_words': 602}