fix typings

This commit is contained in:
Rizky 2024-04-09 15:27:42 +07:00
parent 6f66f4beed
commit d32fde49a9
1 changed files with 29 additions and 37 deletions

View File

@ -147,7 +147,6 @@ export const EdScriptMonaco: FC<{}> = () => {
case "prop-instance": case "prop-instance":
{ {
types._raw = declareScope(p, meta, monaco); types._raw = declareScope(p, meta, monaco);
const nmodel = monaco.editor.createModel( const nmodel = monaco.editor.createModel(
trim(val), trim(val),
"typescript", "typescript",
@ -158,27 +157,7 @@ export const EdScriptMonaco: FC<{}> = () => {
if (component.id) { if (component.id) {
const prop_name = p.ui.popup.script.prop_name; const prop_name = p.ui.popup.script.prop_name;
const prop = meta.item.component?.props[prop_name]; const prop = meta.item.component?.props[prop_name];
propTypings(prop, types);
if (!!prop && typeof prop.typings === "string") {
const typings_fn = new Function(
"active",
`\
${prop.typings};
return typings;`
);
try {
const typings = typings_fn(active);
if (typeof typings === "object") {
for (const [k, v] of Object.entries(typings)) {
if (typeof v === "string") {
types[k] = v;
}
}
}
} catch (e) {
console.log(typings_fn.toString())
}
}
} }
} }
break; break;
@ -197,21 +176,7 @@ return typings;`
if (component.id && meta.jsx_prop?.name) { if (component.id && meta.jsx_prop?.name) {
const prop_name = meta.jsx_prop.name; const prop_name = meta.jsx_prop.name;
const prop = meta.item.component?.props[prop_name]; const prop = meta.item.component?.props[prop_name];
if (!!prop && typeof prop.typings === "string") { propTypings(prop, types);
const typings_src = prop.typings.substring(
`const typings = `.length
);
const typings_fn = new Function(
"active",
`return ${typings_src}`
);
const typings = typings_fn(active);
for (const [k, v] of Object.entries(typings)) {
if (typeof v === "string") {
types[k] = v;
}
}
}
} }
} }
break; break;
@ -415,3 +380,30 @@ return typings;`
/> />
); );
}; };
const propTypings = (prop: FNCompDef | undefined, types: any) => {
if (!!prop && typeof prop.typings === "string") {
const typings_fn = new Function(
"active",
`\
${prop.typings};
return typings;`
);
try {
const typings = typings_fn(active);
if (typeof typings === "object") {
for (const [k, v] of Object.entries(typings)) {
if (typeof v === "string") {
if (k === "_raw" && types[k]) {
types[k] += "\n" + v;
} else {
types[k] = v;
}
}
}
}
} catch (e) {
console.log(typings_fn.toString());
}
}
};