wip fix
This commit is contained in:
parent
9e1b693779
commit
dc44d54924
|
|
@ -2,6 +2,7 @@ import { createRoot } from "react-dom/client";
|
|||
import { defineReact, defineWindow } from "web-utils";
|
||||
import { Root } from "./root";
|
||||
import { initBaseConfig } from "./base/base";
|
||||
import { w } from "./w";
|
||||
|
||||
(async () => {
|
||||
initBaseConfig();
|
||||
|
|
@ -10,6 +11,30 @@ import { initBaseConfig } from "./base/base";
|
|||
const root = createRoot(div);
|
||||
await defineWindow(false);
|
||||
defineReact();
|
||||
|
||||
w.navigateOverride = (_href: string) => {
|
||||
if (_href && _href.startsWith("/")) {
|
||||
if (
|
||||
location.hostname.split(".").length === 4 ||
|
||||
location.hostname === "prasi.app" ||
|
||||
location.hostname === "prasi.avolut.com" ||
|
||||
location.hostname.includes("ngrok") ||
|
||||
location.hostname === "localhost" ||
|
||||
location.hostname === "127.0.0.1" ||
|
||||
location.hostname === "10.0.2.2" // android localhost
|
||||
) {
|
||||
if (
|
||||
location.pathname.startsWith("/deploy") &&
|
||||
!_href.startsWith("/deploy")
|
||||
) {
|
||||
const patharr = location.pathname.split("/");
|
||||
_href = `/deploy/${patharr[2]}${_href}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _href;
|
||||
};
|
||||
|
||||
root.render(<Root />);
|
||||
if (document.body.classList.contains("opacity-0")) {
|
||||
document.body.classList.remove("opacity-0");
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
import { useLocal } from "web-utils";
|
||||
import { FC, useState } from "react";
|
||||
import { DeadEnd } from "../../utils/ui/deadend";
|
||||
import { Loading } from "../../utils/ui/loading";
|
||||
import { evalCJS } from "../ed/logic/ed-sync";
|
||||
import { Vi } from "../vi/vi";
|
||||
import { base } from "./base/base";
|
||||
import { scanComponent } from "./base/component";
|
||||
import { loadPage } from "./base/page";
|
||||
import { detectResponsiveMode } from "./base/responsive";
|
||||
import { initBaseRoute, rebuildMeta } from "./base/route";
|
||||
import { scanComponent } from "./base/component";
|
||||
import { Vi } from "../vi/vi";
|
||||
import { evalCJS } from "../ed/logic/ed-sync";
|
||||
|
||||
const w = window as any;
|
||||
import { w } from "./w";
|
||||
import { GlobalContext } from "web-utils";
|
||||
|
||||
export const Root = () => {
|
||||
const local = useLocal({});
|
||||
// #region context
|
||||
const [_, set] = useState({});
|
||||
const render = () => set({});
|
||||
w.prasiContext.render = render;
|
||||
const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>;
|
||||
// #endregion
|
||||
|
||||
// #region init
|
||||
if (base.route.status !== "ready") {
|
||||
|
|
@ -30,11 +35,11 @@ export const Root = () => {
|
|||
);
|
||||
if (site_script) {
|
||||
for (const [k, v] of Object.entries(site_script)) {
|
||||
w[k] = v;
|
||||
(window as any)[k] = v;
|
||||
}
|
||||
}
|
||||
|
||||
local.render();
|
||||
render();
|
||||
});
|
||||
}
|
||||
return <Loading note="Loading router" />;
|
||||
|
|
@ -66,10 +71,10 @@ export const Root = () => {
|
|||
await scanComponent(root.childs);
|
||||
rebuildMeta(p.meta, root);
|
||||
base.page.cache[p.id] = p;
|
||||
local.render();
|
||||
render();
|
||||
})
|
||||
.catch(() => {
|
||||
local.render();
|
||||
render();
|
||||
});
|
||||
|
||||
return <Loading note="Loading page" />;
|
||||
|
|
@ -80,6 +85,7 @@ export const Root = () => {
|
|||
// #endregion
|
||||
|
||||
return (
|
||||
<Provider value={w.prasiContext}>
|
||||
<div className={cx("relative flex flex-1 items-center justify-center")}>
|
||||
<div
|
||||
className={cx(
|
||||
|
|
@ -136,5 +142,6 @@ export const Root = () => {
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
export const w = window as unknown as {
|
||||
_prasi: {
|
||||
context: {};
|
||||
render: () => {};
|
||||
prasiContext: {
|
||||
global: any;
|
||||
render: () => void;
|
||||
};
|
||||
params: any;
|
||||
navigateOverride: (href: string) => void;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue