wip fix
This commit is contained in:
parent
94f44dbeb6
commit
b9911efc0d
File diff suppressed because one or more lines are too long
|
|
@ -76,5 +76,6 @@ export const loadUrls = async (urls: string[]) => {
|
||||||
})
|
})
|
||||||
.filter((e) => e && e.id);
|
.filter((e) => e && e.id);
|
||||||
|
|
||||||
return await loadPages(founds.map((e) => e?.id) as string[]);
|
const result = await loadPages(founds.map((e) => e?.id) as string[]);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import { loadPage, loadUrls } 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 { w } from "./w";
|
import { w } from "./w";
|
||||||
|
import { IRoot } from "../../utils/types/root";
|
||||||
|
import { IContent } from "../../utils/types/general";
|
||||||
|
|
||||||
export const isPreview = () => {
|
export const isPreview = () => {
|
||||||
return (
|
return (
|
||||||
|
|
@ -179,8 +181,8 @@ export const Root = () => {
|
||||||
}
|
}
|
||||||
script={{ init_local_effect: base.init_local_effect }}
|
script={{ init_local_effect: base.init_local_effect }}
|
||||||
on_preload={async ({ urls, opt }) => {
|
on_preload={async ({ urls, opt }) => {
|
||||||
console.log(urls, opt);
|
|
||||||
const load_urls: string[] = [];
|
const load_urls: string[] = [];
|
||||||
|
const loaded = {} as Record<string, any>;
|
||||||
if (base.cache.urls) {
|
if (base.cache.urls) {
|
||||||
for (const url of urls) {
|
for (const url of urls) {
|
||||||
if (!base.cache.urls.has(url)) {
|
if (!base.cache.urls.has(url)) {
|
||||||
|
|
@ -194,7 +196,7 @@ export const Root = () => {
|
||||||
const pages = await loadUrls(load_urls);
|
const pages = await loadUrls(load_urls);
|
||||||
|
|
||||||
if (opt?.on_load) {
|
if (opt?.on_load) {
|
||||||
opt.on_load(pages);
|
opt.on_load(pages, walkRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(pages)) {
|
if (Array.isArray(pages)) {
|
||||||
|
|
@ -218,3 +220,35 @@ export const Root = () => {
|
||||||
</Provider>
|
</Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const walkRoot = (
|
||||||
|
pages: { root: IRoot }[],
|
||||||
|
visit: (item: IContent) => void | Promise<void>
|
||||||
|
) => {
|
||||||
|
for (const page of pages) {
|
||||||
|
for (const child of page.root.childs) {
|
||||||
|
walk(child, visit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const walk = (
|
||||||
|
item: IContent,
|
||||||
|
visit: (item: IContent) => void | Promise<void>
|
||||||
|
) => {
|
||||||
|
visit(item);
|
||||||
|
|
||||||
|
if (item.type !== "text") {
|
||||||
|
if (item.type === "item" && item.component?.props) {
|
||||||
|
for (const prop of Object.values(item.component.props)) {
|
||||||
|
if (prop.content) {
|
||||||
|
walk(prop.content, visit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const child of item.childs) {
|
||||||
|
walk(child, visit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { IContent } from "../../../utils/types/general";
|
||||||
import { IRoot } from "../../../utils/types/root";
|
import { IRoot } from "../../../utils/types/root";
|
||||||
import { IMeta } from "../../ed/logic/ed-global";
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
import { viParts } from "./parts";
|
import { viParts } from "./parts";
|
||||||
|
|
@ -48,7 +49,11 @@ export const ViGlobal = {
|
||||||
id: string;
|
id: string;
|
||||||
url: string;
|
url: string;
|
||||||
root: IRoot;
|
root: IRoot;
|
||||||
}[]
|
}[],
|
||||||
|
walk: (
|
||||||
|
root: { root: IRoot }[],
|
||||||
|
visit: (item: IContent) => void | Promise<void>
|
||||||
|
) => void
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
}) => Promise<void>),
|
}) => Promise<void>),
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,18 @@ export const baseTypings = `
|
||||||
const isMobile: boolean;
|
const isMobile: boolean;
|
||||||
const isDesktop: boolean;
|
const isDesktop: boolean;
|
||||||
const siteurl: (path:string) => string;
|
const siteurl: (path:string) => string;
|
||||||
const preload: (urls: string | string[], opt: {on_load?: boolean}) => ReactNode;
|
const preload: (urls: string | string[], opt: {
|
||||||
|
on_load?: (
|
||||||
|
pages: {
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
root: IRoot;
|
||||||
|
}[],
|
||||||
|
walk: (
|
||||||
|
root: { root: IRoot }[],
|
||||||
|
visit: (item: IContent) => void | Promise<void>
|
||||||
|
) => void
|
||||||
|
) => void;}) => ReactNode;
|
||||||
const apiHeaders: Record<string, any>;
|
const apiHeaders: Record<string, any>;
|
||||||
const navigate: (url: string) => void;
|
const navigate: (url: string) => void;
|
||||||
const params: any;
|
const params: any;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue