This commit is contained in:
Rizky 2023-11-27 09:21:49 +07:00
parent c47ac70064
commit e18db3795a
5 changed files with 35 additions and 16 deletions

View File

@ -226,7 +226,7 @@ export const EDGlobal = {
},
page: {
open: null as null | ((page_id: string) => void),
form: null as null | PageItem,
form: null as null | Partial<page>,
},
script: {
open: false,

View File

@ -11,13 +11,13 @@ export const EdMain = () => {
return (
<div
className={cx(
"flex flex-1 relative",
"flex flex-1 relative overflow-auto ",
css`
contain: content;
`
)}
>
<div className="absolute overflow-auto inset-0 flex">
<div className="absolute inset-0 flex flex-col">
{!!p.page.building && <Loading backdrop={false} />}
{!p.page.building && code.mode !== "" && (
<View

View File

@ -34,10 +34,14 @@ export const EdPagePop = () => {
cur = pagePicker.tree.find((e) => e.id === parent_id);
}
}
local.tree.open(parents);
if (parents.length === 0) {
local.tree.open("page-root");
} else {
local.tree.open(parents);
}
}
});
}, [p.ui.popup.page.open]);
}, [p.ui.popup.page.open, p.page.cur.id, pagePicker.site_id]);
if (!p.ui.popup.page.open) return null;
@ -106,22 +110,28 @@ export const EdPagePop = () => {
p.ui.popup.page.form = null;
p.render();
}}
onSave={async (page) => {
onSave={async (page, isNew) => {
p.ui.popup.page.form = null;
const found = pagePicker.tree.find(
(e) => e.id === page.id && e.data?.type === "page"
);
if (found) {
for (const [k, v] of Object.entries(found.data || {})) {
if (page[k]) {
(found.data as any)[k] = page[k];
if (isNew) {
p.render();
await reloadPagePicker(p);
navigate(`/ed/${p.site.id}/${page.id}`);
} else {
const found = pagePicker.tree.find(
(e) => e.id === page.id && e.data?.type === "page"
);
if (found) {
for (const [k, v] of Object.entries(found.data || {})) {
if (page[k]) {
(found.data as any)[k] = page[k];
}
}
found.text = page.name;
}
found.text = page.name;
}
p.render();
p.render();
}
}}
/>
)}

View File

@ -128,6 +128,12 @@ export const edPageTreeRender: NodeRender<PageItem> = (
className="btn transition-all bg-white flex items-center border px-1 hover:border-blue-300 hover:bg-blue-100"
onClick={(e) => {
e.stopPropagation();
p.ui.popup.page.form = {
id_site: p.site.id,
id_folder: item.id === "root" ? null : item.id,
};
p.render();
}}
>
+ Page

View File

@ -142,6 +142,9 @@ export const ScriptMonaco = () => {
tabSize: 2,
useTabStops: true,
}}
language={
{ css: "scss", js: "typescript", html: "html" }[p.ui.popup.script.mode]
}
onMount={async (editor, monaco) => {
local.editor = editor;
editor.focus();