diff --git a/core/clipboard/block_paster.ts b/core/clipboard/block_paster.ts new file mode 100644 index 00000000000..363f70cad83 --- /dev/null +++ b/core/clipboard/block_paster.ts @@ -0,0 +1,31 @@ +/** + * @license + * Copyright 2023 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import {BlockSvg} from '../block_svg.js'; +import {CopyData} from '../interfaces/i_copyable'; +import {IPaster} from '../interfaces/i_paster.js'; +import {State, append} from '../serialization/blocks'; +import {Coordinate} from '../utils/coordinate.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; + +export class BlockPaster implements IPaster { + paste( + copyData: BlockCopyData, + workspace: WorkspaceSvg, + coordinate?: Coordinate, + ): BlockSvg | null { + if (!workspace.isCapacityAvailable(copyData.typeCounts!)) return null; + + const state = copyData.saveInfo as State; + if (coordinate) { + state['x'] = coordinate.x; + state['y'] = coordinate.y; + } + return append(state, workspace, {recordUndo: true}) as BlockSvg; + } +} + +export interface BlockCopyData extends CopyData {} diff --git a/core/clipboard/workspace_comment_paster.ts b/core/clipboard/workspace_comment_paster.ts new file mode 100644 index 00000000000..11211564ce7 --- /dev/null +++ b/core/clipboard/workspace_comment_paster.ts @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2023 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import {IPaster} from '../interfaces/i_paster.js'; +import {CopyData} from '../interfaces/i_copyable.js'; +import {Coordinate} from '../utils/coordinate.js'; +import {WorkspaceSvg} from '../workspace_svg.js'; +import {WorkspaceCommentSvg} from '../workspace_comment_svg.js'; + +export class WorkspaceCommentPaster + implements IPaster +{ + paste( + copyData: WorkspaceCommentCopyData, + workspace: WorkspaceSvg, + coordinate?: Coordinate, + ): WorkspaceCommentSvg { + const state = copyData.saveInfo as Element; + if (coordinate) { + state.setAttribute('x', `${coordinate.x}`); + state.setAttribute('y', `${coordinate.y}`); + } + return WorkspaceCommentSvg.fromXmlRendered(state, workspace); + } +} + +export interface WorkspaceCommentCopyData extends CopyData {}