wip component smeta
This commit is contained in:
parent
4d186c8580
commit
c11f01cdb7
|
|
@ -38,7 +38,11 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
|||
const mitem = findId(root, item_id);
|
||||
|
||||
if (mitem) {
|
||||
const adv = mitem.get("adv");
|
||||
let adv = mitem.get("adv");
|
||||
if (!adv) {
|
||||
mitem.set("adv", new Y.Map() as any);
|
||||
adv = mitem.get("adv");
|
||||
}
|
||||
|
||||
if (adv) {
|
||||
const res = await transform(`render(${src})`, {
|
||||
|
|
@ -48,10 +52,13 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
|||
minify: true,
|
||||
sourcemap: "inline",
|
||||
});
|
||||
|
||||
doc?.transact(() => {
|
||||
adv.set(mode, src);
|
||||
if (mode === "js") {
|
||||
adv.set("jsBuilt", res.code);
|
||||
if (adv) {
|
||||
adv.set(mode, src);
|
||||
if (mode === "js") {
|
||||
adv.set("jsBuilt", res.code);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import { EComp } from "../../../../web/src/nova/ed/logic/ed-global";
|
||||
import { genMeta } from "../../../../web/src/nova/vi/meta/meta";
|
||||
import { IItem } from "../../../../web/src/utils/types/item";
|
||||
import { DComp } from "../../../../web/src/utils/types/root";
|
||||
import { SAction } from "../actions";
|
||||
import { loadComponent, userSyncComponent } from "../editor/load-component";
|
||||
import { parseJs } from "../editor/parser/parse-js";
|
||||
import { docs } from "../entity/docs";
|
||||
import { snapshot } from "../entity/snapshot";
|
||||
import { gzipAsync } from "../entity/zlib";
|
||||
|
|
@ -32,8 +35,30 @@ export const comp_load: SAction["comp"]["load"] = async function (
|
|||
|
||||
const snap = snapshot.get("comp", id);
|
||||
if (snap) {
|
||||
const meta = {};
|
||||
const item = docs.comp[id].doc
|
||||
.getMap("map")
|
||||
.get("root")
|
||||
?.toJSON() as IItem;
|
||||
|
||||
genMeta(
|
||||
{
|
||||
comps: {},
|
||||
meta,
|
||||
on: {
|
||||
visit(meta) {
|
||||
if (typeof meta.item.adv?.js === "string") {
|
||||
meta.scope.def = parseJs(meta);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{ item }
|
||||
);
|
||||
|
||||
result[id] = {
|
||||
id,
|
||||
meta,
|
||||
snapshot: await gzipAsync(snap.bin),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,8 +229,10 @@ const scanMeta = async (doc: DPage, sync: SyncConnection) => {
|
|||
meta,
|
||||
on: {
|
||||
visit(meta) {
|
||||
if (typeof meta.item.adv?.js === "string") {
|
||||
meta.scope.def = parseJs(meta);
|
||||
if (!meta.parent?.comp_id) {
|
||||
if (typeof meta.item.adv?.js === "string") {
|
||||
meta.scope.def = parseJs(meta);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
@ -242,7 +244,23 @@ const scanMeta = async (doc: DPage, sync: SyncConnection) => {
|
|||
|
||||
const comps: EPage["comps"] = {};
|
||||
for (const [id, snap] of Object.entries(msnap)) {
|
||||
comps[id] = { id, snapshot: await gzipAsync(snap.bin) };
|
||||
const meta = {};
|
||||
genMeta(
|
||||
{
|
||||
comps: {},
|
||||
meta,
|
||||
on: {
|
||||
visit(meta) {
|
||||
if (typeof meta.item.adv?.js === "string") {
|
||||
meta.scope.def = parseJs(meta);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{ item: mcomps[id].comp }
|
||||
);
|
||||
|
||||
comps[id] = { id, meta, snapshot: await gzipAsync(snap.bin) };
|
||||
}
|
||||
|
||||
return { meta: simplifyMeta(meta), comps, entry };
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ const EmptyPage = {
|
|||
|
||||
const EmptyComp = {
|
||||
id: "",
|
||||
meta: {} as Record<string, ISimpleMeta>,
|
||||
snapshot: null as null | Uint8Array,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export const mainPerItemVisit = (
|
|||
meta: MPIVParam[0],
|
||||
parts: MPIVParam[1]
|
||||
) => {
|
||||
if ((meta.item as IContent).type === "text" && !meta.item.adv?.jsBuilt) {
|
||||
if ((meta.item as IContent).type === "text" && !meta.item.adv?.js) {
|
||||
parts.props.spellCheck = false;
|
||||
parts.props.contentEditable = true;
|
||||
if (meta.parent?.comp_id) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ export const EdPopScript = () => {
|
|||
|
||||
if (script.type === "item") {
|
||||
delete p.script.init_local_effect[active.item_id];
|
||||
treeRebuild(p, { note: "script-close" });
|
||||
}
|
||||
|
||||
p.render();
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ export const EdTreeName = ({
|
|||
) : (
|
||||
<div className="flex flex-col">
|
||||
<Name name={node.text} is_jsx_prop={is_jsx_prop} />
|
||||
{/* <div className={"text-[9px] text-gray-500 -mt-1"}>{node.id} - {item.originalId}</div> */}
|
||||
<div className={"text-[9px] text-gray-500 -mt-1"}>{node.id} - {item.originalId}</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export const viParts = (meta: IMeta, arg?: ViParts) => {
|
|||
};
|
||||
|
||||
let shouldRenderChild = true;
|
||||
if (content.type === "text" && !item.adv?.jsBuilt) {
|
||||
if (content.type === "text" && !item.adv?.js) {
|
||||
props.dangerouslySetInnerHTML = { __html: item.html || "" };
|
||||
shouldRenderChild = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export const viEvalScript = (
|
|||
if (!meta.script) {
|
||||
meta.script = {
|
||||
result: null,
|
||||
Local: createViLocal(meta, scope, vi.script?.init_local_effect),
|
||||
Local: createViLocal(vi.meta, meta, scope, vi.script?.init_local_effect),
|
||||
PassProp: createViPassProp(vi, meta, scope),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { ReactNode, useEffect, useRef, useState } from "react";
|
||||
import { ReactNode, useEffect, useRef } from "react";
|
||||
import { IMeta } from "../../../ed/logic/ed-global";
|
||||
import { updatePropScope } from "./eval-prop";
|
||||
|
||||
export const createViLocal = (
|
||||
metas: Record<string, IMeta>,
|
||||
meta: IMeta,
|
||||
scope: any,
|
||||
init_local_effect: any
|
||||
|
|
@ -32,10 +33,24 @@ export const createViLocal = (
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
let should_run = !init_local_effect[meta.item.id];
|
||||
let id = meta.item.id;
|
||||
if (meta.parent?.instance_id) {
|
||||
const parent_meta = metas[meta.parent?.instance_id];
|
||||
if (parent_meta && parent_meta.instances) {
|
||||
for (const [k, v] of Object.entries(
|
||||
parent_meta.instances[meta.parent.instance_id]
|
||||
)) {
|
||||
if (v === meta.item.id) {
|
||||
id = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let should_run = !init_local_effect[id];
|
||||
if (should_run) {
|
||||
if (typeof init_local_effect === "object") {
|
||||
init_local_effect[meta.item.id] = true;
|
||||
init_local_effect[id] = true;
|
||||
}
|
||||
const fn = async () => {
|
||||
if (arg.effect) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue