{"code":"(window.webpackJsonpGUI=window.webpackJsonpGUI||[]).push([[18],{1546:function(t,e,s){\"use strict\";s.r(e),s.d(e,\"resources\",(function(){return a}));const a={\"userscript.js\":async function(t){let{addon:e,console:s,msg:a,safeMsg:o}=t;const r=await e.tab.traps.getBlockly(),n=e.tab.traps.vm;let i=!1;const l=t=>{const e=t.findIndex((t=>\"CREATE_LIST\"===t.getAttribute(\"callbackkey\")||\"data_addtolist\"===t.getAttribute(\"type\")));return{variables:t.slice(0,e),lists:t.slice(e,t.length)}},c=r.DataCategory;let g,u;const p=t=>{let s=c(t);if(!e.self.disabled&&e.settings.get(\"moveReportersDown\")&&(s=(t=>{const{variables:e,lists:s}=l(t),a=t=>{const e=[],s=[];for(const a of t)a.hasAttribute(\"id\")||\"BUTTON\"===a.tagName?e.push(a):s.push(a);return s.length&&s[s.length-1].setAttribute(\"gap\",24),s.concat(e)};return a(e).concat(a(s))})(s)),!e.self.disabled&&e.settings.get(\"separateLocalVariables\")&&(s=((t,e)=>{const{variables:s,lists:o}=l(e),r=t=>{const e=document.createElement(\"label\");return e.setAttribute(\"text\",a(t)),e},n=t=>{if(t.length>0){for(var e=0;e{const s=[],a=[],o=[],i=[];for(const r of e)if(r.hasAttribute(\"id\")){const e=r.getAttribute(\"id\"),s=t.getVariableById(e);s&&s.isLocal?o.push(r):a.push(r)}else a.length||o.length?i.push(r):s.push(r);const l=s;return a.length&&(l.push(r(\"for-all-sprites\")),n(a),l.push(...a)),o.length&&(l.push(r(\"for-this-sprite-only\")),n(o),l.push(...o)),l.concat(i)};return i(s).concat(i(o))})(t,s)),e.self.disabled||!i)return s;const{variables:o,lists:r}=l(s);return g=o,u=r,g},d=()=>u,b=r.Flyout.prototype.show;r.Flyout.prototype.show=function(t){return this.workspace_.registerToolboxCategoryCallback(\"VARIABLE\",p),this.workspace_.registerToolboxCategoryCallback(\"LIST\",d),b.call(this,t)};const h=n.runtime.getBlocksXML;n.runtime.getBlocksXML=function(t){const s=h.call(this,t);return i=e.settings.get(\"separateListCategory\"),!e.self.disabled&&i&&(s.push({id:\"data\",xml:'\\n \\n \\n \\n ')}),s.map=t=>Array.prototype.map.call(s,(e=>\"data\"===e.id?e:t(e)))),s},n.editingTarget&&n.emitWorkspaceUpdate(),e.settings.addEventListener(\"change\",(t=>{if(e.settings.get(\"separateListCategory\")!==i)n.editingTarget&&n.emitWorkspaceUpdate();else{const t=Blockly.getMainWorkspace();t&&t.refreshToolboxSelection_()}}));const y=()=>{if(e.settings.get(\"separateListCategory\")&&n.editingTarget&&n.emitWorkspaceUpdate(),e.settings.get(\"separateLocalVariables\")||e.settings.get(\"moveReportersDown\")){const t=Blockly.getMainWorkspace();t&&t.refreshToolboxSelection_()}};e.self.addEventListener(\"disabled\",(()=>{y()})),e.self.addEventListener(\"reenabled\",(()=>{y()}))}}}}]);","name":"js/pentapod/addon-entry-data-category-tweaks-v2.8e11932b6d0cefe143de.js","input":"(window[\"webpackJsonpGUI\"] = window[\"webpackJsonpGUI\"] || []).push([[18],{\n\n/***/ 1546:\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n// ESM COMPAT FLAG\n__webpack_require__.r(__webpack_exports__);\n\n// EXPORTS\n__webpack_require__.d(__webpack_exports__, \"resources\", function() { return /* binding */ resources; });\n\n// CONCATENATED MODULE: ./src/addons/addons/data-category-tweaks-v2/userscript.js\n/* harmony default export */ var userscript = (async function (_ref) {\n let {\n addon,\n console,\n msg,\n safeMsg\n } = _ref;\n const ScratchBlocks = await addon.tab.traps.getBlockly();\n const SMALL_GAP = 8;\n const BIG_GAP = 24;\n const vm = addon.tab.traps.vm;\n\n // Used in setting change handler. Updated in getBlocksXML.\n // (Yes this is weird but it's how it was originally and I'm too scared to change it)\n let hasSeparateListCategory = false;\n const separateVariablesByType = toolboxXML => {\n const listButtonIndex = toolboxXML.findIndex(i => i.getAttribute(\"callbackkey\") === \"CREATE_LIST\" || i.getAttribute(\"type\") === \"data_addtolist\");\n return {\n variables: toolboxXML.slice(0, listButtonIndex),\n lists: toolboxXML.slice(listButtonIndex, toolboxXML.length)\n };\n };\n const separateLocalVariables = (workspace, toolboxXML) => {\n const {\n variables,\n lists\n } = separateVariablesByType(toolboxXML);\n const makeLabel = l10n => {\n const label = document.createElement(\"label\");\n label.setAttribute(\"text\", msg(l10n));\n return label;\n };\n const fixGaps = variables => {\n if (variables.length > 0) {\n for (var i = 0; i < variables.length - 1; i++) {\n variables[i].setAttribute(\"gap\", SMALL_GAP);\n }\n variables[i].setAttribute(\"gap\", BIG_GAP);\n }\n };\n const separateVariablesByScope = xml => {\n const before = [];\n const global = [];\n const local = [];\n const after = [];\n for (const blockXML of xml) {\n if (blockXML.hasAttribute(\"id\")) {\n const id = blockXML.getAttribute(\"id\");\n const variable = workspace.getVariableById(id);\n if (!variable || !variable.isLocal) {\n global.push(blockXML);\n } else {\n local.push(blockXML);\n }\n } else if (global.length || local.length) {\n after.push(blockXML);\n } else {\n before.push(blockXML);\n }\n }\n const result = before;\n if (global.length) {\n result.push(makeLabel(\"for-all-sprites\"));\n fixGaps(global);\n result.push(...global);\n }\n if (local.length) {\n result.push(makeLabel(\"for-this-sprite-only\"));\n fixGaps(local);\n result.push(...local);\n }\n return result.concat(after);\n };\n return separateVariablesByScope(variables).concat(separateVariablesByScope(lists));\n };\n const moveReportersDown = toolboxXML => {\n const {\n variables,\n lists\n } = separateVariablesByType(toolboxXML);\n const moveReportersToEnd = xml => {\n const reporters = [];\n const everythingElse = [];\n for (const blockXML of xml) {\n if (blockXML.hasAttribute(\"id\") || blockXML.tagName === \"BUTTON\") {\n // Round reporters and the create variable button\n reporters.push(blockXML);\n } else {\n // Everything else like \"change variable by 1\"\n everythingElse.push(blockXML);\n }\n }\n if (everythingElse.length) {\n everythingElse[everythingElse.length - 1].setAttribute(\"gap\", BIG_GAP);\n }\n return everythingElse.concat(reporters);\n };\n return moveReportersToEnd(variables).concat(moveReportersToEnd(lists));\n };\n const DataCategory = ScratchBlocks.DataCategory;\n let variableCategory;\n let listCategory;\n const variableCategoryCallback = workspace => {\n let result = DataCategory(workspace);\n if (!addon.self.disabled && addon.settings.get(\"moveReportersDown\")) {\n result = moveReportersDown(result);\n }\n if (!addon.self.disabled && addon.settings.get(\"separateLocalVariables\")) {\n result = separateLocalVariables(workspace, result);\n }\n if (addon.self.disabled || !hasSeparateListCategory) {\n return result;\n }\n const {\n variables,\n lists\n } = separateVariablesByType(result);\n variableCategory = variables;\n listCategory = lists;\n return variableCategory;\n };\n const listCategoryCallback = () => {\n // Computed in variable category callback, which should be called before this method.\n return listCategory;\n };\n\n // Each time a new workspace is made, these callbacks are reset, so re-register whenever a flyout is shown.\n // https://github.com/scratchfoundation/scratch-blocks/blob/61f02e4cac0f963abd93013842fe536ef24a0e98/core/flyout_base.js#L469\n const oldShow = ScratchBlocks.Flyout.prototype.show;\n ScratchBlocks.Flyout.prototype.show = function (xmlList) {\n this.workspace_.registerToolboxCategoryCallback(\"VARIABLE\", variableCategoryCallback);\n this.workspace_.registerToolboxCategoryCallback(\"LIST\", listCategoryCallback);\n return oldShow.call(this, xmlList);\n };\n\n // Use Scratch's extension category mechanism to replace the data category with our own.\n // https://github.com/scratchfoundation/scratch-gui/blob/ddd2fa06f2afa140a46ec03be91796ded861e65c/src/containers/blocks.jsx#L344\n // https://github.com/scratchfoundation/scratch-gui/blob/2ceab00370ad7bd8ecdf5c490e70fd02152b3e2a/src/lib/make-toolbox-xml.js#L763\n // https://github.com/scratchfoundation/scratch-vm/blob/a0c11d6d8664a4f2d55632e70630d09ec6e9ae28/src/engine/runtime.js#L1381\n const originalGetBlocksXML = vm.runtime.getBlocksXML;\n vm.runtime.getBlocksXML = function (target) {\n const result = originalGetBlocksXML.call(this, target);\n hasSeparateListCategory = addon.settings.get(\"separateListCategory\");\n if (!addon.self.disabled && hasSeparateListCategory) {\n result.push({\n id: \"data\",\n xml: \"\\n \\n \\n \\n \")\n });\n result.map = callback => {\n // Prevent Scratch from trying to change the color of the added category in high contrast mode.\n // https://github.com/scratchfoundation/scratch-gui/blob/44eb578/src/containers/blocks.jsx#L358-L361\n // https://github.com/scratchfoundation/scratch-gui/blob/44eb578/src/lib/themes/blockHelpers.js#L18-L53\n return Array.prototype.map.call(result, extension => {\n if (extension.id === \"data\") return extension;else return callback(extension);\n });\n };\n }\n return result;\n };\n\n // If editingTarget is set, the editor has already rendered and we have to tell it to rerender.\n if (vm.editingTarget) {\n vm.emitWorkspaceUpdate();\n }\n addon.settings.addEventListener(\"change\", e => {\n // When the separate list category option changes, we need to do a workspace update.\n // For all other options, just refresh the toolbox.\n // Always doing both of these in response to a settings change causes many issues.\n if (addon.settings.get(\"separateListCategory\") !== hasSeparateListCategory) {\n if (vm.editingTarget) {\n vm.emitWorkspaceUpdate();\n }\n } else {\n const workspace = Blockly.getMainWorkspace();\n if (workspace) {\n workspace.refreshToolboxSelection_();\n }\n }\n });\n const dynamicEnableOrDisable = () => {\n // Enabling/disabling is similar to changing settings.\n // If separate list category is enabled, a workspace update is needed.\n // If any other setting is enabled, refresh the toolbox.\n if (addon.settings.get(\"separateListCategory\")) {\n if (vm.editingTarget) {\n vm.emitWorkspaceUpdate();\n }\n }\n if (addon.settings.get(\"separateLocalVariables\") || addon.settings.get(\"moveReportersDown\")) {\n const workspace = Blockly.getMainWorkspace();\n if (workspace) {\n workspace.refreshToolboxSelection_();\n }\n }\n };\n addon.self.addEventListener(\"disabled\", () => {\n dynamicEnableOrDisable();\n });\n addon.self.addEventListener(\"reenabled\", () => {\n dynamicEnableOrDisable();\n });\n});\n// CONCATENATED MODULE: ./src/addons/addons/data-category-tweaks-v2/_runtime_entry.js\n/* generated by pull.js */\n\nconst resources = {\n \"userscript.js\": userscript\n};\n\n/***/ })\n\n}]);","inputSourceMap":null}