fix
This commit is contained in:
parent
b33b7c3db6
commit
6b89a9cafa
File diff suppressed because one or more lines are too long
|
|
@ -111,6 +111,7 @@ export const parseTypeDef = async (path: string) => {
|
|||
|
||||
const result = {} as Record<string, "const" | "type">;
|
||||
const traverse = (items: SingleExport[]) => {
|
||||
if (typeof items === "object") {
|
||||
for (const item of items) {
|
||||
if (item.type === "all") {
|
||||
const found = exports[item.val];
|
||||
|
|
@ -119,6 +120,7 @@ export const parseTypeDef = async (path: string) => {
|
|||
result[item.val] = item.kind;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
traverse(exports.index);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ declare global {
|
|||
export type PropVal =
|
||||
| { mode: "string"; value: string }
|
||||
| { mode: "raw"; value: string; valueBuilt?: string }
|
||||
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
|
||||
| { mode: "jsx"; value: null | (IItem & PrasiEdit) | SimpleItem };
|
||||
|
||||
type ParentArg = {
|
||||
item: IItem & PrasiEdit;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ export const edInitSync = (p: PG) => {
|
|||
}
|
||||
if (!p.sync && !p.sync_assigned) {
|
||||
p.sync_assigned = true;
|
||||
p.site = deepClone(EmptySite);
|
||||
clientStartSync({
|
||||
user_id: p.user.id,
|
||||
site_id: params.site_id,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { NodeModel } from "@minoru/react-dnd-treeview";
|
||||
import { IMeta, PG } from "../../ed-global";
|
||||
import { MItem } from "../../../../../utils/types/item";
|
||||
|
||||
export const pushTreeNode = (
|
||||
p: PG,
|
||||
|
|
@ -26,6 +27,20 @@ export const pushTreeNode = (
|
|||
meta.mitem = mitem;
|
||||
}
|
||||
});
|
||||
|
||||
parent.mitem
|
||||
.get("component")
|
||||
?.get("props")
|
||||
?.forEach((v, k) => {
|
||||
if (typeof v === "object") {
|
||||
if ((v as any)?.get("meta")?.get("type") === "content-element") {
|
||||
const mitem = (v as any).get("content") as MItem;
|
||||
if (meta.item.id === mitem.get("id")) {
|
||||
meta.mitem = mitem;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +60,10 @@ export const pushTreeNode = (
|
|||
data: meta,
|
||||
});
|
||||
} else {
|
||||
if (meta.item.component?.id === "567d5362-2cc8-4ca5-a531-f771a5c866c2") {
|
||||
console.log(meta);
|
||||
}
|
||||
|
||||
if (meta.jsx_prop) {
|
||||
if (meta.jsx_prop.is_root) {
|
||||
if (meta.jsx_prop.name !== "child") {
|
||||
|
|
@ -58,7 +77,8 @@ export const pushTreeNode = (
|
|||
} else {
|
||||
if (meta.jsx_prop.name === "child" && meta.parent.instance_id) {
|
||||
const comp_meta = metas[meta.parent.instance_id] as IMeta;
|
||||
const child_id = comp_meta.item.component?.props?.child?.content?.id;
|
||||
const child_id =
|
||||
comp_meta.item.component?.props?.child?.content?.id;
|
||||
if (child_id && comp_meta.mitem) {
|
||||
const child_meta = metas[child_id];
|
||||
if (child_meta.item.childs.find((e) => meta.item.id === e.id)) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { FC } from "react";
|
||||
import { EDGlobal, IMeta, active } from "../../logic/ed-global";
|
||||
import { useGlobal } from "web-utils";
|
||||
import { useGlobal, useLocal } from "web-utils";
|
||||
import { IItem } from "../../../../utils/types/item";
|
||||
import { EdSidePropComp } from "./prop-master";
|
||||
import { EdStyleAll } from "./style/side-all";
|
||||
|
|
@ -8,6 +8,7 @@ import { Popover } from "../../../../utils/ui/popover";
|
|||
|
||||
export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => {
|
||||
const p = useGlobal(EDGlobal, "EDITOR");
|
||||
const local = useLocal({ value: "" });
|
||||
|
||||
const item = meta?.item as IItem;
|
||||
if (!item) return null;
|
||||
|
|
@ -36,7 +37,7 @@ export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => {
|
|||
`
|
||||
)}
|
||||
spellCheck={false}
|
||||
value={JSON.stringify(meta.item, null, 2)}
|
||||
value={local.value}
|
||||
></textarea>
|
||||
}
|
||||
>
|
||||
|
|
@ -67,6 +68,7 @@ export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => {
|
|||
className="border px-1 cursor-pointer bg-white hover:bg-blue-100"
|
||||
onClick={() => {
|
||||
p.ui.side.prop = true;
|
||||
local.value = JSON.stringify(meta.item, null, 2);
|
||||
p.render();
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
|||
},
|
||||
});
|
||||
|
||||
if (item.childs) {
|
||||
for (const child of Object.values(item.childs)) {
|
||||
if (child?.name?.startsWith("jsx:")) continue;
|
||||
|
||||
|
|
@ -122,4 +123,5 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { IItem, MItem } from "../../../../utils/types/item";
|
||||
import { FNCompDef } from "../../../../utils/types/meta-fn";
|
||||
import { IMeta } from "../../utils/types";
|
||||
|
|
@ -14,7 +15,7 @@ type SingleChange =
|
|||
export type PropVal =
|
||||
| { mode: "string"; value: string }
|
||||
| { mode: "raw"; value: string; valueBuilt?: string }
|
||||
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
|
||||
| { mode: "jsx"; value: null | (IItem & PrasiEdit) | SimpleItem };
|
||||
|
||||
type ParentArg = {
|
||||
item: IItem & PrasiEdit;
|
||||
|
|
@ -132,8 +133,13 @@ export const devItem = (
|
|||
|
||||
const mitem = meta.mitem;
|
||||
const item = mitem.toJSON();
|
||||
if (item) {
|
||||
if (item && item.component) {
|
||||
const props = item?.component?.props as Record<string, FNCompDef>;
|
||||
|
||||
if (!props) {
|
||||
console.log(item, props);
|
||||
return;
|
||||
}
|
||||
const src = {} as Record<string, string>;
|
||||
for (const c of changes) {
|
||||
if (c.type === "prop" && props) {
|
||||
|
|
@ -155,10 +161,23 @@ export const devItem = (
|
|||
} as any;
|
||||
}
|
||||
if (c.value) {
|
||||
props[c.name].content = removeEditFromChilds(
|
||||
[c.value],
|
||||
compile
|
||||
)[0];
|
||||
if (props[c.name]?.content) {
|
||||
props[c.name].content = {
|
||||
...(props[c.name].content as any),
|
||||
childs: [
|
||||
removeEditFromChilds([c.value], compile)[0],
|
||||
],
|
||||
};
|
||||
} else {
|
||||
props[c.name].content = {
|
||||
type: "item",
|
||||
id: createId(),
|
||||
name: c.name,
|
||||
childs: [
|
||||
removeEditFromChilds([c.value], compile)[0],
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -168,6 +187,26 @@ export const devItem = (
|
|||
item[k] = v;
|
||||
}
|
||||
} else if (c.type === "child" && Array.isArray(c.childs)) {
|
||||
if (item.component?.id) {
|
||||
if (!item.component.props) {
|
||||
item.component.props = {};
|
||||
}
|
||||
|
||||
item.component.props.child = {
|
||||
meta: { type: "content-element" },
|
||||
content: {
|
||||
type: "item",
|
||||
id: createId(),
|
||||
name: "child",
|
||||
childs: [
|
||||
removeEditFromChilds(
|
||||
c.childs.filter((e) => e),
|
||||
compile
|
||||
)[0],
|
||||
],
|
||||
},
|
||||
};
|
||||
} else {
|
||||
const childs = removeEditFromChilds(
|
||||
c.childs.filter((e) => e),
|
||||
compile
|
||||
|
|
@ -176,12 +215,15 @@ export const devItem = (
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const [k, v] of Object.entries(compile)) {
|
||||
src[k] = v.value;
|
||||
}
|
||||
|
||||
const code_result = await _api.code_build(src);
|
||||
|
||||
if (props) {
|
||||
for (const [k, v] of Object.entries(code_result) as any) {
|
||||
if (props[k]) {
|
||||
props[k].valueBuilt = v;
|
||||
|
|
@ -189,6 +231,7 @@ export const devItem = (
|
|||
compile[k].valueBuilt = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result[item_id] = item;
|
||||
}
|
||||
|
|
@ -199,7 +242,7 @@ export const devItem = (
|
|||
const m = metas[k];
|
||||
|
||||
if (m.mitem) {
|
||||
console.log(syncronize(m.mitem as any, v));
|
||||
syncronize(m.mitem as any, v);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -350,6 +393,18 @@ const removeEditFromChilds = (
|
|||
const item: any = { ...e };
|
||||
delete item.edit;
|
||||
|
||||
if (!item.id) {
|
||||
item.id = createId();
|
||||
}
|
||||
|
||||
if (item.component) {
|
||||
if (!item.component.instances) {
|
||||
item.component.instances = {};
|
||||
}
|
||||
if (!item.component.ref_ids) {
|
||||
item.component.ref_ids = {};
|
||||
}
|
||||
|
||||
if (item.component?.props) {
|
||||
item.component.props = complexifyProps(item.component.props, compile);
|
||||
|
||||
|
|
@ -359,9 +414,12 @@ const removeEditFromChilds = (
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.childs) {
|
||||
item.childs = removeEditFromChilds(item.childs, compile);
|
||||
} else {
|
||||
item.childs = [];
|
||||
}
|
||||
|
||||
return item;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ export const createViPassProp = (
|
|||
if (!["children", "key"].includes(k)) {
|
||||
is_changed = true;
|
||||
script_pass[k] = v;
|
||||
script.passprop[k] = { end: 0, start: 0, value: v };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ export const baseTypings = `
|
|||
export type PropVal =
|
||||
| { mode: "string"; value: string }
|
||||
| { mode: "raw"; value: string; valueBuilt?: string }
|
||||
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
|
||||
| { mode: "jsx"; value: null | (IItem & PrasiEdit) | SimpleItem };
|
||||
|
||||
type ParentArg = {
|
||||
item: IItem & PrasiEdit;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export const prepareApiRoutes = async () => {
|
|||
try {
|
||||
const api = await import(importPath);
|
||||
let args: string[] = await parseArgs(importPath);
|
||||
if (api) {
|
||||
const route = {
|
||||
url: api._.url,
|
||||
args,
|
||||
|
|
@ -23,6 +24,7 @@ export const prepareApiRoutes = async () => {
|
|||
path: importPath.substring((root || path).length + 1),
|
||||
};
|
||||
g._api[filename] = route;
|
||||
}
|
||||
} catch (e) {
|
||||
g.log.warn(
|
||||
`Failed to import app/srv/api${importPath.substring(
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@
|
|||
"dependencies": {
|
||||
"@paralleldrive/cuid2": "2.2.0",
|
||||
"@types/hash-sum": "^1.0.0",
|
||||
"decircular": "^1.0.0",
|
||||
"goober": "^2.1.13",
|
||||
"hash-sum": "^2.0.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
"react-dom": "18.2.0",
|
||||
"rfdc": "^1.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "18.0.28",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { createId } from "@paralleldrive/cuid2";
|
||||
import {
|
||||
createContext,
|
||||
startTransition,
|
||||
|
|
@ -6,7 +5,6 @@ import {
|
|||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
export const GlobalContext = createContext({
|
||||
global: {},
|
||||
render: () => {},
|
||||
|
|
@ -14,6 +12,7 @@ export const GlobalContext = createContext({
|
|||
global: Record<string, any>;
|
||||
render: (reset?: boolean) => void;
|
||||
});
|
||||
import decircular from "decircular";
|
||||
|
||||
export const uState = useState;
|
||||
export const useGlobal = <T extends object>(
|
||||
|
|
@ -52,25 +51,5 @@ export const useGlobal = <T extends object>(
|
|||
|
||||
return res as any;
|
||||
};
|
||||
export const deepClone = <T extends object>(object: T): T => {
|
||||
if (null == object || typeof object != "object") return object;
|
||||
// Handle Date
|
||||
if (object instanceof Date) {
|
||||
var copy = new Date();
|
||||
copy.setTime(object.getTime());
|
||||
return copy as T;
|
||||
}
|
||||
if (object instanceof Array) {
|
||||
return object.map((item) => deepClone(item)) as T;
|
||||
}
|
||||
|
||||
var newObject: any = {};
|
||||
for (var key in object) {
|
||||
if (typeof object[key] === "object") {
|
||||
newObject[key] = deepClone((object as any)[key]);
|
||||
} else {
|
||||
newObject[key] = object[key];
|
||||
}
|
||||
}
|
||||
return newObject as any;
|
||||
};
|
||||
export const deepClone = decircular;
|
||||
|
|
|
|||
Loading…
Reference in New Issue