Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Move backwards-compatibility hacks to main.js #6260

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 0 additions & 175 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,135 +347,6 @@ exports.setParentContainer = common.setParentContainer;
* Anything in this section may be removed in a future version of Blockly.
*/

// Add accessors for properties on Blockly that have now been deprecated.
Object.defineProperties(exports, {
/**
* Wrapper to window.alert() that app developers may override to
* provide alternatives to the modal browser window.
* @name Blockly.alert
* @type {!function(string, function()=)}
* @deprecated Use Blockly.dialog.alert / .setAlert() instead.
* (December 2021)
* @suppress {checkTypes}
*/
alert: {
set: function(newAlert) {
deprecation.warn('Blockly.alert', 'December 2021', 'December 2022');
dialog.setAlert(newAlert);
},
get: function() {
deprecation.warn(
'Blockly.alert', 'December 2021', 'December 2022',
'Blockly.dialog.alert()');
return dialog.alert;
},
},
/**
* Wrapper to window.confirm() that app developers may override to
* provide alternatives to the modal browser window.
* @name Blockly.confirm
* @type {!function(string, function()=)}
* @deprecated Use Blockly.dialog.confirm / .setConfirm() instead.
* (December 2021)
* @suppress {checkTypes}
*/
confirm: {
set: function(newConfirm) {
deprecation.warn('Blockly.confirm', 'December 2021', 'December 2022');
dialog.setConfirm(newConfirm);
},
get: function() {
deprecation.warn(
'Blockly.confirm', 'December 2021', 'December 2022',
'Blockly.dialog.confirm()');
return dialog.confirm;
},
},
/**
* The main workspace most recently used.
* Set by Blockly.WorkspaceSvg.prototype.markFocused
* @name Blockly.mainWorkspace
* @type {Workspace}
* @suppress {checkTypes}
*/
mainWorkspace: {
set: function(x) {
common.setMainWorkspace(x);
},
get: function() {
return common.getMainWorkspace();
},
},
/**
* Wrapper to window.prompt() that app developers may override to
* provide alternatives to the modal browser window. Built-in
* browser prompts are often used for better text input experience
* on mobile device. We strongly recommend testing mobile when
* overriding this.
* @name Blockly.prompt
* @type {!function(string, string, function()=)}
* @deprecated Use Blockly.dialog.prompt / .setPrompt() instead.
* (December 2021)
* @suppress {checkTypes}
*/
prompt: {
set: function(newPrompt) {
deprecation.warn('Blockly.prompt', 'December 2021', 'December 2022');
dialog.setPrompt(newPrompt);
},
get: function() {
deprecation.warn(
'Blockly.prompt', 'December 2021', 'December 2022',
'Blockly.dialog.prompt()');
return dialog.prompt;
},
},
/**
* Currently selected block.
* @name Blockly.selected
* @type {?ICopyable}
* @suppress {checkTypes}
*/
selected: {
get: function() {
return common.getSelected();
},
set: function(newSelection) {
common.setSelected(newSelection);
},
},
/**
* The richness of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @name Blockly.HSV_SATURATION
* @type {number}
* @suppress {checkTypes}
*/
HSV_SATURATION: {
get: function() {
return utils.colour.getHsvSaturation();
},
set: function(newValue) {
utils.colour.setHsvSaturation(newValue);
},
},
/**
* The intensity of block colours, regardless of the hue.
* Must be in the range of 0 (inclusive) to 1 (exclusive).
* @name Blockly.HSV_VALUE
* @type {number}
* @suppress {checkTypes}
*/
HSV_VALUE: {
get: function() {
return utils.colour.getHsvValue();
},
set: function(newValue) {
utils.colour.setHsvValue(newValue);
},
},
});

/**
* Returns the dimensions of the specified SVG image.
* @param {!SVGElement} svg SVG image.
Expand Down Expand Up @@ -840,49 +711,3 @@ exports.thrasos = thrasos;
exports.uiPosition = uiPosition;
exports.utils = utils;
exports.zelos = zelos;

// If Blockly is compiled with ADVANCED_COMPILATION and/or loaded as a
// CJS or ES module there will not be a Blockly global variable
// created. This can cause problems because a very common way of
// loading translations is to use a <script> tag to load one of
// msg/js/*.js, which consists of lines like:
//
// Blockly.Msg["ADD_COMMENT"] = "Add Comment";
// Blockly.Msg["CLEAN_UP"] = "Clean up Blocks";
//
// This obviously only works if Blockly.Msg is the Msg export from the
// Blockly.Msg module - so make sure it is, but only if there is not
// yet a Blockly global variable.
if (!('Blockly' in globalThis)) {
globalThis['Blockly'] = {'Msg': Msg};
}

// Temporary hack to copy accessor properties from exports to the
// global Blockly object as the routine to copy exports in
// goog.exportPath_ (see closure/goog/base.js) invoked by
// declareLegacyNamespace only copies normal data properties, not
// accessors. This can be removed once all remaining calls to
// declareLegacyNamspace have been removed.
//
// This is only needed in uncompiled mode (see
// google/blockly-samples#902); in compiled mode the exports object is
// already the value of globalThis['Blockly'].
//
// Note that this code will still attempt to redefine accessors on a
// previously-imported copy of the Blockly library if both are
// imported in uncompiled mode. This will fail with TypeError as the
// accessors are nonconfigurable (which is good, as otherwise one
// accessors on one copy would call get/set functions on the other
// copy!)
/* eslint-disable-next-line no-undef */
if (!COMPILED && typeof globalThis['Blockly'] === 'object' &&
globalThis['Blockly'] !== exports) {
const descriptors = Object.getOwnPropertyDescriptors(exports);
const accessors = {};
for (const key in descriptors) {
if (descriptors[key].get || descriptors[key].set) {
accessors[key] = descriptors[key];
}
}
Object.defineProperties(globalThis['Blockly'], accessors);
}
27 changes: 0 additions & 27 deletions core/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const Xml = goog.require('Blockly.Xml');
const aria = goog.require('Blockly.utils.aria');
const browserEvents = goog.require('Blockly.browserEvents');
const clipboard = goog.require('Blockly.clipboard');
const deprecation = goog.require('Blockly.utils.deprecation');
const dom = goog.require('Blockly.utils.dom');
const eventUtils = goog.require('Blockly.Events.utils');
const userAgent = goog.require('Blockly.utils.userAgent');
Expand Down Expand Up @@ -71,32 +70,6 @@ const setCurrentBlock = function(block) {
};
exports.setCurrentBlock = setCurrentBlock;

// Add JS accessors for backwards compatibility.
Object.defineProperties(exports, {
/**
* Which block is the context menu attached to?
* @name Blockly.ContextMenu.currentBlock
* @type {Block}
* @deprecated Use Blockly.Tooltip.getCurrentBlock() /
* .setCurrentBlock() instead. (September 2021)
* @suppress {checkTypes}
*/
currentBlock: {
get: function() {
deprecation.warn(
'Blockly.ContextMenu.currentBlock', 'September 2021',
'September 2022', 'Blockly.Tooltip.getCurrentBlock()');
return getCurrentBlock();
},
set: function(block) {
deprecation.warn(
'Blockly.ContextMenu.currentBlock', 'September 2021',
'September 2022', 'Blockly.Tooltip.setCurrentBlock(block)');
setCurrentBlock(block);
},
},
});

/**
* Menu object.
* @type {Menu}
Expand Down
26 changes: 0 additions & 26 deletions core/events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
goog.module('Blockly.Events');

const deprecation = goog.require('Blockly.utils.deprecation');
const eventUtils = goog.require('Blockly.Events.utils');
const {Abstract: AbstractEvent} = goog.require('Blockly.Events.Abstract');
const {BlockBase} = goog.require('Blockly.Events.BlockBase');
Expand Down Expand Up @@ -120,28 +119,3 @@ exports.isEnabled = eventUtils.isEnabled;
exports.setGroup = eventUtils.setGroup;
exports.setRecordUndo = eventUtils.setRecordUndo;
exports.disableOrphans = eventUtils.disableOrphans;

Object.defineProperties(exports, {
/**
* Sets whether the next event should be added to the undo stack.
* @name Blockly.Evenents.recordUndo
* @type {boolean}
* @deprecated Use Blockly.Events.getRecordUndo() and
* .setRecordUndo(). (September 2021)
* @suppress {checkTypes}
*/
recordUndo: {
get: function() {
deprecation.warn(
'Blockly.Events.recordUndo', 'September 2021', 'September 2022',
'Blockly.Events.getRecordUndo()');
return eventUtils.getRecordUndo();
},
set: function(record) {
deprecation.warn(
'Blockly.Events.recordUndo', 'September 2021', 'September 2022',
'Blockly.Events.setRecordUndo()');
eventUtils.setRecordUndo(record);
},
},
});
4 changes: 2 additions & 2 deletions core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,15 +547,15 @@ Object.defineProperties(Generator.prototype, {
* @return {!Names|undefined} Name database.
*/
get: function() {
deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_');
deprecation.warn('variableDB_', 'May 2021', 'September 2022', 'nameDB_');
return this.nameDB_;
},
/**
* @this {Generator}
* @param {!Names|undefined} nameDb New name database.
*/
set: function(nameDb) {
deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_');
deprecation.warn('variableDB_', 'May 2021', 'September 2022', 'nameDB_');
this.nameDB_ = nameDb;
},
},
Expand Down
Loading