wip fix component loading
This commit is contained in:
parent
603e687d70
commit
01c71a5423
|
|
@ -1,5 +1,6 @@
|
||||||
import { component, page } from "dbgen";
|
import { component, page } from "dbgen";
|
||||||
import {
|
import {
|
||||||
|
EComp,
|
||||||
EPage,
|
EPage,
|
||||||
ESite,
|
ESite,
|
||||||
IScopeComp,
|
IScopeComp,
|
||||||
|
|
@ -45,7 +46,8 @@ export const SyncActions = {
|
||||||
({}) as Record<string, Exclude<component, "content_tree">>,
|
({}) as Record<string, Exclude<component, "content_tree">>,
|
||||||
group: async (id_site: string) =>
|
group: async (id_site: string) =>
|
||||||
({}) as Record<string, { id: string; name: string; comps: string[] }>,
|
({}) as Record<string, { id: string; name: string; comps: string[] }>,
|
||||||
load: async (ids: string[]) => ({}) as Record<string, IScopeComp>,
|
load: async (ids: string[], sync?: boolean) =>
|
||||||
|
({}) as Record<string, EComp>,
|
||||||
},
|
},
|
||||||
page: {
|
page: {
|
||||||
list: async (id_site: string) =>
|
list: async (id_site: string) =>
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,42 @@
|
||||||
import { IScopeComp } from "../../../../web/src/nova/ed/logic/ed-global";
|
import { EComp } from "../../../../web/src/nova/ed/logic/ed-global";
|
||||||
import { DComp } from "../../../../web/src/utils/types/root";
|
import { DComp } from "../../../../web/src/utils/types/root";
|
||||||
import { SAction } from "../actions";
|
import { SAction } from "../actions";
|
||||||
import { loadComponent } from "../editor/load-component";
|
import { loadComponent, userSyncComponent } from "../editor/load-component";
|
||||||
import { docs } from "../entity/docs";
|
import { docs } from "../entity/docs";
|
||||||
|
import { snapshot } from "../entity/snapshot";
|
||||||
import { gzipAsync } from "../entity/zlib";
|
import { gzipAsync } from "../entity/zlib";
|
||||||
import { SyncConnection } from "../type";
|
import { SyncConnection } from "../type";
|
||||||
|
|
||||||
export const comp_load: SAction["comp"]["load"] = async function (
|
export const comp_load: SAction["comp"]["load"] = async function (
|
||||||
this: SyncConnection,
|
this: SyncConnection,
|
||||||
ids: string[]
|
comp_ids: string[],
|
||||||
|
sync
|
||||||
) {
|
) {
|
||||||
const result: Record<string, IScopeComp> = {};
|
const result: Record<string, EComp> = {};
|
||||||
for (const id of ids) {
|
const loading = {} as Record<string, Promise<void>>;
|
||||||
|
|
||||||
|
for (const id of comp_ids) {
|
||||||
|
if (!docs.comp[id]) {
|
||||||
|
if (typeof loading[id] === "undefined") {
|
||||||
|
loading[id] = new Promise<void>(async (resolve) => {
|
||||||
|
await loadComponent(id, sync ? this : undefined);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await loading[id];
|
||||||
|
} else {
|
||||||
|
if (sync) {
|
||||||
|
userSyncComponent(this, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const snap = snapshot.get("comp", id);
|
||||||
|
if (snap) {
|
||||||
|
result[id] = {
|
||||||
|
id,
|
||||||
|
snapshot: await gzipAsync(snap.bin),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,10 @@ import { gzipAsync } from "../entity/zlib";
|
||||||
import { sendWS } from "../sync-handler";
|
import { sendWS } from "../sync-handler";
|
||||||
import { SyncConnection, SyncType } from "../type";
|
import { SyncConnection, SyncType } from "../type";
|
||||||
|
|
||||||
export const loadComponent = async (comp_id: string, sync: SyncConnection) => {
|
export const loadComponent = async (comp_id: string, sync?: SyncConnection) => {
|
||||||
let snap = snapshot.get("comp", comp_id);
|
let snap = snapshot.get("comp", comp_id);
|
||||||
let ydoc = docs.comp[comp_id];
|
let ydoc = docs.comp[comp_id];
|
||||||
const conf = sync.conf;
|
const conf = sync?.conf;
|
||||||
|
|
||||||
if (!conf) return undefined;
|
|
||||||
|
|
||||||
const createUndoManager = async (root: Y.Map<any>) => {
|
const createUndoManager = async (root: Y.Map<any>) => {
|
||||||
const um = new Y.UndoManager(root, {
|
const um = new Y.UndoManager(root, {
|
||||||
|
|
@ -80,14 +78,16 @@ export const loadComponent = async (comp_id: string, sync: SyncConnection) => {
|
||||||
id_doc: doc.clientID,
|
id_doc: doc.clientID,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (sync && sync.conf) {
|
||||||
user.active.add({
|
user.active.add({
|
||||||
...defaultActive,
|
...defaultActive,
|
||||||
client_id: sync.client_id,
|
client_id: sync.client_id,
|
||||||
user_id: sync.user_id,
|
user_id: sync.user_id,
|
||||||
site_id: conf.site_id,
|
site_id: sync.conf.site_id,
|
||||||
page_id: conf.page_id,
|
page_id: sync.conf.page_id,
|
||||||
comp_id: comp.id,
|
comp_id: comp.id,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: comp_id,
|
id: comp_id,
|
||||||
|
|
@ -110,14 +110,16 @@ export const loadComponent = async (comp_id: string, sync: SyncConnection) => {
|
||||||
um,
|
um,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (sync && sync.conf) {
|
||||||
user.active.add({
|
user.active.add({
|
||||||
...defaultActive,
|
...defaultActive,
|
||||||
client_id: sync.client_id,
|
client_id: sync.client_id,
|
||||||
user_id: sync.user_id,
|
user_id: sync.user_id,
|
||||||
site_id: conf.site_id,
|
site_id: sync.conf.site_id,
|
||||||
page_id: conf.page_id,
|
page_id: sync.conf.page_id,
|
||||||
comp_id: comp_id,
|
comp_id: comp_id,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: comp_id,
|
id: comp_id,
|
||||||
|
|
@ -125,14 +127,16 @@ export const loadComponent = async (comp_id: string, sync: SyncConnection) => {
|
||||||
snapshot: await gzipAsync(snap.bin),
|
snapshot: await gzipAsync(snap.bin),
|
||||||
};
|
};
|
||||||
} else if (snap && ydoc) {
|
} else if (snap && ydoc) {
|
||||||
|
if (sync && sync.conf) {
|
||||||
user.active.add({
|
user.active.add({
|
||||||
...defaultActive,
|
...defaultActive,
|
||||||
client_id: sync.client_id,
|
client_id: sync.client_id,
|
||||||
user_id: sync.user_id,
|
user_id: sync.user_id,
|
||||||
site_id: conf.site_id,
|
site_id: sync.conf.site_id,
|
||||||
page_id: conf.page_id,
|
page_id: sync.conf.page_id,
|
||||||
comp_id: comp_id,
|
comp_id: comp_id,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: snap.id,
|
id: snap.id,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const loadcomp = {
|
||||||
pending: new Set<string>(),
|
pending: new Set<string>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadComponent = async (p: PG, id_comp: string) => {
|
export const loadComponent = async (p: PG, id_comp: string, sync?: boolean) => {
|
||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
if (p.comp.list[id_comp]) {
|
if (p.comp.list[id_comp]) {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
|
|
@ -22,14 +22,12 @@ export const loadComponent = async (p: PG, id_comp: string) => {
|
||||||
loadcomp.pending.add(id_comp);
|
loadcomp.pending.add(id_comp);
|
||||||
clearTimeout(loadcomp.timeout);
|
clearTimeout(loadcomp.timeout);
|
||||||
loadcomp.timeout = setTimeout(async () => {
|
loadcomp.timeout = setTimeout(async () => {
|
||||||
const comps = await p.sync.comp.load([...loadcomp.pending]);
|
const comps = await p.sync.comp.load([...loadcomp.pending], sync);
|
||||||
let result = Object.entries(comps);
|
let result = Object.entries(comps);
|
||||||
|
|
||||||
for (const [id_comp, comp] of result) {
|
for (const [id_comp, comp] of result) {
|
||||||
for (const cur of Object.values(comp)) {
|
if (comp && comp.snapshot) {
|
||||||
if (cur && cur.snapshot) {
|
await loadCompSnapshot(p, id_comp, comp.snapshot);
|
||||||
await loadCompSnapshot(p, id_comp, cur.snapshot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadcomp.pending.clear();
|
loadcomp.pending.clear();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
import { getMetaById } from "../../../logic/tree/build";
|
import { getMetaById } from "../../../logic/tree/build";
|
||||||
import { fillID } from "../../../logic/tree/fill-id";
|
import { fillID } from "../../../logic/tree/fill-id";
|
||||||
import { TopBtn } from "../top-btn";
|
import { TopBtn } from "../top-btn";
|
||||||
|
import { loadComponent } from "../../../logic/comp/load";
|
||||||
|
|
||||||
export const EdCompPicker = () => {
|
export const EdCompPicker = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -18,7 +19,7 @@ export const EdCompPicker = () => {
|
||||||
p.ui.popup.comp.open = async (comp_id) => {
|
p.ui.popup.comp.open = async (comp_id) => {
|
||||||
let comp_ref = p.comp.list[comp_id];
|
let comp_ref = p.comp.list[comp_id];
|
||||||
if (!comp_ref) {
|
if (!comp_ref) {
|
||||||
// await loadComponent(p, comp_id);
|
await loadComponent(p, comp_id);
|
||||||
comp_ref = p.comp.list[comp_id];
|
comp_ref = p.comp.list[comp_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export const EdCompPreview = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!p.comp.list[comp_id] && !!comp_id) {
|
if (!p.comp.list[comp_id] && !!comp_id) {
|
||||||
loadComponent(p, comp_id).then(() => {
|
loadComponent(p, comp_id, false).then(() => {
|
||||||
p.render();
|
p.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue