mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
* feat: Add interfaces for keyboard navigation. * feat: Add the Navigator. * feat: Make core types conform to INavigable. * feat: Require FlyoutItems elements to be INavigable. * feat: Add navigation policies for built-in types. * refactor: Convert Marker and LineCursor to operate on INavigables instead of ASTNodes. * chore: Delete dead code in ASTNode. * fix: Fix the tests. * chore: Assuage the linter. * fix: Fix advanced build/tests. * chore: Restore ASTNode tests. * refactor: Move isNavigable() validation into Navigator. * refactor: Exercise navigation instead of ASTNode. * chore: Rename astnode_test.js to navigation_test.js. * chore: Enable the navigation tests. * fix: Fix bug when retrieving the first child of an empty workspace.
87 lines
1.9 KiB
TypeScript
87 lines
1.9 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2024 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import type {IBoundedElement} from './interfaces/i_bounded_element.js';
|
|
import type {INavigable} from './interfaces/i_navigable.js';
|
|
import {Rect} from './utils/rect.js';
|
|
|
|
/**
|
|
* Representation of a gap between elements in a flyout.
|
|
*/
|
|
export class FlyoutSeparator
|
|
implements IBoundedElement, INavigable<FlyoutSeparator>
|
|
{
|
|
private x = 0;
|
|
private y = 0;
|
|
|
|
/**
|
|
* Creates a new separator.
|
|
*
|
|
* @param gap The amount of space this separator should occupy.
|
|
* @param axis The axis along which this separator occupies space.
|
|
*/
|
|
constructor(
|
|
private gap: number,
|
|
private axis: SeparatorAxis,
|
|
) {}
|
|
|
|
/**
|
|
* Returns the bounding box of this separator.
|
|
*
|
|
* @returns The bounding box of this separator.
|
|
*/
|
|
getBoundingRectangle(): Rect {
|
|
switch (this.axis) {
|
|
case SeparatorAxis.X:
|
|
return new Rect(this.y, this.y, this.x, this.x + this.gap);
|
|
case SeparatorAxis.Y:
|
|
return new Rect(this.y, this.y + this.gap, this.x, this.x);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Repositions this separator.
|
|
*
|
|
* @param dx The distance to move this separator on the X axis.
|
|
* @param dy The distance to move this separator on the Y axis.
|
|
* @param _reason The reason this move was initiated.
|
|
*/
|
|
moveBy(dx: number, dy: number, _reason?: string[]) {
|
|
this.x += dx;
|
|
this.y += dy;
|
|
}
|
|
|
|
/**
|
|
* Returns false to prevent this separator from being navigated to by the
|
|
* keyboard.
|
|
*
|
|
* @returns False.
|
|
*/
|
|
isNavigable() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Returns this separator's class.
|
|
*
|
|
* Used by keyboard navigation to look up the rules for navigating from this
|
|
* separator.
|
|
*
|
|
* @returns This separator's class.
|
|
*/
|
|
getClass() {
|
|
return FlyoutSeparator;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Representation of an axis along which a separator occupies space.
|
|
*/
|
|
export const enum SeparatorAxis {
|
|
X = 'x',
|
|
Y = 'y',
|
|
}
|