added format command and added trailing commas to reduce conflicts

This commit is contained in:
dswbx
2025-02-26 20:06:03 +01:00
parent 88b5359f1c
commit 7743f71a11
414 changed files with 3622 additions and 3610 deletions
@@ -39,7 +39,7 @@ const Root = ({ path = "", children }: AnyOfFieldRootProps) => {
lib,
pointer,
value: { matchedIndex, schemas },
schema
schema,
} = useDerivedFieldContext(path, (ctx) => {
const [matchedIndex, schemas = []] = getMultiSchemaMatched(ctx.schema, ctx.value);
return { matchedIndex, schemas };
@@ -58,7 +58,7 @@ const Root = ({ path = "", children }: AnyOfFieldRootProps) => {
const options = schemas.map((s, i) => s.title ?? `Option ${i + 1}`);
const selectSchema = {
type: "string",
enum: options
enum: options,
} satisfies JsonSchema;
const selectedSchema = selected !== null ? (schemas[selected] as JsonSchema) : undefined;
@@ -69,7 +69,7 @@ const Root = ({ path = "", children }: AnyOfFieldRootProps) => {
selectedSchema,
schema,
schemas,
selected
selected,
};
}, [selected]);
@@ -80,7 +80,7 @@ const Root = ({ path = "", children }: AnyOfFieldRootProps) => {
...context,
select,
path,
errors
errors,
}}
>
{children}
@@ -130,7 +130,7 @@ export const AnyOf = {
Root,
Select,
Field,
useContext: useAnyOfContext
useContext: useAnyOfContext,
};
export const AnyOfField = (props: Omit<AnyOfFieldRootProps, "children">) => {
@@ -72,7 +72,7 @@ const ArrayItem = memo(({ path, index, schema }: any) => {
const DeleteButton = useMemo(
() => <IconButton Icon={IconTrash} onClick={() => handleDelete(itemPath)} size="sm" />,
[itemPath]
[itemPath],
);
return (
@@ -95,7 +95,7 @@ const ArrayIterator = memo(
({ name, children }: any) => {
return children(useFormValue(name));
},
(prev, next) => prev.value?.length === next.value?.length
(prev, next) => prev.value?.length === next.value?.length,
);
const ArrayAdd = ({ schema, path }: { schema: JsonSchema; path: string }) => {
@@ -117,11 +117,11 @@ const ArrayAdd = ({ schema, path }: { schema: JsonSchema; path: string }) => {
return (
<Dropdown
dropdownWrapperProps={{
className: "min-w-0"
className: "min-w-0",
}}
items={itemsMultiSchema.map((s, i) => ({
label: s!.title ?? `Option ${i + 1}`,
onClick: () => handleAdd(ctx.lib.getTemplate(undefined, s!))
onClick: () => handleAdd(ctx.lib.getTemplate(undefined, s!)),
}))}
onClickItem={console.log}
>
@@ -92,7 +92,9 @@ export const FieldComponent = ({
// allow override
value: typeof _props.value !== "undefined" ? _props.value : value,
placeholder:
(_props.placeholder ?? typeof schema.default !== "undefined") ? String(schema.default) : ""
(_props.placeholder ?? typeof schema.default !== "undefined")
? String(schema.default)
: "",
};
if (schema.enum) {
@@ -103,7 +105,7 @@ export const FieldComponent = ({
const additional = {
min: schema.minimum,
max: schema.maximum,
step: schema.multipleOf
step: schema.multipleOf,
};
return (
@@ -133,7 +135,7 @@ export const FieldComponent = ({
const date = new Date(e.target.value);
props.onChange?.({
// @ts-ignore
target: { value: date.toISOString() }
target: { value: date.toISOString() },
});
}}
/>
@@ -147,7 +149,7 @@ export const FieldComponent = ({
const additional = {
maxLength: schema.maxLength,
minLength: schema.minLength,
pattern: schema.pattern
pattern: schema.pattern,
} as any;
if (schema.format) {
@@ -7,7 +7,7 @@ import * as Formy from "ui/components/form/Formy";
import {
useFormContext,
useFormError,
useFormValue
useFormValue,
} from "ui/components/form/json-schema-form/Form";
import { Popover } from "ui/components/overlay/Popover";
import { getLabel } from "./utils";
@@ -79,7 +79,7 @@ export function FieldWrapper({
{Children.count(children) === 1 && isValidElement(children)
? cloneElement(children, {
// @ts-ignore
list: examples.length > 0 ? examplesId : undefined
list: examples.length > 0 ? examplesId : undefined,
})
: children}
{examples.length > 0 && (
@@ -100,7 +100,7 @@ export function FieldWrapper({
const FieldDebug = ({
name,
schema,
required
required,
}: Pick<FieldwrapperProps, "name" | "schema" | "required">) => {
const { options } = useFormContext();
if (!options?.debug) return null;
@@ -111,7 +111,7 @@ const FieldDebug = ({
<div className="absolute top-0 right-0">
<Popover
overlayProps={{
className: "max-w-none"
className: "max-w-none",
}}
position="bottom-end"
target={({ toggle }) => (
@@ -122,7 +122,7 @@ const FieldDebug = ({
value,
required,
schema,
errors
errors,
}}
expand={6}
/>
@@ -4,7 +4,7 @@ import {
getDefaultStore,
useAtom,
useAtomValue,
useSetAtom
useSetAtom,
} from "jotai";
import { selectAtom } from "jotai/utils";
import { Draft2019, type JsonError, type JsonSchema as LibJsonSchema } from "json-schema-library";
@@ -20,7 +20,7 @@ import {
useContext,
useEffect,
useMemo,
useRef
useRef,
} from "react";
import { JsonViewer } from "ui/components/code/JsonViewer";
import { useEvent } from "ui/hooks/use-event";
@@ -32,7 +32,7 @@ import {
omitSchema,
pathToPointer,
prefixPath,
prefixPointer
prefixPointer,
} from "./utils";
export type JSONSchema = Exclude<$JSONSchema, boolean>;
@@ -67,7 +67,7 @@ FormContext.displayName = "FormContext";
export function Form<
const Schema extends JSONSchema,
const Data = Schema extends JSONSchema ? FromSchema<Schema> : any
const Data = Schema extends JSONSchema ? FromSchema<Schema> : any,
>({
schema: _schema,
initialValues: _initialValues,
@@ -101,7 +101,7 @@ export function Form<
dirty: false,
submitting: false,
errors: [] as JsonError[],
data: initialValues
data: initialValues,
});
}, [initialValues]);
const setFormState = useSetAtom(_formStateAtom);
@@ -188,9 +188,9 @@ export function Form<
lib,
options,
root: "",
path: ""
path: "",
}),
[schema, initialValues]
[schema, initialValues],
) as any;
return (
@@ -236,7 +236,7 @@ export function FormContextOverride({
const context = {
...ctx,
...overrides,
...additional
...additional,
};
console.log("context", context);
@@ -256,12 +256,12 @@ export function useFormValue(name: string, opts?: { strict?: boolean }) {
const pointer = pathToPointer(prefixedName);
return {
value: getPath(state.data, prefixedName),
errors: state.errors.filter((error) => error.data.pointer.startsWith(pointer))
errors: state.errors.filter((error) => error.data.pointer.startsWith(pointer)),
};
},
[name]
[name],
),
isEqual
isEqual,
);
return useAtom(selected)[0];
}
@@ -280,16 +280,16 @@ export function useFormError(name: string, opt?: { strict?: boolean; debug?: boo
: error.data.pointer.startsWith(pointer);
});
},
[name]
[name],
),
isEqual
isEqual,
);
return useAtom(selected)[0];
}
export function useFormStateSelector<Data = any, Reduced = Data>(
selector: (state: FormState<Data>) => Reduced,
deps: any[] = []
deps: any[] = [],
): Reduced {
const { _formStateAtom } = useFormContext();
const selected = selectAtom(_formStateAtom, useCallback(selector, deps), isEqual);
@@ -309,7 +309,7 @@ export function useDerivedFieldContext<Data = any, Reduced = undefined>(
},
Reduced
>,
_schema?: JSONSchema
_schema?: JSONSchema,
): FormContext<Data> & {
value: Reduced;
pointer: string;
@@ -338,29 +338,29 @@ export function useDerivedFieldContext<Data = any, Reduced = undefined>(
root,
schema: fieldSchema as LibJsonSchema,
pointer,
required
required,
};
const derived = deriveFn?.({ ...context, _formStateAtom, lib, value });
return {
...context,
value: derived
value: derived,
};
},
[path, schema ?? {}, root]
[path, schema ?? {}, root],
),
isEqual
isEqual,
);
return {
...useAtomValue(selected),
_formStateAtom,
lib
lib,
} as any;
}
export function Subscribe<Data = any, Refined = Data>({
children,
selector
selector,
}: {
children: (state: Refined) => ReactNode;
selector?: SelectorFn<FormState<Data>, Refined>;
@@ -102,7 +102,7 @@ export function getMultiSchema(schema: JsonSchema): JsonSchema[] | undefined {
export function getMultiSchemaMatched(
schema: JsonSchema,
data: any
data: any,
): [number, JsonSchema[], JsonSchema | undefined] {
const multiSchema = getMultiSchema(schema);
//console.log("getMultiSchemaMatched", schema, data, multiSchema);
@@ -124,7 +124,7 @@ export function omitSchema<Given extends JSONSchema>(_schema: Given, keys: strin
const updated = {
...schema,
properties: omitKeys(schema.properties, keys)
properties: omitKeys(schema.properties, keys),
};
if (updated.required) {
updated.required = updated.required.filter((key) => !keys.includes(key as any));