/** * AccessibleBlockly * * Copyright 2016 Google Inc. * https://developers.google.com/blockly/ * * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @fileoverview Angular2 Component that details how Blockly.Block's are * rendered in the workspace in AccessibleBlockly. Also handles any * interactions with the blocks. * @author madeeha@google.com (Madeeha Ghori) */ blocklyApp.WorkspaceTreeView = ng.core .Component({ selector: 'tree-view', template: `
  • {{checkParentList(parentList)}}
  • `, directives: [ng.core.forwardRef(function() { return blocklyApp.WorkspaceTreeView; }), blocklyApp.FieldView], inputs: ['block', 'isTopBlock', 'topBlockIndex', 'level', 'parentId'], pipes: [blocklyApp.TranslatePipe], providers: [blocklyApp.TreeService], }) .Class({ constructor: [ blocklyApp.ClipboardService, blocklyApp.TreeService, blocklyApp.UtilsService, function(_clipboardService, _treeService, _utilsService) { this.infoBlocks = Object.create(null); this.clipboardService = _clipboardService; this.treeService = _treeService; this.utilsService = _utilsService; }], deleteBlock: function(block) { // If this is the top block, we should shift focus to the previous tree var topBlocks = blocklyApp.workspace.topBlocks_; for (var i = 0; i < topBlocks.length; i++) { if (topBlocks[i].id == block.id) { this.treeService.goToPreviousTree(this.parentId); break; } } // If this is not the top block, we should change the active descendant // of the tree. block.dispose(true); }, getMarkedBlockCompatibilityHTMLText: function(isCompatible) { return this.utilsService.getMarkedBlockCompatibilityHTMLText(isCompatible); }, generateAriaLabelledByAttr: function() { return this.utilsService.generateAriaLabelledByAttr.apply( this, arguments); }, ngOnInit: function() { var elementsNeedingIds = ['blockSummary', 'listItem', 'label', 'cutListItem', 'cutButton', 'copyListItem', 'copyButton', 'pasteBelow', 'pasteBelowButton', 'pasteAbove', 'pasteAboveButton', 'markBelow', 'markBelowButton', 'markAbove', 'markAboveButton', 'sendToSelectedListItem', 'sendToSelectedButton', 'delete', 'deleteButton']; for (var i = 0; i < this.block.inputList.length; i++) { var inputBlock = this.block.inputList[i]; if (inputBlock.connection && !inputBlock.connection.targetBlock()) { elementsNeedingIds = elementsNeedingIds.concat( ['inputList' + i, 'inputMenuLabel' + i, 'markSpot' + i, 'markSpotButton' + i, 'paste' + i, 'pasteButton' + i]); } } this.idMap = this.utilsService.generateIds(elementsNeedingIds); this.idMap['parentList'] = this.generateParentListId(); }, generateParentListId: function() { if (this.isTopBlock) { return this.parentId + '-node0' } else { return this.utilsService.generateUniqueId(); } }, getNoPreviousConnectionHTMLText: function(block) { if (!block.previousConnection) { return 'blockly-disabled'; } else { return ''; } }, getNoNextConnectionHTMLText: function(block) { if (!block.nextConnection) { return 'blockly-disabled'; } else { return ''; } }, checkParentList: function(parentList) { blocklyApp.debug && console.log('setting parent list'); var tree = parentList; var regex = /^blockly-workspace-tree\d+$/; while (tree && !tree.id.match(regex)) { tree = tree.parentNode; } if (tree && tree.getAttribute('aria-activedescendant') == parentList.id) { this.treeService.updateSelectedNode(parentList, tree, false); } }, sendToSelected: function(block) { if (this.clipboardService) { this.clipboardService.pasteToMarkedConnection(block, false); block.dispose(true); alert('Block moved to marked spot: ' + block.toString()); } } });