fix prettier
This commit is contained in:
parent
a295b2ead8
commit
5f1855780b
|
|
@ -3,7 +3,7 @@ import { page } from "web-utils";
|
|||
import { Loading } from "../../utils/ui/loading";
|
||||
|
||||
export default page({
|
||||
url: "*",
|
||||
url: "**",
|
||||
component: ({}) => {
|
||||
useEffect(() => {
|
||||
if (localStorage.getItem("prasi-session")) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,131 @@
|
|||
import { page } from "web-utils";
|
||||
import { FC, useEffect } from "react";
|
||||
import { page, useGlobal, useLocal } from "web-utils";
|
||||
import { EditorGlobal } from "../../render/editor/logic/global";
|
||||
import { Loading } from "../../utils/ui/loading";
|
||||
|
||||
export default page({
|
||||
url: "/ed/:site_id/:page_id",
|
||||
url: "/editor/**",
|
||||
component: ({}) => {
|
||||
location.href = `/editor/${params.site_id}/${params.page_id}`;
|
||||
return <Loading />;
|
||||
const p = useGlobal(EditorGlobal, "EDITOR");
|
||||
|
||||
const local = useLocal({
|
||||
loading: true,
|
||||
session: null as any,
|
||||
notfound: false,
|
||||
init: false,
|
||||
});
|
||||
const site_id = params.site_id === "_" ? "" : params.site_id;
|
||||
const page_id = params.page_id === "_" ? "" : params.page_id;
|
||||
|
||||
useEffect(() => {
|
||||
if (!local.init) {
|
||||
(async () => {
|
||||
let ses: any = null;
|
||||
try {
|
||||
ses = JSON.parse(localStorage.getItem("prasi-session") || "");
|
||||
} catch (e) {}
|
||||
|
||||
await new Promise<void>(async (done) => {
|
||||
try {
|
||||
if (!!ses) {
|
||||
done();
|
||||
}
|
||||
let e = await api.session();
|
||||
if (!e) {
|
||||
(window as any).redirectTo = location.pathname;
|
||||
console.log("session not found");
|
||||
// navigate("/login");
|
||||
localStorage.removeItem("prasi-session");
|
||||
} else {
|
||||
localStorage.setItem("prasi-session", JSON.stringify(e));
|
||||
}
|
||||
if (!ses) {
|
||||
ses = e;
|
||||
done();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
if (ses) {
|
||||
local.session = ses;
|
||||
|
||||
if (!site_id) {
|
||||
const res = await db.site.findFirst({
|
||||
where: {
|
||||
is_deleted: false,
|
||||
org: {
|
||||
org_user: {
|
||||
some: { id_user: ses.data.user.id },
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
if (res) {
|
||||
const page = await db.page.findFirst({
|
||||
where: {
|
||||
id_site: res.id,
|
||||
is_deleted: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
if (page) {
|
||||
local.loading = false;
|
||||
local.render();
|
||||
navigate(`/editor/${res.id}/${page.id}`);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
local.loading = false;
|
||||
local.render();
|
||||
return;
|
||||
}
|
||||
} else if (!page_id) {
|
||||
let res = await db.page.findFirst({
|
||||
where: {
|
||||
id_site: site_id,
|
||||
is_deleted: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) {
|
||||
res = await db.page.create({
|
||||
data: {
|
||||
content_tree: {
|
||||
childs: [],
|
||||
id: "root",
|
||||
type: "root",
|
||||
},
|
||||
name: "home",
|
||||
url: "/",
|
||||
id_site: site_id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (res) {
|
||||
local.loading = false;
|
||||
local.render();
|
||||
navigate(`/editor/${site_id}/${res.id}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
navigate(`/editor/${site_id}/${page_id}`);
|
||||
})();
|
||||
}
|
||||
}, [local.init]);
|
||||
|
||||
return <Loading note="base-page" />;
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ export const auth_register = {
|
|||
page: () => import("./page/auth/register"),
|
||||
};
|
||||
export const all = {
|
||||
url: "*",
|
||||
url: "**",
|
||||
page: () => import("./page/all"),
|
||||
};
|
||||
export const ed = {
|
||||
url: "/ed/:site_id/:page_id",
|
||||
url: "/editor/**",
|
||||
page: () => import("./page/ed"),
|
||||
};
|
||||
export const editor = {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export const Root: FC<{}> = ({}) => {
|
|||
const local = useLocal(
|
||||
{
|
||||
router: createRouter<{ url: string; Page: FC<any> }>({
|
||||
strictTrailingSlash: false,
|
||||
strictTrailingSlash: true,
|
||||
}),
|
||||
Page: null as any,
|
||||
},
|
||||
|
|
@ -31,7 +31,6 @@ export const Root: FC<{}> = ({}) => {
|
|||
const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>;
|
||||
|
||||
const found = local.router.lookup(location.pathname);
|
||||
console.log(found)
|
||||
|
||||
if (found) {
|
||||
w.params = found.params;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ export const w = window as unknown as {
|
|||
};
|
||||
|
||||
export const initEditor = async (p: PG, site_id: string) => {
|
||||
|
||||
w.isEditor = true;
|
||||
if (typeof w.isLayout === "undefined") {
|
||||
w.isLayout = false;
|
||||
|
|
@ -77,6 +76,7 @@ export const initEditor = async (p: PG, site_id: string) => {
|
|||
return site;
|
||||
};
|
||||
const processSite = async (site: LSite) => {
|
||||
if (!site || (site && !site.id)) return;
|
||||
if (!w.exports) {
|
||||
w.exports = {};
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ export const initEditor = async (p: PG, site_id: string) => {
|
|||
};
|
||||
|
||||
export const execSiteJS = (p: PG) => {
|
||||
if (p) {
|
||||
if (p && p.site.api_url) {
|
||||
p.script.siteTypes = {};
|
||||
const scope: any = {
|
||||
types: p.script.siteTypes,
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ const w = window as unknown as {
|
|||
importCache: {
|
||||
prettier: any;
|
||||
prettier_parser: any;
|
||||
prettier_estree: any;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -87,18 +88,28 @@ export const ScriptMonacoElement: FC<{
|
|||
const doEdit = async (newval: string, all?: boolean) => {
|
||||
if (local.editor) {
|
||||
if (!w.importCache) {
|
||||
w.importCache = { prettier_parser: "", prettier: "" };
|
||||
w.importCache = {
|
||||
prettier_parser: "",
|
||||
prettier: "",
|
||||
prettier_estree: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (!w.importCache.prettier)
|
||||
w.importCache.prettier = (await import("prettier/standalone")).default;
|
||||
|
||||
if (!w.importCache.prettier_parser)
|
||||
w.importCache.prettier_parser = await import(
|
||||
"prettier/plugins/typescript"
|
||||
);
|
||||
|
||||
if (!w.importCache.prettier)
|
||||
w.importCache.prettier = await import("prettier/standalone");
|
||||
if (!w.importCache.prettier_estree)
|
||||
w.importCache.prettier_estree = await import("prettier/plugins/estree");
|
||||
|
||||
const prettier = w.importCache.prettier;
|
||||
const prettier_parser = w.importCache.prettier_parser;
|
||||
const prettier_estree = w.importCache.prettier_estree;
|
||||
|
||||
const text = trim(
|
||||
prettier.format(
|
||||
all
|
||||
|
|
@ -106,7 +117,7 @@ export const ScriptMonacoElement: FC<{
|
|||
: local.editor?.getValue().replace(/\{\s*children\s*\}/gi, newval),
|
||||
{
|
||||
parser: "typescript",
|
||||
plugins: [prettier_parser],
|
||||
plugins: [prettier_parser, prettier_estree],
|
||||
}
|
||||
),
|
||||
"; \n"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ const w = window as unknown as {
|
|||
importCache: {
|
||||
prettier: any;
|
||||
prettier_parser: any;
|
||||
prettier_estree: any;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -52,22 +53,34 @@ export const jsMount = async (p: PG, editor: MonacoEditor, monaco: Monaco) => {
|
|||
monaco.languages.registerDocumentFormattingEditProvider("typescript", {
|
||||
async provideDocumentFormattingEdits(model, options, token) {
|
||||
if (!w.importCache) {
|
||||
w.importCache = { prettier_parser: "", prettier: "" };
|
||||
w.importCache = {
|
||||
prettier_parser: "",
|
||||
prettier: "",
|
||||
prettier_estree: "",
|
||||
};
|
||||
}
|
||||
if (!w.importCache.prettier_parser)
|
||||
w.importCache.prettier_parser = await import(
|
||||
"prettier/plugins/typescript"
|
||||
);
|
||||
|
||||
if (!w.importCache.prettier)
|
||||
w.importCache.prettier = await import("prettier/standalone");
|
||||
w.importCache.prettier = (await import("prettier/standalone")).default;
|
||||
|
||||
if (!w.importCache.prettier_parser)
|
||||
(w.importCache.prettier_parser = await import(
|
||||
"prettier/plugins/typescript"
|
||||
)).default;
|
||||
|
||||
if (!w.importCache.prettier_estree)
|
||||
w.importCache.prettier_estree = (
|
||||
await import("prettier/plugins/estree")
|
||||
).default;
|
||||
|
||||
const prettier = w.importCache.prettier;
|
||||
const prettier_parser = w.importCache.prettier_parser;
|
||||
const prettier_estree = w.importCache.prettier_estree;
|
||||
|
||||
const text = trim(
|
||||
prettier.format(model.getValue(), {
|
||||
await prettier.format(model.getValue(), {
|
||||
parser: "typescript",
|
||||
plugins: [prettier_parser],
|
||||
plugins: [prettier_parser, prettier_estree],
|
||||
}),
|
||||
"; \n"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ export const createAPI = (url: string) => {
|
|||
if (!w.prasiApi) {
|
||||
w.prasiApi = {};
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
throw new Error("s")
|
||||
}
|
||||
return w.apiClient(w.prasiApi[url]?.apiEntry, url);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -30,17 +30,7 @@ export const _ = {
|
|||
await genPages();
|
||||
watch(pagedir, async (event, filename) => {
|
||||
const s = file(dir.path(`${pagedir}/${filename}`));
|
||||
if (s.size > 0) {
|
||||
// await Bun.write(
|
||||
// `app/srv/api/${filename}`,
|
||||
// `\
|
||||
// export const all = {
|
||||
// url: "*",
|
||||
// page: () => import("./page/all"),
|
||||
// };
|
||||
// `
|
||||
// );
|
||||
}
|
||||
genPages();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -190,10 +190,14 @@ export const fetchSendApi = async (
|
|||
|
||||
if (!frm) {
|
||||
await waitUntil(() => {
|
||||
frm = win.frmapi[w.serverurl];
|
||||
frm = win.frmapi[base];
|
||||
return frm;
|
||||
});
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith("//")) {
|
||||
url.pathname = url.pathname.substring(1);
|
||||
}
|
||||
|
||||
return await frm.send(url.pathname, params, win.apiHeaders);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue