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 { defineReact, defineWindow } from "web-utils";
|
||||||
import { Root } from "./root";
|
import { Root } from "./root";
|
||||||
import { initBaseConfig } from "./base/base";
|
import { initBaseConfig } from "./base/base";
|
||||||
|
import { w } from "./w";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
initBaseConfig();
|
initBaseConfig();
|
||||||
|
|
@ -10,6 +11,30 @@ import { initBaseConfig } from "./base/base";
|
||||||
const root = createRoot(div);
|
const root = createRoot(div);
|
||||||
await defineWindow(false);
|
await defineWindow(false);
|
||||||
defineReact();
|
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 />);
|
root.render(<Root />);
|
||||||
if (document.body.classList.contains("opacity-0")) {
|
if (document.body.classList.contains("opacity-0")) {
|
||||||
document.body.classList.remove("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 { DeadEnd } from "../../utils/ui/deadend";
|
||||||
import { Loading } from "../../utils/ui/loading";
|
import { Loading } from "../../utils/ui/loading";
|
||||||
|
import { evalCJS } from "../ed/logic/ed-sync";
|
||||||
|
import { Vi } from "../vi/vi";
|
||||||
import { base } from "./base/base";
|
import { base } from "./base/base";
|
||||||
|
import { scanComponent } from "./base/component";
|
||||||
import { loadPage } from "./base/page";
|
import { loadPage } from "./base/page";
|
||||||
import { detectResponsiveMode } from "./base/responsive";
|
import { detectResponsiveMode } from "./base/responsive";
|
||||||
import { initBaseRoute, rebuildMeta } from "./base/route";
|
import { initBaseRoute, rebuildMeta } from "./base/route";
|
||||||
import { scanComponent } from "./base/component";
|
import { w } from "./w";
|
||||||
import { Vi } from "../vi/vi";
|
import { GlobalContext } from "web-utils";
|
||||||
import { evalCJS } from "../ed/logic/ed-sync";
|
|
||||||
|
|
||||||
const w = window as any;
|
|
||||||
|
|
||||||
export const Root = () => {
|
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
|
// #region init
|
||||||
if (base.route.status !== "ready") {
|
if (base.route.status !== "ready") {
|
||||||
|
|
@ -30,11 +35,11 @@ export const Root = () => {
|
||||||
);
|
);
|
||||||
if (site_script) {
|
if (site_script) {
|
||||||
for (const [k, v] of Object.entries(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" />;
|
return <Loading note="Loading router" />;
|
||||||
|
|
@ -66,10 +71,10 @@ export const Root = () => {
|
||||||
await scanComponent(root.childs);
|
await scanComponent(root.childs);
|
||||||
rebuildMeta(p.meta, root);
|
rebuildMeta(p.meta, root);
|
||||||
base.page.cache[p.id] = p;
|
base.page.cache[p.id] = p;
|
||||||
local.render();
|
render();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
local.render();
|
render();
|
||||||
});
|
});
|
||||||
|
|
||||||
return <Loading note="Loading page" />;
|
return <Loading note="Loading page" />;
|
||||||
|
|
@ -80,6 +85,7 @@ export const Root = () => {
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Provider value={w.prasiContext}>
|
||||||
<div className={cx("relative flex flex-1 items-center justify-center")}>
|
<div className={cx("relative flex flex-1 items-center justify-center")}>
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
|
|
@ -136,5 +142,6 @@ export const Root = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
export const w = window as unknown as {
|
export const w = window as unknown as {
|
||||||
_prasi: {
|
prasiContext: {
|
||||||
context: {};
|
global: any;
|
||||||
render: () => {};
|
render: () => void;
|
||||||
};
|
};
|
||||||
|
params: any;
|
||||||
|
navigateOverride: (href: string) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue