diff --git a/app/web/src/nova/ed/logic/comp/load.tsx b/app/web/src/nova/ed/logic/comp/load.tsx index 47002541..26107f1b 100644 --- a/app/web/src/nova/ed/logic/comp/load.tsx +++ b/app/web/src/nova/ed/logic/comp/load.tsx @@ -153,6 +153,7 @@ export const updateComponentMeta = async ( { comps: p.comp.loaded, meta, + smeta, on: { visit(m) { pushTreeNode(p, m, meta, tree); diff --git a/app/web/src/nova/ed/panel/popup/script/monaco.tsx b/app/web/src/nova/ed/panel/popup/script/monaco.tsx index 446132af..e0341d0c 100644 --- a/app/web/src/nova/ed/panel/popup/script/monaco.tsx +++ b/app/web/src/nova/ed/panel/popup/script/monaco.tsx @@ -227,7 +227,6 @@ export const EdScriptMonaco: FC<{}> = () => { ...arg, }); } - console.log(scope); if (typeof scope === "object") { if (active.comp_id) { diff --git a/app/web/src/nova/ed/panel/popup/script/scope/add-scope.tsx b/app/web/src/nova/ed/panel/popup/script/scope/add-scope.tsx index 7bca01de..336bfd03 100644 --- a/app/web/src/nova/ed/panel/popup/script/scope/add-scope.tsx +++ b/app/web/src/nova/ed/panel/popup/script/scope/add-scope.tsx @@ -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~"); // }); diff --git a/app/web/src/nova/ed/panel/popup/script/scope/map-exim.tsx b/app/web/src/nova/ed/panel/popup/script/scope/map-exim.tsx index 9b1e849e..7e391411 100644 --- a/app/web/src/nova/ed/panel/popup/script/scope/map-exim.tsx +++ b/app/web/src/nova/ed/panel/popup/script/scope/map-exim.tsx @@ -6,16 +6,17 @@ export const scopeMapExportImport = (p: PG, meta: IMeta, parents: IMeta[]) => { let next_parent = parents[i + 1]; const imports = {} as Record; const exports = {} as Record>; + 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) { diff --git a/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx b/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx index 77ca8a5b..2802fcdb 100644 --- a/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx +++ b/app/web/src/nova/ed/panel/popup/script/scope/scope.tsx @@ -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) { diff --git a/app/web/src/nova/vi/render/script/eval-prop.tsx b/app/web/src/nova/vi/render/script/eval-prop.tsx index 547d9029..0f0aedd9 100644 --- a/app/web/src/nova/vi/render/script/eval-prop.tsx +++ b/app/web/src/nova/vi/render/script/eval-prop.tsx @@ -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} diff --git a/app/web/src/nova/vi/render/script/local.tsx b/app/web/src/nova/vi/render/script/local.tsx index dd27a3e2..56783fbe 100644 --- a/app/web/src/nova/vi/render/script/local.tsx +++ b/app/web/src/nova/vi/render/script/local.tsx @@ -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, meta: IMeta, - scope: any, + passprop: any, init_local_effect: any ) => { return >(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 }); }; }; diff --git a/app/web/src/nova/vi/render/script/passprop.tsx b/app/web/src/nova/vi/render/script/passprop.tsx index 5a30218e..f5e4c619 100644 --- a/app/web/src/nova/vi/render/script/passprop.tsx +++ b/app/web/src/nova/vi/render/script/passprop.tsx @@ -5,14 +5,14 @@ import { VG } from "../global"; export const createViPassProp = ( vi: { meta: VG["meta"] }, meta: IMeta, - scope: any + passprop?: any ) => { return (arg: Record & { 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; };