wip fix render
This commit is contained in:
parent
135e7f03df
commit
7283a2b3a1
|
|
@ -45,8 +45,6 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
||||||
jsx: "transform",
|
jsx: "transform",
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
loader: "tsx",
|
loader: "tsx",
|
||||||
minify: true,
|
|
||||||
sourcemap: "inline",
|
|
||||||
});
|
});
|
||||||
doc?.transact(() => {
|
doc?.transact(() => {
|
||||||
const mode = arg.mode;
|
const mode = arg.mode;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export const EmptySite = {
|
||||||
layout: {
|
layout: {
|
||||||
id: "--",
|
id: "--",
|
||||||
snapshot: null as null | Uint8Array,
|
snapshot: null as null | Uint8Array,
|
||||||
|
meta: undefined as void | Record<string, IMeta>,
|
||||||
},
|
},
|
||||||
code: {
|
code: {
|
||||||
snapshot: null as null | Uint8Array,
|
snapshot: null as null | Uint8Array,
|
||||||
|
|
@ -66,7 +67,8 @@ const target = {
|
||||||
instance_item_id: false as any,
|
instance_item_id: false as any,
|
||||||
};
|
};
|
||||||
export const active = {
|
export const active = {
|
||||||
hover: { id: "", renderTree: () => {}, renderMain: () => {} },
|
should_render_main: true,
|
||||||
|
hover: { id: "" },
|
||||||
text: { id: "", content: "", timeout: null as any, el: null as any },
|
text: { id: "", content: "", timeout: null as any, el: null as any },
|
||||||
get item_id() {
|
get item_id() {
|
||||||
if (target.active_id === false) {
|
if (target.active_id === false) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
active.should_render_main = true;
|
||||||
const is_layout =
|
const is_layout =
|
||||||
p.site.layout &&
|
p.site.layout &&
|
||||||
p.site.layout.id === p.page.cur.id &&
|
p.site.layout.id === p.page.cur.id &&
|
||||||
|
|
|
||||||
|
|
@ -134,14 +134,12 @@ export const mainPerItemVisit = (
|
||||||
parts.props.onPointerEnter = (e) => {
|
parts.props.onPointerEnter = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
active.hover.id = meta.item.id;
|
active.hover.id = meta.item.id;
|
||||||
active.hover.renderMain();
|
p.render();
|
||||||
active.hover.renderTree();
|
|
||||||
};
|
};
|
||||||
parts.props.onPointerLeave = (e) => {
|
parts.props.onPointerLeave = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
active.hover.id = "";
|
active.hover.id = "";
|
||||||
active.hover.renderMain();
|
p.render();
|
||||||
active.hover.renderTree();
|
|
||||||
};
|
};
|
||||||
parts.props.onPointerDown = (e) => {
|
parts.props.onPointerDown = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,17 @@ import { mainPerItemVisit } from "./main-per-item";
|
||||||
|
|
||||||
export const EdMain = () => {
|
export const EdMain = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
const local = useLocal({});
|
const local = useLocal({
|
||||||
active.hover.renderMain = local.render;
|
cache: null as any,
|
||||||
|
first_load: false,
|
||||||
|
});
|
||||||
|
|
||||||
const meta = active.comp_id
|
const meta = active.comp_id
|
||||||
? p.comp.list[active.comp_id].meta[active.item_id]
|
? p.comp.list[active.comp_id].meta[active.item_id]
|
||||||
: p.page.meta[active.item_id];
|
: p.page.meta[active.item_id];
|
||||||
|
|
||||||
return (
|
if (active.should_render_main) {
|
||||||
<div
|
local.cache = (
|
||||||
className={cx(
|
|
||||||
"flex flex-1 relative overflow-auto",
|
|
||||||
css`
|
|
||||||
contain: content;
|
|
||||||
`
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className={mainStyle(p, meta)}>
|
|
||||||
<Vi
|
<Vi
|
||||||
meta={p.page.meta}
|
meta={p.page.meta}
|
||||||
api_url={p.site.config.api_url}
|
api_url={p.site.config.api_url}
|
||||||
|
|
@ -35,8 +29,33 @@ export const EdMain = () => {
|
||||||
visit={(meta, parts) => {
|
visit={(meta, parts) => {
|
||||||
return mainPerItemVisit(p, meta, parts);
|
return mainPerItemVisit(p, meta, parts);
|
||||||
}}
|
}}
|
||||||
|
onStatusChanged={(status) => {
|
||||||
|
if (status !== "ready") {
|
||||||
|
active.should_render_main = true;
|
||||||
|
local.render();
|
||||||
|
} else {
|
||||||
|
if (!local.first_load) {
|
||||||
|
local.first_load = true;
|
||||||
|
active.should_render_main = true;
|
||||||
|
local.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
);
|
||||||
|
active.should_render_main = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cx(
|
||||||
|
"flex flex-1 relative overflow-auto",
|
||||||
|
css`
|
||||||
|
contain: content;
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className={mainStyle(p, meta)}>{local.cache}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ const map_childs = (
|
||||||
prop.content &&
|
prop.content &&
|
||||||
prop.jsxCalledBy
|
prop.jsxCalledBy
|
||||||
) {
|
) {
|
||||||
const mjsx = p.comp.list[comp_id].meta[prop.jsxCalledBy];
|
const mjsx = p.comp.list[comp_id].meta[prop.jsxCalledBy[0]];
|
||||||
const { import_map, parent_id } = extract_import_map(
|
const { import_map, parent_id } = extract_import_map(
|
||||||
meta.item.component.id,
|
meta.item.component.id,
|
||||||
jprop.paths,
|
jprop.paths,
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,7 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
}}
|
}}
|
||||||
onMouseEnter={() => {
|
onMouseEnter={() => {
|
||||||
active.hover.id = item.id;
|
active.hover.id = item.id;
|
||||||
active.hover.renderMain();
|
p.render();
|
||||||
active.hover.renderTree();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{active.hover.id === item.id && (
|
{active.hover.id === item.id && (
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ import { viLoadLegacy } from "./load-legacy";
|
||||||
|
|
||||||
export const viLoad = (vi: VG, arg: { site_id: string; api_url: string }) => {
|
export const viLoad = (vi: VG, arg: { site_id: string; api_url: string }) => {
|
||||||
vi.status = "loading";
|
vi.status = "loading";
|
||||||
|
if (vi.on_status_changes) {
|
||||||
|
vi.on_status_changes(vi.status);
|
||||||
|
}
|
||||||
vi.site.id = arg.site_id;
|
vi.site.id = arg.site_id;
|
||||||
vi.site.api_url = arg.api_url;
|
vi.site.api_url = arg.api_url;
|
||||||
|
|
||||||
|
|
@ -31,9 +34,15 @@ export const viLoad = (vi: VG, arg: { site_id: string; api_url: string }) => {
|
||||||
render: vi.render,
|
render: vi.render,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
vi.status = "ready";
|
vi.status = "ready";
|
||||||
|
if (vi.on_status_changes) {
|
||||||
|
vi.on_status_changes(vi.status);
|
||||||
|
}
|
||||||
vi.render();
|
vi.render();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
vi.status = "ready";
|
vi.status = "ready";
|
||||||
|
if (vi.on_status_changes) {
|
||||||
|
vi.on_status_changes(vi.status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ import { IItem } from "../../../utils/types/item";
|
||||||
import { IMeta } from "../../ed/logic/ed-global";
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
import { viParts } from "./parts";
|
import { viParts } from "./parts";
|
||||||
|
|
||||||
|
type ViStatus = "init" | "loading" | "ready";
|
||||||
export const ViGlobal = {
|
export const ViGlobal = {
|
||||||
ts: 0,
|
ts: 0,
|
||||||
status: "init" as "init" | "loading" | "ready",
|
status: "init" as ViStatus,
|
||||||
meta: {} as Record<string, IMeta>,
|
meta: {} as Record<string, IMeta>,
|
||||||
tick: 0,
|
tick: 0,
|
||||||
site: {
|
site: {
|
||||||
|
|
@ -19,6 +20,7 @@ export const ViGlobal = {
|
||||||
visit: undefined as
|
visit: undefined as
|
||||||
| undefined
|
| undefined
|
||||||
| ((meta: IMeta, parts: ReturnType<typeof viParts>) => void),
|
| ((meta: IMeta, parts: ReturnType<typeof viParts>) => void),
|
||||||
|
on_status_changes: undefined as void | ((status: ViStatus) => void),
|
||||||
};
|
};
|
||||||
|
|
||||||
export type VG = typeof ViGlobal & { render: () => void };
|
export type VG = typeof ViGlobal & { render: () => void };
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { IMeta } from "../../../ed/logic/ed-global";
|
||||||
import { VG } from "../global";
|
import { VG } from "../global";
|
||||||
import { ViRender } from "../render";
|
import { ViRender } from "../render";
|
||||||
import { viScriptArg } from "./arg";
|
import { viScriptArg } from "./arg";
|
||||||
|
import { replaceWithObject, replacement } from "./eval-script";
|
||||||
|
|
||||||
export const viEvalProps = (
|
export const viEvalProps = (
|
||||||
vi: { meta: VG["meta"] },
|
vi: { meta: VG["meta"] },
|
||||||
|
|
@ -34,18 +35,32 @@ export const viEvalProps = (
|
||||||
const m = vi.meta[id];
|
const m = vi.meta[id];
|
||||||
if (
|
if (
|
||||||
m.mitem &&
|
m.mitem &&
|
||||||
prop.jsxCalledBy !==
|
prop.jsxCalledBy?.includes(
|
||||||
(arg.meta.item.originalId || arg.meta.item.id)
|
arg.meta.item.originalId || arg.meta.item.id
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
const mprop = meta.mitem
|
const mprop = meta.mitem
|
||||||
?.get("component")
|
?.get("component")
|
||||||
?.get("props")
|
?.get("props")
|
||||||
?.get(name);
|
?.get(name);
|
||||||
if (mprop) {
|
if (mprop) {
|
||||||
mprop.set(
|
let mjby = mprop.get("jsxCalledBy");
|
||||||
"jsxCalledBy",
|
if (!mjby || typeof mjby !== "object") {
|
||||||
|
mprop.set("jsxCalledBy", [
|
||||||
|
arg.meta.item.originalId || arg.meta.item.id,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
!mjby.includes(
|
||||||
|
arg.meta.item.originalId || arg.meta.item.id
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
mjby.push(
|
||||||
arg.meta.item.originalId || arg.meta.item.id
|
arg.meta.item.originalId || arg.meta.item.id
|
||||||
);
|
);
|
||||||
|
mprop.set("jsxCalledBy", mjby);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return <ViRender meta={m} passprop={arg.passprop} />;
|
return <ViRender meta={m} passprop={arg.passprop} />;
|
||||||
|
|
@ -62,14 +77,16 @@ export const viEvalProps = (
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const js = prop.valueBuilt || "";
|
||||||
|
const src = replaceWithObject(js, replacement) || "";
|
||||||
const fn = new Function(
|
const fn = new Function(
|
||||||
...Object.keys(arg),
|
...Object.keys(arg),
|
||||||
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
||||||
return ${prop.valueBuilt || ""}
|
return ${src}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
meta.item.script.props[name] = { value: prop.valueBuilt };
|
meta.item.script.props[name] = { value: src };
|
||||||
let val = fn(...Object.values(arg));
|
let val = fn(...Object.values(arg));
|
||||||
|
|
||||||
if (typeof val === "function") {
|
if (typeof val === "function") {
|
||||||
|
|
@ -96,14 +113,13 @@ export const updatePropScope = (meta: IMeta, scope: any) => {
|
||||||
if (meta.item.script?.props) {
|
if (meta.item.script?.props) {
|
||||||
for (const [name, prop] of Object.entries(meta.item.script.props)) {
|
for (const [name, prop] of Object.entries(meta.item.script.props)) {
|
||||||
if (prop.fn) {
|
if (prop.fn) {
|
||||||
const all_scope = scope;
|
|
||||||
const fn = new Function(
|
const fn = new Function(
|
||||||
...Object.keys(all_scope),
|
...Object.keys(scope),
|
||||||
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
`// [${meta.item.name}] ${name}: ${meta.item.id}
|
||||||
return ${prop.value || ""}
|
return ${prop.value || ""}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
prop.fn = fn(...Object.values(all_scope));
|
prop.fn = fn(...Object.values(scope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,10 +64,13 @@ export const viEvalScript = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const js = meta.item.adv?.jsBuilt || "";
|
||||||
|
const src = replaceWithObject(js, replacement) || "";
|
||||||
|
|
||||||
const fn = new Function(
|
const fn = new Function(
|
||||||
...Object.keys(arg),
|
...Object.keys(arg),
|
||||||
`// ${meta.item.name}: ${meta.item.id}
|
`// ${meta.item.name}: ${meta.item.id}
|
||||||
${replaceWithObject(meta.item.adv?.jsBuilt || "", replacement) || ""}
|
${src}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
fn(...Object.values(arg));
|
fn(...Object.values(arg));
|
||||||
|
|
@ -89,12 +92,16 @@ const JsxProp: FC<{
|
||||||
return local.result;
|
return local.result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const replacement = {
|
export const replacement = {
|
||||||
"stroke-width": "strokeWidth",
|
"stroke-width": "strokeWidth",
|
||||||
|
"fill-rule": "fillRule",
|
||||||
|
"clip-rule": "clipRule",
|
||||||
};
|
};
|
||||||
|
|
||||||
const replaceWithObject = (tpl: string, data: any) => {
|
export const replaceWithObject = (tpl: string, data: any) => {
|
||||||
return tpl.replace(/\$\(([^\)]+)?\)/g, function ($1, $2) {
|
let res = tpl;
|
||||||
return data[$2];
|
for (const [k, v] of Object.entries(data)) {
|
||||||
});
|
res = res.replaceAll(k, v as string);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ export const Vi: FC<{
|
||||||
script?: { init_local_effect: Record<string, boolean> };
|
script?: { init_local_effect: Record<string, boolean> };
|
||||||
visit?: VG["visit"];
|
visit?: VG["visit"];
|
||||||
render_stat?: "enabled" | "disabled";
|
render_stat?: "enabled" | "disabled";
|
||||||
|
onStatusChanged?: (status: VG["status"]) => void;
|
||||||
}> = ({
|
}> = ({
|
||||||
meta,
|
meta,
|
||||||
entry,
|
entry,
|
||||||
|
|
@ -29,8 +30,10 @@ export const Vi: FC<{
|
||||||
visit,
|
visit,
|
||||||
script,
|
script,
|
||||||
render_stat: rs,
|
render_stat: rs,
|
||||||
|
onStatusChanged,
|
||||||
}) => {
|
}) => {
|
||||||
const vi = useGlobal(ViGlobal, "VI");
|
const vi = useGlobal(ViGlobal, "VI");
|
||||||
|
vi.on_status_changes = onStatusChanged;
|
||||||
|
|
||||||
if (rs === "disabled") {
|
if (rs === "disabled") {
|
||||||
render_stat.enabled = false;
|
render_stat.enabled = false;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export type FNCompDef = {
|
||||||
valueBuilt: any;
|
valueBuilt: any;
|
||||||
gen?: string;
|
gen?: string;
|
||||||
genBuilt?: string;
|
genBuilt?: string;
|
||||||
jsxCalledBy?: string;
|
jsxCalledBy?: string[];
|
||||||
content?: IItem;
|
content?: IItem;
|
||||||
visible?: string;
|
visible?: string;
|
||||||
meta?: FNCompMeta;
|
meta?: FNCompMeta;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue