From 7c2ed2b435c14388b4e5169f5882aa50f9ea3205 Mon Sep 17 00:00:00 2001 From: Rizky Date: Wed, 15 Nov 2023 21:01:59 +0700 Subject: [PATCH] fix prasi, font swap --- app/web/src/index.css | 3 +- .../render/editor/panel/side/panel/font.tsx | 2 +- app/web/src/render/live/logic/route.ts | 5 +- app/web/src/render/live/logic/tree-logic.tsx | 3 +- app/web/src/render/site/mobile-loader.tsx | 47 +++++++++++-------- app/web/src/render/site/site.tsx | 3 +- app/web/src/utils/css/font.ts | 2 +- app/web/src/utils/script/init-api.ts | 1 + 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/app/web/src/index.css b/app/web/src/index.css index ff04d3f0..e6e78fe5 100644 --- a/app/web/src/index.css +++ b/app/web/src/index.css @@ -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=JetBrains+Mono&display=block'); + @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap'); @tailwind base; @tailwind components; @@ -16,7 +16,6 @@ display: flex; flex-direction: column; flex: 1; - -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; } diff --git a/app/web/src/render/editor/panel/side/panel/font.tsx b/app/web/src/render/editor/panel/side/panel/font.tsx index dbe22d7a..b1934a3e 100644 --- a/app/web/src/render/editor/panel/side/panel/font.tsx +++ b/app/web/src/render/editor/panel/side/panel/font.tsx @@ -238,7 +238,7 @@ export const PanelFont: FC<{ const doc = document; let weight = `:wght@${[300, 400, 500, 600].join(";")}`; 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}]`)) { const link = doc.createElement("link"); link.type = "text/css"; diff --git a/app/web/src/render/live/logic/route.ts b/app/web/src/render/live/logic/route.ts index 80f07cf2..a6429449 100644 --- a/app/web/src/render/live/logic/route.ts +++ b/app/web/src/render/live/logic/route.ts @@ -99,7 +99,10 @@ const loadNpmPage = async (p: PG, id: string) => { if (typeof window.exports === "undefined") { 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) { console.error(e); diff --git a/app/web/src/render/live/logic/tree-logic.tsx b/app/web/src/render/live/logic/tree-logic.tsx index c66687b4..5009cd6c 100644 --- a/app/web/src/render/live/logic/tree-logic.tsx +++ b/app/web/src/render/live/logic/tree-logic.tsx @@ -1,7 +1,6 @@ import { produceCSS } from "../../../utils/css/gen"; import { IContent } from "../../../utils/types/general"; -import { IItem, MItem } from "../../../utils/types/item"; -import { FNCompDef } from "../../../utils/types/meta-fn"; +import { IItem } from "../../../utils/types/item"; import { instantiateComp, loadComponent } from "./comp"; import { ItemMeta, LiveGlobal, PG } from "./global"; diff --git a/app/web/src/render/site/mobile-loader.tsx b/app/web/src/render/site/mobile-loader.tsx index 948fbeb9..f593e261 100644 --- a/app/web/src/render/site/mobile-loader.tsx +++ b/app/web/src/render/site/mobile-loader.tsx @@ -1,43 +1,50 @@ import { w } from "../../utils/script/init-api"; import { Loader } from "../live/logic/global"; -const base = `/_web/${(window as any).id_site}`; - -const cache = { site: null as any, pages: [] as any, api: null }; +const cache = { + site: null as any, + pages: [] as any, + api: null, + npm_pages: [] as string[], +}; export const mobileLoader: Loader = { async site(p, id) { - const res = (await load(`/site?prod=1`)) as { - site: any; - pages: any; - api: any; - }; - cache.site = res.site; - cache.pages = res.pages; - cache.api = res.api; + const res = (await load(`/content/site/site.json`)) as any; + cache.site = res; - w.serverurl = res.site.config.api_url; - w.apiurl = res.site.config.api_url; + const pages = (await load(`/content/site/pages.json`)) as any; + 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 = { - [res.site.config.api_url]: { apiEntry: res.api }, + [res.config.api_url]: { apiEntry: res.api }, }; - return res.site; + return res; }, 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; return comp; }, npm(p, type, id) { - if (type === "site") return `/_web/${cache.site.id}/npm-site/site.js`; - return `/_web/${cache.site.id}/npm-page/${id}/page.js`; + if (type === "site") return `/content/npm/site/index.js`; + if (cache.npm_pages.includes(id)) { + return `/content/npm/pages/${id}/index.js`; + } + return ""; }, async page(p, id) { const page = cache.pages.find((x: any) => x.id === id); 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 null; @@ -48,7 +55,7 @@ export const mobileLoader: Loader = { }; const load = async (url: string) => { - const res = await fetch(`${base}${url}`); + const res = await fetch(`${w.mobilepath}${url}`); const text = await res.text(); const json = JSON.parse(text); return json; diff --git a/app/web/src/render/site/site.tsx b/app/web/src/render/site/site.tsx index 818fbc10..6f905cf1 100644 --- a/app/web/src/render/site/site.tsx +++ b/app/web/src/render/site/site.tsx @@ -3,6 +3,7 @@ import { createRoot } from "react-dom/client"; import { GlobalContext, defineReact, defineWindow } from "web-utils"; import { siteLoader } from "./site-loader"; import { registerMobile } from "../live/logic/mobile"; +import { mobileLoader } from "./mobile-loader"; const w = window as unknown as { prasiContext: any; @@ -32,7 +33,7 @@ const Root: FC<{ url: URL; Live: any }> = ({ url, Live }) => { ); diff --git a/app/web/src/utils/css/font.ts b/app/web/src/utils/css/font.ts index 6bbf8e12..686fce85 100644 --- a/app/web/src/utils/css/font.ts +++ b/app/web/src/utils/css/font.ts @@ -21,7 +21,7 @@ export const cssFont = ( if (glbFont.loadedFonts.indexOf(font.family) < 0) { glbFont.loadedFonts.push(font.family); 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}]`)) { const link = doc.createElement("link"); link.type = "text/css"; diff --git a/app/web/src/utils/script/init-api.ts b/app/web/src/utils/script/init-api.ts index ecd871db..6826206d 100644 --- a/app/web/src/utils/script/init-api.ts +++ b/app/web/src/utils/script/init-api.ts @@ -9,6 +9,7 @@ export const w = window as unknown as { dbClient: typeof dbClient; serverurl: string; apiurl: string; + mobilepath: string; }; export const createAPI = (url: string) => {