Skip to content

Commit

Permalink
chore: move functions in response to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-fenichel committed Nov 17, 2021
1 parent 9e04be7 commit beb7061
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 62 deletions.
18 changes: 9 additions & 9 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const geras = goog.require('Blockly.geras');
const internalConstants = goog.require('Blockly.internalConstants');
const minimalist = goog.require('Blockly.minimalist');
const registry = goog.require('Blockly.registry');
const svgMath = goog.require('Blockly.utils.svgMath');
const thrasos = goog.require('Blockly.thrasos');
const toolbox = goog.require('Blockly.utils.toolbox');
const uiPosition = goog.require('Blockly.uiPosition');
Expand Down Expand Up @@ -152,7 +153,7 @@ const {WorkspaceCommentSvg} = goog.require('Blockly.WorkspaceCommentSvg');
const {WorkspaceComment} = goog.require('Blockly.WorkspaceComment');
const {WorkspaceDragSurfaceSvg} = goog.require('Blockly.WorkspaceDragSurfaceSvg');
const {WorkspaceDragger} = goog.require('Blockly.WorkspaceDragger');
const {WorkspaceSvg} = goog.require('Blockly.WorkspaceSvg');
const {WorkspaceSvg, resizeSvgContents} = goog.require('Blockly.WorkspaceSvg');
const {Workspace} = goog.require('Blockly.Workspace');
const {ZoomControls} = goog.require('Blockly.ZoomControls');
const {globalThis} = goog.require('Blockly.utils.global');
Expand Down Expand Up @@ -305,7 +306,7 @@ Object.defineProperties(exports, {
* @deprecated Use workspace.setCachedParentSvgSize. (2021 March 5)
* @alias Blockly.svgSize
*/
exports.svgSize = common.svgSize;
exports.svgSize = svgMath.svgSize;

/**
* Size the workspace when the contents change. This also updates
Expand All @@ -314,13 +315,13 @@ exports.svgSize = common.svgSize;
* @deprecated
* @alias Blockly.resizeSvgContents
*/
const resizeSvgContents = function(workspace) {
const resizeSvgContentsLocal = function(workspace) {
deprecation.warn(
'Blockly.resizeSvgContents', 'December 2021', 'December 2022',
'Blockly.common.resizeSvgContents');
common.resizeSvgContents(workspace);
'Blockly.WorkspaceSvg.resizeSvgContents');
resizeSvgContents(workspace);
};
exports.resizeSvgContents = resizeSvgContents;
exports.resizeSvgContents = resizeSvgContentsLocal;

/**
* Copy a block or workspace comment onto the local clipboard.
Expand Down Expand Up @@ -354,10 +355,9 @@ exports.duplicate = clipboard.duplicate;
* @alias Blockly.hideChaff
*/
const hideChaff = function(opt_onlyClosePopups) {
deprecation.warn(
'Blockly.hideChaff', 'December 2021', 'December 2022',
deprecation.warn('Blockly.hideChaff', 'September 2021', 'September 2022',
'workspace.hideChaff');
common.hideChaff(opt_onlyClosePopups);
common.getMainWorkspace().hideChaff(opt_onlyClosePopups);
};
exports.hideChaff = hideChaff;

Expand Down
47 changes: 0 additions & 47 deletions core/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
*/
goog.module('Blockly.common');

const deprecation = goog.require('Blockly.utils.deprecation');
const {Blocks} = goog.require('Blockly.blocks');
/* eslint-disable-next-line no-unused-vars */
const {Connection} = goog.requireType('Blockly.Connection');
/* eslint-disable-next-line no-unused-vars */
const {ICopyable} = goog.requireType('Blockly.ICopyable');
const {Size} = goog.require('Blockly.utils.Size');
/* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block');
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -189,51 +187,6 @@ const getBlockTypeCounts = function(block, opt_stripFollowing) {
};
exports.getBlockTypeCounts = getBlockTypeCounts;

/**
* Size the workspace when the contents change. This also updates
* scrollbars accordingly.
* @param {!WorkspaceSvg} workspace The workspace to resize.
* @alias Blockly.common.resizeSvgContents
*/
const resizeSvgContents = function(workspace) {
workspace.resizeContents();
};
exports.resizeSvgContents = resizeSvgContents;

/**
* Returns the dimensions of the specified SVG image.
* @param {!SVGElement} svg SVG image.
* @return {!Size} Contains width and height properties.
* @deprecated Use workspace.getCachedParentSvgSize. (2021 March 5)
* @alias Blockly.common.svgSize
*/
const svgSize = function(svg) {
// When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_
// from setCachedParentSvgSize.
// The deprecated name is `Blockly.svgSize` because this function used to be
// declared in Blockly.js.
deprecation.warn(
'Blockly.svgSize', 'March 2021', 'March 2022',
'workspace.getCachedParentSvgSize');
svg = /** @type {?} */ (svg);
return new Size(svg.cachedWidth_, svg.cachedHeight_);
};
exports.svgSize = svgSize;

/**
* Close tooltips, context menus, dropdown selections, etc.
* @deprecated Use Blockly.common.getMainWorkspace().hideChaff()
* @param {boolean=} opt_onlyClosePopups Whether only popups should be closed.
* @alias Blockly.common.hideChaff
*/
const hideChaff = function(opt_onlyClosePopups) {
// The deprecated name is `Blockly.hideChaff` because this function used to
// be declared in Blockly.js
deprecation.warn('Blockly.hideChaff', 'September 2021', 'September 2022');
getMainWorkspace().hideChaff(opt_onlyClosePopups);
};
exports.hideChaff = hideChaff;

/**
* Helper function for defining a block from JSON. The resulting function has
* the correct value of jsonDef at the point in code where jsonInit is called.
Expand Down
23 changes: 23 additions & 0 deletions core/utils/svg_math.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
goog.module('Blockly.utils.svgMath');

const deprecation = goog.require('Blockly.utils.deprecation');
const global = goog.require('Blockly.utils.global');
const style = goog.require('Blockly.utils.style');
const userAgent = goog.require('Blockly.utils.userAgent');
const {Coordinate} = goog.require('Blockly.utils.Coordinate');
const {Rect} = goog.require('Blockly.utils.Rect');
const {Size} = goog.require('Blockly.utils.Size');
/* eslint-disable-next-line no-unused-vars */
const {WorkspaceSvg} = goog.requireType('Blockly.WorkspaceSvg');

Expand Down Expand Up @@ -239,6 +241,27 @@ const screenToWsCoordinates = function(ws, screenCoordinates) {
};
exports.screenToWsCoordinates = screenToWsCoordinates;

/**
* Returns the dimensions of the specified SVG image.
* @param {!SVGElement} svg SVG image.
* @return {!Size} Contains width and height properties.
* @deprecated Use workspace.getCachedParentSvgSize. (2021 March 5)
* @alias Blockly.utils.svgMath.svgSize
*/
const svgSize = function(svg) {
// When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_
// from setCachedParentSvgSize.
// The deprecated name is `Blockly.svgSize` because this function used to be
// declared in Blockly.js.
deprecation.warn(
'Blockly.svgSize', 'March 2021', 'March 2022',
'workspace.getCachedParentSvgSize');
svg = /** @type {?} */ (svg);
return new Size(svg.cachedWidth_, svg.cachedHeight_);
};
exports.svgSize = svgSize;


exports.TEST_ONLY = {
XY_REGEX,
XY_STYLE_REGEX,
Expand Down
11 changes: 11 additions & 0 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2697,4 +2697,15 @@ WorkspaceSvg.prototype.hideChaff = function(opt_onlyClosePopups) {
(autoHideable) => autoHideable.autoHide(onlyClosePopups));
};

/**
* Size the workspace when the contents change. This also updates
* scrollbars accordingly.
* @param {!WorkspaceSvg} workspace The workspace to resize.
* @alias Blockly.WorkspaceSvg.resizeSvgContents
*/
const resizeSvgContents = function(workspace) {
workspace.resizeContents();
};
exports.resizeSvgContents = resizeSvgContents;

exports.WorkspaceSvg = WorkspaceSvg;
5 changes: 2 additions & 3 deletions scripts/migration/renamings.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ const renamings = {
},
'Blockly': {
exports: {
svgSize: {module: 'Blockly.common'},
resizeSvgContents: {module: 'Blockly.common'},
hideChaff: {module: 'Blockly.common'},
svgSize: {module: 'Blockly.utils.svgMath'},
resizeSvgContents: {module: 'Blockly.WorkspaecSvg'},
defineBlocksWithJsonArray: {module: 'Blockly.common'},
isNumber: {module: 'Blockly.utils.math'},
},
Expand Down
6 changes: 3 additions & 3 deletions tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit beb7061

Please sign in to comment.