1+ import * as Blockly from 'blockly' ;
2+
3+ // Creating a toolbox containing all the main (default) blocks.
14export const TOOLBOX = {
2- //kind: 'flyoutToolbox',
3- // contents: [
4- // {
5- // kind: 'block',
6- // type: 'controls_if'
7- // },
8- // {
9- // kind: 'block',
10- // type: 'controls_whileUntil'
11- // }
12- // ]
13- //{
145 kind : 'categoryToolbox' ,
156 contents : [
167 {
178 kind : 'category' ,
189 name : 'Logic' ,
19- colour : '210' ,
10+ categorystyle : "logic_category" ,
11+ blockstyle : 'logic_blocks' ,
2012 contents : [
2113 {
2214 kind : 'block' ,
@@ -56,7 +48,8 @@ export const TOOLBOX = {
5648 {
5749 kind : 'category' ,
5850 name : 'Loops' ,
59- colour : '120' ,
51+ categorystyle : "loops_category" ,
52+ blockstyle : 'loops_blocks' ,
6053 contents : [
6154 {
6255 kind : 'BLOCK' ,
@@ -90,7 +83,8 @@ export const TOOLBOX = {
9083 {
9184 kind : 'CATEGORY' ,
9285 name : 'Math' ,
93- colour : '230' ,
86+ categorystyle : "math_category" ,
87+ blockstyle : 'math_blocks' ,
9488 contents : [
9589 {
9690 kind : 'BLOCK' ,
@@ -171,7 +165,8 @@ export const TOOLBOX = {
171165 {
172166 kind : 'CATEGORY' ,
173167 name : 'Text' ,
174- colour : '160' ,
168+ categorystyle : "text_category" ,
169+ blockstyle : 'text_blocks' ,
175170 contents : [
176171 {
177172 kind : 'BLOCK' ,
@@ -248,7 +243,8 @@ export const TOOLBOX = {
248243 {
249244 kind : 'CATEGORY' ,
250245 name : 'Lists' ,
251- colour : '260' ,
246+ categorystyle : "list_category" ,
247+ blockstyle : 'list_blocks' ,
252248 contents : [
253249 {
254250 kind : 'BLOCK' ,
@@ -317,7 +313,8 @@ export const TOOLBOX = {
317313 {
318314 kind : 'CATEGORY' ,
319315 name : 'Color' ,
320- colour : '20' ,
316+ categorystyle : "color_category" ,
317+ blockstyle : 'color_blocks' ,
321318 contents : [
322319 {
323320 kind : 'BLOCK' ,
@@ -349,14 +346,100 @@ export const TOOLBOX = {
349346 {
350347 kind : 'CATEGORY' ,
351348 colour : '330' ,
349+ // categorystyle: "variables_category",
350+ // blockstyle: 'variables_blocks',
352351 custom : 'VARIABLE' ,
353352 name : 'Variables'
354353 } ,
355354 {
356355 kind : 'CATEGORY' ,
357356 colour : '290' ,
357+ // categorystyle: "functions_category",
358+ // blockstyle: 'functions_blocks',
358359 custom : 'PROCEDURE' ,
359360 name : 'Functions'
360361 }
361362 ]
362363} ;
364+
365+ // Defining a Blockly Theme in accordance with the current JupyterLab Theme.
366+ export function define_jupyter_theme ( ) : Blockly . Theme {
367+ Blockly . registry . unregister ( 'theme' , 'jupyterlab' ) ;
368+
369+ var jupyterlab_theme = Blockly . Theme . defineTheme ( 'jupyterlab' , {
370+ 'base' : Blockly . Themes . Classic ,
371+ 'blockStyles' : {
372+ "logic_blocks" : {
373+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-error-color1' ) ,
374+ "colourSecondary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-error-color3' )
375+ } ,
376+ "loops_blocks" : {
377+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-accent-color0' ) ,
378+ "colourSecondary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-accent-color3' )
379+ } ,
380+ "math_blocks" : {
381+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-brand-color0' ) ,
382+ "colourSecondary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-brand-color3' )
383+ } ,
384+ "text_blocks" : {
385+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-icon-contrast-color0' ) ,
386+ } ,
387+ "list_blocks" : {
388+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-icon-contrast-color2' )
389+ } ,
390+ "color_blocks" : {
391+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-warn-color0' ) ,
392+ "colourSecondary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-warn-color3' )
393+ } ,
394+ "variables_blocks" : {
395+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-accent-color2' ) ,
396+ "colourSecondary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-accent-color3' )
397+ } ,
398+ "functions_blocks" : {
399+ "colourPrimary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-info-color0' ) ,
400+ "colourSecondary" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-info-color3' )
401+ }
402+ } ,
403+ 'categoryStyles' : {
404+ "logic_category" : {
405+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-error-color1' )
406+ } ,
407+ "loops_category" : {
408+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-accent-color0' )
409+ } ,
410+ "math_category" : {
411+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-brand-color0' )
412+ } ,
413+ "text_category" : {
414+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-icon-contrast-color0' )
415+ } ,
416+ "list_category" : {
417+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-icon-contrast-color2' )
418+ } ,
419+ "color_category" : {
420+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-warn-color0' )
421+ } ,
422+ "variables_category" : {
423+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-accent-color2' )
424+ } ,
425+ "functions_category" : {
426+ "colour" : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-info-color0' )
427+ }
428+ } ,
429+ 'componentStyles' : {
430+ 'workspaceBackgroundColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-layout-color0' ) ,
431+ 'toolboxBackgroundColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-layout-color2' ) ,
432+ 'toolboxForegroundColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-ui-font-color0' ) ,
433+ 'flyoutBackgroundColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-border-color2' ) ,
434+ 'flyoutForegroundColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-layout-color3' ) ,
435+ 'flyoutOpacity' : 1 ,
436+ 'scrollbarColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-border-color0' ) ,
437+ 'insertionMarkerColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-warn-color-active' ) ,
438+ 'insertionMarkerOpacity' : 0.3 ,
439+ 'scrollbarOpacity' : 0.4 ,
440+ 'cursorColour' : getComputedStyle ( document . documentElement ) . getPropertyValue ( '--jp-scrollbar-background-color' ) ,
441+ }
442+ } ) ;
443+
444+ return jupyterlab_theme ;
445+ }
0 commit comments