-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
Copy pathadvanced_playground.html
158 lines (143 loc) · 4.24 KB
/
advanced_playground.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Advanced Blockly Playground</title>
<script type="module">
import {loadScript} from '../scripts/load.mjs';
import * as Blockly from '../../build/blockly.loader.mjs';
import '../../build/blocks.loader.mjs';
// Generators not needed (but see also bug #6597).
await loadScript('../../build/msg/en.js');
await loadScript('screenshot.js');
await loadScript('../themes/test_themes.js');
await loadScript('../../node_modules/@blockly/dev-tools/dist/index.js');
await loadScript(
'../../node_modules/@blockly/theme-modern/dist/index.js',
);
function start() {
setBackgroundColour();
initPlayground();
}
function createWorkspace(blocklyDiv, options) {
var workspace = Blockly.inject(blocklyDiv, options);
return workspace;
}
function configurePlayground(playground) {
// Rendering options.
var gui = playground.getGUI();
var renderingFolder = gui.addFolder('Rendering');
var renderingOptions = {
'font Size': 10,
};
renderingFolder
.add(renderingOptions, 'font Size', 0, 50)
.onChange(function (value) {
var ws = playground.getWorkspace();
var fontStyle = {
'size': value,
};
ws.getTheme().setFontStyle(fontStyle);
// Refresh theme.
ws.setTheme(ws.getTheme());
});
}
function initPlayground() {
if (typeof window.createPlayground === 'undefined') {
alert(
"You need to run 'npm install' in order to use this playground.",
);
return;
}
var defaultOptions = {
comments: true,
collapse: true,
disable: true,
grid: {
spacing: 25,
length: 3,
colour: '#ccc',
snap: true,
},
horizontalLayout: false,
maxBlocks: Infinity,
maxInstances: {'test_basic_limit_instances': 3},
maxTrashcanContents: 256,
media: '../../media/',
oneBasedIndex: true,
readOnly: false,
rtl: false,
move: {
scrollbars: true,
drag: true,
wheel: false,
},
toolbox: toolboxCategories,
toolboxPosition: 'start',
renderer: 'geras',
zoom: {
controls: true,
wheel: true,
startScale: 1.0,
maxScale: 4,
minScale: 0.25,
scaleSpeed: 1.1,
},
};
const playgroundConfig = {
toolboxes: {
'categories': toolboxCategories,
'simple': toolboxSimple,
'test blocks': toolboxTestBlocks,
},
};
Blockly.ContextMenuItems.registerCommentOptions();
createPlayground(
document.getElementById('root'),
createWorkspace,
defaultOptions,
playgroundConfig,
'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.19.2/min/vs',
).then(function (playground) {
configurePlayground(playground);
});
}
function setBackgroundColour() {
// Set background colour to differentiate file: vs. localhost
// vs. server copy.
if (location.protocol == 'file:') {
document.body.style.backgroundColor = '#89A203'; // Unpleasant green.
} else if (
location.hostname === 'localhost' ||
location.hostname === '127.0.0.1' ||
location.hostname === '[::1]'
) {
document.body.style.backgroundColor = '#d6d6ff'; // Familliar lilac.
}
}
start();
</script>
<style>
html,
body {
margin: 0;
}
.ioLabel > .blocklyFlyoutLabelText {
font-style: italic;
}
.playgroundToggleOptions {
list-style: none;
padding: 0;
}
.playgroundToggleOptions li {
margin-top: 1em;
}
.zelos-renderer .blocklyFlyoutButton .blocklyText {
font-size: 1.5rem;
}
</style>
</head>
<body>
<div id="root"></div>
</body>
</html>