import React, { lazy, useEffect, useState } from "react"; import "./App.css"; const LowcoderAppView: any = lazy(async () => ({ default: (await import("lowcoder-sdk")).LowcoderAppView, })); declare global { interface Window { Base64: { decode: any }; flutter_inappwebview: { callHandler: any }; loadScreen: (arg: never) => void; } } function App() { const [appId, setAppId] = useState(""); const [baseUrl, setBaseUrl] = useState(""); const [webUrl, setWebUrl] = useState(""); const [input, setInput] = useState | undefined>({}); const [appDsl, setAppDsl] = useState(); const [moduleDslMap, setModuleDslMap] = useState(); const emitEvent = (message: any) => { console.debug("event", message); window.flutter_inappwebview?.callHandler("MessageInvoker", message); }; useEffect(() => { const url = new URL(location.href); const appIdQuery = url.searchParams.get("appId"); const moduleInputsQuery = url.searchParams.get("moduleInputs"); const baseUrlQuery = url.searchParams.get("baseUrl") || "https://screenbuilder.smartcity-cloud.org/prod"; const webUrlQuery = url.searchParams.get("webUrl") || "https://screenbuilder.smartcity-cloud.org"; if (appIdQuery) setAppId(appIdQuery); if (moduleInputsQuery) { const parsedInput = JSON.parse(moduleInputsQuery); Object.entries(parsedInput).forEach(([key, value]) => { if (typeof value != "string") parsedInput[key] = JSON.stringify(value); }); setInput(parsedInput); } if (baseUrlQuery) setBaseUrl(baseUrlQuery); if (webUrlQuery) setWebUrl(webUrlQuery); window.loadScreen = ({ appId, baseUrl, moduleInputs, appDsl, moduleDslMap }: any) => { if (appId) setAppId(appId); if (baseUrl) setBaseUrl(baseUrl); if (moduleInputs) setInput(moduleInputs); if (appDsl) setAppDsl(appDsl); if (moduleDslMap) setModuleDslMap(moduleDslMap); }; }, []); return appId ? ( { emitEvent({ type: "event", data: name }); }} onModuleOutputChange={(output: any) => { emitEvent({ type: "outputChange", data: output }); }} appDsl={appDsl} moduleDslMap={moduleDslMap} /> ) : null; } export default App;