fix
This commit is contained in:
parent
30446a29ce
commit
cb0a9b5360
|
|
@ -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<MetaOption[]>),
|
||||
|
|
@ -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,6 +204,12 @@ export const EdPropInstanceOptions: FC<{
|
|||
<div className="flex items-stretch min-h-[28px]">
|
||||
<EdPropLabel name={label || name} labelClick={labelClick} />
|
||||
<div className="flex flex-1 justify-end items-stretch">
|
||||
{local.loading ? (
|
||||
<div className="flex flex-1 justify-center items-center">
|
||||
Loading...
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{mode === "dropdown" && (
|
||||
<select
|
||||
value={evalue}
|
||||
|
|
@ -212,7 +217,9 @@ export const EdPropInstanceOptions: FC<{
|
|||
onChange={(ev) => {
|
||||
onChange(
|
||||
`"${ev.currentTarget.value}"`,
|
||||
local.options.find((e) => e.value === ev.currentTarget.value)
|
||||
local.options.find(
|
||||
(e) => e.value === ev.currentTarget.value
|
||||
)
|
||||
);
|
||||
}}
|
||||
>
|
||||
|
|
@ -269,12 +276,17 @@ export const EdPropInstanceOptions: FC<{
|
|||
<div className={cx("flex flex-col bg-white")}>
|
||||
{Array.isArray(local.options) &&
|
||||
local.options.map((item, idx) => {
|
||||
const val: any[] = Array.isArray(evalue) ? evalue : [];
|
||||
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) {
|
||||
if (
|
||||
typeof e === "object" &&
|
||||
e.value === item.value
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -295,7 +307,8 @@ export const EdPropInstanceOptions: FC<{
|
|||
{item.options &&
|
||||
found &&
|
||||
item.options.map((child, idx) => {
|
||||
const sub_found = found.checked.find((e: any) => {
|
||||
const sub_found = found.checked.find(
|
||||
(e: any) => {
|
||||
if (!item.options) {
|
||||
return e === child.value;
|
||||
} else {
|
||||
|
|
@ -307,7 +320,8 @@ export const EdPropInstanceOptions: FC<{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
return (
|
||||
<Fragment key={idx}>
|
||||
<SingleCheckbox
|
||||
|
|
@ -332,7 +346,10 @@ export const EdPropInstanceOptions: FC<{
|
|||
depth={2}
|
||||
val={sub_found.checked}
|
||||
onChange={(newval) => {
|
||||
onChange(JSON.stringify(val), item);
|
||||
onChange(
|
||||
JSON.stringify(val),
|
||||
item
|
||||
);
|
||||
local.render();
|
||||
}}
|
||||
/>
|
||||
|
|
@ -375,6 +392,8 @@ export const EdPropInstanceOptions: FC<{
|
|||
</div>
|
||||
</Popover>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue