This commit is contained in:
rizrmd 2024-05-24 19:18:13 +07:00
parent 537999cb64
commit b6b849d902
9 changed files with 56 additions and 44 deletions

File diff suppressed because one or more lines are too long

View File

@ -83,9 +83,10 @@ declare global {
type SingleChange = type SingleChange =
| { type: "set"; name: string; value: any } | { type: "set"; name: string; value: any }
| ({ type: "prop"; name: string } & PropVal); | ({ type: "prop"; name: string } & PropVal)
| { type: "child"; childs: SimpleItem[] };
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) };
@ -96,12 +97,17 @@ declare global {
child_idx: number; child_idx: number;
}; };
type PrasiEdit = { type SimpleItem = Partial<Omit<IItem, "component">> & {
component?: { id: string; props: Record<string, PropVal> };
};
export type PrasiEdit = {
edit: { edit: {
setValue: <T extends keyof IItem>(name: T, value: IItem[T]) => void; setValue: <T extends keyof IItem>(name: T, value: IItem[T]) => void;
setProp: (name: string, value: PropVal | string) => void; setProp: (name: string, value: PropVal | string) => void;
pending: SingleChange[]; pending: SingleChange[];
readonly childs: (IItem & PrasiEdit)[]; childs: (IItem & PrasiEdit)[];
setChilds: (childs: ((IItem & PrasiEdit) | SimpleItem)[]) => void;
readonly parent: null | ParentArg; readonly parent: null | ParentArg;
commit: () => Promise<void>; commit: () => Promise<void>;
readonly props?: Record<string, PropVal>; readonly props?: Record<string, PropVal>;

View File

@ -1,4 +1,4 @@
import { useGlobal } from "web-utils"; import { useGlobal, useLocal } from "web-utils";
import { AutoHeightTextarea } from "../../../../../utils/ui/auto-textarea"; import { AutoHeightTextarea } from "../../../../../utils/ui/auto-textarea";
import { EDGlobal } from "../../../logic/ed-global"; import { EDGlobal } from "../../../logic/ed-global";
import { apiRef, apiUrl, server } from "./api-utils"; import { apiRef, apiUrl, server } from "./api-utils";
@ -13,15 +13,18 @@ export const EdApiDB = ({
update: () => void; update: () => void;
}) => { }) => {
const p = useGlobal(EDGlobal, "EDITOR"); const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal({ url: db.url });
const api = apiRef[apiUrl(p)]; const api = apiRef[apiUrl(p)];
return ( return (
<div className="flex border-b py-2 px-2 border-slate-300 boxed flex flex-col items-stretch"> <div className="flex border-b py-2 px-2 border-slate-300 boxed flex-col items-stretch">
<AutoHeightTextarea <AutoHeightTextarea
value={db.url} value={local.url}
className="text-[13px] border p-2 mb-2 " className="text-[13px] border p-2 mb-2 "
onChange={(e) => { onChange={(e) => {
db.url = e.currentTarget.value; local.url = e.currentTarget.value;
p.render(); db.url = local.url;
local.render();
}} }}
onBlur={async () => { onBlur={async () => {
update(); update();
@ -57,6 +60,7 @@ export const EdApiDB = ({
"api-ts-" + p.site.config.api_url, "api-ts-" + p.site.config.api_url,
Date.now().toString() Date.now().toString()
); );
location.reload();
}} }}
> >
DB Pull DB Pull
@ -74,6 +78,7 @@ export const EdApiDB = ({
server.status = "ready"; server.status = "ready";
render(); render();
alert("RESTART: OK"); alert("RESTART: OK");
location.reload();
}} }}
> >
Restart Server Restart Server

View File

@ -62,10 +62,12 @@ export const initLoadComp = async (
} }
for (const component of comps) { for (const component of comps) {
if (component.props) {
for (const prop of Object.values(component.props)) { for (const prop of Object.values(component.props)) {
if (prop.meta?.type === "content-element" && prop.content) { if (prop.meta?.type === "content-element" && prop.content) {
await initLoadComp(p, prop.content, opt, loaded); await initLoadComp(p, prop.content, opt, loaded);
} }
} }
} }
}
}; };

View File

@ -18,7 +18,7 @@ export const instantiate = (arg: {
newitem.hidden = item.hidden; newitem.hidden = item.hidden;
if (newitem.component) { if (newitem.component) {
if (newitem.component.props && item.component) { if (newitem.component.props && item.component && item.component.props) {
for (const k of Object.keys(newitem.component.props)) { for (const k of Object.keys(newitem.component.props)) {
const cprop = item.component.props[k]; const cprop = item.component.props[k];
const nprop = newitem.component.props[k]; const nprop = newitem.component.props[k];

View File

@ -9,7 +9,7 @@ const w = window as unknown as {
type SingleChange = type SingleChange =
| { type: "set"; name: string; value: any } | { type: "set"; name: string; value: any }
| ({ type: "prop"; name: string } & PropVal) | ({ type: "prop"; name: string } & PropVal)
| { type: "child"; childs: SimpleItem[] }; | { type: "child"; childs: ((IItem & PrasiEdit) | SimpleItem)[] };
export type PropVal = export type PropVal =
| { mode: "string"; value: string } | { mode: "string"; value: string }
@ -32,7 +32,7 @@ export type PrasiEdit = {
setProp: (name: string, value: PropVal | string) => void; setProp: (name: string, value: PropVal | string) => void;
pending: SingleChange[]; pending: SingleChange[];
childs: (IItem & PrasiEdit)[]; childs: (IItem & PrasiEdit)[];
setChilds: (childs: SimpleItem[]) => void; setChilds: (childs: ((IItem & PrasiEdit) | SimpleItem)[]) => void;
readonly parent: null | ParentArg; readonly parent: null | ParentArg;
commit: () => Promise<void>; commit: () => Promise<void>;
readonly props?: Record<string, PropVal>; readonly props?: Record<string, PropVal>;
@ -197,8 +197,9 @@ export const devItem = (
mitem.doc?.transact(() => { mitem.doc?.transact(() => {
for (const [k, v] of Object.entries(result)) { for (const [k, v] of Object.entries(result)) {
const m = metas[k]; const m = metas[k];
if (m.mitem) { if (m.mitem) {
syncronize(m.mitem as any, v); console.log(syncronize(m.mitem as any, v));
} }
} }
}); });
@ -306,7 +307,7 @@ export const devItem = (
} as IItem & PrasiEdit; } as IItem & PrasiEdit;
}; };
const complexifyProps = async ( const complexifyProps = (
props: Record<string, PropVal>, props: Record<string, PropVal>,
compileValueBuilt: Record<string, { value: string; valueBuilt?: string }> compileValueBuilt: Record<string, { value: string; valueBuilt?: string }>
) => { ) => {

View File

@ -95,15 +95,13 @@ export const baseTypings = `
setProp: (name: string, value: PropVal | string) => void; setProp: (name: string, value: PropVal | string) => void;
pending: SingleChange[]; pending: SingleChange[];
childs: (IItem & PrasiEdit)[]; childs: (IItem & PrasiEdit)[];
setChilds: (childs: SimpleItem[]) => void; setChilds: (childs: ((IItem & PrasiEdit) | SimpleItem)[]) => void;
readonly parent: null | ParentArg; readonly parent: null | ParentArg;
commit: () => Promise<void>; commit: () => Promise<void>;
readonly props?: Record<string, PropVal>; readonly props?: Record<string, PropVal>;
}; };
}; };
type PrasiItem = IItem & PrasiEdit;
const _item: undefined | PrasiItem; const _item: undefined | PrasiItem;
const PassProp: (arg:Record<string, any> & { children: ReactNode }>) => ReactElement; const PassProp: (arg:Record<string, any> & { children: ReactNode }>) => ReactElement;

View File

@ -3,7 +3,7 @@
"module": "src/index.ts", "module": "src/index.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "bun run --hot ./pkgs/core/index.ts dev", "dev": "bun run --no-clear-screen --hot ./pkgs/core/index.ts dev",
"clean": "rm -rf data/lmdb && rm -rf app/static && rm -rf app/web/.parcel-cache", "clean": "rm -rf data/lmdb && rm -rf app/static && rm -rf app/web/.parcel-cache",
"build": "bun run --silent ./pkgs/core/build.ts", "build": "bun run --silent ./pkgs/core/build.ts",
"db-pull": "bun run ./pkgs/core/db-pull.ts", "db-pull": "bun run ./pkgs/core/db-pull.ts",