mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
chore: Remove underscores from private fields. (#8682)
* chore: Remove underscores from private fields. * refactor: Use public APIs in tests where possible.
This commit is contained in:
126
core/block.ts
126
core/block.ts
@@ -89,7 +89,7 @@ export class Block implements IASTNodeLocation {
|
||||
* Colour of the block as HSV hue value (0-360)
|
||||
* This may be null if the block colour was not set via a hue number.
|
||||
*/
|
||||
private hue_: number | null = null;
|
||||
private hue: number | null = null;
|
||||
|
||||
/** Colour of the block in '#RRGGBB' format. */
|
||||
protected colour_ = '#000000';
|
||||
@@ -184,13 +184,13 @@ export class Block implements IASTNodeLocation {
|
||||
|
||||
protected childBlocks_: this[] = [];
|
||||
|
||||
private deletable_ = true;
|
||||
private deletable = true;
|
||||
|
||||
private movable_ = true;
|
||||
private movable = true;
|
||||
|
||||
private editable_ = true;
|
||||
private editable = true;
|
||||
|
||||
private isShadow_ = false;
|
||||
private shadow = false;
|
||||
|
||||
protected collapsed_ = false;
|
||||
protected outputShape_: number | null = null;
|
||||
@@ -207,7 +207,7 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
initialized = false;
|
||||
|
||||
private readonly xy_: Coordinate;
|
||||
private readonly xy: Coordinate;
|
||||
isInFlyout: boolean;
|
||||
isInMutator: boolean;
|
||||
RTL: boolean;
|
||||
@@ -227,7 +227,7 @@ export class Block implements IASTNodeLocation {
|
||||
helpUrl: string | (() => string) | null = null;
|
||||
|
||||
/** A bound callback function to use when the parent workspace changes. */
|
||||
private onchangeWrapper_: ((p1: Abstract) => void) | null = null;
|
||||
private onchangeWrapper: ((p1: Abstract) => void) | null = null;
|
||||
|
||||
/**
|
||||
* A count of statement inputs on the block.
|
||||
@@ -260,7 +260,7 @@ export class Block implements IASTNodeLocation {
|
||||
* The block's position in workspace units. (0, 0) is at the workspace's
|
||||
* origin; scale does not change this value.
|
||||
*/
|
||||
this.xy_ = new Coordinate(0, 0);
|
||||
this.xy = new Coordinate(0, 0);
|
||||
this.isInFlyout = workspace.isFlyout;
|
||||
this.isInMutator = workspace.isMutator;
|
||||
|
||||
@@ -333,8 +333,8 @@ export class Block implements IASTNodeLocation {
|
||||
// Dispose of this change listener before unplugging.
|
||||
// Technically not necessary due to the event firing delay.
|
||||
// But future-proofing.
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
if (this.onchangeWrapper) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper);
|
||||
}
|
||||
|
||||
this.unplug(healStack);
|
||||
@@ -352,8 +352,8 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
protected disposeInternal() {
|
||||
this.disposing = true;
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
if (this.onchangeWrapper) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper);
|
||||
}
|
||||
|
||||
this.workspace.removeTypedBlock(this);
|
||||
@@ -403,10 +403,10 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
unplug(opt_healStack?: boolean) {
|
||||
if (this.outputConnection) {
|
||||
this.unplugFromRow_(opt_healStack);
|
||||
this.unplugFromRow(opt_healStack);
|
||||
}
|
||||
if (this.previousConnection) {
|
||||
this.unplugFromStack_(opt_healStack);
|
||||
this.unplugFromStack(opt_healStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param opt_healStack Disconnect right-side block and connect to left-side
|
||||
* block. Defaults to false.
|
||||
*/
|
||||
private unplugFromRow_(opt_healStack?: boolean) {
|
||||
private unplugFromRow(opt_healStack?: boolean) {
|
||||
let parentConnection = null;
|
||||
if (this.outputConnection?.isConnected()) {
|
||||
parentConnection = this.outputConnection.targetConnection;
|
||||
@@ -430,7 +430,7 @@ export class Block implements IASTNodeLocation {
|
||||
return;
|
||||
}
|
||||
|
||||
const thisConnection = this.getOnlyValueConnection_();
|
||||
const thisConnection = this.getOnlyValueConnection();
|
||||
if (
|
||||
!thisConnection ||
|
||||
!thisConnection.isConnected() ||
|
||||
@@ -467,7 +467,7 @@ export class Block implements IASTNodeLocation {
|
||||
*
|
||||
* @returns The connection on the value input, or null.
|
||||
*/
|
||||
private getOnlyValueConnection_(): Connection | null {
|
||||
private getOnlyValueConnection(): Connection | null {
|
||||
let connection = null;
|
||||
for (let i = 0; i < this.inputList.length; i++) {
|
||||
const thisConnection = this.inputList[i].connection;
|
||||
@@ -492,7 +492,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param opt_healStack Disconnect child statement and reconnect stack.
|
||||
* Defaults to false.
|
||||
*/
|
||||
private unplugFromStack_(opt_healStack?: boolean) {
|
||||
private unplugFromStack(opt_healStack?: boolean) {
|
||||
let previousTarget = null;
|
||||
if (this.previousConnection?.isConnected()) {
|
||||
// Remember the connection that any next statements need to connect to.
|
||||
@@ -789,8 +789,8 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
isDeletable(): boolean {
|
||||
return (
|
||||
this.deletable_ &&
|
||||
!this.isShadow_ &&
|
||||
this.deletable &&
|
||||
!this.shadow &&
|
||||
!this.isDeadOrDying() &&
|
||||
!this.workspace.options.readOnly
|
||||
);
|
||||
@@ -802,7 +802,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns True if the block's deletable property is true, false otherwise.
|
||||
*/
|
||||
isOwnDeletable(): boolean {
|
||||
return this.deletable_;
|
||||
return this.deletable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -811,7 +811,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param deletable True if deletable.
|
||||
*/
|
||||
setDeletable(deletable: boolean) {
|
||||
this.deletable_ = deletable;
|
||||
this.deletable = deletable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -822,8 +822,8 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
isMovable(): boolean {
|
||||
return (
|
||||
this.movable_ &&
|
||||
!this.isShadow_ &&
|
||||
this.movable &&
|
||||
!this.shadow &&
|
||||
!this.isDeadOrDying() &&
|
||||
!this.workspace.options.readOnly
|
||||
);
|
||||
@@ -836,7 +836,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @internal
|
||||
*/
|
||||
isOwnMovable(): boolean {
|
||||
return this.movable_;
|
||||
return this.movable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -845,7 +845,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param movable True if movable.
|
||||
*/
|
||||
setMovable(movable: boolean) {
|
||||
this.movable_ = movable;
|
||||
this.movable = movable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -871,7 +871,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns True if a shadow.
|
||||
*/
|
||||
isShadow(): boolean {
|
||||
return this.isShadow_;
|
||||
return this.shadow;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -883,7 +883,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @internal
|
||||
*/
|
||||
setShadow(shadow: boolean) {
|
||||
this.isShadow_ = shadow;
|
||||
this.shadow = shadow;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -914,9 +914,7 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
isEditable(): boolean {
|
||||
return (
|
||||
this.editable_ &&
|
||||
!this.isDeadOrDying() &&
|
||||
!this.workspace.options.readOnly
|
||||
this.editable && !this.isDeadOrDying() && !this.workspace.options.readOnly
|
||||
);
|
||||
}
|
||||
|
||||
@@ -926,7 +924,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns True if the block's editable property is true, false otherwise.
|
||||
*/
|
||||
isOwnEditable(): boolean {
|
||||
return this.editable_;
|
||||
return this.editable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -935,7 +933,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param editable True if editable.
|
||||
*/
|
||||
setEditable(editable: boolean) {
|
||||
this.editable_ = editable;
|
||||
this.editable = editable;
|
||||
for (let i = 0, input; (input = this.inputList[i]); i++) {
|
||||
for (let j = 0, field; (field = input.fieldRow[j]); j++) {
|
||||
field.updateEditable();
|
||||
@@ -1046,7 +1044,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns Hue value (0-360).
|
||||
*/
|
||||
getHue(): number | null {
|
||||
return this.hue_;
|
||||
return this.hue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1057,7 +1055,7 @@ export class Block implements IASTNodeLocation {
|
||||
*/
|
||||
setColour(colour: number | string) {
|
||||
const parsed = parsing.parseBlockColour(colour);
|
||||
this.hue_ = parsed.hue;
|
||||
this.hue = parsed.hue;
|
||||
this.colour_ = parsed.hex;
|
||||
}
|
||||
|
||||
@@ -1083,12 +1081,12 @@ export class Block implements IASTNodeLocation {
|
||||
if (onchangeFn && typeof onchangeFn !== 'function') {
|
||||
throw Error('onchange must be a function.');
|
||||
}
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
if (this.onchangeWrapper) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper);
|
||||
}
|
||||
this.onchange = onchangeFn;
|
||||
this.onchangeWrapper_ = onchangeFn.bind(this);
|
||||
this.workspace.addChangeListener(this.onchangeWrapper_);
|
||||
this.onchangeWrapper = onchangeFn.bind(this);
|
||||
this.workspace.addChangeListener(this.onchangeWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1774,15 +1772,15 @@ export class Block implements IASTNodeLocation {
|
||||
if (json['style'] && json['colour']) {
|
||||
throw Error(warningPrefix + 'Must not have both a colour and a style.');
|
||||
} else if (json['style']) {
|
||||
this.jsonInitStyle_(json, warningPrefix);
|
||||
this.jsonInitStyle(json, warningPrefix);
|
||||
} else {
|
||||
this.jsonInitColour_(json, warningPrefix);
|
||||
this.jsonInitColour(json, warningPrefix);
|
||||
}
|
||||
|
||||
// Interpolate the message blocks.
|
||||
let i = 0;
|
||||
while (json['message' + i] !== undefined) {
|
||||
this.interpolate_(
|
||||
this.interpolate(
|
||||
json['message' + i],
|
||||
json['args' + i] || [],
|
||||
// Backwards compatibility: lastDummyAlign aliases implicitAlign.
|
||||
@@ -1857,7 +1855,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param json Structured data describing the block.
|
||||
* @param warningPrefix Warning prefix string identifying block.
|
||||
*/
|
||||
private jsonInitColour_(json: AnyDuringMigration, warningPrefix: string) {
|
||||
private jsonInitColour(json: AnyDuringMigration, warningPrefix: string) {
|
||||
if ('colour' in json) {
|
||||
if (json['colour'] === undefined) {
|
||||
console.warn(warningPrefix + 'Undefined colour value.');
|
||||
@@ -1878,7 +1876,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param json Structured data describing the block.
|
||||
* @param warningPrefix Warning prefix string identifying block.
|
||||
*/
|
||||
private jsonInitStyle_(json: AnyDuringMigration, warningPrefix: string) {
|
||||
private jsonInitStyle(json: AnyDuringMigration, warningPrefix: string) {
|
||||
const blockStyleName = json['style'];
|
||||
try {
|
||||
this.setStyle(blockStyleName);
|
||||
@@ -1930,21 +1928,21 @@ export class Block implements IASTNodeLocation {
|
||||
* of newline tokens, how should it be aligned?
|
||||
* @param warningPrefix Warning prefix string identifying block.
|
||||
*/
|
||||
private interpolate_(
|
||||
private interpolate(
|
||||
message: string,
|
||||
args: AnyDuringMigration[],
|
||||
implicitAlign: string | undefined,
|
||||
warningPrefix: string,
|
||||
) {
|
||||
const tokens = parsing.tokenizeInterpolation(message);
|
||||
this.validateTokens_(tokens, args.length);
|
||||
const elements = this.interpolateArguments_(tokens, args, implicitAlign);
|
||||
this.validateTokens(tokens, args.length);
|
||||
const elements = this.interpolateArguments(tokens, args, implicitAlign);
|
||||
|
||||
// An array of [field, fieldName] tuples.
|
||||
const fieldStack = [];
|
||||
for (let i = 0, element; (element = elements[i]); i++) {
|
||||
if (this.isInputKeyword_(element['type'])) {
|
||||
const input = this.inputFromJson_(element, warningPrefix);
|
||||
if (this.isInputKeyword(element['type'])) {
|
||||
const input = this.inputFromJson(element, warningPrefix);
|
||||
// Should never be null, but just in case.
|
||||
if (input) {
|
||||
for (let j = 0, tuple; (tuple = fieldStack[j]); j++) {
|
||||
@@ -1955,7 +1953,7 @@ export class Block implements IASTNodeLocation {
|
||||
} else {
|
||||
// All other types, including ones starting with 'input_' get routed
|
||||
// here.
|
||||
const field = this.fieldFromJson_(element);
|
||||
const field = this.fieldFromJson(element);
|
||||
if (field) {
|
||||
fieldStack.push([field, element['name']]);
|
||||
}
|
||||
@@ -1971,7 +1969,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param tokens An array of tokens to validate
|
||||
* @param argsCount The number of args that need to be referred to.
|
||||
*/
|
||||
private validateTokens_(tokens: Array<string | number>, argsCount: number) {
|
||||
private validateTokens(tokens: Array<string | number>, argsCount: number) {
|
||||
const visitedArgsHash = [];
|
||||
let visitedArgsCount = 0;
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
@@ -2026,7 +2024,7 @@ export class Block implements IASTNodeLocation {
|
||||
* or dummy inputs, if necessary.
|
||||
* @returns The JSON definitions of field and inputs to add to the block.
|
||||
*/
|
||||
private interpolateArguments_(
|
||||
private interpolateArguments(
|
||||
tokens: Array<string | number>,
|
||||
args: Array<AnyDuringMigration | string>,
|
||||
implicitAlign: string | undefined,
|
||||
@@ -2049,7 +2047,7 @@ export class Block implements IASTNodeLocation {
|
||||
} else {
|
||||
// AnyDuringMigration because: Type '{ text: string; type: string; }
|
||||
// | null' is not assignable to type 'string | number'.
|
||||
element = this.stringToFieldJson_(element) as AnyDuringMigration;
|
||||
element = this.stringToFieldJson(element) as AnyDuringMigration;
|
||||
if (!element) {
|
||||
continue;
|
||||
}
|
||||
@@ -2061,9 +2059,7 @@ export class Block implements IASTNodeLocation {
|
||||
const length = elements.length;
|
||||
if (
|
||||
length &&
|
||||
!this.isInputKeyword_(
|
||||
(elements as AnyDuringMigration)[length - 1]['type'],
|
||||
)
|
||||
!this.isInputKeyword((elements as AnyDuringMigration)[length - 1]['type'])
|
||||
) {
|
||||
const dummyInput = {'type': 'input_dummy'};
|
||||
if (implicitAlign) {
|
||||
@@ -2083,7 +2079,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param element The element to try to turn into a field.
|
||||
* @returns The field defined by the JSON, or null if one couldn't be created.
|
||||
*/
|
||||
private fieldFromJson_(element: {
|
||||
private fieldFromJson(element: {
|
||||
alt?: string;
|
||||
type: string;
|
||||
text?: string;
|
||||
@@ -2091,10 +2087,10 @@ export class Block implements IASTNodeLocation {
|
||||
const field = fieldRegistry.fromJson(element);
|
||||
if (!field && element['alt']) {
|
||||
if (typeof element['alt'] === 'string') {
|
||||
const json = this.stringToFieldJson_(element['alt']);
|
||||
return json ? this.fieldFromJson_(json) : null;
|
||||
const json = this.stringToFieldJson(element['alt']);
|
||||
return json ? this.fieldFromJson(json) : null;
|
||||
}
|
||||
return this.fieldFromJson_(element['alt']);
|
||||
return this.fieldFromJson(element['alt']);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
@@ -2109,7 +2105,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns The input that has been created, or null if one could not be
|
||||
* created for some reason (should never happen).
|
||||
*/
|
||||
private inputFromJson_(
|
||||
private inputFromJson(
|
||||
element: AnyDuringMigration,
|
||||
warningPrefix: string,
|
||||
): Input | null {
|
||||
@@ -2167,7 +2163,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns True if the given string matches one of the input keywords, false
|
||||
* otherwise.
|
||||
*/
|
||||
private isInputKeyword_(str: string): boolean {
|
||||
private isInputKeyword(str: string): boolean {
|
||||
return (
|
||||
str === 'input_value' ||
|
||||
str === 'input_statement' ||
|
||||
@@ -2184,7 +2180,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @param str String to turn into the JSON definition of a label field.
|
||||
* @returns The JSON definition or null.
|
||||
*/
|
||||
private stringToFieldJson_(str: string): {text: string; type: string} | null {
|
||||
private stringToFieldJson(str: string): {text: string; type: string} | null {
|
||||
str = str.trim();
|
||||
if (str) {
|
||||
return {
|
||||
@@ -2445,7 +2441,7 @@ export class Block implements IASTNodeLocation {
|
||||
* @returns Object with .x and .y properties.
|
||||
*/
|
||||
getRelativeToSurfaceXY(): Coordinate {
|
||||
return this.xy_;
|
||||
return this.xy;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2461,7 +2457,7 @@ export class Block implements IASTNodeLocation {
|
||||
}
|
||||
const event = new (eventUtils.get(EventType.BLOCK_MOVE))(this) as BlockMove;
|
||||
if (reason) event.setReason(reason);
|
||||
this.xy_.translate(dx, dy);
|
||||
this.xy.translate(dx, dy);
|
||||
event.recordNew();
|
||||
eventUtils.fire(event);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ export class BlockSvg
|
||||
/** Block's mutator icon (if any). */
|
||||
mutator: MutatorIcon | null = null;
|
||||
|
||||
private svgGroup_: SVGGElement;
|
||||
private svgGroup: SVGGElement;
|
||||
style: BlockStyle;
|
||||
/** @internal */
|
||||
pathObject: IPathObject;
|
||||
@@ -155,15 +155,6 @@ export class BlockSvg
|
||||
|
||||
private visuallyDisabled = false;
|
||||
|
||||
/**
|
||||
* Is this block currently rendering? Used to stop recursive render calls
|
||||
* from actually triggering a re-render.
|
||||
*/
|
||||
private renderIsInProgress_ = false;
|
||||
|
||||
/** Whether mousedown events have been bound yet. */
|
||||
private eventsInit_ = false;
|
||||
|
||||
override workspace: WorkspaceSvg;
|
||||
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
||||
override outputConnection!: RenderedConnection;
|
||||
@@ -201,7 +192,7 @@ export class BlockSvg
|
||||
throw TypeError('Cannot create a rendered block in a headless workspace');
|
||||
}
|
||||
this.workspace = workspace;
|
||||
this.svgGroup_ = dom.createSvgElement(Svg.G, {});
|
||||
this.svgGroup = dom.createSvgElement(Svg.G, {});
|
||||
|
||||
/** A block style object. */
|
||||
this.style = workspace.getRenderer().getConstants().getBlockStyle(null);
|
||||
@@ -209,14 +200,14 @@ export class BlockSvg
|
||||
/** The renderer's path object. */
|
||||
this.pathObject = workspace
|
||||
.getRenderer()
|
||||
.makePathObject(this.svgGroup_, this.style);
|
||||
.makePathObject(this.svgGroup, this.style);
|
||||
|
||||
const svgPath = this.pathObject.svgPath;
|
||||
(svgPath as any).tooltip = this;
|
||||
Tooltip.bindMouseEvents(svgPath);
|
||||
|
||||
// Expose this block's ID on its top-level SVG group.
|
||||
this.svgGroup_.setAttribute('data-id', this.id);
|
||||
this.svgGroup.setAttribute('data-id', this.id);
|
||||
|
||||
this.doInit_();
|
||||
}
|
||||
@@ -238,12 +229,7 @@ export class BlockSvg
|
||||
this.pathObject.updateMovable(this.isMovable() || this.isInFlyout);
|
||||
const svg = this.getSvgRoot();
|
||||
if (!this.workspace.options.readOnly && svg) {
|
||||
browserEvents.conditionalBind(
|
||||
svg,
|
||||
'pointerdown',
|
||||
this,
|
||||
this.onMouseDown_,
|
||||
);
|
||||
browserEvents.conditionalBind(svg, 'pointerdown', this, this.onMouseDown);
|
||||
}
|
||||
|
||||
if (!svg.parentNode) {
|
||||
@@ -518,14 +504,14 @@ export class BlockSvg
|
||||
return;
|
||||
}
|
||||
super.setCollapsed(collapsed);
|
||||
this.updateCollapsed_();
|
||||
this.updateCollapsed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure that when the block is collapsed, it is rendered correctly
|
||||
* for that state.
|
||||
*/
|
||||
private updateCollapsed_() {
|
||||
private updateCollapsed() {
|
||||
const collapsed = this.isCollapsed();
|
||||
const collapsedInputName = constants.COLLAPSED_INPUT_NAME;
|
||||
const collapsedFieldName = constants.COLLAPSED_FIELD_NAME;
|
||||
@@ -592,7 +578,7 @@ export class BlockSvg
|
||||
*
|
||||
* @param e Pointer down event.
|
||||
*/
|
||||
private onMouseDown_(e: PointerEvent) {
|
||||
private onMouseDown(e: PointerEvent) {
|
||||
const gesture = this.workspace.getGesture(e);
|
||||
if (gesture) {
|
||||
gesture.handleBlockStart(e, this);
|
||||
@@ -702,10 +688,10 @@ export class BlockSvg
|
||||
if (adding) {
|
||||
this.translation = '';
|
||||
common.draggingConnections.push(...this.getConnections_(true));
|
||||
dom.addClass(this.svgGroup_, 'blocklyDragging');
|
||||
dom.addClass(this.svgGroup, 'blocklyDragging');
|
||||
} else {
|
||||
common.draggingConnections.length = 0;
|
||||
dom.removeClass(this.svgGroup_, 'blocklyDragging');
|
||||
dom.removeClass(this.svgGroup, 'blocklyDragging');
|
||||
}
|
||||
// Recurse through all blocks attached under this one.
|
||||
for (let i = 0; i < this.childBlocks_.length; i++) {
|
||||
@@ -775,7 +761,7 @@ export class BlockSvg
|
||||
* @returns The root SVG node (probably a group).
|
||||
*/
|
||||
getSvgRoot(): SVGGElement {
|
||||
return this.svgGroup_;
|
||||
return this.svgGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -817,7 +803,7 @@ export class BlockSvg
|
||||
}
|
||||
|
||||
super.dispose(!!healStack);
|
||||
dom.removeNode(this.svgGroup_);
|
||||
dom.removeNode(this.svgGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1565,7 +1551,7 @@ export class BlockSvg
|
||||
dom.startTextWidthCache();
|
||||
|
||||
if (this.isCollapsed()) {
|
||||
this.updateCollapsed_();
|
||||
this.updateCollapsed();
|
||||
}
|
||||
|
||||
if (!this.isEnabled()) {
|
||||
|
||||
@@ -23,10 +23,10 @@ class Capability<_T> {
|
||||
static DRAG_TARGET = new Capability<IDragTarget>('drag_target');
|
||||
static DELETE_AREA = new Capability<IDeleteArea>('delete_area');
|
||||
static AUTOHIDEABLE = new Capability<IAutoHideable>('autohideable');
|
||||
private readonly name_: string;
|
||||
private readonly name: string;
|
||||
/** @param name The name of the component capability. */
|
||||
constructor(name: string) {
|
||||
this.name_ = name;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ class Capability<_T> {
|
||||
* @returns The name.
|
||||
*/
|
||||
toString(): string {
|
||||
return this.name_;
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
export class ContextMenuRegistry {
|
||||
static registry: ContextMenuRegistry;
|
||||
/** Registry of all registered RegistryItems, keyed by ID. */
|
||||
private registry_ = new Map<string, RegistryItem>();
|
||||
private registeredItems = new Map<string, RegistryItem>();
|
||||
|
||||
/** Resets the existing singleton instance of ContextMenuRegistry. */
|
||||
constructor() {
|
||||
@@ -32,7 +32,7 @@ export class ContextMenuRegistry {
|
||||
|
||||
/** Clear and recreate the registry. */
|
||||
reset() {
|
||||
this.registry_.clear();
|
||||
this.registeredItems.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,10 +42,10 @@ export class ContextMenuRegistry {
|
||||
* @throws {Error} if an item with the given ID already exists.
|
||||
*/
|
||||
register(item: RegistryItem) {
|
||||
if (this.registry_.has(item.id)) {
|
||||
if (this.registeredItems.has(item.id)) {
|
||||
throw Error('Menu item with ID "' + item.id + '" is already registered.');
|
||||
}
|
||||
this.registry_.set(item.id, item);
|
||||
this.registeredItems.set(item.id, item);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,10 +55,10 @@ export class ContextMenuRegistry {
|
||||
* @throws {Error} if an item with the given ID does not exist.
|
||||
*/
|
||||
unregister(id: string) {
|
||||
if (!this.registry_.has(id)) {
|
||||
if (!this.registeredItems.has(id)) {
|
||||
throw new Error('Menu item with ID "' + id + '" not found.');
|
||||
}
|
||||
this.registry_.delete(id);
|
||||
this.registeredItems.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ export class ContextMenuRegistry {
|
||||
* @returns RegistryItem or null if not found
|
||||
*/
|
||||
getItem(id: string): RegistryItem | null {
|
||||
return this.registry_.get(id) ?? null;
|
||||
return this.registeredItems.get(id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ export class ContextMenuRegistry {
|
||||
scope: Scope,
|
||||
): ContextMenuOption[] {
|
||||
const menuOptions: ContextMenuOption[] = [];
|
||||
for (const item of this.registry_.values()) {
|
||||
for (const item of this.registeredItems.values()) {
|
||||
if (scopeType === item.scopeType) {
|
||||
const precondition = item.preconditionFn(scope);
|
||||
if (precondition !== 'hidden') {
|
||||
|
||||
@@ -89,7 +89,7 @@ export class BlockMove extends BlockBase {
|
||||
this.recordUndo = false;
|
||||
}
|
||||
|
||||
const location = this.currentLocation_();
|
||||
const location = this.currentLocation();
|
||||
this.oldParentId = location.parentId;
|
||||
this.oldInputName = location.inputName;
|
||||
this.oldCoordinate = location.coordinate;
|
||||
@@ -167,7 +167,7 @@ export class BlockMove extends BlockBase {
|
||||
|
||||
/** Record the block's new location. Called after the move. */
|
||||
recordNew() {
|
||||
const location = this.currentLocation_();
|
||||
const location = this.currentLocation();
|
||||
this.newParentId = location.parentId;
|
||||
this.newInputName = location.inputName;
|
||||
this.newCoordinate = location.coordinate;
|
||||
@@ -188,7 +188,7 @@ export class BlockMove extends BlockBase {
|
||||
*
|
||||
* @returns Collection of location info.
|
||||
*/
|
||||
private currentLocation_(): BlockLocation {
|
||||
private currentLocation(): BlockLocation {
|
||||
const workspace = this.getEventWorkspace_();
|
||||
if (!this.blockId) {
|
||||
throw new Error(
|
||||
|
||||
@@ -107,20 +107,20 @@ export abstract class Field<T = any>
|
||||
* Used to cache the field's tooltip value if setTooltip is called when the
|
||||
* field is not yet initialized. Is *not* guaranteed to be accurate.
|
||||
*/
|
||||
private tooltip_: Tooltip.TipInfo | null = null;
|
||||
private tooltip: Tooltip.TipInfo | null = null;
|
||||
protected size_: Size;
|
||||
|
||||
/**
|
||||
* Holds the cursors svg element when the cursor is attached to the field.
|
||||
* This is null if there is no cursor on the field.
|
||||
*/
|
||||
private cursorSvg_: SVGElement | null = null;
|
||||
private cursorSvg: SVGElement | null = null;
|
||||
|
||||
/**
|
||||
* Holds the markers svg element when the marker is attached to the field.
|
||||
* This is null if there is no marker on the field.
|
||||
*/
|
||||
private markerSvg_: SVGElement | null = null;
|
||||
private markerSvg: SVGElement | null = null;
|
||||
|
||||
/** The rendered field's SVG group element. */
|
||||
protected fieldGroup_: SVGGElement | null = null;
|
||||
@@ -135,7 +135,7 @@ export abstract class Field<T = any>
|
||||
protected textContent_: Text | null = null;
|
||||
|
||||
/** Mouse down event listener data. */
|
||||
private mouseDownWrapper_: browserEvents.Data | null = null;
|
||||
private mouseDownWrapper: browserEvents.Data | null = null;
|
||||
|
||||
/** Constants associated with the source block's renderer. */
|
||||
protected constants_: ConstantProvider | null = null;
|
||||
@@ -312,7 +312,7 @@ export abstract class Field<T = any>
|
||||
sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_);
|
||||
this.initView();
|
||||
this.updateEditable();
|
||||
this.setTooltip(this.tooltip_);
|
||||
this.setTooltip(this.tooltip);
|
||||
this.bindEvents_();
|
||||
this.initModel();
|
||||
this.applyColour();
|
||||
@@ -393,7 +393,7 @@ export abstract class Field<T = any>
|
||||
const clickTarget = this.getClickTarget_();
|
||||
if (!clickTarget) throw new Error('A click target has not been set.');
|
||||
Tooltip.bindMouseEvents(clickTarget);
|
||||
this.mouseDownWrapper_ = browserEvents.conditionalBind(
|
||||
this.mouseDownWrapper = browserEvents.conditionalBind(
|
||||
clickTarget,
|
||||
'pointerdown',
|
||||
this,
|
||||
@@ -1095,7 +1095,7 @@ export abstract class Field<T = any>
|
||||
|
||||
try {
|
||||
const classValidation = this.doClassValidation_(newValue);
|
||||
const classValue = this.processValidation_(
|
||||
const classValue = this.processValidation(
|
||||
newValue,
|
||||
classValidation,
|
||||
fireChangeEvent,
|
||||
@@ -1106,7 +1106,7 @@ export abstract class Field<T = any>
|
||||
}
|
||||
|
||||
const localValidation = this.getValidator()?.call(this, classValue);
|
||||
const localValue = this.processValidation_(
|
||||
const localValue = this.processValidation(
|
||||
classValue,
|
||||
localValidation,
|
||||
fireChangeEvent,
|
||||
@@ -1158,7 +1158,7 @@ export abstract class Field<T = any>
|
||||
* @param fireChangeEvent Whether to fire a change event if the value changes.
|
||||
* @returns New value, or an Error object.
|
||||
*/
|
||||
private processValidation_(
|
||||
private processValidation(
|
||||
newValue: AnyDuringMigration,
|
||||
validatedValue: T | null | undefined,
|
||||
fireChangeEvent: boolean,
|
||||
@@ -1272,7 +1272,7 @@ export abstract class Field<T = any>
|
||||
(clickTarget as AnyDuringMigration).tooltip = newTip;
|
||||
} else {
|
||||
// Field has not been initialized yet.
|
||||
this.tooltip_ = newTip;
|
||||
this.tooltip = newTip;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1286,8 +1286,8 @@ export abstract class Field<T = any>
|
||||
if (clickTarget) {
|
||||
return Tooltip.getTooltipOfObject(clickTarget);
|
||||
}
|
||||
// Field has not been initialized yet. Return stashed this.tooltip_ value.
|
||||
return Tooltip.getTooltipOfObject({tooltip: this.tooltip_});
|
||||
// Field has not been initialized yet. Return stashed this.tooltip value.
|
||||
return Tooltip.getTooltipOfObject({tooltip: this.tooltip});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1396,7 +1396,7 @@ export abstract class Field<T = any>
|
||||
*/
|
||||
setCursorSvg(cursorSvg: SVGElement) {
|
||||
if (!cursorSvg) {
|
||||
this.cursorSvg_ = null;
|
||||
this.cursorSvg = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1404,7 +1404,7 @@ export abstract class Field<T = any>
|
||||
throw new Error(`The field group is ${this.fieldGroup_}.`);
|
||||
}
|
||||
this.fieldGroup_.appendChild(cursorSvg);
|
||||
this.cursorSvg_ = cursorSvg;
|
||||
this.cursorSvg = cursorSvg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1415,7 +1415,7 @@ export abstract class Field<T = any>
|
||||
*/
|
||||
setMarkerSvg(markerSvg: SVGElement) {
|
||||
if (!markerSvg) {
|
||||
this.markerSvg_ = null;
|
||||
this.markerSvg = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1423,7 +1423,7 @@ export abstract class Field<T = any>
|
||||
throw new Error(`The field group is ${this.fieldGroup_}.`);
|
||||
}
|
||||
this.fieldGroup_.appendChild(markerSvg);
|
||||
this.markerSvg_ = markerSvg;
|
||||
this.markerSvg = markerSvg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1437,10 +1437,10 @@ export abstract class Field<T = any>
|
||||
throw new UnattachedFieldError();
|
||||
}
|
||||
const workspace = block.workspace as WorkspaceSvg;
|
||||
if (workspace.keyboardAccessibilityMode && this.cursorSvg_) {
|
||||
if (workspace.keyboardAccessibilityMode && this.cursorSvg) {
|
||||
workspace.getCursor()!.draw();
|
||||
}
|
||||
if (workspace.keyboardAccessibilityMode && this.markerSvg_) {
|
||||
if (workspace.keyboardAccessibilityMode && this.markerSvg) {
|
||||
// TODO(#4592): Update all markers on the field.
|
||||
workspace.getMarker(MarkerManager.LOCAL_MARKER)!.draw();
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ export class FieldCheckbox extends Field<CheckboxBool> {
|
||||
* that this is a either 'TRUE' or 'FALSE'.
|
||||
*/
|
||||
protected override doValueUpdate_(newValue: BoolString) {
|
||||
this.value_ = this.convertValueToBool_(newValue);
|
||||
this.value_ = this.convertValueToBool(newValue);
|
||||
// Update visual.
|
||||
if (this.textElement_) {
|
||||
this.textElement_.style.display = this.value_ ? 'block' : 'none';
|
||||
@@ -201,7 +201,7 @@ export class FieldCheckbox extends Field<CheckboxBool> {
|
||||
* @returns Text representing the value of this field ('true' or 'false').
|
||||
*/
|
||||
override getText(): string {
|
||||
return String(this.convertValueToBool_(this.value_));
|
||||
return String(this.convertValueToBool(this.value_));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,7 +213,7 @@ export class FieldCheckbox extends Field<CheckboxBool> {
|
||||
* @param value The value to convert.
|
||||
* @returns The converted value.
|
||||
*/
|
||||
private convertValueToBool_(value: CheckboxBool | null): boolean {
|
||||
private convertValueToBool(value: CheckboxBool | null): boolean {
|
||||
if (typeof value === 'string') return value === 'TRUE';
|
||||
return !!value;
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
protected valueWhenEditorWasOpened_: string | T | null = null;
|
||||
|
||||
/** Key down event data. */
|
||||
private onKeyDownWrapper_: browserEvents.Data | null = null;
|
||||
private onKeyDownWrapper: browserEvents.Data | null = null;
|
||||
|
||||
/** Key input event data. */
|
||||
private onKeyInputWrapper_: browserEvents.Data | null = null;
|
||||
private onKeyInputWrapper: browserEvents.Data | null = null;
|
||||
|
||||
/**
|
||||
* Whether the field should consider the whole parent block to be its click
|
||||
@@ -338,9 +338,9 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
this.workspace_.options.modalInputs &&
|
||||
(userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)
|
||||
) {
|
||||
this.showPromptEditor_();
|
||||
this.showPromptEditor();
|
||||
} else {
|
||||
this.showInlineEditor_(quietInput);
|
||||
this.showInlineEditor(quietInput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
* Mobile browsers may have issues with in-line textareas (focus and
|
||||
* keyboards).
|
||||
*/
|
||||
private showPromptEditor_() {
|
||||
private showPromptEditor() {
|
||||
dialog.prompt(
|
||||
Msg['CHANGE_VALUE_TITLE'],
|
||||
this.getText(),
|
||||
@@ -368,7 +368,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
*
|
||||
* @param quietInput True if editor should be created without focus.
|
||||
*/
|
||||
private showInlineEditor_(quietInput: boolean) {
|
||||
private showInlineEditor(quietInput: boolean) {
|
||||
const block = this.getSourceBlock();
|
||||
if (!block) {
|
||||
throw new UnattachedFieldError();
|
||||
@@ -518,30 +518,30 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
*/
|
||||
protected bindInputEvents_(htmlInput: HTMLElement) {
|
||||
// Trap Enter without IME and Esc to hide.
|
||||
this.onKeyDownWrapper_ = browserEvents.conditionalBind(
|
||||
this.onKeyDownWrapper = browserEvents.conditionalBind(
|
||||
htmlInput,
|
||||
'keydown',
|
||||
this,
|
||||
this.onHtmlInputKeyDown_,
|
||||
);
|
||||
// Resize after every input change.
|
||||
this.onKeyInputWrapper_ = browserEvents.conditionalBind(
|
||||
this.onKeyInputWrapper = browserEvents.conditionalBind(
|
||||
htmlInput,
|
||||
'input',
|
||||
this,
|
||||
this.onHtmlInputChange_,
|
||||
this.onHtmlInputChange,
|
||||
);
|
||||
}
|
||||
|
||||
/** Unbind handlers for user input and workspace size changes. */
|
||||
protected unbindInputEvents_() {
|
||||
if (this.onKeyDownWrapper_) {
|
||||
browserEvents.unbind(this.onKeyDownWrapper_);
|
||||
this.onKeyDownWrapper_ = null;
|
||||
if (this.onKeyDownWrapper) {
|
||||
browserEvents.unbind(this.onKeyDownWrapper);
|
||||
this.onKeyDownWrapper = null;
|
||||
}
|
||||
if (this.onKeyInputWrapper_) {
|
||||
browserEvents.unbind(this.onKeyInputWrapper_);
|
||||
this.onKeyInputWrapper_ = null;
|
||||
if (this.onKeyInputWrapper) {
|
||||
browserEvents.unbind(this.onKeyInputWrapper);
|
||||
this.onKeyInputWrapper = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
|
||||
*
|
||||
* @param _e Keyboard event.
|
||||
*/
|
||||
private onHtmlInputChange_(_e: Event) {
|
||||
private onHtmlInputChange(_e: Event) {
|
||||
// Intermediate value changes from user input are not confirmed until the
|
||||
// user closes the editor, and may be numerous. Inhibit reporting these as
|
||||
// normal block change events, and instead report them as special
|
||||
|
||||
@@ -207,7 +207,7 @@ export abstract class Flyout
|
||||
/**
|
||||
* Whether the flyout is visible.
|
||||
*/
|
||||
private isVisible_ = false;
|
||||
private visible = false;
|
||||
|
||||
/**
|
||||
* Whether the workspace containing this flyout is visible.
|
||||
@@ -286,7 +286,7 @@ export abstract class Flyout
|
||||
|
||||
this.workspace_.internalIsFlyout = true;
|
||||
// Keep the workspace visibility consistent with the flyout's visibility.
|
||||
this.workspace_.setVisible(this.isVisible_);
|
||||
this.workspace_.setVisible(this.visible);
|
||||
|
||||
/**
|
||||
* The unique id for this component that is used to register with the
|
||||
@@ -532,7 +532,7 @@ export abstract class Flyout
|
||||
* @returns True if visible.
|
||||
*/
|
||||
isVisible(): boolean {
|
||||
return this.isVisible_;
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -545,7 +545,7 @@ export abstract class Flyout
|
||||
setVisible(visible: boolean) {
|
||||
const visibilityChanged = visible !== this.isVisible();
|
||||
|
||||
this.isVisible_ = visible;
|
||||
this.visible = visible;
|
||||
if (visibilityChanged) {
|
||||
if (!this.autoClose) {
|
||||
// Auto-close flyouts are ignored as drag targets, so only non
|
||||
|
||||
@@ -38,7 +38,7 @@ export class FlyoutMetricsManager extends MetricsManager {
|
||||
*
|
||||
* @returns The bounding box of the blocks on the workspace.
|
||||
*/
|
||||
private getBoundingBox_():
|
||||
private getBoundingBox():
|
||||
| SVGRect
|
||||
| {height: number; y: number; width: number; x: number} {
|
||||
let blockBoundingBox;
|
||||
@@ -55,7 +55,7 @@ export class FlyoutMetricsManager extends MetricsManager {
|
||||
|
||||
override getContentMetrics(opt_getWorkspaceCoordinates?: boolean) {
|
||||
// The bounding box is in workspace coordinates.
|
||||
const blockBoundingBox = this.getBoundingBox_();
|
||||
const blockBoundingBox = this.getBoundingBox();
|
||||
const scale = opt_getWorkspaceCoordinates ? 1 : this.workspace_.scale;
|
||||
|
||||
return {
|
||||
|
||||
@@ -146,7 +146,7 @@ export class Gesture {
|
||||
private mostRecentEvent: PointerEvent;
|
||||
|
||||
/** Boolean for whether or not this gesture is a multi-touch gesture. */
|
||||
private isMultiTouch_ = false;
|
||||
private multiTouch = false;
|
||||
|
||||
/** A map of cached points used for tracking multi-touch gestures. */
|
||||
private cachedPoints = new Map<string, Coordinate | null>();
|
||||
@@ -586,7 +586,7 @@ export class Gesture {
|
||||
const point0 = this.cachedPoints.get(pointers[0])!;
|
||||
const point1 = this.cachedPoints.get(pointers[1])!;
|
||||
this.startDistance = Coordinate.distance(point0, point1);
|
||||
this.isMultiTouch_ = true;
|
||||
this.multiTouch = true;
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
@@ -691,7 +691,7 @@ export class Gesture {
|
||||
* @internal
|
||||
*/
|
||||
isMultiTouch(): boolean {
|
||||
return this.isMultiTouch_;
|
||||
return this.multiTouch;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,16 +23,16 @@ export class MarkerManager {
|
||||
static readonly LOCAL_MARKER = 'local_marker_1';
|
||||
|
||||
/** The cursor. */
|
||||
private cursor_: Cursor | null = null;
|
||||
private cursor: Cursor | null = null;
|
||||
|
||||
/** The cursor's SVG element. */
|
||||
private cursorSvg_: SVGElement | null = null;
|
||||
private cursorSvg: SVGElement | null = null;
|
||||
|
||||
/** The map of markers for the workspace. */
|
||||
private markers = new Map<string, Marker>();
|
||||
|
||||
/** The marker's SVG element. */
|
||||
private markerSvg_: SVGElement | null = null;
|
||||
private markerSvg: SVGElement | null = null;
|
||||
|
||||
/**
|
||||
* @param workspace The workspace for the marker manager.
|
||||
@@ -83,7 +83,7 @@ export class MarkerManager {
|
||||
* @returns The cursor for this workspace.
|
||||
*/
|
||||
getCursor(): Cursor | null {
|
||||
return this.cursor_;
|
||||
return this.cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,16 +104,16 @@ export class MarkerManager {
|
||||
* @param cursor The cursor used to move around this workspace.
|
||||
*/
|
||||
setCursor(cursor: Cursor) {
|
||||
if (this.cursor_ && this.cursor_.getDrawer()) {
|
||||
this.cursor_.getDrawer().dispose();
|
||||
if (this.cursor && this.cursor.getDrawer()) {
|
||||
this.cursor.getDrawer().dispose();
|
||||
}
|
||||
this.cursor_ = cursor;
|
||||
if (this.cursor_) {
|
||||
this.cursor = cursor;
|
||||
if (this.cursor) {
|
||||
const drawer = this.workspace
|
||||
.getRenderer()
|
||||
.makeMarkerDrawer(this.workspace, this.cursor_);
|
||||
this.cursor_.setDrawer(drawer);
|
||||
this.setCursorSvg(this.cursor_.getDrawer().createDom());
|
||||
.makeMarkerDrawer(this.workspace, this.cursor);
|
||||
this.cursor.setDrawer(drawer);
|
||||
this.setCursorSvg(this.cursor.getDrawer().createDom());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +126,12 @@ export class MarkerManager {
|
||||
*/
|
||||
setCursorSvg(cursorSvg: SVGElement | null) {
|
||||
if (!cursorSvg) {
|
||||
this.cursorSvg_ = null;
|
||||
this.cursorSvg = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.workspace.getBlockCanvas()!.appendChild(cursorSvg);
|
||||
this.cursorSvg_ = cursorSvg;
|
||||
this.cursorSvg = cursorSvg;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,15 +143,15 @@ export class MarkerManager {
|
||||
*/
|
||||
setMarkerSvg(markerSvg: SVGElement | null) {
|
||||
if (!markerSvg) {
|
||||
this.markerSvg_ = null;
|
||||
this.markerSvg = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.workspace.getBlockCanvas()) {
|
||||
if (this.cursorSvg_) {
|
||||
if (this.cursorSvg) {
|
||||
this.workspace
|
||||
.getBlockCanvas()!
|
||||
.insertBefore(markerSvg, this.cursorSvg_);
|
||||
.insertBefore(markerSvg, this.cursorSvg);
|
||||
} else {
|
||||
this.workspace.getBlockCanvas()!.appendChild(markerSvg);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ export class MarkerManager {
|
||||
* @internal
|
||||
*/
|
||||
updateMarkers() {
|
||||
if (this.workspace.keyboardAccessibilityMode && this.cursorSvg_) {
|
||||
if (this.workspace.keyboardAccessibilityMode && this.cursorSvg) {
|
||||
this.workspace.getCursor()!.draw();
|
||||
}
|
||||
}
|
||||
@@ -181,9 +181,9 @@ export class MarkerManager {
|
||||
this.unregisterMarker(markerId);
|
||||
}
|
||||
this.markers.clear();
|
||||
if (this.cursor_) {
|
||||
this.cursor_.dispose();
|
||||
this.cursor_ = null;
|
||||
if (this.cursor) {
|
||||
this.cursor.dispose();
|
||||
this.cursor = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ export class Options {
|
||||
this.modalInputs = modalInputs;
|
||||
this.pathToMedia = pathToMedia;
|
||||
this.hasCategories = hasCategories;
|
||||
this.moveOptions = Options.parseMoveOptions_(options, hasCategories);
|
||||
this.moveOptions = Options.parseMoveOptions(options, hasCategories);
|
||||
this.hasScrollbars = !!this.moveOptions.scrollbars;
|
||||
this.hasTrashcan = hasTrashcan;
|
||||
this.maxTrashcanContents = maxTrashcanContents;
|
||||
@@ -175,10 +175,10 @@ export class Options {
|
||||
this.hasCss = hasCss;
|
||||
this.horizontalLayout = horizontalLayout;
|
||||
this.languageTree = toolboxJsonDef;
|
||||
this.gridOptions = Options.parseGridOptions_(options);
|
||||
this.zoomOptions = Options.parseZoomOptions_(options);
|
||||
this.gridOptions = Options.parseGridOptions(options);
|
||||
this.zoomOptions = Options.parseZoomOptions(options);
|
||||
this.toolboxPosition = toolboxPosition;
|
||||
this.theme = Options.parseThemeOptions_(options);
|
||||
this.theme = Options.parseThemeOptions(options);
|
||||
this.renderer = renderer;
|
||||
this.rendererOverrides = options['rendererOverrides'] ?? null;
|
||||
|
||||
@@ -201,7 +201,7 @@ export class Options {
|
||||
* @param hasCategories Whether the workspace has categories or not.
|
||||
* @returns Normalized move options.
|
||||
*/
|
||||
private static parseMoveOptions_(
|
||||
private static parseMoveOptions(
|
||||
options: BlocklyOptions,
|
||||
hasCategories: boolean,
|
||||
): MoveOptions {
|
||||
@@ -260,7 +260,7 @@ export class Options {
|
||||
* @param options Dictionary of options.
|
||||
* @returns Normalized zoom options.
|
||||
*/
|
||||
private static parseZoomOptions_(options: BlocklyOptions): ZoomOptions {
|
||||
private static parseZoomOptions(options: BlocklyOptions): ZoomOptions {
|
||||
const zoom = options['zoom'] || {};
|
||||
const zoomOptions = {} as ZoomOptions;
|
||||
if (zoom['controls'] === undefined) {
|
||||
@@ -309,7 +309,7 @@ export class Options {
|
||||
* @param options Dictionary of options.
|
||||
* @returns Normalized grid options.
|
||||
*/
|
||||
private static parseGridOptions_(options: BlocklyOptions): GridOptions {
|
||||
private static parseGridOptions(options: BlocklyOptions): GridOptions {
|
||||
const grid = options['grid'] || {};
|
||||
const gridOptions = {} as GridOptions;
|
||||
gridOptions.spacing = Number(grid['spacing']) || 0;
|
||||
@@ -327,7 +327,7 @@ export class Options {
|
||||
* @param options Dictionary of options.
|
||||
* @returns A Blockly Theme.
|
||||
*/
|
||||
private static parseThemeOptions_(options: BlocklyOptions): Theme {
|
||||
private static parseThemeOptions(options: BlocklyOptions): Theme {
|
||||
const theme = options['theme'] || Classic;
|
||||
if (typeof theme === 'string') {
|
||||
return registry.getObject(registry.Type.THEME, theme) as Theme;
|
||||
|
||||
@@ -27,7 +27,7 @@ export class ScrollbarPair {
|
||||
corner_: SVGRectElement | null = null;
|
||||
|
||||
/** Previously recorded metrics from the workspace. */
|
||||
private oldHostMetrics_: Metrics | null = null;
|
||||
private oldHostMetrics: Metrics | null = null;
|
||||
|
||||
/**
|
||||
* @param workspace Workspace to bind the scrollbars to.
|
||||
@@ -84,7 +84,7 @@ export class ScrollbarPair {
|
||||
dispose() {
|
||||
dom.removeNode(this.corner_);
|
||||
this.corner_ = null;
|
||||
this.oldHostMetrics_ = null;
|
||||
this.oldHostMetrics = null;
|
||||
if (this.hScroll) {
|
||||
this.hScroll.dispose();
|
||||
this.hScroll = null;
|
||||
@@ -111,11 +111,11 @@ export class ScrollbarPair {
|
||||
let resizeH = false;
|
||||
let resizeV = false;
|
||||
if (
|
||||
!this.oldHostMetrics_ ||
|
||||
this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth ||
|
||||
this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight ||
|
||||
this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop ||
|
||||
this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft
|
||||
!this.oldHostMetrics ||
|
||||
this.oldHostMetrics.viewWidth !== hostMetrics.viewWidth ||
|
||||
this.oldHostMetrics.viewHeight !== hostMetrics.viewHeight ||
|
||||
this.oldHostMetrics.absoluteTop !== hostMetrics.absoluteTop ||
|
||||
this.oldHostMetrics.absoluteLeft !== hostMetrics.absoluteLeft
|
||||
) {
|
||||
// The window has been resized or repositioned.
|
||||
resizeH = true;
|
||||
@@ -123,18 +123,18 @@ export class ScrollbarPair {
|
||||
} else {
|
||||
// Has the content been resized or moved?
|
||||
if (
|
||||
!this.oldHostMetrics_ ||
|
||||
this.oldHostMetrics_.scrollWidth !== hostMetrics.scrollWidth ||
|
||||
this.oldHostMetrics_.viewLeft !== hostMetrics.viewLeft ||
|
||||
this.oldHostMetrics_.scrollLeft !== hostMetrics.scrollLeft
|
||||
!this.oldHostMetrics ||
|
||||
this.oldHostMetrics.scrollWidth !== hostMetrics.scrollWidth ||
|
||||
this.oldHostMetrics.viewLeft !== hostMetrics.viewLeft ||
|
||||
this.oldHostMetrics.scrollLeft !== hostMetrics.scrollLeft
|
||||
) {
|
||||
resizeH = true;
|
||||
}
|
||||
if (
|
||||
!this.oldHostMetrics_ ||
|
||||
this.oldHostMetrics_.scrollHeight !== hostMetrics.scrollHeight ||
|
||||
this.oldHostMetrics_.viewTop !== hostMetrics.viewTop ||
|
||||
this.oldHostMetrics_.scrollTop !== hostMetrics.scrollTop
|
||||
!this.oldHostMetrics ||
|
||||
this.oldHostMetrics.scrollHeight !== hostMetrics.scrollHeight ||
|
||||
this.oldHostMetrics.viewTop !== hostMetrics.viewTop ||
|
||||
this.oldHostMetrics.scrollTop !== hostMetrics.scrollTop
|
||||
) {
|
||||
resizeV = true;
|
||||
}
|
||||
@@ -158,23 +158,23 @@ export class ScrollbarPair {
|
||||
if (this.hScroll && this.vScroll) {
|
||||
// Reposition the corner square.
|
||||
if (
|
||||
!this.oldHostMetrics_ ||
|
||||
this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth ||
|
||||
this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft
|
||||
!this.oldHostMetrics ||
|
||||
this.oldHostMetrics.viewWidth !== hostMetrics.viewWidth ||
|
||||
this.oldHostMetrics.absoluteLeft !== hostMetrics.absoluteLeft
|
||||
) {
|
||||
this.corner_?.setAttribute('x', String(this.vScroll.position.x));
|
||||
}
|
||||
if (
|
||||
!this.oldHostMetrics_ ||
|
||||
this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight ||
|
||||
this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop
|
||||
!this.oldHostMetrics ||
|
||||
this.oldHostMetrics.viewHeight !== hostMetrics.viewHeight ||
|
||||
this.oldHostMetrics.absoluteTop !== hostMetrics.absoluteTop
|
||||
) {
|
||||
this.corner_?.setAttribute('y', String(this.hScroll.position.y));
|
||||
}
|
||||
}
|
||||
|
||||
// Cache the current metrics to potentially short-cut the next resize event.
|
||||
this.oldHostMetrics_ = hostMetrics;
|
||||
this.oldHostMetrics = hostMetrics;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -242,7 +242,7 @@ export class ShortcutRegistry {
|
||||
* @returns True if the event was handled, false otherwise.
|
||||
*/
|
||||
onKeyDown(workspace: WorkspaceSvg, e: KeyboardEvent): boolean {
|
||||
const key = this.serializeKeyEvent_(e);
|
||||
const key = this.serializeKeyEvent(e);
|
||||
const shortcutNames = this.getShortcutNamesByKeyCode(key);
|
||||
if (!shortcutNames) return false;
|
||||
for (const shortcutName of shortcutNames) {
|
||||
@@ -294,7 +294,7 @@ export class ShortcutRegistry {
|
||||
* @param e A key down event.
|
||||
* @returns The serialized key code for the given event.
|
||||
*/
|
||||
private serializeKeyEvent_(e: KeyboardEvent): string {
|
||||
private serializeKeyEvent(e: KeyboardEvent): string {
|
||||
let serializedKey = '';
|
||||
for (const modifier in ShortcutRegistry.modifierKeys) {
|
||||
if (e.getModifierState(modifier)) {
|
||||
@@ -318,7 +318,7 @@ export class ShortcutRegistry {
|
||||
* @param modifiers List of modifiers to be used with the key.
|
||||
* @throws {Error} if the modifier is not in the valid modifiers list.
|
||||
*/
|
||||
private checkModifiers_(modifiers: KeyCodes[]) {
|
||||
private checkModifiers(modifiers: KeyCodes[]) {
|
||||
for (const modifier of modifiers) {
|
||||
if (!(modifier in ShortcutRegistry.modifierKeys)) {
|
||||
throw new Error(modifier + ' is not a valid modifier key.');
|
||||
@@ -338,7 +338,7 @@ export class ShortcutRegistry {
|
||||
let serializedKey = '';
|
||||
|
||||
if (modifiers) {
|
||||
this.checkModifiers_(modifiers);
|
||||
this.checkModifiers(modifiers);
|
||||
for (const modifier in ShortcutRegistry.modifierKeys) {
|
||||
const modifierKeyCode = (
|
||||
ShortcutRegistry.modifierKeys as AnyDuringMigration
|
||||
|
||||
@@ -23,7 +23,7 @@ import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
*/
|
||||
export class ThemeManager {
|
||||
/** A list of workspaces that are subscribed to this theme. */
|
||||
private subscribedWorkspaces_: Workspace[] = [];
|
||||
private subscribedWorkspaces: Workspace[] = [];
|
||||
private componentDB = new Map<string, Component[]>();
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ export class ThemeManager {
|
||||
// Refresh all subscribed workspaces.
|
||||
for (
|
||||
let i = 0, workspace;
|
||||
(workspace = this.subscribedWorkspaces_[i]);
|
||||
(workspace = this.subscribedWorkspaces[i]);
|
||||
i++
|
||||
) {
|
||||
(workspace as WorkspaceSvg).refreshTheme();
|
||||
@@ -89,7 +89,7 @@ export class ThemeManager {
|
||||
}
|
||||
}
|
||||
|
||||
for (const workspace of this.subscribedWorkspaces_) {
|
||||
for (const workspace of this.subscribedWorkspaces) {
|
||||
(workspace as WorkspaceSvg).hideChaff();
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ export class ThemeManager {
|
||||
* @internal
|
||||
*/
|
||||
subscribeWorkspace(workspace: Workspace) {
|
||||
this.subscribedWorkspaces_.push(workspace);
|
||||
this.subscribedWorkspaces.push(workspace);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ export class ThemeManager {
|
||||
* @internal
|
||||
*/
|
||||
unsubscribeWorkspace(workspace: Workspace) {
|
||||
if (!arrayUtils.removeElem(this.subscribedWorkspaces_, workspace)) {
|
||||
if (!arrayUtils.removeElem(this.subscribedWorkspaces, workspace)) {
|
||||
throw Error(
|
||||
"Cannot unsubscribe a workspace that hasn't been subscribed.",
|
||||
);
|
||||
@@ -176,7 +176,7 @@ export class ThemeManager {
|
||||
* @internal
|
||||
*/
|
||||
dispose() {
|
||||
this.subscribedWorkspaces_.length = 0;
|
||||
this.subscribedWorkspaces.length = 0;
|
||||
this.componentDB.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,9 +347,9 @@ export class ToolboxCategory
|
||||
'" must not have both a style and a colour',
|
||||
);
|
||||
} else if (styleName) {
|
||||
return this.getColourfromStyle_(styleName);
|
||||
return this.getColourfromStyle(styleName);
|
||||
} else if (colour) {
|
||||
return this.parseColour_(colour);
|
||||
return this.parseColour(colour);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -361,12 +361,12 @@ export class ToolboxCategory
|
||||
* @param styleName Name of the style.
|
||||
* @returns The hex colour for the category.
|
||||
*/
|
||||
private getColourfromStyle_(styleName: string): string {
|
||||
private getColourfromStyle(styleName: string): string {
|
||||
const theme = this.workspace_.getTheme();
|
||||
if (styleName && theme) {
|
||||
const style = theme.categoryStyles[styleName];
|
||||
if (style && style.colour) {
|
||||
return this.parseColour_(style.colour);
|
||||
return this.parseColour(style.colour);
|
||||
} else {
|
||||
console.warn(
|
||||
'Style "' + styleName + '" must exist and contain a colour value',
|
||||
@@ -395,7 +395,7 @@ export class ToolboxCategory
|
||||
* reference string pointing to one of those two values.
|
||||
* @returns The hex colour for the category.
|
||||
*/
|
||||
private parseColour_(colourValue: number | string): string {
|
||||
private parseColour(colourValue: number | string): string {
|
||||
// Decode the colour for any potential message references
|
||||
// (eg. `%{BKY_MATH_HUE}`).
|
||||
const colour = parsing.replaceMessageReferences(colourValue);
|
||||
@@ -541,7 +541,7 @@ export class ToolboxCategory
|
||||
}
|
||||
const className = this.cssConfig_['selected'];
|
||||
if (isSelected) {
|
||||
const defaultColour = this.parseColour_(
|
||||
const defaultColour = this.parseColour(
|
||||
ToolboxCategory.defaultBackgroundColour,
|
||||
);
|
||||
this.rowDiv_.style.backgroundColor = this.colour_ || defaultColour;
|
||||
|
||||
@@ -83,7 +83,7 @@ export class CollapsibleToolboxCategory
|
||||
this.flyoutItems_.push(flyoutItem);
|
||||
prevIsFlyoutItem = true;
|
||||
} else {
|
||||
this.createToolboxItem_(itemDef);
|
||||
this.createToolboxItem(itemDef);
|
||||
prevIsFlyoutItem = false;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ export class CollapsibleToolboxCategory
|
||||
*
|
||||
* @param itemDef The information needed to create a toolbox item.
|
||||
*/
|
||||
private createToolboxItem_(itemDef: toolbox.ToolboxItemInfo) {
|
||||
private createToolboxItem(itemDef: toolbox.ToolboxItemInfo) {
|
||||
let registryName = itemDef['kind'];
|
||||
const categoryDef = itemDef as toolbox.CategoryInfo;
|
||||
// Categories that are collapsible are created using a class registered
|
||||
|
||||
@@ -29,7 +29,7 @@ export class ToolboxSeparator extends ToolboxItem {
|
||||
/** All the CSS class names that are used to create a separator. */
|
||||
protected cssConfig_: CssConfig = {'container': 'blocklyTreeSeparator'};
|
||||
|
||||
private htmlDiv_: HTMLDivElement | null = null;
|
||||
private htmlDiv: HTMLDivElement | null = null;
|
||||
|
||||
/**
|
||||
* @param separatorDef The information needed to create a separator.
|
||||
@@ -58,16 +58,16 @@ export class ToolboxSeparator extends ToolboxItem {
|
||||
if (className) {
|
||||
dom.addClass(container, className);
|
||||
}
|
||||
this.htmlDiv_ = container;
|
||||
this.htmlDiv = container;
|
||||
return container;
|
||||
}
|
||||
|
||||
override getDiv() {
|
||||
return this.htmlDiv_ as HTMLDivElement;
|
||||
return this.htmlDiv as HTMLDivElement;
|
||||
}
|
||||
|
||||
override dispose() {
|
||||
dom.removeNode(this.htmlDiv_ as HTMLDivElement);
|
||||
dom.removeNode(this.htmlDiv as HTMLDivElement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ export class Toolbox
|
||||
*/
|
||||
override id = 'toolbox';
|
||||
protected toolboxDef_: toolbox.ToolboxInfo;
|
||||
private readonly horizontalLayout_: boolean;
|
||||
private readonly horizontalLayout: boolean;
|
||||
|
||||
/** The HTML container for the toolbox. */
|
||||
HtmlDiv: HTMLDivElement | null = null;
|
||||
@@ -81,7 +81,7 @@ export class Toolbox
|
||||
RTL: boolean;
|
||||
|
||||
/** The flyout for the toolbox. */
|
||||
private flyout_: IFlyout | null = null;
|
||||
private flyout: IFlyout | null = null;
|
||||
protected contentMap_: {[key: string]: IToolboxItem};
|
||||
toolboxPosition: toolbox.Position;
|
||||
|
||||
@@ -113,7 +113,7 @@ export class Toolbox
|
||||
};
|
||||
|
||||
/** Whether the toolbox should be laid out horizontally. */
|
||||
this.horizontalLayout_ = workspace.options.horizontalLayout;
|
||||
this.horizontalLayout = workspace.options.horizontalLayout;
|
||||
|
||||
/** Is RTL vs LTR. */
|
||||
this.RTL = workspace.options.RTL;
|
||||
@@ -140,12 +140,12 @@ export class Toolbox
|
||||
const workspace = this.workspace_;
|
||||
const svg = workspace.getParentSvg();
|
||||
|
||||
this.flyout_ = this.createFlyout_();
|
||||
this.flyout = this.createFlyout_();
|
||||
|
||||
this.HtmlDiv = this.createDom_(this.workspace_);
|
||||
dom.insertAfter(this.flyout_.createDom('svg'), svg);
|
||||
dom.insertAfter(this.flyout.createDom('svg'), svg);
|
||||
this.setVisible(true);
|
||||
this.flyout_.init(workspace);
|
||||
this.flyout.init(workspace);
|
||||
|
||||
this.render(this.toolboxDef_);
|
||||
const themeManager = workspace.getThemeManager();
|
||||
@@ -281,16 +281,16 @@ export class Toolbox
|
||||
let handled = false;
|
||||
switch (e.key) {
|
||||
case 'ArrowDown':
|
||||
handled = this.selectNext_();
|
||||
handled = this.selectNext();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
handled = this.selectPrevious_();
|
||||
handled = this.selectPrevious();
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
handled = this.selectParent_();
|
||||
handled = this.selectParent();
|
||||
break;
|
||||
case 'ArrowRight':
|
||||
handled = this.selectChild_();
|
||||
handled = this.selectChild();
|
||||
break;
|
||||
case 'Enter':
|
||||
case ' ':
|
||||
@@ -391,7 +391,7 @@ export class Toolbox
|
||||
const fragment = document.createDocumentFragment();
|
||||
for (let i = 0; i < toolboxDef.length; i++) {
|
||||
const toolboxItemDef = toolboxDef[i];
|
||||
this.createToolboxItem_(toolboxItemDef, fragment);
|
||||
this.createToolboxItem(toolboxItemDef, fragment);
|
||||
}
|
||||
this.contentsDiv_!.appendChild(fragment);
|
||||
}
|
||||
@@ -403,7 +403,7 @@ export class Toolbox
|
||||
* the toolbox.
|
||||
* @param fragment The document fragment to add the child toolbox elements to.
|
||||
*/
|
||||
private createToolboxItem_(
|
||||
private createToolboxItem(
|
||||
toolboxItemDef: toolbox.ToolboxItemInfo,
|
||||
fragment: DocumentFragment,
|
||||
) {
|
||||
@@ -644,7 +644,7 @@ export class Toolbox
|
||||
* @returns The toolbox flyout.
|
||||
*/
|
||||
getFlyout(): IFlyout | null {
|
||||
return this.flyout_;
|
||||
return this.flyout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -682,7 +682,7 @@ export class Toolbox
|
||||
* vertical.
|
||||
*/
|
||||
isHorizontal(): boolean {
|
||||
return this.horizontalLayout_;
|
||||
return this.horizontalLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -697,7 +697,7 @@ export class Toolbox
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.horizontalLayout_) {
|
||||
if (this.horizontalLayout) {
|
||||
toolboxDiv.style.left = '0';
|
||||
toolboxDiv.style.height = 'auto';
|
||||
toolboxDiv.style.width = '100%';
|
||||
@@ -720,7 +720,7 @@ export class Toolbox
|
||||
this.width_ = toolboxDiv.offsetWidth;
|
||||
this.height_ = workspaceMetrics.viewHeight;
|
||||
}
|
||||
this.flyout_!.position();
|
||||
this.flyout!.position();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -780,7 +780,7 @@ export class Toolbox
|
||||
this.selectedItem_.isSelectable() &&
|
||||
this.selectedItem_.getContents().length
|
||||
) {
|
||||
this.flyout_!.show(this.selectedItem_.getContents());
|
||||
this.flyout!.show(this.selectedItem_.getContents());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +808,7 @@ export class Toolbox
|
||||
* Flyouts should not be closed if this is true.
|
||||
*/
|
||||
autoHide(onlyClosePopups: boolean) {
|
||||
if (!onlyClosePopups && this.flyout_ && this.flyout_.autoClose) {
|
||||
if (!onlyClosePopups && this.flyout && this.flyout.autoClose) {
|
||||
this.clearSelection();
|
||||
}
|
||||
}
|
||||
@@ -838,7 +838,7 @@ export class Toolbox
|
||||
}
|
||||
|
||||
this.updateFlyout_(oldItem, newItem);
|
||||
this.fireSelectEvent_(oldItem, newItem);
|
||||
this.fireSelectEvent(oldItem, newItem);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -940,10 +940,10 @@ export class Toolbox
|
||||
(oldItem === newItem && !newItem.isCollapsible()) ||
|
||||
!newItem.getContents().length
|
||||
) {
|
||||
this.flyout_!.hide();
|
||||
this.flyout!.hide();
|
||||
} else {
|
||||
this.flyout_!.show(newItem.getContents());
|
||||
this.flyout_!.scrollToStart();
|
||||
this.flyout!.show(newItem.getContents());
|
||||
this.flyout!.scrollToStart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -953,7 +953,7 @@ export class Toolbox
|
||||
* @param oldItem The previously selected toolbox item.
|
||||
* @param newItem The newly selected toolbox item.
|
||||
*/
|
||||
private fireSelectEvent_(
|
||||
private fireSelectEvent(
|
||||
oldItem: ISelectableToolboxItem | null,
|
||||
newItem: ISelectableToolboxItem | null,
|
||||
) {
|
||||
@@ -976,7 +976,7 @@ export class Toolbox
|
||||
*
|
||||
* @returns True if a parent category was selected, false otherwise.
|
||||
*/
|
||||
private selectParent_(): boolean {
|
||||
private selectParent(): boolean {
|
||||
if (!this.selectedItem_) {
|
||||
return false;
|
||||
}
|
||||
@@ -1004,7 +1004,7 @@ export class Toolbox
|
||||
*
|
||||
* @returns True if a child category was selected, false otherwise.
|
||||
*/
|
||||
private selectChild_(): boolean {
|
||||
private selectChild(): boolean {
|
||||
if (!this.selectedItem_ || !this.selectedItem_.isCollapsible()) {
|
||||
return false;
|
||||
}
|
||||
@@ -1013,7 +1013,7 @@ export class Toolbox
|
||||
collapsibleItem.toggleExpanded();
|
||||
return true;
|
||||
} else {
|
||||
this.selectNext_();
|
||||
this.selectNext();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1023,7 +1023,7 @@ export class Toolbox
|
||||
*
|
||||
* @returns True if a next category was selected, false otherwise.
|
||||
*/
|
||||
private selectNext_(): boolean {
|
||||
private selectNext(): boolean {
|
||||
if (!this.selectedItem_) {
|
||||
return false;
|
||||
}
|
||||
@@ -1047,7 +1047,7 @@ export class Toolbox
|
||||
*
|
||||
* @returns True if a previous category was selected, false otherwise.
|
||||
*/
|
||||
private selectPrevious_(): boolean {
|
||||
private selectPrevious(): boolean {
|
||||
if (!this.selectedItem_) {
|
||||
return false;
|
||||
}
|
||||
@@ -1069,7 +1069,7 @@ export class Toolbox
|
||||
/** Disposes of this toolbox. */
|
||||
dispose() {
|
||||
this.workspace_.getComponentManager().removeComponent('toolbox');
|
||||
this.flyout_!.dispose();
|
||||
this.flyout!.dispose();
|
||||
for (let i = 0; i < this.contents_.length; i++) {
|
||||
const toolboxItem = this.contents_[i];
|
||||
toolboxItem.dispose();
|
||||
|
||||
@@ -76,14 +76,9 @@ export class VariableMap {
|
||||
// The IDs may match if the rename is a simple case change (name1 ->
|
||||
// Name1).
|
||||
if (!conflictVar || conflictVar.getId() === variable.getId()) {
|
||||
this.renameVariableAndUses_(variable, newName, blocks);
|
||||
this.renameVariableAndUses(variable, newName, blocks);
|
||||
} else {
|
||||
this.renameVariableWithConflict_(
|
||||
variable,
|
||||
newName,
|
||||
conflictVar,
|
||||
blocks,
|
||||
);
|
||||
this.renameVariableWithConflict(variable, newName, conflictVar, blocks);
|
||||
}
|
||||
} finally {
|
||||
eventUtils.setGroup(existingGroup);
|
||||
@@ -114,7 +109,7 @@ export class VariableMap {
|
||||
* @param newName New variable name.
|
||||
* @param blocks The list of all blocks in the workspace.
|
||||
*/
|
||||
private renameVariableAndUses_(
|
||||
private renameVariableAndUses(
|
||||
variable: VariableModel,
|
||||
newName: string,
|
||||
blocks: Block[],
|
||||
@@ -139,7 +134,7 @@ export class VariableMap {
|
||||
* @param conflictVar The variable that was already using newName.
|
||||
* @param blocks The list of all blocks in the workspace.
|
||||
*/
|
||||
private renameVariableWithConflict_(
|
||||
private renameVariableWithConflict(
|
||||
variable: VariableModel,
|
||||
newName: string,
|
||||
conflictVar: VariableModel,
|
||||
@@ -150,7 +145,7 @@ export class VariableMap {
|
||||
|
||||
if (newName !== oldCase) {
|
||||
// Simple rename to change the case and update references.
|
||||
this.renameVariableAndUses_(conflictVar, newName, blocks);
|
||||
this.renameVariableAndUses(conflictVar, newName, blocks);
|
||||
}
|
||||
|
||||
// These blocks now refer to a different variable.
|
||||
|
||||
@@ -25,7 +25,7 @@ import type {Workspace} from './workspace.js';
|
||||
*/
|
||||
export class VariableModel {
|
||||
type: string;
|
||||
private readonly id_: string;
|
||||
private readonly id: string;
|
||||
|
||||
/**
|
||||
* @param workspace The variable's workspace.
|
||||
@@ -56,12 +56,12 @@ export class VariableModel {
|
||||
* not change, even if the name changes. In most cases this should be a
|
||||
* UUID.
|
||||
*/
|
||||
this.id_ = opt_id || idGenerator.genUid();
|
||||
this.id = opt_id || idGenerator.genUid();
|
||||
}
|
||||
|
||||
/** @returns The ID for the variable. */
|
||||
getId(): string {
|
||||
return this.id_;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -167,7 +167,7 @@ export class Workspace implements IASTNodeLocation {
|
||||
* @returns The comparison value. This tells Array.sort() how to change object
|
||||
* a's index.
|
||||
*/
|
||||
private sortObjects_(
|
||||
private sortObjects(
|
||||
a: Block | WorkspaceComment,
|
||||
b: Block | WorkspaceComment,
|
||||
): number {
|
||||
@@ -209,7 +209,7 @@ export class Workspace implements IASTNodeLocation {
|
||||
// Copy the topBlocks list.
|
||||
const blocks = new Array<Block>().concat(this.topBlocks);
|
||||
if (ordered && blocks.length > 1) {
|
||||
blocks.sort(this.sortObjects_.bind(this));
|
||||
blocks.sort(this.sortObjects.bind(this));
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ export class Workspace implements IASTNodeLocation {
|
||||
}
|
||||
const blocks = this.typedBlocksDB.get(type)!.slice(0);
|
||||
if (ordered && blocks && blocks.length > 1) {
|
||||
blocks.sort(this.sortObjects_.bind(this));
|
||||
blocks.sort(this.sortObjects.bind(this));
|
||||
}
|
||||
|
||||
return blocks.filter((block) => !block.isInsertionMarker());
|
||||
@@ -308,7 +308,7 @@ export class Workspace implements IASTNodeLocation {
|
||||
// Copy the topComments list.
|
||||
const comments = new Array<WorkspaceComment>().concat(this.topComments);
|
||||
if (ordered && comments.length > 1) {
|
||||
comments.sort(this.sortObjects_.bind(this));
|
||||
comments.sort(this.sortObjects.bind(this));
|
||||
}
|
||||
return comments;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export class WorkspaceAudio {
|
||||
private sounds = new Map<string, HTMLAudioElement>();
|
||||
|
||||
/** Time that the last sound was played. */
|
||||
private lastSound_: Date | null = null;
|
||||
private lastSound: Date | null = null;
|
||||
|
||||
/** Whether the audio is muted or not. */
|
||||
private muted: boolean = false;
|
||||
@@ -132,12 +132,12 @@ export class WorkspaceAudio {
|
||||
// Don't play one sound on top of another.
|
||||
const now = new Date();
|
||||
if (
|
||||
this.lastSound_ !== null &&
|
||||
now.getTime() - this.lastSound_.getTime() < SOUND_LIMIT
|
||||
this.lastSound !== null &&
|
||||
now.getTime() - this.lastSound.getTime() < SOUND_LIMIT
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.lastSound_ = now;
|
||||
this.lastSound = now;
|
||||
let mySound;
|
||||
if (userAgent.IPAD || userAgent.ANDROID) {
|
||||
// Creating a new audio node causes lag in Android and iPad. Android
|
||||
|
||||
@@ -21,17 +21,17 @@ import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
*
|
||||
*/
|
||||
export class WorkspaceDragger {
|
||||
private readonly horizontalScrollEnabled_: boolean;
|
||||
private readonly verticalScrollEnabled_: boolean;
|
||||
private readonly horizontalScrollEnabled: boolean;
|
||||
private readonly verticalScrollEnabled: boolean;
|
||||
protected startScrollXY_: Coordinate;
|
||||
|
||||
/** @param workspace The workspace to drag. */
|
||||
constructor(private workspace: WorkspaceSvg) {
|
||||
/** Whether horizontal scroll is enabled. */
|
||||
this.horizontalScrollEnabled_ = this.workspace.isMovableHorizontally();
|
||||
this.horizontalScrollEnabled = this.workspace.isMovableHorizontally();
|
||||
|
||||
/** Whether vertical scroll is enabled. */
|
||||
this.verticalScrollEnabled_ = this.workspace.isMovableVertically();
|
||||
this.verticalScrollEnabled = this.workspace.isMovableVertically();
|
||||
|
||||
/**
|
||||
* The scroll position of the workspace at the beginning of the drag.
|
||||
@@ -84,11 +84,11 @@ export class WorkspaceDragger {
|
||||
drag(currentDragDeltaXY: Coordinate) {
|
||||
const newXY = Coordinate.sum(this.startScrollXY_, currentDragDeltaXY);
|
||||
|
||||
if (this.horizontalScrollEnabled_ && this.verticalScrollEnabled_) {
|
||||
if (this.horizontalScrollEnabled && this.verticalScrollEnabled) {
|
||||
this.workspace.scroll(newXY.x, newXY.y);
|
||||
} else if (this.horizontalScrollEnabled_) {
|
||||
} else if (this.horizontalScrollEnabled) {
|
||||
this.workspace.scroll(newXY.x, this.workspace.scrollY);
|
||||
} else if (this.verticalScrollEnabled_) {
|
||||
} else if (this.verticalScrollEnabled) {
|
||||
this.workspace.scroll(this.workspace.scrollX, newXY.y);
|
||||
} else {
|
||||
throw new TypeError('Invalid state.');
|
||||
|
||||
@@ -104,7 +104,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* Whether the workspace is visible. False if the workspace has been hidden
|
||||
* by calling `setVisible(false)`.
|
||||
*/
|
||||
private isVisible_ = true;
|
||||
private visible = true;
|
||||
|
||||
/**
|
||||
* Whether this workspace has resizes enabled.
|
||||
@@ -209,7 +209,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* Category-based toolbox providing blocks which may be dragged into this
|
||||
* workspace.
|
||||
*/
|
||||
private toolbox_: IToolbox | null = null;
|
||||
private toolbox: IToolbox | null = null;
|
||||
|
||||
/**
|
||||
* The current gesture in progress on this workspace, if any.
|
||||
@@ -340,7 +340,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
|
||||
/** Translates the workspace. */
|
||||
this.setMetrics =
|
||||
options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics_;
|
||||
options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics;
|
||||
|
||||
this.componentManager = new ComponentManager();
|
||||
|
||||
@@ -540,14 +540,14 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
}
|
||||
|
||||
// Update all blocks in workspace that have a style name.
|
||||
this.updateBlockStyles_(
|
||||
this.updateBlockStyles(
|
||||
this.getAllBlocks(false).filter((block) => !!block.getStyleName()),
|
||||
);
|
||||
|
||||
// Update current toolbox selection.
|
||||
this.refreshToolboxSelection();
|
||||
if (this.toolbox_) {
|
||||
this.toolbox_.refreshTheme();
|
||||
if (this.toolbox) {
|
||||
this.toolbox.refreshTheme();
|
||||
}
|
||||
|
||||
// Re-render if workspace is visible
|
||||
@@ -567,7 +567,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
*
|
||||
* @param blocks List of blocks to update the style on.
|
||||
*/
|
||||
private updateBlockStyles_(blocks: Block[]) {
|
||||
private updateBlockStyles(blocks: Block[]) {
|
||||
for (let i = 0, block; (block = blocks[i]); i++) {
|
||||
const blockStyleName = block.getStyleName();
|
||||
if (blockStyleName) {
|
||||
@@ -608,7 +608,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* False if the workspace has been hidden by calling `setVisible(false)`.
|
||||
*/
|
||||
isVisible(): boolean {
|
||||
return this.isVisible_;
|
||||
return this.visible;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -781,7 +781,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
this.svgGroup_,
|
||||
'pointerdown',
|
||||
this,
|
||||
this.onMouseDown_,
|
||||
this.onMouseDown,
|
||||
false,
|
||||
);
|
||||
// This no-op works around https://bugs.webkit.org/show_bug.cgi?id=226683,
|
||||
@@ -793,7 +793,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
this.svgGroup_,
|
||||
'wheel',
|
||||
this,
|
||||
this.onMouseWheel_,
|
||||
this.onMouseWheel,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -805,7 +805,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
this.options,
|
||||
true,
|
||||
);
|
||||
this.toolbox_ = new ToolboxClass!(this);
|
||||
this.toolbox = new ToolboxClass!(this);
|
||||
}
|
||||
if (this.grid) {
|
||||
this.grid.update(this.scale);
|
||||
@@ -835,9 +835,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
if (this.svgGroup_) {
|
||||
dom.removeNode(this.svgGroup_);
|
||||
}
|
||||
if (this.toolbox_) {
|
||||
this.toolbox_.dispose();
|
||||
this.toolbox_ = null;
|
||||
if (this.toolbox) {
|
||||
this.toolbox.dispose();
|
||||
this.toolbox = null;
|
||||
}
|
||||
if (this.flyout) {
|
||||
this.flyout.dispose();
|
||||
@@ -994,8 +994,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
if (this.flyout || opt_own) {
|
||||
return this.flyout;
|
||||
}
|
||||
if (this.toolbox_) {
|
||||
return this.toolbox_.getFlyout();
|
||||
if (this.toolbox) {
|
||||
return this.toolbox.getFlyout();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1006,14 +1006,14 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* @returns The toolbox on this workspace.
|
||||
*/
|
||||
getToolbox(): IToolbox | null {
|
||||
return this.toolbox_;
|
||||
return this.toolbox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update items that use screen coordinate calculations
|
||||
* because something has changed (e.g. scroll position, window size).
|
||||
*/
|
||||
private updateScreenCalculations_() {
|
||||
private updateScreenCalculations() {
|
||||
this.updateInverseScreenCTM();
|
||||
this.recordDragTargets();
|
||||
}
|
||||
@@ -1043,8 +1043,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* trash, zoom, toolbox, etc. (e.g. window resize).
|
||||
*/
|
||||
resize() {
|
||||
if (this.toolbox_) {
|
||||
this.toolbox_.position();
|
||||
if (this.toolbox) {
|
||||
this.toolbox.position();
|
||||
}
|
||||
if (this.flyout) {
|
||||
this.flyout.position();
|
||||
@@ -1067,7 +1067,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
if (this.scrollbar) {
|
||||
this.scrollbar.resize();
|
||||
}
|
||||
this.updateScreenCalculations_();
|
||||
this.updateScreenCalculations();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1081,7 +1081,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
const currScroll = svgMath.getDocumentScroll();
|
||||
if (!Coordinate.equals(this.lastRecordedPageScroll, currScroll)) {
|
||||
this.lastRecordedPageScroll = currScroll;
|
||||
this.updateScreenCalculations_();
|
||||
this.updateScreenCalculations();
|
||||
}
|
||||
}
|
||||
/* eslint-enable indent */
|
||||
@@ -1223,7 +1223,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* @param isVisible True if workspace should be visible.
|
||||
*/
|
||||
setVisible(isVisible: boolean) {
|
||||
this.isVisible_ = isVisible;
|
||||
this.visible = isVisible;
|
||||
if (!this.svgGroup_) {
|
||||
return;
|
||||
}
|
||||
@@ -1241,9 +1241,9 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
}
|
||||
|
||||
this.getParentSvg().style.display = isVisible ? 'block' : 'none';
|
||||
if (this.toolbox_) {
|
||||
if (this.toolbox) {
|
||||
// Currently does not support toolboxes in mutators.
|
||||
this.toolbox_.setVisible(isVisible);
|
||||
this.toolbox.setVisible(isVisible);
|
||||
}
|
||||
if (!isVisible) {
|
||||
this.hideChaff(true);
|
||||
@@ -1310,8 +1310,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
*/
|
||||
refreshToolboxSelection() {
|
||||
const ws = this.isFlyout ? this.targetWorkspace : this;
|
||||
if (ws && !ws.currentGesture_ && ws.toolbox_ && ws.toolbox_.getFlyout()) {
|
||||
ws.toolbox_.refreshSelection();
|
||||
if (ws && !ws.currentGesture_ && ws.toolbox && ws.toolbox.getFlyout()) {
|
||||
ws.toolbox.refreshSelection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1431,7 +1431,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
*
|
||||
* @param e Pointer down event.
|
||||
*/
|
||||
private onMouseDown_(e: PointerEvent) {
|
||||
private onMouseDown(e: PointerEvent) {
|
||||
const gesture = this.getGesture(e);
|
||||
if (gesture) {
|
||||
gesture.handleWsStart(e, this);
|
||||
@@ -1530,7 +1530,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
*
|
||||
* @param e Mouse wheel event.
|
||||
*/
|
||||
private onMouseWheel_(e: WheelEvent) {
|
||||
private onMouseWheel(e: WheelEvent) {
|
||||
// Don't scroll or zoom anything if drag is in progress.
|
||||
if (Gesture.inProgress()) {
|
||||
e.preventDefault();
|
||||
@@ -1724,11 +1724,11 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
}
|
||||
|
||||
if (toolbox.hasCategories(parsedToolboxDef)) {
|
||||
if (!this.toolbox_) {
|
||||
if (!this.toolbox) {
|
||||
throw Error("Existing toolbox has no categories. Can't change mode.");
|
||||
}
|
||||
this.options.languageTree = parsedToolboxDef;
|
||||
this.toolbox_.render(parsedToolboxDef);
|
||||
this.toolbox.render(parsedToolboxDef);
|
||||
} else {
|
||||
if (!this.flyout) {
|
||||
throw Error("Existing toolbox has categories. Can't change mode.");
|
||||
@@ -2419,7 +2419,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
||||
* @param xyRatio Contains an x and/or y property which is a float between 0
|
||||
* and 1 specifying the degree of scrolling.
|
||||
*/
|
||||
private static setTopLevelWorkspaceMetrics_(
|
||||
private static setTopLevelWorkspaceMetrics(
|
||||
this: WorkspaceSvg,
|
||||
xyRatio: {x?: number; y?: number},
|
||||
) {
|
||||
|
||||
@@ -21,25 +21,25 @@ suite('Block JSON initialization', function () {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('validateTokens_', function () {
|
||||
suite('validateTokens', function () {
|
||||
setup(function () {
|
||||
this.assertError = function (tokens, count, error) {
|
||||
const block = {
|
||||
type: 'test',
|
||||
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
||||
validateTokens: Blockly.Block.prototype.validateTokens,
|
||||
};
|
||||
assert.throws(function () {
|
||||
block.validateTokens_(tokens, count);
|
||||
block.validateTokens(tokens, count);
|
||||
}, error);
|
||||
};
|
||||
|
||||
this.assertNoError = function (tokens, count) {
|
||||
const block = {
|
||||
type: 'test',
|
||||
validateTokens_: Blockly.Block.prototype.validateTokens_,
|
||||
validateTokens: Blockly.Block.prototype.validateTokens,
|
||||
};
|
||||
assert.doesNotThrow(function () {
|
||||
block.validateTokens_(tokens, count);
|
||||
block.validateTokens(tokens, count);
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -97,17 +97,17 @@ suite('Block JSON initialization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite('interpolateArguments_', function () {
|
||||
suite('interpolateArguments', function () {
|
||||
setup(function () {
|
||||
this.assertInterpolation = function (tokens, args, lastAlign, elements) {
|
||||
const block = {
|
||||
type: 'test',
|
||||
interpolateArguments_: Blockly.Block.prototype.interpolateArguments_,
|
||||
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
||||
isInputKeyword_: Blockly.Block.prototype.isInputKeyword_,
|
||||
interpolateArguments: Blockly.Block.prototype.interpolateArguments,
|
||||
stringToFieldJson: Blockly.Block.prototype.stringToFieldJson,
|
||||
isInputKeyword: Blockly.Block.prototype.isInputKeyword,
|
||||
};
|
||||
assert.deepEqual(
|
||||
block.interpolateArguments_(tokens, args, lastAlign),
|
||||
block.interpolateArguments(tokens, args, lastAlign),
|
||||
elements,
|
||||
);
|
||||
};
|
||||
@@ -381,7 +381,7 @@ suite('Block JSON initialization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite('fieldFromJson_', function () {
|
||||
suite('fieldFromJson', function () {
|
||||
setup(function () {
|
||||
this.stub = sinon
|
||||
.stub(Blockly.fieldRegistry.TEST_ONLY, 'fromJsonInternal')
|
||||
@@ -403,10 +403,10 @@ suite('Block JSON initialization', function () {
|
||||
this.assertField = function (json, expectedType) {
|
||||
const block = {
|
||||
type: 'test',
|
||||
fieldFromJson_: Blockly.Block.prototype.fieldFromJson_,
|
||||
stringToFieldJson_: Blockly.Block.prototype.stringToFieldJson_,
|
||||
fieldFromJson: Blockly.Block.prototype.fieldFromJson,
|
||||
stringToFieldJson: Blockly.Block.prototype.stringToFieldJson,
|
||||
};
|
||||
assert.strictEqual(block.fieldFromJson_(json), expectedType);
|
||||
assert.strictEqual(block.fieldFromJson(json), expectedType);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -563,7 +563,7 @@ suite('Block JSON initialization', function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite('inputFromJson_', function () {
|
||||
suite('inputFromJson', function () {
|
||||
setup(function () {
|
||||
this.assertInput = function (json, type, check, align) {
|
||||
const block = this.workspace.newBlock('test_basic_empty');
|
||||
@@ -571,7 +571,7 @@ suite('Block JSON initialization', function () {
|
||||
sinon.spy(block, 'appendValueInput');
|
||||
sinon.spy(block, 'appendStatementInput');
|
||||
|
||||
const input = block.inputFromJson_(json);
|
||||
const input = block.inputFromJson(json);
|
||||
switch (type) {
|
||||
case 'input_dummy':
|
||||
assert.isTrue(
|
||||
@@ -667,7 +667,7 @@ suite('Block JSON initialization', function () {
|
||||
CustomInput,
|
||||
);
|
||||
const block = this.workspace.newBlock('test_basic_empty');
|
||||
block.inputFromJson_({'type': 'custom'});
|
||||
block.inputFromJson({'type': 'custom'});
|
||||
assert.instanceOf(
|
||||
block.inputList[0],
|
||||
CustomInput,
|
||||
|
||||
@@ -2527,12 +2527,12 @@ suite('Blocks', function () {
|
||||
this.block.setColour('20');
|
||||
assert.equal(this.block.getColour(), '#a5745b');
|
||||
assert.equal(this.block.colour_, this.block.getColour());
|
||||
assert.equal(this.block.hue_, '20');
|
||||
assert.equal(this.block.getHue(), '20');
|
||||
});
|
||||
test('Set style', function () {
|
||||
this.block.setStyle('styleOne');
|
||||
assert.equal(this.block.getStyleName(), 'styleOne');
|
||||
assert.isNull(this.block.hue_);
|
||||
assert.isNull(this.block.getHue());
|
||||
// Calling setStyle does not update the colour on a headless block.
|
||||
assert.equal(this.block.getColour(), '#000000');
|
||||
});
|
||||
@@ -2566,14 +2566,14 @@ suite('Blocks', function () {
|
||||
assert.equal(this.block.getStyleName(), 'auto_#a5745b');
|
||||
assert.equal(this.block.getColour(), '#a5745b');
|
||||
assert.equal(this.block.colour_, this.block.getColour());
|
||||
assert.equal(this.block.hue_, '20');
|
||||
assert.equal(this.block.getHue(), '20');
|
||||
});
|
||||
test('Set colour hex', function () {
|
||||
this.block.setColour('#000000');
|
||||
assert.equal(this.block.getStyleName(), 'auto_#000000');
|
||||
assert.equal(this.block.getColour(), '#000000');
|
||||
assert.equal(this.block.colour_, this.block.getColour());
|
||||
assert.isNull(this.block.hue_);
|
||||
assert.isNull(this.block.getHue());
|
||||
});
|
||||
test('Set style', function () {
|
||||
this.block.setStyle('styleOne');
|
||||
|
||||
@@ -38,7 +38,7 @@ suite('Logic ternary', function () {
|
||||
const checkList = ifInput.connection.getCheck();
|
||||
assert.equal(checkList.length, 1);
|
||||
assert.equal(checkList[0], 'Boolean');
|
||||
assert.exists(block.onchangeWrapper_, 'Has onchange handler');
|
||||
assert.exists(block.onchangeWrapper, 'Has onchange handler');
|
||||
if (inputsInline) {
|
||||
assert.isTrue(block.inputsInline);
|
||||
} else {
|
||||
|
||||
@@ -1622,7 +1622,7 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = 'proc name2';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name2');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name2');
|
||||
});
|
||||
@@ -1635,7 +1635,7 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = 'PROC NAME';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'PROC NAME');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'PROC NAME');
|
||||
});
|
||||
@@ -1650,7 +1650,7 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = 'proc name';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||
});
|
||||
@@ -1663,7 +1663,7 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = 'proc name ';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name');
|
||||
});
|
||||
@@ -1676,9 +1676,9 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = 'proc name ';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
defInput.htmlInput_.value = 'proc name 2';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
assert.equal(this.defBlock.getFieldValue('NAME'), 'proc name 2');
|
||||
assert.equal(this.callBlock.getFieldValue('NAME'), 'proc name 2');
|
||||
});
|
||||
@@ -1691,7 +1691,7 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = '';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
assert.equal(
|
||||
this.defBlock.getFieldValue('NAME'),
|
||||
Blockly.Msg['UNNAMED_KEY'],
|
||||
@@ -1710,7 +1710,7 @@ suite('Procedures', function () {
|
||||
);
|
||||
|
||||
defInput.htmlInput_.value = '';
|
||||
defInput.onHtmlInputChange_(null);
|
||||
defInput.onHtmlInputChange(null);
|
||||
const newDefBlock = this.workspace.newBlock(testSuite.defType);
|
||||
newDefBlock.setFieldValue('new name', 'NAME');
|
||||
assert.equal(
|
||||
|
||||
@@ -201,7 +201,7 @@ suite('Events', function () {
|
||||
suite('Block Move', function () {
|
||||
test('by coordinate', function () {
|
||||
const coordinate = new Blockly.utils.Coordinate(3, 4);
|
||||
this.block.xy_ = coordinate;
|
||||
this.block.xy = coordinate;
|
||||
|
||||
const event = new Blockly.Events.BlockMove(this.block);
|
||||
sinon.assert.calledOnce(this.genUidStub);
|
||||
@@ -224,7 +224,7 @@ suite('Events', function () {
|
||||
try {
|
||||
this.parentBlock = createSimpleTestBlock(this.workspace);
|
||||
this.block.parentBlock_ = this.parentBlock;
|
||||
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
||||
this.block.xy = new Blockly.utils.Coordinate(3, 4);
|
||||
const event = new Blockly.Events.BlockMove(this.block);
|
||||
sinon.assert.calledTwice(this.genUidStub);
|
||||
assertEventEquals(
|
||||
@@ -331,7 +331,7 @@ suite('Events', function () {
|
||||
try {
|
||||
this.parentBlock = createSimpleTestBlock(this.workspace);
|
||||
this.block.parentBlock_ = this.parentBlock;
|
||||
this.block.xy_ = new Blockly.utils.Coordinate(3, 4);
|
||||
this.block.xy = new Blockly.utils.Coordinate(3, 4);
|
||||
const event = new Blockly.Events.BlockMove(this.block);
|
||||
sinon.assert.calledTwice(this.genUidStub);
|
||||
assertEventEquals(
|
||||
@@ -1284,7 +1284,7 @@ suite('Events', function () {
|
||||
suite('Filters', function () {
|
||||
function addMoveEvent(events, block, newX, newY) {
|
||||
events.push(new Blockly.Events.BlockMove(block));
|
||||
block.xy_ = new Blockly.utils.Coordinate(newX, newY);
|
||||
block.xy = new Blockly.utils.Coordinate(newX, newY);
|
||||
events[events.length - 1].recordNew();
|
||||
}
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ suite('Number Fields', function () {
|
||||
test('When Editing', function () {
|
||||
this.field.isBeingEdited_ = true;
|
||||
this.field.htmlInput_.value = String(suiteInfo.value);
|
||||
this.field.onHtmlInputChange_(null);
|
||||
this.field.onHtmlInputChange(null);
|
||||
assertFieldValue(
|
||||
this.field,
|
||||
suiteInfo.expectedValue,
|
||||
|
||||
@@ -626,7 +626,7 @@ suite('Abstract Fields', function () {
|
||||
const field = new Blockly.Field('value', null, {
|
||||
tooltip: 'test tooltip',
|
||||
});
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.getTooltip(), 'test tooltip');
|
||||
});
|
||||
test('JS Constructor - Dynamic', function () {
|
||||
const returnTooltip = function () {
|
||||
@@ -635,13 +635,13 @@ suite('Abstract Fields', function () {
|
||||
const field = new Blockly.Field('value', null, {
|
||||
tooltip: returnTooltip,
|
||||
});
|
||||
assert.equal(field.tooltip_, returnTooltip);
|
||||
assert.equal(field.getTooltip(), returnTooltip());
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = CustomField.fromJson({
|
||||
tooltip: 'test tooltip',
|
||||
});
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.getTooltip(), 'test tooltip');
|
||||
});
|
||||
suite('W/ Msg References', function () {
|
||||
setup(function () {
|
||||
@@ -652,13 +652,13 @@ suite('Abstract Fields', function () {
|
||||
const field = new Blockly.Field('value', null, {
|
||||
tooltip: '%{BKY_TOOLTIP}',
|
||||
});
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.getTooltip(), 'test tooltip');
|
||||
});
|
||||
test('JSON Definition', function () {
|
||||
const field = CustomField.fromJson({
|
||||
tooltip: '%{BKY_TOOLTIP}',
|
||||
});
|
||||
assert.equal(field.tooltip_, 'test tooltip');
|
||||
assert.equal(field.getTooltip(), 'test tooltip');
|
||||
});
|
||||
});
|
||||
suite('setTooltip', function () {
|
||||
|
||||
@@ -172,7 +172,7 @@ suite('Text Input Fields', function () {
|
||||
test('When Editing', function () {
|
||||
this.field.isBeingEdited_ = true;
|
||||
this.field.htmlInput_.value = suiteInfo.value;
|
||||
this.field.onHtmlInputChange_(null);
|
||||
this.field.onHtmlInputChange(null);
|
||||
assertFieldValue(
|
||||
this.field,
|
||||
suiteInfo.expectedValue,
|
||||
|
||||
@@ -68,7 +68,7 @@ suite('Key Down', function () {
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
test('Not called on hidden workspaces', function () {
|
||||
this.workspace.isVisible_ = false;
|
||||
this.workspace.visible = false;
|
||||
this.injectionDiv.dispatchEvent(this.event);
|
||||
sinon.assert.notCalled(this.hideChaffSpy);
|
||||
});
|
||||
|
||||
@@ -414,19 +414,19 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
suite('serializeKeyEvent', function () {
|
||||
test('Serialize key', function () {
|
||||
const mockEvent = createKeyDownEvent(Blockly.utils.KeyCodes.A);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
const serializedKey = this.registry.serializeKeyEvent(mockEvent);
|
||||
assert.equal(serializedKey, '65');
|
||||
});
|
||||
test('Serialize key code and modifier', function () {
|
||||
const mockEvent = createKeyDownEvent(Blockly.utils.KeyCodes.A, [
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
]);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
const serializedKey = this.registry.serializeKeyEvent(mockEvent);
|
||||
assert.equal(serializedKey, 'Control+65');
|
||||
});
|
||||
test('Serialize only a modifier', function () {
|
||||
const mockEvent = createKeyDownEvent(null, [Blockly.utils.KeyCodes.CTRL]);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
const serializedKey = this.registry.serializeKeyEvent(mockEvent);
|
||||
assert.equal(serializedKey, 'Control');
|
||||
});
|
||||
test('Serialize multiple modifiers', function () {
|
||||
@@ -434,7 +434,7 @@ suite('Keyboard Shortcut Registry Test', function () {
|
||||
Blockly.utils.KeyCodes.CTRL,
|
||||
Blockly.utils.KeyCodes.SHIFT,
|
||||
]);
|
||||
const serializedKey = this.registry.serializeKeyEvent_(mockEvent);
|
||||
const serializedKey = this.registry.serializeKeyEvent(mockEvent);
|
||||
assert.equal(serializedKey, 'Shift+Control');
|
||||
});
|
||||
test('Throw error when incorrect modifier', function () {
|
||||
|
||||
@@ -238,7 +238,7 @@ export function getBasicToolbox() {
|
||||
const workspace = new Blockly.WorkspaceSvg(new Blockly.Options({}));
|
||||
const toolbox = new Blockly.Toolbox(workspace);
|
||||
toolbox.HtmlDiv = document.createElement('div');
|
||||
toolbox.flyout_ = sinon.createStubInstance(Blockly.VerticalFlyout);
|
||||
toolbox.flyout = sinon.createStubInstance(Blockly.VerticalFlyout);
|
||||
return toolbox;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ suite('Toolbox', function () {
|
||||
const componentManager = this.toolbox.workspace_.getComponentManager();
|
||||
sinon.stub(componentManager, 'addComponent');
|
||||
this.toolbox.init();
|
||||
assert.isDefined(this.toolbox.flyout_);
|
||||
assert.isDefined(this.toolbox.getFlyout());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -239,30 +239,30 @@ suite('Toolbox', function () {
|
||||
sinon.assert.called(preventDefaultEvent);
|
||||
}
|
||||
|
||||
test('Down button is pushed -> Should call selectNext_', function () {
|
||||
testCorrectFunctionCalled(this.toolbox, 'ArrowDown', 'selectNext_', true);
|
||||
test('Down button is pushed -> Should call selectNext', function () {
|
||||
testCorrectFunctionCalled(this.toolbox, 'ArrowDown', 'selectNext', true);
|
||||
});
|
||||
test('Up button is pushed -> Should call selectPrevious_', function () {
|
||||
test('Up button is pushed -> Should call selectPrevious', function () {
|
||||
testCorrectFunctionCalled(
|
||||
this.toolbox,
|
||||
'ArrowUp',
|
||||
'selectPrevious_',
|
||||
'selectPrevious',
|
||||
true,
|
||||
);
|
||||
});
|
||||
test('Left button is pushed -> Should call selectParent_', function () {
|
||||
test('Left button is pushed -> Should call selectParent', function () {
|
||||
testCorrectFunctionCalled(
|
||||
this.toolbox,
|
||||
'ArrowLeft',
|
||||
'selectParent_',
|
||||
'selectParent',
|
||||
true,
|
||||
);
|
||||
});
|
||||
test('Right button is pushed -> Should call selectChild_', function () {
|
||||
test('Right button is pushed -> Should call selectChild', function () {
|
||||
testCorrectFunctionCalled(
|
||||
this.toolbox,
|
||||
'ArrowRight',
|
||||
'selectChild_',
|
||||
'selectChild',
|
||||
true,
|
||||
);
|
||||
});
|
||||
@@ -295,21 +295,21 @@ suite('Toolbox', function () {
|
||||
this.toolbox.dispose();
|
||||
});
|
||||
|
||||
suite('selectChild_', function () {
|
||||
suite('selectChild', function () {
|
||||
test('No item is selected -> Should not handle event', function () {
|
||||
this.toolbox.selectedItem_ = null;
|
||||
const handled = this.toolbox.selectChild_();
|
||||
const handled = this.toolbox.selectChild();
|
||||
assert.isFalse(handled);
|
||||
});
|
||||
test('Selected item is not collapsible -> Should not handle event', function () {
|
||||
this.toolbox.selectedItem_ = getNonCollapsibleItem(this.toolbox);
|
||||
const handled = this.toolbox.selectChild_();
|
||||
const handled = this.toolbox.selectChild();
|
||||
assert.isFalse(handled);
|
||||
});
|
||||
test('Selected item is collapsible -> Should expand', function () {
|
||||
const collapsibleItem = getCollapsibleItem(this.toolbox);
|
||||
this.toolbox.selectedItem_ = collapsibleItem;
|
||||
const handled = this.toolbox.selectChild_();
|
||||
const handled = this.toolbox.selectChild();
|
||||
assert.isTrue(handled);
|
||||
assert.isTrue(collapsibleItem.isExpanded());
|
||||
assert.equal(this.toolbox.selectedItem_, collapsibleItem);
|
||||
@@ -318,25 +318,25 @@ suite('Toolbox', function () {
|
||||
test('Selected item is expanded -> Should select child', function () {
|
||||
const collapsibleItem = getCollapsibleItem(this.toolbox);
|
||||
collapsibleItem.expanded_ = true;
|
||||
const selectNextStub = sinon.stub(this.toolbox, 'selectNext_');
|
||||
const selectNextStub = sinon.stub(this.toolbox, 'selectNext');
|
||||
this.toolbox.selectedItem_ = collapsibleItem;
|
||||
const handled = this.toolbox.selectChild_();
|
||||
const handled = this.toolbox.selectChild();
|
||||
assert.isTrue(handled);
|
||||
sinon.assert.called(selectNextStub);
|
||||
});
|
||||
});
|
||||
|
||||
suite('selectParent_', function () {
|
||||
suite('selectParent', function () {
|
||||
test('No item selected -> Should not handle event', function () {
|
||||
this.toolbox.selectedItem_ = null;
|
||||
const handled = this.toolbox.selectParent_();
|
||||
const handled = this.toolbox.selectParent();
|
||||
assert.isFalse(handled);
|
||||
});
|
||||
test('Selected item is expanded -> Should collapse', function () {
|
||||
const collapsibleItem = getCollapsibleItem(this.toolbox);
|
||||
collapsibleItem.expanded_ = true;
|
||||
this.toolbox.selectedItem_ = collapsibleItem;
|
||||
const handled = this.toolbox.selectParent_();
|
||||
const handled = this.toolbox.selectParent();
|
||||
assert.isTrue(handled);
|
||||
assert.isFalse(collapsibleItem.isExpanded());
|
||||
assert.equal(this.toolbox.selectedItem_, collapsibleItem);
|
||||
@@ -344,29 +344,29 @@ suite('Toolbox', function () {
|
||||
test('Selected item is not expanded -> Should get parent', function () {
|
||||
const childItem = getChildItem(this.toolbox);
|
||||
this.toolbox.selectedItem_ = childItem;
|
||||
const handled = this.toolbox.selectParent_();
|
||||
const handled = this.toolbox.selectParent();
|
||||
assert.isTrue(handled);
|
||||
assert.equal(this.toolbox.selectedItem_, childItem.getParent());
|
||||
});
|
||||
});
|
||||
|
||||
suite('selectNext_', function () {
|
||||
suite('selectNext', function () {
|
||||
test('No item is selected -> Should not handle event', function () {
|
||||
this.toolbox.selectedItem_ = null;
|
||||
const handled = this.toolbox.selectNext_();
|
||||
const handled = this.toolbox.selectNext();
|
||||
assert.isFalse(handled);
|
||||
});
|
||||
test('Next item is selectable -> Should select next item', function () {
|
||||
const item = this.toolbox.contents_[0];
|
||||
this.toolbox.selectedItem_ = item;
|
||||
const handled = this.toolbox.selectNext_();
|
||||
const handled = this.toolbox.selectNext();
|
||||
assert.isTrue(handled);
|
||||
assert.equal(this.toolbox.selectedItem_, this.toolbox.contents_[1]);
|
||||
});
|
||||
test('Selected item is last item -> Should not handle event', function () {
|
||||
const item = this.toolbox.contents_[this.toolbox.contents_.length - 1];
|
||||
this.toolbox.selectedItem_ = item;
|
||||
const handled = this.toolbox.selectNext_();
|
||||
const handled = this.toolbox.selectNext();
|
||||
assert.isFalse(handled);
|
||||
assert.equal(this.toolbox.selectedItem_, item);
|
||||
});
|
||||
@@ -375,7 +375,7 @@ suite('Toolbox', function () {
|
||||
const childItem = item.flyoutItems_[0];
|
||||
item.expanded_ = false;
|
||||
this.toolbox.selectedItem_ = item;
|
||||
const handled = this.toolbox.selectNext_();
|
||||
const handled = this.toolbox.selectNext();
|
||||
assert.isTrue(handled);
|
||||
assert.notEqual(this.toolbox.selectedItem_, childItem);
|
||||
});
|
||||
@@ -384,13 +384,13 @@ suite('Toolbox', function () {
|
||||
suite('selectPrevious', function () {
|
||||
test('No item is selected -> Should not handle event', function () {
|
||||
this.toolbox.selectedItem_ = null;
|
||||
const handled = this.toolbox.selectPrevious_();
|
||||
const handled = this.toolbox.selectPrevious();
|
||||
assert.isFalse(handled);
|
||||
});
|
||||
test('Selected item is first item -> Should not handle event', function () {
|
||||
const item = this.toolbox.contents_[0];
|
||||
this.toolbox.selectedItem_ = item;
|
||||
const handled = this.toolbox.selectPrevious_();
|
||||
const handled = this.toolbox.selectPrevious();
|
||||
assert.isFalse(handled);
|
||||
assert.equal(this.toolbox.selectedItem_, item);
|
||||
});
|
||||
@@ -398,7 +398,7 @@ suite('Toolbox', function () {
|
||||
const item = this.toolbox.contents_[1];
|
||||
const prevItem = this.toolbox.contents_[0];
|
||||
this.toolbox.selectedItem_ = item;
|
||||
const handled = this.toolbox.selectPrevious_();
|
||||
const handled = this.toolbox.selectPrevious();
|
||||
assert.isTrue(handled);
|
||||
assert.equal(this.toolbox.selectedItem_, prevItem);
|
||||
});
|
||||
@@ -409,7 +409,7 @@ suite('Toolbox', function () {
|
||||
// Gets the item after the parent.
|
||||
const item = this.toolbox.contents_[parentIdx + 1];
|
||||
this.toolbox.selectedItem_ = item;
|
||||
const handled = this.toolbox.selectPrevious_();
|
||||
const handled = this.toolbox.selectPrevious();
|
||||
assert.isTrue(handled);
|
||||
assert.notEqual(this.toolbox.selectedItem_, childItem);
|
||||
});
|
||||
@@ -477,7 +477,7 @@ suite('Toolbox', function () {
|
||||
});
|
||||
|
||||
function testHideFlyout(toolbox, oldItem, newItem) {
|
||||
const updateFlyoutStub = sinon.stub(toolbox.flyout_, 'hide');
|
||||
const updateFlyoutStub = sinon.stub(toolbox.getFlyout(), 'hide');
|
||||
toolbox.updateFlyout_(oldItem, newItem);
|
||||
sinon.assert.called(updateFlyoutStub);
|
||||
}
|
||||
@@ -498,9 +498,9 @@ suite('Toolbox', function () {
|
||||
testHideFlyout(this.toolbox, null, newItem);
|
||||
});
|
||||
test('Select selectable item -> Should open flyout', function () {
|
||||
const showFlyoutstub = sinon.stub(this.toolbox.flyout_, 'show');
|
||||
const showFlyoutstub = sinon.stub(this.toolbox.getFlyout(), 'show');
|
||||
const scrollToStartFlyout = sinon.stub(
|
||||
this.toolbox.flyout_,
|
||||
this.toolbox.getFlyout(),
|
||||
'scrollToStart',
|
||||
);
|
||||
const newItem = getNonCollapsibleItem(this.toolbox);
|
||||
@@ -534,14 +534,14 @@ suite('Toolbox', function () {
|
||||
test('HtmlDiv is not created -> Should not resize', function () {
|
||||
const toolbox = this.toolbox;
|
||||
toolbox.HtmlDiv = null;
|
||||
toolbox.horizontalLayout_ = true;
|
||||
toolbox.horizontalLayout = true;
|
||||
toolbox.position();
|
||||
assert.equal(toolbox.height_, 0);
|
||||
});
|
||||
test('Horizontal toolbox at top -> Should anchor horizontal toolbox to top', function () {
|
||||
const toolbox = this.toolbox;
|
||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.TOP;
|
||||
toolbox.horizontalLayout_ = true;
|
||||
toolbox.horizontalLayout = true;
|
||||
toolbox.position();
|
||||
checkHorizontalToolbox(toolbox);
|
||||
assert.equal(toolbox.HtmlDiv.style.top, '0px', 'Check top');
|
||||
@@ -549,7 +549,7 @@ suite('Toolbox', function () {
|
||||
test('Horizontal toolbox at bottom -> Should anchor horizontal toolbox to bottom', function () {
|
||||
const toolbox = this.toolbox;
|
||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.BOTTOM;
|
||||
toolbox.horizontalLayout_ = true;
|
||||
toolbox.horizontalLayout = true;
|
||||
toolbox.position();
|
||||
checkHorizontalToolbox(toolbox);
|
||||
assert.equal(toolbox.HtmlDiv.style.bottom, '0px', 'Check bottom');
|
||||
@@ -557,7 +557,7 @@ suite('Toolbox', function () {
|
||||
test('Vertical toolbox at right -> Should anchor to right', function () {
|
||||
const toolbox = this.toolbox;
|
||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.RIGHT;
|
||||
toolbox.horizontalLayout_ = false;
|
||||
toolbox.horizontalLayout = false;
|
||||
toolbox.position();
|
||||
assert.equal(toolbox.HtmlDiv.style.right, '0px', 'Check right');
|
||||
checkVerticalToolbox(toolbox);
|
||||
@@ -565,7 +565,7 @@ suite('Toolbox', function () {
|
||||
test('Vertical toolbox at left -> Should anchor to left', function () {
|
||||
const toolbox = this.toolbox;
|
||||
toolbox.toolboxPosition = Blockly.utils.toolbox.Position.LEFT;
|
||||
toolbox.horizontalLayout_ = false;
|
||||
toolbox.horizontalLayout = false;
|
||||
toolbox.position();
|
||||
assert.equal(toolbox.HtmlDiv.style.left, '0px', 'Check left');
|
||||
checkVerticalToolbox(toolbox);
|
||||
|
||||
@@ -29,7 +29,7 @@ suite('Variable Model', function () {
|
||||
);
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, 'test_type');
|
||||
assert.equal(variable.id_, 'test_id');
|
||||
assert.equal(variable.getId(), 'test_id');
|
||||
});
|
||||
|
||||
test('Null type', function () {
|
||||
@@ -61,7 +61,7 @@ suite('Variable Model', function () {
|
||||
);
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, 'test_type');
|
||||
assert.exists(variable.id_);
|
||||
assert.exists(variable.getId());
|
||||
});
|
||||
|
||||
test('Undefined id', function () {
|
||||
@@ -73,13 +73,13 @@ suite('Variable Model', function () {
|
||||
);
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, 'test_type');
|
||||
assert.exists(variable.id_);
|
||||
assert.exists(variable.getId());
|
||||
});
|
||||
|
||||
test('Only name provided', function () {
|
||||
const variable = new Blockly.VariableModel(this.workspace, 'test');
|
||||
assert.equal(variable.name, 'test');
|
||||
assert.equal(variable.type, '');
|
||||
assert.exists(variable.id_);
|
||||
assert.exists(variable.getId());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -136,7 +136,7 @@ suite('WorkspaceSvg', function () {
|
||||
sinon
|
||||
.stub(Blockly.utils.toolbox.TEST_ONLY, 'hasCategoriesInternal')
|
||||
.returns(true);
|
||||
this.workspace.toolbox_ = null;
|
||||
this.workspace.toolbox = null;
|
||||
assert.throws(
|
||||
function () {
|
||||
this.workspace.updateToolbox({'contents': []});
|
||||
|
||||
Reference in New Issue
Block a user