Files
blockly/accessible/workspace_treeview.component.js
M 6474fcd774 AccessibleBlockly (#354)
* adding a folder in demos for blind and setting up the package.json file for development. Adding package.json to .gitignore

* removing gitignore~ file

* copied blind blockly demo code over. set up a new dev environment. Up for review: the blind blockly demo code. Much of the drop downs don't actually do anything, but a general look at the way angular is used would be helpful in shaping future development.

* adding an index file that was being ignored by .gitignore

* adding required angular files and libraries previously ignored by git add --a for some unknown reason.

* starting work on toolbox

* got workspace and toolbox connected. Copy to workspace annd copy to clipboard working at 80%.

* cleaning up autogenerated files

* adding my own files. Not sure why the test files are being added.

* cleaning up comments

* removed empty html_formatter.html file from project and put on git ignore list. The file is used on my end to help with formatting the html in javascript files.

* getting rid of unnecessary html_formatter file

* removing merge conflicts

* cleaned up comments

* cleaned up comments, organized file structure, made ToolboxXML a file that can be changed by other developers porting this code, added copyright and file summaries to js files, linted files, moved third party libraries to lib folder

* removing lint files that shouldn't be tracked.

* Made the clipboard a service instead of multiple pieces embedded within the app. Not sold on the name ClipboardService. Open to suggestions.

* syncing up demo updates

* adding insert block menus above and below appropriate blocks.

* hacky version of getting code to run.

* changing toolbox to be a menu. making both the toolbox and workspace ordered lists

* adding new folder dev-old containing a version of blind blockly that uses nested lists for the toolbox

* getting rid of menubar experiment

* adding treeview shenanigans part 1

* adding treeview experiment page and finishing up treeview.

* getting a treeview implementation working in the toolbox

* creating a fishfood folder for fishfood development

* making first level of fishfood

* fixing something

* adding index file for fishfood

* beginning merging the treeview system.

* creating two treeviews

* fishfood level 1 without working music blocks

* fixes to treeview navigation

* final fishfood features done

* adding support for toolboxes without categories

* beginning integration of Sean's new music code

* adding Sean's music blocks and beginning music_player integration.

* merged Sean's music block code into fishfood

* merged Sean's music code and fixed treeview bug with toolbox when no categories

* adding blank_demo

* fixing tab navigation.

* fixing bug with shift-tab. New bug found in alt+tab not opening dropdown?

* fixing labels

* fixing bugs and finding more.

* removing dropdowns in favor of buttons part 1. Still need to change field options.

* index.html for blank_demo

* beginning cleanup

* adding blockly- prefix to label ids.

* integrating AccessibleBlockly with Blockly library.

* remove closure library

* removing testing files that aren't in develop

* removing all demo stuff for a later pull request

* removing gitignore file that doesn't exist in developer branch

* syncing with develop branch files

* removing music files from this pull request

* doing some lint cleanup

* rolling back accidental package.json change

* removing var blocklyApp = blocklyApp || {} from each extraneous file

* adding last debug statement

* changed name of inputType function

* renaming _service arguments

* fixing function names

* fixing all comments.

* fixing minor comments

* renaming variables, etc

* fixing bugs that break demo. Adding the run code and clear workspace buttons back to the workspaceview as their current position breaks tab navigation.

* fixing minor comments

* fixing function names, etc.

* adding comments to getInputTypeLabel function

* removing addClass() calls from the template

* small change to clipboardService

* splitting getCategoryDependantId into two functions: getCategoryId and setActiveDesc

* fixing minor bug with last commit

* using conditional attributes to remove setActiveAttributes function from treeService and do same work in template.

* deleting unnecessary comment created in previous commit.

* adding a utilsService to remove duplicated code.

* changing function names in utilsService

* changing delete to [delete] to allow HTMLText functions to return an empty string instead of undefined. Also renaming concatStringWithSpaces to generateAriaLabelledByAttr

* generating ids in ngOnInit instead of on the fly, allowing us to use [attr.aria-labelledBy] in the template instead of using setLabelledBy(element). Deleting function utilsService.setLabelledBy.

* fixing small bug with tree service left arrow: was throwing an error when you can't go any further left.

* reformatting html to make it easier to read.

* moving from importing the xml file to using an xml toolbox in the demo.

* fixing minor bugs and removing code relevant only to the music game.

* minor fixes

* adding alerts to copy, paste, and mark actions. renaming blocklyApp.TreeView to blocklyApp.WorkspaceTreeView

* Beginning to add Blockly.msg strings.

* making sure index file is being tracked

* adding all demo bits

* removing demo files from this pull request

* fixing providers, some linting, and removing getInfo() function.

* adding small todo comment for sll@

* adding minimal Accessible Blockly demo

* removing demo: accidentally committed to wrong branch

* fixing Blockly.Msg string bugs

* fixing TODOs

* package file changed by an automerge. Changing back.

* addressing sll's comments. Creating shim for utilsService functions.

* fixing comments, changing fieldview to deal with this.field.

* fixing clipboard service bug

* fixing focus bug when editing a text input.

* fixed clipboard bug and added README

* fixing workspaceview not to implement on runCode() function and adding note to README
2016-05-23 16:42:18 -07:00

222 lines
12 KiB
JavaScript

/**
* 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: `
<li #parentList [id]="idMap['parentList']" role="treeitem" class="blocklyHasChildren"
[attr.aria-labelledBy]="generateAriaLabelledByAttr('blockly-block-summary', idMap['blockSummary'])"
[attr.aria-level]="level" aria-selected=false>
{{checkParentList(parentList)}}
<label [id]="idMap['blockSummary']">{{block.toString()}}</label>
<ol role="group" [attr.aria-level]="level+1">
<li [id]="idMap['listItem']" class="blocklyHasChildren" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr('blockly-block-menu', idMap['blockSummary'])"
[attr.aria-level]="level+1" aria-selected=false>
<label [id]="idMap['label']">{{stringMap['BLOCK_ACTION_LIST']}}</label>
<ol role="group" [attr.aria-level]="level+2">
<li [id]="idMap['cutListItem']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['cutButton'], 'blockly-button')"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['cutButton']" (click)="clipboardService.cut(block)">{{stringMap['CUT_BLOCK']}}</button>
</li>
<li [id]="idMap['copyListItem']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['copyButton'], 'blockly-button')"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['copyButton']" (click)="clipboardService.copy(block, true)">{{stringMap['COPY_BLOCK']}}</button>
</li>
<li [id]="idMap['pasteBelow']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['pasteBelowButton'], 'blockly-button', (getNoNextConnectionHTMLText(block)||clipboardService.getClipboardCompatibilityHTMLText(block.nextConnection)))"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['pasteBelowButton']" (click)="clipboardService.pasteFromClipboard(block.nextConnection)"
[disabled]="getNoNextConnectionHTMLText(block)" [disabled]="clipboardService.getClipboardCompatibilityHTMLText(block.nextConnection)">{{stringMap['PASTE_BELOW']}}</button>
</li>
<li [id]="idMap['pasteAbove']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['pasteAboveButton'], 'blockly-button', (getNoPreviousConnectionHTMLText(block) || clipboardService.getClipboardCompatibilityHTMLText(block.previousConnection)))"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['pasteAboveButton']" (click)="clipboardService.pasteFromClipboard(block.previousConnection)"
[disabled]="getNoPreviousConnectionHTMLText(block)" [disabled]="clipboardService.getClipboardCompatibilityHTMLText(block.previousConnection)">{{stringMap['PASTE_ABOVE']}}</button>
</li>
<li [id]="idMap['markBelow']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['markBelowButton'], 'blockly-button', getNoNextConnectionHTMLText(block))"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['markBelowButton']" (click)="clipboardService.markConnection(block.nextConnection)"
[disabled]="getNoNextConnectionHTMLText(block)">{{stringMap['MARK_SPOT_BELOW']}}</button>
</li>
<li [id]="idMap['markAbove']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['markAboveButton'], 'blockly-button', getNoPreviousConnectionHTMLText(block))"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['markAboveButton']" (click)="clipboardService.markConnection(block.previousConnection)"
[disabled]="getNoPreviousConnectionHTMLText(block)">{{stringMap['MARK_SPOT_ABOVE']}}</button>
</li>
<li [id]="idMap['sendToSelectedListItem']" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['sendToSelectedButton'], 'blockly-button', utilsService.getMarkedBlockCompatibilityHTMLText(clipboardService.isBlockCompatibleWithMarkedConnection(block)))"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['sendToSelectedButton']" (click)="sendToSelected(block)"
[disabled]="getMarkedBlockCompatibilityHTMLText(clipboardService.isBlockCompatibleWithMarkedConnection(block))">{{stringMap['MOVE_TO_MARKED_SPOT']}}</button>
</li>
<li [attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['deleteButton'], 'blockly-button')" [id]="idMap['delete']" role="treeitem" aria-selected=false [attr.aria-level]="level+2">
<button [id]="idMap['deleteButton']" (click)="deleteBlock(block)">{{stringMap['DELETE']}}</button>
</li>
</ol>
</li>
<div *ngFor="#inputBlock of block.inputList; #i = index">
<field-view *ngFor="#field of inputBlock.fieldRow" [field]="field"></field-view>
<tree-view *ngIf="inputBlock.connection && inputBlock.connection.targetBlock()" [block]="inputBlock.connection.targetBlock()" [isTopBlock]="false" [level]="level"></tree-view>
<li #inputList [attr.aria-level]="level + 1" [id]="idMap['inputList' + i]"
[attr.aria-labelledBy]="generateAriaLabelledByAttr('blockly-menu', idMap['inputMenuLabel' + i])"
*ngIf="inputBlock.connection && !inputBlock.connection.targetBlock()" (keydown)="treeService.onKeypress($event, tree)">
<!-- TODO(madeeha): i18n here will need to happen in a different way due to the way grammar changes based on language. -->
<label [id]="idMap['inputMenuLabel' + i]"> {{utilsService.getInputTypeLabel(inputBlock.connection)}} {{utilsService.getBlockTypeLabel(inputBlock)}} needed: </label>
<ol role="group" [attr.aria-level]="level+2">
<li [id]="idMap['markSpot' + i]" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['markButton' + i], 'blockly-button')"
[attr.aria-level]="level + 2" aria-selected=false>
<button [id]="idMap['markSpotButton + i']" (click)="clipboardService.markConnection(inputBlock.connection)">{{stringMap['MARK_THIS_SPOT']}}</button>
</li>
<li [id]="idMap['paste' + i]" role="treeitem"
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['pasteButton' + i], 'blockly-button', clipboardService.getClipboardCompatibilityHTMLText(inputBlock.connection))"
[attr.aria-level]="level+2" aria-selected=false>
<button [id]="idMap['pasteButton' + i]" (click)="clipboardService.pasteFromClipboard(inputBlock.connection)"
[disabled]="clipboardService.getClipboardCompatibilityHTMLText(inputBlock.connection)">{{stringMap['PASTE']}}</button>
</li>
</ol>
</li>
</div>
</ol>
</li>
<tree-view *ngIf= "block.nextConnection && block.nextConnection.targetBlock()" [block]="block.nextConnection.targetBlock()" [isTopBlock]="false" [level]="level"></tree-view>
`,
directives: [ng.core.forwardRef(
function() { return blocklyApp.WorkspaceTreeView; }), blocklyApp.FieldView],
inputs: ['block', 'isTopBlock', 'topBlockIndex', 'level', 'parentId'],
providers: [blocklyApp.TreeService, blocklyApp.UtilsService],
})
.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;
this.stringMap = {
'BLOCK_ACTION_LIST': Blockly.Msg.BLOCK_ACTION_LIST,
'PASTE': Blockly.Msg.PASTE,
'PASTE_ABOVE': Blockly.Msg.PASTE_ABOVE,
'PASTE_BELOW': Blockly.Msg.PASTE_BELOW,
'MARK_THIS_SPOT': Blockly.Msg.MARK_THIS_SPOT,
'MARK_SPOT_ABOVE': Blockly.Msg.MARK_SPOT_ABOVE,
'MARK_SPOT_BELOW': Blockly.Msg.MARK_SPOT_BELOW,
'CUT_BLOCK': Blockly.Msg.CUT_BLOCK,
'COPY_BLOCK': Blockly.Msg.COPY_BLOCK,
'MOVE_TO_MARKED_SPOT': Blockly.Msg.MOVE_TO_MARKED_SPOT,
'DELETE': Blockly.Msg.DELETE,
};
}],
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);
}
},
setId: function(block) {
if (this.isTopBlock) {
return this.parentId + '-node0';
}
return this.treeService.createId(block);
},
sendToSelected: function(block) {
if (this.clipboardService) {
this.clipboardService.pasteToMarkedConnection(block, false);
block.dispose(true);
alert('Block moved to marked spot: ' + block.toString());
}
}
});