This commit is contained in:
rizrmd 2024-05-28 20:10:29 +07:00
parent b33b7c3db6
commit 6b89a9cafa
14 changed files with 183 additions and 116 deletions

File diff suppressed because one or more lines are too long

View File

@ -111,12 +111,14 @@ export const parseTypeDef = async (path: string) => {
const result = {} as Record<string, "const" | "type">; const result = {} as Record<string, "const" | "type">;
const traverse = (items: SingleExport[]) => { const traverse = (items: SingleExport[]) => {
for (const item of items) { if (typeof items === "object") {
if (item.type === "all") { for (const item of items) {
const found = exports[item.val]; if (item.type === "all") {
traverse(found); const found = exports[item.val];
} else { traverse(found);
result[item.val] = item.kind; } else {
result[item.val] = item.kind;
}
} }
} }
}; };

View File

@ -89,7 +89,7 @@ declare global {
export type PropVal = export type PropVal =
| { mode: "string"; value: string } | { mode: "string"; value: string }
| { mode: "raw"; value: string; valueBuilt?: string } | { mode: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) }; | { mode: "jsx"; value: null | (IItem & PrasiEdit) | SimpleItem };
type ParentArg = { type ParentArg = {
item: IItem & PrasiEdit; item: IItem & PrasiEdit;

View File

@ -132,6 +132,7 @@ export const edInitSync = (p: PG) => {
} }
if (!p.sync && !p.sync_assigned) { if (!p.sync && !p.sync_assigned) {
p.sync_assigned = true; p.sync_assigned = true;
p.site = deepClone(EmptySite);
clientStartSync({ clientStartSync({
user_id: p.user.id, user_id: p.user.id,
site_id: params.site_id, site_id: params.site_id,

View File

@ -1,5 +1,6 @@
import { NodeModel } from "@minoru/react-dnd-treeview"; import { NodeModel } from "@minoru/react-dnd-treeview";
import { IMeta, PG } from "../../ed-global"; import { IMeta, PG } from "../../ed-global";
import { MItem } from "../../../../../utils/types/item";
export const pushTreeNode = ( export const pushTreeNode = (
p: PG, p: PG,
@ -26,6 +27,20 @@ export const pushTreeNode = (
meta.mitem = mitem; 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, data: meta,
}); });
} else { } else {
if (meta.item.component?.id === "567d5362-2cc8-4ca5-a531-f771a5c866c2") {
console.log(meta);
}
if (meta.jsx_prop) { if (meta.jsx_prop) {
if (meta.jsx_prop.is_root) { if (meta.jsx_prop.is_root) {
if (meta.jsx_prop.name !== "child") { if (meta.jsx_prop.name !== "child") {
@ -58,7 +77,8 @@ export const pushTreeNode = (
} else { } else {
if (meta.jsx_prop.name === "child" && meta.parent.instance_id) { if (meta.jsx_prop.name === "child" && meta.parent.instance_id) {
const comp_meta = metas[meta.parent.instance_id] as IMeta; 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) { if (child_id && comp_meta.mitem) {
const child_meta = metas[child_id]; const child_meta = metas[child_id];
if (child_meta.item.childs.find((e) => meta.item.id === e.id)) { if (child_meta.item.childs.find((e) => meta.item.id === e.id)) {

View File

@ -1,6 +1,6 @@
import { FC } from "react"; import { FC } from "react";
import { EDGlobal, IMeta, active } from "../../logic/ed-global"; 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 { IItem } from "../../../../utils/types/item";
import { EdSidePropComp } from "./prop-master"; import { EdSidePropComp } from "./prop-master";
import { EdStyleAll } from "./style/side-all"; import { EdStyleAll } from "./style/side-all";
@ -8,6 +8,7 @@ import { Popover } from "../../../../utils/ui/popover";
export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => { export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => {
const p = useGlobal(EDGlobal, "EDITOR"); const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal({ value: "" });
const item = meta?.item as IItem; const item = meta?.item as IItem;
if (!item) return null; if (!item) return null;
@ -36,7 +37,7 @@ export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => {
` `
)} )}
spellCheck={false} spellCheck={false}
value={JSON.stringify(meta.item, null, 2)} value={local.value}
></textarea> ></textarea>
} }
> >
@ -67,6 +68,7 @@ export const EdSideStyle: FC<{ meta: IMeta }> = ({ meta }) => {
className="border px-1 cursor-pointer bg-white hover:bg-blue-100" className="border px-1 cursor-pointer bg-white hover:bg-blue-100"
onClick={() => { onClick={() => {
p.ui.side.prop = true; p.ui.side.prop = true;
local.value = JSON.stringify(meta.item, null, 2);
p.render(); p.render();
}} }}
> >

View File

@ -100,24 +100,26 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
}, },
}); });
for (const child of Object.values(item.childs)) { if (item.childs) {
if (child?.name?.startsWith("jsx:")) continue; for (const child of Object.values(item.childs)) {
if (child?.name?.startsWith("jsx:")) continue;
if (child && Object.keys(child).length > 3) { if (child && Object.keys(child).length > 3) {
genMeta( genMeta(
{ ...p, mode: "comp" }, { ...p, mode: "comp" },
{ {
item: child, item: child,
is_root: false, is_root: false,
root: arg.root || arg.item, root: arg.root || arg.item,
parent: { parent: {
item, item,
instance_id: item.id, instance_id: item.id,
root_instances: instances, root_instances: instances,
comp: item_comp, comp: item_comp,
}, },
} }
); );
}
} }
} }
} }

View File

@ -1,3 +1,4 @@
import { createId } from "@paralleldrive/cuid2";
import { IItem, MItem } from "../../../../utils/types/item"; import { IItem, MItem } from "../../../../utils/types/item";
import { FNCompDef } from "../../../../utils/types/meta-fn"; import { FNCompDef } from "../../../../utils/types/meta-fn";
import { IMeta } from "../../utils/types"; import { IMeta } from "../../utils/types";
@ -14,7 +15,7 @@ type SingleChange =
export type PropVal = export type PropVal =
| { mode: "string"; value: string } | { mode: "string"; value: string }
| { mode: "raw"; value: string; valueBuilt?: string } | { mode: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) }; | { mode: "jsx"; value: null | (IItem & PrasiEdit) | SimpleItem };
type ParentArg = { type ParentArg = {
item: IItem & PrasiEdit; item: IItem & PrasiEdit;
@ -132,8 +133,13 @@ export const devItem = (
const mitem = meta.mitem; const mitem = meta.mitem;
const item = mitem.toJSON(); const item = mitem.toJSON();
if (item) { if (item && item.component) {
const props = item?.component?.props as Record<string, FNCompDef>; const props = item?.component?.props as Record<string, FNCompDef>;
if (!props) {
console.log(item, props);
return;
}
const src = {} as Record<string, string>; const src = {} as Record<string, string>;
for (const c of changes) { for (const c of changes) {
if (c.type === "prop" && props) { if (c.type === "prop" && props) {
@ -155,10 +161,23 @@ export const devItem = (
} as any; } as any;
} }
if (c.value) { if (c.value) {
props[c.name].content = removeEditFromChilds( if (props[c.name]?.content) {
[c.value], props[c.name].content = {
compile ...(props[c.name].content as any),
)[0]; 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,11 +187,32 @@ export const devItem = (
item[k] = v; item[k] = v;
} }
} else if (c.type === "child" && Array.isArray(c.childs)) { } else if (c.type === "child" && Array.isArray(c.childs)) {
const childs = removeEditFromChilds( if (item.component?.id) {
c.childs.filter((e) => e), if (!item.component.props) {
compile item.component.props = {};
); }
item.childs = childs;
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
);
item.childs = childs;
}
} }
} }
} }
@ -182,11 +222,14 @@ export const devItem = (
} }
const code_result = await _api.code_build(src); const code_result = await _api.code_build(src);
for (const [k, v] of Object.entries(code_result) as any) {
if (props[k]) { if (props) {
props[k].valueBuilt = v; for (const [k, v] of Object.entries(code_result) as any) {
} else if (compile[k]) { if (props[k]) {
compile[k].valueBuilt = v; props[k].valueBuilt = v;
} else if (compile[k]) {
compile[k].valueBuilt = v;
}
} }
} }
@ -199,7 +242,7 @@ export const devItem = (
const m = metas[k]; const m = metas[k];
if (m.mitem) { if (m.mitem) {
console.log(syncronize(m.mitem as any, v)); syncronize(m.mitem as any, v);
} }
} }
}); });
@ -350,18 +393,33 @@ const removeEditFromChilds = (
const item: any = { ...e }; const item: any = { ...e };
delete item.edit; delete item.edit;
if (item.component?.props) { if (!item.id) {
item.component.props = complexifyProps(item.component.props, compile); item.id = createId();
}
for (const [k, v] of Object.entries(item.component.props) as any) { if (item.component) {
if (!v.valueBuilt && v.value) { if (!item.component.instances) {
compile[item.id + "|||" + k] = v; item.component.instances = {};
}
if (!item.component.ref_ids) {
item.component.ref_ids = {};
}
if (item.component?.props) {
item.component.props = complexifyProps(item.component.props, compile);
for (const [k, v] of Object.entries(item.component.props) as any) {
if (!v.valueBuilt && v.value) {
compile[item.id + "|||" + k] = v;
}
} }
} }
} }
if (item.childs) { if (item.childs) {
item.childs = removeEditFromChilds(item.childs, compile); item.childs = removeEditFromChilds(item.childs, compile);
} else {
item.childs = [];
} }
return item; return item;

View File

@ -44,7 +44,6 @@ export const createViPassProp = (
if (!["children", "key"].includes(k)) { if (!["children", "key"].includes(k)) {
is_changed = true; is_changed = true;
script_pass[k] = v; script_pass[k] = v;
script.passprop[k] = { end: 0, start: 0, value: v };
} }
} }
} }

View File

@ -77,7 +77,7 @@ export const baseTypings = `
export type PropVal = export type PropVal =
| { mode: "string"; value: string } | { mode: "string"; value: string }
| { mode: "raw"; value: string; valueBuilt?: string } | { mode: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) }; | { mode: "jsx"; value: null | (IItem & PrasiEdit) | SimpleItem };
type ParentArg = { type ParentArg = {
item: IItem & PrasiEdit; item: IItem & PrasiEdit;

BIN
bun.lockb

Binary file not shown.

View File

@ -15,14 +15,16 @@ export const prepareApiRoutes = async () => {
try { try {
const api = await import(importPath); const api = await import(importPath);
let args: string[] = await parseArgs(importPath); let args: string[] = await parseArgs(importPath);
const route = { if (api) {
url: api._.url, const route = {
args, url: api._.url,
raw: !!api._.raw, args,
fn: api._.api, raw: !!api._.raw,
path: importPath.substring((root || path).length + 1), fn: api._.api,
}; path: importPath.substring((root || path).length + 1),
g._api[filename] = route; };
g._api[filename] = route;
}
} catch (e) { } catch (e) {
g.log.warn( g.log.warn(
`Failed to import app/srv/api${importPath.substring( `Failed to import app/srv/api${importPath.substring(

View File

@ -5,10 +5,12 @@
"dependencies": { "dependencies": {
"@paralleldrive/cuid2": "2.2.0", "@paralleldrive/cuid2": "2.2.0",
"@types/hash-sum": "^1.0.0", "@types/hash-sum": "^1.0.0",
"decircular": "^1.0.0",
"goober": "^2.1.13", "goober": "^2.1.13",
"hash-sum": "^2.0.0", "hash-sum": "^2.0.0",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0" "react-dom": "18.2.0",
"rfdc": "^1.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "18.0.28", "@types/react": "18.0.28",

View File

@ -1,4 +1,3 @@
import { createId } from "@paralleldrive/cuid2";
import { import {
createContext, createContext,
startTransition, startTransition,
@ -6,7 +5,6 @@ import {
useEffect, useEffect,
useState, useState,
} from "react"; } from "react";
export const GlobalContext = createContext({ export const GlobalContext = createContext({
global: {}, global: {},
render: () => {}, render: () => {},
@ -14,6 +12,7 @@ export const GlobalContext = createContext({
global: Record<string, any>; global: Record<string, any>;
render: (reset?: boolean) => void; render: (reset?: boolean) => void;
}); });
import decircular from "decircular";
export const uState = useState; export const uState = useState;
export const useGlobal = <T extends object>( export const useGlobal = <T extends object>(
@ -52,25 +51,5 @@ export const useGlobal = <T extends object>(
return res as any; 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 = {}; export const deepClone = decircular;
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;
};