From 570164d876d9f38ca1387c0ac86e39b201f0df83 Mon Sep 17 00:00:00 2001 From: Nat Budin Date: Fri, 7 Jun 2024 11:07:02 -0700 Subject: [PATCH] Support Blockly 11 --- package.json | 2 +- src/BlocklyWorkspaceProps.ts | 3 +- src/dev-index.tsx | 26 +++-- src/index.ts | 5 +- src/useBlocklyWorkspace.ts | 24 +++-- yarn.lock | 204 ++++++++++++++++++++--------------- 6 files changed, 157 insertions(+), 107 deletions(-) diff --git a/package.json b/package.json index c925ecc..8866c0f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "author": "Nat Budin ", "license": "MIT", "dependencies": { - "blockly": ">= 10.0.0 < 11.0.0", + "blockly": ">= 11.0.0", "prop-types": "^15.8.1" }, "peerDependencies": { diff --git a/src/BlocklyWorkspaceProps.ts b/src/BlocklyWorkspaceProps.ts index 2d2a956..ed5ef59 100644 --- a/src/BlocklyWorkspaceProps.ts +++ b/src/BlocklyWorkspaceProps.ts @@ -1,4 +1,5 @@ -import Blockly, { WorkspaceSvg } from "blockly"; +import * as Blockly from "blockly/core"; +import { WorkspaceSvg } from "blockly"; import { RefObject } from "react"; export interface CommonBlocklyProps { diff --git a/src/dev-index.tsx b/src/dev-index.tsx index 3cc5162..fd5afc4 100644 --- a/src/dev-index.tsx +++ b/src/dev-index.tsx @@ -1,6 +1,6 @@ import React, { useState } from "react"; import ReactDOM from "react-dom"; -import Blockly from "blockly"; +import * as Blockly from "blockly/core"; import { javascriptGenerator } from "blockly/javascript"; import { BlocklyWorkspace } from "./index"; @@ -67,7 +67,9 @@ const TestEditor = () => { }); const newXml = Blockly.Xml.domToText(Blockly.Xml.workspaceToDom(workspace)); setGeneratedXml(newXml); - const newJson = JSON.stringify(Blockly.serialization.workspaces.save(workspace)); + const newJson = JSON.stringify( + Blockly.serialization.workspaces.save(workspace) + ); setGeneratedJson(newJson); const code = javascriptGenerator.workspaceToCode(workspace); setGeneratedCode(code); @@ -80,11 +82,19 @@ const TestEditor = () => { const onJsonChange = React.useCallback((newJson) => { setGeneratedJson(JSON.stringify(newJson)); }, []); - const [ serialState, setSerialState ] = useState<"XML" | "JSON">("XML") + const [serialState, setSerialState] = useState<"XML" | "JSON">("XML"); return ( <>
- + { snap: true, }, }} - initialXml={serialState === "XML" ? ConfigFiles.INITIAL_XML : undefined} - initialJson={serialState === "JSON" ? ConfigFiles.INITIAL_JSON : undefined} + initialXml={ + serialState === "XML" ? ConfigFiles.INITIAL_XML : undefined + } + initialJson={ + serialState === "JSON" ? ConfigFiles.INITIAL_JSON : undefined + } className="fill-height" onWorkspaceChange={onWorkspaceChange} onXmlChange={onXmlChange} diff --git a/src/index.ts b/src/index.ts index ad83213..89441c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,8 @@ import useBlocklyWorkspace from "./useBlocklyWorkspace"; import BlocklyWorkspace from "./BlocklyWorkspace"; -import Blockly, {WorkspaceSvg, Workspace} from "blockly"; +import { WorkspaceSvg, Workspace } from "blockly"; +import * as Blockly from "blockly/core"; import ToolboxDefinition1 = Blockly.utils.toolbox.ToolboxDefinition; export type ToolboxDefinition = ToolboxDefinition1; export { BlocklyWorkspace, useBlocklyWorkspace }; -export {WorkspaceSvg, Workspace}; +export { WorkspaceSvg, Workspace }; diff --git a/src/useBlocklyWorkspace.ts b/src/useBlocklyWorkspace.ts index f52adfc..7dff9f9 100644 --- a/src/useBlocklyWorkspace.ts +++ b/src/useBlocklyWorkspace.ts @@ -1,5 +1,6 @@ import React from "react"; -import Blockly, { Workspace, WorkspaceSvg } from "blockly"; +import * as Blockly from "blockly/core"; +import { Workspace, WorkspaceSvg } from "blockly"; import { UseBlocklyProps } from "./BlocklyWorkspaceProps"; import debounce from "./debounce"; @@ -50,10 +51,14 @@ const useBlocklyWorkspace = ({ onImportError, onInject, onDispose, -}: UseBlocklyProps): { workspace: WorkspaceSvg | null; xml: string | null, json: object | null } => { - // onImportError replaces onImportXmlError +}: UseBlocklyProps): { + workspace: WorkspaceSvg | null; + xml: string | null; + json: object | null; +} => { + // onImportError replaces onImportXmlError // This is done for not breaking the signature until depreaction - onImportError = onImportError ?? onImportXmlError + onImportError = onImportError ?? onImportXmlError; const [workspace, setWorkspace] = React.useState(null); const [xml, setXml] = React.useState(initialXml || null); @@ -72,7 +77,11 @@ const useBlocklyWorkspace = ({ const toolboxConfigurationRef = React.useRef(toolboxConfiguration); React.useEffect(() => { toolboxConfigurationRef.current = toolboxConfiguration; - if (toolboxConfiguration && workspace && !workspaceConfiguration?.readOnly) { + if ( + toolboxConfiguration && + workspace && + !workspaceConfiguration?.readOnly + ) { workspace.updateToolbox(toolboxConfiguration); } }, [toolboxConfiguration, workspace, workspaceConfiguration]); @@ -180,15 +189,14 @@ const useBlocklyWorkspace = ({ setXml(null); } setDidInitialImport(true); - } - else if (json && workspace && !didInitialImport) { + } else if (json && workspace && !didInitialImport) { const success = importFromJson(json, workspace, onImportError); if (!success) { setJson(null); } const jsonToXml = Blockly.Xml.domToText( Blockly.Xml.workspaceToDom(workspace) - ) + ); setXml(jsonToXml); setDidInitialImport(true); } diff --git a/yarn.lock b/yarn.lock index a9ca58c..a5c4a07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3370,7 +3370,7 @@ __metadata: languageName: node linkType: hard -"abab@npm:^2.0.3, abab@npm:^2.0.5, abab@npm:^2.0.6": +"abab@npm:^2.0.3, abab@npm:^2.0.5": version: 2.0.6 resolution: "abab@npm:2.0.6" checksum: 6ffc1af4ff315066c62600123990d87551ceb0aafa01e6539da77b0f5987ac7019466780bf480f1787576d4385e3690c81ccc37cfda12819bf510b8ab47e5a3e @@ -3493,6 +3493,15 @@ __metadata: languageName: node linkType: hard +"agent-base@npm:^7.0.2, agent-base@npm:^7.1.0": + version: 7.1.1 + resolution: "agent-base@npm:7.1.1" + dependencies: + debug: ^4.3.4 + checksum: 51c158769c5c051482f9ca2e6e1ec085ac72b5a418a9b31b4e82fe6c0a6699adb94c1c42d246699a587b3335215037091c79e0de512c516f73b6ea844202f037 + languageName: node + linkType: hard + "agentkeepalive@npm:^4.2.1": version: 4.2.1 resolution: "agentkeepalive@npm:4.2.1" @@ -4110,12 +4119,12 @@ __metadata: languageName: node linkType: hard -"blockly@npm:>= 10.0.0 < 11.0.0": - version: 10.4.3 - resolution: "blockly@npm:10.4.3" +"blockly@npm:>= 11.0.0": + version: 11.1.0 + resolution: "blockly@npm:11.1.0" dependencies: - jsdom: 22.1.0 - checksum: 1d01db87f31e23c3c1297457a54de887cf932c283d6db60c0ca478ed893f727a595908f86155c233ee93caea67c713b2657fe3966d655b8a35aaa0b5f5c50e0e + jsdom: 23.0.0 + checksum: 60ba27a2ac99129944b007f04f004c82092298a38e490fa6e4d94c51f2bc0495dcf3062b8efa373ff929a5751413512b777263d937836827bb708b2ee2e8939a languageName: node linkType: hard @@ -5142,14 +5151,13 @@ __metadata: languageName: node linkType: hard -"data-urls@npm:^4.0.0": - version: 4.0.0 - resolution: "data-urls@npm:4.0.0" +"data-urls@npm:^5.0.0": + version: 5.0.0 + resolution: "data-urls@npm:5.0.0" dependencies: - abab: ^2.0.6 - whatwg-mimetype: ^3.0.0 - whatwg-url: ^12.0.0 - checksum: 006e869b5bf079647949a3e9b1dd69d84b2d5d26e6b01c265485699bc96e83817d4b5aae758b2910a4c58c0601913f3a0034121c1ca2da268e9a244c57515b15 + whatwg-mimetype: ^4.0.0 + whatwg-url: ^14.0.0 + checksum: 5c40568c31b02641a70204ff233bc4e42d33717485d074244a98661e5f2a1e80e38fe05a5755dfaf2ee549f2ab509d6a3af2a85f4b2ad2c984e5d176695eaf46 languageName: node linkType: hard @@ -5490,15 +5498,6 @@ __metadata: languageName: node linkType: hard -"domexception@npm:^4.0.0": - version: 4.0.0 - resolution: "domexception@npm:4.0.0" - dependencies: - webidl-conversions: ^7.0.0 - checksum: ddbc1268edf33a8ba02ccc596735ede80375ee0cf124b30d2f05df5b464ba78ef4f49889b6391df4a04954e63d42d5631c7fcf8b1c4f12bc531252977a5f13d5 - languageName: node - linkType: hard - "domhandler@npm:^4.0.0, domhandler@npm:^4.2.0, domhandler@npm:^4.3.0": version: 4.3.0 resolution: "domhandler@npm:4.3.0" @@ -7178,12 +7177,12 @@ __metadata: languageName: node linkType: hard -"html-encoding-sniffer@npm:^3.0.0": - version: 3.0.0 - resolution: "html-encoding-sniffer@npm:3.0.0" +"html-encoding-sniffer@npm:^4.0.0": + version: 4.0.0 + resolution: "html-encoding-sniffer@npm:4.0.0" dependencies: - whatwg-encoding: ^2.0.0 - checksum: 8d806aa00487e279e5ccb573366a951a9f68f65c90298eac9c3a2b440a7ffe46615aff2995a2f61c6746c639234e6179a97e18ca5ccbbf93d3725ef2099a4502 + whatwg-encoding: ^3.1.1 + checksum: 3339b71dab2723f3159a56acf541ae90a408ce2d11169f00fe7e0c4663d31d6398c8a4408b504b4eec157444e47b084df09b3cb039c816660f0dd04846b8957d languageName: node linkType: hard @@ -7313,6 +7312,16 @@ __metadata: languageName: node linkType: hard +"http-proxy-agent@npm:^7.0.0": + version: 7.0.2 + resolution: "http-proxy-agent@npm:7.0.2" + dependencies: + agent-base: ^7.1.0 + debug: ^4.3.4 + checksum: 670858c8f8f3146db5889e1fa117630910101db601fff7d5a8aa637da0abedf68c899f03d3451cac2f83bcc4c3d2dabf339b3aa00ff8080571cceb02c3ce02f3 + languageName: node + linkType: hard + "http-proxy-middleware@npm:^2.0.0": version: 2.0.1 resolution: "http-proxy-middleware@npm:2.0.1" @@ -7347,13 +7356,13 @@ __metadata: languageName: node linkType: hard -"https-proxy-agent@npm:^5.0.1": - version: 5.0.1 - resolution: "https-proxy-agent@npm:5.0.1" +"https-proxy-agent@npm:^7.0.2": + version: 7.0.4 + resolution: "https-proxy-agent@npm:7.0.4" dependencies: - agent-base: 6 + agent-base: ^7.0.2 debug: 4 - checksum: 571fccdf38184f05943e12d37d6ce38197becdd69e58d03f43637f7fa1269cf303a7d228aa27e5b27bbd3af8f09fd938e1c91dcfefff2df7ba77c20ed8dfc765 + checksum: daaab857a967a2519ddc724f91edbbd388d766ff141b9025b629f92b9408fc83cee8a27e11a907aede392938e9c398e240d643e178408a59e4073539cde8cfe9 languageName: node linkType: hard @@ -8568,39 +8577,37 @@ __metadata: languageName: node linkType: hard -"jsdom@npm:22.1.0": - version: 22.1.0 - resolution: "jsdom@npm:22.1.0" +"jsdom@npm:23.0.0": + version: 23.0.0 + resolution: "jsdom@npm:23.0.0" dependencies: - abab: ^2.0.6 cssstyle: ^3.0.0 - data-urls: ^4.0.0 + data-urls: ^5.0.0 decimal.js: ^10.4.3 - domexception: ^4.0.0 form-data: ^4.0.0 - html-encoding-sniffer: ^3.0.0 - http-proxy-agent: ^5.0.0 - https-proxy-agent: ^5.0.1 + html-encoding-sniffer: ^4.0.0 + http-proxy-agent: ^7.0.0 + https-proxy-agent: ^7.0.2 is-potential-custom-element-name: ^1.0.1 - nwsapi: ^2.2.4 + nwsapi: ^2.2.7 parse5: ^7.1.2 rrweb-cssom: ^0.6.0 saxes: ^6.0.0 symbol-tree: ^3.2.4 - tough-cookie: ^4.1.2 - w3c-xmlserializer: ^4.0.0 + tough-cookie: ^4.1.3 + w3c-xmlserializer: ^5.0.0 webidl-conversions: ^7.0.0 - whatwg-encoding: ^2.0.0 - whatwg-mimetype: ^3.0.0 - whatwg-url: ^12.0.1 - ws: ^8.13.0 - xml-name-validator: ^4.0.0 + whatwg-encoding: ^3.1.1 + whatwg-mimetype: ^4.0.0 + whatwg-url: ^14.0.0 + ws: ^8.14.2 + xml-name-validator: ^5.0.0 peerDependencies: - canvas: ^2.5.0 + canvas: ^3.0.0 peerDependenciesMeta: canvas: optional: true - checksum: d955ab83a6dad3e6af444098d30647c719bbb4cf97de053aa5751c03c8d6f3283d8c4d7fc2774c181f1d432fb0250e7332bc159e6b466424f4e337d73adcbf30 + checksum: 51c787b6cee1add7a60b5a32faafbff60e29b246568c3c87c0ed766105b2b286dbe4e5bd31d63dc575c1f3eaaa124f1fb02a6b0923780cf95f98faadf33ad1b1 languageName: node linkType: hard @@ -9544,10 +9551,10 @@ __metadata: languageName: node linkType: hard -"nwsapi@npm:^2.2.4": - version: 2.2.7 - resolution: "nwsapi@npm:2.2.7" - checksum: cab25f7983acec7e23490fec3ef7be608041b460504229770e3bfcf9977c41d6fe58f518994d3bd9aa3a101f501089a3d4a63536f4ff8ae4b8c4ca23bdbfda4e +"nwsapi@npm:^2.2.7": + version: 2.2.10 + resolution: "nwsapi@npm:2.2.10" + checksum: 5f1d361b38c47ab49727d5ea8bbfeb5867ae6de0e538eec9a8b77c88005ddde36d8b930e0730b50ee5e5dda949112c0f9ffed1bf15e7e1b3cd9cfa319f5a9b6f languageName: node linkType: hard @@ -11025,13 +11032,20 @@ __metadata: languageName: node linkType: hard -"punycode@npm:^2.1.0, punycode@npm:^2.1.1, punycode@npm:^2.3.0": +"punycode@npm:^2.1.0, punycode@npm:^2.1.1": version: 2.3.0 resolution: "punycode@npm:2.3.0" checksum: 39f760e09a2a3bbfe8f5287cf733ecdad69d6af2fe6f97ca95f24b8921858b91e9ea3c9eeec6e08cede96181b3bb33f95c6ffd8c77e63986508aa2e8159fa200 languageName: node linkType: hard +"punycode@npm:^2.3.1": + version: 2.3.1 + resolution: "punycode@npm:2.3.1" + checksum: bb0a0ceedca4c3c57a9b981b90601579058903c62be23c5e8e843d2c2d4148a3ecf029d5133486fb0e1822b098ba8bba09e89d6b21742d02fa26bda6441a6fb2 + languageName: node + linkType: hard + "q@npm:^1.1.2": version: 1.5.1 resolution: "q@npm:1.5.1" @@ -11136,7 +11150,7 @@ __metadata: "@typescript-eslint/eslint-plugin": ^5.53.0 "@typescript-eslint/parser": ^5.53.0 babel-eslint: ^10.1.0 - blockly: ">= 10.0.0 < 11.0.0" + blockly: ">= 11.0.0" css-loader: ^6.7.3 eslint: ^8.34.0 eslint-config-prettier: ^8.6.0 @@ -12838,7 +12852,7 @@ __metadata: languageName: node linkType: hard -"tough-cookie@npm:^4.0.0, tough-cookie@npm:^4.1.2": +"tough-cookie@npm:^4.0.0": version: 4.1.3 resolution: "tough-cookie@npm:4.1.3" dependencies: @@ -12850,6 +12864,18 @@ __metadata: languageName: node linkType: hard +"tough-cookie@npm:^4.1.3": + version: 4.1.4 + resolution: "tough-cookie@npm:4.1.4" + dependencies: + psl: ^1.1.33 + punycode: ^2.1.1 + universalify: ^0.2.0 + url-parse: ^1.5.3 + checksum: 5815059f014c31179a303c673f753f7899a6fce94ac93712c88ea5f3c26e0c042b5f0c7a599a00f8e0feeca4615dba75c3dffc54f3c1a489978aa8205e09307c + languageName: node + linkType: hard + "tr46@npm:^1.0.1": version: 1.0.1 resolution: "tr46@npm:1.0.1" @@ -12868,12 +12894,12 @@ __metadata: languageName: node linkType: hard -"tr46@npm:^4.1.1": - version: 4.1.1 - resolution: "tr46@npm:4.1.1" +"tr46@npm:^5.0.0": + version: 5.0.0 + resolution: "tr46@npm:5.0.0" dependencies: - punycode: ^2.3.0 - checksum: aeeb821ac2cd792e63ec84888b4fd6598ac6ed75d861579e21a5cf9d4ee78b2c6b94e7d45036f2ca2088bc85b9b46560ad23c4482979421063b24137349dbd96 + punycode: ^2.3.1 + checksum: 8d8b021f8e17675ebf9e672c224b6b6cfdb0d5b92141349e9665c14a2501c54a298d11264bbb0b17b447581e1e83d4fc3c038c929f3d210e3964d4be47460288 languageName: node linkType: hard @@ -13263,12 +13289,12 @@ __metadata: languageName: node linkType: hard -"w3c-xmlserializer@npm:^4.0.0": - version: 4.0.0 - resolution: "w3c-xmlserializer@npm:4.0.0" +"w3c-xmlserializer@npm:^5.0.0": + version: 5.0.0 + resolution: "w3c-xmlserializer@npm:5.0.0" dependencies: - xml-name-validator: ^4.0.0 - checksum: eba070e78deb408ae8defa4d36b429f084b2b47a4741c4a9be3f27a0a3d1845e277e3072b04391a138f7e43776842627d1334e448ff13ff90ad9fb1214ee7091 + xml-name-validator: ^5.0.0 + checksum: 593acc1fdab3f3207ec39d851e6df0f3fa41a36b5809b0ace364c7a6d92e351938c53424a7618ce8e0fbaffee8be2e8e070a5734d05ee54666a8bdf1a376cc40 languageName: node linkType: hard @@ -13589,12 +13615,12 @@ __metadata: languageName: node linkType: hard -"whatwg-encoding@npm:^2.0.0": - version: 2.0.0 - resolution: "whatwg-encoding@npm:2.0.0" +"whatwg-encoding@npm:^3.1.1": + version: 3.1.1 + resolution: "whatwg-encoding@npm:3.1.1" dependencies: iconv-lite: 0.6.3 - checksum: 7087810c410aa9b689cbd6af8773341a53cdc1f3aae2a882c163bd5522ec8ca4cdfc269aef417a5792f411807d5d77d50df4c24e3abb00bb60192858a40cc675 + checksum: f75a61422421d991e4aec775645705beaf99a16a88294d68404866f65e92441698a4f5b9fa11dd609017b132d7b286c3c1534e2de5b3e800333856325b549e3c languageName: node linkType: hard @@ -13612,20 +13638,20 @@ __metadata: languageName: node linkType: hard -"whatwg-mimetype@npm:^3.0.0": - version: 3.0.0 - resolution: "whatwg-mimetype@npm:3.0.0" - checksum: ce08bbb36b6aaf64f3a84da89707e3e6a31e5ab1c1a2379fd68df79ba712a4ab090904f0b50e6693b0dafc8e6343a6157e40bf18fdffd26e513cf95ee2a59824 +"whatwg-mimetype@npm:^4.0.0": + version: 4.0.0 + resolution: "whatwg-mimetype@npm:4.0.0" + checksum: f97edd4b4ee7e46a379f3fb0e745de29fe8b839307cc774300fd49059fcdd560d38cb8fe21eae5575b8f39b022f23477cc66e40b0355c2851ce84760339cef30 languageName: node linkType: hard -"whatwg-url@npm:^12.0.0, whatwg-url@npm:^12.0.1": - version: 12.0.1 - resolution: "whatwg-url@npm:12.0.1" +"whatwg-url@npm:^14.0.0": + version: 14.0.0 + resolution: "whatwg-url@npm:14.0.0" dependencies: - tr46: ^4.1.1 + tr46: ^5.0.0 webidl-conversions: ^7.0.0 - checksum: 8698993b763c1e7eda5ed16c31dab24bca6489626aca7caf8b5a2b64684dda6578194786f10ec42ceb1c175feea16d0a915096e6419e08d154ce551c43176972 + checksum: 4b5887e50f786583bead70916413e67a381d2126899b9eb5c67ce664bba1e7ec07cdff791404581ce73c6190d83c359c9ca1d50711631217905db3877dec075c languageName: node linkType: hard @@ -13988,9 +14014,9 @@ __metadata: languageName: node linkType: hard -"ws@npm:^8.13.0": - version: 8.13.0 - resolution: "ws@npm:8.13.0" +"ws@npm:^8.14.2": + version: 8.17.0 + resolution: "ws@npm:8.17.0" peerDependencies: bufferutil: ^4.0.1 utf-8-validate: ">=5.0.2" @@ -13999,7 +14025,7 @@ __metadata: optional: true utf-8-validate: optional: true - checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c + checksum: 147ef9eab0251364e1d2c55338ad0efb15e6913923ccbfdf20f7a8a6cb8f88432bcd7f4d8f66977135bfad35575644f9983201c1a361019594a4e53977bf6d4e languageName: node linkType: hard @@ -14025,10 +14051,10 @@ __metadata: languageName: node linkType: hard -"xml-name-validator@npm:^4.0.0": - version: 4.0.0 - resolution: "xml-name-validator@npm:4.0.0" - checksum: af100b79c29804f05fa35aa3683e29a321db9b9685d5e5febda3fa1e40f13f85abc40f45a6b2bf7bee33f68a1dc5e8eaef4cec100a304a9db565e6061d4cb5ad +"xml-name-validator@npm:^5.0.0": + version: 5.0.0 + resolution: "xml-name-validator@npm:5.0.0" + checksum: 86effcc7026f437701252fcc308b877b4bc045989049cfc79b0cc112cb365cf7b009f4041fab9fb7cd1795498722c3e9fe9651afc66dfa794c16628a639a4c45 languageName: node linkType: hard