mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
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:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user