This commit is contained in:
Rizky 2024-01-30 14:36:07 +07:00
parent 164bcbf821
commit c38f2a1da5
11 changed files with 115 additions and 66 deletions

View File

@ -28,7 +28,7 @@ export const SyncActionDefinition = {
"code": { "code": {
"load": "16", "load": "16",
"edit": "17", "edit": "17",
"parse": "18" "action": "18"
} }
}; };
export const SyncActionPaths = { export const SyncActionPaths = {
@ -50,5 +50,5 @@ export const SyncActionPaths = {
"15": "client.info", "15": "client.info",
"16": "code.load", "16": "code.load",
"17": "code.edit", "17": "code.edit",
"18": "code.parse" "18": "code.action"
}; };

View File

@ -120,7 +120,10 @@ export const SyncActions = {
value: Uint8Array; value: Uint8Array;
} }
) => ({}) as boolean | ParsedScope | string, ) => ({}) as boolean | ParsedScope | string,
parse: async (code: string | Record<string, string>) => action: async (arg: { type: "startup-check"; site_id: string }) =>
({}) as Record<string, ReturnType<typeof parseJs>>, ({}) as {
type: "startup-check";
status: "disabled" | "running" | "stopped";
},
}, },
}; };

View File

@ -0,0 +1,12 @@
import { SAction } from "../actions";
import { SyncConnection } from "../type";
export const code_action: SAction["code"]["action"] = async function (
this: SyncConnection,
) {
let result = null as unknown as Awaited<
ReturnType<SAction["code"]["action"]>
>;
return result;
}

View File

@ -1,18 +0,0 @@
import { SAction } from "../actions";
import { parseJs } from "../editor/parser/parse-js";
import { SyncConnection } from "../type";
export const code_parse: SAction["code"]["parse"] = async function (
this: SyncConnection,
code
) {
if (typeof code === "object") {
const result: Record<string, ReturnType<typeof parseJs>> = {};
for (const [k, v] of Object.entries(code)) {
result[k] = parseJs(v);
}
return result;
}
return { _: parseJs(code) };
};

View File

@ -16,4 +16,4 @@ export * from "./yjs_sv_remote";
export * from "./client_info"; export * from "./client_info";
export * from "./code_load"; export * from "./code_load";
export * from "./code_edit"; export * from "./code_edit";
export * from "./code_parse"; export * from "./code_action";

View File

@ -233,7 +233,12 @@ export const EDGlobal = {
name: "site", name: "site",
log: "", log: "",
loading: false, loading: false,
startup_running: false, startup_status: "init" as
| "init"
| "loading"
| "disabled"
| "stopped"
| "running",
error: false, error: false,
show_log: false, show_log: false,
list: {} as Record<string, string>, list: {} as Record<string, string>,

View File

@ -51,7 +51,7 @@ export const assignMitem = (arg: {
} }
} else { } else {
parent.mitem.get("childs")?.forEach((child) => { parent.mitem.get("childs")?.forEach((child) => {
if (child.get("id") === m.item.id) { if (child && child.get && child.get("id") === m.item.id) {
m.mitem = child; m.mitem = child;
} }
}); });

View File

@ -22,13 +22,18 @@ export const pushTreeNode = (
if (parent && parent.mitem) { if (parent && parent.mitem) {
parent.mitem.get("childs")?.forEach((mitem) => { parent.mitem.get("childs")?.forEach((mitem) => {
if (mitem.get("id") === meta.item.id) { if (mitem && mitem.get && mitem.get("id") === meta.item.id) {
meta.mitem = mitem; meta.mitem = mitem;
} }
}); });
} }
} }
if (!meta.item || !meta.item.id) {
console.warn("Emptry Tree Item ", meta);
return null;
}
if (tree.find((t) => t.id === meta.item.id)) { if (tree.find((t) => t.id === meta.item.id)) {
console.warn("Double Tree Item: ", meta.item.id, meta.item.name); console.warn("Double Tree Item: ", meta.item.id, meta.item.name);
} else { } else {

View File

@ -12,7 +12,7 @@ import {
iconNewTab, iconNewTab,
iconScrollOff, iconScrollOff,
iconScrollOn, iconScrollOn,
iconUpload iconUpload,
} from "./icons"; } from "./icons";
import { CodeNameItem, CodeNameList } from "./name-list"; import { CodeNameItem, CodeNameList } from "./name-list";
@ -46,6 +46,15 @@ export const EdPopCode = () => {
} }
}, []); }, []);
if (p.ui.popup.code.startup_status === "init" && p.sync.code.action) {
p.ui.popup.code.startup_status = "loading";
p.sync.code
.action({ type: "startup-check", site_id: p.site.id })
.then((res) => {
console.log(res);
});
}
return ( return (
<Modal <Modal
fade={false} fade={false}
@ -75,6 +84,9 @@ export const EdPopCode = () => {
) )
) { ) {
code.mode = "new"; code.mode = "new";
db.code.create({
data: { id_site: p.site.id, name: "site" },
});
p.ui.popup.code.open = false; p.ui.popup.code.open = false;
p.render(); p.render();
} }
@ -95,7 +107,10 @@ export const EdPopCode = () => {
const CodeBody = () => { const CodeBody = () => {
const p = useGlobal(EDGlobal, "EDITOR"); const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal({ namePicker: false, codeAssign: false }); const local = useLocal({
namePicker: false,
codeAssign: false,
});
const vscode_url = isLocalhost() const vscode_url = isLocalhost()
? "http://localhost:3000?" ? "http://localhost:3000?"
@ -171,31 +186,54 @@ const CodeBody = () => {
></div> ></div>
</Tooltip> */} </Tooltip> */}
<Tooltip <Tooltip
content={`Startup Script: ${ content={`Startup Script: ${p.ui.popup.code.startup_status}`}
!p.ui.popup.code.startup_running ? "OFF" : "Running"
}`}
className={cx("flex items-stretch relative border-l")} className={cx("flex items-stretch relative border-l")}
delay={0} delay={0}
placement="bottom" placement="bottom"
> >
{["loading", "init"].includes(p.ui.popup.code.startup_status) ? (
<div
className={cx(
"border-r flex text-center items-center hover:bg-blue-50 cursor-pointer px-2 transition-all"
)}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
className="lucide lucide-hourglass"
>
<path d="M5 22h14" />
<path d="M5 2h14" />
<path d="M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22" />
<path d="M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2" />
</svg>
</div>
) : (
<div <div
className={cx( className={cx(
"border-r flex text-center items-center hover:bg-blue-50 cursor-pointer px-2 transition-all", "border-r flex text-center items-center hover:bg-blue-50 cursor-pointer px-2 transition-all",
p.ui.popup.code.startup_running p.ui.popup.code.startup_status
? "border-b-2 border-b-green-700 bg-green-50" ? "border-b-2 border-b-green-700 bg-green-50"
: "border-b-2 border-b-transparent" : "border-b-2 border-b-transparent"
)} )}
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: p.ui.popup.code.startup_running __html: p.ui.popup.code.startup_status
? iconScrollOn ? iconScrollOn
: iconScrollOff, : iconScrollOff,
}} }}
onClick={() => { onClick={() => {
p.ui.popup.code.startup_running = p.ui.popup.code.startup_status = "loading";
!p.ui.popup.code.startup_running;
p.render(); p.render();
}} }}
></div> ></div>
)}
</Tooltip> </Tooltip>
<Tooltip <Tooltip

View File

@ -13,10 +13,10 @@ import { getActiveMeta } from "../../../logic/active/get-meta";
import { EDGlobal, IMeta, active } from "../../../logic/ed-global"; import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
import { edMonacoDefaultVal } from "./default-val"; import { edMonacoDefaultVal } from "./default-val";
import { declareScope } from "./scope/scope"; import { declareScope } from "./scope/scope";
// @ts-ignore // @ts-ignore
import { constrainedEditor } from "constrained-editor-plugin/dist/esm/constrainedEditor";
import { addScope } from "./scope/add-scope";
import { FNCompDef } from "../../../../../utils/types/meta-fn"; import { FNCompDef } from "../../../../../utils/types/meta-fn";
import { addScope } from "./scope/add-scope";
const scriptEdit = { const scriptEdit = {
timeout: null as any, timeout: null as any,

View File

@ -38,6 +38,7 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
if (item.childs) { if (item.childs) {
for (const [_, v] of Object.entries(item.childs)) { for (const [_, v] of Object.entries(item.childs)) {
if (v.id) {
const carg: GenMetaArg = { const carg: GenMetaArg = {
item: v, item: v,
is_root: false, is_root: false,
@ -56,6 +57,9 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
}; };
} }
genMeta(p, carg); genMeta(p, carg);
} else {
console.warn("invalid item", v);
}
} }
} }
}; };