Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions packages/blockly/core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1393,23 +1393,29 @@ export class BlockSvg
* @internal
*/
moveSvgRootToFront(blockOnly = false) {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block: this | null = this;
if (block.isDeadOrDying()) {
if (this.isDeadOrDying()) {
return;
}
do {
const root = block.getSvgRoot();
const parent = root.parentNode;
if (!parent) return;
const childNodes = parent.childNodes;
// Avoid moving the block if it's already at the bottom.
if (childNodes[childNodes.length - 1] !== root) {
parent.appendChild(root);
}
if (blockOnly) break;
block = block.getParent();
} while (block);
requestAnimationFrame(() => {
if (this.dragging) return;
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block: this | null = this;
do {
if (block.isDeadOrDying()) return;
const root = block.getSvgRoot();
const parent = root.parentNode;
if (!parent) return;
const childNodes = parent.childNodes;
// Avoid moving the block if it's already at the bottom.
if (childNodes[childNodes.length - 1] !== root) {
while (root.nextSibling) {
parent.insertBefore(root.nextSibling, root);
}
}
if (blockOnly) break;
block = block.getParent();
} while (block);
});
}

/**
Expand Down
9 changes: 3 additions & 6 deletions packages/blockly/core/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ const content = `

.blocklyHighlightedConnectionPath {
fill: none;
}

.blocklyHighlightedConnectionPathVisible {
stroke: #fc3;
stroke-width: 4px;
}
Expand Down Expand Up @@ -604,12 +607,6 @@ input[type=number] {
stroke-width: var(--blockly-selection-width);
}

/* Workaround for unexpectedly hidden connection path due to core style. */
.blocklyKeyboardNavigation
.blocklyPassiveFocus.blocklyHighlightedConnectionPath {
display: unset !important;
}

/* Different ways for toolbox/flyout to be the active tree: */
/* Active focus in the flyout. */
.blocklyKeyboardNavigation .blocklyFlyout:has(.blocklyActiveFocus),
Expand Down
26 changes: 21 additions & 5 deletions packages/blockly/core/rendered_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as internalConstants from './internal_constants.js';
import {Msg} from './msg.js';
import * as aria from './utils/aria.js';
import {Coordinate} from './utils/coordinate.js';
import * as dom from './utils/dom.js';
import * as svgMath from './utils/svg_math.js';
import {WorkspaceSvg} from './workspace_svg.js';

Expand Down Expand Up @@ -322,11 +323,11 @@ export class RenderedConnection
}

/**
* Sets the aria role, label, and other state for this connection.
* Sets the aria role and role description for this connection.
*
* @param highlightSvg The focusable element for this connection.
*/
private recomputeAriaContext(highlightSvg: SVGElement) {
setAriaRole(highlightSvg: SVGElement) {
// Note that output connections don't have highlights so this doesn't need to take them into account.
const roleDescription =
this.type === ConnectionType.INPUT_VALUE
Expand All @@ -335,6 +336,15 @@ export class RenderedConnection

aria.setRole(highlightSvg, aria.Role.FIGURE);
aria.setState(highlightSvg, aria.State.ROLEDESCRIPTION, roleDescription);
}

/**
* Sets the aria role, label, and other state for this connection.
*
* @param highlightSvg The focusable element for this connection.
*/
private recomputeAriaContext(highlightSvg: SVGElement) {
this.setAriaRole(highlightSvg);

// 'Next' connections are only focusable if they're the last connection
// inside a statement input. The label for these connections comes from
Expand Down Expand Up @@ -385,8 +395,14 @@ export class RenderedConnection
// draw pass).
const highlightSvg = this.findHighlightSvg();
if (highlightSvg) {
highlightSvg.style.display = '';
highlightSvg.parentElement?.appendChild(highlightSvg);
dom.addClass(highlightSvg, 'blocklyHighlightedConnectionPathVisible');
requestAnimationFrame(() => {
const parent = highlightSvg.parentElement;
if (!parent) return;
while (highlightSvg.nextSibling) {
parent.insertBefore(highlightSvg.nextSibling, highlightSvg);
}
});
this.recomputeAriaContext(highlightSvg);
}
}
Expand All @@ -398,7 +414,7 @@ export class RenderedConnection
// Note that this is done synchronously for parity with highlight().
const highlightSvg = this.findHighlightSvg();
if (highlightSvg) {
highlightSvg.style.display = 'none';
dom.removeClass(highlightSvg, 'blocklyHighlightedConnectionPathVisible');
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/blockly/core/renderers/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ export class ConstantProvider {
`}`,

// Connection highlight.
`${selector} .blocklyHighlightedConnectionPath {`,
`${selector} .blocklyHighlightedConnectionPathVisible {`,
`stroke: #fc3;`,
`}`,

Expand Down
6 changes: 5 additions & 1 deletion packages/blockly/core/renderers/common/drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,11 @@ export class Drawer {

const highlightSvg = this.drawConnectionHighlightPath(elem);
if (highlightSvg) {
highlightSvg.style.display = elem.highlighted ? '' : 'none';
elem.connectionModel.setAriaRole(highlightSvg);
highlightSvg.classList.toggle(
'blocklyHighlightedConnectionPathVisible',
elem.highlighted,
);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/blockly/core/renderers/common/path_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ export class PathObject implements IPathObject {
{
'id': connection.id,
'class': 'blocklyHighlightedConnectionPath',
'style': 'display: none;',
'd': connectionPath,
'transform': transformation,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/blockly/core/renderers/zelos/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ export class ConstantProvider extends BaseConstantProvider {
`}`,

// Connection highlight.
`${selector} .blocklyHighlightedConnectionPath {`,
`${selector} .blocklyHighlightedConnectionPathVisible {`,
`stroke: ${this.SELECTED_GLOW_COLOUR};`,
`}`,

Expand Down
Loading