wip fix name

This commit is contained in:
Rizky 2024-02-18 16:12:56 +07:00
parent 52e739c8df
commit 1e523892bc
5 changed files with 78 additions and 29 deletions

View File

@ -48,7 +48,6 @@ export const code_edit: SAction["code"]["edit"] = async function (
if (root) { if (root) {
const mitem = findId(root, item_id); const mitem = findId(root, item_id);
if (mitem) { if (mitem) {
if (arg.type === "adv") { if (arg.type === "adv") {
const mode = arg.mode; const mode = arg.mode;
@ -228,15 +227,14 @@ const findId = (mitem: MContent | MRoot, id: string) => {
if (!found) { if (!found) {
const mprops = m.get("component")?.get("props"); const mprops = m.get("component")?.get("props");
if (mprops) { if (mprops) {
mprops.forEach((mprop) => { mprops.forEach((mprop) => {
if (mprop.get("meta")?.get("type") === "content-element") { const mcontent = mprop.get("content");
const mcontent = mprop.get("content"); if (mcontent) {
if (mcontent) { const f = findId(mcontent, id);
const f = findId(mcontent, id); if (f) {
if (f) { found = f;
found = f;
}
} }
} }
}); });

View File

@ -38,6 +38,16 @@ export const EdAddItem = () => {
}, },
} as IItem; } as IItem;
if (meta.item.component?.id && meta.item.component.props.child) {
const child_id = meta.item.component.props.child.content?.id;
if (child_id) {
const child_meta = getMetaById(p, child_id);
if (child_meta) {
meta = child_meta;
}
}
}
let mitem = meta.mitem; let mitem = meta.mitem;
if (mitem) { if (mitem) {
const item = meta.item as IContent; const item = meta.item as IContent;

View File

@ -28,6 +28,16 @@ export const EdAddText = () => {
} }
if (!meta) return null; if (!meta) return null;
if (meta.item.component?.id && meta.item.component.props.child) {
const child_id = meta.item.component.props.child.content?.id;
if (child_id) {
const child_meta = getMetaById(p, child_id);
if (child_meta) {
meta = child_meta;
}
}
}
meta.mitem?.doc?.transact(() => { meta.mitem?.doc?.transact(() => {
if (!meta) return null; if (!meta) return null;
@ -45,6 +55,7 @@ export const EdAddText = () => {
} as IText; } as IText;
let mitem = meta.mitem as MContent; let mitem = meta.mitem as MContent;
if (mitem) { if (mitem) {
const item = meta.item as IContent; const item = meta.item as IContent;

View File

@ -9,7 +9,7 @@ import { jscript } from "../../../../../utils/script/jscript";
import { jsMount } from "../../../../../utils/script/mount"; import { jsMount } from "../../../../../utils/script/mount";
import { monacoTypings } from "../../../../../utils/script/typings"; import { monacoTypings } from "../../../../../utils/script/typings";
import { Loading } from "../../../../../utils/ui/loading"; import { Loading } from "../../../../../utils/ui/loading";
import { getActiveMeta } from "../../../logic/active/get-meta"; import { getActiveMeta, getMetaById } from "../../../logic/active/get-meta";
import { EDGlobal, IMeta, active } from "../../../logic/ed-global"; import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
import { edMonacoDefaultVal } from "./default-val"; import { edMonacoDefaultVal } from "./default-val";
import { declareScope } from "./scope/scope"; import { declareScope } from "./scope/scope";
@ -169,7 +169,6 @@ declare global {
} }
` `
); );
} }
const nmodel = monaco.editor.createModel( const nmodel = monaco.editor.createModel(
@ -398,7 +397,7 @@ declare global {
clearTimeout(scriptEdit.timeout); clearTimeout(scriptEdit.timeout);
const applyChanges = async () => { const applyChanges = async () => {
if (!p.sync) return; if (!p.sync) return;
const value = local.value; const value = local.value;
const meta = getActiveMeta(p); const meta = getActiveMeta(p);
const mode = p.ui.popup.script.mode; const mode = p.ui.popup.script.mode;

View File

@ -24,13 +24,18 @@ export const EdTreeName = ({
const item = node.data?.item; const item = node.data?.item;
if (!item) return <></>; if (!item) return <></>;
const is_jsx_prop = !!node.data?.jsx_prop?.is_root; let is_jsx_prop = !!node.data?.jsx_prop?.is_root;
const isRenaming = p.ui.tree.rename_id === item.id; const isRenaming = p.ui.tree.rename_id === item.id;
let name = item.name; let name = item.name;
if (item.component?.id && p.comp.loaded[item.component.id]) { if (item.component?.id && p.comp.loaded[item.component.id]) {
name = p.comp.loaded[item.component.id].name; name = p.comp.loaded[item.component.id].name;
if (item.component.props.child) {
is_jsx_prop = true;
}
} }
return ( return (
<div className="text-[14px] relative flex flex-col justify-center cursor-pointer flex-1"> <div className="text-[14px] relative flex flex-col justify-center cursor-pointer flex-1">
{/* <div className="text-[10px]">{item.id}</div> */} {/* <div className="text-[10px]">{item.id}</div> */}
@ -144,7 +149,7 @@ const Name: FC<{ name: string; is_jsx_prop: boolean; meta?: IMeta }> = ({
P P
</Tooltip> </Tooltip>
<div className="flex-1">{name}</div> <div className="flex-1">{name}</div>
{meta && meta.mitem && <GenerateJSX mitem={meta.mitem} />} {meta && meta.mitem && <GenerateJSX meta={meta} />}
{meta && !meta.mitem && ( {meta && !meta.mitem && (
<Tooltip <Tooltip
delay={0} delay={0}
@ -185,28 +190,54 @@ Please put {${name}} somewhere inside component JS.`}</div>
return <div>{name}</div>; return <div>{name}</div>;
}; };
const GenerateJSX: FC<{ mitem: MItem }> = ({ mitem }) => { const GenerateJSX: FC<{ meta: IMeta }> = ({ meta }) => {
const p = useGlobal(EDGlobal, "EDITOR"); const p = useGlobal(EDGlobal, "EDITOR");
return ( return (
<Tooltip <Tooltip
content="Generate JSX" content="Generate JSX"
onClick={() => { onClick={() => {
const genJSX = findDefaultJSX(p, mitem); let mitem = undefined as undefined | MItem;
const ijson = mitem.toJSON() as IItem; let is_child = false;
mitem.doc?.transact(() => { if (meta.item.component?.id) {
syncronize(mitem as any, { mitem = meta.mitem
type: "item", ?.get("component")
dim: { w: "full", h: "full" }, ?.get("props")
childs: [], ?.get("child")
...(genJSX as any), ?.get("content");
name: ijson.name, is_child = true;
id: ijson.id, } else {
hidden: false, mitem = meta.mitem;
originalId: ijson.originalId, }
if (mitem) {
const genJSX = findDefaultJSX(p, mitem);
const ijson = mitem.toJSON() as IItem;
mitem.doc?.transact(() => {
syncronize(mitem as any, {
type: "item",
dim: { w: "full", h: "full" },
childs: [],
...(genJSX as any),
name: ijson.name,
id: ijson.id,
hidden: false,
originalId: ijson.originalId,
...(is_child
? {
adv: {
css: "",
js: "<>{children}</>",
jsBuilt:
"render(/* @__PURE__ */ React.createElement(React.Fragment, null, children));\n",
},
}
: {}),
});
}); });
}); treeRebuild(p);
treeRebuild(p); p.render();
p.render(); }
}} }}
> >
<div <div