From 4f74210e74ef0b06216ab0f288268192674d69c9 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 31 Jan 2022 18:36:10 +0000 Subject: [PATCH 1/2] fix!: Export loopTypes from Blockly.blocks.loops (#5900) * refactor(blocks): Make loopTypes a Set This is likely to slightly improve performance, especially if there are many entries. * refactor(blocks): Re-export individual block modules from Blockly.blocks.all * fix!(blocks): Have blocks_compressed.js export Blockly.blocks.all Previously the value obtained by const blocks = require('blockly/blocks'); // Node.js or import blocks from 'blockly/blocks.js'; // ES Modules would be the block definitions dictionary (Blockly.Blocks). Change this so that it is instead the export object from Blockly.blocks.all. This means you can now access loopTypes via: import blocks from 'blockly/blocks.js'; blocks.loops.loopTypes.add('my_loop_blocktype'); This is a breaking change for any code which depended on the value that was exported by blocks_compressed.js. BREAKING CHANGE: the exports provided by blocks_compressed.js (and therefore by `import ... from 'blockly/blocks'`) have changed; see above. --- blocks/all.js | 31 ++++++++++++++++++++++--------- blocks/loops.js | 12 ++++++------ scripts/gulpfiles/build_tasks.js | 6 +++--- tests/deps.js | 2 +- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/blocks/all.js b/blocks/all.js index 17000f8c96d..b145d4107d7 100644 --- a/blocks/all.js +++ b/blocks/all.js @@ -11,13 +11,26 @@ 'use strict'; goog.module('Blockly.blocks.all'); +goog.module.declareLegacyNamespace(); + +const colour = goog.require('Blockly.blocks.colour'); +const lists = goog.require('Blockly.blocks.lists'); +const logic = goog.require('Blockly.blocks.logic'); +const loops = goog.require('Blockly.blocks.loops'); +const math = goog.require('Blockly.blocks.math'); +const procedures = goog.require('Blockly.blocks.procedures'); +const texts = goog.require('Blockly.blocks.texts'); +const variables = goog.require('Blockly.blocks.variables'); +const variablesDynamic = goog.require('Blockly.blocks.variablesDynamic'); + + +exports.colour = colour; +exports.lists = lists; +exports.logic = logic; +exports.loops = loops; +exports.math = math; +exports.procedures = procedures; +exports.texts = texts; +exports.variables = variables; +exports.variablesDynamic = variablesDynamic; -goog.require('Blockly.blocks.colour'); -goog.require('Blockly.blocks.lists'); -goog.require('Blockly.blocks.logic'); -goog.require('Blockly.blocks.loops'); -goog.require('Blockly.blocks.math'); -goog.require('Blockly.blocks.procedures'); -goog.require('Blockly.blocks.texts'); -goog.require('Blockly.blocks.variables'); -goog.require('Blockly.blocks.variablesDynamic'); diff --git a/blocks/loops.js b/blocks/loops.js index cc3c27d371f..21e66ece3ad 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -287,21 +287,21 @@ Extensions.register( * * // If using the Blockly npm package and es6 import syntax: * import {loopTypes} from 'blockly/blocks'; - * loopTypes.push('custom_loop'); + * loopTypes.add('custom_loop'); * * // Else if using Closure Compiler and goog.modules: * const {loopTypes} = goog.require('Blockly.blocks.loops'); - * loopTypes.push('custom_loop'); + * loopTypes.add('custom_loop'); * - * @type {!Array} + * @type {!Set} */ -const loopTypes = [ +const loopTypes = new Set([ 'controls_repeat', 'controls_repeat_ext', 'controls_forEach', 'controls_for', 'controls_whileUntil', -]; +]); exports.loopTypes = loopTypes; /** @@ -321,7 +321,7 @@ const CONTROL_FLOW_IN_LOOP_CHECK_MIXIN = { getSurroundLoop: function() { let block = this; do { - if (loopTypes.includes(block.type)) { + if (loopTypes.has(block.type)) { return block; } block = block.getSurroundParent(); diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index aeec016fb76..4706461d6fe 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -107,7 +107,7 @@ const chunks = [ }, { name: 'blocks', entry: 'blocks/all.js', - exports: 'Blockly.Blocks', + exports: 'Blockly.blocks.all', importAs: 'BlocklyBlocks', }, { name: 'javascript', @@ -314,7 +314,7 @@ function chunkWrapper(chunk) { const cjsDeps = fileNames.map(f => `require(${f})`).join(', '); const browserDeps = chunk.dependencies.map(d => `root.${d.exports}`).join(', '); - const imports = chunk.dependencies.map(d => d.importAs).join(', '); + const factoryParams = chunk.dependencies.map(d => d.importAs).join(', '); return `// Do not edit this file; automatically generated. /* eslint-disable */ @@ -326,7 +326,7 @@ function chunkWrapper(chunk) { } else { // Browser root.${chunk.exports} = factory(${browserDeps}); } -}(this, function(${imports}) { +}(this, function(${factoryParams}) { ${chunk.factoryPreamble || FACTORY_PREAMBLE} %output% ${chunk.factoryPostamble || FACTORY_POSTAMBLE} diff --git a/tests/deps.js b/tests/deps.js index a46277b5ad4..10e89592bf4 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -1,4 +1,4 @@ -goog.addDependency('../../blocks/all.js', ['Blockly.blocks.all'], ['Blockly.blocks.colour', 'Blockly.blocks.lists', 'Blockly.blocks.logic', 'Blockly.blocks.loops', 'Blockly.blocks.math', 'Blockly.blocks.procedures', 'Blockly.blocks.texts', 'Blockly.blocks.variables', 'Blockly.blocks.variablesDynamic'], {'module': 'goog'}); +goog.addDependency('../../blocks/all.js', ['Blockly.blocks.all'], ['Blockly.blocks.colour', 'Blockly.blocks.lists', 'Blockly.blocks.logic', 'Blockly.blocks.loops', 'Blockly.blocks.math', 'Blockly.blocks.procedures', 'Blockly.blocks.texts', 'Blockly.blocks.variables', 'Blockly.blocks.variablesDynamic'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/colour.js', ['Blockly.blocks.colour'], ['Blockly.FieldColour', 'Blockly.common'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/lists.js', ['Blockly.blocks.lists'], ['Blockly.ConnectionType', 'Blockly.FieldDropdown', 'Blockly.FieldDropdown', 'Blockly.Input', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.blocks', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../blocks/logic.js', ['Blockly.blocks.logic'], ['Blockly.Events', 'Blockly.Extensions', 'Blockly.FieldDropdown', 'Blockly.FieldLabel', 'Blockly.Msg', 'Blockly.Mutator', 'Blockly.common', 'Blockly.utils.xml'], {'lang': 'es6', 'module': 'goog'}); From 6037694a9998a2c1ebce08c79162cd47613a71f6 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Wed, 9 Feb 2022 16:23:25 -0800 Subject: [PATCH 2/2] release: bump version and rebuild --- blockly_compressed.js | 20 ++++++++++++++++---- blockly_compressed.js.map | 2 +- blocks_compressed.js | 11 ++++++----- blocks_compressed.js.map | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/blockly_compressed.js b/blockly_compressed.js index 81f757cfc59..b101baeb49d 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -38,9 +38,21 @@ $jscomp.polyfill("Object.setPrototypeOf",function(a){return a||$jscomp.setProtot $jscomp.polyfill("Object.getOwnPropertySymbols",function(a){return a?a:function(){return[]}},"es6","es5");$jscomp.polyfill("Reflect.ownKeys",function(a){return a?a:function(b){var c=[],d=Object.getOwnPropertyNames(b);b=Object.getOwnPropertySymbols(b);for(var e=0;ec&&(c=Math.max(0,e+c));if(null==d||d>e)d=e;d=Number(d);0>d&&(d=Math.max(0,e+d));for(c=Number(c||0);cc&&(c=Math.max(c+e,0));c>>/g,a),module$exports$Blockly$Css.content="",a=document.createElement("style"),a.id="blockly-common-style",b=document.createTextNode(b),a.appendChild(b),document.head.insertBefore(a,document.head.firstChild)))};module$exports$Blockly$Css.content='\n .blocklySvg {\n background-color: #fff;\n outline: none;\n overflow: hidden; /* IE overflows by default. */\n position: absolute;\n display: block;\n }\n\n .blocklyWidgetDiv {\n display: none;\n position: absolute;\n z-index: 99999; /* big value for bootstrap3 compatibility */\n }\n\n .injectionDiv {\n height: 100%;\n position: relative;\n overflow: hidden; /* So blocks in drag surface disappear at edges */\n touch-action: none;\n }\n\n .blocklyNonSelectable {\n user-select: none;\n -ms-user-select: none;\n -webkit-user-select: none;\n }\n\n .blocklyWsDragSurface {\n display: none;\n position: absolute;\n top: 0;\n left: 0;\n }\n\n /* Added as a separate rule with multiple classes to make it more specific\n than a bootstrap rule that selects svg:root. See issue #1275 for context.\n */\n .blocklyWsDragSurface.blocklyOverflowVisible {\n overflow: visible;\n }\n\n .blocklyBlockDragSurface {\n display: none;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n overflow: visible !important;\n z-index: 50; /* Display below toolbox, but above everything else. */\n }\n\n .blocklyBlockCanvas.blocklyCanvasTransitioning,\n .blocklyBubbleCanvas.blocklyCanvasTransitioning {\n transition: transform .5s;\n }\n\n .blocklyTooltipDiv {\n background-color: #ffffc7;\n border: 1px solid #ddc;\n box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);\n color: #000;\n display: none;\n font: 9pt sans-serif;\n opacity: .9;\n padding: 2px;\n position: absolute;\n z-index: 100000; /* big value for bootstrap3 compatibility */\n }\n\n .blocklyDropDownDiv {\n position: absolute;\n left: 0;\n top: 0;\n z-index: 1000;\n display: none;\n border: 1px solid;\n border-color: #dadce0;\n background-color: #fff;\n border-radius: 2px;\n padding: 4px;\n box-shadow: 0 0 3px 1px rgba(0,0,0,.3);\n }\n\n .blocklyDropDownDiv.blocklyFocused {\n box-shadow: 0 0 6px 1px rgba(0,0,0,.3);\n }\n\n .blocklyDropDownContent {\n max-height: 300px; // @todo: spec for maximum height.\n overflow: auto;\n overflow-x: hidden;\n position: relative;\n }\n\n .blocklyDropDownArrow {\n position: absolute;\n left: 0;\n top: 0;\n width: 16px;\n height: 16px;\n z-index: -1;\n background-color: inherit;\n border-color: inherit;\n }\n\n .blocklyDropDownButton {\n display: inline-block;\n float: left;\n padding: 0;\n margin: 4px;\n border-radius: 4px;\n outline: none;\n border: 1px solid;\n transition: box-shadow .1s;\n cursor: pointer;\n }\n\n .blocklyArrowTop {\n border-top: 1px solid;\n border-left: 1px solid;\n border-top-left-radius: 4px;\n border-color: inherit;\n }\n\n .blocklyArrowBottom {\n border-bottom: 1px solid;\n border-right: 1px solid;\n border-bottom-right-radius: 4px;\n border-color: inherit;\n }\n\n .blocklyResizeSE {\n cursor: se-resize;\n fill: #aaa;\n }\n\n .blocklyResizeSW {\n cursor: sw-resize;\n fill: #aaa;\n }\n\n .blocklyResizeLine {\n stroke: #515A5A;\n stroke-width: 1;\n }\n\n .blocklyHighlightedConnectionPath {\n fill: none;\n stroke: #fc3;\n stroke-width: 4px;\n }\n\n .blocklyPathLight {\n fill: none;\n stroke-linecap: round;\n stroke-width: 1;\n }\n\n .blocklySelected>.blocklyPathLight {\n display: none;\n }\n\n .blocklyDraggable {\n /* backup for browsers (e.g. IE11) that don\'t support grab */\n cursor: url("<<>>/handopen.cur"), auto;\n cursor: grab;\n cursor: -webkit-grab;\n }\n\n /* backup for browsers (e.g. IE11) that don\'t support grabbing */\n .blocklyDragging {\n /* backup for browsers (e.g. IE11) that don\'t support grabbing */\n cursor: url("<<>>/handclosed.cur"), auto;\n cursor: grabbing;\n cursor: -webkit-grabbing;\n }\n\n /* Changes cursor on mouse down. Not effective in Firefox because of\n https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */\n .blocklyDraggable:active {\n /* backup for browsers (e.g. IE11) that don\'t support grabbing */\n cursor: url("<<>>/handclosed.cur"), auto;\n cursor: grabbing;\n cursor: -webkit-grabbing;\n }\n\n /* Change the cursor on the whole drag surface in case the mouse gets\n ahead of block during a drag. This way the cursor is still a closed hand.\n */\n .blocklyBlockDragSurface .blocklyDraggable {\n /* backup for browsers (e.g. IE11) that don\'t support grabbing */\n cursor: url("<<>>/handclosed.cur"), auto;\n cursor: grabbing;\n cursor: -webkit-grabbing;\n }\n\n .blocklyDragging.blocklyDraggingDelete {\n cursor: url("<<>>/handdelete.cur"), auto;\n }\n\n .blocklyDragging>.blocklyPath,\n .blocklyDragging>.blocklyPathLight {\n fill-opacity: .8;\n stroke-opacity: .8;\n }\n\n .blocklyDragging>.blocklyPathDark {\n display: none;\n }\n\n .blocklyDisabled>.blocklyPath {\n fill-opacity: .5;\n stroke-opacity: .5;\n }\n\n .blocklyDisabled>.blocklyPathLight,\n .blocklyDisabled>.blocklyPathDark {\n display: none;\n }\n\n .blocklyInsertionMarker>.blocklyPath,\n .blocklyInsertionMarker>.blocklyPathLight,\n .blocklyInsertionMarker>.blocklyPathDark {\n fill-opacity: .2;\n stroke: none;\n }\n\n .blocklyMultilineText {\n font-family: monospace;\n }\n\n .blocklyNonEditableText>text {\n pointer-events: none;\n }\n\n .blocklyFlyout {\n position: absolute;\n z-index: 20;\n }\n\n .blocklyText text {\n cursor: default;\n }\n\n /*\n Don\'t allow users to select text. It gets annoying when trying to\n drag a block and selected text moves instead.\n */\n .blocklySvg text,\n .blocklyBlockDragSurface text {\n user-select: none;\n -ms-user-select: none;\n -webkit-user-select: none;\n cursor: inherit;\n }\n\n .blocklyHidden {\n display: none;\n }\n\n .blocklyFieldDropdown:not(.blocklyHidden) {\n display: block;\n }\n\n .blocklyIconGroup {\n cursor: default;\n }\n\n .blocklyIconGroup:not(:hover),\n .blocklyIconGroupReadonly {\n opacity: .6;\n }\n\n .blocklyIconShape {\n fill: #00f;\n stroke: #fff;\n stroke-width: 1px;\n }\n\n .blocklyIconSymbol {\n fill: #fff;\n }\n\n .blocklyMinimalBody {\n margin: 0;\n padding: 0;\n }\n\n .blocklyHtmlInput {\n border: none;\n border-radius: 4px;\n height: 100%;\n margin: 0;\n outline: none;\n padding: 0;\n width: 100%;\n text-align: center;\n display: block;\n box-sizing: border-box;\n }\n\n /* Edge and IE introduce a close icon when the input value is longer than a\n certain length. This affects our sizing calculations of the text input.\n Hiding the close icon to avoid that. */\n .blocklyHtmlInput::-ms-clear {\n display: none;\n }\n\n .blocklyMainBackground {\n stroke-width: 1;\n stroke: #c6c6c6; /* Equates to #ddd due to border being off-pixel. */\n }\n\n .blocklyMutatorBackground {\n fill: #fff;\n stroke: #ddd;\n stroke-width: 1;\n }\n\n .blocklyFlyoutBackground {\n fill: #ddd;\n fill-opacity: .8;\n }\n\n .blocklyMainWorkspaceScrollbar {\n z-index: 20;\n }\n\n .blocklyFlyoutScrollbar {\n z-index: 30;\n }\n\n .blocklyScrollbarHorizontal,\n .blocklyScrollbarVertical {\n position: absolute;\n outline: none;\n }\n\n .blocklyScrollbarBackground {\n opacity: 0;\n }\n\n .blocklyScrollbarHandle {\n fill: #ccc;\n }\n\n .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,\n .blocklyScrollbarHandle:hover {\n fill: #bbb;\n }\n\n /* Darken flyout scrollbars due to being on a grey background. */\n /* By contrast, workspace scrollbars are on a white background. */\n .blocklyFlyout .blocklyScrollbarHandle {\n fill: #bbb;\n }\n\n .blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,\n .blocklyFlyout .blocklyScrollbarHandle:hover {\n fill: #aaa;\n }\n\n .blocklyInvalidInput {\n background: #faa;\n }\n\n .blocklyVerticalMarker {\n stroke-width: 3px;\n fill: rgba(255,255,255,.5);\n pointer-events: none;\n }\n\n .blocklyComputeCanvas {\n position: absolute;\n width: 0;\n height: 0;\n }\n\n .blocklyNoPointerEvents {\n pointer-events: none;\n }\n\n .blocklyContextMenu {\n border-radius: 4px;\n max-height: 100%;\n }\n\n .blocklyDropdownMenu {\n border-radius: 2px;\n padding: 0 !important;\n }\n\n .blocklyDropdownMenu .blocklyMenuItem {\n /* 28px on the left for icon or checkbox. */\n padding-left: 28px;\n }\n\n /* BiDi override for the resting state. */\n .blocklyDropdownMenu .blocklyMenuItemRtl {\n /* Flip left/right padding for BiDi. */\n padding-left: 5px;\n padding-right: 28px;\n }\n\n .blocklyWidgetDiv .blocklyMenu {\n background: #fff;\n border: 1px solid transparent;\n box-shadow: 0 0 3px 1px rgba(0,0,0,.3);\n font: normal 13px Arial, sans-serif;\n margin: 0;\n outline: none;\n padding: 4px 0;\n position: absolute;\n overflow-y: auto;\n overflow-x: hidden;\n max-height: 100%;\n z-index: 20000; /* Arbitrary, but some apps depend on it... */\n }\n\n .blocklyWidgetDiv .blocklyMenu.blocklyFocused {\n box-shadow: 0 0 6px 1px rgba(0,0,0,.3);\n }\n\n .blocklyDropDownDiv .blocklyMenu {\n background: inherit; /* Compatibility with gapi, reset from goog-menu */\n border: inherit; /* Compatibility with gapi, reset from goog-menu */\n font: normal 13px "Helvetica Neue", Helvetica, sans-serif;\n outline: none;\n position: relative; /* Compatibility with gapi, reset from goog-menu */\n z-index: 20000; /* Arbitrary, but some apps depend on it... */\n }\n\n /* State: resting. */\n .blocklyMenuItem {\n border: none;\n color: #000;\n cursor: pointer;\n list-style: none;\n margin: 0;\n /* 7em on the right for shortcut. */\n min-width: 7em;\n padding: 6px 15px;\n white-space: nowrap;\n }\n\n /* State: disabled. */\n .blocklyMenuItemDisabled {\n color: #ccc;\n cursor: inherit;\n }\n\n /* State: hover. */\n .blocklyMenuItemHighlight {\n background-color: rgba(0,0,0,.1);\n }\n\n /* State: selected/checked. */\n .blocklyMenuItemCheckbox {\n height: 16px;\n position: absolute;\n width: 16px;\n }\n\n .blocklyMenuItemSelected .blocklyMenuItemCheckbox {\n background: url(<<>>/sprites.png) no-repeat -48px -16px;\n float: left;\n margin-left: -24px;\n position: static; /* Scroll with the menu. */\n }\n\n .blocklyMenuItemRtl .blocklyMenuItemCheckbox {\n float: right;\n margin-right: -24px;\n }\n';var module$contents$Blockly$utils$string_wrapLine,module$contents$Blockly$utils$string_wrapScore,module$contents$Blockly$utils$string_wrapMutate,module$contents$Blockly$utils$string_wrapToText; $.module$exports$Blockly$utils$string={startsWith:function(a,b){return 0===a.lastIndexOf(b,0)},shortestStringLength:function(a){return a.length?a.reduce(function(b,c){return b.length