diff --git a/app/web/src/nova/ed/panel/side/prop-instance/prop-option.tsx b/app/web/src/nova/ed/panel/side/prop-instance/prop-option.tsx index a5f78a9c..cefaad1e 100644 --- a/app/web/src/nova/ed/panel/side/prop-instance/prop-option.tsx +++ b/app/web/src/nova/ed/panel/side/prop-instance/prop-option.tsx @@ -32,8 +32,7 @@ export const EdPropInstanceOptions: FC<{ const prop = mprop.toJSON() as FNCompDef; const local = useLocal({ codeEditing: false, - loading: false, - loaded: false as any, + loading: true, isOpen: false, val: "", metaFn: null as null | (() => Promise), @@ -47,13 +46,12 @@ export const EdPropInstanceOptions: FC<{ config.opt[name] = () => { local.metaFn = null; - local.loaded = null; local.loading = false; local.render(); }; if (cprop.meta?.options || cprop.meta?.optionsBuilt) { - if (!local.loaded || !local.metaFn) { + if (!local.metaFn || local.optDeps.length > 0) { let fn = "" as any; let arg = {}; try { @@ -132,8 +130,6 @@ export const EdPropInstanceOptions: FC<{ console.error(e); console.warn(fn.toString(), arg); } - } else { - local.options = local.loaded; } } @@ -144,7 +140,7 @@ export const EdPropInstanceOptions: FC<{ const res = local.metaFn(); const callback = (e: any) => { local.loading = false; - local.loaded = e; + local.options = e; local.render(); }; if (res instanceof Promise) { @@ -155,6 +151,9 @@ export const EdPropInstanceOptions: FC<{ } catch (e) { console.error(e); } + } else { + local.loading = false; + local.render(); } }, local.optDeps); @@ -205,175 +204,195 @@ export const EdPropInstanceOptions: FC<{
- {mode === "dropdown" && ( - - )} - - {mode === "button" && ( -
- {Array.isArray(local.options) && - local.options.map((item, idx) => { - return ( -
{ - onChange(`"${item.value}"`, item); - }} - > - {item.label} -
- ); - })} + {local.loading ? ( +
+ Loading...
- )} - - {mode === "checkbox" && ( - + {mode === "dropdown" && ( + + )} + + {mode === "button" && ( +
+ {Array.isArray(local.options) && + local.options.map((item, idx) => { + return ( +
{ + onChange(`"${item.value}"`, item); + }} + > + {item.label} +
+ ); + })}
- } - asChild - > -
{}} - ref={(el) => { - if (!local.checkbox.width && el) { - const bound = el.getBoundingClientRect(); - local.checkbox.width = bound.width; - setTimeout(local.render, 500); + )} + + {mode === "checkbox" && ( + +
+ {Array.isArray(local.options) && + local.options.map((item, idx) => { + const val: any[] = Array.isArray(evalue) + ? evalue + : []; + const found = val.find((e) => { + if (!item.options) { + return e === item.value; + } else { + if ( + typeof e === "object" && + e.value === item.value + ) { + return true; + } + return false; + } + }); + return ( + + { + onChange(JSON.stringify(val), item); + local.render(); + }} + /> + {item.options && + found && + item.options.map((child, idx) => { + const sub_found = found.checked.find( + (e: any) => { + if (!item.options) { + return e === child.value; + } else { + if ( + typeof e === "object" && + e.value === child.value + ) { + return true; + } + return false; + } + } + ); + return ( + + { + onChange(JSON.stringify(val), child); + local.render(); + }} + /> + {child.options && + sub_found && + child.options.map((item, sidx) => { + return ( + { + onChange( + JSON.stringify(val), + item + ); + local.render(); + }} + /> + ); + })} + + ); + })} + + ); + })} +
+
} - }} - > -
-
- {Array.isArray(evalue) - ? evalue.length === 0 - ? "Select Item" - : `${evalue.length} selected` - : `Select Item`} + asChild + > +
{}} + ref={(el) => { + if (!local.checkbox.width && el) { + const bound = el.getBoundingClientRect(); + local.checkbox.width = bound.width; + setTimeout(local.render, 500); + } + }} + > +
+
+ {Array.isArray(evalue) + ? evalue.length === 0 + ? "Select Item" + : `${evalue.length} selected` + : `Select Item`} +
+
+
+ +
-
-
- -
-
-
+ + )} + )}