wip fix passprop
This commit is contained in:
parent
79f29978ea
commit
e474131a87
|
|
@ -6,7 +6,7 @@ export const extractExportImport = (
|
|||
m: IMeta,
|
||||
imports: Record<string, string>
|
||||
) => {
|
||||
const def = m.scope.def;
|
||||
const def = m.item.script;
|
||||
let result: {
|
||||
local?: ReturnType<typeof extractLocal>;
|
||||
passprop?: ReturnType<typeof extractPassProp>;
|
||||
|
|
@ -87,7 +87,7 @@ ${commentize("value", null, m.item.adv?.js)}
|
|||
const extractLocal = (
|
||||
p: PG,
|
||||
m: IMeta,
|
||||
def: IMeta["scope"]["def"],
|
||||
def: IMeta["item"]["script"],
|
||||
imports: Record<string, string>
|
||||
) => {
|
||||
if (def?.local) {
|
||||
|
|
@ -123,7 +123,7 @@ declare global {
|
|||
const extractPassProp = (
|
||||
p: PG,
|
||||
m: IMeta,
|
||||
def: IMeta["scope"]["def"],
|
||||
def: IMeta["item"]["script"],
|
||||
imports: Record<string, string>
|
||||
) => {
|
||||
if (def?.passprop) {
|
||||
|
|
@ -165,7 +165,7 @@ declare global {
|
|||
const extractProps = (
|
||||
p: PG,
|
||||
m: IMeta,
|
||||
def: IMeta["scope"]["def"],
|
||||
def: IMeta["item"]["script"],
|
||||
imports: Record<string, string>
|
||||
) => {
|
||||
if (def?.props) {
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ export const scopeMapExportImport = (p: PG, meta: IMeta, parents: IMeta[]) => {
|
|||
for (const m of parents) {
|
||||
next_parent = parents[i + 1];
|
||||
|
||||
let def = m.scope.def;
|
||||
let def = m.item.script;
|
||||
|
||||
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 = {};
|
||||
def = m.scope.def;
|
||||
def.props = { ...m.scope.def.props, ...meta.scope?.def?.props };
|
||||
if (!m.item.script) m.item.script = {};
|
||||
def = m.item.script;
|
||||
def.props = { ...m.item.script.props, ...meta.item.script?.props };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
|||
const comp = p.comp.loaded[node.data.jsx_prop.comp_id];
|
||||
if (comp) {
|
||||
const prop_name = node.data?.jsx_prop?.name;
|
||||
const cprop = comp.comp.component?.props[prop_name];
|
||||
const cprop = comp.component?.props[prop_name];
|
||||
if (cprop && node.data.parent?.instance_id) {
|
||||
const meta = getMetaById(p, node.data.parent.instance_id);
|
||||
if (meta && prop_name) {
|
||||
const props = meta.scope.def?.props;
|
||||
const props = meta.item.script?.props;
|
||||
if (props) {
|
||||
const prop = props[prop_name];
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ export const viEvalProps = (
|
|||
passprop: any
|
||||
) => {
|
||||
if (meta.item.component?.id) {
|
||||
if (!meta.scope.def) {
|
||||
meta.scope.def = {};
|
||||
if (!meta.item.script) {
|
||||
meta.item.script = {};
|
||||
}
|
||||
|
||||
const exports = (window as any).exports;
|
||||
|
|
@ -19,7 +19,7 @@ export const viEvalProps = (
|
|||
...passprop,
|
||||
};
|
||||
|
||||
meta.scope.def.props = {};
|
||||
meta.item.script.props = {};
|
||||
let fails = new Set<string>();
|
||||
if (!!meta.item.component.props) {
|
||||
for (const [name, prop] of Object.entries(meta.item.component.props)) {
|
||||
|
|
@ -31,13 +31,13 @@ export const viEvalProps = (
|
|||
`
|
||||
);
|
||||
|
||||
meta.scope.def.props[name] = { value: prop.valueBuilt };
|
||||
meta.item.script.props[name] = { value: prop.valueBuilt };
|
||||
let val = fn(...Object.values(arg));
|
||||
|
||||
if (typeof val === "function") {
|
||||
meta.scope.def.props[name].fn = val;
|
||||
meta.item.script.props[name].fn = val;
|
||||
val = (...args: any[]) => {
|
||||
return meta.scope.def?.props?.[name].fn(...args);
|
||||
return meta.item.script?.props?.[name].fn(...args);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +55,8 @@ export const viEvalProps = (
|
|||
};
|
||||
|
||||
export const updatePropScope = (meta: IMeta, scope: any) => {
|
||||
if (meta.scope.def?.props) {
|
||||
for (const [name, prop] of Object.entries(meta.scope.def.props)) {
|
||||
if (meta.item.script?.props) {
|
||||
for (const [name, prop] of Object.entries(meta.item.script.props)) {
|
||||
if (prop.fn) {
|
||||
const all_scope = scope;
|
||||
const fn = new Function(
|
||||
|
|
|
|||
|
|
@ -17,13 +17,20 @@ export const modifyChild = (arg: any, passprop?: any) => {
|
|||
if (k === "key" || k === "idx" || k === "continue") continue;
|
||||
}
|
||||
|
||||
let prop: any = {};
|
||||
if (Array.isArray(arg)) {
|
||||
prop.children = arg;
|
||||
} else {
|
||||
prop = arg;
|
||||
}
|
||||
|
||||
const childs = [];
|
||||
if (Array.isArray(arg.children)) {
|
||||
for (const child of arg.children) {
|
||||
childs.push(modify(child, arg, passprop));
|
||||
if (Array.isArray(prop.children)) {
|
||||
for (const child of prop.children) {
|
||||
childs.push(modify(child, prop, passprop));
|
||||
}
|
||||
} else {
|
||||
childs.push(modify(arg.children, arg, passprop));
|
||||
childs.push(modify(prop.children, prop, passprop));
|
||||
}
|
||||
return childs;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export const getScopeMeta = (
|
|||
}
|
||||
|
||||
for (const m of scopes_meta) {
|
||||
const def = m.scope.def;
|
||||
const def = m.item.script;
|
||||
if (def) {
|
||||
if (def.passprop) {
|
||||
for (const p of Object.keys(def.passprop)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue