diff --git a/packages/blockly/src/manager.ts b/packages/blockly/src/manager.ts index 97a5ee0..f97bc69 100644 --- a/packages/blockly/src/manager.ts +++ b/packages/blockly/src/manager.ts @@ -169,36 +169,42 @@ export class BlocklyManager { private _filterContents(contents: ToolboxItemInfo[]): number { let visible = 0; contents.forEach(itemInfo => { - if ("kind" in itemInfo) { - if (itemInfo.kind.toUpperCase() === "CATEGORY") { - if ("contents" in itemInfo) { + if ('kind' in itemInfo) { + if (itemInfo.kind.toUpperCase() === 'CATEGORY') { + if ('contents' in itemInfo) { const categoryInfo = itemInfo as StaticCategoryInfo; if (this._filterContents(categoryInfo.contents) > 0) { visible++; - categoryInfo.hidden = "false"; + categoryInfo.hidden = 'false'; } else { - categoryInfo.hidden = "true"; + categoryInfo.hidden = 'true'; } - } else if ("custom" in itemInfo) { + } else if ('custom' in itemInfo) { const categoryInfo = itemInfo as DynamicCategoryInfo; - if (this._allowedBlocks === undefined || this._allowedBlocks.includes(categoryInfo.custom.toLowerCase())) { - categoryInfo.hidden = "false"; + if ( + this._allowedBlocks === undefined || + this._allowedBlocks.includes(categoryInfo.custom.toLowerCase()) + ) { + categoryInfo.hidden = 'false'; visible++; - console.log("Category " + categoryInfo.custom + " is allowed"); + console.log(`Category ${categoryInfo.custom} is allowed`); } else { - categoryInfo.hidden = "true"; - console.log("Category " + categoryInfo.custom + " is not allowed"); + categoryInfo.hidden = 'true'; + console.log(`Category ${categoryInfo.custom} is not allowed`); } } - } else if (itemInfo.kind.toUpperCase() === "BLOCK") { + } else if (itemInfo.kind.toUpperCase() === 'BLOCK') { const blockInfo = itemInfo as BlockInfo; - if (this._allowedBlocks === undefined || this._allowedBlocks.includes(blockInfo.type.toLowerCase())) { + if ( + this._allowedBlocks === undefined || + this._allowedBlocks.includes(blockInfo.type.toLowerCase()) + ) { blockInfo.disabled = false; blockInfo.disabledReasons = []; visible++; } else { blockInfo.disabled = true; - blockInfo.disabledReasons = ["This block is not allowed"]; + blockInfo.disabledReasons = ['This block is not allowed']; } } } diff --git a/packages/blockly/src/widget.ts b/packages/blockly/src/widget.ts index be164b0..fa3f605 100644 --- a/packages/blockly/src/widget.ts +++ b/packages/blockly/src/widget.ts @@ -5,9 +5,9 @@ import { } from '@jupyterlab/docregistry'; import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import { runIcon } from '@jupyterlab/ui-components'; -import { showErrorMessage } from "@jupyterlab/apputils"; +import { showErrorMessage } from '@jupyterlab/apputils'; -import { PartialJSONObject } from "@lumino/coreutils"; +import { PartialJSONObject } from '@lumino/coreutils'; import { SplitPanel } from '@lumino/widgets'; import { Signal } from '@lumino/signaling'; @@ -148,30 +148,37 @@ export class BlocklyPanel extends SplitPanel { // Check if format is set or if we have legacy content if (fileFormat === undefined && fileContent['blocks']) { // Load legacy content - (this.layout as BlocklyLayout).workspace = fileContent as any as Blockly.Workspace; + (this.layout as BlocklyLayout).workspace = + fileContent as any as Blockly.Workspace; } else if (fileFormat === 2) { // Load the content from the "workspace" key - (this.layout as BlocklyLayout).workspace = fileContent['workspace'] as any as Blockly.Workspace; + const workspace = fileContent['workspace'] as any as Blockly.Workspace; + (this.layout as BlocklyLayout).workspace = workspace; const metadata = fileContent['metadata']; if (metadata) { if (metadata['toolbox']) { const toolbox = metadata['toolbox']; - if (this._manager.listToolboxes().find(value => value.value === toolbox)) { + if ( + this._manager.listToolboxes().find(value => value.value === toolbox) + ) { this._manager.setToolbox(metadata['toolbox']); } else { // Unknown toolbox - showErrorMessage(`Unknown toolbox`, - `The toolbox '` + toolbox + `' is not available. Using default toolbox.` + showErrorMessage( + 'Unknown toolbox', + `The toolbox '${toolbox}' is not available. Using default toolbox.` ); } } if (metadata['kernel'] && metadata['kernel'] !== 'No kernel') { const kernel = metadata['kernel']; - if (this._manager.listKernels().find(value => value.value === kernel)) { + if ( + this._manager.listKernels().find(value => value.value === kernel) + ) { this._manager.selectKernel(metadata['kernel']); } else { // Unknown kernel - console.warn(`Unknown kernel in blockly file: ` + kernel); + console.warn(`Unknown kernel in blockly file: ${kernel}`); } } if (metadata['allowed_blocks']) { @@ -180,8 +187,9 @@ export class BlocklyPanel extends SplitPanel { } } else { // Unsupported format - showErrorMessage(`Unsupported file format`, - `The file format '` + fileFormat + `' is not supported by the Blockly editor.` + showErrorMessage( + 'Unsupported file format', + `The file format '${fileFormat}' is not supported by the Blockly editor.` ); } }