fix prasi, font swap

This commit is contained in:
Rizky 2023-11-15 21:01:59 +07:00
parent 898685f117
commit 7c2ed2b435
8 changed files with 38 additions and 28 deletions

View File

@ -1,6 +1,6 @@
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=block'); @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap');
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
@ -16,7 +16,6 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
flex: 1; flex: 1;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
overscroll-behavior-y: none; overscroll-behavior-y: none;
} }

View File

@ -238,7 +238,7 @@ export const PanelFont: FC<{
const doc = document; const doc = document;
let weight = `:wght@${[300, 400, 500, 600].join(";")}`; let weight = `:wght@${[300, 400, 500, 600].join(";")}`;
let fontName = item.value.replace(/ /g, "+"); let fontName = item.value.replace(/ /g, "+");
const _href = `https://fonts.googleapis.com/css2?family=${fontName}${weight}&display=block`; const _href = `https://fonts.googleapis.com/css2?family=${fontName}${weight}`;
if (!doc.querySelector(`link[href="${_href}]`)) { if (!doc.querySelector(`link[href="${_href}]`)) {
const link = doc.createElement("link"); const link = doc.createElement("link");
link.type = "text/css"; link.type = "text/css";

View File

@ -99,7 +99,10 @@ const loadNpmPage = async (p: PG, id: string) => {
if (typeof window.exports === "undefined") { if (typeof window.exports === "undefined") {
window.exports = {}; window.exports = {};
} }
await importModule(p.loader.npm(p, "page", id)); const npmurl = p.loader.npm(p, "page", id);
if (npmurl) {
await importModule(npmurl);
}
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -1,7 +1,6 @@
import { produceCSS } from "../../../utils/css/gen"; import { produceCSS } from "../../../utils/css/gen";
import { IContent } from "../../../utils/types/general"; import { IContent } from "../../../utils/types/general";
import { IItem, MItem } from "../../../utils/types/item"; import { IItem } from "../../../utils/types/item";
import { FNCompDef } from "../../../utils/types/meta-fn";
import { instantiateComp, loadComponent } from "./comp"; import { instantiateComp, loadComponent } from "./comp";
import { ItemMeta, LiveGlobal, PG } from "./global"; import { ItemMeta, LiveGlobal, PG } from "./global";

View File

@ -1,43 +1,50 @@
import { w } from "../../utils/script/init-api"; import { w } from "../../utils/script/init-api";
import { Loader } from "../live/logic/global"; import { Loader } from "../live/logic/global";
const base = `/_web/${(window as any).id_site}`; const cache = {
site: null as any,
const cache = { site: null as any, pages: [] as any, api: null }; pages: [] as any,
api: null,
npm_pages: [] as string[],
};
export const mobileLoader: Loader = { export const mobileLoader: Loader = {
async site(p, id) { async site(p, id) {
const res = (await load(`/site?prod=1`)) as { const res = (await load(`/content/site/site.json`)) as any;
site: any; cache.site = res;
pages: any;
api: any;
};
cache.site = res.site;
cache.pages = res.pages;
cache.api = res.api;
w.serverurl = res.site.config.api_url; const pages = (await load(`/content/site/pages.json`)) as any;
w.apiurl = res.site.config.api_url; cache.pages = pages;
const npm_pages = (await load(`/content/site/npm_pages.json`)) as any;
cache.npm_pages = npm_pages;
w.serverurl = res.config.api_url;
w.apiurl = res.config.api_url;
w.prasiApi = { w.prasiApi = {
[res.site.config.api_url]: { apiEntry: res.api }, [res.config.api_url]: { apiEntry: res.api },
}; };
return res.site; return res;
}, },
async comp(p, id) { async comp(p, id) {
const comp = (await load(`/comp/${id}`)) as any; const comp = (await load(`/content/comps/${id}.json`)) as any;
p.comps.all[id] = comp; p.comps.all[id] = comp;
return comp; return comp;
}, },
npm(p, type, id) { npm(p, type, id) {
if (type === "site") return `/_web/${cache.site.id}/npm-site/site.js`; if (type === "site") return `/content/npm/site/index.js`;
return `/_web/${cache.site.id}/npm-page/${id}/page.js`; if (cache.npm_pages.includes(id)) {
return `/content/npm/pages/${id}/index.js`;
}
return "";
}, },
async page(p, id) { async page(p, id) {
const page = cache.pages.find((x: any) => x.id === id); const page = cache.pages.find((x: any) => x.id === id);
if (page && !page.content_tree) { if (page && !page.content_tree) {
const res = (await load(`/page/${id}`)) as any; const res = (await load(`/content/pages/${id}.json`)) as any;
return res; return res;
} }
return null; return null;
@ -48,7 +55,7 @@ export const mobileLoader: Loader = {
}; };
const load = async (url: string) => { const load = async (url: string) => {
const res = await fetch(`${base}${url}`); const res = await fetch(`${w.mobilepath}${url}`);
const text = await res.text(); const text = await res.text();
const json = JSON.parse(text); const json = JSON.parse(text);
return json; return json;

View File

@ -3,6 +3,7 @@ import { createRoot } from "react-dom/client";
import { GlobalContext, defineReact, defineWindow } from "web-utils"; import { GlobalContext, defineReact, defineWindow } from "web-utils";
import { siteLoader } from "./site-loader"; import { siteLoader } from "./site-loader";
import { registerMobile } from "../live/logic/mobile"; import { registerMobile } from "../live/logic/mobile";
import { mobileLoader } from "./mobile-loader";
const w = window as unknown as { const w = window as unknown as {
prasiContext: any; prasiContext: any;
@ -32,7 +33,7 @@ const Root: FC<{ url: URL; Live: any }> = ({ url, Live }) => {
<Live <Live
domain={url.host} domain={url.host}
pathname={location.pathname} pathname={location.pathname}
loader={siteLoader} loader={w.mobilepath ? mobileLoader : siteLoader}
/> />
</Provider> </Provider>
); );

View File

@ -21,7 +21,7 @@ export const cssFont = (
if (glbFont.loadedFonts.indexOf(font.family) < 0) { if (glbFont.loadedFonts.indexOf(font.family) < 0) {
glbFont.loadedFonts.push(font.family); glbFont.loadedFonts.push(font.family);
const doc = document; const doc = document;
const _href = `https://fonts.googleapis.com/css2?family=${fontName}${weight}&display=block`; const _href = `https://fonts.googleapis.com/css2?family=${fontName}${weight}`;
if (!doc.querySelector(`link[href="${_href}]`)) { if (!doc.querySelector(`link[href="${_href}]`)) {
const link = doc.createElement("link"); const link = doc.createElement("link");
link.type = "text/css"; link.type = "text/css";

View File

@ -9,6 +9,7 @@ export const w = window as unknown as {
dbClient: typeof dbClient; dbClient: typeof dbClient;
serverurl: string; serverurl: string;
apiurl: string; apiurl: string;
mobilepath: string;
}; };
export const createAPI = (url: string) => { export const createAPI = (url: string) => {