refactor: split out block serialization for creating new blocks from the flyout (#8065)

* refactor: split out block serialization for creating new blocks from the flyout

* fix: add JSDoc.

* chore: satisfy the linter.
This commit is contained in:
Aaron Dodson
2024-05-03 12:27:55 -07:00
committed by GitHub
parent 4861c7d98a
commit 08183863e7

View File

@@ -1301,8 +1301,8 @@ export abstract class Flyout
}
// Clone the block.
const json = blocks.save(oldBlock) as blocks.State;
// Normallly this resizes leading to weird jumps. Save it for terminateDrag.
const json = this.serializeBlock(oldBlock);
// Normally this resizes leading to weird jumps. Save it for terminateDrag.
targetWorkspace.setResizesEnabled(false);
const block = blocks.append(json, targetWorkspace) as BlockSvg;
@@ -1311,6 +1311,16 @@ export abstract class Flyout
return block;
}
/**
* Serialize a block to JSON.
*
* @param block The block to serialize.
* @returns A serialized representation of the block.
*/
protected serializeBlock(block: BlockSvg): blocks.State {
return blocks.save(block) as blocks.State;
}
/**
* Positions a block on the target workspace.
*