added minimal astro adapter + improved the example

This commit is contained in:
dswbx
2024-11-29 21:21:59 +01:00
parent 6eb0d2242f
commit 582dbd4272
11 changed files with 301 additions and 35 deletions

View File

@@ -179,3 +179,8 @@ await tsup.build({
platform: "node",
format: ["esm", "cjs"]
});
await tsup.build({
...baseConfig("astro"),
format: ["esm", "cjs"]
});

View File

@@ -160,6 +160,11 @@
"import": "./dist/adapter/node/index.js",
"require": "./dist/adapter/node/index.cjs"
},
"./adapter/astro": {
"types": "./dist/adapter/astro/index.d.ts",
"import": "./dist/adapter/astro/index.js",
"require": "./dist/adapter/astro/index.cjs"
},
"./dist/styles.css": "./dist/ui/main.css",
"./dist/manifest.json": "./dist/static/manifest.json"
},

View File

@@ -0,0 +1,21 @@
import { Api, type ApiOptions } from "bknd";
type TAstro = {
request: {
url: string;
headers: Headers;
};
};
export type Options = {
mode?: "static" | "dynamic";
} & Omit<ApiOptions, "host"> & {
host?: string;
};
export function getApi(Astro: TAstro, options: Options = { mode: "static" }) {
return new Api({
host: new URL(Astro.request.url).origin,
headers: options.mode === "dynamic" ? Astro.request.headers : undefined
});
}

View File

@@ -0,0 +1 @@
export * from "./astro.adapter";

View File

@@ -135,10 +135,10 @@ type FormInputElement = HTMLInputElement | HTMLTextAreaElement;
function EntityFormField({ fieldApi, field, action, data, ...props }: EntityFormFieldProps) {
const handleUpdate = useEvent((e: React.ChangeEvent<FormInputElement> | any) => {
if (typeof e === "object" && "target" in e) {
console.log("handleUpdate", e.target.value);
//console.log("handleUpdate", e.target.value);
fieldApi.handleChange(e.target.value);
} else {
console.log("handleUpdate-", e);
//console.log("handleUpdate-", e);
fieldApi.handleChange(e);
}
});