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": {
"load": "16",
"edit": "17",
"parse": "18"
"action": "18"
}
};
export const SyncActionPaths = {
@ -50,5 +50,5 @@ export const SyncActionPaths = {
"15": "client.info",
"16": "code.load",
"17": "code.edit",
"18": "code.parse"
"18": "code.action"
};

View File

@ -120,7 +120,10 @@ export const SyncActions = {
value: Uint8Array;
}
) => ({}) as boolean | ParsedScope | string,
parse: async (code: string | Record<string, string>) =>
({}) as Record<string, ReturnType<typeof parseJs>>,
action: async (arg: { type: "startup-check"; site_id: string }) =>
({}) 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 "./code_load";
export * from "./code_edit";
export * from "./code_parse";
export * from "./code_action";

View File

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

View File

@ -51,7 +51,7 @@ export const assignMitem = (arg: {
}
} else {
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;
}
});

View File

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

View File

@ -12,7 +12,7 @@ import {
iconNewTab,
iconScrollOff,
iconScrollOn,
iconUpload
iconUpload,
} from "./icons";
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 (
<Modal
fade={false}
@ -75,6 +84,9 @@ export const EdPopCode = () => {
)
) {
code.mode = "new";
db.code.create({
data: { id_site: p.site.id, name: "site" },
});
p.ui.popup.code.open = false;
p.render();
}
@ -95,7 +107,10 @@ export const EdPopCode = () => {
const CodeBody = () => {
const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal({ namePicker: false, codeAssign: false });
const local = useLocal({
namePicker: false,
codeAssign: false,
});
const vscode_url = isLocalhost()
? "http://localhost:3000?"
@ -171,31 +186,54 @@ const CodeBody = () => {
></div>
</Tooltip> */}
<Tooltip
content={`Startup Script: ${
!p.ui.popup.code.startup_running ? "OFF" : "Running"
}`}
content={`Startup Script: ${p.ui.popup.code.startup_status}`}
className={cx("flex items-stretch relative border-l")}
delay={0}
placement="bottom"
>
<div
className={cx(
"border-r flex text-center items-center hover:bg-blue-50 cursor-pointer px-2 transition-all",
p.ui.popup.code.startup_running
? "border-b-2 border-b-green-700 bg-green-50"
: "border-b-2 border-b-transparent"
)}
dangerouslySetInnerHTML={{
__html: p.ui.popup.code.startup_running
? iconScrollOn
: iconScrollOff,
}}
onClick={() => {
p.ui.popup.code.startup_running =
!p.ui.popup.code.startup_running;
p.render();
}}
></div>
{["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
className={cx(
"border-r flex text-center items-center hover:bg-blue-50 cursor-pointer px-2 transition-all",
p.ui.popup.code.startup_status
? "border-b-2 border-b-green-700 bg-green-50"
: "border-b-2 border-b-transparent"
)}
dangerouslySetInnerHTML={{
__html: p.ui.popup.code.startup_status
? iconScrollOn
: iconScrollOff,
}}
onClick={() => {
p.ui.popup.code.startup_status = "loading";
p.render();
}}
></div>
)}
</Tooltip>
<Tooltip

View File

@ -13,10 +13,10 @@ import { getActiveMeta } from "../../../logic/active/get-meta";
import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
import { edMonacoDefaultVal } from "./default-val";
import { declareScope } from "./scope/scope";
// @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 { addScope } from "./scope/add-scope";
const scriptEdit = {
timeout: null as any,

View File

@ -38,24 +38,28 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
if (item.childs) {
for (const [_, v] of Object.entries(item.childs)) {
const carg: GenMetaArg = {
item: v,
is_root: false,
root: arg.root || arg.item,
parent: {
item: meta.item,
instance_id: arg.parent?.instance_id,
comp: arg.parent?.comp,
root_instances: arg.parent?.root_instances,
},
};
if (arg.jsx_prop) {
carg.jsx_prop = {
...arg.jsx_prop,
if (v.id) {
const carg: GenMetaArg = {
item: v,
is_root: false,
root: arg.root || arg.item,
parent: {
item: meta.item,
instance_id: arg.parent?.instance_id,
comp: arg.parent?.comp,
root_instances: arg.parent?.root_instances,
},
};
if (arg.jsx_prop) {
carg.jsx_prop = {
...arg.jsx_prop,
is_root: false,
};
}
genMeta(p, carg);
} else {
console.warn("invalid item", v);
}
genMeta(p, carg);
}
}
};