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: "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: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
@ -96,12 +97,17 @@ declare global {
child_idx: number;
};
type PrasiEdit = {
type SimpleItem = Partial<Omit<IItem, "component">> & {
component?: { id: string; props: Record<string, PropVal> };
};
export type PrasiEdit = {
edit: {
setValue: <T extends keyof IItem>(name: T, value: IItem[T]) => void;
setProp: (name: string, value: PropVal | string) => void;
pending: SingleChange[];
readonly childs: (IItem & PrasiEdit)[];
childs: (IItem & PrasiEdit)[];
setChilds: (childs: ((IItem & PrasiEdit) | SimpleItem)[]) => void;
readonly parent: null | ParentArg;
commit: () => Promise<void>;
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 { EDGlobal } from "../../../logic/ed-global";
import { apiRef, apiUrl, server } from "./api-utils";
@ -13,15 +13,18 @@ export const EdApiDB = ({
update: () => void;
}) => {
const p = useGlobal(EDGlobal, "EDITOR");
const local = useLocal({ url: db.url });
const api = apiRef[apiUrl(p)];
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
value={db.url}
value={local.url}
className="text-[13px] border p-2 mb-2 "
onChange={(e) => {
db.url = e.currentTarget.value;
p.render();
local.url = e.currentTarget.value;
db.url = local.url;
local.render();
}}
onBlur={async () => {
update();
@ -57,6 +60,7 @@ export const EdApiDB = ({
"api-ts-" + p.site.config.api_url,
Date.now().toString()
);
location.reload();
}}
>
DB Pull
@ -74,6 +78,7 @@ export const EdApiDB = ({
server.status = "ready";
render();
alert("RESTART: OK");
location.reload();
}}
>
Restart Server

View File

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

View File

@ -18,7 +18,7 @@ export const instantiate = (arg: {
newitem.hidden = item.hidden;
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)) {
const cprop = item.component.props[k];
const nprop = newitem.component.props[k];

View File

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

View File

@ -70,39 +70,37 @@ export const baseTypings = `
};
type SingleChange =
| { type: "set"; name: string; value: any }
| ({ type: "prop"; name: string } & PropVal)
| { type: "child"; childs: SimpleItem[] };
| { type: "set"; name: string; value: any }
| ({ type: "prop"; name: string } & PropVal)
| { type: "child"; childs: SimpleItem[] };
export type PropVal =
| { mode: "string"; value: string }
| { mode: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
| { mode: "string"; value: string }
| { mode: "raw"; value: string; valueBuilt?: string }
| { mode: "jsx"; value: null | (IItem & PrasiEdit) };
type ParentArg = {
item: IItem & PrasiEdit;
child_type: "jsx" | "child";
child_idx: number;
item: IItem & PrasiEdit;
child_type: "jsx" | "child";
child_idx: number;
};
type SimpleItem = Partial<Omit<IItem, "component">> & {
component?: { id: string; props: Record<string, PropVal> };
component?: { id: string; props: Record<string, PropVal> };
};
export type PrasiEdit = {
edit: {
setValue: <T extends keyof IItem>(name: T, value: IItem[T]) => void;
setProp: (name: string, value: PropVal | string) => void;
pending: SingleChange[];
childs: (IItem & PrasiEdit)[];
setChilds: (childs: SimpleItem[]) => void;
readonly parent: null | ParentArg;
commit: () => Promise<void>;
readonly props?: Record<string, PropVal>;
edit: {
setValue: <T extends keyof IItem>(name: T, value: IItem[T]) => void;
setProp: (name: string, value: PropVal | string) => void;
pending: SingleChange[];
childs: (IItem & PrasiEdit)[];
setChilds: (childs: ((IItem & PrasiEdit) | SimpleItem)[]) => void;
readonly parent: null | ParentArg;
commit: () => Promise<void>;
readonly props?: Record<string, PropVal>;
};
};
};
type PrasiItem = IItem & PrasiEdit;
const _item: undefined | PrasiItem;

View File

@ -3,7 +3,7 @@
"module": "src/index.ts",
"type": "module",
"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",
"build": "bun run --silent ./pkgs/core/build.ts",
"db-pull": "bun run ./pkgs/core/db-pull.ts",