From f9a492a290a9471db7ae6219ba8db8c8476c7349 Mon Sep 17 00:00:00 2001 From: Rizky Date: Sat, 2 Dec 2023 11:37:35 +0700 Subject: [PATCH] wip fix --- app/srv/ws/sync/editor/load-page.ts | 40 ++++++++----------- app/web/src/nova/ed/logic/ed-global.ts | 7 ++-- app/web/src/nova/ed/logic/tree/sync-walk.tsx | 17 ++++++-- app/web/src/nova/ed/panel/main/main.tsx | 1 + .../src/nova/ed/panel/tree/node/item/name.tsx | 36 ++++++++--------- app/web/src/nova/view/logic/global.ts | 15 ++++--- app/web/src/nova/view/logic/init.ts | 1 + app/web/src/nova/view/logic/types.ts | 3 +- .../view/render/meta/script/comp-propval.tsx | 17 ++++++-- 9 files changed, 76 insertions(+), 61 deletions(-) diff --git a/app/srv/ws/sync/editor/load-page.ts b/app/srv/ws/sync/editor/load-page.ts index 79a554fa..5aefa599 100644 --- a/app/srv/ws/sync/editor/load-page.ts +++ b/app/srv/ws/sync/editor/load-page.ts @@ -133,6 +133,10 @@ export const serverWalkMap = ( item.id = override_id; } + if (item.name === "render_col") { + console.log(item); + } + const item_comp = item.component; const mitem_comp = mitem.get("component"); if (item_comp && item_comp.id) { @@ -202,6 +206,8 @@ export const serverWalkMap = ( jsx_props: {}, }; + const content_scope: Record = {}; + extractMItemProps({ item_comp, mitem, @@ -216,6 +222,8 @@ export const serverWalkMap = ( parent_mcomp: arg.parent_mcomp, parent_ids: [...arg.parent_ids, item.id], }; + + content_scope[prop_name] = mcontent; } }, }); @@ -234,13 +242,20 @@ export const serverWalkMap = ( if (scope) pcomp.scope[item.id].s = scope; - if (!arg.parent_mcomp) { + if (!p.scope[item.id]) { p.scope[item.id] = { p: arg.parent_ids, n: item.name, s: null, }; - if (scope) p.scope[item.id].s = scope; + } + + if (scope) { + if (!p.scope[item.id].s) { + p.scope[item.id].s = scope; + } else { + p.scope[item.id].s = { ...p.scope[item.id].s, ...scope }; + } } const childs = mcomp.get("childs")?.map((e) => e) || []; @@ -277,27 +292,6 @@ export const serverWalkMap = ( const scope = parseJs(js); if (scope) pcomp.scope[id].s = scope; } - - if (item.name.startsWith("jsx=")) { - const name = item.name.substring(4).trim(); - if (arg.parent_mcomp.jsx_props[name]) { - const jsx = arg.parent_mcomp.jsx_props[name]; - serverWalkMap(p, { - mitem: jsx.mitem, - parent_item: { id: item.id, mitem: mitem as MItem }, - parent_mcomp: jsx.parent_mcomp - ? { - ...jsx.parent_mcomp, - parent_ids: [ - ...(arg.parent_ids || []), - mitem.get("id") || "", - ], - } - : undefined, - parent_ids: [...arg.parent_ids, mitem.get("id") || ""], - }); - } - } } } else { if (!(item_comp && item_comp.id)) { diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index d9a56261..2a755561 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -124,8 +124,9 @@ export type EdMeta = { }; el?: ReactElement; is_layout?: boolean; - is_jsx_prop?: boolean; + jsx_prop_name?: string; /** script related meta **/ + jsx_scope_id?: string; propval?: Record; indexed_scope: Record; memoize?: Record< @@ -155,7 +156,7 @@ export const EDGlobal = { script: { siteTypes: {} as Record, loaded: false, - do_edit: async (newval: string, all?: boolean) => { }, + do_edit: async (newval: string, all?: boolean) => {}, }, page: { root_id: "root", @@ -174,7 +175,7 @@ export const EDGlobal = { meta: {} as Record, entry: [] as string[], tree: [] as NodeModel[], - render: () => { }, + render: () => {}, }, comp: { doc: null as null | DComp, diff --git a/app/web/src/nova/ed/logic/tree/sync-walk.tsx b/app/web/src/nova/ed/logic/tree/sync-walk.tsx index 1ae559a9..5c39c95f 100644 --- a/app/web/src/nova/ed/logic/tree/sync-walk.tsx +++ b/app/web/src/nova/ed/logic/tree/sync-walk.tsx @@ -76,7 +76,7 @@ export const syncWalkMap = ( }; parent_item: EdMeta["parent_item"]; parent_mcomp?: EdMeta["parent_mcomp"]; - is_jsx_prop?: boolean; + jsx_prop_name?: string; skip_add_tree?: boolean; tree_root_id: string; each?: (meta: EdMeta) => void; @@ -129,6 +129,16 @@ export const syncWalkMap = ( item.id = override_id; } + if (arg.jsx_prop_name) { + const pitem = p.meta[arg.parent_item.id].item; + if (pitem.type === "item" && pitem.component) { + const pprop = pitem.component.props[arg.jsx_prop_name]; + if (pprop.content) { + pprop.content.id = item.id; + } + } + } + const item_comp = item.component; const mitem_comp = mitem.get("component"); const metaNotFound = () => { @@ -224,7 +234,7 @@ export const syncWalkMap = ( is_layout: arg.is_layout, tree_root_id: arg.tree_root_id, mitem: mcontent, - is_jsx_prop: true, + jsx_prop_name: k, parent_mcomp: arg.parent_mcomp, parent_item: { id: item.id, mitem: mitem as MItem }, portal: arg.portal, @@ -264,9 +274,9 @@ export const syncWalkMap = ( const meta: EdMeta = { is_layout: arg.is_layout, item, + jsx_prop_name: arg.jsx_prop_name, mitem: mitem as MItem, parent_item, - is_jsx_prop: arg.is_jsx_prop, parent_mcomp: parent_mcomp, indexed_scope: {}, }; @@ -297,7 +307,6 @@ export const syncWalkMap = ( is_layout: arg.is_layout, tree_root_id: arg.tree_root_id, mitem: e, - is_jsx_prop: arg.is_jsx_prop, parent_item: { id: item.id, mitem: mitem as MItem }, parent_mcomp: arg.parent_mcomp, portal: arg.portal, diff --git a/app/web/src/nova/ed/panel/main/main.tsx b/app/web/src/nova/ed/panel/main/main.tsx index f32357f6..fffa7476 100644 --- a/app/web/src/nova/ed/panel/main/main.tsx +++ b/app/web/src/nova/ed/panel/main/main.tsx @@ -35,6 +35,7 @@ export const EdMain = () => { mode: "tree_meta", meta: p.page.meta, entry: p.page.entry, + scope: p.page.scope, }} site_id={p.site.id} page_id={p.page.cur.id} diff --git a/app/web/src/nova/ed/panel/tree/node/item/name.tsx b/app/web/src/nova/ed/panel/tree/node/item/name.tsx index 35481bb4..64bd3db1 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/name.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/name.tsx @@ -22,7 +22,7 @@ export const EdTreeName = ({ const mitem = node.data?.mitem; if (!item || !mitem) return <>; - const is_jsx_prop = !!node.data?.is_jsx_prop; + const is_jsx_prop = !!node.data?.jsx_prop_name; const isRenaming = p.ui.tree.rename_id === item.id; return ( @@ -112,22 +112,22 @@ const Name: FC<{ name: string; is_jsx_prop: boolean }> = ({ ); } - if (typeof name === "string" && name.startsWith("jsx=")) { - return ( -
-
- - - - `, - }} - >
-
{name.substring(4)}
-
- ); - } + // if (typeof name === "string" && name.startsWith("jsx=")) { + // return ( + //
+ //
+ // + // + // + // `, + // }} + // >
+ //
{name.substring(4)}
+ //
+ // ); + // } return
{name}
; }; diff --git a/app/web/src/nova/view/logic/global.ts b/app/web/src/nova/view/logic/global.ts index 3ec72975..b069fce2 100644 --- a/app/web/src/nova/view/logic/global.ts +++ b/app/web/src/nova/view/logic/global.ts @@ -1,7 +1,5 @@ import { ReactElement, ReactNode } from "react"; -import { IContent } from "../../../utils/types/general"; -import { IText } from "../../../utils/types/text"; -import { EdMeta } from "../../ed/logic/ed-global"; +import { EdMeta, IScope } from "../../ed/logic/ed-global"; export const ViewGlobal = { mode: "" as "desktop" | "mobile", @@ -9,10 +7,11 @@ export const ViewGlobal = { current: { site_id: "", page_id: "" }, layout: { show: false }, meta: {} as Record, + scope: null as null | IScope, entry: [] as string[], body_cache: null as null | ReactElement, component: { - load: async (id_comp: string) => { }, + load: async (id_comp: string) => {}, }, script: { api_url: "", @@ -24,10 +23,10 @@ export const ViewGlobal = { active: undefined as | undefined | { - get: (meta: EdMeta) => boolean; - set: (meta: EdMeta) => void; - text?: (meta: EdMeta) => ReactNode - }, + get: (meta: EdMeta) => boolean; + set: (meta: EdMeta) => void; + text?: (meta: EdMeta) => ReactNode; + }, hover: undefined as | undefined | { get: (meta: EdMeta) => boolean; set: (meta: EdMeta) => void }, diff --git a/app/web/src/nova/view/logic/init.ts b/app/web/src/nova/view/logic/init.ts index c04cfd02..8e5128f0 100644 --- a/app/web/src/nova/view/logic/init.ts +++ b/app/web/src/nova/view/logic/init.ts @@ -30,5 +30,6 @@ export const vInit = ( if (load.mode === "tree_meta") { v.meta = load.meta; v.entry = load.entry; + v.scope = load.scope || null; } }; diff --git a/app/web/src/nova/view/logic/types.ts b/app/web/src/nova/view/logic/types.ts index 5296fac3..28c5b6f0 100644 --- a/app/web/src/nova/view/logic/types.ts +++ b/app/web/src/nova/view/logic/types.ts @@ -1,4 +1,4 @@ -import { EdMeta, PG } from "../../ed/logic/ed-global"; +import { EdMeta, IScope, PG } from "../../ed/logic/ed-global"; export type VLoad = | { mode: "page"; page_id: string } @@ -6,6 +6,7 @@ export type VLoad = | { mode: "tree_meta"; entry: string[]; + scope?: IScope; meta: Record; }; diff --git a/app/web/src/nova/view/render/meta/script/comp-propval.tsx b/app/web/src/nova/view/render/meta/script/comp-propval.tsx index 18e5f0b1..0613944d 100644 --- a/app/web/src/nova/view/render/meta/script/comp-propval.tsx +++ b/app/web/src/nova/view/render/meta/script/comp-propval.tsx @@ -1,4 +1,5 @@ import { createAPI, createDB } from "../../../../../utils/script/init-api"; +import { IItem } from "../../../../../utils/types/item"; import { FNCompDef } from "../../../../../utils/types/meta-fn"; import { EdMeta } from "../../../../ed/logic/ed-global"; import { VG } from "../../../logic/global"; @@ -77,10 +78,18 @@ export const compPropVal = ( }) => { if (prop.content) { const meta = v.meta[prop.content.id] as EdMeta; - if (meta) { - if (!meta.parent_item) - meta.parent_item = { id: parent_id }; - else meta.parent_item.id = parent_id; + 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]; + } + } return (