diff --git a/package.json b/package.json index 4418452f5..3ba71fb0d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "gh-pages": "^0.12.0", "highlightjs": "^9.8.0", "htmlparser2": "3.9.2", - "jsdom": "^9.11.0", "json": "^9.0.4", "lodash.defaultsdeep": "4.6.0", "minilog": "3.1.0", diff --git a/src/playground/playground.js b/src/playground/playground.js index f32e17ef9..9ee924122 100644 --- a/src/playground/playground.js +++ b/src/playground/playground.js @@ -59,11 +59,6 @@ window.onload = function () { }); window.workspace = workspace; - // Filter available blocks - var toolbox = vm.filterToolbox(workspace.options.languageTree); - // var toolbox = workspace.options.languageTree; - workspace.updateToolbox(toolbox); - // Attach scratch-blocks events to VM. workspace.addChangeListener(vm.blockListener); var flyoutWorkspace = workspace.getFlyout().getWorkspace(); diff --git a/src/util/filter-toolbox.js b/src/util/filter-toolbox.js deleted file mode 100644 index 54d59ced8..000000000 --- a/src/util/filter-toolbox.js +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Filter Blockly toolbox XML node containing blocks to only those with - * valid opcodes. Return a copy of the node with valid blocks. - * @param {HTMLElement} node Blockly toolbox XML node - * @param {Array.} opcodes Valid opcodes. Blocks producing other opcodes - * will be filtered. - * @returns {HTMLElement} filtered toolbox XML node - */ -var filterToolboxNode = function (node, opcodes) { - var filteredCategory = node.cloneNode(); - for (var block = node.firstElementChild; block; block = block.nextElementSibling) { - if (block.nodeName.toLowerCase() !== 'block') continue; - var opcode = block.getAttribute('type').toLowerCase(); - if (opcodes.indexOf(opcode) !== -1) { - filteredCategory.appendChild(block.cloneNode(true)); - } - } - return filteredCategory; -}; - -/** - * Filter Blockly toolbox XML and return a copy which only contains blocks with - * existent opcodes. Categories with no valid children will be removed. - * @param {HTMLElement} toolbox Blockly toolbox XML node - * @param {Array.} opcodes Valid opcodes. Blocks producing other opcodes - * will be filtered. - * @returns {HTMLElement} filtered toolbox XML node - */ -var filterToolbox = function (toolbox, opcodes) { - if (!toolbox.hasChildNodes()) return toolbox; - var filteredToolbox; - if (toolbox.firstElementChild.nodeName.toLowerCase() === 'category') { - filteredToolbox = toolbox.cloneNode(); - for ( - var category = toolbox.firstElementChild; - category; - category = category.nextElementSibling - ) { - if (category.nodeName.toLowerCase() !== 'category') continue; - var filteredCategory = filterToolboxNode(category, opcodes); - if (filteredCategory.hasChildNodes() || - filteredCategory.hasAttribute('custom') - ) { - filteredToolbox.appendChild(filteredCategory); - } - } - } else { - filteredToolbox = filterToolboxNode(toolbox, opcodes); - } - return filteredToolbox; -}; - -module.exports = filterToolbox; diff --git a/src/virtual-machine.js b/src/virtual-machine.js index b7b56af2c..1431640fb 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -1,7 +1,6 @@ var EventEmitter = require('events'); var util = require('util'); -var filterToolbox = require('./util/filter-toolbox'); var Runtime = require('./engine/runtime'); var sb2import = require('./import/sb2import'); @@ -372,17 +371,4 @@ VirtualMachine.prototype.postSpriteInfo = function (data) { this.editingTarget.postSpriteInfo(data); }; - -/** - * Filter Blockly toolbox XML and return a copy which only contains blocks with - * existent opcodes. Categories with no valid children will be removed. - * @param {HTMLElement} toolbox Blockly toolbox XML node - * @returns {HTMLElement} filtered toolbox XML node - */ -VirtualMachine.prototype.filterToolbox = function (toolbox) { - var opcodes = Object.keys(this.runtime._primitives) - .concat(Object.keys(this.runtime._hats)); - return filterToolbox(toolbox, opcodes); -}; - module.exports = VirtualMachine; diff --git a/test/fixtures/.eslintrc.js b/test/fixtures/.eslintrc.js deleted file mode 100644 index 8df47e667..000000000 --- a/test/fixtures/.eslintrc.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - rules: { - 'max-len': [0] - } -}; diff --git a/test/fixtures/toolboxes.js b/test/fixtures/toolboxes.js deleted file mode 100644 index 5f74c89df..000000000 --- a/test/fixtures/toolboxes.js +++ /dev/null @@ -1,840 +0,0 @@ -var jsdom = require('jsdom').jsdom; -var categories = ''; -var simple = ''; -var empty = ''; -module.exports = { - categories: jsdom(categories).body.firstElementChild, - simple: jsdom(simple).body.firstElementChild, - empty: jsdom(empty).body.firstElementChild -}; diff --git a/test/unit/util_filter-toolbox.js b/test/unit/util_filter-toolbox.js deleted file mode 100644 index 9c3ea073c..000000000 --- a/test/unit/util_filter-toolbox.js +++ /dev/null @@ -1,22 +0,0 @@ -var toolboxes = require('../fixtures/toolboxes'); -var test = require('tap').test; -var filterToolbox = require('../../src/util/filter-toolbox'); - -test('categories', function (t) { - var filteredToolbox = filterToolbox(toolboxes.categories, ['motion_movesteps']); - t.strictEqual(filteredToolbox.children.length, 3); - t.strictEqual(filteredToolbox.firstElementChild.children.length, 1); - t.end(); -}); - -test('simple', function (t) { - var filteredToolbox = filterToolbox(toolboxes.simple, ['motion_movesteps']); - t.strictEqual(filteredToolbox.children.length, 1); - t.end(); -}); - -test('empty', function (t) { - var filteredToolbox = filterToolbox(toolboxes.empty, ['motion_movesteps']); - t.strictEqual(filteredToolbox.children.length, 0); - t.end(); -});