Files
blockly/tests/playgrounds/advanced_playground.html
Christopher Allen 5b5a56586c refactor(tests): Introduce loading shims, use in playgrounds (#7380)
* refactor(build): Simplify implementation of posixPath

* fix(closure): Make safe to import in node.js

  Make the implementation declareModlueId safe to import and
  execute in node.js, which does not provide a window global.

  (N.B. because this is an ESM and therefore automatically
  strict, using window?.goog?.declareModuleId doesn't work
  because window being undefined is an early error.)

* feat(tests): Introduce chunk loading shims

  - Add a buildShims task to build_tasks.js that, for each chunk,
    creates a correspondingly-named build/<chunk>.mjs that will
    either (in uncompressed mode) import and reexport that chunk's
    entry point module (e.g. core/blockly.js) or (in compressed
    mode) load dist/<chunk>_compressed.js using a <script> tag
    and then export the corresponding properties on the chunk's
    exports object.

  - Provide helper methods used by these shims in
    tests/scripts/loading.mjs, including code to detect whether
    to load in compressed or uncompressed mode.

  - Add a quote() function to scripts/helpers.js, used by
    buildShims.  This is copied from tests/bootstrap_helper.js,
    which will be removed in a later commit.

* refactor(tests): Update playground.html to use new loading shims

* refactor(tests): Update advanced_playground.html to use new loading shims

* refactor(tests): Update multi_playground.html to use new loading shims

* chore(tests): Delete playgrounds/shared_procedures.html

  Shared procedure support was moved to a plugin and this should
  have been removed from core along with it.

* docs(tests): Typo corrections.

* chore(tests): Add ".loader" infix to shim filenames.

  Per suggestion on PR #7380, have buildShims name the shims
  ${chunk.name}.loader.mjs instead of just `${chunk.name}.mjs`.
2023-08-14 22:47:19 +01:00

175 lines
4.8 KiB
HTML

<!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);
workspace.configureContextMenu = configureContextMenu.bind(workspace);
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,
},
};
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.
}
}
function configureContextMenu(menuOptions, e) {
var workspace = this;
var screenshotOption = {
text: 'Download Screenshot',
enabled: workspace.getTopBlocks().length,
callback: function () {
downloadScreenshot(workspace);
},
};
menuOptions.push(screenshotOption);
// Adds a default-sized workspace comment to the workspace.
menuOptions.push(
Blockly.ContextMenu.workspaceCommentOption(workspace, e),
);
}
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>