Skip to content

Commit 16f4fb2

Browse files
authored
The great Blockly upgrade (#9865)
* initial blockly work * use newblocks in webapp * bug fixes and array block * if/else block * text blocks * gridpicker * field color number * field slider and math_number_minmax * duplicate on drag * workspace context menu * block context menu * tooltip * remove block dragger patch * Fix insertion marker compile exception * don't duplicate function definition argument reporters in domToBlock * debugging * Add new variable option to variable field dropdown * Bring back the collapsed input rendering * Monkey patch block svg to add expand button * update some fields * get all the rest of the field compiling * bug fixes for fields and toolbox generation * fix asset fields * fix block font * fix expandable blocks * toolbox flyout label styling * clean up the renderer mixin interface * fix prompt placeholders * make flyout buttons bigger and other fixes * fix note editor * Fix project importing * shadow block hack * give comments ids if missing * Cache category flyouts * fix typo in autocomplete field * don't upgrade all shadows * promote shadow blocks to regular blocks when they get non shadow children * fix undo redo * delete dead code * fix flyout click events * port over imagedropdown css * remove dead code * fix toolbox generation for draggable parameters * remove old blocks from pxtrunner * fix tutorial snippets * fix variable prompt * fix draggable decompile * properly hide flyout when closed * don't recycle variable blocks * don't close flyout after creating a variable * fix autocomplete field not resizing * fix ts expression color and autocomplete quotes * fix the speed and angle slider fields * fix flyout groups with the same name as the category * fix collapse field being added multiple times * fix slider initial value * fix slider dragging in firefox * fix width on firefox * fix position field * fix error outline * replace the emboss filter with a darkened outline * fix decompiler tests * fix karma runner * fix karma bugs * fix rest of karma tests * remove old blocks * move newblock to pxtblocks * eliminate last references to pxtblockly * fix editor extensions * fix eslint and patch pxtrunner * lint * fix build * fix build * hoist type * forgot files * fix uglifyify * fix test imports * fix validation * fixing target build * fix duplicate on drag behavior for new functions * fix highlight when blocks change size * remove type reference * fix flyout-only blockly tutorials * fix melody editor and add fixme notes * remove dead code and add fancy note slides * merge conflict * clarify fixmes * fix toggle click target and dropdown for external inputs * bring back menu separators in dropdown * dotted outline for draggable params * get textdropdown color from parent * fix import * fix tests * update blockly * fix edit function arguments * pin new dependencies * bump major version to 10
1 parent eeba7d8 commit 16f4fb2

195 files changed

Lines changed: 22082 additions & 16116 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gulpfile.js

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,14 @@ const pxtlib = () => compileTsProject("pxtlib");
3838
const pxtcompiler = () => compileTsProject("pxtcompiler");
3939
const pxtpy = () => compileTsProject("pxtpy");
4040
const pxtsim = () => compileTsProject("pxtsim");
41-
const pxtblocks = () => compileTsProject("pxtblocks");
4241
const pxtrunner = () => compileTsProject("pxtrunner", "built", true);
4342
const pxteditor = () => compileTsProject("pxteditor", "built", true);
4443
const pxtweb = () => compileTsProject("docfiles/pxtweb", "built/web");
4544
const backendutils = () => compileTsProject("backendutils")
4645
const cli = () => compileTsProject("cli", "built", true);
4746
const webapp = () => compileTsProject("webapp", "built", true);
4847
const reactCommon = () => compileTsProject("react-common", "built/react-common", true);
49-
50-
const pxtblockly = () => gulp.src([
51-
"webapp/public/blockly/blockly_compressed.js",
52-
"webapp/public/blockly/blocks_compressed.js",
53-
"webapp/public/blockly/plugins.js",
54-
"webapp/public/blockly/msg/js/en.js",
55-
"built/pxtblocks.js"
56-
])
57-
.pipe(concat("pxtblockly.js"))
58-
.pipe(gulp.dest("built"));
48+
const pxtblocks = () => compileTsProject("pxtblocks", "built/pxtblocks", true);
5949

6050
const pxtapp = () => gulp.src([
6151
"node_modules/lzma/src/lzma_worker-min.js",
@@ -86,7 +76,6 @@ const pxtembed = () => gulp.src([
8676
"built/pxtlib.js",
8777
"built/pxtcompiler.js",
8878
"built/pxtpy.js",
89-
"built/pxtblockly.js",
9079
"built/pxtsim.js",
9180
"built/web/runnerembed.js"
9281
])
@@ -121,8 +110,8 @@ function initWatch() {
121110
const tasks = [
122111
pxtlib,
123112
gulp.parallel(pxtcompiler, pxtsim, backendutils),
124-
gulp.parallel(pxtpy, gulp.series(copyBlockly, pxtblocks, pxtblockly)),
125-
pxteditor,
113+
pxtpy,
114+
gulp.parallel(pxtblocks, pxteditor),
126115
gulp.parallel(pxtrunner, cli, pxtcommon),
127116
gulp.parallel(updatestrings, browserifyEmbed),
128117
gulp.parallel(pxtjs, pxtdts, pxtapp, pxtworker, pxtembed),
@@ -142,7 +131,7 @@ function initWatch() {
142131
gulp.watch("./backendutils/**/*", gulp.series(backendutils, ...tasks.slice(2)));
143132

144133
gulp.watch("./pxtpy/**/*", gulp.series(pxtpy, ...tasks.slice(3)));
145-
gulp.watch("./pxtblocks/**/*", gulp.series(gulp.series(copyBlockly, pxtblocks, pxtblockly), ...tasks.slice(3)));
134+
gulp.watch("./pxtblocks/**/*", gulp.series(pxtblocks, ...tasks.slice(4)));
146135

147136
gulp.watch("./pxteditor/**/*", gulp.series(pxteditor, ...tasks.slice(4)));
148137

@@ -162,7 +151,7 @@ function initWatchCli() {
162151
const tasks = [
163152
pxtlib,
164153
gulp.parallel(pxtcompiler),
165-
gulp.parallel(pxtpy, gulp.series(pxtblocks, pxtblockly)),
154+
pxtpy,
166155
cli,
167156
notifyBuildComplete
168157
]
@@ -172,7 +161,6 @@ function initWatchCli() {
172161
gulp.watch("./pxtcompiler/**/*", gulp.series(pxtcompiler, ...tasks.slice(2)));
173162

174163
gulp.watch("./pxtpy/**/*", gulp.series(pxtpy, ...tasks.slice(3)));
175-
gulp.watch("./pxtblockly/**/*", gulp.series(gulp.series(copyBlockly, pxtblocks, pxtblockly), ...tasks.slice(3)));
176164

177165
gulp.watch("./cli/**/*", gulp.series(cli, ...tasks.slice(5)));
178166
}
@@ -388,8 +376,6 @@ const copyWebapp = () =>
388376
"built/pxtlib.js",
389377
"built/pxtcompiler.js",
390378
"built/pxtpy.js",
391-
"built/pxtblocks.js",
392-
"built/pxtblockly.js",
393379
"built/pxtsim.js",
394380
"built/webapp/src/worker.js",
395381
"built/webapp/src/serviceworker.js",
@@ -401,17 +387,16 @@ const copyWebapp = () =>
401387
const copySemanticFonts = () => gulp.src("node_modules/semantic-ui-less/themes/default/assets/fonts/*")
402388
.pipe(gulp.dest("built/web/fonts"))
403389

404-
const browserifyWebapp = () => process.env.PXT_ENV == 'production' ?
405-
exec('node node_modules/browserify/bin/cmd ./built/webapp/src/app.js -g [ envify --NODE_ENV production ] -g uglifyify -o ./built/web/main.js') :
406-
exec('node node_modules/browserify/bin/cmd built/webapp/src/app.js -o built/web/main.js --debug')
390+
const execBrowserify = (entryPoint, outfile) => process.env.PXT_ENV == 'production' ?
391+
exec(`node node_modules/browserify/bin/cmd ${entryPoint} -g [ envify --NODE_ENV production ] -g [ uglifyify --ignore '**/node_modules/@blockly/**' ] -o ${outfile}`) :
392+
exec(`node node_modules/browserify/bin/cmd ${entryPoint} -o ${outfile} --debug`);
407393

408-
const browserifyAssetEditor = () => process.env.PXT_ENV == 'production' ?
409-
exec('node node_modules/browserify/bin/cmd ./built/webapp/src/assetEditor.js -g [ envify --NODE_ENV production ] -g uglifyify -o ./built/web/pxtasseteditor.js') :
410-
exec('node node_modules/browserify/bin/cmd built/webapp/src/assetEditor.js -o built/web/pxtasseteditor.js --debug')
394+
const browserifyWebapp = () => execBrowserify("./built/webapp/src/app.js", "./built/web/main.js");
395+
396+
const browserifyAssetEditor = () => execBrowserify("./built/webapp/src/assetEditor.js", "./built/web/pxtasseteditor.js");
397+
398+
const browserifyEmbed = () => execBrowserify("./built/pxtrunner/embed.js", "./built/web/runnerembed.js");
411399

412-
const browserifyEmbed = () => process.env.PXT_ENV == 'production' ?
413-
exec('node node_modules/browserify/bin/cmd ./built/pxtrunner/embed.js -g [ envify --NODE_ENV production ] -g uglifyify -o ./built/web/runnerembed.js') :
414-
exec('node node_modules/browserify/bin/cmd built/pxtrunner/embed.js -o built/web/runnerembed.js --debug')
415400

416401
const buildSVGIcons = () => {
417402
let webfontsGenerator = require('@vusion/webfonts-generator')
@@ -534,37 +519,6 @@ const copyMonaco = gulp.series(
534519
stripMonacoSourceMaps
535520
);
536521

537-
538-
539-
/********************************************************
540-
Blockly
541-
*********************************************************/
542-
543-
const copyBlocklyCompressed = () => gulp.src([
544-
"node_modules/pxt-blockly/blocks_compressed.js",
545-
"node_modules/pxt-blockly/blockly_compressed.js"
546-
])
547-
.pipe(gulp.dest("webapp/public/blockly/"));
548-
549-
const copyBlocklyExtensions = () => gulp.src("node_modules/@blockly/**/dist/index.js")
550-
.pipe(concat("plugins.js"))
551-
.pipe(gulp.dest("webapp/public/blockly/"));
552-
553-
const copyBlocklyEnJs = () => gulp.src("node_modules/pxt-blockly/msg/js/en.js")
554-
.pipe(gulp.dest("webapp/public/blockly/msg/js/"));
555-
556-
const copyBlocklyEnJson = () => gulp.src("node_modules/pxt-blockly/msg/json/en.json")
557-
.pipe(gulp.dest("webapp/public/blockly/msg/json/"));
558-
559-
const copyBlocklyMedia = () => gulp.src("node_modules/pxt-blockly/media/*")
560-
.pipe(gulp.dest("webapp/public/blockly/media"))
561-
562-
const copyBlocklyTypings = () => gulp.src("node_modules/pxt-blockly/typings/blockly.d.ts")
563-
.pipe(gulp.dest("localtypings/"))
564-
565-
const copyBlockly = gulp.parallel(copyBlocklyCompressed, copyBlocklyExtensions, copyBlocklyEnJs, copyBlocklyEnJson, copyBlocklyMedia, copyBlocklyTypings);
566-
567-
568522
/********************************************************
569523
Skillmap
570524
*********************************************************/
@@ -764,7 +718,10 @@ const testtutorials = testTask("tutorial-test", "tutorialrunner.js");
764718
const testlanguageservice = testTask("language-service", "languageservicerunner.js");
765719
const testpxteditor = pxtEditorTestTask();
766720

767-
const buildKarmaRunner = () => compileTsProject("tests/blocklycompiler-test", "built/tests/", true);
721+
const buildKarmaRunner = () => compileTsProject("tests/blocklycompiler-test", "built/", true);
722+
const browserifyKarma = () =>
723+
exec('node node_modules/browserify/bin/cmd built/tests/blocklycompiler-test/test.spec.js -o built/tests/karma-test-runner.js --debug');
724+
768725
const runKarma = () => {
769726
let command;
770727
if (isWin32) {
@@ -777,9 +734,11 @@ const runKarma = () => {
777734
}
778735
return exec(command, true);
779736
}
780-
const karma = gulp.series(buildKarmaRunner, runKarma);
737+
const karma = gulp.series(buildKarmaRunner, browserifyKarma, runKarma);
781738

782-
const buildBlocksTestRunner = () => compileTsProject("tests/blocks-test", "built/tests", true)
739+
const buildBlocksTestRunner = () => compileTsProject("tests/blocks-test", "built/", true);
740+
const browserifyBlocksTestRunner = () =>
741+
exec('node node_modules/browserify/bin/cmd built/tests/blocks-test/blocksrunner.js -o built/tests/blocksrunner.js --debug');
783742

784743
const testAll = gulp.series(
785744
testdecompiler,
@@ -849,11 +808,10 @@ const buildAll = gulp.series(
849808
updatestrings,
850809
maybeUpdateWebappStrings(),
851810
copyTypescriptServices,
852-
copyBlocklyTypings,
853811
gulp.parallel(pxtlib, pxtweb),
854812
gulp.parallel(pxtcompiler, pxtsim, backendutils),
855-
gulp.parallel(pxtpy, gulp.series(copyBlockly, pxtblocks, pxtblockly)),
856-
pxteditor,
813+
pxtpy,
814+
gulp.parallel(pxteditor, pxtblocks),
857815
gulp.parallel(pxtrunner, cli, pxtcommon),
858816
browserifyEmbed,
859817
gulp.parallel(pxtjs, pxtdts, pxtapp, pxtworker, pxtembed),
@@ -866,6 +824,7 @@ const buildAll = gulp.series(
866824
browserifyAssetEditor,
867825
gulp.parallel(semanticjs, copyJquery, copyWebapp, copySemanticFonts, copyMonaco),
868826
buildBlocksTestRunner,
827+
browserifyBlocksTestRunner,
869828
runUglify
870829
);
871830

@@ -876,15 +835,14 @@ exports.clean = clean;
876835
exports.build = buildAll;
877836

878837
exports.webapp = gulp.series(
879-
reactCommon,
838+
gulp.parallel(reactCommon, pxtblocks, pxteditor),
880839
webapp,
881840
browserifyWebapp,
882841
browserifyAssetEditor
883842
)
884843

885844
exports.skillmapTest = testSkillmap;
886845
exports.updatestrings = updatestrings;
887-
exports.updateblockly = copyBlockly;
888846
exports.lint = lint
889847
exports.testdecompiler = testdecompiler;
890848
exports.testlang = testlang;
@@ -915,7 +873,7 @@ exports.testpxteditor = testpxteditor;
915873
exports.cli = gulp.series(
916874
gulp.parallel(pxtlib, pxtweb),
917875
gulp.parallel(pxtcompiler, pxtsim, backendutils),
918-
gulp.parallel(pxtpy, gulp.series(copyBlockly, pxtblocks, pxtblockly)),
876+
pxtpy,
919877
pxteditor,
920878
gulp.parallel(pxtrunner, cli, pxtcommon),
921879
pxtjs

karma.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ module.exports = function(config) {
2121
'built/web/typescript.js',
2222
'webapp/public/blockly/**/*.js',
2323
'built/pxtlib.js',
24-
'built/pxtblocks.js',
2524
'built/pxtcompiler.js',
26-
'built/tests/tests.spec.js',
25+
'built/tests/karma-test-runner.js',
2726

2827
// test assets
2928
{ pattern: 'tests/blocklycompiler-test/cases/*.blocks', watched: false, included: false, served: true, nocache: false },

localtypings/evaluation.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace pxt.blocks {
2+
export interface EvaluationResult {
3+
result: boolean;
4+
}
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type WorkspaceSvg = import("blockly").WorkspaceSvg;
2+
3+
declare module '@blockly/keyboard-navigation' {
4+
class NavigationController {
5+
init(): void;
6+
addWorkspace(workspace: WorkspaceSvg): void;
7+
enable(workspace: WorkspaceSvg): void;
8+
disable(workspace: WorkspaceSvg): void;
9+
focusToolbox(workspace: WorkspaceSvg): void;
10+
navigation: Navigation;
11+
}
12+
13+
class Navigation {
14+
resetFlyout(workspace: WorkspaceSvg, shouldHide: boolean): void;
15+
setState(workspace: WorkspaceSvg, state: BlocklyNavigationState): void;
16+
}
17+
18+
type BlocklyNavigationState = "workspace" | "toolbox" | "flyout";
19+
}

localtypings/pxtarget.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference path="pxtpackage.d.ts" />
22
/// <reference path="pxtparts.d.ts" />
3-
/// <reference path="pxtblockly.d.ts" />
43
/// <reference path="pxtelectron.d.ts" />
54

65
declare namespace pxt {
@@ -356,7 +355,8 @@ declare namespace pxt {
356355
invertedMonaco?: boolean; // if true: use the vs-dark monaco theme
357356
invertedGitHub?: boolean; // inverted github view
358357
lightToc?: boolean; // if true: do NOT use inverted style in docs toc
359-
blocklyOptions?: Blockly.BlocklyOptions; // Blockly options, see Configuration: https://developers.google.com/blockly/guides/get-started/web
358+
// FIXME (riknoll): Can't use Blockly types here
359+
blocklyOptions?: any; // Blockly options, see Configuration: https://developers.google.com/blockly/guides/get-started/web
360360
hideFlyoutHeadings?: boolean; // Hide the flyout headings at the top of the flyout when on a mobile device.
361361
monacoColors?: pxt.Map<string>; // Monaco theme colors, see https://code.visualstudio.com/docs/getstarted/theme-color-reference
362362
simAnimationEnter?: string; // Simulator enter animation
@@ -398,8 +398,8 @@ declare namespace pxt {
398398
useUploadMessage?: boolean; // change "Download" text to "Upload"
399399
downloadIcon?: string; // which icon io use for download
400400
blockColors?: Map<string>; // block namespace colors, used for build in categories
401-
blockIcons?: Map<string>;
402-
blocklyColors?: Blockly.Colours; // Blockly workspace, flyout and other colors
401+
blockIcons?: Map<string | number>;
402+
blocklyColors?: pxt.Map<string>; // Overrides for the styles in the workspace Blockly.Theme.ComponentStyle
403403
socialOptions?: SocialOptions; // show social icons in share dialog, options like twitter handle and org handle
404404
noReloadOnUpdate?: boolean; // do not notify the user or reload the page when a new app cache is downloaded
405405
appPathNames?: string[]; // Authorized URL paths in embedded apps, all other paths will display a warning banner

0 commit comments

Comments
 (0)