Skip to content

Commit

Permalink
TW: add Scratch.gui types
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Apr 7, 2024
1 parent 35c03da commit 0de025f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/test-scratch-vm-extension-tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,12 @@ Scratch.fetch('https://example.com', {
'Content-Type': 'application/json'
}
});

Scratch.gui.getBlockly().then((ScratchBlocks) => {
ScratchBlocks.getMainWorkspace()?.blockDB_;
ScratchBlocks.Workspace;
});
Scratch.gui.getBlocklyEagerly().then((ScratchBlocks) => {
ScratchBlocks.getMainWorkspace()?.blockDB_;
ScratchBlocks.Workspace;
});
2 changes: 1 addition & 1 deletion types/scratch-blocks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ declare namespace ScratchBlocks {

}

interface RealBlockly {
interface RealBlockly extends BlocklyGlobal {
Workspace: WorkspaceConstructor;
WorkspaceSvg: typeof WorkspaceSvg;
}
Expand Down
22 changes: 22 additions & 0 deletions types/scratch-vm-extension.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ declare namespace Scratch {
/** Current language. May change while the project runs. Possible values: "en", "es", "it", etc. */
let language: string;
}
/**
* Only available when run in a scratch-gui environment (website, desktop app).
* In other environments (packager), will be undefined.
*/
namespace gui {
/**
* Lazily get the internal ScratchBlocks object when it becomes available. It may never be
* available if, for example, the user never enters the editor.
*
* ScratchBlocks becoming available does not necessarily mean the user is in the editor due
* to getBlocklyEagerly() also existing.
*/
function getBlockly(): Promise<ScratchBlocks.RealBlockly>;

Check failure on line 85 in types/scratch-vm-extension.d.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find namespace 'ScratchBlocks'.
/**
* Get the internal ScratchBlocks object as soon as possible. This lets you access it even
* if the user never enters the editor.
*
* This method is VERY SLOW and will cause A LOT OF CPU AND NETWORK ACTIVITY because it
* downloads and evaluates all of scratch-blocks, a multi-megabyte JavaScript bundle.
*/
function getBlocklyEagerly(): Promise<ScratchBlocks.RealBlockly>;

Check failure on line 93 in types/scratch-vm-extension.d.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find namespace 'ScratchBlocks'.
}

// Note that the 'B' in the BOOLEAN enums are capitalized in Scratch. It is not a typo in this file.

Expand Down

0 comments on commit 0de025f

Please sign in to comment.