From d58a878fad99b4eedc4db2f09d6ee1820cb0c110 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 29 Jul 2021 12:43:49 -0700 Subject: [PATCH] Switch to getter for keyboard contents. --- core/blockly.js | 34 +++++++++------------------------- core/clipboard.js | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 808c035b0..ab82638fe 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -93,25 +93,12 @@ Blockly.selected = null; Blockly.draggingConnections = []; /** - * Contents of the local clipboard. - * @type {Element} - * @private + * Get the current contents of the clipboard and associated metadata. + * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object + * containing the clipboard contents and associated metadata. + * @public */ -Blockly.clipboardXml_ = Blockly.clipboard.xml; - -/** - * Source of the local clipboard. - * @type {Blockly.WorkspaceSvg} - * @private - */ -Blockly.clipboardSource_ = Blockly.clipboard.source; - -/** - * Map of types to type counts for the clipboard object and descendants. - * @type {Object} - * @private - */ -Blockly.clipboardTypeCounts_ = Blockly.clipboard.typeCounts; +Blockly.getClipboardInfo = Blockly.common.getClipboardInfo; /** * Cached value for whether 3D is supported. @@ -137,9 +124,7 @@ Blockly.svgSize = function(svg) { // When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_ // from setCachedParentSvgSize. Blockly.utils.deprecation.warn( - 'Blockly.svgSize', - 'March 2021', - 'March 2022', + 'Blockly.svgSize', 'March 2021', 'March 2022', 'workspace.getCachedParentSvgSize'); svg = /** @type {?} */ (svg); return new Blockly.utils.Size(svg.cachedWidth_, svg.cachedHeight_); @@ -221,7 +206,8 @@ Blockly.deleteBlock = function(selected) { Blockly.Events.setGroup(true); Blockly.hideChaff(); if (selected.outputConnection) { - // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) + // Do not attempt to heal rows + // (https://github.com/google/blockly/issues/4832) selected.dispose(false, true); } else { selected.dispose(/* heal */ true, true); @@ -366,9 +352,7 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) { 'Block definition #' + i + ' in JSON array' + ' overwrites prior definition of "' + typename + '".'); } - Blockly.Blocks[typename] = { - init: Blockly.jsonInitFactory_(elem) - }; + Blockly.Blocks[typename] = {init: Blockly.jsonInitFactory_(elem)}; } } } diff --git a/core/clipboard.js b/core/clipboard.js index 887346a58..b93f92530 100644 --- a/core/clipboard.js +++ b/core/clipboard.js @@ -26,7 +26,6 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * @private */ let xml = null; -exports.xml = xml; /** * Source of the local clipboard. @@ -34,7 +33,6 @@ exports.xml = xml; * @private */ let source = null; -exports.source = source; /** * Map of types to type counts for the clipboard object and descendants. @@ -42,12 +40,20 @@ exports.source = source; * @private */ let typeCounts = null; -exports.typeCounts = typeCounts; + +/** + * Get the current contents of the clipboard and associated metadata. + * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object + * containing the clipboard contents and associated metadata. + */ +const getClipboardInfo = function() { + return {xml: xml, source: source, typeCounts: typeCounts}; +}; +exports.getClipboardInfo = getClipboardInfo; /** * Copy a block or workspace comment onto the local clipboard. * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. - * @package */ const copy = function(toCopy) { var data = toCopy.toCopyData(); @@ -57,12 +63,12 @@ const copy = function(toCopy) { typeCounts = data.typeCounts; } }; +/** @package */ exports.copy = copy; /** * Paste a block or workspace comment on to the main workspace. * @return {boolean} True if the paste was successful, false otherwise. - * @package */ const paste = function() { if (!xml) { @@ -82,13 +88,13 @@ const paste = function() { } return false; }; +/** @package */ exports.paste = paste; /** * Duplicate this block and its children, or a workspace comment. * @param {!ICopyable} toDuplicate Block or Workspace Comment to be - * copied. - * @package + * duplicated. */ const duplicate = function(toDuplicate) { // Save the clipboard. @@ -103,4 +109,5 @@ const duplicate = function(toDuplicate) { xml = oldXml; source = oldSource; }; +/** @package */ exports.duplicate = duplicate;