wip fix load

This commit is contained in:
Rizky 2023-12-25 22:05:12 +07:00
parent 3dbdcb676d
commit 9ebb28884a
8 changed files with 36 additions and 23 deletions

View File

@ -153,6 +153,7 @@ export const updateComponentMeta = async (
{
comps: p.comp.loaded,
meta,
smeta,
on: {
visit(m) {
pushTreeNode(p, m, meta, tree);

View File

@ -227,7 +227,6 @@ export const EdScriptMonaco: FC<{}> = () => {
...arg,
});
}
console.log(scope);
if (typeof scope === "object") {
if (active.comp_id) {

View File

@ -21,6 +21,7 @@ export const addScope = (
);
model.onDidChangeContent((e) => {
const text = model.getValue();
console.log(filename, text);
// const models = monaco.editor.getModels().filter((e) => {
// return e.uri.toString().startsWith("ts:scope~");
// });

View File

@ -6,16 +6,17 @@ export const scopeMapExportImport = (p: PG, meta: IMeta, parents: IMeta[]) => {
let next_parent = parents[i + 1];
const imports = {} as Record<string, string>;
const exports = {} as Record<string, Record<string, string>>;
for (const m of parents) {
next_parent = parents[i + 1];
if (active.comp_id && m.parent?.id === "root" && active.instance) {
const meta = p.page.meta[active.instance.item_id];
if (meta) {
if (!m.scope.def) m.scope.def = {};
m.scope.def.props = meta.scope?.def?.props;
}
}
// if (active.comp_id && m.parent?.id === "root" && active.instance) {
// const meta = p.page.meta[active.instance.item_id];
// if (meta) {
// if (!m.scope.def) m.scope.def = {};
// m.scope.def.props = { ...m.scope.def.props, ...meta.scope?.def?.props };
// }
// }
const def = m.scope.def;
if (def) {

View File

@ -47,6 +47,7 @@ export const declareScope = async (
for (const [filename, src] of Object.entries(v)) {
if (!added.has(filename)) {
added.add(filename);
addScope(p, monaco, filename, src);
}
}
@ -64,6 +65,14 @@ const map_childs = (
for (const m of childs) {
const meta = metas[m.id];
if (meta) {
if (
meta.item.type === "item" &&
meta.item.component?.id &&
meta.item.component?.id !== active.comp_id
) {
continue;
}
let cur: null | IMeta[] = null;
for (const path of paths) {
if (path[path.length - 1] === parent) {

View File

@ -57,9 +57,7 @@ export const updatePropScope = (meta: IMeta, scope: any) => {
if (meta.scope.def?.props) {
for (const [name, prop] of Object.entries(meta.scope.def.props)) {
if (prop.fn) {
const all_scope = {
...scope,
};
const all_scope = scope;
const fn = new Function(
...Object.keys(all_scope),
`// [${meta.item.name}] ${name}: ${meta.item.id}

View File

@ -1,11 +1,12 @@
import { ReactNode, useEffect, useRef } from "react";
import { IMeta } from "../../../ed/logic/ed-global";
import { updatePropScope } from "./eval-prop";
import { modifyChild } from "./passprop";
export const createViLocal = (
metas: Record<string, IMeta>,
meta: IMeta,
scope: any,
passprop: any,
init_local_effect: any
) => {
return <T extends Record<string, any>>(arg: {
@ -20,7 +21,7 @@ export const createViLocal = (
const local = ref.current;
local.render = meta.render;
updatePropScope(meta, scope);
updatePropScope(meta, passprop);
if (arg.hook) {
arg.hook(local);
@ -58,6 +59,6 @@ export const createViLocal = (
return () => {};
}, []);
return children;
return modifyChild(children, { ...passprop, [arg.name]: local });
};
};

View File

@ -5,14 +5,14 @@ import { VG } from "../global";
export const createViPassProp = (
vi: { meta: VG["meta"] },
meta: IMeta,
scope: any
passprop?: any
) => {
return (arg: Record<string, any> & { children: ReactNode }) => {
return modifyChild(arg);
return modifyChild(arg, passprop);
};
};
export const modifyChild = (arg: any) => {
export const modifyChild = (arg: any, passprop?: any) => {
for (const [k, v] of Object.entries(arg)) {
if (k === "key" || k === "idx" || k === "continue") continue;
}
@ -20,19 +20,22 @@ export const modifyChild = (arg: any) => {
const childs = [];
if (Array.isArray(arg.children)) {
for (const child of arg.children) {
childs.push(modify(child, arg));
childs.push(modify(child, arg, passprop));
}
} else {
childs.push(modify(arg.children, arg));
childs.push(modify(arg.children, arg, passprop));
}
return childs;
};
const modify = (el: ReactNode, arg: any) => {
const modify = (el: ReactNode, arg: any, passprop?: any) => {
if (isValidElement(el)) {
const passprop = { ...arg };
delete passprop.children;
return { ...el, props: { ...el.props, passprop } };
const passarg = { ...arg };
delete passarg.children;
return {
...el,
props: { ...el.props, passprop: { ...passprop, ...passarg } },
};
}
return el;
};