import type { JSONSchema } from "json-schema-to-ts"; import { useBknd } from "ui/client/bknd"; import { Button } from "ui/components/buttons/Button"; import { s } from "bknd/utils"; import { AnyOf, AnyOfField, Field, Form, FormContextOverride, FormDebug, ObjectField, useFormError, } from "ui/components/form/json-schema-form"; import { Scrollable } from "ui/layouts/AppShell/AppShell"; const schema2 = { type: "object", properties: { name: { type: "string", default: "Peter" }, age: { type: "number" }, gender: { type: "string", enum: ["male", "female", "uni"], }, deep: { type: "object", properties: { nested: { type: "string" }, }, }, }, required: ["age"], } as const satisfies JSONSchema; const authSchema = { type: "object", properties: { what: { type: "array", items: { type: "string", }, }, jwt: { type: "object", properties: { fields: { type: "array", items: { type: "string", }, }, }, }, }, } as const satisfies JSONSchema; const objectCodeSchema = { type: "object", properties: { name: { type: "string" }, config: { type: "object", properties: {} }, }, }; const formOptions = { debug: true, }; export default function JsonSchemaForm3() { const { schema: _schema, config } = useBknd(); const schema = JSON.parse(JSON.stringify(_schema)); config.media.storage.body_max_size = 1; schema.media.properties.storage.properties.body_max_size.minimum = 0; schema.media.if = { properties: { enabled: { const: true } } }; // biome-ignore lint/suspicious/noThenProperty: schema.media.then = { required: ["adapter"] }; //schema.media.properties.adapter.anyOf[2].properties.config.properties.path.minLength = 1; return (
{/*
*/} {/* */} {/* console.log("change", data)} onSubmit={(data) => console.log("submit", data)} schema={{ type: "object", properties: { name: { type: "string", default: "Peter", maxLength: 3 }, age: { type: "number" }, deep: { type: "object", properties: { nested: { type: "string" } } } }, required: ["age"], additionalProperties: false }} initialValues={{ name: "Peter", age: 20, deep: { nested: "hello" } }} className="flex flex-col gap-3" validateOn="change" options={{ debug: true }} />*/} {/* {(state) => (
                        {JSON.stringify(state, null, 2)}
                     
)}
*/} {/*
random thing

({ dirty: state.dirty, submitting: state.submitting })} > {(state) => (
                        {JSON.stringify(state)}
                     
)}
*/} {/*
*/} {/*
*/} {/*
*/} {/*
*/} {/**/} {/*
*/} {/* */} {/*
*/} {/*
*/}
); } const ss = { type: "object", properties: { name: { type: "string" }, email: { type: "string", format: "email" }, interested: { type: "boolean" }, bla: { type: "string", enum: ["small", "medium", "large"], }, password: { type: "string", format: "password" }, birthdate: { type: "string", format: "date" }, dinnerTime: { type: "string", format: "date-time" }, age: { type: "number", minimum: 0, multipleOf: 5 }, tags: { type: "array", items: { type: "string", }, }, config: { type: "object", properties: { min: { type: "number" }, }, }, }, required: ["name"], additionalProperties: false, } as const satisfies JSONSchema; function CustomMediaForm() { const { schema: _schema, config } = useBknd(); const schema = JSON.parse(JSON.stringify(_schema)); config.media.storage.body_max_size = 1; schema.media.properties.storage.properties.body_max_size.minimum = 0; schema.media.if = { properties: { enabled: { const: true } } }; // biome-ignore lint/suspicious/noThenProperty: schema.media.then = { required: ["adapter"] }; return ( ); } const Test = () => { const errors = useFormError("", { strict: true }); return
{errors.map((e) => e.message).join("\n")}
; //return
{JSON.stringify(errors, null, 2)}
; }; function CustomMediaFormAdapter() { const ctx = AnyOf.useContext(); return ( <>
{ctx.schemas?.map((schema: any, i) => ( ))}
{ctx.selected !== null && ( )} ); }