Commit Graph

34 Commits

Author SHA1 Message Date
Aaron Dodson
93a9b6bf2e fix: Fix navigation for blocks with multiple statement inputs. (#9143)
* fix: Fix navigation for blocks with multiple statement inputs.

* chore: Add tests to prevent regressions.
2025-06-13 15:08:58 -07:00
Aaron Dodson
38df7c8776 feat: Allow visiting empty input connections. (#9104)
* feat: Update navigation policies to allow visiting empty input connections.

* fix: Fix tests.

* chore: Add JSDoc.

* fix: Add missing import.

* fix: Fix JSDoc.

* chore: Remove double comments.
2025-05-28 20:43:16 -07:00
Aaron Dodson
ece662a45f Fix: don't visit connections with the cursor. (#9030) 2025-05-13 11:03:01 -07:00
Aaron Dodson
acdad98653 refactor!: Use navigation rulesets instead of ASTNode to control keyboard navigation. (#8992)
* feat: Add interfaces for keyboard navigation.

* feat: Add the Navigator.

* feat: Make core types conform to INavigable.

* feat: Require FlyoutItems elements to be INavigable.

* feat: Add navigation policies for built-in types.

* refactor: Convert Marker and LineCursor to operate on INavigables instead of ASTNodes.

* chore: Delete dead code in ASTNode.

* fix: Fix the tests.

* chore: Assuage the linter.

* fix: Fix advanced build/tests.

* chore: Restore ASTNode tests.

* refactor: Move isNavigable() validation into Navigator.

* refactor: Exercise navigation instead of ASTNode.

* chore: Rename astnode_test.js to navigation_test.js.

* chore: Enable the navigation tests.

* fix: Fix bug when retrieving the first child of an empty workspace.
2025-05-07 08:47:52 -07:00
Ben Henning
fdeaa7692b feat: Update line cursor to use focus manager (#8941)
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes #8940
Fixes #8954
Fixes #8955

### Proposed Changes

This updates `LineCursor` to use `FocusManager` rather than selection (principally) as the source of truth.

### Reason for Changes

Ensuring that keyboard navigation works correctly with eventual screen reader support requires ensuring that ever navigated component is focused, and this is primarily what `FocusManager` has been designed to do. Since these nodes are already focused, `FocusManager` can be used as the primary source of truth for determining where the user currently has navigated, and where to go next.

Previously, `LineCursor` relied on selection for this purpose, but selection is now automatically updated (for blocks) using focus-controlled `focus` and `blur` callbacks. Note that the cursor will still fall back to synchronizing with selection state, though this will be removed once the remaining work to eliminate `MarkerSvg` has concluded (which requires further consideration on the keyboard navigation side viz-a-viz styling and CSS decisions) and once mouse clicks are synchronized with focus management.

Note that the changes in this PR are closely tied to https://github.com/google/blockly-keyboard-experimentation/pull/482 as both are necessary in order for the keyboard navigation plugin to correctly work with `FocusManager`.

Some other noteworthy changes:
- Some special handling exists for flyouts to handle navigating across stacks (per the current cursor design).
- `FocusableTreeTraverser` is needed by the keyboard navigation plugin (in https://github.com/google/blockly-keyboard-experimentation/pull/482) so it's now being exported.
- `FocusManager` had one bug that's now patched and tested in this PR: it didn't handle the case of the browser completely forcing focus loss. It would continue to maintain active focus even though no tracked elements now hold focus. One such case is the element being deleted, but there are other cases where this can happen (such as with dialog prompts).
- `FocusManager` had some issues from #8909 wherein it would overeagerly call tree focus callbacks and slightly mismanage the passive node. Since tests haven't yet been added for these lifecycle callbacks, these cases weren't originally caught (per #8910).
- `FocusManager` was updated to move the tracked manager into a static function so that it can be replaced in tests. This was done to facilitate changes to setup_teardown.js to ensure that a unique `FocusManager` exists _per-test_. It's possible for DOM focus state to still bleed across tests, but `FocusManager` largely guarantees eventual consistency. This change prevents a class of focus errors from being possible when running tests.
- A number of cursor tests needed to be updated to ensure that a connections are properly rendered (as this is a requirement for focusable nodes, and cursor is now focusing nodes). One test for output connections was changed to use an input connection, instead, since output connections can no longer be navigated to (and aren't rendered, thus are not focusable). It's possible this will need to be changed in the future if we decide to reintroduce support for output connections in cursor, but it seems like a reasonable stopgap. Huge thanks to @rachel-fenichel for helping investigate and providing an alternative for the output connection test.

**Current gaps** to be fixed after this PR is merged:
- The flyout automatically closes when creating a variable with with keyboard or mouse (I think this is only for the keyboard navigation plugin). I believe this is a regression from previous behavior due to how the navigation plugin is managing state. It would know the flyout should be open and thus ensure it stays open even when things like dialog prompts try to close it with a blur event. However, the new implementation in https://github.com/google/blockly-keyboard-experimentation/pull/482 complicates this since state is now inferred from `FocusManager`, and the flyout _losing_ focus will force it closed. There was a fix introduced in this PR to fix it for keyboard navigation, but fails for clicks because the flyout never receives focus when the create variable button is clicked. It also caused the advanced compilation tests to fail due to a subtle circular dependency from importing `WorkspaceSvg` directly rather than its type.
- The flyout, while it stays open, does not automatically update past the first variable being created without closing and reopening it. I'm actually not at all sure why this particular behavior has regressed.

### Test Coverage

No new non-`FocusManager` tests have been added. It's certainly possible to add unit tests for the focusable configurations being introduced in this PR, but it may not be highly beneficial. It's largely assumed that the individual implementations should work due to a highly tested FocusManager, and it may be the case that the interactions of the components working together is far more important to verify (that is, the end user flows). The latter is planned to be tackled as part of #8915.

Some new `FocusManager` tests were added, but more are still needed and this is tracked as part of #8910.

### Documentation

No new documentation should be needed for these changes.

### Additional Information

This includes changes that have been pulled from #8875.
2025-05-01 22:18:22 -07:00
Grace
8f59649956 fix: LineCursor can loop forward, but not back (#8926)
* fix: loop cursor when moving to prev node

* chore: add loop tests for LineCursor prev and out

* chore: fix out loop test for line cursor
2025-04-25 08:26:58 -07:00
Rachel Fenichel
fac75043dd feat: add loopback in cursor navigation, and add tests (#8883)
* chore: tests for cursor getNextNode

* chore: add tests for getPreviousNode

* feat: add looping to getPreviousNode and getNextNode

* chore: inline returns

* chore: fix test that results in a stack node

* chore: fix annotations
2025-04-14 09:58:58 -07:00
Rachel Fenichel
3160e3d321 feat: add getFirstNode and getLastNode to cursor with tests (#8878)
* feat: add getFirstNode and getlastNode to line_cursor.ts

* chore: add simple tests for getFirstNode and getLastNode

* chore: broken tests for debugging

* chore: additional cursor tests

* chore: lint, format, reenable tasks
2025-04-11 10:13:10 -07:00
Aaron Dodson
ca362725ee refactor!: Backport LineCursor to core. (#8834)
* refactor: Backport LineCursor to core.

* fix: Fix instantiation of LineCursor.

* fix: Fix tests.

* chore: Assauge the linter.

* chore: Fix some typos.

* feat: Make padding configurable for scrollBoundsIntoView.

* chore: Merge in the latest changes from keyboard-experimentation.

* refactor: Clarify name and docs for findSiblingOrParentSibling().

* fix: Improve scrollBoundsIntoView() behavior.

* fix: Export CursorOptions.

* refactor: Further clarify second parameter of setCurNode().

* fix: Revert change that could prevent scrolling bounds into view.
2025-04-03 12:15:17 -07:00
Christopher Allen
ce22f42868 chore: Organise imports (#8527)
* chore(deps): Add pretter-plugin-organize-imports

* chore: Remove insignificant blank lines in import sections

  Since prettier-plugin-organize-imports sorts imports within
  sections separated by blank lines, but preserves the section
  divisions, remove any blank lines that are not dividing imports
  into meaningful sections.

  Do not remove blank lines separating side-effect-only imports
  from main imports.

* chore: Remove unneded eslint-disable directives

* chore: Organise imports
2024-08-15 03:16:14 +01:00
dependabot[bot]
bfb5b1dd49 chore(deps): Bump chai from 4.3.10 to 5.1.1 (#8092)
* chore(deps): Bump chai from 4.3.10 to 5.1.1

  Bumps [chai](https://github.com/chaijs/chai) from 4.3.10 to 5.1.1.
  - [Release notes](https://github.com/chaijs/chai/releases)
  - [Changelog](https://github.com/chaijs/chai/blob/main/History.md)
  - [Commits](https://github.com/chaijs/chai/compare/v4.3.10...v5.1.1)

  ---
  updated-dependencies:
  - dependency-name: chai
    dependency-type: direct:development
    update-type: version-update:semver-major
  ...

  Signed-off-by: dependabot[bot] <support@github.com>

* fix(tests): Migrate all usage of chai to ESM (#8216)

* fix(tests): Migrate node tests from CJS to ESM

  This allows us to import (rather than require) chai, fixing failures
  caused by that package dropping suppport for CJS in chai v5.0.0.

* fix(tests): Have mocha tests directly import chai

  Previously they relied on obtaining it from the global scope, but it's
  better if imports are explicit.

* fix(tests): Remove broken load of chai as script

  Chai v5.0.0 no longer supports being loaded as a script, so this did
  nothing but emit an syntax error message on the console.

* fix(tests): Migrate browser tests from CJS to ESM

  This allows us to import (rather than require) chai, fixing failures
  caused by chai no longer supporting CJS.

* chore(tests): format

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2024-06-17 16:48:21 +01:00
Christopher Allen
6f20ac290d refactor(tests): Use import instead of goog.bootstrap to load Blockly in mocha tests (#7406)
* fix(build): Have buildShims clean up up after itself

  We need to create a build/package.json file to allow node.js to
  load build/src/core/blockly.js and the other chunk entry points
  as ES modules (it forcibly assumes .js means CJS even if one is
  trying to import, unless package.json says {"type": "module"}),
  but this interferes with scripts/migration/js2ts doing a
  require('build/deps.js'), which is _not_ an ES module.

  Specific error message was:

  /Users/cpcallen/src/blockly/scripts/migration/js2ts:56
  require(path.resolve(__dirname, '../../build/deps.js'));
  ^

  Error [ERR_REQUIRE_ESM]: require() of ES Module
  /Users/cpcallen/src/blockly/build/deps.js from /Users/cpcallen/src/blockly/scripts/migration/js2ts
  not supported.
  deps.js is treated as an ES module file as it is a .js file whose
  nearest parent package.json contains "type": "module" which
  declares all .js files in that package scope as ES modules.
  Instead rename deps.js to end in .cjs, change the requiring code
  to use dynamic import() which is available in all CommonJS
  modules, or change "type": "module" to "type": "commonjs" in
  /Users/cpcallen/src/blockly/build/package.json to treat all .js
  files as CommonJS (using .mjs for all ES modules instead).

      at Object.<anonymous> (/Users/cpcallen/src/blockly/scripts/migration/js2ts:56:1) {
    code: 'ERR_REQUIRE_ESM'
  }

* chore(tests): Reorder to put interesting script nearer top of file

* chore(tests): Add missing imports of closure/goog/goog.js

  These modules were depending on being loaded via the
  debug module loader, which cannot be used without first loading
  base.js as a script, and thereby defining goog.declareModuleId
  as a side effect—but if they are to be loaded via direct import
  statements then they need to actually import their own
  dependencies.

  This is a temporary measure as soon the goog.declareMouleId
  calls can themselves be deleted.

* refactor(tests): Use import instead of bootstrap to load Blockly

* chores(build): Stop generating deps.mocha.js

  This file was only needed by tests/mocha/index.html's use of
  the debug module loader (via bootstrap.js), which has now been
  removed.

* chore(tests): Remove unneeded goog.declareModuleId calls

  These were only needed because these modules were previously
  being loaded by goog.require and/or goog.bootstrap.

* chores(tests): Remove dead code

  We are fully committed to proper modules now.
2023-08-18 18:06:52 +01:00
dependabot[bot]
2546b01d70 chore(deps): Bump prettier from 2.8.8 to 3.0.0 (#7322)
* chore(deps): Bump prettier from 2.8.8 to 3.0.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: Reformat using Prettier v3.0 defaults

The main change is to add trailing commas to the last line of
block-formatted function calls.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2023-07-25 14:56:10 +00:00
Maribeth Bottorff
88ff901a72 chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier

* chore: remove clang-format

* chore: remove clang-format config

* chore: lint additional ts files

* chore: fix lint errors in blocks

* chore: add prettier-ignore where needed

* chore: ignore js blocks when formatting

* chore: fix playground html syntax

* chore: fix yaml spacing from merge

* chore: convert text blocks to use arrow functions

* chore: format everything with prettier

* chore: fix lint unused imports in blocks
2023-05-10 16:01:39 -07:00
Rachel Fenichel
5f8330e74e chore: remove underscores from private properties and methods in keyboard nav and rendering (#6975)
* chore: remove underscores in keyboard navigation

* chore: remove private underscores from renderers
2023-04-12 11:19:41 -07:00
Beka Westberg
96758fedd4 chore: convert mocha tests and test helpers to esmodules (#6333)
* chore: change goog.module to goog.declareModuleId

* chore: change test helper exports to esmod exports

* chore: change test helpers to use esmodule imports

* chore: convert imports of test helpers to esmodule imports

* chore: convert other imports in tests to esm imports

* fix: make imports use built files

* chore: add blockly imports to a bunch of tests

* fix: reference Blockly.Blocks instead of Blocks'

* fix: properly import generators

* chore: fix lint

* chore: cleanup from rebase

* chore: cleanup from rebase

* chore: fix blocks tests
2022-08-10 14:54:02 -07:00
Beka Westberg
2edd228117 fix: move test helpers from samples into core (#5969)
* fix: move core test helpers into new directory

* fix: add test helpers to core and convert to goog modules

* fix: change tests to use local helpers

* fix: change local tests to use chai asserts

* fix: skip field tests in serializer b/c test blocks are unavailable

* fix: rename some helper files

* fix: rename some helper modules

* fix: split block helpers into code gen and serialization

* fix: split block defs into new helper file

* fix: split warning helpers into new file

* fix: split user input helpers into new file

* fix: split event helpers into a new file

* fix: split variable helper into new file

* fix: move remaining test helpers to new setup-teardown file

* fix: rename setup and teardown module

* fix: cleanup from rebase

* fix: undo accidental rename

* fix: lint?

* fix: bad toolbox definitions namespace

* fix: fixup warning helpers

* fix: remove inclusion of dev-tools in mocha tests

* move to modules, but break mocha

* fix: run mocha as a module

* fix: lint
2022-03-04 13:10:03 -08:00
Rachel Fenichel
d11cc047a4 chore: fix more lint (#5700)
* chore: fix 918 violations of comma-dangle rule

* chore: fix 2 violations of comma-spacing

* chore: fix 13 violations of padded-blocks

* chore: fix 50 violations of block-spacing

* chore: fix one violation of semi-spacing

* chore: fix 4 violations of space-before-blocks

* chore: fix 38 violations of object-curly-spacing

* chore: fix 30 violations of key-spacing

* chore: fix 3 violations of quote-props

* chore: fix 5 violations of arrow-parens

* chore: fix 8 violations of no-tabs

* chore: allow uncommented helper functions in mocha tests

* chore: fix several more lint errors

* chore: tweak eslint configuration in core and tests

* chore: rebuild for tests
2021-11-10 10:18:36 -08:00
Rachel Fenichel
1ebec55393 chore: apply prefer-const rule fixes in mocha tests (#5682) 2021-11-05 14:25:33 -07:00
Rachel Fenichel
52c0427d85 chore: run eslint--fix for no-var rule in tests/mocha (#5637) 2021-10-25 11:37:23 -07:00
alschmiedt
73580b0ddb chore: named exports for keyboard_nav* files (#5517) 2021-09-22 11:25:38 -07:00
alschmiedt
cf091351d8 chore: remove deprecateLegacyNamespace from keyboard nav files
* chore: Remove deprecateLegacyNamespace & fix tests

* chore: export from the blockly file
2021-09-21 17:18:34 -07:00
alschmiedt
5b1586ee1b test: update mocha tests to use goog_module (#5440)
* Use goog.module in mocha tests

* Fix compiler warnings

* Make test helpers a module

* Name test modules Blockly.test.*

This is to be more consistent with how non-test modules are named.

Also remove top-level goog.require of TestHelpers (now
Blockly.test.helpers) since requiring a side-effect-less module does
nothing.

* Convert block_test.js and comment_test.js to goog.module syntax

* Address PR comments

* Goog modulify tests

* Goog modulify toolbox helpers

* Fixes imports and moves common tests from workspace_test.js to a helper file.

* Update test deps after rebase

Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2021-09-16 13:00:38 -07:00
Monica Kozbial
896c630a89 Shared global cleanup (#4217)
* Refactor block type cleanup into shared cleanup.

* Use shared cleanup for block type cleanup.

* Remove overwriting of core Blockly block in test.

* Rename cleanup arrays for clarity

* Add blocks to cleanup array when defined in shared helpers

* Refactor logic for adding to shared cleanup.

* Add helper for defining block and adding block type to cleanup.

* Fix jsdocs

* Simplifying helpers for adding to cleanup.

* Add missing semicolons

* Update jsdoc for sharedTestSetup

* Use stub to wrap cleanup with defineBlocksWithJsonArray

* Remove unused helper from lint ignore
2020-09-09 15:51:34 -07:00
Monica Kozbial
2e92123314 Adding async cleanup to tests (#4103)
* Adding setup and teardown to more mocha tests.

* Update workspace dispose cleanup calls.
2020-08-05 16:00:00 -07:00
Monica Kozbial
0adf7efd5f Converting jsunit asserts to chai. (#3831)
* Converting jsunit asserts to chai.

* Move jsunit functions to test_utilities.

* Adding eslint exception for helper method.
2020-04-17 16:08:46 -07:00
Neil Fraser
4e2f8e6e02 Use SPDX licences.
This is a followup to #3127.
At the time, SPDX licenses were pending approval by Google.
2020-02-11 13:27:20 -08:00
alschmiedt
481fe63302 Marker manager (#3497)
* Adds a marker manager
2019-12-10 10:53:34 -08:00
Neil Fraser
b46a4fe286 Bring our license format up to date (#3127)
* Google changed from an Inc to an LLC.

This happened back in 2017 but we didn’t notice.  Officially we should update files from Inc to LLC when they are changed as part of regular edits, but this is a nightmare to remember for the next decade.

* Remove project description/titles from licenses

This is no longer part of Google’s header requirements.  Our existing descriptions were useless (“Visual Blocks Editor”) or grossly obselete (“Visual Blocks Language”).

* License no longer requires URL.

* Fix license regexps.
2019-10-02 14:46:56 -07:00
alschmiedt
468b673b73 Fix bugs (#3108)
* Fix various bugs around keyboard nav
2019-09-27 14:34:28 -07:00
alschmiedt
6516363469 Change setLocation to setCurNode (#3051)
* Change setLocation to setCurNode
2019-09-19 15:15:14 -07:00
alschmiedt
2c98ecaed6 Update APIs and Add New Cursor Look (#3009)
* Updates methods to be private in navigation.js

* Update cursor with new look
2019-09-16 12:33:43 -07:00
alschmiedt
ec07a36e44 Update cursor api (#3002)
* Move over to new implementation for cursor
2019-09-11 18:16:05 -07:00
alschmiedt
826409b01a Add tests for keyboard navigation (#2725) 2019-07-29 13:12:09 -07:00