From 09573bcf160de31dc4fc0164b4d21013fe733fe9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 10 Aug 2021 15:43:41 -0700 Subject: [PATCH] Split classes from core/renderers/measurables/inputs.js --- .../measurables/external_value_input.js | 53 ++++++ core/renderers/measurables/inline_input.js | 63 +++++++ .../renderers/measurables/input_connection.js | 55 ++++++ core/renderers/measurables/inputs.js | 162 ------------------ core/renderers/measurables/statement_input.js | 50 ++++++ tests/deps.js | 5 +- 6 files changed, 225 insertions(+), 163 deletions(-) create mode 100644 core/renderers/measurables/external_value_input.js create mode 100644 core/renderers/measurables/inline_input.js create mode 100644 core/renderers/measurables/input_connection.js delete mode 100644 core/renderers/measurables/inputs.js create mode 100644 core/renderers/measurables/statement_input.js diff --git a/core/renderers/measurables/external_value_input.js b/core/renderers/measurables/external_value_input.js new file mode 100644 index 000000000..52fb78a0a --- /dev/null +++ b/core/renderers/measurables/external_value_input.js @@ -0,0 +1,53 @@ +/** + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Class representing external value inputs with connections on a + * rendered block. + * @author fenichel@google.com (Rachel Fenichel) + */ + +goog.provide('Blockly.blockRendering.ExternalValueInput'); + +goog.require('Blockly.blockRendering.InputConnection'); +goog.require('Blockly.blockRendering.Types'); +goog.require('Blockly.utils.object'); + +goog.requireType('Blockly.blockRendering.ConstantProvider'); +goog.requireType('Blockly.Input'); + + +/** + * An object containing information about the space an external value input + * takes up during rendering + * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering + * constants provider. + * @param {!Blockly.Input} input The external value input to measure and store + * information for. + * @package + * @constructor + * @extends {Blockly.blockRendering.InputConnection} + */ +Blockly.blockRendering.ExternalValueInput = function(constants, input) { + Blockly.blockRendering.ExternalValueInput.superClass_.constructor.call(this, + constants, input); + this.type |= Blockly.blockRendering.Types.EXTERNAL_VALUE_INPUT; + if (!this.connectedBlock) { + this.height = this.shape.height; + } else { + this.height = + this.connectedBlockHeight - this.constants_.TAB_OFFSET_FROM_TOP - + this.constants_.MEDIUM_PADDING; + } + this.width = this.shape.width + + this.constants_.EXTERNAL_VALUE_INPUT_PADDING; + + this.connectionOffsetY = this.constants_.TAB_OFFSET_FROM_TOP; + this.connectionHeight = this.shape.height; + this.connectionWidth = this.shape.width; +}; +Blockly.utils.object.inherits(Blockly.blockRendering.ExternalValueInput, + Blockly.blockRendering.InputConnection); diff --git a/core/renderers/measurables/inline_input.js b/core/renderers/measurables/inline_input.js new file mode 100644 index 000000000..59a4bf670 --- /dev/null +++ b/core/renderers/measurables/inline_input.js @@ -0,0 +1,63 @@ +/** + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Class representing inline inputs with connections on a rendered + * block. + * @author fenichel@google.com (Rachel Fenichel) + */ + +goog.provide('Blockly.blockRendering.InlineInput'); + +goog.require('Blockly.blockRendering.InputConnection'); +goog.require('Blockly.blockRendering.Types'); +goog.require('Blockly.utils.object'); + +goog.requireType('Blockly.blockRendering.ConstantProvider'); +goog.requireType('Blockly.Input'); + + +/** + * An object containing information about the space an inline input takes up + * during rendering + * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering + * constants provider. + * @param {!Blockly.Input} input The inline input to measure and store + * information for. + * @package + * @constructor + * @extends {Blockly.blockRendering.InputConnection} + */ +Blockly.blockRendering.InlineInput = function(constants, input) { + Blockly.blockRendering.InlineInput.superClass_.constructor.call(this, + constants, input); + this.type |= Blockly.blockRendering.Types.INLINE_INPUT; + + if (!this.connectedBlock) { + this.height = this.constants_.EMPTY_INLINE_INPUT_HEIGHT; + this.width = this.constants_.EMPTY_INLINE_INPUT_PADDING; + } else { + // We allow the dark path to show on the parent block so that the child + // block looks embossed. This takes up an extra pixel in both x and y. + this.width = this.connectedBlockWidth; + this.height = this.connectedBlockHeight; + } + + this.connectionHeight = !this.isDynamicShape ? this.shape.height : + this.shape.height(this.height); + this.connectionWidth = !this.isDynamicShape ? this.shape.width : + this.shape.width(this.height); + if (!this.connectedBlock) { + this.width += this.connectionWidth * (this.isDynamicShape ? 2 : 1); + } + this.connectionOffsetY = this.isDynamicShape ? + this.shape.connectionOffsetY(this.connectionHeight) : + this.constants_.TAB_OFFSET_FROM_TOP; + this.connectionOffsetX = this.isDynamicShape ? + this.shape.connectionOffsetX(this.connectionWidth) : 0; +}; +Blockly.utils.object.inherits(Blockly.blockRendering.InlineInput, + Blockly.blockRendering.InputConnection); diff --git a/core/renderers/measurables/input_connection.js b/core/renderers/measurables/input_connection.js new file mode 100644 index 000000000..9a9edc887 --- /dev/null +++ b/core/renderers/measurables/input_connection.js @@ -0,0 +1,55 @@ +/** + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Class representing inputs with connections on a rendered block. + * @author fenichel@google.com (Rachel Fenichel) + */ + +goog.provide('Blockly.blockRendering.InputConnection'); + +goog.require('Blockly.blockRendering.Connection'); +goog.require('Blockly.blockRendering.Types'); +goog.require('Blockly.utils.object'); + +goog.requireType('Blockly.blockRendering.ConstantProvider'); +goog.requireType('Blockly.Input'); + + +/** + * The base class to represent an input that takes up space on a block + * during rendering + * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering + * constants provider. + * @param {!Blockly.Input} input The input to measure and store information for. + * @package + * @constructor + * @extends {Blockly.blockRendering.Connection} + */ +Blockly.blockRendering.InputConnection = function(constants, input) { + Blockly.blockRendering.InputConnection.superClass_.constructor.call(this, + constants, input.connection); + + this.type |= Blockly.blockRendering.Types.INPUT; + this.input = input; + this.align = input.align; + this.connectedBlock = input.connection && input.connection.targetBlock() ? + input.connection.targetBlock() : null; + + if (this.connectedBlock) { + var bBox = this.connectedBlock.getHeightWidth(); + this.connectedBlockWidth = bBox.width; + this.connectedBlockHeight = bBox.height; + } else { + this.connectedBlockWidth = 0; + this.connectedBlockHeight = 0; + } + + this.connectionOffsetX = 0; + this.connectionOffsetY = 0; +}; +Blockly.utils.object.inherits(Blockly.blockRendering.InputConnection, + Blockly.blockRendering.Connection); diff --git a/core/renderers/measurables/inputs.js b/core/renderers/measurables/inputs.js deleted file mode 100644 index 5f845d65b..000000000 --- a/core/renderers/measurables/inputs.js +++ /dev/null @@ -1,162 +0,0 @@ -/** - * @license - * Copyright 2019 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview Objects representing inputs with connections on a rendered - * block. - * @author fenichel@google.com (Rachel Fenichel) - */ - -goog.provide('Blockly.blockRendering.ExternalValueInput'); -goog.provide('Blockly.blockRendering.InlineInput'); -goog.provide('Blockly.blockRendering.InputConnection'); -goog.provide('Blockly.blockRendering.StatementInput'); - -goog.require('Blockly.blockRendering.Connection'); -goog.require('Blockly.blockRendering.Types'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.Input'); - - -/** - * The base class to represent an input that takes up space on a block - * during rendering - * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering - * constants provider. - * @param {!Blockly.Input} input The input to measure and store information for. - * @package - * @constructor - * @extends {Blockly.blockRendering.Connection} - */ -Blockly.blockRendering.InputConnection = function(constants, input) { - Blockly.blockRendering.InputConnection.superClass_.constructor.call(this, - constants, input.connection); - - this.type |= Blockly.blockRendering.Types.INPUT; - this.input = input; - this.align = input.align; - this.connectedBlock = input.connection && input.connection.targetBlock() ? - input.connection.targetBlock() : null; - - if (this.connectedBlock) { - var bBox = this.connectedBlock.getHeightWidth(); - this.connectedBlockWidth = bBox.width; - this.connectedBlockHeight = bBox.height; - } else { - this.connectedBlockWidth = 0; - this.connectedBlockHeight = 0; - } - - this.connectionOffsetX = 0; - this.connectionOffsetY = 0; -}; -Blockly.utils.object.inherits(Blockly.blockRendering.InputConnection, - Blockly.blockRendering.Connection); - -/** - * An object containing information about the space an inline input takes up - * during rendering - * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering - * constants provider. - * @param {!Blockly.Input} input The inline input to measure and store - * information for. - * @package - * @constructor - * @extends {Blockly.blockRendering.InputConnection} - */ -Blockly.blockRendering.InlineInput = function(constants, input) { - Blockly.blockRendering.InlineInput.superClass_.constructor.call(this, - constants, input); - this.type |= Blockly.blockRendering.Types.INLINE_INPUT; - - if (!this.connectedBlock) { - this.height = this.constants_.EMPTY_INLINE_INPUT_HEIGHT; - this.width = this.constants_.EMPTY_INLINE_INPUT_PADDING; - } else { - // We allow the dark path to show on the parent block so that the child - // block looks embossed. This takes up an extra pixel in both x and y. - this.width = this.connectedBlockWidth; - this.height = this.connectedBlockHeight; - } - - this.connectionHeight = !this.isDynamicShape ? this.shape.height : - this.shape.height(this.height); - this.connectionWidth = !this.isDynamicShape ? this.shape.width : - this.shape.width(this.height); - if (!this.connectedBlock) { - this.width += this.connectionWidth * (this.isDynamicShape ? 2 : 1); - } - this.connectionOffsetY = this.isDynamicShape ? - this.shape.connectionOffsetY(this.connectionHeight) : - this.constants_.TAB_OFFSET_FROM_TOP; - this.connectionOffsetX = this.isDynamicShape ? - this.shape.connectionOffsetX(this.connectionWidth) : 0; -}; -Blockly.utils.object.inherits(Blockly.blockRendering.InlineInput, - Blockly.blockRendering.InputConnection); - -/** - * An object containing information about the space a statement input takes up - * during rendering - * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering - * constants provider. - * @param {!Blockly.Input} input The statement input to measure and store - * information for. - * @package - * @constructor - * @extends {Blockly.blockRendering.InputConnection} - */ -Blockly.blockRendering.StatementInput = function(constants, input) { - Blockly.blockRendering.StatementInput.superClass_.constructor.call(this, - constants, input); - this.type |= Blockly.blockRendering.Types.STATEMENT_INPUT; - - if (!this.connectedBlock) { - this.height = this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT; - } else { - // We allow the dark path to show on the parent block so that the child - // block looks embossed. This takes up an extra pixel in both x and y. - this.height = - this.connectedBlockHeight + this.constants_.STATEMENT_BOTTOM_SPACER; - } - this.width = this.constants_.STATEMENT_INPUT_NOTCH_OFFSET + this.shape.width; -}; -Blockly.utils.object.inherits(Blockly.blockRendering.StatementInput, - Blockly.blockRendering.InputConnection); - -/** - * An object containing information about the space an external value input - * takes up during rendering - * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering - * constants provider. - * @param {!Blockly.Input} input The external value input to measure and store - * information for. - * @package - * @constructor - * @extends {Blockly.blockRendering.InputConnection} - */ -Blockly.blockRendering.ExternalValueInput = function(constants, input) { - Blockly.blockRendering.ExternalValueInput.superClass_.constructor.call(this, - constants, input); - this.type |= Blockly.blockRendering.Types.EXTERNAL_VALUE_INPUT; - if (!this.connectedBlock) { - this.height = this.shape.height; - } else { - this.height = - this.connectedBlockHeight - this.constants_.TAB_OFFSET_FROM_TOP - - this.constants_.MEDIUM_PADDING; - } - this.width = this.shape.width + - this.constants_.EXTERNAL_VALUE_INPUT_PADDING; - - this.connectionOffsetY = this.constants_.TAB_OFFSET_FROM_TOP; - this.connectionHeight = this.shape.height; - this.connectionWidth = this.shape.width; -}; -Blockly.utils.object.inherits(Blockly.blockRendering.ExternalValueInput, - Blockly.blockRendering.InputConnection); diff --git a/core/renderers/measurables/statement_input.js b/core/renderers/measurables/statement_input.js new file mode 100644 index 000000000..6bd1c23fa --- /dev/null +++ b/core/renderers/measurables/statement_input.js @@ -0,0 +1,50 @@ +/** + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Class representing statement inputs with connections on a + * rendered block. + * @author fenichel@google.com (Rachel Fenichel) + */ + +goog.provide('Blockly.blockRendering.StatementInput'); + +goog.require('Blockly.blockRendering.InputConnection'); +goog.require('Blockly.blockRendering.Types'); +goog.require('Blockly.utils.object'); + +goog.requireType('Blockly.blockRendering.ConstantProvider'); +goog.requireType('Blockly.Input'); + + +/** + * An object containing information about the space a statement input takes up + * during rendering + * @param {!Blockly.blockRendering.ConstantProvider} constants The rendering + * constants provider. + * @param {!Blockly.Input} input The statement input to measure and store + * information for. + * @package + * @constructor + * @extends {Blockly.blockRendering.InputConnection} + */ +Blockly.blockRendering.StatementInput = function(constants, input) { + Blockly.blockRendering.StatementInput.superClass_.constructor.call(this, + constants, input); + this.type |= Blockly.blockRendering.Types.STATEMENT_INPUT; + + if (!this.connectedBlock) { + this.height = this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT; + } else { + // We allow the dark path to show on the parent block so that the child + // block looks embossed. This takes up an extra pixel in both x and y. + this.height = + this.connectedBlockHeight + this.constants_.STATEMENT_BOTTOM_SPACER; + } + this.width = this.constants_.STATEMENT_INPUT_NOTCH_OFFSET + this.shape.width; +}; +Blockly.utils.object.inherits(Blockly.blockRendering.StatementInput, + Blockly.blockRendering.InputConnection); diff --git a/tests/deps.js b/tests/deps.js index 8db3435f9..590b1a3d5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -148,9 +148,12 @@ goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras. goog.addDependency('../../core/renderers/geras/renderer.js', ['Blockly.geras.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.geras.ConstantProvider', 'Blockly.geras.Drawer', 'Blockly.geras.HighlightConstantProvider', 'Blockly.geras.PathObject', 'Blockly.geras.RenderInfo', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/measurables/base.js', ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.Types'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/measurables/connections.js', ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/measurables/inputs.js', ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.StatementInput'], ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/measurables/external_value_input.js', ['Blockly.blockRendering.ExternalValueInput'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/measurables/inline_input.js', ['Blockly.blockRendering.InlineInput'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/measurables/input_connection.js', ['Blockly.blockRendering.InputConnection'], ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/measurables/row_elements.js', ['Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.SquareCorner'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/measurables/rows.js', ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/measurables/statement_input.js', ['Blockly.blockRendering.StatementInput'], ['Blockly.blockRendering.InputConnection', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/measurables/types.js', ['Blockly.blockRendering.Types'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/minimalist/constants.js', ['Blockly.minimalist.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/minimalist/drawer.js', ['Blockly.minimalist.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});