Skip to main content

Class: CrossTabCopyPaste

Defined in: index.ts:93

A Blockly plugin that adds context menu items and keyboard shortcuts to allow users to copy and paste copyable objects between tabs.

Properties index​

PropertyDescription
localStorageKeyKey in which store copy data in the browser's local storage.

Methods index​

MethodDescription
blockCopyToStorageContextMenuAdds a copy command to the context menu for copyable items.
blockCopyToStorageShortcutAdds a keyboard shortcut that will store copy information for a copyable in localStorage.
blockCutToStorageShortcutAdds a keyboard shortcut that will store copy information for copyable items in local storage and delete the item.
blockPasteFromStorageContextMenuAdds a paste command to the context menu for copyable items.
blockPasteFromStorageShortcutAdds a keyboard shortcut that will paste the copyable stored in localStorage.
copyCallbackCopy callback called by both keyboard shortcut and context menu item. Copies the copy data to local storage.
copyPreconditionCopy 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.
getContextMenuTextv12.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.
getCopyDataParses copy data from JSON in local storage, if it exists.
initInitializes the cross tab copy paste plugin. If no options are selected then both context menu items and keyboard shortcuts are added.
pastePreconditionPaste precondition called by both keyboard shortcut and context menu item.

Constructors​

Constructor​

new CrossTabCopyPaste(): CrossTabCopyPaste;

Returns​

CrossTabCopyPaste

Properties​

localStorageKey​

localStorageKey: string = 'blocklyStash';

Defined in: index.ts:95

Key in which store copy data in the browser's local storage.

Methods​

blockCopyToStorageContextMenu()​

blockCopyToStorageContextMenu(): void;

Defined in: index.ts:265

Adds a copy command to the context menu for copyable items.

Returns​

void


blockCopyToStorageShortcut()​

blockCopyToStorageShortcut(): void;

Defined in: index.ts:344

Adds a keyboard shortcut that will store copy information for a copyable in localStorage.

Returns​

void


blockCutToStorageShortcut()​

blockCutToStorageShortcut(): void;

Defined in: index.ts:375

Adds a keyboard shortcut that will store copy information for copyable items in local storage and delete the item.

Returns​

void


blockPasteFromStorageContextMenu()​

blockPasteFromStorageContextMenu(typeErrorCallback?): void;

Defined in: index.ts:295

Adds a paste command to the context menu for copyable items.

Parameters​

ParameterTypeDescription
typeErrorCallback?TypeErrorCallbackcallback function to handle type errors

Returns​

void


blockPasteFromStorageShortcut()​

blockPasteFromStorageShortcut(typeErrorCallback?): void;

Defined in: index.ts:435

Adds a keyboard shortcut that will paste the copyable stored in localStorage.

Parameters​

ParameterTypeDescription
typeErrorCallback?TypeErrorCallbackcallback function to handle type errors

Returns​

void


copyCallback()​

copyCallback(scope, workspace): boolean;

Defined in: index.ts:195

Copy callback called by both keyboard shortcut and context menu item. Copies the copy data to local storage.

Parameters​

ParameterTypeDescription
scopeScopescope for copy action.
workspaceWorkspaceworkspace where shortcut or context menu was activated.

Returns​

boolean

true if copy happened, false otherwise.


copyPrecondition()​

copyPrecondition(scope, workspace?): ContextMenuState;

Defined in: index.ts:162

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.

Parameters​

ParameterTypeDescription
scopeScopescope for copy action.
workspace?Workspaceexplicit workspace for keyboard shortcuts, undefined to get the workspace from the focused node.

Returns​

ContextMenuState

whether the option should be shown/hidden/disabled.


getContextMenuText()​

getContextMenuText(labelText): string;

Defined in: index.ts:253

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.

Parameters​

ParameterTypeDescription
labelTextstringBlockly.Msg for the shortcut

Returns​

string

trimmed label for the context menu item.


getCopyData()​

getCopyData(): ICopyData | undefined;

Defined in: index.ts:146

Parses copy data from JSON in local storage, if it exists.

Returns​

ICopyData | undefined

copy data parsed from local storage, or undefined


init()​

init(
options?,
typeErrorCallback?,
localStorageKey?
): void;

Defined in: index.ts:108

Initializes the cross tab copy paste plugin. If no options are selected then both context menu items and keyboard shortcuts are added.

Parameters​

ParameterTypeDescription
options?{ contextMenu?: true; shortcut?: true; }-
options.contextMenu?trueRegister copy and paste in the context menu.
options.shortcut?trueRegister cut (ctr + x), copy (ctr + c) and paste (ctr + v) in the shortcut.
typeErrorCallback?TypeErrorCallbackcallback function to handle type errors
localStorageKey?stringcustom key for local storage

Returns​

void


pastePrecondition()​

pastePrecondition(workspace): ContextMenuState;

Defined in: index.ts:225

Paste precondition called by both keyboard shortcut and context menu item.

Parameters​

ParameterTypeDescription
workspaceWorkspaceSvgworkspace to paste in. should not be a flyout workspace.

Returns​

ContextMenuState

true if paste happened, false otherwise.