wip fix load
This commit is contained in:
parent
3dbdcb676d
commit
9ebb28884a
|
|
@ -153,6 +153,7 @@ export const updateComponentMeta = async (
|
||||||
{
|
{
|
||||||
comps: p.comp.loaded,
|
comps: p.comp.loaded,
|
||||||
meta,
|
meta,
|
||||||
|
smeta,
|
||||||
on: {
|
on: {
|
||||||
visit(m) {
|
visit(m) {
|
||||||
pushTreeNode(p, m, meta, tree);
|
pushTreeNode(p, m, meta, tree);
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,6 @@ export const EdScriptMonaco: FC<{}> = () => {
|
||||||
...arg,
|
...arg,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(scope);
|
|
||||||
|
|
||||||
if (typeof scope === "object") {
|
if (typeof scope === "object") {
|
||||||
if (active.comp_id) {
|
if (active.comp_id) {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export const addScope = (
|
||||||
);
|
);
|
||||||
model.onDidChangeContent((e) => {
|
model.onDidChangeContent((e) => {
|
||||||
const text = model.getValue();
|
const text = model.getValue();
|
||||||
|
console.log(filename, text);
|
||||||
// const models = monaco.editor.getModels().filter((e) => {
|
// const models = monaco.editor.getModels().filter((e) => {
|
||||||
// return e.uri.toString().startsWith("ts:scope~");
|
// return e.uri.toString().startsWith("ts:scope~");
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,17 @@ export const scopeMapExportImport = (p: PG, meta: IMeta, parents: IMeta[]) => {
|
||||||
let next_parent = parents[i + 1];
|
let next_parent = parents[i + 1];
|
||||||
const imports = {} as Record<string, string>;
|
const imports = {} as Record<string, string>;
|
||||||
const exports = {} as Record<string, Record<string, string>>;
|
const exports = {} as Record<string, Record<string, string>>;
|
||||||
|
|
||||||
for (const m of parents) {
|
for (const m of parents) {
|
||||||
next_parent = parents[i + 1];
|
next_parent = parents[i + 1];
|
||||||
|
|
||||||
if (active.comp_id && m.parent?.id === "root" && active.instance) {
|
// if (active.comp_id && m.parent?.id === "root" && active.instance) {
|
||||||
const meta = p.page.meta[active.instance.item_id];
|
// const meta = p.page.meta[active.instance.item_id];
|
||||||
if (meta) {
|
// if (meta) {
|
||||||
if (!m.scope.def) m.scope.def = {};
|
// if (!m.scope.def) m.scope.def = {};
|
||||||
m.scope.def.props = meta.scope?.def?.props;
|
// m.scope.def.props = { ...m.scope.def.props, ...meta.scope?.def?.props };
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const def = m.scope.def;
|
const def = m.scope.def;
|
||||||
if (def) {
|
if (def) {
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ export const declareScope = async (
|
||||||
for (const [filename, src] of Object.entries(v)) {
|
for (const [filename, src] of Object.entries(v)) {
|
||||||
if (!added.has(filename)) {
|
if (!added.has(filename)) {
|
||||||
added.add(filename);
|
added.add(filename);
|
||||||
|
|
||||||
addScope(p, monaco, filename, src);
|
addScope(p, monaco, filename, src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,6 +65,14 @@ const map_childs = (
|
||||||
for (const m of childs) {
|
for (const m of childs) {
|
||||||
const meta = metas[m.id];
|
const meta = metas[m.id];
|
||||||
if (meta) {
|
if (meta) {
|
||||||
|
if (
|
||||||
|
meta.item.type === "item" &&
|
||||||
|
meta.item.component?.id &&
|
||||||
|
meta.item.component?.id !== active.comp_id
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let cur: null | IMeta[] = null;
|
let cur: null | IMeta[] = null;
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
if (path[path.length - 1] === parent) {
|
if (path[path.length - 1] === parent) {
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,7 @@ export const updatePropScope = (meta: IMeta, scope: any) => {
|
||||||
if (meta.scope.def?.props) {
|
if (meta.scope.def?.props) {
|
||||||
for (const [name, prop] of Object.entries(meta.scope.def.props)) {
|
for (const [name, prop] of Object.entries(meta.scope.def.props)) {
|
||||||
if (prop.fn) {
|
if (prop.fn) {
|
||||||
const all_scope = {
|
const all_scope = scope;
|
||||||
...scope,
|
|
||||||
};
|
|
||||||
const fn = new Function(
|
const fn = new Function(
|
||||||
...Object.keys(all_scope),
|
...Object.keys(all_scope),
|
||||||
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { ReactNode, useEffect, useRef } from "react";
|
import { ReactNode, useEffect, useRef } from "react";
|
||||||
import { IMeta } from "../../../ed/logic/ed-global";
|
import { IMeta } from "../../../ed/logic/ed-global";
|
||||||
import { updatePropScope } from "./eval-prop";
|
import { updatePropScope } from "./eval-prop";
|
||||||
|
import { modifyChild } from "./passprop";
|
||||||
|
|
||||||
export const createViLocal = (
|
export const createViLocal = (
|
||||||
metas: Record<string, IMeta>,
|
metas: Record<string, IMeta>,
|
||||||
meta: IMeta,
|
meta: IMeta,
|
||||||
scope: any,
|
passprop: any,
|
||||||
init_local_effect: any
|
init_local_effect: any
|
||||||
) => {
|
) => {
|
||||||
return <T extends Record<string, any>>(arg: {
|
return <T extends Record<string, any>>(arg: {
|
||||||
|
|
@ -20,7 +21,7 @@ export const createViLocal = (
|
||||||
const local = ref.current;
|
const local = ref.current;
|
||||||
local.render = meta.render;
|
local.render = meta.render;
|
||||||
|
|
||||||
updatePropScope(meta, scope);
|
updatePropScope(meta, passprop);
|
||||||
|
|
||||||
if (arg.hook) {
|
if (arg.hook) {
|
||||||
arg.hook(local);
|
arg.hook(local);
|
||||||
|
|
@ -58,6 +59,6 @@ export const createViLocal = (
|
||||||
return () => {};
|
return () => {};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return children;
|
return modifyChild(children, { ...passprop, [arg.name]: local });
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@ import { VG } from "../global";
|
||||||
export const createViPassProp = (
|
export const createViPassProp = (
|
||||||
vi: { meta: VG["meta"] },
|
vi: { meta: VG["meta"] },
|
||||||
meta: IMeta,
|
meta: IMeta,
|
||||||
scope: any
|
passprop?: any
|
||||||
) => {
|
) => {
|
||||||
return (arg: Record<string, any> & { children: ReactNode }) => {
|
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)) {
|
for (const [k, v] of Object.entries(arg)) {
|
||||||
if (k === "key" || k === "idx" || k === "continue") continue;
|
if (k === "key" || k === "idx" || k === "continue") continue;
|
||||||
}
|
}
|
||||||
|
|
@ -20,19 +20,22 @@ export const modifyChild = (arg: any) => {
|
||||||
const childs = [];
|
const childs = [];
|
||||||
if (Array.isArray(arg.children)) {
|
if (Array.isArray(arg.children)) {
|
||||||
for (const child of arg.children) {
|
for (const child of arg.children) {
|
||||||
childs.push(modify(child, arg));
|
childs.push(modify(child, arg, passprop));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
childs.push(modify(arg.children, arg));
|
childs.push(modify(arg.children, arg, passprop));
|
||||||
}
|
}
|
||||||
return childs;
|
return childs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const modify = (el: ReactNode, arg: any) => {
|
const modify = (el: ReactNode, arg: any, passprop?: any) => {
|
||||||
if (isValidElement(el)) {
|
if (isValidElement(el)) {
|
||||||
const passprop = { ...arg };
|
const passarg = { ...arg };
|
||||||
delete passprop.children;
|
delete passarg.children;
|
||||||
return { ...el, props: { ...el.props, passprop } };
|
return {
|
||||||
|
...el,
|
||||||
|
props: { ...el.props, passprop: { ...passprop, ...passarg } },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue