wip fix layout
This commit is contained in:
parent
24adfb9b05
commit
83c6a91b29
|
|
@ -122,10 +122,10 @@ export type EdMeta = {
|
||||||
mcomp: MItem;
|
mcomp: MItem;
|
||||||
};
|
};
|
||||||
el?: ReactElement;
|
el?: ReactElement;
|
||||||
isLayout?: boolean;
|
is_layout?: boolean;
|
||||||
/** script related meta **/
|
/** script related meta **/
|
||||||
propval?: Record<string, any>;
|
propval?: Record<string, any>;
|
||||||
indexedScope: Record<string, any>;
|
idexed_scope: Record<string, any>;
|
||||||
memoize?: Record<
|
memoize?: Record<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
|
|
@ -156,6 +156,7 @@ export const EDGlobal = {
|
||||||
do_edit: async (newval: string, all?: boolean) => {},
|
do_edit: async (newval: string, all?: boolean) => {},
|
||||||
},
|
},
|
||||||
page: {
|
page: {
|
||||||
|
root_id: "root",
|
||||||
cur: EmptyPage,
|
cur: EmptyPage,
|
||||||
doc: null as null | DPage,
|
doc: null as null | DPage,
|
||||||
list: {} as Record<
|
list: {} as Record<
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
decompress(res.sv)
|
decompress(res.sv)
|
||||||
);
|
);
|
||||||
Y.applyUpdate(doc as any, decompress(res.diff), "local");
|
Y.applyUpdate(doc as any, decompress(res.diff), "local");
|
||||||
await treeRebuild(p, { note: "page-on-update" });
|
await treeRebuild(p, { note: note + " page-on-update" });
|
||||||
|
|
||||||
await p.sync.yjs.diff_local(
|
await p.sync.yjs.diff_local(
|
||||||
"page",
|
"page",
|
||||||
|
|
@ -113,7 +113,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.page.doc) {
|
if (p.page.doc) {
|
||||||
await treeRebuild(p, { note: "reload-page-init" });
|
await treeRebuild(p, { note: note + " page-init" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.status = "ready";
|
p.status = "ready";
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
out: {} as Record<string, EdMeta>,
|
out: {} as Record<string, EdMeta>,
|
||||||
};
|
};
|
||||||
|
|
||||||
let root_id = "root";
|
p.page.root_id = "root";
|
||||||
if (p.site.layout && p.site.layout.id !== p.page.cur.id) {
|
if (p.site.layout && p.site.layout.id !== p.page.cur.id) {
|
||||||
const ldoc = p.page.list[p.site.layout.id];
|
const ldoc = p.page.list[p.site.layout.id];
|
||||||
if (ldoc) {
|
if (ldoc) {
|
||||||
|
|
@ -46,7 +46,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
if (component.pending) await component.pending;
|
if (component.pending) await component.pending;
|
||||||
|
|
||||||
sections.map((e) => {
|
sections.map((e) => {
|
||||||
if (root_id === "root") {
|
if (p.page.root_id === "root") {
|
||||||
p.page.entry.push(e.get("id"));
|
p.page.entry.push(e.get("id"));
|
||||||
}
|
}
|
||||||
syncWalkMap(
|
syncWalkMap(
|
||||||
|
|
@ -58,13 +58,13 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
{
|
{
|
||||||
isLayout: true,
|
isLayout: true,
|
||||||
mitem: e,
|
mitem: e,
|
||||||
parent_item: { id: root_id },
|
parent_item: { id: p.page.root_id },
|
||||||
tree_root_id: root_id,
|
tree_root_id: p.page.root_id,
|
||||||
skip_add_tree: true,
|
skip_add_tree: true,
|
||||||
portal,
|
portal,
|
||||||
each(meta) {
|
each(meta) {
|
||||||
if (meta.item.name === "content") {
|
if (meta.item.name === "content") {
|
||||||
root_id = meta.item.id;
|
p.page.root_id = meta.item.id;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -85,9 +85,9 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if root_id is root, it means content is not found.
|
// if p.page.root_id is root, it means content is not found.
|
||||||
// if content is not found, do not use layout.
|
// if content is not found, do not use layout.
|
||||||
if (root_id === "root") {
|
if (p.page.root_id === "root") {
|
||||||
p.page.entry = [];
|
p.page.entry = [];
|
||||||
p.page.tree = [];
|
p.page.tree = [];
|
||||||
p.page.meta = {};
|
p.page.meta = {};
|
||||||
|
|
@ -113,8 +113,13 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
const sections = root.get("childs");
|
const sections = root.get("childs");
|
||||||
if (sections) {
|
if (sections) {
|
||||||
sections.map((e) => {
|
sections.map((e) => {
|
||||||
if (root_id === "root") {
|
if (p.page.root_id === "root") {
|
||||||
p.page.entry.push(e.get("id"));
|
p.page.entry.push(e.get("id"));
|
||||||
|
} else {
|
||||||
|
const meta = p.page.meta[p.page.root_id];
|
||||||
|
if (meta && meta.item.type === "item") {
|
||||||
|
meta.item.childs.push({ id: e.get("id") } as any);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
syncWalkMap(
|
syncWalkMap(
|
||||||
{
|
{
|
||||||
|
|
@ -126,8 +131,8 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
{
|
{
|
||||||
isLayout: false,
|
isLayout: false,
|
||||||
mitem: e,
|
mitem: e,
|
||||||
parent_item: { id: root_id },
|
parent_item: { id: p.page.root_id },
|
||||||
tree_root_id: root_id,
|
tree_root_id: p.page.root_id,
|
||||||
portal,
|
portal,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -115,8 +115,8 @@ export const walkMap = (
|
||||||
const meta: EdMeta = {
|
const meta: EdMeta = {
|
||||||
item,
|
item,
|
||||||
parent_item,
|
parent_item,
|
||||||
indexedScope: {},
|
idexed_scope: {},
|
||||||
isLayout: arg.isLayout,
|
is_layout: arg.isLayout,
|
||||||
};
|
};
|
||||||
if (item.name.startsWith("⬅")) {
|
if (item.name.startsWith("⬅")) {
|
||||||
arg.portal.in[item.name] = meta;
|
arg.portal.in[item.name] = meta;
|
||||||
|
|
@ -159,9 +159,9 @@ export const walkMap = (
|
||||||
const meta: EdMeta = {
|
const meta: EdMeta = {
|
||||||
item,
|
item,
|
||||||
parent_item,
|
parent_item,
|
||||||
indexedScope: {},
|
idexed_scope: {},
|
||||||
parent_comp,
|
parent_comp,
|
||||||
isLayout: arg.isLayout,
|
is_layout: arg.isLayout,
|
||||||
};
|
};
|
||||||
if (item.name.startsWith("⬅")) {
|
if (item.name.startsWith("⬅")) {
|
||||||
arg.portal.in[item.name] = meta;
|
arg.portal.in[item.name] = meta;
|
||||||
|
|
|
||||||
|
|
@ -154,8 +154,8 @@ export const syncWalkMap = (
|
||||||
mitem: mitem as MItem,
|
mitem: mitem as MItem,
|
||||||
parent_item,
|
parent_item,
|
||||||
parent_mcomp: parent_mcomp,
|
parent_mcomp: parent_mcomp,
|
||||||
indexedScope: {},
|
idexed_scope: {},
|
||||||
isLayout: arg.isLayout,
|
is_layout: arg.isLayout,
|
||||||
};
|
};
|
||||||
if (item.name.startsWith("⬅")) {
|
if (item.name.startsWith("⬅")) {
|
||||||
arg.portal.in[item.name] = meta;
|
arg.portal.in[item.name] = meta;
|
||||||
|
|
@ -163,7 +163,6 @@ export const syncWalkMap = (
|
||||||
if (item.name.startsWith("⮕")) {
|
if (item.name.startsWith("⮕")) {
|
||||||
arg.portal.out[item.name] = meta;
|
arg.portal.out[item.name] = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.each) arg.each(meta);
|
if (arg.each) arg.each(meta);
|
||||||
p.meta[item.id] = meta;
|
p.meta[item.id] = meta;
|
||||||
|
|
||||||
|
|
@ -232,11 +231,12 @@ export const syncWalkMap = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta: EdMeta = {
|
const meta: EdMeta = {
|
||||||
|
is_layout: arg.isLayout,
|
||||||
item,
|
item,
|
||||||
mitem: mitem as MItem,
|
mitem: mitem as MItem,
|
||||||
parent_item,
|
parent_item,
|
||||||
parent_mcomp: parent_mcomp,
|
parent_mcomp: parent_mcomp,
|
||||||
indexedScope: {},
|
idexed_scope: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (item.name.startsWith("⬅")) {
|
if (item.name.startsWith("⬅")) {
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,6 @@ export const EdTreeAction = ({
|
||||||
if (comp_id) {
|
if (comp_id) {
|
||||||
active.instance.item_id = item.id;
|
active.instance.item_id = item.id;
|
||||||
active.instance.comp_id = active.comp_id;
|
active.instance.comp_id = active.comp_id;
|
||||||
console.log(
|
|
||||||
active.instance.comp_id,
|
|
||||||
active.instance.item_id
|
|
||||||
);
|
|
||||||
|
|
||||||
active.comp_id = comp_id || "";
|
active.comp_id = comp_id || "";
|
||||||
const root = p.comp.list[comp_id].tree.find(
|
const root = p.comp.list[comp_id].tree.find(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const ViewMetaRender: FC<{
|
||||||
}> = ({ meta, v, props, className }) => {
|
}> = ({ meta, v, props, className }) => {
|
||||||
let _className = className;
|
let _className = className;
|
||||||
const item = meta.item;
|
const item = meta.item;
|
||||||
if (meta.isLayout && !v.layout.show) {
|
if (meta.is_layout && !v.layout.show) {
|
||||||
return <ViewMetaChildren item={item} />;
|
return <ViewMetaChildren item={item} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { deepClone } from "web-utils";
|
|
||||||
import { createAPI, createDB } from "../../../../../utils/script/init-api";
|
import { createAPI, createDB } from "../../../../../utils/script/init-api";
|
||||||
import { FNCompDef } from "../../../../../utils/types/meta-fn";
|
import { FNCompDef } from "../../../../../utils/types/meta-fn";
|
||||||
import { EdMeta } from "../../../../ed/logic/ed-global";
|
import { EdMeta } from "../../../../ed/logic/ed-global";
|
||||||
|
|
@ -8,17 +7,13 @@ import { ViewMeta } from "../meta";
|
||||||
import { mergeScopeUpwards } from "./merge-upward";
|
import { mergeScopeUpwards } from "./merge-upward";
|
||||||
|
|
||||||
const jsxProps = {} as Record<string, any>;
|
const jsxProps = {} as Record<string, any>;
|
||||||
export const compPropVal = (
|
export const compPropVal = (v: VG, meta: EdMeta) => {
|
||||||
v: VG,
|
|
||||||
meta: EdMeta,
|
|
||||||
) => {
|
|
||||||
let props = {} as Record<string, FNCompDef>;
|
let props = {} as Record<string, FNCompDef>;
|
||||||
let cprops = {} as [string, FNCompDef][];
|
let cprops = {} as [string, FNCompDef][];
|
||||||
const item = meta.item;
|
const item = meta.item;
|
||||||
if (item.type === "item" && item.component?.id) {
|
if (item.type === "item" && item.component?.id) {
|
||||||
const icomp = item.component;
|
const icomp = item.component;
|
||||||
if (icomp) {
|
if (icomp) {
|
||||||
props = deepClone(v.component.map[icomp.id]?.item.component?.props || {});
|
|
||||||
cprops = Object.entries(props);
|
cprops = Object.entries(props);
|
||||||
|
|
||||||
if (v.script.api_url) {
|
if (v.script.api_url) {
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@ export const createLocal = (
|
||||||
}
|
}
|
||||||
scope = meta.scope;
|
scope = meta.scope;
|
||||||
} else {
|
} else {
|
||||||
if (!meta.indexedScope) {
|
if (!meta.idexed_scope) {
|
||||||
meta.indexedScope = {};
|
meta.idexed_scope = {};
|
||||||
}
|
}
|
||||||
if (!meta.indexedScope[local_id]) meta.indexedScope[local_id] = {};
|
if (!meta.idexed_scope[local_id]) meta.idexed_scope[local_id] = {};
|
||||||
scope = meta.indexedScope[local_id];
|
scope = meta.idexed_scope[local_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
const render = () => {
|
const render = () => {
|
||||||
|
|
@ -80,7 +80,7 @@ export const createLocal = (
|
||||||
let page_id = v.current.page_id || "";
|
let page_id = v.current.page_id || "";
|
||||||
const itemid = meta.item.id + (local_id ? `_${local_id}` : "");
|
const itemid = meta.item.id + (local_id ? `_${local_id}` : "");
|
||||||
|
|
||||||
if (meta.isLayout) {
|
if (meta.is_layout) {
|
||||||
page_id = "layout";
|
page_id = "layout";
|
||||||
if (cachedLayout[meta.item.id]) {
|
if (cachedLayout[meta.item.id]) {
|
||||||
scope[name] = cachedLocal[page_id][itemid];
|
scope[name] = cachedLocal[page_id][itemid];
|
||||||
|
|
@ -129,7 +129,7 @@ export const createLocal = (
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (effect) {
|
if (effect) {
|
||||||
if (meta.isLayout) {
|
if (meta.is_layout) {
|
||||||
if (cachedLayout[meta.item.id]) {
|
if (cachedLayout[meta.item.id]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ export const createPassProp = (
|
||||||
const meta = v.meta[id];
|
const meta = v.meta[id];
|
||||||
|
|
||||||
if (typeof arg.idx !== "undefined" && meta && meta.item && meta.item.id) {
|
if (typeof arg.idx !== "undefined" && meta && meta.item && meta.item.id) {
|
||||||
meta.indexedScope[arg.idx] = {};
|
meta.idexed_scope[arg.idx] = {};
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(arg)) {
|
for (const [k, v] of Object.entries(arg)) {
|
||||||
if (k === "children") continue;
|
if (k === "children") continue;
|
||||||
meta.indexedScope[arg.idx][k] = v;
|
meta.idexed_scope[arg.idx][k] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
const scopeIndex = { ...existingScopeIndex, [meta.item.id]: arg.idx };
|
const scopeIndex = { ...existingScopeIndex, [meta.item.id]: arg.idx };
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ export const mergeScopeUpwards = (
|
||||||
|
|
||||||
let indexedScope = null;
|
let indexedScope = null;
|
||||||
|
|
||||||
if (cur.indexedScope && scopeIndex) {
|
if (cur.idexed_scope && scopeIndex) {
|
||||||
const idx = scopeIndex[cur.item.id];
|
const idx = scopeIndex[cur.item.id];
|
||||||
|
|
||||||
if (typeof idx !== "undefined" && cur.indexedScope[idx]) {
|
if (typeof idx !== "undefined" && cur.idexed_scope[idx]) {
|
||||||
indexedScope = cur.indexedScope[idx];
|
indexedScope = cur.idexed_scope[idx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue