wip fix
This commit is contained in:
parent
b5b018084b
commit
79dfc0375b
|
|
@ -191,7 +191,7 @@ export const serverWalkMap = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const pcomp = p.scope_comps[item_comp.id];
|
const pcomp = p.scope_comps[item_comp.id];
|
||||||
pcomp.scope[item.id] = { p: arg.parent_ids, s: null };
|
pcomp.scope[item.id] = { p: arg.parent_ids, n: item.name, s: null };
|
||||||
const js = item.adv?.js;
|
const js = item.adv?.js;
|
||||||
if (typeof js === "string") {
|
if (typeof js === "string") {
|
||||||
const res = parseJs(js);
|
const res = parseJs(js);
|
||||||
|
|
@ -205,9 +205,9 @@ export const serverWalkMap = (
|
||||||
if (!parent_mcomp) {
|
if (!parent_mcomp) {
|
||||||
p.scope[item.id] = {
|
p.scope[item.id] = {
|
||||||
p: arg.parent_ids,
|
p: arg.parent_ids,
|
||||||
name: item.name,
|
n: item.name,
|
||||||
s: null,
|
s: null,
|
||||||
} as any;
|
};
|
||||||
if (scope) p.scope[item.id].s = scope;
|
if (scope) p.scope[item.id].s = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,14 +234,14 @@ export const serverWalkMap = (
|
||||||
|
|
||||||
if (arg.parent_mcomp && !arg.is_prop) {
|
if (arg.parent_mcomp && !arg.is_prop) {
|
||||||
const pcomp = p.scope_comps[arg.parent_mcomp.id];
|
const pcomp = p.scope_comps[arg.parent_mcomp.id];
|
||||||
pcomp.scope[item.id] = { p: arg.parent_ids, s: null };
|
pcomp.scope[item.id] = { p: arg.parent_ids, n: item.name, s: null };
|
||||||
const js = item.adv?.js;
|
const js = item.adv?.js;
|
||||||
if (typeof js === "string") {
|
if (typeof js === "string") {
|
||||||
const scope = parseJs(js);
|
const scope = parseJs(js);
|
||||||
if (scope) pcomp.scope[item.id].s = scope;
|
if (scope) pcomp.scope[item.id].s = scope;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
p.scope[item.id] = { p: arg.parent_ids, name: item.name, s: null } as any;
|
p.scope[item.id] = { p: arg.parent_ids, n: item.name, s: null };
|
||||||
const js = item.adv?.js;
|
const js = item.adv?.js;
|
||||||
if (typeof js === "string") {
|
if (typeof js === "string") {
|
||||||
const scope = parseJs(js);
|
const scope = parseJs(js);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ export const EdLeft = () => {
|
||||||
|
|
||||||
<EdTreeSearch />
|
<EdTreeSearch />
|
||||||
<div className="tree-body flex relative flex-1 overflow-y-auto overflow-x-hidden">
|
<div className="tree-body flex relative flex-1 overflow-y-auto overflow-x-hidden">
|
||||||
<div className="absolute inset-0 flex">
|
<div className="absolute inset-0 flex flex-col">
|
||||||
<DndProvider backend={MultiBackend} options={getBackendOptions()}>
|
<DndProvider backend={MultiBackend} options={getBackendOptions()}>
|
||||||
<EdTreeBody />
|
<EdTreeBody />
|
||||||
</DndProvider>
|
</DndProvider>
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ export type EComp = typeof EmptyComp;
|
||||||
|
|
||||||
export type ISingleScope = {
|
export type ISingleScope = {
|
||||||
p: string[];
|
p: string[];
|
||||||
|
n: string;
|
||||||
s: null | Exclude<ReturnType<typeof parseJs>, undefined>;
|
s: null | Exclude<ReturnType<typeof parseJs>, undefined>;
|
||||||
};
|
};
|
||||||
export type IScope = Record<string, ISingleScope>;
|
export type IScope = Record<string, ISingleScope>;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import type { OnMount } from "@monaco-editor/react";
|
import type { OnMount } from "@monaco-editor/react";
|
||||||
import { deepClone } from "web-utils";
|
import { deepClone } from "web-utils";
|
||||||
import { ISingleScope, PG, active } from "../../../logic/ed-global";
|
import { EPage, ISingleScope, PG, active } from "../../../logic/ed-global";
|
||||||
type Monaco = Parameters<OnMount>[1];
|
type Monaco = Parameters<OnMount>[1];
|
||||||
export type MonacoEditor = Parameters<OnMount>[0];
|
export type MonacoEditor = Parameters<OnMount>[0];
|
||||||
|
|
||||||
|
|
@ -44,12 +44,16 @@ export const declareScope = async (
|
||||||
export const {};
|
export const {};
|
||||||
const __val = ${arg.value};
|
const __val = ${arg.value};
|
||||||
declare global {
|
declare global {
|
||||||
const ${arg.name}: typeof __val;
|
const ${arg.name}: typeof __val ${
|
||||||
|
arg.type === "local" ? " & { render: ()=>void}" : ""
|
||||||
|
};
|
||||||
}`
|
}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const layout_scope = {} as Record<string, ISingleScope>;
|
||||||
|
|
||||||
type IEachArgScope = {
|
type IEachArgScope = {
|
||||||
s: ISingleScope;
|
s: ISingleScope;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -64,8 +68,41 @@ const spreadScope = (
|
||||||
s: ISingleScope,
|
s: ISingleScope,
|
||||||
each: (arg: IEachArgScope) => void
|
each: (arg: IEachArgScope) => void
|
||||||
) => {
|
) => {
|
||||||
for (const parent_id of s.p) {
|
const parents = [...s.p];
|
||||||
const item = p.page.scope[parent_id];
|
const layout_id = p.site.layout.id;
|
||||||
|
let layout = null as null | EPage;
|
||||||
|
if (layout_id && p.page.list[layout_id]) {
|
||||||
|
layout = p.page.list[layout_id].page;
|
||||||
|
if (!layout_scope[layout_id]) {
|
||||||
|
if (layout) {
|
||||||
|
const scope = Object.values(layout.scope).find((e) => {
|
||||||
|
return e.n === "content";
|
||||||
|
});
|
||||||
|
if (scope) {
|
||||||
|
layout_scope[layout_id] = scope;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const scope = layout_scope[layout_id];
|
||||||
|
if (scope) {
|
||||||
|
parents.shift();
|
||||||
|
scope.p.forEach((e) => parents.unshift(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const parent_id of parents) {
|
||||||
|
let item = null as null | ISingleScope;
|
||||||
|
if (layout && layout_scope[layout_id]) {
|
||||||
|
const scope = layout_scope[layout_id];
|
||||||
|
if (scope.p.includes(parent_id)) {
|
||||||
|
item = layout.scope[parent_id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!item) {
|
||||||
|
item = p.page.scope[parent_id];
|
||||||
|
}
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
const scope = item.s;
|
const scope = item.s;
|
||||||
if (scope) {
|
if (scope) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { jscript } from "../../../../../utils/script/jscript";
|
||||||
import { Loading } from "../../../../../utils/ui/loading";
|
import { Loading } from "../../../../../utils/ui/loading";
|
||||||
import { Modal } from "../../../../../utils/ui/modal";
|
import { Modal } from "../../../../../utils/ui/modal";
|
||||||
import { EDGlobal } from "../../../logic/ed-global";
|
import { EDGlobal } from "../../../logic/ed-global";
|
||||||
import { ScriptMonaco } from "./monaco";
|
|
||||||
import { ScriptWorkbench } from "./workbench";
|
import { ScriptWorkbench } from "./workbench";
|
||||||
|
|
||||||
export const EdPopScript = () => {
|
export const EdPopScript = () => {
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ import {
|
||||||
PlaceholderRender,
|
PlaceholderRender,
|
||||||
TreeMethods,
|
TreeMethods,
|
||||||
} from "@minoru/react-dnd-treeview";
|
} from "@minoru/react-dnd-treeview";
|
||||||
|
import { FC } from "react";
|
||||||
import { useGlobal, useLocal } from "web-utils";
|
import { useGlobal, useLocal } from "web-utils";
|
||||||
import { EDGlobal, EdMeta, active } from "../../logic/ed-global";
|
import { EDGlobal, EdMeta, active } from "../../logic/ed-global";
|
||||||
|
import { DEPTH_WIDTH } from "./node/item/indent";
|
||||||
import { indentHook } from "./node/item/indent-hook";
|
import { indentHook } from "./node/item/indent-hook";
|
||||||
import { canDrop, nodeOnDrop } from "./node/on-drop";
|
import { canDrop, nodeOnDrop } from "./node/on-drop";
|
||||||
import { nodeRender } from "./node/render";
|
import { nodeRender } from "./node/render";
|
||||||
import { FC } from "react";
|
|
||||||
import { DEPTH_WIDTH } from "./node/item/indent";
|
|
||||||
import { doTreeSearch } from "./search";
|
import { doTreeSearch } from "./search";
|
||||||
|
|
||||||
export const EdTreeBody = () => {
|
export const EdTreeBody = () => {
|
||||||
|
|
@ -25,9 +25,15 @@ export const EdTreeBody = () => {
|
||||||
if (p.ui.tree.search) {
|
if (p.ui.tree.search) {
|
||||||
tree = doTreeSearch(p);
|
tree = doTreeSearch(p);
|
||||||
} else {
|
} else {
|
||||||
if (active.comp_id) {
|
if (
|
||||||
|
active.comp_id &&
|
||||||
|
p.comp.list[active.comp_id] &&
|
||||||
|
p.comp.list[active.comp_id].tree
|
||||||
|
) {
|
||||||
|
tree = p.comp.list[active.comp_id].tree;
|
||||||
|
} else {
|
||||||
|
tree = p.page.tree;
|
||||||
}
|
}
|
||||||
tree = p.page.tree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree.length === 0)
|
if (tree.length === 0)
|
||||||
|
|
@ -47,27 +53,29 @@ export const EdTreeBody = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypedTree
|
<>
|
||||||
tree={tree}
|
<TypedTree
|
||||||
rootId={"root"}
|
tree={tree}
|
||||||
insertDroppableFirst={false}
|
rootId={"root"}
|
||||||
classes={treeClasses}
|
insertDroppableFirst={false}
|
||||||
ref={(el) => {
|
classes={treeClasses}
|
||||||
local.tree = el;
|
ref={(el) => {
|
||||||
}}
|
local.tree = el;
|
||||||
sort={false}
|
}}
|
||||||
dropTargetOffset={10}
|
sort={false}
|
||||||
render={nodeRender}
|
dropTargetOffset={10}
|
||||||
onDrop={nodeOnDrop}
|
render={nodeRender}
|
||||||
canDrop={(_, args) => {
|
onDrop={nodeOnDrop}
|
||||||
if (!args.dragSource?.data?.item) return false;
|
canDrop={(_, args) => {
|
||||||
return canDrop(p, args);
|
if (!args.dragSource?.data?.item) return false;
|
||||||
}}
|
return canDrop(p, args);
|
||||||
dragPreviewRender={DragPreview}
|
}}
|
||||||
placeholderRender={(node, params) => (
|
dragPreviewRender={DragPreview}
|
||||||
<Placeholder node={node} params={params} />
|
placeholderRender={(node, params) => (
|
||||||
)}
|
<Placeholder node={node} params={params} />
|
||||||
/>
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,10 @@ export const EdTreeAction = ({
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
const item = node.data?.item;
|
const item = node.data?.item;
|
||||||
if (!item) return null;
|
if (!item) return null;
|
||||||
const isComponent = item.type === "item" && !!item.component?.id;
|
const comp = {
|
||||||
|
enabled: item.type === "item" && !!item.component?.id,
|
||||||
|
id: item.type === "item" && item.component ? item.component.id : "",
|
||||||
|
};
|
||||||
|
|
||||||
let mode = "";
|
let mode = "";
|
||||||
if (item.adv?.js) mode = "js";
|
if (item.adv?.js) mode = "js";
|
||||||
|
|
@ -22,27 +25,61 @@ export const EdTreeAction = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center pr-1">
|
<div className="flex items-center pr-1">
|
||||||
{isComponent && (
|
{comp.enabled && (
|
||||||
<Tooltip
|
<>
|
||||||
content="Edit Component"
|
{comp.id !== active.comp_id && (
|
||||||
className="flex items-center border border-slate-500 bg-white rounded-sm text-[10px] px-[2px] cursor-pointer hover:bg-purple-100 hover:border-purple-600"
|
<Tooltip content="Edit Component">
|
||||||
onClick={(e) => {
|
<div
|
||||||
e.stopPropagation();
|
className="flex items-center border border-slate-500 bg-white rounded-sm text-[10px] px-[2px] cursor-pointer hover:bg-purple-100 hover:border-purple-600"
|
||||||
e.preventDefault();
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
const comp_id = item.component?.id;
|
const comp_id = comp.id;
|
||||||
if (comp_id) {
|
if (comp_id) {
|
||||||
active.comp_id = comp_id;
|
active.comp_id = comp_id;
|
||||||
active.comp_item_id = item.id;
|
active.comp_item_id = item.id;
|
||||||
p.render();
|
const root = p.comp.list[comp_id].tree.find(
|
||||||
}
|
(e) => e.parent === "root"
|
||||||
}}
|
);
|
||||||
>
|
if (root && typeof root.id === "string") {
|
||||||
<>Edit</>
|
active.item_id = root.id;
|
||||||
</Tooltip>
|
}
|
||||||
|
|
||||||
|
p.render();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
{comp.id === active.comp_id && (
|
||||||
|
<>
|
||||||
|
<Tooltip content="Edit Component">
|
||||||
|
<div
|
||||||
|
className="flex items-center border border-slate-500 bg-white rounded-sm text-[10px] px-[2px] cursor-pointer hover:bg-purple-100 hover:border-purple-600"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (active.comp_id) {
|
||||||
|
active.comp_id = "";
|
||||||
|
active.item_id = active.comp_item_id;
|
||||||
|
active.comp_item_id = "";
|
||||||
|
p.render();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isComponent && (
|
{!comp.enabled && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={`Edit ${mode}`}
|
content={`Edit ${mode}`}
|
||||||
className={cx(
|
className={cx(
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,6 @@ export const nodeRender: NodeRender<EdMeta> = (node, prm) => {
|
||||||
"relative border-b flex items-stretch outline-none min-h-[26px]",
|
"relative border-b flex items-stretch outline-none min-h-[26px]",
|
||||||
prm.hasChild && "has-child",
|
prm.hasChild && "has-child",
|
||||||
css`
|
css`
|
||||||
&:focus {
|
|
||||||
.focus {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&:hover {
|
&:hover {
|
||||||
.action-script {
|
.action-script {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
|
|
@ -251,7 +246,11 @@ export const nodeRender: NodeRender<EdMeta> = (node, prm) => {
|
||||||
p.page.render();
|
p.page.render();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="focus hidden absolute left-0 bottom-0 top-0 w-[4px] bg-blue-500"></div>
|
{active.item_id === item.id && (
|
||||||
|
<div
|
||||||
|
className={cx("absolute left-0 bottom-0 top-0 w-[4px] bg-blue-500")}
|
||||||
|
></div>
|
||||||
|
)}
|
||||||
{local.rightClick && (
|
{local.rightClick && (
|
||||||
<EdTreeCtxMenu
|
<EdTreeCtxMenu
|
||||||
node={node}
|
node={node}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue