fix prop options

This commit is contained in:
Rizky 2024-06-05 08:11:16 +07:00
parent 60facdb7ac
commit ff1f2e2062
2 changed files with 16 additions and 10 deletions

View File

@ -13,7 +13,7 @@ export const parseJs = (code?: string, show_error?: boolean) => {
const result = {} as { const result = {} as {
local?: typeof local | undefined; local?: typeof local | undefined;
passprop?: typeof passprop | undefined; passprop?: typeof passprop | undefined;
props?: Record<string, { value: string; fn?: any; visible?: boolean }>; props?: Record<string, { value: string; valueBuilt: string; fn?: any; visible?: boolean }>;
}; };
try { try {

View File

@ -111,6 +111,7 @@ export const EdPropInstanceOptions: FC<{
cprop.meta.options || cprop.meta.options ||
"" ""
).trim(); ).trim();
const final = ` const final = `
try { try {
const resOpt = ${src.endsWith(";") ? src : `${src};`} const resOpt = ${src.endsWith(";") ? src : `${src};`}
@ -145,13 +146,18 @@ export const EdPropInstanceOptions: FC<{
local.options = e; local.options = e;
if (local.resetOnDeps) { if (local.resetOnDeps) {
mprop.doc?.transact(() => { const val = meta.item.component?.props?.[name]?.value;
mprop.set("value", "null"); const valBuilt = meta.item.component?.props?.[name]?.valueBuilt;
mprop.set("valueBuilt", "null"); if (val && valBuilt) {
}); mprop.doc?.transact(() => {
mprop.set("value", val);
mprop.set("valueBuilt", valBuilt);
});
treeRebuild(p);
p.render();
}
treeRebuild(p);
p.render();
} }
local.render(); local.render();
}; };
@ -172,7 +178,7 @@ export const EdPropInstanceOptions: FC<{
let evalue: any = null; let evalue: any = null;
try { try {
eval(`evalue = ${prop.value}`); eval(`evalue = ${prop.value}`);
} catch (e) {} } catch (e) { }
useEffect(() => { useEffect(() => {
if (Array.isArray(local.options) && !Array.isArray(evalue)) { if (Array.isArray(local.options) && !Array.isArray(evalue)) {
@ -380,7 +386,7 @@ export const EdPropInstanceOptions: FC<{
> >
<div <div
className="flex flex-1 items-stretch bg-white border hover:border-blue-500 hover:bg-blue-50 rounded-sm select-none cursor-pointer m-[3px]" className="flex flex-1 items-stretch bg-white border hover:border-blue-500 hover:bg-blue-50 rounded-sm select-none cursor-pointer m-[3px]"
onClick={() => {}} onClick={() => { }}
ref={(el) => { ref={(el) => {
if (!local.checkbox.width && el) { if (!local.checkbox.width && el) {
const bound = el.getBoundingClientRect(); const bound = el.getBoundingClientRect();
@ -474,7 +480,7 @@ const SingleCheckbox = ({
idx === 0 && !depth ? "" : "border-t", idx === 0 && !depth ? "" : "border-t",
item.checked && "opacity-50", item.checked && "opacity-50",
depth && depth &&
css` css`
padding-left: ${depth * 20}px; padding-left: ${depth * 20}px;
`, `,
is_check is_check