feat: connection highlighter interface (#7638)

* feat: add connection highlighter interface

* fix: remove unnecessary method from the path object interface
This commit is contained in:
Beka Westberg
2023-11-17 15:55:42 +00:00
parent dc9aa1befb
commit 2c95c4202c
3 changed files with 28 additions and 21 deletions

View File

@@ -1722,7 +1722,8 @@ export class BlockSvg
* @internal
*/
fadeForReplacement(add: boolean) {
this.pathObject.updateReplacementFade(add);
// TODO (7204): Remove these internal methods.
(this.pathObject as AnyDuringMigration).updateReplacementFade(add);
}
/**
@@ -1734,6 +1735,10 @@ export class BlockSvg
* @internal
*/
highlightShapeForInput(conn: RenderedConnection, add: boolean) {
this.pathObject.updateShapeForInputHighlight(conn, add);
// TODO (7204): Remove these internal methods.
(this.pathObject as AnyDuringMigration).updateShapeForInputHighlight(
conn,
add,
);
}
}

View File

@@ -0,0 +1,21 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type {RenderedConnection} from '../rendered_connection';
/**
* Visually highlights connections, usually to preview where a block will be
* connected if it is dropped.
*
* Often implemented by IPathObject classes.
*/
export interface IConnectionHighlighter {
/** Visually highlights the given connection. */
highlightConnection(conn: RenderedConnection): void;
/** Visually unhighlights the given connnection (if it was highlighted). */
unhighlightConnection(conn: RenderedConnection): void;
}

View File

@@ -9,7 +9,6 @@
import type {BlockStyle} from '../../theme.js';
import type {BlockSvg} from '../../block_svg.js';
import type {ConstantProvider} from './constants.js';
import {RenderedConnection} from '../../rendered_connection.js';
/**
* An interface for a block's path object.
@@ -120,22 +119,4 @@ export interface IPathObject {
* @param enable True if the block is movable, false otherwise.
*/
updateMovable(enabled: boolean): void;
/**
* Add or remove styling that shows that if the dragging block is dropped,
* this block will be replaced. If a shadow block, it will disappear.
* Otherwise it will bump.
*
* @param enable True if styling should be added.
*/
updateReplacementFade(enabled: boolean): void;
/**
* Add or remove styling that shows that if the dragging block is dropped,
* this block will be connected to the input.
*
* @param conn The connection on the input to highlight.
* @param enable True if styling should be added.
*/
updateShapeForInputHighlight(conn: RenderedConnection, enable: boolean): void;
}