From 93b47822b879580e07f89ccbbe4bf196df56759c Mon Sep 17 00:00:00 2001 From: 12944qwerty Date: Fri, 14 Oct 2022 17:06:42 +0000 Subject: [PATCH] cleanup --- index.html | 211 +---------------------------------------------------- index.js | 149 +++++++++++++++++++++++++++++++++++++ style.css | 49 +++++++++++++ 3 files changed, 202 insertions(+), 207 deletions(-) create mode 100644 index.js create mode 100644 style.css diff --git a/index.html b/index.html index 9c57666..44d28b9 100644 --- a/index.html +++ b/index.html @@ -14,223 +14,20 @@ - - // Wait for Blockly to finish loading. - - // const IS_UNCOMPRESSED = !window.bootstrapInfo.compressed; // See bootstrap.js - var workspace = null; - - function start() { - setBackgroundColour(); - - var toolbox = getToolboxElement(); - var match = location.search.match(/side=([^&]+)/); - var autoimport = !!location.search.match(/autoimport=([^&]+)/); - // Create main workspace. - workspace = Blockly.inject('blocklyDiv', - { - 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: 'https://unpkg.com/blockly/media/', - oneBasedIndex: true, - readOnly: false, - move: { - scrollbars: true, - drag: true, - wheel: false, - }, - toolbox: toolbox, - toolboxPosition: 'start', - renderer: 'geras', - zoom: - { - controls: true, - wheel: true, - startScale: 1.0, - maxScale: 4, - minScale: 0.25, - scaleSpeed: 1.1 - } - }); - workspace.configureContextMenu = configureContextMenu; - // Restore previously displayed text. - if (localStorage) { - var text = localStorage.getItem('textarea'); - if (text) { - document.getElementById('importExportjson').value = text; - } - } - - load(); - - addEventHandlers(); - } - - function setBackgroundColour() { - document.body.style.backgroundColor = '#60fcfc'; // Familiar lilac. - } - - function getToolboxElement() { - return document.getElementById('toolbox-categories'); - } - - function saveJson() { - var output = document.getElementById('importExportjson'); - var state = Blockly.serialization.workspaces.save(workspace); - var save = JSON.stringify(state, null, 2); - output.value = save; - localStorage.setItem('textarea', save); - } - - function load() { - var input = document.getElementById('importExportjson'); - if (!input.value) { - return; - } - var valid = saveIsValid(input.value); - if (valid.json) { - var state = JSON.parse(input.value); - Blockly.serialization.workspaces.load(state, workspace); - } else if (valid.xml) { - var xml = Blockly.Xml.textToDom(input.value); - Blockly.Xml.domToWorkspace(xml, workspace); - } - - toCode(); - } - - - function toCode() { - var output = document.getElementById('importExport'); - output.value = TagScript.workspaceToCode(workspace); - } - - // Disable the "Load" button if the save state is invalid. - // Preserve text between page reloads. - function taChange() { - toCode() - saveJson(); - } - - function saveIsValid(save) { - var validJson = true; - try { - JSON.parse(save); - } catch (e) { - validJson = false; - } - var validXml = true - try { - Blockly.Xml.textToDom(save); - } catch (e) { - validXml = false; - } - return { - json: validJson, - xml: validXml - } - } - - - function configureContextMenu(menuOptions, e) { - 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)); - } - - function addEventHandlers() { - document.getElementById('importExportjson').addEventListener('change', taChange); - document.getElementById('importExportjson').addEventListener('keyup', taChange); - - document.getElementById('show') - .addEventListener('click', function() { workspace.setVisible(true); }); - document.getElementById('hide') - .addEventListener('click', function() { workspace.setVisible(false); }); - - workspace.addChangeListener(taChange) - } - - // Call start(). Because this - - + -

TagScript Block Editor

+

by 12944qwerty - v0.0.1

- - - +

TagScript Code diff --git a/index.js b/index.js new file mode 100644 index 0000000..9298c7d --- /dev/null +++ b/index.js @@ -0,0 +1,149 @@ +var workspace = null; + +function start() { + setBackgroundColour(); + + var toolbox = getToolboxElement(); + // Create main workspace. + workspace = Blockly.inject('blocklyDiv', { + 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: 'https://unpkg.com/blockly/media/', + oneBasedIndex: true, + readOnly: false, + move: { + scrollbars: true, + drag: true, + wheel: false, + }, + toolbox: toolbox, + toolboxPosition: 'start', + renderer: 'geras', + zoom: { + controls: true, + wheel: true, + startScale: 1.0, + maxScale: 4, + minScale: 0.25, + scaleSpeed: 1.1 + } + }); + + if (localStorage) { + var text = localStorage.getItem('textarea'); + if (text) { + document.getElementById('importExportjson').value = text; + } + } + + load(); + + addEventHandlers(); +} + +function setBackgroundColour() { + document.body.style.backgroundColor = '#60fcfc'; // Familiar lilac. +} + +function getToolboxElement() { + return document.getElementById('toolbox-categories'); +} + +function saveJson() { + var output = document.getElementById('importExportjson'); + var state = Blockly.serialization.workspaces.save(workspace); + var save = JSON.stringify(state, null, 2); + output.value = save; + localStorage.setItem('textarea', save); +} + +function load() { + var input = document.getElementById('importExportjson'); + if (!input.value) { + return; + } + var valid = saveIsValid(input.value); + if (valid.json) { + var state = JSON.parse(input.value); + Blockly.serialization.workspaces.load(state, workspace); + } else if (valid.xml) { + var xml = Blockly.Xml.textToDom(input.value); + Blockly.Xml.domToWorkspace(xml, workspace); + } + + toCode(); +} + + +function toCode() { + var output = document.getElementById('importExport'); + output.value = TagScript.workspaceToCode(workspace); +} + +// Disable the "Load" button if the save state is invalid. +// Preserve text between page reloads. +function taChange() { + toCode() + saveJson(); +} + +function saveIsValid(save) { + var validJson = true; + try { + JSON.parse(save); + } catch (e) { + validJson = false; + } + var validXml = true + try { + Blockly.Xml.textToDom(save); + } catch (e) { + validXml = false; + } + return { + json: validJson, + xml: validXml + } +} + + +function configureContextMenu(menuOptions, e) { + 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)); +} + +function addEventHandlers() { + document.getElementById('importExportjson').addEventListener('change', taChange); + document.getElementById('importExportjson').addEventListener('keyup', taChange); + + document.getElementById('show') + .addEventListener('click', function() { workspace.setVisible(true); }); + document.getElementById('hide') + .addEventListener('click', function() { workspace.setVisible(false); }); + document.getElementById('clear') + .addEventListener('click', function() { document.getElementById('importExportjson').value = '{}'; load() }); + + workspace.addChangeListener(taChange) +} + +start(); diff --git a/style.css b/style.css new file mode 100644 index 0000000..ff5566b --- /dev/null +++ b/style.css @@ -0,0 +1,49 @@ + +html, body { + height: 100%; +} +body { + background-color: #fff; + font-family: sans-serif; + overflow: hidden; + text-align: center; +} +h1 { + font-weight: normal; + font-size: 140%; + margin-bottom: 0px; +} +.version { + font-weight: normal; + margin-top: 0px; + color: #333333; + opacity: 0.8; +} +#blocklyDiv { + float: left; + height: 95%; + width: 70%; +} +#importExport { + font-family: monospace; +} + +.ioLabel>.blocklyFlyoutLabelText { + font-style: italic; +} + +#blocklyDiv.renderingDebug .blockRenderDebug { + display: block; +} + +.playgroundToggleOptions { + list-style: none; + padding: 0; +} +.playgroundToggleOptions li { + margin-top: 1em; +} + +.zelos-renderer .blocklyFlyoutButton .blocklyText { + font-size: 1.5rem; +} \ No newline at end of file