Skip to content

Commit d961db1

Browse files
feat: add a category toolbox to the test page (#161)
1 parent fe651dc commit d961db1

File tree

3 files changed

+850
-44
lines changed

3 files changed

+850
-44
lines changed

src/blocks/toolbox.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,55 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
export const toolbox = {
8-
'kind': 'flyoutToolbox',
9-
'contents': [
10-
{
11-
kind: 'block',
12-
type: 'p5_background_color',
13-
inputs: {
14-
COLOR: {
15-
shadow: {
16-
type: 'colour_picker',
17-
},
7+
export const p5CategoryContents = [
8+
{
9+
kind: 'block',
10+
type: 'p5_background_color',
11+
inputs: {
12+
COLOR: {
13+
shadow: {
14+
type: 'colour_picker',
1815
},
1916
},
2017
},
21-
{
22-
kind: 'block',
23-
type: 'colour_random',
24-
},
25-
{
26-
kind: 'block',
27-
type: 'draw_emoji',
28-
},
29-
{
30-
kind: 'block',
31-
type: 'simple_circle',
32-
inputs: {
33-
COLOR: {
34-
shadow: {
35-
type: 'colour_picker',
36-
},
18+
},
19+
{
20+
kind: 'block',
21+
type: 'colour_random',
22+
},
23+
{
24+
kind: 'block',
25+
type: 'draw_emoji',
26+
},
27+
{
28+
kind: 'block',
29+
type: 'simple_circle',
30+
inputs: {
31+
COLOR: {
32+
shadow: {
33+
type: 'colour_picker',
3734
},
3835
},
3936
},
40-
{
41-
kind: 'block',
42-
type: 'write_text_with_shadow',
43-
inputs: {
44-
TEXT: {
45-
shadow: {
46-
type: 'text_only',
47-
},
37+
},
38+
{
39+
kind: 'block',
40+
type: 'write_text_with_shadow',
41+
inputs: {
42+
TEXT: {
43+
shadow: {
44+
type: 'text_only',
4845
},
4946
},
5047
},
51-
{
52-
kind: 'block',
53-
type: 'write_text_without_shadow',
54-
},
55-
],
48+
},
49+
{
50+
kind: 'block',
51+
type: 'write_text_without_shadow',
52+
},
53+
];
54+
55+
export const toolbox = {
56+
'kind': 'flyoutToolbox',
57+
'contents': p5CategoryContents,
5658
};

test/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
import * as Blockly from 'blockly';
8+
// Import the default blocks.
9+
import * as libraryBlocks from 'blockly/blocks';
810
import {installAllBlocks as installColourBlocks} from '@blockly/field-colour';
911
import {KeyboardNavigation} from '../src/index';
1012
// @ts-expect-error No types in js file
@@ -13,6 +15,8 @@ import {forBlock} from '../src/blocks/p5_generators';
1315
import {blocks} from '../src/blocks/p5_blocks';
1416
// @ts-expect-error No types in js file
1517
import {toolbox} from '../src/blocks/toolbox.js';
18+
// @ts-expect-error No types in js file
19+
import toolboxCategories from './toolboxCategories.js';
1620

1721
import {javascriptGenerator} from 'blockly/javascript';
1822
// @ts-expect-error No types in js file
@@ -47,11 +51,13 @@ function loadScenario(workspace: Blockly.WorkspaceSvg) {
4751
*/
4852
function createWorkspace(): Blockly.WorkspaceSvg {
4953
console.log(location.search);
50-
const renderer =
51-
location.search.includes('geras') ? 'geras' :
52-
location.search.includes('thrasos') ? 'thrasos' : 'zelos';
54+
const renderer = location.search.includes('geras')
55+
? 'geras'
56+
: location.search.includes('thrasos')
57+
? 'thrasos'
58+
: 'zelos';
5359
const options = {
54-
toolbox: toolbox,
60+
toolbox: toolboxCategories,
5561
renderer,
5662
};
5763
const blocklyDiv = document.getElementById('blocklyDiv')!;

0 commit comments

Comments
 (0)