@blockly/plugin-cross-tab-copy-paste
Version:
Allows copying blocks between multiple tabs with Blockly editors.
109 lines • 4.24 kB
TypeScript
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as Blockly from 'blockly/core';
type TypeErrorCallback = () => void;
/**
* Return value for a context menu item's precondition.
*/
declare enum ContextMenuState {
ENABLED = "enabled",
DISABLED = "disabled",
HIDDEN = "hidden"
}
/**
* A Blockly plugin that adds context menu items and keyboard shortcuts
* to allow users to copy and paste copyable objects between tabs.
*/
export declare class CrossTabCopyPaste {
/** Key in which store copy data in the browser's local storage. */
localStorageKey: string;
/**
* Initializes the cross tab copy paste plugin. If no options are selected
* then both context menu items and keyboard shortcuts are added.
*
* @param options
* @param options.shortcut Register cut (ctr + x), copy (ctr + c) and paste (ctr + v)
* in the shortcut.
* @param options.contextMenu Register copy and paste in the context menu.
* @param typeErrorCallback callback function to handle type errors
* @param localStorageKey custom key for local storage
*/
init({ contextMenu, shortcut }?: {
contextMenu?: true;
shortcut?: true;
}, typeErrorCallback?: TypeErrorCallback, localStorageKey?: string): void;
/**
* Parses copy data from JSON in local storage, if it exists.
*
* @returns copy data parsed from local storage, or undefined
*/
getCopyData(): Blockly.ICopyData | undefined;
/**
* Copy precondition called by both keyboard shortcut and context menu item.
* Allows copying out of the flyout, as long as they could be pasted
* into the main workspace.
*
* @param scope scope for copy action.
* @param workspace explicit workspace for keyboard shortcuts,
* undefined to get the workspace from the focused node.
* @returns whether the option should be shown/hidden/disabled.
*/
copyPrecondition(scope: Blockly.ContextMenuRegistry.Scope, workspace?: Blockly.Workspace): ContextMenuState;
/**
* Copy callback called by both keyboard shortcut and context menu item.
* Copies the copy data to local storage.
*
* @param scope scope for copy action.
* @param workspace workspace where shortcut or context menu was activated.
* @returns true if copy happened, false otherwise.
*/
copyCallback(scope: Blockly.ContextMenuRegistry.Scope, workspace: Blockly.Workspace): boolean;
/**
* Paste precondition called by both keyboard shortcut and context menu item.
*
* @param workspace workspace to paste in. should not be a flyout workspace.
* @returns true if paste happened, false otherwise.
*/
pastePrecondition(workspace: Blockly.WorkspaceSvg): ContextMenuState;
/**
* v12.0.0 of Blockly included the keyboard shortcut in Msg string, but
* it was removed in v12.2.0. This function can be removed when this plugin's
* minimum version of Blockly is >=12.2.0.
*
* @param labelText Blockly.Msg for the shortcut
* @returns trimmed label for the context menu item.
*/
getContextMenuText(labelText: string): string;
/**
* Adds a copy command to the context menu for copyable items.
*/
blockCopyToStorageContextMenu(): void;
/**
* Adds a paste command to the context menu for copyable items.
*
* @param typeErrorCallback callback function to handle type errors
*/
blockPasteFromStorageContextMenu(typeErrorCallback?: TypeErrorCallback): void;
/**
* Adds a keyboard shortcut that will store copy information for a copyable
* in localStorage.
*/
blockCopyToStorageShortcut(): void;
/**
* Adds a keyboard shortcut that will store copy information for copyable
* items in local storage and delete the item.
*/
blockCutToStorageShortcut(): void;
/**
* Adds a keyboard shortcut that will paste the copyable stored in localStorage.
*
* @param typeErrorCallback
* callback function to handle type errors
*/
blockPasteFromStorageShortcut(typeErrorCallback?: TypeErrorCallback): void;
}
export {};
//# sourceMappingURL=index.d.ts.map