fix!: remove deprecated APIs (#9938)

This commit is contained in:
Maribeth Moffatt
2026-05-26 17:51:04 -04:00
committed by GitHub
parent aab9e2ac1c
commit 5d1097e58a
8 changed files with 13 additions and 594 deletions
-33
View File
@@ -38,7 +38,6 @@ import type {
import {Msg} from '../core/msg.js';
import {Names} from '../core/names.js';
import * as Procedures from '../core/procedures.js';
import * as deprecation from '../core/utils/deprecation.js';
import * as xmlUtils from '../core/utils/xml.js';
import * as Variables from '../core/variables.js';
import type {Workspace} from '../core/workspace.js';
@@ -345,22 +344,6 @@ const PROCEDURE_DEF_COMMON = {
}
}
},
/**
* Return all variables referenced by this block.
*
* @deprecated v13: Use Blockly.libraryBlocks.procedures.getVarModels()
* .map(m => m.getName())
* @returns List of variable names.
*/
getVars: function (this: ProcedureBlock): string[] {
deprecation.warn(
'Blockly.libraryBlocks.procedures.getVars()',
'v13',
'v14',
'Blockly.libraryBlocks.procedures.getVarModels().map(model => model.getName())',
);
return this.arguments_;
},
/**
* Return all variables referenced by this block.
*
@@ -1033,22 +1016,6 @@ const PROCEDURE_CALL_COMMON = {
this.setProcedureParameters_(params, ids);
}
},
/**
* Return all variables referenced by this block.
*
* @deprecated v13: Use Blockly.libraryBlocks.procedures.getVarModels()
* .map(m => m.getName())
* @returns List of variable names.
*/
getVars: function (this: CallBlock): string[] {
deprecation.warn(
'Blockly.libraryBlocks.procedures.getVars()',
'v13',
'v14',
'Blockly.libraryBlocks.procedures.getVarModels().map(model => model.getName())',
);
return this.arguments_;
},
/**
* Return all variables referenced by this block.
*
-23
View File
@@ -50,7 +50,6 @@ import * as registry from './registry.js';
import * as Tooltip from './tooltip.js';
import * as arrayUtils from './utils/array.js';
import {Coordinate} from './utils/coordinate.js';
import * as deprecation from './utils/deprecation.js';
import * as idGenerator from './utils/idgenerator.js';
import * as parsing from './utils/parsing.js';
import {replaceMessageReferences} from './utils/parsing.js';
@@ -1164,28 +1163,6 @@ export class Block {
}
}
/**
* Return all variables referenced by this block.
*
* @deprecated v13: Use Blockly.Block.getVarModels().map(m => m.getId())
* @returns List of variable ids.
*/
getVars(): string[] {
deprecation.warn(
'Blockly.Block.getVars()',
'v13',
'v14',
'Blockly.Block.getVarModels().map(model => model.getId())',
);
const vars: string[] = [];
for (const field of this.getFields()) {
if (field.referencesVariables()) {
vars.push(field.getValue());
}
}
return vars;
}
/**
* Return all variables referenced by this block.
*
+2 -126
View File
@@ -42,7 +42,6 @@ import {IProcedureModel} from './interfaces/i_procedure_model.js';
import {Msg} from './msg.js';
import {Names} from './names.js';
import {ObservableProcedureMap} from './observable_procedure_map.js';
import * as deprecation from './utils/deprecation.js';
import type {FlyoutItemInfo} from './utils/toolbox.js';
import * as utilsXml from './utils/xml.js';
import * as Variables from './variables.js';
@@ -238,132 +237,9 @@ export function rename(this: Field, name: string): string {
* Construct the blocks required by the flyout for the procedure category.
*
* @param workspace The workspace containing procedures.
* @returns Array of XML block elements.
* @returns List of flyout contents as JSON.
*/
function xmlFlyoutCategory(workspace: WorkspaceSvg): Element[] {
const xmlList = [];
if (Blocks['procedures_defnoreturn']) {
// <block type="procedures_defnoreturn" gap="16">
// <field name="NAME">do something</field>
// </block>
const block = utilsXml.createElement('block');
block.setAttribute('type', 'procedures_defnoreturn');
block.setAttribute('gap', '16');
const nameField = utilsXml.createElement('field');
nameField.setAttribute('name', 'NAME');
nameField.appendChild(
utilsXml.createTextNode(Msg['PROCEDURES_DEFNORETURN_PROCEDURE']),
);
block.appendChild(nameField);
xmlList.push(block);
}
if (Blocks['procedures_defreturn']) {
// <block type="procedures_defreturn" gap="16">
// <field name="NAME">do something</field>
// </block>
const block = utilsXml.createElement('block');
block.setAttribute('type', 'procedures_defreturn');
block.setAttribute('gap', '16');
const nameField = utilsXml.createElement('field');
nameField.setAttribute('name', 'NAME');
nameField.appendChild(
utilsXml.createTextNode(Msg['PROCEDURES_DEFRETURN_PROCEDURE']),
);
block.appendChild(nameField);
xmlList.push(block);
}
if (Blocks['procedures_ifreturn']) {
// <block type="procedures_ifreturn" gap="16"></block>
const block = utilsXml.createElement('block');
block.setAttribute('type', 'procedures_ifreturn');
block.setAttribute('gap', '16');
xmlList.push(block);
}
if (xmlList.length) {
// Add slightly larger gap between system blocks and user calls.
xmlList[xmlList.length - 1].setAttribute('gap', '24');
}
/**
* Add items to xmlList for each listed procedure.
*
* @param procedureList A list of procedures, each of which is defined by a
* three-element list of name, parameter list, and return value boolean.
* @param templateName The type of the block to generate.
*/
function populateProcedures(
procedureList: ProcedureTuple[],
templateName: string,
) {
for (let i = 0; i < procedureList.length; i++) {
const name = procedureList[i][0];
const args = procedureList[i][1];
// <block type="procedures_callnoreturn" gap="16">
// <mutation name="do something">
// <arg name="x"></arg>
// </mutation>
// </block>
const block = utilsXml.createElement('block');
block.setAttribute('type', templateName);
block.setAttribute('gap', '16');
const mutation = utilsXml.createElement('mutation');
mutation.setAttribute('name', name);
block.appendChild(mutation);
for (let j = 0; j < args.length; j++) {
const arg = utilsXml.createElement('arg');
arg.setAttribute('name', args[j]);
mutation.appendChild(arg);
}
xmlList.push(block);
}
}
const tuple = allProcedures(workspace);
populateProcedures(tuple[0], 'procedures_callnoreturn');
populateProcedures(tuple[1], 'procedures_callreturn');
return xmlList;
}
/**
* Internal wrapper that returns the contents of the procedure category.
*
* @internal
* @param workspace The workspace to populate procedure blocks for.
*/
export function internalFlyoutCategory(
workspace: WorkspaceSvg,
): FlyoutItemInfo[] {
return flyoutCategory(workspace, false);
}
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml: true,
): Element[];
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml: false,
): FlyoutItemInfo[];
/**
* Construct the blocks required by the flyout for the procedure category.
*
* @param workspace The workspace containing procedures.
* @param useXml True to return the contents as XML, false to use JSON.
* @returns List of flyout contents as either XML or JSON.
*/
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml = true,
): Element[] | FlyoutItemInfo[] {
if (useXml) {
deprecation.warn(
'The XML return value of Blockly.Procedures.flyoutCategory()',
'v12',
'v13',
'the same method, but handle a return type of FlyoutItemInfo[] (JSON) instead.',
);
return xmlFlyoutCategory(workspace);
}
export function flyoutCategory(workspace: WorkspaceSvg): FlyoutItemInfo[] {
const blocks = [];
if (Blocks['procedures_defnoreturn']) {
blocks.push({
+1 -84
View File
@@ -23,9 +23,8 @@ import type {IVariableMap} from './interfaces/i_variable_map.js';
import {IVariableModel, IVariableState} from './interfaces/i_variable_model.js';
import {Names} from './names.js';
import * as registry from './registry.js';
import * as deprecation from './utils/deprecation.js';
import * as idGenerator from './utils/idgenerator.js';
import {deleteVariable, getVariableUsesById} from './variables.js';
import {getVariableUsesById} from './variables.js';
import type {Workspace} from './workspace.js';
/**
@@ -135,29 +134,6 @@ export class VariableMap implements IVariableMap<
return variable;
}
/**
* Rename a variable by updating its name in the variable map. Identify the
* variable to rename with the given ID.
*
* @deprecated v12: use VariableMap.renameVariable.
* @param id ID of the variable to rename.
* @param newName New variable name.
*/
renameVariableById(id: string, newName: string) {
deprecation.warn(
'VariableMap.renameVariableById',
'v12',
'v13',
'VariableMap.renameVariable',
);
const variable = this.getVariableById(id);
if (!variable) {
throw Error("Tried to rename a variable that didn't exist. ID: " + id);
}
this.renameVariable(variable, newName);
}
/**
* Update the name of the given variable and refresh all references to it.
* The new name must not conflict with any existing variable names.
@@ -335,26 +311,6 @@ export class VariableMap implements IVariableMap<
}
}
/**
* Delete a variables by the passed in ID and all of its uses from this
* workspace. May prompt the user for confirmation.
*
* @deprecated v12: use Blockly.Variables.deleteVariable.
* @param id ID of variable to delete.
*/
deleteVariableById(id: string) {
deprecation.warn(
'VariableMap.deleteVariableById',
'v12',
'v13',
'Blockly.Variables.deleteVariable',
);
const variable = this.getVariableById(id);
if (variable) {
deleteVariable(this.workspace, variable);
}
}
/* End functions for variable deletion. */
/**
* Find the variable by the given name and type and return it. Return null if
@@ -432,45 +388,6 @@ export class VariableMap implements IVariableMap<
}
return allVariables;
}
/**
* Returns all of the variable names of all types.
*
* @deprecated v12: use Blockly.Variables.getAllVariables.
* @returns All of the variable names of all types.
*/
getAllVariableNames(): string[] {
deprecation.warn(
'VariableMap.getAllVariableNames',
'v12',
'v13',
'Blockly.Variables.getAllVariables',
);
const names: string[] = [];
for (const variables of this.variableMap.values()) {
for (const variable of variables.values()) {
names.push(variable.getName());
}
}
return names;
}
/**
* Find all the uses of a named variable.
*
* @deprecated v12: use Blockly.Variables.getVariableUsesById.
* @param id ID of the variable to find.
* @returns Array of block usages.
*/
getVariableUsesById(id: string): Block[] {
deprecation.warn(
'VariableMap.getVariableUsesById',
'v12',
'v13',
'Blockly.Variables.getVariableUsesById',
);
return getVariableUsesById(this.workspace, id);
}
}
registry.register(registry.Type.VARIABLE_MAP, registry.DEFAULT, VariableMap);
+2 -61
View File
@@ -18,7 +18,6 @@ import {isVariableBackedParameterModel} from './interfaces/i_variable_backed_par
import {IVariableModel, IVariableState} from './interfaces/i_variable_model.js';
import {keyboardNavigationController} from './keyboard_navigation_controller.js';
import {Msg} from './msg.js';
import * as deprecation from './utils/deprecation.js';
import type {BlockInfo, FlyoutItemInfo} from './utils/toolbox.js';
import * as utilsXml from './utils/xml.js';
import type {Workspace} from './workspace.js';
@@ -93,54 +92,20 @@ export function allDeveloperVariables(workspace: Workspace): string[] {
return Array.from(variables.values());
}
/**
* Internal wrapper that returns the contents of the variables category.
*
* @internal
* @param workspace The workspace to populate variable blocks for.
*/
export function internalFlyoutCategory(
workspace: WorkspaceSvg,
): FlyoutItemInfo[] {
return flyoutCategory(workspace, false);
}
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml: true,
): Element[];
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml: false,
): FlyoutItemInfo[];
/**
* Construct the elements (blocks and button) required by the flyout for the
* variable category.
*
* @param workspace The workspace containing variables.
* @param useXml True to return the contents as XML, false to use JSON.
* @returns List of flyout contents as either XML or JSON.
* @returns List of flyout contents as JSON.
*/
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml = true,
): Element[] | FlyoutItemInfo[] {
export function flyoutCategory(workspace: WorkspaceSvg): FlyoutItemInfo[] {
if (!Blocks['variables_set'] && !Blocks['variables_get']) {
console.warn(
'There are no variable blocks, but there is a variable category.',
);
}
if (useXml) {
deprecation.warn(
'The XML return value of Blockly.Variables.flyoutCategory()',
'v12',
'v13',
'the same method, but handle a return type of FlyoutItemInfo[] (JSON) instead.',
);
return xmlFlyoutCategory(workspace);
}
workspace.registerButtonCallback('CREATE_VARIABLE', function (button) {
createVariableButtonHandler(button.getTargetWorkspace());
});
@@ -244,30 +209,6 @@ export function jsonFlyoutCategoryBlocks(
return blocks;
}
/**
* Construct the elements (blocks and button) required by the flyout for the
* variable category.
*
* @param workspace The workspace containing variables.
* @returns Array of XML elements.
*/
function xmlFlyoutCategory(workspace: WorkspaceSvg): Element[] {
let xmlList = new Array<Element>();
const button = document.createElement('button');
button.setAttribute('text', '%{BKY_NEW_VARIABLE}');
button.setAttribute('callbackKey', 'CREATE_VARIABLE');
workspace.registerButtonCallback('CREATE_VARIABLE', function (button) {
createVariableButtonHandler(button.getTargetWorkspace());
});
xmlList.push(button);
const blockList = flyoutCategoryBlocks(workspace);
xmlList = xmlList.concat(blockList);
return xmlList;
}
/**
* Construct the blocks required by the flyout for the variable category.
*
+2 -77
View File
@@ -9,7 +9,6 @@
import {Blocks} from './blocks.js';
import type {FlyoutButton} from './flyout_button.js';
import {Msg} from './msg.js';
import * as deprecation from './utils/deprecation.js';
import type {FlyoutItemInfo} from './utils/toolbox.js';
import * as xml from './utils/xml.js';
import * as Variables from './variables.js';
@@ -70,53 +69,19 @@ function colourButtonClickHandler(button: FlyoutButton) {
// eslint-disable-next-line camelcase
export const onCreateVariableButtonClick_Colour = colourButtonClickHandler;
/**
* Internal wrapper that returns the contents of the dynamic variables category.
*
* @internal
* @param workspace The workspace to populate variable blocks for.
*/
export function internalFlyoutCategory(
workspace: WorkspaceSvg,
): FlyoutItemInfo[] {
return flyoutCategory(workspace, false);
}
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml: true,
): Element[];
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml: false,
): FlyoutItemInfo[];
/**
* Construct the elements (blocks and button) required by the flyout for the
* dynamic variables category.
*
* @param useXml True to return the contents as XML, false to use JSON.
* @returns List of flyout contents as either XML or JSON.
* @returns List of flyout contents as JSON.
*/
export function flyoutCategory(
workspace: WorkspaceSvg,
useXml = true,
): Element[] | FlyoutItemInfo[] {
export function flyoutCategory(workspace: WorkspaceSvg): FlyoutItemInfo[] {
if (!Blocks['variables_set_dynamic'] && !Blocks['variables_get_dynamic']) {
console.warn(
'There are no dynamic variable blocks, but there is a dynamic variable category.',
);
}
if (useXml) {
deprecation.warn(
'The XML return value of Blockly.VariablesDynamic.flyoutCategory()',
'v12',
'v13',
'the same method, but handle a return type of FlyoutItemInfo[] (JSON) instead.',
);
return xmlFlyoutCategory(workspace);
}
workspace.registerButtonCallback(
'CREATE_VARIABLE_STRING',
stringButtonClickHandler,
@@ -156,46 +121,6 @@ export function flyoutCategory(
];
}
/**
* Construct the elements (blocks and button) required by the flyout for the
* variable category.
*
* @param workspace The workspace containing variables.
* @returns Array of XML elements.
*/
function xmlFlyoutCategory(workspace: WorkspaceSvg): Element[] {
let xmlList = new Array<Element>();
let button = document.createElement('button');
button.setAttribute('text', Msg['NEW_STRING_VARIABLE']);
button.setAttribute('callbackKey', 'CREATE_VARIABLE_STRING');
xmlList.push(button);
button = document.createElement('button');
button.setAttribute('text', Msg['NEW_NUMBER_VARIABLE']);
button.setAttribute('callbackKey', 'CREATE_VARIABLE_NUMBER');
xmlList.push(button);
button = document.createElement('button');
button.setAttribute('text', Msg['NEW_COLOUR_VARIABLE']);
button.setAttribute('callbackKey', 'CREATE_VARIABLE_COLOUR');
xmlList.push(button);
workspace.registerButtonCallback(
'CREATE_VARIABLE_STRING',
stringButtonClickHandler,
);
workspace.registerButtonCallback(
'CREATE_VARIABLE_NUMBER',
numberButtonClickHandler,
);
workspace.registerButtonCallback(
'CREATE_VARIABLE_COLOUR',
colourButtonClickHandler,
);
const blockList = flyoutCategoryBlocks(workspace);
xmlList = xmlList.concat(blockList);
return xmlList;
}
/**
* Construct the blocks required by the flyout for the variable category.
*
-184
View File
@@ -33,12 +33,10 @@ import {ObservableProcedureMap} from './observable_procedure_map.js';
import {Options} from './options.js';
import * as registry from './registry.js';
import * as arrayUtils from './utils/array.js';
import * as deprecation from './utils/deprecation.js';
import * as idGenerator from './utils/idgenerator.js';
import * as math from './utils/math.js';
import {Rect} from './utils/rect.js';
import type * as toolbox from './utils/toolbox.js';
import {deleteVariable, getVariableUsesById} from './variables.js';
/**
* Class for a workspace. This is a data structure that contains blocks.
@@ -406,188 +404,6 @@ export class Workspace {
}
}
/* Begin functions that are just pass-throughs to the variable map. */
/**
* Rename a variable by updating its name in the variable
* map. Identify the variable to rename with the given ID.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().renameVariable
* @param id ID of the variable to rename.
* @param newName New variable name.
*/
renameVariableById(id: string, newName: string) {
deprecation.warn(
'Blockly.Workspace.renameVariableById',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().renameVariable',
);
const variable = this.variableMap.getVariableById(id);
if (!variable) return;
this.variableMap.renameVariable(variable, newName);
}
/**
* Create a variable with a given name, optional type, and optional ID.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().createVariable.
* @param name The name of the variable. This must be unique across variables
* and procedures.
* @param opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based
* on their type. This will default to '' which is a specific type.
* @param opt_id The unique ID of the variable. This will default to a UUID.
* @returns The newly created variable.
*/
createVariable(
name: string,
opt_type?: string | null,
opt_id?: string | null,
): IVariableModel<IVariableState> {
deprecation.warn(
'Blockly.Workspace.createVariable',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().createVariable',
);
return this.variableMap.createVariable(
name,
opt_type ?? undefined,
opt_id ?? undefined,
);
}
/**
* Find all the uses of the given variable, which is identified by ID.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().getVariableUsesById
* @param id ID of the variable to find.
* @returns Array of block usages.
*/
getVariableUsesById(id: string): Block[] {
deprecation.warn(
'Blockly.Workspace.getVariableUsesById',
'v12',
'v13',
'Blockly.Variables.getVariableUsesById',
);
return getVariableUsesById(this, id);
}
/**
* Delete a variables by the passed in ID and all of its uses from this
* workspace. May prompt the user for confirmation.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().deleteVariable.
* @param id ID of variable to delete.
*/
deleteVariableById(id: string) {
deprecation.warn(
'Blockly.Workspace.deleteVariableById',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().deleteVariable',
);
const variable = this.variableMap.getVariableById(id);
if (!variable) {
console.warn(`Can't delete non-existent variable: ${id}`);
return;
}
deleteVariable(this, variable);
}
/**
* Find the variable by the given name and return it. Return null if not
* found.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().getVariable.
* @param name The name to check for.
* @param opt_type The type of the variable. If not provided it defaults to
* the empty string, which is a specific type.
* @returns The variable with the given name.
*/
getVariable(
name: string,
opt_type?: string,
): IVariableModel<IVariableState> | null {
deprecation.warn(
'Blockly.Workspace.getVariable',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().getVariable',
);
// TODO (#1559): Possibly delete this function after resolving #1559.
return this.variableMap.getVariable(name, opt_type);
}
/**
* Find the variable by the given ID and return it. Return null if not found.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().getVariableById.
* @param id The ID to check for.
* @returns The variable with the given ID.
*/
getVariableById(id: string): IVariableModel<IVariableState> | null {
deprecation.warn(
'Blockly.Workspace.getVariableById',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().getVariableById',
);
return this.variableMap.getVariableById(id);
}
/**
* Find the variable with the specified type. If type is null, return list of
* variables with empty string type.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().getVariablesOfType.
* @param type Type of the variables to find.
* @returns The sought after variables of the passed in type. An empty array
* if none are found.
*/
getVariablesOfType(type: string | null): IVariableModel<IVariableState>[] {
deprecation.warn(
'Blockly.Workspace.getVariablesOfType',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().getVariablesOfType',
);
return this.variableMap.getVariablesOfType(type ?? '');
}
/**
* Return all variables of all types.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().getAllVariables.
* @returns List of variable models.
*/
getAllVariables(): IVariableModel<IVariableState>[] {
deprecation.warn(
'Blockly.Workspace.getAllVariables',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().getAllVariables',
);
return this.variableMap.getAllVariables();
}
/**
* Returns all variable names of all types.
*
* @deprecated v12: use Blockly.Workspace.getVariableMap().getAllVariables.
* @returns List of all variable names of all types.
*/
getAllVariableNames(): string[] {
deprecation.warn(
'Blockly.Workspace.getAllVariableNames',
'v12',
'v13',
'Blockly.Workspace.getVariableMap().getAllVariables',
);
return this.variableMap.getAllVariables().map((v) => v.getName());
}
/* End functions that are just pass-throughs to the variable map. */
/**
* Returns the horizontal offset of the workspace.
* Intended for LTR/RTL compatibility in XML.
+6 -6
View File
@@ -394,24 +394,24 @@ export class WorkspaceSvg
? new Grid(this.options.gridPattern, options.gridOptions)
: null;
if (Variables && Variables.internalFlyoutCategory) {
if (Variables && Variables.flyoutCategory) {
this.registerToolboxCategoryCallback(
Variables.CATEGORY_NAME,
Variables.internalFlyoutCategory,
Variables.flyoutCategory,
);
}
if (VariablesDynamic && VariablesDynamic.internalFlyoutCategory) {
if (VariablesDynamic && VariablesDynamic.flyoutCategory) {
this.registerToolboxCategoryCallback(
VariablesDynamic.CATEGORY_NAME,
VariablesDynamic.internalFlyoutCategory,
VariablesDynamic.flyoutCategory,
);
}
if (Procedures && Procedures.internalFlyoutCategory) {
if (Procedures && Procedures.flyoutCategory) {
this.registerToolboxCategoryCallback(
Procedures.CATEGORY_NAME,
Procedures.internalFlyoutCategory,
Procedures.flyoutCategory,
);
this.addChangeListener(Procedures.mutatorOpenListener);
}