fix!: refactor mutator icon (#7115)

* feat: add basic mutator icon

* feat: add actual mutation behavior to icon

* chore: add bumping blocks back into the bubble

* fix: add updating block styles

* feat: add static methods to mutator icon

* chore: delete old mutator code

* fix: use the new mutator icon

* chore: docs and format

* chore: my own comments

* chore: first pass at PR comments

* chore: make type strings internal

* chore: add todo

* chore: format

* chore: move properties to module level

* chore: fix using in demos

* chore: move Mutator to icons.MutatorIcon

* chore: move reconnect to connection

* chore: move findParentWs to workspace

* chore: properly override and call super

* chore: remove bubbleIsVisible check

* chore: change imports to import type

* chore: use elvis operator

* chore: update renamings

* chore: reduce changes to js block files
This commit is contained in:
Beka Westberg
2023-06-02 12:18:41 -07:00
committed by GitHub
parent 50d9474db5
commit 2f74ce822f
23 changed files with 629 additions and 723 deletions

View File

@@ -333,6 +333,36 @@ export class Connection implements IASTNodeLocationWithBlock {
this.createShadowBlock(true);
}
/**
* Reconnects this connection to the input with the given name on the given
* block. If there is already a connection connected to that input, that
* connection is disconnected.
*
* @param block The block to connect this connection to.
* @param inputName The name of the input to connect this connection to.
* @returns True if this connection was able to connect, false otherwise.
*/
reconnect(block: Block, inputName: string): boolean {
// No need to reconnect if this connection's block is deleted.
if (this.getSourceBlock().isDeadOrDying()) return false;
const connectionParent = block.getInput(inputName)?.connection;
const currentParent = this.targetBlock();
if (
(!currentParent || currentParent === block) &&
connectionParent &&
connectionParent.targetConnection !== this
) {
if (connectionParent.isConnected()) {
// There's already something connected here. Get rid of it.
connectionParent.disconnect();
}
connectionParent.connect(this);
return true;
}
return false;
}
/**
* Returns the block that this connection connects to.
*