mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
feat: Include parent category in verbose block descriptions (#9522)
* feat: Include parent category in verbose block descriptions * fix: Loosen typechecking to break import cycle * chore: Make the linter happy
This commit is contained in:
@@ -56,6 +56,7 @@ import {RenderedConnection} from './rendered_connection.js';
|
||||
import type {IPathObject} from './renderers/common/i_path_object.js';
|
||||
import * as blocks from './serialization/blocks.js';
|
||||
import type {BlockStyle} from './theme.js';
|
||||
import type {ToolboxCategory} from './toolbox/category.js';
|
||||
import * as Tooltip from './tooltip.js';
|
||||
import {idGenerator} from './utils.js';
|
||||
import * as aria from './utils/aria.js';
|
||||
@@ -2157,6 +2158,51 @@ function buildBlockSummary(block: BlockSvg, verbose: boolean): BlockSummary {
|
||||
}
|
||||
flushLabels();
|
||||
|
||||
if (verbose) {
|
||||
const toolbox = block.workspace.getToolbox();
|
||||
let parentCategory: ToolboxCategory | undefined = undefined;
|
||||
let colourMatchingCategory: ToolboxCategory | undefined = undefined;
|
||||
if (
|
||||
toolbox &&
|
||||
'getToolboxItems' in toolbox &&
|
||||
typeof toolbox.getToolboxItems === 'function'
|
||||
) {
|
||||
for (const category of toolbox.getToolboxItems()) {
|
||||
if (
|
||||
!(
|
||||
'getColour' in category &&
|
||||
typeof category.getColour === 'function' &&
|
||||
'getContents' in category &&
|
||||
typeof category.getContents === 'function'
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (category.getColour() === block.getColour()) {
|
||||
colourMatchingCategory = category;
|
||||
}
|
||||
const contents = category.getContents();
|
||||
if (!Array.isArray(contents)) break;
|
||||
for (const item of contents) {
|
||||
if (
|
||||
item.kind.toLowerCase() === 'block' &&
|
||||
'type' in item &&
|
||||
item.type === block.type
|
||||
) {
|
||||
parentCategory = category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (parentCategory) break;
|
||||
}
|
||||
}
|
||||
if (parentCategory || colourMatchingCategory) {
|
||||
spokenParts.push(
|
||||
`${(parentCategory ?? colourMatchingCategory)?.getName()} category`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// comma-separate label runs and inputs
|
||||
const commaSeparatedSummary = spokenParts.join(', ');
|
||||
|
||||
|
||||
@@ -381,6 +381,15 @@ export class ToolboxCategory
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the colour of this category.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
getColour() {
|
||||
return this.colour_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTML element that is clickable.
|
||||
* The parent toolbox element receives clicks. The parent toolbox will add an
|
||||
|
||||
Reference in New Issue
Block a user