1
+ import * as Blockly from 'blockly' ;
2
+
3
+ // Creating a toolbox containing all the main (default) blocks.
1
4
export 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
- //{
14
5
kind : 'categoryToolbox' ,
15
6
contents : [
16
7
{
17
8
kind : 'category' ,
18
9
name : 'Logic' ,
19
- colour : '210' ,
10
+ categorystyle : "logic_category" ,
11
+ blockstyle : 'logic_blocks' ,
20
12
contents : [
21
13
{
22
14
kind : 'block' ,
@@ -56,7 +48,8 @@ export const TOOLBOX = {
56
48
{
57
49
kind : 'category' ,
58
50
name : 'Loops' ,
59
- colour : '120' ,
51
+ categorystyle : "loops_category" ,
52
+ blockstyle : 'loops_blocks' ,
60
53
contents : [
61
54
{
62
55
kind : 'BLOCK' ,
@@ -90,7 +83,8 @@ export const TOOLBOX = {
90
83
{
91
84
kind : 'CATEGORY' ,
92
85
name : 'Math' ,
93
- colour : '230' ,
86
+ categorystyle : "math_category" ,
87
+ blockstyle : 'math_blocks' ,
94
88
contents : [
95
89
{
96
90
kind : 'BLOCK' ,
@@ -171,7 +165,8 @@ export const TOOLBOX = {
171
165
{
172
166
kind : 'CATEGORY' ,
173
167
name : 'Text' ,
174
- colour : '160' ,
168
+ categorystyle : "text_category" ,
169
+ blockstyle : 'text_blocks' ,
175
170
contents : [
176
171
{
177
172
kind : 'BLOCK' ,
@@ -248,7 +243,8 @@ export const TOOLBOX = {
248
243
{
249
244
kind : 'CATEGORY' ,
250
245
name : 'Lists' ,
251
- colour : '260' ,
246
+ categorystyle : "list_category" ,
247
+ blockstyle : 'list_blocks' ,
252
248
contents : [
253
249
{
254
250
kind : 'BLOCK' ,
@@ -317,7 +313,8 @@ export const TOOLBOX = {
317
313
{
318
314
kind : 'CATEGORY' ,
319
315
name : 'Color' ,
320
- colour : '20' ,
316
+ categorystyle : "color_category" ,
317
+ blockstyle : 'color_blocks' ,
321
318
contents : [
322
319
{
323
320
kind : 'BLOCK' ,
@@ -349,14 +346,100 @@ export const TOOLBOX = {
349
346
{
350
347
kind : 'CATEGORY' ,
351
348
colour : '330' ,
349
+ // categorystyle: "variables_category",
350
+ // blockstyle: 'variables_blocks',
352
351
custom : 'VARIABLE' ,
353
352
name : 'Variables'
354
353
} ,
355
354
{
356
355
kind : 'CATEGORY' ,
357
356
colour : '290' ,
357
+ // categorystyle: "functions_category",
358
+ // blockstyle: 'functions_blocks',
358
359
custom : 'PROCEDURE' ,
359
360
name : 'Functions'
360
361
}
361
362
]
362
363
} ;
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