This commit is contained in:
rizrmd 2024-05-19 21:02:52 +07:00
parent fe92fa4ab0
commit e64b589246
15 changed files with 172 additions and 79 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ import { FMCompDef, FNCompDef } from "../../../../../utils/types/meta-fn";
import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
import { treeRebuild } from "../../../logic/tree/build";
import { EdPropLabel } from "./prop-label";
import { devItem } from "../../../../vi/render/script/dev-item";
import { devItem } from "../../../../vi/render/script/item-dev";
export const w = window as any;

View File

@ -16,7 +16,8 @@ import { updatePropScope } from "./eval-prop";
import { extractNavigate } from "./extract-nav";
import { createViLocal } from "./local";
import { createViPassProp } from "./passprop";
import { devItem } from "./dev-item";
import { devItem } from "./item-dev";
import { prodItem } from "./item-prod";
export const viEvalScript = (
vi: {
page: VG["page"];
@ -63,7 +64,7 @@ export const viEvalScript = (
newElement: () => {},
_item: meta.mitem
? devItem(vi.meta, meta.mitem, vi.page.cur.id)
: meta.item,
: prodItem(vi.meta, meta.item, vi.page.cur.id),
_meta: vi.meta,
render: (jsx: ReactNode) => {
let result = jsx;

View File

@ -10,7 +10,7 @@ type SingleChange =
| { type: "set"; name: string; value: any }
| ({ type: "prop"; name: string } & PropVal);
type PropVal =
export type PropVal =
| { mode: "string"; value: string }
| { mode: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
@ -21,7 +21,7 @@ type ParentArg = {
child_idx: number;
};
type PrasiEdit = {
export type PrasiEdit = {
edit: {
setValue: <T extends keyof IItem>(name: T, value: IItem[T]) => void;
setProp: (name: string, value: PropVal | string) => void;

View File

@ -0,0 +1,91 @@
import { IItem } from "../../../../utils/types/item";
import { IMeta } from "../../utils/types";
import { PrasiEdit, PropVal } from "./item-dev";
export const prodItem = (
metas: Record<string, IMeta>,
item: IItem,
page_id: string
) => {
return {
...item,
edit: {
get childs() {
if (item.component?.id) {
const child = item.component?.props.child;
if (child.content) {
return [prodItem(metas, child.content, page_id)];
}
return [];
}
if (item.childs) {
return item.childs
.map((e) => {
if (e) {
const m = metas[e.id];
if (m && m.item) return prodItem(metas, m.item, page_id);
}
})
.filter((e) => e);
}
return [];
},
get props() {
if (item.component?.props) {
const result: Record<string, PropVal> = {};
for (const [k, v] of Object.entries(item.component.props)) {
if (v.content) {
const content = item.component?.props?.[k]?.content;
if (content) {
result[k] = {
mode: "jsx",
value: prodItem(metas, content, page_id),
};
} else {
result[k] = {
mode: "jsx",
value: null as any,
};
}
} else {
let vbuilt =
typeof v.valueBuilt === "string"
? (v.valueBuilt.trim() as string)
: "";
if (vbuilt.endsWith(";\n")) {
vbuilt = vbuilt.substring(0, vbuilt.length - ";\n".length);
}
if (vbuilt && vbuilt === v.value.trim()) {
const fn = new Function(`return ${v.value}`);
result[k] = { mode: "string", value: fn() };
} else {
result[k] = {
mode: "raw",
value: v.value,
valueBuilt: v.valueBuilt,
};
}
}
}
return result;
}
return undefined;
},
async commit() {},
get parent() {
const meta = metas[item.id];
if (meta && meta.parent?.id) {
const parent = metas[meta.parent.id];
return prodItem(metas, parent.item, page_id);
}
return null as any;
},
pending: [],
setProp(name, value) {},
setValue(name, value) {},
} as PrasiEdit["edit"],
};
};