This commit is contained in:
Rizky 2024-01-24 06:01:04 +07:00
parent 669ed3112c
commit 2f74afcd30
5 changed files with 33 additions and 24 deletions

View File

@ -35,6 +35,7 @@ export const EdMain = () => {
local.cache = ( local.cache = (
<Vi <Vi
meta={p.page.meta} meta={p.page.meta}
mode={p.mode}
api_url={p.site.config.api_url} api_url={p.site.config.api_url}
site_id={p.site.id} site_id={p.site.id}
page_id={p.page.cur.id} page_id={p.page.cur.id}

View File

@ -82,6 +82,7 @@ export const ViPreview = (arg: { pathname: string }) => {
> >
<Vi <Vi
meta={p.page.meta} meta={p.page.meta}
mode={p.mode}
api_url={p.site.config.api_url} api_url={p.site.config.api_url}
site_id={p.site.id} site_id={p.site.id}
page_id={p.page.cur.id} page_id={p.page.cur.id}

View File

@ -4,26 +4,27 @@ import { viParts } from "./parts";
type ViStatus = "init" | "loading" | "ready"; type ViStatus = "init" | "loading" | "ready";
export const ViGlobal = { export const ViGlobal = {
ts: 0, ts: 0,
status: "init" as ViStatus, status: "init" as ViStatus,
meta: {} as Record<string, IMeta>, meta: {} as Record<string, IMeta>,
tick: 0, tick: 0,
site: { mode: "desktop" as "mobile" | "desktop",
id: "", site: {
api_url: "", id: "",
api: null as any, api_url: "",
db: null as any, api: null as any,
code: { db: null as any,
mode: "old" as "old" | "vsc", code: {
}, mode: "old" as "old" | "vsc",
}, },
script: { },
init_local_effect: undefined as undefined | Record<string, boolean>, script: {
}, init_local_effect: undefined as undefined | Record<string, boolean>,
visit: undefined as },
| undefined visit: undefined as
| ((meta: IMeta, parts: ReturnType<typeof viParts>) => void), | undefined
on_status_changes: undefined as void | ((status: ViStatus) => void), | ((meta: IMeta, parts: ReturnType<typeof viParts>) => void),
on_status_changes: undefined as void | ((status: ViStatus) => void),
}; };
export type VG = typeof ViGlobal & { render: () => void }; export type VG = typeof ViGlobal & { render: () => void };

View File

@ -1,5 +1,8 @@
export const viScriptArg = (vi: { site: { db: any; api: any } }) => ({ export const viScriptArg = (vi: {
isMobile: false, mode: "mobile" | "desktop";
isDesktop: true, site: { db: any; api: any };
isEditor: true, }) => ({
isMobile: vi.mode === "mobile",
isDesktop: vi.mode === "desktop",
isEditor: location.pathname.startsWith("/ed/"),
}); });

View File

@ -9,6 +9,7 @@ import { render_stat } from "./render/render";
export const Vi: FC<{ export const Vi: FC<{
meta: Record<string, IMeta>; meta: Record<string, IMeta>;
mode: "mobile" | "desktop";
comp_load?: (comp_id: string) => Promise<void>; comp_load?: (comp_id: string) => Promise<void>;
entry: string[]; entry: string[];
api_url: string; api_url: string;
@ -26,6 +27,7 @@ export const Vi: FC<{
api_url, api_url,
site_id, site_id,
api, api,
mode,
db, db,
visit, visit,
script, script,
@ -33,6 +35,7 @@ export const Vi: FC<{
on_status_changed, on_status_changed,
}) => { }) => {
const vi = useGlobal(ViGlobal, "VI"); const vi = useGlobal(ViGlobal, "VI");
vi.mode = mode;
vi.on_status_changes = on_status_changed; vi.on_status_changes = on_status_changed;
if (rs === "disabled") { if (rs === "disabled") {