chore: fix paster exports and registration (#7343)

This commit is contained in:
Beka Westberg
2023-07-31 10:46:49 -07:00
committed by GitHub
parent 68a8a5ff19
commit 74c01d2794
6 changed files with 54 additions and 2 deletions

View File

@@ -152,6 +152,7 @@ import {IKeyboardAccessible} from './interfaces/i_keyboard_accessible.js';
import {IMetricsManager} from './interfaces/i_metrics_manager.js';
import {IMovable} from './interfaces/i_movable.js';
import {IObservable, isObservable} from './interfaces/i_observable.js';
import {IPaster, isPaster} from './interfaces/i_paster.js';
import {IPositionable} from './interfaces/i_positionable.js';
import {IRegistrable} from './interfaces/i_registrable.js';
import {ISelectable} from './interfaces/i_selectable.js';
@@ -606,6 +607,7 @@ export {Input};
export {inputs};
export {InsertionMarkerManager};
export {IObservable, isObservable};
export {IPaster, isPaster};
export {IPositionable};
export {IRegistrable};
export {ISelectable};

View File

@@ -8,6 +8,8 @@ import * as goog from '../closure/goog/goog.js';
goog.declareModuleId('Blockly.clipboard');
import type {CopyData, ICopyable} from './interfaces/i_copyable.js';
import {BlockPaster} from './clipboard/block_paster.js';
import * as registry from './clipboard/registry.js';
/** Metadata about the object that is currently on the clipboard. */
let copyData: CopyData | null = null;
@@ -82,3 +84,5 @@ export const TEST_ONLY = {
duplicateInternal,
copyInternal,
};
export {BlockPaster, registry};

View File

@@ -5,13 +5,16 @@
*/
import {BlockSvg} from '../block_svg.js';
import {CopyData} from '../interfaces/i_copyable';
import {registry} from '../clipboard.js';
import {CopyData} from '../interfaces/i_copyable.js';
import {IPaster} from '../interfaces/i_paster.js';
import {State, append} from '../serialization/blocks';
import {State, append} from '../serialization/blocks.js';
import {Coordinate} from '../utils/coordinate.js';
import {WorkspaceSvg} from '../workspace_svg.js';
export class BlockPaster implements IPaster<BlockCopyData, BlockSvg> {
static TYPE = 'block';
paste(
copyData: BlockCopyData,
workspace: WorkspaceSvg,
@@ -29,3 +32,5 @@ export class BlockPaster implements IPaster<BlockCopyData, BlockSvg> {
}
export interface BlockCopyData extends CopyData {}
registry.register(BlockPaster.TYPE, new BlockPaster());

View File

@@ -0,0 +1,31 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {ICopyable, CopyData} from '../interfaces/i_copyable.js';
import type {IPaster} from '../interfaces/i_paster.js';
import * as registry from '../registry.js';
/**
* Registers the given paster so that it cna be used for pasting.
*
* @param type The type of the paster to register, e.g. 'block', 'comment', etc.
* @param paster The paster to register.
*/
export function register<U extends CopyData, T extends ICopyable>(
type: string,
paster: IPaster<U, T>,
) {
registry.register(registry.Type.PASTER, type, paster);
}
/**
* Unregisters the paster associated with the given type.
*
* @param type The type of the paster to unregister.
*/
export function unregister(type: string) {
registry.unregister(registry.Type.PASTER, type);
}

View File

@@ -9,10 +9,13 @@ 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';
import {registry} from '../clipboard.js';
export class WorkspaceCommentPaster
implements IPaster<WorkspaceCommentCopyData, WorkspaceCommentSvg>
{
static TYPE = 'workspace-comment';
paste(
copyData: WorkspaceCommentCopyData,
workspace: WorkspaceSvg,
@@ -28,3 +31,5 @@ export class WorkspaceCommentPaster
}
export interface WorkspaceCommentCopyData extends CopyData {}
registry.register(WorkspaceCommentPaster.TYPE, new WorkspaceCommentPaster());

View File

@@ -22,6 +22,8 @@ import type {Options} from './options.js';
import type {Renderer} from './renderers/common/renderer.js';
import type {Theme} from './theme.js';
import type {ToolboxItem} from './toolbox/toolbox_item.js';
import {IPaster} from './interfaces/i_paster.js';
import {CopyData, ICopyable} from './interfaces/i_copyable.js';
/**
* A map of maps. With the keys being the type and name of the class we are
@@ -96,6 +98,9 @@ export class Type<_T> {
/** @internal */
static ICON = new Type<IIcon>('icon');
/** @internal */
static PASTER = new Type<IPaster<CopyData, ICopyable>>('paster');
}
/**