Commit Graph

3880 Commits

Author SHA1 Message Date
Christopher Allen
00a75ca048 refactor: Be more selective in eslint ignorance (#5955)
Rather than ignoring blockly_uncompressed.js, gulpfile.js and
core/utils/global.js entirely, add suitable eslint-disable directives
to those files so that they lint cleanly (and migrate gulpfile to
use const instead of var).
2022-02-23 22:12:15 +00:00
Beka Westberg
be9ca98cdc refactor: convert toolbox items to ES6 classes (#5947)
* refact: convert toolbox items to ES6 classes

* fix: and SENTINEL so that contents can be parsed properly

* fix: fix types and whatnot related to new SENTINEL

* clean: format

* refactor: reorganize overridable calls into the init function, and remove sentinel

* clean: format

* fix: inline docs and organization
2022-02-22 15:21:23 -08:00
Rachel Fenichel
f1148f1732 refactor: convert registry files to es6 classes (#5940)
* refactor: convert shortcut registry to es6 class

* refactor: convert context menu registry to es6 class

* refactor: convert registry type to es6 class

* chore: format

* chore: respond to PR comments
2022-02-18 11:36:41 -08:00
Rachel Fenichel
b52c65c810 refactor: convert some classes to ES6 classes (#5928)
* refactor: move optional function declarations into the constructor

* refactor: convert options.js to es6 class

* refactor: convert generator.js to es6 class

* refactor: convert workspace_events.js to es6 class

* refactor: convert events_abstract.js to an es6 class

* chore: format

* chore: fix lint

* chore: rebuild

* chore: respond to PR feedback
2022-02-16 13:48:18 -08:00
Neil Fraser
bce4c5e2c6 Delete events should animate when played (#5919)
Same as PR #5640, except for the addition of a parameter in the JSON to turn this on or off.  While one would normally want animations/sounds on (e.g. undo/redo stack) sometimes they'd be annoying (e.g. events from realtime collaborators).
2022-02-11 14:20:10 -08:00
alschmiedt
4b5733e7c8 refactor!: allows previously internal constants to be configurable (#5897) 2022-02-09 09:46:34 -08:00
Rachel Fenichel
9e8c5ea8ed refactor: convert some files to es classes (#5917)
* refactor: update several files to es6 classes

* refactor: update several files to es6 classes

* chore: add some type casts for specificity about event types

* chore: run formatter

* chore: rebuild
2022-02-09 08:29:39 -08:00
Aaron Dodson
328cd35d10 refactor: Migrate Blockly.Events.Abstract to named exports (#5916) 2022-02-04 15:32:33 -08:00
Rachel Fenichel
4cf1a5c886 refactor: convert some files to es classes (#5913)
* refactor: update workspace_comment and _svg to es classes

* refactor: update classes that extend icon to es classes

* refactor: update icon to es6 class

* refactor: update connection classes to es6 classes and add casts as needed

* refactor: update scrollbar to es6 class and add casts as needed

* refactor: update workspace_svg to es6 class

* refactor: update several files to es6 classes

* refactor: update several files to es6 classes

* refactor: update renderers/common/info.js to es6 class

* refactor: update several files to es6 classes

* chore: rebuild deps.js

* chore: run format
2022-02-04 10:58:22 -08:00
Rachel Fenichel
97c19be612 refactor: convert renderer measurables to es6 classes (#5899)
* chore: use casts to narrow types in renderers

* chore: add @struct and type information on common measurables

* refactor: update some renderer measurables to es6 classes

* refactor: convert many measurables to es6 classes

* chore: format

* chore: rebuild
2022-02-01 15:43:11 -08:00
Christopher Allen
ffb8907db8 feature(blocks): Export block definitions (#5908)
* refactor: Provide a BlockDefinition type

* refactor: Split defineBlocksWithJsonArray

  Split defineBlocksWithJsonArray into:

  - createBlockDefinitionsFromJsonArray, which creates BlockDefinitions
    from a (possibly JSON-originated) POJsO array, having no side-effects
    except possibly issuing warnings to the console.
  - defineBlocks, which add any dictionary of BlockDefinitions to
    the Blocks dictionary.

* feat(blocks): Export block definitions per-module

  - Define all blocks in a local blocks dictionary, often using
    createBlockDefinitionFromJsonArray, without registering them.
  - Separately, use defineBlocks to register the exported
    BlockDefinitions at the end of each Blockly.blocks.*
    module.
  - In Blockly.blocks.all, create a blocks export that combines all
    of the blocks exports from the individual blocks modules.

* chore: have format script run clang-format on blocks/ too
2022-01-31 21:41:29 +00:00
Neil Fraser
1f6a1bd8d9 chore: Use ES6 template strings in CSS and code generators (#5902)
* Unindent CSS, save 3 kb of code.
* Convert generator functions to template strings. 
This resolves #5761.
2022-01-28 17:58:43 -08:00
Rachel Fenichel
efdb6549d9 refactor: convert some classes to es6 classes (#5873)
* refactor: convert flyout_button.js to ES6 class

* chore: move some properties into constructor and add annotations for flyout base

* refactor: convert flyout_horizontal.js to ES6 class

* refactor: convert flyout_vertical.js to ES6 class

* refactor: convert flyout_base.js to ES6 class

* refactor: convert flyout_metrics_manager.js to ES6 class

* refactor: convert insertion_marker_manager.js to ES6 class

* refactor: convert metrics_manager.js to ES6 class

* refactor: convert grid.js to ES6 class

* refactor: convert input.js to ES6 class

* refactor: convert touch_gesture.js to ES6 class

* refactor: convert gesture.js to ES6 class

* refactor: convert trashcan.js to ES6 class

* chore: rebuild and run format

* chore: fix review comments

* chore: respond to PR comments
2022-01-25 15:26:20 -08:00
alschmiedt
3f4f505791 fix: Adds check for changedTouches (#5869) 2022-01-25 14:50:00 -08:00
alschmiedt
f0b10776eb refactor!: remove unused constants from internalConstants (#5889) 2022-01-21 14:57:32 -08:00
Rachel Fenichel
f5caf964aa refactor: convert renderer classes to es6 classes (#5874)
* refactor: convert zelos renderer classes to es6 classes

* refactor: convert zelos measurables to es6 classes

* refactor: convert thrasos classes to es6 classes

* refactor: convert minimalist classes to es6 classes

* refactor: update geras classes to es6 classes

* chore: rebuild and format

* chore: fix indentation in comments
2022-01-14 12:43:13 -08:00
Rachel Fenichel
29fb7b7893 refactor: convert leaf event classes to es6 classes (#5870)
* chore(tests): update event assert functions to pass in types directly

* refactor: move event types from prototypes to constructors

* refactor: convert events/events_block_change.js to ES6 class

* refactor: convert events/events_block_create.js to ES6 class

* refactor: convert events/events_block_delete.js to ES6 class

* refactor: convert events/events_block_drag.js to ES6 class

* refactor: convert events/events_block_move.js to ES6 class

* refactor: convert events/events_click.js to ES6 class

* refactor: convert events/events_comment_change.js to ES6 class

* refactor: convert events/events_comment_create.js to ES6 class

* refactor: convert events/events_comment_delete.js to ES6 class

* refactor: convert events/events_comment_move.js to ES6 class

* refactor: convert events/events_marker_move.js to ES6 class

* refactor: convert events/events_selected.js to ES6 class

* refactor: convert events/events_theme_change.js to ES6 class

* refactor: convert events/events_toolbox_item_select.js to ES6 class

* refactor: convert events/events_trashcan_open.js to ES6 class

* refactor: convert events/events_ui.js to ES6 class

* refactor: convert events/events_var_create.js to ES6 class

* refactor: convert events/events_var_delete.js to ES6 class

* refactor: convert events/events_var_rename.js to ES6 class

* refactor: convert events/events_viewport.js to ES6 class

* chore: rebuild

* chore: run clang-format
2022-01-12 09:29:30 -08:00
Rachel Fenichel
1c74679d83 refactor: convert some files to es6 classes (#5863)
* refactor: convert menu.js to ES6 class

* refactor: convert menuitem.js to ES6 class

* refactor: convert scrollbar_pair.js to ES6 class

* chore: define properties in the constructor in names.js

* refactor: convert names.js to ES6 class

* chore: run clang-format
2022-01-10 09:18:11 -08:00
Rachel Fenichel
6ee63894b3 chore: declare properties in the constructor instead of at first use (#5862) 2022-01-07 15:58:23 -08:00
Rachel Fenichel
9d8eeb30f6 refactor: convert some files to es6 classes (#5861)
* refactor: convert utils/coordinate.js to ES6 class

* refactor: convert utils/rect.js to ES6 class

* refactor: convert utils/size.js to ES6 class

* refactor: convert block_drag_surface.js to ES6 class

* refactor: convert block_dragger.js to ES6 class

* refactor: convert bubble_dragger.js to ES6 class

* chore: declare bubble property in the constructor

* refactor: convert bubble.js to ES6 class

* chore: clang-format

* chore(lint): lint and format
2022-01-07 14:49:49 -08:00
Rachel Fenichel
df2eafb8dd refactor: move properties into constructors and convert to classes (#5822)
* refactor: move properties to constructor in block_drag_surface.js

* refactor: move properties to constructor in block_svg.js

* refactor: move properties to constructor in block.js

* refactor: move properties to constructor in bubble.js

* refactor: move properties to constructor in connection.js

* refactor: move properties to constructor in flyout_base.js

* refactor: move properties to constructor in flyout_button.js

* refactor: move properties to constructor in generator.js

* refactor: move properties to constructor in grid.js

* refactor: move properties to constructor in input.js

* refactor: move properties to constructor in mutator.js

* refactor: move properties to constructor in scrollbar.js

* refactor: move properties to constructor in trashcan.js

* refactor: move properties to constructor in warning.js

* refactor: move properties to constructor in workspace_audio.js

* refactor: move properties to constructor in workspace_drag_surface_svg.js

* refactor: move properties to constructor in workspace_svg.js

* refactor: move properties to constructor in workspace.js

* refactor: move properties to constructor in zoom_controls.js

* chore: rebuild

* refactor: convert zoom_controls.js to es6 class and format

* refactor: convert workspace_audio.js to es6 class and format

* refactor: convert workspace_dragger.js to es6 class and format

* refactor: convert workspace_drag_surface_svg.js to es6 class and format

* refactor: convert variable_model.js to es6 class and format

* refactor: convert variable_map.js to es6 class and format

* refactor: convert theme.js to es6 class and format

* chore: remove bad comment
2022-01-06 13:13:40 -08:00
Neil Fraser
769a25f4ba fix: Don't throw if drag surface is empty. (#5695)
Observed this error in Blockly Games Bird 6 (Chrome OS):
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
It has only shown up once, and I can't reproduce, but it looks like the drag surface was being cleared while empty.  Maybe some weird multi-touch operation?

Open question: Leave the code as is so that the error is thown and visible, or supress it?
2022-01-06 10:42:32 -08:00
Beka Westberg
5204569cff fix: bumping a block after duplicate breaking undo (#5844)
* fix: bumping a block after duplicate breaking undo

* fix: fixup dependencies
2022-01-06 10:08:43 -08:00
Beka Westberg
8a71f87950 fix: procedure param edits breaking undo (#5845) 2022-01-04 15:07:41 -08:00
alschmiedt
835fb02343 fix: setting null for a font style on a theme (#5831) 2022-01-04 15:06:41 -08:00
Mark Friedman
68d81132b8 fix: change getCandidate_ and showInsertionMarker_ to be more dynamic (#5722)
* Change getCandidate_ and showInsertionMarker_ to be more dynamic

* Ran clang formatter

* Fix typos

* Fix issue with dragging stacks

* From PR comment
2021-12-15 15:46:17 -08:00
Rachel Fenichel
6fc3316309 fix: re-expose HSV_VALUE and HSV_SATURATION as settable properties on Blockly (#5821) 2021-12-14 11:51:03 -08:00
Maribeth Bottorff
025bab6566 fix: Use correct namespace for svgMath functions (#5813) 2021-12-13 14:56:22 -08:00
Maribeth Bottorff
0a96543a11 fix: fix keycodes type (#5805) 2021-12-13 14:56:05 -08:00
Maribeth Bottorff
64107ccb04 fix: don't use fully qualified namespace in aria (#5804) 2021-12-09 10:40:12 -08:00
Maribeth Bottorff
98f94707ac fix: allow undefined color in toolbox definition (#5801) 2021-12-08 18:17:19 -08:00
Maribeth Bottorff
7784eac9be chore!: Add deprecation notices to values in blockly.js (#5555)
* Add deprecation warnings and reorganize blockly.js

* Update usages of deprecated properties

* chore: make dates consistent, remove extra function

* chore: run clang-format and fix lint

* chore: add more  tags

* chore: fix updated location of Align types

* chore: fix deprecated usages in tests

* chore: rebuild deps

* chore: fix moved Align types in demos and tests

* chore: update which properties are actually deprecated

* chore: don't deprecate Blockly.selected.
2021-12-08 18:16:13 -08:00
Christopher Allen
10cfc11809 chore: Remove core/requires.js (#5718)
* chore: Remove requires that duplicate those in blockly.js

* refactor: Remove core/requires.js, make blockly.js be entry point

It sort of makes sense, doesn't it?

The only remaining require not duplicated in `blockly.js` was that for
`Blockly.themes.Classic`, but it is already required by
`Blockly.themes` (itself required by `Blockly`).
2021-12-06 08:46:14 -08:00
Christopher Allen
3d7262fed2 fix(tests): Fix & reenable the advanced compilation test (#5781)
* fix(test): Fix advanced compilation test

- Fix loading of blocks in `tests/compile/main.js` caused by
  recent `goog.module`-ification work.
- Fix problem caused by ADVANCED_OPTIMISATIONS renaming the Msg
  property on the fake Blockly object created by the
  translation-loading hack in `blockly.js`.

* chore(build): Reenable advanced compilation test

Fixes #5602.
2021-12-03 10:14:19 -08:00
alschmiedt
c93e1dfd30 deprecate!: removes deprecated connection functions (#5713) 2021-12-02 18:21:21 -08:00
alschmiedt
719e0fbf38 chore: updates the names for parsing (#5778) 2021-12-02 17:52:33 -08:00
alschmiedt
6128f2dfd4 feat: make checkAndDelete a public API (#5772) 2021-12-02 11:39:08 -08:00
alschmiedt
5515afc708 chore: Remove declareLegacyNamespace from serialization folder (#5757) 2021-12-02 10:21:58 -08:00
Christopher Allen
da16a66f33 refactor: msg.js: use named export, remove declareLegacyNamespace (#5768) 2021-12-02 16:47:27 +00:00
alschmiedt
35279eb8b7 chore: correctly updates the compiled flag (#5767) 2021-12-02 08:29:53 -08:00
alschmiedt
780198e0c0 chore: revert #5730 (#5740)
* chore: revert #5730

* fix: Fix compile failure due to incorrect visibility

The CONTROL_FLOW_IN_LOOP_CHECK_MIXIN is intended to be used outside of
blocks/ (it is, in particular, used in generators/) so it should have
been marked @public from the beginning.
2021-11-30 19:27:19 +00:00
Neil Fraser
341dba5965 fix: Prevent error when maxTrashcanContents is 0 (#5739)
* fix: Prevent error when maxTrashcanContents is 0

Resolves #5729.

* Eliminate ’smart’ quotes.
2021-11-30 10:25:16 -08:00
Rachel Fenichel
8ef0b20146 feat: clarify variable and procedure constants (#5743)
* chore: move dynamic category names into their respective files

* feat: create NameType enum on Names

* chore: use NameType enum for Names helper functions

* docs: update comments for category names
2021-11-30 09:13:36 -08:00
Christopher Allen
c0d22f2002 refactor: Rename ALIGN to Align and move from constants.js to input.js (#5742)
This constant is used to specify the alignment of
an Input, so it should live in the same file as the Input class.

I've done this as a separate named export, but it could alternatively
be made a static member of Input (i.e., Input.Align with only Input
being exported by name).

Where mocha tests were referring to Blockly.constants.ALIGN.*
without actually requiring Blockly.constants, I have reverted
them to refer to Blockly.ALIGN_* instead (pending conversion
to named requries).

Part of #5073.
2021-11-29 21:59:48 +00:00
Christopher Allen
985af10f6e chore(build): Use chunked compilation (#5721)
* chore(build): Add "all" modules for blocks & generators

These modules (Blockly.blocks.all and Blockly.<Generator>.all) will
be the entry points for the corresponding chunks.

They also make it easier to pull in all the modules in each package
(e.g. for playground and tests).

It is necessary to set the Closure Compiler dependency_mode to
SORT_ONLY as otherwise it tries to compile the "all" modules before
their dependencies, which fails.

The only impact on the _compressed.js files is the addition of a short
string to the very end of each file, e.g.:

    var module$exports$Blockly$JavaScript$all={};

* chore(deps): Add devDependency on closure-calculate-chunks

* feat(build): First pass at chunked complation

Add a new buildCompiled gulp target (npm run build:compiled) that
uses closure-calculate-chunks to do chunked compliation of core/,
blocks/ and generators/ all in a single pass.

This work is incomplete: the resulting *_compressed.js files don't
(yet) have UMD wrappers.

* chore(build): Generate chunk wrappers

A first pass; this does not have support for a namespace object yet.

* refactor(build): Use chunked compilation by default

Remove old "compressed" gulp tasks in favour of new "compiled" task.

* chore(build): Remove cruft from buildCompiled

Remove unneeded `done` parameter and commented-out options that had
been cargo-culted from the old build pipeline.

* fix(build): Fix test failures caused by new build pipeline

- Exclude closure/goog/base.js from compiler input; use
  externs/goog-externs.js instead.

- Have the build:debug and build:strict targets only build the first
  chunk (blockly_compressed.js).

- Fix namespace entries for blocks and generators.

* fix(build): Fix build failures on node v12

closure-calculate-chunks requires node.js v14 or later.

When running on node.js v14 or later have getChunkOptions save
the output of closure-calculate-chunks to
scripts/gulpfiles/chunks.json.  When running on older versions of
node.js have it use this checked-in, cached output instead of
attempting to run closure-calculate-chunks.

* chore(build): enable --rename_prefix_namespace

This will allow modules in blocks/ and generators/ to use
goog.require to obtain the exports object of goog.modules from
core/.

* fix(build): Always build all chunks

The previous commit enabled --rename_prefix_namespace option to
Closure Compiler, and this causes the buildCompressed target to
work fine when run without --debug or --strict, but adding either
of those flags (as for example when `npm test` runs
`npm run build:debug`) causes an issue:

- Because of many compiler errors in blocks/ and generators/,
  a previous commit added a hack to only build the first chunk
  when doing debug/strict builds.

- When asked to build only one chunk, Closure Compiler ignores the
  --rename_prefix_namespace flag, because it 'correctly' infers
  that there are no later chunks that will need to access global
  variables from the first chunk.

- This causes a test failure, because `npm test` first runs
  `npm run build`, which generates a valid blockly_compressed.js,
  but this is then overrwritten by an invalid one when it next runs
  `npm run build:debug`.

  (The invalid one is missing all `$.` prefixes on 'global' variables,
  including on Blockly, so the wrapper's last two lines -
  "$.Blockly.internal_ = $;" and "return $.Blockly" - fail.)

The fix is to add appropriate @suppress annotations to blocks/*.js and
generators/**/*.js and then remove the first-chunk-only hack.

* refactor(build): Just build once

Since the previous commit caused `npm run build:debug` to do
everything that `... build:compressed` does - and to produce
byte-for-byte identical output - it doesn't make sense to run
both when testing.  To that end:

- Replace the build:debug and build:strict package scripts that
  did `gulp buildCompressed --...` with new scripts build-debug
  and build-strict that do `gulp build --...` instead.

  (The target names are changed so as to extend our existing naming
  convention as follows: a target named "foo:bar" does some sub-part
  of the job done by target "foo", but a target named "foo-bar" does
  all the work of the target "foo" with some extra options.)

- build:debug:log and build:strict:log are similarly replaced with
  build-debug-log and build-strict-log.

- Modify run_all_tests.js to just do `npm run build-debug` instead of
  doing both `npm run build` and `npm run build:debug`.

- Also remove the 'build:blocks' script that should have been removed
  when the buildBlocks gulp task was deleted previously.

* refactor(build): Compile with base_minimal.js instead of base.js

Introduce a (very!) cut-down version of closure/goog/base.js named
base_minimal.js that is used as input to the compiler as an
alternative to using externs/goog-externs.js (which will be deleted
once the buildAdvancedCompilationTest target has been updated).

This will allow use of goog.setTestOnly since it will now exist in
compiled mode, and allows the changes made in 5b112db to filter
base.js out of the files for the first chunk to be reverted.
(It also obliges a change to the compiled-mode check in blockly.js.)

* fix(build): Fix buildAdvanceCompilationTest

- In build_tasks.js:
  - Replace the old compile() function with a new one factored out of
    buildCompiled().
  - Update buildAdvancedCompilationTest to use the new compile()
    and other helpers created in the meantime.
  - Remove no-longer-used maybeAddClosureLibrary().

- Remove externs/{block,generator,goog}-externs.js, which are no longer
  used by any compile pipeline.

- Update core/blockly.js to fix issue with detection of compiled mode
  when using ADVANCED_OPTIMISATIONS.

- Update only other use of globalThis, in core/utils/xml.js, to
  consistently treat it as a dictionary object.

- Update instructions in tests/compile/index.html.

This commit is sort-of-a-prerequisite to #5602; test:compile:advanced
was previously working but the generated `main_compresed.js` would
throw errors upon loading.
2021-11-29 17:50:17 +00:00
Neil Fraser
1a470003fe fix: Stop throwing error when PointerEvent.pageX is 0. (#5727)
The e.pageX (and .pageY) checks aren't strict enough.  0 is a perfectly valid coordinate.

Checking for the existence of changedTouches is an easier way to distinguish a PointerEvent from a TouchEvent.
2021-11-26 10:27:43 -08:00
Mark Friedman
da3df70f6f feat: Enable the creation of concurrent, but not connected, output and previous connectors (#5702)
* Add new connection checks and tests

* Enable concurrent output and previous connections on blocks

  * and remove assumption from unplug().

* Make changes compatible with new module system

* Fix issue do to Connection class change.

  . and change some var's to const's now that that appears to be ok ;-)

* Fix more code that assumes only one of output and previous connections

* Change function name as per PR comment

* Fix lint errors

* Fix clang format issues
2021-11-24 17:03:21 -08:00
alschmiedt
308253bfdf chore: moves the public loop mixin into its own file (#5730) 2021-11-24 15:57:28 -08:00
Maribeth Bottorff
6c33373d5b chore: make Blockly.common.setSelected package and update docs (#5728) 2021-11-22 15:03:41 -08:00
Rachel Fenichel
bbf768a920 chore: enable eslint-config-google (#5717)
* chore(deps): update package-lock.json

* chore(deps): install eslint-config-google as a dev dependency

* chore: enable eslint-config-google

* chore: fix missing commas
2021-11-18 09:30:34 -08:00