fix options jsx

This commit is contained in:
Rizky 2024-03-29 15:35:39 +07:00
parent ddad7fcbec
commit 7582371142
6 changed files with 52 additions and 79 deletions

File diff suppressed because one or more lines are too long

View File

@ -70,6 +70,7 @@ const target = {
export const active = {
should_render_main: true,
hover: { id: "" },
scope: {} as any,
script_nav: {
list: [] as {
item_id: string;

View File

@ -1,4 +1,4 @@
import { FC, MouseEvent } from "react";
import { FC, MouseEvent, useEffect } from "react";
import { useGlobal, useLocal } from "web-utils";
import { IItem } from "../../../../utils/types/item";
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
@ -13,6 +13,8 @@ import { EdPropInstanceText } from "./prop-instance/prop-text";
import { EdStyleAll } from "./style/side-all";
import { EdPropInstanceButton } from "./prop-instance/prop-button";
const w = window as any;
export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal(
@ -71,7 +73,7 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
if (visible && visible !== "true") {
try {
const arg: any = {};
const arg: any = { ...active.scope };
if (meta.item.script?.props) {
for (const [k, v] of Object.entries(meta.item.script?.props)) {
eval(`arg.${k} = ${v.value}`);
@ -93,6 +95,7 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
return;
}
} catch (e) {
console.log(e);
return;
}
}

View File

@ -17,7 +17,6 @@ export const EdPropInstanceButton: FC<{
labelClick?: React.MouseEventHandler<HTMLDivElement> | undefined;
}> = ({ label, name, cprop, mprop, meta }) => {
const p = useGlobal(EDGlobal, "EDITOR");
const val = cprop?.valueBuilt;
const local = useLocal({
value: [] as {
@ -28,16 +27,6 @@ export const EdPropInstanceButton: FC<{
timeout: null as any,
});
if (!w.prop_buttons) {
w.prop_buttons = {};
}
if (!w.prop_buttons[name]) {
w.prop_buttons[name] = {
meta: meta,
local: local,
src: val,
};
}
useEffect(() => {
return () => {

View File

@ -3,7 +3,7 @@ import { useGlobal, useLocal } from "web-utils";
import { apiProxy } from "../../../../../base/load/api/api-proxy";
import { dbProxy } from "../../../../../base/load/db/db-proxy";
import { FMCompDef, FNCompDef } from "../../../../../utils/types/meta-fn";
import { EDGlobal, IMeta } from "../../../logic/ed-global";
import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
import { treeRebuild } from "../../../logic/tree/build";
import { EdPropLabel } from "./prop-label";
import { ChevronDown } from "../../tree/node/item/indent";
@ -62,6 +62,7 @@ export const EdPropInstanceOptions: FC<{
...window.exports,
db: p.script.db,
api: p.script.api,
...active.scope,
};
if (meta.item.script?.props) {
@ -78,7 +79,7 @@ ${Object.entries(arg)
.map((e) => `const ${e[0]} = arg["${e[0]}"]`)
.join(";\n")}
const resOpt = ${cprop.meta.optionsBuilt || cprop.meta.options};
if (typeof resOpt === 'function') local.metaFn = resOpt;
if (typeof resOpt === 'function') local.metaFn = resOpt;
else metaOptions = resOpt;
`);
} catch (e) {
@ -90,11 +91,14 @@ else metaOptions = resOpt;
if (local.metaFn && !local.loaded && !local.loading) {
local.loading = true;
local.metaFn().then((e) => {
const res = local.metaFn();
const callback = (e: any) => {
local.loading = false;
local.loaded = e;
local.render();
});
};
if (res instanceof Promise) res.then(callback);
else callback(res);
}
}

View File

@ -1,6 +1,6 @@
import { createId } from "@paralleldrive/cuid2";
import { FMCompDef } from "../../../../utils/types/meta-fn";
import { IMeta } from "../../../ed/logic/ed-global";
import { IMeta, active } from "../../../ed/logic/ed-global";
import { VG } from "../global";
import { ViRender } from "../render";
import { viScriptArg } from "./arg";
@ -152,38 +152,14 @@ export const viEvalProps = (
}
}
if (w.prop_buttons) {
for (const [k, v] of Object.entries(w.prop_buttons)) {
const btn = v as {
meta: IMeta;
src: string;
local: { value: any; render: () => void };
};
let found = false;
let cur = btn.meta;
while (cur && cur.parent) {
if (
(btn.meta.item.id === cur.item.id,
btn.meta.item.originalId === cur.item.originalId)
) {
found = true;
break;
}
cur = vi.meta[cur.parent.id];
if (location.pathname.startsWith("/ed/") && active.item_id) {
if (meta.item.id === active.item_id) {
active.scope = {};
for (const [k, v] of Object.entries(passprop)) {
active.scope[k] = v;
}
if (found) {
const curprops = { ...passprop, _props };
const fn = new Function(
...Object.keys(curprops),
`return ${btn.src}`
);
btn.local.value = fn(...Object.values(curprops));
setTimeout(btn.local.render, 300);
setTimeout(btn.local.render, 1000);
}
active.scope.self_props = _props;
}
}
}