<commit_before>/**
 * @fileoverview High-level view of a Blockly Workspace that allows
 * for programmatically adding, moving, and deleting blocks. Does NOT
 * provide error checking.
 * @author <EMAIL> (<NAME>)
 */
'use strict';

goog.provide('SpeechBlocks.Controller');

goog.require('Blockly.Events');
goog.require('Blockly.Field');
goog.require('Blockly.FieldAngle');
goog.require('Blockly.FieldColour');
goog.require('Blockly.FieldDropdown');
goog.require('Blockly.FieldNumber');
goog.require('Blockly.FieldTextInput');
goog.require('Blockly.FieldVariable');
goog.require('Blockly.JavaScript');
goog.require('Blockly.Workspace');
goog.require('Blockly.Xml');
goog.require('Blockly.constants');
goog.require('Blockly.inject');
goog.require('SpeechBlocks.Blocks');
goog.require('SpeechBlocks.FieldTypes');
goog.require('SpeechBlocks.Translation');
goog.require('SpeechBlocks.Where');
goog.require('goog.asserts');
goog.require('goog.structs.Map');
goog.require('goog.structs.Set');

// TODO(evanfredhernandez): Remove direct access of private fields of workspace
// (particularly workspace.toolbox_) once accessors are provided.

/**
 * @param {!Blockly.Workspace} workspace
 * @private
 * @constructor
 */
SpeechBlocks.Controller = function(workspace) {
  /** @private @const {!Blockly.Workspace} */
  this.workspace_ = workspace;

  /** @private */
  this.blockCounter_ = 1;

  // Override the newBlock function to use our default IDs.
  var nextId = function() { return (this.blockCounter_++).toString(); }.bind(this);
  var newBlockOld = this.workspace_.newBlock.bind(this.workspace_);
  this.workspace_.newBlock = function(prototypeName) {
    return newBlockOld(prototypeName, nextId());
  };

  // Listen for create events and tag the block with its ID.
  this.workspace_.addChangeListener(function(event) {
    if (event.type == Blockly.Events.CREATE) {
      var newBlock =
          SpeechBlocks.Blocks.getBlock(event.blockId, this.workspace_);
      newBlock.appendDummyInput().appendField(
          new Blockly.FieldLabel(newBlock.id, 'block-id-style'));
    }
  }.bind(this));

  // Create a map of block definitions.
  this.blockXmlMap_ = new goog.structs.Map();
  if(this.workspace_.options.hasCategories) {
    this.workspace_.toolbox_.tree_.forEachChild(function(blockTab) {
      blockTab.blocks.forEach(function(block) {
        this.blockXmlMap_.set(block.getAttribute('type'), block);
      }, this)
    }, this);
  } else {
    var arr = this.workspace_.options.languageTree.children;
    for(var i = 0, len = arr.length; i < len; i++) {
        this.blockXmlMap_.set(arr[i].getAttribute('type'), arr[i]);
    }
  }
};

/**
 * Injects Blockly into the given container using the given options, and returns
 * the corresponding SpeechBlocks controller.
 * @param {!Element|string} container Containing element, or its ID, or a CSS selector.
 * @param {Object=} opt_options Optional dictionary of options.
 * @return {!SpeechBlocks.Controller} Controller for the Blockly workspace.
 * @public
 */
SpeechBlocks.Controller.injectIntoDiv = function(container, opt_options) {<commit_msg>Changed text for block number<commit_after>/**
 * @fileoverview High-level view of a Blockly Workspace that allows
 * for programmatically adding, moving, and deleting blocks. Does NOT
 * provide error checking.
 * @author <EMAIL> (<NAME>)
 */
'use strict';

goog.provide('SpeechBlocks.Controller');

goog.require('Blockly.Events');
goog.require('Blockly.Field');
goog.require('Blockly.FieldAngle');
goog.require('Blockly.FieldColour');
goog.require('Blockly.FieldDropdown');
goog.require('Blockly.FieldNumber');
goog.require('Blockly.FieldTextInput');
goog.require('Blockly.FieldVariable');
goog.require('Blockly.JavaScript');
goog.require('Blockly.Workspace');
goog.require('Blockly.Xml');
goog.require('Blockly.constants');
goog.require('Blockly.inject');
goog.require('SpeechBlocks.Blocks');
goog.require('SpeechBlocks.FieldTypes');
goog.require('SpeechBlocks.Translation');
goog.require('SpeechBlocks.Where');
goog.require('goog.asserts');
goog.require('goog.structs.Map');
goog.require('goog.structs.Set');

// TODO(evanfredhernandez): Remove direct access of private fields of workspace
// (particularly workspace.toolbox_) once accessors are provided.

/**
 * @param {!Blockly.Workspace} workspace
 * @private
 * @constructor
 */
SpeechBlocks.Controller = function(workspace) {
  /** @private @const {!Blockly.Workspace} */
  this.workspace_ = workspace;

  /** @private */
  this.blockCounter_ = 1;

  // Override the newBlock function to use our default IDs.
  var nextId = function() { return (this.blockCounter_++).toString(); }.bind(this);
  var newBlockOld = this.workspace_.newBlock.bind(this.workspace_);
  this.workspace_.newBlock = function(prototypeName) {
    return newBlockOld(prototypeName, nextId());
  };

  // Listen for create events and tag the block with its ID.
  this.workspace_.addChangeListener(function(event) {
    if (event.type == Blockly.Events.CREATE) {
      var newBlock =
          SpeechBlocks.Blocks.getBlock(event.blockId, this.workspace_);
      newBlock.appendDummyInput().appendField(
          new Blockly.FieldLabel("Block " + newBlock.id, 'block-id-style'));
    }
  }.bind(this));

  // Create a map of block definitions.
  this.blockXmlMap_ = new goog.structs.Map();
  if(this.workspace_.options.hasCategories) {
    this.workspace_.toolbox_.tree_.forEachChild(function(blockTab) {
      blockTab.blocks.forEach(function(block) {
        this.blockXmlMap_.set(block.getAttribute('type'), block);
      }, this)
    }, this);
  } else {
    var arr = this.workspace_.options.languageTree.children;
    for(var i = 0, len = arr.length; i < len; i++) {
        this.blockXmlMap_.set(arr[i].getAttribute('type'), arr[i]);
    }
  }
};

/**
 * Injects Blockly into the given container using the given options, and returns
 * the corresponding SpeechBlocks controller.
 * @param {!Element|string} container Containing element, or its ID, or a CSS selector.
 * @param {Object=} opt_options Optional dictionary of options.
 * @return {!SpeechBlocks.Controller} Controller for the Blockly workspace.
 * @public
 */
SpeechBlocks.Controller.injectIntoDiv = function(container, opt_options) {
{'fraction_non_alphanumeric': 0.14473473313030935, 'fraction_numerical': 0.0006411283859592883, 'mean_word_length': 4.703839122486289, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '940409', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1849, 'n_words': 407}