<commit_before>/*eslint quotes: [2, "single"]*/

/*global document, window */

/*global utils */

/*global TermGlobals */
/*global termKey */
/*global Parser */
/*global Terminal */

/*global Mousetrap */


// TODO 0 move
var http = {};
http.get = function (url, success) {
  var request = new XMLHttpRequest();
  request.onload = function (e) {
    success(JSON.parse(request.responseText));
  };
  request.open("get", url, true);
  request.send();
};

(function(){
    'use strict';
    // Keyboard shortcuts.

    var setCurrentBlock = function (block) {
        var current = document.querySelector('z-block.current');
        block.classList.toggle('current');
        current.classList.toggle('current');
    };

    var setCurrentPort = function (port) {
        var current = document.querySelector('z-port.current');
        port.classList.toggle('current');
        current.classList.toggle('current');
    };

    var offsetCurrentBlock = function (offset) {
        var elements = document.querySelectorAll('z-block');
        var current = document.querySelector('z-block.current');
        for (var i = 0; i < elements.length; i++) {
            if (elements[i] === current) {
                var index = (elements.length + i + offset) % elements.length;
                setCurrentBlock(elements[index]);
            }
        }
    };

    // TODO 'context' or 'mode'?
    var context = 'block';
    var offsetCurrentPort = function (offset) {
        var elements = document.querySelectorAll('z-block.current-off-context * z-port.' + context);
        var current = document.querySelector('z-port.current');
        for (var i = 0; i < elements.length; i++) {
            if (elements[i] === current) {
                var index = (elements.length + i + offset) % elements.length;
                setCurrentPort(elements[index]);
            }
        }
    };

    window.commands = {};
    var commands = window.commands;
    var offsetCurrent = function (offset) {
        if (context === 'block') {
            offsetCurrentBlock(offset);
        } else if (context === 'input' || context === 'output') {
            offsetCurrentPort(offset);
        }
    };

    commands.prev = offsetCurrent.bind(null, -1);
    commands.next = offsetCurrent.bind(null, 1);

    commands.createBlockElement = function (content, nInputs, nOutputs) {
        var patch = document.querySelector('#patch');
        content = [
            '<z-port class="input"></z-port>'.repeat(nInputs),
            content,
            '<z-port class="output"></z-port>'.repeat(nOutputs)
        ].join('');
        var htmlString = '<z-block>' + content + '</z-block>';
        var fragment = utils.dom.createFragment(htmlString);
        var block = fragment.querySelector('z-block');

        var currentBlock = document.querySelector('z-block.current');
        var position = utils.dom.getPosition(currentBlock, currentBlock.parentNode);
        var top = position.y + currentBlock.getBoundingClientRect().height + 23;
        var left = position.x;
        block.style.top = top + 'px';
        block.style.left = left + 'px';

        setCurrentBlock(block);
        patch.appendChild(fragment);
    };

    commands.addBlock = function (type) {
        var args = arguments;
        var zeClass = '';
        if (args[1] === 'number') {
            type = 'html';
            args[1] = 'span';
            zeClass = 'zed-number';
        }
        if (type === 'html') {
            var tagName = args[1];
            var content = args[2];
            var newContent = '<' + tagName + ' class="ze-content ' + zeClass + '" contenteditable>' + content + '</' + tagName + '>';
            if (tagName === 'script') {
                newContent = '<script class="ze-content" type="application/x-prevent-script-execution-onload" style="display: block;" contenteditable oninput="compileScript(this)">' + content + '</script>';
            }
            if (tagName === 'button') {
                newContent = '<button onclick="sendEventToOutputPort(this)" class="ze-content" contenteditable>' + content + '</button>';
            }
            if (tagName[0] === '<') {
                // Actually tagName contains a HTML string.
                newContent = tagName;
            }
            args = Array.prototype.slice.call(args, 2);
            args[0] = newContent;
        }
        commands.createBlockElement.apply(null, args);
    };

    commands.add = function () {
        var current;
        if (context === 'block') {
            commands.addBlock.apply(null, arguments);
        } else if (context === 'input') {
            current = document.querySelector('z-block.current-off-context');
            current.addPort('<z-port class="input"></z-port>');
        } else if (context === 'output') {
            current = document.querySelector('z-block.current-off-context');
            current.addPort('<z-port class="output"></z-port>');
        }
    };

    commands.remove = function () {
        if (context === 'block') {<commit_msg>'remove' command can now been used to remove the selected link<commit_after>/*eslint quotes: [2, "single"]*/

/*global document, window */

/*global utils */

/*global TermGlobals */
/*global termKey */
/*global Parser */
/*global Terminal */

/*global Mousetrap */


// TODO 0 move
var http = {};
http.get = function (url, success) {
  var request = new XMLHttpRequest();
  request.onload = function (e) {
    success(JSON.parse(request.responseText));
  };
  request.open("get", url, true);
  request.send();
};

(function(){
    'use strict';
    // Keyboard shortcuts.

    var setCurrentBlock = function (block) {
        var current = document.querySelector('z-block.current');
        block.classList.toggle('current');
        current.classList.toggle('current');
    };

    var setCurrentPort = function (port) {
        var current = document.querySelector('z-port.current');
        port.classList.toggle('current');
        current.classList.toggle('current');
    };

    var offsetCurrentBlock = function (offset) {
        var elements = document.querySelectorAll('z-block');
        var current = document.querySelector('z-block.current');
        for (var i = 0; i < elements.length; i++) {
            if (elements[i] === current) {
                var index = (elements.length + i + offset) % elements.length;
                setCurrentBlock(elements[index]);
            }
        }
    };

    // TODO 'context' or 'mode'?
    var context = 'block';
    var offsetCurrentPort = function (offset) {
        var elements = document.querySelectorAll('z-block.current-off-context * z-port.' + context);
        var current = document.querySelector('z-port.current');
        for (var i = 0; i < elements.length; i++) {
            if (elements[i] === current) {
                var index = (elements.length + i + offset) % elements.length;
                setCurrentPort(elements[index]);
            }
        }
    };

    window.commands = {};
    var commands = window.commands;
    var offsetCurrent = function (offset) {
        if (context === 'block') {
            offsetCurrentBlock(offset);
        } else if (context === 'input' || context === 'output') {
            offsetCurrentPort(offset);
        }
    };

    commands.prev = offsetCurrent.bind(null, -1);
    commands.next = offsetCurrent.bind(null, 1);

    commands.createBlockElement = function (content, nInputs, nOutputs) {
        var patch = document.querySelector('#patch');
        content = [
            '<z-port class="input"></z-port>'.repeat(nInputs),
            content,
            '<z-port class="output"></z-port>'.repeat(nOutputs)
        ].join('');
        var htmlString = '<z-block>' + content + '</z-block>';
        var fragment = utils.dom.createFragment(htmlString);
        var block = fragment.querySelector('z-block');

        var currentBlock = document.querySelector('z-block.current');
        var position = utils.dom.getPosition(currentBlock, currentBlock.parentNode);
        var top = position.y + currentBlock.getBoundingClientRect().height + 23;
        var left = position.x;
        block.style.top = top + 'px';
        block.style.left = left + 'px';

        setCurrentBlock(block);
        patch.appendChild(fragment);
    };

    commands.addBlock = function (type) {
        var args = arguments;
        var zeClass = '';
        if (args[1] === 'number') {
            type = 'html';
            args[1] = 'span';
            zeClass = 'zed-number';
        }
        if (type === 'html') {
            var tagName = args[1];
            var content = args[2];
            var newContent = '<' + tagName + ' class="ze-content ' + zeClass + '" contenteditable>' + content + '</' + tagName + '>';
            if (tagName === 'script') {
                newContent = '<script class="ze-content" type="application/x-prevent-script-execution-onload" style="display: block;" contenteditable oninput="compileScript(this)">' + content + '</script>';
            }
            if (tagName === 'button') {
                newContent = '<button onclick="sendEventToOutputPort(this)" class="ze-content" contenteditable>' + content + '</button>';
            }
            if (tagName[0] === '<') {
                // Actually tagName contains a HTML string.
                newContent = tagName;
            }
            args = Array.prototype.slice.call(args, 2);
            args[0] = newContent;
        }
        commands.createBlockElement.apply(null, args);
    };

    commands.add = function () {
        var current;
        if (context === 'block') {
            commands.addBlock.apply(null, arguments);
        } else if (context === 'input') {
            current = document.querySelector('z-block.current-off-context');
            current.addPort('<z-port class="input"></z-port>');
        } else if (context === 'output') {
            current = document.querySelector('z-block.current-off-context');
            current.addPort('<z-port class="output"></z-port>');
        }
    };

    commands.remove = function () {
        var selected = document.querySelector('.selected');
        if (selected.tagName === 'Z-LINK') {
            var link = selected;
            link.begin.port.unplug();
        } else if (context === 'block') {
{'fraction_non_alphanumeric': 0.15495547812620983, 'fraction_numerical': 0.0029036004645760743, 'mean_word_length': 2.2149968886123212, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 35, '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': '4070982', 'n_tokens_mistral': 2852, 'n_tokens_neox': 2832, 'n_words': 629}