Temporarily exclude the generated .d.ts files for blocks/* and
generators/* from the package.
This will in due course replace the (very simplistic) hand-written
versions in typings/, but for now they are not referenced
anywhere a developer's tooling should be looking, and contain
in some cases actually incorrect typings (e.g., in unmigrated
blocks files, the blocks export is typed as ObjectConstructor,
which is wrong), so do not include them in the package least they
cause problems for the unwary.
We introduced the SKIP_SETUP sentinel value when converting
Field and its subclasses to ES6 class syntax, because super
must be called before any other code in a subclass
constructor, breaking the previous mechanism where subclasses
would set some properties before calling their superclass
constructor.
SKIP_SETUP was a singleton value of class Sentinel.
Recently, in PR #6639 @btw17 introduced the isSentinel type
predicate to improve the typing of Field. Unfortunately, there
were some aspects of this change that were not very elegant:
- isSentinel was declared as a static method on Field (rather
than on Sentinel itself).
- It only checks against the specific value SKIP_SETUP,
rather than checking if the argument is instanceof Sentinel
(though perhaps this is for efficiency?)
Additionally - as a result of the migration from ES6 to TS, and
predating PR #6639 - The signature for the Field constructor's
first argument was typed T|Sentinel, with subclass constructors
generally being <some type(s)>|Sentinel.
This creates a small problem when attempting to port Fields from
core to plugins, because Sentinel is not reexported by
core/utils.ts (and therefore not from core/blockly.ts either).
The latter problem could be solved simply by reexporting Sentinel,
or by having plugin constructors not accept SKIP_SETUP (though
this potentially makes them more difficult to subclass), but
neither is particularly desirable.
Instead, this PR proposes that we:
- Make Field.SKIP_SETUP a (unique) Symbol.
- Change the value argument to the Field constructor to accept
T|typeof Field.SKIP_SETUP - where typeof Field.SKIP_SETUP is
(like a literal type) a type that accepts just the single
value SKIP_SETUP.
- Remove the Sentinel class and core/utils/sentinel.ts.
Not treating this as a breaking change:
- Removes Field.isSentinel - though this addition has not yet
been published, so it can only break our own as-yet-unreleased
code in samples.
- Changes the type of Field.SKIP_SETUP and the first argument
of the Field constructor from Sentinel to typeof SKIP_SETUP
(a unique Symbol) - but given that Sentinel has never been
exported this should not break any actual external code.
* refactor(blocks): Auto-migration of blocks/math.js to ts
This is just the result of running js2ts on this file.
* fix(blocks): Manually migrate & fix types in math.ts
* chore(blocks): clang-format math.ts
* fix(blocks): Corrections for comments on PR #6900
* refactor(blocks): Define types for mixin-ed blocks, etc.
Define types to represent the union of Block and each of the
*_MIXINs, and use these types for the type of this in mixin
methods.
* refactor(blocks): Misc minor changes
Make sure validator functions explicitly return undefined.
Field.prototype.setValidator takes a FieldValidator<T>, which
must be a non-void function. I'm not sure why tsc was not
objecting to the void implementation here, but it does in
other very similar situations so for consistency explicitly
return undefined to signal the value should be used unchanged.
Also undo previous change of !. to ?.: I think it wisest to
try to preserve the existing behaviour as exactly as possible
for now, and make behaviour changes (i.e., ones that affect
the generated code) separately.
* fix(blocks): Fix erroneous typing of mixins
It turns out that the previous types for these were completely
wrong, for two reasons:
- They should be intersection types (which have the union of the
properties), not union types (which have the interseciton of the
properties).
- The *_MIXIN types were already declared as having type
BlockDefinition, which is ultimately an alias for any.
TypeScript doesn't like (some) kinds of circularly defined types,
so fixing the above necessitates declaring a few auxiliary types
just to make the type checker happy - but the end result is
excellent and caught an actual type error in the code.
* fix: Don't clober event group when renaming vars
Also audit all existing event group commands and tweak a few of them where I think there's a potential issue.
* fix: early return from updateDisabled if it is noop
* chore: trigger connect and disconnect before hiding
* chore: remove disconnectInternal
* fix: skip setting parent when disconnecting before connecting
* chore: fixup docs
* chore: remove erroneous test
* fix: add delay to context menu callback.
Improve INP by allowing the browser to do a paint (closing the context
menu) before we trigger callbacks. This improves the user experience
for expensive callbacks (e.g. collapsing, or updating disabled).
* fix: rendering bug
When disconnecting the last block in the stack, the block would not be
rerendered correctly (the top-start corner would not be reshaped)
* fix: connecting bug
The order for applying connections was changed so that connections were
applied and then the insertion marker was hidden. This caused an error
because hiding the insertion marker expected there to be a child block
when there was not.
* chore: remove setParent param from public API
* chore: tsdoc