diff --git a/app/srv/ws/sync/actions/page_load.ts b/app/srv/ws/sync/actions/page_load.ts index 167552cb..cfd2afc4 100644 --- a/app/srv/ws/sync/actions/page_load.ts +++ b/app/srv/ws/sync/actions/page_load.ts @@ -1,4 +1,5 @@ import { EPage } from "../../../../web/src/nova/ed/logic/ed-global"; +import { assignMitem } from "../../../../web/src/nova/ed/logic/tree/assign-mitem"; import { initLoadComp } from "../../../../web/src/nova/vi/meta/comp/init-comp-load"; import { genMeta } from "../../../../web/src/nova/vi/meta/meta"; import { simplifyMeta } from "../../../../web/src/nova/vi/meta/simplify"; @@ -239,6 +240,10 @@ const scanMeta = async (doc: DPage, sync: SyncConnection) => { ); } + const transact = { + instances_check: {} as Record, + }; + for (const mitem of childs) { const item = mitem.toJSON() as IItem; entry.push(item.id); @@ -247,10 +252,21 @@ const scanMeta = async (doc: DPage, sync: SyncConnection) => { comps: mcomps, meta, on: { - visit(meta) { - if (!meta.parent?.comp_id) { - if (typeof meta.item.adv?.js === "string") { - meta.scope.def = parseJs(meta.item.adv?.js); + visit_component(item) { + if (!item.component?.instances) { + transact.instances_check[item.id] = true; + } + }, + visit(m) { + if (!m.parent?.comp_id) { + if (typeof m.item.adv?.js === "string") { + m.scope.def = parseJs(m.item.adv?.js); + } + } + + if (m.item.component?.id) { + if (transact.instances_check[m.item.id]) { + transact.instances_check[m.item.id] = m; } } }, diff --git a/app/web/package.json b/app/web/package.json index 0009ebc2..473868b8 100644 --- a/app/web/package.json +++ b/app/web/package.json @@ -19,7 +19,7 @@ "@qiwi/deep-proxy": "^2.0.3", "algoliasearch": "^4.22.0", "date-fns": "^2.30.0", - "fast-safe-stringify": "^2.1.1", + "safe-flat": "^2.1.0", "dbgen": "workspace:*", "downshift": "^8.2.3", "esbuild-wasm": "^0.19.10", @@ -105,4 +105,4 @@ "staticFiles": { "staticPath": "public" } -} +} \ No newline at end of file diff --git a/app/web/src/nova/ed/logic/tree/assign-mitem.ts b/app/web/src/nova/ed/logic/tree/assign-mitem.ts new file mode 100644 index 00000000..b8166435 --- /dev/null +++ b/app/web/src/nova/ed/logic/tree/assign-mitem.ts @@ -0,0 +1,54 @@ +import { IItem, MItem } from "../../../../utils/types/item"; +import { IMeta } from "../ed-global"; + +export const assignMitem = (arg: { + m: IMeta; + item: IItem; + mitem: MItem; + meta: Record; +}) => { + const { m, item, mitem, meta } = arg; + if (m.parent) { + if (m.parent.id === "root") { + if (m.item.id === item.id) { + m.mitem = mitem; + } + } else { + const parent = meta[m.parent.id]; + if (parent.mitem) { + parent.mitem.get("childs")?.forEach((child) => { + if (child.get("id") === m.item.id) { + m.mitem = child; + + if (m.item.component?.props) { + for (const [prop_name, v] of Object.entries( + m.item.component.props + )) { + const mprop = m.mitem + ?.get("component") + ?.get("props") + ?.get(prop_name); + if (v.content && mprop) { + const pmeta = meta[v.content.id]; + if (pmeta) { + pmeta.mitem = mprop.get("content"); + } + } + } + } + } + }); + } + } + } + + if (m.jsx_prop && m.parent?.instance_id) { + const parent = meta[m.parent?.instance_id]; + if (parent) { + const prop = parent.item.component?.props[m.jsx_prop.name]; + if (prop) { + prop.content = m.item; + } + } + } +}; diff --git a/app/web/src/nova/ed/logic/tree/build.tsx b/app/web/src/nova/ed/logic/tree/build.tsx index 3f66ddfa..09c52334 100644 --- a/app/web/src/nova/ed/logic/tree/build.tsx +++ b/app/web/src/nova/ed/logic/tree/build.tsx @@ -2,6 +2,7 @@ import { IItem, MItem } from "../../../../utils/types/item"; import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn"; import { genMeta } from "../../../vi/meta/meta"; import { IMeta, PG, active } from "../ed-global"; +import { assignMitem } from "./assign-mitem"; import { pushTreeNode } from "./build/push-tree"; export const treeRebuild = async (p: PG, arg?: { note?: string }) => { @@ -45,49 +46,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => { if (!is_layout) { pushTreeNode(p, m, meta, p.page.tree); - if (m.parent) { - if (m.parent.id === "root") { - if (m.item.id === item.id) { - m.mitem = mitem; - } - } else { - const parent = meta[m.parent.id]; - if (parent.mitem) { - parent.mitem.get("childs")?.forEach((child) => { - if (child.get("id") === m.item.id) { - m.mitem = child; - - if (m.item.component?.props) { - for (const [prop_name, v] of Object.entries( - m.item.component.props - )) { - const mprop = m.mitem - ?.get("component") - ?.get("props") - ?.get(prop_name); - if (v.content && mprop) { - const pmeta = meta[v.content.id]; - if (pmeta) { - pmeta.mitem = mprop.get("content"); - } - } - } - } - } - }); - } - } - } - - if (m.jsx_prop && m.parent?.instance_id) { - const parent = meta[m.parent?.instance_id]; - if (parent) { - const prop = parent.item.component?.props[m.jsx_prop.name]; - if (prop) { - prop.content = m.item; - } - } - } + assignMitem({ m, item, mitem, meta }); } }, }, 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 1f1972a6..f50a5b97 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 @@ -98,7 +98,7 @@ export const EdTreeName = ({ ) : (
- {/*
{node.id} - {item.originalId}
*/} +
{node.id} - {item.originalId}
)} diff --git a/app/web/src/nova/vi/meta/comp.tsx b/app/web/src/nova/vi/meta/comp.tsx index 415d8c41..28a49e09 100644 --- a/app/web/src/nova/vi/meta/comp.tsx +++ b/app/web/src/nova/vi/meta/comp.tsx @@ -1,6 +1,6 @@ import { deepClone } from "web-utils"; import { GenMetaArg, GenMetaP, IMeta, ISimpleMeta } from "../utils/types"; -import { instantiate, walkChild } from "./comp/instantiate"; +import { instantiate } from "./comp/instantiate"; import { walkProp } from "./comp/walk-prop"; import { genMeta } from "./meta"; import { simplifyItemChild } from "./simplify"; @@ -10,7 +10,7 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => { if (item.type === "item" && item.component?.id && arg.parent?.item.id) { let pcomp = p.comps[item.component.id]; if (p.on?.visit_component) { - p.on.visit_component(item.component.id); + p.on.visit_component(item); } if (!pcomp) { @@ -21,10 +21,15 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => { let instance = {}; let instances: IMeta["instances"] = undefined; - const parent_instance = getParentInstance(p, arg, item.id); - - instance = parent_instance || {}; - instances = !parent_instance ? { [item.id]: instance } : undefined; + if (item.component.instances) { + instances = item.component.instances; + instance = instances[item.id] || {}; + instances[item.id] = instance; + } else { + const parent_instance = getParentInstance(p, arg, item.id); + instance = parent_instance || {}; + instances = !parent_instance ? { [item.id]: instance } : undefined; + } instantiate({ item, @@ -72,8 +77,6 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => { if (prop.meta?.type === "content-element" && comp_id) { if (prop.content) { - walkChild(prop.content, instance); - genMeta( { ...p, smeta }, { diff --git a/app/web/src/nova/vi/meta/comp/init-comp-load.tsx b/app/web/src/nova/vi/meta/comp/init-comp-load.tsx index 3202a900..f7f62a79 100644 --- a/app/web/src/nova/vi/meta/comp/init-comp-load.tsx +++ b/app/web/src/nova/vi/meta/comp/init-comp-load.tsx @@ -13,10 +13,13 @@ export const initLoadComp = async ( { ...p, on: { - visit_component: (id) => { - if (!p.comps[id]) { - if (!_loaded || (_loaded && !_loaded.has(id))) { - comp_ids.add(id); + visit_component: ({ component }) => { + if (component) { + const { id } = component; + if (!p.comps[id]) { + if (!_loaded || (_loaded && !_loaded.has(id))) { + comp_ids.add(id); + } } } }, diff --git a/app/web/src/nova/vi/meta/comp/instantiate.tsx b/app/web/src/nova/vi/meta/comp/instantiate.tsx index 6093827d..2bc3bf11 100644 --- a/app/web/src/nova/vi/meta/comp/instantiate.tsx +++ b/app/web/src/nova/vi/meta/comp/instantiate.tsx @@ -22,7 +22,7 @@ export const instantiate = (arg: { if (item.component.props[k]) { newitem.component.props[k] = item.component.props[k]; } - + const content = newitem.component.props[k].content; if (content) { walkChild(content, ids); @@ -37,7 +37,6 @@ export const instantiate = (arg: { for (const [k, v] of Object.entries(newitem)) { (item as any)[k] = v; } - }; export const walkChild = ( diff --git a/app/web/src/nova/vi/render/script/eval-script.tsx b/app/web/src/nova/vi/render/script/eval-script.tsx index 30b51bc1..b51de23c 100644 --- a/app/web/src/nova/vi/render/script/eval-script.tsx +++ b/app/web/src/nova/vi/render/script/eval-script.tsx @@ -8,6 +8,7 @@ import { updatePropScope } from "./eval-prop"; import { createViLocal } from "./local"; import { createViPassProp } from "./passprop"; import hash_sum from "hash-sum"; +import { flatten } from "safe-flat"; export const viEvalScript = ( vi: { @@ -22,7 +23,7 @@ export const viEvalScript = ( if (vi.visit) vi.visit(meta, parts); - const mhash = hash_sum(passprop); + const mhash = hash_sum(flatten(passprop)); if (!meta.script) meta.script = {}; if (!meta.script[mhash]) { diff --git a/app/web/src/nova/vi/utils/types.ts b/app/web/src/nova/vi/utils/types.ts index a406f9c5..c948e0cf 100644 --- a/app/web/src/nova/vi/utils/types.ts +++ b/app/web/src/nova/vi/utils/types.ts @@ -9,7 +9,7 @@ export type GenMetaP = { meta: Record; comps: Record }>; on?: { - visit_component?: (id: string) => void; + visit_component?: (item: IItem) => void; visit?: (meta: IMeta) => void; item_exists?: (arg: { old: IMeta; new: IMeta }) => void; item_new?: (arg: { new: IMeta }) => void; diff --git a/app/web/src/utils/types/meta-fn.ts b/app/web/src/utils/types/meta-fn.ts index a98eaee7..ed4f11a6 100644 --- a/app/web/src/utils/types/meta-fn.ts +++ b/app/web/src/utils/types/meta-fn.ts @@ -1,7 +1,5 @@ import { TypedMap } from "yjs-types"; import { IItem, MItem } from "./item"; -import * as Y from "yjs"; -import { YText } from "yjs/dist/src/internals"; export type FNLayout = { dir: "row" | "col" | "row-reverse" | "col-reverse"; align: FNAlign; @@ -25,6 +23,7 @@ export type FNComponent = { loaded?: boolean; props: Record; ref_ids?: Record; + instances?: Record>; }; export type FNCompDef = { diff --git a/bun.lockb b/bun.lockb index 455ac6ce..f4335ef4 100755 Binary files a/bun.lockb and b/bun.lockb differ