From 214492cd088740fb9af0401321d138dea82c7ada Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 9 Jul 2021 12:41:13 +0100 Subject: [PATCH 001/833] Use the current standard Closure base.js The version of base.js we have been using is a cut-down copy of an older version, stripped of everything that wasn't strictly needed for Blockly. We now need things that were previously stripped out, so restore the current version from https://github.com/google/closure-library/blob/master/closure/goog/base.js as of commit 5cb5e81 (2021-06-04). We can always strip out unused sections again in future - once we know which sections those are. --- closure/goog/base.js | 3843 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 3597 insertions(+), 246 deletions(-) diff --git a/closure/goog/base.js b/closure/goog/base.js index 52a15dbcb..310db20f7 100644 --- a/closure/goog/base.js +++ b/closure/goog/base.js @@ -1,16 +1,8 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/** + * @license + * Copyright The Closure Library Authors. + * SPDX-License-Identifier: Apache-2.0 + */ /** * @fileoverview Bootstrap for the Google JS Library (Closure). @@ -26,6 +18,12 @@ */ +/** + * @define {boolean} Overridden to true by the compiler. + */ +var COMPILED = false; + + /** * Base namespace for the Closure library. Checks to see goog is already * defined in the current scope before assigning to prevent clobbering if @@ -57,17 +55,65 @@ goog.global = // For in-page browser environments and workers. self; + +/** + * A hook for overriding the define values in uncompiled mode. + * + * In uncompiled mode, `CLOSURE_UNCOMPILED_DEFINES` may be defined before + * loading base.js. If a key is defined in `CLOSURE_UNCOMPILED_DEFINES`, + * `goog.define` will use the value instead of the default value. This + * allows flags to be overwritten without compilation (this is normally + * accomplished with the compiler's "define" flag). + * + * Example: + *
+ *   var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
+ * 
+ * + * @type {Object|undefined} + */ +goog.global.CLOSURE_UNCOMPILED_DEFINES; + + +/** + * A hook for overriding the define values in uncompiled or compiled mode, + * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In + * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence. + * + * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or + * string literals or the compiler will emit an error. + * + * While any @define value may be set, only those set with goog.define will be + * effective for uncompiled code. + * + * Example: + *
+ *   var CLOSURE_DEFINES = {'goog.DEBUG': false} ;
+ * 
+ * + * @type {Object|undefined} + */ +goog.global.CLOSURE_DEFINES; + + /** * Builds an object structure for the provided namespace path, ensuring that * names that already exist are not overwritten. For example: * "a.b.c" -> a = {};a.b={};a.b.c={}; * Used by goog.provide and goog.exportSymbol. - * @param {string} name name of the object that this file defines. + * @param {string} name The name of the object that this file defines. + * @param {*=} object The object to expose at the end of the path. + * @param {boolean=} overwriteImplicit If object is set and a previous call + * implicitly constructed the namespace given by name, this parameter + * controls whether object should overwrite the implicitly constructed + * namespace or be merged into it. Defaults to false. + * @param {?Object=} objectToExportTo The object to add the path to; if this + * field is not specified, its value defaults to `goog.global`. * @private */ -goog.exportPath_ = function(name) { +goog.exportPath_ = function(name, object, overwriteImplicit, objectToExportTo) { var parts = name.split('.'); - var cur = goog.global; + var cur = objectToExportTo || goog.global; // Internet Explorer exhibits strange behavior when throwing errors from // methods externed in this manner. See the testExportSymbolExceptions in @@ -77,7 +123,24 @@ goog.exportPath_ = function(name) { } for (var part; parts.length && (part = parts.shift());) { - if (cur[part] && cur[part] !== Object.prototype[part]) { + if (!parts.length && object !== undefined) { + if (!overwriteImplicit && goog.isObject(object) && + goog.isObject(cur[part])) { + // Merge properties on object (the input parameter) with the existing + // implicitly defined namespace, so as to not clobber previously + // defined child namespaces. + for (var prop in object) { + if (object.hasOwnProperty(prop)) { + cur[part][prop] = object[prop]; + } + } + } else { + // Either there is no existing implicit namespace, or overwriteImplicit + // is set to true, so directly assign object (the input parameter) to + // the namespace. + cur[part] = object; + } + } else if (cur[part] && cur[part] !== Object.prototype[part]) { cur = cur[part]; } else { cur = cur[part] = {}; @@ -85,6 +148,152 @@ goog.exportPath_ = function(name) { } }; + +/** + * Defines a named value. In uncompiled mode, the value is retrieved from + * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and + * has the property specified, and otherwise used the defined defaultValue. + * When compiled the default can be overridden using the compiler options or the + * value set in the CLOSURE_DEFINES object. Returns the defined value so that it + * can be used safely in modules. Note that the value type MUST be either + * boolean, number, or string. + * + * @param {string} name The distinguished name to provide. + * @param {T} defaultValue + * @return {T} The defined value. + * @template T + */ +goog.define = function(name, defaultValue) { + var value = defaultValue; + if (!COMPILED) { + var uncompiledDefines = goog.global.CLOSURE_UNCOMPILED_DEFINES; + var defines = goog.global.CLOSURE_DEFINES; + if (uncompiledDefines && + // Anti DOM-clobbering runtime check (b/37736576). + /** @type {?} */ (uncompiledDefines).nodeType === undefined && + Object.prototype.hasOwnProperty.call(uncompiledDefines, name)) { + value = uncompiledDefines[name]; + } else if ( + defines && + // Anti DOM-clobbering runtime check (b/37736576). + /** @type {?} */ (defines).nodeType === undefined && + Object.prototype.hasOwnProperty.call(defines, name)) { + value = defines[name]; + } + } + return value; +}; + + +/** + * @define {number} Integer year indicating the set of browser features that are + * guaranteed to be present. This is defined to include exactly features that + * work correctly on all "modern" browsers that are stable on January 1 of the + * specified year. For example, + * ```js + * if (goog.FEATURESET_YEAR >= 2019) { + * // use APIs known to be available on all major stable browsers Jan 1, 2019 + * } else { + * // polyfill for older browsers + * } + * ``` + * This is intended to be the primary define for removing + * unnecessary browser compatibility code (such as ponyfills and workarounds), + * and should inform the default value for most other defines: + * ```js + * const ASSUME_NATIVE_PROMISE = + * goog.define('ASSUME_NATIVE_PROMISE', goog.FEATURESET_YEAR >= 2016); + * ``` + * + * The default assumption is that IE9 is the lowest supported browser, which was + * first available Jan 1, 2012. + * + * TODO(user): Reference more thorough documentation when it's available. + */ +goog.FEATURESET_YEAR = goog.define('goog.FEATURESET_YEAR', 2012); + + +/** + * @define {boolean} DEBUG is provided as a convenience so that debugging code + * that should not be included in a production. It can be easily stripped + * by specifying --define goog.DEBUG=false to the Closure Compiler aka + * JSCompiler. For example, most toString() methods should be declared inside an + * "if (goog.DEBUG)" conditional because they are generally used for debugging + * purposes and it is difficult for the JSCompiler to statically determine + * whether they are used. + */ +goog.DEBUG = goog.define('goog.DEBUG', true); + + +/** + * @define {string} LOCALE defines the locale being used for compilation. It is + * used to select locale specific data to be compiled in js binary. BUILD rule + * can specify this value by "--define goog.LOCALE=" as a compiler + * option. + * + * Take into account that the locale code format is important. You should use + * the canonical Unicode format with hyphen as a delimiter. Language must be + * lowercase, Language Script - Capitalized, Region - UPPERCASE. + * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN. + * + * See more info about locale codes here: + * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers + * + * For language codes you should use values defined by ISO 693-1. See it here + * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from + * this rule: the Hebrew language. For legacy reasons the old code (iw) should + * be used instead of the new code (he). + * + */ +goog.LOCALE = goog.define('goog.LOCALE', 'en'); // default to en + + +/** + * This method is intended to be used for bookkeeping purposes. We would + * like to distinguish uses of goog.LOCALE used for code stripping purposes + * and uses of goog.LOCALE for other uses (such as URL parameters). + * + * This allows us to ban direct uses of goog.LOCALE and to ensure that all + * code has been transformed to our new localization build scheme. + * + * @return {string} + * + */ +goog.getLocale = function() { + return goog.LOCALE; +}; + + +/** + * @define {boolean} Whether this code is running on trusted sites. + * + * On untrusted sites, several native functions can be defined or overridden by + * external libraries like Prototype, Datejs, and JQuery and setting this flag + * to false forces closure to use its own implementations when possible. + * + * If your JavaScript can be loaded by a third party site and you are wary about + * relying on non-standard implementations, specify + * "--define goog.TRUSTED_SITE=false" to the compiler. + */ +goog.TRUSTED_SITE = goog.define('goog.TRUSTED_SITE', true); + + +/** + * @define {boolean} Whether code that calls {@link goog.setTestOnly} should + * be disallowed in the compilation unit. + */ +goog.DISALLOW_TEST_ONLY_CODE = + goog.define('goog.DISALLOW_TEST_ONLY_CODE', COMPILED && !goog.DEBUG); + + +/** + * @define {boolean} Whether to use a Chrome app CSP-compliant method for + * loading scripts via goog.require. @see appendScriptSrcNode_. + */ +goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING = + goog.define('goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING', false); + + /** * Defines a namespace in Closure. * @@ -106,27 +315,199 @@ goog.exportPath_ = function(name) { * @see goog.module * @param {string} name Namespace provided by this file in the form * "goog.package.part". + * deprecated Use goog.module (see b/159289405) */ goog.provide = function(name) { - // Ensure that the same namespace isn't provided twice. - // A goog.module/goog.provide maps a goog.require to a specific file - if (goog.isProvided_(name)) { - throw Error('Namespace "' + name + '" already declared.'); + if (goog.isInModuleLoader_()) { + throw new Error('goog.provide cannot be used within a module.'); } - - delete goog.implicitNamespaces_[name]; - - var namespace = name; - while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) { - if (goog.getObjectByName(namespace)) { - break; + if (!COMPILED) { + // Ensure that the same namespace isn't provided twice. + // A goog.module/goog.provide maps a goog.require to a specific file + if (goog.isProvided_(name)) { + throw new Error('Namespace "' + name + '" already declared.'); } - goog.implicitNamespaces_[namespace] = true; } - goog.exportPath_(name); + goog.constructNamespace_(name); }; + +/** + * @param {string} name Namespace provided by this file in the form + * "goog.package.part". + * @param {?Object=} object The object to embed in the namespace. + * @param {boolean=} overwriteImplicit If object is set and a previous call + * implicitly constructed the namespace given by name, this parameter + * controls whether opt_obj should overwrite the implicitly constructed + * namespace or be merged into it. Defaults to false. + * @private + */ +goog.constructNamespace_ = function(name, object, overwriteImplicit) { + if (!COMPILED) { + delete goog.implicitNamespaces_[name]; + + var namespace = name; + while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) { + if (goog.getObjectByName(namespace)) { + break; + } + goog.implicitNamespaces_[namespace] = true; + } + } + + goog.exportPath_(name, object, overwriteImplicit); +}; + + +/** + * According to the CSP3 spec a nonce must be a valid base64 string. + * @see https://www.w3.org/TR/CSP3/#grammardef-base64-value + * @private @const + */ +goog.NONCE_PATTERN_ = /^[\w+/_-]+[=]{0,2}$/; + + +/** + * Returns CSP nonce, if set for any script tag. + * @param {?Window=} opt_window The window context used to retrieve the nonce. + * Defaults to global context. + * @return {string} CSP nonce or empty string if no nonce is present. + * @private + */ +goog.getScriptNonce_ = function(opt_window) { + var doc = (opt_window || goog.global).document; + var script = doc.querySelector && doc.querySelector('script[nonce]'); + if (script) { + // Try to get the nonce from the IDL property first, because browsers that + // implement additional nonce protection features (currently only Chrome) to + // prevent nonce stealing via CSS do not expose the nonce via attributes. + // See https://github.com/whatwg/html/issues/2369 + var nonce = script['nonce'] || script.getAttribute('nonce'); + if (nonce && goog.NONCE_PATTERN_.test(nonce)) { + return nonce; + } + } + return ''; +}; + + +/** + * Module identifier validation regexp. + * Note: This is a conservative check, it is very possible to be more lenient, + * the primary exclusion here is "/" and "\" and a leading ".", these + * restrictions are intended to leave the door open for using goog.require + * with relative file paths rather than module identifiers. + * @private + */ +goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/; + + +/** + * Defines a module in Closure. + * + * Marks that this file must be loaded as a module and claims the namespace. + * + * A namespace may only be defined once in a codebase. It may be defined using + * goog.provide() or goog.module(). + * + * goog.module() has three requirements: + * - goog.module may not be used in the same file as goog.provide. + * - goog.module must be the first statement in the file. + * - only one goog.module is allowed per file. + * + * When a goog.module annotated file is loaded, it is enclosed in + * a strict function closure. This means that: + * - any variables declared in a goog.module file are private to the file + * (not global), though the compiler is expected to inline the module. + * - The code must obey all the rules of "strict" JavaScript. + * - the file will be marked as "use strict" + * + * NOTE: unlike goog.provide, goog.module does not declare any symbols by + * itself. If declared symbols are desired, use + * goog.module.declareLegacyNamespace(). + * + * + * See the public goog.module proposal: http://goo.gl/Va1hin + * + * @param {string} name Namespace provided by this file in the form + * "goog.package.part", is expected but not required. + * @return {void} + */ +goog.module = function(name) { + if (typeof name !== 'string' || !name || + name.search(goog.VALID_MODULE_RE_) == -1) { + throw new Error('Invalid module identifier'); + } + if (!goog.isInGoogModuleLoader_()) { + throw new Error( + 'Module ' + name + ' has been loaded incorrectly. Note, ' + + 'modules cannot be loaded as normal scripts. They require some kind of ' + + 'pre-processing step. You\'re likely trying to load a module via a ' + + 'script tag or as a part of a concatenated bundle without rewriting the ' + + 'module. For more info see: ' + + 'https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.'); + } + if (goog.moduleLoaderState_.moduleName) { + throw new Error('goog.module may only be called once per module.'); + } + + // Store the module name for the loader. + goog.moduleLoaderState_.moduleName = name; + if (!COMPILED) { + // Ensure that the same namespace isn't provided twice. + // A goog.module/goog.provide maps a goog.require to a specific file + if (goog.isProvided_(name)) { + throw new Error('Namespace "' + name + '" already declared.'); + } + delete goog.implicitNamespaces_[name]; + } +}; + + +/** + * @param {string} name The module identifier. + * @return {?} The module exports for an already loaded module or null. + * + * Note: This is not an alternative to goog.require, it does not + * indicate a hard dependency, instead it is used to indicate + * an optional dependency or to access the exports of a module + * that has already been loaded. + * @suppress {missingProvide} + */ +goog.module.get = function(name) { + return goog.module.getInternal_(name); +}; + + +/** + * @param {string} name The module identifier. + * @return {?} The module exports for an already loaded module or null. + * @private + */ +goog.module.getInternal_ = function(name) { + if (!COMPILED) { + if (name in goog.loadedModules_) { + return goog.loadedModules_[name].exports; + } else if (!goog.implicitNamespaces_[name]) { + var ns = goog.getObjectByName(name); + return ns != null ? ns : null; + } + } + return null; +}; + + +/** + * Types of modules the debug loader can load. + * @enum {string} + */ +goog.ModuleType = { + ES6: 'es6', + GOOG: 'goog' +}; + + /** * @private {?{ * moduleName: (string|undefined), @@ -136,32 +517,210 @@ goog.provide = function(name) { */ goog.moduleLoaderState_ = null; + /** - * Check if the given name has been goog.provided. This will return false for - * names that are available only as implicit namespaces. - * @param {string} name name of the object to look for. - * @return {boolean} Whether the name has been provided. * @private + * @return {boolean} Whether a goog.module or an es6 module is currently being + * initialized. */ -goog.isProvided_ = function(name) { - return (!goog.implicitNamespaces_[name] && - goog.isDefAndNotNull(goog.getObjectByName(name))); +goog.isInModuleLoader_ = function() { + return goog.isInGoogModuleLoader_() || goog.isInEs6ModuleLoader_(); }; -/** - * Namespaces implicitly defined by goog.provide. For example, - * goog.provide('goog.events.Event') implicitly declares that 'goog' and - * 'goog.events' must be namespaces. - * - * @type {!Object} - * @private - */ -goog.implicitNamespaces_ = {}; -// NOTE: We add goog.module as an implicit namespace as goog.module is defined -// here and because the existing module package has not been moved yet out of -// the goog.module namespace. This satisfies both the debug loader and -// ahead-of-time dependency management. +/** + * @private + * @return {boolean} Whether a goog.module is currently being initialized. + */ +goog.isInGoogModuleLoader_ = function() { + return !!goog.moduleLoaderState_ && + goog.moduleLoaderState_.type == goog.ModuleType.GOOG; +}; + + +/** + * @private + * @return {boolean} Whether an es6 module is currently being initialized. + */ +goog.isInEs6ModuleLoader_ = function() { + var inLoader = !!goog.moduleLoaderState_ && + goog.moduleLoaderState_.type == goog.ModuleType.ES6; + + if (inLoader) { + return true; + } + + var jscomp = goog.global['$jscomp']; + + if (jscomp) { + // jscomp may not have getCurrentModulePath if this is a compiled bundle + // that has some of the runtime, but not all of it. This can happen if + // optimizations are turned on so the unused runtime is removed but renaming + // and Closure pass are off (so $jscomp is still named $jscomp and the + // goog.provide/require calls still exist). + if (typeof jscomp.getCurrentModulePath != 'function') { + return false; + } + + // Bundled ES6 module. + return !!jscomp.getCurrentModulePath(); + } + + return false; +}; + + +/** + * Provide the module's exports as a globally accessible object under the + * module's declared name. This is intended to ease migration to goog.module + * for files that have existing usages. + * @suppress {missingProvide} + */ +goog.module.declareLegacyNamespace = function() { + if (!COMPILED && !goog.isInGoogModuleLoader_()) { + throw new Error( + 'goog.module.declareLegacyNamespace must be called from ' + + 'within a goog.module'); + } + if (!COMPILED && !goog.moduleLoaderState_.moduleName) { + throw new Error( + 'goog.module must be called prior to ' + + 'goog.module.declareLegacyNamespace.'); + } + goog.moduleLoaderState_.declareLegacyNamespace = true; +}; + + +/** + * Associates an ES6 module with a Closure module ID so that is available via + * goog.require. The associated ID acts like a goog.module ID - it does not + * create any global names, it is merely available via goog.require / + * goog.module.get / goog.forwardDeclare / goog.requireType. goog.require and + * goog.module.get will return the entire module as if it was import *'d. This + * allows Closure files to reference ES6 modules for the sake of migration. + * + * @param {string} namespace + * @suppress {missingProvide} + */ +goog.declareModuleId = function(namespace) { + if (!COMPILED) { + if (!goog.isInEs6ModuleLoader_()) { + throw new Error( + 'goog.declareModuleId may only be called from ' + + 'within an ES6 module'); + } + if (goog.moduleLoaderState_ && goog.moduleLoaderState_.moduleName) { + throw new Error( + 'goog.declareModuleId may only be called once per module.'); + } + if (namespace in goog.loadedModules_) { + throw new Error( + 'Module with namespace "' + namespace + '" already exists.'); + } + } + if (goog.moduleLoaderState_) { + // Not bundled - debug loading. + goog.moduleLoaderState_.moduleName = namespace; + } else { + // Bundled - not debug loading, no module loader state. + var jscomp = goog.global['$jscomp']; + if (!jscomp || typeof jscomp.getCurrentModulePath != 'function') { + throw new Error( + 'Module with namespace "' + namespace + + '" has been loaded incorrectly.'); + } + var exports = jscomp.require(jscomp.getCurrentModulePath()); + goog.loadedModules_[namespace] = { + exports: exports, + type: goog.ModuleType.ES6, + moduleId: namespace + }; + } +}; + + +/** + * Marks that the current file should only be used for testing, and never for + * live code in production. + * + * In the case of unit tests, the message may optionally be an exact namespace + * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra + * provide (if not explicitly defined in the code). + * + * @param {string=} opt_message Optional message to add to the error that's + * raised when used in production code. + */ +goog.setTestOnly = function(opt_message) { + if (goog.DISALLOW_TEST_ONLY_CODE) { + opt_message = opt_message || ''; + throw new Error( + 'Importing test-only code into non-debug environment' + + (opt_message ? ': ' + opt_message : '.')); + } +}; + + +/** + * Forward declares a symbol. This is an indication to the compiler that the + * symbol may be used in the source yet is not required and may not be provided + * in compilation. + * + * The most common usage of forward declaration is code that takes a type as a + * function parameter but does not need to require it. By forward declaring + * instead of requiring, no hard dependency is made, and (if not required + * elsewhere) the namespace may never be required and thus, not be pulled + * into the JavaScript binary. If it is required elsewhere, it will be type + * checked as normal. + * + * Before using goog.forwardDeclare, please read the documentation at + * https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation to + * understand the options and tradeoffs when working with forward declarations. + * + * @param {string} name The namespace to forward declare in the form of + * "goog.package.part". + * @deprecated See go/noforwarddeclaration, Use `goog.requireType` instead. + */ +goog.forwardDeclare = function(name) {}; + + +/** + * Forward declare type information. Used to assign types to goog.global + * referenced object that would otherwise result in unknown type references + * and thus block property disambiguation. + */ +goog.forwardDeclare('Document'); +goog.forwardDeclare('HTMLScriptElement'); +goog.forwardDeclare('XMLHttpRequest'); + + +if (!COMPILED) { + /** + * Check if the given name has been goog.provided. This will return false for + * names that are available only as implicit namespaces. + * @param {string} name name of the object to look for. + * @return {boolean} Whether the name has been provided. + * @private + */ + goog.isProvided_ = function(name) { + return (name in goog.loadedModules_) || + (!goog.implicitNamespaces_[name] && goog.getObjectByName(name) != null); + }; + + /** + * Namespaces implicitly defined by goog.provide. For example, + * goog.provide('goog.events.Event') implicitly declares that 'goog' and + * 'goog.events' must be namespaces. + * + * @type {!Object} + * @private + */ + goog.implicitNamespaces_ = {'goog.module': true}; + + // NOTE: We add goog.module as an implicit namespace as goog.module is defined + // here and because the existing module package has not been moved yet out of + // the goog.module namespace. This satisifies both the debug loader and + // ahead-of-time dependency management. +} /** @@ -180,7 +739,7 @@ goog.getObjectByName = function(name, opt_obj) { var cur = opt_obj || goog.global; for (var i = 0; i < parts.length; i++) { cur = cur[parts[i]]; - if (!goog.isDefAndNotNull(cur)) { + if (cur == null) { return null; } } @@ -195,14 +754,18 @@ goog.getObjectByName = function(name, opt_obj) { * the names of the objects this file provides. * @param {!Array} requires An array of strings with * the names of the objects this file requires. + * @param {boolean|!Object=} opt_loadFlags Parameters indicating + * how the file must be loaded. The boolean 'true' is equivalent + * to {'module': 'goog'} for backwards-compatibility. Valid properties + * and values include {'module': 'goog'} and {'lang': 'es6'}. */ -goog.addDependency = function(relPath, provides, requires) { - goog.debugLoader_.addDependency(relPath, provides, requires); +goog.addDependency = function(relPath, provides, requires, opt_loadFlags) { + if (!COMPILED && goog.DEPENDENCIES_ENABLED) { + goog.debugLoader_.addDependency(relPath, provides, requires, opt_loadFlags); + } }; - - // NOTE(nnaze): The debug DOM loader was included in base.js as an original way // to do "debug-mode" development. The dependency system can sometimes be // confusing, as can the debug DOM loader's asynchronous nature. @@ -222,6 +785,30 @@ goog.addDependency = function(relPath, provides, requires) { // for example). See bootstrap/ for more information. +/** + * @define {boolean} Whether to enable the debug loader. + * + * If enabled, a call to goog.require() will attempt to load the namespace by + * appending a script tag to the DOM (if the namespace has been registered). + * + * If disabled, goog.require() will simply assert that the namespace has been + * provided (and depend on the fact that some outside tool correctly ordered + * the script). + */ +goog.ENABLE_DEBUG_LOADER = goog.define('goog.ENABLE_DEBUG_LOADER', true); + + +/** + * @param {string} msg + * @private + */ +goog.logToConsole_ = function(msg) { + if (goog.global.console) { + goog.global.console['error'](msg); + } +}; + + /** * Implements a system for the dynamic resolution of dependencies that works in * parallel with the BUILD system. @@ -236,20 +823,32 @@ goog.addDependency = function(relPath, provides, requires) { * namespace or module otherwise null. */ goog.require = function(namespace) { - // If the object already exists we do not need to do anything. - if (!goog.isProvided_(namespace)) { - var moduleLoaderState = goog.moduleLoaderState_; - goog.moduleLoaderState_ = null; - try { - goog.debugLoader_.load_(namespace); - } finally { - goog.moduleLoaderState_ = moduleLoaderState; + if (!COMPILED) { + // Might need to lazy load on old IE. + if (goog.ENABLE_DEBUG_LOADER) { + goog.debugLoader_.requested(namespace); } - } - return null; + // If the object already exists we do not need to do anything. + if (goog.isProvided_(namespace)) { + if (goog.isInModuleLoader_()) { + return goog.module.getInternal_(namespace); + } + } else if (goog.ENABLE_DEBUG_LOADER) { + var moduleLoaderState = goog.moduleLoaderState_; + goog.moduleLoaderState_ = null; + try { + goog.debugLoader_.load_(namespace); + } finally { + goog.moduleLoaderState_ = moduleLoaderState; + } + } + + return null; + } }; + /** * Requires a symbol for its type information. This is an indication to the * compiler that the symbol may appear in type annotations, yet it is not @@ -273,12 +872,275 @@ goog.requireType = function(namespace) { return {}; }; + /** * Path for included scripts. * @type {string} */ goog.basePath = ''; + +/** + * A hook for overriding the base path. + * @type {string|undefined} + */ +goog.global.CLOSURE_BASE_PATH; + + +/** + * Whether to attempt to load Closure's deps file. By default, when uncompiled, + * deps files will attempt to be loaded. + * @type {boolean|undefined} + */ +goog.global.CLOSURE_NO_DEPS; + + +/** + * A function to import a single script. This is meant to be overridden when + * Closure is being run in non-HTML contexts, such as web workers. It's defined + * in the global scope so that it can be set before base.js is loaded, which + * allows deps.js to be imported properly. + * + * The first parameter the script source, which is a relative URI. The second, + * optional parameter is the script contents, in the event the script needed + * transformation. It should return true if the script was imported, false + * otherwise. + * @type {(function(string, string=): boolean)|undefined} + */ +goog.global.CLOSURE_IMPORT_SCRIPT; + + +/** + * Null function used for default values of callbacks, etc. + * @return {void} Nothing. + * @deprecated use '()=>{}' or 'function(){}' instead. + */ +goog.nullFunction = function() {}; + + +/** + * When defining a class Foo with an abstract method bar(), you can do: + * Foo.prototype.bar = goog.abstractMethod + * + * Now if a subclass of Foo fails to override bar(), an error will be thrown + * when bar() is invoked. + * + * @type {!Function} + * @throws {Error} when invoked to indicate the method should be overridden. + * @deprecated Use "@abstract" annotation instead of goog.abstractMethod in new + * code. See + * https://github.com/google/closure-compiler/wiki/@abstract-classes-and-methods + */ +goog.abstractMethod = function() { + throw new Error('unimplemented abstract method'); +}; + + +/** + * Adds a `getInstance` static method that always returns the same + * instance object. + * @param {!Function} ctor The constructor for the class to add the static + * method to. + * @suppress {missingProperties} 'instance_' isn't a property on 'Function' + * but we don't have a better type to use here. + */ +goog.addSingletonGetter = function(ctor) { + // instance_ is immediately set to prevent issues with sealed constructors + // such as are encountered when a constructor is returned as the export object + // of a goog.module in unoptimized code. + // Delcare type to avoid conformance violations that ctor.instance_ is unknown + /** @type {undefined|!Object} @suppress {underscore} */ + ctor.instance_ = undefined; + ctor.getInstance = function() { + if (ctor.instance_) { + return ctor.instance_; + } + if (goog.DEBUG) { + // NOTE: JSCompiler can't optimize away Array#push. + goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor; + } + // Cast to avoid conformance violations that ctor.instance_ is unknown + return /** @type {!Object|undefined} */ (ctor.instance_) = new ctor; + }; +}; + + +/** + * All singleton classes that have been instantiated, for testing. Don't read + * it directly, use the `goog.testing.singleton` module. The compiler + * removes this variable if unused. + * @type {!Array} + * @private + */ +goog.instantiatedSingletons_ = []; + + +/** + * @define {boolean} Whether to load goog.modules using `eval` when using + * the debug loader. This provides a better debugging experience as the + * source is unmodified and can be edited using Chrome Workspaces or similar. + * However in some environments the use of `eval` is banned + * so we provide an alternative. + */ +goog.LOAD_MODULE_USING_EVAL = goog.define('goog.LOAD_MODULE_USING_EVAL', true); + + +/** + * @define {boolean} Whether the exports of goog.modules should be sealed when + * possible. + */ +goog.SEAL_MODULE_EXPORTS = goog.define('goog.SEAL_MODULE_EXPORTS', goog.DEBUG); + + +/** + * The registry of initialized modules: + * The module identifier or path to module exports map. + * @private @const {!Object} + */ +goog.loadedModules_ = {}; + + +/** + * True if the debug loader enabled and used. + * @const {boolean} + */ +goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER; + + +/** + * @define {string} How to decide whether to transpile. Valid values + * are 'always', 'never', and 'detect'. The default ('detect') is to + * use feature detection to determine which language levels need + * transpilation. + */ +// NOTE(sdh): we could expand this to accept a language level to bypass +// detection: e.g. goog.TRANSPILE == 'es5' would transpile ES6 files but +// would leave ES3 and ES5 files alone. +goog.TRANSPILE = goog.define('goog.TRANSPILE', 'detect'); + +/** + * @define {boolean} If true assume that ES modules have already been + * transpiled by the jscompiler (in the same way that transpile.js would + * transpile them - to jscomp modules). Useful only for servers that wish to use + * the debug loader and transpile server side. Thus this is only respected if + * goog.TRANSPILE is "never". + */ +goog.ASSUME_ES_MODULES_TRANSPILED = + goog.define('goog.ASSUME_ES_MODULES_TRANSPILED', false); + + +/** + * @define {string} If a file needs to be transpiled what the output language + * should be. By default this is the highest language level this file detects + * the current environment supports. Generally this flag should not be set, but + * it could be useful to override. Example: If the current environment supports + * ES6 then by default ES7+ files will be transpiled to ES6, unless this is + * overridden. + * + * Valid values include: es3, es5, es6, es7, and es8. Anything not recognized + * is treated as es3. + * + * Note that setting this value does not force transpilation. Just if + * transpilation occurs this will be the output. So this is most useful when + * goog.TRANSPILE is set to 'always' and then forcing the language level to be + * something lower than what the environment detects. + */ +goog.TRANSPILE_TO_LANGUAGE = goog.define('goog.TRANSPILE_TO_LANGUAGE', ''); + + +/** + * @define {string} Path to the transpiler. Executing the script at this + * path (relative to base.js) should define a function $jscomp.transpile. + */ +goog.TRANSPILER = goog.define('goog.TRANSPILER', 'transpile.js'); + + +/** + * @define {string} Trusted Types policy name. If non-empty then Closure will + * use Trusted Types. + */ +goog.TRUSTED_TYPES_POLICY_NAME = + goog.define('goog.TRUSTED_TYPES_POLICY_NAME', 'goog'); + + +/** + * @package {?boolean} + * Visible for testing. + */ +goog.hasBadLetScoping = null; + + +/** + * @param {function(?):?|string} moduleDef The module definition. + */ +goog.loadModule = function(moduleDef) { + // NOTE: we allow function definitions to be either in the from + // of a string to eval (which keeps the original source intact) or + // in a eval forbidden environment (CSP) we allow a function definition + // which in its body must call `goog.module`, and return the exports + // of the module. + var previousState = goog.moduleLoaderState_; + try { + goog.moduleLoaderState_ = { + moduleName: '', + declareLegacyNamespace: false, + type: goog.ModuleType.GOOG + }; + var origExports = {}; + var exports = origExports; + if (typeof moduleDef === 'function') { + exports = moduleDef.call(undefined, exports); + } else if (typeof moduleDef === 'string') { + exports = goog.loadModuleFromSource_.call(undefined, exports, moduleDef); + } else { + throw new Error('Invalid module definition'); + } + + var moduleName = goog.moduleLoaderState_.moduleName; + if (typeof moduleName === 'string' && moduleName) { + // Don't seal legacy namespaces as they may be used as a parent of + // another namespace + if (goog.moduleLoaderState_.declareLegacyNamespace) { + // Whether exports was overwritten via default export assignment. + // This is important for legacy namespaces as it dictates whether + // previously a previously loaded implicit namespace should be clobbered + // or not. + var isDefaultExport = origExports !== exports; + goog.constructNamespace_(moduleName, exports, isDefaultExport); + } else if ( + goog.SEAL_MODULE_EXPORTS && Object.seal && + typeof exports == 'object' && exports != null) { + Object.seal(exports); + } + + var data = { + exports: exports, + type: goog.ModuleType.GOOG, + moduleId: goog.moduleLoaderState_.moduleName + }; + goog.loadedModules_[moduleName] = data; + } else { + throw new Error('Invalid module name \"' + moduleName + '\"'); + } + } finally { + goog.moduleLoaderState_ = previousState; + } +}; + + +/** + * @private @const + */ +goog.loadModuleFromSource_ = + /** @type {function(!Object, string):?} */ (function(exports) { + // NOTE: we avoid declaring parameters or local variables here to avoid + // masking globals or leaking values into the module definition. + 'use strict'; + eval(goog.CLOSURE_EVAL_PREFILTER_.createScript(arguments[1])); + return exports; + }); + + /** * Normalize a file path by removing redundant ".." and extraneous "." file * path components. @@ -304,228 +1166,2717 @@ goog.normalizePath_ = function(path) { }; +/** + * Provides a hook for loading a file when using Closure's goog.require() API + * with goog.modules. In particular this hook is provided to support Node.js. + * + * @type {(function(string):string)|undefined} + */ +goog.global.CLOSURE_LOAD_FILE_SYNC; + + +/** + * Loads file by synchronous XHR. Should not be used in production environments. + * @param {string} src Source URL. + * @return {?string} File contents, or null if load failed. + * @private + */ +goog.loadFileSync_ = function(src) { + if (goog.global.CLOSURE_LOAD_FILE_SYNC) { + return goog.global.CLOSURE_LOAD_FILE_SYNC(src); + } else { + try { + /** @type {XMLHttpRequest} */ + var xhr = new goog.global['XMLHttpRequest'](); + xhr.open('get', src, false); + xhr.send(); + // NOTE: Successful http: requests have a status of 200, but successful + // file: requests may have a status of zero. Any other status, or a + // thrown exception (particularly in case of file: requests) indicates + // some sort of error, which we treat as a missing or unavailable file. + return xhr.status == 0 || xhr.status == 200 ? xhr.responseText : null; + } catch (err) { + // No need to rethrow or log, since errors should show up on their own. + return null; + } + } +}; + + +/** + * Lazily retrieves the transpiler and applies it to the source. + * @param {string} code JS code. + * @param {string} path Path to the code. + * @param {string} target Language level output. + * @return {string} The transpiled code. + * @private + */ +goog.transpile_ = function(code, path, target) { + var jscomp = goog.global['$jscomp']; + if (!jscomp) { + goog.global['$jscomp'] = jscomp = {}; + } + var transpile = jscomp.transpile; + if (!transpile) { + var transpilerPath = goog.basePath + goog.TRANSPILER; + var transpilerCode = goog.loadFileSync_(transpilerPath); + if (transpilerCode) { + // This must be executed synchronously, since by the time we know we + // need it, we're about to load and write the ES6 code synchronously, + // so a normal script-tag load will be too slow. Wrapped in a function + // so that code is eval'd in the global scope. + (function() { + (0, eval)(transpilerCode + '\n//# sourceURL=' + transpilerPath); + }).call(goog.global); + // Even though the transpiler is optional, if $gwtExport is found, it's + // a sign the transpiler was loaded and the $jscomp.transpile *should* + // be there. + if (goog.global['$gwtExport'] && goog.global['$gwtExport']['$jscomp'] && + !goog.global['$gwtExport']['$jscomp']['transpile']) { + throw new Error( + 'The transpiler did not properly export the "transpile" ' + + 'method. $gwtExport: ' + JSON.stringify(goog.global['$gwtExport'])); + } + // transpile.js only exports a single $jscomp function, transpile. We + // grab just that and add it to the existing definition of $jscomp which + // contains the polyfills. + goog.global['$jscomp'].transpile = + goog.global['$gwtExport']['$jscomp']['transpile']; + jscomp = goog.global['$jscomp']; + transpile = jscomp.transpile; + } + } + if (!transpile) { + // The transpiler is an optional component. If it's not available then + // replace it with a pass-through function that simply logs. + var suffix = ' requires transpilation but no transpiler was found.'; + transpile = jscomp.transpile = function(code, path) { + // TODO(sdh): figure out some way to get this error to show up + // in test results, noting that the failure may occur in many + // different ways, including in loadModule() before the test + // runner even comes up. + goog.logToConsole_(path + suffix); + return code; + }; + } + // Note: any transpilation errors/warnings will be logged to the console. + return transpile(code, path, target); +}; + //============================================================================== // Language Enhancements //============================================================================== /** - * Returns true if the specified value is defined and not null. - * @param {?} val Variable to test. - * @return {boolean} Whether variable is defined and not null. + * This is a "fixed" version of the typeof operator. It differs from the typeof + * operator in such a way that null returns 'null' and arrays return 'array'. + * @param {?} value The value to get the type of. + * @return {string} The name of the type. */ -goog.isDefAndNotNull = function(val) { - // Note that undefined == null. - return val != null; +goog.typeOf = function(value) { + var s = typeof value; + + if (s != 'object') { + return s; + } + + if (!value) { + return 'null'; + } + + if (Array.isArray(value)) { + return 'array'; + } + return s; }; + +/** + * Returns true if the object looks like an array. To qualify as array like + * the value needs to be either a NodeList or an object with a Number length + * property. Note that for this function neither strings nor functions are + * considered "array-like". + * + * @param {?} val Variable to test. + * @return {boolean} Whether variable is an array. + */ +goog.isArrayLike = function(val) { + var type = goog.typeOf(val); + // We do not use goog.isObject here in order to exclude function values. + return type == 'array' || type == 'object' && typeof val.length == 'number'; +}; + + +/** + * Returns true if the object looks like a Date. To qualify as Date-like the + * value needs to be an object and have a getFullYear() function. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is a like a Date. + */ +goog.isDateLike = function(val) { + return goog.isObject(val) && typeof val.getFullYear == 'function'; +}; + + +/** + * Returns true if the specified value is an object. This includes arrays and + * functions. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is an object. + */ +goog.isObject = function(val) { + var type = typeof val; + return type == 'object' && val != null || type == 'function'; + // return Object(val) === val also works, but is slower, especially if val is + // not an object. +}; + + +/** + * Gets a unique ID for an object. This mutates the object so that further calls + * with the same object as a parameter returns the same value. The unique ID is + * guaranteed to be unique across the current session amongst objects that are + * passed into `getUid`. There is no guarantee that the ID is unique or + * consistent across sessions. It is unsafe to generate unique ID for function + * prototypes. + * + * @param {Object} obj The object to get the unique ID for. + * @return {number} The unique ID for the object. + */ +goog.getUid = function(obj) { + // TODO(arv): Make the type stricter, do not accept null. + return Object.prototype.hasOwnProperty.call(obj, goog.UID_PROPERTY_) && + obj[goog.UID_PROPERTY_] || + (obj[goog.UID_PROPERTY_] = ++goog.uidCounter_); +}; + + +/** + * Whether the given object is already assigned a unique ID. + * + * This does not modify the object. + * + * @param {!Object} obj The object to check. + * @return {boolean} Whether there is an assigned unique id for the object. + */ +goog.hasUid = function(obj) { + return !!obj[goog.UID_PROPERTY_]; +}; + + +/** + * Removes the unique ID from an object. This is useful if the object was + * previously mutated using `goog.getUid` in which case the mutation is + * undone. + * @param {Object} obj The object to remove the unique ID field from. + */ +goog.removeUid = function(obj) { + // TODO(arv): Make the type stricter, do not accept null. + + // In IE, DOM nodes are not instances of Object and throw an exception if we + // try to delete. Instead we try to use removeAttribute. + if (obj !== null && 'removeAttribute' in obj) { + obj.removeAttribute(goog.UID_PROPERTY_); + } + + try { + delete obj[goog.UID_PROPERTY_]; + } catch (ex) { + } +}; + + +/** + * Name for unique ID property. Initialized in a way to help avoid collisions + * with other closure JavaScript on the same page. + * @type {string} + * @private + */ +goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0); + + +/** + * Counter for UID. + * @type {number} + * @private + */ +goog.uidCounter_ = 0; + + +/** + * Clones a value. The input may be an Object, Array, or basic type. Objects and + * arrays will be cloned recursively. + * + * WARNINGS: + * goog.cloneObject does not detect reference loops. Objects that + * refer to themselves will cause infinite recursion. + * + * goog.cloneObject is unaware of unique identifiers, and copies + * UIDs created by getUid into cloned results. + * + * @param {*} obj The value to clone. + * @return {*} A clone of the input value. + * @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods. + */ +goog.cloneObject = function(obj) { + var type = goog.typeOf(obj); + if (type == 'object' || type == 'array') { + if (typeof obj.clone === 'function') { + return obj.clone(); + } + if (typeof Map !== 'undefined' && obj instanceof Map) { + return new Map(obj); + } else if (typeof Set !== 'undefined' && obj instanceof Set) { + return new Set(obj); + } + var clone = type == 'array' ? [] : {}; + for (var key in obj) { + clone[key] = goog.cloneObject(obj[key]); + } + return clone; + } + + return obj; +}; + + +/** + * A native implementation of goog.bind. + * @param {?function(this:T, ...)} fn A function to partially apply. + * @param {T} selfObj Specifies the object which this should point to when the + * function is run. + * @param {...*} var_args Additional arguments that are partially applied to the + * function. + * @return {!Function} A partially-applied form of the function goog.bind() was + * invoked as a method of. + * @template T + * @private + */ +goog.bindNative_ = function(fn, selfObj, var_args) { + return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments)); +}; + + +/** + * A pure-JS implementation of goog.bind. + * @param {?function(this:T, ...)} fn A function to partially apply. + * @param {T} selfObj Specifies the object which this should point to when the + * function is run. + * @param {...*} var_args Additional arguments that are partially applied to the + * function. + * @return {!Function} A partially-applied form of the function goog.bind() was + * invoked as a method of. + * @template T + * @private + */ +goog.bindJs_ = function(fn, selfObj, var_args) { + if (!fn) { + throw new Error(); + } + + if (arguments.length > 2) { + var boundArgs = Array.prototype.slice.call(arguments, 2); + return function() { + // Prepend the bound arguments to the current arguments. + var newArgs = Array.prototype.slice.call(arguments); + Array.prototype.unshift.apply(newArgs, boundArgs); + return fn.apply(selfObj, newArgs); + }; + + } else { + return function() { + return fn.apply(selfObj, arguments); + }; + } +}; + + +/** + * Partially applies this function to a particular 'this object' and zero or + * more arguments. The result is a new function with some arguments of the first + * function pre-filled and the value of this 'pre-specified'. + * + * Remaining arguments specified at call-time are appended to the pre-specified + * ones. + * + * Also see: {@link #partial}. + * + * Usage: + *
var barMethBound = goog.bind(myFunction, myObj, 'arg1', 'arg2');
+ * barMethBound('arg3', 'arg4');
+ * + * @param {?function(this:T, ...)} fn A function to partially apply. + * @param {T} selfObj Specifies the object which this should point to when the + * function is run. + * @param {...*} var_args Additional arguments that are partially applied to the + * function. + * @return {!Function} A partially-applied form of the function goog.bind() was + * invoked as a method of. + * @template T + * @suppress {deprecated} See above. + * @deprecated use `=> {}` or Function.prototype.bind instead. + */ +goog.bind = function(fn, selfObj, var_args) { + // TODO(nicksantos): narrow the type signature. + if (Function.prototype.bind && + // NOTE(nicksantos): Somebody pulled base.js into the default Chrome + // extension environment. This means that for Chrome extensions, they get + // the implementation of Function.prototype.bind that calls goog.bind + // instead of the native one. Even worse, we don't want to introduce a + // circular dependency between goog.bind and Function.prototype.bind, so + // we have to hack this to make sure it works correctly. + Function.prototype.bind.toString().indexOf('native code') != -1) { + goog.bind = goog.bindNative_; + } else { + goog.bind = goog.bindJs_; + } + return goog.bind.apply(null, arguments); +}; + + +/** + * Like goog.bind(), except that a 'this object' is not required. Useful when + * the target function is already bound. + * + * Usage: + * var g = goog.partial(f, arg1, arg2); + * g(arg3, arg4); + * + * @param {Function} fn A function to partially apply. + * @param {...*} var_args Additional arguments that are partially applied to fn. + * @return {!Function} A partially-applied form of the function goog.partial() + * was invoked as a method of. + */ +goog.partial = function(fn, var_args) { + var args = Array.prototype.slice.call(arguments, 1); + return function() { + // Clone the array (with slice()) and append additional arguments + // to the existing arguments. + var newArgs = args.slice(); + newArgs.push.apply(newArgs, arguments); + return fn.apply(/** @type {?} */ (this), newArgs); + }; +}; + + +/** + * Copies all the members of a source object to a target object. This method + * does not work on all browsers for all objects that contain keys such as + * toString or hasOwnProperty. Use goog.object.extend for this purpose. + * + * NOTE: Some have advocated for the use of goog.mixin to setup classes + * with multiple inheritence (traits, mixins, etc). However, as it simply + * uses "for in", this is not compatible with ES6 classes whose methods are + * non-enumerable. Changing this, would break cases where non-enumerable + * properties are not expected. + * + * @param {Object} target Target. + * @param {Object} source Source. + * @deprecated Prefer Object.assign + */ +goog.mixin = function(target, source) { + for (var x in source) { + target[x] = source[x]; + } + + // For IE7 or lower, the for-in-loop does not contain any properties that are + // not enumerable on the prototype object (for example, isPrototypeOf from + // Object.prototype) but also it will not include 'replace' on objects that + // extend String and change 'replace' (not that it is common for anyone to + // extend anything except Object). +}; + + +/** + * @return {number} An integer value representing the number of milliseconds + * between midnight, January 1, 1970 and the current time. + * @deprecated Use Date.now + */ +goog.now = function() { + return Date.now(); +}; + + +/** + * Evals JavaScript in the global scope. + * + * Throws an exception if neither execScript or eval is defined. + * @param {string|!TrustedScript} script JavaScript string. + */ +goog.globalEval = function(script) { + (0, eval)(script); +}; + + +/** + * Optional map of CSS class names to obfuscated names used with + * goog.getCssName(). + * @private {!Object|undefined} + * @see goog.setCssNameMapping + */ +goog.cssNameMapping_; + + +/** + * Optional obfuscation style for CSS class names. Should be set to either + * 'BY_WHOLE' or 'BY_PART' if defined. + * @type {string|undefined} + * @private + * @see goog.setCssNameMapping + */ +goog.cssNameMappingStyle_; + + + +/** + * A hook for modifying the default behavior goog.getCssName. The function + * if present, will receive the standard output of the goog.getCssName as + * its input. + * + * @type {(function(string):string)|undefined} + */ +goog.global.CLOSURE_CSS_NAME_MAP_FN; + + +/** + * Handles strings that are intended to be used as CSS class names. + * + * This function works in tandem with @see goog.setCssNameMapping. + * + * Without any mapping set, the arguments are simple joined with a hyphen and + * passed through unaltered. + * + * When there is a mapping, there are two possible styles in which these + * mappings are used. In the BY_PART style, each part (i.e. in between hyphens) + * of the passed in css name is rewritten according to the map. In the BY_WHOLE + * style, the full css name is looked up in the map directly. If a rewrite is + * not specified by the map, the compiler will output a warning. + * + * When the mapping is passed to the compiler, it will replace calls to + * goog.getCssName with the strings from the mapping, e.g. + * var x = goog.getCssName('foo'); + * var y = goog.getCssName(this.baseClass, 'active'); + * becomes: + * var x = 'foo'; + * var y = this.baseClass + '-active'; + * + * If one argument is passed it will be processed, if two are passed only the + * modifier will be processed, as it is assumed the first argument was generated + * as a result of calling goog.getCssName. + * + * @param {string} className The class name. + * @param {string=} opt_modifier A modifier to be appended to the class name. + * @return {string} The class name or the concatenation of the class name and + * the modifier. + */ +goog.getCssName = function(className, opt_modifier) { + // String() is used for compatibility with compiled soy where the passed + // className can be non-string objects. + if (String(className).charAt(0) == '.') { + throw new Error( + 'className passed in goog.getCssName must not start with ".".' + + ' You passed: ' + className); + } + + var getMapping = function(cssName) { + return goog.cssNameMapping_[cssName] || cssName; + }; + + var renameByParts = function(cssName) { + // Remap all the parts individually. + var parts = cssName.split('-'); + var mapped = []; + for (var i = 0; i < parts.length; i++) { + mapped.push(getMapping(parts[i])); + } + return mapped.join('-'); + }; + + var rename; + if (goog.cssNameMapping_) { + rename = + goog.cssNameMappingStyle_ == 'BY_WHOLE' ? getMapping : renameByParts; + } else { + rename = function(a) { + return a; + }; + } + + var result = + opt_modifier ? className + '-' + rename(opt_modifier) : rename(className); + + // The special CLOSURE_CSS_NAME_MAP_FN allows users to specify further + // processing of the class name. + if (goog.global.CLOSURE_CSS_NAME_MAP_FN) { + return goog.global.CLOSURE_CSS_NAME_MAP_FN(result); + } + + return result; +}; + + +/** + * Sets the map to check when returning a value from goog.getCssName(). Example: + *
+ * goog.setCssNameMapping({
+ *   "goog": "a",
+ *   "disabled": "b",
+ * });
+ *
+ * var x = goog.getCssName('goog');
+ * // The following evaluates to: "a a-b".
+ * goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')
+ * 
+ * When declared as a map of string literals to string literals, the JSCompiler + * will replace all calls to goog.getCssName() using the supplied map if the + * --process_closure_primitives flag is set. + * + * @param {!Object} mapping A map of strings to strings where keys are possible + * arguments to goog.getCssName() and values are the corresponding values + * that should be returned. + * @param {string=} opt_style The style of css name mapping. There are two valid + * options: 'BY_PART', and 'BY_WHOLE'. + * @see goog.getCssName for a description. + */ +goog.setCssNameMapping = function(mapping, opt_style) { + goog.cssNameMapping_ = mapping; + goog.cssNameMappingStyle_ = opt_style; +}; + + +/** + * To use CSS renaming in compiled mode, one of the input files should have a + * call to goog.setCssNameMapping() with an object literal that the JSCompiler + * can extract and use to replace all calls to goog.getCssName(). In uncompiled + * mode, JavaScript code should be loaded before this base.js file that declares + * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is + * to ensure that the mapping is loaded before any calls to goog.getCssName() + * are made in uncompiled mode. + * + * A hook for overriding the CSS name mapping. + * @type {!Object|undefined} + */ +goog.global.CLOSURE_CSS_NAME_MAPPING; + + +if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) { + // This does not call goog.setCssNameMapping() because the JSCompiler + // requires that goog.setCssNameMapping() be called with an object literal. + goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING; +} + + +/** + * Gets a localized message. + * + * This function is a compiler primitive. If you give the compiler a localized + * message bundle, it will replace the string at compile-time with a localized + * version, and expand goog.getMsg call to a concatenated string. + * + * Messages must be initialized in the form: + * + * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'}); + * + * + * This function produces a string which should be treated as plain text. Use + * {@link goog.html.SafeHtmlFormatter} in conjunction with goog.getMsg to + * produce SafeHtml. + * + * @param {string} str Translatable string, places holders in the form {$foo}. + * @param {Object=} opt_values Maps place holder name to value. + * @param {{html: (boolean|undefined), + * unescapeHtmlEntities: (boolean|undefined)}=} opt_options Options: + * html: Escape '<' in str to '<'. Used by Closure Templates where the + * generated code size and performance is critical which is why {@link + * goog.html.SafeHtmlFormatter} is not used. The value must be literal true + * or false. + * unescapeHtmlEntities: Unescape common html entities: >, <, ', + * " and &. Used for messages not in HTML context, such as with + * `textContent` property. + * @return {string} message with placeholders filled. + */ +goog.getMsg = function(str, opt_values, opt_options) { + if (opt_options && opt_options.html) { + // Note that '&' is not replaced because the translation can contain HTML + // entities. + str = str.replace(/') + .replace(/'/g, '\'') + .replace(/"/g, '"') + .replace(/&/g, '&'); + } + if (opt_values) { + str = str.replace(/\{\$([^}]+)}/g, function(match, key) { + return (opt_values != null && key in opt_values) ? opt_values[key] : + match; + }); + } + return str; +}; + + +/** + * Gets a localized message. If the message does not have a translation, gives a + * fallback message. + * + * This is useful when introducing a new message that has not yet been + * translated into all languages. + * + * This function is a compiler primitive. Must be used in the form: + * var x = goog.getMsgWithFallback(MSG_A, MSG_B); + * where MSG_A and MSG_B were initialized with goog.getMsg. + * + * @param {string} a The preferred message. + * @param {string} b The fallback message. + * @return {string} The best translated message. + */ +goog.getMsgWithFallback = function(a, b) { + return a; +}; + + +/** + * Exposes an unobfuscated global namespace path for the given object. + * Note that fields of the exported object *will* be obfuscated, unless they are + * exported in turn via this function or goog.exportProperty. + * + * Also handy for making public items that are defined in anonymous closures. + * + * ex. goog.exportSymbol('public.path.Foo', Foo); + * + * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction); + * public.path.Foo.staticFunction(); + * + * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod', + * Foo.prototype.myMethod); + * new public.path.Foo().myMethod(); + * + * @param {string} publicPath Unobfuscated name to export. + * @param {*} object Object the name should point to. + * @param {?Object=} objectToExportTo The object to add the path to; default + * is goog.global. + */ +goog.exportSymbol = function(publicPath, object, objectToExportTo) { + goog.exportPath_( + publicPath, object, /* overwriteImplicit= */ true, objectToExportTo); +}; + + +/** + * Exports a property unobfuscated into the object's namespace. + * ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction); + * ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod); + * @param {Object} object Object whose static property is being exported. + * @param {string} publicName Unobfuscated name to export. + * @param {*} symbol Object the name should point to. + */ +goog.exportProperty = function(object, publicName, symbol) { + object[publicName] = symbol; +}; + + +/** + * Inherit the prototype methods from one constructor into another. + * + * Usage: + *
+ * function ParentClass(a, b) { }
+ * ParentClass.prototype.foo = function(a) { };
+ *
+ * function ChildClass(a, b, c) {
+ *   ChildClass.base(this, 'constructor', a, b);
+ * }
+ * goog.inherits(ChildClass, ParentClass);
+ *
+ * var child = new ChildClass('a', 'b', 'see');
+ * child.foo(); // This works.
+ * 
+ * + * @param {!Function} childCtor Child class. + * @param {!Function} parentCtor Parent class. + * @suppress {strictMissingProperties} superClass_ and base is not defined on + * Function. + * @deprecated Use ECMAScript class syntax instead. + */ +goog.inherits = function(childCtor, parentCtor) { + /** @constructor */ + function tempCtor() {} + tempCtor.prototype = parentCtor.prototype; + childCtor.superClass_ = parentCtor.prototype; + childCtor.prototype = new tempCtor(); + /** @override */ + childCtor.prototype.constructor = childCtor; + + /** + * Calls superclass constructor/method. + * + * This function is only available if you use goog.inherits to + * express inheritance relationships between classes. + * + * NOTE: This is a replacement for goog.base and for superClass_ + * property defined in childCtor. + * + * @param {!Object} me Should always be "this". + * @param {string} methodName The method name to call. Calling + * superclass constructor can be done with the special string + * 'constructor'. + * @param {...*} var_args The arguments to pass to superclass + * method/constructor. + * @return {*} The return value of the superclass method/constructor. + */ + childCtor.base = function(me, methodName, var_args) { + // Copying using loop to avoid deop due to passing arguments object to + // function. This is faster in many JS engines as of late 2014. + var args = new Array(arguments.length - 2); + for (var i = 2; i < arguments.length; i++) { + args[i - 2] = arguments[i]; + } + return parentCtor.prototype[methodName].apply(me, args); + }; +}; + + +/** + * Allow for aliasing within scope functions. This function exists for + * uncompiled code - in compiled code the calls will be inlined and the aliases + * applied. In uncompiled code the function is simply run since the aliases as + * written are valid JavaScript. + * + * + * @param {function()} fn Function to call. This function can contain aliases + * to namespaces (e.g. "var dom = goog.dom") or classes + * (e.g. "var Timer = goog.Timer"). + * @deprecated Use goog.module instead. + */ +goog.scope = function(fn) { + if (goog.isInModuleLoader_()) { + throw new Error('goog.scope is not supported within a module.'); + } + fn.call(goog.global); +}; + + +/* + * To support uncompiled, strict mode bundles that use eval to divide source + * like so: + * eval('someSource;//# sourceUrl sourcefile.js'); + * We need to export the globally defined symbols "goog" and "COMPILED". + * Exporting "goog" breaks the compiler optimizations, so we required that + * be defined externally. + * NOTE: We don't use goog.exportSymbol here because we don't want to trigger + * extern generation when that compiler option is enabled. + */ +if (!COMPILED) { + goog.global['COMPILED'] = COMPILED; +} + + //============================================================================== // goog.defineClass implementation //============================================================================== +/** + * Creates a restricted form of a Closure "class": + * - from the compiler's perspective, the instance returned from the + * constructor is sealed (no new properties may be added). This enables + * better checks. + * - the compiler will rewrite this definition to a form that is optimal + * for type checking and optimization (initially this will be a more + * traditional form). + * + * @param {Function} superClass The superclass, Object or null. + * @param {goog.defineClass.ClassDescriptor} def + * An object literal describing + * the class. It may have the following properties: + * "constructor": the constructor function + * "statics": an object literal containing methods to add to the constructor + * as "static" methods or a function that will receive the constructor + * function as its only parameter to which static properties can + * be added. + * all other properties are added to the prototype. + * @return {!Function} The class constructor. + * @deprecated Use ECMAScript class syntax instead. + */ +goog.defineClass = function(superClass, def) { + // TODO(johnlenz): consider making the superClass an optional parameter. + var constructor = def.constructor; + var statics = def.statics; + // Wrap the constructor prior to setting up the prototype and static methods. + if (!constructor || constructor == Object.prototype.constructor) { + constructor = function() { + throw new Error( + 'cannot instantiate an interface (no constructor defined).'); + }; + } + + var cls = goog.defineClass.createSealingConstructor_(constructor, superClass); + if (superClass) { + goog.inherits(cls, superClass); + } + + // Remove all the properties that should not be copied to the prototype. + delete def.constructor; + delete def.statics; + + goog.defineClass.applyProperties_(cls.prototype, def); + if (statics != null) { + if (statics instanceof Function) { + statics(cls); + } else { + goog.defineClass.applyProperties_(cls, statics); + } + } + + return cls; +}; + + +/** + * @typedef {{ + * constructor: (!Function|undefined), + * statics: (Object|undefined|function(Function):void) + * }} + */ +goog.defineClass.ClassDescriptor; + + +/** + * @define {boolean} Whether the instances returned by goog.defineClass should + * be sealed when possible. + * + * When sealing is disabled the constructor function will not be wrapped by + * goog.defineClass, making it incompatible with ES6 class methods. + */ +goog.defineClass.SEAL_CLASS_INSTANCES = + goog.define('goog.defineClass.SEAL_CLASS_INSTANCES', goog.DEBUG); + + +/** + * If goog.defineClass.SEAL_CLASS_INSTANCES is enabled and Object.seal is + * defined, this function will wrap the constructor in a function that seals the + * results of the provided constructor function. + * + * @param {!Function} ctr The constructor whose results maybe be sealed. + * @param {Function} superClass The superclass constructor. + * @return {!Function} The replacement constructor. + * @private + */ +goog.defineClass.createSealingConstructor_ = function(ctr, superClass) { + if (!goog.defineClass.SEAL_CLASS_INSTANCES) { + // Do now wrap the constructor when sealing is disabled. Angular code + // depends on this for injection to work properly. + return ctr; + } + + // NOTE: The sealing behavior has been removed + + /** + * @this {Object} + * @return {?} + */ + var wrappedCtr = function() { + // Don't seal an instance of a subclass when it calls the constructor of + // its super class as there is most likely still setup to do. + var instance = ctr.apply(this, arguments) || this; + instance[goog.UID_PROPERTY_] = instance[goog.UID_PROPERTY_]; + + return instance; + }; + + return wrappedCtr; +}; + + + +// TODO(johnlenz): share these values with the goog.object +/** + * The names of the fields that are defined on Object.prototype. + * @type {!Array} + * @private + * @const + */ +goog.defineClass.OBJECT_PROTOTYPE_FIELDS_ = [ + 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', + 'toLocaleString', 'toString', 'valueOf' +]; + + +// TODO(johnlenz): share this function with the goog.object +/** + * @param {!Object} target The object to add properties to. + * @param {!Object} source The object to copy properties from. + * @private + */ +goog.defineClass.applyProperties_ = function(target, source) { + // TODO(johnlenz): update this to support ES5 getters/setters + + var key; + for (key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + + // For IE the for-in-loop does not contain any properties that are not + // enumerable on the prototype object (for example isPrototypeOf from + // Object.prototype) and it will also not include 'replace' on objects that + // extend String and change 'replace' (not that it is common for anyone to + // extend anything except Object). + for (var i = 0; i < goog.defineClass.OBJECT_PROTOTYPE_FIELDS_.length; i++) { + key = goog.defineClass.OBJECT_PROTOTYPE_FIELDS_[i]; + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } +}; + +/** + * Returns the parameter. + * @param {string} s + * @return {string} + * @private + */ +goog.identity_ = function(s) { + return s; +}; + + +/** + * Creates Trusted Types policy if Trusted Types are supported by the browser. + * The policy just blesses any string as a Trusted Type. It is not visibility + * restricted because anyone can also call trustedTypes.createPolicy directly. + * However, the allowed names should be restricted by a HTTP header and the + * reference to the created policy should be visibility restricted. + * @param {string} name + * @return {?TrustedTypePolicy} + */ +goog.createTrustedTypesPolicy = function(name) { + var policy = null; + var policyFactory = goog.global.trustedTypes; + if (!policyFactory || !policyFactory.createPolicy) { + return policy; + } + // trustedTypes.createPolicy throws if called with a name that is already + // registered, even in report-only mode. Until the API changes, catch the + // error not to break the applications functionally. In such case, the code + // will fall back to using regular Safe Types. + // TODO(koto): Remove catching once createPolicy API stops throwing. + try { + policy = policyFactory.createPolicy(name, { + createHTML: goog.identity_, + createScript: goog.identity_, + createScriptURL: goog.identity_ + }); + } catch (e) { + goog.logToConsole_(e.message); + } + return policy; +}; + // There's a bug in the compiler where without collapse properties the // Closure namespace defines do not guard code correctly. To help reduce code // size also check for !COMPILED even though it redundant until this is fixed. +if (!COMPILED && goog.DEPENDENCIES_ENABLED) { -/** - * Tries to detect the base path of base.js script that bootstraps Closure. - * @private - */ -goog.findBasePath_ = function() { - /** @type {!Document} */ - var doc = goog.global.document; - // If we have a currentScript available, use it exclusively. - var currentScript = doc.currentScript; - if (currentScript) { - var scripts = [currentScript]; - } else { - var scripts = doc.getElementsByTagName('SCRIPT'); - } - // Search backwards since the current script is in almost all cases the one - // that has base.js. - for (var i = scripts.length - 1; i >= 0; --i) { - var script = /** @type {!HTMLScriptElement} */ (scripts[i]); - var src = script.src; - var qmark = src.lastIndexOf('?'); - var l = qmark == -1 ? src.length : qmark; - if (src.substr(l - 7, 7) == 'base.js') { - goog.basePath = src.substr(0, l - 7); + + /** + * Tries to detect whether the current browser is Edge, based on the user + * agent. This matches only pre-Chromium Edge. + * @see https://docs.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-string + * @return {boolean} True if the current browser is Edge. + * @private + */ + goog.isEdge_ = function() { + var userAgent = goog.global.navigator && goog.global.navigator.userAgent ? + goog.global.navigator.userAgent : + ''; + var edgeRe = /Edge\/(\d+)(\.\d)*/i; + return !!userAgent.match(edgeRe); + }; + + + /** + * Tries to detect whether is in the context of an HTML document. + * @return {boolean} True if it looks like HTML document. + * @private + */ + goog.inHtmlDocument_ = function() { + /** @type {!Document} */ + var doc = goog.global.document; + return doc != null && 'write' in doc; // XULDocument misses write. + }; + + + /** + * We'd like to check for if the document readyState is 'loading'; however + * there are bugs on IE 10 and below where the readyState being anything other + * than 'complete' is not reliable. + * @return {boolean} + * @private + */ + goog.isDocumentLoading_ = function() { + // attachEvent is available on IE 6 thru 10 only, and thus can be used to + // detect those browsers. + /** @type {!HTMLDocument} */ + var doc = goog.global.document; + return doc.attachEvent ? doc.readyState != 'complete' : + doc.readyState == 'loading'; + }; + + + /** + * Tries to detect the base path of base.js script that bootstraps Closure. + * @private + */ + goog.findBasePath_ = function() { + if (goog.global.CLOSURE_BASE_PATH != undefined && + // Anti DOM-clobbering runtime check (b/37736576). + typeof goog.global.CLOSURE_BASE_PATH === 'string') { + goog.basePath = goog.global.CLOSURE_BASE_PATH; + return; + } else if (!goog.inHtmlDocument_()) { return; } - } -}; + /** @type {!Document} */ + var doc = goog.global.document; + // If we have a currentScript available, use it exclusively. + var currentScript = doc.currentScript; + if (currentScript) { + var scripts = [currentScript]; + } else { + var scripts = doc.getElementsByTagName('SCRIPT'); + } + // Search backwards since the current script is in almost all cases the one + // that has base.js. + for (var i = scripts.length - 1; i >= 0; --i) { + var script = /** @type {!HTMLScriptElement} */ (scripts[i]); + var src = script.src; + var qmark = src.lastIndexOf('?'); + var l = qmark == -1 ? src.length : qmark; + if (src.substr(l - 7, 7) == 'base.js') { + goog.basePath = src.substr(0, l - 7); + return; + } + } + }; -goog.findBasePath_(); + goog.findBasePath_(); -/** - * A debug loader is responsible for downloading and executing javascript - * files in an unbundled, uncompiled environment. - * - * @struct @constructor @final @private - */ -goog.DebugLoader_ = function() { - /** @private @const {!Object} */ - this.dependencies_ = {}; - /** @private @const {!Object} */ - this.idToPath_ = {}; - /** @private @const {!Object} */ - this.written_ = {}; - /** @private {!Array} */ - this.depsToLoad_ = []; -}; + /** @struct @constructor @final */ + goog.Transpiler = function() { + /** @private {?Object} */ + this.requiresTranspilation_ = null; + /** @private {string} */ + this.transpilationTarget_ = goog.TRANSPILE_TO_LANGUAGE; + }; + /** + * Returns a newly created map from language mode string to a boolean + * indicating whether transpilation should be done for that mode as well as + * the highest level language that this environment supports. + * + * Guaranteed invariant: + * For any two modes, l1 and l2 where l2 is a newer mode than l1, + * `map[l1] == true` implies that `map[l2] == true`. + * + * Note this method is extracted and used elsewhere, so it cannot rely on + * anything external (it should easily be able to be transformed into a + * standalone, top level function). + * + * @private + * @return {{ + * target: string, + * map: !Object + * }} + */ + goog.Transpiler.prototype.createRequiresTranspilation_ = function() { + var transpilationTarget = 'es3'; + var /** !Object */ requiresTranspilation = {'es3': false}; + var transpilationRequiredForAllLaterModes = false; + + /** + * Adds an entry to requiresTranspliation for the given language mode. + * + * IMPORTANT: Calls must be made in order from oldest to newest language + * mode. + * @param {string} modeName + * @param {function(): boolean} isSupported Returns true if the JS engine + * supports the given mode. + */ + function addNewerLanguageTranspilationCheck(modeName, isSupported) { + if (transpilationRequiredForAllLaterModes) { + requiresTranspilation[modeName] = true; + } else if (isSupported()) { + transpilationTarget = modeName; + requiresTranspilation[modeName] = false; + } else { + requiresTranspilation[modeName] = true; + transpilationRequiredForAllLaterModes = true; + } + } + + /** + * Does the given code evaluate without syntax errors and return a truthy + * result? + */ + function /** boolean */ evalCheck(/** string */ code) { + try { + return !!eval(goog.CLOSURE_EVAL_PREFILTER_.createScript(code)); + } catch (ignored) { + return false; + } + } + + // Identify ES3-only browsers by their incorrect treatment of commas. + addNewerLanguageTranspilationCheck('es5', function() { + return evalCheck('[1,].length==1'); + }); + addNewerLanguageTranspilationCheck('es6', function() { + // Edge has a non-deterministic (i.e., not reproducible) bug with ES6: + // https://github.com/Microsoft/ChakraCore/issues/1496. + if (goog.isEdge_()) { + // The Reflect.construct test below is flaky on Edge. It can sometimes + // pass or fail on 40 15.15063, so just exit early for Edge and treat + // it as ES5. Until we're on a more up to date version just always use + // ES5. See https://github.com/Microsoft/ChakraCore/issues/3217. + return false; + } + // Test es6: [FF50 (?), Edge 14 (?), Chrome 50] + // (a) default params (specifically shadowing locals), + // (b) destructuring, (c) block-scoped functions, + // (d) for-of (const), (e) new.target/Reflect.construct + var es6fullTest = + 'class X{constructor(){if(new.target!=String)throw 1;this.x=42}}' + + 'let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof ' + + 'String))throw 1;for(const a of[2,3]){if(a==2)continue;function ' + + 'f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()' + + '==3}'; + + return evalCheck('(()=>{"use strict";' + es6fullTest + '})()'); + }); + // ** and **= are the only new features in 'es7' + addNewerLanguageTranspilationCheck('es7', function() { + return evalCheck('2**3==8'); + }); + // async functions are the only new features in 'es8' + addNewerLanguageTranspilationCheck('es8', function() { + return evalCheck('async()=>1,1'); + }); + addNewerLanguageTranspilationCheck('es9', function() { + return evalCheck('({...rest}={}),1'); + }); + // optional catch binding, unescaped unicode paragraph separator in strings + addNewerLanguageTranspilationCheck('es_2019', function() { + return evalCheck('let r;try{r="\u2029"}catch{};r'); + }); + // optional chaining, nullish coalescing + // untested/unsupported: bigint, import meta + addNewerLanguageTranspilationCheck('es_2020', function() { + return evalCheck('null?.x??1'); + }); + addNewerLanguageTranspilationCheck('es_next', function() { + return false; // assume it always need to transpile + }); + return {target: transpilationTarget, map: requiresTranspilation}; + }; -/** - * Travserses the dependency graph and queues the given dependency, and all of - * its transitive dependencies, for loading and then starts loading if not - * paused. - * - * @param {string} namespace - * @private - */ -goog.DebugLoader_.prototype.load_ = function(namespace) { - if (!this.getPathFromDeps_(namespace)) { - throw Error('goog.require could not find: ' + namespace); - } else { - var loader = this; + /** + * Determines whether the given language needs to be transpiled. + * @param {string} lang + * @param {string|undefined} module + * @return {boolean} + */ + goog.Transpiler.prototype.needsTranspile = function(lang, module) { + if (goog.TRANSPILE == 'always') { + return true; + } else if (goog.TRANSPILE == 'never') { + return false; + } else if (!this.requiresTranspilation_) { + var obj = this.createRequiresTranspilation_(); + this.requiresTranspilation_ = obj.map; + this.transpilationTarget_ = this.transpilationTarget_ || obj.target; + } + if (lang in this.requiresTranspilation_) { + if (this.requiresTranspilation_[lang]) { + return true; + } else if ( + goog.inHtmlDocument_() && module == 'es6' && + !('noModule' in goog.global.document.createElement('script'))) { + return true; + } else { + return false; + } + } else { + throw new Error('Unknown language mode: ' + lang); + } + }; + + + /** + * Lazily retrieves the transpiler and applies it to the source. + * @param {string} code JS code. + * @param {string} path Path to the code. + * @return {string} The transpiled code. + */ + goog.Transpiler.prototype.transpile = function(code, path) { + // TODO(johnplaisted): We should delete goog.transpile_ and just have this + // function. But there's some compile error atm where goog.global is being + // stripped incorrectly without this. + return goog.transpile_(code, path, this.transpilationTarget_); + }; + + + /** @private @final {!goog.Transpiler} */ + goog.transpiler_ = new goog.Transpiler(); + + /** + * Rewrites closing script tags in input to avoid ending an enclosing script + * tag. + * + * @param {string} str + * @return {string} + * @private + */ + goog.protectScriptTag_ = function(str) { + return str.replace(/<\/(SCRIPT)/ig, '\\x3c/$1'); + }; + + + /** + * A debug loader is responsible for downloading and executing javascript + * files in an unbundled, uncompiled environment. + * + * This can be custimized via the setDependencyFactory method, or by + * CLOSURE_IMPORT_SCRIPT/CLOSURE_LOAD_FILE_SYNC. + * + * @struct @constructor @final @private + */ + goog.DebugLoader_ = function() { + /** @private @const {!Object} */ + this.dependencies_ = {}; + /** @private @const {!Object} */ + this.idToPath_ = {}; + /** @private @const {!Object} */ + this.written_ = {}; + /** @private @const {!Array} */ + this.loadingDeps_ = []; + /** @private {!Array} */ + this.depsToLoad_ = []; + /** @private {boolean} */ + this.paused_ = false; + /** @private {!goog.DependencyFactory} */ + this.factory_ = new goog.DependencyFactory(goog.transpiler_); + /** @private @const {!Object} */ + this.deferredCallbacks_ = {}; + /** @private @const {!Array} */ + this.deferredQueue_ = []; + }; + + /** + * @param {!Array} namespaces + * @param {function(): undefined} callback Function to call once all the + * namespaces have loaded. + */ + goog.DebugLoader_.prototype.bootstrap = function(namespaces, callback) { + var cb = callback; + function resolve() { + if (cb) { + goog.global.setTimeout(cb, 0); + cb = null; + } + } + + if (!namespaces.length) { + resolve(); + return; + } var deps = []; - - /** @param {string} namespace */ - var visit = function(namespace) { - var path = loader.getPathFromDeps_(namespace); - + for (var i = 0; i < namespaces.length; i++) { + var path = this.getPathFromDeps_(namespaces[i]); if (!path) { - throw Error('Bad dependency path or symbol: ' + namespace); + throw new Error('Unregonized namespace: ' + namespaces[i]); + } + deps.push(this.dependencies_[path]); + } + + var require = goog.require; + var loaded = 0; + for (var i = 0; i < namespaces.length; i++) { + require(namespaces[i]); + deps[i].onLoad(function() { + if (++loaded == namespaces.length) { + resolve(); + } + }); + } + }; + + + /** + * Loads the Closure Dependency file. + * + * Exposed a public function so CLOSURE_NO_DEPS can be set to false, base + * loaded, setDependencyFactory called, and then this called. i.e. allows + * custom loading of the deps file. + */ + goog.DebugLoader_.prototype.loadClosureDeps = function() { + // Circumvent addDependency, which would try to transpile deps.js if + // transpile is set to always. + var relPath = 'deps.js'; + this.depsToLoad_.push(this.factory_.createDependency( + goog.normalizePath_(goog.basePath + relPath), relPath, [], [], {}, + false)); + this.loadDeps_(); + }; + + + /** + * Notifies the debug loader when a dependency has been requested. + * + * @param {string} absPathOrId Path of the dependency or goog id. + * @param {boolean=} opt_force + */ + goog.DebugLoader_.prototype.requested = function(absPathOrId, opt_force) { + var path = this.getPathFromDeps_(absPathOrId); + if (path && + (opt_force || this.areDepsLoaded_(this.dependencies_[path].requires))) { + var callback = this.deferredCallbacks_[path]; + if (callback) { + delete this.deferredCallbacks_[path]; + callback(); + } + } + }; + + + /** + * Sets the dependency factory, which can be used to create custom + * goog.Dependency implementations to control how dependencies are loaded. + * + * @param {!goog.DependencyFactory} factory + */ + goog.DebugLoader_.prototype.setDependencyFactory = function(factory) { + this.factory_ = factory; + }; + + + /** + * Travserses the dependency graph and queues the given dependency, and all of + * its transitive dependencies, for loading and then starts loading if not + * paused. + * + * @param {string} namespace + * @private + */ + goog.DebugLoader_.prototype.load_ = function(namespace) { + if (!this.getPathFromDeps_(namespace)) { + var errorMessage = 'goog.require could not find: ' + namespace; + goog.logToConsole_(errorMessage); + } else { + var loader = this; + + var deps = []; + + /** @param {string} namespace */ + var visit = function(namespace) { + var path = loader.getPathFromDeps_(namespace); + + if (!path) { + throw new Error('Bad dependency path or symbol: ' + namespace); + } + + if (loader.written_[path]) { + return; + } + + loader.written_[path] = true; + + var dep = loader.dependencies_[path]; + for (var i = 0; i < dep.requires.length; i++) { + if (!goog.isProvided_(dep.requires[i])) { + visit(dep.requires[i]); + } + } + + deps.push(dep); + }; + + visit(namespace); + + var wasLoading = !!this.depsToLoad_.length; + this.depsToLoad_ = this.depsToLoad_.concat(deps); + + if (!this.paused_ && !wasLoading) { + this.loadDeps_(); + } + } + }; + + + /** + * Loads any queued dependencies until they are all loaded or paused. + * + * @private + */ + goog.DebugLoader_.prototype.loadDeps_ = function() { + var loader = this; + var paused = this.paused_; + + while (this.depsToLoad_.length && !paused) { + (function() { + var loadCallDone = false; + var dep = loader.depsToLoad_.shift(); + + var loaded = false; + loader.loading_(dep); + + var controller = { + pause: function() { + if (loadCallDone) { + throw new Error('Cannot call pause after the call to load.'); + } else { + paused = true; + } + }, + resume: function() { + if (loadCallDone) { + loader.resume_(); + } else { + // Some dep called pause and then resume in the same load call. + // Just keep running this same loop. + paused = false; + } + }, + loaded: function() { + if (loaded) { + throw new Error('Double call to loaded.'); + } + + loaded = true; + loader.loaded_(dep); + }, + pending: function() { + // Defensive copy. + var pending = []; + for (var i = 0; i < loader.loadingDeps_.length; i++) { + pending.push(loader.loadingDeps_[i]); + } + return pending; + }, + /** + * @param {goog.ModuleType} type + */ + setModuleState: function(type) { + goog.moduleLoaderState_ = { + type: type, + moduleName: '', + declareLegacyNamespace: false + }; + }, + /** @type {function(string, string, string=)} */ + registerEs6ModuleExports: function( + path, exports, opt_closureNamespace) { + if (opt_closureNamespace) { + goog.loadedModules_[opt_closureNamespace] = { + exports: exports, + type: goog.ModuleType.ES6, + moduleId: opt_closureNamespace || '' + }; + } + }, + /** @type {function(string, ?)} */ + registerGoogModuleExports: function(moduleId, exports) { + goog.loadedModules_[moduleId] = { + exports: exports, + type: goog.ModuleType.GOOG, + moduleId: moduleId + }; + }, + clearModuleState: function() { + goog.moduleLoaderState_ = null; + }, + defer: function(callback) { + if (loadCallDone) { + throw new Error( + 'Cannot register with defer after the call to load.'); + } + loader.defer_(dep, callback); + }, + areDepsLoaded: function() { + return loader.areDepsLoaded_(dep.requires); + } + }; + + try { + dep.load(controller); + } finally { + loadCallDone = true; + } + })(); + } + + if (paused) { + this.pause_(); + } + }; + + + /** @private */ + goog.DebugLoader_.prototype.pause_ = function() { + this.paused_ = true; + }; + + + /** @private */ + goog.DebugLoader_.prototype.resume_ = function() { + if (this.paused_) { + this.paused_ = false; + this.loadDeps_(); + } + }; + + + /** + * Marks the given dependency as loading (load has been called but it has not + * yet marked itself as finished). Useful for dependencies that want to know + * what else is loading. Example: goog.modules cannot eval if there are + * loading dependencies. + * + * @param {!goog.Dependency} dep + * @private + */ + goog.DebugLoader_.prototype.loading_ = function(dep) { + this.loadingDeps_.push(dep); + }; + + + /** + * Marks the given dependency as having finished loading and being available + * for require. + * + * @param {!goog.Dependency} dep + * @private + */ + goog.DebugLoader_.prototype.loaded_ = function(dep) { + for (var i = 0; i < this.loadingDeps_.length; i++) { + if (this.loadingDeps_[i] == dep) { + this.loadingDeps_.splice(i, 1); + break; + } + } + + for (var i = 0; i < this.deferredQueue_.length; i++) { + if (this.deferredQueue_[i] == dep.path) { + this.deferredQueue_.splice(i, 1); + break; + } + } + + if (this.loadingDeps_.length == this.deferredQueue_.length && + !this.depsToLoad_.length) { + // Something has asked to load these, but they may not be directly + // required again later, so load them now that we know we're done loading + // everything else. e.g. a goog module entry point. + while (this.deferredQueue_.length) { + this.requested(this.deferredQueue_.shift(), true); + } + } + + dep.loaded(); + }; + + + /** + * @param {!Array} pathsOrIds + * @return {boolean} + * @private + */ + goog.DebugLoader_.prototype.areDepsLoaded_ = function(pathsOrIds) { + for (var i = 0; i < pathsOrIds.length; i++) { + var path = this.getPathFromDeps_(pathsOrIds[i]); + if (!path || + (!(path in this.deferredCallbacks_) && + !goog.isProvided_(pathsOrIds[i]))) { + return false; + } + } + + return true; + }; + + + /** + * @param {string} absPathOrId + * @return {?string} + * @private + */ + goog.DebugLoader_.prototype.getPathFromDeps_ = function(absPathOrId) { + if (absPathOrId in this.idToPath_) { + return this.idToPath_[absPathOrId]; + } else if (absPathOrId in this.dependencies_) { + return absPathOrId; + } else { + return null; + } + }; + + + /** + * @param {!goog.Dependency} dependency + * @param {!Function} callback + * @private + */ + goog.DebugLoader_.prototype.defer_ = function(dependency, callback) { + this.deferredCallbacks_[dependency.path] = callback; + this.deferredQueue_.push(dependency.path); + }; + + + /** + * Interface for goog.Dependency implementations to have some control over + * loading of dependencies. + * + * @record + */ + goog.LoadController = function() {}; + + + /** + * Tells the controller to halt loading of more dependencies. + */ + goog.LoadController.prototype.pause = function() {}; + + + /** + * Tells the controller to resume loading of more dependencies if paused. + */ + goog.LoadController.prototype.resume = function() {}; + + + /** + * Tells the controller that this dependency has finished loading. + * + * This causes this to be removed from pending() and any load callbacks to + * fire. + */ + goog.LoadController.prototype.loaded = function() {}; + + + /** + * List of dependencies on which load has been called but which have not + * called loaded on their controller. This includes the current dependency. + * + * @return {!Array} + */ + goog.LoadController.prototype.pending = function() {}; + + + /** + * Registers an object as an ES6 module's exports so that goog.modules may + * require it by path. + * + * @param {string} path Full path of the module. + * @param {?} exports + * @param {string=} opt_closureNamespace Closure namespace to associate with + * this module. + */ + goog.LoadController.prototype.registerEs6ModuleExports = function( + path, exports, opt_closureNamespace) {}; + + + /** + * Sets the current module state. + * + * @param {goog.ModuleType} type Type of module. + */ + goog.LoadController.prototype.setModuleState = function(type) {}; + + + /** + * Clears the current module state. + */ + goog.LoadController.prototype.clearModuleState = function() {}; + + + /** + * Registers a callback to call once the dependency is actually requested + * via goog.require + all of the immediate dependencies have been loaded or + * all other files have been loaded. Allows for lazy loading until + * require'd without pausing dependency loading, which is needed on old IE. + * + * @param {!Function} callback + */ + goog.LoadController.prototype.defer = function(callback) {}; + + + /** + * @return {boolean} + */ + goog.LoadController.prototype.areDepsLoaded = function() {}; + + + /** + * Basic super class for all dependencies Closure Library can load. + * + * This default implementation is designed to load untranspiled, non-module + * scripts in a web broswer. + * + * For transpiled non-goog.module files {@see goog.TranspiledDependency}. + * For goog.modules see {@see goog.GoogModuleDependency}. + * For untranspiled ES6 modules {@see goog.Es6ModuleDependency}. + * + * @param {string} path Absolute path of this script. + * @param {string} relativePath Path of this script relative to goog.basePath. + * @param {!Array} provides goog.provided or goog.module symbols + * in this file. + * @param {!Array} requires goog symbols or relative paths to Closure + * this depends on. + * @param {!Object} loadFlags + * @struct @constructor + */ + goog.Dependency = function( + path, relativePath, provides, requires, loadFlags) { + /** @const */ + this.path = path; + /** @const */ + this.relativePath = relativePath; + /** @const */ + this.provides = provides; + /** @const */ + this.requires = requires; + /** @const */ + this.loadFlags = loadFlags; + /** @private {boolean} */ + this.loaded_ = false; + /** @private {!Array} */ + this.loadCallbacks_ = []; + }; + + + /** + * @return {string} The pathname part of this dependency's path if it is a + * URI. + */ + goog.Dependency.prototype.getPathName = function() { + var pathName = this.path; + var protocolIndex = pathName.indexOf('://'); + if (protocolIndex >= 0) { + pathName = pathName.substring(protocolIndex + 3); + var slashIndex = pathName.indexOf('/'); + if (slashIndex >= 0) { + pathName = pathName.substring(slashIndex + 1); + } + } + return pathName; + }; + + + /** + * @param {function()} callback Callback to fire as soon as this has loaded. + * @final + */ + goog.Dependency.prototype.onLoad = function(callback) { + if (this.loaded_) { + callback(); + } else { + this.loadCallbacks_.push(callback); + } + }; + + + /** + * Marks this dependency as loaded and fires any callbacks registered with + * onLoad. + * @final + */ + goog.Dependency.prototype.loaded = function() { + this.loaded_ = true; + var callbacks = this.loadCallbacks_; + this.loadCallbacks_ = []; + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](); + } + }; + + + /** + * Whether or not document.written / appended script tags should be deferred. + * + * @private {boolean} + */ + goog.Dependency.defer_ = false; + + + /** + * Map of script ready / state change callbacks. Old IE cannot handle putting + * these properties on goog.global. + * + * @private @const {!Object} + */ + goog.Dependency.callbackMap_ = {}; + + + /** + * @param {function(...?):?} callback + * @return {string} + * @private + */ + goog.Dependency.registerCallback_ = function(callback) { + var key = Math.random().toString(32); + goog.Dependency.callbackMap_[key] = callback; + return key; + }; + + + /** + * @param {string} key + * @private + */ + goog.Dependency.unregisterCallback_ = function(key) { + delete goog.Dependency.callbackMap_[key]; + }; + + + /** + * @param {string} key + * @param {...?} var_args + * @private + * @suppress {unusedPrivateMembers} + */ + goog.Dependency.callback_ = function(key, var_args) { + if (key in goog.Dependency.callbackMap_) { + var callback = goog.Dependency.callbackMap_[key]; + var args = []; + for (var i = 1; i < arguments.length; i++) { + args.push(arguments[i]); + } + callback.apply(undefined, args); + } else { + var errorMessage = 'Callback key ' + key + + ' does not exist (was base.js loaded more than once?).'; + throw Error(errorMessage); + } + }; + + + /** + * Starts loading this dependency. This dependency can pause loading if it + * needs to and resume it later via the controller interface. + * + * When this is loaded it should call controller.loaded(). Note that this will + * end up calling the loaded method of this dependency; there is no need to + * call it explicitly. + * + * @param {!goog.LoadController} controller + */ + goog.Dependency.prototype.load = function(controller) { + if (goog.global.CLOSURE_IMPORT_SCRIPT) { + if (goog.global.CLOSURE_IMPORT_SCRIPT(this.path)) { + controller.loaded(); + } else { + controller.pause(); + } + return; + } + + if (!goog.inHtmlDocument_()) { + goog.logToConsole_( + 'Cannot use default debug loader outside of HTML documents.'); + if (this.relativePath == 'deps.js') { + // Some old code is relying on base.js auto loading deps.js failing with + // no error before later setting CLOSURE_IMPORT_SCRIPT. + // CLOSURE_IMPORT_SCRIPT should be set *before* base.js is loaded, or + // CLOSURE_NO_DEPS set to true. + goog.logToConsole_( + 'Consider setting CLOSURE_IMPORT_SCRIPT before loading base.js, ' + + 'or setting CLOSURE_NO_DEPS to true.'); + controller.loaded(); + } else { + controller.pause(); + } + return; + } + + /** @type {!HTMLDocument} */ + var doc = goog.global.document; + + // If the user tries to require a new symbol after document load, + // something has gone terribly wrong. Doing a document.write would + // wipe out the page. This does not apply to the CSP-compliant method + // of writing script tags. + if (doc.readyState == 'complete' && + !goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING) { + // Certain test frameworks load base.js multiple times, which tries + // to write deps.js each time. If that happens, just fail silently. + // These frameworks wipe the page between each load of base.js, so this + // is OK. + var isDeps = /\bdeps.js$/.test(this.path); + if (isDeps) { + controller.loaded(); + return; + } else { + throw Error('Cannot write "' + this.path + '" after document load'); + } + } + + var nonce = goog.getScriptNonce_(); + if (!goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING && + goog.isDocumentLoading_()) { + var key; + var callback = function(script) { + if (script.readyState && script.readyState != 'complete') { + script.onload = callback; + return; + } + goog.Dependency.unregisterCallback_(key); + controller.loaded(); + }; + key = goog.Dependency.registerCallback_(callback); + + var defer = goog.Dependency.defer_ ? ' defer' : ''; + var nonceAttr = nonce ? ' nonce="' + nonce + '"' : ''; + var script = ''); + // Load dependency graph info from test/deps.js. To update + // deps.js, run `npm run build:deps`. + document.write( + ''); + // Load the rest of Blockly. + document.write(''); } - return ''; })(this); - -this.BLOCKLY_BOOT = function(root) { - // Execute after Closure has loaded. -goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); -goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []); -goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); -goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []); -goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); -goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); -goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], []); -goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); -goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); -goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); -goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es5'}); -goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); -goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); -goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); -goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); -goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events']); -goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_click.js', ['Blockly.Events.Click'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_marker_move.js', ['Blockly.Events.MarkerMove'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_selected.js', ['Blockly.Events.Selected'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_theme_change.js', ['Blockly.Events.ThemeChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_toolbox_item_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events.TrashcanOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/events_viewport.js', ['Blockly.Events.ViewportChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/ui_events.js', ['Blockly.Events.Ui', 'Blockly.Events.UiBase'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarBase', 'Blockly.Events.VarCreate', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); -goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); -goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils']); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); -goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); -goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); -goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); -goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); -goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); -goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); -goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); -goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], []); -goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], []); -goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); -goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], []); -goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); -goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); -goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); -goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], []); -goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget']); -goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); -goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); -goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); -goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); -goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], []); -goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); -goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); -goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], []); -goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); -goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); -goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es5'}); -goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); -goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); -goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); -goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); -goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); -goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); -goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); -goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); -goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); -goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); -goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); -goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); -goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); -goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); -goog.addDependency('../../core/renderers/geras/highlight_constants.js', ['Blockly.geras.HighlightConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/geras/highlighter.js', ['Blockly.geras.Highlighter'], ['Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); -goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/geras/measurables/inputs.js', ['Blockly.geras.InlineInput', 'Blockly.geras.StatementInput'], ['Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.PathObject', 'Blockly.geras.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); -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']); -goog.addDependency('../../core/renderers/measurables/base.js', ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.Types']); -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/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/types.js', ['Blockly.blockRendering.Types'], []); -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.minimalist.RenderInfo', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/minimalist/info.js', ['Blockly.minimalist', 'Blockly.minimalist.RenderInfo'], ['Blockly.utils.object']); -goog.addDependency('../../core/renderers/minimalist/renderer.js', ['Blockly.minimalist.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.minimalist.ConstantProvider', 'Blockly.minimalist.Drawer', 'Blockly.minimalist.RenderInfo', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/thrasos/info.js', ['Blockly.thrasos', 'Blockly.thrasos.RenderInfo'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/thrasos/renderer.js', ['Blockly.thrasos.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.thrasos.RenderInfo', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/zelos/drawer.js', ['Blockly.zelos.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.utils.object', 'Blockly.utils.svgPaths', 'Blockly.zelos.RenderInfo']); -goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); -goog.addDependency('../../core/renderers/zelos/marker_svg.js', ['Blockly.zelos.MarkerSvg'], ['Blockly.blockRendering.MarkerSvg', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/zelos/measurables/inputs.js', ['Blockly.zelos.StatementInput'], ['Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/measurables/row_elements.js', ['Blockly.zelos.RightConnectionShape'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/measurables/rows.js', ['Blockly.zelos.BottomRow', 'Blockly.zelos.TopRow'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.TopRow', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos.PathObject'], ['Blockly.blockRendering.PathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider']); -goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); -goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Themes.Dark', 'Blockly.Themes.Deuteranopia', 'Blockly.Themes.HighContrast', 'Blockly.Themes.Tritanopia', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); -goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); -goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); -goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); -goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); -goog.addDependency('../../core/theme/dark.js', ['Blockly.Themes.Dark'], ['Blockly.Theme']); -goog.addDependency('../../core/theme/deuteranopia.js', ['Blockly.Themes.Deuteranopia'], ['Blockly.Theme']); -goog.addDependency('../../core/theme/highcontrast.js', ['Blockly.Themes.HighContrast'], ['Blockly.Theme']); -goog.addDependency('../../core/theme/modern.js', ['Blockly.Themes.Modern'], ['Blockly.Theme']); -goog.addDependency('../../core/theme/tritanopia.js', ['Blockly.Themes.Tritanopia'], ['Blockly.Theme']); -goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); -goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); -goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); -goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); -goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); -goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); -goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); -goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); -goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); -goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); -goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); -goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); -goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); -goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); -goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); -goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); -goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); -goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); -goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); -goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); -goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); -goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); -goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.xml']); -goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); -goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); -goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); -goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); -goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); -goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency("base.js", [], []); - -// Load Blockly. -goog.require('Blockly.requires'); - -delete root.BLOCKLY_DIR; -delete root.BLOCKLY_BOOT; -delete root.IS_NODE_JS; -}; - -if (this.IS_NODE_JS) { - this.BLOCKLY_BOOT(this); - module.exports = Blockly; -} else { - document.write(''); - document.write(''); -} diff --git a/gulpfile.js b/gulpfile.js index 53a756874..dc5d1e71f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -25,10 +25,10 @@ module.exports = { default: buildTasks.build, generateLangfiles: buildTasks.generateLangfiles, build: buildTasks.build, + buildDeps: buildTasks.deps, buildCore: buildTasks.core, buildBlocks: buildTasks.blocks, buildLangfiles: buildTasks.langfiles, - buildUncompressed: buildTasks.uncompressed, buildCompressed: buildTasks.compressed, buildGenerators: buildTasks.generators, buildAdvancedCompilationTest: buildTasks.advancedCompilationTest, diff --git a/package.json b/package.json index 75d294dc0..dda2766d2 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "build:core": "gulp buildCore", "build:debug": "gulp buildCompressed --verbose --debug", "build:debug:log": "npm run build:debug > build-debug.log 2>&1 && tail -3 build-debug.log", + "build:deps": "gulp buildDeps", "build:strict": "gulp buildCompressed --verbose --strict", "build:strict:log": "npm run build:strict > build-debug.log 2>&1 && tail -3 build-debug.log", "build:generators": "gulp buildGenerators", "build:langfiles": "gulp buildLangfiles", - "build:uncompressed": "gulp buildUncompressed", "bump": "npm --no-git-tag-version version 4.$(date +'%Y%m%d').0", "clean": "gulp clean", "clean:build": "gulp cleanBuildDir", diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index b27d21a5b..d341b5601 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -330,84 +330,21 @@ const buildGenerators = gulp.parallel( ); /** - * This task builds Blockly's uncompressed file. - * blockly_uncompressed.js + * This task updates tests/deps.js, used by blockly_uncompressed.js + * when loading Blockly in uncompiled mode. */ -function buildUncompressed() { +function buildDeps(done) { const closurePath = argv.closureLibrary ? - 'node_modules/google-closure-library/closure/goog' : - 'closure/goog'; - const header = `// Do not edit this file; automatically generated by gulp. -'use strict'; - -this.IS_NODE_JS = !!(typeof module !== 'undefined' && module.exports); - -this.BLOCKLY_DIR = (function(root) { - if (!root.IS_NODE_JS) { - // Find name of current directory. - var scripts = document.getElementsByTagName('script'); - var re = new RegExp('(.+)[\\\/]blockly_(.*)uncompressed\\\.js$'); - for (var i = 0, script; script = scripts[i]; i++) { - var match = re.exec(script.src); - if (match) { - return match[1]; - } - } - alert('Could not detect Blockly\\'s directory name.'); - } - return ''; -})(this); - -this.BLOCKLY_BOOT = function(root) { - // Execute after Closure has loaded. -`; - const footer = ` -delete root.BLOCKLY_DIR; -delete root.BLOCKLY_BOOT; -delete root.IS_NODE_JS; -}; - -if (this.IS_NODE_JS) { - this.BLOCKLY_BOOT(this); - module.exports = Blockly; -} else { - document.write(''); - document.write(''); -} -`; - -let deps = []; -return gulp.src(maybeAddClosureLibrary(['core/**/**/*.js'])) - .pipe(through2.obj((file, _enc, cb) => { - const result = closureDeps.parser.parseFile(file.path); - for (const dep of result.dependencies) { - deps.push(dep); - } - cb(null); - })) - .on('end', () => { - // Update the path to closure for any files that we don't know the full path - // of (parsed from a goog.addDependency call). - for (const dep of deps) { - dep.setClosurePath(closurePath); - } - - const addDependency = closureDeps.depFile - .getDepFileText(closurePath, deps) - .replace(/\\/g, '\/'); - - const requires = `goog.addDependency("base.js", [], []); - -// Load Blockly. -goog.require('Blockly.requires'); -`; - fs.writeFileSync('blockly_uncompressed.js', - header + - addDependency + - requires + - footer); - }); + 'node_modules/google-closure-library/closure/goog' : + 'closure/goog'; + const roots = [ + closurePath, + 'core', + 'blocks', + ]; + const args = roots.map(root => `--root '${root}' `).join(''); + execSync(`closure-make-deps ${args} > tests/deps.js`, {stdio: 'inherit'}); + done(); }; /** @@ -517,10 +454,10 @@ function buildAdvancedCompilationTest() { * blockly_uncompressed.js */ const buildCore = gulp.parallel( - buildCompressed, - buildBlocks, - buildUncompressed -); + buildDeps, + buildCompressed, + buildBlocks, + ); /** * This task builds all of Blockly: @@ -535,10 +472,10 @@ const buildCore = gulp.parallel( * msg/json/*.js */ const build = gulp.parallel( - buildCore, - buildGenerators, - buildLangfiles -); + buildCore, + buildGenerators, + buildLangfiles, + ); /** * This task copies built files from BUILD_DIR back to the repository @@ -566,11 +503,11 @@ function cleanBuildDir(done) { module.exports = { build: build, + deps: buildDeps, core: buildCore, blocks: buildBlocks, generateLangfiles: generateLangfiles, langfiles: buildLangfiles, - uncompressed: buildUncompressed, compressed: buildCompressed, generators: buildGenerators, checkinBuilt: checkinBuilt, diff --git a/tests/deps.js b/tests/deps.js new file mode 100644 index 000000000..ee068001a --- /dev/null +++ b/tests/deps.js @@ -0,0 +1,214 @@ +goog.addDependency('../../blocks/colour.js', ['Blockly.Blocks.colour', 'Blockly.Constants.Colour'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldColour', 'Blockly.FieldLabel']); +goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); +goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); +goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); +goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); +goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); +goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); +goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []); +goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); +goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []); +goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); +goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], []); +goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); +goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); +goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es5'}); +goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); +goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); +goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); +goog.addDependency('../../core/events/events_abstract.js', ['Blockly.Events.Abstract'], ['Blockly.Events']); +goog.addDependency('../../core/events/events_block_drag.js', ['Blockly.Events.BlockDrag'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_bubble_open.js', ['Blockly.Events.BubbleOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_click.js', ['Blockly.Events.Click'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_marker_move.js', ['Blockly.Events.MarkerMove'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_selected.js', ['Blockly.Events.Selected'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_theme_change.js', ['Blockly.Events.ThemeChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_toolbox_item_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events.TrashcanOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/events_viewport.js', ['Blockly.Events.ViewportChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/ui_events.js', ['Blockly.Events.Ui', 'Blockly.Events.UiBase'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarBase', 'Blockly.Events.VarCreate', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); +goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); +goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils']); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); +goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); +goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); +goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); +goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], []); +goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], []); +goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); +goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], []); +goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); +goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); +goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); +goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], []); +goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); +goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); +goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); +goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], []); +goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); +goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], []); +goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); +goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); +goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); +goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); +goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); +goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); +goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); +goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); +goog.addDependency('../../core/renderers/geras/highlight_constants.js', ['Blockly.geras.HighlightConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/geras/highlighter.js', ['Blockly.geras.Highlighter'], ['Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); +goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/geras/measurables/inputs.js', ['Blockly.geras.InlineInput', 'Blockly.geras.StatementInput'], ['Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.PathObject', 'Blockly.geras.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); +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']); +goog.addDependency('../../core/renderers/measurables/base.js', ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.Types']); +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/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/types.js', ['Blockly.blockRendering.Types'], []); +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.minimalist.RenderInfo', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/minimalist/info.js', ['Blockly.minimalist', 'Blockly.minimalist.RenderInfo'], ['Blockly.utils.object']); +goog.addDependency('../../core/renderers/minimalist/renderer.js', ['Blockly.minimalist.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.minimalist.ConstantProvider', 'Blockly.minimalist.Drawer', 'Blockly.minimalist.RenderInfo', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/thrasos/info.js', ['Blockly.thrasos', 'Blockly.thrasos.RenderInfo'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/thrasos/renderer.js', ['Blockly.thrasos.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.thrasos.RenderInfo', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/zelos/drawer.js', ['Blockly.zelos.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.utils.object', 'Blockly.utils.svgPaths', 'Blockly.zelos.RenderInfo']); +goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); +goog.addDependency('../../core/renderers/zelos/marker_svg.js', ['Blockly.zelos.MarkerSvg'], ['Blockly.blockRendering.MarkerSvg', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/zelos/measurables/inputs.js', ['Blockly.zelos.StatementInput'], ['Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/zelos/measurables/row_elements.js', ['Blockly.zelos.RightConnectionShape'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/zelos/measurables/rows.js', ['Blockly.zelos.BottomRow', 'Blockly.zelos.TopRow'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.TopRow', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos.PathObject'], ['Blockly.blockRendering.PathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider']); +goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); +goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Themes.Dark', 'Blockly.Themes.Deuteranopia', 'Blockly.Themes.HighContrast', 'Blockly.Themes.Tritanopia', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); +goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); +goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); +goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); +goog.addDependency('../../core/theme/dark.js', ['Blockly.Themes.Dark'], ['Blockly.Theme']); +goog.addDependency('../../core/theme/deuteranopia.js', ['Blockly.Themes.Deuteranopia'], ['Blockly.Theme']); +goog.addDependency('../../core/theme/highcontrast.js', ['Blockly.Themes.HighContrast'], ['Blockly.Theme']); +goog.addDependency('../../core/theme/modern.js', ['Blockly.Themes.Modern'], ['Blockly.Theme']); +goog.addDependency('../../core/theme/tritanopia.js', ['Blockly.Themes.Tritanopia'], ['Blockly.Theme']); +goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); +goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); +goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); +goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); +goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); +goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); +goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); +goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); +goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); +goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); +goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); +goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); +goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); +goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); +goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); +goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); +goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); +goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); +goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); +goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); +goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); +goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.xml']); +goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); +goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); +goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); +goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); +goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); +goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('base.js', [], []); + From 173ea2bc795cf725cdbe5e9865787a1109754304 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 12 Jul 2021 02:54:59 +0100 Subject: [PATCH 003/833] Have eslint ignore undefined variable "exports" Modules defined using goog.module declare their exported functions by assigning them to properties on an object which is the value of the variable "exports" (e.g., "exports.MyClass = class { ... };"). Normally eslint would complain about this variable being undefined, but this commit suppresses these errors. --- .eslintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 47430bdf2..0d5daf79c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -79,7 +79,8 @@ }, "globals": { "Blockly": true, - "goog": true + "goog": true, + "exports": true }, "extends": [ "eslint:recommended" From 1197afcee7a6dfcfbdde77f10317ffba90e418c2 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 12 Jul 2021 03:17:14 +0100 Subject: [PATCH 004/833] Fix JSDoc type annotations causing closure-make-deps warnings Some type annotations were missing curly brackets, which makes closure-make-deps emit uninteresting warnings. Now any output from the command will be informative and related to whatever one is presently working on. --- blocks/procedures.js | 4 ++-- core/contextmenu_items.js | 3 ++- core/renderers/geras/info.js | 12 ++++++------ core/renderers/thrasos/info.js | 12 ++++++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index d6127cca0..644d7a751 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -519,7 +519,7 @@ Blockly.Blocks['procedures_mutatorarg'] = { * @param {string} varName User-supplied name. * @return {?string} Valid name, or null if a name was not specified. * @private - * @this Blockly.FieldTextInput + * @this {Blockly.FieldTextInput} */ validator_: function(varName) { var sourceBlock = this.getSourceBlock(); @@ -571,7 +571,7 @@ Blockly.Blocks['procedures_mutatorarg'] = { * variable name. * @param {string} newText The new variable name. * @private - * @this Blockly.FieldTextInput + * @this {Blockly.FieldTextInput} */ deleteIntermediateVars_: function(newText) { var outerWs = Blockly.Mutator.findParentWs(this.getSourceBlock().workspace); diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index 581de6cdf..a8e3a41e5 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -191,7 +191,8 @@ Blockly.ContextMenuItems.addDeletableBlocks_ = function(block, deleteList) { if (block.isDeletable()) { Array.prototype.push.apply(deleteList, block.getDescendants(false)); } else { - var children = /** @type !Array */ (block.getChildren(false)); + var children = + /** @type {!Array} */ (block.getChildren(false)); for (var i = 0; i < children.length; i++) { Blockly.ContextMenuItems.addDeletableBlocks_(children[i], deleteList); } diff --git a/core/renderers/geras/info.js b/core/renderers/geras/info.js index 4bca698f6..ffc515a17 100644 --- a/core/renderers/geras/info.js +++ b/core/renderers/geras/info.js @@ -158,7 +158,7 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Between an editable field and the beginning of the row. if (next && Blockly.blockRendering.Types.isField(next) && - (/** @type Blockly.blockRendering.Field */ (next)).isEditable) { + (/** @type {Blockly.blockRendering.Field} */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Inline input at the beginning of the row. @@ -177,7 +177,7 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { Blockly.blockRendering.Types.isStatementInput(next))) { // Between an editable field and the end of the row. if (Blockly.blockRendering.Types.isField(prev) && - (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { + (/** @type {Blockly.blockRendering.Field} */ (prev)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Padding at the end of an icon-only row to make the block shape clearer. @@ -219,7 +219,7 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { next && Blockly.blockRendering.Types.isInput(next)) { // Between an editable field and an input. if (Blockly.blockRendering.Types.isField(prev) && - (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { + (/** @type {Blockly.blockRendering.Field} */ (prev)).isEditable) { if (Blockly.blockRendering.Types.isInlineInput(next)) { return this.constants_.SMALL_PADDING; } else if (Blockly.blockRendering.Types.isExternalInput(next)) { @@ -247,7 +247,7 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (Blockly.blockRendering.Types.isInlineInput(prev) && next && Blockly.blockRendering.Types.isField(next)) { // Editable field after inline input. - if ((/** @type Blockly.blockRendering.Field */ (next)).isEditable) { + if ((/** @type {Blockly.blockRendering.Field} */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } else { // Noneditable field after inline input. @@ -288,8 +288,8 @@ Blockly.geras.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { // Spacing between two fields of the same editability. if (Blockly.blockRendering.Types.isField(prev) && next && Blockly.blockRendering.Types.isField(next) && - ((/** @type Blockly.blockRendering.Field */ (prev)).isEditable == - (/** @type Blockly.blockRendering.Field */ (next)).isEditable)) { + ((/** @type {Blockly.blockRendering.Field} */ (prev)).isEditable == + (/** @type {Blockly.blockRendering.Field} */ (next)).isEditable)) { return this.constants_.LARGE_PADDING; } diff --git a/core/renderers/thrasos/info.js b/core/renderers/thrasos/info.js index a5208c57d..962c6ea6d 100644 --- a/core/renderers/thrasos/info.js +++ b/core/renderers/thrasos/info.js @@ -97,7 +97,7 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Between an editable field and the beginning of the row. if (next && Blockly.blockRendering.Types.isField(next) && - (/** @type Blockly.blockRendering.Field */ (next)).isEditable) { + (/** @type {Blockly.blockRendering.Field} */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Inline input at the beginning of the row. @@ -115,7 +115,7 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!Blockly.blockRendering.Types.isInput(prev) && !next) { // Between an editable field and the end of the row. if (Blockly.blockRendering.Types.isField(prev) && - (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { + (/** @type {Blockly.blockRendering.Field} */ (prev)).isEditable) { return this.constants_.MEDIUM_PADDING; } // Padding at the end of an icon-only row to make the block shape clearer. @@ -157,7 +157,7 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { next && Blockly.blockRendering.Types.isInput(next)) { // Between an editable field and an input. if (Blockly.blockRendering.Types.isField(prev) && - (/** @type Blockly.blockRendering.Field */ (prev)).isEditable) { + (/** @type {Blockly.blockRendering.Field} */ (prev)).isEditable) { if (Blockly.blockRendering.Types.isInlineInput(next)) { return this.constants_.SMALL_PADDING; } else if (Blockly.blockRendering.Types.isExternalInput(next)) { @@ -185,7 +185,7 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (Blockly.blockRendering.Types.isInlineInput(prev) && next && Blockly.blockRendering.Types.isField(next)) { // Editable field after inline input. - if ((/** @type Blockly.blockRendering.Field */ (next)).isEditable) { + if ((/** @type {Blockly.blockRendering.Field} */ (next)).isEditable) { return this.constants_.MEDIUM_PADDING; } else { // Noneditable field after inline input. @@ -213,8 +213,8 @@ Blockly.thrasos.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { // Spacing between two fields of the same editability. if (Blockly.blockRendering.Types.isField(prev) && next && Blockly.blockRendering.Types.isField(next) && - ((/** @type Blockly.blockRendering.Field */ (prev)).isEditable == - (/** @type Blockly.blockRendering.Field */ (next)).isEditable)) { + ((/** @type {Blockly.blockRendering.Field} */ (prev)).isEditable == + (/** @type {Blockly.blockRendering.Field} */ (next)).isEditable)) { return this.constants_.LARGE_PADDING; } From 603755f250f4f8da9324f699ba946c2cc67fe7c2 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 12 Jul 2021 03:51:17 +0100 Subject: [PATCH 005/833] Suppress spurious eslint error eslint appears to be confused by the leading JSDoc comment on the continuation line and suggests it should be indented only 4 rather than 8 spaces. --- core/contextmenu_items.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index a8e3a41e5..da417cac6 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -191,6 +191,7 @@ Blockly.ContextMenuItems.addDeletableBlocks_ = function(block, deleteList) { if (block.isDeletable()) { Array.prototype.push.apply(deleteList, block.getDescendants(false)); } else { + /* eslint-disable indent */ var children = /** @type {!Array} */ (block.getChildren(false)); for (var i = 0; i < children.length; i++) { From 948fade7c5c0593f964c12b305fd8bbb3db09da9 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Tue, 13 Jul 2021 12:08:35 +0100 Subject: [PATCH 006/833] Only disable eslint indent check on one line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For whatever reason eslint was rejecting the (styleguide-correct) indentation of the line beginning with "/** @type ...", and in my naïvete I got a little more zealous than I intended in suppressing the error. --- core/contextmenu_items.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index da417cac6..dffd4a83d 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -191,8 +191,7 @@ Blockly.ContextMenuItems.addDeletableBlocks_ = function(block, deleteList) { if (block.isDeletable()) { Array.prototype.push.apply(deleteList, block.getDescendants(false)); } else { - /* eslint-disable indent */ - var children = + var children = /* eslint-disable-next-line indent */ /** @type {!Array} */ (block.getChildren(false)); for (var i = 0; i < children.length; i++) { Blockly.ContextMenuItems.addDeletableBlocks_(children[i], deleteList); From 78b8e2fa85aae38ca3c01ef7b194863a21c9071e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 14:42:56 -0700 Subject: [PATCH 007/833] Migrate object.js to ES6 const/let --- core/utils/object.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/object.js b/core/utils/object.js index 3e95934d2..1317fd58b 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -46,7 +46,7 @@ Blockly.utils.object.inherits = function(childCtor, parentCtor) { * @param {!Object} source Source. */ Blockly.utils.object.mixin = function(target, source) { - for (var x in source) { + for (const x in source) { target[x] = source[x]; } }; @@ -58,7 +58,7 @@ Blockly.utils.object.mixin = function(target, source) { * @return {!Object} The resulting object. */ Blockly.utils.object.deepMerge = function(target, source) { - for (var x in source) { + for (const x in source) { if (source[x] != null && typeof source[x] === 'object') { target[x] = Blockly.utils.object.deepMerge( target[x] || Object.create(null), source[x]); From d224a2341deffc33d628d3da148cc7489ad9483e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 15:30:56 -0700 Subject: [PATCH 008/833] Migrate object.js to goog.module --- core/utils/object.js | 21 ++++++++++++++------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/utils/object.js b/core/utils/object.js index 1317fd58b..ea7b3632a 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -14,7 +14,8 @@ * @name Blockly.utils.object * @namespace */ -goog.provide('Blockly.utils.object'); +goog.module('Blockly.utils.object'); +goog.module.declareLegacyNamespace(); /** @@ -23,7 +24,7 @@ goog.provide('Blockly.utils.object'); * @param {!Function} parentCtor Parent class. * @suppress {strictMissingProperties} superClass_ is not defined on Function. */ -Blockly.utils.object.inherits = function(childCtor, parentCtor) { +const inherits = function(childCtor, parentCtor) { // Set a .superClass_ property so that methods can call parent methods // without hard-coding the parent class name. // Could be replaced by ES6's super(). @@ -45,7 +46,7 @@ Blockly.utils.object.inherits = function(childCtor, parentCtor) { * @param {!Object} target Target. * @param {!Object} source Source. */ -Blockly.utils.object.mixin = function(target, source) { +const mixin = function(target, source) { for (const x in source) { target[x] = source[x]; } @@ -57,11 +58,10 @@ Blockly.utils.object.mixin = function(target, source) { * @param {!Object} source Source. * @return {!Object} The resulting object. */ -Blockly.utils.object.deepMerge = function(target, source) { +const deepMerge = function(target, source) { for (const x in source) { if (source[x] != null && typeof source[x] === 'object') { - target[x] = Blockly.utils.object.deepMerge( - target[x] || Object.create(null), source[x]); + target[x] = deepMerge(target[x] || Object.create(null), source[x]); } else { target[x] = source[x]; } @@ -74,7 +74,7 @@ Blockly.utils.object.deepMerge = function(target, source) { * @param {!Object} obj Object containing values. * @return {!Array} Array of values. */ -Blockly.utils.object.values = function(obj) { +const values = function(obj) { if (Object.values) { return Object.values(obj); } @@ -83,3 +83,10 @@ Blockly.utils.object.values = function(obj) { return obj[e]; }); }; + +exports = { + inherits, + mixin, + deepMerge, + values, +} \ No newline at end of file diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..01054cdfa 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -179,7 +179,7 @@ goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerato goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); -goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); +goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); From 2bdf2627afa2b1ef721b77f0f491ab563c8378b7 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Tue, 13 Jul 2021 23:54:36 +0100 Subject: [PATCH 009/833] Configure eslint and Closure Compiler to accept ES6 --- .eslintrc.json | 1 + scripts/gulpfiles/build_tasks.js | 1 + 2 files changed, 2 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index 0d5daf79c..9d74291da 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -75,6 +75,7 @@ }] }, "env": { + "es6": true, "browser": true }, "globals": { diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index 3aaa4ac04..e6f496544 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -118,6 +118,7 @@ function compile(compilerOptions, opt_verbose, opt_warnings_as_error, const options = {}; options.compilation_level = 'SIMPLE_OPTIMIZATIONS'; options.warning_level = opt_verbose ? 'VERBOSE' : 'DEFAULT'; + options.language_in = 'ECMASCRIPT6_STRICT', options.language_out = 'ECMASCRIPT5_STRICT'; options.rewrite_polyfills = false; options.hide_warnings_for = 'node_modules'; From 632ef12ed577d0aa881b579b0e1625b20faf0e6e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:45:34 -0700 Subject: [PATCH 010/833] Migrate core/utils/keycodes.js to goog.module --- core/utils/keycodes.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/utils/keycodes.js b/core/utils/keycodes.js index a5be94cb8..586d2f97e 100644 --- a/core/utils/keycodes.js +++ b/core/utils/keycodes.js @@ -16,7 +16,8 @@ * @name Blockly.utils.KeyCodes * @namespace */ -goog.provide('Blockly.utils.KeyCodes'); +goog.module('Blockly.utils.KeyCodes'); +goog.module.declareLegacyNamespace(); /** @@ -29,7 +30,7 @@ goog.provide('Blockly.utils.KeyCodes'); * * @enum {number} */ -Blockly.utils.KeyCodes = { +const KeyCodes = { WIN_KEY_FF_LINUX: 0, MAC_ENTER: 3, BACKSPACE: 8, @@ -166,3 +167,5 @@ Blockly.utils.KeyCodes = { // http://en.community.dell.com/support-forums/laptop/f/3518/p/19285957/19523128.aspx PHANTOM: 255 }; + +exports = KeyCodes; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..45860bd0c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -176,7 +176,7 @@ goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecatio goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); -goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); +goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); From b92fba1a5a934d051be8e0e1fb9b4b8497c7ecf5 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 10:55:10 -0700 Subject: [PATCH 011/833] Fixed missing semicolon. --- core/utils/object.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/object.js b/core/utils/object.js index ea7b3632a..dae55ec51 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -89,4 +89,4 @@ exports = { mixin, deepMerge, values, -} \ No newline at end of file +}; From cd4831537eea7e0547dd68f7626303a2012d0d8e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 17:16:17 -0700 Subject: [PATCH 012/833] Migrate core/utils/deprecation.js to ES6 const/let --- core/utils/deprecation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index 4c948f22b..b849c2a1a 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -31,8 +31,8 @@ goog.provide('Blockly.utils.deprecation'); */ Blockly.utils.deprecation.warn = function( name, deprecationDate, deletionDate, opt_use) { - var msg = name + ' was deprecated on ' + deprecationDate + - ' and will be deleted on ' + deletionDate + '.'; + let msg = name + ' was deprecated on ' + deprecationDate + + ' and will be deleted on ' + deletionDate + '.'; if (opt_use) { msg += '\nUse ' + opt_use + ' instead.'; } From 2bf717019fc555fb9f6d6a713460929b18b105e5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:12:10 -0700 Subject: [PATCH 013/833] Migrate core/utils/deprecation.js to goog.module --- core/utils/deprecation.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index b849c2a1a..a361f563d 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -15,7 +15,8 @@ * @name Blockly.utils.deprecation * @namespace */ -goog.provide('Blockly.utils.deprecation'); +goog.module('Blockly.utils.deprecation'); +goog.module.declareLegacyNamespace(); /** @@ -29,7 +30,7 @@ goog.provide('Blockly.utils.deprecation'); * if any. * @package */ -Blockly.utils.deprecation.warn = function( +const warn = function( name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + ' and will be deleted on ' + deletionDate + '.'; @@ -38,3 +39,5 @@ Blockly.utils.deprecation.warn = function( } console.warn(msg); }; + +exports = {warn}; diff --git a/tests/deps.js b/tests/deps.js index 45860bd0c..daed787d5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -172,7 +172,7 @@ goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Bl goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); -goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); +goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); From 819a0f1596c66faa0cf5bcc88fe912d8c42b0422 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:12:13 -0700 Subject: [PATCH 014/833] clang-format core/utils/deprecation.js --- core/utils/deprecation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index a361f563d..ad798b1ab 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -30,8 +30,7 @@ goog.module.declareLegacyNamespace(); * if any. * @package */ -const warn = function( - name, deprecationDate, deletionDate, opt_use) { +const warn = function(name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + ' and will be deleted on ' + deletionDate + '.'; if (opt_use) { From 08911510d2c18ad66d41007727abc1a688d93239 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 13:23:57 -0700 Subject: [PATCH 015/833] Migrate core/utils/idgenerator.js to goog.module --- core/utils/idgenerator.js | 11 +++++++---- tests/deps.js | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/utils/idgenerator.js b/core/utils/idgenerator.js index 347b71d02..6ad7bcf55 100644 --- a/core/utils/idgenerator.js +++ b/core/utils/idgenerator.js @@ -16,7 +16,8 @@ * @name Blockly.utils.IdGenerator * @namespace */ -goog.provide('Blockly.utils.IdGenerator'); +goog.module('Blockly.utils.IdGenerator'); +goog.module.declareLegacyNamespace(); /** @@ -24,7 +25,7 @@ goog.provide('Blockly.utils.IdGenerator'); * @type {number} * @private */ -Blockly.utils.IdGenerator.nextId_ = 0; +let nextId = 0; /** * Gets the next unique ID. @@ -32,6 +33,8 @@ Blockly.utils.IdGenerator.nextId_ = 0; * Use only ASCII letters, digits, '_', '-' and '.' * @return {string} The next unique identifier. */ -Blockly.utils.IdGenerator.getNextUniqueId = function() { - return 'blockly-' + (Blockly.utils.IdGenerator.nextId_++).toString(36); +const getNextUniqueId = function() { + return 'blockly-' + (nextId++).toString(36); }; + +exports = {getNextUniqueId}; diff --git a/tests/deps.js b/tests/deps.js index 45860bd0c..d0f01aef3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,6 +4,7 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -175,7 +176,7 @@ goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate' goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); -goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); +goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); From 78e72222c1e82c55b04ff7a836cfec50f06e8479 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 13:48:22 -0700 Subject: [PATCH 016/833] Migrate core/utils/style.js to ES6 const/let --- core/utils/style.js | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 1c169453d..cdb22139c 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -34,17 +34,17 @@ Blockly.utils.style.getSize = function(element) { } // Evaluate size with a temporary element. - var style = element.style; - var originalDisplay = style.display; - var originalVisibility = style.visibility; - var originalPosition = style.position; + const style = element.style; + const originalDisplay = style.display; + const originalVisibility = style.visibility; + const originalPosition = style.position; style.visibility = 'hidden'; style.position = 'absolute'; style.display = 'inline'; - var offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; - var offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; + const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; + const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; style.display = originalDisplay; style.position = originalPosition; @@ -60,8 +60,8 @@ Blockly.utils.style.getSize = function(element) { * @private */ Blockly.utils.style.getSizeWithDisplay_ = function(element) { - var offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; - var offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; + const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; + const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Blockly.utils.Size(offsetWidth, offsetHeight); }; @@ -99,7 +99,7 @@ Blockly.utils.style.getStyle_ = function(element, style) { */ Blockly.utils.style.getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { - var styles = document.defaultView.getComputedStyle(element, null); + const styles = document.defaultView.getComputedStyle(element, null); if (styles) { // element.style[..] is undefined for browser specific styles // as 'filter'. @@ -132,13 +132,13 @@ Blockly.utils.style.getCascadedStyle = function(element, style) { * @return {!Blockly.utils.Coordinate} The page offset. */ Blockly.utils.style.getPageOffset = function(el) { - var pos = new Blockly.utils.Coordinate(0, 0); - var box = el.getBoundingClientRect(); - var documentElement = document.documentElement; + const pos = new Blockly.utils.Coordinate(0, 0); + const box = el.getBoundingClientRect(); + const documentElement = document.documentElement; // Must add the scroll coordinates in to get the absolute page offset // of element since getBoundingClientRect returns relative coordinates to // the viewport. - var scrollCoord = new Blockly.utils.Coordinate( + const scrollCoord = new Blockly.utils.Coordinate( window.pageXOffset || documentElement.scrollLeft, window.pageYOffset || documentElement.scrollTop); pos.x = box.left + scrollCoord.x; @@ -153,10 +153,10 @@ Blockly.utils.style.getPageOffset = function(el) { * @return {!Blockly.utils.Coordinate} The page offset of the viewport. */ Blockly.utils.style.getViewportPageOffset = function() { - var body = document.body; - var documentElement = document.documentElement; - var scrollLeft = body.scrollLeft || documentElement.scrollLeft; - var scrollTop = body.scrollTop || documentElement.scrollTop; + const body = document.body; + const documentElement = document.documentElement; + const scrollLeft = body.scrollLeft || documentElement.scrollLeft; + const scrollTop = body.scrollTop || documentElement.scrollTop; return new Blockly.utils.Coordinate(scrollLeft, scrollTop); }; @@ -194,10 +194,10 @@ Blockly.utils.style.isRightToLeft = function(el) { * @return {!Object} The computed border widths. */ Blockly.utils.style.getBorderBox = function(element) { - var left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth'); - var right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth'); - var top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth'); - var bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth'); + const left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth'); + const right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth'); + const top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth'); + const bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth'); return { top: parseFloat(top), @@ -222,7 +222,7 @@ Blockly.utils.style.getBorderBox = function(element) { */ Blockly.utils.style.scrollIntoContainerView = function( element, container, opt_center) { - var offset = + const offset = Blockly.utils.style.getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; @@ -247,21 +247,21 @@ Blockly.utils.style.scrollIntoContainerView = function( Blockly.utils.style.getContainerOffsetToScrollInto = function( element, container, opt_center) { // Absolute position of the element's border's top left corner. - var elementPos = Blockly.utils.style.getPageOffset(element); + const elementPos = Blockly.utils.style.getPageOffset(element); // Absolute position of the container's border's top left corner. - var containerPos = Blockly.utils.style.getPageOffset(container); - var containerBorder = Blockly.utils.style.getBorderBox(container); + const containerPos = Blockly.utils.style.getPageOffset(container); + const containerBorder = Blockly.utils.style.getBorderBox(container); // Relative pos. of the element's border box to the container's content box. - var relX = elementPos.x - containerPos.x - containerBorder.left; - var relY = elementPos.y - containerPos.y - containerBorder.top; + const relX = elementPos.x - containerPos.x - containerBorder.left; + const relY = elementPos.y - containerPos.y - containerBorder.top; // How much the element can move in the container, i.e. the difference between // the element's bottom-right-most and top-left-most position where it's // fully visible. - var elementSize = Blockly.utils.style.getSizeWithDisplay_(element); - var spaceX = container.clientWidth - elementSize.width; - var spaceY = container.clientHeight - elementSize.height; - var scrollLeft = container.scrollLeft; - var scrollTop = container.scrollTop; + const elementSize = Blockly.utils.style.getSizeWithDisplay_(element); + const spaceX = container.clientWidth - elementSize.width; + const spaceY = container.clientHeight - elementSize.height; + let scrollLeft = container.scrollLeft; + let scrollTop = container.scrollTop; if (opt_center) { // All browsers round non-integer scroll positions down. scrollLeft += relX - spaceX / 2; From 656f4fc9d680fa9e5b4b577942d03900c858ef2a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 13:58:05 -0700 Subject: [PATCH 017/833] Migrate core/utils/style.js to goog.module --- core/utils/style.js | 68 +++++++++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index cdb22139c..9447db11a 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -16,7 +16,8 @@ * @name Blockly.utils.style * @namespace */ -goog.provide('Blockly.utils.style'); +goog.module('Blockly.utils.style'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.Size'); @@ -28,9 +29,9 @@ goog.require('Blockly.utils.Size'); * @param {!Element} element Element to get size of. * @return {!Blockly.utils.Size} Object with width/height properties. */ -Blockly.utils.style.getSize = function(element) { - if (Blockly.utils.style.getStyle_(element, 'display') != 'none') { - return Blockly.utils.style.getSizeWithDisplay_(element); +const getSize = function(element) { + if (getStyle(element, 'display') != 'none') { + return getSizeWithDisplay(element); } // Evaluate size with a temporary element. @@ -59,7 +60,7 @@ Blockly.utils.style.getSize = function(element) { * @return {!Blockly.utils.Size} Object with width/height properties. * @private */ -Blockly.utils.style.getSizeWithDisplay_ = function(element) { +const getSizeWithDisplay = function(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Blockly.utils.Size(offsetWidth, offsetHeight); @@ -79,9 +80,9 @@ Blockly.utils.style.getSizeWithDisplay_ = function(element) { * @return {string} Style value. * @private */ -Blockly.utils.style.getStyle_ = function(element, style) { - return Blockly.utils.style.getComputedStyle(element, style) || - Blockly.utils.style.getCascadedStyle(element, style) || +const getStyle = function(element, style) { + return getComputedStyle(element, style) || + getCascadedStyle(element, style) || (element.style && element.style[style]); }; @@ -97,7 +98,7 @@ Blockly.utils.style.getStyle_ = function(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -Blockly.utils.style.getComputedStyle = function(element, property) { +const getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -120,7 +121,7 @@ Blockly.utils.style.getComputedStyle = function(element, property) { * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -Blockly.utils.style.getCascadedStyle = function(element, style) { +const getCascadedStyle = function(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); }; @@ -131,7 +132,7 @@ Blockly.utils.style.getCascadedStyle = function(element, style) { * @param {!Element} el Element to get the page offset for. * @return {!Blockly.utils.Coordinate} The page offset. */ -Blockly.utils.style.getPageOffset = function(el) { +const getPageOffset = function(el) { const pos = new Blockly.utils.Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -152,7 +153,7 @@ Blockly.utils.style.getPageOffset = function(el) { * Similar to Closure's goog.style.getViewportPageOffset * @return {!Blockly.utils.Coordinate} The page offset of the viewport. */ -Blockly.utils.style.getViewportPageOffset = function() { +const getViewportPageOffset = function() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; @@ -172,7 +173,7 @@ Blockly.utils.style.getViewportPageOffset = function() { * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -Blockly.utils.style.setElementShown = function(el, isShown) { +const setElementShown = function(el, isShown) { el.style.display = isShown ? '' : 'none'; }; @@ -183,8 +184,8 @@ Blockly.utils.style.setElementShown = function(el, isShown) { * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -Blockly.utils.style.isRightToLeft = function(el) { - return 'rtl' == Blockly.utils.style.getStyle_(el, 'direction'); +const isRightToLeft = function(el) { + return 'rtl' == getStyle(el, 'direction'); }; /** @@ -193,11 +194,11 @@ Blockly.utils.style.isRightToLeft = function(el) { * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -Blockly.utils.style.getBorderBox = function(element) { - const left = Blockly.utils.style.getComputedStyle(element, 'borderLeftWidth'); - const right = Blockly.utils.style.getComputedStyle(element, 'borderRightWidth'); - const top = Blockly.utils.style.getComputedStyle(element, 'borderTopWidth'); - const bottom = Blockly.utils.style.getComputedStyle(element, 'borderBottomWidth'); +const getBorderBox = function(element) { + const left = getComputedStyle(element, 'borderLeftWidth'); + const right = getComputedStyle(element, 'borderRightWidth'); + const top = getComputedStyle(element, 'borderTopWidth'); + const bottom = getComputedStyle(element, 'borderBottomWidth'); return { top: parseFloat(top), @@ -220,10 +221,10 @@ Blockly.utils.style.getBorderBox = function(element) { * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -Blockly.utils.style.scrollIntoContainerView = function( +const scrollIntoContainerView = function( element, container, opt_center) { const offset = - Blockly.utils.style.getContainerOffsetToScrollInto(element, + getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; @@ -244,20 +245,20 @@ Blockly.utils.style.scrollIntoContainerView = function( * @return {!Blockly.utils.Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -Blockly.utils.style.getContainerOffsetToScrollInto = function( +const getContainerOffsetToScrollInto = function( element, container, opt_center) { // Absolute position of the element's border's top left corner. - const elementPos = Blockly.utils.style.getPageOffset(element); + const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. - const containerPos = Blockly.utils.style.getPageOffset(container); - const containerBorder = Blockly.utils.style.getBorderBox(container); + const containerPos = getPageOffset(container); + const containerBorder = getBorderBox(container); // Relative pos. of the element's border box to the container's content box. const relX = elementPos.x - containerPos.x - containerBorder.left; const relY = elementPos.y - containerPos.y - containerBorder.top; // How much the element can move in the container, i.e. the difference between // the element's bottom-right-most and top-left-most position where it's // fully visible. - const elementSize = Blockly.utils.style.getSizeWithDisplay_(element); + const elementSize = getSizeWithDisplay(element); const spaceX = container.clientWidth - elementSize.width; const spaceY = container.clientHeight - elementSize.height; let scrollLeft = container.scrollLeft; @@ -279,3 +280,16 @@ Blockly.utils.style.getContainerOffsetToScrollInto = function( } return new Blockly.utils.Coordinate(scrollLeft, scrollTop); }; + +exports = { + getSize, + getComputedStyle, + getCascadedStyle, + getPageOffset, + getViewportPageOffset, + setElementShown, + isRightToLeft, + getBorderBox, + scrollIntoContainerView, + getContainerOffsetToScrollInto, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..fafe772f1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -183,7 +183,7 @@ goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], []); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); -goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); +goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); From 55ac3741b7ec070315f44d97a604b048db2df43e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:10:42 -0700 Subject: [PATCH 018/833] Migrate core/utils/style.js to named requires --- core/utils/style.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 9447db11a..90cfa1d9a 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -19,15 +19,15 @@ goog.module('Blockly.utils.style'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.Size'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Size = goog.require('Blockly.utils.Size'); /** * Gets the height and width of an element. * Similar to Closure's goog.style.getSize * @param {!Element} element Element to get size of. - * @return {!Blockly.utils.Size} Object with width/height properties. + * @return {!Size} Object with width/height properties. */ const getSize = function(element) { if (getStyle(element, 'display') != 'none') { @@ -51,19 +51,19 @@ const getSize = function(element) { style.position = originalPosition; style.visibility = originalVisibility; - return new Blockly.utils.Size(offsetWidth, offsetHeight); + return new Size(offsetWidth, offsetHeight); }; /** * Gets the height and width of an element when the display is not none. * @param {!Element} element Element to get size of. - * @return {!Blockly.utils.Size} Object with width/height properties. + * @return {!Size} Object with width/height properties. * @private */ const getSizeWithDisplay = function(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; - return new Blockly.utils.Size(offsetWidth, offsetHeight); + return new Size(offsetWidth, offsetHeight); }; /** @@ -130,16 +130,16 @@ const getCascadedStyle = function(element, style) { * Returns a Coordinate object relative to the top-left of the HTML document. * Similar to Closure's goog.style.getPageOffset * @param {!Element} el Element to get the page offset for. - * @return {!Blockly.utils.Coordinate} The page offset. + * @return {!Coordinate} The page offset. */ const getPageOffset = function(el) { - const pos = new Blockly.utils.Coordinate(0, 0); + const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; // Must add the scroll coordinates in to get the absolute page offset // of element since getBoundingClientRect returns relative coordinates to // the viewport. - const scrollCoord = new Blockly.utils.Coordinate( + const scrollCoord = new Coordinate( window.pageXOffset || documentElement.scrollLeft, window.pageYOffset || documentElement.scrollTop); pos.x = box.left + scrollCoord.x; @@ -151,14 +151,14 @@ const getPageOffset = function(el) { /** * Calculates the viewport coordinates relative to the document. * Similar to Closure's goog.style.getViewportPageOffset - * @return {!Blockly.utils.Coordinate} The page offset of the viewport. + * @return {!Coordinate} The page offset of the viewport. */ const getViewportPageOffset = function() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; const scrollTop = body.scrollTop || documentElement.scrollTop; - return new Blockly.utils.Coordinate(scrollLeft, scrollTop); + return new Coordinate(scrollLeft, scrollTop); }; /** @@ -242,7 +242,7 @@ const scrollIntoContainerView = function( * document scroll element will be used. * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. - * @return {!Blockly.utils.Coordinate} The new scroll position of the container, + * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ const getContainerOffsetToScrollInto = function( @@ -278,7 +278,7 @@ const getContainerOffsetToScrollInto = function( scrollLeft += Math.min(relX, Math.max(relX - spaceX, 0)); scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } - return new Blockly.utils.Coordinate(scrollLeft, scrollTop); + return new Coordinate(scrollLeft, scrollTop); }; exports = { From 46a3462026e158f5821207bd32bc1f3836371b87 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:11:25 -0700 Subject: [PATCH 019/833] clang-format core/utils/style.js --- core/utils/style.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 90cfa1d9a..028b746b8 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -81,8 +81,7 @@ const getSizeWithDisplay = function(element) { * @private */ const getStyle = function(element, style) { - return getComputedStyle(element, style) || - getCascadedStyle(element, style) || + return getComputedStyle(element, style) || getCascadedStyle(element, style) || (element.style && element.style[style]); }; @@ -221,11 +220,8 @@ const getBorderBox = function(element) { * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -const scrollIntoContainerView = function( - element, container, opt_center) { - const offset = - getContainerOffsetToScrollInto(element, - container, opt_center); +const scrollIntoContainerView = function(element, container, opt_center) { + const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; }; From 72a07613120361d3ecc9425dd2e5127f7bd40016 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:43:15 -0700 Subject: [PATCH 020/833] Migrate core/utils/svg_paths.js to goog.module --- core/utils/svg_paths.js | 30 +++++++++++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index e123dca28..d380d45f6 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -15,7 +15,8 @@ * @name Blockly.utils.svgPaths * @namespace */ -goog.provide('Blockly.utils.svgPaths'); +goog.module('Blockly.utils.svgPaths'); +goog.module.declareLegacyNamespace(); /** @@ -28,7 +29,7 @@ goog.provide('Blockly.utils.svgPaths'); * @return {string} A string of the format ' x,y ' * @public */ -Blockly.utils.svgPaths.point = function(x, y) { +const point = function(x, y) { return ' ' + x + ',' + y + ' '; }; @@ -45,7 +46,7 @@ Blockly.utils.svgPaths.point = function(x, y) { * documentation for exact format. * @public */ -Blockly.utils.svgPaths.curve = function(command, points) { +const curve = function(command, points) { return ' ' + command + points.join(''); }; @@ -59,7 +60,7 @@ Blockly.utils.svgPaths.curve = function(command, points) { * @return {string} A string of the format ' M x,y ' * @public */ -Blockly.utils.svgPaths.moveTo = function(x, y) { +const moveTo = function(x, y) { return ' M ' + x + ',' + y + ' '; }; @@ -73,7 +74,7 @@ Blockly.utils.svgPaths.moveTo = function(x, y) { * @return {string} A string of the format ' m dx,dy ' * @public */ -Blockly.utils.svgPaths.moveBy = function(dx, dy) { +const moveBy = function(dx, dy) { return ' m ' + dx + ',' + dy + ' '; }; @@ -87,7 +88,7 @@ Blockly.utils.svgPaths.moveBy = function(dx, dy) { * @return {string} A string of the format ' l dx,dy ' * @public */ -Blockly.utils.svgPaths.lineTo = function(dx, dy) { +const lineTo = function(dx, dy) { return ' l ' + dx + ',' + dy + ' '; }; @@ -102,7 +103,7 @@ Blockly.utils.svgPaths.lineTo = function(dx, dy) { * @return {string} A string of the format ' l (dx,dy)+ ' * @public */ -Blockly.utils.svgPaths.line = function(points) { +const line = function(points) { return ' l' + points.join(''); }; @@ -119,7 +120,7 @@ Blockly.utils.svgPaths.line = function(points) { * @return {string} A string of the format ' command val ' * @public */ -Blockly.utils.svgPaths.lineOnAxis = function(command, val) { +const lineOnAxis = function(command, val) { return ' ' + command + ' ' + val + ' '; }; @@ -137,6 +138,17 @@ Blockly.utils.svgPaths.lineOnAxis = function(command, val) { * @return {string} A string of the format 'command radius radius flags point' * @public */ -Blockly.utils.svgPaths.arc = function(command, flags, radius, point) { +const arc = function(command, flags, radius, point) { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; }; + +exports = { + point, + curve, + moveTo, + moveBy, + lineTo, + line, + lineOnAxis, + arc, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..1c324ff68 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -185,7 +185,7 @@ goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); From 916b49a2e5d4a757dbf4d6504af1713edfee32ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:44:17 -0700 Subject: [PATCH 021/833] clang-format core/utils/svg_paths.js --- core/utils/svg_paths.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index d380d45f6..02602e4ac 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -39,9 +39,9 @@ const point = function(x, y) { * These coordinates are unitless and hence in the user coordinate system. * @param {string} command The command to use. * Should be one of: c, C, s, S, q, Q. - * @param {!Array} points An array containing all of the points to pass to the - * curve command, in order. The points are represented as strings of the - * format ' x, y '. + * @param {!Array} points An array containing all of the points to pass + * to the curve command, in order. The points are represented as strings of + * the format ' x, y '. * @return {string} A string defining one or more Bezier curves. See the MDN * documentation for exact format. * @public From 042b235764e98e359d67672121170d487b618534 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 14:52:17 -0700 Subject: [PATCH 022/833] Migrate core/utils/dom.js to ES6 const/let --- core/utils/dom.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 57843c8b9..049aa9f07 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -84,9 +84,9 @@ Blockly.utils.dom.canvasContext_ = null; * @template T */ Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { - var e = /** @type {T} */ + const e = /** @type {T} */ (document.createElementNS(Blockly.utils.dom.SVG_NS, String(name))); - for (var key in attrs) { + for (const key in attrs) { e.setAttribute(key, attrs[key]); } // IE defines a unique attribute "runtimeStyle", it is NOT applied to @@ -109,7 +109,7 @@ Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { * @return {boolean} True if class was added, false if already present. */ Blockly.utils.dom.addClass = function(element, className) { - var classes = element.getAttribute('class') || ''; + let classes = element.getAttribute('class') || ''; if ((' ' + classes + ' ').indexOf(' ' + className + ' ') != -1) { return false; } @@ -127,9 +127,9 @@ Blockly.utils.dom.addClass = function(element, className) { * element. */ Blockly.utils.dom.removeClasses = function(element, classNames) { - var classList = classNames.split(' '); - for (var i = 0; i < classList.length; i++) { - var cssName = classList[i]; + const classList = classNames.split(' '); + for (let i = 0; i < classList.length; i++) { + const cssName = classList[i]; Blockly.utils.dom.removeClass(element, cssName); } }; @@ -142,12 +142,12 @@ Blockly.utils.dom.removeClasses = function(element, classNames) { * @return {boolean} True if class was removed, false if never present. */ Blockly.utils.dom.removeClass = function(element, className) { - var classes = element.getAttribute('class'); + const classes = element.getAttribute('class'); if ((' ' + classes + ' ').indexOf(' ' + className + ' ') == -1) { return false; } - var classList = classes.split(/\s+/); - for (var i = 0; i < classList.length; i++) { + const classList = classes.split(/\s+/); + for (let i = 0; i < classList.length; i++) { if (!classList[i] || classList[i] == className) { classList.splice(i, 1); i--; @@ -169,7 +169,7 @@ Blockly.utils.dom.removeClass = function(element, className) { * @return {boolean} True if class exists, false otherwise. */ Blockly.utils.dom.hasClass = function(element, className) { - var classes = element.getAttribute('class'); + const classes = element.getAttribute('class'); return (' ' + classes + ' ').indexOf(' ' + className + ' ') != -1; }; @@ -190,8 +190,8 @@ Blockly.utils.dom.removeNode = function(node) { * @param {!Element} refNode Existing element to precede new node. */ Blockly.utils.dom.insertAfter = function(newNode, refNode) { - var siblingNode = refNode.nextSibling; - var parentNode = refNode.parentNode; + const siblingNode = refNode.nextSibling; + const parentNode = refNode.parentNode; if (!parentNode) { throw Error('Reference node has no parent.'); } @@ -253,8 +253,8 @@ Blockly.utils.dom.stopTextWidthCache = function() { * @return {number} Width of element. */ Blockly.utils.dom.getTextWidth = function(textElement) { - var key = textElement.textContent + '\n' + textElement.className.baseVal; - var width; + const key = textElement.textContent + '\n' + textElement.className.baseVal; + let width; // Return the cached width if it exists. if (Blockly.utils.dom.cacheWidths_) { @@ -316,9 +316,9 @@ Blockly.utils.dom.getFastTextWidth = function(textElement, */ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, fontSize, fontWeight, fontFamily) { - var text = textElement.textContent; - var key = text + '\n' + textElement.className.baseVal; - var width; + const text = textElement.textContent; + const key = text + '\n' + textElement.className.baseVal; + let width; // Return the cached width if it exists. if (Blockly.utils.dom.cacheWidths_) { @@ -330,7 +330,7 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, if (!Blockly.utils.dom.canvasContext_) { // Inject the canvas element used for computing text widths. - var computeCanvas = document.createElement('canvas'); + const computeCanvas = document.createElement('canvas'); computeCanvas.className = 'blocklyComputeCanvas'; document.body.appendChild(computeCanvas); @@ -364,15 +364,15 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, Blockly.utils.dom.measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) { - var span = document.createElement('span'); + const span = document.createElement('span'); span.style.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; span.textContent = text; - var block = document.createElement('div'); + const block = document.createElement('div'); block.style.width = '1px'; block.style.height = 0; - var div = document.createElement('div'); + const div = document.createElement('div'); div.setAttribute('style', 'position: fixed; top: 0; left: 0; display: flex;'); div.appendChild(span); div.appendChild(block); From 563defa3badcf64f8f18d8f5c1a4d52017b5313b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 15:01:16 -0700 Subject: [PATCH 023/833] Migrate core/utils/dom.js to goog.module --- core/utils/dom.js | 113 ++++++++++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 049aa9f07..7219bd93c 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -16,7 +16,8 @@ * @name Blockly.utils.dom * @namespace */ -goog.provide('Blockly.utils.dom'); +goog.module('Blockly.utils.dom'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.Svg'); goog.require('Blockly.utils.userAgent'); @@ -26,26 +27,26 @@ goog.require('Blockly.utils.userAgent'); * Required name space for SVG elements. * @const */ -Blockly.utils.dom.SVG_NS = 'http://www.w3.org/2000/svg'; +const SVG_NS = 'http://www.w3.org/2000/svg'; /** * Required name space for HTML elements. * @const */ -Blockly.utils.dom.HTML_NS = 'http://www.w3.org/1999/xhtml'; +const HTML_NS = 'http://www.w3.org/1999/xhtml'; /** * Required name space for XLINK elements. * @const */ -Blockly.utils.dom.XLINK_NS = 'http://www.w3.org/1999/xlink'; +const XLINK_NS = 'http://www.w3.org/1999/xlink'; /** * Node type constants. * https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType * @enum {number} */ -Blockly.utils.dom.NodeType = { +const NodeType = { ELEMENT_NODE: 1, TEXT_NODE: 3, COMMENT_NODE: 8, @@ -57,21 +58,21 @@ Blockly.utils.dom.NodeType = { * @type {Object} * @private */ -Blockly.utils.dom.cacheWidths_ = null; +let cacheWidths = null; /** * Number of current references to cache. * @type {number} * @private */ -Blockly.utils.dom.cacheReference_ = 0; +let cacheReference = 0; /** * A HTML canvas context used for computing text width. * @type {CanvasRenderingContext2D} * @private */ -Blockly.utils.dom.canvasContext_ = null; +let canvasContext = null; /** * Helper method for creating SVG elements. @@ -83,9 +84,9 @@ Blockly.utils.dom.canvasContext_ = null; * Blockly.utils.Svg * @template T */ -Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { +const createSvgElement = function(name, attrs, opt_parent) { const e = /** @type {T} */ - (document.createElementNS(Blockly.utils.dom.SVG_NS, String(name))); + (document.createElementNS(SVG_NS, String(name))); for (const key in attrs) { e.setAttribute(key, attrs[key]); } @@ -108,7 +109,7 @@ Blockly.utils.dom.createSvgElement = function(name, attrs, opt_parent) { * @param {string} className Name of class to add. * @return {boolean} True if class was added, false if already present. */ -Blockly.utils.dom.addClass = function(element, className) { +const addClass = function(element, className) { let classes = element.getAttribute('class') || ''; if ((' ' + classes + ' ').indexOf(' ' + className + ' ') != -1) { return false; @@ -126,11 +127,11 @@ Blockly.utils.dom.addClass = function(element, className) { * @param {string} classNames A string of one or multiple class names for an * element. */ -Blockly.utils.dom.removeClasses = function(element, classNames) { +const removeClasses = function(element, classNames) { const classList = classNames.split(' '); for (let i = 0; i < classList.length; i++) { const cssName = classList[i]; - Blockly.utils.dom.removeClass(element, cssName); + removeClass(element, cssName); } }; @@ -141,7 +142,7 @@ Blockly.utils.dom.removeClasses = function(element, classNames) { * @param {string} className Name of class to remove. * @return {boolean} True if class was removed, false if never present. */ -Blockly.utils.dom.removeClass = function(element, className) { +const removeClass = function(element, className) { const classes = element.getAttribute('class'); if ((' ' + classes + ' ').indexOf(' ' + className + ' ') == -1) { return false; @@ -168,7 +169,7 @@ Blockly.utils.dom.removeClass = function(element, className) { * @param {string} className Name of class to check. * @return {boolean} True if class exists, false otherwise. */ -Blockly.utils.dom.hasClass = function(element, className) { +const hasClass = function(element, className) { const classes = element.getAttribute('class'); return (' ' + classes + ' ').indexOf(' ' + className + ' ') != -1; }; @@ -179,7 +180,7 @@ Blockly.utils.dom.hasClass = function(element, className) { * @return {?Node} The node removed if removed; else, null. */ // Copied from Closure goog.dom.removeNode -Blockly.utils.dom.removeNode = function(node) { +const removeNode = function(node) { return node && node.parentNode ? node.parentNode.removeChild(node) : null; }; @@ -189,7 +190,7 @@ Blockly.utils.dom.removeNode = function(node) { * @param {!Element} newNode New element to insert. * @param {!Element} refNode Existing element to precede new node. */ -Blockly.utils.dom.insertAfter = function(newNode, refNode) { +const insertAfter = function(newNode, refNode) { const siblingNode = refNode.nextSibling; const parentNode = refNode.parentNode; if (!parentNode) { @@ -208,9 +209,9 @@ Blockly.utils.dom.insertAfter = function(newNode, refNode) { * @param {!Node} descendant The node to test presence of. * @return {boolean} Whether the parent node contains the descendant node. */ -Blockly.utils.dom.containsNode = function(parent, descendant) { +const containsNode = function(parent, descendant) { return !!(parent.compareDocumentPosition(descendant) & - Blockly.utils.dom.NodeType.DOCUMENT_POSITION_CONTAINED_BY); + NodeType.DOCUMENT_POSITION_CONTAINED_BY); }; /** @@ -220,7 +221,7 @@ Blockly.utils.dom.containsNode = function(parent, descendant) { * @param {!Element} element Element to which the CSS transform will be applied. * @param {string} transform The value of the CSS `transform` property. */ -Blockly.utils.dom.setCssTransform = function(element, transform) { +const setCssTransform = function(element, transform) { element.style['transform'] = transform; element.style['-webkit-transform'] = transform; }; @@ -229,10 +230,10 @@ Blockly.utils.dom.setCssTransform = function(element, transform) { * Start caching text widths. Every call to this function MUST also call * stopTextWidthCache. Caches must not survive between execution threads. */ -Blockly.utils.dom.startTextWidthCache = function() { - Blockly.utils.dom.cacheReference_++; - if (!Blockly.utils.dom.cacheWidths_) { - Blockly.utils.dom.cacheWidths_ = Object.create(null); +const startTextWidthCache = function() { + cacheReference++; + if (!cacheWidths) { + cacheWidths = Object.create(null); } }; @@ -240,10 +241,10 @@ Blockly.utils.dom.startTextWidthCache = function() { * Stop caching field widths. Unless caching was already on when the * corresponding call to startTextWidthCache was made. */ -Blockly.utils.dom.stopTextWidthCache = function() { - Blockly.utils.dom.cacheReference_--; - if (!Blockly.utils.dom.cacheReference_) { - Blockly.utils.dom.cacheWidths_ = null; +const stopTextWidthCache = function() { + cacheReference--; + if (!cacheReference) { + cacheWidths = null; } }; @@ -252,13 +253,13 @@ Blockly.utils.dom.stopTextWidthCache = function() { * @param {!Element} textElement An SVG 'text' element. * @return {number} Width of element. */ -Blockly.utils.dom.getTextWidth = function(textElement) { +const getTextWidth = function(textElement) { const key = textElement.textContent + '\n' + textElement.className.baseVal; let width; // Return the cached width if it exists. - if (Blockly.utils.dom.cacheWidths_) { - width = Blockly.utils.dom.cacheWidths_[key]; + if (cacheWidths) { + width = cacheWidths[key]; if (width) { return width; } @@ -280,8 +281,8 @@ Blockly.utils.dom.getTextWidth = function(textElement) { } // Cache the computed width and return. - if (Blockly.utils.dom.cacheWidths_) { - Blockly.utils.dom.cacheWidths_[key] = width; + if (cacheWidths) { + cacheWidths[key] = width; } return width; }; @@ -296,9 +297,9 @@ Blockly.utils.dom.getTextWidth = function(textElement) { * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -Blockly.utils.dom.getFastTextWidth = function(textElement, +const getFastTextWidth = function(textElement, fontSize, fontWeight, fontFamily) { - return Blockly.utils.dom.getFastTextWidthWithSizeString(textElement, + return getFastTextWidthWithSizeString(textElement, fontSize + 'pt', fontWeight, fontFamily); }; @@ -314,21 +315,21 @@ Blockly.utils.dom.getFastTextWidth = function(textElement, * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, +const getFastTextWidthWithSizeString = function(textElement, fontSize, fontWeight, fontFamily) { const text = textElement.textContent; const key = text + '\n' + textElement.className.baseVal; let width; // Return the cached width if it exists. - if (Blockly.utils.dom.cacheWidths_) { - width = Blockly.utils.dom.cacheWidths_[key]; + if (cacheWidths) { + width = cacheWidths[key]; if (width) { return width; } } - if (!Blockly.utils.dom.canvasContext_) { + if (!canvasContext) { // Inject the canvas element used for computing text widths. const computeCanvas = document.createElement('canvas'); computeCanvas.className = 'blocklyComputeCanvas'; @@ -337,18 +338,18 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, // Initialize the HTML canvas context and set the font. // The context font must match blocklyText's fontsize and font-family // set in CSS. - Blockly.utils.dom.canvasContext_ = computeCanvas.getContext('2d'); + canvasContext = computeCanvas.getContext('2d'); } // Set the desired font size and family. - Blockly.utils.dom.canvasContext_.font = + canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; // Measure the text width using the helper canvas context. - width = Blockly.utils.dom.canvasContext_.measureText(text).width; + width = canvasContext.measureText(text).width; // Cache the computed width and return. - if (Blockly.utils.dom.cacheWidths_) { - Blockly.utils.dom.cacheWidths_[key] = width; + if (cacheWidths) { + cacheWidths[key] = width; } return width; }; @@ -361,7 +362,7 @@ Blockly.utils.dom.getFastTextWidthWithSizeString = function(textElement, * @param {string} fontFamily The font family to use. * @return {{height: number, baseline: number}} Font measurements. */ -Blockly.utils.dom.measureFontMetrics = function(text, fontSize, fontWeight, +const measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) { const span = document.createElement('span'); @@ -389,3 +390,25 @@ Blockly.utils.dom.measureFontMetrics = function(text, fontSize, fontWeight, } return result; }; + +exports = { + SVG_NS, + HTML_NS, + XLINK_NS, + NodeType, + createSvgElement, + addClass, + removeClasses, + removeClass, + hasClass, + removeNode, + insertAfter, + containsNode, + setCssTransform, + startTextWidthCache, + stopTextWidthCache, + getTextWidth, + getFastTextWidth, + getFastTextWidthWithSizeString, + measureFontMetrics, +}; diff --git a/tests/deps.js b/tests/deps.js index 4cb0f6fd3..dc28906b6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -173,7 +173,7 @@ goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); -goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); From 5fbf5fe40d97e4ad7b40b0c3c848e4c43478069d Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 10:39:37 -0700 Subject: [PATCH 024/833] Migrate core/utils/math.js to ES6 const/let --- core/utils/math.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/math.js b/core/utils/math.js index 516972579..e85b808e7 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -48,7 +48,7 @@ Blockly.utils.math.toDegrees = function(angleRadians) { */ Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { if (upperBound < lowerBound) { - var temp = upperBound; + const temp = upperBound; upperBound = lowerBound; lowerBound = temp; } From 06cbde1dba0f3dbf11ac9e8d63b5d40abdc9d2d4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 10:45:45 -0700 Subject: [PATCH 025/833] Migrate core/utils/math.js to goog.module --- core/utils/math.js | 11 +++++++---- tests/deps.js | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/utils/math.js b/core/utils/math.js index e85b808e7..2bc28eefe 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -16,7 +16,8 @@ * @name Blockly.utils.math * @namespace */ -goog.provide('Blockly.utils.math'); +goog.module('Blockly.utils.math'); +goog.module.declareLegacyNamespace(); /** @@ -25,7 +26,7 @@ goog.provide('Blockly.utils.math'); * @param {number} angleDegrees Angle in degrees. * @return {number} Angle in radians. */ -Blockly.utils.math.toRadians = function(angleDegrees) { +const toRadians = function(angleDegrees) { return angleDegrees * Math.PI / 180; }; @@ -35,7 +36,7 @@ Blockly.utils.math.toRadians = function(angleDegrees) { * @param {number} angleRadians Angle in radians. * @return {number} Angle in degrees. */ -Blockly.utils.math.toDegrees = function(angleRadians) { +const toDegrees = function(angleRadians) { return angleRadians * 180 / Math.PI; }; @@ -46,7 +47,7 @@ Blockly.utils.math.toDegrees = function(angleRadians) { * @param {number} upperBound The desired upper bound. * @return {number} The clamped number. */ -Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { +const clamp = function(lowerBound, number, upperBound) { if (upperBound < lowerBound) { const temp = upperBound; upperBound = lowerBound; @@ -54,3 +55,5 @@ Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { } return Math.max(lowerBound, Math.min(number, upperBound)); }; + +exports = {toRadians, toDegrees, clamp}; diff --git a/tests/deps.js b/tests/deps.js index f24feabaa..ecc86147d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,7 +4,6 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); -goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -178,7 +177,7 @@ goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.u goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], []); +goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); From 7cc85d9c4a172ce4efba910e8ad4ca848542ce8f Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:02:20 -0700 Subject: [PATCH 026/833] clang-format core/utils/math.js --- core/utils/math.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/utils/math.js b/core/utils/math.js index 2bc28eefe..dade91c21 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -56,4 +56,8 @@ const clamp = function(lowerBound, number, upperBound) { return Math.max(lowerBound, Math.min(number, upperBound)); }; -exports = {toRadians, toDegrees, clamp}; +exports = { + toRadians, + toDegrees, + clamp +}; From 1d8f6e903c2a74bc4ba9e2eeb0e563becd0ae33c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 15:38:35 -0700 Subject: [PATCH 027/833] Migrate core/utils/dom.js to named requires --- core/utils/dom.js | 11 +++++------ tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 7219bd93c..192aba58e 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -19,8 +19,8 @@ goog.module('Blockly.utils.dom'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Svg = goog.require('Blockly.utils.Svg'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** @@ -76,12 +76,11 @@ let canvasContext = null; /** * Helper method for creating SVG elements. - * @param {string|Blockly.utils.Svg} name Element's tag name. + * @param {string|Svg} name Element's tag name. * @param {!Object} attrs Dictionary of attribute names and values. * @param {Element=} opt_parent Optional parent on which to append the element. * @return {T} Newly created SVG element. The return type is {!SVGElement} if - * name is a string or a more specific type if it a member of - * Blockly.utils.Svg + * name is a string or a more specific type if it a member of Svg. * @template T */ const createSvgElement = function(name, attrs, opt_parent) { @@ -267,7 +266,7 @@ const getTextWidth = function(textElement) { // Attempt to compute fetch the width of the SVG text element. try { - if (Blockly.utils.userAgent.IE || Blockly.utils.userAgent.EDGE) { + if (userAgent.IE || userAgent.EDGE) { width = textElement.getBBox().width; } else { width = textElement.getComputedTextLength(); diff --git a/tests/deps.js b/tests/deps.js index dc28906b6..b8b42f583 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -173,7 +173,7 @@ goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], []); -goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], []); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], []); From 38324a1f637d20f87ca9090e0e1172bc2f4fbaf7 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 15:59:30 -0700 Subject: [PATCH 028/833] Updates eslint rules to work while converting to goog.module (#5063) --- .eslintrc.json | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9d74291da..28766db11 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,29 +2,6 @@ "rules": { "curly": ["error"], "eol-last": ["error"], - // Blockly/Google use 2-space indents. - // Blockly/Google uses +4 space indents for line continuations. - // Ignore default rules for ternary expressions. - "indent": [ - "error", 2, - { - "SwitchCase": 1, - "MemberExpression": 2, - "ObjectExpression": 1, - "FunctionDeclaration": { - "body": 1, - "parameters": 2 - }, - "FunctionExpression": { - "body": 1, - "parameters": 2 - }, - "CallExpression": { - "arguments": 2 - }, - "ignoredNodes": ["ConditionalExpression"] - } - ], "keyword-spacing": ["error"], "linebreak-style": ["error", "unix"], "max-len": [ @@ -39,7 +16,7 @@ ], "no-trailing-spaces": ["error", { "skipBlankLines": true }], "no-unused-vars": [ - "error", + "warn", { "args": "after-used", // Ignore vars starting with an underscore. @@ -48,7 +25,6 @@ "argsIgnorePattern": "^_" } ], - "no-use-before-define": ["error"], // Blockly uses for exporting symbols. no-self-assign added in eslint 5. "no-self-assign": ["off"], // Blockly uses single quotes except for JSON blobs, which must use double quotes. From 466a0db8099d34dba282c8c2d55549753ca6a610 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 13:56:18 -0700 Subject: [PATCH 029/833] Migrate core/utils/rect.js to goog.module --- core/utils/rect.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/utils/rect.js b/core/utils/rect.js index 128ec4eae..318cf1d0d 100644 --- a/core/utils/rect.js +++ b/core/utils/rect.js @@ -16,7 +16,8 @@ * @name Blockly.utils.Rect * @namespace */ -goog.provide('Blockly.utils.Rect'); +goog.module('Blockly.utils.Rect'); +goog.module.declareLegacyNamespace(); /** @@ -28,7 +29,7 @@ goog.provide('Blockly.utils.Rect'); * @struct * @constructor */ -Blockly.utils.Rect = function(top, bottom, left, right) { +const Rect = function(top, bottom, left, right) { /** @type {number} */ this.top = top; @@ -49,7 +50,7 @@ Blockly.utils.Rect = function(top, bottom, left, right) { * @param {number} y The y coordinate to test for containment. * @return {boolean} Whether this rectangle contains given coordinate. */ -Blockly.utils.Rect.prototype.contains = function(x, y) { +Rect.prototype.contains = function(x, y) { return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom; }; @@ -60,7 +61,9 @@ Blockly.utils.Rect.prototype.contains = function(x, y) { * intersection with. * @return {boolean} Whether this rectangle intersects the provided rectangle. */ -Blockly.utils.Rect.prototype.intersects = function(other) { +Rect.prototype.intersects = function(other) { return !(this.left > other.right || this.right < other.left || this.top > other.bottom || this.bottom < other.top); }; + +exports = Rect; diff --git a/tests/deps.js b/tests/deps.js index 4e222cf85..b98f68ecd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -180,7 +180,7 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); From de2cff80fdec4a262048bbb401b95d6e90163e80 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 16:11:11 -0700 Subject: [PATCH 030/833] clang-format core/utils/rect.js --- core/utils/rect.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/utils/rect.js b/core/utils/rect.js index 318cf1d0d..85ade5388 100644 --- a/core/utils/rect.js +++ b/core/utils/rect.js @@ -62,7 +62,8 @@ Rect.prototype.contains = function(x, y) { * @return {boolean} Whether this rectangle intersects the provided rectangle. */ Rect.prototype.intersects = function(other) { - return !(this.left > other.right || this.right < other.left || + return !( + this.left > other.right || this.right < other.left || this.top > other.bottom || this.bottom < other.top); }; From 5e31d8d7f3167c38c96e4df1705ebcf2d00cf015 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Wed, 14 Jul 2021 16:58:10 -0700 Subject: [PATCH 031/833] Migrate core/utils/aria.js to ES6 const/let --- core/utils/aria.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/aria.js b/core/utils/aria.js index 4cacc1ff7..cc731e299 100644 --- a/core/utils/aria.js +++ b/core/utils/aria.js @@ -166,6 +166,6 @@ Blockly.utils.aria.setState = function(element, stateName, value) { if (Array.isArray(value)) { value = value.join(' '); } - var attrStateName = Blockly.utils.aria.ARIA_PREFIX_ + stateName; + const attrStateName = Blockly.utils.aria.ARIA_PREFIX_ + stateName; element.setAttribute(attrStateName, value); }; From 0ceee1b775edbc73a70e6af020531857edc4ee09 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Wed, 14 Jul 2021 16:59:32 -0700 Subject: [PATCH 032/833] Update incorrect JsDoc comment. --- core/utils/aria.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/aria.js b/core/utils/aria.js index cc731e299..b75b7e3cd 100644 --- a/core/utils/aria.js +++ b/core/utils/aria.js @@ -5,7 +5,7 @@ */ /** - * @fileoverview Constant declarations for common key codes. + * @fileoverview ARIA-related constants and utilities. * These methods are not specific to Blockly, and could be factored out into * a JavaScript framework such as Closure. * @author samelh@google.com (Sam El-Husseini) From 9afd937568cb7302cbc50b7f1d63bed33a7575fa Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Wed, 14 Jul 2021 17:33:01 -0700 Subject: [PATCH 033/833] Migrate core/utils/aria.js to goog.module --- core/utils/aria.js | 38 ++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/utils/aria.js b/core/utils/aria.js index b75b7e3cd..464ba77b0 100644 --- a/core/utils/aria.js +++ b/core/utils/aria.js @@ -16,27 +16,22 @@ * @name Blockly.utils.aria * @namespace */ -goog.provide('Blockly.utils.aria'); +goog.module('Blockly.utils.aria'); +goog.module.declareLegacyNamespace(); -/** - * ARIA states/properties prefix. - * @private - */ -Blockly.utils.aria.ARIA_PREFIX_ = 'aria-'; +/** ARIA states/properties prefix. */ +const ARIA_PREFIX = 'aria-'; -/** - * ARIA role attribute. - * @private - */ -Blockly.utils.aria.ROLE_ATTRIBUTE_ = 'role'; +/** ARIA role attribute. */ +const ROLE_ATTRIBUTE = 'role'; /** * ARIA role values. * Copied from Closure's goog.a11y.aria.Role * @enum {string} */ -Blockly.utils.aria.Role = { +const Role = { // ARIA role for an interactive control of tabular data. GRID: 'grid', @@ -80,7 +75,7 @@ Blockly.utils.aria.Role = { * Copied from Closure's goog.a11y.aria.State * @enum {string} */ -Blockly.utils.aria.State = { +const State = { // ARIA property for setting the currently active descendant of an element, // for example the selected item in a list box. Value: ID of an element. ACTIVEDESCENDANT: 'activedescendant', @@ -148,24 +143,31 @@ Blockly.utils.aria.State = { * @param {!Element} element DOM node to set role of. * @param {!Blockly.utils.aria.Role} roleName Role name. */ -Blockly.utils.aria.setRole = function(element, roleName) { - element.setAttribute(Blockly.utils.aria.ROLE_ATTRIBUTE_, roleName); +const setRole = function(element, roleName) { + element.setAttribute(ROLE_ATTRIBUTE, roleName); }; /** * Sets the state or property of an element. * Copied from Closure's goog.a11y.aria * @param {!Element} element DOM node where we set state. - * @param {!Blockly.utils.aria.State} stateName State attribute being set. + * @param {!State} stateName State attribute being set. * Automatically adds prefix 'aria-' to the state name if the attribute is * not an extra attribute. * @param {string|boolean|number|!Array} value Value * for the state attribute. */ -Blockly.utils.aria.setState = function(element, stateName, value) { +const setState = function(element, stateName, value) { if (Array.isArray(value)) { value = value.join(' '); } - const attrStateName = Blockly.utils.aria.ARIA_PREFIX_ + stateName; + const attrStateName = ARIA_PREFIX + stateName; element.setAttribute(attrStateName, value); }; + +exports = { + Role, + State, + setRole, + setState, +}; diff --git a/tests/deps.js b/tests/deps.js index ecc86147d..3f6eae7a5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -169,7 +169,7 @@ goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); +goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); From 426c741e90f9134e013f5b37742c8dde6d6b1d11 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 17:03:33 -0700 Subject: [PATCH 034/833] Migrate core/utils/colour.js to ES6 const/let --- core/utils/colour.js | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index b64b81eb5..12c9a9998 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -32,7 +32,7 @@ goog.provide('Blockly.utils.colour'); */ Blockly.utils.colour.parse = function(str) { str = String(str).toLowerCase().trim(); - var hex = Blockly.utils.colour.names[str]; + let hex = Blockly.utils.colour.names[str]; if (hex) { // e.g. 'red' return hex; @@ -47,12 +47,12 @@ Blockly.utils.colour.parse = function(str) { // e.g. '#0f8' return ['#', hex[1], hex[1], hex[2], hex[2], hex[3], hex[3]].join(''); } - var rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/); + const rgb = str.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/); if (rgb) { // e.g. 'rgb(0, 128, 255)' - var r = Number(rgb[1]); - var g = Number(rgb[2]); - var b = Number(rgb[3]); + const r = Number(rgb[1]); + const g = Number(rgb[2]); + const b = Number(rgb[3]); if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { return Blockly.utils.colour.rgbToHex(r, g, b); } @@ -68,7 +68,7 @@ Blockly.utils.colour.parse = function(str) { * @return {string} Hex representation of the colour. */ Blockly.utils.colour.rgbToHex = function(r, g, b) { - var rgb = (r << 16) | (g << 8) | b; + const rgb = (r << 16) | (g << 8) | b; if (r < 0x10) { return '#' + (0x1000000 | rgb).toString(16).substr(1); } @@ -82,15 +82,15 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) { * @return {!Array} RGB representation of the colour. */ Blockly.utils.colour.hexToRgb = function(colour) { - var hex = Blockly.utils.colour.parse(colour); + const hex = Blockly.utils.colour.parse(colour); if (!hex) { return [0, 0, 0]; } - var rgb = parseInt(hex.substr(1), 16); - var r = rgb >> 16; - var g = (rgb >> 8) & 255; - var b = rgb & 255; + const rgb = parseInt(hex.substr(1), 16); + const r = rgb >> 16; + const g = (rgb >> 8) & 255; + const b = rgb & 255; return [r, g, b]; }; @@ -103,19 +103,19 @@ Blockly.utils.colour.hexToRgb = function(colour) { * @return {string} Hex representation of the colour. */ Blockly.utils.colour.hsvToHex = function(h, s, v) { - var red = 0; - var green = 0; - var blue = 0; + let red = 0; + let green = 0; + let blue = 0; if (s == 0) { red = v; green = v; blue = v; } else { - var sextant = Math.floor(h / 60); - var remainder = (h / 60) - sextant; - var val1 = v * (1 - s); - var val2 = v * (1 - (s * remainder)); - var val3 = v * (1 - (s * (1 - remainder))); + const sextant = Math.floor(h / 60); + const remainder = (h / 60) - sextant; + const val1 = v * (1 - s); + const val2 = v * (1 - (s * remainder)); + const val3 = v * (1 - (s * (1 - remainder))); switch (sextant) { case 1: red = val2; @@ -164,19 +164,19 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * @return {?string} Combined colour represented in hex. */ Blockly.utils.colour.blend = function(colour1, colour2, factor) { - var hex1 = Blockly.utils.colour.parse(colour1); + const hex1 = Blockly.utils.colour.parse(colour1); if (!hex1) { return null; } - var hex2 = Blockly.utils.colour.parse(colour2); + const hex2 = Blockly.utils.colour.parse(colour2); if (!hex2) { return null; } - var rgb1 = Blockly.utils.colour.hexToRgb(hex1); - var rgb2 = Blockly.utils.colour.hexToRgb(hex2); - var r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); - var g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); - var b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); + const rgb1 = Blockly.utils.colour.hexToRgb(hex1); + const rgb2 = Blockly.utils.colour.hexToRgb(hex2); + const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); + const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); + const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); return Blockly.utils.colour.rgbToHex(r, g, b); }; From 8abfa3d888f81136d6cc337a154aea7e0a7b0477 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:53:16 -0700 Subject: [PATCH 035/833] Migrate core/utils/colour.js to goog.module --- core/utils/colour.js | 35 +++++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index 12c9a9998..dffd193f3 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -16,7 +16,8 @@ * @name Blockly.utils.colour * @namespace */ -goog.provide('Blockly.utils.colour'); +goog.module('Blockly.utils.colour'); +goog.module.declareLegacyNamespace(); /** @@ -30,9 +31,9 @@ goog.provide('Blockly.utils.colour'); * @return {?string} A string containing a hex representation of the colour, * or null if can't be parsed. */ -Blockly.utils.colour.parse = function(str) { +const parse = function(str) { str = String(str).toLowerCase().trim(); - let hex = Blockly.utils.colour.names[str]; + let hex = names[str]; if (hex) { // e.g. 'red' return hex; @@ -54,7 +55,7 @@ Blockly.utils.colour.parse = function(str) { const g = Number(rgb[2]); const b = Number(rgb[3]); if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) { - return Blockly.utils.colour.rgbToHex(r, g, b); + return rgbToHex(r, g, b); } } return null; @@ -67,7 +68,7 @@ Blockly.utils.colour.parse = function(str) { * @param {number} b Amount of blue, int between 0 and 255. * @return {string} Hex representation of the colour. */ -Blockly.utils.colour.rgbToHex = function(r, g, b) { +const rgbToHex = function(r, g, b) { const rgb = (r << 16) | (g << 8) | b; if (r < 0x10) { return '#' + (0x1000000 | rgb).toString(16).substr(1); @@ -81,8 +82,8 @@ Blockly.utils.colour.rgbToHex = function(r, g, b) { * colour format ('#ff0000', 'red', '0xff000', etc). * @return {!Array} RGB representation of the colour. */ -Blockly.utils.colour.hexToRgb = function(colour) { - const hex = Blockly.utils.colour.parse(colour); +const hexToRgb = function(colour) { + const hex = parse(colour); if (!hex) { return [0, 0, 0]; } @@ -102,7 +103,7 @@ Blockly.utils.colour.hexToRgb = function(colour) { * @param {number} v Brightness in [0, 255]. * @return {string} Hex representation of the colour. */ -Blockly.utils.colour.hsvToHex = function(h, s, v) { +const hsvToHex = function(h, s, v) { let red = 0; let green = 0; let blue = 0; @@ -150,7 +151,7 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { break; } } - return Blockly.utils.colour.rgbToHex( + return rgbToHex( Math.floor(red), Math.floor(green), Math.floor(blue)); }; @@ -163,21 +164,21 @@ Blockly.utils.colour.hsvToHex = function(h, s, v) { * Values should be in the range [0, 1]. * @return {?string} Combined colour represented in hex. */ -Blockly.utils.colour.blend = function(colour1, colour2, factor) { - const hex1 = Blockly.utils.colour.parse(colour1); +const blend = function(colour1, colour2, factor) { + const hex1 = parse(colour1); if (!hex1) { return null; } - const hex2 = Blockly.utils.colour.parse(colour2); + const hex2 = parse(colour2); if (!hex2) { return null; } - const rgb1 = Blockly.utils.colour.hexToRgb(hex1); - const rgb2 = Blockly.utils.colour.hexToRgb(hex2); + const rgb1 = hexToRgb(hex1); + const rgb2 = hexToRgb(hex2); const r = Math.round(rgb2[0] + factor * (rgb1[0] - rgb2[0])); const g = Math.round(rgb2[1] + factor * (rgb1[1] - rgb2[1])); const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); - return Blockly.utils.colour.rgbToHex(r, g, b); + return rgbToHex(r, g, b); }; /** @@ -188,7 +189,7 @@ Blockly.utils.colour.blend = function(colour1, colour2, factor) { * * @type {!Object} */ -Blockly.utils.colour.names = { +const names = { 'aqua': '#00ffff', 'black': '#000000', 'blue': '#0000ff', @@ -206,3 +207,5 @@ Blockly.utils.colour.names = { 'white': '#ffffff', 'yellow': '#ffff00' }; + +exports = {parse, rgbToHex, hexToRgb, hsvToHex, blend, names}; diff --git a/tests/deps.js b/tests/deps.js index b98f68ecd..e83f61c67 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -170,7 +170,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); From f63bf29b7689b0ed92cfa2fb70f1be9b79fda2b8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:53:21 -0700 Subject: [PATCH 036/833] clang-format core/utils/colour.js --- core/utils/colour.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/utils/colour.js b/core/utils/colour.js index dffd193f3..7b2c978f4 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -151,8 +151,7 @@ const hsvToHex = function(h, s, v) { break; } } - return rgbToHex( - Math.floor(red), Math.floor(green), Math.floor(blue)); + return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue)); }; /** @@ -208,4 +207,11 @@ const names = { 'yellow': '#ffff00' }; -exports = {parse, rgbToHex, hexToRgb, hsvToHex, blend, names}; +exports = { + parse, + rgbToHex, + hexToRgb, + hsvToHex, + blend, + names +}; From 07bd3b3c799fd99aa02ce3c08462bd312925c501 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 08:42:28 -0700 Subject: [PATCH 037/833] clang-format core/utils/dom.js --- core/utils/dom.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 192aba58e..0e0480c0f 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -209,8 +209,9 @@ const insertAfter = function(newNode, refNode) { * @return {boolean} Whether the parent node contains the descendant node. */ const containsNode = function(parent, descendant) { - return !!(parent.compareDocumentPosition(descendant) & - NodeType.DOCUMENT_POSITION_CONTAINED_BY); + return !!( + parent.compareDocumentPosition(descendant) & + NodeType.DOCUMENT_POSITION_CONTAINED_BY); }; /** @@ -296,10 +297,10 @@ const getTextWidth = function(textElement) { * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -const getFastTextWidth = function(textElement, - fontSize, fontWeight, fontFamily) { - return getFastTextWidthWithSizeString(textElement, - fontSize + 'pt', fontWeight, fontFamily); +const getFastTextWidth = function( + textElement, fontSize, fontWeight, fontFamily) { + return getFastTextWidthWithSizeString( + textElement, fontSize + 'pt', fontWeight, fontFamily); }; /** @@ -314,8 +315,8 @@ const getFastTextWidth = function(textElement, * @param {string} fontFamily The font family to use. * @return {number} Width of element. */ -const getFastTextWidthWithSizeString = function(textElement, - fontSize, fontWeight, fontFamily) { +const getFastTextWidthWithSizeString = function( + textElement, fontSize, fontWeight, fontFamily) { const text = textElement.textContent; const key = text + '\n' + textElement.className.baseVal; let width; @@ -340,8 +341,7 @@ const getFastTextWidthWithSizeString = function(textElement, canvasContext = computeCanvas.getContext('2d'); } // Set the desired font size and family. - canvasContext.font = - fontWeight + ' ' + fontSize + ' ' + fontFamily; + canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; // Measure the text width using the helper canvas context. width = canvasContext.measureText(text).width; @@ -361,9 +361,7 @@ const getFastTextWidthWithSizeString = function(textElement, * @param {string} fontFamily The font family to use. * @return {{height: number, baseline: number}} Font measurements. */ -const measureFontMetrics = function(text, fontSize, fontWeight, - fontFamily) { - +const measureFontMetrics = function(text, fontSize, fontWeight, fontFamily) { const span = document.createElement('span'); span.style.font = fontWeight + ' ' + fontSize + ' ' + fontFamily; span.textContent = text; From f0d905dde0371a98f84eb3515d97f609e96b86ff Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 14 Jul 2021 14:18:05 -0700 Subject: [PATCH 038/833] Migrate core/utils/toolbox.js to ES6 const/let --- core/utils/toolbox.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index e9a9d2b2a..cbca92843 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -206,7 +206,7 @@ Blockly.utils.toolbox.convertToolboxDefToJson = function(toolboxDef) { toolboxDef = Blockly.utils.toolbox.convertToToolboxJson_(toolboxDef); } - var toolboxJson = /** @type {Blockly.utils.toolbox.ToolboxInfo} */ (toolboxDef); + const toolboxJson = /** @type {Blockly.utils.toolbox.ToolboxInfo} */ (toolboxDef); Blockly.utils.toolbox.validateToolbox_(toolboxJson); return toolboxJson; }; @@ -219,8 +219,8 @@ Blockly.utils.toolbox.convertToolboxDefToJson = function(toolboxDef) { * @private */ Blockly.utils.toolbox.validateToolbox_ = function(toolboxJson) { - var toolboxKind = toolboxJson['kind']; - var toolboxContents = toolboxJson['contents']; + const toolboxKind = toolboxJson['kind']; + const toolboxContents = toolboxJson['contents']; if (toolboxKind) { if (toolboxKind != Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND && @@ -274,12 +274,12 @@ Blockly.utils.toolbox.hasCategories = function(toolboxJson) { return false; } - var toolboxKind = toolboxJson['kind']; + let toolboxKind = toolboxJson['kind']; if (toolboxKind) { return toolboxKind == Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND; } - var categories = toolboxJson['contents'].filter(function(item) { + const categories = toolboxJson['contents'].filter(function (item) { return item['kind'].toUpperCase() == 'CATEGORY'; }); return !!categories.length; @@ -297,7 +297,7 @@ Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { return false; } - var categories = categoryInfo['contents'].filter(function(item) { + const categories = categoryInfo['contents'].filter(function(item) { return item['kind'].toUpperCase() == 'CATEGORY'; }); return !!categories.length; @@ -311,9 +311,9 @@ Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { * @private */ Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { - var contents = Blockly.utils.toolbox.xmlToJsonArray_( + const contents = Blockly.utils.toolbox.xmlToJsonArray_( /** @type {!Node|!Array} */ (toolboxDef)); - var toolboxJson = {'contents': contents}; + const toolboxJson = {'contents': contents}; if (toolboxDef instanceof Node) { Blockly.utils.toolbox.addAttributes_(toolboxDef, toolboxJson); } @@ -330,19 +330,19 @@ Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { * @private */ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { - var arr = []; + const arr = []; // If it is a node it will have children. - var childNodes = toolboxDef.childNodes; + let childNodes = toolboxDef.childNodes; if (!childNodes) { // Otherwise the toolboxDef is an array or collection. childNodes = toolboxDef; } - for (var i = 0, child; (child = childNodes[i]); i++) { + for (let i = 0, child; (child = childNodes[i]); i++) { if (!child.tagName) { continue; } - var obj = {}; - var tagName = child.tagName.toUpperCase(); + const obj = {}; + const tagName = child.tagName.toUpperCase(); obj['kind'] = tagName; // Store the XML for a block. @@ -367,8 +367,8 @@ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { * @private */ Blockly.utils.toolbox.addAttributes_ = function(node, obj) { - for (var j = 0; j < node.attributes.length; j++) { - var attr = node.attributes[j]; + for (let j = 0; j < node.attributes.length; j++) { + const attr = node.attributes[j]; if (attr.nodeName.indexOf('css-') > -1) { obj['cssconfig'] = obj['cssconfig'] || {}; obj['cssconfig'][attr.nodeName.replace('css-', '')] = attr.value; From d3cc70eb37e367e9707b5757d58e4c4c2e3a4759 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 15 Jul 2021 12:56:01 -0700 Subject: [PATCH 039/833] Migrate core/utils/toolbox.js to goog.module --- core/utils/toolbox.js | 140 +++++++++++++++++++++--------------------- tests/deps.js | 9 +-- 2 files changed, 76 insertions(+), 73 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index cbca92843..51ffdc7eb 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -14,7 +14,8 @@ * @name Blockly.utils.toolbox * @namespace */ -goog.provide('Blockly.utils.toolbox'); +goog.module('Blockly.utils.toolbox'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); @@ -34,7 +35,7 @@ goog.requireType('Blockly.ToolboxSeparator'); * disabled: (string|boolean|undefined) * }} */ -Blockly.utils.toolbox.BlockInfo; +let BlockInfo; /** * The information needed to create a separator in the toolbox. @@ -45,7 +46,7 @@ Blockly.utils.toolbox.BlockInfo; * cssconfig:(!Blockly.ToolboxSeparator.CssConfig|undefined) * }} */ -Blockly.utils.toolbox.SeparatorInfo; +let SeparatorInfo; /** * The information needed to create a button in the toolbox. @@ -55,7 +56,7 @@ Blockly.utils.toolbox.SeparatorInfo; * callbackkey:string * }} */ -Blockly.utils.toolbox.ButtonInfo; +let ButtonInfo; /** * The information needed to create a label in the toolbox. @@ -65,21 +66,21 @@ Blockly.utils.toolbox.ButtonInfo; * id:(string|undefined) * }} */ -Blockly.utils.toolbox.LabelInfo; +let LabelInfo; /** * The information needed to create either a button or a label in the flyout. - * @typedef {Blockly.utils.toolbox.ButtonInfo| - * Blockly.utils.toolbox.LabelInfo} + * @typedef {ButtonInfo| + * LabelInfo} */ -Blockly.utils.toolbox.ButtonOrLabelInfo; +let ButtonOrLabelInfo; /** * The information needed to create a category in the toolbox. * @typedef {{ * kind:string, * name:string, - * contents:!Array, + * contents:!Array, * id:(string|undefined), * categorystyle:(string|undefined), * colour:(string|undefined), @@ -87,7 +88,7 @@ Blockly.utils.toolbox.ButtonOrLabelInfo; * hidden:(string|undefined) * }} */ -Blockly.utils.toolbox.StaticCategoryInfo; +let StaticCategoryInfo; /** * The information needed to create a custom category. @@ -101,65 +102,65 @@ Blockly.utils.toolbox.StaticCategoryInfo; * hidden:(string|undefined) * }} */ -Blockly.utils.toolbox.DynamicCategoryInfo; +let DynamicCategoryInfo; /** * The information needed to create either a dynamic or static category. - * @typedef {Blockly.utils.toolbox.StaticCategoryInfo| - * Blockly.utils.toolbox.DynamicCategoryInfo} + * @typedef {StaticCategoryInfo| + * DynamicCategoryInfo} */ -Blockly.utils.toolbox.CategoryInfo; +let CategoryInfo; /** * Any information that can be used to create an item in the toolbox. - * @typedef {Blockly.utils.toolbox.FlyoutItemInfo| - * Blockly.utils.toolbox.StaticCategoryInfo} + * @typedef {FlyoutItemInfo| + * StaticCategoryInfo} */ -Blockly.utils.toolbox.ToolboxItemInfo; +let ToolboxItemInfo; /** * All the different types that can be displayed in a flyout. - * @typedef {Blockly.utils.toolbox.BlockInfo| - * Blockly.utils.toolbox.SeparatorInfo| - * Blockly.utils.toolbox.ButtonInfo| - * Blockly.utils.toolbox.LabelInfo| - * Blockly.utils.toolbox.DynamicCategoryInfo} + * @typedef {BlockInfo| + * SeparatorInfo| + * ButtonInfo| + * LabelInfo| + * DynamicCategoryInfo} */ -Blockly.utils.toolbox.FlyoutItemInfo; +let FlyoutItemInfo; /** * The JSON definition of a toolbox. * @typedef {{ * kind:(string|undefined), - * contents:!Array + * contents:!Array * }} */ -Blockly.utils.toolbox.ToolboxInfo; +let ToolboxInfo; /** * An array holding flyout items. * @typedef { - * Array + * Array * } */ -Blockly.utils.toolbox.FlyoutItemInfoArray; +let FlyoutItemInfoArray; /** * All of the different types that can create a toolbox. * @typedef {Node| - * Blockly.utils.toolbox.ToolboxInfo| + * ToolboxInfo| * string} */ -Blockly.utils.toolbox.ToolboxDefinition; +let ToolboxDefinition; /** * All of the different types that can be used to show items in a flyout. - * @typedef {Blockly.utils.toolbox.FlyoutItemInfoArray| + * @typedef {FlyoutItemInfoArray| * NodeList| - * Blockly.utils.toolbox.ToolboxInfo| + * ToolboxInfo| * Array} */ -Blockly.utils.toolbox.FlyoutDefinition; +let FlyoutDefinition; /** * The name used to identify a toolbox that has category like items. @@ -168,20 +169,20 @@ Blockly.utils.toolbox.FlyoutDefinition; * 'category'. * @const {string} */ -Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND = 'categoryToolbox'; +const CATEGORY_TOOLBOX_KIND = 'categoryToolbox'; /** * The name used to identify a toolbox that has no categories and is displayed * as a simple flyout displaying blocks, buttons, or labels. * @const {string} */ -Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND = 'flyoutToolbox'; +const FLYOUT_TOOLBOX_KIND = 'flyoutToolbox'; /** * Position of the toolbox and/or flyout relative to the workspace. * @enum {number} */ -Blockly.utils.toolbox.Position = { +const Position = { TOP: 0, BOTTOM: 1, LEFT: 2, @@ -190,45 +191,45 @@ Blockly.utils.toolbox.Position = { /** * Converts the toolbox definition into toolbox JSON. - * @param {?Blockly.utils.toolbox.ToolboxDefinition} toolboxDef The definition + * @param {?ToolboxDefinition} toolboxDef The definition * of the toolbox in one of its many forms. - * @return {?Blockly.utils.toolbox.ToolboxInfo} Object holding information + * @return {?ToolboxInfo} Object holding information * for creating a toolbox. * @package */ -Blockly.utils.toolbox.convertToolboxDefToJson = function(toolboxDef) { +const convertToolboxDefToJson = function(toolboxDef) { if (!toolboxDef) { return null; } if (toolboxDef instanceof Element || typeof toolboxDef == 'string') { - toolboxDef = Blockly.utils.toolbox.parseToolboxTree(toolboxDef); - toolboxDef = Blockly.utils.toolbox.convertToToolboxJson_(toolboxDef); + toolboxDef = parseToolboxTree(toolboxDef); + toolboxDef = convertToToolboxJson(toolboxDef); } - const toolboxJson = /** @type {Blockly.utils.toolbox.ToolboxInfo} */ (toolboxDef); - Blockly.utils.toolbox.validateToolbox_(toolboxJson); + const toolboxJson = /** @type {ToolboxInfo} */ (toolboxDef); + validateToolbox(toolboxJson); return toolboxJson; }; /** * Validates the toolbox JSON fields have been set correctly. - * @param {!Blockly.utils.toolbox.ToolboxInfo} toolboxJson Object holding + * @param {!ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @throws {Error} if the toolbox is not the correct format. * @private */ -Blockly.utils.toolbox.validateToolbox_ = function(toolboxJson) { +const validateToolbox = function(toolboxJson) { const toolboxKind = toolboxJson['kind']; const toolboxContents = toolboxJson['contents']; if (toolboxKind) { - if (toolboxKind != Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND && - toolboxKind != Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND) { + if (toolboxKind != FLYOUT_TOOLBOX_KIND && + toolboxKind != CATEGORY_TOOLBOX_KIND) { throw Error('Invalid toolbox kind ' + toolboxKind + '.' + ' Please supply either ' + - Blockly.utils.toolbox.FLYOUT_TOOLBOX_KIND + ' or ' + - Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND); + FLYOUT_TOOLBOX_KIND + ' or ' + + CATEGORY_TOOLBOX_KIND); } } if (!toolboxContents) { @@ -238,12 +239,12 @@ Blockly.utils.toolbox.validateToolbox_ = function(toolboxJson) { /** * Converts the flyout definition into a list of flyout items. - * @param {?Blockly.utils.toolbox.FlyoutDefinition} flyoutDef The definition of + * @param {?FlyoutDefinition} flyoutDef The definition of * the flyout in one of its many forms. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray} A list of flyout items. + * @return {!FlyoutItemInfoArray} A list of flyout items. * @package */ -Blockly.utils.toolbox.convertFlyoutDefToJsonArray = function(flyoutDef) { +const convertFlyoutDefToJsonArray = function(flyoutDef) { if (!flyoutDef) { return []; } @@ -258,25 +259,24 @@ Blockly.utils.toolbox.convertFlyoutDefToJsonArray = function(flyoutDef) { return flyoutDef; } - return Blockly.utils.toolbox.xmlToJsonArray_( - /** @type {!Array|!NodeList} */ (flyoutDef)); + return xmlToJsonArray(/** @type {!Array|!NodeList} */ (flyoutDef)); }; /** * Whether or not the toolbox definition has categories. - * @param {?Blockly.utils.toolbox.ToolboxInfo} toolboxJson Object holding + * @param {?ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @return {boolean} True if the toolbox has categories. * @package */ -Blockly.utils.toolbox.hasCategories = function(toolboxJson) { +const hasCategories = function(toolboxJson) { if (!toolboxJson) { return false; } let toolboxKind = toolboxJson['kind']; if (toolboxKind) { - return toolboxKind == Blockly.utils.toolbox.CATEGORY_TOOLBOX_KIND; + return toolboxKind == CATEGORY_TOOLBOX_KIND; } const categories = toolboxJson['contents'].filter(function (item) { @@ -287,12 +287,12 @@ Blockly.utils.toolbox.hasCategories = function(toolboxJson) { /** * Whether or not the category is collapsible. - * @param {!Blockly.utils.toolbox.CategoryInfo} categoryInfo Object holing + * @param {!CategoryInfo} categoryInfo Object holing * information for creating a category. * @return {boolean} True if the category has subcategories. * @package */ -Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { +const isCategoryCollapsible = function(categoryInfo) { if (!categoryInfo || !categoryInfo['contents']) { return false; } @@ -306,16 +306,16 @@ Blockly.utils.toolbox.isCategoryCollapsible = function(categoryInfo) { /** * Parses the provided toolbox definition into a consistent format. * @param {Node} toolboxDef The definition of the toolbox in one of its many forms. - * @return {!Blockly.utils.toolbox.ToolboxInfo} Object holding information + * @return {!ToolboxInfo} Object holding information * for creating a toolbox. * @private */ -Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { - const contents = Blockly.utils.toolbox.xmlToJsonArray_( +const convertToToolboxJson = function(toolboxDef) { + const contents = xmlToJsonArray( /** @type {!Node|!Array} */ (toolboxDef)); const toolboxJson = {'contents': contents}; if (toolboxDef instanceof Node) { - Blockly.utils.toolbox.addAttributes_(toolboxDef, toolboxJson); + addAttributes(toolboxDef, toolboxJson); } return toolboxJson; }; @@ -324,12 +324,12 @@ Blockly.utils.toolbox.convertToToolboxJson_ = function(toolboxDef) { * Converts the xml for a toolbox to JSON. * @param {!Node|!Array|!NodeList} toolboxDef The * definition of the toolbox in one of its many forms. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray| - * !Array} A list of objects in + * @return {!FlyoutItemInfoArray| + * !Array} A list of objects in * the toolbox. * @private */ -Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { +const xmlToJsonArray = function(toolboxDef) { const arr = []; // If it is a node it will have children. let childNodes = toolboxDef.childNodes; @@ -350,11 +350,11 @@ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { obj['blockxml'] = child; } else if (child.childNodes && child.childNodes.length > 0) { // Get the contents of a category - obj['contents'] = Blockly.utils.toolbox.xmlToJsonArray_(child); + obj['contents'] = xmlToJsonArray(child); } // Add XML attributes to object - Blockly.utils.toolbox.addAttributes_(child, obj); + addAttributes(child, obj); arr.push(obj); } return arr; @@ -366,7 +366,7 @@ Blockly.utils.toolbox.xmlToJsonArray_ = function(toolboxDef) { * @param {!Object} obj The object to copy the attributes to. * @private */ -Blockly.utils.toolbox.addAttributes_ = function(node, obj) { +const addAttributes = function(node, obj) { for (let j = 0; j < node.attributes.length; j++) { const attr = node.attributes[j]; if (attr.nodeName.indexOf('css-') > -1) { @@ -384,7 +384,7 @@ Blockly.utils.toolbox.addAttributes_ = function(node, obj) { * of same. * @return {?Node} DOM tree of blocks, or null. */ -Blockly.utils.toolbox.parseToolboxTree = function(toolboxDef) { +const parseToolboxTree = function(toolboxDef) { if (toolboxDef) { if (typeof toolboxDef != 'string') { if (Blockly.utils.userAgent.IE && toolboxDef.outerHTML) { @@ -408,3 +408,5 @@ Blockly.utils.toolbox.parseToolboxTree = function(toolboxDef) { } return toolboxDef; }; + +exports = {BlockInfo, SeparatorInfo, ButtonInfo, LabelInfo, ButtonOrLabelInfo, StaticCategoryInfo, DynamicCategoryInfo, CategoryInfo, ToolboxItemInfo, FlyoutItemInfo, ToolboxInfo, FlyoutItemInfoArray, ToolboxDefinition, FlyoutDefinition, Position, convertToolboxDefToJson, convertFlyoutDefToJsonArray, hasCategories, isCategoryCollapsible, parseToolboxTree} diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..0654ec508 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,6 +4,7 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -170,7 +171,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); @@ -180,13 +181,13 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From 2ab3bfd4cbd51ef1357b6271efb3debcea313c67 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 15 Jul 2021 11:29:50 -0700 Subject: [PATCH 040/833] Migrate core/utils/toolbox.js named requires --- core/utils/toolbox.js | 19 +++++++++---------- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index 51ffdc7eb..40e9fe78b 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -17,12 +17,11 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -goog.require('Blockly.Xml'); +const {IE} = goog.require('Blockly.utils.userAgent'); +const {textToDom} = goog.require('Blockly.Xml'); -goog.requireType('Blockly.ToolboxCategory'); -goog.requireType('Blockly.ToolboxSeparator'); +const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); +const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparator'); /** @@ -43,7 +42,7 @@ let BlockInfo; * kind:string, * id:(string|undefined), * gap:(number|undefined), - * cssconfig:(!Blockly.ToolboxSeparator.CssConfig|undefined) + * cssconfig:(!SeparatorCssConfig|undefined) * }} */ let SeparatorInfo; @@ -84,7 +83,7 @@ let ButtonOrLabelInfo; * id:(string|undefined), * categorystyle:(string|undefined), * colour:(string|undefined), - * cssconfig:(!Blockly.ToolboxCategory.CssConfig|undefined), + * cssconfig:(!CategoryCssConfig|undefined), * hidden:(string|undefined) * }} */ @@ -98,7 +97,7 @@ let StaticCategoryInfo; * id:(string|undefined), * categorystyle:(string|undefined), * colour:(string|undefined), - * cssconfig:(!Blockly.ToolboxCategory.CssConfig|undefined), + * cssconfig:(!CategoryCssConfig|undefined), * hidden:(string|undefined) * }} */ @@ -387,7 +386,7 @@ const addAttributes = function(node, obj) { const parseToolboxTree = function(toolboxDef) { if (toolboxDef) { if (typeof toolboxDef != 'string') { - if (Blockly.utils.userAgent.IE && toolboxDef.outerHTML) { + if (IE && toolboxDef.outerHTML) { // In this case the tree will not have been properly built by the // browser. The HTML will be contained in the element, but it will // not have the proper DOM structure since the browser doesn't support @@ -398,7 +397,7 @@ const parseToolboxTree = function(toolboxDef) { } } if (typeof toolboxDef == 'string') { - toolboxDef = Blockly.Xml.textToDom(toolboxDef); + toolboxDef = textToDom(toolboxDef); if (toolboxDef.nodeName.toLowerCase() != 'xml') { throw TypeError('Toolbox should be an document.'); } diff --git a/tests/deps.js b/tests/deps.js index 0654ec508..81507d9de 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -187,7 +187,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From fe9273ad5c60a53130a18e6e6806a788893e01b2 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 15 Jul 2021 13:00:45 -0700 Subject: [PATCH 041/833] clang-format core/utils/toolbox.js --- core/utils/toolbox.js | 38 ++++++++++++++++++++++++++++++-------- tests/deps.js | 6 +++--- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index 40e9fe78b..ec050d178 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -224,11 +224,11 @@ const validateToolbox = function(toolboxJson) { if (toolboxKind) { if (toolboxKind != FLYOUT_TOOLBOX_KIND && - toolboxKind != CATEGORY_TOOLBOX_KIND) { - throw Error('Invalid toolbox kind ' + toolboxKind + '.' + - ' Please supply either ' + - FLYOUT_TOOLBOX_KIND + ' or ' + - CATEGORY_TOOLBOX_KIND); + toolboxKind != CATEGORY_TOOLBOX_KIND) { + throw Error( + 'Invalid toolbox kind ' + toolboxKind + '.' + + ' Please supply either ' + FLYOUT_TOOLBOX_KIND + ' or ' + + CATEGORY_TOOLBOX_KIND); } } if (!toolboxContents) { @@ -278,7 +278,7 @@ const hasCategories = function(toolboxJson) { return toolboxKind == CATEGORY_TOOLBOX_KIND; } - const categories = toolboxJson['contents'].filter(function (item) { + const categories = toolboxJson['contents'].filter(function(item) { return item['kind'].toUpperCase() == 'CATEGORY'; }); return !!categories.length; @@ -304,7 +304,8 @@ const isCategoryCollapsible = function(categoryInfo) { /** * Parses the provided toolbox definition into a consistent format. - * @param {Node} toolboxDef The definition of the toolbox in one of its many forms. + * @param {Node} toolboxDef The definition of the toolbox in one of its many + * forms. * @return {!ToolboxInfo} Object holding information * for creating a toolbox. * @private @@ -408,4 +409,25 @@ const parseToolboxTree = function(toolboxDef) { return toolboxDef; }; -exports = {BlockInfo, SeparatorInfo, ButtonInfo, LabelInfo, ButtonOrLabelInfo, StaticCategoryInfo, DynamicCategoryInfo, CategoryInfo, ToolboxItemInfo, FlyoutItemInfo, ToolboxInfo, FlyoutItemInfoArray, ToolboxDefinition, FlyoutDefinition, Position, convertToolboxDefToJson, convertFlyoutDefToJsonArray, hasCategories, isCategoryCollapsible, parseToolboxTree} +exports = { + BlockInfo, + SeparatorInfo, + ButtonInfo, + LabelInfo, + ButtonOrLabelInfo, + StaticCategoryInfo, + DynamicCategoryInfo, + CategoryInfo, + ToolboxItemInfo, + FlyoutItemInfo, + ToolboxInfo, + FlyoutItemInfoArray, + ToolboxDefinition, + FlyoutDefinition, + Position, + convertToolboxDefToJson, + convertFlyoutDefToJsonArray, + hasCategories, + isCategoryCollapsible, + parseToolboxTree +} diff --git a/tests/deps.js b/tests/deps.js index 81507d9de..3d4531cf1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -171,7 +171,7 @@ goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Bl goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); -goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], []); +goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); @@ -181,12 +181,12 @@ goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], []); +goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size']); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); -goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], []); +goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); From b43b19c7a336b59b93986b29cfbb3406a76f8040 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 15 Jul 2021 14:38:16 -0700 Subject: [PATCH 042/833] Migrate core/renderers/common/drawer.js to ES6 const/let --- core/renderers/common/drawer.js | 120 ++++++++++++++++---------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index f91b97d7a..0d3a5bab9 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -90,7 +90,7 @@ Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { - for (var i = 0, iconInfo; (iconInfo = this.info_.hiddenIcons[i]); i++) { + for (let i = 0, iconInfo; (iconInfo = this.info_.hiddenIcons[i]); i++) { iconInfo.icon.iconGroup_.setAttribute('display', 'none'); } }; @@ -101,8 +101,8 @@ Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { */ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { this.drawTop_(); - for (var r = 1; r < this.info_.rows.length - 1; r++) { - var row = this.info_.rows[r]; + for (let r = 1; r < this.info_.rows.length - 1; r++) { + const row = this.info_.rows[r]; if (row.hasJaggedEdge) { this.drawJaggedEdge_(row); } else if (row.hasStatement) { @@ -124,13 +124,13 @@ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { - var topRow = this.info_.topRow; - var elements = topRow.elements; + const topRow = this.info_.topRow; + const elements = topRow.elements; this.positionPreviousConnection_(); this.outlinePath_ += Blockly.utils.svgPaths.moveBy(topRow.xPos, this.info_.startY); - for (var i = 0, elem; (elem = elements[i]); i++) { + for (let i = 0, elem; (elem = elements[i]); i++) { if (Blockly.blockRendering.Types.isLeftRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft; @@ -155,8 +155,7 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { - var remainder = - row.height - this.constants_.JAGGED_TEETH.height; + const remainder = row.height - this.constants_.JAGGED_TEETH.height; this.outlinePath_ += this.constants_.JAGGED_TEETH.path + Blockly.utils.svgPaths.lineOnAxis('v', remainder); }; @@ -169,10 +168,10 @@ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { - var input = row.getLastInput(); + const input = row.getLastInput(); this.positionExternalValueConnection_(row); - var pathDown = (typeof input.shape.pathDown == "function") ? + const pathDown = (typeof input.shape.pathDown == 'function') ? input.shape.pathDown(input.height) : input.shape.pathDown; @@ -190,18 +189,16 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { - var input = row.getLastInput(); + const input = row.getLastInput(); // Where to start drawing the notch, which is on the right side in LTR. - var x = input.xPos + input.notchOffset + input.shape.width; + const x = input.xPos + input.notchOffset + input.shape.width; - var innerTopLeftCorner = - input.shape.pathRight + - Blockly.utils.svgPaths.lineOnAxis('h', - -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + + const innerTopLeftCorner = input.shape.pathRight + + Blockly.utils.svgPaths.lineOnAxis( + 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + this.constants_.INSIDE_CORNERS.pathTop; - var innerHeight = - row.height - (2 * this.constants_.INSIDE_CORNERS.height); + const innerHeight = row.height - (2 * this.constants_.INSIDE_CORNERS.height); this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', x) + innerTopLeftCorner + @@ -231,13 +228,13 @@ Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { - var bottomRow = this.info_.bottomRow; - var elems = bottomRow.elements; + const bottomRow = this.info_.bottomRow; + const elems = bottomRow.elements; this.positionNextConnection_(); - var rightCornerYOffset = 0; - var outlinePath = ''; - for (var i = elems.length - 1, elem; (elem = elems[i]); i--) { + let rightCornerYOffset = 0; + let outlinePath = ''; + for (let i = elems.length - 1, elem; (elem = elems[i]); i--) { if (Blockly.blockRendering.Types.isNextConnection(elem)) { outlinePath += elem.shape.pathRight; } else if (Blockly.blockRendering.Types.isLeftSquareCorner(elem)) { @@ -263,13 +260,13 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { - var outputConnection = this.info_.outputConnection; + const outputConnection = this.info_.outputConnection; this.positionOutputConnection_(); if (outputConnection) { - var tabBottom = outputConnection.connectionOffsetY + - outputConnection.height; - var pathUp = (typeof outputConnection.shape.pathUp == "function") ? + const tabBottom = + outputConnection.connectionOffsetY + outputConnection.height; + const pathUp = (typeof outputConnection.shape.pathUp == 'function') ? outputConnection.shape.pathUp(outputConnection.height) : outputConnection.shape.pathUp; @@ -289,8 +286,8 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { - for (var i = 0, row; (row = this.info_.rows[i]); i++) { - for (var j = 0, elem; (elem = row.elements[j]); j++) { + for (let i = 0, row; (row = this.info_.rows[i]); i++) { + for (let j = 0, elem; (elem = row.elements[j]); j++) { if (Blockly.blockRendering.Types.isInlineInput(elem)) { this.drawInlineInput_( /** @type {!Blockly.blockRendering.InlineInput} */ (elem)); @@ -311,15 +308,16 @@ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { * @protected */ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { + let svgGroup; if (Blockly.blockRendering.Types.isField(fieldInfo)) { - var svgGroup = fieldInfo.field.getSvgRoot(); + svgGroup = fieldInfo.field.getSvgRoot(); } else if (Blockly.blockRendering.Types.isIcon(fieldInfo)) { - var svgGroup = fieldInfo.icon.iconGroup_; + svgGroup = fieldInfo.icon.iconGroup_; } - var yPos = fieldInfo.centerline - fieldInfo.height / 2; - var xPos = fieldInfo.xPos; - var scale = ''; + const yPos = fieldInfo.centerline - fieldInfo.height / 2; + let xPos = fieldInfo.xPos; + let scale = ''; if (this.info_.RTL) { xPos = -(xPos + fieldInfo.width); if (fieldInfo.flipRtl) { @@ -350,13 +348,13 @@ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { * @protected */ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { - var width = input.width; - var height = input.height; - var yPos = input.centerline - height / 2; + const width = input.width; + const height = input.height; + const yPos = input.centerline - height / 2; - var connectionTop = input.connectionOffsetY; - var connectionBottom = input.connectionHeight + connectionTop; - var connectionRight = input.xPos + input.connectionWidth; + const connectionTop = input.connectionOffsetY; + const connectionBottom = input.connectionHeight + connectionTop; + const connectionRight = input.xPos + input.connectionWidth; this.inlinePath_ += Blockly.utils.svgPaths.moveTo(connectionRight, yPos) + Blockly.utils.svgPaths.lineOnAxis('v', connectionTop) + @@ -377,12 +375,13 @@ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { * the input that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = function(input) { - var yPos = input.centerline - input.height / 2; +Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = + function(input) { + const yPos = input.centerline - input.height / 2; // Move the connection. if (input.connectionModel) { // xPos already contains info about startX - var connX = input.xPos + input.connectionWidth + input.connectionOffsetX; + let connX = input.xPos + input.connectionWidth + input.connectionOffsetX; if (this.info_.RTL) { connX *= -1; } @@ -398,10 +397,11 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = functio * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = function(row) { - var input = row.getLastInput(); +Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = + function(row) { + const input = row.getLastInput(); if (input.connectionModel) { - var connX = row.xPos + row.statementEdge + input.notchOffset; + let connX = row.xPos + row.statementEdge + input.notchOffset; if (this.info_.RTL) { connX *= -1; } @@ -416,10 +416,11 @@ Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = func * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = function(row) { - var input = row.getLastInput(); +Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = + function(row) { + const input = row.getLastInput(); if (input.connectionModel) { - var connX = row.xPos + row.width; + let connX = row.xPos + row.width; if (this.info_.RTL) { connX *= -1; } @@ -431,11 +432,12 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = funct * Position the previous connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = function() { - var topRow = this.info_.topRow; +Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = + function() { + const topRow = this.info_.topRow; if (topRow.connection) { - var x = topRow.xPos + topRow.notchOffset; - var connX = (this.info_.RTL ? -x : x); + const x = topRow.xPos + topRow.notchOffset; + const connX = (this.info_.RTL ? -x : x); topRow.connection.connectionModel.setOffsetInBlock(connX, 0); } }; @@ -445,12 +447,12 @@ Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = function() * @protected */ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { - var bottomRow = this.info_.bottomRow; + const bottomRow = this.info_.bottomRow; if (bottomRow.connection) { - var connInfo = bottomRow.connection; - var x = connInfo.xPos; // Already contains info about startX. - var connX = (this.info_.RTL ? -x : x); + const connInfo = bottomRow.connection; + const x = connInfo.xPos; // Already contains info about startX. + const connX = (this.info_.RTL ? -x : x); connInfo.connectionModel.setOffsetInBlock(connX, bottomRow.baseline); } }; @@ -461,8 +463,8 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { */ Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { if (this.info_.outputConnection) { - var x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; - var connX = this.info_.RTL ? -x : x; + const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; + const connX = this.info_.RTL ? -x : x; this.block_.outputConnection.setOffsetInBlock(connX, this.info_.outputConnection.connectionOffsetY); } From 66c959b4a3e6ca3ad8884303f9a9a4aed85af801 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 14:57:23 -0700 Subject: [PATCH 043/833] Migrate core/block_animations.js to ES6 const/let --- core/block_animations.js | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 82e2516b1..54b776d98 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -38,13 +38,13 @@ Blockly.blockAnimations.disconnectGroup_ = null; * @package */ Blockly.blockAnimations.disposeUiEffect = function(block) { - var workspace = block.workspace; - var svgGroup = block.getSvgRoot(); + const workspace = block.workspace; + const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); - var xy = workspace.getSvgXY(svgGroup); + const xy = workspace.getSvgXY(svgGroup); // Deeply clone the current block. - var clone = svgGroup.cloneNode(true); + const clone = svgGroup.cloneNode(true); clone.translateX_ = xy.x; clone.translateY_ = xy.y; clone.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); @@ -67,15 +67,15 @@ Blockly.blockAnimations.disposeUiEffect = function(block) { */ Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, workspaceScale) { - var ms = new Date - start; - var percent = ms / 150; + const ms = new Date - start; + const percent = ms / 150; if (percent > 1) { Blockly.utils.dom.removeNode(clone); } else { - var x = clone.translateX_ + + const x = clone.translateX_ + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; - var y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; - var scale = (1 - percent) * workspaceScale; + const y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; + const scale = (1 - percent) * workspaceScale; clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')'); setTimeout(Blockly.blockAnimations.disposeUiStep_, 10, clone, rtl, start, @@ -89,14 +89,14 @@ Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, * @package */ Blockly.blockAnimations.connectionUiEffect = function(block) { - var workspace = block.workspace; - var scale = workspace.scale; + const workspace = block.workspace; + const scale = workspace.scale; workspace.getAudioManager().play('click'); if (scale < 1) { return; // Too small to care about visual effects. } // Determine the absolute coordinates of the inferior block. - var xy = workspace.getSvgXY(block.getSvgRoot()); + const xy = workspace.getSvgXY(block.getSvgRoot()); // Offset the coordinates based on the two connection types, fix scale. if (block.outputConnection) { xy.x += (block.RTL ? 3 : -3) * scale; @@ -105,7 +105,7 @@ Blockly.blockAnimations.connectionUiEffect = function(block) { xy.x += (block.RTL ? -23 : 23) * scale; xy.y += 3 * scale; } - var ripple = Blockly.utils.dom.createSvgElement( + const ripple = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CIRCLE, { 'cx': xy.x, @@ -128,8 +128,8 @@ Blockly.blockAnimations.connectionUiEffect = function(block) { * @private */ Blockly.blockAnimations.connectionUiStep_ = function(ripple, start, scale) { - var ms = new Date - start; - var percent = ms / 150; + const ms = new Date - start; + const percent = ms / 150; if (percent > 1) { Blockly.utils.dom.removeNode(ripple); } else { @@ -151,10 +151,10 @@ Blockly.blockAnimations.disconnectUiEffect = function(block) { return; // Too small to care about visual effects. } // Horizontal distance for bottom of block to wiggle. - var DISPLACEMENT = 10; + const DISPLACEMENT = 10; // Scale magnitude of skew to height of block. - var height = block.getHeightWidth().height; - var magnitude = Math.atan(DISPLACEMENT / height) / Math.PI * 180; + const height = block.getHeightWidth().height; + let magnitude = Math.atan(DISPLACEMENT / height) / Math.PI * 180; if (!block.RTL) { magnitude *= -1; } @@ -170,16 +170,16 @@ Blockly.blockAnimations.disconnectUiEffect = function(block) { * @private */ Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { - var DURATION = 200; // Milliseconds. - var WIGGLES = 3; // Half oscillations. + const DURATION = 200; // Milliseconds. + const WIGGLES = 3; // Half oscillations. - var ms = new Date - start; - var percent = ms / DURATION; + const ms = new Date - start; + const percent = ms / DURATION; if (percent > 1) { group.skew_ = ''; } else { - var skew = Math.round( + const skew = Math.round( Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); group.skew_ = 'skewX(' + skew + ')'; Blockly.blockAnimations.disconnectGroup_ = group; @@ -197,7 +197,7 @@ Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { Blockly.blockAnimations.disconnectUiStop = function() { if (Blockly.blockAnimations.disconnectGroup_) { clearTimeout(Blockly.blockAnimations.disconnectPid_); - var group = Blockly.blockAnimations.disconnectGroup_; + const group = Blockly.blockAnimations.disconnectGroup_; group.skew_ = ''; group.setAttribute('transform', group.translate_); Blockly.blockAnimations.disconnectGroup_ = null; From ab0b03c4725c895e70cf6ecd35616562f5070985 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 15:29:35 -0700 Subject: [PATCH 044/833] Migrate core/block_animations.js to goog.module --- core/block_animations.js | 79 ++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 54b776d98..e6a7cf4f2 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockAnimations'); +goog.module('Blockly.blockAnimations'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -21,23 +22,20 @@ goog.requireType('Blockly.BlockSvg'); /** * PID of disconnect UI animation. There can only be one at a time. * @type {number} - * @private */ -Blockly.blockAnimations.disconnectPid_ = 0; +let disconnectPid = 0; /** * SVG group of wobbling block. There can only be one at a time. * @type {Element} - * @private */ -Blockly.blockAnimations.disconnectGroup_ = null; +let disconnectGroup = null; /** * Play some UI effects (sound, animation) when disposing of a block. * @param {!Blockly.BlockSvg} block The block being disposed of. - * @package */ -Blockly.blockAnimations.disposeUiEffect = function(block) { +function disposeUiEffect(block) { const workspace = block.workspace; const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); @@ -51,9 +49,11 @@ Blockly.blockAnimations.disposeUiEffect = function(block) { workspace.getParentSvg().appendChild(clone); clone.bBox_ = clone.getBBox(); // Start the animation. - Blockly.blockAnimations.disposeUiStep_(clone, workspace.RTL, new Date, + disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); -}; +} +/** @package */ +exports.disposeUiEffect = disposeUiEffect; /** * Animate a cloned block and eventually dispose of it. @@ -63,9 +63,8 @@ Blockly.blockAnimations.disposeUiEffect = function(block) { * @param {boolean} rtl True if RTL, false if LTR. * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. - * @private */ -Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, +function disposeUiStep(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; @@ -78,17 +77,16 @@ Blockly.blockAnimations.disposeUiStep_ = function(clone, rtl, start, const scale = (1 - percent) * workspaceScale; clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + ' scale(' + scale + ')'); - setTimeout(Blockly.blockAnimations.disposeUiStep_, 10, clone, rtl, start, + setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } -}; +} /** * Play some UI effects (sound, ripple) after a connection has been established. * @param {!Blockly.BlockSvg} block The block being connected. - * @package */ -Blockly.blockAnimations.connectionUiEffect = function(block) { +function connectionUiEffect(block) { const workspace = block.workspace; const scale = workspace.scale; workspace.getAudioManager().play('click'); @@ -117,17 +115,18 @@ Blockly.blockAnimations.connectionUiEffect = function(block) { }, workspace.getParentSvg()); // Start the animation. - Blockly.blockAnimations.connectionUiStep_(ripple, new Date, scale); -}; + connectionUiStep(ripple, new Date, scale); +} +/** @package */ +exports.connectionUiEffect = connectionUiEffect; /** * Expand a ripple around a connection. * @param {!SVGElement} ripple Element to animate. * @param {!Date} start Date of animation's start. * @param {number} scale Scale of workspace. - * @private */ -Blockly.blockAnimations.connectionUiStep_ = function(ripple, start, scale) { +function connectionUiStep(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -135,17 +134,16 @@ Blockly.blockAnimations.connectionUiStep_ = function(ripple, start, scale) { } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; - Blockly.blockAnimations.disconnectPid_ = setTimeout( - Blockly.blockAnimations.connectionUiStep_, 10, ripple, start, scale); + disconnectPid = setTimeout( + connectionUiStep, 10, ripple, start, scale); } -}; +} /** * Play some UI effects (sound, animation) when disconnecting a block. * @param {!Blockly.BlockSvg} block The block being disconnected. - * @package */ -Blockly.blockAnimations.disconnectUiEffect = function(block) { +function disconnectUiEffect(block) { block.workspace.getAudioManager().play('disconnect'); if (block.workspace.scale < 1) { return; // Too small to care about visual effects. @@ -159,17 +157,19 @@ Blockly.blockAnimations.disconnectUiEffect = function(block) { magnitude *= -1; } // Start the animation. - Blockly.blockAnimations.disconnectUiStep_( + disconnectUiStep( block.getSvgRoot(), magnitude, new Date); -}; +} +/** @package */ +exports.disconnectUiEffect = disconnectUiEffect; + /** * Animate a brief wiggle of a disconnected block. * @param {!SVGElement} group SVG element to animate. * @param {number} magnitude Maximum degrees skew (reversed for RTL). * @param {!Date} start Date of animation's start. - * @private */ -Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { +function disconnectUiStep(group, magnitude, start) { const DURATION = 200; // Milliseconds. const WIGGLES = 3; // Half oscillations. @@ -182,24 +182,25 @@ Blockly.blockAnimations.disconnectUiStep_ = function(group, magnitude, start) { const skew = Math.round( Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); group.skew_ = 'skewX(' + skew + ')'; - Blockly.blockAnimations.disconnectGroup_ = group; - Blockly.blockAnimations.disconnectPid_ = - setTimeout(Blockly.blockAnimations.disconnectUiStep_, 10, group, + disconnectGroup = group; + disconnectPid = + setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); -}; +} /** * Stop the disconnect UI animation immediately. - * @package */ -Blockly.blockAnimations.disconnectUiStop = function() { - if (Blockly.blockAnimations.disconnectGroup_) { - clearTimeout(Blockly.blockAnimations.disconnectPid_); - const group = Blockly.blockAnimations.disconnectGroup_; +function disconnectUiStop() { + if (disconnectGroup) { + clearTimeout(disconnectPid); + const group = disconnectGroup; group.skew_ = ''; group.setAttribute('transform', group.translate_); - Blockly.blockAnimations.disconnectGroup_ = null; + disconnectGroup = null; } -}; +} +/** @package */ +exports.disconnectUiStop = disconnectUiStop; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..f1a4cd48c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -8,7 +8,7 @@ goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Con goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); -goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); From 5f025f4d03c64fc8af4ea339fde9a7345a8168bf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 15:32:40 -0700 Subject: [PATCH 045/833] Migrate core/block_animations.js to named requires --- core/block_animations.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index e6a7cf4f2..c973bd097 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,10 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const Svg = goog.require('Blockly.utils.Svg'); -goog.requireType('Blockly.BlockSvg'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** @@ -33,7 +33,7 @@ let disconnectGroup = null; /** * Play some UI effects (sound, animation) when disposing of a block. - * @param {!Blockly.BlockSvg} block The block being disposed of. + * @param {!BlockSvg} block The block being disposed of. */ function disposeUiEffect(block) { const workspace = block.workspace; @@ -69,7 +69,7 @@ function disposeUiStep(clone, rtl, start, const ms = new Date - start; const percent = ms / 150; if (percent > 1) { - Blockly.utils.dom.removeNode(clone); + dom.removeNode(clone); } else { const x = clone.translateX_ + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; @@ -84,7 +84,7 @@ function disposeUiStep(clone, rtl, start, /** * Play some UI effects (sound, ripple) after a connection has been established. - * @param {!Blockly.BlockSvg} block The block being connected. + * @param {!BlockSvg} block The block being connected. */ function connectionUiEffect(block) { const workspace = block.workspace; @@ -103,8 +103,8 @@ function connectionUiEffect(block) { xy.x += (block.RTL ? -23 : 23) * scale; xy.y += 3 * scale; } - const ripple = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + const ripple = dom.createSvgElement( + Svg.CIRCLE, { 'cx': xy.x, 'cy': xy.y, @@ -130,7 +130,7 @@ function connectionUiStep(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { - Blockly.utils.dom.removeNode(ripple); + dom.removeNode(ripple); } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; @@ -141,7 +141,7 @@ function connectionUiStep(ripple, start, scale) { /** * Play some UI effects (sound, animation) when disconnecting a block. - * @param {!Blockly.BlockSvg} block The block being disconnected. + * @param {!BlockSvg} block The block being disconnected. */ function disconnectUiEffect(block) { block.workspace.getAudioManager().play('disconnect'); From f93ed6086978fef5619970d74889c6ed8b20f844 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 15 Jul 2021 15:33:59 -0700 Subject: [PATCH 046/833] clang-format core/block_animations.js --- core/block_animations.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index c973bd097..86b4b44b5 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,11 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); const dom = goog.require('Blockly.utils.dom'); const Svg = goog.require('Blockly.utils.Svg'); -const BlockSvg = goog.requireType('Blockly.BlockSvg'); - /** * PID of disconnect UI animation. There can only be one at a time. @@ -49,8 +48,7 @@ function disposeUiEffect(block) { workspace.getParentSvg().appendChild(clone); clone.bBox_ = clone.getBBox(); // Start the animation. - disposeUiStep(clone, workspace.RTL, new Date, - workspace.scale); + disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); } /** @package */ exports.disposeUiEffect = disposeUiEffect; @@ -64,8 +62,7 @@ exports.disposeUiEffect = disposeUiEffect; * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. */ -function disposeUiStep(clone, rtl, start, - workspaceScale) { +function disposeUiStep(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -75,10 +72,11 @@ function disposeUiStep(clone, rtl, start, (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; const y = clone.translateY_ + clone.bBox_.height * workspaceScale * percent; const scale = (1 - percent) * workspaceScale; - clone.setAttribute('transform', 'translate(' + x + ',' + y + ')' + - ' scale(' + scale + ')'); - setTimeout(disposeUiStep, 10, clone, rtl, start, - workspaceScale); + clone.setAttribute( + 'transform', + 'translate(' + x + ',' + y + ')' + + ' scale(' + scale + ')'); + setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } } @@ -104,8 +102,7 @@ function connectionUiEffect(block) { xy.y += 3 * scale; } const ripple = dom.createSvgElement( - Svg.CIRCLE, - { + Svg.CIRCLE, { 'cx': xy.x, 'cy': xy.y, 'r': 0, @@ -134,8 +131,7 @@ function connectionUiStep(ripple, start, scale) { } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; - disconnectPid = setTimeout( - connectionUiStep, 10, ripple, start, scale); + disconnectPid = setTimeout(connectionUiStep, 10, ripple, start, scale); } } @@ -157,8 +153,7 @@ function disconnectUiEffect(block) { magnitude *= -1; } // Start the animation. - disconnectUiStep( - block.getSvgRoot(), magnitude, new Date); + disconnectUiStep(block.getSvgRoot(), magnitude, new Date); } /** @package */ exports.disconnectUiEffect = disconnectUiEffect; @@ -171,7 +166,7 @@ exports.disconnectUiEffect = disconnectUiEffect; */ function disconnectUiStep(group, magnitude, start) { const DURATION = 200; // Milliseconds. - const WIGGLES = 3; // Half oscillations. + const WIGGLES = 3; // Half oscillations. const ms = new Date - start; const percent = ms / DURATION; @@ -183,9 +178,7 @@ function disconnectUiStep(group, magnitude, start) { Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude); group.skew_ = 'skewX(' + skew + ')'; disconnectGroup = group; - disconnectPid = - setTimeout(disconnectUiStep, 10, group, - magnitude, start); + disconnectPid = setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); } From 46e00f6ac99f8a82a65fd7d2e6beee124c7d6e3c Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:58:23 -0700 Subject: [PATCH 047/833] Migrate core/block_drag_surface.js to ES6 const/let --- core/block_drag_surface.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index b2a2cda0f..f1db819e8 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -134,8 +134,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. - var fixedX = x.toFixed(0); - var fixedY = y.toFixed(0); + const fixedX = x.toFixed(0); + const fixedY = y.toFixed(0); this.childSurfaceXY_.x = parseInt(fixedX, 10); this.childSurfaceXY_.y = parseInt(fixedY, 10); @@ -150,8 +150,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( * @private */ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { - var x = this.surfaceXY_.x; - var y = this.surfaceXY_.y; + let x = this.surfaceXY_.x; + let y = this.surfaceXY_.y; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. x = x.toFixed(0); @@ -168,8 +168,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { * @param {number} deltaY Vertical offset in pixel units. */ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { - var x = this.surfaceXY_.x + deltaX; - var y = this.surfaceXY_.y + deltaY; + const x = this.surfaceXY_.x + deltaX; + const y = this.surfaceXY_.y + deltaY; this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); this.translateSurfaceInternal_(); }; @@ -194,7 +194,8 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - var xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); + const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ + (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; From 4689c30634227e2d6da1294ea2475b5be2555d36 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:02:05 -0700 Subject: [PATCH 048/833] Migrate core/block_drag_surface.js to goog.module --- core/block_drag_surface.js | 46 +++++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index f1db819e8..f5bb42aea 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -15,7 +15,9 @@ 'use strict'; -goog.provide('Blockly.BlockDragSurfaceSvg'); +goog.module('Blockly.BlockDragSurfaceSvg'); +goog.module.declareLegacyNamespace(); + goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -28,7 +30,7 @@ goog.require('Blockly.utils.Svg'); * @param {!Element} container Containing element. * @constructor */ -Blockly.BlockDragSurfaceSvg = function(container) { +const BlockDragSurfaceSvg = function(container) { /** * @type {!Element} * @private @@ -38,11 +40,11 @@ Blockly.BlockDragSurfaceSvg = function(container) { }; /** - * The SVG drag surface. Set once by Blockly.BlockDragSurfaceSvg.createDom. + * The SVG drag surface. Set once by BlockDragSurfaceSvg.createDom. * @type {?SVGElement} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null; +BlockDragSurfaceSvg.prototype.SVG_ = null; /** * This is where blocks live while they are being dragged if the drag surface @@ -50,14 +52,14 @@ Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null; * @type {?SVGElement} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.dragGroup_ = null; +BlockDragSurfaceSvg.prototype.dragGroup_ = null; /** * Containing HTML element; parent of the workspace and the drag surface. * @type {?Element} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.container_ = null; +BlockDragSurfaceSvg.prototype.container_ = null; /** * Cached value for the scale of the drag surface. @@ -65,7 +67,7 @@ Blockly.BlockDragSurfaceSvg.prototype.container_ = null; * @type {number} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1; +BlockDragSurfaceSvg.prototype.scale_ = 1; /** * Cached value for the translation of the drag surface. @@ -74,7 +76,7 @@ Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1; * @type {?Blockly.utils.Coordinate} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null; +BlockDragSurfaceSvg.prototype.surfaceXY_ = null; /** * Cached value for the translation of the child drag surface in pixel units. @@ -83,13 +85,13 @@ Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * @type {!Blockly.utils.Coordinate} * @private */ -Blockly.BlockDragSurfaceSvg.prototype.childSurfaceXY_ = +BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Blockly.utils.Coordinate(0, 0); /** * Create the drag surface and inject it into the container. */ -Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { +BlockDragSurfaceSvg.prototype.createDom = function() { if (this.SVG_) { return; // Already created. } @@ -112,7 +114,7 @@ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() { * @param {!SVGElement} blocks Block or group of blocks to place on the drag * surface. */ -Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { +BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { if (this.dragGroup_.childNodes.length) { throw Error('Already dragging a block.'); } @@ -129,7 +131,7 @@ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { * @param {number} y Y translation in pixel coordinates. * @param {number} scale Scale of the group. */ -Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( +BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( x, y, scale) { this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering @@ -149,7 +151,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( * Translate the drag surface's SVG based on its internal state. * @private */ -Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { +BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { let x = this.surfaceXY_.x; let y = this.surfaceXY_.y; // This is a work-around to prevent a the blocks from rendering @@ -167,7 +169,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { * @param {number} deltaX Horizontal offset in pixel units. * @param {number} deltaY Vertical offset in pixel units. */ -Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { +BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { const x = this.surfaceXY_.x + deltaX; const y = this.surfaceXY_.y + deltaY; this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); @@ -182,7 +184,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { * @param {number} x X translation for the entire surface. * @param {number} y Y translation for the entire surface. */ -Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { +BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { this.surfaceXY_ = new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); @@ -193,7 +195,7 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { * Use this when finishing a drag to return blocks to the correct position. * @return {!Blockly.utils.Coordinate} Current translation of the surface. */ -Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { +BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); @@ -204,7 +206,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { * BlockSvg.getRelativeToSurfaceXY). * @return {?SVGElement} Drag surface group element. */ -Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { +BlockDragSurfaceSvg.prototype.getGroup = function() { return this.dragGroup_; }; @@ -212,7 +214,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() { * Returns the SVG drag surface. * @returns {?SVGElement} The SVG drag surface. */ -Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() { +BlockDragSurfaceSvg.prototype.getSvgRoot = function() { return this.SVG_; }; @@ -221,7 +223,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() { * for BlockSvg.getRelativeToSurfaceXY). * @return {?Element} Drag surface block DOM element, or null if no blocks exist. */ -Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { +BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { return /** @type {Element} */ (this.dragGroup_.firstChild); }; @@ -231,7 +233,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * moved. * @return {!Blockly.utils.Coordinate} The amount the workspace has been moved. */ -Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() { +BlockDragSurfaceSvg.prototype.getWsTranslation = function() { // Returning a copy so the coordinate can not be changed outside this class. return this.childSurfaceXY_.clone(); }; @@ -245,7 +247,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() { * to, or null if the blocks should be removed from this surface without * being moved to a different surface. */ -Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { +BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { if (opt_newSurface) { // appendChild removes the node from this.dragGroup_ opt_newSurface.appendChild(this.getCurrentBlock()); @@ -258,3 +260,5 @@ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) { } this.surfaceXY_ = null; }; + +exports = BlockDragSurfaceSvg; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..2edd38475 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -9,7 +9,7 @@ goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Bl goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); From 18996f3aac825b35a4b79c26c813d32c98017076 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:10:57 -0700 Subject: [PATCH 049/833] Migrate core/block_drag_surface.js named requires --- core/block_drag_surface.js | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index f5bb42aea..7b573fcfd 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -18,10 +18,10 @@ goog.module('Blockly.BlockDragSurfaceSvg'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const {G, SVG} = goog.require('Blockly.utils.Svg'); +const {getRelativeXY} = goog.require('Blockly.utils'); +const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom'); /** @@ -73,7 +73,7 @@ BlockDragSurfaceSvg.prototype.scale_ = 1; * Cached value for the translation of the drag surface. * This translation is in pixel units, because the scale is applied to the * drag group rather than the top-level SVG. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @private */ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; @@ -82,11 +82,11 @@ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * Cached value for the translation of the child drag surface in pixel units. * Since the child drag surface tracks the translation of the workspace this is * ultimately the translation of the workspace. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ BlockDragSurfaceSvg.prototype.childSurfaceXY_ = - new Blockly.utils.Coordinate(0, 0); + new Coordinate(0, 0); /** * Create the drag surface and inject it into the container. @@ -95,17 +95,17 @@ BlockDragSurfaceSvg.prototype.createDom = function() { if (this.SVG_) { return; // Already created. } - this.SVG_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.SVG, { - 'xmlns': Blockly.utils.dom.SVG_NS, - 'xmlns:html': Blockly.utils.dom.HTML_NS, - 'xmlns:xlink': Blockly.utils.dom.XLINK_NS, + this.SVG_ = createSvgElement( + SVG, { + 'xmlns': SVG_NS, + 'xmlns:html': HTML_NS, + 'xmlns:xlink': XLINK_NS, 'version': '1.1', 'class': 'blocklyBlockDragSurface' }, this.container_); this.dragGroup_ = - Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.G, {}, this.SVG_); + createSvgElement(G, {}, this.SVG_); }; /** @@ -121,7 +121,7 @@ BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { // appendChild removes the blocks from the previous parent this.dragGroup_.appendChild(blocks); this.SVG_.style.display = 'block'; - this.surfaceXY_ = new Blockly.utils.Coordinate(0, 0); + this.surfaceXY_ = new Coordinate(0, 0); }; /** @@ -160,7 +160,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { y = y.toFixed(0); this.SVG_.style.display = 'block'; - Blockly.utils.dom.setCssTransform( + setCssTransform( this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); }; @@ -172,7 +172,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { const x = this.surfaceXY_.x + deltaX; const y = this.surfaceXY_.y + deltaY; - this.surfaceXY_ = new Blockly.utils.Coordinate(x, y); + this.surfaceXY_ = new Coordinate(x, y); this.translateSurfaceInternal_(); }; @@ -186,19 +186,18 @@ BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { */ BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { this.surfaceXY_ = - new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_); + new Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); }; /** * Reports the surface translation in scaled workspace coordinates. * Use this when finishing a drag to return blocks to the correct position. - * @return {!Blockly.utils.Coordinate} Current translation of the surface. + * @return {!Coordinate} Current translation of the surface. */ BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() { - const xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ - (this.SVG_)); - return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_); + const xy = getRelativeXY(/** @type {!SVGElement} */ (this.SVG_)); + return new Coordinate(xy.x / this.scale_, xy.y / this.scale_); }; /** @@ -231,7 +230,7 @@ BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { * Gets the translation of the child block surface * This surface is in charge of keeping track of how much the workspace has * moved. - * @return {!Blockly.utils.Coordinate} The amount the workspace has been moved. + * @return {!Coordinate} The amount the workspace has been moved. */ BlockDragSurfaceSvg.prototype.getWsTranslation = function() { // Returning a copy so the coordinate can not be changed outside this class. From 5a834a9ec9874a501ff7fe8eb46778668a147c16 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:11:19 -0700 Subject: [PATCH 050/833] clang-format core/block_drag_surface.js --- core/block_drag_surface.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 7b573fcfd..69b7a5ca5 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -85,8 +85,7 @@ BlockDragSurfaceSvg.prototype.surfaceXY_ = null; * @type {!Coordinate} * @private */ -BlockDragSurfaceSvg.prototype.childSurfaceXY_ = - new Coordinate(0, 0); +BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Coordinate(0, 0); /** * Create the drag surface and inject it into the container. @@ -104,8 +103,7 @@ BlockDragSurfaceSvg.prototype.createDom = function() { 'class': 'blocklyBlockDragSurface' }, this.container_); - this.dragGroup_ = - createSvgElement(G, {}, this.SVG_); + this.dragGroup_ = createSvgElement(G, {}, this.SVG_); }; /** @@ -131,8 +129,7 @@ BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) { * @param {number} y Y translation in pixel coordinates. * @param {number} scale Scale of the group. */ -BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function( - x, y, scale) { +BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(x, y, scale) { this.scale_ = scale; // This is a work-around to prevent a the blocks from rendering // fuzzy while they are being dragged on the drag surface. @@ -160,8 +157,7 @@ BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() { y = y.toFixed(0); this.SVG_.style.display = 'block'; - setCssTransform( - this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); + setCssTransform(this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)'); }; /** @@ -185,8 +181,7 @@ BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) { * @param {number} y Y translation for the entire surface. */ BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) { - this.surfaceXY_ = - new Coordinate(x * this.scale_, y * this.scale_); + this.surfaceXY_ = new Coordinate(x * this.scale_, y * this.scale_); this.translateSurfaceInternal_(); }; @@ -220,7 +215,8 @@ BlockDragSurfaceSvg.prototype.getSvgRoot = function() { /** * Get the current blocks on the drag surface, if any (primarily * for BlockSvg.getRelativeToSurfaceXY). - * @return {?Element} Drag surface block DOM element, or null if no blocks exist. + * @return {?Element} Drag surface block DOM element, or null if no blocks + * exist. */ BlockDragSurfaceSvg.prototype.getCurrentBlock = function() { return /** @type {Element} */ (this.dragGroup_.firstChild); From 81b16abb92d4a89e0c40ecce8aa4cb7126e324a8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 16:54:21 -0700 Subject: [PATCH 051/833] Migrate core/utils/metrics.js to goog.module --- core/utils/metrics.js | 49 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/core/utils/metrics.js b/core/utils/metrics.js index 226ef0734..55cadfae9 100644 --- a/core/utils/metrics.js +++ b/core/utils/metrics.js @@ -14,139 +14,142 @@ * @name Blockly.utils.Metrics * @namespace */ -goog.provide('Blockly.utils.Metrics'); +goog.module('Blockly.utils.Metrics'); +goog.module.declareLegacyNamespace(); /** * @record */ -Blockly.utils.Metrics = function() {}; +const Metrics = function() {}; /** * Height of the visible portion of the workspace. * @type {number} */ -Blockly.utils.Metrics.prototype.viewHeight; +Metrics.prototype.viewHeight; /** * Width of the visible portion of the workspace. * @type {number} */ -Blockly.utils.Metrics.prototype.viewWidth; +Metrics.prototype.viewWidth; /** * Height of the content. * @type {number} */ -Blockly.utils.Metrics.prototype.contentHeight; +Metrics.prototype.contentHeight; /** * Width of the content. * @type {number} */ -Blockly.utils.Metrics.prototype.contentWidth; +Metrics.prototype.contentWidth; /** * Height of the scroll area. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollHeight; +Metrics.prototype.scrollHeight; /** * Width of the scroll area. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollWidth; +Metrics.prototype.scrollWidth; /** * Top-edge of the visible portion of the workspace, relative to the workspace * origin. * @type {number} */ -Blockly.utils.Metrics.prototype.viewTop; +Metrics.prototype.viewTop; /** * Left-edge of the visible portion of the workspace, relative to the workspace * origin. * @type {number} */ -Blockly.utils.Metrics.prototype.viewLeft; +Metrics.prototype.viewLeft; /** * Top-edge of the content, relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.contentTop; +Metrics.prototype.contentTop; /** * Left-edge of the content relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.contentLeft; +Metrics.prototype.contentLeft; /** * Top-edge of the scroll area, relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollTop; +Metrics.prototype.scrollTop; /** * Left-edge of the scroll area relative to the workspace origin. * @type {number} */ -Blockly.utils.Metrics.prototype.scrollLeft; +Metrics.prototype.scrollLeft; /** * Top-edge of the visible portion of the workspace, relative to the blocklyDiv. * @type {number} */ -Blockly.utils.Metrics.prototype.absoluteTop; +Metrics.prototype.absoluteTop; /** * Left-edge of the visible portion of the workspace, relative to the * blocklyDiv. * @type {number} */ -Blockly.utils.Metrics.prototype.absoluteLeft; +Metrics.prototype.absoluteLeft; /** * Height of the Blockly div (the view + the toolbox, simple of otherwise). * @type {number} */ -Blockly.utils.Metrics.prototype.svgHeight; +Metrics.prototype.svgHeight; /** * Width of the Blockly div (the view + the toolbox, simple or otherwise). * @type {number} */ -Blockly.utils.Metrics.prototype.svgWidth; +Metrics.prototype.svgWidth; /** * Width of the toolbox, if it exists. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxWidth; +Metrics.prototype.toolboxWidth; /** * Height of the toolbox, if it exists. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxHeight; +Metrics.prototype.toolboxHeight; /** * Top, bottom, left or right. Use TOOLBOX_AT constants to compare. * @type {number} */ -Blockly.utils.Metrics.prototype.toolboxPosition; +Metrics.prototype.toolboxPosition; /** * Width of the flyout if it is always open. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.flyoutWidth; +Metrics.prototype.flyoutWidth; /** * Height of the flyout if it is always open. Otherwise zero. * @type {number} */ -Blockly.utils.Metrics.prototype.flyoutHeight; +Metrics.prototype.flyoutHeight; + +exports = Metrics; diff --git a/tests/deps.js b/tests/deps.js index 2edd38475..d1a516942 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -178,7 +178,7 @@ goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []); +goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); From d8c45411300199db80218f4488f4a156a3f81f49 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:16:05 -0700 Subject: [PATCH 052/833] Migrate core/blocks.js to goog.module --- core/blocks.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/blocks.js b/core/blocks.js index 5f0d96b21..fadc62959 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -14,10 +14,13 @@ * A mapping of block type names to block prototype objects. * @name Blockly.Blocks */ -goog.provide('Blockly.Blocks'); +goog.module('Blockly.Blocks'); +goog.module.declareLegacyNamespace(); /** * A mapping of block type names to block prototype objects. * @type {!Object} */ -Blockly.Blocks = Object.create(null); +const Blocks = Object.create(null); + +exports = Blocks; diff --git a/tests/deps.js b/tests/deps.js index d1a516942..89bb3d512 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -13,7 +13,7 @@ goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfac goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []); +goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From 99f822665565d72b635bc59292f25d91d5bf9d37 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 18:15:52 -0700 Subject: [PATCH 053/833] Update Blockly.Blocks type annotation --- core/blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/blocks.js b/core/blocks.js index fadc62959..37c2105ce 100644 --- a/core/blocks.js +++ b/core/blocks.js @@ -19,7 +19,7 @@ goog.module.declareLegacyNamespace(); /** * A mapping of block type names to block prototype objects. - * @type {!Object} + * @type {!Object} */ const Blocks = Object.create(null); From 4c93a048f25d0313bcd65a4a3bd57a5606cac4a4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:09:43 -0700 Subject: [PATCH 054/833] Migrate core/bubble_dragger.js to ES6 const/let --- core/bubble_dragger.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index e014b8738..bec5dba15 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -123,14 +123,14 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() { * @package */ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc); - var oldDragTarget = this.dragTarget_; + const oldDragTarget = this.dragTarget_; this.dragTarget_ = this.workspace_.getDragTarget(e); - var oldWouldDeleteBubble = this.wouldDeleteBubble_; + const oldWouldDeleteBubble = this.wouldDeleteBubble_; this.wouldDeleteBubble_ = this.shouldDelete_(this.dragTarget_); if (oldWouldDeleteBubble != this.wouldDeleteBubble_) { // Prevent unnecessary add/remove class calls. @@ -155,8 +155,8 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { */ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { - var componentManager = this.workspace_.getComponentManager(); - var isDeleteArea = componentManager.hasCapability(dragTarget.id, + const componentManager = this.workspace_.getComponentManager(); + const isDeleteArea = componentManager.hasCapability(dragTarget.id, Blockly.ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { return (/** @type {!Blockly.IDeleteArea} */ (dragTarget)) @@ -187,13 +187,14 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( // Make sure internal state is fresh. this.dragBubble(e, currentDragDeltaXY); - var preventMove = this.dragTarget_ && + const preventMove = this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBubble_); + let newLoc; if (preventMove) { - var newLoc = this.startXY_; + newLoc = this.startXY_; } else { - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); } // Move the bubble to its final location. this.draggingBubble_.moveTo(newLoc.x, newLoc.y); @@ -227,7 +228,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( */ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { - var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( + const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); event.setOldCoordinate(this.startXY_); event.recordNew(); @@ -249,7 +250,7 @@ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { * @private */ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - var result = new Blockly.utils.Coordinate( + const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { @@ -257,7 +258,7 @@ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { // oddities in our rendering optimizations. The actual scale is the same as // the scale on the parent workspace. // Fix that for dragging. - var mainScale = this.workspace_.options.parentWorkspace.scale; + const mainScale = this.workspace_.options.parentWorkspace.scale; result.scale(1 / mainScale); } return result; From 42fd43b1c6e85e068e56e9fb806dade12139b808 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:14:47 -0700 Subject: [PATCH 055/833] Migrate core/bubble_dragger.js to goog.module --- core/bubble_dragger.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index bec5dba15..7b6f932d6 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.BubbleDragger'); +goog.module('Blockly.BubbleDragger'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); @@ -36,7 +37,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on. * @constructor */ -Blockly.BubbleDragger = function(bubble, workspace) { +const BubbleDragger = function(bubble, workspace) { /** * The item on the bubble canvas that is being dragged. * @type {!Blockly.IBubble} @@ -90,7 +91,7 @@ Blockly.BubbleDragger = function(bubble, workspace) { * @package * @suppress {checkTypes} */ -Blockly.BubbleDragger.prototype.dispose = function() { +BubbleDragger.prototype.dispose = function() { this.draggingBubble_ = null; this.workspace_ = null; this.dragSurface_ = null; @@ -100,7 +101,7 @@ Blockly.BubbleDragger.prototype.dispose = function() { * Start dragging a bubble. This includes moving it to the drag surface. * @package */ -Blockly.BubbleDragger.prototype.startBubbleDrag = function() { +BubbleDragger.prototype.startBubbleDrag = function() { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); } @@ -122,7 +123,7 @@ Blockly.BubbleDragger.prototype.startBubbleDrag = function() { * moved from the position at the start of the drag, in pixel units. * @package */ -Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { +BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc); @@ -153,7 +154,7 @@ Blockly.BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { * block. * @private */ -Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { +BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); const isDeleteArea = componentManager.hasCapability(dragTarget.id, @@ -171,7 +172,7 @@ Blockly.BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { * dragging bubble would be deleted if released immediately. * @private */ -Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { +BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { this.draggingBubble_.setDeleteStyle(this.wouldDeleteBubble_); }; @@ -182,7 +183,7 @@ Blockly.BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { * moved from the position at the start of the drag, in pixel units. * @package */ -Blockly.BubbleDragger.prototype.endBubbleDrag = function( +BubbleDragger.prototype.endBubbleDrag = function( e, currentDragDeltaXY) { // Make sure internal state is fresh. this.dragBubble(e, currentDragDeltaXY); @@ -226,7 +227,7 @@ Blockly.BubbleDragger.prototype.endBubbleDrag = function( * Fire a move event at the end of a bubble drag. * @private */ -Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { +BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); @@ -249,7 +250,7 @@ Blockly.BubbleDragger.prototype.fireMoveEvent_ = function() { * workspace scale. * @private */ -Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { +BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); @@ -269,9 +270,11 @@ Blockly.BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { * drag surface to preserve the apparent location of the bubble. * @private */ -Blockly.BubbleDragger.prototype.moveToDragSurface_ = function() { +BubbleDragger.prototype.moveToDragSurface_ = function() { this.draggingBubble_.moveTo(0, 0); this.dragSurface_.translateSurface(this.startXY_.x, this.startXY_.y); // Execute the move on the top-level SVG component. this.dragSurface_.setBlocksAndShow(this.draggingBubble_.getSvgRoot()); }; + +exports = BubbleDragger; diff --git a/tests/deps.js b/tests/deps.js index 89bb3d512..e038319d0 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -16,7 +16,7 @@ goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentMana goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); From 94685bd8be3450bb746e232c6a408b4b83978cf5 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 09:52:32 -0700 Subject: [PATCH 056/833] Migrate core/renderers/common/drawer.js to goog.module --- core/renderers/common/drawer.js | 51 ++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 0d3a5bab9..4eca204a3 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.Drawer'); +goog.module('Blockly.blockRendering.Drawer'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Row'); @@ -32,7 +33,7 @@ goog.requireType('Blockly.BlockSvg'); * @package * @constructor */ -Blockly.blockRendering.Drawer = function(block, info) { +const Drawer = function(block, info) { this.block_ = block; this.info_ = info; this.topLeft_ = block.getRelativeToSurfaceXY(); @@ -57,7 +58,7 @@ Blockly.blockRendering.Drawer = function(block, info) { * required. * @package */ -Blockly.blockRendering.Drawer.prototype.draw = function() { +Drawer.prototype.draw = function() { this.hideHiddenIcons_(); this.drawOutline_(); this.drawInternals_(); @@ -78,7 +79,7 @@ Blockly.blockRendering.Drawer.prototype.draw = function() { * render. Anything that needs to be kept around should be set in this function. * @protected */ -Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() { +Drawer.prototype.recordSizeOnBlock_ = function() { // This is used when the block is reporting its size to anyone else. // The dark path adds to the size of the block in both X and Y. this.block_.height = this.info_.height; @@ -89,7 +90,7 @@ Blockly.blockRendering.Drawer.prototype.recordSizeOnBlock_ = function() { * Hide icons that were marked as hidden. * @protected */ -Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { +Drawer.prototype.hideHiddenIcons_ = function() { for (let i = 0, iconInfo; (iconInfo = this.info_.hiddenIcons[i]); i++) { iconInfo.icon.iconGroup_.setAttribute('display', 'none'); } @@ -99,7 +100,7 @@ Blockly.blockRendering.Drawer.prototype.hideHiddenIcons_ = function() { * Create the outline of the block. This is a single continuous path. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { +Drawer.prototype.drawOutline_ = function() { this.drawTop_(); for (let r = 1; r < this.info_.rows.length - 1; r++) { const row = this.info_.rows[r]; @@ -123,7 +124,7 @@ Blockly.blockRendering.Drawer.prototype.drawOutline_ = function() { * details such as hats and rounded corners. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { +Drawer.prototype.drawTop_ = function() { const topRow = this.info_.topRow; const elements = topRow.elements; @@ -154,7 +155,7 @@ Blockly.blockRendering.Drawer.prototype.drawTop_ = function() { * @param {!Blockly.blockRendering.Row} row The row to draw the side of. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { +Drawer.prototype.drawJaggedEdge_ = function(row) { const remainder = row.height - this.constants_.JAGGED_TEETH.height; this.outlinePath_ += this.constants_.JAGGED_TEETH.path + Blockly.utils.svgPaths.lineOnAxis('v', remainder); @@ -167,7 +168,7 @@ Blockly.blockRendering.Drawer.prototype.drawJaggedEdge_ = function(row) { * belongs to. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { +Drawer.prototype.drawValueInput_ = function(row) { const input = row.getLastInput(); this.positionExternalValueConnection_(row); @@ -188,7 +189,7 @@ Blockly.blockRendering.Drawer.prototype.drawValueInput_ = function(row) { * belongs to. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { +Drawer.prototype.drawStatementInput_ = function(row) { const input = row.getLastInput(); // Where to start drawing the notch, which is on the right side in LTR. const x = input.xPos + input.notchOffset + input.shape.width; @@ -216,7 +217,7 @@ Blockly.blockRendering.Drawer.prototype.drawStatementInput_ = function(row) { * side of. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { +Drawer.prototype.drawRightSideRow_ = function(row) { this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height); }; @@ -227,7 +228,7 @@ Blockly.blockRendering.Drawer.prototype.drawRightSideRow_ = function(row) { * for the next connection. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { +Drawer.prototype.drawBottom_ = function() { const bottomRow = this.info_.bottomRow; const elems = bottomRow.elements; this.positionNextConnection_(); @@ -259,7 +260,7 @@ Blockly.blockRendering.Drawer.prototype.drawBottom_ = function() { * connection * @protected */ -Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { +Drawer.prototype.drawLeft_ = function() { const outputConnection = this.info_.outputConnection; this.positionOutputConnection_(); @@ -285,7 +286,7 @@ Blockly.blockRendering.Drawer.prototype.drawLeft_ = function() { * not depend on the outer path for placement. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { +Drawer.prototype.drawInternals_ = function() { for (let i = 0, row; (row = this.info_.rows[i]); i++) { for (let j = 0, elem; (elem = row.elements[j]); j++) { if (Blockly.blockRendering.Types.isInlineInput(elem)) { @@ -307,7 +308,7 @@ Blockly.blockRendering.Drawer.prototype.drawInternals_ = function() { * The rendering information for the field or icon. * @protected */ -Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { +Drawer.prototype.layoutField_ = function(fieldInfo) { let svgGroup; if (Blockly.blockRendering.Types.isField(fieldInfo)) { svgGroup = fieldInfo.field.getSvgRoot(); @@ -347,7 +348,7 @@ Blockly.blockRendering.Drawer.prototype.layoutField_ = function(fieldInfo) { * input to render. * @protected */ -Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { +Drawer.prototype.drawInlineInput_ = function(input) { const width = input.width; const height = input.height; const yPos = input.centerline - height / 2; @@ -375,8 +376,7 @@ Blockly.blockRendering.Drawer.prototype.drawInlineInput_ = function(input) { * the input that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = - function(input) { +Drawer.prototype.positionInlineInputConnection_ = function(input) { const yPos = input.centerline - input.height / 2; // Move the connection. if (input.connectionModel) { @@ -397,8 +397,7 @@ Blockly.blockRendering.Drawer.prototype.positionInlineInputConnection_ = * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = - function(row) { +Drawer.prototype.positionStatementInputConnection_ = function(row) { const input = row.getLastInput(); if (input.connectionModel) { let connX = row.xPos + row.statementEdge + input.notchOffset; @@ -416,8 +415,7 @@ Blockly.blockRendering.Drawer.prototype.positionStatementInputConnection_ = * @param {!Blockly.blockRendering.Row} row The row that the connection is on. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = - function(row) { +Drawer.prototype.positionExternalValueConnection_ = function(row) { const input = row.getLastInput(); if (input.connectionModel) { let connX = row.xPos + row.width; @@ -432,8 +430,7 @@ Blockly.blockRendering.Drawer.prototype.positionExternalValueConnection_ = * Position the previous connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = - function() { +Drawer.prototype.positionPreviousConnection_ = function() { const topRow = this.info_.topRow; if (topRow.connection) { const x = topRow.xPos + topRow.notchOffset; @@ -446,7 +443,7 @@ Blockly.blockRendering.Drawer.prototype.positionPreviousConnection_ = * Position the next connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { +Drawer.prototype.positionNextConnection_ = function() { const bottomRow = this.info_.bottomRow; if (bottomRow.connection) { @@ -461,7 +458,7 @@ Blockly.blockRendering.Drawer.prototype.positionNextConnection_ = function() { * Position the output connection on a block. * @protected */ -Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { +Drawer.prototype.positionOutputConnection_ = function() { if (this.info_.outputConnection) { const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; const connX = this.info_.RTL ? -x : x; @@ -469,3 +466,5 @@ Blockly.blockRendering.Drawer.prototype.positionOutputConnection_ = function() { this.info_.outputConnection.connectionOffsetY); } }; + +exports = Drawer; diff --git a/tests/deps.js b/tests/deps.js index e83f61c67..7cade6c4e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -116,7 +116,7 @@ goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnec goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); +goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From fef2ccfcc8f7129e6a53dd138638e0eab7a24ee2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:57:43 -0700 Subject: [PATCH 057/833] Migrate core/bubble_dragger.js to named requires --- core/bubble_dragger.js | 63 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 7b6f932d6..fb4c4e4ef 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -13,48 +13,49 @@ goog.module('Blockly.BubbleDragger'); goog.module.declareLegacyNamespace(); +const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +const IBubble = goog.requireType('Blockly.IBubble'); +const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const utils = goog.require('Blockly.utils'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); -goog.require('Blockly.ComponentManager'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentMove'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); - -goog.requireType('Blockly.BlockDragSurfaceSvg'); -goog.requireType('Blockly.IBubble'); -goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a bubble dragger. It moves things on the bubble canvas around the * workspace when they are being dragged by a mouse or touch. These can be * block comments, mutators, warnings, or workspace comments. - * @param {!Blockly.IBubble} bubble The item on the bubble canvas to drag. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on. + * @param {!IBubble} bubble The item on the bubble canvas to drag. + * @param {!WorkspaceSvg} workspace The workspace to drag on. * @constructor */ const BubbleDragger = function(bubble, workspace) { /** * The item on the bubble canvas that is being dragged. - * @type {!Blockly.IBubble} + * @type {!IBubble} * @private */ this.draggingBubble_ = bubble; /** * The workspace on which the bubble is being dragged. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; /** * Which drag target the mouse pointer is over, if any. - * @type {?Blockly.IDragTarget} + * @type {?IDragTarget} * @private */ this.dragTarget_ = null; @@ -69,7 +70,7 @@ const BubbleDragger = function(bubble, workspace) { /** * The location of the top left corner of the dragging bubble's body at the * beginning of the drag, in workspace coordinates. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ this.startXY_ = this.draggingBubble_.getRelativeToSurfaceXY(); @@ -77,11 +78,11 @@ const BubbleDragger = function(bubble, workspace) { /** * The drag surface to move bubbles to during a drag, or null if none should * be used. Block dragging and bubble dragging use the same surface. - * @type {Blockly.BlockDragSurfaceSvg} + * @type {BlockDragSurfaceSvg} * @private */ this.dragSurface_ = - Blockly.utils.is3dSupported() && !!workspace.getBlockDragSurface() ? + utils.is3dSupported() && !!workspace.getBlockDragSurface() ? workspace.getBlockDragSurface() : null; }; @@ -102,8 +103,8 @@ BubbleDragger.prototype.dispose = function() { * @package */ BubbleDragger.prototype.startBubbleDrag = function() { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } this.workspace_.setResizesEnabled(false); @@ -119,13 +120,13 @@ BubbleDragger.prototype.startBubbleDrag = function() { * Execute a step of bubble dragging, based on the given event. Update the * display accordingly. * @param {!Event} e The most recent move event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. * @package */ BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBubble_.moveDuringDrag(this.dragSurface_, newLoc); const oldDragTarget = this.dragTarget_; @@ -148,7 +149,7 @@ BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { /** * Whether ending the drag would delete the bubble. - * @param {?Blockly.IDragTarget} dragTarget The drag target that the bubblee is + * @param {?IDragTarget} dragTarget The drag target that the bubblee is * currently over. * @return {boolean} Whether dropping the bubble immediately would delete the * block. @@ -158,9 +159,9 @@ BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); const isDeleteArea = componentManager.hasCapability(dragTarget.id, - Blockly.ComponentManager.Capability.DELETE_AREA); + ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { - return (/** @type {!Blockly.IDeleteArea} */ (dragTarget)) + return (/** @type {!IDeleteArea} */ (dragTarget)) .wouldDelete(this.draggingBubble_, false); } } @@ -179,7 +180,7 @@ BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { /** * Finish a bubble drag and put the bubble back on the workspace. * @param {!Event} e The mouseup/touchend event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. * @package */ @@ -195,7 +196,7 @@ BubbleDragger.prototype.endBubbleDrag = function( newLoc = this.startXY_; } else { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + newLoc = Coordinate.sum(this.startXY_, delta); } // Move the bubble to its final location. this.draggingBubble_.moveTo(newLoc.x, newLoc.y); @@ -220,7 +221,7 @@ BubbleDragger.prototype.endBubbleDrag = function( } this.workspace_.setResizesEnabled(true); - Blockly.Events.setGroup(false); + Events.setGroup(false); }; /** @@ -229,11 +230,11 @@ BubbleDragger.prototype.endBubbleDrag = function( */ BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { - const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))( + const event = new (Events.get(Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); event.setOldCoordinate(this.startXY_); event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } // TODO (fenichel): move events for comments. return; @@ -244,14 +245,14 @@ BubbleDragger.prototype.fireMoveEvent_ = function() { * correction for mutator workspaces. * This function does not consider differing origins. It simply scales the * input's x and y values. - * @param {!Blockly.utils.Coordinate} pixelCoord A coordinate with x and y + * @param {!Coordinate} pixelCoord A coordinate with x and y * values in CSS pixel units. - * @return {!Blockly.utils.Coordinate} The input coordinate divided by the + * @return {!Coordinate} The input coordinate divided by the * workspace scale. * @private */ BubbleDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - const result = new Blockly.utils.Coordinate( + const result = new Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { From d9f024eb9e8fa599dcdb6f6988be7010ec03b6d2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 09:58:30 -0700 Subject: [PATCH 058/833] clang-format core/bubble_dragger.js --- core/bubble_dragger.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index fb4c4e4ef..d5cb8beae 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -158,8 +158,8 @@ BubbleDragger.prototype.dragBubble = function(e, currentDragDeltaXY) { BubbleDragger.prototype.shouldDelete_ = function(dragTarget) { if (dragTarget) { const componentManager = this.workspace_.getComponentManager(); - const isDeleteArea = componentManager.hasCapability(dragTarget.id, - ComponentManager.Capability.DELETE_AREA); + const isDeleteArea = componentManager.hasCapability( + dragTarget.id, ComponentManager.Capability.DELETE_AREA); if (isDeleteArea) { return (/** @type {!IDeleteArea} */ (dragTarget)) .wouldDelete(this.draggingBubble_, false); @@ -184,8 +184,7 @@ BubbleDragger.prototype.updateCursorDuringBubbleDrag_ = function() { * moved from the position at the start of the drag, in pixel units. * @package */ -BubbleDragger.prototype.endBubbleDrag = function( - e, currentDragDeltaXY) { +BubbleDragger.prototype.endBubbleDrag = function(e, currentDragDeltaXY) { // Make sure internal state is fresh. this.dragBubble(e, currentDragDeltaXY); From 6dcc24901c021c903d51191c2348da88a86e35d5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:37:05 -0700 Subject: [PATCH 059/833] Migrate core/extensions.js to ES6 const/let --- core/extensions.js | 53 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 0a2c146ad..4871d4622 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -84,7 +84,7 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) { */ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { - var errorPrefix = 'Error when registering mutator "' + name + '": '; + const errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. Blockly.Extensions.checkHasFunction_( @@ -92,7 +92,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, Blockly.Extensions.checkHasFunction_( errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); - var hasMutatorDialog = + const hasMutatorDialog = Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix); if (opt_helperFn && (typeof opt_helperFn != 'function')) { @@ -138,22 +138,23 @@ Blockly.Extensions.unregister = function(name) { * @throws {Error} if the extension is not found. */ Blockly.Extensions.apply = function(name, block, isMutator) { - var extensionFn = Blockly.Extensions.ALL_[name]; + const extensionFn = Blockly.Extensions.ALL_[name]; if (typeof extensionFn != 'function') { throw Error('Error: Extension "' + name + '" not found.'); } + let mutatorProperties; if (isMutator) { // Fail early if the block already has mutation properties. Blockly.Extensions.checkNoMutatorProperties_(name, block); } else { // Record the old properties so we can make sure they don't change after // applying the extension. - var mutatorProperties = Blockly.Extensions.getMutatorProperties_(block); + mutatorProperties = Blockly.Extensions.getMutatorProperties_(block); } extensionFn.apply(block); if (isMutator) { - var errorPrefix = 'Error after applying mutator "' + name + '": '; + const errorPrefix = 'Error after applying mutator "' + name + '": '; Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block); } else { if (!Blockly.Extensions.mutatorPropertiesMatch_( @@ -194,7 +195,7 @@ Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, * @private */ Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { - var properties = Blockly.Extensions.getMutatorProperties_(block); + const properties = Blockly.Extensions.getMutatorProperties_(block); if (properties.length) { throw Error('Error: tried to apply mutation "' + mutationName + '" to a block that already has mutator functions.' + @@ -215,8 +216,8 @@ Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { * @private */ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { - var hasCompose = object.compose !== undefined; - var hasDecompose = object.decompose !== undefined; + const hasCompose = object.compose !== undefined; + const hasDecompose = object.decompose !== undefined; if (hasCompose && hasDecompose) { if (typeof object.compose != 'function') { @@ -261,7 +262,7 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, * @private */ Blockly.Extensions.getMutatorProperties_ = function(block) { - var result = []; + const result = []; // List each function explicitly by reference to allow for renaming // during compilation. if (block.domToMutation !== undefined) { @@ -289,11 +290,11 @@ Blockly.Extensions.getMutatorProperties_ = function(block) { * @private */ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { - var newProperties = Blockly.Extensions.getMutatorProperties_(block); + const newProperties = Blockly.Extensions.getMutatorProperties_(block); if (newProperties.length != oldProperties.length) { return false; } - for (var i = 0; i < newProperties.length; i++) { + for (let i = 0; i < newProperties.length; i++) { if (oldProperties[i] != newProperties[i]) { return false; } @@ -323,7 +324,7 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. - var blockTypesChecked = []; + const blockTypesChecked = []; // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. @@ -331,7 +332,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, // document object, in which case skip the validation. if (typeof document == 'object') { // Relies on document.readyState Blockly.utils.runAfterPageLoad(function() { - for (var key in lookupTable) { + for (let key in lookupTable) { // Will print warnings if reference is missing. Blockly.utils.checkMessageReferences(lookupTable[key]); } @@ -342,20 +343,20 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, * The actual extension. * @this {Blockly.Block} */ - var extensionFn = function() { + const extensionFn = function () { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { Blockly.Extensions.checkDropdownOptionsInTable_( this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } - this.setTooltip(function() { - var value = String(this.getFieldValue(dropdownName)); - var tooltip = lookupTable[value]; + this.setTooltip(function () { + const value = String(this.getFieldValue(dropdownName)); + let tooltip = lookupTable[value]; if (tooltip == null) { if (blockTypesChecked.indexOf(this.type) == -1) { // Warn for missing values on generated tooltips. - var warning = 'No tooltip mapping for value ' + value + + let warning = 'No tooltip mapping for value ' + value + ' of field ' + dropdownName; if (this.type != null) { warning += (' of block type ' + this.type); @@ -382,11 +383,11 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, lookupTable) { // Validate all dropdown options have values. - var dropdown = block.getField(dropdownName); + const dropdown = block.getField(dropdownName); if (!dropdown.isOptionListDynamic()) { - var options = dropdown.getOptions(); - for (var i = 0; i < options.length; ++i) { - var optionKey = options[i][1]; // label, then value + const options = dropdown.getOptions(); + for (let i = 0; i < options.length; ++i) { + const optionKey = options[i][1]; // label, then value if (lookupTable[optionKey] == null) { console.warn('No tooltip mapping for value ' + optionKey + ' of field ' + dropdownName + ' of block type ' + block.type); @@ -421,9 +422,9 @@ Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, * The actual extension. * @this {Blockly.Block} */ - var extensionFn = function() { - this.setTooltip(function() { - var field = this.getField(fieldName); + const extensionFn = function () { + this.setTooltip(function () { + const field = this.getField(fieldName); return Blockly.utils.replaceMessageReferences(msgTemplate) .replace('%1', field ? field.getText() : ''); }.bind(this)); @@ -442,7 +443,7 @@ Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, Blockly.Extensions.extensionParentTooltip_ = function() { this.tooltipWhenNotConnected_ = this.tooltip; this.setTooltip(function() { - var parent = this.getParent(); + const parent = this.getParent(); return (parent && parent.getInputsInline() && parent.tooltip) || this.tooltipWhenNotConnected_; }.bind(this)); From fed47362cd7fe77bd1cff3e7a3ddaf1786492ceb Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:45:22 -0700 Subject: [PATCH 060/833] Migrate core/extensions.js to goog.module --- core/extensions.js | 81 ++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 4871d4622..8a287e33a 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -17,7 +17,8 @@ * @name Blockly.Extensions * @namespace */ -goog.provide('Blockly.Extensions'); +goog.module('Blockly.Extensions'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils'); @@ -28,7 +29,7 @@ goog.requireType('Blockly.Block'); * The set of all registered extensions, keyed by extension name/id. * @private */ -Blockly.Extensions.ALL_ = Object.create(null); +const ALL = Object.create(null); /** * Registers a new extension function. Extensions are functions that help @@ -40,17 +41,17 @@ Blockly.Extensions.ALL_ = Object.create(null); * @throws {Error} if the extension name is empty, the extension is already * registered, or extensionFn is not a function. */ -Blockly.Extensions.register = function(name, initFn) { +const register = function(name, initFn) { if ((typeof name != 'string') || (name.trim() == '')) { throw Error('Error: Invalid extension name "' + name + '"'); } - if (Blockly.Extensions.ALL_[name]) { + if (ALL[name]) { throw Error('Error: Extension "' + name + '" is already registered.'); } if (typeof initFn != 'function') { throw Error('Error: Extension "' + name + '" must be a function'); } - Blockly.Extensions.ALL_[name] = initFn; + ALL[name] = initFn; }; /** @@ -60,11 +61,11 @@ Blockly.Extensions.register = function(name, initFn) { * @throws {Error} if the extension name is empty or the extension is already * registered. */ -Blockly.Extensions.registerMixin = function(name, mixinObj) { +const registerMixin = function(name, mixinObj) { if (!mixinObj || typeof mixinObj != 'object') { throw Error('Error: Mixin "' + name + '" must be a object'); } - Blockly.Extensions.register(name, function() { + register(name, function() { this.mixin(mixinObj); }); }; @@ -82,25 +83,25 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) { * flyout of the mutator dialog. * @throws {Error} if the mutation is invalid or can't be applied to the block. */ -Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, +const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { const errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. - Blockly.Extensions.checkHasFunction_( + checkHasFunction( errorPrefix, mixinObj.domToMutation, 'domToMutation'); - Blockly.Extensions.checkHasFunction_( + checkHasFunction( errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); const hasMutatorDialog = - Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix); + checkMutatorDialog(mixinObj, errorPrefix); if (opt_helperFn && (typeof opt_helperFn != 'function')) { throw Error('Extension "' + name + '" is not a function'); } // Sanity checks passed. - Blockly.Extensions.register(name, function() { + register(name, function() { if (hasMutatorDialog) { if (!Blockly.Mutator) { throw Error(errorPrefix + 'Missing require for Blockly.Mutator'); @@ -120,9 +121,9 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, * Unregisters the extension registered with the given name. * @param {string} name The name of the extension to unregister. */ -Blockly.Extensions.unregister = function(name) { - if (Blockly.Extensions.ALL_[name]) { - delete Blockly.Extensions.ALL_[name]; +const unregister = function(name) { + if (ALL[name]) { + delete ALL[name]; } else { console.warn('No extension mapping for name "' + name + '" found to unregister'); @@ -137,27 +138,27 @@ Blockly.Extensions.unregister = function(name) { * @param {boolean} isMutator True if this extension defines a mutator. * @throws {Error} if the extension is not found. */ -Blockly.Extensions.apply = function(name, block, isMutator) { - const extensionFn = Blockly.Extensions.ALL_[name]; +const apply = function(name, block, isMutator) { + const extensionFn = ALL[name]; if (typeof extensionFn != 'function') { throw Error('Error: Extension "' + name + '" not found.'); } let mutatorProperties; if (isMutator) { // Fail early if the block already has mutation properties. - Blockly.Extensions.checkNoMutatorProperties_(name, block); + checkNoMutatorProperties(name, block); } else { // Record the old properties so we can make sure they don't change after // applying the extension. - mutatorProperties = Blockly.Extensions.getMutatorProperties_(block); + mutatorProperties = getMutatorProperties(block); } extensionFn.apply(block); if (isMutator) { const errorPrefix = 'Error after applying mutator "' + name + '": '; - Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block); + checkBlockHasMutatorProperties(errorPrefix, block); } else { - if (!Blockly.Extensions.mutatorPropertiesMatch_( + if (!mutatorPropertiesMatch( /** @type {!Array} */ (mutatorProperties), block)) { throw Error('Error when applying extension "' + name + '": ' + 'mutation properties changed when applying a non-mutator extension.'); @@ -173,7 +174,7 @@ Blockly.Extensions.apply = function(name, block, isMutator) { * @throws {Error} if the property does not exist or is not a function. * @private */ -Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, +const checkHasFunction = function(errorPrefix, func, propertyName) { if (!func) { throw Error(errorPrefix + @@ -194,8 +195,8 @@ Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, * @throws {Error} if any of the properties already exist on the block. * @private */ -Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { - const properties = Blockly.Extensions.getMutatorProperties_(block); +const checkNoMutatorProperties = function(mutationName, block) { + const properties = getMutatorProperties(block); if (properties.length) { throw Error('Error: tried to apply mutation "' + mutationName + '" to a block that already has mutator functions.' + @@ -215,7 +216,7 @@ Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) { * @throws {Error} if the object has only one of the functions. * @private */ -Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { +const checkMutatorDialog = function(object, errorPrefix) { const hasCompose = object.compose !== undefined; const hasDecompose = object.decompose !== undefined; @@ -240,7 +241,7 @@ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { * @param {!Blockly.Block} block The block to inspect. * @private */ -Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, +const checkBlockHasMutatorProperties = function(errorPrefix, block) { if (typeof block.domToMutation != 'function') { throw Error(errorPrefix + 'Applying a mutator didn\'t add "domToMutation"'); @@ -251,7 +252,7 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, // A block with a mutator isn't required to have a mutation dialog, but // it should still have both or neither of compose and decompose. - Blockly.Extensions.checkMutatorDialog_(block, errorPrefix); + checkMutatorDialog(block, errorPrefix); }; /** @@ -261,7 +262,7 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, * should be functions, but may be anything other than undefined. * @private */ -Blockly.Extensions.getMutatorProperties_ = function(block) { +const getMutatorProperties = function(block) { const result = []; // List each function explicitly by reference to allow for renaming // during compilation. @@ -289,8 +290,8 @@ Blockly.Extensions.getMutatorProperties_ = function(block) { * @return {boolean} True if the property lists match. * @private */ -Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { - const newProperties = Blockly.Extensions.getMutatorProperties_(block); +const mutatorPropertiesMatch = function(oldProperties, block) { + const newProperties = getMutatorProperties(block); if (newProperties.length != oldProperties.length) { return false; } @@ -321,7 +322,7 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { * tooltip text. * @return {!Function} The extension function. */ -Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, +const buildTooltipForDropdown = function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. const blockTypesChecked = []; @@ -345,7 +346,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, */ const extensionFn = function () { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { - Blockly.Extensions.checkDropdownOptionsInTable_( + checkDropdownOptionsInTable( this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } @@ -380,7 +381,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, * @param {!Object} lookupTable The string lookup table * @private */ -Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, +const checkDropdownOptionsInTable = function(block, dropdownName, lookupTable) { // Validate all dropdown options have values. const dropdown = block.getField(dropdownName); @@ -405,7 +406,7 @@ Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName, * @param {string} fieldName The field with the replacement text. * @return {!Function} The extension function. */ -Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, +const buildTooltipWithFieldText = function(msgTemplate, fieldName) { // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. @@ -440,13 +441,15 @@ Blockly.Extensions.buildTooltipWithFieldText = function(msgTemplate, * @this {Blockly.Block} * @private */ -Blockly.Extensions.extensionParentTooltip_ = function() { - this.tooltipWhenNotConnected_ = this.tooltip; +const extensionParentTooltip = function() { + this.tooltipWhenNotConnected = this.tooltip; this.setTooltip(function() { const parent = this.getParent(); return (parent && parent.getInputsInline() && parent.tooltip) || - this.tooltipWhenNotConnected_; + this.tooltipWhenNotConnected; }.bind(this)); }; -Blockly.Extensions.register('parent_tooltip_when_inline', - Blockly.Extensions.extensionParentTooltip_); +register('parent_tooltip_when_inline', + extensionParentTooltip); + +exports = {ALL_: ALL, register, registerMixin, registerMutator, unregister, apply, buildTooltipForDropdown, buildTooltipWithFieldText}; diff --git a/tests/deps.js b/tests/deps.js index 89bb3d512..5c46df3f6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -47,7 +47,7 @@ goog.addDependency('../../core/events/ui_events.js', ['Blockly.Events.Ui', 'Bloc goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarBase', 'Blockly.Events.VarCreate', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); -goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils']); +goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); From 0bd678fe556db1c68f961abd65a6453ad112b6a1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 15:54:37 -0700 Subject: [PATCH 061/833] Migrate core/extensions.js named requires --- core/extensions.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 8a287e33a..c382c615c 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -20,9 +20,8 @@ goog.module('Blockly.Extensions'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils'); - -goog.requireType('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); +const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goog.require('Blockly.utils'); /** @@ -134,7 +133,7 @@ const unregister = function(name) { * Applies an extension method to a block. This should only be called during * block construction. * @param {string} name The name of the extension. - * @param {!Blockly.Block} block The block to apply the named extension to. + * @param {!Block} block The block to apply the named extension to. * @param {boolean} isMutator True if this extension defines a mutator. * @throws {Error} if the extension is not found. */ @@ -191,7 +190,7 @@ const checkHasFunction = function(errorPrefix, func, * extension to a block, to make sure we are not overwriting properties. * @param {string} mutationName The name of the mutation to reference in error * messages. - * @param {!Blockly.Block} block The block to check. + * @param {!Block} block The block to check. * @throws {Error} if any of the properties already exist on the block. * @private */ @@ -238,7 +237,7 @@ const checkMutatorDialog = function(object, errorPrefix) { * Check that a block has required mutator properties. This should be called * after applying a mutation extension. * @param {string} errorPrefix The string to prepend to any error message. - * @param {!Blockly.Block} block The block to inspect. + * @param {!Block} block The block to inspect. * @private */ const checkBlockHasMutatorProperties = function(errorPrefix, @@ -257,7 +256,7 @@ const checkBlockHasMutatorProperties = function(errorPrefix, /** * Get a list of values of mutator properties on the given block. - * @param {!Blockly.Block} block The block to inspect. + * @param {!Block} block The block to inspect. * @return {!Array} A list with all of the defined properties, which * should be functions, but may be anything other than undefined. * @private @@ -286,7 +285,7 @@ const getMutatorProperties = function(block) { * properties. This should be called after applying a non-mutator extension, * to verify that the extension didn't change properties it shouldn't. * @param {!Array} oldProperties The old values to compare to. - * @param {!Blockly.Block} block The block to inspect for new values. + * @param {!Block} block The block to inspect for new values. * @return {boolean} True if the property lists match. * @private */ @@ -332,17 +331,17 @@ const buildTooltipForDropdown = function(dropdownName, // runAfterPageLoad() does not run in a Node.js environment due to lack of // document object, in which case skip the validation. if (typeof document == 'object') { // Relies on document.readyState - Blockly.utils.runAfterPageLoad(function() { + runAfterPageLoad(function() { for (let key in lookupTable) { // Will print warnings if reference is missing. - Blockly.utils.checkMessageReferences(lookupTable[key]); + checkMessageReferences(lookupTable[key]); } }); } /** * The actual extension. - * @this {Blockly.Block} + * @this {Block} */ const extensionFn = function () { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { @@ -365,7 +364,7 @@ const buildTooltipForDropdown = function(dropdownName, console.warn(warning + '.'); } } else { - tooltip = Blockly.utils.replaceMessageReferences(tooltip); + tooltip = replaceMessageReferences(tooltip); } return tooltip; }.bind(this)); @@ -376,7 +375,7 @@ const buildTooltipForDropdown = function(dropdownName, /** * Checks all options keys are present in the provided string lookup table. * Emits console warnings when they are not. - * @param {!Blockly.Block} block The block containing the dropdown + * @param {!Block} block The block containing the dropdown * @param {string} dropdownName The name of the dropdown * @param {!Object} lookupTable The string lookup table * @private @@ -413,20 +412,20 @@ const buildTooltipWithFieldText = function(msgTemplate, // runAfterPageLoad() does not run in a Node.js environment due to lack of // document object, in which case skip the validation. if (typeof document == 'object') { // Relies on document.readyState - Blockly.utils.runAfterPageLoad(function() { + runAfterPageLoad(function() { // Will print warnings if reference is missing. - Blockly.utils.checkMessageReferences(msgTemplate); + checkMessageReferences(msgTemplate); }); } /** * The actual extension. - * @this {Blockly.Block} + * @this {Block} */ const extensionFn = function () { this.setTooltip(function () { const field = this.getField(fieldName); - return Blockly.utils.replaceMessageReferences(msgTemplate) + return replaceMessageReferences(msgTemplate) .replace('%1', field ? field.getText() : ''); }.bind(this)); }; @@ -438,7 +437,7 @@ const buildTooltipWithFieldText = function(msgTemplate, * uses the tooltip text at the time this extension is initialized. This takes * advantage of the fact that all other values from JSON are initialized before * extensions. - * @this {Blockly.Block} + * @this {Block} * @private */ const extensionParentTooltip = function() { From 9ba9627ed164f8719d3ce54e4766c55b28d8b907 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 18:03:56 -0700 Subject: [PATCH 062/833] clang-format core/extensions.js --- core/extensions.js | 86 ++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index c382c615c..50eb8a70b 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -82,18 +82,14 @@ const registerMixin = function(name, mixinObj) { * flyout of the mutator dialog. * @throws {Error} if the mutation is invalid or can't be applied to the block. */ -const registerMutator = function(name, mixinObj, opt_helperFn, - opt_blockList) { +const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { const errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. - checkHasFunction( - errorPrefix, mixinObj.domToMutation, 'domToMutation'); - checkHasFunction( - errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); + checkHasFunction(errorPrefix, mixinObj.domToMutation, 'domToMutation'); + checkHasFunction(errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); - const hasMutatorDialog = - checkMutatorDialog(mixinObj, errorPrefix); + const hasMutatorDialog = checkMutatorDialog(mixinObj, errorPrefix); if (opt_helperFn && (typeof opt_helperFn != 'function')) { throw Error('Extension "' + name + '" is not a function'); @@ -124,8 +120,8 @@ const unregister = function(name) { if (ALL[name]) { delete ALL[name]; } else { - console.warn('No extension mapping for name "' + name + - '" found to unregister'); + console.warn( + 'No extension mapping for name "' + name + '" found to unregister'); } }; @@ -158,8 +154,9 @@ const apply = function(name, block, isMutator) { checkBlockHasMutatorProperties(errorPrefix, block); } else { if (!mutatorPropertiesMatch( - /** @type {!Array} */ (mutatorProperties), block)) { - throw Error('Error when applying extension "' + name + '": ' + + /** @type {!Array} */ (mutatorProperties), block)) { + throw Error( + 'Error when applying extension "' + name + '": ' + 'mutation properties changed when applying a non-mutator extension.'); } } @@ -173,14 +170,14 @@ const apply = function(name, block, isMutator) { * @throws {Error} if the property does not exist or is not a function. * @private */ -const checkHasFunction = function(errorPrefix, func, - propertyName) { +const checkHasFunction = function(errorPrefix, func, propertyName) { if (!func) { - throw Error(errorPrefix + - 'missing required property "' + propertyName + '"'); + throw Error( + errorPrefix + 'missing required property "' + propertyName + '"'); } else if (typeof func != 'function') { - throw Error(errorPrefix + - '" required property "' + propertyName + '" must be a function'); + throw Error( + errorPrefix + '" required property "' + propertyName + + '" must be a function'); } }; @@ -197,7 +194,8 @@ const checkHasFunction = function(errorPrefix, func, const checkNoMutatorProperties = function(mutationName, block) { const properties = getMutatorProperties(block); if (properties.length) { - throw Error('Error: tried to apply mutation "' + mutationName + + throw Error( + 'Error: tried to apply mutation "' + mutationName + '" to a block that already has mutator functions.' + ' Block id: ' + block.id); } @@ -229,8 +227,8 @@ const checkMutatorDialog = function(object, errorPrefix) { } else if (!hasCompose && !hasDecompose) { return false; } - throw Error(errorPrefix + - 'Must have both or neither of "compose" and "decompose"'); + throw Error( + errorPrefix + 'Must have both or neither of "compose" and "decompose"'); }; /** @@ -240,8 +238,7 @@ const checkMutatorDialog = function(object, errorPrefix) { * @param {!Block} block The block to inspect. * @private */ -const checkBlockHasMutatorProperties = function(errorPrefix, - block) { +const checkBlockHasMutatorProperties = function(errorPrefix, block) { if (typeof block.domToMutation != 'function') { throw Error(errorPrefix + 'Applying a mutator didn\'t add "domToMutation"'); } @@ -321,8 +318,7 @@ const mutatorPropertiesMatch = function(oldProperties, block) { * tooltip text. * @return {!Function} The extension function. */ -const buildTooltipForDropdown = function(dropdownName, - lookupTable) { +const buildTooltipForDropdown = function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. const blockTypesChecked = []; @@ -343,21 +339,20 @@ const buildTooltipForDropdown = function(dropdownName, * The actual extension. * @this {Block} */ - const extensionFn = function () { + const extensionFn = function() { if (this.type && blockTypesChecked.indexOf(this.type) == -1) { - checkDropdownOptionsInTable( - this, dropdownName, lookupTable); + checkDropdownOptionsInTable(this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } - this.setTooltip(function () { + this.setTooltip(function() { const value = String(this.getFieldValue(dropdownName)); let tooltip = lookupTable[value]; if (tooltip == null) { if (blockTypesChecked.indexOf(this.type) == -1) { // Warn for missing values on generated tooltips. - let warning = 'No tooltip mapping for value ' + value + - ' of field ' + dropdownName; + let warning = 'No tooltip mapping for value ' + value + ' of field ' + + dropdownName; if (this.type != null) { warning += (' of block type ' + this.type); } @@ -380,8 +375,7 @@ const buildTooltipForDropdown = function(dropdownName, * @param {!Object} lookupTable The string lookup table * @private */ -const checkDropdownOptionsInTable = function(block, dropdownName, - lookupTable) { +const checkDropdownOptionsInTable = function(block, dropdownName, lookupTable) { // Validate all dropdown options have values. const dropdown = block.getField(dropdownName); if (!dropdown.isOptionListDynamic()) { @@ -389,8 +383,9 @@ const checkDropdownOptionsInTable = function(block, dropdownName, for (let i = 0; i < options.length; ++i) { const optionKey = options[i][1]; // label, then value if (lookupTable[optionKey] == null) { - console.warn('No tooltip mapping for value ' + optionKey + - ' of field ' + dropdownName + ' of block type ' + block.type); + console.warn( + 'No tooltip mapping for value ' + optionKey + ' of field ' + + dropdownName + ' of block type ' + block.type); } } } @@ -405,8 +400,7 @@ const checkDropdownOptionsInTable = function(block, dropdownName, * @param {string} fieldName The field with the replacement text. * @return {!Function} The extension function. */ -const buildTooltipWithFieldText = function(msgTemplate, - fieldName) { +const buildTooltipWithFieldText = function(msgTemplate, fieldName) { // Check the tooltip string messages for invalid references. // Wait for load, in case Blockly.Msg is not yet populated. // runAfterPageLoad() does not run in a Node.js environment due to lack of @@ -422,8 +416,8 @@ const buildTooltipWithFieldText = function(msgTemplate, * The actual extension. * @this {Block} */ - const extensionFn = function () { - this.setTooltip(function () { + const extensionFn = function() { + this.setTooltip(function() { const field = this.getField(fieldName); return replaceMessageReferences(msgTemplate) .replace('%1', field ? field.getText() : ''); @@ -448,7 +442,15 @@ const extensionParentTooltip = function() { this.tooltipWhenNotConnected; }.bind(this)); }; -register('parent_tooltip_when_inline', - extensionParentTooltip); +register('parent_tooltip_when_inline', extensionParentTooltip); -exports = {ALL_: ALL, register, registerMixin, registerMutator, unregister, apply, buildTooltipForDropdown, buildTooltipWithFieldText}; +exports = { + ALL_: ALL, + register, + registerMixin, + registerMutator, + unregister, + apply, + buildTooltipForDropdown, + buildTooltipWithFieldText +}; From fa9a175296d40c8db1e9d4e4fd7b2300321b57cc Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 12:30:09 -0700 Subject: [PATCH 063/833] Update name of private property --- core/extensions.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/extensions.js b/core/extensions.js index 50eb8a70b..c73737c43 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -28,7 +28,7 @@ const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goo * The set of all registered extensions, keyed by extension name/id. * @private */ -const ALL = Object.create(null); +const allExtensions = Object.create(null); /** * Registers a new extension function. Extensions are functions that help @@ -44,13 +44,13 @@ const register = function(name, initFn) { if ((typeof name != 'string') || (name.trim() == '')) { throw Error('Error: Invalid extension name "' + name + '"'); } - if (ALL[name]) { + if (allExtensions[name]) { throw Error('Error: Extension "' + name + '" is already registered.'); } if (typeof initFn != 'function') { throw Error('Error: Extension "' + name + '" must be a function'); } - ALL[name] = initFn; + allExtensions[name] = initFn; }; /** @@ -117,8 +117,8 @@ const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { * @param {string} name The name of the extension to unregister. */ const unregister = function(name) { - if (ALL[name]) { - delete ALL[name]; + if (allExtensions[name]) { + delete allExtensions[name]; } else { console.warn( 'No extension mapping for name "' + name + '" found to unregister'); @@ -134,7 +134,7 @@ const unregister = function(name) { * @throws {Error} if the extension is not found. */ const apply = function(name, block, isMutator) { - const extensionFn = ALL[name]; + const extensionFn = allExtensions[name]; if (typeof extensionFn != 'function') { throw Error('Error: Extension "' + name + '" not found.'); } @@ -445,7 +445,7 @@ const extensionParentTooltip = function() { register('parent_tooltip_when_inline', extensionParentTooltip); exports = { - ALL_: ALL, + ALL_: allExtensions, register, registerMixin, registerMutator, From 80d953d5b964eb45576854ff5a80e93dc18a93b9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 14 Jul 2021 17:29:55 -0700 Subject: [PATCH 064/833] Migrate core/css.js to ES6 const/let --- core/css.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/css.js b/core/css.js index 9f6037d7b..a72088a7f 100644 --- a/core/css.js +++ b/core/css.js @@ -55,19 +55,19 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { return; } Blockly.Css.injected_ = true; - var text = Blockly.Css.CONTENT.join('\n'); + let text = Blockly.Css.CONTENT.join('\n'); Blockly.Css.CONTENT.length = 0; // Garbage collect CSS content. if (!hasCss) { return; } // Strip off any trailing slash (either Unix or Windows). - var mediaPath = pathToMedia.replace(/[\\/]$/, ''); + const mediaPath = pathToMedia.replace(/[\\/]$/, ''); text = text.replace(/<<>>/g, mediaPath); // Inject CSS tag at start of head. - var cssNode = document.createElement('style'); + const cssNode = document.createElement('style'); cssNode.id = 'blockly-common-style'; - var cssTextNode = document.createTextNode(text); + const cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); }; From 902112be3d88493261435b2c786b274d261fcccb Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:00:56 -0700 Subject: [PATCH 065/833] Use ES6 template strings in core/css.js --- core/css.js | 766 ++++++++++++++++++++++++++-------------------------- 1 file changed, 384 insertions(+), 382 deletions(-) diff --git a/core/css.js b/core/css.js index a72088a7f..b63c7ed8e 100644 --- a/core/css.js +++ b/core/css.js @@ -76,477 +76,479 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { * Array making up the CSS content for Blockly. */ Blockly.Css.CONTENT = [ - /* eslint-disable indent */ - '.blocklySvg {', - 'background-color: #fff;', - 'outline: none;', - 'overflow: hidden;', /* IE overflows by default. */ - 'position: absolute;', - 'display: block;', - '}', +`.blocklySvg { + background-color: #fff; + outline: none; + overflow: hidden; /* IE overflows by default. */ + position: absolute; + display: block; +}`, - '.blocklyWidgetDiv {', - 'display: none;', - 'position: absolute;', - 'z-index: 99999;', /* big value for bootstrap3 compatibility */ - '}', +`.blocklyWidgetDiv { + display: none; + position: absolute; + z-index: 99999; /* big value for bootstrap3 compatibility */ +}`, - '.injectionDiv {', - 'height: 100%;', - 'position: relative;', - 'overflow: hidden;', /* So blocks in drag surface disappear at edges */ - 'touch-action: none;', - '}', +`.injectionDiv { + height: 100%; + position: relative; + overflow: hidden; /* So blocks in drag surface disappear at edges */ + touch-action: none; +}`, - '.blocklyNonSelectable {', - 'user-select: none;', - '-ms-user-select: none;', - '-webkit-user-select: none;', - '}', +`.blocklyNonSelectable { + user-select: none; + -ms-user-select: none; + -webkit-user-select: none; +}`, + +`.blocklyWsDragSurface { + display: none; + position: absolute; + top: 0; + left: 0; +}`, - '.blocklyWsDragSurface {', - 'display: none;', - 'position: absolute;', - 'top: 0;', - 'left: 0;', - '}', /* Added as a separate rule with multiple classes to make it more specific than a bootstrap rule that selects svg:root. See issue #1275 for context. */ - '.blocklyWsDragSurface.blocklyOverflowVisible {', - 'overflow: visible;', - '}', +`.blocklyWsDragSurface.blocklyOverflowVisible { + overflow: visible; +}`, - '.blocklyBlockDragSurface {', - 'display: none;', - 'position: absolute;', - 'top: 0;', - 'left: 0;', - 'right: 0;', - 'bottom: 0;', - 'overflow: visible !important;', - 'z-index: 50;', /* Display below toolbox, but above everything else. */ - '}', +`.blocklyBlockDragSurface { + display: none; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + overflow: visible !important; + z-index: 50;', /* Display below toolbox, but above everything else. */ +}`, - '.blocklyBlockCanvas.blocklyCanvasTransitioning,', - '.blocklyBubbleCanvas.blocklyCanvasTransitioning {', - 'transition: transform .5s;', - '}', +`.blocklyBlockCanvas.blocklyCanvasTransitioning, +.blocklyBubbleCanvas.blocklyCanvasTransitioning { + transition: transform .5s; +}`, - '.blocklyTooltipDiv {', - 'background-color: #ffffc7;', - 'border: 1px solid #ddc;', - 'box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);', - 'color: #000;', - 'display: none;', - 'font: 9pt sans-serif;', - 'opacity: .9;', - 'padding: 2px;', - 'position: absolute;', - 'z-index: 100000;', /* big value for bootstrap3 compatibility */ - '}', +`.blocklyTooltipDiv { + background-color: #ffffc7; + border: 1px solid #ddc; + box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15); + color: #000; + display: none; + font: 9pt sans-serif; + opacity: .9; + padding: 2px; + position: absolute; + z-index: 100000;', /* big value for bootstrap3 compatibility */ +}`, - '.blocklyDropDownDiv {', - 'position: absolute;', - 'left: 0;', - 'top: 0;', - 'z-index: 1000;', - 'display: none;', - 'border: 1px solid;', - 'border-color: #dadce0;', - 'background-color: #fff;', - 'border-radius: 2px;', - 'padding: 4px;', - 'box-shadow: 0 0 3px 1px rgba(0,0,0,.3);', - '}', +`.blocklyDropDownDiv { + position: absolute; + left: 0; + top: 0; + z-index: 1000; + display: none; + border: 1px solid; + border-color: #dadce0; + background-color: #fff; + border-radius: 2px; + padding: 4px; + box-shadow: 0 0 3px 1px rgba(0,0,0,.3); +}`, - '.blocklyDropDownDiv.blocklyFocused {', - 'box-shadow: 0 0 6px 1px rgba(0,0,0,.3);', - '}', +`.blocklyDropDownDiv.blocklyFocused { + box-shadow: 0 0 6px 1px rgba(0,0,0,.3); +}`, - '.blocklyDropDownContent {', - 'max-height: 300px;', // @todo: spec for maximum height. - 'overflow: auto;', - 'overflow-x: hidden;', - 'position: relative;', - '}', +`.blocklyDropDownContent { + max-height: 300px;', // @todo: spec for maximum height. + overflow: auto; + overflow-x: hidden; + position: relative; +}`, - '.blocklyDropDownArrow {', - 'position: absolute;', - 'left: 0;', - 'top: 0;', - 'width: 16px;', - 'height: 16px;', - 'z-index: -1;', - 'background-color: inherit;', - 'border-color: inherit;', - '}', +`.blocklyDropDownArrow { + position: absolute; + left: 0; + top: 0; + width: 16px; + height: 16px; + z-index: -1; + background-color: inherit; + border-color: inherit; +}`, - '.blocklyDropDownButton {', - 'display: inline-block;', - 'float: left;', - 'padding: 0;', - 'margin: 4px;', - 'border-radius: 4px;', - 'outline: none;', - 'border: 1px solid;', - 'transition: box-shadow .1s;', - 'cursor: pointer;', - '}', +`.blocklyDropDownButton { + display: inline-block; + float: left; + padding: 0; + margin: 4px; + border-radius: 4px; + outline: none; + border: 1px solid; + transition: box-shadow .1s; + cursor: pointer; +}`, - '.blocklyArrowTop {', - 'border-top: 1px solid;', - 'border-left: 1px solid;', - 'border-top-left-radius: 4px;', - 'border-color: inherit;', - '}', +`.blocklyArrowTop { + border-top: 1px solid; + border-left: 1px solid; + border-top-left-radius: 4px; + border-color: inherit; +}`, - '.blocklyArrowBottom {', - 'border-bottom: 1px solid;', - 'border-right: 1px solid;', - 'border-bottom-right-radius: 4px;', - 'border-color: inherit;', - '}', +`.blocklyArrowBottom { + border-bottom: 1px solid; + border-right: 1px solid; + border-bottom-right-radius: 4px; + border-color: inherit; +}`, - '.blocklyResizeSE {', - 'cursor: se-resize;', - 'fill: #aaa;', - '}', +`.blocklyResizeSE { + cursor: se-resize; + fill: #aaa; +}`, - '.blocklyResizeSW {', - 'cursor: sw-resize;', - 'fill: #aaa;', - '}', +`.blocklyResizeSW { + cursor: sw-resize; + fill: #aaa; +}`, - '.blocklyResizeLine {', - 'stroke: #515A5A;', - 'stroke-width: 1;', - '}', +`.blocklyResizeLine { + stroke: #515A5A; + stroke-width: 1; +}`, - '.blocklyHighlightedConnectionPath {', - 'fill: none;', - 'stroke: #fc3;', - 'stroke-width: 4px;', - '}', +`.blocklyHighlightedConnectionPath { + fill: none; + stroke: #fc3; + stroke-width: 4px; +}`, - '.blocklyPathLight {', - 'fill: none;', - 'stroke-linecap: round;', - 'stroke-width: 1;', - '}', +`.blocklyPathLight { + fill: none; + stroke-linecap: round; + stroke-width: 1; +}`, - '.blocklySelected>.blocklyPathLight {', - 'display: none;', - '}', +`.blocklySelected>.blocklyPathLight { + display: none; +}`, - '.blocklyDraggable {', - /* backup for browsers (e.g. IE11) that don't support grab */ - 'cursor: url("<<>>/handopen.cur"), auto;', - 'cursor: grab;', - 'cursor: -webkit-grab;', - '}', +`.blocklyDraggable { + /* backup for browsers (e.g. IE11) that don't support grab */ + cursor: url("<<>>/handopen.cur"), auto; + cursor: grab; + cursor: -webkit-grab; +}`, + + /* backup for browsers (e.g. IE11) that don't support grabbing */ +`.blocklyDragging { + /* backup for browsers (e.g. IE11) that don't support grabbing */ + cursor: url("<<>>/handclosed.cur"), auto; + cursor: grabbing; + cursor: -webkit-grabbing; +}`, - '.blocklyDragging {', - /* backup for browsers (e.g. IE11) that don't support grabbing */ - 'cursor: url("<<>>/handclosed.cur"), auto;', - 'cursor: grabbing;', - 'cursor: -webkit-grabbing;', - '}', /* Changes cursor on mouse down. Not effective in Firefox because of - https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */ - '.blocklyDraggable:active {', - /* backup for browsers (e.g. IE11) that don't support grabbing */ - 'cursor: url("<<>>/handclosed.cur"), auto;', - 'cursor: grabbing;', - 'cursor: -webkit-grabbing;', - '}', + https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */ +`.blocklyDraggable:active { + /* backup for browsers (e.g. IE11) that don't support grabbing */ + cursor: url("<<>>/handclosed.cur"), auto; + cursor: grabbing; + cursor: -webkit-grabbing; +}`, + /* Change the cursor on the whole drag surface in case the mouse gets ahead of block during a drag. This way the cursor is still a closed hand. */ - '.blocklyBlockDragSurface .blocklyDraggable {', - /* backup for browsers (e.g. IE11) that don't support grabbing */ - 'cursor: url("<<>>/handclosed.cur"), auto;', - 'cursor: grabbing;', - 'cursor: -webkit-grabbing;', - '}', +`.blocklyBlockDragSurface .blocklyDraggable { + /* backup for browsers (e.g. IE11) that don't support grabbing */ + cursor: url("<<>>/handclosed.cur"), auto; + cursor: grabbing; + cursor: -webkit-grabbing; +}`, - '.blocklyDragging.blocklyDraggingDelete {', - 'cursor: url("<<>>/handdelete.cur"), auto;', - '}', +`.blocklyDragging.blocklyDraggingDelete { + cursor: url("<<>>/handdelete.cur"), auto; +}`, - '.blocklyDragging>.blocklyPath,', - '.blocklyDragging>.blocklyPathLight {', - 'fill-opacity: .8;', - 'stroke-opacity: .8;', - '}', +`.blocklyDragging>.blocklyPath, +.blocklyDragging>.blocklyPathLight { + fill-opacity: .8; + stroke-opacity: .8; +}`, - '.blocklyDragging>.blocklyPathDark {', - 'display: none;', - '}', +`.blocklyDragging>.blocklyPathDark { + display: none; +}`, - '.blocklyDisabled>.blocklyPath {', - 'fill-opacity: .5;', - 'stroke-opacity: .5;', - '}', +`.blocklyDisabled>.blocklyPath { + fill-opacity: .5; + stroke-opacity: .5; +}`, - '.blocklyDisabled>.blocklyPathLight,', - '.blocklyDisabled>.blocklyPathDark {', - 'display: none;', - '}', +`.blocklyDisabled>.blocklyPathLight, +.blocklyDisabled>.blocklyPathDark { + display: none; +}`, - '.blocklyInsertionMarker>.blocklyPath,', - '.blocklyInsertionMarker>.blocklyPathLight,', - '.blocklyInsertionMarker>.blocklyPathDark {', - 'fill-opacity: .2;', - 'stroke: none;', - '}', +`.blocklyInsertionMarker>.blocklyPath, +.blocklyInsertionMarker>.blocklyPathLight, +.blocklyInsertionMarker>.blocklyPathDark { + fill-opacity: .2; + stroke: none; +}`, - '.blocklyMultilineText {', - 'font-family: monospace;', - '}', +`.blocklyMultilineText { + font-family: monospace; +}`, - '.blocklyNonEditableText>text {', - 'pointer-events: none;', - '}', +`.blocklyNonEditableText>text { + pointer-events: none; +}`, - '.blocklyFlyout {', - 'position: absolute;', - 'z-index: 20;', - '}', +`.blocklyFlyout { + position: absolute; + z-index: 20; +}`, - '.blocklyText text {', - 'cursor: default;', - '}', +`.blocklyText text { + cursor: default; +}`, /* Don't allow users to select text. It gets annoying when trying to drag a block and selected text moves instead. */ - '.blocklySvg text,', - '.blocklyBlockDragSurface text {', - 'user-select: none;', - '-ms-user-select: none;', - '-webkit-user-select: none;', - 'cursor: inherit;', - '}', +`.blocklySvg text, +.blocklyBlockDragSurface text { + user-select: none; + -ms-user-select: none; + -webkit-user-select: none; + cursor: inherit; +}`, - '.blocklyHidden {', - 'display: none;', - '}', +`.blocklyHidden { + display: none; +}`, - '.blocklyFieldDropdown:not(.blocklyHidden) {', - 'display: block;', - '}', +`.blocklyFieldDropdown:not(.blocklyHidden) { + display: block; +}`, - '.blocklyIconGroup {', - 'cursor: default;', - '}', +`.blocklyIconGroup { + cursor: default; +}`, - '.blocklyIconGroup:not(:hover),', - '.blocklyIconGroupReadonly {', - 'opacity: .6;', - '}', +`.blocklyIconGroup:not(:hover), +.blocklyIconGroupReadonly { + opacity: .6; +}`, - '.blocklyIconShape {', - 'fill: #00f;', - 'stroke: #fff;', - 'stroke-width: 1px;', - '}', +`.blocklyIconShape { + fill: #00f; + stroke: #fff; + stroke-width: 1px; +}`, - '.blocklyIconSymbol {', - 'fill: #fff;', - '}', +`.blocklyIconSymbol { + fill: #fff; +}`, - '.blocklyMinimalBody {', - 'margin: 0;', - 'padding: 0;', - '}', +`.blocklyMinimalBody { + margin: 0; + padding: 0; +}`, - '.blocklyHtmlInput {', - 'border: none;', - 'border-radius: 4px;', - 'height: 100%;', - 'margin: 0;', - 'outline: none;', - 'padding: 0;', - 'width: 100%;', - 'text-align: center;', - 'display: block;', - 'box-sizing: border-box;', - '}', +`.blocklyHtmlInput { + border: none; + border-radius: 4px; + height: 100%; + margin: 0; + outline: none; + padding: 0; + width: 100%; + text-align: center; + display: block; + box-sizing: border-box; +}`, /* Edge and IE introduce a close icon when the input value is longer than a certain length. This affects our sizing calculations of the text input. Hiding the close icon to avoid that. */ - '.blocklyHtmlInput::-ms-clear {', - 'display: none;', - '}', +`.blocklyHtmlInput::-ms-clear { + display: none; +}`, - '.blocklyMainBackground {', - 'stroke-width: 1;', - 'stroke: #c6c6c6;', /* Equates to #ddd due to border being off-pixel. */ - '}', +`.blocklyMainBackground { + stroke-width: 1; + stroke: #c6c6c6;', /* Equates to #ddd due to border being off-pixel. */ +}`, - '.blocklyMutatorBackground {', - 'fill: #fff;', - 'stroke: #ddd;', - 'stroke-width: 1;', - '}', +`.blocklyMutatorBackground { + fill: #fff; + stroke: #ddd; + stroke-width: 1; +}`, - '.blocklyFlyoutBackground {', - 'fill: #ddd;', - 'fill-opacity: .8;', - '}', +`.blocklyFlyoutBackground { + fill: #ddd; + fill-opacity: .8; +}`, - '.blocklyMainWorkspaceScrollbar {', - 'z-index: 20;', - '}', +`.blocklyMainWorkspaceScrollbar { + z-index: 20; +}`, - '.blocklyFlyoutScrollbar {', - 'z-index: 30;', - '}', +`.blocklyFlyoutScrollbar { + z-index: 30; +}`, - '.blocklyScrollbarHorizontal,', - '.blocklyScrollbarVertical {', - 'position: absolute;', - 'outline: none;', - '}', +`.blocklyScrollbarHorizontal, +.blocklyScrollbarVertical { + position: absolute; + outline: none; +}`, - '.blocklyScrollbarBackground {', - 'opacity: 0;', - '}', +`.blocklyScrollbarBackground { + opacity: 0; +}`, - '.blocklyScrollbarHandle {', - 'fill: #ccc;', - '}', +`.blocklyScrollbarHandle { + fill: #ccc; +}`, - '.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,', - '.blocklyScrollbarHandle:hover {', - 'fill: #bbb;', - '}', +`.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, +.blocklyScrollbarHandle:hover { + fill: #bbb; +}`, /* Darken flyout scrollbars due to being on a grey background. */ /* By contrast, workspace scrollbars are on a white background. */ - '.blocklyFlyout .blocklyScrollbarHandle {', - 'fill: #bbb;', - '}', +`.blocklyFlyout .blocklyScrollbarHandle { + fill: #bbb; +}`, - '.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,', - '.blocklyFlyout .blocklyScrollbarHandle:hover {', - 'fill: #aaa;', - '}', +`.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, +.blocklyFlyout .blocklyScrollbarHandle:hover { + fill: #aaa; +}`, - '.blocklyInvalidInput {', - 'background: #faa;', - '}', +`.blocklyInvalidInput { + background: #faa; +}`, - '.blocklyVerticalMarker {', - 'stroke-width: 3px;', - 'fill: rgba(255,255,255,.5);', - 'pointer-events: none;', - '}', +`.blocklyVerticalMarker { + stroke-width: 3px; + fill: rgba(255,255,255,.5); + pointer-events: none; +}`, - '.blocklyComputeCanvas {', - 'position: absolute;', - 'width: 0;', - 'height: 0;', - '}', +`.blocklyComputeCanvas { + position: absolute; + width: 0; + height: 0; +}`, - '.blocklyNoPointerEvents {', - 'pointer-events: none;', - '}', +`.blocklyNoPointerEvents { + pointer-events: none; +}`, - '.blocklyContextMenu {', - 'border-radius: 4px;', - 'max-height: 100%;', - '}', +`.blocklyContextMenu { + border-radius: 4px; + max-height: 100%; +}`, - '.blocklyDropdownMenu {', - 'border-radius: 2px;', - 'padding: 0 !important;', - '}', +`.blocklyDropdownMenu { + border-radius: 2px; + padding: 0 !important; +}`, - '.blocklyDropdownMenu .blocklyMenuItem {', - /* 28px on the left for icon or checkbox. */ - 'padding-left: 28px;', - '}', +`.blocklyDropdownMenu .blocklyMenuItem { + /* 28px on the left for icon or checkbox. */ + padding-left: 28px; +}`, /* BiDi override for the resting state. */ - '.blocklyDropdownMenu .blocklyMenuItemRtl {', - /* Flip left/right padding for BiDi. */ - 'padding-left: 5px;', - 'padding-right: 28px;', - '}', +`.blocklyDropdownMenu .blocklyMenuItemRtl { + /* Flip left/right padding for BiDi. */ + padding-left: 5px; + padding-right: 28px; +}`, - '.blocklyWidgetDiv .blocklyMenu {', - 'background: #fff;', - 'border: 1px solid transparent;', - 'box-shadow: 0 0 3px 1px rgba(0,0,0,.3);', - 'font: normal 13px Arial, sans-serif;', - 'margin: 0;', - 'outline: none;', - 'padding: 4px 0;', - 'position: absolute;', - 'overflow-y: auto;', - 'overflow-x: hidden;', - 'max-height: 100%;', - 'z-index: 20000;', /* Arbitrary, but some apps depend on it... */ - '}', +`.blocklyWidgetDiv .blocklyMenu { + background: #fff; + border: 1px solid transparent; + box-shadow: 0 0 3px 1px rgba(0,0,0,.3); + font: normal 13px Arial, sans-serif; + margin: 0; + outline: none; + padding: 4px 0; + position: absolute; + overflow-y: auto; + overflow-x: hidden; + max-height: 100%; + z-index: 20000;', /* Arbitrary, but some apps depend on it... */ +}`, - '.blocklyWidgetDiv .blocklyMenu.blocklyFocused {', - 'box-shadow: 0 0 6px 1px rgba(0,0,0,.3);', - '}', +`.blocklyWidgetDiv .blocklyMenu.blocklyFocused { + box-shadow: 0 0 6px 1px rgba(0,0,0,.3); +}`, - '.blocklyDropDownDiv .blocklyMenu {', - 'background: inherit;', /* Compatibility with gapi, reset from goog-menu */ - 'border: inherit;', /* Compatibility with gapi, reset from goog-menu */ - 'font: normal 13px "Helvetica Neue", Helvetica, sans-serif;', - 'outline: none;', - 'position: relative;', /* Compatibility with gapi, reset from goog-menu */ - 'z-index: 20000;', /* Arbitrary, but some apps depend on it... */ - '}', +`.blocklyDropDownDiv .blocklyMenu { + background: inherit;', /* Compatibility with gapi, reset from goog-menu */ + border: inherit;', /* Compatibility with gapi, reset from goog-menu */ + font: normal 13px "Helvetica Neue", Helvetica, sans-serif; + outline: none; + position: relative;', /* Compatibility with gapi, reset from goog-menu */ + z-index: 20000;', /* Arbitrary, but some apps depend on it... */ +}`, /* State: resting. */ - '.blocklyMenuItem {', - 'border: none;', - 'color: #000;', - 'cursor: pointer;', - 'list-style: none;', - 'margin: 0;', - /* 7em on the right for shortcut. */ - 'min-width: 7em;', - 'padding: 6px 15px;', - 'white-space: nowrap;', - '}', +`.blocklyMenuItem { + border: none; + color: #000; + cursor: pointer; + list-style: none; + margin: 0; + /* 7em on the right for shortcut. */ + min-width: 7em; + padding: 6px 15px; + white-space: nowrap; +}`, /* State: disabled. */ - '.blocklyMenuItemDisabled {', - 'color: #ccc;', - 'cursor: inherit;', - '}', +`.blocklyMenuItemDisabled { + color: #ccc; + cursor: inherit; +}`, /* State: hover. */ - '.blocklyMenuItemHighlight {', - 'background-color: rgba(0,0,0,.1);', - '}', +`.blocklyMenuItemHighlight { + background-color: rgba(0,0,0,.1); +}`, /* State: selected/checked. */ - '.blocklyMenuItemCheckbox {', - 'height: 16px;', - 'position: absolute;', - 'width: 16px;', - '}', +`.blocklyMenuItemCheckbox { + height: 16px; + position: absolute; + width: 16px; +}`, - '.blocklyMenuItemSelected .blocklyMenuItemCheckbox {', - 'background: url(<<>>/sprites.png) no-repeat -48px -16px;', - 'float: left;', - 'margin-left: -24px;', - 'position: static;', /* Scroll with the menu. */ - '}', +`.blocklyMenuItemSelected .blocklyMenuItemCheckbox { + background: url(<<>>/sprites.png) no-repeat -48px -16px; + float: left; + margin-left: -24px; + position: static;', /* Scroll with the menu. */ +}`, - '.blocklyMenuItemRtl .blocklyMenuItemCheckbox {', - 'float: right;', - 'margin-right: -24px;', - '}', - /* eslint-enable indent */ +`.blocklyMenuItemRtl .blocklyMenuItemCheckbox { + float: right; + margin-right: -24px; +}`, ]; From 7c23985d30493cc1f60399ffbcce111444da3f11 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:04:38 -0700 Subject: [PATCH 066/833] Migrate core/css.js to goog.module --- core/css.js | 27 +++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/css.js b/core/css.js index b63c7ed8e..02d3db4bf 100644 --- a/core/css.js +++ b/core/css.js @@ -14,7 +14,8 @@ * @name Blockly.Css * @namespace */ -goog.provide('Blockly.Css'); +goog.module('Blockly.Css'); +goog.module.declareLegacyNamespace(); /** @@ -22,7 +23,7 @@ goog.provide('Blockly.Css'); * @type {boolean} * @private */ -Blockly.Css.injected_ = false; +let injected = false; /** * Add some CSS to the blob that will be injected later. Allows optional @@ -30,12 +31,12 @@ Blockly.Css.injected_ = false; * The provided array of CSS will be destroyed by this function. * @param {!Array} cssArray Array of CSS strings. */ -Blockly.Css.register = function(cssArray) { - if (Blockly.Css.injected_) { +const register = function(cssArray) { + if (injected) { throw Error('CSS already injected'); } - // Concatenate cssArray onto Blockly.Css.CONTENT. - Array.prototype.push.apply(Blockly.Css.CONTENT, cssArray); + // Concatenate cssArray onto CONTENT. + Array.prototype.push.apply(CONTENT, cssArray); cssArray.length = 0; // Garbage collect provided CSS content. }; @@ -49,14 +50,14 @@ Blockly.Css.register = function(cssArray) { * (providing CSS becomes the document's responsibility). * @param {string} pathToMedia Path from page to the Blockly media directory. */ -Blockly.Css.inject = function(hasCss, pathToMedia) { +const inject = function(hasCss, pathToMedia) { // Only inject the CSS once. - if (Blockly.Css.injected_) { + if (injected) { return; } - Blockly.Css.injected_ = true; - let text = Blockly.Css.CONTENT.join('\n'); - Blockly.Css.CONTENT.length = 0; // Garbage collect CSS content. + injected = true; + let text = CONTENT.join('\n'); + CONTENT.length = 0; // Garbage collect CSS content. if (!hasCss) { return; } @@ -75,7 +76,7 @@ Blockly.Css.inject = function(hasCss, pathToMedia) { /** * Array making up the CSS content for Blockly. */ -Blockly.Css.CONTENT = [ +const CONTENT = [ `.blocklySvg { background-color: #fff; outline: none; @@ -552,3 +553,5 @@ Blockly.Css.CONTENT = [ margin-right: -24px; }`, ]; + +exports = {register, inject, CONTENT}; diff --git a/tests/deps.js b/tests/deps.js index 5c46df3f6..a44954c4f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -27,7 +27,7 @@ goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.c goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); -goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es5'}); +goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); From 7aae731a521b91c32bc102d55d9461f18becb3dd Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:05:00 -0700 Subject: [PATCH 067/833] clang-format core/css.js --- core/css.js | 154 +++++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 75 deletions(-) diff --git a/core/css.js b/core/css.js index 02d3db4bf..52228b4fb 100644 --- a/core/css.js +++ b/core/css.js @@ -77,7 +77,7 @@ const inject = function(hasCss, pathToMedia) { * Array making up the CSS content for Blockly. */ const CONTENT = [ -`.blocklySvg { + `.blocklySvg { background-color: #fff; outline: none; overflow: hidden; /* IE overflows by default. */ @@ -85,26 +85,26 @@ const CONTENT = [ display: block; }`, -`.blocklyWidgetDiv { + `.blocklyWidgetDiv { display: none; position: absolute; z-index: 99999; /* big value for bootstrap3 compatibility */ }`, -`.injectionDiv { + `.injectionDiv { height: 100%; position: relative; overflow: hidden; /* So blocks in drag surface disappear at edges */ touch-action: none; }`, -`.blocklyNonSelectable { + `.blocklyNonSelectable { user-select: none; -ms-user-select: none; -webkit-user-select: none; }`, -`.blocklyWsDragSurface { + `.blocklyWsDragSurface { display: none; position: absolute; top: 0; @@ -114,11 +114,11 @@ const CONTENT = [ /* Added as a separate rule with multiple classes to make it more specific than a bootstrap rule that selects svg:root. See issue #1275 for context. */ -`.blocklyWsDragSurface.blocklyOverflowVisible { + `.blocklyWsDragSurface.blocklyOverflowVisible { overflow: visible; }`, -`.blocklyBlockDragSurface { + `.blocklyBlockDragSurface { display: none; position: absolute; top: 0; @@ -129,12 +129,12 @@ const CONTENT = [ z-index: 50;', /* Display below toolbox, but above everything else. */ }`, -`.blocklyBlockCanvas.blocklyCanvasTransitioning, + `.blocklyBlockCanvas.blocklyCanvasTransitioning, .blocklyBubbleCanvas.blocklyCanvasTransitioning { transition: transform .5s; }`, -`.blocklyTooltipDiv { + `.blocklyTooltipDiv { background-color: #ffffc7; border: 1px solid #ddc; box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15); @@ -147,7 +147,7 @@ const CONTENT = [ z-index: 100000;', /* big value for bootstrap3 compatibility */ }`, -`.blocklyDropDownDiv { + `.blocklyDropDownDiv { position: absolute; left: 0; top: 0; @@ -161,18 +161,18 @@ const CONTENT = [ box-shadow: 0 0 3px 1px rgba(0,0,0,.3); }`, -`.blocklyDropDownDiv.blocklyFocused { + `.blocklyDropDownDiv.blocklyFocused { box-shadow: 0 0 6px 1px rgba(0,0,0,.3); }`, -`.blocklyDropDownContent { + `.blocklyDropDownContent { max-height: 300px;', // @todo: spec for maximum height. overflow: auto; overflow-x: hidden; position: relative; }`, -`.blocklyDropDownArrow { + `.blocklyDropDownArrow { position: absolute; left: 0; top: 0; @@ -183,7 +183,7 @@ const CONTENT = [ border-color: inherit; }`, -`.blocklyDropDownButton { + `.blocklyDropDownButton { display: inline-block; float: left; padding: 0; @@ -195,52 +195,52 @@ const CONTENT = [ cursor: pointer; }`, -`.blocklyArrowTop { + `.blocklyArrowTop { border-top: 1px solid; border-left: 1px solid; border-top-left-radius: 4px; border-color: inherit; }`, -`.blocklyArrowBottom { + `.blocklyArrowBottom { border-bottom: 1px solid; border-right: 1px solid; border-bottom-right-radius: 4px; border-color: inherit; }`, -`.blocklyResizeSE { + `.blocklyResizeSE { cursor: se-resize; fill: #aaa; }`, -`.blocklyResizeSW { + `.blocklyResizeSW { cursor: sw-resize; fill: #aaa; }`, -`.blocklyResizeLine { + `.blocklyResizeLine { stroke: #515A5A; stroke-width: 1; }`, -`.blocklyHighlightedConnectionPath { + `.blocklyHighlightedConnectionPath { fill: none; stroke: #fc3; stroke-width: 4px; }`, -`.blocklyPathLight { + `.blocklyPathLight { fill: none; stroke-linecap: round; stroke-width: 1; }`, -`.blocklySelected>.blocklyPathLight { + `.blocklySelected>.blocklyPathLight { display: none; }`, -`.blocklyDraggable { + `.blocklyDraggable { /* backup for browsers (e.g. IE11) that don't support grab */ cursor: url("<<>>/handopen.cur"), auto; cursor: grab; @@ -248,7 +248,7 @@ const CONTENT = [ }`, /* backup for browsers (e.g. IE11) that don't support grabbing */ -`.blocklyDragging { + `.blocklyDragging { /* backup for browsers (e.g. IE11) that don't support grabbing */ cursor: url("<<>>/handclosed.cur"), auto; cursor: grabbing; @@ -257,7 +257,7 @@ const CONTENT = [ /* Changes cursor on mouse down. Not effective in Firefox because of https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */ -`.blocklyDraggable:active { + `.blocklyDraggable:active { /* backup for browsers (e.g. IE11) that don't support grabbing */ cursor: url("<<>>/handclosed.cur"), auto; cursor: grabbing; @@ -267,58 +267,58 @@ const CONTENT = [ /* Change the cursor on the whole drag surface in case the mouse gets ahead of block during a drag. This way the cursor is still a closed hand. */ -`.blocklyBlockDragSurface .blocklyDraggable { + `.blocklyBlockDragSurface .blocklyDraggable { /* backup for browsers (e.g. IE11) that don't support grabbing */ cursor: url("<<>>/handclosed.cur"), auto; cursor: grabbing; cursor: -webkit-grabbing; }`, -`.blocklyDragging.blocklyDraggingDelete { + `.blocklyDragging.blocklyDraggingDelete { cursor: url("<<>>/handdelete.cur"), auto; }`, -`.blocklyDragging>.blocklyPath, + `.blocklyDragging>.blocklyPath, .blocklyDragging>.blocklyPathLight { fill-opacity: .8; stroke-opacity: .8; }`, -`.blocklyDragging>.blocklyPathDark { + `.blocklyDragging>.blocklyPathDark { display: none; }`, -`.blocklyDisabled>.blocklyPath { + `.blocklyDisabled>.blocklyPath { fill-opacity: .5; stroke-opacity: .5; }`, -`.blocklyDisabled>.blocklyPathLight, + `.blocklyDisabled>.blocklyPathLight, .blocklyDisabled>.blocklyPathDark { display: none; }`, -`.blocklyInsertionMarker>.blocklyPath, + `.blocklyInsertionMarker>.blocklyPath, .blocklyInsertionMarker>.blocklyPathLight, .blocklyInsertionMarker>.blocklyPathDark { fill-opacity: .2; stroke: none; }`, -`.blocklyMultilineText { + `.blocklyMultilineText { font-family: monospace; }`, -`.blocklyNonEditableText>text { + `.blocklyNonEditableText>text { pointer-events: none; }`, -`.blocklyFlyout { + `.blocklyFlyout { position: absolute; z-index: 20; }`, -`.blocklyText text { + `.blocklyText text { cursor: default; }`, @@ -326,7 +326,7 @@ const CONTENT = [ Don't allow users to select text. It gets annoying when trying to drag a block and selected text moves instead. */ -`.blocklySvg text, + `.blocklySvg text, .blocklyBlockDragSurface text { user-select: none; -ms-user-select: none; @@ -334,39 +334,39 @@ const CONTENT = [ cursor: inherit; }`, -`.blocklyHidden { + `.blocklyHidden { display: none; }`, -`.blocklyFieldDropdown:not(.blocklyHidden) { + `.blocklyFieldDropdown:not(.blocklyHidden) { display: block; }`, -`.blocklyIconGroup { + `.blocklyIconGroup { cursor: default; }`, -`.blocklyIconGroup:not(:hover), + `.blocklyIconGroup:not(:hover), .blocklyIconGroupReadonly { opacity: .6; }`, -`.blocklyIconShape { + `.blocklyIconShape { fill: #00f; stroke: #fff; stroke-width: 1px; }`, -`.blocklyIconSymbol { + `.blocklyIconSymbol { fill: #fff; }`, -`.blocklyMinimalBody { + `.blocklyMinimalBody { margin: 0; padding: 0; }`, -`.blocklyHtmlInput { + `.blocklyHtmlInput { border: none; border-radius: 4px; height: 100%; @@ -382,107 +382,107 @@ const CONTENT = [ /* Edge and IE introduce a close icon when the input value is longer than a certain length. This affects our sizing calculations of the text input. Hiding the close icon to avoid that. */ -`.blocklyHtmlInput::-ms-clear { + `.blocklyHtmlInput::-ms-clear { display: none; }`, -`.blocklyMainBackground { + `.blocklyMainBackground { stroke-width: 1; stroke: #c6c6c6;', /* Equates to #ddd due to border being off-pixel. */ }`, -`.blocklyMutatorBackground { + `.blocklyMutatorBackground { fill: #fff; stroke: #ddd; stroke-width: 1; }`, -`.blocklyFlyoutBackground { + `.blocklyFlyoutBackground { fill: #ddd; fill-opacity: .8; }`, -`.blocklyMainWorkspaceScrollbar { + `.blocklyMainWorkspaceScrollbar { z-index: 20; }`, -`.blocklyFlyoutScrollbar { + `.blocklyFlyoutScrollbar { z-index: 30; }`, -`.blocklyScrollbarHorizontal, + `.blocklyScrollbarHorizontal, .blocklyScrollbarVertical { position: absolute; outline: none; }`, -`.blocklyScrollbarBackground { + `.blocklyScrollbarBackground { opacity: 0; }`, -`.blocklyScrollbarHandle { + `.blocklyScrollbarHandle { fill: #ccc; }`, -`.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, + `.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, .blocklyScrollbarHandle:hover { fill: #bbb; }`, /* Darken flyout scrollbars due to being on a grey background. */ /* By contrast, workspace scrollbars are on a white background. */ -`.blocklyFlyout .blocklyScrollbarHandle { + `.blocklyFlyout .blocklyScrollbarHandle { fill: #bbb; }`, -`.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, + `.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle, .blocklyFlyout .blocklyScrollbarHandle:hover { fill: #aaa; }`, -`.blocklyInvalidInput { + `.blocklyInvalidInput { background: #faa; }`, -`.blocklyVerticalMarker { + `.blocklyVerticalMarker { stroke-width: 3px; fill: rgba(255,255,255,.5); pointer-events: none; }`, -`.blocklyComputeCanvas { + `.blocklyComputeCanvas { position: absolute; width: 0; height: 0; }`, -`.blocklyNoPointerEvents { + `.blocklyNoPointerEvents { pointer-events: none; }`, -`.blocklyContextMenu { + `.blocklyContextMenu { border-radius: 4px; max-height: 100%; }`, -`.blocklyDropdownMenu { + `.blocklyDropdownMenu { border-radius: 2px; padding: 0 !important; }`, -`.blocklyDropdownMenu .blocklyMenuItem { + `.blocklyDropdownMenu .blocklyMenuItem { /* 28px on the left for icon or checkbox. */ padding-left: 28px; }`, /* BiDi override for the resting state. */ -`.blocklyDropdownMenu .blocklyMenuItemRtl { + `.blocklyDropdownMenu .blocklyMenuItemRtl { /* Flip left/right padding for BiDi. */ padding-left: 5px; padding-right: 28px; }`, -`.blocklyWidgetDiv .blocklyMenu { + `.blocklyWidgetDiv .blocklyMenu { background: #fff; border: 1px solid transparent; box-shadow: 0 0 3px 1px rgba(0,0,0,.3); @@ -497,11 +497,11 @@ const CONTENT = [ z-index: 20000;', /* Arbitrary, but some apps depend on it... */ }`, -`.blocklyWidgetDiv .blocklyMenu.blocklyFocused { + `.blocklyWidgetDiv .blocklyMenu.blocklyFocused { box-shadow: 0 0 6px 1px rgba(0,0,0,.3); }`, -`.blocklyDropDownDiv .blocklyMenu { + `.blocklyDropDownDiv .blocklyMenu { background: inherit;', /* Compatibility with gapi, reset from goog-menu */ border: inherit;', /* Compatibility with gapi, reset from goog-menu */ font: normal 13px "Helvetica Neue", Helvetica, sans-serif; @@ -511,7 +511,7 @@ const CONTENT = [ }`, /* State: resting. */ -`.blocklyMenuItem { + `.blocklyMenuItem { border: none; color: #000; cursor: pointer; @@ -524,34 +524,38 @@ const CONTENT = [ }`, /* State: disabled. */ -`.blocklyMenuItemDisabled { + `.blocklyMenuItemDisabled { color: #ccc; cursor: inherit; }`, /* State: hover. */ -`.blocklyMenuItemHighlight { + `.blocklyMenuItemHighlight { background-color: rgba(0,0,0,.1); }`, /* State: selected/checked. */ -`.blocklyMenuItemCheckbox { + `.blocklyMenuItemCheckbox { height: 16px; position: absolute; width: 16px; }`, -`.blocklyMenuItemSelected .blocklyMenuItemCheckbox { + `.blocklyMenuItemSelected .blocklyMenuItemCheckbox { background: url(<<>>/sprites.png) no-repeat -48px -16px; float: left; margin-left: -24px; position: static;', /* Scroll with the menu. */ }`, -`.blocklyMenuItemRtl .blocklyMenuItemCheckbox { + `.blocklyMenuItemRtl .blocklyMenuItemCheckbox { float: right; margin-right: -24px; }`, ]; -exports = {register, inject, CONTENT}; +exports = { + register, + inject, + CONTENT +}; From f80764e1537232c0903d7ba0b7694f2219fde92c Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 10:51:14 -0700 Subject: [PATCH 068/833] Migrate core/renderers/common/drawer.js to named requires --- core/renderers/common/drawer.js | 130 +++++++++++++++----------------- 1 file changed, 60 insertions(+), 70 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 4eca204a3..30018aae1 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,22 +13,22 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.RenderInfo'); -goog.require('Blockly.blockRendering.Row'); -goog.require('Blockly.blockRendering.Types'); -goog.require('Blockly.utils.svgPaths'); +const RenderInfo = goog.require('Blockly.blockRendering.RenderInfo'); +const Row = goog.require('Blockly.blockRendering.Row'); +const Types = goog.require('Blockly.blockRendering.Types'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.blockRendering.Field'); -goog.requireType('Blockly.blockRendering.Icon'); -goog.requireType('Blockly.blockRendering.InlineInput'); -goog.requireType('Blockly.BlockSvg'); +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +const Field = goog.requireType('Blockly.blockRendering.Field'); +const Icon = goog.requireType('Blockly.blockRendering.Icon'); +const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** * An object that draws a block based on the given rendering information. - * @param {!Blockly.BlockSvg} block The block to render. - * @param {!Blockly.blockRendering.RenderInfo} info An object containing all + * @param {!BlockSvg} block The block to render. + * @param {!RenderInfo} info An object containing all * information needed to render this block. * @package * @constructor @@ -42,7 +42,7 @@ const Drawer = function(block, info) { /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @protected */ this.constants_ = info.getRenderer().getConstants(); @@ -129,42 +129,41 @@ Drawer.prototype.drawTop_ = function() { const elements = topRow.elements; this.positionPreviousConnection_(); - this.outlinePath_ += - Blockly.utils.svgPaths.moveBy(topRow.xPos, this.info_.startY); + this.outlinePath_ += svgPaths.moveBy(topRow.xPos, this.info_.startY); for (let i = 0, elem; (elem = elements[i]); i++) { - if (Blockly.blockRendering.Types.isLeftRoundedCorner(elem)) { + if (Types.isLeftRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft; - } else if (Blockly.blockRendering.Types.isRightRoundedCorner(elem)) { + } else if (Types.isRightRoundedCorner(elem)) { this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topRight; - } else if (Blockly.blockRendering.Types.isPreviousConnection(elem)) { + } else if (Types.isPreviousConnection(elem)) { this.outlinePath_ += elem.shape.pathLeft; - } else if (Blockly.blockRendering.Types.isHat(elem)) { + } else if (Types.isHat(elem)) { this.outlinePath_ += this.constants_.START_HAT.path; - } else if (Blockly.blockRendering.Types.isSpacer(elem)) { - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('h', elem.width); + } else if (Types.isSpacer(elem)) { + this.outlinePath_ += svgPaths.lineOnAxis('h', elem.width); } // No branch for a square corner, because it's a no-op. } - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('v', topRow.height); + this.outlinePath_ += svgPaths.lineOnAxis('v', topRow.height); }; /** * Add steps for the jagged edge of a row on a collapsed block. - * @param {!Blockly.blockRendering.Row} row The row to draw the side of. + * @param {!Row} row The row to draw the side of. * @protected */ Drawer.prototype.drawJaggedEdge_ = function(row) { const remainder = row.height - this.constants_.JAGGED_TEETH.height; - this.outlinePath_ += this.constants_.JAGGED_TEETH.path + - Blockly.utils.svgPaths.lineOnAxis('v', remainder); + this.outlinePath_ += + this.constants_.JAGGED_TEETH.path + svgPaths.lineOnAxis('v', remainder); }; /** * Add steps for an external value input, rendered as a notch in the side * of the block. - * @param {!Blockly.blockRendering.Row} row The row that this input + * @param {!Row} row The row that this input * belongs to. * @protected */ @@ -176,16 +175,14 @@ Drawer.prototype.drawValueInput_ = function(row) { input.shape.pathDown(input.height) : input.shape.pathDown; - this.outlinePath_ += - Blockly.utils.svgPaths.lineOnAxis('H', input.xPos + input.width) + - pathDown + - Blockly.utils.svgPaths.lineOnAxis('v', row.height - input.connectionHeight); + this.outlinePath_ += svgPaths.lineOnAxis('H', input.xPos + input.width) + + pathDown + svgPaths.lineOnAxis('v', row.height - input.connectionHeight); }; /** * Add steps for a statement input. - * @param {!Blockly.blockRendering.Row} row The row that this input + * @param {!Row} row The row that this input * belongs to. * @protected */ @@ -195,17 +192,16 @@ Drawer.prototype.drawStatementInput_ = function(row) { const x = input.xPos + input.notchOffset + input.shape.width; const innerTopLeftCorner = input.shape.pathRight + - Blockly.utils.svgPaths.lineOnAxis( + svgPaths.lineOnAxis( 'h', -(input.notchOffset - this.constants_.INSIDE_CORNERS.width)) + this.constants_.INSIDE_CORNERS.pathTop; const innerHeight = row.height - (2 * this.constants_.INSIDE_CORNERS.height); - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('H', x) + - innerTopLeftCorner + - Blockly.utils.svgPaths.lineOnAxis('v', innerHeight) + + this.outlinePath_ += svgPaths.lineOnAxis('H', x) + innerTopLeftCorner + + svgPaths.lineOnAxis('v', innerHeight) + this.constants_.INSIDE_CORNERS.pathBottom + - Blockly.utils.svgPaths.lineOnAxis('H', row.xPos + row.width); + svgPaths.lineOnAxis('H', row.xPos + row.width); this.positionStatementInputConnection_(row); }; @@ -213,13 +209,12 @@ Drawer.prototype.drawStatementInput_ = function(row) { /** * Add steps for the right side of a row that does not have value or * statement input connections. - * @param {!Blockly.blockRendering.Row} row The row to draw the + * @param {!Row} row The row to draw the * side of. * @protected */ Drawer.prototype.drawRightSideRow_ = function(row) { - this.outlinePath_ += - Blockly.utils.svgPaths.lineOnAxis('V', row.yPos + row.height); + this.outlinePath_ += svgPaths.lineOnAxis('V', row.yPos + row.height); }; @@ -236,22 +231,22 @@ Drawer.prototype.drawBottom_ = function() { let rightCornerYOffset = 0; let outlinePath = ''; for (let i = elems.length - 1, elem; (elem = elems[i]); i--) { - if (Blockly.blockRendering.Types.isNextConnection(elem)) { + if (Types.isNextConnection(elem)) { outlinePath += elem.shape.pathRight; - } else if (Blockly.blockRendering.Types.isLeftSquareCorner(elem)) { - outlinePath += Blockly.utils.svgPaths.lineOnAxis('H', bottomRow.xPos); - } else if (Blockly.blockRendering.Types.isLeftRoundedCorner(elem)) { + } else if (Types.isLeftSquareCorner(elem)) { + outlinePath += svgPaths.lineOnAxis('H', bottomRow.xPos); + } else if (Types.isLeftRoundedCorner(elem)) { outlinePath += this.constants_.OUTSIDE_CORNERS.bottomLeft; - } else if (Blockly.blockRendering.Types.isRightRoundedCorner(elem)) { + } else if (Types.isRightRoundedCorner(elem)) { outlinePath += this.constants_.OUTSIDE_CORNERS.bottomRight; rightCornerYOffset = this.constants_.OUTSIDE_CORNERS.rightHeight; - } else if (Blockly.blockRendering.Types.isSpacer(elem)) { - outlinePath += Blockly.utils.svgPaths.lineOnAxis('h', elem.width * -1); + } else if (Types.isSpacer(elem)) { + outlinePath += svgPaths.lineOnAxis('h', elem.width * -1); } } - this.outlinePath_ += Blockly.utils.svgPaths.lineOnAxis('V', - bottomRow.baseline - rightCornerYOffset); + this.outlinePath_ += + svgPaths.lineOnAxis('V', bottomRow.baseline - rightCornerYOffset); this.outlinePath_ += outlinePath; }; @@ -272,9 +267,7 @@ Drawer.prototype.drawLeft_ = function() { outputConnection.shape.pathUp; // Draw a line up to the bottom of the tab. - this.outlinePath_ += - Blockly.utils.svgPaths.lineOnAxis('V', tabBottom) + - pathUp; + this.outlinePath_ += svgPaths.lineOnAxis('V', tabBottom) + pathUp; } // Close off the path. This draws a vertical line up to the start of the // block's path, which may be either a rounded or a sharp corner. @@ -289,13 +282,12 @@ Drawer.prototype.drawLeft_ = function() { Drawer.prototype.drawInternals_ = function() { for (let i = 0, row; (row = this.info_.rows[i]); i++) { for (let j = 0, elem; (elem = row.elements[j]); j++) { - if (Blockly.blockRendering.Types.isInlineInput(elem)) { + if (Types.isInlineInput(elem)) { this.drawInlineInput_( - /** @type {!Blockly.blockRendering.InlineInput} */ (elem)); - } else if (Blockly.blockRendering.Types.isIcon(elem) || - Blockly.blockRendering.Types.isField(elem)) { + /** @type {!InlineInput} */ (elem)); + } else if (Types.isIcon(elem) || Types.isField(elem)) { this.layoutField_( - /** @type {!Blockly.blockRendering.Field|!Blockly.blockRendering.Icon} */ + /** @type {!Field|!Icon} */ (elem)); } } @@ -304,15 +296,15 @@ Drawer.prototype.drawInternals_ = function() { /** * Push a field or icon's new position to its SVG root. - * @param {!Blockly.blockRendering.Icon|!Blockly.blockRendering.Field} fieldInfo + * @param {!Icon|!Field} fieldInfo * The rendering information for the field or icon. * @protected */ Drawer.prototype.layoutField_ = function(fieldInfo) { let svgGroup; - if (Blockly.blockRendering.Types.isField(fieldInfo)) { + if (Types.isField(fieldInfo)) { svgGroup = fieldInfo.field.getSvgRoot(); - } else if (Blockly.blockRendering.Types.isIcon(fieldInfo)) { + } else if (Types.isIcon(fieldInfo)) { svgGroup = fieldInfo.icon.iconGroup_; } @@ -326,7 +318,7 @@ Drawer.prototype.layoutField_ = function(fieldInfo) { scale = 'scale(-1 1)'; } } - if (Blockly.blockRendering.Types.isIcon(fieldInfo)) { + if (Types.isIcon(fieldInfo)) { svgGroup.setAttribute('display', 'block'); svgGroup.setAttribute('transform', 'translate(' + xPos + ',' + yPos + ')'); fieldInfo.icon.computeIconLocation(); @@ -344,7 +336,7 @@ Drawer.prototype.layoutField_ = function(fieldInfo) { /** * Add steps for an inline input. - * @param {!Blockly.blockRendering.InlineInput} input The information about the + * @param {!InlineInput} input The information about the * input to render. * @protected */ @@ -357,13 +349,11 @@ Drawer.prototype.drawInlineInput_ = function(input) { const connectionBottom = input.connectionHeight + connectionTop; const connectionRight = input.xPos + input.connectionWidth; - this.inlinePath_ += Blockly.utils.svgPaths.moveTo(connectionRight, yPos) + - Blockly.utils.svgPaths.lineOnAxis('v', connectionTop) + - input.shape.pathDown + - Blockly.utils.svgPaths.lineOnAxis('v', height - connectionBottom) + - Blockly.utils.svgPaths.lineOnAxis('h', width - input.connectionWidth) + - Blockly.utils.svgPaths.lineOnAxis('v', -height) + - 'z'; + this.inlinePath_ += svgPaths.moveTo(connectionRight, yPos) + + svgPaths.lineOnAxis('v', connectionTop) + input.shape.pathDown + + svgPaths.lineOnAxis('v', height - connectionBottom) + + svgPaths.lineOnAxis('h', width - input.connectionWidth) + + svgPaths.lineOnAxis('v', -height) + 'z'; this.positionInlineInputConnection_(input); }; @@ -372,7 +362,7 @@ Drawer.prototype.drawInlineInput_ = function(input) { * Position the connection on an inline value input, taking into account * RTL and the small gap between the parent block and child block which lets the * parent block's dark path show through. - * @param {Blockly.blockRendering.InlineInput} input The information about + * @param {InlineInput} input The information about * the input that the connection is on. * @protected */ @@ -394,7 +384,7 @@ Drawer.prototype.positionInlineInputConnection_ = function(input) { * Position the connection on a statement input, taking into account * RTL and the small gap between the parent block and child block which lets the * parent block's dark path show through. - * @param {!Blockly.blockRendering.Row} row The row that the connection is on. + * @param {!Row} row The row that the connection is on. * @protected */ Drawer.prototype.positionStatementInputConnection_ = function(row) { @@ -412,7 +402,7 @@ Drawer.prototype.positionStatementInputConnection_ = function(row) { * Position the connection on an external value input, taking into account * RTL and the small gap between the parent block and child block which lets the * parent block's dark path show through. - * @param {!Blockly.blockRendering.Row} row The row that the connection is on. + * @param {!Row} row The row that the connection is on. * @protected */ Drawer.prototype.positionExternalValueConnection_ = function(row) { From 7e74017342561048ece8520c9a1f0d316e69eb5d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 15 Jul 2021 16:12:10 -0700 Subject: [PATCH 069/833] Migrate core/connection_types.js to goog.module --- core/connection_types.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/connection_types.js b/core/connection_types.js index b2116812b..569ffc442 100644 --- a/core/connection_types.js +++ b/core/connection_types.js @@ -11,13 +11,14 @@ 'use strict'; -goog.provide('Blockly.connectionTypes'); +goog.module('Blockly.connectionTypes'); +goog.module.declareLegacyNamespace(); /** * Enum for the type of a connection or input. * @enum {number} */ -Blockly.connectionTypes = { +const connectionTypes = { // A right-facing value input. E.g. 'set item to' or 'return'. INPUT_VALUE: 1, // A left-facing value output. E.g. 'random fraction'. @@ -27,3 +28,5 @@ Blockly.connectionTypes = { // An up-facing block stack. E.g. 'break out of loop'. PREVIOUS_STATEMENT: 4 }; + +exports = connectionTypes; diff --git a/tests/deps.js b/tests/deps.js index a44954c4f..2e7e55bf8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -22,7 +22,7 @@ goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); -goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], []); +goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); From d2142a2e9ff17dd8f530e1fa8d97fbb967abc9f7 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 11:00:50 -0700 Subject: [PATCH 070/833] Clang-format core/renderers/common/drawer.js and remove unused require --- core/renderers/common/drawer.js | 25 ++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 30018aae1..a0181bf8f 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,7 +13,6 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); -const RenderInfo = goog.require('Blockly.blockRendering.RenderInfo'); const Row = goog.require('Blockly.blockRendering.Row'); const Types = goog.require('Blockly.blockRendering.Types'); const svgPaths = goog.require('Blockly.utils.svgPaths'); @@ -22,6 +21,7 @@ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvid const Field = goog.requireType('Blockly.blockRendering.Field'); const Icon = goog.requireType('Blockly.blockRendering.Icon'); const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); @@ -132,11 +132,9 @@ Drawer.prototype.drawTop_ = function() { this.outlinePath_ += svgPaths.moveBy(topRow.xPos, this.info_.startY); for (let i = 0, elem; (elem = elements[i]); i++) { if (Types.isLeftRoundedCorner(elem)) { - this.outlinePath_ += - this.constants_.OUTSIDE_CORNERS.topLeft; + this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topLeft; } else if (Types.isRightRoundedCorner(elem)) { - this.outlinePath_ += - this.constants_.OUTSIDE_CORNERS.topRight; + this.outlinePath_ += this.constants_.OUTSIDE_CORNERS.topRight; } else if (Types.isPreviousConnection(elem)) { this.outlinePath_ += elem.shape.pathLeft; } else if (Types.isHat(elem)) { @@ -163,8 +161,7 @@ Drawer.prototype.drawJaggedEdge_ = function(row) { /** * Add steps for an external value input, rendered as a notch in the side * of the block. - * @param {!Row} row The row that this input - * belongs to. + * @param {!Row} row The row that this input belongs to. * @protected */ Drawer.prototype.drawValueInput_ = function(row) { @@ -182,8 +179,7 @@ Drawer.prototype.drawValueInput_ = function(row) { /** * Add steps for a statement input. - * @param {!Row} row The row that this input - * belongs to. + * @param {!Row} row The row that this input belongs to. * @protected */ Drawer.prototype.drawStatementInput_ = function(row) { @@ -209,8 +205,7 @@ Drawer.prototype.drawStatementInput_ = function(row) { /** * Add steps for the right side of a row that does not have value or * statement input connections. - * @param {!Row} row The row to draw the - * side of. + * @param {!Row} row The row to draw the side of. * @protected */ Drawer.prototype.drawRightSideRow_ = function(row) { @@ -375,8 +370,8 @@ Drawer.prototype.positionInlineInputConnection_ = function(input) { if (this.info_.RTL) { connX *= -1; } - input.connectionModel.setOffsetInBlock(connX, - yPos + input.connectionOffsetY); + input.connectionModel.setOffsetInBlock( + connX, yPos + input.connectionOffsetY); } }; @@ -452,8 +447,8 @@ Drawer.prototype.positionOutputConnection_ = function() { if (this.info_.outputConnection) { const x = this.info_.startX + this.info_.outputConnection.connectionOffsetX; const connX = this.info_.RTL ? -x : x; - this.block_.outputConnection.setOffsetInBlock(connX, - this.info_.outputConnection.connectionOffsetY); + this.block_.outputConnection.setOffsetInBlock( + connX, this.info_.outputConnection.connectionOffsetY); } }; diff --git a/tests/deps.js b/tests/deps.js index 7cade6c4e..b0183d469 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -116,7 +116,7 @@ goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnec goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 8f5da9c41d6cedf9c334406e565b960218fb1605 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 10:55:04 -0700 Subject: [PATCH 071/833] Migrate core/component_manager.js to ES6 const/let --- core/component_manager.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index d8b215504..5d50dcf91 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -62,16 +62,16 @@ Blockly.ComponentManager.ComponentDatum; Blockly.ComponentManager.prototype.addComponent = function( componentInfo, opt_allowOverrides) { // Don't throw an error if opt_allowOverrides is true. - var id = componentInfo.component.id; + const id = componentInfo.component.id; if (!opt_allowOverrides && this.componentData_[id]) { throw Error( 'Plugin "' + id + '" with capabilities "' + this.componentData_[id].capabilities + '" already added.'); } this.componentData_[id] = componentInfo; - var stringCapabilities = []; - for (var i = 0; i < componentInfo.capabilities.length; i++) { - var capability = String(componentInfo.capabilities[i]).toLowerCase(); + const stringCapabilities = []; + for (let i = 0; i < componentInfo.capabilities.length; i++) { + const capability = String(componentInfo.capabilities[i]).toLowerCase(); stringCapabilities.push(capability); if (this.capabilityToComponentIds_[capability] === undefined) { this.capabilityToComponentIds_[capability] = [id]; @@ -87,12 +87,12 @@ Blockly.ComponentManager.prototype.addComponent = function( * @param {string} id The ID of the component to remove. */ Blockly.ComponentManager.prototype.removeComponent = function(id) { - var componentInfo = this.componentData_[id]; + const componentInfo = this.componentData_[id]; if (!componentInfo) { return; } - for (var i = 0; i < componentInfo.capabilities.length; i++) { - var capability = String(componentInfo.capabilities[i]).toLowerCase(); + for (let i = 0; i < componentInfo.capabilities.length; i++) { + const capability = String(componentInfo.capabilities[i]).toLowerCase(); this.capabilityToComponentIds_[capability].splice( this.capabilityToComponentIds_[capability].indexOf(id), 1); } @@ -178,14 +178,14 @@ Blockly.ComponentManager.prototype.getComponent = function(id) { */ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) { capability = String(capability).toLowerCase(); - var componentIds = this.capabilityToComponentIds_[capability]; + const componentIds = this.capabilityToComponentIds_[capability]; if (!componentIds) { return []; } - var components = []; + const components = []; if (sorted) { - var componentDataList = []; - var componentData = this.componentData_; + const componentDataList = []; + const componentData = this.componentData_; componentIds.forEach(function(id) { componentDataList.push(componentData[id]); }); @@ -196,7 +196,7 @@ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) components.push(ComponentDatum.component); }); } else { - var componentData = this.componentData_; + const componentData = this.componentData_; componentIds.forEach(function(id) { components.push(componentData[id].component); }); From 85b8ffce8ba56d04992850a68c8f8744d7adffec Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:06:05 -0700 Subject: [PATCH 072/833] Migrate core/component_manager.js to goog.module --- core/component_manager.js | 65 ++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index 5d50dcf91..fbf66d544 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ComponentManager'); +goog.module('Blockly.ComponentManager'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.IAutoHideable'); goog.requireType('Blockly.IComponent'); @@ -24,10 +25,10 @@ goog.requireType('Blockly.IPositionable'); * Manager for all items registered with the workspace. * @constructor */ -Blockly.ComponentManager = function() { +const ComponentManager = function() { /** * A map of the components registered with the workspace, mapped to id. - * @type {!Object} + * @type {!Object} * @private */ this.componentData_ = Object.create(null); @@ -45,21 +46,21 @@ Blockly.ComponentManager = function() { * @typedef {{ * component: !Blockly.IComponent, * capabilities: ( - * !Array> + * !Array> * ), * weight: number * }} */ -Blockly.ComponentManager.ComponentDatum; +ComponentManager.ComponentDatum; /** * Adds a component. - * @param {!Blockly.ComponentManager.ComponentDatum} componentInfo The data for + * @param {!ComponentManager.ComponentDatum} componentInfo The data for * the component to register. * @param {boolean=} opt_allowOverrides True to prevent an error when overriding * an already registered item. */ -Blockly.ComponentManager.prototype.addComponent = function( +ComponentManager.prototype.addComponent = function( componentInfo, opt_allowOverrides) { // Don't throw an error if opt_allowOverrides is true. const id = componentInfo.component.id; @@ -86,7 +87,7 @@ Blockly.ComponentManager.prototype.addComponent = function( * Removes a component. * @param {string} id The ID of the component to remove. */ -Blockly.ComponentManager.prototype.removeComponent = function(id) { +ComponentManager.prototype.removeComponent = function(id) { const componentInfo = this.componentData_[id]; if (!componentInfo) { return; @@ -102,11 +103,11 @@ Blockly.ComponentManager.prototype.removeComponent = function(id) { /** * Adds a capability to a existing registered component. * @param {string} id The ID of the component to add the capability to. - * @param {string|!Blockly.ComponentManager.Capability} capability The + * @param {string|!ComponentManager.Capability} capability The * capability to add. * @template T */ -Blockly.ComponentManager.prototype.addCapability = function(id, capability) { +ComponentManager.prototype.addCapability = function(id, capability) { if (!this.getComponent(id)) { throw Error('Cannot add capability, "' + capability + '". Plugin "' + id + '" has not been added to the ComponentManager'); @@ -124,11 +125,11 @@ Blockly.ComponentManager.prototype.addCapability = function(id, capability) { /** * Removes a capability from an existing registered component. * @param {string} id The ID of the component to remove the capability from. - * @param {string|!Blockly.ComponentManager.Capability} capability The + * @param {string|!ComponentManager.Capability} capability The * capability to remove. * @template T */ -Blockly.ComponentManager.prototype.removeCapability = function(id, capability) { +ComponentManager.prototype.removeCapability = function(id, capability) { if (!this.getComponent(id)) { throw Error('Cannot remove capability, "' + capability + '". Plugin "' + id + '" has not been added to the ComponentManager'); @@ -148,12 +149,12 @@ Blockly.ComponentManager.prototype.removeCapability = function(id, capability) { /** * Returns whether the component with this id has the specified capability. * @param {string} id The ID of the component to check. - * @param {string|!Blockly.ComponentManager.Capability} capability The + * @param {string|!ComponentManager.Capability} capability The * capability to check for. * @return {boolean} Whether the component has the capability. * @template T */ -Blockly.ComponentManager.prototype.hasCapability = function(id, capability) { +ComponentManager.prototype.hasCapability = function(id, capability) { capability = String(capability).toLowerCase(); return this.componentData_[id].capabilities.indexOf(capability) !== -1; }; @@ -164,19 +165,19 @@ Blockly.ComponentManager.prototype.hasCapability = function(id, capability) { * @return {!Blockly.IComponent|undefined} The component with the given name * or undefined if not found. */ -Blockly.ComponentManager.prototype.getComponent = function(id) { +ComponentManager.prototype.getComponent = function(id) { return this.componentData_[id] && this.componentData_[id].component; }; /** * Gets all the components with the specified capability. - * @param {string|!Blockly.ComponentManager.Capability + * @param {string|!ComponentManager.Capability * } capability The capability of the component. * @param {boolean} sorted Whether to return list ordered by weights. * @return {!Array} The components that match the specified capability. * @template T */ -Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) { +ComponentManager.prototype.getComponents = function(capability, sorted) { capability = String(capability).toLowerCase(); const componentIds = this.capabilityToComponentIds_[capability]; if (!componentIds) { @@ -210,7 +211,7 @@ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) * @constructor * @template T */ -Blockly.ComponentManager.Capability = function(name) { +ComponentManager.Capability = function(name) { /** * @type {string} * @private @@ -223,22 +224,24 @@ Blockly.ComponentManager.Capability = function(name) { * @return {string} The name. * @override */ -Blockly.ComponentManager.Capability.prototype.toString = function() { +ComponentManager.Capability.prototype.toString = function() { return this.name_; }; -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.POSITIONABLE = - new Blockly.ComponentManager.Capability('positionable'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.POSITIONABLE = + new ComponentManager.Capability('positionable'); -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.DRAG_TARGET = - new Blockly.ComponentManager.Capability('drag_target'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.DRAG_TARGET = + new ComponentManager.Capability('drag_target'); -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.DELETE_AREA = - new Blockly.ComponentManager.Capability('delete_area'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.DELETE_AREA = + new ComponentManager.Capability('delete_area'); -/** @type {!Blockly.ComponentManager.Capability} */ -Blockly.ComponentManager.Capability.AUTOHIDEABLE = - new Blockly.ComponentManager.Capability('autohideable'); +/** @type {!ComponentManager.Capability} */ +ComponentManager.Capability.AUTOHIDEABLE = + new ComponentManager.Capability('autohideable'); + +exports = ComponentManager; diff --git a/tests/deps.js b/tests/deps.js index 7baee6eb9..052655acd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -18,7 +18,7 @@ goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], [' goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []); +goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); From 3c5479e0009333190e9db8acb24f470796cf0dd1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:07:34 -0700 Subject: [PATCH 073/833] Migrate core/component_manager.js named requires --- core/component_manager.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index fbf66d544..cbc4baa60 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -14,11 +14,11 @@ goog.module('Blockly.ComponentManager'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.IAutoHideable'); -goog.requireType('Blockly.IComponent'); -goog.requireType('Blockly.IDeleteArea'); -goog.requireType('Blockly.IDragTarget'); -goog.requireType('Blockly.IPositionable'); +const IAutoHideable = goog.requireType('Blockly.IAutoHideable'); +const IComponent = goog.requireType('Blockly.IComponent'); +const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const IPositionable = goog.requireType('Blockly.IPositionable'); /** @@ -44,9 +44,9 @@ const ComponentManager = function() { /** * An object storing component information. * @typedef {{ - * component: !Blockly.IComponent, + * component: !IComponent, * capabilities: ( - * !Array> + * !Array> * ), * weight: number * }} @@ -162,7 +162,7 @@ ComponentManager.prototype.hasCapability = function(id, capability) { /** * Gets the component with the given ID. * @param {string} id The ID of the component to get. - * @return {!Blockly.IComponent|undefined} The component with the given name + * @return {!IComponent|undefined} The component with the given name * or undefined if not found. */ ComponentManager.prototype.getComponent = function(id) { @@ -228,19 +228,19 @@ ComponentManager.Capability.prototype.toString = function() { return this.name_; }; -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.POSITIONABLE = new ComponentManager.Capability('positionable'); -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.DRAG_TARGET = new ComponentManager.Capability('drag_target'); -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.DELETE_AREA = new ComponentManager.Capability('delete_area'); -/** @type {!ComponentManager.Capability} */ +/** @type {!ComponentManager.Capability} */ ComponentManager.Capability.AUTOHIDEABLE = new ComponentManager.Capability('autohideable'); From 81658d78ce82fcb2babb21a9d3cc19ea50183357 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:07:37 -0700 Subject: [PATCH 074/833] clang-format core/component_manager.js --- core/component_manager.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/component_manager.js b/core/component_manager.js index cbc4baa60..31b661e8a 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -109,12 +109,13 @@ ComponentManager.prototype.removeComponent = function(id) { */ ComponentManager.prototype.addCapability = function(id, capability) { if (!this.getComponent(id)) { - throw Error('Cannot add capability, "' + capability + '". Plugin "' + - id + '" has not been added to the ComponentManager'); + throw Error( + 'Cannot add capability, "' + capability + '". Plugin "' + id + + '" has not been added to the ComponentManager'); } if (this.hasCapability(id, capability)) { - console.warn('Plugin "' + id + 'already has capability "' + - capability + '"'); + console.warn( + 'Plugin "' + id + 'already has capability "' + capability + '"'); return; } capability = String(capability).toLowerCase(); @@ -131,12 +132,14 @@ ComponentManager.prototype.addCapability = function(id, capability) { */ ComponentManager.prototype.removeCapability = function(id, capability) { if (!this.getComponent(id)) { - throw Error('Cannot remove capability, "' + capability + '". Plugin "' + - id + '" has not been added to the ComponentManager'); + throw Error( + 'Cannot remove capability, "' + capability + '". Plugin "' + id + + '" has not been added to the ComponentManager'); } if (!this.hasCapability(id, capability)) { - console.warn('Plugin "' + id + 'doesn\'t have capability "' + - capability + '" to remove'); + console.warn( + 'Plugin "' + id + 'doesn\'t have capability "' + capability + + '" to remove'); return; } capability = String(capability).toLowerCase(); From a9e60851ef87625f915a1fe33da6cb5b909f313a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 11:49:35 -0700 Subject: [PATCH 075/833] Auto-tag and add milestones for cleanup PRs For new pull requests against the goog_module branch, adds the 'type: cleanup' label and sets the milestone to q3 2021 release. Based on [this PR](https://github.com/eclipse-theia/theia/pull/8631/files). --- .github/workflows/tag_module_cleanup.yml | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/tag_module_cleanup.yml diff --git a/.github/workflows/tag_module_cleanup.yml b/.github/workflows/tag_module_cleanup.yml new file mode 100644 index 000000000..8ee344066 --- /dev/null +++ b/.github/workflows/tag_module_cleanup.yml @@ -0,0 +1,34 @@ +# For new pull requests against the goog_module branch, adds the 'type: cleanup' +# label and sets the milestone to q3 2021 release. + +name: Tag module cleanup + +# Trigger on pull requests against goog_module branch only +on: + pull_request: + branches: + - goog_module + +jobs: + tag-module-cleanup: + + # Add the type: cleanup label + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@a3e7071 + with: + script: | + // 2021 q3 release milestone. + // https://github.com/google/blockly/milestone/18 + const milestoneNumber = 18; + // Note that pull requests are accessed through the issues API. + const issuesUpdateParams = { + owner: context.repo.owner, + repo: context.repo.repo, + // Adds the milestone + milestone: milestoneNumber, + issue_number: context.issue.number, + // Sets the labels + labels: ['type: cleanup'] + } + await github.issues.update(issuesUpdateParams) From 05f8c27302718a89136532b57d18e87557542bcb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 11:52:38 -0700 Subject: [PATCH 076/833] Use full commit hash. --- .github/workflows/tag_module_cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag_module_cleanup.yml b/.github/workflows/tag_module_cleanup.yml index 8ee344066..2b14426ad 100644 --- a/.github/workflows/tag_module_cleanup.yml +++ b/.github/workflows/tag_module_cleanup.yml @@ -15,7 +15,7 @@ jobs: # Add the type: cleanup label runs-on: ubuntu-latest steps: - - uses: actions/github-script@a3e7071 + - uses: actions/github-script@a3e7071a34d7e1f219a8a4de9a5e0a34d1ee1293 with: script: | // 2021 q3 release milestone. From fb7bba34916a184761f365d92fbcbbe984f67acc Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 15:56:05 -0700 Subject: [PATCH 077/833] Migrate core/utils/coordinate.js to ES6 const/let --- core/utils/coordinate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/coordinate.js b/core/utils/coordinate.js index edf513b28..da50f2623 100644 --- a/core/utils/coordinate.js +++ b/core/utils/coordinate.js @@ -63,8 +63,8 @@ Blockly.utils.Coordinate.equals = function(a, b) { * @return {number} The distance between `a` and `b`. */ Blockly.utils.Coordinate.distance = function(a, b) { - var dx = a.x - b.x; - var dy = a.y - b.y; + const dx = a.x - b.x; + const dy = a.y - b.y; return Math.sqrt(dx * dx + dy * dy); }; From 972f3022ed29dc52f3ebe3d4194d8ae3f396ebd1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 13 Jul 2021 18:37:28 -0700 Subject: [PATCH 078/833] Migrate core/utils/coordinate.js to goog.module --- core/utils/coordinate.js | 62 +++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/core/utils/coordinate.js b/core/utils/coordinate.js index da50f2623..ca5a248d3 100644 --- a/core/utils/coordinate.js +++ b/core/utils/coordinate.js @@ -16,8 +16,8 @@ * @name Blockly.utils.Coordinate * @namespace */ -goog.provide('Blockly.utils.Coordinate'); - +goog.module('Blockly.utils.Coordinate'); +goog.module.declareLegacyNamespace(); /** * Class for representing coordinates and positions. @@ -26,7 +26,7 @@ goog.provide('Blockly.utils.Coordinate'); * @struct * @constructor */ -Blockly.utils.Coordinate = function(x, y) { +const Coordinate = function(x, y) { /** * X-value * @type {number} @@ -42,11 +42,11 @@ Blockly.utils.Coordinate = function(x, y) { /** * Compares coordinates for equality. - * @param {?Blockly.utils.Coordinate} a A Coordinate. - * @param {?Blockly.utils.Coordinate} b A Coordinate. + * @param {?Coordinate} a A Coordinate. + * @param {?Coordinate} b A Coordinate. * @return {boolean} True iff the coordinates are equal, or if both are null. */ -Blockly.utils.Coordinate.equals = function(a, b) { +Coordinate.equals = function(a, b) { if (a == b) { return true; } @@ -58,11 +58,11 @@ Blockly.utils.Coordinate.equals = function(a, b) { /** * Returns the distance between two coordinates. - * @param {!Blockly.utils.Coordinate} a A Coordinate. - * @param {!Blockly.utils.Coordinate} b A Coordinate. + * @param {!Coordinate} a A Coordinate. + * @param {!Coordinate} b A Coordinate. * @return {number} The distance between `a` and `b`. */ -Blockly.utils.Coordinate.distance = function(a, b) { +Coordinate.distance = function(a, b) { const dx = a.x - b.x; const dy = a.y - b.y; return Math.sqrt(dx * dx + dy * dy); @@ -70,50 +70,50 @@ Blockly.utils.Coordinate.distance = function(a, b) { /** * Returns the magnitude of a coordinate. - * @param {!Blockly.utils.Coordinate} a A Coordinate. + * @param {!Coordinate} a A Coordinate. * @return {number} The distance between the origin and `a`. */ -Blockly.utils.Coordinate.magnitude = function(a) { +Coordinate.magnitude = function(a) { return Math.sqrt(a.x * a.x + a.y * a.y); }; /** * Returns the difference between two coordinates as a new - * Blockly.utils.Coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Blockly.utils.Coordinate} A Coordinate representing the difference + * Coordinate. + * @param {!Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Coordinate} A Coordinate representing the difference * between `a` and `b`. */ -Blockly.utils.Coordinate.difference = function(a, b) { - return new Blockly.utils.Coordinate(a.x - b.x, a.y - b.y); +Coordinate.difference = function(a, b) { + return new Coordinate(a.x - b.x, a.y - b.y); }; /** - * Returns the sum of two coordinates as a new Blockly.utils.Coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate. - * @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate. - * @return {!Blockly.utils.Coordinate} A Coordinate representing the sum of + * Returns the sum of two coordinates as a new Coordinate. + * @param {!Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Coordinate} A Coordinate representing the sum of * the two coordinates. */ -Blockly.utils.Coordinate.sum = function(a, b) { - return new Blockly.utils.Coordinate(a.x + b.x, a.y + b.y); +Coordinate.sum = function(a, b) { + return new Coordinate(a.x + b.x, a.y + b.y); }; /** * Creates a new copy of this coordinate. - * @return {!Blockly.utils.Coordinate} A copy of this coordinate. + * @return {!Coordinate} A copy of this coordinate. */ -Blockly.utils.Coordinate.prototype.clone = function() { - return new Blockly.utils.Coordinate(this.x, this.y); +Coordinate.prototype.clone = function() { + return new Coordinate(this.x, this.y); }; /** * Scales this coordinate by the given scale factor. * @param {number} s The scale factor to use for both x and y dimensions. - * @return {!Blockly.utils.Coordinate} This coordinate after scaling. + * @return {!Coordinate} This coordinate after scaling. */ -Blockly.utils.Coordinate.prototype.scale = function(s) { +Coordinate.prototype.scale = function(s) { this.x *= s; this.y *= s; return this; @@ -124,10 +124,12 @@ Blockly.utils.Coordinate.prototype.scale = function(s) { * respectively. * @param {number} tx The value to translate x by. * @param {number} ty The value to translate y by. - * @return {!Blockly.utils.Coordinate} This coordinate after translating. + * @return {!Coordinate} This coordinate after translating. */ -Blockly.utils.Coordinate.prototype.translate = function(tx, ty) { +Coordinate.prototype.translate = function(tx, ty) { this.x += tx; this.y += ty; return this; }; + +exports = Coordinate; diff --git a/tests/deps.js b/tests/deps.js index 052655acd..c9321eaf9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -171,7 +171,7 @@ goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.Com goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], []); +goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/dom.js', ['Blockly.utils.dom'], ['Blockly.utils.Svg', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []); From 19e86ed5dbca92be79e9d6de17454922b5e7d22c Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:52:13 -0700 Subject: [PATCH 079/833] Migrate core/interfaces/i_block_dragger.js to goog.module --- core/interfaces/i_block_dragger.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index ec7b79ac6..2276c7459 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IBlockDragger'); +goog.module('Blockly.IBlockDragger'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.utils.Coordinate'); @@ -21,7 +22,7 @@ goog.requireType('Blockly.utils.Coordinate'); * A block dragger interface. * @interface */ -Blockly.IBlockDragger = function() {}; +const IBlockDragger = function() {}; /** * Start dragging a block. This includes moving it to the drag surface. @@ -30,7 +31,7 @@ Blockly.IBlockDragger = function() {}; * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. */ -Blockly.IBlockDragger.prototype.startDrag; +IBlockDragger.prototype.startDrag; /** * Execute a step of block dragging, based on the given event. Update the @@ -39,7 +40,7 @@ Blockly.IBlockDragger.prototype.startDrag; * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. */ -Blockly.IBlockDragger.prototype.drag; +IBlockDragger.prototype.drag; /** * Finish a block drag and put the block back on the workspace. @@ -47,7 +48,7 @@ Blockly.IBlockDragger.prototype.drag; * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. */ -Blockly.IBlockDragger.prototype.endDrag; +IBlockDragger.prototype.endDrag; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, @@ -55,4 +56,6 @@ Blockly.IBlockDragger.prototype.endDrag; * @return {!Array.} A possibly empty list of insertion * marker blocks. */ -Blockly.IBlockDragger.prototype.getInsertionMarkers; +IBlockDragger.prototype.getInsertionMarkers; + +exports = IBlockDragger; diff --git a/tests/deps.js b/tests/deps.js index c9321eaf9..5a06dd4ae 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -75,7 +75,7 @@ goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockl goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); -goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], []); +goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], []); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], []); From 88525f5ab4aeb0d4ddef54b2f7aba6b67c42eab0 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:54:26 -0700 Subject: [PATCH 080/833] Migrate core/interfaces/i_block_dragger.js named requires --- core/interfaces/i_block_dragger.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index 2276c7459..ebfc820ba 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -14,8 +14,8 @@ goog.module('Blockly.IBlockDragger'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); /** @@ -26,7 +26,7 @@ const IBlockDragger = function() {}; /** * Start dragging a block. This includes moving it to the drag surface. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. @@ -37,7 +37,7 @@ IBlockDragger.prototype.startDrag; * Execute a step of block dragging, based on the given event. Update the * display accordingly. * @param {!Event} e The most recent move event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. */ IBlockDragger.prototype.drag; @@ -45,7 +45,7 @@ IBlockDragger.prototype.drag; /** * Finish a block drag and put the block back on the workspace. * @param {!Event} e The mouseup/touchend event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. */ IBlockDragger.prototype.endDrag; @@ -53,7 +53,7 @@ IBlockDragger.prototype.endDrag; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, * or 2 insertion markers. - * @return {!Array.} A possibly empty list of insertion + * @return {!Array.} A possibly empty list of insertion * marker blocks. */ IBlockDragger.prototype.getInsertionMarkers; From e922d2a831ea76bcf1c2ddc10f3ad3f2ce8e12a9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:05:21 -0700 Subject: [PATCH 081/833] Migrate core/interfaces/i_bounded_element.js to goog.module --- core/interfaces/i_bounded_element.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index bc5ffeee6..fdbeb5b99 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IBoundedElement'); +goog.module('Blockly.IBoundedElement'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.utils.Rect'); @@ -20,7 +21,7 @@ goog.requireType('Blockly.utils.Rect'); * A bounded element interface. * @interface */ -Blockly.IBoundedElement = function() {}; +const IBoundedElement = function() {}; /** * Returns the coordinates of a bounded element describing the dimensions of the @@ -28,11 +29,13 @@ Blockly.IBoundedElement = function() {}; * Coordinate system: workspace coordinates. * @return {!Blockly.utils.Rect} Object with coordinates of the bounded element. */ -Blockly.IBoundedElement.prototype.getBoundingRectangle; +IBoundedElement.prototype.getBoundingRectangle; /** * Move the element by a relative offset. * @param {number} dx Horizontal offset in workspace units. * @param {number} dy Vertical offset in workspace units. */ -Blockly.IBoundedElement.prototype.moveBy; +IBoundedElement.prototype.moveBy; + +exports = IBoundedElement; diff --git a/tests/deps.js b/tests/deps.js index 5a06dd4ae..ac9153ec9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -76,7 +76,7 @@ goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.Insertion goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], []); +goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], []); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); From bfc801ed9f9baa9ff37894dea9ecf88a7fdb2cd1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:05:45 -0700 Subject: [PATCH 082/833] Migrate core/interfaces/i_bounded_element.js named requires --- core/interfaces/i_bounded_element.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index fdbeb5b99..461d52ca1 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -14,7 +14,7 @@ goog.module('Blockly.IBoundedElement'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.utils.Rect'); +const Rect = goog.requireType('Blockly.utils.Rect'); /** @@ -27,7 +27,7 @@ const IBoundedElement = function() {}; * Returns the coordinates of a bounded element describing the dimensions of the * element. * Coordinate system: workspace coordinates. - * @return {!Blockly.utils.Rect} Object with coordinates of the bounded element. + * @return {!Rect} Object with coordinates of the bounded element. */ IBoundedElement.prototype.getBoundingRectangle; From 4ab9380434d6a435c65a8adcf46d48d5e90fd5f6 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:33:07 -0700 Subject: [PATCH 083/833] Migrate core/interfaces/i_component.js to goog.module --- core/interfaces/i_component.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_component.js b/core/interfaces/i_component.js index efb195966..d1acc592f 100644 --- a/core/interfaces/i_component.js +++ b/core/interfaces/i_component.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IComponent'); +goog.module('Blockly.IComponent'); +goog.module.declareLegacyNamespace(); /** @@ -20,11 +21,13 @@ goog.provide('Blockly.IComponent'); * ComponentManager. * @interface */ -Blockly.IComponent = function() {}; +const IComponent = function() {}; /** * The unique id for this component that is used to register with the * ComponentManager. * @type {string} */ -Blockly.IComponent.id; +IComponent.id; + +exports = IComponent; diff --git a/tests/deps.js b/tests/deps.js index ac9153ec9..ed2af0dc9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -78,7 +78,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); -goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], []); +goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); From 218046495f052fb7400f7afb736e52bfa0626618 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 13:12:05 -0700 Subject: [PATCH 084/833] Sort requires --- core/renderers/common/drawer.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index a0181bf8f..9504695a2 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,16 +13,15 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); -const Row = goog.require('Blockly.blockRendering.Row'); -const Types = goog.require('Blockly.blockRendering.Types'); -const svgPaths = goog.require('Blockly.utils.svgPaths'); - +const BlockSvg = goog.requireType('Blockly.BlockSvg'); const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); const Field = goog.requireType('Blockly.blockRendering.Field'); const Icon = goog.requireType('Blockly.blockRendering.Icon'); const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); -const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Row = goog.require('Blockly.blockRendering.Row'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); +const Types = goog.require('Blockly.blockRendering.Types'); /** From a2d12a1536a1cf223bab1ba40a4f1027b41c5263 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:00:31 -0700 Subject: [PATCH 085/833] Migrate core/interfaces/i_deletable.js to goog.module --- core/interfaces/i_deletable.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_deletable.js b/core/interfaces/i_deletable.js index 8e8524863..ff24023d9 100644 --- a/core/interfaces/i_deletable.js +++ b/core/interfaces/i_deletable.js @@ -11,17 +11,20 @@ 'use strict'; -goog.provide('Blockly.IDeletable'); +goog.module('Blockly.IDeletable'); +goog.module.declareLegacyNamespace(); /** * The interface for an object that can be deleted. * @interface */ -Blockly.IDeletable = function() {}; +const IDeletable = function() {}; /** * Get whether this object is deletable or not. * @return {boolean} True if deletable. */ -Blockly.IDeletable.prototype.isDeletable; +IDeletable.prototype.isDeletable; + +exports = IDeletable; diff --git a/tests/deps.js b/tests/deps.js index ed2af0dc9..5ab286fc5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -82,7 +82,7 @@ goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent' goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); -goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], []); +goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget']); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); From fa158d143ec4f74a759557b232ae9d959401e122 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:48:33 -0700 Subject: [PATCH 086/833] Migrate core/connection.js to ES6 const/let --- core/connection.js | 82 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/core/connection.js b/core/connection.js index 27526c711..23d2193bd 100644 --- a/core/connection.js +++ b/core/connection.js @@ -104,10 +104,10 @@ Blockly.Connection.prototype.y = 0; * @protected */ Blockly.Connection.prototype.connect_ = function(childConnection) { - var INPUT = Blockly.connectionTypes.INPUT_VALUE; - var parentConnection = this; - var parentBlock = parentConnection.getSourceBlock(); - var childBlock = childConnection.getSourceBlock(); + const INPUT = Blockly.connectionTypes.INPUT_VALUE; + const parentConnection = this; + const parentBlock = parentConnection.getSourceBlock(); + const childBlock = childConnection.getSourceBlock(); // Make sure the childConnection is available. if (childConnection.isConnected()) { @@ -115,11 +115,11 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { } // Make sure the parentConnection is available. - var orphan; + let orphan; if (parentConnection.isConnected()) { - var shadowDom = parentConnection.getShadowDom(true); + const shadowDom = parentConnection.getShadowDom(true); parentConnection.shadowDom_ = null; // Set to null so it doesn't respawn. - var target = parentConnection.targetBlock(); + const target = parentConnection.targetBlock(); if (target.isShadow()) { target.dispose(false); } else { @@ -130,7 +130,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { } // Connect the new connection to the parent. - var event; + let event; if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } @@ -143,9 +143,9 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { // Deal with the orphan if it exists. if (orphan) { - var orphanConnection = parentConnection.type === INPUT ? + const orphanConnection = parentConnection.type === INPUT ? orphan.outputConnection : orphan.previousConnection; - var connection = Blockly.Connection.getConnectionForOrphanedConnection( + const connection = Blockly.Connection.getConnectionForOrphanedConnection( childBlock, /** @type {!Blockly.Connection} */ (orphanConnection)); if (connection) { orphanConnection.connect(connection); @@ -167,7 +167,7 @@ Blockly.Connection.prototype.dispose = function() { // Destroy the attached shadow block & its children (if it exists). this.setShadowDom(null); - var targetBlock = this.targetBlock(); + const targetBlock = this.targetBlock(); if (targetBlock) { // Disconnect the attached normal block. targetBlock.unplug(); @@ -236,8 +236,8 @@ Blockly.Connection.prototype.checkConnection = function(target) { 'July 2020', 'July 2021', 'the workspace\'s connection checker'); - var checker = this.getConnectionChecker(); - var reason = checker.canConnectWithReason(this, target, false); + const checker = this.getConnectionChecker(); + const reason = checker.canConnectWithReason(this, target, false); if (reason != Blockly.Connection.CAN_CONNECT) { throw new Error(checker.getErrorMessage(reason, this, target)); } @@ -290,9 +290,9 @@ Blockly.Connection.prototype.connect = function(otherConnection) { return; } - var checker = this.getConnectionChecker(); + const checker = this.getConnectionChecker(); if (checker.canConnect(this, otherConnection, false)) { - var eventGroup = Blockly.Events.getGroup(); + const eventGroup = Blockly.Events.getGroup(); if (!eventGroup) { Blockly.Events.setGroup(true); } @@ -336,12 +336,12 @@ Blockly.Connection.connectReciprocally_ = function(first, second) { * @private */ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { - var foundConnection = null; - var output = orphanBlock.outputConnection; - var typeChecker = output.getConnectionChecker(); + let foundConnection = null; + const output = orphanBlock.outputConnection; + const typeChecker = output.getConnectionChecker(); - for (var i = 0, input; (input = block.inputList[i]); i++) { - var connection = input.connection; + for (let i = 0, input; (input = block.inputList[i]); i++) { + const connection = input.connection; if (connection && typeChecker.canConnect(output, connection, false)) { if (foundConnection) { return null; // More than one connection. @@ -366,8 +366,8 @@ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { */ Blockly.Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { - var newBlock = startBlock; - var connection; + let newBlock = startBlock; + let connection; while ((connection = Blockly.Connection.getSingleConnection_( /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); @@ -395,8 +395,8 @@ Blockly.Connection.getConnectionForOrphanedConnection = startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. - var connection = startBlock.lastConnectionInStack(true); - var checker = orphanConnection.getConnectionChecker(); + const connection = startBlock.lastConnectionInStack(true); + const checker = orphanConnection.getConnectionChecker(); if (connection && checker.canConnect(orphanConnection, connection, false)) { return connection; @@ -408,14 +408,14 @@ Blockly.Connection.getConnectionForOrphanedConnection = * Disconnect this connection. */ Blockly.Connection.prototype.disconnect = function() { - var otherConnection = this.targetConnection; + const otherConnection = this.targetConnection; if (!otherConnection) { throw Error('Source connection not connected.'); } if (otherConnection.targetConnection != this) { throw Error('Target connection not connected to source connection.'); } - var parentBlock, childBlock, parentConnection; + let parentBlock, childBlock, parentConnection; if (this.isSuperior()) { // Superior block. parentBlock = this.sourceBlock_; @@ -428,7 +428,7 @@ Blockly.Connection.prototype.disconnect = function() { parentConnection = otherConnection; } - var eventGroup = Blockly.Events.getGroup(); + const eventGroup = Blockly.Events.getGroup(); if (!eventGroup) { Blockly.Events.setGroup(true); } @@ -450,11 +450,11 @@ Blockly.Connection.prototype.disconnect = function() { */ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { - var event; + let event; if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } - var otherConnection = this.targetConnection; + const otherConnection = this.targetConnection; otherConnection.targetConnection = null; this.targetConnection = null; childBlock.setParent(null); @@ -469,10 +469,10 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, * @protected */ Blockly.Connection.prototype.respawnShadow_ = function() { - var parentBlock = this.getSourceBlock(); - var shadow = this.getShadowDom(); + const parentBlock = this.getSourceBlock(); + const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { - var blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); + const blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); if (blockShadow.outputConnection) { this.connect(blockShadow.outputConnection); } else if (blockShadow.previousConnection) { @@ -540,7 +540,7 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( this, this.targetConnection, false))) { - var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; + const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); } }; @@ -582,7 +582,7 @@ Blockly.Connection.prototype.getCheck = function() { */ Blockly.Connection.prototype.setShadowDom = function(shadow) { this.shadowDom_ = shadow; - var target = this.targetBlock(); + const target = this.targetBlock(); if (!target) { this.respawnShadow_(); } else if (target.isShadow()) { @@ -630,9 +630,9 @@ Blockly.Connection.prototype.neighbours = function(_maxLimit) { * @package */ Blockly.Connection.prototype.getParentInput = function() { - var parentInput = null; - var inputs = this.sourceBlock_.inputList; - for (var i = 0; i < inputs.length; i++) { + let parentInput = null; + const inputs = this.sourceBlock_.inputList; + for (let i = 0; i < inputs.length; i++) { if (inputs[i].connection === this) { parentInput = inputs[i]; break; @@ -647,11 +647,11 @@ Blockly.Connection.prototype.getParentInput = function() { * @return {string} The description. */ Blockly.Connection.prototype.toString = function() { - var block = this.sourceBlock_; + const block = this.sourceBlock_; if (!block) { return 'Orphan Connection'; } - var msg; + let msg; if (block.outputConnection == this) { msg = 'Output Connection of '; } else if (block.previousConnection == this) { @@ -659,8 +659,8 @@ Blockly.Connection.prototype.toString = function() { } else if (block.nextConnection == this) { msg = 'Next Connection of '; } else { - var parentInput = null; - for (var i = 0, input; (input = block.inputList[i]); i++) { + let parentInput = null; + for (let i = 0, input; (input = block.inputList[i]); i++) { if (input.connection == this) { parentInput = input; break; From fc62fed33c94564449d521644bc0d44dbca739f9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:55:08 -0700 Subject: [PATCH 087/833] Migrate core/connection.js to goog.module --- core/connection.js | 141 +++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 73 insertions(+), 70 deletions(-) diff --git a/core/connection.js b/core/connection.js index 23d2193bd..be9a08eb9 100644 --- a/core/connection.js +++ b/core/connection.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Connection'); +goog.module('Blockly.Connection'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ @@ -34,7 +35,7 @@ goog.requireType('Blockly.Input'); * @constructor * @implements {Blockly.IASTNodeLocationWithBlock} */ -Blockly.Connection = function(source, type) { +const Connection = function(source, type) { /** * @type {!Blockly.Block} * @protected @@ -47,63 +48,63 @@ Blockly.Connection = function(source, type) { /** * Constants for checking whether two connections are compatible. */ -Blockly.Connection.CAN_CONNECT = 0; -Blockly.Connection.REASON_SELF_CONNECTION = 1; -Blockly.Connection.REASON_WRONG_TYPE = 2; -Blockly.Connection.REASON_TARGET_NULL = 3; -Blockly.Connection.REASON_CHECKS_FAILED = 4; -Blockly.Connection.REASON_DIFFERENT_WORKSPACES = 5; -Blockly.Connection.REASON_SHADOW_PARENT = 6; -Blockly.Connection.REASON_DRAG_CHECKS_FAILED = 7; +Connection.CAN_CONNECT = 0; +Connection.REASON_SELF_CONNECTION = 1; +Connection.REASON_WRONG_TYPE = 2; +Connection.REASON_TARGET_NULL = 3; +Connection.REASON_CHECKS_FAILED = 4; +Connection.REASON_DIFFERENT_WORKSPACES = 5; +Connection.REASON_SHADOW_PARENT = 6; +Connection.REASON_DRAG_CHECKS_FAILED = 7; /** * Connection this connection connects to. Null if not connected. - * @type {Blockly.Connection} + * @type {Connection} */ -Blockly.Connection.prototype.targetConnection = null; +Connection.prototype.targetConnection = null; /** * Has this connection been disposed of? * @type {boolean} * @package */ -Blockly.Connection.prototype.disposed = false; +Connection.prototype.disposed = false; /** * List of compatible value types. Null if all types are compatible. * @type {Array} * @private */ -Blockly.Connection.prototype.check_ = null; +Connection.prototype.check_ = null; /** * DOM representation of a shadow block, or null if none. * @type {Element} * @private */ -Blockly.Connection.prototype.shadowDom_ = null; +Connection.prototype.shadowDom_ = null; /** * Horizontal location of this connection. * @type {number} * @package */ -Blockly.Connection.prototype.x = 0; +Connection.prototype.x = 0; /** * Vertical location of this connection. * @type {number} * @package */ -Blockly.Connection.prototype.y = 0; +Connection.prototype.y = 0; /** * Connect two connections together. This is the connection on the superior * block. - * @param {!Blockly.Connection} childConnection Connection on inferior block. + * @param {!Connection} childConnection Connection on inferior block. * @protected */ -Blockly.Connection.prototype.connect_ = function(childConnection) { +Connection.prototype.connect_ = function(childConnection) { const INPUT = Blockly.connectionTypes.INPUT_VALUE; const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); @@ -134,7 +135,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { if (Blockly.Events.isEnabled()) { event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); } - Blockly.Connection.connectReciprocally_(parentConnection, childConnection); + Connection.connectReciprocally_(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); @@ -145,8 +146,8 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { if (orphan) { const orphanConnection = parentConnection.type === INPUT ? orphan.outputConnection : orphan.previousConnection; - const connection = Blockly.Connection.getConnectionForOrphanedConnection( - childBlock, /** @type {!Blockly.Connection} */ (orphanConnection)); + const connection = Connection.getConnectionForOrphanedConnection( + childBlock, /** @type {!Connection} */ (orphanConnection)); if (connection) { orphanConnection.connect(connection); } else { @@ -160,7 +161,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { * Dispose of this connection and deal with connected blocks. * @package */ -Blockly.Connection.prototype.dispose = function() { +Connection.prototype.dispose = function() { // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { @@ -181,7 +182,7 @@ Blockly.Connection.prototype.dispose = function() { * Get the source block for this connection. * @return {!Blockly.Block} The source block. */ -Blockly.Connection.prototype.getSourceBlock = function() { +Connection.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -189,7 +190,7 @@ Blockly.Connection.prototype.getSourceBlock = function() { * Does the connection belong to a superior block (higher in the source stack)? * @return {boolean} True if connection faces down or right. */ -Blockly.Connection.prototype.isSuperior = function() { +Connection.prototype.isSuperior = function() { return this.type == Blockly.connectionTypes.INPUT_VALUE || this.type == Blockly.connectionTypes.NEXT_STATEMENT; }; @@ -198,20 +199,20 @@ Blockly.Connection.prototype.isSuperior = function() { * Is the connection connected? * @return {boolean} True if connection is connected to another connection. */ -Blockly.Connection.prototype.isConnected = function() { +Connection.prototype.isConnected = function() { return !!this.targetConnection; }; /** * Checks whether the current connection can connect with the target * connection. - * @param {Blockly.Connection} target Connection to check compatibility with. - * @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal, + * @param {Connection} target Connection to check compatibility with. + * @return {number} Connection.CAN_CONNECT if the connection is legal, * an error code otherwise. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.canConnectWithReason = function(target) { +Connection.prototype.canConnectWithReason = function(target) { Blockly.utils.deprecation.warn( 'Connection.prototype.canConnectWithReason', 'July 2020', @@ -224,13 +225,13 @@ Blockly.Connection.prototype.canConnectWithReason = function(target) { /** * Checks whether the current connection and target connection are compatible * and throws an exception if they are not. - * @param {Blockly.Connection} target The connection to check compatibility + * @param {Connection} target The connection to check compatibility * with. * @package * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.checkConnection = function(target) { +Connection.prototype.checkConnection = function(target) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkConnection', 'July 2020', @@ -238,7 +239,7 @@ Blockly.Connection.prototype.checkConnection = function(target) { 'the workspace\'s connection checker'); const checker = this.getConnectionChecker(); const reason = checker.canConnectWithReason(this, target, false); - if (reason != Blockly.Connection.CAN_CONNECT) { + if (reason != Connection.CAN_CONNECT) { throw new Error(checker.getErrorMessage(reason, this, target)); } }; @@ -249,18 +250,18 @@ Blockly.Connection.prototype.checkConnection = function(target) { * source block's workspace. * @package */ -Blockly.Connection.prototype.getConnectionChecker = function() { +Connection.prototype.getConnectionChecker = function() { return this.sourceBlock_.workspace.connectionChecker; }; /** * Check if the two connections can be dragged to connect to each other. - * @param {!Blockly.Connection} candidate A nearby connection to check. + * @param {!Connection} candidate A nearby connection to check. * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.isConnectionAllowed = function(candidate) { +Connection.prototype.isConnectionAllowed = function(candidate) { Blockly.utils.deprecation.warn( 'Connection.prototype.isConnectionAllowed', 'July 2020', @@ -272,19 +273,19 @@ Blockly.Connection.prototype.isConnectionAllowed = function(candidate) { /** * Called when an attempted connection fails. NOP by default (i.e. for headless * workspaces). - * @param {!Blockly.Connection} _otherConnection Connection that this connection + * @param {!Connection} _otherConnection Connection that this connection * failed to connect to. * @package */ -Blockly.Connection.prototype.onFailedConnect = function(_otherConnection) { +Connection.prototype.onFailedConnect = function(_otherConnection) { // NOP }; /** * Connect this connection to another connection. - * @param {!Blockly.Connection} otherConnection Connection to connect to. + * @param {!Connection} otherConnection Connection to connect to. */ -Blockly.Connection.prototype.connect = function(otherConnection) { +Connection.prototype.connect = function(otherConnection) { if (this.targetConnection == otherConnection) { // Already connected together. NOP. return; @@ -312,11 +313,11 @@ Blockly.Connection.prototype.connect = function(otherConnection) { /** * Update two connections to target each other. - * @param {Blockly.Connection} first The first connection to update. - * @param {Blockly.Connection} second The second connection to update. + * @param {Connection} first The first connection to update. + * @param {Connection} second The second connection to update. * @private */ -Blockly.Connection.connectReciprocally_ = function(first, second) { +Connection.connectReciprocally_ = function(first, second) { if (!first || !second) { throw Error('Cannot connect null connections.'); } @@ -331,11 +332,11 @@ Blockly.Connection.connectReciprocally_ = function(first, second) { * connections, this returns null. * @param {!Blockly.Block} block The superior block. * @param {!Blockly.Block} orphanBlock The inferior block. - * @return {?Blockly.Connection} The suitable connection point on 'block', + * @return {?Connection} The suitable connection point on 'block', * or null. * @private */ -Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { +Connection.getSingleConnection_ = function(block, orphanBlock) { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -360,15 +361,15 @@ Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) { * Terminates early for shadow blocks. * @param {!Blockly.Block} startBlock The block on which to start the search. * @param {!Blockly.Block} orphanBlock The block that is looking for a home. - * @return {?Blockly.Connection} The suitable connection point on the chain + * @return {?Connection} The suitable connection point on the chain * of blocks, or null. * @private */ -Blockly.Connection.getConnectionForOrphanedOutput_ = +Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { let newBlock = startBlock; let connection; - while ((connection = Blockly.Connection.getSingleConnection_( + while ((connection = Connection.getSingleConnection_( /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { @@ -383,15 +384,15 @@ Blockly.Connection.getConnectionForOrphanedOutput_ = * the given connection. This includes compatible connection types and * connection checks. * @param {!Blockly.Block} startBlock The block on which to start the search. - * @param {!Blockly.Connection} orphanConnection The connection that is looking + * @param {!Connection} orphanConnection The connection that is looking * for a home. - * @return {?Blockly.Connection} The suitable connection point on the chain of + * @return {?Connection} The suitable connection point on the chain of * blocks, or null. */ -Blockly.Connection.getConnectionForOrphanedConnection = +Connection.getConnectionForOrphanedConnection = function(startBlock, orphanConnection) { if (orphanConnection.type === Blockly.connectionTypes.OUTPUT_VALUE) { - return Blockly.Connection.getConnectionForOrphanedOutput_( + return Connection.getConnectionForOrphanedOutput_( startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. @@ -407,7 +408,7 @@ Blockly.Connection.getConnectionForOrphanedConnection = /** * Disconnect this connection. */ -Blockly.Connection.prototype.disconnect = function() { +Connection.prototype.disconnect = function() { const otherConnection = this.targetConnection; if (!otherConnection) { throw Error('Source connection not connected.'); @@ -448,7 +449,7 @@ Blockly.Connection.prototype.disconnect = function() { * @param {!Blockly.Block} childBlock The inferior block. * @protected */ -Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, +Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; if (Blockly.Events.isEnabled()) { @@ -468,7 +469,7 @@ Blockly.Connection.prototype.disconnectInternal_ = function(parentBlock, * Respawn the shadow block if there was one connected to the this connection. * @protected */ -Blockly.Connection.prototype.respawnShadow_ = function() { +Connection.prototype.respawnShadow_ = function() { const parentBlock = this.getSourceBlock(); const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { @@ -487,7 +488,7 @@ Blockly.Connection.prototype.respawnShadow_ = function() { * Returns the block that this connection connects to. * @return {?Blockly.Block} The connected block or null if none is connected. */ -Blockly.Connection.prototype.targetBlock = function() { +Connection.prototype.targetBlock = function() { if (this.isConnected()) { return this.targetConnection.getSourceBlock(); } @@ -497,12 +498,12 @@ Blockly.Connection.prototype.targetBlock = function() { /** * Is this connection compatible with another connection with respect to the * value type system. E.g. square_root("Hello") is not compatible. - * @param {!Blockly.Connection} otherConnection Connection to compare against. + * @param {!Connection} otherConnection Connection to compare against. * @return {boolean} True if the connections share a type. * @deprecated July 2020. Will be deleted July 2021. Use the workspace's * connectionChecker instead. */ -Blockly.Connection.prototype.checkType = function(otherConnection) { +Connection.prototype.checkType = function(otherConnection) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkType', 'October 2019', @@ -515,14 +516,14 @@ Blockly.Connection.prototype.checkType = function(otherConnection) { /** * Is this connection compatible with another connection with respect to the * value type system. E.g. square_root("Hello") is not compatible. - * @param {!Blockly.Connection} otherConnection Connection to compare against. + * @param {!Connection} otherConnection Connection to compare against. * @return {boolean} True if the connections share a type. * @private * @deprecated October 2019. Will be deleted January 2021. Use the workspace's * connectionChecker instead. * @suppress {unusedPrivateMembers} */ -Blockly.Connection.prototype.checkType_ = function(otherConnection) { +Connection.prototype.checkType_ = function(otherConnection) { Blockly.utils.deprecation.warn( 'Connection.prototype.checkType_', 'October 2019', @@ -535,7 +536,7 @@ Blockly.Connection.prototype.checkType_ = function(otherConnection) { * Function to be called when this connection's compatible types have changed. * @protected */ -Blockly.Connection.prototype.onCheckChanged_ = function() { +Connection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( @@ -549,10 +550,10 @@ Blockly.Connection.prototype.onCheckChanged_ = function() { * Change a connection's compatibility. * @param {?(string|!Array)} check Compatible value type or list of * value types. Null if all types are compatible. - * @return {!Blockly.Connection} The connection being modified + * @return {!Connection} The connection being modified * (to allow chaining). */ -Blockly.Connection.prototype.setCheck = function(check) { +Connection.prototype.setCheck = function(check) { if (check) { // Ensure that check is in an array. if (!Array.isArray(check)) { @@ -572,7 +573,7 @@ Blockly.Connection.prototype.setCheck = function(check) { * Null if all types are compatible. * @public */ -Blockly.Connection.prototype.getCheck = function() { +Connection.prototype.getCheck = function() { return this.check_; }; @@ -580,7 +581,7 @@ Blockly.Connection.prototype.getCheck = function() { * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. */ -Blockly.Connection.prototype.setShadowDom = function(shadow) { +Connection.prototype.setShadowDom = function(shadow) { this.shadowDom_ = shadow; const target = this.targetBlock(); if (!target) { @@ -600,7 +601,7 @@ Blockly.Connection.prototype.setShadowDom = function(shadow) { * shadowDom is just returned. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Connection.prototype.getShadowDom = function(returnCurrent) { +Connection.prototype.getShadowDom = function(returnCurrent) { return (returnCurrent && this.targetBlock().isShadow()) ? /** @type {!Element} */ (Blockly.Xml.blockToDom( /** @type {!Blockly.Block} */ (this.targetBlock()))) : @@ -616,10 +617,10 @@ Blockly.Connection.prototype.getShadowDom = function(returnCurrent) { * {@link Blockly.RenderedConnection} overrides this behavior with a list * computed from the rendered positioning. * @param {number} _maxLimit The maximum radius to another connection. - * @return {!Array} List of connections. + * @return {!Array} List of connections. * @package */ -Blockly.Connection.prototype.neighbours = function(_maxLimit) { +Connection.prototype.neighbours = function(_maxLimit) { return []; }; @@ -629,7 +630,7 @@ Blockly.Connection.prototype.neighbours = function(_maxLimit) { * no parent exists. * @package */ -Blockly.Connection.prototype.getParentInput = function() { +Connection.prototype.getParentInput = function() { let parentInput = null; const inputs = this.sourceBlock_.inputList; for (let i = 0; i < inputs.length; i++) { @@ -646,7 +647,7 @@ Blockly.Connection.prototype.getParentInput = function() { * (English only). Intended to on be used in console logs and errors. * @return {string} The description. */ -Blockly.Connection.prototype.toString = function() { +Connection.prototype.toString = function() { const block = this.sourceBlock_; if (!block) { return 'Orphan Connection'; @@ -675,3 +676,5 @@ Blockly.Connection.prototype.toString = function() { } return msg + block.toDevString(); }; + +exports = Connection; diff --git a/tests/deps.js b/tests/deps.js index ed2af0dc9..b435a26ba 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -19,7 +19,7 @@ goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); From 8c0304ece883d9adc77b3f1c9445cf057aa8b50a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:02:44 -0700 Subject: [PATCH 088/833] Use pull request target trigger for tagging cleanup --- .github/workflows/tag_module_cleanup.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tag_module_cleanup.yml b/.github/workflows/tag_module_cleanup.yml index 2b14426ad..94e7ec692 100644 --- a/.github/workflows/tag_module_cleanup.yml +++ b/.github/workflows/tag_module_cleanup.yml @@ -4,8 +4,9 @@ name: Tag module cleanup # Trigger on pull requests against goog_module branch only +# Uses pull_request_target to get write permissions so that it can write labels. on: - pull_request: + pull_request_target: branches: - goog_module From 210fcea19889f19c008899e3f89a1837d76a8174 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:13:40 -0700 Subject: [PATCH 089/833] Migrate core/connection.js to named requires --- core/connection.js | 95 +++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/core/connection.js b/core/connection.js index be9a08eb9..0c7f54605 100644 --- a/core/connection.js +++ b/core/connection.js @@ -13,31 +13,30 @@ goog.module('Blockly.Connection'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const Block = goog.requireType('Blockly.Block'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const Events = goog.require('Blockly.Events'); +const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +const Input = goog.requireType('Blockly.Input'); +const Xml = goog.require('Blockly.Xml'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.IASTNodeLocationWithBlock'); -goog.require('Blockly.utils.deprecation'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.Input'); /** * Class for a connection between blocks. - * @param {!Blockly.Block} source The block establishing this connection. + * @param {!Block} source The block establishing this connection. * @param {number} type The type of the connection. * @constructor - * @implements {Blockly.IASTNodeLocationWithBlock} + * @implements {IASTNodeLocationWithBlock} */ const Connection = function(source, type) { /** - * @type {!Blockly.Block} + * @type {!Block} * @protected */ this.sourceBlock_ = source; @@ -105,7 +104,7 @@ Connection.prototype.y = 0; * @protected */ Connection.prototype.connect_ = function(childConnection) { - const INPUT = Blockly.connectionTypes.INPUT_VALUE; + const INPUT = connectionTypes.INPUT_VALUE; const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); const childBlock = childConnection.getSourceBlock(); @@ -132,14 +131,14 @@ Connection.prototype.connect_ = function(childConnection) { // Connect the new connection to the parent. let event; - if (Blockly.Events.isEnabled()) { - event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); + if (Events.isEnabled()) { + event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } Connection.connectReciprocally_(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } // Deal with the orphan if it exists. @@ -180,7 +179,7 @@ Connection.prototype.dispose = function() { /** * Get the source block for this connection. - * @return {!Blockly.Block} The source block. + * @return {!Block} The source block. */ Connection.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -191,8 +190,8 @@ Connection.prototype.getSourceBlock = function() { * @return {boolean} True if connection faces down or right. */ Connection.prototype.isSuperior = function() { - return this.type == Blockly.connectionTypes.INPUT_VALUE || - this.type == Blockly.connectionTypes.NEXT_STATEMENT; + return this.type == connectionTypes.INPUT_VALUE || + this.type == connectionTypes.NEXT_STATEMENT; }; /** @@ -213,7 +212,7 @@ Connection.prototype.isConnected = function() { * connectionChecker instead. */ Connection.prototype.canConnectWithReason = function(target) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.canConnectWithReason', 'July 2020', 'July 2021', @@ -232,7 +231,7 @@ Connection.prototype.canConnectWithReason = function(target) { * connectionChecker instead. */ Connection.prototype.checkConnection = function(target) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkConnection', 'July 2020', 'July 2021', @@ -246,7 +245,7 @@ Connection.prototype.checkConnection = function(target) { /** * Get the workspace's connection type checker object. - * @return {!Blockly.IConnectionChecker} The connection type checker for the + * @return {!IConnectionChecker} The connection type checker for the * source block's workspace. * @package */ @@ -262,7 +261,7 @@ Connection.prototype.getConnectionChecker = function() { * connectionChecker instead. */ Connection.prototype.isConnectionAllowed = function(candidate) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', @@ -293,9 +292,9 @@ Connection.prototype.connect = function(otherConnection) { const checker = this.getConnectionChecker(); if (checker.canConnect(this, otherConnection, false)) { - const eventGroup = Blockly.Events.getGroup(); + const eventGroup = Events.getGroup(); if (!eventGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } // Determine which block is superior (higher in the source stack). if (this.isSuperior()) { @@ -306,7 +305,7 @@ Connection.prototype.connect = function(otherConnection) { otherConnection.connect_(this); } if (!eventGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } }; @@ -330,8 +329,8 @@ Connection.connectReciprocally_ = function(first, second) { * block, if one can be found. If the block has multiple compatible connections * (even if they are filled) this returns null. If the block has no compatible * connections, this returns null. - * @param {!Blockly.Block} block The superior block. - * @param {!Blockly.Block} orphanBlock The inferior block. + * @param {!Block} block The superior block. + * @param {!Block} orphanBlock The inferior block. * @return {?Connection} The suitable connection point on 'block', * or null. * @private @@ -359,8 +358,8 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * are zero or multiple eligible connections, returns null. Otherwise * returns the only input on the last block in the chain. * Terminates early for shadow blocks. - * @param {!Blockly.Block} startBlock The block on which to start the search. - * @param {!Blockly.Block} orphanBlock The block that is looking for a home. + * @param {!Block} startBlock The block on which to start the search. + * @param {!Block} orphanBlock The block that is looking for a home. * @return {?Connection} The suitable connection point on the chain * of blocks, or null. * @private @@ -370,7 +369,7 @@ Connection.getConnectionForOrphanedOutput_ = let newBlock = startBlock; let connection; while ((connection = Connection.getSingleConnection_( - /** @type {!Blockly.Block} */ (newBlock), orphanBlock))) { + /** @type {!Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { return connection; @@ -383,7 +382,7 @@ Connection.getConnectionForOrphanedOutput_ = * Returns the connection (starting at the startBlock) which will accept * the given connection. This includes compatible connection types and * connection checks. - * @param {!Blockly.Block} startBlock The block on which to start the search. + * @param {!Block} startBlock The block on which to start the search. * @param {!Connection} orphanConnection The connection that is looking * for a home. * @return {?Connection} The suitable connection point on the chain of @@ -391,7 +390,7 @@ Connection.getConnectionForOrphanedOutput_ = */ Connection.getConnectionForOrphanedConnection = function(startBlock, orphanConnection) { - if (orphanConnection.type === Blockly.connectionTypes.OUTPUT_VALUE) { + if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { return Connection.getConnectionForOrphanedOutput_( startBlock, orphanConnection.getSourceBlock()); } @@ -429,9 +428,9 @@ Connection.prototype.disconnect = function() { parentConnection = otherConnection; } - const eventGroup = Blockly.Events.getGroup(); + const eventGroup = Events.getGroup(); if (!eventGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } this.disconnectInternal_(parentBlock, childBlock); if (!childBlock.isShadow()) { @@ -439,21 +438,21 @@ Connection.prototype.disconnect = function() { parentConnection.respawnShadow_(); } if (!eventGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; /** * Disconnect two blocks that are connected by this connection. - * @param {!Blockly.Block} parentBlock The superior block. - * @param {!Blockly.Block} childBlock The inferior block. + * @param {!Block} parentBlock The superior block. + * @param {!Block} childBlock The inferior block. * @protected */ Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; - if (Blockly.Events.isEnabled()) { - event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(childBlock); + if (Events.isEnabled()) { + event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } const otherConnection = this.targetConnection; otherConnection.targetConnection = null; @@ -461,7 +460,7 @@ Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock.setParent(null); if (event) { event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); } }; @@ -473,7 +472,7 @@ Connection.prototype.respawnShadow_ = function() { const parentBlock = this.getSourceBlock(); const shadow = this.getShadowDom(); if (parentBlock.workspace && shadow) { - const blockShadow = Blockly.Xml.domToBlock(shadow, parentBlock.workspace); + const blockShadow = Xml.domToBlock(shadow, parentBlock.workspace); if (blockShadow.outputConnection) { this.connect(blockShadow.outputConnection); } else if (blockShadow.previousConnection) { @@ -486,7 +485,7 @@ Connection.prototype.respawnShadow_ = function() { /** * Returns the block that this connection connects to. - * @return {?Blockly.Block} The connected block or null if none is connected. + * @return {?Block} The connected block or null if none is connected. */ Connection.prototype.targetBlock = function() { if (this.isConnected()) { @@ -504,7 +503,7 @@ Connection.prototype.targetBlock = function() { * connectionChecker instead. */ Connection.prototype.checkType = function(otherConnection) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkType', 'October 2019', 'January 2021', @@ -524,7 +523,7 @@ Connection.prototype.checkType = function(otherConnection) { * @suppress {unusedPrivateMembers} */ Connection.prototype.checkType_ = function(otherConnection) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'Connection.prototype.checkType_', 'October 2019', 'January 2021', @@ -603,8 +602,8 @@ Connection.prototype.setShadowDom = function(shadow) { */ Connection.prototype.getShadowDom = function(returnCurrent) { return (returnCurrent && this.targetBlock().isShadow()) ? - /** @type {!Element} */ (Blockly.Xml.blockToDom( - /** @type {!Blockly.Block} */ (this.targetBlock()))) : + /** @type {!Element} */ (Xml.blockToDom( + /** @type {!Block} */ (this.targetBlock()))) : this.shadowDom_; }; @@ -626,7 +625,7 @@ Connection.prototype.neighbours = function(_maxLimit) { /** * Get the parent input of a connection. - * @return {?Blockly.Input} The input that the connection belongs to or null if + * @return {?Input} The input that the connection belongs to or null if * no parent exists. * @package */ From cae985369dbc913006ee91bda183f8da84375538 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:05:36 -0700 Subject: [PATCH 090/833] Migrate core/interfaces/i_delete_area.js to goog.module --- core/interfaces/i_delete_area.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 31f53350e..923c0bd7c 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IDeleteArea'); +goog.module('Blockly.IDeleteArea'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDragTarget'); @@ -25,7 +26,7 @@ goog.requireType('Blockly.IDraggable'); * @extends {Blockly.IDragTarget} * @interface */ -Blockly.IDeleteArea = function() {}; +const IDeleteArea = function() {}; /** * Returns whether the provided block or bubble would be deleted if dropped on @@ -39,4 +40,6 @@ Blockly.IDeleteArea = function() {}; * @return {boolean} Whether the element provided would be deleted if dropped on * this area. */ -Blockly.IDeleteArea.prototype.wouldDelete; +IDeleteArea.prototype.wouldDelete; + +exports = IDeleteArea; diff --git a/tests/deps.js b/tests/deps.js index c23b3f10c..234dbe062 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -83,7 +83,7 @@ goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IC goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); From 98e6020baf1e8d4904bb3c4a751e3cb030e80e34 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:06:35 -0700 Subject: [PATCH 091/833] Migrate core/interfaces/i_delete_area.js named requires --- core/interfaces/i_delete_area.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 923c0bd7c..5c5cbd380 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -15,15 +15,14 @@ goog.module('Blockly.IDeleteArea'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDragTarget'); - -goog.requireType('Blockly.IDraggable'); +const IDraggable = goog.requireType('Blockly.IDraggable'); +const IDragTarget = goog.require('Blockly.IDragTarget'); /** * Interface for a component that can delete a block or bubble that is dropped * on top of it. - * @extends {Blockly.IDragTarget} + * @extends {IDragTarget} * @interface */ const IDeleteArea = function() {}; @@ -33,7 +32,7 @@ const IDeleteArea = function() {}; * this area. * This method should check if the element is deletable and is always called * before onDragEnter/onDragOver/onDragExit. - * @param {!Blockly.IDraggable} element The block or bubble currently being + * @param {!IDraggable} element The block or bubble currently being * dragged. * @param {boolean} couldConnect Whether the element could could connect to * another. From 9806fc13f97819ba76ad077b8d0e5f2fc63dd0e5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:32:10 -0700 Subject: [PATCH 092/833] Migrate core/interfaces/i_draggable.js to goog.module --- core/interfaces/i_draggable.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index f140555a1..cb77f3dce 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IDraggable'); +goog.module('Blockly.IDraggable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDeletable'); @@ -21,4 +22,6 @@ goog.require('Blockly.IDeletable'); * @extends {Blockly.IDeletable} * @interface */ -Blockly.IDraggable = function() {}; +const IDraggable = function() {}; + +exports = IDraggable; diff --git a/tests/deps.js b/tests/deps.js index 234dbe062..5f5f93d89 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -85,7 +85,7 @@ goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); -goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable']); +goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], []); From 1b15437e2fb296688b3750fca6f1aa1f906a5848 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:32:40 -0700 Subject: [PATCH 093/833] Migrate core/interfaces/i_draggable.js named requires --- core/interfaces/i_draggable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index cb77f3dce..81303a24b 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -14,12 +14,12 @@ goog.module('Blockly.IDraggable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDeletable'); +const IDeletable = goog.require('Blockly.IDeletable'); /** * The interface for an object that can be dragged. - * @extends {Blockly.IDeletable} + * @extends {IDeletable} * @interface */ const IDraggable = function() {}; From 1e81334c15cffda802a0d44f27ffc993052483a8 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:15:25 -0700 Subject: [PATCH 094/833] Migrate core/renderers/common/info.js to ES6 const/let --- core/renderers/common/info.js | 108 +++++++++++++++++----------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index f3eac053a..9c5d62a9a 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -205,13 +205,13 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() { Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); - var activeRow = new Blockly.blockRendering.InputRow(this.constants_); + let activeRow = new Blockly.blockRendering.InputRow(this.constants_); this.inputRows.push(activeRow); // Icons always go on the first row, before anything else. - var icons = this.block_.getIcons(); - for (var i = 0, icon; (icon = icons[i]); i++) { - var iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); + const icons = this.block_.getIcons(); + for (let i = 0, icon; (icon = icons[i]); i++) { + const iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); if (this.isCollapsed && icon.collapseHidden) { this.hiddenIcons.push(iconInfo); } else { @@ -219,10 +219,10 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { } } - var lastInput = null; + let lastInput = null; // Loop across all of the inputs on the block, creating objects for anything // that needs to be rendered and breaking the block up into visual rows. - for (var i = 0, input; (input = this.block_.inputList[i]); i++) { + for (let i = 0, input; (input = this.block_.inputList[i]); i++) { if (!input.isVisible()) { continue; } @@ -234,7 +234,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { } // All of the fields in an input go on the same row. - for (var j = 0, field; (field = input.fieldRow[j]); j++) { + for (let j = 0, field; (field = input.fieldRow[j]); j++) { activeRow.elements.push( new Blockly.blockRendering.Field(this.constants_, field, input)); } @@ -260,17 +260,18 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { * @package */ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { - var hasPrevious = !!this.block_.previousConnection; - var hasHat = (this.block_.hat ? - this.block_.hat === 'cap' : this.constants_.ADD_START_HATS) && + const hasPrevious = !!this.block_.previousConnection; + const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : + this.constants_.ADD_START_HATS) && !this.outputConnection && !hasPrevious; - var cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : Blockly.blockRendering.RoundCorner; + let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? + Blockly.blockRendering.SquareCorner : + Blockly.blockRendering.RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { - var hat = new Blockly.blockRendering.Hat(this.constants_); + const hat = new Blockly.blockRendering.Hat(this.constants_); this.topRow.elements.push(hat); this.topRow.capline = hat.ascenderHeight; } else if (hasPrevious) { @@ -282,7 +283,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { this.topRow.elements.push(this.topRow.connection); } - var precedesStatement = this.block_.inputList.length && + const precedesStatement = this.block_.inputList.length && this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a @@ -306,7 +307,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; - var followsStatement = this.block_.inputList.length && + const followsStatement = this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type == Blockly.inputTypes.STATEMENT; @@ -319,7 +320,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } - var leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); + const leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); if (leftSquareCorner) { this.bottomRow.elements.push( @@ -336,7 +337,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.elements.push(this.bottomRow.connection); } - var rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); + const rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); if (rightSquareCorner) { this.bottomRow.elements.push( @@ -414,8 +415,8 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, * @protected */ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { - for (var i = 0, row; (row = this.rows[i]); i++) { - var oldElems = row.elements; + for (let i = 0, row; (row = this.rows[i]); i++) { + const oldElems = row.elements; row.elements = []; // No spacing needed before the corner on the top row or the bottom row. if (row.startsWithElemSpacer()) { @@ -426,9 +427,9 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { if (!oldElems.length) { continue; } - for (var e = 0; e < oldElems.length - 1; e++) { + for (let e = 0; e < oldElems.length - 1; e++) { row.elements.push(oldElems[e]); - var spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); + const spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); row.elements.push( new Blockly.blockRendering.InRowSpacer(this.constants_, spacing)); } @@ -496,15 +497,15 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne */ // TODO: More cleanup. Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { - var widestStatementRowFields = 0; - var blockWidth = 0; - var widestRowWithConnectedBlocks = 0; - for (var i = 0, row; (row = this.rows[i]); i++) { + let widestStatementRowFields = 0; + let blockWidth = 0; + let widestRowWithConnectedBlocks = 0; + for (let i = 0, row; (row = this.rows[i]); i++) { row.measure(); blockWidth = Math.max(blockWidth, row.width); if (row.hasStatement) { - var statementInput = row.getLastInput(); - var innerWidth = row.width - statementInput.width; + const statementInput = row.getLastInput(); + const innerWidth = row.width - statementInput.width; widestStatementRowFields = Math.max(widestStatementRowFields, innerWidth); } widestRowWithConnectedBlocks = @@ -514,7 +515,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { this.statementEdge = widestStatementRowFields; this.width = blockWidth; - for (var i = 0, row; (row = this.rows[i]); i++) { + for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { row.statementEdge = this.statementEdge; } @@ -536,14 +537,14 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { * @protected */ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { - for (var i = 0, row; (row = this.rows[i]); i++) { + for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( /** @type {!Blockly.blockRendering.InputRow} */ (row)); } else { - var currentWidth = row.width; - var desiredWidth = this.getDesiredRowWidth_(row); - var missingSpace = desiredWidth - currentWidth; + const currentWidth = row.width; + const desiredWidth = this.getDesiredRowWidth_(row); + const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } @@ -573,10 +574,10 @@ Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( * @param {number} missingSpace How much padding to add. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, - missingSpace) { - var firstSpacer = row.getFirstSpacer(); - var lastSpacer = row.getLastSpacer(); +Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( + row, missingSpace) { + const firstSpacer = row.getFirstSpacer(); + const lastSpacer = row.getLastSpacer(); if (row.hasExternalInput || row.hasStatement) { row.widthWithConnectedBlocks += missingSpace; } @@ -606,11 +607,11 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function(row, * @protected */ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { - var statementInput = row.getLastInput(); - var currentWidth = row.width - statementInput.width; - var desiredWidth = this.statementEdge; + const statementInput = row.getLastInput(); + let currentWidth = row.width - statementInput.width; + let desiredWidth = this.statementEdge; // Add padding before the statement input. - var missingSpace = desiredWidth - currentWidth; + const missingSpace = desiredWidth - currentWidth; if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } @@ -630,10 +631,10 @@ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { * @protected */ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { - var oldRows = this.rows; + const oldRows = this.rows; this.rows = []; - for (var r = 0; r < oldRows.length; r++) { + for (let r = 0; r < oldRows.length; r++) { this.rows.push(oldRows[r]); if (r != oldRows.length - 1) { this.rows.push(this.makeSpacerRow_(oldRows[r], oldRows[r + 1])); @@ -648,11 +649,12 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { - var height = this.getSpacerRowHeight_(prev, next); - var width = this.getSpacerRowWidth_(prev, next); - var spacer = new Blockly.blockRendering.SpacerRow( - this.constants_, height, width); +Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( + prev, next) { + const height = this.getSpacerRowHeight_(prev, next); + const width = this.getSpacerRowWidth_(prev, next); + const spacer = + new Blockly.blockRendering.SpacerRow(this.constants_, height, width); if (prev.hasStatement) { spacer.followsStatement = true; } @@ -703,7 +705,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, return row.yPos + elem.height / 2; } if (Blockly.blockRendering.Types.isBottomRow(row)) { - var baseline = row.yPos + row.height - row.descenderHeight; + const baseline = row.yPos + row.height - row.descenderHeight; if (Blockly.blockRendering.Types.isNextConnection(elem)) { return baseline + elem.height / 2; } @@ -726,8 +728,8 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, */ Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( row) { - var xCursor = row.xPos; - for (var j = 0, elem; (elem = row.elements[j]); j++) { + let xCursor = row.xPos; + for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. if (Blockly.blockRendering.Types.isSpacer(elem)) { elem.height = row.height; @@ -747,9 +749,9 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { // Performance note: this could be combined with the draw pass, if the time // that this takes is excessive. But it shouldn't be, because it only // accesses and sets properties that already exist on the objects. - var widestRowWithConnectedBlocks = 0; - var yCursor = 0; - for (var i = 0, row; (row = this.rows[i]); i++) { + let widestRowWithConnectedBlocks = 0; + let yCursor = 0; + for (let i = 0, row; (row = this.rows[i]); i++) { row.yPos = yCursor; row.xPos = this.startX; yCursor += row.height; From bdd0353549c57936601e884fcaffc5c4e209db70 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:16:06 -0700 Subject: [PATCH 095/833] clang-format core/connection.js --- core/connection.js | 95 ++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/core/connection.js b/core/connection.js index 0c7f54605..0b26e9ace 100644 --- a/core/connection.js +++ b/core/connection.js @@ -144,7 +144,8 @@ Connection.prototype.connect_ = function(childConnection) { // Deal with the orphan if it exists. if (orphan) { const orphanConnection = parentConnection.type === INPUT ? - orphan.outputConnection : orphan.previousConnection; + orphan.outputConnection : + orphan.previousConnection; const connection = Connection.getConnectionForOrphanedConnection( childBlock, /** @type {!Connection} */ (orphanConnection)); if (connection) { @@ -161,7 +162,6 @@ Connection.prototype.connect_ = function(childConnection) { * @package */ Connection.prototype.dispose = function() { - // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { // Destroy the attached shadow block & its children (if it exists). @@ -213,12 +213,9 @@ Connection.prototype.isConnected = function() { */ Connection.prototype.canConnectWithReason = function(target) { deprecation.warn( - 'Connection.prototype.canConnectWithReason', - 'July 2020', - 'July 2021', + 'Connection.prototype.canConnectWithReason', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); - return this.getConnectionChecker().canConnectWithReason( - this, target, false); + return this.getConnectionChecker().canConnectWithReason(this, target, false); }; /** @@ -232,9 +229,7 @@ Connection.prototype.canConnectWithReason = function(target) { */ Connection.prototype.checkConnection = function(target) { deprecation.warn( - 'Connection.prototype.checkConnection', - 'July 2020', - 'July 2021', + 'Connection.prototype.checkConnection', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); const checker = this.getConnectionChecker(); const reason = checker.canConnectWithReason(this, target, false); @@ -262,9 +257,7 @@ Connection.prototype.getConnectionChecker = function() { */ Connection.prototype.isConnectionAllowed = function(candidate) { deprecation.warn( - 'Connection.prototype.isConnectionAllowed', - 'July 2020', - 'July 2021', + 'Connection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', 'the workspace\'s connection checker'); return this.getConnectionChecker().canConnect(this, candidate, true); }; @@ -364,19 +357,19 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * of blocks, or null. * @private */ -Connection.getConnectionForOrphanedOutput_ = - function(startBlock, orphanBlock) { - let newBlock = startBlock; - let connection; - while ((connection = Connection.getSingleConnection_( - /** @type {!Block} */ (newBlock), orphanBlock))) { - newBlock = connection.targetBlock(); - if (!newBlock || newBlock.isShadow()) { - return connection; - } - } - return null; - }; +Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { + let newBlock = startBlock; + let connection; + while ( + (connection = Connection.getSingleConnection_( + /** @type {!Block} */ (newBlock), orphanBlock))) { + newBlock = connection.targetBlock(); + if (!newBlock || newBlock.isShadow()) { + return connection; + } + } + return null; +}; /** * Returns the connection (starting at the startBlock) which will accept @@ -388,21 +381,20 @@ Connection.getConnectionForOrphanedOutput_ = * @return {?Connection} The suitable connection point on the chain of * blocks, or null. */ -Connection.getConnectionForOrphanedConnection = - function(startBlock, orphanConnection) { - if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { - return Connection.getConnectionForOrphanedOutput_( - startBlock, orphanConnection.getSourceBlock()); - } - // Otherwise we're dealing with a stack. - const connection = startBlock.lastConnectionInStack(true); - const checker = orphanConnection.getConnectionChecker(); - if (connection && - checker.canConnect(orphanConnection, connection, false)) { - return connection; - } - return null; - }; +Connection.getConnectionForOrphanedConnection = function( + startBlock, orphanConnection) { + if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { + return Connection.getConnectionForOrphanedOutput_( + startBlock, orphanConnection.getSourceBlock()); + } + // Otherwise we're dealing with a stack. + const connection = startBlock.lastConnectionInStack(true); + const checker = orphanConnection.getConnectionChecker(); + if (connection && checker.canConnect(orphanConnection, connection, false)) { + return connection; + } + return null; +}; /** * Disconnect this connection. @@ -448,8 +440,7 @@ Connection.prototype.disconnect = function() { * @param {!Block} childBlock The inferior block. * @protected */ -Connection.prototype.disconnectInternal_ = function(parentBlock, - childBlock) { +Connection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { let event; if (Events.isEnabled()) { event = new (Events.get(Events.BLOCK_MOVE))(childBlock); @@ -504,12 +495,9 @@ Connection.prototype.targetBlock = function() { */ Connection.prototype.checkType = function(otherConnection) { deprecation.warn( - 'Connection.prototype.checkType', - 'October 2019', - 'January 2021', + 'Connection.prototype.checkType', 'October 2019', 'January 2021', 'the workspace\'s connection checker'); - return this.getConnectionChecker().canConnect(this, otherConnection, - false); + return this.getConnectionChecker().canConnect(this, otherConnection, false); }; /** @@ -524,9 +512,7 @@ Connection.prototype.checkType = function(otherConnection) { */ Connection.prototype.checkType_ = function(otherConnection) { deprecation.warn( - 'Connection.prototype.checkType_', - 'October 2019', - 'January 2021', + 'Connection.prototype.checkType_', 'October 2019', 'January 2021', 'the workspace\'s connection checker'); return this.checkType(otherConnection); }; @@ -537,9 +523,10 @@ Connection.prototype.checkType_ = function(otherConnection) { */ Connection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. - if (this.isConnected() && (!this.targetConnection || - !this.getConnectionChecker().canConnect( - this, this.targetConnection, false))) { + if (this.isConnected() && + (!this.targetConnection || + !this.getConnectionChecker().canConnect( + this, this.targetConnection, false))) { const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); } From 29c560dfbb225d702f95a30a9560baca65a4e457 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:26:36 -0700 Subject: [PATCH 096/833] Migrate core/connection_checker.js to ES6 const/let --- core/connection_checker.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 004d5e3f3..d0e4576c2 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -64,14 +64,14 @@ Blockly.ConnectionChecker.prototype.canConnect = function(a, b, */ Blockly.ConnectionChecker.prototype.canConnectWithReason = function( a, b, isDragging, opt_distance) { - var safety = this.doSafetyChecks(a, b); + const safety = this.doSafetyChecks(a, b); if (safety != Blockly.Connection.CAN_CONNECT) { return safety; } // If the safety checks passed, both connections are non-null. - var connOne = /** @type {!Blockly.Connection} **/ (a); - var connTwo = /** @type {!Blockly.Connection} **/ (b); + const connOne = /** @type {!Blockly.Connection} **/ (a); + const connTwo = /** @type {!Blockly.Connection} **/ (b); if (!this.doTypeChecks(connOne, connTwo)) { return Blockly.Connection.REASON_CHECKS_FAILED; } @@ -108,12 +108,13 @@ Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode, return 'Attempt to connect incompatible types.'; case Blockly.Connection.REASON_TARGET_NULL: return 'Target connection is null.'; - case Blockly.Connection.REASON_CHECKS_FAILED: - var connOne = /** @type {!Blockly.Connection} **/ (a); - var connTwo = /** @type {!Blockly.Connection} **/ (b); - var msg = 'Connection checks failed. '; + case Blockly.Connection.REASON_CHECKS_FAILED: { + const connOne = /** @type {!Blockly.Connection} **/ (a); + const connTwo = /** @type {!Blockly.Connection} **/ (b); + let msg = 'Connection checks failed. '; msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck(); return msg; + } case Blockly.Connection.REASON_SHADOW_PARENT: return 'Connecting non-shadow to shadow block.'; case Blockly.Connection.REASON_DRAG_CHECKS_FAILED: @@ -135,12 +136,13 @@ Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { return Blockly.Connection.REASON_TARGET_NULL; } + let blockA, blockB; if (a.isSuperior()) { - var blockA = a.getSourceBlock(); - var blockB = b.getSourceBlock(); + blockA = a.getSourceBlock(); + blockB = b.getSourceBlock(); } else { - var blockB = a.getSourceBlock(); - var blockA = b.getSourceBlock(); + blockB = a.getSourceBlock(); + blockA = b.getSourceBlock(); } if (blockA == blockB) { return Blockly.Connection.REASON_SELF_CONNECTION; @@ -164,15 +166,15 @@ Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { * @public */ Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) { - var checkArrayOne = a.getCheck(); - var checkArrayTwo = b.getCheck(); + const checkArrayOne = a.getCheck(); + const checkArrayTwo = b.getCheck(); if (!checkArrayOne || !checkArrayTwo) { // One or both sides are promiscuous enough that anything will fit. return true; } // Find any intersection in the check lists. - for (var i = 0; i < checkArrayOne.length; i++) { + for (let i = 0; i < checkArrayOne.length; i++) { if (checkArrayTwo.indexOf(checkArrayOne[i]) != -1) { return true; } @@ -274,7 +276,7 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { return true; } - var targetBlock = b.targetBlock(); + const targetBlock = b.targetBlock(); // If it is connected to a real block, game over. if (!targetBlock.isInsertionMarker()) { return false; From 50793c20cb507eceb5385c4e9f298a8702824798 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:30:16 -0700 Subject: [PATCH 097/833] Migrate core/connection_checker.js to goog.module --- core/connection_checker.js | 23 +++++++++++++---------- tests/deps.js | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index d0e4576c2..c4086a141 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.ConnectionChecker'); +goog.module('Blockly.ConnectionChecker'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); @@ -28,7 +29,7 @@ goog.requireType('Blockly.RenderedConnection'); * @implements {Blockly.IConnectionChecker} * @constructor */ -Blockly.ConnectionChecker = function() { +const ConnectionChecker = function() { }; /** @@ -43,7 +44,7 @@ Blockly.ConnectionChecker = function() { * @return {boolean} Whether the connection is legal. * @public */ -Blockly.ConnectionChecker.prototype.canConnect = function(a, b, +ConnectionChecker.prototype.canConnect = function(a, b, isDragging, opt_distance) { return this.canConnectWithReason(a, b, isDragging, opt_distance) == Blockly.Connection.CAN_CONNECT; @@ -62,7 +63,7 @@ Blockly.ConnectionChecker.prototype.canConnect = function(a, b, * an error code otherwise. * @public */ -Blockly.ConnectionChecker.prototype.canConnectWithReason = function( +ConnectionChecker.prototype.canConnectWithReason = function( a, b, isDragging, opt_distance) { const safety = this.doSafetyChecks(a, b); if (safety != Blockly.Connection.CAN_CONNECT) { @@ -96,7 +97,7 @@ Blockly.ConnectionChecker.prototype.canConnectWithReason = function( * @return {string} A developer-readable error string. * @public */ -Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode, +ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) { switch (errorCode) { case Blockly.Connection.REASON_SELF_CONNECTION: @@ -132,7 +133,7 @@ Blockly.ConnectionChecker.prototype.getErrorMessage = function(errorCode, * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ -Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { +ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { return Blockly.Connection.REASON_TARGET_NULL; } @@ -165,7 +166,7 @@ Blockly.ConnectionChecker.prototype.doSafetyChecks = function(a, b) { * @return {boolean} True if the connections share a type. * @public */ -Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) { +ConnectionChecker.prototype.doTypeChecks = function(a, b) { const checkArrayOne = a.getCheck(); const checkArrayTwo = b.getCheck(); @@ -191,7 +192,7 @@ Blockly.ConnectionChecker.prototype.doTypeChecks = function(a, b) { * @return {boolean} True if the connection is allowed during a drag. * @public */ -Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { +ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { if (a.distanceFrom(b) > distance) { return false; } @@ -260,7 +261,7 @@ Blockly.ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { * @return {boolean} True if the connection is allowed, false otherwise. * @protected */ -Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { +ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { if (a.targetConnection) { // This connection is already occupied. // A next connection will never disconnect itself mid-drag. @@ -288,4 +289,6 @@ Blockly.ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { }; Blockly.registry.register(Blockly.registry.Type.CONNECTION_CHECKER, - Blockly.registry.DEFAULT, Blockly.ConnectionChecker); + Blockly.registry.DEFAULT, ConnectionChecker); + +exports = ConnectionChecker; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..328c3bee3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -20,7 +20,7 @@ goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], [' goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); +goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); From 35cc70c52801cc5d68f27a64877943515ca0a686 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:56:16 -0700 Subject: [PATCH 098/833] Migrate core/interfaces/i_copyable.js to goog.module --- core/interfaces/i_copyable.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index 4aeac9776..db3381fae 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ICopyable'); +goog.module('Blockly.ICopyable'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.ISelectable'); goog.requireType('Blockly.WorkspaceSvg'); @@ -21,13 +22,13 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.ISelectable} * @interface */ -Blockly.ICopyable = function() {}; +const ICopyable = function() {}; /** * Encode for copying. - * @return {?Blockly.ICopyable.CopyData} Copy metadata. + * @return {?ICopyable.CopyData} Copy metadata. */ -Blockly.ICopyable.prototype.toCopyData; +ICopyable.prototype.toCopyData; /** * Copy Metadata. @@ -37,4 +38,6 @@ Blockly.ICopyable.prototype.toCopyData; * typeCounts:?Object * }} */ -Blockly.ICopyable.CopyData; +ICopyable.CopyData; + +exports = ICopyable; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..230083d23 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -81,7 +81,7 @@ goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['B goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); -goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], []); +goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); From fb512f8b8ecb0221bc8556c9d97d0cf697b5577c Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:57:09 -0700 Subject: [PATCH 099/833] Migrate core/interfaces/i_copyable.js named requires --- core/interfaces/i_copyable.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index db3381fae..07556eb23 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -14,12 +14,12 @@ goog.module('Blockly.ICopyable'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.ISelectable'); -goog.requireType('Blockly.WorkspaceSvg'); +const ISelectable = goog.requireType('Blockly.ISelectable'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** - * @extends {Blockly.ISelectable} + * @extends {ISelectable} * @interface */ const ICopyable = function() {}; @@ -34,7 +34,7 @@ ICopyable.prototype.toCopyData; * Copy Metadata. * @typedef {{ * xml:!Element, - * source:Blockly.WorkspaceSvg, + * source:WorkspaceSvg, * typeCounts:?Object * }} */ From 20079a64aa66b87ca2ee8026801178fb4178ebb3 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 14:38:01 -0700 Subject: [PATCH 100/833] Migrate core/renderers/common/info.js to goog.module --- core/renderers/common/info.js | 56 ++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 9c5d62a9a..6efc4692f 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.RenderInfo'); +goog.module('Blockly.blockRendering.RenderInfo'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.BottomRow'); goog.require('Blockly.blockRendering.ExternalValueInput'); @@ -55,7 +56,7 @@ goog.requireType('Blockly.RenderedConnection'); * @constructor * @package */ -Blockly.blockRendering.RenderInfo = function(renderer, block) { +const RenderInfo = function(renderer, block) { this.block_ = block; /** @@ -174,7 +175,7 @@ Blockly.blockRendering.RenderInfo = function(renderer, block) { * @return {!Blockly.blockRendering.Renderer} The block renderer in use. * @package */ -Blockly.blockRendering.RenderInfo.prototype.getRenderer = function() { +RenderInfo.prototype.getRenderer = function() { return this.renderer_; }; @@ -188,7 +189,7 @@ Blockly.blockRendering.RenderInfo.prototype.getRenderer = function() { * * @package */ -Blockly.blockRendering.RenderInfo.prototype.measure = function() { +RenderInfo.prototype.measure = function() { this.createRows_(); this.addElemSpacing_(); this.addRowSpacing_(); @@ -202,7 +203,7 @@ Blockly.blockRendering.RenderInfo.prototype.measure = function() { * block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { +RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); let activeRow = new Blockly.blockRendering.InputRow(this.constants_); @@ -259,7 +260,7 @@ Blockly.blockRendering.RenderInfo.prototype.createRows_ = function() { * Create all non-spacer elements that belong on the top row. * @package */ -Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { +RenderInfo.prototype.populateTopRow_ = function() { const hasPrevious = !!this.block_.previousConnection; const hasHat = (this.block_.hat ? this.block_.hat === 'cap' : this.constants_.ADD_START_HATS) && @@ -304,7 +305,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateTopRow_ = function() { * Create all non-spacer elements that belong on the bottom row. * @package */ -Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { +RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && @@ -356,7 +357,7 @@ Blockly.blockRendering.RenderInfo.prototype.populateBottomRow_ = function() { * populated. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRow) { +RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. if (this.isInline && input.type == Blockly.inputTypes.VALUE) { activeRow.elements.push( @@ -391,7 +392,7 @@ Blockly.blockRendering.RenderInfo.prototype.addInput_ = function(input, activeRo * @return {boolean} True if the next input should be rendered on a new row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { +RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { // If this is the first input, just add to the existing row. // That row is either empty or has some icons in it. if (!lastInput) { @@ -414,7 +415,7 @@ Blockly.blockRendering.RenderInfo.prototype.shouldStartNewRow_ = function(input, * Add horizontal spacing between and around elements within each row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { +RenderInfo.prototype.addElemSpacing_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { const oldElems = row.elements; row.elements = []; @@ -453,7 +454,7 @@ Blockly.blockRendering.RenderInfo.prototype.addElemSpacing_ = function() { * @return {number} The size of the spacing between the two elements. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { +RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Statement input padding. if (next && Blockly.blockRendering.Types.isStatementInput(next)) { @@ -496,7 +497,7 @@ Blockly.blockRendering.RenderInfo.prototype.getInRowSpacing_ = function(prev, ne * @protected */ // TODO: More cleanup. -Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { +RenderInfo.prototype.computeBounds_ = function() { let widestStatementRowFields = 0; let blockWidth = 0; let widestRowWithConnectedBlocks = 0; @@ -536,7 +537,7 @@ Blockly.blockRendering.RenderInfo.prototype.computeBounds_ = function() { * the sizes of all rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { +RenderInfo.prototype.alignRowElements_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( @@ -561,8 +562,7 @@ Blockly.blockRendering.RenderInfo.prototype.alignRowElements_ = function() { * @return {number} The desired width of the input row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( - _row) { +RenderInfo.prototype.getDesiredRowWidth_ = function(_row) { return this.width - this.startX; }; @@ -574,8 +574,7 @@ Blockly.blockRendering.RenderInfo.prototype.getDesiredRowWidth_ = function( * @param {number} missingSpace How much padding to add. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( - row, missingSpace) { +RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { const firstSpacer = row.getFirstSpacer(); const lastSpacer = row.getLastSpacer(); if (row.hasExternalInput || row.hasStatement) { @@ -606,7 +605,7 @@ Blockly.blockRendering.RenderInfo.prototype.addAlignmentPadding_ = function( * @param {!Blockly.blockRendering.InputRow} row The statement row to resize. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { +RenderInfo.prototype.alignStatementRow_ = function(row) { const statementInput = row.getLastInput(); let currentWidth = row.width - statementInput.width; let desiredWidth = this.statementEdge; @@ -630,7 +629,7 @@ Blockly.blockRendering.RenderInfo.prototype.alignStatementRow_ = function(row) { * Add spacers between rows and set their sizes. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { +RenderInfo.prototype.addRowSpacing_ = function() { const oldRows = this.rows; this.rows = []; @@ -649,8 +648,7 @@ Blockly.blockRendering.RenderInfo.prototype.addRowSpacing_ = function() { * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( - prev, next) { +RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { const height = this.getSpacerRowHeight_(prev, next); const width = this.getSpacerRowWidth_(prev, next); const spacer = @@ -671,8 +669,7 @@ Blockly.blockRendering.RenderInfo.prototype.makeSpacerRow_ = function( * @return {number} The desired width of the spacer row between these two rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function( - _prev, _next) { +RenderInfo.prototype.getSpacerRowWidth_ = function(_prev, _next) { return this.width - this.startX; }; @@ -683,8 +680,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowWidth_ = function( * @return {number} The desired height of the spacer row between these two rows. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function( - _prev, _next) { +RenderInfo.prototype.getSpacerRowHeight_ = function(_prev, _next) { return this.constants_.MEDIUM_PADDING; }; @@ -699,8 +695,7 @@ Blockly.blockRendering.RenderInfo.prototype.getSpacerRowHeight_ = function( * from the top left of the block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, - elem) { +RenderInfo.prototype.getElemCenterline_ = function(row, elem) { if (Blockly.blockRendering.Types.isSpacer(elem)) { return row.yPos + elem.height / 2; } @@ -726,8 +721,7 @@ Blockly.blockRendering.RenderInfo.prototype.getElemCenterline_ = function(row, * @param {!Blockly.blockRendering.Row} row The row containing the elements. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( - row) { +RenderInfo.prototype.recordElemPositions_ = function(row) { let xCursor = row.xPos; for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. @@ -745,7 +739,7 @@ Blockly.blockRendering.RenderInfo.prototype.recordElemPositions_ = function( * store the y position of each row, and record the height of the full block. * @protected */ -Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { +RenderInfo.prototype.finalize_ = function() { // Performance note: this could be combined with the draw pass, if the time // that this takes is excessive. But it shouldn't be, because it only // accesses and sets properties that already exist on the objects. @@ -774,3 +768,5 @@ Blockly.blockRendering.RenderInfo.prototype.finalize_ = function() { this.startY = this.topRow.capline; this.bottomRow.baseline = yCursor - this.bottomRow.descenderHeight; }; + +exports = RenderInfo; diff --git a/tests/deps.js b/tests/deps.js index 5a06dd4ae..8baeee5ab 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); From e23560343ed0d9ab3fc80ae4bd908fd23e12d576 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:45:35 -0700 Subject: [PATCH 101/833] Migrate core/connection_checker.js to named requires --- core/connection_checker.js | 103 ++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index c4086a141..4c350fc9c 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -14,19 +14,18 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.connectionTypes'); +const Connection = goog.require('Blockly.Connection'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +const registry = goog.require('Blockly.registry'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.IConnectionChecker'); -goog.require('Blockly.registry'); - -goog.requireType('Blockly.RenderedConnection'); /** * Class for connection type checking logic. - * @implements {Blockly.IConnectionChecker} + * @implements {IConnectionChecker} * @constructor */ const ConnectionChecker = function() { @@ -35,8 +34,8 @@ const ConnectionChecker = function() { /** * Check whether the current connection can connect with the target * connection. - * @param {Blockly.Connection} a Connection to check compatibility with. - * @param {Blockly.Connection} b Connection to check compatibility with. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. * @param {boolean} isDragging True if the connection is being made by dragging * a block. * @param {number=} opt_distance The max allowable distance between the @@ -47,52 +46,52 @@ const ConnectionChecker = function() { ConnectionChecker.prototype.canConnect = function(a, b, isDragging, opt_distance) { return this.canConnectWithReason(a, b, isDragging, opt_distance) == - Blockly.Connection.CAN_CONNECT; + Connection.CAN_CONNECT; }; /** * Checks whether the current connection can connect with the target * connection, and return an error code if there are problems. - * @param {Blockly.Connection} a Connection to check compatibility with. - * @param {Blockly.Connection} b Connection to check compatibility with. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. * @param {boolean} isDragging True if the connection is being made by dragging * a block. * @param {number=} opt_distance The max allowable distance between the * connections for drag checks. - * @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal, + * @return {number} Connection.CAN_CONNECT if the connection is legal, * an error code otherwise. * @public */ ConnectionChecker.prototype.canConnectWithReason = function( a, b, isDragging, opt_distance) { const safety = this.doSafetyChecks(a, b); - if (safety != Blockly.Connection.CAN_CONNECT) { + if (safety != Connection.CAN_CONNECT) { return safety; } // If the safety checks passed, both connections are non-null. - const connOne = /** @type {!Blockly.Connection} **/ (a); - const connTwo = /** @type {!Blockly.Connection} **/ (b); + const connOne = /** @type {!Connection} **/ (a); + const connTwo = /** @type {!Connection} **/ (b); if (!this.doTypeChecks(connOne, connTwo)) { - return Blockly.Connection.REASON_CHECKS_FAILED; + return Connection.REASON_CHECKS_FAILED; } if (isDragging && !this.doDragChecks( - /** @type {!Blockly.RenderedConnection} **/ (a), - /** @type {!Blockly.RenderedConnection} **/ (b), + /** @type {!RenderedConnection} **/ (a), + /** @type {!RenderedConnection} **/ (b), opt_distance || 0)) { - return Blockly.Connection.REASON_DRAG_CHECKS_FAILED; + return Connection.REASON_DRAG_CHECKS_FAILED; } - return Blockly.Connection.CAN_CONNECT; + return Connection.CAN_CONNECT; }; /** * Helper method that translates a connection error code into a string. * @param {number} errorCode The error code. - * @param {Blockly.Connection} a One of the two connections being checked. - * @param {Blockly.Connection} b The second of the two connections being + * @param {Connection} a One of the two connections being checked. + * @param {Connection} b The second of the two connections being * checked. * @return {string} A developer-readable error string. * @public @@ -100,25 +99,25 @@ ConnectionChecker.prototype.canConnectWithReason = function( ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) { switch (errorCode) { - case Blockly.Connection.REASON_SELF_CONNECTION: + case Connection.REASON_SELF_CONNECTION: return 'Attempted to connect a block to itself.'; - case Blockly.Connection.REASON_DIFFERENT_WORKSPACES: + case Connection.REASON_DIFFERENT_WORKSPACES: // Usually this means one block has been deleted. return 'Blocks not on same workspace.'; - case Blockly.Connection.REASON_WRONG_TYPE: + case Connection.REASON_WRONG_TYPE: return 'Attempt to connect incompatible types.'; - case Blockly.Connection.REASON_TARGET_NULL: + case Connection.REASON_TARGET_NULL: return 'Target connection is null.'; - case Blockly.Connection.REASON_CHECKS_FAILED: { - const connOne = /** @type {!Blockly.Connection} **/ (a); - const connTwo = /** @type {!Blockly.Connection} **/ (b); + case Connection.REASON_CHECKS_FAILED: { + const connOne = /** @type {!Connection} **/ (a); + const connTwo = /** @type {!Connection} **/ (b); let msg = 'Connection checks failed. '; msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck(); return msg; } - case Blockly.Connection.REASON_SHADOW_PARENT: + case Connection.REASON_SHADOW_PARENT: return 'Connecting non-shadow to shadow block.'; - case Blockly.Connection.REASON_DRAG_CHECKS_FAILED: + case Connection.REASON_DRAG_CHECKS_FAILED: return 'Drag checks failed.'; default: return 'Unknown connection failure: this should never happen!'; @@ -128,14 +127,14 @@ ConnectionChecker.prototype.getErrorMessage = function(errorCode, /** * Check that connecting the given connections is safe, meaning that it would * not break any of Blockly's basic assumptions (e.g. no self connections). - * @param {Blockly.Connection} a The first of the connections to check. - * @param {Blockly.Connection} b The second of the connections to check. + * @param {Connection} a The first of the connections to check. + * @param {Connection} b The second of the connections to check. * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { - return Blockly.Connection.REASON_TARGET_NULL; + return Connection.REASON_TARGET_NULL; } let blockA, blockB; if (a.isSuperior()) { @@ -146,23 +145,23 @@ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { blockA = b.getSourceBlock(); } if (blockA == blockB) { - return Blockly.Connection.REASON_SELF_CONNECTION; + return Connection.REASON_SELF_CONNECTION; } else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) { - return Blockly.Connection.REASON_WRONG_TYPE; + return Connection.REASON_WRONG_TYPE; } else if (blockA.workspace !== blockB.workspace) { - return Blockly.Connection.REASON_DIFFERENT_WORKSPACES; + return Connection.REASON_DIFFERENT_WORKSPACES; } else if (blockA.isShadow() && !blockB.isShadow()) { - return Blockly.Connection.REASON_SHADOW_PARENT; + return Connection.REASON_SHADOW_PARENT; } - return Blockly.Connection.CAN_CONNECT; + return Connection.CAN_CONNECT; }; /** * Check whether this connection is compatible with another connection with * respect to the value type system. E.g. square_root("Hello") is not * compatible. - * @param {!Blockly.Connection} a Connection to compare. - * @param {!Blockly.Connection} b Connection to compare against. + * @param {!Connection} a Connection to compare. + * @param {!Connection} b Connection to compare against. * @return {boolean} True if the connections share a type. * @public */ @@ -186,8 +185,8 @@ ConnectionChecker.prototype.doTypeChecks = function(a, b) { /** * Check whether this connection can be made by dragging. - * @param {!Blockly.RenderedConnection} a Connection to compare. - * @param {!Blockly.RenderedConnection} b Connection to compare against. + * @param {!RenderedConnection} a Connection to compare. + * @param {!RenderedConnection} b Connection to compare against. * @param {number} distance The maximum allowable distance between connections. * @return {boolean} True if the connection is allowed during a drag. * @public @@ -203,9 +202,9 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } switch (b.type) { - case Blockly.connectionTypes.PREVIOUS_STATEMENT: + case connectionTypes.PREVIOUS_STATEMENT: return this.canConnectToPrevious_(a, b); - case Blockly.connectionTypes.OUTPUT_VALUE: { + case connectionTypes.OUTPUT_VALUE: { // Don't offer to connect an already connected left (male) value plug to // an available right (female) value plug. if ((b.isConnected() && @@ -215,7 +214,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } break; } - case Blockly.connectionTypes.INPUT_VALUE: { + case connectionTypes.INPUT_VALUE: { // Offering to connect the left (male) of a value block to an already // connected value pair is ok, we'll splice it in. // However, don't offer to splice into an immovable block. @@ -226,7 +225,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { } break; } - case Blockly.connectionTypes.NEXT_STATEMENT: { + case connectionTypes.NEXT_STATEMENT: { // Don't let a block with no next connection bump other blocks out of the // stack. But covering up a shadow block or stack of shadow blocks is // fine. Similarly, replacing a terminal statement with another terminal @@ -254,9 +253,9 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { /** * Helper function for drag checking. - * @param {!Blockly.Connection} a The connection to check, which must be a + * @param {!Connection} a The connection to check, which must be a * statement input or next connection. - * @param {!Blockly.Connection} b A nearby connection to check, which + * @param {!Connection} b A nearby connection to check, which * must be a previous connection. * @return {boolean} True if the connection is allowed, false otherwise. * @protected @@ -288,7 +287,7 @@ ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { return !targetBlock.getPreviousBlock(); }; -Blockly.registry.register(Blockly.registry.Type.CONNECTION_CHECKER, - Blockly.registry.DEFAULT, ConnectionChecker); +registry.register(registry.Type.CONNECTION_CHECKER, + registry.DEFAULT, ConnectionChecker); exports = ConnectionChecker; From 5b9505802e4aea4e403cb1ef4fcc1adbd6a92f67 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 14:46:07 -0700 Subject: [PATCH 102/833] clang-format core/connection_checker.js --- core/connection_checker.js | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 4c350fc9c..3a405edcb 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -5,8 +5,8 @@ */ /** - * @fileoverview An object that encapsulates logic for checking whether a potential - * connection is safe and valid. + * @fileoverview An object that encapsulates logic for checking whether a + * potential connection is safe and valid. * @author fenichel@google.com (Rachel Fenichel) */ 'use strict'; @@ -28,8 +28,7 @@ goog.require('Blockly.constants'); * @implements {IConnectionChecker} * @constructor */ -const ConnectionChecker = function() { -}; +const ConnectionChecker = function() {}; /** * Check whether the current connection can connect with the target @@ -43,8 +42,8 @@ const ConnectionChecker = function() { * @return {boolean} Whether the connection is legal. * @public */ -ConnectionChecker.prototype.canConnect = function(a, b, - isDragging, opt_distance) { +ConnectionChecker.prototype.canConnect = function( + a, b, isDragging, opt_distance) { return this.canConnectWithReason(a, b, isDragging, opt_distance) == Connection.CAN_CONNECT; }; @@ -79,8 +78,7 @@ ConnectionChecker.prototype.canConnectWithReason = function( if (isDragging && !this.doDragChecks( /** @type {!RenderedConnection} **/ (a), - /** @type {!RenderedConnection} **/ (b), - opt_distance || 0)) { + /** @type {!RenderedConnection} **/ (b), opt_distance || 0)) { return Connection.REASON_DRAG_CHECKS_FAILED; } @@ -96,8 +94,7 @@ ConnectionChecker.prototype.canConnectWithReason = function( * @return {string} A developer-readable error string. * @public */ -ConnectionChecker.prototype.getErrorMessage = function(errorCode, - a, b) { +ConnectionChecker.prototype.getErrorMessage = function(errorCode, a, b) { switch (errorCode) { case Connection.REASON_SELF_CONNECTION: return 'Attempted to connect a block to itself.'; @@ -112,7 +109,8 @@ ConnectionChecker.prototype.getErrorMessage = function(errorCode, const connOne = /** @type {!Connection} **/ (a); const connTwo = /** @type {!Connection} **/ (b); let msg = 'Connection checks failed. '; - msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + connTwo.getCheck(); + msg += connOne + ' expected ' + connOne.getCheck() + ', found ' + + connTwo.getCheck(); return msg; } case Connection.REASON_SHADOW_PARENT: @@ -207,8 +205,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { case connectionTypes.OUTPUT_VALUE: { // Don't offer to connect an already connected left (male) value plug to // an available right (female) value plug. - if ((b.isConnected() && - !b.targetBlock().isInsertionMarker()) || + if ((b.isConnected() && !b.targetBlock().isInsertionMarker()) || a.isConnected()) { return false; } @@ -218,8 +215,7 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { // Offering to connect the left (male) of a value block to an already // connected value pair is ok, we'll splice it in. // However, don't offer to splice into an immovable block. - if (b.isConnected() && - !b.targetBlock().isMovable() && + if (b.isConnected() && !b.targetBlock().isMovable() && !b.targetBlock().isShadow()) { return false; } @@ -230,10 +226,8 @@ ConnectionChecker.prototype.doDragChecks = function(a, b, distance) { // stack. But covering up a shadow block or stack of shadow blocks is // fine. Similarly, replacing a terminal statement with another terminal // statement is allowed. - if (b.isConnected() && - !a.getSourceBlock().nextConnection && - !b.targetBlock().isShadow() && - b.targetBlock().nextConnection) { + if (b.isConnected() && !a.getSourceBlock().nextConnection && + !b.targetBlock().isShadow() && b.targetBlock().nextConnection) { return false; } break; @@ -287,7 +281,7 @@ ConnectionChecker.prototype.canConnectToPrevious_ = function(a, b) { return !targetBlock.getPreviousBlock(); }; -registry.register(registry.Type.CONNECTION_CHECKER, - registry.DEFAULT, ConnectionChecker); +registry.register( + registry.Type.CONNECTION_CHECKER, registry.DEFAULT, ConnectionChecker); exports = ConnectionChecker; From f38a4519878a0e6c70218af505c4aaf5a01eaef7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:11:19 -0700 Subject: [PATCH 103/833] Migrate core/comment.js to ES6 const/let --- core/comment.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/comment.js b/core/comment.js index 7917b2ec5..5e867d9df 100644 --- a/core/comment.js +++ b/core/comment.js @@ -152,13 +152,13 @@ Blockly.Comment.prototype.createEditor_ = function() { {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, null); - var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); + const body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS( Blockly.utils.dom.HTML_NS, 'textarea'); - var textarea = this.textarea_; + const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); textarea.value = this.model_.text; @@ -228,10 +228,10 @@ Blockly.Comment.prototype.onBubbleResize_ = function() { * @private */ Blockly.Comment.prototype.resizeTextarea_ = function() { - var size = this.model_.size; - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; - var widthMinusBorder = size.width - doubleBorderWidth; - var heightMinusBorder = size.height - doubleBorderWidth; + const size = this.model_.size; + const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const widthMinusBorder = size.width - doubleBorderWidth; + const heightMinusBorder = size.height - doubleBorderWidth; this.foreignObject_.setAttribute('width', widthMinusBorder); this.foreignObject_.setAttribute('height', heightMinusBorder); this.textarea_.style.width = (widthMinusBorder - 4) + 'px'; From 530964e03b83a26f0e6880040bc73dcdad8dabed Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:15:42 -0700 Subject: [PATCH 104/833] Migrate core/comment.js to goog.module --- core/comment.js | 43 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/core/comment.js b/core/comment.js index 5e867d9df..1e585d63c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Comment'); +goog.module('Blockly.Comment'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Bubble'); @@ -41,8 +42,8 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Comment = function(block) { - Blockly.Comment.superClass_.constructor.call(this, block); +const Comment = function(block) { + Comment.superClass_.constructor.call(this, block); /** * The model for this comment. @@ -92,14 +93,14 @@ Blockly.Comment = function(block) { this.createIcon(); }; -Blockly.utils.object.inherits(Blockly.Comment, Blockly.Icon); +Blockly.utils.object.inherits(Comment, Blockly.Icon); /** * Draw the comment icon. * @param {!Element} group The icon group. * @protected */ -Blockly.Comment.prototype.drawIcon_ = function(group) { +Comment.prototype.drawIcon_ = function(group) { // Circle. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CIRCLE, @@ -134,7 +135,7 @@ Blockly.Comment.prototype.drawIcon_ = function(group) { * @return {!SVGElement} The top-level node of the editor. * @private */ -Blockly.Comment.prototype.createEditor_ = function() { +Comment.prototype.createEditor_ = function() { /* Create the editor. Here's the markup that will be generated in * editable mode: @@ -200,8 +201,8 @@ Blockly.Comment.prototype.createEditor_ = function() { * Add or remove editability of the comment. * @override */ -Blockly.Comment.prototype.updateEditable = function() { - Blockly.Comment.superClass_.updateEditable.call(this); +Comment.prototype.updateEditable = function() { + Comment.superClass_.updateEditable.call(this); if (this.isVisible()) { // Recreate the bubble with the correct UI. this.disposeBubble_(); @@ -214,7 +215,7 @@ Blockly.Comment.prototype.updateEditable = function() { * Resize the text area accordingly. * @private */ -Blockly.Comment.prototype.onBubbleResize_ = function() { +Comment.prototype.onBubbleResize_ = function() { if (!this.isVisible()) { return; } @@ -227,7 +228,7 @@ Blockly.Comment.prototype.onBubbleResize_ = function() { * the size of the bubble). * @private */ -Blockly.Comment.prototype.resizeTextarea_ = function() { +Comment.prototype.resizeTextarea_ = function() { const size = this.model_.size; const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; const widthMinusBorder = size.width - doubleBorderWidth; @@ -242,7 +243,7 @@ Blockly.Comment.prototype.resizeTextarea_ = function() { * Show or hide the comment bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Comment.prototype.setVisible = function(visible) { +Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } @@ -260,7 +261,7 @@ Blockly.Comment.prototype.setVisible = function(visible) { * Show the bubble. Handles deciding if it should be editable or not. * @private */ -Blockly.Comment.prototype.createBubble_ = function() { +Comment.prototype.createBubble_ = function() { if (!this.block_.isEditable() || Blockly.utils.userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 @@ -275,7 +276,7 @@ Blockly.Comment.prototype.createBubble_ = function() { * Show an editable bubble. * @private */ -Blockly.Comment.prototype.createEditableBubble_ = function() { +Comment.prototype.createEditableBubble_ = function() { this.bubble_ = new Blockly.Bubble( /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, @@ -292,7 +293,7 @@ Blockly.Comment.prototype.createEditableBubble_ = function() { * @private * @suppress {checkTypes} Suppress `this` type mismatch. */ -Blockly.Comment.prototype.createNonEditableBubble_ = function() { +Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. this.paragraphElement_ = Blockly.Bubble.textToDom(this.block_.getCommentText()); this.bubble_ = Blockly.Bubble.createNonEditableBubble( @@ -306,7 +307,7 @@ Blockly.Comment.prototype.createNonEditableBubble_ = function() { * @private * @suppress {checkTypes} Suppress `this` type mismatch. */ -Blockly.Comment.prototype.disposeBubble_ = function() { +Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { Blockly.browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; @@ -338,7 +339,7 @@ Blockly.Comment.prototype.disposeBubble_ = function() { * @param {!Event} _e Mouse up event. * @private */ -Blockly.Comment.prototype.startEdit_ = function(_e) { +Comment.prototype.startEdit_ = function(_e) { if (this.bubble_.promote()) { // Since the act of moving this node within the DOM causes a loss of focus, // we need to reapply the focus. @@ -352,7 +353,7 @@ Blockly.Comment.prototype.startEdit_ = function(_e) { * Get the dimensions of this comment's bubble. * @return {Blockly.utils.Size} Object with width and height properties. */ -Blockly.Comment.prototype.getBubbleSize = function() { +Comment.prototype.getBubbleSize = function() { return this.model_.size; }; @@ -361,7 +362,7 @@ Blockly.Comment.prototype.getBubbleSize = function() { * @param {number} width Width of the bubble. * @param {number} height Height of the bubble. */ -Blockly.Comment.prototype.setBubbleSize = function(width, height) { +Comment.prototype.setBubbleSize = function(width, height) { if (this.bubble_) { this.bubble_.setBubbleSize(width, height); } else { @@ -374,7 +375,7 @@ Blockly.Comment.prototype.setBubbleSize = function(width, height) { * Update the comment's view to match the model. * @package */ -Blockly.Comment.prototype.updateText = function() { +Comment.prototype.updateText = function() { if (this.textarea_) { this.textarea_.value = this.model_.text; } else if (this.paragraphElement_) { @@ -390,7 +391,7 @@ Blockly.Comment.prototype.updateText = function() { * If you want to receive a comment "delete" event (newValue: null), then this * should not be called directly. Instead call block.setCommentText(null); */ -Blockly.Comment.prototype.dispose = function() { +Comment.prototype.dispose = function() { this.block_.comment = null; Blockly.Icon.prototype.dispose.call(this); }; @@ -412,3 +413,5 @@ Blockly.Css.register([ '}' /* eslint-enable indent */ ]); + +exports = Comment; diff --git a/tests/deps.js b/tests/deps.js index 5f5f93d89..f04468cf7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -17,7 +17,7 @@ goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6 goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']); From 30a6948a9a30a04ad60de79831d56a3a0ea79e82 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:37:05 -0700 Subject: [PATCH 105/833] Migrate core/comment.js to named requires --- core/comment.js | 116 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/core/comment.js b/core/comment.js index 1e585d63c..18615d669 100644 --- a/core/comment.js +++ b/core/comment.js @@ -13,33 +13,33 @@ goog.module('Blockly.Comment'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Bubble'); -goog.require('Blockly.Css'); -goog.require('Blockly.Events'); +const Block = goog.requireType('Blockly.Block'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const Bubble = goog.require('Blockly.Bubble'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const Css = goog.require('Blockly.Css'); +const dom = goog.require('Blockly.utils.dom'); +const Events = goog.require('Blockly.Events'); +const Icon = goog.require('Blockly.Icon'); +const Size = goog.requireType('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utilsObject = goog.require('Blockly.utils.object'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {CommentModel} = goog.requireType('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); -goog.require('Blockly.Icon'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Warning'); -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.utils.Size'); -goog.requireType('Blockly.WorkspaceSvg'); - /** * Class for a comment. - * @param {!Blockly.Block} block The block associated with this comment. - * @extends {Blockly.Icon} + * @param {!Block} block The block associated with this comment. + * @extends {Icon} * @constructor */ const Comment = function(block) { @@ -47,7 +47,7 @@ const Comment = function(block) { /** * The model for this comment. - * @type {!Blockly.Block.CommentModel} + * @type {!CommentModel} * @private */ this.model_ = block.commentModel; @@ -65,35 +65,35 @@ const Comment = function(block) { /** * Mouse up event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseUpWrapper_ = null; /** * Wheel event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onWheelWrapper_ = null; /** * Change event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onChangeWrapper_ = null; /** * Input event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onInputWrapper_ = null; this.createIcon(); }; -Blockly.utils.object.inherits(Comment, Blockly.Icon); +utilsObject.inherits(Comment, Icon); /** * Draw the comment icon. @@ -102,15 +102,15 @@ Blockly.utils.object.inherits(Comment, Blockly.Icon); */ Comment.prototype.drawIcon_ = function(group) { // Circle. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + dom.createSvgElement( + Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + @@ -118,8 +118,8 @@ Comment.prototype.drawIcon_ = function(group) { '-1.201,0.998 -1.201,1.528 -1.204,2.19z'}, group); // Dot of question mark. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', @@ -148,17 +148,17 @@ Comment.prototype.createEditor_ = function() { * For non-editable mode see Warning.textToDom_. */ - this.foreignObject_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FOREIGNOBJECT, - {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, + this.foreignObject_ = dom.createSvgElement( + Svg.FOREIGNOBJECT, + {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); - const body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); - body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); + const body = document.createElementNS(dom.HTML_NS, 'body'); + body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; this.textarea_ = document.createElementNS( - Blockly.utils.dom.HTML_NS, 'textarea'); + dom.HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -171,23 +171,23 @@ Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseUpWrapper_ = browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = Blockly.browserEvents.conditionalBind( + this.onWheelWrapper_ = browserEvents.conditionalBind( textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = Blockly.browserEvents.conditionalBind( + this.onChangeWrapper_ = browserEvents.conditionalBind( textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire( + new (Events.get(Events.BLOCK_CHANGE))( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = Blockly.browserEvents.conditionalBind( + this.onInputWrapper_ = browserEvents.conditionalBind( textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -230,7 +230,7 @@ Comment.prototype.onBubbleResize_ = function() { */ Comment.prototype.resizeTextarea_ = function() { const size = this.model_.size; - const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; const widthMinusBorder = size.width - doubleBorderWidth; const heightMinusBorder = size.height - doubleBorderWidth; this.foreignObject_.setAttribute('width', widthMinusBorder); @@ -247,7 +247,7 @@ Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + Events.fire(new (Events.get(Events.BUBBLE_OPEN))( this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { @@ -262,7 +262,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || Blockly.utils.userAgent.IE) { + if (!this.block_.isEditable() || userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. @@ -277,10 +277,10 @@ Comment.prototype.createBubble_ = function() { * @private */ Comment.prototype.createEditableBubble_ = function() { - this.bubble_ = new Blockly.Bubble( - /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), + this.bubble_ = new Bubble( + /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_), + /** @type {!Coordinate} */ (this.iconXY_), this.model_.size.width, this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); @@ -295,10 +295,10 @@ Comment.prototype.createEditableBubble_ = function() { */ Comment.prototype.createNonEditableBubble_ = function() { // TODO (#2917): It would be great if the comment could support line breaks. - this.paragraphElement_ = Blockly.Bubble.textToDom(this.block_.getCommentText()); - this.bubble_ = Blockly.Bubble.createNonEditableBubble( - this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_)); + this.paragraphElement_ = Bubble.textToDom(this.block_.getCommentText()); + this.bubble_ = Bubble.createNonEditableBubble( + this.paragraphElement_, /** @type {!BlockSvg} */ (this.block_), + /** @type {!Coordinate} */ (this.iconXY_)); this.applyColour(); }; @@ -309,19 +309,19 @@ Comment.prototype.createNonEditableBubble_ = function() { */ Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + browserEvents.unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - Blockly.browserEvents.unbind(this.onWheelWrapper_); + browserEvents.unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - Blockly.browserEvents.unbind(this.onChangeWrapper_); + browserEvents.unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - Blockly.browserEvents.unbind(this.onInputWrapper_); + browserEvents.unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); @@ -351,7 +351,7 @@ Comment.prototype.startEdit_ = function(_e) { /** * Get the dimensions of this comment's bubble. - * @return {Blockly.utils.Size} Object with width and height properties. + * @return {Size} Object with width and height properties. */ Comment.prototype.getBubbleSize = function() { return this.model_.size; @@ -393,13 +393,13 @@ Comment.prototype.updateText = function() { */ Comment.prototype.dispose = function() { this.block_.comment = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; /** * CSS for block comment. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyCommentTextarea {', 'background-color: #fef49c;', From d1ae27eb6071981e60751fa44244790e15c9bfa1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 16 Jul 2021 13:38:00 -0700 Subject: [PATCH 106/833] clang-format core/comment.js --- core/comment.js | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/core/comment.js b/core/comment.js index 18615d669..fe0c940a6 100644 --- a/core/comment.js +++ b/core/comment.js @@ -103,24 +103,22 @@ utilsObject.inherits(Comment, Icon); Comment.prototype.drawIcon_ = function(group) { // Circle. dom.createSvgElement( - Svg.CIRCLE, - {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, + Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + - '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + - '-1.201,0.998 -1.201,1.528 -1.204,2.19z'}, + '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' + + '-1.201,0.998 -1.201,1.528 -1.204,2.19z' + }, group); // Dot of question mark. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', 'y': '10.78', @@ -149,16 +147,14 @@ Comment.prototype.createEditor_ = function() { */ this.foreignObject_ = dom.createSvgElement( - Svg.FOREIGNOBJECT, - {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, + Svg.FOREIGNOBJECT, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); const body = document.createElementNS(dom.HTML_NS, 'body'); body.setAttribute('xmlns', dom.HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS( - dom.HTML_NS, 'textarea'); + this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -174,21 +170,20 @@ Comment.prototype.createEditor_ = function() { this.onMouseUpWrapper_ = browserEvents.conditionalBind( textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = browserEvents.conditionalBind( - textarea, 'wheel', this, function(e) { + this.onWheelWrapper_ = + browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - this.onChangeWrapper_ = browserEvents.conditionalBind( - textarea, 'change', this, function(_e) { + this.onChangeWrapper_ = + browserEvents.conditionalBind(textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { - Events.fire( - new (Events.get(Events.BLOCK_CHANGE))( - this.block_, 'comment', null, this.cachedText_, - this.model_.text)); + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( + this.block_, 'comment', null, this.cachedText_, + this.model_.text)); } }); - this.onInputWrapper_ = browserEvents.conditionalBind( - textarea, 'input', this, function(_e) { + this.onInputWrapper_ = + browserEvents.conditionalBind(textarea, 'input', this, function(_e) { this.model_.text = textarea.value; }); @@ -247,8 +242,8 @@ Comment.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'comment')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'comment')); this.model_.pinned = visible; if (visible) { this.createBubble_(); @@ -280,8 +275,8 @@ Comment.prototype.createEditableBubble_ = function() { this.bubble_ = new Bubble( /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Coordinate} */ (this.iconXY_), - this.model_.size.width, this.model_.size.height); + /** @type {!Coordinate} */ (this.iconXY_), this.model_.size.width, + this.model_.size.height); // Expose this comment's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerResizeEvent(this.onBubbleResize_.bind(this)); From b3877ffbb9e720351bb2e3aa27982584233fffe1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 15:13:41 -0700 Subject: [PATCH 107/833] Migrate core/renderers/common/info.js to named requires --- core/renderers/common/info.js | 249 ++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 118 insertions(+), 133 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 6efc4692f..3c5e70ee4 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -13,35 +13,34 @@ goog.module('Blockly.blockRendering.RenderInfo'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.BottomRow'); -goog.require('Blockly.blockRendering.ExternalValueInput'); -goog.require('Blockly.blockRendering.Field'); -goog.require('Blockly.blockRendering.Hat'); -goog.require('Blockly.blockRendering.InlineInput'); -goog.require('Blockly.blockRendering.InputRow'); -goog.require('Blockly.blockRendering.InRowSpacer'); -goog.require('Blockly.blockRendering.JaggedEdge'); -goog.require('Blockly.blockRendering.Measurable'); -goog.require('Blockly.blockRendering.NextConnection'); -goog.require('Blockly.blockRendering.OutputConnection'); -goog.require('Blockly.blockRendering.PreviousConnection'); -goog.require('Blockly.blockRendering.RoundCorner'); -goog.require('Blockly.blockRendering.Row'); -goog.require('Blockly.blockRendering.SpacerRow'); -goog.require('Blockly.blockRendering.SquareCorner'); -goog.require('Blockly.blockRendering.StatementInput'); -goog.require('Blockly.blockRendering.TopRow'); -goog.require('Blockly.blockRendering.Types'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const BottomRow = goog.require('Blockly.blockRendering.BottomRow'); +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +const ExternalValueInput = goog.require('Blockly.blockRendering.ExternalValueInput'); +const Field = goog.require('Blockly.blockRendering.Field'); +const Hat = goog.require('Blockly.blockRendering.Hat'); +const Icon = goog.require('Blockly.blockRendering.Icon'); +const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); +const Input = goog.requireType('Blockly.Input'); +const InputRow = goog.require('Blockly.blockRendering.InputRow'); +const inputTypes = goog.require('Blockly.inputTypes'); +const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); +const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); +const Measurable = goog.require('Blockly.blockRendering.Measurable'); +const NextConnection = goog.require('Blockly.blockRendering.NextConnection'); +const OutputConnection = goog.require('Blockly.blockRendering.OutputConnection'); +const PreviousConnection = goog.require('Blockly.blockRendering.PreviousConnection'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +const RoundCorner = goog.require('Blockly.blockRendering.RoundCorner'); +const Row = goog.require('Blockly.blockRendering.Row'); +const SpacerRow = goog.require('Blockly.blockRendering.SpacerRow'); +const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); +const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); +const TopRow = goog.require('Blockly.blockRendering.TopRow'); +const Types = goog.require('Blockly.blockRendering.Types'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.blockRendering.Icon'); -goog.requireType('Blockly.blockRendering.Renderer'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.RenderedConnection'); +const blocklyConstants = goog.require('Blockly.constants'); /** @@ -51,8 +50,8 @@ goog.requireType('Blockly.RenderedConnection'); * may choose to rerender when getSize() is called). However, calling it * repeatedly may be expensive. * - * @param {!Blockly.blockRendering.Renderer} renderer The renderer in use. - * @param {!Blockly.BlockSvg} block The block to measure. + * @param {!Renderer} renderer The renderer in use. + * @param {!BlockSvg} block The block to measure. * @constructor * @package */ @@ -61,14 +60,14 @@ const RenderInfo = function(renderer, block) { /** * The block renderer in use. - * @type {!Blockly.blockRendering.Renderer} + * @type {!Renderer} * @protected */ this.renderer_ = renderer; /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @protected */ this.constants_ = this.renderer_.getConstants(); @@ -76,12 +75,13 @@ const RenderInfo = function(renderer, block) { /** * A measurable representing the output connection if the block has one. * Otherwise null. - * @type {Blockly.blockRendering.OutputConnection} + * @type {OutputConnection} */ - this.outputConnection = !block.outputConnection ? null : - new Blockly.blockRendering.OutputConnection( + this.outputConnection = !block.outputConnection ? + null : + new OutputConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */(block.outputConnection)); + /** @type {RenderedConnection} */ (block.outputConnection)); /** * Whether the block should be rendered as a single line, either because it's @@ -136,33 +136,33 @@ const RenderInfo = function(renderer, block) { /** * An array of Row objects containing sizing information. - * @type {!Array} + * @type {!Array} */ this.rows = []; /** * An array of input rows on the block. - * @type {!Array} + * @type {!Array} */ this.inputRows = []; /** * An array of measurable objects containing hidden icons. - * @type {!Array} + * @type {!Array} */ this.hiddenIcons = []; /** * An object with rendering information about the top row of the block. - * @type {!Blockly.blockRendering.TopRow} + * @type {!TopRow} */ - this.topRow = new Blockly.blockRendering.TopRow(this.constants_); + this.topRow = new TopRow(this.constants_); /** * An object with rendering information about the bottom row of the block. - * @type {!Blockly.blockRendering.BottomRow} + * @type {!BottomRow} */ - this.bottomRow = new Blockly.blockRendering.BottomRow(this.constants_); + this.bottomRow = new BottomRow(this.constants_); // The position of the start point for drawing, relative to the block's // location. @@ -172,7 +172,7 @@ const RenderInfo = function(renderer, block) { /** * Get the block renderer in use. - * @return {!Blockly.blockRendering.Renderer} The block renderer in use. + * @return {!Renderer} The block renderer in use. * @package */ RenderInfo.prototype.getRenderer = function() { @@ -206,13 +206,13 @@ RenderInfo.prototype.measure = function() { RenderInfo.prototype.createRows_ = function() { this.populateTopRow_(); this.rows.push(this.topRow); - let activeRow = new Blockly.blockRendering.InputRow(this.constants_); + let activeRow = new InputRow(this.constants_); this.inputRows.push(activeRow); // Icons always go on the first row, before anything else. const icons = this.block_.getIcons(); for (let i = 0, icon; (icon = icons[i]); i++) { - const iconInfo = new Blockly.blockRendering.Icon(this.constants_, icon); + const iconInfo = new Icon(this.constants_, icon); if (this.isCollapsed && icon.collapseHidden) { this.hiddenIcons.push(iconInfo); } else { @@ -230,14 +230,13 @@ RenderInfo.prototype.createRows_ = function() { if (this.shouldStartNewRow_(input, lastInput)) { // Finish this row and create a new one. this.rows.push(activeRow); - activeRow = new Blockly.blockRendering.InputRow(this.constants_); + activeRow = new InputRow(this.constants_); this.inputRows.push(activeRow); } // All of the fields in an input go on the same row. for (let j = 0, field; (field = input.fieldRow[j]); j++) { - activeRow.elements.push( - new Blockly.blockRendering.Field(this.constants_, field, input)); + activeRow.elements.push(new Field(this.constants_, field, input)); } this.addInput_(input, activeRow); lastInput = input; @@ -245,8 +244,7 @@ RenderInfo.prototype.createRows_ = function() { if (this.isCollapsed) { activeRow.hasJaggedEdge = true; - activeRow.elements.push( - new Blockly.blockRendering.JaggedEdge(this.constants_)); + activeRow.elements.push(new JaggedEdge(this.constants_)); } if (activeRow.elements.length || activeRow.hasDummyInput) { @@ -266,26 +264,25 @@ RenderInfo.prototype.populateTopRow_ = function() { this.constants_.ADD_START_HATS) && !this.outputConnection && !hasPrevious; - let cornerClass = this.topRow.hasLeftSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : - Blockly.blockRendering.RoundCorner; + let cornerClass = + this.topRow.hasLeftSquareCorner(this.block_) ? SquareCorner : RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_)); if (hasHat) { - const hat = new Blockly.blockRendering.Hat(this.constants_); + const hat = new Hat(this.constants_); this.topRow.elements.push(hat); this.topRow.capline = hat.ascenderHeight; } else if (hasPrevious) { this.topRow.hasPreviousConnection = true; - this.topRow.connection = new Blockly.blockRendering.PreviousConnection( + this.topRow.connection = new PreviousConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */ + /** @type {RenderedConnection} */ (this.block_.previousConnection)); this.topRow.elements.push(this.topRow.connection); } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type == Blockly.inputTypes.STATEMENT; + this.block_.inputList[0].type == inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -296,8 +293,8 @@ RenderInfo.prototype.populateTopRow_ = function() { this.topRow.minHeight = this.constants_.TOP_ROW_MIN_HEIGHT; } - cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? - Blockly.blockRendering.SquareCorner : Blockly.blockRendering.RoundCorner; + cornerClass = this.topRow.hasRightSquareCorner(this.block_) ? SquareCorner : + RoundCorner; this.topRow.elements.push(new cornerClass(this.constants_, 'right')); }; @@ -310,7 +307,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { const followsStatement = this.block_.inputList.length && this.block_.inputList[this.block_.inputList.length - 1].type == - Blockly.inputTypes.STATEMENT; + inputTypes.STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -324,54 +321,47 @@ RenderInfo.prototype.populateBottomRow_ = function() { const leftSquareCorner = this.bottomRow.hasLeftSquareCorner(this.block_); if (leftSquareCorner) { - this.bottomRow.elements.push( - new Blockly.blockRendering.SquareCorner(this.constants_)); + this.bottomRow.elements.push(new SquareCorner(this.constants_)); } else { - this.bottomRow.elements.push( - new Blockly.blockRendering.RoundCorner(this.constants_)); + this.bottomRow.elements.push(new RoundCorner(this.constants_)); } if (this.bottomRow.hasNextConnection) { - this.bottomRow.connection = new Blockly.blockRendering.NextConnection( + this.bottomRow.connection = new NextConnection( this.constants_, - /** @type {Blockly.RenderedConnection} */ (this.block_.nextConnection)); + /** @type {RenderedConnection} */ (this.block_.nextConnection)); this.bottomRow.elements.push(this.bottomRow.connection); } const rightSquareCorner = this.bottomRow.hasRightSquareCorner(this.block_); if (rightSquareCorner) { - this.bottomRow.elements.push( - new Blockly.blockRendering.SquareCorner(this.constants_, 'right')); + this.bottomRow.elements.push(new SquareCorner(this.constants_, 'right')); } else { - this.bottomRow.elements.push( - new Blockly.blockRendering.RoundCorner(this.constants_, 'right')); + this.bottomRow.elements.push(new RoundCorner(this.constants_, 'right')); } }; /** * Add an input element to the active row, if needed, and record the type of the * input on the row. - * @param {!Blockly.Input} input The input to record information about. - * @param {!Blockly.blockRendering.Row} activeRow The row that is currently being + * @param {!Input} input The input to record information about. + * @param {!Row} activeRow The row that is currently being * populated. * @protected */ RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. - if (this.isInline && input.type == Blockly.inputTypes.VALUE) { - activeRow.elements.push( - new Blockly.blockRendering.InlineInput(this.constants_, input)); + if (this.isInline && input.type == inputTypes.VALUE) { + activeRow.elements.push(new InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == Blockly.inputTypes.STATEMENT) { - activeRow.elements.push( - new Blockly.blockRendering.StatementInput(this.constants_, input)); + } else if (input.type == inputTypes.STATEMENT) { + activeRow.elements.push(new StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == Blockly.inputTypes.VALUE) { - activeRow.elements.push( - new Blockly.blockRendering.ExternalValueInput(this.constants_, input)); + } else if (input.type == inputTypes.VALUE) { + activeRow.elements.push(new ExternalValueInput(this.constants_, input)); activeRow.hasExternalInput = true; - } else if (input.type == Blockly.inputTypes.DUMMY) { + } else if (input.type == inputTypes.DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. activeRow.minHeight = Math.max(activeRow.minHeight, @@ -387,8 +377,8 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) { /** * Decide whether to start a new row between the two Blockly.Inputs. - * @param {!Blockly.Input} input The first input to consider - * @param {Blockly.Input} lastInput The input that follows. + * @param {!Input} input The first input to consider + * @param {Input} lastInput The input that follows. * @return {boolean} True if the next input should be rendered on a new row. * @protected */ @@ -399,13 +389,12 @@ RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { return false; } // A statement input or an input following one always gets a new row. - if (input.type == Blockly.inputTypes.STATEMENT || - lastInput.type == Blockly.inputTypes.STATEMENT) { + if (input.type == inputTypes.STATEMENT || + lastInput.type == inputTypes.STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. - if (input.type == Blockly.inputTypes.VALUE || - input.type == Blockly.inputTypes.DUMMY) { + if (input.type == inputTypes.VALUE || input.type == inputTypes.DUMMY) { return !this.isInline; } return false; @@ -422,7 +411,7 @@ RenderInfo.prototype.addElemSpacing_ = function() { // No spacing needed before the corner on the top row or the bottom row. if (row.startsWithElemSpacer()) { // There's a spacer before the first element in the row. - row.elements.push(new Blockly.blockRendering.InRowSpacer( + row.elements.push(new InRowSpacer( this.constants_, this.getInRowSpacing_(null, oldElems[0]))); } if (!oldElems.length) { @@ -431,13 +420,12 @@ RenderInfo.prototype.addElemSpacing_ = function() { for (let e = 0; e < oldElems.length - 1; e++) { row.elements.push(oldElems[e]); const spacing = this.getInRowSpacing_(oldElems[e], oldElems[e + 1]); - row.elements.push( - new Blockly.blockRendering.InRowSpacer(this.constants_, spacing)); + row.elements.push(new InRowSpacer(this.constants_, spacing)); } row.elements.push(oldElems[oldElems.length - 1]); if (row.endsWithElemSpacer()) { // There's a spacer after the last element in the row. - row.elements.push(new Blockly.blockRendering.InRowSpacer( + row.elements.push(new InRowSpacer( this.constants_, this.getInRowSpacing_(oldElems[oldElems.length - 1], null))); } @@ -448,42 +436,40 @@ RenderInfo.prototype.addElemSpacing_ = function() { * Calculate the width of a spacer element in a row based on the previous and * next elements in that row. For instance, extra padding is added between two * editable fields. - * @param {Blockly.blockRendering.Measurable} prev The element before the + * @param {Measurable} prev The element before the * spacer. - * @param {Blockly.blockRendering.Measurable} next The element after the spacer. + * @param {Measurable} next The element after the spacer. * @return {number} The size of the spacing between the two elements. * @protected */ RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { if (!prev) { // Statement input padding. - if (next && Blockly.blockRendering.Types.isStatementInput(next)) { + if (next && Types.isStatementInput(next)) { return this.constants_.STATEMENT_INPUT_PADDING_LEFT; } } // Between inputs and the end of the row. - if (prev && Blockly.blockRendering.Types.isInput(prev) && !next) { - if (Blockly.blockRendering.Types.isExternalInput(prev)) { + if (prev && Types.isInput(prev) && !next) { + if (Types.isExternalInput(prev)) { return this.constants_.NO_PADDING; - } else if (Blockly.blockRendering.Types.isInlineInput(prev)) { + } else if (Types.isInlineInput(prev)) { return this.constants_.LARGE_PADDING; - } else if (Blockly.blockRendering.Types.isStatementInput(prev)) { + } else if (Types.isStatementInput(prev)) { return this.constants_.NO_PADDING; } } // Spacing between a square corner and a previous or next connection - if (prev && Blockly.blockRendering.Types.isLeftSquareCorner(prev) && next) { - if (Blockly.blockRendering.Types.isPreviousConnection(next) || - Blockly.blockRendering.Types.isNextConnection(next)) { + if (prev && Types.isLeftSquareCorner(prev) && next) { + if (Types.isPreviousConnection(next) || Types.isNextConnection(next)) { return next.notchOffset; } } // Spacing between a rounded corner and a previous or next connection. - if (prev && Blockly.blockRendering.Types.isLeftRoundedCorner(prev) && next) { - if (Blockly.blockRendering.Types.isPreviousConnection(next) || - Blockly.blockRendering.Types.isNextConnection(next)) { + if (prev && Types.isLeftRoundedCorner(prev) && next) { + if (Types.isPreviousConnection(next) || Types.isNextConnection(next)) { return next.notchOffset - this.constants_.CORNER_RADIUS; } } @@ -541,7 +527,7 @@ RenderInfo.prototype.alignRowElements_ = function() { for (let i = 0, row; (row = this.rows[i]); i++) { if (row.hasStatement) { this.alignStatementRow_( - /** @type {!Blockly.blockRendering.InputRow} */ (row)); + /** @type {!InputRow} */ (row)); } else { const currentWidth = row.width; const desiredWidth = this.getDesiredRowWidth_(row); @@ -549,7 +535,7 @@ RenderInfo.prototype.alignRowElements_ = function() { if (missingSpace > 0) { this.addAlignmentPadding_(row, missingSpace); } - if (Blockly.blockRendering.Types.isTopOrBottomRow(row)) { + if (Types.isTopOrBottomRow(row)) { row.widthWithConnectedBlocks = row.width; } } @@ -558,7 +544,7 @@ RenderInfo.prototype.alignRowElements_ = function() { /** * Calculate the desired width of an input row. - * @param {!Blockly.blockRendering.Row} _row The input row. + * @param {!Row} _row The input row. * @return {number} The desired width of the input row. * @protected */ @@ -570,7 +556,7 @@ RenderInfo.prototype.getDesiredRowWidth_ = function(_row) { * Modify the given row to add the given amount of padding around its fields. * The exact location of the padding is based on the alignment property of the * last input in the field. - * @param {Blockly.blockRendering.Row} row The row to add padding to. + * @param {Row} row The row to add padding to. * @param {number} missingSpace How much padding to add. * @protected */ @@ -582,14 +568,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { } // Decide where the extra padding goes. - if (row.align == Blockly.constants.ALIGN.LEFT) { + if (row.align == blocklyConstants.ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == Blockly.constants.ALIGN.CENTRE) { + } else if (row.align == blocklyConstants.ALIGN.CENTRE) { // Split the padding between the beginning and end of the row. firstSpacer.width += missingSpace / 2; lastSpacer.width += missingSpace / 2; - } else if (row.align == Blockly.constants.ALIGN.RIGHT) { + } else if (row.align == blocklyConstants.ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { @@ -602,7 +588,7 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { /** * Align the elements of a statement row based on computed bounds. * Unlike other types of rows, statement rows add space in multiple places. - * @param {!Blockly.blockRendering.InputRow} row The statement row to resize. + * @param {!InputRow} row The statement row to resize. * @protected */ RenderInfo.prototype.alignStatementRow_ = function(row) { @@ -643,16 +629,15 @@ RenderInfo.prototype.addRowSpacing_ = function() { /** * Create a spacer row to go between prev and next, and set its size. - * @param {!Blockly.blockRendering.Row} prev The previous row. - * @param {!Blockly.blockRendering.Row} next The next row. - * @return {!Blockly.blockRendering.SpacerRow} The newly created spacer row. + * @param {!Row} prev The previous row. + * @param {!Row} next The next row. + * @return {!SpacerRow} The newly created spacer row. * @protected */ RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { const height = this.getSpacerRowHeight_(prev, next); const width = this.getSpacerRowWidth_(prev, next); - const spacer = - new Blockly.blockRendering.SpacerRow(this.constants_, height, width); + const spacer = new SpacerRow(this.constants_, height, width); if (prev.hasStatement) { spacer.followsStatement = true; } @@ -664,8 +649,8 @@ RenderInfo.prototype.makeSpacerRow_ = function(prev, next) { /** * Calculate the width of a spacer row. - * @param {!Blockly.blockRendering.Row} _prev The row before the spacer. - * @param {!Blockly.blockRendering.Row} _next The row after the spacer. + * @param {!Row} _prev The row before the spacer. + * @param {!Row} _next The row after the spacer. * @return {number} The desired width of the spacer row between these two rows. * @protected */ @@ -675,8 +660,8 @@ RenderInfo.prototype.getSpacerRowWidth_ = function(_prev, _next) { /** * Calculate the height of a spacer row. - * @param {!Blockly.blockRendering.Row} _prev The row before the spacer. - * @param {!Blockly.blockRendering.Row} _next The row after the spacer. + * @param {!Row} _prev The row before the spacer. + * @param {!Row} _next The row after the spacer. * @return {number} The desired height of the spacer row between these two rows. * @protected */ @@ -689,25 +674,25 @@ RenderInfo.prototype.getSpacerRowHeight_ = function(_prev, _next) { * This base implementation puts the centerline at the middle of the row * vertically, with no special cases. You will likely need extra logic to * handle (at minimum) top and bottom rows. - * @param {!Blockly.blockRendering.Row} row The row containing the element. - * @param {!Blockly.blockRendering.Measurable} elem The element to place. + * @param {!Row} row The row containing the element. + * @param {!Measurable} elem The element to place. * @return {number} The desired centerline of the given element, as an offset * from the top left of the block. * @protected */ RenderInfo.prototype.getElemCenterline_ = function(row, elem) { - if (Blockly.blockRendering.Types.isSpacer(elem)) { + if (Types.isSpacer(elem)) { return row.yPos + elem.height / 2; } - if (Blockly.blockRendering.Types.isBottomRow(row)) { + if (Types.isBottomRow(row)) { const baseline = row.yPos + row.height - row.descenderHeight; - if (Blockly.blockRendering.Types.isNextConnection(elem)) { + if (Types.isNextConnection(elem)) { return baseline + elem.height / 2; } return baseline - elem.height / 2; } - if (Blockly.blockRendering.Types.isTopRow(row)) { - if (Blockly.blockRendering.Types.isHat(elem)) { + if (Types.isTopRow(row)) { + if (Types.isHat(elem)) { return row.capline - elem.height / 2; } return row.capline + elem.height / 2; @@ -718,14 +703,14 @@ RenderInfo.prototype.getElemCenterline_ = function(row, elem) { /** * Record final position information on elements on the given row, for use in * drawing. At minimum this records xPos and centerline on each element. - * @param {!Blockly.blockRendering.Row} row The row containing the elements. + * @param {!Row} row The row containing the elements. * @protected */ RenderInfo.prototype.recordElemPositions_ = function(row) { let xCursor = row.xPos; for (let j = 0, elem; (elem = row.elements[j]); j++) { // Now that row heights are finalized, make spacers use the row height. - if (Blockly.blockRendering.Types.isSpacer(elem)) { + if (Types.isSpacer(elem)) { elem.height = row.height; } elem.xPos = xCursor; diff --git a/tests/deps.js b/tests/deps.js index 8baeee5ab..f2de1b0f9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); From f7a5d809bc3e37fd736aa29c7c35a47791c569d0 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 16 Jul 2021 15:14:32 -0700 Subject: [PATCH 108/833] clang-format core/renderers/common/info.js --- core/renderers/common/info.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 3c5e70ee4..146ca5cdd 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -313,7 +313,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { // greater height it will be overwritten in the compute pass. if (followsStatement) { this.bottomRow.minHeight = - this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; + this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT; } else { this.bottomRow.minHeight = this.constants_.BOTTOM_ROW_MIN_HEIGHT; } @@ -364,10 +364,11 @@ RenderInfo.prototype.addInput_ = function(input, activeRow) { } else if (input.type == inputTypes.DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. - activeRow.minHeight = Math.max(activeRow.minHeight, + activeRow.minHeight = Math.max( + activeRow.minHeight, input.getSourceBlock() && input.getSourceBlock().isShadow() ? - this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : - this.constants_.DUMMY_INPUT_MIN_HEIGHT); + this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT : + this.constants_.DUMMY_INPUT_MIN_HEIGHT); activeRow.hasDummyInput = true; } if (activeRow.align == null) { @@ -478,8 +479,8 @@ RenderInfo.prototype.getInRowSpacing_ = function(prev, next) { }; /** - * Figure out where the right edge of the block and right edge of statement inputs - * should be placed. + * Figure out where the right edge of the block and right edge of statement + * inputs should be placed. * @protected */ // TODO: More cleanup. @@ -607,8 +608,8 @@ RenderInfo.prototype.alignStatementRow_ = function(row) { statementInput.width += (desiredWidth - currentWidth); statementInput.height = Math.max(statementInput.height, row.height); row.width += (desiredWidth - currentWidth); - row.widthWithConnectedBlocks = Math.max(row.width, - this.statementEdge + row.connectedBlockWidths); + row.widthWithConnectedBlocks = + Math.max(row.width, this.statementEdge + row.connectedBlockWidths); }; /** @@ -742,9 +743,9 @@ RenderInfo.prototype.finalize_ = function() { if (this.outputConnection && this.block_.nextConnection && this.block_.nextConnection.isConnected()) { // Include width of connected block in value to stack width measurement. - widestRowWithConnectedBlocks = - Math.max(widestRowWithConnectedBlocks, - this.block_.nextConnection.targetBlock().getHeightWidth().width); + widestRowWithConnectedBlocks = Math.max( + widestRowWithConnectedBlocks, + this.block_.nextConnection.targetBlock().getHeightWidth().width); } this.widthWithChildren = widestRowWithConnectedBlocks + this.startX; From dbf6308f03e6db01eb77022c7891879665dea9f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:36:34 -0700 Subject: [PATCH 109/833] Migrate core/interfaces/i_movable.js to goog.module --- core/interfaces/i_movable.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_movable.js b/core/interfaces/i_movable.js index bc0c3bf9f..25a92d6bb 100644 --- a/core/interfaces/i_movable.js +++ b/core/interfaces/i_movable.js @@ -11,17 +11,20 @@ 'use strict'; -goog.provide('Blockly.IMovable'); +goog.module('Blockly.IMovable'); +goog.module.declareLegacyNamespace(); /** * The interface for an object that is movable. * @interface */ -Blockly.IMovable = function() {}; +const IMovable = function() {}; /** * Get whether this is movable or not. * @return {boolean} True if movable. */ -Blockly.IMovable.prototype.isMovable; +IMovable.prototype.isMovable; + +exports = IMovable; diff --git a/tests/deps.js b/tests/deps.js index 230083d23..3ce0457fb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -88,7 +88,7 @@ goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarg goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); -goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], []); +goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); From b990eb08a3021f9cdc71f3325e31774507ee0b75 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:15:15 -0700 Subject: [PATCH 110/833] Migrate core/interfaces/i_styleable.js to goog.module --- core/interfaces/i_styleable.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_styleable.js b/core/interfaces/i_styleable.js index 944ee9d65..14dea3ce1 100644 --- a/core/interfaces/i_styleable.js +++ b/core/interfaces/i_styleable.js @@ -11,23 +11,26 @@ 'use strict'; -goog.provide('Blockly.IStyleable'); +goog.module('Blockly.IStyleable'); +goog.module.declareLegacyNamespace(); /** * Interface for an object that a style can be added to. * @interface */ -Blockly.IStyleable = function() {}; +const IStyleable = function() {}; /** * Adds a style on the toolbox. Usually used to change the cursor. * @param {string} style The name of the class to add. */ -Blockly.IStyleable.prototype.addStyle; +IStyleable.prototype.addStyle; /** * Removes a style from the toolbox. Usually used to change the cursor. * @param {string} style The name of the class to remove. */ -Blockly.IStyleable.prototype.removeStyle; +IStyleable.prototype.removeStyle; + +exports = IStyleable; diff --git a/tests/deps.js b/tests/deps.js index 3ce0457fb..c9ef15a2f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -93,7 +93,7 @@ goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositio goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); -goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], []); +goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); From bbdf5730f6aec7af34be3582d80e39e088ba61b8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 08:10:47 -0700 Subject: [PATCH 111/833] Reordered core/connection_checker.js requires --- core/connection_checker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 3a405edcb..4bd7bd4e2 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -15,10 +15,10 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); -const connectionTypes = goog.require('Blockly.connectionTypes'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); -const registry = goog.require('Blockly.registry'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); From c6112df77a17f8e130c43cd1959e3391cea41fdf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:16:29 -0700 Subject: [PATCH 112/833] Switch some requires in core/comment.js to destructuring --- core/comment.js | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/core/comment.js b/core/comment.js index fe0c940a6..de947fa5f 100644 --- a/core/comment.js +++ b/core/comment.js @@ -15,19 +15,17 @@ goog.module.declareLegacyNamespace(); const Block = goog.requireType('Blockly.Block'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); -const browserEvents = goog.require('Blockly.browserEvents'); const Bubble = goog.require('Blockly.Bubble'); const Coordinate = goog.requireType('Blockly.utils.Coordinate'); -const Css = goog.require('Blockly.Css'); -const dom = goog.require('Blockly.utils.dom'); const Events = goog.require('Blockly.Events'); const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); -const userAgent = goog.require('Blockly.utils.userAgent'); -const utilsObject = goog.require('Blockly.utils.object'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const {CommentModel} = goog.requireType('Blockly.Block'); +const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); +const {dom, userAgent, object: utilsObject} = goog.require('Blockly.utils'); +const {register} = goog.require('Blockly.Css'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -65,28 +63,28 @@ const Comment = function(block) { /** * Mouse up event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onMouseUpWrapper_ = null; /** * Wheel event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onWheelWrapper_ = null; /** * Change event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onChangeWrapper_ = null; /** * Input event data. - * @type {?browserEvents.Data} + * @type {?Data} * @private */ this.onInputWrapper_ = null; @@ -167,25 +165,23 @@ Comment.prototype.createEditor_ = function() { // Ideally this would be hooked to the focus event for the comment. // However doing so in Firefox swallows the cursor for unknown reasons. // So this is hooked to mouseup instead. No big deal. - this.onMouseUpWrapper_ = browserEvents.conditionalBind( - textarea, 'mouseup', this, this.startEdit_, true, true); + this.onMouseUpWrapper_ = + conditionalBind(textarea, 'mouseup', this, this.startEdit_, true, true); // Don't zoom with mousewheel. - this.onWheelWrapper_ = - browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { - e.stopPropagation(); - }); + this.onWheelWrapper_ = conditionalBind(textarea, 'wheel', this, function(e) { + e.stopPropagation(); + }); this.onChangeWrapper_ = - browserEvents.conditionalBind(textarea, 'change', this, function(_e) { + conditionalBind(textarea, 'change', this, function(_e) { if (this.cachedText_ != this.model_.text) { Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this.block_, 'comment', null, this.cachedText_, this.model_.text)); } }); - this.onInputWrapper_ = - browserEvents.conditionalBind(textarea, 'input', this, function(_e) { - this.model_.text = textarea.value; - }); + this.onInputWrapper_ = conditionalBind(textarea, 'input', this, function(_e) { + this.model_.text = textarea.value; + }); setTimeout(textarea.focus.bind(textarea), 0); @@ -304,19 +300,19 @@ Comment.prototype.createNonEditableBubble_ = function() { */ Comment.prototype.disposeBubble_ = function() { if (this.onMouseUpWrapper_) { - browserEvents.unbind(this.onMouseUpWrapper_); + unbind(this.onMouseUpWrapper_); this.onMouseUpWrapper_ = null; } if (this.onWheelWrapper_) { - browserEvents.unbind(this.onWheelWrapper_); + unbind(this.onWheelWrapper_); this.onWheelWrapper_ = null; } if (this.onChangeWrapper_) { - browserEvents.unbind(this.onChangeWrapper_); + unbind(this.onChangeWrapper_); this.onChangeWrapper_ = null; } if (this.onInputWrapper_) { - browserEvents.unbind(this.onInputWrapper_); + unbind(this.onInputWrapper_); this.onInputWrapper_ = null; } this.bubble_.dispose(); @@ -394,7 +390,7 @@ Comment.prototype.dispose = function() { /** * CSS for block comment. See css.js for use. */ -Css.register([ +register([ /* eslint-disable indent */ '.blocklyCommentTextarea {', 'background-color: #fef49c;', From 11b47aab2537c1ad8b26eb815f357717729e9bff Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:39:35 -0700 Subject: [PATCH 113/833] Migrate core/interfaces/i_positionable.js to goog.module --- core/interfaces/i_positionable.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index 356510c81..3ab5b88f4 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IPositionable'); +goog.module('Blockly.IPositionable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IComponent'); @@ -24,7 +25,7 @@ goog.requireType('Blockly.utils.Rect'); * @extends {Blockly.IComponent} * @interface */ -Blockly.IPositionable = function() {}; +const IPositionable = function() {}; /** * Positions the element. Called when the window is resized. @@ -32,7 +33,7 @@ Blockly.IPositionable = function() {}; * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.IPositionable.prototype.position; +IPositionable.prototype.position; /** * Returns the bounding rectangle of the UI element in pixel units relative to @@ -40,4 +41,6 @@ Blockly.IPositionable.prototype.position; * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.IPositionable.prototype.getBoundingRectangle; +IPositionable.prototype.getBoundingRectangle; + +exports = IPositionable; diff --git a/tests/deps.js b/tests/deps.js index e8a2a7f06..56cbcce9e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -89,7 +89,7 @@ goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable' goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); From 282cd26edeaeca7c71fe70863f1283f6e5178c9b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:41:40 -0700 Subject: [PATCH 114/833] Migrate core/interfaces/i_positionable.js named requires --- core/interfaces/i_positionable.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index 3ab5b88f4..ed324196b 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -14,23 +14,22 @@ goog.module('Blockly.IPositionable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IComponent'); - -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.utils.Rect'); +const IComponent = goog.require('Blockly.IComponent'); +const Rect = goog.requireType('Blockly.utils.Rect'); +const {UiMetrics} = goog.requireType('Blockly.MetricsManager'); /** * Interface for a component that is positioned on top of the workspace. - * @extends {Blockly.IComponent} + * @extends {IComponent} * @interface */ const IPositionable = function() {}; /** * Positions the element. Called when the window is resized. - * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics. - * @param {!Array} savedPositions List of rectangles that + * @param {!UiMetrics} metrics The workspace metrics. + * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ IPositionable.prototype.position; @@ -38,7 +37,7 @@ IPositionable.prototype.position; /** * Returns the bounding rectangle of the UI element in pixel units relative to * the Blockly injection div. - * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if + * @return {?Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ IPositionable.prototype.getBoundingRectangle; From f723d1d3842cac4caa4dd75c253f4455db1b8079 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:09:04 -0700 Subject: [PATCH 115/833] Migrate core/interfaces/i_drag_target.js to goog.module --- core/interfaces/i_drag_target.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index 0af765d57..ada85a8e3 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IDragTarget'); +goog.module('Blockly.IDragTarget'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IComponent'); @@ -25,7 +26,7 @@ goog.requireType('Blockly.utils.Rect'); * @extends {Blockly.IComponent} * @interface */ -Blockly.IDragTarget = function() {}; +const IDragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units @@ -33,14 +34,14 @@ Blockly.IDragTarget = function() {}; * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.IDragTarget.prototype.getClientRect; +IDragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDragEnter; +IDragTarget.prototype.onDragEnter; /** * Handles when a cursor with a block or bubble is dragged over this drag @@ -48,7 +49,7 @@ Blockly.IDragTarget.prototype.onDragEnter; * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDragOver; +IDragTarget.prototype.onDragOver; /** @@ -56,7 +57,7 @@ Blockly.IDragTarget.prototype.onDragOver; * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDragExit; +IDragTarget.prototype.onDragExit; /** * Handles when a block or bubble is dropped on this component. @@ -64,7 +65,7 @@ Blockly.IDragTarget.prototype.onDragExit; * @param {!Blockly.IDraggable} dragElement The block or bubble currently being * dragged. */ -Blockly.IDragTarget.prototype.onDrop; +IDragTarget.prototype.onDrop; /** * Returns whether the provided block or bubble should not be moved after being @@ -75,4 +76,6 @@ Blockly.IDragTarget.prototype.onDrop; * @return {boolean} Whether the block or bubble provided should be returned to * drag start. */ -Blockly.IDragTarget.prototype.shouldPreventMove; +IDragTarget.prototype.shouldPreventMove; + +exports = IDragTarget; diff --git a/tests/deps.js b/tests/deps.js index 56cbcce9e..7a562a115 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -84,7 +84,7 @@ goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextM goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); From cc324d53e59cf0f9145643e7e12583065dcebb3b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:20:23 -0700 Subject: [PATCH 116/833] Migrate core/interfaces/i_drag_target.js named requires --- core/interfaces/i_drag_target.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index ada85a8e3..803bcbc74 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -15,15 +15,15 @@ goog.module('Blockly.IDragTarget'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IComponent'); +const IComponent = goog.require('Blockly.IComponent'); +const IDraggable = goog.requireType('Blockly.IDraggable'); +const Rect = goog.requireType('Blockly.utils.Rect'); -goog.requireType('Blockly.IDraggable'); -goog.requireType('Blockly.utils.Rect'); /** * Interface for a component with custom behaviour when a block or bubble is * dragged over or dropped on top of it. - * @extends {Blockly.IComponent} + * @extends {IComponent} * @interface */ const IDragTarget = function() {}; @@ -31,14 +31,14 @@ const IDragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ IDragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDragEnter; @@ -46,7 +46,7 @@ IDragTarget.prototype.onDragEnter; /** * Handles when a cursor with a block or bubble is dragged over this drag * target. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDragOver; @@ -54,7 +54,7 @@ IDragTarget.prototype.onDragOver; /** * Handles when a cursor with a block or bubble exits this drag target. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDragExit; @@ -62,7 +62,7 @@ IDragTarget.prototype.onDragExit; /** * Handles when a block or bubble is dropped on this component. * Should not handle delete here. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. */ IDragTarget.prototype.onDrop; @@ -71,7 +71,7 @@ IDragTarget.prototype.onDrop; * Returns whether the provided block or bubble should not be moved after being * dropped on this component. If true, the element will return to where it was * when the drag started. - * @param {!Blockly.IDraggable} dragElement The block or bubble currently being + * @param {!IDraggable} dragElement The block or bubble currently being * dragged. * @return {boolean} Whether the block or bubble provided should be returned to * drag start. From daa0b3bfb557482579c8e30cbe61320f14c0ed27 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:26:17 -0700 Subject: [PATCH 117/833] Add TODO for resolving WorkspaceCommentSvg require issue --- core/bubble_dragger.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index d5cb8beae..3a6d36331 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -229,6 +229,7 @@ BubbleDragger.prototype.endBubbleDrag = function(e, currentDragDeltaXY) { */ BubbleDragger.prototype.fireMoveEvent_ = function() { if (this.draggingBubble_.isComment) { + // TODO (adodson): Resolve build errors when requiring WorkspaceCommentSvg. const event = new (Events.get(Events.COMMENT_MOVE))( /** @type {!Blockly.WorkspaceCommentSvg} */ (this.draggingBubble_)); event.setOldCoordinate(this.startXY_); From 9b5a9192124d4952e3591535584957d2875b1ab9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 09:41:58 -0700 Subject: [PATCH 118/833] Convert core/utils/styles.js to inline export style --- core/utils/style.js | 74 +++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/core/utils/style.js b/core/utils/style.js index 028b746b8..1fcfbdd62 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -29,7 +29,7 @@ const Size = goog.require('Blockly.utils.Size'); * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -const getSize = function(element) { +function getSize(element) { if (getStyle(element, 'display') != 'none') { return getSizeWithDisplay(element); } @@ -52,19 +52,19 @@ const getSize = function(element) { style.visibility = originalVisibility; return new Size(offsetWidth, offsetHeight); -}; +} +exports.getSize = getSize; /** * Gets the height and width of an element when the display is not none. * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. - * @private */ -const getSizeWithDisplay = function(element) { +function getSizeWithDisplay(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Size(offsetWidth, offsetHeight); -}; +} /** * Cross-browser pseudo get computed style. It returns the computed style where @@ -78,12 +78,11 @@ const getSizeWithDisplay = function(element) { * @param {!Element} element Element to get style of. * @param {string} style Property to get (must be camelCase, not CSS-style). * @return {string} Style value. - * @private */ -const getStyle = function(element, style) { +function getStyle(element, style) { return getComputedStyle(element, style) || getCascadedStyle(element, style) || (element.style && element.style[style]); -}; +} /** * Retrieves a computed style value of a node. It returns empty string if the @@ -97,7 +96,7 @@ const getStyle = function(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -const getComputedStyle = function(element, property) { +function getComputedStyle(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -108,7 +107,8 @@ const getComputedStyle = function(element, property) { } return ''; -}; +} +exports.getComputedStyle = getComputedStyle; /** * Gets the cascaded style value of a node, or null if the value cannot be @@ -120,10 +120,11 @@ const getComputedStyle = function(element, property) { * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -const getCascadedStyle = function(element, style) { +function getCascadedStyle(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); -}; +} +exports.getCascadedStyle = getCascadedStyle; /** * Returns a Coordinate object relative to the top-left of the HTML document. @@ -131,7 +132,7 @@ const getCascadedStyle = function(element, style) { * @param {!Element} el Element to get the page offset for. * @return {!Coordinate} The page offset. */ -const getPageOffset = function(el) { +function getPageOffset(el) { const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -145,20 +146,22 @@ const getPageOffset = function(el) { pos.y = box.top + scrollCoord.y; return pos; -}; +} +exports.getPageOffset = getPageOffset; /** * Calculates the viewport coordinates relative to the document. * Similar to Closure's goog.style.getViewportPageOffset * @return {!Coordinate} The page offset of the viewport. */ -const getViewportPageOffset = function() { +function getViewportPageOffset() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; const scrollTop = body.scrollTop || documentElement.scrollTop; return new Coordinate(scrollLeft, scrollTop); -}; +} +exports.getViewportPageOffset = getViewportPageOffset; /** * Shows or hides an element from the page. Hiding the element is done by @@ -172,9 +175,10 @@ const getViewportPageOffset = function() { * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -const setElementShown = function(el, isShown) { +function setElementShown(el, isShown) { el.style.display = isShown ? '' : 'none'; -}; +} +exports.setElementShown = setElementShown; /** * Returns true if the element is using right to left (RTL) direction. @@ -183,9 +187,10 @@ const setElementShown = function(el, isShown) { * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -const isRightToLeft = function(el) { +function isRightToLeft(el) { return 'rtl' == getStyle(el, 'direction'); -}; +} +exports.isRightToLeft = isRightToLeft; /** * Gets the computed border widths (on all sides) in pixels @@ -193,7 +198,7 @@ const isRightToLeft = function(el) { * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -const getBorderBox = function(element) { +function getBorderBox(element) { const left = getComputedStyle(element, 'borderLeftWidth'); const right = getComputedStyle(element, 'borderRightWidth'); const top = getComputedStyle(element, 'borderTopWidth'); @@ -205,7 +210,8 @@ const getBorderBox = function(element) { bottom: parseFloat(bottom), left: parseFloat(left) }; -}; +} +exports.getBorderBox = getBorderBox; /** * Changes the scroll position of `container` with the minimum amount so @@ -220,11 +226,12 @@ const getBorderBox = function(element) { * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -const scrollIntoContainerView = function(element, container, opt_center) { +function scrollIntoContainerView(element, container, opt_center) { const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; -}; +} +exports.scrollIntoContainerView = scrollIntoContainerView; /** * Calculate the scroll position of `container` with the minimum amount so @@ -241,8 +248,7 @@ const scrollIntoContainerView = function(element, container, opt_center) { * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -const getContainerOffsetToScrollInto = function( - element, container, opt_center) { +function getContainerOffsetToScrollInto(element, container, opt_center) { // Absolute position of the element's border's top left corner. const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. @@ -275,17 +281,5 @@ const getContainerOffsetToScrollInto = function( scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } return new Coordinate(scrollLeft, scrollTop); -}; - -exports = { - getSize, - getComputedStyle, - getCascadedStyle, - getPageOffset, - getViewportPageOffset, - setElementShown, - isRightToLeft, - getBorderBox, - scrollIntoContainerView, - getContainerOffsetToScrollInto, -}; +} +exports.getContainerOffsetToScrollInto = getContainerOffsetToScrollInto; From 30f27606c8d01b69260a79fb30e159f65d16b36e Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:12:44 -0700 Subject: [PATCH 119/833] Migrate core/interfaces/i_bubble.js to goog.module --- core/interfaces/i_bubble.js | 23 +++++++++++++---------- tests/deps.js | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index 7fae99edf..487d2a8a8 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IBubble'); +goog.module('Blockly.IBubble'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IContextMenu'); goog.require('Blockly.IDraggable'); @@ -26,20 +27,20 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.IDraggable} * @extends {Blockly.IContextMenu} */ -Blockly.IBubble = function() {}; +const IBubble = function() {}; /** * Return the coordinates of the top-left corner of this bubble's body relative * to the drawing surface's origin (0,0), in workspace units. * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. */ -Blockly.IBubble.prototype.getRelativeToSurfaceXY; +IBubble.prototype.getRelativeToSurfaceXY; /** * Return the root node of the bubble's SVG group. * @return {!SVGElement} The root SVG node of the bubble's group. */ -Blockly.IBubble.prototype.getSvgRoot; +IBubble.prototype.getSvgRoot; /** * Set whether auto-layout of this bubble is enabled. The first time a bubble @@ -48,13 +49,13 @@ Blockly.IBubble.prototype.getSvgRoot; * @param {boolean} enable True if auto-layout should be enabled, false * otherwise. */ -Blockly.IBubble.prototype.setAutoLayout; +IBubble.prototype.setAutoLayout; /** * Triggers a move callback if one exists at the end of a drag. * @param {boolean} adding True if adding, false if removing. */ -Blockly.IBubble.prototype.setDragging; +IBubble.prototype.setDragging; /** * Move this bubble during a drag, taking into account whether or not there is @@ -64,23 +65,25 @@ Blockly.IBubble.prototype.setDragging; * @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in * workspace coordinates. */ -Blockly.IBubble.prototype.moveDuringDrag; +IBubble.prototype.moveDuringDrag; /** * Move the bubble to the specified location in workspace coordinates. * @param {number} x The x position to move to. * @param {number} y The y position to move to. */ -Blockly.IBubble.prototype.moveTo; +IBubble.prototype.moveTo; /** * Update the style of this bubble when it is dragged over a delete area. * @param {boolean} enable True if the bubble is about to be deleted, false * otherwise. */ -Blockly.IBubble.prototype.setDeleteStyle; +IBubble.prototype.setDeleteStyle; /** * Dispose of this bubble. */ -Blockly.IBubble.prototype.dispose; +IBubble.prototype.dispose; + +exports = IBubble; diff --git a/tests/deps.js b/tests/deps.js index cdeae73f4..8ce3faaae 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -77,7 +77,7 @@ goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNod goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable']); +goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); From 2c80b90dab65941610882aeebe598016724a2baa Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:17:08 -0700 Subject: [PATCH 120/833] Migrate core/interfaces/i_bubble.js named requires --- core/interfaces/i_bubble.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index 487d2a8a8..08e339a19 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -14,25 +14,24 @@ goog.module('Blockly.IBubble'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IContextMenu'); -goog.require('Blockly.IDraggable'); - -goog.requireType('Blockly.BlockDragSurfaceSvg'); -goog.requireType('Blockly.utils.Coordinate'); +const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const IContextMenu = goog.require('Blockly.IContextMenu'); +const IDraggable = goog.require('Blockly.IDraggable'); /** * A bubble interface. * @interface - * @extends {Blockly.IDraggable} - * @extends {Blockly.IContextMenu} + * @extends {IDraggable} + * @extends {IContextMenu} */ const IBubble = function() {}; /** * Return the coordinates of the top-left corner of this bubble's body relative * to the drawing surface's origin (0,0), in workspace units. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. */ IBubble.prototype.getRelativeToSurfaceXY; @@ -60,9 +59,9 @@ IBubble.prototype.setDragging; /** * Move this bubble during a drag, taking into account whether or not there is * a drag surface. - * @param {Blockly.BlockDragSurfaceSvg} dragSurface The surface that carries + * @param {BlockDragSurfaceSvg} dragSurface The surface that carries * rendered items during a drag, or null if no drag surface is in use. - * @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in + * @param {!Coordinate} newLoc The location to translate to, in * workspace coordinates. */ IBubble.prototype.moveDuringDrag; From bac62dc9be141d4c2433a02235d1be57d7d12868 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 09:26:39 -0700 Subject: [PATCH 121/833] Update jsdoc annotation in core/interfaces/i_bubble.js --- core/interfaces/i_bubble.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index 08e339a19..e41a1bf25 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -59,7 +59,7 @@ IBubble.prototype.setDragging; /** * Move this bubble during a drag, taking into account whether or not there is * a drag surface. - * @param {BlockDragSurfaceSvg} dragSurface The surface that carries + * @param {?BlockDragSurfaceSvg} dragSurface The surface that carries * rendered items during a drag, or null if no drag surface is in use. * @param {!Coordinate} newLoc The location to translate to, in * workspace coordinates. From 456969767b4f9d29abf4e9709407d7fed0df892c Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:03:50 -0700 Subject: [PATCH 122/833] Migrate core/interfaces/i_selectable.js to goog.module --- core/interfaces/i_selectable.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/interfaces/i_selectable.js b/core/interfaces/i_selectable.js index e3d817fde..d3355f9ab 100644 --- a/core/interfaces/i_selectable.js +++ b/core/interfaces/i_selectable.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ISelectable'); +goog.module('Blockly.ISelectable'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.IDeletable'); goog.requireType('Blockly.IMovable'); @@ -23,21 +24,23 @@ goog.requireType('Blockly.IMovable'); * @extends {Blockly.IMovable} * @interface */ -Blockly.ISelectable = function() {}; +const ISelectable = function() {}; /** * @type {string} */ -Blockly.ISelectable.prototype.id; +ISelectable.prototype.id; /** * Select this. Highlight it visually. * @return {void} */ -Blockly.ISelectable.prototype.select; +ISelectable.prototype.select; /** * Unselect this. Unhighlight it visually. * @return {void} */ -Blockly.ISelectable.prototype.unselect; +ISelectable.prototype.unselect; + +exports = ISelectable; diff --git a/tests/deps.js b/tests/deps.js index 8ce3faaae..33396a17b 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -92,7 +92,7 @@ goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [ goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); -goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], []); +goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); From e722097c1bac2e658e5dedbfa9c2b9c0df66cef3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:21:47 -0700 Subject: [PATCH 123/833] Break up interfaces in core/i_accessibility.js into separate files --- core/interfaces/i_accessibility.js | 75 ------------------- core/interfaces/i_ast_node_location.js | 20 +++++ core/interfaces/i_ast_node_location_svg.js | 38 ++++++++++ .../i_ast_node_location_with_block.js | 32 ++++++++ core/interfaces/i_keyboard_accessible.js | 30 ++++++++ 5 files changed, 120 insertions(+), 75 deletions(-) delete mode 100644 core/interfaces/i_accessibility.js create mode 100644 core/interfaces/i_ast_node_location.js create mode 100644 core/interfaces/i_ast_node_location_svg.js create mode 100644 core/interfaces/i_ast_node_location_with_block.js create mode 100644 core/interfaces/i_keyboard_accessible.js diff --git a/core/interfaces/i_accessibility.js b/core/interfaces/i_accessibility.js deleted file mode 100644 index 30d724959..000000000 --- a/core/interfaces/i_accessibility.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @license - * Copyright 2020 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview AST Node and keyboard navigation interfaces. - * @author samelh@google.com (Sam El-Husseini) - */ - -'use strict'; - -goog.provide('Blockly.IASTNodeLocation'); -goog.provide('Blockly.IASTNodeLocationSvg'); -goog.provide('Blockly.IASTNodeLocationWithBlock'); -goog.provide('Blockly.IKeyboardAccessible'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.ShortcutRegistry'); - - -/** - * An AST node location interface. - * @interface - */ -Blockly.IASTNodeLocation = function() {}; - -/** - * An AST node location SVG interface. - * @interface - * @extends {Blockly.IASTNodeLocation} - */ -Blockly.IASTNodeLocationSvg = function() {}; - -/** - * Add the marker SVG to this node's SVG group. - * @param {SVGElement} markerSvg The SVG root of the marker to be added to the - * SVG group. - */ -Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg; - -/** - * Add the cursor SVG to this node's SVG group. - * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the - * SVG group. - */ -Blockly.IASTNodeLocationSvg.prototype.setCursorSvg; - -/** - * An AST node location that has an associated block. - * @interface - * @extends {Blockly.IASTNodeLocation} - */ -Blockly.IASTNodeLocationWithBlock = function() {}; - -/** - * Get the source block associated with this node. - * @return {Blockly.Block} The source block. - */ -Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock; - - -/** - * An interface for an object that handles keyboard shortcuts. - * @interface - */ -Blockly.IKeyboardAccessible = function() {}; - -/** - * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. - * @return {boolean} True if the shortcut has been handled, false otherwise. - */ -Blockly.IKeyboardAccessible.prototype.onShortcut; diff --git a/core/interfaces/i_ast_node_location.js b/core/interfaces/i_ast_node_location.js new file mode 100644 index 000000000..8d3d8cb97 --- /dev/null +++ b/core/interfaces/i_ast_node_location.js @@ -0,0 +1,20 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for an AST node location. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IASTNodeLocation'); + +/** + * An AST node location interface. + * @interface + */ +Blockly.IASTNodeLocation = function() {}; diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js new file mode 100644 index 000000000..7711289b1 --- /dev/null +++ b/core/interfaces/i_ast_node_location_svg.js @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for an AST node location SVG. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IASTNodeLocationSvg'); + +goog.require('Blockly.IASTNodeLocation'); + + +/** + * An AST node location SVG interface. + * @interface + * @extends {Blockly.IASTNodeLocation} + */ +Blockly.IASTNodeLocationSvg = function() {}; + +/** + * Add the marker SVG to this node's SVG group. + * @param {SVGElement} markerSvg The SVG root of the marker to be added to the + * SVG group. + */ +Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg; + +/** + * Add the cursor SVG to this node's SVG group. + * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the + * SVG group. + */ +Blockly.IASTNodeLocationSvg.prototype.setCursorSvg; diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js new file mode 100644 index 000000000..612ef0e73 --- /dev/null +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -0,0 +1,32 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for an AST node location that has an associated + * block. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IASTNodeLocationWithBlock'); + +goog.require('Blockly.IASTNodeLocation'); +goog.requireType('Blockly.Block'); + + +/** + * An AST node location that has an associated block. + * @interface + * @extends {Blockly.IASTNodeLocation} + */ +Blockly.IASTNodeLocationWithBlock = function() {}; + +/** + * Get the source block associated with this node. + * @return {Blockly.Block} The source block. + */ +Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock; diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js new file mode 100644 index 000000000..5807e47bf --- /dev/null +++ b/core/interfaces/i_keyboard_accessible.js @@ -0,0 +1,30 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for objects that handle keyboard shortcuts. + * @author samelh@google.com (Sam El-Husseini) + */ + +'use strict'; + +goog.provide('Blockly.IKeyboardAccessible'); + +goog.requireType('Blockly.ShortcutRegistry'); + + +/** + * An interface for an object that handles keyboard shortcuts. + * @interface + */ +Blockly.IKeyboardAccessible = function() {}; + +/** + * Handles the given keyboard shortcut. + * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. + * @return {boolean} True if the shortcut has been handled, false otherwise. + */ +Blockly.IKeyboardAccessible.prototype.onShortcut; From 81b067f83acce2898372771d25cdc08b76f0d148 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:41:41 -0700 Subject: [PATCH 124/833] Migrate core/interfaces/i_ast_node_location.js to goog.module --- core/interfaces/i_ast_node_location.js | 7 +++++-- tests/deps.js | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/interfaces/i_ast_node_location.js b/core/interfaces/i_ast_node_location.js index 8d3d8cb97..0ebec8ebd 100644 --- a/core/interfaces/i_ast_node_location.js +++ b/core/interfaces/i_ast_node_location.js @@ -11,10 +11,13 @@ 'use strict'; -goog.provide('Blockly.IASTNodeLocation'); +goog.module('Blockly.IASTNodeLocation'); +goog.module.declareLegacyNamespace(); /** * An AST node location interface. * @interface */ -Blockly.IASTNodeLocation = function() {}; +const IASTNodeLocation = function() {}; + +exports = IASTNodeLocation; diff --git a/tests/deps.js b/tests/deps.js index 33396a17b..274980325 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -73,7 +73,9 @@ goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDr goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); -goog.addDependency('../../core/interfaces/i_accessibility.js', ['Blockly.IASTNodeLocation', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible'], []); +goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation']); +goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation']); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); @@ -87,6 +89,7 @@ goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteAr goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); +goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], []); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); From 1c72055e4f798cd98d4c2d8ddf304092f2a67835 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:42:08 -0700 Subject: [PATCH 125/833] Migrate core/interfaces/i_ast_node_location_svg.js to goog.module --- core/interfaces/i_ast_node_location_svg.js | 11 +++++++---- tests/deps.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index 7711289b1..cf7c1e1cf 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IASTNodeLocationSvg'); +goog.module('Blockly.IASTNodeLocationSvg'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IASTNodeLocation'); @@ -21,18 +22,20 @@ goog.require('Blockly.IASTNodeLocation'); * @interface * @extends {Blockly.IASTNodeLocation} */ -Blockly.IASTNodeLocationSvg = function() {}; +const IASTNodeLocationSvg = function() {}; /** * Add the marker SVG to this node's SVG group. * @param {SVGElement} markerSvg The SVG root of the marker to be added to the * SVG group. */ -Blockly.IASTNodeLocationSvg.prototype.setMarkerSvg; +IASTNodeLocationSvg.prototype.setMarkerSvg; /** * Add the cursor SVG to this node's SVG group. * @param {SVGElement} cursorSvg The SVG root of the cursor to be added to the * SVG group. */ -Blockly.IASTNodeLocationSvg.prototype.setCursorSvg; +IASTNodeLocationSvg.prototype.setCursorSvg; + +exports = IASTNodeLocationSvg; diff --git a/tests/deps.js b/tests/deps.js index 274980325..d2f153f3c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -74,7 +74,7 @@ goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connectio goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation']); +goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation']); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); From cdea0789dd79a06b0b06fd9e410d28cd838063af Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:42:37 -0700 Subject: [PATCH 126/833] Migrate core/interfaces/i_ast_node_location_svg.js named requires --- core/interfaces/i_ast_node_location_svg.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index cf7c1e1cf..5b58d4abc 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -14,13 +14,13 @@ goog.module('Blockly.IASTNodeLocationSvg'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IASTNodeLocation'); +const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); /** * An AST node location SVG interface. * @interface - * @extends {Blockly.IASTNodeLocation} + * @extends {IASTNodeLocation} */ const IASTNodeLocationSvg = function() {}; From 794e4554fe3b7f191d12787b7060ea28021e2bc8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:43:03 -0700 Subject: [PATCH 127/833] Migrate core/interfaces/i_ast_node_location_with_block.js to goog.module --- core/interfaces/i_ast_node_location_with_block.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 612ef0e73..85606e546 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IASTNodeLocationWithBlock'); +goog.module('Blockly.IASTNodeLocationWithBlock'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IASTNodeLocation'); goog.requireType('Blockly.Block'); @@ -23,10 +24,12 @@ goog.requireType('Blockly.Block'); * @interface * @extends {Blockly.IASTNodeLocation} */ -Blockly.IASTNodeLocationWithBlock = function() {}; +const IASTNodeLocationWithBlock = function() {}; /** * Get the source block associated with this node. * @return {Blockly.Block} The source block. */ -Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock; +IASTNodeLocationWithBlock.prototype.getSourceBlock; + +exports = IASTNodeLocationWithBlock; diff --git a/tests/deps.js b/tests/deps.js index d2f153f3c..9346e750f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -75,7 +75,7 @@ goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockl goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation']); +goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); From 04ef2705d169aead800b17336fb85c7569765d16 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:43:27 -0700 Subject: [PATCH 128/833] Migrate core/interfaces/i_ast_node_location_with_block.js named requires --- core/interfaces/i_ast_node_location_with_block.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 85606e546..58da7a902 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -15,20 +15,20 @@ goog.module('Blockly.IASTNodeLocationWithBlock'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IASTNodeLocation'); -goog.requireType('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); +const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); /** * An AST node location that has an associated block. * @interface - * @extends {Blockly.IASTNodeLocation} + * @extends {IASTNodeLocation} */ const IASTNodeLocationWithBlock = function() {}; /** * Get the source block associated with this node. - * @return {Blockly.Block} The source block. + * @return {Block} The source block. */ IASTNodeLocationWithBlock.prototype.getSourceBlock; From 3d174ae058ddb2bea96b942d95b5bc4329931ada Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:32:12 -0700 Subject: [PATCH 129/833] Migrate core/interfaces/i_keyboard_accessible.js to goog.module --- core/interfaces/i_keyboard_accessible.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 5807e47bf..3720ddc08 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IKeyboardAccessible'); +goog.module('Blockly.IKeyboardAccessible'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.ShortcutRegistry'); @@ -20,11 +21,13 @@ goog.requireType('Blockly.ShortcutRegistry'); * An interface for an object that handles keyboard shortcuts. * @interface */ -Blockly.IKeyboardAccessible = function() {}; +const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ -Blockly.IKeyboardAccessible.prototype.onShortcut; +IKeyboardAccessible.prototype.onShortcut; + +exports = IKeyboardAccessible; diff --git a/tests/deps.js b/tests/deps.js index 9346e750f..188e4ed43 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -89,7 +89,7 @@ goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteAr goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); -goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], []); +goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); From 94e36dba319bb1580b3e16a1f9496f5f54377740 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:32:21 -0700 Subject: [PATCH 130/833] Migrate core/interfaces/i_keyboard_accessible.js named requires --- core/interfaces/i_keyboard_accessible.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 3720ddc08..8f21153da 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -14,7 +14,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.ShortcutRegistry'); +const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); /** @@ -25,7 +25,7 @@ const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled. + * @param {!KeyboardShortcut} shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ IKeyboardAccessible.prototype.onShortcut; From bdede7c1ab5bbef39421c90db0ab5d5aceb8a734 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:41:13 -0700 Subject: [PATCH 131/833] Migrate core/interfaces/i_contextmenu.js to goog.module --- core/interfaces/i_contextmenu.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_contextmenu.js b/core/interfaces/i_contextmenu.js index fcc406b05..79117d5ed 100644 --- a/core/interfaces/i_contextmenu.js +++ b/core/interfaces/i_contextmenu.js @@ -11,16 +11,19 @@ 'use strict'; -goog.provide('Blockly.IContextMenu'); +goog.module('Blockly.IContextMenu'); +goog.module.declareLegacyNamespace(); /** * @interface */ -Blockly.IContextMenu = function() {}; +const IContextMenu = function() {}; /** * Show the context menu for this object. * @param {!Event} e Mouse event. */ -Blockly.IContextMenu.prototype.showContextMenu; +IContextMenu.prototype.showContextMenu; + +exports = IContextMenu; diff --git a/tests/deps.js b/tests/deps.js index 188e4ed43..455f21cc6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -82,7 +82,7 @@ goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoun goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); -goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], []); +goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); From f77d5f12647fcfa3c9d262cd32187a4539bf1886 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:49:20 -0700 Subject: [PATCH 132/833] Migrate core/connection_db.js to ES6 const/let --- core/connection_db.js | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index 4b2615725..b6d990af1 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -56,7 +56,7 @@ Blockly.ConnectionDB = function(checker) { * @package */ Blockly.ConnectionDB.prototype.addConnection = function(connection, yPos) { - var index = this.calculateIndexForYPos_(yPos); + const index = this.calculateIndexForYPos_(yPos); this.connections_.splice(index, 0, connection); }; @@ -76,7 +76,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { return -1; } - var bestGuess = this.calculateIndexForYPos_(yPos); + const bestGuess = this.calculateIndexForYPos_(yPos); if (bestGuess >= this.connections_.length) { // Not in list return -1; @@ -84,7 +84,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { yPos = conn.y; // Walk forward and back on the y axis looking for the connection. - var pointer = bestGuess; + let pointer = bestGuess; while (pointer >= 0 && this.connections_[pointer].y == yPos) { if (this.connections_[pointer] == conn) { return pointer; @@ -114,10 +114,10 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { if (!this.connections_.length) { return 0; } - var pointerMin = 0; - var pointerMax = this.connections_.length; + let pointerMin = 0; + let pointerMax = this.connections_.length; while (pointerMin < pointerMax) { - var pointerMid = Math.floor((pointerMin + pointerMax) / 2); + const pointerMid = Math.floor((pointerMin + pointerMax) / 2); if (this.connections_[pointerMid].y < yPos) { pointerMin = pointerMid + 1; } else if (this.connections_[pointerMid].y > yPos) { @@ -137,7 +137,7 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { * @throws {Error} If the connection cannot be found in the database. */ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { - var index = this.findIndexOfConnection_(connection, yPos); + const index = this.findIndexOfConnection_(connection, yPos); if (index == -1) { throw Error('Unable to find connection in connectionDB.'); } @@ -153,14 +153,14 @@ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { * @return {!Array} List of connections. */ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { - var db = this.connections_; - var currentX = connection.x; - var currentY = connection.y; + const db = this.connections_; + const currentX = connection.x; + const currentY = connection.y; // Binary search to find the closest y location. - var pointerMin = 0; - var pointerMax = db.length - 2; - var pointerMid = pointerMax; + let pointerMin = 0; + let pointerMax = db.length - 2; + let pointerMid = pointerMax; while (pointerMin < pointerMid) { if (db[pointerMid].y < currentY) { pointerMin = pointerMid; @@ -170,7 +170,7 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { pointerMid = Math.floor((pointerMin + pointerMax) / 2); } - var neighbours = []; + const neighbours = []; /** * Computes if the current connection is within the allowed radius of another * connection. @@ -180,9 +180,9 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { * the other connection is less than the allowed radius. */ function checkConnection_(yIndex) { - var dx = currentX - db[yIndex].x; - var dy = currentY - db[yIndex].y; - var r = Math.sqrt(dx * dx + dy * dy); + const dx = currentX - db[yIndex].x; + const dy = currentY - db[yIndex].y; + const r = Math.sqrt(dx * dx + dy * dy); if (r <= maxRadius) { neighbours.push(db[yIndex]); } @@ -237,8 +237,8 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, } // Stash the values of x and y from before the drag. - var baseY = conn.y; - var baseX = conn.x; + const baseY = conn.y; + const baseX = conn.x; conn.x = baseX + dxy.x; conn.y = baseY + dxy.y; @@ -246,14 +246,14 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, // calculateIndexForYPos_ finds an index for insertion, which is always // after any block with the same y index. We want to search both forward // and back, so search on both sides of the index. - var closestIndex = this.calculateIndexForYPos_(conn.y); + const closestIndex = this.calculateIndexForYPos_(conn.y); - var bestConnection = null; - var bestRadius = maxRadius; - var temp; + let bestConnection = null; + let bestRadius = maxRadius; + let temp; // Walk forward and back on the y axis looking for the closest x,y point. - var pointerMin = closestIndex - 1; + let pointerMin = closestIndex - 1; while (pointerMin >= 0 && this.isInYRange_(pointerMin, conn.y, maxRadius)) { temp = this.connections_[pointerMin]; if (this.connectionChecker_.canConnect(conn, temp, true, bestRadius)) { @@ -263,7 +263,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, pointerMin--; } - var pointerMax = closestIndex; + let pointerMax = closestIndex; while (pointerMax < this.connections_.length && this.isInYRange_(pointerMax, conn.y, maxRadius)) { temp = this.connections_[pointerMax]; @@ -290,7 +290,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, */ Blockly.ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. - var dbList = []; + const dbList = []; dbList[Blockly.connectionTypes.INPUT_VALUE] = new Blockly.ConnectionDB(checker); dbList[Blockly.connectionTypes.OUTPUT_VALUE] = From a87b2b0bfa8cb88cc8dec88362b9c0ee4b05a888 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:53:42 -0700 Subject: [PATCH 133/833] Migrate core/connection_db.js to goog.module --- core/connection_db.js | 33 ++++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index b6d990af1..81782397b 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.ConnectionDB'); +goog.module('Blockly.ConnectionDB'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ @@ -32,7 +33,7 @@ goog.requireType('Blockly.utils.Coordinate'); * drag. * @constructor */ -Blockly.ConnectionDB = function(checker) { +const ConnectionDB = function(checker) { /** * Array of connections sorted by y position in workspace units. * @type {!Array} @@ -55,7 +56,7 @@ Blockly.ConnectionDB = function(checker) { * connection. * @package */ -Blockly.ConnectionDB.prototype.addConnection = function(connection, yPos) { +ConnectionDB.prototype.addConnection = function(connection, yPos) { const index = this.calculateIndexForYPos_(yPos); this.connections_.splice(index, 0, connection); }; @@ -71,7 +72,7 @@ Blockly.ConnectionDB.prototype.addConnection = function(connection, yPos) { * not found. * @private */ -Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { +ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { if (!this.connections_.length) { return -1; } @@ -110,7 +111,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) { * @return {number} The candidate index. * @private */ -Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { +ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { if (!this.connections_.length) { return 0; } @@ -136,7 +137,7 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { * @param {number} yPos The y position used to find the index of the connection. * @throws {Error} If the connection cannot be found in the database. */ -Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { +ConnectionDB.prototype.removeConnection = function(connection, yPos) { const index = this.findIndexOfConnection_(connection, yPos); if (index == -1) { throw Error('Unable to find connection in connectionDB.'); @@ -152,7 +153,7 @@ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) { * @param {number} maxRadius The maximum radius to another connection. * @return {!Array} List of connections. */ -Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { +ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { const db = this.connections_; const currentX = connection.x; const currentY = connection.y; @@ -213,7 +214,7 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { * @return {boolean} True if connection is in range. * @private */ -Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { +ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { return (Math.abs(this.connections_[index].y - baseY) <= maxRadius); }; @@ -229,7 +230,7 @@ Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { * Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ -Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, +ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) { if (!this.connections_.length) { // Don't bother. @@ -286,18 +287,20 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, * Initialize a set of connection DBs for a workspace. * @param {!Blockly.IConnectionChecker} checker The workspace's * connection checker, used to decide if connections are valid during a drag. - * @return {!Array} Array of databases. + * @return {!Array} Array of databases. */ -Blockly.ConnectionDB.init = function(checker) { +ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. const dbList = []; dbList[Blockly.connectionTypes.INPUT_VALUE] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); dbList[Blockly.connectionTypes.OUTPUT_VALUE] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); dbList[Blockly.connectionTypes.NEXT_STATEMENT] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); dbList[Blockly.connectionTypes.PREVIOUS_STATEMENT] = - new Blockly.ConnectionDB(checker); + new ConnectionDB(checker); return dbList; }; + +exports = ConnectionDB; diff --git a/tests/deps.js b/tests/deps.js index cdeae73f4..7531e34ae 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -21,7 +21,7 @@ goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubbl goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); From acd7e5596898e39097a7a91faf2760226137ba25 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:59:08 -0700 Subject: [PATCH 134/833] Migrate core/connection_db.js to named requires --- core/connection_db.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index 81782397b..0493cf077 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -15,20 +15,19 @@ goog.module('Blockly.ConnectionDB'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +const RenderedConnection = goog.require('Blockly.RenderedConnection'); +const connectionTypes = goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.RenderedConnection'); - -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.utils.Coordinate'); /** * Database of connections. * Connections are stored in order of their vertical component. This way * connections in an area may be looked up quickly using a binary search. - * @param {!Blockly.IConnectionChecker} checker The workspace's + * @param {!IConnectionChecker} checker The workspace's * connection type checker, used to decide if connections are valid during a * drag. * @constructor @@ -36,14 +35,14 @@ goog.requireType('Blockly.utils.Coordinate'); const ConnectionDB = function(checker) { /** * Array of connections sorted by y position in workspace units. - * @type {!Array} + * @type {!Array} * @private */ this.connections_ = []; /** * The workspace's connection type checker, used to decide if connections are * valid during a drag. - * @type {!Blockly.IConnectionChecker} + * @type {!IConnectionChecker} * @private */ this.connectionChecker_ = checker; @@ -51,7 +50,7 @@ const ConnectionDB = function(checker) { /** * Add a connection to the database. Should not already exist in the database. - * @param {!Blockly.RenderedConnection} connection The connection to be added. + * @param {!RenderedConnection} connection The connection to be added. * @param {number} yPos The y position used to decide where to insert the * connection. * @package @@ -66,7 +65,7 @@ ConnectionDB.prototype.addConnection = function(connection, yPos) { * * Starts by doing a binary search to find the approximate location, then * linearly searches nearby for the exact connection. - * @param {!Blockly.RenderedConnection} conn The connection to find. + * @param {!RenderedConnection} conn The connection to find. * @param {number} yPos The y position used to find the index of the connection. * @return {number} The index of the connection, or -1 if the connection was * not found. @@ -133,7 +132,7 @@ ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) { /** * Remove a connection from the database. Must already exist in DB. - * @param {!Blockly.RenderedConnection} connection The connection to be removed. + * @param {!RenderedConnection} connection The connection to be removed. * @param {number} yPos The y position used to find the index of the connection. * @throws {Error} If the connection cannot be found in the database. */ @@ -148,10 +147,10 @@ ConnectionDB.prototype.removeConnection = function(connection, yPos) { /** * Find all nearby connections to the given connection. * Type checking does not apply, since this function is used for bumping. - * @param {!Blockly.RenderedConnection} connection The connection whose + * @param {!RenderedConnection} connection The connection whose * neighbours should be returned. * @param {number} maxRadius The maximum radius to another connection. - * @return {!Array} List of connections. + * @return {!Array} List of connections. */ ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { const db = this.connections_; @@ -220,13 +219,13 @@ ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { /** * Find the closest compatible connection to this connection. - * @param {!Blockly.RenderedConnection} conn The connection searching for a compatible + * @param {!RenderedConnection} conn The connection searching for a compatible * mate. * @param {number} maxRadius The maximum radius to another connection. - * @param {!Blockly.utils.Coordinate} dxy Offset between this connection's + * @param {!Coordinate} dxy Offset between this connection's * location in the database and the current location (as a result of * dragging). - * @return {!{connection: Blockly.RenderedConnection, radius: number}} + * @return {!{connection: RenderedConnection, radius: number}} * Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ @@ -285,20 +284,20 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, /** * Initialize a set of connection DBs for a workspace. - * @param {!Blockly.IConnectionChecker} checker The workspace's + * @param {!IConnectionChecker} checker The workspace's * connection checker, used to decide if connections are valid during a drag. * @return {!Array} Array of databases. */ ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. const dbList = []; - dbList[Blockly.connectionTypes.INPUT_VALUE] = + dbList[connectionTypes.INPUT_VALUE] = new ConnectionDB(checker); - dbList[Blockly.connectionTypes.OUTPUT_VALUE] = + dbList[connectionTypes.OUTPUT_VALUE] = new ConnectionDB(checker); - dbList[Blockly.connectionTypes.NEXT_STATEMENT] = + dbList[connectionTypes.NEXT_STATEMENT] = new ConnectionDB(checker); - dbList[Blockly.connectionTypes.PREVIOUS_STATEMENT] = + dbList[connectionTypes.PREVIOUS_STATEMENT] = new ConnectionDB(checker); return dbList; }; From f2ca65944763ac76339eadb708d0caca8db447cc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 10:59:44 -0700 Subject: [PATCH 135/833] clang-format core/connection_db.js --- core/connection_db.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/core/connection_db.js b/core/connection_db.js index 0493cf077..abc47beb3 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -229,8 +229,7 @@ ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) { * Contains two properties: 'connection' which is either another * connection or null, and 'radius' which is the distance. */ -ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, - dxy) { +ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) { if (!this.connections_.length) { // Don't bother. return {connection: null, radius: maxRadius}; @@ -265,7 +264,7 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, let pointerMax = closestIndex; while (pointerMax < this.connections_.length && - this.isInYRange_(pointerMax, conn.y, maxRadius)) { + this.isInYRange_(pointerMax, conn.y, maxRadius)) { temp = this.connections_[pointerMax]; if (this.connectionChecker_.canConnect(conn, temp, true, bestRadius)) { bestConnection = temp; @@ -285,20 +284,17 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, /** * Initialize a set of connection DBs for a workspace. * @param {!IConnectionChecker} checker The workspace's - * connection checker, used to decide if connections are valid during a drag. + * connection checker, used to decide if connections are valid during a + * drag. * @return {!Array} Array of databases. */ ConnectionDB.init = function(checker) { // Create four databases, one for each connection type. const dbList = []; - dbList[connectionTypes.INPUT_VALUE] = - new ConnectionDB(checker); - dbList[connectionTypes.OUTPUT_VALUE] = - new ConnectionDB(checker); - dbList[connectionTypes.NEXT_STATEMENT] = - new ConnectionDB(checker); - dbList[connectionTypes.PREVIOUS_STATEMENT] = - new ConnectionDB(checker); + dbList[connectionTypes.INPUT_VALUE] = new ConnectionDB(checker); + dbList[connectionTypes.OUTPUT_VALUE] = new ConnectionDB(checker); + dbList[connectionTypes.NEXT_STATEMENT] = new ConnectionDB(checker); + dbList[connectionTypes.PREVIOUS_STATEMENT] = new ConnectionDB(checker); return dbList; }; From 8afef7f59861c0b0af34f99dee6e36aa0fd19607 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 19 Jul 2021 13:29:45 -0700 Subject: [PATCH 136/833] Destructure some requires --- core/renderers/common/info.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 146ca5cdd..1cc61af85 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -23,7 +23,6 @@ const Icon = goog.require('Blockly.blockRendering.Icon'); const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); const Input = goog.requireType('Blockly.Input'); const InputRow = goog.require('Blockly.blockRendering.InputRow'); -const inputTypes = goog.require('Blockly.inputTypes'); const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); const Measurable = goog.require('Blockly.blockRendering.Measurable'); @@ -39,8 +38,9 @@ const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); const TopRow = goog.require('Blockly.blockRendering.TopRow'); const Types = goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -const blocklyConstants = goog.require('Blockly.constants'); +const {ALIGN} = goog.require('Blockly.constants'); +const {VALUE, STATEMENT, DUMMY} = goog.require('Blockly.inputTypes'); + /** @@ -282,7 +282,7 @@ RenderInfo.prototype.populateTopRow_ = function() { } const precedesStatement = this.block_.inputList.length && - this.block_.inputList[0].type == inputTypes.STATEMENT; + this.block_.inputList[0].type == STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -306,8 +306,7 @@ RenderInfo.prototype.populateBottomRow_ = function() { this.bottomRow.hasNextConnection = !!this.block_.nextConnection; const followsStatement = this.block_.inputList.length && - this.block_.inputList[this.block_.inputList.length - 1].type == - inputTypes.STATEMENT; + this.block_.inputList[this.block_.inputList.length - 1].type == STATEMENT; // This is the minimum height for the row. If one of its elements has a // greater height it will be overwritten in the compute pass. @@ -352,16 +351,16 @@ RenderInfo.prototype.populateBottomRow_ = function() { */ RenderInfo.prototype.addInput_ = function(input, activeRow) { // Non-dummy inputs have visual representations onscreen. - if (this.isInline && input.type == inputTypes.VALUE) { + if (this.isInline && input.type == VALUE) { activeRow.elements.push(new InlineInput(this.constants_, input)); activeRow.hasInlineInput = true; - } else if (input.type == inputTypes.STATEMENT) { + } else if (input.type == STATEMENT) { activeRow.elements.push(new StatementInput(this.constants_, input)); activeRow.hasStatement = true; - } else if (input.type == inputTypes.VALUE) { + } else if (input.type == VALUE) { activeRow.elements.push(new ExternalValueInput(this.constants_, input)); activeRow.hasExternalInput = true; - } else if (input.type == inputTypes.DUMMY) { + } else if (input.type == DUMMY) { // Dummy inputs have no visual representation, but the information is still // important. activeRow.minHeight = Math.max( @@ -390,12 +389,11 @@ RenderInfo.prototype.shouldStartNewRow_ = function(input, lastInput) { return false; } // A statement input or an input following one always gets a new row. - if (input.type == inputTypes.STATEMENT || - lastInput.type == inputTypes.STATEMENT) { + if (input.type == STATEMENT || lastInput.type == STATEMENT) { return true; } // Value and dummy inputs get new row if inputs are not inlined. - if (input.type == inputTypes.VALUE || input.type == inputTypes.DUMMY) { + if (input.type == VALUE || input.type == DUMMY) { return !this.isInline; } return false; @@ -569,14 +567,14 @@ RenderInfo.prototype.addAlignmentPadding_ = function(row, missingSpace) { } // Decide where the extra padding goes. - if (row.align == blocklyConstants.ALIGN.LEFT) { + if (row.align == ALIGN.LEFT) { // Add padding to the end of the row. lastSpacer.width += missingSpace; - } else if (row.align == blocklyConstants.ALIGN.CENTRE) { + } else if (row.align == ALIGN.CENTRE) { // Split the padding between the beginning and end of the row. firstSpacer.width += missingSpace / 2; lastSpacer.width += missingSpace / 2; - } else if (row.align == blocklyConstants.ALIGN.RIGHT) { + } else if (row.align == ALIGN.RIGHT) { // Add padding at the beginning of the row. firstSpacer.width += missingSpace; } else { From 268a83d054a0c62e6a67a0b5062c037237cb1dda Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Mon, 19 Jul 2021 13:40:05 -0700 Subject: [PATCH 137/833] Address PR comments --- core/utils/toolbox.js | 8 ++++---- tests/deps.js | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index ec050d178..aab51d826 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -17,7 +17,7 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); -const {IE} = goog.require('Blockly.utils.userAgent'); +const userAgent = goog.require('Blockly.utils.userAgent'); const {textToDom} = goog.require('Blockly.Xml'); const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); @@ -273,7 +273,7 @@ const hasCategories = function(toolboxJson) { return false; } - let toolboxKind = toolboxJson['kind']; + const toolboxKind = toolboxJson['kind']; if (toolboxKind) { return toolboxKind == CATEGORY_TOOLBOX_KIND; } @@ -387,7 +387,7 @@ const addAttributes = function(node, obj) { const parseToolboxTree = function(toolboxDef) { if (toolboxDef) { if (typeof toolboxDef != 'string') { - if (IE && toolboxDef.outerHTML) { + if (userAgent.IE && toolboxDef.outerHTML) { // In this case the tree will not have been properly built by the // browser. The HTML will be contained in the element, but it will // not have the proper DOM structure since the browser doesn't support @@ -430,4 +430,4 @@ exports = { hasCategories, isCategoryCollapsible, parseToolboxTree -} +}; diff --git a/tests/deps.js b/tests/deps.js index 3d4531cf1..00ce56da3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -4,7 +4,6 @@ goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Co goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); -goog.addDependency('../../blocks/test_blocks.js', ['Blockly.TestBlocks'], ['Blockly', 'Blockly.Blocks'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); From ac1fb9a4ddd628d630ce0a049371f15b42884623 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 13:53:47 -0700 Subject: [PATCH 138/833] Revise imports in core/comment.js --- core/comment.js | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/core/comment.js b/core/comment.js index de947fa5f..7caf61614 100644 --- a/core/comment.js +++ b/core/comment.js @@ -22,10 +22,11 @@ const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); -const {CommentModel} = goog.requireType('Blockly.Block'); const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); -const {dom, userAgent, object: utilsObject} = goog.require('Blockly.utils'); +const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); const {register} = goog.require('Blockly.Css'); +const {IE} = goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -45,7 +46,7 @@ const Comment = function(block) { /** * The model for this comment. - * @type {!CommentModel} + * @type {!Block.CommentModel} * @private */ this.model_ = block.commentModel; @@ -91,7 +92,7 @@ const Comment = function(block) { this.createIcon(); }; -utilsObject.inherits(Comment, Icon); +inherits(Comment, Icon); /** * Draw the comment icon. @@ -100,13 +101,13 @@ utilsObject.inherits(Comment, Icon); */ Comment.prototype.drawIcon_ = function(group) { // Circle. - dom.createSvgElement( + createSvgElement( Svg.CIRCLE, {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'}, group); // Can't use a real '?' text character since different browsers and operating // systems render it differently. // Body of question mark. - dom.createSvgElement( + createSvgElement( Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' + @@ -115,7 +116,7 @@ Comment.prototype.drawIcon_ = function(group) { }, group); // Dot of question mark. - dom.createSvgElement( + createSvgElement( Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '6.8', @@ -144,15 +145,15 @@ Comment.prototype.createEditor_ = function() { * For non-editable mode see Warning.textToDom_. */ - this.foreignObject_ = dom.createSvgElement( + this.foreignObject_ = createSvgElement( Svg.FOREIGNOBJECT, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); - const body = document.createElementNS(dom.HTML_NS, 'body'); - body.setAttribute('xmlns', dom.HTML_NS); + const body = document.createElementNS(HTML_NS, 'body'); + body.setAttribute('xmlns', HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS(dom.HTML_NS, 'textarea'); + this.textarea_ = document.createElementNS(HTML_NS, 'textarea'); const textarea = this.textarea_; textarea.className = 'blocklyCommentTextarea'; textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); @@ -253,7 +254,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || userAgent.IE) { + if (!this.block_.isEditable() || IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. @@ -392,16 +393,9 @@ Comment.prototype.dispose = function() { */ register([ /* eslint-disable indent */ - '.blocklyCommentTextarea {', - 'background-color: #fef49c;', - 'border: 0;', - 'outline: 0;', - 'margin: 0;', - 'padding: 3px;', - 'resize: none;', - 'display: block;', - 'text-overflow: hidden;', - '}' + '.blocklyCommentTextarea {', 'background-color: #fef49c;', 'border: 0;', + 'outline: 0;', 'margin: 0;', 'padding: 3px;', 'resize: none;', + 'display: block;', 'text-overflow: hidden;', '}' /* eslint-enable indent */ ]); From a8cba441e7d2a7766b4b5941a2519ce0e45e61af Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 19 Jul 2021 14:33:15 -0700 Subject: [PATCH 139/833] Fix comment indentation in core/connection_db.js --- core/connection_db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/connection_db.js b/core/connection_db.js index abc47beb3..49bccb504 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -285,7 +285,7 @@ ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dxy) { * Initialize a set of connection DBs for a workspace. * @param {!IConnectionChecker} checker The workspace's * connection checker, used to decide if connections are valid during a - * drag. + * drag. * @return {!Array} Array of databases. */ ConnectionDB.init = function(checker) { From 583e321647b14f58501c2773177e516601fd57ed Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 13:38:22 -0700 Subject: [PATCH 140/833] Migrate core/interfaces/i_flyout.js to goog.module --- core/interfaces/i_flyout.js | 55 +++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index b819c3347..7a05fb9da 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IFlyout'); +goog.module('Blockly.IFlyout'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.IRegistrable'); @@ -26,45 +27,45 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.IRegistrable} * @interface */ -Blockly.IFlyout = function() {}; +const IFlyout = function() {}; /** * Whether the flyout is laid out horizontally or not. * @type {boolean} */ -Blockly.IFlyout.prototype.horizontalLayout; +IFlyout.prototype.horizontalLayout; /** * Is RTL vs LTR. * @type {boolean} */ -Blockly.IFlyout.prototype.RTL; +IFlyout.prototype.RTL; /** * The target workspace * @type {?Blockly.WorkspaceSvg} */ -Blockly.IFlyout.prototype.targetWorkspace; +IFlyout.prototype.targetWorkspace; /** * Margin around the edges of the blocks in the flyout. * @type {number} * @const */ -Blockly.IFlyout.prototype.MARGIN; +IFlyout.prototype.MARGIN; /** * Does the flyout automatically close when a block is created? * @type {boolean} */ -Blockly.IFlyout.prototype.autoClose; +IFlyout.prototype.autoClose; /** * Corner radius of the flyout background. * @type {number} * @const */ -Blockly.IFlyout.prototype.CORNER_RADIUS; +IFlyout.prototype.CORNER_RADIUS; /** * Creates the flyout's DOM. Only needs to be called once. The flyout can @@ -76,62 +77,62 @@ Blockly.IFlyout.prototype.CORNER_RADIUS; * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ -Blockly.IFlyout.prototype.createDom; +IFlyout.prototype.createDom; /** * Initializes the flyout. * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ -Blockly.IFlyout.prototype.init; +IFlyout.prototype.init; /** * Dispose of this flyout. * Unlink from all DOM elements to prevent memory leaks. */ -Blockly.IFlyout.prototype.dispose; +IFlyout.prototype.dispose; /** * Get the width of the flyout. * @return {number} The width of the flyout. */ -Blockly.IFlyout.prototype.getWidth; +IFlyout.prototype.getWidth; /** * Get the height of the flyout. * @return {number} The width of the flyout. */ -Blockly.IFlyout.prototype.getHeight; +IFlyout.prototype.getHeight; /** * Get the workspace inside the flyout. * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. */ -Blockly.IFlyout.prototype.getWorkspace; +IFlyout.prototype.getWorkspace; /** * Is the flyout visible? * @return {boolean} True if visible. */ -Blockly.IFlyout.prototype.isVisible; +IFlyout.prototype.isVisible; /** * Set whether the flyout is visible. A value of true does not necessarily mean * that the flyout is shown. It could be hidden because its container is hidden. * @param {boolean} visible True if visible. */ -Blockly.IFlyout.prototype.setVisible; +IFlyout.prototype.setVisible; /** * Set whether this flyout's container is visible. * @param {boolean} visible Whether the container is visible. */ -Blockly.IFlyout.prototype.setContainerVisible; +IFlyout.prototype.setContainerVisible; /** * Hide and empty the flyout. */ -Blockly.IFlyout.prototype.hide; +IFlyout.prototype.hide; /** * Show and populate the flyout. @@ -139,7 +140,7 @@ Blockly.IFlyout.prototype.hide; * display in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ -Blockly.IFlyout.prototype.show; +IFlyout.prototype.show; /** * Create a copy of this block on the workspace. @@ -147,36 +148,36 @@ Blockly.IFlyout.prototype.show; * @return {!Blockly.BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. */ -Blockly.IFlyout.prototype.createBlock; +IFlyout.prototype.createBlock; /** * Reflow blocks and their mats. */ -Blockly.IFlyout.prototype.reflow; +IFlyout.prototype.reflow; /** * @return {boolean} True if this flyout may be scrolled with a scrollbar or by * dragging. */ -Blockly.IFlyout.prototype.isScrollable; +IFlyout.prototype.isScrollable; /** * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.IFlyout.prototype.getX; +IFlyout.prototype.getX; /** * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.IFlyout.prototype.getY; +IFlyout.prototype.getY; /** * Position the flyout. * @return {void} */ -Blockly.IFlyout.prototype.position; +IFlyout.prototype.position; /** * Determine if a drag delta is toward the workspace, based on the position @@ -186,4 +187,6 @@ Blockly.IFlyout.prototype.position; * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. */ -Blockly.IFlyout.prototype.isDragTowardWorkspace; +IFlyout.prototype.isDragTowardWorkspace; + +exports = IFlyout; diff --git a/tests/deps.js b/tests/deps.js index b4d64e1fa..3163a584c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -88,7 +88,7 @@ goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable' goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], []); +goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); From d55ce5922441f0926915ebb2a0f7e20f6e4eb0eb Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 14:09:04 -0700 Subject: [PATCH 141/833] Migrate core/interfaces/i_flyout.js named requires --- core/interfaces/i_flyout.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index 7a05fb9da..b9b1c8e15 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -14,17 +14,17 @@ goog.module('Blockly.IFlyout'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.IRegistrable'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.utils.Svg'); -goog.requireType('Blockly.utils.toolbox'); -goog.requireType('Blockly.WorkspaceSvg'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const IRegistrable = goog.require('Blockly.IRegistrable'); +const Svg = goog.requireType('Blockly.utils.Svg'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {FlyoutDefinition} = goog.requireType('Blockly.utils.toolbox'); /** * Interface for a flyout. - * @extends {Blockly.IRegistrable} + * @extends {IRegistrable} * @interface */ const IFlyout = function() {}; @@ -43,7 +43,7 @@ IFlyout.prototype.RTL; /** * The target workspace - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} */ IFlyout.prototype.targetWorkspace; @@ -72,8 +72,8 @@ IFlyout.prototype.CORNER_RADIUS; * either exist as its own svg element or be a g element nested inside a * separate svg element. * @param {string| - * !Blockly.utils.Svg| - * !Blockly.utils.Svg} tagName The type of tag to + * !Svg| + * !Svg} tagName The type of tag to * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ @@ -81,7 +81,7 @@ IFlyout.prototype.createDom; /** * Initializes the flyout. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to + * @param {!WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ IFlyout.prototype.init; @@ -106,7 +106,7 @@ IFlyout.prototype.getHeight; /** * Get the workspace inside the flyout. - * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. + * @return {!WorkspaceSvg} The workspace inside the flyout. */ IFlyout.prototype.getWorkspace; @@ -136,7 +136,7 @@ IFlyout.prototype.hide; /** * Show and populate the flyout. - * @param {!Blockly.utils.toolbox.FlyoutDefinition|string} flyoutDef Contents to + * @param {!FlyoutDefinition|string} flyoutDef Contents to * display in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ @@ -144,8 +144,8 @@ IFlyout.prototype.show; /** * Create a copy of this block on the workspace. - * @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout. - * @return {!Blockly.BlockSvg} The newly created block. + * @param {!BlockSvg} originalBlock The block to copy from the flyout. + * @return {!BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. */ IFlyout.prototype.createBlock; @@ -183,7 +183,7 @@ IFlyout.prototype.position; * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. */ From c72805b48a9fb4c9204e39fd5d9649b69402d23b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:18:09 -0700 Subject: [PATCH 142/833] Migrate core/interfaces/i_toolbox.js to goog.module --- core/interfaces/i_toolbox.js | 39 +++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index 208be48cc..b530a10f4 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IToolbox'); +goog.module('Blockly.IToolbox'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.IFlyout'); goog.requireType('Blockly.IRegistrable'); @@ -25,76 +26,76 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.IRegistrable} * @interface */ -Blockly.IToolbox = function() {}; +const IToolbox = function() {}; /** * Initializes the toolbox. * @return {void} */ -Blockly.IToolbox.prototype.init; +IToolbox.prototype.init; /** * Fills the toolbox with new toolbox items and removes any old contents. * @param {!Blockly.utils.toolbox.ToolboxInfo} toolboxDef Object holding information * for creating a toolbox. */ -Blockly.IToolbox.prototype.render; +IToolbox.prototype.render; /** * Gets the width of the toolbox. * @return {number} The width of the toolbox. */ -Blockly.IToolbox.prototype.getWidth; +IToolbox.prototype.getWidth; /** * Gets the height of the toolbox. * @return {number} The width of the toolbox. */ -Blockly.IToolbox.prototype.getHeight; +IToolbox.prototype.getHeight; /** * Gets the toolbox flyout. * @return {?Blockly.IFlyout} The toolbox flyout. */ -Blockly.IToolbox.prototype.getFlyout; +IToolbox.prototype.getFlyout; /** * Gets the workspace for the toolbox. * @return {!Blockly.WorkspaceSvg} The parent workspace for the toolbox. */ -Blockly.IToolbox.prototype.getWorkspace; +IToolbox.prototype.getWorkspace; /** * Gets whether or not the toolbox is horizontal. * @return {boolean} True if the toolbox is horizontal, false if the toolbox is * vertical. */ -Blockly.IToolbox.prototype.isHorizontal; +IToolbox.prototype.isHorizontal; /** * Positions the toolbox based on whether it is a horizontal toolbox and whether * the workspace is in rtl. * @return {void} */ -Blockly.IToolbox.prototype.position; +IToolbox.prototype.position; /** * Handles resizing the toolbox when a toolbox item resizes. * @return {void} */ -Blockly.IToolbox.prototype.handleToolboxItemResize; +IToolbox.prototype.handleToolboxItemResize; /** * Unhighlights any previously selected item. * @return {void} */ -Blockly.IToolbox.prototype.clearSelection; +IToolbox.prototype.clearSelection; /** * Updates the category colours and background colour of selected categories. * @return {void} */ -Blockly.IToolbox.prototype.refreshTheme; +IToolbox.prototype.refreshTheme; /** * Updates the flyout's content without closing it. Should be used in response @@ -102,30 +103,32 @@ Blockly.IToolbox.prototype.refreshTheme; * procedures. * @return {void} */ -Blockly.IToolbox.prototype.refreshSelection; +IToolbox.prototype.refreshSelection; /** * Sets the visibility of the toolbox. * @param {boolean} isVisible True if toolbox should be visible. */ -Blockly.IToolbox.prototype.setVisible; +IToolbox.prototype.setVisible; /** * Selects the toolbox item by it's position in the list of toolbox items. * @param {number} position The position of the item to select. * @return {void} */ -Blockly.IToolbox.prototype.selectItemByPosition; +IToolbox.prototype.selectItemByPosition; /** * Gets the selected item. * @return {?Blockly.IToolboxItem} The selected item, or null if no item is * currently selected. */ -Blockly.IToolbox.prototype.getSelectedItem; +IToolbox.prototype.getSelectedItem; /** * Disposes of this toolbox. * @return {void} */ -Blockly.IToolbox.prototype.dispose; +IToolbox.prototype.dispose; + +exports = IToolbox; diff --git a/tests/deps.js b/tests/deps.js index 3163a584c..fe97eefd7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -97,7 +97,7 @@ goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistra goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], []); +goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es5'}); From 867c6cb140f37957b2ab5a3753e259462237ece4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 16:26:08 -0700 Subject: [PATCH 143/833] Migrate core/interfaces/i_toolbox.js named requires --- core/interfaces/i_toolbox.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index b530a10f4..5ecd0a69f 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -14,16 +14,16 @@ goog.module('Blockly.IToolbox'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.IRegistrable'); -goog.requireType('Blockly.IToolboxItem'); -goog.requireType('Blockly.utils.toolbox'); -goog.requireType('Blockly.WorkspaceSvg'); +const IFlyout = goog.requireType('Blockly.IFlyout'); +const IRegistrable = goog.require('Blockly.IRegistrable'); +const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {ToolboxInfo} = goog.requireType('Blockly.utils.toolbox'); /** * Interface for a toolbox. - * @extends {Blockly.IRegistrable} + * @extends {IRegistrable} * @interface */ const IToolbox = function() {}; @@ -36,7 +36,7 @@ IToolbox.prototype.init; /** * Fills the toolbox with new toolbox items and removes any old contents. - * @param {!Blockly.utils.toolbox.ToolboxInfo} toolboxDef Object holding information + * @param {!ToolboxInfo} toolboxDef Object holding information * for creating a toolbox. */ IToolbox.prototype.render; @@ -55,13 +55,13 @@ IToolbox.prototype.getHeight; /** * Gets the toolbox flyout. - * @return {?Blockly.IFlyout} The toolbox flyout. + * @return {?IFlyout} The toolbox flyout. */ IToolbox.prototype.getFlyout; /** * Gets the workspace for the toolbox. - * @return {!Blockly.WorkspaceSvg} The parent workspace for the toolbox. + * @return {!WorkspaceSvg} The parent workspace for the toolbox. */ IToolbox.prototype.getWorkspace; @@ -120,7 +120,7 @@ IToolbox.prototype.selectItemByPosition; /** * Gets the selected item. - * @return {?Blockly.IToolboxItem} The selected item, or null if no item is + * @return {?IToolboxItem} The selected item, or null if no item is * currently selected. */ IToolbox.prototype.getSelectedItem; From e43c82d9bb3d71b72f7d42d81f2994a8f15253f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:03:40 -0700 Subject: [PATCH 144/833] Migrate core/interfaces/i_autohideable.js to goog.module --- core/interfaces/i_autohideable.js | 9 ++++++--- tests/deps.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index ff976c549..7b1613405 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.IAutoHideable'); +goog.module('Blockly.IAutoHideable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IComponent'); @@ -22,11 +23,13 @@ goog.require('Blockly.IComponent'); * @extends {Blockly.IComponent} * @interface */ -Blockly.IAutoHideable = function() {}; +const IAutoHideable = function() {}; /** * Hides the component. Called in Blockly.hideChaff. * @param {boolean} onlyClosePopups Whether only popups should be closed. * Flyouts should not be closed if this is true. */ -Blockly.IAutoHideable.prototype.autoHide; +IAutoHideable.prototype.autoHide; + +exports = IAutoHideable; diff --git a/tests/deps.js b/tests/deps.js index fe97eefd7..c3788886c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -76,7 +76,7 @@ goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.Insertion goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent']); +goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHideable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); From 514f744a6f348f14f1cce37d72356b2eeb062885 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 11:08:54 -0700 Subject: [PATCH 145/833] Migrate core/interfaces/i_autohideable.js named requires --- core/interfaces/i_autohideable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index 7b1613405..bf11adc01 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -15,12 +15,12 @@ goog.module('Blockly.IAutoHideable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IComponent'); +const IComponent = goog.require('Blockly.IComponent'); /** * Interface for a component that can be automatically hidden. - * @extends {Blockly.IComponent} + * @extends {IComponent} * @interface */ const IAutoHideable = function() {}; From ff591b0e732395085f89fc5e1d0d7c100a455317 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 19 Jul 2021 21:26:53 -0700 Subject: [PATCH 146/833] Alphabetize --- core/renderers/common/info.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 1cc61af85..73e02dfff 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -39,7 +39,7 @@ const StatementInput = goog.require('Blockly.blockRendering.StatementInput'); const TopRow = goog.require('Blockly.blockRendering.TopRow'); const Types = goog.require('Blockly.blockRendering.Types'); const {ALIGN} = goog.require('Blockly.constants'); -const {VALUE, STATEMENT, DUMMY} = goog.require('Blockly.inputTypes'); +const {DUMMY, STATEMENT, VALUE} = goog.require('Blockly.inputTypes'); From d9625b1cafd3b94afa0ced4061527d2ad406e04b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 09:38:06 -0700 Subject: [PATCH 147/833] Require userAgent module instead of destructuring in core/comment.js --- core/comment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/comment.js b/core/comment.js index 7caf61614..7f4085faf 100644 --- a/core/comment.js +++ b/core/comment.js @@ -22,11 +22,11 @@ const Icon = goog.require('Blockly.Icon'); const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const userAgent = goog.require('Blockly.utils.userAgent'); const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); const {inherits} = goog.require('Blockly.utils.object'); const {register} = goog.require('Blockly.Css'); -const {IE} = goog.require('Blockly.utils.userAgent'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ @@ -254,7 +254,7 @@ Comment.prototype.setVisible = function(visible) { * @private */ Comment.prototype.createBubble_ = function() { - if (!this.block_.isEditable() || IE) { + if (!this.block_.isEditable() || userAgent.IE) { // MSIE does not support foreignobject; textareas are impossible. // https://docs.microsoft.com/en-us/openspecs/ie_standards/ms-svg/56e6e04c-7c8c-44dd-8100-bd745ee42034 // Always treat comments in IE as uneditable. From 09b020e62fbc22d4866543581aae61d2528bd4c2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 16:02:02 -0700 Subject: [PATCH 148/833] Migrate core/keyboard_nav/basic_cursor.js to ES6 const/let --- core/keyboard_nav/basic_cursor.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index e38031321..89a61cf09 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -43,11 +43,11 @@ Blockly.BasicCursor.registrationName = 'basicCursor'; * @override */ Blockly.BasicCursor.prototype.next = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = this.getNextNode_(curNode, this.validNode_); + const newNode = this.getNextNode_(curNode, this.validNode_); if (newNode) { this.setCurNode(newNode); @@ -74,11 +74,11 @@ Blockly.BasicCursor.prototype.in = function() { * @override */ Blockly.BasicCursor.prototype.prev = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = this.getPreviousNode_(curNode, this.validNode_); + const newNode = this.getPreviousNode_(curNode, this.validNode_); if (newNode) { this.setCurNode(newNode); @@ -112,13 +112,13 @@ Blockly.BasicCursor.prototype.getNextNode_ = function(node, isValid) { if (!node) { return null; } - var newNode = node.in() || node.next(); + const newNode = node.in() || node.next(); if (isValid(newNode)) { return newNode; } else if (newNode) { return this.getNextNode_(newNode, isValid); } - var siblingOrParent = this.findSiblingOrParent_(node.out()); + const siblingOrParent = this.findSiblingOrParent_(node.out()); if (isValid(siblingOrParent)) { return siblingOrParent; } else if (siblingOrParent) { @@ -142,7 +142,7 @@ Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { if (!node) { return null; } - var newNode = node.prev(); + let newNode = node.prev(); if (newNode) { newNode = this.getRightMostChild_(newNode); @@ -165,8 +165,8 @@ Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { * @protected */ Blockly.BasicCursor.prototype.validNode_ = function(node) { - var isValid = false; - var type = node && node.getType(); + let isValid = false; + const type = node && node.getType(); if (type == Blockly.ASTNode.types.OUTPUT || type == Blockly.ASTNode.types.INPUT || type == Blockly.ASTNode.types.FIELD || @@ -189,7 +189,7 @@ Blockly.BasicCursor.prototype.findSiblingOrParent_ = function(node) { if (!node) { return null; } - var nextNode = node.next(); + const nextNode = node.next(); if (nextNode) { return nextNode; } @@ -208,7 +208,7 @@ Blockly.BasicCursor.prototype.getRightMostChild_ = function(node) { if (!node.in()) { return node; } - var newNode = node.in(); + let newNode = node.in(); while (newNode.next()) { newNode = newNode.next(); } From 29cfb470aa21db332ca01ec3822a5df47350b1a4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 16:17:53 -0700 Subject: [PATCH 149/833] Migrate core/keyboard_nav/basic_cursor.js to goog.module --- core/keyboard_nav/basic_cursor.js | 35 +++++++++++++++++-------------- tests/deps.js | 6 +++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index 89a61cf09..63df6a03f 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.BasicCursor'); +goog.module('Blockly.BasicCursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.Cursor'); @@ -25,16 +26,16 @@ goog.require('Blockly.registry'); * @constructor * @extends {Blockly.Cursor} */ -Blockly.BasicCursor = function() { - Blockly.BasicCursor.superClass_.constructor.call(this); +const BasicCursor = function() { + BasicCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(Blockly.BasicCursor, Blockly.Cursor); +Blockly.utils.object.inherits(BasicCursor, Blockly.Cursor); /** * Name used for registering a basic cursor. * @const {string} */ -Blockly.BasicCursor.registrationName = 'basicCursor'; +BasicCursor.registrationName = 'basicCursor'; /** * Find the next node in the pre order traversal. @@ -42,7 +43,7 @@ Blockly.BasicCursor.registrationName = 'basicCursor'; * not set or there is no next value. * @override */ -Blockly.BasicCursor.prototype.next = function() { +BasicCursor.prototype.next = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -63,7 +64,7 @@ Blockly.BasicCursor.prototype.next = function() { * not set or there is no next value. * @override */ -Blockly.BasicCursor.prototype.in = function() { +BasicCursor.prototype.in = function() { return this.next(); }; @@ -73,7 +74,7 @@ Blockly.BasicCursor.prototype.in = function() { * is not set or there is no previous value. * @override */ -Blockly.BasicCursor.prototype.prev = function() { +BasicCursor.prototype.prev = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -94,7 +95,7 @@ Blockly.BasicCursor.prototype.prev = function() { * not set or there is no previous value. * @override */ -Blockly.BasicCursor.prototype.out = function() { +BasicCursor.prototype.out = function() { return this.prev(); }; @@ -108,7 +109,7 @@ Blockly.BasicCursor.prototype.out = function() { * @return {Blockly.ASTNode} The next node in the traversal. * @protected */ -Blockly.BasicCursor.prototype.getNextNode_ = function(node, isValid) { +BasicCursor.prototype.getNextNode_ = function(node, isValid) { if (!node) { return null; } @@ -138,7 +139,7 @@ Blockly.BasicCursor.prototype.getNextNode_ = function(node, isValid) { * previous node exists. * @protected */ -Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { +BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { if (!node) { return null; } @@ -164,7 +165,7 @@ Blockly.BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { * @return {boolean} True if the node should be visited, false otherwise. * @protected */ -Blockly.BasicCursor.prototype.validNode_ = function(node) { +BasicCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (type == Blockly.ASTNode.types.OUTPUT || @@ -185,7 +186,7 @@ Blockly.BasicCursor.prototype.validNode_ = function(node) { * valid parents. * @private */ -Blockly.BasicCursor.prototype.findSiblingOrParent_ = function(node) { +BasicCursor.prototype.findSiblingOrParent_ = function(node) { if (!node) { return null; } @@ -204,7 +205,7 @@ Blockly.BasicCursor.prototype.findSiblingOrParent_ = function(node) { * if no child exists. * @private */ -Blockly.BasicCursor.prototype.getRightMostChild_ = function(node) { +BasicCursor.prototype.getRightMostChild_ = function(node) { if (!node.in()) { return node; } @@ -216,5 +217,7 @@ Blockly.BasicCursor.prototype.getRightMostChild_ = function(node) { }; Blockly.registry.register( - Blockly.registry.Type.CURSOR, Blockly.BasicCursor.registrationName, - Blockly.BasicCursor); + Blockly.registry.Type.CURSOR, BasicCursor.registrationName, + BasicCursor); + +exports = BasicCursor; diff --git a/tests/deps.js b/tests/deps.js index dfbcfe352..74512fae5 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -88,7 +88,7 @@ goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable' goog.addDependency('../../core/interfaces/i_delete_area.js', ['Blockly.IDeleteArea'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarget'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); @@ -97,10 +97,10 @@ goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistra goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); -goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); From 4a3d67abebdf3e0b79728ae8b7d382c13d968e93 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 18:00:30 -0700 Subject: [PATCH 150/833] Migrate core/keyboard_nav/basic_cursor.js named requires --- core/keyboard_nav/basic_cursor.js | 57 ++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index 63df6a03f..9260fa62a 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -14,9 +14,10 @@ goog.module('Blockly.BasicCursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.Cursor'); -goog.require('Blockly.registry'); +const ASTNode = goog.require('Blockly.ASTNode'); +const Cursor = goog.require('Blockly.Cursor'); +const {register, Type} = goog.require('Blockly.registry'); +const {inherits} = goog.require('Blockly.utils.object'); /** @@ -24,12 +25,12 @@ goog.require('Blockly.registry'); * This will allow the user to get to all nodes in the AST by hitting next or * previous. * @constructor - * @extends {Blockly.Cursor} + * @extends {Cursor} */ const BasicCursor = function() { BasicCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(BasicCursor, Blockly.Cursor); +inherits(BasicCursor, Cursor); /** * Name used for registering a basic cursor. @@ -39,7 +40,7 @@ BasicCursor.registrationName = 'basicCursor'; /** * Find the next node in the pre order traversal. - * @return {Blockly.ASTNode} The next node, or null if the current node is + * @return {?ASTNode} The next node, or null if the current node is * not set or there is no next value. * @override */ @@ -60,7 +61,7 @@ BasicCursor.prototype.next = function() { * For a basic cursor we only have the ability to go next and previous, so * in will also allow the user to get to the next node in the pre order * traversal. - * @return {Blockly.ASTNode} The next node, or null if the current node is + * @return {?ASTNode} The next node, or null if the current node is * not set or there is no next value. * @override */ @@ -70,7 +71,7 @@ BasicCursor.prototype.in = function() { /** * Find the previous node in the pre order traversal. - * @return {Blockly.ASTNode} The previous node, or null if the current node + * @return {?ASTNode} The previous node, or null if the current node * is not set or there is no previous value. * @override */ @@ -91,7 +92,7 @@ BasicCursor.prototype.prev = function() { * For a basic cursor we only have the ability to go next and previous, so * out will allow the user to get to the previous node in the pre order * traversal. - * @return {Blockly.ASTNode} The previous node, or null if the current node is + * @return {?ASTNode} The previous node, or null if the current node is * not set or there is no previous value. * @override */ @@ -103,10 +104,10 @@ BasicCursor.prototype.out = function() { * Uses pre order traversal to navigate the Blockly AST. This will allow * a user to easily navigate the entire Blockly AST without having to go in * and out levels on the tree. - * @param {Blockly.ASTNode} node The current position in the AST. - * @param {!function(Blockly.ASTNode) : boolean} isValid A function true/false + * @param {?ASTNode} node The current position in the AST. + * @param {!function(ASTNode) : boolean} isValid A function true/false * depending on whether the given node should be traversed. - * @return {Blockly.ASTNode} The next node in the traversal. + * @return {?ASTNode} The next node in the traversal. * @protected */ BasicCursor.prototype.getNextNode_ = function(node, isValid) { @@ -132,10 +133,10 @@ BasicCursor.prototype.getNextNode_ = function(node, isValid) { * Reverses the pre order traversal in order to find the previous node. This * will allow a user to easily navigate the entire Blockly AST without having to * go in and out levels on the tree. - * @param {Blockly.ASTNode} node The current position in the AST. - * @param {!function(Blockly.ASTNode) : boolean} isValid A function true/false + * @param {?ASTNode} node The current position in the AST. + * @param {!function(ASTNode) : boolean} isValid A function true/false * depending on whether the given node should be traversed. - * @return {Blockly.ASTNode} The previous node in the traversal or null if no + * @return {?ASTNode} The previous node in the traversal or null if no * previous node exists. * @protected */ @@ -161,19 +162,19 @@ BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { /** * Decides what nodes to traverse and which ones to skip. Currently, it * skips output, stack and workspace nodes. - * @param {Blockly.ASTNode} node The AST node to check whether it is valid. + * @param {?ASTNode} node The AST node to check whether it is valid. * @return {boolean} True if the node should be visited, false otherwise. * @protected */ BasicCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); - if (type == Blockly.ASTNode.types.OUTPUT || - type == Blockly.ASTNode.types.INPUT || - type == Blockly.ASTNode.types.FIELD || - type == Blockly.ASTNode.types.NEXT || - type == Blockly.ASTNode.types.PREVIOUS || - type == Blockly.ASTNode.types.WORKSPACE) { + if (type == ASTNode.types.OUTPUT || + type == ASTNode.types.INPUT || + type == ASTNode.types.FIELD || + type == ASTNode.types.NEXT || + type == ASTNode.types.PREVIOUS || + type == ASTNode.types.WORKSPACE) { isValid = true; } return isValid; @@ -181,8 +182,8 @@ BasicCursor.prototype.validNode_ = function(node) { /** * From the given node find either the next valid sibling or parent. - * @param {Blockly.ASTNode} node The current position in the AST. - * @return {Blockly.ASTNode} The parent AST node or null if there are no + * @param {?ASTNode} node The current position in the AST. + * @return {?ASTNode} The parent AST node or null if there are no * valid parents. * @private */ @@ -200,8 +201,8 @@ BasicCursor.prototype.findSiblingOrParent_ = function(node) { /** * Get the right most child of a node. - * @param {Blockly.ASTNode} node The node to find the right most child of. - * @return {Blockly.ASTNode} The right most child of the given node, or the node + * @param {?ASTNode} node The node to find the right most child of. + * @return {?ASTNode} The right most child of the given node, or the node * if no child exists. * @private */ @@ -216,8 +217,8 @@ BasicCursor.prototype.getRightMostChild_ = function(node) { return this.getRightMostChild_(newNode); }; -Blockly.registry.register( - Blockly.registry.Type.CURSOR, BasicCursor.registrationName, +register( + Type.CURSOR, BasicCursor.registrationName, BasicCursor); exports = BasicCursor; diff --git a/tests/deps.js b/tests/deps.js index 74512fae5..0b641086e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -100,7 +100,7 @@ goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable' goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); -goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); From 2ef8b2c86b2e55bb8e51115ed89b46cf0f04f42d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 18:02:39 -0700 Subject: [PATCH 151/833] clang-format core/keyboard_nav/basic_cursor.js --- core/keyboard_nav/basic_cursor.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/core/keyboard_nav/basic_cursor.js b/core/keyboard_nav/basic_cursor.js index 9260fa62a..e9780e119 100644 --- a/core/keyboard_nav/basic_cursor.js +++ b/core/keyboard_nav/basic_cursor.js @@ -169,12 +169,9 @@ BasicCursor.prototype.getPreviousNode_ = function(node, isValid) { BasicCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); - if (type == ASTNode.types.OUTPUT || - type == ASTNode.types.INPUT || - type == ASTNode.types.FIELD || - type == ASTNode.types.NEXT || - type == ASTNode.types.PREVIOUS || - type == ASTNode.types.WORKSPACE) { + if (type == ASTNode.types.OUTPUT || type == ASTNode.types.INPUT || + type == ASTNode.types.FIELD || type == ASTNode.types.NEXT || + type == ASTNode.types.PREVIOUS || type == ASTNode.types.WORKSPACE) { isValid = true; } return isValid; @@ -217,8 +214,6 @@ BasicCursor.prototype.getRightMostChild_ = function(node) { return this.getRightMostChild_(newNode); }; -register( - Type.CURSOR, BasicCursor.registrationName, - BasicCursor); +register(Type.CURSOR, BasicCursor.registrationName, BasicCursor); exports = BasicCursor; From da960d5973912c660d802b2d3c4850b58d25b0ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 10:49:21 -0700 Subject: [PATCH 152/833] Convert private static functions to module-internal functions in core/connection.js --- core/connection.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/connection.js b/core/connection.js index 0b26e9ace..553938825 100644 --- a/core/connection.js +++ b/core/connection.js @@ -134,7 +134,7 @@ Connection.prototype.connect_ = function(childConnection) { if (Events.isEnabled()) { event = new (Events.get(Events.BLOCK_MOVE))(childBlock); } - Connection.connectReciprocally_(parentConnection, childConnection); + connectReciprocally(parentConnection, childConnection); childBlock.setParent(parentBlock); if (event) { event.recordNew(); @@ -307,9 +307,8 @@ Connection.prototype.connect = function(otherConnection) { * Update two connections to target each other. * @param {Connection} first The first connection to update. * @param {Connection} second The second connection to update. - * @private */ -Connection.connectReciprocally_ = function(first, second) { +const connectReciprocally = function(first, second) { if (!first || !second) { throw Error('Cannot connect null connections.'); } @@ -326,9 +325,8 @@ Connection.connectReciprocally_ = function(first, second) { * @param {!Block} orphanBlock The inferior block. * @return {?Connection} The suitable connection point on 'block', * or null. - * @private */ -Connection.getSingleConnection_ = function(block, orphanBlock) { +const getSingleConnection = function(block, orphanBlock) { let foundConnection = null; const output = orphanBlock.outputConnection; const typeChecker = output.getConnectionChecker(); @@ -355,13 +353,12 @@ Connection.getSingleConnection_ = function(block, orphanBlock) { * @param {!Block} orphanBlock The block that is looking for a home. * @return {?Connection} The suitable connection point on the chain * of blocks, or null. - * @private */ -Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { +const getConnectionForOrphanedOutput = function(startBlock, orphanBlock) { let newBlock = startBlock; let connection; while ( - (connection = Connection.getSingleConnection_( + (connection = getSingleConnection( /** @type {!Block} */ (newBlock), orphanBlock))) { newBlock = connection.targetBlock(); if (!newBlock || newBlock.isShadow()) { @@ -384,7 +381,7 @@ Connection.getConnectionForOrphanedOutput_ = function(startBlock, orphanBlock) { Connection.getConnectionForOrphanedConnection = function( startBlock, orphanConnection) { if (orphanConnection.type === connectionTypes.OUTPUT_VALUE) { - return Connection.getConnectionForOrphanedOutput_( + return getConnectionForOrphanedOutput( startBlock, orphanConnection.getSourceBlock()); } // Otherwise we're dealing with a stack. From 77aaab0e1f0496115cebedc5c81307ab4e78982b Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:35:32 -0700 Subject: [PATCH 153/833] Migrate core/interfaces/i_connection_checker.js to goog.module --- core/interfaces/i_connection_checker.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 4b6120da1..527dec4c5 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.IConnectionChecker'); +goog.module('Blockly.IConnectionChecker'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.Connection'); goog.requireType('Blockly.RenderedConnection'); @@ -21,7 +22,7 @@ goog.requireType('Blockly.RenderedConnection'); * Class for connection type checking logic. * @interface */ -Blockly.IConnectionChecker = function() {}; +const IConnectionChecker = function() {}; /** * Check whether the current connection can connect with the target @@ -35,7 +36,7 @@ Blockly.IConnectionChecker = function() {}; * @return {boolean} Whether the connection is legal. * @public */ -Blockly.IConnectionChecker.prototype.canConnect; +IConnectionChecker.prototype.canConnect; /** * Checks whether the current connection can connect with the target @@ -50,7 +51,7 @@ Blockly.IConnectionChecker.prototype.canConnect; * an error code otherwise. * @public */ -Blockly.IConnectionChecker.prototype.canConnectWithReason; +IConnectionChecker.prototype.canConnectWithReason; /** * Helper method that translates a connection error code into a string. @@ -61,7 +62,7 @@ Blockly.IConnectionChecker.prototype.canConnectWithReason; * @return {string} A developer-readable error string. * @public */ -Blockly.IConnectionChecker.prototype.getErrorMessage; +IConnectionChecker.prototype.getErrorMessage; /** * Check that connecting the given connections is safe, meaning that it would @@ -71,7 +72,7 @@ Blockly.IConnectionChecker.prototype.getErrorMessage; * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ -Blockly.IConnectionChecker.prototype.doSafetyChecks; +IConnectionChecker.prototype.doSafetyChecks; /** * Check whether this connection is compatible with another connection with @@ -82,7 +83,7 @@ Blockly.IConnectionChecker.prototype.doSafetyChecks; * @return {boolean} True if the connections share a type. * @public */ -Blockly.IConnectionChecker.prototype.doTypeChecks; +IConnectionChecker.prototype.doTypeChecks; /** * Check whether this connection can be made by dragging. @@ -92,4 +93,6 @@ Blockly.IConnectionChecker.prototype.doTypeChecks; * @return {boolean} True if the connection is allowed during a drag. * @public */ -Blockly.IConnectionChecker.prototype.doDragChecks; +IConnectionChecker.prototype.doDragChecks; + +exports = IConnectionChecker; diff --git a/tests/deps.js b/tests/deps.js index 0b641086e..aa3fc9275 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -81,7 +81,7 @@ goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockD goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], []); +goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_copyable.js', ['Blockly.ICopyable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_deletable.js', ['Blockly.IDeletable'], [], {'lang': 'es6', 'module': 'goog'}); From 9eee8869256cd8637e56d528f097ebf35cf80829 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 12:37:10 -0700 Subject: [PATCH 154/833] Migrate core/interfaces/i_connection_checker.js named requires --- core/interfaces/i_connection_checker.js | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 527dec4c5..03693604c 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -14,8 +14,8 @@ goog.module('Blockly.IConnectionChecker'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.Connection'); -goog.requireType('Blockly.RenderedConnection'); +const Connection = goog.requireType('Blockly.Connection'); +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); /** @@ -27,8 +27,8 @@ const IConnectionChecker = function() {}; /** * Check whether the current connection can connect with the target * connection. - * @param {Blockly.Connection} a Connection to check compatibility with. - * @param {Blockly.Connection} b Connection to check compatibility with. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. * @param {boolean} isDragging True if the connection is being made by dragging * a block. * @param {number=} opt_distance The max allowable distance between the @@ -41,13 +41,13 @@ IConnectionChecker.prototype.canConnect; /** * Checks whether the current connection can connect with the target * connection, and return an error code if there are problems. - * @param {Blockly.Connection} a Connection to check compatibility with. - * @param {Blockly.Connection} b Connection to check compatibility with. + * @param {Connection} a Connection to check compatibility with. + * @param {Connection} b Connection to check compatibility with. * @param {boolean} isDragging True if the connection is being made by dragging * a block. * @param {number=} opt_distance The max allowable distance between the * connections for drag checks. - * @return {number} Blockly.Connection.CAN_CONNECT if the connection is legal, + * @return {number} Connection.CAN_CONNECT if the connection is legal, * an error code otherwise. * @public */ @@ -56,8 +56,8 @@ IConnectionChecker.prototype.canConnectWithReason; /** * Helper method that translates a connection error code into a string. * @param {number} errorCode The error code. - * @param {Blockly.Connection} a One of the two connections being checked. - * @param {Blockly.Connection} b The second of the two connections being + * @param {Connection} a One of the two connections being checked. + * @param {Connection} b The second of the two connections being * checked. * @return {string} A developer-readable error string. * @public @@ -67,8 +67,8 @@ IConnectionChecker.prototype.getErrorMessage; /** * Check that connecting the given connections is safe, meaning that it would * not break any of Blockly's basic assumptions (e.g. no self connections). - * @param {Blockly.Connection} a The first of the connections to check. - * @param {Blockly.Connection} b The second of the connections to check. + * @param {Connection} a The first of the connections to check. + * @param {Connection} b The second of the connections to check. * @return {number} An enum with the reason this connection is safe or unsafe. * @public */ @@ -78,8 +78,8 @@ IConnectionChecker.prototype.doSafetyChecks; * Check whether this connection is compatible with another connection with * respect to the value type system. E.g. square_root("Hello") is not * compatible. - * @param {!Blockly.Connection} a Connection to compare. - * @param {!Blockly.Connection} b Connection to compare against. + * @param {!Connection} a Connection to compare. + * @param {!Connection} b Connection to compare against. * @return {boolean} True if the connections share a type. * @public */ @@ -87,8 +87,8 @@ IConnectionChecker.prototype.doTypeChecks; /** * Check whether this connection can be made by dragging. - * @param {!Blockly.RenderedConnection} a Connection to compare. - * @param {!Blockly.RenderedConnection} b Connection to compare against. + * @param {!RenderedConnection} a Connection to compare. + * @param {!RenderedConnection} b Connection to compare against. * @param {number} distance The maximum allowable distance between connections. * @return {boolean} True if the connection is allowed during a drag. * @public From 317a2e6f53d46e07c6eca16c18be07a295612ae5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:17:10 -0700 Subject: [PATCH 155/833] Migrate core/keyboard_nav/cursor.js to ES6 const/let --- core/keyboard_nav/cursor.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 882be726a..c73d49046 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -42,12 +42,12 @@ Blockly.utils.object.inherits(Blockly.Cursor, Blockly.Marker); * @public */ Blockly.Cursor.prototype.next = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = curNode.next(); + let newNode = curNode.next(); while (newNode && newNode.next() && (newNode.getType() == Blockly.ASTNode.types.NEXT || newNode.getType() == Blockly.ASTNode.types.BLOCK)) { @@ -67,7 +67,7 @@ Blockly.Cursor.prototype.next = function() { * @public */ Blockly.Cursor.prototype.in = function() { - var curNode = this.getCurNode(); + let curNode = this.getCurNode(); if (!curNode) { return null; } @@ -77,7 +77,7 @@ Blockly.Cursor.prototype.in = function() { curNode.getType() == Blockly.ASTNode.types.OUTPUT) { curNode = curNode.next(); } - var newNode = curNode.in(); + const newNode = curNode.in(); if (newNode) { this.setCurNode(newNode); @@ -92,11 +92,11 @@ Blockly.Cursor.prototype.in = function() { * @public */ Blockly.Cursor.prototype.prev = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = curNode.prev(); + let newNode = curNode.prev(); while (newNode && newNode.prev() && (newNode.getType() == Blockly.ASTNode.types.NEXT || @@ -117,11 +117,11 @@ Blockly.Cursor.prototype.prev = function() { * @public */ Blockly.Cursor.prototype.out = function() { - var curNode = this.getCurNode(); + const curNode = this.getCurNode(); if (!curNode) { return null; } - var newNode = curNode.out(); + let newNode = curNode.out(); if (newNode && newNode.getType() == Blockly.ASTNode.types.BLOCK) { newNode = newNode.prev() || newNode; From e50c60bfdbaf92af822cb1dcb819a90c4c057d43 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:17:18 -0700 Subject: [PATCH 156/833] Migrate core/keyboard_nav/cursor.js to goog.module --- core/keyboard_nav/cursor.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index c73d49046..87375108a 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Cursor'); +goog.module('Blockly.Cursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.Marker'); @@ -25,15 +26,15 @@ goog.require('Blockly.utils.object'); * @constructor * @extends {Blockly.Marker} */ -Blockly.Cursor = function() { - Blockly.Cursor.superClass_.constructor.call(this); +const Cursor = function() { + Cursor.superClass_.constructor.call(this); /** * @override */ this.type = 'cursor'; }; -Blockly.utils.object.inherits(Blockly.Cursor, Blockly.Marker); +Blockly.utils.object.inherits(Cursor, Blockly.Marker); /** * Find the next connection, field, or block. @@ -41,7 +42,7 @@ Blockly.utils.object.inherits(Blockly.Cursor, Blockly.Marker); * not set or there is no next value. * @public */ -Blockly.Cursor.prototype.next = function() { +Cursor.prototype.next = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -66,7 +67,7 @@ Blockly.Cursor.prototype.next = function() { * not set or there is no in value. * @public */ -Blockly.Cursor.prototype.in = function() { +Cursor.prototype.in = function() { let curNode = this.getCurNode(); if (!curNode) { return null; @@ -91,7 +92,7 @@ Blockly.Cursor.prototype.in = function() { * is not set or there is no previous value. * @public */ -Blockly.Cursor.prototype.prev = function() { +Cursor.prototype.prev = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -116,7 +117,7 @@ Blockly.Cursor.prototype.prev = function() { * not set or there is no out value. * @public */ -Blockly.Cursor.prototype.out = function() { +Cursor.prototype.out = function() { const curNode = this.getCurNode(); if (!curNode) { return null; @@ -134,4 +135,6 @@ Blockly.Cursor.prototype.out = function() { }; Blockly.registry.register( - Blockly.registry.Type.CURSOR, Blockly.registry.DEFAULT, Blockly.Cursor); + Blockly.registry.Type.CURSOR, Blockly.registry.DEFAULT, Cursor); + +exports = Cursor; diff --git a/tests/deps.js b/tests/deps.js index aa3fc9275..6128287ca 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -101,7 +101,7 @@ goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], [ goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); From c9f2a92ace5497c6dd70cdd7c8037e770a921fde Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 15:01:12 -0700 Subject: [PATCH 157/833] Migrate core/keyboard_nav/cursor.js named requires --- core/keyboard_nav/cursor.js | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/core/keyboard_nav/cursor.js b/core/keyboard_nav/cursor.js index 87375108a..de3d97498 100644 --- a/core/keyboard_nav/cursor.js +++ b/core/keyboard_nav/cursor.js @@ -14,17 +14,17 @@ goog.module('Blockly.Cursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.Marker'); -goog.require('Blockly.registry'); -goog.require('Blockly.utils.object'); +const ASTNode = goog.require('Blockly.ASTNode'); +const Marker = goog.require('Blockly.Marker'); +const {DEFAULT, register, Type} = goog.require('Blockly.registry'); +const {inherits} = goog.require('Blockly.utils.object'); /** * Class for a cursor. * A cursor controls how a user navigates the Blockly AST. * @constructor - * @extends {Blockly.Marker} + * @extends {Marker} */ const Cursor = function() { Cursor.superClass_.constructor.call(this); @@ -34,11 +34,11 @@ const Cursor = function() { */ this.type = 'cursor'; }; -Blockly.utils.object.inherits(Cursor, Blockly.Marker); +inherits(Cursor, Marker); /** * Find the next connection, field, or block. - * @return {Blockly.ASTNode} The next element, or null if the current node is + * @return {ASTNode} The next element, or null if the current node is * not set or there is no next value. * @public */ @@ -50,8 +50,8 @@ Cursor.prototype.next = function() { let newNode = curNode.next(); while (newNode && newNode.next() && - (newNode.getType() == Blockly.ASTNode.types.NEXT || - newNode.getType() == Blockly.ASTNode.types.BLOCK)) { + (newNode.getType() == ASTNode.types.NEXT || + newNode.getType() == ASTNode.types.BLOCK)) { newNode = newNode.next(); } @@ -63,7 +63,7 @@ Cursor.prototype.next = function() { /** * Find the in connection or field. - * @return {Blockly.ASTNode} The in element, or null if the current node is + * @return {ASTNode} The in element, or null if the current node is * not set or there is no in value. * @public */ @@ -74,8 +74,8 @@ Cursor.prototype.in = function() { } // If we are on a previous or output connection, go to the block level before // performing next operation. - if (curNode.getType() == Blockly.ASTNode.types.PREVIOUS || - curNode.getType() == Blockly.ASTNode.types.OUTPUT) { + if (curNode.getType() == ASTNode.types.PREVIOUS || + curNode.getType() == ASTNode.types.OUTPUT) { curNode = curNode.next(); } const newNode = curNode.in(); @@ -88,7 +88,7 @@ Cursor.prototype.in = function() { /** * Find the previous connection, field, or block. - * @return {Blockly.ASTNode} The previous element, or null if the current node + * @return {ASTNode} The previous element, or null if the current node * is not set or there is no previous value. * @public */ @@ -100,8 +100,8 @@ Cursor.prototype.prev = function() { let newNode = curNode.prev(); while (newNode && newNode.prev() && - (newNode.getType() == Blockly.ASTNode.types.NEXT || - newNode.getType() == Blockly.ASTNode.types.BLOCK)) { + (newNode.getType() == ASTNode.types.NEXT || + newNode.getType() == ASTNode.types.BLOCK)) { newNode = newNode.prev(); } @@ -113,7 +113,7 @@ Cursor.prototype.prev = function() { /** * Find the out connection, field, or block. - * @return {Blockly.ASTNode} The out element, or null if the current node is + * @return {ASTNode} The out element, or null if the current node is * not set or there is no out value. * @public */ @@ -124,7 +124,7 @@ Cursor.prototype.out = function() { } let newNode = curNode.out(); - if (newNode && newNode.getType() == Blockly.ASTNode.types.BLOCK) { + if (newNode && newNode.getType() == ASTNode.types.BLOCK) { newNode = newNode.prev() || newNode; } @@ -134,7 +134,6 @@ Cursor.prototype.out = function() { return newNode; }; -Blockly.registry.register( - Blockly.registry.Type.CURSOR, Blockly.registry.DEFAULT, Cursor); +register(Type.CURSOR, DEFAULT, Cursor); exports = Cursor; From f0fc360bfa8849cac38f68988f3f1370797ecac8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 20 Jul 2021 11:30:09 -0700 Subject: [PATCH 158/833] Inline otherwise-unused variable in core/utils/dom.js --- core/utils/dom.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/utils/dom.js b/core/utils/dom.js index 0e0480c0f..5ec684acf 100644 --- a/core/utils/dom.js +++ b/core/utils/dom.js @@ -129,8 +129,7 @@ const addClass = function(element, className) { const removeClasses = function(element, classNames) { const classList = classNames.split(' '); for (let i = 0; i < classList.length; i++) { - const cssName = classList[i]; - removeClass(element, cssName); + removeClass(element, classList[i]); } }; From d101e591de50f7e74f9ed288cdc5dc555e9c2bfe Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Tue, 20 Jul 2021 13:06:39 -0700 Subject: [PATCH 159/833] Removes unnecessary test --- tests/mocha/workspace_svg_test.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/mocha/workspace_svg_test.js b/tests/mocha/workspace_svg_test.js index 339a19a98..d79707d08 100644 --- a/tests/mocha/workspace_svg_test.js +++ b/tests/mocha/workspace_svg_test.js @@ -112,11 +112,6 @@ suite('WorkspaceSvg', function() { this.workspace.updateToolbox({'contents': []}); }.bind(this), 'Existing toolbox has categories. Can\'t change mode.'); }); - test('Passing in string as toolboxdef', function() { - var parseToolboxFake = sinon.spy(Blockly.utils.toolbox, 'parseToolboxTree'); - this.workspace.updateToolbox(''); - sinon.assert.calledOnce(parseToolboxFake); - }); }); suite('addTopBlock', function() { From 5f5b4370250dd3784ed83feb97e7e24528c2113d Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 12:06:50 -0700 Subject: [PATCH 160/833] Add script for partially automating goog.module conversion steps --- scripts/goog_module/convert-file.sh | 281 ++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100755 scripts/goog_module/convert-file.sh diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh new file mode 100755 index 000000000..aae6a9191 --- /dev/null +++ b/scripts/goog_module/convert-file.sh @@ -0,0 +1,281 @@ +#!/bin/bash + +####################################### +# Logging functions +####################################### +COLOR_NONE="\033[0m" +GREEN="\033[0;32m" +BLUE="\033[0;34m" +ORANGE="\033[0;33m" +RED="\033[0;31m" +success() { + echo -e "${GREEN}[SUCCESS]:${COLOR_NONE} $*" >&2 +} +inf() { + echo -e "${BLUE}[INFO]:${COLOR_NONE} $*" >&2 +} +warn() { + echo -e "${ORANGE}[WARN]:${COLOR_NONE} $*" >&2 +} +err() { + echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 +} +####################################### +# Checks whether the provided filepath exists. +# Arguments: +# The filepath to check for existence. +####################################### +verify-filepath() { + if [[ ! -f "$1" ]]; then + err "File $1 does not exist" + return 1 + fi +} +####################################### +# Creates a commit with a message based on the specified step and file. +# Arguments: +# Which conversion step this message is for. +# The filepath of the file being converted. +####################################### +commit-step() { + local step="$1" + local filepath="$2" + if [ -z "${step}" ]; then + err "Missing argument (1-4)" + return 1 + fi + if [ -z "${filepath}" ]; then + err "Missing argument filepath" + return 1 + fi + verify-filepath "${filepath}" + if [[ $? -eq 1 ]]; then return 1; fi + + local message='' + case $1 in + 1) + message="Migrate ${filepath} to ES6 const/let" + ;; + 2) + message="Migrate ${filepath} to goog.module" + ;; + 3) + message="Migrate ${filepath} named requires" + ;; + 4) + message="clang-format ${filepath}" + ;; + *) + err 'INVALID ARGUMENT' + return 1 + ;; + esac + git add . + if [[ -z $(git status --porcelain) ]]; then + success "Nothing to commit" + return 0 + fi + git commit -m "${message}" + success "created commit with message: \"${message}\"" +} +####################################### +# Runs step 2 of the automated conversion. +# Arguments: +# The filepath of the file being converted. +####################################### +step2 () { + local filepath="$1" + if [ -z "${filepath}" ]; then + err "Missing argument filepath" + return 1 + fi + + inf "Verifying single goog.provide declarations..." + local provide_count=$(grep -o 'goog.provide' ${filepath} | wc -l) + if [[ "${provide_count}" -gt "1" ]]; then + err "Cannot convert file with multiple provides. Please split the file first." + return 1 + elif [[ "${provide_count}" -eq "0" ]]; then + err "Cannot convert file without a provide." + return 1 + fi + + inf "Updating goog.provide declaration..." + perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" + + + inf "Extracting module name..." + local module_name=$(grep -oP "(?<=^goog\.module\(\')([^\')]+)" "${filepath}") + if [[ -z "${module_name}" ]]; then + err "Could not extract module name" + return 1 + fi + inf "Extracted module name \"${module_name}\"" + + if [[ $(grep "${module_name} = " "${filepath}") ]]; then + local class_name=$(echo "${module_name}" | grep -oP "(\w+)$") + inf "Found class \"${class_name}\" in file." + inf "Updating class declaration..." + perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" + inf 'Updating class properties...' + perl -pi -e 's/^'"${module_name}"'((\.\w+)+) =/'"${class_name}"'\1 =/g' "${filepath}" + + inf "Updating local references to class..." + perl -pi -e 's/'"${module_name}"'([^'\''])/'"${class_name}"'\1/g' "${filepath}" + + inf "Appending class export to end of file..." + echo "" >> "${filepath}" + echo "exports = ${class_name};" >> "${filepath}" + + npm run build:deps + + success "Completed automated conversion to goog.module. Please manually review before committing." + return 0 + fi + + # No top level class. + inf 'Updating top-level property declarations...' + perl -pi -e 's/^'"${module_name}"'\.([^ ]+) =/const \1 =/g' "${filepath}" + inf "Updating local references to module..." + perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" + + npm run build:deps + success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." + +} +####################################### +# Runs step 3 of the automated conversion. +# Arguments: +# The filepath of the file being converted. +####################################### +step3() { + local filepath="$1" + if [ -z "${filepath}" ]; then + err "Missing argument filepath" + return 1 + fi + + local requires=$(grep -E -o '^goog.require(|Type)\('\''(.*)'\''\)' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + + # Process each require + echo "${requires}" | while read -r require ; do + local usages=$(grep -Pe ''"${require}"'(?!'\'')' "${filepath}" | wc -l) + if [[ "${usages}" -eq "0" ]]; then + warn "Unused require \"${require}\"" + continue + fi + + local direct_access_count=$(grep -Pe ''"${require}"'[^\.'\'']' "${filepath}" | wc -l) + local prop_access_count=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | wc -l) + if [[ "${direct_access_count}" -eq "0" && "${prop_access_count}" -gt "0" ]]; then + local deconstructed=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | perl -pe 's/'"${require}"'\.([^\(\[,\.]+).*/\1/g') + local deconstructed_comma=$(echo "${deconstructed}" | perl -zpe 's/\s+/, /g' | perl 's/, $//') + inf "Deconstructing ${require} into \"${deconstructed_comma}\"" + + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" + + echo "${deconstructed}" | while read -r require_prop ; do + inf "Updating references of ${require}.${require_prop} to ${require_prop}..." + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''])/'"${require_prop}"'\1/g' "${filepath}" + done + continue + fi + + local require_name=$(echo "${require}" | perl -pe 's/(\w+\.)+(\w+)/\2/g') + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" + + inf "Updating references of ${require} to ${require_name}..." + perl -pi -e 's/'"${require}"'([^'\''])/'"${require_name}"'\1/g' "${filepath}" + done + + local missing_requires=$(grep -Pe '(?|-s |-f] " + echo " -h Display help" + echo " -c Create a commit for the specified step [2-4]" + echo " -s Run the specified step [1-4]" +} + +if [ "$1" = "" ]; then + help +else + command="$1" + shift + case $command in + -h) help $@;; + -c) commit-step $@;; + -s) run-step $@;; + *) help;; + esac +fi From 89e4151810c08500d04cbd984a9f5a04e02e76e2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 14:48:11 -0700 Subject: [PATCH 161/833] Update commands to be OSX compatible --- scripts/goog_module/convert-file.sh | 33 ++++++++++++++++++----------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index aae6a9191..6673106ee 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -159,6 +159,7 @@ step3() { # Process each require echo "${requires}" | while read -r require ; do + inf "Processing require \"${require}\"" local usages=$(grep -Pe ''"${require}"'(?!'\'')' "${filepath}" | wc -l) if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" @@ -166,18 +167,26 @@ step3() { fi local direct_access_count=$(grep -Pe ''"${require}"'[^\.'\'']' "${filepath}" | wc -l) - local prop_access_count=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | wc -l) - if [[ "${direct_access_count}" -eq "0" && "${prop_access_count}" -gt "0" ]]; then - local deconstructed=$(grep -Pe ''"${require}"'\.(?!prototype)' "${filepath}" | perl -pe 's/'"${require}"'\.([^\(\[,\.]+).*/\1/g') - local deconstructed_comma=$(echo "${deconstructed}" | perl -zpe 's/\s+/, /g' | perl 's/, $//') - inf "Deconstructing ${require} into \"${deconstructed_comma}\"" + local properties_accessed=$(grep -Po '(?<='"${require}"'\.)(?!prototype)\w+' "${filepath}" | tr ' ' '\n' | sort -u) + # Detect overlap (ex: Blockly.utils and Blockly.utils.dom) + local overlap=$(echo "${requires}"| grep -Po "(?<=${require}\.)\w+") + if [[ ! -z "${overlap}" ]]; then + while read -r overlap_prop ; do + properties_accessed=$(echo "$properties_accessed" | perl -pe 's/'"${overlap_prop}"'//g') + done <<<"${overlap}" + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) + fi + + if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then + local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') + inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"" inf "Updating require declaration for ${require}..." - perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - echo "${deconstructed}" | while read -r require_prop ; do + echo "${properties_accessed}" | while read -r require_prop ; do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''])/'"${require_prop}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done continue fi @@ -187,13 +196,13 @@ step3() { perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" inf "Updating references of ${require} to ${require_name}..." - perl -pi -e 's/'"${require}"'([^'\''])/'"${require_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'([^'\''\w])/'"${require_name}"'\1/g' "${filepath}" done - local missing_requires=$(grep -Pe '(? Date: Tue, 20 Jul 2021 15:11:51 -0700 Subject: [PATCH 162/833] Update grep calls --- scripts/goog_module/convert-file.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 6673106ee..f7adee01e 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -105,7 +105,7 @@ step2 () { inf "Extracting module name..." - local module_name=$(grep -oP "(?<=^goog\.module\(\')([^\')]+)" "${filepath}") + local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 @@ -113,7 +113,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | grep -oP "(\w+)$") + local class_name=$(echo "${module_name}" | grep -E -o "(\w+)$") inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -160,16 +160,17 @@ step3() { # Process each require echo "${requires}" | while read -r require ; do inf "Processing require \"${require}\"" - local usages=$(grep -Pe ''"${require}"'(?!'\'')' "${filepath}" | wc -l) + local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) + if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" continue fi - local direct_access_count=$(grep -Pe ''"${require}"'[^\.'\'']' "${filepath}" | wc -l) - local properties_accessed=$(grep -Po '(?<='"${require}"'\.)(?!prototype)\w+' "${filepath}" | tr ' ' '\n' | sort -u) + local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) + local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) # Detect overlap (ex: Blockly.utils and Blockly.utils.dom) - local overlap=$(echo "${requires}"| grep -Po "(?<=${require}\.)\w+") + local overlap=$(echo "${requires}"| perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ ! -z "${overlap}" ]]; then while read -r overlap_prop ; do properties_accessed=$(echo "$properties_accessed" | perl -pe 's/'"${overlap_prop}"'//g') From edfb87fd6150b4b14c65f5f769e405b543d099c3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 15:37:50 -0700 Subject: [PATCH 163/833] Update more grep calls --- scripts/goog_module/convert-file.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index f7adee01e..9b62892b5 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -113,7 +113,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | grep -E -o "(\w+)$") + local class_name=$(echo "${module_name}" | perl -nle'print $& while m{(\w+)$}g') inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -155,7 +155,7 @@ step3() { return 1 fi - local requires=$(grep -E -o '^goog.require(|Type)\('\''(.*)'\''\)' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') # Process each require echo "${requires}" | while read -r require ; do @@ -200,7 +200,7 @@ step3() { perl -pi -e 's/'"${require}"'([^'\''\w])/'"${require_name}"'\1/g' "${filepath}" done - local missing_requires=$(grep -Po '(? Date: Thu, 24 Jun 2021 20:24:53 +0000 Subject: [PATCH 164/833] Bump google-closure-compiler from 20210505.0.0 to 20210601.0.0 Bumps [google-closure-compiler](https://github.com/google/closure-compiler-npm) from 20210505.0.0 to 20210601.0.0. - [Release notes](https://github.com/google/closure-compiler-npm/releases) - [Commits](https://github.com/google/closure-compiler-npm/compare/v20210505.0.0...v20210601.0.0) --- updated-dependencies: - dependency-name: google-closure-compiler dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package-lock.json | 38 +++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index d70d69a71..bc2e15371 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16916,45 +16916,45 @@ } }, "google-closure-compiler": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20210505.0.0.tgz", - "integrity": "sha512-moeYaj4S6YTdOOvjv1ZLdUld/2YXw7q1GqUUHJJd+rE/uViyesozg8yKQZWcB3tvurhb+qEvFFet8CYoeaQHng==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler/-/google-closure-compiler-20210601.0.0.tgz", + "integrity": "sha512-lzzEoG2VTB7uUjnWnMyeZMU163w69HJpM27yh8Up9Ha5McHZeESjt3NRwU8cWMbCRdY06nFbRCDIVCRcadHCiw==", "dev": true, "requires": { "chalk": "2.x", - "google-closure-compiler-java": "^20210505.0.0", - "google-closure-compiler-linux": "^20210505.0.0", - "google-closure-compiler-osx": "^20210505.0.0", - "google-closure-compiler-windows": "^20210505.0.0", + "google-closure-compiler-java": "^20210601.0.0", + "google-closure-compiler-linux": "^20210601.0.0", + "google-closure-compiler-osx": "^20210601.0.0", + "google-closure-compiler-windows": "^20210601.0.0", "minimist": "1.x", "vinyl": "2.x", "vinyl-sourcemaps-apply": "^0.2.0" } }, "google-closure-compiler-java": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20210505.0.0.tgz", - "integrity": "sha512-h+DfQAaaCLFmmtasOS8eyh0M4D+JInTJfEP4byV5R1cnMninpGGLHOG3PNgLLzkXkIO/fu4ILEcVzoGmgJEoMA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-java/-/google-closure-compiler-java-20210601.0.0.tgz", + "integrity": "sha512-bH6nIwOmp4qDWvlbXx5/DE3XA2aDGQoCpmRYZJGONY1Sy6Xfbq0ioXRHH9eBDP9hxhCJ5Sd/K89A0NZ8Nz9RJA==", "dev": true }, "google-closure-compiler-linux": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20210505.0.0.tgz", - "integrity": "sha512-ADN2kFfIR1NiR24kLYb4YkX4MeXDJaT5OfRQEkiuIdZMtd28oEkm80LxCGuC7ftKEixoMm3f9/OG01B4U+xsnA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-linux/-/google-closure-compiler-linux-20210601.0.0.tgz", + "integrity": "sha512-rnEQt7zz/1P1SfPhJiHQpfCgMPrsVVyEgDs09h67xn6+LXa9L0RP+hrJDEHqSWwjDPz0BkfUUv6zkqZvp1h/lw==", "dev": true, "optional": true }, "google-closure-compiler-osx": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20210505.0.0.tgz", - "integrity": "sha512-JTwdh23aD2pwRU4QZjujxp/+rGfhex3utNWEdUDRMNpUGstUK7XPCDG8jNBtUpyuRiXFnpZa90qButqRgotQBA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20210601.0.0.tgz", + "integrity": "sha512-A5r4s/WthR2iLMM0mxsluw8EW2AcOomC5ri/H6FjzpMq0RVEnLTgaGYdXolUAfEzH/7XtJJT2+JkYk3HSLCtrg==", "dev": true, "optional": true }, "google-closure-compiler-windows": { - "version": "20210505.0.0", - "resolved": "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20210505.0.0.tgz", - "integrity": "sha512-bKTbg/f4ak72OggEMaH/7oExqOO9dS+TxwGhoovYOt/YaVR/8MDfGdxsOhqoiboiFwYysTPz8bwINjYQK6AwnA==", + "version": "20210601.0.0", + "resolved": "https://registry.npmjs.org/google-closure-compiler-windows/-/google-closure-compiler-windows-20210601.0.0.tgz", + "integrity": "sha512-6r94bPShnB0XXh9+5/qXGDHJN2PQGhF9yJPcgBZj+FAZlQGzlYkT0pkyp+loZT3lG+YRbjD28Lgo7xMcY4xgkA==", "dev": true, "optional": true }, diff --git a/package.json b/package.json index dda2766d2..969a07cba 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "clang-format": "^1.5.0", "concurrently": "^6.0.0", "eslint": "^7.28.0", - "google-closure-compiler": "^20210505.0.0", + "google-closure-compiler": "^20210601.0.0", "google-closure-deps": "^20210601.0.0", "gulp": "^4.0.2", "gulp-concat": "^2.6.1", From ce078a013941b466ebe6982d61798a9ccf3ac688 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 1 Jul 2021 15:59:05 +0000 Subject: [PATCH 165/833] Bump typescript from 4.3.2 to 4.3.5 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.3.2 to 4.3.5. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v4.3.2...v4.3.5) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc2e15371..899eb7600 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21533,9 +21533,9 @@ "dev": true }, "typescript": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz", - "integrity": "sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", + "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", "dev": true }, "typescript-closure-tools": { From 8d3c39212b370c54f2262d5e4955632c2b3455cb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 12 Jul 2021 13:37:25 -0700 Subject: [PATCH 166/833] Added script and workflow to automatically update build artifact sizes in check_metadata.sh --- .github/workflows/update_metadata.yml | 39 +++++++++++++++++++++++++++ tests/scripts/update_metadata.sh | 31 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/update_metadata.yml create mode 100755 tests/scripts/update_metadata.sh diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml new file mode 100644 index 000000000..5b5e401fa --- /dev/null +++ b/.github/workflows/update_metadata.yml @@ -0,0 +1,39 @@ +# This workflow updates the check_metadata.sh script, which compares the current +# size of build artifacts against their size in the previous version of Blockly. + +name: Update Metadata + +on: [workflow_dispatch] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node-version: [16.x] + + steps: + - name: Check Out Blockly + uses: actions/checkout@v2 + with: + ref: 'develop' + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Update Metadata + run: source ./tests/scripts/update_metadata.sh + + - name: Create Pull Request + uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 + with: + commit-message: Updated build artifact sizes in check_metadata.sh + delete-branch: true + title: Updated build artifact sizes in check_metadata.sh + + - name: View Pull Request + run: echo "View Pull Request - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh new file mode 100755 index 000000000..cfd2f43d0 --- /dev/null +++ b/tests/scripts/update_metadata.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Determines the size of generated files and updates check_metadata.sh to +# reflect the new values. + +blockly_size=$(wc -c < "blockly_compressed.js") +blocks_size=$(wc -c < "blocks_compressed.js") +blockly_gz_size=$(wc -c < "blockly_compressed.js.gz") +blocks_gz_size=$(wc -c < "blocks_compressed.js.gz") +quarter=$(date "+Q%q %Y") +version=$(npx -c 'echo "$npm_package_version"') + +replacement="# ${quarter}\t${version}\t${blockly_size}\n" +replacement+="readonly BLOCKLY_SIZE_EXPECTED=${blockly_size}" +sed -ri "s/readonly BLOCKLY_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blocks_size}\n" +replacement+="readonly BLOCKS_SIZE_EXPECTED=${blocks_size}" +sed -ri "s/readonly BLOCKS_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blockly_gz_size}\n" +replacement+="readonly BLOCKLY_GZ_SIZE_EXPECTED=${blockly_gz_size}" +sed -ri "s/readonly BLOCKLY_GZ_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh + +replacement="# ${quarter}\t${version}\t${blocks_gz_size}\n" +replacement+="readonly BLOCKS_GZ_SIZE_EXPECTED=${blocks_gz_size}" +sed -ri "s/readonly BLOCKS_GZ_SIZE_EXPECTED=[0-9]+/${replacement}/g" \ + tests/scripts/check_metadata.sh \ No newline at end of file From eddc5f676b2901277d5227fa21ed927f2fb08aa3 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 13 Jul 2021 08:43:52 -0700 Subject: [PATCH 167/833] Calculate metadata size from freshly-built and gzipped Blockly. --- .github/workflows/update_metadata.yml | 29 +++++++++++++++++---------- tests/scripts/update_metadata.sh | 8 ++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 5b5e401fa..7b83b5a03 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -6,13 +6,8 @@ name: Update Metadata on: [workflow_dispatch] jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ubuntu-latest] - node-version: [16.x] + update-metadata: + runs-on: ubuntu-latest steps: - name: Check Out Blockly @@ -20,10 +15,22 @@ jobs: with: ref: 'develop' - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js 16.x uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} + node-version: 16.x + + - name: Build Blockly + run: npm run build:compressed + + - name: Build Blockly blocks + run: npm run build:blocks + + - name: Gzip Blockly + run: gzip -k build/blockly_compressed.js + + - name: Gzip Blockly blocks + run: gzip -k build/blocks_compressed.js - name: Update Metadata run: source ./tests/scripts/update_metadata.sh @@ -31,9 +38,9 @@ jobs: - name: Create Pull Request uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 with: - commit-message: Updated build artifact sizes in check_metadata.sh + commit-message: Update build artifact sizes in check_metadata.sh delete-branch: true - title: Updated build artifact sizes in check_metadata.sh + title: Update build artifact sizes in check_metadata.sh - name: View Pull Request run: echo "View Pull Request - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index cfd2f43d0..d0dac71e7 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -3,10 +3,10 @@ # Determines the size of generated files and updates check_metadata.sh to # reflect the new values. -blockly_size=$(wc -c < "blockly_compressed.js") -blocks_size=$(wc -c < "blocks_compressed.js") -blockly_gz_size=$(wc -c < "blockly_compressed.js.gz") -blocks_gz_size=$(wc -c < "blocks_compressed.js.gz") +blockly_size=$(wc -c < "build/blockly_compressed.js") +blocks_size=$(wc -c < "build/blocks_compressed.js") +blockly_gz_size=$(wc -c < "build/blockly_compressed.js.gz") +blocks_gz_size=$(wc -c < "build/blocks_compressed.js.gz") quarter=$(date "+Q%q %Y") version=$(npx -c 'echo "$npm_package_version"') From 78a5d98c20bf64876295c1b5ac6d4f849219569c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 14 Jul 2021 10:58:08 -0700 Subject: [PATCH 168/833] Gzip build output files in update_metadata.sh instead of update_metadata.yml. --- .github/workflows/update_metadata.yml | 6 ------ tests/scripts/update_metadata.sh | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/update_metadata.yml b/.github/workflows/update_metadata.yml index 7b83b5a03..82a36230f 100644 --- a/.github/workflows/update_metadata.yml +++ b/.github/workflows/update_metadata.yml @@ -26,12 +26,6 @@ jobs: - name: Build Blockly blocks run: npm run build:blocks - - name: Gzip Blockly - run: gzip -k build/blockly_compressed.js - - - name: Gzip Blockly blocks - run: gzip -k build/blocks_compressed.js - - name: Update Metadata run: source ./tests/scripts/update_metadata.sh diff --git a/tests/scripts/update_metadata.sh b/tests/scripts/update_metadata.sh index d0dac71e7..d3b97f3ab 100755 --- a/tests/scripts/update_metadata.sh +++ b/tests/scripts/update_metadata.sh @@ -3,6 +3,9 @@ # Determines the size of generated files and updates check_metadata.sh to # reflect the new values. +gzip -k build/blockly_compressed.js +gzip -k build/blocks_compressed.js + blockly_size=$(wc -c < "build/blockly_compressed.js") blocks_size=$(wc -c < "build/blocks_compressed.js") blockly_gz_size=$(wc -c < "build/blockly_compressed.js.gz") From 926b14b15ee53f185959f5867a0811e110236a19 Mon Sep 17 00:00:00 2001 From: hpnrep6 Date: Fri, 16 Jul 2021 13:42:09 -0400 Subject: [PATCH 169/833] Fix code in code demo executing twice on mobile (#5037) * Prevent code from executing twice on touchscreens --- demos/code/code.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/demos/code/code.js b/demos/code/code.js index 0c2765325..2377203a2 100644 --- a/demos/code/code.js +++ b/demos/code/code.js @@ -549,8 +549,14 @@ Code.initLanguage = function() { /** * Execute the user's code. * Just a quick and dirty eval. Catch infinite loops. + * @param {Event} event Event created from listener bound to the function. */ -Code.runJS = function() { +Code.runJS = function(event) { + // Prevent code from being executed twice on touchscreens. + if (event.type == 'touchend') { + event.preventDefault(); + } + Blockly.JavaScript.INFINITE_LOOP_TRAP = 'checkTimeout();\n'; var timeouts = 0; var checkTimeout = function() { From 3aa6b476aafc790c583dfd23826ff446119e2fcb Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 19 Jul 2021 15:59:27 +0100 Subject: [PATCH 170/833] Ignore public/ directory; always serve repository root By default http-server will serve ./public if it exists. We want it to always serve the repository root, so configure the start script to specify that explicitly, so that the existence of a public/ directory will not break things. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 969a07cba..6026bc4ec 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "publish:beta": "gulp publishBeta", "recompile": "gulp recompile", "release": "gulp gitCreateRC", - "start": "http-server -o /tests/playground.html", + "start": "http-server ./ -o /tests/playground.html", "test": "tests/run_all_tests.sh", "test:generators": "tests/scripts/run_generators.sh", "test:compile:advanced": "gulp buildAdvancedCompilationTest", From 50a66c024d6b0107e620ea6ed78e56c07cce4bfd Mon Sep 17 00:00:00 2001 From: jschanker Date: Mon, 19 Jul 2021 21:02:20 -0400 Subject: [PATCH 171/833] Permit single field disabling (#4932) (#4941) * Permit single field disabling (https://github.com/google/blockly/issues/4932) * Permit single field disabling (#4932) * Fixed lint error (moved && to end of line and adjusted line breaks accordingly) * Added XML Field (De)Serialization * Call parent method in FieldDropdown's fromXml * Added protected helper methods to handle serialization/deserialization of enabled property/attribute of fields * Minor changes to annotations to account for field disabling and 4 spaces per line break per style guide * Revert "Added XML Field (De)Serialization" This reverts commit 1964e866b6ab5c1615522f0a7a634a7ea9a9004b. * Comment style changes * Comment reversions * Indentation fix * Indentation reversion --- core/field.js | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/core/field.js b/core/field.js index c343359da..f5f027c45 100644 --- a/core/field.js +++ b/core/field.js @@ -203,6 +203,13 @@ Blockly.Field.prototype.isDirty_ = true; */ Blockly.Field.prototype.visible_ = true; +/** + * Can the field value be changed using the editor on an editable block? + * @type {boolean} + * @protected + */ +Blockly.Field.prototype.enabled_ = true; + /** * The element the click handler is bound to. * @type {Element} @@ -393,8 +400,8 @@ Blockly.Field.prototype.bindEvents_ = function() { }; /** - * Sets the field's value based on the given XML element. Should only be - * called by Blockly.Xml. + * Sets the field's value based on the given XML element. Should only be called + * by Blockly.Xml. * @param {!Element} fieldElement The element containing info about the * field's state. * @package @@ -441,7 +448,7 @@ Blockly.Field.prototype.updateEditable = function() { if (!this.EDITABLE || !group) { return; } - if (this.sourceBlock_.isEditable()) { + if (this.enabled_ && this.sourceBlock_.isEditable()) { Blockly.utils.dom.addClass(group, 'blocklyEditableText'); Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText'); group.style.cursor = this.CURSOR; @@ -452,23 +459,45 @@ Blockly.Field.prototype.updateEditable = function() { } }; +/** + * Set whether this field's value can be changed using the editor when the + * source block is editable. + * @param {boolean} enabled True if enabled. + */ +Blockly.Field.prototype.setEnabled = function(enabled) { + this.enabled_ = enabled; + this.updateEditable(); +}; + +/** + * Check whether this field's value can be changed using the editor when the + * source block is editable. + * @return {boolean} Whether this field is enabled. + */ +Blockly.Field.prototype.isEnabled = function() { + return this.enabled_; +}; + /** * Check whether this field defines the showEditor_ function. * @return {boolean} Whether this field is clickable. */ Blockly.Field.prototype.isClickable = function() { - return !!this.sourceBlock_ && this.sourceBlock_.isEditable() && - !!this.showEditor_ && (typeof this.showEditor_ === 'function'); + return this.enabled_ && !!this.sourceBlock_ && + this.sourceBlock_.isEditable() && !!this.showEditor_ && + (typeof this.showEditor_ === 'function'); }; /** * Check whether this field is currently editable. Some fields are never * EDITABLE (e.g. text labels). Other fields may be EDITABLE but may exist on - * non-editable blocks. - * @return {boolean} Whether this field is editable and on an editable block + * non-editable blocks or be currently disabled. + * @return {boolean} Whether this field is currently enabled, editable and on + * an editable block. */ Blockly.Field.prototype.isCurrentlyEditable = function() { - return this.EDITABLE && !!this.sourceBlock_ && this.sourceBlock_.isEditable(); + return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ && + this.sourceBlock_.isEditable(); }; /** From e9a16684455c790e98ae99c5321d71ca745c92d5 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Mon, 19 Jul 2021 18:14:23 -0700 Subject: [PATCH 172/833] Only lint once in CI (#5128) --- .github/workflows/build.yml | 16 ++++++++++++++++ tests/run_all_tests.sh | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f00730990..9a7d2b859 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,3 +41,19 @@ jobs: env: CI: true + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js 16.x + uses: actions/setup-node@v1 + with: + node-version: 16.x + + - name: Npm Install + run: npm install + + - name: Lint + run: npm run lint diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index f6c7c0f8c..ccb18cf9c 100755 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -49,7 +49,10 @@ run_test_command () { } # Lint the codebase. -run_test_command "eslint" "eslint ." +# Skip for CI environments, because linting is run separately. +if [ -z $CI ]; then + run_test_command "eslint" "eslint ." +fi # Run the full usual build process. run_test_command "build" "npm run build" From 6b10f9545c7e18d806bc8926a7d612e61e0e8712 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 16 Jul 2021 15:11:14 -0700 Subject: [PATCH 173/833] Migrate core/interfaces/i_registrable.js to goog.module --- core/interfaces/i_registrable.js | 7 +++++-- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/interfaces/i_registrable.js b/core/interfaces/i_registrable.js index f7b8ca719..5698ad313 100644 --- a/core/interfaces/i_registrable.js +++ b/core/interfaces/i_registrable.js @@ -12,11 +12,14 @@ 'use strict'; -goog.provide('Blockly.IRegistrable'); +goog.module('Blockly.IRegistrable'); +goog.module.declareLegacyNamespace(); /** * The interface for a Blockly component that can be registered. * @interface */ -Blockly.IRegistrable = function() {}; +const IRegistrable = function() {}; + +exports = IRegistrable; diff --git a/tests/deps.js b/tests/deps.js index 95ce972c7..aa7cf5039 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -93,7 +93,7 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); From 599385891a896e9f6f4b18442076f5ba8ce3db5f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:08:27 -0700 Subject: [PATCH 174/833] Break up interfaces in core/i_toolbox_item.js into separate files --- core/interfaces/i_collapsible_toolbox_item.js | 45 +++++++++++ core/interfaces/i_selectable_toolbox_item.js | 65 ++++++++++++++++ core/interfaces/i_toolbox_item.js | 76 ------------------- 3 files changed, 110 insertions(+), 76 deletions(-) create mode 100644 core/interfaces/i_collapsible_toolbox_item.js create mode 100644 core/interfaces/i_selectable_toolbox_item.js diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js new file mode 100644 index 000000000..c92008358 --- /dev/null +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -0,0 +1,45 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for a collapsible toolbox item. + * @author kozbial@google.com (Monica Kozbial) + */ + +'use strict'; + +goog.provide('Blockly.ICollapsibleToolboxItem'); + +goog.require('Blockly.IToolboxItem'); +goog.requireType('Blockly.utils.toolbox'); + + +/** + * Interface for an item in the toolbox that can be collapsed. + * @extends {Blockly.ISelectableToolboxItem} + * @interface + */ +Blockly.ICollapsibleToolboxItem = function() {}; + +/** + * Gets any children toolbox items. (ex. Gets the subcategories) + * @return {!Array} The child toolbox items. + */ +Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; + +/** + * Whether the toolbox item is expanded to show its child subcategories. + * @return {boolean} True if the toolbox item shows its children, false if it + * is collapsed. + * @public + */ +Blockly.ICollapsibleToolboxItem.prototype.isExpanded; + +/** + * Toggles whether or not the toolbox item is expanded. + * @public + */ +Blockly.ICollapsibleToolboxItem.prototype.toggleExpanded; diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js new file mode 100644 index 000000000..fb7b8558f --- /dev/null +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -0,0 +1,65 @@ +/** + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview The interface for a selectable toolbox item. + * @author aschmiedt@google.com (Abby Schmiedt) + */ + +'use strict'; + +goog.provide('Blockly.ISelectableToolboxItem'); + +goog.require('Blockly.IToolboxItem'); +goog.requireType('Blockly.utils.toolbox'); + + +/** + * Interface for an item in the toolbox that can be selected. + * @extends {Blockly.IToolboxItem} + * @interface + */ +Blockly.ISelectableToolboxItem = function() {}; + +/** + * Gets the name of the toolbox item. Used for emitting events. + * @return {string} The name of the toolbox item. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.getName; + +/** + * Gets the contents of the toolbox item. These are items that are meant to be + * displayed in the flyout. + * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray|string} The definition + * of items to be displayed in the flyout. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.getContents; + +/** + * Sets the current toolbox item as selected. + * @param {boolean} _isSelected True if this category is selected, false + * otherwise. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.setSelected; + +/** + * Gets the HTML element that is clickable. + * The parent toolbox element receives clicks. The parent toolbox will add an ID + * to this element so it can pass the onClick event to the correct toolboxItem. + * @return {!Element} The HTML element that receives clicks. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.getClickTarget; + +/** + * Handles when the toolbox item is clicked. + * @param {!Event} _e Click event to handle. + * @public + */ +Blockly.ISelectableToolboxItem.prototype.onClick; diff --git a/core/interfaces/i_toolbox_item.js b/core/interfaces/i_toolbox_item.js index afd6191f7..ce646d376 100644 --- a/core/interfaces/i_toolbox_item.js +++ b/core/interfaces/i_toolbox_item.js @@ -11,8 +11,6 @@ 'use strict'; -goog.provide('Blockly.ICollapsibleToolboxItem'); -goog.provide('Blockly.ISelectableToolboxItem'); goog.provide('Blockly.IToolboxItem'); goog.requireType('Blockly.utils.toolbox'); @@ -81,77 +79,3 @@ Blockly.IToolboxItem.prototype.isCollapsible; * @public */ Blockly.IToolboxItem.prototype.dispose; - -/** - * Interface for an item in the toolbox that can be selected. - * @extends {Blockly.IToolboxItem} - * @interface - */ -Blockly.ISelectableToolboxItem = function() {}; - -/** - * Gets the name of the toolbox item. Used for emitting events. - * @return {string} The name of the toolbox item. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.getName; - -/** - * Gets the contents of the toolbox item. These are items that are meant to be - * displayed in the flyout. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray|string} The definition - * of items to be displayed in the flyout. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.getContents; - -/** - * Sets the current toolbox item as selected. - * @param {boolean} _isSelected True if this category is selected, false - * otherwise. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.setSelected; - -/** - * Gets the HTML element that is clickable. - * The parent toolbox element receives clicks. The parent toolbox will add an ID - * to this element so it can pass the onClick event to the correct toolboxItem. - * @return {!Element} The HTML element that receives clicks. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.getClickTarget; - -/** - * Handles when the toolbox item is clicked. - * @param {!Event} _e Click event to handle. - * @public - */ -Blockly.ISelectableToolboxItem.prototype.onClick; - -/** - * Interface for an item in the toolbox that can be collapsed. - * @extends {Blockly.ISelectableToolboxItem} - * @interface - */ -Blockly.ICollapsibleToolboxItem = function() {}; - -/** - * Gets any children toolbox items. (ex. Gets the subcategories) - * @return {!Array} The child toolbox items. - */ -Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; - -/** - * Whether the toolbox item is expanded to show its child subcategories. - * @return {boolean} True if the toolbox item shows its children, false if it - * is collapsed. - * @public - */ -Blockly.ICollapsibleToolboxItem.prototype.isExpanded; - -/** - * Toggles whether or not the toolbox item is expanded. - * @public - */ -Blockly.ICollapsibleToolboxItem.prototype.toggleExpanded; From 1b09c8d8b736257d5829c9629c3dcc7e771f0290 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:09:51 -0700 Subject: [PATCH 175/833] Migrate core/interfaces/i_collapsible_toolbox_item.js, core/interfaces/i_selectable_toolbox_item.js, and core/interfaces/i_toolbox_item.js to goog.module --- core/interfaces/i_collapsible_toolbox_item.js | 17 +++++++------ core/interfaces/i_selectable_toolbox_item.js | 17 +++++++------ core/interfaces/i_toolbox_item.js | 25 ++++++++++--------- tests/deps.js | 4 ++- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index c92008358..3af4d2692 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -11,10 +11,11 @@ 'use strict'; -goog.provide('Blockly.ICollapsibleToolboxItem'); +goog.module('Blockly.ICollapsibleToolboxItem'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.IToolboxItem'); -goog.requireType('Blockly.utils.toolbox'); +goog.require('Blockly.ISelectableToolboxItem'); +goog.requireType('Blockly.IToolboxItem'); /** @@ -22,13 +23,13 @@ goog.requireType('Blockly.utils.toolbox'); * @extends {Blockly.ISelectableToolboxItem} * @interface */ -Blockly.ICollapsibleToolboxItem = function() {}; +const ICollapsibleToolboxItem = function() {}; /** * Gets any children toolbox items. (ex. Gets the subcategories) * @return {!Array} The child toolbox items. */ -Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; +ICollapsibleToolboxItem.prototype.getChildToolboxItems; /** * Whether the toolbox item is expanded to show its child subcategories. @@ -36,10 +37,12 @@ Blockly.ICollapsibleToolboxItem.prototype.getChildToolboxItems; * is collapsed. * @public */ -Blockly.ICollapsibleToolboxItem.prototype.isExpanded; +ICollapsibleToolboxItem.prototype.isExpanded; /** * Toggles whether or not the toolbox item is expanded. * @public */ -Blockly.ICollapsibleToolboxItem.prototype.toggleExpanded; +ICollapsibleToolboxItem.prototype.toggleExpanded; + +exports = ICollapsibleToolboxItem; diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index fb7b8558f..535f65401 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.ISelectableToolboxItem'); +goog.module('Blockly.ISelectableToolboxItem'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IToolboxItem'); goog.requireType('Blockly.utils.toolbox'); @@ -22,14 +23,14 @@ goog.requireType('Blockly.utils.toolbox'); * @extends {Blockly.IToolboxItem} * @interface */ -Blockly.ISelectableToolboxItem = function() {}; +const ISelectableToolboxItem = function() {}; /** * Gets the name of the toolbox item. Used for emitting events. * @return {string} The name of the toolbox item. * @public */ -Blockly.ISelectableToolboxItem.prototype.getName; +ISelectableToolboxItem.prototype.getName; /** * Gets the contents of the toolbox item. These are items that are meant to be @@ -38,7 +39,7 @@ Blockly.ISelectableToolboxItem.prototype.getName; * of items to be displayed in the flyout. * @public */ -Blockly.ISelectableToolboxItem.prototype.getContents; +ISelectableToolboxItem.prototype.getContents; /** * Sets the current toolbox item as selected. @@ -46,7 +47,7 @@ Blockly.ISelectableToolboxItem.prototype.getContents; * otherwise. * @public */ -Blockly.ISelectableToolboxItem.prototype.setSelected; +ISelectableToolboxItem.prototype.setSelected; /** * Gets the HTML element that is clickable. @@ -55,11 +56,13 @@ Blockly.ISelectableToolboxItem.prototype.setSelected; * @return {!Element} The HTML element that receives clicks. * @public */ -Blockly.ISelectableToolboxItem.prototype.getClickTarget; +ISelectableToolboxItem.prototype.getClickTarget; /** * Handles when the toolbox item is clicked. * @param {!Event} _e Click event to handle. * @public */ -Blockly.ISelectableToolboxItem.prototype.onClick; +ISelectableToolboxItem.prototype.onClick; + +exports = ISelectableToolboxItem; diff --git a/core/interfaces/i_toolbox_item.js b/core/interfaces/i_toolbox_item.js index ce646d376..061b7ae27 100644 --- a/core/interfaces/i_toolbox_item.js +++ b/core/interfaces/i_toolbox_item.js @@ -11,16 +11,15 @@ 'use strict'; -goog.provide('Blockly.IToolboxItem'); - -goog.requireType('Blockly.utils.toolbox'); +goog.module('Blockly.IToolboxItem'); +goog.module.declareLegacyNamespace(); /** * Interface for an item in the toolbox. * @interface */ -Blockly.IToolboxItem = function() {}; +const IToolboxItem = function() {}; /** * Initializes the toolbox item. @@ -29,21 +28,21 @@ Blockly.IToolboxItem = function() {}; * @return {void} * @public */ -Blockly.IToolboxItem.prototype.init; +IToolboxItem.prototype.init; /** * Gets the div for the toolbox item. * @return {?Element} The div for the toolbox item. * @public */ -Blockly.IToolboxItem.prototype.getDiv; +IToolboxItem.prototype.getDiv; /** * Gets a unique identifier for this toolbox item. * @return {string} The ID for the toolbox item. * @public */ -Blockly.IToolboxItem.prototype.getId; +IToolboxItem.prototype.getId; /** * Gets the parent if the toolbox item is nested. @@ -51,31 +50,33 @@ Blockly.IToolboxItem.prototype.getId; * this toolbox item is not nested. * @public */ -Blockly.IToolboxItem.prototype.getParent; +IToolboxItem.prototype.getParent; /** * Gets the nested level of the category. * @return {number} The nested level of the category. * @package */ -Blockly.IToolboxItem.prototype.getLevel; +IToolboxItem.prototype.getLevel; /** * Whether the toolbox item is selectable. * @return {boolean} True if the toolbox item can be selected. * @public */ -Blockly.IToolboxItem.prototype.isSelectable; +IToolboxItem.prototype.isSelectable; /** * Whether the toolbox item is collapsible. * @return {boolean} True if the toolbox item is collapsible. * @public */ -Blockly.IToolboxItem.prototype.isCollapsible; +IToolboxItem.prototype.isCollapsible; /** * Dispose of this toolbox item. No-op by default. * @public */ -Blockly.IToolboxItem.prototype.dispose; +IToolboxItem.prototype.dispose; + +exports = IToolboxItem; diff --git a/tests/deps.js b/tests/deps.js index aa7cf5039..979c58c74 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -80,6 +80,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -96,9 +97,10 @@ goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositio goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 3c77ff1fb2d6096a00d21f99fe71a5df48b2e750 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:19:08 -0700 Subject: [PATCH 176/833] Migrate core/interfaces/i_collapsible_toolbox_item.js, core/interfaces/i_selectable_toolbox_item.js, and core/interfaces/i_toolbox_item.js named requires --- core/interfaces/i_collapsible_toolbox_item.js | 8 ++++---- core/interfaces/i_selectable_toolbox_item.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index 3af4d2692..732c7aab7 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -14,20 +14,20 @@ goog.module('Blockly.ICollapsibleToolboxItem'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ISelectableToolboxItem'); -goog.requireType('Blockly.IToolboxItem'); +const ISelectableToolboxItem = goog.require('Blockly.ISelectableToolboxItem'); +const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); /** * Interface for an item in the toolbox that can be collapsed. - * @extends {Blockly.ISelectableToolboxItem} + * @extends {ISelectableToolboxItem} * @interface */ const ICollapsibleToolboxItem = function() {}; /** * Gets any children toolbox items. (ex. Gets the subcategories) - * @return {!Array} The child toolbox items. + * @return {!Array} The child toolbox items. */ ICollapsibleToolboxItem.prototype.getChildToolboxItems; diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index 535f65401..2addc7b9e 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -14,13 +14,13 @@ goog.module('Blockly.ISelectableToolboxItem'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IToolboxItem'); -goog.requireType('Blockly.utils.toolbox'); +const IToolboxItem = goog.require('Blockly.IToolboxItem'); +const {FlyoutItemInfoArray} = goog.requireType('Blockly.utils.toolbox'); /** * Interface for an item in the toolbox that can be selected. - * @extends {Blockly.IToolboxItem} + * @extends {IToolboxItem} * @interface */ const ISelectableToolboxItem = function() {}; @@ -35,7 +35,7 @@ ISelectableToolboxItem.prototype.getName; /** * Gets the contents of the toolbox item. These are items that are meant to be * displayed in the flyout. - * @return {!Blockly.utils.toolbox.FlyoutItemInfoArray|string} The definition + * @return {!FlyoutItemInfoArray|string} The definition * of items to be displayed in the flyout. * @public */ From b2ed132ebb1f5d3bd118c4085472ad1d9f14f06b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:52:52 -0700 Subject: [PATCH 177/833] Fix bug where script was incorrectly reporting missing requires --- scripts/goog_module/convert-file.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 9b62892b5..35d3f3377 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -201,12 +201,12 @@ step3() { done local missing_requires=$(perl -nle'print $& while m{(? Date: Tue, 20 Jul 2021 17:54:09 -0700 Subject: [PATCH 178/833] Fix bugs caused by Blockly being a require --- scripts/goog_module/convert-file.sh | 31 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 35d3f3377..5fc37fe19 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -155,6 +155,14 @@ step3() { return 1 fi + inf "Extracting module name..." + local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + if [[ -z "${module_name}" ]]; then + err "Could not extract module name" + return 1 + fi + inf "Extracted module name \"${module_name}\"" + local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') # Process each require @@ -169,14 +177,21 @@ step3() { local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) - # Detect overlap (ex: Blockly.utils and Blockly.utils.dom) - local overlap=$(echo "${requires}"| perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${overlap}" ]]; then - while read -r overlap_prop ; do - properties_accessed=$(echo "$properties_accessed" | perl -pe 's/'"${overlap_prop}"'//g') - done <<<"${overlap}" - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) + # Detect requires overlap + # (ex: Blockly.utils require and Blockly.utils.dom also in requires) + local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + if [[ ! -z "${requires_overlap}" ]]; then + while read -r requires_overlap_prop ; do + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') + done <<<"${requires_overlap}" fi + # Detect module name overlap + # (ex: Blockly require and Blockly.ContextMenuItems module being converted) + local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + if [[ ! -z "${module_overlap}" ]]; then + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') + fi + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') @@ -185,7 +200,7 @@ step3() { inf "Updating require declaration for ${require}..." perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - echo "${properties_accessed}" | while read -r require_prop ; do + for require_prop in $(echo "${properties_accessed}"); do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done From 5e3209b6f5dfccc2ca5ee076a50c045ec225a9fc Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 17:57:37 -0700 Subject: [PATCH 179/833] Remove extra logging line --- scripts/goog_module/convert-file.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 5fc37fe19..7a440b8b9 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -217,7 +217,6 @@ step3() { local missing_requires=$(perl -nle'print $& while m{(? Date: Tue, 20 Jul 2021 18:16:37 -0700 Subject: [PATCH 180/833] fix formatting and help --- scripts/goog_module/convert-file.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 7a440b8b9..79ceeed42 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -141,7 +141,6 @@ step2 () { npm run build:deps success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." - } ####################################### # Runs step 3 of the automated conversion. @@ -285,7 +284,7 @@ function help { echo " 3. Rewrite goog.requires statements and add missing requires (often skipped for simple files)" echo " 4. Run clang-format on the whole file" echo "" - echo "Usage: $0 [-h|-c |-s |-f] " + echo "Usage: $0 [-h|-c |-s ] " echo " -h Display help" echo " -c Create a commit for the specified step [2-4]" echo " -s Run the specified step [1-4]" From 8d6f2626cda8703c1b4a01139cc721f76e854bae Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 19:01:01 -0700 Subject: [PATCH 181/833] Remove command to add missing nullability modifiers --- scripts/goog_module/convert-file.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 79ceeed42..1861ad7f3 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -219,9 +219,6 @@ step3() { err "Missing requires for: ${missing_requires} Please manually fix." fi - inf "Add missing nullability modifiers..." - perl -pi -e 's/@(param|return) \{([A-Z])/@\1 \{?\2/g' "${filepath}" - success "Completed automation for step 3. Please manually review and reorder requires." } ####################################### From 0e6258ca1a78f384944977c29e5c3e3bcf0ba748 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:17:13 -0700 Subject: [PATCH 182/833] Migrated to inline exports --- core/block_animations.js | 31 +++++----- core/block_drag_surface.js | 2 +- core/bubble_dragger.js | 11 +++- core/comment.js | 6 ++ core/component_manager.js | 5 ++ core/connection.js | 8 ++- core/connection_checker.js | 2 + core/connection_db.js | 3 + core/css.js | 9 +-- core/extensions.js | 20 +++--- core/interfaces/i_ast_node_location_svg.js | 1 + .../i_ast_node_location_with_block.js | 2 + core/interfaces/i_autohideable.js | 1 + core/interfaces/i_block_dragger.js | 2 + core/interfaces/i_bounded_element.js | 1 + core/interfaces/i_bubble.js | 4 ++ core/interfaces/i_connection_checker.js | 2 + core/interfaces/i_copyable.js | 2 + core/interfaces/i_delete_area.js | 2 + core/interfaces/i_drag_target.js | 3 + core/interfaces/i_draggable.js | 1 + core/interfaces/i_flyout.js | 6 ++ core/interfaces/i_keyboard_accessible.js | 1 + core/interfaces/i_positionable.js | 3 + core/interfaces/i_toolbox.js | 5 ++ core/renderers/common/drawer.js | 9 ++- core/utils/colour.js | 15 ++--- core/utils/deprecation.js | 5 +- core/utils/idgenerator.js | 4 +- core/utils/math.js | 9 +-- core/utils/object.js | 11 ++-- core/utils/style.js | 48 +++++++-------- core/utils/svg_paths.js | 27 +++----- core/utils/toolbox.js | 61 ++++++++----------- 34 files changed, 178 insertions(+), 144 deletions(-) diff --git a/core/block_animations.js b/core/block_animations.js index 86b4b44b5..27926002e 100644 --- a/core/block_animations.js +++ b/core/block_animations.js @@ -13,9 +13,10 @@ goog.module('Blockly.blockAnimations'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); -const dom = goog.require('Blockly.utils.dom'); const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); /** @@ -34,7 +35,7 @@ let disconnectGroup = null; * Play some UI effects (sound, animation) when disposing of a block. * @param {!BlockSvg} block The block being disposed of. */ -function disposeUiEffect(block) { +const disposeUiEffect = function(block) { const workspace = block.workspace; const svgGroup = block.getSvgRoot(); workspace.getAudioManager().play('delete'); @@ -49,7 +50,7 @@ function disposeUiEffect(block) { clone.bBox_ = clone.getBBox(); // Start the animation. disposeUiStep(clone, workspace.RTL, new Date, workspace.scale); -} +}; /** @package */ exports.disposeUiEffect = disposeUiEffect; @@ -62,7 +63,7 @@ exports.disposeUiEffect = disposeUiEffect; * @param {!Date} start Date of animation's start. * @param {number} workspaceScale Scale of workspace. */ -function disposeUiStep(clone, rtl, start, workspaceScale) { +const disposeUiStep = function(clone, rtl, start, workspaceScale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -78,13 +79,13 @@ function disposeUiStep(clone, rtl, start, workspaceScale) { ' scale(' + scale + ')'); setTimeout(disposeUiStep, 10, clone, rtl, start, workspaceScale); } -} +}; /** * Play some UI effects (sound, ripple) after a connection has been established. * @param {!BlockSvg} block The block being connected. */ -function connectionUiEffect(block) { +const connectionUiEffect = function(block) { const workspace = block.workspace; const scale = workspace.scale; workspace.getAudioManager().play('click'); @@ -113,7 +114,7 @@ function connectionUiEffect(block) { workspace.getParentSvg()); // Start the animation. connectionUiStep(ripple, new Date, scale); -} +}; /** @package */ exports.connectionUiEffect = connectionUiEffect; @@ -123,7 +124,7 @@ exports.connectionUiEffect = connectionUiEffect; * @param {!Date} start Date of animation's start. * @param {number} scale Scale of workspace. */ -function connectionUiStep(ripple, start, scale) { +const connectionUiStep = function(ripple, start, scale) { const ms = new Date - start; const percent = ms / 150; if (percent > 1) { @@ -133,13 +134,13 @@ function connectionUiStep(ripple, start, scale) { ripple.style.opacity = 1 - percent; disconnectPid = setTimeout(connectionUiStep, 10, ripple, start, scale); } -} +}; /** * Play some UI effects (sound, animation) when disconnecting a block. * @param {!BlockSvg} block The block being disconnected. */ -function disconnectUiEffect(block) { +const disconnectUiEffect = function(block) { block.workspace.getAudioManager().play('disconnect'); if (block.workspace.scale < 1) { return; // Too small to care about visual effects. @@ -154,7 +155,7 @@ function disconnectUiEffect(block) { } // Start the animation. disconnectUiStep(block.getSvgRoot(), magnitude, new Date); -} +}; /** @package */ exports.disconnectUiEffect = disconnectUiEffect; @@ -164,7 +165,7 @@ exports.disconnectUiEffect = disconnectUiEffect; * @param {number} magnitude Maximum degrees skew (reversed for RTL). * @param {!Date} start Date of animation's start. */ -function disconnectUiStep(group, magnitude, start) { +const disconnectUiStep = function(group, magnitude, start) { const DURATION = 200; // Milliseconds. const WIGGLES = 3; // Half oscillations. @@ -181,12 +182,12 @@ function disconnectUiStep(group, magnitude, start) { disconnectPid = setTimeout(disconnectUiStep, 10, group, magnitude, start); } group.setAttribute('transform', group.translate_ + group.skew_); -} +}; /** * Stop the disconnect UI animation immediately. */ -function disconnectUiStop() { +const disconnectUiStop = function() { if (disconnectGroup) { clearTimeout(disconnectPid); const group = disconnectGroup; @@ -194,6 +195,6 @@ function disconnectUiStop() { group.setAttribute('transform', group.translate_); disconnectGroup = null; } -} +}; /** @package */ exports.disconnectUiStop = disconnectUiStop; diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 69b7a5ca5..2b911ef09 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -20,8 +20,8 @@ goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); const {G, SVG} = goog.require('Blockly.utils.Svg'); -const {getRelativeXY} = goog.require('Blockly.utils'); const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom'); +const {getRelativeXY} = goog.require('Blockly.utils'); /** diff --git a/core/bubble_dragger.js b/core/bubble_dragger.js index 3a6d36331..d06c2fdc0 100644 --- a/core/bubble_dragger.js +++ b/core/bubble_dragger.js @@ -13,21 +13,26 @@ goog.module('Blockly.BubbleDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); const ComponentManager = goog.require('Blockly.ComponentManager'); const Coordinate = goog.require('Blockly.utils.Coordinate'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IBubble = goog.requireType('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); -const utils = goog.require('Blockly.utils'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Bubble'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -/** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentMove'); +/** @suppress {extraRequire} */ +goog.require('Blockly.constants'); /** diff --git a/core/comment.js b/core/comment.js index 7f4085faf..99d81e89c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -13,16 +13,22 @@ goog.module('Blockly.Comment'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const Bubble = goog.require('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); const Events = goog.require('Blockly.Events'); const Icon = goog.require('Blockly.Icon'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const userAgent = goog.require('Blockly.utils.userAgent'); +/* eslint-disable-next-line no-unused-vars */ const {conditionalBind, Data, unbind} = goog.require('Blockly.browserEvents'); const {createSvgElement, HTML_NS} = goog.require('Blockly.utils.dom'); const {inherits} = goog.require('Blockly.utils.object'); diff --git a/core/component_manager.js b/core/component_manager.js index 31b661e8a..ad2370bd6 100644 --- a/core/component_manager.js +++ b/core/component_manager.js @@ -14,10 +14,15 @@ goog.module('Blockly.ComponentManager'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IAutoHideable = goog.requireType('Blockly.IAutoHideable'); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.requireType('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const IDeleteArea = goog.requireType('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); +/* eslint-disable-next-line no-unused-vars */ const IPositionable = goog.requireType('Blockly.IPositionable'); diff --git a/core/connection.js b/core/connection.js index 553938825..f272b59e0 100644 --- a/core/connection.js +++ b/core/connection.js @@ -13,14 +13,18 @@ goog.module('Blockly.Connection'); goog.module.declareLegacyNamespace(); -const connectionTypes = goog.require('Blockly.connectionTypes'); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); -const deprecation = goog.require('Blockly.utils.deprecation'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); const Xml = goog.require('Blockly.Xml'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const deprecation = goog.require('Blockly.utils.deprecation'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); /** @suppress {extraRequire} */ diff --git a/core/connection_checker.js b/core/connection_checker.js index 4bd7bd4e2..12c6418db 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -15,7 +15,9 @@ goog.module('Blockly.ConnectionChecker'); goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); diff --git a/core/connection_db.js b/core/connection_db.js index 49bccb504..d3bc0507d 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -15,8 +15,11 @@ goog.module('Blockly.ConnectionDB'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.require('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); /** @suppress {extraRequire} */ diff --git a/core/css.js b/core/css.js index 52228b4fb..6f34e6c0d 100644 --- a/core/css.js +++ b/core/css.js @@ -39,6 +39,7 @@ const register = function(cssArray) { Array.prototype.push.apply(CONTENT, cssArray); cssArray.length = 0; // Garbage collect provided CSS content. }; +exports.register = register; /** * Inject the CSS into the DOM. This is preferable over using a regular CSS @@ -72,6 +73,7 @@ const inject = function(hasCss, pathToMedia) { cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); }; +exports.inject = inject; /** * Array making up the CSS content for Blockly. @@ -553,9 +555,4 @@ const CONTENT = [ margin-right: -24px; }`, ]; - -exports = { - register, - inject, - CONTENT -}; +exports.CONTENT = CONTENT; diff --git a/core/extensions.js b/core/extensions.js index c73737c43..3f20777aa 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -20,6 +20,7 @@ goog.module('Blockly.Extensions'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goog.require('Blockly.utils'); @@ -29,6 +30,7 @@ const {checkMessageReferences, replaceMessageReferences, runAfterPageLoad} = goo * @private */ const allExtensions = Object.create(null); +exports.ALL_ = allExtensions; /** * Registers a new extension function. Extensions are functions that help @@ -52,6 +54,7 @@ const register = function(name, initFn) { } allExtensions[name] = initFn; }; +exports.register = register; /** * Registers a new extension function that adds all key/value of mixinObj. @@ -68,6 +71,7 @@ const registerMixin = function(name, mixinObj) { this.mixin(mixinObj); }); }; +exports.registerMixin = registerMixin; /** * Registers a new extension function that adds a mutator to the block. @@ -111,6 +115,7 @@ const registerMutator = function(name, mixinObj, opt_helperFn, opt_blockList) { } }); }; +exports.registerMutator = registerMutator; /** * Unregisters the extension registered with the given name. @@ -124,6 +129,7 @@ const unregister = function(name) { 'No extension mapping for name "' + name + '" found to unregister'); } }; +exports.unregister = unregister; /** * Applies an extension method to a block. This should only be called during @@ -161,6 +167,7 @@ const apply = function(name, block, isMutator) { } } }; +exports.apply = apply; /** * Check that the given value is a function. @@ -366,6 +373,7 @@ const buildTooltipForDropdown = function(dropdownName, lookupTable) { }; return extensionFn; }; +exports.buildTooltipForDropdown = buildTooltipForDropdown; /** * Checks all options keys are present in the provided string lookup table. @@ -425,6 +433,7 @@ const buildTooltipWithFieldText = function(msgTemplate, fieldName) { }; return extensionFn; }; +exports.buildTooltipWithFieldText = buildTooltipWithFieldText; /** * Configures the tooltip to mimic the parent block when connected. Otherwise, @@ -443,14 +452,3 @@ const extensionParentTooltip = function() { }.bind(this)); }; register('parent_tooltip_when_inline', extensionParentTooltip); - -exports = { - ALL_: allExtensions, - register, - registerMixin, - registerMutator, - unregister, - apply, - buildTooltipForDropdown, - buildTooltipWithFieldText -}; diff --git a/core/interfaces/i_ast_node_location_svg.js b/core/interfaces/i_ast_node_location_svg.js index 5b58d4abc..526fbffa3 100644 --- a/core/interfaces/i_ast_node_location_svg.js +++ b/core/interfaces/i_ast_node_location_svg.js @@ -14,6 +14,7 @@ goog.module('Blockly.IASTNodeLocationSvg'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); diff --git a/core/interfaces/i_ast_node_location_with_block.js b/core/interfaces/i_ast_node_location_with_block.js index 58da7a902..002db0ad8 100644 --- a/core/interfaces/i_ast_node_location_with_block.js +++ b/core/interfaces/i_ast_node_location_with_block.js @@ -15,7 +15,9 @@ goog.module('Blockly.IASTNodeLocationWithBlock'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.require('Blockly.IASTNodeLocation'); diff --git a/core/interfaces/i_autohideable.js b/core/interfaces/i_autohideable.js index bf11adc01..0ccbf310a 100644 --- a/core/interfaces/i_autohideable.js +++ b/core/interfaces/i_autohideable.js @@ -15,6 +15,7 @@ goog.module('Blockly.IAutoHideable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); diff --git a/core/interfaces/i_block_dragger.js b/core/interfaces/i_block_dragger.js index ebfc820ba..b87cd9865 100644 --- a/core/interfaces/i_block_dragger.js +++ b/core/interfaces/i_block_dragger.js @@ -14,7 +14,9 @@ goog.module('Blockly.IBlockDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); diff --git a/core/interfaces/i_bounded_element.js b/core/interfaces/i_bounded_element.js index 461d52ca1..f2c84633e 100644 --- a/core/interfaces/i_bounded_element.js +++ b/core/interfaces/i_bounded_element.js @@ -14,6 +14,7 @@ goog.module('Blockly.IBoundedElement'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); diff --git a/core/interfaces/i_bubble.js b/core/interfaces/i_bubble.js index e41a1bf25..b6e9736d7 100644 --- a/core/interfaces/i_bubble.js +++ b/core/interfaces/i_bubble.js @@ -14,9 +14,13 @@ goog.module('Blockly.IBubble'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IContextMenu = goog.require('Blockly.IContextMenu'); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.require('Blockly.IDraggable'); diff --git a/core/interfaces/i_connection_checker.js b/core/interfaces/i_connection_checker.js index 03693604c..d0eb21e24 100644 --- a/core/interfaces/i_connection_checker.js +++ b/core/interfaces/i_connection_checker.js @@ -14,7 +14,9 @@ goog.module('Blockly.IConnectionChecker'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); diff --git a/core/interfaces/i_copyable.js b/core/interfaces/i_copyable.js index 07556eb23..87b776600 100644 --- a/core/interfaces/i_copyable.js +++ b/core/interfaces/i_copyable.js @@ -14,7 +14,9 @@ goog.module('Blockly.ICopyable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ISelectable = goog.requireType('Blockly.ISelectable'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); diff --git a/core/interfaces/i_delete_area.js b/core/interfaces/i_delete_area.js index 5c5cbd380..845d7dddb 100644 --- a/core/interfaces/i_delete_area.js +++ b/core/interfaces/i_delete_area.js @@ -15,7 +15,9 @@ goog.module('Blockly.IDeleteArea'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.require('Blockly.IDragTarget'); diff --git a/core/interfaces/i_drag_target.js b/core/interfaces/i_drag_target.js index 803bcbc74..6b777781d 100644 --- a/core/interfaces/i_drag_target.js +++ b/core/interfaces/i_drag_target.js @@ -15,8 +15,11 @@ goog.module('Blockly.IDragTarget'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); diff --git a/core/interfaces/i_draggable.js b/core/interfaces/i_draggable.js index 81303a24b..5d7e17d53 100644 --- a/core/interfaces/i_draggable.js +++ b/core/interfaces/i_draggable.js @@ -14,6 +14,7 @@ goog.module('Blockly.IDraggable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IDeletable = goog.require('Blockly.IDeletable'); diff --git a/core/interfaces/i_flyout.js b/core/interfaces/i_flyout.js index b9b1c8e15..23c76dd0b 100644 --- a/core/interfaces/i_flyout.js +++ b/core/interfaces/i_flyout.js @@ -14,11 +14,17 @@ goog.module('Blockly.IFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ const Svg = goog.requireType('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const {FlyoutDefinition} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8f21153da..8243e67d1 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -14,6 +14,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); diff --git a/core/interfaces/i_positionable.js b/core/interfaces/i_positionable.js index ed324196b..1fe773add 100644 --- a/core/interfaces/i_positionable.js +++ b/core/interfaces/i_positionable.js @@ -14,8 +14,11 @@ goog.module('Blockly.IPositionable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IComponent = goog.require('Blockly.IComponent'); +/* eslint-disable-next-line no-unused-vars */ const Rect = goog.requireType('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ const {UiMetrics} = goog.requireType('Blockly.MetricsManager'); diff --git a/core/interfaces/i_toolbox.js b/core/interfaces/i_toolbox.js index 5ecd0a69f..0c7e7deb3 100644 --- a/core/interfaces/i_toolbox.js +++ b/core/interfaces/i_toolbox.js @@ -14,10 +14,15 @@ goog.module('Blockly.IToolbox'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IFlyout = goog.requireType('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ const {ToolboxInfo} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/renderers/common/drawer.js b/core/renderers/common/drawer.js index 9504695a2..2dde92d3f 100644 --- a/core/renderers/common/drawer.js +++ b/core/renderers/common/drawer.js @@ -13,15 +13,22 @@ goog.module('Blockly.blockRendering.Drawer'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.blockRendering.Field'); +/* eslint-disable-next-line no-unused-vars */ const Icon = goog.requireType('Blockly.blockRendering.Icon'); +/* eslint-disable-next-line no-unused-vars */ const InlineInput = goog.requireType('Blockly.blockRendering.InlineInput'); +/* eslint-disable-next-line no-unused-vars */ const RenderInfo = goog.requireType('Blockly.blockRendering.RenderInfo'); +/* eslint-disable-next-line no-unused-vars */ const Row = goog.require('Blockly.blockRendering.Row'); -const svgPaths = goog.require('Blockly.utils.svgPaths'); const Types = goog.require('Blockly.blockRendering.Types'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); /** diff --git a/core/utils/colour.js b/core/utils/colour.js index 7b2c978f4..29ba0187c 100644 --- a/core/utils/colour.js +++ b/core/utils/colour.js @@ -60,6 +60,7 @@ const parse = function(str) { } return null; }; +exports.parse = parse; /** * Converts a colour from RGB to hex representation. @@ -75,6 +76,7 @@ const rgbToHex = function(r, g, b) { } return '#' + rgb.toString(16); }; +exports.rgbToHex = rgbToHex; /** * Converts a colour to RGB. @@ -95,6 +97,7 @@ const hexToRgb = function(colour) { return [r, g, b]; }; +exports.hexToRgb = hexToRgb; /** * Converts an HSV triplet to hex representation. @@ -153,6 +156,7 @@ const hsvToHex = function(h, s, v) { } return rgbToHex(Math.floor(red), Math.floor(green), Math.floor(blue)); }; +exports.hsvToHex = hsvToHex; /** * Blend two colours together, using the specified factor to indicate the @@ -179,6 +183,7 @@ const blend = function(colour1, colour2, factor) { const b = Math.round(rgb2[2] + factor * (rgb1[2] - rgb2[2])); return rgbToHex(r, g, b); }; +exports.blend = blend; /** * A map that contains the 16 basic colour keywords as defined by W3C: @@ -206,12 +211,4 @@ const names = { 'white': '#ffffff', 'yellow': '#ffff00' }; - -exports = { - parse, - rgbToHex, - hexToRgb, - hsvToHex, - blend, - names -}; +exports.names = names; diff --git a/core/utils/deprecation.js b/core/utils/deprecation.js index ad798b1ab..870294172 100644 --- a/core/utils/deprecation.js +++ b/core/utils/deprecation.js @@ -28,7 +28,6 @@ goog.module.declareLegacyNamespace(); * deprecation date. * @param {string=} opt_use The name of a function or property to use instead, * if any. - * @package */ const warn = function(name, deprecationDate, deletionDate, opt_use) { let msg = name + ' was deprecated on ' + deprecationDate + @@ -38,5 +37,5 @@ const warn = function(name, deprecationDate, deletionDate, opt_use) { } console.warn(msg); }; - -exports = {warn}; +/** @package */ +exports.warn = warn; diff --git a/core/utils/idgenerator.js b/core/utils/idgenerator.js index 6ad7bcf55..537dfde2b 100644 --- a/core/utils/idgenerator.js +++ b/core/utils/idgenerator.js @@ -23,7 +23,6 @@ goog.module.declareLegacyNamespace(); /** * Next unique ID to use. * @type {number} - * @private */ let nextId = 0; @@ -36,5 +35,4 @@ let nextId = 0; const getNextUniqueId = function() { return 'blockly-' + (nextId++).toString(36); }; - -exports = {getNextUniqueId}; +exports.getNextUniqueId = getNextUniqueId; diff --git a/core/utils/math.js b/core/utils/math.js index dade91c21..9b717d065 100644 --- a/core/utils/math.js +++ b/core/utils/math.js @@ -29,6 +29,7 @@ goog.module.declareLegacyNamespace(); const toRadians = function(angleDegrees) { return angleDegrees * Math.PI / 180; }; +exports.toRadians = toRadians; /** * Converts radians to degrees. @@ -39,6 +40,7 @@ const toRadians = function(angleDegrees) { const toDegrees = function(angleRadians) { return angleRadians * 180 / Math.PI; }; +exports.toDegrees = toDegrees; /** * Clamp the provided number between the lower bound and the upper bound. @@ -55,9 +57,4 @@ const clamp = function(lowerBound, number, upperBound) { } return Math.max(lowerBound, Math.min(number, upperBound)); }; - -exports = { - toRadians, - toDegrees, - clamp -}; +exports.clamp = clamp; diff --git a/core/utils/object.js b/core/utils/object.js index dae55ec51..3507d33ab 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -40,6 +40,7 @@ const inherits = function(childCtor, parentCtor) { // Alternatively, one could use this instead: // Object.setPrototypeOf(childCtor.prototype, parentCtor.prototype); }; +exports.inherits = inherits; /** * Copies all the members of a source object to a target object. @@ -51,6 +52,7 @@ const mixin = function(target, source) { target[x] = source[x]; } }; +exports.mixin = mixin; /** * Complete a deep merge of all members of a source object with a target object. @@ -68,6 +70,7 @@ const deepMerge = function(target, source) { } return target; }; +exports.deepMerge = deepMerge; /** * Returns an array of a given object's own enumerable property values. @@ -83,10 +86,4 @@ const values = function(obj) { return obj[e]; }); }; - -exports = { - inherits, - mixin, - deepMerge, - values, -}; +exports.values = values; diff --git a/core/utils/style.js b/core/utils/style.js index 1fcfbdd62..0fbd22093 100644 --- a/core/utils/style.js +++ b/core/utils/style.js @@ -29,7 +29,7 @@ const Size = goog.require('Blockly.utils.Size'); * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -function getSize(element) { +const getSize = function(element) { if (getStyle(element, 'display') != 'none') { return getSizeWithDisplay(element); } @@ -52,7 +52,7 @@ function getSize(element) { style.visibility = originalVisibility; return new Size(offsetWidth, offsetHeight); -} +}; exports.getSize = getSize; /** @@ -60,11 +60,11 @@ exports.getSize = getSize; * @param {!Element} element Element to get size of. * @return {!Size} Object with width/height properties. */ -function getSizeWithDisplay(element) { +const getSizeWithDisplay = function(element) { const offsetWidth = /** @type {!HTMLElement} */ (element).offsetWidth; const offsetHeight = /** @type {!HTMLElement} */ (element).offsetHeight; return new Size(offsetWidth, offsetHeight); -} +}; /** * Cross-browser pseudo get computed style. It returns the computed style where @@ -79,10 +79,10 @@ function getSizeWithDisplay(element) { * @param {string} style Property to get (must be camelCase, not CSS-style). * @return {string} Style value. */ -function getStyle(element, style) { +const getStyle = function(element, style) { return getComputedStyle(element, style) || getCascadedStyle(element, style) || (element.style && element.style[style]); -} +}; /** * Retrieves a computed style value of a node. It returns empty string if the @@ -96,7 +96,7 @@ function getStyle(element, style) { * @param {string} property Property to get (camel-case). * @return {string} Style value. */ -function getComputedStyle(element, property) { +const getComputedStyle = function(element, property) { if (document.defaultView && document.defaultView.getComputedStyle) { const styles = document.defaultView.getComputedStyle(element, null); if (styles) { @@ -107,7 +107,7 @@ function getComputedStyle(element, property) { } return ''; -} +}; exports.getComputedStyle = getComputedStyle; /** @@ -120,10 +120,10 @@ exports.getComputedStyle = getComputedStyle; * @param {string} style Property to get (camel-case). * @return {string} Style value. */ -function getCascadedStyle(element, style) { +const getCascadedStyle = function(element, style) { return /** @type {string} */ ( element.currentStyle ? element.currentStyle[style] : null); -} +}; exports.getCascadedStyle = getCascadedStyle; /** @@ -132,7 +132,7 @@ exports.getCascadedStyle = getCascadedStyle; * @param {!Element} el Element to get the page offset for. * @return {!Coordinate} The page offset. */ -function getPageOffset(el) { +const getPageOffset = function(el) { const pos = new Coordinate(0, 0); const box = el.getBoundingClientRect(); const documentElement = document.documentElement; @@ -146,7 +146,7 @@ function getPageOffset(el) { pos.y = box.top + scrollCoord.y; return pos; -} +}; exports.getPageOffset = getPageOffset; /** @@ -154,13 +154,13 @@ exports.getPageOffset = getPageOffset; * Similar to Closure's goog.style.getViewportPageOffset * @return {!Coordinate} The page offset of the viewport. */ -function getViewportPageOffset() { +const getViewportPageOffset = function() { const body = document.body; const documentElement = document.documentElement; const scrollLeft = body.scrollLeft || documentElement.scrollLeft; const scrollTop = body.scrollTop || documentElement.scrollTop; return new Coordinate(scrollLeft, scrollTop); -} +}; exports.getViewportPageOffset = getViewportPageOffset; /** @@ -175,9 +175,9 @@ exports.getViewportPageOffset = getViewportPageOffset; * @param {*} isShown True to render the element in its default style, * false to disable rendering the element. */ -function setElementShown(el, isShown) { +const setElementShown = function(el, isShown) { el.style.display = isShown ? '' : 'none'; -} +}; exports.setElementShown = setElementShown; /** @@ -187,9 +187,9 @@ exports.setElementShown = setElementShown; * @param {!Element} el The element to test. * @return {boolean} True for right to left, false for left to right. */ -function isRightToLeft(el) { +const isRightToLeft = function(el) { return 'rtl' == getStyle(el, 'direction'); -} +}; exports.isRightToLeft = isRightToLeft; /** @@ -198,7 +198,7 @@ exports.isRightToLeft = isRightToLeft; * @param {!Element} element The element to get the border widths for. * @return {!Object} The computed border widths. */ -function getBorderBox(element) { +const getBorderBox = function(element) { const left = getComputedStyle(element, 'borderLeftWidth'); const right = getComputedStyle(element, 'borderRightWidth'); const top = getComputedStyle(element, 'borderTopWidth'); @@ -210,7 +210,7 @@ function getBorderBox(element) { bottom: parseFloat(bottom), left: parseFloat(left) }; -} +}; exports.getBorderBox = getBorderBox; /** @@ -226,11 +226,11 @@ exports.getBorderBox = getBorderBox; * @param {boolean=} opt_center Whether to center the element in the container. * Defaults to false. */ -function scrollIntoContainerView(element, container, opt_center) { +const scrollIntoContainerView = function(element, container, opt_center) { const offset = getContainerOffsetToScrollInto(element, container, opt_center); container.scrollLeft = offset.x; container.scrollTop = offset.y; -} +}; exports.scrollIntoContainerView = scrollIntoContainerView; /** @@ -248,7 +248,7 @@ exports.scrollIntoContainerView = scrollIntoContainerView; * @return {!Coordinate} The new scroll position of the container, * in form of goog.math.Coordinate(scrollLeft, scrollTop). */ -function getContainerOffsetToScrollInto(element, container, opt_center) { +const getContainerOffsetToScrollInto = function(element, container, opt_center) { // Absolute position of the element's border's top left corner. const elementPos = getPageOffset(element); // Absolute position of the container's border's top left corner. @@ -281,5 +281,5 @@ function getContainerOffsetToScrollInto(element, container, opt_center) { scrollTop += Math.min(relY, Math.max(relY - spaceY, 0)); } return new Coordinate(scrollLeft, scrollTop); -} +}; exports.getContainerOffsetToScrollInto = getContainerOffsetToScrollInto; diff --git a/core/utils/svg_paths.js b/core/utils/svg_paths.js index 02602e4ac..7286e8bc6 100644 --- a/core/utils/svg_paths.js +++ b/core/utils/svg_paths.js @@ -27,11 +27,11 @@ goog.module.declareLegacyNamespace(); * @param {number} x The x coordinate. * @param {number} y The y coordinate. * @return {string} A string of the format ' x,y ' - * @public */ const point = function(x, y) { return ' ' + x + ',' + y + ' '; }; +exports.point = point; /** * Draw a cubic or quadratic curve. See @@ -44,11 +44,11 @@ const point = function(x, y) { * the format ' x, y '. * @return {string} A string defining one or more Bezier curves. See the MDN * documentation for exact format. - * @public */ const curve = function(command, points) { return ' ' + command + points.join(''); }; +exports.curve = curve; /** * Move the cursor to the given position without drawing a line. @@ -58,11 +58,11 @@ const curve = function(command, points) { * @param {number} x The absolute x coordinate. * @param {number} y The absolute y coordinate. * @return {string} A string of the format ' M x,y ' - * @public */ const moveTo = function(x, y) { return ' M ' + x + ',' + y + ' '; }; +exports.moveTo = moveTo; /** * Move the cursor to the given position without drawing a line. @@ -72,11 +72,11 @@ const moveTo = function(x, y) { * @param {number} dx The relative x coordinate. * @param {number} dy The relative y coordinate. * @return {string} A string of the format ' m dx,dy ' - * @public */ const moveBy = function(dx, dy) { return ' m ' + dx + ',' + dy + ' '; }; +exports.moveBy = moveBy; /** * Draw a line from the current point to the end point, which is the current @@ -86,11 +86,11 @@ const moveBy = function(dx, dy) { * @param {number} dx The relative x coordinate. * @param {number} dy The relative y coordinate. * @return {string} A string of the format ' l dx,dy ' - * @public */ const lineTo = function(dx, dy) { return ' l ' + dx + ',' + dy + ' '; }; +exports.lineTo = lineTo; /** * Draw multiple lines connecting all of the given points in order. This is @@ -101,11 +101,11 @@ const lineTo = function(dx, dy) { * draw lines to, in order. The points are represented as strings of the * format ' dx,dy '. * @return {string} A string of the format ' l (dx,dy)+ ' - * @public */ const line = function(points) { return ' l' + points.join(''); }; +exports.line = line; /** * Draw a horizontal or vertical line. @@ -118,11 +118,11 @@ const line = function(points) { * @param {number} val The coordinate to pass to the command. It may be * absolute or relative. * @return {string} A string of the format ' command val ' - * @public */ const lineOnAxis = function(command, val) { return ' ' + command + ' ' + val + ' '; }; +exports.lineOnAxis = lineOnAxis; /** * Draw an elliptical arc curve. @@ -136,19 +136,8 @@ const lineOnAxis = function(command, val) { * specified either in absolute or relative coordinates depending on the * command. * @return {string} A string of the format 'command radius radius flags point' - * @public */ const arc = function(command, flags, radius, point) { return command + ' ' + radius + ' ' + radius + ' ' + flags + point; }; - -exports = { - point, - curve, - moveTo, - moveBy, - lineTo, - line, - lineOnAxis, - arc, -}; +exports.arc = arc; diff --git a/core/utils/toolbox.js b/core/utils/toolbox.js index aab51d826..6dabc1fd5 100644 --- a/core/utils/toolbox.js +++ b/core/utils/toolbox.js @@ -18,11 +18,11 @@ goog.module('Blockly.utils.toolbox'); goog.module.declareLegacyNamespace(); const userAgent = goog.require('Blockly.utils.userAgent'); -const {textToDom} = goog.require('Blockly.Xml'); - +/* eslint-disable-next-line no-unused-vars */ const {CssConfig: CategoryCssConfig} = goog.requireType('Blockly.ToolboxCategory'); +/* eslint-disable-next-line no-unused-vars */ const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparator'); - +const {textToDom} = goog.require('Blockly.Xml'); /** * The information needed to create a block in the toolbox. @@ -35,6 +35,7 @@ const {CssConfig: SeparatorCssConfig} = goog.requireType('Blockly.ToolboxSeparat * }} */ let BlockInfo; +exports.BlockInfo = BlockInfo; /** * The information needed to create a separator in the toolbox. @@ -46,6 +47,7 @@ let BlockInfo; * }} */ let SeparatorInfo; +exports.SeparatorInfo = SeparatorInfo; /** * The information needed to create a button in the toolbox. @@ -56,6 +58,7 @@ let SeparatorInfo; * }} */ let ButtonInfo; +exports.ButtonInfo = ButtonInfo; /** * The information needed to create a label in the toolbox. @@ -66,6 +69,7 @@ let ButtonInfo; * }} */ let LabelInfo; +exports.LabelInfo = LabelInfo; /** * The information needed to create either a button or a label in the flyout. @@ -73,6 +77,7 @@ let LabelInfo; * LabelInfo} */ let ButtonOrLabelInfo; +exports.ButtonOrLabelInfo = ButtonOrLabelInfo; /** * The information needed to create a category in the toolbox. @@ -88,6 +93,7 @@ let ButtonOrLabelInfo; * }} */ let StaticCategoryInfo; +exports.StaticCategoryInfo = StaticCategoryInfo; /** * The information needed to create a custom category. @@ -102,6 +108,7 @@ let StaticCategoryInfo; * }} */ let DynamicCategoryInfo; +exports.DynamicCategoryInfo = DynamicCategoryInfo; /** * The information needed to create either a dynamic or static category. @@ -109,6 +116,7 @@ let DynamicCategoryInfo; * DynamicCategoryInfo} */ let CategoryInfo; +exports.CategoryInfo = CategoryInfo; /** * Any information that can be used to create an item in the toolbox. @@ -116,6 +124,7 @@ let CategoryInfo; * StaticCategoryInfo} */ let ToolboxItemInfo; +exports.ToolboxItemInfo = ToolboxItemInfo; /** * All the different types that can be displayed in a flyout. @@ -126,6 +135,7 @@ let ToolboxItemInfo; * DynamicCategoryInfo} */ let FlyoutItemInfo; +exports.FlyoutItemInfo = FlyoutItemInfo; /** * The JSON definition of a toolbox. @@ -135,6 +145,7 @@ let FlyoutItemInfo; * }} */ let ToolboxInfo; +exports.ToolboxInfo = ToolboxInfo; /** * An array holding flyout items. @@ -143,6 +154,7 @@ let ToolboxInfo; * } */ let FlyoutItemInfoArray; +exports.FlyoutItemInfoArray = FlyoutItemInfoArray; /** * All of the different types that can create a toolbox. @@ -151,6 +163,7 @@ let FlyoutItemInfoArray; * string} */ let ToolboxDefinition; +exports.ToolboxDefinition = ToolboxDefinition; /** * All of the different types that can be used to show items in a flyout. @@ -160,6 +173,7 @@ let ToolboxDefinition; * Array} */ let FlyoutDefinition; +exports.FlyoutDefinition = FlyoutDefinition; /** * The name used to identify a toolbox that has category like items. @@ -187,6 +201,7 @@ const Position = { LEFT: 2, RIGHT: 3 }; +exports.Position = Position; /** * Converts the toolbox definition into toolbox JSON. @@ -194,7 +209,6 @@ const Position = { * of the toolbox in one of its many forms. * @return {?ToolboxInfo} Object holding information * for creating a toolbox. - * @package */ const convertToolboxDefToJson = function(toolboxDef) { if (!toolboxDef) { @@ -210,13 +224,14 @@ const convertToolboxDefToJson = function(toolboxDef) { validateToolbox(toolboxJson); return toolboxJson; }; +/** @package */ +exports.convertToolboxDefToJson = convertToolboxDefToJson; /** * Validates the toolbox JSON fields have been set correctly. * @param {!ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @throws {Error} if the toolbox is not the correct format. - * @private */ const validateToolbox = function(toolboxJson) { const toolboxKind = toolboxJson['kind']; @@ -241,7 +256,6 @@ const validateToolbox = function(toolboxJson) { * @param {?FlyoutDefinition} flyoutDef The definition of * the flyout in one of its many forms. * @return {!FlyoutItemInfoArray} A list of flyout items. - * @package */ const convertFlyoutDefToJsonArray = function(flyoutDef) { if (!flyoutDef) { @@ -260,13 +274,14 @@ const convertFlyoutDefToJsonArray = function(flyoutDef) { return xmlToJsonArray(/** @type {!Array|!NodeList} */ (flyoutDef)); }; +/** @package */ +exports.convertFlyoutDefToJsonArray = convertFlyoutDefToJsonArray; /** * Whether or not the toolbox definition has categories. * @param {?ToolboxInfo} toolboxJson Object holding * information for creating a toolbox. * @return {boolean} True if the toolbox has categories. - * @package */ const hasCategories = function(toolboxJson) { if (!toolboxJson) { @@ -283,13 +298,14 @@ const hasCategories = function(toolboxJson) { }); return !!categories.length; }; +/** @package */ +exports.hasCategories = hasCategories; /** * Whether or not the category is collapsible. * @param {!CategoryInfo} categoryInfo Object holing * information for creating a category. * @return {boolean} True if the category has subcategories. - * @package */ const isCategoryCollapsible = function(categoryInfo) { if (!categoryInfo || !categoryInfo['contents']) { @@ -301,6 +317,8 @@ const isCategoryCollapsible = function(categoryInfo) { }); return !!categories.length; }; +/** @package */ +exports.isCategoryCollapsible = isCategoryCollapsible; /** * Parses the provided toolbox definition into a consistent format. @@ -308,7 +326,6 @@ const isCategoryCollapsible = function(categoryInfo) { * forms. * @return {!ToolboxInfo} Object holding information * for creating a toolbox. - * @private */ const convertToToolboxJson = function(toolboxDef) { const contents = xmlToJsonArray( @@ -327,7 +344,6 @@ const convertToToolboxJson = function(toolboxDef) { * @return {!FlyoutItemInfoArray| * !Array} A list of objects in * the toolbox. - * @private */ const xmlToJsonArray = function(toolboxDef) { const arr = []; @@ -364,7 +380,6 @@ const xmlToJsonArray = function(toolboxDef) { * Adds the attributes on the node to the given object. * @param {!Node} node The node to copy the attributes from. * @param {!Object} obj The object to copy the attributes to. - * @private */ const addAttributes = function(node, obj) { for (let j = 0; j < node.attributes.length; j++) { @@ -408,26 +423,4 @@ const parseToolboxTree = function(toolboxDef) { } return toolboxDef; }; - -exports = { - BlockInfo, - SeparatorInfo, - ButtonInfo, - LabelInfo, - ButtonOrLabelInfo, - StaticCategoryInfo, - DynamicCategoryInfo, - CategoryInfo, - ToolboxItemInfo, - FlyoutItemInfo, - ToolboxInfo, - FlyoutItemInfoArray, - ToolboxDefinition, - FlyoutDefinition, - Position, - convertToolboxDefToJson, - convertFlyoutDefToJsonArray, - hasCategories, - isCategoryCollapsible, - parseToolboxTree -}; +exports.parseToolboxTree = parseToolboxTree; From 94bdd1850582ef4332c76f3f9c486fba9c48367b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:23:17 -0700 Subject: [PATCH 183/833] Migrate core/field_number.js to ES6 const/let --- core/field_number.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 369a161f8..d45c790cd 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -225,14 +225,14 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { */ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; - var precisionString = String(this.precision_); + let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { // String() is fast. But it turns .0000001 into '1e-7'. // Use the much slower toLocaleString to access all the digits. precisionString = this.precision_.toLocaleString('en-US', {maximumFractionDigits: 20}); } - var decimalIndex = precisionString.indexOf('.'); + const decimalIndex = precisionString.indexOf('.'); if (decimalIndex == -1) { // If the precision is 0 (float) allow any number of decimals, // otherwise allow none. @@ -265,7 +265,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { return null; } // Clean up text. - var newValue = String(opt_newValue); + let newValue = String(opt_newValue); // TODO: Handle cases like 'ten', '1.203,14', etc. // 'O' is sometimes mistaken for '0' by inexperienced users. newValue = newValue.replace(/O/ig, '0'); @@ -275,7 +275,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { newValue = newValue.replace(/infinity/i, 'Infinity'); // Clean up number. - var n = Number(newValue || 0); + let n = Number(newValue || 0); if (isNaN(n)) { // Invalid number. return null; @@ -300,7 +300,7 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @override */ Blockly.FieldNumber.prototype.widgetCreate_ = function() { - var htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); + const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..5485014dd 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); From 0a1311c9b5002d8edd568eb24f8e203743b699f2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:26:41 -0700 Subject: [PATCH 184/833] Migrate core/field_number.js to goog.module --- core/field_number.js | 51 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index d45c790cd..67900f344 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldNumber'); +goog.module('Blockly.FieldNumber'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.fieldRegistry'); goog.require('Blockly.FieldTextInput'); @@ -34,7 +35,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, +const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config) { /** @@ -66,31 +67,31 @@ Blockly.FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, */ this.decimalPlaces_ = null; - Blockly.FieldNumber.superClass_.constructor.call( + FieldNumber.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); if (!opt_config) { // Only do one kind of configuration or the other. this.setConstraints(opt_min, opt_max, opt_precision); } }; -Blockly.utils.object.inherits(Blockly.FieldNumber, Blockly.FieldTextInput); +Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldNumber.prototype.DEFAULT_VALUE = 0; +FieldNumber.prototype.DEFAULT_VALUE = 0; /** * Construct a FieldNumber from a JSON arg object. * @param {!Object} options A JSON object with options (value, min, max, and * precision). - * @return {!Blockly.FieldNumber} The new field instance. + * @return {!FieldNumber} The new field instance. * @package * @nocollapse */ -Blockly.FieldNumber.fromJson = function(options) { +FieldNumber.fromJson = function(options) { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. return new this(options['value'], @@ -102,7 +103,7 @@ Blockly.FieldNumber.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldNumber.prototype.SERIALIZABLE = true; +FieldNumber.prototype.SERIALIZABLE = true; /** * Configure the field based on the given map of options. @@ -110,8 +111,8 @@ Blockly.FieldNumber.prototype.SERIALIZABLE = true; * @protected * @override */ -Blockly.FieldNumber.prototype.configure_ = function(config) { - Blockly.FieldNumber.superClass_.configure_.call(this, config); +FieldNumber.prototype.configure_ = function(config) { + FieldNumber.superClass_.configure_.call(this, config); this.setMinInternal_(config['min']); this.setMaxInternal_(config['max']); this.setPrecisionInternal_(config['precision']); @@ -128,7 +129,7 @@ Blockly.FieldNumber.prototype.configure_ = function(config) { * @param {?(number|string|undefined)} max Maximum value. * @param {?(number|string|undefined)} precision Precision for value. */ -Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) { +FieldNumber.prototype.setConstraints = function(min, max, precision) { this.setMinInternal_(min); this.setMaxInternal_(max); this.setPrecisionInternal_(precision); @@ -139,7 +140,7 @@ Blockly.FieldNumber.prototype.setConstraints = function(min, max, precision) { * Sets the minimum value this field can contain. Updates the value to reflect. * @param {?(number|string|undefined)} min Minimum value. */ -Blockly.FieldNumber.prototype.setMin = function(min) { +FieldNumber.prototype.setMin = function(min) { this.setMinInternal_(min); this.setValue(this.getValue()); }; @@ -150,7 +151,7 @@ Blockly.FieldNumber.prototype.setMin = function(min) { * @param {?(number|string|undefined)} min Minimum value. * @private */ -Blockly.FieldNumber.prototype.setMinInternal_ = function(min) { +FieldNumber.prototype.setMinInternal_ = function(min) { if (min == null) { this.min_ = -Infinity; } else { @@ -166,7 +167,7 @@ Blockly.FieldNumber.prototype.setMinInternal_ = function(min) { * -Infinity. * @return {number} The current minimum value this field can contain. */ -Blockly.FieldNumber.prototype.getMin = function() { +FieldNumber.prototype.getMin = function() { return this.min_; }; @@ -174,7 +175,7 @@ Blockly.FieldNumber.prototype.getMin = function() { * Sets the maximum value this field can contain. Updates the value to reflect. * @param {?(number|string|undefined)} max Maximum value. */ -Blockly.FieldNumber.prototype.setMax = function(max) { +FieldNumber.prototype.setMax = function(max) { this.setMaxInternal_(max); this.setValue(this.getValue()); }; @@ -185,7 +186,7 @@ Blockly.FieldNumber.prototype.setMax = function(max) { * @param {?(number|string|undefined)} max Maximum value. * @private */ -Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) { +FieldNumber.prototype.setMaxInternal_ = function(max) { if (max == null) { this.max_ = Infinity; } else { @@ -201,7 +202,7 @@ Blockly.FieldNumber.prototype.setMaxInternal_ = function(max) { * Infinity. * @return {number} The current maximum value this field can contain. */ -Blockly.FieldNumber.prototype.getMax = function() { +FieldNumber.prototype.getMax = function() { return this.max_; }; @@ -211,7 +212,7 @@ Blockly.FieldNumber.prototype.getMax = function() { * @param {?(number|string|undefined)} precision The number to which the * field's value is rounded. */ -Blockly.FieldNumber.prototype.setPrecision = function(precision) { +FieldNumber.prototype.setPrecision = function(precision) { this.setPrecisionInternal_(precision); this.setValue(this.getValue()); }; @@ -223,7 +224,7 @@ Blockly.FieldNumber.prototype.setPrecision = function(precision) { * field's value is rounded. * @private */ -Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { +FieldNumber.prototype.setPrecisionInternal_ = function(precision) { this.precision_ = Number(precision) || 0; let precisionString = String(this.precision_); if (precisionString.indexOf('e') != -1) { @@ -248,7 +249,7 @@ Blockly.FieldNumber.prototype.setPrecisionInternal_ = function(precision) { * the value is not rounded. * @return {number} The number to which this field's value is rounded. */ -Blockly.FieldNumber.prototype.getPrecision = function() { +FieldNumber.prototype.getPrecision = function() { return this.precision_; }; @@ -260,7 +261,7 @@ Blockly.FieldNumber.prototype.getPrecision = function() { * @protected * @override */ -Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { +FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } @@ -299,8 +300,8 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) { * @protected * @override */ -Blockly.FieldNumber.prototype.widgetCreate_ = function() { - const htmlInput = Blockly.FieldNumber.superClass_.widgetCreate_.call(this); +FieldNumber.prototype.widgetCreate_ = function() { + const htmlInput = FieldNumber.superClass_.widgetCreate_.call(this); // Set the accessibility state if (this.min_ > -Infinity) { @@ -314,4 +315,6 @@ Blockly.FieldNumber.prototype.widgetCreate_ = function() { return htmlInput; }; -Blockly.fieldRegistry.register('field_number', Blockly.FieldNumber); +Blockly.fieldRegistry.register('field_number', FieldNumber); + +exports = FieldNumber; diff --git a/tests/deps.js b/tests/deps.js index 5485014dd..80ddf87c8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -57,7 +57,7 @@ goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockl goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6'}); +goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); From 25fc34925f194c3c703cb9b4c7945e34950f1b34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:31:39 -0700 Subject: [PATCH 185/833] Migrate core/field_number.js to named requires --- core/field_number.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index 67900f344..e8d628572 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -13,10 +13,10 @@ goog.module('Blockly.FieldNumber'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.object'); +const FieldTextInput = goog.require('Blockly.FieldTextInput'); +const aria = goog.require('Blockly.utils.aria'); +const {inherits} = goog.require('Blockly.utils.object'); +const {register} = goog.require('Blockly.fieldRegistry'); /** @@ -32,7 +32,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldTextInput} + * @extends {FieldTextInput} * @constructor */ const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, @@ -74,7 +74,7 @@ const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, this.setConstraints(opt_min, opt_max, opt_precision); } }; -Blockly.utils.object.inherits(FieldNumber, Blockly.FieldTextInput); +inherits(FieldNumber, FieldTextInput); /** * The default value for this field. @@ -305,16 +305,16 @@ FieldNumber.prototype.widgetCreate_ = function() { // Set the accessibility state if (this.min_ > -Infinity) { - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.VALUEMIN, this.min_); + aria.setState(htmlInput, + aria.State.VALUEMIN, this.min_); } if (this.max_ < Infinity) { - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.VALUEMAX, this.max_); + aria.setState(htmlInput, + aria.State.VALUEMAX, this.max_); } return htmlInput; }; -Blockly.fieldRegistry.register('field_number', FieldNumber); +register('field_number', FieldNumber); exports = FieldNumber; From e15470bbd0f7ca74e0452dba8606fe2344e1539b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:32:09 -0700 Subject: [PATCH 186/833] clang-format core/field_number.js --- core/field_number.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/field_number.js b/core/field_number.js index e8d628572..8389f477f 100644 --- a/core/field_number.js +++ b/core/field_number.js @@ -30,14 +30,14 @@ const {register} = goog.require('Blockly.fieldRegistry'); * changes to the field's value. Takes in a number & returns a validated * number, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/number#creation} * for a list of properties this parameter supports. * @extends {FieldTextInput} * @constructor */ -const FieldNumber = function(opt_value, opt_min, opt_max, opt_precision, - opt_validator, opt_config) { - +const FieldNumber = function( + opt_value, opt_min, opt_max, opt_precision, opt_validator, opt_config) { /** * The minimum value this number field can contain. * @type {number} @@ -94,8 +94,8 @@ FieldNumber.prototype.DEFAULT_VALUE = 0; FieldNumber.fromJson = function(options) { // `this` might be a subclass of FieldNumber if that class doesn't override // the static fromJson method. - return new this(options['value'], - undefined, undefined, undefined, undefined, options); + return new this( + options['value'], undefined, undefined, undefined, undefined, options); }; /** @@ -305,12 +305,10 @@ FieldNumber.prototype.widgetCreate_ = function() { // Set the accessibility state if (this.min_ > -Infinity) { - aria.setState(htmlInput, - aria.State.VALUEMIN, this.min_); + aria.setState(htmlInput, aria.State.VALUEMIN, this.min_); } if (this.max_ < Infinity) { - aria.setState(htmlInput, - aria.State.VALUEMAX, this.max_); + aria.setState(htmlInput, aria.State.VALUEMAX, this.max_); } return htmlInput; }; From 7a050d021db8d56f2c64a139678c7659ff739e23 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:43:46 -0700 Subject: [PATCH 187/833] Migrate core/field_checkbox.js to goog.module --- core/field_checkbox.js | 55 ++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 207b29f7f..df3509239 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldCheckbox'); +goog.module('Blockly.FieldCheckbox'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -34,7 +35,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) { +const FieldCheckbox = function(opt_value, opt_validator, opt_config) { /** * Character for the check mark. Used to apply a different check mark * character to individual fields. @@ -43,26 +44,26 @@ Blockly.FieldCheckbox = function(opt_value, opt_validator, opt_config) { */ this.checkChar_ = null; - Blockly.FieldCheckbox.superClass_.constructor.call( + FieldCheckbox.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); }; -Blockly.utils.object.inherits(Blockly.FieldCheckbox, Blockly.Field); +Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldCheckbox.prototype.DEFAULT_VALUE = false; +FieldCheckbox.prototype.DEFAULT_VALUE = false; /** * Construct a FieldCheckbox from a JSON arg object. * @param {!Object} options A JSON object with options (checked). - * @return {!Blockly.FieldCheckbox} The new field instance. + * @return {!FieldCheckbox} The new field instance. * @package * @nocollapse */ -Blockly.FieldCheckbox.fromJson = function(options) { +FieldCheckbox.fromJson = function(options) { // `this` might be a subclass of FieldCheckbox if that class doesn't override // the static fromJson method. return new this(options['checked'], undefined, options); @@ -73,19 +74,19 @@ Blockly.FieldCheckbox.fromJson = function(options) { * @type {string} * @const */ -Blockly.FieldCheckbox.CHECK_CHAR = '\u2713'; +FieldCheckbox.CHECK_CHAR = '\u2713'; /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldCheckbox.prototype.SERIALIZABLE = true; +FieldCheckbox.prototype.SERIALIZABLE = true; /** * Mouse cursor style when over the hotspot that initiates editability. */ -Blockly.FieldCheckbox.prototype.CURSOR = 'default'; +FieldCheckbox.prototype.CURSOR = 'default'; /** * Configure the field based on the given map of options. @@ -93,8 +94,8 @@ Blockly.FieldCheckbox.prototype.CURSOR = 'default'; * @protected * @override */ -Blockly.FieldCheckbox.prototype.configure_ = function(config) { - Blockly.FieldCheckbox.superClass_.configure_.call(this, config); +FieldCheckbox.prototype.configure_ = function(config) { + FieldCheckbox.superClass_.configure_.call(this, config); if (config['checkCharacter']) { this.checkChar_ = config['checkCharacter']; } @@ -104,8 +105,8 @@ Blockly.FieldCheckbox.prototype.configure_ = function(config) { * Create the block UI for this checkbox. * @package */ -Blockly.FieldCheckbox.prototype.initView = function() { - Blockly.FieldCheckbox.superClass_.initView.call(this); +FieldCheckbox.prototype.initView = function() { + FieldCheckbox.superClass_.initView.call(this); Blockly.utils.dom.addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); @@ -115,7 +116,7 @@ Blockly.FieldCheckbox.prototype.initView = function() { /** * @override */ -Blockly.FieldCheckbox.prototype.render_ = function() { +FieldCheckbox.prototype.render_ = function() { if (this.textContent_) { this.textContent_.nodeValue = this.getDisplayText_(); } @@ -125,8 +126,8 @@ Blockly.FieldCheckbox.prototype.render_ = function() { /** * @override */ -Blockly.FieldCheckbox.prototype.getDisplayText_ = function() { - return this.checkChar_ || Blockly.FieldCheckbox.CHECK_CHAR; +FieldCheckbox.prototype.getDisplayText_ = function() { + return this.checkChar_ || FieldCheckbox.CHECK_CHAR; }; /** @@ -134,7 +135,7 @@ Blockly.FieldCheckbox.prototype.getDisplayText_ = function() { * @param {?string} character The character to use for the check mark, or * null to use the default. */ -Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) { +FieldCheckbox.prototype.setCheckCharacter = function(character) { this.checkChar_ = character; this.forceRerender(); }; @@ -143,7 +144,7 @@ Blockly.FieldCheckbox.prototype.setCheckCharacter = function(character) { * Toggle the state of the checkbox on click. * @protected */ -Blockly.FieldCheckbox.prototype.showEditor_ = function() { +FieldCheckbox.prototype.showEditor_ = function() { this.setValue(!this.value_); }; @@ -153,7 +154,7 @@ Blockly.FieldCheckbox.prototype.showEditor_ = function() { * @return {?string} A valid value ('TRUE' or 'FALSE), or null if invalid. * @protected */ -Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { +FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === true || opt_newValue === 'TRUE') { return 'TRUE'; } @@ -169,7 +170,7 @@ Blockly.FieldCheckbox.prototype.doClassValidation_ = function(opt_newValue) { * that this is a either 'TRUE' or 'FALSE'. * @protected */ -Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { +FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { this.value_ = this.convertValueToBool_(newValue); // Update visual. if (this.textElement_) { @@ -181,7 +182,7 @@ Blockly.FieldCheckbox.prototype.doValueUpdate_ = function(newValue) { * Get the value of this field, either 'TRUE' or 'FALSE'. * @return {string} The value of this field. */ -Blockly.FieldCheckbox.prototype.getValue = function() { +FieldCheckbox.prototype.getValue = function() { return this.value_ ? 'TRUE' : 'FALSE'; }; @@ -189,7 +190,7 @@ Blockly.FieldCheckbox.prototype.getValue = function() { * Get the boolean value of this field. * @return {boolean} The boolean value of this field. */ -Blockly.FieldCheckbox.prototype.getValueBoolean = function() { +FieldCheckbox.prototype.getValueBoolean = function() { return /** @type {boolean} */ (this.value_); }; @@ -198,7 +199,7 @@ Blockly.FieldCheckbox.prototype.getValueBoolean = function() { * @return {string} Text representing the value of this field * ('true' or 'false'). */ -Blockly.FieldCheckbox.prototype.getText = function() { +FieldCheckbox.prototype.getText = function() { return String(this.convertValueToBool_(this.value_)); }; @@ -211,7 +212,7 @@ Blockly.FieldCheckbox.prototype.getText = function() { * @return {boolean} The converted value. * @private */ -Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { +FieldCheckbox.prototype.convertValueToBool_ = function(value) { if (typeof value == 'string') { return value == 'TRUE'; } else { @@ -219,4 +220,6 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -Blockly.fieldRegistry.register('field_checkbox', Blockly.FieldCheckbox); +Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox); + +exports = FieldCheckbox; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..d6e6163f8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -50,7 +50,7 @@ goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.Co goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); From 29135ec920d974b1eb170b44f59b19a6194de19d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:47:44 -0700 Subject: [PATCH 188/833] Migrate core/field_checkbox.js to named requires --- core/field_checkbox.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index df3509239..9100aa8d3 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -13,12 +13,12 @@ goog.module('Blockly.FieldCheckbox'); goog.module.declareLegacyNamespace(); +const Field = goog.require('Blockly.Field'); +const {addClass} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {register} = goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); /** @@ -32,7 +32,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldCheckbox = function(opt_value, opt_validator, opt_config) { @@ -47,7 +47,7 @@ const FieldCheckbox = function(opt_value, opt_validator, opt_config) { FieldCheckbox.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); }; -Blockly.utils.object.inherits(FieldCheckbox, Blockly.Field); +inherits(FieldCheckbox, Field); /** * The default value for this field. @@ -108,7 +108,7 @@ FieldCheckbox.prototype.configure_ = function(config) { FieldCheckbox.prototype.initView = function() { FieldCheckbox.superClass_.initView.call(this); - Blockly.utils.dom.addClass( + addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); this.textElement_.style.display = this.value_ ? 'block' : 'none'; }; @@ -220,6 +220,6 @@ FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -Blockly.fieldRegistry.register('field_checkbox', FieldCheckbox); +register('field_checkbox', FieldCheckbox); exports = FieldCheckbox; From 5bc41ac960588334e0af831754f58a92ae264ab4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 08:48:43 -0700 Subject: [PATCH 189/833] clang-format core/field_checkbox.js --- core/field_checkbox.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 9100aa8d3..3cbe8d07f 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -30,7 +30,8 @@ goog.require('Blockly.Events.BlockChange'); * returns a validated value ('TRUE' or 'FALSE'), or null to abort the * change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/checkbox#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor From 9d6cbe96d3df420984b23f2fb02ea57722691962 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:45:30 -0700 Subject: [PATCH 190/833] Migrate core/keyboard_nav/tab_navigate_cursor.js to ES6 const/let --- core/keyboard_nav/tab_navigate_cursor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 7d43a79f8..b339520c0 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -37,10 +37,10 @@ Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); * @override */ Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { - var isValid = false; - var type = node && node.getType(); + let isValid = false; + const type = node && node.getType(); if (node) { - var location = /** @type {Blockly.Field} */ (node.getLocation()); + const location = /** @type {Blockly.Field} */ (node.getLocation()); if (type == Blockly.ASTNode.types.FIELD && location && location.isTabNavigable() && location.isClickable()) { isValid = true; From f282c573239970143e4d92eb6933cff82086e914 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:45:55 -0700 Subject: [PATCH 191/833] Migrate core/keyboard_nav/tab_navigate_cursor.js to goog.module --- core/keyboard_nav/tab_navigate_cursor.js | 13 ++++++++----- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index b339520c0..ad2bb45ba 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.TabNavigateCursor'); +goog.module('Blockly.TabNavigateCursor'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); goog.require('Blockly.BasicCursor'); @@ -25,10 +26,10 @@ goog.requireType('Blockly.Field'); * @constructor * @extends {Blockly.BasicCursor} */ -Blockly.TabNavigateCursor = function() { - Blockly.TabNavigateCursor.superClass_.constructor.call(this); +const TabNavigateCursor = function() { + TabNavigateCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); +Blockly.utils.object.inherits(TabNavigateCursor, Blockly.BasicCursor); /** * Skip all nodes except for tab navigable fields. @@ -36,7 +37,7 @@ Blockly.utils.object.inherits(Blockly.TabNavigateCursor, Blockly.BasicCursor); * @return {boolean} True if the node should be visited, false otherwise. * @override */ -Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { +TabNavigateCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (node) { @@ -48,3 +49,5 @@ Blockly.TabNavigateCursor.prototype.validNode_ = function(node) { } return isValid; }; + +exports = TabNavigateCursor; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..0c03cecf3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], [ goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); From 9a6a92bf52d748bd36c82250e9c023a0084e550e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:47:25 -0700 Subject: [PATCH 192/833] Migrate core/keyboard_nav/tab_navigate_cursor.js named requires --- core/keyboard_nav/tab_navigate_cursor.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index ad2bb45ba..37f90fe37 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -14,26 +14,25 @@ goog.module('Blockly.TabNavigateCursor'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); -goog.require('Blockly.BasicCursor'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Field'); +const ASTNode = goog.require('Blockly.ASTNode'); +const BasicCursor = goog.require('Blockly.BasicCursor'); +const Field = goog.requireType('Blockly.Field'); +const {inherits} = goog.require('Blockly.utils.object'); /** * A cursor for navigating between tab navigable fields. * @constructor - * @extends {Blockly.BasicCursor} + * @extends {BasicCursor} */ const TabNavigateCursor = function() { TabNavigateCursor.superClass_.constructor.call(this); }; -Blockly.utils.object.inherits(TabNavigateCursor, Blockly.BasicCursor); +inherits(TabNavigateCursor, BasicCursor); /** * Skip all nodes except for tab navigable fields. - * @param {Blockly.ASTNode} node The AST node to check whether it is valid. + * @param {?ASTNode} node The AST node to check whether it is valid. * @return {boolean} True if the node should be visited, false otherwise. * @override */ @@ -41,8 +40,8 @@ TabNavigateCursor.prototype.validNode_ = function(node) { let isValid = false; const type = node && node.getType(); if (node) { - const location = /** @type {Blockly.Field} */ (node.getLocation()); - if (type == Blockly.ASTNode.types.FIELD && + const location = /** @type {Field} */ (node.getLocation()); + if (type == ASTNode.types.FIELD && location && location.isTabNavigable() && location.isClickable()) { isValid = true; } From ecec6daf80e9b7910393e371223b3824855f180b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:47:41 -0700 Subject: [PATCH 193/833] clang-format core/keyboard_nav/tab_navigate_cursor.js --- core/keyboard_nav/tab_navigate_cursor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 37f90fe37..3b82267a1 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -41,8 +41,8 @@ TabNavigateCursor.prototype.validNode_ = function(node) { const type = node && node.getType(); if (node) { const location = /** @type {Field} */ (node.getLocation()); - if (type == ASTNode.types.FIELD && - location && location.isTabNavigable() && location.isClickable()) { + if (type == ASTNode.types.FIELD && location && location.isTabNavigable() && + location.isClickable()) { isValid = true; } } From b2a68532d2870fe75ce0198c1c66913ca32391ba Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 10:48:56 -0700 Subject: [PATCH 194/833] Migrate core/delete_area.js to ES6 const/let --- core/delete_area.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/delete_area.js b/core/delete_area.js index 384136a05..8a9f4ec6d 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -55,8 +55,8 @@ Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); */ Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) { if (element instanceof Blockly.BlockSvg) { - var block = /** @type {Blockly.BlockSvg} */ (element); - var couldDeleteBlock = !block.getParent() && block.isDeletable(); + const block = /** @type {Blockly.BlockSvg} */ (element); + const couldDeleteBlock = !block.getParent() && block.isDeletable(); this.updateWouldDelete_(couldDeleteBlock && !couldConnect); } else { this.updateWouldDelete_(element.isDeletable()); From 7219b83093311b52366226142cc6f5d9866e1033 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 10:52:35 -0700 Subject: [PATCH 195/833] Migrate core/delete_area.js to goog.module --- core/delete_area.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/delete_area.js b/core/delete_area.js index 8a9f4ec6d..64605dee0 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.DeleteArea'); +goog.module('Blockly.DeleteArea'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.BlockSvg'); goog.require('Blockly.DragTarget'); @@ -27,8 +28,8 @@ goog.requireType('Blockly.IDraggable'); * @implements {Blockly.IDeleteArea} * @constructor */ -Blockly.DeleteArea = function() { - Blockly.DeleteArea.superClass_.constructor.call(this); +const DeleteArea = function() { + DeleteArea.superClass_.constructor.call(this); /** * Whether the last block or bubble dragged over this delete area would be @@ -39,7 +40,7 @@ Blockly.DeleteArea = function() { */ this.wouldDelete_ = false; }; -Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); +Blockly.utils.object.inherits(DeleteArea, Blockly.DragTarget); /** * Returns whether the provided block or bubble would be deleted if dropped on @@ -53,7 +54,7 @@ Blockly.utils.object.inherits(Blockly.DeleteArea, Blockly.DragTarget); * @return {boolean} Whether the element provided would be deleted if dropped on * this area. */ -Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) { +DeleteArea.prototype.wouldDelete = function(element, couldConnect) { if (element instanceof Blockly.BlockSvg) { const block = /** @type {Blockly.BlockSvg} */ (element); const couldDeleteBlock = !block.getParent() && block.isDeletable(); @@ -69,6 +70,8 @@ Blockly.DeleteArea.prototype.wouldDelete = function(element, couldConnect) { * @param {boolean} wouldDelete The new value for the wouldDelete state. * @protected */ -Blockly.DeleteArea.prototype.updateWouldDelete_ = function(wouldDelete) { +DeleteArea.prototype.updateWouldDelete_ = function(wouldDelete) { this.wouldDelete_ = wouldDelete; }; + +exports = DeleteArea; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..3486a6137 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -28,7 +28,7 @@ goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Block goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); +goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); From ff34d8c37e414c5c029db760920760b5e4e8db88 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 10:57:20 -0700 Subject: [PATCH 196/833] Migrate core/delete_area.js to named requires --- core/delete_area.js | 24 +++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/delete_area.js b/core/delete_area.js index 64605dee0..55eb61a34 100644 --- a/core/delete_area.js +++ b/core/delete_area.js @@ -15,17 +15,19 @@ goog.module('Blockly.DeleteArea'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.BlockSvg'); -goog.require('Blockly.DragTarget'); -goog.require('Blockly.IDeleteArea'); - -goog.requireType('Blockly.IDraggable'); +const BlockSvg = goog.require('Blockly.BlockSvg'); +const DragTarget = goog.require('Blockly.DragTarget'); +/* eslint-disable-next-line no-unused-vars */ +const IDeleteArea = goog.require('Blockly.IDeleteArea'); +/* eslint-disable-next-line no-unused-vars */ +const IDraggable = goog.requireType('Blockly.IDraggable'); +const {inherits} = goog.require('Blockly.utils.object'); /** * Abstract class for a component that can delete a block or bubble that is * dropped on top of it. - * @extends {Blockly.DragTarget} - * @implements {Blockly.IDeleteArea} + * @extends {DragTarget} + * @implements {IDeleteArea} * @constructor */ const DeleteArea = function() { @@ -40,14 +42,14 @@ const DeleteArea = function() { */ this.wouldDelete_ = false; }; -Blockly.utils.object.inherits(DeleteArea, Blockly.DragTarget); +inherits(DeleteArea, DragTarget); /** * Returns whether the provided block or bubble would be deleted if dropped on * this area. * This method should check if the element is deletable and is always called * before onDragEnter/onDragOver/onDragExit. - * @param {!Blockly.IDraggable} element The block or bubble currently being + * @param {!IDraggable} element The block or bubble currently being * dragged. * @param {boolean} couldConnect Whether the element could could connect to * another. @@ -55,8 +57,8 @@ Blockly.utils.object.inherits(DeleteArea, Blockly.DragTarget); * this area. */ DeleteArea.prototype.wouldDelete = function(element, couldConnect) { - if (element instanceof Blockly.BlockSvg) { - const block = /** @type {Blockly.BlockSvg} */ (element); + if (element instanceof BlockSvg) { + const block = /** @type {BlockSvg} */ (element); const couldDeleteBlock = !block.getParent() && block.isDeletable(); this.updateWouldDelete_(couldDeleteBlock && !couldConnect); } else { diff --git a/tests/deps.js b/tests/deps.js index 3486a6137..aabe7c944 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -28,7 +28,7 @@ goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Block goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); From 0dc01b16188564b949b90512133d59c4eabb7c40 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:02:32 -0700 Subject: [PATCH 197/833] Migrate core/drag_target.js to goog.module --- core/drag_target.js | 19 +++++++++++-------- tests/deps.js | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/drag_target.js b/core/drag_target.js index 438bf6a31..91d46c5ca 100644 --- a/core/drag_target.js +++ b/core/drag_target.js @@ -12,7 +12,8 @@ 'use strict'; -goog.provide('Blockly.DragTarget'); +goog.module('Blockly.DragTarget'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.IDragTarget'); @@ -26,7 +27,7 @@ goog.requireType('Blockly.utils.Rect'); * @implements {Blockly.IDragTarget} * @constructor */ -Blockly.DragTarget = function() {}; +const DragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units @@ -34,14 +35,14 @@ Blockly.DragTarget = function() {}; * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.DragTarget.prototype.getClientRect; +DragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragEnter = function(_dragElement) { +DragTarget.prototype.onDragEnter = function(_dragElement) { // no-op }; @@ -51,7 +52,7 @@ Blockly.DragTarget.prototype.onDragEnter = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragOver = function(_dragElement) { +DragTarget.prototype.onDragOver = function(_dragElement) { // no-op }; @@ -60,7 +61,7 @@ Blockly.DragTarget.prototype.onDragOver = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDragExit = function(_dragElement) { +DragTarget.prototype.onDragExit = function(_dragElement) { // no-op }; @@ -70,7 +71,7 @@ Blockly.DragTarget.prototype.onDragExit = function(_dragElement) { * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being * dragged. */ -Blockly.DragTarget.prototype.onDrop = function(_dragElement) { +DragTarget.prototype.onDrop = function(_dragElement) { // no-op }; @@ -83,6 +84,8 @@ Blockly.DragTarget.prototype.onDrop = function(_dragElement) { * @return {boolean} Whether the block or bubble provided should be returned to * drag start. */ -Blockly.DragTarget.prototype.shouldPreventMove = function(_dragElement) { +DragTarget.prototype.shouldPreventMove = function(_dragElement) { return false; }; + +exports = DragTarget; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..74b561fe4 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); From b1b5358b678041ac0603fc59f93c4829e0554735 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:06:53 -0700 Subject: [PATCH 198/833] Migrate core/drag_target.js to named requires --- core/drag_target.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/drag_target.js b/core/drag_target.js index 91d46c5ca..18e29b40a 100644 --- a/core/drag_target.js +++ b/core/drag_target.js @@ -15,16 +15,18 @@ goog.module('Blockly.DragTarget'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.IDragTarget'); - -goog.requireType('Blockly.IDraggable'); -goog.requireType('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ +const IDragTarget = goog.require('Blockly.IDragTarget'); +/* eslint-disable-next-line no-unused-vars */ +const IDraggable = goog.requireType('Blockly.IDraggable'); +/* eslint-disable-next-line no-unused-vars */ +const Rect = goog.requireType('Blockly.utils.Rect'); /** * Abstract class for a component with custom behaviour when a block or bubble * is dragged over or dropped on top of it. - * @implements {Blockly.IDragTarget} + * @implements {IDragTarget} * @constructor */ const DragTarget = function() {}; @@ -32,14 +34,14 @@ const DragTarget = function() {}; /** * Returns the bounding rectangle of the drag target area in pixel units * relative to the Blockly injection div. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ DragTarget.prototype.getClientRect; /** * Handles when a cursor with a block or bubble enters this drag target. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDragEnter = function(_dragElement) { @@ -49,7 +51,7 @@ DragTarget.prototype.onDragEnter = function(_dragElement) { /** * Handles when a cursor with a block or bubble is dragged over this drag * target. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDragOver = function(_dragElement) { @@ -58,7 +60,7 @@ DragTarget.prototype.onDragOver = function(_dragElement) { /** * Handles when a cursor with a block or bubble exits this drag target. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDragExit = function(_dragElement) { @@ -68,7 +70,7 @@ DragTarget.prototype.onDragExit = function(_dragElement) { /** * Handles when a block or bubble is dropped on this component. * Should not handle delete here. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. */ DragTarget.prototype.onDrop = function(_dragElement) { @@ -79,7 +81,7 @@ DragTarget.prototype.onDrop = function(_dragElement) { * Returns whether the provided block or bubble should not be moved after being * dropped on this component. If true, the element will return to where it was * when the drag started. - * @param {!Blockly.IDraggable} _dragElement The block or bubble currently being + * @param {!IDraggable} _dragElement The block or bubble currently being * dragged. * @return {boolean} Whether the block or bubble provided should be returned to * drag start. From a57399704f5be6af807040bc12190f8e00f576f0 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:15:25 -0700 Subject: [PATCH 199/833] Migrate core/field.js to ES6 const/let --- core/field.js | 79 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/core/field.js b/core/field.js index f5f027c45..ed15cd494 100644 --- a/core/field.js +++ b/core/field.js @@ -267,7 +267,7 @@ Blockly.Field.prototype.SERIALIZABLE = false; * @protected */ Blockly.Field.prototype.configure_ = function(config) { - var tooltip = config['tooltip']; + let tooltip = config['tooltip']; if (typeof tooltip == 'string') { tooltip = Blockly.utils.replaceMessageReferences( config['tooltip']); @@ -325,7 +325,7 @@ Blockly.Field.prototype.init = function() { if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } - var sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_); this.initView(); this.updateEditable(); @@ -444,7 +444,7 @@ Blockly.Field.prototype.dispose = function() { * Add or remove the UI indicating if this field is editable or not. */ Blockly.Field.prototype.updateEditable = function() { - var group = this.fieldGroup_; + const group = this.fieldGroup_; if (!this.EDITABLE || !group) { return; } @@ -506,7 +506,7 @@ Blockly.Field.prototype.isCurrentlyEditable = function() { * @return {boolean} Whether this field should be serialized or not. */ Blockly.Field.prototype.isSerializable = function() { - var isSerializable = false; + let isSerializable = false; if (this.name) { if (this.SERIALIZABLE) { isSerializable = true; @@ -539,7 +539,7 @@ Blockly.Field.prototype.setVisible = function(visible) { return; } this.visible_ = visible; - var root = this.getSvgRoot(); + const root = this.getSvgRoot(); if (root) { root.style.display = visible ? 'block' : 'none'; } @@ -622,13 +622,13 @@ Blockly.Field.prototype.showEditor = function(opt_e) { * @protected */ Blockly.Field.prototype.updateSize_ = function(opt_margin) { - var constants = this.getConstants(); - var xOffset = opt_margin != undefined ? opt_margin : + const constants = this.getConstants(); + const xOffset = opt_margin != undefined ? opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); - var totalWidth = xOffset * 2; - var totalHeight = constants.FIELD_TEXT_HEIGHT; + let totalWidth = xOffset * 2; + let totalHeight = constants.FIELD_TEXT_HEIGHT; - var contentWidth = 0; + let contentWidth = 0; if (this.textElement_) { contentWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, constants.FIELD_TEXT_FONTSIZE, @@ -658,8 +658,8 @@ Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { if (!this.textElement_) { return; } - var constants = this.getConstants(); - var halfHeight = this.size_.height / 2; + const constants = this.getConstants(); + const halfHeight = this.size_.height / 2; this.textElement_.setAttribute('x', this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : xOffset); @@ -717,15 +717,16 @@ Blockly.Field.prototype.getSize = function() { * @package */ Blockly.Field.prototype.getScaledBBox = function() { + let scaledWidth, scaledHeight, xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. // - Webkit / Blink: fill-box / object bounding box // - Gecko / Triden / EdgeHTML: stroke-box - var bBox = this.sourceBlock_.getHeightWidth(); - var scale = this.sourceBlock_.workspace.scale; - var xy = this.getAbsoluteXY_(); - var scaledWidth = bBox.width * scale; - var scaledHeight = bBox.height * scale; + const bBox = this.sourceBlock_.getHeightWidth(); + const scale = this.sourceBlock_.workspace.scale; + xy = this.getAbsoluteXY_(); + scaledWidth = bBox.width * scale; + scaledHeight = bBox.height * scale; if (Blockly.utils.userAgent.GECKO) { xy.x += 1.5 * scale; @@ -741,10 +742,10 @@ Blockly.Field.prototype.getScaledBBox = function() { scaledHeight += 1 * scale; } } else { - var bBox = this.borderRect_.getBoundingClientRect(); - var xy = Blockly.utils.style.getPageOffset(this.borderRect_); - var scaledWidth = bBox.width; - var scaledHeight = bBox.height; + const bBox = this.borderRect_.getBoundingClientRect(); + xy = Blockly.utils.style.getPageOffset(this.borderRect_); + scaledWidth = bBox.width; + scaledHeight = bBox.height; } return new Blockly.utils.Rect( xy.y, @@ -761,7 +762,7 @@ Blockly.Field.prototype.getScaledBBox = function() { * @protected */ Blockly.Field.prototype.getDisplayText_ = function() { - var text = this.getText(); + let text = this.getText(); if (!text) { // Prevent the field from disappearing if empty. return Blockly.Field.NBSP; @@ -785,7 +786,7 @@ Blockly.Field.prototype.getDisplayText_ = function() { */ Blockly.Field.prototype.getText = function() { if (this.getText_) { - var text = this.getText_.call(this); + const text = this.getText_.call(this); if (text !== null) { return String(text); } @@ -828,14 +829,14 @@ Blockly.Field.prototype.forceRerender = function() { * @param {*} newValue New value. */ Blockly.Field.prototype.setValue = function(newValue) { - var doLogging = false; + const doLogging = false; if (newValue === null) { doLogging && console.log('null, return'); // Not a valid value to check. return; } - var validatedValue = this.doClassValidation_(newValue); + let validatedValue = this.doClassValidation_(newValue); // Class validators might accidentally forget to return, we'll ignore that. newValue = this.processValidation_(newValue, validatedValue); if (newValue instanceof Error) { @@ -843,7 +844,7 @@ Blockly.Field.prototype.setValue = function(newValue) { return; } - var localValidator = this.getValidator(); + const localValidator = this.getValidator(); if (localValidator) { validatedValue = localValidator.call(this, newValue); // Local validators might accidentally forget to return, we'll ignore that. @@ -853,12 +854,12 @@ Blockly.Field.prototype.setValue = function(newValue) { return; } } - var source = this.sourceBlock_; + const source = this.sourceBlock_; if (source && source.disposed) { doLogging && console.log('source disposed, return'); return; } - var oldValue = this.getValue(); + const oldValue = this.getValue(); if (oldValue === newValue) { doLogging && console.log('same, doValueUpdate_, return'); this.doValueUpdate_(newValue); @@ -951,7 +952,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) { if (!this.sourceBlock_ || !this.sourceBlock_.workspace) { return; } - var gesture = this.sourceBlock_.workspace.getGesture(e); + const gesture = this.sourceBlock_.workspace.getGesture(e); if (gesture) { gesture.setStartField(this); } @@ -968,7 +969,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; } - var clickTarget = this.getClickTarget_(); + const clickTarget = this.getClickTarget_(); if (clickTarget) { clickTarget.tooltip = newTip; } else { @@ -982,7 +983,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { * @return {string} The tooltip text for this field. */ Blockly.Field.prototype.getTooltip = function() { - var clickTarget = this.getClickTarget_(); + const clickTarget = this.getClickTarget_(); if (clickTarget) { return Blockly.Tooltip.getTooltipOfObject(clickTarget); } @@ -1030,14 +1031,14 @@ Blockly.Field.prototype.referencesVariables = function() { * @package */ Blockly.Field.prototype.getParentInput = function() { - var parentInput = null; - var block = this.sourceBlock_; - var inputs = block.inputList; + let parentInput = null; + const block = this.sourceBlock_; + const inputs = block.inputList; - for (var idx = 0; idx < block.inputList.length; idx++) { - var input = inputs[idx]; - var fieldRows = input.fieldRow; - for (var j = 0; j < fieldRows.length; j++) { + for (let idx = 0; idx < block.inputList.length; idx++) { + const input = inputs[idx]; + const fieldRows = input.fieldRow; + for (let j = 0; j < fieldRows.length; j++) { if (fieldRows[j] === this) { parentInput = input; break; @@ -1110,7 +1111,7 @@ Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { * @protected */ Blockly.Field.prototype.updateMarkers_ = function() { - var workspace = + const workspace = /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); From 91721f7d163092940d6cb8941889d8a6045acee2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:18:41 -0700 Subject: [PATCH 200/833] Migrate core/field.js to goog.module --- core/field.js | 151 +++++++++++++++++++++++++------------------------- tests/deps.js | 2 +- 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/core/field.js b/core/field.js index ed15cd494..d9db11cbd 100644 --- a/core/field.js +++ b/core/field.js @@ -7,12 +7,13 @@ /** * @fileoverview Field. Used for editable titles, variables, etc. * This is an abstract class that defines the UI on the block. Actual - * instances would be Blockly.FieldTextInput, Blockly.FieldDropdown, etc. + * instances would be FieldTextInput, FieldDropdown, etc. * @author fraser@google.com (Neil Fraser) */ 'use strict'; -goog.provide('Blockly.Field'); +goog.module('Blockly.Field'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.DropDownDiv'); @@ -61,7 +62,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @implements {Blockly.IKeyboardAccessible} * @implements {Blockly.IRegistrable} */ -Blockly.Field = function(value, opt_validator, opt_config) { +const Field = function(value, opt_validator, opt_config) { /** * A generic value possessed by the field. * Should generally be non-null, only null when the field is created. @@ -160,62 +161,62 @@ Blockly.Field = function(value, opt_validator, opt_config) { * @type {*} * @protected */ -Blockly.Field.prototype.DEFAULT_VALUE = null; +Field.prototype.DEFAULT_VALUE = null; /** * Name of field. Unique within each block. * Static labels are usually unnamed. * @type {string|undefined} */ -Blockly.Field.prototype.name = undefined; +Field.prototype.name = undefined; /** * Has this field been disposed of? * @type {boolean} * @package */ -Blockly.Field.prototype.disposed = false; +Field.prototype.disposed = false; /** * Maximum characters of text to display before adding an ellipsis. * @type {number} */ -Blockly.Field.prototype.maxDisplayLength = 50; +Field.prototype.maxDisplayLength = 50; /** * Block this field is attached to. Starts as null, then set in init. * @type {Blockly.Block} * @protected */ -Blockly.Field.prototype.sourceBlock_ = null; +Field.prototype.sourceBlock_ = null; /** * Does this block need to be re-rendered? * @type {boolean} * @protected */ -Blockly.Field.prototype.isDirty_ = true; +Field.prototype.isDirty_ = true; /** * Is the field visible, or hidden due to the block being collapsed? * @type {boolean} * @protected */ -Blockly.Field.prototype.visible_ = true; +Field.prototype.visible_ = true; /** * Can the field value be changed using the editor on an editable block? * @type {boolean} * @protected */ -Blockly.Field.prototype.enabled_ = true; +Field.prototype.enabled_ = true; /** * The element the click handler is bound to. * @type {Element} * @protected */ -Blockly.Field.prototype.clickTarget_ = null; +Field.prototype.clickTarget_ = null; /** * A developer hook to override the returned text of this field. @@ -225,7 +226,7 @@ Blockly.Field.prototype.clickTarget_ = null; * @return {?string} Current text. Return null to resort to a string cast. * @protected */ -Blockly.Field.prototype.getText_; +Field.prototype.getText_; /** * An optional method that can be defined to show an editor when the field is @@ -236,20 +237,20 @@ Blockly.Field.prototype.getText_; * @return {void} * @protected */ -Blockly.Field.prototype.showEditor_; +Field.prototype.showEditor_; /** * Non-breaking space. * @const */ -Blockly.Field.NBSP = '\u00A0'; +Field.NBSP = '\u00A0'; /** * Editable fields usually show some sort of UI indicating they are editable. * They will also be saved by the XML renderer. * @type {boolean} */ -Blockly.Field.prototype.EDITABLE = true; +Field.prototype.EDITABLE = true; /** * Serializable fields are saved by the XML renderer, non-serializable fields @@ -257,7 +258,7 @@ Blockly.Field.prototype.EDITABLE = true; * case by default so that SERIALIZABLE is backwards compatible. * @type {boolean} */ -Blockly.Field.prototype.SERIALIZABLE = false; +Field.prototype.SERIALIZABLE = false; /** * Process the configuration map passed to the field. @@ -266,7 +267,7 @@ Blockly.Field.prototype.SERIALIZABLE = false; * parameter supports. * @protected */ -Blockly.Field.prototype.configure_ = function(config) { +Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { tooltip = Blockly.utils.replaceMessageReferences( @@ -282,7 +283,7 @@ Blockly.Field.prototype.configure_ = function(config) { * Attach this field to a block. * @param {!Blockly.Block} block The block containing this field. */ -Blockly.Field.prototype.setSourceBlock = function(block) { +Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { throw Error('Field already bound to a block'); } @@ -294,7 +295,7 @@ Blockly.Field.prototype.setSourceBlock = function(block) { * @return {?Blockly.blockRendering.ConstantProvider} The renderer constant * provider. */ -Blockly.Field.prototype.getConstants = function() { +Field.prototype.getConstants = function() { if (!this.constants_ && this.sourceBlock_ && this.sourceBlock_.workspace && this.sourceBlock_.workspace.rendered) { this.constants_ = this.sourceBlock_.workspace.getRenderer().getConstants(); @@ -306,7 +307,7 @@ Blockly.Field.prototype.getConstants = function() { * Get the block this field is attached to. * @return {Blockly.Block} The block containing this field. */ -Blockly.Field.prototype.getSourceBlock = function() { +Field.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -315,7 +316,7 @@ Blockly.Field.prototype.getSourceBlock = function() { * methods initModel and initView rather than this method. * @package */ -Blockly.Field.prototype.init = function() { +Field.prototype.init = function() { if (this.fieldGroup_) { // Field has already been initialized once. return; @@ -338,7 +339,7 @@ Blockly.Field.prototype.init = function() { * Create the block UI for this field. * @package */ -Blockly.Field.prototype.initView = function() { +Field.prototype.initView = function() { this.createBorderRect_(); this.createTextElement_(); }; @@ -348,7 +349,7 @@ Blockly.Field.prototype.initView = function() { * No-op by default. * @package */ -Blockly.Field.prototype.initModel = function() { +Field.prototype.initModel = function() { }; /** @@ -357,7 +358,7 @@ Blockly.Field.prototype.initModel = function() { * separate function to call. * @protected */ -Blockly.Field.prototype.createBorderRect_ = function() { +Field.prototype.createBorderRect_ = function() { this.borderRect_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'rx': this.getConstants().FIELD_BORDER_RECT_RADIUS, @@ -376,7 +377,7 @@ Blockly.Field.prototype.createBorderRect_ = function() { * function to call. * @protected */ -Blockly.Field.prototype.createTextElement_ = function() { +Field.prototype.createTextElement_ = function() { this.textElement_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText', @@ -393,7 +394,7 @@ Blockly.Field.prototype.createTextElement_ = function() { * custom input handling. * @protected */ -Blockly.Field.prototype.bindEvents_ = function() { +Field.prototype.bindEvents_ = function() { Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); @@ -406,7 +407,7 @@ Blockly.Field.prototype.bindEvents_ = function() { * field's state. * @package */ -Blockly.Field.prototype.fromXml = function(fieldElement) { +Field.prototype.fromXml = function(fieldElement) { this.setValue(fieldElement.textContent); }; @@ -417,7 +418,7 @@ Blockly.Field.prototype.fromXml = function(fieldElement) { * @return {!Element} The element containing info about the field's state. * @package */ -Blockly.Field.prototype.toXml = function(fieldElement) { +Field.prototype.toXml = function(fieldElement) { fieldElement.textContent = this.getValue(); return fieldElement; }; @@ -426,7 +427,7 @@ Blockly.Field.prototype.toXml = function(fieldElement) { * Dispose of all DOM objects and events belonging to this editable field. * @package */ -Blockly.Field.prototype.dispose = function() { +Field.prototype.dispose = function() { Blockly.DropDownDiv.hideIfOwner(this); Blockly.WidgetDiv.hideIfOwner(this); Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); @@ -443,7 +444,7 @@ Blockly.Field.prototype.dispose = function() { /** * Add or remove the UI indicating if this field is editable or not. */ -Blockly.Field.prototype.updateEditable = function() { +Field.prototype.updateEditable = function() { const group = this.fieldGroup_; if (!this.EDITABLE || !group) { return; @@ -464,7 +465,7 @@ Blockly.Field.prototype.updateEditable = function() { * source block is editable. * @param {boolean} enabled True if enabled. */ -Blockly.Field.prototype.setEnabled = function(enabled) { +Field.prototype.setEnabled = function(enabled) { this.enabled_ = enabled; this.updateEditable(); }; @@ -474,7 +475,7 @@ Blockly.Field.prototype.setEnabled = function(enabled) { * source block is editable. * @return {boolean} Whether this field is enabled. */ -Blockly.Field.prototype.isEnabled = function() { +Field.prototype.isEnabled = function() { return this.enabled_; }; @@ -482,7 +483,7 @@ Blockly.Field.prototype.isEnabled = function() { * Check whether this field defines the showEditor_ function. * @return {boolean} Whether this field is clickable. */ -Blockly.Field.prototype.isClickable = function() { +Field.prototype.isClickable = function() { return this.enabled_ && !!this.sourceBlock_ && this.sourceBlock_.isEditable() && !!this.showEditor_ && (typeof this.showEditor_ === 'function'); @@ -495,7 +496,7 @@ Blockly.Field.prototype.isClickable = function() { * @return {boolean} Whether this field is currently enabled, editable and on * an editable block. */ -Blockly.Field.prototype.isCurrentlyEditable = function() { +Field.prototype.isCurrentlyEditable = function() { return this.enabled_ && this.EDITABLE && !!this.sourceBlock_ && this.sourceBlock_.isEditable(); }; @@ -505,7 +506,7 @@ Blockly.Field.prototype.isCurrentlyEditable = function() { * Handles the logic for backwards compatibility and incongruous states. * @return {boolean} Whether this field should be serialized or not. */ -Blockly.Field.prototype.isSerializable = function() { +Field.prototype.isSerializable = function() { let isSerializable = false; if (this.name) { if (this.SERIALIZABLE) { @@ -524,7 +525,7 @@ Blockly.Field.prototype.isSerializable = function() { * Gets whether this editable field is visible or not. * @return {boolean} True if visible. */ -Blockly.Field.prototype.isVisible = function() { +Field.prototype.isVisible = function() { return this.visible_; }; @@ -534,7 +535,7 @@ Blockly.Field.prototype.isVisible = function() { * @param {boolean} visible True if visible. * @package */ -Blockly.Field.prototype.setVisible = function(visible) { +Field.prototype.setVisible = function(visible) { if (this.visible_ == visible) { return; } @@ -560,7 +561,7 @@ Blockly.Field.prototype.setVisible = function(visible) { * @param {Function} handler The validator function * or null to clear a previous validator. */ -Blockly.Field.prototype.setValidator = function(handler) { +Field.prototype.setValidator = function(handler) { this.validator_ = handler; }; @@ -568,7 +569,7 @@ Blockly.Field.prototype.setValidator = function(handler) { * Gets the validation function for editable fields, or null if not set. * @return {?Function} Validation function, or null. */ -Blockly.Field.prototype.getValidator = function() { +Field.prototype.getValidator = function() { return this.validator_; }; @@ -577,7 +578,7 @@ Blockly.Field.prototype.getValidator = function() { * Used for measuring the size and for positioning. * @return {!SVGGElement} The group element. */ -Blockly.Field.prototype.getSvgRoot = function() { +Field.prototype.getSvgRoot = function() { return /** @type {!SVGGElement} */ (this.fieldGroup_); }; @@ -586,7 +587,7 @@ Blockly.Field.prototype.getSvgRoot = function() { * called by BlockSvg.applyColour(). * @package */ -Blockly.Field.prototype.applyColour = function() { +Field.prototype.applyColour = function() { // Non-abstract sub-classes may wish to implement this. See FieldDropdown. }; @@ -597,7 +598,7 @@ Blockly.Field.prototype.applyColour = function() { * done here, and should be triggered by getSize(). * @protected */ -Blockly.Field.prototype.render_ = function() { +Field.prototype.render_ = function() { if (this.textContent_) { this.textContent_.nodeValue = this.getDisplayText_(); } @@ -610,7 +611,7 @@ Blockly.Field.prototype.render_ = function() { * or undefined if triggered programmatically. * @package */ -Blockly.Field.prototype.showEditor = function(opt_e) { +Field.prototype.showEditor = function(opt_e) { if (this.isClickable()) { this.showEditor_(opt_e); } @@ -621,7 +622,7 @@ Blockly.Field.prototype.showEditor = function(opt_e) { * @param {number=} opt_margin margin to use when positioning the text element. * @protected */ -Blockly.Field.prototype.updateSize_ = function(opt_margin) { +Field.prototype.updateSize_ = function(opt_margin) { const constants = this.getConstants(); const xOffset = opt_margin != undefined ? opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); @@ -654,7 +655,7 @@ Blockly.Field.prototype.updateSize_ = function(opt_margin) { * @param {number} contentWidth The content width. * @protected */ -Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { +Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { if (!this.textElement_) { return; } @@ -672,7 +673,7 @@ Blockly.Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { * Position a field's border rect after a size change. * @protected */ -Blockly.Field.prototype.positionBorderRect_ = function() { +Field.prototype.positionBorderRect_ = function() { if (!this.borderRect_) { return; } @@ -691,7 +692,7 @@ Blockly.Field.prototype.positionBorderRect_ = function() { * This should *in general* be the only place render_ gets called from. * @return {!Blockly.utils.Size} Height and width. */ -Blockly.Field.prototype.getSize = function() { +Field.prototype.getSize = function() { if (!this.isVisible()) { return new Blockly.utils.Size(0, 0); } @@ -716,7 +717,7 @@ Blockly.Field.prototype.getSize = function() { * pixels relative to the top left corner of the page (window coordinates). * @package */ -Blockly.Field.prototype.getScaledBBox = function() { +Field.prototype.getScaledBBox = function() { let scaledWidth, scaledHeight, xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. @@ -761,18 +762,18 @@ Blockly.Field.prototype.getScaledBBox = function() { * @return {string} Text to display. * @protected */ -Blockly.Field.prototype.getDisplayText_ = function() { +Field.prototype.getDisplayText_ = function() { let text = this.getText(); if (!text) { // Prevent the field from disappearing if empty. - return Blockly.Field.NBSP; + return Field.NBSP; } if (text.length > this.maxDisplayLength) { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 2) + '\u2026'; } // Replace whitespace with non-breaking spaces so the text doesn't collapse. - text = text.replace(/\s/g, Blockly.Field.NBSP); + text = text.replace(/\s/g, Field.NBSP); if (this.sourceBlock_ && this.sourceBlock_.RTL) { // The SVG is LTR, force text to be RTL. text += '\u200F'; @@ -784,7 +785,7 @@ Blockly.Field.prototype.getDisplayText_ = function() { * Get the text from this field. * @return {string} Current text. */ -Blockly.Field.prototype.getText = function() { +Field.prototype.getText = function() { if (this.getText_) { const text = this.getText_.call(this); if (text !== null) { @@ -801,7 +802,7 @@ Blockly.Field.prototype.getText = function() { * already been recorded. * @package */ -Blockly.Field.prototype.markDirty = function() { +Field.prototype.markDirty = function() { this.isDirty_ = true; this.constants_ = null; }; @@ -813,7 +814,7 @@ Blockly.Field.prototype.markDirty = function() { * already been recorded. * @package */ -Blockly.Field.prototype.forceRerender = function() { +Field.prototype.forceRerender = function() { this.isDirty_ = true; if (this.sourceBlock_ && this.sourceBlock_.rendered) { this.sourceBlock_.render(); @@ -828,7 +829,7 @@ Blockly.Field.prototype.forceRerender = function() { * than this method. * @param {*} newValue New value. */ -Blockly.Field.prototype.setValue = function(newValue) { +Field.prototype.setValue = function(newValue) { const doLogging = false; if (newValue === null) { doLogging && console.log('null, return'); @@ -884,7 +885,7 @@ Blockly.Field.prototype.setValue = function(newValue) { * @return {*} New value, or an Error object. * @private */ -Blockly.Field.prototype.processValidation_ = function(newValue, +Field.prototype.processValidation_ = function(newValue, validatedValue) { if (validatedValue === null) { this.doValueInvalid_(newValue); @@ -903,7 +904,7 @@ Blockly.Field.prototype.processValidation_ = function(newValue, * Get the current value of the field. * @return {*} Current value. */ -Blockly.Field.prototype.getValue = function() { +Field.prototype.getValue = function() { return this.value_; }; @@ -914,7 +915,7 @@ Blockly.Field.prototype.getValue = function() { * @return {*} The validated value, same as input by default. * @protected */ -Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) { +Field.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -927,7 +928,7 @@ Blockly.Field.prototype.doClassValidation_ = function(opt_newValue) { * @param {*} newValue The value to be saved. * @protected */ -Blockly.Field.prototype.doValueUpdate_ = function(newValue) { +Field.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; this.isDirty_ = true; }; @@ -939,7 +940,7 @@ Blockly.Field.prototype.doValueUpdate_ = function(newValue) { * @param {*} _invalidValue The input value that was determined to be invalid. * @protected */ -Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { +Field.prototype.doValueInvalid_ = function(_invalidValue) { // NOP }; @@ -948,7 +949,7 @@ Blockly.Field.prototype.doValueInvalid_ = function(_invalidValue) { * @param {!Event} e Mouse down event. * @protected */ -Blockly.Field.prototype.onMouseDown_ = function(e) { +Field.prototype.onMouseDown_ = function(e) { if (!this.sourceBlock_ || !this.sourceBlock_.workspace) { return; } @@ -965,7 +966,7 @@ Blockly.Field.prototype.onMouseDown_ = function(e) { * parent object whose tooltip will be used, or null to display the tooltip * of the parent block. To not display a tooltip pass the empty string. */ -Blockly.Field.prototype.setTooltip = function(newTip) { +Field.prototype.setTooltip = function(newTip) { if (!newTip && newTip !== '') { // If null or undefined. newTip = this.sourceBlock_; } @@ -982,7 +983,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { * Returns the tooltip text for this field. * @return {string} The tooltip text for this field. */ -Blockly.Field.prototype.getTooltip = function() { +Field.prototype.getTooltip = function() { const clickTarget = this.getClickTarget_(); if (clickTarget) { return Blockly.Tooltip.getTooltipOfObject(clickTarget); @@ -998,7 +999,7 @@ Blockly.Field.prototype.getTooltip = function() { * @return {!Element} Element to bind click handler to. * @protected */ -Blockly.Field.prototype.getClickTarget_ = function() { +Field.prototype.getClickTarget_ = function() { return this.clickTarget_ || this.getSvgRoot(); }; @@ -1008,7 +1009,7 @@ Blockly.Field.prototype.getClickTarget_ = function() { * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. * @protected */ -Blockly.Field.prototype.getAbsoluteXY_ = function() { +Field.prototype.getAbsoluteXY_ = function() { return Blockly.utils.style.getPageOffset( /** @type {!SVGRectElement} */ (this.getClickTarget_())); }; @@ -1020,7 +1021,7 @@ Blockly.Field.prototype.getAbsoluteXY_ = function() { * @return {boolean} True if this field has any variable references. * @package */ -Blockly.Field.prototype.referencesVariables = function() { +Field.prototype.referencesVariables = function() { return false; }; @@ -1030,7 +1031,7 @@ Blockly.Field.prototype.referencesVariables = function() { * @return {Blockly.Input} The input that the field belongs to. * @package */ -Blockly.Field.prototype.getParentInput = function() { +Field.prototype.getParentInput = function() { let parentInput = null; const block = this.sourceBlock_; const inputs = block.inputList; @@ -1052,7 +1053,7 @@ Blockly.Field.prototype.getParentInput = function() { * Returns whether or not we should flip the field in RTL. * @return {boolean} True if we should flip in RTL. */ -Blockly.Field.prototype.getFlipRtl = function() { +Field.prototype.getFlipRtl = function() { return false; }; @@ -1060,7 +1061,7 @@ Blockly.Field.prototype.getFlipRtl = function() { * Returns whether or not the field is tab navigable. * @return {boolean} True if the field is tab navigable. */ -Blockly.Field.prototype.isTabNavigable = function() { +Field.prototype.isTabNavigable = function() { return false; }; @@ -1070,7 +1071,7 @@ Blockly.Field.prototype.isTabNavigable = function() { * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ -Blockly.Field.prototype.onShortcut = function(_shortcut) { +Field.prototype.onShortcut = function(_shortcut) { return false; }; @@ -1080,7 +1081,7 @@ Blockly.Field.prototype.onShortcut = function(_shortcut) { * field group. * @package */ -Blockly.Field.prototype.setCursorSvg = function(cursorSvg) { +Field.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -1096,7 +1097,7 @@ Blockly.Field.prototype.setCursorSvg = function(cursorSvg) { * field group. * @package */ -Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { +Field.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -1110,7 +1111,7 @@ Blockly.Field.prototype.setMarkerSvg = function(markerSvg) { * Redraw any attached marker or cursor svgs if needed. * @protected */ -Blockly.Field.prototype.updateMarkers_ = function() { +Field.prototype.updateMarkers_ = function() { const workspace = /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { @@ -1121,3 +1122,5 @@ Blockly.Field.prototype.updateMarkers_ = function() { workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw(); } }; + +exports = Field; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..8d3cef438 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -48,7 +48,7 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); From 00a74e9d37dbc74dd6b479714b8c7a9ca655320c Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:26:28 -0700 Subject: [PATCH 201/833] Migrate core/interfaces/i_registrable_field.js to goog.module --- core/interfaces/i_registrable_field.js | 12 ++++++++---- tests/deps.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 1d49edad2..180599bdb 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -11,21 +11,25 @@ 'use strict'; -goog.provide('Blockly.IRegistrableField'); +goog.module('Blockly.IRegistrableField'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.Field'); + /** * A registrable field. * Note: We are not using an interface here as we are interested in defining the * static methods of a field rather than the instance methods. * @typedef {{ - * fromJson:Blockly.IRegistrableField.fromJson + * fromJson:IRegistrableField.fromJson * }} */ -Blockly.IRegistrableField; +let IRegistrableField; /** * @typedef {function(!Object): Blockly.Field} */ -Blockly.IRegistrableField.fromJson; +IRegistrableField.fromJson; + +exports = IRegistrableField; diff --git a/tests/deps.js b/tests/deps.js index 9a0ae6896..fb0b9793c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -95,7 +95,7 @@ goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetr goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); From 7d946afb4ea7f00f8111444dd828b6c3400122f7 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 12:26:43 -0700 Subject: [PATCH 202/833] Migrate core/interfaces/i_registrable_field.js named requires --- core/interfaces/i_registrable_field.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 180599bdb..2c8c005bd 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -14,7 +14,7 @@ goog.module('Blockly.IRegistrableField'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.Field'); +const Field = goog.requireType('Blockly.Field'); /** @@ -28,7 +28,7 @@ goog.requireType('Blockly.Field'); let IRegistrableField; /** - * @typedef {function(!Object): Blockly.Field} + * @typedef {function(!Object): Field} */ IRegistrableField.fromJson; From a3ae4f30162f500619325c44f211179a9369cdee Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:41:48 -0700 Subject: [PATCH 203/833] Migrate core/field.js to named requires --- core/field.js | 163 +++++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 76 deletions(-) diff --git a/core/field.js b/core/field.js index d9db11cbd..37352c64e 100644 --- a/core/field.js +++ b/core/field.js @@ -15,35 +15,46 @@ goog.module('Blockly.Field'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocationSvg = goog.require('Blockly.IASTNodeLocationSvg'); +/* eslint-disable-next-line no-unused-vars */ +const IASTNodeLocationWithBlock = goog.require('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ +const IKeyboardAccessible = goog.require('Blockly.IKeyboardAccessible'); +/* eslint-disable-next-line no-unused-vars */ +const IRegistrable = goog.require('Blockly.IRegistrable'); +/* eslint-disable-next-line no-unused-vars */ +const Input = goog.requireType('Blockly.Input'); +const MarkerManager = goog.require('Blockly.MarkerManager'); +const Rect = goog.require('Blockly.utils.Rect'); +/* eslint-disable-next-line no-unused-vars */ +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const Tooltip = goog.require('Blockly.Tooltip'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {addClass, createSvgElement, getFastTextWidth, removeClass, removeNode} = goog.require('Blockly.utils.dom'); +/* eslint-disable-next-line no-unused-vars */ +const {conditionalBind, unbind, Data} = goog.require('Blockly.browserEvents'); +const {getPageOffset} = goog.require('Blockly.utils.style'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Gesture'); -goog.require('Blockly.IASTNodeLocationSvg'); -goog.require('Blockly.IASTNodeLocationWithBlock'); -goog.require('Blockly.IKeyboardAccessible'); -goog.require('Blockly.IRegistrable'); -goog.require('Blockly.MarkerManager'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.style'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.blockRendering.ConstantProvider'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.ShortcutRegistry'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -57,10 +68,10 @@ goog.requireType('Blockly.WorkspaceSvg'); * parameter supports. * @constructor * @abstract - * @implements {Blockly.IASTNodeLocationSvg} - * @implements {Blockly.IASTNodeLocationWithBlock} - * @implements {Blockly.IKeyboardAccessible} - * @implements {Blockly.IRegistrable} + * @implements {IASTNodeLocationSvg} + * @implements {IASTNodeLocationWithBlock} + * @implements {IKeyboardAccessible} + * @implements {IRegistrable} */ const Field = function(value, opt_validator, opt_config) { /** @@ -81,17 +92,17 @@ const Field = function(value, opt_validator, opt_config) { /** * 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. - * @type {?Blockly.Tooltip.TipInfo} + * @type {?Tooltip.TipInfo} * @private */ this.tooltip_ = null; /** * The size of the area rendered by the field. - * @type {!Blockly.utils.Size} + * @type {!Size} * @protected */ - this.size_ = new Blockly.utils.Size(0, 0); + this.size_ = new Size(0, 0); /** * Holds the cursors svg element when the cursor is attached to the field. @@ -139,14 +150,14 @@ const Field = function(value, opt_validator, opt_config) { /** * Mouse down event listener data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseDownWrapper_ = null; /** * Constants associated with the source block's renderer. - * @type {Blockly.blockRendering.ConstantProvider} + * @type {ConstantProvider} * @protected */ this.constants_ = null; @@ -185,7 +196,7 @@ Field.prototype.maxDisplayLength = 50; /** * Block this field is attached to. Starts as null, then set in init. - * @type {Blockly.Block} + * @type {Block} * @protected */ Field.prototype.sourceBlock_ = null; @@ -270,7 +281,7 @@ Field.prototype.SERIALIZABLE = false; Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { - tooltip = Blockly.utils.replaceMessageReferences( + tooltip = replaceMessageReferences( config['tooltip']); } tooltip && this.setTooltip(tooltip); @@ -281,7 +292,7 @@ Field.prototype.configure_ = function(config) { /** * Attach this field to a block. - * @param {!Blockly.Block} block The block containing this field. + * @param {!Block} block The block containing this field. */ Field.prototype.setSourceBlock = function(block) { if (this.sourceBlock_) { @@ -292,7 +303,7 @@ Field.prototype.setSourceBlock = function(block) { /** * Get the renderer constant provider. - * @return {?Blockly.blockRendering.ConstantProvider} The renderer constant + * @return {?ConstantProvider} The renderer constant * provider. */ Field.prototype.getConstants = function() { @@ -305,7 +316,7 @@ Field.prototype.getConstants = function() { /** * Get the block this field is attached to. - * @return {Blockly.Block} The block containing this field. + * @return {Block} The block containing this field. */ Field.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -321,12 +332,12 @@ Field.prototype.init = function() { // Field has already been initialized once. return; } - this.fieldGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {}, null); + this.fieldGroup_ = createSvgElement( + Svg.G, {}, null); if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } - const sourceBlockSvg = /** @type {!Blockly.BlockSvg} **/ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!BlockSvg} **/ (this.sourceBlock_); sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_); this.initView(); this.updateEditable(); @@ -359,8 +370,8 @@ Field.prototype.initModel = function() { * @protected */ Field.prototype.createBorderRect_ = function() { - this.borderRect_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, { + this.borderRect_ = createSvgElement( + Svg.RECT, { 'rx': this.getConstants().FIELD_BORDER_RECT_RADIUS, 'ry': this.getConstants().FIELD_BORDER_RECT_RADIUS, 'x': 0, @@ -378,8 +389,8 @@ Field.prototype.createBorderRect_ = function() { * @protected */ Field.prototype.createTextElement_ = function() { - this.textElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + this.textElement_ = createSvgElement( + Svg.TEXT, { 'class': 'blocklyText', }, this.fieldGroup_); if (this.getConstants().FIELD_TEXT_BASELINE_CENTER) { @@ -395,8 +406,8 @@ Field.prototype.createTextElement_ = function() { * @protected */ Field.prototype.bindEvents_ = function() { - Blockly.Tooltip.bindMouseEvents(this.getClickTarget_()); - this.mouseDownWrapper_ = Blockly.browserEvents.conditionalBind( + Tooltip.bindMouseEvents(this.getClickTarget_()); + this.mouseDownWrapper_ = conditionalBind( this.getClickTarget_(), 'mousedown', this, this.onMouseDown_); }; @@ -428,15 +439,15 @@ Field.prototype.toXml = function(fieldElement) { * @package */ Field.prototype.dispose = function() { - Blockly.DropDownDiv.hideIfOwner(this); - Blockly.WidgetDiv.hideIfOwner(this); - Blockly.Tooltip.unbindMouseEvents(this.getClickTarget_()); + DropDownDiv.hideIfOwner(this); + WidgetDiv.hideIfOwner(this); + Tooltip.unbindMouseEvents(this.getClickTarget_()); if (this.mouseDownWrapper_) { - Blockly.browserEvents.unbind(this.mouseDownWrapper_); + unbind(this.mouseDownWrapper_); } - Blockly.utils.dom.removeNode(this.fieldGroup_); + removeNode(this.fieldGroup_); this.disposed = true; }; @@ -450,12 +461,12 @@ Field.prototype.updateEditable = function() { return; } if (this.enabled_ && this.sourceBlock_.isEditable()) { - Blockly.utils.dom.addClass(group, 'blocklyEditableText'); - Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText'); + addClass(group, 'blocklyEditableText'); + removeClass(group, 'blocklyNonEditableText'); group.style.cursor = this.CURSOR; } else { - Blockly.utils.dom.addClass(group, 'blocklyNonEditableText'); - Blockly.utils.dom.removeClass(group, 'blocklyEditableText'); + addClass(group, 'blocklyNonEditableText'); + removeClass(group, 'blocklyEditableText'); group.style.cursor = ''; } }; @@ -631,7 +642,7 @@ Field.prototype.updateSize_ = function(opt_margin) { let contentWidth = 0; if (this.textElement_) { - contentWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + contentWidth = getFastTextWidth(this.textElement_, constants.FIELD_TEXT_FONTSIZE, constants.FIELD_TEXT_FONTWEIGHT, constants.FIELD_TEXT_FONTFAMILY); @@ -690,11 +701,11 @@ Field.prototype.positionBorderRect_ = function() { * Returns the height and width of the field. * * This should *in general* be the only place render_ gets called from. - * @return {!Blockly.utils.Size} Height and width. + * @return {!Size} Height and width. */ Field.prototype.getSize = function() { if (!this.isVisible()) { - return new Blockly.utils.Size(0, 0); + return new Size(0, 0); } if (this.isDirty_) { @@ -713,7 +724,7 @@ Field.prototype.getSize = function() { /** * Returns the bounding box of the rendered field, accounting for workspace * scaling. - * @return {!Blockly.utils.Rect} An object with top, bottom, left, and right in + * @return {!Rect} An object with top, bottom, left, and right in * pixels relative to the top left corner of the page (window coordinates). * @package */ @@ -729,13 +740,13 @@ Field.prototype.getScaledBBox = function() { scaledWidth = bBox.width * scale; scaledHeight = bBox.height * scale; - if (Blockly.utils.userAgent.GECKO) { + if (userAgent.GECKO) { xy.x += 1.5 * scale; xy.y += 1.5 * scale; scaledWidth += 1 * scale; scaledHeight += 1 * scale; } else { - if (!Blockly.utils.userAgent.EDGE && !Blockly.utils.userAgent.IE) { + if (!userAgent.EDGE && !userAgent.IE) { xy.x -= 0.5 * scale; xy.y -= 0.5 * scale; } @@ -744,11 +755,11 @@ Field.prototype.getScaledBBox = function() { } } else { const bBox = this.borderRect_.getBoundingClientRect(); - xy = Blockly.utils.style.getPageOffset(this.borderRect_); + xy = getPageOffset(this.borderRect_); scaledWidth = bBox.width; scaledHeight = bBox.height; } - return new Blockly.utils.Rect( + return new Rect( xy.y, xy.y + scaledHeight, xy.x, @@ -867,8 +878,8 @@ Field.prototype.setValue = function(newValue) { return; } - if (source && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + if (source && Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( source, 'field', this.name || null, oldValue, newValue)); } this.doValueUpdate_(newValue); @@ -961,7 +972,7 @@ Field.prototype.onMouseDown_ = function(e) { /** * Sets the tooltip for this field. - * @param {?Blockly.Tooltip.TipInfo} newTip The + * @param {?Tooltip.TipInfo} newTip The * text for the tooltip, a function that returns the text for the tooltip, a * parent object whose tooltip will be used, or null to display the tooltip * of the parent block. To not display a tooltip pass the empty string. @@ -986,10 +997,10 @@ Field.prototype.setTooltip = function(newTip) { Field.prototype.getTooltip = function() { const clickTarget = this.getClickTarget_(); if (clickTarget) { - return Blockly.Tooltip.getTooltipOfObject(clickTarget); + return Tooltip.getTooltipOfObject(clickTarget); } // Field has not been initialized yet. Return stashed this.tooltip_ value. - return Blockly.Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); + return Tooltip.getTooltipOfObject({tooltip: this.tooltip_}); }; /** @@ -1006,11 +1017,11 @@ Field.prototype.getClickTarget_ = function() { /** * Return the absolute coordinates of the top-left corner of this field. * The origin (0,0) is the top-left corner of the page body. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. * @protected */ Field.prototype.getAbsoluteXY_ = function() { - return Blockly.utils.style.getPageOffset( + return getPageOffset( /** @type {!SVGRectElement} */ (this.getClickTarget_())); }; @@ -1028,7 +1039,7 @@ Field.prototype.referencesVariables = function() { /** * Search through the list of inputs and their fields in order to find the * parent input of a field. - * @return {Blockly.Input} The input that the field belongs to. + * @return {Input} The input that the field belongs to. * @package */ Field.prototype.getParentInput = function() { @@ -1067,7 +1078,7 @@ Field.prototype.isTabNavigable = function() { /** * Handles the given keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ @@ -1113,13 +1124,13 @@ Field.prototype.setMarkerSvg = function(markerSvg) { */ Field.prototype.updateMarkers_ = function() { const workspace = - /** @type {!Blockly.WorkspaceSvg} */ (this.sourceBlock_.workspace); + /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); } if (workspace.keyboardAccessibilityMode && this.markerSvg_) { // TODO(#4592): Update all markers on the field. - workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw(); + workspace.getMarker(MarkerManager.LOCAL_MARKER).draw(); } }; From edcfc04da15db66184f8ace8f3f2ce026b7c31c2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 11:45:32 -0700 Subject: [PATCH 204/833] clang-format core/field.js --- core/field.js | 74 +++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/core/field.js b/core/field.js index 37352c64e..926e62008 100644 --- a/core/field.js +++ b/core/field.js @@ -281,8 +281,7 @@ Field.prototype.SERIALIZABLE = false; Field.prototype.configure_ = function(config) { let tooltip = config['tooltip']; if (typeof tooltip == 'string') { - tooltip = replaceMessageReferences( - config['tooltip']); + tooltip = replaceMessageReferences(config['tooltip']); } tooltip && this.setTooltip(tooltip); @@ -332,8 +331,7 @@ Field.prototype.init = function() { // Field has already been initialized once. return; } - this.fieldGroup_ = createSvgElement( - Svg.G, {}, null); + this.fieldGroup_ = createSvgElement(Svg.G, {}, null); if (!this.isVisible()) { this.fieldGroup_.style.display = 'none'; } @@ -360,8 +358,7 @@ Field.prototype.initView = function() { * No-op by default. * @package */ -Field.prototype.initModel = function() { -}; +Field.prototype.initModel = function() {}; /** * Create a field border rect element. Not to be overridden by subclasses. @@ -379,7 +376,8 @@ Field.prototype.createBorderRect_ = function() { 'height': this.size_.height, 'width': this.size_.width, 'class': 'blocklyFieldRect' - }, this.fieldGroup_); + }, + this.fieldGroup_); }; /** @@ -392,7 +390,8 @@ Field.prototype.createTextElement_ = function() { this.textElement_ = createSvgElement( Svg.TEXT, { 'class': 'blocklyText', - }, this.fieldGroup_); + }, + this.fieldGroup_); if (this.getConstants().FIELD_TEXT_BASELINE_CENTER) { this.textElement_.setAttribute('dominant-baseline', 'central'); } @@ -523,9 +522,10 @@ Field.prototype.isSerializable = function() { if (this.SERIALIZABLE) { isSerializable = true; } else if (this.EDITABLE) { - console.warn('Detected an editable field that was not serializable.' + - ' Please define SERIALIZABLE property as true on all editable custom' + - ' fields. Proceeding with serialization.'); + console.warn( + 'Detected an editable field that was not serializable.' + + ' Please define SERIALIZABLE property as true on all editable custom' + + ' fields. Proceeding with serialization.'); isSerializable = true; } } @@ -635,17 +635,17 @@ Field.prototype.showEditor = function(opt_e) { */ Field.prototype.updateSize_ = function(opt_margin) { const constants = this.getConstants(); - const xOffset = opt_margin != undefined ? opt_margin : + const xOffset = opt_margin != undefined ? + opt_margin : (this.borderRect_ ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0); let totalWidth = xOffset * 2; let totalHeight = constants.FIELD_TEXT_HEIGHT; let contentWidth = 0; if (this.textElement_) { - contentWidth = getFastTextWidth(this.textElement_, - constants.FIELD_TEXT_FONTSIZE, - constants.FIELD_TEXT_FONTWEIGHT, - constants.FIELD_TEXT_FONTFAMILY); + contentWidth = getFastTextWidth( + this.textElement_, constants.FIELD_TEXT_FONTSIZE, + constants.FIELD_TEXT_FONTWEIGHT, constants.FIELD_TEXT_FONTFAMILY); totalWidth += contentWidth; } if (this.borderRect_) { @@ -673,11 +673,15 @@ Field.prototype.positionTextElement_ = function(xOffset, contentWidth) { const constants = this.getConstants(); const halfHeight = this.size_.height / 2; - this.textElement_.setAttribute('x', this.sourceBlock_.RTL ? - this.size_.width - contentWidth - xOffset : xOffset); - this.textElement_.setAttribute('y', constants.FIELD_TEXT_BASELINE_CENTER ? - halfHeight : halfHeight - constants.FIELD_TEXT_HEIGHT / 2 + - constants.FIELD_TEXT_BASELINE); + this.textElement_.setAttribute( + 'x', + this.sourceBlock_.RTL ? this.size_.width - contentWidth - xOffset : + xOffset); + this.textElement_.setAttribute( + 'y', + constants.FIELD_TEXT_BASELINE_CENTER ? halfHeight : + halfHeight - + constants.FIELD_TEXT_HEIGHT / 2 + constants.FIELD_TEXT_BASELINE); }; /** @@ -690,10 +694,10 @@ Field.prototype.positionBorderRect_ = function() { } this.borderRect_.setAttribute('width', this.size_.width); this.borderRect_.setAttribute('height', this.size_.height); - this.borderRect_.setAttribute('rx', - this.getConstants().FIELD_BORDER_RECT_RADIUS); - this.borderRect_.setAttribute('ry', - this.getConstants().FIELD_BORDER_RECT_RADIUS); + this.borderRect_.setAttribute( + 'rx', this.getConstants().FIELD_BORDER_RECT_RADIUS); + this.borderRect_.setAttribute( + 'ry', this.getConstants().FIELD_BORDER_RECT_RADIUS); }; @@ -714,8 +718,9 @@ Field.prototype.getSize = function() { } else if (this.visible_ && this.size_.width == 0) { // If the field is not visible the width will be 0 as well, one of the // problems with the old system. - console.warn('Deprecated use of setting size_.width to 0 to rerender a' + - ' field. Set field.isDirty_ to true instead.'); + console.warn( + 'Deprecated use of setting size_.width to 0 to rerender a' + + ' field. Set field.isDirty_ to true instead.'); this.render_(); } return this.size_; @@ -759,12 +764,7 @@ Field.prototype.getScaledBBox = function() { scaledWidth = bBox.width; scaledHeight = bBox.height; } - return new Rect( - xy.y, - xy.y + scaledHeight, - xy.x, - xy.x + scaledWidth - ); + return new Rect(xy.y, xy.y + scaledHeight, xy.x, xy.x + scaledWidth); }; /** @@ -896,8 +896,7 @@ Field.prototype.setValue = function(newValue) { * @return {*} New value, or an Error object. * @private */ -Field.prototype.processValidation_ = function(newValue, - validatedValue) { +Field.prototype.processValidation_ = function(newValue, validatedValue) { if (validatedValue === null) { this.doValueInvalid_(newValue); if (this.isDirty_) { @@ -1078,7 +1077,8 @@ Field.prototype.isTabNavigable = function() { /** * Handles the given keyboard shortcut. - * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. * @public */ @@ -1124,7 +1124,7 @@ Field.prototype.setMarkerSvg = function(markerSvg) { */ Field.prototype.updateMarkers_ = function() { const workspace = - /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); + /** @type {!WorkspaceSvg} */ (this.sourceBlock_.workspace); if (workspace.keyboardAccessibilityMode && this.cursorSvg_) { workspace.getCursor().draw(); } From 5f305041a9de4108a00535060cb1df3b54a8aa34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 12:57:19 -0700 Subject: [PATCH 205/833] Migrate core/field_colour.js to ES6 const/let --- core/field_colour.js | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 17d593f0e..632bf6965 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -233,7 +233,7 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { * @return {string} Text representing the value of this field. */ Blockly.FieldColour.prototype.getText = function() { - var colour = /** @type {string} */ (this.value_); + let colour = /** @type {string} */ (this.value_); // Try to use #rgb format if possible, rather than #rrggbb. if (/^#(.)\1(.)\2(.)\3$/.test(colour)) { colour = '#' + colour[1] + colour[3] + colour[5]; @@ -339,8 +339,8 @@ Blockly.FieldColour.prototype.showEditor_ = function() { * @private */ Blockly.FieldColour.prototype.onClick_ = function(e) { - var cell = /** @type {!Element} */ (e.target); - var colour = cell && cell.label; + const cell = /** @type {!Element} */ (e.target); + const colour = cell && cell.label; if (colour !== null) { this.setValue(colour); Blockly.DropDownDiv.hideIfOwner(this); @@ -354,7 +354,7 @@ Blockly.FieldColour.prototype.onClick_ = function(e) { * @private */ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { - var handled = false; + let handled = false; if (e.keyCode === Blockly.utils.KeyCodes.UP) { this.moveHighlightBy_(0, -1); handled = true; @@ -369,9 +369,9 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { handled = true; } else if (e.keyCode === Blockly.utils.KeyCodes.ENTER) { // Select the highlighted colour. - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { - var colour = highlighted && highlighted.label; + const colour = highlighted && highlighted.label; if (colour !== null) { this.setValue(colour); } @@ -391,12 +391,12 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { * @private */ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { - var colours = this.colours_ || Blockly.FieldColour.COLOURS; - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const colours = this.colours_ || Blockly.FieldColour.COLOURS; + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; // Get the current x and y coordinates - var x = this.highlightedIndex_ % columns; - var y = Math.floor(this.highlightedIndex_ / columns); + let x = this.highlightedIndex_ % columns; + let y = Math.floor(this.highlightedIndex_ / columns); // Add the offset x += dx; @@ -434,8 +434,8 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } // Move the highlight to the new coordinates. - var cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); - var index = (y * columns) + x; + const cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); + const index = (y * columns) + x; this.setHighlightedCell_(cell, index); }; @@ -445,8 +445,8 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { * @private */ Blockly.FieldColour.prototype.onMouseMove_ = function(e) { - var cell = /** @type {!Element} */ (e.target); - var index = cell && Number(cell.getAttribute('data-index')); + const cell = /** @type {!Element} */ (e.target); + const index = cell && Number(cell.getAttribute('data-index')); if (index !== null && index !== this.highlightedIndex_) { this.setHighlightedCell_(cell, index); } @@ -467,7 +467,7 @@ Blockly.FieldColour.prototype.onMouseEnter_ = function() { */ Blockly.FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); } @@ -479,14 +479,14 @@ Blockly.FieldColour.prototype.onMouseLeave_ = function() { * @private */ Blockly.FieldColour.prototype.getHighlighted_ = function() { - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; - var x = this.highlightedIndex_ % columns; - var y = Math.floor(this.highlightedIndex_ / columns); - var row = this.picker_.childNodes[y]; + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const x = this.highlightedIndex_ % columns; + const y = Math.floor(this.highlightedIndex_ / columns); + const row = this.picker_.childNodes[y]; if (!row) { return null; } - var col = /** @type {HTMLElement} */ (row.childNodes[x]); + const col = /** @type {HTMLElement} */ (row.childNodes[x]); return col; }; @@ -498,7 +498,7 @@ Blockly.FieldColour.prototype.getHighlighted_ = function() { */ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. - var highlighted = this.getHighlighted_(); + const highlighted = this.getHighlighted_(); if (highlighted) { Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); } @@ -517,12 +517,12 @@ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { * @private */ Blockly.FieldColour.prototype.dropdownCreate_ = function() { - var columns = this.columns_ || Blockly.FieldColour.COLUMNS; - var colours = this.colours_ || Blockly.FieldColour.COLOURS; - var titles = this.titles_ || Blockly.FieldColour.TITLES; - var selectedColour = this.getValue(); + const columns = this.columns_ || Blockly.FieldColour.COLUMNS; + const colours = this.colours_ || Blockly.FieldColour.COLOURS; + const titles = this.titles_ || Blockly.FieldColour.TITLES; + const selectedColour = this.getValue(); // Create the palette. - var table = document.createElement('table'); + const table = document.createElement('table'); table.className = 'blocklyColourTable'; table.tabIndex = 0; table.dir = 'ltr'; @@ -532,14 +532,14 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { Math.floor(colours.length / columns)); Blockly.utils.aria.setState(table, Blockly.utils.aria.State.COLCOUNT, columns); - var row; - for (var i = 0; i < colours.length; i++) { + let row; + for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { row = document.createElement('tr'); Blockly.utils.aria.setRole(row, Blockly.utils.aria.Role.ROW); table.appendChild(row); } - var cell = document.createElement('td'); + const cell = document.createElement('td'); row.appendChild(cell); cell.label = colours[i]; // This becomes the value, if clicked. cell.title = titles[i] || colours[i]; From 03e1725f3244bfbedc9934b2ca339f73cbfcb646 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:00:05 -0700 Subject: [PATCH 206/833] Migrate core/field_colour.js to goog.module --- core/field_colour.js | 99 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 632bf6965..9d342150c 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldColour'); +goog.module('Blockly.FieldColour'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); @@ -41,8 +42,8 @@ goog.require('Blockly.utils.Size'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldColour = function(opt_value, opt_validator, opt_config) { - Blockly.FieldColour.superClass_.constructor.call( +const FieldColour = function(opt_value, opt_validator, opt_config) { + FieldColour.superClass_.constructor.call( this, opt_value, opt_validator, opt_config); /** @@ -94,16 +95,16 @@ Blockly.FieldColour = function(opt_value, opt_validator, opt_config) { */ this.onKeyDownWrapper_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldColour, Blockly.Field); +Blockly.utils.object.inherits(FieldColour, Blockly.Field); /** * Construct a FieldColour from a JSON arg object. * @param {!Object} options A JSON object with options (colour). - * @return {!Blockly.FieldColour} The new field instance. + * @return {!FieldColour} The new field instance. * @package * @nocollapse */ -Blockly.FieldColour.fromJson = function(options) { +FieldColour.fromJson = function(options) { // `this` might be a subclass of FieldColour if that class doesn't override // the static fromJson method. return new this(options['colour'], undefined, options); @@ -114,12 +115,12 @@ Blockly.FieldColour.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldColour.prototype.SERIALIZABLE = true; +FieldColour.prototype.SERIALIZABLE = true; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldColour.prototype.CURSOR = 'default'; +FieldColour.prototype.CURSOR = 'default'; /** * Used to tell if the field needs to be rendered the next time the block is @@ -128,21 +129,21 @@ Blockly.FieldColour.prototype.CURSOR = 'default'; * @type {boolean} * @protected */ -Blockly.FieldColour.prototype.isDirty_ = false; +FieldColour.prototype.isDirty_ = false; /** * Array of colours used by this field. If null, use the global list. * @type {Array} * @private */ -Blockly.FieldColour.prototype.colours_ = null; +FieldColour.prototype.colours_ = null; /** * Array of colour tooltips used by this field. If null, use the global list. * @type {Array} * @private */ -Blockly.FieldColour.prototype.titles_ = null; +FieldColour.prototype.titles_ = null; /** * Number of colour columns used by this field. If 0, use the global setting. @@ -150,7 +151,7 @@ Blockly.FieldColour.prototype.titles_ = null; * @type {number} * @private */ -Blockly.FieldColour.prototype.columns_ = 0; +FieldColour.prototype.columns_ = 0; /** * Configure the field based on the given map of options. @@ -158,8 +159,8 @@ Blockly.FieldColour.prototype.columns_ = 0; * @protected * @override */ -Blockly.FieldColour.prototype.configure_ = function(config) { - Blockly.FieldColour.superClass_.configure_.call(this, config); +FieldColour.prototype.configure_ = function(config) { + FieldColour.superClass_.configure_.call(this, config); if (config['colourOptions']) { this.colours_ = config['colourOptions']; this.titles_ = config['colourTitles']; @@ -173,7 +174,7 @@ Blockly.FieldColour.prototype.configure_ = function(config) { * Create the block UI for this colour field. * @package */ -Blockly.FieldColour.prototype.initView = function() { +FieldColour.prototype.initView = function() { this.size_ = new Blockly.utils.Size( this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH, this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT); @@ -188,7 +189,7 @@ Blockly.FieldColour.prototype.initView = function() { /** * @override */ -Blockly.FieldColour.prototype.applyColour = function() { +FieldColour.prototype.applyColour = function() { if (!this.getConstants().FIELD_COLOUR_FULL_BLOCK) { if (this.borderRect_) { this.borderRect_.style.fill = /** @type {string} */ (this.getValue()); @@ -205,7 +206,7 @@ Blockly.FieldColour.prototype.applyColour = function() { * @return {?string} A valid colour, or null if invalid. * @protected */ -Blockly.FieldColour.prototype.doClassValidation_ = function(opt_newValue) { +FieldColour.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } @@ -218,7 +219,7 @@ Blockly.FieldColour.prototype.doClassValidation_ = function(opt_newValue) { * that this is a colour in '#rrggbb' format. * @protected */ -Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { +FieldColour.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.borderRect_) { this.borderRect_.style.fill = /** @type {string} */ (newValue); @@ -232,7 +233,7 @@ Blockly.FieldColour.prototype.doValueUpdate_ = function(newValue) { * Get the text for this field. Used when the block is collapsed. * @return {string} Text representing the value of this field. */ -Blockly.FieldColour.prototype.getText = function() { +FieldColour.prototype.getText = function() { let colour = /** @type {string} */ (this.value_); // Try to use #rgb format if possible, rather than #rrggbb. if (/^#(.)\1(.)\2(.)\3$/.test(colour)) { @@ -247,7 +248,7 @@ Blockly.FieldColour.prototype.getText = function() { * All colour pickers use this unless overridden with setColours. * @type {!Array} */ -Blockly.FieldColour.COLOURS = [ +FieldColour.COLOURS = [ // grays '#ffffff', '#cccccc', '#c0c0c0', '#999999', '#666666', '#333333', '#000000', // reds @@ -275,7 +276,7 @@ Blockly.FieldColour.COLOURS = [ * @type {*} * @protected */ -Blockly.FieldColour.prototype.DEFAULT_VALUE = Blockly.FieldColour.COLOURS[0]; +FieldColour.prototype.DEFAULT_VALUE = FieldColour.COLOURS[0]; /** * An array of tooltip strings for the palette. If not the same length as @@ -283,23 +284,23 @@ Blockly.FieldColour.prototype.DEFAULT_VALUE = Blockly.FieldColour.COLOURS[0]; * All colour pickers use this unless overridden with setColours. * @type {!Array} */ -Blockly.FieldColour.TITLES = []; +FieldColour.TITLES = []; /** * Number of columns in the palette. * All colour pickers use this unless overridden with setColumns. */ -Blockly.FieldColour.COLUMNS = 7; +FieldColour.COLUMNS = 7; /** * Set a custom colour grid for this field. * @param {Array} colours Array of colours for this block, - * or null to use default (Blockly.FieldColour.COLOURS). + * or null to use default (FieldColour.COLOURS). * @param {Array=} opt_titles Optional array of colour tooltips, - * or null to use default (Blockly.FieldColour.TITLES). - * @return {!Blockly.FieldColour} Returns itself (for method chaining). + * or null to use default (FieldColour.TITLES). + * @return {!FieldColour} Returns itself (for method chaining). */ -Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) { +FieldColour.prototype.setColours = function(colours, opt_titles) { this.colours_ = colours; if (opt_titles) { this.titles_ = opt_titles; @@ -310,10 +311,10 @@ Blockly.FieldColour.prototype.setColours = function(colours, opt_titles) { /** * Set a custom grid size for this field. * @param {number} columns Number of columns for this block, - * or 0 to use default (Blockly.FieldColour.COLUMNS). - * @return {!Blockly.FieldColour} Returns itself (for method chaining). + * or 0 to use default (FieldColour.COLUMNS). + * @return {!FieldColour} Returns itself (for method chaining). */ -Blockly.FieldColour.prototype.setColumns = function(columns) { +FieldColour.prototype.setColumns = function(columns) { this.columns_ = columns; return this; }; @@ -322,7 +323,7 @@ Blockly.FieldColour.prototype.setColumns = function(columns) { * Create and show the colour field's editor. * @protected */ -Blockly.FieldColour.prototype.showEditor_ = function() { +FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); Blockly.DropDownDiv.getContentDiv().appendChild(this.picker_); @@ -338,7 +339,7 @@ Blockly.FieldColour.prototype.showEditor_ = function() { * @param {!MouseEvent} e Mouse event. * @private */ -Blockly.FieldColour.prototype.onClick_ = function(e) { +FieldColour.prototype.onClick_ = function(e) { const cell = /** @type {!Element} */ (e.target); const colour = cell && cell.label; if (colour !== null) { @@ -353,7 +354,7 @@ Blockly.FieldColour.prototype.onClick_ = function(e) { * @param {!KeyboardEvent} e Keyboard event. * @private */ -Blockly.FieldColour.prototype.onKeyDown_ = function(e) { +FieldColour.prototype.onKeyDown_ = function(e) { let handled = false; if (e.keyCode === Blockly.utils.KeyCodes.UP) { this.moveHighlightBy_(0, -1); @@ -390,9 +391,9 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) { * @param {number} dy Change of y * @private */ -Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { - const colours = this.colours_ || Blockly.FieldColour.COLOURS; - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; +FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { + const colours = this.colours_ || FieldColour.COLOURS; + const columns = this.columns_ || FieldColour.COLUMNS; // Get the current x and y coordinates let x = this.highlightedIndex_ % columns; @@ -444,7 +445,7 @@ Blockly.FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { * @param {!MouseEvent} e Mouse event. * @private */ -Blockly.FieldColour.prototype.onMouseMove_ = function(e) { +FieldColour.prototype.onMouseMove_ = function(e) { const cell = /** @type {!Element} */ (e.target); const index = cell && Number(cell.getAttribute('data-index')); if (index !== null && index !== this.highlightedIndex_) { @@ -456,7 +457,7 @@ Blockly.FieldColour.prototype.onMouseMove_ = function(e) { * Handle a mouse enter event. Focus the picker. * @private */ -Blockly.FieldColour.prototype.onMouseEnter_ = function() { +FieldColour.prototype.onMouseEnter_ = function() { this.picker_.focus({preventScroll:true}); }; @@ -465,7 +466,7 @@ Blockly.FieldColour.prototype.onMouseEnter_ = function() { * the currently highlighted colour. * @private */ -Blockly.FieldColour.prototype.onMouseLeave_ = function() { +FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); const highlighted = this.getHighlighted_(); if (highlighted) { @@ -478,8 +479,8 @@ Blockly.FieldColour.prototype.onMouseLeave_ = function() { * @return {?HTMLElement} Highlighted item (null if none). * @private */ -Blockly.FieldColour.prototype.getHighlighted_ = function() { - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; +FieldColour.prototype.getHighlighted_ = function() { + const columns = this.columns_ || FieldColour.COLUMNS; const x = this.highlightedIndex_ % columns; const y = Math.floor(this.highlightedIndex_ / columns); const row = this.picker_.childNodes[y]; @@ -496,7 +497,7 @@ Blockly.FieldColour.prototype.getHighlighted_ = function() { * @param {number} index the index of the new cell * @private */ -Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { +FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. const highlighted = this.getHighlighted_(); if (highlighted) { @@ -516,10 +517,10 @@ Blockly.FieldColour.prototype.setHighlightedCell_ = function(cell, index) { * Create a colour picker dropdown editor. * @private */ -Blockly.FieldColour.prototype.dropdownCreate_ = function() { - const columns = this.columns_ || Blockly.FieldColour.COLUMNS; - const colours = this.colours_ || Blockly.FieldColour.COLOURS; - const titles = this.titles_ || Blockly.FieldColour.TITLES; +FieldColour.prototype.dropdownCreate_ = function() { + const columns = this.columns_ || FieldColour.COLUMNS; + const colours = this.colours_ || FieldColour.COLOURS; + const titles = this.titles_ || FieldColour.TITLES; const selectedColour = this.getValue(); // Create the palette. const table = document.createElement('table'); @@ -576,7 +577,7 @@ Blockly.FieldColour.prototype.dropdownCreate_ = function() { * Disposes of events and DOM-references belonging to the colour editor. * @private */ -Blockly.FieldColour.prototype.dropdownDispose_ = function() { +FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { Blockly.browserEvents.unbind(this.onClickWrapper_); this.onClickWrapper_ = null; @@ -637,4 +638,6 @@ Blockly.Css.register([ /* eslint-enable indent */ ]); -Blockly.fieldRegistry.register('field_colour', Blockly.FieldColour); +Blockly.fieldRegistry.register('field_colour', FieldColour); + +exports = FieldColour; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..0e33cec9b 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -51,7 +51,7 @@ goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); From ba30031d366e2b7f9af77f1be01c433487d76842 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:13:31 -0700 Subject: [PATCH 207/833] Migrate core/field_colour.js to named requires --- core/field_colour.js | 119 ++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 9d342150c..879c340bc 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -13,20 +13,21 @@ goog.module('Blockly.FieldColour'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Css'); -goog.require('Blockly.DropDownDiv'); +const Css = goog.require('Blockly.Css'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Field = goog.require('Blockly.Field'); +const IdGenerator = goog.require('Blockly.utils.IdGenerator'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Size = goog.require('Blockly.utils.Size'); +const aria = goog.require('Blockly.utils.aria'); +const colour = goog.require('Blockly.utils.colour'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {addClass, removeClass} = goog.require('Blockly.utils.dom'); +/* eslint-disable-next-line no-unused-vars */ +const {conditionalBind, unbind, Data} = goog.require('Blockly.browserEvents'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.IdGenerator'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); /** @@ -35,11 +36,11 @@ goog.require('Blockly.utils.Size'); * '#rrggbb' format. Defaults to the first value in the default colour array. * @param {Function=} opt_validator A function that is called to validate * changes to the field's value. Takes in a colour string & returns a - * validated colour string ('#rrggbb' format), or null to abort the change. + * validated colour string ('#rrggbb' format), or null to abort the change.Blockly. * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldColour = function(opt_value, opt_validator, opt_config) { @@ -62,40 +63,40 @@ const FieldColour = function(opt_value, opt_validator, opt_config) { /** * Mouse click event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onClickWrapper_ = null; /** * Mouse move event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseMoveWrapper_ = null; /** * Mouse enter event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseEnterWrapper_ = null; /** * Mouse leave event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onMouseLeaveWrapper_ = null; /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onKeyDownWrapper_ = null; }; -Blockly.utils.object.inherits(FieldColour, Blockly.Field); +inherits(FieldColour, Field); /** * Construct a FieldColour from a JSON arg object. @@ -175,7 +176,7 @@ FieldColour.prototype.configure_ = function(config) { * @package */ FieldColour.prototype.initView = function() { - this.size_ = new Blockly.utils.Size( + this.size_ = new Size( this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH, this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT); if (!this.getConstants().FIELD_COLOUR_FULL_BLOCK) { @@ -210,7 +211,7 @@ FieldColour.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } - return Blockly.utils.colour.parse(opt_newValue); + return colour.parse(opt_newValue); }; /** @@ -325,9 +326,9 @@ FieldColour.prototype.setColumns = function(columns) { */ FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); - Blockly.DropDownDiv.getContentDiv().appendChild(this.picker_); + DropDownDiv.getContentDiv().appendChild(this.picker_); - Blockly.DropDownDiv.showPositionedByField( + DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); // Focus so we can start receiving keyboard events. @@ -344,7 +345,7 @@ FieldColour.prototype.onClick_ = function(e) { const colour = cell && cell.label; if (colour !== null) { this.setValue(colour); - Blockly.DropDownDiv.hideIfOwner(this); + DropDownDiv.hideIfOwner(this); } }; @@ -356,19 +357,19 @@ FieldColour.prototype.onClick_ = function(e) { */ FieldColour.prototype.onKeyDown_ = function(e) { let handled = false; - if (e.keyCode === Blockly.utils.KeyCodes.UP) { + if (e.keyCode === KeyCodes.UP) { this.moveHighlightBy_(0, -1); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.DOWN) { + } else if (e.keyCode === KeyCodes.DOWN) { this.moveHighlightBy_(0, 1); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.LEFT) { + } else if (e.keyCode === KeyCodes.LEFT) { this.moveHighlightBy_(-1, 0); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.RIGHT) { + } else if (e.keyCode === KeyCodes.RIGHT) { this.moveHighlightBy_(1, 0); handled = true; - } else if (e.keyCode === Blockly.utils.KeyCodes.ENTER) { + } else if (e.keyCode === KeyCodes.ENTER) { // Select the highlighted colour. const highlighted = this.getHighlighted_(); if (highlighted) { @@ -377,7 +378,7 @@ FieldColour.prototype.onKeyDown_ = function(e) { this.setValue(colour); } } - Blockly.DropDownDiv.hideWithoutAnimation(); + DropDownDiv.hideWithoutAnimation(); handled = true; } if (handled) { @@ -470,7 +471,7 @@ FieldColour.prototype.onMouseLeave_ = function() { this.picker_.blur(); const highlighted = this.getHighlighted_(); if (highlighted) { - Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); + removeClass(highlighted, 'blocklyColourHighlighted'); } }; @@ -501,16 +502,16 @@ FieldColour.prototype.setHighlightedCell_ = function(cell, index) { // Unhighlight the current item. const highlighted = this.getHighlighted_(); if (highlighted) { - Blockly.utils.dom.removeClass(highlighted, 'blocklyColourHighlighted'); + removeClass(highlighted, 'blocklyColourHighlighted'); } // Highlight new item. - Blockly.utils.dom.addClass(cell, 'blocklyColourHighlighted'); + addClass(cell, 'blocklyColourHighlighted'); // Set new highlighted index. this.highlightedIndex_ = index; // Update accessibility roles. - Blockly.utils.aria.setState(/** @type {!Element} */ (this.picker_), - Blockly.utils.aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); + aria.setState(/** @type {!Element} */ (this.picker_), + aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); }; /** @@ -527,30 +528,30 @@ FieldColour.prototype.dropdownCreate_ = function() { table.className = 'blocklyColourTable'; table.tabIndex = 0; table.dir = 'ltr'; - Blockly.utils.aria.setRole(table, Blockly.utils.aria.Role.GRID); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.EXPANDED, true); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.ROWCOUNT, + aria.setRole(table, aria.Role.GRID); + aria.setState(table, aria.State.EXPANDED, true); + aria.setState(table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); - Blockly.utils.aria.setState(table, Blockly.utils.aria.State.COLCOUNT, + aria.setState(table, aria.State.COLCOUNT, columns); let row; for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { row = document.createElement('tr'); - Blockly.utils.aria.setRole(row, Blockly.utils.aria.Role.ROW); + aria.setRole(row, aria.Role.ROW); table.appendChild(row); } const cell = document.createElement('td'); row.appendChild(cell); cell.label = colours[i]; // This becomes the value, if clicked. cell.title = titles[i] || colours[i]; - cell.id = Blockly.utils.IdGenerator.getNextUniqueId(); + cell.id = IdGenerator.getNextUniqueId(); cell.setAttribute('data-index', i); - Blockly.utils.aria.setRole(cell, Blockly.utils.aria.Role.GRIDCELL); - Blockly.utils.aria.setState(cell, - Blockly.utils.aria.State.LABEL, colours[i]); - Blockly.utils.aria.setState(cell, - Blockly.utils.aria.State.SELECTED, colours[i] == selectedColour); + aria.setRole(cell, aria.Role.GRIDCELL); + aria.setState(cell, + aria.State.LABEL, colours[i]); + aria.setState(cell, + aria.State.SELECTED, colours[i] == selectedColour); cell.style.backgroundColor = colours[i]; if (colours[i] == selectedColour) { cell.className = 'blocklyColourSelected'; @@ -559,15 +560,15 @@ FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = Blockly.browserEvents.conditionalBind( + this.onClickWrapper_ = conditionalBind( table, 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseMoveWrapper_ = conditionalBind( table, 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseEnterWrapper_ = conditionalBind( table, 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseLeaveWrapper_ = conditionalBind( table, 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownWrapper_ = conditionalBind( table, 'keydown', this, this.onKeyDown_); this.picker_ = table; @@ -579,23 +580,23 @@ FieldColour.prototype.dropdownCreate_ = function() { */ FieldColour.prototype.dropdownDispose_ = function() { if (this.onClickWrapper_) { - Blockly.browserEvents.unbind(this.onClickWrapper_); + unbind(this.onClickWrapper_); this.onClickWrapper_ = null; } if (this.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); + unbind(this.onMouseMoveWrapper_); this.onMouseMoveWrapper_ = null; } if (this.onMouseEnterWrapper_) { - Blockly.browserEvents.unbind(this.onMouseEnterWrapper_); + unbind(this.onMouseEnterWrapper_); this.onMouseEnterWrapper_ = null; } if (this.onMouseLeaveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseLeaveWrapper_); + unbind(this.onMouseLeaveWrapper_); this.onMouseLeaveWrapper_ = null; } if (this.onKeyDownWrapper_) { - Blockly.browserEvents.unbind(this.onKeyDownWrapper_); + unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } this.picker_ = null; @@ -605,7 +606,7 @@ FieldColour.prototype.dropdownDispose_ = function() { /** * CSS for colour picker. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyColourTable {', 'border-collapse: collapse;', @@ -638,6 +639,6 @@ Blockly.Css.register([ /* eslint-enable indent */ ]); -Blockly.fieldRegistry.register('field_colour', FieldColour); +fieldRegistry.register('field_colour', FieldColour); exports = FieldColour; From 595f3c0802ce404b8d8987c747278acc1c1c339d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:17:10 -0700 Subject: [PATCH 208/833] clang-format core/field_colour.js --- core/field_colour.js | 57 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/core/field_colour.js b/core/field_colour.js index 879c340bc..a3dc0bf72 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -36,9 +36,11 @@ goog.require('Blockly.Events.BlockChange'); * '#rrggbb' format. Defaults to the first value in the default colour array. * @param {Function=} opt_validator A function that is called to validate * changes to the field's value. Takes in a colour string & returns a - * validated colour string ('#rrggbb' format), or null to abort the change.Blockly. + * validated colour string ('#rrggbb' format), or null to abort the + * change.Blockly. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/colour} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -328,11 +330,10 @@ FieldColour.prototype.showEditor_ = function() { this.dropdownCreate_(); DropDownDiv.getContentDiv().appendChild(this.picker_); - DropDownDiv.showPositionedByField( - this, this.dropdownDispose_.bind(this)); + DropDownDiv.showPositionedByField(this, this.dropdownDispose_.bind(this)); // Focus so we can start receiving keyboard events. - this.picker_.focus({preventScroll:true}); + this.picker_.focus({preventScroll: true}); }; /** @@ -416,8 +417,7 @@ FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } else if (dx > 0) { // Move right one grid cell, even in RTL. // Loop to the start of the next row, if there's room. - if (x > columns - 1 && - y < Math.floor(colours.length / columns) - 1) { + if (x > columns - 1 && y < Math.floor(colours.length / columns) - 1) { x = 0; y++; } else if (x > columns - 1) { @@ -436,7 +436,8 @@ FieldColour.prototype.moveHighlightBy_ = function(dx, dy) { } // Move the highlight to the new coordinates. - const cell = /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); + const cell = + /** @type {!Element} */ (this.picker_.childNodes[y].childNodes[x]); const index = (y * columns) + x; this.setHighlightedCell_(cell, index); }; @@ -459,7 +460,7 @@ FieldColour.prototype.onMouseMove_ = function(e) { * @private */ FieldColour.prototype.onMouseEnter_ = function() { - this.picker_.focus({preventScroll:true}); + this.picker_.focus({preventScroll: true}); }; /** @@ -510,8 +511,9 @@ FieldColour.prototype.setHighlightedCell_ = function(cell, index) { this.highlightedIndex_ = index; // Update accessibility roles. - aria.setState(/** @type {!Element} */ (this.picker_), - aria.State.ACTIVEDESCENDANT, cell.getAttribute('id')); + aria.setState( + /** @type {!Element} */ (this.picker_), aria.State.ACTIVEDESCENDANT, + cell.getAttribute('id')); }; /** @@ -530,10 +532,9 @@ FieldColour.prototype.dropdownCreate_ = function() { table.dir = 'ltr'; aria.setRole(table, aria.Role.GRID); aria.setState(table, aria.State.EXPANDED, true); - aria.setState(table, aria.State.ROWCOUNT, - Math.floor(colours.length / columns)); - aria.setState(table, aria.State.COLCOUNT, - columns); + aria.setState( + table, aria.State.ROWCOUNT, Math.floor(colours.length / columns)); + aria.setState(table, aria.State.COLCOUNT, columns); let row; for (let i = 0; i < colours.length; i++) { if (i % columns == 0) { @@ -548,10 +549,8 @@ FieldColour.prototype.dropdownCreate_ = function() { cell.id = IdGenerator.getNextUniqueId(); cell.setAttribute('data-index', i); aria.setRole(cell, aria.Role.GRIDCELL); - aria.setState(cell, - aria.State.LABEL, colours[i]); - aria.setState(cell, - aria.State.SELECTED, colours[i] == selectedColour); + aria.setState(cell, aria.State.LABEL, colours[i]); + aria.setState(cell, aria.State.SELECTED, colours[i] == selectedColour); cell.style.backgroundColor = colours[i]; if (colours[i] == selectedColour) { cell.className = 'blocklyColourSelected'; @@ -560,16 +559,16 @@ FieldColour.prototype.dropdownCreate_ = function() { } // Configure event handler on the table to listen for any event in a cell. - this.onClickWrapper_ = conditionalBind( - table, 'click', this, this.onClick_, true); - this.onMouseMoveWrapper_ = conditionalBind( - table, 'mousemove', this, this.onMouseMove_, true); - this.onMouseEnterWrapper_ = conditionalBind( - table, 'mouseenter', this, this.onMouseEnter_, true); - this.onMouseLeaveWrapper_ = conditionalBind( - table, 'mouseleave', this, this.onMouseLeave_, true); - this.onKeyDownWrapper_ = conditionalBind( - table, 'keydown', this, this.onKeyDown_); + this.onClickWrapper_ = + conditionalBind(table, 'click', this, this.onClick_, true); + this.onMouseMoveWrapper_ = + conditionalBind(table, 'mousemove', this, this.onMouseMove_, true); + this.onMouseEnterWrapper_ = + conditionalBind(table, 'mouseenter', this, this.onMouseEnter_, true); + this.onMouseLeaveWrapper_ = + conditionalBind(table, 'mouseleave', this, this.onMouseLeave_, true); + this.onKeyDownWrapper_ = + conditionalBind(table, 'keydown', this, this.onKeyDown_); this.picker_ = table; }; From 0d248583c8e542cf979a1e4e14117a4b94113bb1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:26:52 -0700 Subject: [PATCH 209/833] Migrate core/field_dropdown.js to ES6 const/let --- core/field_dropdown.js | 102 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5dad752d8..c1554928d 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -299,14 +299,14 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { } // Element gets created in render. this.menu_.render(Blockly.DropDownDiv.getContentDiv()); - var menuElement = /** @type {!Element} */ (this.menu_.getElement()); + const menuElement = /** @type {!Element} */ (this.menu_.getElement()); Blockly.utils.dom.addClass(menuElement, 'blocklyDropdownMenu'); if (this.getConstants().FIELD_DROPDOWN_COLOURED_DIV) { - var primaryColour = (this.sourceBlock_.isShadow()) ? + const primaryColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().getColour() : this.sourceBlock_.getColour(); - var borderColour = (this.sourceBlock_.isShadow()) ? + const borderColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; Blockly.DropDownDiv.setColour(primaryColour, borderColour); @@ -332,23 +332,23 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { * @private */ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { - var menu = new Blockly.Menu(); + const menu = new Blockly.Menu(); menu.setRole(Blockly.utils.aria.Role.LISTBOX); this.menu_ = menu; - var options = this.getOptions(false); + const options = this.getOptions(false); this.selectedMenuItem_ = null; - for (var i = 0; i < options.length; i++) { - var content = options[i][0]; // Human-readable text or image. - var value = options[i][1]; // Language-neutral value. + for (let i = 0; i < options.length; i++) { + let content = options[i][0]; // Human-readable text or image. + const value = options[i][1]; // Language-neutral value. if (typeof content == 'object') { // An image, not text. - var image = new Image(content['width'], content['height']); + const image = new Image(content['width'], content['height']); image.src = content['src']; image.alt = content['alt'] || ''; content = image; } - var menuItem = new Blockly.MenuItem(content, value); + const menuItem = new Blockly.MenuItem(content, value); menuItem.setRole(Blockly.utils.aria.Role.OPTION); menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setCheckable(true); @@ -400,15 +400,15 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * @private */ Blockly.FieldDropdown.prototype.trimOptions_ = function() { - var options = this.menuGenerator_; + const options = this.menuGenerator_; if (!Array.isArray(options)) { return; } - var hasImages = false; + let hasImages = false; // Localize label text and image alt text. - for (var i = 0; i < options.length; i++) { - var label = options[i][0]; + for (let i = 0; i < options.length; i++) { + const label = options[i][0]; if (typeof label == 'string') { options[i][0] = Blockly.utils.replaceMessageReferences(label); } else { @@ -421,13 +421,13 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { if (hasImages || options.length < 2) { return; // Do nothing if too few items or at least one label is an image. } - var strings = []; - for (var i = 0; i < options.length; i++) { + const strings = []; + for (let i = 0; i < options.length; i++) { strings.push(options[i][0]); } - var shortest = Blockly.utils.string.shortestStringLength(strings); - var prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); - var suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); + const shortest = Blockly.utils.string.shortestStringLength(strings); + const prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); + const suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } @@ -457,11 +457,11 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { */ Blockly.FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { - var newOptions = []; + const newOptions = []; // Remove the prefix and suffix from the options. - for (var i = 0; i < options.length; i++) { - var text = options[i][0]; - var value = options[i][1]; + for (let i = 0; i < options.length; i++) { + let text = options[i][0]; + const value = options[i][1]; text = text.substring(prefixLength, text.length - suffixLength); newOptions[i] = [text, value]; } @@ -502,9 +502,9 @@ Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { * @protected */ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { - var isValueValid = false; - var options = this.getOptions(true); - for (var i = 0, option; (option = options[i]); i++) { + let isValueValid = false; + const options = this.getOptions(true); + for (let i = 0, option; (option = options[i]); i++) { // Options are tuples of human-readable text and language-neutral values. if (option[1] == opt_newValue) { isValueValid = true; @@ -530,8 +530,8 @@ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { */ Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { Blockly.FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); - var options = this.getOptions(true); - for (var i = 0, option; (option = options[i]); i++) { + const options = this.getOptions(true); + for (let i = 0, option; (option = options[i]); i++) { if (option[1] == this.value_) { this.selectedOption_ = option; } @@ -573,7 +573,7 @@ Blockly.FieldDropdown.prototype.render_ = function() { this.imageElement_.style.display = 'none'; // Show correct element. - var option = this.selectedOption_ && this.selectedOption_[0]; + const option = this.selectedOption_ && this.selectedOption_[0]; if (option && typeof option == 'object') { this.renderSelectedImage_( /** @type {!Blockly.FieldDropdown.ImageProperties} */ (option)); @@ -597,16 +597,16 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); - var imageHeight = Number(imageJson.height); - var imageWidth = Number(imageJson.width); + const imageHeight = Number(imageJson.height); + const imageWidth = Number(imageJson.width); // Height and width include the border rect. - var hasBorder = !!this.borderRect_; - var height = Math.max( + const hasBorder = !!this.borderRect_; + const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING); - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var arrowWidth = 0; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); @@ -620,9 +620,9 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.size_.width = imageWidth + arrowWidth + xPadding * 2; this.size_.height = height; - var arrowX = 0; + let arrowX = 0; if (this.sourceBlock_.RTL) { - var imageX = xPadding + arrowWidth; + const imageX = xPadding + arrowWidth; this.imageElement_.setAttribute('x', imageX); } else { arrowX = imageWidth + arrowWidth; @@ -646,16 +646,16 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { this.textElement_.setAttribute('text-anchor', 'start'); // Height and width include the border rect. - var hasBorder = !!this.borderRect_; - var height = Math.max( + const hasBorder = !!this.borderRect_; + const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - var textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + const textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var arrowWidth = 0; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + let arrowWidth = 0; if (this.svgArrow_) { arrowWidth = this.positionSVGArrow_(textWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); @@ -677,11 +677,11 @@ Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { if (!this.svgArrow_) { return 0; } - var hasBorder = !!this.borderRect_; - var xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; - var textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; - var svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; - var arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; + const hasBorder = !!this.borderRect_; + const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; + const svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; + const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; this.svgArrow_.setAttribute('transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; @@ -699,7 +699,7 @@ Blockly.FieldDropdown.prototype.getText_ = function() { if (!this.selectedOption_) { return null; } - var option = this.selectedOption_[0]; + const option = this.selectedOption_[0]; if (typeof option == 'object') { return option['alt']; } @@ -719,9 +719,9 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { if (!options.length) { throw TypeError('FieldDropdown options must not be an empty array.'); } - var foundError = false; - for (var i = 0; i < options.length; ++i) { - var tuple = options[i]; + let foundError = false; + for (let i = 0; i < options.length; ++i) { + const tuple = options[i]; if (!Array.isArray(tuple)) { foundError = true; console.error( From 5f213b48a691992489b6de9df8560637aad2a712 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 13:30:06 -0700 Subject: [PATCH 210/833] Migrate core/field_dropdown.js to goog.module --- core/field_dropdown.js | 101 +++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index c1554928d..be6c38e98 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldDropdown'); +goog.module('Blockly.FieldDropdown'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Field'); @@ -44,16 +45,16 @@ goog.require('Blockly.utils.userAgent'); * @constructor * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ -Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { +const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { if (typeof menuGenerator != 'function') { - Blockly.FieldDropdown.validateOptions_(menuGenerator); + FieldDropdown.validateOptions_(menuGenerator); } /** * An array of options for a dropdown list, * or a function which generates these options. * @type {(!Array| - * !function(this:Blockly.FieldDropdown): !Array)} + * !function(this:FieldDropdown): !Array)} * @protected */ this.menuGenerator_ = menuGenerator; @@ -90,7 +91,7 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { this.selectedOption_ = this.getOptions(false)[0]; // Call parent's constructor. - Blockly.FieldDropdown.superClass_.constructor.call( + FieldDropdown.superClass_.constructor.call( this, this.selectedOption_[1], opt_validator, opt_config); /** @@ -128,7 +129,7 @@ Blockly.FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.svgArrow_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldDropdown, Blockly.Field); +Blockly.utils.object.inherits(FieldDropdown, Blockly.Field); /** * Dropdown image properties. @@ -139,16 +140,16 @@ Blockly.utils.object.inherits(Blockly.FieldDropdown, Blockly.Field); * height:number * }} */ -Blockly.FieldDropdown.ImageProperties; +FieldDropdown.ImageProperties; /** * Construct a FieldDropdown from a JSON arg object. * @param {!Object} options A JSON object with options (options). - * @return {!Blockly.FieldDropdown} The new field instance. + * @return {!FieldDropdown} The new field instance. * @package * @nocollapse */ -Blockly.FieldDropdown.fromJson = function(options) { +FieldDropdown.fromJson = function(options) { // `this` might be a subclass of FieldDropdown if that class doesn't override // the static fromJson method. return new this(options['options'], undefined, options); @@ -161,7 +162,7 @@ Blockly.FieldDropdown.fromJson = function(options) { * field's state. * @package */ -Blockly.FieldDropdown.prototype.fromXml = function(fieldElement) { +FieldDropdown.prototype.fromXml = function(fieldElement) { if (this.isOptionListDynamic()) { this.getOptions(false); } @@ -173,17 +174,17 @@ Blockly.FieldDropdown.prototype.fromXml = function(fieldElement) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldDropdown.prototype.SERIALIZABLE = true; +FieldDropdown.prototype.SERIALIZABLE = true; /** * Horizontal distance that a checkmark overhangs the dropdown. */ -Blockly.FieldDropdown.CHECKMARK_OVERHANG = 25; +FieldDropdown.CHECKMARK_OVERHANG = 25; /** * Maximum height of the dropdown menu, as a percentage of the viewport height. */ -Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; +FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; /** * The y offset from the top of the field to the top of the image, if an image @@ -192,7 +193,7 @@ Blockly.FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; * @const * @private */ -Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5; +FieldDropdown.IMAGE_Y_OFFSET = 5; /** * The total vertical padding above and below an image. @@ -200,25 +201,25 @@ Blockly.FieldDropdown.IMAGE_Y_OFFSET = 5; * @const * @private */ -Blockly.FieldDropdown.IMAGE_Y_PADDING = - Blockly.FieldDropdown.IMAGE_Y_OFFSET * 2; +FieldDropdown.IMAGE_Y_PADDING = + FieldDropdown.IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "▾", so use "▼" instead. */ -Blockly.FieldDropdown.ARROW_CHAR = +FieldDropdown.ARROW_CHAR = Blockly.utils.userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldDropdown.prototype.CURSOR = 'default'; +FieldDropdown.prototype.CURSOR = 'default'; /** * Create the block UI for this dropdown. * @package */ -Blockly.FieldDropdown.prototype.initView = function() { +FieldDropdown.prototype.initView = function() { if (this.shouldAddBorderRect_()) { this.createBorderRect_(); } else { @@ -245,7 +246,7 @@ Blockly.FieldDropdown.prototype.initView = function() { * @return {boolean} True if the dropdown field should add a border rect. * @protected */ -Blockly.FieldDropdown.prototype.shouldAddBorderRect_ = function() { +FieldDropdown.prototype.shouldAddBorderRect_ = function() { return !this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || (this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && !this.sourceBlock_.isShadow()); @@ -255,13 +256,13 @@ Blockly.FieldDropdown.prototype.shouldAddBorderRect_ = function() { * Create a tspan based arrow. * @protected */ -Blockly.FieldDropdown.prototype.createTextArrow_ = function() { +FieldDropdown.prototype.createTextArrow_ = function() { this.arrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( this.sourceBlock_.RTL ? - Blockly.FieldDropdown.ARROW_CHAR + ' ' : - ' ' + Blockly.FieldDropdown.ARROW_CHAR)); + FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { this.textElement_.insertBefore(this.arrow_, this.textContent_); } else { @@ -273,7 +274,7 @@ Blockly.FieldDropdown.prototype.createTextArrow_ = function() { * Create an SVG based arrow. * @protected */ -Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { +FieldDropdown.prototype.createSVGArrow_ = function() { this.svgArrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', @@ -289,7 +290,7 @@ Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { * or undefined if triggered programmatically. * @protected */ -Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { +FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { this.menu_.openingCoords = @@ -331,7 +332,7 @@ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { * Create the dropdown editor. * @private */ -Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { +FieldDropdown.prototype.dropdownCreate_ = function() { const menu = new Blockly.Menu(); menu.setRole(Blockly.utils.aria.Role.LISTBOX); this.menu_ = menu; @@ -365,7 +366,7 @@ Blockly.FieldDropdown.prototype.dropdownCreate_ = function() { * Disposes of events and DOM-references belonging to the dropdown editor. * @private */ -Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { +FieldDropdown.prototype.dropdownDispose_ = function() { if (this.menu_) { this.menu_.dispose(); } @@ -379,7 +380,7 @@ Blockly.FieldDropdown.prototype.dropdownDispose_ = function() { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @private */ -Blockly.FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { +FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { Blockly.DropDownDiv.hideIfOwner(this, true); this.onItemSelected_(/** @type {!Blockly.Menu} */ (this.menu_), menuItem); }; @@ -390,7 +391,7 @@ Blockly.FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @protected */ -Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { +FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { this.setValue(menuItem.getValue()); }; @@ -399,7 +400,7 @@ Blockly.FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { * Create prefix and/or suffix labels. * @private */ -Blockly.FieldDropdown.prototype.trimOptions_ = function() { +FieldDropdown.prototype.trimOptions_ = function() { const options = this.menuGenerator_; if (!Array.isArray(options)) { return; @@ -442,7 +443,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { this.suffixField = strings[0].substr(1 - suffixLength); } - this.menuGenerator_ = Blockly.FieldDropdown.applyTrim_(options, prefixLength, + this.menuGenerator_ = FieldDropdown.applyTrim_(options, prefixLength, suffixLength); }; @@ -455,7 +456,7 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { * @param {number} suffixLength The length of the common suffix * @return {!Array} A new array with all of the option text trimmed. */ -Blockly.FieldDropdown.applyTrim_ = function(options, +FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { const newOptions = []; // Remove the prefix and suffix from the options. @@ -472,7 +473,7 @@ Blockly.FieldDropdown.applyTrim_ = function(options, * @return {boolean} True if the option list is generated by a function. * Otherwise false. */ -Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { +FieldDropdown.prototype.isOptionListDynamic = function() { return typeof this.menuGenerator_ == 'function'; }; @@ -484,11 +485,11 @@ Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { * (human-readable text or image, language-neutral name). * @throws {TypeError} If generated options are incorrectly structured. */ -Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { +FieldDropdown.prototype.getOptions = function(opt_useCache) { if (this.isOptionListDynamic()) { if (!this.generatedOptions_ || !opt_useCache) { this.generatedOptions_ = this.menuGenerator_.call(this); - Blockly.FieldDropdown.validateOptions_(this.generatedOptions_); + FieldDropdown.validateOptions_(this.generatedOptions_); } return this.generatedOptions_; } @@ -501,7 +502,7 @@ Blockly.FieldDropdown.prototype.getOptions = function(opt_useCache) { * @return {?string} A valid language-neutral option, or null if invalid. * @protected */ -Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { +FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { let isValueValid = false; const options = this.getOptions(true); for (let i = 0, option; (option = options[i]); i++) { @@ -528,8 +529,8 @@ Blockly.FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { * that this is one of the valid dropdown options. * @protected */ -Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { - Blockly.FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); +FieldDropdown.prototype.doValueUpdate_ = function(newValue) { + FieldDropdown.superClass_.doValueUpdate_.call(this, newValue); const options = this.getOptions(true); for (let i = 0, option; (option = options[i]); i++) { if (option[1] == this.value_) { @@ -542,7 +543,7 @@ Blockly.FieldDropdown.prototype.doValueUpdate_ = function(newValue) { * Updates the dropdown arrow to match the colour/style of the block. * @package */ -Blockly.FieldDropdown.prototype.applyColour = function() { +FieldDropdown.prototype.applyColour = function() { if (this.borderRect_) { this.borderRect_.setAttribute('stroke', this.sourceBlock_.style.colourTertiary); @@ -567,7 +568,7 @@ Blockly.FieldDropdown.prototype.applyColour = function() { * Draws the border with the correct width. * @protected */ -Blockly.FieldDropdown.prototype.render_ = function() { +FieldDropdown.prototype.render_ = function() { // Hide both elements. this.textContent_.nodeValue = ''; this.imageElement_.style.display = 'none'; @@ -576,7 +577,7 @@ Blockly.FieldDropdown.prototype.render_ = function() { const option = this.selectedOption_ && this.selectedOption_[0]; if (option && typeof option == 'object') { this.renderSelectedImage_( - /** @type {!Blockly.FieldDropdown.ImageProperties} */ (option)); + /** @type {!FieldDropdown.ImageProperties} */ (option)); } else { this.renderSelectedText_(); } @@ -586,11 +587,11 @@ Blockly.FieldDropdown.prototype.render_ = function() { /** * Renders the selected option, which must be an image. - * @param {!Blockly.FieldDropdown.ImageProperties} imageJson Selected + * @param {!FieldDropdown.ImageProperties} imageJson Selected * option that must be an image. * @private */ -Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { +FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; this.imageElement_.setAttributeNS( Blockly.utils.dom.XLINK_NS, 'xlink:href', imageJson.src); @@ -604,7 +605,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const hasBorder = !!this.borderRect_; const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + Blockly.FieldDropdown.IMAGE_Y_PADDING); + imageHeight + FieldDropdown.IMAGE_Y_PADDING); const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { @@ -638,7 +639,7 @@ Blockly.FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { * Renders the selected option, which must be text. * @private */ -Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { +FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); Blockly.utils.dom.addClass(/** @type {!Element} */ (this.textElement_), @@ -673,7 +674,7 @@ Blockly.FieldDropdown.prototype.renderSelectedText_ = function() { * @return {number} Amount of space the arrow is taking up, in px. * @private */ -Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { +FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { if (!this.svgArrow_) { return 0; } @@ -695,7 +696,7 @@ Blockly.FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { * @protected * @override */ -Blockly.FieldDropdown.prototype.getText_ = function() { +FieldDropdown.prototype.getText_ = function() { if (!this.selectedOption_) { return null; } @@ -712,7 +713,7 @@ Blockly.FieldDropdown.prototype.getText_ = function() { * @throws {TypeError} If proposed options are incorrectly structured. * @private */ -Blockly.FieldDropdown.validateOptions_ = function(options) { +FieldDropdown.validateOptions_ = function(options) { if (!Array.isArray(options)) { throw TypeError('FieldDropdown options must be an array.'); } @@ -747,4 +748,6 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { } }; -Blockly.fieldRegistry.register('field_dropdown', Blockly.FieldDropdown); +Blockly.fieldRegistry.register('field_dropdown', FieldDropdown); + +exports = FieldDropdown; diff --git a/tests/deps.js b/tests/deps.js index 979c58c74..65e09fda9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -52,7 +52,7 @@ goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownD goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); From 393cdf1fa4d5a94a083755b4037e5beac28f2f6a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:18:05 -0700 Subject: [PATCH 211/833] Switch from destructuring to normal imports in core/field_checkbox.js --- core/field_checkbox.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 3cbe8d07f..d2ce60eaa 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -14,9 +14,9 @@ goog.module('Blockly.FieldCheckbox'); goog.module.declareLegacyNamespace(); const Field = goog.require('Blockly.Field'); -const {addClass} = goog.require('Blockly.utils.dom'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); const {inherits} = goog.require('Blockly.utils.object'); -const {register} = goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -109,7 +109,7 @@ FieldCheckbox.prototype.configure_ = function(config) { FieldCheckbox.prototype.initView = function() { FieldCheckbox.superClass_.initView.call(this); - addClass( + dom.addClass( /** @type {!SVGTextElement} **/ (this.textElement_), 'blocklyCheckbox'); this.textElement_.style.display = this.value_ ? 'block' : 'none'; }; @@ -221,6 +221,6 @@ FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; -register('field_checkbox', FieldCheckbox); +fieldRegistry.register('field_checkbox', FieldCheckbox); exports = FieldCheckbox; From 36bb605bbc9f362a2bbf435048c420bf763ef397 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:53:44 -0700 Subject: [PATCH 212/833] Migrate core/field_dropdown.js to named requires --- core/field_dropdown.js | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index be6c38e98..5a5234c90 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -15,19 +15,19 @@ goog.module('Blockly.FieldDropdown'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.Menu'); -goog.require('Blockly.MenuItem'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.string'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Field = goog.require('Blockly.Field'); +const Menu = goog.require('Blockly.Menu'); +const MenuItem = goog.require('Blockly.MenuItem'); +const Svg = goog.require('Blockly.utils.Svg'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {commonWordPrefix, commonWordSuffix, shortestStringLength} = goog.require('Blockly.utils.string'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -41,7 +41,7 @@ goog.require('Blockly.utils.userAgent'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor * @throws {TypeError} If `menuGenerator` options are incorrectly structured. */ @@ -96,14 +96,14 @@ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { /** * A reference to the currently selected menu item. - * @type {?Blockly.MenuItem} + * @type {?MenuItem} * @private */ this.selectedMenuItem_ = null; /** * The dropdown menu. - * @type {?Blockly.Menu} + * @type {?Menu} * @protected */ this.menu_ = null; @@ -129,7 +129,7 @@ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { */ this.svgArrow_ = null; }; -Blockly.utils.object.inherits(FieldDropdown, Blockly.Field); +inherits(FieldDropdown, Field); /** * Dropdown image properties. @@ -208,7 +208,7 @@ FieldDropdown.IMAGE_Y_PADDING = * Android can't (in 2014) display "▾", so use "▼" instead. */ FieldDropdown.ARROW_CHAR = - Blockly.utils.userAgent.ANDROID ? '\u25BC' : '\u25BE'; + userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. @@ -227,8 +227,8 @@ FieldDropdown.prototype.initView = function() { } this.createTextElement_(); - this.imageElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, {}, this.fieldGroup_); + this.imageElement_ = dom.createSvgElement( + Svg.IMAGE, {}, this.fieldGroup_); if (this.getConstants().FIELD_DROPDOWN_SVG_ARROW) { this.createSVGArrow_(); @@ -237,7 +237,7 @@ FieldDropdown.prototype.initView = function() { } if (this.borderRect_) { - Blockly.utils.dom.addClass(this.borderRect_, 'blocklyDropdownRect'); + dom.addClass(this.borderRect_, 'blocklyDropdownRect'); } }; @@ -257,8 +257,8 @@ FieldDropdown.prototype.shouldAddBorderRect_ = function() { * @protected */ FieldDropdown.prototype.createTextArrow_ = function() { - this.arrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TSPAN, {}, this.textElement_); + this.arrow_ = dom.createSvgElement( + Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : @@ -275,12 +275,12 @@ FieldDropdown.prototype.createTextArrow_ = function() { * @protected */ FieldDropdown.prototype.createSVGArrow_ = function() { - this.svgArrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { + this.svgArrow_ = dom.createSvgElement( + Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', 'width': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px' }, this.fieldGroup_); - this.svgArrow_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.svgArrow_.setAttributeNS(dom.XLINK_NS, 'xlink:href', this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI); }; @@ -294,14 +294,14 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { this.menu_.openingCoords = - new Blockly.utils.Coordinate(opt_e.clientX, opt_e.clientY); + new Coordinate(opt_e.clientX, opt_e.clientY); } else { this.menu_.openingCoords = null; } // Element gets created in render. - this.menu_.render(Blockly.DropDownDiv.getContentDiv()); + this.menu_.render(DropDownDiv.getContentDiv()); const menuElement = /** @type {!Element} */ (this.menu_.getElement()); - Blockly.utils.dom.addClass(menuElement, 'blocklyDropdownMenu'); + dom.addClass(menuElement, 'blocklyDropdownMenu'); if (this.getConstants().FIELD_DROPDOWN_COLOURED_DIV) { const primaryColour = (this.sourceBlock_.isShadow()) ? @@ -310,10 +310,10 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { const borderColour = (this.sourceBlock_.isShadow()) ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; - Blockly.DropDownDiv.setColour(primaryColour, borderColour); + DropDownDiv.setColour(primaryColour, borderColour); } - Blockly.DropDownDiv.showPositionedByField( + DropDownDiv.showPositionedByField( this, this.dropdownDispose_.bind(this)); // Focusing needs to be handled after the menu is rendered and positioned. @@ -333,8 +333,8 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { * @private */ FieldDropdown.prototype.dropdownCreate_ = function() { - const menu = new Blockly.Menu(); - menu.setRole(Blockly.utils.aria.Role.LISTBOX); + const menu = new Menu(); + menu.setRole(aria.Role.LISTBOX); this.menu_ = menu; const options = this.getOptions(false); @@ -349,8 +349,8 @@ FieldDropdown.prototype.dropdownCreate_ = function() { image.alt = content['alt'] || ''; content = image; } - const menuItem = new Blockly.MenuItem(content, value); - menuItem.setRole(Blockly.utils.aria.Role.OPTION); + const menuItem = new MenuItem(content, value); + menuItem.setRole(aria.Role.OPTION); menuItem.setRightToLeft(this.sourceBlock_.RTL); menuItem.setCheckable(true); menu.addChild(menuItem); @@ -377,18 +377,18 @@ FieldDropdown.prototype.dropdownDispose_ = function() { /** * Handle an action in the dropdown menu. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @private */ FieldDropdown.prototype.handleMenuActionEvent_ = function(menuItem) { - Blockly.DropDownDiv.hideIfOwner(this, true); - this.onItemSelected_(/** @type {!Blockly.Menu} */ (this.menu_), menuItem); + DropDownDiv.hideIfOwner(this, true); + this.onItemSelected_(/** @type {!Menu} */ (this.menu_), menuItem); }; /** * Handle the selection of an item in the dropdown menu. - * @param {!Blockly.Menu} menu The Menu component clicked. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!Menu} menu The Menu component clicked. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @protected */ FieldDropdown.prototype.onItemSelected_ = function(menu, menuItem) { @@ -411,10 +411,10 @@ FieldDropdown.prototype.trimOptions_ = function() { for (let i = 0; i < options.length; i++) { const label = options[i][0]; if (typeof label == 'string') { - options[i][0] = Blockly.utils.replaceMessageReferences(label); + options[i][0] = replaceMessageReferences(label); } else { if (label.alt != null) { - options[i][0].alt = Blockly.utils.replaceMessageReferences(label.alt); + options[i][0].alt = replaceMessageReferences(label.alt); } hasImages = true; } @@ -426,9 +426,9 @@ FieldDropdown.prototype.trimOptions_ = function() { for (let i = 0; i < options.length; i++) { strings.push(options[i][0]); } - const shortest = Blockly.utils.string.shortestStringLength(strings); - const prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); - const suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); + const shortest = shortestStringLength(strings); + const prefixLength = commonWordPrefix(strings, shortest); + const suffixLength = commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } @@ -594,7 +594,7 @@ FieldDropdown.prototype.render_ = function() { FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; this.imageElement_.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', imageJson.src); + dom.XLINK_NS, 'xlink:href', imageJson.src); this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); @@ -612,7 +612,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { - arrowWidth = Blockly.utils.dom.getFastTextWidth( + arrowWidth = dom.getFastTextWidth( /** @type {!SVGTSpanElement} */ (this.arrow_), this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, @@ -642,7 +642,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); - Blockly.utils.dom.addClass(/** @type {!Element} */ (this.textElement_), + dom.addClass(/** @type {!Element} */ (this.textElement_), 'blocklyDropdownText'); this.textElement_.setAttribute('text-anchor', 'start'); @@ -651,7 +651,7 @@ FieldDropdown.prototype.renderSelectedText_ = function() { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - const textWidth = Blockly.utils.dom.getFastTextWidth(this.textElement_, + const textWidth = dom.getFastTextWidth(this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); @@ -748,6 +748,6 @@ FieldDropdown.validateOptions_ = function(options) { } }; -Blockly.fieldRegistry.register('field_dropdown', FieldDropdown); +fieldRegistry.register('field_dropdown', FieldDropdown); exports = FieldDropdown; From 740e4651b178dfbcbe6ab07930896ee3ccf10834 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 14:56:32 -0700 Subject: [PATCH 213/833] clang-format core/field_dropdown.js --- core/field_dropdown.js | 118 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 5a5234c90..79b6ea404 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -39,7 +39,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * option & returns a validated language-neutral dropdown option, or null to * abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -134,12 +135,12 @@ inherits(FieldDropdown, Field); /** * Dropdown image properties. * @typedef {{ - * src:string, - * alt:string, - * width:number, - * height:number - * }} - */ + * src:string, + * alt:string, + * width:number, + * height:number + * }} + */ FieldDropdown.ImageProperties; /** @@ -201,14 +202,12 @@ FieldDropdown.IMAGE_Y_OFFSET = 5; * @const * @private */ -FieldDropdown.IMAGE_Y_PADDING = - FieldDropdown.IMAGE_Y_OFFSET * 2; +FieldDropdown.IMAGE_Y_PADDING = FieldDropdown.IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "▾", so use "▼" instead. */ -FieldDropdown.ARROW_CHAR = - userAgent.ANDROID ? '\u25BC' : '\u25BE'; +FieldDropdown.ARROW_CHAR = userAgent.ANDROID ? '\u25BC' : '\u25BE'; /** * Mouse cursor style when over the hotspot that initiates the editor. @@ -227,8 +226,7 @@ FieldDropdown.prototype.initView = function() { } this.createTextElement_(); - this.imageElement_ = dom.createSvgElement( - Svg.IMAGE, {}, this.fieldGroup_); + this.imageElement_ = dom.createSvgElement(Svg.IMAGE, {}, this.fieldGroup_); if (this.getConstants().FIELD_DROPDOWN_SVG_ARROW) { this.createSVGArrow_(); @@ -249,7 +247,7 @@ FieldDropdown.prototype.initView = function() { FieldDropdown.prototype.shouldAddBorderRect_ = function() { return !this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || (this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW && - !this.sourceBlock_.isShadow()); + !this.sourceBlock_.isShadow()); }; /** @@ -257,12 +255,10 @@ FieldDropdown.prototype.shouldAddBorderRect_ = function() { * @protected */ FieldDropdown.prototype.createTextArrow_ = function() { - this.arrow_ = dom.createSvgElement( - Svg.TSPAN, {}, this.textElement_); + this.arrow_ = dom.createSvgElement(Svg.TSPAN, {}, this.textElement_); this.arrow_.appendChild(document.createTextNode( - this.sourceBlock_.RTL ? - FieldDropdown.ARROW_CHAR + ' ' : - ' ' + FieldDropdown.ARROW_CHAR)); + this.sourceBlock_.RTL ? FieldDropdown.ARROW_CHAR + ' ' : + ' ' + FieldDropdown.ARROW_CHAR)); if (this.sourceBlock_.RTL) { this.textElement_.insertBefore(this.arrow_, this.textContent_); } else { @@ -279,8 +275,10 @@ FieldDropdown.prototype.createSVGArrow_ = function() { Svg.IMAGE, { 'height': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px', 'width': this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE + 'px' - }, this.fieldGroup_); - this.svgArrow_.setAttributeNS(dom.XLINK_NS, 'xlink:href', + }, + this.fieldGroup_); + this.svgArrow_.setAttributeNS( + dom.XLINK_NS, 'xlink:href', this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI); }; @@ -293,8 +291,7 @@ FieldDropdown.prototype.createSVGArrow_ = function() { FieldDropdown.prototype.showEditor_ = function(opt_e) { this.dropdownCreate_(); if (opt_e && typeof opt_e.clientX === 'number') { - this.menu_.openingCoords = - new Coordinate(opt_e.clientX, opt_e.clientY); + this.menu_.openingCoords = new Coordinate(opt_e.clientX, opt_e.clientY); } else { this.menu_.openingCoords = null; } @@ -313,8 +310,7 @@ FieldDropdown.prototype.showEditor_ = function(opt_e) { DropDownDiv.setColour(primaryColour, borderColour); } - DropDownDiv.showPositionedByField( - this, this.dropdownDispose_.bind(this)); + DropDownDiv.showPositionedByField(this, this.dropdownDispose_.bind(this)); // Focusing needs to be handled after the menu is rendered and positioned. // Otherwise it will cause a page scroll to get the misplaced menu in @@ -341,7 +337,7 @@ FieldDropdown.prototype.dropdownCreate_ = function() { this.selectedMenuItem_ = null; for (let i = 0; i < options.length; i++) { let content = options[i][0]; // Human-readable text or image. - const value = options[i][1]; // Language-neutral value. + const value = options[i][1]; // Language-neutral value. if (typeof content == 'object') { // An image, not text. const image = new Image(content['width'], content['height']); @@ -443,8 +439,8 @@ FieldDropdown.prototype.trimOptions_ = function() { this.suffixField = strings[0].substr(1 - suffixLength); } - this.menuGenerator_ = FieldDropdown.applyTrim_(options, prefixLength, - suffixLength); + this.menuGenerator_ = + FieldDropdown.applyTrim_(options, prefixLength, suffixLength); }; /** @@ -456,8 +452,7 @@ FieldDropdown.prototype.trimOptions_ = function() { * @param {number} suffixLength The length of the common suffix * @return {!Array} A new array with all of the option text trimmed. */ -FieldDropdown.applyTrim_ = function(options, - prefixLength, suffixLength) { +FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) { const newOptions = []; // Remove the prefix and suffix from the options. for (let i = 0; i < options.length; i++) { @@ -514,9 +509,10 @@ FieldDropdown.prototype.doClassValidation_ = function(opt_newValue) { } if (!isValueValid) { if (this.sourceBlock_) { - console.warn('Cannot set the dropdown\'s value to an unavailable option.' + - ' Block type: ' + this.sourceBlock_.type + ', Field name: ' + this.name + - ', Value: ' + opt_newValue); + console.warn( + 'Cannot set the dropdown\'s value to an unavailable option.' + + ' Block type: ' + this.sourceBlock_.type + + ', Field name: ' + this.name + ', Value: ' + opt_newValue); } return null; } @@ -545,11 +541,11 @@ FieldDropdown.prototype.doValueUpdate_ = function(newValue) { */ FieldDropdown.prototype.applyColour = function() { if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'stroke', this.sourceBlock_.style.colourTertiary); if (this.menu_) { - this.borderRect_.setAttribute('fill', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'fill', this.sourceBlock_.style.colourTertiary); } else { this.borderRect_.setAttribute('fill', 'transparent'); } @@ -593,8 +589,7 @@ FieldDropdown.prototype.render_ = function() { */ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { this.imageElement_.style.display = ''; - this.imageElement_.setAttributeNS( - dom.XLINK_NS, 'xlink:href', imageJson.src); + this.imageElement_.setAttributeNS(dom.XLINK_NS, 'xlink:href', imageJson.src); this.imageElement_.setAttribute('height', imageJson.height); this.imageElement_.setAttribute('width', imageJson.width); @@ -606,11 +601,13 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, imageHeight + FieldDropdown.IMAGE_Y_PADDING); - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { - arrowWidth = this.positionSVGArrow_(imageWidth + xPadding, height / 2 - - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + arrowWidth = this.positionSVGArrow_( + imageWidth + xPadding, + height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } else { arrowWidth = dom.getFastTextWidth( /** @type {!SVGTSpanElement} */ (this.arrow_), @@ -642,8 +639,8 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { FieldDropdown.prototype.renderSelectedText_ = function() { // Retrieves the selected option to display through getText_. this.textContent_.nodeValue = this.getDisplayText_(); - dom.addClass(/** @type {!Element} */ (this.textElement_), - 'blocklyDropdownText'); + dom.addClass( + /** @type {!Element} */ (this.textElement_), 'blocklyDropdownText'); this.textElement_.setAttribute('text-anchor', 'start'); // Height and width include the border rect. @@ -651,15 +648,17 @@ FieldDropdown.prototype.renderSelectedText_ = function() { const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, this.getConstants().FIELD_TEXT_HEIGHT); - const textWidth = dom.getFastTextWidth(this.textElement_, - this.getConstants().FIELD_TEXT_FONTSIZE, + const textWidth = dom.getFastTextWidth( + this.textElement_, this.getConstants().FIELD_TEXT_FONTSIZE, this.getConstants().FIELD_TEXT_FONTWEIGHT, this.getConstants().FIELD_TEXT_FONTFAMILY); - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; if (this.svgArrow_) { - arrowWidth = this.positionSVGArrow_(textWidth + xPadding, height / 2 - - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); + arrowWidth = this.positionSVGArrow_( + textWidth + xPadding, + height / 2 - this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE / 2); } this.size_.width = textWidth + arrowWidth + xPadding * 2; this.size_.height = height; @@ -679,12 +678,13 @@ FieldDropdown.prototype.positionSVGArrow_ = function(x, y) { return 0; } const hasBorder = !!this.borderRect_; - const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; + const xPadding = + hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; const textPadding = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING; const svgArrowSize = this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE; const arrowX = this.sourceBlock_.RTL ? xPadding : x + textPadding; - this.svgArrow_.setAttribute('transform', - 'translate(' + arrowX + ',' + y + ')'); + this.svgArrow_.setAttribute( + 'transform', 'translate(' + arrowX + ',' + y + ')'); return svgArrowSize + textPadding; }; @@ -727,19 +727,21 @@ FieldDropdown.validateOptions_ = function(options) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must be an ' + - 'array. Found: ', tuple); + 'array. Found: ', + tuple); } else if (typeof tuple[1] != 'string') { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option id must be ' + - 'a string. Found ' + tuple[1] + ' in: ', tuple); - } else if (tuple[0] && - (typeof tuple[0] != 'string') && - (typeof tuple[0].src != 'string')) { + 'a string. Found ' + tuple[1] + ' in: ', + tuple); + } else if ( + tuple[0] && (typeof tuple[0] != 'string') && + (typeof tuple[0].src != 'string')) { foundError = true; console.error( 'Invalid option[' + i + ']: Each FieldDropdown option must have a ' + - 'string label or image description. Found' + tuple[0] + ' in: ', + 'string label or image description. Found' + tuple[0] + ' in: ', tuple); } } From 5e3940195f8c718d812a4c5b7d0b64a8f7fd6a7c Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Wed, 21 Jul 2021 15:02:35 -0700 Subject: [PATCH 214/833] Migrate private static fields/functions in core/field_dropdown.js to module-internal --- core/field_dropdown.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 79b6ea404..ddb5a4e18 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -48,7 +48,7 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); */ const FieldDropdown = function(menuGenerator, opt_validator, opt_config) { if (typeof menuGenerator != 'function') { - FieldDropdown.validateOptions_(menuGenerator); + validateOptions(menuGenerator); } /** @@ -192,17 +192,15 @@ FieldDropdown.MAX_MENU_HEIGHT_VH = 0.45; * is selected. * @type {number} * @const - * @private */ -FieldDropdown.IMAGE_Y_OFFSET = 5; +const IMAGE_Y_OFFSET = 5; /** * The total vertical padding above and below an image. * @type {number} * @const - * @private */ -FieldDropdown.IMAGE_Y_PADDING = FieldDropdown.IMAGE_Y_OFFSET * 2; +const IMAGE_Y_PADDING = IMAGE_Y_OFFSET * 2; /** * Android can't (in 2014) display "▾", so use "▼" instead. @@ -484,7 +482,7 @@ FieldDropdown.prototype.getOptions = function(opt_useCache) { if (this.isOptionListDynamic()) { if (!this.generatedOptions_ || !opt_useCache) { this.generatedOptions_ = this.menuGenerator_.call(this); - FieldDropdown.validateOptions_(this.generatedOptions_); + validateOptions(this.generatedOptions_); } return this.generatedOptions_; } @@ -600,7 +598,7 @@ FieldDropdown.prototype.renderSelectedImage_ = function(imageJson) { const hasBorder = !!this.borderRect_; const height = Math.max( hasBorder ? this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT : 0, - imageHeight + FieldDropdown.IMAGE_Y_PADDING); + imageHeight + IMAGE_Y_PADDING); const xPadding = hasBorder ? this.getConstants().FIELD_BORDER_RECT_X_PADDING : 0; let arrowWidth = 0; @@ -711,9 +709,8 @@ FieldDropdown.prototype.getText_ = function() { * Validates the data structure to be processed as an options list. * @param {?} options The proposed dropdown options. * @throws {TypeError} If proposed options are incorrectly structured. - * @private */ -FieldDropdown.validateOptions_ = function(options) { +const validateOptions = function(options) { if (!Array.isArray(options)) { throw TypeError('FieldDropdown options must be an array.'); } From c15f1e4767798f1b8230fc07f9ae7d89e669e634 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:17:00 -0700 Subject: [PATCH 215/833] Move constants to internal_constants.js and add aliases --- core/blockly.js | 36 ++++++ core/constants.js | 189 ++------------------------------ core/internal_constants.js | 217 +++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+), 181 deletions(-) create mode 100644 core/internal_constants.js diff --git a/core/blockly.js b/core/blockly.js index 92716e4d1..554e02c8d 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -35,6 +35,7 @@ goog.require('Blockly.Events.VarCreate'); /** @suppress {extraRequire} */ goog.require('Blockly.inject'); goog.require('Blockly.inputTypes'); +goog.require('Blockly.internalConstants'); /** @suppress {extraRequire} */ goog.require('Blockly.Procedures'); goog.require('Blockly.ShortcutRegistry'); @@ -596,3 +597,38 @@ Blockly.TOOLBOX_AT_LEFT = Blockly.utils.toolbox.Position.LEFT; * @see Blockly.utils.toolbox.Position.RIGHT */ Blockly.TOOLBOX_AT_RIGHT = Blockly.utils.toolbox.Position.RIGHT; + +// Aliases to allow external code to access these values for legacy reasons. +Blockly.LINE_MODE_MULTIPLIER = Blockly.internalConstants.LINE_MODE_MULTIPLIER; +Blockly.PAGE_MODE_MULTIPLIER = Blockly.internalConstants.PAGE_MODE_MULTIPLIER; +Blockly.DRAG_RADIUS = Blockly.internalConstants.DRAG_RADIUS; +Blockly.FLYOUT_DRAG_RADIUS = Blockly.internalConstants.FLYOUT_DRAG_RADIUS; +Blockly.SNAP_RADIUS = Blockly.internalConstants.SNAP_RADIUS; +Blockly.CONNECTING_SNAP_RADIUS = + Blockly.internalConstants.CONNECTING_SNAP_RADIUS; +Blockly.CURRENT_CONNECTION_PREFERENCE = + Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE; +Blockly.BUMP_DELAY = Blockly.internalConstants.BUMP_DELAY; +Blockly.BUMP_RANDOMNESS = Blockly.internalConstants.BUMP_RANDOMNESS; +Blockly.COLLAPSE_CHARS = Blockly.internalConstants.COLLAPSE_CHARS; +Blockly.LONGPRESS = Blockly.internalConstants.LONGPRESS; +Blockly.SOUND_LIMIT = Blockly.internalConstants.SOUND_LIMIT; +Blockly.DRAG_STACK = Blockly.internalConstants.DRAG_STACK; +Blockly.HSV_SATURATION = Blockly.internalConstants.HSV_SATURATION; +Blockly.HSV_VALUE = Blockly.internalConstants.HSV_VALUE; +Blockly.SPRITE = Blockly.internalConstants.SPRITE; +Blockly.DRAG_NONE = Blockly.internalConstants.DRAG_NONE; +Blockly.DRAG_STICKY = Blockly.internalConstants.DRAG_STICKY; +Blockly.DRAG_BEGIN = Blockly.internalConstants.DRAG_BEGIN; +Blockly.DRAG_FREE = Blockly.internalConstants.DRAG_FREE; +Blockly.OPPOSITE_TYPE = Blockly.internalConstants.OPPOSITE_TYPE; +Blockly.VARIABLE_CATEGORY_NAME = + Blockly.internalConstants.VARIABLE_CATEGORY_NAME; +Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = + Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME; +Blockly.PROCEDURE_CATEGORY_NAME = + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME; +Blockly.RENAME_VARIABLE_ID = Blockly.internalConstants.RENAME_VARIABLE_ID; +Blockly.DELETE_VARIABLE_ID = Blockly.internalConstants.DELETE_VARIABLE_ID; +Blockly.COLLAPSED_INPUT_NAME = Blockly.constants.COLLAPSED_INPUT_NAME; +Blockly.COLLAPSED_FIELD_NAME = Blockly.constants.COLLAPSED_FIELD_NAME; diff --git a/core/constants.js b/core/constants.js index 1d19fb8d5..727e42a1f 100644 --- a/core/constants.js +++ b/core/constants.js @@ -10,204 +10,31 @@ */ 'use strict'; -goog.provide('Blockly.constants'); +goog.module('Blockly.constants'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); - - -/** - * The multiplier for scroll wheel deltas using the line delta mode. - * @type {number} - */ -Blockly.LINE_MODE_MULTIPLIER = 40; - -/** - * The multiplier for scroll wheel deltas using the page delta mode. - * @type {number} - */ -Blockly.PAGE_MODE_MULTIPLIER = 125; - -/** - * Number of pixels the mouse must move before a drag starts. - */ -Blockly.DRAG_RADIUS = 5; - -/** - * Number of pixels the mouse must move before a drag/scroll starts from the - * flyout. Because the drag-intention is determined when this is reached, it is - * larger than Blockly.DRAG_RADIUS so that the drag-direction is clearer. - */ -Blockly.FLYOUT_DRAG_RADIUS = 10; - -/** - * Maximum misalignment between connections for them to snap together. - */ -Blockly.SNAP_RADIUS = 28; - -/** - * Maximum misalignment between connections for them to snap together, - * when a connection is already highlighted. - */ -Blockly.CONNECTING_SNAP_RADIUS = Blockly.SNAP_RADIUS; - -/** - * How much to prefer staying connected to the current connection over moving to - * a new connection. The current previewed connection is considered to be this - * much closer to the matching connection on the block than it actually is. - */ -Blockly.CURRENT_CONNECTION_PREFERENCE = 8; - -/** - * Delay in ms between trigger and bumping unconnected block out of alignment. - */ -Blockly.BUMP_DELAY = 250; - -/** - * Maximum randomness in workspace units for bumping a block. - */ -Blockly.BUMP_RANDOMNESS = 10; - -/** - * Number of characters to truncate a collapsed block to. - */ -Blockly.COLLAPSE_CHARS = 30; - -/** - * Length in ms for a touch to become a long press. - */ -Blockly.LONGPRESS = 750; - -/** - * Prevent a sound from playing if another sound preceded it within this many - * milliseconds. - */ -Blockly.SOUND_LIMIT = 100; - -/** - * When dragging a block out of a stack, split the stack in two (true), or drag - * out the block healing the stack (false). - */ -Blockly.DRAG_STACK = true; - -/** - * The richness of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - */ -Blockly.HSV_SATURATION = 0.45; - -/** - * The intensity of block colours, regardless of the hue. - * Must be in the range of 0 (inclusive) to 1 (exclusive). - */ -Blockly.HSV_VALUE = 0.65; - -/** - * Sprited icons and images. - */ -Blockly.SPRITE = { - width: 96, - height: 124, - url: 'sprites.png' -}; - -// Constants below this point are not intended to be changed. /** * Enum for alignment of inputs. * @enum {number} */ -Blockly.constants.ALIGN = { +const ALIGN = { LEFT: -1, CENTRE: 0, RIGHT: 1 }; - -/** - * ENUM for no drag operation. - * @const - */ -Blockly.DRAG_NONE = 0; - -/** - * ENUM for inside the sticky DRAG_RADIUS. - * @const - */ -Blockly.DRAG_STICKY = 1; - -/** - * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between - * clicks and drags. - * @const - */ -Blockly.DRAG_BEGIN = 1; - -/** - * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). - * @const - */ -Blockly.DRAG_FREE = 2; - -/** - * Lookup table for determining the opposite type of a connection. - * @const - */ -Blockly.OPPOSITE_TYPE = []; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.INPUT_VALUE] = - Blockly.connectionTypes.OUTPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.OUTPUT_VALUE] = - Blockly.connectionTypes.INPUT_VALUE; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.NEXT_STATEMENT] = - Blockly.connectionTypes.PREVIOUS_STATEMENT; -Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.PREVIOUS_STATEMENT] = - Blockly.connectionTypes.NEXT_STATEMENT; - -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * @const {string} - */ -Blockly.VARIABLE_CATEGORY_NAME = 'VARIABLE'; -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * variable blocks. - * @const {string} - */ -Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC'; - -/** - * String for use in the "custom" attribute of a category in toolbox XML. - * This string indicates that the category should be dynamically populated with - * procedure blocks. - * @const {string} - */ -Blockly.PROCEDURE_CATEGORY_NAME = 'PROCEDURE'; - -/** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Rename - * variable...' and if selected, should trigger the prompt to rename a variable. - * @const {string} - */ -Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; - -/** - * String for use in the dropdown created in field_variable. - * This string indicates that this option in the dropdown is 'Delete the "%1" - * variable' and if selected, should trigger the prompt to delete a variable. - * @const {string} - */ -Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; +exports.ALIGN = ALIGN; /** * The language-neutral ID given to the collapsed input. * @const {string} */ -Blockly.constants.COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT'; +const COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT'; +exports.COLLAPSED_INPUT_NAME = COLLAPSED_INPUT_NAME; /** * The language-neutral ID given to the collapsed field. * @const {string} */ -Blockly.constants.COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD'; +const COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD'; +exports.COLLAPSED_FIELD_NAME = COLLAPSED_FIELD_NAME; diff --git a/core/internal_constants.js b/core/internal_constants.js new file mode 100644 index 000000000..b5a8cd568 --- /dev/null +++ b/core/internal_constants.js @@ -0,0 +1,217 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Module that provides constants for use inside Blockly. Do not + * use these constants outside of the core library. + * @author fenichel@google.com (Rachel Fenichel) + */ +'use strict'; + +goog.module('Blockly.internalConstants'); +goog.module.declareLegacyNamespace(); + +const connectionTypes = goog.require('Blockly.connectionTypes'); + + +/** + * The multiplier for scroll wheel deltas using the line delta mode. + * @type {number} + */ +const LINE_MODE_MULTIPLIER = 40; +exports.LINE_MODE_MULTIPLIER = LINE_MODE_MULTIPLIER; + +/** + * The multiplier for scroll wheel deltas using the page delta mode. + * @type {number} + */ +const PAGE_MODE_MULTIPLIER = 125; +exports.PAGE_MODE_MULTIPLIER = PAGE_MODE_MULTIPLIER; + +/** + * Number of pixels the mouse must move before a drag starts. + */ +const DRAG_RADIUS = 5; +exports.DRAG_RADIUS = DRAG_RADIUS; + +/** + * Number of pixels the mouse must move before a drag/scroll starts from the + * flyout. Because the drag-intention is determined when this is reached, it is + * larger than DRAG_RADIUS so that the drag-direction is clearer. + */ +const FLYOUT_DRAG_RADIUS = 10; +exports.FLYOUT_DRAG_RADIUS = FLYOUT_DRAG_RADIUS; + +/** + * Maximum misalignment between connections for them to snap together. + */ +const SNAP_RADIUS = 28; +exports.SNAP_RADIUS = SNAP_RADIUS; + +/** + * Maximum misalignment between connections for them to snap together, + * when a connection is already highlighted. + */ +const CONNECTING_SNAP_RADIUS = SNAP_RADIUS; +exports.CONNECTING_SNAP_RADIUS = CONNECTING_SNAP_RADIUS; + +/** + * How much to prefer staying connected to the current connection over moving to + * a new connection. The current previewed connection is considered to be this + * much closer to the matching connection on the block than it actually is. + */ +const CURRENT_CONNECTION_PREFERENCE = 8; +exports.CURRENT_CONNECTION_PREFERENCE = CURRENT_CONNECTION_PREFERENCE; + +/** + * Delay in ms between trigger and bumping unconnected block out of alignment. + */ +const BUMP_DELAY = 250; +exports.BUMP_DELAY = BUMP_DELAY; + +/** + * Maximum randomness in workspace units for bumping a block. + */ +const BUMP_RANDOMNESS = 10; +exports.BUMP_RANDOMNESS = BUMP_RANDOMNESS; + +/** + * Number of characters to truncate a collapsed block to. + */ +const COLLAPSE_CHARS = 30; +exports.COLLAPSE_CHARS = COLLAPSE_CHARS; + +/** + * Length in ms for a touch to become a long press. + */ +const LONGPRESS = 750; +exports.LONGPRESS = LONGPRESS; + +/** + * Prevent a sound from playing if another sound preceded it within this many + * milliseconds. + */ +const SOUND_LIMIT = 100; +exports.SOUND_LIMIT = SOUND_LIMIT; + +/** + * When dragging a block out of a stack, split the stack in two (true), or drag + * out the block healing the stack (false). + */ +const DRAG_STACK = true; +exports.DRAG_STACK = DRAG_STACK; + +/** + * The richness of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + */ +const HSV_SATURATION = 0.45; +exports.HSV_SATURATION = HSV_SATURATION; + +/** + * The intensity of block colours, regardless of the hue. + * Must be in the range of 0 (inclusive) to 1 (exclusive). + */ +const HSV_VALUE = 0.65; +exports.HSV_VALUE = HSV_VALUE; + +/** + * Sprited icons and images. + */ +const SPRITE = { + width: 96, + height: 124, + url: 'sprites.png' +}; +exports.SPRITE = SPRITE; + +/** + * ENUM for no drag operation. + * @const + */ +const DRAG_NONE = 0; +exports.DRAG_NONE = DRAG_NONE; + +/** + * ENUM for inside the sticky DRAG_RADIUS. + * @const + */ +const DRAG_STICKY = 1; +exports.DRAG_STICKY = DRAG_STICKY; + +/** + * ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between + * clicks and drags. + * @const + */ +const DRAG_BEGIN = 1; +exports.DRAG_BEGIN = DRAG_BEGIN; + +/** + * ENUM for freely draggable (outside the DRAG_RADIUS, if one applies). + * @const + */ +const DRAG_FREE = 2; +exports.DRAG_FREE = DRAG_FREE; + +/** + * Lookup table for determining the opposite type of a connection. + * @const + */ +const OPPOSITE_TYPE = []; +OPPOSITE_TYPE[connectionTypes.INPUT_VALUE] = connectionTypes.OUTPUT_VALUE; +OPPOSITE_TYPE[connectionTypes.OUTPUT_VALUE] = connectionTypes.INPUT_VALUE; +OPPOSITE_TYPE[connectionTypes.NEXT_STATEMENT] = + connectionTypes.PREVIOUS_STATEMENT; +OPPOSITE_TYPE[connectionTypes.PREVIOUS_STATEMENT] = + connectionTypes.NEXT_STATEMENT; + +exports.OPPOSITE_TYPE = OPPOSITE_TYPE; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * variable blocks. + * @const {string} + */ +const VARIABLE_CATEGORY_NAME = 'VARIABLE'; +exports.VARIABLE_CATEGORY_NAME = VARIABLE_CATEGORY_NAME; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * variable blocks. + * @const {string} + */ +const VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC'; +exports.VARIABLE_DYNAMIC_CATEGORY_NAME = VARIABLE_DYNAMIC_CATEGORY_NAME; + +/** + * String for use in the "custom" attribute of a category in toolbox XML. + * This string indicates that the category should be dynamically populated with + * procedure blocks. + * @const {string} + */ +const PROCEDURE_CATEGORY_NAME = 'PROCEDURE'; +exports.PROCEDURE_CATEGORY_NAME = PROCEDURE_CATEGORY_NAME; + +/** + * String for use in the dropdown created in field_variable. + * This string indicates that this option in the dropdown is 'Rename + * variable...' and if selected, should trigger the prompt to rename a variable. + * @const {string} + */ +const RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; +exports.RENAME_VARIABLE_ID = RENAME_VARIABLE_ID; + +/** + * String for use in the dropdown created in field_variable. + * This string indicates that this option in the dropdown is 'Delete the "%1" + * variable' and if selected, should trigger the prompt to delete a variable. + * @const {string} + */ +const DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; +exports.DELETE_VARIABLE_ID = DELETE_VARIABLE_ID; From 324c3c038f81dad7ce7c321c97cc4b4b3a8ab12e Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:17:19 -0700 Subject: [PATCH 216/833] Rebuild --- tests/deps.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/deps.js b/tests/deps.js index 52ca3e4f3..d7e7ec201 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -12,7 +12,7 @@ goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'] goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); @@ -23,7 +23,7 @@ goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/constants.js', ['Blockly.constants'], ['Blockly.connectionTypes']); +goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); @@ -100,7 +100,12 @@ goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectabl goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); +<<<<<<< HEAD goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); +======= +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); +>>>>>>> 3a5ddf4d (Rebuild) goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From cc7a263fb3842ca6a2bc800288eca2d4474bfba0 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:48:56 -0700 Subject: [PATCH 217/833] Replace references to SPRITE and SOUND_LIMIT with internalConstants versions --- core/trashcan.js | 29 +++++++++++++++-------------- core/workspace_audio.js | 5 ++--- core/zoom_controls.js | 40 ++++++++++++++++++++++------------------ tests/deps.js | 6 +++--- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 831a26ba4..619299b21 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -14,13 +14,12 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.DeleteArea'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.TrashcanOpen'); goog.require('Blockly.IAutoHideable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.IPositionable'); goog.require('Blockly.Options'); goog.require('Blockly.registry'); @@ -316,17 +315,18 @@ Blockly.Trashcan.prototype.createDom = function() { }, clip); var body = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, - 'height': Blockly.SPRITE.height, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')' }, this.svgGroup_); - body.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + body.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, @@ -336,17 +336,18 @@ Blockly.Trashcan.prototype.createDom = function() { Blockly.utils.Svg.RECT, {'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip); this.svgLid_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, - 'height': Blockly.SPRITE.height, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')' }, this.svgGroup_); - this.svgLid_.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + this.svgLid_.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // bindEventWithChecks_ quashes events too aggressively. See: // https://groups.google.com/forum/#!topic/blockly/QF4yB9Wx00s diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 954b8f892..378c19287 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -13,8 +13,7 @@ goog.provide('Blockly.WorkspaceAudio'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.userAgent'); @@ -135,7 +134,7 @@ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { // Don't play one sound on top of another. var now = new Date; if (this.lastSound_ != null && - now - this.lastSound_ < Blockly.SOUND_LIMIT) { + now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 96ff41ac4..6ecf8b041 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -21,6 +21,7 @@ goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); goog.require('Blockly.IPositionable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Touch'); goog.require('Blockly.uiPosition'); goog.require('Blockly.utils'); @@ -337,17 +338,18 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { }, clip); var zoomoutSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'x': -64, 'y': -92, 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')' }, this.zoomOutGroup_); - zoomoutSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoomoutSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( @@ -388,17 +390,18 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { }, clip); var zoominSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'x': -32, 'y': -92, 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')' }, this.zoomInGroup_); - zoominSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoominSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach listener. this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( @@ -456,16 +459,17 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { }, clip); var zoomresetSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, - { - 'width': Blockly.SPRITE.width, - 'height': Blockly.SPRITE.height, + Blockly.utils.Svg.IMAGE, { + 'width': Blockly.internalConstants.SPRITE.width, + 'height': Blockly.internalConstants.SPRITE.height, 'y': -92, 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')' }, this.zoomResetGroup_); - zoomresetSvg.setAttributeNS(Blockly.utils.dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + Blockly.SPRITE.url); + zoomresetSvg.setAttributeNS( + Blockly.utils.dom.XLINK_NS, 'xlink:href', + this.workspace_.options.pathToMedia + + Blockly.internalConstants.SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( diff --git a/tests/deps.js b/tests/deps.js index d7e7ec201..abbcce849 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -177,7 +177,7 @@ goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'] goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); -goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); @@ -206,7 +206,7 @@ goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); -goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -214,6 +214,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From ad5836b26d73e153cc0f8499abdfa2534f3a94bd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 13:57:48 -0700 Subject: [PATCH 218/833] Convert more names to use internalConstants --- blocks/procedures.js | 6 ++++-- core/block_svg.js | 3 ++- core/contextmenu.js | 9 ++++----- core/gesture.js | 8 ++++---- core/insertion_marker_manager.js | 7 +++---- core/rendered_connection.js | 21 +++++++++++++-------- core/utils.js | 16 ++++++++-------- core/workspace_svg.js | 12 ++++++------ tests/deps.js | 14 +++++++------- 9 files changed, 51 insertions(+), 45 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 644d7a751..328bc89e0 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -18,6 +18,7 @@ goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Mutator'); goog.require('Blockly.Warning'); @@ -867,8 +868,9 @@ Blockly.Blocks['procedures_callnoreturn'] = { var block = Blockly.utils.xml.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); - var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); - var y = xy.y + Blockly.SNAP_RADIUS * 2; + var x = + xy.x + Blockly.internalConstants.SNAP_RADIUS * (this.RTL ? -1 : 1); + var y = xy.y + Blockly.internalConstants.SNAP_RADIUS * 2; block.setAttribute('x', x); block.setAttribute('y', y); var mutation = this.mutationToDom(); diff --git a/core/block_svg.js b/core/block_svg.js index 08e5addcb..f7da81fe3 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1550,7 +1550,8 @@ Blockly.BlockSvg.prototype.bumpNeighbours = function() { connection.targetBlock().bumpNeighbours(); } - var neighbours = connection.neighbours(Blockly.SNAP_RADIUS); + var neighbours = + connection.neighbours(Blockly.internalConstants.SNAP_RADIUS); for (var j = 0, otherConnection; (otherConnection = neighbours[j]); j++) { // If both connections are connected, that's probably fine. But if diff --git a/core/contextmenu.js b/core/contextmenu.js index e070207b7..3bfcda167 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -17,11 +17,10 @@ goog.provide('Blockly.ContextMenu'); goog.require('Blockly.browserEvents'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Menu'); goog.require('Blockly.MenuItem'); goog.require('Blockly.Msg'); @@ -195,11 +194,11 @@ Blockly.ContextMenu.callbackFactory = function(block, xml) { // Move the new block next to the old block. var xy = block.getRelativeToSurfaceXY(); if (block.RTL) { - xy.x -= Blockly.SNAP_RADIUS; + xy.x -= Blockly.internalConstants.SNAP_RADIUS; } else { - xy.x += Blockly.SNAP_RADIUS; + xy.x += Blockly.internalConstants.SNAP_RADIUS; } - xy.y += Blockly.SNAP_RADIUS * 2; + xy.y += Blockly.internalConstants.SNAP_RADIUS * 2; newBlock.moveBy(xy.x, xy.y); } finally { Blockly.Events.enable(); diff --git a/core/gesture.js b/core/gesture.js index 55378930b..77a720527 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -18,11 +18,10 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.BlockDragger'); goog.require('Blockly.browserEvents'); goog.require('Blockly.BubbleDragger'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); @@ -295,8 +294,9 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - var limitRadius = - this.flyout_ ? Blockly.FLYOUT_DRAG_RADIUS : Blockly.DRAG_RADIUS; + var limitRadius = this.flyout_ ? + Blockly.internalConstants.FLYOUT_DRAG_RADIUS : + Blockly.internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index d0fea4502..bad4f28bc 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -15,9 +15,8 @@ goog.provide('Blockly.InsertionMarkerManager'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); +goog.require('Blockly.internalConstants'); goog.requireType('Blockly.BlockSvg'); goog.requireType('Blockly.RenderedConnection'); @@ -439,9 +438,9 @@ Blockly.InsertionMarkerManager.prototype.getStartRadius_ = function() { // By increasing radiusConnection when a connection already exists, // we never "lose" the connection from the offset. if (this.closestConnection_ && this.localConnection_) { - return Blockly.CONNECTING_SNAP_RADIUS; + return Blockly.internalConstants.CONNECTING_SNAP_RADIUS; } - return Blockly.SNAP_RADIUS; + return Blockly.internalConstants.SNAP_RADIUS; }; /** diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f9d3864e3..f229a2fac 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -14,8 +14,7 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.deprecation'); @@ -173,17 +172,23 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { // Raise it to the top for extra visibility. var selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - var dx = (staticConnection.x + Blockly.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x; - var dy = (staticConnection.y + Blockly.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.y; + var dx = + (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.x; + var dy = + (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. dy = -dy; } if (rootBlock.RTL) { - dx = (staticConnection.x - Blockly.SNAP_RADIUS - - Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x; + dx = (staticConnection.x - Blockly.internalConstants.SNAP_RADIUS - + Math.floor( + Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + this.x; } rootBlock.moveBy(dx, dy); selected || rootBlock.removeSelect(); diff --git a/core/utils.js b/core/utils.js index 171e83422..8213d38d9 100644 --- a/core/utils.js +++ b/core/utils.js @@ -18,8 +18,7 @@ */ goog.provide('Blockly.utils'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.Coordinate'); @@ -194,13 +193,13 @@ Blockly.utils.getScrollDeltaPixels = function(e) { }; case 0x01: // Line mode. return { - x: e.deltaX * Blockly.LINE_MODE_MULTIPLIER, - y: e.deltaY * Blockly.LINE_MODE_MULTIPLIER + x: e.deltaX * Blockly.internalConstants.LINE_MODE_MULTIPLIER, + y: e.deltaY * Blockly.internalConstants.LINE_MODE_MULTIPLIER }; case 0x02: // Page mode. return { - x: e.deltaX * Blockly.PAGE_MODE_MULTIPLIER, - y: e.deltaY * Blockly.PAGE_MODE_MULTIPLIER + x: e.deltaX * Blockly.internalConstants.PAGE_MODE_MULTIPLIER, + y: e.deltaY * Blockly.internalConstants.PAGE_MODE_MULTIPLIER }; } }; @@ -634,8 +633,9 @@ Blockly.utils.parseBlockColour = function(colour) { if (!isNaN(hue) && 0 <= hue && hue <= 360) { return { hue: hue, - hex: Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255) + hex: Blockly.utils.colour.hsvToHex( + hue, Blockly.internalConstants.HSV_SATURATION, + Blockly.internalConstants.HSV_VALUE * 255) }; } else { var hex = Blockly.utils.colour.parse(dereferenced); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 21ee217ae..f62107e4f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -17,8 +17,6 @@ goog.require('Blockly.BlockSvg'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.ConnectionDB'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); goog.require('Blockly.Events'); @@ -31,6 +29,7 @@ goog.require('Blockly.Events.ViewportChange'); goog.require('Blockly.Gesture'); goog.require('Blockly.Grid'); goog.require('Blockly.IASTNodeLocationSvg'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.MarkerManager'); /** @suppress {extraRequire} */ goog.require('Blockly.MetricsManager'); @@ -1521,7 +1520,8 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { // Check for blocks in snap range to any of its connections. var connections = block.getConnections_(false); for (var i = 0, connection; (connection = connections[i]); i++) { - var neighbour = connection.closest(Blockly.SNAP_RADIUS, + var neighbour = connection.closest( + Blockly.internalConstants.SNAP_RADIUS, new Blockly.utils.Coordinate(blockX, blockY)); if (neighbour.connection) { collide = true; @@ -1531,11 +1531,11 @@ Blockly.WorkspaceSvg.prototype.pasteBlock_ = function(xmlBlock) { } if (collide) { if (this.RTL) { - blockX -= Blockly.SNAP_RADIUS; + blockX -= Blockly.internalConstants.SNAP_RADIUS; } else { - blockX += Blockly.SNAP_RADIUS; + blockX += Blockly.internalConstants.SNAP_RADIUS; } - blockY += Blockly.SNAP_RADIUS * 2; + blockY += Blockly.internalConstants.SNAP_RADIUS * 2; } } while (collide); block.moveBy(blockX, blockY); diff --git a/tests/deps.js b/tests/deps.js index abbcce849..a41eba2bb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -3,7 +3,7 @@ goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Block goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); -goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -24,7 +24,7 @@ goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionCheck goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); @@ -66,13 +66,13 @@ goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Bl goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); -goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es5'}); +goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_svg.js', ['Blockly.IASTNodeLocationSvg'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_ast_node_location_with_block.js', ['Blockly.IASTNodeLocationWithBlock'], ['Blockly.IASTNodeLocation'], {'lang': 'es6', 'module': 'goog'}); @@ -122,7 +122,7 @@ goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); -goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); @@ -178,7 +178,7 @@ goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.brows goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.constants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'}); @@ -212,7 +212,7 @@ goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.Works goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); -goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From 8b5f5f72d632ecbcaa55277a08c56b825ef6cf82 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:10:34 -0700 Subject: [PATCH 219/833] Refer to more constants through internalConstants --- blocks/procedures.js | 6 ++---- core/block_svg.js | 8 ++++---- core/blockly.js | 5 +++-- core/gesture.js | 2 +- core/insertion_marker_manager.js | 6 ++++-- core/mutator.js | 3 ++- core/rendered_connection.js | 2 +- core/touch.js | 6 ++---- tests/deps.js | 8 ++++---- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 328bc89e0..644d7a751 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -18,7 +18,6 @@ goog.require('Blockly.Comment'); goog.require('Blockly.FieldCheckbox'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.internalConstants'); goog.require('Blockly.Mutator'); goog.require('Blockly.Warning'); @@ -868,9 +867,8 @@ Blockly.Blocks['procedures_callnoreturn'] = { var block = Blockly.utils.xml.createElement('block'); block.setAttribute('type', this.defType_); var xy = this.getRelativeToSurfaceXY(); - var x = - xy.x + Blockly.internalConstants.SNAP_RADIUS * (this.RTL ? -1 : 1); - var y = xy.y + Blockly.internalConstants.SNAP_RADIUS * 2; + var x = xy.x + Blockly.SNAP_RADIUS * (this.RTL ? -1 : 1); + var y = xy.y + Blockly.SNAP_RADIUS * 2; block.setAttribute('x', x); block.setAttribute('y', y); var mutation = this.mutationToDom(); diff --git a/core/block_svg.js b/core/block_svg.js index f7da81fe3..fd5be3212 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -18,7 +18,6 @@ goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering.IPathObject'); goog.require('Blockly.browserEvents'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.ContextMenu'); goog.require('Blockly.ContextMenuRegistry'); @@ -31,6 +30,7 @@ goog.require('Blockly.IASTNodeLocationSvg'); goog.require('Blockly.IBoundedElement'); goog.require('Blockly.ICopyable'); goog.require('Blockly.IDraggable'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.RenderedConnection'); goog.require('Blockly.TabNavigateCursor'); @@ -688,7 +688,7 @@ Blockly.BlockSvg.prototype.updateCollapsed_ = function() { icon.setVisible(false); } - var text = this.toString(Blockly.COLLAPSE_CHARS); + var text = this.toString(Blockly.internalConstants.COLLAPSE_CHARS); var field = this.getField(collapsedFieldName); if (field) { field.setValue(text); @@ -1586,13 +1586,13 @@ Blockly.BlockSvg.prototype.scheduleSnapAndBump = function() { Blockly.Events.setGroup(group); block.snapToGrid(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY / 2); + }, Blockly.internalConstants.BUMP_DELAY / 2); setTimeout(function() { Blockly.Events.setGroup(group); block.bumpNeighbours(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY); + }, Blockly.internalConstants.BUMP_DELAY); }; /** diff --git a/core/blockly.js b/core/blockly.js index 554e02c8d..94f485c99 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -425,8 +425,9 @@ Blockly.isNumber = function(str) { * @return {string} RGB code, e.g. '#5ba65b'. */ Blockly.hueToHex = function(hue) { - return Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255); + return Blockly.utils.colour.hsvToHex( + hue, Blockly.internalConstants.HSV_SATURATION, + Blockly.internalConstants.HSV_VALUE * 255); }; /** diff --git a/core/gesture.js b/core/gesture.js index 77a720527..483d73a25 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -229,7 +229,7 @@ Blockly.Gesture = function(e, creatorWorkspace) { * @type {boolean} * @private */ - this.healStack_ = !Blockly.DRAG_STACK; + this.healStack_ = !Blockly.internalConstants.DRAG_STACK; }; /** diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index bad4f28bc..614f7e70b 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -377,8 +377,10 @@ Blockly.InsertionMarkerManager.prototype.shouldUpdatePreviews_ = function( var yDiff = this.localConnection_.y + dxy.y - this.closestConnection_.y; var curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff); // Slightly prefer the existing preview over a new preview. - return !(candidateClosest && radius > curDistance - - Blockly.CURRENT_CONNECTION_PREFERENCE); + return !( + candidateClosest && + radius > curDistance - + Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE); } else if (!this.localConnection_ && !this.closestConnection_) { // We weren't showing a preview before, but we should now. return true; diff --git a/core/mutator.js b/core/mutator.js index 1bd6d0988..2733964c7 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -20,6 +20,7 @@ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); goog.require('Blockly.Icon'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Options'); goog.require('Blockly.utils'); goog.require('Blockly.utils.dom'); @@ -444,7 +445,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { Blockly.Events.setGroup(group); block.bumpNeighbours(); Blockly.Events.setGroup(false); - }, Blockly.BUMP_DELAY); + }, Blockly.internalConstants.BUMP_DELAY); } // Don't update the bubble until the drag has ended, to avoid moving blocks diff --git a/core/rendered_connection.js b/core/rendered_connection.js index f229a2fac..14795c181 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -471,7 +471,7 @@ Blockly.RenderedConnection.prototype.onFailedConnect = this.bumpAwayFrom(otherConnection); Blockly.Events.setGroup(false); } - }.bind(this), Blockly.BUMP_DELAY); + }.bind(this), Blockly.internalConstants.BUMP_DELAY); } }; diff --git a/core/touch.js b/core/touch.js index b6668c398..7dc578663 100644 --- a/core/touch.js +++ b/core/touch.js @@ -16,8 +16,7 @@ */ goog.provide('Blockly.Touch'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.string'); @@ -107,8 +106,7 @@ Blockly.longStart = function(e, gesture) { if (gesture) { gesture.handleRightClick(e); } - - }, Blockly.LONGPRESS); + }, Blockly.internalConstants.LONGPRESS); }; /** diff --git a/tests/deps.js b/tests/deps.js index a41eba2bb..39f55df61 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -3,7 +3,7 @@ goog.addDependency('../../blocks/lists.js', ['Blockly.Constants.Lists'], ['Block goog.addDependency('../../blocks/logic.js', ['Blockly.Blocks.logic', 'Blockly.Constants.Logic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Mutator']); goog.addDependency('../../blocks/loops.js', ['Blockly.Blocks.loops', 'Blockly.Constants.Loops'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable', 'Blockly.Warning']); goog.addDependency('../../blocks/math.js', ['Blockly.Blocks.math', 'Blockly.Constants.Math'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.FieldNumber', 'Blockly.FieldVariable']); -goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.internalConstants'], {'lang': 'es5'}); +goog.addDependency('../../blocks/procedures.js', ['Blockly.Blocks.procedures'], ['Blockly', 'Blockly.Blocks', 'Blockly.Comment', 'Blockly.FieldCheckbox', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.Mutator', 'Blockly.Warning'], {'lang': 'es5'}); goog.addDependency('../../blocks/text.js', ['Blockly.Blocks.texts', 'Blockly.Constants.Text'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldMultilineInput', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.Mutator']); goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Blockly.Constants.Variables'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']); @@ -11,7 +11,7 @@ goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); -goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); @@ -116,7 +116,7 @@ goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEven goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); -goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); @@ -175,7 +175,7 @@ goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); -goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.constants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); +goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); From b3f837a8d2d9152bad0dff2b54278de32f750733 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:24:59 -0700 Subject: [PATCH 220/833] Replace references to constants with internalConstants --- core/connection_checker.js | 5 ++--- core/field_variable.js | 22 ++++++++++------------ core/generator.js | 7 +++---- core/names.js | 17 +++++++++-------- core/procedures.js | 8 ++++---- core/rendered_connection.js | 5 +++-- core/variables.js | 7 +++---- core/workspace_svg.js | 9 ++++++--- tests/deps.js | 12 ++++++------ 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 4bd7bd4e2..5dcaef376 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -16,11 +16,10 @@ goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); +const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); /** @@ -144,7 +143,7 @@ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { } if (blockA == blockB) { return Connection.REASON_SELF_CONNECTION; - } else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) { + } else if (b.type != OPPOSITE_TYPE[a.type]) { return Connection.REASON_WRONG_TYPE; } else if (blockA.workspace !== blockB.workspace) { return Connection.REASON_DIFFERENT_WORKSPACES; diff --git a/core/field_variable.js b/core/field_variable.js index 18f2d20b4..e5e379c13 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -12,13 +12,11 @@ goog.provide('Blockly.FieldVariable'); -/** @suppress {extraRequire} */ -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.FieldDropdown'); goog.require('Blockly.fieldRegistry'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('Blockly.utils.object'); @@ -417,14 +415,14 @@ Blockly.FieldVariable.dropdownCreate = function() { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } - options.push([Blockly.Msg['RENAME_VARIABLE'], Blockly.RENAME_VARIABLE_ID]); + options.push([ + Blockly.Msg['RENAME_VARIABLE'], Blockly.internalConstants.RENAME_VARIABLE_ID + ]); if (Blockly.Msg['DELETE_VARIABLE']) { - options.push( - [ - Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), - Blockly.DELETE_VARIABLE_ID - ] - ); + options.push([ + Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), + Blockly.internalConstants.DELETE_VARIABLE_ID + ]); } return options; @@ -442,12 +440,12 @@ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { var id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { - if (id == Blockly.RENAME_VARIABLE_ID) { + if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { // Rename variable. Blockly.Variables.renameVariable( this.sourceBlock_.workspace, this.variable_); return; - } else if (id == Blockly.DELETE_VARIABLE_ID) { + } else if (id == Blockly.internalConstants.DELETE_VARIABLE_ID) { // Delete variable. this.sourceBlock_.workspace.deleteVariableById(this.variable_.getId()); return; diff --git a/core/generator.js b/core/generator.js index d2af08852..e365c69ba 100644 --- a/core/generator.js +++ b/core/generator.js @@ -14,8 +14,7 @@ goog.provide('Blockly.Generator'); goog.require('Blockly.Block'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.utils.deprecation'); goog.requireType('Blockly.Names'); @@ -451,8 +450,8 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { */ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { - var functionName = this.nameDB_.getDistinctName(desiredName, - Blockly.PROCEDURE_CATEGORY_NAME); + var functionName = this.nameDB_.getDistinctName( + desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; var codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); diff --git a/core/names.js b/core/names.js index 3abd27f9e..a559321cf 100644 --- a/core/names.js +++ b/core/names.js @@ -12,8 +12,7 @@ goog.provide('Blockly.Names'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.requireType('Blockly.VariableMap'); @@ -77,7 +76,7 @@ Blockly.Names.prototype.setVariableMap = function(map) { /** * Get the name for a user-defined variable, based on its ID. * This should only be used for variables of realm - * Blockly.VARIABLE_CATEGORY_NAME. + * Blockly.internalConstants.VARIABLE_CATEGORY_NAME. * @param {string} id The ID to look up in the variable map. * @return {?string} The name of the referenced variable, or null if there was * no variable map or the variable was not found in the map. @@ -106,7 +105,8 @@ Blockly.Names.prototype.getNameForUserVariable_ = function(id) { Blockly.Names.prototype.populateVariables = function(workspace) { var variables = Blockly.Variables.allUsedVarModels(workspace); for (var i = 0; i < variables.length; i++) { - this.getName(variables[i].getId(), Blockly.VARIABLE_CATEGORY_NAME); + this.getName( + variables[i].getId(), Blockly.internalConstants.VARIABLE_CATEGORY_NAME); } }; @@ -119,7 +119,8 @@ Blockly.Names.prototype.populateProcedures = function(workspace) { // Flatten the return vs no-return procedure lists. procedures = procedures[0].concat(procedures[1]); for (var i = 0; i < procedures.length; i++) { - this.getName(procedures[i][0], Blockly.PROCEDURE_CATEGORY_NAME); + this.getName( + procedures[i][0], Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); } }; @@ -133,7 +134,7 @@ Blockly.Names.prototype.populateProcedures = function(workspace) { */ Blockly.Names.prototype.getName = function(nameOrId, realm) { var name = nameOrId; - if (realm == Blockly.VARIABLE_CATEGORY_NAME) { + if (realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME) { var varName = this.getNameForUserVariable_(nameOrId); if (varName) { // Successful ID lookup. @@ -142,7 +143,7 @@ Blockly.Names.prototype.getName = function(nameOrId, realm) { } var normalizedName = name.toLowerCase(); - var isVar = realm == Blockly.VARIABLE_CATEGORY_NAME || + var isVar = realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME || realm == Blockly.Names.DEVELOPER_VARIABLE_TYPE; var prefix = isVar ? this.variablePrefix_ : ''; @@ -189,7 +190,7 @@ Blockly.Names.prototype.getDistinctName = function(name, realm) { } safeName += i; this.dbReverse_[safeName] = true; - var isVar = realm == Blockly.VARIABLE_CATEGORY_NAME || + var isVar = realm == Blockly.internalConstants.VARIABLE_CATEGORY_NAME || realm == Blockly.Names.DEVELOPER_VARIABLE_TYPE; var prefix = isVar ? this.variablePrefix_ : ''; return prefix + safeName; diff --git a/core/procedures.js b/core/procedures.js index 984ef03fa..3323bb130 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -17,12 +17,11 @@ goog.provide('Blockly.Procedures'); goog.require('Blockly.Blocks'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.Names'); goog.require('Blockly.utils.xml'); @@ -37,9 +36,10 @@ goog.requireType('Blockly.WorkspaceSvg'); /** * Constant to separate procedure names from variables and generated functions * when running generators. - * @deprecated Use Blockly.PROCEDURE_CATEGORY_NAME + * @deprecated Use Blockly.internalConstants.PROCEDURE_CATEGORY_NAME */ -Blockly.Procedures.NAME_TYPE = Blockly.PROCEDURE_CATEGORY_NAME; +Blockly.Procedures.NAME_TYPE = + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME; /** * The default argument for a procedures_mutatorarg block. diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 14795c181..cddda9200 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -50,8 +50,9 @@ Blockly.RenderedConnection = function(source, type) { * @const {!Blockly.ConnectionDB} * @private */ - this.dbOpposite_ = source.workspace - .connectionDBList[Blockly.OPPOSITE_TYPE[type]]; + this.dbOpposite_ = + source.workspace + .connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. diff --git a/core/variables.js b/core/variables.js index 1c091898e..223838a2b 100644 --- a/core/variables.js +++ b/core/variables.js @@ -17,8 +17,7 @@ goog.provide('Blockly.Variables'); goog.require('Blockly.Blocks'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); +goog.require('Blockly.internalConstants'); goog.require('Blockly.Msg'); goog.require('Blockly.utils'); goog.require('Blockly.utils.xml'); @@ -31,9 +30,9 @@ goog.requireType('Blockly.Workspace'); /** * Constant to separate variable names from procedures and generated functions * when running generators. - * @deprecated Use Blockly.VARIABLE_CATEGORY_NAME + * @deprecated Use Blockly.internalConstants.VARIABLE_CATEGORY_NAME */ -Blockly.Variables.NAME_TYPE = Blockly.VARIABLE_CATEGORY_NAME; +Blockly.Variables.NAME_TYPE = Blockly.internalConstants.VARIABLE_CATEGORY_NAME; /** * Find all user-created variables that are in use in the workspace. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index f62107e4f..1c3cee44f 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -180,15 +180,18 @@ Blockly.WorkspaceSvg = function( this.flyoutButtonCallbacks_ = Object.create(null); if (Blockly.Variables && Blockly.Variables.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.VARIABLE_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.VARIABLE_CATEGORY_NAME, Blockly.Variables.flyoutCategory); } if (Blockly.VariablesDynamic && Blockly.VariablesDynamic.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME, Blockly.VariablesDynamic.flyoutCategory); } if (Blockly.Procedures && Blockly.Procedures.flyoutCategory) { - this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME, + this.registerToolboxCategoryCallback( + Blockly.internalConstants.PROCEDURE_CATEGORY_NAME, Blockly.Procedures.flyoutCategory); this.addChangeListener(Blockly.Procedures.mutatorOpenListener); } diff --git a/tests/deps.js b/tests/deps.js index 39f55df61..8570bfd1c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -20,7 +20,7 @@ goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], [' goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); @@ -60,12 +60,12 @@ goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilin goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object']); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); +goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.constants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); @@ -117,10 +117,10 @@ goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.uti goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); -goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.constants']); +goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.internalConstants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils.xml']); +goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); @@ -201,7 +201,7 @@ goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); -goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.xml']); +goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); From cf7a8b95b847be2f6136f121601bc81c5c8674df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Jul 2021 14:51:58 -0700 Subject: [PATCH 221/833] Remove extra requires of Blockly.constants --- core/flyout_horizontal.js | 2 -- core/input.js | 2 -- core/keyboard_nav/ast_node.js | 2 -- core/renderers/common/constants.js | 2 -- core/renderers/common/debugger.js | 2 -- core/renderers/common/marker_svg.js | 2 -- core/renderers/common/renderer.js | 2 -- core/renderers/geras/info.js | 2 -- core/renderers/zelos/constants.js | 2 -- core/renderers/zelos/info.js | 2 -- core/renderers/zelos/renderer.js | 2 -- core/xml.js | 3 -- core/zoom_controls.js | 2 -- tests/deps.js | 48 +++++++++++++---------------- 14 files changed, 21 insertions(+), 54 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 485d29617..66e9ff18e 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -14,8 +14,6 @@ goog.provide('Blockly.HorizontalFlyout'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.DropDownDiv'); goog.require('Blockly.Flyout'); goog.require('Blockly.registry'); diff --git a/core/input.js b/core/input.js index 57189c278..443bfc83f 100644 --- a/core/input.js +++ b/core/input.js @@ -13,8 +13,6 @@ goog.provide('Blockly.Input'); goog.require('Blockly.Connection'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.fieldRegistry'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 37145a090..332e9af8c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,8 +13,6 @@ goog.provide('Blockly.ASTNode'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.Coordinate'); goog.requireType('Blockly.Block'); diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index a21ef85aa..5c73d0510 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,8 +13,6 @@ goog.provide('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); diff --git a/core/renderers/common/debugger.js b/core/renderers/common/debugger.js index 0e99fc613..a6ab9d387 100644 --- a/core/renderers/common/debugger.js +++ b/core/renderers/common/debugger.js @@ -17,8 +17,6 @@ goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Row'); goog.require('Blockly.blockRendering.Types'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); diff --git a/core/renderers/common/marker_svg.js b/core/renderers/common/marker_svg.js index f9559e071..36d12b119 100644 --- a/core/renderers/common/marker_svg.js +++ b/core/renderers/common/marker_svg.js @@ -15,8 +15,6 @@ goog.provide('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.ASTNode'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.MarkerMove'); diff --git a/core/renderers/common/renderer.js b/core/renderers/common/renderer.js index 77df5e518..37e4a883a 100644 --- a/core/renderers/common/renderer.js +++ b/core/renderers/common/renderer.js @@ -20,8 +20,6 @@ goog.require('Blockly.blockRendering.MarkerSvg'); goog.require('Blockly.blockRendering.PathObject'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.IRegistrable'); diff --git a/core/renderers/geras/info.js b/core/renderers/geras/info.js index ffc515a17..121e3b353 100644 --- a/core/renderers/geras/info.js +++ b/core/renderers/geras/info.js @@ -19,8 +19,6 @@ goog.require('Blockly.blockRendering.InputRow'); goog.require('Blockly.blockRendering.InRowSpacer'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.geras.InlineInput'); goog.require('Blockly.geras.StatementInput'); goog.require('Blockly.inputTypes'); diff --git a/core/renderers/zelos/constants.js b/core/renderers/zelos/constants.js index bb039250a..2070197cf 100644 --- a/core/renderers/zelos/constants.js +++ b/core/renderers/zelos/constants.js @@ -15,8 +15,6 @@ goog.provide('Blockly.zelos.ConstantProvider'); goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.utils.colour'); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.object'); diff --git a/core/renderers/zelos/info.js b/core/renderers/zelos/info.js index b7dc3d972..078031756 100644 --- a/core/renderers/zelos/info.js +++ b/core/renderers/zelos/info.js @@ -18,8 +18,6 @@ goog.require('Blockly.blockRendering.InRowSpacer'); goog.require('Blockly.blockRendering.Measurable'); goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Types'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.FieldImage'); goog.require('Blockly.FieldLabel'); goog.require('Blockly.FieldTextInput'); diff --git a/core/renderers/zelos/renderer.js b/core/renderers/zelos/renderer.js index d192fa178..3c5287bbb 100644 --- a/core/renderers/zelos/renderer.js +++ b/core/renderers/zelos/renderer.js @@ -15,8 +15,6 @@ goog.provide('Blockly.zelos.Renderer'); goog.require('Blockly.blockRendering'); goog.require('Blockly.blockRendering.Renderer'); goog.require('Blockly.connectionTypes'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.InsertionMarkerManager'); goog.require('Blockly.utils.object'); goog.require('Blockly.zelos.ConstantProvider'); diff --git a/core/xml.js b/core/xml.js index 4140d6528..e581bfd01 100644 --- a/core/xml.js +++ b/core/xml.js @@ -15,9 +15,6 @@ * @namespace */ goog.provide('Blockly.Xml'); - -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Events'); goog.require('Blockly.inputTypes'); goog.require('Blockly.utils'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 6ecf8b041..7d0d7e6ce 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -14,8 +14,6 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); -/** @suppress {extraRequire} */ -goog.require('Blockly.constants'); goog.require('Blockly.Css'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ diff --git a/tests/deps.js b/tests/deps.js index 8570bfd1c..2d1386395 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); @@ -48,9 +48,9 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -63,14 +63,14 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); @@ -80,7 +80,6 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -94,23 +93,18 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -<<<<<<< HEAD -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); -======= goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); ->>>>>>> 3a5ddf4d (Rebuild) -goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); @@ -124,19 +118,19 @@ goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); -goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes', 'Blockly.constants']); +goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); goog.addDependency('../../core/renderers/geras/highlight_constants.js', ['Blockly.geras.HighlightConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/highlighter.js', ['Blockly.geras.Highlighter'], ['Blockly.blockRendering.Types', 'Blockly.utils.svgPaths']); -goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); +goog.addDependency('../../core/renderers/geras/info.js', ['Blockly.geras', 'Blockly.geras.RenderInfo'], ['Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.geras.InlineInput', 'Blockly.geras.StatementInput', 'Blockly.inputTypes', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/measurables/inputs.js', ['Blockly.geras.InlineInput', 'Blockly.geras.StatementInput'], ['Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/geras/path_object.js', ['Blockly.geras.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.PathObject', 'Blockly.geras.ConstantProvider', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); 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']); @@ -152,15 +146,15 @@ goog.addDependency('../../core/renderers/minimalist/info.js', ['Blockly.minimali goog.addDependency('../../core/renderers/minimalist/renderer.js', ['Blockly.minimalist.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.minimalist.ConstantProvider', 'Blockly.minimalist.Drawer', 'Blockly.minimalist.RenderInfo', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/thrasos/info.js', ['Blockly.thrasos', 'Blockly.thrasos.RenderInfo'], ['Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/thrasos/renderer.js', ['Blockly.thrasos.Renderer'], ['Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.thrasos.RenderInfo', 'Blockly.utils.object']); -goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/zelos/constants.js', ['Blockly.zelos.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.svgPaths'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/zelos/drawer.js', ['Blockly.zelos.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.utils.object', 'Blockly.utils.svgPaths', 'Blockly.zelos.RenderInfo']); -goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); +goog.addDependency('../../core/renderers/zelos/info.js', ['Blockly.zelos', 'Blockly.zelos.RenderInfo'], ['Blockly.FieldImage', 'Blockly.FieldLabel', 'Blockly.FieldTextInput', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Types', 'Blockly.inputTypes', 'Blockly.utils.object', 'Blockly.zelos.BottomRow', 'Blockly.zelos.RightConnectionShape', 'Blockly.zelos.TopRow']); goog.addDependency('../../core/renderers/zelos/marker_svg.js', ['Blockly.zelos.MarkerSvg'], ['Blockly.blockRendering.MarkerSvg', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/zelos/measurables/inputs.js', ['Blockly.zelos.StatementInput'], ['Blockly.blockRendering.StatementInput', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/measurables/row_elements.js', ['Blockly.zelos.RightConnectionShape'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.Types', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/measurables/rows.js', ['Blockly.zelos.BottomRow', 'Blockly.zelos.TopRow'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.TopRow', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos.PathObject'], ['Blockly.blockRendering.PathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider']); -goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); +goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); @@ -196,7 +190,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); @@ -213,7 +207,7 @@ goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCom goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('base.js', [], []); From 12636da1824cce1eb429d61ca974556e2b1208cb Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 21 Jul 2021 15:47:55 -0700 Subject: [PATCH 222/833] Reorder some requires and rebuild --- core/connection_checker.js | 2 +- core/internal_constants.js | 1 + tests/deps.js | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/connection_checker.js b/core/connection_checker.js index 5dcaef376..8b2abfaab 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -16,10 +16,10 @@ goog.module.declareLegacyNamespace(); const Connection = goog.require('Blockly.Connection'); const IConnectionChecker = goog.require('Blockly.IConnectionChecker'); -const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); const connectionTypes = goog.require('Blockly.connectionTypes'); const registry = goog.require('Blockly.registry'); +const {OPPOSITE_TYPE} = goog.require('Blockly.internalConstants'); /** diff --git a/core/internal_constants.js b/core/internal_constants.js index b5a8cd568..b97c723b4 100644 --- a/core/internal_constants.js +++ b/core/internal_constants.js @@ -8,6 +8,7 @@ * @fileoverview Module that provides constants for use inside Blockly. Do not * use these constants outside of the core library. * @author fenichel@google.com (Rachel Fenichel) + * @package */ 'use strict'; diff --git a/tests/deps.js b/tests/deps.js index 2d1386395..74d330e51 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -29,7 +29,7 @@ goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea']); -goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget']); +goog.addDependency('../../core/drag_target.js', ['Blockly.DragTarget'], ['Blockly.IDragTarget'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/dropdowndiv.js', ['Blockly.DropDownDiv'], ['Blockly.utils.Rect', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.style']); goog.addDependency('../../core/events/block_events.js', ['Blockly.Events.BlockBase', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Events.Change', 'Blockly.Events.Create', 'Blockly.Events.Delete', 'Blockly.Events.Move'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/events/events.js', ['Blockly.Events'], ['Blockly.registry', 'Blockly.utils']); @@ -48,9 +48,9 @@ goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarB goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); @@ -80,6 +80,7 @@ goog.addDependency('../../core/interfaces/i_autohideable.js', ['Blockly.IAutoHid goog.addDependency('../../core/interfaces/i_block_dragger.js', ['Blockly.IBlockDragger'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bounded_element.js', ['Blockly.IBoundedElement'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_bubble.js', ['Blockly.IBubble'], ['Blockly.IContextMenu', 'Blockly.IDraggable'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_collapsible_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem'], ['Blockly.ISelectableToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_component.js', ['Blockly.IComponent'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_connection_checker.js', ['Blockly.IConnectionChecker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_contextmenu.js', ['Blockly.IContextMenu'], [], {'lang': 'es6', 'module': 'goog'}); @@ -93,18 +94,19 @@ goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.I goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], []); -goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], []); +goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_registrable_field.js', ['Blockly.IRegistrableField'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_selectable.js', ['Blockly.ISelectable'], [], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/interfaces/i_selectable_toolbox_item.js', ['Blockly.ISelectableToolboxItem'], ['Blockly.IToolboxItem'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.ICollapsibleToolboxItem', 'Blockly.ISelectableToolboxItem', 'Blockly.IToolboxItem'], []); +goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); -goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object']); +goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); @@ -122,7 +124,7 @@ goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRe goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); -goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.inputTypes']); +goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); @@ -190,7 +192,7 @@ goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.constants']); +goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); From c6650f0b8313b9ab93cf8ce3a2badd7a03e8c997 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 21 Jul 2021 16:53:08 -0700 Subject: [PATCH 223/833] Remove need for require instead of requireType for Block in ASTNode (#5157) --- core/keyboard_nav/ast_node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 332e9af8c..d86a22a4c 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -418,7 +418,7 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { */ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); - if (!(curLocation instanceof Blockly.Block)) { + if (curLocation.getSourceBlock) { curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( curLocation).getSourceBlock(); } From f1a41023d9a21ccd121c10aea22eb897a9a95925 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:27:35 -0700 Subject: [PATCH 224/833] Migrate core/field_registry.js to ES6 const/let --- core/field_registry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_registry.js b/core/field_registry.js index 7f431ff7d..463308d3e 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -54,7 +54,7 @@ Blockly.fieldRegistry.unregister = function(type) { * @package */ Blockly.fieldRegistry.fromJson = function(options) { - var fieldObject = /** @type {?Blockly.IRegistrableField} */ ( + const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); if (!fieldObject) { console.warn('Blockly could not create a field of type ' + options['type'] + From 063dc8b804af6caa117afbe361b5cfde7ec6fd22 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:30:54 -0700 Subject: [PATCH 225/833] Migrate core/field_registry.js to goog.module --- core/field_registry.js | 14 +++++++++----- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index 463308d3e..f1c342579 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.fieldRegistry'); +goog.module('Blockly.fieldRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.registry'); @@ -31,17 +32,19 @@ goog.requireType('Blockly.IRegistrableField'); * registered, or the fieldClass is not an object containing a fromJson * function. */ -Blockly.fieldRegistry.register = function(type, fieldClass) { +const register = function(type, fieldClass) { Blockly.registry.register(Blockly.registry.Type.FIELD, type, fieldClass); }; +exports.register = register; /** * Unregisters the field registered with the given type. * @param {string} type The field type name as used in the JSON definition. */ -Blockly.fieldRegistry.unregister = function(type) { +const unregister = function(type) { Blockly.registry.unregister(Blockly.registry.Type.FIELD, type); }; +exports.unregister = unregister; /** * Construct a Field from a JSON arg object. @@ -51,9 +54,8 @@ Blockly.fieldRegistry.unregister = function(type) { * to the field type. * @return {?Blockly.Field} The new field instance or null if a field wasn't * found with the given type name - * @package */ -Blockly.fieldRegistry.fromJson = function(options) { +const fromJson = function(options) { const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); if (!fieldObject) { @@ -65,3 +67,5 @@ Blockly.fieldRegistry.fromJson = function(options) { } return fieldObject.fromJson(options); }; +/** @package */ +exports.fromJson = fromJson; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..2cb4d384f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -58,7 +58,7 @@ goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockl goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); +goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); From 222b23480253e7a35e0b426baa2a9fa07b966ed2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:34:55 -0700 Subject: [PATCH 226/833] Migrate core/field_registry.js to named requires --- core/field_registry.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index f1c342579..1ae36d903 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -15,25 +15,26 @@ goog.module('Blockly.fieldRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.registry'); - -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IRegistrableField'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IRegistrableField = goog.requireType('Blockly.IRegistrableField'); +const registry = goog.require('Blockly.registry'); /** * Registers a field type. - * Blockly.fieldRegistry.fromJson uses this registry to + * fieldRegistry.fromJson uses this registry to * find the appropriate field type. * @param {string} type The field type name as used in the JSON definition. - * @param {!Blockly.IRegistrableField} fieldClass The field class containing a + * @param {!IRegistrableField} fieldClass The field class containing a * fromJson function that can construct an instance of the field. * @throws {Error} if the type name is empty, the field is already * registered, or the fieldClass is not an object containing a fromJson * function. */ const register = function(type, fieldClass) { - Blockly.registry.register(Blockly.registry.Type.FIELD, type, fieldClass); + registry.register(registry.Type.FIELD, type, fieldClass); }; exports.register = register; @@ -42,22 +43,22 @@ exports.register = register; * @param {string} type The field type name as used in the JSON definition. */ const unregister = function(type) { - Blockly.registry.unregister(Blockly.registry.Type.FIELD, type); + registry.unregister(registry.Type.FIELD, type); }; exports.unregister = unregister; /** * Construct a Field from a JSON arg object. * Finds the appropriate registered field by the type name as registered using - * Blockly.fieldRegistry.register. + * fieldRegistry.register. * @param {!Object} options A JSON object with a type and options specific * to the field type. - * @return {?Blockly.Field} The new field instance or null if a field wasn't + * @return {?Field} The new field instance or null if a field wasn't * found with the given type name */ const fromJson = function(options) { - const fieldObject = /** @type {?Blockly.IRegistrableField} */ ( - Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type'])); + const fieldObject = /** @type {?IRegistrableField} */ ( + registry.getObject(registry.Type.FIELD, options['type'])); if (!fieldObject) { console.warn('Blockly could not create a field of type ' + options['type'] + '. The field is probably not being registered. This could be because' + From 223ec1dd6c717dc12ccf1e9d78f6a4eb783f93e9 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:35:25 -0700 Subject: [PATCH 227/833] clang-format core/field_registry.js --- core/field_registry.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/field_registry.js b/core/field_registry.js index 1ae36d903..97c149346 100644 --- a/core/field_registry.js +++ b/core/field_registry.js @@ -58,12 +58,13 @@ exports.unregister = unregister; */ const fromJson = function(options) { const fieldObject = /** @type {?IRegistrableField} */ ( - registry.getObject(registry.Type.FIELD, options['type'])); + registry.getObject(registry.Type.FIELD, options['type'])); if (!fieldObject) { - console.warn('Blockly could not create a field of type ' + options['type'] + - '. The field is probably not being registered. This could be because' + - ' the file is not loaded, the field does not register itself (Issue' + - ' #1584), or the registration is not being reached.'); + console.warn( + 'Blockly could not create a field of type ' + options['type'] + + '. The field is probably not being registered. This could be because' + + ' the file is not loaded, the field does not register itself (Issue' + + ' #1584), or the registration is not being reached.'); return null; } return fieldObject.fromJson(options); From c3eaf1afc5061f8d20665355b070724e2acfd584 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:44:28 -0700 Subject: [PATCH 228/833] Migrate core/field_textinput.js to ES6 const/let --- core/field_textinput.js | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index b2153b65e..c4c55dfcf 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -109,7 +109,7 @@ Blockly.FieldTextInput.prototype.DEFAULT_VALUE = ''; * @nocollapse */ Blockly.FieldTextInput.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -150,12 +150,12 @@ Blockly.FieldTextInput.prototype.initView = function() { if (this.getConstants().FULL_BLOCK_FIELDS) { // Step one: figure out if this is the only field on this block. // Rendering is quite different in that case. - var nFields = 0; - var nConnections = 0; + let nFields = 0; + let nConnections = 0; // Count the number of fields, excluding text fields - for (var i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { - for (var j = 0; (input.fieldRow[j]); j++) { + for (let i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { + for (let j = 0; (input.fieldRow[j]); j++) { nFields ++; } if (input.connection) { @@ -203,7 +203,7 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; - var oldValue = this.value_; + const oldValue = this.value_; // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Blockly.Events.isEnabled()) { @@ -257,7 +257,7 @@ Blockly.FieldTextInput.prototype.render_ = function() { // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { this.resizeEditor_(); - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); Blockly.utils.aria.setState(htmlInput, @@ -296,7 +296,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; - var quietInput = opt_quietInput || false; + const quietInput = opt_quietInput || false; if (!quietInput && (Blockly.utils.userAgent.MOBILE || Blockly.utils.userAgent.ANDROID || Blockly.utils.userAgent.IPAD)) { @@ -343,28 +343,28 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { */ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { Blockly.Events.setGroup(true); - var div = Blockly.WidgetDiv.DIV; + const div = Blockly.WidgetDiv.DIV; Blockly.utils.dom.addClass(this.getClickTarget_(), 'editing'); - var htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); + const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var scale = this.workspace_.getScale(); - var fontSize = + const scale = this.workspace_.getScale(); + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - var borderRadius = + let borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { - var bBox = this.getScaledBBox(); + const bBox = this.getScaledBBox(); // Override border radius. borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block - var strokeColour = this.sourceBlock_.getParent() ? + const strokeColour = this.sourceBlock_.getParent() ? this.sourceBlock_.getParent().style.colourTertiary : this.sourceBlock_.style.colourTertiary; htmlInput.style.border = (1 * scale) + 'px solid ' + strokeColour; @@ -409,7 +409,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { // Actual disposal. this.unbindInputEvents_(); - var style = Blockly.WidgetDiv.DIV.style; + const style = Blockly.WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; @@ -477,11 +477,11 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { * @private */ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { - var text = this.htmlInput_.value; + const text = this.htmlInput_.value; if (text !== this.htmlInput_.oldValue_) { this.htmlInput_.oldValue_ = text; - var value = this.getValueFromEditorText_(text); + const value = this.getValueFromEditorText_(text); this.setValue(value); this.forceRerender(); this.resizeEditor_(); @@ -512,15 +512,15 @@ Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { * @protected */ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { - var div = Blockly.WidgetDiv.DIV; - var bBox = this.getScaledBBox(); + const div = Blockly.WidgetDiv.DIV; + const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; div.style.height = bBox.bottom - bBox.top + 'px'; // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. - var x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; - var xy = new Blockly.utils.Coordinate(x, bBox.top); + const x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; + const xy = new Blockly.utils.Coordinate(x, bBox.top); div.style.left = xy.x + 'px'; div.style.top = xy.y + 'px'; From d2a43460d0de014ee671de42f123a6f4ae1bc523 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 08:49:08 -0700 Subject: [PATCH 229/833] Migrate core/field_textinput.js to goog.module --- core/field_textinput.js | 77 +++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index c4c55dfcf..4585ba382 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldTextInput'); +goog.module('Blockly.FieldTextInput'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.DropDownDiv'); @@ -46,7 +47,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { +const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * Allow browser to spellcheck this field. * @type {boolean} @@ -54,7 +55,7 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.spellcheck_ = true; - Blockly.FieldTextInput.superClass_.constructor.call(this, + FieldTextInput.superClass_.constructor.call(this, opt_value, opt_validator, opt_config); /** @@ -91,24 +92,24 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.workspace_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldTextInput, Blockly.Field); +Blockly.utils.object.inherits(FieldTextInput, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldTextInput.prototype.DEFAULT_VALUE = ''; +FieldTextInput.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldTextInput from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!Blockly.FieldTextInput} The new field instance. + * @return {!FieldTextInput} The new field instance. * @package * @nocollapse */ -Blockly.FieldTextInput.fromJson = function(options) { +FieldTextInput.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. @@ -120,24 +121,24 @@ Blockly.FieldTextInput.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldTextInput.prototype.SERIALIZABLE = true; +FieldTextInput.prototype.SERIALIZABLE = true; /** * Pixel size of input border radius. * Should match blocklyText's border-radius in CSS. */ -Blockly.FieldTextInput.BORDERRADIUS = 4; +FieldTextInput.BORDERRADIUS = 4; /** * Mouse cursor style when over the hotspot that initiates the editor. */ -Blockly.FieldTextInput.prototype.CURSOR = 'text'; +FieldTextInput.prototype.CURSOR = 'text'; /** * @override */ -Blockly.FieldTextInput.prototype.configure_ = function(config) { - Blockly.FieldTextInput.superClass_.configure_.call(this, config); +FieldTextInput.prototype.configure_ = function(config) { + FieldTextInput.superClass_.configure_.call(this, config); if (typeof config['spellcheck'] == 'boolean') { this.spellcheck_ = config['spellcheck']; } @@ -146,7 +147,7 @@ Blockly.FieldTextInput.prototype.configure_ = function(config) { /** * @override */ -Blockly.FieldTextInput.prototype.initView = function() { +FieldTextInput.prototype.initView = function() { if (this.getConstants().FULL_BLOCK_FIELDS) { // Step one: figure out if this is the only field on this block. // Rendering is quite different in that case. @@ -184,7 +185,7 @@ Blockly.FieldTextInput.prototype.initView = function() { * @return {*} A valid string, or null if invalid. * @protected */ -Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { +FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -200,7 +201,7 @@ Blockly.FieldTextInput.prototype.doClassValidation_ = function(opt_newValue) { * the htmlInput_. * @protected */ -Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { +FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { if (this.isBeingEdited_) { this.isTextValid_ = false; const oldValue = this.value_; @@ -221,7 +222,7 @@ Blockly.FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { * that this is a string. * @protected */ -Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { +FieldTextInput.prototype.doValueUpdate_ = function(newValue) { this.isTextValid_ = true; this.value_ = newValue; if (!this.isBeingEdited_) { @@ -234,7 +235,7 @@ Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { * Updates text field to match the colour/style of the block. * @package */ -Blockly.FieldTextInput.prototype.applyColour = function() { +FieldTextInput.prototype.applyColour = function() { if (this.sourceBlock_ && this.getConstants().FULL_BLOCK_FIELDS) { if (this.borderRect_) { this.borderRect_.setAttribute('stroke', @@ -251,8 +252,8 @@ Blockly.FieldTextInput.prototype.applyColour = function() { * field's value. * @protected */ -Blockly.FieldTextInput.prototype.render_ = function() { - Blockly.FieldTextInput.superClass_.render_.call(this); +FieldTextInput.prototype.render_ = function() { + FieldTextInput.superClass_.render_.call(this); // This logic is done in render_ rather than doValueInvalid_ or // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { @@ -274,7 +275,7 @@ Blockly.FieldTextInput.prototype.render_ = function() { * Set whether this field is spellchecked by the browser. * @param {boolean} check True if checked. */ -Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { +FieldTextInput.prototype.setSpellcheck = function(check) { if (check == this.spellcheck_) { return; } @@ -292,7 +293,7 @@ Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { * focus. Defaults to false. * @protected */ -Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, +FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; @@ -311,7 +312,7 @@ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, * Mobile browsers have issues with in-line textareas (focus and keyboards). * @private */ -Blockly.FieldTextInput.prototype.showPromptEditor_ = function() { +FieldTextInput.prototype.showPromptEditor_ = function() { Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { this.setValue(this.getValueFromEditorText_(text)); @@ -324,7 +325,7 @@ Blockly.FieldTextInput.prototype.showPromptEditor_ = function() { * focus. * @private */ -Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { +FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { Blockly.WidgetDiv.show( this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); @@ -341,7 +342,7 @@ Blockly.FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { * @return {!HTMLElement} The newly created text input editor. * @protected */ -Blockly.FieldTextInput.prototype.widgetCreate_ = function() { +FieldTextInput.prototype.widgetCreate_ = function() { Blockly.Events.setGroup(true); const div = Blockly.WidgetDiv.DIV; @@ -356,7 +357,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; let borderRadius = - (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + (FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { const bBox = this.getScaledBBox(); @@ -395,7 +396,7 @@ Blockly.FieldTextInput.prototype.widgetCreate_ = function() { * DOM-references belonging to the editor. * @protected */ -Blockly.FieldTextInput.prototype.widgetDispose_ = function() { +FieldTextInput.prototype.widgetDispose_ = function() { // Non-disposal related things that we do when the editor closes. this.isBeingEdited_ = false; this.isTextValid_ = true; @@ -426,7 +427,7 @@ Blockly.FieldTextInput.prototype.widgetDispose_ = function() { * handlers will be bound. * @protected */ -Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { +FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); @@ -439,7 +440,7 @@ Blockly.FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { * Unbind handlers for user input and workspace size changes. * @protected */ -Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { +FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { Blockly.browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; @@ -455,7 +456,7 @@ Blockly.FieldTextInput.prototype.unbindInputEvents_ = function() { * @param {!Event} e Keyboard event. * @protected */ -Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { +FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { if (e.keyCode == Blockly.utils.KeyCodes.ENTER) { Blockly.WidgetDiv.hide(); Blockly.DropDownDiv.hideWithoutAnimation(); @@ -476,7 +477,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { * @param {!Event} _e Keyboard event. * @private */ -Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { +FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { const text = this.htmlInput_.value; if (text !== this.htmlInput_.oldValue_) { this.htmlInput_.oldValue_ = text; @@ -495,7 +496,7 @@ Blockly.FieldTextInput.prototype.onHtmlInputChange_ = function(_e) { * @param {*} newValue New value. * @protected */ -Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { +FieldTextInput.prototype.setEditorValue_ = function(newValue) { this.isDirty_ = true; if (this.isBeingEdited_) { // In the case this method is passed an invalid value, we still @@ -511,7 +512,7 @@ Blockly.FieldTextInput.prototype.setEditorValue_ = function(newValue) { * Resize the editor to fit the text. * @protected */ -Blockly.FieldTextInput.prototype.resizeEditor_ = function() { +FieldTextInput.prototype.resizeEditor_ = function() { const div = Blockly.WidgetDiv.DIV; const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; @@ -531,7 +532,7 @@ Blockly.FieldTextInput.prototype.resizeEditor_ = function() { * @return {boolean} True if the field is tab navigable. * @override */ -Blockly.FieldTextInput.prototype.isTabNavigable = function() { +FieldTextInput.prototype.isTabNavigable = function() { return true; }; @@ -544,7 +545,7 @@ Blockly.FieldTextInput.prototype.isTabNavigable = function() { * @protected * @override */ -Blockly.FieldTextInput.prototype.getText_ = function() { +FieldTextInput.prototype.getText_ = function() { if (this.isBeingEdited_ && this.htmlInput_) { // We are currently editing, return the HTML input value instead. return this.htmlInput_.value; @@ -561,7 +562,7 @@ Blockly.FieldTextInput.prototype.getText_ = function() { * @return {string} The text to show on the HTML input. * @protected */ -Blockly.FieldTextInput.prototype.getEditorText_ = function(value) { +FieldTextInput.prototype.getEditorText_ = function(value) { return String(value); }; @@ -575,8 +576,10 @@ Blockly.FieldTextInput.prototype.getEditorText_ = function(value) { * @return {*} The value to store. * @protected */ -Blockly.FieldTextInput.prototype.getValueFromEditorText_ = function(text) { +FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -Blockly.fieldRegistry.register('field_input', Blockly.FieldTextInput); +Blockly.fieldRegistry.register('field_input', FieldTextInput); + +exports = FieldTextInput; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..0e96aa2c3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -59,7 +59,7 @@ goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabe goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); From 9134d45d94e3d3506e7b1b9d3bb2bac18d8b45b8 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:35:59 -0700 Subject: [PATCH 230/833] Migrate core/menu.js to ES6 const/let --- core/menu.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/core/menu.js b/core/menu.js index 97f47248a..011199252 100644 --- a/core/menu.js +++ b/core/menu.js @@ -118,7 +118,8 @@ Blockly.Menu.prototype.addChild = function(menuItem) { * @param {!Element} container Element upon which to append this menu. */ Blockly.Menu.prototype.render = function(container) { - var element = /** @type {!HTMLDivElement} */ (document.createElement('div')); + const element = /** @type {!HTMLDivElement} */ (document.createElement( + 'div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; @@ -128,7 +129,7 @@ Blockly.Menu.prototype.render = function(container) { this.element_ = element; // Add menu items. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { element.appendChild(menuItem.createDom()); } @@ -161,7 +162,7 @@ Blockly.Menu.prototype.getElement = function() { * @package */ Blockly.Menu.prototype.focus = function() { - var el = this.getElement(); + const el = this.getElement(); if (el) { el.focus({preventScroll:true}); Blockly.utils.dom.addClass(el, 'blocklyFocused'); @@ -173,7 +174,7 @@ Blockly.Menu.prototype.focus = function() { * @private */ Blockly.Menu.prototype.blur_ = function() { - var el = this.getElement(); + const el = this.getElement(); if (el) { el.blur(); Blockly.utils.dom.removeClass(el, 'blocklyFocused'); @@ -216,7 +217,7 @@ Blockly.Menu.prototype.dispose = function() { } // Remove menu items. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { menuItem.dispose(); } this.element_ = null; @@ -232,7 +233,7 @@ Blockly.Menu.prototype.dispose = function() { * @private */ Blockly.Menu.prototype.getMenuItem_ = function(elem) { - var menuElem = this.getElement(); + const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. // Walk up parents until one meets either the menu's root element, or @@ -240,7 +241,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { while (elem && elem != menuElem) { if (Blockly.utils.dom.hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. - for (var i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { + for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { return menuItem; } @@ -259,7 +260,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { * @package */ Blockly.Menu.prototype.setHighlighted = function(item) { - var currentHighlighted = this.highlightedItem_; + const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); this.highlightedItem_ = null; @@ -269,7 +270,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { this.highlightedItem_ = item; // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. - var el = /** @type {!Element} */ (this.getElement()); + const el = /** @type {!Element} */ (this.getElement()); Blockly.utils.style.scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); @@ -284,7 +285,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { * @package */ Blockly.Menu.prototype.highlightNext = function() { - var index = this.menuItems_.indexOf(this.highlightedItem_); + const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index, 1); }; @@ -294,7 +295,7 @@ Blockly.Menu.prototype.highlightNext = function() { * @package */ Blockly.Menu.prototype.highlightPrevious = function() { - var index = this.menuItems_.indexOf(this.highlightedItem_); + const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); }; @@ -322,8 +323,8 @@ Blockly.Menu.prototype.highlightLast_ = function() { * @private */ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { - var index = startIndex + delta; - var menuItem; + let index = startIndex + delta; + let menuItem; while ((menuItem = this.menuItems_[index])) { if (menuItem.isEnabled()) { this.setHighlighted(menuItem); @@ -341,7 +342,7 @@ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { * @private */ Blockly.Menu.prototype.handleMouseOver_ = function(e) { - var menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); + const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { if (menuItem.isEnabled()) { @@ -360,11 +361,11 @@ Blockly.Menu.prototype.handleMouseOver_ = function(e) { * @private */ Blockly.Menu.prototype.handleClick_ = function(e) { - var oldCoords = this.openingCoords; + const oldCoords = this.openingCoords; // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; if (oldCoords && typeof e.clientX == 'number') { - var newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); if (Blockly.utils.Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same @@ -374,7 +375,7 @@ Blockly.Menu.prototype.handleClick_ = function(e) { } } - var menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); + const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { menuItem.performAction(); } @@ -419,7 +420,7 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { return; } - var highlighted = this.highlightedItem_; + const highlighted = this.highlightedItem_; switch (e.keyCode) { case Blockly.utils.KeyCodes.ENTER: case Blockly.utils.KeyCodes.SPACE: @@ -461,8 +462,9 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { * @package */ Blockly.Menu.prototype.getSize = function() { - var menuDom = this.getElement(); - var menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); + const menuDom = this.getElement(); + const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ + (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; From 4b19c7ecb5bc873009ba7621dff90054b1b141c3 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:41:32 -0700 Subject: [PATCH 231/833] Migrate core/menu.js to goog.module --- core/menu.js | 47 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/menu.js b/core/menu.js index 011199252..d1faf4415 100644 --- a/core/menu.js +++ b/core/menu.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Menu'); +goog.module('Blockly.Menu'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.utils.aria'); @@ -27,7 +28,7 @@ goog.requireType('Blockly.utils.Size'); * A basic menu class. * @constructor */ -Blockly.Menu = function() { +const Menu = function() { /** * Array of menu items. * (Nulls are never in the array, but typing the array as nullable prevents @@ -109,7 +110,7 @@ Blockly.Menu = function() { * Add a new menu item to the bottom of this menu. * @param {!Blockly.MenuItem} menuItem Menu item to append. */ -Blockly.Menu.prototype.addChild = function(menuItem) { +Menu.prototype.addChild = function(menuItem) { this.menuItems_.push(menuItem); }; @@ -117,7 +118,7 @@ Blockly.Menu.prototype.addChild = function(menuItem) { * Creates the menu DOM. * @param {!Element} container Element upon which to append this menu. */ -Blockly.Menu.prototype.render = function(container) { +Menu.prototype.render = function(container) { const element = /** @type {!HTMLDivElement} */ (document.createElement( 'div')); // goog-menu is deprecated, use blocklyMenu. May 2020. @@ -153,7 +154,7 @@ Blockly.Menu.prototype.render = function(container) { * @return {?Element} The DOM element. * @package */ -Blockly.Menu.prototype.getElement = function() { +Menu.prototype.getElement = function() { return this.element_; }; @@ -161,7 +162,7 @@ Blockly.Menu.prototype.getElement = function() { * Focus the menu element. * @package */ -Blockly.Menu.prototype.focus = function() { +Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll:true}); @@ -173,7 +174,7 @@ Blockly.Menu.prototype.focus = function() { * Blur the menu element. * @private */ -Blockly.Menu.prototype.blur_ = function() { +Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); @@ -186,14 +187,14 @@ Blockly.Menu.prototype.blur_ = function() { * @param {!Blockly.utils.aria.Role} roleName role name. * @package */ -Blockly.Menu.prototype.setRole = function(roleName) { +Menu.prototype.setRole = function(roleName) { this.roleName_ = roleName; }; /** * Dispose of this menu. */ -Blockly.Menu.prototype.dispose = function() { +Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { Blockly.browserEvents.unbind(this.mouseOverHandler_); @@ -232,7 +233,7 @@ Blockly.Menu.prototype.dispose = function() { * @return {?Blockly.MenuItem} Menu item for which the DOM element belongs to. * @private */ -Blockly.Menu.prototype.getMenuItem_ = function(elem) { +Menu.prototype.getMenuItem_ = function(elem) { const menuElem = this.getElement(); // Node might be the menu border (resulting in no associated menu item), or // a menu item's div, or some element within the menu item. @@ -259,7 +260,7 @@ Blockly.Menu.prototype.getMenuItem_ = function(elem) { * @param {?Blockly.MenuItem} item Item to highlight, or null. * @package */ -Blockly.Menu.prototype.setHighlighted = function(item) { +Menu.prototype.setHighlighted = function(item) { const currentHighlighted = this.highlightedItem_; if (currentHighlighted) { currentHighlighted.setHighlighted(false); @@ -284,7 +285,7 @@ Blockly.Menu.prototype.setHighlighted = function(item) { * highlighted). * @package */ -Blockly.Menu.prototype.highlightNext = function() { +Menu.prototype.highlightNext = function() { const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index, 1); }; @@ -294,7 +295,7 @@ Blockly.Menu.prototype.highlightNext = function() { * currently highlighted). * @package */ -Blockly.Menu.prototype.highlightPrevious = function() { +Menu.prototype.highlightPrevious = function() { const index = this.menuItems_.indexOf(this.highlightedItem_); this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); }; @@ -303,7 +304,7 @@ Blockly.Menu.prototype.highlightPrevious = function() { * Highlights the first highlightable item. * @private */ -Blockly.Menu.prototype.highlightFirst_ = function() { +Menu.prototype.highlightFirst_ = function() { this.highlightHelper_(-1, 1); }; @@ -311,7 +312,7 @@ Blockly.Menu.prototype.highlightFirst_ = function() { * Highlights the last highlightable item. * @private */ -Blockly.Menu.prototype.highlightLast_ = function() { +Menu.prototype.highlightLast_ = function() { this.highlightHelper_(this.menuItems_.length, -1); }; @@ -322,7 +323,7 @@ Blockly.Menu.prototype.highlightLast_ = function() { * @param {number} delta Step direction: 1 to go down, -1 to go up. * @private */ -Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { +Menu.prototype.highlightHelper_ = function(startIndex, delta) { let index = startIndex + delta; let menuItem; while ((menuItem = this.menuItems_[index])) { @@ -341,7 +342,7 @@ Blockly.Menu.prototype.highlightHelper_ = function(startIndex, delta) { * @param {!Event} e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseOver_ = function(e) { +Menu.prototype.handleMouseOver_ = function(e) { const menuItem = this.getMenuItem_(/** @type {Element} */ (e.target)); if (menuItem) { @@ -360,7 +361,7 @@ Blockly.Menu.prototype.handleMouseOver_ = function(e) { * @param {!Event} e Click event to handle. * @private */ -Blockly.Menu.prototype.handleClick_ = function(e) { +Menu.prototype.handleClick_ = function(e) { const oldCoords = this.openingCoords; // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; @@ -386,7 +387,7 @@ Blockly.Menu.prototype.handleClick_ = function(e) { * @param {!Event} _e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseEnter_ = function(_e) { +Menu.prototype.handleMouseEnter_ = function(_e) { this.focus(); }; @@ -395,7 +396,7 @@ Blockly.Menu.prototype.handleMouseEnter_ = function(_e) { * @param {!Event} _e Mouse event to handle. * @private */ -Blockly.Menu.prototype.handleMouseLeave_ = function(_e) { +Menu.prototype.handleMouseLeave_ = function(_e) { if (this.getElement()) { this.blur_(); this.setHighlighted(null); @@ -410,7 +411,7 @@ Blockly.Menu.prototype.handleMouseLeave_ = function(_e) { * @param {!Event} e Key event to handle. * @private */ -Blockly.Menu.prototype.handleKeyEvent_ = function(e) { +Menu.prototype.handleKeyEvent_ = function(e) { if (!this.menuItems_.length) { // Empty menu. return; @@ -461,7 +462,7 @@ Blockly.Menu.prototype.handleKeyEvent_ = function(e) { * @return {!Blockly.utils.Size} Object with width and height properties. * @package */ -Blockly.Menu.prototype.getSize = function() { +Menu.prototype.getSize = function() { const menuDom = this.getElement(); const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ (menuDom)); @@ -469,3 +470,5 @@ Blockly.Menu.prototype.getSize = function() { menuSize.height = menuDom.scrollHeight; return menuSize; }; + +exports = Menu; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..477087f5c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -108,7 +108,7 @@ goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Bl goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); -goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style']); +goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); From 6dd36c3432c499d862f18096861b9aa35efa7bf6 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:47:09 -0700 Subject: [PATCH 232/833] Migrate core/menu.js named requires --- core/menu.js | 99 ++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/core/menu.js b/core/menu.js index d1faf4415..df7f8058d 100644 --- a/core/menu.js +++ b/core/menu.js @@ -13,15 +13,14 @@ goog.module('Blockly.Menu'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.style'); - -goog.requireType('Blockly.MenuItem'); -goog.requireType('Blockly.utils.Size'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const MenuItem = goog.requireType('Blockly.MenuItem'); +const Size = goog.requireType('Blockly.utils.Size'); +const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); +const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); +const {DOWN, END, ENTER, HOME, PAGE_DOWN, PAGE_UP, SPACE, UP} = goog.require('Blockly.utils.KeyCodes'); +const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); +const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); /** @@ -33,7 +32,7 @@ const Menu = function() { * Array of menu items. * (Nulls are never in the array, but typing the array as nullable prevents * the compiler from objecting to .indexOf(null)) - * @type {!Array} + * @type {!Array} * @private */ this.menuItems_ = []; @@ -42,7 +41,7 @@ const Menu = function() { * Coordinates of the mousedown event that caused this menu to open. Used to * prevent the consequent mouseup event due to a simple click from activating * a menu item immediately. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @package */ this.openingCoords = null; @@ -50,42 +49,42 @@ const Menu = function() { /** * This is the element that we will listen to the real focus events on. * A value of null means no menu item is highlighted. - * @type {?Blockly.MenuItem} + * @type {?MenuItem} * @private */ this.highlightedItem_ = null; /** * Mouse over event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseOverHandler_ = null; /** * Click event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.clickHandler_ = null; /** * Mouse enter event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseEnterHandler_ = null; /** * Mouse leave event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.mouseLeaveHandler_ = null; /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?Data} * @private */ this.onKeyDownHandler_ = null; @@ -99,7 +98,7 @@ const Menu = function() { /** * ARIA name for this menu. - * @type {?Blockly.utils.aria.Role} + * @type {?Role} * @private */ this.roleName_ = null; @@ -108,7 +107,7 @@ const Menu = function() { /** * Add a new menu item to the bottom of this menu. - * @param {!Blockly.MenuItem} menuItem Menu item to append. + * @param {!MenuItem} menuItem Menu item to append. */ Menu.prototype.addChild = function(menuItem) { this.menuItems_.push(menuItem); @@ -125,7 +124,7 @@ Menu.prototype.render = function(container) { element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; if (this.roleName_) { - Blockly.utils.aria.setRole(element, this.roleName_); + setRole(element, this.roleName_); } this.element_ = element; @@ -135,15 +134,15 @@ Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseOverHandler_ = conditionalBind( element, 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = Blockly.browserEvents.conditionalBind( + this.clickHandler_ = conditionalBind( element, 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseEnterHandler_ = conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = Blockly.browserEvents.conditionalBind( + this.mouseLeaveHandler_ = conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownHandler_ = conditionalBind( element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); @@ -166,7 +165,7 @@ Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll:true}); - Blockly.utils.dom.addClass(el, 'blocklyFocused'); + addClass(el, 'blocklyFocused'); } }; @@ -178,13 +177,13 @@ Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); - Blockly.utils.dom.removeClass(el, 'blocklyFocused'); + removeClass(el, 'blocklyFocused'); } }; /** * Set the menu accessibility role. - * @param {!Blockly.utils.aria.Role} roleName role name. + * @param {!Role} roleName role name. * @package */ Menu.prototype.setRole = function(roleName) { @@ -197,23 +196,23 @@ Menu.prototype.setRole = function(roleName) { Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - Blockly.browserEvents.unbind(this.mouseOverHandler_); + unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - Blockly.browserEvents.unbind(this.clickHandler_); + unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - Blockly.browserEvents.unbind(this.mouseEnterHandler_); + unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - Blockly.browserEvents.unbind(this.mouseLeaveHandler_); + unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - Blockly.browserEvents.unbind(this.onKeyDownHandler_); + unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } @@ -230,7 +229,7 @@ Menu.prototype.dispose = function() { * Returns the child menu item that owns the given DOM element, * or null if no such menu item is found. * @param {Element} elem DOM element whose owner is to be returned. - * @return {?Blockly.MenuItem} Menu item for which the DOM element belongs to. + * @return {?MenuItem} Menu item for which the DOM element belongs to. * @private */ Menu.prototype.getMenuItem_ = function(elem) { @@ -240,7 +239,7 @@ Menu.prototype.getMenuItem_ = function(elem) { // Walk up parents until one meets either the menu's root element, or // a menu item's div. while (elem && elem != menuElem) { - if (Blockly.utils.dom.hasClass(elem, 'blocklyMenuItem')) { + if (hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { @@ -257,7 +256,7 @@ Menu.prototype.getMenuItem_ = function(elem) { /** * Highlights the given menu item, or clears highlighting if null. - * @param {?Blockly.MenuItem} item Item to highlight, or null. + * @param {?MenuItem} item Item to highlight, or null. * @package */ Menu.prototype.setHighlighted = function(item) { @@ -272,10 +271,10 @@ Menu.prototype.setHighlighted = function(item) { // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. const el = /** @type {!Element} */ (this.getElement()); - Blockly.utils.style.scrollIntoContainerView( + scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - Blockly.utils.aria.setState(el, Blockly.utils.aria.State.ACTIVEDESCENDANT, + setState(el, State.ACTIVEDESCENDANT, item.getId()); } }; @@ -366,8 +365,8 @@ Menu.prototype.handleClick_ = function(e) { // Clear out the saved opening coords immediately so they're not used twice. this.openingCoords = null; if (oldCoords && typeof e.clientX == 'number') { - const newCoords = new Blockly.utils.Coordinate(e.clientX, e.clientY); - if (Blockly.utils.Coordinate.distance(oldCoords, newCoords) < 1) { + const newCoords = new Coordinate(e.clientX, e.clientY); + if (Coordinate.distance(oldCoords, newCoords) < 1) { // This menu was opened by a mousedown and we're handling the consequent // click event. The coords haven't changed, meaning this was the same // opening event. Don't do the usual behavior because the menu just popped @@ -423,28 +422,28 @@ Menu.prototype.handleKeyEvent_ = function(e) { const highlighted = this.highlightedItem_; switch (e.keyCode) { - case Blockly.utils.KeyCodes.ENTER: - case Blockly.utils.KeyCodes.SPACE: + case ENTER: + case SPACE: if (highlighted) { highlighted.performAction(); } break; - case Blockly.utils.KeyCodes.UP: + case UP: this.highlightPrevious(); break; - case Blockly.utils.KeyCodes.DOWN: + case DOWN: this.highlightNext(); break; - case Blockly.utils.KeyCodes.PAGE_UP: - case Blockly.utils.KeyCodes.HOME: + case PAGE_UP: + case HOME: this.highlightFirst_(); break; - case Blockly.utils.KeyCodes.PAGE_DOWN: - case Blockly.utils.KeyCodes.END: + case PAGE_DOWN: + case END: this.highlightLast_(); break; @@ -459,12 +458,12 @@ Menu.prototype.handleKeyEvent_ = function(e) { /** * Get the size of a rendered menu. - * @return {!Blockly.utils.Size} Object with width and height properties. + * @return {!Size} Object with width and height properties. * @package */ Menu.prototype.getSize = function() { const menuDom = this.getElement(); - const menuSize = Blockly.utils.style.getSize(/** @type {!Element} */ + const menuSize = getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; From e5468a50b4e5cca373e72281a482d532ac855172 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:47:58 -0700 Subject: [PATCH 233/833] clang-format core/menu.js --- core/menu.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/core/menu.js b/core/menu.js index df7f8058d..85672f717 100644 --- a/core/menu.js +++ b/core/menu.js @@ -118,8 +118,8 @@ Menu.prototype.addChild = function(menuItem) { * @param {!Element} container Element upon which to append this menu. */ Menu.prototype.render = function(container) { - const element = /** @type {!HTMLDivElement} */ (document.createElement( - 'div')); + const element = + /** @type {!HTMLDivElement} */ (document.createElement('div')); // goog-menu is deprecated, use blocklyMenu. May 2020. element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; @@ -134,16 +134,16 @@ Menu.prototype.render = function(container) { } // Add event handlers. - this.mouseOverHandler_ = conditionalBind( - element, 'mouseover', this, this.handleMouseOver_, true); - this.clickHandler_ = conditionalBind( - element, 'click', this, this.handleClick_, true); + this.mouseOverHandler_ = + conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); + this.clickHandler_ = + conditionalBind(element, 'click', this, this.handleClick_, true); this.mouseEnterHandler_ = conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); this.mouseLeaveHandler_ = conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); - this.onKeyDownHandler_ = conditionalBind( - element, 'keydown', this, this.handleKeyEvent_); + this.onKeyDownHandler_ = + conditionalBind(element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -164,7 +164,7 @@ Menu.prototype.getElement = function() { Menu.prototype.focus = function() { const el = this.getElement(); if (el) { - el.focus({preventScroll:true}); + el.focus({preventScroll: true}); addClass(el, 'blocklyFocused'); } }; @@ -274,8 +274,7 @@ Menu.prototype.setHighlighted = function(item) { scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - setState(el, State.ACTIVEDESCENDANT, - item.getId()); + setState(el, State.ACTIVEDESCENDANT, item.getId()); } }; @@ -464,7 +463,7 @@ Menu.prototype.handleKeyEvent_ = function(e) { Menu.prototype.getSize = function() { const menuDom = this.getElement(); const menuSize = getSize(/** @type {!Element} */ - (menuDom)); + (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; return menuSize; From 296eed06fbd64d7e6b554665a3332806da495b0b Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 09:01:59 -0700 Subject: [PATCH 234/833] Fix build --- core/menu.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/menu.js b/core/menu.js index 85672f717..ac79922cf 100644 --- a/core/menu.js +++ b/core/menu.js @@ -18,7 +18,7 @@ const MenuItem = goog.requireType('Blockly.MenuItem'); const Size = goog.requireType('Blockly.utils.Size'); const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); -const {DOWN, END, ENTER, HOME, PAGE_DOWN, PAGE_UP, SPACE, UP} = goog.require('Blockly.utils.KeyCodes'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); @@ -421,28 +421,28 @@ Menu.prototype.handleKeyEvent_ = function(e) { const highlighted = this.highlightedItem_; switch (e.keyCode) { - case ENTER: - case SPACE: + case KeyCodes.ENTER: + case KeyCodes.SPACE: if (highlighted) { highlighted.performAction(); } break; - case UP: + case KeyCodes.UP: this.highlightPrevious(); break; - case DOWN: + case KeyCodes.DOWN: this.highlightNext(); break; - case PAGE_UP: - case HOME: + case KeyCodes.PAGE_UP: + case KeyCodes.HOME: this.highlightFirst_(); break; - case PAGE_DOWN: - case END: + case KeyCodes.PAGE_DOWN: + case KeyCodes.END: this.highlightLast_(); break; From efdc9e3afab6993d69c80799d263492913310d4a Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 09:11:54 -0700 Subject: [PATCH 235/833] Support filepath as first argument and cleanup (#5168) --- scripts/goog_module/convert-file.sh | 125 ++++++++++++++-------------- 1 file changed, 61 insertions(+), 64 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 1861ad7f3..fa66fe0f9 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -1,7 +1,7 @@ #!/bin/bash ####################################### -# Logging functions +# Logging functions. ####################################### COLOR_NONE="\033[0m" GREEN="\033[0;32m" @@ -20,17 +20,24 @@ warn() { err() { echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 } + ####################################### # Checks whether the provided filepath exists. # Arguments: # The filepath to check for existence. +# Optional: Whether to log an error. ####################################### verify-filepath() { - if [[ ! -f "$1" ]]; then - err "File $1 does not exist" + local filepath="$1" + local no_log="$2" + if [[ ! -f "${filepath}" ]]; then + if [[ -z "${no_log}" || "${no_log}" == 'true' ]]; then + err "File ${filepath} does not exist" + fi return 1 fi } + ####################################### # Creates a commit with a message based on the specified step and file. # Arguments: @@ -40,11 +47,11 @@ verify-filepath() { commit-step() { local step="$1" local filepath="$2" - if [ -z "${step}" ]; then + if [[ -z "${step}" ]]; then err "Missing argument (1-4)" return 1 fi - if [ -z "${filepath}" ]; then + if [[ -z "${filepath}" ]]; then err "Missing argument filepath" return 1 fi @@ -78,6 +85,7 @@ commit-step() { git commit -m "${message}" success "created commit with message: \"${message}\"" } + ####################################### # Runs step 2 of the automated conversion. # Arguments: @@ -85,25 +93,10 @@ commit-step() { ####################################### step2 () { local filepath="$1" - if [ -z "${filepath}" ]; then - err "Missing argument filepath" - return 1 - fi - - inf "Verifying single goog.provide declarations..." - local provide_count=$(grep -o 'goog.provide' ${filepath} | wc -l) - if [[ "${provide_count}" -gt "1" ]]; then - err "Cannot convert file with multiple provides. Please split the file first." - return 1 - elif [[ "${provide_count}" -eq "0" ]]; then - err "Cannot convert file without a provide." - return 1 - fi inf "Updating goog.provide declaration..." perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" - inf "Extracting module name..." local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then @@ -117,11 +110,9 @@ step2 () { inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" - inf 'Updating class properties...' - perl -pi -e 's/^'"${module_name}"'((\.\w+)+) =/'"${class_name}"'\1 =/g' "${filepath}" inf "Updating local references to class..." - perl -pi -e 's/'"${module_name}"'([^'\''])/'"${class_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${module_name}"'(?!['\''\w])/'"${class_name}"'/g' "${filepath}" inf "Appending class export to end of file..." echo "" >> "${filepath}" @@ -140,20 +131,15 @@ step2 () { perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" npm run build:deps - success "Completed automation for step 3. Please manually review and add exports for non-private top-level functions." + success "Completed automation for step 2. Please manually review and add exports for non-private top-level functions." } + ####################################### # Runs step 3 of the automated conversion. # Arguments: # The filepath of the file being converted. ####################################### step3() { - local filepath="$1" - if [ -z "${filepath}" ]; then - err "Missing argument filepath" - return 1 - fi - inf "Extracting module name..." local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") if [[ -z "${module_name}" ]]; then @@ -162,10 +148,10 @@ step3() { fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle'print $& while m{^goog.require(|Type)\('\''(.*)'\''\)}g' "${filepath}" | perl -pe 's/goog.require(|Type)\('\''(.*)'\''\)/\2/g') + local requires=$(perl -nle'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") # Process each require - echo "${requires}" | while read -r require ; do + echo "${requires}" | while read -r require; do inf "Processing require \"${require}\"" local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) @@ -179,27 +165,25 @@ step3() { # Detect requires overlap # (ex: Blockly.utils require and Blockly.utils.dom also in requires) local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${requires_overlap}" ]]; then - while read -r requires_overlap_prop ; do + if [[ -n "${requires_overlap}" ]]; then + while read -r requires_overlap_prop; do properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') done <<<"${requires_overlap}" fi # Detect module name overlap # (ex: Blockly require and Blockly.ContextMenuItems module being converted) local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ ! -z "${module_overlap}" ]]; then + if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') fi properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) - if [[ "${direct_access_count}" -eq "0" && ! -z "${properties_accessed}" ]]; then + if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"" - - inf "Updating require declaration for ${require}..." + inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"..." perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - for require_prop in $(echo "${properties_accessed}"); do + for require_prop in echo "${properties_accessed}"; do inf "Updating references of ${require}.${require_prop} to ${require_prop}..." perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" done @@ -215,26 +199,24 @@ step3() { done local missing_requires=$(perl -nle'print $& while m{(?|-s ] " - echo " -h Display help" - echo " -c Create a commit for the specified step [2-4]" - echo " -s Run the specified step [1-4]" + echo "Usage: $0 [-h] [-c |-s ]" + echo " -h Display help and exit" + echo " -c Create a commit for the specified step [2-4]" + echo " -s Run the specified step [1-4]" } -if [ "$1" = "" ]; then +####################################### +# Main entry point. +####################################### +main { + if [ "$1" = "" ]; then help else - command="$1" + local filepath="" + # Support filepath as first argument. + verify-filepath "${filepath}" "false" + if [[ $? -eq 0 ]]; then + filepath="$1" + shift + fi + + local command="$1" shift case $command in - -h) help $@;; - -c) commit-step $@;; - -s) run-step $@;; - *) help;; + -c) commit-step "$@" "${filepath}" ;; + -s) run-step "$@" "${filepath}" ;; + *) err "INVALID ARGUMENT ${command}";; esac fi +} + +main "$@" From 720059e502394ebc44e4d01686d2b67f652a32f5 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 09:59:02 -0700 Subject: [PATCH 236/833] Fix bugs (#5175) --- scripts/goog_module/convert-file.sh | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index fa66fe0f9..24529dab1 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -257,7 +257,7 @@ run-step() { ####################################### # Prints usage information. ####################################### -help { +help() { echo "Conversion steps:" echo " 1. Use IDE to convert var to let/const" echo " 2. Rewrite the goog.provide statement as goog.module and explicitly enumerate exports" @@ -273,26 +273,26 @@ help { ####################################### # Main entry point. ####################################### -main { +main() { if [ "$1" = "" ]; then - help -else - local filepath="" - # Support filepath as first argument. - verify-filepath "${filepath}" "false" - if [[ $? -eq 0 ]]; then - filepath="$1" - shift - fi + help + else + local filepath="" + # Support filepath as first argument. + verify-filepath "$1" "false" + if [[ $? -eq 0 ]]; then + filepath="$1" + shift + fi - local command="$1" - shift - case $command in - -c) commit-step "$@" "${filepath}" ;; - -s) run-step "$@" "${filepath}" ;; - *) err "INVALID ARGUMENT ${command}";; - esac -fi + local command="$1" + shift + case $command in + -c) commit-step "$@" "${filepath}" ;; + -s) run-step "$@" "${filepath}" ;; + *) err "INVALID ARGUMENT ${command}";; + esac + fi } main "$@" From 9d29bff7138b954351c6ed9bee23504ae40cf795 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Thu, 22 Jul 2021 10:01:41 -0700 Subject: [PATCH 237/833] Ask before deconstructing properties for a require (#5169) --- scripts/goog_module/convert-file.sh | 35 +++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 24529dab1..8b6bdfc6f 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -20,6 +20,9 @@ warn() { err() { echo -e "${RED}[ERROR]:${COLOR_NONE} $*" >&2 } +reenter_instructions() { + echo -e "${ORANGE}$*${COLOR_NONE}" >&2 +} ####################################### # Checks whether the provided filepath exists. @@ -180,14 +183,32 @@ step3() { if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - inf "Deconstructing ${require} into \"{${deconstructed_comma}}\"..." - perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const \{'"${deconstructed_comma}"'\} = \1/' "${filepath}" - - for require_prop in echo "${properties_accessed}"; do - inf "Updating references of ${require}.${require_prop} to ${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_prop}"'\1/g' "${filepath}" + local confirm='' + while true; do + read -p "Would you like to deconstruct ${require} into \"{${deconstructed_comma}}\"? (y/n): " yn Date: Thu, 22 Jul 2021 10:21:57 -0700 Subject: [PATCH 238/833] Migrate core/field_textinput.js to named requires --- core/field_textinput.js | 120 ++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 4585ba382..07c0e3282 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -13,25 +13,27 @@ goog.module('Blockly.FieldTextInput'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Events = goog.require('Blockly.Events'); +const Field = goog.require('Blockly.Field'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Msg = goog.require('Blockly.Msg'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const aria = goog.require('Blockly.utils.aria'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {inherits} = goog.require('Blockly.utils.object'); +const {prompt: blocklyPrompt} = goog.require('Blockly'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -44,7 +46,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldTextInput = function(opt_value, opt_validator, opt_config) { @@ -66,14 +68,14 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * Key down event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onKeyDownWrapper_ = null; /** * Key input event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onKeyInputWrapper_ = null; @@ -87,12 +89,12 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { /** * The workspace that this field belongs to. - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @protected */ this.workspace_ = null; }; -Blockly.utils.object.inherits(FieldTextInput, Blockly.Field); +inherits(FieldTextInput, Field); /** * The default value for this field. @@ -110,7 +112,7 @@ FieldTextInput.prototype.DEFAULT_VALUE = ''; * @nocollapse */ FieldTextInput.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldTextInput if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -207,8 +209,8 @@ FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { const oldValue = this.value_; // Revert value when the text becomes invalid. this.value_ = this.htmlInput_.untypedDefaultValue_; - if (this.sourceBlock_ && Blockly.Events.isEnabled()) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + if (this.sourceBlock_ && Events.isEnabled()) { + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); } } @@ -260,13 +262,13 @@ FieldTextInput.prototype.render_ = function() { this.resizeEditor_(); const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, true); + dom.addClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, true); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, false); + dom.removeClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, false); } } }; @@ -296,11 +298,11 @@ FieldTextInput.prototype.setSpellcheck = function(check) { FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { this.workspace_ = - (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; + (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; const quietInput = opt_quietInput || false; - if (!quietInput && (Blockly.utils.userAgent.MOBILE || - Blockly.utils.userAgent.ANDROID || - Blockly.utils.userAgent.IPAD)) { + if (!quietInput && (userAgent.MOBILE || + userAgent.ANDROID || + userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -313,7 +315,7 @@ FieldTextInput.prototype.showEditor_ = function(_opt_e, * @private */ FieldTextInput.prototype.showPromptEditor_ = function() { - Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.getText(), + blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { this.setValue(this.getValueFromEditorText_(text)); }.bind(this)); @@ -326,7 +328,7 @@ FieldTextInput.prototype.showPromptEditor_ = function() { * @private */ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { - Blockly.WidgetDiv.show( + WidgetDiv.show( this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); this.isBeingEdited_ = true; @@ -343,10 +345,10 @@ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { * @protected */ FieldTextInput.prototype.widgetCreate_ = function() { - Blockly.Events.setGroup(true); - const div = Blockly.WidgetDiv.DIV; + Events.setGroup(true); + const div = WidgetDiv.DIV; - Blockly.utils.dom.addClass(this.getClickTarget_(), 'editing'); + dom.addClass(this.getClickTarget_(), 'editing'); const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; @@ -406,11 +408,11 @@ FieldTextInput.prototype.widgetDispose_ = function() { if (this.onFinishEditing_) { this.onFinishEditing_(this.value_); } - Blockly.Events.setGroup(false); + Events.setGroup(false); // Actual disposal. this.unbindInputEvents_(); - const style = Blockly.WidgetDiv.DIV.style; + const style = WidgetDiv.DIV.style; style.width = 'auto'; style.height = 'auto'; style.fontSize = ''; @@ -418,7 +420,7 @@ FieldTextInput.prototype.widgetDispose_ = function() { style.boxShadow = ''; this.htmlInput_ = null; - Blockly.utils.dom.removeClass(this.getClickTarget_(), 'editing'); + dom.removeClass(this.getClickTarget_(), 'editing'); }; /** @@ -429,10 +431,10 @@ FieldTextInput.prototype.widgetDispose_ = function() { */ FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { // Trap Enter without IME and Esc to hide. - this.onKeyDownWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyDownWrapper_ = browserEvents.conditionalBind( htmlInput, 'keydown', this, this.onHtmlInputKeyDown_); // Resize after every input change. - this.onKeyInputWrapper_ = Blockly.browserEvents.conditionalBind( + this.onKeyInputWrapper_ = browserEvents.conditionalBind( htmlInput, 'input', this, this.onHtmlInputChange_); }; @@ -442,11 +444,11 @@ FieldTextInput.prototype.bindInputEvents_ = function(htmlInput) { */ FieldTextInput.prototype.unbindInputEvents_ = function() { if (this.onKeyDownWrapper_) { - Blockly.browserEvents.unbind(this.onKeyDownWrapper_); + browserEvents.unbind(this.onKeyDownWrapper_); this.onKeyDownWrapper_ = null; } if (this.onKeyInputWrapper_) { - Blockly.browserEvents.unbind(this.onKeyInputWrapper_); + browserEvents.unbind(this.onKeyInputWrapper_); this.onKeyInputWrapper_ = null; } }; @@ -457,16 +459,16 @@ FieldTextInput.prototype.unbindInputEvents_ = function() { * @protected */ FieldTextInput.prototype.onHtmlInputKeyDown_ = function(e) { - if (e.keyCode == Blockly.utils.KeyCodes.ENTER) { - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); - } else if (e.keyCode == Blockly.utils.KeyCodes.ESC) { + if (e.keyCode == KeyCodes.ENTER) { + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); + } else if (e.keyCode == KeyCodes.ESC) { this.setValue(this.htmlInput_.untypedDefaultValue_); - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); - } else if (e.keyCode == Blockly.utils.KeyCodes.TAB) { - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); + } else if (e.keyCode == KeyCodes.TAB) { + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); this.sourceBlock_.tab(this, !e.shiftKey); e.preventDefault(); } @@ -513,7 +515,7 @@ FieldTextInput.prototype.setEditorValue_ = function(newValue) { * @protected */ FieldTextInput.prototype.resizeEditor_ = function() { - const div = Blockly.WidgetDiv.DIV; + const div = WidgetDiv.DIV; const bBox = this.getScaledBBox(); div.style.width = bBox.right - bBox.left + 'px'; div.style.height = bBox.bottom - bBox.top + 'px'; @@ -521,7 +523,7 @@ FieldTextInput.prototype.resizeEditor_ = function() { // In RTL mode block fields and LTR input fields the left edge moves, // whereas the right edge is fixed. Reposition the editor. const x = this.sourceBlock_.RTL ? bBox.right - div.offsetWidth : bBox.left; - const xy = new Blockly.utils.Coordinate(x, bBox.top); + const xy = new Coordinate(x, bBox.top); div.style.left = xy.x + 'px'; div.style.top = xy.y + 'px'; @@ -580,6 +582,6 @@ FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -Blockly.fieldRegistry.register('field_input', FieldTextInput); +fieldRegistry.register('field_input', FieldTextInput); exports = FieldTextInput; diff --git a/tests/deps.js b/tests/deps.js index 0e96aa2c3..c68a0441f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -59,7 +59,7 @@ goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabe goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); -goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); From 13272c37136992a91639e6c27ed0fcd100f9cabb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:23:06 -0700 Subject: [PATCH 239/833] clang-format core/field_textinput.js --- core/field_textinput.js | 76 +++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/core/field_textinput.js b/core/field_textinput.js index 07c0e3282..cfa891e34 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -44,7 +44,8 @@ goog.require('Blockly.Events.BlockChange'); * changes to the field's value. Takes in a string & returns a validated * string, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/text-input#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -57,8 +58,8 @@ const FieldTextInput = function(opt_value, opt_validator, opt_config) { */ this.spellcheck_ = true; - FieldTextInput.superClass_.constructor.call(this, - opt_value, opt_validator, opt_config); + FieldTextInput.superClass_.constructor.call( + this, opt_value, opt_validator, opt_config); /** * The HTML input element. @@ -159,7 +160,7 @@ FieldTextInput.prototype.initView = function() { // Count the number of fields, excluding text fields for (let i = 0, input; (input = this.sourceBlock_.inputList[i]); i++) { for (let j = 0; (input.fieldRow[j]); j++) { - nFields ++; + nFields++; } if (input.connection) { nConnections++; @@ -211,7 +212,8 @@ FieldTextInput.prototype.doValueInvalid_ = function(_invalidValue) { this.value_ = this.htmlInput_.untypedDefaultValue_; if (this.sourceBlock_ && Events.isEnabled()) { Events.fire(new (Events.get(Events.BLOCK_CHANGE))( - this.sourceBlock_, 'field', this.name || null, oldValue, this.value_)); + this.sourceBlock_, 'field', this.name || null, oldValue, + this.value_)); } } }; @@ -240,11 +242,11 @@ FieldTextInput.prototype.doValueUpdate_ = function(newValue) { FieldTextInput.prototype.applyColour = function() { if (this.sourceBlock_ && this.getConstants().FULL_BLOCK_FIELDS) { if (this.borderRect_) { - this.borderRect_.setAttribute('stroke', - this.sourceBlock_.style.colourTertiary); + this.borderRect_.setAttribute( + 'stroke', this.sourceBlock_.style.colourTertiary); } else { - this.sourceBlock_.pathObject.svgPath.setAttribute('fill', - this.getConstants().FIELD_BORDER_RECT_COLOUR); + this.sourceBlock_.pathObject.svgPath.setAttribute( + 'fill', this.getConstants().FIELD_BORDER_RECT_COLOUR); } } }; @@ -260,15 +262,13 @@ FieldTextInput.prototype.render_ = function() { // doValueUpdate_ so that the code is more centralized. if (this.isBeingEdited_) { this.resizeEditor_(); - const htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + const htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (!this.isTextValid_) { dom.addClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, true); + aria.setState(htmlInput, aria.State.INVALID, true); } else { dom.removeClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, false); + aria.setState(htmlInput, aria.State.INVALID, false); } } }; @@ -295,14 +295,11 @@ FieldTextInput.prototype.setSpellcheck = function(check) { * focus. Defaults to false. * @protected */ -FieldTextInput.prototype.showEditor_ = function(_opt_e, - opt_quietInput) { - this.workspace_ = - (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; +FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { + this.workspace_ = (/** @type {!BlockSvg} */ (this.sourceBlock_)).workspace; const quietInput = opt_quietInput || false; - if (!quietInput && (userAgent.MOBILE || - userAgent.ANDROID || - userAgent.IPAD)) { + if (!quietInput && + (userAgent.MOBILE || userAgent.ANDROID || userAgent.IPAD)) { this.showPromptEditor_(); } else { this.showInlineEditor_(quietInput); @@ -315,10 +312,9 @@ FieldTextInput.prototype.showEditor_ = function(_opt_e, * @private */ FieldTextInput.prototype.showPromptEditor_ = function() { - blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), - function(text) { - this.setValue(this.getValueFromEditorText_(text)); - }.bind(this)); + blocklyPrompt(Msg['CHANGE_VALUE_TITLE'], this.getText(), function(text) { + this.setValue(this.getValueFromEditorText_(text)); + }.bind(this)); }; /** @@ -328,13 +324,12 @@ FieldTextInput.prototype.showPromptEditor_ = function() { * @private */ FieldTextInput.prototype.showInlineEditor_ = function(quietInput) { - WidgetDiv.show( - this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); + WidgetDiv.show(this, this.sourceBlock_.RTL, this.widgetDispose_.bind(this)); this.htmlInput_ = this.widgetCreate_(); this.isBeingEdited_ = true; if (!quietInput) { - this.htmlInput_.focus({preventScroll:true}); + this.htmlInput_.focus({preventScroll: true}); this.htmlInput_.select(); } }; @@ -350,16 +345,15 @@ FieldTextInput.prototype.widgetCreate_ = function() { dom.addClass(this.getClickTarget_(), 'editing'); - const htmlInput = /** @type {HTMLInputElement} */ (document.createElement('input')); + const htmlInput = + /** @type {HTMLInputElement} */ (document.createElement('input')); htmlInput.className = 'blocklyHtmlInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); const scale = this.workspace_.getScale(); - const fontSize = - (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - let borderRadius = - (FieldTextInput.BORDERRADIUS * scale) + 'px'; + let borderRadius = (FieldTextInput.BORDERRADIUS * scale) + 'px'; if (this.fullBlockClickTarget_) { const bBox = this.getScaledBBox(); @@ -368,14 +362,14 @@ FieldTextInput.prototype.widgetCreate_ = function() { borderRadius = (bBox.bottom - bBox.top) / 2 + 'px'; // Pull stroke colour from the existing shadow block const strokeColour = this.sourceBlock_.getParent() ? - this.sourceBlock_.getParent().style.colourTertiary : - this.sourceBlock_.style.colourTertiary; + this.sourceBlock_.getParent().style.colourTertiary : + this.sourceBlock_.style.colourTertiary; htmlInput.style.border = (1 * scale) + 'px solid ' + strokeColour; div.style.borderRadius = borderRadius; div.style.transition = 'box-shadow 0.25s ease 0s'; if (this.getConstants().FIELD_TEXTINPUT_BOX_SHADOW) { - div.style.boxShadow = 'rgba(255, 255, 255, 0.3) 0 0 0 ' + - (4 * scale) + 'px'; + div.style.boxShadow = + 'rgba(255, 255, 255, 0.3) 0 0 0 ' + (4 * scale) + 'px'; } } htmlInput.style.borderRadius = borderRadius; @@ -539,10 +533,10 @@ FieldTextInput.prototype.isTabNavigable = function() { }; /** - * Use the `getText_` developer hook to override the field's text representation. - * When we're currently editing, return the current HTML value instead. - * Otherwise, return null which tells the field to use the default behaviour - * (which is a string cast of the field's value). + * Use the `getText_` developer hook to override the field's text + * representation. When we're currently editing, return the current HTML value + * instead. Otherwise, return null which tells the field to use the default + * behaviour (which is a string cast of the field's value). * @return {?string} The HTML value if we're editing, otherwise null. * @protected * @override From f92968b3023759af5e78a887332cf6e5c7d75abd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:29:34 -0700 Subject: [PATCH 240/833] Migrate core/field_variable.js to ES6 const/let --- core/field_variable.js | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index e5e379c13..e481c728a 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -97,7 +97,7 @@ Blockly.utils.object.inherits(Blockly.FieldVariable, Blockly.FieldDropdown); * @nocollapse */ Blockly.FieldVariable.fromJson = function(options) { - var varName = Blockly.utils.replaceMessageReferences(options['variable']); + const varName = Blockly.utils.replaceMessageReferences(options['variable']); // `this` might be a subclass of FieldVariable if that class doesn't override // the static fromJson method. return new this(varName, undefined, undefined, undefined, options); @@ -130,7 +130,7 @@ Blockly.FieldVariable.prototype.initModel = function() { if (this.variable_) { return; // Initialization already happened. } - var variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Blockly.Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, null, this.defaultVariableName, this.defaultType_); @@ -153,14 +153,14 @@ Blockly.FieldVariable.prototype.shouldAddBorderRect_ = function() { * variable field's state. */ Blockly.FieldVariable.prototype.fromXml = function(fieldElement) { - var id = fieldElement.getAttribute('id'); - var variableName = fieldElement.textContent; + const id = fieldElement.getAttribute('id'); + const variableName = fieldElement.textContent; // 'variabletype' should be lowercase, but until July 2019 it was sometimes // recorded as 'variableType'. Thus we need to check for both. - var variableType = fieldElement.getAttribute('variabletype') || + const variableType = fieldElement.getAttribute('variabletype') || fieldElement.getAttribute('variableType') || ''; - var variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Blockly.Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, id, variableName, variableType); // This should never happen :) @@ -259,8 +259,8 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } - var newId = /** @type {string} */ (opt_newValue); - var variable = Blockly.Variables.getVariable( + const newId = /** @type {string} */ (opt_newValue); + const variable = Blockly.Variables.getVariable( this.sourceBlock_.workspace, newId); if (!variable) { console.warn('Variable id doesn\'t point to a real variable! ' + @@ -268,7 +268,7 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { return null; } // Type Checks. - var type = variable.type; + const type = variable.type; if (!this.typeIsAllowed_(type)) { console.warn('Variable type doesn\'t match this field! Type was ' + type); return null; @@ -297,11 +297,11 @@ Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { * @private */ Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { - var typeList = this.getVariableTypes_(); + const typeList = this.getVariableTypes_(); if (!typeList) { return true; // If it's null, all types are valid. } - for (var i = 0; i < typeList.length; i++) { + for (let i = 0; i < typeList.length; i++) { if (type == typeList[i]) { return true; } @@ -317,7 +317,7 @@ Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { */ Blockly.FieldVariable.prototype.getVariableTypes_ = function() { // TODO (#1513): Try to avoid calling this every time the field is edited. - var variableTypes = this.variableTypes; + let variableTypes = this.variableTypes; if (variableTypes === null) { // If variableTypes is null, return all variable types. if (this.sourceBlock_ && this.sourceBlock_.workspace) { @@ -327,7 +327,7 @@ Blockly.FieldVariable.prototype.getVariableTypes_ = function() { variableTypes = variableTypes || ['']; if (variableTypes.length == 0) { // Throw an error if variableTypes is an empty list. - var name = this.getText(); + const name = this.getText(); throw Error('\'variableTypes\' of field variable ' + name + ' was an empty list'); } @@ -348,15 +348,16 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, opt_defaultType) { // If you expected that the default type would be the same as the only entry // in the variable types array, tell the Blockly team by commenting on #1499. - var defaultType = opt_defaultType || ''; + const defaultType = opt_defaultType || ''; + let variableTypes; // Set the allowable variable types. Null means all types on the workspace. if (opt_variableTypes == null || opt_variableTypes == undefined) { - var variableTypes = null; + variableTypes = null; } else if (Array.isArray(opt_variableTypes)) { - var variableTypes = opt_variableTypes; + variableTypes = opt_variableTypes; // Make sure the default type is valid. - var isInArray = false; - for (var i = 0; i < variableTypes.length; i++) { + let isInArray = false; + for (let i = 0; i < variableTypes.length; i++) { if (variableTypes[i] == defaultType) { isInArray = true; } @@ -395,23 +396,23 @@ Blockly.FieldVariable.dropdownCreate = function() { throw Error('Tried to call dropdownCreate on a variable field with no' + ' variable selected.'); } - var name = this.getText(); - var variableModelList = []; + const name = this.getText(); + let variableModelList = []; if (this.sourceBlock_ && this.sourceBlock_.workspace) { - var variableTypes = this.getVariableTypes_(); + const variableTypes = this.getVariableTypes_(); // Get a copy of the list, so that adding rename and new variable options // doesn't modify the workspace's list. - for (var i = 0; i < variableTypes.length; i++) { - var variableType = variableTypes[i]; - var variables = + for (let i = 0; i < variableTypes.length; i++) { + const variableType = variableTypes[i]; + const variables = this.sourceBlock_.workspace.getVariablesOfType(variableType); variableModelList = variableModelList.concat(variables); } } variableModelList.sort(Blockly.VariableModel.compareByName); - var options = []; - for (var i = 0; i < variableModelList.length; i++) { + const options = []; + for (let i = 0; i < variableModelList.length; i++) { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } @@ -437,7 +438,7 @@ Blockly.FieldVariable.dropdownCreate = function() { * @protected */ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { - var id = menuItem.getValue(); + const id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { From f5de84486f8d10bfa55737f816c7fc3b25690ee7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:32:47 -0700 Subject: [PATCH 241/833] Migrate core/field_variable.js to goog.module --- core/field_variable.js | 67 ++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index e481c728a..11d16532e 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldVariable'); +goog.module('Blockly.FieldVariable'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); @@ -47,7 +48,7 @@ goog.requireType('Blockly.MenuItem'); * @extends {Blockly.FieldDropdown} * @constructor */ -Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, +const FieldVariable = function(varName, opt_validator, opt_variableTypes, opt_defaultType, opt_config) { // The FieldDropdown constructor expects the field's initial value to be // the first entry in the menu generator, which it may or may not be. @@ -60,7 +61,7 @@ Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, * !function(this:Blockly.FieldDropdown): !Array)} * @protected */ - this.menuGenerator_ = Blockly.FieldVariable.dropdownCreate; + this.menuGenerator_ = FieldVariable.dropdownCreate; /** * The initial variable name passed to this field's constructor, or an @@ -85,18 +86,18 @@ Blockly.FieldVariable = function(varName, opt_validator, opt_variableTypes, this.setTypes_(opt_variableTypes, opt_defaultType); } }; -Blockly.utils.object.inherits(Blockly.FieldVariable, Blockly.FieldDropdown); +Blockly.utils.object.inherits(FieldVariable, Blockly.FieldDropdown); /** * Construct a FieldVariable from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (variable, * variableTypes, and defaultType). - * @return {!Blockly.FieldVariable} The new field instance. + * @return {!FieldVariable} The new field instance. * @package * @nocollapse */ -Blockly.FieldVariable.fromJson = function(options) { +FieldVariable.fromJson = function(options) { const varName = Blockly.utils.replaceMessageReferences(options['variable']); // `this` might be a subclass of FieldVariable if that class doesn't override // the static fromJson method. @@ -108,15 +109,15 @@ Blockly.FieldVariable.fromJson = function(options) { * are not. Editable fields should also be serializable. * @type {boolean} */ -Blockly.FieldVariable.prototype.SERIALIZABLE = true; +FieldVariable.prototype.SERIALIZABLE = true; /** * Configure the field based on the given map of options. * @param {!Object} config A map of options to configure the field based on. * @protected */ -Blockly.FieldVariable.prototype.configure_ = function(config) { - Blockly.FieldVariable.superClass_.configure_.call(this, config); +FieldVariable.prototype.configure_ = function(config) { + FieldVariable.superClass_.configure_.call(this, config); this.setTypes_(config['variableTypes'], config['defaultType']); }; @@ -126,7 +127,7 @@ Blockly.FieldVariable.prototype.configure_ = function(config) { * variable rather than let the value be invalid. * @package */ -Blockly.FieldVariable.prototype.initModel = function() { +FieldVariable.prototype.initModel = function() { if (this.variable_) { return; // Initialization already happened. } @@ -141,8 +142,8 @@ Blockly.FieldVariable.prototype.initModel = function() { /** * @override */ -Blockly.FieldVariable.prototype.shouldAddBorderRect_ = function() { - return Blockly.FieldVariable.superClass_.shouldAddBorderRect_.call(this) && +FieldVariable.prototype.shouldAddBorderRect_ = function() { + return FieldVariable.superClass_.shouldAddBorderRect_.call(this) && (!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || this.sourceBlock_.type != 'variables_get'); }; @@ -152,7 +153,7 @@ Blockly.FieldVariable.prototype.shouldAddBorderRect_ = function() { * @param {!Element} fieldElement The element containing information about the * variable field's state. */ -Blockly.FieldVariable.prototype.fromXml = function(fieldElement) { +FieldVariable.prototype.fromXml = function(fieldElement) { const id = fieldElement.getAttribute('id'); const variableName = fieldElement.textContent; // 'variabletype' should be lowercase, but until July 2019 it was sometimes @@ -180,7 +181,7 @@ Blockly.FieldVariable.prototype.fromXml = function(fieldElement) { * field's state. * @return {!Element} The element containing info about the field's state. */ -Blockly.FieldVariable.prototype.toXml = function(fieldElement) { +FieldVariable.prototype.toXml = function(fieldElement) { // Make sure the variable is initialized. this.initModel(); @@ -196,18 +197,18 @@ Blockly.FieldVariable.prototype.toXml = function(fieldElement) { * Attach this field to a block. * @param {!Blockly.Block} block The block containing this field. */ -Blockly.FieldVariable.prototype.setSourceBlock = function(block) { +FieldVariable.prototype.setSourceBlock = function(block) { if (block.isShadow()) { throw Error('Variable fields are not allowed to exist on shadow blocks.'); } - Blockly.FieldVariable.superClass_.setSourceBlock.call(this, block); + FieldVariable.superClass_.setSourceBlock.call(this, block); }; /** * Get the variable's ID. * @return {string} Current variable's ID. */ -Blockly.FieldVariable.prototype.getValue = function() { +FieldVariable.prototype.getValue = function() { return this.variable_ ? this.variable_.getId() : null; }; @@ -216,7 +217,7 @@ Blockly.FieldVariable.prototype.getValue = function() { * @return {string} The selected variable's name, or the empty string if no * variable is selected. */ -Blockly.FieldVariable.prototype.getText = function() { +FieldVariable.prototype.getText = function() { return this.variable_ ? this.variable_.name : ''; }; @@ -228,7 +229,7 @@ Blockly.FieldVariable.prototype.getText = function() { * selected. * @package */ -Blockly.FieldVariable.prototype.getVariable = function() { +FieldVariable.prototype.getVariable = function() { return this.variable_; }; @@ -239,7 +240,7 @@ Blockly.FieldVariable.prototype.getVariable = function() { * a block and workspace at that point. * @return {?Function} Validation function, or null. */ -Blockly.FieldVariable.prototype.getValidator = function() { +FieldVariable.prototype.getValidator = function() { // Validators shouldn't operate on the initial setValue call. // Normally this is achieved by calling setValidator after setValue, but // this is not a possibility with variable fields. @@ -255,7 +256,7 @@ Blockly.FieldVariable.prototype.getValidator = function() { * @return {?string} The validated ID, or null if invalid. * @protected */ -Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { +FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null) { return null; } @@ -284,10 +285,10 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { * @param {*} newId The value to be saved. * @protected */ -Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { +FieldVariable.prototype.doValueUpdate_ = function(newId) { this.variable_ = Blockly.Variables.getVariable( this.sourceBlock_.workspace, /** @type {string} */ (newId)); - Blockly.FieldVariable.superClass_.doValueUpdate_.call(this, newId); + FieldVariable.superClass_.doValueUpdate_.call(this, newId); }; /** @@ -296,7 +297,7 @@ Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { * @return {boolean} True if the type is in the list of allowed types. * @private */ -Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { +FieldVariable.prototype.typeIsAllowed_ = function(type) { const typeList = this.getVariableTypes_(); if (!typeList) { return true; // If it's null, all types are valid. @@ -315,7 +316,7 @@ Blockly.FieldVariable.prototype.typeIsAllowed_ = function(type) { * @throws {Error} if variableTypes is an empty array. * @private */ -Blockly.FieldVariable.prototype.getVariableTypes_ = function() { +FieldVariable.prototype.getVariableTypes_ = function() { // TODO (#1513): Try to avoid calling this every time the field is edited. let variableTypes = this.variableTypes; if (variableTypes === null) { @@ -344,7 +345,7 @@ Blockly.FieldVariable.prototype.getVariableTypes_ = function() { * field's value is not explicitly set. Defaults to ''. * @private */ -Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, +FieldVariable.prototype.setTypes_ = function(opt_variableTypes, opt_defaultType) { // If you expected that the default type would be the same as the only entry // in the variable types array, tell the Blockly team by commenting on #1499. @@ -381,7 +382,7 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, * be called by the block. * @package */ -Blockly.FieldVariable.prototype.refreshVariableName = function() { +FieldVariable.prototype.refreshVariableName = function() { this.forceRerender(); }; @@ -389,9 +390,9 @@ Blockly.FieldVariable.prototype.refreshVariableName = function() { * Return a sorted list of variable names for variable dropdown menus. * Include a special option at the end for creating a new variable name. * @return {!Array} Array of variable names/id tuples. - * @this {Blockly.FieldVariable} + * @this {FieldVariable} */ -Blockly.FieldVariable.dropdownCreate = function() { +FieldVariable.dropdownCreate = function() { if (!this.variable_) { throw Error('Tried to call dropdownCreate on a variable field with no' + ' variable selected.'); @@ -437,7 +438,7 @@ Blockly.FieldVariable.dropdownCreate = function() { * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. * @protected */ -Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { +FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { const id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { @@ -462,8 +463,10 @@ Blockly.FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { * @package * @override */ -Blockly.FieldVariable.prototype.referencesVariables = function() { +FieldVariable.prototype.referencesVariables = function() { return true; }; -Blockly.fieldRegistry.register('field_variable', Blockly.FieldVariable); +Blockly.fieldRegistry.register('field_variable', FieldVariable); + +exports = FieldVariable; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..5b085e8e6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -60,7 +60,7 @@ goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilin goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); +goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From bd5fd3bb088af2127d717dea81825ba178e86f1e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:37:24 -0700 Subject: [PATCH 242/833] Migrate core/field_variable.js named requires --- core/field_variable.js | 75 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 11d16532e..1a50f8c88 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -13,22 +13,21 @@ goog.module('Blockly.FieldVariable'); goog.module.declareLegacyNamespace(); +const Block = goog.requireType('Blockly.Block'); +const FieldDropdown = goog.require('Blockly.FieldDropdown'); +const Menu = goog.requireType('Blockly.Menu'); +const MenuItem = goog.requireType('Blockly.MenuItem'); +const Msg = goog.require('Blockly.Msg'); +const Size = goog.require('Blockly.utils.Size'); +const VariableModel = goog.require('Blockly.VariableModel'); +const Variables = goog.require('Blockly.Variables'); +const Xml = goog.require('Blockly.Xml'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const internalConstants = goog.require('Blockly.internalConstants'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); -goog.require('Blockly.FieldDropdown'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.VariableModel'); -goog.require('Blockly.Variables'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Menu'); -goog.requireType('Blockly.MenuItem'); /** @@ -45,7 +44,7 @@ goog.requireType('Blockly.MenuItem'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldDropdown} + * @extends {FieldDropdown} * @constructor */ const FieldVariable = function(varName, opt_validator, opt_variableTypes, @@ -58,7 +57,7 @@ const FieldVariable = function(varName, opt_validator, opt_variableTypes, * An array of options for a dropdown list, * or a function which generates these options. * @type {(!Array| - * !function(this:Blockly.FieldDropdown): !Array)} + * !function(this:FieldDropdown): !Array)} * @protected */ this.menuGenerator_ = FieldVariable.dropdownCreate; @@ -73,11 +72,11 @@ const FieldVariable = function(varName, opt_validator, opt_variableTypes, /** * The size of the area rendered by the field. - * @type {Blockly.utils.Size} + * @type {Size} * @protected * @override */ - this.size_ = new Blockly.utils.Size(0, 0); + this.size_ = new Size(0, 0); opt_config && this.configure_(opt_config); opt_validator && this.setValidator(opt_validator); @@ -86,7 +85,7 @@ const FieldVariable = function(varName, opt_validator, opt_variableTypes, this.setTypes_(opt_variableTypes, opt_defaultType); } }; -Blockly.utils.object.inherits(FieldVariable, Blockly.FieldDropdown); +inherits(FieldVariable, FieldDropdown); /** * Construct a FieldVariable from a JSON arg object, @@ -98,7 +97,7 @@ Blockly.utils.object.inherits(FieldVariable, Blockly.FieldDropdown); * @nocollapse */ FieldVariable.fromJson = function(options) { - const varName = Blockly.utils.replaceMessageReferences(options['variable']); + const varName = replaceMessageReferences(options['variable']); // `this` might be a subclass of FieldVariable if that class doesn't override // the static fromJson method. return new this(varName, undefined, undefined, undefined, options); @@ -131,7 +130,7 @@ FieldVariable.prototype.initModel = function() { if (this.variable_) { return; // Initialization already happened. } - const variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, null, this.defaultVariableName, this.defaultType_); @@ -161,7 +160,7 @@ FieldVariable.prototype.fromXml = function(fieldElement) { const variableType = fieldElement.getAttribute('variabletype') || fieldElement.getAttribute('variableType') || ''; - const variable = Blockly.Variables.getOrCreateVariablePackage( + const variable = Variables.getOrCreateVariablePackage( this.sourceBlock_.workspace, id, variableName, variableType); // This should never happen :) @@ -169,7 +168,7 @@ FieldVariable.prototype.fromXml = function(fieldElement) { throw Error('Serialized variable type with id \'' + variable.getId() + '\' had type ' + variable.type + ', and ' + 'does not match variable field that references it: ' + - Blockly.Xml.domToText(fieldElement) + '.'); + Xml.domToText(fieldElement) + '.'); } this.setValue(variable.getId()); @@ -195,7 +194,7 @@ FieldVariable.prototype.toXml = function(fieldElement) { /** * Attach this field to a block. - * @param {!Blockly.Block} block The block containing this field. + * @param {!Block} block The block containing this field. */ FieldVariable.prototype.setSourceBlock = function(block) { if (block.isShadow()) { @@ -225,7 +224,7 @@ FieldVariable.prototype.getText = function() { * Get the variable model for the selected variable. * Not guaranteed to be in the variable map on the workspace (e.g. if accessed * after the variable has been deleted). - * @return {?Blockly.VariableModel} The selected variable, or null if none was + * @return {?VariableModel} The selected variable, or null if none was * selected. * @package */ @@ -261,7 +260,7 @@ FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { return null; } const newId = /** @type {string} */ (opt_newValue); - const variable = Blockly.Variables.getVariable( + const variable = Variables.getVariable( this.sourceBlock_.workspace, newId); if (!variable) { console.warn('Variable id doesn\'t point to a real variable! ' + @@ -286,7 +285,7 @@ FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { * @protected */ FieldVariable.prototype.doValueUpdate_ = function(newId) { - this.variable_ = Blockly.Variables.getVariable( + this.variable_ = Variables.getVariable( this.sourceBlock_.workspace, /** @type {string} */ (newId)); FieldVariable.superClass_.doValueUpdate_.call(this, newId); }; @@ -410,7 +409,7 @@ FieldVariable.dropdownCreate = function() { variableModelList = variableModelList.concat(variables); } } - variableModelList.sort(Blockly.VariableModel.compareByName); + variableModelList.sort(VariableModel.compareByName); const options = []; for (let i = 0; i < variableModelList.length; i++) { @@ -418,12 +417,12 @@ FieldVariable.dropdownCreate = function() { options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } options.push([ - Blockly.Msg['RENAME_VARIABLE'], Blockly.internalConstants.RENAME_VARIABLE_ID + Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID ]); - if (Blockly.Msg['DELETE_VARIABLE']) { + if (Msg['DELETE_VARIABLE']) { options.push([ - Blockly.Msg['DELETE_VARIABLE'].replace('%1', name), - Blockly.internalConstants.DELETE_VARIABLE_ID + Msg['DELETE_VARIABLE'].replace('%1', name), + internalConstants.DELETE_VARIABLE_ID ]); } @@ -434,20 +433,20 @@ FieldVariable.dropdownCreate = function() { * Handle the selection of an item in the variable dropdown menu. * Special case the 'Rename variable...' and 'Delete variable...' options. * In the rename case, prompt the user for a new name. - * @param {!Blockly.Menu} menu The Menu component clicked. - * @param {!Blockly.MenuItem} menuItem The MenuItem selected within menu. + * @param {!Menu} menu The Menu component clicked. + * @param {!MenuItem} menuItem The MenuItem selected within menu. * @protected */ FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { const id = menuItem.getValue(); // Handle special cases. if (this.sourceBlock_ && this.sourceBlock_.workspace) { - if (id == Blockly.internalConstants.RENAME_VARIABLE_ID) { + if (id == internalConstants.RENAME_VARIABLE_ID) { // Rename variable. - Blockly.Variables.renameVariable( + Variables.renameVariable( this.sourceBlock_.workspace, this.variable_); return; - } else if (id == Blockly.internalConstants.DELETE_VARIABLE_ID) { + } else if (id == internalConstants.DELETE_VARIABLE_ID) { // Delete variable. this.sourceBlock_.workspace.deleteVariableById(this.variable_.getId()); return; @@ -467,6 +466,6 @@ FieldVariable.prototype.referencesVariables = function() { return true; }; -Blockly.fieldRegistry.register('field_variable', FieldVariable); +fieldRegistry.register('field_variable', FieldVariable); exports = FieldVariable; From 88aa32510c8549a68d0e234146535710a8689b83 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:38:10 -0700 Subject: [PATCH 243/833] clang-format core/field_variable.js --- core/field_variable.js | 56 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 1a50f8c88..f700d4a99 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -42,13 +42,14 @@ goog.require('Blockly.Events.BlockChange'); * @param {string=} opt_defaultType The type of variable to create if this * field's value is not explicitly set. Defaults to ''. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation} * for a list of properties this parameter supports. * @extends {FieldDropdown} * @constructor */ -const FieldVariable = function(varName, opt_validator, opt_variableTypes, - opt_defaultType, opt_config) { +const FieldVariable = function( + varName, opt_validator, opt_variableTypes, opt_defaultType, opt_config) { // The FieldDropdown constructor expects the field's initial value to be // the first entry in the menu generator, which it may or may not be. // Just do the relevant parts of the constructor. @@ -131,8 +132,8 @@ FieldVariable.prototype.initModel = function() { return; // Initialization already happened. } const variable = Variables.getOrCreateVariablePackage( - this.sourceBlock_.workspace, null, - this.defaultVariableName, this.defaultType_); + this.sourceBlock_.workspace, null, this.defaultVariableName, + this.defaultType_); // Don't call setValue because we don't want to cause a rerender. this.doValueUpdate_(variable.getId()); @@ -143,8 +144,8 @@ FieldVariable.prototype.initModel = function() { */ FieldVariable.prototype.shouldAddBorderRect_ = function() { return FieldVariable.superClass_.shouldAddBorderRect_.call(this) && - (!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || - this.sourceBlock_.type != 'variables_get'); + (!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW || + this.sourceBlock_.type != 'variables_get'); }; /** @@ -165,10 +166,11 @@ FieldVariable.prototype.fromXml = function(fieldElement) { // This should never happen :) if (variableType != null && variableType !== variable.type) { - throw Error('Serialized variable type with id \'' + - variable.getId() + '\' had type ' + variable.type + ', and ' + - 'does not match variable field that references it: ' + - Xml.domToText(fieldElement) + '.'); + throw Error( + 'Serialized variable type with id \'' + variable.getId() + + '\' had type ' + variable.type + ', and ' + + 'does not match variable field that references it: ' + + Xml.domToText(fieldElement) + '.'); } this.setValue(variable.getId()); @@ -260,10 +262,10 @@ FieldVariable.prototype.doClassValidation_ = function(opt_newValue) { return null; } const newId = /** @type {string} */ (opt_newValue); - const variable = Variables.getVariable( - this.sourceBlock_.workspace, newId); + const variable = Variables.getVariable(this.sourceBlock_.workspace, newId); if (!variable) { - console.warn('Variable id doesn\'t point to a real variable! ' + + console.warn( + 'Variable id doesn\'t point to a real variable! ' + 'ID was ' + newId); return null; } @@ -328,8 +330,8 @@ FieldVariable.prototype.getVariableTypes_ = function() { if (variableTypes.length == 0) { // Throw an error if variableTypes is an empty list. const name = this.getText(); - throw Error('\'variableTypes\' of field variable ' + - name + ' was an empty list'); + throw Error( + '\'variableTypes\' of field variable ' + name + ' was an empty list'); } return variableTypes; }; @@ -344,8 +346,8 @@ FieldVariable.prototype.getVariableTypes_ = function() { * field's value is not explicitly set. Defaults to ''. * @private */ -FieldVariable.prototype.setTypes_ = function(opt_variableTypes, - opt_defaultType) { +FieldVariable.prototype.setTypes_ = function( + opt_variableTypes, opt_defaultType) { // If you expected that the default type would be the same as the only entry // in the variable types array, tell the Blockly team by commenting on #1499. const defaultType = opt_defaultType || ''; @@ -363,11 +365,13 @@ FieldVariable.prototype.setTypes_ = function(opt_variableTypes, } } if (!isInArray) { - throw Error('Invalid default type \'' + defaultType + '\' in ' + + throw Error( + 'Invalid default type \'' + defaultType + '\' in ' + 'the definition of a FieldVariable'); } } else { - throw Error('\'variableTypes\' was not an array in the definition of ' + + throw Error( + '\'variableTypes\' was not an array in the definition of ' + 'a FieldVariable'); } // Only update the field once all checks pass. @@ -393,7 +397,8 @@ FieldVariable.prototype.refreshVariableName = function() { */ FieldVariable.dropdownCreate = function() { if (!this.variable_) { - throw Error('Tried to call dropdownCreate on a variable field with no' + + throw Error( + 'Tried to call dropdownCreate on a variable field with no' + ' variable selected.'); } const name = this.getText(); @@ -405,7 +410,7 @@ FieldVariable.dropdownCreate = function() { for (let i = 0; i < variableTypes.length; i++) { const variableType = variableTypes[i]; const variables = - this.sourceBlock_.workspace.getVariablesOfType(variableType); + this.sourceBlock_.workspace.getVariablesOfType(variableType); variableModelList = variableModelList.concat(variables); } } @@ -416,9 +421,7 @@ FieldVariable.dropdownCreate = function() { // Set the UUID as the internal representation of the variable. options[i] = [variableModelList[i].name, variableModelList[i].getId()]; } - options.push([ - Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID - ]); + options.push([Msg['RENAME_VARIABLE'], internalConstants.RENAME_VARIABLE_ID]); if (Msg['DELETE_VARIABLE']) { options.push([ Msg['DELETE_VARIABLE'].replace('%1', name), @@ -443,8 +446,7 @@ FieldVariable.prototype.onItemSelected_ = function(menu, menuItem) { if (this.sourceBlock_ && this.sourceBlock_.workspace) { if (id == internalConstants.RENAME_VARIABLE_ID) { // Rename variable. - Variables.renameVariable( - this.sourceBlock_.workspace, this.variable_); + Variables.renameVariable(this.sourceBlock_.workspace, this.variable_); return; } else if (id == internalConstants.DELETE_VARIABLE_ID) { // Delete variable. From ee565f16d6899cbe857529194a4d7852d0effdf2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 10:41:55 -0700 Subject: [PATCH 244/833] Silence unused variable warnings for requires used in JSDoc --- core/interfaces/i_collapsible_toolbox_item.js | 2 ++ core/interfaces/i_registrable_field.js | 1 + core/interfaces/i_selectable_toolbox_item.js | 2 ++ core/keyboard_nav/tab_navigate_cursor.js | 1 + core/renderers/common/info.js | 8 ++++++++ 5 files changed, 14 insertions(+) diff --git a/core/interfaces/i_collapsible_toolbox_item.js b/core/interfaces/i_collapsible_toolbox_item.js index 732c7aab7..45bd3ae3e 100644 --- a/core/interfaces/i_collapsible_toolbox_item.js +++ b/core/interfaces/i_collapsible_toolbox_item.js @@ -14,7 +14,9 @@ goog.module('Blockly.ICollapsibleToolboxItem'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ISelectableToolboxItem = goog.require('Blockly.ISelectableToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index 2c8c005bd..c9d04325d 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -14,6 +14,7 @@ goog.module('Blockly.IRegistrableField'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); diff --git a/core/interfaces/i_selectable_toolbox_item.js b/core/interfaces/i_selectable_toolbox_item.js index 2addc7b9e..cefe35740 100644 --- a/core/interfaces/i_selectable_toolbox_item.js +++ b/core/interfaces/i_selectable_toolbox_item.js @@ -14,7 +14,9 @@ goog.module('Blockly.ISelectableToolboxItem'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.require('Blockly.IToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const {FlyoutItemInfoArray} = goog.requireType('Blockly.utils.toolbox'); diff --git a/core/keyboard_nav/tab_navigate_cursor.js b/core/keyboard_nav/tab_navigate_cursor.js index 3b82267a1..77fc5a2a2 100644 --- a/core/keyboard_nav/tab_navigate_cursor.js +++ b/core/keyboard_nav/tab_navigate_cursor.js @@ -16,6 +16,7 @@ goog.module.declareLegacyNamespace(); const ASTNode = goog.require('Blockly.ASTNode'); const BasicCursor = goog.require('Blockly.BasicCursor'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); const {inherits} = goog.require('Blockly.utils.object'); diff --git a/core/renderers/common/info.js b/core/renderers/common/info.js index 73e02dfff..0f8548192 100644 --- a/core/renderers/common/info.js +++ b/core/renderers/common/info.js @@ -13,25 +13,33 @@ goog.module('Blockly.blockRendering.RenderInfo'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const BottomRow = goog.require('Blockly.blockRendering.BottomRow'); +/* eslint-disable-next-line no-unused-vars */ const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); const ExternalValueInput = goog.require('Blockly.blockRendering.ExternalValueInput'); const Field = goog.require('Blockly.blockRendering.Field'); const Hat = goog.require('Blockly.blockRendering.Hat'); const Icon = goog.require('Blockly.blockRendering.Icon'); const InlineInput = goog.require('Blockly.blockRendering.InlineInput'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); const InputRow = goog.require('Blockly.blockRendering.InputRow'); const InRowSpacer = goog.require('Blockly.blockRendering.InRowSpacer'); const JaggedEdge = goog.require('Blockly.blockRendering.JaggedEdge'); +/* eslint-disable-next-line no-unused-vars */ const Measurable = goog.require('Blockly.blockRendering.Measurable'); const NextConnection = goog.require('Blockly.blockRendering.NextConnection'); const OutputConnection = goog.require('Blockly.blockRendering.OutputConnection'); const PreviousConnection = goog.require('Blockly.blockRendering.PreviousConnection'); +/* eslint-disable-next-line no-unused-vars */ const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +/* eslint-disable-next-line no-unused-vars */ const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +/* eslint-disable-next-line no-unused-vars */ const RoundCorner = goog.require('Blockly.blockRendering.RoundCorner'); +/* eslint-disable-next-line no-unused-vars */ const Row = goog.require('Blockly.blockRendering.Row'); const SpacerRow = goog.require('Blockly.blockRendering.SpacerRow'); const SquareCorner = goog.require('Blockly.blockRendering.SquareCorner'); From 48ccc38cbb2c45ea34b796cacf338319d6a721c3 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 10:42:56 -0700 Subject: [PATCH 245/833] Fix destructuring --- core/menu.js | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/core/menu.js b/core/menu.js index ac79922cf..083d76e06 100644 --- a/core/menu.js +++ b/core/menu.js @@ -15,12 +15,12 @@ goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); const MenuItem = goog.requireType('Blockly.MenuItem'); -const Size = goog.requireType('Blockly.utils.Size'); -const {addClass, hasClass, removeClass} = goog.require('Blockly.utils.dom'); -const {Data, conditionalBind, unbind} = goog.require('Blockly.browserEvents'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); -const {getSize, scrollIntoContainerView} = goog.require('Blockly.utils.style'); -const {Role, State, setRole, setState} = goog.require('Blockly.utils.aria'); +const Size = goog.requireType('Blockly.utils.Size'); +const aria = goog.require('Blockly.utils.aria'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const style = goog.require('Blockly.utils.style'); /** @@ -56,35 +56,35 @@ const Menu = function() { /** * Mouse over event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseOverHandler_ = null; /** * Click event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.clickHandler_ = null; /** * Mouse enter event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseEnterHandler_ = null; /** * Mouse leave event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.mouseLeaveHandler_ = null; /** * Key down event data. - * @type {?Data} + * @type {?browserEvents.Data} * @private */ this.onKeyDownHandler_ = null; @@ -98,7 +98,7 @@ const Menu = function() { /** * ARIA name for this menu. - * @type {?Role} + * @type {?aria.Role} * @private */ this.roleName_ = null; @@ -124,7 +124,7 @@ Menu.prototype.render = function(container) { element.className = 'blocklyMenu goog-menu blocklyNonSelectable'; element.tabIndex = 0; if (this.roleName_) { - setRole(element, this.roleName_); + aria.setRole(element, this.roleName_); } this.element_ = element; @@ -135,15 +135,15 @@ Menu.prototype.render = function(container) { // Add event handlers. this.mouseOverHandler_ = - conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); + browserEvents.conditionalBind(element, 'mouseover', this, this.handleMouseOver_, true); this.clickHandler_ = - conditionalBind(element, 'click', this, this.handleClick_, true); - this.mouseEnterHandler_ = conditionalBind( + browserEvents.conditionalBind(element, 'click', this, this.handleClick_, true); + this.mouseEnterHandler_ = browserEvents.conditionalBind( element, 'mouseenter', this, this.handleMouseEnter_, true); - this.mouseLeaveHandler_ = conditionalBind( + this.mouseLeaveHandler_ = browserEvents.conditionalBind( element, 'mouseleave', this, this.handleMouseLeave_, true); this.onKeyDownHandler_ = - conditionalBind(element, 'keydown', this, this.handleKeyEvent_); + browserEvents.conditionalBind(element, 'keydown', this, this.handleKeyEvent_); container.appendChild(element); }; @@ -165,7 +165,7 @@ Menu.prototype.focus = function() { const el = this.getElement(); if (el) { el.focus({preventScroll: true}); - addClass(el, 'blocklyFocused'); + dom.addClass(el, 'blocklyFocused'); } }; @@ -177,13 +177,13 @@ Menu.prototype.blur_ = function() { const el = this.getElement(); if (el) { el.blur(); - removeClass(el, 'blocklyFocused'); + dom.removeClass(el, 'blocklyFocused'); } }; /** * Set the menu accessibility role. - * @param {!Role} roleName role name. + * @param {!aria.Role} roleName role name. * @package */ Menu.prototype.setRole = function(roleName) { @@ -196,23 +196,23 @@ Menu.prototype.setRole = function(roleName) { Menu.prototype.dispose = function() { // Remove event handlers. if (this.mouseOverHandler_) { - unbind(this.mouseOverHandler_); + browserEvents.unbind(this.mouseOverHandler_); this.mouseOverHandler_ = null; } if (this.clickHandler_) { - unbind(this.clickHandler_); + browserEvents.unbind(this.clickHandler_); this.clickHandler_ = null; } if (this.mouseEnterHandler_) { - unbind(this.mouseEnterHandler_); + browserEvents.unbind(this.mouseEnterHandler_); this.mouseEnterHandler_ = null; } if (this.mouseLeaveHandler_) { - unbind(this.mouseLeaveHandler_); + browserEvents.unbind(this.mouseLeaveHandler_); this.mouseLeaveHandler_ = null; } if (this.onKeyDownHandler_) { - unbind(this.onKeyDownHandler_); + browserEvents.unbind(this.onKeyDownHandler_); this.onKeyDownHandler_ = null; } @@ -239,7 +239,7 @@ Menu.prototype.getMenuItem_ = function(elem) { // Walk up parents until one meets either the menu's root element, or // a menu item's div. while (elem && elem != menuElem) { - if (hasClass(elem, 'blocklyMenuItem')) { + if (dom.hasClass(elem, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; (menuItem = this.menuItems_[i]); i++) { if (menuItem.getElement() == elem) { @@ -271,10 +271,10 @@ Menu.prototype.setHighlighted = function(item) { // Bring the highlighted item into view. This has no effect if the menu is // not scrollable. const el = /** @type {!Element} */ (this.getElement()); - scrollIntoContainerView( + style.scrollIntoContainerView( /** @type {!Element} */ (item.getElement()), el); - setState(el, State.ACTIVEDESCENDANT, item.getId()); + aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId()); } }; @@ -462,7 +462,7 @@ Menu.prototype.handleKeyEvent_ = function(e) { */ Menu.prototype.getSize = function() { const menuDom = this.getElement(); - const menuSize = getSize(/** @type {!Element} */ + const menuSize = style.getSize(/** @type {!Element} */ (menuDom)); // Recalculate height for the total content, not only box height. menuSize.height = menuDom.scrollHeight; From 380cfd5963d3a2e2e235fcccee3ebd02718e1573 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:08:58 -0700 Subject: [PATCH 246/833] Migrate core/flyout_base.js to ES6 const/let --- core/flyout_base.js | 144 +++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 84d6d3870..3c62ebe51 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -396,7 +396,7 @@ Blockly.Flyout.prototype.isVisible = function() { * @param {boolean} visible True if visible. */ Blockly.Flyout.prototype.setVisible = function(visible) { - var visibilityChanged = (visible != this.isVisible()); + const visibilityChanged = (visible != this.isVisible()); this.isVisible_ = visible; if (visibilityChanged) { @@ -414,7 +414,7 @@ Blockly.Flyout.prototype.setVisible = function(visible) { * @param {boolean} visible Whether the container is visible. */ Blockly.Flyout.prototype.setContainerVisible = function(visible) { - var visibilityChanged = (visible != this.containerVisible_); + const visibilityChanged = (visible != this.containerVisible_); this.containerVisible_ = visible; if (visibilityChanged) { this.updateDisplay_(); @@ -427,7 +427,7 @@ Blockly.Flyout.prototype.setContainerVisible = function(visible) { * @private */ Blockly.Flyout.prototype.updateDisplay_ = function() { - var show = true; + let show = true; if (!this.containerVisible_) { show = false; } else { @@ -453,17 +453,17 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { this.workspace_.setCachedParentSvgSize(width, height); if (this.svgGroup_.tagName == 'svg') { - var transform = 'translate(' + x + 'px,' + y + 'px)'; + const transform = 'translate(' + x + 'px,' + y + 'px)'; Blockly.utils.dom.setCssTransform(this.svgGroup_, transform); } else { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself - var transform = 'translate(' + x + ',' + y + ')'; + const transform = 'translate(' + x + ',' + y + ')'; this.svgGroup_.setAttribute("transform", transform); } // Update the scrollbar (if one exists). - var scrollbar = this.workspace_.scrollbar; + const scrollbar = this.workspace_.scrollbar; if (scrollbar) { // Set the scrollbars origin to be the top left of the flyout. scrollbar.setOrigin(x, y); @@ -491,7 +491,7 @@ Blockly.Flyout.prototype.hide = function() { } this.setVisible(false); // Delete all the event listeners. - for (var i = 0, listen; (listen = this.listeners_[i]); i++) { + for (let i = 0, listen; (listen = this.listeners_[i]); i++) { Blockly.browserEvents.unbind(listen); } this.listeners_.length = 0; @@ -521,8 +521,8 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { this.setVisible(true); // Parse the Array, Node or NodeList into a a list of flyout items. - var parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); - var flyoutInfo = + const parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); + const flyoutInfo = /** @type {{contents:!Array, gaps:!Array}} */ ( this.createFlyoutInfo_(parsedContent)); @@ -530,9 +530,9 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { // IE 11 is an incompetent browser that fails to fire mouseout events. // When the mouse is over the background, deselect all blocks. - var deselectAll = function() { - var topBlocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = topBlocks[i]); i++) { + const deselectAll = function() { + const topBlocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = topBlocks[i]); i++) { block.removeSelect(); } }; @@ -567,50 +567,54 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { * @private */ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { - var contents = []; - var gaps = []; + const contents = []; + const gaps = []; this.permanentlyDisabled_.length = 0; - var defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; - for (var i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { + const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; + for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { if (contentInfo['custom']) { - var customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); - var categoryName = customInfo['custom']; - var flyoutDef = this.getDynamicCategoryContents_(categoryName); - var parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ + const customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); + const categoryName = customInfo['custom']; + const flyoutDef = this.getDynamicCategoryContents_(categoryName); + const parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ (Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef)); parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } switch (contentInfo['kind'].toUpperCase()) { - case 'BLOCK': - var blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); - var blockXml = this.getBlockXml_(blockInfo); - var block = this.createBlock_(blockXml); + case 'BLOCK': { + const blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); + const blockXml = this.getBlockXml_(blockInfo); + const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. // - var gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); + const gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); gaps.push(isNaN(gap) ? defaultGap : gap); contents.push({type: 'block', block: block}); break; - case 'SEP': - var sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); + } + case 'SEP': { + const sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); this.addSeparatorGap_(sepInfo, gaps, defaultGap); break; - case 'LABEL': - var labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); + } + case 'LABEL': { + const labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); // A label is a button with different styling. - var label = this.createButton_(labelInfo, /** isLabel */ true); + const label = this.createButton_(labelInfo, /** isLabel */ true); contents.push({type: 'button', button: label}); gaps.push(defaultGap); break; - case 'BUTTON': - var buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); - var button = this.createButton_(buttonInfo, /** isLabel */ false); + } + case 'BUTTON': { + const buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); + const button = this.createButton_(buttonInfo, /** isLabel */ false); contents.push({type: 'button', button: button}); gaps.push(defaultGap); break; + } } } return {contents: contents, gaps: gaps}; @@ -625,13 +629,13 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. - var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( + const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( categoryName); if (typeof fnToApply != 'function') { throw TypeError('Couldn\'t find a callback function when opening' + ' a toolbox category.'); } - var flyoutDef = fnToApply(this.workspace_.targetWorkspace); + const flyoutDef = fnToApply(this.workspace_.targetWorkspace); if (!Array.isArray(flyoutDef)) { throw new TypeError('Result of toolbox category callback must be an array.'); } @@ -651,7 +655,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!Blockly.FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - var curButton = new Blockly.FlyoutButton(this.workspace_, + const curButton = new Blockly.FlyoutButton(this.workspace_, /** @type {!Blockly.WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; @@ -665,7 +669,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @protected */ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { - var curBlock = /** @type {!Blockly.BlockSvg} */ ( + const curBlock = /** @type {!Blockly.BlockSvg} */ ( Blockly.Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. @@ -684,8 +688,8 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { * @private */ Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { - var blockElement = null; - var blockXml = blockInfo['blockxml']; + let blockElement = null; + const blockXml = blockInfo['blockxml']; if (blockXml && typeof blockXml != 'string') { blockElement = blockXml; @@ -718,7 +722,7 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) // // The default gap is 24, can be set larger or smaller. // This overwrites the gap attribute on the previous element. - var newGap = parseInt(sepInfo['gap'], 10); + const newGap = parseInt(sepInfo['gap'], 10); // Ignore gaps before the first block. if (!isNaN(newGap) && gaps.length > 0) { gaps[gaps.length - 1] = newGap; @@ -733,15 +737,15 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) */ Blockly.Flyout.prototype.clearOldBlocks_ = function() { // Delete any blocks from a previous showing. - var oldBlocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = oldBlocks[i]); i++) { + const oldBlocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = oldBlocks[i]); i++) { if (block.workspace == this.workspace_) { block.dispose(false, false); } } // Delete any mats from a previous showing. - for (var j = 0; j < this.mats_.length; j++) { - var rect = this.mats_[j]; + for (let j = 0; j < this.mats_.length; j++) { + const rect = this.mats_[j]; if (rect) { Blockly.Tooltip.unbindMouseEvents(rect); Blockly.utils.dom.removeNode(rect); @@ -749,7 +753,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { } this.mats_.length = 0; // Delete any buttons from a previous showing. - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { button.dispose(); } this.buttons_.length = 0; @@ -788,9 +792,9 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { * @private */ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { - var flyout = this; + const flyout = this; return function(e) { - var gesture = flyout.targetWorkspace.getGesture(e); + const gesture = flyout.targetWorkspace.getGesture(e); if (gesture) { gesture.setStartBlock(block); gesture.handleFlyoutStart(e, flyout); @@ -804,7 +808,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { * @private */ Blockly.Flyout.prototype.onMouseDown_ = function(e) { - var gesture = this.targetWorkspace.getGesture(e); + const gesture = this.targetWorkspace.getGesture(e); if (gesture) { gesture.handleFlyoutStart(e, this); } @@ -830,9 +834,9 @@ Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { * @package */ Blockly.Flyout.prototype.createBlock = function(originalBlock) { - var newBlock = null; + let newBlock = null; Blockly.Events.disable(); - var variablesBeforeCreation = this.targetWorkspace.getAllVariables(); + const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); this.targetWorkspace.setResizesEnabled(false); try { newBlock = this.placeNewBlock_(originalBlock); @@ -843,14 +847,14 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { // Close the flyout. Blockly.hideChaff(); - var newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, + const newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, variablesBeforeCreation); if (Blockly.Events.isEnabled()) { Blockly.Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. - for (var i = 0; i < newVariables.length; i++) { - var thisVariable = newVariables[i]; + for (let i = 0; i < newVariables.length; i++) { + const thisVariable = newVariables[i]; Blockly.Events.fire( new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); } @@ -877,7 +881,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { * @protected */ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { - var buttonSvg = button.createDom(); + const buttonSvg = button.createDom(); button.moveTo(x, y); button.show(); // Clicking on a flyout button or label is a lot like clicking on the @@ -904,7 +908,7 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. - var rect = Blockly.utils.dom.createSvgElement( + const rect = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'fill-opacity': 0, @@ -931,11 +935,11 @@ Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * @protected */ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { - var blockHW = block.getHeightWidth(); + const blockHW = block.getHeightWidth(); rect.setAttribute('width', blockHW.width); rect.setAttribute('height', blockHW.height); - var blockXY = block.getRelativeToSurfaceXY(); + const blockXY = block.getRelativeToSurfaceXY(); rect.setAttribute('y', blockXY.y); rect.setAttribute('x', this.RTL ? blockXY.x - blockHW.width : blockXY.x); }; @@ -947,10 +951,10 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { * @private */ Blockly.Flyout.prototype.filterForCapacity_ = function() { - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { - var enable = this.targetWorkspace + const enable = this.targetWorkspace .isCapacityAvailable(Blockly.utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); @@ -990,50 +994,50 @@ Blockly.Flyout.prototype.isScrollable = function() { * @private */ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { - var targetWorkspace = this.targetWorkspace; - var svgRootOld = oldBlock.getSvgRoot(); + const targetWorkspace = this.targetWorkspace; + const svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { throw Error('oldBlock is not rendered.'); } // Create the new block by cloning the block in the flyout (via XML). // This cast assumes that the oldBlock can not be an insertion marker. - var xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); + const xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); // The target workspace would normally resize during domToBlock, which will // lead to weird jumps. Save it for terminateDrag. targetWorkspace.setResizesEnabled(false); // Using domToBlock instead of domToWorkspace means that the new block will be // placed at position (0, 0) in main workspace units. - var block = /** @type {!Blockly.BlockSvg} */ + const block = /** @type {!Blockly.BlockSvg} */ (Blockly.Xml.domToBlock(xml, targetWorkspace)); - var svgRootNew = block.getSvgRoot(); + const svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw Error('block is not rendered.'); } // The offset in pixels between the main workspace's origin and the upper left // corner of the injection div. - var mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels(); + const mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels(); // The offset in pixels between the flyout workspace's origin and the upper // left corner of the injection div. - var flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels(); + const flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels(); // The position of the old block in flyout workspace coordinates. - var oldBlockPos = oldBlock.getRelativeToSurfaceXY(); + const oldBlockPos = oldBlock.getRelativeToSurfaceXY(); // The position of the old block in pixels relative to the flyout // workspace's origin. oldBlockPos.scale(this.workspace_.scale); // The position of the old block in pixels relative to the upper left corner // of the injection div. - var oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, + const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - var finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, + const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); From 3df8c32594b6583a3f692f16952ea4dc254a83ce Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:11:27 -0700 Subject: [PATCH 247/833] Migrate core/flyout_base.js to goog.module --- core/flyout_base.js | 117 +++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 61 insertions(+), 58 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 3c62ebe51..18a3ab909 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Flyout'); +goog.module('Blockly.Flyout'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Block'); /** @suppress {extraRequire} */ @@ -55,8 +56,8 @@ goog.requireType('Blockly.utils.Rect'); * @implements {Blockly.IFlyout} * @extends {Blockly.DeleteArea} */ -Blockly.Flyout = function(workspaceOptions) { - Blockly.Flyout.superClass_.constructor.call(this); +const Flyout = function(workspaceOptions) { + Flyout.superClass_.constructor.call(this); workspaceOptions.setMetrics = this.setMetrics_.bind(this); /** @@ -149,41 +150,41 @@ Blockly.Flyout = function(workspaceOptions) { */ this.targetWorkspace = null; }; -Blockly.utils.object.inherits(Blockly.Flyout, Blockly.DeleteArea); +Blockly.utils.object.inherits(Flyout, Blockly.DeleteArea); /** * Does the flyout automatically close when a block is created? * @type {boolean} */ -Blockly.Flyout.prototype.autoClose = true; +Flyout.prototype.autoClose = true; /** * Whether the flyout is visible. * @type {boolean} * @private */ -Blockly.Flyout.prototype.isVisible_ = false; +Flyout.prototype.isVisible_ = false; /** * Whether the workspace containing this flyout is visible. * @type {boolean} * @private */ -Blockly.Flyout.prototype.containerVisible_ = true; +Flyout.prototype.containerVisible_ = true; /** * Corner radius of the flyout background. * @type {number} * @const */ -Blockly.Flyout.prototype.CORNER_RADIUS = 8; +Flyout.prototype.CORNER_RADIUS = 8; /** * Margin around the edges of the blocks in the flyout. * @type {number} * @const */ -Blockly.Flyout.prototype.MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS; +Flyout.prototype.MARGIN = Flyout.prototype.CORNER_RADIUS; // TODO: Move GAP_X and GAP_Y to their appropriate files. @@ -192,35 +193,35 @@ Blockly.Flyout.prototype.MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS; * element. * @const {number} */ -Blockly.Flyout.prototype.GAP_X = Blockly.Flyout.prototype.MARGIN * 3; +Flyout.prototype.GAP_X = Flyout.prototype.MARGIN * 3; /** * Gap between items in vertical flyouts. Can be overridden with the "sep" * element. * @const {number} */ -Blockly.Flyout.prototype.GAP_Y = Blockly.Flyout.prototype.MARGIN * 3; +Flyout.prototype.GAP_Y = Flyout.prototype.MARGIN * 3; /** * Top/bottom padding between scrollbar and edge of flyout background. * @type {number} * @const */ -Blockly.Flyout.prototype.SCROLLBAR_MARGIN = 2.5; +Flyout.prototype.SCROLLBAR_MARGIN = 2.5; /** * Width of flyout. * @type {number} * @protected */ -Blockly.Flyout.prototype.width_ = 0; +Flyout.prototype.width_ = 0; /** * Height of flyout. * @type {number} * @protected */ -Blockly.Flyout.prototype.height_ = 0; +Flyout.prototype.height_ = 0; /** * Range of a drag angle from a flyout considered "dragging toward workspace". @@ -238,7 +239,7 @@ Blockly.Flyout.prototype.height_ = 0; * @type {number} * @protected */ -Blockly.Flyout.prototype.dragAngleRange_ = 70; +Flyout.prototype.dragAngleRange_ = 70; /** * Creates the flyout's DOM. Only needs to be called once. The flyout can @@ -250,7 +251,7 @@ Blockly.Flyout.prototype.dragAngleRange_ = 70; * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ -Blockly.Flyout.prototype.createDom = function(tagName) { +Flyout.prototype.createDom = function(tagName) { /* @@ -277,7 +278,7 @@ Blockly.Flyout.prototype.createDom = function(tagName) { * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ -Blockly.Flyout.prototype.init = function(targetWorkspace) { +Flyout.prototype.init = function(targetWorkspace) { this.targetWorkspace = targetWorkspace; this.workspace_.targetWorkspace = targetWorkspace; @@ -326,7 +327,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { * Unlink from all DOM elements to prevent memory leaks. * @suppress {checkTypes} */ -Blockly.Flyout.prototype.dispose = function() { +Flyout.prototype.dispose = function() { this.hide(); this.workspace_.getComponentManager().removeComponent(this.id); Blockly.browserEvents.unbind(this.eventWrappers_); @@ -352,7 +353,7 @@ Blockly.Flyout.prototype.dispose = function() { * Get the width of the flyout. * @return {number} The width of the flyout. */ -Blockly.Flyout.prototype.getWidth = function() { +Flyout.prototype.getWidth = function() { return this.width_; }; @@ -360,7 +361,7 @@ Blockly.Flyout.prototype.getWidth = function() { * Get the height of the flyout. * @return {number} The width of the flyout. */ -Blockly.Flyout.prototype.getHeight = function() { +Flyout.prototype.getHeight = function() { return this.height_; }; @@ -369,7 +370,7 @@ Blockly.Flyout.prototype.getHeight = function() { * this matches the target workspace scale, but this can be overridden. * @return {number} Flyout workspace scale. */ -Blockly.Flyout.prototype.getFlyoutScale = function() { +Flyout.prototype.getFlyoutScale = function() { return this.targetWorkspace.scale; }; @@ -378,7 +379,7 @@ Blockly.Flyout.prototype.getFlyoutScale = function() { * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. * @package */ -Blockly.Flyout.prototype.getWorkspace = function() { +Flyout.prototype.getWorkspace = function() { return this.workspace_; }; @@ -386,7 +387,7 @@ Blockly.Flyout.prototype.getWorkspace = function() { * Is the flyout visible? * @return {boolean} True if visible. */ -Blockly.Flyout.prototype.isVisible = function() { +Flyout.prototype.isVisible = function() { return this.isVisible_; }; @@ -395,7 +396,7 @@ Blockly.Flyout.prototype.isVisible = function() { * that the flyout is shown. It could be hidden because its container is hidden. * @param {boolean} visible True if visible. */ -Blockly.Flyout.prototype.setVisible = function(visible) { +Flyout.prototype.setVisible = function(visible) { const visibilityChanged = (visible != this.isVisible()); this.isVisible_ = visible; @@ -413,7 +414,7 @@ Blockly.Flyout.prototype.setVisible = function(visible) { * Set whether this flyout's container is visible. * @param {boolean} visible Whether the container is visible. */ -Blockly.Flyout.prototype.setContainerVisible = function(visible) { +Flyout.prototype.setContainerVisible = function(visible) { const visibilityChanged = (visible != this.containerVisible_); this.containerVisible_ = visible; if (visibilityChanged) { @@ -426,7 +427,7 @@ Blockly.Flyout.prototype.setContainerVisible = function(visible) { * be visible and whether its containing workspace is visible. * @private */ -Blockly.Flyout.prototype.updateDisplay_ = function() { +Flyout.prototype.updateDisplay_ = function() { let show = true; if (!this.containerVisible_) { show = false; @@ -447,7 +448,7 @@ Blockly.Flyout.prototype.updateDisplay_ = function() { * @param {number} y The computed y origin of the flyout's SVG group. * @protected */ -Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { +Flyout.prototype.positionAt_ = function(width, height, x, y) { this.svgGroup_.setAttribute("width", width); this.svgGroup_.setAttribute("height", height); this.workspace_.setCachedParentSvgSize(width, height); @@ -485,7 +486,7 @@ Blockly.Flyout.prototype.positionAt_ = function(width, height, x, y) { /** * Hide and empty the flyout. */ -Blockly.Flyout.prototype.hide = function() { +Flyout.prototype.hide = function() { if (!this.isVisible()) { return; } @@ -509,7 +510,7 @@ Blockly.Flyout.prototype.hide = function() { * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ -Blockly.Flyout.prototype.show = function(flyoutDef) { +Flyout.prototype.show = function(flyoutDef) { this.workspace_.setResizesEnabled(false); this.hide(); this.clearOldBlocks_(); @@ -566,7 +567,7 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { * and gaps needed to lay out the flyout. * @private */ -Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { +Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { const contents = []; const gaps = []; this.permanentlyDisabled_.length = 0; @@ -626,7 +627,7 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { * @return {!Array} The array of flyout items. * @private */ -Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { +Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( @@ -651,7 +652,7 @@ Blockly.Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { * flyout. * @private */ -Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { +Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!Blockly.FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } @@ -668,7 +669,7 @@ Blockly.Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @return {!Blockly.BlockSvg} The block created from the blockXml. * @protected */ -Blockly.Flyout.prototype.createBlock_ = function(blockXml) { +Flyout.prototype.createBlock_ = function(blockXml) { const curBlock = /** @type {!Blockly.BlockSvg} */ ( Blockly.Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { @@ -687,7 +688,7 @@ Blockly.Flyout.prototype.createBlock_ = function(blockXml) { * @throws {Error} if the xml is not a valid block definition. * @private */ -Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { +Flyout.prototype.getBlockXml_ = function(blockInfo) { let blockElement = null; const blockXml = blockInfo['blockxml']; @@ -717,7 +718,7 @@ Blockly.Flyout.prototype.getBlockXml_ = function(blockInfo) { * @param {number} defaultGap The default gap between the button and next element. * @private */ -Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { +Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { // Change the gap between two toolbox elements. // // The default gap is 24, can be set larger or smaller. @@ -735,7 +736,7 @@ Blockly.Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) * Delete blocks, mats and buttons from a previous showing of the flyout. * @protected */ -Blockly.Flyout.prototype.clearOldBlocks_ = function() { +Flyout.prototype.clearOldBlocks_ = function() { // Delete any blocks from a previous showing. const oldBlocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = oldBlocks[i]); i++) { @@ -770,7 +771,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { * as a mat for that block. * @protected */ -Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { +Flyout.prototype.addBlockListeners_ = function(root, block, rect) { this.listeners_.push(Blockly.browserEvents.conditionalBind( root, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push(Blockly.browserEvents.conditionalBind( @@ -791,7 +792,7 @@ Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) { * @return {!Function} Function to call when block is clicked. * @private */ -Blockly.Flyout.prototype.blockMouseDown_ = function(block) { +Flyout.prototype.blockMouseDown_ = function(block) { const flyout = this; return function(e) { const gesture = flyout.targetWorkspace.getGesture(e); @@ -807,7 +808,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) { * @param {!Event} e Mouse down event. * @private */ -Blockly.Flyout.prototype.onMouseDown_ = function(e) { +Flyout.prototype.onMouseDown_ = function(e) { const gesture = this.targetWorkspace.getGesture(e); if (gesture) { gesture.handleFlyoutStart(e, this); @@ -822,7 +823,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { * otherwise. * @package */ -Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { +Flyout.prototype.isBlockCreatable_ = function(block) { return block.isEnabled(); }; @@ -833,7 +834,7 @@ Blockly.Flyout.prototype.isBlockCreatable_ = function(block) { * @throws {Error} if something went wrong with deserialization. * @package */ -Blockly.Flyout.prototype.createBlock = function(originalBlock) { +Flyout.prototype.createBlock = function(originalBlock) { let newBlock = null; Blockly.Events.disable(); const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); @@ -880,7 +881,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) { * @param {number} y The y position of the cursor during this layout pass. * @protected */ -Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { +Flyout.prototype.initFlyoutButton_ = function(button, x, y) { const buttonSvg = button.createDom(); button.moveTo(x, y); button.show(); @@ -905,7 +906,7 @@ Blockly.Flyout.prototype.initFlyoutButton_ = function(button, x, y) { * block. * @protected */ -Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { +Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = Blockly.utils.dom.createSvgElement( @@ -934,7 +935,7 @@ Blockly.Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * @param {!Blockly.BlockSvg} block The block the rectangle should be behind. * @protected */ -Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { +Flyout.prototype.moveRectToBlock_ = function(rect, block) { const blockHW = block.getHeightWidth(); rect.setAttribute('width', blockHW.width); rect.setAttribute('height', blockHW.height); @@ -950,7 +951,7 @@ Blockly.Flyout.prototype.moveRectToBlock_ = function(rect, block) { * the workspace, an "a + b" block that has two shadow blocks would be disabled. * @private */ -Blockly.Flyout.prototype.filterForCapacity_ = function() { +Flyout.prototype.filterForCapacity_ = function() { const blocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { @@ -967,7 +968,7 @@ Blockly.Flyout.prototype.filterForCapacity_ = function() { /** * Reflow blocks and their mats. */ -Blockly.Flyout.prototype.reflow = function() { +Flyout.prototype.reflow = function() { if (this.reflowWrapper_) { this.workspace_.removeChangeListener(this.reflowWrapper_); } @@ -982,7 +983,7 @@ Blockly.Flyout.prototype.reflow = function() { * dragging. * @package */ -Blockly.Flyout.prototype.isScrollable = function() { +Flyout.prototype.isScrollable = function() { return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : false; }; @@ -993,7 +994,7 @@ Blockly.Flyout.prototype.isScrollable = function() { * @return {!Blockly.BlockSvg} The new block in the main workspace. * @private */ -Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { +Flyout.prototype.placeNewBlock_ = function(oldBlock) { const targetWorkspace = this.targetWorkspace; const svgRootOld = oldBlock.getSvgRoot(); if (!svgRootOld) { @@ -1051,13 +1052,13 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) { * relative to viewport. * @return {Blockly.utils.Rect} The component's bounding box. */ -Blockly.Flyout.prototype.getClientRect; +Flyout.prototype.getClientRect; /** * Position the flyout. * @return {void} */ -Blockly.Flyout.prototype.position; +Flyout.prototype.position; /** * Determine if a drag delta is toward the workspace, based on the position @@ -1068,7 +1069,7 @@ Blockly.Flyout.prototype.position; * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.Flyout.prototype.isDragTowardWorkspace; +Flyout.prototype.isDragTowardWorkspace; /** * Sets the translation of the flyout to match the scrollbars. @@ -1077,7 +1078,7 @@ Blockly.Flyout.prototype.isDragTowardWorkspace; * similar x property. * @protected */ -Blockly.Flyout.prototype.setMetrics_; +Flyout.prototype.setMetrics_; /** * Lay out the blocks in the flyout. @@ -1085,14 +1086,14 @@ Blockly.Flyout.prototype.setMetrics_; * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.Flyout.prototype.layout_; +Flyout.prototype.layout_; /** * Scroll the flyout. * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.Flyout.prototype.wheel_; +Flyout.prototype.wheel_; /** * Compute height of flyout. Position mat under each block. @@ -1100,16 +1101,18 @@ Blockly.Flyout.prototype.wheel_; * @return {void} * @protected */ -Blockly.Flyout.prototype.reflowInternal_; +Flyout.prototype.reflowInternal_; /** * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.Flyout.prototype.getX; +Flyout.prototype.getX; /** * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.Flyout.prototype.getY; +Flyout.prototype.getY; + +exports = Flyout; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..f9a77b67a 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -61,7 +61,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From c5694ba711ba14e43a7bf9906d9bcde94b05c99b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:26:32 -0700 Subject: [PATCH 248/833] Migrate core/flyout_base.js named requires --- core/flyout_base.js | 228 ++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 117 insertions(+), 113 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 18a3ab909..42e4d0966 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -13,60 +13,64 @@ goog.module('Blockly.Flyout'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const DeleteArea = goog.require('Blockly.DeleteArea'); +const Events = goog.require('Blockly.Events'); +const FlyoutButton = goog.require('Blockly.FlyoutButton'); +const FlyoutMetricsManager = goog.require('Blockly.FlyoutMetricsManager'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.require('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const ScrollbarPair = goog.require('Blockly.ScrollbarPair'); +const Svg = goog.require('Blockly.utils.Svg'); +const Tooltip = goog.require('Blockly.Tooltip'); +const Variables = goog.require('Blockly.Variables'); +const WorkspaceSvg = goog.require('Blockly.WorkspaceSvg'); +const Xml = goog.require('Blockly.Xml'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const toolbox = goog.require('Blockly.utils.toolbox'); +const utils = goog.require('Blockly.utils'); +const utilsXml = goog.require('Blockly.utils.xml'); +const {hideChaff} = goog.require('Blockly'); /** @suppress {extraRequire} */ goog.require('Blockly.blockRendering'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.ComponentManager'); -goog.require('Blockly.DeleteArea'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockCreate'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarCreate'); -goog.require('Blockly.FlyoutMetricsManager'); /** @suppress {extraRequire} */ goog.require('Blockly.Gesture'); -goog.require('Blockly.IFlyout'); -goog.require('Blockly.ScrollbarPair'); -goog.require('Blockly.Tooltip'); /** @suppress {extraRequire} */ goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.utils.xml'); -goog.require('Blockly.WorkspaceSvg'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.FlyoutButton'); -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Rect'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. * @constructor * @abstract - * @implements {Blockly.IFlyout} - * @extends {Blockly.DeleteArea} + * @implements {IFlyout} + * @extends {DeleteArea} */ const Flyout = function(workspaceOptions) { Flyout.superClass_.constructor.call(this); workspaceOptions.setMetrics = this.setMetrics_.bind(this); /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @protected */ - this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); + this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.setMetricsManager( - new Blockly.FlyoutMetricsManager(this.workspace_, this)); + new FlyoutMetricsManager(this.workspace_, this)); this.workspace_.isFlyout = true; // Keep the workspace visibility consistent with the flyout's visibility. @@ -77,7 +81,7 @@ const Flyout = function(workspaceOptions) { * ComponentManager. * @type {string} */ - this.id = Blockly.utils.genUid(); + this.id = utils.genUid(); /** * Is RTL vs LTR. @@ -116,7 +120,7 @@ const Flyout = function(workspaceOptions) { /** * List of visible buttons. - * @type {!Array} + * @type {!Array} * @protected */ this.buttons_ = []; @@ -130,7 +134,7 @@ const Flyout = function(workspaceOptions) { /** * List of blocks that should always be disabled. - * @type {!Array} + * @type {!Array} * @private */ this.permanentlyDisabled_ = []; @@ -145,12 +149,12 @@ const Flyout = function(workspaceOptions) { /** * The target workspace - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @package */ this.targetWorkspace = null; }; -Blockly.utils.object.inherits(Flyout, Blockly.DeleteArea); +utils.object.inherits(Flyout, DeleteArea); /** * Does the flyout automatically close when a block is created? @@ -246,8 +250,8 @@ Flyout.prototype.dragAngleRange_ = 70; * either exist as its own SVG element or be a g element nested inside a * separate SVG element. * @param {string| - * !Blockly.utils.Svg| - * !Blockly.utils.Svg} tagName The type of tag to + * !Svg| + * !Svg} tagName The type of tag to * put the flyout in. This should be or . * @return {!SVGElement} The flyout's SVG group. */ @@ -260,10 +264,10 @@ Flyout.prototype.createDom = function(tagName) { */ // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. - this.svgGroup_ = Blockly.utils.dom.createSvgElement(tagName, + this.svgGroup_ = dom.createSvgElement(tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}, null); - this.svgBackground_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + this.svgBackground_ = dom.createSvgElement( + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( @@ -275,14 +279,14 @@ Flyout.prototype.createDom = function(tagName) { /** * Initializes the flyout. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The workspace in which to + * @param {!WorkspaceSvg} targetWorkspace The workspace in which to * create new blocks. */ Flyout.prototype.init = function(targetWorkspace) { this.targetWorkspace = targetWorkspace; this.workspace_.targetWorkspace = targetWorkspace; - this.workspace_.scrollbar = new Blockly.ScrollbarPair( + this.workspace_.scrollbar = new ScrollbarPair( this.workspace_, this.horizontalLayout, !this.horizontalLayout, 'blocklyFlyoutScrollbar', this.SCROLLBAR_MARGIN); @@ -290,7 +294,7 @@ Flyout.prototype.init = function(targetWorkspace) { Array.prototype.push.apply( this.eventWrappers_, - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.svgGroup_, 'wheel', this, this.wheel_)); if (!this.autoClose) { this.filterWrapper_ = this.filterForCapacity_.bind(this); @@ -300,7 +304,7 @@ Flyout.prototype.init = function(targetWorkspace) { // Dragging the flyout up and down. Array.prototype.push.apply( this.eventWrappers_, - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.svgBackground_, 'mousedown', this, this.onMouseDown_)); // A flyout connected to a workspace doesn't have its own current gesture. @@ -316,8 +320,8 @@ Flyout.prototype.init = function(targetWorkspace) { component: this, weight: 1, capabilities: [ - Blockly.ComponentManager.Capability.DELETE_AREA, - Blockly.ComponentManager.Capability.DRAG_TARGET + ComponentManager.Capability.DELETE_AREA, + ComponentManager.Capability.DRAG_TARGET ] }); }; @@ -330,7 +334,7 @@ Flyout.prototype.init = function(targetWorkspace) { Flyout.prototype.dispose = function() { this.hide(); this.workspace_.getComponentManager().removeComponent(this.id); - Blockly.browserEvents.unbind(this.eventWrappers_); + browserEvents.unbind(this.eventWrappers_); if (this.filterWrapper_) { this.targetWorkspace.removeChangeListener(this.filterWrapper_); this.filterWrapper_ = null; @@ -342,7 +346,7 @@ Flyout.prototype.dispose = function() { this.workspace_ = null; } if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.svgBackground_ = null; @@ -376,7 +380,7 @@ Flyout.prototype.getFlyoutScale = function() { /** * Get the workspace inside the flyout. - * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. + * @return {!WorkspaceSvg} The workspace inside the flyout. * @package */ Flyout.prototype.getWorkspace = function() { @@ -455,7 +459,7 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { if (this.svgGroup_.tagName == 'svg') { const transform = 'translate(' + x + 'px,' + y + 'px)'; - Blockly.utils.dom.setCssTransform(this.svgGroup_, transform); + dom.setCssTransform(this.svgGroup_, transform); } else { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself @@ -493,7 +497,7 @@ Flyout.prototype.hide = function() { this.setVisible(false); // Delete all the event listeners. for (let i = 0, listen; (listen = this.listeners_[i]); i++) { - Blockly.browserEvents.unbind(listen); + browserEvents.unbind(listen); } this.listeners_.length = 0; if (this.reflowWrapper_) { @@ -506,7 +510,7 @@ Flyout.prototype.hide = function() { /** * Show and populate the flyout. - * @param {!Blockly.utils.toolbox.FlyoutDefinition|string} flyoutDef Contents to display + * @param {!toolbox.FlyoutDefinition|string} flyoutDef Contents to display * in the flyout. This is either an array of Nodes, a NodeList, a * toolbox definition, or a string with the name of the dynamic category. */ @@ -522,7 +526,7 @@ Flyout.prototype.show = function(flyoutDef) { this.setVisible(true); // Parse the Array, Node or NodeList into a a list of flyout items. - const parsedContent = Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef); + const parsedContent = toolbox.convertFlyoutDefToJsonArray(flyoutDef); const flyoutInfo = /** @type {{contents:!Array, gaps:!Array}} */ ( this.createFlyoutInfo_(parsedContent)); @@ -538,7 +542,7 @@ Flyout.prototype.show = function(flyoutDef) { } }; - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( this.svgBackground_, 'mouseover', this, deselectAll)); if (this.horizontalLayout) { @@ -561,7 +565,7 @@ Flyout.prototype.show = function(flyoutDef) { /** * Create the contents array and gaps array necessary to create the layout for * the flyout. - * @param {!Blockly.utils.toolbox.FlyoutItemInfoArray} parsedContent The array + * @param {!toolbox.FlyoutItemInfoArray} parsedContent The array * of objects to show in the flyout. * @return {{contents:Array, gaps:Array}} The list of contents * and gaps needed to lay out the flyout. @@ -575,18 +579,18 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { if (contentInfo['custom']) { - const customInfo = /** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ (contentInfo); + const customInfo = /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); - const parsedDynamicContent = /** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */ - (Blockly.utils.toolbox.convertFlyoutDefToJsonArray(flyoutDef)); + const parsedDynamicContent = /** @type {!toolbox.FlyoutItemInfoArray} */ + (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } switch (contentInfo['kind'].toUpperCase()) { case 'BLOCK': { - const blockInfo = /** @type {!Blockly.utils.toolbox.BlockInfo} */ (contentInfo); + const blockInfo = /** @type {!toolbox.BlockInfo} */ (contentInfo); const blockXml = this.getBlockXml_(blockInfo); const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. @@ -597,12 +601,12 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { break; } case 'SEP': { - const sepInfo = /** @type {!Blockly.utils.toolbox.SeparatorInfo} */ (contentInfo); + const sepInfo = /** @type {!toolbox.SeparatorInfo} */ (contentInfo); this.addSeparatorGap_(sepInfo, gaps, defaultGap); break; } case 'LABEL': { - const labelInfo = /** @type {!Blockly.utils.toolbox.LabelInfo} */ (contentInfo); + const labelInfo = /** @type {!toolbox.LabelInfo} */ (contentInfo); // A label is a button with different styling. const label = this.createButton_(labelInfo, /** isLabel */ true); contents.push({type: 'button', button: label}); @@ -610,7 +614,7 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { break; } case 'BUTTON': { - const buttonInfo = /** @type {!Blockly.utils.toolbox.ButtonInfo} */ (contentInfo); + const buttonInfo = /** @type {!toolbox.ButtonInfo} */ (contentInfo); const button = this.createButton_(buttonInfo, /** isLabel */ false); contents.push({type: 'button', button: button}); gaps.push(defaultGap); @@ -645,19 +649,19 @@ Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { /** * Creates a flyout button or a flyout label. - * @param {!Blockly.utils.toolbox.ButtonOrLabelInfo} btnInfo + * @param {!toolbox.ButtonOrLabelInfo} btnInfo * The object holding information about a button or a label. * @param {boolean} isLabel True if the button is a label, false otherwise. - * @return {!Blockly.FlyoutButton} The object used to display the button in the + * @return {!FlyoutButton} The object used to display the button in the * flyout. * @private */ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { - if (!Blockly.FlyoutButton) { + if (!FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - const curButton = new Blockly.FlyoutButton(this.workspace_, - /** @type {!Blockly.WorkspaceSvg} */ (this.targetWorkspace), btnInfo, + const curButton = new FlyoutButton(this.workspace_, + /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; }; @@ -666,12 +670,12 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * Create a block from the xml and permanently disable any blocks that were * defined as disabled. * @param {!Element} blockXml The xml of the block. - * @return {!Blockly.BlockSvg} The block created from the blockXml. + * @return {!BlockSvg} The block created from the blockXml. * @protected */ Flyout.prototype.createBlock_ = function(blockXml) { - const curBlock = /** @type {!Blockly.BlockSvg} */ ( - Blockly.Xml.domToBlock(blockXml, this.workspace_)); + const curBlock = /** @type {!BlockSvg} */ ( + Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. // Do not enable these blocks as a result of capacity filtering. @@ -682,7 +686,7 @@ Flyout.prototype.createBlock_ = function(blockXml) { /** * Get the xml from the block info object. - * @param {!Blockly.utils.toolbox.BlockInfo} blockInfo The object holding + * @param {!toolbox.BlockInfo} blockInfo The object holding * information about a block. * @return {!Element} The xml for the block. * @throws {Error} if the xml is not a valid block definition. @@ -695,10 +699,10 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { if (blockXml && typeof blockXml != 'string') { blockElement = blockXml; } else if (blockXml && typeof blockXml == 'string') { - blockElement = Blockly.Xml.textToDom(blockXml); + blockElement = Xml.textToDom(blockXml); blockInfo['blockxml'] = blockElement; } else if (blockInfo['type']) { - blockElement = Blockly.utils.xml.createElement('xml'); + blockElement = utilsXml.createElement('xml'); blockElement.setAttribute('type', blockInfo['type']); blockElement.setAttribute('disabled', blockInfo['disabled']); blockInfo['blockxml'] = blockElement; @@ -712,7 +716,7 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { /** * Add the necessary gap in the flyout for a separator. - * @param {!Blockly.utils.toolbox.SeparatorInfo} sepInfo The object holding + * @param {!toolbox.SeparatorInfo} sepInfo The object holding * information about a separator. * @param {!Array} gaps The list gaps between items in the flyout. * @param {number} defaultGap The default gap between the button and next element. @@ -748,8 +752,8 @@ Flyout.prototype.clearOldBlocks_ = function() { for (let j = 0; j < this.mats_.length; j++) { const rect = this.mats_[j]; if (rect) { - Blockly.Tooltip.unbindMouseEvents(rect); - Blockly.utils.dom.removeNode(rect); + Tooltip.unbindMouseEvents(rect); + dom.removeNode(rect); } } this.mats_.length = 0; @@ -766,29 +770,29 @@ Flyout.prototype.clearOldBlocks_ = function() { /** * Add listeners to a block that has been added to the flyout. * @param {!SVGElement} root The root node of the SVG group the block is in. - * @param {!Blockly.BlockSvg} block The block to add listeners for. + * @param {!BlockSvg} block The block to add listeners for. * @param {!SVGElement} rect The invisible rectangle under the block that acts * as a mat for that block. * @protected */ Flyout.prototype.addBlockListeners_ = function(root, block, rect) { - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( root, 'mousedown', null, this.blockMouseDown_(block))); - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( - Blockly.browserEvents.bind(root, 'mouseenter', block, block.addSelect)); - this.listeners_.push(Blockly.browserEvents.bind( + browserEvents.bind(root, 'mouseenter', block, block.addSelect)); + this.listeners_.push(browserEvents.bind( root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( - Blockly.browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); - this.listeners_.push(Blockly.browserEvents.bind( + browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); + this.listeners_.push(browserEvents.bind( rect, 'mouseleave', block, block.removeSelect)); }; /** * Handle a mouse-down on an SVG block in a non-closing flyout. - * @param {!Blockly.BlockSvg} block The flyout block to copy. + * @param {!BlockSvg} block The flyout block to copy. * @return {!Function} Function to call when block is clicked. * @private */ @@ -818,7 +822,7 @@ Flyout.prototype.onMouseDown_ = function(e) { /** * Does this flyout allow you to create a new instance of the given block? * Used for deciding if a block can be "dragged out of" the flyout. - * @param {!Blockly.BlockSvg} block The block to copy from the flyout. + * @param {!BlockSvg} block The block to copy from the flyout. * @return {boolean} True if you can create a new instance of the block, false * otherwise. * @package @@ -829,41 +833,41 @@ Flyout.prototype.isBlockCreatable_ = function(block) { /** * Create a copy of this block on the workspace. - * @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout. - * @return {!Blockly.BlockSvg} The newly created block. + * @param {!BlockSvg} originalBlock The block to copy from the flyout. + * @return {!BlockSvg} The newly created block. * @throws {Error} if something went wrong with deserialization. * @package */ Flyout.prototype.createBlock = function(originalBlock) { let newBlock = null; - Blockly.Events.disable(); + Events.disable(); const variablesBeforeCreation = this.targetWorkspace.getAllVariables(); this.targetWorkspace.setResizesEnabled(false); try { newBlock = this.placeNewBlock_(originalBlock); } finally { - Blockly.Events.enable(); + Events.enable(); } // Close the flyout. - Blockly.hideChaff(); + hideChaff(); - const newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace, + const newVariables = Variables.getAddedVariables(this.targetWorkspace, variablesBeforeCreation); - if (Blockly.Events.isEnabled()) { - Blockly.Events.setGroup(true); + if (Events.isEnabled()) { + Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.VAR_CREATE))(thisVariable)); + Events.fire( + new (Events.get(Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)); + Events.fire( + new (Events.get(Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); @@ -876,7 +880,7 @@ Flyout.prototype.createBlock = function(originalBlock) { /** * Initialize the given button: move it to the correct location, * add listeners, etc. - * @param {!Blockly.FlyoutButton} button The button to initialize and place. + * @param {!FlyoutButton} button The button to initialize and place. * @param {number} x The x position of the cursor during this layout pass. * @param {number} y The y position of the cursor during this layout pass. * @protected @@ -887,7 +891,7 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { button.show(); // Clicking on a flyout button or label is a lot like clicking on the // flyout background. - this.listeners_.push(Blockly.browserEvents.conditionalBind( + this.listeners_.push(browserEvents.conditionalBind( buttonSvg, 'mousedown', this, this.onMouseDown_)); this.buttons_.push(button); @@ -895,7 +899,7 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { /** * Create and place a rectangle corresponding to the given block. - * @param {!Blockly.BlockSvg} block The block to associate the rect to. + * @param {!BlockSvg} block The block to associate the rect to. * @param {number} x The x position of the cursor during this layout pass. * @param {number} y The y position of the cursor during this layout pass. * @param {!{height: number, width: number}} blockHW The height and width of the @@ -909,8 +913,8 @@ Flyout.prototype.initFlyoutButton_ = function(button, x, y) { Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. - const rect = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + const rect = dom.createSvgElement( + Svg.RECT, { 'fill-opacity': 0, 'x': x, @@ -919,7 +923,7 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { 'width': blockHW.width }, null); rect.tooltip = block; - Blockly.Tooltip.bindMouseEvents(rect); + Tooltip.bindMouseEvents(rect); // Add the rectangles under the blocks, so that the blocks' tooltips work. this.workspace_.getCanvas().insertBefore(rect, block.getSvgRoot()); @@ -932,7 +936,7 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { * Move a rectangle to sit exactly behind a block, taking into account tabs, * hats, and any other protrusions we invent. * @param {!SVGElement} rect The rectangle to move directly behind the block. - * @param {!Blockly.BlockSvg} block The block the rectangle should be behind. + * @param {!BlockSvg} block The block the rectangle should be behind. * @protected */ Flyout.prototype.moveRectToBlock_ = function(rect, block) { @@ -956,7 +960,7 @@ Flyout.prototype.filterForCapacity_ = function() { for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { const enable = this.targetWorkspace - .isCapacityAvailable(Blockly.utils.getBlockTypeCounts(block)); + .isCapacityAvailable(utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -990,8 +994,8 @@ Flyout.prototype.isScrollable = function() { /** * Copy a block from the flyout to the workspace and position it correctly. - * @param {!Blockly.BlockSvg} oldBlock The flyout block to copy. - * @return {!Blockly.BlockSvg} The new block in the main workspace. + * @param {!BlockSvg} oldBlock The flyout block to copy. + * @return {!BlockSvg} The new block in the main workspace. * @private */ Flyout.prototype.placeNewBlock_ = function(oldBlock) { @@ -1003,15 +1007,15 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // Create the new block by cloning the block in the flyout (via XML). // This cast assumes that the oldBlock can not be an insertion marker. - const xml = /** @type {!Element} */ (Blockly.Xml.blockToDom(oldBlock, true)); + const xml = /** @type {!Element} */ (Xml.blockToDom(oldBlock, true)); // The target workspace would normally resize during domToBlock, which will // lead to weird jumps. Save it for terminateDrag. targetWorkspace.setResizesEnabled(false); // Using domToBlock instead of domToWorkspace means that the new block will be // placed at position (0, 0) in main workspace units. - const block = /** @type {!Blockly.BlockSvg} */ - (Blockly.Xml.domToBlock(xml, targetWorkspace)); + const block = /** @type {!BlockSvg} */ + (Xml.domToBlock(xml, targetWorkspace)); const svgRootNew = block.getSvgRoot(); if (!svgRootNew) { throw Error('block is not rendered.'); @@ -1033,12 +1037,12 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // The position of the old block in pixels relative to the upper left corner // of the injection div. - const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, + const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, + const finalOffset = Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); @@ -1050,7 +1054,7 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {Blockly.utils.Rect} The component's bounding box. + * @return {utils.Rect} The component's bounding box. */ Flyout.prototype.getClientRect; @@ -1064,7 +1068,7 @@ Flyout.prototype.position; * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package diff --git a/tests/deps.js b/tests/deps.js index f9a77b67a..54c8af48e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -61,7 +61,7 @@ goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Bloc goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry']); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object']); -goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly', 'Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutButton', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); From 47314fd0b921a0d315f6aadc4cd6837a039613b8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 11:27:36 -0700 Subject: [PATCH 249/833] clang-format core/flyout_base.js --- core/flyout_base.js | 97 +++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/core/flyout_base.js b/core/flyout_base.js index 42e4d0966..594d83a9f 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -242,7 +242,7 @@ Flyout.prototype.height_ = 0; * flyout. Setting it to 360 means that all drags create a new block. * @type {number} * @protected -*/ + */ Flyout.prototype.dragAngleRange_ = 70; /** @@ -264,11 +264,10 @@ Flyout.prototype.createDom = function(tagName) { */ // Setting style to display:none to start. The toolbox and flyout // hide/show code will set up proper visibility and size later. - this.svgGroup_ = dom.createSvgElement(tagName, - {'class': 'blocklyFlyout', 'style': 'display: none'}, null); + this.svgGroup_ = dom.createSvgElement( + tagName, {'class': 'blocklyFlyout', 'style': 'display: none'}, null); this.svgBackground_ = dom.createSvgElement( - Svg.PATH, - {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); + Svg.PATH, {'class': 'blocklyFlyoutBackground'}, this.svgGroup_); this.svgGroup_.appendChild(this.workspace_.createDom()); this.workspace_.getThemeManager().subscribe( this.svgBackground_, 'flyoutBackgroundColour', 'fill'); @@ -453,8 +452,8 @@ Flyout.prototype.updateDisplay_ = function() { * @protected */ Flyout.prototype.positionAt_ = function(width, height, x, y) { - this.svgGroup_.setAttribute("width", width); - this.svgGroup_.setAttribute("height", height); + this.svgGroup_.setAttribute('width', width); + this.svgGroup_.setAttribute('height', height); this.workspace_.setCachedParentSvgSize(width, height); if (this.svgGroup_.tagName == 'svg') { @@ -464,7 +463,7 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { // IE and Edge don't support CSS transforms on SVG elements so // it's important to set the transform on the SVG element itself const transform = 'translate(' + x + ',' + y + ')'; - this.svgGroup_.setAttribute("transform", transform); + this.svgGroup_.setAttribute('transform', transform); } // Update the scrollbar (if one exists). @@ -482,7 +481,6 @@ Flyout.prototype.positionAt_ = function(width, height, x, y) { if (scrollbar.vScroll) { scrollbar.vScroll.setPosition( scrollbar.vScroll.position.x, scrollbar.vScroll.position.y); - } } }; @@ -528,8 +526,8 @@ Flyout.prototype.show = function(flyoutDef) { // Parse the Array, Node or NodeList into a a list of flyout items. const parsedContent = toolbox.convertFlyoutDefToJsonArray(flyoutDef); const flyoutInfo = - /** @type {{contents:!Array, gaps:!Array}} */ ( - this.createFlyoutInfo_(parsedContent)); + /** @type {{contents:!Array, gaps:!Array}} */ ( + this.createFlyoutInfo_(parsedContent)); this.layout_(flyoutInfo.contents, flyoutInfo.gaps); @@ -577,14 +575,15 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { this.permanentlyDisabled_.length = 0; const defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; for (let i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { - if (contentInfo['custom']) { - const customInfo = /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); + const customInfo = + /** @type {!toolbox.DynamicCategoryInfo} */ (contentInfo); const categoryName = customInfo['custom']; const flyoutDef = this.getDynamicCategoryContents_(categoryName); const parsedDynamicContent = /** @type {!toolbox.FlyoutItemInfoArray} */ - (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); - parsedContent.splice.apply(parsedContent, [i, 1].concat(parsedDynamicContent)); + (toolbox.convertFlyoutDefToJsonArray(flyoutDef)); + parsedContent.splice.apply( + parsedContent, [i, 1].concat(parsedDynamicContent)); contentInfo = parsedContent[i]; } @@ -595,7 +594,8 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { const block = this.createBlock_(blockXml); // This is a deprecated method for adding gap to a block. // - const gap = parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); + const gap = + parseInt(blockInfo['gap'] || blockXml.getAttribute('gap'), 10); gaps.push(isNaN(gap) ? defaultGap : gap); contents.push({type: 'block', block: block}); break; @@ -634,15 +634,17 @@ Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { Flyout.prototype.getDynamicCategoryContents_ = function(categoryName) { // Look up the correct category generation function and call that to get a // valid XML list. - const fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback( - categoryName); + const fnToApply = + this.workspace_.targetWorkspace.getToolboxCategoryCallback(categoryName); if (typeof fnToApply != 'function') { - throw TypeError('Couldn\'t find a callback function when opening' + + throw TypeError( + 'Couldn\'t find a callback function when opening' + ' a toolbox category.'); } const flyoutDef = fnToApply(this.workspace_.targetWorkspace); if (!Array.isArray(flyoutDef)) { - throw new TypeError('Result of toolbox category callback must be an array.'); + throw new TypeError( + 'Result of toolbox category callback must be an array.'); } return flyoutDef; }; @@ -660,9 +662,9 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { if (!FlyoutButton) { throw Error('Missing require for Blockly.FlyoutButton'); } - const curButton = new FlyoutButton(this.workspace_, - /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, - isLabel); + const curButton = new FlyoutButton( + this.workspace_, + /** @type {!WorkspaceSvg} */ (this.targetWorkspace), btnInfo, isLabel); return curButton; }; @@ -674,8 +676,8 @@ Flyout.prototype.createButton_ = function(btnInfo, isLabel) { * @protected */ Flyout.prototype.createBlock_ = function(blockXml) { - const curBlock = /** @type {!BlockSvg} */ ( - Xml.domToBlock(blockXml, this.workspace_)); + const curBlock = + /** @type {!BlockSvg} */ (Xml.domToBlock(blockXml, this.workspace_)); if (!curBlock.isEnabled()) { // Record blocks that were initially disabled. // Do not enable these blocks as a result of capacity filtering. @@ -709,7 +711,8 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { } if (!blockElement) { - throw Error('Error: Invalid block definition. Block definition must have blockxml or type.'); + throw Error( + 'Error: Invalid block definition. Block definition must have blockxml or type.'); } return blockElement; }; @@ -719,7 +722,8 @@ Flyout.prototype.getBlockXml_ = function(blockInfo) { * @param {!toolbox.SeparatorInfo} sepInfo The object holding * information about a separator. * @param {!Array} gaps The list gaps between items in the flyout. - * @param {number} defaultGap The default gap between the button and next element. + * @param {number} defaultGap The default gap between the button and next + * element. * @private */ Flyout.prototype.addSeparatorGap_ = function(sepInfo, gaps, defaultGap) { @@ -782,12 +786,12 @@ Flyout.prototype.addBlockListeners_ = function(root, block, rect) { rect, 'mousedown', null, this.blockMouseDown_(block))); this.listeners_.push( browserEvents.bind(root, 'mouseenter', block, block.addSelect)); - this.listeners_.push(browserEvents.bind( - root, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + browserEvents.bind(root, 'mouseleave', block, block.removeSelect)); this.listeners_.push( browserEvents.bind(rect, 'mouseenter', block, block.addSelect)); - this.listeners_.push(browserEvents.bind( - rect, 'mouseleave', block, block.removeSelect)); + this.listeners_.push( + browserEvents.bind(rect, 'mouseleave', block, block.removeSelect)); }; /** @@ -852,22 +856,20 @@ Flyout.prototype.createBlock = function(originalBlock) { // Close the flyout. hideChaff(); - const newVariables = Variables.getAddedVariables(this.targetWorkspace, - variablesBeforeCreation); + const newVariables = Variables.getAddedVariables( + this.targetWorkspace, variablesBeforeCreation); if (Events.isEnabled()) { Events.setGroup(true); // Fire a VarCreate event for each (if any) new variable created. for (let i = 0; i < newVariables.length; i++) { const thisVariable = newVariables[i]; - Events.fire( - new (Events.get(Events.VAR_CREATE))(thisVariable)); + Events.fire(new (Events.get(Events.VAR_CREATE))(thisVariable)); } // Block events come after var events, in case they refer to newly created // variables. - Events.fire( - new (Events.get(Events.BLOCK_CREATE))(newBlock)); + Events.fire(new (Events.get(Events.BLOCK_CREATE))(newBlock)); } if (this.autoClose) { this.hide(); @@ -914,14 +916,14 @@ Flyout.prototype.createRect_ = function(block, x, y, blockHW, index) { // Create an invisible rectangle under the block to act as a button. Just // using the block as a button is poor, since blocks have holes in them. const rect = dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'fill-opacity': 0, 'x': x, 'y': y, 'height': blockHW.height, 'width': blockHW.width - }, null); + }, + null); rect.tooltip = block; Tooltip.bindMouseEvents(rect); // Add the rectangles under the blocks, so that the blocks' tooltips work. @@ -959,8 +961,8 @@ Flyout.prototype.filterForCapacity_ = function() { const blocks = this.workspace_.getTopBlocks(false); for (let i = 0, block; (block = blocks[i]); i++) { if (this.permanentlyDisabled_.indexOf(block) == -1) { - const enable = this.targetWorkspace - .isCapacityAvailable(utils.getBlockTypeCounts(block)); + const enable = this.targetWorkspace.isCapacityAvailable( + utils.getBlockTypeCounts(block)); while (block) { block.setEnabled(enable); block = block.getNextBlock(); @@ -988,8 +990,8 @@ Flyout.prototype.reflow = function() { * @package */ Flyout.prototype.isScrollable = function() { - return this.workspace_.scrollbar ? - this.workspace_.scrollbar.isVisible() : false; + return this.workspace_.scrollbar ? this.workspace_.scrollbar.isVisible() : + false; }; /** @@ -1037,13 +1039,12 @@ Flyout.prototype.placeNewBlock_ = function(oldBlock) { // The position of the old block in pixels relative to the upper left corner // of the injection div. - const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, - oldBlockPos); + const oldBlockOffsetPixels = Coordinate.sum(flyoutOffsetPixels, oldBlockPos); // The position of the old block in pixels relative to the origin of the // main workspace. - const finalOffset = Coordinate.difference(oldBlockOffsetPixels, - mainOffsetPixels); + const finalOffset = + Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels); // The position of the old block in main workspace coordinates. finalOffset.scale(1 / targetWorkspace.scale); From c3d14479932c33aca47fdbdd54d9de766290fede Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 14:47:23 -0700 Subject: [PATCH 250/833] Migrate core/flyout_button.js to ES6 const/let --- core/flyout_button.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 643790d9f..793699e6a 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -126,7 +126,7 @@ Blockly.FlyoutButton.prototype.height = 0; * @return {!SVGElement} The button's SVG group. */ Blockly.FlyoutButton.prototype.createDom = function() { - var cssClass = this.isLabel_ ? 'blocklyFlyoutLabel' : 'blocklyFlyoutButton'; + let cssClass = this.isLabel_ ? 'blocklyFlyoutLabel' : 'blocklyFlyoutButton'; if (this.cssClass_) { cssClass += ' ' + this.cssClass_; } @@ -135,9 +135,10 @@ Blockly.FlyoutButton.prototype.createDom = function() { Blockly.utils.Svg.G, {'class': cssClass}, this.workspace_.getCanvas()); + let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). - var shadow = Blockly.utils.dom.createSvgElement( + shadow = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'class': 'blocklyFlyoutButtonShadow', @@ -146,7 +147,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { this.svgGroup_); } // Background rectangle. - var rect = Blockly.utils.dom.createSvgElement( + const rect = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { 'class': this.isLabel_ ? @@ -155,7 +156,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { }, this.svgGroup_); - var svgText = Blockly.utils.dom.createSvgElement( + const svgText = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', @@ -164,7 +165,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { 'text-anchor': 'middle' }, this.svgGroup_); - var text = Blockly.utils.replaceMessageReferences(this.text_); + let text = Blockly.utils.replaceMessageReferences(this.text_); if (this.workspace_.RTL) { // Force text to be RTL by adding an RLM. text += '\u200F'; @@ -176,12 +177,12 @@ Blockly.FlyoutButton.prototype.createDom = function() { 'flyoutForegroundColour', 'fill'); } - var fontSize = Blockly.utils.style.getComputedStyle(svgText, 'fontSize'); - var fontWeight = Blockly.utils.style.getComputedStyle(svgText, 'fontWeight'); - var fontFamily = Blockly.utils.style.getComputedStyle(svgText, 'fontFamily'); + const fontSize = Blockly.utils.style.getComputedStyle(svgText, 'fontSize'); + const fontWeight = Blockly.utils.style.getComputedStyle(svgText, 'fontWeight'); + const fontFamily = Blockly.utils.style.getComputedStyle(svgText, 'fontFamily'); this.width = Blockly.utils.dom.getFastTextWidthWithSizeString(svgText, fontSize, fontWeight, fontFamily); - var fontMetrics = Blockly.utils.dom.measureFontMetrics(text, fontSize, + const fontMetrics = Blockly.utils.dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; @@ -286,7 +287,7 @@ Blockly.FlyoutButton.prototype.dispose = function() { * @private */ Blockly.FlyoutButton.prototype.onMouseUp_ = function(e) { - var gesture = this.targetWorkspace_.getGesture(e); + const gesture = this.targetWorkspace_.getGesture(e); if (gesture) { gesture.cancel(); } From a84660000f78ef26d89c2a204f11eeac720099f4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 14:53:15 -0700 Subject: [PATCH 251/833] Migrate core/flyout_button.js to goog.module --- core/flyout_button.js | 39 +++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 793699e6a..7399e3997 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FlyoutButton'); +goog.module('Blockly.FlyoutButton'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.Css'); @@ -35,7 +36,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { +const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { // Labels behave the same as buttons, but are styled differently. /** @@ -102,30 +103,30 @@ Blockly.FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { /** * The horizontal margin around the text in the button. */ -Blockly.FlyoutButton.MARGIN_X = 5; +FlyoutButton.MARGIN_X = 5; /** * The vertical margin around the text in the button. */ -Blockly.FlyoutButton.MARGIN_Y = 2; +FlyoutButton.MARGIN_Y = 2; /** * The width of the button's rect. * @type {number} */ -Blockly.FlyoutButton.prototype.width = 0; +FlyoutButton.prototype.width = 0; /** * The height of the button's rect. * @type {number} */ -Blockly.FlyoutButton.prototype.height = 0; +FlyoutButton.prototype.height = 0; /** * Create the button elements. * @return {!SVGElement} The button's SVG group. */ -Blockly.FlyoutButton.prototype.createDom = function() { +FlyoutButton.prototype.createDom = function() { let cssClass = this.isLabel_ ? 'blocklyFlyoutLabel' : 'blocklyFlyoutButton'; if (this.cssClass_) { cssClass += ' ' + this.cssClass_; @@ -187,8 +188,8 @@ Blockly.FlyoutButton.prototype.createDom = function() { this.height = fontMetrics.height; if (!this.isLabel_) { - this.width += 2 * Blockly.FlyoutButton.MARGIN_X; - this.height += 2 * Blockly.FlyoutButton.MARGIN_Y; + this.width += 2 * FlyoutButton.MARGIN_X; + this.height += 2 * FlyoutButton.MARGIN_Y; shadow.setAttribute('width', this.width); shadow.setAttribute('height', this.height); } @@ -209,7 +210,7 @@ Blockly.FlyoutButton.prototype.createDom = function() { /** * Correctly position the flyout button and make it visible. */ -Blockly.FlyoutButton.prototype.show = function() { +FlyoutButton.prototype.show = function() { this.updateTransform_(); this.svgGroup_.setAttribute('display', 'block'); }; @@ -218,7 +219,7 @@ Blockly.FlyoutButton.prototype.show = function() { * Update SVG attributes to match internal state. * @private */ -Blockly.FlyoutButton.prototype.updateTransform_ = function() { +FlyoutButton.prototype.updateTransform_ = function() { this.svgGroup_.setAttribute('transform', 'translate(' + this.position_.x + ',' + this.position_.y + ')'); }; @@ -228,7 +229,7 @@ Blockly.FlyoutButton.prototype.updateTransform_ = function() { * @param {number} x The new x coordinate. * @param {number} y The new y coordinate. */ -Blockly.FlyoutButton.prototype.moveTo = function(x, y) { +FlyoutButton.prototype.moveTo = function(x, y) { this.position_.x = x; this.position_.y = y; this.updateTransform_(); @@ -237,7 +238,7 @@ Blockly.FlyoutButton.prototype.moveTo = function(x, y) { /** * @return {boolean} Whether or not the button is a label. */ -Blockly.FlyoutButton.prototype.isLabel = function() { +FlyoutButton.prototype.isLabel = function() { return this.isLabel_; }; @@ -246,14 +247,14 @@ Blockly.FlyoutButton.prototype.isLabel = function() { * @return {!Blockly.utils.Coordinate} x, y coordinates. * @package */ -Blockly.FlyoutButton.prototype.getPosition = function() { +FlyoutButton.prototype.getPosition = function() { return this.position_; }; /** * @return {string} Text of the button. */ -Blockly.FlyoutButton.prototype.getButtonText = function() { +FlyoutButton.prototype.getButtonText = function() { return this.text_; }; @@ -262,14 +263,14 @@ Blockly.FlyoutButton.prototype.getButtonText = function() { * @return {!Blockly.WorkspaceSvg} The target workspace of the flyout where this * button resides. */ -Blockly.FlyoutButton.prototype.getTargetWorkspace = function() { +FlyoutButton.prototype.getTargetWorkspace = function() { return this.targetWorkspace_; }; /** * Dispose of this button. */ -Blockly.FlyoutButton.prototype.dispose = function() { +FlyoutButton.prototype.dispose = function() { if (this.onMouseUpWrapper_) { Blockly.browserEvents.unbind(this.onMouseUpWrapper_); } @@ -286,7 +287,7 @@ Blockly.FlyoutButton.prototype.dispose = function() { * @param {!Event} e Mouse up event. * @private */ -Blockly.FlyoutButton.prototype.onMouseUp_ = function(e) { +FlyoutButton.prototype.onMouseUp_ = function(e) { const gesture = this.targetWorkspace_.getGesture(e); if (gesture) { gesture.cancel(); @@ -329,3 +330,5 @@ Blockly.Css.register([ '}', /* eslint-enable indent */ ]); + +exports = FlyoutButton; diff --git a/tests/deps.js b/tests/deps.js index d02bbc5ea..d0f326297 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -62,7 +62,7 @@ goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], [' goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); -goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); +goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); From fe01fbebc211a49bdd120acaeaba695486e0a9b1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 15:03:35 -0700 Subject: [PATCH 252/833] Migrate core/flyout_button.js named requires --- core/flyout_button.js | 79 ++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 7399e3997..372060237 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -13,24 +13,25 @@ goog.module('Blockly.FlyoutButton'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.Css'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.style'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.utils.toolbox'); -goog.requireType('Blockly.WorkspaceSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Css = goog.require('Blockly.Css'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const style = goog.require('Blockly.utils.style'); +/* eslint-disable-next-line no-unused-vars */ +const toolbox = goog.requireType('Blockly.utils.toolbox'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** * Class for a button in the flyout. - * @param {!Blockly.WorkspaceSvg} workspace The workspace in which to place this + * @param {!WorkspaceSvg} workspace The workspace in which to place this * button. - * @param {!Blockly.WorkspaceSvg} targetWorkspace The flyout's target workspace. - * @param {!Blockly.utils.toolbox.ButtonOrLabelInfo} json + * @param {!WorkspaceSvg} targetWorkspace The flyout's target workspace. + * @param {!toolbox.ButtonOrLabelInfo} json * The JSON specifying the label/button. * @param {boolean} isLabel Whether this button should be styled as a label. * @constructor @@ -40,13 +41,13 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { // Labels behave the same as buttons, but are styled differently. /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.targetWorkspace_ = targetWorkspace; @@ -58,10 +59,10 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { this.text_ = json['text']; /** - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.position_ = new Blockly.utils.Coordinate(0, 0); + this.position_ = new Coordinate(0, 0); /** * Whether this button should be styled as a label. @@ -88,14 +89,14 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { /** * Mouse up event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseUpWrapper_ = null; /** * The JSON specifying the label / button. - * @type {!Blockly.utils.toolbox.ButtonOrLabelInfo} + * @type {!toolbox.ButtonOrLabelInfo} */ this.info = json; }; @@ -132,15 +133,15 @@ FlyoutButton.prototype.createDom = function() { cssClass += ' ' + this.cssClass_; } - this.svgGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {'class': cssClass}, + this.svgGroup_ = dom.createSvgElement( + Svg.G, {'class': cssClass}, this.workspace_.getCanvas()); let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). - shadow = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + shadow = dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyFlyoutButtonShadow', 'rx': 4, 'ry': 4, 'x': 1, 'y': 1 @@ -148,8 +149,8 @@ FlyoutButton.prototype.createDom = function() { this.svgGroup_); } // Background rectangle. - const rect = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + const rect = dom.createSvgElement( + Svg.RECT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', @@ -157,8 +158,8 @@ FlyoutButton.prototype.createDom = function() { }, this.svgGroup_); - const svgText = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, + const svgText = dom.createSvgElement( + Svg.TEXT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', 'x': 0, @@ -166,7 +167,7 @@ FlyoutButton.prototype.createDom = function() { 'text-anchor': 'middle' }, this.svgGroup_); - let text = Blockly.utils.replaceMessageReferences(this.text_); + let text = replaceMessageReferences(this.text_); if (this.workspace_.RTL) { // Force text to be RTL by adding an RLM. text += '\u200F'; @@ -178,12 +179,12 @@ FlyoutButton.prototype.createDom = function() { 'flyoutForegroundColour', 'fill'); } - const fontSize = Blockly.utils.style.getComputedStyle(svgText, 'fontSize'); - const fontWeight = Blockly.utils.style.getComputedStyle(svgText, 'fontWeight'); - const fontFamily = Blockly.utils.style.getComputedStyle(svgText, 'fontFamily'); - this.width = Blockly.utils.dom.getFastTextWidthWithSizeString(svgText, + const fontSize = style.getComputedStyle(svgText, 'fontSize'); + const fontWeight = style.getComputedStyle(svgText, 'fontWeight'); + const fontFamily = style.getComputedStyle(svgText, 'fontFamily'); + this.width = dom.getFastTextWidthWithSizeString(svgText, fontSize, fontWeight, fontFamily); - const fontMetrics = Blockly.utils.dom.measureFontMetrics(text, fontSize, + const fontMetrics = dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; @@ -202,7 +203,7 @@ FlyoutButton.prototype.createDom = function() { this.updateTransform_(); - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseUpWrapper_ = browserEvents.conditionalBind( this.svgGroup_, 'mouseup', this, this.onMouseUp_); return this.svgGroup_; }; @@ -244,7 +245,7 @@ FlyoutButton.prototype.isLabel = function() { /** * Location of the button. - * @return {!Blockly.utils.Coordinate} x, y coordinates. + * @return {!Coordinate} x, y coordinates. * @package */ FlyoutButton.prototype.getPosition = function() { @@ -260,7 +261,7 @@ FlyoutButton.prototype.getButtonText = function() { /** * Get the button's target workspace. - * @return {!Blockly.WorkspaceSvg} The target workspace of the flyout where this + * @return {!WorkspaceSvg} The target workspace of the flyout where this * button resides. */ FlyoutButton.prototype.getTargetWorkspace = function() { @@ -272,10 +273,10 @@ FlyoutButton.prototype.getTargetWorkspace = function() { */ FlyoutButton.prototype.dispose = function() { if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + browserEvents.unbind(this.onMouseUpWrapper_); } if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); } if (this.svgText_) { this.workspace_.getThemeManager().unsubscribe(this.svgText_); @@ -306,7 +307,7 @@ FlyoutButton.prototype.onMouseUp_ = function(e) { /** * CSS for buttons and labels. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyFlyoutButton {', 'fill: #888;', From 6a43f7c9b7f04bbc355bb0fb1a9b7313d4cabfd4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 22 Jul 2021 15:04:19 -0700 Subject: [PATCH 253/833] clang-format core/flyout_button.js --- core/flyout_button.js | 57 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/core/flyout_button.js b/core/flyout_button.js index 372060237..db05ca4f4 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -77,8 +77,8 @@ const FlyoutButton = function(workspace, targetWorkspace, json, isLabel) { * @private */ this.callbackKey_ = json['callbackKey'] || - /* Check the lower case version too to satisfy IE */ - json['callbackkey']; + /* Check the lower case version too to satisfy IE */ + json['callbackkey']; /** * If specified, a CSS class to add to this button. @@ -134,33 +134,33 @@ FlyoutButton.prototype.createDom = function() { } this.svgGroup_ = dom.createSvgElement( - Svg.G, {'class': cssClass}, - this.workspace_.getCanvas()); + Svg.G, {'class': cssClass}, this.workspace_.getCanvas()); let shadow; if (!this.isLabel_) { // Shadow rectangle (light source does not mirror in RTL). shadow = dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyFlyoutButtonShadow', - 'rx': 4, 'ry': 4, 'x': 1, 'y': 1 + 'rx': 4, + 'ry': 4, + 'x': 1, + 'y': 1 }, this.svgGroup_); } // Background rectangle. const rect = dom.createSvgElement( - Svg.RECT, - { - 'class': this.isLabel_ ? - 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', - 'rx': 4, 'ry': 4 + Svg.RECT, { + 'class': this.isLabel_ ? 'blocklyFlyoutLabelBackground' : + 'blocklyFlyoutButtonBackground', + 'rx': 4, + 'ry': 4 }, this.svgGroup_); const svgText = dom.createSvgElement( - Svg.TEXT, - { + Svg.TEXT, { 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', 'x': 0, 'y': 0, @@ -175,17 +175,17 @@ FlyoutButton.prototype.createDom = function() { svgText.textContent = text; if (this.isLabel_) { this.svgText_ = svgText; - this.workspace_.getThemeManager().subscribe(this.svgText_, - 'flyoutForegroundColour', 'fill'); + this.workspace_.getThemeManager().subscribe( + this.svgText_, 'flyoutForegroundColour', 'fill'); } const fontSize = style.getComputedStyle(svgText, 'fontSize'); const fontWeight = style.getComputedStyle(svgText, 'fontWeight'); const fontFamily = style.getComputedStyle(svgText, 'fontFamily'); - this.width = dom.getFastTextWidthWithSizeString(svgText, - fontSize, fontWeight, fontFamily); - const fontMetrics = dom.measureFontMetrics(text, fontSize, - fontWeight, fontFamily); + this.width = dom.getFastTextWidthWithSizeString( + svgText, fontSize, fontWeight, fontFamily); + const fontMetrics = + dom.measureFontMetrics(text, fontSize, fontWeight, fontFamily); this.height = fontMetrics.height; if (!this.isLabel_) { @@ -198,8 +198,8 @@ FlyoutButton.prototype.createDom = function() { rect.setAttribute('height', this.height); svgText.setAttribute('x', this.width / 2); - svgText.setAttribute('y', this.height / 2 - fontMetrics.height / 2 + - fontMetrics.baseline); + svgText.setAttribute( + 'y', this.height / 2 - fontMetrics.height / 2 + fontMetrics.baseline); this.updateTransform_(); @@ -221,7 +221,8 @@ FlyoutButton.prototype.show = function() { * @private */ FlyoutButton.prototype.updateTransform_ = function() { - this.svgGroup_.setAttribute('transform', + this.svgGroup_.setAttribute( + 'transform', 'translate(' + this.position_.x + ',' + this.position_.y + ')'); }; @@ -296,8 +297,10 @@ FlyoutButton.prototype.onMouseUp_ = function(e) { if (this.isLabel_ && this.callbackKey_) { console.warn('Labels should not have callbacks. Label text: ' + this.text_); - } else if (!this.isLabel_ && !(this.callbackKey_ && - this.targetWorkspace_.getButtonCallback(this.callbackKey_))) { + } else if ( + !this.isLabel_ && + !(this.callbackKey_ && + this.targetWorkspace_.getButtonCallback(this.callbackKey_))) { console.warn('Buttons should have callbacks. Button text: ' + this.text_); } else if (!this.isLabel_) { this.targetWorkspace_.getButtonCallback(this.callbackKey_)(this); @@ -326,9 +329,7 @@ Css.register([ 'cursor: default;', '}', - '.blocklyFlyoutLabelBackground {', - 'opacity: 0;', - '}', + '.blocklyFlyoutLabelBackground {', 'opacity: 0;', '}', /* eslint-enable indent */ ]); From 8cb794feb5f9285476c6fdff6e7467881535afcf Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 16:36:30 -0700 Subject: [PATCH 254/833] Suppress unused vars --- core/menu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.js b/core/menu.js index 083d76e06..6a1667964 100644 --- a/core/menu.js +++ b/core/menu.js @@ -14,6 +14,7 @@ goog.module('Blockly.Menu'); goog.module.declareLegacyNamespace(); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); const Size = goog.requireType('Blockly.utils.Size'); From 39f5b4c7cd606602cffa70a1b8d2f60d3f794296 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 16:49:01 -0700 Subject: [PATCH 255/833] Fixes lint warnings --- core/menu.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/menu.js b/core/menu.js index 6a1667964..91cfb4d36 100644 --- a/core/menu.js +++ b/core/menu.js @@ -17,6 +17,7 @@ const Coordinate = goog.require('Blockly.utils.Coordinate'); /* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); const aria = goog.require('Blockly.utils.aria'); const browserEvents = goog.require('Blockly.browserEvents'); From b07c6869ba6cc42b80db3c8a9b458d04b930fc20 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:28 -0700 Subject: [PATCH 256/833] Migrate core/field_label_serializable.js to ES6 const/let --- core/field_label_serializable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 0201db130..0d1acf52a 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -47,7 +47,7 @@ Blockly.utils.object.inherits(Blockly.FieldLabelSerializable, * @nocollapse */ Blockly.FieldLabelSerializable.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. return new this(text, undefined, options); From 20ef2462b5bdaf24d0e2d527ca63e8bb25e806cc Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:40 -0700 Subject: [PATCH 257/833] Migrate core/field_label_serializable.js to goog.module --- core/field_label_serializable.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 0d1acf52a..77784eb4c 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabelSerializable'); +goog.module('Blockly.FieldLabelSerializable'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.FieldLabel'); goog.require('Blockly.fieldRegistry'); @@ -31,22 +32,22 @@ goog.require('Blockly.utils.object'); * @constructor * */ -Blockly.FieldLabelSerializable = function(opt_value, opt_class, opt_config) { - Blockly.FieldLabelSerializable.superClass_.constructor.call( +const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { + FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -Blockly.utils.object.inherits(Blockly.FieldLabelSerializable, +Blockly.utils.object.inherits(FieldLabelSerializable, Blockly.FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabelSerializable} The new field instance. + * @return {!FieldLabelSerializable} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabelSerializable.fromJson = function(options) { +FieldLabelSerializable.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. @@ -58,14 +59,16 @@ Blockly.FieldLabelSerializable.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabelSerializable.prototype.EDITABLE = false; +FieldLabelSerializable.prototype.EDITABLE = false; /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. This field should be serialized, but only edited programmatically. * @type {boolean} */ -Blockly.FieldLabelSerializable.prototype.SERIALIZABLE = true; +FieldLabelSerializable.prototype.SERIALIZABLE = true; Blockly.fieldRegistry.register( - 'field_label_serializable', Blockly.FieldLabelSerializable); + 'field_label_serializable', FieldLabelSerializable); + +exports = FieldLabelSerializable; diff --git a/tests/deps.js b/tests/deps.js index d02bbc5ea..226f67c0f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -55,7 +55,7 @@ goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Bloc goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); -goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); From bcb57b7efd721878e275255ac4b09fc18064fced Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:45:51 -0700 Subject: [PATCH 258/833] Migrate core/field_label_serializable.js named requires --- core/field_label_serializable.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 77784eb4c..828a9954b 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -14,10 +14,10 @@ goog.module('Blockly.FieldLabelSerializable'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.FieldLabel'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); +const FieldLabel = goog.require('Blockly.FieldLabel'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -28,7 +28,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldLabel} + * @extends {FieldLabel} * @constructor * */ @@ -36,8 +36,8 @@ const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -Blockly.utils.object.inherits(FieldLabelSerializable, - Blockly.FieldLabel); +inherits(FieldLabelSerializable, + FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, @@ -48,7 +48,7 @@ Blockly.utils.object.inherits(FieldLabelSerializable, * @nocollapse */ FieldLabelSerializable.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabelSerializable if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -68,7 +68,7 @@ FieldLabelSerializable.prototype.EDITABLE = false; */ FieldLabelSerializable.prototype.SERIALIZABLE = true; -Blockly.fieldRegistry.register( +fieldRegistry.register( 'field_label_serializable', FieldLabelSerializable); exports = FieldLabelSerializable; From 569a86901ea7888678d7364e96a1d6b99284d103 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:08:45 -0700 Subject: [PATCH 259/833] clang-format core/field_label_serializable.js --- core/field_label_serializable.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/field_label_serializable.js b/core/field_label_serializable.js index 828a9954b..daabaa59f 100644 --- a/core/field_label_serializable.js +++ b/core/field_label_serializable.js @@ -26,7 +26,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * string. Defaults to an empty string if null or undefined. * @param {string=} opt_class Optional CSS class for the field's text. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label-serializable#creation} * for a list of properties this parameter supports. * @extends {FieldLabel} * @constructor @@ -36,8 +37,7 @@ const FieldLabelSerializable = function(opt_value, opt_class, opt_config) { FieldLabelSerializable.superClass_.constructor.call( this, opt_value, opt_class, opt_config); }; -inherits(FieldLabelSerializable, - FieldLabel); +inherits(FieldLabelSerializable, FieldLabel); /** * Construct a FieldLabelSerializable from a JSON arg object, @@ -68,7 +68,6 @@ FieldLabelSerializable.prototype.EDITABLE = false; */ FieldLabelSerializable.prototype.SERIALIZABLE = true; -fieldRegistry.register( - 'field_label_serializable', FieldLabelSerializable); +fieldRegistry.register('field_label_serializable', FieldLabelSerializable); exports = FieldLabelSerializable; From 60c03cef4fd495cb2a23dc25ce00d70d9e2b89bd Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:23:23 -0700 Subject: [PATCH 260/833] Migrate core/field_image.js to ES6 const/let --- core/field_image.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index eed381b63..163941efb 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -44,8 +44,8 @@ Blockly.FieldImage = function(src, width, height, throw Error('Src value of an image field is required'); } src = Blockly.utils.replaceMessageReferences(src); - var imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); - var imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); + const imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); + const imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error('Height and width values of an image field must cast to' + ' numbers.'); From f1882fc2180949292db8f5961ffa8308ff254c26 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:23:35 -0700 Subject: [PATCH 261/833] Migrate core/field_image.js to goog.module --- core/field_image.js | 55 ++++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 163941efb..68a1fb43c 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldImage'); +goog.module('Blockly.FieldImage'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.Svg'); * @param {!(string|number)} width Width of the image. * @param {!(string|number)} height Height of the image. * @param {string=} opt_alt Optional alt text for when block is collapsed. - * @param {function(!Blockly.FieldImage)=} opt_onClick Optional function to be + * @param {function(!FieldImage)=} opt_onClick Optional function to be * called when the image is clicked. If opt_onClick is defined, opt_alt must * also be defined. * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL. @@ -37,7 +38,7 @@ goog.require('Blockly.utils.Svg'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldImage = function(src, width, height, +const FieldImage = function(src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) { // Return early. if (!src) { @@ -70,7 +71,7 @@ Blockly.FieldImage = function(src, width, height, */ this.altText_ = ''; - Blockly.FieldImage.superClass_.constructor.call( + FieldImage.superClass_.constructor.call( this, src, null, opt_config); if (!opt_config) { // If the config wasn't passed, do old configuration. @@ -86,7 +87,7 @@ Blockly.FieldImage = function(src, width, height, * @override */ this.size_ = new Blockly.utils.Size(imageWidth, - imageHeight + Blockly.FieldImage.Y_PADDING); + imageHeight + FieldImage.Y_PADDING); /** * Store the image height, since it is different from the field height. @@ -97,7 +98,7 @@ Blockly.FieldImage = function(src, width, height, /** * The function to be called when this field is clicked. - * @type {?function(!Blockly.FieldImage)} + * @type {?function(!FieldImage)} * @private */ this.clickHandler_ = null; @@ -113,25 +114,25 @@ Blockly.FieldImage = function(src, width, height, */ this.imageElement_ = null; }; -Blockly.utils.object.inherits(Blockly.FieldImage, Blockly.Field); +Blockly.utils.object.inherits(FieldImage, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldImage.prototype.DEFAULT_VALUE = ''; +FieldImage.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldImage from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (src, width, height, * alt, and flipRtl). - * @return {!Blockly.FieldImage} The new field instance. + * @return {!FieldImage} The new field instance. * @package * @nocollapse */ -Blockly.FieldImage.fromJson = function(options) { +FieldImage.fromJson = function(options) { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. return new this(options['src'], options['width'], options['height'], @@ -144,14 +145,14 @@ Blockly.FieldImage.fromJson = function(options) { * @type {number} * @private */ -Blockly.FieldImage.Y_PADDING = 1; +FieldImage.Y_PADDING = 1; /** * Editable fields usually show some sort of UI indicating they are * editable. This field should not. * @type {boolean} */ -Blockly.FieldImage.prototype.EDITABLE = false; +FieldImage.prototype.EDITABLE = false; /** * Used to tell if the field needs to be rendered the next time the block is @@ -160,7 +161,7 @@ Blockly.FieldImage.prototype.EDITABLE = false; * @type {boolean} * @protected */ -Blockly.FieldImage.prototype.isDirty_ = false; +FieldImage.prototype.isDirty_ = false; /** * Configure the field based on the given map of options. @@ -168,8 +169,8 @@ Blockly.FieldImage.prototype.isDirty_ = false; * @protected * @override */ -Blockly.FieldImage.prototype.configure_ = function(config) { - Blockly.FieldImage.superClass_.configure_.call(this, config); +FieldImage.prototype.configure_ = function(config) { + FieldImage.superClass_.configure_.call(this, config); this.flipRtl_ = !!config['flipRtl']; this.altText_ = Blockly.utils.replaceMessageReferences(config['alt']) || ''; }; @@ -178,7 +179,7 @@ Blockly.FieldImage.prototype.configure_ = function(config) { * Create the block UI for this image. * @package */ -Blockly.FieldImage.prototype.initView = function() { +FieldImage.prototype.initView = function() { this.imageElement_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { @@ -198,7 +199,7 @@ Blockly.FieldImage.prototype.initView = function() { /** * @override */ -Blockly.FieldImage.prototype.updateSize_ = function() { +FieldImage.prototype.updateSize_ = function() { // NOP }; @@ -208,7 +209,7 @@ Blockly.FieldImage.prototype.updateSize_ = function() { * @return {?string} A string, or null if invalid. * @protected */ -Blockly.FieldImage.prototype.doClassValidation_ = function(opt_newValue) { +FieldImage.prototype.doClassValidation_ = function(opt_newValue) { if (typeof opt_newValue != 'string') { return null; } @@ -221,7 +222,7 @@ Blockly.FieldImage.prototype.doClassValidation_ = function(opt_newValue) { * that this is a string. * @protected */ -Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) { +FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, @@ -234,7 +235,7 @@ Blockly.FieldImage.prototype.doValueUpdate_ = function(newValue) { * @return {boolean} True if we should flip in RTL. * @override */ -Blockly.FieldImage.prototype.getFlipRtl = function() { +FieldImage.prototype.getFlipRtl = function() { return this.flipRtl_; }; @@ -243,7 +244,7 @@ Blockly.FieldImage.prototype.getFlipRtl = function() { * @param {?string} alt New alt text. * @public */ -Blockly.FieldImage.prototype.setAlt = function(alt) { +FieldImage.prototype.setAlt = function(alt) { if (alt == this.altText_) { return; } @@ -258,7 +259,7 @@ Blockly.FieldImage.prototype.setAlt = function(alt) { * call the handler. * @protected */ -Blockly.FieldImage.prototype.showEditor_ = function() { +FieldImage.prototype.showEditor_ = function() { if (this.clickHandler_) { this.clickHandler_(this); } @@ -266,10 +267,10 @@ Blockly.FieldImage.prototype.showEditor_ = function() { /** * Set the function that is called when this image is clicked. - * @param {?function(!Blockly.FieldImage)} func The function that is called + * @param {?function(!FieldImage)} func The function that is called * when the image is clicked, or null to remove. */ -Blockly.FieldImage.prototype.setOnClickHandler = function(func) { +FieldImage.prototype.setOnClickHandler = function(func) { this.clickHandler_ = func; }; @@ -281,8 +282,10 @@ Blockly.FieldImage.prototype.setOnClickHandler = function(func) { * @protected * @override */ -Blockly.FieldImage.prototype.getText_ = function() { +FieldImage.prototype.getText_ = function() { return this.altText_; }; -Blockly.fieldRegistry.register('field_image', Blockly.FieldImage); +Blockly.fieldRegistry.register('field_image', FieldImage); + +exports = FieldImage; diff --git a/tests/deps.js b/tests/deps.js index 226f67c0f..77f7d15a2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -53,7 +53,7 @@ goog.addDependency('../../core/field_angle.js', ['Blockly.FieldAngle'], ['Blockl goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], ['Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); From 8a934b0e9c27871561679bca3e502a51f41b16ec Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:24:07 -0700 Subject: [PATCH 262/833] Migrate core/field_image.js named requires --- core/field_image.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 68a1fb43c..09c814a1b 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -13,13 +13,13 @@ goog.module('Blockly.FieldImage'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); +const Field = goog.require('Blockly.Field'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const {createSvgElement, XLINK_NS} = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -35,7 +35,7 @@ goog.require('Blockly.utils.Svg'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldImage = function(src, width, height, @@ -44,9 +44,9 @@ const FieldImage = function(src, width, height, if (!src) { throw Error('Src value of an image field is required'); } - src = Blockly.utils.replaceMessageReferences(src); - const imageHeight = Number(Blockly.utils.replaceMessageReferences(height)); - const imageWidth = Number(Blockly.utils.replaceMessageReferences(width)); + src = replaceMessageReferences(src); + const imageHeight = Number(replaceMessageReferences(height)); + const imageWidth = Number(replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { throw Error('Height and width values of an image field must cast to' + ' numbers.'); @@ -76,17 +76,17 @@ const FieldImage = function(src, width, height, if (!opt_config) { // If the config wasn't passed, do old configuration. this.flipRtl_ = !!opt_flipRtl; - this.altText_ = Blockly.utils.replaceMessageReferences(opt_alt) || ''; + this.altText_ = replaceMessageReferences(opt_alt) || ''; } // Initialize other properties. /** * The size of the area rendered by the field. - * @type {Blockly.utils.Size} + * @type {Size} * @protected * @override */ - this.size_ = new Blockly.utils.Size(imageWidth, + this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING); /** @@ -114,7 +114,7 @@ const FieldImage = function(src, width, height, */ this.imageElement_ = null; }; -Blockly.utils.object.inherits(FieldImage, Blockly.Field); +inherits(FieldImage, Field); /** * The default value for this field. @@ -172,7 +172,7 @@ FieldImage.prototype.isDirty_ = false; FieldImage.prototype.configure_ = function(config) { FieldImage.superClass_.configure_.call(this, config); this.flipRtl_ = !!config['flipRtl']; - this.altText_ = Blockly.utils.replaceMessageReferences(config['alt']) || ''; + this.altText_ = replaceMessageReferences(config['alt']) || ''; }; /** @@ -180,15 +180,15 @@ FieldImage.prototype.configure_ = function(config) { * @package */ FieldImage.prototype.initView = function() { - this.imageElement_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, + this.imageElement_ = createSvgElement( + Svg.IMAGE, { 'height': this.imageHeight_ + 'px', 'width': this.size_.width + 'px', 'alt': this.altText_ }, this.fieldGroup_); - this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, + this.imageElement_.setAttributeNS(XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_)); if (this.clickHandler_) { @@ -225,7 +225,7 @@ FieldImage.prototype.doClassValidation_ = function(opt_newValue) { FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { - this.imageElement_.setAttributeNS(Blockly.utils.dom.XLINK_NS, + this.imageElement_.setAttributeNS(XLINK_NS, 'xlink:href', String(this.value_)); } }; @@ -286,6 +286,6 @@ FieldImage.prototype.getText_ = function() { return this.altText_; }; -Blockly.fieldRegistry.register('field_image', FieldImage); +fieldRegistry.register('field_image', FieldImage); exports = FieldImage; From 8b815cd5b14976764b243dce5b9d625874baad5d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:41:35 -0700 Subject: [PATCH 263/833] clang-format core/field_image.js --- core/field_image.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/core/field_image.js b/core/field_image.js index 09c814a1b..9edc92c56 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -33,13 +33,14 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * also be defined. * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor */ -const FieldImage = function(src, width, height, - opt_alt, opt_onClick, opt_flipRtl, opt_config) { +const FieldImage = function( + src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) { // Return early. if (!src) { throw Error('Src value of an image field is required'); @@ -48,12 +49,14 @@ const FieldImage = function(src, width, height, const imageHeight = Number(replaceMessageReferences(height)); const imageWidth = Number(replaceMessageReferences(width)); if (isNaN(imageHeight) || isNaN(imageWidth)) { - throw Error('Height and width values of an image field must cast to' + - ' numbers.'); + throw Error( + 'Height and width values of an image field must cast to' + + ' numbers.'); } if (imageHeight <= 0 || imageWidth <= 0) { - throw Error('Height and width values of an image field must be greater' + - ' than 0.'); + throw Error( + 'Height and width values of an image field must be greater' + + ' than 0.'); } // Initialize configurable properties. @@ -71,8 +74,7 @@ const FieldImage = function(src, width, height, */ this.altText_ = ''; - FieldImage.superClass_.constructor.call( - this, src, null, opt_config); + FieldImage.superClass_.constructor.call(this, src, null, opt_config); if (!opt_config) { // If the config wasn't passed, do old configuration. this.flipRtl_ = !!opt_flipRtl; @@ -86,8 +88,7 @@ const FieldImage = function(src, width, height, * @protected * @override */ - this.size_ = new Size(imageWidth, - imageHeight + FieldImage.Y_PADDING); + this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING); /** * Store the image height, since it is different from the field height. @@ -135,8 +136,9 @@ FieldImage.prototype.DEFAULT_VALUE = ''; FieldImage.fromJson = function(options) { // `this` might be a subclass of FieldImage if that class doesn't override // the static fromJson method. - return new this(options['src'], options['width'], options['height'], - undefined, undefined, undefined, options); + return new this( + options['src'], options['width'], options['height'], undefined, undefined, + undefined, options); }; /** @@ -181,15 +183,14 @@ FieldImage.prototype.configure_ = function(config) { */ FieldImage.prototype.initView = function() { this.imageElement_ = createSvgElement( - Svg.IMAGE, - { + Svg.IMAGE, { 'height': this.imageHeight_ + 'px', 'width': this.size_.width + 'px', 'alt': this.altText_ }, this.fieldGroup_); - this.imageElement_.setAttributeNS(XLINK_NS, - 'xlink:href', /** @type {string} */ (this.value_)); + this.imageElement_.setAttributeNS( + XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_)); if (this.clickHandler_) { this.imageElement_.style.cursor = 'pointer'; @@ -225,8 +226,8 @@ FieldImage.prototype.doClassValidation_ = function(opt_newValue) { FieldImage.prototype.doValueUpdate_ = function(newValue) { this.value_ = newValue; if (this.imageElement_) { - this.imageElement_.setAttributeNS(XLINK_NS, - 'xlink:href', String(this.value_)); + this.imageElement_.setAttributeNS( + XLINK_NS, 'xlink:href', String(this.value_)); } }; From ae818c05261522af9ab105712ffb2004690a530d Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:52:54 -0700 Subject: [PATCH 264/833] Migrate core/field_multilineinput.js to ES6 const/let --- core/field_multilineinput.js | 70 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index 887d4007f..d57989b86 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -88,7 +88,7 @@ Blockly.FieldMultilineInput.prototype.configure_ = function(config) { * @nocollapse */ Blockly.FieldMultilineInput.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -141,16 +141,17 @@ Blockly.FieldMultilineInput.prototype.initView = function() { * @override */ Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { - var textLines = this.getText(); + let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. return Blockly.Field.NBSP; } - var lines = textLines.split('\n'); + const lines = textLines.split('\n'); textLines = ''; - var displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ : lines.length; - for (var i = 0; i < displayLinesNumber; i++) { - var text = lines[i]; + const displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ + : lines.length; + for (let i = 0; i < displayLinesNumber; i++) { + let text = lines[i]; if (text.length > this.maxDisplayLength) { // Truncate displayed string and add an ellipsis ('...'). text = text.substring(0, this.maxDisplayLength - 4) + '...'; @@ -192,18 +193,18 @@ Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { */ Blockly.FieldMultilineInput.prototype.render_ = function() { // Remove all text group children. - var currentChild; + let currentChild; while ((currentChild = this.textGroup_.firstChild)) { this.textGroup_.removeChild(currentChild); } // Add in text elements into the group. - var lines = this.getDisplayText_().split('\n'); - var y = 0; - for (var i = 0; i < lines.length; i++) { - var lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + + const lines = this.getDisplayText_().split('\n'); + let y = 0; + for (let i = 0; i < lines.length; i++) { + const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; - var span = Blockly.utils.dom.createSvgElement( + const span = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, @@ -252,12 +253,12 @@ Blockly.FieldMultilineInput.prototype.render_ = function() { * @protected */ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { - var nodes = this.textGroup_.childNodes; - var totalWidth = 0; - var totalHeight = 0; + const nodes = this.textGroup_.childNodes; + let totalWidth = 0; + let totalHeight = 0; for (var i = 0; i < nodes.length; i++) { - var tspan = /** @type {!Element} */ (nodes[i]); - var textWidth = Blockly.utils.dom.getTextWidth(tspan); + const tspan = /** @type {!Element} */ (nodes[i]); + const textWidth = Blockly.utils.dom.getTextWidth(tspan); if (textWidth > totalWidth) { totalWidth = textWidth; } @@ -270,26 +271,27 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { // absolute longest line, even if it would be truncated after editing. // Otherwise we would get wrong editor width when there are more // lines than this.maxLines_. - var actualEditorLines = this.value_.split('\n'); - var dummyTextElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT,{'class': 'blocklyText blocklyMultilineText'}); - var fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; - var fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; - var fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; + const actualEditorLines = this.value_.split('\n'); + const dummyTextElement = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); + const fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; + const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; + const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; for (var i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; - var lineWidth = Blockly.utils.dom.getFastTextWidth( + const lineWidth = Blockly.utils.dom.getFastTextWidth( dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; } } - var scrollbarWidth = this.htmlInput_.offsetWidth - this.htmlInput_.clientWidth; + const scrollbarWidth = this.htmlInput_.offsetWidth + - this.htmlInput_.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -325,23 +327,23 @@ Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietIn * @protected */ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { - var div = Blockly.WidgetDiv.DIV; - var scale = this.workspace_.getScale(); + const div = Blockly.WidgetDiv.DIV; + const scale = this.workspace_.getScale(); - var htmlInput = - /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); + const htmlInput = + /** @type {HTMLTextAreaElement} */ (document.createElement('textarea')); htmlInput.className = 'blocklyHtmlInput blocklyHtmlTextAreaInput'; htmlInput.setAttribute('spellcheck', this.spellcheck_); - var fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; + const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - var borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + const borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; htmlInput.style.borderRadius = borderRadius; - var paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; - var paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; + const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; + const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + 'px ' + paddingX + 'px'; - var lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + + const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = (lineHeight * scale) + 'px'; From 8af597761d267fde72c23794badeb35bb6c57a17 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:53:18 -0700 Subject: [PATCH 265/833] Migrate core/field_multilineinput.js to goog.module --- core/field_multilineinput.js | 51 +++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index d57989b86..ea6ed7531 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldMultilineInput'); +goog.module('Blockly.FieldMultilineInput'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Css'); goog.require('Blockly.Field'); @@ -42,8 +43,8 @@ goog.require('Blockly.WidgetDiv'); * @extends {Blockly.FieldTextInput} * @constructor */ -Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { - Blockly.FieldMultilineInput.superClass_.constructor.call(this, +const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { + FieldMultilineInput.superClass_.constructor.call(this, opt_value, opt_validator, opt_config); /** @@ -68,14 +69,14 @@ Blockly.FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -Blockly.utils.object.inherits(Blockly.FieldMultilineInput, +Blockly.utils.object.inherits(FieldMultilineInput, Blockly.FieldTextInput); /** * @override */ -Blockly.FieldMultilineInput.prototype.configure_ = function(config) { - Blockly.FieldMultilineInput.superClass_.configure_.call(this, config); +FieldMultilineInput.prototype.configure_ = function(config) { + FieldMultilineInput.superClass_.configure_.call(this, config); config.maxLines && this.setMaxLines(config.maxLines); }; @@ -83,11 +84,11 @@ Blockly.FieldMultilineInput.prototype.configure_ = function(config) { * Construct a FieldMultilineInput from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and spellcheck). - * @return {!Blockly.FieldMultilineInput} The new field instance. + * @return {!FieldMultilineInput} The new field instance. * @package * @nocollapse */ -Blockly.FieldMultilineInput.fromJson = function(options) { +FieldMultilineInput.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. @@ -101,7 +102,7 @@ Blockly.FieldMultilineInput.fromJson = function(options) { * @return {!Element} The element containing info about the field's state. * @package */ -Blockly.FieldMultilineInput.prototype.toXml = function(fieldElement) { +FieldMultilineInput.prototype.toXml = function(fieldElement) { // Replace '\n' characters with HTML-escaped equivalent ' '. This is // needed so the plain-text representation of the XML produced by // `Blockly.Xml.domToText` will appear on a single line (this is a limitation @@ -117,7 +118,7 @@ Blockly.FieldMultilineInput.prototype.toXml = function(fieldElement) { * field's state. * @package */ -Blockly.FieldMultilineInput.prototype.fromXml = function(fieldElement) { +FieldMultilineInput.prototype.fromXml = function(fieldElement) { this.setValue(fieldElement.textContent.replace(/ /g, '\n')); }; @@ -125,7 +126,7 @@ Blockly.FieldMultilineInput.prototype.fromXml = function(fieldElement) { * Create the block UI for this field. * @package */ -Blockly.FieldMultilineInput.prototype.initView = function() { +FieldMultilineInput.prototype.initView = function() { this.createBorderRect_(); this.textGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, { @@ -140,7 +141,7 @@ Blockly.FieldMultilineInput.prototype.initView = function() { * @protected * @override */ -Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { +FieldMultilineInput.prototype.getDisplayText_ = function() { let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. @@ -182,8 +183,8 @@ Blockly.FieldMultilineInput.prototype.getDisplayText_ = function() { * that this is a string. * @protected */ -Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { - Blockly.FieldMultilineInput.superClass_.doValueUpdate_.call(this, newValue); +FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { + FieldMultilineInput.superClass_.doValueUpdate_.call(this, newValue); this.isOverflowedY_ = this.value_.split('\n').length > this.maxLines_; }; @@ -191,7 +192,7 @@ Blockly.FieldMultilineInput.prototype.doValueUpdate_ = function(newValue) { * Updates the text of the textElement. * @protected */ -Blockly.FieldMultilineInput.prototype.render_ = function() { +FieldMultilineInput.prototype.render_ = function() { // Remove all text group children. let currentChild; while ((currentChild = this.textGroup_.firstChild)) { @@ -252,7 +253,7 @@ Blockly.FieldMultilineInput.prototype.render_ = function() { * Updates the size of the field based on the text. * @protected */ -Blockly.FieldMultilineInput.prototype.updateSize_ = function() { +FieldMultilineInput.prototype.updateSize_ = function() { const nodes = this.textGroup_.childNodes; let totalWidth = 0; let totalHeight = 0; @@ -316,8 +317,8 @@ Blockly.FieldMultilineInput.prototype.updateSize_ = function() { * focus. Defaults to false. * @override */ -Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - Blockly.FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); +FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { + FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); this.forceRerender(); }; @@ -326,7 +327,7 @@ Blockly.FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietIn * @return {!HTMLTextAreaElement} The newly created text input editor. * @protected */ -Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { +FieldMultilineInput.prototype.widgetCreate_ = function() { const div = Blockly.WidgetDiv.DIV; const scale = this.workspace_.getScale(); @@ -369,7 +370,7 @@ Blockly.FieldMultilineInput.prototype.widgetCreate_ = function() { * @param {number} maxLines Defines the maximum number of lines allowed, * before scrolling functionality is enabled. */ -Blockly.FieldMultilineInput.prototype.setMaxLines = function(maxLines) { +FieldMultilineInput.prototype.setMaxLines = function(maxLines) { if (typeof maxLines === 'number' && maxLines > 0 && maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); @@ -380,7 +381,7 @@ Blockly.FieldMultilineInput.prototype.setMaxLines = function(maxLines) { * Returns the maxLines config of this field. * @return {number} The maxLines config value. */ -Blockly.FieldMultilineInput.prototype.getMaxLines = function() { +FieldMultilineInput.prototype.getMaxLines = function() { return this.maxLines_; }; @@ -390,9 +391,9 @@ Blockly.FieldMultilineInput.prototype.getMaxLines = function() { * @param {!Event} e Keyboard event. * @protected */ -Blockly.FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { +FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { if (e.keyCode !== Blockly.utils.KeyCodes.ENTER) { - Blockly.FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); + FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); } }; @@ -415,4 +416,6 @@ Blockly.Css.register([ ]); -Blockly.fieldRegistry.register('field_multilinetext', Blockly.FieldMultilineInput); +Blockly.fieldRegistry.register('field_multilinetext', FieldMultilineInput); + +exports = FieldMultilineInput; diff --git a/tests/deps.js b/tests/deps.js index 77f7d15a2..f62333982 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -56,7 +56,7 @@ goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], [' goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_registry.js', ['Blockly.fieldRegistry'], ['Blockly.registry'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); From d91f36eab9f4e9a3251d95967ffea3947166daf5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:51:10 -0700 Subject: [PATCH 266/833] Migrate core/field_multilineinput.js named requires --- core/field_multilineinput.js | 80 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index ea6ed7531..f3872919a 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -15,18 +15,18 @@ goog.module('Blockly.FieldMultilineInput'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Css'); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.FieldTextInput'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); -goog.require('Blockly.WidgetDiv'); +const Css = goog.require('Blockly.Css'); +const Field = goog.require('Blockly.Field'); +const FieldTextInput = goog.require('Blockly.FieldTextInput'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +const Svg = goog.require('Blockly.utils.Svg'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -40,7 +40,7 @@ goog.require('Blockly.WidgetDiv'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} * for a list of properties this parameter supports. - * @extends {Blockly.FieldTextInput} + * @extends {FieldTextInput} * @constructor */ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { @@ -69,8 +69,8 @@ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -Blockly.utils.object.inherits(FieldMultilineInput, - Blockly.FieldTextInput); +inherits(FieldMultilineInput, + FieldTextInput); /** * @override @@ -89,7 +89,7 @@ FieldMultilineInput.prototype.configure_ = function(config) { * @nocollapse */ FieldMultilineInput.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldMultilineInput if that class doesn't // override the static fromJson method. return new this(text, undefined, options); @@ -128,8 +128,8 @@ FieldMultilineInput.prototype.fromXml = function(fieldElement) { */ FieldMultilineInput.prototype.initView = function() { this.createBorderRect_(); - this.textGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, { + this.textGroup_ = dom.createSvgElement( + Svg.G, { 'class': 'blocklyEditableText', }, this.fieldGroup_); }; @@ -145,7 +145,7 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { let textLines = this.getText(); if (!textLines) { // Prevent the field from disappearing if empty. - return Blockly.Field.NBSP; + return Field.NBSP; } const lines = textLines.split('\n'); textLines = ''; @@ -160,7 +160,7 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { text = text.substring(0, text.length - 3) + '...'; } // Replace whitespace with non-breaking spaces so the text doesn't collapse. - text = text.replace(/\s/g, Blockly.Field.NBSP); + text = text.replace(/\s/g, Field.NBSP); textLines += text; if (i !== displayLinesNumber - 1) { @@ -205,8 +205,8 @@ FieldMultilineInput.prototype.render_ = function() { for (let i = 0; i < lines.length; i++) { const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; - const span = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + const span = dom.createSvgElement( + Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, @@ -219,9 +219,9 @@ FieldMultilineInput.prototype.render_ = function() { if (this.isBeingEdited_) { var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (this.isOverflowedY_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); + dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); + dom.removeClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } } @@ -238,13 +238,13 @@ FieldMultilineInput.prototype.render_ = function() { } var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); if (!this.isTextValid_) { - Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, true); + dom.addClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, true); } else { - Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); - Blockly.utils.aria.setState(htmlInput, - Blockly.utils.aria.State.INVALID, false); + dom.removeClass(htmlInput, 'blocklyInvalidInput'); + aria.setState(htmlInput, + aria.State.INVALID, false); } } }; @@ -259,7 +259,7 @@ FieldMultilineInput.prototype.updateSize_ = function() { let totalHeight = 0; for (var i = 0; i < nodes.length; i++) { const tspan = /** @type {!Element} */ (nodes[i]); - const textWidth = Blockly.utils.dom.getTextWidth(tspan); + const textWidth = dom.getTextWidth(tspan); if (textWidth > totalWidth) { totalWidth = textWidth; } @@ -273,8 +273,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { // Otherwise we would get wrong editor width when there are more // lines than this.maxLines_. const actualEditorLines = this.value_.split('\n'); - const dummyTextElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); + const dummyTextElement = dom.createSvgElement( + Svg.TEXT, {'class': 'blocklyText blocklyMultilineText'}); const fontSize = this.getConstants().FIELD_TEXT_FONTSIZE; const fontWeight = this.getConstants().FIELD_TEXT_FONTWEIGHT; const fontFamily = this.getConstants().FIELD_TEXT_FONTFAMILY; @@ -284,7 +284,7 @@ FieldMultilineInput.prototype.updateSize_ = function() { actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; - const lineWidth = Blockly.utils.dom.getFastTextWidth( + const lineWidth = dom.getFastTextWidth( dummyTextElement, fontSize, fontWeight, fontFamily); if (lineWidth > totalWidth) { totalWidth = lineWidth; @@ -328,7 +328,7 @@ FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { * @protected */ FieldMultilineInput.prototype.widgetCreate_ = function() { - const div = Blockly.WidgetDiv.DIV; + const div = WidgetDiv.DIV; const scale = this.workspace_.getScale(); const htmlInput = @@ -338,7 +338,7 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { const fontSize = (this.getConstants().FIELD_TEXT_FONTSIZE * scale) + 'pt'; div.style.fontSize = fontSize; htmlInput.style.fontSize = fontSize; - const borderRadius = (Blockly.FieldTextInput.BORDERRADIUS * scale) + 'px'; + const borderRadius = (FieldTextInput.BORDERRADIUS * scale) + 'px'; htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; @@ -353,7 +353,7 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { htmlInput.value = htmlInput.defaultValue = this.getEditorText_(this.value_); htmlInput.untypedDefaultValue_ = this.value_; htmlInput.oldValue_ = null; - if (Blockly.utils.userAgent.GECKO) { + if (userAgent.GECKO) { // In FF, ensure the browser reflows before resizing to avoid issue #2777. setTimeout(this.resizeEditor_.bind(this), 0); } else { @@ -392,7 +392,7 @@ FieldMultilineInput.prototype.getMaxLines = function() { * @protected */ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { - if (e.keyCode !== Blockly.utils.KeyCodes.ENTER) { + if (e.keyCode !== KeyCodes.ENTER) { FieldMultilineInput.superClass_.onHtmlInputKeyDown_.call(this, e); } }; @@ -400,7 +400,7 @@ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { /** * CSS for multiline field. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyHtmlTextAreaInput {', 'font-family: monospace;', @@ -416,6 +416,6 @@ Blockly.Css.register([ ]); -Blockly.fieldRegistry.register('field_multilinetext', FieldMultilineInput); +fieldRegistry.register('field_multilinetext', FieldMultilineInput); exports = FieldMultilineInput; From aeac27661dacc3b01d9d6fb79ccf28b9b92681f5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 11:01:39 -0700 Subject: [PATCH 267/833] clang-format core/field_multilineinput.js --- core/field_multilineinput.js | 69 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index f3872919a..4842429a5 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -38,14 +38,15 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * text as an argument and returns either the accepted text, a replacement * text, or null to abort the change. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/multiline-text-input#creation} * for a list of properties this parameter supports. * @extends {FieldTextInput} * @constructor */ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { - FieldMultilineInput.superClass_.constructor.call(this, - opt_value, opt_validator, opt_config); + FieldMultilineInput.superClass_.constructor.call( + this, opt_value, opt_validator, opt_config); /** * The SVG group element that will contain a text element for each text row @@ -69,8 +70,7 @@ const FieldMultilineInput = function(opt_value, opt_validator, opt_config) { */ this.isOverflowedY_ = false; }; -inherits(FieldMultilineInput, - FieldTextInput); +inherits(FieldMultilineInput, FieldTextInput); /** * @override @@ -131,7 +131,8 @@ FieldMultilineInput.prototype.initView = function() { this.textGroup_ = dom.createSvgElement( Svg.G, { 'class': 'blocklyEditableText', - }, this.fieldGroup_); + }, + this.fieldGroup_); }; /** @@ -149,8 +150,8 @@ FieldMultilineInput.prototype.getDisplayText_ = function() { } const lines = textLines.split('\n'); textLines = ''; - const displayLinesNumber = this.isOverflowedY_ ? this.maxLines_ - : lines.length; + const displayLinesNumber = + this.isOverflowedY_ ? this.maxLines_ : lines.length; for (let i = 0; i < displayLinesNumber; i++) { let text = lines[i]; if (text.length > this.maxDisplayLength) { @@ -211,13 +212,14 @@ FieldMultilineInput.prototype.render_ = function() { x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, dy: this.getConstants().FIELD_TEXT_BASELINE - }, this.textGroup_); + }, + this.textGroup_); span.appendChild(document.createTextNode(lines[i])); y += lineHeight; } if (this.isBeingEdited_) { - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (this.isOverflowedY_) { dom.addClass(htmlInput, 'blocklyHtmlTextAreaInputOverflowedY'); } else { @@ -236,15 +238,13 @@ FieldMultilineInput.prototype.render_ = function() { } else { this.resizeEditor_(); } - var htmlInput = /** @type {!HTMLElement} */(this.htmlInput_); + var htmlInput = /** @type {!HTMLElement} */ (this.htmlInput_); if (!this.isTextValid_) { dom.addClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, true); + aria.setState(htmlInput, aria.State.INVALID, true); } else { dom.removeClass(htmlInput, 'blocklyInvalidInput'); - aria.setState(htmlInput, - aria.State.INVALID, false); + aria.setState(htmlInput, aria.State.INVALID, false); } } }; @@ -281,7 +281,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { for (var i = 0; i < actualEditorLines.length; i++) { if (actualEditorLines[i].length > this.maxDisplayLength) { - actualEditorLines[i] = actualEditorLines[i].substring(0, this.maxDisplayLength); + actualEditorLines[i] = + actualEditorLines[i].substring(0, this.maxDisplayLength); } dummyTextElement.textContent = actualEditorLines[i]; const lineWidth = dom.getFastTextWidth( @@ -291,8 +292,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { } } - const scrollbarWidth = this.htmlInput_.offsetWidth - - this.htmlInput_.clientWidth; + const scrollbarWidth = + this.htmlInput_.offsetWidth - this.htmlInput_.clientWidth; totalWidth += scrollbarWidth; } if (this.borderRect_) { @@ -318,7 +319,8 @@ FieldMultilineInput.prototype.updateSize_ = function() { * @override */ FieldMultilineInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - FieldMultilineInput.superClass_.showEditor_.call(this, _opt_e, opt_quietInput); + FieldMultilineInput.superClass_.showEditor_.call( + this, _opt_e, opt_quietInput); this.forceRerender(); }; @@ -342,8 +344,8 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { htmlInput.style.borderRadius = borderRadius; const paddingX = this.getConstants().FIELD_BORDER_RECT_X_PADDING * scale; const paddingY = this.getConstants().FIELD_BORDER_RECT_Y_PADDING * scale / 2; - htmlInput.style.padding = paddingY + 'px ' + paddingX + 'px ' + paddingY + - 'px ' + paddingX + 'px'; + htmlInput.style.padding = + paddingY + 'px ' + paddingX + 'px ' + paddingY + 'px ' + paddingX + 'px'; const lineHeight = this.getConstants().FIELD_TEXT_HEIGHT + this.getConstants().FIELD_BORDER_RECT_Y_PADDING; htmlInput.style.lineHeight = (lineHeight * scale) + 'px'; @@ -371,7 +373,8 @@ FieldMultilineInput.prototype.widgetCreate_ = function() { * before scrolling functionality is enabled. */ FieldMultilineInput.prototype.setMaxLines = function(maxLines) { - if (typeof maxLines === 'number' && maxLines > 0 && maxLines !== this.maxLines_) { + if (typeof maxLines === 'number' && maxLines > 0 && + maxLines !== this.maxLines_) { this.maxLines_ = maxLines; this.forceRerender(); } @@ -401,18 +404,16 @@ FieldMultilineInput.prototype.onHtmlInputKeyDown_ = function(e) { * CSS for multiline field. See css.js for use. */ Css.register([ - /* eslint-disable indent */ - '.blocklyHtmlTextAreaInput {', - 'font-family: monospace;', - 'resize: none;', - 'overflow: hidden;', - 'height: 100%;', - 'text-align: left;', - '}', - '.blocklyHtmlTextAreaInputOverflowedY {', - 'overflow-y: scroll;', - '}' - /* eslint-enable indent */ + `.blocklyHtmlTextAreaInput { + font-family: monospace; + resize: none; + overflow: hidden; + height: 100%; + text-align: left; +}`, + `.blocklyHtmlTextAreaInputOverflowedY { + overflow-y: scroll; +}` ]); From b1f868fbafd01b8284f1e6155e71442303424b9b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:02:15 -0700 Subject: [PATCH 268/833] Migrate core/flyout_horizontal.js to ES6 const/let --- core/flyout_horizontal.js | 103 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 66e9ff18e..3ec62518a 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -53,10 +53,10 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = @@ -85,13 +85,13 @@ Blockly.HorizontalFlyout.prototype.getY = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); - var y = 0; - var atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + let y = 0; + const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. @@ -133,18 +133,18 @@ Blockly.HorizontalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the width for workspace metrics. this.width_ = targetWorkspaceViewMetrics.width; - var edgeWidth = targetWorkspaceViewMetrics.width - 2 * this.CORNER_RADIUS; - var edgeHeight = this.height_ - this.CORNER_RADIUS; + const edgeWidth = targetWorkspaceViewMetrics.width - 2 * this.CORNER_RADIUS; + const edgeHeight = this.height_ - this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -159,9 +159,9 @@ Blockly.HorizontalFlyout.prototype.position = function() { */ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { - var atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // Start at top left. - var path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; + const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; if (atTop) { // Top. @@ -206,15 +206,15 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); - var delta = scrollDelta.x || scrollDelta.y; + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const delta = scrollDelta.x || scrollDelta.y; if (delta) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.left - scrollMetrics.left) + delta; + const pos = (viewMetrics.left - scrollMetrics.left) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. Blockly.WidgetDiv.hide(); @@ -235,37 +235,38 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { */ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + let cursorX = margin + this.tabWidth_; + const cursorY = margin; if (this.RTL) { contents = contents.reverse(); } - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); // Figure out where to place the block. - var tab = block.outputConnection ? this.tabWidth_ : 0; + const tab = block.outputConnection ? this.tabWidth_ : 0; + let moveX; if (this.RTL) { - var moveX = cursorX + blockHW.width; + moveX = cursorX + blockHW.width; } else { - var moveX = cursorX - tab; + moveX = cursorX - tab; } block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, moveX, cursorY, blockHW, i); + const rect = this.createRect_(block, moveX, cursorY, blockHW, i); cursorX += (blockHW.width + gaps[i]); this.addBlockListeners_(root, block, rect); @@ -287,12 +288,12 @@ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for up or down dragging. if ((dragDirection < 90 + range && dragDirection > 90 - range) || (dragDirection > -90 - range && dragDirection < -90 + range)) { @@ -314,15 +315,15 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var top = flyoutRect.top; + const BIG_NUM = 1000000000; + const top = flyoutRect.top; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP) { - var height = flyoutRect.height; + const height = flyoutRect.height; return new Blockly.utils.Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); } else { // Bottom. return new Blockly.utils.Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); @@ -336,13 +337,13 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { */ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutHeight = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { + let flyoutHeight = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { flyoutHeight = Math.max(flyoutHeight, block.getHeightWidth().height); } - var buttons = this.buttons_; - for (var i = 0, button; (button = buttons[i]); i++) { + const buttons = this.buttons_; + for (let i = 0, button; (button = buttons[i]); i++) { flyoutHeight = Math.max(flyoutHeight, button.height); } flyoutHeight += this.MARGIN * 1.5; @@ -350,7 +351,7 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { flyoutHeight += Blockly.Scrollbar.scrollbarThickness; if (this.height_ != flyoutHeight) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (block.flyoutRect_) { this.moveRectToBlock_(block.flyoutRect_, block); } From 8b0d1df173b43ae48d4d9d84e89d46ded89d2659 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:04:52 -0700 Subject: [PATCH 269/833] Migrate core/flyout_horizontal.js to goog.module --- core/flyout_horizontal.js | 35 +++++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 3ec62518a..96cad2c9f 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.HorizontalFlyout'); +goog.module('Blockly.HorizontalFlyout'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); @@ -35,11 +36,11 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Flyout} * @constructor */ -Blockly.HorizontalFlyout = function(workspaceOptions) { - Blockly.HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); +const HorizontalFlyout = function(workspaceOptions) { + HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); this.horizontalLayout = true; }; -Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); +Blockly.utils.object.inherits(HorizontalFlyout, Blockly.Flyout); /** * Sets the translation of the flyout to match the scrollbars. @@ -48,7 +49,7 @@ Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); * similar x property. * @protected */ -Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { +HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } @@ -72,7 +73,7 @@ Blockly.HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.HorizontalFlyout.prototype.getX = function() { +HorizontalFlyout.prototype.getX = function() { // X is always 0 since this is a horizontal flyout. return 0; }; @@ -81,7 +82,7 @@ Blockly.HorizontalFlyout.prototype.getX = function() { * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.HorizontalFlyout.prototype.getY = function() { +HorizontalFlyout.prototype.getY = function() { if (!this.isVisible()) { return 0; } @@ -129,7 +130,7 @@ Blockly.HorizontalFlyout.prototype.getY = function() { /** * Move the flyout to the edge of the workspace. */ -Blockly.HorizontalFlyout.prototype.position = function() { +HorizontalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } @@ -157,7 +158,7 @@ Blockly.HorizontalFlyout.prototype.position = function() { * rounded corners. * @private */ -Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( +HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; // Start at top left. @@ -196,7 +197,7 @@ Blockly.HorizontalFlyout.prototype.setBackgroundPath_ = function( /** * Scroll the flyout to the top. */ -Blockly.HorizontalFlyout.prototype.scrollToStart = function() { +HorizontalFlyout.prototype.scrollToStart = function() { this.workspace_.scrollbar.setX(this.RTL ? Infinity : 0); }; @@ -205,7 +206,7 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { +HorizontalFlyout.prototype.wheel_ = function(e) { const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); const delta = scrollDelta.x || scrollDelta.y; @@ -233,7 +234,7 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { +HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; const margin = this.MARGIN; let cursorX = margin + this.tabWidth_; @@ -286,7 +287,7 @@ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( +HorizontalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; @@ -308,7 +309,7 @@ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function( * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.HorizontalFlyout.prototype.getClientRect = function() { +HorizontalFlyout.prototype.getClientRect = function() { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -335,7 +336,7 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { * For RTL: Lay out the blocks right-aligned. * @protected */ -Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { +HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); let flyoutHeight = 0; const blocks = this.workspace_.getTopBlocks(false); @@ -375,4 +376,6 @@ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { }; Blockly.registry.register(Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - Blockly.registry.DEFAULT, Blockly.HorizontalFlyout); + Blockly.registry.DEFAULT, HorizontalFlyout); + +exports = HorizontalFlyout; diff --git a/tests/deps.js b/tests/deps.js index f62333982..87600526f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -63,7 +63,7 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From 7ee9b0a41cc286cab6ff75e163c02d92ccc0c010 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:11:53 -0700 Subject: [PATCH 270/833] Migrate core/flyout_horizontal.js to named requires --- core/flyout_horizontal.js | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 96cad2c9f..8f530516d 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -13,34 +13,35 @@ goog.module('Blockly.HorizontalFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Flyout = goog.require('Blockly.Flyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const registry = goog.require('Blockly.registry'); +const {Position} = goog.require('Blockly.utils.toolbox'); +const {getScrollDeltaPixels} = goog.require('Blockly.utils'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.registry'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. - * @extends {Blockly.Flyout} + * @extends {Flyout} * @constructor */ const HorizontalFlyout = function(workspaceOptions) { HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); this.horizontalLayout = true; }; -Blockly.utils.object.inherits(HorizontalFlyout, Blockly.Flyout); +inherits(HorizontalFlyout, Flyout); /** * Sets the translation of the flyout to match the scrollbars. @@ -92,7 +93,7 @@ HorizontalFlyout.prototype.getY = function() { const toolboxMetrics = metricsManager.getToolboxMetrics(); let y = 0; - const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Position.TOP; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. @@ -160,7 +161,7 @@ HorizontalFlyout.prototype.position = function() { */ HorizontalFlyout.prototype.setBackgroundPath_ = function( width, height) { - const atTop = this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP; + const atTop = this.toolboxPosition_ == Position.TOP; // Start at top left. const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; @@ -207,7 +208,7 @@ HorizontalFlyout.prototype.scrollToStart = function() { * @protected */ HorizontalFlyout.prototype.wheel_ = function(e) { - const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = getScrollDeltaPixels(e); const delta = scrollDelta.x || scrollDelta.y; if (delta) { @@ -218,8 +219,8 @@ HorizontalFlyout.prototype.wheel_ = function(e) { const pos = (viewMetrics.left - scrollMetrics.left) + delta; this.workspace_.scrollbar.setX(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. @@ -282,7 +283,7 @@ HorizontalFlyout.prototype.layout_ = function(contents, gaps) { * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package @@ -306,7 +307,7 @@ HorizontalFlyout.prototype.isDragTowardWorkspace = function( /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ HorizontalFlyout.prototype.getClientRect = function() { @@ -323,11 +324,11 @@ HorizontalFlyout.prototype.getClientRect = function() { const BIG_NUM = 1000000000; const top = flyoutRect.top; - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP) { + if (this.toolboxPosition_ == Position.TOP) { const height = flyoutRect.height; - return new Blockly.utils.Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); + return new Rect(-BIG_NUM, top + height, -BIG_NUM, BIG_NUM); } else { // Bottom. - return new Blockly.utils.Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); + return new Rect(top, BIG_NUM, -BIG_NUM, BIG_NUM); } }; @@ -349,7 +350,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } flyoutHeight += this.MARGIN * 1.5; flyoutHeight *= this.workspace_.scale; - flyoutHeight += Blockly.Scrollbar.scrollbarThickness; + flyoutHeight += Scrollbar.scrollbarThickness; if (this.height_ != flyoutHeight) { for (let i = 0, block; (block = blocks[i]); i++) { @@ -359,7 +360,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_ && - this.toolboxPosition_ == Blockly.utils.toolbox.Position.TOP && + this.toolboxPosition_ == Position.TOP && !this.targetWorkspace.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that (0,0) // is in the correct position relative to the new absolute edge (ie @@ -375,7 +376,7 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } }; -Blockly.registry.register(Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - Blockly.registry.DEFAULT, HorizontalFlyout); +registry.register(registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, + registry.DEFAULT, HorizontalFlyout); exports = HorizontalFlyout; From 08c18b479cc9f6d5cc9566d00dfb5a534e6ad35b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:13:11 -0700 Subject: [PATCH 271/833] clang-format core/flyout_horizontal.js --- core/flyout_horizontal.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 8f530516d..9bfc8aa91 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -63,10 +63,11 @@ HorizontalFlyout.prototype.setMetrics_ = function(xyRatio) { if (typeof xyRatio.x == 'number') { this.workspace_.scrollX = -(scrollMetrics.left + - (scrollMetrics.width - viewMetrics.width) * xyRatio.x); + (scrollMetrics.width - viewMetrics.width) * xyRatio.x); } - this.workspace_.translate(this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.translate( + this.workspace_.scrollX + absoluteMetrics.left, this.workspace_.scrollY + absoluteMetrics.top); }; @@ -159,8 +160,7 @@ HorizontalFlyout.prototype.position = function() { * rounded corners. * @private */ -HorizontalFlyout.prototype.setBackgroundPath_ = function( - width, height) { +HorizontalFlyout.prototype.setBackgroundPath_ = function(width, height) { const atTop = this.toolboxPosition_ == Position.TOP; // Start at top left. const path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; @@ -171,20 +171,24 @@ HorizontalFlyout.prototype.setBackgroundPath_ = function( // Right. path.push('v', height); // Bottom. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('h', -width); // Left. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, -this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('z'); } else { // Top. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, -this.CORNER_RADIUS); path.push('h', width); // Right. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, 1, this.CORNER_RADIUS, this.CORNER_RADIUS); path.push('v', height); // Bottom. @@ -366,7 +370,8 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { // is in the correct position relative to the new absolute edge (ie // toolbox edge). this.targetWorkspace.translate( - this.targetWorkspace.scrollX, this.targetWorkspace.scrollY + flyoutHeight); + this.targetWorkspace.scrollX, + this.targetWorkspace.scrollY + flyoutHeight); } // Record the height for workspace metrics and .position. @@ -376,7 +381,8 @@ HorizontalFlyout.prototype.reflowInternal_ = function() { } }; -registry.register(registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, - registry.DEFAULT, HorizontalFlyout); +registry.register( + registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, registry.DEFAULT, + HorizontalFlyout); exports = HorizontalFlyout; From adc78d192c6b5852f0cfc5363777a5ac2a882465 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:24:09 -0700 Subject: [PATCH 272/833] Migrate core/flyout_vertical.js to ES6 const/let --- core/flyout_vertical.js | 106 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index a09b3fb8e..786deff96 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -59,10 +59,10 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = @@ -81,11 +81,11 @@ Blockly.VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var absoluteMetrics = metricsManager.getAbsoluteMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var toolboxMetrics = metricsManager.getToolboxMetrics(); - var x = 0; + const metricsManager = this.targetWorkspace.getMetricsManager(); + const absoluteMetrics = metricsManager.getAbsoluteMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const toolboxMetrics = metricsManager.getToolboxMetrics(); + let x = 0; // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { @@ -137,18 +137,18 @@ Blockly.VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } - var metricsManager = this.targetWorkspace.getMetricsManager(); - var targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); + const metricsManager = this.targetWorkspace.getMetricsManager(); + const targetWorkspaceViewMetrics = metricsManager.getViewMetrics(); // Record the height for workspace metrics. this.height_ = targetWorkspaceViewMetrics.height; - var edgeWidth = this.width_ - this.CORNER_RADIUS; - var edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; + const edgeWidth = this.width_ - this.CORNER_RADIUS; + const edgeHeight = targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS; this.setBackgroundPath_(edgeWidth, edgeHeight); - var x = this.getX(); - var y = this.getY(); + const x = this.getX(); + const y = this.getY(); this.positionAt_(this.width_, this.height_, x, y); }; @@ -162,11 +162,11 @@ Blockly.VerticalFlyout.prototype.position = function() { * @private */ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - var atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; - var totalWidth = width + this.CORNER_RADIUS; + const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. - var path = ['M ' + (atRight ? totalWidth : 0) + ',0']; + const path = ['M ' + (atRight ? totalWidth : 0) + ',0']; // Top. path.push('h', atRight ? -width : width); // Rounded corner. @@ -200,13 +200,13 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @protected */ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { - var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { - var metricsManager = this.workspace_.getMetricsManager(); - var scrollMetrics = metricsManager.getScrollMetrics(); - var viewMetrics = metricsManager.getViewMetrics(); - var pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; + const metricsManager = this.workspace_.getMetricsManager(); + const scrollMetrics = metricsManager.getScrollMetrics(); + const viewMetrics = metricsManager.getViewMetrics(); + const pos = (viewMetrics.top - scrollMetrics.top) + scrollDelta.y; this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. @@ -228,27 +228,27 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { */ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; - var margin = this.MARGIN; - var cursorX = this.RTL ? margin : margin + this.tabWidth_; - var cursorY = margin; + const margin = this.MARGIN; + const cursorX = this.RTL ? margin : margin + this.tabWidth_; + let cursorY = margin; - for (var i = 0, item; (item = contents[i]); i++) { + for (let i = 0, item; (item = contents[i]); i++) { if (item.type == 'block') { - var block = item.block; - var allBlocks = block.getDescendants(false); - for (var j = 0, child; (child = allBlocks[j]); j++) { + const block = item.block; + const allBlocks = block.getDescendants(false); + for (let j = 0, child; (child = allBlocks[j]); j++) { // Mark blocks as being inside a flyout. This is used to detect and // prevent the closure of the flyout if the user right-clicks on such a // block. child.isInFlyout = true; } block.render(); - var root = block.getSvgRoot(); - var blockHW = block.getHeightWidth(); - var moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; + const root = block.getSvgRoot(); + const blockHW = block.getHeightWidth(); + const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - var rect = this.createRect_(block, + const rect = this.createRect_(block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,12 +272,12 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { */ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { - var dx = currentDragDeltaXY.x; - var dy = currentDragDeltaXY.y; + const dx = currentDragDeltaXY.x; + const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. - var dragDirection = Math.atan2(dy, dx) / Math.PI * 180; + const dragDirection = Math.atan2(dy, dx) / Math.PI * 180; - var range = this.dragAngleRange_; + const range = this.dragAngleRange_; // Check for left or right dragging. if ((dragDirection < range && dragDirection > -range) || (dragDirection < -180 + range || dragDirection > 180 - range)) { @@ -299,15 +299,15 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { return null; } - var flyoutRect = this.svgGroup_.getBoundingClientRect(); + const flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, // but be smaller than half Number.MAX_SAFE_INTEGER (not available on IE). - var BIG_NUM = 1000000000; - var left = flyoutRect.left; + const BIG_NUM = 1000000000; + const left = flyoutRect.left; if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { - var width = flyoutRect.width; + const width = flyoutRect.width; return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); @@ -321,16 +321,16 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { */ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); - var flyoutWidth = 0; - var blocks = this.workspace_.getTopBlocks(false); - for (var i = 0, block; (block = blocks[i]); i++) { - var width = block.getHeightWidth().width; + let flyoutWidth = 0; + const blocks = this.workspace_.getTopBlocks(false); + for (let i = 0, block; (block = blocks[i]); i++) { + let width = block.getHeightWidth().width; if (block.outputConnection) { width -= this.tabWidth_; } flyoutWidth = Math.max(flyoutWidth, width); } - for (var i = 0, button; (button = this.buttons_[i]); i++) { + for (let i = 0, button; (button = this.buttons_[i]); i++) { flyoutWidth = Math.max(flyoutWidth, button.width); } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; @@ -338,11 +338,11 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { flyoutWidth += Blockly.Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { - for (var i = 0, block; (block = blocks[i]); i++) { + for (let i = 0, block; (block = blocks[i]); i++) { if (this.RTL) { // With the flyoutWidth known, right-align the blocks. - var oldX = block.getRelativeToSurfaceXY().x; - var newX = flyoutWidth / this.workspace_.scale - this.MARGIN; + const oldX = block.getRelativeToSurfaceXY().x; + let newX = flyoutWidth / this.workspace_.scale - this.MARGIN; if (!block.outputConnection) { newX -= this.tabWidth_; } @@ -354,9 +354,9 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.RTL) { // With the flyoutWidth known, right-align the buttons. - for (var i = 0, button; (button = this.buttons_[i]); i++) { - var y = button.getPosition().y; - var x = flyoutWidth / this.workspace_.scale - button.width - + for (let i = 0, button; (button = this.buttons_[i]); i++) { + const y = button.getPosition().y; + const x = flyoutWidth / this.workspace_.scale - button.width - this.MARGIN - this.tabWidth_; button.moveTo(x, y); } From cd4f0e9f8c67edcfc9f068de9a3c49526b85bdaf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:27:27 -0700 Subject: [PATCH 273/833] Migrate core/flyout_vertical.js to goog.module --- core/flyout_vertical.js | 37 ++++++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 786deff96..d937cce6e 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VerticalFlyout'); +goog.module('Blockly.VerticalFlyout'); +goog.module.declareLegacyNamespace(); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); @@ -37,16 +38,16 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Flyout} * @constructor */ -Blockly.VerticalFlyout = function(workspaceOptions) { - Blockly.VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); +const VerticalFlyout = function(workspaceOptions) { + VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); }; -Blockly.utils.object.inherits(Blockly.VerticalFlyout, Blockly.Flyout); +Blockly.utils.object.inherits(VerticalFlyout, Blockly.Flyout); /** * The name of the vertical flyout in the registry. * @type {string} */ -Blockly.VerticalFlyout.registryName = 'verticalFlyout'; +VerticalFlyout.registryName = 'verticalFlyout'; /** * Sets the translation of the flyout to match the scrollbars. @@ -55,7 +56,7 @@ Blockly.VerticalFlyout.registryName = 'verticalFlyout'; * similar x property. * @protected */ -Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { +VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (!this.isVisible()) { return; } @@ -77,7 +78,7 @@ Blockly.VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { * Calculates the x coordinate for the flyout position. * @return {number} X coordinate. */ -Blockly.VerticalFlyout.prototype.getX = function() { +VerticalFlyout.prototype.getX = function() { if (!this.isVisible()) { return 0; } @@ -125,7 +126,7 @@ Blockly.VerticalFlyout.prototype.getX = function() { * Calculates the y coordinate for the flyout position. * @return {number} Y coordinate. */ -Blockly.VerticalFlyout.prototype.getY = function() { +VerticalFlyout.prototype.getY = function() { // Y is always 0 since this is a vertical flyout. return 0; }; @@ -133,7 +134,7 @@ Blockly.VerticalFlyout.prototype.getY = function() { /** * Move the flyout to the edge of the workspace. */ -Blockly.VerticalFlyout.prototype.position = function() { +VerticalFlyout.prototype.position = function() { if (!this.isVisible() || !this.targetWorkspace.isVisible()) { return; } @@ -161,7 +162,7 @@ Blockly.VerticalFlyout.prototype.position = function() { * rounded corners. * @private */ -Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { +VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; const totalWidth = width + this.CORNER_RADIUS; @@ -190,7 +191,7 @@ Blockly.VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { /** * Scroll the flyout to the top. */ -Blockly.VerticalFlyout.prototype.scrollToStart = function() { +VerticalFlyout.prototype.scrollToStart = function() { this.workspace_.scrollbar.setY(0); }; @@ -199,7 +200,7 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { * @param {!Event} e Mouse wheel scroll event. * @protected */ -Blockly.VerticalFlyout.prototype.wheel_ = function(e) { +VerticalFlyout.prototype.wheel_ = function(e) { const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); if (scrollDelta.y) { @@ -226,7 +227,7 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { * @param {!Array} gaps The visible gaps between blocks. * @protected */ -Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { +VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; const margin = this.MARGIN; const cursorX = this.RTL ? margin : margin + this.tabWidth_; @@ -270,7 +271,7 @@ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( +VerticalFlyout.prototype.isDragTowardWorkspace = function( currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; @@ -292,7 +293,7 @@ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function( * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.VerticalFlyout.prototype.getClientRect = function() { +VerticalFlyout.prototype.getClientRect = function() { if (!this.svgGroup_ || this.autoClose || !this.isVisible()) { // The bounding rectangle won't compute correctly if the flyout is closed // and auto-close flyouts aren't valid drag targets (or delete areas). @@ -319,7 +320,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { * For RTL: Lay out the blocks and buttons to be right-aligned. * @protected */ -Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { +VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.getFlyoutScale(); let flyoutWidth = 0; const blocks = this.workspace_.getTopBlocks(false); @@ -380,4 +381,6 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { }; Blockly.registry.register(Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - Blockly.registry.DEFAULT, Blockly.VerticalFlyout); + Blockly.registry.DEFAULT, VerticalFlyout); + +exports = VerticalFlyout; diff --git a/tests/deps.js b/tests/deps.js index f62333982..de0ab070c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -64,7 +64,7 @@ goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], [' goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); From 394d71a7d97cd24653491a944c17e0c746bac810 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:32:27 -0700 Subject: [PATCH 274/833] Migrate core/flyout_vertical.js to named requires --- core/flyout_vertical.js | 63 +++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index d937cce6e..8c1177c30 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -13,35 +13,36 @@ goog.module('Blockly.VerticalFlyout'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const DropDownDiv = goog.require('Blockly.DropDownDiv'); +const Flyout = goog.require('Blockly.Flyout'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +const Rect = goog.require('Blockly.utils.Rect'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const WidgetDiv = goog.require('Blockly.WidgetDiv'); +const registry = goog.require('Blockly.registry'); +const {Position} = goog.require('Blockly.utils.toolbox'); +const {getScrollDeltaPixels} = goog.require('Blockly.utils'); +const {inherits} = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Block'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.DropDownDiv'); -goog.require('Blockly.Flyout'); -goog.require('Blockly.registry'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.WidgetDiv'); - -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a flyout. - * @param {!Blockly.Options} workspaceOptions Dictionary of options for the + * @param {!Options} workspaceOptions Dictionary of options for the * workspace. - * @extends {Blockly.Flyout} + * @extends {Flyout} * @constructor */ const VerticalFlyout = function(workspaceOptions) { VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); }; -Blockly.utils.object.inherits(VerticalFlyout, Blockly.Flyout); +inherits(VerticalFlyout, Flyout); /** * The name of the vertical flyout in the registry. @@ -92,14 +93,14 @@ VerticalFlyout.prototype.getX = function() { if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. if (this.targetWorkspace.getToolbox()) { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = toolboxMetrics.width; } else { x = viewMetrics.width - this.width_; } // Simple (flyout-only) toolbox. } else { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = 0; } else { // The simple flyout does not cover the workspace. @@ -108,7 +109,7 @@ VerticalFlyout.prototype.getX = function() { } // Trashcan flyout is opposite the main flyout. } else { - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { x = 0; } else { // Because the anchor point of the flyout is on the left, but we want @@ -163,7 +164,7 @@ VerticalFlyout.prototype.position = function() { * @private */ VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { - const atRight = this.toolboxPosition_ == Blockly.utils.toolbox.Position.RIGHT; + const atRight = this.toolboxPosition_ == Position.RIGHT; const totalWidth = width + this.CORNER_RADIUS; // Decide whether to start on the left or right. @@ -201,7 +202,7 @@ VerticalFlyout.prototype.scrollToStart = function() { * @protected */ VerticalFlyout.prototype.wheel_ = function(e) { - const scrollDelta = Blockly.utils.getScrollDeltaPixels(e); + const scrollDelta = getScrollDeltaPixels(e); if (scrollDelta.y) { const metricsManager = this.workspace_.getMetricsManager(); @@ -211,8 +212,8 @@ VerticalFlyout.prototype.wheel_ = function(e) { this.workspace_.scrollbar.setY(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. - Blockly.WidgetDiv.hide(); - Blockly.DropDownDiv.hideWithoutAnimation(); + WidgetDiv.hide(); + DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. @@ -266,7 +267,7 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { * Determine if a drag delta is toward the workspace, based on the position * and orientation of the flyout. This is used in determineDragIntention_ to * determine if a new block should be created or if the flyout should scroll. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @return {boolean} True if the drag is toward the workspace. * @package @@ -290,7 +291,7 @@ VerticalFlyout.prototype.isDragTowardWorkspace = function( /** * Returns the bounding rectangle of the drag target area in pixel units * relative to viewport. - * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag + * @return {?Rect} The component's bounding box. Null if drag * target area should be ignored. */ VerticalFlyout.prototype.getClientRect = function() { @@ -307,11 +308,11 @@ VerticalFlyout.prototype.getClientRect = function() { const BIG_NUM = 1000000000; const left = flyoutRect.left; - if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { + if (this.toolboxPosition_ == Position.LEFT) { const width = flyoutRect.width; - return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); + return new Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width); } else { // Right - return new Blockly.utils.Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); + return new Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM); } }; @@ -336,7 +337,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_; flyoutWidth *= this.workspace_.scale; - flyoutWidth += Blockly.Scrollbar.scrollbarThickness; + flyoutWidth += Scrollbar.scrollbarThickness; if (this.width_ != flyoutWidth) { for (let i = 0, block; (block = blocks[i]); i++) { @@ -364,7 +365,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_ && - this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT && + this.toolboxPosition_ == Position.LEFT && !this.targetWorkspace.getToolbox()) { // This flyout is a simple toolbox. Reposition the workspace so that (0,0) // is in the correct position relative to the new absolute edge (ie @@ -380,7 +381,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } }; -Blockly.registry.register(Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - Blockly.registry.DEFAULT, VerticalFlyout); +registry.register(registry.Type.FLYOUTS_VERTICAL_TOOLBOX, + registry.DEFAULT, VerticalFlyout); exports = VerticalFlyout; From def3458a10729c15b43bd1bac35e78cd931d9951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:32:59 -0700 Subject: [PATCH 275/833] clang-format core/flyout_vertical.js --- core/flyout_vertical.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 8c1177c30..2091d1321 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -69,9 +69,10 @@ VerticalFlyout.prototype.setMetrics_ = function(xyRatio) { if (typeof xyRatio.y == 'number') { this.workspace_.scrollY = -(scrollMetrics.top + - (scrollMetrics.height - viewMetrics.height) * xyRatio.y); + (scrollMetrics.height - viewMetrics.height) * xyRatio.y); } - this.workspace_.translate(this.workspace_.scrollX + absoluteMetrics.left, + this.workspace_.translate( + this.workspace_.scrollX + absoluteMetrics.left, this.workspace_.scrollY + absoluteMetrics.top); }; @@ -172,17 +173,15 @@ VerticalFlyout.prototype.setBackgroundPath_ = function(width, height) { // Top. path.push('h', atRight ? -width : width); // Rounded corner. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, - atRight ? 0 : 1, - atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, - this.CORNER_RADIUS); + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS); // Side closest to workspace. path.push('v', Math.max(0, height)); // Rounded corner. - path.push('a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, - atRight ? 0 : 1, - atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, - this.CORNER_RADIUS); + path.push( + 'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1, + atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS); // Bottom. path.push('h', atRight ? width : -width); path.push('z'); @@ -250,8 +249,8 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { const moveX = block.outputConnection ? cursorX - this.tabWidth_ : cursorX; block.moveBy(moveX, cursorY); - const rect = this.createRect_(block, - this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); + const rect = this.createRect_( + block, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW, i); this.addBlockListeners_(root, block, rect); @@ -272,8 +271,7 @@ VerticalFlyout.prototype.layout_ = function(contents, gaps) { * @return {boolean} True if the drag is toward the workspace. * @package */ -VerticalFlyout.prototype.isDragTowardWorkspace = function( - currentDragDeltaXY) { +VerticalFlyout.prototype.isDragTowardWorkspace = function(currentDragDeltaXY) { const dx = currentDragDeltaXY.x; const dy = currentDragDeltaXY.y; // Direction goes from -180 to 180, with 0 toward the right and 90 on top. @@ -371,7 +369,8 @@ VerticalFlyout.prototype.reflowInternal_ = function() { // is in the correct position relative to the new absolute edge (ie // toolbox edge). this.targetWorkspace.translate( - this.targetWorkspace.scrollX + flyoutWidth, this.targetWorkspace.scrollY); + this.targetWorkspace.scrollX + flyoutWidth, + this.targetWorkspace.scrollY); } // Record the width for workspace metrics and .position. @@ -381,7 +380,7 @@ VerticalFlyout.prototype.reflowInternal_ = function() { } }; -registry.register(registry.Type.FLYOUTS_VERTICAL_TOOLBOX, - registry.DEFAULT, VerticalFlyout); +registry.register( + registry.Type.FLYOUTS_VERTICAL_TOOLBOX, registry.DEFAULT, VerticalFlyout); exports = VerticalFlyout; From 90ed883eb0d06fceecbb6a17aa5bd018105adad6 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:38:39 -0700 Subject: [PATCH 276/833] Migrate core/generator.js to ES6 const/let --- core/generator.js | 48 +++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/generator.js b/core/generator.js index e365c69ba..a9a2d5418 100644 --- a/core/generator.js +++ b/core/generator.js @@ -96,11 +96,11 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { console.warn('No workspace specified in workspaceToCode call. Guessing.'); workspace = Blockly.getMainWorkspace(); } - var code = []; + let code = []; this.init(workspace); - var blocks = workspace.getTopBlocks(true); - for (var i = 0, block; (block = blocks[i]); i++) { - var line = this.blockToCode(block); + const blocks = workspace.getTopBlocks(true); + for (let i = 0, block; (block = blocks[i]); i++) { + let line = this.blockToCode(block); if (Array.isArray(line)) { // Value blocks return tuples of code and operator order. // Top-level blocks don't care about operator order. @@ -150,10 +150,10 @@ Blockly.Generator.prototype.prefixLines = function(text, prefix) { * @return {string} Concatenated list of comments. */ Blockly.Generator.prototype.allNestedComments = function(block) { - var comments = []; - var blocks = block.getDescendants(true); - for (var i = 0; i < blocks.length; i++) { - var comment = blocks[i].getCommentText(); + const comments = []; + const blocks = block.getDescendants(true); + for (let i = 0; i < blocks.length; i++) { + const comment = blocks[i].getCommentText(); if (comment) { comments.push(comment); } @@ -191,7 +191,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { return opt_thisOnly ? '' : this.blockToCode(block.getChildren(false)[0]); } - var func = this[block.type]; + const func = this[block.type]; if (typeof func != 'function') { throw Error('Language "' + this.name_ + '" does not know how to generate ' + 'code for block type "' + block.type + '".'); @@ -200,7 +200,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { // Prior to 24 September 2013 'this' was the only way to access the block. // The current preferred method of accessing the block is through the second // argument to func.call, which becomes the first parameter to the generator. - var code = func.call(block, block); + let code = func.call(block, block); if (Array.isArray(code)) { // Value blocks return tuples of code and operator order. if (!block.outputConnection) { @@ -235,11 +235,11 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { throw TypeError('Expecting valid order from block: ' + block.type); } - var targetBlock = block.getInputTargetBlock(name); + const targetBlock = block.getInputTargetBlock(name); if (!targetBlock) { return ''; } - var tuple = this.blockToCode(targetBlock); + const tuple = this.blockToCode(targetBlock); if (tuple === '') { // Disabled block. return ''; @@ -249,8 +249,8 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { if (!Array.isArray(tuple)) { throw TypeError('Expecting tuple from value block: ' + targetBlock.type); } - var code = tuple[0]; - var innerOrder = tuple[1]; + let code = tuple[0]; + const innerOrder = tuple[1]; if (isNaN(innerOrder)) { throw TypeError('Expecting valid order from value block: ' + targetBlock.type); @@ -260,9 +260,9 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { } // Add parentheses if needed. - var parensNeeded = false; - var outerOrderClass = Math.floor(outerOrder); - var innerOrderClass = Math.floor(innerOrder); + let parensNeeded = false; + const outerOrderClass = Math.floor(outerOrder); + const innerOrderClass = Math.floor(innerOrder); if (outerOrderClass <= innerOrderClass) { if (outerOrderClass == innerOrderClass && (outerOrderClass == 0 || outerOrderClass == 99)) { @@ -276,7 +276,7 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { // wrap the code in parentheses. parensNeeded = true; // Check for special exceptions. - for (var i = 0; i < this.ORDER_OVERRIDES.length; i++) { + for (let i = 0; i < this.ORDER_OVERRIDES.length; i++) { if (this.ORDER_OVERRIDES[i][0] == outerOrder && this.ORDER_OVERRIDES[i][1] == innerOrder) { parensNeeded = false; @@ -303,8 +303,8 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { * @return {string} Generated code or '' if no blocks are connected. */ Blockly.Generator.prototype.statementToCode = function(block, name) { - var targetBlock = block.getInputTargetBlock(name); - var code = this.blockToCode(targetBlock); + const targetBlock = block.getInputTargetBlock(name); + let code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. // Statement blocks must only return code. if (typeof code != 'string') { @@ -350,7 +350,7 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) { * @return {string} Code snippet with ID. */ Blockly.Generator.prototype.injectId = function(msg, block) { - var id = block.id.replace(/\$/g, '$$$$'); // Issue 251. + const id = block.id.replace(/\$/g, '$$$$'); // Issue 251. return msg.replace(/%1/g, '\'' + id + '\''); }; @@ -450,16 +450,16 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { */ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { - var functionName = this.nameDB_.getDistinctName( + const functionName = this.nameDB_.getDistinctName( desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; - var codeText = code.join('\n').replace( + let codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); // Change all ' ' indents into the desired indent. // To avoid an infinite loop of replacements, change all indents to '\0' // character first, then replace them all with the indent. // We are assuming that no provided functions contain a literal null char. - var oldCodeText; + let oldCodeText; while (oldCodeText != codeText) { oldCodeText = codeText; codeText = codeText.replace(/^(( {2})*) {2}/gm, '$1\0'); diff --git a/tests/deps.js b/tests/deps.js index f62333982..87a32ab95 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 4741d4c312586221a1c776510b8354fde6f1102f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:41:57 -0700 Subject: [PATCH 277/833] Migrate core/generator.js to goog.module --- core/generator.js | 69 ++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/core/generator.js b/core/generator.js index a9a2d5418..609e9d56c 100644 --- a/core/generator.js +++ b/core/generator.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Generator'); +goog.module('Blockly.Generator'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Block'); goog.require('Blockly.internalConstants'); @@ -26,7 +27,7 @@ goog.requireType('Blockly.Workspace'); * @param {string} name Language name of this generator. * @constructor */ -Blockly.Generator = function(name) { +const Generator = function(name) { this.name_ = name; this.FUNCTION_NAME_PLACEHOLDER_REGEXP_ = new RegExp(this.FUNCTION_NAME_PLACEHOLDER_, 'g'); @@ -38,7 +39,7 @@ Blockly.Generator = function(name) { * E.g. ' checkTimeout(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null; +Generator.prototype.INFINITE_LOOP_TRAP = null; /** * Arbitrary code to inject before every statement. @@ -46,7 +47,7 @@ Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null; * E.g. 'highlight(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.STATEMENT_PREFIX = null; +Generator.prototype.STATEMENT_PREFIX = null; /** * Arbitrary code to inject after every statement. @@ -54,27 +55,27 @@ Blockly.Generator.prototype.STATEMENT_PREFIX = null; * E.g. 'highlight(%1);\n' * @type {?string} */ -Blockly.Generator.prototype.STATEMENT_SUFFIX = null; +Generator.prototype.STATEMENT_SUFFIX = null; /** * The method of indenting. Defaults to two spaces, but language generators * may override this to increase indent or change to tabs. * @type {string} */ -Blockly.Generator.prototype.INDENT = ' '; +Generator.prototype.INDENT = ' '; /** * Maximum length for a comment before wrapping. Does not account for * indenting level. * @type {number} */ -Blockly.Generator.prototype.COMMENT_WRAP = 60; +Generator.prototype.COMMENT_WRAP = 60; /** * List of outer-inner pairings that do NOT require parentheses. * @type {!Array>} */ -Blockly.Generator.prototype.ORDER_OVERRIDES = []; +Generator.prototype.ORDER_OVERRIDES = []; /** * Whether the init method has been called. @@ -83,14 +84,14 @@ Blockly.Generator.prototype.ORDER_OVERRIDES = []; * initialized. If this flag is untouched, it will have no effect. * @type {?boolean} */ -Blockly.Generator.prototype.isInitialized = null; +Generator.prototype.isInitialized = null; /** * Generate code for all blocks in the workspace to the specified language. * @param {!Blockly.Workspace=} workspace Workspace to generate code from. * @return {string} Generated code. */ -Blockly.Generator.prototype.workspaceToCode = function(workspace) { +Generator.prototype.workspaceToCode = function(workspace) { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn('No workspace specified in workspaceToCode call. Guessing.'); @@ -140,7 +141,7 @@ Blockly.Generator.prototype.workspaceToCode = function(workspace) { * @param {string} prefix The common prefix. * @return {string} The prefixed lines of code. */ -Blockly.Generator.prototype.prefixLines = function(text, prefix) { +Generator.prototype.prefixLines = function(text, prefix) { return prefix + text.replace(/(?!\n$)\n/g, '\n' + prefix); }; @@ -149,7 +150,7 @@ Blockly.Generator.prototype.prefixLines = function(text, prefix) { * @param {!Blockly.Block} block The block from which to start spidering. * @return {string} Concatenated list of comments. */ -Blockly.Generator.prototype.allNestedComments = function(block) { +Generator.prototype.allNestedComments = function(block) { const comments = []; const blocks = block.getDescendants(true); for (let i = 0; i < blocks.length; i++) { @@ -174,7 +175,7 @@ Blockly.Generator.prototype.allNestedComments = function(block) { * For value blocks, an array containing the generated code and an * operator order value. Returns '' if block is null. */ -Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { +Generator.prototype.blockToCode = function(block, opt_thisOnly) { if (this.isInitialized === false) { console.warn( 'Generator init was not called before blockToCode was called.'); @@ -231,7 +232,7 @@ Blockly.Generator.prototype.blockToCode = function(block, opt_thisOnly) { * @return {string} Generated code or '' if no blocks are connected or the * specified input does not exist. */ -Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { +Generator.prototype.valueToCode = function(block, name, outerOrder) { if (isNaN(outerOrder)) { throw TypeError('Expecting valid order from block: ' + block.type); } @@ -302,7 +303,7 @@ Blockly.Generator.prototype.valueToCode = function(block, name, outerOrder) { * @param {string} name The name of the input. * @return {string} Generated code or '' if no blocks are connected. */ -Blockly.Generator.prototype.statementToCode = function(block, name) { +Generator.prototype.statementToCode = function(block, name) { const targetBlock = block.getInputTargetBlock(name); let code = this.blockToCode(targetBlock); // Value blocks must return code and order of operations info. @@ -326,7 +327,7 @@ Blockly.Generator.prototype.statementToCode = function(block, name) { * @param {!Blockly.Block} block Enclosing block. * @return {string} Loop contents, with infinite loop trap added. */ -Blockly.Generator.prototype.addLoopTrap = function(branch, block) { +Generator.prototype.addLoopTrap = function(branch, block) { if (this.INFINITE_LOOP_TRAP) { branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + branch; @@ -349,7 +350,7 @@ Blockly.Generator.prototype.addLoopTrap = function(branch, block) { * @param {!Blockly.Block} block Block which has an ID. * @return {string} Code snippet with ID. */ -Blockly.Generator.prototype.injectId = function(msg, block) { +Generator.prototype.injectId = function(msg, block) { const id = block.id.replace(/\$/g, '$$$$'); // Issue 251. return msg.replace(/%1/g, '\'' + id + '\''); }; @@ -359,33 +360,33 @@ Blockly.Generator.prototype.injectId = function(msg, block) { * @type {string} * @protected */ -Blockly.Generator.prototype.RESERVED_WORDS_ = ''; +Generator.prototype.RESERVED_WORDS_ = ''; /** * Add one or more words to the list of reserved words for this language. * @param {string} words Comma-separated list of words to add to the list. * No spaces. Duplicates are ok. */ -Blockly.Generator.prototype.addReservedWords = function(words) { +Generator.prototype.addReservedWords = function(words) { this.RESERVED_WORDS_ += words + ','; }; /** * This is used as a placeholder in functions defined using - * Blockly.Generator.provideFunction_. It must not be legal code that could + * Generator.provideFunction_. It must not be legal code that could * legitimately appear in a function definition (or comment), and it must * not confuse the regular expression parser. * @type {string} * @protected */ -Blockly.Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; +Generator.prototype.FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; /** * A dictionary of definitions to be printed before the code. * @type {!Object|undefined} * @protected */ -Blockly.Generator.prototype.definitions_; +Generator.prototype.definitions_; /** * A dictionary mapping desired function names in definitions_ to actual @@ -393,20 +394,20 @@ Blockly.Generator.prototype.definitions_; * @type {!Object|undefined} * @protected */ -Blockly.Generator.prototype.functionNames_; +Generator.prototype.functionNames_; /** * A database of variable and procedure names. * @type {!Blockly.Names|undefined} * @protected */ -Blockly.Generator.prototype.nameDB_; +Generator.prototype.nameDB_; -Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { +Object.defineProperty(Generator.prototype, 'variableDB_', { /** * Getter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). - * @this {Blockly.Generator} + * @this {Generator} * @return {!Blockly.Names|undefined} Name database. */ get: function() { @@ -417,7 +418,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { /** * Setter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). - * @this {Blockly.Generator} + * @this {Generator} * @param {!Blockly.Names|undefined} nameDb New name database. */ set: function(nameDb) { @@ -439,7 +440,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { * "listRandom", not "random"). There is no danger of colliding with reserved * words, or user-defined variable or procedure names. * - * The code gets output when Blockly.Generator.finish() is called. + * The code gets output when Generator.finish() is called. * * @param {string} desiredName The desired name of the function * (e.g. mathIsPrime). @@ -448,7 +449,7 @@ Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', { * from desiredName if the former has already been taken by the user. * @protected */ -Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { +Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { const functionName = this.nameDB_.getDistinctName( desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); @@ -476,7 +477,7 @@ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { * names. * @param {!Blockly.Workspace} _workspace Workspace to generate code from. */ -Blockly.Generator.prototype.init = function(_workspace) { +Generator.prototype.init = function(_workspace) { // Optionally override // Create a dictionary of definitions to be printed before the code. this.definitions_ = Object.create(null); @@ -499,7 +500,7 @@ Blockly.Generator.prototype.init = function(_workspace) { * @return {string} Code with comments and subsequent blocks added. * @protected */ -Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { +Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { // Optionally override return code; }; @@ -511,7 +512,7 @@ Blockly.Generator.prototype.scrub_ = function(_block, code, _opt_thisOnly) { * @param {string} code Generated code. * @return {string} Completed code. */ -Blockly.Generator.prototype.finish = function(code) { +Generator.prototype.finish = function(code) { // Optionally override // Clean up temporary data. delete this.definitions_; @@ -527,7 +528,9 @@ Blockly.Generator.prototype.finish = function(code) { * @param {string} line Line of generated code. * @return {string} Legal line of code. */ -Blockly.Generator.prototype.scrubNakedValue = function(line) { +Generator.prototype.scrubNakedValue = function(line) { // Optionally override return line; }; + +exports = Generator; diff --git a/tests/deps.js b/tests/deps.js index 87a32ab95..db93b7671 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 1a1bad0bd718255cf53ce9de1787e123356da225 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:45:25 -0700 Subject: [PATCH 278/833] Migrate core/generator.js to named requires --- core/generator.js | 47 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/generator.js b/core/generator.js index 609e9d56c..7882a0402 100644 --- a/core/generator.js +++ b/core/generator.js @@ -14,12 +14,15 @@ goog.module('Blockly.Generator'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Block'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils.deprecation'); - -goog.requireType('Blockly.Names'); -goog.requireType('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.require('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Names = goog.requireType('Blockly.Names'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const internalConstants = goog.require('Blockly.internalConstants'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const {getMainWorkspace} = goog.require('Blockly'); /** @@ -88,14 +91,14 @@ Generator.prototype.isInitialized = null; /** * Generate code for all blocks in the workspace to the specified language. - * @param {!Blockly.Workspace=} workspace Workspace to generate code from. + * @param {!Workspace=} workspace Workspace to generate code from. * @return {string} Generated code. */ Generator.prototype.workspaceToCode = function(workspace) { if (!workspace) { // Backwards compatibility from before there could be multiple workspaces. console.warn('No workspace specified in workspaceToCode call. Guessing.'); - workspace = Blockly.getMainWorkspace(); + workspace = getMainWorkspace(); } let code = []; this.init(workspace); @@ -147,7 +150,7 @@ Generator.prototype.prefixLines = function(text, prefix) { /** * Recursively spider a tree of blocks, returning all their comments. - * @param {!Blockly.Block} block The block from which to start spidering. + * @param {!Block} block The block from which to start spidering. * @return {string} Concatenated list of comments. */ Generator.prototype.allNestedComments = function(block) { @@ -169,7 +172,7 @@ Generator.prototype.allNestedComments = function(block) { /** * Generate code for the specified block (and attached blocks). * The generator must be initialized before calling this function. - * @param {Blockly.Block} block The block to generate code for. + * @param {Block} block The block to generate code for. * @param {boolean=} opt_thisOnly True to generate code for only this statement. * @return {string|!Array} For statement blocks, the generated code. * For value blocks, an array containing the generated code and an @@ -225,7 +228,7 @@ Generator.prototype.blockToCode = function(block, opt_thisOnly) { /** * Generate code representing the specified value input. - * @param {!Blockly.Block} block The block containing the input. + * @param {!Block} block The block containing the input. * @param {string} name The name of the input. * @param {number} outerOrder The maximum binding strength (minimum order value) * of any operators adjacent to "block". @@ -299,7 +302,7 @@ Generator.prototype.valueToCode = function(block, name, outerOrder) { * statement input. Indent the code. * This is mainly used in generators. When trying to generate code to evaluate * look at using workspaceToCode or blockToCode. - * @param {!Blockly.Block} block The block containing the input. + * @param {!Block} block The block containing the input. * @param {string} name The name of the input. * @return {string} Generated code or '' if no blocks are connected. */ @@ -324,7 +327,7 @@ Generator.prototype.statementToCode = function(block, name) { * statement executes), and a statement prefix to the end of the loop block * (right before the loop statement executes). * @param {string} branch Code for loop contents. - * @param {!Blockly.Block} block Enclosing block. + * @param {!Block} block Enclosing block. * @return {string} Loop contents, with infinite loop trap added. */ Generator.prototype.addLoopTrap = function(branch, block) { @@ -347,7 +350,7 @@ Generator.prototype.addLoopTrap = function(branch, block) { * Inject a block ID into a message to replace '%1'. * Used for STATEMENT_PREFIX, STATEMENT_SUFFIX, and INFINITE_LOOP_TRAP. * @param {string} msg Code snippet with '%1'. - * @param {!Blockly.Block} block Block which has an ID. + * @param {!Block} block Block which has an ID. * @return {string} Code snippet with ID. */ Generator.prototype.injectId = function(msg, block) { @@ -398,7 +401,7 @@ Generator.prototype.functionNames_; /** * A database of variable and procedure names. - * @type {!Blockly.Names|undefined} + * @type {!Names|undefined} * @protected */ Generator.prototype.nameDB_; @@ -408,10 +411,10 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * Getter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @this {Generator} - * @return {!Blockly.Names|undefined} Name database. + * @return {!Names|undefined} Name database. */ get: function() { - Blockly.utils.deprecation.warn( + deprecation.warn( 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); return this.nameDB_; }, @@ -419,10 +422,10 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * Setter. * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @this {Generator} - * @param {!Blockly.Names|undefined} nameDb New name database. + * @param {!Names|undefined} nameDb New name database. */ set: function(nameDb) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; } @@ -452,7 +455,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { Generator.prototype.provideFunction_ = function(desiredName, code) { if (!this.definitions_[desiredName]) { const functionName = this.nameDB_.getDistinctName( - desiredName, Blockly.internalConstants.PROCEDURE_CATEGORY_NAME); + desiredName, internalConstants.PROCEDURE_CATEGORY_NAME); this.functionNames_[desiredName] = functionName; let codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); @@ -475,7 +478,7 @@ Generator.prototype.provideFunction_ = function(desiredName, code) { * Hook for code to run before code generation starts. * Subclasses may override this, e.g. to initialise the database of variable * names. - * @param {!Blockly.Workspace} _workspace Workspace to generate code from. + * @param {!Workspace} _workspace Workspace to generate code from. */ Generator.prototype.init = function(_workspace) { // Optionally override @@ -493,7 +496,7 @@ Generator.prototype.init = function(_workspace) { * Subclasses may override this, e.g. to generate code for statements following * the block, or to handle comments for the specified block and any connected * value blocks. - * @param {!Blockly.Block} _block The current block. + * @param {!Block} _block The current block. * @param {string} code The code created for this block. * @param {boolean=} _opt_thisOnly True to generate code for only this * statement. diff --git a/tests/deps.js b/tests/deps.js index db93b7671..c40db7cbc 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From da77f3e5b42985828486f19fefcaeacca0c0eedd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:46:01 -0700 Subject: [PATCH 279/833] clang-format core/generator.js --- core/generator.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/core/generator.js b/core/generator.js index 7882a0402..8e71fb040 100644 --- a/core/generator.js +++ b/core/generator.js @@ -197,7 +197,8 @@ Generator.prototype.blockToCode = function(block, opt_thisOnly) { const func = this[block.type]; if (typeof func != 'function') { - throw Error('Language "' + this.name_ + '" does not know how to generate ' + + throw Error( + 'Language "' + this.name_ + '" does not know how to generate ' + 'code for block type "' + block.type + '".'); } // First argument to func.call is the value of 'this' in the generator. @@ -256,8 +257,8 @@ Generator.prototype.valueToCode = function(block, name, outerOrder) { let code = tuple[0]; const innerOrder = tuple[1]; if (isNaN(innerOrder)) { - throw TypeError('Expecting valid order from value block: ' + - targetBlock.type); + throw TypeError( + 'Expecting valid order from value block: ' + targetBlock.type); } if (!code) { return ''; @@ -312,7 +313,8 @@ Generator.prototype.statementToCode = function(block, name) { // Value blocks must return code and order of operations info. // Statement blocks must only return code. if (typeof code != 'string') { - throw TypeError('Expecting code from statement block: ' + + throw TypeError( + 'Expecting code from statement block: ' + (targetBlock && targetBlock.type)); } if (code) { @@ -332,16 +334,19 @@ Generator.prototype.statementToCode = function(block, name) { */ Generator.prototype.addLoopTrap = function(branch, block) { if (this.INFINITE_LOOP_TRAP) { - branch = this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP, block), - this.INDENT) + branch; + branch = this.prefixLines( + this.injectId(this.INFINITE_LOOP_TRAP, block), this.INDENT) + + branch; } if (this.STATEMENT_SUFFIX && !block.suppressPrefixSuffix) { - branch = this.prefixLines(this.injectId(this.STATEMENT_SUFFIX, block), - this.INDENT) + branch; + branch = this.prefixLines( + this.injectId(this.STATEMENT_SUFFIX, block), this.INDENT) + + branch; } if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) { - branch = branch + this.prefixLines(this.injectId(this.STATEMENT_PREFIX, - block), this.INDENT); + branch = branch + + this.prefixLines( + this.injectId(this.STATEMENT_PREFIX, block), this.INDENT); } return branch; }; @@ -414,8 +419,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * @return {!Names|undefined} Name database. */ get: function() { - deprecation.warn( - 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); return this.nameDB_; }, /** @@ -425,8 +429,7 @@ Object.defineProperty(Generator.prototype, 'variableDB_', { * @param {!Names|undefined} nameDb New name database. */ set: function(nameDb) { - deprecation.warn( - 'variableDB_', 'May 2021', 'May 2026', 'nameDB_'); + deprecation.warn('variableDB_', 'May 2021', 'May 2026', 'nameDB_'); this.nameDB_ = nameDb; } }); From 1941e857e3564b6aa9ad323b607d66559ef1fe5b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:51:58 -0700 Subject: [PATCH 280/833] Migrate core/grid.js to ES6 const/let --- core/grid.js | 10 +++++----- tests/deps.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/grid.js b/core/grid.js index 56171ef50..b01d59dbd 100644 --- a/core/grid.js +++ b/core/grid.js @@ -125,14 +125,14 @@ Blockly.Grid.prototype.getPatternId = function() { Blockly.Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. - var safeSpacing = (this.spacing_ * scale) || 100; + const safeSpacing = (this.spacing_ * scale) || 100; this.gridPattern_.setAttribute('width', safeSpacing); this.gridPattern_.setAttribute('height', safeSpacing); - var half = Math.floor(this.spacing_ / 2) + 0.5; - var start = half - this.length_ / 2; - var end = half + this.length_ / 2; + let half = Math.floor(this.spacing_ / 2) + 0.5; + let start = half - this.length_ / 2; + let end = half + this.length_ / 2; half *= scale; start *= scale; @@ -197,7 +197,7 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { */ - var gridPattern = Blockly.utils.dom.createSvgElement( + const gridPattern = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, diff --git a/tests/deps.js b/tests/deps.js index f62333982..25dd37c2e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 4c7ac8dd382cd2cc8d2dd46c4e9eabf7af86def4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:54:43 -0700 Subject: [PATCH 281/833] Migrate core/grid.js to goog.module --- core/grid.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index b01d59dbd..48189fe69 100644 --- a/core/grid.js +++ b/core/grid.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Grid'); +goog.module('Blockly.Grid'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Svg'); @@ -27,7 +28,7 @@ goog.require('Blockly.utils.userAgent'); * https://developers.google.com/blockly/guides/configure/web/grid * @constructor */ -Blockly.Grid = function(pattern, options) { +const Grid = function(pattern, options) { /** * The grid's SVG pattern, created during injection. * @type {!SVGElement} @@ -78,14 +79,14 @@ Blockly.Grid = function(pattern, options) { * @type {number} * @private */ -Blockly.Grid.prototype.scale_ = 1; +Grid.prototype.scale_ = 1; /** * Dispose of this grid and unlink from the DOM. * @package * @suppress {checkTypes} */ -Blockly.Grid.prototype.dispose = function() { +Grid.prototype.dispose = function() { this.gridPattern_ = null; }; @@ -94,7 +95,7 @@ Blockly.Grid.prototype.dispose = function() { * @return {boolean} True if blocks should snap, false otherwise. * @package */ -Blockly.Grid.prototype.shouldSnap = function() { +Grid.prototype.shouldSnap = function() { return this.snapToGrid_; }; @@ -103,7 +104,7 @@ Blockly.Grid.prototype.shouldSnap = function() { * @return {number} The spacing of the grid points. * @package */ -Blockly.Grid.prototype.getSpacing = function() { +Grid.prototype.getSpacing = function() { return this.spacing_; }; @@ -113,7 +114,7 @@ Blockly.Grid.prototype.getSpacing = function() { * @return {string} The pattern ID. * @package */ -Blockly.Grid.prototype.getPatternId = function() { +Grid.prototype.getPatternId = function() { return this.gridPattern_.id; }; @@ -122,7 +123,7 @@ Blockly.Grid.prototype.getPatternId = function() { * @param {number} scale The new workspace scale. * @package */ -Blockly.Grid.prototype.update = function(scale) { +Grid.prototype.update = function(scale) { this.scale_ = scale; // MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100. const safeSpacing = (this.spacing_ * scale) || 100; @@ -153,7 +154,7 @@ Blockly.Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Blockly.Grid.prototype.setLineAttributes_ = function(line, width, +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); @@ -171,7 +172,7 @@ Blockly.Grid.prototype.setLineAttributes_ = function(line, width, * @param {number} y The new y position of the grid (in px). * @package */ -Blockly.Grid.prototype.moveTo = function(x, y) { +Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); @@ -190,7 +191,7 @@ Blockly.Grid.prototype.moveTo = function(x, y) { * @return {!SVGElement} The SVG element for the grid pattern. * @package */ -Blockly.Grid.createDom = function(rnd, gridOptions, defs) { +Grid.createDom = function(rnd, gridOptions, defs) { /* @@ -220,3 +221,5 @@ Blockly.Grid.createDom = function(rnd, gridOptions, defs) { } return gridPattern; }; + +exports = Grid; diff --git a/tests/deps.js b/tests/deps.js index 25dd37c2e..f6a0972e2 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -67,7 +67,7 @@ goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); -goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6'}); +goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); From 25cb8773cd0627fe8c6066a5bf6c2198f2de5cac Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 08:59:42 -0700 Subject: [PATCH 282/833] Migrate core/grid.js to named requires --- core/grid.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/grid.js b/core/grid.js index 48189fe69..b93a39fa1 100644 --- a/core/grid.js +++ b/core/grid.js @@ -14,9 +14,9 @@ goog.module('Blockly.Grid'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** @@ -176,7 +176,7 @@ Grid.prototype.moveTo = function(x, y) { this.gridPattern_.setAttribute('x', x); this.gridPattern_.setAttribute('y', y); - if (Blockly.utils.userAgent.IE || Blockly.utils.userAgent.EDGE) { + if (userAgent.IE || userAgent.EDGE) { // IE/Edge doesn't notice that the x/y offsets have changed. // Force an update. this.update(this.scale_); @@ -198,26 +198,26 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ - const gridPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + const gridPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse' }, defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, + dom.createSvgElement( + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, {}, gridPattern); + dom.createSvgElement( + Svg.LINE, {}, gridPattern); } return gridPattern; }; From d36abd2b338117eb4ca248346926bdc5f36e7c2f Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:00:09 -0700 Subject: [PATCH 283/833] clang-format core/grid.js --- core/grid.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/core/grid.js b/core/grid.js index b93a39fa1..1a1d5f2a3 100644 --- a/core/grid.js +++ b/core/grid.js @@ -62,8 +62,8 @@ const Grid = function(pattern, options) { * @type {SVGElement} * @private */ - this.line2_ = this.line1_ && - (/** @type {SVGElement} */ (this.line1_.nextSibling)); + this.line2_ = + this.line1_ && (/** @type {SVGElement} */ (this.line1_.nextSibling)); /** * Whether blocks should snap to the grid. @@ -154,8 +154,7 @@ Grid.prototype.update = function(scale) { * @param {number} y2 The new y end position of the line (in px). * @private */ -Grid.prototype.setLineAttributes_ = function(line, width, - x1, x2, y1, y2) { +Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) { if (line) { line.setAttribute('stroke-width', width); line.setAttribute('x1', x1); @@ -200,24 +199,19 @@ Grid.createDom = function(rnd, gridOptions, defs) { */ const gridPattern = dom.createSvgElement( Svg.PATTERN, - { - 'id': 'blocklyGridPattern' + rnd, - 'patternUnits': 'userSpaceOnUse' - }, defs); + {'id': 'blocklyGridPattern' + rnd, 'patternUnits': 'userSpaceOnUse'}, + defs); if (gridOptions['length'] > 0 && gridOptions['spacing'] > 0) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); if (gridOptions['length'] > 1) { dom.createSvgElement( - Svg.LINE, - {'stroke': gridOptions['colour']}, gridPattern); + Svg.LINE, {'stroke': gridOptions['colour']}, gridPattern); } // x1, y1, x1, x2 properties will be set later in update. } else { // Edge 16 doesn't handle empty patterns - dom.createSvgElement( - Svg.LINE, {}, gridPattern); + dom.createSvgElement(Svg.LINE, {}, gridPattern); } return gridPattern; }; From 341b5156934f8239924049c51c918c80ec973258 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:15:58 -0700 Subject: [PATCH 284/833] Migrate core/icon.js to ES6 const/let --- core/icon.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/icon.js b/core/icon.js index c5f3477cd..ca1548aa3 100644 --- a/core/icon.js +++ b/core/icon.js @@ -164,10 +164,10 @@ Blockly.Icon.prototype.setIconLocation = function(xy) { */ Blockly.Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. - var blockXY = this.block_.getRelativeToSurfaceXY(); - var iconXY = Blockly.utils.getRelativeXY( + const blockXY = this.block_.getRelativeToSurfaceXY(); + const iconXY = Blockly.utils.getRelativeXY( /** @type {!SVGElement} */ (this.iconGroup_)); - var newXY = new Blockly.utils.Coordinate( + const newXY = new Blockly.utils.Coordinate( blockXY.x + iconXY.x + this.SIZE / 2, blockXY.y + iconXY.y + this.SIZE / 2); if (!Blockly.utils.Coordinate.equals(this.getIconLocation(), newXY)) { From 8f72d004741ef12eca40fd96ebd4ff85395efa41 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:17:59 -0700 Subject: [PATCH 285/833] Migrate core/icon.js to goog.module --- core/icon.js | 41 ++++++++++++++++++++++------------------- tests/deps.js | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/core/icon.js b/core/icon.js index ca1548aa3..02e6f7348 100644 --- a/core/icon.js +++ b/core/icon.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Icon'); +goog.module('Blockly.Icon'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.utils'); @@ -29,7 +30,7 @@ goog.requireType('Blockly.Bubble'); * @constructor * @abstract */ -Blockly.Icon = function(block) { +const Icon = function(block) { /** * The block this icon is attached to. * @type {Blockly.BlockSvg} @@ -47,31 +48,31 @@ Blockly.Icon = function(block) { /** * Does this icon get hidden when the block is collapsed. */ -Blockly.Icon.prototype.collapseHidden = true; +Icon.prototype.collapseHidden = true; /** * Height and width of icons. */ -Blockly.Icon.prototype.SIZE = 17; +Icon.prototype.SIZE = 17; /** * Bubble UI (if visible). * @type {?Blockly.Bubble} * @protected */ -Blockly.Icon.prototype.bubble_ = null; +Icon.prototype.bubble_ = null; /** * Absolute coordinate of icon's center. * @type {?Blockly.utils.Coordinate} * @protected */ -Blockly.Icon.prototype.iconXY_ = null; +Icon.prototype.iconXY_ = null; /** * Create the icon on the block. */ -Blockly.Icon.prototype.createIcon = function() { +Icon.prototype.createIcon = function() { if (this.iconGroup_) { // Icon already exists. return; @@ -99,7 +100,7 @@ Blockly.Icon.prototype.createIcon = function() { /** * Dispose of this icon. */ -Blockly.Icon.prototype.dispose = function() { +Icon.prototype.dispose = function() { // Dispose of and unlink the icon. Blockly.utils.dom.removeNode(this.iconGroup_); this.iconGroup_ = null; @@ -111,7 +112,7 @@ Blockly.Icon.prototype.dispose = function() { /** * Add or remove the UI indicating if this icon may be clicked or not. */ -Blockly.Icon.prototype.updateEditable = function() { +Icon.prototype.updateEditable = function() { // No-op on the base class. }; @@ -119,7 +120,7 @@ Blockly.Icon.prototype.updateEditable = function() { * Is the associated bubble visible? * @return {boolean} True if the bubble is visible. */ -Blockly.Icon.prototype.isVisible = function() { +Icon.prototype.isVisible = function() { return !!this.bubble_; }; @@ -128,7 +129,7 @@ Blockly.Icon.prototype.isVisible = function() { * @param {!Event} e Mouse click event. * @protected */ -Blockly.Icon.prototype.iconClick_ = function(e) { +Icon.prototype.iconClick_ = function(e) { if (this.block_.workspace.isDragging()) { // Drag operation is concluding. Don't open the editor. return; @@ -141,7 +142,7 @@ Blockly.Icon.prototype.iconClick_ = function(e) { /** * Change the colour of the associated bubble to match its block. */ -Blockly.Icon.prototype.applyColour = function() { +Icon.prototype.applyColour = function() { if (this.isVisible()) { this.bubble_.setColour(this.block_.style.colourPrimary); } @@ -151,7 +152,7 @@ Blockly.Icon.prototype.applyColour = function() { * Notification that the icon has moved. Update the arrow accordingly. * @param {!Blockly.utils.Coordinate} xy Absolute location in workspace coordinates. */ -Blockly.Icon.prototype.setIconLocation = function(xy) { +Icon.prototype.setIconLocation = function(xy) { this.iconXY_ = xy; if (this.isVisible()) { this.bubble_.setAnchorLocation(xy); @@ -162,7 +163,7 @@ Blockly.Icon.prototype.setIconLocation = function(xy) { * Notification that the icon has moved, but we don't really know where. * Recompute the icon's location from scratch. */ -Blockly.Icon.prototype.computeIconLocation = function() { +Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. const blockXY = this.block_.getRelativeToSurfaceXY(); const iconXY = Blockly.utils.getRelativeXY( @@ -180,7 +181,7 @@ Blockly.Icon.prototype.computeIconLocation = function() { * @return {?Blockly.utils.Coordinate} Object with x and y properties in * workspace coordinates. */ -Blockly.Icon.prototype.getIconLocation = function() { +Icon.prototype.getIconLocation = function() { return this.iconXY_; }; @@ -191,9 +192,9 @@ Blockly.Icon.prototype.getIconLocation = function() { * @return {!Blockly.utils.Size} Height and width. */ // TODO (#2562): Remove getCorrectedSize. -Blockly.Icon.prototype.getCorrectedSize = function() { +Icon.prototype.getCorrectedSize = function() { return new Blockly.utils.Size( - Blockly.Icon.prototype.SIZE, Blockly.Icon.prototype.SIZE - 2); + Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; /** @@ -201,10 +202,12 @@ Blockly.Icon.prototype.getCorrectedSize = function() { * @param {!Element} group The icon group. * @protected */ -Blockly.Icon.prototype.drawIcon_; +Icon.prototype.drawIcon_; /** * Show or hide the icon. * @param {boolean} visible True if the icon should be visible. */ -Blockly.Icon.prototype.setVisible; +Icon.prototype.setVisible; + +exports = Icon; diff --git a/tests/deps.js b/tests/deps.js index f62333982..57ab7a557 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -68,7 +68,7 @@ goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); From f0a3c7214dc086de2ad29dabc41fc35e8c975102 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 13:40:19 -0700 Subject: [PATCH 286/833] Migrate core/interfaces/i_metrics_manager.js to goog.module --- core/interfaces/i_metrics_manager.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index 916f14d5d..f9b74e4c2 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.IMetricsManager'); +goog.module('Blockly.IMetricsManager'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.MetricsManager'); goog.requireType('Blockly.utils.Metrics'); @@ -22,14 +23,14 @@ goog.requireType('Blockly.utils.Size'); * Interface for a metrics manager. * @interface */ -Blockly.IMetricsManager = function() {}; +const IMetricsManager = function() {}; /** * Returns whether the scroll area has fixed edges. * @return {boolean} Whether the scroll area has fixed edges. * @package */ -Blockly.IMetricsManager.prototype.hasFixedEdges; +IMetricsManager.prototype.hasFixedEdges; /** * Returns the metrics for the scroll area of the workspace. @@ -44,7 +45,7 @@ Blockly.IMetricsManager.prototype.hasFixedEdges; * @return {!Blockly.MetricsManager.ContainerRegion} The metrics for the scroll * container */ -Blockly.IMetricsManager.prototype.getScrollMetrics; +IMetricsManager.prototype.getScrollMetrics; /** * Gets the width and the height of the flyout on the workspace in pixel @@ -55,7 +56,7 @@ Blockly.IMetricsManager.prototype.getScrollMetrics; * flyout. * @public */ -Blockly.IMetricsManager.prototype.getFlyoutMetrics; +IMetricsManager.prototype.getFlyoutMetrics; /** * Gets the width, height and position of the toolbox on the workspace in pixel @@ -66,7 +67,7 @@ Blockly.IMetricsManager.prototype.getFlyoutMetrics; * height and position of the toolbox. * @public */ -Blockly.IMetricsManager.prototype.getToolboxMetrics; +IMetricsManager.prototype.getToolboxMetrics; /** * Gets the width and height of the workspace's parent SVG element in pixel @@ -75,7 +76,7 @@ Blockly.IMetricsManager.prototype.getToolboxMetrics; * SVG element. * @public */ -Blockly.IMetricsManager.prototype.getSvgMetrics; +IMetricsManager.prototype.getSvgMetrics; /** * Gets the absolute left and absolute top in pixel coordinates. @@ -84,7 +85,7 @@ Blockly.IMetricsManager.prototype.getSvgMetrics; * the workspace. * @public */ -Blockly.IMetricsManager.prototype.getAbsoluteMetrics; +IMetricsManager.prototype.getAbsoluteMetrics; /** * Gets the metrics for the visible workspace in either pixel or workspace @@ -96,7 +97,7 @@ Blockly.IMetricsManager.prototype.getAbsoluteMetrics; * coordinates. * @public */ -Blockly.IMetricsManager.prototype.getViewMetrics; +IMetricsManager.prototype.getViewMetrics; /** * Gets content metrics in either pixel or workspace coordinates. @@ -108,7 +109,7 @@ Blockly.IMetricsManager.prototype.getViewMetrics; * metrics for the content container. * @public */ -Blockly.IMetricsManager.prototype.getContentMetrics; +IMetricsManager.prototype.getContentMetrics; /** * Returns an object with all the metrics required to size scrollbars for a @@ -142,4 +143,6 @@ Blockly.IMetricsManager.prototype.getContentMetrics; * level workspace. * @public */ -Blockly.IMetricsManager.prototype.getMetrics; +IMetricsManager.prototype.getMetrics; + +exports = IMetricsManager; diff --git a/tests/deps.js b/tests/deps.js index f62333982..5cadf3977 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -91,7 +91,7 @@ goog.addDependency('../../core/interfaces/i_drag_target.js', ['Blockly.IDragTarg goog.addDependency('../../core/interfaces/i_draggable.js', ['Blockly.IDraggable'], ['Blockly.IDeletable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_flyout.js', ['Blockly.IFlyout'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_keyboard_accessible.js', ['Blockly.IKeyboardAccessible'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], []); +goog.addDependency('../../core/interfaces/i_metrics_manager.js', ['Blockly.IMetricsManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_movable.js', ['Blockly.IMovable'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_positionable.js', ['Blockly.IPositionable'], ['Blockly.IComponent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_registrable.js', ['Blockly.IRegistrable'], [], {'lang': 'es6', 'module': 'goog'}); From f3a0c6414f673f957afff3e921023821820a6f7d Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 13:40:51 -0700 Subject: [PATCH 287/833] Migrate core/interfaces/i_metrics_manager.js named requires --- core/interfaces/i_metrics_manager.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index f9b74e4c2..b8cbd2231 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -14,9 +14,9 @@ goog.module('Blockly.IMetricsManager'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.utils.Metrics'); -goog.requireType('Blockly.utils.Size'); +const Metrics = goog.requireType('Blockly.utils.Metrics'); +const Size = goog.requireType('Blockly.utils.Size'); +const {AbsoluteMetrics, ContainerRegion, ToolboxMetrics} = goog.requireType('Blockly.MetricsManager'); /** @@ -36,13 +36,13 @@ IMetricsManager.prototype.hasFixedEdges; * Returns the metrics for the scroll area of the workspace. * @param {boolean=} opt_getWorkspaceCoordinates True to get the scroll metrics * in workspace coordinates, false to get them in pixel coordinates. - * @param {!Blockly.MetricsManager.ContainerRegion=} opt_viewMetrics The view + * @param {!ContainerRegion=} opt_viewMetrics The view * metrics if they have been previously computed. Passing in null may cause * the view metrics to be computed again, if it is needed. - * @param {!Blockly.MetricsManager.ContainerRegion=} opt_contentMetrics The + * @param {!ContainerRegion=} opt_contentMetrics The * content metrics if they have been previously computed. Passing in null * may cause the content metrics to be computed again, if it is needed. - * @return {!Blockly.MetricsManager.ContainerRegion} The metrics for the scroll + * @return {!ContainerRegion} The metrics for the scroll * container */ IMetricsManager.prototype.getScrollMetrics; @@ -52,7 +52,7 @@ IMetricsManager.prototype.getScrollMetrics; * coordinates. Returns 0 for the width and height if the workspace has a * category toolbox instead of a simple toolbox. * @param {boolean=} opt_own Whether to only return the workspace's own flyout. - * @return {!Blockly.MetricsManager.ToolboxMetrics} The width and height of the + * @return {!ToolboxMetrics} The width and height of the * flyout. * @public */ @@ -63,7 +63,7 @@ IMetricsManager.prototype.getFlyoutMetrics; * coordinates. Returns 0 for the width and height if the workspace has a simple * toolbox instead of a category toolbox. To get the width and height of a * simple toolbox @see {@link getFlyoutMetrics}. - * @return {!Blockly.MetricsManager.ToolboxMetrics} The object with the width, + * @return {!ToolboxMetrics} The object with the width, * height and position of the toolbox. * @public */ @@ -72,7 +72,7 @@ IMetricsManager.prototype.getToolboxMetrics; /** * Gets the width and height of the workspace's parent SVG element in pixel * coordinates. This area includes the toolbox and the visible workspace area. - * @return {!Blockly.utils.Size} The width and height of the workspace's parent + * @return {!Size} The width and height of the workspace's parent * SVG element. * @public */ @@ -81,7 +81,7 @@ IMetricsManager.prototype.getSvgMetrics; /** * Gets the absolute left and absolute top in pixel coordinates. * This is where the visible workspace starts in relation to the SVG container. - * @return {!Blockly.MetricsManager.AbsoluteMetrics} The absolute metrics for + * @return {!AbsoluteMetrics} The absolute metrics for * the workspace. * @public */ @@ -92,7 +92,7 @@ IMetricsManager.prototype.getAbsoluteMetrics; * coordinates. The visible workspace does not include the toolbox or flyout. * @param {boolean=} opt_getWorkspaceCoordinates True to get the view metrics in * workspace coordinates, false to get them in pixel coordinates. - * @return {!Blockly.MetricsManager.ContainerRegion} The width, height, top and + * @return {!ContainerRegion} The width, height, top and * left of the viewport in either workspace coordinates or pixel * coordinates. * @public @@ -105,7 +105,7 @@ IMetricsManager.prototype.getViewMetrics; * workspace (workspace comments and blocks). * @param {boolean=} opt_getWorkspaceCoordinates True to get the content metrics * in workspace coordinates, false to get them in pixel coordinates. - * @return {!Blockly.MetricsManager.ContainerRegion} The + * @return {!ContainerRegion} The * metrics for the content container. * @public */ @@ -139,7 +139,7 @@ IMetricsManager.prototype.getContentMetrics; * .flyoutHeight: Height of the flyout if it is always open. Otherwise zero. * .toolboxPosition: Top, bottom, left or right. Use TOOLBOX_AT constants to * compare. - * @return {!Blockly.utils.Metrics} Contains size and position metrics of a top + * @return {!Metrics} Contains size and position metrics of a top * level workspace. * @public */ From b72c07ad8decc7ec809a2e566bb9bfd524a38d4f Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 09:16:10 -0700 Subject: [PATCH 288/833] Add eslint disable for no-unused-vars to core/interfaces/i_metrics_manager.js --- core/interfaces/i_metrics_manager.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/interfaces/i_metrics_manager.js b/core/interfaces/i_metrics_manager.js index b8cbd2231..db1f575c1 100644 --- a/core/interfaces/i_metrics_manager.js +++ b/core/interfaces/i_metrics_manager.js @@ -14,8 +14,11 @@ goog.module('Blockly.IMetricsManager'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Metrics = goog.requireType('Blockly.utils.Metrics'); +/* eslint-disable-next-line no-unused-vars */ const Size = goog.requireType('Blockly.utils.Size'); +/* eslint-disable-next-line no-unused-vars */ const {AbsoluteMetrics, ContainerRegion, ToolboxMetrics} = goog.requireType('Blockly.MetricsManager'); From 977d0f35bff7303573bb83e93e821edd4b839c8d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:21:00 -0700 Subject: [PATCH 289/833] Migrate core/icon.js to named requires --- core/icon.js | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/icon.js b/core/icon.js index 02e6f7348..0eaf37f0b 100644 --- a/core/icon.js +++ b/core/icon.js @@ -13,27 +13,28 @@ goog.module('Blockly.Icon'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Bubble = goog.requireType('Blockly.Bubble'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const {getRelativeXY, isRightButton} = goog.require('Blockly.utils'); /** * Class for an icon. - * @param {Blockly.BlockSvg} block The block associated with this icon. + * @param {BlockSvg} block The block associated with this icon. * @constructor * @abstract */ const Icon = function(block) { /** * The block this icon is attached to. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @protected */ this.block_ = block; @@ -57,14 +58,14 @@ Icon.prototype.SIZE = 17; /** * Bubble UI (if visible). - * @type {?Blockly.Bubble} + * @type {?Bubble} * @protected */ Icon.prototype.bubble_ = null; /** * Absolute coordinate of icon's center. - * @type {?Blockly.utils.Coordinate} + * @type {?Coordinate} * @protected */ Icon.prototype.iconXY_ = null; @@ -82,17 +83,17 @@ Icon.prototype.createIcon = function() { ... */ - this.iconGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.iconGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } this.drawIcon_(this.iconGroup_); this.block_.getSvgRoot().appendChild(this.iconGroup_); - Blockly.browserEvents.conditionalBind( + browserEvents.conditionalBind( this.iconGroup_, 'mouseup', this, this.iconClick_); this.updateEditable(); }; @@ -102,7 +103,7 @@ Icon.prototype.createIcon = function() { */ Icon.prototype.dispose = function() { // Dispose of and unlink the icon. - Blockly.utils.dom.removeNode(this.iconGroup_); + dom.removeNode(this.iconGroup_); this.iconGroup_ = null; // Dispose of and unlink the bubble. this.setVisible(false); @@ -134,7 +135,7 @@ Icon.prototype.iconClick_ = function(e) { // Drag operation is concluding. Don't open the editor. return; } - if (!this.block_.isInFlyout && !Blockly.utils.isRightButton(e)) { + if (!this.block_.isInFlyout && !isRightButton(e)) { this.setVisible(!this.isVisible()); } }; @@ -150,7 +151,7 @@ Icon.prototype.applyColour = function() { /** * Notification that the icon has moved. Update the arrow accordingly. - * @param {!Blockly.utils.Coordinate} xy Absolute location in workspace coordinates. + * @param {!Coordinate} xy Absolute location in workspace coordinates. */ Icon.prototype.setIconLocation = function(xy) { this.iconXY_ = xy; @@ -166,19 +167,19 @@ Icon.prototype.setIconLocation = function(xy) { Icon.prototype.computeIconLocation = function() { // Find coordinates for the centre of the icon and update the arrow. const blockXY = this.block_.getRelativeToSurfaceXY(); - const iconXY = Blockly.utils.getRelativeXY( + const iconXY = getRelativeXY( /** @type {!SVGElement} */ (this.iconGroup_)); - const newXY = new Blockly.utils.Coordinate( + const newXY = new Coordinate( blockXY.x + iconXY.x + this.SIZE / 2, blockXY.y + iconXY.y + this.SIZE / 2); - if (!Blockly.utils.Coordinate.equals(this.getIconLocation(), newXY)) { + if (!Coordinate.equals(this.getIconLocation(), newXY)) { this.setIconLocation(newXY); } }; /** * Returns the center of the block's icon relative to the surface. - * @return {?Blockly.utils.Coordinate} Object with x and y properties in + * @return {?Coordinate} Object with x and y properties in * workspace coordinates. */ Icon.prototype.getIconLocation = function() { @@ -189,11 +190,11 @@ Icon.prototype.getIconLocation = function() { * Get the size of the icon as used for rendering. * This differs from the actual size of the icon, because it bulges slightly * out of its row rather than increasing the height of its row. - * @return {!Blockly.utils.Size} Height and width. + * @return {!Size} Height and width. */ // TODO (#2562): Remove getCorrectedSize. Icon.prototype.getCorrectedSize = function() { - return new Blockly.utils.Size( + return new Size( Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; From 7175e9452bceadbf15e80e017bf00e5ffb61bb6b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:21:41 -0700 Subject: [PATCH 290/833] clang-format core/icon.js --- core/icon.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/icon.js b/core/icon.js index 0eaf37f0b..b6b8942a7 100644 --- a/core/icon.js +++ b/core/icon.js @@ -83,9 +83,8 @@ Icon.prototype.createIcon = function() { ... */ - this.iconGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyIconGroup'}, null); + this.iconGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); @@ -194,8 +193,7 @@ Icon.prototype.getIconLocation = function() { */ // TODO (#2562): Remove getCorrectedSize. Icon.prototype.getCorrectedSize = function() { - return new Size( - Icon.prototype.SIZE, Icon.prototype.SIZE - 2); + return new Size(Icon.prototype.SIZE, Icon.prototype.SIZE - 2); }; /** From 2aff67498b516c50479c51a5fbda79bd04aa0951 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:49:13 -0700 Subject: [PATCH 291/833] Migrate core/input.js to ES6 const/let --- core/input.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/input.js b/core/input.js index 443bfc83f..315570ed3 100644 --- a/core/input.js +++ b/core/input.js @@ -151,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * @throws {Error} if the field is not present and opt_quiet is false. */ Blockly.Input.prototype.removeField = function(name, opt_quiet) { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); this.fieldRow.splice(i, 1); @@ -189,13 +189,13 @@ Blockly.Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. - var renderList = []; + let renderList = []; if (this.visible_ == visible) { return renderList; } this.visible_ = visible; - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.setVisible(visible); } if (this.connection) { @@ -207,7 +207,7 @@ Blockly.Input.prototype.setVisible = function(visible) { } else { this.connection.stopTrackingAll(); } - var child = this.connection.targetBlock(); + const child = this.connection.targetBlock(); if (child) { child.getSvgRoot().style.display = visible ? 'block' : 'none'; } @@ -220,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * @package */ Blockly.Input.prototype.markDirty = function() { - for (var y = 0, field; (field = this.fieldRow[y]); y++) { + for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } }; @@ -285,7 +285,7 @@ Blockly.Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } - for (var i = 0; i < this.fieldRow.length; i++) { + for (let i = 0; i < this.fieldRow.length; i++) { this.fieldRow[i].init(); } }; @@ -295,7 +295,7 @@ Blockly.Input.prototype.init = function() { * @suppress {checkTypes} */ Blockly.Input.prototype.dispose = function() { - for (var i = 0, field; (field = this.fieldRow[i]); i++) { + for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } if (this.connection) { From f96c14c0033b27e1a1eef0146fef5f6615283287 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:51:25 -0700 Subject: [PATCH 292/833] Migrate core/input.js to goog.module --- core/input.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/core/input.js b/core/input.js index 315570ed3..b9b277fde 100644 --- a/core/input.js +++ b/core/input.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Input'); +goog.module('Blockly.Input'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.fieldRegistry'); @@ -33,7 +34,7 @@ goog.requireType('Blockly.RenderedConnection'); * @param {Blockly.Connection} connection Optional connection for this input. * @constructor */ -Blockly.Input = function(type, name, block, connection) { +const Input = function(type, name, block, connection) { if (type != Blockly.inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } @@ -56,20 +57,20 @@ Blockly.Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Blockly.Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = Blockly.constants.ALIGN.LEFT; /** * Is the input visible? * @type {boolean} * @private */ -Blockly.Input.prototype.visible_ = true; +Input.prototype.visible_ = true; /** * Get the source block for this input. * @return {?Blockly.Block} The source block, or null if there is none. */ -Blockly.Input.prototype.getSourceBlock = function() { +Input.prototype.getSourceBlock = function() { return this.sourceBlock_; }; @@ -79,9 +80,9 @@ Blockly.Input.prototype.getSourceBlock = function() { * @param {string|!Blockly.Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. - * @return {!Blockly.Input} The input being append to (to allow chaining). + * @return {!Input} The input being append to (to allow chaining). */ -Blockly.Input.prototype.appendField = function(field, opt_name) { +Input.prototype.appendField = function(field, opt_name) { this.insertFieldAt(this.fieldRow.length, field, opt_name); return this; }; @@ -95,7 +96,7 @@ Blockly.Input.prototype.appendField = function(field, opt_name) { * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. */ -Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { +Input.prototype.insertFieldAt = function(index, field, opt_name) { if (index < 0 || index > this.fieldRow.length) { throw Error('index ' + index + ' out of bounds.'); } @@ -150,7 +151,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) { * and opt_quiet is true. * @throws {Error} if the field is not present and opt_quiet is false. */ -Blockly.Input.prototype.removeField = function(name, opt_quiet) { +Input.prototype.removeField = function(name, opt_quiet) { for (let i = 0, field; (field = this.fieldRow[i]); i++) { if (field.name === name) { field.dispose(); @@ -174,7 +175,7 @@ Blockly.Input.prototype.removeField = function(name, opt_quiet) { * Gets whether this input is visible or not. * @return {boolean} True if visible. */ -Blockly.Input.prototype.isVisible = function() { +Input.prototype.isVisible = function() { return this.visible_; }; @@ -185,7 +186,7 @@ Blockly.Input.prototype.isVisible = function() { * @return {!Array} List of blocks to render. * @package */ -Blockly.Input.prototype.setVisible = function(visible) { +Input.prototype.setVisible = function(visible) { // Note: Currently there are only unit tests for block.setCollapsed() // because this function is package. If this function goes back to being a // public API tests (lots of tests) should be added. @@ -219,7 +220,7 @@ Blockly.Input.prototype.setVisible = function(visible) { * Mark all fields on this input as dirty. * @package */ -Blockly.Input.prototype.markDirty = function() { +Input.prototype.markDirty = function() { for (let y = 0, field; (field = this.fieldRow[y]); y++) { field.markDirty(); } @@ -229,9 +230,9 @@ Blockly.Input.prototype.markDirty = function() { * Change a connection's compatibility. * @param {string|Array|null} check Compatible value type or * list of value types. Null if all types are compatible. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setCheck = function(check) { +Input.prototype.setCheck = function(check) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -243,9 +244,9 @@ Blockly.Input.prototype.setCheck = function(check) { * Change the alignment of the connection's field(s). * @param {number} align One of the values of Blockly.constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setAlign = function(align) { +Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); @@ -257,9 +258,9 @@ Blockly.Input.prototype.setAlign = function(align) { /** * Changes the connection's shadow block. * @param {?Element} shadow DOM representation of a block or null. - * @return {!Blockly.Input} The input being modified (to allow chaining). + * @return {!Input} The input being modified (to allow chaining). */ -Blockly.Input.prototype.setShadowDom = function(shadow) { +Input.prototype.setShadowDom = function(shadow) { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -271,7 +272,7 @@ Blockly.Input.prototype.setShadowDom = function(shadow) { * Returns the XML representation of the connection's shadow block. * @return {?Element} Shadow DOM representation of a block or null. */ -Blockly.Input.prototype.getShadowDom = function() { +Input.prototype.getShadowDom = function() { if (!this.connection) { throw Error('This input does not have a connection.'); } @@ -281,7 +282,7 @@ Blockly.Input.prototype.getShadowDom = function() { /** * Initialize the fields on this input. */ -Blockly.Input.prototype.init = function() { +Input.prototype.init = function() { if (!this.sourceBlock_.workspace.rendered) { return; // Headless blocks don't need fields initialized. } @@ -294,7 +295,7 @@ Blockly.Input.prototype.init = function() { * Sever all links to this input. * @suppress {checkTypes} */ -Blockly.Input.prototype.dispose = function() { +Input.prototype.dispose = function() { for (let i = 0, field; (field = this.fieldRow[i]); i++) { field.dispose(); } @@ -303,3 +304,5 @@ Blockly.Input.prototype.dispose = function() { } this.sourceBlock_ = null; }; + +exports = Input; From f59da974b44dcd4fd1de119ae889815e5e86ca7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:55:41 -0700 Subject: [PATCH 293/833] Migrate core/input.js to named requires --- core/input.js | 56 +++++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/core/input.js b/core/input.js index b9b277fde..59c3b8a72 100644 --- a/core/input.js +++ b/core/input.js @@ -13,29 +13,33 @@ goog.module('Blockly.Input'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.fieldRegistry'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const constants = goog.require('Blockly.constants'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const inputTypes = goog.require('Blockly.inputTypes'); /** @suppress {extraRequire} */ goog.require('Blockly.FieldLabel'); -goog.require('Blockly.inputTypes'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.RenderedConnection'); - /** * Class for an input with an optional field. * @param {number} type The type of the input. * @param {string} name Language-neutral identifier which may used to find this * input again. - * @param {!Blockly.Block} block The block containing this input. - * @param {Blockly.Connection} connection Optional connection for this input. + * @param {!Block} block The block containing this input. + * @param {Connection} connection Optional connection for this input. * @constructor */ const Input = function(type, name, block, connection) { - if (type != Blockly.inputTypes.DUMMY && !name) { + if (type != inputTypes.DUMMY && !name) { throw Error('Value inputs and statement inputs must have non-empty name.'); } /** @type {number} */ @@ -43,13 +47,13 @@ const Input = function(type, name, block, connection) { /** @type {string} */ this.name = name; /** - * @type {!Blockly.Block} + * @type {!Block} * @private */ this.sourceBlock_ = block; - /** @type {Blockly.Connection} */ + /** @type {Connection} */ this.connection = connection; - /** @type {!Array} */ + /** @type {!Array} */ this.fieldRow = []; }; @@ -57,7 +61,7 @@ const Input = function(type, name, block, connection) { * Alignment of input's fields (left, right or centre). * @type {number} */ -Input.prototype.align = Blockly.constants.ALIGN.LEFT; +Input.prototype.align = constants.ALIGN.LEFT; /** * Is the input visible? @@ -68,7 +72,7 @@ Input.prototype.visible_ = true; /** * Get the source block for this input. - * @return {?Blockly.Block} The source block, or null if there is none. + * @return {?Block} The source block, or null if there is none. */ Input.prototype.getSourceBlock = function() { return this.sourceBlock_; @@ -77,7 +81,7 @@ Input.prototype.getSourceBlock = function() { /** * Add a field (or label from string), and all prefix and suffix fields, to the * end of the input's field row. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {!Input} The input being append to (to allow chaining). @@ -91,7 +95,7 @@ Input.prototype.appendField = function(field, opt_name) { * Inserts a field (or label from string), and all prefix and suffix fields, at * the location of the input's field row. * @param {number} index The index at which to insert field. - * @param {string|!Blockly.Field} field Something to add as a field. + * @param {string|!Field} field Something to add as a field. * @param {string=} opt_name Language-neutral identifier which may used to find * this field again. Should be unique to the host block. * @return {number} The index following the last inserted field. @@ -108,7 +112,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { // Generate a FieldLabel when given a plain text field. if (typeof field == 'string') { - field = /** @type {!Blockly.Field} **/ (Blockly.fieldRegistry.fromJson({ + field = /** @type {!Field} **/ (fieldRegistry.fromJson({ 'type': 'field_label', 'text': field, })); @@ -135,7 +139,7 @@ Input.prototype.insertFieldAt = function(index, field, opt_name) { } if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Adding a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -157,7 +161,7 @@ Input.prototype.removeField = function(name, opt_quiet) { field.dispose(); this.fieldRow.splice(i, 1); if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); // Removing a field will cause the block to change shape. this.sourceBlock_.bumpNeighbours(); @@ -183,7 +187,7 @@ Input.prototype.isVisible = function() { * Sets whether this input is visible or not. * Should only be used to collapse/uncollapse a block. * @param {boolean} visible True if visible. - * @return {!Array} List of blocks to render. + * @return {!Array} List of blocks to render. * @package */ Input.prototype.setVisible = function(visible) { @@ -201,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!Blockly.RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); @@ -242,14 +246,14 @@ Input.prototype.setCheck = function(check) { /** * Change the alignment of the connection's field(s). - * @param {number} align One of the values of Blockly.constants.ALIGN. + * @param {number} align One of the values of constants.ALIGN. * In RTL mode directions are reversed, and ALIGN.RIGHT aligns to the left. * @return {!Input} The input being modified (to allow chaining). */ Input.prototype.setAlign = function(align) { this.align = align; if (this.sourceBlock_.rendered) { - this.sourceBlock_ = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + this.sourceBlock_ = /** @type {!BlockSvg} */ (this.sourceBlock_); this.sourceBlock_.render(); } return this; diff --git a/tests/deps.js b/tests/deps.js index f62333982..1cda35a7e 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -70,7 +70,7 @@ goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.Block goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/input.js', ['Blockly.Input'], ['Blockly.Connection', 'Blockly.FieldLabel', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/input_types.js', ['Blockly.inputTypes'], ['Blockly.connectionTypes']); goog.addDependency('../../core/insertion_marker_manager.js', ['Blockly.InsertionMarkerManager'], ['Blockly.ComponentManager', 'Blockly.Events', 'Blockly.blockAnimations', 'Blockly.connectionTypes', 'Blockly.internalConstants'], {'lang': 'es5'}); goog.addDependency('../../core/interfaces/i_ast_node_location.js', ['Blockly.IASTNodeLocation'], [], {'lang': 'es6', 'module': 'goog'}); From 761eec2b69dd20638171cf7a75302d1a79a89e3b Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 09:56:17 -0700 Subject: [PATCH 294/833] clang-format core/input.js --- core/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/input.js b/core/input.js index 59c3b8a72..afa7a3358 100644 --- a/core/input.js +++ b/core/input.js @@ -205,7 +205,7 @@ Input.prototype.setVisible = function(visible) { } if (this.connection) { this.connection = - /** @type {!RenderedConnection} */ (this.connection); + /** @type {!RenderedConnection} */ (this.connection); // Has a connection. if (visible) { renderList = this.connection.startTrackingAll(); From fc10f9e62551d7a5e13841f6ce3fab0751705322 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 07:57:49 -0700 Subject: [PATCH 295/833] Migrate core/block_dragger.js to ES6 const/let --- core/block_dragger.js | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index a1d4b6f2d..d51eead48 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -116,12 +116,13 @@ Blockly.BlockDragger.prototype.dispose = function() { */ Blockly.BlockDragger.initIconData_ = function(block) { // Build a list of icons that need to be moved and where they started. - var dragIconData = []; - var descendants = block.getDescendants(false); - for (var i = 0, descendant; (descendant = descendants[i]); i++) { - var icons = descendant.getIcons(); - for (var j = 0; j < icons.length; j++) { - var data = { + const dragIconData = []; + const descendants = block.getDescendants(false); + + for (let i = 0, descendant; (descendant = descendants[i]); i++) { + const icons = descendant.getIcons(); + for (let j = 0; j < icons.length; j++) { + const data = { // Blockly.utils.Coordinate with x and y properties (workspace // coordinates). location: icons[j].getIconLocation(), @@ -198,8 +199,8 @@ Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { Blockly.BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); Blockly.blockAnimations.disconnectUiEffect(this.draggingBlock_); @@ -211,7 +212,7 @@ Blockly.BlockDragger.prototype.disconnectBlock_ = function( * @protected */ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -225,16 +226,16 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { * @public */ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { - var delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - var newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); + const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); - var oldDragTarget = this.dragTarget_; + const oldDragTarget = this.dragTarget_; this.dragTarget_ = this.workspace_.getDragTarget(e); this.draggedConnectionManager_.update(delta, this.dragTarget_); - var oldWouldDeleteBlock = this.wouldDeleteBlock_; + const oldWouldDeleteBlock = this.wouldDeleteBlock_; this.wouldDeleteBlock_ = this.draggedConnectionManager_.wouldDeleteBlock(); if (oldWouldDeleteBlock != this.wouldDeleteBlock_) { // Prevent unnecessary add/remove class calls. @@ -267,12 +268,12 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { Blockly.blockAnimations.disconnectUiStop(); - var preventMove = !!this.dragTarget_ && + const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); if (preventMove) { var newLoc = this.startXY_; } else { - var newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY); + const newValues = this.getNewLocationAfterDrag_(currentDragDeltaXY); var delta = newValues.delta; var newLoc = newValues.newLocation; } @@ -282,7 +283,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragTarget_.onDrop(this.draggingBlock_); } - var deleted = this.maybeDeleteBlock_(); + const deleted = this.maybeDeleteBlock_(); if (!deleted) { // These are expensive and don't need to be done if we're deleting. this.draggingBlock_.setDragging(false); @@ -314,7 +315,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { */ Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( currentDragDeltaXY) { - var newValues = {}; + const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); newValues.newLocation = Blockly.utils.Coordinate.sum(this.startXY_, newValues.delta); @@ -362,7 +363,7 @@ Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { - var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); }; @@ -375,11 +376,11 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @protected */ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { - var toolbox = this.workspace_.getToolbox(); + const toolbox = this.workspace_.getToolbox(); if (toolbox) { - var style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + const style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : + 'blocklyToolboxGrab'; if (isEnd && typeof toolbox.removeStyle == 'function') { toolbox.removeStyle(style); @@ -395,7 +396,7 @@ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { - var event = + const event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); @@ -423,7 +424,7 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * @protected */ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - var result = new Blockly.utils.Coordinate( + const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { @@ -431,7 +432,7 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { // oddities in our rendering optimizations. The actual scale is the same as // the scale on the parent workspace. // Fix that for dragging. - var mainScale = this.workspace_.options.parentWorkspace.scale; + const mainScale = this.workspace_.options.parentWorkspace.scale; result.scale(1 / mainScale); } return result; @@ -445,8 +446,8 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { */ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. - for (var i = 0; i < this.dragIconData_.length; i++) { - var data = this.dragIconData_[i]; + for (let i = 0; i < this.dragIconData_.length; i++) { + const data = this.dragIconData_[i]; data.icon.setIconLocation(Blockly.utils.Coordinate.sum(data.location, dxy)); } }; From 4850ad0300f5293bbe37511e52cda6853126a662 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:08:31 -0700 Subject: [PATCH 296/833] Migrate core/block_dragger.js to goog.module --- core/block_dragger.js | 48 ++++++++++++++++++++++--------------------- tests/deps.js | 2 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index d51eead48..ee103f81b 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.BlockDragger'); +goog.module('Blockly.BlockDragger'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockAnimations'); /** @suppress {extraRequire} */ @@ -39,7 +40,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @implements {Blockly.IBlockDragger} */ -Blockly.BlockDragger = function(block, workspace) { +const BlockDragger = function(block, workspace) { /** * The top block in the stack that is being dragged. * @type {!Blockly.BlockSvg} @@ -91,14 +92,14 @@ Blockly.BlockDragger = function(block, workspace) { * @type {Array} * @protected */ - this.dragIconData_ = Blockly.BlockDragger.initIconData_(block); + this.dragIconData_ = initIconData(block); }; /** * Sever all links from this object. * @package */ -Blockly.BlockDragger.prototype.dispose = function() { +BlockDragger.prototype.dispose = function() { this.dragIconData_.length = 0; if (this.draggedConnectionManager_) { @@ -112,9 +113,8 @@ Blockly.BlockDragger.prototype.dispose = function() { * extends from it if that bubble is open. * @param {!Blockly.BlockSvg} block The root block that is being dragged. * @return {!Array} The list of all icons and their locations. - * @private */ -Blockly.BlockDragger.initIconData_ = function(block) { +const initIconData = function(block) { // Build a list of icons that need to be moved and where they started. const dragIconData = []; const descendants = block.getDescendants(false); @@ -143,7 +143,7 @@ Blockly.BlockDragger.initIconData_ = function(block) { * disconnecting. * @public */ -Blockly.BlockDragger.prototype.startDrag = function( +BlockDragger.prototype.startDrag = function( currentDragDeltaXY, healStack) { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); @@ -181,7 +181,7 @@ Blockly.BlockDragger.prototype.startDrag = function( * @return {boolean} True to disconnect the block, false otherwise. * @protected */ -Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { +BlockDragger.prototype.shouldDisconnect_ = function(healStack) { return !!( this.draggingBlock_.getParent() || (healStack && this.draggingBlock_.nextConnection && @@ -196,7 +196,7 @@ Blockly.BlockDragger.prototype.shouldDisconnect_ = function(healStack) { * moved from the position at mouse down, in pixel units. * @protected */ -Blockly.BlockDragger.prototype.disconnectBlock_ = function( +BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); @@ -211,7 +211,7 @@ Blockly.BlockDragger.prototype.disconnectBlock_ = function( * Fire a UI event at the start of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { +BlockDragger.prototype.fireDragStartEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); @@ -225,7 +225,7 @@ Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() { * moved from the position at the start of the drag, in pixel units. * @public */ -Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { +BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); @@ -258,7 +258,7 @@ Blockly.BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { * moved from the position at the start of the drag, in pixel units. * @public */ -Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { +BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { // Make sure internal state is fresh. this.drag(e, currentDragDeltaXY); this.dragIconData_ = []; @@ -313,7 +313,7 @@ Blockly.BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { * end up. * @protected */ -Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( +BlockDragger.prototype.getNewLocationAfterDrag_ = function( currentDragDeltaXY) { const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); @@ -329,7 +329,7 @@ Blockly.BlockDragger.prototype.getNewLocationAfterDrag_ = function( * @return {boolean} True if the block was deleted. * @protected */ -Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() { +BlockDragger.prototype.maybeDeleteBlock_ = function() { if (this.wouldDeleteBlock_) { // Fire a move event, so we know where to go back to for an undo. this.fireMoveEvent_(); @@ -346,7 +346,7 @@ Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() { * the block started the drag to where it ended the drag. * @protected */ -Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { +BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { this.draggingBlock_.moveConnections(delta.x, delta.y); this.fireMoveEvent_(); if (this.draggedConnectionManager_.wouldConnectBlock()) { @@ -362,7 +362,7 @@ Blockly.BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * Fire a UI event at the end of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { +BlockDragger.prototype.fireDragEndEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); Blockly.Events.fire(event); @@ -375,7 +375,7 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() { * @param {boolean} isEnd True if we are at the end of a drag, false otherwise. * @protected */ -Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { +BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { const toolbox = this.workspace_.getToolbox(); if (toolbox) { @@ -395,7 +395,7 @@ Blockly.BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * Fire a move event at the end of a block drag. * @protected */ -Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { +BlockDragger.prototype.fireMoveEvent_ = function() { const event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; @@ -408,7 +408,7 @@ Blockly.BlockDragger.prototype.fireMoveEvent_ = function() { * dragging block would be deleted if released immediately. * @protected */ -Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { +BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { this.draggingBlock_.setDeleteStyle(this.wouldDeleteBlock_); }; @@ -423,7 +423,7 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * workspace scale. * @protected */ -Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { +BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { const result = new Blockly.utils.Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); @@ -444,7 +444,7 @@ Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { * original positions, in workspace units. * @protected */ -Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { +BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. for (let i = 0; i < this.dragIconData_.length; i++) { const data = this.dragIconData_[i]; @@ -459,7 +459,7 @@ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { * marker blocks. * @public */ -Blockly.BlockDragger.prototype.getInsertionMarkers = function() { +BlockDragger.prototype.getInsertionMarkers = function() { // No insertion markers with the old style of dragged connection managers. if (this.draggedConnectionManager_ && this.draggedConnectionManager_.getInsertionMarkers) { @@ -470,4 +470,6 @@ Blockly.BlockDragger.prototype.getInsertionMarkers = function() { Blockly.registry.register( Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, - Blockly.BlockDragger); + BlockDragger); + +exports = BlockDragger; diff --git a/tests/deps.js b/tests/deps.js index da56c39f2..b268b88c1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,7 +10,7 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); From 873b75e58a8560506daf39f06c9ed19ddbe3a62f Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:15:10 -0700 Subject: [PATCH 297/833] Migrate core/block_dragger.js named requires --- core/block_dragger.js | 109 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index ee103f81b..40436a4e1 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,59 +13,58 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockAnimations'); +const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); +const BlockSvg = goog.requireType('Blockly.BlockSvg'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -goog.require('Blockly.Events'); +const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -goog.require('Blockly.IBlockDragger'); -goog.require('Blockly.InsertionMarkerManager'); -goog.require('Blockly.registry'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.IDragTarget'); -goog.requireType('Blockly.WorkspaceSvg'); +const IBlockDragger = goog.require('Blockly.IBlockDragger'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +const {DEFAULT, Type, register} = goog.require('Blockly.registry'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a block dragger. It moves blocks around the workspace when they * are being dragged by a mouse or touch. - * @param {!Blockly.BlockSvg} block The block to drag. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on. + * @param {!BlockSvg} block The block to drag. + * @param {!WorkspaceSvg} workspace The workspace to drag on. * @constructor - * @implements {Blockly.IBlockDragger} + * @implements {IBlockDragger} */ const BlockDragger = function(block, workspace) { /** * The top block in the stack that is being dragged. - * @type {!Blockly.BlockSvg} + * @type {!BlockSvg} * @protected */ this.draggingBlock_ = block; /** * The workspace on which the block is being dragged. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @protected */ this.workspace_ = workspace; /** * Object that keeps track of connections on dragged blocks. - * @type {!Blockly.InsertionMarkerManager} + * @type {!InsertionMarkerManager} * @protected */ this.draggedConnectionManager_ = - new Blockly.InsertionMarkerManager(this.draggingBlock_); + new InsertionMarkerManager(this.draggingBlock_); /** * Which drag area the mouse pointer is over, if any. - * @type {?Blockly.IDragTarget} + * @type {?IDragTarget} * @private */ this.dragTarget_ = null; @@ -80,7 +79,7 @@ const BlockDragger = function(block, workspace) { /** * The location of the top left corner of the dragging block at the beginning * of the drag in workspace coordinates. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @protected */ this.startXY_ = this.draggingBlock_.getRelativeToSurfaceXY(); @@ -111,7 +110,7 @@ BlockDragger.prototype.dispose = function() { * Make a list of all of the icons (comment, warning, and mutator) that are * on this block and its descendants. Moving an icon moves the bubble that * extends from it if that bubble is open. - * @param {!Blockly.BlockSvg} block The root block that is being dragged. + * @param {!BlockSvg} block The root block that is being dragged. * @return {!Array} The list of all icons and their locations. */ const initIconData = function(block) { @@ -123,7 +122,7 @@ const initIconData = function(block) { const icons = descendant.getIcons(); for (let j = 0; j < icons.length; j++) { const data = { - // Blockly.utils.Coordinate with x and y properties (workspace + // Coordinate with x and y properties (workspace // coordinates). location: icons[j].getIconLocation(), // Blockly.Icon @@ -137,7 +136,7 @@ const initIconData = function(block) { /** * Start dragging a block. This includes moving it to the drag surface. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. @@ -145,8 +144,8 @@ const initIconData = function(block) { */ BlockDragger.prototype.startDrag = function( currentDragDeltaXY, healStack) { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!getGroup()) { + setGroup(true); } this.fireDragStartEvent_(); @@ -160,9 +159,9 @@ BlockDragger.prototype.startDrag = function( // During a drag there may be a lot of rerenders, but not field changes. // Turn the cache on so we don't do spurious remeasures during the drag. - Blockly.utils.dom.startTextWidthCache(); + startTextWidthCache(); this.workspace_.setResizesEnabled(false); - Blockly.blockAnimations.disconnectUiStop(); + disconnectUiStop(); if (this.shouldDisconnect_(healStack)) { this.disconnectBlock_(healStack, currentDragDeltaXY); @@ -192,7 +191,7 @@ BlockDragger.prototype.shouldDisconnect_ = function(healStack) { * Disconnects the block and moves it to a new location. * @param {boolean} healStack Whether or not to heal the stack after * disconnecting. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at mouse down, in pixel units. * @protected */ @@ -200,10 +199,10 @@ BlockDragger.prototype.disconnectBlock_ = function( healStack, currentDragDeltaXY) { this.draggingBlock_.unplug(healStack); const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); - Blockly.blockAnimations.disconnectUiEffect(this.draggingBlock_); + disconnectUiEffect(this.draggingBlock_); this.draggedConnectionManager_.updateAvailableConnections(); }; @@ -212,22 +211,22 @@ BlockDragger.prototype.disconnectBlock_ = function( * @protected */ BlockDragger.prototype.fireDragStartEvent_ = function() { - const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (get(BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event); + fire(event); }; /** * Execute a step of block dragging, based on the given event. Update the * display accordingly. * @param {!Event} e The most recent move event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. * @public */ BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { const delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - const newLoc = Blockly.utils.Coordinate.sum(this.startXY_, delta); + const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.moveDuringDrag(newLoc); this.dragIcons_(delta); @@ -254,7 +253,7 @@ BlockDragger.prototype.drag = function(e, currentDragDeltaXY) { /** * Finish a block drag and put the block back on the workspace. * @param {!Event} e The mouseup/touchend event. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the position at the start of the drag, in pixel units. * @public */ @@ -264,9 +263,9 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragIconData_ = []; this.fireDragEndEvent_(); - Blockly.utils.dom.stopTextWidthCache(); + stopTextWidthCache(); - Blockly.blockAnimations.disconnectUiStop(); + disconnectUiStop(); const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); @@ -300,15 +299,15 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { } this.workspace_.setResizesEnabled(true); - Blockly.Events.setGroup(false); + setGroup(false); }; /** * Calculates the drag delta and new location values after a block is dragged. - * @param {!Blockly.utils.Coordinate} currentDragDeltaXY How far the pointer has + * @param {!Coordinate} currentDragDeltaXY How far the pointer has * moved from the start of the drag, in pixel units. - * @return {{delta: !Blockly.utils.Coordinate, newLocation: - * !Blockly.utils.Coordinate}} New location after drag. delta is in + * @return {{delta: !Coordinate, newLocation: + * !Coordinate}} New location after drag. delta is in * workspace units. newLocation is the new coordinate where the block should * end up. * @protected @@ -318,7 +317,7 @@ BlockDragger.prototype.getNewLocationAfterDrag_ = function( const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); newValues.newLocation = - Blockly.utils.Coordinate.sum(this.startXY_, newValues.delta); + Coordinate.sum(this.startXY_, newValues.delta); return newValues; }; @@ -342,7 +341,7 @@ BlockDragger.prototype.maybeDeleteBlock_ = function() { /** * Updates the necessary information to place a block at a certain location. - * @param {!Blockly.utils.Coordinate} delta The change in location from where + * @param {!Coordinate} delta The change in location from where * the block started the drag to where it ended the drag. * @protected */ @@ -363,9 +362,9 @@ BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ BlockDragger.prototype.fireDragEndEvent_ = function() { - const event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))( + const event = new (get(BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); - Blockly.Events.fire(event); + fire(event); }; /** @@ -397,10 +396,10 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { */ BlockDragger.prototype.fireMoveEvent_ = function() { const event = - new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this.draggingBlock_); + new (get(BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); - Blockly.Events.fire(event); + fire(event); }; /** @@ -417,14 +416,14 @@ BlockDragger.prototype.updateCursorDuringBlockDrag_ = function() { * correction for mutator workspaces. * This function does not consider differing origins. It simply scales the * input's x and y values. - * @param {!Blockly.utils.Coordinate} pixelCoord A coordinate with x and y + * @param {!Coordinate} pixelCoord A coordinate with x and y * values in CSS pixel units. - * @return {!Blockly.utils.Coordinate} The input coordinate divided by the + * @return {!Coordinate} The input coordinate divided by the * workspace scale. * @protected */ BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { - const result = new Blockly.utils.Coordinate( + const result = new Coordinate( pixelCoord.x / this.workspace_.scale, pixelCoord.y / this.workspace_.scale); if (this.workspace_.isMutator) { @@ -440,7 +439,7 @@ BlockDragger.prototype.pixelsToWorkspaceUnits_ = function(pixelCoord) { /** * Move all of the icons connected to this drag. - * @param {!Blockly.utils.Coordinate} dxy How far to move the icons from their + * @param {!Coordinate} dxy How far to move the icons from their * original positions, in workspace units. * @protected */ @@ -448,14 +447,14 @@ BlockDragger.prototype.dragIcons_ = function(dxy) { // Moving icons moves their associated bubbles. for (let i = 0; i < this.dragIconData_.length; i++) { const data = this.dragIconData_[i]; - data.icon.setIconLocation(Blockly.utils.Coordinate.sum(data.location, dxy)); + data.icon.setIconLocation(Coordinate.sum(data.location, dxy)); } }; /** * Get a list of the insertion markers that currently exist. Drags have 0, 1, * or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion + * @return {!Array} A possibly empty list of insertion * marker blocks. * @public */ @@ -468,8 +467,8 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -Blockly.registry.register( - Blockly.registry.Type.BLOCK_DRAGGER, Blockly.registry.DEFAULT, +register( + Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); exports = BlockDragger; From 848ec34a0aef90bafe46c2cbee9b5f761d002f99 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:16:19 -0700 Subject: [PATCH 298/833] clang-format core/block_dragger.js --- core/block_dragger.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 40436a4e1..e97457d22 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -142,8 +142,7 @@ const initIconData = function(block) { * disconnecting. * @public */ -BlockDragger.prototype.startDrag = function( - currentDragDeltaXY, healStack) { +BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { if (!getGroup()) { setGroup(true); } @@ -182,7 +181,7 @@ BlockDragger.prototype.startDrag = function( */ BlockDragger.prototype.shouldDisconnect_ = function(healStack) { return !!( - this.draggingBlock_.getParent() || + this.draggingBlock_.getParent() || (healStack && this.draggingBlock_.nextConnection && this.draggingBlock_.nextConnection.targetBlock())); }; @@ -312,12 +311,10 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { * end up. * @protected */ -BlockDragger.prototype.getNewLocationAfterDrag_ = function( - currentDragDeltaXY) { +BlockDragger.prototype.getNewLocationAfterDrag_ = function(currentDragDeltaXY) { const newValues = {}; newValues.delta = this.pixelsToWorkspaceUnits_(currentDragDeltaXY); - newValues.newLocation = - Coordinate.sum(this.startXY_, newValues.delta); + newValues.newLocation = Coordinate.sum(this.startXY_, newValues.delta); return newValues; }; @@ -379,7 +376,7 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { if (toolbox) { const style = this.draggingBlock_.isDeletable() ? 'blocklyToolboxDelete' : - 'blocklyToolboxGrab'; + 'blocklyToolboxGrab'; if (isEnd && typeof toolbox.removeStyle == 'function') { toolbox.removeStyle(style); @@ -395,8 +392,7 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ BlockDragger.prototype.fireMoveEvent_ = function() { - const event = - new (get(BLOCK_MOVE))(this.draggingBlock_); + const event = new (get(BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); fire(event); @@ -467,8 +463,6 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -register( - Type.BLOCK_DRAGGER, DEFAULT, - BlockDragger); +register(Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); exports = BlockDragger; From c838b0e27c158e72810250442e119fffedf8f223 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Thu, 22 Jul 2021 08:23:28 -0700 Subject: [PATCH 299/833] Reorder requires --- core/block_dragger.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index e97457d22..20c619cbc 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,22 +13,22 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); -const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const IBlockDragger = goog.require('Blockly.IBlockDragger'); +const IDragTarget = goog.requireType('Blockly.IDragTarget'); +const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); +const {DEFAULT, Type, register} = goog.require('Blockly.registry'); +const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); +const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); -const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); -const IBlockDragger = goog.require('Blockly.IBlockDragger'); -const IDragTarget = goog.requireType('Blockly.IDragTarget'); -const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); -const {DEFAULT, Type, register} = goog.require('Blockly.registry'); -const Coordinate = goog.require('Blockly.utils.Coordinate'); -const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); -const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** From 2688329aefdc7b5501a1d77aa688ec842d0923bf Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 23 Jul 2021 12:12:59 -0700 Subject: [PATCH 300/833] Fix imports --- core/block_dragger.js | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 20c619cbc..5c3ff6916 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -13,16 +13,20 @@ goog.module('Blockly.BlockDragger'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const BlockSvg = goog.requireType('Blockly.BlockSvg'); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const IBlockDragger = goog.require('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ const IDragTarget = goog.requireType('Blockly.IDragTarget'); const InsertionMarkerManager = goog.require('Blockly.InsertionMarkerManager'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); -const {BLOCK_DRAG, BLOCK_MOVE, fire, get, getGroup, setGroup} = goog.require('Blockly.Events'); -const {DEFAULT, Type, register} = goog.require('Blockly.registry'); -const {disconnectUiEffect, disconnectUiStop} = goog.require('Blockly.blockAnimations'); -const {startTextWidthCache, stopTextWidthCache} = goog.require('Blockly.utils.dom'); +const blockAnimation = goog.require('Blockly.blockAnimations'); +const dom = goog.require('Blockly.utils.dom'); +const events = goog.require('Blockly.Events'); +const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); /** @suppress {extraRequire} */ @@ -143,8 +147,8 @@ const initIconData = function(block) { * @public */ BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { - if (!getGroup()) { - setGroup(true); + if (!events.getGroup()) { + events.setGroup(true); } this.fireDragStartEvent_(); @@ -158,9 +162,9 @@ BlockDragger.prototype.startDrag = function(currentDragDeltaXY, healStack) { // During a drag there may be a lot of rerenders, but not field changes. // Turn the cache on so we don't do spurious remeasures during the drag. - startTextWidthCache(); + dom.startTextWidthCache(); this.workspace_.setResizesEnabled(false); - disconnectUiStop(); + blockAnimation.disconnectUiStop(); if (this.shouldDisconnect_(healStack)) { this.disconnectBlock_(healStack, currentDragDeltaXY); @@ -201,7 +205,7 @@ BlockDragger.prototype.disconnectBlock_ = function( const newLoc = Coordinate.sum(this.startXY_, delta); this.draggingBlock_.translate(newLoc.x, newLoc.y); - disconnectUiEffect(this.draggingBlock_); + blockAnimation.disconnectUiEffect(this.draggingBlock_); this.draggedConnectionManager_.updateAvailableConnections(); }; @@ -210,9 +214,9 @@ BlockDragger.prototype.disconnectBlock_ = function( * @protected */ BlockDragger.prototype.fireDragStartEvent_ = function() { - const event = new (get(BLOCK_DRAG))( + const event = new (events.get(events.BLOCK_DRAG))( this.draggingBlock_, true, this.draggingBlock_.getDescendants(false)); - fire(event); + events.fire(event); }; /** @@ -262,9 +266,9 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { this.dragIconData_ = []; this.fireDragEndEvent_(); - stopTextWidthCache(); + dom.stopTextWidthCache(); - disconnectUiStop(); + blockAnimation.disconnectUiStop(); const preventMove = !!this.dragTarget_ && this.dragTarget_.shouldPreventMove(this.draggingBlock_); @@ -298,7 +302,7 @@ BlockDragger.prototype.endDrag = function(e, currentDragDeltaXY) { } this.workspace_.setResizesEnabled(true); - setGroup(false); + events.setGroup(false); }; /** @@ -359,9 +363,9 @@ BlockDragger.prototype.updateBlockAfterMove_ = function(delta) { * @protected */ BlockDragger.prototype.fireDragEndEvent_ = function() { - const event = new (get(BLOCK_DRAG))( + const event = new (events.get(events.BLOCK_DRAG))( this.draggingBlock_, false, this.draggingBlock_.getDescendants(false)); - fire(event); + events.fire(event); }; /** @@ -392,10 +396,10 @@ BlockDragger.prototype.updateToolboxStyle_ = function(isEnd) { * @protected */ BlockDragger.prototype.fireMoveEvent_ = function() { - const event = new (get(BLOCK_MOVE))(this.draggingBlock_); + const event = new (events.get(events.BLOCK_MOVE))(this.draggingBlock_); event.oldCoordinate = this.startXY_; event.recordNew(); - fire(event); + events.fire(event); }; /** @@ -463,6 +467,6 @@ BlockDragger.prototype.getInsertionMarkers = function() { return []; }; -register(Type.BLOCK_DRAGGER, DEFAULT, BlockDragger); +registry.register(registry.Type.BLOCK_DRAGGER, registry.DEFAULT, BlockDragger); exports = BlockDragger; From f88320770c7d6e045279916b537eabcdc3345aa7 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Fri, 23 Jul 2021 12:16:00 -0700 Subject: [PATCH 301/833] Remove unnecessary require --- core/block_dragger.js | 2 -- tests/deps.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 5c3ff6916..b7c11e8a3 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -28,8 +28,6 @@ const dom = goog.require('Blockly.utils.dom'); const events = goog.require('Blockly.Events'); const registry = goog.require('Blockly.registry'); /** @suppress {extraRequire} */ -goog.require('Blockly.constants'); -/** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockDrag'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockMove'); diff --git a/tests/deps.js b/tests/deps.js index b268b88c1..42191e253 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -10,7 +10,7 @@ goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.Vari goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); From 6649619f120e5c8a98c1e581a2a32e87f61269fd Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 12:47:55 -0700 Subject: [PATCH 302/833] Convert Blockly.Block from require to requireType --- core/generator.js | 2 +- tests/deps.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/generator.js b/core/generator.js index 8e71fb040..112c2f8a1 100644 --- a/core/generator.js +++ b/core/generator.js @@ -15,7 +15,7 @@ goog.module('Blockly.Generator'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const Block = goog.require('Blockly.Block'); +const Block = goog.requireType('Blockly.Block'); /* eslint-disable-next-line no-unused-vars */ const Names = goog.requireType('Blockly.Names'); /* eslint-disable-next-line no-unused-vars */ diff --git a/tests/deps.js b/tests/deps.js index c40db7cbc..94b646890 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -65,7 +65,7 @@ goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Bl goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); -goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From 35673a79e12376c4beacd1223591c230f2c3ea34 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 13:02:15 -0700 Subject: [PATCH 303/833] Remove unused Block.Block require --- core/flyout_horizontal.js | 2 -- tests/deps.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index 9bfc8aa91..7f1ad72fd 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -26,8 +26,6 @@ const registry = goog.require('Blockly.registry'); const {Position} = goog.require('Blockly.utils.toolbox'); const {getScrollDeltaPixels} = goog.require('Blockly.utils'); const {inherits} = goog.require('Blockly.utils.object'); -/** @suppress {extraRequire} */ -goog.require('Blockly.Block'); /** diff --git a/tests/deps.js b/tests/deps.js index 87600526f..a5e2310db 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -63,7 +63,7 @@ goog.addDependency('../../core/field_textinput.js', ['Blockly.FieldTextInput'], goog.addDependency('../../core/field_variable.js', ['Blockly.FieldVariable'], ['Blockly.Events.BlockChange', 'Blockly.FieldDropdown', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.Xml', 'Blockly.fieldRegistry', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_base.js', ['Blockly.Flyout'], ['Blockly.Block', 'Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.VarCreate', 'Blockly.FlyoutMetricsManager', 'Blockly.Gesture', 'Blockly.IFlyout', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Blockly.Css', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es5'}); -goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly.Block', 'Blockly.internalConstants', 'Blockly.utils.deprecation']); goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); From a5c486e5717215fa4fe83ca64988f22c4149b622 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 13:09:48 -0700 Subject: [PATCH 304/833] Made icon size field const --- core/icon.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/icon.js b/core/icon.js index b6b8942a7..69ff3ef37 100644 --- a/core/icon.js +++ b/core/icon.js @@ -53,6 +53,7 @@ Icon.prototype.collapseHidden = true; /** * Height and width of icons. + * @const */ Icon.prototype.SIZE = 17; From 808ec6a5d3c6069c28e9751e369c224df1cbfcc0 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:29:05 -0700 Subject: [PATCH 305/833] Migrate core/marker_manager.js to ES6 const/let --- core/marker_manager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 82c149052..3d3c64bbb 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -81,7 +81,7 @@ Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { * @param {string} id The ID of the marker to unregister. */ Blockly.MarkerManager.prototype.unregisterMarker = function(id) { - var marker = this.markers_[id]; + const marker = this.markers_[id]; if (marker) { marker.dispose(); delete this.markers_[id]; @@ -119,7 +119,7 @@ Blockly.MarkerManager.prototype.setCursor = function(cursor) { } this.cursor_ = cursor; if (this.cursor_) { - var drawer = this.workspace_.getRenderer() + const drawer = this.workspace_.getRenderer() .makeMarkerDrawer(this.workspace_, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); @@ -180,8 +180,8 @@ Blockly.MarkerManager.prototype.updateMarkers = function() { * @package */ Blockly.MarkerManager.prototype.dispose = function() { - var markerIds = Object.keys(this.markers_); - for (var i = 0, markerId; (markerId = markerIds[i]); i++) { + const markerIds = Object.keys(this.markers_); + for (let i = 0, markerId; (markerId = markerIds[i]); i++) { this.unregisterMarker(markerId); } this.markers_ = null; From df794d7e3a47acec6fe91ed278ea99fbcb2652ab Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:31:10 -0700 Subject: [PATCH 306/833] Migrate core/marker_manager.js to goog.module --- core/marker_manager.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 3d3c64bbb..59bc64b7a 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.MarkerManager'); +goog.module('Blockly.MarkerManager'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Cursor'); goog.require('Blockly.Marker'); @@ -24,7 +25,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.MarkerManager = function(workspace){ +const MarkerManager = function(workspace){ /** * The cursor. * @type {?Blockly.Cursor} @@ -59,14 +60,14 @@ Blockly.MarkerManager = function(workspace){ * @type {string} * @const */ -Blockly.MarkerManager.LOCAL_MARKER = 'local_marker_1'; +MarkerManager.LOCAL_MARKER = 'local_marker_1'; /** * Register the marker by adding it to the map of markers. * @param {string} id A unique identifier for the marker. * @param {!Blockly.Marker} marker The marker to register. */ -Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { +MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { this.unregisterMarker(id); } @@ -80,7 +81,7 @@ Blockly.MarkerManager.prototype.registerMarker = function(id, marker) { * Unregister the marker by removing it from the map of markers. * @param {string} id The ID of the marker to unregister. */ -Blockly.MarkerManager.prototype.unregisterMarker = function(id) { +MarkerManager.prototype.unregisterMarker = function(id) { const marker = this.markers_[id]; if (marker) { marker.dispose(); @@ -95,7 +96,7 @@ Blockly.MarkerManager.prototype.unregisterMarker = function(id) { * Get the cursor for the workspace. * @return {?Blockly.Cursor} The cursor for this workspace. */ -Blockly.MarkerManager.prototype.getCursor = function() { +MarkerManager.prototype.getCursor = function() { return this.cursor_; }; @@ -105,7 +106,7 @@ Blockly.MarkerManager.prototype.getCursor = function() { * @return {?Blockly.Marker} The marker that corresponds to the given ID, * or null if none exists. */ -Blockly.MarkerManager.prototype.getMarker = function(id) { +MarkerManager.prototype.getMarker = function(id) { return this.markers_[id] || null; }; @@ -113,7 +114,7 @@ Blockly.MarkerManager.prototype.getMarker = function(id) { * Sets the cursor and initializes the drawer for use with keyboard navigation. * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. */ -Blockly.MarkerManager.prototype.setCursor = function(cursor) { +MarkerManager.prototype.setCursor = function(cursor) { if (this.cursor_ && this.cursor_.getDrawer()) { this.cursor_.getDrawer().dispose(); } @@ -132,7 +133,7 @@ Blockly.MarkerManager.prototype.setCursor = function(cursor) { * workspace SVG group. * @package */ -Blockly.MarkerManager.prototype.setCursorSvg = function(cursorSvg) { +MarkerManager.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg_ = null; return; @@ -148,7 +149,7 @@ Blockly.MarkerManager.prototype.setCursorSvg = function(cursorSvg) { * workspace SVG group. * @package */ -Blockly.MarkerManager.prototype.setMarkerSvg = function(markerSvg) { +MarkerManager.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg_ = null; return; @@ -167,7 +168,7 @@ Blockly.MarkerManager.prototype.setMarkerSvg = function(markerSvg) { * Redraw the attached cursor SVG if needed. * @package */ -Blockly.MarkerManager.prototype.updateMarkers = function() { +MarkerManager.prototype.updateMarkers = function() { if (this.workspace_.keyboardAccessibilityMode && this.cursorSvg_) { this.workspace_.getCursor().draw(); } @@ -179,7 +180,7 @@ Blockly.MarkerManager.prototype.updateMarkers = function() { * @suppress {checkTypes} * @package */ -Blockly.MarkerManager.prototype.dispose = function() { +MarkerManager.prototype.dispose = function() { const markerIds = Object.keys(this.markers_); for (let i = 0, markerId; (markerId = markerIds[i]); i++) { this.unregisterMarker(markerId); @@ -190,3 +191,5 @@ Blockly.MarkerManager.prototype.dispose = function() { this.cursor_ = null; } }; + +exports = MarkerManager; From 608a4fd9f1906f99704751d457f578688cbf92de Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:34:01 -0700 Subject: [PATCH 307/833] Migrate core/marker_manager.js to named requires --- core/marker_manager.js | 26 ++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 59bc64b7a..b2d5c2bd5 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -13,22 +13,24 @@ goog.module('Blockly.MarkerManager'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Cursor'); -goog.require('Blockly.Marker'); - -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Cursor = goog.requireType('Blockly.Cursor'); +/* eslint-disable-next-line no-unused-vars */ +const Marker = goog.requireType('Blockly.Marker'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Class to manage the multiple markers and the cursor on a workspace. - * @param {!Blockly.WorkspaceSvg} workspace The workspace for the marker manager. + * @param {!WorkspaceSvg} workspace The workspace for the marker manager. * @constructor * @package */ const MarkerManager = function(workspace){ /** * The cursor. - * @type {?Blockly.Cursor} + * @type {?Cursor} * @private */ this.cursor_ = null; @@ -42,14 +44,14 @@ const MarkerManager = function(workspace){ /** * The map of markers for the workspace. - * @type {!Object} + * @type {!Object} * @private */ this.markers_ = Object.create(null); /** * The workspace this marker manager is associated with. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; @@ -65,7 +67,7 @@ MarkerManager.LOCAL_MARKER = 'local_marker_1'; /** * Register the marker by adding it to the map of markers. * @param {string} id A unique identifier for the marker. - * @param {!Blockly.Marker} marker The marker to register. + * @param {!Marker} marker The marker to register. */ MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { @@ -94,7 +96,7 @@ MarkerManager.prototype.unregisterMarker = function(id) { /** * Get the cursor for the workspace. - * @return {?Blockly.Cursor} The cursor for this workspace. + * @return {?Cursor} The cursor for this workspace. */ MarkerManager.prototype.getCursor = function() { return this.cursor_; @@ -103,7 +105,7 @@ MarkerManager.prototype.getCursor = function() { /** * Get a single marker that corresponds to the given ID. * @param {string} id A unique identifier for the marker. - * @return {?Blockly.Marker} The marker that corresponds to the given ID, + * @return {?Marker} The marker that corresponds to the given ID, * or null if none exists. */ MarkerManager.prototype.getMarker = function(id) { @@ -112,7 +114,7 @@ MarkerManager.prototype.getMarker = function(id) { /** * Sets the cursor and initializes the drawer for use with keyboard navigation. - * @param {Blockly.Cursor} cursor The cursor used to move around this workspace. + * @param {Cursor} cursor The cursor used to move around this workspace. */ MarkerManager.prototype.setCursor = function(cursor) { if (this.cursor_ && this.cursor_.getDrawer()) { diff --git a/tests/deps.js b/tests/deps.js index de575339f..6ed58a69c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -107,7 +107,7 @@ goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCur goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], ['Blockly.Cursor', 'Blockly.Marker']); +goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); From 126e02927f8752b9dc1c18bee9b9c4e4ab2117d8 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:34:30 -0700 Subject: [PATCH 308/833] clang-format core/marker_manager.js --- core/marker_manager.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index b2d5c2bd5..1f16f500a 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -27,7 +27,7 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -const MarkerManager = function(workspace){ +const MarkerManager = function(workspace) { /** * The cursor. * @type {?Cursor} @@ -73,8 +73,8 @@ MarkerManager.prototype.registerMarker = function(id, marker) { if (this.markers_[id]) { this.unregisterMarker(id); } - marker.setDrawer(this.workspace_.getRenderer() - .makeMarkerDrawer(this.workspace_, marker)); + marker.setDrawer( + this.workspace_.getRenderer().makeMarkerDrawer(this.workspace_, marker)); this.setMarkerSvg(marker.getDrawer().createDom()); this.markers_[id] = marker; }; @@ -89,7 +89,8 @@ MarkerManager.prototype.unregisterMarker = function(id) { marker.dispose(); delete this.markers_[id]; } else { - throw Error('Marker with ID ' + id + ' does not exist. ' + + throw Error( + 'Marker with ID ' + id + ' does not exist. ' + 'Can only unregister markers that exist.'); } }; @@ -122,8 +123,8 @@ MarkerManager.prototype.setCursor = function(cursor) { } this.cursor_ = cursor; if (this.cursor_) { - const drawer = this.workspace_.getRenderer() - .makeMarkerDrawer(this.workspace_, this.cursor_); + const drawer = this.workspace_.getRenderer().makeMarkerDrawer( + this.workspace_, this.cursor_); this.cursor_.setDrawer(drawer); this.setCursorSvg(this.cursor_.getDrawer().createDom()); } From 046636547ef5e31ea7db352509248a9ccb500fc1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:26:11 -0700 Subject: [PATCH 309/833] Change how the debug filter is created --- core/renderers/common/constants.js | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 5c73d0510..7508b6050 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -401,6 +401,14 @@ Blockly.blockRendering.ConstantProvider = function() { */ this.randomIdentifier = String(Math.random()).substring(2); + /** + * The defs tag that contains all filters and patterns for this Blockly + * instance. + * @type {SVGElement} + * @private + */ + this.defs = null; + /** * The ID of the emboss filter, or the empty string if no filter is set. * @type {string} @@ -1023,7 +1031,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - var defs = Blockly.utils.dom.createSvgElement( + this.defs = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.DEFS, {}, svg); /* @@ -1041,7 +1049,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, */ var embossFilter = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FILTER, - {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, defs); + {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); @@ -1095,7 +1103,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 - }, defs); + }, this.defs); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); @@ -1105,42 +1113,46 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; - if (Blockly.blockRendering.Debug) { + this.createDebugFilter(); +}; + +/** + * Create a filter for highlighting the currently rendering block during + * render debugging. + * @private + */ +Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = + function() { + // Only create the debug filter once. + if (!this.debugFilter_) { var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, - { + Blockly.utils.Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', y: '-30%', x: '-40%' }, - defs); + this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, { - 'result': 'outBlur' - }, debugFilter); + Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + debugFilter); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEFUNCA, - { - 'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1' - }, + {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.FEFLOOD, - { - 'flood-color': '#ff0000', - 'flood-opacity': 0.5, - 'result': 'outColor' - }, + {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, - { - 'in': 'outColor', 'in2': 'outBlur', - 'operator': 'in', 'result': 'outGlow' + Blockly.utils.Svg.FECOMPOSITE, { + 'in': 'outColor', + 'in2': 'outBlur', + 'operator': 'in', + 'result': 'outGlow' }, debugFilter); this.debugFilterId = debugFilter.id; From e9c1e67d17457111c02f3c1bc53681dafa540974 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:38:20 -0700 Subject: [PATCH 310/833] Migrate core/renderers/common/constants.js to goog.module --- core/renderers/common/constants.js | 53 ++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 7508b6050..071b21e7d 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.blockRendering.ConstantProvider'); +goog.module('Blockly.blockRendering.ConstantProvider'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); goog.require('Blockly.utils'); @@ -30,7 +31,7 @@ goog.requireType('Blockly.Theme'); * @constructor * @package */ -Blockly.blockRendering.ConstantProvider = function() { +const ConstantProvider = function() { /** * The size of an empty spacer. @@ -543,7 +544,7 @@ Blockly.blockRendering.ConstantProvider = function() { * Initialize shape objects based on the constants set in the constructor. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.init = function() { +ConstantProvider.prototype.init = function() { /** * An object containing sizing and path information about collapsed block @@ -588,7 +589,7 @@ Blockly.blockRendering.ConstantProvider.prototype.init = function() { * @param {!Blockly.Theme} theme The current workspace theme. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.setTheme = function( +ConstantProvider.prototype.setTheme = function( theme) { /** @@ -611,7 +612,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setTheme = function( * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setDynamicProperties_ = +ConstantProvider.prototype.setDynamicProperties_ = function(theme) { /* eslint-disable indent */ this.setFontConstants_(theme); @@ -626,7 +627,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setDynamicProperties_ = * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setFontConstants_ = function( +ConstantProvider.prototype.setFontConstants_ = function( theme) { this.FIELD_TEXT_FONTFAMILY = theme.fontStyle && theme.fontStyle['family'] != undefined ? @@ -652,7 +653,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setFontConstants_ = function( * @param {!Blockly.Theme} theme The current workspace theme. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.setComponentConstants_ = +ConstantProvider.prototype.setComponentConstants_ = function(theme) { /* eslint-disable indent */ this.CURSOR_COLOUR = theme.getComponentStyle('cursorColour') || @@ -675,7 +676,7 @@ Blockly.blockRendering.ConstantProvider.prototype.setComponentConstants_ = * containing the style and an autogenerated name for that style. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.getBlockStyleForColour = +ConstantProvider.prototype.getBlockStyleForColour = function(colour) { /* eslint-disable indent */ var name = 'auto_' + colour; @@ -691,7 +692,7 @@ Blockly.blockRendering.ConstantProvider.prototype.getBlockStyleForColour = * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ -Blockly.blockRendering.ConstantProvider.prototype.getBlockStyle = function( +ConstantProvider.prototype.getBlockStyle = function( blockStyleName) { return this.blockStyles[blockStyleName || ''] || (blockStyleName && blockStyleName.indexOf('auto_') == 0 ? @@ -706,7 +707,7 @@ Blockly.blockRendering.ConstantProvider.prototype.getBlockStyle = function( * given colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.createBlockStyle_ = function( +ConstantProvider.prototype.createBlockStyle_ = function( colour) { return this.validatedBlockStyle_({ 'colourPrimary': colour @@ -727,7 +728,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createBlockStyle_ = function( * required properties populated. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.validatedBlockStyle_ = +ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. @@ -756,7 +757,7 @@ Blockly.blockRendering.ConstantProvider.prototype.validatedBlockStyle_ = * @return {string} The generated secondary colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.generateSecondaryColour_ = +ConstantProvider.prototype.generateSecondaryColour_ = function(colour) { /* eslint-disable indent */ return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; @@ -768,7 +769,7 @@ Blockly.blockRendering.ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.generateTertiaryColour_ = +ConstantProvider.prototype.generateTertiaryColour_ = function(colour) { /* eslint-disable indent */ return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; @@ -780,7 +781,7 @@ Blockly.blockRendering.ConstantProvider.prototype.generateTertiaryColour_ = * Delete all DOM elements that this provider created. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { +ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { Blockly.utils.dom.removeNode(this.embossFilter_); } @@ -798,7 +799,7 @@ Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { * collapsed block indicators. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeJaggedTeeth = function() { +ConstantProvider.prototype.makeJaggedTeeth = function() { var height = this.JAGGED_TEETH_HEIGHT; var width = this.JAGGED_TEETH_WIDTH; @@ -821,7 +822,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeJaggedTeeth = function() { * start hats. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeStartHat = function() { +ConstantProvider.prototype.makeStartHat = function() { var height = this.START_HAT_HEIGHT; var width = this.START_HAT_WIDTH; @@ -844,7 +845,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeStartHat = function() { * puzzle tabs. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makePuzzleTab = function() { +ConstantProvider.prototype.makePuzzleTab = function() { var width = this.TAB_WIDTH; var height = this.TAB_HEIGHT; @@ -898,7 +899,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makePuzzleTab = function() { * notches. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeNotch = function() { +ConstantProvider.prototype.makeNotch = function() { var width = this.NOTCH_WIDTH; var height = this.NOTCH_HEIGHT; var innerWidth = 3; @@ -928,7 +929,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeNotch = function() { * inside corners. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeInsideCorners = function() { +ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, @@ -950,7 +951,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeInsideCorners = function() * outside corners. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function() { +ConstantProvider.prototype.makeOutsideCorners = function() { var radius = this.CORNER_RADIUS; /** * SVG path for drawing the rounded top-left corner. @@ -1000,7 +1001,7 @@ Blockly.blockRendering.ConstantProvider.prototype.makeOutsideCorners = function( * @return {!Object} The shape object for the connection. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( +ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { case Blockly.connectionTypes.INPUT_VALUE: @@ -1022,7 +1023,7 @@ Blockly.blockRendering.ConstantProvider.prototype.shapeFor = function( * @suppress {strictModuleDepCheck} Debug renderer only included in playground. * @package */ -Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, +ConstantProvider.prototype.createDom = function(svg, tagName, selector) { this.injectCSS_(tagName, selector); @@ -1121,7 +1122,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg, * render debugging. * @private */ -Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = +ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { @@ -1166,7 +1167,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDebugFilter = * @param {string} selector The CSS selector to use. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.injectCSS_ = function( +ConstantProvider.prototype.injectCSS_ = function( tagName, selector) { var cssArray = this.getCSS_(selector); var cssNodeId = 'blockly-renderer-style-' + tagName; @@ -1194,7 +1195,7 @@ Blockly.blockRendering.ConstantProvider.prototype.injectCSS_ = function( * @return {!Array} Array of CSS strings. * @protected */ -Blockly.blockRendering.ConstantProvider.prototype.getCSS_ = function(selector) { +ConstantProvider.prototype.getCSS_ = function(selector) { return [ /* eslint-disable indent */ // Text. @@ -1269,3 +1270,5 @@ Blockly.blockRendering.ConstantProvider.prototype.getCSS_ = function(selector) { /* eslint-enable indent */ ]; }; + +exports = ConstantProvider; diff --git a/tests/deps.js b/tests/deps.js index de575339f..14992f734 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -120,7 +120,7 @@ goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); -goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRendering.Drawer'], ['Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.utils.svgPaths'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); From 227030f451511c0eceb3bf303de25e2ad89e57ca Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:41:22 -0700 Subject: [PATCH 311/833] Migrate core/mutator.js to ES6 const/let --- core/mutator.js | 98 +++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index 2733964c7..3a87e2035 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -161,17 +161,18 @@ Blockly.Mutator.prototype.createEditor_ = function() { {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, null); // Convert the list of names into a list of XML objects for the flyout. + let quarkXml; if (this.quarkNames_.length) { - var quarkXml = Blockly.utils.xml.createElement('xml'); - for (var i = 0, quarkName; (quarkName = this.quarkNames_[i]); i++) { - var element = Blockly.utils.xml.createElement('block'); + quarkXml = Blockly.utils.xml.createElement('xml'); + for (let i = 0, quarkName; (quarkName = this.quarkNames_[i]); i++) { + const element = Blockly.utils.xml.createElement('block'); element.setAttribute('type', quarkName); quarkXml.appendChild(element); } } else { - var quarkXml = null; + quarkXml = null; } - var workspaceOptions = new Blockly.Options( + const workspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ // If you want to enable disabling, also remove the @@ -187,7 +188,7 @@ Blockly.Mutator.prototype.createEditor_ = function() { workspaceOptions.toolboxPosition = this.block_.RTL ? Blockly.utils.toolbox.Position.RIGHT : Blockly.utils.toolbox.Position.LEFT; - var hasFlyout = !!quarkXml; + const hasFlyout = !!quarkXml; if (hasFlyout) { workspaceOptions.languageTree = Blockly.utils.toolbox.convertToolboxDefToJson(quarkXml); @@ -200,9 +201,9 @@ Blockly.Mutator.prototype.createEditor_ = function() { // a top level SVG. Instead of handling scale themselves, mutators // inherit scale from the parent workspace. // To fix this, scale needs to be applied at a different level in the DOM. - var flyoutSvg = hasFlyout ? + const flyoutSvg = hasFlyout ? this.workspace_.addFlyout(Blockly.utils.Svg.G) : null; - var background = this.workspace_.createDom('blocklyMutatorBackground'); + const background = this.workspace_.createDom('blocklyMutatorBackground'); if (flyoutSvg) { // Insert the flyout after the but before the block canvas so that @@ -244,13 +245,13 @@ Blockly.Mutator.prototype.updateEditable = function() { * @private */ Blockly.Mutator.prototype.resizeBubble_ = function() { - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; - var workspaceSize = this.workspace_.getCanvas().getBBox(); - var width = workspaceSize.width + workspaceSize.x; - var height = workspaceSize.height + doubleBorderWidth * 3; - var flyout = this.workspace_.getFlyout(); + const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const workspaceSize = this.workspace_.getCanvas().getBBox(); + let width = workspaceSize.width + workspaceSize.x; + let height = workspaceSize.height + doubleBorderWidth * 3; + const flyout = this.workspace_.getFlyout(); if (flyout) { - var flyoutScrollMetrics = flyout.getWorkspace().getMetricsManager() + const flyoutScrollMetrics = flyout.getWorkspace().getMetricsManager() .getScrollMetrics(); height = Math.max(height, flyoutScrollMetrics.height + 20); width += flyout.getWidth(); @@ -276,7 +277,7 @@ Blockly.Mutator.prototype.resizeBubble_ = function() { if (this.block_.RTL) { // Scroll the workspace to always left-align. - var translation = 'translate(' + this.workspaceWidth_ + ',0)'; + const translation = 'translate(' + this.workspaceWidth_ + ',0)'; this.workspace_.getCanvas().setAttribute('transform', translation); } this.workspace_.resize(); @@ -312,27 +313,28 @@ Blockly.Mutator.prototype.setVisible = function(visible) { // Expose this mutator's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerMoveEvent(this.onBubbleMove_.bind(this)); - var tree = this.workspace_.options.languageTree; - var flyout = this.workspace_.getFlyout(); + const tree = this.workspace_.options.languageTree; + const flyout = this.workspace_.getFlyout(); if (tree) { flyout.init(this.workspace_); flyout.show(tree); } this.rootBlock_ = this.block_.decompose(this.workspace_); - var blocks = this.rootBlock_.getDescendants(false); - for (var i = 0, child; (child = blocks[i]); i++) { + const blocks = this.rootBlock_.getDescendants(false); + for (let i = 0, child; (child = blocks[i]); i++) { child.render(); } // The root block should not be draggable or deletable. this.rootBlock_.setMovable(false); this.rootBlock_.setDeletable(false); + let margin, x; if (flyout) { - var margin = flyout.CORNER_RADIUS * 2; - var x = this.rootBlock_.RTL ? flyout.getWidth() + margin : margin; + margin = flyout.CORNER_RADIUS * 2; + x = this.rootBlock_.RTL ? flyout.getWidth() + margin : margin; } else { - var margin = 16; - var x = margin; + margin = 16; + x = margin; } if (this.block_.RTL) { x = -x; @@ -340,8 +342,8 @@ Blockly.Mutator.prototype.setVisible = function(visible) { this.rootBlock_.moveBy(x, margin); // Save the initial connections, then listen for further changes. if (this.block_.saveConnections) { - var thisMutator = this; - var mutatorBlock = + const thisMutator = this; + const mutatorBlock = /** @type {{saveConnections: function(!Blockly.Block)}} */ ( this.block_); mutatorBlock.saveConnections(this.rootBlock_); @@ -385,11 +387,11 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { } if (!this.workspace_.isDragging()) { - var blocks = this.workspace_.getTopBlocks(false); - var MARGIN = 20; + const blocks = this.workspace_.getTopBlocks(false); + const MARGIN = 20; - for (var b = 0, block; (block = blocks[b]); b++) { - var blockXY = block.getRelativeToSurfaceXY(); + for (let b = 0, block; (block = blocks[b]); b++) { + const blockXY = block.getRelativeToSurfaceXY(); // Bump any block that's above the top back inside. if (blockXY.y < MARGIN) { @@ -397,8 +399,8 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { } // Bump any block overlapping the flyout back inside. if (block.RTL) { - var right = -MARGIN; - var flyout = this.workspace_.getFlyout(); + let right = -MARGIN; + const flyout = this.workspace_.getFlyout(); if (flyout) { right -= flyout.getWidth(); } @@ -414,12 +416,12 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { // When the mutator's workspace changes, update the source block. if (this.rootBlock_.workspace == this.workspace_) { Blockly.Events.setGroup(true); - var block = this.block_; - var oldMutationDom = block.mutationToDom(); - var oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); + const block = this.block_; + const oldMutationDom = block.mutationToDom(); + const oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); // Switch off rendering while the source block is rebuilt. - var savedRendered = block.rendered; + const savedRendered = block.rendered; // TODO(#4288): We should not be setting the rendered property to false. block.rendered = false; @@ -434,13 +436,13 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { block.render(); } - var newMutationDom = block.mutationToDom(); - var newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); + const newMutationDom = block.mutationToDom(); + const newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); if (oldMutation != newMutation) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( block, 'mutation', null, oldMutation, newMutation)); // Ensure that any bump is part of this mutation's event group. - var group = Blockly.Events.getGroup(); + const group = Blockly.Events.getGroup(); setTimeout(function() { Blockly.Events.setGroup(group); block.bumpNeighbours(); @@ -470,18 +472,18 @@ Blockly.Mutator.prototype.dispose = function() { * @public */ Blockly.Mutator.prototype.updateBlockStyle = function() { - var ws = this.workspace_; + const ws = this.workspace_; if (ws && ws.getAllBlocks(false)) { - var workspaceBlocks = ws.getAllBlocks(false); - for (var i = 0, block; (block = workspaceBlocks[i]); i++) { + const workspaceBlocks = ws.getAllBlocks(false); + for (let i = 0, block; (block = workspaceBlocks[i]); i++) { block.setStyle(block.getStyleName()); } - var flyout = ws.getFlyout(); + const flyout = ws.getFlyout(); if (flyout) { - var flyoutBlocks = flyout.workspace_.getAllBlocks(false); - for (var i = 0, block; (block = flyoutBlocks[i]); i++) { + const flyoutBlocks = flyout.workspace_.getAllBlocks(false); + for (let i = 0, block; (block = flyoutBlocks[i]); i++) { block.setStyle(block.getStyleName()); } } @@ -499,8 +501,8 @@ Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { if (!connectionChild || !connectionChild.getSourceBlock().workspace) { return false; // No connection or block has been deleted. } - var connectionParent = block.getInput(inputName).connection; - var currentParent = connectionChild.targetBlock(); + const connectionParent = block.getInput(inputName).connection; + const currentParent = connectionChild.targetBlock(); if ((!currentParent || currentParent == block) && connectionParent.targetConnection != connectionChild) { if (connectionParent.isConnected()) { @@ -521,9 +523,9 @@ Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { * @public */ Blockly.Mutator.findParentWs = function(workspace) { - var outerWs = null; + let outerWs = null; if (workspace && workspace.options) { - var parent = workspace.options.parentWorkspace; + const parent = workspace.options.parentWorkspace; // If we were in a flyout in a mutator, need to go up two levels to find // the actual parent. if (workspace.isFlyout) { From e843a68b4117c4d96d497d22b43ed31f80007604 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 14:43:32 -0700 Subject: [PATCH 312/833] Migrate core/mutator.js to goog.module --- core/mutator.js | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index 3a87e2035..5f1c4cfab 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Mutator'); +goog.module('Blockly.Mutator'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Bubble'); goog.require('Blockly.Events'); @@ -45,37 +46,37 @@ goog.requireType('Blockly.Workspace'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Mutator = function(quarkNames) { - Blockly.Mutator.superClass_.constructor.call(this, null); +const Mutator = function(quarkNames) { + Mutator.superClass_.constructor.call(this, null); this.quarkNames_ = quarkNames; }; -Blockly.utils.object.inherits(Blockly.Mutator, Blockly.Icon); +Blockly.utils.object.inherits(Mutator, Blockly.Icon); /** * Workspace in the mutator's bubble. * @type {?Blockly.WorkspaceSvg} * @private */ -Blockly.Mutator.prototype.workspace_ = null; +Mutator.prototype.workspace_ = null; /** * Width of workspace. * @private */ -Blockly.Mutator.prototype.workspaceWidth_ = 0; +Mutator.prototype.workspaceWidth_ = 0; /** * Height of workspace. * @private */ -Blockly.Mutator.prototype.workspaceHeight_ = 0; +Mutator.prototype.workspaceHeight_ = 0; /** * Set the block this mutator is associated with. * @param {!Blockly.BlockSvg} block The block associated with this mutator. * @package */ -Blockly.Mutator.prototype.setBlock = function(block) { +Mutator.prototype.setBlock = function(block) { this.block_ = block; }; @@ -85,7 +86,7 @@ Blockly.Mutator.prototype.setBlock = function(block) { * bubble or null if the mutator isn't open. * @package */ -Blockly.Mutator.prototype.getWorkspace = function() { +Mutator.prototype.getWorkspace = function() { return this.workspace_; }; @@ -94,7 +95,7 @@ Blockly.Mutator.prototype.getWorkspace = function() { * @param {!Element} group The icon group. * @protected */ -Blockly.Mutator.prototype.drawIcon_ = function(group) { +Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, @@ -139,7 +140,7 @@ Blockly.Mutator.prototype.drawIcon_ = function(group) { * @protected * @override */ -Blockly.Mutator.prototype.iconClick_ = function(e) { +Mutator.prototype.iconClick_ = function(e) { if (this.block_.isEditable()) { Blockly.Icon.prototype.iconClick_.call(this, e); } @@ -150,7 +151,7 @@ Blockly.Mutator.prototype.iconClick_ = function(e) { * @return {!SVGElement} The top-level node of the editor. * @private */ -Blockly.Mutator.prototype.createEditor_ = function() { +Mutator.prototype.createEditor_ = function() { /* Create the editor. Here's the markup that will be generated: [Workspace] @@ -219,8 +220,8 @@ Blockly.Mutator.prototype.createEditor_ = function() { /** * Add or remove the UI indicating if this icon may be clicked or not. */ -Blockly.Mutator.prototype.updateEditable = function() { - Blockly.Mutator.superClass_.updateEditable.call(this); +Mutator.prototype.updateEditable = function() { + Mutator.superClass_.updateEditable.call(this); if (!this.block_.isInFlyout) { if (this.block_.isEditable()) { if (this.iconGroup_) { @@ -244,7 +245,7 @@ Blockly.Mutator.prototype.updateEditable = function() { * Resize the bubble to match the size of the workspace. * @private */ -Blockly.Mutator.prototype.resizeBubble_ = function() { +Mutator.prototype.resizeBubble_ = function() { const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; const workspaceSize = this.workspace_.getCanvas().getBBox(); let width = workspaceSize.width + workspaceSize.x; @@ -287,7 +288,7 @@ Blockly.Mutator.prototype.resizeBubble_ = function() { * A method handler for when the bubble is moved. * @private */ -Blockly.Mutator.prototype.onBubbleMove_ = function() { +Mutator.prototype.onBubbleMove_ = function() { if (this.workspace_) { this.workspace_.recordDragTargets(); } @@ -297,7 +298,7 @@ Blockly.Mutator.prototype.onBubbleMove_ = function() { * Show or hide the mutator bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Mutator.prototype.setVisible = function(visible) { +Mutator.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { // No change. return; @@ -380,7 +381,7 @@ Blockly.Mutator.prototype.setVisible = function(visible) { * @param {!Blockly.Events.Abstract} e Custom data for event. * @private */ -Blockly.Mutator.prototype.workspaceChanged_ = function(e) { +Mutator.prototype.workspaceChanged_ = function(e) { if (e.isUiEvent || (e.type == Blockly.Events.CHANGE && e.element == 'disabled')) { return; @@ -462,7 +463,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { /** * Dispose of this mutator. */ -Blockly.Mutator.prototype.dispose = function() { +Mutator.prototype.dispose = function() { this.block_.mutator = null; Blockly.Icon.prototype.dispose.call(this); }; @@ -471,7 +472,7 @@ Blockly.Mutator.prototype.dispose = function() { * Update the styles on all blocks in the mutator. * @public */ -Blockly.Mutator.prototype.updateBlockStyle = function() { +Mutator.prototype.updateBlockStyle = function() { const ws = this.workspace_; if (ws && ws.getAllBlocks(false)) { @@ -497,7 +498,7 @@ Blockly.Mutator.prototype.updateBlockStyle = function() { * @param {string} inputName Name of input on parent block. * @return {boolean} True iff a reconnection was made, false otherwise. */ -Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { +Mutator.reconnect = function(connectionChild, block, inputName) { if (!connectionChild || !connectionChild.getSourceBlock().workspace) { return false; // No connection or block has been deleted. } @@ -522,7 +523,7 @@ Blockly.Mutator.reconnect = function(connectionChild, block, inputName) { * @return {?Blockly.Workspace} The mutator's parent workspace or null. * @public */ -Blockly.Mutator.findParentWs = function(workspace) { +Mutator.findParentWs = function(workspace) { let outerWs = null; if (workspace && workspace.options) { const parent = workspace.options.parentWorkspace; @@ -538,3 +539,5 @@ Blockly.Mutator.findParentWs = function(workspace) { } return outerWs; }; + +exports = Mutator; From 82c1d8c47ad70327dde017dfd1a13142109e679a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 14:48:55 -0700 Subject: [PATCH 313/833] Migrate core/renderers/common/constants.js named requires --- core/renderers/common/constants.js | 207 ++++++++++++++--------------- 1 file changed, 103 insertions(+), 104 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 071b21e7d..4f64223d7 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -13,17 +13,17 @@ goog.module('Blockly.blockRendering.ConstantProvider'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.colour'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.svgPaths'); -goog.require('Blockly.utils.userAgent'); - -goog.requireType('Blockly.blockRendering.Debug'); -goog.requireType('Blockly.RenderedConnection'); -goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const RenderedConnection = goog.requireType('Blockly.RenderedConnection'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const colour = goog.require('Blockly.utils.colour'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const dom = goog.require('Blockly.utils.dom'); +const svgPaths = goog.require('Blockly.utils.svgPaths'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utils = goog.require('Blockly.utils'); /** @@ -223,7 +223,7 @@ const ConstantProvider = function() { */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; - this.START_POINT = Blockly.utils.svgPaths.moveBy(0, 0); + this.START_POINT = svgPaths.moveBy(0, 0); /** * Height of SVG path for jagged teeth at the end of collapsed blocks. @@ -305,7 +305,7 @@ const ConstantProvider = function() { * @type {boolean} */ this.FIELD_TEXT_BASELINE_CENTER = - !Blockly.utils.userAgent.IE && !Blockly.utils.userAgent.EDGE; + !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -586,7 +586,7 @@ ConstantProvider.prototype.init = function() { /** * Refresh constants properties that depend on the theme. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @package */ ConstantProvider.prototype.setTheme = function( @@ -594,7 +594,7 @@ ConstantProvider.prototype.setTheme = function( /** * The block styles map. - * @type {Object} + * @type {Object} * @package */ this.blockStyles = Object.create(null); @@ -609,7 +609,7 @@ ConstantProvider.prototype.setTheme = function( /** * Sets dynamic properties that depend on other values or theme properties. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setDynamicProperties_ = @@ -624,7 +624,7 @@ ConstantProvider.prototype.setDynamicProperties_ = /** * Set constants related to fonts. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setFontConstants_ = function( @@ -639,7 +639,7 @@ ConstantProvider.prototype.setFontConstants_ = function( theme.fontStyle && theme.fontStyle['size'] != undefined ? theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = Blockly.utils.dom.measureFontMetrics('Hg', + var fontMetrics = dom.measureFontMetrics('Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -650,7 +650,7 @@ ConstantProvider.prototype.setFontConstants_ = function( /** * Set constants from a theme's component styles. - * @param {!Blockly.Theme} theme The current workspace theme. + * @param {!Theme} theme The current workspace theme. * @protected */ ConstantProvider.prototype.setComponentConstants_ = @@ -672,7 +672,7 @@ ConstantProvider.prototype.setComponentConstants_ = * Get or create a block style based on a single colour value. Generate a name * for the style based on the colour. * @param {string} colour #RRGGBB colour string. - * @return {{style: !Blockly.Theme.BlockStyle, name: string}} An object + * @return {{style: !Theme.BlockStyle, name: string}} An object * containing the style and an autogenerated name for that style. * @package */ @@ -689,7 +689,7 @@ ConstantProvider.prototype.getBlockStyleForColour = /** * Gets the BlockStyle for the given block style name. * @param {?string} blockStyleName The name of the block style. - * @return {!Blockly.Theme.BlockStyle} The named block style, or a default style + * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ ConstantProvider.prototype.getBlockStyle = function( @@ -703,7 +703,7 @@ ConstantProvider.prototype.getBlockStyle = function( /** * Create a block style object based on the given colour. * @param {string} colour #RRGGBB colour string. - * @return {!Blockly.Theme.BlockStyle} A populated block style based on the + * @return {!Theme.BlockStyle} A populated block style based on the * given colour. * @protected */ @@ -724,7 +724,7 @@ ConstantProvider.prototype.createBlockStyle_ = function( * hat:(string|undefined) * }} blockStyle A full or partial block style object. - * @return {!Blockly.Theme.BlockStyle} A full block style object, with all + * @return {!Theme.BlockStyle} A full block style object, with all * required properties populated. * @protected */ @@ -732,19 +732,19 @@ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { /* eslint-disable indent */ // Make a new object with all of the same properties. - var valid = /** @type {!Blockly.Theme.BlockStyle} */ ({}); + var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { - Blockly.utils.object.mixin(valid, blockStyle); + utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = Blockly.utils.parseBlockColour( + var parsedColour = utils.parseBlockColour( valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? - Blockly.utils.parseBlockColour(valid['colourSecondary']).hex : + utils.parseBlockColour(valid['colourSecondary']).hex : this.generateSecondaryColour_(valid.colourPrimary); valid.colourTertiary = valid['colourTertiary'] ? - Blockly.utils.parseBlockColour(valid['colourTertiary']).hex : + utils.parseBlockColour(valid['colourTertiary']).hex : this.generateTertiaryColour_(valid.colourPrimary); valid.hat = valid['hat'] || ''; @@ -758,9 +758,9 @@ ConstantProvider.prototype.validatedBlockStyle_ = * @protected */ ConstantProvider.prototype.generateSecondaryColour_ = - function(colour) { + function(inputColour) { /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.6) || colour; + return colour.blend('#fff', inputColour, 0.6) || inputColour; }; /* eslint-enable indent */ /** @@ -769,10 +769,9 @@ ConstantProvider.prototype.generateSecondaryColour_ = * @return {string} The generated tertiary colour. * @protected */ -ConstantProvider.prototype.generateTertiaryColour_ = - function(colour) { - /* eslint-disable indent */ - return Blockly.utils.colour.blend('#fff', colour, 0.3) || colour; +ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { + /* eslint-disable indent */ + return colour.blend('#fff', inputColour, 0.3) || inputColour; }; /* eslint-enable indent */ @@ -783,13 +782,13 @@ ConstantProvider.prototype.generateTertiaryColour_ = */ ConstantProvider.prototype.dispose = function() { if (this.embossFilter_) { - Blockly.utils.dom.removeNode(this.embossFilter_); + dom.removeNode(this.embossFilter_); } if (this.disabledPattern_) { - Blockly.utils.dom.removeNode(this.disabledPattern_); + dom.removeNode(this.disabledPattern_); } if (this.debugFilter_) { - Blockly.utils.dom.removeNode(this.debugFilter_); + dom.removeNode(this.debugFilter_); } this.cssNode_ = null; }; @@ -804,11 +803,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var width = this.JAGGED_TEETH_WIDTH; var mainPath = - Blockly.utils.svgPaths.line( + svgPaths.line( [ - Blockly.utils.svgPaths.point(width, height / 4), - Blockly.utils.svgPaths.point(-width * 2, height / 2), - Blockly.utils.svgPaths.point(width, height / 4) + svgPaths.point(width, height / 4), + svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) ]); return { height: height, @@ -827,11 +826,11 @@ ConstantProvider.prototype.makeStartHat = function() { var width = this.START_HAT_WIDTH; var mainPath = - Blockly.utils.svgPaths.curve('c', + svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(30, -height), - Blockly.utils.svgPaths.point(70, -height), - Blockly.utils.svgPaths.point(width, 0) + svgPaths.point(30, -height), + svgPaths.point(70, -height), + svgPaths.point(width, 0) ]); return { height: height, @@ -864,18 +863,18 @@ ConstantProvider.prototype.makePuzzleTab = function() { var control2Y = halfHeight + 0.5; var control3Y = overlap; // 2.5 - var endPoint1 = Blockly.utils.svgPaths.point(-width, forward * halfHeight); - var endPoint2 = Blockly.utils.svgPaths.point(width, forward * halfHeight); + var endPoint1 = svgPaths.point(-width, forward * halfHeight); + var endPoint2 = svgPaths.point(width, forward * halfHeight); - return Blockly.utils.svgPaths.curve('c', + return svgPaths.curve('c', [ - Blockly.utils.svgPaths.point(0, forward * control1Y), - Blockly.utils.svgPaths.point(-width, back * control2Y), + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 ]) + - Blockly.utils.svgPaths.curve('s', + svgPaths.curve('s', [ - Blockly.utils.svgPaths.point(width, back * control3Y), + svgPaths.point(width, back * control3Y), endPoint2 ]); } @@ -905,11 +904,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return Blockly.utils.svgPaths.line( + return svgPaths.line( [ - Blockly.utils.svgPaths.point(dir * outerWidth, height), - Blockly.utils.svgPaths.point(dir * innerWidth, 0), - Blockly.utils.svgPaths.point(dir * outerWidth, -height) + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) ]); } var pathLeft = makeMainPath(1); @@ -932,11 +931,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = Blockly.utils.svgPaths.arc('a', '0 0,0', radius, - Blockly.utils.svgPaths.point(radius, radius)); + var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, + svgPaths.point(radius, radius)); return { width: radius, @@ -958,31 +957,31 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @const */ var topLeft = - Blockly.utils.svgPaths.moveBy(0, radius) + - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, -radius)); + svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, -radius)); + var bottomLeft = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = Blockly.utils.svgPaths.arc('a', '0 0,1', radius, - Blockly.utils.svgPaths.point(-radius, radius)); + var bottomRight = svgPaths.arc('a', '0 0,1', radius, + svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -996,7 +995,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { /** * Get an object with connection shape and sizing information based on the type * of the connection. - * @param {!Blockly.RenderedConnection} connection The connection to find a + * @param {!RenderedConnection} connection The connection to find a * shape object for * @return {!Object} The shape object for the connection. * @package @@ -1004,11 +1003,11 @@ ConstantProvider.prototype.makeOutsideCorners = function() { ConstantProvider.prototype.shapeFor = function( connection) { switch (connection.type) { - case Blockly.connectionTypes.INPUT_VALUE: - case Blockly.connectionTypes.OUTPUT_VALUE: + case connectionTypes.INPUT_VALUE: + case connectionTypes.OUTPUT_VALUE: return this.PUZZLE_TAB; - case Blockly.connectionTypes.PREVIOUS_STATEMENT: - case Blockly.connectionTypes.NEXT_STATEMENT: + case connectionTypes.PREVIOUS_STATEMENT: + case connectionTypes.NEXT_STATEMENT: return this.NOTCH; default: throw Error('Unknown connection type'); @@ -1032,8 +1031,8 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement( + Svg.DEFS, {}, svg); /* @@ -1048,14 +1047,14 @@ ConstantProvider.prototype.createDom = function(svg, k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, + var embossFilter = dom.createSvgElement( + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEGAUSSIANBLUR, + dom.createSvgElement( + Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FESPECULARLIGHTING, + var feSpecularLighting = dom.createSvgElement( + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1065,19 +1064,19 @@ ConstantProvider.prototype.createDom = function(svg, 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEPOINTLIGHT, + dom.createSvgElement( + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' }, embossFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', @@ -1097,19 +1096,19 @@ ConstantProvider.prototype.createDom = function(svg, */ - var disabledPattern = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATTERN, + var disabledPattern = dom.createSvgElement( + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 }, this.defs); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1126,8 +1125,8 @@ ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FILTER, { + var debugFilter = dom.createSvgElement( + Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', @@ -1136,20 +1135,20 @@ ConstantProvider.prototype.createDebugFilter = }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, + var debugComponentTransfer = dom.createSvgElement( + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFUNCA, + dom.createSvgElement( + Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, debugComponentTransfer); // Color the highlight - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FEFLOOD, + dom.createSvgElement( + Svg.FEFLOOD, {'flood-color': '#ff0000', 'flood-opacity': 0.5, 'result': 'outColor'}, debugFilter); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FECOMPOSITE, { + dom.createSvgElement( + Svg.FECOMPOSITE, { 'in': 'outColor', 'in2': 'outBlur', 'operator': 'in', From 96ec93f91e9f2e46295e70cd72dd712c2921afb8 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Fri, 23 Jul 2021 14:52:42 -0700 Subject: [PATCH 314/833] Remove deconstructing properties and update logic (#5202) --- scripts/goog_module/convert-file.sh | 47 +++++++++-------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 8b6bdfc6f..f3138e9cf 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -163,6 +163,11 @@ step3() { continue fi + local require_name=$(echo "${require}" | perl -pe 's/(\w+\.)+(\w+)/\2/g') + inf "Updating require declaration for ${require}..." + perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" + + # Parse property access of module local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) # Detect requires overlap @@ -181,42 +186,18 @@ step3() { fi properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) - if [[ "${direct_access_count}" -eq "0" && -n "${properties_accessed}" ]]; then - local deconstructed_comma=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') - local confirm='' - while true; do - read -p "Would you like to deconstruct ${require} into \"{${deconstructed_comma}}\"? (y/n): " yn Date: Fri, 23 Jul 2021 14:59:16 -0700 Subject: [PATCH 315/833] Migrate core/mutator.js to named requires --- core/mutator.js | 142 +++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index 5f1c4cfab..ca8475cdf 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -14,47 +14,53 @@ goog.module('Blockly.Mutator'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Bubble'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Abstract = goog.requireType('Blockly.Events.Abstract'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Blockly = goog.requireType('Blockly'); +const Bubble = goog.require('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +const Icon = goog.require('Blockly.Icon'); +const Options = goog.require('Blockly.Options'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const WorkspaceSvg = goog.require('Blockly.WorkspaceSvg'); +const Xml = goog.require('Blockly.Xml'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const object = goog.require('Blockly.utils.object'); +const toolbox = goog.require('Blockly.utils.toolbox'); +const xml = goog.require('Blockly.utils.xml'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BlockChange'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); -goog.require('Blockly.Icon'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.Options'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.toolbox'); -goog.require('Blockly.utils.xml'); -goog.require('Blockly.WorkspaceSvg'); -goog.require('Blockly.Xml'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Connection'); -goog.requireType('Blockly.Events.Abstract'); -goog.requireType('Blockly.utils.Coordinate'); -goog.requireType('Blockly.Workspace'); /** * Class for a mutator dialog. * @param {!Array} quarkNames List of names of sub-blocks for flyout. - * @extends {Blockly.Icon} + * @extends {Icon} * @constructor */ const Mutator = function(quarkNames) { Mutator.superClass_.constructor.call(this, null); this.quarkNames_ = quarkNames; }; -Blockly.utils.object.inherits(Mutator, Blockly.Icon); +object.inherits(Mutator, Icon); /** * Workspace in the mutator's bubble. - * @type {?Blockly.WorkspaceSvg} + * @type {?WorkspaceSvg} * @private */ Mutator.prototype.workspace_ = null; @@ -73,7 +79,7 @@ Mutator.prototype.workspaceHeight_ = 0; /** * Set the block this mutator is associated with. - * @param {!Blockly.BlockSvg} block The block associated with this mutator. + * @param {!BlockSvg} block The block associated with this mutator. * @package */ Mutator.prototype.setBlock = function(block) { @@ -82,7 +88,7 @@ Mutator.prototype.setBlock = function(block) { /** * Returns the workspace inside this mutator icon's bubble. - * @return {?Blockly.WorkspaceSvg} The workspace inside this mutator icon's + * @return {?WorkspaceSvg} The workspace inside this mutator icon's * bubble or null if the mutator isn't open. * @package */ @@ -97,8 +103,8 @@ Mutator.prototype.getWorkspace = function() { */ Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconShape', 'rx': '4', @@ -108,8 +114,8 @@ Mutator.prototype.drawIcon_ = function(group) { }, group); // Gear teeth. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' + @@ -122,8 +128,8 @@ Mutator.prototype.drawIcon_ = function(group) { }, group); // Axle hole. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, + dom.createSvgElement( + Svg.CIRCLE, { 'class': 'blocklyIconShape', 'r': '2.7', @@ -142,7 +148,7 @@ Mutator.prototype.drawIcon_ = function(group) { */ Mutator.prototype.iconClick_ = function(e) { if (this.block_.isEditable()) { - Blockly.Icon.prototype.iconClick_.call(this, e); + Icon.prototype.iconClick_.call(this, e); } }; @@ -157,23 +163,23 @@ Mutator.prototype.createEditor_ = function() { [Workspace] */ - this.svgDialog_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.SVG, - {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH}, + this.svgDialog_ = dom.createSvgElement( + Svg.SVG, + {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); // Convert the list of names into a list of XML objects for the flyout. let quarkXml; if (this.quarkNames_.length) { - quarkXml = Blockly.utils.xml.createElement('xml'); + quarkXml = xml.createElement('xml'); for (let i = 0, quarkName; (quarkName = this.quarkNames_[i]); i++) { - const element = Blockly.utils.xml.createElement('block'); + const element = xml.createElement('block'); element.setAttribute('type', quarkName); quarkXml.appendChild(element); } } else { quarkXml = null; } - const workspaceOptions = new Blockly.Options( + const workspaceOptions = new Options( /** @type {!Blockly.BlocklyOptions} */ ({ // If you want to enable disabling, also remove the @@ -187,23 +193,23 @@ Mutator.prototype.createEditor_ = function() { 'rendererOverrides': this.block_.workspace.options.rendererOverrides })); workspaceOptions.toolboxPosition = this.block_.RTL ? - Blockly.utils.toolbox.Position.RIGHT : - Blockly.utils.toolbox.Position.LEFT; + toolbox.Position.RIGHT : + toolbox.Position.LEFT; const hasFlyout = !!quarkXml; if (hasFlyout) { workspaceOptions.languageTree = - Blockly.utils.toolbox.convertToolboxDefToJson(quarkXml); + toolbox.convertToolboxDefToJson(quarkXml); } - this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); + this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.isMutator = true; - this.workspace_.addChangeListener(Blockly.Events.disableOrphans); + this.workspace_.addChangeListener(Events.disableOrphans); // Mutator flyouts go inside the mutator workspace's rather than in // a top level SVG. Instead of handling scale themselves, mutators // inherit scale from the parent workspace. // To fix this, scale needs to be applied at a different level in the DOM. const flyoutSvg = hasFlyout ? - this.workspace_.addFlyout(Blockly.utils.Svg.G) : null; + this.workspace_.addFlyout(Svg.G) : null; const background = this.workspace_.createDom('blocklyMutatorBackground'); if (flyoutSvg) { @@ -225,7 +231,7 @@ Mutator.prototype.updateEditable = function() { if (!this.block_.isInFlyout) { if (this.block_.isEditable()) { if (this.iconGroup_) { - Blockly.utils.dom.removeClass( + dom.removeClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } @@ -233,7 +239,7 @@ Mutator.prototype.updateEditable = function() { // Close any mutator bubble. Icon is not clickable. this.setVisible(false); if (this.iconGroup_) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } @@ -246,7 +252,7 @@ Mutator.prototype.updateEditable = function() { * @private */ Mutator.prototype.resizeBubble_ = function() { - const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; const workspaceSize = this.workspace_.getCanvas().getBBox(); let width = workspaceSize.width + workspaceSize.x; let height = workspaceSize.height + doubleBorderWidth * 3; @@ -303,14 +309,14 @@ Mutator.prototype.setVisible = function(visible) { // No change. return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + Events.fire(new (Events.get(Events.BUBBLE_OPEN))( this.block_, visible, 'mutator')); if (visible) { // Create the bubble. - this.bubble_ = new Blockly.Bubble( - /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), + this.bubble_ = new Bubble( + /** @type {!WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.pathObject.svgPath, - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_), null, null); + /** @type {!Coordinate} */ (this.iconXY_), null, null); // Expose this mutator's block's ID on its top-level SVG group. this.bubble_.setSvgId(this.block_.id); this.bubble_.registerMoveEvent(this.onBubbleMove_.bind(this)); @@ -345,7 +351,7 @@ Mutator.prototype.setVisible = function(visible) { if (this.block_.saveConnections) { const thisMutator = this; const mutatorBlock = - /** @type {{saveConnections: function(!Blockly.Block)}} */ ( + /** @type {{saveConnections: function(!Block)}} */ ( this.block_); mutatorBlock.saveConnections(this.rootBlock_); this.sourceListener_ = function() { @@ -378,12 +384,12 @@ Mutator.prototype.setVisible = function(visible) { * Update the source block when the mutator's blocks are changed. * Bump down any block that's too high. * Fired whenever a change is made to the mutator's workspace. - * @param {!Blockly.Events.Abstract} e Custom data for event. + * @param {!Abstract} e Custom data for event. * @private */ Mutator.prototype.workspaceChanged_ = function(e) { if (e.isUiEvent || - (e.type == Blockly.Events.CHANGE && e.element == 'disabled')) { + (e.type == Events.CHANGE && e.element == 'disabled')) { return; } @@ -416,10 +422,10 @@ Mutator.prototype.workspaceChanged_ = function(e) { // When the mutator's workspace changes, update the source block. if (this.rootBlock_.workspace == this.workspace_) { - Blockly.Events.setGroup(true); + Events.setGroup(true); const block = this.block_; const oldMutationDom = block.mutationToDom(); - const oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); + const oldMutation = oldMutationDom && Xml.domToText(oldMutationDom); // Switch off rendering while the source block is rebuilt. const savedRendered = block.rendered; @@ -438,17 +444,17 @@ Mutator.prototype.workspaceChanged_ = function(e) { } const newMutationDom = block.mutationToDom(); - const newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); + const newMutation = newMutationDom && Xml.domToText(newMutationDom); if (oldMutation != newMutation) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CHANGE))( + Events.fire(new (Events.get(Events.BLOCK_CHANGE))( block, 'mutation', null, oldMutation, newMutation)); // Ensure that any bump is part of this mutation's event group. - const group = Blockly.Events.getGroup(); + const group = Events.getGroup(); setTimeout(function() { - Blockly.Events.setGroup(group); + Events.setGroup(group); block.bumpNeighbours(); - Blockly.Events.setGroup(false); - }, Blockly.internalConstants.BUMP_DELAY); + Events.setGroup(false); + }, internalConstants.BUMP_DELAY); } // Don't update the bubble until the drag has ended, to avoid moving blocks @@ -456,7 +462,7 @@ Mutator.prototype.workspaceChanged_ = function(e) { if (!this.workspace_.isDragging()) { this.resizeBubble_(); } - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; @@ -465,7 +471,7 @@ Mutator.prototype.workspaceChanged_ = function(e) { */ Mutator.prototype.dispose = function() { this.block_.mutator = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; /** @@ -493,8 +499,8 @@ Mutator.prototype.updateBlockStyle = function() { /** * Reconnect an block to a mutated input. - * @param {Blockly.Connection} connectionChild Connection on child block. - * @param {!Blockly.Block} block Parent block. + * @param {Connection} connectionChild Connection on child block. + * @param {!Block} block Parent block. * @param {string} inputName Name of input on parent block. * @return {boolean} True iff a reconnection was made, false otherwise. */ @@ -519,8 +525,8 @@ Mutator.reconnect = function(connectionChild, block, inputName) { /** * Get the parent workspace of a workspace that is inside a mutator, taking into * account whether it is a flyout. - * @param {Blockly.Workspace} workspace The workspace that is inside a mutator. - * @return {?Blockly.Workspace} The mutator's parent workspace or null. + * @param {Workspace} workspace The workspace that is inside a mutator. + * @return {?Workspace} The mutator's parent workspace or null. * @public */ Mutator.findParentWs = function(workspace) { diff --git a/tests/deps.js b/tests/deps.js index de575339f..de6795326 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -112,7 +112,7 @@ goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEven goog.addDependency('../../core/menuitem.js', ['Blockly.MenuItem'], ['Blockly.utils.IdGenerator', 'Blockly.utils.aria', 'Blockly.utils.dom']); goog.addDependency('../../core/metrics_manager.js', ['Blockly.FlyoutMetricsManager', 'Blockly.MetricsManager'], ['Blockly.IMetricsManager', 'Blockly.registry', 'Blockly.utils.Size', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/msg.js', ['Blockly.Msg'], ['Blockly.utils.global']); -goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml']); +goog.addDependency('../../core/mutator.js', ['Blockly.Mutator'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Options', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Blockly.internalConstants']); goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); From e7feef669ebe281630c1cd16e8d1bf7c9ef011a5 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 23 Jul 2021 15:00:09 -0700 Subject: [PATCH 316/833] clang-format core/mutator.js --- core/mutator.js | 55 ++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/core/mutator.js b/core/mutator.js index ca8475cdf..8f9bab118 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -104,8 +104,7 @@ Mutator.prototype.getWorkspace = function() { Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconShape', 'rx': '4', 'ry': '4', @@ -115,28 +114,21 @@ Mutator.prototype.drawIcon_ = function(group) { group); // Gear teeth. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' + - '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' + - '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' + - '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' + - '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' + - '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' + - '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z' + '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' + + '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' + + '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' + + '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' + + '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' + + '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z' }, group); // Axle hole. dom.createSvgElement( Svg.CIRCLE, - { - 'class': 'blocklyIconShape', - 'r': '2.7', - 'cx': '8', - 'cy': '8' - }, - group); + {'class': 'blocklyIconShape', 'r': '2.7', 'cx': '8', 'cy': '8'}, group); }; /** @@ -164,9 +156,7 @@ Mutator.prototype.createEditor_ = function() { */ this.svgDialog_ = dom.createSvgElement( - Svg.SVG, - {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, - null); + Svg.SVG, {'x': Bubble.BORDER_WIDTH, 'y': Bubble.BORDER_WIDTH}, null); // Convert the list of names into a list of XML objects for the flyout. let quarkXml; if (this.quarkNames_.length) { @@ -192,13 +182,11 @@ Mutator.prototype.createEditor_ = function() { 'renderer': this.block_.workspace.options.renderer, 'rendererOverrides': this.block_.workspace.options.rendererOverrides })); - workspaceOptions.toolboxPosition = this.block_.RTL ? - toolbox.Position.RIGHT : - toolbox.Position.LEFT; + workspaceOptions.toolboxPosition = + this.block_.RTL ? toolbox.Position.RIGHT : toolbox.Position.LEFT; const hasFlyout = !!quarkXml; if (hasFlyout) { - workspaceOptions.languageTree = - toolbox.convertToolboxDefToJson(quarkXml); + workspaceOptions.languageTree = toolbox.convertToolboxDefToJson(quarkXml); } this.workspace_ = new WorkspaceSvg(workspaceOptions); this.workspace_.isMutator = true; @@ -208,8 +196,7 @@ Mutator.prototype.createEditor_ = function() { // a top level SVG. Instead of handling scale themselves, mutators // inherit scale from the parent workspace. // To fix this, scale needs to be applied at a different level in the DOM. - const flyoutSvg = hasFlyout ? - this.workspace_.addFlyout(Svg.G) : null; + const flyoutSvg = hasFlyout ? this.workspace_.addFlyout(Svg.G) : null; const background = this.workspace_.createDom('blocklyMutatorBackground'); if (flyoutSvg) { @@ -258,8 +245,8 @@ Mutator.prototype.resizeBubble_ = function() { let height = workspaceSize.height + doubleBorderWidth * 3; const flyout = this.workspace_.getFlyout(); if (flyout) { - const flyoutScrollMetrics = flyout.getWorkspace().getMetricsManager() - .getScrollMetrics(); + const flyoutScrollMetrics = + flyout.getWorkspace().getMetricsManager().getScrollMetrics(); height = Math.max(height, flyoutScrollMetrics.height + 20); width += flyout.getWidth(); } @@ -309,8 +296,8 @@ Mutator.prototype.setVisible = function(visible) { // No change. return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'mutator')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'mutator')); if (visible) { // Create the bubble. this.bubble_ = new Bubble( @@ -351,8 +338,7 @@ Mutator.prototype.setVisible = function(visible) { if (this.block_.saveConnections) { const thisMutator = this; const mutatorBlock = - /** @type {{saveConnections: function(!Block)}} */ ( - this.block_); + /** @type {{saveConnections: function(!Block)}} */ (this.block_); mutatorBlock.saveConnections(this.rootBlock_); this.sourceListener_ = function() { mutatorBlock.saveConnections(thisMutator.rootBlock_); @@ -388,8 +374,7 @@ Mutator.prototype.setVisible = function(visible) { * @private */ Mutator.prototype.workspaceChanged_ = function(e) { - if (e.isUiEvent || - (e.type == Events.CHANGE && e.element == 'disabled')) { + if (e.isUiEvent || (e.type == Events.CHANGE && e.element == 'disabled')) { return; } From 4aef7e3bcdc78d8f09c44253d48a3a5cfcd238ef Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 15:00:14 -0700 Subject: [PATCH 317/833] clang-format core/renderers/common/constants.js --- core/renderers/common/constants.js | 286 ++++++++++++----------------- 1 file changed, 118 insertions(+), 168 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 4f64223d7..5fdacc2ea 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -32,7 +32,6 @@ const utils = goog.require('Blockly.utils'); * @package */ const ConstantProvider = function() { - /** * The size of an empty spacer. * @type {number} @@ -215,10 +214,10 @@ const ConstantProvider = function() { this.EXTERNAL_VALUE_INPUT_PADDING = 2; /** - * The height of an empty statement input. Note that in the old rendering this - * varies slightly depending on whether the block has external or inline inputs. - * In the new rendering this is consistent. It seems unlikely that the old - * behaviour was intentional. + * The height of an empty statement input. Note that in the old rendering + * this varies slightly depending on whether the block has external or inline + * inputs. In the new rendering this is consistent. It seems unlikely that + * the old behaviour was intentional. * @type {number} */ this.EMPTY_STATEMENT_INPUT_HEIGHT = this.MIN_BLOCK_HEIGHT; @@ -304,8 +303,7 @@ const ConstantProvider = function() { * A field's text element's dominant baseline. * @type {boolean} */ - this.FIELD_TEXT_BASELINE_CENTER = - !userAgent.IE && !userAgent.EDGE; + this.FIELD_TEXT_BASELINE_CENTER = !userAgent.IE && !userAgent.EDGE; /** * A dropdown field's border rect height. @@ -350,17 +348,17 @@ const ConstantProvider = function() { * @type {string} */ this.FIELD_DROPDOWN_SVG_ARROW_DATAURI = - 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + - 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + - 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + - 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + - 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + - 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + - 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + - 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + - 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + - 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + - 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; + 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllci' + + 'AxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaG' + + 'VpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLW' + + 'Fycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuND' + + 'EsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTD' + + 'AuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNz' + + 'FDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMC' + + 'wxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNz' + + 'lhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYz' + + 'AuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMz' + + 'dBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4='; /** * Whether or not to show a box shadow around the widget div. This is only a @@ -534,10 +532,7 @@ const ConstantProvider = function() { * Enum for connection shapes. * @enum {number} */ - this.SHAPES = { - PUZZLE: 1, - NOTCH: 2 - }; + this.SHAPES = {PUZZLE: 1, NOTCH: 2}; }; /** @@ -545,7 +540,6 @@ const ConstantProvider = function() { * @package */ ConstantProvider.prototype.init = function() { - /** * An object containing sizing and path information about collapsed block * indicators. @@ -589,9 +583,7 @@ ConstantProvider.prototype.init = function() { * @param {!Theme} theme The current workspace theme. * @package */ -ConstantProvider.prototype.setTheme = function( - theme) { - +ConstantProvider.prototype.setTheme = function(theme) { /** * The block styles map. * @type {Object} @@ -612,36 +604,35 @@ ConstantProvider.prototype.setTheme = function( * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setDynamicProperties_ = - function(theme) { - /* eslint-disable indent */ +ConstantProvider.prototype.setDynamicProperties_ = function(theme) { this.setFontConstants_(theme); this.setComponentConstants_(theme); - this.ADD_START_HATS = theme.startHats != null ? theme.startHats : - this.ADD_START_HATS; -}; /* eslint-enable indent */ + this.ADD_START_HATS = + theme.startHats != null ? theme.startHats : this.ADD_START_HATS; +}; /** * Set constants related to fonts. * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setFontConstants_ = function( - theme) { +ConstantProvider.prototype.setFontConstants_ = function(theme) { this.FIELD_TEXT_FONTFAMILY = theme.fontStyle && theme.fontStyle['family'] != undefined ? - theme.fontStyle['family'] : this.FIELD_TEXT_FONTFAMILY; + theme.fontStyle['family'] : + this.FIELD_TEXT_FONTFAMILY; this.FIELD_TEXT_FONTWEIGHT = theme.fontStyle && theme.fontStyle['weight'] != undefined ? - theme.fontStyle['weight'] : this.FIELD_TEXT_FONTWEIGHT; + theme.fontStyle['weight'] : + this.FIELD_TEXT_FONTWEIGHT; this.FIELD_TEXT_FONTSIZE = theme.fontStyle && theme.fontStyle['size'] != undefined ? - theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; + theme.fontStyle['size'] : + this.FIELD_TEXT_FONTSIZE; - var fontMetrics = dom.measureFontMetrics('Hg', - this.FIELD_TEXT_FONTSIZE + 'pt', - this.FIELD_TEXT_FONTWEIGHT, + var fontMetrics = dom.measureFontMetrics( + 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); this.FIELD_TEXT_HEIGHT = fontMetrics.height; @@ -653,20 +644,18 @@ ConstantProvider.prototype.setFontConstants_ = function( * @param {!Theme} theme The current workspace theme. * @protected */ -ConstantProvider.prototype.setComponentConstants_ = - function(theme) { - /* eslint-disable indent */ - this.CURSOR_COLOUR = theme.getComponentStyle('cursorColour') || - this.CURSOR_COLOUR; - this.MARKER_COLOUR = theme.getComponentStyle('markerColour') || - this.MARKER_COLOUR; +ConstantProvider.prototype.setComponentConstants_ = function(theme) { + this.CURSOR_COLOUR = + theme.getComponentStyle('cursorColour') || this.CURSOR_COLOUR; + this.MARKER_COLOUR = + theme.getComponentStyle('markerColour') || this.MARKER_COLOUR; this.INSERTION_MARKER_COLOUR = - theme.getComponentStyle('insertionMarkerColour') || - this.INSERTION_MARKER_COLOUR; + theme.getComponentStyle('insertionMarkerColour') || + this.INSERTION_MARKER_COLOUR; this.INSERTION_MARKER_OPACITY = - Number(theme.getComponentStyle('insertionMarkerOpacity')) || - this.INSERTION_MARKER_OPACITY; -}; /* eslint-enable indent */ + Number(theme.getComponentStyle('insertionMarkerOpacity')) || + this.INSERTION_MARKER_OPACITY; +}; /** * Get or create a block style based on a single colour value. Generate a name @@ -676,15 +665,13 @@ ConstantProvider.prototype.setComponentConstants_ = * containing the style and an autogenerated name for that style. * @package */ -ConstantProvider.prototype.getBlockStyleForColour = - function(colour) { - /* eslint-disable indent */ +ConstantProvider.prototype.getBlockStyleForColour = function(colour) { var name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } return {style: this.blockStyles[name], name: name}; -}; /* eslint-enable indent */ +}; /** * Gets the BlockStyle for the given block style name. @@ -692,12 +679,11 @@ ConstantProvider.prototype.getBlockStyleForColour = * @return {!Theme.BlockStyle} The named block style, or a default style * if no style with the given name was found. */ -ConstantProvider.prototype.getBlockStyle = function( - blockStyleName) { +ConstantProvider.prototype.getBlockStyle = function(blockStyleName) { return this.blockStyles[blockStyleName || ''] || (blockStyleName && blockStyleName.indexOf('auto_') == 0 ? - this.getBlockStyleForColour(blockStyleName.substring(5)).style : - this.createBlockStyle_('#000000')); + this.getBlockStyleForColour(blockStyleName.substring(5)).style : + this.createBlockStyle_('#000000')); }; /** @@ -707,11 +693,8 @@ ConstantProvider.prototype.getBlockStyle = function( * given colour. * @protected */ -ConstantProvider.prototype.createBlockStyle_ = function( - colour) { - return this.validatedBlockStyle_({ - 'colourPrimary': colour - }); +ConstantProvider.prototype.createBlockStyle_ = function(colour) { + return this.validatedBlockStyle_({'colourPrimary': colour}); }; /** @@ -728,17 +711,14 @@ ConstantProvider.prototype.createBlockStyle_ = function( * required properties populated. * @protected */ -ConstantProvider.prototype.validatedBlockStyle_ = - function(blockStyle) { - /* eslint-disable indent */ +ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { // Make a new object with all of the same properties. var valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = utils.parseBlockColour( - valid['colourPrimary'] || '#000'); + var parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? utils.parseBlockColour(valid['colourSecondary']).hex : @@ -749,30 +729,27 @@ ConstantProvider.prototype.validatedBlockStyle_ = valid.hat = valid['hat'] || ''; return valid; -}; /* eslint-enable indent */ +}; /** * Generate a secondary colour from the passed in primary colour. - * @param {string} colour Primary colour. + * @param {string} inputColour Primary colour. * @return {string} The generated secondary colour. * @protected */ -ConstantProvider.prototype.generateSecondaryColour_ = - function(inputColour) { - /* eslint-disable indent */ - return colour.blend('#fff', inputColour, 0.6) || inputColour; -}; /* eslint-enable indent */ +ConstantProvider.prototype.generateSecondaryColour_ = function(inputColour) { + return colour.blend('#fff', inputColour, 0.6) || inputColour; +}; /** * Generate a tertiary colour from the passed in primary colour. - * @param {string} colour Primary colour. + * @param {string} inputColour Primary colour. * @return {string} The generated tertiary colour. * @protected */ ConstantProvider.prototype.generateTertiaryColour_ = function(inputColour) { - /* eslint-disable indent */ return colour.blend('#fff', inputColour, 0.3) || inputColour; -}; /* eslint-enable indent */ +}; /** @@ -802,18 +779,11 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { var height = this.JAGGED_TEETH_HEIGHT; var width = this.JAGGED_TEETH_WIDTH; - var mainPath = - svgPaths.line( - [ - svgPaths.point(width, height / 4), - svgPaths.point(-width * 2, height / 2), - svgPaths.point(width, height / 4) - ]); - return { - height: height, - width: width, - path: mainPath - }; + var mainPath = svgPaths.line([ + svgPaths.point(width, height / 4), svgPaths.point(-width * 2, height / 2), + svgPaths.point(width, height / 4) + ]); + return {height: height, width: width, path: mainPath}; }; /** @@ -825,18 +795,11 @@ ConstantProvider.prototype.makeStartHat = function() { var height = this.START_HAT_HEIGHT; var width = this.START_HAT_WIDTH; - var mainPath = - svgPaths.curve('c', - [ - svgPaths.point(30, -height), - svgPaths.point(70, -height), - svgPaths.point(width, 0) - ]); - return { - height: height, - width: width, - path: mainPath - }; + var mainPath = svgPaths.curve('c', [ + svgPaths.point(30, -height), svgPaths.point(70, -height), + svgPaths.point(width, 0) + ]); + return {height: height, width: width, path: mainPath}; }; /** @@ -866,17 +829,14 @@ ConstantProvider.prototype.makePuzzleTab = function() { var endPoint1 = svgPaths.point(-width, forward * halfHeight); var endPoint2 = svgPaths.point(width, forward * halfHeight); - return svgPaths.curve('c', - [ - svgPaths.point(0, forward * control1Y), - svgPaths.point(-width, back * control2Y), - endPoint1 - ]) + - svgPaths.curve('s', - [ - svgPaths.point(width, back * control3Y), - endPoint2 - ]); + return svgPaths.curve( + 'c', + [ + svgPaths.point(0, forward * control1Y), + svgPaths.point(-width, back * control2Y), endPoint1 + ]) + + svgPaths.curve( + 's', [svgPaths.point(width, back * control3Y), endPoint2]); } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 @@ -904,12 +864,11 @@ ConstantProvider.prototype.makeNotch = function() { var innerWidth = 3; var outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { - return svgPaths.line( - [ - svgPaths.point(dir * outerWidth, height), - svgPaths.point(dir * innerWidth, 0), - svgPaths.point(dir * outerWidth, -height) - ]); + return svgPaths.line([ + svgPaths.point(dir * outerWidth, height), + svgPaths.point(dir * innerWidth, 0), + svgPaths.point(dir * outerWidth, -height) + ]); } var pathLeft = makeMainPath(1); var pathRight = makeMainPath(-1); @@ -931,11 +890,11 @@ ConstantProvider.prototype.makeNotch = function() { ConstantProvider.prototype.makeInsideCorners = function() { var radius = this.CORNER_RADIUS; - var innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, - svgPaths.point(-radius, radius)); + var innerTopLeftCorner = + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, - svgPaths.point(radius, radius)); + var innerBottomLeftCorner = + svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { width: radius, @@ -956,32 +915,29 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * SVG path for drawing the rounded top-left corner. * @const */ - var topLeft = - svgPaths.moveBy(0, radius) + - svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(radius, -radius)); + var topLeft = svgPaths.moveBy(0, radius) + + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ var topRight = - svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(radius, radius)); + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(-radius, -radius)); + var bottomLeft = + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = svgPaths.arc('a', '0 0,1', radius, - svgPaths.point(-radius, radius)); + var bottomRight = + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { topLeft: topLeft, @@ -1000,8 +956,7 @@ ConstantProvider.prototype.makeOutsideCorners = function() { * @return {!Object} The shape object for the connection. * @package */ -ConstantProvider.prototype.shapeFor = function( - connection) { +ConstantProvider.prototype.shapeFor = function(connection) { switch (connection.type) { case connectionTypes.INPUT_VALUE: case connectionTypes.OUTPUT_VALUE: @@ -1022,8 +977,7 @@ ConstantProvider.prototype.shapeFor = function( * @suppress {strictModuleDepCheck} Debug renderer only included in playground. * @package */ -ConstantProvider.prototype.createDom = function(svg, - tagName, selector) { +ConstantProvider.prototype.createDom = function(svg, tagName, selector) { this.injectCSS_(tagName, selector); /* @@ -1031,8 +985,7 @@ ConstantProvider.prototype.createDom = function(svg, ... filters go here ... */ - this.defs = dom.createSvgElement( - Svg.DEFS, {}, svg); + this.defs = dom.createSvgElement(Svg.DEFS, {}, svg); /* @@ -1048,14 +1001,13 @@ ConstantProvider.prototype.createDom = function(svg, */ var embossFilter = dom.createSvgElement( - Svg.FILTER, - {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); + Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, + this.defs); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); var feSpecularLighting = dom.createSvgElement( - Svg.FESPECULARLIGHTING, - { + Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, 'specularConstant': 0.5, @@ -1065,19 +1017,18 @@ ConstantProvider.prototype.createDom = function(svg, }, embossFilter); dom.createSvgElement( - Svg.FEPOINTLIGHT, - {'x': -5000, 'y': -10000, 'z': 20000}, feSpecularLighting); + Svg.FEPOINTLIGHT, {'x': -5000, 'y': -10000, 'z': 20000}, + feSpecularLighting); dom.createSvgElement( - Svg.FECOMPOSITE, - { + Svg.FECOMPOSITE, { 'in': 'specOut', 'in2': 'SourceAlpha', 'operator': 'in', 'result': 'specOut' - }, embossFilter); + }, + embossFilter); dom.createSvgElement( - Svg.FECOMPOSITE, - { + Svg.FECOMPOSITE, { 'in': 'SourceGraphic', 'in2': 'specOut', 'operator': 'arithmetic', @@ -1085,7 +1036,8 @@ ConstantProvider.prototype.createDom = function(svg, 'k2': 1, 'k3': 1, 'k4': 0 - }, embossFilter); + }, + embossFilter); this.embossFilterId = embossFilter.id; this.embossFilter_ = embossFilter; @@ -1097,19 +1049,18 @@ ConstantProvider.prototype.createDom = function(svg, */ var disabledPattern = dom.createSvgElement( - Svg.PATTERN, - { + Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', 'width': 10, 'height': 10 - }, this.defs); + }, + this.defs); dom.createSvgElement( - Svg.RECT, - {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); + Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( - Svg.PATH, - {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, disabledPattern); + Svg.PATH, {'d': 'M 0 0 L 10 10 M 10 0 L 0 10', 'stroke': '#cc0'}, + disabledPattern); this.disabledPatternId = disabledPattern.id; this.disabledPattern_ = disabledPattern; @@ -1121,8 +1072,7 @@ ConstantProvider.prototype.createDom = function(svg, * render debugging. * @private */ -ConstantProvider.prototype.createDebugFilter = - function() { +ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { var debugFilter = dom.createSvgElement( @@ -1136,8 +1086,7 @@ ConstantProvider.prototype.createDebugFilter = this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood var debugComponentTransfer = dom.createSvgElement( - Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, - debugFilter); + Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( Svg.FEFUNCA, {'type': 'table', 'tableValues': '0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'}, @@ -1166,12 +1115,11 @@ ConstantProvider.prototype.createDebugFilter = * @param {string} selector The CSS selector to use. * @protected */ -ConstantProvider.prototype.injectCSS_ = function( - tagName, selector) { +ConstantProvider.prototype.injectCSS_ = function(tagName, selector) { var cssArray = this.getCSS_(selector); var cssNodeId = 'blockly-renderer-style-' + tagName; this.cssNode_ = - /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); + /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); var text = cssArray.join('\n'); if (this.cssNode_) { // Already injected, update if the theme changed. @@ -1180,7 +1128,7 @@ ConstantProvider.prototype.injectCSS_ = function( } // Inject CSS tag at start of head. var cssNode = - /** @type {!HTMLStyleElement} */ (document.createElement('style')); + /** @type {!HTMLStyleElement} */ (document.createElement('style')); cssNode.id = cssNodeId; var cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); @@ -1197,6 +1145,7 @@ ConstantProvider.prototype.injectCSS_ = function( ConstantProvider.prototype.getCSS_ = function(selector) { return [ /* eslint-disable indent */ + /* clang-format off */ // Text. selector + ' .blocklyText, ', selector + ' .blocklyFlyoutLabelText {', @@ -1266,6 +1215,7 @@ ConstantProvider.prototype.getCSS_ = function(selector) { 'fill-opacity: ' + this.INSERTION_MARKER_OPACITY + ';', 'stroke: none;', '}', + /* clang-format on */ /* eslint-enable indent */ ]; }; From a392696c7a633f0e4d88fa2db42977ca39ce413b Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 15:07:30 -0700 Subject: [PATCH 318/833] Convert core/renderers/common/constants.js to const/let --- core/renderers/common/constants.js | 98 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 5fdacc2ea..6847aea22 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -591,8 +591,8 @@ ConstantProvider.prototype.setTheme = function(theme) { */ this.blockStyles = Object.create(null); - var blockStyles = theme.blockStyles; - for (var key in blockStyles) { + const blockStyles = theme.blockStyles; + for (const key in blockStyles) { this.blockStyles[key] = this.validatedBlockStyle_(blockStyles[key]); } @@ -631,7 +631,7 @@ ConstantProvider.prototype.setFontConstants_ = function(theme) { theme.fontStyle['size'] : this.FIELD_TEXT_FONTSIZE; - var fontMetrics = dom.measureFontMetrics( + const fontMetrics = dom.measureFontMetrics( 'Hg', this.FIELD_TEXT_FONTSIZE + 'pt', this.FIELD_TEXT_FONTWEIGHT, this.FIELD_TEXT_FONTFAMILY); @@ -666,7 +666,7 @@ ConstantProvider.prototype.setComponentConstants_ = function(theme) { * @package */ ConstantProvider.prototype.getBlockStyleForColour = function(colour) { - var name = 'auto_' + colour; + const name = 'auto_' + colour; if (!this.blockStyles[name]) { this.blockStyles[name] = this.createBlockStyle_(colour); } @@ -713,12 +713,12 @@ ConstantProvider.prototype.createBlockStyle_ = function(colour) { */ ConstantProvider.prototype.validatedBlockStyle_ = function(blockStyle) { // Make a new object with all of the same properties. - var valid = /** @type {!Theme.BlockStyle} */ ({}); + const valid = /** @type {!Theme.BlockStyle} */ ({}); if (blockStyle) { utils.object.mixin(valid, blockStyle); } // Validate required properties. - var parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); + const parsedColour = utils.parseBlockColour(valid['colourPrimary'] || '#000'); valid.colourPrimary = parsedColour.hex; valid.colourSecondary = valid['colourSecondary'] ? utils.parseBlockColour(valid['colourSecondary']).hex : @@ -776,10 +776,10 @@ ConstantProvider.prototype.dispose = function() { * @package */ ConstantProvider.prototype.makeJaggedTeeth = function() { - var height = this.JAGGED_TEETH_HEIGHT; - var width = this.JAGGED_TEETH_WIDTH; + const height = this.JAGGED_TEETH_HEIGHT; + const width = this.JAGGED_TEETH_WIDTH; - var mainPath = svgPaths.line([ + const mainPath = svgPaths.line([ svgPaths.point(width, height / 4), svgPaths.point(-width * 2, height / 2), svgPaths.point(width, height / 4) ]); @@ -792,10 +792,10 @@ ConstantProvider.prototype.makeJaggedTeeth = function() { * @package */ ConstantProvider.prototype.makeStartHat = function() { - var height = this.START_HAT_HEIGHT; - var width = this.START_HAT_WIDTH; + const height = this.START_HAT_HEIGHT; + const width = this.START_HAT_WIDTH; - var mainPath = svgPaths.curve('c', [ + const mainPath = svgPaths.curve('c', [ svgPaths.point(30, -height), svgPaths.point(70, -height), svgPaths.point(width, 0) ]); @@ -808,8 +808,8 @@ ConstantProvider.prototype.makeStartHat = function() { * @package */ ConstantProvider.prototype.makePuzzleTab = function() { - var width = this.TAB_WIDTH; - var height = this.TAB_HEIGHT; + const width = this.TAB_WIDTH; + const height = this.TAB_HEIGHT; // The main path for the puzzle tab is made out of a few curves (c and s). // Those curves are defined with relative positions. The 'up' and 'down' @@ -817,17 +817,17 @@ ConstantProvider.prototype.makePuzzleTab = function() { // are the signs to use to move the cursor in the direction that the path is // being drawn. function makeMainPath(up) { - var forward = up ? -1 : 1; - var back = -forward; + const forward = up ? -1 : 1; + const back = -forward; - var overlap = 2.5; - var halfHeight = height / 2; - var control1Y = halfHeight + overlap; - var control2Y = halfHeight + 0.5; - var control3Y = overlap; // 2.5 + const overlap = 2.5; + const halfHeight = height / 2; + const control1Y = halfHeight + overlap; + const control2Y = halfHeight + 0.5; + const control3Y = overlap; // 2.5 - var endPoint1 = svgPaths.point(-width, forward * halfHeight); - var endPoint2 = svgPaths.point(width, forward * halfHeight); + const endPoint1 = svgPaths.point(-width, forward * halfHeight); + const endPoint2 = svgPaths.point(width, forward * halfHeight); return svgPaths.curve( 'c', @@ -840,9 +840,9 @@ ConstantProvider.prototype.makePuzzleTab = function() { } // c 0,-10 -8,8 -8,-7.5 s 8,2.5 8,-7.5 - var pathUp = makeMainPath(true); + const pathUp = makeMainPath(true); // c 0,10 -8,-8 -8,7.5 s 8,-2.5 8,7.5 - var pathDown = makeMainPath(false); + const pathDown = makeMainPath(false); return { type: this.SHAPES.PUZZLE, @@ -859,10 +859,10 @@ ConstantProvider.prototype.makePuzzleTab = function() { * @package */ ConstantProvider.prototype.makeNotch = function() { - var width = this.NOTCH_WIDTH; - var height = this.NOTCH_HEIGHT; - var innerWidth = 3; - var outerWidth = (width - innerWidth) / 2; + const width = this.NOTCH_WIDTH; + const height = this.NOTCH_HEIGHT; + const innerWidth = 3; + const outerWidth = (width - innerWidth) / 2; function makeMainPath(dir) { return svgPaths.line([ svgPaths.point(dir * outerWidth, height), @@ -870,8 +870,8 @@ ConstantProvider.prototype.makeNotch = function() { svgPaths.point(dir * outerWidth, -height) ]); } - var pathLeft = makeMainPath(1); - var pathRight = makeMainPath(-1); + const pathLeft = makeMainPath(1); + const pathRight = makeMainPath(-1); return { type: this.SHAPES.NOTCH, @@ -888,12 +888,12 @@ ConstantProvider.prototype.makeNotch = function() { * @package */ ConstantProvider.prototype.makeInsideCorners = function() { - var radius = this.CORNER_RADIUS; + const radius = this.CORNER_RADIUS; - var innerTopLeftCorner = + const innerTopLeftCorner = svgPaths.arc('a', '0 0,0', radius, svgPaths.point(-radius, radius)); - var innerBottomLeftCorner = + const innerBottomLeftCorner = svgPaths.arc('a', '0 0,0', radius, svgPaths.point(radius, radius)); return { @@ -910,33 +910,33 @@ ConstantProvider.prototype.makeInsideCorners = function() { * @package */ ConstantProvider.prototype.makeOutsideCorners = function() { - var radius = this.CORNER_RADIUS; + const radius = this.CORNER_RADIUS; /** * SVG path for drawing the rounded top-left corner. * @const */ - var topLeft = svgPaths.moveBy(0, radius) + + const topLeft = svgPaths.moveBy(0, radius) + svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, -radius)); /** * SVG path for drawing the rounded top-right corner. * @const */ - var topRight = + const topRight = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(radius, radius)); /** * SVG path for drawing the rounded bottom-left corner. * @const */ - var bottomLeft = + const bottomLeft = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, -radius)); /** * SVG path for drawing the rounded bottom-right corner. * @const */ - var bottomRight = + const bottomRight = svgPaths.arc('a', '0 0,1', radius, svgPaths.point(-radius, radius)); return { @@ -1000,13 +1000,13 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { k1="0" k2="1" k3="1" k4="0" /> */ - var embossFilter = dom.createSvgElement( + const embossFilter = dom.createSvgElement( Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, this.defs); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); - var feSpecularLighting = dom.createSvgElement( + const feSpecularLighting = dom.createSvgElement( Svg.FESPECULARLIGHTING, { 'in': 'blur', 'surfaceScale': 1, @@ -1048,7 +1048,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { */ - var disabledPattern = dom.createSvgElement( + const disabledPattern = dom.createSvgElement( Svg.PATTERN, { 'id': 'blocklyDisabledPattern' + this.randomIdentifier, 'patternUnits': 'userSpaceOnUse', @@ -1075,7 +1075,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { ConstantProvider.prototype.createDebugFilter = function() { // Only create the debug filter once. if (!this.debugFilter_) { - var debugFilter = dom.createSvgElement( + const debugFilter = dom.createSvgElement( Svg.FILTER, { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', @@ -1085,7 +1085,7 @@ ConstantProvider.prototype.createDebugFilter = function() { }, this.defs); // Set all gaussian blur pixels to 1 opacity before applying flood - var debugComponentTransfer = dom.createSvgElement( + const debugComponentTransfer = dom.createSvgElement( Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); dom.createSvgElement( Svg.FEFUNCA, @@ -1116,21 +1116,21 @@ ConstantProvider.prototype.createDebugFilter = function() { * @protected */ ConstantProvider.prototype.injectCSS_ = function(tagName, selector) { - var cssArray = this.getCSS_(selector); - var cssNodeId = 'blockly-renderer-style-' + tagName; + const cssArray = this.getCSS_(selector); + const cssNodeId = 'blockly-renderer-style-' + tagName; this.cssNode_ = /** @type {!HTMLStyleElement} */ (document.getElementById(cssNodeId)); - var text = cssArray.join('\n'); + const text = cssArray.join('\n'); if (this.cssNode_) { // Already injected, update if the theme changed. this.cssNode_.firstChild.textContent = text; return; } // Inject CSS tag at start of head. - var cssNode = + const cssNode = /** @type {!HTMLStyleElement} */ (document.createElement('style')); cssNode.id = cssNodeId; - var cssTextNode = document.createTextNode(text); + const cssTextNode = document.createTextNode(text); cssNode.appendChild(cssTextNode); document.head.insertBefore(cssNode, document.head.firstChild); this.cssNode_ = cssNode; From 1dfee3a722a6f542700a5d980440e6c091418bcd Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 23 Jul 2021 16:39:40 -0700 Subject: [PATCH 319/833] Make defs private and add nullability --- core/renderers/common/constants.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 6847aea22..5e5ecb747 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -403,10 +403,10 @@ const ConstantProvider = function() { /** * The defs tag that contains all filters and patterns for this Blockly * instance. - * @type {SVGElement} + * @type {?SVGElement} * @private */ - this.defs = null; + this.defs_ = null; /** * The ID of the emboss filter, or the empty string if no filter is set. @@ -985,7 +985,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { ... filters go here ... */ - this.defs = dom.createSvgElement(Svg.DEFS, {}, svg); + this.defs_ = dom.createSvgElement(Svg.DEFS, {}, svg); /* @@ -1002,7 +1002,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { */ const embossFilter = dom.createSvgElement( Svg.FILTER, {'id': 'blocklyEmbossFilter' + this.randomIdentifier}, - this.defs); + this.defs_); dom.createSvgElement( Svg.FEGAUSSIANBLUR, {'in': 'SourceAlpha', 'stdDeviation': 1, 'result': 'blur'}, embossFilter); @@ -1055,7 +1055,7 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { 'width': 10, 'height': 10 }, - this.defs); + this.defs_); dom.createSvgElement( Svg.RECT, {'width': 10, 'height': 10, 'fill': '#aaa'}, disabledPattern); dom.createSvgElement( @@ -1083,7 +1083,7 @@ ConstantProvider.prototype.createDebugFilter = function() { y: '-30%', x: '-40%' }, - this.defs); + this.defs_); // Set all gaussian blur pixels to 1 opacity before applying flood const debugComponentTransfer = dom.createSvgElement( Svg.FECOMPONENTTRANSFER, {'result': 'outBlur'}, debugFilter); From 1360b5bb49fa460f7ccaf1ba37fa56999b0b95b1 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Fri, 23 Jul 2021 18:10:38 -0700 Subject: [PATCH 320/833] Apply fixes for convert-file script (#5206) --- scripts/goog_module/convert-file.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index f3138e9cf..6a8d36cd0 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -190,20 +190,27 @@ step3() { local comma_properties=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') inf "Detected references of ${require}: ${comma_properties}" - for require_prop in echo "${properties_accessed}"; do + for require_prop in $(echo "${properties_accessed}"); do inf "Updating references of ${require}.${require_prop} to ${require_name}.${require_prop}..." - perl -pi -e 's/'"${require}"'\.'"${require_prop}"'([^'\''\w])/'"${require_name}"'\.'"${require_prop}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'\.'"${require_prop}"'(?!\w)/'"${require_name}"'\.'"${require_prop}"'/g' "${filepath}" done fi inf "Updating direct references of ${require} to ${require_name}..." - perl -pi -e 's/'"${require}"'([^'\''\w]\.)/'"${require_name}"'\1/g' "${filepath}" + perl -pi -e 's/'"${require}"'(?!['\''\w\.])/'"${require_name}"'/g' "${filepath}" done local missing_requires=$(perl -nle'print $& while m{(? Date: Wed, 21 Jul 2021 15:32:39 -0700 Subject: [PATCH 321/833] Migrate core/field_label.js to ES6 const/let --- core/field_label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index 5dc434c92..4a19dc07e 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -64,7 +64,7 @@ Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; * @nocollapse */ Blockly.FieldLabel.fromJson = function(options) { - var text = Blockly.utils.replaceMessageReferences(options['text']); + const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. return new this(text, undefined, options); From a765a3016e4f9cc341f0b5696be548a5f0e6acfa Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:32:52 -0700 Subject: [PATCH 322/833] Migrate core/field_label.js to goog.module --- core/field_label.js | 31 +++++++++++++++++-------------- tests/deps.js | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4a19dc07e..4c15d4f96 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.FieldLabel'); +goog.module('Blockly.FieldLabel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Field'); goog.require('Blockly.fieldRegistry'); @@ -31,7 +32,7 @@ goog.require('Blockly.utils.object'); * @extends {Blockly.Field} * @constructor */ -Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { +const FieldLabel = function(opt_value, opt_class, opt_config) { /** * The html class name to use for this field. * @type {?string} @@ -39,31 +40,31 @@ Blockly.FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - Blockly.FieldLabel.superClass_.constructor.call( + FieldLabel.superClass_.constructor.call( this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(Blockly.FieldLabel, Blockly.Field); +Blockly.utils.object.inherits(FieldLabel, Blockly.Field); /** * The default value for this field. * @type {*} * @protected */ -Blockly.FieldLabel.prototype.DEFAULT_VALUE = ''; +FieldLabel.prototype.DEFAULT_VALUE = ''; /** * Construct a FieldLabel from a JSON arg object, * dereferencing any string table references. * @param {!Object} options A JSON object with options (text, and class). - * @return {!Blockly.FieldLabel} The new field instance. + * @return {!FieldLabel} The new field instance. * @package * @nocollapse */ -Blockly.FieldLabel.fromJson = function(options) { +FieldLabel.fromJson = function(options) { const text = Blockly.utils.replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. @@ -75,13 +76,13 @@ Blockly.FieldLabel.fromJson = function(options) { * editable. This field should not. * @type {boolean} */ -Blockly.FieldLabel.prototype.EDITABLE = false; +FieldLabel.prototype.EDITABLE = false; /** * @override */ -Blockly.FieldLabel.prototype.configure_ = function(config) { - Blockly.FieldLabel.superClass_.configure_.call(this, config); +FieldLabel.prototype.configure_ = function(config) { + FieldLabel.superClass_.configure_.call(this, config); this.class_ = config['class']; }; @@ -89,7 +90,7 @@ Blockly.FieldLabel.prototype.configure_ = function(config) { * Create block UI for this label. * @package */ -Blockly.FieldLabel.prototype.initView = function() { +FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { Blockly.utils.dom.addClass( @@ -103,7 +104,7 @@ Blockly.FieldLabel.prototype.initView = function() { * @return {?string} A valid string, or null if invalid. * @protected */ -Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { +FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { if (opt_newValue === null || opt_newValue === undefined) { return null; } @@ -114,7 +115,7 @@ Blockly.FieldLabel.prototype.doClassValidation_ = function(opt_newValue) { * Set the CSS class applied to the field's textElement_. * @param {?string} cssClass The new CSS class name, or null to remove. */ -Blockly.FieldLabel.prototype.setClass = function(cssClass) { +FieldLabel.prototype.setClass = function(cssClass) { if (this.textElement_) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. @@ -128,4 +129,6 @@ Blockly.FieldLabel.prototype.setClass = function(cssClass) { this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', Blockly.FieldLabel); +Blockly.fieldRegistry.register('field_label', FieldLabel); + +exports = FieldLabel; diff --git a/tests/deps.js b/tests/deps.js index 3dc163ac5..9b2ca48af 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -54,7 +54,7 @@ goog.addDependency('../../core/field_checkbox.js', ['Blockly.FieldCheckbox'], [' goog.addDependency('../../core/field_colour.js', ['Blockly.FieldColour'], ['Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.browserEvents', 'Blockly.fieldRegistry', 'Blockly.utils.IdGenerator', 'Blockly.utils.KeyCodes', 'Blockly.utils.Size', 'Blockly.utils.aria', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_dropdown.js', ['Blockly.FieldDropdown'], ['Blockly.DropDownDiv', 'Blockly.Field', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.string', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_image.js', ['Blockly.FieldImage'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/field_label.js', ['Blockly.FieldLabel'], ['Blockly.Field', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_label_serializable.js', ['Blockly.FieldLabelSerializable'], ['Blockly.FieldLabel', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_multilineinput.js', ['Blockly.FieldMultilineInput'], ['Blockly.Css', 'Blockly.Field', 'Blockly.FieldTextInput', 'Blockly.WidgetDiv', 'Blockly.fieldRegistry', 'Blockly.utils', 'Blockly.utils.KeyCodes', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field_number.js', ['Blockly.FieldNumber'], ['Blockly.FieldTextInput', 'Blockly.fieldRegistry', 'Blockly.utils.aria', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 4945825d6edeeed9728751cd27755dbe341c5ff5 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 15:33:37 -0700 Subject: [PATCH 323/833] Migrate core/field_label.js named requires --- core/field_label.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index 4c15d4f96..c6f1bbcd8 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -14,11 +14,11 @@ goog.module('Blockly.FieldLabel'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Field'); -goog.require('Blockly.fieldRegistry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); +const Field = goog.require('Blockly.Field'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); +const dom = goog.require('Blockly.utils.dom'); +const {inherits} = goog.require('Blockly.utils.object'); +const {replaceMessageReferences} = goog.require('Blockly.utils'); /** @@ -29,7 +29,7 @@ goog.require('Blockly.utils.object'); * @param {Object=} opt_config A map of options used to configure the field. * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} * for a list of properties this parameter supports. - * @extends {Blockly.Field} + * @extends {Field} * @constructor */ const FieldLabel = function(opt_value, opt_class, opt_config) { @@ -47,7 +47,7 @@ const FieldLabel = function(opt_value, opt_class, opt_config) { this.class_ = opt_class || null; } }; -Blockly.utils.object.inherits(FieldLabel, Blockly.Field); +inherits(FieldLabel, Field); /** * The default value for this field. @@ -65,7 +65,7 @@ FieldLabel.prototype.DEFAULT_VALUE = ''; * @nocollapse */ FieldLabel.fromJson = function(options) { - const text = Blockly.utils.replaceMessageReferences(options['text']); + const text = replaceMessageReferences(options['text']); // `this` might be a subclass of FieldLabel if that class doesn't override // the static fromJson method. return new this(text, undefined, options); @@ -93,7 +93,7 @@ FieldLabel.prototype.configure_ = function(config) { FieldLabel.prototype.initView = function() { this.createTextElement_(); if (this.class_) { - Blockly.utils.dom.addClass( + dom.addClass( /** @type {!SVGTextElement} */ (this.textElement_), this.class_); } }; @@ -120,15 +120,15 @@ FieldLabel.prototype.setClass = function(cssClass) { // This check isn't necessary, but it's faster than letting removeClass // figure it out. if (this.class_) { - Blockly.utils.dom.removeClass(this.textElement_, this.class_); + dom.removeClass(this.textElement_, this.class_); } if (cssClass) { - Blockly.utils.dom.addClass(this.textElement_, cssClass); + dom.addClass(this.textElement_, cssClass); } } this.class_ = cssClass; }; -Blockly.fieldRegistry.register('field_label', FieldLabel); +fieldRegistry.register('field_label', FieldLabel); exports = FieldLabel; From 0889defe55645de721ba84e56e2e26c4d1baf1ad Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:22:33 -0700 Subject: [PATCH 324/833] clang-format core/field_label.js --- core/field_label.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/field_label.js b/core/field_label.js index c6f1bbcd8..8d23bbb18 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -27,7 +27,8 @@ const {replaceMessageReferences} = goog.require('Blockly.utils'); * string. Defaults to an empty string if null or undefined. * @param {string=} opt_class Optional CSS class for the field's text. * @param {Object=} opt_config A map of options used to configure the field. - * See the [field creation documentation]{@link https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} + * See the [field creation documentation]{@link + * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/label#creation} * for a list of properties this parameter supports. * @extends {Field} * @constructor @@ -40,8 +41,7 @@ const FieldLabel = function(opt_value, opt_class, opt_config) { */ this.class_ = null; - FieldLabel.superClass_.constructor.call( - this, opt_value, null, opt_config); + FieldLabel.superClass_.constructor.call(this, opt_value, null, opt_config); if (!opt_config) { // If the config was not passed use old configuration. this.class_ = opt_class || null; From e997330085edd26b57dd254ae4622bb6186c4d40 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:24:42 -0700 Subject: [PATCH 325/833] Fix require order in core/field_label.js --- core/field_label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/field_label.js b/core/field_label.js index 8d23bbb18..822d476ab 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -15,8 +15,8 @@ goog.module('Blockly.FieldLabel'); goog.module.declareLegacyNamespace(); const Field = goog.require('Blockly.Field'); -const fieldRegistry = goog.require('Blockly.fieldRegistry'); const dom = goog.require('Blockly.utils.dom'); +const fieldRegistry = goog.require('Blockly.fieldRegistry'); const {inherits} = goog.require('Blockly.utils.object'); const {replaceMessageReferences} = goog.require('Blockly.utils'); From ccd314279e022002fe4feaa1011e43dd6c66c5de Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:24:43 -0700 Subject: [PATCH 326/833] Migrate core/registry.js to ES6 const/let --- core/registry.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/registry.js b/core/registry.js index 2959cf73e..0ea2883f8 100644 --- a/core/registry.js +++ b/core/registry.js @@ -139,7 +139,7 @@ Blockly.registry.register = function( if (!registryItem) { throw Error('Can not register a null value'); } - var typeRegistry = Blockly.registry.typeMap_[type]; + let typeRegistry = Blockly.registry.typeMap_[type]; // If the type registry has not been created, create it. if (!typeRegistry) { typeRegistry = Blockly.registry.typeMap_[type] = Object.create(null); @@ -184,7 +184,7 @@ Blockly.registry.validate_ = function(type, registryItem) { Blockly.registry.unregister = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - var typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = Blockly.registry.typeMap_[type]; if (!typeRegistry || !typeRegistry[name]) { console.warn('Unable to unregister [' + name + '][' + type + '] from the ' + 'registry.'); @@ -208,9 +208,9 @@ Blockly.registry.unregister = function(type, name) { Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { type = String(type).toLowerCase(); name = name.toLowerCase(); - var typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = Blockly.registry.typeMap_[type]; if (!typeRegistry || !typeRegistry[name]) { - var msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; + const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { throw new Error(msg + ' You must require or register a ' + type + ' plugin.'); @@ -235,7 +235,7 @@ Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { Blockly.registry.hasItem = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - var typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = Blockly.registry.typeMap_[type]; if (!typeRegistry) { return false; } @@ -286,8 +286,8 @@ Blockly.registry.getObject = function(type, name, opt_throwIfMissing) { */ Blockly.registry.getClassFromOptions = function(type, options, opt_throwIfMissing) { - var typeName = type.toString(); - var plugin = options.plugins[typeName] || Blockly.registry.DEFAULT; + const typeName = type.toString(); + const plugin = options.plugins[typeName] || Blockly.registry.DEFAULT; // If the user passed in a plugin class instead of a registered plugin name. if (typeof plugin == 'function') { From 6ce759d15e02ffbd7bddb5902ccf7dca93d9f7f7 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:40:02 -0700 Subject: [PATCH 327/833] Migrate core/registry.js to goog.module --- core/registry.js | 138 +++++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 75 insertions(+), 65 deletions(-) diff --git a/core/registry.js b/core/registry.js index 0ea2883f8..9d7d72201 100644 --- a/core/registry.js +++ b/core/registry.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.registry'); +goog.module('Blockly.registry'); +goog.module.declareLegacyNamespace(); goog.requireType('Blockly.blockRendering.Renderer'); goog.requireType('Blockly.Cursor'); @@ -34,13 +35,16 @@ goog.requireType('Blockly.ToolboxItem'); * * @type {Object>} */ -Blockly.registry.typeMap_ = Object.create(null); +const typeMap = Object.create(null); +/** @private */ +exports.typeMap_ = typeMap; /** * The string used to register the default class for a type of plugin. * @type {string} */ -Blockly.registry.DEFAULT = 'default'; +const DEFAULT = 'default'; +exports.DEFAULT = DEFAULT; /** * A name with the type of the element stored in the generic. @@ -48,67 +52,68 @@ Blockly.registry.DEFAULT = 'default'; * @constructor * @template T */ -Blockly.registry.Type = function(name) { +const Type = function(name) { /** * @type {string} * @private */ this.name_ = name; }; +exports.Type = Type; /** * Returns the name of the type. * @return {string} The name. * @override */ -Blockly.registry.Type.prototype.toString = function() { +Type.prototype.toString = function() { return this.name_; }; -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.CONNECTION_CHECKER = - new Blockly.registry.Type('connectionChecker'); +/** @type {!Type} */ +Type.CONNECTION_CHECKER = + new Type('connectionChecker'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.CURSOR = new Blockly.registry.Type('cursor'); +/** @type {!Type} */ +Type.CURSOR = new Type('cursor'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.EVENT = new Blockly.registry.Type('event'); +/** @type {!Type} */ +Type.EVENT = new Type('event'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.FIELD = new Blockly.registry.Type('field'); +/** @type {!Type} */ +Type.FIELD = new Type('field'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.RENDERER = new Blockly.registry.Type('renderer'); +/** @type {!Type} */ +Type.RENDERER = new Type('renderer'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.TOOLBOX = new Blockly.registry.Type('toolbox'); +/** @type {!Type} */ +Type.TOOLBOX = new Type('toolbox'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.THEME = new Blockly.registry.Type('theme'); +/** @type {!Type} */ +Type.THEME = new Type('theme'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.TOOLBOX_ITEM = new Blockly.registry.Type('toolboxItem'); +/** @type {!Type} */ +Type.TOOLBOX_ITEM = new Type('toolboxItem'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX = - new Blockly.registry.Type('flyoutsVerticalToolbox'); +/** @type {!Type} */ +Type.FLYOUTS_VERTICAL_TOOLBOX = + new Type('flyoutsVerticalToolbox'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX = - new Blockly.registry.Type('flyoutsHorizontalToolbox'); +/** @type {!Type} */ +Type.FLYOUTS_HORIZONTAL_TOOLBOX = + new Type('flyoutsHorizontalToolbox'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.METRICS_MANAGER = - new Blockly.registry.Type('metricsManager'); +/** @type {!Type} */ +Type.METRICS_MANAGER = + new Type('metricsManager'); -/** @type {!Blockly.registry.Type} */ -Blockly.registry.Type.BLOCK_DRAGGER = - new Blockly.registry.Type('blockDragger'); +/** @type {!Type} */ +Type.BLOCK_DRAGGER = + new Type('blockDragger'); /** * Registers a class based on a type and name. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @param {?function(new:T, ...?)|Object} registryItem The class or object to @@ -120,13 +125,13 @@ Blockly.registry.Type.BLOCK_DRAGGER = * it's type. * @template T */ -Blockly.registry.register = function( +const register = function( type, name, registryItem, opt_allowOverrides) { - if ((!(type instanceof Blockly.registry.Type) && typeof type != 'string') || + if ((!(type instanceof Type) && typeof type != 'string') || String(type).trim() == '') { throw Error( 'Invalid type "' + type + '". The type must be a' + - ' non-empty string or a Blockly.registry.Type.'); + ' non-empty string or a Type.'); } type = String(type).toLowerCase(); @@ -139,14 +144,14 @@ Blockly.registry.register = function( if (!registryItem) { throw Error('Can not register a null value'); } - let typeRegistry = Blockly.registry.typeMap_[type]; + let typeRegistry = typeMap[type]; // If the type registry has not been created, create it. if (!typeRegistry) { - typeRegistry = Blockly.registry.typeMap_[type] = Object.create(null); + typeRegistry = typeMap[type] = Object.create(null); } // Validate that the given class has all the required properties. - Blockly.registry.validate_(type, registryItem); + validate(type, registryItem); // Don't throw an error if opt_allowOverrides is true. if (!opt_allowOverrides && typeRegistry[name]) { @@ -155,6 +160,7 @@ Blockly.registry.register = function( } typeRegistry[name] = registryItem; }; +exports.register = register; /** * Checks the given registry item for properties that are required based on the @@ -162,11 +168,10 @@ Blockly.registry.register = function( * @param {string} type The type of the plugin. (e.g. Field, Renderer) * @param {Function|Object} registryItem A class or object that we are checking * for the required properties. - * @private */ -Blockly.registry.validate_ = function(type, registryItem) { +const validate = function(type, registryItem) { switch (type) { - case String(Blockly.registry.Type.FIELD): + case String(Type.FIELD): if (typeof registryItem.fromJson != 'function') { throw Error('Type "' + type + '" must have a fromJson function'); } @@ -176,27 +181,28 @@ Blockly.registry.validate_ = function(type, registryItem) { /** * Unregisters the registry item with the given type and name. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @template T */ -Blockly.registry.unregister = function(type, name) { +const unregister = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - const typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { console.warn('Unable to unregister [' + name + '][' + type + '] from the ' + 'registry.'); return; } - delete Blockly.registry.typeMap_[type][name]; + delete typeMap[type][name]; }; +exports.unregister = unregister; /** * Gets the registry item for the given name and type. This can be either a * class or an object. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -205,10 +211,10 @@ Blockly.registry.unregister = function(type, name) { * name and type or null if none exists. * @template T */ -Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { +const getItem = function(type, name, opt_throwIfMissing) { type = String(type).toLowerCase(); name = name.toLowerCase(); - const typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { @@ -225,26 +231,27 @@ Blockly.registry.getItem_ = function(type, name, opt_throwIfMissing) { /** * Returns whether or not the registry contains an item with the given type and * name. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @return {boolean} True if the registry has an item with the given type and * name, false otherwise. * @template T */ -Blockly.registry.hasItem = function(type, name) { +const hasItem = function(type, name) { type = String(type).toLowerCase(); name = name.toLowerCase(); - const typeRegistry = Blockly.registry.typeMap_[type]; + const typeRegistry = typeMap[type]; if (!typeRegistry) { return false; } return !!(typeRegistry[name]); }; +exports.hasItem = hasItem; /** * Gets the class for the given name and type. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Field, Renderer) * @param {string} name The plugin's name. (Ex. field_angle, geras) * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -253,14 +260,15 @@ Blockly.registry.hasItem = function(type, name) { * null if none exists. * @template T */ -Blockly.registry.getClass = function(type, name, opt_throwIfMissing) { +const getClass = function(type, name, opt_throwIfMissing) { return /** @type {?function(new:T, ...?)} */ ( - Blockly.registry.getItem_(type, name, opt_throwIfMissing)); + getItem(type, name, opt_throwIfMissing)); }; +exports.getClass = getClass; /** * Gets the object for the given name and type. - * @param {string|!Blockly.registry.Type} type The type of the plugin. + * @param {string|!Type} type The type of the plugin. * (e.g. Category) * @param {string} name The plugin's name. (Ex. logic_category) * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -268,15 +276,16 @@ Blockly.registry.getClass = function(type, name, opt_throwIfMissing) { * @return {?T} The object with the given name and type or null if none exists. * @template T */ -Blockly.registry.getObject = function(type, name, opt_throwIfMissing) { +const getObject = function(type, name, opt_throwIfMissing) { return /** @type {T} */ ( - Blockly.registry.getItem_(type, name, opt_throwIfMissing)); + getItem(type, name, opt_throwIfMissing)); }; +exports.getObject = getObject; /** * Gets the class from Blockly options for the given type. * This is used for plugins that override a built in feature. (e.g. Toolbox) - * @param {!Blockly.registry.Type} type The type of the plugin. + * @param {!Type} type The type of the plugin. * @param {!Blockly.Options} options The option object to check for the given * plugin. * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we @@ -284,14 +293,15 @@ Blockly.registry.getObject = function(type, name, opt_throwIfMissing) { * @return {?function(new:T, ...?)} The class for the plugin. * @template T */ -Blockly.registry.getClassFromOptions = function(type, options, +const getClassFromOptions = function(type, options, opt_throwIfMissing) { const typeName = type.toString(); - const plugin = options.plugins[typeName] || Blockly.registry.DEFAULT; + const plugin = options.plugins[typeName] || DEFAULT; // If the user passed in a plugin class instead of a registered plugin name. if (typeof plugin == 'function') { return plugin; } - return Blockly.registry.getClass(type, plugin, opt_throwIfMissing); + return getClass(type, plugin, opt_throwIfMissing); }; +exports.getClassFromOptions = getClassFromOptions; diff --git a/tests/deps.js b/tests/deps.js index de575339f..93d8ee6a0 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -117,7 +117,7 @@ goog.addDependency('../../core/names.js', ['Blockly.Names'], ['Blockly.Msg', 'Bl goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme', 'Blockly.Themes.Classic', 'Blockly.registry', 'Blockly.utils.IdGenerator', 'Blockly.utils.Metrics', 'Blockly.utils.toolbox']); goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); -goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); +goog.addDependency('../../core/registry.js', ['Blockly.registry'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); From 71e187adc9af78b56c171ebaf46c8d7926172a28 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 17:59:35 -0700 Subject: [PATCH 328/833] Migrate core/gesture.js to ES6 const/let --- core/gesture.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 483d73a25..59dbd57f0 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -266,8 +266,8 @@ Blockly.Gesture.prototype.dispose = function() { * @private */ Blockly.Gesture.prototype.updateFromEvent_ = function(e) { - var currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); - var changed = this.updateDragDelta_(currentXY); + const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { this.updateIsDragging_(); @@ -290,11 +290,11 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { - var currentDragDelta = + const currentDragDelta = Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - var limitRadius = this.flyout_ ? + const limitRadius = this.flyout_ ? Blockly.internalConstants.FLYOUT_DRAG_RADIUS : Blockly.internalConstants.DRAG_RADIUS; @@ -394,7 +394,7 @@ Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { * @private */ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { - var wsMovable = this.flyout_ ? + const wsMovable = this.flyout_ ? this.flyout_.isScrollable() : this.startWorkspace_ && this.startWorkspace_.isDraggable(); @@ -439,8 +439,9 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() { * @private */ Blockly.Gesture.prototype.startDraggingBlock_ = function() { - var BlockDraggerClass = Blockly.registry.getClassFromOptions( - Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); + const BlockDraggerClass = Blockly.registry.getClassFromOptions( + Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, + true); this.blockDragger_ = new BlockDraggerClass( /** @type {!Blockly.BlockSvg} */ (this.targetBlock_), @@ -747,12 +748,12 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { if (!Blockly.Events.getGroup()) { Blockly.Events.setGroup(true); } - var newBlock = this.flyout_.createBlock(this.targetBlock_); + const newBlock = this.flyout_.createBlock(this.targetBlock_); newBlock.scheduleSnapAndBump(); } } else { // Clicks events are on the start block, even if it was a shadow. - var event = new (Blockly.Events.get(Blockly.Events.CLICK))( + const event = new (Blockly.Events.get(Blockly.Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); Blockly.Events.fire(event); } @@ -767,7 +768,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { * @private */ Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { - var ws = this.creatorWorkspace_; + const ws = this.creatorWorkspace_; if (Blockly.selected) { Blockly.selected.unselect(); } @@ -888,7 +889,7 @@ Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { */ Blockly.Gesture.prototype.isBubbleClick_ = function() { // A bubble click starts on a bubble and never escapes the drag radius. - var hasStartBubble = !!this.startBubble_; + const hasStartBubble = !!this.startBubble_; return hasStartBubble && !this.hasExceededDragRadius_; }; @@ -901,7 +902,7 @@ Blockly.Gesture.prototype.isBubbleClick_ = function() { Blockly.Gesture.prototype.isBlockClick_ = function() { // A block click starts on a block, never escapes the drag radius, and is not // a field click. - var hasStartBlock = !!this.startBlock_; + const hasStartBlock = !!this.startBlock_; return hasStartBlock && !this.hasExceededDragRadius_ && !this.isFieldClick_(); }; @@ -912,7 +913,7 @@ Blockly.Gesture.prototype.isBlockClick_ = function() { * @private */ Blockly.Gesture.prototype.isFieldClick_ = function() { - var fieldClickable = + const fieldClickable = this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && (!this.flyout_ || !this.flyout_.autoClose); @@ -925,7 +926,7 @@ Blockly.Gesture.prototype.isFieldClick_ = function() { * @private */ Blockly.Gesture.prototype.isWorkspaceClick_ = function() { - var onlyTouchedWorkspace = + const onlyTouchedWorkspace = !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; }; @@ -991,8 +992,8 @@ Blockly.Gesture.prototype.getCurrentDragger = function() { * @return {boolean} True if gesture is occurring. */ Blockly.Gesture.inProgress = function() { - var workspaces = Blockly.Workspace.getAll(); - for (var i = 0, workspace; (workspace = workspaces[i]); i++) { + const workspaces = Blockly.Workspace.getAll(); + for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { return true; } From 1d847eda4a847ad0ac77326db8a79cbd7d2e3893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:45:51 -0700 Subject: [PATCH 329/833] Migrate core/gesture.js to goog.module --- core/gesture.js | 90 ++++++++++++++++++++++++++----------------------- tests/deps.js | 2 +- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index 59dbd57f0..a5b786b5b 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Gesture'); +goog.module('Blockly.Gesture'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockAnimations'); /** @suppress {extraRequire} */ @@ -22,6 +23,7 @@ goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); goog.require('Blockly.internalConstants'); +goog.require('Blockly.registry'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); @@ -50,7 +52,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * this gesture and has a reference to it. * @constructor */ -Blockly.Gesture = function(e, creatorWorkspace) { +const Gesture = function(e, creatorWorkspace) { /** * The position of the mouse when the gesture started. Units are CSS pixels, * with (0, 0) at the top left of the browser window (mouseEvent clientX/Y). @@ -236,7 +238,7 @@ Blockly.Gesture = function(e, creatorWorkspace) { * Sever all links from this object. * @package */ -Blockly.Gesture.prototype.dispose = function() { +Gesture.prototype.dispose = function() { Blockly.Touch.clearTouchIdentifier(); Blockly.Tooltip.unblock(); // Clear the owner's reference to this gesture. @@ -265,7 +267,7 @@ Blockly.Gesture.prototype.dispose = function() { * @param {!Event} e The most recent mouse or touch event. * @private */ -Blockly.Gesture.prototype.updateFromEvent_ = function(e) { +Gesture.prototype.updateFromEvent_ = function(e) { const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. @@ -284,7 +286,7 @@ Blockly.Gesture.prototype.updateFromEvent_ = function(e) { * first time. * @private */ -Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { +Gesture.prototype.updateDragDelta_ = function(currentXY) { this.currentDragDeltaXY_ = Blockly.utils.Coordinate.difference( currentXY, /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); @@ -314,7 +316,7 @@ Blockly.Gesture.prototype.updateDragDelta_ = function(currentXY) { * @return {boolean} True if a block is being dragged from the flyout. * @private */ -Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { +Gesture.prototype.updateIsDraggingFromFlyout_ = function() { if (!this.targetBlock_) { return false; } @@ -348,7 +350,7 @@ Blockly.Gesture.prototype.updateIsDraggingFromFlyout_ = function() { * @return {boolean} True if a bubble is being dragged. * @private */ -Blockly.Gesture.prototype.updateIsDraggingBubble_ = function() { +Gesture.prototype.updateIsDraggingBubble_ = function() { if (!this.startBubble_) { return false; } @@ -367,7 +369,7 @@ Blockly.Gesture.prototype.updateIsDraggingBubble_ = function() { * @return {boolean} True if a block is being dragged. * @private */ -Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { +Gesture.prototype.updateIsDraggingBlock_ = function() { if (!this.targetBlock_) { return false; } @@ -393,7 +395,7 @@ Blockly.Gesture.prototype.updateIsDraggingBlock_ = function() { * WorkspaceDragger and starts the drag. * @private */ -Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { +Gesture.prototype.updateIsDraggingWorkspace_ = function() { const wsMovable = this.flyout_ ? this.flyout_.isScrollable() : this.startWorkspace_ && this.startWorkspace_.isDraggable(); @@ -415,7 +417,7 @@ Blockly.Gesture.prototype.updateIsDraggingWorkspace_ = function() { * drag radius is exceeded. It should be called no more than once per gesture. * @private */ -Blockly.Gesture.prototype.updateIsDragging_ = function() { +Gesture.prototype.updateIsDragging_ = function() { // Sanity check. if (this.calledUpdateIsDragging_) { throw Error('updateIsDragging_ should only be called once per gesture.'); @@ -438,7 +440,7 @@ Blockly.Gesture.prototype.updateIsDragging_ = function() { * Create a block dragger and start dragging the selected block. * @private */ -Blockly.Gesture.prototype.startDraggingBlock_ = function() { +Gesture.prototype.startDraggingBlock_ = function() { const BlockDraggerClass = Blockly.registry.getClassFromOptions( Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); @@ -455,7 +457,7 @@ Blockly.Gesture.prototype.startDraggingBlock_ = function() { * @private */ // TODO (fenichel): Possibly combine this and startDraggingBlock_. -Blockly.Gesture.prototype.startDraggingBubble_ = function() { +Gesture.prototype.startDraggingBubble_ = function() { this.bubbleDragger_ = new Blockly.BubbleDragger( /** @type {!Blockly.IBubble} */ (this.startBubble_), /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); @@ -469,7 +471,7 @@ Blockly.Gesture.prototype.startDraggingBubble_ = function() { * @param {!Event} e A mouse down or touch start event. * @package */ -Blockly.Gesture.prototype.doStart = function(e) { +Gesture.prototype.doStart = function(e) { if (Blockly.utils.isTargetInput(e)) { this.cancel(); return; @@ -519,7 +521,7 @@ Blockly.Gesture.prototype.doStart = function(e) { * @param {!Event} e A mouse down or touch start event. * @package */ -Blockly.Gesture.prototype.bindMouseEvents = function(e) { +Gesture.prototype.bindMouseEvents = function(e) { this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( @@ -534,7 +536,7 @@ Blockly.Gesture.prototype.bindMouseEvents = function(e) { * @param {!Event} e A mouse move or touch move event. * @package */ -Blockly.Gesture.prototype.handleMove = function(e) { +Gesture.prototype.handleMove = function(e) { this.updateFromEvent_(e); if (this.isDraggingWorkspace_) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); @@ -554,7 +556,7 @@ Blockly.Gesture.prototype.handleMove = function(e) { * @param {!Event} e A mouse up or touch end event. * @package */ -Blockly.Gesture.prototype.handleUp = function(e) { +Gesture.prototype.handleUp = function(e) { this.updateFromEvent_(e); Blockly.longStop_(); @@ -596,7 +598,7 @@ Blockly.Gesture.prototype.handleUp = function(e) { * end the drag at the most recent location. * @package */ -Blockly.Gesture.prototype.cancel = function() { +Gesture.prototype.cancel = function() { // Disposing of a block cancels in-progress drags, but dragging to a delete // area disposes of a block and leads to recursive disposal. Break that cycle. if (this.isEnding_) { @@ -620,7 +622,7 @@ Blockly.Gesture.prototype.cancel = function() { * @param {!Event} e A mouse move or touch move event. * @package */ -Blockly.Gesture.prototype.handleRightClick = function(e) { +Gesture.prototype.handleRightClick = function(e) { if (this.targetBlock_) { this.bringBlockToFront_(); Blockly.hideChaff(!!this.flyout_); @@ -645,7 +647,7 @@ Blockly.Gesture.prototype.handleRightClick = function(e) { * @param {!Blockly.WorkspaceSvg} ws The workspace the event hit. * @package */ -Blockly.Gesture.prototype.handleWsStart = function(e, ws) { +Gesture.prototype.handleWsStart = function(e, ws) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleWsStart, ' + @@ -661,7 +663,7 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) { * @param {!Blockly.WorkspaceSvg} ws The workspace that a user clicks on. * @private */ -Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { +Gesture.prototype.fireWorkspaceClick_ = function(ws) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( null, ws.id, 'workspace')); }; @@ -672,7 +674,7 @@ Blockly.Gesture.prototype.fireWorkspaceClick_ = function(ws) { * @param {!Blockly.IFlyout} flyout The flyout the event hit. * @package */ -Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { +Gesture.prototype.handleFlyoutStart = function(e, flyout) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleFlyoutStart, ' + @@ -688,7 +690,7 @@ Blockly.Gesture.prototype.handleFlyoutStart = function(e, flyout) { * @param {!Blockly.BlockSvg} block The block the event hit. * @package */ -Blockly.Gesture.prototype.handleBlockStart = function(e, block) { +Gesture.prototype.handleBlockStart = function(e, block) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleBlockStart, ' + @@ -704,7 +706,7 @@ Blockly.Gesture.prototype.handleBlockStart = function(e, block) { * @param {!Blockly.IBubble} bubble The bubble the event hit. * @package */ -Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { +Gesture.prototype.handleBubbleStart = function(e, bubble) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.handleBubbleStart, ' + @@ -722,7 +724,7 @@ Blockly.Gesture.prototype.handleBubbleStart = function(e, bubble) { * Execute a bubble click. * @private */ -Blockly.Gesture.prototype.doBubbleClick_ = function() { +Gesture.prototype.doBubbleClick_ = function() { // TODO (#1673): Consistent handling of single clicks. this.startBubble_.setFocus && this.startBubble_.setFocus(); this.startBubble_.select && this.startBubble_.select(); @@ -732,7 +734,7 @@ Blockly.Gesture.prototype.doBubbleClick_ = function() { * Execute a field click. * @private */ -Blockly.Gesture.prototype.doFieldClick_ = function() { +Gesture.prototype.doFieldClick_ = function() { this.startField_.showEditor(this.mostRecentEvent_); this.bringBlockToFront_(); }; @@ -741,7 +743,7 @@ Blockly.Gesture.prototype.doFieldClick_ = function() { * Execute a block click. * @private */ -Blockly.Gesture.prototype.doBlockClick_ = function() { +Gesture.prototype.doBlockClick_ = function() { // Block click in an autoclosing flyout. if (this.flyout_ && this.flyout_.autoClose) { if (this.targetBlock_.isEnabled()) { @@ -767,7 +769,7 @@ Blockly.Gesture.prototype.doBlockClick_ = function() { * @param {!Event} _e A mouse up or touch end event. * @private */ -Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { +Gesture.prototype.doWorkspaceClick_ = function(_e) { const ws = this.creatorWorkspace_; if (Blockly.selected) { Blockly.selected.unselect(); @@ -784,7 +786,7 @@ Blockly.Gesture.prototype.doWorkspaceClick_ = function(_e) { * not occluded by other blocks. * @private */ -Blockly.Gesture.prototype.bringBlockToFront_ = function() { +Gesture.prototype.bringBlockToFront_ = function() { // Blocks in the flyout don't overlap, so skip the work. if (this.targetBlock_ && !this.flyout_) { this.targetBlock_.bringToFront(); @@ -798,7 +800,7 @@ Blockly.Gesture.prototype.bringBlockToFront_ = function() { * @param {Blockly.Field} field The field the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartField = function(field) { +Gesture.prototype.setStartField = function(field) { if (this.hasStarted_) { throw Error( 'Tried to call gesture.setStartField, ' + @@ -814,7 +816,7 @@ Blockly.Gesture.prototype.setStartField = function(field) { * @param {Blockly.IBubble} bubble The bubble the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartBubble = function(bubble) { +Gesture.prototype.setStartBubble = function(bubble) { if (!this.startBubble_) { this.startBubble_ = bubble; } @@ -826,7 +828,7 @@ Blockly.Gesture.prototype.setStartBubble = function(bubble) { * @param {Blockly.BlockSvg} block The block the gesture started on. * @package */ -Blockly.Gesture.prototype.setStartBlock = function(block) { +Gesture.prototype.setStartBlock = function(block) { // If the gesture already went through a bubble, don't set the start block. if (!this.startBlock_ && !this.startBubble_) { this.startBlock_ = block; @@ -845,7 +847,7 @@ Blockly.Gesture.prototype.setStartBlock = function(block) { * @param {Blockly.BlockSvg} block The block the gesture targets. * @private */ -Blockly.Gesture.prototype.setTargetBlock_ = function(block) { +Gesture.prototype.setTargetBlock_ = function(block) { if (block.isShadow()) { this.setTargetBlock_(block.getParent()); } else { @@ -858,7 +860,7 @@ Blockly.Gesture.prototype.setTargetBlock_ = function(block) { * @param {Blockly.WorkspaceSvg} ws The workspace the gesture started on. * @private */ -Blockly.Gesture.prototype.setStartWorkspace_ = function(ws) { +Gesture.prototype.setStartWorkspace_ = function(ws) { if (!this.startWorkspace_) { this.startWorkspace_ = ws; } @@ -869,7 +871,7 @@ Blockly.Gesture.prototype.setStartWorkspace_ = function(ws) { * @param {Blockly.IFlyout} flyout The flyout the gesture started on. * @private */ -Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { +Gesture.prototype.setStartFlyout_ = function(flyout) { if (!this.flyout_) { this.flyout_ = flyout; } @@ -887,7 +889,7 @@ Blockly.Gesture.prototype.setStartFlyout_ = function(flyout) { * @return {boolean} Whether this gesture was a click on a bubble. * @private */ -Blockly.Gesture.prototype.isBubbleClick_ = function() { +Gesture.prototype.isBubbleClick_ = function() { // A bubble click starts on a bubble and never escapes the drag radius. const hasStartBubble = !!this.startBubble_; return hasStartBubble && !this.hasExceededDragRadius_; @@ -899,7 +901,7 @@ Blockly.Gesture.prototype.isBubbleClick_ = function() { * @return {boolean} Whether this gesture was a click on a block. * @private */ -Blockly.Gesture.prototype.isBlockClick_ = function() { +Gesture.prototype.isBlockClick_ = function() { // A block click starts on a block, never escapes the drag radius, and is not // a field click. const hasStartBlock = !!this.startBlock_; @@ -912,7 +914,7 @@ Blockly.Gesture.prototype.isBlockClick_ = function() { * @return {boolean} Whether this gesture was a click on a field. * @private */ -Blockly.Gesture.prototype.isFieldClick_ = function() { +Gesture.prototype.isFieldClick_ = function() { const fieldClickable = this.startField_ ? this.startField_.isClickable() : false; return fieldClickable && !this.hasExceededDragRadius_ && @@ -925,7 +927,7 @@ Blockly.Gesture.prototype.isFieldClick_ = function() { * @return {boolean} Whether this gesture was a click on a workspace. * @private */ -Blockly.Gesture.prototype.isWorkspaceClick_ = function() { +Gesture.prototype.isWorkspaceClick_ = function() { const onlyTouchedWorkspace = !this.startBlock_ && !this.startBubble_ && !this.startField_; return onlyTouchedWorkspace && !this.hasExceededDragRadius_; @@ -940,7 +942,7 @@ Blockly.Gesture.prototype.isWorkspaceClick_ = function() { * @return {boolean} True if this gesture is a drag of a workspace or block. * @package */ -Blockly.Gesture.prototype.isDragging = function() { +Gesture.prototype.isDragging = function() { return this.isDraggingWorkspace_ || this.isDraggingBlock_ || this.isDraggingBubble_; }; @@ -952,7 +954,7 @@ Blockly.Gesture.prototype.isDragging = function() { * @return {boolean} Whether this gesture was a click on a workspace. * @package */ -Blockly.Gesture.prototype.hasStarted = function() { +Gesture.prototype.hasStarted = function() { return this.hasStarted_; }; @@ -963,7 +965,7 @@ Blockly.Gesture.prototype.hasStarted = function() { * marker blocks. * @package */ -Blockly.Gesture.prototype.getInsertionMarkers = function() { +Gesture.prototype.getInsertionMarkers = function() { if (this.blockDragger_) { return this.blockDragger_.getInsertionMarkers(); } @@ -976,7 +978,7 @@ Blockly.Gesture.prototype.getInsertionMarkers = function() { * @return {!Blockly.WorkspaceDragger|!Blockly.BubbleDragger|!Blockly.IBlockDragger|null} * The dragger that is currently in use or null if no drag is in progress. */ -Blockly.Gesture.prototype.getCurrentDragger = function() { +Gesture.prototype.getCurrentDragger = function() { if (this.isDraggingBlock_) { return this.blockDragger_; } else if (this.isDraggingWorkspace_) { @@ -991,7 +993,7 @@ Blockly.Gesture.prototype.getCurrentDragger = function() { * Is a drag or other gesture currently in progress on any workspace? * @return {boolean} True if gesture is occurring. */ -Blockly.Gesture.inProgress = function() { +Gesture.inProgress = function() { const workspaces = Blockly.Workspace.getAll(); for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { @@ -1000,3 +1002,5 @@ Blockly.Gesture.inProgress = function() { } return false; }; + +exports = Gesture; diff --git a/tests/deps.js b/tests/deps.js index 9b2ca48af..6d78e4217 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -66,7 +66,7 @@ goog.addDependency('../../core/flyout_button.js', ['Blockly.FlyoutButton'], ['Bl goog.addDependency('../../core/flyout_horizontal.js', ['Blockly.HorizontalFlyout'], ['Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/flyout_vertical.js', ['Blockly.VerticalFlyout'], ['Blockly.Block', 'Blockly.DropDownDiv', 'Blockly.Flyout', 'Blockly.Scrollbar', 'Blockly.WidgetDiv', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/generator.js', ['Blockly.Generator'], ['Blockly', 'Blockly.internalConstants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate']); +goog.addDependency('../../core/gesture.js', ['Blockly.Gesture'], ['Blockly.BlockDragger', 'Blockly.BubbleDragger', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.WorkspaceDragger', 'Blockly.blockAnimations', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/grid.js', ['Blockly.Grid'], ['Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/icon.js', ['Blockly.Icon'], ['Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/inject.js', ['Blockly.inject'], ['Blockly.BlockDragSurfaceSvg', 'Blockly.Css', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Grid', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ScrollbarPair', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.Workspace', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.WorkspaceSvg', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); From 12aa4af67462d8c5003836c10cb13ae2b9e31a1d Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:47:55 -0700 Subject: [PATCH 330/833] Migrate core/gesture.js named requires --- core/gesture.js | 177 +++++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index a5b786b5b..c74efb2f4 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -14,29 +14,36 @@ goog.module('Blockly.Gesture'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockAnimations'); +// TODO(#5073): Add Blockly require after fixing circular dependency. +// goog.require('Blockly'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const BubbleDragger = goog.require('Blockly.BubbleDragger'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ +const Events = goog.require('Blockly.Events'); +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IBlockDragger = goog.requireType('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ +const IBubble = goog.requireType('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.requireType('Blockly.IFlyout'); +const Tooltip = goog.require('Blockly.Tooltip'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.require('Blockly.Workspace'); +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const WorkspaceDragger = goog.require('Blockly.WorkspaceDragger'); +const blockAnimations = goog.require('Blockly.blockAnimations'); +const browserEvents = goog.require('Blockly.browserEvents'); +const internalConstants = goog.require('Blockly.internalConstants'); +const registry = goog.require('Blockly.registry'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.BlockDragger'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.BubbleDragger'); -goog.require('Blockly.Events'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.registry'); -goog.require('Blockly.Tooltip'); -goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.Workspace'); -goog.require('Blockly.WorkspaceDragger'); - -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IBlockDragger'); -goog.requireType('Blockly.IBubble'); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.WorkspaceSvg'); /** @@ -48,7 +55,7 @@ goog.requireType('Blockly.WorkspaceSvg'); /** * Class for one gesture. * @param {!Event} e The event that kicked off this gesture. - * @param {!Blockly.WorkspaceSvg} creatorWorkspace The workspace that created + * @param {!WorkspaceSvg} creatorWorkspace The workspace that created * this gesture and has a reference to it. * @constructor */ @@ -56,7 +63,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The position of the mouse when the gesture started. Units are CSS pixels, * with (0, 0) at the top left of the browser window (mouseEvent clientX/Y). - * @type {Blockly.utils.Coordinate} + * @type {Coordinate} * @private */ this.mouseDownXY_ = null; @@ -64,15 +71,15 @@ const Gesture = function(e, creatorWorkspace) { /** * How far the mouse has moved during this drag, in pixel units. * (0, 0) is at this.mouseDownXY_. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.currentDragDeltaXY_ = new Blockly.utils.Coordinate(0, 0); + this.currentDragDeltaXY_ = new Coordinate(0, 0); /** * The bubble that the gesture started on, or null if it did not start on a * bubble. - * @type {Blockly.IBubble} + * @type {IBubble} * @private */ this.startBubble_ = null; @@ -80,7 +87,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The field that the gesture started on, or null if it did not start on a * field. - * @type {Blockly.Field} + * @type {Field} * @private */ this.startField_ = null; @@ -88,7 +95,7 @@ const Gesture = function(e, creatorWorkspace) { /** * The block that the gesture started on, or null if it did not start on a * block. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @private */ this.startBlock_ = null; @@ -98,7 +105,7 @@ const Gesture = function(e, creatorWorkspace) { * shadow block, this is the first non-shadow parent of the block. If the * gesture started in the flyout, this is the root block of the block group * that was clicked or dragged. - * @type {Blockly.BlockSvg} + * @type {BlockSvg} * @private */ this.targetBlock_ = null; @@ -107,7 +114,7 @@ const Gesture = function(e, creatorWorkspace) { * The workspace that the gesture started on. There may be multiple * workspaces on a page; this is more accurate than using * Blockly.getMainWorkspace(). - * @type {Blockly.WorkspaceSvg} + * @type {WorkspaceSvg} * @protected */ this.startWorkspace_ = null; @@ -117,7 +124,7 @@ const Gesture = function(e, creatorWorkspace) { * to the gesture, which will need to be cleared at deletion. * This may be different from the start workspace. For instance, a flyout is * a workspace, but its parent workspace manages gestures for it. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.creatorWorkspace_ = creatorWorkspace; @@ -162,7 +169,7 @@ const Gesture = function(e, creatorWorkspace) { /** * A handle to use to unbind a mouse move listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @protected */ this.onMoveWrapper_ = null; @@ -170,21 +177,21 @@ const Gesture = function(e, creatorWorkspace) { /** * A handle to use to unbind a mouse up listener at the end of a drag. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @protected */ this.onUpWrapper_ = null; /** * The object tracking a bubble drag, or null if none is in progress. - * @type {Blockly.BubbleDragger} + * @type {BubbleDragger} * @private */ this.bubbleDragger_ = null; /** * The object tracking a block drag, or null if none is in progress. - * @type {?Blockly.IBlockDragger} + * @type {?IBlockDragger} * @private */ this.blockDragger_ = null; @@ -192,14 +199,14 @@ const Gesture = function(e, creatorWorkspace) { /** * The object tracking a workspace or flyout workspace drag, or null if none * is in progress. - * @type {Blockly.WorkspaceDragger} + * @type {WorkspaceDragger} * @private */ this.workspaceDragger_ = null; /** * The flyout a gesture started in, if any. - * @type {Blockly.IFlyout} + * @type {IFlyout} * @private */ this.flyout_ = null; @@ -231,7 +238,7 @@ const Gesture = function(e, creatorWorkspace) { * @type {boolean} * @private */ - this.healStack_ = !Blockly.internalConstants.DRAG_STACK; + this.healStack_ = !internalConstants.DRAG_STACK; }; /** @@ -239,16 +246,16 @@ const Gesture = function(e, creatorWorkspace) { * @package */ Gesture.prototype.dispose = function() { - Blockly.Touch.clearTouchIdentifier(); - Blockly.Tooltip.unblock(); + Touch.clearTouchIdentifier(); + Tooltip.unblock(); // Clear the owner's reference to this gesture. this.creatorWorkspace_.clearGesture(); if (this.onMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMoveWrapper_); + browserEvents.unbind(this.onMoveWrapper_); } if (this.onUpWrapper_) { - Blockly.browserEvents.unbind(this.onUpWrapper_); + browserEvents.unbind(this.onUpWrapper_); } if (this.blockDragger_) { @@ -268,7 +275,7 @@ Gesture.prototype.dispose = function() { * @private */ Gesture.prototype.updateFromEvent_ = function(e) { - const currentXY = new Blockly.utils.Coordinate(e.clientX, e.clientY); + const currentXY = new Coordinate(e.clientX, e.clientY); const changed = this.updateDragDelta_(currentXY); // Exceeded the drag radius for the first time. if (changed) { @@ -280,25 +287,25 @@ Gesture.prototype.updateFromEvent_ = function(e) { /** * DO MATH to set currentDragDeltaXY_ based on the most recent mouse position. - * @param {!Blockly.utils.Coordinate} currentXY The most recent mouse/pointer + * @param {!Coordinate} currentXY The most recent mouse/pointer * position, in pixel units, with (0, 0) at the window's top left corner. * @return {boolean} True if the drag just exceeded the drag radius for the * first time. * @private */ Gesture.prototype.updateDragDelta_ = function(currentXY) { - this.currentDragDeltaXY_ = Blockly.utils.Coordinate.difference( + this.currentDragDeltaXY_ = Coordinate.difference( currentXY, - /** @type {!Blockly.utils.Coordinate} */ (this.mouseDownXY_)); + /** @type {!Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { const currentDragDelta = - Blockly.utils.Coordinate.magnitude(this.currentDragDeltaXY_); + Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. const limitRadius = this.flyout_ ? - Blockly.internalConstants.FLYOUT_DRAG_RADIUS : - Blockly.internalConstants.DRAG_RADIUS; + internalConstants.FLYOUT_DRAG_RADIUS : + internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -329,8 +336,8 @@ Gesture.prototype.updateIsDraggingFromFlyout_ = function() { this.startWorkspace_.updateScreenCalculationsIfScrolled(); // Start the event group now, so that the same event group is used for block // creation and block dragging. - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } // The start block is no longer relevant, because this is a drag. this.startBlock_ = null; @@ -404,8 +411,8 @@ Gesture.prototype.updateIsDraggingWorkspace_ = function() { return; } - this.workspaceDragger_ = new Blockly.WorkspaceDragger( - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + this.workspaceDragger_ = new WorkspaceDragger( + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.isDraggingWorkspace_ = true; this.workspaceDragger_.startDrag(); @@ -441,13 +448,13 @@ Gesture.prototype.updateIsDragging_ = function() { * @private */ Gesture.prototype.startDraggingBlock_ = function() { - const BlockDraggerClass = Blockly.registry.getClassFromOptions( - Blockly.registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, + const BlockDraggerClass = registry.getClassFromOptions( + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); this.blockDragger_ = new BlockDraggerClass( - /** @type {!Blockly.BlockSvg} */ (this.targetBlock_), - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + /** @type {!BlockSvg} */ (this.targetBlock_), + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.blockDragger_.startDrag(this.currentDragDeltaXY_, this.healStack_); this.blockDragger_.drag(this.mostRecentEvent_, this.currentDragDeltaXY_); }; @@ -458,9 +465,9 @@ Gesture.prototype.startDraggingBlock_ = function() { */ // TODO (fenichel): Possibly combine this and startDraggingBlock_. Gesture.prototype.startDraggingBubble_ = function() { - this.bubbleDragger_ = new Blockly.BubbleDragger( - /** @type {!Blockly.IBubble} */ (this.startBubble_), - /** @type {!Blockly.WorkspaceSvg} */ (this.startWorkspace_)); + this.bubbleDragger_ = new BubbleDragger( + /** @type {!IBubble} */ (this.startBubble_), + /** @type {!WorkspaceSvg} */ (this.startWorkspace_)); this.bubbleDragger_.startBubbleDrag(); this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_); @@ -472,13 +479,13 @@ Gesture.prototype.startDraggingBubble_ = function() { * @package */ Gesture.prototype.doStart = function(e) { - if (Blockly.utils.isTargetInput(e)) { + if (utils.isTargetInput(e)) { this.cancel(); return; } this.hasStarted_ = true; - Blockly.blockAnimations.disconnectUiStop(); + blockAnimations.disconnectUiStop(); this.startWorkspace_.updateScreenCalculationsIfScrolled(); if (this.startWorkspace_.isMutator) { // Mutator's coordinate system could be out of date because the bubble was @@ -493,13 +500,13 @@ Gesture.prototype.doStart = function(e) { this.startWorkspace_.markFocused(); this.mostRecentEvent_ = e; - Blockly.Tooltip.block(); + Tooltip.block(); if (this.targetBlock_) { this.targetBlock_.select(); } - if (Blockly.utils.isRightButton(e)) { + if (utils.isRightButton(e)) { this.handleRightClick(e); return; } @@ -510,7 +517,7 @@ Gesture.prototype.doStart = function(e) { Blockly.longStart(e, this); } - this.mouseDownXY_ = new Blockly.utils.Coordinate(e.clientX, e.clientY); + this.mouseDownXY_ = new Coordinate(e.clientX, e.clientY); this.healStack_ = e.altKey || e.ctrlKey || e.metaKey; this.bindMouseEvents(e); @@ -522,9 +529,9 @@ Gesture.prototype.doStart = function(e) { * @package */ Gesture.prototype.bindMouseEvents = function(e) { - this.onMoveWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMoveWrapper_ = browserEvents.conditionalBind( document, 'mousemove', null, this.handleMove.bind(this)); - this.onUpWrapper_ = Blockly.browserEvents.conditionalBind( + this.onUpWrapper_ = browserEvents.conditionalBind( document, 'mouseup', null, this.handleUp.bind(this)); e.preventDefault(); @@ -644,7 +651,7 @@ Gesture.prototype.handleRightClick = function(e) { /** * Handle a mousedown/touchstart event on a workspace. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.WorkspaceSvg} ws The workspace the event hit. + * @param {!WorkspaceSvg} ws The workspace the event hit. * @package */ Gesture.prototype.handleWsStart = function(e, ws) { @@ -660,18 +667,18 @@ Gesture.prototype.handleWsStart = function(e, ws) { /** * Fires a workspace click event. - * @param {!Blockly.WorkspaceSvg} ws The workspace that a user clicks on. + * @param {!WorkspaceSvg} ws The workspace that a user clicks on. * @private */ Gesture.prototype.fireWorkspaceClick_ = function(ws) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.CLICK))( + Events.fire(new (Events.get(Events.CLICK))( null, ws.id, 'workspace')); }; /** * Handle a mousedown/touchstart event on a flyout. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.IFlyout} flyout The flyout the event hit. + * @param {!IFlyout} flyout The flyout the event hit. * @package */ Gesture.prototype.handleFlyoutStart = function(e, flyout) { @@ -687,7 +694,7 @@ Gesture.prototype.handleFlyoutStart = function(e, flyout) { /** * Handle a mousedown/touchstart event on a block. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.BlockSvg} block The block the event hit. + * @param {!BlockSvg} block The block the event hit. * @package */ Gesture.prototype.handleBlockStart = function(e, block) { @@ -703,7 +710,7 @@ Gesture.prototype.handleBlockStart = function(e, block) { /** * Handle a mousedown/touchstart event on a bubble. * @param {!Event} e A mouse down or touch start event. - * @param {!Blockly.IBubble} bubble The bubble the event hit. + * @param {!IBubble} bubble The bubble the event hit. * @package */ Gesture.prototype.handleBubbleStart = function(e, bubble) { @@ -747,20 +754,20 @@ Gesture.prototype.doBlockClick_ = function() { // Block click in an autoclosing flyout. if (this.flyout_ && this.flyout_.autoClose) { if (this.targetBlock_.isEnabled()) { - if (!Blockly.Events.getGroup()) { - Blockly.Events.setGroup(true); + if (!Events.getGroup()) { + Events.setGroup(true); } const newBlock = this.flyout_.createBlock(this.targetBlock_); newBlock.scheduleSnapAndBump(); } } else { // Clicks events are on the start block, even if it was a shadow. - const event = new (Blockly.Events.get(Blockly.Events.CLICK))( + const event = new (Events.get(Events.CLICK))( this.startBlock_, this.startWorkspace_.id, 'block'); - Blockly.Events.fire(event); + Events.fire(event); } this.bringBlockToFront_(); - Blockly.Events.setGroup(false); + Events.setGroup(false); }; /** @@ -797,7 +804,7 @@ Gesture.prototype.bringBlockToFront_ = function() { /** * Record the field that a gesture started on. - * @param {Blockly.Field} field The field the gesture started on. + * @param {Field} field The field the gesture started on. * @package */ Gesture.prototype.setStartField = function(field) { @@ -813,7 +820,7 @@ Gesture.prototype.setStartField = function(field) { /** * Record the bubble that a gesture started on - * @param {Blockly.IBubble} bubble The bubble the gesture started on. + * @param {IBubble} bubble The bubble the gesture started on. * @package */ Gesture.prototype.setStartBubble = function(bubble) { @@ -825,7 +832,7 @@ Gesture.prototype.setStartBubble = function(bubble) { /** * Record the block that a gesture started on, and set the target block * appropriately. - * @param {Blockly.BlockSvg} block The block the gesture started on. + * @param {BlockSvg} block The block the gesture started on. * @package */ Gesture.prototype.setStartBlock = function(block) { @@ -844,7 +851,7 @@ Gesture.prototype.setStartBlock = function(block) { * Record the block that a gesture targets, meaning the block that will be * dragged if this turns into a drag. If this block is a shadow, that will be * its first non-shadow parent. - * @param {Blockly.BlockSvg} block The block the gesture targets. + * @param {BlockSvg} block The block the gesture targets. * @private */ Gesture.prototype.setTargetBlock_ = function(block) { @@ -857,7 +864,7 @@ Gesture.prototype.setTargetBlock_ = function(block) { /** * Record the workspace that a gesture started on. - * @param {Blockly.WorkspaceSvg} ws The workspace the gesture started on. + * @param {WorkspaceSvg} ws The workspace the gesture started on. * @private */ Gesture.prototype.setStartWorkspace_ = function(ws) { @@ -868,7 +875,7 @@ Gesture.prototype.setStartWorkspace_ = function(ws) { /** * Record the flyout that a gesture started on. - * @param {Blockly.IFlyout} flyout The flyout the gesture started on. + * @param {IFlyout} flyout The flyout the gesture started on. * @private */ Gesture.prototype.setStartFlyout_ = function(flyout) { @@ -961,7 +968,7 @@ Gesture.prototype.hasStarted = function() { /** * Get a list of the insertion markers that currently exist. Block drags have * 0, 1, or 2 insertion markers. - * @return {!Array} A possibly empty list of insertion + * @return {!Array} A possibly empty list of insertion * marker blocks. * @package */ @@ -975,7 +982,7 @@ Gesture.prototype.getInsertionMarkers = function() { /** * Gets the current dragger if an item is being dragged. Null if nothing is * being dragged. - * @return {!Blockly.WorkspaceDragger|!Blockly.BubbleDragger|!Blockly.IBlockDragger|null} + * @return {!WorkspaceDragger|!BubbleDragger|!IBlockDragger|null} * The dragger that is currently in use or null if no drag is in progress. */ Gesture.prototype.getCurrentDragger = function() { @@ -994,7 +1001,7 @@ Gesture.prototype.getCurrentDragger = function() { * @return {boolean} True if gesture is occurring. */ Gesture.inProgress = function() { - const workspaces = Blockly.Workspace.getAll(); + const workspaces = Workspace.getAll(); for (let i = 0, workspace; (workspace = workspaces[i]); i++) { if (workspace.currentGesture_) { return true; From 46c0050ce6f4ec2bbc5a87c3e4e2adf9b4b72aaf Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 18:48:02 -0700 Subject: [PATCH 331/833] clang-format core/gesture.js --- core/gesture.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/gesture.js b/core/gesture.js index c74efb2f4..933930e44 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -299,13 +299,11 @@ Gesture.prototype.updateDragDelta_ = function(currentXY) { /** @type {!Coordinate} */ (this.mouseDownXY_)); if (!this.hasExceededDragRadius_) { - const currentDragDelta = - Coordinate.magnitude(this.currentDragDeltaXY_); + const currentDragDelta = Coordinate.magnitude(this.currentDragDeltaXY_); // The flyout has a different drag radius from the rest of Blockly. - const limitRadius = this.flyout_ ? - internalConstants.FLYOUT_DRAG_RADIUS : - internalConstants.DRAG_RADIUS; + const limitRadius = this.flyout_ ? internalConstants.FLYOUT_DRAG_RADIUS : + internalConstants.DRAG_RADIUS; this.hasExceededDragRadius_ = currentDragDelta > limitRadius; return this.hasExceededDragRadius_; @@ -449,8 +447,7 @@ Gesture.prototype.updateIsDragging_ = function() { */ Gesture.prototype.startDraggingBlock_ = function() { const BlockDraggerClass = registry.getClassFromOptions( - registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, - true); + registry.Type.BLOCK_DRAGGER, this.creatorWorkspace_.options, true); this.blockDragger_ = new BlockDraggerClass( /** @type {!BlockSvg} */ (this.targetBlock_), @@ -548,8 +545,7 @@ Gesture.prototype.handleMove = function(e) { if (this.isDraggingWorkspace_) { this.workspaceDragger_.drag(this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { - this.blockDragger_.drag( - this.mostRecentEvent_, this.currentDragDeltaXY_); + this.blockDragger_.drag(this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingBubble_) { this.bubbleDragger_.dragBubble( this.mostRecentEvent_, this.currentDragDeltaXY_); @@ -616,8 +612,7 @@ Gesture.prototype.cancel = function() { this.bubbleDragger_.endBubbleDrag( this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingBlock_) { - this.blockDragger_.endDrag( - this.mostRecentEvent_, this.currentDragDeltaXY_); + this.blockDragger_.endDrag(this.mostRecentEvent_, this.currentDragDeltaXY_); } else if (this.isDraggingWorkspace_) { this.workspaceDragger_.endDrag(this.currentDragDeltaXY_); } @@ -671,8 +666,7 @@ Gesture.prototype.handleWsStart = function(e, ws) { * @private */ Gesture.prototype.fireWorkspaceClick_ = function(ws) { - Events.fire(new (Events.get(Events.CLICK))( - null, ws.id, 'workspace')); + Events.fire(new (Events.get(Events.CLICK))(null, ws.id, 'workspace')); }; /** From 6c40e05dc83973d108a4baf1b7997745b8b81140 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:46:35 -0700 Subject: [PATCH 332/833] Migrate core/registry.js to named requires --- core/registry.js | 62 +++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/core/registry.js b/core/registry.js index 9d7d72201..8c29a6e3e 100644 --- a/core/registry.js +++ b/core/registry.js @@ -14,18 +14,30 @@ goog.module('Blockly.registry'); goog.module.declareLegacyNamespace(); -goog.requireType('Blockly.blockRendering.Renderer'); -goog.requireType('Blockly.Cursor'); -goog.requireType('Blockly.Events.Abstract'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IBlockDragger'); -goog.requireType('Blockly.IConnectionChecker'); -goog.requireType('Blockly.IFlyout'); -goog.requireType('Blockly.IMetricsManager'); -goog.requireType('Blockly.IToolbox'); -goog.requireType('Blockly.Options'); -goog.requireType('Blockly.Theme'); -goog.requireType('Blockly.ToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ +const Abstract = goog.requireType('Blockly.Events.Abstract'); +/* eslint-disable-next-line no-unused-vars */ +const Cursor = goog.requireType('Blockly.Cursor'); +/* eslint-disable-next-line no-unused-vars */ +const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ +const IBlockDragger = goog.requireType('Blockly.IBlockDragger'); +/* eslint-disable-next-line no-unused-vars */ +const IConnectionChecker = goog.requireType('Blockly.IConnectionChecker'); +/* eslint-disable-next-line no-unused-vars */ +const IFlyout = goog.requireType('Blockly.IFlyout'); +/* eslint-disable-next-line no-unused-vars */ +const IMetricsManager = goog.requireType('Blockly.IMetricsManager'); +/* eslint-disable-next-line no-unused-vars */ +const IToolbox = goog.requireType('Blockly.IToolbox'); +/* eslint-disable-next-line no-unused-vars */ +const Options = goog.requireType('Blockly.Options'); +/* eslint-disable-next-line no-unused-vars */ +const Renderer = goog.requireType('Blockly.blockRendering.Renderer'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const ToolboxItem = goog.requireType('Blockly.ToolboxItem'); /** @@ -70,44 +82,44 @@ Type.prototype.toString = function() { return this.name_; }; -/** @type {!Type} */ +/** @type {!Type} */ Type.CONNECTION_CHECKER = new Type('connectionChecker'); -/** @type {!Type} */ +/** @type {!Type} */ Type.CURSOR = new Type('cursor'); -/** @type {!Type} */ +/** @type {!Type} */ Type.EVENT = new Type('event'); -/** @type {!Type} */ +/** @type {!Type} */ Type.FIELD = new Type('field'); -/** @type {!Type} */ +/** @type {!Type} */ Type.RENDERER = new Type('renderer'); -/** @type {!Type} */ +/** @type {!Type} */ Type.TOOLBOX = new Type('toolbox'); -/** @type {!Type} */ +/** @type {!Type} */ Type.THEME = new Type('theme'); -/** @type {!Type} */ +/** @type {!Type} */ Type.TOOLBOX_ITEM = new Type('toolboxItem'); -/** @type {!Type} */ +/** @type {!Type} */ Type.FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); -/** @type {!Type} */ +/** @type {!Type} */ Type.FLYOUTS_HORIZONTAL_TOOLBOX = new Type('flyoutsHorizontalToolbox'); -/** @type {!Type} */ +/** @type {!Type} */ Type.METRICS_MANAGER = new Type('metricsManager'); -/** @type {!Type} */ +/** @type {!Type} */ Type.BLOCK_DRAGGER = new Type('blockDragger'); @@ -286,7 +298,7 @@ exports.getObject = getObject; * Gets the class from Blockly options for the given type. * This is used for plugins that override a built in feature. (e.g. Toolbox) * @param {!Type} type The type of the plugin. - * @param {!Blockly.Options} options The option object to check for the given + * @param {!Options} options The option object to check for the given * plugin. * @param {boolean=} opt_throwIfMissing Whether or not to throw an error if we * are unable to find the plugin. From e0efd4cf29293dd5ee348ccde3674c171be8905a Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:47:06 -0700 Subject: [PATCH 333/833] clang-format core/registry.js --- core/registry.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/core/registry.js b/core/registry.js index 8c29a6e3e..1be9b2a2b 100644 --- a/core/registry.js +++ b/core/registry.js @@ -83,8 +83,7 @@ Type.prototype.toString = function() { }; /** @type {!Type} */ -Type.CONNECTION_CHECKER = - new Type('connectionChecker'); +Type.CONNECTION_CHECKER = new Type('connectionChecker'); /** @type {!Type} */ Type.CURSOR = new Type('cursor'); @@ -108,20 +107,16 @@ Type.THEME = new Type('theme'); Type.TOOLBOX_ITEM = new Type('toolboxItem'); /** @type {!Type} */ -Type.FLYOUTS_VERTICAL_TOOLBOX = - new Type('flyoutsVerticalToolbox'); +Type.FLYOUTS_VERTICAL_TOOLBOX = new Type('flyoutsVerticalToolbox'); /** @type {!Type} */ -Type.FLYOUTS_HORIZONTAL_TOOLBOX = - new Type('flyoutsHorizontalToolbox'); +Type.FLYOUTS_HORIZONTAL_TOOLBOX = new Type('flyoutsHorizontalToolbox'); /** @type {!Type} */ -Type.METRICS_MANAGER = - new Type('metricsManager'); +Type.METRICS_MANAGER = new Type('metricsManager'); /** @type {!Type} */ -Type.BLOCK_DRAGGER = - new Type('blockDragger'); +Type.BLOCK_DRAGGER = new Type('blockDragger'); /** * Registers a class based on a type and name. @@ -137,8 +132,7 @@ Type.BLOCK_DRAGGER = * it's type. * @template T */ -const register = function( - type, name, registryItem, opt_allowOverrides) { +const register = function(type, name, registryItem, opt_allowOverrides) { if ((!(type instanceof Type) && typeof type != 'string') || String(type).trim() == '') { throw Error( @@ -203,8 +197,9 @@ const unregister = function(type, name) { name = name.toLowerCase(); const typeRegistry = typeMap[type]; if (!typeRegistry || !typeRegistry[name]) { - console.warn('Unable to unregister [' + name + '][' + type + '] from the ' + - 'registry.'); + console.warn( + 'Unable to unregister [' + name + '][' + type + '] from the ' + + 'registry.'); return; } delete typeMap[type][name]; @@ -230,8 +225,8 @@ const getItem = function(type, name, opt_throwIfMissing) { if (!typeRegistry || !typeRegistry[name]) { const msg = 'Unable to find [' + name + '][' + type + '] in the registry.'; if (opt_throwIfMissing) { - throw new Error(msg + ' You must require or register a ' + type + - ' plugin.'); + throw new Error( + msg + ' You must require or register a ' + type + ' plugin.'); } else { console.warn(msg); } @@ -274,7 +269,7 @@ exports.hasItem = hasItem; */ const getClass = function(type, name, opt_throwIfMissing) { return /** @type {?function(new:T, ...?)} */ ( - getItem(type, name, opt_throwIfMissing)); + getItem(type, name, opt_throwIfMissing)); }; exports.getClass = getClass; @@ -289,8 +284,7 @@ exports.getClass = getClass; * @template T */ const getObject = function(type, name, opt_throwIfMissing) { - return /** @type {T} */ ( - getItem(type, name, opt_throwIfMissing)); + return /** @type {T} */ (getItem(type, name, opt_throwIfMissing)); }; exports.getObject = getObject; @@ -305,8 +299,7 @@ exports.getObject = getObject; * @return {?function(new:T, ...?)} The class for the plugin. * @template T */ -const getClassFromOptions = function(type, options, - opt_throwIfMissing) { +const getClassFromOptions = function(type, options, opt_throwIfMissing) { const typeName = type.toString(); const plugin = options.plugins[typeName] || DEFAULT; From a663b1225b8f7fe4fd534187e5e5d28324498334 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:50:47 -0700 Subject: [PATCH 334/833] Move @package annotation to export for core/marker_manager.js --- core/marker_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/marker_manager.js b/core/marker_manager.js index 1f16f500a..60cb3b870 100644 --- a/core/marker_manager.js +++ b/core/marker_manager.js @@ -25,7 +25,6 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * Class to manage the multiple markers and the cursor on a workspace. * @param {!WorkspaceSvg} workspace The workspace for the marker manager. * @constructor - * @package */ const MarkerManager = function(workspace) { /** @@ -195,4 +194,5 @@ MarkerManager.prototype.dispose = function() { } }; +/** @package */ exports = MarkerManager; From d5f729e636b2c318b820b79afceabcfbfc74e1d1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:56:57 -0700 Subject: [PATCH 335/833] Migrate core/rendered_connection.js to ES6 const/let --- core/rendered_connection.js | 88 ++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index cddda9200..11c7a9a6d 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -135,8 +135,8 @@ Blockly.RenderedConnection.prototype.targetBlock = function() { * @return {number} The distance between connections, in workspace units. */ Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) { - var xDiff = this.x - otherConnection.x; - var yDiff = this.y - otherConnection.y; + const xDiff = this.x - otherConnection.x; + const yDiff = this.y - otherConnection.y; return Math.sqrt(xDiff * xDiff + yDiff * yDiff); }; @@ -153,12 +153,12 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { return; } // Move the root block. - var rootBlock = this.sourceBlock_.getRootBlock(); + let rootBlock = this.sourceBlock_.getRootBlock(); if (rootBlock.isInFlyout) { // Don't move blocks around in a flyout. return; } - var reverse = false; + let reverse = false; if (!rootBlock.isMovable()) { // Can't bump an uneditable block away. // Check to see if the other block is movable. @@ -171,13 +171,13 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { reverse = true; } // Raise it to the top for extra visibility. - var selected = Blockly.selected == rootBlock; + const selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - var dx = + let dx = (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - this.x; - var dy = + let dy = (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - this.y; @@ -257,16 +257,16 @@ Blockly.RenderedConnection.prototype.getOffsetInBlock = function() { * @package */ Blockly.RenderedConnection.prototype.tighten = function() { - var dx = this.targetConnection.x - this.x; - var dy = this.targetConnection.y - this.y; + const dx = this.targetConnection.x - this.x; + const dy = this.targetConnection.y - this.y; if (dx != 0 || dy != 0) { - var block = this.targetBlock(); - var svgRoot = block.getSvgRoot(); + const block = this.targetBlock(); + const svgRoot = block.getSvgRoot(); if (!svgRoot) { throw Error('block is not rendered.'); } // Workspace coordinates. - var xy = Blockly.utils.getRelativeXY(svgRoot); + const xy = Blockly.utils.getRelativeXY(svgRoot); block.getSvgRoot().setAttribute('transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block.moveConnections(-dx, -dy); @@ -291,20 +291,20 @@ Blockly.RenderedConnection.prototype.closest = function(maxLimit, dxy) { * Add highlighting around this connection. */ Blockly.RenderedConnection.prototype.highlight = function() { - var steps; - var sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); - var renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); - var shape = renderConstants.shapeFor(this); + let steps; + const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); + const shape = renderConstants.shapeFor(this); if (this.type == Blockly.connectionTypes.INPUT_VALUE || this.type == Blockly.connectionTypes.OUTPUT_VALUE) { // Vertical line, puzzle tab, vertical line. - var yLen = renderConstants.TAB_OFFSET_FROM_TOP; + const yLen = renderConstants.TAB_OFFSET_FROM_TOP; steps = Blockly.utils.svgPaths.moveBy(0, -yLen) + Blockly.utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown + Blockly.utils.svgPaths.lineOnAxis('v', yLen); } else { - var xLen = + const xLen = renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. steps = Blockly.utils.svgPaths.moveBy(-xLen, 0) + @@ -312,9 +312,9 @@ Blockly.RenderedConnection.prototype.highlight = function() { shape.pathLeft + Blockly.utils.svgPaths.lineOnAxis('h', xLen); } - var xy = this.sourceBlock_.getRelativeToSurfaceXY(); - var x = this.x - xy.x; - var y = this.y - xy.y; + const xy = this.sourceBlock_.getRelativeToSurfaceXY(); + const x = this.x - xy.x; + const y = this.y - xy.y; Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATH, { @@ -372,17 +372,17 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { Blockly.RenderedConnection.prototype.stopTrackingAll = function() { this.setTracking(false); if (this.targetConnection) { - var blocks = this.targetBlock().getDescendants(false); - for (var i = 0; i < blocks.length; i++) { - var block = blocks[i]; + const blocks = this.targetBlock().getDescendants(false); + for (let i = 0; i < blocks.length; i++) { + const block = blocks[i]; // Stop tracking connections of all children. - var connections = block.getConnections_(true); - for (var j = 0; j < connections.length; j++) { + const connections = block.getConnections_(true); + for (let j = 0; j < connections.length; j++) { connections[j].setTracking(false); } // Close all bubbles of all children. - var icons = block.getIcons(); - for (var j = 0; j < icons.length; j++) { + const icons = block.getIcons(); + for (let j = 0; j < icons.length; j++) { icons[j].setVisible(false); } } @@ -400,15 +400,15 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() { // rendering takes place, since rendering requires knowing the dimensions // of lower blocks. Also, since rendering a block renders all its parents, // we only need to render the leaf nodes. - var renderList = []; + const renderList = []; if (this.type != Blockly.connectionTypes.INPUT_VALUE && this.type != Blockly.connectionTypes.NEXT_STATEMENT) { // Only spider down. return renderList; } - var block = this.targetBlock(); + const block = this.targetBlock(); if (block) { - var connections; + let connections; if (block.isCollapsed()) { // This block should only be partially revealed since it is collapsed. connections = []; @@ -419,7 +419,7 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() { // Show all connections of this block. connections = block.getConnections_(true); } - for (var i = 0; i < connections.length; i++) { + for (let i = 0; i < connections.length; i++) { renderList.push.apply(renderList, connections[i].startTrackingAll()); } if (!renderList.length) { @@ -463,9 +463,9 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, */ Blockly.RenderedConnection.prototype.onFailedConnect = function(otherConnection) { - var block = this.getSourceBlock(); + const block = this.getSourceBlock(); if (Blockly.Events.recordUndo) { - var group = Blockly.Events.getGroup(); + const group = Blockly.Events.getGroup(); setTimeout(function() { if (!block.isDisposed() && !block.getParent()) { Blockly.Events.setGroup(group); @@ -508,7 +508,7 @@ Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, */ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { Blockly.RenderedConnection.superClass_.respawnShadow_.call(this); - var blockShadow = this.targetBlock(); + const blockShadow = this.targetBlock(); if (!blockShadow) { // This connection must not have a shadowDom_. return; @@ -516,7 +516,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { blockShadow.initSvg(); blockShadow.render(false); - var parentBlock = this.getSourceBlock(); + const parentBlock = this.getSourceBlock(); if (parentBlock.rendered) { parentBlock.render(); } @@ -543,11 +543,11 @@ Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) { Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection); - var parentConnection = this; - var parentBlock = parentConnection.getSourceBlock(); - var childBlock = childConnection.getSourceBlock(); - var parentRendered = parentBlock.rendered; - var childRendered = childBlock.rendered; + const parentConnection = this; + const parentBlock = parentConnection.getSourceBlock(); + const childBlock = childConnection.getSourceBlock(); + const parentRendered = parentBlock.rendered; + const childRendered = childBlock.rendered; if (parentRendered) { parentBlock.updateDisabled(); @@ -569,9 +569,9 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { } // The input the child block is connected to (if any). - var parentInput = parentBlock.getInputWithBlock(childBlock); + const parentInput = parentBlock.getInputWithBlock(childBlock); if (parentInput) { - var visible = parentInput.isVisible(); + const visible = parentInput.isVisible(); childBlock.getSvgRoot().style.display = visible ? 'block' : 'none'; } }; @@ -585,7 +585,7 @@ Blockly.RenderedConnection.prototype.onCheckChanged_ = function() { if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( this, this.targetConnection, false))) { - var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; + const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); // Bump away. this.sourceBlock_.bumpNeighbours(); From 07b2e07ba88903ff385ebdc595c59f9eab9f9a95 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 09:59:41 -0700 Subject: [PATCH 336/833] Migrate core/rendered_connection.js to goog.module --- core/rendered_connection.js | 99 +++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 11c7a9a6d..a4d265746 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.RenderedConnection'); +goog.module('Blockly.RenderedConnection'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Connection'); goog.require('Blockly.connectionTypes'); @@ -34,8 +35,8 @@ goog.requireType('Blockly.ConnectionDB'); * @extends {Blockly.Connection} * @constructor */ -Blockly.RenderedConnection = function(source, type) { - Blockly.RenderedConnection.superClass_.constructor.call(this, source, type); +const RenderedConnection = function(source, type) { + RenderedConnection.superClass_.constructor.call(this, source, type); /** * Connection database for connections of this type on the current workspace. @@ -63,18 +64,18 @@ Blockly.RenderedConnection = function(source, type) { /** * Describes the state of this connection's tracked-ness. - * @type {Blockly.RenderedConnection.TrackedState} + * @type {RenderedConnection.TrackedState} * @private */ - this.trackedState_ = Blockly.RenderedConnection.TrackedState.WILL_TRACK; + this.trackedState_ = RenderedConnection.TrackedState.WILL_TRACK; /** * Connection this connection connects to. Null if not connected. - * @type {Blockly.RenderedConnection} + * @type {RenderedConnection} */ this.targetConnection = null; }; -Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); +Blockly.utils.object.inherits(RenderedConnection, Blockly.Connection); /** * Enum for different kinds of tracked states. @@ -88,7 +89,7 @@ Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); * TRACKED means that this connection is currently being tracked. * @enum {number} */ -Blockly.RenderedConnection.TrackedState = { +RenderedConnection.TrackedState = { WILL_TRACK: -1, UNTRACKED: 0, TRACKED: 1 @@ -100,9 +101,9 @@ Blockly.RenderedConnection.TrackedState = { * @override * @package */ -Blockly.RenderedConnection.prototype.dispose = function() { - Blockly.RenderedConnection.superClass_.dispose.call(this); - if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) { +RenderedConnection.prototype.dispose = function() { + RenderedConnection.superClass_.dispose.call(this); + if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); } }; @@ -112,9 +113,9 @@ Blockly.RenderedConnection.prototype.dispose = function() { * @return {!Blockly.BlockSvg} The source block. * @override */ -Blockly.RenderedConnection.prototype.getSourceBlock = function() { +RenderedConnection.prototype.getSourceBlock = function() { return /** @type {!Blockly.BlockSvg} */ ( - Blockly.RenderedConnection.superClass_.getSourceBlock.call(this)); + RenderedConnection.superClass_.getSourceBlock.call(this)); }; /** @@ -122,9 +123,9 @@ Blockly.RenderedConnection.prototype.getSourceBlock = function() { * @return {?Blockly.BlockSvg} The connected block or null if none is connected. * @override */ -Blockly.RenderedConnection.prototype.targetBlock = function() { +RenderedConnection.prototype.targetBlock = function() { return /** @type {Blockly.BlockSvg} */ ( - Blockly.RenderedConnection.superClass_.targetBlock.call(this)); + RenderedConnection.superClass_.targetBlock.call(this)); }; /** @@ -134,7 +135,7 @@ Blockly.RenderedConnection.prototype.targetBlock = function() { * the distance to. * @return {number} The distance between connections, in workspace units. */ -Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) { +RenderedConnection.prototype.distanceFrom = function(otherConnection) { const xDiff = this.x - otherConnection.x; const yDiff = this.y - otherConnection.y; return Math.sqrt(xDiff * xDiff + yDiff * yDiff); @@ -147,7 +148,7 @@ Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) { * from. * @package */ -Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { +RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { if (this.sourceBlock_.workspace.isDragging()) { // Don't move blocks around while the user is doing the same. return; @@ -200,11 +201,11 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { * @param {number} x New absolute x coordinate, in workspace coordinates. * @param {number} y New absolute y coordinate, in workspace coordinates. */ -Blockly.RenderedConnection.prototype.moveTo = function(x, y) { - if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.WILL_TRACK) { +RenderedConnection.prototype.moveTo = function(x, y) { + if (this.trackedState_ == RenderedConnection.TrackedState.WILL_TRACK) { this.db_.addConnection(this, y); - this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED; - } else if (this.trackedState_ == Blockly.RenderedConnection + this.trackedState_ = RenderedConnection.TrackedState.TRACKED; + } else if (this.trackedState_ == RenderedConnection .TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); this.db_.addConnection(this, y); @@ -218,7 +219,7 @@ Blockly.RenderedConnection.prototype.moveTo = function(x, y) { * @param {number} dx Change to x coordinate, in workspace units. * @param {number} dy Change to y coordinate, in workspace units. */ -Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) { +RenderedConnection.prototype.moveBy = function(dx, dy) { this.moveTo(this.x + dx, this.y + dy); }; @@ -228,7 +229,7 @@ Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) { * @param {!Blockly.utils.Coordinate} blockTL The location of the top left * corner of the block, in workspace coordinates. */ -Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) { +RenderedConnection.prototype.moveToOffset = function(blockTL) { this.moveTo(blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y); }; @@ -238,7 +239,7 @@ Blockly.RenderedConnection.prototype.moveToOffset = function(blockTL) { * @param {number} x The new relative x, in workspace units. * @param {number} y The new relative y, in workspace units. */ -Blockly.RenderedConnection.prototype.setOffsetInBlock = function(x, y) { +RenderedConnection.prototype.setOffsetInBlock = function(x, y) { this.offsetInBlock_.x = x; this.offsetInBlock_.y = y; }; @@ -248,7 +249,7 @@ Blockly.RenderedConnection.prototype.setOffsetInBlock = function(x, y) { * @return {!Blockly.utils.Coordinate} The offset of the connection. * @package */ -Blockly.RenderedConnection.prototype.getOffsetInBlock = function() { +RenderedConnection.prototype.getOffsetInBlock = function() { return this.offsetInBlock_; }; @@ -256,7 +257,7 @@ Blockly.RenderedConnection.prototype.getOffsetInBlock = function() { * Move the blocks on either side of this connection right next to each other. * @package */ -Blockly.RenderedConnection.prototype.tighten = function() { +RenderedConnection.prototype.tighten = function() { const dx = this.targetConnection.x - this.x; const dy = this.targetConnection.y - this.y; if (dx != 0 || dy != 0) { @@ -283,14 +284,14 @@ Blockly.RenderedConnection.prototype.tighten = function() { * properties: 'connection' which is either another connection or null, * and 'radius' which is the distance. */ -Blockly.RenderedConnection.prototype.closest = function(maxLimit, dxy) { +RenderedConnection.prototype.closest = function(maxLimit, dxy) { return this.dbOpposite_.searchForClosest(this, maxLimit, dxy); }; /** * Add highlighting around this connection. */ -Blockly.RenderedConnection.prototype.highlight = function() { +RenderedConnection.prototype.highlight = function() { let steps; const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); @@ -329,7 +330,7 @@ Blockly.RenderedConnection.prototype.highlight = function() { /** * Remove the highlighting around this connection. */ -Blockly.RenderedConnection.prototype.unhighlight = function() { +RenderedConnection.prototype.unhighlight = function() { Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); delete Blockly.Connection.highlightedPath_; }; @@ -339,11 +340,11 @@ Blockly.RenderedConnection.prototype.unhighlight = function() { * @param {boolean} doTracking If true, start tracking. If false, stop tracking. * @package */ -Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { +RenderedConnection.prototype.setTracking = function(doTracking) { if ((doTracking && this.trackedState_ == - Blockly.RenderedConnection.TrackedState.TRACKED) || + RenderedConnection.TrackedState.TRACKED) || (!doTracking && this.trackedState_ == - Blockly.RenderedConnection.TrackedState.UNTRACKED)) { + RenderedConnection.TrackedState.UNTRACKED)) { return; } if (this.sourceBlock_.isInFlyout) { @@ -352,13 +353,13 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { } if (doTracking) { this.db_.addConnection(this, this.y); - this.trackedState_ = Blockly.RenderedConnection.TrackedState.TRACKED; + this.trackedState_ = RenderedConnection.TrackedState.TRACKED; return; } - if (this.trackedState_ == Blockly.RenderedConnection.TrackedState.TRACKED) { + if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); } - this.trackedState_ = Blockly.RenderedConnection.TrackedState.UNTRACKED; + this.trackedState_ = RenderedConnection.TrackedState.UNTRACKED; }; /** @@ -369,7 +370,7 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) { * Also closes down-stream icons/bubbles. * @package */ -Blockly.RenderedConnection.prototype.stopTrackingAll = function() { +RenderedConnection.prototype.stopTrackingAll = function() { this.setTracking(false); if (this.targetConnection) { const blocks = this.targetBlock().getDescendants(false); @@ -394,7 +395,7 @@ Blockly.RenderedConnection.prototype.stopTrackingAll = function() { * any block attached to this connection. This happens when a block is expanded. * @return {!Array} List of blocks to render. */ -Blockly.RenderedConnection.prototype.startTrackingAll = function() { +RenderedConnection.prototype.startTrackingAll = function() { this.setTracking(true); // All blocks that are not tracked must start tracking before any // rendering takes place, since rendering requires knowing the dimensions @@ -438,7 +439,7 @@ Blockly.RenderedConnection.prototype.startTrackingAll = function() { * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020 */ -Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, +RenderedConnection.prototype.isConnectionAllowed = function(candidate, maxRadius) { Blockly.utils.deprecation.warn( 'RenderedConnection.prototype.isConnectionAllowed', @@ -449,7 +450,7 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, return false; } - return Blockly.RenderedConnection.superClass_.isConnectionAllowed.call(this, + return RenderedConnection.superClass_.isConnectionAllowed.call(this, candidate); }; @@ -461,7 +462,7 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate, * failed to connect to. * @package */ -Blockly.RenderedConnection.prototype.onFailedConnect = +RenderedConnection.prototype.onFailedConnect = function(otherConnection) { const block = this.getSourceBlock(); if (Blockly.Events.recordUndo) { @@ -484,9 +485,9 @@ Blockly.RenderedConnection.prototype.onFailedConnect = * @protected * @override */ -Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, +RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { - Blockly.RenderedConnection.superClass_.disconnectInternal_.call(this, + RenderedConnection.superClass_.disconnectInternal_.call(this, parentBlock, childBlock); // Rerender the parent so that it may reflow. if (parentBlock.rendered) { @@ -506,8 +507,8 @@ Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, * @protected * @override */ -Blockly.RenderedConnection.prototype.respawnShadow_ = function() { - Blockly.RenderedConnection.superClass_.respawnShadow_.call(this); +RenderedConnection.prototype.respawnShadow_ = function() { + RenderedConnection.superClass_.respawnShadow_.call(this); const blockShadow = this.targetBlock(); if (!blockShadow) { // This connection must not have a shadowDom_. @@ -530,7 +531,7 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() { * @return {!Array} List of connections. * @package */ -Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) { +RenderedConnection.prototype.neighbours = function(maxLimit) { return this.dbOpposite_.getNeighbours(this, maxLimit); }; @@ -540,8 +541,8 @@ Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) { * @param {!Blockly.Connection} childConnection Connection on inferior block. * @protected */ -Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { - Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection); +RenderedConnection.prototype.connect_ = function(childConnection) { + RenderedConnection.superClass_.connect_.call(this, childConnection); const parentConnection = this; const parentBlock = parentConnection.getSourceBlock(); @@ -580,7 +581,7 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { * Function to be called when this connection's compatible types have changed. * @protected */ -Blockly.RenderedConnection.prototype.onCheckChanged_ = function() { +RenderedConnection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. if (this.isConnected() && (!this.targetConnection || !this.getConnectionChecker().canConnect( @@ -591,3 +592,5 @@ Blockly.RenderedConnection.prototype.onCheckChanged_ = function() { this.sourceBlock_.bumpNeighbours(); } }; + +exports = RenderedConnection; diff --git a/tests/deps.js b/tests/deps.js index de575339f..367e41229 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); -goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); From c9225da3f3038f7965f9bb94de6aebdd09fa2185 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 10:38:47 -0700 Subject: [PATCH 337/833] Migrate core/rendered_connection.js to named requires --- core/rendered_connection.js | 139 ++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index a4d265746..953062f20 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -13,26 +13,29 @@ goog.module('Blockly.RenderedConnection'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Connection'); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.deprecation'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.ConnectionDB'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Connection = goog.require('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const ConnectionDB = goog.requireType('Blockly.ConnectionDB'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +const Svg = goog.require('Blockly.utils.Svg'); +const connectionTypes = goog.require('Blockly.connectionTypes'); +const deprecation = goog.require('Blockly.utils.deprecation'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const object = goog.require('Blockly.utils.object'); +const utils = goog.require('Blockly.utils'); /** * Class for a connection between blocks that may be rendered on screen. - * @param {!Blockly.BlockSvg} source The block establishing this connection. + * @param {!BlockSvg} source The block establishing this connection. * @param {number} type The type of the connection. - * @extends {Blockly.Connection} + * @extends {Connection} * @constructor */ const RenderedConnection = function(source, type) { @@ -40,7 +43,7 @@ const RenderedConnection = function(source, type) { /** * Connection database for connections of this type on the current workspace. - * @const {!Blockly.ConnectionDB} + * @const {!ConnectionDB} * @private */ this.db_ = source.workspace.connectionDBList[type]; @@ -48,19 +51,19 @@ const RenderedConnection = function(source, type) { /** * Connection database for connections compatible with this type on the * current workspace. - * @const {!Blockly.ConnectionDB} + * @const {!ConnectionDB} * @private */ this.dbOpposite_ = source.workspace - .connectionDBList[Blockly.internalConstants.OPPOSITE_TYPE[type]]; + .connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @private */ - this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0); + this.offsetInBlock_ = new Coordinate(0, 0); /** * Describes the state of this connection's tracked-ness. @@ -75,7 +78,7 @@ const RenderedConnection = function(source, type) { */ this.targetConnection = null; }; -Blockly.utils.object.inherits(RenderedConnection, Blockly.Connection); +object.inherits(RenderedConnection, Connection); /** * Enum for different kinds of tracked states. @@ -110,28 +113,28 @@ RenderedConnection.prototype.dispose = function() { /** * Get the source block for this connection. - * @return {!Blockly.BlockSvg} The source block. + * @return {!BlockSvg} The source block. * @override */ RenderedConnection.prototype.getSourceBlock = function() { - return /** @type {!Blockly.BlockSvg} */ ( + return /** @type {!BlockSvg} */ ( RenderedConnection.superClass_.getSourceBlock.call(this)); }; /** * Returns the block that this connection connects to. - * @return {?Blockly.BlockSvg} The connected block or null if none is connected. + * @return {?BlockSvg} The connected block or null if none is connected. * @override */ RenderedConnection.prototype.targetBlock = function() { - return /** @type {Blockly.BlockSvg} */ ( + return /** @type {BlockSvg} */ ( RenderedConnection.superClass_.targetBlock.call(this)); }; /** * Returns the distance between this connection and another connection in * workspace units. - * @param {!Blockly.Connection} otherConnection The other connection to measure + * @param {!Connection} otherConnection The other connection to measure * the distance to. * @return {number} The distance between connections, in workspace units. */ @@ -144,7 +147,7 @@ RenderedConnection.prototype.distanceFrom = function(otherConnection) { /** * Move the block(s) belonging to the connection to a point where they don't * visually interfere with the specified connection. - * @param {!Blockly.Connection} staticConnection The connection to move away + * @param {!Connection} staticConnection The connection to move away * from. * @package */ @@ -175,21 +178,21 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { const selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); let dx = - (staticConnection.x + Blockly.internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + (staticConnection.x + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; let dy = - (staticConnection.y + Blockly.internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + (staticConnection.y + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. dy = -dy; } if (rootBlock.RTL) { - dx = (staticConnection.x - Blockly.internalConstants.SNAP_RADIUS - + dx = (staticConnection.x - internalConstants.SNAP_RADIUS - Math.floor( - Math.random() * Blockly.internalConstants.BUMP_RANDOMNESS)) - + Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; } rootBlock.moveBy(dx, dy); @@ -226,7 +229,7 @@ RenderedConnection.prototype.moveBy = function(dx, dy) { /** * Move this connection to the location given by its offset within the block and * the location of the block's top left corner. - * @param {!Blockly.utils.Coordinate} blockTL The location of the top left + * @param {!Coordinate} blockTL The location of the top left * corner of the block, in workspace coordinates. */ RenderedConnection.prototype.moveToOffset = function(blockTL) { @@ -246,7 +249,7 @@ RenderedConnection.prototype.setOffsetInBlock = function(x, y) { /** * Get the offset of this connection relative to the top left of its block. - * @return {!Blockly.utils.Coordinate} The offset of the connection. + * @return {!Coordinate} The offset of the connection. * @package */ RenderedConnection.prototype.getOffsetInBlock = function() { @@ -267,7 +270,7 @@ RenderedConnection.prototype.tighten = function() { throw Error('block is not rendered.'); } // Workspace coordinates. - const xy = Blockly.utils.getRelativeXY(svgRoot); + const xy = utils.getRelativeXY(svgRoot); block.getSvgRoot().setAttribute('transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block.moveConnections(-dx, -dy); @@ -278,9 +281,9 @@ RenderedConnection.prototype.tighten = function() { * Find the closest compatible connection to this connection. * All parameters are in workspace units. * @param {number} maxLimit The maximum radius to another connection. - * @param {!Blockly.utils.Coordinate} dxy Offset between this connection's location + * @param {!Coordinate} dxy Offset between this connection's location * in the database and the current location (as a result of dragging). - * @return {!{connection: ?Blockly.Connection, radius: number}} Contains two + * @return {!{connection: ?Connection, radius: number}} Contains two * properties: 'connection' which is either another connection or null, * and 'radius' which is the distance. */ @@ -293,31 +296,31 @@ RenderedConnection.prototype.closest = function(maxLimit, dxy) { */ RenderedConnection.prototype.highlight = function() { let steps; - const sourceBlockSvg = /** @type {!Blockly.BlockSvg} */ (this.sourceBlock_); + const sourceBlockSvg = /** @type {!BlockSvg} */ (this.sourceBlock_); const renderConstants = sourceBlockSvg.workspace.getRenderer().getConstants(); const shape = renderConstants.shapeFor(this); - if (this.type == Blockly.connectionTypes.INPUT_VALUE || - this.type == Blockly.connectionTypes.OUTPUT_VALUE) { + if (this.type == connectionTypes.INPUT_VALUE || + this.type == connectionTypes.OUTPUT_VALUE) { // Vertical line, puzzle tab, vertical line. const yLen = renderConstants.TAB_OFFSET_FROM_TOP; - steps = Blockly.utils.svgPaths.moveBy(0, -yLen) + - Blockly.utils.svgPaths.lineOnAxis('v', yLen) + + steps = utils.svgPaths.moveBy(0, -yLen) + + utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown + - Blockly.utils.svgPaths.lineOnAxis('v', yLen); + utils.svgPaths.lineOnAxis('v', yLen); } else { const xLen = renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. - steps = Blockly.utils.svgPaths.moveBy(-xLen, 0) + - Blockly.utils.svgPaths.lineOnAxis('h', xLen) + + steps = utils.svgPaths.moveBy(-xLen, 0) + + utils.svgPaths.lineOnAxis('h', xLen) + shape.pathLeft + - Blockly.utils.svgPaths.lineOnAxis('h', xLen); + utils.svgPaths.lineOnAxis('h', xLen); } const xy = this.sourceBlock_.getRelativeToSurfaceXY(); const x = this.x - xy.x; const y = this.y - xy.y; - Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + Connection.highlightedPath_ = dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyHighlightedConnectionPath', 'd': steps, @@ -331,8 +334,8 @@ RenderedConnection.prototype.highlight = function() { * Remove the highlighting around this connection. */ RenderedConnection.prototype.unhighlight = function() { - Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); - delete Blockly.Connection.highlightedPath_; + dom.removeNode(Connection.highlightedPath_); + delete Connection.highlightedPath_; }; /** @@ -393,7 +396,7 @@ RenderedConnection.prototype.stopTrackingAll = function() { /** * Start tracking this connection, as well as all down-stream connections on * any block attached to this connection. This happens when a block is expanded. - * @return {!Array} List of blocks to render. + * @return {!Array} List of blocks to render. */ RenderedConnection.prototype.startTrackingAll = function() { this.setTracking(true); @@ -402,8 +405,8 @@ RenderedConnection.prototype.startTrackingAll = function() { // of lower blocks. Also, since rendering a block renders all its parents, // we only need to render the leaf nodes. const renderList = []; - if (this.type != Blockly.connectionTypes.INPUT_VALUE && - this.type != Blockly.connectionTypes.NEXT_STATEMENT) { + if (this.type != connectionTypes.INPUT_VALUE && + this.type != connectionTypes.NEXT_STATEMENT) { // Only spider down. return renderList; } @@ -433,7 +436,7 @@ RenderedConnection.prototype.startTrackingAll = function() { /** * Check if the two connections can be dragged to connect to each other. - * @param {!Blockly.Connection} candidate A nearby connection to check. + * @param {!Connection} candidate A nearby connection to check. * @param {number=} maxRadius The maximum radius allowed for connections, in * workspace units. * @return {boolean} True if the connection is allowed, false otherwise. @@ -441,7 +444,7 @@ RenderedConnection.prototype.startTrackingAll = function() { */ RenderedConnection.prototype.isConnectionAllowed = function(candidate, maxRadius) { - Blockly.utils.deprecation.warn( + deprecation.warn( 'RenderedConnection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', @@ -458,30 +461,30 @@ RenderedConnection.prototype.isConnectionAllowed = function(candidate, * Behavior after a connection attempt fails. * Bumps this connection away from the other connection. Called when an * attempted connection fails. - * @param {!Blockly.Connection} otherConnection Connection that this connection + * @param {!Connection} otherConnection Connection that this connection * failed to connect to. * @package */ RenderedConnection.prototype.onFailedConnect = function(otherConnection) { const block = this.getSourceBlock(); - if (Blockly.Events.recordUndo) { - const group = Blockly.Events.getGroup(); + if (Events.recordUndo) { + const group = Events.getGroup(); setTimeout(function() { if (!block.isDisposed() && !block.getParent()) { - Blockly.Events.setGroup(group); + Events.setGroup(group); this.bumpAwayFrom(otherConnection); - Blockly.Events.setGroup(false); + Events.setGroup(false); } - }.bind(this), Blockly.internalConstants.BUMP_DELAY); + }.bind(this), internalConstants.BUMP_DELAY); } }; /** * Disconnect two blocks that are connected by this connection. - * @param {!Blockly.Block} parentBlock The superior block. - * @param {!Blockly.Block} childBlock The inferior block. + * @param {!Block} parentBlock The superior block. + * @param {!Block} childBlock The inferior block. * @protected * @override */ @@ -528,7 +531,7 @@ RenderedConnection.prototype.respawnShadow_ = function() { * Type checking does not apply, since this function is used for bumping. * @param {number} maxLimit The maximum radius to another connection, in * workspace units. - * @return {!Array} List of connections. + * @return {!Array} List of connections. * @package */ RenderedConnection.prototype.neighbours = function(maxLimit) { @@ -538,7 +541,7 @@ RenderedConnection.prototype.neighbours = function(maxLimit) { /** * Connect two connections together. This is the connection on the superior * block. Rerender blocks as needed. - * @param {!Blockly.Connection} childConnection Connection on inferior block. + * @param {!Connection} childConnection Connection on inferior block. * @protected */ RenderedConnection.prototype.connect_ = function(childConnection) { @@ -557,8 +560,8 @@ RenderedConnection.prototype.connect_ = function(childConnection) { childBlock.updateDisabled(); } if (parentRendered && childRendered) { - if (parentConnection.type == Blockly.connectionTypes.NEXT_STATEMENT || - parentConnection.type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { + if (parentConnection.type == connectionTypes.NEXT_STATEMENT || + parentConnection.type == connectionTypes.PREVIOUS_STATEMENT) { // Child block may need to square off its corners if it is in a stack. // Rendering a child will render its parent. childBlock.render(); diff --git a/tests/deps.js b/tests/deps.js index 367e41229..1b419caf7 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -118,7 +118,7 @@ goog.addDependency('../../core/options.js', ['Blockly.Options'], ['Blockly.Theme goog.addDependency('../../core/positionable_helpers.js', ['Blockly.uiPosition'], ['Blockly.Scrollbar', 'Blockly.utils.Rect', 'Blockly.utils.toolbox']); goog.addDependency('../../core/procedures.js', ['Blockly.Procedures'], ['Blockly.Blocks', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Field', 'Blockly.Msg', 'Blockly.Names', 'Blockly.Workspace', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils.xml']); goog.addDependency('../../core/registry.js', ['Blockly.registry'], []); -goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/rendered_connection.js', ['Blockly.RenderedConnection'], ['Blockly.Connection', 'Blockly.Events', 'Blockly.connectionTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/block_rendering.js', ['Blockly.blockRendering'], ['Blockly.registry']); goog.addDependency('../../core/renderers/common/constants.js', ['Blockly.blockRendering.ConstantProvider'], ['Blockly.connectionTypes', 'Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.colour', 'Blockly.utils.dom', 'Blockly.utils.svgPaths', 'Blockly.utils.userAgent'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/common/debugger.js', ['Blockly.blockRendering.Debug'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.RenderInfo', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.Types', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); From 372f5c0834f23d8e08cfc6fee4278f2c7bc74668 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 10:39:45 -0700 Subject: [PATCH 338/833] clang-format core/rendered_connection.js --- core/rendered_connection.js | 99 +++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 953062f20..0abc123e5 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -55,8 +55,7 @@ const RenderedConnection = function(source, type) { * @private */ this.dbOpposite_ = - source.workspace - .connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; + source.workspace.connectionDBList[internalConstants.OPPOSITE_TYPE[type]]; /** * Workspace units, (0, 0) is top left of block. @@ -118,7 +117,7 @@ RenderedConnection.prototype.dispose = function() { */ RenderedConnection.prototype.getSourceBlock = function() { return /** @type {!BlockSvg} */ ( - RenderedConnection.superClass_.getSourceBlock.call(this)); + RenderedConnection.superClass_.getSourceBlock.call(this)); }; /** @@ -128,7 +127,7 @@ RenderedConnection.prototype.getSourceBlock = function() { */ RenderedConnection.prototype.targetBlock = function() { return /** @type {BlockSvg} */ ( - RenderedConnection.superClass_.targetBlock.call(this)); + RenderedConnection.superClass_.targetBlock.call(this)); }; /** @@ -177,13 +176,11 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { // Raise it to the top for extra visibility. const selected = Blockly.selected == rootBlock; selected || rootBlock.addSelect(); - let dx = - (staticConnection.x + internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - + let dx = (staticConnection.x + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; - let dy = - (staticConnection.y + internalConstants.SNAP_RADIUS + - Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - + let dy = (staticConnection.y + internalConstants.SNAP_RADIUS + + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.y; if (reverse) { // When reversing a bump due to an uneditable block, bump up. @@ -191,8 +188,7 @@ RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) { } if (rootBlock.RTL) { dx = (staticConnection.x - internalConstants.SNAP_RADIUS - - Math.floor( - Math.random() * internalConstants.BUMP_RANDOMNESS)) - + Math.floor(Math.random() * internalConstants.BUMP_RANDOMNESS)) - this.x; } rootBlock.moveBy(dx, dy); @@ -208,8 +204,7 @@ RenderedConnection.prototype.moveTo = function(x, y) { if (this.trackedState_ == RenderedConnection.TrackedState.WILL_TRACK) { this.db_.addConnection(this, y); this.trackedState_ = RenderedConnection.TrackedState.TRACKED; - } else if (this.trackedState_ == RenderedConnection - .TrackedState.TRACKED) { + } else if (this.trackedState_ == RenderedConnection.TrackedState.TRACKED) { this.db_.removeConnection(this, this.y); this.db_.addConnection(this, y); } @@ -233,8 +228,8 @@ RenderedConnection.prototype.moveBy = function(dx, dy) { * corner of the block, in workspace coordinates. */ RenderedConnection.prototype.moveToOffset = function(blockTL) { - this.moveTo(blockTL.x + this.offsetInBlock_.x, - blockTL.y + this.offsetInBlock_.y); + this.moveTo( + blockTL.x + this.offsetInBlock_.x, blockTL.y + this.offsetInBlock_.y); }; /** @@ -271,8 +266,8 @@ RenderedConnection.prototype.tighten = function() { } // Workspace coordinates. const xy = utils.getRelativeXY(svgRoot); - block.getSvgRoot().setAttribute('transform', - 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); + block.getSvgRoot().setAttribute( + 'transform', 'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')'); block.moveConnections(-dx, -dy); } }; @@ -304,24 +299,21 @@ RenderedConnection.prototype.highlight = function() { // Vertical line, puzzle tab, vertical line. const yLen = renderConstants.TAB_OFFSET_FROM_TOP; steps = utils.svgPaths.moveBy(0, -yLen) + - utils.svgPaths.lineOnAxis('v', yLen) + - shape.pathDown + + utils.svgPaths.lineOnAxis('v', yLen) + shape.pathDown + utils.svgPaths.lineOnAxis('v', yLen); } else { const xLen = renderConstants.NOTCH_OFFSET_LEFT - renderConstants.CORNER_RADIUS; // Horizontal line, notch, horizontal line. steps = utils.svgPaths.moveBy(-xLen, 0) + - utils.svgPaths.lineOnAxis('h', xLen) + - shape.pathLeft + + utils.svgPaths.lineOnAxis('h', xLen) + shape.pathLeft + utils.svgPaths.lineOnAxis('h', xLen); } const xy = this.sourceBlock_.getRelativeToSurfaceXY(); const x = this.x - xy.x; const y = this.y - xy.y; Connection.highlightedPath_ = dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyHighlightedConnectionPath', 'd': steps, transform: 'translate(' + x + ',' + y + ')' + @@ -344,10 +336,10 @@ RenderedConnection.prototype.unhighlight = function() { * @package */ RenderedConnection.prototype.setTracking = function(doTracking) { - if ((doTracking && this.trackedState_ == - RenderedConnection.TrackedState.TRACKED) || - (!doTracking && this.trackedState_ == - RenderedConnection.TrackedState.UNTRACKED)) { + if ((doTracking && + this.trackedState_ == RenderedConnection.TrackedState.TRACKED) || + (!doTracking && + this.trackedState_ == RenderedConnection.TrackedState.UNTRACKED)) { return; } if (this.sourceBlock_.isInFlyout) { @@ -442,19 +434,18 @@ RenderedConnection.prototype.startTrackingAll = function() { * @return {boolean} True if the connection is allowed, false otherwise. * @deprecated July 2020 */ -RenderedConnection.prototype.isConnectionAllowed = function(candidate, - maxRadius) { +RenderedConnection.prototype.isConnectionAllowed = function( + candidate, maxRadius) { deprecation.warn( - 'RenderedConnection.prototype.isConnectionAllowed', - 'July 2020', + 'RenderedConnection.prototype.isConnectionAllowed', 'July 2020', 'July 2021', 'Blockly.Workspace.prototype.getConnectionChecker().canConnect'); if (this.distanceFrom(candidate) > maxRadius) { return false; } - return RenderedConnection.superClass_.isConnectionAllowed.call(this, - candidate); + return RenderedConnection.superClass_.isConnectionAllowed.call( + this, candidate); }; /** @@ -465,20 +456,19 @@ RenderedConnection.prototype.isConnectionAllowed = function(candidate, * failed to connect to. * @package */ -RenderedConnection.prototype.onFailedConnect = - function(otherConnection) { - const block = this.getSourceBlock(); - if (Events.recordUndo) { - const group = Events.getGroup(); - setTimeout(function() { - if (!block.isDisposed() && !block.getParent()) { - Events.setGroup(group); - this.bumpAwayFrom(otherConnection); - Events.setGroup(false); - } - }.bind(this), internalConstants.BUMP_DELAY); +RenderedConnection.prototype.onFailedConnect = function(otherConnection) { + const block = this.getSourceBlock(); + if (Events.recordUndo) { + const group = Events.getGroup(); + setTimeout(function() { + if (!block.isDisposed() && !block.getParent()) { + Events.setGroup(group); + this.bumpAwayFrom(otherConnection); + Events.setGroup(false); } - }; + }.bind(this), internalConstants.BUMP_DELAY); + } +}; /** @@ -488,10 +478,10 @@ RenderedConnection.prototype.onFailedConnect = * @protected * @override */ -RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, - childBlock) { - RenderedConnection.superClass_.disconnectInternal_.call(this, - parentBlock, childBlock); +RenderedConnection.prototype.disconnectInternal_ = function( + parentBlock, childBlock) { + RenderedConnection.superClass_.disconnectInternal_.call( + this, parentBlock, childBlock); // Rerender the parent so that it may reflow. if (parentBlock.rendered) { parentBlock.render(); @@ -586,9 +576,10 @@ RenderedConnection.prototype.connect_ = function(childConnection) { */ RenderedConnection.prototype.onCheckChanged_ = function() { // The new value type may not be compatible with the existing connection. - if (this.isConnected() && (!this.targetConnection || - !this.getConnectionChecker().canConnect( - this, this.targetConnection, false))) { + if (this.isConnected() && + (!this.targetConnection || + !this.getConnectionChecker().canConnect( + this, this.targetConnection, false))) { const child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_; child.unplug(); // Bump away. From 055533e783dcaf9268a3f6849a2974e91537be7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:17:17 -0700 Subject: [PATCH 339/833] Migrate core/shortcut_registry.js to ES6 const/let --- core/shortcut_registry.js | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 14684e1b8..807f40d84 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -78,7 +78,7 @@ Blockly.ShortcutRegistry.KeyboardShortcut; */ Blockly.ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { - var registeredShortcut = this.registry_[shortcut.name]; + const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( 'Shortcut with name "' + shortcut.name + '" already exists.'); @@ -94,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @public */ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { - var shortcut = this.registry_[shortcutName]; + const shortcut = this.registry_[shortcutName]; if (!shortcut) { console.warn( @@ -123,7 +123,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { Blockly.ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (shortcutNames && !opt_allowCollision) { throw new Error( 'Shortcut with name "' + shortcutName + '" collides with shortcuts ' + @@ -149,7 +149,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( */ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (!shortcutNames && !opt_quiet) { console.warn( @@ -158,7 +158,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( return false; } - var shortcutIdx = shortcutNames.indexOf(shortcutName); + const shortcutIdx = shortcutNames.indexOf(shortcutName); if (shortcutIdx > -1) { shortcutNames.splice(shortcutIdx, 1); if (shortcutNames.length == 0) { @@ -181,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @public */ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { - for (var keyCode in this.keyMap_) { + for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } }; @@ -225,13 +225,13 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @public */ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { - var key = this.serializeKeyEvent_(e); - var shortcutNames = this.getShortcutNamesByKeyCode(key); + const key = this.serializeKeyEvent_(e); + const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { return false; } - for (var i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { - var shortcut = this.registry_[shortcutName]; + for (let i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { + const shortcut = this.registry_[shortcutName]; if (!shortcut.preconditionFn || shortcut.preconditionFn(workspace)) { // If the key has been handled, stop processing shortcuts. if (shortcut.callback && shortcut.callback(workspace, e, shortcut)) { @@ -264,10 +264,10 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( */ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { - var keys = []; - for (var keyCode in this.keyMap_) { - var shortcuts = this.keyMap_[keyCode]; - var shortcutIdx = shortcuts.indexOf(shortcutName); + const keys = []; + for (const keyCode in this.keyMap_) { + const shortcuts = this.keyMap_[keyCode]; + const shortcutIdx = shortcuts.indexOf(shortcutName); if (shortcutIdx > -1) { keys.push(keyCode); } @@ -282,8 +282,8 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @private */ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { - var serializedKey = ''; - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { + let serializedKey = ''; + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -307,9 +307,9 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - var validModifiers = Blockly.utils.object.values( + const validModifiers = Blockly.utils.object.values( Blockly.ShortcutRegistry.modifierKeys); - for (var i = 0, modifier; (modifier = modifiers[i]); i++) { + for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); } @@ -327,12 +327,12 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( */ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { - var serializedKey = ''; + let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { - var modifierKeyCode = + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + const modifierKeyCode = Blockly.ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { From 69b900aa4626cf584066a670e22cd8ae4553bc99 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:25:30 -0700 Subject: [PATCH 340/833] Migrate core/shortcut_registry.js to goog.module --- core/interfaces/i_keyboard_accessible.js | 5 +- core/shortcut_registry.js | 71 ++++++++++++------------ tests/deps.js | 2 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8243e67d1..04704a2fe 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -15,7 +15,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); /** @@ -26,7 +26,8 @@ const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. - * @param {!KeyboardShortcut} shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ IKeyboardAccessible.prototype.onShortcut; diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 807f40d84..d75ec9546 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.ShortcutRegistry'); +goog.module('Blockly.ShortcutRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.KeyCodes'); goog.require('Blockly.utils.object'); @@ -22,16 +23,16 @@ goog.requireType('Blockly.Workspace'); /** * Class for the registry of keyboard shortcuts. This is intended to be a * singleton. You should not create a new instance, and only access this class - * from Blockly.ShortcutRegistry.registry. + * from ShortcutRegistry.registry. * @constructor */ -Blockly.ShortcutRegistry = function() { +const ShortcutRegistry = function() { // Singleton instance should be registered once. - Blockly.ShortcutRegistry.registry = this; + ShortcutRegistry.registry = this; /** * Registry of all keyboard shortcuts, keyed by name of shortcut. - * @type {!Object} + * @type {!Object} * @private */ this.registry_ = Object.create(null); @@ -48,7 +49,7 @@ Blockly.ShortcutRegistry = function() { * Enum of valid modifiers. * @enum {!Blockly.utils.KeyCodes} */ -Blockly.ShortcutRegistry.modifierKeys = { +ShortcutRegistry.modifierKeys = { 'Shift': Blockly.utils.KeyCodes.SHIFT, 'Control': Blockly.utils.KeyCodes.CTRL, 'Alt': Blockly.utils.KeyCodes.ALT, @@ -59,24 +60,24 @@ Blockly.ShortcutRegistry.modifierKeys = { * A keyboard shortcut. * @typedef {{ * callback: ((function(!Blockly.Workspace, Event, - * !Blockly.ShortcutRegistry.KeyboardShortcut):boolean)|undefined), + * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ -Blockly.ShortcutRegistry.KeyboardShortcut; +ShortcutRegistry.KeyboardShortcut; /** * Registers a keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The * shortcut for this key code. * @param {boolean=} opt_allowOverrides True to prevent a warning when * overriding an already registered item. * @throws {Error} if a shortcut with the same name already exists. * @public */ -Blockly.ShortcutRegistry.prototype.register = function( +ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { @@ -93,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @return {boolean} True if an item was unregistered, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { +ShortcutRegistry.prototype.unregister = function(shortcutName) { const shortcut = this.registry_[shortcutName]; if (!shortcut) { @@ -112,7 +113,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * Adds a mapping between a keycode and a keyboard shortcut. * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_allowCollision True to prevent an error when adding a @@ -120,7 +121,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * @throws {Error} if the given key code is already mapped to a shortcut. * @public */ -Blockly.ShortcutRegistry.prototype.addKeyMapping = function( +ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); const shortcutNames = this.keyMap_[keyCode]; @@ -139,7 +140,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * Removes a mapping between a keycode and a keyboard shortcut. * @param {string} keyCode The key code for the keyboard shortcut. If * registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_quiet True to not console warn when there is no @@ -147,7 +148,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * @return {boolean} True if a key mapping was removed, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( +ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { const shortcutNames = this.keyMap_[keyCode]; @@ -180,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @param {string} shortcutName The name of the shortcut to remove from the key map. * @public */ -Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { +ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } @@ -192,27 +193,27 @@ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) * shortcut names. * @public */ -Blockly.ShortcutRegistry.prototype.setKeyMap = function(keyMap) { +ShortcutRegistry.prototype.setKeyMap = function(keyMap) { this.keyMap_ = keyMap; }; /** * Gets the current key map. - * @return {!Object>} - * The object holding key codes to Blockly.ShortcutRegistry.KeyboardShortcut. + * @return {!Object>} + * The object holding key codes to ShortcutRegistry.KeyboardShortcut. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyMap = function() { +ShortcutRegistry.prototype.getKeyMap = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); }; /** * Gets the registry of keyboard shortcuts. - * @return {!Object} + * @return {!Object} * The registry of keyboard shortcuts. * @public */ -Blockly.ShortcutRegistry.prototype.getRegistry = function() { +ShortcutRegistry.prototype.getRegistry = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); }; @@ -224,7 +225,7 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @return {boolean} True if the event was handled, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { +ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { const key = this.serializeKeyEvent_(e); const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { @@ -249,7 +250,7 @@ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( keyCode) { return this.keyMap_[keyCode] || []; }; @@ -262,7 +263,7 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { @@ -281,9 +282,9 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @return {string} The serialized key code for the given event. * @private */ -Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { +ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { let serializedKey = ''; - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -305,10 +306,10 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( +ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { const validModifiers = Blockly.utils.object.values( - Blockly.ShortcutRegistry.modifierKeys); + ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -321,19 +322,19 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( * @param {number} keyCode Number code representing the key. * @param {?Array} modifiers List of modifier key codes to be used with * the key. All valid modifiers can be found in the - * Blockly.ShortcutRegistry.modifierKeys. + * ShortcutRegistry.modifierKeys. * @return {string} The serialized key code for the given modifiers and key. * @public */ -Blockly.ShortcutRegistry.prototype.createSerializedKey = function( +ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { const modifierKeyCode = - Blockly.ShortcutRegistry.modifierKeys[modifier]; + ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; @@ -352,4 +353,6 @@ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( }; // Creates and assigns the singleton instance. -new Blockly.ShortcutRegistry(); +new ShortcutRegistry(); + +exports = ShortcutRegistry; diff --git a/tests/deps.js b/tests/deps.js index de575339f..d67006c87 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -160,7 +160,7 @@ goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Ren goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); -goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); +goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); From 3519f4abc8d5352214a3a9f7851ca9ca9326afd1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:19 -0700 Subject: [PATCH 341/833] Migrate core/shortcut_registry.js to named requires --- core/shortcut_registry.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index d75ec9546..ac492397a 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -14,10 +14,10 @@ goog.module('Blockly.ShortcutRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Workspace'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const object = goog.require('Blockly.utils.object'); /** @@ -47,22 +47,22 @@ const ShortcutRegistry = function() { /** * Enum of valid modifiers. - * @enum {!Blockly.utils.KeyCodes} + * @enum {!KeyCodes} */ ShortcutRegistry.modifierKeys = { - 'Shift': Blockly.utils.KeyCodes.SHIFT, - 'Control': Blockly.utils.KeyCodes.CTRL, - 'Alt': Blockly.utils.KeyCodes.ALT, - 'Meta': Blockly.utils.KeyCodes.META + 'Shift': KeyCodes.SHIFT, + 'Control': KeyCodes.CTRL, + 'Alt': KeyCodes.ALT, + 'Meta': KeyCodes.META }; /** * A keyboard shortcut. * @typedef {{ - * callback: ((function(!Blockly.Workspace, Event, + * callback: ((function(!Workspace, Event, * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, - * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), + * preconditionFn: ((function(!Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ @@ -111,7 +111,7 @@ ShortcutRegistry.prototype.unregister = function(shortcutName) { /** * Adds a mapping between a keycode and a keyboard shortcut. - * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard + * @param {string|KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the @@ -204,7 +204,7 @@ ShortcutRegistry.prototype.setKeyMap = function(keyMap) { * @public */ ShortcutRegistry.prototype.getKeyMap = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); + return object.deepMerge(Object.create(null), this.keyMap_); }; /** @@ -214,12 +214,12 @@ ShortcutRegistry.prototype.getKeyMap = function() { * @public */ ShortcutRegistry.prototype.getRegistry = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); + return object.deepMerge(Object.create(null), this.registry_); }; /** * Handles key down events. - * @param {!Blockly.Workspace} workspace The main workspace where the event was + * @param {!Workspace} workspace The main workspace where the event was * captured. * @param {!Event} e The key down event. * @return {boolean} True if the event was handled, false otherwise. @@ -308,7 +308,7 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - const validModifiers = Blockly.utils.object.values( + const validModifiers = object.values( ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { From 9e2d6f2aba5b7c3d43a0705ce7d28f5b4d44cc76 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:57 -0700 Subject: [PATCH 342/833] clang-format core/shortcut_registry.js --- core/shortcut_registry.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index ac492397a..3da777eae 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -77,8 +77,7 @@ ShortcutRegistry.KeyboardShortcut; * @throws {Error} if a shortcut with the same name already exists. * @public */ -ShortcutRegistry.prototype.register = function( - shortcut, opt_allowOverrides) { +ShortcutRegistry.prototype.register = function(shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( @@ -168,7 +167,8 @@ ShortcutRegistry.prototype.removeKeyMapping = function( return true; } if (!opt_quiet) { - console.warn('No keyboard shortcut with name "' + shortcutName + + console.warn( + 'No keyboard shortcut with name "' + shortcutName + '" registered with key code "' + keyCode + '"'); } return false; @@ -176,9 +176,10 @@ ShortcutRegistry.prototype.removeKeyMapping = function( /** * Removes all the key mappings for a shortcut with the given name. - * Useful when changing the default key mappings and the key codes registered to the shortcut are - * unknown. - * @param {string} shortcutName The name of the shortcut to remove from the key map. + * Useful when changing the default key mappings and the key codes registered to + * the shortcut are unknown. + * @param {string} shortcutName The name of the shortcut to remove from the key + * map. * @public */ ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { @@ -250,8 +251,7 @@ ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( - keyCode) { +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function(keyCode) { return this.keyMap_[keyCode] || []; }; @@ -263,8 +263,7 @@ ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( - shortcutName) { +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function(shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { const shortcuts = this.keyMap_[keyCode]; @@ -306,10 +305,8 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -ShortcutRegistry.prototype.checkModifiers_ = function( - modifiers) { - const validModifiers = object.values( - ShortcutRegistry.modifierKeys); +ShortcutRegistry.prototype.checkModifiers_ = function(modifiers) { + const validModifiers = object.values(ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -326,15 +323,13 @@ ShortcutRegistry.prototype.checkModifiers_ = function( * @return {string} The serialized key code for the given modifiers and key. * @public */ -ShortcutRegistry.prototype.createSerializedKey = function( - keyCode, modifiers) { +ShortcutRegistry.prototype.createSerializedKey = function(keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); for (const modifier in ShortcutRegistry.modifierKeys) { - const modifierKeyCode = - ShortcutRegistry.modifierKeys[modifier]; + const modifierKeyCode = ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; From a106f37cbb3f9a1dd62062c3ed5eedb7b472c0c4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:33:46 -0700 Subject: [PATCH 343/833] Migrate core/theme.js to ES6 const/let --- core/theme.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/theme.js b/core/theme.js index 182710f16..75bfb3779 100644 --- a/core/theme.js +++ b/core/theme.js @@ -165,7 +165,7 @@ Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, * @return {?string} The style value. */ Blockly.Theme.prototype.getComponentStyle = function(componentName) { - var style = this.componentStyles[componentName]; + const style = this.componentStyles[componentName]; if (style && typeof style == 'string' && this.getComponentStyle(/** @type {string} */ (style))) { return this.getComponentStyle(/** @type {string} */ (style)); @@ -207,8 +207,8 @@ Blockly.Theme.prototype.setStartHats = function(startHats) { * @return {!Blockly.Theme} A new Blockly theme. */ Blockly.Theme.defineTheme = function(name, themeObj) { - var theme = new Blockly.Theme(name); - var base = themeObj['base']; + const theme = new Blockly.Theme(name); + let base = themeObj['base']; if (base) { if (typeof base == "string") { base = Blockly.registry.getObject(Blockly.registry.Type.THEME, base); From 367b94dfdd8c2856efea4f9b66e6237a73200787 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:36:48 -0700 Subject: [PATCH 344/833] Migrate core/theme.js to goog.module --- core/theme.js | 61 +++++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/core/theme.js b/core/theme.js index 75bfb3779..16289a3ad 100644 --- a/core/theme.js +++ b/core/theme.js @@ -9,7 +9,8 @@ */ 'use strict'; -goog.provide('Blockly.Theme'); +goog.module('Blockly.Theme'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.registry'); goog.require('Blockly.utils'); @@ -19,16 +20,16 @@ goog.require('Blockly.utils.object'); /** * Class for a theme. * @param {string} name Theme name. - * @param {!Object=} opt_blockStyles A map + * @param {!Object=} opt_blockStyles A map * from style names (strings) to objects with style attributes for blocks. - * @param {!Object=} opt_categoryStyles A + * @param {!Object=} opt_categoryStyles A * map from style names (strings) to objects with style attributes for * categories. - * @param {!Blockly.Theme.ComponentStyle=} opt_componentStyles A map of Blockly + * @param {!Theme.ComponentStyle=} opt_componentStyles A map of Blockly * component names to style value. * @constructor */ -Blockly.Theme = function(name, opt_blockStyles, opt_categoryStyles, +const Theme = function(name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) { /** @@ -39,32 +40,32 @@ Blockly.Theme = function(name, opt_blockStyles, opt_categoryStyles, /** * The block styles map. - * @type {!Object} + * @type {!Object} * @package */ this.blockStyles = opt_blockStyles || Object.create(null); /** * The category styles map. - * @type {!Object} + * @type {!Object} * @package */ this.categoryStyles = opt_categoryStyles || Object.create(null); /** * The UI components styles map. - * @type {!Blockly.Theme.ComponentStyle} + * @type {!Theme.ComponentStyle} * @package */ this.componentStyles = opt_componentStyles || - (/** @type {Blockly.Theme.ComponentStyle} */ (Object.create(null))); + (/** @type {Theme.ComponentStyle} */ (Object.create(null))); /** * The font style. - * @type {!Blockly.Theme.FontStyle} + * @type {!Theme.FontStyle} * @package */ - this.fontStyle = /** @type {Blockly.Theme.FontStyle} */ (Object.create(null)); + this.fontStyle = /** @type {Theme.FontStyle} */ (Object.create(null)); /** * Whether or not to add a 'hat' on top of all blocks with no previous or @@ -87,7 +88,7 @@ Blockly.Theme = function(name, opt_blockStyles, opt_categoryStyles, * hat:string * }} */ -Blockly.Theme.BlockStyle; +Theme.BlockStyle; /** * A category style. @@ -95,7 +96,7 @@ Blockly.Theme.BlockStyle; * colour:string * }} */ -Blockly.Theme.CategoryStyle; +Theme.CategoryStyle; /** * A component style. @@ -118,7 +119,7 @@ Blockly.Theme.CategoryStyle; * replacementGlowOpacity:?number * }} */ -Blockly.Theme.ComponentStyle; +Theme.ComponentStyle; /** * A font style. @@ -128,32 +129,32 @@ Blockly.Theme.ComponentStyle; * size:?number * }} */ -Blockly.Theme.FontStyle; +Theme.FontStyle; /** * Gets the class name that identifies this theme. * @return {string} The CSS class name. * @package */ -Blockly.Theme.prototype.getClassName = function() { +Theme.prototype.getClassName = function() { return this.name + '-theme'; }; /** * Overrides or adds a style to the blockStyles map. * @param {string} blockStyleName The name of the block style. - * @param {Blockly.Theme.BlockStyle} blockStyle The block style. + * @param {Theme.BlockStyle} blockStyle The block style. */ -Blockly.Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { +Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { this.blockStyles[blockStyleName] = blockStyle; }; /** * Overrides or adds a style to the categoryStyles map. * @param {string} categoryStyleName The name of the category style. - * @param {Blockly.Theme.CategoryStyle} categoryStyle The category style. + * @param {Theme.CategoryStyle} categoryStyle The category style. */ -Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, +Theme.prototype.setCategoryStyle = function(categoryStyleName, categoryStyle) { this.categoryStyles[categoryStyleName] = categoryStyle; }; @@ -164,7 +165,7 @@ Blockly.Theme.prototype.setCategoryStyle = function(categoryStyleName, * @param {string} componentName The name of the component. * @return {?string} The style value. */ -Blockly.Theme.prototype.getComponentStyle = function(componentName) { +Theme.prototype.getComponentStyle = function(componentName) { const style = this.componentStyles[componentName]; if (style && typeof style == 'string' && this.getComponentStyle(/** @type {string} */ (style))) { @@ -178,16 +179,16 @@ Blockly.Theme.prototype.getComponentStyle = function(componentName) { * @param {string} componentName The name of the component. * @param {*} styleValue The style value. */ -Blockly.Theme.prototype.setComponentStyle = function(componentName, +Theme.prototype.setComponentStyle = function(componentName, styleValue) { this.componentStyles[componentName] = styleValue; }; /** * Configure a theme's font style. - * @param {Blockly.Theme.FontStyle} fontStyle The font style. + * @param {Theme.FontStyle} fontStyle The font style. */ -Blockly.Theme.prototype.setFontStyle = function(fontStyle) { +Theme.prototype.setFontStyle = function(fontStyle) { this.fontStyle = fontStyle; }; @@ -196,7 +197,7 @@ Blockly.Theme.prototype.setFontStyle = function(fontStyle) { * @param {boolean} startHats True if the theme enables start hats, false * otherwise. */ -Blockly.Theme.prototype.setStartHats = function(startHats) { +Theme.prototype.setStartHats = function(startHats) { this.startHats = startHats; }; @@ -204,16 +205,16 @@ Blockly.Theme.prototype.setStartHats = function(startHats) { * Define a new Blockly theme. * @param {string} name The name of the theme. * @param {!Object} themeObj An object containing theme properties. - * @return {!Blockly.Theme} A new Blockly theme. + * @return {!Theme} A new Blockly theme. */ -Blockly.Theme.defineTheme = function(name, themeObj) { - const theme = new Blockly.Theme(name); +Theme.defineTheme = function(name, themeObj) { + const theme = new Theme(name); let base = themeObj['base']; if (base) { if (typeof base == "string") { base = Blockly.registry.getObject(Blockly.registry.Type.THEME, base); } - if (base instanceof Blockly.Theme) { + if (base instanceof Theme) { Blockly.utils.object.deepMerge(theme, base); theme.name = name; } @@ -233,3 +234,5 @@ Blockly.Theme.defineTheme = function(name, themeObj) { return theme; }; + +exports = Theme; diff --git a/tests/deps.js b/tests/deps.js index de575339f..42d14c6a8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -161,7 +161,7 @@ goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', ' goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); -goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); From 9cf50a61c189e9e3c076f81bd86d1b436a1878dc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:39:57 -0700 Subject: [PATCH 345/833] Migrate core/theme.js to named requires --- core/theme.js | 19 +++++++++---------- tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/theme.js b/core/theme.js index 16289a3ad..c9cd46968 100644 --- a/core/theme.js +++ b/core/theme.js @@ -12,9 +12,8 @@ goog.module('Blockly.Theme'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.registry'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); +const object = goog.require('Blockly.utils.object'); +const registry = goog.require('Blockly.registry'); /** @@ -76,7 +75,7 @@ const Theme = function(name, opt_blockStyles, opt_categoryStyles, this.startHats = null; // Register the theme by name. - Blockly.registry.register(Blockly.registry.Type.THEME, name, this); + registry.register(registry.Type.THEME, name, this); }; /** @@ -212,21 +211,21 @@ Theme.defineTheme = function(name, themeObj) { let base = themeObj['base']; if (base) { if (typeof base == "string") { - base = Blockly.registry.getObject(Blockly.registry.Type.THEME, base); + base = registry.getObject(registry.Type.THEME, base); } if (base instanceof Theme) { - Blockly.utils.object.deepMerge(theme, base); + object.deepMerge(theme, base); theme.name = name; } } - Blockly.utils.object.deepMerge(theme.blockStyles, + object.deepMerge(theme.blockStyles, themeObj['blockStyles']); - Blockly.utils.object.deepMerge(theme.categoryStyles, + object.deepMerge(theme.categoryStyles, themeObj['categoryStyles']); - Blockly.utils.object.deepMerge(theme.componentStyles, + object.deepMerge(theme.componentStyles, themeObj['componentStyles']); - Blockly.utils.object.deepMerge(theme.fontStyle, + object.deepMerge(theme.fontStyle, themeObj['fontStyle']); if (themeObj['startHats'] != null) { theme.startHats = themeObj['startHats']; diff --git a/tests/deps.js b/tests/deps.js index 42d14c6a8..d27093d4d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -161,7 +161,7 @@ goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', ' goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); -goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); From 4e3bfee2aacb5391a8ee0ede11b4d3b8989ceaf2 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:42:17 -0700 Subject: [PATCH 346/833] clang-format core/theme.js --- core/theme.js | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/core/theme.js b/core/theme.js index c9cd46968..11c72e491 100644 --- a/core/theme.js +++ b/core/theme.js @@ -28,9 +28,8 @@ const registry = goog.require('Blockly.registry'); * component names to style value. * @constructor */ -const Theme = function(name, opt_blockStyles, opt_categoryStyles, - opt_componentStyles) { - +const Theme = function( + name, opt_blockStyles, opt_categoryStyles, opt_componentStyles) { /** * The theme name. This can be used to reference a specific theme in CSS. * @type {string} @@ -57,7 +56,7 @@ const Theme = function(name, opt_blockStyles, opt_categoryStyles, * @package */ this.componentStyles = opt_componentStyles || - (/** @type {Theme.ComponentStyle} */ (Object.create(null))); + (/** @type {Theme.ComponentStyle} */ (Object.create(null))); /** * The font style. @@ -143,7 +142,7 @@ Theme.prototype.getClassName = function() { * Overrides or adds a style to the blockStyles map. * @param {string} blockStyleName The name of the block style. * @param {Theme.BlockStyle} blockStyle The block style. -*/ + */ Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { this.blockStyles[blockStyleName] = blockStyle; }; @@ -152,9 +151,8 @@ Theme.prototype.setBlockStyle = function(blockStyleName, blockStyle) { * Overrides or adds a style to the categoryStyles map. * @param {string} categoryStyleName The name of the category style. * @param {Theme.CategoryStyle} categoryStyle The category style. -*/ -Theme.prototype.setCategoryStyle = function(categoryStyleName, - categoryStyle) { + */ +Theme.prototype.setCategoryStyle = function(categoryStyleName, categoryStyle) { this.categoryStyles[categoryStyleName] = categoryStyle; }; @@ -177,16 +175,15 @@ Theme.prototype.getComponentStyle = function(componentName) { * Configure a specific Blockly UI component with a style value. * @param {string} componentName The name of the component. * @param {*} styleValue The style value. -*/ -Theme.prototype.setComponentStyle = function(componentName, - styleValue) { + */ +Theme.prototype.setComponentStyle = function(componentName, styleValue) { this.componentStyles[componentName] = styleValue; }; /** * Configure a theme's font style. * @param {Theme.FontStyle} fontStyle The font style. -*/ + */ Theme.prototype.setFontStyle = function(fontStyle) { this.fontStyle = fontStyle; }; @@ -195,7 +192,7 @@ Theme.prototype.setFontStyle = function(fontStyle) { * Configure a theme's start hats. * @param {boolean} startHats True if the theme enables start hats, false * otherwise. -*/ + */ Theme.prototype.setStartHats = function(startHats) { this.startHats = startHats; }; @@ -205,12 +202,12 @@ Theme.prototype.setStartHats = function(startHats) { * @param {string} name The name of the theme. * @param {!Object} themeObj An object containing theme properties. * @return {!Theme} A new Blockly theme. -*/ + */ Theme.defineTheme = function(name, themeObj) { const theme = new Theme(name); let base = themeObj['base']; if (base) { - if (typeof base == "string") { + if (typeof base == 'string') { base = registry.getObject(registry.Type.THEME, base); } if (base instanceof Theme) { @@ -219,14 +216,10 @@ Theme.defineTheme = function(name, themeObj) { } } - object.deepMerge(theme.blockStyles, - themeObj['blockStyles']); - object.deepMerge(theme.categoryStyles, - themeObj['categoryStyles']); - object.deepMerge(theme.componentStyles, - themeObj['componentStyles']); - object.deepMerge(theme.fontStyle, - themeObj['fontStyle']); + object.deepMerge(theme.blockStyles, themeObj['blockStyles']); + object.deepMerge(theme.categoryStyles, themeObj['categoryStyles']); + object.deepMerge(theme.componentStyles, themeObj['componentStyles']); + object.deepMerge(theme.fontStyle, themeObj['fontStyle']); if (themeObj['startHats'] != null) { theme.startHats = themeObj['startHats']; } From 2d480a1b202e9fca2eda7bfb25c6c7c8a7e07c79 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:46:58 -0700 Subject: [PATCH 347/833] Migrate core/theme_manager.js to ES6 const/let --- core/theme_manager.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index 6c461a2e7..d432e0dd0 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -82,11 +82,11 @@ Blockly.ThemeManager.prototype.getTheme = function() { * @package */ Blockly.ThemeManager.prototype.setTheme = function(theme) { - var prevTheme = this.theme_; + const prevTheme = this.theme_; this.theme_ = theme; // Set the theme name onto the injection div. - var injectionDiv = this.workspace_.getInjectionDiv(); + const injectionDiv = this.workspace_.getInjectionDiv(); if (injectionDiv) { if (prevTheme) { Blockly.utils.dom.removeClass(injectionDiv, prevTheme.getClassName()); @@ -95,17 +95,17 @@ Blockly.ThemeManager.prototype.setTheme = function(theme) { } // Refresh all subscribed workspaces. - for (var i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) { + for (let i = 0, workspace; (workspace = this.subscribedWorkspaces_[i]); i++) { workspace.refreshTheme(); } // Refresh all registered Blockly UI components. - for (var i = 0, keys = Object.keys(this.componentDB_), + for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]); i++) { - for (var j = 0, component; (component = this.componentDB_[key][j]); j++) { - var element = component.element; - var propertyName = component.propertyName; - var style = this.theme_ && this.theme_.getComponentStyle(key); + for (let j = 0, component; (component = this.componentDB_[key][j]); j++) { + const element = component.element; + const propertyName = component.propertyName; + const style = this.theme_ && this.theme_.getComponentStyle(key); element.style[propertyName] = style || ''; } } @@ -129,7 +129,7 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { * @package */ Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { - var index = this.subscribedWorkspaces_.indexOf(workspace); + const index = this.subscribedWorkspaces_.indexOf(workspace); if (index < 0) { throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.'); } @@ -158,7 +158,7 @@ Blockly.ThemeManager.prototype.subscribe = function(element, componentName, }); // Initialize the element with its corresponding theme style. - var style = this.theme_ && this.theme_.getComponentStyle(componentName); + const style = this.theme_ && this.theme_.getComponentStyle(componentName); element.style[propertyName] = style || ''; }; @@ -172,10 +172,10 @@ Blockly.ThemeManager.prototype.unsubscribe = function(element) { return; } // Go through all component, and remove any references to this element. - var componentNames = Object.keys(this.componentDB_); - for (var c = 0, componentName; (componentName = componentNames[c]); c++) { - var elements = this.componentDB_[componentName]; - for (var i = elements.length - 1; i >= 0; i--) { + const componentNames = Object.keys(this.componentDB_); + for (let c = 0, componentName; (componentName = componentNames[c]); c++) { + const elements = this.componentDB_[componentName]; + for (let i = elements.length - 1; i >= 0; i--) { if (elements[i].element === element) { elements.splice(i, 1); } From 48d422159b246c1062ff413f02ca51c4916bf7fc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:48:59 -0700 Subject: [PATCH 348/833] Migrate core/theme_manager.js to goog.module --- core/theme_manager.js | 25 ++++++++++++++----------- tests/deps.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index d432e0dd0..3b43f2f55 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -12,7 +12,8 @@ */ 'use strict'; -goog.provide('Blockly.ThemeManager'); +goog.module('Blockly.ThemeManager'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Theme'); @@ -27,7 +28,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @package */ -Blockly.ThemeManager = function(workspace, theme) { +const ThemeManager = function(workspace, theme) { /** * The main workspace. @@ -52,7 +53,7 @@ Blockly.ThemeManager = function(workspace, theme) { /** * A map of subscribed UI components, keyed by component name. - * @type {!Object>} + * @type {!Object>} * @private */ this.componentDB_ = Object.create(null); @@ -65,14 +66,14 @@ Blockly.ThemeManager = function(workspace, theme) { * propertyName:string * }} */ -Blockly.ThemeManager.Component; +ThemeManager.Component; /** * Get the workspace theme. * @return {!Blockly.Theme} The workspace theme. * @package */ -Blockly.ThemeManager.prototype.getTheme = function() { +ThemeManager.prototype.getTheme = function() { return this.theme_; }; @@ -81,7 +82,7 @@ Blockly.ThemeManager.prototype.getTheme = function() { * @param {!Blockly.Theme} theme The workspace theme. * @package */ -Blockly.ThemeManager.prototype.setTheme = function(theme) { +ThemeManager.prototype.setTheme = function(theme) { const prevTheme = this.theme_; this.theme_ = theme; @@ -119,7 +120,7 @@ Blockly.ThemeManager.prototype.setTheme = function(theme) { * @param {!Blockly.Workspace} workspace The workspace to subscribe. * @package */ -Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { +ThemeManager.prototype.subscribeWorkspace = function(workspace) { this.subscribedWorkspaces_.push(workspace); }; @@ -128,7 +129,7 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) { * @param {!Blockly.Workspace} workspace The workspace to unsubscribe. * @package */ -Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { +ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { const index = this.subscribedWorkspaces_.indexOf(workspace); if (index < 0) { throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.'); @@ -145,7 +146,7 @@ Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { * @param {string} propertyName The inline style property name to update. * @package */ -Blockly.ThemeManager.prototype.subscribe = function(element, componentName, +ThemeManager.prototype.subscribe = function(element, componentName, propertyName) { if (!this.componentDB_[componentName]) { this.componentDB_[componentName] = []; @@ -167,7 +168,7 @@ Blockly.ThemeManager.prototype.subscribe = function(element, componentName, * @param {Element} element The element to unsubscribe. * @package */ -Blockly.ThemeManager.prototype.unsubscribe = function(element) { +ThemeManager.prototype.unsubscribe = function(element) { if (!element) { return; } @@ -192,9 +193,11 @@ Blockly.ThemeManager.prototype.unsubscribe = function(element) { * @package * @suppress {checkTypes} */ -Blockly.ThemeManager.prototype.dispose = function() { +ThemeManager.prototype.dispose = function() { this.owner_ = null; this.theme_ = null; this.subscribedWorkspaces_ = null; this.componentDB_ = null; }; + +exports = ThemeManager; diff --git a/tests/deps.js b/tests/deps.js index de575339f..48a76dd48 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -164,7 +164,7 @@ goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme']); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); From 794e28ed481da67009d366e35a60d6de034837ea Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:52:43 -0700 Subject: [PATCH 349/833] Migrate core/theme_manager.js to named requires --- core/theme_manager.js | 33 ++++++++++++++++++--------------- tests/deps.js | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index 3b43f2f55..a4f0aed6c 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -15,16 +15,19 @@ goog.module('Blockly.ThemeManager'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Theme'); - -goog.requireType('Blockly.Workspace'); -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const dom = goog.require('Blockly.utils.dom'); /** * Class for storing and updating a workspace's theme and UI components. - * @param {!Blockly.WorkspaceSvg} workspace The main workspace. - * @param {!Blockly.Theme} theme The workspace theme. + * @param {!WorkspaceSvg} workspace The main workspace. + * @param {!Theme} theme The workspace theme. * @constructor * @package */ @@ -32,21 +35,21 @@ const ThemeManager = function(workspace, theme) { /** * The main workspace. - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; /** * The Blockly theme to use. - * @type {!Blockly.Theme} + * @type {!Theme} * @private */ this.theme_ = theme; /** * A list of workspaces that are subscribed to this theme. - * @type {!Array} + * @type {!Array} * @private */ this.subscribedWorkspaces_ = []; @@ -70,7 +73,7 @@ ThemeManager.Component; /** * Get the workspace theme. - * @return {!Blockly.Theme} The workspace theme. + * @return {!Theme} The workspace theme. * @package */ ThemeManager.prototype.getTheme = function() { @@ -79,7 +82,7 @@ ThemeManager.prototype.getTheme = function() { /** * Set the workspace theme, and refresh the workspace and all components. - * @param {!Blockly.Theme} theme The workspace theme. + * @param {!Theme} theme The workspace theme. * @package */ ThemeManager.prototype.setTheme = function(theme) { @@ -90,9 +93,9 @@ ThemeManager.prototype.setTheme = function(theme) { const injectionDiv = this.workspace_.getInjectionDiv(); if (injectionDiv) { if (prevTheme) { - Blockly.utils.dom.removeClass(injectionDiv, prevTheme.getClassName()); + dom.removeClass(injectionDiv, prevTheme.getClassName()); } - Blockly.utils.dom.addClass(injectionDiv, this.theme_.getClassName()); + dom.addClass(injectionDiv, this.theme_.getClassName()); } // Refresh all subscribed workspaces. @@ -117,7 +120,7 @@ ThemeManager.prototype.setTheme = function(theme) { /** * Subscribe a workspace to changes to the selected theme. If a new theme is * set, the workspace is called to refresh its blocks. - * @param {!Blockly.Workspace} workspace The workspace to subscribe. + * @param {!Workspace} workspace The workspace to subscribe. * @package */ ThemeManager.prototype.subscribeWorkspace = function(workspace) { @@ -126,7 +129,7 @@ ThemeManager.prototype.subscribeWorkspace = function(workspace) { /** * Unsubscribe a workspace to changes to the selected theme. - * @param {!Blockly.Workspace} workspace The workspace to unsubscribe. + * @param {!Workspace} workspace The workspace to unsubscribe. * @package */ ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { diff --git a/tests/deps.js b/tests/deps.js index 48a76dd48..6affa4354 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -164,7 +164,7 @@ goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); -goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.Theme'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); From d2a6e93a8a168c2ed87ea3370011de6cffc20722 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:53:07 -0700 Subject: [PATCH 350/833] clang-format core/theme_manager.js --- core/theme_manager.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/theme_manager.js b/core/theme_manager.js index a4f0aed6c..859a33658 100644 --- a/core/theme_manager.js +++ b/core/theme_manager.js @@ -32,7 +32,6 @@ const dom = goog.require('Blockly.utils.dom'); * @package */ const ThemeManager = function(workspace, theme) { - /** * The main workspace. * @type {!WorkspaceSvg} @@ -65,10 +64,10 @@ const ThemeManager = function(workspace, theme) { /** * A Blockly UI component type. * @typedef {{ - * element:!Element, - * propertyName:string - * }} - */ + * element:!Element, + * propertyName:string + * }} + */ ThemeManager.Component; /** @@ -104,8 +103,8 @@ ThemeManager.prototype.setTheme = function(theme) { } // Refresh all registered Blockly UI components. - for (let i = 0, keys = Object.keys(this.componentDB_), - key; (key = keys[i]); i++) { + for (let i = 0, keys = Object.keys(this.componentDB_), key; (key = keys[i]); + i++) { for (let j = 0, component; (component = this.componentDB_[key][j]); j++) { const element = component.element; const propertyName = component.propertyName; @@ -149,17 +148,15 @@ ThemeManager.prototype.unsubscribeWorkspace = function(workspace) { * @param {string} propertyName The inline style property name to update. * @package */ -ThemeManager.prototype.subscribe = function(element, componentName, - propertyName) { +ThemeManager.prototype.subscribe = function( + element, componentName, propertyName) { if (!this.componentDB_[componentName]) { this.componentDB_[componentName] = []; } // Add the element to our component map. - this.componentDB_[componentName].push({ - element: element, - propertyName: propertyName - }); + this.componentDB_[componentName].push( + {element: element, propertyName: propertyName}); // Initialize the element with its corresponding theme style. const style = this.theme_ && this.theme_.getComponentStyle(componentName); From f6adf865f29bd9619148a1fbd77ccecfbe25457e Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 23 Jul 2021 19:39:37 +0100 Subject: [PATCH 351/833] Migrate core/utils/size.js to goog.module --- core/utils/size.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/utils/size.js b/core/utils/size.js index 2ffa91ac1..56ec2eb91 100644 --- a/core/utils/size.js +++ b/core/utils/size.js @@ -13,10 +13,11 @@ 'use strict'; /** - * @name Blockly.utils.Size + * @name Size * @namespace */ -goog.provide('Blockly.utils.Size'); +goog.module('Blockly.utils.Size'); +goog.module.declareLegacyNamespace(); /** @@ -26,7 +27,7 @@ goog.provide('Blockly.utils.Size'); * @struct * @constructor */ -Blockly.utils.Size = function(width, height) { +const Size = function(width, height) { /** * Width * @type {number} @@ -42,12 +43,12 @@ Blockly.utils.Size = function(width, height) { /** * Compares sizes for equality. - * @param {?Blockly.utils.Size} a A Size. - * @param {?Blockly.utils.Size} b A Size. + * @param {?Size} a A Size. + * @param {?Size} b A Size. * @return {boolean} True iff the sizes have equal widths and equal * heights, or if both are null. */ -Blockly.utils.Size.equals = function(a, b) { +Size.equals = function(a, b) { if (a == b) { return true; } @@ -56,3 +57,5 @@ Blockly.utils.Size.equals = function(a, b) { } return a.width == b.width && a.height == b.height; }; + +exports = Size; diff --git a/tests/deps.js b/tests/deps.js index ae77407c9..c9fc4067f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -187,7 +187,7 @@ goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lan goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []); +goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/string.js', ['Blockly.utils.string'], []); goog.addDependency('../../core/utils/style.js', ['Blockly.utils.style'], ['Blockly.utils.Coordinate', 'Blockly.utils.Size'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/svg.js', ['Blockly.utils.Svg'], []); From 61bbffc29e28af25531c081760f9ddee9766d48f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:03:46 -0700 Subject: [PATCH 352/833] Migrate core/zoom_controls.js to ES6 const/let --- core/zoom_controls.js | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 7d0d7e6ce..465a5d165 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -182,7 +182,7 @@ Blockly.ZoomControls.prototype.createDom = function() { // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. // https://neil.fraser.name/news/2015/11/01/ - var rnd = String(Math.random()).substring(2); + const rnd = String(Math.random()).substring(2); this.createZoomOutSvg_(rnd); this.createZoomInSvg_(rnd); if (this.workspace_.isMovable()) { @@ -232,12 +232,12 @@ Blockly.ZoomControls.prototype.dispose = function() { * bounding box should be ignored by other UI elements. */ Blockly.ZoomControls.prototype.getBoundingRectangle = function() { - var height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; + let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - var bottom = this.top_ + height; - var right = this.left_ + this.WIDTH_; + const bottom = this.top_ + height; + const right = this.left_ + this.WIDTH_; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -256,41 +256,41 @@ Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { return; } - var cornerPosition = + const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - var height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; + let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - var startRect = Blockly.uiPosition.getStartPositionRect( + const startRect = Blockly.uiPosition.getStartPositionRect( cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); - var verticalPosition = cornerPosition.vertical; - var bumpDirection = + const verticalPosition = cornerPosition.vertical; + const bumpDirection = verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? Blockly.uiPosition.bumpDirection.DOWN : Blockly.uiPosition.bumpDirection.UP; - var positionRect = Blockly.uiPosition.bumpPositionRect( + const positionRect = Blockly.uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === Blockly.uiPosition.verticalPosition.TOP) { - var zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; + const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { - var zoomResetTranslateY = + const zoomResetTranslateY = zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; this.zoomResetGroup_.setAttribute('transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { - var zoomInTranslateY = this.zoomResetGroup_ ? + const zoomInTranslateY = this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); - var zoomOutTranslateY = + const zoomOutTranslateY = zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; this.zoomOutGroup_.setAttribute('transform', 'translate(0, ' + zoomOutTranslateY + ')'); @@ -322,7 +322,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.zoomOutGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd @@ -335,7 +335,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { 'height': 32, }, clip); - var zoomoutSvg = Blockly.utils.dom.createSvgElement( + const zoomoutSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -374,7 +374,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.zoomInGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd @@ -387,7 +387,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { 'height': 32, }, clip); - var zoominSvg = Blockly.utils.dom.createSvgElement( + const zoominSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -443,7 +443,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.zoomResetGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - var clip = Blockly.utils.dom.createSvgElement( + const clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd @@ -456,7 +456,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { 'height': 32 }, clip); - var zoomresetSvg = Blockly.utils.dom.createSvgElement( + const zoomresetSvg = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'height': Blockly.internalConstants.SPRITE.height, @@ -484,14 +484,14 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { // zoom is passed amount and computes the new scale using the formula: // targetScale = currentScale * Math.pow(speed, amount) - var targetScale = this.workspace_.options.zoomOptions.startScale; - var currentScale = this.workspace_.scale; - var speed = this.workspace_.options.zoomOptions.scaleSpeed; + const targetScale = this.workspace_.options.zoomOptions.startScale; + const currentScale = this.workspace_.scale; + const speed = this.workspace_.options.zoomOptions.scaleSpeed; // To compute amount: // amount = log(speed, (targetScale / currentScale)) // Math.log computes natural logarithm (ln), to change the base, use formula: // log(base, value) = ln(value) / ln(base) - var amount = Math.log(targetScale / currentScale) / Math.log(speed); + const amount = Math.log(targetScale / currentScale) / Math.log(speed); this.workspace_.beginCanvasTransition(); this.workspace_.zoomCenter(amount); this.workspace_.scrollCenter(); @@ -508,7 +508,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * @private */ Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { - var uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( + const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); }; From bc7c5115e1ca36f235a64052584878cb49b8b8e4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:03:55 -0700 Subject: [PATCH 353/833] Migrate core/zoom_controls.js to goog.module --- core/zoom_controls.js | 50 +++++++++++++++++++++++-------------------- tests/deps.js | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 465a5d165..61455c120 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -10,8 +10,10 @@ */ 'use strict'; -goog.provide('Blockly.ZoomControls'); +goog.module('Blockly.ZoomControls'); +goog.module.declareLegacyNamespace(); +goog.require('Blockly'); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.Css'); @@ -36,7 +38,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @constructor * @implements {Blockly.IPositionable} */ -Blockly.ZoomControls = function(workspace) { +const ZoomControls = function(workspace) { /** * @type {!Blockly.WorkspaceSvg} * @private @@ -102,7 +104,7 @@ Blockly.ZoomControls = function(workspace) { * @const * @private */ -Blockly.ZoomControls.prototype.WIDTH_ = 32; +ZoomControls.prototype.WIDTH_ = 32; /** * Height of each zoom control. @@ -110,7 +112,7 @@ Blockly.ZoomControls.prototype.WIDTH_ = 32; * @const * @private */ -Blockly.ZoomControls.prototype.HEIGHT_ = 32; +ZoomControls.prototype.HEIGHT_ = 32; /** * Small spacing used between the zoom in and out control, in pixels. @@ -118,7 +120,7 @@ Blockly.ZoomControls.prototype.HEIGHT_ = 32; * @const * @private */ -Blockly.ZoomControls.prototype.SMALL_SPACING_ = 2; +ZoomControls.prototype.SMALL_SPACING_ = 2; /** * Large spacing used between the zoom in and reset control, in pixels. @@ -126,7 +128,7 @@ Blockly.ZoomControls.prototype.SMALL_SPACING_ = 2; * @const * @private */ -Blockly.ZoomControls.prototype.LARGE_SPACING_ = 11; +ZoomControls.prototype.LARGE_SPACING_ = 11; /** * Distance between zoom controls and bottom or top edge of workspace. @@ -134,48 +136,48 @@ Blockly.ZoomControls.prototype.LARGE_SPACING_ = 11; * @const * @private */ -Blockly.ZoomControls.prototype.MARGIN_VERTICAL_ = 20; +ZoomControls.prototype.MARGIN_VERTICAL_ = 20; /** * Distance between zoom controls and right or left edge of workspace. * @type {number} * @private */ -Blockly.ZoomControls.prototype.MARGIN_HORIZONTAL_ = 20; +ZoomControls.prototype.MARGIN_HORIZONTAL_ = 20; /** * The SVG group containing the zoom controls. * @type {SVGElement} * @private */ -Blockly.ZoomControls.prototype.svgGroup_ = null; +ZoomControls.prototype.svgGroup_ = null; /** * Left coordinate of the zoom controls. * @type {number} * @private */ -Blockly.ZoomControls.prototype.left_ = 0; +ZoomControls.prototype.left_ = 0; /** * Top coordinate of the zoom controls. * @type {number} * @private */ -Blockly.ZoomControls.prototype.top_ = 0; +ZoomControls.prototype.top_ = 0; /** * Whether this has been initialized. * @type {boolean} * @private */ -Blockly.ZoomControls.prototype.initialized_ = false; +ZoomControls.prototype.initialized_ = false; /** * Create the zoom controls. * @return {!SVGElement} The zoom controls SVG group. */ -Blockly.ZoomControls.prototype.createDom = function() { +ZoomControls.prototype.createDom = function() { this.svgGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {}, null); @@ -196,7 +198,7 @@ Blockly.ZoomControls.prototype.createDom = function() { /** * Initializes the zoom controls. */ -Blockly.ZoomControls.prototype.init = function() { +ZoomControls.prototype.init = function() { this.workspace_.getComponentManager().addComponent({ component: this, weight: 2, @@ -209,7 +211,7 @@ Blockly.ZoomControls.prototype.init = function() { * Disposes of this zoom controls. * Unlink from all DOM elements to prevent memory leaks. */ -Blockly.ZoomControls.prototype.dispose = function() { +ZoomControls.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); @@ -231,7 +233,7 @@ Blockly.ZoomControls.prototype.dispose = function() { * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.ZoomControls.prototype.getBoundingRectangle = function() { +ZoomControls.prototype.getBoundingRectangle = function() { let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; @@ -250,7 +252,7 @@ Blockly.ZoomControls.prototype.getBoundingRectangle = function() { * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { +ZoomControls.prototype.position = function(metrics, savedPositions) { // Not yet initialized. if (!this.initialized_) { return; @@ -309,7 +311,7 @@ Blockly.ZoomControls.prototype.position = function(metrics, savedPositions) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { +ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -361,7 +363,7 @@ Blockly.ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { +ZoomControls.prototype.createZoomInSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -414,7 +416,7 @@ Blockly.ZoomControls.prototype.createZoomInSvg_ = function(rnd) { * @param {!Event} e A mouse down event. * @private */ -Blockly.ZoomControls.prototype.zoom_ = function(amount, e) { +ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.markFocused(); this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); @@ -430,7 +432,7 @@ Blockly.ZoomControls.prototype.zoom_ = function(amount, e) { * instances on the same page. * @private */ -Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { +ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { /* This markup will be generated and added to the .svgGroup_: @@ -479,7 +481,7 @@ Blockly.ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { * @param {!Event} e A mouse down event. * @private */ -Blockly.ZoomControls.prototype.resetZoom_ = function(e) { +ZoomControls.prototype.resetZoom_ = function(e) { this.workspace_.markFocused(); // zoom is passed amount and computes the new scale using the formula: @@ -507,7 +509,7 @@ Blockly.ZoomControls.prototype.resetZoom_ = function(e) { * Fires a zoom control UI event. * @private */ -Blockly.ZoomControls.prototype.fireZoomEvent_ = function() { +ZoomControls.prototype.fireZoomEvent_ = function() { const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); Blockly.Events.fire(uiEvent); @@ -531,3 +533,5 @@ Blockly.Css.register([ '}' /* eslint-enable indent */ ]); + +exports = ZoomControls; diff --git a/tests/deps.js b/tests/deps.js index 702bf5ae4..c61cd74c1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -210,6 +210,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es5'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('base.js', [], []); From 40c095f496a8d901d97b0b3506fdc586e0f12101 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:05:49 -0700 Subject: [PATCH 354/833] Migrate core/zoom_controls.js named requires --- core/zoom_controls.js | 166 +++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 61455c120..84451bbd1 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -13,34 +13,34 @@ goog.module('Blockly.ZoomControls'); goog.module.declareLegacyNamespace(); -goog.require('Blockly'); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.ComponentManager'); -goog.require('Blockly.Css'); -goog.require('Blockly.Events'); +const Blockly = goog.require('Blockly'); +const ComponentManager = goog.require('Blockly.ComponentManager'); +const Css = goog.require('Blockly.Css'); +const Events = goog.require('Blockly.Events'); +const IPositionable = goog.require('Blockly.IPositionable'); +const Rect = goog.require('Blockly.utils.Rect'); +const Svg = goog.require('Blockly.utils.Svg'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const internalConstants = goog.require('Blockly.internalConstants'); +const uiPosition = goog.require('Blockly.uiPosition'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Click'); -goog.require('Blockly.IPositionable'); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.Touch'); -goog.require('Blockly.uiPosition'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Rect'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.WorkspaceSvg'); /** * Class for a zoom controls. - * @param {!Blockly.WorkspaceSvg} workspace The workspace to sit in. + * @param {!WorkspaceSvg} workspace The workspace to sit in. * @constructor - * @implements {Blockly.IPositionable} + * @implements {IPositionable} */ const ZoomControls = function(workspace) { /** - * @type {!Blockly.WorkspaceSvg} + * @type {!WorkspaceSvg} * @private */ this.workspace_ = workspace; @@ -55,7 +55,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom reset * button. Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomResetWrapper_ = null; @@ -63,7 +63,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom in button. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomInWrapper_ = null; @@ -71,7 +71,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom out button. * Opaque data returned from Blockly.bindEventWithChecks_. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onZoomOutWrapper_ = null; @@ -178,8 +178,8 @@ ZoomControls.prototype.initialized_ = false; * @return {!SVGElement} The zoom controls SVG group. */ ZoomControls.prototype.createDom = function() { - this.svgGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, {}, null); + this.svgGroup_ = dom.createSvgElement( + Svg.G, {}, null); // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. @@ -202,7 +202,7 @@ ZoomControls.prototype.init = function() { this.workspace_.getComponentManager().addComponent({ component: this, weight: 2, - capabilities: [Blockly.ComponentManager.Capability.POSITIONABLE] + capabilities: [ComponentManager.Capability.POSITIONABLE] }); this.initialized_ = true; }; @@ -214,23 +214,23 @@ ZoomControls.prototype.init = function() { ZoomControls.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('zoomControls'); if (this.svgGroup_) { - Blockly.utils.dom.removeNode(this.svgGroup_); + dom.removeNode(this.svgGroup_); } if (this.onZoomResetWrapper_) { - Blockly.browserEvents.unbind(this.onZoomResetWrapper_); + browserEvents.unbind(this.onZoomResetWrapper_); } if (this.onZoomInWrapper_) { - Blockly.browserEvents.unbind(this.onZoomInWrapper_); + browserEvents.unbind(this.onZoomInWrapper_); } if (this.onZoomOutWrapper_) { - Blockly.browserEvents.unbind(this.onZoomOutWrapper_); + browserEvents.unbind(this.onZoomOutWrapper_); } }; /** * Returns the bounding rectangle of the UI element in pixel units relative to * the Blockly injection div. - * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if + * @return {?Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ ZoomControls.prototype.getBoundingRectangle = function() { @@ -240,7 +240,7 @@ ZoomControls.prototype.getBoundingRectangle = function() { } const bottom = this.top_ + height; const right = this.left_ + this.WIDTH_; - return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); + return new Rect(this.top_, bottom, this.left_, right); }; @@ -249,7 +249,7 @@ ZoomControls.prototype.getBoundingRectangle = function() { * It is positioned in the opposite corner to the corner the * categories/toolbox starts at. * @param {!Blockly.MetricsManager.UiMetrics} metrics The workspace metrics. - * @param {!Array} savedPositions List of rectangles that + * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ ZoomControls.prototype.position = function(metrics, savedPositions) { @@ -259,25 +259,25 @@ ZoomControls.prototype.position = function(metrics, savedPositions) { } const cornerPosition = - Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); + uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); let height = this.SMALL_SPACING_ + 2 * this.HEIGHT_; if (this.zoomResetGroup_) { height += this.LARGE_SPACING_ + this.HEIGHT_; } - const startRect = Blockly.uiPosition.getStartPositionRect( - cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), + const startRect = uiPosition.getStartPositionRect( + cornerPosition, new utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; const bumpDirection = - verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? - Blockly.uiPosition.bumpDirection.DOWN : - Blockly.uiPosition.bumpDirection.UP; - const positionRect = Blockly.uiPosition.bumpPositionRect( + verticalPosition === uiPosition.verticalPosition.TOP ? + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; + const positionRect = uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); - if (verticalPosition === Blockly.uiPosition.verticalPosition.TOP) { + if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; this.zoomInGroup_.setAttribute('transform', 'translate(0, ' + zoomInTranslateY + ')'); @@ -321,38 +321,38 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { clip-path="url(#blocklyZoomoutClipPath837493)"> */ - this.zoomOutGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomOutGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoomoutClipPath' + rnd }, this.zoomOutGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32, }, clip); - const zoomoutSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoomoutSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'x': -64, 'y': -92, 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')' }, this.zoomOutGroup_); zoomoutSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach listener. - this.onZoomOutWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomOutWrapper_ = browserEvents.conditionalBind( this.zoomOutGroup_, 'mousedown', null, this.zoom_.bind(this, -1)); }; @@ -373,38 +373,38 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { clip-path="url(#blocklyZoominClipPath837493)"> */ - this.zoomInGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomInGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoominClipPath' + rnd }, this.zoomInGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32, }, clip); - const zoominSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoominSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'x': -32, 'y': -92, 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')' }, this.zoomInGroup_); zoominSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach listener. - this.onZoomInWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomInWrapper_ = browserEvents.conditionalBind( this.zoomInGroup_, 'mousedown', null, this.zoom_.bind(this, 1)); }; @@ -420,7 +420,7 @@ ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.markFocused(); this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); - Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. + Touch.clearTouchIdentifier(); // Don't block future drags. e.stopPropagation(); // Don't start a workspace scroll. e.preventDefault(); // Stop double-clicking from selecting text. }; @@ -442,37 +442,37 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { clip-path="url(#blocklyZoomresetClipPath837493)"> */ - this.zoomResetGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.zoomResetGroup_ = dom.createSvgElement( + Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); - const clip = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CLIPPATH, + const clip = dom.createSvgElement( + Svg.CLIPPATH, { 'id': 'blocklyZoomresetClipPath' + rnd }, this.zoomResetGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'width': 32, 'height': 32 }, clip); - const zoomresetSvg = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.IMAGE, { - 'width': Blockly.internalConstants.SPRITE.width, - 'height': Blockly.internalConstants.SPRITE.height, + const zoomresetSvg = dom.createSvgElement( + Svg.IMAGE, { + 'width': internalConstants.SPRITE.width, + 'height': internalConstants.SPRITE.height, 'y': -92, 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')' }, this.zoomResetGroup_); zoomresetSvg.setAttributeNS( - Blockly.utils.dom.XLINK_NS, 'xlink:href', + dom.XLINK_NS, 'xlink:href', this.workspace_.options.pathToMedia + - Blockly.internalConstants.SPRITE.url); + internalConstants.SPRITE.url); // Attach event listeners. - this.onZoomResetWrapper_ = Blockly.browserEvents.conditionalBind( + this.onZoomResetWrapper_ = browserEvents.conditionalBind( this.zoomResetGroup_, 'mousedown', null, this.resetZoom_.bind(this)); }; @@ -500,7 +500,7 @@ ZoomControls.prototype.resetZoom_ = function(e) { setTimeout(this.workspace_.endCanvasTransition.bind(this.workspace_), 500); this.fireZoomEvent_(); - Blockly.Touch.clearTouchIdentifier(); // Don't block future drags. + Touch.clearTouchIdentifier(); // Don't block future drags. e.stopPropagation(); // Don't start a workspace scroll. e.preventDefault(); // Stop double-clicking from selecting text. }; @@ -510,15 +510,15 @@ ZoomControls.prototype.resetZoom_ = function(e) { * @private */ ZoomControls.prototype.fireZoomEvent_ = function() { - const uiEvent = new (Blockly.Events.get(Blockly.Events.CLICK))( + const uiEvent = new (Events.get(Events.CLICK))( null, this.workspace_.id, 'zoom_controls'); - Blockly.Events.fire(uiEvent); + Events.fire(uiEvent); }; /** * CSS for zoom controls. See css.js for use. */ -Blockly.Css.register([ +Css.register([ /* eslint-disable indent */ '.blocklyZoom>image, .blocklyZoom>svg>image {', 'opacity: .4;', From 5a5aabb7e7a759ce254cd675be84ad8e297285b8 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:09:14 -0700 Subject: [PATCH 355/833] clang-format core/zoom_controls.js --- core/zoom_controls.js | 133 +++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 80 deletions(-) diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 84451bbd1..37c1cb17d 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -178,8 +178,7 @@ ZoomControls.prototype.initialized_ = false; * @return {!SVGElement} The zoom controls SVG group. */ ZoomControls.prototype.createDom = function() { - this.svgGroup_ = dom.createSvgElement( - Svg.G, {}, null); + this.svgGroup_ = dom.createSvgElement(Svg.G, {}, null); // Each filter/pattern needs a unique ID for the case of multiple Blockly // instances on a page. Browser behaviour becomes undefined otherwise. @@ -266,42 +265,40 @@ ZoomControls.prototype.position = function(metrics, savedPositions) { } const startRect = uiPosition.getStartPositionRect( cornerPosition, new utils.Size(this.WIDTH_, height), - this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, - this.workspace_); + this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; - const bumpDirection = - verticalPosition === uiPosition.verticalPosition.TOP ? - uiPosition.bumpDirection.DOWN : - uiPosition.bumpDirection.UP; + const bumpDirection = verticalPosition === uiPosition.verticalPosition.TOP ? + uiPosition.bumpDirection.DOWN : + uiPosition.bumpDirection.UP; const positionRect = uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); if (verticalPosition === uiPosition.verticalPosition.TOP) { const zoomInTranslateY = this.SMALL_SPACING_ + this.HEIGHT_; - this.zoomInGroup_.setAttribute('transform', - 'translate(0, ' + zoomInTranslateY + ')'); + this.zoomInGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); if (this.zoomResetGroup_) { const zoomResetTranslateY = zoomInTranslateY + this.LARGE_SPACING_ + this.HEIGHT_; - this.zoomResetGroup_.setAttribute('transform', - 'translate(0, ' + zoomResetTranslateY + ')'); + this.zoomResetGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomResetTranslateY + ')'); } } else { - const zoomInTranslateY = this.zoomResetGroup_ ? - this.LARGE_SPACING_ + this.HEIGHT_ : 0; - this.zoomInGroup_.setAttribute('transform', - 'translate(0, ' + zoomInTranslateY + ')'); + const zoomInTranslateY = + this.zoomResetGroup_ ? this.LARGE_SPACING_ + this.HEIGHT_ : 0; + this.zoomInGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomInTranslateY + ')'); const zoomOutTranslateY = zoomInTranslateY + this.SMALL_SPACING_ + this.HEIGHT_; - this.zoomOutGroup_.setAttribute('transform', - 'translate(0, ' + zoomOutTranslateY + ')'); + this.zoomOutGroup_.setAttribute( + 'transform', 'translate(0, ' + zoomOutTranslateY + ')'); } this.top_ = positionRect.top; this.left_ = positionRect.left; - this.svgGroup_.setAttribute('transform', - 'translate(' + this.left_ + ',' + this.top_ + ')'); + this.svgGroup_.setAttribute( + 'transform', 'translate(' + this.left_ + ',' + this.top_ + ')'); }; /** @@ -317,22 +314,17 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { */ - this.zoomOutGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomOutGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoomoutClipPath' + rnd - }, - this.zoomOutGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoomoutClipPath' + rnd}, this.zoomOutGroup_); dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'width': 32, 'height': 32, }, @@ -348,8 +340,7 @@ ZoomControls.prototype.createZoomOutSvg_ = function(rnd) { this.zoomOutGroup_); zoomoutSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach listener. this.onZoomOutWrapper_ = browserEvents.conditionalBind( @@ -369,22 +360,17 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { - */ - this.zoomInGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomInGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoominClipPath' + rnd - }, - this.zoomInGroup_); + Svg.CLIPPATH, {'id': 'blocklyZoominClipPath' + rnd}, this.zoomInGroup_); dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'width': 32, 'height': 32, }, @@ -400,8 +386,7 @@ ZoomControls.prototype.createZoomInSvg_ = function(rnd) { this.zoomInGroup_); zoominSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach listener. this.onZoomInWrapper_ = browserEvents.conditionalBind( @@ -421,8 +406,8 @@ ZoomControls.prototype.zoom_ = function(amount, e) { this.workspace_.zoomCenter(amount); this.fireZoomEvent_(); Touch.clearTouchIdentifier(); // Don't block future drags. - e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); // Stop double-clicking from selecting text. + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. }; /** @@ -438,26 +423,17 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { - */ - this.zoomResetGroup_ = dom.createSvgElement( - Svg.G, - {'class': 'blocklyZoom'}, this.svgGroup_); + this.zoomResetGroup_ = + dom.createSvgElement(Svg.G, {'class': 'blocklyZoom'}, this.svgGroup_); const clip = dom.createSvgElement( - Svg.CLIPPATH, - { - 'id': 'blocklyZoomresetClipPath' + rnd - }, + Svg.CLIPPATH, {'id': 'blocklyZoomresetClipPath' + rnd}, this.zoomResetGroup_); - dom.createSvgElement( - Svg.RECT, - { - 'width': 32, - 'height': 32 - }, - clip); + dom.createSvgElement(Svg.RECT, {'width': 32, 'height': 32}, clip); const zoomresetSvg = dom.createSvgElement( Svg.IMAGE, { 'width': internalConstants.SPRITE.width, @@ -468,8 +444,7 @@ ZoomControls.prototype.createZoomResetSvg_ = function(rnd) { this.zoomResetGroup_); zoomresetSvg.setAttributeNS( dom.XLINK_NS, 'xlink:href', - this.workspace_.options.pathToMedia + - internalConstants.SPRITE.url); + this.workspace_.options.pathToMedia + internalConstants.SPRITE.url); // Attach event listeners. this.onZoomResetWrapper_ = browserEvents.conditionalBind( @@ -501,8 +476,8 @@ ZoomControls.prototype.resetZoom_ = function(e) { setTimeout(this.workspace_.endCanvasTransition.bind(this.workspace_), 500); this.fireZoomEvent_(); Touch.clearTouchIdentifier(); // Don't block future drags. - e.stopPropagation(); // Don't start a workspace scroll. - e.preventDefault(); // Stop double-clicking from selecting text. + e.stopPropagation(); // Don't start a workspace scroll. + e.preventDefault(); // Stop double-clicking from selecting text. }; /** @@ -510,8 +485,8 @@ ZoomControls.prototype.resetZoom_ = function(e) { * @private */ ZoomControls.prototype.fireZoomEvent_ = function() { - const uiEvent = new (Events.get(Events.CLICK))( - null, this.workspace_.id, 'zoom_controls'); + const uiEvent = + new (Events.get(Events.CLICK))(null, this.workspace_.id, 'zoom_controls'); Events.fire(uiEvent); }; @@ -519,19 +494,17 @@ ZoomControls.prototype.fireZoomEvent_ = function() { * CSS for zoom controls. See css.js for use. */ Css.register([ - /* eslint-disable indent */ - '.blocklyZoom>image, .blocklyZoom>svg>image {', - 'opacity: .4;', - '}', + `.blocklyZoom>image, .blocklyZoom>svg>image { + opacity: .4; +}`, - '.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover {', - 'opacity: .6;', - '}', + `.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover { + opacity: .6; +}`, - '.blocklyZoom>image:active, .blocklyZoom>svg>image:active {', - 'opacity: .8;', - '}' - /* eslint-enable indent */ + `.blocklyZoom>image:active, .blocklyZoom>svg>image:active { + 'opacity: .8; +}` ]); exports = ZoomControls; From 636cd58add1b0449e6b91d660374eecd1eedae4d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 12:35:21 -0700 Subject: [PATCH 356/833] Add comment to top of convert-file script for reference to syntax used throughout the file --- scripts/goog_module/convert-file.sh | 55 +++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 6a8d36cd0..9f8ea63ee 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -1,5 +1,39 @@ #!/bin/bash +# This file makes extensive use of perl for the purpose of extracting and +# replacing string (regex) patterns in a way that is both GNU and macOS +# compatible. +# +# Common perl flags used (also decribed at https://perldoc.perl.org/perlrun): +# -e : Used to execute perl programs on the command line +# -p : Assumes an input loop around script. Prints every processed line. +# -n : Assumes an input loop around script. Does not print every line. +# -i : Used for in-place editing. Used for commands for find/replace. +# -l[octnum] : Assigns the output record separator "$/" as an octal number. If +# octnum is not present, sets output record separator to the current +# value of the input record separator "$\". +# +# Common perl commands found: +# 1. perl -pi -e 's/regex/replacement/modifiers' +# This command does an in-place search-and-replace. The global ("/g") modifier +# causes it to replace all occurrences, rather than only the first match. +# 2. perl -ne 'print m/regex/modifiers' +# This command returns the all regex matches. If the global ("/g") modifier is +# specified, then the capture group "()" is not necessary and it will return +# all matches, rather than only the first match. +# 3. perl -nle 'print $& while m{regex}modifiers' +# Similar to (2), but returns regex matches separated by newlines. +# The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. +# +# Additional information on regex: +# This script makes use of some advanced regex syntax such as "capture groups" +# and "lookaround assertions". +# Additionally, characters are escaped from regex with a backslash "\". +# Single quotes need to be escaped in both regex and the string, resulting in +# '\'' being used to represent a single quote character. +# For a reference to syntax of regular expressions in Perl, see: +# https://perldoc.perl.org/perire + ####################################### # Logging functions. ####################################### @@ -98,10 +132,10 @@ step2 () { local filepath="$1" inf "Updating goog.provide declaration..." - perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/g' "${filepath}" + perl -pi -e 's/^goog\.provide(\([^\)]+\)\;)/goog\.module\1\ngoog.module.declareLegacyNamespace\(\)\;/' "${filepath}" inf "Extracting module name..." - local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + local module_name=$(perl -ne 'print m/(?<=^goog\.module\('\'')([^'\'']+)/' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 @@ -109,7 +143,7 @@ step2 () { inf "Extracted module name \"${module_name}\"" if [[ $(grep "${module_name} = " "${filepath}") ]]; then - local class_name=$(echo "${module_name}" | perl -nle'print $& while m{(\w+)$}g') + local class_name=$(echo "${module_name}" | perl -ne 'print m/(\w+)$/') inf "Found class \"${class_name}\" in file." inf "Updating class declaration..." perl -pi -e 's/^('"${module_name}"') =/const '"${class_name}"' =/g' "${filepath}" @@ -144,19 +178,19 @@ step2 () { ####################################### step3() { inf "Extracting module name..." - local module_name=$(perl -nle'print $& while m{(?<=^goog\.module\('\'')([^'\'')]+)}g' "${filepath}") + local module_name=$(perl -ne 'print m/(?<=^goog\.module\('\'')([^'\'']+)/' "${filepath}") if [[ -z "${module_name}" ]]; then err "Could not extract module name" return 1 fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") # Process each require echo "${requires}" | while read -r require; do inf "Processing require \"${require}\"" - local usages=$(perl -nle'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) + local usages=$(perl -nle 'print $& while m{'"${require}"'(?!'\'')}g' "${filepath}" | wc -l) if [[ "${usages}" -eq "0" ]]; then warn "Unused require \"${require}\"" @@ -168,11 +202,12 @@ step3() { perl -pi -e 's/^(goog\.(require|requireType)\('\'"${require}"\''\);)/const '"${require_name}"' = \1/' "${filepath}" # Parse property access of module - local direct_access_count=$(perl -nle'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) - local properties_accessed=$(perl -nle'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | tr ' ' '\n' | sort -u) + local direct_access_count=$(perl -nle 'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) + local properties_accessed=$(perl -nle 'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | sort -u) + # Detect requires overlap # (ex: Blockly.utils require and Blockly.utils.dom also in requires) - local requires_overlap=$(echo "${requires}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + local requires_overlap=$(echo "${requires}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') @@ -180,7 +215,7 @@ step3() { fi # Detect module name overlap # (ex: Blockly require and Blockly.ContextMenuItems module being converted) - local module_overlap=$(echo "${module_name}" | perl -nle'print $& while m{(?<='"${require}"'\.)\w+}g') + local module_overlap=$(echo "${module_name}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') fi From f64e8df4866056444c44505f771397e40ea0fed1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 15:26:16 -0700 Subject: [PATCH 357/833] Update wording --- scripts/goog_module/convert-file.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 9f8ea63ee..0246be0be 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -18,9 +18,10 @@ # This command does an in-place search-and-replace. The global ("/g") modifier # causes it to replace all occurrences, rather than only the first match. # 2. perl -ne 'print m/regex/modifiers' -# This command returns the all regex matches. If the global ("/g") modifier is -# specified, then the capture group "()" is not necessary and it will return -# all matches, rather than only the first match. +# This command returns a string containing the regex match. The regex must +# contain a capture group "()", unless the global ("\g") modifier is +# specified. This will return the first match, unless the global modifier is +# specified, in which case, it will return all matches. # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. From 3fbbedf6f1c9156b7ddfd64d4e82b8a28271c191 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 18:10:53 -0700 Subject: [PATCH 358/833] Fix typos and update wording again --- scripts/goog_module/convert-file.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 0246be0be..38ac2eafb 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -4,11 +4,11 @@ # replacing string (regex) patterns in a way that is both GNU and macOS # compatible. # -# Common perl flags used (also decribed at https://perldoc.perl.org/perlrun): +# Common perl flags used (also described at https://perldoc.perl.org/perlrun): # -e : Used to execute perl programs on the command line # -p : Assumes an input loop around script. Prints every processed line. # -n : Assumes an input loop around script. Does not print every line. -# -i : Used for in-place editing. Used for commands for find/replace. +# -i : Used for in-place editing. Used in commands for find/replace. # -l[octnum] : Assigns the output record separator "$/" as an octal number. If # octnum is not present, sets output record separator to the current # value of the input record separator "$\". @@ -18,10 +18,11 @@ # This command does an in-place search-and-replace. The global ("/g") modifier # causes it to replace all occurrences, rather than only the first match. # 2. perl -ne 'print m/regex/modifiers' -# This command returns a string containing the regex match. The regex must -# contain a capture group "()", unless the global ("\g") modifier is -# specified. This will return the first match, unless the global modifier is -# specified, in which case, it will return all matches. +# This command returns a string containing the regex match (designated by the +# capture group "()" in the regex). This will return the first match, unless +# the global modifier is specified, in which case, it will return all matches. +# If this command is used without a capture group it returns true or false (in +# the form a truthy or falsey value) # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. @@ -33,7 +34,7 @@ # Single quotes need to be escaped in both regex and the string, resulting in # '\'' being used to represent a single quote character. # For a reference to syntax of regular expressions in Perl, see: -# https://perldoc.perl.org/perire +# https://perldoc.perl.org/perlre ####################################### # Logging functions. @@ -240,7 +241,7 @@ step3() { missing_requires=$(echo "${missing_requires}" | tr ' ' '\n' | sort -u) if [[ -n "${missing_requires}" ]]; then # Search for the string goog.require('Blockly') or goog.requireType('Blockly') - local has_blockly_require=$(perl -ne'print m{goog\.(require|requireType)\('\''Blockly'\''\)}g' "${filepath}") + local has_blockly_require=$(perl -ne 'print m/goog\.(?:require|requireType)\('\''Blockly'\''\)/' "${filepath}") if [[ -n "${has_blockly_require}" ]]; then warn 'Blockly detected as a require.' warn "Potentially missing requires for:\n${missing_requires}\nPlease manually review." From 7495fad6b3d9e489e504f66a7b19e96288df55c4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 18:37:13 -0700 Subject: [PATCH 359/833] Add missing period and fix typo --- scripts/goog_module/convert-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 38ac2eafb..ebf791d3b 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -22,7 +22,7 @@ # capture group "()" in the regex). This will return the first match, unless # the global modifier is specified, in which case, it will return all matches. # If this command is used without a capture group it returns true or false (in -# the form a truthy or falsey value) +# the form a truthy or falsy value). # 3. perl -nle 'print $& while m{regex}modifiers' # Similar to (2), but returns regex matches separated by newlines. # The "m{regex}modifiers" is equivalent to "m/regex/modifiers" syntax. From c068a3b6f9dcd304278bd5aa87a0d66460d698df Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:26:04 -0700 Subject: [PATCH 360/833] Migrate core/renderers/common/path_object.js to goog.module --- core/renderers/common/path_object.js | 39 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index e81b8e0e2..c6de3c492 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -11,7 +11,8 @@ 'use strict'; -goog.provide('Blockly.blockRendering.PathObject'); +goog.module('Blockly.blockRendering.PathObject'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.blockRendering.ConstantProvider'); goog.require('Blockly.blockRendering.IPathObject'); @@ -35,7 +36,7 @@ goog.requireType('Blockly.Connection'); * @implements {Blockly.blockRendering.IPathObject} * @package */ -Blockly.blockRendering.PathObject = function(root, style, constants) { +const PathObject = function(root, style, constants) { /** * The renderer's constant provider. * @type {!Blockly.blockRendering.ConstantProvider} @@ -83,7 +84,7 @@ Blockly.blockRendering.PathObject = function(root, style, constants) { * @param {string} pathString The path. * @package */ -Blockly.blockRendering.PathObject.prototype.setPath = function(pathString) { +PathObject.prototype.setPath = function(pathString) { this.svgPath.setAttribute('d', pathString); }; @@ -91,7 +92,7 @@ Blockly.blockRendering.PathObject.prototype.setPath = function(pathString) { * Flip the SVG paths in RTL. * @package */ -Blockly.blockRendering.PathObject.prototype.flipRTL = function() { +PathObject.prototype.flipRTL = function() { // Mirror the block's path. this.svgPath.setAttribute('transform', 'scale(-1 1)'); }; @@ -102,7 +103,7 @@ Blockly.blockRendering.PathObject.prototype.flipRTL = function() { * block SVG group. * @package */ -Blockly.blockRendering.PathObject.prototype.setCursorSvg = function(cursorSvg) { +PathObject.prototype.setCursorSvg = function(cursorSvg) { if (!cursorSvg) { this.cursorSvg = null; return; @@ -118,7 +119,7 @@ Blockly.blockRendering.PathObject.prototype.setCursorSvg = function(cursorSvg) { * block SVG group. * @package */ -Blockly.blockRendering.PathObject.prototype.setMarkerSvg = function(markerSvg) { +PathObject.prototype.setMarkerSvg = function(markerSvg) { if (!markerSvg) { this.markerSvg = null; return; @@ -138,7 +139,7 @@ Blockly.blockRendering.PathObject.prototype.setMarkerSvg = function(markerSvg) { * @param {!Blockly.Block} block The source block. * @package */ -Blockly.blockRendering.PathObject.prototype.applyColour = function(block) { +PathObject.prototype.applyColour = function(block) { this.svgPath.setAttribute('stroke', this.style.colourTertiary); this.svgPath.setAttribute('fill', this.style.colourPrimary); @@ -151,7 +152,7 @@ Blockly.blockRendering.PathObject.prototype.applyColour = function(block) { * @param {!Blockly.Theme.BlockStyle} blockStyle The block style to use. * @package */ -Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) { +PathObject.prototype.setStyle = function(blockStyle) { this.style = blockStyle; }; @@ -162,7 +163,7 @@ Blockly.blockRendering.PathObject.prototype.setStyle = function(blockStyle) { * be removed. * @protected */ -Blockly.blockRendering.PathObject.prototype.setClass_ = function( +PathObject.prototype.setClass_ = function( className, add) { if (add) { Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgRoot), @@ -179,7 +180,7 @@ Blockly.blockRendering.PathObject.prototype.setClass_ = function( * @param {boolean} enable True if highlighted. * @package */ -Blockly.blockRendering.PathObject.prototype.updateHighlighted = function( +PathObject.prototype.updateHighlighted = function( enable) { if (enable) { this.svgPath.setAttribute('filter', @@ -194,7 +195,7 @@ Blockly.blockRendering.PathObject.prototype.updateHighlighted = function( * @param {boolean} shadow True if the block is a shadow block. * @protected */ -Blockly.blockRendering.PathObject.prototype.updateShadow_ = function(shadow) { +PathObject.prototype.updateShadow_ = function(shadow) { if (shadow) { this.svgPath.setAttribute('stroke', 'none'); this.svgPath.setAttribute('fill', this.style.colourSecondary); @@ -206,7 +207,7 @@ Blockly.blockRendering.PathObject.prototype.updateShadow_ = function(shadow) { * @param {boolean} disabled True if disabled. * @protected */ -Blockly.blockRendering.PathObject.prototype.updateDisabled_ = function( +PathObject.prototype.updateDisabled_ = function( disabled) { this.setClass_('blocklyDisabled', disabled); if (disabled) { @@ -220,7 +221,7 @@ Blockly.blockRendering.PathObject.prototype.updateDisabled_ = function( * @param {boolean} enable True if selection is enabled, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateSelected = function(enable) { +PathObject.prototype.updateSelected = function(enable) { this.setClass_('blocklySelected', enable); }; @@ -230,7 +231,7 @@ Blockly.blockRendering.PathObject.prototype.updateSelected = function(enable) { * area, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateDraggingDelete = function( +PathObject.prototype.updateDraggingDelete = function( enable) { this.setClass_('blocklyDraggingDelete', enable); }; @@ -241,7 +242,7 @@ Blockly.blockRendering.PathObject.prototype.updateDraggingDelete = function( * otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateInsertionMarker = function( +PathObject.prototype.updateInsertionMarker = function( enable) { this.setClass_('blocklyInsertionMarker', enable); }; @@ -251,7 +252,7 @@ Blockly.blockRendering.PathObject.prototype.updateInsertionMarker = function( * @param {boolean} enable True if the block is movable, false otherwise. * @package */ -Blockly.blockRendering.PathObject.prototype.updateMovable = function(enable) { +PathObject.prototype.updateMovable = function(enable) { this.setClass_('blocklyDraggable', enable); }; @@ -262,7 +263,7 @@ Blockly.blockRendering.PathObject.prototype.updateMovable = function(enable) { * @param {boolean} enable True if styling should be added. * @package */ -Blockly.blockRendering.PathObject.prototype.updateReplacementFade = +PathObject.prototype.updateReplacementFade = function(enable) { /* eslint-disable indent */ this.setClass_('blocklyReplaceable', enable); @@ -275,8 +276,10 @@ Blockly.blockRendering.PathObject.prototype.updateReplacementFade = * @param {boolean} _enable True if styling should be added. * @package */ -Blockly.blockRendering.PathObject.prototype.updateShapeForInputHighlight = +PathObject.prototype.updateShapeForInputHighlight = function(_conn, _enable) { /* eslint-disable indent */ // NOP }; /* eslint-enable indent */ + +exports = PathObject; diff --git a/tests/deps.js b/tests/deps.js index 805416071..aa69691cb 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -126,7 +126,7 @@ goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRende goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom']); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); From 027763e094ad3d68a0a78f1db485115e1c5c1cdd Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Tue, 27 Jul 2021 14:28:13 -0700 Subject: [PATCH 361/833] Update exports to new agreed syntax --- core/utils/aria.js | 11 ++++------- tests/deps.js | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/utils/aria.js b/core/utils/aria.js index 464ba77b0..b387b4677 100644 --- a/core/utils/aria.js +++ b/core/utils/aria.js @@ -69,6 +69,7 @@ const Role = { // ARIA role for a tree item that sometimes may be expanded or collapsed. TREEITEM: 'treeitem' }; +exports.Role = Role; /** * ARIA states and properties. @@ -134,6 +135,7 @@ const State = { // ARIA property for slider minimum value. Value: number. VALUEMIN: 'valuemin' }; +exports.State = State; /** * Sets the role of an element. @@ -146,6 +148,7 @@ const State = { const setRole = function(element, roleName) { element.setAttribute(ROLE_ATTRIBUTE, roleName); }; +exports.setRole = setRole; /** * Sets the state or property of an element. @@ -164,10 +167,4 @@ const setState = function(element, stateName, value) { const attrStateName = ARIA_PREFIX + stateName; element.setAttribute(attrStateName, value); }; - -exports = { - Role, - State, - setRole, - setState, -}; +exports.setState = setState; diff --git a/tests/deps.js b/tests/deps.js index 805416071..d695aabd8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -175,7 +175,7 @@ goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalC goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); +goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/coordinate.js', ['Blockly.utils.Coordinate'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/deprecation.js', ['Blockly.utils.deprecation'], [], {'lang': 'es6', 'module': 'goog'}); From cf3d22c4901b65894ce6a63151140139079173f2 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:39:02 -0700 Subject: [PATCH 362/833] Migrate core/renderers/common/path_object.js named requires --- core/renderers/common/path_object.js | 44 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index c6de3c492..bb3cca63a 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -14,32 +14,36 @@ goog.module('Blockly.blockRendering.PathObject'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.blockRendering.ConstantProvider'); -goog.require('Blockly.blockRendering.IPathObject'); -goog.require('Blockly.Theme'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const Connection = goog.requireType('Blockly.Connection'); +/* eslint-disable-next-line no-unused-vars */ +const ConstantProvider = goog.requireType('Blockly.blockRendering.ConstantProvider'); +/* eslint-disable-next-line no-unused-vars */ +const IPathObject = goog.require('Blockly.blockRendering.IPathObject'); +const Svg = goog.require('Blockly.utils.Svg'); +/* eslint-disable-next-line no-unused-vars */ +const Theme = goog.requireType('Blockly.Theme'); +const dom = goog.require('Blockly.utils.dom'); /** * An object that handles creating and setting each of the SVG elements * used by the renderer. * @param {!SVGElement} root The root SVG element. - * @param {!Blockly.Theme.BlockStyle} style The style object to use for + * @param {!Theme.BlockStyle} style The style object to use for * colouring. - * @param {!Blockly.blockRendering.ConstantProvider} constants The renderer's + * @param {!ConstantProvider} constants The renderer's * constants. * @constructor - * @implements {Blockly.blockRendering.IPathObject} + * @implements {IPathObject} * @package */ const PathObject = function(root, style, constants) { /** * The renderer's constant provider. - * @type {!Blockly.blockRendering.ConstantProvider} + * @type {!ConstantProvider} * @package */ this.constants = constants; @@ -51,13 +55,13 @@ const PathObject = function(root, style, constants) { * @type {!SVGElement} * @package */ - this.svgPath = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + this.svgPath = dom.createSvgElement( + Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); /** * The style object to use when colouring block paths. - * @type {!Blockly.Theme.BlockStyle} + * @type {!Theme.BlockStyle} * @package */ this.style = style; @@ -136,7 +140,7 @@ PathObject.prototype.setMarkerSvg = function(markerSvg) { /** * Apply the stored colours to the block's path, taking into account whether * the paths belong to a shadow block. - * @param {!Blockly.Block} block The source block. + * @param {!Block} block The source block. * @package */ PathObject.prototype.applyColour = function(block) { @@ -149,7 +153,7 @@ PathObject.prototype.applyColour = function(block) { /** * Set the style. - * @param {!Blockly.Theme.BlockStyle} blockStyle The block style to use. + * @param {!Theme.BlockStyle} blockStyle The block style to use. * @package */ PathObject.prototype.setStyle = function(blockStyle) { @@ -166,10 +170,10 @@ PathObject.prototype.setStyle = function(blockStyle) { PathObject.prototype.setClass_ = function( className, add) { if (add) { - Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgRoot), + dom.addClass(/** @type {!Element} */ (this.svgRoot), className); } else { - Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.svgRoot), + dom.removeClass(/** @type {!Element} */ (this.svgRoot), className); } }; @@ -272,7 +276,7 @@ PathObject.prototype.updateReplacementFade = /** * Add or remove styling that shows that if the dragging block is dropped, this * block will be connected to the input. - * @param {Blockly.Connection} _conn The connection on the input to highlight. + * @param {Connection} _conn The connection on the input to highlight. * @param {boolean} _enable True if styling should be added. * @package */ diff --git a/tests/deps.js b/tests/deps.js index aa69691cb..8d394ea2f 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -126,7 +126,7 @@ goog.addDependency('../../core/renderers/common/drawer.js', ['Blockly.blockRende goog.addDependency('../../core/renderers/common/i_path_object.js', ['Blockly.blockRendering.IPathObject'], []); goog.addDependency('../../core/renderers/common/info.js', ['Blockly.blockRendering.RenderInfo'], ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.ExternalValueInput', 'Blockly.blockRendering.Field', 'Blockly.blockRendering.Hat', 'Blockly.blockRendering.Icon', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.InlineInput', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.JaggedEdge', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.RoundCorner', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.SquareCorner', 'Blockly.blockRendering.StatementInput', 'Blockly.blockRendering.TopRow', 'Blockly.blockRendering.Types', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/marker_svg.js', ['Blockly.blockRendering.MarkerSvg'], ['Blockly.ASTNode', 'Blockly.Events', 'Blockly.Events.MarkerMove', 'Blockly.connectionTypes', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.Theme', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/renderers/common/path_object.js', ['Blockly.blockRendering.PathObject'], ['Blockly.blockRendering.IPathObject', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/renderers/common/renderer.js', ['Blockly.blockRendering.Renderer'], ['Blockly.IRegistrable', 'Blockly.InsertionMarkerManager', 'Blockly.blockRendering.ConstantProvider', 'Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.IPathObject', 'Blockly.blockRendering.MarkerSvg', 'Blockly.blockRendering.PathObject', 'Blockly.blockRendering.RenderInfo', 'Blockly.connectionTypes']); goog.addDependency('../../core/renderers/geras/constants.js', ['Blockly.geras.ConstantProvider'], ['Blockly.blockRendering.ConstantProvider', 'Blockly.utils.object'], {'lang': 'es5'}); goog.addDependency('../../core/renderers/geras/drawer.js', ['Blockly.geras.Drawer'], ['Blockly.blockRendering.Drawer', 'Blockly.geras.Highlighter', 'Blockly.geras.RenderInfo', 'Blockly.utils.object', 'Blockly.utils.svgPaths']); From 55207a2e7fd152412d0a41740e5dfdc17201a705 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 14:41:29 -0700 Subject: [PATCH 363/833] clang-format core/renderers/common/path_object.js --- core/renderers/common/path_object.js | 46 ++++++++++------------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/core/renderers/common/path_object.js b/core/renderers/common/path_object.js index bb3cca63a..7b1f6af9d 100644 --- a/core/renderers/common/path_object.js +++ b/core/renderers/common/path_object.js @@ -55,9 +55,8 @@ const PathObject = function(root, style, constants) { * @type {!SVGElement} * @package */ - this.svgPath = dom.createSvgElement( - Svg.PATH, - {'class': 'blocklyPath'}, this.svgRoot); + this.svgPath = + dom.createSvgElement(Svg.PATH, {'class': 'blocklyPath'}, this.svgRoot); /** * The style object to use when colouring block paths. @@ -167,14 +166,11 @@ PathObject.prototype.setStyle = function(blockStyle) { * be removed. * @protected */ -PathObject.prototype.setClass_ = function( - className, add) { +PathObject.prototype.setClass_ = function(className, add) { if (add) { - dom.addClass(/** @type {!Element} */ (this.svgRoot), - className); + dom.addClass(/** @type {!Element} */ (this.svgRoot), className); } else { - dom.removeClass(/** @type {!Element} */ (this.svgRoot), - className); + dom.removeClass(/** @type {!Element} */ (this.svgRoot), className); } }; @@ -184,11 +180,10 @@ PathObject.prototype.setClass_ = function( * @param {boolean} enable True if highlighted. * @package */ -PathObject.prototype.updateHighlighted = function( - enable) { +PathObject.prototype.updateHighlighted = function(enable) { if (enable) { - this.svgPath.setAttribute('filter', - 'url(#' + this.constants.embossFilterId + ')'); + this.svgPath.setAttribute( + 'filter', 'url(#' + this.constants.embossFilterId + ')'); } else { this.svgPath.setAttribute('filter', 'none'); } @@ -211,12 +206,11 @@ PathObject.prototype.updateShadow_ = function(shadow) { * @param {boolean} disabled True if disabled. * @protected */ -PathObject.prototype.updateDisabled_ = function( - disabled) { +PathObject.prototype.updateDisabled_ = function(disabled) { this.setClass_('blocklyDisabled', disabled); if (disabled) { - this.svgPath.setAttribute('fill', - 'url(#' + this.constants.disabledPatternId + ')'); + this.svgPath.setAttribute( + 'fill', 'url(#' + this.constants.disabledPatternId + ')'); } }; @@ -235,8 +229,7 @@ PathObject.prototype.updateSelected = function(enable) { * area, false otherwise. * @package */ -PathObject.prototype.updateDraggingDelete = function( - enable) { +PathObject.prototype.updateDraggingDelete = function(enable) { this.setClass_('blocklyDraggingDelete', enable); }; @@ -246,8 +239,7 @@ PathObject.prototype.updateDraggingDelete = function( * otherwise. * @package */ -PathObject.prototype.updateInsertionMarker = function( - enable) { +PathObject.prototype.updateInsertionMarker = function(enable) { this.setClass_('blocklyInsertionMarker', enable); }; @@ -267,11 +259,9 @@ PathObject.prototype.updateMovable = function(enable) { * @param {boolean} enable True if styling should be added. * @package */ -PathObject.prototype.updateReplacementFade = - function(enable) { - /* eslint-disable indent */ +PathObject.prototype.updateReplacementFade = function(enable) { this.setClass_('blocklyReplaceable', enable); -}; /* eslint-enable indent */ +}; /** * Add or remove styling that shows that if the dragging block is dropped, this @@ -280,10 +270,8 @@ PathObject.prototype.updateReplacementFade = * @param {boolean} _enable True if styling should be added. * @package */ -PathObject.prototype.updateShapeForInputHighlight = - function(_conn, _enable) { - /* eslint-disable indent */ +PathObject.prototype.updateShapeForInputHighlight = function(_conn, _enable) { // NOP -}; /* eslint-enable indent */ +}; exports = PathObject; From e04050cd710199763591270640fefa7b3a3d6aba Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:54:32 -0700 Subject: [PATCH 364/833] Migrate core/warning.js to ES6 const/let --- core/warning.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/warning.js b/core/warning.js index 9bbd9c91b..e596f0328 100644 --- a/core/warning.js +++ b/core/warning.js @@ -145,8 +145,8 @@ Blockly.Warning.prototype.setText = function(text, id) { * @return {string} All texts concatenated into one string. */ Blockly.Warning.prototype.getText = function() { - var allWarnings = []; - for (var id in this.text_) { + const allWarnings = []; + for (let id in this.text_) { allWarnings.push(this.text_[id]); } return allWarnings.join('\n'); From 94b9169bf56402140a0cbcb123595fd5cabb64ab Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:54:52 -0700 Subject: [PATCH 365/833] Migrate core/warning.js to goog.module --- core/warning.js | 27 +++++++++++++++------------ tests/deps.js | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/warning.js b/core/warning.js index e596f0328..c39e7cad9 100644 --- a/core/warning.js +++ b/core/warning.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Warning'); +goog.module('Blockly.Warning'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Bubble'); goog.require('Blockly.Events'); @@ -32,25 +33,25 @@ goog.requireType('Blockly.utils.Coordinate'); * @extends {Blockly.Icon} * @constructor */ -Blockly.Warning = function(block) { - Blockly.Warning.superClass_.constructor.call(this, block); +const Warning = function(block) { + Warning.superClass_.constructor.call(this, block); this.createIcon(); // The text_ object can contain multiple warnings. this.text_ = Object.create(null); }; -Blockly.utils.object.inherits(Blockly.Warning, Blockly.Icon); +Blockly.utils.object.inherits(Warning, Blockly.Icon); /** * Does this icon get hidden when the block is collapsed. */ -Blockly.Warning.prototype.collapseHidden = false; +Warning.prototype.collapseHidden = false; /** * Draw the warning icon. * @param {!Element} group The icon group. * @protected */ -Blockly.Warning.prototype.drawIcon_ = function(group) { +Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATH, @@ -83,7 +84,7 @@ Blockly.Warning.prototype.drawIcon_ = function(group) { * Show or hide the warning bubble. * @param {boolean} visible True if the bubble should be visible. */ -Blockly.Warning.prototype.setVisible = function(visible) { +Warning.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } @@ -100,7 +101,7 @@ Blockly.Warning.prototype.setVisible = function(visible) { * Show the bubble. * @private */ -Blockly.Warning.prototype.createBubble_ = function() { +Warning.prototype.createBubble_ = function() { this.paragraphElement_ = Blockly.Bubble.textToDom(this.getText()); this.bubble_ = Blockly.Bubble.createNonEditableBubble( this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), @@ -112,7 +113,7 @@ Blockly.Warning.prototype.createBubble_ = function() { * Dispose of the bubble and references to it. * @private */ -Blockly.Warning.prototype.disposeBubble_ = function() { +Warning.prototype.disposeBubble_ = function() { this.bubble_.dispose(); this.bubble_ = null; this.paragraphElement_ = null; @@ -125,7 +126,7 @@ Blockly.Warning.prototype.disposeBubble_ = function() { * @param {string} id An ID for this text entry to be able to maintain * multiple warnings. */ -Blockly.Warning.prototype.setText = function(text, id) { +Warning.prototype.setText = function(text, id) { if (this.text_[id] == text) { return; } @@ -144,7 +145,7 @@ Blockly.Warning.prototype.setText = function(text, id) { * Get this warning's texts. * @return {string} All texts concatenated into one string. */ -Blockly.Warning.prototype.getText = function() { +Warning.prototype.getText = function() { const allWarnings = []; for (let id in this.text_) { allWarnings.push(this.text_[id]); @@ -155,7 +156,9 @@ Blockly.Warning.prototype.getText = function() { /** * Dispose of this warning. */ -Blockly.Warning.prototype.dispose = function() { +Warning.prototype.dispose = function() { this.block_.warning = null; Blockly.Icon.prototype.dispose.call(this); }; + +exports = Warning; diff --git a/tests/deps.js b/tests/deps.js index 84c1c2b48..c6ccc9bb8 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -199,7 +199,7 @@ goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Bloc goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); -goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); From 9f3139c7520906c91ba18bc2edbcbda170414893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:58:28 -0700 Subject: [PATCH 366/833] Migrate core/warning.js named requires --- core/warning.js | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/core/warning.js b/core/warning.js index c39e7cad9..90bc15b12 100644 --- a/core/warning.js +++ b/core/warning.js @@ -13,24 +13,26 @@ goog.module('Blockly.Warning'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Bubble'); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Bubble = goog.require('Blockly.Bubble'); +/* eslint-disable-next-line no-unused-vars */ +const Coordinate = goog.requireType('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +const Icon = goog.require('Blockly.Icon'); +const Svg = goog.require('Blockly.utils.Svg'); +const dom = goog.require('Blockly.utils.dom'); +const object = goog.require('Blockly.utils.object'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.BubbleOpen'); -goog.require('Blockly.Icon'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.Svg'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.utils.Coordinate'); /** * Class for a warning. - * @param {!Blockly.Block} block The block associated with this warning. - * @extends {Blockly.Icon} + * @param {!Block} block The block associated with this warning. + * @extends {Icon} * @constructor */ const Warning = function(block) { @@ -39,7 +41,7 @@ const Warning = function(block) { // The text_ object can contain multiple warnings. this.text_ = Object.create(null); }; -Blockly.utils.object.inherits(Warning, Blockly.Icon); +object.inherits(Warning, Icon); /** * Does this icon get hidden when the block is collapsed. @@ -53,8 +55,8 @@ Warning.prototype.collapseHidden = false; */ Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconShape', 'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z' @@ -63,16 +65,16 @@ Warning.prototype.drawIcon_ = function(group) { // Can't use a real '!' text character since different browsers and operating // systems render it differently. // Body of exclamation point. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, + dom.createSvgElement( + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z' }, group); // Dot of exclamation point. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, + dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyIconSymbol', 'x': '7', 'y': '11', 'height': '2', 'width': '2' @@ -88,7 +90,7 @@ Warning.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BUBBLE_OPEN))( + Events.fire(new (Events.get(Events.BUBBLE_OPEN))( this.block_, visible, 'warning')); if (visible) { this.createBubble_(); @@ -102,10 +104,10 @@ Warning.prototype.setVisible = function(visible) { * @private */ Warning.prototype.createBubble_ = function() { - this.paragraphElement_ = Blockly.Bubble.textToDom(this.getText()); - this.bubble_ = Blockly.Bubble.createNonEditableBubble( - this.paragraphElement_, /** @type {!Blockly.BlockSvg} */ (this.block_), - /** @type {!Blockly.utils.Coordinate} */ (this.iconXY_)); + this.paragraphElement_ = Bubble.textToDom(this.getText()); + this.bubble_ = Bubble.createNonEditableBubble( + this.paragraphElement_, /** @type {!BlockSvg} */ (this.block_), + /** @type {!Coordinate} */ (this.iconXY_)); this.applyColour(); }; @@ -158,7 +160,7 @@ Warning.prototype.getText = function() { */ Warning.prototype.dispose = function() { this.block_.warning = null; - Blockly.Icon.prototype.dispose.call(this); + Icon.prototype.dispose.call(this); }; exports = Warning; From 8056bf04845a1c6666e6db8a3f02b4f2a762b291 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 13:59:56 -0700 Subject: [PATCH 367/833] clang-format core/warning.js --- core/warning.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core/warning.js b/core/warning.js index 90bc15b12..e08088e94 100644 --- a/core/warning.js +++ b/core/warning.js @@ -56,8 +56,7 @@ Warning.prototype.collapseHidden = false; Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconShape', 'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z' }, @@ -66,18 +65,19 @@ Warning.prototype.drawIcon_ = function(group) { // systems render it differently. // Body of exclamation point. dom.createSvgElement( - Svg.PATH, - { + Svg.PATH, { 'class': 'blocklyIconSymbol', 'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z' }, group); // Dot of exclamation point. dom.createSvgElement( - Svg.RECT, - { + Svg.RECT, { 'class': 'blocklyIconSymbol', - 'x': '7', 'y': '11', 'height': '2', 'width': '2' + 'x': '7', + 'y': '11', + 'height': '2', + 'width': '2' }, group); }; @@ -90,8 +90,8 @@ Warning.prototype.setVisible = function(visible) { if (visible == this.isVisible()) { return; } - Events.fire(new (Events.get(Events.BUBBLE_OPEN))( - this.block_, visible, 'warning')); + Events.fire( + new (Events.get(Events.BUBBLE_OPEN))(this.block_, visible, 'warning')); if (visible) { this.createBubble_(); } else { From 284d68be805dfc891d5f12d44abf73076098e70e Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 15:17:11 -0700 Subject: [PATCH 368/833] Update syntax for for..in loop --- core/warning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/warning.js b/core/warning.js index e08088e94..6ed5d0c02 100644 --- a/core/warning.js +++ b/core/warning.js @@ -149,7 +149,7 @@ Warning.prototype.setText = function(text, id) { */ Warning.prototype.getText = function() { const allWarnings = []; - for (let id in this.text_) { + for (const id in this.text_) { allWarnings.push(this.text_[id]); } return allWarnings.join('\n'); From e6bd6cabb18a312ae9c7ba35157d28576c5bc2b3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:01:01 -0700 Subject: [PATCH 369/833] Migrate core/keyboard_nav/ast_node.js to ES6 const/let --- core/keyboard_nav/ast_node.js | 156 ++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 71 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index d86a22a4c..115ffe2a1 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -147,7 +147,7 @@ Blockly.ASTNode.createConnectionNode = function(connection) { if (!connection) { return null; } - var type = connection.type; + const type = connection.type; if (type == Blockly.connectionTypes.INPUT_VALUE) { return Blockly.ASTNode.createInputNode(connection.getParentInput()); } else if (type == Blockly.connectionTypes.NEXT_STATEMENT && @@ -215,7 +215,7 @@ Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { if (!wsCoordinate || !workspace) { return null; } - var params = { + const params = { wsCoordinate: wsCoordinate }; return new Blockly.ASTNode( @@ -230,8 +230,8 @@ Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { * block. */ Blockly.ASTNode.createTopNode = function(block) { - var astNode; - var topConnection = block.previousConnection || block.outputConnection; + let astNode; + const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { astNode = Blockly.ASTNode.createConnectionNode(topConnection); } else { @@ -302,13 +302,15 @@ Blockly.ASTNode.prototype.isConnection = function() { * @private */ Blockly.ASTNode.prototype.findNextForInput_ = function() { - var location = /** @type {!Blockly.Connection} */ (this.location_); - var parentInput = location.getParentInput(); - var block = parentInput.getSourceBlock(); - var curIdx = block.inputList.indexOf(parentInput); - for (var i = curIdx + 1, input; (input = block.inputList[i]); i++) { - var fieldRow = input.fieldRow; - for (var j = 0, field; (field = fieldRow[j]); j++) { + const location = /** @type {!Blockly.Connection} */ (this.location_); + const parentInput = location.getParentInput(); + const block = parentInput.getSourceBlock(); + const curIdx = block.inputList.indexOf(parentInput); + let i = curIdx + 1, input; + for (; (input = block.inputList[i]); i++) { + const fieldRow = input.fieldRow; + let j = 0, field; + for (; (field = fieldRow[j]); j++) { if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(field); } @@ -329,13 +331,14 @@ Blockly.ASTNode.prototype.findNextForInput_ = function() { * @private */ Blockly.ASTNode.prototype.findNextForField_ = function() { - var location = /** @type {!Blockly.Field} */ (this.location_); - var input = location.getParentInput(); - var block = location.getSourceBlock(); - var curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); - var fieldIdx = input.fieldRow.indexOf(location) + 1; - for (var i = curIdx, newInput; (newInput = block.inputList[i]); i++) { - var fieldRow = newInput.fieldRow; + const location = /** @type {!Blockly.Field} */ (this.location_); + const input = location.getParentInput(); + const block = location.getSourceBlock(); + const curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); + let fieldIdx = input.fieldRow.indexOf(location) + 1; + let i = curIdx, newInput; + for (; (newInput = block.inputList[i]); i++) { + const fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); @@ -359,16 +362,18 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { * @private */ Blockly.ASTNode.prototype.findPrevForInput_ = function() { - var location = /** @type {!Blockly.Connection} */ (this.location_); - var parentInput = location.getParentInput(); - var block = parentInput.getSourceBlock(); - var curIdx = block.inputList.indexOf(parentInput); - for (var i = curIdx, input; (input = block.inputList[i]); i--) { + const location = /** @type {!Blockly.Connection} */ (this.location_); + const parentInput = location.getParentInput(); + const block = parentInput.getSourceBlock(); + const curIdx = block.inputList.indexOf(parentInput); + let i = curIdx, input; + for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { return Blockly.ASTNode.createInputNode(input); } - var fieldRow = input.fieldRow; - for (var j = fieldRow.length - 1, field; (field = fieldRow[j]); j--) { + const fieldRow = input.fieldRow; + let j = fieldRow.length - 1, field; + for (; (field = fieldRow[j]); j--) { if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(field); } @@ -384,17 +389,18 @@ Blockly.ASTNode.prototype.findPrevForInput_ = function() { * @private */ Blockly.ASTNode.prototype.findPrevForField_ = function() { - var location = /** @type {!Blockly.Field} */ (this.location_); - var parentInput = location.getParentInput(); - var block = location.getSourceBlock(); - var curIdx = block.inputList.indexOf( + const location = /** @type {!Blockly.Field} */ (this.location_); + const parentInput = location.getParentInput(); + const block = location.getSourceBlock(); + const curIdx = block.inputList.indexOf( /** @type {!Blockly.Input} */ (parentInput)); - var fieldIdx = parentInput.fieldRow.indexOf(location) - 1; - for (var i = curIdx, input; (input = block.inputList[i]); i--) { + let fieldIdx = parentInput.fieldRow.indexOf(location) - 1; + let i = curIdx, input; + for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { return Blockly.ASTNode.createInputNode(input); } - var fieldRow = input.fieldRow; + const fieldRow = input.fieldRow; while (fieldIdx > -1) { if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); @@ -425,12 +431,13 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { if (!curLocation || !curLocation.workspace) { return null; } - var curRoot = curLocation.getRootBlock(); - var topBlocks = curRoot.workspace.getTopBlocks(true); - for (var i = 0, topBlock; (topBlock = topBlocks[i]); i++) { + const curRoot = curLocation.getRootBlock(); + const topBlocks = curRoot.workspace.getTopBlocks(true); + let i = 0, topBlock; + for (; (topBlock = topBlocks[i]); i++) { if (curRoot.id == topBlock.id) { - var offset = forward ? 1 : -1; - var resultIndex = i + offset; + const offset = forward ? 1 : -1; + const resultIndex = i + offset; if (resultIndex == -1 || resultIndex == topBlocks.length) { return null; } @@ -450,7 +457,7 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { * @private */ Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { - var topConnection = block.previousConnection || block.outputConnection; + const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { return /** @type {!Blockly.ASTNode} */ (Blockly.ASTNode.createConnectionNode( topConnection)); @@ -472,11 +479,12 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { if (!block) { return null; } - var topBlock; + let topBlock; // If the block doesn't have a previous connection then it is the top of the // substack. topBlock = block.getTopStackBlock(); - var topConnection = topBlock.previousConnection || topBlock.outputConnection; + const topConnection = + topBlock.previousConnection || topBlock.outputConnection; // If the top connection has a parentInput, create an AST node pointing to // that input. if (topConnection && topConnection.targetConnection && @@ -497,10 +505,12 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { * @private */ Blockly.ASTNode.prototype.findFirstFieldOrInput_ = function(block) { - var inputs = block.inputList; - for (var i = 0, input; (input = inputs[i]); i++) { - var fieldRow = input.fieldRow; - for (var j = 0, field; (field = fieldRow[j]); j++) { + const inputs = block.inputList; + let i = 0, input; + for (; (input = inputs[i]); i++) { + const fieldRow = input.fieldRow; + let j = 0, field; + for (; (field = fieldRow[j]); j++) { if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { return Blockly.ASTNode.createFieldNode(field); } @@ -536,12 +546,13 @@ Blockly.ASTNode.prototype.getSourceBlock = function() { * block, or workspace. Or null if there is no node to the right. */ Blockly.ASTNode.prototype.next = function() { + let connection, block, nextConnection, targetConnection; switch (this.type_) { case Blockly.ASTNode.types.STACK: return this.navigateBetweenStacks_(true); case Blockly.ASTNode.types.OUTPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); case Blockly.ASTNode.types.FIELD: @@ -551,17 +562,17 @@ Blockly.ASTNode.prototype.next = function() { return this.findNextForInput_(); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); - var nextConnection = block.nextConnection; + block = /** @type {!Blockly.Block} */ (this.location_); + nextConnection = block.nextConnection; return Blockly.ASTNode.createConnectionNode(nextConnection); case Blockly.ASTNode.types.PREVIOUS: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); case Blockly.ASTNode.types.NEXT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var targetConnection = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + targetConnection = connection.targetConnection; return Blockly.ASTNode.createConnectionNode(targetConnection); } @@ -575,26 +586,27 @@ Blockly.ASTNode.prototype.next = function() { * workspace, or block. Or null if there is nothing below this node. */ Blockly.ASTNode.prototype.in = function() { + let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { case Blockly.ASTNode.types.WORKSPACE: - var workspace = /** @type {!Blockly.Workspace} */ (this.location_); - var topBlocks = workspace.getTopBlocks(true); + workspace = /** @type {!Blockly.Workspace} */ (this.location_); + topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { return Blockly.ASTNode.createStackNode(topBlocks[0]); } break; case Blockly.ASTNode.types.STACK: - var block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Blockly.Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Blockly.Block} */ (this.location_); return this.findFirstFieldOrInput_(block); case Blockly.ASTNode.types.INPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var targetConnection = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + targetConnection = connection.targetConnection; return Blockly.ASTNode.createConnectionNode(targetConnection); } @@ -608,6 +620,7 @@ Blockly.ASTNode.prototype.in = function() { * null. */ Blockly.ASTNode.prototype.prev = function() { + let block, topConnection, connection, targetConnection; switch (this.type_) { case Blockly.ASTNode.types.STACK: return this.navigateBetweenStacks_(false); @@ -622,20 +635,20 @@ Blockly.ASTNode.prototype.prev = function() { return this.findPrevForInput_(); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); - var topConnection = block.previousConnection || block.outputConnection; + block = /** @type {!Blockly.Block} */ (this.location_); + topConnection = block.previousConnection || block.outputConnection; return Blockly.ASTNode.createConnectionNode(topConnection); case Blockly.ASTNode.types.PREVIOUS: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var targetConnection = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { return Blockly.ASTNode.createConnectionNode(targetConnection); } break; case Blockly.ASTNode.types.NEXT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); } @@ -649,41 +662,42 @@ Blockly.ASTNode.prototype.prev = function() { * workspace or block. Or null if we are at the workspace level. */ Blockly.ASTNode.prototype.out = function() { + let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { case Blockly.ASTNode.types.STACK: - var block = /** @type {!Blockly.Block} */ (this.location_); - var blockPos = block.getRelativeToSurfaceXY(); + block = /** @type {!Blockly.Block} */ (this.location_); + blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - var wsCoordinate = new Blockly.utils.Coordinate( + wsCoordinate = new Blockly.utils.Coordinate( blockPos.x, blockPos.y + Blockly.ASTNode.DEFAULT_OFFSET_Y); return Blockly.ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); case Blockly.ASTNode.types.OUTPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); - var target = connection.targetConnection; + connection = /** @type {!Blockly.Connection} */ (this.location_); + target = connection.targetConnection; if (target) { return Blockly.ASTNode.createConnectionNode(target); } return Blockly.ASTNode.createStackNode(connection.getSourceBlock()); case Blockly.ASTNode.types.FIELD: - var field = /** @type {!Blockly.Field} */ (this.location_); + field = /** @type {!Blockly.Field} */ (this.location_); return Blockly.ASTNode.createBlockNode(field.getSourceBlock()); case Blockly.ASTNode.types.INPUT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); case Blockly.ASTNode.types.BLOCK: - var block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Blockly.Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); case Blockly.ASTNode.types.PREVIOUS: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); case Blockly.ASTNode.types.NEXT: - var connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); } From ec06ea6586f06ded38c27815bdc07722406f6819 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 20 Jul 2021 16:13:39 -0700 Subject: [PATCH 370/833] Migrate core/keyboard_nav/ast_node.js to goog.module --- core/keyboard_nav/ast_node.js | 279 +++++++++++++++++----------------- tests/deps.js | 2 +- 2 files changed, 142 insertions(+), 139 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 115ffe2a1..e0a75d0c0 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.ASTNode'); +goog.module('Blockly.ASTNode'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.connectionTypes'); goog.require('Blockly.utils.Coordinate'); @@ -29,19 +30,19 @@ goog.requireType('Blockly.Workspace'); * It is recommended that you use one of the createNode methods instead of * creating a node directly. * @param {string} type The type of the location. - * Must be in Blockly.ASTNode.types. + * Must be in ASTNode.types. * @param {!Blockly.IASTNodeLocation} location The position in the AST. - * @param {!Blockly.ASTNode.Params=} opt_params Optional dictionary of options. + * @param {!ASTNode.Params=} opt_params Optional dictionary of options. * @constructor */ -Blockly.ASTNode = function(type, location, opt_params) { +const ASTNode = function(type, location, opt_params) { if (!location) { throw Error('Cannot create a node without a location.'); } /** * The type of the location. - * One of Blockly.ASTNode.types + * One of ASTNode.types * @type {string} * @private */ @@ -52,7 +53,7 @@ Blockly.ASTNode = function(type, location, opt_params) { * @type {boolean} * @private */ - this.isConnection_ = Blockly.ASTNode.isConnectionType_(type); + this.isConnection_ = ASTNode.isConnectionType_(type); /** * The location of the AST node. @@ -76,13 +77,13 @@ Blockly.ASTNode = function(type, location, opt_params) { * wsCoordinate: Blockly.utils.Coordinate * }} */ -Blockly.ASTNode.Params; +ASTNode.Params; /** * Object holding different types for an AST node. * @enum {string} */ -Blockly.ASTNode.types = { +ASTNode.types = { FIELD: 'field', BLOCK: 'block', INPUT: 'input', @@ -97,7 +98,7 @@ Blockly.ASTNode.types = { * True to navigate to all fields. False to only navigate to clickable fields. * @type {boolean} */ -Blockly.ASTNode.NAVIGATE_ALL_FIELDS = false; +ASTNode.NAVIGATE_ALL_FIELDS = false; /** * The default y offset to use when moving the cursor from a stack to the @@ -105,20 +106,20 @@ Blockly.ASTNode.NAVIGATE_ALL_FIELDS = false; * @type {number} * @private */ -Blockly.ASTNode.DEFAULT_OFFSET_Y = -20; +ASTNode.DEFAULT_OFFSET_Y = -20; /** * Whether an AST node of the given type points to a connection. - * @param {string} type The type to check. One of Blockly.ASTNode.types. + * @param {string} type The type to check. One of ASTNode.types. * @return {boolean} True if a node of the given type points to a connection. * @private */ -Blockly.ASTNode.isConnectionType_ = function(type) { +ASTNode.isConnectionType_ = function(type) { switch (type) { - case Blockly.ASTNode.types.PREVIOUS: - case Blockly.ASTNode.types.NEXT: - case Blockly.ASTNode.types.INPUT: - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.PREVIOUS: + case ASTNode.types.NEXT: + case ASTNode.types.INPUT: + case ASTNode.types.OUTPUT: return true; } return false; @@ -127,13 +128,13 @@ Blockly.ASTNode.isConnectionType_ = function(type) { /** * Create an AST node pointing to a field. * @param {Blockly.Field} field The location of the AST node. - * @return {Blockly.ASTNode} An AST node pointing to a field. + * @return {ASTNode} An AST node pointing to a field. */ -Blockly.ASTNode.createFieldNode = function(field) { +ASTNode.createFieldNode = function(field) { if (!field) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.FIELD, field); + return new ASTNode(ASTNode.types.FIELD, field); }; /** @@ -141,24 +142,24 @@ Blockly.ASTNode.createFieldNode = function(field) { * input then create an AST node of type input that will hold the connection. * @param {Blockly.Connection} connection This is the connection the node will * point to. - * @return {Blockly.ASTNode} An AST node pointing to a connection. + * @return {ASTNode} An AST node pointing to a connection. */ -Blockly.ASTNode.createConnectionNode = function(connection) { +ASTNode.createConnectionNode = function(connection) { if (!connection) { return null; } const type = connection.type; if (type == Blockly.connectionTypes.INPUT_VALUE) { - return Blockly.ASTNode.createInputNode(connection.getParentInput()); + return ASTNode.createInputNode(connection.getParentInput()); } else if (type == Blockly.connectionTypes.NEXT_STATEMENT && connection.getParentInput()) { - return Blockly.ASTNode.createInputNode(connection.getParentInput()); + return ASTNode.createInputNode(connection.getParentInput()); } else if (type == Blockly.connectionTypes.NEXT_STATEMENT) { - return new Blockly.ASTNode(Blockly.ASTNode.types.NEXT, connection); + return new ASTNode(ASTNode.types.NEXT, connection); } else if (type == Blockly.connectionTypes.OUTPUT_VALUE) { - return new Blockly.ASTNode(Blockly.ASTNode.types.OUTPUT, connection); + return new ASTNode(ASTNode.types.OUTPUT, connection); } else if (type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { - return new Blockly.ASTNode(Blockly.ASTNode.types.PREVIOUS, connection); + return new ASTNode(ASTNode.types.PREVIOUS, connection); } return null; }; @@ -167,25 +168,25 @@ Blockly.ASTNode.createConnectionNode = function(connection) { * Creates an AST node pointing to an input. Stores the input connection as the * location. * @param {Blockly.Input} input The input used to create an AST node. - * @return {Blockly.ASTNode} An AST node pointing to a input. + * @return {ASTNode} An AST node pointing to a input. */ -Blockly.ASTNode.createInputNode = function(input) { +ASTNode.createInputNode = function(input) { if (!input || !input.connection) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.INPUT, input.connection); + return new ASTNode(ASTNode.types.INPUT, input.connection); }; /** * Creates an AST node pointing to a block. * @param {Blockly.Block} block The block used to create an AST node. - * @return {Blockly.ASTNode} An AST node pointing to a block. + * @return {ASTNode} An AST node pointing to a block. */ -Blockly.ASTNode.createBlockNode = function(block) { +ASTNode.createBlockNode = function(block) { if (!block) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, block); + return new ASTNode(ASTNode.types.BLOCK, block); }; /** @@ -193,14 +194,14 @@ Blockly.ASTNode.createBlockNode = function(block) { * the set of all blocks connected to a top block, including the top block. * @param {Blockly.Block} topBlock A top block has no parent and can be found * in the list returned by workspace.getTopBlocks(). - * @return {Blockly.ASTNode} An AST node of type stack that points to the top + * @return {ASTNode} An AST node of type stack that points to the top * block on the stack. */ -Blockly.ASTNode.createStackNode = function(topBlock) { +ASTNode.createStackNode = function(topBlock) { if (!topBlock) { return null; } - return new Blockly.ASTNode(Blockly.ASTNode.types.STACK, topBlock); + return new ASTNode(ASTNode.types.STACK, topBlock); }; /** @@ -208,44 +209,44 @@ Blockly.ASTNode.createStackNode = function(topBlock) { * @param {!Blockly.Workspace} workspace The workspace that we are on. * @param {Blockly.utils.Coordinate} wsCoordinate The position on the workspace * for this node. - * @return {Blockly.ASTNode} An AST node pointing to a workspace and a position + * @return {ASTNode} An AST node pointing to a workspace and a position * on the workspace. */ -Blockly.ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { +ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { if (!wsCoordinate || !workspace) { return null; } const params = { wsCoordinate: wsCoordinate }; - return new Blockly.ASTNode( - Blockly.ASTNode.types.WORKSPACE, workspace, params); + return new ASTNode( + ASTNode.types.WORKSPACE, workspace, params); }; /** * Creates an AST node for the top position on a block. * This is either an output connection, previous connection, or block. * @param {!Blockly.Block} block The block to find the top most AST node on. - * @return {Blockly.ASTNode} The AST node holding the top most position on the + * @return {ASTNode} The AST node holding the top most position on the * block. */ -Blockly.ASTNode.createTopNode = function(block) { +ASTNode.createTopNode = function(block) { let astNode; const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { - astNode = Blockly.ASTNode.createConnectionNode(topConnection); + astNode = ASTNode.createConnectionNode(topConnection); } else { - astNode = Blockly.ASTNode.createBlockNode(block); + astNode = ASTNode.createBlockNode(block); } return astNode; }; /** * Parse the optional parameters. - * @param {?Blockly.ASTNode.Params} params The user specified parameters. + * @param {?ASTNode.Params} params The user specified parameters. * @private */ -Blockly.ASTNode.prototype.processParams_ = function(params) { +ASTNode.prototype.processParams_ = function(params) { if (!params) { return; } @@ -261,16 +262,16 @@ Blockly.ASTNode.prototype.processParams_ = function(params) { * @return {!Blockly.IASTNodeLocation} The current field, connection, workspace, or * block the cursor is on. */ -Blockly.ASTNode.prototype.getLocation = function() { +ASTNode.prototype.getLocation = function() { return this.location_; }; /** * The type of the current location. - * One of Blockly.ASTNode.types + * One of ASTNode.types * @return {string} The type of the location. */ -Blockly.ASTNode.prototype.getType = function() { +ASTNode.prototype.getType = function() { return this.type_; }; @@ -279,7 +280,7 @@ Blockly.ASTNode.prototype.getType = function() { * @return {Blockly.utils.Coordinate} The workspace coordinate or null if the * location is not a workspace. */ -Blockly.ASTNode.prototype.getWsCoordinate = function() { +ASTNode.prototype.getWsCoordinate = function() { return this.wsCoordinate_; }; @@ -288,7 +289,7 @@ Blockly.ASTNode.prototype.getWsCoordinate = function() { * @return {boolean} [description] * @package */ -Blockly.ASTNode.prototype.isConnection = function() { +ASTNode.prototype.isConnection = function() { return this.isConnection_; }; @@ -296,12 +297,12 @@ Blockly.ASTNode.prototype.isConnection = function() { * Given an input find the next editable field or an input with a non null * connection in the same block. The current location must be an input * connection. - * @return {Blockly.ASTNode} The AST node holding the next field or connection + * @return {ASTNode} The AST node holding the next field or connection * or null if there is no editable field or input connection after the given * input. * @private */ -Blockly.ASTNode.prototype.findNextForInput_ = function() { +ASTNode.prototype.findNextForInput_ = function() { const location = /** @type {!Blockly.Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); @@ -311,12 +312,12 @@ Blockly.ASTNode.prototype.findNextForInput_ = function() { const fieldRow = input.fieldRow; let j = 0, field; for (; (field = fieldRow[j]); j++) { - if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(field); + if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(field); } } if (input.connection) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } } return null; @@ -325,12 +326,12 @@ Blockly.ASTNode.prototype.findNextForInput_ = function() { /** * Given a field find the next editable field or an input with a non null * connection in the same block. The current location must be a field. - * @return {Blockly.ASTNode} The AST node pointing to the next field or + * @return {ASTNode} The AST node pointing to the next field or * connection or null if there is no editable field or input connection * after the given input. * @private */ -Blockly.ASTNode.prototype.findNextForField_ = function() { +ASTNode.prototype.findNextForField_ = function() { const location = /** @type {!Blockly.Field} */ (this.location_); const input = location.getParentInput(); const block = location.getSourceBlock(); @@ -340,14 +341,14 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { for (; (newInput = block.inputList[i]); i++) { const fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { - if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); + if (fieldRow[fieldIdx].isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(fieldRow[fieldIdx]); } fieldIdx++; } fieldIdx = 0; if (newInput.connection) { - return Blockly.ASTNode.createInputNode(newInput); + return ASTNode.createInputNode(newInput); } } return null; @@ -357,11 +358,11 @@ Blockly.ASTNode.prototype.findNextForField_ = function() { * Given an input find the previous editable field or an input with a non null * connection in the same block. The current location must be an input * connection. - * @return {Blockly.ASTNode} The AST node holding the previous field or + * @return {ASTNode} The AST node holding the previous field or * connection. * @private */ -Blockly.ASTNode.prototype.findPrevForInput_ = function() { +ASTNode.prototype.findPrevForInput_ = function() { const location = /** @type {!Blockly.Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); @@ -369,13 +370,13 @@ Blockly.ASTNode.prototype.findPrevForInput_ = function() { let i = curIdx, input; for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } const fieldRow = input.fieldRow; let j = fieldRow.length - 1, field; for (; (field = fieldRow[j]); j--) { - if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(field); + if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(field); } } } @@ -385,10 +386,10 @@ Blockly.ASTNode.prototype.findPrevForInput_ = function() { /** * Given a field find the previous editable field or an input with a non null * connection in the same block. The current location must be a field. - * @return {Blockly.ASTNode} The AST node holding the previous input or field. + * @return {ASTNode} The AST node holding the previous input or field. * @private */ -Blockly.ASTNode.prototype.findPrevForField_ = function() { +ASTNode.prototype.findPrevForField_ = function() { const location = /** @type {!Blockly.Field} */ (this.location_); const parentInput = location.getParentInput(); const block = location.getSourceBlock(); @@ -398,12 +399,12 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { let i = curIdx, input; for (; (input = block.inputList[i]); i--) { if (input.connection && input !== parentInput) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } const fieldRow = input.fieldRow; while (fieldIdx > -1) { - if (fieldRow[fieldIdx].isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(fieldRow[fieldIdx]); + if (fieldRow[fieldIdx].isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(fieldRow[fieldIdx]); } fieldIdx--; } @@ -418,11 +419,11 @@ Blockly.ASTNode.prototype.findPrevForField_ = function() { /** * Navigate between stacks of blocks on the workspace. * @param {boolean} forward True to go forward. False to go backwards. - * @return {Blockly.ASTNode} The first block of the next stack or null if there + * @return {ASTNode} The first block of the next stack or null if there * are no blocks on the workspace. * @private */ -Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { +ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); if (curLocation.getSourceBlock) { curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( @@ -441,7 +442,7 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { if (resultIndex == -1 || resultIndex == topBlocks.length) { return null; } - return Blockly.ASTNode.createStackNode(topBlocks[resultIndex]); + return ASTNode.createStackNode(topBlocks[resultIndex]); } } throw Error('Couldn\'t find ' + (forward ? 'next' : 'previous') + ' stack?!'); @@ -453,16 +454,16 @@ Blockly.ASTNode.prototype.navigateBetweenStacks_ = function(forward) { * on what kind of connections the block has. * @param {!Blockly.Block} block The block that we want to find the top * connection on. - * @return {!Blockly.ASTNode} The AST node containing the top connection. + * @return {!ASTNode} The AST node containing the top connection. * @private */ -Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { +ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { - return /** @type {!Blockly.ASTNode} */ (Blockly.ASTNode.createConnectionNode( + return /** @type {!ASTNode} */ (ASTNode.createConnectionNode( topConnection)); } else { - return /** @type {!Blockly.ASTNode} */ (Blockly.ASTNode.createBlockNode( + return /** @type {!ASTNode} */ (ASTNode.createBlockNode( block)); } }; @@ -471,11 +472,11 @@ Blockly.ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { * Get the AST node pointing to the input that the block is nested under or if * the block is not nested then get the stack AST node. * @param {Blockly.Block} block The source block of the current location. - * @return {Blockly.ASTNode} The AST node pointing to the input connection or + * @return {ASTNode} The AST node pointing to the input connection or * the top block of the stack this block is in. * @private */ -Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { +ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { if (!block) { return null; } @@ -489,34 +490,34 @@ Blockly.ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { // that input. if (topConnection && topConnection.targetConnection && topConnection.targetConnection.getParentInput()) { - return Blockly.ASTNode.createInputNode( + return ASTNode.createInputNode( topConnection.targetConnection.getParentInput()); } else { // Go to stack level if you are not underneath an input. - return Blockly.ASTNode.createStackNode(topBlock); + return ASTNode.createStackNode(topBlock); } }; /** * Find the first editable field or input with a connection on a given block. * @param {!Blockly.Block} block The source block of the current location. - * @return {Blockly.ASTNode} An AST node pointing to the first field or input. + * @return {ASTNode} An AST node pointing to the first field or input. * Null if there are no editable fields or inputs with connections on the block. * @private */ -Blockly.ASTNode.prototype.findFirstFieldOrInput_ = function(block) { +ASTNode.prototype.findFirstFieldOrInput_ = function(block) { const inputs = block.inputList; let i = 0, input; for (; (input = inputs[i]); i++) { const fieldRow = input.fieldRow; let j = 0, field; for (; (field = fieldRow[j]); j++) { - if (field.isClickable() || Blockly.ASTNode.NAVIGATE_ALL_FIELDS) { - return Blockly.ASTNode.createFieldNode(field); + if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { + return ASTNode.createFieldNode(field); } } if (input.connection) { - return Blockly.ASTNode.createInputNode(input); + return ASTNode.createInputNode(input); } } return null; @@ -527,12 +528,12 @@ Blockly.ASTNode.prototype.findFirstFieldOrInput_ = function(block) { * @return {Blockly.Block} The source block of the location, or null if the node * is of type workspace. */ -Blockly.ASTNode.prototype.getSourceBlock = function() { - if (this.getType() === Blockly.ASTNode.types.BLOCK) { +ASTNode.prototype.getSourceBlock = function() { + if (this.getType() === ASTNode.types.BLOCK) { return /** @type {Blockly.Block} */ (this.getLocation()); - } else if (this.getType() === Blockly.ASTNode.types.STACK) { + } else if (this.getType() === ASTNode.types.STACK) { return /** @type {Blockly.Block} */ (this.getLocation()); - } else if (this.getType() === Blockly.ASTNode.types.WORKSPACE) { + } else if (this.getType() === ASTNode.types.WORKSPACE) { return null; } else { return /** @type {Blockly.IASTNodeLocationWithBlock} */ ( @@ -542,38 +543,38 @@ Blockly.ASTNode.prototype.getSourceBlock = function() { /** * Find the element to the right of the current element in the AST. - * @return {Blockly.ASTNode} An AST node that wraps the next field, connection, + * @return {ASTNode} An AST node that wraps the next field, connection, * block, or workspace. Or null if there is no node to the right. */ -Blockly.ASTNode.prototype.next = function() { +ASTNode.prototype.next = function() { let connection, block, nextConnection, targetConnection; switch (this.type_) { - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: return this.navigateBetweenStacks_(true); - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.OUTPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.FIELD: + case ASTNode.types.FIELD: return this.findNextForField_(); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: return this.findNextForInput_(); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); nextConnection = block.nextConnection; - return Blockly.ASTNode.createConnectionNode(nextConnection); + return ASTNode.createConnectionNode(nextConnection); - case Blockly.ASTNode.types.PREVIOUS: + case ASTNode.types.PREVIOUS: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.NEXT: + case ASTNode.types.NEXT: connection = /** @type {!Blockly.Connection} */ (this.location_); targetConnection = connection.targetConnection; - return Blockly.ASTNode.createConnectionNode(targetConnection); + return ASTNode.createConnectionNode(targetConnection); } return null; @@ -582,32 +583,32 @@ Blockly.ASTNode.prototype.next = function() { /** * Find the element one level below and all the way to the left of the current * location. - * @return {Blockly.ASTNode} An AST node that wraps the next field, connection, + * @return {ASTNode} An AST node that wraps the next field, connection, * workspace, or block. Or null if there is nothing below this node. */ -Blockly.ASTNode.prototype.in = function() { +ASTNode.prototype.in = function() { let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { - case Blockly.ASTNode.types.WORKSPACE: + case ASTNode.types.WORKSPACE: workspace = /** @type {!Blockly.Workspace} */ (this.location_); topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { - return Blockly.ASTNode.createStackNode(topBlocks[0]); + return ASTNode.createStackNode(topBlocks[0]); } break; - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: block = /** @type {!Blockly.Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); return this.findFirstFieldOrInput_(block); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); targetConnection = connection.targetConnection; - return Blockly.ASTNode.createConnectionNode(targetConnection); + return ASTNode.createConnectionNode(targetConnection); } return null; @@ -615,41 +616,41 @@ Blockly.ASTNode.prototype.in = function() { /** * Find the element to the left of the current element in the AST. - * @return {Blockly.ASTNode} An AST node that wraps the previous field, + * @return {ASTNode} An AST node that wraps the previous field, * connection, workspace or block. Or null if no node exists to the left. * null. */ -Blockly.ASTNode.prototype.prev = function() { +ASTNode.prototype.prev = function() { let block, topConnection, connection, targetConnection; switch (this.type_) { - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: return this.navigateBetweenStacks_(false); - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.OUTPUT: return null; - case Blockly.ASTNode.types.FIELD: + case ASTNode.types.FIELD: return this.findPrevForField_(); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: return this.findPrevForInput_(); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); topConnection = block.previousConnection || block.outputConnection; - return Blockly.ASTNode.createConnectionNode(topConnection); + return ASTNode.createConnectionNode(topConnection); - case Blockly.ASTNode.types.PREVIOUS: + case ASTNode.types.PREVIOUS: connection = /** @type {!Blockly.Connection} */ (this.location_); targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { - return Blockly.ASTNode.createConnectionNode(targetConnection); + return ASTNode.createConnectionNode(targetConnection); } break; - case Blockly.ASTNode.types.NEXT: + case ASTNode.types.NEXT: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); } return null; @@ -658,48 +659,50 @@ Blockly.ASTNode.prototype.prev = function() { /** * Find the next element that is one position above and all the way to the left * of the current location. - * @return {Blockly.ASTNode} An AST node that wraps the next field, connection, + * @return {ASTNode} An AST node that wraps the next field, connection, * workspace or block. Or null if we are at the workspace level. */ -Blockly.ASTNode.prototype.out = function() { +ASTNode.prototype.out = function() { let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { - case Blockly.ASTNode.types.STACK: + case ASTNode.types.STACK: block = /** @type {!Blockly.Block} */ (this.location_); blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. wsCoordinate = new Blockly.utils.Coordinate( - blockPos.x, blockPos.y + Blockly.ASTNode.DEFAULT_OFFSET_Y); - return Blockly.ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); + blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); + return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); - case Blockly.ASTNode.types.OUTPUT: + case ASTNode.types.OUTPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); target = connection.targetConnection; if (target) { - return Blockly.ASTNode.createConnectionNode(target); + return ASTNode.createConnectionNode(target); } - return Blockly.ASTNode.createStackNode(connection.getSourceBlock()); + return ASTNode.createStackNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.FIELD: + case ASTNode.types.FIELD: field = /** @type {!Blockly.Field} */ (this.location_); - return Blockly.ASTNode.createBlockNode(field.getSourceBlock()); + return ASTNode.createBlockNode(field.getSourceBlock()); - case Blockly.ASTNode.types.INPUT: + case ASTNode.types.INPUT: connection = /** @type {!Blockly.Connection} */ (this.location_); - return Blockly.ASTNode.createBlockNode(connection.getSourceBlock()); + return ASTNode.createBlockNode(connection.getSourceBlock()); - case Blockly.ASTNode.types.BLOCK: + case ASTNode.types.BLOCK: block = /** @type {!Blockly.Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); - case Blockly.ASTNode.types.PREVIOUS: + case ASTNode.types.PREVIOUS: connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); - case Blockly.ASTNode.types.NEXT: + case ASTNode.types.NEXT: connection = /** @type {!Blockly.Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); } return null; }; + +exports = ASTNode; diff --git a/tests/deps.js b/tests/deps.js index c6ccc9bb8..957896ec3 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -102,7 +102,7 @@ goog.addDependency('../../core/interfaces/i_styleable.js', ['Blockly.IStyleable' goog.addDependency('../../core/interfaces/i_toolbox.js', ['Blockly.IToolbox'], ['Blockly.IRegistrable'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/interfaces/i_toolbox_item.js', ['Blockly.IToolboxItem'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstants'], ['Blockly.connectionTypes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es5'}); +goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); From e79faf4147255a29982e12b95d3d6bb3bfc36939 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 21 Jul 2021 17:16:02 -0700 Subject: [PATCH 371/833] Migrate core/keyboard_nav/ast_node.js named requires --- core/keyboard_nav/ast_node.js | 123 +++++++++++++++++----------------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index e0a75d0c0..09a63b3a2 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,16 +13,15 @@ goog.module('Blockly.ASTNode'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.connectionTypes'); -goog.require('Blockly.utils.Coordinate'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.Connection'); -goog.requireType('Blockly.Field'); -goog.requireType('Blockly.IASTNodeLocation'); -goog.requireType('Blockly.IASTNodeLocationWithBlock'); -goog.requireType('Blockly.Input'); -goog.requireType('Blockly.Workspace'); +const Block = goog.requireType('Blockly.Block'); +const Connection = goog.requireType('Blockly.Connection'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Field = goog.requireType('Blockly.Field'); +const IASTNodeLocation = goog.requireType('Blockly.IASTNodeLocation'); +const IASTNodeLocationWithBlock = goog.requireType('Blockly.IASTNodeLocationWithBlock'); +const Input = goog.requireType('Blockly.Input'); +const Workspace = goog.requireType('Blockly.Workspace'); +const connectionTypes = goog.require('Blockly.connectionTypes'); /** @@ -31,7 +30,7 @@ goog.requireType('Blockly.Workspace'); * creating a node directly. * @param {string} type The type of the location. * Must be in ASTNode.types. - * @param {!Blockly.IASTNodeLocation} location The position in the AST. + * @param {!IASTNodeLocation} location The position in the AST. * @param {!ASTNode.Params=} opt_params Optional dictionary of options. * @constructor */ @@ -57,14 +56,14 @@ const ASTNode = function(type, location, opt_params) { /** * The location of the AST node. - * @type {!Blockly.IASTNodeLocation} + * @type {!IASTNodeLocation} * @private */ this.location_ = location; /** * The coordinate on the workspace. - * @type {Blockly.utils.Coordinate} + * @type {Coordinate} * @private */ this.wsCoordinate_ = null; @@ -74,7 +73,7 @@ const ASTNode = function(type, location, opt_params) { /** * @typedef {{ - * wsCoordinate: Blockly.utils.Coordinate + * wsCoordinate: Coordinate * }} */ ASTNode.Params; @@ -127,7 +126,7 @@ ASTNode.isConnectionType_ = function(type) { /** * Create an AST node pointing to a field. - * @param {Blockly.Field} field The location of the AST node. + * @param {Field} field The location of the AST node. * @return {ASTNode} An AST node pointing to a field. */ ASTNode.createFieldNode = function(field) { @@ -140,7 +139,7 @@ ASTNode.createFieldNode = function(field) { /** * Creates an AST node pointing to a connection. If the connection has a parent * input then create an AST node of type input that will hold the connection. - * @param {Blockly.Connection} connection This is the connection the node will + * @param {Connection} connection This is the connection the node will * point to. * @return {ASTNode} An AST node pointing to a connection. */ @@ -149,16 +148,16 @@ ASTNode.createConnectionNode = function(connection) { return null; } const type = connection.type; - if (type == Blockly.connectionTypes.INPUT_VALUE) { + if (type == connectionTypes.INPUT_VALUE) { return ASTNode.createInputNode(connection.getParentInput()); - } else if (type == Blockly.connectionTypes.NEXT_STATEMENT && + } else if (type == connectionTypes.NEXT_STATEMENT && connection.getParentInput()) { return ASTNode.createInputNode(connection.getParentInput()); - } else if (type == Blockly.connectionTypes.NEXT_STATEMENT) { + } else if (type == connectionTypes.NEXT_STATEMENT) { return new ASTNode(ASTNode.types.NEXT, connection); - } else if (type == Blockly.connectionTypes.OUTPUT_VALUE) { + } else if (type == connectionTypes.OUTPUT_VALUE) { return new ASTNode(ASTNode.types.OUTPUT, connection); - } else if (type == Blockly.connectionTypes.PREVIOUS_STATEMENT) { + } else if (type == connectionTypes.PREVIOUS_STATEMENT) { return new ASTNode(ASTNode.types.PREVIOUS, connection); } return null; @@ -167,7 +166,7 @@ ASTNode.createConnectionNode = function(connection) { /** * Creates an AST node pointing to an input. Stores the input connection as the * location. - * @param {Blockly.Input} input The input used to create an AST node. + * @param {Input} input The input used to create an AST node. * @return {ASTNode} An AST node pointing to a input. */ ASTNode.createInputNode = function(input) { @@ -179,7 +178,7 @@ ASTNode.createInputNode = function(input) { /** * Creates an AST node pointing to a block. - * @param {Blockly.Block} block The block used to create an AST node. + * @param {Block} block The block used to create an AST node. * @return {ASTNode} An AST node pointing to a block. */ ASTNode.createBlockNode = function(block) { @@ -192,7 +191,7 @@ ASTNode.createBlockNode = function(block) { /** * Create an AST node of type stack. A stack, represented by its top block, is * the set of all blocks connected to a top block, including the top block. - * @param {Blockly.Block} topBlock A top block has no parent and can be found + * @param {Block} topBlock A top block has no parent and can be found * in the list returned by workspace.getTopBlocks(). * @return {ASTNode} An AST node of type stack that points to the top * block on the stack. @@ -206,8 +205,8 @@ ASTNode.createStackNode = function(topBlock) { /** * Creates an AST node pointing to a workspace. - * @param {!Blockly.Workspace} workspace The workspace that we are on. - * @param {Blockly.utils.Coordinate} wsCoordinate The position on the workspace + * @param {!Workspace} workspace The workspace that we are on. + * @param {Coordinate} wsCoordinate The position on the workspace * for this node. * @return {ASTNode} An AST node pointing to a workspace and a position * on the workspace. @@ -226,7 +225,7 @@ ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { /** * Creates an AST node for the top position on a block. * This is either an output connection, previous connection, or block. - * @param {!Blockly.Block} block The block to find the top most AST node on. + * @param {!Block} block The block to find the top most AST node on. * @return {ASTNode} The AST node holding the top most position on the * block. */ @@ -259,7 +258,7 @@ ASTNode.prototype.processParams_ = function(params) { * Gets the value pointed to by this node. * It is the callers responsibility to check the node type to figure out what * type of object they get back from this. - * @return {!Blockly.IASTNodeLocation} The current field, connection, workspace, or + * @return {!IASTNodeLocation} The current field, connection, workspace, or * block the cursor is on. */ ASTNode.prototype.getLocation = function() { @@ -277,7 +276,7 @@ ASTNode.prototype.getType = function() { /** * The coordinate on the workspace. - * @return {Blockly.utils.Coordinate} The workspace coordinate or null if the + * @return {Coordinate} The workspace coordinate or null if the * location is not a workspace. */ ASTNode.prototype.getWsCoordinate = function() { @@ -303,7 +302,7 @@ ASTNode.prototype.isConnection = function() { * @private */ ASTNode.prototype.findNextForInput_ = function() { - const location = /** @type {!Blockly.Connection} */ (this.location_); + const location = /** @type {!Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); @@ -332,10 +331,10 @@ ASTNode.prototype.findNextForInput_ = function() { * @private */ ASTNode.prototype.findNextForField_ = function() { - const location = /** @type {!Blockly.Field} */ (this.location_); + const location = /** @type {!Field} */ (this.location_); const input = location.getParentInput(); const block = location.getSourceBlock(); - const curIdx = block.inputList.indexOf(/** @type {!Blockly.Input} */ (input)); + const curIdx = block.inputList.indexOf(/** @type {!Input} */ (input)); let fieldIdx = input.fieldRow.indexOf(location) + 1; let i = curIdx, newInput; for (; (newInput = block.inputList[i]); i++) { @@ -363,7 +362,7 @@ ASTNode.prototype.findNextForField_ = function() { * @private */ ASTNode.prototype.findPrevForInput_ = function() { - const location = /** @type {!Blockly.Connection} */ (this.location_); + const location = /** @type {!Connection} */ (this.location_); const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); @@ -390,11 +389,11 @@ ASTNode.prototype.findPrevForInput_ = function() { * @private */ ASTNode.prototype.findPrevForField_ = function() { - const location = /** @type {!Blockly.Field} */ (this.location_); + const location = /** @type {!Field} */ (this.location_); const parentInput = location.getParentInput(); const block = location.getSourceBlock(); const curIdx = block.inputList.indexOf( - /** @type {!Blockly.Input} */ (parentInput)); + /** @type {!Input} */ (parentInput)); let fieldIdx = parentInput.fieldRow.indexOf(location) - 1; let i = curIdx, input; for (; (input = block.inputList[i]); i--) { @@ -426,7 +425,7 @@ ASTNode.prototype.findPrevForField_ = function() { ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); if (curLocation.getSourceBlock) { - curLocation = /** @type {!Blockly.IASTNodeLocationWithBlock} */ ( + curLocation = /** @type {!IASTNodeLocationWithBlock} */ ( curLocation).getSourceBlock(); } if (!curLocation || !curLocation.workspace) { @@ -452,7 +451,7 @@ ASTNode.prototype.navigateBetweenStacks_ = function(forward) { * Finds the top most AST node for a given block. * This is either the previous connection, output connection or block depending * on what kind of connections the block has. - * @param {!Blockly.Block} block The block that we want to find the top + * @param {!Block} block The block that we want to find the top * connection on. * @return {!ASTNode} The AST node containing the top connection. * @private @@ -471,7 +470,7 @@ ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { /** * Get the AST node pointing to the input that the block is nested under or if * the block is not nested then get the stack AST node. - * @param {Blockly.Block} block The source block of the current location. + * @param {Block} block The source block of the current location. * @return {ASTNode} The AST node pointing to the input connection or * the top block of the stack this block is in. * @private @@ -500,7 +499,7 @@ ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { /** * Find the first editable field or input with a connection on a given block. - * @param {!Blockly.Block} block The source block of the current location. + * @param {!Block} block The source block of the current location. * @return {ASTNode} An AST node pointing to the first field or input. * Null if there are no editable fields or inputs with connections on the block. * @private @@ -525,18 +524,18 @@ ASTNode.prototype.findFirstFieldOrInput_ = function(block) { /** * Finds the source block of the location of this node. - * @return {Blockly.Block} The source block of the location, or null if the node + * @return {Block} The source block of the location, or null if the node * is of type workspace. */ ASTNode.prototype.getSourceBlock = function() { if (this.getType() === ASTNode.types.BLOCK) { - return /** @type {Blockly.Block} */ (this.getLocation()); + return /** @type {Block} */ (this.getLocation()); } else if (this.getType() === ASTNode.types.STACK) { - return /** @type {Blockly.Block} */ (this.getLocation()); + return /** @type {Block} */ (this.getLocation()); } else if (this.getType() === ASTNode.types.WORKSPACE) { return null; } else { - return /** @type {Blockly.IASTNodeLocationWithBlock} */ ( + return /** @type {IASTNodeLocationWithBlock} */ ( this.getLocation()).getSourceBlock(); } }; @@ -553,7 +552,7 @@ ASTNode.prototype.next = function() { return this.navigateBetweenStacks_(true); case ASTNode.types.OUTPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); case ASTNode.types.FIELD: @@ -563,16 +562,16 @@ ASTNode.prototype.next = function() { return this.findNextForInput_(); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); nextConnection = block.nextConnection; return ASTNode.createConnectionNode(nextConnection); case ASTNode.types.PREVIOUS: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); case ASTNode.types.NEXT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); } @@ -590,7 +589,7 @@ ASTNode.prototype.in = function() { let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { case ASTNode.types.WORKSPACE: - workspace = /** @type {!Blockly.Workspace} */ (this.location_); + workspace = /** @type {!Workspace} */ (this.location_); topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { return ASTNode.createStackNode(topBlocks[0]); @@ -598,15 +597,15 @@ ASTNode.prototype.in = function() { break; case ASTNode.types.STACK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); return this.findFirstFieldOrInput_(block); case ASTNode.types.INPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); } @@ -636,12 +635,12 @@ ASTNode.prototype.prev = function() { return this.findPrevForInput_(); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); topConnection = block.previousConnection || block.outputConnection; return ASTNode.createConnectionNode(topConnection); case ASTNode.types.PREVIOUS: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { return ASTNode.createConnectionNode(targetConnection); @@ -649,7 +648,7 @@ ASTNode.prototype.prev = function() { break; case ASTNode.types.NEXT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); } @@ -666,15 +665,15 @@ ASTNode.prototype.out = function() { let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { case ASTNode.types.STACK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - wsCoordinate = new Blockly.utils.Coordinate( + wsCoordinate = new Coordinate( blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); case ASTNode.types.OUTPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); target = connection.targetConnection; if (target) { return ASTNode.createConnectionNode(target); @@ -682,23 +681,23 @@ ASTNode.prototype.out = function() { return ASTNode.createStackNode(connection.getSourceBlock()); case ASTNode.types.FIELD: - field = /** @type {!Blockly.Field} */ (this.location_); + field = /** @type {!Field} */ (this.location_); return ASTNode.createBlockNode(field.getSourceBlock()); case ASTNode.types.INPUT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); case ASTNode.types.BLOCK: - block = /** @type {!Blockly.Block} */ (this.location_); + block = /** @type {!Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); case ASTNode.types.PREVIOUS: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); case ASTNode.types.NEXT: - connection = /** @type {!Blockly.Connection} */ (this.location_); + connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); } From c19ce37a4accf24f1f044691bcf68af1d19c1938 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:29:05 -0700 Subject: [PATCH 372/833] clang-format core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 09a63b3a2..0c349bbd0 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -150,8 +150,8 @@ ASTNode.createConnectionNode = function(connection) { const type = connection.type; if (type == connectionTypes.INPUT_VALUE) { return ASTNode.createInputNode(connection.getParentInput()); - } else if (type == connectionTypes.NEXT_STATEMENT && - connection.getParentInput()) { + } else if ( + type == connectionTypes.NEXT_STATEMENT && connection.getParentInput()) { return ASTNode.createInputNode(connection.getParentInput()); } else if (type == connectionTypes.NEXT_STATEMENT) { return new ASTNode(ASTNode.types.NEXT, connection); @@ -215,11 +215,8 @@ ASTNode.createWorkspaceNode = function(workspace, wsCoordinate) { if (!wsCoordinate || !workspace) { return null; } - const params = { - wsCoordinate: wsCoordinate - }; - return new ASTNode( - ASTNode.types.WORKSPACE, workspace, params); + const params = {wsCoordinate: wsCoordinate}; + return new ASTNode(ASTNode.types.WORKSPACE, workspace, params); }; /** @@ -425,8 +422,8 @@ ASTNode.prototype.findPrevForField_ = function() { ASTNode.prototype.navigateBetweenStacks_ = function(forward) { var curLocation = this.getLocation(); if (curLocation.getSourceBlock) { - curLocation = /** @type {!IASTNodeLocationWithBlock} */ ( - curLocation).getSourceBlock(); + curLocation = /** @type {!IASTNodeLocationWithBlock} */ (curLocation) + .getSourceBlock(); } if (!curLocation || !curLocation.workspace) { return null; @@ -459,11 +456,10 @@ ASTNode.prototype.navigateBetweenStacks_ = function(forward) { ASTNode.prototype.findTopASTNodeForBlock_ = function(block) { const topConnection = block.previousConnection || block.outputConnection; if (topConnection) { - return /** @type {!ASTNode} */ (ASTNode.createConnectionNode( - topConnection)); + return /** @type {!ASTNode} */ ( + ASTNode.createConnectionNode(topConnection)); } else { - return /** @type {!ASTNode} */ (ASTNode.createBlockNode( - block)); + return /** @type {!ASTNode} */ (ASTNode.createBlockNode(block)); } }; @@ -535,8 +531,8 @@ ASTNode.prototype.getSourceBlock = function() { } else if (this.getType() === ASTNode.types.WORKSPACE) { return null; } else { - return /** @type {IASTNodeLocationWithBlock} */ ( - this.getLocation()).getSourceBlock(); + return /** @type {IASTNodeLocationWithBlock} */ (this.getLocation()) + .getSourceBlock(); } }; @@ -668,8 +664,8 @@ ASTNode.prototype.out = function() { block = /** @type {!Block} */ (this.location_); blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - wsCoordinate = new Coordinate( - blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); + wsCoordinate = + new Coordinate(blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); case ASTNode.types.OUTPUT: From 02f1055c445fb3db78a1dd30695dc2802f94c523 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:05:24 -0700 Subject: [PATCH 373/833] Add eslint disable lines to core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 0c349bbd0..c1323099f 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -13,13 +13,20 @@ goog.module('Blockly.ASTNode'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); +/* eslint-disable-next-line no-unused-vars */ const Connection = goog.requireType('Blockly.Connection'); const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocation = goog.requireType('Blockly.IASTNodeLocation'); +/* eslint-disable-next-line no-unused-vars */ const IASTNodeLocationWithBlock = goog.requireType('Blockly.IASTNodeLocationWithBlock'); +/* eslint-disable-next-line no-unused-vars */ const Input = goog.requireType('Blockly.Input'); +/* eslint-disable-next-line no-unused-vars */ const Workspace = goog.requireType('Blockly.Workspace'); const connectionTypes = goog.require('Blockly.connectionTypes'); From d9edeca432351250bf2077c4b2ffd8ba3b91eba6 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:19:13 -0700 Subject: [PATCH 374/833] Update for loop syntax in core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index c1323099f..11405bc22 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -310,11 +310,11 @@ ASTNode.prototype.findNextForInput_ = function() { const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); - let i = curIdx + 1, input; - for (; (input = block.inputList[i]); i++) { + for (let i = curIdx + 1; i < block.inputList.length; i++) { + const input = block.inputList[i]; const fieldRow = input.fieldRow; - let j = 0, field; - for (; (field = fieldRow[j]); j++) { + for (let j = 0; j < fieldRow.length; j++) { + const field = fieldRow[j]; if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { return ASTNode.createFieldNode(field); } @@ -340,8 +340,8 @@ ASTNode.prototype.findNextForField_ = function() { const block = location.getSourceBlock(); const curIdx = block.inputList.indexOf(/** @type {!Input} */ (input)); let fieldIdx = input.fieldRow.indexOf(location) + 1; - let i = curIdx, newInput; - for (; (newInput = block.inputList[i]); i++) { + for (let i = curIdx; i < block.inputList.length; i++) { + const newInput = block.inputList[i]; const fieldRow = newInput.fieldRow; while (fieldIdx < fieldRow.length) { if (fieldRow[fieldIdx].isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { @@ -370,14 +370,14 @@ ASTNode.prototype.findPrevForInput_ = function() { const parentInput = location.getParentInput(); const block = parentInput.getSourceBlock(); const curIdx = block.inputList.indexOf(parentInput); - let i = curIdx, input; - for (; (input = block.inputList[i]); i--) { + for (let i = curIdx; i >= 0; i--) { + const input = block.inputList[i]; if (input.connection && input !== parentInput) { return ASTNode.createInputNode(input); } const fieldRow = input.fieldRow; - let j = fieldRow.length - 1, field; - for (; (field = fieldRow[j]); j--) { + for (let j = fieldRow.length - 1; j >= 0; j--) { + const field = fieldRow[j]; if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { return ASTNode.createFieldNode(field); } @@ -399,8 +399,8 @@ ASTNode.prototype.findPrevForField_ = function() { const curIdx = block.inputList.indexOf( /** @type {!Input} */ (parentInput)); let fieldIdx = parentInput.fieldRow.indexOf(location) - 1; - let i = curIdx, input; - for (; (input = block.inputList[i]); i--) { + for (let i = curIdx; i >= 0; i--) { + const input = block.inputList[i]; if (input.connection && input !== parentInput) { return ASTNode.createInputNode(input); } @@ -437,8 +437,8 @@ ASTNode.prototype.navigateBetweenStacks_ = function(forward) { } const curRoot = curLocation.getRootBlock(); const topBlocks = curRoot.workspace.getTopBlocks(true); - let i = 0, topBlock; - for (; (topBlock = topBlocks[i]); i++) { + for (let i = 0; i < topBlocks.length; i++) { + const topBlock = topBlocks[i]; if (curRoot.id == topBlock.id) { const offset = forward ? 1 : -1; const resultIndex = i + offset; @@ -509,11 +509,11 @@ ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { */ ASTNode.prototype.findFirstFieldOrInput_ = function(block) { const inputs = block.inputList; - let i = 0, input; - for (; (input = inputs[i]); i++) { + for (let i = 0; i < inputs.length; i++) { + const input = inputs[i]; const fieldRow = input.fieldRow; - let j = 0, field; - for (; (field = fieldRow[j]); j++) { + for (let j = 0; j < fieldRow.length; j++) { + const field = fieldRow[j]; if (field.isClickable() || ASTNode.NAVIGATE_ALL_FIELDS) { return ASTNode.createFieldNode(field); } From fabba95beb07a268b81e2a5e7f408aa20555e917 Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:26:15 -0700 Subject: [PATCH 375/833] Adding blocks to case statements in core/keyboard_nav/ast_node.js --- core/keyboard_nav/ast_node.js | 126 +++++++++++++++++----------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index 11405bc22..b52ca1b18 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -549,34 +549,34 @@ ASTNode.prototype.getSourceBlock = function() { * block, or workspace. Or null if there is no node to the right. */ ASTNode.prototype.next = function() { - let connection, block, nextConnection, targetConnection; switch (this.type_) { case ASTNode.types.STACK: return this.navigateBetweenStacks_(true); - case ASTNode.types.OUTPUT: - connection = /** @type {!Connection} */ (this.location_); + case ASTNode.types.OUTPUT: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); - + } case ASTNode.types.FIELD: return this.findNextForField_(); case ASTNode.types.INPUT: return this.findNextForInput_(); - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); - nextConnection = block.nextConnection; + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); + const nextConnection = block.nextConnection; return ASTNode.createConnectionNode(nextConnection); - - case ASTNode.types.PREVIOUS: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.PREVIOUS: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); - - case ASTNode.types.NEXT: - connection = /** @type {!Connection} */ (this.location_); - targetConnection = connection.targetConnection; + } + case ASTNode.types.NEXT: { + const connection = /** @type {!Connection} */ (this.location_); + const targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); + } } return null; @@ -589,28 +589,28 @@ ASTNode.prototype.next = function() { * workspace, or block. Or null if there is nothing below this node. */ ASTNode.prototype.in = function() { - let workspace, topBlocks, block, connection, targetConnection; switch (this.type_) { - case ASTNode.types.WORKSPACE: - workspace = /** @type {!Workspace} */ (this.location_); - topBlocks = workspace.getTopBlocks(true); + case ASTNode.types.WORKSPACE: { + const workspace = /** @type {!Workspace} */ (this.location_); + const topBlocks = workspace.getTopBlocks(true); if (topBlocks.length > 0) { return ASTNode.createStackNode(topBlocks[0]); } break; - - case ASTNode.types.STACK: - block = /** @type {!Block} */ (this.location_); + } + case ASTNode.types.STACK: { + const block = /** @type {!Block} */ (this.location_); return this.findTopASTNodeForBlock_(block); - - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); + } + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); return this.findFirstFieldOrInput_(block); - - case ASTNode.types.INPUT: - connection = /** @type {!Connection} */ (this.location_); - targetConnection = connection.targetConnection; + } + case ASTNode.types.INPUT: { + const connection = /** @type {!Connection} */ (this.location_); + const targetConnection = connection.targetConnection; return ASTNode.createConnectionNode(targetConnection); + } } return null; @@ -623,7 +623,6 @@ ASTNode.prototype.in = function() { * null. */ ASTNode.prototype.prev = function() { - let block, topConnection, connection, targetConnection; switch (this.type_) { case ASTNode.types.STACK: return this.navigateBetweenStacks_(false); @@ -637,22 +636,23 @@ ASTNode.prototype.prev = function() { case ASTNode.types.INPUT: return this.findPrevForInput_(); - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); - topConnection = block.previousConnection || block.outputConnection; + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); + const topConnection = block.previousConnection || block.outputConnection; return ASTNode.createConnectionNode(topConnection); - - case ASTNode.types.PREVIOUS: - connection = /** @type {!Connection} */ (this.location_); - targetConnection = connection.targetConnection; + } + case ASTNode.types.PREVIOUS: { + const connection = /** @type {!Connection} */ (this.location_); + const targetConnection = connection.targetConnection; if (targetConnection && !targetConnection.getParentInput()) { return ASTNode.createConnectionNode(targetConnection); } break; - - case ASTNode.types.NEXT: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.NEXT: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); + } } return null; @@ -665,43 +665,43 @@ ASTNode.prototype.prev = function() { * workspace or block. Or null if we are at the workspace level. */ ASTNode.prototype.out = function() { - let block, blockPos, wsCoordinate, connection, target, field; switch (this.type_) { - case ASTNode.types.STACK: - block = /** @type {!Block} */ (this.location_); - blockPos = block.getRelativeToSurfaceXY(); + case ASTNode.types.STACK: { + const block = /** @type {!Block} */ (this.location_); + const blockPos = block.getRelativeToSurfaceXY(); // TODO: Make sure this is in the bounds of the workspace. - wsCoordinate = + const wsCoordinate = new Coordinate(blockPos.x, blockPos.y + ASTNode.DEFAULT_OFFSET_Y); return ASTNode.createWorkspaceNode(block.workspace, wsCoordinate); - - case ASTNode.types.OUTPUT: - connection = /** @type {!Connection} */ (this.location_); - target = connection.targetConnection; + } + case ASTNode.types.OUTPUT: { + const connection = /** @type {!Connection} */ (this.location_); + const target = connection.targetConnection; if (target) { return ASTNode.createConnectionNode(target); } return ASTNode.createStackNode(connection.getSourceBlock()); - - case ASTNode.types.FIELD: - field = /** @type {!Field} */ (this.location_); + } + case ASTNode.types.FIELD: { + const field = /** @type {!Field} */ (this.location_); return ASTNode.createBlockNode(field.getSourceBlock()); - - case ASTNode.types.INPUT: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.INPUT: { + const connection = /** @type {!Connection} */ (this.location_); return ASTNode.createBlockNode(connection.getSourceBlock()); - - case ASTNode.types.BLOCK: - block = /** @type {!Block} */ (this.location_); + } + case ASTNode.types.BLOCK: { + const block = /** @type {!Block} */ (this.location_); return this.getOutAstNodeForBlock_(block); - - case ASTNode.types.PREVIOUS: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.PREVIOUS: { + const connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); - - case ASTNode.types.NEXT: - connection = /** @type {!Connection} */ (this.location_); + } + case ASTNode.types.NEXT: { + const connection = /** @type {!Connection} */ (this.location_); return this.getOutAstNodeForBlock_(connection.getSourceBlock()); + } } return null; From 6787624e3ef9cb748b3d8e1f534b3ece46d483e1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:46:10 -0700 Subject: [PATCH 376/833] Migrate core/workspace_audio.js to ES6 const/let --- core/workspace_audio.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 378c19287..1ca2a2255 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -71,17 +71,18 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { if (!filenames.length) { return; } + let audioTest; try { - var audioTest = new Blockly.utils.global['Audio'](); + audioTest = new Blockly.utils.global['Audio'](); } catch (e) { // No browser support for Audio. // IE can throw an error even if the Audio object exists. return; } - var sound; - for (var i = 0; i < filenames.length; i++) { - var filename = filenames[i]; - var ext = filename.match(/\.(\w+)$/); + let sound; + for (let i = 0; i < filenames.length; i++) { + const filename = filenames[i]; + const ext = filename.match(/\.(\w+)$/); if (ext && audioTest.canPlayType('audio/' + ext[1])) { // Found an audio format we can play. sound = new Blockly.utils.global['Audio'](filename); @@ -98,10 +99,10 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { * @package */ Blockly.WorkspaceAudio.prototype.preload = function() { - for (var name in this.SOUNDS_) { - var sound = this.SOUNDS_[name]; + for (let name in this.SOUNDS_) { + const sound = this.SOUNDS_[name]; sound.volume = 0.01; - var playPromise = sound.play(); + const playPromise = sound.play(); // Edge does not return a promise, so we need to check. if (playPromise !== undefined) { // If we don't wait for the play request to complete before calling pause() @@ -129,16 +130,16 @@ Blockly.WorkspaceAudio.prototype.preload = function() { * @param {number=} opt_volume Volume of sound (0-1). */ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { - var sound = this.SOUNDS_[name]; + const sound = this.SOUNDS_[name]; if (sound) { // Don't play one sound on top of another. - var now = new Date; + const now = new Date; if (this.lastSound_ != null && now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; - var mySound; + let mySound; if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.ANDROID) { // Creating a new audio node causes lag in Android and iPad. Android // refetches the file from the server, iPad uses a singleton audio From f7c88bfcd91bb2168137358e91ce01ae17036bee Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:46:27 -0700 Subject: [PATCH 377/833] Migrate core/workspace_audio.js to goog.module --- core/workspace_audio.js | 18 ++++++++++-------- tests/deps.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 1ca2a2255..72e66d952 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -11,10 +11,10 @@ */ 'use strict'; -goog.provide('Blockly.WorkspaceAudio'); +goog.module('Blockly.WorkspaceAudio'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils'); goog.require('Blockly.utils.global'); goog.require('Blockly.utils.userAgent'); @@ -27,7 +27,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * this audio object belongs to, or null. * @constructor */ -Blockly.WorkspaceAudio = function(parentWorkspace) { +const WorkspaceAudio = function(parentWorkspace) { /** * The parent of the workspace this object belongs to, or null. May be @@ -49,13 +49,13 @@ Blockly.WorkspaceAudio = function(parentWorkspace) { * @type {Date} * @private */ -Blockly.WorkspaceAudio.prototype.lastSound_ = null; +WorkspaceAudio.prototype.lastSound_ = null; /** * Dispose of this audio manager. * @package */ -Blockly.WorkspaceAudio.prototype.dispose = function() { +WorkspaceAudio.prototype.dispose = function() { this.parentWorkspace_ = null; this.SOUNDS_ = null; }; @@ -67,7 +67,7 @@ Blockly.WorkspaceAudio.prototype.dispose = function() { * Filenames include path from Blockly's root. File extensions matter. * @param {string} name Name of sound. */ -Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { +WorkspaceAudio.prototype.load = function(filenames, name) { if (!filenames.length) { return; } @@ -98,7 +98,7 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) { * Preload all the audio files so that they play quickly when asked for. * @package */ -Blockly.WorkspaceAudio.prototype.preload = function() { +WorkspaceAudio.prototype.preload = function() { for (let name in this.SOUNDS_) { const sound = this.SOUNDS_[name]; sound.volume = 0.01; @@ -129,7 +129,7 @@ Blockly.WorkspaceAudio.prototype.preload = function() { * @param {string} name Name of sound. * @param {number=} opt_volume Volume of sound (0-1). */ -Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { +WorkspaceAudio.prototype.play = function(name, opt_volume) { const sound = this.SOUNDS_[name]; if (sound) { // Don't play one sound on top of another. @@ -155,3 +155,5 @@ Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) { this.parentWorkspace_.getAudioManager().play(name, opt_volume); } }; + +exports = WorkspaceAudio; diff --git a/tests/deps.js b/tests/deps.js index 957896ec3..0018d3a1d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -202,7 +202,7 @@ goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); -goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es5'}); +goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); From 5f819cd0fe949c619b1d333492ad074e3e51e38d Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:48:10 -0700 Subject: [PATCH 378/833] Migrate core/workspace_audio.js named requires --- core/workspace_audio.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 72e66d952..7a6acde4f 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -14,16 +14,16 @@ goog.module('Blockly.WorkspaceAudio'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.internalConstants'); -goog.require('Blockly.utils.global'); -goog.require('Blockly.utils.userAgent'); - -goog.requireType('Blockly.WorkspaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const global = goog.require('Blockly.utils.global'); +const internalConstants = goog.require('Blockly.internalConstants'); +const userAgent = goog.require('Blockly.utils.userAgent'); /** * Class for loading, storing, and playing audio for a workspace. - * @param {Blockly.WorkspaceSvg} parentWorkspace The parent of the workspace + * @param {WorkspaceSvg} parentWorkspace The parent of the workspace * this audio object belongs to, or null. * @constructor */ @@ -32,7 +32,7 @@ const WorkspaceAudio = function(parentWorkspace) { /** * The parent of the workspace this object belongs to, or null. May be * checked for sounds that this object can't find. - * @type {Blockly.WorkspaceSvg} + * @type {WorkspaceSvg} * @private */ this.parentWorkspace_ = parentWorkspace; @@ -73,7 +73,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) { } let audioTest; try { - audioTest = new Blockly.utils.global['Audio'](); + audioTest = new global['Audio'](); } catch (e) { // No browser support for Audio. // IE can throw an error even if the Audio object exists. @@ -85,7 +85,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) { const ext = filename.match(/\.(\w+)$/); if (ext && audioTest.canPlayType('audio/' + ext[1])) { // Found an audio format we can play. - sound = new Blockly.utils.global['Audio'](filename); + sound = new global['Audio'](filename); break; } } @@ -117,7 +117,7 @@ WorkspaceAudio.prototype.preload = function() { // iOS can only process one sound at a time. Trying to load more than one // corrupts the earlier ones. Just load one and leave the others uncached. - if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.IPHONE) { + if (userAgent.IPAD || userAgent.IPHONE) { break; } } @@ -135,12 +135,12 @@ WorkspaceAudio.prototype.play = function(name, opt_volume) { // Don't play one sound on top of another. const now = new Date; if (this.lastSound_ != null && - now - this.lastSound_ < Blockly.internalConstants.SOUND_LIMIT) { + now - this.lastSound_ < internalConstants.SOUND_LIMIT) { return; } this.lastSound_ = now; let mySound; - if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.ANDROID) { + if (userAgent.IPAD || userAgent.ANDROID) { // Creating a new audio node causes lag in Android and iPad. Android // refetches the file from the server, iPad uses a singleton audio // node which must be deleted and recreated for each new audio tag. From 813f27706f4ce84db3d54ac8d1e41341e35559a2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:50:13 -0700 Subject: [PATCH 379/833] clang-format core/workspace_audio.js --- core/workspace_audio.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 7a6acde4f..11f16b8b1 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -28,7 +28,6 @@ const userAgent = goog.require('Blockly.utils.userAgent'); * @constructor */ const WorkspaceAudio = function(parentWorkspace) { - /** * The parent of the workspace this object belongs to, or null. May be * checked for sounds that this object can't find. @@ -105,9 +104,10 @@ WorkspaceAudio.prototype.preload = function() { const playPromise = sound.play(); // Edge does not return a promise, so we need to check. if (playPromise !== undefined) { - // If we don't wait for the play request to complete before calling pause() - // we will get an exception: (DOMException: The play() request was interrupted) - // See more: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted + // If we don't wait for the play request to complete before calling + // pause() we will get an exception: (DOMException: The play() request was + // interrupted) See more: + // https://developers.google.com/web/updates/2017/06/play-request-was-interrupted playPromise.then(sound.pause).catch(function() { // Play without user interaction was prevented. }); From 4e147b2593befd887a06c5dae91583019c4cbc00 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 15:32:42 -0700 Subject: [PATCH 380/833] Update syntax for for..in loop --- core/workspace_audio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 11f16b8b1..ba1da0c95 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -98,7 +98,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) { * @package */ WorkspaceAudio.prototype.preload = function() { - for (let name in this.SOUNDS_) { + for (const name in this.SOUNDS_) { const sound = this.SOUNDS_[name]; sound.volume = 0.01; const playPromise = sound.play(); From 887e9d79cd6dc2f7c682340e629fa163750e2e71 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Tue, 27 Jul 2021 16:01:18 -0700 Subject: [PATCH 381/833] Migrate core/bubble.js to ES6 const/let --- core/bubble.js | 170 ++++++++++++++++++++++++------------------------- 1 file changed, 84 insertions(+), 86 deletions(-) diff --git a/core/bubble.js b/core/bubble.js index 161b2fb29..f1b5b6318 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -87,18 +87,18 @@ Blockly.Bubble = function( */ this.disposed = false; - var angle = Blockly.Bubble.ARROW_ANGLE; + let angle = Blockly.Bubble.ARROW_ANGLE; if (this.workspace_.RTL) { angle = -angle; } this.arrow_radians_ = Blockly.utils.math.toRadians(angle); - var canvas = workspace.getBubbleCanvas(); + const canvas = workspace.getBubbleCanvas(); canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight))); this.setAnchorLocation(anchorXY); if (!bubbleWidth || !bubbleHeight) { - var bBox = /** @type {SVGLocatable} */ (this.content_).getBBox(); + const bBox = /** @type {SVGLocatable} */ (this.content_).getBBox(); bubbleWidth = bBox.width + 2 * Blockly.Bubble.BORDER_WIDTH; bubbleHeight = bBox.height + 2 * Blockly.Bubble.BORDER_WIDTH; } @@ -245,7 +245,7 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { */ this.bubbleGroup_ = Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.G, {}, null); - var filter = { + let filter = { 'filter': 'url(#' + this.workspace_.getRenderer().getConstants().embossFilterId + ')' }; @@ -254,7 +254,7 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { // https://github.com/google/blockly/issues/99 filter = {}; } - var bubbleEmboss = Blockly.utils.dom.createSvgElement( + const bubbleEmboss = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, filter, this.bubbleGroup_); this.bubbleArrow_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.PATH, {}, bubbleEmboss); @@ -272,7 +272,7 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { Blockly.utils.Svg.G, {'class': this.workspace_.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE'}, this.bubbleGroup_); - var resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; + const resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.POLYGON, {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, @@ -335,7 +335,7 @@ Blockly.Bubble.prototype.setSvgId = function(id) { * @private */ Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) { - var gesture = this.workspace_.getGesture(e); + const gesture = this.workspace_.getGesture(e); if (gesture) { gesture.handleBubbleStart(e, this); } @@ -404,7 +404,7 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) { */ Blockly.Bubble.prototype.resizeMouseMove_ = function(e) { this.autoLayout_ = false; - var newXY = this.workspace_.moveDrag(e); + const newXY = this.workspace_.moveDrag(e); this.setBubbleSize(this.workspace_.RTL ? -newXY.x : newXY.x, newXY.y); if (this.workspace_.RTL) { // RTL requires the bubble to move its left edge. @@ -434,7 +434,7 @@ Blockly.Bubble.prototype.registerMoveEvent = function(callback) { * @package */ Blockly.Bubble.prototype.promote = function() { - var svgGroup = this.bubbleGroup_.parentNode; + const svgGroup = this.bubbleGroup_.parentNode; if (svgGroup.lastChild !== this.bubbleGroup_) { svgGroup.appendChild(this.bubbleGroup_); return true; @@ -460,32 +460,32 @@ Blockly.Bubble.prototype.setAnchorLocation = function(xy) { */ Blockly.Bubble.prototype.layoutBubble_ = function() { // Get the metrics in workspace units. - var viewMetrics = this.workspace_.getMetricsManager().getViewMetrics(true); + const viewMetrics = this.workspace_.getMetricsManager().getViewMetrics(true); - var optimalLeft = this.getOptimalRelativeLeft_(viewMetrics); - var optimalTop = this.getOptimalRelativeTop_(viewMetrics); - var bbox = this.shape_.getBBox(); + const optimalLeft = this.getOptimalRelativeLeft_(viewMetrics); + const optimalTop = this.getOptimalRelativeTop_(viewMetrics); + const bbox = this.shape_.getBBox(); - var topPosition = { + const topPosition = { x: optimalLeft, y: -this.height_ - this.workspace_.getRenderer().getConstants().MIN_BLOCK_HEIGHT }; - var startPosition = {x: -this.width_ - 30, y: optimalTop}; - var endPosition = {x: bbox.width, y: optimalTop}; - var bottomPosition = {x: optimalLeft, y: bbox.height}; + const startPosition = {x: -this.width_ - 30, y: optimalTop}; + const endPosition = {x: bbox.width, y: optimalTop}; + const bottomPosition = {x: optimalLeft, y: bbox.height}; - var closerPosition = bbox.width < bbox.height ? endPosition : bottomPosition; - var fartherPosition = bbox.width < bbox.height ? bottomPosition : endPosition; + const closerPosition = bbox.width < bbox.height ? endPosition : bottomPosition; + const fartherPosition = bbox.width < bbox.height ? bottomPosition : endPosition; - var topPositionOverlap = this.getOverlap_(topPosition, viewMetrics); - var startPositionOverlap = this.getOverlap_(startPosition, viewMetrics); - var closerPositionOverlap = this.getOverlap_(closerPosition, viewMetrics); - var fartherPositionOverlap = this.getOverlap_(fartherPosition, viewMetrics); + const topPositionOverlap = this.getOverlap_(topPosition, viewMetrics); + const startPositionOverlap = this.getOverlap_(startPosition, viewMetrics); + const closerPositionOverlap = this.getOverlap_(closerPosition, viewMetrics); + const fartherPositionOverlap = this.getOverlap_(fartherPosition, viewMetrics); // Set the position to whichever position shows the most of the bubble, // with tiebreaks going in the order: top > start > close > far. - var mostOverlap = Math.max( + const mostOverlap = Math.max( topPositionOverlap, startPositionOverlap, closerPositionOverlap, fartherPositionOverlap); if (topPositionOverlap == mostOverlap) { @@ -522,13 +522,13 @@ Blockly.Bubble.prototype.layoutBubble_ = function() { */ Blockly.Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { // The position of the top-left corner of the bubble in workspace units. - var bubbleMin = { + const bubbleMin = { x: this.workspace_.RTL ? (this.anchorXY_.x - relativeMin.x - this.width_) : (relativeMin.x + this.anchorXY_.x), y: relativeMin.y + this.anchorXY_.y }; // The position of the bottom-right corner of the bubble in workspace units. - var bubbleMax = {x: bubbleMin.x + this.width_, y: bubbleMin.y + this.height_}; + const bubbleMax = {x: bubbleMin.x + this.width_, y: bubbleMin.y + this.height_}; // We could adjust these values to account for the scrollbars, but the // bubbles should have been adjusted to not collide with them anyway, so @@ -536,16 +536,16 @@ Blockly.Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { // calculation. // The position of the top-left corner of the workspace. - var workspaceMin = {x: viewMetrics.left, y: viewMetrics.top}; + const workspaceMin = {x: viewMetrics.left, y: viewMetrics.top}; // The position of the bottom-right corner of the workspace. - var workspaceMax = { + const workspaceMax = { x: viewMetrics.left + viewMetrics.width, y: viewMetrics.top + viewMetrics.height }; - var overlapWidth = Math.min(bubbleMax.x, workspaceMax.x) - + const overlapWidth = Math.min(bubbleMax.x, workspaceMax.x) - Math.max(bubbleMin.x, workspaceMin.x); - var overlapHeight = Math.min(bubbleMax.y, workspaceMax.y) - + const overlapHeight = Math.min(bubbleMax.y, workspaceMax.y) - Math.max(bubbleMin.y, workspaceMin.y); return Math.max( 0, @@ -564,7 +564,7 @@ Blockly.Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { * @private */ Blockly.Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { - var relativeLeft = -this.width_ / 4; + let relativeLeft = -this.width_ / 4; // No amount of sliding left or right will give us a better overlap. if (this.width_ > viewMetrics.width) { @@ -573,24 +573,14 @@ Blockly.Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { if (this.workspace_.RTL) { // Bubble coordinates are flipped in RTL. - var bubbleRight = this.anchorXY_.x - relativeLeft; - var bubbleLeft = bubbleRight - this.width_; + const bubbleRight = this.anchorXY_.x - relativeLeft; + const bubbleLeft = bubbleRight - this.width_; - var workspaceRight = viewMetrics.left + viewMetrics.width; - var workspaceLeft = viewMetrics.left + + const workspaceRight = viewMetrics.left + viewMetrics.width; + const workspaceLeft = viewMetrics.left + // Thickness in workspace units. (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); - } else { - var bubbleLeft = relativeLeft + this.anchorXY_.x; - var bubbleRight = bubbleLeft + this.width_; - var workspaceLeft = viewMetrics.left; - var workspaceRight = viewMetrics.left + viewMetrics.width - - // Thickness in workspace units. - (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); - } - - if (this.workspace_.RTL) { if (bubbleLeft < workspaceLeft) { // Slide the bubble right until it is onscreen. relativeLeft = -(workspaceLeft - this.anchorXY_.x + this.width_); @@ -599,6 +589,14 @@ Blockly.Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { relativeLeft = -(workspaceRight - this.anchorXY_.x); } } else { + const bubbleLeft = relativeLeft + this.anchorXY_.x; + const bubbleRight = bubbleLeft + this.width_; + + const workspaceLeft = viewMetrics.left; + const workspaceRight = viewMetrics.left + viewMetrics.width - + // Thickness in workspace units. + (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); + if (bubbleLeft < workspaceLeft) { // Slide the bubble right until it is onscreen. relativeLeft = workspaceLeft - this.anchorXY_.x; @@ -622,21 +620,21 @@ Blockly.Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { * @private */ Blockly.Bubble.prototype.getOptimalRelativeTop_ = function(viewMetrics) { - var relativeTop = -this.height_ / 4; + let relativeTop = -this.height_ / 4; // No amount of sliding up or down will give us a better overlap. if (this.height_ > viewMetrics.height) { return relativeTop; } - var bubbleTop = this.anchorXY_.y + relativeTop; - var bubbleBottom = bubbleTop + this.height_; - var workspaceTop = viewMetrics.top; - var workspaceBottom = viewMetrics.top + viewMetrics.height - + const bubbleTop = this.anchorXY_.y + relativeTop; + const bubbleBottom = bubbleTop + this.height_; + const workspaceTop = viewMetrics.top; + const workspaceBottom = viewMetrics.top + viewMetrics.height - // Thickness in workspace units. (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); - var anchorY = this.anchorXY_.y; + const anchorY = this.anchorXY_.y; if (bubbleTop < workspaceTop) { // Slide the bubble down until it is onscreen. relativeTop = workspaceTop - anchorY; @@ -653,13 +651,13 @@ Blockly.Bubble.prototype.getOptimalRelativeTop_ = function(viewMetrics) { * @private */ Blockly.Bubble.prototype.positionBubble_ = function() { - var left = this.anchorXY_.x; + let left = this.anchorXY_.x; if (this.workspace_.RTL) { left -= this.relativeLeft_ + this.width_; } else { left += this.relativeLeft_; } - var top = this.relativeTop_ + this.anchorXY_.y; + const top = this.relativeTop_ + this.anchorXY_.y; this.moveTo(left, top); }; @@ -698,7 +696,7 @@ Blockly.Bubble.prototype.getBubbleSize = function() { * @param {number} height Height of the bubble. */ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; // Minimum size of a bubble. width = Math.max(width, doubleBorderWidth + 45); height = Math.max(height, doubleBorderWidth + 20); @@ -709,7 +707,7 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { if (this.resizeGroup_) { if (this.workspace_.RTL) { // Mirror the resize group. - var resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; + const resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; this.resizeGroup_.setAttribute( 'transform', 'translate(' + resizeSize + ',' + (height - doubleBorderWidth) + @@ -738,62 +736,62 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { * @private */ Blockly.Bubble.prototype.renderArrow_ = function() { - var steps = []; + const steps = []; // Find the relative coordinates of the center of the bubble. - var relBubbleX = this.width_ / 2; - var relBubbleY = this.height_ / 2; + const relBubbleX = this.width_ / 2; + const relBubbleY = this.height_ / 2; // Find the relative coordinates of the center of the anchor. - var relAnchorX = -this.relativeLeft_; - var relAnchorY = -this.relativeTop_; + let relAnchorX = -this.relativeLeft_; + let relAnchorY = -this.relativeTop_; if (relBubbleX == relAnchorX && relBubbleY == relAnchorY) { // Null case. Bubble is directly on top of the anchor. // Short circuit this rather than wade through divide by zeros. steps.push('M ' + relBubbleX + ',' + relBubbleY); } else { // Compute the angle of the arrow's line. - var rise = relAnchorY - relBubbleY; - var run = relAnchorX - relBubbleX; + const rise = relAnchorY - relBubbleY; + let run = relAnchorX - relBubbleX; if (this.workspace_.RTL) { run *= -1; } - var hypotenuse = Math.sqrt(rise * rise + run * run); - var angle = Math.acos(run / hypotenuse); + const hypotenuse = Math.sqrt(rise * rise + run * run); + let angle = Math.acos(run / hypotenuse); if (rise < 0) { angle = 2 * Math.PI - angle; } // Compute a line perpendicular to the arrow. - var rightAngle = angle + Math.PI / 2; + let rightAngle = angle + Math.PI / 2; if (rightAngle > Math.PI * 2) { rightAngle -= Math.PI * 2; } - var rightRise = Math.sin(rightAngle); - var rightRun = Math.cos(rightAngle); + const rightRise = Math.sin(rightAngle); + const rightRun = Math.cos(rightAngle); // Calculate the thickness of the base of the arrow. - var bubbleSize = this.getBubbleSize(); - var thickness = + const bubbleSize = this.getBubbleSize(); + let thickness = (bubbleSize.width + bubbleSize.height) / Blockly.Bubble.ARROW_THICKNESS; thickness = Math.min(thickness, bubbleSize.width, bubbleSize.height) / 4; // Back the tip of the arrow off of the anchor. - var backoffRatio = 1 - Blockly.Bubble.ANCHOR_RADIUS / hypotenuse; + const backoffRatio = 1 - Blockly.Bubble.ANCHOR_RADIUS / hypotenuse; relAnchorX = relBubbleX + backoffRatio * run; relAnchorY = relBubbleY + backoffRatio * rise; // Coordinates for the base of the arrow. - var baseX1 = relBubbleX + thickness * rightRun; - var baseY1 = relBubbleY + thickness * rightRise; - var baseX2 = relBubbleX - thickness * rightRun; - var baseY2 = relBubbleY - thickness * rightRise; + const baseX1 = relBubbleX + thickness * rightRun; + const baseY1 = relBubbleY + thickness * rightRise; + const baseX2 = relBubbleX - thickness * rightRun; + const baseY2 = relBubbleY - thickness * rightRise; // Distortion to curve the arrow. - var swirlAngle = angle + this.arrow_radians_; + let swirlAngle = angle + this.arrow_radians_; if (swirlAngle > Math.PI * 2) { swirlAngle -= Math.PI * 2; } - var swirlRise = + const swirlRise = Math.sin(swirlAngle) * hypotenuse / Blockly.Bubble.ARROW_BEND; - var swirlRun = + const swirlRun = Math.cos(swirlAngle) * hypotenuse / Blockly.Bubble.ARROW_BEND; steps.push('M' + baseX1 + ',' + baseY1); @@ -888,18 +886,18 @@ Blockly.Bubble.prototype.setAutoLayout = function(enable) { * @package */ Blockly.Bubble.textToDom = function(text) { - var paragraph = Blockly.utils.dom.createSvgElement( + const paragraph = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText blocklyBubbleText blocklyNoPointerEvents', 'y': Blockly.Bubble.BORDER_WIDTH }, null); - var lines = text.split('\n'); - for (var i = 0; i < lines.length; i++) { - var tspanElement = Blockly.utils.dom.createSvgElement( + const lines = text.split('\n'); + for (let i = 0; i < lines.length; i++) { + const tspanElement = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TSPAN, {'dy': '1em', 'x': Blockly.Bubble.BORDER_WIDTH}, paragraph); - var textNode = document.createTextNode(lines[i]); + const textNode = document.createTextNode(lines[i]); tspanElement.appendChild(textNode); } return paragraph; @@ -916,7 +914,7 @@ Blockly.Bubble.textToDom = function(text) { */ Blockly.Bubble.createNonEditableBubble = function( paragraphElement, block, iconXY) { - var bubble = new Blockly.Bubble( + const bubble = new Blockly.Bubble( /** @type {!Blockly.WorkspaceSvg} */ (block.workspace), paragraphElement, block.pathObject.svgPath, /** @type {!Blockly.utils.Coordinate} */ (iconXY), null, null); @@ -925,9 +923,9 @@ Blockly.Bubble.createNonEditableBubble = function( if (block.RTL) { // Right-align the paragraph. // This cannot be done until the bubble is rendered on screen. - var maxWidth = paragraphElement.getBBox().width; - for (var i = 0, textElement; (textElement = paragraphElement.childNodes[i]); - i++) { + const maxWidth = paragraphElement.getBBox().width; + for (let i = 0, textElement; (textElement = paragraphElement.childNodes[i]); + i++) { textElement.setAttribute('text-anchor', 'end'); textElement.setAttribute('x', maxWidth + Blockly.Bubble.BORDER_WIDTH); } From 79bcdb015266d43a1eec1e12f18b77e879f1b41c Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Tue, 27 Jul 2021 16:04:14 -0700 Subject: [PATCH 382/833] Migrate core/bubble.js to goog.module --- core/bubble.js | 157 +++++++++++++++++++++++++------------------------ tests/deps.js | 2 +- 2 files changed, 81 insertions(+), 78 deletions(-) diff --git a/core/bubble.js b/core/bubble.js index f1b5b6318..aeae81769 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Bubble'); +goog.module('Blockly.Bubble'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.IBubble'); @@ -45,7 +46,7 @@ goog.requireType('Blockly.WorkspaceSvg'); * @implements {Blockly.IBubble} * @constructor */ -Blockly.Bubble = function( +const Bubble = function( workspace, content, shape, anchorXY, bubbleWidth, bubbleHeight) { this.workspace_ = workspace; this.content_ = content; @@ -87,7 +88,7 @@ Blockly.Bubble = function( */ this.disposed = false; - let angle = Blockly.Bubble.ARROW_ANGLE; + let angle = Bubble.ARROW_ANGLE; if (this.workspace_.RTL) { angle = -angle; } @@ -99,8 +100,8 @@ Blockly.Bubble = function( this.setAnchorLocation(anchorXY); if (!bubbleWidth || !bubbleHeight) { const bBox = /** @type {SVGLocatable} */ (this.content_).getBBox(); - bubbleWidth = bBox.width + 2 * Blockly.Bubble.BORDER_WIDTH; - bubbleHeight = bBox.height + 2 * Blockly.Bubble.BORDER_WIDTH; + bubbleWidth = bBox.width + 2 * Bubble.BORDER_WIDTH; + bubbleHeight = bBox.height + 2 * Bubble.BORDER_WIDTH; } this.setBubbleSize(bubbleWidth, bubbleHeight); @@ -113,55 +114,55 @@ Blockly.Bubble = function( /** * Width of the border around the bubble. */ -Blockly.Bubble.BORDER_WIDTH = 6; +Bubble.BORDER_WIDTH = 6; /** * Determines the thickness of the base of the arrow in relation to the size * of the bubble. Higher numbers result in thinner arrows. */ -Blockly.Bubble.ARROW_THICKNESS = 5; +Bubble.ARROW_THICKNESS = 5; /** * The number of degrees that the arrow bends counter-clockwise. */ -Blockly.Bubble.ARROW_ANGLE = 20; +Bubble.ARROW_ANGLE = 20; /** * The sharpness of the arrow's bend. Higher numbers result in smoother arrows. */ -Blockly.Bubble.ARROW_BEND = 4; +Bubble.ARROW_BEND = 4; /** * Distance between arrow point and anchor point. */ -Blockly.Bubble.ANCHOR_RADIUS = 8; +Bubble.ANCHOR_RADIUS = 8; /** * Mouse up event data. * @type {?Blockly.browserEvents.Data} * @private */ -Blockly.Bubble.onMouseUpWrapper_ = null; +Bubble.onMouseUpWrapper_ = null; /** * Mouse move event data. * @type {?Blockly.browserEvents.Data} * @private */ -Blockly.Bubble.onMouseMoveWrapper_ = null; +Bubble.onMouseMoveWrapper_ = null; /** * Stop binding to the global mouseup and mousemove events. * @private */ -Blockly.Bubble.unbindDragEvents_ = function() { - if (Blockly.Bubble.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(Blockly.Bubble.onMouseUpWrapper_); - Blockly.Bubble.onMouseUpWrapper_ = null; +Bubble.unbindDragEvents_ = function() { + if (Bubble.onMouseUpWrapper_) { + Blockly.browserEvents.unbind(Bubble.onMouseUpWrapper_); + Bubble.onMouseUpWrapper_ = null; } - if (Blockly.Bubble.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(Blockly.Bubble.onMouseMoveWrapper_); - Blockly.Bubble.onMouseMoveWrapper_ = null; + if (Bubble.onMouseMoveWrapper_) { + Blockly.browserEvents.unbind(Bubble.onMouseMoveWrapper_); + Bubble.onMouseMoveWrapper_ = null; } }; @@ -170,23 +171,23 @@ Blockly.Bubble.unbindDragEvents_ = function() { * @param {!Event} _e Mouse up event. * @private */ -Blockly.Bubble.bubbleMouseUp_ = function(_e) { +Bubble.bubbleMouseUp_ = function(_e) { Blockly.Touch.clearTouchIdentifier(); - Blockly.Bubble.unbindDragEvents_(); + Bubble.unbindDragEvents_(); }; /** * Flag to stop incremental rendering during construction. * @private */ -Blockly.Bubble.prototype.rendered_ = false; +Bubble.prototype.rendered_ = false; /** * Absolute coordinate of anchor point, in workspace coordinates. * @type {Blockly.utils.Coordinate} * @private */ -Blockly.Bubble.prototype.anchorXY_ = null; +Bubble.prototype.anchorXY_ = null; /** * Relative X coordinate of bubble with respect to the anchor's centre, @@ -194,32 +195,32 @@ Blockly.Bubble.prototype.anchorXY_ = null; * In RTL mode the initial value is negated. * @private */ -Blockly.Bubble.prototype.relativeLeft_ = 0; +Bubble.prototype.relativeLeft_ = 0; /** * Relative Y coordinate of bubble with respect to the anchor's centre, in * workspace units. * @private */ -Blockly.Bubble.prototype.relativeTop_ = 0; +Bubble.prototype.relativeTop_ = 0; /** * Width of bubble, in workspace units. * @private */ -Blockly.Bubble.prototype.width_ = 0; +Bubble.prototype.width_ = 0; /** * Height of bubble, in workspace units. * @private */ -Blockly.Bubble.prototype.height_ = 0; +Bubble.prototype.height_ = 0; /** * Automatically position and reposition the bubble. * @private */ -Blockly.Bubble.prototype.autoLayout_ = true; +Bubble.prototype.autoLayout_ = true; /** * Create the bubble's DOM. @@ -228,7 +229,7 @@ Blockly.Bubble.prototype.autoLayout_ = true; * @return {!SVGElement} The bubble's SVG group. * @private */ -Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { +Bubble.prototype.createDom_ = function(content, hasResize) { /* Create the bubble. Here's the markup that will be generated: @@ -263,8 +264,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { 'class': 'blocklyDraggable', 'x': 0, 'y': 0, - 'rx': Blockly.Bubble.BORDER_WIDTH, - 'ry': Blockly.Bubble.BORDER_WIDTH + 'rx': Bubble.BORDER_WIDTH, + 'ry': Bubble.BORDER_WIDTH }, bubbleEmboss); if (hasResize) { @@ -272,7 +273,7 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { Blockly.utils.Svg.G, {'class': this.workspace_.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE'}, this.bubbleGroup_); - const resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; + const resizeSize = 2 * Bubble.BORDER_WIDTH; Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.POLYGON, {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, @@ -315,7 +316,7 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { * Return the root node of the bubble's SVG group. * @return {!SVGElement} The root SVG node of the bubble's group. */ -Blockly.Bubble.prototype.getSvgRoot = function() { +Bubble.prototype.getSvgRoot = function() { return this.bubbleGroup_; }; @@ -323,7 +324,7 @@ Blockly.Bubble.prototype.getSvgRoot = function() { * Expose the block's ID on the bubble's top-level SVG group. * @param {string} id ID of block. */ -Blockly.Bubble.prototype.setSvgId = function(id) { +Bubble.prototype.setSvgId = function(id) { if (this.bubbleGroup_.dataset) { this.bubbleGroup_.dataset['blockId'] = id; } @@ -334,7 +335,7 @@ Blockly.Bubble.prototype.setSvgId = function(id) { * @param {!Event} e Mouse down event. * @private */ -Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) { +Bubble.prototype.bubbleMouseDown_ = function(e) { const gesture = this.workspace_.getGesture(e); if (gesture) { gesture.handleBubbleStart(e, this); @@ -346,7 +347,7 @@ Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) { * @param {!Event} _e Mouse event. * @package */ -Blockly.Bubble.prototype.showContextMenu = function(_e) { +Bubble.prototype.showContextMenu = function(_e) { // NOP on bubbles, but used by the bubble dragger to pass events to // workspace comments. }; @@ -356,7 +357,7 @@ Blockly.Bubble.prototype.showContextMenu = function(_e) { * @return {boolean} True if deletable. * @package */ -Blockly.Bubble.prototype.isDeletable = function() { +Bubble.prototype.isDeletable = function() { return false; }; @@ -365,7 +366,7 @@ Blockly.Bubble.prototype.isDeletable = function() { * @param {boolean} _enable True if the bubble is about to be deleted, false * otherwise. */ -Blockly.Bubble.prototype.setDeleteStyle = function(_enable) { +Bubble.prototype.setDeleteStyle = function(_enable) { // NOP if bubble is not deletable. }; @@ -374,9 +375,9 @@ Blockly.Bubble.prototype.setDeleteStyle = function(_enable) { * @param {!Event} e Mouse down event. * @private */ -Blockly.Bubble.prototype.resizeMouseDown_ = function(e) { +Bubble.prototype.resizeMouseDown_ = function(e) { this.promote(); - Blockly.Bubble.unbindDragEvents_(); + Bubble.unbindDragEvents_(); if (Blockly.utils.isRightButton(e)) { // No right-click. e.stopPropagation(); @@ -388,9 +389,9 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) { new Blockly.utils.Coordinate( this.workspace_.RTL ? -this.width_ : this.width_, this.height_)); - Blockly.Bubble.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( - document, 'mouseup', this, Blockly.Bubble.bubbleMouseUp_); - Blockly.Bubble.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + Bubble.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mouseup', this, Bubble.bubbleMouseUp_); + Bubble.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( document, 'mousemove', this, this.resizeMouseMove_); Blockly.hideChaff(); // This event has been handled. No need to bubble up to the document. @@ -402,7 +403,7 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) { * @param {!Event} e Mouse move event. * @private */ -Blockly.Bubble.prototype.resizeMouseMove_ = function(e) { +Bubble.prototype.resizeMouseMove_ = function(e) { this.autoLayout_ = false; const newXY = this.workspace_.moveDrag(e); this.setBubbleSize(this.workspace_.RTL ? -newXY.x : newXY.x, newXY.y); @@ -416,7 +417,7 @@ Blockly.Bubble.prototype.resizeMouseMove_ = function(e) { * Register a function as a callback event for when the bubble is resized. * @param {!Function} callback The function to call on resize. */ -Blockly.Bubble.prototype.registerResizeEvent = function(callback) { +Bubble.prototype.registerResizeEvent = function(callback) { this.resizeCallback_ = callback; }; @@ -424,7 +425,7 @@ Blockly.Bubble.prototype.registerResizeEvent = function(callback) { * Register a function as a callback event for when the bubble is moved. * @param {!Function} callback The function to call on move. */ -Blockly.Bubble.prototype.registerMoveEvent = function(callback) { +Bubble.prototype.registerMoveEvent = function(callback) { this.moveCallback_ = callback; }; @@ -433,7 +434,7 @@ Blockly.Bubble.prototype.registerMoveEvent = function(callback) { * @return {boolean} Whether or not the bubble has been moved. * @package */ -Blockly.Bubble.prototype.promote = function() { +Bubble.prototype.promote = function() { const svgGroup = this.bubbleGroup_.parentNode; if (svgGroup.lastChild !== this.bubbleGroup_) { svgGroup.appendChild(this.bubbleGroup_); @@ -447,7 +448,7 @@ Blockly.Bubble.prototype.promote = function() { * Update the arrow and bubble accordingly. * @param {!Blockly.utils.Coordinate} xy Absolute location. */ -Blockly.Bubble.prototype.setAnchorLocation = function(xy) { +Bubble.prototype.setAnchorLocation = function(xy) { this.anchorXY_ = xy; if (this.rendered_) { this.positionBubble_(); @@ -458,7 +459,7 @@ Blockly.Bubble.prototype.setAnchorLocation = function(xy) { * Position the bubble so that it does not fall off-screen. * @private */ -Blockly.Bubble.prototype.layoutBubble_ = function() { +Bubble.prototype.layoutBubble_ = function() { // Get the metrics in workspace units. const viewMetrics = this.workspace_.getMetricsManager().getViewMetrics(true); @@ -520,7 +521,7 @@ Blockly.Bubble.prototype.layoutBubble_ = function() { * @return {number} The percentage of the bubble that is visible. * @private */ -Blockly.Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { +Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { // The position of the top-left corner of the bubble in workspace units. const bubbleMin = { x: this.workspace_.RTL ? (this.anchorXY_.x - relativeMin.x - this.width_) : @@ -563,7 +564,7 @@ Blockly.Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { * of the bubble. * @private */ -Blockly.Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { +Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { let relativeLeft = -this.width_ / 4; // No amount of sliding left or right will give us a better overlap. @@ -619,7 +620,7 @@ Blockly.Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { * of the bubble. * @private */ -Blockly.Bubble.prototype.getOptimalRelativeTop_ = function(viewMetrics) { +Bubble.prototype.getOptimalRelativeTop_ = function(viewMetrics) { let relativeTop = -this.height_ / 4; // No amount of sliding up or down will give us a better overlap. @@ -650,7 +651,7 @@ Blockly.Bubble.prototype.getOptimalRelativeTop_ = function(viewMetrics) { * Move the bubble to a location relative to the anchor's centre. * @private */ -Blockly.Bubble.prototype.positionBubble_ = function() { +Bubble.prototype.positionBubble_ = function() { let left = this.anchorXY_.x; if (this.workspace_.RTL) { left -= this.relativeLeft_ + this.width_; @@ -667,7 +668,7 @@ Blockly.Bubble.prototype.positionBubble_ = function() { * @param {number} y The y position to move to. * @package */ -Blockly.Bubble.prototype.moveTo = function(x, y) { +Bubble.prototype.moveTo = function(x, y) { this.bubbleGroup_.setAttribute('transform', 'translate(' + x + ',' + y + ')'); }; @@ -676,7 +677,7 @@ Blockly.Bubble.prototype.moveTo = function(x, y) { * @param {boolean} adding True if adding, false if removing. * @package */ -Blockly.Bubble.prototype.setDragging = function(adding) { +Bubble.prototype.setDragging = function(adding) { if (!adding && this.moveCallback_) { this.moveCallback_(); } @@ -686,7 +687,7 @@ Blockly.Bubble.prototype.setDragging = function(adding) { * Get the dimensions of this bubble. * @return {!Blockly.utils.Size} The height and width of the bubble. */ -Blockly.Bubble.prototype.getBubbleSize = function() { +Bubble.prototype.getBubbleSize = function() { return new Blockly.utils.Size(this.width_, this.height_); }; @@ -695,8 +696,8 @@ Blockly.Bubble.prototype.getBubbleSize = function() { * @param {number} width Width of the bubble. * @param {number} height Height of the bubble. */ -Blockly.Bubble.prototype.setBubbleSize = function(width, height) { - const doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; +Bubble.prototype.setBubbleSize = function(width, height) { + const doubleBorderWidth = 2 * Bubble.BORDER_WIDTH; // Minimum size of a bubble. width = Math.max(width, doubleBorderWidth + 45); height = Math.max(height, doubleBorderWidth + 20); @@ -707,7 +708,7 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { if (this.resizeGroup_) { if (this.workspace_.RTL) { // Mirror the resize group. - const resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH; + const resizeSize = 2 * Bubble.BORDER_WIDTH; this.resizeGroup_.setAttribute( 'transform', 'translate(' + resizeSize + ',' + (height - doubleBorderWidth) + @@ -735,7 +736,7 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { * Draw the arrow between the bubble and the origin. * @private */ -Blockly.Bubble.prototype.renderArrow_ = function() { +Bubble.prototype.renderArrow_ = function() { const steps = []; // Find the relative coordinates of the center of the bubble. const relBubbleX = this.width_ / 2; @@ -770,11 +771,11 @@ Blockly.Bubble.prototype.renderArrow_ = function() { // Calculate the thickness of the base of the arrow. const bubbleSize = this.getBubbleSize(); let thickness = - (bubbleSize.width + bubbleSize.height) / Blockly.Bubble.ARROW_THICKNESS; + (bubbleSize.width + bubbleSize.height) / Bubble.ARROW_THICKNESS; thickness = Math.min(thickness, bubbleSize.width, bubbleSize.height) / 4; // Back the tip of the arrow off of the anchor. - const backoffRatio = 1 - Blockly.Bubble.ANCHOR_RADIUS / hypotenuse; + const backoffRatio = 1 - Bubble.ANCHOR_RADIUS / hypotenuse; relAnchorX = relBubbleX + backoffRatio * run; relAnchorY = relBubbleY + backoffRatio * rise; @@ -790,9 +791,9 @@ Blockly.Bubble.prototype.renderArrow_ = function() { swirlAngle -= Math.PI * 2; } const swirlRise = - Math.sin(swirlAngle) * hypotenuse / Blockly.Bubble.ARROW_BEND; + Math.sin(swirlAngle) * hypotenuse / Bubble.ARROW_BEND; const swirlRun = - Math.cos(swirlAngle) * hypotenuse / Blockly.Bubble.ARROW_BEND; + Math.cos(swirlAngle) * hypotenuse / Bubble.ARROW_BEND; steps.push('M' + baseX1 + ',' + baseY1); steps.push( @@ -810,7 +811,7 @@ Blockly.Bubble.prototype.renderArrow_ = function() { * Change the colour of a bubble. * @param {string} hexColour Hex code of colour. */ -Blockly.Bubble.prototype.setColour = function(hexColour) { +Bubble.prototype.setColour = function(hexColour) { this.bubbleBack_.setAttribute('fill', hexColour); this.bubbleArrow_.setAttribute('fill', hexColour); }; @@ -818,14 +819,14 @@ Blockly.Bubble.prototype.setColour = function(hexColour) { /** * Dispose of this bubble. */ -Blockly.Bubble.prototype.dispose = function() { +Bubble.prototype.dispose = function() { if (this.onMouseDownBubbleWrapper_) { Blockly.browserEvents.unbind(this.onMouseDownBubbleWrapper_); } if (this.onMouseDownResizeWrapper_) { Blockly.browserEvents.unbind(this.onMouseDownResizeWrapper_); } - Blockly.Bubble.unbindDragEvents_(); + Bubble.unbindDragEvents_(); Blockly.utils.dom.removeNode(this.bubbleGroup_); this.disposed = true; }; @@ -839,7 +840,7 @@ Blockly.Bubble.prototype.dispose = function() { * workspace coordinates. * @package */ -Blockly.Bubble.prototype.moveDuringDrag = function(dragSurface, newLoc) { +Bubble.prototype.moveDuringDrag = function(dragSurface, newLoc) { if (dragSurface) { dragSurface.translateSurface(newLoc.x, newLoc.y); } else { @@ -859,7 +860,7 @@ Blockly.Bubble.prototype.moveDuringDrag = function(dragSurface, newLoc) { * to the drawing surface's origin (0,0), in workspace units. * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. */ -Blockly.Bubble.prototype.getRelativeToSurfaceXY = function() { +Bubble.prototype.getRelativeToSurfaceXY = function() { return new Blockly.utils.Coordinate( this.workspace_.RTL ? -this.relativeLeft_ + this.anchorXY_.x - this.width_ : @@ -875,7 +876,7 @@ Blockly.Bubble.prototype.getRelativeToSurfaceXY = function() { * otherwise. * @package */ -Blockly.Bubble.prototype.setAutoLayout = function(enable) { +Bubble.prototype.setAutoLayout = function(enable) { this.autoLayout_ = enable; }; @@ -885,18 +886,18 @@ Blockly.Bubble.prototype.setAutoLayout = function(enable) { * @return {!SVGTextElement} The top-level node of the text. * @package */ -Blockly.Bubble.textToDom = function(text) { +Bubble.textToDom = function(text) { const paragraph = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TEXT, { 'class': 'blocklyText blocklyBubbleText blocklyNoPointerEvents', - 'y': Blockly.Bubble.BORDER_WIDTH + 'y': Bubble.BORDER_WIDTH }, null); const lines = text.split('\n'); for (let i = 0; i < lines.length; i++) { const tspanElement = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.TSPAN, - {'dy': '1em', 'x': Blockly.Bubble.BORDER_WIDTH}, paragraph); + {'dy': '1em', 'x': Bubble.BORDER_WIDTH}, paragraph); const textNode = document.createTextNode(lines[i]); tspanElement.appendChild(textNode); } @@ -909,12 +910,12 @@ Blockly.Bubble.textToDom = function(text) { * editable bubble. * @param {!Blockly.BlockSvg} block The block that the bubble is attached to. * @param {!Blockly.utils.Coordinate} iconXY The coordinate of the icon. - * @return {!Blockly.Bubble} The non editable bubble. + * @return {!Bubble} The non editable bubble. * @package */ -Blockly.Bubble.createNonEditableBubble = function( +Bubble.createNonEditableBubble = function( paragraphElement, block, iconXY) { - const bubble = new Blockly.Bubble( + const bubble = new Bubble( /** @type {!Blockly.WorkspaceSvg} */ (block.workspace), paragraphElement, block.pathObject.svgPath, /** @type {!Blockly.utils.Coordinate} */ (iconXY), null, null); @@ -927,8 +928,10 @@ Blockly.Bubble.createNonEditableBubble = function( for (let i = 0, textElement; (textElement = paragraphElement.childNodes[i]); i++) { textElement.setAttribute('text-anchor', 'end'); - textElement.setAttribute('x', maxWidth + Blockly.Bubble.BORDER_WIDTH); + textElement.setAttribute('x', maxWidth + Bubble.BORDER_WIDTH); } } return bubble; }; + +exports = Bubble; diff --git a/tests/deps.js b/tests/deps.js index 805416071..684fe3598 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -15,7 +15,7 @@ goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.AS goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); -goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); +goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); From a6a10ee9459b83fc43e03a11bc91c3f795a10e8a Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Tue, 27 Jul 2021 16:31:02 -0700 Subject: [PATCH 383/833] Migrate core/bubble.js to named requires --- core/bubble.js | 155 ++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 73 deletions(-) diff --git a/core/bubble.js b/core/bubble.js index aeae81769..b1b70da4c 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -13,37 +13,46 @@ goog.module('Blockly.Bubble'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.browserEvents'); -goog.require('Blockly.IBubble'); -goog.require('Blockly.Scrollbar'); -goog.require('Blockly.Touch'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.math'); -goog.require('Blockly.utils.Size'); -goog.require('Blockly.utils.Svg'); -goog.require('Blockly.utils.userAgent'); +// TODO(#5073): Fix Blockly requires for Blockly.hideChaff() +// const Blockly = goog.require('Blockly'); +/* eslint-disable-next-line no-unused-vars */ +const BlockDragSurfaceSvg = goog.requireType('Blockly.BlockDragSurfaceSvg'); +/* eslint-disable-next-line no-unused-vars */ +const BlockSvg = goog.requireType('Blockly.BlockSvg'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +/* eslint-disable-next-line no-unused-vars */ +const IBubble = goog.require('Blockly.IBubble'); +/* eslint-disable-next-line no-unused-vars */ +const MetricsManager = goog.requireType('Blockly.MetricsManager'); +const Scrollbar = goog.require('Blockly.Scrollbar'); +const Size = goog.require('Blockly.utils.Size'); +const Svg = goog.require('Blockly.utils.Svg'); +const Touch = goog.require('Blockly.Touch'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); +const browserEvents = goog.require('Blockly.browserEvents'); +const dom = goog.require('Blockly.utils.dom'); +const math = goog.require('Blockly.utils.math'); +const userAgent = goog.require('Blockly.utils.userAgent'); +const utils = goog.require('Blockly.utils'); + /** @suppress {extraRequire} */ goog.require('Blockly.Workspace'); -goog.requireType('Blockly.BlockDragSurfaceSvg'); -goog.requireType('Blockly.BlockSvg'); -goog.requireType('Blockly.MetricsManager'); -goog.requireType('Blockly.WorkspaceSvg'); + /** * Class for UI bubble. - * @param {!Blockly.WorkspaceSvg} workspace The workspace on which to draw the + * @param {!WorkspaceSvg} workspace The workspace on which to draw the * bubble. * @param {!Element} content SVG content for the bubble. * @param {!Element} shape SVG element to avoid eclipsing. - * @param {!Blockly.utils.Coordinate} anchorXY Absolute position of bubble's + * @param {!Coordinate} anchorXY Absolute position of bubble's * anchor point. * @param {?number} bubbleWidth Width of bubble, or null if not resizable. * @param {?number} bubbleHeight Height of bubble, or null if not resizable. - * @implements {Blockly.IBubble} + * @implements {IBubble} * @constructor */ const Bubble = function( @@ -68,14 +77,14 @@ const Bubble = function( /** * Mouse down on bubbleBack_ event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseDownBubbleWrapper_ = null; /** * Mouse down on resizeGroup_ event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ this.onMouseDownResizeWrapper_ = null; @@ -92,7 +101,7 @@ const Bubble = function( if (this.workspace_.RTL) { angle = -angle; } - this.arrow_radians_ = Blockly.utils.math.toRadians(angle); + this.arrow_radians_ = math.toRadians(angle); const canvas = workspace.getBubbleCanvas(); canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight))); @@ -139,14 +148,14 @@ Bubble.ANCHOR_RADIUS = 8; /** * Mouse up event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ Bubble.onMouseUpWrapper_ = null; /** * Mouse move event data. - * @type {?Blockly.browserEvents.Data} + * @type {?browserEvents.Data} * @private */ Bubble.onMouseMoveWrapper_ = null; @@ -157,11 +166,11 @@ Bubble.onMouseMoveWrapper_ = null; */ Bubble.unbindDragEvents_ = function() { if (Bubble.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(Bubble.onMouseUpWrapper_); + browserEvents.unbind(Bubble.onMouseUpWrapper_); Bubble.onMouseUpWrapper_ = null; } if (Bubble.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(Bubble.onMouseMoveWrapper_); + browserEvents.unbind(Bubble.onMouseMoveWrapper_); Bubble.onMouseMoveWrapper_ = null; } }; @@ -172,7 +181,7 @@ Bubble.unbindDragEvents_ = function() { * @private */ Bubble.bubbleMouseUp_ = function(_e) { - Blockly.Touch.clearTouchIdentifier(); + Touch.clearTouchIdentifier(); Bubble.unbindDragEvents_(); }; @@ -184,7 +193,7 @@ Bubble.prototype.rendered_ = false; /** * Absolute coordinate of anchor point, in workspace coordinates. - * @type {Blockly.utils.Coordinate} + * @type {Coordinate} * @private */ Bubble.prototype.anchorXY_ = null; @@ -245,22 +254,22 @@ Bubble.prototype.createDom_ = function(content, hasResize) { */ this.bubbleGroup_ = - Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.G, {}, null); + dom.createSvgElement(Svg.G, {}, null); let filter = { 'filter': 'url(#' + this.workspace_.getRenderer().getConstants().embossFilterId + ')' }; - if (Blockly.utils.userAgent.JAVA_FX) { + if (userAgent.JAVA_FX) { // Multiple reports that JavaFX can't handle filters. // https://github.com/google/blockly/issues/99 filter = {}; } - const bubbleEmboss = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, filter, this.bubbleGroup_); - this.bubbleArrow_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.PATH, {}, bubbleEmboss); - this.bubbleBack_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, { + const bubbleEmboss = dom.createSvgElement( + Svg.G, filter, this.bubbleGroup_); + this.bubbleArrow_ = dom.createSvgElement( + Svg.PATH, {}, bubbleEmboss); + this.bubbleBack_ = dom.createSvgElement( + Svg.RECT, { 'class': 'blocklyDraggable', 'x': 0, 'y': 0, @@ -269,17 +278,17 @@ Bubble.prototype.createDom_ = function(content, hasResize) { }, bubbleEmboss); if (hasResize) { - this.resizeGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, + this.resizeGroup_ = dom.createSvgElement( + Svg.G, {'class': this.workspace_.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE'}, this.bubbleGroup_); const resizeSize = 2 * Bubble.BORDER_WIDTH; - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.POLYGON, + dom.createSvgElement( + Svg.POLYGON, {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, this.resizeGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, { + dom.createSvgElement( + Svg.LINE, { 'class': 'blocklyResizeLine', 'x1': resizeSize / 3, 'y1': resizeSize - 1, @@ -287,8 +296,8 @@ Bubble.prototype.createDom_ = function(content, hasResize) { 'y2': resizeSize / 3 }, this.resizeGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, { + dom.createSvgElement( + Svg.LINE, { 'class': 'blocklyResizeLine', 'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1, @@ -301,10 +310,10 @@ Bubble.prototype.createDom_ = function(content, hasResize) { } if (!this.workspace_.options.readOnly) { - this.onMouseDownBubbleWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseDownBubbleWrapper_ = browserEvents.conditionalBind( this.bubbleBack_, 'mousedown', this, this.bubbleMouseDown_); if (this.resizeGroup_) { - this.onMouseDownResizeWrapper_ = Blockly.browserEvents.conditionalBind( + this.onMouseDownResizeWrapper_ = browserEvents.conditionalBind( this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); } } @@ -378,7 +387,7 @@ Bubble.prototype.setDeleteStyle = function(_enable) { Bubble.prototype.resizeMouseDown_ = function(e) { this.promote(); Bubble.unbindDragEvents_(); - if (Blockly.utils.isRightButton(e)) { + if (utils.isRightButton(e)) { // No right-click. e.stopPropagation(); return; @@ -386,12 +395,12 @@ Bubble.prototype.resizeMouseDown_ = function(e) { // Left-click (or middle click) this.workspace_.startDrag( e, - new Blockly.utils.Coordinate( + new Coordinate( this.workspace_.RTL ? -this.width_ : this.width_, this.height_)); - Bubble.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + Bubble.onMouseUpWrapper_ = browserEvents.conditionalBind( document, 'mouseup', this, Bubble.bubbleMouseUp_); - Bubble.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + Bubble.onMouseMoveWrapper_ = browserEvents.conditionalBind( document, 'mousemove', this, this.resizeMouseMove_); Blockly.hideChaff(); // This event has been handled. No need to bubble up to the document. @@ -446,7 +455,7 @@ Bubble.prototype.promote = function() { /** * Notification that the anchor has moved. * Update the arrow and bubble accordingly. - * @param {!Blockly.utils.Coordinate} xy Absolute location. + * @param {!Coordinate} xy Absolute location. */ Bubble.prototype.setAnchorLocation = function(xy) { this.anchorXY_ = xy; @@ -516,7 +525,7 @@ Bubble.prototype.layoutBubble_ = function() { * workspace (what percentage of the bubble is visible). * @param {!{x: number, y: number}} relativeMin The position of the top-left * corner of the bubble relative to the anchor point. - * @param {!Blockly.MetricsManager.ContainerRegion} viewMetrics The view metrics + * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics * of the workspace the bubble will appear in. * @return {number} The percentage of the bubble that is visible. * @private @@ -558,7 +567,7 @@ Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { * Calculate what the optimal horizontal position of the top-left corner of the * bubble is (relative to the anchor point) so that the most area of the * bubble is shown. - * @param {!Blockly.MetricsManager.ContainerRegion} viewMetrics The view metrics + * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics * of the workspace the bubble will appear in. * @return {number} The optimal horizontal position of the top-left corner * of the bubble. @@ -580,7 +589,7 @@ Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { const workspaceRight = viewMetrics.left + viewMetrics.width; const workspaceLeft = viewMetrics.left + // Thickness in workspace units. - (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); + (Scrollbar.scrollbarThickness / this.workspace_.scale); if (bubbleLeft < workspaceLeft) { // Slide the bubble right until it is onscreen. @@ -596,7 +605,7 @@ Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { const workspaceLeft = viewMetrics.left; const workspaceRight = viewMetrics.left + viewMetrics.width - // Thickness in workspace units. - (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); + (Scrollbar.scrollbarThickness / this.workspace_.scale); if (bubbleLeft < workspaceLeft) { // Slide the bubble right until it is onscreen. @@ -614,7 +623,7 @@ Bubble.prototype.getOptimalRelativeLeft_ = function(viewMetrics) { * Calculate what the optimal vertical position of the top-left corner of * the bubble is (relative to the anchor point) so that the most area of the * bubble is shown. - * @param {!Blockly.MetricsManager.ContainerRegion} viewMetrics The view metrics + * @param {!MetricsManager.ContainerRegion} viewMetrics The view metrics * of the workspace the bubble will appear in. * @return {number} The optimal vertical position of the top-left corner * of the bubble. @@ -633,7 +642,7 @@ Bubble.prototype.getOptimalRelativeTop_ = function(viewMetrics) { const workspaceTop = viewMetrics.top; const workspaceBottom = viewMetrics.top + viewMetrics.height - // Thickness in workspace units. - (Blockly.Scrollbar.scrollbarThickness / this.workspace_.scale); + (Scrollbar.scrollbarThickness / this.workspace_.scale); const anchorY = this.anchorXY_.y; if (bubbleTop < workspaceTop) { @@ -685,10 +694,10 @@ Bubble.prototype.setDragging = function(adding) { /** * Get the dimensions of this bubble. - * @return {!Blockly.utils.Size} The height and width of the bubble. + * @return {!Size} The height and width of the bubble. */ Bubble.prototype.getBubbleSize = function() { - return new Blockly.utils.Size(this.width_, this.height_); + return new Size(this.width_, this.height_); }; /** @@ -821,22 +830,22 @@ Bubble.prototype.setColour = function(hexColour) { */ Bubble.prototype.dispose = function() { if (this.onMouseDownBubbleWrapper_) { - Blockly.browserEvents.unbind(this.onMouseDownBubbleWrapper_); + browserEvents.unbind(this.onMouseDownBubbleWrapper_); } if (this.onMouseDownResizeWrapper_) { - Blockly.browserEvents.unbind(this.onMouseDownResizeWrapper_); + browserEvents.unbind(this.onMouseDownResizeWrapper_); } Bubble.unbindDragEvents_(); - Blockly.utils.dom.removeNode(this.bubbleGroup_); + dom.removeNode(this.bubbleGroup_); this.disposed = true; }; /** * Move this bubble during a drag, taking into account whether or not there is * a drag surface. - * @param {Blockly.BlockDragSurfaceSvg} dragSurface The surface that carries + * @param {BlockDragSurfaceSvg} dragSurface The surface that carries * rendered items during a drag, or null if no drag surface is in use. - * @param {!Blockly.utils.Coordinate} newLoc The location to translate to, in + * @param {!Coordinate} newLoc The location to translate to, in * workspace coordinates. * @package */ @@ -858,10 +867,10 @@ Bubble.prototype.moveDuringDrag = function(dragSurface, newLoc) { /** * Return the coordinates of the top-left corner of this bubble's body relative * to the drawing surface's origin (0,0), in workspace units. - * @return {!Blockly.utils.Coordinate} Object with .x and .y properties. + * @return {!Coordinate} Object with .x and .y properties. */ Bubble.prototype.getRelativeToSurfaceXY = function() { - return new Blockly.utils.Coordinate( + return new Coordinate( this.workspace_.RTL ? -this.relativeLeft_ + this.anchorXY_.x - this.width_ : this.anchorXY_.x + this.relativeLeft_, @@ -887,16 +896,16 @@ Bubble.prototype.setAutoLayout = function(enable) { * @package */ Bubble.textToDom = function(text) { - const paragraph = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TEXT, { + const paragraph = dom.createSvgElement( + Svg.TEXT, { 'class': 'blocklyText blocklyBubbleText blocklyNoPointerEvents', 'y': Bubble.BORDER_WIDTH }, null); const lines = text.split('\n'); for (let i = 0; i < lines.length; i++) { - const tspanElement = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.TSPAN, + const tspanElement = dom.createSvgElement( + Svg.TSPAN, {'dy': '1em', 'x': Bubble.BORDER_WIDTH}, paragraph); const textNode = document.createTextNode(lines[i]); tspanElement.appendChild(textNode); @@ -908,17 +917,17 @@ Bubble.textToDom = function(text) { * Creates a bubble that can not be edited. * @param {!SVGTextElement} paragraphElement The text element for the non * editable bubble. - * @param {!Blockly.BlockSvg} block The block that the bubble is attached to. - * @param {!Blockly.utils.Coordinate} iconXY The coordinate of the icon. + * @param {!BlockSvg} block The block that the bubble is attached to. + * @param {!Coordinate} iconXY The coordinate of the icon. * @return {!Bubble} The non editable bubble. * @package */ Bubble.createNonEditableBubble = function( paragraphElement, block, iconXY) { const bubble = new Bubble( - /** @type {!Blockly.WorkspaceSvg} */ (block.workspace), paragraphElement, + /** @type {!WorkspaceSvg} */ (block.workspace), paragraphElement, block.pathObject.svgPath, - /** @type {!Blockly.utils.Coordinate} */ (iconXY), null, null); + /** @type {!Coordinate} */ (iconXY), null, null); // Expose this bubble's block's ID on its top-level SVG group. bubble.setSvgId(block.id); if (block.RTL) { From e1f06ca8a43bc7a82d717cee6251c9fc07738fe5 Mon Sep 17 00:00:00 2001 From: Maribeth Bottorff Date: Tue, 27 Jul 2021 16:34:32 -0700 Subject: [PATCH 384/833] clang-format core/bubble.js --- core/bubble.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/core/bubble.js b/core/bubble.js index b1b70da4c..a31d16a90 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -41,7 +41,6 @@ goog.require('Blockly.Workspace'); - /** * Class for UI bubble. * @param {!WorkspaceSvg} workspace The workspace on which to draw the @@ -253,8 +252,7 @@ Bubble.prototype.createDom_ = function(content, hasResize) { [...content goes here...] */ - this.bubbleGroup_ = - dom.createSvgElement(Svg.G, {}, null); + this.bubbleGroup_ = dom.createSvgElement(Svg.G, {}, null); let filter = { 'filter': 'url(#' + this.workspace_.getRenderer().getConstants().embossFilterId + ')' @@ -264,10 +262,8 @@ Bubble.prototype.createDom_ = function(content, hasResize) { // https://github.com/google/blockly/issues/99 filter = {}; } - const bubbleEmboss = dom.createSvgElement( - Svg.G, filter, this.bubbleGroup_); - this.bubbleArrow_ = dom.createSvgElement( - Svg.PATH, {}, bubbleEmboss); + const bubbleEmboss = dom.createSvgElement(Svg.G, filter, this.bubbleGroup_); + this.bubbleArrow_ = dom.createSvgElement(Svg.PATH, {}, bubbleEmboss); this.bubbleBack_ = dom.createSvgElement( Svg.RECT, { 'class': 'blocklyDraggable', @@ -485,8 +481,10 @@ Bubble.prototype.layoutBubble_ = function() { const endPosition = {x: bbox.width, y: optimalTop}; const bottomPosition = {x: optimalLeft, y: bbox.height}; - const closerPosition = bbox.width < bbox.height ? endPosition : bottomPosition; - const fartherPosition = bbox.width < bbox.height ? bottomPosition : endPosition; + const closerPosition = + bbox.width < bbox.height ? endPosition : bottomPosition; + const fartherPosition = + bbox.width < bbox.height ? bottomPosition : endPosition; const topPositionOverlap = this.getOverlap_(topPosition, viewMetrics); const startPositionOverlap = this.getOverlap_(startPosition, viewMetrics); @@ -538,7 +536,10 @@ Bubble.prototype.getOverlap_ = function(relativeMin, viewMetrics) { y: relativeMin.y + this.anchorXY_.y }; // The position of the bottom-right corner of the bubble in workspace units. - const bubbleMax = {x: bubbleMin.x + this.width_, y: bubbleMin.y + this.height_}; + const bubbleMax = { + x: bubbleMin.x + this.width_, + y: bubbleMin.y + this.height_ + }; // We could adjust these values to account for the scrollbars, but the // bubbles should have been adjusted to not collide with them anyway, so @@ -799,10 +800,8 @@ Bubble.prototype.renderArrow_ = function() { if (swirlAngle > Math.PI * 2) { swirlAngle -= Math.PI * 2; } - const swirlRise = - Math.sin(swirlAngle) * hypotenuse / Bubble.ARROW_BEND; - const swirlRun = - Math.cos(swirlAngle) * hypotenuse / Bubble.ARROW_BEND; + const swirlRise = Math.sin(swirlAngle) * hypotenuse / Bubble.ARROW_BEND; + const swirlRun = Math.cos(swirlAngle) * hypotenuse / Bubble.ARROW_BEND; steps.push('M' + baseX1 + ',' + baseY1); steps.push( @@ -905,8 +904,7 @@ Bubble.textToDom = function(text) { const lines = text.split('\n'); for (let i = 0; i < lines.length; i++) { const tspanElement = dom.createSvgElement( - Svg.TSPAN, - {'dy': '1em', 'x': Bubble.BORDER_WIDTH}, paragraph); + Svg.TSPAN, {'dy': '1em', 'x': Bubble.BORDER_WIDTH}, paragraph); const textNode = document.createTextNode(lines[i]); tspanElement.appendChild(textNode); } @@ -922,8 +920,7 @@ Bubble.textToDom = function(text) { * @return {!Bubble} The non editable bubble. * @package */ -Bubble.createNonEditableBubble = function( - paragraphElement, block, iconXY) { +Bubble.createNonEditableBubble = function(paragraphElement, block, iconXY) { const bubble = new Bubble( /** @type {!WorkspaceSvg} */ (block.workspace), paragraphElement, block.pathObject.svgPath, From adc4c02abfd85b4d60a064d94b433e52ed56f787 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 16:39:44 -0700 Subject: [PATCH 385/833] Fix lint --- core/field_variable.js | 3 +++ core/gesture.js | 2 ++ core/zoom_controls.js | 8 ++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index f700d4a99..f4ae38a51 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -13,9 +13,12 @@ goog.module('Blockly.FieldVariable'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const Block = goog.requireType('Blockly.Block'); const FieldDropdown = goog.require('Blockly.FieldDropdown'); +/* eslint-disable-next-line no-unused-vars */ const Menu = goog.requireType('Blockly.Menu'); +/* eslint-disable-next-line no-unused-vars */ const MenuItem = goog.requireType('Blockly.MenuItem'); const Msg = goog.require('Blockly.Msg'); const Size = goog.require('Blockly.utils.Size'); diff --git a/core/gesture.js b/core/gesture.js index 933930e44..a1ef6ca91 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -22,6 +22,7 @@ const BubbleDragger = goog.require('Blockly.BubbleDragger'); const Coordinate = goog.require('Blockly.utils.Coordinate'); /* eslint-disable-next-line no-unused-vars */ const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const Field = goog.requireType('Blockly.Field'); /* eslint-disable-next-line no-unused-vars */ const IBlockDragger = goog.requireType('Blockly.IBlockDragger'); @@ -33,6 +34,7 @@ const Tooltip = goog.require('Blockly.Tooltip'); const Touch = goog.require('Blockly.Touch'); /* eslint-disable-next-line no-unused-vars */ const Workspace = goog.require('Blockly.Workspace'); +/* eslint-disable-next-line no-unused-vars */ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); const WorkspaceDragger = goog.require('Blockly.WorkspaceDragger'); const blockAnimations = goog.require('Blockly.blockAnimations'); diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 37c1cb17d..1b7a568cc 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -13,10 +13,10 @@ goog.module('Blockly.ZoomControls'); goog.module.declareLegacyNamespace(); -const Blockly = goog.require('Blockly'); const ComponentManager = goog.require('Blockly.ComponentManager'); const Css = goog.require('Blockly.Css'); const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ const IPositionable = goog.require('Blockly.IPositionable'); const Rect = goog.require('Blockly.utils.Rect'); const Svg = goog.require('Blockly.utils.Svg'); @@ -54,7 +54,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom reset - * button. Opaque data returned from Blockly.bindEventWithChecks_. + * button. Opaque data returned from browserEvents.conditionalBind. * @type {?browserEvents.Data} * @private */ @@ -62,7 +62,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom in button. - * Opaque data returned from Blockly.bindEventWithChecks_. + * Opaque data returned from browserEvents.conditionalBind. * @type {?browserEvents.Data} * @private */ @@ -70,7 +70,7 @@ const ZoomControls = function(workspace) { /** * A handle to use to unbind the mouse down event handler for zoom out button. - * Opaque data returned from Blockly.bindEventWithChecks_. + * Opaque data returned from browserEvents.conditionalBind. * @type {?browserEvents.Data} * @private */ From 4c6b2bae3985979c565d83af4622c1d01adb7c1f Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 27 Jul 2021 16:45:05 -0700 Subject: [PATCH 386/833] Rebuild --- tests/deps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/deps.js b/tests/deps.js index 0018d3a1d..0820fc9e1 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -210,6 +210,6 @@ goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.Workspa goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/xml.js', ['Blockly.Xml'], ['Blockly.Events', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.dom', 'Blockly.utils.xml']); -goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/zoom_controls.js', ['Blockly.ZoomControls'], ['Blockly.ComponentManager', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.Click', 'Blockly.IPositionable', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('base.js', [], []); From 38374405647c789c4e74eafae77f578e5a92177f Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:27:57 -0700 Subject: [PATCH 387/833] Migrate core/keyboard_nav/marker.js to ES6 const/let --- core/keyboard_nav/marker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index de31d6084..555bf7c97 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -85,7 +85,7 @@ Blockly.Marker.prototype.getCurNode = function() { * @param {Blockly.ASTNode} newNode The new location of the marker. */ Blockly.Marker.prototype.setCurNode = function(newNode) { - var oldNode = this.curNode_; + const oldNode = this.curNode_; this.curNode_ = newNode; if (this.drawer_) { this.drawer_.draw(oldNode, this.curNode_); From 014316431e848ff549352d1f5ba4e491219199a3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 19 Jul 2021 11:28:11 -0700 Subject: [PATCH 388/833] Migrate core/keyboard_nav/marker.js to goog.module --- core/keyboard_nav/marker.js | 21 ++++++++++++--------- tests/deps.js | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 555bf7c97..115a1f861 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.Marker'); +goog.module('Blockly.Marker'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ASTNode'); @@ -23,7 +24,7 @@ goog.requireType('Blockly.blockRendering.MarkerSvg'); * This is used in keyboard navigation to save a location in the Blockly AST. * @constructor */ -Blockly.Marker = function() { +const Marker = function() { /** * The colour of the marker. * @type {?string} @@ -56,7 +57,7 @@ Blockly.Marker = function() { * @param {Blockly.blockRendering.MarkerSvg} drawer The object in charge of * drawing the marker. */ -Blockly.Marker.prototype.setDrawer = function(drawer) { +Marker.prototype.setDrawer = function(drawer) { this.drawer_ = drawer; }; @@ -65,7 +66,7 @@ Blockly.Marker.prototype.setDrawer = function(drawer) { * @return {Blockly.blockRendering.MarkerSvg} The object in charge of drawing * the marker. */ -Blockly.Marker.prototype.getDrawer = function() { +Marker.prototype.getDrawer = function() { return this.drawer_; }; @@ -74,7 +75,7 @@ Blockly.Marker.prototype.getDrawer = function() { * @return {Blockly.ASTNode} The current field, connection, or block the marker * is on. */ -Blockly.Marker.prototype.getCurNode = function() { +Marker.prototype.getCurNode = function() { return this.curNode_; }; @@ -84,7 +85,7 @@ Blockly.Marker.prototype.getCurNode = function() { * output or previous connection on a stack. * @param {Blockly.ASTNode} newNode The new location of the marker. */ -Blockly.Marker.prototype.setCurNode = function(newNode) { +Marker.prototype.setCurNode = function(newNode) { const oldNode = this.curNode_; this.curNode_ = newNode; if (this.drawer_) { @@ -96,7 +97,7 @@ Blockly.Marker.prototype.setCurNode = function(newNode) { * Redraw the current marker. * @package */ -Blockly.Marker.prototype.draw = function() { +Marker.prototype.draw = function() { if (this.drawer_) { this.drawer_.draw(this.curNode_, this.curNode_); } @@ -105,7 +106,7 @@ Blockly.Marker.prototype.draw = function() { /** * Hide the marker SVG. */ -Blockly.Marker.prototype.hide = function() { +Marker.prototype.hide = function() { if (this.drawer_) { this.drawer_.hide(); } @@ -114,8 +115,10 @@ Blockly.Marker.prototype.hide = function() { /** * Dispose of this marker. */ -Blockly.Marker.prototype.dispose = function() { +Marker.prototype.dispose = function() { if (this.getDrawer()) { this.getDrawer().dispose(); } }; + +exports = Marker; diff --git a/tests/deps.js b/tests/deps.js index 759caeae4..8d3102c14 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstan goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode']); +goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); From 50f7293f2d4b16eda5c72cf3e4d9e1c275991d5e Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:34:35 -0700 Subject: [PATCH 389/833] Migrate core/keyboard_nav/marker.js named requires --- core/keyboard_nav/marker.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 115a1f861..28f905949 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -14,9 +14,8 @@ goog.module('Blockly.Marker'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ASTNode'); - -goog.requireType('Blockly.blockRendering.MarkerSvg'); +const ASTNode = goog.require('Blockly.ASTNode'); +const MarkerSvg = goog.requireType('Blockly.blockRendering.MarkerSvg'); /** @@ -33,14 +32,14 @@ const Marker = function() { /** * The current location of the marker. - * @type {Blockly.ASTNode} + * @type {ASTNode} * @private */ this.curNode_ = null; /** * The object in charge of drawing the visual representation of the current node. - * @type {Blockly.blockRendering.MarkerSvg} + * @type {MarkerSvg} * @private */ this.drawer_ = null; @@ -54,7 +53,7 @@ const Marker = function() { /** * Sets the object in charge of drawing the marker. - * @param {Blockly.blockRendering.MarkerSvg} drawer The object in charge of + * @param {MarkerSvg} drawer The object in charge of * drawing the marker. */ Marker.prototype.setDrawer = function(drawer) { @@ -63,7 +62,7 @@ Marker.prototype.setDrawer = function(drawer) { /** * Get the current drawer for the marker. - * @return {Blockly.blockRendering.MarkerSvg} The object in charge of drawing + * @return {MarkerSvg} The object in charge of drawing * the marker. */ Marker.prototype.getDrawer = function() { @@ -72,7 +71,7 @@ Marker.prototype.getDrawer = function() { /** * Gets the current location of the marker. - * @return {Blockly.ASTNode} The current field, connection, or block the marker + * @return {ASTNode} The current field, connection, or block the marker * is on. */ Marker.prototype.getCurNode = function() { @@ -83,7 +82,7 @@ Marker.prototype.getCurNode = function() { * Set the location of the marker and call the update method. * Setting isStack to true will only work if the newLocation is the top most * output or previous connection on a stack. - * @param {Blockly.ASTNode} newNode The new location of the marker. + * @param {ASTNode} newNode The new location of the marker. */ Marker.prototype.setCurNode = function(newNode) { const oldNode = this.curNode_; From 1a83b7584680f48a226d40cc87780d50eeec127c Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 22 Jul 2021 10:34:44 -0700 Subject: [PATCH 390/833] clang-format core/keyboard_nav/marker.js --- core/keyboard_nav/marker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 28f905949..654703f7b 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -38,7 +38,8 @@ const Marker = function() { this.curNode_ = null; /** - * The object in charge of drawing the visual representation of the current node. + * The object in charge of drawing the visual representation of the current + * node. * @type {MarkerSvg} * @private */ From 667048b3f52262e8f1e0ff3c78a0bf411b20be4d Mon Sep 17 00:00:00 2001 From: kozbial Date: Fri, 23 Jul 2021 19:29:17 -0700 Subject: [PATCH 391/833] Add eslint disable and make ASTNode a requireType --- core/keyboard_nav/marker.js | 4 +++- tests/deps.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/keyboard_nav/marker.js b/core/keyboard_nav/marker.js index 654703f7b..4b6f341bb 100644 --- a/core/keyboard_nav/marker.js +++ b/core/keyboard_nav/marker.js @@ -14,7 +14,9 @@ goog.module('Blockly.Marker'); goog.module.declareLegacyNamespace(); -const ASTNode = goog.require('Blockly.ASTNode'); +/* eslint-disable-next-line no-unused-vars */ +const ASTNode = goog.requireType('Blockly.ASTNode'); +/* eslint-disable-next-line no-unused-vars */ const MarkerSvg = goog.requireType('Blockly.blockRendering.MarkerSvg'); diff --git a/tests/deps.js b/tests/deps.js index 8d3102c14..6666e9369 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -105,7 +105,7 @@ goog.addDependency('../../core/internal_constants.js', ['Blockly.internalConstan goog.addDependency('../../core/keyboard_nav/ast_node.js', ['Blockly.ASTNode'], ['Blockly.connectionTypes', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/basic_cursor.js', ['Blockly.BasicCursor'], ['Blockly.ASTNode', 'Blockly.Cursor', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/cursor.js', ['Blockly.Cursor'], ['Blockly.ASTNode', 'Blockly.Marker', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], ['Blockly.ASTNode'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/keyboard_nav/marker.js', ['Blockly.Marker'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/keyboard_nav/tab_navigate_cursor.js', ['Blockly.TabNavigateCursor'], ['Blockly.ASTNode', 'Blockly.BasicCursor', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/marker_manager.js', ['Blockly.MarkerManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/menu.js', ['Blockly.Menu'], ['Blockly.browserEvents', 'Blockly.utils.Coordinate', 'Blockly.utils.KeyCodes', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.style'], {'lang': 'es6', 'module': 'goog'}); From 961254663d1a0347e664638c077af54d3fbc6002 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 28 Jul 2021 11:57:24 -0700 Subject: [PATCH 392/833] Move clipboard functions to a separate namespace --- core/blockly.js | 50 ++---------- core/clipboard.js | 106 ++++++++++++++++++++++++++ core/contextmenu_items.js | 4 +- core/shortcut_items.js | 7 +- tests/deps.js | 7 +- tests/mocha/contextmenu_items_test.js | 10 +-- tests/mocha/keydown_test.js | 2 +- 7 files changed, 129 insertions(+), 57 deletions(-) create mode 100644 core/clipboard.js diff --git a/core/blockly.js b/core/blockly.js index 94f485c99..808c035b0 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -17,6 +17,7 @@ goog.provide('Blockly'); goog.require('Blockly.browserEvents'); +goog.require('Blockly.clipboard'); goog.require('Blockly.ComponentManager'); goog.require('Blockly.connectionTypes'); goog.require('Blockly.constants'); @@ -96,21 +97,21 @@ Blockly.draggingConnections = []; * @type {Element} * @private */ -Blockly.clipboardXml_ = null; +Blockly.clipboardXml_ = Blockly.clipboard.xml; /** * Source of the local clipboard. * @type {Blockly.WorkspaceSvg} * @private */ -Blockly.clipboardSource_ = null; +Blockly.clipboardSource_ = Blockly.clipboard.source; /** * Map of types to type counts for the clipboard object and descendants. * @type {Object} * @private */ -Blockly.clipboardTypeCounts_ = null; +Blockly.clipboardTypeCounts_ = Blockly.clipboard.typeCounts; /** * Cached value for whether 3D is supported. @@ -234,39 +235,14 @@ Blockly.deleteBlock = function(selected) { * @param {!Blockly.ICopyable} toCopy Block or Workspace Comment to be copied. * @package */ -Blockly.copy = function(toCopy) { - var data = toCopy.toCopyData(); - if (data) { - Blockly.clipboardXml_ = data.xml; - Blockly.clipboardSource_ = data.source; - Blockly.clipboardTypeCounts_ = data.typeCounts; - } -}; +Blockly.copy = Blockly.clipboard.copy; /** * Paste a block or workspace comment on to the main workspace. * @return {boolean} True if the paste was successful, false otherwise. * @package */ -Blockly.paste = function() { - if (!Blockly.clipboardXml_) { - return false; - } - // Pasting always pastes to the main workspace, even if the copy - // started in a flyout workspace. - var workspace = Blockly.clipboardSource_; - if (workspace.isFlyout) { - workspace = workspace.targetWorkspace; - } - if (Blockly.clipboardTypeCounts_ && - workspace.isCapacityAvailable(Blockly.clipboardTypeCounts_)) { - Blockly.Events.setGroup(true); - workspace.paste(Blockly.clipboardXml_); - Blockly.Events.setGroup(false); - return true; - } - return false; -}; +Blockly.paste = Blockly.clipboard.paste; /** * Duplicate this block and its children, or a workspace comment. @@ -274,19 +250,7 @@ Blockly.paste = function() { * copied. * @package */ -Blockly.duplicate = function(toDuplicate) { - // Save the clipboard. - var clipboardXml = Blockly.clipboardXml_; - var clipboardSource = Blockly.clipboardSource_; - - // Create a duplicate via a copy/paste operation. - Blockly.copy(toDuplicate); - toDuplicate.workspace.paste(Blockly.clipboardXml_); - - // Restore the clipboard. - Blockly.clipboardXml_ = clipboardXml; - Blockly.clipboardSource_ = clipboardSource; -}; +Blockly.duplicate = Blockly.clipboard.duplicate; /** * Cancel the native context menu, unless the focus is on an HTML input widget. diff --git a/core/clipboard.js b/core/clipboard.js new file mode 100644 index 000000000..887346a58 --- /dev/null +++ b/core/clipboard.js @@ -0,0 +1,106 @@ +/** + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Blockly's internal clipboard for managing copy-paste. + * @author fenichel@google.com (Rachel Fenichel) + */ +'use strict'; + +goog.module('Blockly.clipboard'); +goog.module.declareLegacyNamespace(); + +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const ICopyable = goog.requireType('Blockly.ICopyable'); +/* eslint-disable-next-line no-unused-vars */ +const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); + + +/** + * Contents of the local clipboard. + * @type {Element} + * @private + */ +let xml = null; +exports.xml = xml; + +/** + * Source of the local clipboard. + * @type {WorkspaceSvg} + * @private + */ +let source = null; +exports.source = source; + +/** + * Map of types to type counts for the clipboard object and descendants. + * @type {Object} + * @private + */ +let typeCounts = null; +exports.typeCounts = typeCounts; + +/** + * Copy a block or workspace comment onto the local clipboard. + * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. + * @package + */ +const copy = function(toCopy) { + var data = toCopy.toCopyData(); + if (data) { + xml = data.xml; + source = data.source; + typeCounts = data.typeCounts; + } +}; +exports.copy = copy; + +/** + * Paste a block or workspace comment on to the main workspace. + * @return {boolean} True if the paste was successful, false otherwise. + * @package + */ +const paste = function() { + if (!xml) { + return false; + } + // Pasting always pastes to the main workspace, even if the copy + // started in a flyout workspace. + var workspace = source; + if (workspace.isFlyout) { + workspace = workspace.targetWorkspace; + } + if (typeCounts && workspace.isCapacityAvailable(typeCounts)) { + Events.setGroup(true); + workspace.paste(xml); + Events.setGroup(false); + return true; + } + return false; +}; +exports.paste = paste; + +/** + * Duplicate this block and its children, or a workspace comment. + * @param {!ICopyable} toDuplicate Block or Workspace Comment to be + * copied. + * @package + */ +const duplicate = function(toDuplicate) { + // Save the clipboard. + const oldXml = xml; + const oldSource = source; + + // Create a duplicate via a copy/paste operation. + copy(toDuplicate); + toDuplicate.workspace.paste(xml); + + // Restore the clipboard. + xml = oldXml; + source = oldSource; +}; +exports.duplicate = duplicate; diff --git a/core/contextmenu_items.js b/core/contextmenu_items.js index dffd4a83d..e985a8e5c 100644 --- a/core/contextmenu_items.js +++ b/core/contextmenu_items.js @@ -15,7 +15,7 @@ * @namespace */ goog.provide('Blockly.ContextMenuItems'); - +goog.require('Blockly.clipboard'); /** @suppress {extraRequire} */ goog.require('Blockly.constants'); goog.require('Blockly.ContextMenuRegistry'); @@ -316,7 +316,7 @@ Blockly.ContextMenuItems.registerDuplicate = function() { }, callback: function(/** @type {!Blockly.ContextMenuRegistry.Scope} */ scope) { if (scope.block) { - Blockly.duplicate(scope.block); + Blockly.clipboard.duplicate(scope.block); } }, scopeType: Blockly.ContextMenuRegistry.ScopeType.BLOCK, diff --git a/core/shortcut_items.js b/core/shortcut_items.js index ef1cb07fc..494b64bfe 100644 --- a/core/shortcut_items.js +++ b/core/shortcut_items.js @@ -16,6 +16,7 @@ */ goog.provide('Blockly.ShortcutItems'); +goog.require('Blockly.clipboard'); goog.require('Blockly.Gesture'); goog.require('Blockly.ShortcutRegistry'); goog.require('Blockly.utils.KeyCodes'); @@ -104,7 +105,7 @@ Blockly.ShortcutItems.registerCopy = function() { // an error due to the lack of a selection. e.preventDefault(); Blockly.hideChaff(); - Blockly.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); + Blockly.clipboard.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); return true; } }; @@ -137,7 +138,7 @@ Blockly.ShortcutItems.registerCut = function() { !Blockly.selected.workspace.isFlyout; }, callback: function() { - Blockly.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); + Blockly.clipboard.copy(/** @type {!Blockly.ICopyable} */ (Blockly.selected)); Blockly.deleteBlock(/** @type {!Blockly.BlockSvg} */ (Blockly.selected)); return true; } @@ -167,7 +168,7 @@ Blockly.ShortcutItems.registerPaste = function() { return !workspace.options.readOnly && !Blockly.Gesture.inProgress(); }, callback: function() { - return Blockly.paste(); + return Blockly.clipboard.paste(); } }; diff --git a/tests/deps.js b/tests/deps.js index b28f86da2..44b852995 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -12,11 +12,12 @@ goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'] goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.clipboard', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']); goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']); goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']); goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/clipboard.js', ['Blockly.clipboard'], ['Blockly.Events'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation'], {'lang': 'es6', 'module': 'goog'}); @@ -25,7 +26,7 @@ goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Bl goog.addDependency('../../core/connection_types.js', ['Blockly.connectionTypes'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/constants.js', ['Blockly.constants'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/contextmenu.js', ['Blockly.ContextMenu'], ['Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Menu', 'Blockly.MenuItem', 'Blockly.Msg', 'Blockly.WidgetDiv', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.userAgent']); -goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); +goog.addDependency('../../core/contextmenu_items.js', ['Blockly.ContextMenuItems'], ['Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.clipboard', 'Blockly.constants', 'Blockly.inputTypes'], {'lang': 'es5'}); goog.addDependency('../../core/contextmenu_registry.js', ['Blockly.ContextMenuRegistry'], [], {'lang': 'es5'}); goog.addDependency('../../core/css.js', ['Blockly.Css'], [], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/delete_area.js', ['Blockly.DeleteArea'], ['Blockly.BlockSvg', 'Blockly.DragTarget', 'Blockly.IDeleteArea', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); @@ -159,7 +160,7 @@ goog.addDependency('../../core/renderers/zelos/path_object.js', ['Blockly.zelos. goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Renderer'], ['Blockly.InsertionMarkerManager', 'Blockly.blockRendering', 'Blockly.blockRendering.Renderer', 'Blockly.connectionTypes', 'Blockly.utils.object', 'Blockly.zelos.ConstantProvider', 'Blockly.zelos.Drawer', 'Blockly.zelos.MarkerSvg', 'Blockly.zelos.PathObject', 'Blockly.zelos.RenderInfo']); goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); +goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.clipboard', 'Blockly.utils.KeyCodes']); goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); diff --git a/tests/mocha/contextmenu_items_test.js b/tests/mocha/contextmenu_items_test.js index 62dd6f9ea..0d69fa77e 100644 --- a/tests/mocha/contextmenu_items_test.js +++ b/tests/mocha/contextmenu_items_test.js @@ -17,11 +17,11 @@ suite('Context Menu Items', function() { Blockly.ContextMenuItems.registerDefaultOptions(); this.registry = Blockly.ContextMenuRegistry.registry; }); - + teardown(function() { sharedTestTeardown.call(this); }); - + suite('Workspace Items', function() { setup(function() { this.scope = {workspace: this.workspace}; @@ -328,12 +328,12 @@ suite('Context Menu Items', function() { }); test('Calls duplicate', function() { - var stub = sinon.stub(Blockly, 'duplicate'); + var spy = sinon.spy(Blockly.clipboard, 'duplicate'); this.duplicateOption.callback(this.scope); - sinon.assert.calledOnce(stub); - sinon.assert.calledWith(stub, this.block); + sinon.assert.calledOnce(spy); + sinon.assert.calledWith(spy, this.block); }); test('Has correct label', function() { diff --git a/tests/mocha/keydown_test.js b/tests/mocha/keydown_test.js index aec646111..22fdbf96e 100644 --- a/tests/mocha/keydown_test.js +++ b/tests/mocha/keydown_test.js @@ -93,7 +93,7 @@ suite('Key Down', function() { suite('Copy', function() { setup(function() { setSelectedBlock(this.workspace); - this.copySpy = sinon.spy(Blockly, 'copy'); + this.copySpy = sinon.spy(Blockly.clipboard, 'copy'); this.hideChaffSpy = sinon.spy(Blockly, 'hideChaff'); }); var testCases = [ From 311373230fed2adb4cdfd103a87d412902f574e3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 28 Jul 2021 14:48:08 -0700 Subject: [PATCH 393/833] Fix help log --- scripts/goog_module/convert-file.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index ebf791d3b..a412a7933 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -312,8 +312,8 @@ help() { echo "" echo "Usage: $0 [-h] [-c |-s ]" echo " -h Display help and exit" - echo " -c Create a commit for the specified step [2-4]" - echo " -s Run the specified step [1-4]" + echo " -c Create a commit for the specified step [1-4]" + echo " -s Run the specified step [2-4]" } ####################################### From 87a714fff8d10073f813a9afce8aceda6060c2f9 Mon Sep 17 00:00:00 2001 From: kozbial Date: Wed, 28 Jul 2021 14:47:25 -0700 Subject: [PATCH 394/833] Add handling for modules that are not leaf nodes --- scripts/goog_module/convert-file.sh | 85 ++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index a412a7933..1c5b92fc8 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -125,6 +125,59 @@ commit-step() { success "created commit with message: \"${message}\"" } +####################################### +# Extracts a list of properties that are accessed on the specified module name. +# Excludes any matches +# Arguments: +# The module name to find properties accessed for. +# The modules required by the specified module as a single string. +# The filepath to extract requires from. +# Optional: The top-level module. +# Outputs: +# Writes list of properties to stdout as items separated by spaces. +####################################### +getPropertiesAccessed() { + local module_name="$1" + local requires="$2" + local filepath="$3" + local top_module_name="$4" + # Get any strings that follow "$module_name.", excluding matches for + # "$module_name.prototype" and remove list item duplicates (sort -u). + local properties_accessed=$(perl -nle 'print $& while m{(?<='"${module_name}"'\.)(?!prototype)\w+}g' "${filepath}" | sort -u) + + # Get a list of any requires that are a child of $module_name. + # Ex: Blockly.utils.dom is a child of Blockly.utils, this would return "dom" + local requires_overlap=$(echo "${requires}" | perl -nle 'print $& while m{(?<='"${module_name}"'\.)\w+}g') + # Detect if there was any overlap. + if [[ -n "${requires_overlap}" ]]; then + while read -r requires_overlap_prop; do + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') + done <<<"${requires_overlap}" + fi + + # Fix formatting (remove extra whitespace) and delimit the list with spaces. + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) + + echo "${properties_accessed}" +} + +####################################### +# Extracts a list of requires defined in the file in the form of a single string +# of items separated by newlines. +# Arguments: +# The filepath to extract requires from. +# Outputs: +# Writes list of requires to stdout as items separated by newlines. +####################################### +getRequires() { + local filepath="$1" + # Extracts all strings that start with goog.require(' or goog.requireType(' + # up until the ending single quote. + # Ex: "goog.require('Blockly.utils')" would extract "Blockly.utils" + local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + echo "${requires}" +} + ####################################### # Runs step 2 of the automated conversion. # Arguments: @@ -166,8 +219,18 @@ step2 () { # No top level class. inf 'Updating top-level property declarations...' perl -pi -e 's/^'"${module_name}"'\.([^ ]+) =/const \1 =/g' "${filepath}" + + # Extract specific properties accessed so that properties from requires that + # are children of the module aren't changed. + # Ex: The module Blockly.utils shouldn't update Blockly.utils.dom (since it is + # a require from another module. + local requires=$(getRequires "${filepath}") + local properties_accessed=$(getPropertiesAccessed "${module_name}" "${requires}" "${filepath}") inf "Updating local references to module..." - perl -pi -e 's/'"${module_name}"'\.([^ ]+)/\1/g' "${filepath}" + for property in $(echo "${properties_accessed}"); do + inf "Updating references of ${module_name}.${property} to ${property}..." + perl -pi -e 's/'"${module_name}"'\.'"${property}"'(?!\w)/'"${property}"'/g' "${filepath}" + done npm run build:deps success "Completed automation for step 2. Please manually review and add exports for non-private top-level functions." @@ -187,7 +250,7 @@ step3() { fi inf "Extracted module name \"${module_name}\"" - local requires=$(perl -nle 'print $& while m{(?:(?<=^goog.require\('\'')|(?<=^goog.requireType\('\''))[^'\'']+}g' "${filepath}") + local requires=$(getRequires "${filepath}") # Process each require echo "${requires}" | while read -r require; do @@ -205,23 +268,17 @@ step3() { # Parse property access of module local direct_access_count=$(perl -nle 'print $& while m{'"${require}"'[^\.'\'']}g' "${filepath}" | wc -l) - local properties_accessed=$(perl -nle 'print $& while m{(?<='"${require}"'\.)(?!prototype)\w+}g' "${filepath}" | sort -u) + local properties_accessed=$(getPropertiesAccessed "${require}" "${requires}" "${filepath}") - # Detect requires overlap - # (ex: Blockly.utils require and Blockly.utils.dom also in requires) - local requires_overlap=$(echo "${requires}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') - if [[ -n "${requires_overlap}" ]]; then - while read -r requires_overlap_prop; do - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') - done <<<"${requires_overlap}" - fi - # Detect module name overlap - # (ex: Blockly require and Blockly.ContextMenuItems module being converted) + # Remove $module_name in case it is a child of $require. + # Ex: Blockly.utils.dom would be a child of Blockly, module_overlap would be + # "utils" local module_overlap=$(echo "${module_name}" | perl -nle 'print $& while m{(?<='"${require}"'\.)\w+}g') if [[ -n "${module_overlap}" ]]; then properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${module_overlap}"'//g') + # Trim any extra whitespace created. + properties_accessed=$(echo "${properties_accessed}" | xargs) fi - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/\s+/ /g' | xargs) if [[ -n "${properties_accessed}" ]]; then local comma_properties=$(echo "${properties_accessed}" | perl -pe 's/\s+/, /g' | perl -pe 's/, $//') From 8372ecb2125e75e35ec532fa40b46fa4f10fb34d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:05:40 -0700 Subject: [PATCH 395/833] Include full namespace in error message --- core/registry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/registry.js b/core/registry.js index 1be9b2a2b..5752702ae 100644 --- a/core/registry.js +++ b/core/registry.js @@ -137,7 +137,7 @@ const register = function(type, name, registryItem, opt_allowOverrides) { String(type).trim() == '') { throw Error( 'Invalid type "' + type + '". The type must be a' + - ' non-empty string or a Type.'); + ' non-empty string or a Blockly.registry.Type.'); } type = String(type).toLowerCase(); From 0f193f1f5a9c502824fb7987f494062ee39ca1cf Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:17:57 -0700 Subject: [PATCH 396/833] Migrate core/trashcan.js to ES6 const/let --- core/trashcan.js | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 619299b21..dea20acd2 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -80,7 +80,7 @@ Blockly.Trashcan = function(workspace) { return; } // Create flyout options. - var flyoutWorkspaceOptions = new Blockly.Options( + const flyoutWorkspaceOptions = new Blockly.Options( /** @type {!Blockly.BlocklyOptions} */ ({ 'scrollbars': true, @@ -98,7 +98,7 @@ Blockly.Trashcan = function(workspace) { flyoutWorkspaceOptions.toolboxPosition = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.TOP ? Blockly.utils.toolbox.Position.BOTTOM : Blockly.utils.toolbox.Position.TOP; - var HorizontalFlyout = Blockly.registry.getClassFromOptions( + const HorizontalFlyout = Blockly.registry.getClassFromOptions( Blockly.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.workspace_.options, true); this.flyout = new HorizontalFlyout(flyoutWorkspaceOptions); @@ -106,7 +106,7 @@ Blockly.Trashcan = function(workspace) { flyoutWorkspaceOptions.toolboxPosition = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.RIGHT ? Blockly.utils.toolbox.Position.LEFT : Blockly.utils.toolbox.Position.RIGHT; - var VerticalFlyout = Blockly.registry.getClassFromOptions( + const VerticalFlyout = Blockly.registry.getClassFromOptions( Blockly.registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.workspace_.options, true); this.flyout = new VerticalFlyout(flyoutWorkspaceOptions); @@ -300,8 +300,8 @@ Blockly.Trashcan.prototype.createDom = function() { this.svgGroup_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.G, {'class': 'blocklyTrash'}, null); - var clip; - var rnd = String(Math.random()).substring(2); + let clip; + const rnd = String(Math.random()).substring(2); clip = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.CLIPPATH, {'id': 'blocklyTrashBodyClipPath' + rnd}, @@ -314,7 +314,7 @@ Blockly.Trashcan.prototype.createDom = function() { 'y': this.LID_HEIGHT_ }, clip); - var body = Blockly.utils.dom.createSvgElement( + const body = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, 'x': -this.SPRITE_LEFT_, @@ -427,7 +427,7 @@ Blockly.Trashcan.prototype.openFlyout = function() { if (this.contentsIsOpen()) { return; } - var xml = this.contents_.map(Blockly.Xml.textToDom); + const xml = this.contents_.map(Blockly.Xml.textToDom); this.flyout.show(xml); this.fireUiEvent_(true); }; @@ -483,20 +483,20 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { return; } - var cornerPosition = + const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - var height = this.BODY_HEIGHT_ + this.LID_HEIGHT_; - var startRect = Blockly.uiPosition.getStartPositionRect( + const height = this.BODY_HEIGHT_ + this.LID_HEIGHT_; + const startRect = Blockly.uiPosition.getStartPositionRect( cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); - var verticalPosition = cornerPosition.vertical; - var bumpDirection = + const verticalPosition = cornerPosition.vertical; + const bumpDirection = verticalPosition === Blockly.uiPosition.verticalPosition.TOP ? Blockly.uiPosition.bumpDirection.DOWN : Blockly.uiPosition.bumpDirection.UP; - var positionRect = Blockly.uiPosition.bumpPositionRect( + const positionRect = Blockly.uiPosition.bumpPositionRect( startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); this.top_ = positionRect.top; @@ -512,8 +512,8 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { * bounding box should be ignored by other UI elements. */ Blockly.Trashcan.prototype.getBoundingRectangle = function() { - var bottom = this.top_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; - var right = this.left_ + this.WIDTH_; + const bottom = this.top_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; + const right = this.left_ + this.WIDTH_; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -528,12 +528,12 @@ Blockly.Trashcan.prototype.getClientRect = function() { return null; } - var trashRect = this.svgGroup_.getBoundingClientRect(); - var top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; - var bottom = top + this.LID_HEIGHT_ + this.BODY_HEIGHT_ + + const trashRect = this.svgGroup_.getBoundingClientRect(); + const top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; + const bottom = top + this.LID_HEIGHT_ + this.BODY_HEIGHT_ + 2 * this.MARGIN_HOTSPOT_; - var left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; - var right = left + this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; + const left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; + const right = left + this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; return new Blockly.utils.Rect(top, bottom, left, right); }; @@ -588,18 +588,18 @@ Blockly.Trashcan.prototype.setLidOpen = function(state) { * @private */ Blockly.Trashcan.prototype.animateLid_ = function() { - var frames = Blockly.Trashcan.ANIMATION_FRAMES_; + const frames = Blockly.Trashcan.ANIMATION_FRAMES_; - var delta = 1 / (frames + 1); + const delta = 1 / (frames + 1); this.lidOpen_ += this.isLidOpen ? delta : -delta; this.lidOpen_ = Math.min(Math.max(this.lidOpen_, this.minOpenness_), 1); this.setLidAngle_(this.lidOpen_ * Blockly.Trashcan.MAX_LID_ANGLE_); - var minOpacity = Blockly.Trashcan.OPACITY_MIN_; - var maxOpacity = Blockly.Trashcan.OPACITY_MAX_; + const minOpacity = Blockly.Trashcan.OPACITY_MIN_; + const maxOpacity = Blockly.Trashcan.OPACITY_MAX_; // Linear interpolation between min and max. - var opacity = minOpacity + this.lidOpen_ * (maxOpacity - minOpacity); + const opacity = minOpacity + this.lidOpen_ * (maxOpacity - minOpacity); this.svgGroup_.style.opacity = opacity; if (this.lidOpen_ > this.minOpenness_ && this.lidOpen_ < 1) { @@ -614,7 +614,7 @@ Blockly.Trashcan.prototype.animateLid_ = function() { * @private */ Blockly.Trashcan.prototype.setLidAngle_ = function(lidAngle) { - var openAtRight = + const openAtRight = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.RIGHT || (this.workspace_.horizontalLayout && this.workspace_.RTL); this.svgLid_.setAttribute('transform', 'rotate(' + @@ -661,7 +661,7 @@ Blockly.Trashcan.prototype.click = function() { * @private */ Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { - var uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( + const uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( trashcanOpen,this.workspace_.id); Blockly.Events.fire(uiEvent); }; @@ -710,7 +710,7 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { // Must check that the tagName exists since oldXml can be a DocumentFragment. if (event.type == Blockly.Events.BLOCK_DELETE && event.oldXml.tagName && event.oldXml.tagName.toLowerCase() != 'shadow') { - var cleanedXML = this.cleanBlockXML_(event.oldXml); + const cleanedXML = this.cleanBlockXML_(event.oldXml); if (this.contents_.indexOf(cleanedXML) != -1) { return; } @@ -734,8 +734,8 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { * @private */ Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { - var xmlBlock = xml.cloneNode(true); - var node = xmlBlock; + const xmlBlock = xml.cloneNode(true); + let node = xmlBlock; while (node) { // Things like text inside tags are still treated as nodes, but they // don't have attributes (or the removeAttribute function) so we can @@ -753,7 +753,7 @@ Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { } // Try to go down the tree - var nextNode = node.firstChild || node.nextSibling; + let nextNode = node.firstChild || node.nextSibling; // If we can't go down, try to go back up the tree. if (!nextNode) { nextNode = node.parentNode; From 1d9c9359f959d931668ef625ad0a7bdb36fc74cb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:30:44 -0700 Subject: [PATCH 397/833] Migrate core/variable_map.js to ES6 const/let --- core/variable_map.js | 98 ++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index 34fa926ec..3cbe5d561 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -66,9 +66,9 @@ Blockly.VariableMap.prototype.clear = function() { * @package */ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { - var type = variable.type; - var conflictVar = this.getVariable(newName, type); - var blocks = this.workspace.getAllBlocks(false); + const type = variable.type; + const conflictVar = this.getVariable(newName, type); + const blocks = this.workspace.getAllBlocks(false); Blockly.Events.setGroup(true); try { // The IDs may match if the rename is a simple case change (name1 -> Name1). @@ -89,7 +89,7 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { * @param {string} newName New variable name. */ Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { - var variable = this.getVariableById(id); + const variable = this.getVariableById(id); if (!variable) { throw Error('Tried to rename a variable that didn\'t exist. ID: ' + id); } @@ -111,7 +111,7 @@ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( variable, newName)); variable.name = newName; - for (var i = 0; i < blocks.length; i++) { + for (let i = 0; i < blocks.length; i++) { blocks[i].updateVarName(variable); } }; @@ -131,8 +131,8 @@ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, */ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, newName, conflictVar, blocks) { - var type = variable.type; - var oldCase = conflictVar.name; + const type = variable.type; + const oldCase = conflictVar.name; if (newName != oldCase) { // Simple rename to change the case and update references. @@ -141,7 +141,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, // These blocks now refer to a different variable. // These will fire change events. - for (var i = 0; i < blocks.length; i++) { + for (let i = 0; i < blocks.length; i++) { blocks[i].renameVarById(variable.getId(), conflictVar.getId()); } @@ -149,8 +149,8 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( variable)); // And remove it from the list. - var variableList = this.getVariablesOfType(type); - var variableIndex = variableList.indexOf(variable); + const variableList = this.getVariablesOfType(type); + const variableIndex = variableList.indexOf(variable); this.variableMap_[type].splice(variableIndex, 1); }; @@ -170,7 +170,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, */ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { - var variable = this.getVariable(name, opt_type); + let variable = this.getVariable(name, opt_type); if (variable) { if (opt_id && variable.getId() != opt_id) { throw Error('Variable "' + name + '" is already in use and its id is "' + @@ -183,11 +183,11 @@ Blockly.VariableMap.prototype.createVariable = function(name, if (opt_id && this.getVariableById(opt_id)) { throw Error('Variable id, "' + opt_id + '", is already in use.'); } - var id = opt_id || Blockly.utils.genUid(); - var type = opt_type || ''; + const id = opt_id || Blockly.utils.genUid(); + const type = opt_type || ''; variable = new Blockly.VariableModel(this.workspace, name, type, id); - var variables = this.variableMap_[type] || []; + const variables = this.variableMap_[type] || []; variables.push(variable); // Delete the list of variables of this type, and re-add it so that // the most recent addition is at the end. @@ -205,8 +205,8 @@ Blockly.VariableMap.prototype.createVariable = function(name, * @param {!Blockly.VariableModel} variable Variable to delete. */ Blockly.VariableMap.prototype.deleteVariable = function(variable) { - var variableList = this.variableMap_[variable.type]; - for (var i = 0, tempVar; (tempVar = variableList[i]); i++) { + const variableList = this.variableMap_[variable.type]; + for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( @@ -222,16 +222,16 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) { * @param {string} id ID of variable to delete. */ Blockly.VariableMap.prototype.deleteVariableById = function(id) { - var variable = this.getVariableById(id); + const variable = this.getVariableById(id); if (variable) { // Check whether this variable is a function parameter before deleting. - var variableName = variable.name; - var uses = this.getVariableUsesById(id); - for (var i = 0, block; (block = uses[i]); i++) { + const variableName = variable.name; + const uses = this.getVariableUsesById(id); + for (let i = 0, block; (block = uses[i]); i++) { if (block.type == 'procedures_defnoreturn' || block.type == 'procedures_defreturn') { - var procedureName = block.getFieldValue('NAME'); - var deleteText = Blockly.Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. + const procedureName = block.getFieldValue('NAME'); + const deleteText = Blockly.Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. replace('%1', variableName). replace('%2', procedureName); Blockly.alert(deleteText); @@ -239,10 +239,10 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { } } - var map = this; + const map = this; if (uses.length > 1) { // Confirm before deleting multiple blocks. - var confirmText = Blockly.Msg['DELETE_VARIABLE_CONFIRMATION']. + const confirmText = Blockly.Msg['DELETE_VARIABLE_CONFIRMATION']. replace('%1', String(uses.length)). replace('%2', variableName); Blockly.confirm(confirmText, @@ -269,12 +269,12 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { */ Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, uses) { - var existingGroup = Blockly.Events.getGroup(); + const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { Blockly.Events.setGroup(true); } try { - for (var i = 0; i < uses.length; i++) { + for (let i = 0; i < uses.length; i++) { uses[i].dispose(true); } this.deleteVariable(variable); @@ -297,10 +297,10 @@ Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, * it was not found. */ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { - var type = opt_type || ''; - var list = this.variableMap_[type]; + const type = opt_type || ''; + const list = this.variableMap_[type]; if (list) { - for (var j = 0, variable; (variable = list[j]); j++) { + for (let j = 0, variable; (variable = list[j]); j++) { if (Blockly.Names.equals(variable.name, name)) { return variable; } @@ -315,10 +315,10 @@ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { * @return {?Blockly.VariableModel} The variable with the given ID. */ Blockly.VariableMap.prototype.getVariableById = function(id) { - var keys = Object.keys(this.variableMap_); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - for (var j = 0, variable; (variable = this.variableMap_[key][j]); j++) { + const keys = Object.keys(this.variableMap_); + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + for (let j = 0, variable; (variable = this.variableMap_[key][j]); j++) { if (variable.getId() == id) { return variable; } @@ -336,7 +336,7 @@ Blockly.VariableMap.prototype.getVariableById = function(id) { */ Blockly.VariableMap.prototype.getVariablesOfType = function(type) { type = type || ''; - var variable_list = this.variableMap_[type]; + const variable_list = this.variableMap_[type]; if (variable_list) { return variable_list.slice(); } @@ -353,15 +353,15 @@ Blockly.VariableMap.prototype.getVariablesOfType = function(type) { * @package */ Blockly.VariableMap.prototype.getVariableTypes = function(ws) { - var variableMap = {}; + const variableMap = {}; Blockly.utils.object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { Blockly.utils.object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_); } - var types = Object.keys(variableMap); - var hasEmpty = false; - for (var i = 0; i < types.length; i++) { + const types = Object.keys(variableMap); + let hasEmpty = false; + for (let i = 0; i < types.length; i++) { if (types[i] == '') { hasEmpty = true; } @@ -377,8 +377,8 @@ Blockly.VariableMap.prototype.getVariableTypes = function(ws) { * @return {!Array} List of variable models. */ Blockly.VariableMap.prototype.getAllVariables = function() { - var all_variables = []; - for (var key in this.variableMap_) { + let all_variables = []; + for (const key in this.variableMap_) { all_variables = all_variables.concat(this.variableMap_[key]); } return all_variables; @@ -389,10 +389,10 @@ Blockly.VariableMap.prototype.getAllVariables = function() { * @return {!Array} All of the variable names of all types. */ Blockly.VariableMap.prototype.getAllVariableNames = function() { - var allNames = []; - for (var key in this.variableMap_) { - var variables = this.variableMap_[key]; - for (var i = 0, variable; (variable = variables[i]); i++) { + const allNames = []; + for (const key in this.variableMap_) { + const variables = this.variableMap_[key]; + for (let i = 0, variable; (variable = variables[i]); i++) { allNames.push(variable.name); } } @@ -405,13 +405,13 @@ Blockly.VariableMap.prototype.getAllVariableNames = function() { * @return {!Array} Array of block usages. */ Blockly.VariableMap.prototype.getVariableUsesById = function(id) { - var uses = []; - var blocks = this.workspace.getAllBlocks(false); + const uses = []; + const blocks = this.workspace.getAllBlocks(false); // Iterate through every block and check the name. - for (var i = 0; i < blocks.length; i++) { - var blockVariables = blocks[i].getVarModels(); + for (let i = 0; i < blocks.length; i++) { + const blockVariables = blocks[i].getVarModels(); if (blockVariables) { - for (var j = 0; j < blockVariables.length; j++) { + for (let j = 0; j < blockVariables.length; j++) { if (blockVariables[j].getId() == id) { uses.push(blocks[i]); } From 959d976723edc29c9caecfdb648c7975b0d39f64 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:34:37 -0700 Subject: [PATCH 398/833] Migrate core/variable_map.js to goog.module --- core/variable_map.js | 39 +++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index 3cbe5d561..22eb11c9c 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VariableMap'); +goog.module('Blockly.VariableMap'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -33,7 +34,7 @@ goog.requireType('Blockly.Workspace'); * @param {!Blockly.Workspace} workspace The workspace this map belongs to. * @constructor */ -Blockly.VariableMap = function(workspace) { +const VariableMap = function(workspace) { /** * A map from variable type to list of variable names. The lists contain all * of the named variables in the workspace, including variables @@ -53,7 +54,7 @@ Blockly.VariableMap = function(workspace) { /** * Clear the variable map. */ -Blockly.VariableMap.prototype.clear = function() { +VariableMap.prototype.clear = function() { this.variableMap_ = Object.create(null); }; @@ -65,7 +66,7 @@ Blockly.VariableMap.prototype.clear = function() { * @param {string} newName New variable name. * @package */ -Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { +VariableMap.prototype.renameVariable = function(variable, newName) { const type = variable.type; const conflictVar = this.getVariable(newName, type); const blocks = this.workspace.getAllBlocks(false); @@ -88,7 +89,7 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) { * @param {string} id ID of the variable to rename. * @param {string} newName New variable name. */ -Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { +VariableMap.prototype.renameVariableById = function(id, newName) { const variable = this.getVariableById(id); if (!variable) { throw Error('Tried to rename a variable that didn\'t exist. ID: ' + id); @@ -106,7 +107,7 @@ Blockly.VariableMap.prototype.renameVariableById = function(id, newName) { * workspace. * @private */ -Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, +VariableMap.prototype.renameVariableAndUses_ = function(variable, newName, blocks) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( variable, newName)); @@ -129,7 +130,7 @@ Blockly.VariableMap.prototype.renameVariableAndUses_ = function(variable, * workspace. * @private */ -Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, +VariableMap.prototype.renameVariableWithConflict_ = function(variable, newName, conflictVar, blocks) { const type = variable.type; const oldCase = conflictVar.name; @@ -168,7 +169,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable, * a UUID. * @return {!Blockly.VariableModel} The newly created variable. */ -Blockly.VariableMap.prototype.createVariable = function(name, +VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { let variable = this.getVariable(name, opt_type); if (variable) { @@ -204,7 +205,7 @@ Blockly.VariableMap.prototype.createVariable = function(name, * Delete a variable. * @param {!Blockly.VariableModel} variable Variable to delete. */ -Blockly.VariableMap.prototype.deleteVariable = function(variable) { +VariableMap.prototype.deleteVariable = function(variable) { const variableList = this.variableMap_[variable.type]; for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { @@ -221,7 +222,7 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) { * workspace. May prompt the user for confirmation. * @param {string} id ID of variable to delete. */ -Blockly.VariableMap.prototype.deleteVariableById = function(id) { +VariableMap.prototype.deleteVariableById = function(id) { const variable = this.getVariableById(id); if (variable) { // Check whether this variable is a function parameter before deleting. @@ -267,7 +268,7 @@ Blockly.VariableMap.prototype.deleteVariableById = function(id) { * @param {!Array} uses An array of uses of the variable. * @package */ -Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, +VariableMap.prototype.deleteVariableInternal = function(variable, uses) { const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { @@ -296,7 +297,7 @@ Blockly.VariableMap.prototype.deleteVariableInternal = function(variable, * @return {?Blockly.VariableModel} The variable with the given name, or null if * it was not found. */ -Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { +VariableMap.prototype.getVariable = function(name, opt_type) { const type = opt_type || ''; const list = this.variableMap_[type]; if (list) { @@ -314,7 +315,7 @@ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) { * @param {string} id The ID to check for. * @return {?Blockly.VariableModel} The variable with the given ID. */ -Blockly.VariableMap.prototype.getVariableById = function(id) { +VariableMap.prototype.getVariableById = function(id) { const keys = Object.keys(this.variableMap_); for (let i = 0; i < keys.length; i++) { const key = keys[i]; @@ -334,7 +335,7 @@ Blockly.VariableMap.prototype.getVariableById = function(id) { * @return {!Array} The sought after variables of the * passed in type. An empty array if none are found. */ -Blockly.VariableMap.prototype.getVariablesOfType = function(type) { +VariableMap.prototype.getVariablesOfType = function(type) { type = type || ''; const variable_list = this.variableMap_[type]; if (variable_list) { @@ -352,7 +353,7 @@ Blockly.VariableMap.prototype.getVariablesOfType = function(type) { * @return {!Array} List of variable types. * @package */ -Blockly.VariableMap.prototype.getVariableTypes = function(ws) { +VariableMap.prototype.getVariableTypes = function(ws) { const variableMap = {}; Blockly.utils.object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { @@ -376,7 +377,7 @@ Blockly.VariableMap.prototype.getVariableTypes = function(ws) { * Return all variables of all types. * @return {!Array} List of variable models. */ -Blockly.VariableMap.prototype.getAllVariables = function() { +VariableMap.prototype.getAllVariables = function() { let all_variables = []; for (const key in this.variableMap_) { all_variables = all_variables.concat(this.variableMap_[key]); @@ -388,7 +389,7 @@ Blockly.VariableMap.prototype.getAllVariables = function() { * Returns all of the variable names of all types. * @return {!Array} All of the variable names of all types. */ -Blockly.VariableMap.prototype.getAllVariableNames = function() { +VariableMap.prototype.getAllVariableNames = function() { const allNames = []; for (const key in this.variableMap_) { const variables = this.variableMap_[key]; @@ -404,7 +405,7 @@ Blockly.VariableMap.prototype.getAllVariableNames = function() { * @param {string} id ID of the variable to find. * @return {!Array} Array of block usages. */ -Blockly.VariableMap.prototype.getVariableUsesById = function(id) { +VariableMap.prototype.getVariableUsesById = function(id) { const uses = []; const blocks = this.workspace.getAllBlocks(false); // Iterate through every block and check the name. @@ -420,3 +421,5 @@ Blockly.VariableMap.prototype.getVariableUsesById = function(id) { } return uses; }; + +exports = VariableMap; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..d4217d539 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -195,7 +195,7 @@ goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); -goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); +goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); From 9847b8c027c6581246616d6554eb1e6c541eb6fc Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:39:58 -0700 Subject: [PATCH 399/833] Migrate core/variable_map.js to named requires --- core/variable_map.js | 86 ++++++++++++++++++++++---------------------- tests/deps.js | 2 +- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index 22eb11c9c..e2c371149 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -13,25 +13,27 @@ goog.module('Blockly.VariableMap'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Block = goog.requireType('Blockly.Block'); +const Events = goog.require('Blockly.Events'); +const Msg = goog.require('Blockly.Msg'); +const Names = goog.require('Blockly.Names'); +const VariableModel = goog.require('Blockly.VariableModel'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const object = goog.require('Blockly.utils.object'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarDelete'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarRename'); -goog.require('Blockly.Msg'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Block'); -goog.requireType('Blockly.VariableModel'); -goog.requireType('Blockly.Workspace'); /** * Class for a variable map. This contains a dictionary data structure with * variable types as keys and lists of variables as values. The list of * variables are the type indicated by the key. - * @param {!Blockly.Workspace} workspace The workspace this map belongs to. + * @param {!Workspace} workspace The workspace this map belongs to. * @constructor */ const VariableMap = function(workspace) { @@ -39,14 +41,14 @@ const VariableMap = function(workspace) { * A map from variable type to list of variable names. The lists contain all * of the named variables in the workspace, including variables * that are not currently in use. - * @type {!Object>} + * @type {!Object>} * @private */ this.variableMap_ = Object.create(null); /** * The workspace this map belongs to. - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; }; @@ -62,7 +64,7 @@ VariableMap.prototype.clear = function() { /** * Rename the given variable by updating its name in the variable map. - * @param {!Blockly.VariableModel} variable Variable to rename. + * @param {!VariableModel} variable Variable to rename. * @param {string} newName New variable name. * @package */ @@ -70,7 +72,7 @@ VariableMap.prototype.renameVariable = function(variable, newName) { const type = variable.type; const conflictVar = this.getVariable(newName, type); const blocks = this.workspace.getAllBlocks(false); - Blockly.Events.setGroup(true); + Events.setGroup(true); try { // The IDs may match if the rename is a simple case change (name1 -> Name1). if (!conflictVar || conflictVar.getId() == variable.getId()) { @@ -79,7 +81,7 @@ VariableMap.prototype.renameVariable = function(variable, newName) { this.renameVariableWithConflict_(variable, newName, conflictVar, blocks); } } finally { - Blockly.Events.setGroup(false); + Events.setGroup(false); } }; @@ -101,15 +103,15 @@ VariableMap.prototype.renameVariableById = function(id, newName) { /** * Update the name of the given variable and refresh all references to it. * The new name must not conflict with any existing variable names. - * @param {!Blockly.VariableModel} variable Variable to rename. + * @param {!VariableModel} variable Variable to rename. * @param {string} newName New variable name. - * @param {!Array} blocks The list of all blocks in the + * @param {!Array} blocks The list of all blocks in the * workspace. * @private */ VariableMap.prototype.renameVariableAndUses_ = function(variable, newName, blocks) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_RENAME))( + Events.fire(new (Events.get(Events.VAR_RENAME))( variable, newName)); variable.name = newName; for (let i = 0; i < blocks.length; i++) { @@ -122,11 +124,11 @@ VariableMap.prototype.renameVariableAndUses_ = function(variable, * variable. The two variables are coalesced into a single variable with the ID * of the existing variable that was already using newName. * Refresh all references to the variable. - * @param {!Blockly.VariableModel} variable Variable to rename. + * @param {!VariableModel} variable Variable to rename. * @param {string} newName New variable name. - * @param {!Blockly.VariableModel} conflictVar The variable that was already + * @param {!VariableModel} conflictVar The variable that was already * using newName. - * @param {!Array} blocks The list of all blocks in the + * @param {!Array} blocks The list of all blocks in the * workspace. * @private */ @@ -147,7 +149,7 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, } // Finally delete the original variable, which is now unreferenced. - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( + Events.fire(new (Events.get(Events.VAR_DELETE))( variable)); // And remove it from the list. const variableList = this.getVariablesOfType(type); @@ -167,7 +169,7 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, * their type. This will default to '' which is a specific type. * @param {?string=} opt_id The unique ID of the variable. This will default to * a UUID. - * @return {!Blockly.VariableModel} The newly created variable. + * @return {!VariableModel} The newly created variable. */ VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { @@ -184,9 +186,9 @@ VariableMap.prototype.createVariable = function(name, if (opt_id && this.getVariableById(opt_id)) { throw Error('Variable id, "' + opt_id + '", is already in use.'); } - const id = opt_id || Blockly.utils.genUid(); + const id = opt_id || utils.genUid(); const type = opt_type || ''; - variable = new Blockly.VariableModel(this.workspace, name, type, id); + variable = new VariableModel(this.workspace, name, type, id); const variables = this.variableMap_[type] || []; variables.push(variable); @@ -203,14 +205,14 @@ VariableMap.prototype.createVariable = function(name, /** * Delete a variable. - * @param {!Blockly.VariableModel} variable Variable to delete. + * @param {!VariableModel} variable Variable to delete. */ VariableMap.prototype.deleteVariable = function(variable) { const variableList = this.variableMap_[variable.type]; for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))( + Events.fire(new (Events.get(Events.VAR_DELETE))( variable)); return; } @@ -232,7 +234,7 @@ VariableMap.prototype.deleteVariableById = function(id) { if (block.type == 'procedures_defnoreturn' || block.type == 'procedures_defreturn') { const procedureName = block.getFieldValue('NAME'); - const deleteText = Blockly.Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. + const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. replace('%1', variableName). replace('%2', procedureName); Blockly.alert(deleteText); @@ -243,7 +245,7 @@ VariableMap.prototype.deleteVariableById = function(id) { const map = this; if (uses.length > 1) { // Confirm before deleting multiple blocks. - const confirmText = Blockly.Msg['DELETE_VARIABLE_CONFIRMATION']. + const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION']. replace('%1', String(uses.length)). replace('%2', variableName); Blockly.confirm(confirmText, @@ -264,15 +266,15 @@ VariableMap.prototype.deleteVariableById = function(id) { /** * Deletes a variable and all of its uses from this workspace without asking the * user for confirmation. - * @param {!Blockly.VariableModel} variable Variable to delete. - * @param {!Array} uses An array of uses of the variable. + * @param {!VariableModel} variable Variable to delete. + * @param {!Array} uses An array of uses of the variable. * @package */ VariableMap.prototype.deleteVariableInternal = function(variable, uses) { - const existingGroup = Blockly.Events.getGroup(); + const existingGroup = Events.getGroup(); if (!existingGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } try { for (let i = 0; i < uses.length; i++) { @@ -281,7 +283,7 @@ VariableMap.prototype.deleteVariableInternal = function(variable, this.deleteVariable(variable); } finally { if (!existingGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } }; @@ -294,7 +296,7 @@ VariableMap.prototype.deleteVariableInternal = function(variable, * @param {string} name The name to check for. * @param {?string=} opt_type The type of the variable. If not provided it * defaults to the empty string, which is a specific type. - * @return {?Blockly.VariableModel} The variable with the given name, or null if + * @return {?VariableModel} The variable with the given name, or null if * it was not found. */ VariableMap.prototype.getVariable = function(name, opt_type) { @@ -302,7 +304,7 @@ VariableMap.prototype.getVariable = function(name, opt_type) { const list = this.variableMap_[type]; if (list) { for (let j = 0, variable; (variable = list[j]); j++) { - if (Blockly.Names.equals(variable.name, name)) { + if (Names.equals(variable.name, name)) { return variable; } } @@ -313,7 +315,7 @@ VariableMap.prototype.getVariable = function(name, opt_type) { /** * Find the variable by the given ID and return it. Return null if not found. * @param {string} id The ID to check for. - * @return {?Blockly.VariableModel} The variable with the given ID. + * @return {?VariableModel} The variable with the given ID. */ VariableMap.prototype.getVariableById = function(id) { const keys = Object.keys(this.variableMap_); @@ -332,7 +334,7 @@ VariableMap.prototype.getVariableById = function(id) { * Get a list containing all of the variables of a specified type. If type is * null, return list of variables with empty string type. * @param {?string} type Type of the variables to find. - * @return {!Array} The sought after variables of the + * @return {!Array} The sought after variables of the * passed in type. An empty array if none are found. */ VariableMap.prototype.getVariablesOfType = function(type) { @@ -347,7 +349,7 @@ VariableMap.prototype.getVariablesOfType = function(type) { /** * Return all variable and potential variable types. This list always contains * the empty string. - * @param {?Blockly.Workspace} ws The workspace used to look for potential + * @param {?Workspace} ws The workspace used to look for potential * variables. This can be different than the workspace stored on this object * if the passed in ws is a flyout workspace. * @return {!Array} List of variable types. @@ -355,9 +357,9 @@ VariableMap.prototype.getVariablesOfType = function(type) { */ VariableMap.prototype.getVariableTypes = function(ws) { const variableMap = {}; - Blockly.utils.object.mixin(variableMap, this.variableMap_); + object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { - Blockly.utils.object.mixin(variableMap, + object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_); } const types = Object.keys(variableMap); @@ -375,7 +377,7 @@ VariableMap.prototype.getVariableTypes = function(ws) { /** * Return all variables of all types. - * @return {!Array} List of variable models. + * @return {!Array} List of variable models. */ VariableMap.prototype.getAllVariables = function() { let all_variables = []; @@ -403,7 +405,7 @@ VariableMap.prototype.getAllVariableNames = function() { /** * Find all the uses of a named variable. * @param {string} id ID of the variable to find. - * @return {!Array} Array of block usages. + * @return {!Array} Array of block usages. */ VariableMap.prototype.getVariableUsesById = function(id) { const uses = []; diff --git a/tests/deps.js b/tests/deps.js index d4217d539..fa4d62a5c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -195,7 +195,7 @@ goog.addDependency('../../core/utils/svg_paths.js', ['Blockly.utils.svgPaths'], goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['Blockly.Xml', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); -goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.Names', 'Blockly.VariableModel', 'Blockly.utils', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); From d58a878fad99b4eedc4db2f09d6ee1820cb0c110 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 29 Jul 2021 12:43:49 -0700 Subject: [PATCH 400/833] Switch to getter for keyboard contents. --- core/blockly.js | 34 +++++++++------------------------- core/clipboard.js | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index 808c035b0..ab82638fe 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -93,25 +93,12 @@ Blockly.selected = null; Blockly.draggingConnections = []; /** - * Contents of the local clipboard. - * @type {Element} - * @private + * Get the current contents of the clipboard and associated metadata. + * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object + * containing the clipboard contents and associated metadata. + * @public */ -Blockly.clipboardXml_ = Blockly.clipboard.xml; - -/** - * Source of the local clipboard. - * @type {Blockly.WorkspaceSvg} - * @private - */ -Blockly.clipboardSource_ = Blockly.clipboard.source; - -/** - * Map of types to type counts for the clipboard object and descendants. - * @type {Object} - * @private - */ -Blockly.clipboardTypeCounts_ = Blockly.clipboard.typeCounts; +Blockly.getClipboardInfo = Blockly.common.getClipboardInfo; /** * Cached value for whether 3D is supported. @@ -137,9 +124,7 @@ Blockly.svgSize = function(svg) { // When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_ // from setCachedParentSvgSize. Blockly.utils.deprecation.warn( - 'Blockly.svgSize', - 'March 2021', - 'March 2022', + 'Blockly.svgSize', 'March 2021', 'March 2022', 'workspace.getCachedParentSvgSize'); svg = /** @type {?} */ (svg); return new Blockly.utils.Size(svg.cachedWidth_, svg.cachedHeight_); @@ -221,7 +206,8 @@ Blockly.deleteBlock = function(selected) { Blockly.Events.setGroup(true); Blockly.hideChaff(); if (selected.outputConnection) { - // Do not attempt to heal rows (https://github.com/google/blockly/issues/4832) + // Do not attempt to heal rows + // (https://github.com/google/blockly/issues/4832) selected.dispose(false, true); } else { selected.dispose(/* heal */ true, true); @@ -366,9 +352,7 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) { 'Block definition #' + i + ' in JSON array' + ' overwrites prior definition of "' + typename + '".'); } - Blockly.Blocks[typename] = { - init: Blockly.jsonInitFactory_(elem) - }; + Blockly.Blocks[typename] = {init: Blockly.jsonInitFactory_(elem)}; } } } diff --git a/core/clipboard.js b/core/clipboard.js index 887346a58..b93f92530 100644 --- a/core/clipboard.js +++ b/core/clipboard.js @@ -26,7 +26,6 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); * @private */ let xml = null; -exports.xml = xml; /** * Source of the local clipboard. @@ -34,7 +33,6 @@ exports.xml = xml; * @private */ let source = null; -exports.source = source; /** * Map of types to type counts for the clipboard object and descendants. @@ -42,12 +40,20 @@ exports.source = source; * @private */ let typeCounts = null; -exports.typeCounts = typeCounts; + +/** + * Get the current contents of the clipboard and associated metadata. + * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object + * containing the clipboard contents and associated metadata. + */ +const getClipboardInfo = function() { + return {xml: xml, source: source, typeCounts: typeCounts}; +}; +exports.getClipboardInfo = getClipboardInfo; /** * Copy a block or workspace comment onto the local clipboard. * @param {!ICopyable} toCopy Block or Workspace Comment to be copied. - * @package */ const copy = function(toCopy) { var data = toCopy.toCopyData(); @@ -57,12 +63,12 @@ const copy = function(toCopy) { typeCounts = data.typeCounts; } }; +/** @package */ exports.copy = copy; /** * Paste a block or workspace comment on to the main workspace. * @return {boolean} True if the paste was successful, false otherwise. - * @package */ const paste = function() { if (!xml) { @@ -82,13 +88,13 @@ const paste = function() { } return false; }; +/** @package */ exports.paste = paste; /** * Duplicate this block and its children, or a workspace comment. * @param {!ICopyable} toDuplicate Block or Workspace Comment to be - * copied. - * @package + * duplicated. */ const duplicate = function(toDuplicate) { // Save the clipboard. @@ -103,4 +109,5 @@ const duplicate = function(toDuplicate) { xml = oldXml; source = oldSource; }; +/** @package */ exports.duplicate = duplicate; From 78646eae51980af96b9e97add9a13d8978773595 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:47:51 -0700 Subject: [PATCH 401/833] clang-format core/variable_map.js --- core/variable_map.js | 57 +++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/core/variable_map.js b/core/variable_map.js index e2c371149..a22ab75d5 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -109,10 +109,9 @@ VariableMap.prototype.renameVariableById = function(id, newName) { * workspace. * @private */ -VariableMap.prototype.renameVariableAndUses_ = function(variable, - newName, blocks) { - Events.fire(new (Events.get(Events.VAR_RENAME))( - variable, newName)); +VariableMap.prototype.renameVariableAndUses_ = function( + variable, newName, blocks) { + Events.fire(new (Events.get(Events.VAR_RENAME))(variable, newName)); variable.name = newName; for (let i = 0; i < blocks.length; i++) { blocks[i].updateVarName(variable); @@ -132,8 +131,8 @@ VariableMap.prototype.renameVariableAndUses_ = function(variable, * workspace. * @private */ -VariableMap.prototype.renameVariableWithConflict_ = function(variable, - newName, conflictVar, blocks) { +VariableMap.prototype.renameVariableWithConflict_ = function( + variable, newName, conflictVar, blocks) { const type = variable.type; const oldCase = conflictVar.name; @@ -149,13 +148,11 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, } // Finally delete the original variable, which is now unreferenced. - Events.fire(new (Events.get(Events.VAR_DELETE))( - variable)); + Events.fire(new (Events.get(Events.VAR_DELETE))(variable)); // And remove it from the list. const variableList = this.getVariablesOfType(type); const variableIndex = variableList.indexOf(variable); this.variableMap_[type].splice(variableIndex, 1); - }; /* End functions for renaming variables. */ @@ -171,12 +168,12 @@ VariableMap.prototype.renameVariableWithConflict_ = function(variable, * a UUID. * @return {!VariableModel} The newly created variable. */ -VariableMap.prototype.createVariable = function(name, - opt_type, opt_id) { +VariableMap.prototype.createVariable = function(name, opt_type, opt_id) { let variable = this.getVariable(name, opt_type); if (variable) { if (opt_id && variable.getId() != opt_id) { - throw Error('Variable "' + name + '" is already in use and its id is "' + + throw Error( + 'Variable "' + name + '" is already in use and its id is "' + variable.getId() + '" which conflicts with the passed in ' + 'id, "' + opt_id + '".'); } @@ -212,8 +209,7 @@ VariableMap.prototype.deleteVariable = function(variable) { for (let i = 0, tempVar; (tempVar = variableList[i]); i++) { if (tempVar.getId() == variable.getId()) { variableList.splice(i, 1); - Events.fire(new (Events.get(Events.VAR_DELETE))( - variable)); + Events.fire(new (Events.get(Events.VAR_DELETE))(variable)); return; } } @@ -232,11 +228,11 @@ VariableMap.prototype.deleteVariableById = function(id) { const uses = this.getVariableUsesById(id); for (let i = 0, block; (block = uses[i]); i++) { if (block.type == 'procedures_defnoreturn' || - block.type == 'procedures_defreturn') { + block.type == 'procedures_defreturn') { const procedureName = block.getFieldValue('NAME'); - const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE']. - replace('%1', variableName). - replace('%2', procedureName); + const deleteText = Msg['CANNOT_DELETE_VARIABLE_PROCEDURE'] + .replace('%1', variableName) + .replace('%2', procedureName); Blockly.alert(deleteText); return; } @@ -245,21 +241,20 @@ VariableMap.prototype.deleteVariableById = function(id) { const map = this; if (uses.length > 1) { // Confirm before deleting multiple blocks. - const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION']. - replace('%1', String(uses.length)). - replace('%2', variableName); - Blockly.confirm(confirmText, - function(ok) { - if (ok && variable) { - map.deleteVariableInternal(variable, uses); - } - }); + const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION'] + .replace('%1', String(uses.length)) + .replace('%2', variableName); + Blockly.confirm(confirmText, function(ok) { + if (ok && variable) { + map.deleteVariableInternal(variable, uses); + } + }); } else { // No confirmation necessary for a single block. map.deleteVariableInternal(variable, uses); } } else { - console.warn("Can't delete non-existent variable: " + id); + console.warn('Can\'t delete non-existent variable: ' + id); } }; @@ -270,8 +265,7 @@ VariableMap.prototype.deleteVariableById = function(id) { * @param {!Array} uses An array of uses of the variable. * @package */ -VariableMap.prototype.deleteVariableInternal = function(variable, - uses) { +VariableMap.prototype.deleteVariableInternal = function(variable, uses) { const existingGroup = Events.getGroup(); if (!existingGroup) { Events.setGroup(true); @@ -359,8 +353,7 @@ VariableMap.prototype.getVariableTypes = function(ws) { const variableMap = {}; object.mixin(variableMap, this.variableMap_); if (ws && ws.getPotentialVariableMap()) { - object.mixin(variableMap, - ws.getPotentialVariableMap().variableMap_); + object.mixin(variableMap, ws.getPotentialVariableMap().variableMap_); } const types = Object.keys(variableMap); let hasEmpty = false; From dc4a719e2f507468b303ed228381dc7d033cdd57 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:50:42 -0700 Subject: [PATCH 402/833] Migrate core/variable_model.js to goog.module --- core/variable_model.js | 15 +++++++++------ tests/deps.js | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index bc097da8a..ce4c37c66 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.VariableModel'); +goog.module('Blockly.VariableModel'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -34,7 +35,7 @@ goog.requireType('Blockly.Workspace'); * @see {Blockly.FieldVariable} * @constructor */ -Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { +const VariableModel = function(workspace, name, opt_type, opt_id) { /** * The workspace the variable is in. * @type {!Blockly.Workspace} @@ -73,18 +74,20 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) { /** * @return {string} The ID for the variable. */ -Blockly.VariableModel.prototype.getId = function() { +VariableModel.prototype.getId = function() { return this.id_; }; /** * A custom compare function for the VariableModel objects. - * @param {Blockly.VariableModel} var1 First variable to compare. - * @param {Blockly.VariableModel} var2 Second variable to compare. + * @param {VariableModel} var1 First variable to compare. + * @param {VariableModel} var2 Second variable to compare. * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, * and 1 if greater. * @package */ -Blockly.VariableModel.compareByName = function(var1, var2) { +VariableModel.compareByName = function(var1, var2) { return var1.name.localeCompare(var2.name, undefined, {sensitivity: 'base'}); }; + +exports = VariableModel; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..0e0a7f034 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -196,7 +196,7 @@ goog.addDependency('../../core/utils/toolbox.js', ['Blockly.utils.toolbox'], ['B goog.addDependency('../../core/utils/useragent.js', ['Blockly.utils.userAgent'], ['Blockly.utils.global']); goog.addDependency('../../core/utils/xml.js', ['Blockly.utils.xml'], []); goog.addDependency('../../core/variable_map.js', ['Blockly.VariableMap'], ['Blockly.Events', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename', 'Blockly.Msg', 'Blockly.utils', 'Blockly.utils.object']); -goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils']); +goog.addDependency('../../core/variable_model.js', ['Blockly.VariableModel'], ['Blockly.Events', 'Blockly.Events.VarCreate', 'Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/variables.js', ['Blockly.Variables'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Xml', 'Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.xml']); goog.addDependency('../../core/variables_dynamic.js', ['Blockly.VariablesDynamic'], ['Blockly.Blocks', 'Blockly.Msg', 'Blockly.VariableModel', 'Blockly.Variables', 'Blockly.utils.xml']); goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubble', 'Blockly.Events', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); From 714bb6120f9caebc04dc6707d300f784924b33b7 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 29 Jul 2021 12:52:14 -0700 Subject: [PATCH 403/833] Fix annotations --- core/blockly.js | 6 +++--- core/clipboard.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/blockly.js b/core/blockly.js index ab82638fe..9fae4e84a 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -94,11 +94,11 @@ Blockly.draggingConnections = []; /** * Get the current contents of the clipboard and associated metadata. - * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object - * containing the clipboard contents and associated metadata. + * @return {{xml: ?Element, source: ?Blockly.WorkspaceSvg, typeCounts: ?Object}} + * An object containing the clipboard contents and associated metadata. * @public */ -Blockly.getClipboardInfo = Blockly.common.getClipboardInfo; +Blockly.getClipboardInfo = Blockly.clipboard.getClipboardInfo; /** * Cached value for whether 3D is supported. diff --git a/core/clipboard.js b/core/clipboard.js index b93f92530..9f7097f71 100644 --- a/core/clipboard.js +++ b/core/clipboard.js @@ -22,29 +22,29 @@ const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg'); /** * Contents of the local clipboard. - * @type {Element} + * @type {?Element} * @private */ let xml = null; /** * Source of the local clipboard. - * @type {WorkspaceSvg} + * @type {?WorkspaceSvg} * @private */ let source = null; /** * Map of types to type counts for the clipboard object and descendants. - * @type {Object} + * @type {?Object} * @private */ let typeCounts = null; /** * Get the current contents of the clipboard and associated metadata. - * @return {{xml: Element, source: WorkspaceSvg, typeCounts: Object}} An object - * containing the clipboard contents and associated metadata. + * @return {{xml: ?Element, source: ?WorkspaceSvg, typeCounts: ?Object}} An + * object containing the clipboard contents and associated metadata. */ const getClipboardInfo = function() { return {xml: xml, source: source, typeCounts: typeCounts}; From 0a6893706f2c2a64b6865ab68c4bc62ce625a2ff Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:55:26 -0700 Subject: [PATCH 404/833] Migrate core/variable_model.js to named requires --- core/variable_model.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index ce4c37c66..74bc2b578 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -13,18 +13,18 @@ goog.module('Blockly.VariableModel'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const utils = goog.require('Blockly.utils'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.VarCreate'); -goog.require('Blockly.utils'); - -goog.requireType('Blockly.Workspace'); /** * Class for a variable model. * Holds information for the variable including name, ID, and type. - * @param {!Blockly.Workspace} workspace The variable's workspace. + * @param {!Workspace} workspace The variable's workspace. * @param {string} name The name of the variable. This is the user-visible name * (e.g. 'my var' or '私の変数'), not the generated name. * @param {string=} opt_type The type of the variable like 'int' or 'string'. @@ -38,7 +38,7 @@ goog.requireType('Blockly.Workspace'); const VariableModel = function(workspace, name, opt_type, opt_id) { /** * The workspace the variable is in. - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; @@ -65,9 +65,9 @@ const VariableModel = function(workspace, name, opt_type, opt_id) { * @type {string} * @private */ - this.id_ = opt_id || Blockly.utils.genUid(); + this.id_ = opt_id || utils.genUid(); - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_CREATE))( + Events.fire(new (Events.get(Events.VAR_CREATE))( this)); }; From 6eb8667c3ccb5c9a4d613a881f0711a845cec533 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 12:55:46 -0700 Subject: [PATCH 405/833] clang-format core/variable_model.js --- core/variable_model.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/variable_model.js b/core/variable_model.js index 74bc2b578..2f5936f4e 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -67,8 +67,7 @@ const VariableModel = function(workspace, name, opt_type, opt_id) { */ this.id_ = opt_id || utils.genUid(); - Events.fire(new (Events.get(Events.VAR_CREATE))( - this)); + Events.fire(new (Events.get(Events.VAR_CREATE))(this)); }; /** From 34042519f47492a9041e071556a18b8999858cbc Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 29 Jul 2021 15:00:44 -0700 Subject: [PATCH 406/833] Add regex lookarounds to check for require overlaps --- scripts/goog_module/convert-file.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 1c5b92fc8..4f433e428 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -151,7 +151,12 @@ getPropertiesAccessed() { # Detect if there was any overlap. if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do - properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/'"${requires_overlap_prop}"'//g') + # Replace any instances of $requires_overlap_prop. Includes regex + # lookarounds so that it does not simply match string contains. + # Ex: if $requires_overlap is "Svg", then it would update the list + # "isTargetInput mouseToSvg noEvent Svg" to + # "isTargetInput mouseToSvg noEvent " (note that mouseToSvg is unchanged). + properties_accessed=$(echo "${properties_accessed}" | perl -pe 's/(? Date: Thu, 29 Jul 2021 15:18:15 -0700 Subject: [PATCH 407/833] wording update --- scripts/goog_module/convert-file.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/goog_module/convert-file.sh b/scripts/goog_module/convert-file.sh index 4f433e428..4d6c13345 100755 --- a/scripts/goog_module/convert-file.sh +++ b/scripts/goog_module/convert-file.sh @@ -151,7 +151,7 @@ getPropertiesAccessed() { # Detect if there was any overlap. if [[ -n "${requires_overlap}" ]]; then while read -r requires_overlap_prop; do - # Replace any instances of $requires_overlap_prop. Includes regex + # Removes any instances of $requires_overlap_prop. Includes regex # lookarounds so that it does not simply match string contains. # Ex: if $requires_overlap is "Svg", then it would update the list # "isTargetInput mouseToSvg noEvent Svg" to From b3bbd70280d2ddab3844ea918800c5c9922b056e Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Thu, 29 Jul 2021 15:57:08 -0700 Subject: [PATCH 408/833] Migrate core/trashcan.js to goog.module --- core/trashcan.js | 195 ++++++++++++++++++++--------------------------- tests/deps.js | 2 +- 2 files changed, 85 insertions(+), 112 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index dea20acd2..7771deba0 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.Trashcan'); +goog.module('Blockly.Trashcan'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.browserEvents'); goog.require('Blockly.ComponentManager'); @@ -46,8 +47,8 @@ goog.requireType('Blockly.WorkspaceSvg'); * @implements {Blockly.IPositionable} * @extends {Blockly.DeleteArea} */ -Blockly.Trashcan = function(workspace) { - Blockly.Trashcan.superClass_.constructor.call(this); +const Trashcan = function(workspace) { + Trashcan.superClass_.constructor.call(this); /** * The workspace the trashcan sits in. * @type {!Blockly.WorkspaceSvg} @@ -113,113 +114,85 @@ Blockly.Trashcan = function(workspace) { } this.workspace_.addChangeListener(this.onDelete_.bind(this)); }; -Blockly.utils.object.inherits(Blockly.Trashcan, Blockly.DeleteArea); +Blockly.utils.object.inherits(Trashcan, Blockly.DeleteArea); /** * Width of both the trash can and lid images. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.WIDTH_ = 47; +const WIDTH = 47; /** * Height of the trashcan image (minus lid). - * @const {number} - * @private */ -Blockly.Trashcan.prototype.BODY_HEIGHT_ = 44; +const BODY_HEIGHT = 44; /** * Height of the lid image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.LID_HEIGHT_ = 16; +const LID_HEIGHT = 16; /** * Distance between trashcan and bottom or top edge of workspace. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.MARGIN_VERTICAL_ = 20; +const MARGIN_VERTICAL = 20; /** * Distance between trashcan and right or left edge of workspace. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.MARGIN_HORIZONTAL_ = 20; +const MARGIN_HORIZONTAL = 20; /** * Extent of hotspot on all sides beyond the size of the image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.MARGIN_HOTSPOT_ = 10; +const MARGIN_HOTSPOT = 10; /** * Location of trashcan in sprite image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.SPRITE_LEFT_ = 0; +const SPRITE_LEFT = 0; /** * Location of trashcan in sprite image. - * @const {number} - * @private */ -Blockly.Trashcan.prototype.SPRITE_TOP_ = 32; +const SPRITE_TOP = 32; /** * The openness of the lid when the trashcan contains blocks. * (0.0 = closed, 1.0 = open) - * @const {number} - * @private */ -Blockly.Trashcan.prototype.HAS_BLOCKS_LID_ANGLE_ = 0.1; +const HAS_BLOCKS_LID_ANGLE = 0.1; /** * The length of the lid open/close animation in milliseconds. - * @const {number} - * @private */ -Blockly.Trashcan.ANIMATION_LENGTH_ = 80; +const ANIMATION_LENGTH = 80; /** * The number of frames in the animation. - * @const {number} - * @private */ -Blockly.Trashcan.ANIMATION_FRAMES_ = 4; +const ANIMATION_FRAMES = 4; /** * The minimum (resting) opacity of the trashcan and lid. - * @const {number} - * @private */ -Blockly.Trashcan.OPACITY_MIN_ = 0.4; +const OPACITY_MIN = 0.4; /** * The maximum (hovered) opacity of the trashcan and lid. - * @const {number} - * @private */ -Blockly.Trashcan.OPACITY_MAX_ = 0.8; +const OPACITY_MAX = 0.8; /** * The maximum angle the trashcan lid can opens to. At the end of the open * animation the lid will be open to this angle. - * @const {number} - * @private */ -Blockly.Trashcan.MAX_LID_ANGLE_ = 45; +const MAX_LID_ANGLE = 45; /** * Current open/close state of the lid. * @type {boolean} */ -Blockly.Trashcan.prototype.isLidOpen = false; +Trashcan.prototype.isLidOpen = false; /** * The minimum openness of the lid. Used to indicate if the trashcan contains @@ -227,62 +200,62 @@ Blockly.Trashcan.prototype.isLidOpen = false; * @type {number} * @private */ -Blockly.Trashcan.prototype.minOpenness_ = 0; +Trashcan.prototype.minOpenness_ = 0; /** * The SVG group containing the trash can. * @type {SVGElement} * @private */ -Blockly.Trashcan.prototype.svgGroup_ = null; +Trashcan.prototype.svgGroup_ = null; /** * The SVG image element of the trash can lid. * @type {SVGElement} * @private */ -Blockly.Trashcan.prototype.svgLid_ = null; +Trashcan.prototype.svgLid_ = null; /** * Task ID of opening/closing animation. * @type {number} * @private */ -Blockly.Trashcan.prototype.lidTask_ = 0; +Trashcan.prototype.lidTask_ = 0; /** * Current state of lid opening (0.0 = closed, 1.0 = open). * @type {number} * @private */ -Blockly.Trashcan.prototype.lidOpen_ = 0; +Trashcan.prototype.lidOpen_ = 0; /** * Left coordinate of the trash can. * @type {number} * @private */ -Blockly.Trashcan.prototype.left_ = 0; +Trashcan.prototype.left_ = 0; /** * Top coordinate of the trash can. * @type {number} * @private */ -Blockly.Trashcan.prototype.top_ = 0; +Trashcan.prototype.top_ = 0; /** * Whether this has been initialized. * @type {boolean} * @private */ -Blockly.Trashcan.prototype.initialized_ = false; +Trashcan.prototype.initialized_ = false; /** * Create the trash can elements. * @return {!SVGElement} The trash can's SVG group. */ -Blockly.Trashcan.prototype.createDom = function() { +Trashcan.prototype.createDom = function() { /* Here's the markup that will be generated: @@ -309,17 +282,17 @@ Blockly.Trashcan.prototype.createDom = function() { Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, { - 'width': this.WIDTH_, - 'height': this.BODY_HEIGHT_, - 'y': this.LID_HEIGHT_ + 'width': WIDTH, + 'height': BODY_HEIGHT, + 'y': LID_HEIGHT }, clip); const body = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, - 'x': -this.SPRITE_LEFT_, + 'x': -SPRITE_LEFT, 'height': Blockly.internalConstants.SPRITE.height, - 'y': -this.SPRITE_TOP_, + 'y': -SPRITE_TOP, 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')' }, this.svgGroup_); @@ -334,13 +307,13 @@ Blockly.Trashcan.prototype.createDom = function() { this.svgGroup_); Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.RECT, - {'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip); + {'width': WIDTH, 'height': LID_HEIGHT}, clip); this.svgLid_ = Blockly.utils.dom.createSvgElement( Blockly.utils.Svg.IMAGE, { 'width': Blockly.internalConstants.SPRITE.width, - 'x': -this.SPRITE_LEFT_, + 'x': -SPRITE_LEFT, 'height': Blockly.internalConstants.SPRITE.height, - 'y': -this.SPRITE_TOP_, + 'y': -SPRITE_TOP, 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')' }, this.svgGroup_); @@ -366,7 +339,7 @@ Blockly.Trashcan.prototype.createDom = function() { /** * Initializes the trash can. */ -Blockly.Trashcan.prototype.init = function() { +Trashcan.prototype.init = function() { if (this.workspace_.options.maxTrashcanContents > 0) { Blockly.utils.dom.insertAfter( this.flyout.createDom(Blockly.utils.Svg.SVG), @@ -392,7 +365,7 @@ Blockly.Trashcan.prototype.init = function() { * Unlink from all DOM elements to prevent memory leaks. * @suppress {checkTypes} */ -Blockly.Trashcan.prototype.dispose = function() { +Trashcan.prototype.dispose = function() { this.workspace_.getComponentManager().removeComponent('trashcan'); if (this.svgGroup_) { Blockly.utils.dom.removeNode(this.svgGroup_); @@ -408,7 +381,7 @@ Blockly.Trashcan.prototype.dispose = function() { * @return {boolean} True if the trashcan has contents. * @private */ -Blockly.Trashcan.prototype.hasContents_ = function() { +Trashcan.prototype.hasContents_ = function() { return !!this.contents_.length; }; @@ -416,14 +389,14 @@ Blockly.Trashcan.prototype.hasContents_ = function() { * Returns true if the trashcan contents-flyout is currently open. * @return {boolean} True if the trashcan contents-flyout is currently open. */ -Blockly.Trashcan.prototype.contentsIsOpen = function() { +Trashcan.prototype.contentsIsOpen = function() { return this.flyout.isVisible(); }; /** * Opens the trashcan flyout. */ -Blockly.Trashcan.prototype.openFlyout = function() { +Trashcan.prototype.openFlyout = function() { if (this.contentsIsOpen()) { return; } @@ -435,7 +408,7 @@ Blockly.Trashcan.prototype.openFlyout = function() { /** * Closes the trashcan flyout. */ -Blockly.Trashcan.prototype.closeFlyout = function() { +Trashcan.prototype.closeFlyout = function() { if (!this.contentsIsOpen()) { return; } @@ -448,7 +421,7 @@ Blockly.Trashcan.prototype.closeFlyout = function() { * @param {boolean} onlyClosePopups Whether only popups should be closed. * Flyouts should not be closed if this is true. */ -Blockly.Trashcan.prototype.autoHide = function(onlyClosePopups) { +Trashcan.prototype.autoHide = function(onlyClosePopups) { // For now the trashcan flyout always autocloses because it overlays the // trashcan UI (no trashcan to click to close it). if (!onlyClosePopups && this.flyout) { @@ -460,7 +433,7 @@ Blockly.Trashcan.prototype.autoHide = function(onlyClosePopups) { * Empties the trashcan's contents. If the contents-flyout is currently open * it will be closed. */ -Blockly.Trashcan.prototype.emptyContents = function() { +Trashcan.prototype.emptyContents = function() { if (!this.hasContents_()) { return; } @@ -477,7 +450,7 @@ Blockly.Trashcan.prototype.emptyContents = function() { * @param {!Array} savedPositions List of rectangles that * are already on the workspace. */ -Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { +Trashcan.prototype.position = function(metrics, savedPositions) { // Not yet initialized. if (!this.initialized_) { return; @@ -486,10 +459,10 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { const cornerPosition = Blockly.uiPosition.getCornerOppositeToolbox(this.workspace_, metrics); - const height = this.BODY_HEIGHT_ + this.LID_HEIGHT_; + const height = BODY_HEIGHT + LID_HEIGHT; const startRect = Blockly.uiPosition.getStartPositionRect( - cornerPosition, new Blockly.utils.Size(this.WIDTH_, height), - this.MARGIN_HORIZONTAL_, this.MARGIN_VERTICAL_, metrics, this.workspace_); + cornerPosition, new Blockly.utils.Size(WIDTH, height), + MARGIN_HORIZONTAL, MARGIN_VERTICAL, metrics, this.workspace_); const verticalPosition = cornerPosition.vertical; const bumpDirection = @@ -497,7 +470,7 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { Blockly.uiPosition.bumpDirection.DOWN : Blockly.uiPosition.bumpDirection.UP; const positionRect = Blockly.uiPosition.bumpPositionRect( - startRect, this.MARGIN_VERTICAL_, bumpDirection, savedPositions); + startRect, MARGIN_VERTICAL, bumpDirection, savedPositions); this.top_ = positionRect.top; this.left_ = positionRect.left; @@ -511,9 +484,9 @@ Blockly.Trashcan.prototype.position = function(metrics, savedPositions) { * @return {?Blockly.utils.Rect} The UI elements’s bounding box. Null if * bounding box should be ignored by other UI elements. */ -Blockly.Trashcan.prototype.getBoundingRectangle = function() { - const bottom = this.top_ + this.BODY_HEIGHT_ + this.LID_HEIGHT_; - const right = this.left_ + this.WIDTH_; +Trashcan.prototype.getBoundingRectangle = function() { + const bottom = this.top_ + BODY_HEIGHT + LID_HEIGHT; + const right = this.left_ + WIDTH; return new Blockly.utils.Rect(this.top_, bottom, this.left_, right); }; @@ -523,17 +496,17 @@ Blockly.Trashcan.prototype.getBoundingRectangle = function() { * @return {?Blockly.utils.Rect} The component's bounding box. Null if drag * target area should be ignored. */ -Blockly.Trashcan.prototype.getClientRect = function() { +Trashcan.prototype.getClientRect = function() { if (!this.svgGroup_) { return null; } const trashRect = this.svgGroup_.getBoundingClientRect(); - const top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; - const bottom = top + this.LID_HEIGHT_ + this.BODY_HEIGHT_ + - 2 * this.MARGIN_HOTSPOT_; - const left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; - const right = left + this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; + const top = trashRect.top + SPRITE_TOP - MARGIN_HOTSPOT; + const bottom = top + LID_HEIGHT + BODY_HEIGHT + + 2 * MARGIN_HOTSPOT; + const left = trashRect.left + SPRITE_LEFT - MARGIN_HOTSPOT; + const right = left + WIDTH + 2 * MARGIN_HOTSPOT; return new Blockly.utils.Rect(top, bottom, left, right); }; @@ -544,7 +517,7 @@ Blockly.Trashcan.prototype.getClientRect = function() { * dragged. * @override */ -Blockly.Trashcan.prototype.onDragOver = function(_dragElement) { +Trashcan.prototype.onDragOver = function(_dragElement) { this.setLidOpen(this.wouldDelete_); }; @@ -554,7 +527,7 @@ Blockly.Trashcan.prototype.onDragOver = function(_dragElement) { * dragged. * @override */ -Blockly.Trashcan.prototype.onDragExit = function(_dragElement) { +Trashcan.prototype.onDragExit = function(_dragElement) { this.setLidOpen(false); }; @@ -565,7 +538,7 @@ Blockly.Trashcan.prototype.onDragExit = function(_dragElement) { * dragged. * @override */ -Blockly.Trashcan.prototype.onDrop = function(_dragElement) { +Trashcan.prototype.onDrop = function(_dragElement) { setTimeout(this.setLidOpen.bind(this, false), 100); }; @@ -574,7 +547,7 @@ Blockly.Trashcan.prototype.onDrop = function(_dragElement) { * @param {boolean} state True if open. * @package */ -Blockly.Trashcan.prototype.setLidOpen = function(state) { +Trashcan.prototype.setLidOpen = function(state) { if (this.isLidOpen == state) { return; } @@ -587,24 +560,22 @@ Blockly.Trashcan.prototype.setLidOpen = function(state) { * Rotate the lid open or closed by one step. Then wait and recurse. * @private */ -Blockly.Trashcan.prototype.animateLid_ = function() { - const frames = Blockly.Trashcan.ANIMATION_FRAMES_; +Trashcan.prototype.animateLid_ = function() { + const frames = ANIMATION_FRAMES; const delta = 1 / (frames + 1); this.lidOpen_ += this.isLidOpen ? delta : -delta; this.lidOpen_ = Math.min(Math.max(this.lidOpen_, this.minOpenness_), 1); - this.setLidAngle_(this.lidOpen_ * Blockly.Trashcan.MAX_LID_ANGLE_); + this.setLidAngle_(this.lidOpen_ * MAX_LID_ANGLE); - const minOpacity = Blockly.Trashcan.OPACITY_MIN_; - const maxOpacity = Blockly.Trashcan.OPACITY_MAX_; // Linear interpolation between min and max. - const opacity = minOpacity + this.lidOpen_ * (maxOpacity - minOpacity); + const opacity = OPACITY_MIN + this.lidOpen_ * (OPACITY_MAX - OPACITY_MIN); this.svgGroup_.style.opacity = opacity; if (this.lidOpen_ > this.minOpenness_ && this.lidOpen_ < 1) { this.lidTask_ = setTimeout(this.animateLid_.bind(this), - Blockly.Trashcan.ANIMATION_LENGTH_ / frames); + ANIMATION_LENGTH / frames); } }; @@ -613,14 +584,14 @@ Blockly.Trashcan.prototype.animateLid_ = function() { * @param {number} lidAngle The angle at which to set the lid. * @private */ -Blockly.Trashcan.prototype.setLidAngle_ = function(lidAngle) { +Trashcan.prototype.setLidAngle_ = function(lidAngle) { const openAtRight = this.workspace_.toolboxPosition == Blockly.utils.toolbox.Position.RIGHT || (this.workspace_.horizontalLayout && this.workspace_.RTL); this.svgLid_.setAttribute('transform', 'rotate(' + (openAtRight ? -lidAngle : lidAngle) + ',' + - (openAtRight ? 4 : this.WIDTH_ - 4) + ',' + - (this.LID_HEIGHT_ - 2) + ')'); + (openAtRight ? 4 : WIDTH - 4) + ',' + + (LID_HEIGHT - 2) + ')'); }; /** @@ -630,10 +601,10 @@ Blockly.Trashcan.prototype.setLidAngle_ = function(lidAngle) { * 0 and 1. * @private */ -Blockly.Trashcan.prototype.setMinOpenness_ = function(newMin) { +Trashcan.prototype.setMinOpenness_ = function(newMin) { this.minOpenness_ = newMin; if (!this.isLidOpen) { - this.setLidAngle_(newMin * Blockly.Trashcan.MAX_LID_ANGLE_); + this.setLidAngle_(newMin * MAX_LID_ANGLE); } }; @@ -641,14 +612,14 @@ Blockly.Trashcan.prototype.setMinOpenness_ = function(newMin) { * Flip the lid shut. * Called externally after a drag. */ -Blockly.Trashcan.prototype.closeLid = function() { +Trashcan.prototype.closeLid = function() { this.setLidOpen(false); }; /** * Inspect the contents of the trash. */ -Blockly.Trashcan.prototype.click = function() { +Trashcan.prototype.click = function() { if (!this.hasContents_()) { return; } @@ -660,7 +631,7 @@ Blockly.Trashcan.prototype.click = function() { * @param {boolean} trashcanOpen Whether the flyout is opening. * @private */ -Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { +Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { const uiEvent = new (Blockly.Events.get(Blockly.Events.TRASHCAN_OPEN))( trashcanOpen,this.workspace_.id); Blockly.Events.fire(uiEvent); @@ -671,7 +642,7 @@ Blockly.Trashcan.prototype.fireUiEvent_ = function(trashcanOpen) { * @param {!Event} e A mouse down event. * @private */ -Blockly.Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) { +Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) { if (!this.contentsIsOpen() && this.hasContents_()) { e.stopPropagation(); // Don't start a workspace scroll. } @@ -681,7 +652,7 @@ Blockly.Trashcan.prototype.blockMouseDownWhenOpenable_ = function(e) { * Indicate that the trashcan can be clicked (by opening it) if it has blocks. * @private */ -Blockly.Trashcan.prototype.mouseOver_ = function() { +Trashcan.prototype.mouseOver_ = function() { if (this.hasContents_()) { this.setLidOpen(true); } @@ -692,7 +663,7 @@ Blockly.Trashcan.prototype.mouseOver_ = function() { * blocks). * @private */ -Blockly.Trashcan.prototype.mouseOut_ = function() { +Trashcan.prototype.mouseOut_ = function() { // No need to do a .hasBlocks check here because if it doesn't the trashcan // won't be open in the first place, and setOpen won't run. this.setLidOpen(false); @@ -703,7 +674,7 @@ Blockly.Trashcan.prototype.mouseOut_ = function() { * @param {!Blockly.Events.Abstract} event Workspace event. * @private */ -Blockly.Trashcan.prototype.onDelete_ = function(event) { +Trashcan.prototype.onDelete_ = function(event) { if (this.workspace_.options.maxTrashcanContents <= 0) { return; } @@ -720,7 +691,7 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { this.contents_.pop(); } - this.setMinOpenness_(this.HAS_BLOCKS_LID_ANGLE_); + this.setMinOpenness_(HAS_BLOCKS_LID_ANGLE); } }; @@ -733,7 +704,7 @@ Blockly.Trashcan.prototype.onDelete_ = function(event) { * attributes. * @private */ -Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { +Trashcan.prototype.cleanBlockXML_ = function(xml) { const xmlBlock = xml.cloneNode(true); let node = xmlBlock; while (node) { @@ -772,3 +743,5 @@ Blockly.Trashcan.prototype.cleanBlockXML_ = function(xml) { } return Blockly.Xml.domToText(xmlBlock); }; + +exports = Trashcan; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..ed128d55c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -173,7 +173,7 @@ goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'] goog.addDependency('../../core/tooltip.js', ['Blockly.Tooltip'], ['Blockly.browserEvents', 'Blockly.utils.string']); goog.addDependency('../../core/touch.js', ['Blockly.Touch'], ['Blockly.internalConstants', 'Blockly.utils', 'Blockly.utils.global', 'Blockly.utils.string']); goog.addDependency('../../core/touch_gesture.js', ['Blockly.TouchGesture'], ['Blockly.Gesture', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.object']); -goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); +goog.addDependency('../../core/trashcan.js', ['Blockly.Trashcan'], ['Blockly.ComponentManager', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.TrashcanOpen', 'Blockly.IAutoHideable', 'Blockly.IPositionable', 'Blockly.Options', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.uiPosition', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/utils.js', ['Blockly.utils'], ['Blockly.Msg', 'Blockly.internalConstants', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.colour', 'Blockly.utils.global', 'Blockly.utils.string', 'Blockly.utils.style', 'Blockly.utils.userAgent']); goog.addDependency('../../core/utils/aria.js', ['Blockly.utils.aria'], []); goog.addDependency('../../core/utils/colour.js', ['Blockly.utils.colour'], [], {'lang': 'es6', 'module': 'goog'}); From 787145acf46c6feae193b521477d25c402b0ebca Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:40:48 -0700 Subject: [PATCH 409/833] Migrate core/toolbox/collapsible_category.js to ES6 const/let --- core/toolbox/collapsible_category.js | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index 979931848..4bf907278 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -92,7 +92,8 @@ Blockly.CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; * @override */ Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { - var cssConfig = Blockly.CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call(this); + const cssConfig = Blockly.CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( + this); cssConfig['contents'] = 'blocklyToolboxContents'; return cssConfig; }; @@ -101,19 +102,20 @@ Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() * @override */ Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { - var contents = categoryDef['contents']; - var prevIsFlyoutItem = true; + const contents = categoryDef['contents']; + let prevIsFlyoutItem = true; if (categoryDef['custom']) { this.flyoutItems_ = categoryDef['custom']; } else if (contents) { - for (var i = 0, itemDef; (itemDef = contents[i]); i++) { + for (let i = 0; i < contents.length; i++) { + const itemDef = contents[i]; // Separators can exist as either a flyout item or a toolbox item so // decide where it goes based on the type of the previous item. if (!Blockly.registry.hasItem(Blockly.registry.Type.TOOLBOX_ITEM, itemDef['kind']) || (itemDef['kind'].toLowerCase() == Blockly.ToolboxSeparator.registrationName && prevIsFlyoutItem)) { - var flyoutItem = /** @type {Blockly.utils.toolbox.FlyoutItemInfo} */ (itemDef); + const flyoutItem = /** @type {Blockly.utils.toolbox.FlyoutItemInfo} */ (itemDef); this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; } else { @@ -131,8 +133,8 @@ Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryD * @private */ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { - var registryName = itemDef['kind']; - var categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); + let registryName = itemDef['kind']; + const categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); // Categories that are collapsible are created using a class registered under // a diffferent name. @@ -140,9 +142,9 @@ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemD Blockly.utils.toolbox.isCategoryCollapsible(categoryDef)) { registryName = Blockly.CollapsibleToolboxCategory.registrationName; } - var ToolboxItemClass = Blockly.registry.getClass( + const ToolboxItemClass = Blockly.registry.getClass( Blockly.registry.Type.TOOLBOX_ITEM, registryName); - var toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); + const toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); this.toolboxItems_.push(toolboxItem); }; @@ -162,7 +164,7 @@ Blockly.CollapsibleToolboxCategory.prototype.init = function() { Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { Blockly.CollapsibleToolboxCategory.superClass_.createDom_.call(this); - var subCategories = this.getChildToolboxItems(); + const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); Blockly.utils.aria.setRole(this.subcategoriesDiv_, Blockly.utils.aria.Role.GROUP); @@ -175,7 +177,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { * @override */ Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { - var toolboxIcon = document.createElement('span'); + const toolboxIcon = document.createElement('span'); if (!this.parentToolbox_.isHorizontal()) { Blockly.utils.dom.addClass(toolboxIcon, this.cssConfig_['icon']); toolboxIcon.style.visibility = 'visible'; @@ -192,13 +194,13 @@ Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { * @protected */ Blockly.CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { - var contentsContainer = document.createElement('div'); + const contentsContainer = document.createElement('div'); Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['contents']); - for (var i = 0; i < subcategories.length; i++) { - var newCategory = subcategories[i]; + for (let i = 0; i < subcategories.length; i++) { + const newCategory = subcategories[i]; newCategory.init(); - var newCategoryDiv = newCategory.getDiv(); + const newCategoryDiv = newCategory.getDiv(); contentsContainer.appendChild(newCategoryDiv); if (newCategory.getClickTarget) { newCategory.getClickTarget().setAttribute('id', newCategory.getId()); @@ -236,7 +238,9 @@ Blockly.CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) */ Blockly.CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { this.htmlDiv_.style.display = isVisible ? 'block' : 'none'; - for (var i = 0, child; (child = this.getChildToolboxItems()[i]); i++) { + const childToolboxItems = this.getChildToolboxItems(); + for (let i = 0; i < childToolboxItems.length; i++) { + const child = childToolboxItems[i]; child.setVisible_(isVisible); } this.isHidden_ = !isVisible; From 41b53c50cd4c0e0c83a1d6cb0a28a8a4173048ff Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:41:01 -0700 Subject: [PATCH 410/833] Migrate core/toolbox/collapsible_category.js to goog.module --- core/toolbox/collapsible_category.js | 55 +++++++++++++++------------- tests/deps.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index 4bf907278..50c0a2d5d 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.CollapsibleToolboxCategory'); +goog.module('Blockly.CollapsibleToolboxCategory'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.ICollapsibleToolboxItem'); goog.require('Blockly.registry'); @@ -37,7 +38,7 @@ goog.requireType('Blockly.IToolboxItem'); * @extends {Blockly.ToolboxCategory} * @implements {Blockly.ICollapsibleToolboxItem} */ -Blockly.CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { +const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** * Container for any child categories. * @type {?Element} @@ -59,11 +60,11 @@ Blockly.CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) */ this.toolboxItems_ = []; - Blockly.CollapsibleToolboxCategory.superClass_.constructor.call( + CollapsibleToolboxCategory.superClass_.constructor.call( this, categoryDef, toolbox, opt_parent); }; -Blockly.utils.object.inherits(Blockly.CollapsibleToolboxCategory, Blockly.ToolboxCategory); +Blockly.utils.object.inherits(CollapsibleToolboxCategory, Blockly.ToolboxCategory); /** * All the CSS class names that are used to create a collapsible @@ -80,19 +81,19 @@ Blockly.utils.object.inherits(Blockly.CollapsibleToolboxCategory, Blockly.Toolbo * contents:?string * }} */ -Blockly.CollapsibleToolboxCategory.CssConfig; +CollapsibleToolboxCategory.CssConfig; /** * Name used for registering a collapsible toolbox category. * @const {string} */ -Blockly.CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; +CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { - const cssConfig = Blockly.CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( +CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { + const cssConfig = CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( this); cssConfig['contents'] = 'blocklyToolboxContents'; return cssConfig; @@ -101,7 +102,7 @@ Blockly.CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { +CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { const contents = categoryDef['contents']; let prevIsFlyoutItem = true; @@ -132,7 +133,7 @@ Blockly.CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryD * to create a toolbox item. * @private */ -Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { +CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { let registryName = itemDef['kind']; const categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); @@ -140,7 +141,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemD // a diffferent name. if (registryName.toUpperCase() == 'CATEGORY' && Blockly.utils.toolbox.isCategoryCollapsible(categoryDef)) { - registryName = Blockly.CollapsibleToolboxCategory.registrationName; + registryName = CollapsibleToolboxCategory.registrationName; } const ToolboxItemClass = Blockly.registry.getClass( Blockly.registry.Type.TOOLBOX_ITEM, registryName); @@ -151,8 +152,8 @@ Blockly.CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemD /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.init = function() { - Blockly.CollapsibleToolboxCategory.superClass_.init.call(this); +CollapsibleToolboxCategory.prototype.init = function() { + CollapsibleToolboxCategory.superClass_.init.call(this); this.setExpanded(this.toolboxItemDef_['expanded'] == 'true' || this.toolboxItemDef_['expanded']); @@ -161,8 +162,8 @@ Blockly.CollapsibleToolboxCategory.prototype.init = function() { /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { - Blockly.CollapsibleToolboxCategory.superClass_.createDom_.call(this); +CollapsibleToolboxCategory.prototype.createDom_ = function() { + CollapsibleToolboxCategory.superClass_.createDom_.call(this); const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); @@ -176,7 +177,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createDom_ = function() { /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { +CollapsibleToolboxCategory.prototype.createIconDom_ = function() { const toolboxIcon = document.createElement('span'); if (!this.parentToolbox_.isHorizontal()) { Blockly.utils.dom.addClass(toolboxIcon, this.cssConfig_['icon']); @@ -193,7 +194,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createIconDom_ = function() { * @return {!Element} The div holding all the subcategories. * @protected */ -Blockly.CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { +CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { const contentsContainer = document.createElement('div'); Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['contents']); @@ -215,7 +216,7 @@ Blockly.CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function( * @param {boolean} isExpanded True to expand the category, false to close. * @public */ -Blockly.CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { +CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { if (this.expanded_ == isExpanded) { return; } @@ -236,7 +237,7 @@ Blockly.CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { +CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { this.htmlDiv_.style.display = isVisible ? 'block' : 'none'; const childToolboxItems = this.getChildToolboxItems(); for (let i = 0; i < childToolboxItems.length; i++) { @@ -256,21 +257,21 @@ Blockly.CollapsibleToolboxCategory.prototype.setVisible_ = function(isVisible) { * is collapsed. * @public */ -Blockly.CollapsibleToolboxCategory.prototype.isExpanded = function() { +CollapsibleToolboxCategory.prototype.isExpanded = function() { return this.expanded_; }; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.isCollapsible = function() { +CollapsibleToolboxCategory.prototype.isCollapsible = function() { return true; }; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.onClick = function(_e) { +CollapsibleToolboxCategory.prototype.onClick = function(_e) { this.toggleExpanded(); }; @@ -278,14 +279,14 @@ Blockly.CollapsibleToolboxCategory.prototype.onClick = function(_e) { * Toggles whether or not the category is expanded. * @public */ -Blockly.CollapsibleToolboxCategory.prototype.toggleExpanded = function() { +CollapsibleToolboxCategory.prototype.toggleExpanded = function() { this.setExpanded(!this.expanded_); }; /** * @override */ -Blockly.CollapsibleToolboxCategory.prototype.getDiv = function() { +CollapsibleToolboxCategory.prototype.getDiv = function() { return this.htmlDiv_; }; @@ -293,10 +294,12 @@ Blockly.CollapsibleToolboxCategory.prototype.getDiv = function() { * Gets any children toolbox items. (ex. Gets the subcategories) * @return {!Array} The child toolbox items. */ -Blockly.CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { +CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { return this.toolboxItems_; }; Blockly.registry.register(Blockly.registry.Type.TOOLBOX_ITEM, - Blockly.CollapsibleToolboxCategory.registrationName, Blockly.CollapsibleToolboxCategory); + CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); + +exports = CollapsibleToolboxCategory; diff --git a/tests/deps.js b/tests/deps.js index 20fb4e48e..46ca32e0a 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -166,7 +166,7 @@ goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], [' goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox']); +goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); From d7a864a498677c2cf733b0845f86c17c88bfd6e3 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:42:18 -0700 Subject: [PATCH 411/833] Migrate core/toolbox/collapsible_category.js named requires --- core/toolbox/collapsible_category.js | 71 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index 50c0a2d5d..a35220fb8 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -13,30 +13,29 @@ goog.module('Blockly.CollapsibleToolboxCategory'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.ICollapsibleToolboxItem'); -goog.require('Blockly.registry'); -goog.require('Blockly.ToolboxCategory'); -goog.require('Blockly.ToolboxItem'); -goog.require('Blockly.ToolboxSeparator'); -goog.require('Blockly.utils.aria'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.object'); -goog.require('Blockly.utils.toolbox'); - -goog.requireType('Blockly.IToolbox'); -goog.requireType('Blockly.IToolboxItem'); +const ICollapsibleToolboxItem = goog.require('Blockly.ICollapsibleToolboxItem'); +const IToolbox = goog.requireType('Blockly.IToolbox'); +const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); +const ToolboxCategory = goog.require('Blockly.ToolboxCategory'); +const ToolboxItem = goog.require('Blockly.ToolboxItem'); +const ToolboxSeparator = goog.require('Blockly.ToolboxSeparator'); +const aria = goog.require('Blockly.utils.aria'); +const dom = goog.require('Blockly.utils.dom'); +const object = goog.require('Blockly.utils.object'); +const registry = goog.require('Blockly.registry'); +const toolbox = goog.require('Blockly.utils.toolbox'); /** * Class for a category in a toolbox that can be collapsed. - * @param {!Blockly.utils.toolbox.CategoryInfo} categoryDef The information needed + * @param {!toolbox.CategoryInfo} categoryDef The information needed * to create a category in the toolbox. - * @param {!Blockly.IToolbox} toolbox The parent toolbox for the category. - * @param {Blockly.ICollapsibleToolboxItem=} opt_parent The parent category or null if + * @param {!IToolbox} toolbox The parent toolbox for the category. + * @param {ICollapsibleToolboxItem=} opt_parent The parent category or null if * the category does not have a parent. * @constructor - * @extends {Blockly.ToolboxCategory} - * @implements {Blockly.ICollapsibleToolboxItem} + * @extends {ToolboxCategory} + * @implements {ICollapsibleToolboxItem} */ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** @@ -55,7 +54,7 @@ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** * The child toolbox items for this category. - * @type {!Array} + * @type {!Array} * @protected */ this.toolboxItems_ = []; @@ -64,7 +63,7 @@ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { this, categoryDef, toolbox, opt_parent); }; -Blockly.utils.object.inherits(CollapsibleToolboxCategory, Blockly.ToolboxCategory); +object.inherits(CollapsibleToolboxCategory, ToolboxCategory); /** * All the CSS class names that are used to create a collapsible @@ -113,10 +112,10 @@ CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { const itemDef = contents[i]; // Separators can exist as either a flyout item or a toolbox item so // decide where it goes based on the type of the previous item. - if (!Blockly.registry.hasItem(Blockly.registry.Type.TOOLBOX_ITEM, itemDef['kind']) || - (itemDef['kind'].toLowerCase() == Blockly.ToolboxSeparator.registrationName && + if (!registry.hasItem(registry.Type.TOOLBOX_ITEM, itemDef['kind']) || + (itemDef['kind'].toLowerCase() == ToolboxSeparator.registrationName && prevIsFlyoutItem)) { - const flyoutItem = /** @type {Blockly.utils.toolbox.FlyoutItemInfo} */ (itemDef); + const flyoutItem = /** @type {toolbox.FlyoutItemInfo} */ (itemDef); this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; } else { @@ -129,22 +128,22 @@ CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { /** * Creates a toolbox item and adds it to the list of toolbox items. - * @param {!Blockly.utils.toolbox.ToolboxItemInfo} itemDef The information needed + * @param {!toolbox.ToolboxItemInfo} itemDef The information needed * to create a toolbox item. * @private */ CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { let registryName = itemDef['kind']; - const categoryDef = /** @type {!Blockly.utils.toolbox.CategoryInfo} */ (itemDef); + const categoryDef = /** @type {!toolbox.CategoryInfo} */ (itemDef); // Categories that are collapsible are created using a class registered under // a diffferent name. if (registryName.toUpperCase() == 'CATEGORY' && - Blockly.utils.toolbox.isCategoryCollapsible(categoryDef)) { + toolbox.isCategoryCollapsible(categoryDef)) { registryName = CollapsibleToolboxCategory.registrationName; } - const ToolboxItemClass = Blockly.registry.getClass( - Blockly.registry.Type.TOOLBOX_ITEM, registryName); + const ToolboxItemClass = registry.getClass( + registry.Type.TOOLBOX_ITEM, registryName); const toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); this.toolboxItems_.push(toolboxItem); }; @@ -167,8 +166,8 @@ CollapsibleToolboxCategory.prototype.createDom_ = function() { const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); - Blockly.utils.aria.setRole(this.subcategoriesDiv_, - Blockly.utils.aria.Role.GROUP); + aria.setRole(this.subcategoriesDiv_, + aria.Role.GROUP); this.htmlDiv_.appendChild(this.subcategoriesDiv_); return this.htmlDiv_; @@ -180,7 +179,7 @@ CollapsibleToolboxCategory.prototype.createDom_ = function() { CollapsibleToolboxCategory.prototype.createIconDom_ = function() { const toolboxIcon = document.createElement('span'); if (!this.parentToolbox_.isHorizontal()) { - Blockly.utils.dom.addClass(toolboxIcon, this.cssConfig_['icon']); + dom.addClass(toolboxIcon, this.cssConfig_['icon']); toolboxIcon.style.visibility = 'visible'; } @@ -190,13 +189,13 @@ CollapsibleToolboxCategory.prototype.createIconDom_ = function() { /** * Create the DOM for all subcategories. - * @param {!Array} subcategories The subcategories. + * @param {!Array} subcategories The subcategories. * @return {!Element} The div holding all the subcategories. * @protected */ CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { const contentsContainer = document.createElement('div'); - Blockly.utils.dom.addClass(contentsContainer, this.cssConfig_['contents']); + dom.addClass(contentsContainer, this.cssConfig_['contents']); for (let i = 0; i < subcategories.length; i++) { const newCategory = subcategories[i]; @@ -228,8 +227,8 @@ CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { this.subcategoriesDiv_.style.display = 'none'; this.closeIcon_(this.iconDom_); } - Blockly.utils.aria.setState(/** @type {!Element} */ (this.htmlDiv_), - Blockly.utils.aria.State.EXPANDED, isExpanded); + aria.setState(/** @type {!Element} */ (this.htmlDiv_), + aria.State.EXPANDED, isExpanded); this.parentToolbox_.handleToolboxItemResize(); }; @@ -292,14 +291,14 @@ CollapsibleToolboxCategory.prototype.getDiv = function() { /** * Gets any children toolbox items. (ex. Gets the subcategories) - * @return {!Array} The child toolbox items. + * @return {!Array} The child toolbox items. */ CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { return this.toolboxItems_; }; -Blockly.registry.register(Blockly.registry.Type.TOOLBOX_ITEM, +registry.register(registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); exports = CollapsibleToolboxCategory; From c3521b7eb479781c371d5facd3837964ef4115d1 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:42:23 -0700 Subject: [PATCH 412/833] clang-format core/toolbox/collapsible_category.js --- core/toolbox/collapsible_category.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index a35220fb8..fde610f0c 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -92,8 +92,8 @@ CollapsibleToolboxCategory.registrationName = 'collapsibleCategory'; * @override */ CollapsibleToolboxCategory.prototype.makeDefaultCssConfig_ = function() { - const cssConfig = CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call( - this); + const cssConfig = + CollapsibleToolboxCategory.superClass_.makeDefaultCssConfig_.call(this); cssConfig['contents'] = 'blocklyToolboxContents'; return cssConfig; }; @@ -114,7 +114,7 @@ CollapsibleToolboxCategory.prototype.parseContents_ = function(categoryDef) { // decide where it goes based on the type of the previous item. if (!registry.hasItem(registry.Type.TOOLBOX_ITEM, itemDef['kind']) || (itemDef['kind'].toLowerCase() == ToolboxSeparator.registrationName && - prevIsFlyoutItem)) { + prevIsFlyoutItem)) { const flyoutItem = /** @type {toolbox.FlyoutItemInfo} */ (itemDef); this.flyoutItems_.push(flyoutItem); prevIsFlyoutItem = true; @@ -142,8 +142,8 @@ CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { toolbox.isCategoryCollapsible(categoryDef)) { registryName = CollapsibleToolboxCategory.registrationName; } - const ToolboxItemClass = registry.getClass( - registry.Type.TOOLBOX_ITEM, registryName); + const ToolboxItemClass = + registry.getClass(registry.Type.TOOLBOX_ITEM, registryName); const toolboxItem = new ToolboxItemClass(itemDef, this.parentToolbox_, this); this.toolboxItems_.push(toolboxItem); }; @@ -154,7 +154,8 @@ CollapsibleToolboxCategory.prototype.createToolboxItem_ = function(itemDef) { CollapsibleToolboxCategory.prototype.init = function() { CollapsibleToolboxCategory.superClass_.init.call(this); - this.setExpanded(this.toolboxItemDef_['expanded'] == 'true' || + this.setExpanded( + this.toolboxItemDef_['expanded'] == 'true' || this.toolboxItemDef_['expanded']); }; @@ -166,8 +167,7 @@ CollapsibleToolboxCategory.prototype.createDom_ = function() { const subCategories = this.getChildToolboxItems(); this.subcategoriesDiv_ = this.createSubCategoriesDom_(subCategories); - aria.setRole(this.subcategoriesDiv_, - aria.Role.GROUP); + aria.setRole(this.subcategoriesDiv_, aria.Role.GROUP); this.htmlDiv_.appendChild(this.subcategoriesDiv_); return this.htmlDiv_; @@ -193,7 +193,8 @@ CollapsibleToolboxCategory.prototype.createIconDom_ = function() { * @return {!Element} The div holding all the subcategories. * @protected */ -CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function(subcategories) { +CollapsibleToolboxCategory.prototype.createSubCategoriesDom_ = function( + subcategories) { const contentsContainer = document.createElement('div'); dom.addClass(contentsContainer, this.cssConfig_['contents']); @@ -227,8 +228,8 @@ CollapsibleToolboxCategory.prototype.setExpanded = function(isExpanded) { this.subcategoriesDiv_.style.display = 'none'; this.closeIcon_(this.iconDom_); } - aria.setState(/** @type {!Element} */ (this.htmlDiv_), - aria.State.EXPANDED, isExpanded); + aria.setState( + /** @type {!Element} */ (this.htmlDiv_), aria.State.EXPANDED, isExpanded); this.parentToolbox_.handleToolboxItemResize(); }; @@ -298,7 +299,8 @@ CollapsibleToolboxCategory.prototype.getChildToolboxItems = function() { }; -registry.register(registry.Type.TOOLBOX_ITEM, - CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); +registry.register( + registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, + CollapsibleToolboxCategory); exports = CollapsibleToolboxCategory; From 17bc528039beb9a6d11d2a3f66c3bdc107e883d4 Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 16:52:03 -0700 Subject: [PATCH 413/833] Add eslint disable for requireType in core/toolbox/collapsible_category.js --- core/toolbox/collapsible_category.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index fde610f0c..bc6ea253d 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -14,7 +14,9 @@ goog.module('Blockly.CollapsibleToolboxCategory'); goog.module.declareLegacyNamespace(); const ICollapsibleToolboxItem = goog.require('Blockly.ICollapsibleToolboxItem'); +/* eslint-disable-next-line no-unused-vars */ const IToolbox = goog.requireType('Blockly.IToolbox'); +/* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); const ToolboxCategory = goog.require('Blockly.ToolboxCategory'); const ToolboxItem = goog.require('Blockly.ToolboxItem'); From 7f5ec67860777ec680e61555e4b919ae079b52d2 Mon Sep 17 00:00:00 2001 From: kozbial Date: Thu, 29 Jul 2021 16:50:38 -0700 Subject: [PATCH 414/833] Fix lint warnings in core/toolbox/collapsible_category.js --- core/toolbox/collapsible_category.js | 6 +++--- tests/deps.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/toolbox/collapsible_category.js b/core/toolbox/collapsible_category.js index bc6ea253d..ae243f1e6 100644 --- a/core/toolbox/collapsible_category.js +++ b/core/toolbox/collapsible_category.js @@ -13,13 +13,13 @@ goog.module('Blockly.CollapsibleToolboxCategory'); goog.module.declareLegacyNamespace(); +/* eslint-disable-next-line no-unused-vars */ const ICollapsibleToolboxItem = goog.require('Blockly.ICollapsibleToolboxItem'); /* eslint-disable-next-line no-unused-vars */ const IToolbox = goog.requireType('Blockly.IToolbox'); /* eslint-disable-next-line no-unused-vars */ const IToolboxItem = goog.requireType('Blockly.IToolboxItem'); const ToolboxCategory = goog.require('Blockly.ToolboxCategory'); -const ToolboxItem = goog.require('Blockly.ToolboxItem'); const ToolboxSeparator = goog.require('Blockly.ToolboxSeparator'); const aria = goog.require('Blockly.utils.aria'); const dom = goog.require('Blockly.utils.dom'); @@ -56,7 +56,7 @@ const CollapsibleToolboxCategory = function(categoryDef, toolbox, opt_parent) { /** * The child toolbox items for this category. - * @type {!Array} + * @type {!Array} * @protected */ this.toolboxItems_ = []; @@ -191,7 +191,7 @@ CollapsibleToolboxCategory.prototype.createIconDom_ = function() { /** * Create the DOM for all subcategories. - * @param {!Array} subcategories The subcategories. + * @param {!Array} subcategories The subcategories. * @return {!Element} The div holding all the subcategories. * @protected */ diff --git a/tests/deps.js b/tests/deps.js index 46ca32e0a..613a2793d 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -166,7 +166,7 @@ goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], [' goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); goog.addDependency('../../core/theme_manager.js', ['Blockly.ThemeManager'], ['Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/category.js', ['Blockly.ToolboxCategory'], ['Blockly.ISelectableToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); -goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxItem', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../core/toolbox/collapsible_category.js', ['Blockly.CollapsibleToolboxCategory'], ['Blockly.ICollapsibleToolboxItem', 'Blockly.ToolboxCategory', 'Blockly.ToolboxSeparator', 'Blockly.registry', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/toolbox/separator.js', ['Blockly.ToolboxSeparator'], ['Blockly.IToolboxItem', 'Blockly.ToolboxItem', 'Blockly.registry', 'Blockly.utils.dom'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox.js', ['Blockly.Toolbox'], ['Blockly.BlockSvg', 'Blockly.CollapsibleToolboxCategory', 'Blockly.ComponentManager', 'Blockly.Css', 'Blockly.DeleteArea', 'Blockly.Events', 'Blockly.Events.ToolboxItemSelect', 'Blockly.IAutoHideable', 'Blockly.IKeyboardAccessible', 'Blockly.IStyleable', 'Blockly.IToolbox', 'Blockly.Options', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.aria', 'Blockly.utils.dom', 'Blockly.utils.toolbox'], {'lang': 'es5'}); goog.addDependency('../../core/toolbox/toolbox_item.js', ['Blockly.ToolboxItem'], ['Blockly.IToolboxItem']); From 9f83ade1e7ba6413c6c32d7e0d623a4d36a64893 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:12:17 -0700 Subject: [PATCH 415/833] Migrate core/workspace_comment.js to ES6 const/let --- core/workspace_comment.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 5399dbe39..d71b60c60 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -185,7 +185,7 @@ Blockly.WorkspaceComment.prototype.getXY = function() { * @package */ Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { - var event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); + const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); Blockly.Events.fire(event); @@ -275,7 +275,7 @@ Blockly.WorkspaceComment.prototype.setContent = function(content) { * @package */ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { - var element = this.toXml(opt_noId); + const element = this.toXml(opt_noId); element.setAttribute('x', Math.round(this.xy_.x)); element.setAttribute('y', Math.round(this.xy_.y)); element.setAttribute('h', this.height_); @@ -292,7 +292,7 @@ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @package */ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { - var commentElement = Blockly.utils.xml.createElement('comment'); + const commentElement = Blockly.utils.xml.createElement('comment'); if (!opt_noId) { commentElement.id = this.id; } @@ -307,7 +307,7 @@ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { */ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { if (Blockly.Events.isEnabled()) { - var existingGroup = Blockly.Events.getGroup(); + const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { Blockly.Events.setGroup(true); } @@ -330,13 +330,13 @@ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { * @package */ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { - var info = Blockly.WorkspaceComment.parseAttributes(xmlComment); + const info = Blockly.WorkspaceComment.parseAttributes(xmlComment); - var comment = new Blockly.WorkspaceComment( + const comment = new Blockly.WorkspaceComment( workspace, info.content, info.h, info.w, info.id); - var commentX = parseInt(xmlComment.getAttribute('x'), 10); - var commentY = parseInt(xmlComment.getAttribute('y'), 10); + const commentX = parseInt(xmlComment.getAttribute('x'), 10); + const commentY = parseInt(xmlComment.getAttribute('y'), 10); if (!isNaN(commentX) && !isNaN(commentY)) { comment.moveBy(commentX, commentY); } @@ -353,8 +353,8 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { * @package */ Blockly.WorkspaceComment.parseAttributes = function(xml) { - var xmlH = xml.getAttribute('h'); - var xmlW = xml.getAttribute('w'); + const xmlH = xml.getAttribute('h'); + const xmlW = xml.getAttribute('w'); return { // @type {string} From 2b6f5ba31a399d9a93711a6e8cb878480342dd4b Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:12:28 -0700 Subject: [PATCH 416/833] Migrate core/workspace_comment.js to goog.module --- core/workspace_comment.js | 61 +++++++++++++++++++++------------------ tests/deps.js | 2 +- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index d71b60c60..874877a89 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -10,7 +10,8 @@ */ 'use strict'; -goog.provide('Blockly.WorkspaceComment'); +goog.module('Blockly.WorkspaceComment'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -25,6 +26,8 @@ goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.xml'); +goog.requireType('Blockly.Workspace'); + /** * Class for a workspace comment. @@ -36,7 +39,7 @@ goog.require('Blockly.utils.xml'); * create a new ID. * @constructor */ -Blockly.WorkspaceComment = function(workspace, content, height, width, opt_id) { +const WorkspaceComment = function(workspace, content, height, width, opt_id) { /** @type {string} */ this.id = (opt_id && !workspace.getCommentById(opt_id)) ? opt_id : Blockly.utils.genUid(); @@ -106,14 +109,14 @@ Blockly.WorkspaceComment = function(workspace, content, height, width, opt_id) { */ this.isComment = true; - Blockly.WorkspaceComment.fireCreateEvent(this); + WorkspaceComment.fireCreateEvent(this); }; /** * Dispose of this comment. * @package */ -Blockly.WorkspaceComment.prototype.dispose = function() { +WorkspaceComment.prototype.dispose = function() { if (!this.workspace) { // The comment has already been deleted. return; @@ -137,7 +140,7 @@ Blockly.WorkspaceComment.prototype.dispose = function() { * @return {number} Comment height. * @package */ -Blockly.WorkspaceComment.prototype.getHeight = function() { +WorkspaceComment.prototype.getHeight = function() { return this.height_; }; @@ -146,7 +149,7 @@ Blockly.WorkspaceComment.prototype.getHeight = function() { * @param {number} height Comment height. * @package */ -Blockly.WorkspaceComment.prototype.setHeight = function(height) { +WorkspaceComment.prototype.setHeight = function(height) { this.height_ = height; }; @@ -155,7 +158,7 @@ Blockly.WorkspaceComment.prototype.setHeight = function(height) { * @return {number} Comment width. * @package */ -Blockly.WorkspaceComment.prototype.getWidth = function() { +WorkspaceComment.prototype.getWidth = function() { return this.width_; }; @@ -164,7 +167,7 @@ Blockly.WorkspaceComment.prototype.getWidth = function() { * @param {number} width comment width. * @package */ -Blockly.WorkspaceComment.prototype.setWidth = function(width) { +WorkspaceComment.prototype.setWidth = function(width) { this.width_ = width; }; @@ -174,7 +177,7 @@ Blockly.WorkspaceComment.prototype.setWidth = function(width) { * This is not valid if the comment is currently being dragged. * @package */ -Blockly.WorkspaceComment.prototype.getXY = function() { +WorkspaceComment.prototype.getXY = function() { return new Blockly.utils.Coordinate(this.xy_.x, this.xy_.y); }; @@ -184,7 +187,7 @@ Blockly.WorkspaceComment.prototype.getXY = function() { * @param {number} dy Vertical offset, in workspace units. * @package */ -Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { +WorkspaceComment.prototype.moveBy = function(dx, dy) { const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); @@ -196,7 +199,7 @@ Blockly.WorkspaceComment.prototype.moveBy = function(dx, dy) { * @return {boolean} True if deletable. * @package */ -Blockly.WorkspaceComment.prototype.isDeletable = function() { +WorkspaceComment.prototype.isDeletable = function() { return this.deletable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -206,7 +209,7 @@ Blockly.WorkspaceComment.prototype.isDeletable = function() { * @param {boolean} deletable True if deletable. * @package */ -Blockly.WorkspaceComment.prototype.setDeletable = function(deletable) { +WorkspaceComment.prototype.setDeletable = function(deletable) { this.deletable_ = deletable; }; @@ -215,7 +218,7 @@ Blockly.WorkspaceComment.prototype.setDeletable = function(deletable) { * @return {boolean} True if movable. * @package */ -Blockly.WorkspaceComment.prototype.isMovable = function() { +WorkspaceComment.prototype.isMovable = function() { return this.movable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -225,7 +228,7 @@ Blockly.WorkspaceComment.prototype.isMovable = function() { * @param {boolean} movable True if movable. * @package */ -Blockly.WorkspaceComment.prototype.setMovable = function(movable) { +WorkspaceComment.prototype.setMovable = function(movable) { this.movable_ = movable; }; @@ -233,7 +236,7 @@ Blockly.WorkspaceComment.prototype.setMovable = function(movable) { * Get whether this comment is editable or not. * @return {boolean} True if editable. */ -Blockly.WorkspaceComment.prototype.isEditable = function() { +WorkspaceComment.prototype.isEditable = function() { return this.editable_ && !(this.workspace && this.workspace.options.readOnly); }; @@ -242,7 +245,7 @@ Blockly.WorkspaceComment.prototype.isEditable = function() { * Set whether this comment is editable or not. * @param {boolean} editable True if editable. */ -Blockly.WorkspaceComment.prototype.setEditable = function(editable) { +WorkspaceComment.prototype.setEditable = function(editable) { this.editable_ = editable; }; @@ -251,7 +254,7 @@ Blockly.WorkspaceComment.prototype.setEditable = function(editable) { * @return {string} Comment text. * @package */ -Blockly.WorkspaceComment.prototype.getContent = function() { +WorkspaceComment.prototype.getContent = function() { return this.content_; }; @@ -260,7 +263,7 @@ Blockly.WorkspaceComment.prototype.getContent = function() { * @param {string} content Comment content. * @package */ -Blockly.WorkspaceComment.prototype.setContent = function(content) { +WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.COMMENT_CHANGE))( this, this.content_, content)); @@ -274,7 +277,7 @@ Blockly.WorkspaceComment.prototype.setContent = function(content) { * @return {!Element} Tree of XML elements. * @package */ -Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { +WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { const element = this.toXml(opt_noId); element.setAttribute('x', Math.round(this.xy_.x)); element.setAttribute('y', Math.round(this.xy_.y)); @@ -291,7 +294,7 @@ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @return {!Element} Tree of XML elements. * @package */ -Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { +WorkspaceComment.prototype.toXml = function(opt_noId) { const commentElement = Blockly.utils.xml.createElement('comment'); if (!opt_noId) { commentElement.id = this.id; @@ -302,10 +305,10 @@ Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) { /** * Fire a create event for the given workspace comment, if comments are enabled. - * @param {!Blockly.WorkspaceComment} comment The comment that was just created. + * @param {!WorkspaceComment} comment The comment that was just created. * @package */ -Blockly.WorkspaceComment.fireCreateEvent = function(comment) { +WorkspaceComment.fireCreateEvent = function(comment) { if (Blockly.Events.isEnabled()) { const existingGroup = Blockly.Events.getGroup(); if (!existingGroup) { @@ -326,13 +329,13 @@ Blockly.WorkspaceComment.fireCreateEvent = function(comment) { * Decode an XML comment tag and create a comment on the workspace. * @param {!Element} xmlComment XML comment element. * @param {!Blockly.Workspace} workspace The workspace. - * @return {!Blockly.WorkspaceComment} The created workspace comment. + * @return {!WorkspaceComment} The created workspace comment. * @package */ -Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { - const info = Blockly.WorkspaceComment.parseAttributes(xmlComment); +WorkspaceComment.fromXml = function(xmlComment, workspace) { + const info = WorkspaceComment.parseAttributes(xmlComment); - const comment = new Blockly.WorkspaceComment( + const comment = new WorkspaceComment( workspace, info.content, info.h, info.w, info.id); const commentX = parseInt(xmlComment.getAttribute('x'), 10); @@ -341,7 +344,7 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { comment.moveBy(commentX, commentY); } - Blockly.WorkspaceComment.fireCreateEvent(comment); + WorkspaceComment.fireCreateEvent(comment); return comment; }; @@ -352,7 +355,7 @@ Blockly.WorkspaceComment.fromXml = function(xmlComment, workspace) { * object containing the id, size, position, and comment string. * @package */ -Blockly.WorkspaceComment.parseAttributes = function(xml) { +WorkspaceComment.parseAttributes = function(xml) { const xmlH = xml.getAttribute('h'); const xmlW = xml.getAttribute('w'); @@ -377,3 +380,5 @@ Blockly.WorkspaceComment.parseAttributes = function(xml) { content: xml.textContent }; }; + +exports = WorkspaceComment; diff --git a/tests/deps.js b/tests/deps.js index 613a2793d..f17d995b9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -203,7 +203,7 @@ goog.addDependency('../../core/warning.js', ['Blockly.Warning'], ['Blockly.Bubbl goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.utils.dom']); goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml']); +goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); From b159c382a0ddfe5466a7f919b03b8fcd0d57cd0e Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:15:33 -0700 Subject: [PATCH 417/833] Migrate core/workspace_comment.js named requires --- core/workspace_comment.js | 54 +++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 874877a89..971cbd0a7 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -13,7 +13,12 @@ goog.module('Blockly.WorkspaceComment'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); +const Coordinate = goog.require('Blockly.utils.Coordinate'); +const Events = goog.require('Blockly.Events'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const utils = goog.require('Blockly.utils'); +const xml = goog.require('Blockly.utils.xml'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentChange'); /** @suppress {extraRequire} */ @@ -22,16 +27,11 @@ goog.require('Blockly.Events.CommentCreate'); goog.require('Blockly.Events.CommentDelete'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.CommentMove'); -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.xml'); - -goog.requireType('Blockly.Workspace'); /** * Class for a workspace comment. - * @param {!Blockly.Workspace} workspace The block's workspace. + * @param {!Workspace} workspace The block's workspace. * @param {string} content The content of this workspace comment. * @param {number} height Height of the comment. * @param {number} width Width of the comment. @@ -42,17 +42,17 @@ goog.requireType('Blockly.Workspace'); const WorkspaceComment = function(workspace, content, height, width, opt_id) { /** @type {string} */ this.id = (opt_id && !workspace.getCommentById(opt_id)) ? - opt_id : Blockly.utils.genUid(); + opt_id : utils.genUid(); workspace.addTopComment(this); /** * The comment's position in workspace units. (0, 0) is at the workspace's * origin; scale does not change this value. - * @type {!Blockly.utils.Coordinate} + * @type {!Coordinate} * @protected */ - this.xy_ = new Blockly.utils.Coordinate(0, 0); + this.xy_ = new Coordinate(0, 0); /** * The comment's height in workspace units. Scale does not change this value. @@ -69,7 +69,7 @@ const WorkspaceComment = function(workspace, content, height, width, opt_id) { this.width_ = width; /** - * @type {!Blockly.Workspace} + * @type {!Workspace} */ this.workspace = workspace; @@ -122,9 +122,9 @@ WorkspaceComment.prototype.dispose = function() { return; } - if (Blockly.Events.isEnabled()) { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.COMMENT_DELETE))(this)); + if (Events.isEnabled()) { + Events.fire( + new (Events.get(Events.COMMENT_DELETE))(this)); } // Remove from the list of top comments and the comment database. @@ -173,12 +173,12 @@ WorkspaceComment.prototype.setWidth = function(width) { /** * Get stored location. - * @return {!Blockly.utils.Coordinate} The comment's stored location. + * @return {!Coordinate} The comment's stored location. * This is not valid if the comment is currently being dragged. * @package */ WorkspaceComment.prototype.getXY = function() { - return new Blockly.utils.Coordinate(this.xy_.x, this.xy_.y); + return new Coordinate(this.xy_.x, this.xy_.y); }; /** @@ -188,10 +188,10 @@ WorkspaceComment.prototype.getXY = function() { * @package */ WorkspaceComment.prototype.moveBy = function(dx, dy) { - const event = new (Blockly.Events.get(Blockly.Events.COMMENT_MOVE))(this); + const event = new (Events.get(Events.COMMENT_MOVE))(this); this.xy_.translate(dx, dy); event.recordNew(); - Blockly.Events.fire(event); + Events.fire(event); }; /** @@ -265,7 +265,7 @@ WorkspaceComment.prototype.getContent = function() { */ WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { - Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.COMMENT_CHANGE))( + Events.fire(new (Events.get(Events.COMMENT_CHANGE))( this, this.content_, content)); this.content_ = content; } @@ -295,7 +295,7 @@ WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) { * @package */ WorkspaceComment.prototype.toXml = function(opt_noId) { - const commentElement = Blockly.utils.xml.createElement('comment'); + const commentElement = xml.createElement('comment'); if (!opt_noId) { commentElement.id = this.id; } @@ -309,17 +309,17 @@ WorkspaceComment.prototype.toXml = function(opt_noId) { * @package */ WorkspaceComment.fireCreateEvent = function(comment) { - if (Blockly.Events.isEnabled()) { - const existingGroup = Blockly.Events.getGroup(); + if (Events.isEnabled()) { + const existingGroup = Events.getGroup(); if (!existingGroup) { - Blockly.Events.setGroup(true); + Events.setGroup(true); } try { - Blockly.Events.fire( - new (Blockly.Events.get(Blockly.Events.COMMENT_CREATE))(comment)); + Events.fire( + new (Events.get(Events.COMMENT_CREATE))(comment)); } finally { if (!existingGroup) { - Blockly.Events.setGroup(false); + Events.setGroup(false); } } } @@ -328,7 +328,7 @@ WorkspaceComment.fireCreateEvent = function(comment) { /** * Decode an XML comment tag and create a comment on the workspace. * @param {!Element} xmlComment XML comment element. - * @param {!Blockly.Workspace} workspace The workspace. + * @param {!Workspace} workspace The workspace. * @return {!WorkspaceComment} The created workspace comment. * @package */ From 568c5cb40f6af9d661d6965befa090a15535a721 Mon Sep 17 00:00:00 2001 From: kozbial Date: Mon, 26 Jul 2021 14:16:47 -0700 Subject: [PATCH 418/833] clang-format core/workspace_comment.js --- core/workspace_comment.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/core/workspace_comment.js b/core/workspace_comment.js index 971cbd0a7..8d9009f94 100644 --- a/core/workspace_comment.js +++ b/core/workspace_comment.js @@ -41,8 +41,8 @@ goog.require('Blockly.Events.CommentMove'); */ const WorkspaceComment = function(workspace, content, height, width, opt_id) { /** @type {string} */ - this.id = (opt_id && !workspace.getCommentById(opt_id)) ? - opt_id : utils.genUid(); + this.id = + (opt_id && !workspace.getCommentById(opt_id)) ? opt_id : utils.genUid(); workspace.addTopComment(this); @@ -123,8 +123,7 @@ WorkspaceComment.prototype.dispose = function() { } if (Events.isEnabled()) { - Events.fire( - new (Events.get(Events.COMMENT_DELETE))(this)); + Events.fire(new (Events.get(Events.COMMENT_DELETE))(this)); } // Remove from the list of top comments and the comment database. @@ -219,8 +218,7 @@ WorkspaceComment.prototype.setDeletable = function(deletable) { * @package */ WorkspaceComment.prototype.isMovable = function() { - return this.movable_ && - !(this.workspace && this.workspace.options.readOnly); + return this.movable_ && !(this.workspace && this.workspace.options.readOnly); }; /** @@ -237,8 +235,7 @@ WorkspaceComment.prototype.setMovable = function(movable) { * @return {boolean} True if editable. */ WorkspaceComment.prototype.isEditable = function() { - return this.editable_ && - !(this.workspace && this.workspace.options.readOnly); + return this.editable_ && !(this.workspace && this.workspace.options.readOnly); }; /** @@ -265,8 +262,8 @@ WorkspaceComment.prototype.getContent = function() { */ WorkspaceComment.prototype.setContent = function(content) { if (this.content_ != content) { - Events.fire(new (Events.get(Events.COMMENT_CHANGE))( - this, this.content_, content)); + Events.fire( + new (Events.get(Events.COMMENT_CHANGE))(this, this.content_, content)); this.content_ = content; } }; @@ -315,8 +312,7 @@ WorkspaceComment.fireCreateEvent = function(comment) { Events.setGroup(true); } try { - Events.fire( - new (Events.get(Events.COMMENT_CREATE))(comment)); + Events.fire(new (Events.get(Events.COMMENT_CREATE))(comment)); } finally { if (!existingGroup) { Events.setGroup(false); @@ -335,8 +331,8 @@ WorkspaceComment.fireCreateEvent = function(comment) { WorkspaceComment.fromXml = function(xmlComment, workspace) { const info = WorkspaceComment.parseAttributes(xmlComment); - const comment = new WorkspaceComment( - workspace, info.content, info.h, info.w, info.id); + const comment = + new WorkspaceComment(workspace, info.content, info.h, info.w, info.id); const commentX = parseInt(xmlComment.getAttribute('x'), 10); const commentY = parseInt(xmlComment.getAttribute('y'), 10); From beff5e19bf5e8fab93a7fac6d5f76a34e6ee0c3b Mon Sep 17 00:00:00 2001 From: kozbial Date: Tue, 27 Jul 2021 15:41:33 -0700 Subject: [PATCH 419/833] Combine workspace_comment_render_svg.js with workspace_comment_svg.js --- core/requires.js | 1 - core/workspace_comment_render_svg.js | 463 --------------------- core/workspace_comment_svg.js | 450 ++++++++++++++++++++ tests/deps.js | 3 +- tests/playground.html | 1 - tests/playgrounds/advanced_playground.html | 1 - 6 files changed, 451 insertions(+), 468 deletions(-) delete mode 100644 core/workspace_comment_render_svg.js diff --git a/core/requires.js b/core/requires.js index 2ca295441..cc67f564a 100644 --- a/core/requires.js +++ b/core/requires.js @@ -42,7 +42,6 @@ goog.require('Blockly.Trashcan'); goog.require('Blockly.VariablesDynamic'); // Only need to require these two if you're using workspace comments. // goog.require('Blockly.WorkspaceCommentSvg'); -// goog.require('Blockly.WorkspaceCommentSvg.render'); // If zoom controls aren't required, then Blockly.inject's // "zoom"/"controls" configuration must be false. goog.require('Blockly.ZoomControls'); diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js deleted file mode 100644 index 5097f0c92..000000000 --- a/core/workspace_comment_render_svg.js +++ /dev/null @@ -1,463 +0,0 @@ -/** - * @license - * Copyright 2017 Google LLC - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @fileoverview Methods for rendering a workspace comment as SVG - * @author fenichel@google.com (Rachel Fenichel) - */ -'use strict'; - -goog.provide('Blockly.WorkspaceCommentSvg.render'); - -goog.require('Blockly.utils'); -goog.require('Blockly.utils.Coordinate'); -goog.require('Blockly.utils.dom'); -goog.require('Blockly.utils.Svg'); - - -/** - * Size of the resize icon. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.RESIZE_SIZE = 8; - -/** - * Radius of the border around the comment. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.BORDER_RADIUS = 3; - -/** - * Offset from the foreignobject edge to the textarea edge. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET = 2; - -/** - * Offset from the top to make room for a top bar. - * @type {number} - * @const - * @private - */ -Blockly.WorkspaceCommentSvg.TOP_OFFSET = 10; - -/** - * Returns a bounding box describing the dimensions of this comment. - * @return {!{height: number, width: number}} Object with height and width - * properties in workspace units. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.getHeightWidth = function() { - return { width: this.getWidth(), height: this.getHeight() }; -}; - -/** - * Renders the workspace comment. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.render = function() { - if (this.rendered_) { - return; - } - - var size = this.getHeightWidth(); - - // Add text area - this.createEditor_(); - this.svgGroup_.appendChild(this.foreignObject_); - - this.svgHandleTarget_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, - { - 'class': 'blocklyCommentHandleTarget', - 'x': 0, - 'y': 0 - }); - this.svgGroup_.appendChild(this.svgHandleTarget_); - this.svgRectTarget_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.RECT, - { - 'class': 'blocklyCommentTarget', - 'x': 0, - 'y': 0, - 'rx': Blockly.WorkspaceCommentSvg.BORDER_RADIUS, - 'ry': Blockly.WorkspaceCommentSvg.BORDER_RADIUS - }); - this.svgGroup_.appendChild(this.svgRectTarget_); - - // Add the resize icon - this.addResizeDom_(); - if (this.isDeletable()) { - // Add the delete icon - this.addDeleteDom_(); - } - - this.setSize_(size.width, size.height); - - // Set the content - this.textarea_.value = this.content_; - - this.rendered_ = true; - - if (this.resizeGroup_) { - Blockly.browserEvents.conditionalBind( - this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); - } - - if (this.isDeletable()) { - Blockly.browserEvents.conditionalBind( - this.deleteGroup_, 'mousedown', this, this.deleteMouseDown_); - Blockly.browserEvents.conditionalBind( - this.deleteGroup_, 'mouseout', this, this.deleteMouseOut_); - Blockly.browserEvents.conditionalBind( - this.deleteGroup_, 'mouseup', this, this.deleteMouseUp_); - } -}; - -/** - * Create the text area for the comment. - * @return {!Element} The top-level node of the editor. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() { - /* Create the editor. Here's the markup that will be generated: - - - - - - */ - this.foreignObject_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.FOREIGNOBJECT, - { - 'x': 0, - 'y': Blockly.WorkspaceCommentSvg.TOP_OFFSET, - 'class': 'blocklyCommentForeignObject' - }, - null); - var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); - body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); - body.className = 'blocklyMinimalBody'; - var textarea = document.createElementNS(Blockly.utils.dom.HTML_NS, 'textarea'); - textarea.className = 'blocklyCommentTextarea'; - textarea.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); - textarea.readOnly = !this.isEditable(); - body.appendChild(textarea); - this.textarea_ = textarea; - this.foreignObject_.appendChild(body); - // Don't zoom with mousewheel. - Blockly.browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { - e.stopPropagation(); - }); - Blockly.browserEvents.conditionalBind( - textarea, 'change', this, - function( - /* eslint-disable no-unused-vars */ e - /* eslint-enable no-unused-vars */) { - this.setContent(textarea.value); - }); - return this.foreignObject_; -}; - -/** - * Add the resize icon to the DOM - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.addResizeDom_ = function() { - this.resizeGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, - { - 'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE' - }, - this.svgGroup_); - var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.POLYGON, - {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, - this.resizeGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'class': 'blocklyResizeLine', - 'x1': resizeSize / 3, 'y1': resizeSize - 1, - 'x2': resizeSize - 1, 'y2': resizeSize / 3 - }, this.resizeGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'class': 'blocklyResizeLine', - 'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1, - 'x2': resizeSize - 1, 'y2': resizeSize * 2 / 3 - }, this.resizeGroup_); -}; - -/** - * Add the delete icon to the DOM - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() { - this.deleteGroup_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.G, - { - 'class': 'blocklyCommentDeleteIcon' - }, - this.svgGroup_); - this.deleteIconBorder_ = Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.CIRCLE, - { - 'class': 'blocklyDeleteIconShape', - 'r': '7', - 'cx': '7.5', - 'cy': '7.5' - }, - this.deleteGroup_); - // x icon. - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'x1': '5', 'y1': '10', - 'x2': '10', 'y2': '5', - 'stroke': '#fff', - 'stroke-width': '2' - }, - this.deleteGroup_); - Blockly.utils.dom.createSvgElement( - Blockly.utils.Svg.LINE, - { - 'x1': '5', 'y1': '5', - 'x2': '10', 'y2': '10', - 'stroke': '#fff', - 'stroke-width': '2' - }, - this.deleteGroup_); -}; - -/** - * Handle a mouse-down on comment's resize corner. - * @param {!Event} e Mouse down event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) { - this.unbindDragEvents_(); - if (Blockly.utils.isRightButton(e)) { - // No right-click. - e.stopPropagation(); - return; - } - // Left-click (or middle click) - this.workspace.startDrag(e, new Blockly.utils.Coordinate( - this.workspace.RTL ? -this.width_ : this.width_, this.height_)); - - this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( - document, 'mouseup', this, this.resizeMouseUp_); - this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( - document, 'mousemove', this, this.resizeMouseMove_); - Blockly.hideChaff(); - // This event has been handled. No need to bubble up to the document. - e.stopPropagation(); -}; - -/** - * Handle a mouse-down on comment's delete icon. - * @param {!Event} e Mouse down event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) { - // Highlight the delete icon. - Blockly.utils.dom.addClass( - /** @type {!Element} */ (this.deleteIconBorder_), - 'blocklyDeleteIconHighlighted'); - // This event has been handled. No need to bubble up to the document. - e.stopPropagation(); -}; - -/** - * Handle a mouse-out on comment's delete icon. - * @param {!Event} _e Mouse out event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(_e) { - // Restore highlight on the delete icon. - Blockly.utils.dom.removeClass( - /** @type {!Element} */ (this.deleteIconBorder_), - 'blocklyDeleteIconHighlighted'); -}; - -/** - * Handle a mouse-up on comment's delete icon. - * @param {!Event} e Mouse up event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_ = function(e) { - // Delete this comment. - this.dispose(true, true); - // This event has been handled. No need to bubble up to the document. - e.stopPropagation(); -}; - -/** - * Stop binding to the global mouseup and mousemove events. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_ = function() { - if (this.onMouseUpWrapper_) { - Blockly.browserEvents.unbind(this.onMouseUpWrapper_); - this.onMouseUpWrapper_ = null; - } - if (this.onMouseMoveWrapper_) { - Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); - this.onMouseMoveWrapper_ = null; - } -}; - -/** - * Handle a mouse-up event while dragging a comment's border or resize handle. - * @param {!Event} e Mouse up event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_ = function(/* e */) { - Blockly.Touch.clearTouchIdentifier(); - this.unbindDragEvents_(); -}; - -/** - * Resize this comment to follow the mouse. - * @param {!Event} e Mouse move event. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_ = function(e) { - this.autoLayout_ = false; - var newXY = this.workspace.moveDrag(e); - this.setSize_(this.RTL ? -newXY.x : newXY.x, newXY.y); -}; - -/** - * Callback function triggered when the comment has resized. - * Resize the text area accordingly. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.resizeComment_ = function() { - var size = this.getHeightWidth(); - var topOffset = Blockly.WorkspaceCommentSvg.TOP_OFFSET; - var textOffset = Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET * 2; - - this.foreignObject_.setAttribute('width', size.width); - this.foreignObject_.setAttribute('height', size.height - topOffset); - if (this.RTL) { - this.foreignObject_.setAttribute('x', -size.width); - } - this.textarea_.style.width = (size.width - textOffset) + 'px'; - this.textarea_.style.height = (size.height - textOffset - topOffset) + 'px'; -}; - -/** - * Set size - * @param {number} width width of the container - * @param {number} height height of the container - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.setSize_ = function(width, height) { - // Minimum size of a comment. - width = Math.max(width, 45); - height = Math.max(height, 20 + Blockly.WorkspaceCommentSvg.TOP_OFFSET); - this.width_ = width; - this.height_ = height; - this.svgRect_.setAttribute('width', width); - this.svgRect_.setAttribute('height', height); - this.svgRectTarget_.setAttribute('width', width); - this.svgRectTarget_.setAttribute('height', height); - this.svgHandleTarget_.setAttribute('width', width); - this.svgHandleTarget_.setAttribute('height', - Blockly.WorkspaceCommentSvg.TOP_OFFSET); - if (this.RTL) { - this.svgRect_.setAttribute('transform', 'scale(-1 1)'); - this.svgRectTarget_.setAttribute('transform', 'scale(-1 1)'); - } - - var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; - if (this.resizeGroup_) { - if (this.RTL) { - // Mirror the resize group. - this.resizeGroup_.setAttribute('transform', 'translate(' + - (-width + resizeSize) + ',' + (height - resizeSize) + ') scale(-1 1)'); - this.deleteGroup_.setAttribute('transform', 'translate(' + - (-width + resizeSize) + ',' + (-resizeSize) + ') scale(-1 1)'); - } else { - this.resizeGroup_.setAttribute('transform', 'translate(' + - (width - resizeSize) + ',' + - (height - resizeSize) + ')'); - this.deleteGroup_.setAttribute('transform', 'translate(' + - (width - resizeSize) + ',' + - (-resizeSize) + ')'); - } - } - - // Allow the contents to resize. - this.resizeComment_(); -}; - -/** - * Dispose of any rendered comment components. - * @private - */ -Blockly.WorkspaceCommentSvg.prototype.disposeInternal_ = function() { - this.textarea_ = null; - this.foreignObject_ = null; - this.svgRectTarget_ = null; - this.svgHandleTarget_ = null; - this.disposed_ = true; -}; - -/** - * Set the focus on the text area. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.setFocus = function() { - var comment = this; - this.focused_ = true; - // Defer CSS changes. - setTimeout(function() { - if (comment.disposed_) { - return; - } - comment.textarea_.focus(); - comment.addFocus(); - Blockly.utils.dom.addClass( - comment.svgRectTarget_, 'blocklyCommentTargetFocused'); - Blockly.utils.dom.addClass( - comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); - }, 0); -}; - -/** - * Remove focus from the text area. - * @package - */ -Blockly.WorkspaceCommentSvg.prototype.blurFocus = function() { - var comment = this; - this.focused_ = false; - // Defer CSS changes. - setTimeout(function() { - if (comment.disposed_) { - return; - } - - comment.textarea_.blur(); - comment.removeFocus(); - Blockly.utils.dom.removeClass( - comment.svgRectTarget_, 'blocklyCommentTargetFocused'); - Blockly.utils.dom.removeClass( - comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); - }, 0); -}; diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 401b840e1..84864422b 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -12,6 +12,9 @@ goog.provide('Blockly.WorkspaceCommentSvg'); +goog.require('Blockly'); +goog.require('Blockly.browserEvents'); +goog.require('Blockly.ContextMenu'); goog.require('Blockly.Css'); goog.require('Blockly.Events'); /** @suppress {extraRequire} */ @@ -22,6 +25,7 @@ goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); /** @suppress {extraRequire} */ goog.require('Blockly.Events.Selected'); +goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); @@ -30,9 +34,11 @@ goog.require('Blockly.utils.Rect'); goog.require('Blockly.utils.Svg'); goog.require('Blockly.WorkspaceComment'); +goog.requireType('Blockly.BlockDragSurfaceSvg'); goog.requireType('Blockly.IBoundedElement'); goog.requireType('Blockly.IBubble'); goog.requireType('Blockly.ICopyable'); +goog.requireType('Blockly.Workspace'); /** @@ -116,6 +122,38 @@ Blockly.utils.object.inherits( */ Blockly.WorkspaceCommentSvg.DEFAULT_SIZE = 100; +/** + * Size of the resize icon. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.RESIZE_SIZE = 8; + +/** + * Radius of the border around the comment. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.BORDER_RADIUS = 3; + +/** + * Offset from the foreignobject edge to the textarea edge. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET = 2; + +/** + * Offset from the top to make room for a top bar. + * @type {number} + * @const + * @private + */ +Blockly.WorkspaceCommentSvg.TOP_OFFSET = 10; + /** * Dispose of this comment. * @package @@ -646,6 +684,418 @@ Blockly.WorkspaceCommentSvg.prototype.toCopyData = function() { return {xml: this.toXmlWithXY(), source: this.workspace, typeCounts: null}; }; +/** + * Returns a bounding box describing the dimensions of this comment. + * @return {!{height: number, width: number}} Object with height and width + * properties in workspace units. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.getHeightWidth = function() { + return { width: this.getWidth(), height: this.getHeight() }; +}; + +/** + * Renders the workspace comment. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.render = function() { + if (this.rendered_) { + return; + } + + var size = this.getHeightWidth(); + + // Add text area + this.createEditor_(); + this.svgGroup_.appendChild(this.foreignObject_); + + this.svgHandleTarget_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.RECT, + { + 'class': 'blocklyCommentHandleTarget', + 'x': 0, + 'y': 0 + }); + this.svgGroup_.appendChild(this.svgHandleTarget_); + this.svgRectTarget_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.RECT, + { + 'class': 'blocklyCommentTarget', + 'x': 0, + 'y': 0, + 'rx': Blockly.WorkspaceCommentSvg.BORDER_RADIUS, + 'ry': Blockly.WorkspaceCommentSvg.BORDER_RADIUS + }); + this.svgGroup_.appendChild(this.svgRectTarget_); + + // Add the resize icon + this.addResizeDom_(); + if (this.isDeletable()) { + // Add the delete icon + this.addDeleteDom_(); + } + + this.setSize_(size.width, size.height); + + // Set the content + this.textarea_.value = this.content_; + + this.rendered_ = true; + + if (this.resizeGroup_) { + Blockly.browserEvents.conditionalBind( + this.resizeGroup_, 'mousedown', this, this.resizeMouseDown_); + } + + if (this.isDeletable()) { + Blockly.browserEvents.conditionalBind( + this.deleteGroup_, 'mousedown', this, this.deleteMouseDown_); + Blockly.browserEvents.conditionalBind( + this.deleteGroup_, 'mouseout', this, this.deleteMouseOut_); + Blockly.browserEvents.conditionalBind( + this.deleteGroup_, 'mouseup', this, this.deleteMouseUp_); + } +}; + +/** + * Create the text area for the comment. + * @return {!Element} The top-level node of the editor. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() { + /* Create the editor. Here's the markup that will be generated: + + + + + + */ + this.foreignObject_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.FOREIGNOBJECT, + { + 'x': 0, + 'y': Blockly.WorkspaceCommentSvg.TOP_OFFSET, + 'class': 'blocklyCommentForeignObject' + }, + null); + var body = document.createElementNS(Blockly.utils.dom.HTML_NS, 'body'); + body.setAttribute('xmlns', Blockly.utils.dom.HTML_NS); + body.className = 'blocklyMinimalBody'; + var textarea = document.createElementNS(Blockly.utils.dom.HTML_NS, 'textarea'); + textarea.className = 'blocklyCommentTextarea'; + textarea.setAttribute('dir', this.RTL ? 'RTL' : 'LTR'); + textarea.readOnly = !this.isEditable(); + body.appendChild(textarea); + this.textarea_ = textarea; + this.foreignObject_.appendChild(body); + // Don't zoom with mousewheel. + Blockly.browserEvents.conditionalBind(textarea, 'wheel', this, function(e) { + e.stopPropagation(); + }); + Blockly.browserEvents.conditionalBind( + textarea, 'change', this, + function( + /* eslint-disable no-unused-vars */ e + /* eslint-enable no-unused-vars */) { + this.setContent(textarea.value); + }); + return this.foreignObject_; +}; + +/** + * Add the resize icon to the DOM + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.addResizeDom_ = function() { + this.resizeGroup_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.G, + { + 'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE' + }, + this.svgGroup_); + var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.POLYGON, + {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())}, + this.resizeGroup_); + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'class': 'blocklyResizeLine', + 'x1': resizeSize / 3, 'y1': resizeSize - 1, + 'x2': resizeSize - 1, 'y2': resizeSize / 3 + }, this.resizeGroup_); + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'class': 'blocklyResizeLine', + 'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1, + 'x2': resizeSize - 1, 'y2': resizeSize * 2 / 3 + }, this.resizeGroup_); +}; + +/** + * Add the delete icon to the DOM + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() { + this.deleteGroup_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.G, + { + 'class': 'blocklyCommentDeleteIcon' + }, + this.svgGroup_); + this.deleteIconBorder_ = Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.CIRCLE, + { + 'class': 'blocklyDeleteIconShape', + 'r': '7', + 'cx': '7.5', + 'cy': '7.5' + }, + this.deleteGroup_); + // x icon. + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'x1': '5', 'y1': '10', + 'x2': '10', 'y2': '5', + 'stroke': '#fff', + 'stroke-width': '2' + }, + this.deleteGroup_); + Blockly.utils.dom.createSvgElement( + Blockly.utils.Svg.LINE, + { + 'x1': '5', 'y1': '5', + 'x2': '10', 'y2': '10', + 'stroke': '#fff', + 'stroke-width': '2' + }, + this.deleteGroup_); +}; + +/** + * Handle a mouse-down on comment's resize corner. + * @param {!Event} e Mouse down event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) { + this.unbindDragEvents_(); + if (Blockly.utils.isRightButton(e)) { + // No right-click. + e.stopPropagation(); + return; + } + // Left-click (or middle click) + this.workspace.startDrag(e, new Blockly.utils.Coordinate( + this.workspace.RTL ? -this.width_ : this.width_, this.height_)); + + this.onMouseUpWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mouseup', this, this.resizeMouseUp_); + this.onMouseMoveWrapper_ = Blockly.browserEvents.conditionalBind( + document, 'mousemove', this, this.resizeMouseMove_); + Blockly.hideChaff(); + // This event has been handled. No need to bubble up to the document. + e.stopPropagation(); +}; + +/** + * Handle a mouse-down on comment's delete icon. + * @param {!Event} e Mouse down event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) { + // Highlight the delete icon. + Blockly.utils.dom.addClass( + /** @type {!Element} */ (this.deleteIconBorder_), + 'blocklyDeleteIconHighlighted'); + // This event has been handled. No need to bubble up to the document. + e.stopPropagation(); +}; + +/** + * Handle a mouse-out on comment's delete icon. + * @param {!Event} _e Mouse out event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(_e) { + // Restore highlight on the delete icon. + Blockly.utils.dom.removeClass( + /** @type {!Element} */ (this.deleteIconBorder_), + 'blocklyDeleteIconHighlighted'); +}; + +/** + * Handle a mouse-up on comment's delete icon. + * @param {!Event} e Mouse up event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_ = function(e) { + // Delete this comment. + this.dispose(true, true); + // This event has been handled. No need to bubble up to the document. + e.stopPropagation(); +}; + +/** + * Stop binding to the global mouseup and mousemove events. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_ = function() { + if (this.onMouseUpWrapper_) { + Blockly.browserEvents.unbind(this.onMouseUpWrapper_); + this.onMouseUpWrapper_ = null; + } + if (this.onMouseMoveWrapper_) { + Blockly.browserEvents.unbind(this.onMouseMoveWrapper_); + this.onMouseMoveWrapper_ = null; + } +}; + +/** + * Handle a mouse-up event while dragging a comment's border or resize handle. + * @param {!Event} e Mouse up event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_ = function(/* e */) { + Blockly.Touch.clearTouchIdentifier(); + this.unbindDragEvents_(); +}; + +/** + * Resize this comment to follow the mouse. + * @param {!Event} e Mouse move event. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_ = function(e) { + this.autoLayout_ = false; + var newXY = this.workspace.moveDrag(e); + this.setSize_(this.RTL ? -newXY.x : newXY.x, newXY.y); +}; + +/** + * Callback function triggered when the comment has resized. + * Resize the text area accordingly. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.resizeComment_ = function() { + var size = this.getHeightWidth(); + var topOffset = Blockly.WorkspaceCommentSvg.TOP_OFFSET; + var textOffset = Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET * 2; + + this.foreignObject_.setAttribute('width', size.width); + this.foreignObject_.setAttribute('height', size.height - topOffset); + if (this.RTL) { + this.foreignObject_.setAttribute('x', -size.width); + } + this.textarea_.style.width = (size.width - textOffset) + 'px'; + this.textarea_.style.height = (size.height - textOffset - topOffset) + 'px'; +}; + +/** + * Set size + * @param {number} width width of the container + * @param {number} height height of the container + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.setSize_ = function(width, height) { + // Minimum size of a comment. + width = Math.max(width, 45); + height = Math.max(height, 20 + Blockly.WorkspaceCommentSvg.TOP_OFFSET); + this.width_ = width; + this.height_ = height; + this.svgRect_.setAttribute('width', width); + this.svgRect_.setAttribute('height', height); + this.svgRectTarget_.setAttribute('width', width); + this.svgRectTarget_.setAttribute('height', height); + this.svgHandleTarget_.setAttribute('width', width); + this.svgHandleTarget_.setAttribute('height', + Blockly.WorkspaceCommentSvg.TOP_OFFSET); + if (this.RTL) { + this.svgRect_.setAttribute('transform', 'scale(-1 1)'); + this.svgRectTarget_.setAttribute('transform', 'scale(-1 1)'); + } + + var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE; + if (this.resizeGroup_) { + if (this.RTL) { + // Mirror the resize group. + this.resizeGroup_.setAttribute('transform', 'translate(' + + (-width + resizeSize) + ',' + (height - resizeSize) + ') scale(-1 1)'); + this.deleteGroup_.setAttribute('transform', 'translate(' + + (-width + resizeSize) + ',' + (-resizeSize) + ') scale(-1 1)'); + } else { + this.resizeGroup_.setAttribute('transform', 'translate(' + + (width - resizeSize) + ',' + + (height - resizeSize) + ')'); + this.deleteGroup_.setAttribute('transform', 'translate(' + + (width - resizeSize) + ',' + + (-resizeSize) + ')'); + } + } + + // Allow the contents to resize. + this.resizeComment_(); +}; + +/** + * Dispose of any rendered comment components. + * @private + */ +Blockly.WorkspaceCommentSvg.prototype.disposeInternal_ = function() { + this.textarea_ = null; + this.foreignObject_ = null; + this.svgRectTarget_ = null; + this.svgHandleTarget_ = null; + this.disposed_ = true; +}; + +/** + * Set the focus on the text area. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.setFocus = function() { + var comment = this; + this.focused_ = true; + // Defer CSS changes. + setTimeout(function() { + if (comment.disposed_) { + return; + } + comment.textarea_.focus(); + comment.addFocus(); + Blockly.utils.dom.addClass( + comment.svgRectTarget_, 'blocklyCommentTargetFocused'); + Blockly.utils.dom.addClass( + comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); + }, 0); +}; + +/** + * Remove focus from the text area. + * @package + */ +Blockly.WorkspaceCommentSvg.prototype.blurFocus = function() { + var comment = this; + this.focused_ = false; + // Defer CSS changes. + setTimeout(function() { + if (comment.disposed_) { + return; + } + + comment.textarea_.blur(); + comment.removeFocus(); + Blockly.utils.dom.removeClass( + comment.svgRectTarget_, 'blocklyCommentTargetFocused'); + Blockly.utils.dom.removeClass( + comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); + }, 0); +}; + /** * CSS for workspace comment. See css.js for use. */ diff --git a/tests/deps.js b/tests/deps.js index f17d995b9..a729ae7b9 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -204,8 +204,7 @@ goog.addDependency('../../core/widgetdiv.js', ['Blockly.WidgetDiv'], ['Blockly.u goog.addDependency('../../core/workspace.js', ['Blockly.Workspace'], ['Blockly.ConnectionChecker', 'Blockly.Events', 'Blockly.IASTNodeLocation', 'Blockly.Options', 'Blockly.VariableMap', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.math']); goog.addDependency('../../core/workspace_audio.js', ['Blockly.WorkspaceAudio'], ['Blockly.internalConstants', 'Blockly.utils.global', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/workspace_comment.js', ['Blockly.WorkspaceComment'], ['Blockly.Events', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/workspace_comment_render_svg.js', ['Blockly.WorkspaceCommentSvg.render'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']); -goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.WorkspaceComment', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); +goog.addDependency('../../core/workspace_comment_svg.js', ['Blockly.WorkspaceCommentSvg'], ['Blockly', 'Blockly.ContextMenu', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove', 'Blockly.Events.Selected', 'Blockly.Touch', 'Blockly.WorkspaceComment', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object']); goog.addDependency('../../core/workspace_drag_surface_svg.js', ['Blockly.WorkspaceDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/workspace_dragger.js', ['Blockly.WorkspaceDragger'], ['Blockly.utils.Coordinate']); goog.addDependency('../../core/workspace_svg.js', ['Blockly.WorkspaceSvg'], ['Blockly.BlockSvg', 'Blockly.ComponentManager', 'Blockly.ConnectionDB', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.ThemeChange', 'Blockly.Events.ViewportChange', 'Blockly.Gesture', 'Blockly.Grid', 'Blockly.IASTNodeLocationSvg', 'Blockly.MarkerManager', 'Blockly.MetricsManager', 'Blockly.Msg', 'Blockly.Options', 'Blockly.ThemeManager', 'Blockly.Themes.Classic', 'Blockly.TouchGesture', 'Blockly.Workspace', 'Blockly.WorkspaceAudio', 'Blockly.WorkspaceDragSurfaceSvg', 'Blockly.Xml', 'Blockly.blockRendering', 'Blockly.browserEvents', 'Blockly.internalConstants', 'Blockly.registry', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.toolbox'], {'lang': 'es5'}); diff --git a/tests/playground.html b/tests/playground.html index 11179a0db..b53e76ea8 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -71,7 +71,6 @@