This commit is contained in:
Rizky 2023-12-09 12:32:15 +07:00
parent 9e39b7d0fd
commit 65da157965
13 changed files with 50 additions and 49 deletions

View File

@ -126,6 +126,7 @@ export type EdMeta = {
el?: ReactElement;
is_layout?: boolean;
jsx_prop_name?: string;
jsx_prop_root?: boolean;
/** script related meta **/
jsx_scope_id?: string;
propval?: Record<string, any>;

View File

@ -76,6 +76,7 @@ export const syncWalkMap = (
parent_item: EdMeta["parent_item"];
parent_mcomp?: EdMeta["parent_mcomp"];
jsx_prop_name?: string;
jsx_prop_root?: boolean;
skip_add_tree?: boolean;
tree_root_id: string;
each?: (meta: EdMeta) => void;
@ -239,6 +240,7 @@ export const syncWalkMap = (
tree_root_id: arg.tree_root_id,
mitem: mcontent,
jsx_prop_name: k,
jsx_prop_root: true,
parent_mcomp: { minstance, meta, mcomp },
parent_item: { id: item.id, mitem: mitem as MItem },
portal: arg.portal,
@ -279,6 +281,7 @@ export const syncWalkMap = (
is_layout: arg.is_layout,
item,
jsx_prop_name: arg.jsx_prop_name,
jsx_prop_root: arg.jsx_prop_root,
mitem: mitem as MItem,
parent_item,
parent_mcomp: arg.parent_mcomp,
@ -311,6 +314,7 @@ export const syncWalkMap = (
is_layout: arg.is_layout,
tree_root_id: arg.tree_root_id,
mitem: e,
jsx_prop_name: arg.jsx_prop_name,
parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: arg.parent_mcomp,
portal: arg.portal,

View File

@ -67,6 +67,8 @@ export const EdMain = () => {
},
set(meta) {
const outer = getOuterItem(meta);
console.log(meta);
if (outer) {
active.item_id = outer.id;
}
@ -154,6 +156,9 @@ export const EdMain = () => {
const getOuterItem = (meta: EdMeta) => {
let cur: undefined | EdMeta = meta;
if (cur.jsx_prop_name) return meta.item;
while (cur.parent_mcomp) {
cur = cur.parent_mcomp.meta;
}

View File

@ -47,6 +47,7 @@ export const ScriptMonaco = () => {
}, []);
useEffect(() => {
clearTimeout(scriptEdit.timeout);
(async () => {
const editor = local.editor;
const monaco = local.monaco;

View File

@ -101,7 +101,6 @@ else metaOptions = resOpt;
local.render();
}}
onChange={(sel) => {
console.log(sel);
if (!sel) {
local.val = evalue;
local.isOpen = false;

View File

@ -29,35 +29,12 @@ export const nodeRender: NodeRender<EdMeta> = (node, prm) => {
);
}
if (node.data?.jsx_prop_name) {
if (node.data?.jsx_prop_root && node.data?.jsx_prop_name) {
const meta = getMetaById(p, node.data?.parent_item.id);
if (meta) {
if (meta.propvis) {
jsxPropVisCache[meta.item.id] = meta.propvis;
if (meta.propvis[node.data.jsx_prop_name] === false) return <></>;
} else {
if (jsxPropVisCache[meta.item.id]) {
meta.propvis = jsxPropVisCache[meta.item.id];
if (meta.propvis) {
if (meta.propvis[node.data.jsx_prop_name] === false) return <></>;
}
} else {
if (!jsxPropLoadingRender[meta.item.id]) {
setTimeout(p.render, 100);
setTimeout(p.render, 500);
jsxPropLoadingRender[meta.item.id] = node.data.jsx_prop_name;
}
if (jsxPropLoadingRender[meta.item.id] === node.data.jsx_prop_name) {
return (
<div
className={"relative border-b flex items-stretch min-h-[26px]"}
>
<Loading backdrop={false} />
</div>
);
}
return <></>;
}
}
}
}

View File

@ -45,7 +45,7 @@ export const oldLoadCode = async (v: VG) => {
exports: {} as any,
},
};
exec(site.js_compiled, scope);
await exec(site.js_compiled, scope);
if (scope.module.exports) {
for (const [k, v] of Object.entries(scope.module.exports)) {
w.exports[k] = v;

View File

@ -37,12 +37,5 @@ export const ViewMetaChildren: FC<{
}
}
return (
<>
{/* <div className={"text-[9px] text-gray-500 -mt-1"}>
{item.id} - {item.originalId}
</div> */}
{Object.values(children)}
</>
);
return <>{Object.values(children)}</>;
};

View File

@ -1,5 +1,5 @@
import hash_sum from "hash-sum";
import { FC, ReactNode, useEffect } from "react";
import { FC, ReactNode, isValidElement, useEffect } from "react";
import { useLocal } from "web-utils";
import { produceCSS } from "../../../../utils/css/gen";
import { createAPI, createDB } from "../../../../utils/script/init-api";
@ -170,8 +170,16 @@ export const ViewMetaScript: FC<{
},
useEffect: useEffect,
render: (jsx: ReactNode) => {
output.jsx = jsx;
renderLimit[v.current.page_id][item.id].cache = output.jsx;
if (isValidElement(jsx)) {
// output.jsx = (
// <>
// <div className={"absolute bg-white px-1 z-10 text-[9px] text-gray-500 -mt-1"}>{item.id}</div>
// {jsx}
// </>
// );
output.jsx = jsx;
renderLimit[v.current.page_id][item.id].cache = output.jsx;
}
},
};

View File

@ -61,7 +61,8 @@ export const compPropVal = (
prop.value
);
}
} else if (prop.meta?.type === "content-element") {
}
if (prop.meta?.type === "content-element") {
if (!(typeof value === "object" && !!value && value._jsx)) {
const id = `${meta.item.id}-${name}`;
if (!jsxProps[id]) {
@ -79,14 +80,7 @@ export const compPropVal = (
let parent = v.meta[parent_id];
if (meta && parent) {
if (v.scope) {
while (parent) {
if (v.scope[parent.item.id]) {
v.scope[prop.content.id] = v.scope[parent.item.id];
}
parent = v.meta[parent.parent_item.id];
}
}
meta.parent_item.id = parent_id;
return (
<ViewMeta
@ -106,6 +100,7 @@ export const compPropVal = (
result[name] = value;
}
meta.propval = result;
const propvis: any = {};

View File

@ -47,6 +47,15 @@ export const jsMount = async (editor: MonacoEditor, monaco: Monaco, p?: PG) => {
const id = path[path.length - 1].replace(".d.ts", "");
if (type === "prop") {
if (p.ui.popup.script.type === "item") {
p.ui.popup.script.open = false;
p.render();
setTimeout(() => {
p.ui.popup.script.open = true;
p.render();
}, 100);
}
p.ui.popup.script.prop_name = path[1];
p.ui.popup.script.type = "prop-instance";
p.ui.popup.script.prop_kind = "value";
@ -66,7 +75,16 @@ export const jsMount = async (editor: MonacoEditor, monaco: Monaco, p?: PG) => {
return false;
} else {
p.ui.popup.script.type = "item";
if (p.ui.popup.script.type !== "item") {
p.ui.popup.script.open = false;
p.ui.popup.script.type = "item";
p.ui.popup.script.prop_name = "";
p.render();
setTimeout(() => {
p.ui.popup.script.open = true;
p.render();
}, 100);
}
}
if (comp_id) {

View File

@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"dev": "bun run --hot ./pkgs/core/index.ts dev",
"clean": "rm -rf app/static && rm -rf app/web/.parcel-cache",
"clean": "rm -rf data/lmdb && rm -rf app/static && rm -rf app/web/.parcel-cache",
"build": "bun run --silent ./pkgs/core/build.ts",
"build-site": "bun run --silent ./pkgs/core/build-site.ts",
"db-pull": "bun run ./pkgs/crm -rf data && rore/db-pull.ts",
@ -29,4 +29,4 @@
"fdir": "^6.1.0",
"typescript": "^5.2.2"
}
}
}