Skip to content

Commit

Permalink
feat: add pasters for blocks and workspace comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Jul 27, 2023
1 parent bd2332d commit 2ed4271
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions core/clipboard/block_paster.ts
Original file line number Diff line number Diff line change
@@ -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<BlockCopyData, BlockSvg> {
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 {}
30 changes: 30 additions & 0 deletions core/clipboard/workspace_comment_paster.ts
Original file line number Diff line number Diff line change
@@ -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<WorkspaceCommentCopyData, WorkspaceCommentSvg>
{
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 {}

0 comments on commit 2ed4271

Please sign in to comment.