mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
chore: remove deprecated functionality for v10 (#7077)
* chore: remove deprecated functionality in events files * chore: remove deprecated items in renderers * chore: remove deprecated items in core * chore: remove mixin deprecation * chore: fix tests after removing deprecations
This commit is contained in:
@@ -729,7 +729,7 @@ const QUOTES_EXTENSION = function (this: QuoteImageBlock) {
|
||||
};
|
||||
|
||||
/** Type of a block that has TEXT_JOIN_MUTATOR_MIXIN */
|
||||
type JoinMutatorBlock = Block & JoinMutatorMixin & QuoteImageMixin;
|
||||
type JoinMutatorBlock = BlockSvg & JoinMutatorMixin & QuoteImageMixin;
|
||||
interface JoinMutatorMixin extends JoinMutatorMixinType {}
|
||||
type JoinMutatorMixinType = typeof JOIN_MUTATOR_MIXIN;
|
||||
|
||||
@@ -896,7 +896,7 @@ const JOIN_EXTENSION = function (this: JoinMutatorBlock) {
|
||||
this.itemCount_ = 2;
|
||||
this.updateShape_();
|
||||
// Configure the mutator UI.
|
||||
this.setMutator(new Mutator(['text_create_join_item']));
|
||||
this.setMutator(new Mutator(['text_create_join_item'], this));
|
||||
};
|
||||
|
||||
// Update the tooltip of 'text_append' block to reference the variable.
|
||||
|
||||
205
core/blockly.ts
205
core/blockly.ts
@@ -12,8 +12,6 @@ import './events/events_block_create.js';
|
||||
// Unused import preserved for side-effects. Remove if unneeded.
|
||||
import './events/workspace_events.js';
|
||||
// Unused import preserved for side-effects. Remove if unneeded.
|
||||
import './events/events_ui.js';
|
||||
// Unused import preserved for side-effects. Remove if unneeded.
|
||||
import './events/events_ui_base.js';
|
||||
// Unused import preserved for side-effects. Remove if unneeded.
|
||||
import './events/events_var_create.js';
|
||||
@@ -207,8 +205,6 @@ import * as Tooltip from './tooltip.js';
|
||||
import * as Touch from './touch.js';
|
||||
import {Trashcan} from './trashcan.js';
|
||||
import * as utils from './utils.js';
|
||||
import * as colour from './utils/colour.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
import * as toolbox from './utils/toolbox.js';
|
||||
import {VariableMap} from './variable_map.js';
|
||||
import {VariableModel} from './variable_model.js';
|
||||
@@ -222,10 +218,7 @@ import {WorkspaceComment} from './workspace_comment.js';
|
||||
import {WorkspaceCommentSvg} from './workspace_comment_svg.js';
|
||||
import {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js';
|
||||
import {WorkspaceDragger} from './workspace_dragger.js';
|
||||
import {
|
||||
resizeSvgContents as realResizeSvgContents,
|
||||
WorkspaceSvg,
|
||||
} from './workspace_svg.js';
|
||||
import {WorkspaceSvg} from './workspace_svg.js';
|
||||
import * as Xml from './xml.js';
|
||||
import {ZoomControls} from './zoom_controls.js';
|
||||
|
||||
@@ -378,201 +371,6 @@ export const defineBlocksWithJsonArray = common.defineBlocksWithJsonArray;
|
||||
*/
|
||||
export const setParentContainer = common.setParentContainer;
|
||||
|
||||
/**
|
||||
* Size the workspace when the contents change. This also updates
|
||||
* scrollbars accordingly.
|
||||
*
|
||||
* @param workspace The workspace to resize.
|
||||
* @deprecated Use **workspace.resizeContents** instead.
|
||||
* @see Blockly.WorkspaceSvg.resizeContents
|
||||
*/
|
||||
function resizeSvgContentsLocal(workspace: WorkspaceSvg) {
|
||||
deprecation.warn(
|
||||
'Blockly.resizeSvgContents',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.WorkspaceSvg.resizeSvgContents'
|
||||
);
|
||||
realResizeSvgContents(workspace);
|
||||
}
|
||||
export const resizeSvgContents = resizeSvgContentsLocal;
|
||||
|
||||
/**
|
||||
* Copy a block or workspace comment onto the local clipboard.
|
||||
*
|
||||
* @param toCopy Block or Workspace Comment to be copied.
|
||||
* @deprecated Use **Blockly.clipboard.copy** instead.
|
||||
* @see Blockly.clipboard.copy
|
||||
*/
|
||||
export function copy(toCopy: ICopyable) {
|
||||
deprecation.warn(
|
||||
'Blockly.copy',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.clipboard.copy'
|
||||
);
|
||||
clipboard.copy(toCopy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste a block or workspace comment on to the main workspace.
|
||||
*
|
||||
* @returns True if the paste was successful, false otherwise.
|
||||
* @deprecated Use **Blockly.clipboard.paste** instead.
|
||||
* @see Blockly.clipboard.paste
|
||||
*/
|
||||
export function paste(): boolean {
|
||||
deprecation.warn(
|
||||
'Blockly.paste',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.clipboard.paste'
|
||||
);
|
||||
return !!clipboard.paste();
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate this block and its children, or a workspace comment.
|
||||
*
|
||||
* @param toDuplicate Block or Workspace Comment to be copied.
|
||||
* @deprecated Use **Blockly.clipboard.duplicate** instead.
|
||||
* @see Blockly.clipboard.duplicate
|
||||
*/
|
||||
export function duplicate(toDuplicate: ICopyable) {
|
||||
deprecation.warn(
|
||||
'Blockly.duplicate',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.clipboard.duplicate'
|
||||
);
|
||||
clipboard.duplicate(toDuplicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given string a number (includes negative and decimals).
|
||||
*
|
||||
* @param str Input string.
|
||||
* @returns True if number, false otherwise.
|
||||
* @deprecated Use **Blockly.utils.string.isNumber** instead.
|
||||
* @see Blockly.utils.string.isNumber
|
||||
*/
|
||||
export function isNumber(str: string): boolean {
|
||||
deprecation.warn(
|
||||
'Blockly.isNumber',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.string.isNumber'
|
||||
);
|
||||
return utils.string.isNumber(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a hue (HSV model) into an RGB hex triplet.
|
||||
*
|
||||
* @param hue Hue on a colour wheel (0-360).
|
||||
* @returns RGB code, e.g. '#5ba65b'.
|
||||
* @deprecated Use **Blockly.utils.colour.hueToHex** instead.
|
||||
* @see Blockly.utils.colour.hueToHex
|
||||
*/
|
||||
export function hueToHex(hue: number): string {
|
||||
deprecation.warn(
|
||||
'Blockly.hueToHex',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.colour.hueToHex'
|
||||
);
|
||||
return colour.hueToHex(hue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind an event handler that should be called regardless of whether it is part
|
||||
* of the active touch stream.
|
||||
* Use this for events that are not part of a multi-part gesture (e.g.
|
||||
* mouseover for tooltips).
|
||||
*
|
||||
* @param node Node upon which to listen.
|
||||
* @param name Event name to listen to (e.g. 'mousedown').
|
||||
* @param thisObject The value of 'this' in the function.
|
||||
* @param func Function to call when event is triggered.
|
||||
* @returns Opaque data that can be passed to unbindEvent_.
|
||||
* @deprecated Use **Blockly.browserEvents.bind** instead.
|
||||
* @see Blockly.browserEvents.bind
|
||||
*/
|
||||
export function bindEvent_(
|
||||
node: EventTarget,
|
||||
name: string,
|
||||
thisObject: Object | null,
|
||||
func: Function
|
||||
): browserEvents.Data {
|
||||
deprecation.warn(
|
||||
'Blockly.bindEvent_',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.browserEvents.bind'
|
||||
);
|
||||
return browserEvents.bind(node, name, thisObject, func);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind one or more events event from a function call.
|
||||
*
|
||||
* @param bindData Opaque data from bindEvent_.
|
||||
* This list is emptied during the course of calling this function.
|
||||
* @returns The function call.
|
||||
* @deprecated Use **Blockly.browserEvents.unbind** instead.
|
||||
* @see browserEvents.unbind
|
||||
*/
|
||||
export function unbindEvent_(bindData: browserEvents.Data): Function {
|
||||
deprecation.warn(
|
||||
'Blockly.unbindEvent_',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.browserEvents.unbind'
|
||||
);
|
||||
return browserEvents.unbind(bindData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind an event handler that can be ignored if it is not part of the active
|
||||
* touch stream.
|
||||
* Use this for events that either start or continue a multi-part gesture (e.g.
|
||||
* mousedown or mousemove, which may be part of a drag or click).
|
||||
*
|
||||
* @param node Node upon which to listen.
|
||||
* @param name Event name to listen to (e.g. 'mousedown').
|
||||
* @param thisObject The value of 'this' in the function.
|
||||
* @param func Function to call when event is triggered.
|
||||
* @param opt_noCaptureIdentifier True if triggering on this event should not
|
||||
* block execution of other event handlers on this touch or other
|
||||
* simultaneous touches. False by default.
|
||||
* @param _opt_noPreventDefault No-op, deprecated and will be removed in v10.
|
||||
* @returns Opaque data that can be passed to unbindEvent_.
|
||||
* @deprecated Use **Blockly.browserEvents.conditionalBind** instead.
|
||||
* @see browserEvents.conditionalBind
|
||||
*/
|
||||
export function bindEventWithChecks_(
|
||||
node: EventTarget,
|
||||
name: string,
|
||||
thisObject: Object | null,
|
||||
func: Function,
|
||||
opt_noCaptureIdentifier?: boolean,
|
||||
_opt_noPreventDefault?: boolean
|
||||
): browserEvents.Data {
|
||||
deprecation.warn(
|
||||
'Blockly.bindEventWithChecks_',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.browserEvents.conditionalBind'
|
||||
);
|
||||
return browserEvents.conditionalBind(
|
||||
node,
|
||||
name,
|
||||
thisObject,
|
||||
func,
|
||||
opt_noCaptureIdentifier
|
||||
);
|
||||
}
|
||||
|
||||
// Aliases to allow external code to access these values for legacy reasons.
|
||||
export const COLLAPSE_CHARS = internalConstants.COLLAPSE_CHARS;
|
||||
export const DRAG_STACK = internalConstants.DRAG_STACK;
|
||||
@@ -774,7 +572,6 @@ export {FlyoutMetricsManager};
|
||||
export {CodeGenerator};
|
||||
export {CodeGenerator as Generator}; // Deprecated name, October 2022.
|
||||
export {Gesture};
|
||||
export {Gesture as TouchGesture}; // Remove in v10.
|
||||
export {Grid};
|
||||
export {HorizontalFlyout};
|
||||
export {IASTNodeLocation};
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as goog from '../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.browserEvents');
|
||||
|
||||
import * as Touch from './touch.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
import * as userAgent from './utils/useragent.js';
|
||||
|
||||
/**
|
||||
@@ -44,7 +43,6 @@ const PAGE_MODE_MULTIPLIER = 125;
|
||||
* @param opt_noCaptureIdentifier True if triggering on this event should not
|
||||
* block execution of other event handlers on this touch or other
|
||||
* simultaneous touches. False by default.
|
||||
* @param opt_noPreventDefault No-op, deprecated and will be removed in v10.
|
||||
* @returns Opaque data that can be passed to unbindEvent_.
|
||||
*/
|
||||
export function conditionalBind(
|
||||
@@ -52,16 +50,8 @@ export function conditionalBind(
|
||||
name: string,
|
||||
thisObject: Object | null,
|
||||
func: Function,
|
||||
opt_noCaptureIdentifier?: boolean,
|
||||
opt_noPreventDefault?: boolean
|
||||
opt_noCaptureIdentifier?: boolean
|
||||
): Data {
|
||||
if (opt_noPreventDefault !== undefined) {
|
||||
deprecation.warn(
|
||||
'The opt_noPreventDefault argument of conditionalBind',
|
||||
'version 9',
|
||||
'version 10'
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
|
||||
@@ -29,7 +29,6 @@ import {
|
||||
ToolboxItemSelectJson,
|
||||
} from './events_toolbox_item_select.js';
|
||||
import {TrashcanOpen, TrashcanOpenJson} from './events_trashcan_open.js';
|
||||
import {Ui} from './events_ui.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import {VarBase, VarBaseJson} from './events_var_base.js';
|
||||
import {VarCreate, VarCreateJson} from './events_var_create.js';
|
||||
@@ -37,7 +36,7 @@ import {VarDelete, VarDeleteJson} from './events_var_delete.js';
|
||||
import {VarRename, VarRenameJson} from './events_var_rename.js';
|
||||
import {ViewportChange, ViewportChangeJson} from './events_viewport.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
import {FinishedLoading, FinishedLoadingJson} from './workspace_events.js';
|
||||
import {FinishedLoading} from './workspace_events.js';
|
||||
|
||||
// Events.
|
||||
export {Abstract};
|
||||
@@ -70,7 +69,6 @@ export {CommentDelete};
|
||||
export {CommentMove};
|
||||
export {CommentMoveJson};
|
||||
export {FinishedLoading};
|
||||
export {FinishedLoadingJson};
|
||||
export {MarkerMove};
|
||||
export {MarkerMoveJson};
|
||||
export {Selected};
|
||||
@@ -81,7 +79,6 @@ export {ToolboxItemSelect};
|
||||
export {ToolboxItemSelectJson};
|
||||
export {TrashcanOpen};
|
||||
export {TrashcanOpenJson};
|
||||
export {Ui};
|
||||
export {UiBase};
|
||||
export {VarBase};
|
||||
export {VarBaseJson};
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.Abstract');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as common from '../common.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
|
||||
@@ -66,22 +65,6 @@ export abstract class Abstract {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
fromJson(json: AbstractEventJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.Abstract.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
this.isBlank = false;
|
||||
this.group = json['group'] || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.BlockBase');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
|
||||
import {
|
||||
@@ -61,22 +60,6 @@ export class BlockBase extends AbstractEvent {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BlockBaseJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BlockBase.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.blockId = json['blockId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.BlockChange');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import type {BlockSvg} from '../block_svg.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import * as utilsXml from '../utils/xml.js';
|
||||
import {Workspace} from '../workspace.js';
|
||||
@@ -89,25 +88,6 @@ export class BlockChange extends BlockBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BlockChangeJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BlockChange.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.element = json['element'];
|
||||
this.name = json['name'];
|
||||
this.oldValue = json['oldValue'];
|
||||
this.newValue = json['newValue'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.BlockCreate');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import * as blocks from '../serialization/blocks.js';
|
||||
import * as utilsXml from '../utils/xml.js';
|
||||
@@ -92,27 +91,6 @@ export class BlockCreate extends BlockBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BlockCreateJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BlockCreate.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.xml = utilsXml.textToDom(json['xml']);
|
||||
this.ids = json['ids'];
|
||||
this.json = json['json'] as blocks.State;
|
||||
if (json['recordUndo'] !== undefined) {
|
||||
this.recordUndo = json['recordUndo'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.BlockDelete');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import * as blocks from '../serialization/blocks.js';
|
||||
import * as utilsXml from '../utils/xml.js';
|
||||
@@ -107,29 +106,6 @@ export class BlockDelete extends BlockBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BlockDeleteJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BlockDelete.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.oldXml = utilsXml.textToDom(json['oldXml']);
|
||||
this.ids = json['ids'];
|
||||
this.wasShadow =
|
||||
json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow';
|
||||
this.oldJson = json['oldJson'];
|
||||
if (json['recordUndo'] !== undefined) {
|
||||
this.recordUndo = json['recordUndo'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.BlockDrag');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
@@ -83,24 +82,6 @@ export class BlockDrag extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BlockDragJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BlockDrag.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.isStart = json['isStart'];
|
||||
this.blockId = json['blockId'];
|
||||
this.blocks = json['blocks'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.BlockMove');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import {ConnectionType} from '../connection_type.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {Coordinate} from '../utils/coordinate.js';
|
||||
|
||||
@@ -128,39 +127,6 @@ export class BlockMove extends BlockBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BlockMoveJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BlockMove.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.oldParentId = json['oldParentId'];
|
||||
this.oldInputName = json['oldInputName'];
|
||||
if (json['oldCoordinate']) {
|
||||
const xy = json['oldCoordinate'].split(',');
|
||||
this.oldCoordinate = new Coordinate(Number(xy[0]), Number(xy[1]));
|
||||
}
|
||||
this.newParentId = json['newParentId'];
|
||||
this.newInputName = json['newInputName'];
|
||||
if (json['newCoordinate']) {
|
||||
const xy = json['newCoordinate'].split(',');
|
||||
this.newCoordinate = new Coordinate(Number(xy[0]), Number(xy[1]));
|
||||
}
|
||||
if (json['reason'] !== undefined) {
|
||||
this.reason = json['reason'];
|
||||
}
|
||||
if (json['recordUndo'] !== undefined) {
|
||||
this.recordUndo = json['recordUndo'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.BubbleOpen');
|
||||
|
||||
import type {AbstractEventJson} from './events_abstract.js';
|
||||
import type {BlockSvg} from '../block_svg.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
@@ -81,24 +80,6 @@ export class BubbleOpen extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: BubbleOpenJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.BubbleOpen.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.isOpen = json['isOpen'];
|
||||
this.bubbleType = json['bubbleType'];
|
||||
this.blockId = json['blockId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.Click');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
|
||||
@@ -77,23 +76,6 @@ export class Click extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: ClickJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.Click.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.targetType = json['targetType'];
|
||||
this.blockId = json['blockId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.CommentBase');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as utilsXml from '../utils/xml.js';
|
||||
import type {WorkspaceComment} from '../workspace_comment.js';
|
||||
import * as Xml from '../xml.js';
|
||||
@@ -69,22 +68,6 @@ export class CommentBase extends AbstractEvent {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: CommentBaseJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.CommentBase.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.commentId = json['commentId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.CommentChange');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {WorkspaceComment} from '../workspace_comment.js';
|
||||
|
||||
@@ -80,23 +79,6 @@ export class CommentChange extends CommentBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: CommentChangeJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.CommentChange.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.oldContents_ = json['oldContents'];
|
||||
this.newContents_ = json['newContents'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.CommentCreate');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {WorkspaceComment} from '../workspace_comment.js';
|
||||
import * as utilsXml from '../utils/xml.js';
|
||||
@@ -63,22 +62,6 @@ export class CommentCreate extends CommentBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: CommentCreateJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.CommentCreate.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.xml = utilsXml.textToDom(json['xml']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.CommentMove');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {Coordinate} from '../utils/coordinate.js';
|
||||
import type {WorkspaceComment} from '../workspace_comment.js';
|
||||
@@ -112,25 +111,6 @@ export class CommentMove extends CommentBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: CommentMoveJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.CommentMove.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
let xy = json['oldCoordinate'].split(',');
|
||||
this.oldCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1]));
|
||||
xy = json['newCoordinate'].split(',');
|
||||
this.newCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.MarkerMove');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import {ASTNode} from '../keyboard_nav/ast_node.js';
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
@@ -99,25 +98,6 @@ export class MarkerMove extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: MarkerMoveJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.MarkerMove.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.isCursor = json['isCursor'];
|
||||
this.blockId = json['blockId'];
|
||||
this.oldNode = json['oldNode'];
|
||||
this.newNode = json['newNode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.Selected');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
|
||||
@@ -67,23 +66,6 @@ export class Selected extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: SelectedJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.Selected.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.oldElementId = json['oldElementId'];
|
||||
this.newElementId = json['newElementId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.ThemeChange');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
@@ -55,22 +54,6 @@ export class ThemeChange extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: ThemeChangeJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.ThemeChange.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.themeName = json['themeName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.ToolboxItemSelect');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
@@ -61,23 +60,6 @@ export class ToolboxItemSelect extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: ToolboxItemSelectJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.ToolboxItemSelect.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.oldItem = json['oldItem'];
|
||||
this.newItem = json['newItem'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.TrashcanOpen');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
|
||||
@@ -59,22 +58,6 @@ export class TrashcanOpen extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: TrashcanOpenJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.TrashcanOpen.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.isOpen = json['isOpen'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2018 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* (Deprecated) Events fired as a result of UI actions in
|
||||
* Blockly's editor.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.Ui');
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
|
||||
/**
|
||||
* Class for a UI event.
|
||||
*
|
||||
* @deprecated December 2020. Instead use a more specific UI event.
|
||||
*/
|
||||
export class Ui extends UiBase {
|
||||
blockId: AnyDuringMigration;
|
||||
element: AnyDuringMigration;
|
||||
oldValue: AnyDuringMigration;
|
||||
newValue: AnyDuringMigration;
|
||||
override type = eventUtils.UI;
|
||||
|
||||
/**
|
||||
* @param opt_block The affected block. Null for UI events that do not have
|
||||
* an associated block. Undefined for a blank event.
|
||||
* @param opt_element One of 'selected', 'comment', 'mutatorOpen', etc.
|
||||
* @param opt_oldValue Previous value of element.
|
||||
* @param opt_newValue New value of element.
|
||||
*/
|
||||
constructor(
|
||||
opt_block?: Block | null,
|
||||
opt_element?: string,
|
||||
opt_oldValue?: AnyDuringMigration,
|
||||
opt_newValue?: AnyDuringMigration
|
||||
) {
|
||||
const workspaceId = opt_block ? opt_block.workspace.id : undefined;
|
||||
super(workspaceId);
|
||||
|
||||
this.blockId = opt_block ? opt_block.id : null;
|
||||
this.element = typeof opt_element === 'undefined' ? '' : opt_element;
|
||||
this.oldValue = typeof opt_oldValue === 'undefined' ? '' : opt_oldValue;
|
||||
this.newValue = typeof opt_newValue === 'undefined' ? '' : opt_newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
*
|
||||
* @returns JSON representation.
|
||||
*/
|
||||
override toJson(): AnyDuringMigration {
|
||||
const json = super.toJson() as AnyDuringMigration;
|
||||
json['element'] = this.element;
|
||||
if (this.newValue !== undefined) {
|
||||
json['newValue'] = this.newValue;
|
||||
}
|
||||
if (this.blockId) {
|
||||
json['blockId'] = this.blockId;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: AnyDuringMigration) {
|
||||
super.fromJson(json);
|
||||
this.element = json['element'];
|
||||
this.newValue = json['newValue'];
|
||||
this.blockId = json['blockId'];
|
||||
}
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, eventUtils.UI, Ui);
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.VarBase');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
|
||||
import {
|
||||
@@ -59,22 +58,6 @@ export class VarBase extends AbstractEvent {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: VarBaseJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.VarBase.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.varId = json['varId'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.VarCreate');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
|
||||
@@ -69,23 +68,6 @@ export class VarCreate extends VarBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: VarCreateJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.VarCreate.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.varType = json['varType'];
|
||||
this.varName = json['varName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.VarDelete');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
|
||||
@@ -64,23 +63,6 @@ export class VarDelete extends VarBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: VarDeleteJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.VarDelete.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.varType = json['varType'];
|
||||
this.varName = json['varName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.VarRename');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {VariableModel} from '../variable_model.js';
|
||||
|
||||
@@ -67,23 +66,6 @@ export class VarRename extends VarBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: VarRenameJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.VarRename.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.oldName = json['oldName'];
|
||||
this.newName = json['newName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Events.ViewportChange');
|
||||
|
||||
import * as deprecation from '../utils/deprecation.js';
|
||||
import * as registry from '../registry.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
@@ -110,25 +109,6 @@ export class ViewportChange extends UiBase {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: ViewportChangeJson) {
|
||||
deprecation.warn(
|
||||
'Blockly.Events.Viewport.prototype.fromJson',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.Events.fromJson'
|
||||
);
|
||||
super.fromJson(json);
|
||||
this.viewTop = json['viewTop'];
|
||||
this.viewLeft = json['viewLeft'];
|
||||
this.scale = json['scale'];
|
||||
this.oldScale = json['oldScale'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
|
||||
@@ -487,32 +487,7 @@ export function fromJson(
|
||||
const eventClass = get(json['type']);
|
||||
if (!eventClass) throw Error('Unknown event type.');
|
||||
|
||||
if (eventClassHasStaticFromJson(eventClass)) {
|
||||
return (eventClass as any).fromJson(json, workspace);
|
||||
}
|
||||
|
||||
// Fallback to the old deserialization method.
|
||||
const event = new eventClass();
|
||||
event.fromJson(json);
|
||||
event.workspaceId = workspace.id;
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given event constructor has /its own/ static fromJson
|
||||
* method.
|
||||
*
|
||||
* Returns false if no static fromJson method exists on the contructor, or if
|
||||
* the static fromJson method is inheritted.
|
||||
*/
|
||||
function eventClassHasStaticFromJson(
|
||||
eventClass: new (...p: any[]) => Abstract
|
||||
): boolean {
|
||||
const untypedEventClass = eventClass as any;
|
||||
return (
|
||||
Object.getOwnPropertyDescriptors(untypedEventClass).fromJson &&
|
||||
typeof untypedEventClass.fromJson === 'function'
|
||||
);
|
||||
return (eventClass as any).fromJson(json, workspace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,10 +14,7 @@ goog.declareModuleId('Blockly.Events.FinishedLoading');
|
||||
|
||||
import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {
|
||||
Abstract as AbstractEvent,
|
||||
AbstractEventJson,
|
||||
} from './events_abstract.js';
|
||||
import {Abstract as AbstractEvent} from './events_abstract.js';
|
||||
import * as eventUtils from './utils.js';
|
||||
|
||||
/**
|
||||
@@ -41,37 +38,6 @@ export class FinishedLoading extends AbstractEvent {
|
||||
|
||||
this.workspaceId = opt_workspace.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
*
|
||||
* @returns JSON representation.
|
||||
*/
|
||||
override toJson(): FinishedLoadingJson {
|
||||
const json = super.toJson() as FinishedLoadingJson;
|
||||
if (!this.workspaceId) {
|
||||
throw new Error(
|
||||
'The workspace ID is undefined. Either pass a workspace to ' +
|
||||
'the constructor, or call fromJson'
|
||||
);
|
||||
}
|
||||
json['workspaceId'] = this.workspaceId;
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the JSON event.
|
||||
*
|
||||
* @param json JSON representation.
|
||||
*/
|
||||
override fromJson(json: FinishedLoadingJson) {
|
||||
super.fromJson(json);
|
||||
this.workspaceId = json['workspaceId'];
|
||||
}
|
||||
}
|
||||
|
||||
export interface FinishedLoadingJson extends AbstractEventJson {
|
||||
workspaceId: string;
|
||||
}
|
||||
|
||||
registry.register(
|
||||
|
||||
@@ -16,7 +16,6 @@ goog.declareModuleId('Blockly.CodeGenerator');
|
||||
import type {Block} from './block.js';
|
||||
import * as common from './common.js';
|
||||
import {Names, NameType} from './names.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
import type {Workspace} from './workspace.js';
|
||||
|
||||
/**
|
||||
@@ -547,25 +546,3 @@ export class CodeGenerator {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperties(CodeGenerator.prototype, {
|
||||
/**
|
||||
* A database of variable names.
|
||||
*
|
||||
* @name Blockly.CodeGenerator.prototype.variableDB_
|
||||
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
variableDB_: {
|
||||
/** @returns Name database. */
|
||||
get(this: CodeGenerator): Names | undefined {
|
||||
deprecation.warn('variableDB_', 'version 9', 'version 10', 'nameDB_');
|
||||
return this.nameDB_;
|
||||
},
|
||||
/** @param nameDb New name database. */
|
||||
set(this: CodeGenerator, nameDb: Names | undefined) {
|
||||
deprecation.warn('variableDB_', 'version 9', 'version 10', 'nameDB_');
|
||||
this.nameDB_ = nameDb;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -20,13 +20,12 @@ import * as dom from './utils/dom.js';
|
||||
import {Size} from './utils/size.js';
|
||||
import {Svg} from './utils/svg.js';
|
||||
import * as svgMath from './utils/svg_math.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
|
||||
/**
|
||||
* Class for an icon.
|
||||
*/
|
||||
export abstract class Icon {
|
||||
protected block_: BlockSvg | null;
|
||||
protected block_: BlockSvg;
|
||||
/** The icon SVG group. */
|
||||
iconGroup_: SVGGElement | null = null;
|
||||
|
||||
@@ -43,15 +42,7 @@ export abstract class Icon {
|
||||
protected iconXY_: Coordinate | null = null;
|
||||
|
||||
/** @param block The block associated with this icon. */
|
||||
constructor(block: BlockSvg | null) {
|
||||
if (!block) {
|
||||
deprecation.warn(
|
||||
'Calling the Icon constructor with a null block',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'a non-null block'
|
||||
);
|
||||
}
|
||||
constructor(block: BlockSvg) {
|
||||
this.block_ = block;
|
||||
}
|
||||
|
||||
@@ -197,10 +188,6 @@ export abstract class Icon {
|
||||
* @returns The block this icon is attached to.
|
||||
*/
|
||||
protected getBlock(): BlockSvg {
|
||||
if (!this.block_) {
|
||||
throw new Error('Block is not set for this icon.');
|
||||
}
|
||||
|
||||
return this.block_;
|
||||
}
|
||||
}
|
||||
|
||||
329
core/main.js
329
core/main.js
@@ -13,334 +13,9 @@
|
||||
|
||||
goog.module('Blockly.main');
|
||||
|
||||
const Blockly = goog.require('Blockly');
|
||||
const ContextMenu = goog.require('Blockly.ContextMenu');
|
||||
const Events = goog.require('Blockly.Events');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly');
|
||||
const Msg = goog.require('Blockly.Msg');
|
||||
const Tooltip = goog.require('Blockly.Tooltip');
|
||||
const WidgetDiv = goog.require('Blockly.WidgetDiv');
|
||||
const colour = goog.require('Blockly.utils.colour');
|
||||
const common = goog.require('Blockly.common');
|
||||
const deprecation = goog.require('Blockly.utils.deprecation');
|
||||
const dialog = goog.require('Blockly.dialog');
|
||||
const eventUtils = goog.require('Blockly.Events.utils');
|
||||
|
||||
/*
|
||||
* Aliased functions and properties that used to be on the Blockly namespace.
|
||||
* Everything in this section is deprecated. Both external and internal code
|
||||
* should avoid using these functions and use the designated replacements.
|
||||
* Everything in this section will be removed in a future version of Blockly.
|
||||
*/
|
||||
|
||||
// Add accessors for properties on Blockly that have now been deprecated.
|
||||
Object.defineProperties(Blockly, {
|
||||
/**
|
||||
* 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',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.dialog.setAlert'
|
||||
);
|
||||
dialog.setAlert(newAlert);
|
||||
},
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.alert',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'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',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.dialog.setConfirm'
|
||||
);
|
||||
dialog.setConfirm(newConfirm);
|
||||
},
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.confirm',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'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) {
|
||||
deprecation.warn(
|
||||
'Blockly.mainWorkspace',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.getMainWorkspace'
|
||||
);
|
||||
common.setMainWorkspace(x);
|
||||
},
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.mainWorkspace',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.getMainWorkspace'
|
||||
);
|
||||
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',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.dialog.setPrompt'
|
||||
);
|
||||
dialog.setPrompt(newPrompt);
|
||||
},
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.prompt',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.dialog.prompt'
|
||||
);
|
||||
return dialog.prompt;
|
||||
},
|
||||
},
|
||||
/**
|
||||
* Currently selected block.
|
||||
* @name Blockly.selected
|
||||
* @type {?ICopyable}
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
selected: {
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.selected',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.getSelected'
|
||||
);
|
||||
return common.getSelected();
|
||||
},
|
||||
set: function (newSelection) {
|
||||
deprecation.warn(
|
||||
'Blockly.selected',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Blockly.getSelected'
|
||||
);
|
||||
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 colour.getHsvSaturation();
|
||||
},
|
||||
set: function (newValue) {
|
||||
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 colour.getHsvValue();
|
||||
},
|
||||
set: function (newValue) {
|
||||
colour.setHsvValue(newValue);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Add accessors for properties on Blockly.ContextMenu that have now
|
||||
// been deprecated.
|
||||
Object.defineProperties(ContextMenu, {
|
||||
/**
|
||||
* 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 ContextMenu.getCurrentBlock();
|
||||
},
|
||||
set: function (block) {
|
||||
deprecation.warn(
|
||||
'Blockly.ContextMenu.currentBlock',
|
||||
'September 2021',
|
||||
'September 2022',
|
||||
'Blockly.Tooltip.setCurrentBlock(block)'
|
||||
);
|
||||
ContextMenu.setCurrentBlock(block);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Add accessors for properties on Blockly.Events that have now been
|
||||
// deprecated.
|
||||
Object.defineProperties(Events, {
|
||||
/**
|
||||
* 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);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Add accessors for properties on Blockly.Tooltip that have now been
|
||||
// deprecated.
|
||||
Object.defineProperties(Tooltip, {
|
||||
/**
|
||||
* Is a tooltip currently showing?
|
||||
* @name Blockly.Tooltip.visible
|
||||
* @type {boolean}
|
||||
* @deprecated Use Blockly.Tooltip.isVisible() instead. (September
|
||||
* 2021)
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
visible: {
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.Tooltip.visible',
|
||||
'September 2021',
|
||||
'September 2022',
|
||||
'Blockly.Tooltip.isVisible()'
|
||||
);
|
||||
return Tooltip.isVisible();
|
||||
},
|
||||
},
|
||||
/**
|
||||
* The HTML container. Set once by createDom.
|
||||
* @name Blockly.Tooltip.DIV
|
||||
* @type {HTMLDivElement}
|
||||
* @deprecated Use Blockly.Tooltip.getDiv() and .setDiv().
|
||||
* (September 2021)
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
DIV: {
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.Tooltip.DIV',
|
||||
'September 2021',
|
||||
'September 2022',
|
||||
'Blockly.Tooltip.getDiv()'
|
||||
);
|
||||
return Tooltip.getDiv();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Add accessors for properties on Blockly.WidgetDiv that have now been
|
||||
// deprecated.
|
||||
Object.defineProperties(WidgetDiv, {
|
||||
/**
|
||||
* The HTML container for popup overlays (e.g. editor widgets).
|
||||
* @name Blockly.WidgetDiv.DIV
|
||||
* @type {?Element}
|
||||
* @deprecated Use Blockly.WidgetDiv.getDiv() and .setDiv().
|
||||
* (September 2021)
|
||||
* @suppress {checkTypes}
|
||||
*/
|
||||
DIV: {
|
||||
get: function () {
|
||||
deprecation.warn(
|
||||
'Blockly.WidgetDiv.DIV',
|
||||
'September 2021',
|
||||
'September 2022',
|
||||
'Blockly.WidgetDiv.getDiv()'
|
||||
);
|
||||
return WidgetDiv.getDiv();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// If Blockly is compiled with ADVANCED_COMPILATION and/or loaded as a
|
||||
// CJS or ES module there will not be a Blockly global variable
|
||||
|
||||
@@ -32,7 +32,6 @@ import * as dom from './utils/dom.js';
|
||||
import {Svg} from './utils/svg.js';
|
||||
import * as toolbox from './utils/toolbox.js';
|
||||
import * as xml from './utils/xml.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
|
||||
/**
|
||||
@@ -79,16 +78,8 @@ export class Mutator extends Icon {
|
||||
private updateWorkspacePid: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
/** @param quarkNames List of names of sub-blocks for flyout. */
|
||||
constructor(quarkNames: string[], block?: BlockSvg) {
|
||||
if (!block) {
|
||||
deprecation.warn(
|
||||
'Calling the Mutator constructor without passing the block it is attached to',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'the constructor by passing the list of subblocks and the block instance to attach the mutator to'
|
||||
);
|
||||
}
|
||||
super(block ?? null);
|
||||
constructor(quarkNames: string[], block: BlockSvg) {
|
||||
super(block);
|
||||
this.quarkNames = quarkNames;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ goog.declareModuleId('Blockly.blockRendering');
|
||||
|
||||
import * as registry from '../../registry.js';
|
||||
import type {Theme} from '../../theme.js';
|
||||
import * as deprecation from '../../utils/deprecation.js';
|
||||
import {Measurable} from '../measurables/base.js';
|
||||
import {BottomRow} from '../measurables/bottom_row.js';
|
||||
import {Connection} from '../measurables/connection.js';
|
||||
@@ -34,7 +33,6 @@ import {TopRow} from '../measurables/top_row.js';
|
||||
import {Types} from '../measurables/types.js';
|
||||
|
||||
import {ConstantProvider} from './constants.js';
|
||||
import * as debug from './debug.js';
|
||||
import {Debug} from './debugger.js';
|
||||
import {Drawer} from './drawer.js';
|
||||
import type {IPathObject} from './i_path_object.js';
|
||||
@@ -63,23 +61,6 @@ export function unregister(name: string) {
|
||||
registry.unregister(registry.Type.RENDERER, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off the blocks debugger.
|
||||
*
|
||||
* @deprecated Use the debug renderer in **\@blockly/dev-tools** (See {@link
|
||||
* https://www.npmjs.com/package/@blockly/dev-tools}.)
|
||||
* @internal
|
||||
*/
|
||||
export function stopDebugger() {
|
||||
deprecation.warn(
|
||||
'Blockly.blockRendering.stopDebugger()',
|
||||
'September 2021',
|
||||
'September 2022',
|
||||
'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'
|
||||
);
|
||||
debug.stopDebugger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize anything needed for rendering (constants, etc).
|
||||
*
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as goog from '../../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.blockRendering.debug');
|
||||
|
||||
import * as deprecation from '../../utils/deprecation.js';
|
||||
|
||||
/** Whether or not the debugger is turned on. */
|
||||
let useDebugger = false;
|
||||
/**
|
||||
* Returns whether the debugger is turned on.
|
||||
*
|
||||
* @returns Whether the debugger is turned on.
|
||||
* @internal
|
||||
*/
|
||||
export function isDebuggerEnabled(): boolean {
|
||||
return useDebugger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on the blocks debugger.
|
||||
*
|
||||
* @deprecated March 2022. Use the rendering debugger in @blockly/dev-tools.
|
||||
* See https://www.npmjs.com/package/@blockly/dev-tools for more information.
|
||||
* @internal
|
||||
*/
|
||||
export function startDebugger() {
|
||||
deprecation.warn(
|
||||
'Blockly.blockRendering.debug.startDebugger()',
|
||||
'version 8',
|
||||
'version 10',
|
||||
'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'
|
||||
);
|
||||
useDebugger = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off the blocks debugger.
|
||||
*
|
||||
* @deprecated March 2022. Use the rendering debugger in @blockly/dev-tools.
|
||||
* See https://www.npmjs.com/package/@blockly/dev-tools for more information.
|
||||
* @internal
|
||||
*/
|
||||
export function stopDebugger() {
|
||||
deprecation.warn(
|
||||
'Blockly.blockRendering.debug.stopDebugger()',
|
||||
'version 8',
|
||||
'version 10',
|
||||
'the debug renderer in @blockly/dev-tools (See https://www.npmjs.com/package/@blockly/dev-tools.)'
|
||||
);
|
||||
useDebugger = false;
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import {Types} from '../measurables/types.js';
|
||||
|
||||
import {isDynamicShape} from './constants.js';
|
||||
import type {ConstantProvider, Notch, PuzzleTab} from './constants.js';
|
||||
import * as debug from './debug.js';
|
||||
import type {RenderInfo} from './info.js';
|
||||
|
||||
/**
|
||||
@@ -67,9 +66,6 @@ export class Drawer {
|
||||
if (this.info_.RTL) {
|
||||
this.block_.pathObject.flipRTL();
|
||||
}
|
||||
if (debug.isDebuggerEnabled()) {
|
||||
this.block_.renderingDebugger?.drawDebug(this.block_, this.info_);
|
||||
}
|
||||
this.recordSizeOnBlock_();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@ import type {BlockStyle, Theme} from '../../theme.js';
|
||||
import type {WorkspaceSvg} from '../../workspace_svg.js';
|
||||
|
||||
import {ConstantProvider} from './constants.js';
|
||||
import * as debug from './debug.js';
|
||||
import {Debug} from './debugger.js';
|
||||
import {Drawer} from './drawer.js';
|
||||
import type {IPathObject} from './i_path_object.js';
|
||||
import {RenderInfo} from './info.js';
|
||||
@@ -157,17 +155,6 @@ export class Renderer implements IRegistrable {
|
||||
return new Drawer(block, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the renderer's debugger.
|
||||
*
|
||||
* @returns The renderer debugger.
|
||||
* @suppress {strictModuleDepCheck} Debug renderer only included in
|
||||
* playground.
|
||||
*/
|
||||
protected makeDebugger_(): Debug {
|
||||
return new Debug(this.getConstants());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the renderer's marker drawer.
|
||||
*
|
||||
@@ -278,9 +265,6 @@ export class Renderer implements IRegistrable {
|
||||
* @internal
|
||||
*/
|
||||
render(block: BlockSvg) {
|
||||
if (debug.isDebuggerEnabled() && !block.renderingDebugger) {
|
||||
block.renderingDebugger = this.makeDebugger_();
|
||||
}
|
||||
const info = this.makeRenderInfo_(block);
|
||||
info.measure();
|
||||
this.makeDrawer_(block, info).draw();
|
||||
|
||||
@@ -9,7 +9,6 @@ goog.declareModuleId('Blockly.geras.Drawer');
|
||||
|
||||
import type {BlockSvg} from '../../block_svg.js';
|
||||
import * as svgPaths from '../../utils/svg_paths.js';
|
||||
import * as debug from '../common/debug.js';
|
||||
import {Drawer as BaseDrawer} from '../common/drawer.js';
|
||||
import type {Row} from '../measurables/row.js';
|
||||
|
||||
@@ -50,9 +49,6 @@ export class Drawer extends BaseDrawer {
|
||||
if (this.info_.RTL) {
|
||||
pathObject.flipRTL();
|
||||
}
|
||||
if (debug.isDebuggerEnabled()) {
|
||||
this.block_?.renderingDebugger?.drawDebug(this.block_, this.info_);
|
||||
}
|
||||
this.recordSizeOnBlock_();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ goog.declareModuleId('Blockly.zelos.Drawer');
|
||||
import type {BlockSvg} from '../../block_svg.js';
|
||||
import * as svgPaths from '../../utils/svg_paths.js';
|
||||
import type {BaseShape, DynamicShape, Notch} from '../common/constants.js';
|
||||
import * as debug from '../common/debug.js';
|
||||
import {Drawer as BaseDrawer} from '../common/drawer.js';
|
||||
import type {InlineInput} from '../measurables/inline_input.js';
|
||||
import type {Row} from '../measurables/row.js';
|
||||
@@ -49,9 +48,6 @@ export class Drawer extends BaseDrawer {
|
||||
if (this.info_.RTL) {
|
||||
pathObject.flipRTL();
|
||||
}
|
||||
if (debug.isDebuggerEnabled()) {
|
||||
this.block_?.renderingDebugger?.drawDebug(this.block_, this.info_);
|
||||
}
|
||||
this.recordSizeOnBlock_();
|
||||
if (this.info_.outputConnection) {
|
||||
// Store the output connection shape type for parent blocks to use during
|
||||
|
||||
106
core/touch.ts
106
core/touch.ts
@@ -8,19 +8,6 @@ import * as goog from '../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.Touch');
|
||||
|
||||
import type {Gesture} from './gesture.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
|
||||
/**
|
||||
* A mock event, created from either a mouse or touch event,
|
||||
* with no more than one entry in the changedTouches array.
|
||||
*/
|
||||
interface PseudoEvent {
|
||||
type: string;
|
||||
changedTouches: Touch[];
|
||||
target: Element;
|
||||
stopPropagation: () => void;
|
||||
preventDefault: () => void;
|
||||
}
|
||||
|
||||
/** Length in ms for a touch to become a long press. */
|
||||
const LONGPRESS = 750;
|
||||
@@ -167,96 +154,3 @@ export function checkTouchIdentifier(e: PointerEvent): boolean {
|
||||
// pointer was down.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an event's clientX and clientY from its first changed touch. Use this to
|
||||
* make a touch event work in a mouse event handler.
|
||||
*
|
||||
* @param e A touch event.
|
||||
*/
|
||||
export function setClientFromTouch(e: Event | PseudoEvent) {
|
||||
deprecation.warn('setClientFromTouch()', 'version 9', 'version 10');
|
||||
// AnyDuringMigration because: Property 'changedTouches' does not exist on
|
||||
// type 'PseudoEvent | Event'.
|
||||
if (e.type.startsWith('touch') && (e as AnyDuringMigration).changedTouches) {
|
||||
// Map the touch event's properties to the event.
|
||||
// AnyDuringMigration because: Property 'changedTouches' does not exist on
|
||||
// type 'PseudoEvent | Event'.
|
||||
const touchPoint = (e as AnyDuringMigration).changedTouches[0];
|
||||
// AnyDuringMigration because: Property 'clientX' does not exist on type
|
||||
// 'PseudoEvent | Event'.
|
||||
(e as AnyDuringMigration).clientX = touchPoint.clientX;
|
||||
// AnyDuringMigration because: Property 'clientY' does not exist on type
|
||||
// 'PseudoEvent | Event'.
|
||||
(e as AnyDuringMigration).clientY = touchPoint.clientY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given event is a mouse, touch, or pointer event.
|
||||
*
|
||||
* @param e An event.
|
||||
* @returns True if it is a mouse, touch, or pointer event; false otherwise.
|
||||
*/
|
||||
export function isMouseOrTouchEvent(e: Event | PseudoEvent): boolean {
|
||||
deprecation.warn('isMouseOrTouchEvent()', 'version 9', 'version 10');
|
||||
return (
|
||||
e.type.startsWith('touch') ||
|
||||
e.type.startsWith('mouse') ||
|
||||
e.type.startsWith('pointer')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given event is a touch event or a pointer event.
|
||||
*
|
||||
* @param e An event.
|
||||
* @returns True if it is a touch or pointer event; false otherwise.
|
||||
*/
|
||||
export function isTouchEvent(e: Event | PseudoEvent): boolean {
|
||||
deprecation.warn('isTouchEvent()', 'version 9', 'version 10');
|
||||
return e.type.startsWith('touch') || e.type.startsWith('pointer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Split an event into an array of events, one per changed touch or mouse
|
||||
* point.
|
||||
*
|
||||
* @param e A mouse event or a touch event with one or more changed touches.
|
||||
* @returns An array of events or pseudo events.
|
||||
* Each pseudo-touch event will have exactly one changed touch and there
|
||||
* will be no real touch events.
|
||||
*/
|
||||
export function splitEventByTouches(e: Event): Array<Event | PseudoEvent> {
|
||||
deprecation.warn('splitEventByTouches()', 'version 9', 'version 10');
|
||||
const events = [];
|
||||
// AnyDuringMigration because: Property 'changedTouches' does not exist on
|
||||
// type 'PseudoEvent | Event'.
|
||||
if ((e as AnyDuringMigration).changedTouches) {
|
||||
// AnyDuringMigration because: Property 'changedTouches' does not exist on
|
||||
// type 'PseudoEvent | Event'.
|
||||
for (let i = 0; i < (e as AnyDuringMigration).changedTouches.length; i++) {
|
||||
const newEvent = {
|
||||
type: e.type,
|
||||
// AnyDuringMigration because: Property 'changedTouches' does not exist
|
||||
// on type 'PseudoEvent | Event'.
|
||||
changedTouches: [(e as AnyDuringMigration).changedTouches[i]],
|
||||
target: e.target,
|
||||
stopPropagation() {
|
||||
e.stopPropagation();
|
||||
},
|
||||
preventDefault() {
|
||||
e.preventDefault();
|
||||
},
|
||||
};
|
||||
events[i] = newEvent;
|
||||
}
|
||||
} else {
|
||||
events.push(e);
|
||||
}
|
||||
// AnyDuringMigration because: Type '(Event | { type: string; changedTouches:
|
||||
// Touch[]; target: EventTarget | null; stopPropagation(): void;
|
||||
// preventDefault(): void; })[]' is not assignable to type '(PseudoEvent |
|
||||
// Event)[]'.
|
||||
return events as AnyDuringMigration;
|
||||
}
|
||||
|
||||
259
core/utils.ts
259
core/utils.ts
@@ -7,9 +7,7 @@
|
||||
import * as goog from '../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.utils');
|
||||
|
||||
import type {Block} from './block.js';
|
||||
import * as browserEvents from './browser_events.js';
|
||||
import * as common from './common.js';
|
||||
import * as extensions from './extensions.js';
|
||||
import * as aria from './utils/aria.js';
|
||||
import * as arrayUtils from './utils/array.js';
|
||||
@@ -33,7 +31,6 @@ import * as svgPaths from './utils/svg_paths.js';
|
||||
import * as toolbox from './utils/toolbox.js';
|
||||
import * as userAgent from './utils/useragent.js';
|
||||
import * as xml from './utils/xml.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
|
||||
export {
|
||||
aria,
|
||||
@@ -61,259 +58,3 @@ export {
|
||||
userAgent,
|
||||
xml,
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the coordinates of the top-left corner of this element relative to
|
||||
* its parent. Only for SVG elements and children (e.g. rect, g, path).
|
||||
*
|
||||
* @param element SVG element to find the coordinates of.
|
||||
* @returns Object with .x and .y properties.
|
||||
* @deprecated Use **Blockly.utils.svgMath.getRelativeXY** instead.
|
||||
*/
|
||||
export function getRelativeXY(element: Element): Coordinate {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.getRelativeXY',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.svgMath.getRelativeXY'
|
||||
);
|
||||
return svgMath.getRelativeXY(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinates of the top-left corner of this element relative to
|
||||
* the div Blockly was injected into.
|
||||
*
|
||||
* @param element SVG element to find the coordinates of. If this is not a child
|
||||
* of the div Blockly was injected into, the behaviour is undefined.
|
||||
* @returns Object with .x and .y properties.
|
||||
* @deprecated Use **Blockly.utils.svgMath.getInjectionDivXY** instead.
|
||||
*/
|
||||
function getInjectionDivXY(element: Element): Coordinate {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.getInjectionDivXY_',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.svgMath.getInjectionDivXY'
|
||||
);
|
||||
return svgMath.getInjectionDivXY(element);
|
||||
}
|
||||
export const getInjectionDivXY_ = getInjectionDivXY;
|
||||
|
||||
/**
|
||||
* Parse a string with any number of interpolation tokens (%1, %2, ...).
|
||||
* It will also replace string table references (e.g., %{bky_my_msg} and
|
||||
* %{BKY_MY_MSG} will both be replaced with the value in
|
||||
* Msg['MY_MSG']). Percentage sign characters '%' may be self-escaped
|
||||
* (e.g., '%%').
|
||||
*
|
||||
* @param message Text which might contain string table references and
|
||||
* interpolation tokens.
|
||||
* @returns Array of strings and numbers.
|
||||
* @deprecated Use **Blockly.utils.parsing.tokenizeInterpolation** instead.
|
||||
*/
|
||||
export function tokenizeInterpolation(message: string): Array<string | number> {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.tokenizeInterpolation',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.parsing.tokenizeInterpolation'
|
||||
);
|
||||
return parsing.tokenizeInterpolation(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces string table references in a message, if the message is a string.
|
||||
* For example, "%{bky_my_msg}" and "%{BKY_MY_MSG}" will both be replaced with
|
||||
* the value in Msg['MY_MSG'].
|
||||
*
|
||||
* @param message Message, which may be a string that contains string table
|
||||
* references.
|
||||
* @returns String with message references replaced.
|
||||
* @deprecated Use **Blockly.utils.parsing.replaceMessageReferences** instead.
|
||||
*/
|
||||
export function replaceMessageReferences(message: string | any): string {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.replaceMessageReferences',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.parsing.replaceMessageReferences'
|
||||
);
|
||||
return parsing.replaceMessageReferences(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that any %{MSG_KEY} references in the message refer to keys of
|
||||
* the Msg string table.
|
||||
*
|
||||
* @param message Text which might contain string table references.
|
||||
* @returns True if all message references have matching values.
|
||||
* Otherwise, false.
|
||||
* @deprecated Use **Blockly.utils.parsing.checkMessageReferences** instead.
|
||||
*/
|
||||
export function checkMessageReferences(message: string): boolean {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.checkMessageReferences',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.parsing.checkMessageReferences'
|
||||
);
|
||||
return parsing.checkMessageReferences(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if 3D transforms are supported by adding an element
|
||||
* and attempting to set the property.
|
||||
*
|
||||
* @returns True if 3D transforms are supported.
|
||||
* @deprecated Use **Blockly.utils.svgMath.is3dSupported** instead.
|
||||
*/
|
||||
export function is3dSupported(): boolean {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.is3dSupported',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.svgMath.is3dSupported'
|
||||
);
|
||||
return svgMath.is3dSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the current viewport in window coordinates. This takes
|
||||
* scroll into account.
|
||||
*
|
||||
* @returns An object containing window width, height, and scroll position in
|
||||
* window coordinates.
|
||||
* @deprecated Use **Blockly.utils.svgMath.getViewportBBox** instead.
|
||||
* @internal
|
||||
*/
|
||||
export function getViewportBBox(): Rect {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.getViewportBBox',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.svgMath.getViewportBBox'
|
||||
);
|
||||
return svgMath.getViewportBBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the first occurrence of a particular value from an array.
|
||||
*
|
||||
* @param arr Array from which to remove value.
|
||||
* @param value Value to remove.
|
||||
* @returns True if an element was removed.
|
||||
* @deprecated Use **Blockly.array.removeElem** instead.
|
||||
* @internal
|
||||
*/
|
||||
export function arrayRemove<T>(arr: Array<T>, value: T): boolean {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.arrayRemove',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.array.removeElem'
|
||||
);
|
||||
return arrayUtils.removeElem(arr, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the document scroll distance as a coordinate object.
|
||||
* Copied from Closure's goog.dom.getDocumentScroll.
|
||||
*
|
||||
* @returns Object with values 'x' and 'y'.
|
||||
* @deprecated Use **Blockly.utils.svgMath.getDocumentScroll** instead.
|
||||
*/
|
||||
export function getDocumentScroll(): Coordinate {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.getDocumentScroll',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.svgMath.getDocumentScroll'
|
||||
);
|
||||
return svgMath.getDocumentScroll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a map of all the block's descendants mapping their type to the number of
|
||||
* children with that type.
|
||||
*
|
||||
* @param block The block to map.
|
||||
* @param opt_stripFollowing Optionally ignore all following statements (blocks
|
||||
* that are not inside a value or statement input of the block).
|
||||
* @returns Map of types to type counts for descendants of the bock.
|
||||
* @deprecated Use **Blockly.common.getBlockTypeCounts** instead.
|
||||
*/
|
||||
export function getBlockTypeCounts(
|
||||
block: Block,
|
||||
opt_stripFollowing?: boolean
|
||||
): {[key: string]: number} {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.getBlockTypeCounts',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.common.getBlockTypeCounts'
|
||||
);
|
||||
return common.getBlockTypeCounts(block, opt_stripFollowing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts screen coordinates to workspace coordinates.
|
||||
*
|
||||
* @param ws The workspace to find the coordinates on.
|
||||
* @param screenCoordinates The screen coordinates to be converted to workspace
|
||||
* coordinates
|
||||
* @deprecated Use **Blockly.utils.svgMath.screenToWsCoordinates** instead.
|
||||
* @returns The workspace coordinates.
|
||||
*/
|
||||
export function screenToWsCoordinates(
|
||||
ws: WorkspaceSvg,
|
||||
screenCoordinates: Coordinate
|
||||
): Coordinate {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.screenToWsCoordinates',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.svgMath.screenToWsCoordinates'
|
||||
);
|
||||
return svgMath.screenToWsCoordinates(ws, screenCoordinates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a block colour from a number or string, as provided in a block
|
||||
* definition.
|
||||
*
|
||||
* @param colour HSV hue value (0 to 360), #RRGGBB string, or a message
|
||||
* reference string pointing to one of those two values.
|
||||
* @returns An object containing the colour as a #RRGGBB string, and the hue if
|
||||
* the input was an HSV hue value.
|
||||
* @throws {Error} If the colour cannot be parsed.
|
||||
* @deprecated Use **Blockly.utils.parsing.parseBlockColour** instead.
|
||||
*/
|
||||
export function parseBlockColour(colour: number | string): {
|
||||
hue: number | null;
|
||||
hex: string;
|
||||
} {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.parseBlockColour',
|
||||
'December 2021',
|
||||
'December 2022',
|
||||
'Blockly.utils.parsing.parseBlockColour'
|
||||
);
|
||||
return parsing.parseBlockColour(colour);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a function after the page has loaded, possibly immediately.
|
||||
*
|
||||
* @param fn Function to run.
|
||||
* @throws Error Will throw if no global document can be found (e.g., Node.js).
|
||||
* @deprecated No longer provided by Blockly.
|
||||
*/
|
||||
export function runAfterPageLoad(fn: () => void) {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.runAfterPageLoad',
|
||||
'December 2021',
|
||||
'December 2022'
|
||||
);
|
||||
extensions.runAfterPageLoad(fn);
|
||||
}
|
||||
|
||||
@@ -7,55 +7,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.utils.object');
|
||||
|
||||
import * as deprecation from './deprecation.js';
|
||||
|
||||
/**
|
||||
* Inherit the prototype methods from one constructor into another.
|
||||
*
|
||||
* @param childCtor Child class.
|
||||
* @param parentCtor Parent class.
|
||||
* @suppress {strictMissingProperties} superClass_ is not defined on Function.
|
||||
* @deprecated No longer provided by Blockly.
|
||||
*/
|
||||
export function inherits(childCtor: Function, parentCtor: Function) {
|
||||
deprecation.warn('Blockly.utils.object.inherits', 'version 9', 'version 10');
|
||||
// Set a .superClass_ property so that methods can call parent methods
|
||||
// without hard-coding the parent class name.
|
||||
// Could be replaced by ES6's super().
|
||||
// AnyDuringMigration because: Property 'superClass_' does not exist on type
|
||||
// 'Function'.
|
||||
(childCtor as AnyDuringMigration).superClass_ = parentCtor.prototype;
|
||||
|
||||
// Link the child class to the parent class so that static methods inherit.
|
||||
Object.setPrototypeOf(childCtor, parentCtor);
|
||||
|
||||
// Replace the child constructor's prototype object with an instance
|
||||
// of the parent class.
|
||||
childCtor.prototype = Object.create(parentCtor.prototype);
|
||||
childCtor.prototype.constructor = childCtor;
|
||||
}
|
||||
// Alternatively, one could use this instead:
|
||||
// Object.setPrototypeOf(childCtor.prototype, parentCtor.prototype);
|
||||
|
||||
/**
|
||||
* Copies all the members of a source object to a target object.
|
||||
*
|
||||
* @param target Target.
|
||||
* @param source Source.
|
||||
* @deprecated Use the built-in **Object.assign** instead.
|
||||
*/
|
||||
export function mixin(target: AnyDuringMigration, source: AnyDuringMigration) {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.object.mixin',
|
||||
'May 2022',
|
||||
'May 2023',
|
||||
'Object.assign'
|
||||
);
|
||||
for (const x in source) {
|
||||
target[x] = source[x];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete a deep merge of all members of a source object with a target object.
|
||||
*
|
||||
@@ -76,20 +27,3 @@ export function deepMerge(
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of a given object's own enumerable property values.
|
||||
*
|
||||
* @param obj Object containing values.
|
||||
* @returns Array of values.
|
||||
* @deprecated Use the built-in **Object.values** instead.
|
||||
*/
|
||||
export function values(obj: AnyDuringMigration): AnyDuringMigration[] {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.object.values',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Object.values'
|
||||
);
|
||||
return Object.values(obj);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.utils.style');
|
||||
|
||||
import * as deprecation from './deprecation.js';
|
||||
import {Coordinate} from './coordinate.js';
|
||||
import {Rect} from './rect.js';
|
||||
import {Size} from './size.js';
|
||||
@@ -86,31 +85,6 @@ export function getComputedStyle(element: Element, property: string): string {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cascaded style value of a node, or null if the value cannot be
|
||||
* computed (only Internet Explorer can do this).
|
||||
*
|
||||
* Copied from Closure's goog.style.getCascadedStyle
|
||||
*
|
||||
* @param element Element to get style of.
|
||||
* @param style Property to get (camel-case).
|
||||
* @returns Style value.
|
||||
* @deprecated No longer provided by Blockly.
|
||||
*/
|
||||
export function getCascadedStyle(element: Element, style: string): string {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.style.getCascadedStyle',
|
||||
'version 9',
|
||||
'version 10'
|
||||
);
|
||||
// AnyDuringMigration because: Property 'currentStyle' does not exist on type
|
||||
// 'Element'. AnyDuringMigration because: Property 'currentStyle' does not
|
||||
// exist on type 'Element'.
|
||||
return (element as AnyDuringMigration).currentStyle
|
||||
? (element as AnyDuringMigration).currentStyle[style]
|
||||
: ('' as string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Coordinate object relative to the top-left of the HTML document.
|
||||
* Similar to Closure's goog.style.getPageOffset
|
||||
|
||||
@@ -10,7 +10,6 @@ goog.declareModuleId('Blockly.utils.svgMath');
|
||||
import type {WorkspaceSvg} from '../workspace_svg.js';
|
||||
|
||||
import {Coordinate} from './coordinate.js';
|
||||
import * as deprecation from './deprecation.js';
|
||||
import {Rect} from './rect.js';
|
||||
import * as style from './style.js';
|
||||
|
||||
@@ -100,23 +99,6 @@ export function getInjectionDivXY(element: Element): Coordinate {
|
||||
return new Coordinate(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if 3D transforms are supported by adding an element
|
||||
* and attempting to set the property.
|
||||
*
|
||||
* @returns True if 3D transforms are supported.
|
||||
* @deprecated No longer provided by Blockly.
|
||||
*/
|
||||
export function is3dSupported(): boolean {
|
||||
// All browsers support translate3d in 2022.
|
||||
deprecation.warn(
|
||||
'Blockly.utils.svgMath.is3dSupported',
|
||||
'version 9',
|
||||
'version 10'
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the current viewport in window coordinates. This takes
|
||||
* scroll into account.
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
import * as goog from '../../closure/goog/goog.js';
|
||||
goog.declareModuleId('Blockly.utils.xml');
|
||||
|
||||
import * as deprecation from './deprecation.js';
|
||||
|
||||
let domParser: DOMParser = {
|
||||
parseFromString: function () {
|
||||
throw new Error(
|
||||
@@ -82,28 +80,6 @@ export const NAME_SPACE = 'https://developers.google.com/blockly/xml';
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const INVALID_CONTROL_CHARS = /[\x00-\x09\x0B\x0C\x0E-\x1F]/g;
|
||||
|
||||
/**
|
||||
* Get the document object to use for XML serialization.
|
||||
*
|
||||
* @returns The document object.
|
||||
* @deprecated No longer provided by Blockly.
|
||||
*/
|
||||
export function getDocument(): Document {
|
||||
deprecation.warn('Blockly.utils.xml.getDocument', 'version 9', 'version 10');
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the document object to use for XML serialization.
|
||||
*
|
||||
* @param xmlDocument The document object to use.
|
||||
* @deprecated No longer provided by Blockly.
|
||||
*/
|
||||
export function setDocument(xmlDocument: Document) {
|
||||
deprecation.warn('Blockly.utils.xml.setDocument', 'version 9', 'version 10');
|
||||
document = xmlDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create DOM element for XML.
|
||||
*
|
||||
@@ -164,22 +140,6 @@ export function textToDom(text: string): Element {
|
||||
throw new Error(`DOMParser was unable to parse: ${text}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an XML string into a DOM tree.
|
||||
*
|
||||
* @param text XML string.
|
||||
* @returns The DOM document.
|
||||
* @throws if XML doesn't parse.
|
||||
*/
|
||||
export function textToDomDocument(text: string): Document {
|
||||
deprecation.warn(
|
||||
'Blockly.utils.xml.textToDomDocument',
|
||||
'version 10',
|
||||
'version 11'
|
||||
);
|
||||
return domParser.parseFromString(text, 'text/xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a DOM structure into plain text.
|
||||
* Currently the text format is fairly ugly: all one line with no whitespace.
|
||||
|
||||
20
core/xml.ts
20
core/xml.ts
@@ -10,7 +10,6 @@ goog.declareModuleId('Blockly.Xml');
|
||||
import type {Block} from './block.js';
|
||||
import type {BlockSvg} from './block_svg.js';
|
||||
import type {Connection} from './connection.js';
|
||||
import * as deprecation from './utils/deprecation.js';
|
||||
import * as eventUtils from './events/utils.js';
|
||||
import type {Field} from './field.js';
|
||||
import {inputTypes} from './inputs/input_types.js';
|
||||
@@ -374,25 +373,6 @@ export function domToPrettyText(dom: Node): string {
|
||||
return text.replace(/^\n/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an XML string into a DOM structure.
|
||||
*
|
||||
* @param text An XML string.
|
||||
* @returns A DOM object representing the singular child of the document
|
||||
* element.
|
||||
* @throws if the text doesn't parse.
|
||||
* @deprecated Moved to core/utils/xml.js.
|
||||
*/
|
||||
export function textToDom(text: string): Element {
|
||||
deprecation.warn(
|
||||
'Blockly.Xml.textToDom',
|
||||
'version 9',
|
||||
'version 10',
|
||||
'Use Blockly.utils.xml.textToDom instead'
|
||||
);
|
||||
return utilsXml.textToDom(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the given workspace then decode an XML DOM and
|
||||
* create blocks on the workspace.
|
||||
|
||||
@@ -149,14 +149,14 @@ dartGenerator['unittest_adjustindex'] = function(block) {
|
||||
dartGenerator.ORDER_ADDITIVE) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
if (Blockly.utils.string.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, dartGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
} else if (Blockly.utils.string.isNumber(index)) {
|
||||
return [index, dartGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, dartGenerator.ORDER_ADDITIVE];
|
||||
|
||||
@@ -153,14 +153,14 @@ javascriptGenerator['unittest_adjustindex'] = function(block) {
|
||||
javascriptGenerator.ORDER_ADDITION) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
if (Blockly.utils.string.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, javascriptGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
} else if (Blockly.utils.string.isNumber(index)) {
|
||||
return [index, javascriptGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, javascriptGenerator.ORDER_ADDITION];
|
||||
|
||||
@@ -156,7 +156,7 @@ luaGenerator['unittest_fail'] = function(block) {
|
||||
luaGenerator['unittest_adjustindex'] = function(block) {
|
||||
var index = luaGenerator.valueToCode(block, 'INDEX',
|
||||
luaGenerator.ORDER_ADDITIVE) || '0';
|
||||
if (Blockly.isNumber(index)) {
|
||||
if (Blockly.utils.string.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, luaGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
@@ -140,14 +140,14 @@ phpGenerator['unittest_adjustindex'] = function(block) {
|
||||
phpGenerator.ORDER_ADDITION) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
if (Blockly.utils.string.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, phpGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
} else if (Blockly.utils.string.isNumber(index)) {
|
||||
return [index, phpGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, phpGenerator.ORDER_ADDITION];
|
||||
|
||||
@@ -124,14 +124,14 @@ pythonGenerator['unittest_adjustindex'] = function(block) {
|
||||
pythonGenerator.ORDER_ADDITIVE) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
if (Blockly.utils.string.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [Number(index) + 1, pythonGenerator.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
} else if (Blockly.utils.string.isNumber(index)) {
|
||||
return [index, pythonGenerator.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, pythonGenerator.ORDER_ADDITIVE];
|
||||
|
||||
@@ -111,26 +111,6 @@ suite('Events', function () {
|
||||
);
|
||||
});
|
||||
|
||||
test('Old UI event without block', function () {
|
||||
const TEST_GROUP_ID = 'testGroup';
|
||||
eventUtils.setGroup(TEST_GROUP_ID);
|
||||
const event = new Blockly.Events.Ui(null, 'foo', 'bar', 'baz');
|
||||
assertEventEquals(
|
||||
event,
|
||||
Blockly.Events.UI,
|
||||
'',
|
||||
null,
|
||||
{
|
||||
'element': 'foo',
|
||||
'oldValue': 'bar',
|
||||
'newValue': 'baz',
|
||||
'recordUndo': false,
|
||||
'group': TEST_GROUP_ID,
|
||||
},
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
suite('With simple blocks', function () {
|
||||
setup(function () {
|
||||
this.TEST_BLOCK_ID = 'test_block_id';
|
||||
@@ -182,27 +162,6 @@ suite('Events', function () {
|
||||
);
|
||||
});
|
||||
|
||||
test('Old UI event with block', function () {
|
||||
const TEST_GROUP_ID = 'testGroup';
|
||||
eventUtils.setGroup(TEST_GROUP_ID);
|
||||
const event = new Blockly.Events.Ui(this.block, 'foo', 'bar', 'baz');
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
assertEventEquals(
|
||||
event,
|
||||
Blockly.Events.UI,
|
||||
this.workspace.id,
|
||||
this.TEST_BLOCK_ID,
|
||||
{
|
||||
'element': 'foo',
|
||||
'oldValue': 'bar',
|
||||
'newValue': 'baz',
|
||||
'recordUndo': false,
|
||||
'group': TEST_GROUP_ID,
|
||||
},
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
test('Click with block', function () {
|
||||
const TEST_GROUP_ID = 'testGroup';
|
||||
eventUtils.setGroup(TEST_GROUP_ID);
|
||||
@@ -833,18 +792,6 @@ suite('Events', function () {
|
||||
}),
|
||||
},
|
||||
];
|
||||
const workspaceEventTestCases = [
|
||||
{
|
||||
title: 'Finished Loading',
|
||||
class: Blockly.Events.FinishedLoading,
|
||||
getArgs: (thisObj) => [thisObj.workspace],
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'finished_loading',
|
||||
group: '',
|
||||
workspaceId: thisObj.workspace.id,
|
||||
}),
|
||||
},
|
||||
];
|
||||
const workspaceCommentEventTestCases = [
|
||||
{
|
||||
title: 'Comment change',
|
||||
@@ -911,11 +858,6 @@ suite('Events', function () {
|
||||
thisObj.shadowBlock.setShadow(true);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Workspace events',
|
||||
testCases: workspaceEventTestCases,
|
||||
setup: (_) => {},
|
||||
},
|
||||
{
|
||||
title: 'WorkspaceComment events',
|
||||
testCases: workspaceCommentEventTestCases,
|
||||
@@ -1268,13 +1210,13 @@ suite('Events', function () {
|
||||
const block = this.workspace.newBlock('field_variable_test_block', '1');
|
||||
const events = [
|
||||
new Blockly.Events.Click(block),
|
||||
new Blockly.Events.Ui(block, 'stackclick', undefined, undefined),
|
||||
new Blockly.Events.BlockDrag(block, true),
|
||||
];
|
||||
const filteredEvents = eventUtils.filter(events, true);
|
||||
// click and stackclick should both exist
|
||||
chai.assert.equal(filteredEvents.length, 2);
|
||||
chai.assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
|
||||
chai.assert.equal(filteredEvents[1].element, 'stackclick');
|
||||
chai.assert.equal(filteredEvents[1].isStart, true);
|
||||
});
|
||||
|
||||
test('Merging null operations dropped', function () {
|
||||
|
||||
@@ -293,16 +293,6 @@ suite('Utils', function () {
|
||||
);
|
||||
});
|
||||
|
||||
test('arrayRemove', function () {
|
||||
const arr = [1, 2, 3, 2];
|
||||
chai.assert.isFalse(Blockly.utils.arrayRemove(arr, 0), 'Remove Not found');
|
||||
chai.assert.equal(arr.join(','), '1,2,3,2', 'Remove Not found result');
|
||||
chai.assert.isTrue(Blockly.utils.arrayRemove(arr, 2), 'Remove item');
|
||||
chai.assert.equal(arr.join(','), '1,3,2', 'Remove item result');
|
||||
chai.assert.isTrue(Blockly.utils.arrayRemove(arr, 2), 'Remove item again');
|
||||
chai.assert.equal(arr.join(','), '1,3', 'Remove item again result');
|
||||
});
|
||||
|
||||
test('XY_REGEX_', function () {
|
||||
const regex = Blockly.utils.svgMath.TEST_ONLY.XY_REGEX;
|
||||
let m;
|
||||
|
||||
Reference in New Issue
Block a user