@overmap-ai/forms 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +12 -0
  2. package/dist/builder/DropDispatch.d.ts +27 -0
  3. package/dist/builder/FieldActions.d.ts +11 -0
  4. package/dist/builder/FieldBuilder.d.ts +22 -0
  5. package/dist/builder/FieldSectionWithActions.d.ts +10 -0
  6. package/dist/builder/FieldWithActions.d.ts +10 -0
  7. package/dist/builder/FieldsEditor.d.ts +2 -0
  8. package/dist/builder/FormBuilder.d.ts +15 -0
  9. package/dist/builder/constants.d.ts +1 -0
  10. package/dist/builder/index.d.ts +2 -0
  11. package/dist/builder/typings.d.ts +11 -0
  12. package/dist/builder/utils.d.ts +11 -0
  13. package/dist/fields/BaseField/BaseField.d.ts +32 -0
  14. package/dist/fields/BaseField/hooks.d.ts +374 -0
  15. package/dist/fields/BaseField/index.d.ts +4 -0
  16. package/dist/fields/BaseField/layouts.d.ts +19 -0
  17. package/dist/fields/BaseField/typings.d.ts +7 -0
  18. package/dist/fields/BooleanField/BooleanInput.d.ts +4 -0
  19. package/dist/fields/BooleanField/index.d.ts +2 -0
  20. package/dist/fields/CustomField/CustomField.d.ts +19 -0
  21. package/dist/fields/CustomField/FieldInputClonerField/FieldInputCloner.d.ts +8 -0
  22. package/dist/fields/CustomField/FieldInputClonerField/FieldInputClonerField.d.ts +18 -0
  23. package/dist/fields/CustomField/FieldInputClonerField/index.d.ts +3 -0
  24. package/dist/fields/CustomField/FieldInputClonerField/typings.d.ts +5 -0
  25. package/dist/fields/CustomField/index.d.ts +1 -0
  26. package/dist/fields/DateField/DateInput.d.ts +4 -0
  27. package/dist/fields/DateField/index.d.ts +2 -0
  28. package/dist/fields/FieldSection/FieldSection.d.ts +29 -0
  29. package/dist/fields/FieldSection/FieldSectionLayout.d.ts +7 -0
  30. package/dist/fields/FieldSection/index.d.ts +1 -0
  31. package/dist/fields/MultiStringField/MultiStringInput.d.ts +8 -0
  32. package/dist/fields/MultiStringField/index.d.ts +2 -0
  33. package/dist/fields/NumberField/NumberInput.d.ts +4 -0
  34. package/dist/fields/NumberField/index.d.ts +2 -0
  35. package/dist/fields/SelectField/BaseSelectField.d.ts +26 -0
  36. package/dist/fields/SelectField/MultiSelectInput.d.ts +4 -0
  37. package/dist/fields/SelectField/SelectInput.d.ts +4 -0
  38. package/dist/fields/SelectField/index.d.ts +4 -0
  39. package/dist/fields/StringOrTextFields/StringField/StringInput.d.ts +4 -0
  40. package/dist/fields/StringOrTextFields/StringField/index.d.ts +2 -0
  41. package/dist/fields/StringOrTextFields/StringOrTextField.d.ts +29 -0
  42. package/dist/fields/StringOrTextFields/TextField/TextInput.d.ts +4 -0
  43. package/dist/fields/StringOrTextFields/TextField/index.d.ts +2 -0
  44. package/dist/fields/StringOrTextFields/index.d.ts +2 -0
  45. package/dist/fields/constants.d.ts +18 -0
  46. package/dist/fields/hooks.d.ts +6 -0
  47. package/dist/fields/index.d.ts +11 -0
  48. package/dist/fields/typings.d.ts +24 -0
  49. package/dist/fields/utils.d.ts +12 -0
  50. package/dist/forms.js +1786 -0
  51. package/dist/forms.umd.cjs +1 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/renderer/FormBrowser/FormBrowser.d.ts +11 -0
  54. package/dist/renderer/FormRenderer/FormRenderer.d.ts +28 -0
  55. package/dist/renderer/FormSubmissionBrowser/FormSubmissionBrowser.d.ts +28 -0
  56. package/dist/renderer/FormSubmissionViewer/FormSubmissionViewer.d.ts +17 -0
  57. package/dist/renderer/PatchForm/Field.d.ts +15 -0
  58. package/dist/renderer/PatchForm/Provider.d.ts +24 -0
  59. package/dist/renderer/PatchForm/index.d.ts +2 -0
  60. package/dist/renderer/index.d.ts +5 -0
  61. package/dist/style.css +1 -0
  62. package/dist/typings.d.ts +5 -0
  63. package/dist/utils.d.ts +7 -0
  64. package/package.json +88 -0
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { FieldInputClonerProps } from "./typings.ts";
3
+ /**
4
+ * Used to dynamically "clone" a field's input for use in conditional sections. When a field is selected for a
5
+ * condition, we need to render the same input in the condition section, so the user can input a value for the
6
+ * condition.
7
+ */
8
+ export declare const FieldInputCloner: import("react").NamedExoticComponent<FieldInputClonerProps>;
@@ -0,0 +1,18 @@
1
+ import { CustomField, CustomFieldOptions } from "../CustomField";
2
+ import { FieldValue, ISerializedField } from "@overmap-ai/core";
3
+ import { FieldInputClonerProps } from "./index";
4
+ export interface FieldInputClonerFieldOptions extends CustomFieldOptions<unknown> {
5
+ /** Given an identifier, should return the options of the field with the
6
+ * corresponding identifier (the field being cloned) */
7
+ getFieldToClone: (identifier: string) => ISerializedField | null;
8
+ /** The identifier of the field to clone */
9
+ clonedFieldIdentifier: string;
10
+ }
11
+ /**
12
+ * The purpose of this is to display a value input field in the condition of a section. The input field will look like
13
+ * the input field of the condition. For example, when specifying the conditional value of a SelectField, a SelectInput
14
+ * will be rendered.
15
+ */
16
+ export declare class FieldInputClonerField extends CustomField<FieldValue, FieldInputClonerFieldOptions, FieldInputClonerProps> {
17
+ constructor(options: FieldInputClonerFieldOptions);
18
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./FieldInputCloner";
2
+ export * from "./FieldInputClonerField";
3
+ export * from "./typings";
@@ -0,0 +1,5 @@
1
+ import { FieldValue } from "@overmap-ai/core";
2
+ import { AnyField, ComponentProps, GetInputProps } from "../../typings";
3
+ import { CustomField } from "../CustomField";
4
+ import { FieldInputClonerFieldOptions } from "./FieldInputClonerField";
5
+ export type FieldInputClonerProps = ComponentProps<CustomField<FieldValue, FieldInputClonerFieldOptions, GetInputProps<AnyField>>>;
@@ -0,0 +1 @@
1
+ export * from "./CustomField";
@@ -0,0 +1,4 @@
1
+ import { ComponentProps } from '../typings';
2
+ import React from "react";
3
+ import { DateField } from "./DateField";
4
+ export declare const DateInput: React.NamedExoticComponent<ComponentProps<DateField>>;
@@ -0,0 +1,2 @@
1
+ export * from "./DateField";
2
+ export * from "./DateInput";
@@ -0,0 +1,29 @@
1
+ import { BaseSerializedObject, ISerializedField, SerializedCondition, SerializedFieldSection } from "@overmap-ai/core";
2
+ import { GetInputProps } from '..';
3
+ import { AnyField } from '../typings';
4
+ import { BaseFormElement } from '../BaseField';
5
+ import React from "react";
6
+ import { Form } from '../../typings';
7
+ interface FieldSectionOptions extends Omit<BaseSerializedObject, "type"> {
8
+ label?: string | null;
9
+ conditional?: boolean;
10
+ condition?: SerializedCondition | null;
11
+ fields: AnyField[];
12
+ }
13
+ export declare class FieldSection extends BaseFormElement<"section"> {
14
+ static readonly fieldTypeName = "Section";
15
+ static readonly fieldTypeDescription = "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.";
16
+ readonly label: string | null;
17
+ readonly fields: AnyField[];
18
+ readonly condition: SerializedCondition | null;
19
+ constructor(options: FieldSectionOptions);
20
+ static getFieldCreationSchema(options: ISerializedField[]): BaseFormElement[];
21
+ static deserialize(data: ISerializedField): FieldSection;
22
+ conditional(): this is {
23
+ condition: SerializedCondition;
24
+ };
25
+ serialize(): SerializedFieldSection;
26
+ getErrors(allValues: Form): Record<string, string>;
27
+ getInput(props: GetInputProps<this>): React.ReactNode;
28
+ }
29
+ export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from '..';
3
+ import { FieldSection } from ".";
4
+ /**
5
+ * Used by FieldSection to render a section of fields.
6
+ */
7
+ export declare const FieldSectionLayout: import("react").NamedExoticComponent<ComponentProps<FieldSection>>;
@@ -0,0 +1 @@
1
+ export * from "./FieldSection";
@@ -0,0 +1,8 @@
1
+ import { ComponentProps } from "../typings.ts";
2
+ import React from "react";
3
+ import { MultiStringField } from "./MultiStringField";
4
+ /**
5
+ * Allows the user to create an array of unique strings and customize the order.
6
+ * User to generate options for the Select field.
7
+ */
8
+ export declare const MultiStringInput: React.NamedExoticComponent<ComponentProps<MultiStringField>>;
@@ -0,0 +1,2 @@
1
+ export * from "./MultiStringField";
2
+ export * from "./MultiStringInput";
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from '../typings';
3
+ import { NumberField } from ".";
4
+ export declare const NumberInput: import("react").NamedExoticComponent<ComponentProps<NumberField>>;
@@ -0,0 +1,2 @@
1
+ export * from "./NumberField";
2
+ export * from "./NumberInput";
@@ -0,0 +1,26 @@
1
+ import { FieldValue, SelectFieldOption } from "@overmap-ai/core";
2
+ import { BaseField, ChildFieldOptions } from "../BaseField";
3
+ import { MultiStringField } from "../MultiStringField";
4
+ /**
5
+ * The options passed to the constructor of SelectField.
6
+ */
7
+ export interface BaseSelectFieldOptions<TValue, TIdentifier extends "select" | "multi-select"> extends ChildFieldOptions<TValue> {
8
+ /** When instantiating a SelectField, you can either pass an array of strings or an array of objects. User-created
9
+ * forms only support arrays of strings. For more complex internal purposes, you can provide an array of objects
10
+ * where the `label` is the text to display to the user and the `value` is the value handled by Formik.*/
11
+ options: string[] | SelectFieldOption[];
12
+ type: TIdentifier;
13
+ }
14
+ export declare abstract class BaseSelectField<TValue extends FieldValue, TIdentifier extends "select" | "multi-select"> extends BaseField<TValue, TIdentifier> {
15
+ readonly options: SelectFieldOption[];
16
+ protected constructor(options: BaseSelectFieldOptions<TValue, TIdentifier>);
17
+ protected _serialize(): {
18
+ options: SelectFieldOption[];
19
+ label: string;
20
+ required: boolean;
21
+ description?: string | null | undefined;
22
+ identifier: string;
23
+ type: TIdentifier;
24
+ };
25
+ static getFieldCreationSchema(): MultiStringField[];
26
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../typings";
3
+ import { MultiSelectField } from "./MultiSelectField";
4
+ export declare const MultiSelectInput: import("react").NamedExoticComponent<ComponentProps<MultiSelectField>>;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from "../typings";
3
+ import { SelectField } from "./SelectField";
4
+ export declare const SelectInput: import("react").NamedExoticComponent<ComponentProps<SelectField>>;
@@ -0,0 +1,4 @@
1
+ export * from "./SelectField";
2
+ export * from "./SelectInput";
3
+ export * from "./MultiSelectInput";
4
+ export * from "./MultiSelectField";
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from '../../typings';
3
+ import { StringField } from "./StringField";
4
+ export declare const StringInput: import("react").NamedExoticComponent<ComponentProps<StringField>>;
@@ -0,0 +1,2 @@
1
+ export * from "./StringField";
2
+ export * from "./StringInput";
@@ -0,0 +1,29 @@
1
+ import { NumberField, NumberFieldValue } from "../NumberField";
2
+ import { BaseField, FieldOptions } from "../BaseField";
3
+ import { SerializedStringField } from "@overmap-ai/core";
4
+ import { InputFieldLevelValidator, InputValidator } from '../typings';
5
+ export interface StringOrTextFieldOptions extends FieldOptions<string> {
6
+ minLength?: NumberFieldValue;
7
+ maxLength?: NumberFieldValue;
8
+ }
9
+ export type SerializedStringOrTextField<TIdentifier extends "string" | "text"> = Omit<SerializedStringField, "type"> & {
10
+ type: TIdentifier;
11
+ };
12
+ export declare abstract class StringOrTextField<TIdentifier extends "string" | "text"> extends BaseField<string, TIdentifier> {
13
+ readonly minLength?: number;
14
+ readonly maxLength: number;
15
+ protected constructor(options: StringOrTextFieldOptions);
16
+ /**
17
+ * This function validates that the value given for "minimum length" (when creating a new field) is less than or
18
+ * equal to the value given for "maximum length".
19
+ */
20
+ static _validateMin: InputValidator<NumberFieldValue>;
21
+ /**
22
+ * This function validates that the value given for "maximum length" (when creating a new field) is greater than or
23
+ * equal to the value given for "minimum length".
24
+ */
25
+ static _validateMax: InputValidator<NumberFieldValue>;
26
+ static getFieldCreationSchema(): NumberField[];
27
+ getFieldValidators(): InputFieldLevelValidator<string>[];
28
+ protected _serialize(): SerializedStringOrTextField<TIdentifier>;
29
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { ComponentProps } from '../../typings';
3
+ import { TextField } from "./TextField";
4
+ export declare const TextInput: import("react").NamedExoticComponent<ComponentProps<TextField>>;
@@ -0,0 +1,2 @@
1
+ export * from "./TextField";
2
+ export * from "./TextInput";
@@ -0,0 +1,2 @@
1
+ export * from "./StringField";
2
+ export * from "./TextField";
@@ -0,0 +1,18 @@
1
+ import { StringField, TextField } from "./StringOrTextFields";
2
+ import { BooleanField } from "./BooleanField";
3
+ import { DateField } from "./DateField";
4
+ import { NumberField } from "./NumberField";
5
+ import { MultiSelectField, SelectField } from "./SelectField";
6
+ import { CustomField } from "./CustomField";
7
+ import { MultiStringField } from "./MultiStringField";
8
+ export declare const FieldTypeToClsMapping: {
9
+ readonly date: typeof DateField;
10
+ readonly number: typeof NumberField;
11
+ readonly boolean: typeof BooleanField;
12
+ readonly select: typeof SelectField;
13
+ readonly string: typeof StringField;
14
+ readonly text: typeof TextField;
15
+ readonly custom: typeof CustomField;
16
+ readonly "multi-string": typeof MultiStringField;
17
+ readonly "multi-select": typeof MultiSelectField;
18
+ };
@@ -0,0 +1,6 @@
1
+ import { GetInputProps } from "./typings";
2
+ import { ReactNode } from "react";
3
+ import { BaseField, BaseFormElement } from "./BaseField";
4
+ import { FieldValue } from "@overmap-ai/core";
5
+ export declare const useFieldInput: <TField extends BaseFormElement<import("@overmap-ai/core").FieldTypeIdentifier> | null>(field: TField, props: TField extends BaseFormElement<import("@overmap-ai/core").FieldTypeIdentifier> ? GetInputProps<TField> : null) => ReactNode;
6
+ export declare const useFieldInputs: (fields: BaseFormElement[], props: GetInputProps<BaseField<FieldValue>>) => ReactNode;
@@ -0,0 +1,11 @@
1
+ export type { BaseField } from "./BaseField";
2
+ export * from "./NumberField";
3
+ export * from "./DateField";
4
+ export * from "./StringOrTextFields";
5
+ export * from "./BooleanField";
6
+ export * from "./SelectField";
7
+ export * from "./MultiStringField";
8
+ export * from "./FieldSection";
9
+ export * from "./utils";
10
+ export * from "./hooks";
11
+ export type * from "./typings";
@@ -0,0 +1,24 @@
1
+ import { HTMLProps, ReactNode } from "react";
2
+ import { Form } from '../typings';
3
+ import { BaseField, BaseFormElement } from "./BaseField";
4
+ import { ISerializedField, SerializedFieldSection } from "@overmap-ai/core";
5
+ export interface SchemaMeta {
6
+ readonly: boolean;
7
+ }
8
+ export interface ISchema {
9
+ id?: string;
10
+ fields: BaseFormElement[];
11
+ meta: SchemaMeta;
12
+ title: ReactNode;
13
+ description?: ReactNode;
14
+ }
15
+ export type InputFieldLevelValidator<TValue> = (value: TValue | undefined) => string | null | undefined;
16
+ export type InputFormLevelValidator<TValue> = (value: TValue | undefined, allValues: Form) => string | null | undefined;
17
+ export type InputValidator<TValue> = InputFieldLevelValidator<TValue> | InputFormLevelValidator<TValue>;
18
+ export interface ComponentProps<TField extends BaseFormElement> extends Omit<HTMLProps<HTMLElement>, "color" | "size" | "ref" | "type" | "onChange" | "onBlur" | "value" | "defaultValue" | "name" | "dir"> {
19
+ field: TField;
20
+ formId: string;
21
+ }
22
+ export type GetInputProps<TField extends BaseFormElement> = Omit<ComponentProps<TField>, "field">;
23
+ export type AnyField = BaseField<any>;
24
+ export type ISerializedOnlyField = Exclude<ISerializedField, SerializedFieldSection>;
@@ -0,0 +1,12 @@
1
+ import { AnyField, ISchema, ISerializedOnlyField, SchemaMeta } from "./typings";
2
+ import { FieldValue, ISerializedField, SerializedCondition, UserFormRevision } from "@overmap-ai/core";
3
+ import { FieldSection } from "./FieldSection";
4
+ /** Deserializes anything but a FieldSection.
5
+ * @see `deserialize` for most use cases
6
+ */
7
+ export declare const deserializeField: (serializedField: ISerializedOnlyField) => AnyField;
8
+ /** Deserializes anything */
9
+ export declare const deserialize: (serialized: ISerializedField) => AnyField | FieldSection;
10
+ export type PartialFormRevision = Pick<UserFormRevision, "title" | "fields" | "description"> & Partial<UserFormRevision>;
11
+ export declare function formRevisionToSchema(formRevision: PartialFormRevision, meta?: Partial<SchemaMeta>): ISchema;
12
+ export declare function isConditionMet<TValue extends FieldValue>(condition: SerializedCondition<TValue> | null, value: TValue): boolean;