/
index.ts
48 lines (42 loc) · 1.13 KB
/
index.ts
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
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Plugin test.
*/
import * as Blockly from 'blockly';
import {toolboxCategories, createPlayground} from '@blockly/dev-tools';
import {PositionedMinimap} from '../src/index';
let minimap: PositionedMinimap | null = null;
/**
* Create a workspace.
*
* @param blocklyDiv The blockly container div.
* @param options The Blockly options.
* @returns The created workspace.
*/
function createWorkspace(
blocklyDiv: HTMLElement,
options: Blockly.BlocklyOptions,
): Blockly.WorkspaceSvg {
// Creates the primary workspace and adds the minimap.
if (minimap) {
minimap.dispose();
}
const workspace = Blockly.inject(blocklyDiv, options);
minimap = new PositionedMinimap(workspace);
minimap.init();
return workspace;
}
document.addEventListener('DOMContentLoaded', function () {
const rootElement = document.getElementById('root');
if (rootElement === null) {
console.error("No element with id 'root' found");
return;
}
createPlayground(rootElement, createWorkspace, {
toolbox: toolboxCategories,
});
});