wip fix
This commit is contained in:
parent
03ac444c76
commit
4a0ae73c0c
|
|
@ -40,5 +40,3 @@ export const comp_load: SAction["comp"]["load"] = async function (
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const scanMeta = async (id: string, doc: DComp, sync: SyncConnection) => {};
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { IItem } from "../../../../web/src/utils/types/item";
|
||||||
|
import { DComp } from "../../../../web/src/utils/types/root";
|
||||||
import { conns } from "../entity/conn";
|
import { conns } from "../entity/conn";
|
||||||
import { docs } from "../entity/docs";
|
import { docs } from "../entity/docs";
|
||||||
import { snapshot } from "../entity/snapshot";
|
import { snapshot } from "../entity/snapshot";
|
||||||
|
|
@ -9,7 +11,6 @@ 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 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, {
|
||||||
|
|
@ -22,6 +23,21 @@ export const loadComponent = async (comp_id: string, sync?: SyncConnection) => {
|
||||||
const attachOnUpdate = async (doc: Y.Doc, um: Y.UndoManager) => {
|
const attachOnUpdate = async (doc: Y.Doc, um: Y.UndoManager) => {
|
||||||
snapshot.set("comp", comp_id, "id_doc", um.doc.clientID);
|
snapshot.set("comp", comp_id, "id_doc", um.doc.clientID);
|
||||||
|
|
||||||
|
const mitem = (doc as DComp).getMap("map").get("root");
|
||||||
|
if (mitem) {
|
||||||
|
const item = mitem.toJSON() as IItem;
|
||||||
|
if (!item.component) {
|
||||||
|
const component = new Y.Map();
|
||||||
|
syncronize(component, { id: comp_id, props: {} });
|
||||||
|
mitem.set("component", component as any);
|
||||||
|
} else if (item.component.id !== comp_id) {
|
||||||
|
const mcomp = mitem.get("component");
|
||||||
|
if (mcomp && mcomp.get("id") !== comp_id) {
|
||||||
|
mcomp.set("id", comp_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doc.on("update", async (update: Uint8Array, origin: any) => {
|
doc.on("update", async (update: Uint8Array, origin: any) => {
|
||||||
const bin = Y.encodeStateAsUpdate(doc);
|
const bin = Y.encodeStateAsUpdate(doc);
|
||||||
snapshot.set("comp", comp_id, "bin", bin);
|
snapshot.set("comp", comp_id, "bin", bin);
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,7 @@ export const EDGlobal = {
|
||||||
entry: [] as string[],
|
entry: [] as string[],
|
||||||
tree: [] as NodeModel<IMeta>[],
|
tree: [] as NodeModel<IMeta>[],
|
||||||
render: () => {},
|
render: () => {},
|
||||||
|
prevent_rebuild: false,
|
||||||
},
|
},
|
||||||
comp: {
|
comp: {
|
||||||
doc: null as null | DComp,
|
doc: null as null | DComp,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import { IMeta, PG, active } from "../ed-global";
|
||||||
import { pushTreeNode } from "./build/push-tree";
|
import { pushTreeNode } from "./build/push-tree";
|
||||||
|
|
||||||
export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
|
if (p.page.prevent_rebuild) return;
|
||||||
|
|
||||||
const is_layout =
|
const is_layout =
|
||||||
p.site.layout &&
|
p.site.layout &&
|
||||||
p.site.layout.id === p.page.cur.id &&
|
p.site.layout.id === p.page.cur.id &&
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ import { IMeta, PG, active } from "../../logic/ed-global";
|
||||||
import { treeRebuild } from "../../logic/tree/build";
|
import { treeRebuild } from "../../logic/tree/build";
|
||||||
|
|
||||||
type MPIVParam = Parameters<Exclude<VG["visit"], undefined>>;
|
type MPIVParam = Parameters<Exclude<VG["visit"], undefined>>;
|
||||||
|
|
||||||
|
const text_edit = { timeout: null as any };
|
||||||
|
|
||||||
export const mainPerItemVisit = (
|
export const mainPerItemVisit = (
|
||||||
p: PG,
|
p: PG,
|
||||||
meta: MPIVParam[0],
|
meta: MPIVParam[0],
|
||||||
|
|
@ -12,45 +15,55 @@ export const mainPerItemVisit = (
|
||||||
if ((meta.item as IContent).type === "text" && !meta.item.adv?.jsBuilt) {
|
if ((meta.item as IContent).type === "text" && !meta.item.adv?.jsBuilt) {
|
||||||
parts.props.spellCheck = false;
|
parts.props.spellCheck = false;
|
||||||
parts.props.contentEditable = true;
|
parts.props.contentEditable = true;
|
||||||
parts.props.dangerouslySetInnerHTML = {
|
|
||||||
__html: meta.item.html || " ",
|
|
||||||
};
|
|
||||||
parts.props.onFocus = (e) => {
|
parts.props.onFocus = (e) => {
|
||||||
if (![meta.item.originalId, meta.item.id].includes(active.item_id)) {
|
p.page.prevent_rebuild = true;
|
||||||
|
p.render();
|
||||||
|
const is_active = ![meta.item.originalId, meta.item.id].includes(
|
||||||
|
active.item_id
|
||||||
|
);
|
||||||
|
if (is_active) {
|
||||||
e.currentTarget.blur();
|
e.currentTarget.blur();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
parts.props.onBlur = (e) => {
|
parts.props.onBlur = (e) => {
|
||||||
e.stopPropagation();
|
p.page.prevent_rebuild = false;
|
||||||
const val = e.currentTarget.innerHTML;
|
p.render();
|
||||||
if (active.comp_id && meta.parent?.comp_id === active.comp_id) {
|
};
|
||||||
const comp = p.comp.list[active.comp_id];
|
|
||||||
const m = comp.meta[meta.item.originalId || meta.item.id];
|
|
||||||
if (m && m.mitem) {
|
|
||||||
m.item.html = val;
|
|
||||||
m.mitem.set("html", val);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mitem = meta.mitem;
|
parts.props.onInput = (e) => {
|
||||||
if (mitem) {
|
e.stopPropagation();
|
||||||
meta.item.html = val;
|
e.preventDefault();
|
||||||
mitem.set("html", val);
|
const val = e.currentTarget.innerHTML;
|
||||||
}
|
clearTimeout(text_edit.timeout);
|
||||||
|
text_edit.timeout = setTimeout(() => {
|
||||||
|
if (active.comp_id && meta.parent?.comp_id === active.comp_id) {
|
||||||
|
const comp = p.comp.list[active.comp_id];
|
||||||
|
const m = comp.meta[meta.item.originalId || meta.item.id];
|
||||||
|
if (m && m.mitem) {
|
||||||
|
m.item.html = val;
|
||||||
|
m.mitem.set("html", val);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mitem = meta.mitem;
|
||||||
|
if (mitem) {
|
||||||
|
meta.item.html = val;
|
||||||
|
mitem.set("html", val);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let isActive: boolean = active.item_id === meta.item.id;
|
let is_active: boolean = active.item_id === meta.item.id;
|
||||||
if (active.comp_id) {
|
if (active.comp_id) {
|
||||||
isActive = active.item_id === meta.item.originalId;
|
is_active = active.item_id === meta.item.originalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.props.className = cx(
|
parts.props.className = cx(
|
||||||
parts.props.className,
|
parts.props.className,
|
||||||
isActive && "el-active",
|
is_active && "el-active",
|
||||||
isActive &&
|
is_active &&
|
||||||
css`
|
css`
|
||||||
&::after {
|
&::after {
|
||||||
content: " ";
|
content: " ";
|
||||||
|
|
@ -123,14 +136,3 @@ const getOuterMeta = (p: { meta: Record<string, IMeta> }, meta: IMeta) => {
|
||||||
|
|
||||||
if (cur) return cur;
|
if (cur) return cur;
|
||||||
};
|
};
|
||||||
function setEndOfContenteditable(div: any) {
|
|
||||||
let range: any, sel: any;
|
|
||||||
if (document.createRange) {
|
|
||||||
//Firefox, Chrome, Opera, Safari, IE 9+
|
|
||||||
range = document.createRange();
|
|
||||||
range.selectNodeContents(div);
|
|
||||||
sel = window.getSelection();
|
|
||||||
sel.removeAllRanges();
|
|
||||||
sel.addRange(range);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,11 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
p.page.render();
|
p.page.render();
|
||||||
if ((item as IContent).type === "text") {
|
if ((item as IContent).type === "text") {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
(document.querySelector(".el-active") as any)?.focus();
|
if (document.activeElement?.tagName === "INPUT") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const el_active = document.querySelector(".el-active") as any;
|
||||||
|
if (el_active) el_active.focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue